novolis-governance / imports-todo/internal-novolis-audit/ilgpu-bvh-slab-parity.md
ILGPU / Vulkan — BVH slab parity with `Novolis.Math.Geometry`
Policies that keep the org coherent
dotnetgovernancenovolis
What
Align device-side BVH traversal numerics with the host-tested implementation in Math:
| Component | Status (2026-05-25) |
|---|---|
| CPU `PathTracerEngine` | Uses `BvhRaycast` + `AxisAlignedBox.RayInterval` + `GeometryConstants` |
| `IlgpuPathTracerKernels.RaySlabIntersect` | Private duplicate; hard-coded `1e-15f` parallel epsilon |
| `IlgpuPathTracerKernels` triangle test | `Float3` Möller–Trumbore (expected on device) |
| `GpuBvhNode.From(TriangleBvhNode)` | Layout adapter only — keep |
Import options (pick one per milestone):
- Documented parity contract — comments + ILGPU unit test comparing host
AxisAlignedBox.RayIntervalresults to kernel slab for a grid of rays/boxes. - Shared constants — copy
GeometryConstants.RayParallelEpsiloninto ILGPU asconstwith same literal (no runtime dep on Math in kernels). - Long-term — shared-source file included in both Math and ILGPU projects (only if maintenance cost is justified).
Why
- Shadow and primary rays that disagree between CPU fallback and ILGPU backend produce “works in CPU, wrong on GPU” bugs that are expensive to debug.
- Math already owns BVH structure; governance says Physics/Rendering must not fork slab tests silently.
- Vulkan path currently delegates to CPU-backed surface in tests; ILGPU is the path that still carries duplicate slab logic.
How
- Short term (recommended)
- In
IlgpuPathTracerKernels, set parallel epsilon to1e-15fvia named constant matchingGeometryConstants.RayParallelEpsilon. - Add test in
Novolis.Rendering.Unit(Backends.Igpu): for N random boxes/rays, hostAxisAlignedBox.RayIntervalmatches a small C# port ofRaySlabIntersectlogic (or invoke CPU reference and compare bool + tEnter/tExit).
- Medium term
- Add
/// <remarks>onRaySlabIntersectciting Math as authority; link toBvhRaycastTests/AxisAlignedBox_RayInterval_HitsUnitCubeFace.
- Do not
- Reference
Novolis.Math.Geometryfrom ILGPU kernel assemblies if it pulls disallowed types into device compilation — keepFloat3on device.
Acceptance
- Documented epsilon source of truth is
GeometryConstants. - At least one automated parity test between host slab and ILGPU slab helper.
- No second public
RaySlabIntersectin Rendering.Runtime.