1#include "ComputeTask.h"
3#include "Rendering/ICapabilities.h"
4#include "Rendering/IContext.h"
5#include "Rendering/IGraphicsDevice.h"
7#include "Foundation/Logging/Logger.h"
8#include "Resources/ShaderBuilderPostProcess.h"
10#include "Renderer/Renderer.h"
19void Cogs::Core::ComputeTask::initialize(RenderTaskContext * context)
23 for (
auto & p : effectParameter.values) {
24 if (p.key ==
"definitions") {
25 for (
auto & d : p.values) {
26 desc.definitions.push_back({ d.key, d.value });
29 else if (p.key ==
"source") {
32 else if (p.key ==
"useVariables") {
35 else if (p.key ==
"setVariables") {
38 else if (p.key ==
"useComponentFields") {
41 else if (p.key ==
"properties") {
44 else if (p.key ==
"groups" && p.values.size() == 3) {
47 else if (p.key ==
"options") {
51 LOG_WARNING(logger,
"Unknown compute task pipeline section \"%s\"", p.key.c_str());
55 effect = context->renderer->getEffectCache().loadEffect(context, desc);
58void Cogs::Core::ComputeTask::initialize(RenderTaskContext* context,
const RenderTaskDefinition& taskDefinition) {
59 ProcessTask::initialize(context, taskDefinition);
62 for (
auto& p : effectParameter.values) {
63 if (p.key ==
"definitions") {
64 for (
auto& d : p.values) {
65 desc.definitions.push_back({ d.key, d.value });
68 else if (p.key ==
"source") {
71 else if (p.key ==
"useVariables") {
74 else if (p.key ==
"setVariables") {
77 else if (p.key ==
"useComponentFields") {
80 else if (p.key ==
"properties") {
83 else if (p.key ==
"groups" && p.values.size() == 3) {
86 else if (p.key ==
"options") {
90 LOG_WARNING(logger,
"Unknown compute task pipeline section \"%s\"", p.key.c_str());
97 switch (graphicsDeviceType)
102 success = Cogs::Core::buildPostProcessEffectES3(context, desc,
this);
105 success = buildPostProcessEffectWebGPU(context, desc);
110 success = buildComputeEffect(context, desc,
this);
116 LOG_ERROR(logger,
"Failed to build post processing shader source");
120 effect = context->renderer->getEffectCache().loadEffect(context, desc);
123void Cogs::Core::ComputeTask::cleanup(RenderTaskContext * context)
125 ProcessTask::cleanup(context);
128void Cogs::Core::ComputeTask::apply(RenderTaskContext * context)
130 DynamicRenderInstrumentationScope(context->device->getImmediateContext(), SCOPE_RENDERING,
"ComputeTask", (std::string(
"ComputeTask<") + name +
">::apply").c_str());
133 LOG_ERROR(logger,
"Invalid compute effect handle.");
137 auto device = context->renderer->getDevice();
138 auto deviceContext = device->getImmediateContext();
140 if(!device->getCapabilities()->getDeviceCapabilities().RenderPass){
145 deviceContext->setEffect(effect->handle);
147 setProperties(context);
151 uint32_t groups[3] = { 1, 1, 1 };
153 if (this->groups.expressions.size() == 3) {
154 for (
size_t i = 0; i < 3; i++) {
155 groups[i] = this->scope->update(this->groups.expressions[i].second, 0);
159 for (
auto & ep : effectParameter.values) {
160 if (ep.key !=
"groups")
continue;
162 for (uint32_t i = 0; i < 3; i++) {
163 groups[i] =
static_cast<uint32_t
>(ep.float3Value[i]);
168 if (groups[0] && groups[1] && groups[2]) {
169 deviceContext->dispatchCompute(groups[0], groups[1], groups[2]);
171 LOG_WARNING(logger,
"Empty compute shader dimensions.");
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.
Contains an effect description used to load a single effect.
static const Handle_t NoHandle
Represents a handle to nothing.
static SamplerState & DefaultState()
Constructs a sampler state initialized with the default values.