Nameless Engine
Loading...
Searching...
No Matches
DirectXPso.h
1#pragma once
2
3// Custom.
4#include "render/general/pipeline/Pipeline.h"
5#include "shader/hlsl/SpecialRootParameterSlot.hpp"
6#include "render/general/resource/frame/FrameResourceManager.h"
7#include "render/directx/resource/DirectXResource.h"
8
9// External.
10#include "directx/d3dx12.h"
11
12// OS.
13#include <wrl.h>
14
15namespace ne {
16 using namespace Microsoft::WRL;
17
18 class DirectXResource;
19 class DirectXRenderer;
20
22 class DirectXPso : public Pipeline {
23 // Renderer will ask us to bind global shader resource views.
24 friend class DirectXRenderer;
25
26 public:
30 ComPtr<ID3D12RootSignature> pRootSignature;
31
33 ComPtr<ID3D12PipelineState> pPso;
34
42 std::unordered_map<std::string, UINT> rootParameterIndices;
43
54 std::array<UINT, static_cast<unsigned int>(SpecialRootParameterSlot::SIZE)>
56
65 std::unordered_map<
66 UINT,
69
75 std::unordered_map<UINT, std::unique_ptr<ContinuousDirectXDescriptorRange>>
77
79 bool bIsReadyForUsage = false;
80 };
81
82 DirectXPso() = delete;
83 DirectXPso(const DirectXPso&) = delete;
84 DirectXPso& operator=(const DirectXPso&) = delete;
85
86 virtual ~DirectXPso() override;
87
98 static std::variant<std::shared_ptr<DirectXPso>, Error> createGraphicsPso(
101 std::unique_ptr<PipelineConfiguration> pPipelineConfiguration);
102
113 static std::variant<std::shared_ptr<DirectXPso>, Error> createComputePso(
114 Renderer* pRenderer, PipelineManager* pPipelineManager, const std::string& sComputeShaderName);
115
124 std::variant<unsigned int, Error> getRootParameterIndex(const std::string& sShaderResourceName);
125
131 std::pair<std::recursive_mutex, InternalResources>* getInternalResources() {
132 return &mtxInternalResources;
133 }
134
135 protected:
150 [[nodiscard]] virtual std::optional<Error> releaseInternalResources() override;
151
160 [[nodiscard]] virtual std::optional<Error> restoreInternalResources() override;
161
162 private:
170 explicit DirectXPso(
173 std::unique_ptr<PipelineConfiguration> pPipelineConfiguration);
174
185 const ComPtr<ID3D12GraphicsCommandList>& pCommandList, size_t iCurrentFrameResourceIndex) const {
186 // No need to lock internal resources mutex since the caller is expected to lock that mutex
187 // because this function is expected to be called inside of the `draw` function.
188
189 // Bind global SRVs.
190 for (const auto& [iRootParameterIndex, vResourcesToBind] :
191 mtxInternalResources.second.globalShaderResourceSrvs) {
192 // Set view.
193 pCommandList->SetGraphicsRootShaderResourceView(
194 iRootParameterIndex,
195 vResourcesToBind[iCurrentFrameResourceIndex]
196 ->getInternalResource()
197 ->GetGPUVirtualAddress());
198 }
199 }
200
210 [[nodiscard]] std::optional<Error> generateGraphicsPso();
211
221 [[nodiscard]] std::optional<Error> generateComputePso();
222
227 std::pair<std::recursive_mutex, InternalResources> mtxInternalResources;
228 };
229} // namespace ne
Definition: DirectXPso.h:22
static std::variant< std::shared_ptr< DirectXPso >, Error > createGraphicsPso(Renderer *pRenderer, PipelineManager *pPipelineManager, std::unique_ptr< PipelineConfiguration > pPipelineConfiguration)
Definition: DirectXPso.cpp:35
virtual std::optional< Error > restoreInternalResources() override
Definition: DirectXPso.cpp:136
std::optional< Error > generateGraphicsPso()
Definition: DirectXPso.cpp:150
static std::variant< std::shared_ptr< DirectXPso >, Error > createComputePso(Renderer *pRenderer, PipelineManager *pPipelineManager, const std::string &sComputeShaderName)
Definition: DirectXPso.cpp:53
std::pair< std::recursive_mutex, InternalResources > mtxInternalResources
Definition: DirectXPso.h:227
std::pair< std::recursive_mutex, InternalResources > * getInternalResources()
Definition: DirectXPso.h:131
std::variant< unsigned int, Error > getRootParameterIndex(const std::string &sShaderResourceName)
Definition: DirectXPso.cpp:70
virtual std::optional< Error > releaseInternalResources() override
Definition: DirectXPso.cpp:85
void bindGlobalShaderResourceViews(const ComPtr< ID3D12GraphicsCommandList > &pCommandList, size_t iCurrentFrameResourceIndex) const
Definition: DirectXPso.h:184
std::optional< Error > generateComputePso()
Definition: DirectXPso.cpp:369
Definition: DirectXRenderer.h:36
Definition: DirectXResource.h:32
Definition: Error.h:27
static constexpr unsigned int getFrameResourceCount()
Definition: FrameResourceManager.h:74
Definition: PipelineManager.h:98
Definition: Pipeline.h:20
const std::unique_ptr< PipelineConfiguration > pPipelineConfiguration
Definition: Pipeline.h:274
Renderer *const pRenderer
Definition: Pipeline.h:280
PipelineManager *const pPipelineManager
Definition: Pipeline.h:277
Definition: Renderer.h:43
Definition: DirectXPso.h:28
bool bIsReadyForUsage
Definition: DirectXPso.h:79
std::array< UINT, static_cast< unsigned int >(SpecialRootParameterSlot::SIZE)> vSpecialRootParameterIndices
Definition: DirectXPso.h:55
std::unordered_map< UINT, std::unique_ptr< ContinuousDirectXDescriptorRange > > descriptorTablesToBind
Definition: DirectXPso.h:76
std::unordered_map< std::string, UINT > rootParameterIndices
Definition: DirectXPso.h:42
ComPtr< ID3D12RootSignature > pRootSignature
Definition: DirectXPso.h:30
std::unordered_map< UINT, std::array< DirectXResource *, FrameResourceManager::getFrameResourceCount()> > globalShaderResourceSrvs
Definition: DirectXPso.h:68
ComPtr< ID3D12PipelineState > pPso
Definition: DirectXPso.h:33