gpt4 book ai didi

c++ - CreateInputLayout 返回 E_INVALIDARG

转载 作者:行者123 更新时间:2023-11-28 01:17:37 25 4
gpt4 key购买 nike

我正在使用 DirectX11 用 C++ 编写程序。现在我想从着色器开始,为此我还需要 ID3D11InputLayout

//in main
shader.Bind(DeviceContext);

ID3D11InputLayout *pLayout;
D3D11_INPUT_ELEMENT_DESC ied[] =
{
{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
{"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
};

HRESULT hh = Device->CreateInputLayout(ied, 2, shader.GetVSBlob()->GetBufferPointer(), shader.GetVSBlob()->GetBufferSize(), &pLayout);

DeviceContext->IASetInputLayout(pLayout);

//Vertex Shader
struct VOut
{
float4 position : SV_POSITION;
float4 color : COLOR;
};

VOut main(float4 position : POSITION, float4 color : COLOR)
{
VOut output;

output.position = position;
output.color = color;

return output;
}
//pixel shader
struct VOut
{
float4 position : SV_POSITION;
float4 color : COLOR;
};

float4 main(float4 position : SV_POSITION, float4 color : COLOR) : SV_TARGET
{
return color;
}

Device->CreateInputLayout() 返回 E_INVALIDARG。

最佳答案

启用 Direct3D Debug Device并查找调试输出。

D3D11 ERROR: ID3D11Device::CreateInputLayout: The provided input signature expects
to read an element with SemanticName/Index: 'SV_Position'/0, but the declaration
doesn't provide a matching name.
[ STATE_CREATION ERROR #163: CREATEINPUTLAYOUT_MISSINGELEMENT]

在这种情况下,您会看到您在布局中使用了遗留的“POSITION”语义,但在着色器中使用了“SV_Position”。它们需要保持一致。

关于c++ - CreateInputLayout 返回 E_INVALIDARG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58117319/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com