I’ve been experimenting with OptiX and trying to retrieve the size of a BVH (Bounding Volume Hierarchy) structure after it’s been built. I came across some discussions where developers mentioned the build time and memory usage of different primitives used to construct BVH trees, but I couldn’t find a direct method for retrieving the size of the BVH in OptiX.
Could anyone please share the recommended method to get the size of a BVH in OptiX? Is there a function that directly provides this information, or is it something that needs to be estimated using specific calculations?
The final size of a BVH in OptiX is calculated during the BVH build, and can be emitting as a property of the build. This will allow you to allocate a smaller buffer, move your BVH, and release the initial buffer that is slightly oversized, if you want. We call this process ‘compaction’, and you can find examples of it in the OptiX SDK. You can find more info in the OptiX Programming Guide’s section on compacting acceleration structures.
Here’s a code snippet from optixPathTracer demonstrating how to get the final BVH size, which is stored in the variable compacted_gas_size. I’ve included the call to optixAccelCompact after the final size is queried, just to show the context.