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

时间:2018-12-07 01:54:57

标签: c++ directx-12

如何编译用于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)

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

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

1 个答案:

答案 0 :(得分:1)

您需要添加更多报价。根签名需要用引号引起来的字符串:

#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)"