Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1067298 Posts in 43578 Topics- by 35619 Members - Latest Member: teamsheepy

November 28, 2014, 07:41:08 AM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)D3D11 shader linkage error
Pages: [1]
Print
Author Topic: D3D11 shader linkage error  (Read 1009 times)
Crimsontide
Level 3
***


View Profile
« on: April 30, 2013, 10:53:21 AM »

Came across a funny D3D11 error that has me kinda puzzled.

I have a very simple vertex and pixel shader that in combination with some otherwise simple code shows a cube on screen (usual 'hello world' type app as I play around with changes from D3D9 to D3D11).

Normally my pixel shader input struct is my vertex shader output struct, but to try some stuff out the pixel and vertex shaders are in different files with different inputs/outputs.  Now the vertex shader outputs match up with the pixel shader inputs, but sometimes if they are not identical, there are errors... sometimes...

For example:

Code:
float4 PShader (float4 position : SV_POSITION, float4 color : TEXCOORD6) : SV_TARGET {
   return color;
   }

renders fine while:

Code:
float4 PShader (float4 color : TEXCOORD6) : SV_TARGET {
   return color;
   }

does not render fine (colors are all screwy).  Playing around with different structure layouts likewise yielded equally confusing results.  I was under the impression that as long as the values going in and out of the semantics matched up you were fine (ie. if u sent a normal in TEXCOORD2, and retrieved the normal in TEXCOORD2, regardless of how it was defined all was fine).  But this doesn't seem to be the case.  For example, in the code snippets above why does "float4 position : SV_POSITION" need to be defined, if it is not going to be used?

There's something about this I'm not understanding.
Logged
SoulSharer
Level 1
*



View Profile
« Reply #1 on: April 30, 2013, 01:56:49 PM »

Came across a funny D3D11 error that has me kinda puzzled.

I have a very simple vertex and pixel shader that in combination with some otherwise simple code shows a cube on screen (usual 'hello world' type app as I play around with changes from D3D9 to D3D11).

Normally my pixel shader input struct is my vertex shader output struct, but to try some stuff out the pixel and vertex shaders are in different files with different inputs/outputs.  Now the vertex shader outputs match up with the pixel shader inputs, but sometimes if they are not identical, there are errors... sometimes...

For example:

Code:
float4 PShader (float4 position : SV_POSITION, float4 color : TEXCOORD6) : SV_TARGET {
   return color;
   }

renders fine while:

Code:
float4 PShader (float4 color : TEXCOORD6) : SV_TARGET {
   return color;
   }

does not render fine (colors are all screwy).  Playing around with different structure layouts likewise yielded equally confusing results.  I was under the impression that as long as the values going in and out of the semantics matched up you were fine (ie. if u sent a normal in TEXCOORD2, and retrieved the normal in TEXCOORD2, regardless of how it was defined all was fine).  But this doesn't seem to be the case.  For example, in the code snippets above why does "float4 position : SV_POSITION" need to be defined, if it is not going to be used?

There's something about this I'm not understanding.

Can you show full shader file (including vertex shader)? And if possible, code where you load in values into constant buffers.

Also are you sure shader compiled successfully?
« Last Edit: April 30, 2013, 02:27:29 PM by Yaroslav » Logged

Twitter: twitter.com/SoulSharer
Skype: disturbedfearless
Crimsontide
Level 3
***


View Profile
« Reply #2 on: April 30, 2013, 03:52:00 PM »

Vertex shader looks like:

Code:
// *************************************************************************************
// ShaderTest1_VS.hlsl
//
// Ryan Boghean
// Feb 01, 2013
//
// *************************************************************************************

#include "LinearAlgebra.hlsl"



// ---------------------------------------------------------------------------------------------------------------------------
// constants/types
// ---------------------------------------------------------------------------------------------------------------------------

// ----- constants -----
cbuffer CameraConstants : register(b0) {

// perspective constants
float4 vp_rect; // x0, y0, x1, y1
float4 vp_dim; // width, height, width/height, 0.0f
float4 vp_z_values; // (x,y) = viewport z, (z,w) = perspective z
float4 vp_fov; // (horizontal fov, vertical fov, 0.0f, 0.0f)

// camera constants
float4 cam_origin; // camera origin point
float4 cam_lookat; // camera look-at point
float4 cam_up; // camera up vector

// matrices
float4x4 persp_matrix; // perspective matrix transformation
float4x4 cam_matrix; // camera matrix transformation
float4x4 cam_persp_matrix; // combined perspective/camera transformation matrix
};


// ----- structures -----
struct VIn {

// vertex data
    float4 position : POSITION;
float4 tex : NORMAL0; // texture coords in object space
    float4 color : NORMAL1;

// instance data
float4 offset : NORMAL2;
float4 dim : NORMAL3;
float4x4 transform_matrix : TEXCOORD0;
float4x4 transform_inverse : TEXCOORD4;
};

