简体   繁体   English

问:DX12 创建图形管道状态时出错

[英]Q: DX12 Error in creation of graphics pipeline state

By following the Microsoft documentation and creating the PSO, I receive the following D3D12 errors.通过遵循 Microsoft 文档并创建 PSO,我收到以下 D3D12 错误。

Error code错误代码

Considering the first error states that the encoded signature size doesn't match the specified size.考虑到第一个错误表明编码的签名大小与指定的大小不匹配。 I compared the shader and the signature.我比较了着色器和签名。

    D3D12_INPUT_ELEMENT_DESC inputElementDesc[] =
    {{
      "POSITION",
      0,
      DXGI_FORMAT_R32G32B32_FLOAT,
      0,
      0,
      D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA,
      0
    }};

    D3D12_INPUT_LAYOUT_DESC inputLayoutDesc;
    inputLayoutDesc.pInputElementDescs = inputElementDesc;
    inputLayoutDesc.NumElements = ARRAYSIZE(inputElementDesc);
struct VSIn 
{
    float3 pos : POSITION;
};

struct VSOut
{
    float4 pos : SV_POSITION;
};

VSOut vs_main( VSIn input, uint index : SV_VertexID )
{
    VSOut output = (VSOut)0;
    output.pos = float4(input.pos, 1.0f);
    return output;
}

I cannot seem to find any wrongdoings.我似乎找不到任何不当行为。 So I thought that maybe the fault lies within how I compiled my shaders.所以我想可能问题在于我编译着色器的方式。 I used the IDxcCompiler library for this purpose.为此,我使用了 IDxcCompiler 库。 When debugging I didn't get any errors from compiling.调试时,我没有从编译中得到任何错误。

    ComPtr<IDxcOperationResult> result = nullptr;
    ComPtr<IDxcBlobEncoding> vertexBlob = nullptr;
    std::vector<LPCWSTR> compileArguments;
    compileArguments.push_back(L"/Gis");
    ThrowIfFailed(library->CreateBlobFromFile(L"VertexShader.hlsl", nullptr, &vertexBlob));
    ThrowIfFailed(compiler->Compile(
        vertexBlob.Get(),
        L"VertexShader.hlsl",
        L"vs_main",
        L"vs_6_4",
        compileArguments.data(),
        (UINT)compileArguments.size(),
        NULL,
        NULL,
        NULL,
        &result
    ));

And the blobs seem to have received its information斑点似乎已经收到了它的信息

D3D12_GRAPHICS_PIPELINE_STATE_DESC gPipelineStateDesc;
gPipelineStateDesc.pRootSignature = this->gRootSignature.Get();
gPipelineStateDesc.InputLayout = inputLayoutDesc;
gPipelineStateDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;

ComPtr<IDxcBlobEncoding> test16;
gPipelineStateDesc.VS.pShaderBytecode = reinterpret_cast<void*>(vertexBlob->GetBufferPointer());
library->GetBlobAsUtf16(vertexBlob.Get(), &test16);
OutputDebugStringW(reinterpret_cast<LPCWSTR>(test16->GetBufferPointer()));
gPipelineStateDesc.VS.BytecodeLength = vertexBlob->GetBufferSize();

gPipelineStateDesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM;
gPipelineStateDesc.NumRenderTargets = 1;
gPipelineStateDesc.SampleDesc.Count = 1;
gPipelineStateDesc.SampleMask = UINT_MAX;

gPipelineStateDesc.RasterizerState.FillMode = D3D12_FILL_MODE_SOLID;
gPipelineStateDesc.RasterizerState.CullMode = D3D12_CULL_MODE_BACK;

D3D12_RENDER_TARGET_BLEND_DESC RTBlendDesc = {
    false,
    false,
    D3D12_BLEND_ONE, D3D12_BLEND_ZERO, D3D12_BLEND_OP_ADD,
    D3D12_BLEND_ONE, D3D12_BLEND_ZERO, D3D12_BLEND_OP_ADD,
    D3D12_LOGIC_OP_NOOP, D3D12_COLOR_WRITE_ENABLE_ALL
};
for (UINT i = 0; i < D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
{
    gPipelineStateDesc.BlendState.RenderTarget[i] = RTBlendDesc;
}
ThrowIfFailed(this->gDevice->CreateGraphicsPipelineState(&gPipelineStateDesc, IID_PPV_ARGS(&this->gPipelineState)));

Output Results输出结果

With a buffer size/byte code length of 241 bytes.缓冲区大小/字节代码长度为 241 字节。 Does anyone have any clue of what has gone wrong?有没有人知道出了什么问题?

Chuck Walbourn Helped me find the solution. Chuck Walbourn 帮助我找到了解决方案。 The blob did not get the results from compiling similar to D3DCompileFromFile(). blob 没有得到类似于 D3DCompileFromFile() 的编译结果。 By utilizing the IDxcOperationResult in the last parameter of the compiler.通过在编译器的最后一个参数中使用 IDxcOperationResult。 You are fetching the results from the compiler like this:您正在从编译器中获取结果,如下所示:

    ComPtr<IDxcOperationResult> result = nullptr;
    ....
    ...
    ..
    ComPtr<IDxcBlob> vertexShader = nullptr;
    result->GetResult(vertexShader);

In this way ->GetBufferPointer() should work properly.这样 ->GetBufferPointer() 应该可以正常工作。 The rest of the errors were due to forgetting to initialize the pipeline state description with "={};".其余的错误是由于忘记用“={};”初始化管道状态描述。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM