Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5055432
startup: lower the FP32 box case of image_bvh_intersect_ray
lambirou Nov 26, 2026
2ec454f
startup: keep non-BVH resource manifests from reading a third field
lambirou Nov 26, 2026
34a2c5c
startup: lower binary16 box nodes in image_bvh_intersect_ray
lambirou Nov 26, 2026
c47f598
tests: compile the binary16 BVH helper with DXC
lambirou Nov 26, 2026
1fd5475
tests: dispatch the binary16 BVH helper on WARP
lambirou Nov 26, 2026
cfe00df
Merge remote-tracking branch 'origin/main' into startup/bvh-intersect…
lambirou Nov 27, 2026
35a342d
Merge remote-tracking branch 'origin/main' into startup/bvh-intersect…
lambirou Nov 27, 2026
94e9029
startup: keep unsorted BVH hits in child order
lambirou Nov 27, 2026
07a60ea
merge the sort-disabled BVH fix into the binary16 slice
lambirou Nov 27, 2026
6d2b778
merge main into the binary16 BVH slice
lambirou Nov 27, 2026
6459442
Merge remote-tracking branch 'origin/main' into startup/bvh-intersect…
lambirou Nov 27, 2026
c7a23a1
Merge remote-tracking branch 'origin/main' into startup/bvh-intersect…
lambirou Nov 27, 2026
1316703
Merge origin/main into startup/bvh-intersect-box16
lambirou Nov 27, 2026
b7117d4
docs: correct the binary16 node count in the BVH receipt
lambirou Nov 27, 2026
5640a90
startup: lower triangle nodes in image_bvh_intersect_ray
lambirou Nov 27, 2026
bf0e664
Merge remote-tracking branch 'origin/main' into startup/bvh-intersect…
lambirou Nov 27, 2026
5098855
Merge branch 'startup/bvh-intersect-box16' into startup/bvh-intersect…
lambirou Nov 27, 2026
aa5c901
Merge remote-tracking branch 'origin/main' into startup/bvh-intersect…
lambirou Nov 27, 2026
004fcd0
Merge branch 'startup/bvh-intersect-box16' into startup/bvh-intersect…
lambirou Nov 27, 2026
3ac44c2
startup: treat the BVH descriptor size as a count minus one
lambirou Nov 27, 2026
d70721a
Merge branch 'startup/bvh-intersect-box16' into startup/bvh-intersect…
lambirou Nov 27, 2026
070b12d
startup: use the decoded BVH extent for triangle nodes
lambirou Nov 27, 2026
d2eeb68
Merge remote-tracking branch 'origin/main' into startup/bvh-intersect…
lambirou Nov 27, 2026
a68c9bd
Merge branch 'startup/bvh-intersect-box16' into startup/bvh-intersect…
lambirou Nov 27, 2026
263604f
startup: cover BVH triangle operands and box return mode
lambirou Nov 27, 2026
b2f86a8
Merge remote-tracking branch 'origin/main' into startup/bvh-intersect…
lambirou Nov 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/experiments.md
Original file line number Diff line number Diff line change
Expand Up @@ -4806,6 +4806,9 @@ Native readback remains pending, including the raw miss and disabled-slot
words. The probe leaves translator behavior and form coverage unchanged.
The node model and its witness set are described in
[bvh-node-model.md](experiments/bvh-node-model.md).
The translator slices that consume the model are the
[FP32 and binary16 box nodes](experiments/startup-gfx2hlsl-bvh-box32.md) and the
[triangle nodes](experiments/startup-gfx2hlsl-bvh-triangle.md).

### gfx1013 2D explicit-LOD image gathers

Expand Down
5 changes: 3 additions & 2 deletions docs/experiments/startup-gfx2hlsl-bvh-box32.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ in `min.x`.
for binary16, two for FP32; `size=0` is a one-unit span) and below 4 GiB;
- a constant node pointer whose low three bits are 4 (64-byte aligned) or 5 (128-byte aligned) and inside the
same 4 GiB relative address window; the entire node must fit within the 48-bit absolute address space;
- either value of the sort bit.
- either value of the sort bit, and either value of the triangle return mode bit (bit 120);
it selects the triangle result layout and does not change a box result.

