Sign in to follow this  
matt77hias

X4580 this variable dependent on potentially uninitialized data

Recommended Posts

[maxvertexcount(3)]
void GS(triangle PSInputPositionNormalTexture input[3],
    inout TriangleStream< PSInputPositionNormalTexture > output_stream) {

    // Calculate the dominant direction of the surface normal.
    // 
    // Face normal based on the triangle edges:
    // normalize(cross(input[1].p_view - input[0].p_view, 
    //                 input[2].p_view - input[0].p_view))
    // Normalization is not needed (i.e. uniform scaling):
    const float3 abs_n = abs(cross(input[1].p_view - input[0].p_view, 
                                   input[2].p_view - input[0].p_view));
    const uint dir_xy = (abs_n.x > abs_n.y)       ? 0u : 1u;
    const uint dir    = (abs_n.z > abs_n[dir_xy]) ? 2u : dir_xy;
    
    PSInputPositionNormalTexture output[3];

    // Project the triangle in the dominant direction for rasterization (p),
    // but not for lighting (p_view).
    [unroll]
    for (uint i = 0u; i < 3u; ++i) {
        output[i].p.xyz = input[i].p_view - g_voxel_grid_center;
    
        [flatten]
        if (0u == dir) {
            output[i].p.xy = output[i].p.yz;
        } else if (1u == dir) {
            output[i].p.xy = output[i].p.zx;
        }

        // [m] * [voxels/m] * [1/voxels]
        output[i].p.xy  *= (g_voxel_grid_inv_size * g_voxel_grid_inv_resolution);
#ifdef DISSABLE_INVERTED_Z_BUFFER
        output[i].p.zw   = float2(0.0f, 1.0f);
#else  // DISSABLE_INVERTED_Z_BUFFER
        output[i].p.zw   = float2(1.0f, 1.0f);
#endif // DISSABLE_INVERTED_Z_BUFFER
        output[i].p_view = input[i].p_view;
        output[i].n_view = input[i].n_view;
        output[i].tex    = input[i].tex;
        output[i].tex2   = input[i].tex2;
    }
    
    // For each projected triangle, a slightly larger bounding triangle ensures 
    // that any projected triangle touching a pixel will necessarily touch the 
    // center of this pixel and thus will get a fragment emitted by the rasterizer.
    const float2 delta_10 = normalize(output[1].p.xy - output[0].p.xy);
    const float2 delta_21 = normalize(output[2].p.xy - output[1].p.xy);
    const float2 delta_02 = normalize(output[0].p.xy - output[2].p.xy);
    // Move vertices for conservative rasterization.
    output[0].p.xy += normalize(delta_02 - delta_10) * g_voxel_grid_inv_resolution;
    output[1].p.xy += normalize(delta_10 - delta_21) * g_voxel_grid_inv_resolution;
    output[2].p.xy += normalize(delta_21 - delta_02) * g_voxel_grid_inv_resolution;

    // Output a triangle strip of three vertices.
    [unroll]
    for (uint j = 0u; j < 3u; ++j) {
        // Output a vertex.
        output_stream.Append(output[j]);
    }

    // End the current triangle strip.
    output_stream.RestartStrip();
}

I switched to SM 5.1 and suddenly the warnings I originally got, but couldn't explain, mutated into errors.

FXC gives me 6 identical, cryptical, just-figure-it-out-yourself errors:

Error    X4580    emitting a system-interpreted value which is not written in every execution path of the shader. Unconditional initialization may help.

Beside these (which were originally just warnings), I now also got another 4 errors:

Error    X4580    this variable dependent on potentially uninitialized data: delta_10
Error    X4580    this variable dependent on potentially uninitialized data: delta_10  
Error    X4580    this variable dependent on potentially uninitialized data: delta_02  
Error    X4580    this variable dependent on potentially uninitialized data: delta_02

and are associated with the block of code beneath the 

"Move vertices for conservative rasterization." 

But as one can see very clearly, my parameters and all their channels are completely initialized?

 

Edited by matt77hias

Share this post


Link to post
Share on other sites

This solves the issue, though the compiler is wrong.

const float3 p_voxel = input[i].p_view - g_voxel_grid_center;
    
[flatten]
if (0u == dir) {
  output[i].p.xy = p_voxel.yz;
} 
else if (1u == dir) {
  output[i].p.xy = p_voxel.zx;
}
else {
  output[i].p.xy = p_voxel.xy;
}

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this