如何编译用于D3D12管道状态对象的“独立”根签名?

我一直按照此MSDN page上概述的步骤尝试从hlsl编译D3D12根签名,但到目前为止,我肯定已经错过了一个关键的细节,因为它们都产生相同的错误:

error X3004: undeclared identifier 'ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT'

方法A:

#include <d3dcompiler.h>
#include <Windows.h>
#include <wrl.h>

const char* definition =
    "#define RS1 "
    "RootFlags(ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT | DENY_HULL_SHADER_ROOT_ACCESS | DENY_DOMAIN_SHADER_ROOT_ACCESS | DENY_GEOMETRY_SHADER_ROOT_ACCESS),"
    "DescriptorTable(SRV(t0, flags = DATA_STATIC), visibility = SHADER_VISIBILITY_PIXEL),"
    "DescriptorTable(CBV(b0, flags = DATA_STATIC), visibility = SHADER_VISIBILITY_VERTEX),"
    "StaticSampler(s0, addressU = TEXTURE_ADDRESS_BORDER, filter = FILTER_MIN_MAG_MIP_POINT)";

int WINAPI WinMain(HINSTANCE /*hInstance*/, HINSTANCE, LPSTR, int /*nCmdShow*/)
{
    {
        Microsoft::WRL::ComPtr<ID3DBlob> errorMsgs;
        Microsoft::WRL::ComPtr<ID3DBlob> signatureBlob;
        if (FAILED(D3DCompile(definition, strlen(definition), nullptr, nullptr, nullptr, "RS1", "rootsig_1_1", 0, 0, &signatureBlob, &errorMsgs)))
        {
            OutputDebugStringA((LPCSTR)errorMsgs.Get()->GetBufferPointer());
        }
    }

    {
        Microsoft::WRL::ComPtr<ID3DBlob> errorMsgs;
        Microsoft::WRL::ComPtr<ID3DBlob> signatureBlob;
        if (FAILED(D3DCompile2(definition, strlen(definition), nullptr, nullptr, nullptr, "RS1", "rootsig_1_1", 0, D3DCOMPILE_FLAGS2_FORCE_ROOT_SIGNATURE_1_1, 0, nullptr, 0, &signatureBlob, &errorMsgs)))
        {
            OutputDebugStringA((LPCSTR)errorMsgs.Get()->GetBufferPointer());
        }
    }

    return 0;
}


方法B:

名为fxc_rootsig_test.hlsl的文件,其中包含:

#define RS1 RootFlags(ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT | DENY_HULL_SHADER_ROOT_ACCESS | DENY_DOMAIN_SHADER_ROOT_ACCESS | DENY_GEOMETRY_SHADER_ROOT_ACCESS), \
            DescriptorTable(SRV(t0, flags = DATA_STATIC), visibility = SHADER_VISIBILITY_PIXEL), \
            DescriptorTable(CBV(b0, flags = DATA_STATIC), visibility = SHADER_VISIBILITY_VERTEX), \
            StaticSampler(s0, addressU = TEXTURE_ADDRESS_BORDER, addressV = TEXTURE_ADDRESS_BORDER, filter = FILTER_MIN_MAG_MIP_POINT)


并使用以下命令行调用fxc:fxc.exe /T rootsig_1_1 fxc_rootsig_test.hlsl /E RS1 /Fo fxc_rootsig_test.fxo

其他相关信息:


平台:Windows 10 x64(版本1803)
Windows SDK版本:10.0.17763.0
Visual Studio 2017社区版(15.9.3)


PS:我还尝试了使用[RootSignature(RS1)]和着色器对文件中的字符串进行多种变体,然后尝试使用该着色器的目标即ps_5_1进行编译。

P.P.S:我也尝试过删除ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT,但是它只是抱怨DENY_HULL_SHADER_ROOT_ACCESS

最佳答案

您需要添加更多报价。根签名必须是带引号的字符串:

#define RS1 "RootFlags(ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT | DENY_HULL_SHADER_ROOT_ACCESS | DENY_DOMAIN_SHADER_ROOT_ACCESS | DENY_GEOMETRY_SHADER_ROOT_ACCESS), " \
"            DescriptorTable(SRV(t0, flags = DATA_STATIC), visibility = SHADER_VISIBILITY_PIXEL)," \
"            DescriptorTable(CBV(b0, flags = DATA_STATIC), visibility = SHADER_VISIBILITY_VERTEX)," \
"            StaticSampler(s0, addressU = TEXTURE_ADDRESS_BORDER, addressV = TEXTURE_ADDRESS_BORDER, filter = FILTER_MIN_MAG_MIP_POINT)"

09-25 17:42