BRE12
PSOManager.h
1 #pragma once
2 
3 #include <d3d12.h>
4 #include <mutex>
5 #include <tbb/concurrent_unordered_set.h>
6 
7 #include <DXUtils/D3DFactory.h>
8 
9 namespace BRE {
10 // To create/get/erase pipeline state objects
11 class PSOManager {
12 public:
13  PSOManager() = delete;
14  ~PSOManager() = delete;
15  PSOManager(const PSOManager&) = delete;
16  const PSOManager& operator=(const PSOManager&) = delete;
17  PSOManager(PSOManager&&) = delete;
18  PSOManager& operator=(PSOManager&&) = delete;
19 
20  static void EraseAll() noexcept;
21 
22  struct PSOCreationData {
23  PSOCreationData() = default;
24  ~PSOCreationData() = default;
25  PSOCreationData(const PSOCreationData&) = delete;
26  const PSOCreationData& operator=(const PSOCreationData&) = delete;
27  PSOCreationData(PSOCreationData&&) = delete;
28  PSOCreationData& operator=(PSOCreationData&&) = delete;
29 
30  bool IsDataValid() const noexcept;
31 
32  std::vector<D3D12_INPUT_ELEMENT_DESC> mInputLayoutDescriptors{};
33 
34  ID3D12RootSignature* mRootSignature{ nullptr };
35 
36  // If a shader bytecode is not valid, then we do not load it.
37  D3D12_SHADER_BYTECODE mVertexShaderBytecode{ 0UL };
38  D3D12_SHADER_BYTECODE mGeometryShaderBytecode{ 0UL };
39  D3D12_SHADER_BYTECODE mDomainShaderBytecode{ 0UL };
40  D3D12_SHADER_BYTECODE mHullShaderBytecode{ 0UL };
41  D3D12_SHADER_BYTECODE mPixelShaderBytecode{ 0UL };
42 
43  D3D12_BLEND_DESC mBlendDescriptor = D3DFactory::GetDisabledBlendDesc();
44  D3D12_RASTERIZER_DESC mRasterizerDescriptor = D3DFactory::GetDefaultRasterizerDesc();
45  D3D12_DEPTH_STENCIL_DESC mDepthStencilDescriptor = D3DFactory::GetDefaultDepthStencilDesc();
46  std::uint32_t mNumRenderTargets{ 0U };
47  DXGI_FORMAT mRenderTargetFormats[D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT]{ DXGI_FORMAT_UNKNOWN };
48  DXGI_SAMPLE_DESC mSampleDescriptor{ 1U, 0U };
49  std::uint32_t mSampleMask{ UINT_MAX };
50  D3D12_PRIMITIVE_TOPOLOGY_TYPE mPrimitiveTopologyType{ D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE };
51  };
52 
53  // Preconditions:
54  // - "psoCreationData" must be valid
55  static ID3D12PipelineState& CreateGraphicsPSO(const PSOManager::PSOCreationData& psoCreationData) noexcept;
56 
57 private:
58  static ID3D12PipelineState& CreateGraphicsPSOByDescriptor(const D3D12_GRAPHICS_PIPELINE_STATE_DESC& psoDescriptor) noexcept;
59 
61  static PSOs mPSOs;
62 
63  static std::mutex mMutex;
64 };
65 
66 }
67 
Definition: Camera.cpp:8
Definition: PSOManager.h:11
Definition: concurrent_unordered_set.h:58
Definition: PSOManager.h:22