C++ 添加几何体着色器会导致;着色器链接错误“;
我正在向DirectX 11程序添加一个几何体着色器(一个非常简单的着色器)。我已经编写了顶点和像素着色器,它们的工作方式和预期的一样-没有错误,没有警告。着色器也很简单。顶点着色器是:C++ 添加几何体着色器会导致;着色器链接错误“;,c++,shader,directx,hlsl,C++,Shader,Directx,Hlsl,我正在向DirectX 11程序添加一个几何体着色器(一个非常简单的着色器)。我已经编写了顶点和像素着色器,它们的工作方式和预期的一样-没有错误,没有警告。着色器也很简单。顶点着色器是: cbuffer PerApplication : register(b0) { matrix projectionMatrix; } cbuffer PerFrame : register(b1) { matrix viewMatrix; } cbuffer PerObject : regi
cbuffer PerApplication : register(b0)
{
matrix projectionMatrix;
}
cbuffer PerFrame : register(b1)
{
matrix viewMatrix;
}
cbuffer PerObject : register(b2)
{
matrix worldMatrix;
}
struct VertexShaderInput
{
float4 position : POSITION;
float4 color: COLOR;
};
struct VertexShaderOutput
{
float4 color : COLOR;
float4 position : SV_POSITION;
};
//entry point
VertexShaderOutput SimpleVertexShader(VertexShaderInput IN)
{
VertexShaderOutput OUT;
matrix mvp = mul(projectionMatrix, mul(viewMatrix, worldMatrix));
OUT.color = IN.color;
OUT.position = mul(mvp, IN.position);
return OUT;
}
struct PixelShaderInput
{
float4 color : COLOR;
};
float4 SimplePixelShader(PixelShaderInput IN) : SV_TARGET
{
return IN.color;
}
struct VertexInput
{
float4 color : COLOR;
float4 position : POSITIONT;
};
struct VertexOutput
{
float4 color : COLOR;
float4 position : SV_Position;
};
[maxvertexcount(3)]
void SimpleGeometryShader(triangle VertexInput input[3], inout TriangleStream<VertexOutput> stream)
{
VertexOutput v1 = { input[0].color, input[0].position };
stream.Append(v1);
VertexOutput v2 = { input[1].color, input[1].position };
stream.Append(v2);
VertexOutput v3 = { input[2].color, input[2].position };
stream.Append(v3);
stream.RestartStrip();
}
像素着色器是:
cbuffer PerApplication : register(b0)
{
matrix projectionMatrix;
}
cbuffer PerFrame : register(b1)
{
matrix viewMatrix;
}
cbuffer PerObject : register(b2)
{
matrix worldMatrix;
}
struct VertexShaderInput
{
float4 position : POSITION;
float4 color: COLOR;
};
struct VertexShaderOutput
{
float4 color : COLOR;
float4 position : SV_POSITION;
};
//entry point
VertexShaderOutput SimpleVertexShader(VertexShaderInput IN)
{
VertexShaderOutput OUT;
matrix mvp = mul(projectionMatrix, mul(viewMatrix, worldMatrix));
OUT.color = IN.color;
OUT.position = mul(mvp, IN.position);
return OUT;
}
struct PixelShaderInput
{
float4 color : COLOR;
};
float4 SimplePixelShader(PixelShaderInput IN) : SV_TARGET
{
return IN.color;
}
struct VertexInput
{
float4 color : COLOR;
float4 position : POSITIONT;
};
struct VertexOutput
{
float4 color : COLOR;
float4 position : SV_Position;
};
[maxvertexcount(3)]
void SimpleGeometryShader(triangle VertexInput input[3], inout TriangleStream<VertexOutput> stream)
{
VertexOutput v1 = { input[0].color, input[0].position };
stream.Append(v1);
VertexOutput v2 = { input[1].color, input[1].position };
stream.Append(v2);
VertexOutput v3 = { input[2].color, input[2].position };
stream.Append(v3);
stream.RestartStrip();
}
嗯,正如我所说,这很有效。然后我添加了一个几何体着色器,它实际上什么都不做,它只需要一个三角形并返回相同的三角形。几何体着色器是:
cbuffer PerApplication : register(b0)
{
matrix projectionMatrix;
}
cbuffer PerFrame : register(b1)
{
matrix viewMatrix;
}
cbuffer PerObject : register(b2)
{
matrix worldMatrix;
}
struct VertexShaderInput
{
float4 position : POSITION;
float4 color: COLOR;
};
struct VertexShaderOutput
{
float4 color : COLOR;
float4 position : SV_POSITION;
};
//entry point
VertexShaderOutput SimpleVertexShader(VertexShaderInput IN)
{
VertexShaderOutput OUT;
matrix mvp = mul(projectionMatrix, mul(viewMatrix, worldMatrix));
OUT.color = IN.color;
OUT.position = mul(mvp, IN.position);
return OUT;
}
struct PixelShaderInput
{
float4 color : COLOR;
};
float4 SimplePixelShader(PixelShaderInput IN) : SV_TARGET
{
return IN.color;
}
struct VertexInput
{
float4 color : COLOR;
float4 position : POSITIONT;
};
struct VertexOutput
{
float4 color : COLOR;
float4 position : SV_Position;
};
[maxvertexcount(3)]
void SimpleGeometryShader(triangle VertexInput input[3], inout TriangleStream<VertexOutput> stream)
{
VertexOutput v1 = { input[0].color, input[0].position };
stream.Append(v1);
VertexOutput v2 = { input[1].color, input[1].position };
stream.Append(v2);
VertexOutput v3 = { input[2].color, input[2].position };
stream.Append(v3);
stream.RestartStrip();
}
这个程序本身是有效的,正如预期的那样,我看到了我期望看到的。但现在有两个D3D11错误:
D3D11错误:ID3D11DeviceContext::DrawIndexed:顶点着色器-几何体着色器链接错误:阶段之间的签名不兼容。输入阶段需要语义/索引(POSITIONT,0)作为输入,但输出阶段不提供。[执行错误#342:未找到设备(着色器)链接(语义名称)]
D3D11错误:ID3D11DeviceContext::DrawIndexed:几何体着色器-像素着色器链接错误:阶段之间的签名不兼容。输入阶段需要语义/索引(TEXCOORD,0)作为输入,但输出阶段不提供。[执行错误#342:未找到设备(着色器)链接(语义名称)]
两者都很奇怪。顶点着色器清楚地返回一个POSITIONT,并且颜色和POSITIONT的顺序相同。我的错误是什么?问题的原因是,除了使用我提供的着色器渲染场景外,我还使用一些库绘制文本。显然,其中涉及一些顶点和像素着色器,它们有自己的输入和输出签名。将几何体着色器设置为null解决了我的问题。问题的原因是,除了使用我提供的着色器渲染场景外,我还使用一些库绘制文本。显然,其中涉及一些顶点和像素着色器,它们有自己的输入和输出签名。将几何体着色器设置为null解决了我的问题