Skip to content

startup: lower the binary16 BVH box node - #3032

Open
lambirou wants to merge 14 commits into
R0Y00:mainfrom
lambirou:startup/bvh-intersect-box16
Open

lambirou wants to merge 14 commits into
R0Y00:mainfrom
lambirou:startup/bvh-intersect-box16

Conversation

@lambirou

@lambirou lambirou commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

What changed

This is the binary16 slice of image_bvh_intersect_ray, stacked on the merged FP32 box slice (#2922) and the corrected FP32 semantics from #3040.

  • Accepts the 64-byte binary16 box node (kind 4): four child pointers at bytes 0..15 and four boxes of six binary16 values at bytes 16..63.
  • Widens the bounds with f16tof32 and reuses the slab test, extent clip, inactive-box rule, descriptor validation and sort rules of the FP32 helper.
  • Keeps the shader: correct FP32 BVH descriptor byte units and child results #3040 result rules for both kinds: the descriptor base is decoded from 256-byte units, the 48-bit end-exclusive check uses the node size, unsorted results stay in their original child slots with 0xffffffff for holes, and sorted misses use a positive-infinity key.
  • The translator emits x2w_bvh_intersect_box16 for kind 4 and keeps the same srv <i> bvh base 0x<base> size 0x<size> manifest line.
  • Triangle nodes, the 64-bit form, A16, dynamic descriptors and every other node kind are still refused by name with no partial output.

The node layout follows Mesa 25.1.0 RADV's radv_bvh_box16_node (MIT). No game files or captures are included.

Tests

python -B tests/startup_gfx2hlsl_bvh_check.py
ctest --preset <dev|release> --no-tests=error -R '^startup_gfx2hlsl_bvh' -V

The combined check writes four FP32 nodes, four binary16 nodes and 21 rays and compares the 1232-byte readback. Binary16 bounds are packed as binary16 and read by the independent tests/gfx1030_bvh_box/bvh_model.py; one bound at 1.1 rounds to 1.099609375 so a ray extent between the two values proves f16tof32 is used. Six mutants cover miss filling (box32 and box16), unsorted compaction with a box16 witness, the finite miss key, the low-byte base check and the high-byte base handling.

Passed on b7117d46, dev and release:

  • startup_gfx2hlsl_bvh: pass, both DXC compiles ok.
  • startup_gfx2hlsl_bvh_dispatch_warp: pass, 21/21 cases and 6/6 controls on Microsoft Basic Render Driver 1414:008c, driver 10.0.26100.10068.
  • startup_gfx2hlsl_bvh_dispatch_hardware: pass, 21/21 cases and 6/6 controls on AMD Radeon RX 9060 XT 1002:7590, driver 32.0.32029.2010.

The branch is merged with current main e1ea515d and preserves the #3040 descriptor/count semantics. The earlier Windows receipt predates those changes.

Limits

This is a translator slice. It does not bind the node buffer on a D3D12 device or establish title behavior. The runtime manifest loader does not yet consume the bvhbase line, so a real dispatch is refused rather than bound at a wrong address.

Refs #870, #1268, #2922, #3040.

AI-assisted.

@chadhyatt

Copy link
Copy Markdown
Contributor

I am preparing an AI-assisted backport patch from x2w-microlift for three independently reproducible FP32 corrections: encoded descriptor base is in 256-byte units (keep the upper base byte), unsorted hits preserve original child slots (existing box32/mixed-nosort witness), and misses use positive infinity rather than FLT_MAX. These are shared with this FP16 extension; I would prefer to land the focused FP32 correction first and have this PR adopt the same semantics.

One separate FP16-specific point from RDNA2 ISA Table 49: size encodes the number of nodes minus one, so a single-unit binary16 node at offset == size, including size zero/offset zero, is valid. The current two-unit bounds check and shared size-zero refusal need adjustment for box16. I will keep the standalone FP32 patch source-built/title-neutral and avoid runtime binding changes.

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of head c7a23a1 (a merge of main on top of the code I read; the PR-only diff is the same 3 files) (comment only).

Read the diff of tools/startup/gfx2hlsl.py (85 lines): kind-4 (binary16) box nodes are now lowered through x2w_bvh_box16_slot / x2w_bvh_intersect_box16, with a 64-byte node alignment check (offset & 0x3f), the same descriptor-size rule in 64-byte units, miss compaction, and a separate path for unsorted boxes (the sort network is not reused, with the reason in a comment). The six half values per child are read as f16tof32 and the box32 maths is reused, which is exact.

The check has what a lowering needs: startup_gfx2hlsl_bvh_dispatch_warp / _hardware run the generated HLSL on a node buffer and compare the readback with the CPU reference(...) for both box32 and box16 cases (including the half-node cases), plus the translator-level startup_gfx2hlsl_bvh.

Ran locally (Linux; no dxc here, so the dispatch part skips): python3 -B tests/startup_gfx2hlsl_bvh_check.py: all ok.

  • Mutation A: the lo.z half read changed from h1 to h2 in the HLSL helper: the Linux part does NOT catch it (HLSL maths only runs in the dispatch test); only the WARP dispatch can.
  • Mutation B: accepted kinds reduced to (5,): the translator control fails (StopIteration, no box16 call).

No defect found. It only lacks a Windows receipt on this head: ctest -R "startup_gfx2hlsl_bvh" (dev + release).

AI-assisted; commands listed were executed locally.

Copy link
Copy Markdown
Contributor Author

Windows receipt on c7a23a1b (head), main e446b072:

ctest --preset dev --no-tests=error -R "startup_gfx2hlsl_bvh"
3/3 passed: startup_gfx2hlsl_bvh, dispatch_warp, dispatch_hardware
ctest --preset release --no-tests=error -R "startup_gfx2hlsl_bvh"
3/3 passed: same three

Hardware adapter: AMD Radeon RX 9060 XT (1002:7590, driver 32.0.32029.2010). Both WARP and hardware runs report all six FP32 and five binary16 dispatch cases exact; the miss-fill control also passes.

The translator controls and both DXC compiles pass in dev and release. No code changes since the head you reviewed; this is only the requested Windows receipt.

@chadhyatt

Copy link
Copy Markdown
Contributor

The focused FP32 correction is available in #3040 now. It also checks the 48-bit node-address end-exclusive bound. Portable CPU model/translator checks passed; GPU dispatch remains unverified on this host.

R0Y00 commented Nov 27, 2026

Copy link
Copy Markdown
Owner

#3040 has landed on main as 1c879506. Please rebase or merge the current main into this PR and preserve the descriptor base in 256-byte units, the 48-bit end-exclusive bound, positional misses with sorting disabled, and the +infinity miss key. Please carry the focused controls into the combined box32/box16 run on the new head. The earlier Windows receipt predates those semantics.

Adopt the FP32 BVH descriptor unit decode, 48-bit end-exclusive bound, positional unsorted results and positive-infinity miss keys for both box kinds. Binary16 fixtures are packed as half values and share the independent model; dev and release WARP and RX 9060 XT dispatch pass 21 cases plus six mutants.

Copy link
Copy Markdown
Contributor Author

Merged main at e1ea515d into this branch. Head is now b7117d46; the Windows receipt was taken on 13167033, and the only later change is a one-line correction to the node count in the experiment note.

The binary16 path now shares the #3040 semantics:

  • the descriptor base stays encoded in 256-byte units and is decoded once for the manifest and binding;
  • the 48-bit end-exclusive check uses the node size (64 bytes for binary16, 128 bytes for FP32), so a node ending exactly at the boundary translates and a wrapping node is refused before any resource is bound;
  • with sorting disabled both helpers return uint4(c0, c1, c2, c3) in child slots, with 0xffffffff for a miss;
  • sorted misses use asfloat(0x7f800000u), so the finite FLT_MAX hit still sorts ahead.

The combined check writes four FP32 nodes, four binary16 nodes and 21 rays, and compares the 1232-byte readback. Binary16 bounds are packed as binary16 bytes and read by the independent tests/gfx1030_bvh_box/bvh_model.py; one bound at 1.1 rounds to 1.099609375, so a ray extent between the two values proves f16tof32 is used. Six mutants cover miss filling (box32 and box16), unsorted compaction with a box16 witness, the finite miss key, the low-byte base check and the high-byte base handling.

Windows receipt on 13167033 (dev and release), ctest --preset <dev|release> --no-tests=error -R '^startup_gfx2hlsl_bvh':

  • startup_gfx2hlsl_bvh: pass, both DXC compiles ok.
  • startup_gfx2hlsl_bvh_dispatch_warp: pass, 21/21 cases and 6/6 controls on Microsoft Basic Render Driver 1414:008c, driver 10.0.26100.10068.
  • startup_gfx2hlsl_bvh_dispatch_hardware: pass, 21/21 cases and 6/6 controls on AMD Radeon RX 9060 XT 1002:7590, driver 32.0.32029.2010.

The earlier Windows receipt predates the #3040 changes; this one is on the new head.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants