16 {
17
18 D3D12_ROOT_PARAMETER parameters[3];
19
20
21 parameters[0].ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV;
22 parameters[0].Descriptor.ShaderRegister = 0;
24 parameters[0].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
25 int parameterCount = 1;
26
27 int numShaderViews = numTextureSamplers + numUAVs;
30 if (numTextureSamplers) {
31
32
33
34
35
36
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
43
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
52
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
61
62 shaderViewRanges[numTextureSamplers].BaseShaderRegister = 2 * numTextureSamplers;
63
64 shaderViewRanges[numTextureSamplers].RegisterSpace =
66
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
97
98 HRESULT hr = D3D12SerializeRootSignature(&rootDesc, D3D_ROOT_SIGNATURE_VERSION_1_0,
99 &rootSigBinary, &
error);
100
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));
112 SkDebugf(
"Failed to create root signature.\n");
113 return nullptr;
114 }
115
117 numTextureSamplers,
118 numUAVs));
119}
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
ID3D12Device * device() const
const uint8_t uint32_t uint32_t GError ** error