The manifest names the node allocation with `srv <i> bvh base 0x<base> size 0x<size>`, using the decoded
byte address for `base` and the unchanged descriptor size field for `size`. All four original descriptor
Expand All @@ -40,7 +41,7 @@ of this change.

## Refused by name

Triangle nodes (kinds 0..3), every other node kind, `image_bvh64_intersect_ray`, A16,
Every node kind other than 4 and 5, `image_bvh64_intersect_ray`, A16,
non-sequential addresses, a pixel or vertex stage, a node pointer that is not a straight-line constant, a T#
loaded at run time, a type other than 8, nonzero box growing, an absolute (zero) base, a size that
does not cover the node, size bits above 4 GiB, a node address that wraps the 48-bit address space,
Expand Down
81 changes: 81 additions & 0 deletions docs/experiments/startup-gfx2hlsl-bvh-triangle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# `image_bvh_intersect_ray` triangle nodes

`tools/startup/gfx2hlsl.py` now lowers the 64-byte triangle node forms (kinds 0..3) of the 32-bit
`image_bvh_intersect_ray` (RDNA 2 MIMG opcode 230), in addition to the FP32 and binary16 box nodes.

## Node and test

A triangle node is 64 bytes: five `float3` vertices at bytes 0..59 and one ID dword at byte 60. The
kind selects one of the four 8-bit maps in the ID dword. Each map holds `i` in two bits and `j` in
two bits; the third index is `(3 - i - j) & 3`. The kind also selects the base vertex triple, which
is the table in Mesa 25.1.0 RADV's `radv_bvh_triangle_node` (MIT):

```text
kind 0: 0 1 2
kind 1: 1 3 2
kind 2: 2 3 4
kind 3: 2 4 0
```

The test is the watertight ray/triangle formulation from Woop, Benthin and Wald, as RADV uses it.
The helper projects the vertices onto the dominant ray axis, shears them, computes the three
barycentric numerators `u`, `v` and `w`, the determinant `u + (v + w)` and
`t = u*az + v*bz + w*cz` in binary32. A hit requires all three barycentrics to share a sign and
`t` to have the matching sign. The instruction does not test `ray_extent` for triangles.

## Return and descriptor

