Opening a USD stage and rendering in a separate thread

I have a C++ physical simulation app which opens the USD stage to read physics from it and start the simulation. Now I’d like a simple debug visualization but I’m really concerned that this might impact my simulation requirements (200hz, cannot slow this down due to hardware in the loop).

What would the best way to go about this? I’m comfortable with the storm GL renderer but can I just UsdStage::Open(usdFilePath); the same stage into another thread and proceed to do the rendering from there (the main simulation thread would send transforms data to the secondary ‘debug visualization’ rendering thread to a queue asynchronously - again real time visualization is not important here, just a debug visualization of the simulation progress) or will I run into some sort of issues? (or maybe there’s a better way?)

I’m mostly afraid that if I loaded my OpenUSD library and opened a stage in the main thread, if I create another thread and open another stage from that secondary thread there could be some global state in OpenUSD that might trigger problems.

In general, you should be fine to have stages and layers on different threads. The only issue is that you have to make sure you aren’t reading and writing from different threads to the same layers without a synchronization primitive or something since layers aren’t RW thread safe.

1 Like