CreateGraphicsPipelineState 失败 E_INVALIDARG

CreateGraphicsPipelineState fails with E_INVALIDARG

在 Directx 12 中创建管道状态对象失败并显示 E_INVALIDARG,调试层输出一堆废话说 D3D12_GRAPHICS_PIPELINE_STATE_DESC 实例中的数据无效:

D3D12 ERROR: ID3D12Device::CreateBlendState: DestBlendAlpha[ 0 ] is trying to use a D3D11_BLEND value (0x4) that manipulates color, which is invalid. [ STATE_CREATION ERROR #115: CREATEBLENDSTATE_INVALIDDESTBLENDALPHA] D3D12 ERROR: ID3D12Device::CreateDepthStencilState: BackFace.StencilFailOp has an unrecognized value. [ STATE_CREATION ERROR #106: CREATEDEPTHSTENCILSTATE_INVALIDBACKFACESTENCILFAILOP] D3D12 ERROR: ID3D12Device::CreateDepthStencilState: BackFace.StencilDepthFailOp has an unrecognized value. [ STATE_CREATION ERROR #107: CREATEDEPTHSTENCILSTATE_INVALIDBACKFACESTENCILZFAILOP] D3D12 ERROR: ID3D12Device::CreateDepthStencilState: BackFace.StencilPassOp has an unrecognized value. [ STATE_CREATION ERROR #108: CREATEDEPTHSTENCILSTATE_INVALIDBACKFACESTENCILPASSOP] D3D12 ERROR: ID3D12Device::CreateDepthStencilState: BackFace.StencilFunc has an unrecognized value. [ STATE_CREATION ERROR #109: CREATEDEPTHSTENCILSTATE_INVALIDBACKFACESTENCILFUNC] D3D12 ERROR: ID3D12Device::CreateRasterizerState: FillMode has an unrecognized value. [ STATE_CREATION ERROR #95: CREATERASTERIZERSTATE_INVALIDFILLMODE] D3D12 ERROR: ID3D12Device::CreateRasterizerState: FillMode must be D3D12_FILL_MODE_SOLID when ConservativeRaster is D3D12_CONSERVATIVE_RASTERIZATION_MODE_ON: FillMode = D3D12_FILL_MODE_WIREFRAME, ConservativeRaster = D3D12_CONSERVATIVE_RASTERIZATION_MODE_ON. [ STATE_CREATION ERROR #95: CREATERASTERIZERSTATE_INVALIDFILLMODE] D3D12 ERROR: ID3D12Device::Create*: The specified node mask (0xcccccccc) contains a bit set beyond the node count of the device. [ STATE_CREATION ERROR #900: INVALID_NODE_INDEX]

列表继续...

好像是内存坏了,其实不是,我一遍又一遍地检查了所有的值,它们都很好。 至少 一些 的值必须是正确的,例如看最后一条消息,它说

The specified node mask (0xcccccccc)

…我确定在 CreateGraphicsPipelineState 调用之前它不是 0xcccccccc,调试器确认。

原来在我的机器上构建的 exe 在其他计算机上无法创建 PSO,但是如果项目是在其他机器上构建并且 运行 在我的机器上,就不会有 PSO 问题。

重新安装 Windows SDK 有助于解决问题。

您可以先尝试对 psoDesc 进行零初始化,以避免 NodeMask 字段中的 0xcccccccc 等不正确的值:

D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc = {};