我正在用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。
发布于 2019-09-26 21:44:52
在您的描述中,您的位置定义为R32G32B32,但着色器应为float4,这是为什么?
要么是这样,要么是blob数据有问题。我假设着色器斑点数据是用于顶点着色器而不是像素着色器?
发布于 2019-09-28 02:05:41
启用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”。他们需要保持一致。
https://stackoverflow.com/questions/58117319
复制相似问题