创建根签名时未声明的标识符

Undeclared Identifier while creating a root signature

如何编译 "standalone" 根签名以用于 D3D12 管道状态对象?

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

error X3004: undeclared identifier 'ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT'

方法一:

#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

其他相关信息:

P.S:我还尝试了文件中字符串的几种变体,使用 [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)"