Skip to content

rdna2spirv: BVH box extent test as measured on RDNA2: max(tnear, 0) <= extent (SHADER-835) - #4750

Open
shelbykb2 wants to merge 2 commits into
ItsNotRexed:mainfrom
shelbykb2:fix/bvh-box-extent
Open

shelbykb2 wants to merge 2 commits into
ItsNotRexed:mainfrom
shelbykb2:fix/bvh-box-extent

Conversation

@shelbykb2

Copy link
Copy Markdown
Contributor

Claimed as SHADER-835 (#4571 (comment)). Follow-up to #3567, which listed the extent boundary as not measured. cc @controldebils

What and why

On RDNA2 a box child is kept when max(tnear, 0) ≤ extent. main tests tnear < extent (from #3567, which had only extent 100). One compare in the box branch of Gen.image_bvh changes (OpFOrdLessThan(tmin, extent) → OpFOrdLessThanEqual(max(tnear, 0), extent)); the emitted SPIR-V is the same size.

Measurement

AMD Radeon RX 6800 (gfx1030), AMD driver 26.11.2, Windows 11, tools/hw_oracle raw kernels, 2026-11-23. Three kernels, 36 new rows plus 6 controls copied from rows that already reproduce #3567 (all 6 bit-exact). BOX32, sorting on, 32-bit form, default descriptor, exact binary inputs (some extents are the next/previous float of one). Each kernel differs from a box kernel that had already run only in bound and ray constants.

Candidate rules and their predicted words were written down before the runs:

rule rows matched of 36
max(tnear, 0) ≤ extent 36
tnear ≤ extent 31
max(tnear, 0) < extent 11
tnear < extent (main, #3567) 7
RADV software rule 6

What the rows show:

  • Inclusive boundary. tnear equal to the extent is a hit, from 2^-100 to 2^100 and at FLT_MAX; the float just above is a miss. Odd-mantissa extents behave the same, so the whole extent word is compared.
  • A negative extent misses every child, with the origin inside the box too (−inf and −FLT_MAX included). This is what separates the rule from plain tnear ≤ extent.
  • +0 and −0 keep boxes around or starting at the origin; tnear = 2^-20 misses.
  • +inf keeps everything the slab test passes, including tnear = +inf.
  • A NaN extent misses every child (no triangle-style invalid-ray words).
  • tfar is not compared with the extent. Sort order follows rdna2spirv: BVH box test as measured on RDNA2: NaN planes skipped, near/far by direction sign (SHADER-650) #3567's network with key max(tnear, 0).

Tested (256eedc on 98fa503f)

  • python -m unittest discover -s tests/semantic -p "test_image_bvh*.py": 13 tests OK. The 36 rows are in test_image_bvh_box_hw.py as EXTENT_CASES; all 241 existing measured rows of rdna2spirv: BVH box test as measured on RDNA2: NaN planes skipped, near/far by direction sign (SHADER-650) #3567 still pass.
  • Negative control: unmodified main fails 29 of the 36 new rows.
  • tests/test_docs_*.py, test_ci_registration.py, test_text_encoding.py: 43 passed.
  • run_gpu_tests.py --filter bvh on the RX 6800: cs_bvh, cs_bvh32 pass, expected words unchanged.
  • Full semantic suite (worker run, before the last rebase): the only failures are in test_loop_ballot_barrier, identical with main's translator.

Not measured

Denormal or −NaN extents, BOX16, sorting off, other descriptors (the game sets big_page, #4639), the 64-bit form on box nodes, inputs whose slab distances round, gfx1013 (the console).

tools/xdxr_bvh.py's box test models the public XDXR software path and already uses clamped entry ≤ extent, so it is unchanged. The docs/design.md Ray tracing row is also edited by #4202 and #4639 (different sentences).

No game files involved. AI-assisted (Claude Code; an Opus worker prepared and ran the probes, I reviewed each kernel before it ran and re-ran the tests).

🤖 Generated with Claude Code

shelbykb2 and others added 2 commits November 22, 2026 21:47
…= extent

The box branch of image_bvh_intersect_ray / image_bvh64_intersect_ray tested tnear < extent. On an AMD Radeon
RX 6800 (gfx1030, AMD driver 26.11.2, Windows 11, tools/hw_oracle raw kernels) the hardware keeps a child when
max(tnear, 0) <= extent, an ordered compare:
- tnear equal to the extent is a hit;
- a negative extent (-inf included) or a NaN extent misses every child;
- an extent of +-0 keeps the boxes around or starting at the origin;
- +inf keeps a box at tnear = +inf.

36 rows in three kernels, 6 control rows that reproduced earlier measured words bit for bit. The rule was one of
eleven candidates registered before the runs and the only one that fit all 36; tnear < extent fit 7.

The change is one comparison: OpFOrdLessThanEqual(FMax(0, tmin), tmax) in place of OpFOrdLessThan(tmin, tmax).
It adds no SPIR-V instruction or word per site. The sort key and the NaN-skipping are unchanged.

tests/semantic/test_image_bvh_box_hw.py gains the 36 rows as EXTENT_CASES, run in the 32-bit form as measured.
All 241 existing measured rows still pass. Unmodified main fails 29 of the 36 new rows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Ray tracing row of docs/design.md said the box extent boundary was not measured. It now states the measured
rule, max(tnear, 0) <= extent, and what is still not measured.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 256eedcb on Windows 11 with CPython 3.14.7. The CPU translator and interpreter checks pass.

I ran python -I -m unittest discover -s tests/semantic -p "test_image_bvh*.py". All 13 tests pass. I also tested four identical boxes from (−1, −1, −1) to (1, 1, 1). The ray starts at the origin and points along +Z. An extent of negative zero (0x80000000) keeps all four child IDs. The next float below zero (0x80000001) returns four misses in the interpreter.

For the negative control, I used the translator from 98fa503f with the new tests. The test_image_bvh_box_hw.py suite reports 29 failed comparisons. This run checks the emitted shader in the CPU interpreter. It does not repeat the native RDNA2 measurement.

AI-assisted.

@justr4mzi

Copy link
Copy Markdown
Contributor

Verified commit 256eedcb on Windows 11 x64 with live native RDNA2 hardware (AMD Radeon RX 6700 XT, gfx1031, AMD driver 26.11.2) as well as the Vulkan and Python suites:

  • Native gfx1031 hardware (tools/hw_oracle raw image_bvh_intersect_ray kernels via rocm-sdk-core): independently re-ran all 36 EXTENT_CASES directly on AMD Radeon RX 6700 XT (gfx1031) — 36/36 match (mismatches=0), confirming max(tnear, 0) <= extent (including tnear == extent hit, tnear < 0 with +-0.0 extent hit, negative/NaN/-inf extent misses, and +inf hit) on gfx1031 as measured for gfx1030.
  • Vulkan GPU tests (scripts/run_gpu_tests.py --filter bvh --require-pass, LEONIDA_VK_VALIDATION=1): cs_bvh and cs_bvh32 translated (2/2 spirv-val valid) and 2/2 passed on AMD Radeon RX 6700 XT (0 validation errors).
  • Semantic & repo suites:
    • python -I -m unittest discover -s tests/semantic -p "test_image_bvh*.py" -v: 13/13 OK (3.074s, covering all 241 MEASURED cases + 36 EXTENT_CASES + EmptyBox + test_image_bvh_tri).
    • python -I tests/test_xdxr_bvh.py: 37/37 OK (3.157s); python -I tests/test_bvh_geometry_check.py: 6/6 OK (0.038s); python -I tests/test_shader_checks.py: 79/79 OK (2.069s).
    • tests/test_docs_*.py: 30/30 OK (36.787s); py_compile, scripts/check_no_game_data.py, and git diff --check: all exit 0.

Reviewed tools/rdna2spirv.py (OpFOrdLessThanEqual(tnear, tmax)), tests/semantic/test_image_bvh_box.py, tests/semantic/test_image_bvh_box_hw.py, and docs/design.md; looks solid.

AI-assisted (Gemini, Antigravity).

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ran this at 256eedcbf on Windows 11 (semantic tests need the repo's no--I invocation): test_image_bvh_box.py -> 4 tests, OK; test_image_bvh_box_hw.py -> 2 tests, OK; git diff --check clean.

The Ray-tracing row now states the measured RDNA2 extent rule, and the translator's box test expectation is aligned with it; the hardware test covers the measured extents. No blocking issue.

@Atomic258

Copy link
Copy Markdown
Contributor

Tested 256eedcbf73612c506697cab83bc4628006f5366 on Windows 11, CPython 3.15.2 (C:\Python315), in a clean worktree.

Commands and results:

  • python -I -m unittest discover -s tests/semantic -p "test_image_bvh*.py" -> 13 tests, OK (~1s; CPU-only translator + SPIR-V interpreter, no GPU/llvm-mc needed). This covers both touched test files plus test_image_bvh_tri.py.
  • python -m compileall -q make_game.py tools tests -> clean.
  • git diff --check origin/main...HEAD -> clean.

Note: python -I test_image_bvh_box.py run directly fails with ModuleNotFoundError: No module named 'support' — isolated mode strips the script's directory from sys.path; unittest discover is the working invocation here.

Red control: git checkout origin/main -- tools/rdna2spirv.py, re-ran the same discover command -> FAILED (failures=29), all 29 in MeasuredExtentBoundary.test_extent_test_is_clamped_tnear_at_most_extent subtests (matches the PR's "29 of the 36 new rows" claim; the other 12 tests still pass). Restored with git checkout HEAD -- tools/rdna2spirv.py -> 13 tests OK, git status --porcelain clean.

AI-assisted (Devin).

@memorypressure

Copy link
Copy Markdown

Verified merged with current main: the CPU coverage is complete and green — the semantic box/tri suites pass (4 + 2 + 7 tests, the new interpreter check covers all 36 extent rows), test_xdxr_bvh.py passes 37, both docs guards pass, and the only red is the known test_rdna2_decode exp-null parity failure that reproduces identically on main (#4421). One checklist gap: the new extent rule updates the design.md contract row but builds its shader inline in the Python test instead of adding the semantic .asm fixture the translator-rule convention expects — please add one so the measured rule is pinned in the standard form alongside test_image_bvh_box_hw.py. The native RDNA2 measurement itself was not repeated here. Checks pending. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@gertify

gertify commented Nov 23, 2026

Copy link
Copy Markdown

Tested 256eedc on Intel UHD 630 (Coffee Lake GT2), Mesa 25.2.8 ANV, Ubuntu 24.04: tests/semantic test_image_bvh*.py passes (13 tests), and the docs, CI-registration and text-encoding tests pass (30, 11 and 2 tests). With the tools from the base 98fa503 the same 13 tests give failures=29, so the new rows discriminate. run_gpu_tests.py --filter bvh with LEONIDA_VK_DEVICE=Intel passes cs_bvh and cs_bvh32 (2/2). The PR's 36-row hardware measurement on an RX 6800 was not reproduced.

AI-assisted.

@gertify

gertify commented Nov 23, 2026

Copy link
Copy Markdown

Tested 256eedc on AMD Radeon 610M (RADV, subgroup 32..64), Linux: tests/semantic test_image_bvh*.py passes (13 tests, no GPU involved), and the docs, CI-registration and text-encoding tests pass (30, 11 and 2 tests, 43 together). run_gpu_tests.py --filter bvh with LEONIDA_VK_DEVICE=RADV passes cs_bvh and cs_bvh32 (2/2), and with a nonexistent device name both fail with "no Vulkan physical device matches", so the filter applied. I did not check whether the cs_bvh and cs_bvh32 scenes reach the extent boundary this PR changes, and I did not repeat the PR's hardware measurement of that boundary.

AI-assisted.

@Atomic258

Copy link
Copy Markdown
Contributor

Tested 256eedc on Windows Server 2022, CPython 3.13.12: pass

  • python -I -m unittest discover -s tests/semantic -p "test_image_bvh_box.py" -> OK
  • rdna2spirv semantic side; hw fixture not run (no GPU).

git diff --check clean; python -m compileall -q exit 0. No game files, no GPU. AI-assisted (Devin).

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.

7 participants