Plasma Engine  2.0
Loading...
Searching...
No Matches
CommandEncoderImplDX11.h
1
2#pragma once
3
4#include <Foundation/Types/Bitflags.h>
5#include <RendererDX11/RendererDX11DLL.h>
6#include <RendererFoundation/CommandEncoder/CommandEncoderPlatformInterface.h>
7#include <RendererFoundation/Resources/RenderTargetSetup.h>
8
9struct ID3D11DeviceChild;
10struct ID3D11DeviceContext;
11struct ID3DUserDefinedAnnotation;
12struct ID3D11RenderTargetView;
13struct ID3D11DepthStencilView;
14struct ID3D11Buffer;
15struct ID3D11ShaderResourceView;
16struct ID3D11UnorderedAccessView;
17struct ID3D11SamplerState;
18struct ID3D11Query;
19
20class plGALDeviceDX11;
21
23{
24public:
27
28 // plGALCommandEncoderCommonPlatformInterface
29 // State setting functions
30
31 virtual void SetShaderPlatform(const plGALShader* pShader) override;
32
33 virtual void SetConstantBufferPlatform(const plShaderResourceBinding& binding, const plGALBuffer* pBuffer) override;
34 virtual void SetSamplerStatePlatform(const plShaderResourceBinding& binding, const plGALSamplerState* pSamplerState) override;
35 virtual void SetResourceViewPlatform(const plShaderResourceBinding& binding, const plGALTextureResourceView* pResourceView) override;
36 virtual void SetResourceViewPlatform(const plShaderResourceBinding& binding, const plGALBufferResourceView* pResourceView) override;
37 virtual void SetUnorderedAccessViewPlatform(const plShaderResourceBinding& binding, const plGALTextureUnorderedAccessView* pUnorderedAccessView) override;
38 virtual void SetUnorderedAccessViewPlatform(const plShaderResourceBinding& binding, const plGALBufferUnorderedAccessView* pUnorderedAccessView) override;
39 virtual void SetPushConstantsPlatform(plArrayPtr<const plUInt8> data) override;
40
41 // GPU -> CPU query functions
42
43 virtual plGALTimestampHandle InsertTimestampPlatform() override;
44 virtual plGALOcclusionHandle BeginOcclusionQueryPlatform(plEnum<plGALQueryType> type) override;
45 virtual void EndOcclusionQueryPlatform(plGALOcclusionHandle hOcclusion) override;
46 virtual plGALFenceHandle InsertFencePlatform() override;
47
48 // Resource update functions
49
50 virtual void ClearUnorderedAccessViewPlatform(const plGALTextureUnorderedAccessView* pUnorderedAccessView, plVec4 vClearValues) override;
51 virtual void ClearUnorderedAccessViewPlatform(const plGALBufferUnorderedAccessView* pUnorderedAccessView, plVec4 vClearValues) override;
52
53 virtual void ClearUnorderedAccessViewPlatform(const plGALTextureUnorderedAccessView* pUnorderedAccessView, plVec4U32 vClearValues) override;
54 virtual void ClearUnorderedAccessViewPlatform(const plGALBufferUnorderedAccessView* pUnorderedAccessView, plVec4U32 vClearValues) override;
55
56 virtual void CopyBufferPlatform(const plGALBuffer* pDestination, const plGALBuffer* pSource) override;
57 virtual void CopyBufferRegionPlatform(const plGALBuffer* pDestination, plUInt32 uiDestOffset, const plGALBuffer* pSource, plUInt32 uiSourceOffset, plUInt32 uiByteCount) override;
58
59 virtual void UpdateBufferPlatform(const plGALBuffer* pDestination, plUInt32 uiDestOffset, plArrayPtr<const plUInt8> sourceData, plGALUpdateMode::Enum updateMode) override;
60
61 virtual void CopyTexturePlatform(const plGALTexture* pDestination, const plGALTexture* pSource) override;
62 virtual void CopyTextureRegionPlatform(const plGALTexture* pDestination, const plGALTextureSubresource& destinationSubResource, const plVec3U32& vDestinationPoint, const plGALTexture* pSource, const plGALTextureSubresource& sourceSubResource, const plBoundingBoxu32& box) override;
63
64 virtual void UpdateTexturePlatform(const plGALTexture* pDestination, const plGALTextureSubresource& destinationSubResource,
65 const plBoundingBoxu32& destinationBox, const plGALSystemMemoryDescription& sourceData) override;
66
67 virtual void ResolveTexturePlatform(const plGALTexture* pDestination, const plGALTextureSubresource& destinationSubResource,
68 const plGALTexture* pSource, const plGALTextureSubresource& sourceSubResource) override;
69
70 virtual void ReadbackTexturePlatform(const plGALTexture* pTexture) override;
71
72 virtual void CopyTextureReadbackResultPlatform(const plGALTexture* pTexture, plArrayPtr<plGALTextureSubresource> sourceSubResource, plArrayPtr<plGALSystemMemoryDescription> targetData) override;
73
74 virtual void GenerateMipMapsPlatform(const plGALTextureResourceView* pResourceView) override;
75
76 // Misc
77
78 virtual void FlushPlatform() override;
79
80 // Debug helper functions
81
82 virtual void PushMarkerPlatform(const char* szMarker) override;
83 virtual void PopMarkerPlatform() override;
84 virtual void InsertEventMarkerPlatform(const char* szMarker) override;
85
86 // plGALCommandEncoderComputePlatformInterface
87 // Dispatch
88 virtual void BeginComputePlatform() override;
89 virtual void EndComputePlatform() override;
90
91 virtual plResult DispatchPlatform(plUInt32 uiThreadGroupCountX, plUInt32 uiThreadGroupCountY, plUInt32 uiThreadGroupCountZ) override;
92 virtual plResult DispatchIndirectPlatform(const plGALBuffer* pIndirectArgumentBuffer, plUInt32 uiArgumentOffsetInBytes) override;
93
94 // plGALCommandEncoderRenderPlatformInterface
95 virtual void BeginRenderingPlatform(const plGALRenderingSetup& renderingSetup) override;
96 virtual void EndRenderingPlatform() override;
97
98 // Draw functions
99
100 virtual void ClearPlatform(const plColor& clearColor, plUInt32 uiRenderTargetClearMask, bool bClearDepth, bool bClearStencil, float fDepthClear, plUInt8 uiStencilClear) override;
101
102 virtual plResult DrawPlatform(plUInt32 uiVertexCount, plUInt32 uiStartVertex) override;
103 virtual plResult DrawIndexedPlatform(plUInt32 uiIndexCount, plUInt32 uiStartIndex) override;
104 virtual plResult DrawIndexedInstancedPlatform(plUInt32 uiIndexCountPerInstance, plUInt32 uiInstanceCount, plUInt32 uiStartIndex) override;
105 virtual plResult DrawIndexedInstancedIndirectPlatform(const plGALBuffer* pIndirectArgumentBuffer, plUInt32 uiArgumentOffsetInBytes) override;
106 virtual plResult DrawInstancedPlatform(plUInt32 uiVertexCountPerInstance, plUInt32 uiInstanceCount, plUInt32 uiStartVertex) override;
107 virtual plResult DrawInstancedIndirectPlatform(const plGALBuffer* pIndirectArgumentBuffer, plUInt32 uiArgumentOffsetInBytes) override;
108
109 // State functions
110
111 virtual void SetIndexBufferPlatform(const plGALBuffer* pIndexBuffer) override;
112 virtual void SetVertexBufferPlatform(plUInt32 uiSlot, const plGALBuffer* pVertexBuffer) override;
113 virtual void SetVertexDeclarationPlatform(const plGALVertexDeclaration* pVertexDeclaration) override;
114 virtual void SetPrimitiveTopologyPlatform(plGALPrimitiveTopology::Enum topology) override;
115
116 virtual void SetBlendStatePlatform(const plGALBlendState* pBlendState, const plColor& blendFactor, plUInt32 uiSampleMask) override;
117 virtual void SetDepthStencilStatePlatform(const plGALDepthStencilState* pDepthStencilState, plUInt8 uiStencilRefValue) override;
118 virtual void SetRasterizerStatePlatform(const plGALRasterizerState* pRasterizerState) override;
119
120 virtual void SetViewportPlatform(const plRectFloat& rect, float fMinDepth, float fMaxDepth) override;
121 virtual void SetScissorRectPlatform(const plRectU32& rect) override;
122
123private:
124 friend class plGALDeviceDX11;
125
126 bool UnsetResourceViews(const plGALResourceBase* pResource);
127 bool UnsetUnorderedAccessViews(const plGALResourceBase* pResource);
128 plResult FlushDeferredStateChanges();
129
130 plGALDeviceDX11& m_GALDeviceDX11;
131 plGALCommandEncoder* m_pOwner = nullptr;
132
133 ID3D11DeviceContext* m_pDXContext = nullptr;
134 ID3DUserDefinedAnnotation* m_pDXAnnotation = nullptr;
135
136 // Bound objects for deferred state flushes
138 plUInt8 m_uiTessellationPatchControlPoints = 0;
139
140 ID3D11Buffer* m_pBoundConstantBuffers[PL_GAL_MAX_CONSTANT_BUFFER_COUNT] = {};
141 plGAL::ModifiedRange m_BoundConstantBuffersRange[plGALShaderStage::ENUM_COUNT];
142
143 plHybridArray<ID3D11ShaderResourceView*, 16> m_pBoundShaderResourceViews[plGALShaderStage::ENUM_COUNT] = {};
144 plHybridArray<const plGALResourceBase*, 16> m_ResourcesForResourceViews[plGALShaderStage::ENUM_COUNT];
145 plGAL::ModifiedRange m_BoundShaderResourceViewsRange[plGALShaderStage::ENUM_COUNT];
146
147 plHybridArray<ID3D11UnorderedAccessView*, 16> m_BoundUnorderedAccessViews;
148 plHybridArray<const plGALResourceBase*, 16> m_ResourcesForUnorderedAccessViews;
149 plGAL::ModifiedRange m_BoundUnorderedAccessViewsRange;
150
151 ID3D11SamplerState* m_pBoundSamplerStates[plGALShaderStage::ENUM_COUNT][PL_GAL_MAX_SAMPLER_COUNT] = {};
152 plGAL::ModifiedRange m_BoundSamplerStatesRange[plGALShaderStage::ENUM_COUNT];
153
154 ID3D11DeviceChild* m_pBoundShaders[plGALShaderStage::ENUM_COUNT] = {};
155
156 plGALRenderTargetSetup m_RenderTargetSetup;
157 ID3D11RenderTargetView* m_pBoundRenderTargets[PL_GAL_MAX_RENDERTARGET_COUNT] = {};
158 plUInt32 m_uiBoundRenderTargetCount = 0;
159 ID3D11DepthStencilView* m_pBoundDepthStencilTarget = nullptr;
160
161 ID3D11Buffer* m_pBoundVertexBuffers[PL_GAL_MAX_VERTEX_BUFFER_COUNT] = {};
162 plGAL::ModifiedRange m_BoundVertexBuffersRange;
163
164 plUInt32 m_VertexBufferStrides[PL_GAL_MAX_VERTEX_BUFFER_COUNT] = {};
165 plUInt32 m_VertexBufferOffsets[PL_GAL_MAX_VERTEX_BUFFER_COUNT] = {};
166 void SetResourceView(const plShaderResourceBinding& binding, const plGALResourceBase* pResource, ID3D11ShaderResourceView* pResourceViewDX11);
167 void SetUnorderedAccessView(const plShaderResourceBinding& binding, ID3D11UnorderedAccessView* pUnorderedAccessViewDX11, plGALResourceBase* pResource);
168};
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
Definition State.h:7
Definition Buffer.h:8
Definition ResourceView.h:30
Definition UnorderedAccesView.h:28
Definition CommandEncoderPlatformInterface.h:13
Definition CommandEncoder.h:11
Definition CommandEncoderImplDX11.h:23
Definition State.h:20
The DX11 device implementation of the graphics abstraction layer.
Definition DeviceDX11.h:32
Definition State.h:33
Definition RenderTargetSetup.h:19
Definition Resource.h:9
Definition State.h:46
Definition Shader.h:7
Definition Texture.h:8
Definition ResourceView.h:11
Definition UnorderedAccesView.h:11
Definition VertexDeclaration.h:8
A hybrid array uses in-place storage to handle the first few elements without any allocation....
Definition HybridArray.h:12
A custom enum implementation that allows to define the underlying storage type to control its memory ...
Definition Enum.h:37
Definition RendererFoundationDLL.h:502
Definition RenderTargetSetup.h:44
Definition RendererFoundationDLL.h:365
Definition RendererFoundationDLL.h:359
Enum
Definition RendererFoundationDLL.h:336
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