Skip to content

vk_compute_test: VKC_HEAP_FILE, so a corpus shader can read a real BVH - #3533

Open
SuarezPM wants to merge 3 commits into
ItsNotRexed:mainfrom
SuarezPM:rt-shader-real-bvh
Open

SuarezPM wants to merge 3 commits into
ItsNotRexed:mainfrom
SuarezPM:rt-shader-real-bvh

Conversation

@SuarezPM

@SuarezPM SuarezPM commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: new RT item — real-BVH GPU harness + first game RT CS execution; the real-BLAS execution is #3794.

What and why

vk_compute_test could only read the 0x280-byte synthetic BVH scene it builds itself (cs_bvh.asm). This adds VKC_HEAP_FILE=<path>[@<offset>], which copies a file into the heap at a chosen Xbox VA, so a translated corpus shader can read a real BVH, its descriptor blocks and the records. The file is read at run time only; nothing is committed.

That feature is what made the first execution of one of the game's 64 RT compute shaders on a PC GPU possible, and it is also how the real console BLAS was traversed in #3794.

While this PR was in review, main gained VKC_HEAP_INIT (seeds the heap at VA 0 and requires the file to fit). The merge keeps both loaders: VKC_HEAP_INIT at VA 0, VKC_HEAP_FILE at an offset and growing the buffer; the parser and overlap notes above are unchanged.

