Skip to content

Ray tracing: the first real core_bvh4 BLAS on a GPU (the descriptor base is the 256-byte-unit field) - #3794

Closed
SuarezPM wants to merge 10 commits into
ItsNotRexed:mainfrom
SuarezPM:real-bvh-core
Closed

SuarezPM wants to merge 10 commits into
ItsNotRexed:mainfrom
SuarezPM:real-bvh-core

Conversation

@SuarezPM

@SuarezPM SuarezPM commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: RT-212. Depends on: #3533 (the VKC_HEAP_FILE harness this was measured with).

What and why

The first controller-free traversal of a real GTA VI acceleration structure on a PC GPU, and the measurement that pins its descriptor-base semantics:

  • core_bvh4.rpf indexes to 271,637 BVH4 streams / 1,896,784,254 nodes (121.4 GB inflated) in 1,034 s (bvh_index.py).
  • The first BLAS (stream 0x12060, 39,257 nodes) matches one drawable among the 258,037 models exported from levels.rpf: 12 geometries, 21,814 leaves. bvh_match.py's four checks pass: 0 leaves outside, 335/0 overrides, area ratio 1.000. bvh_rehydrate.py writes the 2,512,512-byte structure; its runtime root is the first node of the last level-table entry (the header keeps the dehydrated root), and its leaves are in the leaf frame (header sceneBounds ±2.5, leaf vertices ≈19,040).
  • Descriptor base, measured at two addresses: the game passes ptr >> 8 in the descriptor's dword0 — the base in 256-byte units. The | 0x30 its shader ORs is only the temporary address it uses for the rootNodePtr load, not the descriptor base. At base 0 and at base 0x1000 (structure copied to VA 0x1000, dword0 0x10) the emulation's existing << 8 reads the right nodes. A masked-byte variant (base40 & ~0xFF) reads base 0 in the second case and misses; it was falsified and reverted. No translator change is needed.

The GPU evidence

The game's RT shadow CS (deferred_tiled family, 32-bit image_bvh_intersect_ray, the smallest buffer-only one) over the rehydrated real BLAS, RTX 2060 SUPER, driver 620.73.04, Vulkan 1.4.357. First dynamic call, lane 0:

structure VA descriptor dword0 emulated base node GPU children CPU (intersect_node)
0 0x30 0 0x4CABC [0x4CAA4, 0x4CA9C, FFFFFFFF, FFFFFFFF] identical set and order
0x1000 0x10 0x1000 0x4CABC [0x4CAA4, 0x4CA9C, FFFFFFFF, FFFFFFFF] identical set and order

Origin/direction/tmax are the leaf-0 ray (centroid + normal·0.5, tmax 2.0); the CPU walker reaches t=0.5, leaf 8240, geometry 0, primitive 0. The shader's second traversal site remains engine-gated (the executable's call sites), so the full output stays FLT_MAX; that limit is documented in the RT-212 findings.

Tested

  • python3 -I -m unittest discover -s tests/semantic -p 'test_image_bvh_tri.py' — 7 tests OK. The fixture's dword0 is 0x10 (base 0x1000 in 256-byte units); the masked variant makes it fail, the << 8 passes, and the docstring now records the GPU measurement.
  • python3 -I tests/test_docs_links.py — OK.
  • Both GPU runs above; the debug instrumentation was reverted. No game data is committed: the package, OBJ, structure and heap stay in the user's work folder; the docs carry counts and offsets only.

