Is it possible for Optix to run in a background (host) thread

Apologies if this is mentioned elsewhere but I couldn’t much detail about host threads, just multiple Optix contexts.

My issue is that I would like to render my (progressively path traced SDF fractal) scene using a tile based rendering method, I was hoping this would help keep the interactive preview responsive because after each tile launch Optix would return control to the host code long enough to update the GUI etc. However, because everything is single threaded currently there’s no opportunity for the user to actually stop the render in progress / break out of the tile loop because any variables/buttons events are still only processed after all the tiles have launched and completed.

Before I spend some time making the design more multi-threaded I wanted to double check if this is even possible or a good idea, currently I use the GL interop to use my Optix result buffer directly as a viewport. I don’t believe OpenGL plays well with multiple threads at all, so I’m assuming I would have to do something like

Background thread

  • Launch each tile and place the results in a non-GLBO Optix buffer
  • If some 'restart' variable switch has been set to false, break out of the tile render loop and restart
  • If some 'stop' variable flag has been set to false, break out of the tile render loop and clean up

Host thread

  • Periodically copy over the contents of the Optix result buffer into an OpenGL buffer for the purpose of visualisation
  • If the camera has moved, the viewport resized or if the user closes the main window, set the restart/quit flag

Would this work at all? And would it even improve performance, since now renders will be much slower despite potentially improving the visual feedback speed (the price of launching separate tile renders is going to be much slower than doing it in one go, and copying over entire buffers for the purpose of GL visualisation would be slower than using the GL interop).

Any help is appreciate, thanks!

Running OptiX in a separate thread should just work.
Just make sure only that thread is doing OptiX calls.
The OptiX API is not guaranteed to be multi-threaded safe.

Doing this will not improve the renderer time.
Also if the GUI is run on the same GPU as OptiX there will always be a sluggishness to the GUI unless your OptiX renderer has a very small runtime per frame.
With a dedicated compute GPU or VCA cluster, running OptiX fully asynchronous in a separate host thread would make the GUI rendering independent of the ray tracing. That’s one thing on my list to implement in a renderer app.

I see, thanks for the advice!