fix(webgpu-rt): dynamic rayQuery TLAS leaf-start so picks hit for realistic instance counts (#25) #26
No reviewers
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!26
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "claude/issue-25"
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?
Summary
Fixes the WebGPU software ray-query shim's TLAS traversal, which used a
compile-time-constant leaf-start (
TLAS_BVH_LEAVES_START = 16384 - 1)while the actual TLAS sweep tree is built at depth
log2(next_pow2(instanceCount)). For any scene with fewer than 8193instances the padded leaf count is far below 16384, so no node index
ever reached the hardcoded leaf start — every node looked internal, the
descent walked into zeroed out-of-tree AABBs, and
_rqTraverseTlasreported a permanent miss. This broke every
rayQuery=truecompute shaderon the WebGPU backend (builder picking, splash queries, …).
Fix
The shim now derives its leaf-start the same way the megakernel
_rtwTraverseTlasdoes — from a per-build dynamic value:RqTlasMeta.nPaddeduniform at@group(1) @binding(10), writteneach
wgpuBuildTLASfromwfNextPow2(instanceCount).wgpuDispatchCustom,wgpuDispatchCompute) and declared in both rayQuery BGLs._rqTraverseTlascomputesleavesStart = rqTlasMeta.nPadded - 1uinstead of the constant.
Test
Adds
examples/RayQueryPick: an 8³ = 512-instance TLAS (squarely in thebroken
< 8193regime) that shoots one analytically-determined raythrough a
rayQuery=truePlainComputeShaderand checks the read-backcommitted hit. Verified in Firefox against a real WebGPU adapter:
hit=1,customIndex=484, andt=40.75all match the analytic answer(ray from x=50 down the row, hitting the +X face of the ix=7 cube at
x=9.25). Before the fix this read back a permanent miss.
crafter-build testis green.Screenshots
The example also renders the 512-cube grid through the wavefront RT
pipeline:
Resolves #25