0

I'm new to MSFT and DirectX so please go easy on me..

If an hlsl shader uses the [RootSignature(SignatureName)] attribute, will it be overridden by a root signature defined in code using ID3D12RootSignature?

E.g. in sample code I have this in an .hlsli file which is included by a shader:

    "RootFlags(ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT), " \
    "CBV(b0, visibility = SHADER_VISIBILITY_VERTEX), " \
    "CBV(b0, visibility = SHADER_VISIBILITY_PIXEL), " \
    "DescriptorTable(SRV(t0, numDescriptors = 6), visibility = SHADER_VISIBILITY_PIXEL)," \
    "DescriptorTable(SRV(t64, numDescriptors = 6), visibility = SHADER_VISIBILITY_PIXEL)," \
    "RootConstants(b1, num32BitConstants = 2, visibility = SHADER_VISIBILITY_VERTEX), " \
    "StaticSampler(s0, maxAnisotropy = 8, visibility = SHADER_VISIBILITY_PIXEL)," \
    "StaticSampler(s1, visibility = SHADER_VISIBILITY_PIXEL," \
        "addressU = TEXTURE_ADDRESS_CLAMP," \
        "addressV = TEXTURE_ADDRESS_CLAMP," \
        "addressW = TEXTURE_ADDRESS_CLAMP," \
        "comparisonFunc = COMPARISON_GREATER_EQUAL," \
        "filter = FILTER_MIN_MAG_LINEAR_MIP_POINT)"

And in the shader:

[RootSignature(ModelViewer_RootSig)]
VSOutput main(VSInput vsInput)
{
    VSOutput vsOutput;

    vsOutput.position = mul(modelToProjection, float4(vsInput.position, 1.0));
    vsOutput.worldPos = vsInput.position;
    vsOutput.texCoord = vsInput.texcoord0;
    vsOutput.viewDir = vsInput.position - ViewerPos;
 <etc>

Will this override or be overridden by a root signature created with something like the following: ASSERT_SUCCEEDED( g_Device->CreateRootSignature(1, pOutBlob->GetBufferPointer(), pOutBlob->GetBufferSize(), MY_IID_PPV_ARGS(&m_Signature)) );

mike
  • 1,192
  • 9
  • 32

1 Answers1

2

On PC if you have both a "code-provided" Root Signature and a "shader-provided" Root Signature, the code one takes precedence. Generally you should use one or the other, not both.

For DirectX Tool Kit for DX12 on GitHub I use both in violation of what I just said above, but there's good reasons for it. In general the "code-style" Root Signature seems easier to understand for 'newbies', and therefore I make use of it in the tool kit since it's primarily intended for learning projects, samples, etc. I do also support Xbox development, where the strong recommendation is to always use shader-based root signatures.

This is because on Xbox the shaders are 'fully precompiled' and any difference in the root signature triggers a 'recompile' at runtime. The Xbox version of the runtime generates debug output if my code and shader signatures are out-of-sync, so it's easy enough for me to maintain. That's not true for most people. It also provides a bunch of examples of the same root sig in both code and shader notation, which is a good thing for deved, but probably not worthwhile for most projects.

Chuck Walbourn
  • 38,259
  • 2
  • 58
  • 81
  • I'm asking as I'm using the MSFT DX12 samples (https://github.com/Microsoft/DirectX-Graphics-Samples) which use both :-D – mike Feb 17 '21 at 09:02