# D3D11 shader signature validation with SV semantics

I'm trying to figure out what the rules are for linking the outputs of one shader stage to the inputs of the next. Since D3D11 does not have any error checking for linkage between shader stages, I have written some code to check them by comparing the D3D11_SIGNATURE_PARAMETER_DESC struct from each input and matching it to an output of the previous stage. The code for checking the signatures is here.

This mostly works, except when there are certain special inputs to a stage that don't get passed from the previous stage. One example is the SV_IsFrontFace input to the pixel shader. Another example is the SV_PrimitiveID input to any stage after the vertex shader.

I've been googling and reading msdn.microsoft.com and so far it's totally unclear to me exactly how these special SV semantics work. In particular:

Q1. Does the ordering of them matter? Or must they occur AFTER all inputs that are passed in from the previous stage?

Q2. Some of these "special" SV values can be identified by looking at the SystemValueType field of the D3D11_SIGNATURE_PARAMETER_DESC. For example SV_IsFrontFace can be identified by checking if the SystemValueType field is D3D_NAME_IS_FRONT_FACE. However, what about SV_GSInstanceID? There doesn't seem to be a corresponding value in the D3D_NAME enumeration for that. http://msdn.microsoft.com/en-us/library/windows/desktop/ff728724(v=vs.85).aspx

Q3. Is there a link where the rules for shader input parameter linkage is explained clearly? Or better yet, code for validating shader signatures?

• D3D11 does have error checking. You just have to turn on the debug layer—then it will complain loudly about any mismatches of shader signatures. Also, is the instance ID not just D3D_NAME_INSTANCE_ID? As for ordering, AFAIK the order of outputs and inputs has to match, so any new SV inputs in a shader stage would indeed have to come at the end of the list. – Nathan Reed Jul 22 '14 at 4:29
• @Nathan Reed thanks for the tip about the debug layer, I'll check that out. I'm not sure if SV_GSInstanceID and SV_InstanceID are the same thing or not, but they seem like distinct semantics. – lunkhound Jul 22 '14 at 7:23

I tested it out and verified that it does indeed detect when shader signatures are incompatible. I also verified that new SV inputs to a shader stage must come last in the list of inputs.