4
votes

I've been asked to split questions which I asked here:

HLSL and Pix number of questions

I thought two and three would both fit in the same question as a solution of one may help resolve the other. I'm trying to debug a shader and seem to be running into issues. Firstly Pix seems to be skipping a large amount of code when I'm running analyse mode. This is analysing an experiment with F12 captures and with D3DX analysis turned off. I have to turn it off as I'm using XNA. The shader code in question is below:

float4 PixelShaderFunction(float2 OriginalUV : TEXCOORD0) : COLOR0
{   

    // Get the depth buffer value at this pixel.  
    float4 color = float4 (0, 0,0,0);
    float4 finalColor = float4(0,0,0,0);

    float zOverW = tex2D(mySampler, OriginalUV);  
    // H is the viewport position at this pixel in the range -1 to 1.  
    float4 H = float4(OriginalUV.x * 2 - 1, (1 - OriginalUV.y) * 2 - 1,  
    zOverW, 1);  
    // Transform by the view-projection inverse.  
    float4 D = mul(H, xViewProjectionInverseMatrix);  
    // Divide by w to get the world position.  
    float4 worldPos = D / D.w;  

    // Current viewport position  
    float4 currentPos = H;  
    // Use the world position, and transform by the previous view-  
    // projection matrix.  
    float4 previousPos = mul(worldPos, xPreviousViewProjectionMatrix);  
    // Convert to nonhomogeneous points [-1,1] by dividing by w.  
    previousPos /= previousPos.w;  
    // Use this frame's position and last frame's to compute the pixel  
       // velocity.  
    float2 velocity = (currentPos - previousPos)/2.f;  

    // Get the initial color at this pixel.  
    color = tex2D(sceneSampler, OriginalUV);  
    OriginalUV += velocity;  
    for(int i = 1; i < 1; ++i, OriginalUV += velocity)  
    {  
        // Sample the color buffer along the velocity vector.  
        float4 currentColor = tex2D(sceneSampler, OriginalUV);  
        // Add the current color to our color sum.  
        color += currentColor;  
    } 
    // Average all of the samples to get the final blur color.  
    finalColor = color / xNumSamples;  


    return finalColor;
}

With a captured frame and when debugging a pixel I can only see two lines working. These are color = tex2D(sceneSampler, OriginalUV) and finalColor = color / xNumSamples. The rest of it Pix just skips or doesn't do.

Also can I debug in real time using Pix? I'm wondering if this method would reveal more information.

Cheers,

1

1 Answers

1
votes

It would appear that most of that shader code is being optimized out (not compiled because it is irrelevant).

In the end, all that matters in the return value of finalColor which is set with color and xNumSamples.

// Average all of the samples to get the final blur color.  
finalColor = color / xNumSamples; 

I am not sure where xNumSamples gets set, but you can see that the only line that matters to color is color = tex2D(sceneSampler, OriginalUV); (hence it not being removed).

Every line before that is irrelevant because it will be overwritten by that line.

The only bit that follows is that for loop:

for(int i = 1; i < 1; ++i, OriginalUV += velocity)  

But this would never execute because i < 1 is false from the get-go (i is assigned a starting value of 1).

Hope that helps!


To answer you second question, I believe to debug shaders in real-time you need to use something like Nvidia's FX Composer and Shader Debugger. However, those run outside of your game, so results are not always useful.