Triangle return mode 1 (bit 120 of the BVH T#, bit 24 of descriptor DWORD 3) returns the four words
`{t, determinant, v, w}` as float bit patterns. A miss is `{+inf, 1.0, 0, 0}`. For triangle nodes,
return mode 0 and every other reserved word-3 bit are refused by name before any HLSL is emitted.
Box nodes (kinds 4 and 5) ignore bit 24 because one T# can cover both node types; every other
word-3 bit is still refused for them.

The accepted slice uses:

- compute stage only;
- `image_bvh_intersect_ray v[4], v[11], s[4]` with the packed address form;
- a constant inline T# built by four SGPR constants, type 8, nonzero encoded base, box growing zero,
size field (a count minus one in 64-byte units) whose decoded extent covers the node; `size=0` is
a one-unit span, and the field stays below 4 GiB;
- a constant node pointer whose low three bits are 0..3 and whose address is inside the descriptor
size and the 48-bit absolute address space;
- either value of the sort bit; it is ignored for triangles.

The manifest still names the allocation with `srv <i> bvh base 0x<base> size 0x<size>`, using the
decoded byte address for `base`. The host binds `(size + 1) * 64` bytes. That binding remains
outside this change.

## Refused by name

Return mode 0, every node kind other than 0..3, `image_bvh64_intersect_ray`, A16, non-sequential
addresses, a pixel or vertex stage, a node pointer that is not a straight-line constant, a T# loaded
at run time, a type other than 8, nonzero box growing, an absolute (zero) base, a size that does not
cover the node, size bits above 4 GiB, a 48-bit node wrap, and every reserved T# field. The checks
assert that a refusal emits no helper call and no destination VGPR assignment.

## Evidence

```sh
python3 -B tests/startup_gfx2hlsl_bvh_triangle_check.py
python3 -B tests/startup_gfx2hlsl_bvh_triangle_check.py dispatch <dxc> <offscreen_check> warp
```

The check reuses the 119 triangle witnesses in `tests/gfx1030_bvh_box/check.py` and the independent
model in `tests/gfx1030_bvh_box/bvh_model.py`. These witnesses come from the CPU model (#2921), not a
hardware capture; the dispatch shows that the HLSL matches the model, not RDNA 2 hardware. It covers
all four kinds, each of the four ID map bytes, edge and vertex hits, outside and behind rays, zero
direction and negative zero, `t = 0`, `extent = 0`, 1024x scaling in both directions, degenerate and
malformed nodes, and the unknown kinds 6 and 7 (instance and procedural in the model).

The dispatch writes 71 unique triangle images at 64-byte offsets, runs the emitted helper for all
119 witnesses, and compares all 476 result words. It passes on WARP (`1414:008c`, driver
`10.0.26100.10068`) and on an AMD Radeon RX 9060 XT (`1002:7590`, driver `32.0.32029.2010`), in
both the dev and release presets, with `dxc -Gis` matching the runtime's strict-IEEE compile. Four
mutants change the determinant sign, the ID shift, the `u` term and the miss words; each must change
at least one witness. The existing box32/box16 tests still pass 6/6 in both presets.

This is a translator slice. It does not bind the node buffer on a D3D12 device, does not execute the
native gfx1030 probe, and does not 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.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tests/startup_gfx2hlsl_bvh_triangle_check.py
15 changes: 15 additions & 0 deletions tests/cmake/startup_gfx2hlsl_bvh_triangle.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# gfx2hlsl image_bvh_intersect_ray triangle-node slice: translator controls, a DXC compile when
# one is available, and a WARP/hardware dispatch when offscreen_check is built.
if(EXISTS "${INTAKE_PYTHON}")
add_test(NAME startup_gfx2hlsl_bvh_triangle COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_bvh_triangle_check.py")
endif()
if(EXISTS "${INTAKE_PYTHON}" AND TARGET offscreen_check)
foreach(adapter IN ITEMS warp hardware)
add_test(NAME startup_gfx2hlsl_bvh_triangle_dispatch_${adapter} COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_bvh_triangle_check.py" dispatch "${DXC_EXECUTABLE}"
"$<TARGET_FILE:offscreen_check>" ${adapter})
set_tests_properties(startup_gfx2hlsl_bvh_triangle_dispatch_${adapter} PROPERTIES TIMEOUT 120 SKIP_RETURN_CODE 77)
endforeach()
endif()

36 changes: 29 additions & 7 deletions tests/startup_gfx2hlsl_bvh_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
The instruction is RDNA 2 MIMG opcode 230. This check covers the translator path and the
box model only: a constant inline BVH T#[12:15], an 11-dword packed address, a constant
node base whose low three bits are 4 (binary16) or 5 (FP32), and the four child results.
Triangle nodes, the 64-bit form, A16, NSA and every dynamic descriptor or node base are
refused by name before any HLSL is emitted. The independent CPU box reference is
The triangle kinds have a dedicated check. The 64-bit form, A16, NSA and every dynamic
descriptor or node base are refused by name before any HLSL is emitted. The independent CPU box reference is
tests/gfx1030_bvh_box/bvh_model.py; the Windows dispatch exercises both emitted helpers.
"""
import math
Expand Down Expand Up @@ -198,10 +198,22 @@ def dispatch_cases():
cases.append(dict(name=name, helper="x2w_bvh_intersect_box16", pointer=(offset >> 3) | 4,
word0=0x1000, word1=0, word2=0x40,
extent=extent, origin=origin, direction=direction, expected=expected))
# A T# can cover both box and triangle nodes; box kinds ignore the triangle return mode
# bit. These cases fail if either the translator or the emitted box helper rejects it.
name, offset, extent, origin, direction, expected = RAYS[0]
cases.append(dict(name="box32_return_mode_ignored", helper="x2w_bvh_intersect_box32",
pointer=(offset >> 3) | 5, word0=0x1000, word1=SORT_ENABLE, word2=0x0b,
word3=RESOURCE_TYPE | 0x01000000, extent=extent, origin=origin,
direction=direction, expected=expected))
name, offset, extent, origin, direction, expected = HALF_RAYS[0]
cases.append(dict(name="box16_return_mode_ignored", helper="x2w_bvh_intersect_box16",
pointer=(offset >> 3) | 4, word0=0x1000, word1=SORT_ENABLE, word2=0x40,
word3=RESOURCE_TYPE | 0x01000000, extent=extent, origin=origin,
direction=direction, expected=expected))
return cases


BUFFER_SIZE = RESULT_OFFSET + 16 * (len(RAYS) + len(UNSORTED_RAYS) + len(HALF_RAYS) + len(HALF_UNSORTED_RAYS))
BUFFER_SIZE = RESULT_OFFSET + 16 * len(dispatch_cases())


def translate_program(*, node=0x05, sort_boxes=True, word0=0x1000, word1=None, word2=0x0b,
Expand Down Expand Up @@ -348,6 +360,16 @@ def controls():
check("sort-disabled box16 call uses a zero sort word",
"0x00001000u, 0x00000000u, 0x0000000bu, 0x80000000u" in call, call)

# One T# can cover both node types, so a box node ignores the triangle return mode bit.
for node, helper in ((0x05, "x2w_bvh_intersect_box32"), (0x04, "x2w_bvh_intersect_box16")):
pipe, hlsl, refusals = translate_program(node=node, word3=RESOURCE_TYPE | 0x01000000)
check("box kind %d with triangle return mode bit translates" % (node & 7),
pipe is not None and not refusals, str(refusals))
if pipe is not None:
call = next((line for line in hlsl.splitlines() if helper + "(r0" in line), "")
check("box kind %d call preserves the ignored return mode bit" % (node & 7),
"0x00001000u, 0x80000000u, 0x0000000bu, 0x81000000u" in call, call)

# Independently decode the 40-bit unit field; test the same raw DWORDs in
# the emitted call and the decoded byte-address binding in the manifest.
for units, high, base in ((0x1000, 0, 0x100000), (0x1008, 0, 0x100800),
Expand Down Expand Up @@ -424,7 +446,6 @@ def controls():

# Every refusal must happen before a helper call or a result VGPR is emitted.
cases = [
("triangle node", dict(node=0x00), "triangle node (kind 0)"),
("unknown node kind", dict(node=0x06), "node kind 6"),
("unaligned node", dict(node=0x0d), "not an aligned 128-byte node"),
("non-constant node", dict(constant_node=False), "non-constant node base"),
Expand All @@ -439,7 +460,7 @@ def controls():
("node outside size", dict(node=0x25, word2=3), "outside descriptor size"),
("box16 node outside size", dict(node=0x54, word2=9), "outside descriptor size"),
("absolute base", dict(word0=0, word1=0), "absolute node base"),
("size high bits", dict(word3=RESOURCE_TYPE | 0x100), "size above 4 GiB"),
("size high bits", dict(word3=RESOURCE_TYPE | 0x100), "does not match node kind 5"),
]
for label, kwargs, reason in cases:
if label == "NSA address":
Expand Down Expand Up @@ -487,7 +508,7 @@ def compile_check(hlsl):
with tempfile.TemporaryDirectory(dir=ROOT / "out" if (ROOT / "out").is_dir() else None) as temporary:
source = Path(temporary) / "bvh_box.hlsl"
source.write_text(hlsl, encoding="ascii")
result = subprocess.run([dxc, "-T", "cs_6_0", "-E", "main", "-Fo", str(source.with_suffix(".cso")), str(source)],
result = subprocess.run([dxc, "-Gis", "-T", "cs_6_0", "-E", "main", "-Fo", str(source.with_suffix(".cso")), str(source)],
capture_output=True, text=True)
if result.returncode or result.stderr:
check("dxc compiles the translated helper", False, result.stderr or "exit %d" % result.returncode)
Expand Down Expand Up @@ -550,9 +571,10 @@ def dispatch_hlsl(mutation=None):
for case, item in enumerate(dispatch_cases()):
inv = tuple(1.0 / c for c in item["direction"])
lines.append(
" uint4 r%d = %s(data, 0x%08xu, 0x%08xu, 0x%08xu, 0x%08xu, 0x80000000u, "
" uint4 r%d = %s(data, 0x%08xu, 0x%08xu, 0x%08xu, 0x%08xu, 0x%08xu, "
"%s, float3(%s, %s, %s), float3(%s, %s, %s));" % (
case, item["helper"], item["pointer"], item["word0"], item["word1"], item["word2"],
item.get("word3", 0x80000000),
ffloat(item["extent"]), ffloat(item["origin"][0]), ffloat(item["origin"][1]),
ffloat(item["origin"][2]), ffloat(inv[0]), ffloat(inv[1]), ffloat(inv[2])))
for word in range(4):
Expand Down
Loading
Loading