Plasma Engine  2.0
Loading...
Searching...
No Matches
DeviceDX11.h
1
2#pragma once
3
4#include <Foundation/Types/Bitflags.h>
5#include <Foundation/Types/UniquePtr.h>
6#include <RendererDX11/RendererDX11DLL.h>
7#include <RendererFoundation/Device/Device.h>
8
9// TODO: This should not be included in a header, it exposes Windows.h to the outside
10#include <Foundation/Basics/Platform/Win/IncludeWindows.h>
11#include <dxgi.h>
12
13struct ID3D11Device;
14struct ID3D11Device3;
15struct ID3D11DeviceContext;
16struct ID3D11Debug;
17struct IDXGIFactory1;
18struct IDXGIAdapter1;
19struct IDXGIDevice1;
20struct ID3D11Resource;
21struct ID3D11Query;
22struct IDXGIAdapter;
23
24using plGALFormatLookupEntryDX11 = plGALFormatLookupEntry<DXGI_FORMAT, (DXGI_FORMAT)0>;
26
28class plQueryPoolDX11;
29
31class PL_RENDERERDX11_DLL plGALDeviceDX11 : public plGALDevice
32{
33private:
34 friend plInternal::NewInstance<plGALDevice> CreateDX11Device(plAllocator* pAllocator, const plGALDeviceCreationDescription& description);
36
37public:
38 virtual ~plGALDeviceDX11();
39
40public:
41 ID3D11Device* GetDXDevice() const;
42 ID3D11Device3* GetDXDevice3() const;
43 ID3D11DeviceContext* GetDXImmediateContext() const;
44 IDXGIFactory1* GetDXGIFactory() const;
45 plGALCommandEncoder* GetCommandEncoder() const;
46
47 plFenceQueueDX11& GetFenceQueue() const;
48 plQueryPoolDX11& GetQueryPool() const;
49
50 const plGALFormatLookupTableDX11& GetFormatLookupTable() const;
51
52 void ReportLiveGpuObjects();
53
54 void FlushDeadObjects();
55
56 // These functions need to be implemented by a render API abstraction
57protected:
58 // Init & shutdown functions
59
64 plResult InitPlatform(DWORD flags, IDXGIAdapter* pUsedAdapter);
65
66 virtual plStringView GetRendererPlatform() override;
67 virtual plResult InitPlatform() override;
68 virtual plResult ShutdownPlatform() override;
69
70 // Command encoder functions
71
72 virtual plGALCommandEncoder* BeginCommandsPlatform(const char* szName) override;
73 virtual void EndCommandsPlatform(plGALCommandEncoder* pPass) override;
74
75 virtual void FlushPlatform() override;
76
77
78 // State creation functions
79
80 virtual plGALBlendState* CreateBlendStatePlatform(const plGALBlendStateCreationDescription& Description) override;
81 virtual void DestroyBlendStatePlatform(plGALBlendState* pBlendState) override;
82
83 virtual plGALDepthStencilState* CreateDepthStencilStatePlatform(const plGALDepthStencilStateCreationDescription& Description) override;
84 virtual void DestroyDepthStencilStatePlatform(plGALDepthStencilState* pDepthStencilState) override;
85
86 virtual plGALRasterizerState* CreateRasterizerStatePlatform(const plGALRasterizerStateCreationDescription& Description) override;
87 virtual void DestroyRasterizerStatePlatform(plGALRasterizerState* pRasterizerState) override;
88
89 virtual plGALSamplerState* CreateSamplerStatePlatform(const plGALSamplerStateCreationDescription& Description) override;
90 virtual void DestroySamplerStatePlatform(plGALSamplerState* pSamplerState) override;
91
92
93 // Resource creation functions
94
95 virtual plGALShader* CreateShaderPlatform(const plGALShaderCreationDescription& Description) override;
96 virtual void DestroyShaderPlatform(plGALShader* pShader) override;
97
98 virtual plGALBuffer* CreateBufferPlatform(const plGALBufferCreationDescription& Description, plArrayPtr<const plUInt8> pInitialData) override;
99 virtual void DestroyBufferPlatform(plGALBuffer* pBuffer) override;
100
101 virtual plGALTexture* CreateTexturePlatform(const plGALTextureCreationDescription& Description, plArrayPtr<plGALSystemMemoryDescription> pInitialData) override;
102 virtual void DestroyTexturePlatform(plGALTexture* pTexture) override;
103
104 virtual plGALTexture* CreateSharedTexturePlatform(const plGALTextureCreationDescription& Description, plArrayPtr<plGALSystemMemoryDescription> pInitialData, plEnum<plGALSharedTextureType> sharedType, plGALPlatformSharedHandle handle) override;
105 virtual void DestroySharedTexturePlatform(plGALTexture* pTexture) override;
106
107 virtual plGALTextureResourceView* CreateResourceViewPlatform(plGALTexture* pResource, const plGALTextureResourceViewCreationDescription& Description) override;
108 virtual void DestroyResourceViewPlatform(plGALTextureResourceView* pResourceView) override;
109
110 virtual plGALBufferResourceView* CreateResourceViewPlatform(plGALBuffer* pResource, const plGALBufferResourceViewCreationDescription& Description) override;
111 virtual void DestroyResourceViewPlatform(plGALBufferResourceView* pResourceView) override;
112
113 virtual plGALRenderTargetView* CreateRenderTargetViewPlatform(plGALTexture* pTexture, const plGALRenderTargetViewCreationDescription& Description) override;
114 virtual void DestroyRenderTargetViewPlatform(plGALRenderTargetView* pRenderTargetView) override;
115
116 plGALTextureUnorderedAccessView* CreateUnorderedAccessViewPlatform(plGALTexture* pResource, const plGALTextureUnorderedAccessViewCreationDescription& Description) override;
117 virtual void DestroyUnorderedAccessViewPlatform(plGALTextureUnorderedAccessView* pUnorderedAccessView) override;
118
119 plGALBufferUnorderedAccessView* CreateUnorderedAccessViewPlatform(plGALBuffer* pResource, const plGALBufferUnorderedAccessViewCreationDescription& Description) override;
120 virtual void DestroyUnorderedAccessViewPlatform(plGALBufferUnorderedAccessView* pUnorderedAccessView) override;
121
122 // Other rendering creation functions
123
124 virtual plGALVertexDeclaration* CreateVertexDeclarationPlatform(const plGALVertexDeclarationCreationDescription& Description) override;
125 virtual void DestroyVertexDeclarationPlatform(plGALVertexDeclaration* pVertexDeclaration) override;
126
127 // GPU -> CPU query functions
128
129 virtual plEnum<plGALAsyncResult> GetTimestampResultPlatform(plGALTimestampHandle hTimestamp, plTime& out_result) override;
130 virtual plEnum<plGALAsyncResult> GetOcclusionResultPlatform(plGALOcclusionHandle hOcclusion, plUInt64& out_uiResult) override;
131 virtual plEnum<plGALAsyncResult> GetFenceResultPlatform(plGALFenceHandle hFence, plTime timeout) override;
132
133 // Swap chain functions
134
135 void PresentPlatform(const plGALSwapChain* pSwapChain, bool bVSync);
136
137 // Misc functions
138
139 virtual void BeginFramePlatform(plArrayPtr<plGALSwapChain*> swapchains, const plUInt64 uiAppFrame) override;
140 virtual void EndFramePlatform(plArrayPtr<plGALSwapChain*> swapchains) override;
141 virtual plUInt64 GetCurrentFramePlatform() const override;
142 virtual plUInt64 GetSafeFramePlatform() const override;
143
144 virtual void FillCapabilitiesPlatform() override;
145
146 virtual void WaitIdlePlatform() override;
147
148 virtual const plGALSharedTexture* GetSharedTexture(plGALTextureHandle hTexture) const override;
149
151
152private:
153 friend class plGALCommandEncoderImplDX11;
154
155 struct TempResourceType
156 {
157 enum Enum
158 {
159 Buffer,
160 Texture,
161
162 ENUM_COUNT
163 };
164 };
165
166 ID3D11Resource* FindTempBuffer(plUInt32 uiSize);
167 ID3D11Resource* FindTempTexture(plUInt32 uiWidth, plUInt32 uiHeight, plUInt32 uiDepth, plGALResourceFormat::Enum format);
168 void FreeTempResources(plUInt64 uiFrame);
169
170 void FillFormatLookupTable();
171
172
173 static constexpr plUInt32 FRAMES = 4;
174
175 ID3D11Device* m_pDevice = nullptr;
176 ID3D11Device3* m_pDevice3 = nullptr;
177 ID3D11DeviceContext* m_pImmediateContext;
178 ID3D11Debug* m_pDebug = nullptr;
179 IDXGIFactory1* m_pDXGIFactory = nullptr;
180 IDXGIAdapter1* m_pDXGIAdapter = nullptr;
181 IDXGIDevice1* m_pDXGIDevice = nullptr;
182
183 plUniquePtr<plFenceQueueDX11> m_pFenceQueue;
184 plUniquePtr<plQueryPoolDX11> m_pQueryPool;
185 plGALFormatLookupTableDX11 m_FormatLookupTable;
186
187 // NOLINTNEXTLINE
188 plUInt32 m_uiFeatureLevel; // D3D_FEATURE_LEVEL can't be forward declared
189
190 plUniquePtr<plGALCommandEncoderImplDX11> m_pCommandEncoderImpl;
191 plUniquePtr<plGALCommandEncoder> m_pCommandEncoder;
192
193 struct PerFrameData
194 {
195 plGALFenceHandle m_hFence = {};
196 plUInt64 m_uiFrame = -1;
197 };
198
199 PerFrameData m_PerFrameData[FRAMES];
200
201 plUInt64 m_uiFrameCounter = 1;
202 plUInt64 m_uiSafeFrame = 0;
203 plUInt8 m_uiCurrentPerFrameData = m_uiFrameCounter % FRAMES;
204
205 struct UsedTempResource
206 {
207 PL_DECLARE_POD_TYPE();
208
209 ID3D11Resource* m_pResource;
210 plUInt64 m_uiFrame;
211 plUInt32 m_uiHash;
212 };
213
215 plDeque<UsedTempResource, plLocalAllocatorWrapper> m_UsedTempResources[TempResourceType::ENUM_COUNT];
216
217 struct GPUTimingScope* m_pFrameTimingScope = nullptr;
218 struct GPUTimingScope* m_pPipelineTimingScope = nullptr;
219 struct GPUTimingScope* m_pPassTimingScope = nullptr;
220};
221
222#include <RendererDX11/Device/Implementation/DeviceDX11_inl.h>
Base class for all memory allocators.
Definition Allocator.h:23
This class encapsulates an array and it's size. It is recommended to use this class instead of plain ...
Definition ArrayPtr.h:37
Definition Deque.h:270
Definition FencePoolDX11.h:30
Definition State.h:7
Definition Buffer.h:8
Definition ResourceView.h:30
Definition UnorderedAccesView.h:28
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
The plRenderDevice class is the primary interface for interactions with rendering APIs It contains a ...
Definition Device.h:19
Definition ResourceFormats.h:136
Definition State.h:33
Definition RenderTargetView.h:8
Definition State.h:46
Definition Shader.h:7
Optional interface for plGALTexture if it was created via plGALDevice::CreateSharedTexture....
Definition Texture.h:33
Definition SwapChain.h:11
Definition RendererFoundationDLL.h:411
Definition Texture.h:8
Definition ResourceView.h:11
Definition UnorderedAccesView.h:11
Definition VertexDeclaration.h:8
Definition Map.h:408
Pool for GPU queries.
Definition QueryPoolDX11.h:11
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
A Unique ptr manages an object and destroys that object when it goes out of scope....
Definition UniquePtr.h:10
A comparer object is used in sorting algorithms to compare to objects of the same type.
Definition Comparer.h:7
A custom enum implementation that allows to define the underlying storage type to control its memory ...
Definition Enum.h:37
Definition Descriptors.h:70
Definition Descriptors.h:169
Definition Descriptors.h:211
Definition Descriptors.h:39
Definition Descriptors.h:277
Describes the settings for a new rasterizer state. See plGALDevice::CreateRasterizerState.
Definition Descriptors.h:105
Definition Descriptors.h:220
Definition Descriptors.h:118
Definition Descriptors.h:44
Definition Descriptors.h:177
Definition Descriptors.h:153
A generic id class that holds an id combined of an instance index and a generation counter.
Definition Id.h:52
Definition Allocator_inl.h:18
Definition AllocatorWrapper.h:30
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54
The time class encapsulates a double value storing the time in seconds.
Definition Time.h:12