1#include "ComputeTask.h"
3#include "Rendering/ICapabilities.h"
4#include "Rendering/IContext.h"
5#include "Rendering/IEffects.h"
6#include "Rendering/IGraphicsDevice.h"
8#include "Foundation/Logging/Logger.h"
9#include "Resources/ShaderBuilderPostProcess.h"
11#include "Renderer/Renderer.h"
22void Cogs::Core::ComputeTask::initialize(RenderTaskContext * context)
26 for (
auto & p : effectParameter.values) {
27 if (p.key ==
"definitions") {
28 for (
auto & d : p.values) {
29 desc.definitions.push_back({ d.key, d.value });
32 else if (p.key ==
"source") {
35 else if (p.key ==
"useVariables") {
38 else if (p.key ==
"setVariables") {
41 else if (p.key ==
"useComponentFields") {
44 else if (p.key ==
"properties") {
47 else if (p.key ==
"groups" && p.values.size() == 3) {
50 else if (p.key ==
"options") {
54 LOG_WARNING(logger,
"Unknown compute task pipeline section \"%s\"", p.key.c_str());
58 effect = context->renderer->getEffectCache().loadEffect(context, desc);
61void Cogs::Core::ComputeTask::initialize(RenderTaskContext* context,
const RenderTaskDefinition& taskDefinition) {
62 ProcessTask::initialize(context, taskDefinition);
65 for (
auto& p : effectParameter.values) {
66 if (p.key ==
"definitions") {
67 for (
auto& d : p.values) {
68 desc.definitions.push_back({ d.key, d.value });
71 else if (p.key ==
"source") {
74 else if (p.key ==
"useVariables") {
77 else if (p.key ==
"setVariables") {
80 else if (p.key ==
"useComponentFields") {
83 else if (p.key ==
"properties") {
86 else if (p.key ==
"groups" && p.values.size() == 3) {
89 else if (p.key ==
"options") {
93 LOG_WARNING(logger,
"Unknown compute task pipeline section \"%s\"", p.key.c_str());
100 switch (graphicsDeviceType)
105 success = Cogs::Core::buildPostProcessEffectES3(context, desc,
this);
108 success = buildPostProcessEffectWebGPU(context, desc);
113 success = buildComputeEffect(context, desc,
this);
119 LOG_ERROR(logger,
"Failed to build post processing shader source");
123 effect = context->renderer->getEffectCache().loadEffect(context, desc);
126void Cogs::Core::ComputeTask::cleanup(RenderTaskContext * context)
128 ProcessTask::cleanup(context);
138 LOG_ERROR(logger,
"Invalid compute effect handle.");
141 effectStatus = status;
147 DynamicRenderInstrumentationScope(context->device->
getImmediateContext(), SCOPE_RENDERING,
"ComputeTask", (std::string(
"ComputeTask<") + name +
">::apply").c_str());
151 auto device = context->renderer->
getDevice();
154 if(!device->getCapabilities()->getDeviceCapabilities().RenderPass){
159 deviceContext->setEffect(effect->handle);
161 setProperties(context);
165 uint32_t groups[3] = { 1, 1, 1 };
167 if (this->groups.expressions.size() == 3) {
168 for (
size_t i = 0; i < 3; i++) {
169 groups[i] = this->scope->update(this->groups.expressions[i].second, 0);
173 for (
auto & ep : effectParameter.values) {
174 if (ep.key !=
"groups")
continue;
176 for (uint32_t i = 0; i < 3; i++) {
177 groups[i] =
static_cast<uint32_t
>(ep.float3Value[i]);
182 if (groups[0] && groups[1] && groups[2]) {
183 deviceContext->dispatchCompute(groups[0], groups[1], groups[2]);
185 LOG_WARNING(logger,
"Empty compute shader dimensions.");
IGraphicsDevice * getDevice() override
Get the graphics device used by the renderer.
virtual IEffects * getEffects()=0
Get a pointer to the effect management interface.
virtual IContext * getImmediateContext()=0
Get a pointer to the immediate context used to issue commands to the graphics device.
Log implementation class.
bool HandleIsValid(const ResourceHandle_t< T > &handle)
Check if the given resource is valid, that is not equal to NoHandle or InvalidHandle.
constexpr Log getLogger(const char(&name)[LEN]) noexcept
Contains all Cogs related functionality.
GraphicsDeviceType
Contains types of graphics devices that may be supported.
@ OpenGLES30
Graphics device using the OpenGLES 3.0 API.
@ Direct3D11
Graphics device using the Direct3D 11 API.
@ OpenGL20
Graphics device using OpenGL, supporting at least OpenGL 2.0.
@ WebGPU
Graphics device using the WebGPU API Backend.
ResourceStatus
Status of an asynchronously loaded resource, such as an effect or a pipeline.
@ Error
The resource failed to load.
@ Ready
The resource has loaded successfully and is ready for use.
Cogs::ResourceStatus checkReady(RenderTaskContext *context) override
Check if the task is ready to be applied, e.g.
Contains an effect description used to load a single effect.
static const Handle_t NoHandle
Represents a handle to nothing.
virtual void setRenderTarget(const RenderTargetHandle handle, const DepthStencilHandle depthStencilHandle)=0
Sets the current render target and an associated depth stencil target.
Provides effects and shader management functionality.
virtual ResourceStatus checkEffect(EffectHandle effectHandle)=0
Check the load status of the effect with the given effectHandle.
static SamplerState & DefaultState()
Constructs a sampler state initialized with the default values.