Jump to content
  • Advertisement
Sign in to follow this  
Funkymunky

DX12 [D3D12] Root Signature Reflection

This topic is 639 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to get a shader's root signature via reflection so that I can validate what I'm setting.

 

First of all, this page for D3D12CreateRootSignatureDeserializer says that the function has been superceded by D3D12CreateVersionedRootSignatureDeserializer, but I apparently don't have that function in my DirectX 12 header/lib?

 

Regardless, I tried calling D3D12CreateRootSignatureDeserializer as follows:

.

ComPtr<ID3D12RootSignatureDeserializer> deserializer;
D3D12CreateRootSignatureDeserializer(blob->GetBufferPointer(), blob->GetBufferSize(), IID_PPV_ARGS(&deserializer));
D3D12_ROOT_SIGNATURE_DESC *desc = (D3D12_ROOT_SIGNATURE_DESC *)deserializer->GetRootSignatureDesc();

.

But this crashes, because the ID3D12RootSignatureDeserializer pointer returned is null.  "blob" in that code is a ComPtr<ID3DBlob> returned by D3DCompileFromFile, and that part is working fine (I can compile and render using the shader, I just can't get the root signature via reflection).  I'm not sure if the blob is the correct thing to pass, as the documentation only says "If an application has a serialized root signature already or has a compiled shader that contains a root signature and wants to determine the layout definition, it can call D3D12CreateRootSignatureDeserializer to generate a ID3D12RootSignatureDeserializer interface."

 

Anyone have any experience with either of these two issues?

Share this post


Link to post
Share on other sites
Advertisement

D3D12CreateRootSignatureDeserializer returns an HRESULT. What's the result of calling the function? If you're getting back a null pointer, it's probably not success.

 

Are you sure that the blob you're passing in is/contains a root signature? It should either be a blob retrieved from D3D12SerializeRootSignature or the result of compiling a shader whose entrypoint is marked with the [RootSignature] attribute.

Share this post


Link to post
Share on other sites

The function returns E_INVALIDARG.  I'm trying to call this with a compiled shader (ie the resulting blob from D3DCompileFromFile).  I'm not specifying the RootSignature in the HLSL directly, I'm creating it in the C++ code and passing it to the pipeline state.

 

Seeing as misaligning the root signature on purpose causes an error telling me I'm binding the wrong descriptor table type (for example), it seems like the implicit root signature in the compiled shader is known.  How do I get it via reflection?

Share this post


Link to post
Share on other sites

Seeing as misaligning the root signature on purpose causes an error telling me I'm binding the wrong descriptor table type (for example), it seems like the implicit root signature in the compiled shader is known.  How do I get it via reflection?

 

As far as I'm aware you won't be able to retrieve a root signature from your bytecode if you don't explicitly define it in your shader code.

One type of validation you could do is to get information of SRV/CBV/UAV/Sampler bindings using shader reflection. You can cross-reference this data against your root signature to see whether the root signature has the appropriate descriptors, descriptor tables, constants or static samplers to support your shader.

 

Other than doing that I don't think you can actually extract explicit root signature information out of a shader without defining it in your HLSL code.

Share this post


Link to post
Share on other sites

It's not a root signature in the shader.

 

The shader declares registers. The root signature declares root parameters, and a mapping from those parameters to shader registers. The runtime does validation that the root signature declares exactly one root parameter which covers every shader register that the shader uses.

 

To reflect shader registers, you use ID3D12ShaderReflection.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!