Nameless Engine
Loading...
Searching...
No Matches
ComputeShaderInterface.h
1#pragma once
2
3// Standard.
4#include <string>
5#include <memory>
6#include <vector>
7#include <variant>
8#include <functional>
9
10// Custom.
11#include "misc/Error.h"
12#include "render/general/pipeline/PipelineSharedPtr.h"
13#include "render/general/resource/GpuResource.h"
14
15namespace ne {
16 class Renderer;
17
19 enum class ComputeResourceUsage {
20 READ_ONLY_ARRAY_BUFFER, //< `StructuredBuffer` in HLSL, `readonly buffer` in GLSL.
21 READ_WRITE_ARRAY_BUFFER, //< `RWStructuredBuffer` in HLSL, `buffer` in GLSL.
22 CONSTANT_BUFFER, //< `cbuffer` in HLSL, `uniform` in GLSL.
23 READ_ONLY_TEXTURE, //< `Texture2D` in HLSL, `uniform sampler2D` in GLSL.
24 READ_WRITE_TEXTURE, //< `RWTexture2D` in HLSL, `uniform image2D` in GLSL.
25 };
26
28 enum class ComputeExecutionStage : size_t {
29 AFTER_DEPTH_PREPASS = 0, //< After depth texture is fully written but before color rendering (main
30 // pass) is < started.
31
32 SIZE //< Marks the size of this enum.
33 };
34
39 enum class ComputeExecutionGroup : size_t {
40 FIRST = 0,
41 SECOND,
42 SIZE //< Marks the size of this enum.
43 };
44
47 public:
48 ComputeShaderInterface() = delete;
50
52 ComputeShaderInterface& operator=(const ComputeShaderInterface&) = delete;
53
72 static std::variant<std::unique_ptr<ComputeShaderInterface>, Error> createUsingGraphicsQueue(
74 const std::string& sCompiledComputeShaderName,
75 ComputeExecutionStage executionStage,
76 ComputeExecutionGroup executionGroup = ComputeExecutionGroup::FIRST);
77
97 [[nodiscard]] virtual std::optional<Error> bindResource(
98 GpuResource* pResource,
99 const std::string& sShaderResourceName,
100 ComputeResourceUsage usage,
101 bool bUpdateOnlyCurrentFrameResourceDescriptors = false) = 0;
102
118 unsigned int iThreadGroupCountX,
119 unsigned int iThreadGroupCountY,
120 unsigned int iThreadGroupCountZ);
121
128 ComputeExecutionGroup getExecutionGroup() const;
129
135 ComputeExecutionStage getExecutionStage() const;
136
142 std::string getComputeShaderName() const;
143
149 Pipeline* getUsedPipeline() const;
150
151 protected:
163 static std::variant<std::unique_ptr<ComputeShaderInterface>, Error> createRenderSpecificInterface(
165 const std::string& sComputeShaderName,
166 ComputeExecutionStage executionStage,
167 ComputeExecutionGroup executionGroup);
168
181 static std::unique_ptr<ComputeShaderInterface> createPartiallyInitializedRenderSpecificInterface(
183 const std::string& sComputeShaderName,
184 ComputeExecutionStage executionStage,
185 ComputeExecutionGroup executionGroup);
186
198 const std::string& sComputeShaderName,
199 ComputeExecutionStage executionStage,
200 ComputeExecutionGroup executionGroup);
201
210
216 Pipeline* getPipeline() const;
217
223 inline unsigned int getThreadGroupCountX() const { return iThreadGroupCountX; }
224
230 inline unsigned int getThreadGroupCountY() const { return iThreadGroupCountY; }
231
237 inline unsigned int getThreadGroupCountZ() const { return iThreadGroupCountZ; }
238
239 private:
241 Renderer* pRenderer = nullptr;
242
245
247 unsigned int iThreadGroupCountX = 0;
248
250 unsigned int iThreadGroupCountY = 0;
251
253 unsigned int iThreadGroupCountZ = 0;
254
256 const ComputeExecutionStage executionStage = ComputeExecutionStage::AFTER_DEPTH_PREPASS;
257
259 const ComputeExecutionGroup executionGroup = ComputeExecutionGroup::FIRST;
260
262 const std::string sComputeShaderName;
263 };
264}
Definition: ComputeShaderInterface.h:46
void submitForExecution(unsigned int iThreadGroupCountX, unsigned int iThreadGroupCountY, unsigned int iThreadGroupCountZ)
Definition: ComputeShaderInterface.cpp:104
static std::variant< std::unique_ptr< ComputeShaderInterface >, Error > createRenderSpecificInterface(Renderer *pRenderer, const std::string &sComputeShaderName, ComputeExecutionStage executionStage, ComputeExecutionGroup executionGroup)
Definition: ComputeShaderInterface.cpp:79
std::string getComputeShaderName() const
Definition: ComputeShaderInterface.cpp:130
unsigned int iThreadGroupCountY
Definition: ComputeShaderInterface.h:250
ComputeExecutionGroup getExecutionGroup() const
Definition: ComputeShaderInterface.cpp:126
Pipeline * getPipeline() const
Definition: ComputeShaderInterface.cpp:136
unsigned int getThreadGroupCountX() const
Definition: ComputeShaderInterface.h:223
Renderer * pRenderer
Definition: ComputeShaderInterface.h:241
unsigned int getThreadGroupCountY() const
Definition: ComputeShaderInterface.h:230
const ComputeExecutionGroup executionGroup
Definition: ComputeShaderInterface.h:259
ComputeExecutionStage getExecutionStage() const
Definition: ComputeShaderInterface.cpp:128
unsigned int iThreadGroupCountX
Definition: ComputeShaderInterface.h:247
const ComputeExecutionStage executionStage
Definition: ComputeShaderInterface.h:256
Renderer * getRenderer()
Definition: ComputeShaderInterface.cpp:134
virtual std::optional< Error > bindResource(GpuResource *pResource, const std::string &sShaderResourceName, ComputeResourceUsage usage, bool bUpdateOnlyCurrentFrameResourceDescriptors=false)=0
unsigned int iThreadGroupCountZ
Definition: ComputeShaderInterface.h:253
PipelineSharedPtr pPipeline
Definition: ComputeShaderInterface.h:244
unsigned int getThreadGroupCountZ() const
Definition: ComputeShaderInterface.h:237
static std::variant< std::unique_ptr< ComputeShaderInterface >, Error > createUsingGraphicsQueue(Renderer *pRenderer, const std::string &sCompiledComputeShaderName, ComputeExecutionStage executionStage, ComputeExecutionGroup executionGroup=ComputeExecutionGroup::FIRST)
Definition: ComputeShaderInterface.cpp:46
Pipeline * getUsedPipeline() const
Definition: ComputeShaderInterface.cpp:132
const std::string sComputeShaderName
Definition: ComputeShaderInterface.h:262
static std::unique_ptr< ComputeShaderInterface > createPartiallyInitializedRenderSpecificInterface(Renderer *pRenderer, const std::string &sComputeShaderName, ComputeExecutionStage executionStage, ComputeExecutionGroup executionGroup)
Definition: ComputeShaderInterface.cpp:56
Definition: Error.h:27
Definition: GpuResource.h:16
Definition: PipelineSharedPtr.h:15
Definition: Pipeline.h:20
Definition: Renderer.h:43