Skip to content

xdxr_build: take the BOX16 half sign without a shift-then-mask (AMD driver miscompile) - #1210

Open
whoalin1 wants to merge 1 commit into
ProjectLeonida:mainfrom
whoalin1:amd-val-box16-sign
Open

whoalin1 wants to merge 1 commit into
ProjectLeonida:mainfrom
whoalin1:amd-val-box16-sign

Conversation

@whoalin1

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: XDXR-BOX16-SIGN-AMD (claim)

Depends on: none

What and why

On the AMD Windows driver (24.10.24, Vulkan 1.3.280, gfx1035), every MINIMIZE_MEMORY BOX16 build through xdxr_build.comp produced corrupt boxes: tools/xdxr_bvh.py check-build reported ~20,727 problems ("child box not inside its parent's box") and essentially all rays missed. BOX32 builds of the same trees were bit-exact, and NVIDIA produced correct output from the identical SPIR-V module — an AMD shader-compiler miscompile, not a logic bug.

Bisection isolated half_directed() in runtime/src/xdxr_build.comp: it computed the half's sign as (u >> 16) & 0x8000. The bit-equivalent (u & 0x80000000u) >> 16 produces correct output on the same driver. In SPIR-V the old form is OpShiftRightLogical + OpBitwiseAnd with a 0x8000 mask; the new form reuses the existing 0x80000000 constant. Deterministic across runs and across -O/-O0 glslc output.

Changes:

  • runtime/src/xdxr_build.comp: one-line rewrite + comment.
  • runtime/src/xdxr_build.inc: regenerated with glslc from Vulkan SDK 1.4.363.0 (the large diff is SPIR-V result-ID renumbering).
  • docs/bvh.md: note in the BOX16 section.

Tested

  • vk_xdxr_build_test + xdxr_bvh.py check-build --rays 1000 on the AMD iGPU: 20,727 problems → all cases match (box16/paired/extremes/refit).
  • d3d12_xdxr_rt + its check on AMD iGPU: all match (was failing before).
  • NVIDIA RTX 4070 SUPER re-run: still all match (no regression).
  • py -3.14 -I tests/test_xdxr_bvh.py: 47 tests OK.
  • LEONIDA_VK_VALIDATION=1 ctest sweep on AMD iGPU: 0 VUIDs (unrelated suite run the same session).

GPUs tested: AMD Radeon Graphics (Ryzen 5 7600 iGPU, gfx1035-class RDNA2, driver 24.10.24, Vulkan 1.3.280, Windows 11); NVIDIA GeForce RTX 4070 SUPER (driver 610.88, Windows 11)

AI-assisted: yes (Devin)

Checklist

  • Based on current main and merges cleanly
  • One topic; follow-up work goes in a new pull request
  • No game data, keys or decryption
  • N/A — runtime shader-source workaround, no translator rule added

@quartz-heron-58

Copy link
Copy Markdown
Contributor

Independent run on a second AMD Windows driver and on NVIDIA, head 42d6623, built with scripts\build_runtime.ps1 (MSVC 14.44, RelWithDebInfo), Windows 11 build 26300.

GPU driver main 71f99e22 this PR
AMD Radeon Graphics (Ryzen 9 9950X3D iGPU, PCI 1002:13c0) 32.0.21042.62, Vulkan 1.4.315 4 of 4 pass 4 of 4 pass
NVIDIA GeForce RTX 4080 621.24 4 of 4 pass 4 of 4 pass

The four tests are xdxr_build, xdxr_build_check, d3d12_xdxr_rt and d3d12_xdxr_rt_check (ctest, device picked with LEONIDA_VK_DEVICE; the test output names the device in each run).

So the miscompile does not reproduce on this newer AMD driver: the BOX16 checks already pass on main here. The fix does not regress either card. I cannot confirm the failure itself, only that the rewritten form is also correct on these two drivers.

The "main" column is 71f99e22, not this branch's parent 6293c1c4; xdxr_build.comp, xdxr_build.inc, xdxr_bvh.py and the two test sources are identical between those two commits. One run of each. No game files.

AI-assisted: yes (Claude Code)

@adrianmjim

Copy link
Copy Markdown

Tested 42d6623 applied onto main 66d4f5a on an AMD Radeon RX 7900 XT: a discrete RDNA3 card on the current proprietary driver, next to the two iGPU runs. Setup: AMD Radeon RX 7900 XT (RDNA3, gfx1100), AMD proprietary driver 32.0.32029.2010 (26.11.2), Windows 11 build 26300, VS 2022 RelWithDebInfo, Vulkan SDK 1.4.363.0. No game files.

The .inc is the .comp. I regenerated runtime/src/xdxr_build.inc from the PR's xdxr_build.comp with glslc --target-env=vulkan1.2 -O -mfmt=c (shaderc v2026.4, Vulkan SDK 1.4.363.0). All 30316 words are identical to the committed file. The same check on main also matches (30320 words).

GPU, 2 runs each. ctest -R "^(xdxr_build|xdxr_build_check|xdxr_builder_validation|d3d12_xdxr_rt|d3d12_xdxr_rt_check)$", LEONIDA_RT_AS unset:

