Multiple raygen functions within same pipeline in Optix 7?

In Optix 6, the was a “context launch index” to select which entry program to run. Now in Optix 7, only a single “raygen” program can be specified per pipeline.
I have a Optix 7 workflow split in multiple phases operating on the same data (sbt, ray types, programs) to reduce divergence and having overly complex Optix programs. Since I essentially only want to change the raygen program across phases, compiling multiple near-identical pipelines per phase seems wasteful.
I could use a switch statement at run-time with a “phase” parameter in the raygen program passed by a record, but is there a better solution? Or will the performance overhead be negligible?

Now in Optix 7, only a single “raygen” program can be specified per pipeline.

That’s actually not the case.

There can be as many ray generation programs inside an OptixPipeline as you need, but there can be only one inside the Shader Binding Table (SBT) CUdeviceptr raygenRecord.

There are some things to consider when putting many raygen programs into one OptixPipeline.

Above link effectively answers your question already. Just to formulate things again with pros and cons:

1.) Recommended because that works fully asynchronously:
Set up as many SBTs as you have ray generation entry points. Set the CUdeviceptr raygenRecord to the entry point you want. All other SBT records remains identical in all SBTs. Means since those are only pointers, there is no duplicated data on the device and all optixLaunch() use the same pipeline, same stream, but different SBTs.

2.) Synchronous, not fully recommended. (If you need to sync between launches anyway to grab the results etc. it’s not that bad.)
Instead of using different SBTs, use only one and exchange the CUdeviceptr raygenRecord between launches.
That would be slower because since optixLaunch() calls are asynchronous, you would need to synchronize with the CUDA stream before you can manipulate the SBT.
(Similar for any data in the constant launch parameter buffer, BTW.)

3.) If what changes in the ray generation program is only the projection, implement the projection as direct callable programs and simply select the necessary projection program with an index in the optixLaunch() constant parameter block. That would only require a single raygeneration program
This can even be updated asynchronously with a cuMemcpyHtoDAsync() if the indices are sourced from different host locations.
Example were I use that method:

Hi Detlef,
Thank you very much for your fast and detailed reply.