1#include "ComputeTask.h"
3#include "Rendering/IGraphicsDevice.h"
4#include "Rendering/IContext.h"
6#include "Foundation/Logging/Logger.h"
7#include "Resources/ShaderBuilderPostProcess.h"
9#include "Renderer/Renderer.h"
18void Cogs::Core::ComputeTask::initialize(RenderTaskContext * context)
22 for (
auto & p : effectParameter.values) {
23 if (p.key ==
"definitions") {
24 for (
auto & d : p.values) {
25 desc.definitions.push_back({ d.key, d.value });
28 if (p.key ==
"source") {
33 effect = context->renderer->getEffectCache().loadEffect(context, desc);
36void Cogs::Core::ComputeTask::initialize(RenderTaskContext* context,
const RenderTaskDefinition& taskDefinition) {
37 ProcessTask::initialize(context, taskDefinition);
40 for (
auto& p : effectParameter.values) {
41 if (p.key ==
"definitions") {
42 for (
auto& d : p.values) {
43 desc.definitions.push_back({ d.key, d.value });
46 if (p.key ==
"source") {
54 switch (graphicsDeviceType)
59 success = Cogs::Core::buildPostProcessEffectES3(context, desc,
this);
62 success = buildPostProcessEffectWebGPU(context, desc);
67 success = buildComputeEffect(context, desc,
this);
73 LOG_ERROR(logger,
"Failed to build post processing shader source");
77 effect = context->renderer->getEffectCache().loadEffect(context, desc);
80void Cogs::Core::ComputeTask::cleanup(RenderTaskContext * context)
82 ProcessTask::cleanup(context);
85void Cogs::Core::ComputeTask::apply(RenderTaskContext * context)
87 DynamicRenderInstrumentationScope(context->device->getImmediateContext(), SCOPE_RENDERING,
"ComputeTask", (std::string(
"ComputeTask<") + name +
">::apply").c_str());
90 LOG_ERROR(logger,
"Invalid compute effect handle.");
94 auto device = context->renderer->getDevice();
95 auto deviceContext = device->getImmediateContext();
100 deviceContext->setEffect(effect->handle);
102 setProperties(context);
106 uint32_t groups[3] = { 1, 1, 1 };
108 if (this->groups.expressions.size() == 3) {
109 for (
size_t i = 0; i < 3; i++) {
110 groups[i] = this->scope->update(this->groups.expressions[i].second, 0);
114 for (
auto & ep : effectParameter.values) {
115 if (ep.key !=
"groups")
continue;
117 for (uint32_t i = 0; i < 3; i++) {
118 groups[i] =
static_cast<uint32_t
>(ep.float3Value[i]);
123 if (groups[0] && groups[1] && groups[2]) {
124 deviceContext->dispatchCompute(groups[0], groups[1], groups[2]);
126 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.