Divergence and step by step path tracing


I am trying to implement a path tracing renderer with OptiX, and I am wondering how efficient OptiX is at minimizing divergence. I already have it working with diffuse material, but I would like some information before proceeding forward and adding other materials.

To explain a little bit, at every step of tracing a path, I update the ray information with the material information that it has just intersected, then decide on whether or not to terminate the ray. If not, I then recast the ray according to a random material (if one object is partly glossy, partly diffuse, and partly reflective that makes 3 possible different BRDF computations) and so on and so on…
Because at every step, rays can either be emitted according to different BRDFs, sometimes secondary rays are cast (for direct lightning estimation), and sometimes even terminated (the choice of terminating a ray is random), this creates divergence.
So I have thought of 2 choices.

  • Assume OptiX is good at minimizing divergence and do it naively.
  • Do the computation step by step. Let me explain my idea a bit :
    I have a “pool” of diffuse rays, a “pool” of glossy rays and so forth…
  1. Find a pool that is sufficiently full and make it the actual pool. If none found, then select the camera for starting new paths as the actual pool.
  2. Trace all the rays from the actual pool, which include BRDF computation (in this way we only use a single BRDF/raygen program at every step).
  3. Upon intersection, update the ray information with the material from the intersected object. Choose whether to retrace a ray or not. If yes, select a material randomly and put the ray in the appropriate ray "pool". If no, accumulate the ray result in the appropriate output buffer.
  4. Back to step 1

But the biggest problem with this is that I do not know how to implement these “pools” of rays.
In my implementation, some part of the scene can be much more difficult to render than others, so I would trace way more paths for one pixel than for another, so I do not think using buffers that reflect that would work.

So, is OptiX able to efficiently manage diverging programs, or should I find a way to remove divergence? Any tip or link to papers for the second part?

Thank you in advance.