0
votes

I have the following compute shader code for computing depth of field. However, very unusually, the loop executes just once, even if g_rayCount is 10. Please have a look in the main function raycastercs where the for loop lies.

//--------------------------------------------------------------------------------------
// Compute Shader
//-------------------------------------------------------------------------------------

SamplerState SSLinear
{
    Filter = Min_Mag_Linear_Mip_Point;
    AddressU = Border;
    AddressV = Border;
    AddressW = Border;
};

float3 CalculateDoF(uint seedIndex, uint2 fragPos)
{
    ;
}

[numthreads(RAYCASTER_THREAD_BLOCK_SIZE, RAYCASTER_THREAD_BLOCK_SIZE, 1)]
void RaycasterCS(in uint3 threadID: SV_GroupThreadID, in uint3 groupID: SV_GroupID, in uint3 dispatchThreadID :SV_DispatchThreadID)
{
    uint2 fragPos   = groupID.xy * RAYCASTER_THREAD_BLOCK_SIZE + threadID.xy;
    float4 dstColor = g_texFinal[fragPos];
    uint seedIndex  = dispatchThreadID.x * dispatchThreadID.y;


    float3 final = float3(0, 0, 0);
    float color = 0;

    [loop][allow_uav_condition]
    for (int i = 0; i < g_rayCount; ++i);
    {
        float3 dof = CalculateDoF(seedIndex, fragPos);
        final += dof;
    }

    final *= 1.0f / ((float) g_rayCount);
    g_texFinalRW[fragPos] = float4(final, 1);
}


//--------------------------------------------------------------------------------------


technique10 Raycaster
{
    pass RaycastDefault
    {
        SetVertexShader(NULL);
        SetGeometryShader(NULL);
        SetPixelShader(NULL);
        SetComputeShader(CompileShader(cs_5_0, RaycasterCS()));
    }
}
1

1 Answers

4
votes

Remove the semicolon at the end of the for statement

for (int i = 0; i < g_rayCount; ++i)  // removed semicolon
{
    float3 dof = CalculateDoF(seedIndex, fragPos);
    final += dof;
}

As I guess you know, the semicolon was just running an empty for loop, then the code in braces was thereafter executed just once.