1#include "ComputeTask.h"
3#include "Rendering/IGraphicsDevice.h"
4#include "Rendering/IContext.h"
6#include "Foundation/Logging/Logger.h"
8#include "Renderer/Renderer.h"
17void Cogs::Core::ComputeTask::initialize(RenderTaskContext * context)
21 for (
auto & p : effectParameter.values) {
22 if (p.key ==
"definitions") {
23 for (
auto & d : p.values) {
24 desc.definitions.push_back({ d.key, d.value });
27 if (p.key ==
"source") {
32 effect = context->renderer->getEffectCache().loadEffect(context, desc);
35void Cogs::Core::ComputeTask::cleanup(RenderTaskContext * context)
37 ProcessTask::cleanup(context);
40void Cogs::Core::ComputeTask::apply(RenderTaskContext * context)
42 DynamicRenderInstrumentationScope(context->device->getImmediateContext(), SCOPE_RENDERING,
"ComputeTask", (std::string(
"ComputeTask<") + name +
">::apply").c_str());
45 LOG_ERROR(logger,
"Invalid compute effect handle.");
49 auto device = context->renderer->getDevice();
50 auto deviceContext = device->getImmediateContext();
55 deviceContext->setEffect(effect->handle);
57 setProperties(context);
61 uint32_t groups[3] = { 1, 1, 1 };
63 if (this->groups.expressions.size() == 3) {
64 for (
size_t i = 0; i < 3; i++) {
65 groups[i] = this->scope->update(this->groups.expressions[i].second, 0);
69 for (
auto & ep : effectParameter.values) {
70 if (ep.key !=
"groups")
continue;
72 for (uint32_t i = 0; i < 3; i++) {
73 groups[i] =
static_cast<uint32_t
>(ep.float3Value[i]);
78 if (groups[0] && groups[1] && groups[2]) {
79 deviceContext->dispatchCompute(groups[0], groups[1], groups[2]);
81 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.
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.