Creating Root Signature failed after changing version 1.1

Viewed 31

I mimimized my code to the problem part. I used to create root signature version 1.0 with no problem. Then I tried to upgrade my code to compatible with root signature version 1.1 if the hardware support.

   D3D12_ROOT_DESCRIPTOR1 CBV1rootDescriptor;
   CBV1rootDescriptor.ShaderRegister = 0;
   CBV1rootDescriptor.RegisterSpace = 0;
   CBV1rootDescriptor.Flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE;

   D3D12_ROOT_DESCRIPTOR1 CBV2rootDescriptor;
   CBV2rootDescriptor.ShaderRegister = 1;
   CBV2rootDescriptor.RegisterSpace = 0;
   CBV1rootDescriptor.Flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE;

   D3D12_ROOT_PARAMETER1 rootParam[2];
   rootParam[0].ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV;
   rootParam[0].Descriptor = CBV1rootDescriptor;
   rootParam[0].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;

   rootParam[1].ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV;
   rootParam[1].Descriptor = CBV2rootDescriptor;
   rootParam[1].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;

   D3D12_FEATURE_DATA_ROOT_SIGNATURE featureData = {};
   featureData.HighestVersion = D3D_ROOT_SIGNATURE_VERSION_1_1;
   if (FAILED(device->CheckFeatureSupport(D3D12_FEATURE_ROOT_SIGNATURE, &featureData, sizeof(featureData))))
   {
       featureData.HighestVersion = D3D_ROOT_SIGNATURE_VERSION_1_0;
   }

   D3D12_ROOT_SIGNATURE_DESC1 rootSigDesc = {};
   rootSigDesc.NumParameters = _countof(rootParam);
   rootSigDesc.pParameters = rootParam;
   rootSigDesc.NumStaticSamplers = 0;
   rootSigDesc.pStaticSamplers = nullptr;
   rootSigDesc.Flags = D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT;

   D3D12_VERSIONED_ROOT_SIGNATURE_DESC VersionedrootSigDesc = {};
   VersionedrootSigDesc.Version = featureData.HighestVersion;
   VersionedrootSigDesc.Desc_1_1 = rootSigDesc;

   ID3DBlob* serializedRootSig = nullptr;
   ID3DBlob* errorBlob = nullptr;

   ThrowIfFailed(D3DX12SerializeVersionedRootSignature(&VersionedrootSigDesc, featureData.HighestVersion, &serializedRootSig, &errorBlob));

The code will throw if I run like above, I checked featureData.HighestVersion is 1.1. If I forced featureData.HighestVersion to 1.0, the code will pass. And if I remove the second rootParam[1], only use 1 rootParam, even featureData.HighestVersion is 1.1, the code will pass. Does version 1.1 has some restrictions on CBV on root descriptor? (Windows 10 21H2 OS Build 19044.1706, Visual Studio 2022 community 17.2.2)

1 Answers
D3D12_ROOT_DESCRIPTOR1 CBV2rootDescriptor;
CBV2rootDescriptor.ShaderRegister = 1;
CBV2rootDescriptor.RegisterSpace = 0;
CBV1rootDescriptor.Flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE;

Since I copied and pasted for CBV2, I didn't change CBV1rootDescriptor.Flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE; to CBV2rootDescriptor.Flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE; and I didn't initialize CBV2rootDescriptor, so CBV2rootDescriptor.Flags could be random number which cause the creation failed. I found this when I initialize CBV2rootDescriptor to {}, then the failure gone, which made to to look at each assignment again and found CBV1rootDescriptor.Flags didn't change to CBV2rootDescriptor.Flags.

Related