Explanation for loop in PathTracer example

Hey everyone,
i looked through the optixPathTracer example from the 7.3 SDK and was wondering what this for loop from the optixPathTracer.cu in the __raygen__rg() program does.

extern "C" __global__ void __raygen__rg()
{
    int i = params.samples_per_launch;
    do
    {
        for( ;; )   
        {
        }
    }
    while( --i );
}

I’ve seen the expression with for( ;; ) explained somewhere but i can’t remember where. Can anyone give me some info on what this loop is iterating and how it works? Thanks in advance!

OK so after digging further through the internet i found that this basically is a C for loop that doesn’t use any code for the initialization, condition and after running, so it is essentially a while(true){} function that relies on a break inside of it…

Just to add a little more color, the outer loop (the do/while) is looping over samples, while the inner loop (the for(;;)) is looping over path depth. This is what the iterative path tracing algorithm looks like: a loop over depth in the raygen program. The common alternative is to put an optixTrace() call inside a closest-hit shader, and when you do that, the path tracing becomes recursive rather than iterative. The advantage of iterative is that it requires less stack space.


David.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.