[Resolved] Zero-copy model update with instancing

I was pleased to see the new instancing feature in Optix Prime. A feature we would like to see, and please let me know if it already exists, is the ability to supply a transformation matrix to a particular model in a scene between subsequent ray traces. This would be useful as it would only require localized updates to a single acceleration structure (and depending on how that acceleration structure is implemented those updates could be simple transforms). Having to subsequently copy the entirety of a scene would be expensive between traces.

Hi Adam,

Either Prime’s instancing supports this, or I don’t understand what you mean. You can modify the transform on a single instance between ray tracing queries. This doesn’t rebuild the model’s BVH, only the top-level BVH.

So I guess my question is to clarify some confusion about the Prime API. If I were to modify the transformation of a single instanced model by calling the rtpSetModelInstances function (with all identical transformation matrices but one, and the same descriptors for the models), I would or wouldn’t need to call rtpModelUpdate()? And if it is in fact needed, would it be a zero-copy operation with minimal changes to the Trbvh?

Hi Dave,

refering to primeInstance Example:

// Create Transform
for(int i=0;i<numInstances;i++) {
   createTransform(transforms[i], invTransforms[i], sceneSize, baseScale[modelId]);
// Now Create Instances
scene->setInstances(numInstances, RTP_BUFFER_TYPE_HOST, &instances[0], 
                        RTP_BUFFER_FORMAT_TRANSFORM_FLOAT4x3, RTP_BUFFER_TYPE_HOST, &transforms[0] );
// BVH Update
// now change transform again
for (int i = 0; i < 1; i++) {
   transforms[i] = SimpleMatrix4x3(
   c, 0, -s, tx,
   0, 1, 0, 0,
   s, 0, c, tz

// It seems that it only works, if i use setInstances + update again

scene->setInstances(numInstances, RTP_BUFFER_TYPE_HOST, &instances[0], 
                        RTP_BUFFER_FORMAT_TRANSFORM_FLOAT4x3, RTP_BUFFER_TYPE_HOST, &transforms[0] );

// ...

This way the only way that worked for me to update the transform for the instances.
Unfortunately, the Performance of the second setInstances+update is the same as the first (both 30ms on GTX 980), although i only want to change one transform.

Or is there another way to update the transform for instances?

This looks correct. You need the call to update() to rebuild the top-level BVH with the new transforms. This does not rebuild the “leaf” BVHs, which are usually a lot heavier. We do not have an API function to set a single transform, and you would still need the call to update() anyway, so I don’t think it would lower your time much.

30ms seems long for a GPU build on a GTX 980. Please confirm that you are passing “-c cuda” to primeInstancing.

The default on that sample – for no good reason that I can see – is to do a CPU build and a CPU trace, which could explain the 30ms. When I tested this just now on a Quadro card I saw about 5 ms for setInstances+update, almost all spent in the build.

If you can confirm, then I’ll make a note to change the default.

Hi dlancewell,

indeed i missed the -c cuda flag.
Now i get 4 ms. Even with much larger OBJ Files.


Thanks for confirming. I’ll mark this as resolved and also change the default value of “-c” for the next release.