main gained VKC_HEAP_INIT (fixed VA 0) while this was in review; #3533 keeps both loaders. The two runs above used VKC_HEAP_FILE at VA 0 and VA 0x1000.

  • @kacper-serewis (RTX 5070, driver 616.56): a hand-written traversal with a synthetic dword0 0x1030 (byte base + flags, the shader's temp) matches the CPU 4/4 with the mask and 3/4 with the shift; that descriptor is not the game's. The game shader passes ptr >> 8 (0x10), where the shift matches. The two results are consistent; the game's construction is the deciding evidence.

  • @chpeu (RTX 3080 and RTX 5080, Linux, driver 615.71.09): re-applied on main f847748c, GPU suite 184/199, 15 skipped, 0 failed on both cards; the branch's 174/189 is the older fixture set. The core_bvh4 probe is a separate manual run, not in run_gpu_tests.py.

  • @requiemsnkrp (RTX 3060, Windows 11, MSVC 19.51): semantic 7/7; cs_bvh/cs_bvh32 through VKC_HEAP_FILE at 0x1000 and at @4096, 0 mismatches; @-5 and a missing file exit 2 with the message; full ctest 148/148.

  • @crastinator (RX 6700 XT, RADV Mesa 26.3.1): GPU suite 185/199, ctest 41/41, semantic 7 passed (13 subtests).

  • @kapitche (RTX 4080 SUPER and Intel UHD 770, Windows 11): semantic passes; --filter bvh 2/2 on both GPUs; full suite 164/210 and 146/210, no failures attributable to this PR. No negative control is possible because the translator has no delta: the mask was falsified and reverted.

  • @dcastell1 (RTX 5090, driver 621.24, Windows 11): shader suite 195/210, 0 failed; xdxr_build, xdxr_build_check, d3d12_xdxr_rt, d3d12_xdxr_rt_check 5/5 passed.

  • @TheMrBeez (gfx1036, Ryzen 9 9950X3D iGPU, driver 32.0.21030.2001): ran the native image_bvh_intersect_ray and image_bvh64_intersect_ray through tools/hw_oracle over hand-built box32 nodes, wave32 and wave64. dword0 (P >> 8) + 0x10 with node 0|5, and (P >> 8) + 0x08 with node 0x800>>3|5, both traverse the node at P + 0x1000; the control reads the decoy. So address = base x 256 + (node & ~7) x 8, and the base and the node offset add. The same layout translated at 7bf1db92 gives the same 32 words on the RTX 5080 and on gfx1036 through Vulkan, spirv-val clean. Limits: descriptor bits 39:32, non-box32 nodes and a 0x1030-style dword0 were not exercised.

  • @lunisahdidouch (RX 9070, RDNA4, driver 26.11.1, Windows 11): semantic 7/7; GPU suite 196/210, 14 skipped, 0 failed, with cs_bvh/cs_bvh32 passing; full ctest 153/154, the one failure being vk_pipeline_check_cli's first-launch timeout (3/3 on rerun, seen on main). The 7 failures/2 errors in the full semantic suite reproduce on the main this branch merged, not here.

Limits

The rehydrated structure is the offline form; the pipeline patches its runtime root and builds rays in the leaf frame. The shader's second site needs the executable. AI-assisted.

Checklist

The harness could only read the 0x280-byte synthetic bvh scene it builds itself. VKC_HEAP_FILE=<path>[@<offset>] copies a file into the heap, so a translated corpus shader can read a BVH, its descriptor blocks and the records from the user's work folder. Used to dispatch one of the game's RT compute shaders over a real GPU-built BLAS; the file is read at run time and never committed, so no game data enters the repository.
The game's RT shaders build the BVH descriptor base as (ptr & ~0xFF) | 0x30: a
byte address with flags in the low bits, not the 256-byte-unit field the
emulation assumed (base40 << 8). Masking the low byte fixes the address; a
non-zero base moved every node by 256x the flags.

The semantic test now runs the masked-base case (dword0 0x1030 -> base 0x1000,
node at 0x1040) and fails under the old shift. Measured with the first real
core_bvh4 BLAS (docs/bvh.md 7b): header at VA 0, root 0x4CABC; the game RT
shadow CS returns the CPU walker's children in the same order on the RTX 2060.
strtoull(..., 0) accepted a leading zero as octal (@0256 loaded at 0xae), and a
sign or spaces. Parse decimal or 0x hex explicitly, cap the offset at 4 GiB, and
document the two overlaps: bvh mode writes its synthetic scene after the copy,
so 0x100..0x264 is overwritten there, and the output V# starts at heap offset 0.
Reported by @wildheathen.
@iurysf

iurysf commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Code read of 2c51fb2d (translator side): looks good.

  • The change is one line in image_bvh_intersect_ray: the descriptor base goes from base40 << 8 to
    base40 & 0xFFFFFFFF00, with the docstring and the old "RADV only ever uses base 0" assumption updated to match.
  • tests/semantic/test_image_bvh_tri.py uses dword0 = 0x1030 (base 0x1000 plus flags 0x30), so it tells the two rules
    apart where the GPU evidence (header at VA 0) can't. Mutation: back to base40 << 8 gives 17 failed, 3 passed;
    at this head 7 passed, 13 subtests passed.
  • Note: since the GPU run is at base 0, it might be worth saying that the nonzero-base case rests on the game's
    (ptr & ~0xFF) | 0x30 pattern and this semantic test, not on a measurement.

Ran on Windows 11 with pytest 9.2: the file above. The VKC_HEAP_FILE harness part (#3533) wasn't read.

AI-assisted code read (Claude).

@SuarezPM

Copy link
Copy Markdown
Contributor Author

Good catch, and you are right: the GPU run is at base 0, so the nonzero case currently rests on the shader's (ptr & ~0xFF) | 0x30 pattern plus the semantic test. I am measuring it now: the same real BLAS uploaded at VA 0x1000, block A+0x20 = 0x1000, so the shader builds dword0 = 0x1030 and the masked base must be 0x1000; the first call is compared with intersect_node(mem, 0x1000, …). I will update the body and docs/design.md with the result either way. Thanks for the mutation count. AI-assisted.

@kacper-serewis

Copy link
Copy Markdown
Contributor

RTX 5070, driver 616.56, head 2c51fb2 versus parent 0c1cb46 with the #3533 harness: a hand-written traversal of one geometry-matched 1.0.2.1 BLAS root matched the CPU walk on 4/4 output words both at byte address zero and relocated to 0x1000. The parent matched 3/4 at each address. Both revisions passed spirv-val and all seven triangle semantic tests passed on head. The relocated control exercises preservation of the nonzero address above the low flags. Coverage is one root and a synthetic instruction; full retail shader execution remains open. AI-assisted.

The nonzero-base measurement falsifies the earlier mask. The game passes
ptr >> 8 in the descriptor's dword0 (0x10 for a structure at VA 0x1000), and
the |0x30 its shader ORs is only the temporary root-load address. The original
<< 8 is correct at base 0 and at 0x1000; the GPU returns the CPU walker's
children at both. This commit restores the translator and the test fixture to
main and keeps the measured result in docs/bvh.md 7b and the Ray tracing row.
@SuarezPM SuarezPM changed the title rdna2spirv: the game's BVH descriptor base is a byte address with flags (first real pack BLAS on a GPU) Ray tracing: the first real core_bvh4 BLAS on a GPU (the descriptor base is the 256-byte-unit field) Nov 22, 2026
Resolve the VKC_HEAP_INIT/VKC_HEAP_FILE overlap by keeping both: INIT seeds VA 0 (main), FILE loads at an offset and grows the buffer (this branch).
git add -A picked up .xwin-cache (643 local SDK files). They are a build artifact, never part of the PR; the tree returns to the four intended files. The path is now in .git/info/exclude.
git add -A also staged .ignore, .slim/ and the codemap.md files; they are local agent artifacts, not part of the PR.
@SuarezPM

Copy link
Copy Markdown
Contributor Author

Measured, and it changes the conclusion: the nonzero base falsifies the mask. The same real BLAS at VA 0x1000 (dword0 0x10):

  • original base40 << 8 -> base 0x1000, node 0x4CABC, children [0x4CAA4, 0x4CA9C, FFFFFFFF, FFFFFFFF] — identical to intersect_node(mem, 0x1000, …);
  • base40 & ~0xFF -> base 0, same node, all FFFFFFFF — miss.

So the game's dword0 is ptr >> 8 (the 256-byte-unit field); the | 0x30 its shader ORs is only the temporary address for the rootNodePtr load, not the descriptor base. My earlier base-0 evidence could not tell the two apart. The mask fix is reverted, the translator and the test fixture are back to main, and #3794 is rescoped to docs + the measurement (both base 0 and 0x1000), no code fix. Your note is exactly what caught it; thanks. AI-assisted.

@chpeu

chpeu commented Nov 22, 2026

Copy link
Copy Markdown

Tested 33e00a4e on two NVIDIA cards, Linux, no game files. main f847748c is not in this branch's
history, so I ran it twice: as it stands, and re-applied on top of current main.

As it stands (33e00a4e)

  • LEONIDA_W64_EMULATE=1 python -I scripts/run_gpu_tests.py --build runtime/build/linux --llvm-mc /usr/lib/llvm-20/bin/llvm-mc
    → RTX 3080 174/189 passed, 15 skipped, 0 failed; RTX 5080 (LEONIDA_VK_DEVICE="RTX 5080") the same.
    The total is 189 on this branch, 199 on current main — the branch predates the newest fixtures.

Re-applied on current main (git merge --no-ff --no-commit of your head into f847748c: clean, no
conflicts):

  • GPU suite → 184/199 passed, 15 skipped, 0 failed on the RTX 3080 and on the RTX 5080 with the wave64
    emulation, 153/199 passed, 46 skipped without it — exactly what main alone gives here, so nothing moved
    for the existing fixtures.
  • Build clean (cmake --build runtime/build/linux --parallel), python -m compileall -q make_game.py tools tests
    clean.

What this does not cover: both cards report ray-tracing support, but our skip list is the wave64 one, and the
core_bvh4 BLAS path you are exercising needs the ray-tracing fixtures to actually run. If your new program is
built by scripts/run_gpu_tests.py, it was included in the 199 and did not fail; if it is a separate probe run
by a script of its own, I did not run it — say which and I'll run it here on both cards.

Machine: Linux Mint 22 (Ubuntu 24.04 base), NVIDIA driver 615.71.09, Vulkan 1.4.351, llvm-mc 20.1.2,
SPIRV-Tools 2025.1~rc1 (Ubuntu packages), GCC 13.3, Python 3.12.3 with pytest 9.2.0 and numpy 2.5.5, built with
cmake -S runtime -B runtime/build/linux -DLEONIDA_VULKAN_HEADERS_FETCH=ON. AI-assisted testing, counts read
through by hand.

@SuarezPM

Copy link
Copy Markdown
Contributor Author

Thanks. One distinction decides this: which value does your traversal put in descriptor dword0?

  • The game's RT CS builds dword0 = ptr >> 8 (0x10 for a structure at VA 0x1000). The |0x30 is only the temporary address it uses for the s_load of rootNodePtr. Dumping that shader's first call (the deferred_tiled 32-bit one) gives base 0 and base 0x1000 with the shift; the mask gives base 0 and misses at 0x1000.
  • Your synthetic traversal likely passes 0x1030 (byte base + flags) as dword0. With that value the mask must win (0x1030 & ~0xFF = 0x1000) and the shift gives 0x103000, which explains 4/4 vs 3/4.

So both results are consistent: they are different descriptors. The game shader is the deciding evidence for the game's convention, and it says the 256-byte-unit field. Can you confirm the exact dword0 your test writes? If it is 0x1030, I will cite it in the PR as the synthetic control (and note that the game does not build that value). Also, which of the 4 words differs with the shift at the parent? If it is the tie order, it may be the same float32 tie we see elsewhere.

AI-assisted.

@SuarezPM

Copy link
Copy Markdown
Contributor Author

Thanks for the two-card run and the merge-on-main numbers; 0 failures at 184/199 is exactly the assurance this needed.

The core_bvh4 probe is not in run_gpu_tests.py; it is a separate manual run (VKC_HEAP_FILE + a translated game shader + a heap built in /tmp from a rehydrated BLAS). The PR is now docs-only: the harness is #3533, and the base-fix premise was falsified and reverted. So there is no new program to run here; if you ever want to reproduce the instruction side, a 32-bit image_bvh_intersect_ray shader over a heap file is enough, but the retail BLAS belongs to the player's copy.

AI-assisted.

@requiemsnkrp

Copy link
Copy Markdown

Tested 7bf1db92 (merged onto main aa2988cc) on NVIDIA GeForce RTX 3060, driver 32.0.16.1714, Windows 11, MSVC 19.51, Vulkan SDK 1.4.363.0: pass for the parts that need no game data. The real core_bvh4 BLAS measurement needs the game files, so I did not reproduce it.

  • python -I -m unittest discover -s tests/semantic -p test_image_bvh_tri.py: Ran 7 tests ... OK.
  • cs_bvh and cs_bvh32 translated with runtime/test/shaders/build.py (2 translated, 2 pass spirv-val), then run through vk_compute_test <spv> 1 bvh. Plain, both: 1 groups x 64: 0 mismatches. With a 4096-byte synthetic file, VKC_HEAP_FILE=hf.bin@0x1000, both: heap file: hf.bin at 0x1000 (4096 bytes), bvh out = 00000048 00000040 ffffffff ffffffff | c1200000 bf800000 be800000 be800000, 0 mismatches. Decimal @4096 gives the same result.
  • Parsing errors: @-5 gives VKC_HEAP_FILE: expected <path>[@<offset>], got "hf.bin@-5" and exit 2; a missing file gives VKC_HEAP_FILE: cannot read nope.bin and exit 2.
  • vk_compute_test has no LEONIDA_VK_VALIDATION hook, so these direct runs were without the validation layer.
  • Full ctest (-E "present|swapchain|frame_pacer", with LEONIDA_VK_VALIDATION=1): 100% tests passed, 0 tests failed out of 148 (9 skipped/disabled, same set as main: shader_library_corpus, bink_decode, bink_play_headless, fsr_dispatch, bvh_builder, bink_audio, gameinput, d3d12_rgb9e5_rtv, d3d12_first_light).
  • Note: the diff contains VKC_HEAP_FILE, which the description attributes to vk_compute_test: VKC_HEAP_FILE, so a corpus shader can read a real BVH #3533. If vk_compute_test: VKC_HEAP_FILE, so a corpus shader can read a real BVH #3533 lands first, this will conflict or duplicate.

AI-assisted (Claude). No game files.

@crastinator

Copy link
Copy Markdown
Contributor

Tested 2c51fb2 merged into main f847748c (clean merge) on AMD Radeon RX 6700 XT (Navi 22, gfx1031, subgroup 32..64), RADV Mesa 26.3.1, CachyOS, Linux 7.3.5, GCC 16.2.1, llvm-mc 23.1.5: pass.

  • Whole run_gpu_tests.py: 185/199 native, 185/199 with LEONIDA_W64_EMULATE=1 (skips: the D3D12-only fixtures and ps_w64x_readlane, as on main). ctest 41/41.
  • tests/semantic/test_image_bvh_tri.py: 7 passed, 13 subtests passed.

No game files. AI-assisted (Claude Code).

@SuarezPM

Copy link
Copy Markdown
Contributor Author

Thanks, this is a useful independent pass: the semantic file, the cs_bvh/cs_bvh32 runs through VKC_HEAP_FILE at 0x1000, the @4096/error cases and the full 148-test ctest are exactly the surface this touches.

Your note is correct and expected: #3794 is stacked on #3533 (the VKC_HEAP_FILE commit is in this branch's history, hence the diff). The board's merge chain lists #3533 → #3794; once #3533 lands, this PR's diff is only the measured docs and the semantic-test comment, with no translator change (the nonzero-base measurement falsified the mask, see the thread). No action needed from you.

AI-assisted.

@kapitche

Copy link
Copy Markdown
Contributor

Tested on Windows 11 with two GPUs on one machine (head merged with main aa2988c, MSVC 14.51, Python 3.13.1):

  • tests/semantic/test_image_bvh_tri.py passes.
  • RTX 4080 SUPER: run_gpu_tests.py --filter bvh: cs_bvh and cs_bvh32 PASS, 2/2.
  • Intel UHD 770 (VK_LOADER_DRIVERS_DISABLE=*nv*): cs_bvh and cs_bvh32 PASS, 2/2.
  • Whole run_gpu_tests.py suite with the PR's vk_compute_test swapped into a main build: RTX 4080 SUPER 164/210, Intel UHD 770 146/210, no failures from this PR. (Against my baseline, which has an older vk_compute_test, cs_heap_init is FAIL there and PASS here on both GPUs; I read that as the baseline's stale executable, not this PR.)
  • Negative control: none to give. The << 8 base change in tools/rdna2spirv.py is already on main (the diff against main is only docs/bvh.md, docs/design.md, vk_compute_test.cpp and the test), so reverting the translator to main changes nothing and the unit test passes either way. What I could not run is the real-structure core_bvh4 probe the description measures, as it needs the user's package.

The other vk_* programs came from a runtime built from main f847748.

@dcastell1

dcastell1 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Tested dbfbb38 on RTX 5090, 621.24, Windows 11: pass.

  • Shader suite (programs rebuilt from this head, LEONIDA_W64_EMULATE=1): 195/210 passed, 15 skipped, 0 failed; cs_bvh and cs_bvh32 among the passes.
  • xdxr set, from 7bf1db92: xdxr_build 0.48 s, xdxr_build_check 38.81 s, d3d12_xdxr_rt 0.63 s, d3d12_xdxr_rt_check 8.62 s → 5/5.

@dcastell1

Copy link
Copy Markdown
Contributor

Built the rest of it and ran the whole xdxr set on the RTX 5090 (621.24, Windows 11, MSVC 19.44, Ninja), 7bf1db9:

xdxr_build         Passed  0.48 s
xdxr_build_check   Passed 38.81 s
d3d12_xdxr_rt      Passed  0.63 s
d3d12_xdxr_rt_check Passed 8.62 s
100% tests passed, 0 tests failed out of 5

So the BLAS half runs here too: the 256-byte-u descriptor base and the BVH4 records are read back as the check expects. With the earlier shader run (195/210, 0 failed), both halves of this PR are now verified on this GPU.

@SuarezPM

Copy link
Copy Markdown
Contributor Author

Thanks — both results are useful, and your negative-control note is exactly right.

There is no translator delta in this branch: the masked-byte variant (base40 & ~0xFF) was measured against the real structure at VA 0x1000 and falsified there (it reads base 0 and misses), so it was reverted. main keeps the same << 8 this branch has; the only behavioural change in the diff is #3533's VKC_HEAP_FILE loader, which is stacked (#3533 → #3794). That is also why reverting the translator changes nothing: there is nothing to revert.

On cs_heap_init: the binary you used here is #3533's, so FAIL→PASS against your older vk_compute_test is most likely the rebuilt executable, as you read it. The heap-init path itself is untouched; #3533 only adds a second loader for a file-backed heap. If you ever want to close it, build main's runtime/test/vk_compute_test.cpp at aa2988cc with the same MSVC and rerun — not needed for this PR.

The Intel UHD 770 pass is worth having: it shows the cs_bvh/cs_bvh32 fixture path is not NVIDIA-specific.

AI-assisted.

@SuarezPM

Copy link
Copy Markdown
Contributor Author

Thanks — that is the most complete pass this PR has had: both halves, same machine.

  • The shader suite (195/210, 0 failed) covers the descriptor consumers.
  • The xdxr set covers the other side: xdxr_build/xdxr_build_check and d3d12_xdxr_rt/d3d12_xdxr_rt_check read back the 256-byte-unit base and the BVH4 records as the check expects, 5/5.

To keep the scope exact: those xdxr fixtures are synthetic. The retail core_bvh4 measurement needs the player's package and stays as described in the body (base 0 and 0x1000, RTX 2060 SUPER). No further runs needed — thanks for building the ctest half too.

AI-assisted.

@TheMrBeez

Copy link
Copy Markdown

The descriptor-base semantics this PR documents, measured on the native instruction rather than through the emulation. The GPU runs in the thread all execute the translator's << 8. They show the game builds ptr >> 8 and that this agrees with the emulation. They can't show what the hardware does with the field. An RDNA2 iGPU can run image_bvh*_intersect_ray itself through tools/hw_oracle. I did that on gfx1036 (the Ryzen 9 9950X3D iGPU, AMD driver 32.0.21030.2001), in wave32 and wave64.

Setup. Hand-built nodes, no game data. P is the oracle's 256-aligned output buffer.

  • A decoy box32 node sits at P + 0x000, with children D00 D08 D10 D18.
  • The real box32 node sits at P + 0x1000, with children A00 A08 A10 A18 and the same four boxes.
  • One +z ray hits three of the boxes. The sort bit is set, so the result is x18 x08 x00 FFFFFFFF.
  • Descriptor: dword0 = base[31:0], dword1 = base[39:32] | sort bit, dword2 = -1, dword3 = 0x81000000.
dword0 (base) node id image_bvh64_intersect_ray image_bvh_intersect_ray (32-bit)
q0 P >> 8 0x1000 >> 3 | 5 real real
q1 (P >> 8) + 0x10 0 | 5 real real
q2 (P >> 8) + 0x08 0x800 >> 3 | 5 real real
q3 (control) P >> 8 0 | 5 decoy decoy

So on hardware, node address = base × 256 + (node & ~7) × 8, in both forms. That is the << 8 in tools/rdna2spirv.py, and it matches the 256-byte units this PR writes into docs/design.md and docs/bvh.md.

  • q1 is the PR's VA 0x1000 / dword0 0x10 case done on the hardware itself.
  • q2 shows that the base and the node offset add.

The same layout translated at 7bf1db92 (no translator change against main aa2988cc, which I also ran) gives the same 32 words on the RTX 5080 (driver 621.01) and on the gfx1036 through Vulkan. spirv-val is clean.

Limits:

  • P >> 8 fits in 32 bits here, so dword1[7:0] (base bits 39:32) was 0, and that half of the 40-bit field was not exercised.
  • Only box32 nodes and descriptor dword0 values of base + 0x00/0x08/0x10 were tried.
  • I did not try a byte address with flags (0x1030-style) as dword0 on hardware. On these results the hardware would read it as base 0x103000, which is @kacper-serewis's synthetic case, not the game's.

One wording point for the Ray tracing row. Its existing sentence "A GPU can't confirm the rule either, because every GPU runs this emulation and none runs the native instruction" is about the triangle rule, and it isn't quite right anymore. tools/hw_oracle runs the native instruction on an RDNA2 GPU. I've used it for box nodes here, in #3803, and in #3366/#3373. Triangle nodes could be measured the same way.

Windows 11, Vulkan SDK 1.4.363. The probe scripts are local. AI-assisted (Claude Code).

@TheMrBeez ran image_bvh_intersect_ray and image_bvh64_intersect_ray through
tools/hw_oracle on gfx1036 over hand-built box32 nodes: dword0 (P >> 8) + 0x10
with node 0|5 and (P >> 8) + 0x08 with node 0x800>>3|5 both traverse the node at
P + 0x1000, so address = base * 256 + (node & ~7) * 8 and the base and the node
offset add; the control reads the decoy. Recorded in bvh.md 7b. The Ray tracing
row drops the "a GPU can't confirm the rule" sentence: it was about the triangle
rule, and hw_oracle can run the native instruction, so that measurement is a
follow-up rather than an impossibility.

Docs only; test_docs_links, test_docs_repo_paths, test_docs_design_rows,
test_docs_table_rows and test_docs_list_items pass.
@SuarezPM

Copy link
Copy Markdown
Contributor Author

@TheMrBeez — this is the measurement the row was missing, and the wording correction is right. Thanks for running the native instruction instead of the emulation.

What I take from the run: on hardware, address = base × 256 + (node & ~7) × 8, in both image_bvh_intersect_ray and image_bvh64_intersect_ray. q1 is exactly the game's VA 0x1000 / dword0 0x10 case, and q2 shows the base and the node offset add rather than one overriding the other. That is stronger than this PR could claim from the emulation alone: the translator's << 8 now has a hardware check behind it, not only a CPU agreement.

I changed the Ray tracing row: the sentence now says the triangle rule has not been measured on the native instruction yet, that tools/hw_oracle can run it on RDNA2 and was used for box32 nodes, so the triangle counterpart is a follow-up rather than an impossibility. docs/bvh.md §7b records your run (gfx1036, driver 32.0.21030.2001, both widths, q1/q2/control) and its limits: descriptor bits 39:32, non-box32 nodes and a 0x1030-style dword0 were not exercised — which also keeps @kacper-serewis's synthetic descriptor distinct from the game's.

The translated-layout runs at 7bf1db92 on the RTX 5080 and on gfx1036 through Vulkan (same 32 words, spirv-val clean) are now in the PR body's review list.

Push dbfbb386. AI-assisted.

@lunisahdidouch

lunisahdidouch commented Nov 22, 2026 •

Copy link
Copy Markdown

Tested 7bf1db9 on an RX 9070 (RDNA4), AMD 26.11.1, Windows 11 (26300), VS 2022 Build Tools, RelWithDebInfo with SDL3: pass for this PR's changes

  • test_image_bvh_tri.py: 7 tests OK.
  • run_gpu_tests.py with native wave64: 196/210 passed, 14 skipped (the usual "run by d3d12_*_test" ones), nothing failed. cs_bvh and cs_bvh32 pass.
  • Full ctest: 153 of 154 passed. The one failure was vk_pipeline_check_cli timing out on the freshly built tool's first launch, and it passes 3 of 3 when rerun. I've seen the same thing on main here.

The full tests/semantic run reports 7 failures and 2 errors. They aren't from this PR: I get the same ones on 4c52ce2 (the main this branch merged) without the PR. They are test_cmp_class_f64.test_rejected_forms (2), test_loop_ballot_barrier (test_divergent_loop_wave64_emulate_and_native_cs in the three emulate_*_sg32 modes, plus errors in test_nested_divergent_loops_emulate and test_bug4b_loop_carried_split_sgpr_pair_ballot), and test_mutations (the v_mul_legacy_f32 anchor is no longer found exactly once). Against 4c52ce2 the branch only touches docs, vk_compute_test.cpp and test_image_bvh_tri.py.

The new head dbfbb38 only adds to docs/bvh.md and docs/design.md on top of what I tested.

AI-assisted

@tupacfan04

Copy link
Copy Markdown
Contributor

Request changes - the diff does not match the title, and it duplicates another PR.

  • The title says "the BVH descriptor base is a byte address with flags" and names rdna2spirv, but there is no translator change; the decode at tools/rdna2spirv.py:11223-11224 shifts a 256-byte-unit field, and the PR's own 0x1000 measurement plus docs/bvh.md:561-571 conclude 256-byte units with no masking. Retitle (and drop the translator claim) or add the change the title promises.
  • runtime/test/vk_compute_test.cpp:104-140 is byte-identical to vk_compute_test: VKC_HEAP_FILE, so a corpus shader can read a real BVH #3533, which the body says it depends on; keep it there only, or this PR is redundant.
  • The semantic change is a docstring only (tests/semantic/test_image_bvh_tri.py:14-16), and the base-0x10 fixture already exists on main (:26), so this adds no coverage.

What does check out: 7/7 semantic tests, 6/6 docs links, compileall clean, the masked-base control fails with 17 errors, and the decode matches docs/bvh.md:561/docs/design.md:297. The game-derived counts cannot be checked here.

AI-assisted review, no game files, no GPU.

@SuarezPM

Copy link
Copy Markdown
Contributor Author

@tupacfan04 — thanks for the review, including the parts that check out. One correction first, then the two points that are fair.

Title. The title you quote is the pre-measurement one. It was renamed at 22:00Z, before this review, after the base-0x1000 run falsified the masking: the current title is "Ray tracing: the first real core_bvh4 BLAS on a GPU (the descriptor base is the 256-byte-unit field)". The PR intentionally has no translator change — rdna2spirv.py keeps the << 8 at 11223-11224, exactly as you read it — because the measurement showed the field is 256-byte units and a byte-address-with-flags fix would be wrong. The docs record that result; the body says "No translator change is needed". If you were looking at a cached title or diff, a refresh should show the rename.

Duplication. You are right that runtime/test/vk_compute_test.cpp:104-140 is byte-identical to #3533: it is that PR's stacked commit, not a second submission. The body declares Depends on: #3533 and the coordination board lists the merge chain #3533 → #3794. When #3533 lands, this diff drops to the docs and the test comment automatically. I agree it is redundant in the meantime. If the maintainers prefer not to wait for #3533, I can rebase this branch onto main without the harness commit — that needs a force-push on my fork — and the diff becomes three files; I have not done it unilaterally because the PR documents the harness it was measured with. Say the word and I will unstack it.

Coverage. Correct, and not claimed. The three added lines are a docstring, not a new fixture: the 0x10 fixture already exists on main as NODE = 0x1040. What the comment records is what the GPU run established about that fixture's descriptor (base 0x1000, the << 8, no masking), and the measurement itself is in docs/bvh.md §7b with the base-0 and base-0x1000 GPU comparison. If you would rather not have the comment in the test file, I can drop it, but it is the only in-tree pointer tying the fixture to the measurement.

The game-derived counts cannot be checked from outside, as you note; that is why the body separates them from the reproducible parts. Thanks for the masked-base control (17 errors) — that is the control that settled the question.

AI-assisted.

@SuarezPM

Copy link
Copy Markdown
Contributor Author

@lunisahdidouch — thanks for the RDNA4 pass; it is the first one this PR has, and it matters because the descriptor decoding is the thing under test.

Your read of the semantic failures matches ours: none of them touch this PR's files, and the branch only changes docs, vk_compute_test.cpp (the #3533 stacked commit) and a docstring. The vk_pipeline_check_cli first-launch timeout also matches what a freshly built tool does here.

dbfbb386 only adds the native-instruction measurement to docs/bvh.md and the corrected sentence in docs/design.md on top of 7bf1db92, so your verification stands for the new head.

Thanks for running the whole suite instead of only the fixture.

AI-assisted.

shelbykb2 added a commit to shelbykb2/Leonida that referenced this pull request Nov 23, 2026
…ks on inner back edges

The summary now says, per category, how many sites have a some-paths read
before the next call in program order and how many have them all after a
later call. strip() also drops the saved-mask SGPRs, so a mask saved in one
pass of an inner loop cannot place a read in the next. The docs quote the
split instead of guessing causes, name the integer mnemonics, and no longer
mention word 0 (the base field belongs to ItsNotRexed#3794).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Resolve the Ray tracing row: keep main's native box-test details (SHADER-650)
and add the game's descriptor-base measurement (dword0 is `ptr >> 8`; the
`| 0x30` is only the rootNodePtr load address; base 0 and base 0x1000 agree),
plus the §7b run on the native instruction. `vk_compute_test.cpp` auto-merges
with both heap loaders: VKC_HEAP_INIT from main and VKC_HEAP_FILE from ItsNotRexed#3533.

Docs tests: test_docs_links, test_docs_repo_paths, test_docs_design_rows,
test_docs_table_rows and test_docs_list_items pass.
@sovljanskii

Copy link
Copy Markdown
Contributor

Tested eb1ab385 (it already contains main 3faac557) on an Apple M4 with MoltenVK 1.4.2 (Vulkan 1.4.357), macOS on arm64, Apple clang. Result: pass for everything that needs no game data. I could not reproduce the real core_bvh4 probe here.

Build and bvh tests

  • vk_compute_test builds with no warnings.
  • run_gpu_tests.py --filter bvh: cs_bvh and cs_bvh32 pass, 2/2.

Direct runs with VKC_HEAP_FILE

  • Both shaders were run three ways: with no heap file, then a 4096-byte synthetic file at @0x1000 and at @4096.
  • All three print bvh out = 00000068 00000048 00000040 ffffffff | c1200000 bf800000 be800000 be800000 and 0 mismatches.
  • The first word is 0x68 here, not the 0x48 in the earlier reports. Main's scene gained the SHADER-650 NaN box since then, and main's own binary prints the same 0x68.

The file lands at the offset you give

  • The bvh shader never reads 0x1000, so I wrote a scratch shader (not committed). It does a buffer_load_dwordx4 from VA 0x1000 through the output V# and stores the four words at 0.
  • The test file is 16 bytes: 0x1badb002 0xcafef00d 0x80000001 0x0000ffff.
  • With @0x1000 and with @4096, the shader reads back exactly those four words.
  • The buffer grew to 1,028 words on its own, without VKC_OUT_WORDS.
  • @0x1004 shifts the words by one.
  • With no file, the shader reads the 0xEE fill.
  • cs_heap_init with the same file at @0x100 reads the four words too.

Parser errors

  • Each of these exits with status 2 and prints the message: @-5, @, @0x, @12ab, @ 16, @0x1ffffffff, @16 (empty path), and a missing file.

Whole suite

  • run_gpu_tests.py: 152/217 passed, 58 skipped. Every test has the same result as main 3faac557 on this machine.
  • The 7 failures (cs_fma_fused, ps_ssharp, the f16/NaN compares) fail on main too, on MoltenVK.
  • ctest: 49/50. The one failure is vk_overlapping_occlusion, the same as on main.

One small note, not blocking

  • The bound check is parsed > (1ull << 32), so an offset of exactly 0x100000000 is accepted.
  • That offset runs fine but allocates a 4 GiB host-visible heap (4.3 GB resident here).
  • 0xFFFFFFFC with a file that ends past 4 GiB is accepted as well.
  • If the intent is offsets inside the 32-bit range, >= would express that, or a check on offset + size. If larger heaps are meant to work, ignore this.

No validation layer is installed on this Mac, so these direct runs had no validation. No game files were used. AI-assisted.

@chpeu

chpeu commented Nov 23, 2026

Copy link
Copy Markdown

Re-tested the current head eb1ab385 on Linux (RTX 3080, driver 615.71.09, Vulkan 1.4.351, llvm-mc 20.1.2, no
game files). My earlier report was on an older head; this head already contains current main.

  • GPU suite: LEONIDA_W64_EMULATE=1 python -I scripts/run_gpu_tests.py --build runtime/build/linux --llvm-mc /usr/lib/llvm-20/bin/llvm-mc → 201/217 passed, 16 skipped, 0 failed; without the variable 170/217,
    47 skipped, 0 failed
    — the same totals as main on this box.

  • The file you changed, runtime/test/vk_compute_test.cpp, is the runner those compute programs use, so the suite
    does exercise it; your ray-tracing programs come through green and say which card they ran on:

    PASS  cs_bvh    device: NVIDIA GeForce RTX 3080 (subgroup 32..32)
    PASS  cs_bvh32  device: NVIDIA GeForce RTX 3080 (subgroup 32..32)
    
  • python -m unittest discover -s tests/semantic -p test_image_bvh_tri.py → OK; the 31 pytest-marked
    translator files → 1637 passed, 37 skipped, 108 subtests, 0 failed, identical to main measured in the same
    session. python -m compileall -q make_game.py tools tests: clean.

  • Running vk_compute_test by hand still needs its arguments (usage: vk_compute_test cs.spv groups expect [--require-wave64]), which is why the run above — through scripts/run_gpu_tests.py — is the meaningful one.

The RTX 5080 was not run in this pass (186 MiB free, another job holds the card); on the passes where it did run it
matched the 3080 exactly. AI-assisted testing, counts read through by hand.

ItsNotRexed added a commit that referenced this pull request Nov 23, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	docs/design.md
@Jadiac5

Jadiac5 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

#3794 (head eb1ab38, open)

Tested eb1ab38 on Windows 11, AMD Radeon RX 9070 XT (RDNA4), driver 32.0.32029.2010: pass

  • python -I -m unittest discover -s tests/semantic -p test_image_bvh_tri.py: 7 tests OK.
  • Built vk_compute_test from this head (the only file the PR changes in runtime/). python -I scripts/run_gpu_tests.py --filter bvh: cs_bvh and cs_bvh32 PASS, 2/2. Full run with LEONIDA_W64_EMULATE=1: 202/217 passed, 15 skipped, 0 failed.
  • VKC_HEAP_FILE by hand with cs_bvh and a 64-byte file of my own: no offset, @4096, @0x1000, @0X10 all run, 0 mismatches, and the log line says "at 0x1000 (64 bytes)" for @0x1000. Exit 2 with the message for @-5, @, @0x, @12abc, a missing file, a missing file with an offset, and a spec with no path (@4096).
  • The PR has no translator change, so there is no negative control. The GPU measurement on a game shader in the description was not repeated (needs the game files).
  • An RX 9070 result exists at the earlier head 7bf1db9; this is the current head.

AI-assisted (Claude Code).

@SuarezPM

Copy link
Copy Markdown
Contributor Author

@sovljanskii — thanks; this is the first macOS/MoltenVK pass and the scratch-shader check is the piece that was missing: it proves the bytes land at @0x1000/@4096, not only that the shader ignores them. Your 0x68 vs 0x48 note is right: main's scene gained SHADER-650's NaN box, and main's own binary prints 0x68 too; the real-BLAS numbers in §7b are a different structure.

The 0x100000000 boundary is a real off-by-one (parsed > (1ull << 32)), so exactly 4 GiB is accepted. I am recording it as a follow-up: the intent is offsets inside the 32-bit range.

This PR closes as landed: main already contains §7b, the Ray tracing row and the test comment (dbfbb386 is an ancestor), and #3533 merged at 11:36, so there is no diff left. Thanks for the pass.

AI-assisted.

@SuarezPM

Copy link
Copy Markdown
Contributor Author

@chpeu — thanks for re-testing the current head and for matching main's totals exactly (201/217 with wave64, 170/217 native). That the suite runs vk_compute_test is the point; your green cs_bvh/cs_bvh32 on the 3080 plus the 1,637 translator tests are the assurance this needed.

This PR closes as landed: main already has the docs and #3533 merged at 11:36, so the branch has no diff left. Thanks for the repeat run.

AI-assisted.

@SuarezPM

Copy link
Copy Markdown
Contributor Author

@Jadiac5 — thanks for the RDNA4 pass on the current head and for the parser matrix. @0X10 works because the parser takes both cases; the exit-2 cases match the intent.

Your no-negative-control note is correct: there is no translator change to revert — the masked variant was measured at base 0x1000 and falsified, which is why the docs record 256-byte units. The game-shader measurement needs the package, as you say.

This PR closes as landed: main already contains the docs and the test comment (dbfbb386 is an ancestor), and #3533 merged at 11:36, so there is no diff left.

AI-assisted.

@SuarezPM

Copy link
Copy Markdown
Contributor Author

Closing as landed. dbfbb386 is an ancestor of main (git merge-base --is-ancestor), and current main carries docs/bvh.md §7b, the Ray tracing row additions and the test_image_bvh_tri.py comment; #3533 merged at 11:36 as well. The branch has no diff left against main (git diff upstream/main is empty), so there is nothing left to merge.

Thanks to everyone who measured it: RDNA4 (RX 9070 and 9070 XT), macOS/MoltenVK, RTX 3060/3080/4080/5070/5080/5090, the native box32 run and the semantic controls. AI-assisted.

@SuarezPM SuarezPM closed this Nov 23, 2026
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.