Rewrite BVH generation to run faster/handle larger models
umar-ahmed opened this issue · comments
Umar Ahmed commented
Context
The current version of BVH construction is written in a ~150 lines of TypeScript code. This code works well for small models, but for larger models, the page hangs for a bit and becomes unresponsive.
There are a few options I've considered to move forward:
- Move the existing TypeScript code to a Web Worker: This would free up the main thread and not cause locking. It wouldn't really make the process go faster, but might avoid some crashes
- Rewrite the code in a more efficient language like C++ or Rust and compile to WASM: We can take advantage of compiler optimizations and eke out a bit more performance.
- Construct the BVH on the GPU: Using the approach described in this series of blog posts by NVIDIA: https://developer.nvidia.com/blog/thinking-parallel-part-iii-tree-construction-gpu/ , we can construct a Linear BVH on the GPU using the concept of Morton codes to spatially sort the bounding boxes.
Existing Code
https://github.com/umar-ahmed/webgpu-pathtracer/blob/main/src%2Fpasses%2Fraytrace.ts#L511-L631