Blowbox 2017
A 3D Game Engine by Riko Ophorst using DirectX 12
root_signature.h
1 #pragma once
2 
3 #include "util/string.h"
4 #include "d3d12_includes.h"
5 
6 #define ROOT_SIGNATURE_MAX_PARAMETERS 64
7 #define ROOT_SIGNATURE_MAX_STATIC_SAMPLERS 64
8 
9 namespace blowbox
10 {
11  class RootSignature;
12 
21  class RootParameter : public D3D12_ROOT_PARAMETER
22  {
23  friend class RootSignature;
24  protected:
26  RootParameter();
27 
32  RootParameter(RootSignature* owning_signature);
33 
36 
41  void Initialize(RootSignature* owning_signature);
42 
44  void Clear();
45 
46  public:
53  void InitAsConstants(UINT shader_register, UINT num_dwords, D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL);
54 
60  void InitAsConstantBuffer(UINT shader_register, D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL);
61 
67  void InitAsBufferSRV(UINT shader_register, D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL);
68 
74  void InitAsBufferUAV(UINT shader_register, D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL);
75 
83  void InitAsDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE type, UINT count, UINT shader_register, D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL);
84 
91  void InitAsDescriptorTable(UINT range_count, D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL);
92 
101  void SetDescriptorRangeInTable(UINT range_index, D3D12_DESCRIPTOR_RANGE_TYPE type, UINT shader_register, UINT count, UINT space = 0);
102 
103  private:
105  };
106 
107 
122  {
123  friend class RootParameter;
124  public:
126  RootSignature();
127 
129  ~RootSignature();
130 
136  void Create(UINT num_root_parameters, UINT num_static_samplers);
137 
143  void Finalize(const WString& name, D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE);
144 
146  RootParameter& operator[](UINT i);
147 
149  const RootParameter& operator[](UINT i) const;
150 
152  ID3D12RootSignature* Get() const { return root_signature_; }
153 
155  operator ID3D12RootSignature*() const { return root_signature_; }
156 
158  ID3D12RootSignature* operator->() const { return root_signature_; }
159 
166  void InitStaticSampler(const D3D12_STATIC_SAMPLER_DESC& static_sampler_desc, D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL);
167 
174  void InitStaticSampler(UINT shader_register, const D3D12_SAMPLER_DESC& sampler_desc, D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL);
175 
176  protected:
181  void ConfirmInitializedParameter();
182 
183  private:
184  bool finalized_;
189  ID3D12RootSignature* root_signature_;
190  RootParameter root_parameters_[ROOT_SIGNATURE_MAX_PARAMETERS];
191  D3D12_STATIC_SAMPLER_DESC static_samplers_[ROOT_SIGNATURE_MAX_STATIC_SAMPLERS];
192  };
193 }
UINT num_initialized_static_samplers_
The number of currently initialized static samplers.
Definition: root_signature.h:188
void SetDescriptorRangeInTable(UINT range_index, D3D12_DESCRIPTOR_RANGE_TYPE type, UINT shader_register, UINT count, UINT space=0)
Sets a descriptor range inside of this RootParameter (which should have been initialized as a Descrip...
Definition: root_signature.cc:286
UINT num_root_parameters_
The number of RootParameters in this RootSignature.
Definition: root_signature.h:185
void InitAsConstants(UINT shader_register, UINT num_dwords, D3D12_SHADER_VISIBILITY visibility=D3D12_SHADER_VISIBILITY_ALL)
Initializes this RootParameter as root constants.
Definition: root_signature.cc:228
RootParameter()
Constructs a RootParameter.
Definition: root_signature.cc:191
UINT num_initialized_root_parameters_
The number of currently initialized RootParameters.
Definition: root_signature.h:186
void InitAsConstantBuffer(UINT shader_register, D3D12_SHADER_VISIBILITY visibility=D3D12_SHADER_VISIBILITY_ALL)
Initializes this RootParameter as a root constant buffer.
Definition: root_signature.cc:239
Wraps the ID3D12RootSignature object.
Definition: root_signature.h:121
ID3D12RootSignature * operator->() const
Overload the pointer operator to access the underlying ID3D12RootSignature.
Definition: root_signature.h:158
bool finalized_
Whether the RootSignature has been finalized.
Definition: root_signature.h:184
void Initialize(RootSignature *owning_signature)
Initializes the root parameter.
Definition: root_signature.cc:210
void InitAsDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE type, UINT count, UINT shader_register, D3D12_SHADER_VISIBILITY visibility=D3D12_SHADER_VISIBILITY_ALL)
Initializes this RootParameter as a descriptor range (actually it gets initialized as a descriptor ta...
Definition: root_signature.cc:269
eastl::wstring WString
Typedef for wrapping the EASTL wstring.
Definition: string.h:20
~RootParameter()
Destructs this RootParameter.
Definition: root_signature.cc:204
ID3D12RootSignature * root_signature_
The underlying ID3D12RootSignature.
Definition: root_signature.h:189
void InitAsBufferUAV(UINT shader_register, D3D12_SHADER_VISIBILITY visibility=D3D12_SHADER_VISIBILITY_ALL)
Initializes this RootParameter as a root UAV buffer.
Definition: root_signature.cc:259
void InitAsBufferSRV(UINT shader_register, D3D12_SHADER_VISIBILITY visibility=D3D12_SHADER_VISIBILITY_ALL)
Initializes this RootParameter as a root SRV buffer.
Definition: root_signature.cc:249
RootSignature * owning_signature_
The RootSignature that owns this RootParameter.
Definition: root_signature.h:104
The main Blowbox namespace.
Definition: image.cc:8
void InitAsDescriptorTable(UINT range_count, D3D12_SHADER_VISIBILITY visibility=D3D12_SHADER_VISIBILITY_ALL)
Initializes this RootParameter as a descriptor table.
Definition: root_signature.cc:277
UINT num_static_samplers_
The number of static samplers in this RootSignature.
Definition: root_signature.h:187
ID3D12RootSignature * Get() const
Definition: root_signature.h:152
Makes it easy to configure a D3D12_ROOT_PARAMETER.
Definition: root_signature.h:21
void Clear()
Clears the root parameter.
Definition: root_signature.cc:217