main 66d4f5aa3 this PR
the five tests 5/5 passed, both runs 5/5 passed, both runs
d3d12_blas_box16 0/1000 rays differ (711 hits) the same
d3d12_blas_box16_update 0/1000 rays differ (666 hits) the same
blas_paired_grid_box16 0/1000 rays differ (373 hits) the same
blas_box16_two_geometries 0/1000 rays differ (70 hits) the same
blas_box16_sort_tiles 0/200 rays differ (133 hits) the same
full ctest 311/314 311/314, the same three failures (d3d12_texture_tiles, d3d12_close_parity, since fixed by #1286, d3d12_clear)

On this card and driver the BOX16 miscompile does not reproduce: main already builds every BOX16 case bit-exact. The rewrite changes nothing here and causes no regression. It is a bit-equivalent rewrite, so it stays harmless on drivers that compile the old form correctly.

@whoalin1

Copy link
Copy Markdown
Contributor Author

Independent confirmation on a second AMD device: clean origin/main 4a50caf fails d3d12_xdxr_rt_check on AMD Radeon iGPU (gfx1035, driver 24.10.24, Vulkan 1.3.280, validation on) — d3d12_blas_box16 975 + d3d12_blas_box16_update 959 internal validation errors ('child box/triangle not inside parent's box'), 711/1000 and 666/1000 rays differ, 0 hits; all other BLAS/TLAS cases pass and the same test passes on RTX 4070 SUPER. Repro: ctest --test-dir runtime/build -C RelWithDebInfo --output-on-failure -R d3d12_xdxr_rt_check under VK_LOADER_DRIVERS_SELECT=*amd-vulkan* LEONIDA_VK_DEVICE=radeon LEONIDA_PC_TAIL_UBO=1 LEONIDA_VK_VALIDATION=1. Matches this PR's AMD shader-compiler miscompile diagnosis exactly. AI-assisted verification (Devin).

@whoalin1

Copy link
Copy Markdown
Contributor Author

Confirmed on a second AMD part — Ryzen 5 7600 iGPU (Raphael gfx1036, driver 24.10.24, Vulkan 1.3.280, validation on, LEONIDA_PC_TAIL_UBO=1): at origin/main b4b7756 both xdxr_build_check and d3d12_xdxr_rt_check fail with the box16 'child box/triangle not inside parent's box' errors (1938 problems, 666/1000 rays differ); at this PR's head 536df5c the same ctest -R xdxr run is 8/8 PASS. Same (u >> 16) & 0x8000 miscompile — this fix covers both ctest entries. AI-assisted verification (Devin).

@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 25, 2026
@whoalin1

Copy link
Copy Markdown
Contributor Author

Dual-GPU verification on 512eae3ed is now complete.

Runtime rebuild succeeded (BUILD_RC=0), then the six xdxr-related CTest entries were run with Vulkan validation enabled:

xdxr_builder_validation
xdxr_build
xdxr_build_check
d3d12_xdxr_rt
d3d12_xdxr_rt_check
vk_xdxr_postbuild_readback

Results:

  • AMD RDNA2 iGPU (VK_LOADER_DRIVERS_SELECT=*amd-vulkan*, LEONIDA_VK_DEVICE=radeon): 6/6 passed; d3d12_xdxr_rt_check passed in 19.36 s and xdxr_build_check in 82.45 s.
  • NVIDIA RTX 4070 SUPER (VK_LOADER_DRIVERS_SELECT=*nv-vk*, LEONIDA_VK_DEVICE=4070): 6/6 passed; d3d12_xdxr_rt_check passed in 18.21 s and xdxr_build_check in 76.24 s.

Together with the earlier tests/test_xdxr_bvh.py 54/54 pass, this covers both the CPU validator and the real dual-GPU build/check path. Logs are local in leonida-w1/.scratch/xdxr_{amd,nv}.log. AI-assisted verification with Devin.

(u >> 16) & 0x8000 and (u & 0x80000000) >> 16 are the same bits, but the
AMD Windows shader compiler (24.10.24, Vulkan 1.3.280, gfx1035) miscompiles
the first: every BOX16 box word comes out with flipped half signs, so every
MINIMIZE_MEMORY BLAS fails xdxr_bvh.py check-build (thousands of 'child box
not inside its parent' errors, all rays miss) while BOX32 builds of the same
tree are bit-exact. Deterministic across runs and across -O levels, and
NVIDIA produces correct output from the same SPIR-V module.

AI-assisted; verified on AMD Radeon(TM) Graphics (RDNA2 gfx1035, driver
24.10.24, Vulkan 1.3.280) and NVIDIA RTX 4070 SUPER: vk_xdxr_build_test +
xdxr_bvh.py check-build --rays 1000 goes from 20727 problems to 'all cases
match' on AMD; d3d12_xdxr_rt + check likewise.

Co-Authored-By: Devin <noreply@cognition.ai>
@whoalin1

Copy link
Copy Markdown
Contributor Author

Rebased cleanly onto current main (db1a22d29) as 4a4aa9b6d; no conflicts. The branch is unchanged: BOX16 half sign without shift-then-mask. The six xdxr CTests on both GPUs posted earlier stand on the same diff. AI-assisted with Devin.

@github-actions github-actions Bot added needs rebase Conflicts with the base branch: rebase it on main and removed needs rebase Conflicts with the base branch: rebase it on main labels Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs rebase Conflicts with the base branch: rebase it on main

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants