Open heyx3 opened 8 months ago
It's unclear how to pass existing allocations/BVHs/buffers to the BVH builders. For instance, the mini tree builder needs to create mini-trees that require their own allocations of impredictable size, and other builders over-allocate in order to avoid allocating often when building the tree (they over-allocate, then shrink the resulting buffers). This design is very efficient and simple and I would like to keep it as it is.
While it is theoretically possible to pass an additional buffer for builders other than the mini-tree one, there's a good chance that it won't be large enough anyway (due to the over-allocation+shrinking design). That said, if your only concern is performance, you can just drop your old BVH right before building a new one with the same size, and the OS will likely re-use the blocks that were just freed.
If your concern is running this code in an embedded scenario, or some other application where allocations should be tightly controlled, the real solution here would be to use custom STL allocators (that would allow the builders to use a pool-based allocator, for instance). I am open to a PR tackling that problem, if you have the time.
Currently, if I'm reading the builders correctly, they always allocate a new
bvh
instance when building. It would be nice to have the option of re-using allocations.