Flutter Engine
The Flutter Engine
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
GrD3DRootSignature Class Reference

#include <GrD3DRootSignature.h>

Inheritance diagram for GrD3DRootSignature:
GrManagedResource SkNoncopyable

Public Types

enum class  ParamIndex { kConstantBufferView = 0 , kShaderViewDescriptorTable = 1 , kSamplerDescriptorTable = 2 , kLast = kSamplerDescriptorTable }
 

Public Member Functions

bool isCompatible (int numTextureSamplers, int numUAVs) const
 
ID3D12RootSignature * rootSignature () const
 
- Public Member Functions inherited from GrManagedResource
 GrManagedResource ()
 
virtual ~GrManagedResource ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Static Public Member Functions

static sk_sp< GrD3DRootSignatureMake (GrD3DGpu *gpu, int numTextureSamplers, int numUAVs)
 

Static Public Attributes

static constexpr unsigned int kParamIndexCount = (unsigned int)(ParamIndex::kLast) + 1
 

Detailed Description

Definition at line 16 of file GrD3DRootSignature.h.

Member Enumeration Documentation

◆ ParamIndex

enum class GrD3DRootSignature::ParamIndex
strong
Enumerator
kConstantBufferView 
kShaderViewDescriptorTable 
kSamplerDescriptorTable 
kLast 

Definition at line 20 of file GrD3DRootSignature.h.

20 {
21 kConstantBufferView = 0,
22 kShaderViewDescriptorTable = 1,
23 kSamplerDescriptorTable = 2,
24
25 kLast = kSamplerDescriptorTable
26 };

Member Function Documentation

◆ isCompatible()

bool GrD3DRootSignature::isCompatible ( int  numTextureSamplers,
int  numUAVs 
) const

Definition at line 128 of file GrD3DRootSignature.cpp.

128 {
129 return fNumTextureSamplers == numTextureSamplers && fNumUAVs == numUAVs;
130}

◆ Make()

sk_sp< GrD3DRootSignature > GrD3DRootSignature::Make ( GrD3DGpu gpu,
int  numTextureSamplers,
int  numUAVs 
)
static

Definition at line 15 of file GrD3DRootSignature.cpp.

