Mismatch between SetInputLayout, VertexShader and PixelShader

I have obvious inconsistencies between each of them, but I don't understand why or how they do not match. I've looked at her for so long that I can't see anything now, so maybe a few more sets of eyes ...

Here are the members of the vertex struct:
    XMFLOAT4   _vertexPosition;
    XMFLOAT4   _vertexColor;

      

Here's a description of the input layout:

static const D3D11_INPUT_ELEMENT_DESC vertexLayout[] =
{
    { "SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0,  0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
    { "COLOR",       0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0 },
};

      

Below is the vertex shader input:

struct VertexShaderInput
{
    float4 Position             : SV_POSITION0;
    float4 Color                : COLOR0;
};

      

and finally the pixel shader input:

struct PixelShaderInput
{
    float4 Color                : COLOR0;
};

      

And the final error, currently between the two stages, is this:

D3D11 ERROR: ID3D11DeviceContext::Draw: Input Assembler - Vertex Shader linkage error: Signatures between stages are incompatible. The input stage requires Semantic/Index (SV_POSITION,0) as input, but it is not provided by the output stage. [ EXECUTION ERROR #342: DEVICE_SHADER_LINKAGE_SEMANTICNAME_NOT_FOUND]
D3D11 ERROR: ID3D11DeviceContext::Draw: Vertex Shader - Pixel Shader linkage error: Signatures between stages are incompatible. Semantic 'COLOR' is defined for mismatched hardware registers between the output stage and input stage. [ EXECUTION ERROR #343: DEVICE_SHADER_LINKAGE_REGISTERINDEX]

      

For me, the definition of vertexLayout seems to match the input of the vertex shader, but no certainty about it! Can anyone identify what I messed up? Any advice would be appreciated! Thank!

+3


source to share


1 answer


The Vertex Shader needs to be deduced SV_POSITION

as it is used by the rasterizer to determine where the pixel shader should run. Pixel Shader does not have this right to have input SV_POSITION

, but in this case you cannot use the same PixelShaderInput structure as VS output and PS input.

Also by convention you are not using a semantic index with position, so change SV_POSITION0

to SV_POSITION

in your HLSL shader - a vertex cannot be in two places at the same time.



As a vertex vertex vertex shader is commonly used COLOR

, while COLOR0

/ is COLOR1

used in shader shader / pixel shader pins for diffuse or specular colors.

struct VertexShaderInput
{
    float4 Position             : SV_POSITION;
    float4 Color                : COLOR;
};

      

+3


source







All Articles