gpt4 book ai didi

directx - 着色器链接错误/不匹配

转载 作者:行者123 更新时间:2023-12-04 03:29:29 24 4
gpt4 key购买 nike

我正在研究动态立方体贴图渲染。特别是,为了渲染立方体贴图,我使用了 DirectX SDK 示例“CubeMapGS”中的着色器。着色器似乎是正确的,如您在此处所见:

SamplerState ss;
Texture2D tex;

cbuffer Constants
{
float4x4 worldMat;
float4x4 viewMats[6];
float4x4 projMat;
};

struct VS_CUBEMAP_IN
{
float4 Pos : POSITION;
float3 Normal : NORMAL;
float2 Tex : TEXCOORD0;
};

struct GS_CUBEMAP_IN
{
float4 Pos : SV_POSITION; // World position
float2 Tex : TEXCOORD0; // Texture coord
};


struct PS_CUBEMAP_IN
{
float4 Pos : SV_POSITION; // Projection coord
float2 Tex : TEXCOORD0; // Texture coord
uint RTIndex : SV_RenderTargetArrayIndex;
};


GS_CUBEMAP_IN VShader(VS_CUBEMAP_IN input)
{
GS_CUBEMAP_IN output = (GS_CUBEMAP_IN) 0.0f;

// Compute world position
output.Pos = mul(input.Pos, worldMat);

// Propagate tex coord
output.Tex = input.Tex;

return output;
}

[maxvertexcount(18)]
void GShader(triangle GS_CUBEMAP_IN input[3], inout TriangleStream<PS_CUBEMAP_IN> CubeMapStream)
{
for (int f = 0; f < 6; ++f)
{
// Compute screen coordinates
PS_CUBEMAP_IN output;
output.RTIndex = f;
for (int v = 0; v < 3; v++)
{
output.Pos = mul(input[v].Pos, viewMats[f]);
output.Pos = mul(output.Pos, projMat);
output.Tex = input[v].Tex;
CubeMapStream.Append(output);
}
CubeMapStream.RestartStrip();
}
}


float4 PShader(PS_CUBEMAP_IN input) : SV_Target {
return tex.Sample(ss, input.Tex);
}

但是,它不起作用。事实上,我收到以下 DirectX 错误消息:

D3D11 ERROR: ID3D11DeviceContext::DrawIndexed: Vertex Shader - Geometry Shader linkage error: Signatures between stages are incompatible. Semantic 'SV_POSITION' is defined for mismatched hardware registers between the output stage and input stage. [ EXECUTION ERROR #343: DEVICE_SHADER_LINKAGE_REGISTERINDEX]
D3D11 ERROR: ID3D11DeviceContext::DrawIndexed: Vertex Shader - Geometry Shader linkage error: Signatures between stages are incompatible. Semantic 'TEXCOORD' is defined for mismatched hardware registers between the output stage and input stage. [ EXECUTION ERROR #343: DEVICE_SHADER_LINKAGE_REGISTERINDEX]
D3D11 ERROR: ID3D11DeviceContext::DrawIndexed: Geometry Shader - Pixel Shader linkage error: Signatures between stages are incompatible. Semantic 'TEXCOORD' is defined for mismatched hardware registers between the output stage and input stage. [ EXECUTION ERROR #343: DEVICE_SHADER_LINKAGE_REGISTERINDEX]
D3D11 ERROR: ID3D11DeviceContext::DrawIndexed: Geometry Shader - Pixel Shader linkage error: Signatures between stages are incompatible. Semantic 'SV_POSITION' is defined for mismatched hardware registers between the output stage and input stage. [ EXECUTION ERROR #343: DEVICE_SHADER_LINKAGE_REGISTERINDEX]

错误消息似乎表明输入参数与不同着色器函数的输出值之间存在某种不匹配,但我无法真正识别出这种不匹配。

关于此错误的任何想法或解释?

最佳答案

您不会在像素着色器中读取 Pos,因为 Tex 获得寄存器 0,而在几何着色器输出中,它是寄存器 1。

你可以像这样修复它,通过将下一阶段未读取的输出放在结构的末尾

struct PS_CUBEMAP_IN
{
float2 Tex : TEXCOORD0; // Texture coord
uint RTIndex : SV_RenderTargetArrayIndex;
float4 Pos : SV_POSITION; // Projection coord
};

此外,请小心使用特殊的 SV_POSITION,而不是来自像素着色器之前的最后阶段,它在 nvidia 和 AMD 之间的行为不同。只需将其命名为 POSDONTMESSWITHME 并且因为顶点着色器必须输出它,所以在 GS_CUBEMAP_IN 的末尾放置一个假的并将其设置为 0。

作为一条建议,几何着色器是个坏主意。几何扩展非常慢,对于那种应用程序来说不值得,它们更擅长剔除三角形,遗憾的是它们是唯一无需扩展即可输出 rt 和视口(viewport)索引的阶段。

关于directx - 着色器链接错误/不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37739038/

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