References:

* "Efficient Incoherent Ray Traversal on GPUs Through Compressed Wide BVHs" 2017, NVIDIA
* https://github.com/jan-van-bergen/GPU-Raytracer
* https://github.com/WeiPhil/nbvh/blob/0a7f8e0e09898ba6e161cd7433325368355e2d2a/include/cuda/accel/bvh8.cuh#L35
* https://github.com/DGriffin91/obvhs/tree/main/src/cwbvh
*

Build

* Consider triangles in groups of up-to 32 (bitmask)
    * Find "lowest" index
    * Walk up, and mark bitmask

Explore additional metrics such as:

* % of empty nodes
* % of utilized triangle slots (up to 3 per child)

Runtime

* Debug shader for raycast, visualize:
    * traversal depth (number of node intersection tests)
    * number of triangle tests
    * amount of memory bandwidth (estimate based on size of what we have to load)

# Findings [2024/12/27]:

> [2026-06-11] The numbers below predate the review-01 fixes (see REVIEW_01_ACTION_PLAN.md) —
> notably the morton sort keyed on box *size* instead of box *center* (F4) and the converter's
> corrupted SAH cost table (F3), both of which directly degrade build quality and time.
> Re-measure before drawing conclusions from this section.

Conclusion for now - not worth it. Too slow to build, and runtime performance inadequate.

// RUNGHOLT, ORIGINAL build mechanism
BVH8 triangles = 24, size = 480 bytes, quality = 88.16 (total=53.92515886274739)
Geometry build: 27701.5078125 ms
BVH2 size total: 465,232,160
BLAS size: 134,670,480 bytes

// RUNGHOLT, NEW (by A.G.)
BVH8 triangles = 24, size = 240 bytes, quality = 145.27999999999997 (total=594.418961181131)
Geometry build: 315166.4069824219 ms
BVH2 size total: 465,232,160
BLAS size: 302,576,640 bytes

## Findings

* Build times are far too long for runtime.
* Binary sizes are considerably smaller than BVH2
* Render times are much worse, in some cases 10x on shadows alone
* Sorting children during traversal does help, as paper claims, by as much as 10%
* packing a lot of triangles is tricky, due to restriction of only being able to address 24 contiunuous primitives per
  node
* you have to try and pack at least 1 triangle per node, otherwise you're wasting the 4 bytes reserved for base triangle
  offset
* original paper requires an extra triangle index array, which is hugely wasteful and creates an extra indirection
  table, which is bad for perf

# microsoft's DXR fallback implementation

https://github.com/microsoft/DirectX-Graphics-Samples/tree/master/Libraries/D3D12RaytracingFallback