Blowbox 2017
A 3D Game Engine by Riko Ophorst using DirectX 12
pipeline_state.h
1 #pragma once
2 
3 #include "util/unordered_map.h"
4 #include "util/string.h"
5 
6 #include "renderer/root_signature.h"
7 
8 namespace blowbox
9 {
10  class Shader;
11 
20  class PSO
21  {
22  public:
24  PSO() : root_signature_(nullptr), pso_(nullptr) {}
25 
30  void SetRootSignature(RootSignature& root_signature) { root_signature_ = &root_signature; }
31 
34 
36  ID3D12PipelineState* operator->() { return pso_; }
37 
39  virtual void Finalize() = 0;
40 
42  void Destroy();
43 
45  ID3D12PipelineState* GetPSO() const { return pso_; }
46 
47  protected:
48  ID3D12PipelineState* pso_;
50  };
51 
61  class GraphicsPSO : public PSO
62  {
63  public:
65  GraphicsPSO();
66 
68  ~GraphicsPSO();
69 
70  public:
75  void SetBlendState(const D3D12_BLEND_DESC& blend_desc);
76 
81  void SetRasterizerState(const D3D12_RASTERIZER_DESC& rasterizer_desc);
82 
87  void SetDepthStencilState(const D3D12_DEPTH_STENCIL_DESC& depth_stencil_desc);
88 
93  void SetSampleMask(UINT sample_mask);
94 
99  void SetPrimitiveTopologyType(D3D12_PRIMITIVE_TOPOLOGY_TYPE topology_type);
100 
108  void SetRenderTargetFormat(DXGI_FORMAT rtv_format, DXGI_FORMAT dsv_format, UINT msaa_count = 1, UINT msaa_quality = 0);
109 
118  void SetRenderTargetFormats(UINT num_rtvs, const DXGI_FORMAT* rtv_formats, DXGI_FORMAT dsv_format, UINT msaa_count = 1, UINT msaa_quality = 0);
119 
125  void SetInputLayout(UINT num_elements, const D3D12_INPUT_ELEMENT_DESC* input_element_descs);
126 
131  void SetPrimitiveRestart(D3D12_INDEX_BUFFER_STRIP_CUT_VALUE ib_props);
132 
137  void SetVertexShader(const D3D12_SHADER_BYTECODE& binary) { pso_desc_.VS = binary; }
138 
143  void SetPixelShader(const D3D12_SHADER_BYTECODE& binary) { pso_desc_.PS = binary; }
144 
149  void SetGeometryShader(const D3D12_SHADER_BYTECODE& binary) { pso_desc_.GS = binary; }
150 
155  void SetHullShader(const D3D12_SHADER_BYTECODE& binary) { pso_desc_.HS = binary; }
156 
161  void SetDomainShader(const D3D12_SHADER_BYTECODE& binary) { pso_desc_.DS = binary; }
162 
164  void Finalize() override;
165  protected:
166  D3D12_GRAPHICS_PIPELINE_STATE_DESC pso_desc_;
167  D3D12_INPUT_ELEMENT_DESC input_element_descs_[16];
168  };
169 
179  class ComputePSO : public PSO
180  {
181  public:
183  ComputePSO();
185  ~ComputePSO();
186 
187  public:
193  void SetComputeShader(const void* binary, size_t size) { pso_desc_.CS = CD3DX12_SHADER_BYTECODE(binary, size); }
194 
199  void SetComputeShader(const D3D12_SHADER_BYTECODE& binary) { pso_desc_.CS = binary; }
200 
202  void Finalize() override;
203  protected:
204  D3D12_COMPUTE_PIPELINE_STATE_DESC pso_desc_;
205  };
206 }
ID3D12PipelineState * operator->()
Pointer operator overload which returns the underlying PSO.
Definition: pipeline_state.h:36
RootSignature & GetRootSignature()
Definition: pipeline_state.h:33
The base PipelineStateObject.
Definition: pipeline_state.h:20
void SetComputeShader(const void *binary, size_t size)
Sets the compute shader on this ComputePSO.
Definition: pipeline_state.h:193
D3D12_GRAPHICS_PIPELINE_STATE_DESC pso_desc_
The PSO description.
Definition: pipeline_state.h:166
void SetRootSignature(RootSignature &root_signature)
Sets the root signature in the PSO.
Definition: pipeline_state.h:30
Wraps the PipelineStateObject for graphics pipelines.
Definition: pipeline_state.h:61
void SetGeometryShader(const D3D12_SHADER_BYTECODE &binary)
Sets this PSO's geometry shader.
Definition: pipeline_state.h:149
PSO()
Constructs the PSO.
Definition: pipeline_state.h:24
Wraps the ID3D12RootSignature object.
Definition: root_signature.h:121
void Destroy()
Destroys the PSO.
Definition: pipeline_state.cc:10
void SetDomainShader(const D3D12_SHADER_BYTECODE &binary)
Sets this PSO's domain shader.
Definition: pipeline_state.h:161
Manages the PipelineStateObject for compute pipelines.
Definition: pipeline_state.h:179
virtual void Finalize()=0
Finalizes the PSO - it actually makes it ready for use.
The main Blowbox namespace.
Definition: image.cc:8
void SetPixelShader(const D3D12_SHADER_BYTECODE &binary)
Sets this PSO's pixel shader.
Definition: pipeline_state.h:143
ID3D12PipelineState * GetPSO() const
Definition: pipeline_state.h:45
void SetComputeShader(const D3D12_SHADER_BYTECODE &binary)
Sets the compute shader on this ComputePSO.
Definition: pipeline_state.h:199
ID3D12PipelineState * pso_
The underlying PSO object.
Definition: pipeline_state.h:48
RootSignature * root_signature_
The root signature that is bound to this PSO.
Definition: pipeline_state.h:49
void SetHullShader(const D3D12_SHADER_BYTECODE &binary)
Sets this PSO's hull shader.
Definition: pipeline_state.h:155
void SetVertexShader(const D3D12_SHADER_BYTECODE &binary)
Sets this PSO's vertex shader.
Definition: pipeline_state.h:137
D3D12_COMPUTE_PIPELINE_STATE_DESC pso_desc_
The PSO description.
Definition: pipeline_state.h:204