2016-06-10 113 views
2

我正在處理動態立方體貼圖渲染。特別是,爲了渲染立方體貼圖,我使用了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] 

錯誤消息,似乎預示着某種輸入參數和不同的Shader功能的輸出值之間的不匹配的,但我真的不能認識到這一點不匹配。

有關此錯誤的任何想法或解釋?

回答

0

你不要在你的像素着色器讀取的名次,因爲那句話獲取寄存器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和視口索引而沒有擴展的唯一階段。