16 {
17 // Just allocate enough space for 3 in case we need it.
18 D3D12_ROOT_PARAMETER parameters[3];
19
20 // The first will always be our uniforms
21 parameters[0].ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV;
22 parameters[0].Descriptor.ShaderRegister = 0;
23 parameters[0].Descriptor.RegisterSpace = GrSPIRVUniformHandler::kUniformDescriptorSet;
24 parameters[0].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
25 int parameterCount = 1;
26
27 int numShaderViews = numTextureSamplers + numUAVs;
28 AutoTArray<D3D12_DESCRIPTOR_RANGE> samplerRanges(numTextureSamplers);
29 AutoTArray<D3D12_DESCRIPTOR_RANGE> shaderViewRanges(numShaderViews);
30 if (numTextureSamplers) {
31 // Now handle the textures and samplers. We need a range for each sampler because of the
32 // interaction between how we set bindings and spirv-cross. Each binding value is used for
33 // the register value in the HLSL shader. So setting a binding of i for a texture will give
34 // it register t[i] in HLSL. We set the bindings of textures and samplers in pairs with the
35 // sampler at i and the corresponding texture at i+1. Thus no textures or samplers will have
36 // a contiguous range of HLSL registers so we must define a different range for each.
37 for (int i = 0; i < numTextureSamplers; ++i) {
38 samplerRanges[i].RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER;
39 samplerRanges[i].NumDescriptors = 1;
40 samplerRanges[i].BaseShaderRegister = 2 * i;
41 // Spirv-Cross uses the descriptor set as the space in HLSL
42 samplerRanges[i].RegisterSpace = GrSPIRVUniformHandler::kSamplerTextureDescriptorSet;
43 // In the descriptor table the descriptors will all be contiguous.
44 samplerRanges[i].OffsetInDescriptorsFromTableStart =
45 D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND;
46
47 shaderViewRanges[i].RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SRV;
48 shaderViewRanges[i].NumDescriptors = 1;
49 shaderViewRanges[i].BaseShaderRegister = 2 * i + 1;
50 // Spirv-Cross uses the descriptor set as the space in HLSL
51 shaderViewRanges[i].RegisterSpace = GrSPIRVUniformHandler::kSamplerTextureDescriptorSet;
52 // In the descriptor table the descriptors will all be contiguous.
53 shaderViewRanges[i].OffsetInDescriptorsFromTableStart =
54 D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND;
55 }
56 }
57 if (numUAVs) {
58 shaderViewRanges[numTextureSamplers].RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_UAV;
59 shaderViewRanges[numTextureSamplers].NumDescriptors = numUAVs;
60 // The assigned register range for the texture SRVs and samplers is from 0 to
61 // 2*(numTextureSamplers-1) + 1, so we start with the next register, 2*numTextureSamplers
62 shaderViewRanges[numTextureSamplers].BaseShaderRegister = 2 * numTextureSamplers;
63 // We share texture descriptor set
64 shaderViewRanges[numTextureSamplers].RegisterSpace =
66 // In the descriptor table the descriptors will all be contiguous.
67 shaderViewRanges[numTextureSamplers].OffsetInDescriptorsFromTableStart =
68 D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND;
69 }
70
71 if (numShaderViews) {
72 unsigned numDescriptorRanges = numUAVs ? numTextureSamplers + 1 : numTextureSamplers;
73 parameters[parameterCount].ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
74 parameters[parameterCount].DescriptorTable.NumDescriptorRanges = numDescriptorRanges;
75 parameters[parameterCount].DescriptorTable.pDescriptorRanges = shaderViewRanges.get();
76 parameters[parameterCount].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
77 parameterCount++;
78 }
79
80 if (numTextureSamplers) {
81 parameters[parameterCount].ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
82 parameters[parameterCount].DescriptorTable.NumDescriptorRanges = numTextureSamplers;
83 parameters[parameterCount].DescriptorTable.pDescriptorRanges = samplerRanges.get();
84 parameters[parameterCount].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
85 parameterCount++;
86 }
87
88 D3D12_ROOT_SIGNATURE_DESC rootDesc{};
89 rootDesc.NumParameters = parameterCount;
90 rootDesc.pParameters = parameters;
91 rootDesc.NumStaticSamplers = 0;
92 rootDesc.pStaticSamplers = nullptr;
93 rootDesc.Flags = D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT;
94
95 gr_cp<ID3DBlob> rootSigBinary;
97 // TODO: D3D Static Function
98 HRESULT hr = D3D12SerializeRootSignature(&rootDesc, D3D_ROOT_SIGNATURE_VERSION_1_0,
99 &rootSigBinary, &error);
100
101 if (!SUCCEEDED(hr)) {
102 SkDebugf("Failed to serialize root signature. Error: %s\n",
103 reinterpret_cast<char*>(error->GetBufferPointer()));
104 return nullptr;
105 }
106
108
109 hr = gpu->device()->CreateRootSignature(0, rootSigBinary->GetBufferPointer(),
110 rootSigBinary->GetBufferSize(), IID_PPV_ARGS(&rootSig));
111 if (!SUCCEEDED(hr)) {
112 SkDebugf("Failed to create root signature.\n");
113 return nullptr;
114 }
115
116 return sk_sp<GrD3DRootSignature>(new GrD3DRootSignature(std::move(rootSig),
117 numTextureSamplers,
118 numUAVs));
119}
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
ID3D12Device * device() const
Definition: GrD3DGpu.h:43
const uint8_t uint32_t uint32_t GError ** error
#define SUCCEEDED(hr)

◆ rootSignature()

ID3D12RootSignature * GrD3DRootSignature::rootSignature ( ) const
inline

Definition at line 31 of file GrD3DRootSignature.h.

31{ return fRootSignature.get(); }
T * get() const
Definition: GrD3DTypes.h:108

Member Data Documentation

◆ kParamIndexCount

constexpr unsigned int GrD3DRootSignature::kParamIndexCount = (unsigned int)(ParamIndex::kLast) + 1
inlinestaticconstexpr

Definition at line 27 of file GrD3DRootSignature.h.


The documentation for this class was generated from the following files: