Plasma Engine  2.0
Loading...
Searching...
No Matches
CommandEncoder.h
1
2#pragma once
3
4#include <Foundation/Threading/ThreadUtils.h>
5#include <RendererFoundation/CommandEncoder/CommandEncoderPlatformInterface.h>
6#include <RendererFoundation/CommandEncoder/CommandEncoderState.h>
7
9
10class PL_RENDERERFOUNDATION_DLL plGALCommandEncoder
11{
12 PL_DISALLOW_COPY_AND_ASSIGN(plGALCommandEncoder);
13
14public:
16 virtual ~plGALCommandEncoder();
17
18 // State setting functions
19
20 void SetShader(plGALShaderHandle hShader);
21
22 void SetConstantBuffer(const plShaderResourceBinding& binding, plGALBufferHandle hBuffer);
23 void SetSamplerState(const plShaderResourceBinding& binding, plGALSamplerStateHandle hSamplerState);
24 void SetResourceView(const plShaderResourceBinding& binding, plGALTextureResourceViewHandle hResourceView);
25 void SetResourceView(const plShaderResourceBinding& binding, plGALBufferResourceViewHandle hResourceView);
26 void SetUnorderedAccessView(const plShaderResourceBinding& binding, plGALTextureUnorderedAccessViewHandle hUnorderedAccessView);
27 void SetUnorderedAccessView(const plShaderResourceBinding& binding, plGALBufferUnorderedAccessViewHandle hUnorderedAccessView);
28 void SetPushConstants(plArrayPtr<const plUInt8> data);
29
30 // GPU -> CPU query functions
31
34 plGALTimestampHandle InsertTimestamp();
35
41 plGALOcclusionHandle BeginOcclusionQuery(plEnum<plGALQueryType> type);
42
47 void EndOcclusionQuery(plGALOcclusionHandle hOcclusion);
48
53 plGALFenceHandle InsertFence();
54
55 // Resource functions
56
58 void ClearUnorderedAccessView(plGALTextureUnorderedAccessViewHandle hUnorderedAccessView, plVec4 vClearValues);
59 void ClearUnorderedAccessView(plGALBufferUnorderedAccessViewHandle hUnorderedAccessView, plVec4 vClearValues);
60
62 void ClearUnorderedAccessView(plGALTextureUnorderedAccessViewHandle hUnorderedAccessView, plVec4U32 vClearValues);
63 void ClearUnorderedAccessView(plGALBufferUnorderedAccessViewHandle hUnorderedAccessView, plVec4U32 vClearValues);
64
65 void CopyBuffer(plGALBufferHandle hDest, plGALBufferHandle hSource);
66 void CopyBufferRegion(plGALBufferHandle hDest, plUInt32 uiDestOffset, plGALBufferHandle hSource, plUInt32 uiSourceOffset, plUInt32 uiByteCount);
67 void UpdateBuffer(plGALBufferHandle hDest, plUInt32 uiDestOffset, plArrayPtr<const plUInt8> sourceData, plGALUpdateMode::Enum updateMode = plGALUpdateMode::Discard);
68
69 void CopyTexture(plGALTextureHandle hDest, plGALTextureHandle hSource);
70 void CopyTextureRegion(plGALTextureHandle hDest, const plGALTextureSubresource& destinationSubResource, const plVec3U32& vDestinationPoint, plGALTextureHandle hSource, const plGALTextureSubresource& sourceSubResource, const plBoundingBoxu32& box);
71
72 void UpdateTexture(plGALTextureHandle hDest, const plGALTextureSubresource& destinationSubResource, const plBoundingBoxu32& destinationBox, const plGALSystemMemoryDescription& sourceData);
73
74 void ResolveTexture(plGALTextureHandle hDest, const plGALTextureSubresource& destinationSubResource, plGALTextureHandle hSource, const plGALTextureSubresource& sourceSubResource);
75
76 void ReadbackTexture(plGALTextureHandle hTexture);
77 void CopyTextureReadbackResult(plGALTextureHandle hTexture, plArrayPtr<plGALTextureSubresource> sourceSubResource, plArrayPtr<plGALSystemMemoryDescription> targetData);
78
79 void GenerateMipMaps(plGALTextureResourceViewHandle hResourceView);
80
81 // Misc
84 void Flush();
85
86 // Debug helper functions
87
88 void PushMarker(const char* szMarker);
89 void PopMarker();
90 void InsertEventMarker(const char* szMarker);
91
92 // Dispatch
93
94 void BeginCompute(const char* szName = "");
95 void EndCompute();
96
97 plResult Dispatch(plUInt32 uiThreadGroupCountX, plUInt32 uiThreadGroupCountY, plUInt32 uiThreadGroupCountZ);
98 plResult DispatchIndirect(plGALBufferHandle hIndirectArgumentBuffer, plUInt32 uiArgumentOffsetInBytes);
99
100 // Draw functions
101
102 void BeginRendering(const plGALRenderingSetup& renderingSetup, const char* szName = "");
103 void EndRendering();
104
109 void Clear(const plColor& clearColor, plUInt32 uiRenderTargetClearMask = 0xFFFFFFFFu, bool bClearDepth = true, bool bClearStencil = true, float fDepthClear = 1.0f, plUInt8 uiStencilClear = 0x0u);
110
111 plResult Draw(plUInt32 uiVertexCount, plUInt32 uiStartVertex);
112 plResult DrawIndexed(plUInt32 uiIndexCount, plUInt32 uiStartIndex);
113 plResult DrawIndexedInstanced(plUInt32 uiIndexCountPerInstance, plUInt32 uiInstanceCount, plUInt32 uiStartIndex);
114 plResult DrawIndexedInstancedIndirect(plGALBufferHandle hIndirectArgumentBuffer, plUInt32 uiArgumentOffsetInBytes);
115 plResult DrawInstanced(plUInt32 uiVertexCountPerInstance, plUInt32 uiInstanceCount, plUInt32 uiStartVertex);
116 plResult DrawInstancedIndirect(plGALBufferHandle hIndirectArgumentBuffer, plUInt32 uiArgumentOffsetInBytes);
117
118 // State functions
119
120 void SetIndexBuffer(plGALBufferHandle hIndexBuffer);
121 void SetVertexBuffer(plUInt32 uiSlot, plGALBufferHandle hVertexBuffer);
122 void SetVertexDeclaration(plGALVertexDeclarationHandle hVertexDeclaration);
123
124 plGALPrimitiveTopology::Enum GetPrimitiveTopology() const { return m_State.m_Topology; }
125 void SetPrimitiveTopology(plGALPrimitiveTopology::Enum topology);
126
127 void SetBlendState(plGALBlendStateHandle hBlendState, const plColor& blendFactor = plColor::White, plUInt32 uiSampleMask = 0xFFFFFFFFu);
128 void SetDepthStencilState(plGALDepthStencilStateHandle hDepthStencilState, plUInt8 uiStencilRefValue = 0xFFu);
129 void SetRasterizerState(plGALRasterizerStateHandle hRasterizerState);
130
131 void SetViewport(const plRectFloat& rect, float fMinDepth = 0.0f, float fMaxDepth = 1.0f);
132 void SetScissorRect(const plRectU32& rect);
133
134 // Internal
135
136 PL_ALWAYS_INLINE plGALDevice& GetDevice() { return m_Device; }
137 // Don't use light hearted ;)
138 void InvalidateState();
139
140protected:
141 friend class plGALDevice;
142
143 void AssertRenderingThread()
144 {
145 PL_ASSERT_DEV(plThreadUtils::IsMainThread(), "This function can only be executed on the main thread.");
146 }
147
148private:
149 void ClearStatisticsCounters();
150 void CountDispatchCall() { m_uiDispatchCalls++; }
151 void CountDrawCall() { m_uiDrawCalls++; }
152
153private:
154 friend class plMemoryUtils;
155
156 // Statistic variables
157 plUInt32 m_uiDispatchCalls = 0;
158 plUInt32 m_uiDrawCalls = 0;
159
160 enum class CommandEncoderType
161 {
162 Invalid,
163 Render,
164 Compute
165 };
166
167 CommandEncoderType m_CurrentCommandEncoderType = CommandEncoderType::Invalid;
168 bool m_bMarker = false;
169
170 // Parent Device
171 plGALDevice& m_Device;
174
175 plGALOcclusionHandle m_hPendingOcclusionQuery = {};
176};
This class encapsulates an array and it's size. It is recommended to use this class instead of plain ...
Definition ArrayPtr.h:37
An axis-aligned bounding box implementation.
Definition BoundingBox.h:12
plColor represents an RGBA color in linear color space. Values are stored as float,...
Definition Color.h:44
static const plColor White
#FFFFFF
Definition Color.h:194
Definition RendererFoundationDLL.h:467
Definition RendererFoundationDLL.h:418
Definition RendererFoundationDLL.h:432
Definition RendererFoundationDLL.h:446
Definition CommandEncoderPlatformInterface.h:13
Definition CommandEncoder.h:11
Definition RendererFoundationDLL.h:460
The plRenderDevice class is the primary interface for interactions with rendering APIs It contains a ...
Definition Device.h:19
Definition RendererFoundationDLL.h:474
Definition RendererFoundationDLL.h:481
Definition RendererFoundationDLL.h:404
Definition RendererFoundationDLL.h:411
Definition RendererFoundationDLL.h:425
Definition RendererFoundationDLL.h:439
Definition RendererFoundationDLL.h:488
This class provides functions to work on raw memory.
Definition MemoryUtils.h:26
static bool IsMainThread()
Helper function to check if the current thread is the main thread (e.g. the thread which initialized ...
Definition ThreadUtils_Posix.h:47
A custom enum implementation that allows to define the underlying storage type to control its memory ...
Definition Enum.h:37
Definition CommandEncoderState.h:10
Definition RenderTargetSetup.h:44
Definition RendererFoundationDLL.h:365
Definition RendererFoundationDLL.h:359
Enum
Definition RendererFoundationDLL.h:336
@ Discard
Buffer must be completely overwritten. No old data will be read. Data will not persist across frames.
Definition RendererFoundationDLL.h:337
A generic id class that holds an id combined of an instance index and a generation counter.
Definition Id.h:52
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54
Shader reflection of a single shader resource (texture, constant buffer, etc.).
Definition ShaderByteCode.h:77