Tested

  • This machine (Linux, RTX 2060 SUPER, driver 620.73.04, Vulkan 1.4.357): the game's RT shadow CS over a rehydrated core_bvh4 BLAS; the first traversal call's children match xdxr_bvh.intersect_node, same order (Ray tracing: the first real core_bvh4 BLAS on a GPU (the descriptor base is the 256-byte-unit field) #3794).
  • @wildheathen (Windows 11, RTX 5080, driver 621.24, MSVC 14.51): pass. Builds clean; cs_bvh/cs_bvh32 unchanged; the same scene through the file gives the same eight words, and parsing/error cases behave. With eight console BLAS (2 to 21,814 leaves) rehydrated with bvh_rehydrate.py, one image_bvh_intersect_ray step per node over 48 rays per BLAS: 1,647 steps, all agree with intersect_node except 116 box ties (same children, float32 entry-distance order), 27 triangle t values within float32 ulps of the vertices, and one shared-edge pair where each chooses a different triangle (watertight; one hit either way). Negative control: zeroing the BVH changes 38 of 64 lanes.
  • @crastinator (AMD RX 6700 XT, gfx1031, RADV Mesa 26.3.1, Linux 7.3.5, GCC 16.2.1): pass. Whole run_gpu_tests.py 185/199 native and with LEONIDA_W64_EMULATE=1, ctest 41/41 (the skips match main).
  • Our own: the game RT CS over the real BLAS (see Ray tracing: the first real core_bvh4 BLAS on a GPU (the descriptor base is the 256-byte-unit field) #3794); spirv-val pass.

Two review nits are fixed in 557a25ed: the offset is parsed as decimal or 0x hex explicitly (a leading zero was octal: @0256 loaded at 0xae; signs/spaces are rejected; 4 GiB cap), and the comment documents the two overlaps (bvh mode overwrites 0x100..0x264 after the copy; the output V# starts at heap offset 0, so a file at @0 shares bytes with it).

No game data: the file path is supplied by the user at run time and nothing decoded is committed. AI-assisted.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md): the file path is supplied by the user at run time and nothing decoded is committed; the validation quoted here is counts and node ids only.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (Not applicable: no translator change in this PR.)

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.
@wildheathen

Copy link
Copy Markdown
Contributor

Tested 0c1cb465 on Windows 11, RTX 5080 (driver 621.24, Vulkan SDK 1.4.363), MSVC 14.51, with my own copy of the game for the last part: pass.

  • Build: vk_compute_test builds with no warnings.
  • Existing tests, no env var: run_gpu_tests.py --filter cs_bvh: cs_bvh and cs_bvh32 PASS.
  • Same scene through the file: I took the 384 bytes bvh mode writes at 0x100 from a VKC_DUMP and loaded them back with VKC_HEAP_FILE=scene.bin@0x100 in a mode that writes nothing itself. cs_bvh32 gives the same eight words as bvh mode (48 40 ffffffff ffffffff c1200000 bf800000 be800000 be800000), and the first 0x280 bytes of the two dumps are identical. Without the file, both steps miss.
  • Parsing: @256 and @0x100 both load at 0x100. x@, x@zz, @0x100, a missing file and an empty file each exit 2 with the message.
  • Real console BLAS, not GPU-built: this complements your vk_xdxr_build_test case. I used eight console BLAS, 2 to 21,814 leaves, rehydrated with tools/bvh_rehydrate.py from my copy and loaded with VKC_HEAP_FILE. A local 18-line shader, not committed, runs one 32-bit image_bvh_intersect_ray step per lane, reading node, ray and inverse direction from the heap. For 48 rays per BLAS, every node a closest-hit traversal visits is one step: 1,647 steps in all (1,302 box, 345 triangle, 180 triangle hits), each compared with tools/xdxr_bvh.py's intersect_node. Everything agrees except:
    • 116 box steps return the same children in a different order. Each is a true tie: the GPU order is sorted by float32 entry distance in every one of them, the same as your 0.0 case.
    • 27 triangle steps differ in t within float32 precision of the vertex coordinates (16 ulp of the largest coordinate or less). The CPU walker matches the exact rational intersection; the barycentrics agree within 1e-4.
    • 2 triangle steps come from one ray through the edge two triangles of one leaf share. The CPU gives the hit to one triangle and the GPU to the other: one hit either way, so still watertight.
    • Negative control: zeroing the BVH bytes in the file changes 38 of the 64 lanes.

Two small points, neither blocking:

  1. The offset goes through strtoull(digits, &end, 0), so a leading zero means octal: @0256 loads at 0xae, not 256. A leading - or spaces are accepted too. parse_u32 in the same file already does "decimal or 0x hex" exactly; a 64-bit variant of it would make the two variables behave the same.
  2. Two overlaps, worth one line in the comment or a warning:
    • In bvh mode the synthetic scene is written after the file, so it overwrites 0x100-0x264 of a file placed there.
    • The dispatch's output words start at heap offset 0, so a file loaded at @0 (as in your example, with the BVH at VA 0) shares bytes with the output. That is harmless for one group writing at the end, but not in general.

AI-assisted.

@crastinator

Copy link
Copy Markdown
Contributor

Tested 0c1cb46 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 (the skips are the D3D12-only fixtures and ps_w64x_readlane, as on main). ctest 41/41.

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

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.
@SuarezPM

Copy link
Copy Markdown
Contributor Author

Thanks for the AMD/RADV pass and for running the whole suite and ctest, not just the new path; that is the coverage this needed. The two earlier nits from @wildheathen are fixed in 557a25ed, so the branch moved after your run by that parser-only change. Nothing else changed. AI-assisted.

@SuarezPM

Copy link
Copy Markdown
Contributor Author

Thanks, this is the strongest validation the harness has: eight real console BLAS, 1,647 steps against intersect_node, plus the negative control. The tie orders and the ulp t values are the expected float32 differences; the shared-edge pair being watertight (one hit either way) is exactly the right result.

Both nits are fixed in 557a25ed:

  • The offset now parses decimal or 0x hex explicitly (64-bit, 4 GiB cap). @0256 is 256 now, and signs/spaces are rejected like the invalid cases you tried.
  • The comment documents both overlaps: bvh mode writes its scene after the copy, so 0x100..0x264 is overwritten there; the output V# starts at heap offset 0, so @0 shares bytes with the output.

Your eight-BLAS run is cited in the PR body. AI-assisted.

Keep both heap loaders: main's VKC_HEAP_INIT (VA 0) and this branch's VKC_HEAP_FILE (offset, auto-sized).
@JRamos1993

Copy link
Copy Markdown
Contributor

Tested 73bee00 merged onto main aa2988c on an RTX 5090 (driver 616.92), Windows 11, MSVC 19.44, Vulkan SDK 1.4.363, RelWithDebInfo:

  • Full ctest: 154/154.
  • Warnings: none new in the files this PR changes.

AI-assisted (Claude Code).

@SuarezPM

Copy link
Copy Markdown
Contributor Author

@JRamos1993 Thanks!

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