18 D3D12_ROOT_PARAMETER parameters[3];
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;
27 int numShaderViews = numTextureSamplers + numUAVs;
30 if (numTextureSamplers) {
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;
44 samplerRanges[
i].OffsetInDescriptorsFromTableStart =
45 D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND;
47 shaderViewRanges[
i].RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SRV;
48 shaderViewRanges[
i].NumDescriptors = 1;
49 shaderViewRanges[
i].BaseShaderRegister = 2 *
i + 1;
53 shaderViewRanges[
i].OffsetInDescriptorsFromTableStart =
54 D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND;
58 shaderViewRanges[numTextureSamplers].RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_UAV;
59 shaderViewRanges[numTextureSamplers].NumDescriptors = numUAVs;
62 shaderViewRanges[numTextureSamplers].BaseShaderRegister = 2 * numTextureSamplers;
64 shaderViewRanges[numTextureSamplers].RegisterSpace =
67 shaderViewRanges[numTextureSamplers].OffsetInDescriptorsFromTableStart =
68 D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND;
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;
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;
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;
98 HRESULT hr = D3D12SerializeRootSignature(&rootDesc, D3D_ROOT_SIGNATURE_VERSION_1_0,
99 &rootSigBinary, &
error);
102 SkDebugf(
"Failed to serialize root signature. Error: %s\n",
103 reinterpret_cast<char*
>(
error->GetBufferPointer()));
109 hr = gpu->
device()->CreateRootSignature(0, rootSigBinary->GetBufferPointer(),
110 rootSigBinary->GetBufferSize(), IID_PPV_ARGS(&rootSig));
112 SkDebugf(
"Failed to create root signature.\n");
123 : fRootSignature(
std::move(rootSig))
124 , fNumTextureSamplers(numTextureSamplers)
125 , fNumUAVs(numUAVs) {
129 return fNumTextureSamplers == numTextureSamplers && fNumUAVs == numUAVs;
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
ID3D12Device * device() const
bool isCompatible(int numTextureSamplers, int numUAVs) const
static sk_sp< GrD3DRootSignature > Make(GrD3DGpu *gpu, int numTextureSamplers, int numUAVs)
const uint8_t uint32_t uint32_t GError ** error