WebGPU rayQuery TLAS traversal hardcodes leaf-start (16383) — picks always miss below 8193 instances #25
Labels
No labels
claude:done
claude:in-progress
claude:ready
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Catcrafts/Crafter.Graphics#25
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
WebGPU rayQuery TLAS traversal uses a hardcoded leaf-start, so picks miss for any realistic instance count
additional/dom-webgpu.jsprovides a softwarerayQuery*shim for compute shaders (rayQueryFlagpipelines). Its TLAS traversal_rqTraverseTlasdetects BVH leaves with a compile-time constant:But the megakernel traversal
_rtwTraverseTlascorrectly uses the per-frame dynamic value:tlasNPadded = wfNextPow2(instanceCount)(see the TLAS build, ~line 3220). For any scene with fewer than 8193 instances,tlasNPaddedis far below 16384, so in the rayQuery shim no node index ever reaches 16383 — every node is treated as internal and the descent walks2*nodeIdx+1into zeroed/out-of-tree AABBs, which fail the slab test. Result:_rqTraverseTlasreports a permanent miss. The rayQuery path can only ever hit wheninstanceCounthappens to land in(8192, 16384].This breaks every
rayQuery=truecompute shader on the WebGPU backend (builder picking, splash queries, …). The hardware-RT path on Vulkan is unaffected because it uses the real driver ray query.Repro
3DForts builder picking: enter a match (~2000 RT instances), hover any node/brace — the GPU picker's
PickerResult.hitstays 0 for the whole screen, while the identical request returns hits on Vulkan.Suggested fix
Have the rayQuery shim derive
leavesStartfrom the active TLAS the same way the megakernel does — passtlasNPadded(or the BVH leaf count) into the rayQuery group(1) bindings / a small uniform, instead of the hardcodedTLAS_BVH_N_PADDED - 1u. The leaf count is already known at TLAS-build time (currentEntryOrderlength /wfNextPow2(instanceCount)).Workaround in the meantime
Downstream (3DForts #92) we fell back to a CPU ray test for builder picking on the WebGPU target so selection/build works in the browser; the GPU rayQuery picker can be re-enabled once this is fixed.