struct VOut {
    float4 position : SV_POSITION;
float4 tex : TEXCOORD0; // texture coordinates in object space
float4 normal_x : TEXCOORD1; // world x-axis in object space
float4 normal_y : TEXCOORD2; // world y-axis in object space
float4 normal_z : TEXCOORD3; // world z-axis in object space
float4 ray : TEXCOORD4; // ray vector in object space
float4 rayi : TEXCOORD5; // ray inverse vector in object space
    float4 color : TEXCOORD6;
};



// ---------------------------------------------------------------------------------------------------------------------------
// VShader
// ---------------------------------------------------------------------------------------------------------------------------

// ----- VShader -----
VOut VShader (VIn input) {

// calculate inverse/transpose of the transformation matrix
float4x4 transform_matrix = input.transform_matrix;
float4x4 transform_inverse = input.transform_inverse; // used to transform ray into object space
float4x4 transform_inverse_transpose = transpose(transform_inverse); // used to transform normals

// calculate position and ray
float4 pos = mul(transform_matrix,input.position); // transform vertex into object space
float4 ray = mul(transform_inverse, pos - cam_origin ); // transform ray into object space
float4 rayi = float4(1,1,1,1) / ray; // ray inverse
pos = mul(cam_persp_matrix,pos); // transform vertex into clip space

// calculate normals
float4 normal_x = mul(transform_inverse_transpose, float4(1,0,0,0) );
float4 normal_y = mul(transform_inverse_transpose, float4(0,1,0,0) );
float4 normal_z = mul(transform_inverse_transpose, float4(0,0,1,0) );

// done
    VOut output;
    output.position = pos;
output.tex = input.tex;
output.normal_x = normal_x;
output.normal_y = normal_y;
output.normal_z = normal_z;
output.ray = ray;
output.rayi = rayi;
    output.color = input.color;

    return output;
}

Pixel shader looks like:

Code:
// *************************************************************************************
// ShaderTest1_PS.hlsl
//
//
// Ryan Boghean
// Feb 01, 2013
//
// *************************************************************************************

struct PIn {
float4 position : SV_POSITION;
float4 tex : TEXCOORD0; // texture coordinates in object space
float4 normal_x : TEXCOORD1; // world x-axis in object space
float4 normal_y : TEXCOORD2; // world y-axis in object space
float4 normal_z : TEXCOORD3; // world z-axis in object space
float4 ray : TEXCOORD4; // ray vector in object space
float4 rayi : TEXCOORD5; // ray inverse vector in object space
    float4 color : TEXCOORD6;
};


// ----- pixel shader -----
float4 PShader (PIn input) : SV_TARGET {
    return input.color;
}

//float4 PShader (float4 position : SV_POSITION, float4 color : TEXCOORD6) : SV_TARGET {
//    return color;
// }

I get no errors on compile.  In the case where SV_POSITION is not used I get a warning:

Quote
D3D11 ERROR: ID3D11DeviceContext::DrawInstanced: Vertex 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]
Logged
SoulSharer
Level 1
*



View Profile
« Reply #3 on: April 30, 2013, 11:00:58 PM »

Quote
D3D11 ERROR: ID3D11DeviceContext::DrawInstanced: Vertex 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]

I think it explains everything? You didn't successfully link the shader because of mismatched input and output. You can't rely on any result when compilation or linkage fails.
Logged

Twitter: twitter.com/SoulSharer
Skype: disturbedfearless
Crimsontide
Level 3
***


View Profile
« Reply #4 on: May 01, 2013, 07:52:24 AM »

Quote
D3D11 ERROR: ID3D11DeviceContext::DrawInstanced: Vertex 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]

I think it explains everything? You didn't successfully link the shader because of mismatched input and output. You can't rely on any result when compilation or linkage fails.

Then what wasn't linked?  The only time I get that error is when SV_POSITION is not defined in the pixel shader.  When it is defined no errors.  I have no use for SV_POSITION in the pixel shader, why is it required?  Not to mention SV_POSITION in the vertex shader means something completely different than SV_POSITION in the pixel shader.
Logged
PompiPompi
Level 10
*****



View Profile WWW
« Reply #5 on: May 01, 2013, 11:57:32 AM »

I think you are not suppose to add the index at the end. The TEXCOORD with index at the end is used in DX9, in DX11 it is done a bit differently, but I don't recall how.
You can give any label you like(unless it's a special label). But something about the indices is different.
So you can have for instance float3 color: PERVERTEXCOLOR; if you like.
Logged

Master of all trades.
Crimsontide
Level 3
***


View Profile
« Reply #6 on: May 01, 2013, 12:33:01 PM »

I think you are not suppose to add the index at the end. The TEXCOORD with index at the end is used in DX9, in DX11 it is done a bit differently, but I don't recall how.
You can give any label you like(unless it's a special label). But something about the indices is different.
So you can have for instance float3 color: PERVERTEXCOLOR; if you like.

Quite possibly, but then how do you link from the vertex declaration to the vertex shader?  They even have the semantic index just for that from what I understand.  And it still doesn't explain the need for SV_POSITION in the pixel shader.

I've scoured the MSDN website but its not explained at all as far as I can tell.  Any ideas where I can find some real information on what I can, can't, and should do?
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic