Optix 7 Acceleration Structure Dynamic Updates and Compaction

I just wanted to know how to dynamically update a compacted acceleration structure.
So I’ve done the below from examples in the docs but don’t know how to do #4

  1. Build acceleration struct GAS (optixAccelBuild() with OPTIX_BUILD_OPERATION_BUILD)
  2. Compact GAS (optixAccelCompact())
  3. Update GAS (optixAccelBuild() with OPTIX_BUILD_OPERATION_UPDATE)
  4. Recompact GAS (call optixAccelCompact() again?)

Do I need to call optixAccelCompact() again after I update the GAS or is this done implicitly?

From the docs it says…
“A compacted acceleration structure supports dynamic updates only if the uncompacted source acceleration structure was built with the [OPTIX_BUILD_FLAG_ALLOW_UPDATE] build flag”
but don’t have an example how it is done.

I haven’t tried that myself either, but the documentation is pretty clear.
It says you can update a compacted AS when the original un-compacted AS has been built with the OPTIX_BUILD_FLAG_ALLOW_UPDATE flag.

Literally: 5.7 Compacting acceleration structures “A compacted acceleration structure may still be used for traversal and update operations or as input to optixAccelRelocate.”

Means your initial AS should be built with both the flags OPTIX_BUILD_FLAG_ALLOW_UPDATE | OPTIX_BUILD_FLAG_ALLOW_COMPACTION ORed together.
Then build that AS with optixAccelBuild(OPTIX_BUILD_OPERATION_BUILD) as usual and compact it with optixAccelCompact().

Later you should be able to update the compacted AS with an optixAccelBuild(OPTIX_BUILD_OPERATION_UPDATE).

Just give it a try.

Other resources about this topic:
My nvlink_shared example does Geometry AS compaction:
https://github.com/NVIDIA/OptiX_Apps/blob/master/apps/nvlink_shared/src/Device.cpp#L1234
My intro_motion_blur example doesn’t do vertex motion and only needs to update the root Instance AS: https://github.com/NVIDIA/OptiX_Apps/blob/master/apps/intro_motion_blur/src/Application.cpp#L2483

1 Like

Just to add to what Detlef said:

Do I need to call optixAccelCompact() again after I update the GAS or is this done implicitly?

No, you should not re-compact your GAS after an update. The UPDATE operation on the GAS will not cause the GAS to fragment or become uncompacted. Updating a GAS will only modify position data of the boxes in your BVH, it will not change the hierarchy, and it will not add or remove any boxes. This is why the UPDATE operation must contain the exact same primitives as the original BUILD operation, and the options to optixAccelBuild() must be exactly the same when updating as they were when building the first time. These reasons are also why updating a GAS many times or using large motions can cause the GAS traversal performance to slow down over time. If the motion of the primitives in your GAS is large over time, consider rebuilding your GAS occasionally.


David.

1 Like

Edit: I mistyped optixAccelBuild() the first time in my reply. In case the email notifications went out that way, you call optixAccelBuild() multiple times, but you only need to call optixAccelCompact() once for each BUILD operation, and you don’t need to call optixAccelCompact() after any UPDATE operations. I haven’t tried that, but I believe it will be a no-op, you’ll just waste time.

I should also add, since I brought up the notion of rebuilding your GAS occasionally, you can only rebuild your GAS if you don’t use compaction at all. The BUILD operation always requires an output buffer large enough for an uncompacted GAS. Only the UPDATE operation will work on an output buffer that is already compacted.


David.

1 Like

Thanks David.
That makes more sense now.