Search code examples
windowsreverse-engineeringdirect3dpixel-shaderdirect3d11

Shader inputs to registers mapping


I have a compiled pixel shader 4.0 (I don’t have source code for that), with the following in the input signature:

// Name                 Index   Mask Register
// TEXCOORD                 4   xyz         4
// TEXCOORD                 8      w        4

There’re are other input slots, I’ve only pasted the interesting lines of the signature.

As you see, the signature says both TEXCOORD4 and TEXCOORD8 input values go to v4 input register, the former one to xyz fields, the latter one to w field.

MSDN says the type of TEXCOORD[n] input is float4.

Which component of TEXCOORD8 input value goes to the v4.w field, x or w?


Solution

  • I don't think that mapping is specific to a particular component - the HLSL compiler is just attempting to map the inputs to a more efficient layout. I'm fairly certain the input signature for the shader is going to look something like:

    float4 myPixelShader(float3 input_f3 : TEXCOORD4, float input_scalar : TEXCOORD8)
    {
        // ...
    }
    

    so if you're looking to create a vertex shader that outputs to this particular shader, you could just mirror that layout in your output, so something like:

    struct MyInterpolants
    {
        float3 something : TEXCOORD4;
        float  something_scalar : TEXCOORD8;
    }
    
    MyInterpolants MyVertexShader(...)
    {
        MyInterpolants o;
    
        float3 calc;
        float4 some_var;
    
        // Some code here that does something and fills elements of some_var and calc
    
        o.something = calc;
        o.something_scalar = some_var.z;
    
        return o;
    }
    

    should map just fine. It doesn't really matter which element of a local variable is mapped to that output, as long as you're passing a scalar and the signatures between the pixel shader input and vertex shader outputs match. So you could pass x, y, z or w to that scalar output and it'll work out the same.