xshader: lower inline BVH64 ray-query walks to native ray queries #425

Merged
glovepost merged 3 commits from upstream-pr/425 into main 2026-11-29 01:16:17 +00:00
glovepost commented 2026-11-28 23:18:46 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by glovepost on 2026-11-28T23:18:46Z.


Summary

The compiler turns an HLSL RayQuery with one Proceed() and no candidate code into a loop around image_bvh64_intersect_ray: a shared-memory node stack, an instance-node branch that transforms the ray, and a first-hit or closest-hit triangle test. Upstream refuses these with "raw BVH node intersection requires traversal translation at N" unless the program is one of the four that scarlett_rays recognises by hash.

hlsl/ray_query.rs recognises the walk by its structure: the innermost s_cbranch_scc1 loop around a single image_bvh64_intersect_ray with no other memory traffic, entered only at its top, with the scene header read through (descriptor & 0xffffff00) | 0x30 before it. It reads the ray registers, tMin, the instance mask, the static facing cull, and the committed outputs (tMax, barycentrics, facing, hit flag) from the loop, and replaces the loop, its root-node load and its stack seed with one query instruction. The Committed*() node loads after the walk become reads of the query's CommittedInstanceID(), PrimitiveIndex() and so on.

The scene descriptor is resolved from the masking s_and_b32 to the title's acceleration structure at that table slot and read from the runtime's private scene space 900 at its index (scarlett_rays' numbering, now shared), which runtime/d3d12 already binds from the title's table or root SRV. The lowering runs after scarlett_rays and the radiance probes, so their programs keep their own path.

Over 36,644 recorded ProjectScarlett 1.0.2.1 requests main refused 21 with "raw BVH node intersection requires traversal translation"; 11 now translate (every program whose walks are all pure BVH64 queries), 11 compile with DXC and pass DXV. All other requests translate to byte-identical HLSL. BVH32 walks and walks with candidate code are left for later changes.

Tests: hlsl::ray_query::tests::a_closest_hit_bvh64_walk_becomes_one_native_query (fails on main with the refusal above), a_walk_whose_scene_is_not_an_acceleration_structure_is_refused, a_walk_that_reads_other_memory_is_left_alone, committed_accessors_after_the_walk_read_the_query, instance_masks_and_cull_modes_are_read_from_the_walk.

Tested

Run the checks relevant to this change.

  • The checks relevant to this change passed
  • Changed or new behaviour is covered by a Lanes scenario, or the reason it cannot be is stated below
  • Where the table calls for AMD and NVIDIA, they passed on both

No Lanes scenario for the new walk. Lanes has no RayQuery program with an inline BVH64 node loop. bvh64-query translates that walk and compares CommittedRayT with one front-facing triangle. The full check still ran the Lanes suites on both cards.

GPU, driver and backend: NVIDIA GeForce RTX 2070 SUPER (10de:1e84), driver 620.73.04; AMD Ryzen 7 9800X3D (RADV RAPHAEL_MENDOCINO, 1002:13c0); GE-Proton11-14 for both, under gamescope --backend headless with ENABLE_GAMESCOPE_WSI=0.

Commands run and their results. The Proton build is GE-Proton11-14 and the prefix is upstream-pr-checks. --windows-dxc points at Microsoft's x64 dxcompiler.dll and dxil.dll.

gamescope --backend headless -w 1280 -h 720 --prefer-vk-device 10de:1e84 -- \
  env WAYLAND_DISPLAY=$GAMESCOPE_WAYLAND_DISPLAY ENABLE_GAMESCOPE_WSI=0 \
  python3 tuxbox.py check --windows-dxc <dxc-dir> --backend proton \
    --proton GE-Proton11-14 --prefix upstream-pr-checks --adapter 10de:1e84
All checks passed.

gamescope --backend headless -w 1280 -h 720 --prefer-vk-device 1002:13c0 -- \
  env WAYLAND_DISPLAY=$GAMESCOPE_WAYLAND_DISPLAY ENABLE_GAMESCOPE_WSI=0 \
  python3 tuxbox.py check --windows-dxc <dxc-dir> --backend proton \
    --proton GE-Proton11-14 --prefix upstream-pr-checks --adapter 1002:13c0
All checks passed.

Present was inside that full check (private rootful Xwayland, ENABLE_GAMESCOPE_WSI=0): guest-present, guest-present-rgb10, guest-present-planes, the four 4k cases, on both adapters. The named Lanes suites in the shader-compiler row passed on both cards: lanes-shader-cache, lanes-raster-tables, lanes-compute-root, lanes-compute-root-recovery, and lanes-bindless-compute. The shader translator GPU check passed on both. Results are in build/check/results.json on the machine that ran them.

The new behaviour is covered by a translator GPU check. Same headless gamescope wrapper, Proton GE-Proton11-14, prefix upstream-pr-checks. --compiler-dir is the directory of Microsoft's x64 dxcompiler.dll and dxil.dll. --dxc is the native dxc executable, with dxv beside it.

gamescope --backend headless -w 1280 -h 720 --prefer-vk-device 10de:1e84 -- \
  env WAYLAND_DISPLAY=$GAMESCOPE_WAYLAND_DISPLAY ENABLE_GAMESCOPE_WSI=0 \
  python3 tools/check_translator_gpu.py \
    --provider build/d3d12-smoke/d3d12_xs.dll \
    --proton GE-Proton11-14 --prefix upstream-pr-checks \
    --compiler-dir <dxc-dir> --dxc <native-dxc> --llvm-mc llvm-mc \
    --adapter 10de:1e84 --work <fresh-work> --only bvh64-query

PASS on NVIDIA (10de:1e84). Hit bits 0000803f (t = 1), 16 words.

gamescope --backend headless -w 1280 -h 720 --prefer-vk-device 1002:13c0 -- \
  env WAYLAND_DISPLAY=$GAMESCOPE_WAYLAND_DISPLAY ENABLE_GAMESCOPE_WSI=0 \
  python3 tools/check_translator_gpu.py \
    --provider build/d3d12-smoke/d3d12_xs.dll \
    --proton GE-Proton11-14 --prefix upstream-pr-checks \
    --compiler-dir <dxc-dir> --dxc <native-dxc> --llvm-mc llvm-mc \
    --adapter 1002:13c0 --work <fresh-work> --only bvh64-query

PASS on AMD (1002:13c0). Same hit, 16 words.

AI use: Claude Code ported the change and wrote the tests. The headless checks above were already recorded on both GPUs. This session added the BVH64 GPU check, ran it on both GPUs, and updated the branch.

<!-- greyfinch-sync:brcly/TuxBox:issue:5545557678 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/425). Originally posted by [glovepost](https://github.com/glovepost) on 2026-11-28T23:18:46Z. --- ## Summary The compiler turns an HLSL RayQuery with one Proceed() and no candidate code into a loop around `image_bvh64_intersect_ray`: a shared-memory node stack, an instance-node branch that transforms the ray, and a first-hit or closest-hit triangle test. Upstream refuses these with "raw BVH node intersection requires traversal translation at N" unless the program is one of the four that `scarlett_rays` recognises by hash. `hlsl/ray_query.rs` recognises the walk by its structure: the innermost `s_cbranch_scc1` loop around a single `image_bvh64_intersect_ray` with no other memory traffic, entered only at its top, with the scene header read through `(descriptor & 0xffffff00) | 0x30` before it. It reads the ray registers, tMin, the instance mask, the static facing cull, and the committed outputs (tMax, barycentrics, facing, hit flag) from the loop, and replaces the loop, its root-node load and its stack seed with one query instruction. The Committed*() node loads after the walk become reads of the query's CommittedInstanceID(), PrimitiveIndex() and so on. The scene descriptor is resolved from the masking `s_and_b32` to the title's acceleration structure at that table slot and read from the runtime's private scene space 900 at its index (`scarlett_rays`' numbering, now shared), which `runtime/d3d12` already binds from the title's table or root SRV. The lowering runs after `scarlett_rays` and the radiance probes, so their programs keep their own path. Over 36,644 recorded ProjectScarlett 1.0.2.1 requests main refused 21 with "raw BVH node intersection requires traversal translation"; 11 now translate (every program whose walks are all pure BVH64 queries), 11 compile with DXC and pass DXV. All other requests translate to byte-identical HLSL. BVH32 walks and walks with candidate code are left for later changes. Tests: `hlsl::ray_query::tests::a_closest_hit_bvh64_walk_becomes_one_native_query` (fails on main with the refusal above), `a_walk_whose_scene_is_not_an_acceleration_structure_is_refused`, `a_walk_that_reads_other_memory_is_left_alone`, `committed_accessors_after_the_walk_read_the_query`, `instance_masks_and_cull_modes_are_read_from_the_walk`. ## Tested Run the [checks relevant to this change](../CONTRIBUTING.md#test-what-your-change-touches). - [x] The checks relevant to this change passed - [x] Changed or new behaviour is covered by a Lanes scenario, or the reason it cannot be is stated below - [x] Where the table calls for AMD and NVIDIA, they passed on both No Lanes scenario for the new walk. Lanes has no RayQuery program with an inline BVH64 node loop. `bvh64-query` translates that walk and compares `CommittedRayT` with one front-facing triangle. The full check still ran the Lanes suites on both cards. GPU, driver and backend: NVIDIA GeForce RTX 2070 SUPER (10de:1e84), driver 620.73.04; AMD Ryzen 7 9800X3D (RADV RAPHAEL_MENDOCINO, 1002:13c0); GE-Proton11-14 for both, under `gamescope --backend headless` with `ENABLE_GAMESCOPE_WSI=0`. Commands run and their results. The Proton build is GE-Proton11-14 and the prefix is `upstream-pr-checks`. `--windows-dxc` points at Microsoft's x64 `dxcompiler.dll` and `dxil.dll`. ```text gamescope --backend headless -w 1280 -h 720 --prefer-vk-device 10de:1e84 -- \ env WAYLAND_DISPLAY=$GAMESCOPE_WAYLAND_DISPLAY ENABLE_GAMESCOPE_WSI=0 \ python3 tuxbox.py check --windows-dxc <dxc-dir> --backend proton \ --proton GE-Proton11-14 --prefix upstream-pr-checks --adapter 10de:1e84 All checks passed. gamescope --backend headless -w 1280 -h 720 --prefer-vk-device 1002:13c0 -- \ env WAYLAND_DISPLAY=$GAMESCOPE_WAYLAND_DISPLAY ENABLE_GAMESCOPE_WSI=0 \ python3 tuxbox.py check --windows-dxc <dxc-dir> --backend proton \ --proton GE-Proton11-14 --prefix upstream-pr-checks --adapter 1002:13c0 All checks passed. ``` Present was inside that full check (private rootful Xwayland, `ENABLE_GAMESCOPE_WSI=0`): guest-present, guest-present-rgb10, guest-present-planes, the four 4k cases, on both adapters. The named Lanes suites in the shader-compiler row passed on both cards: `lanes-shader-cache`, `lanes-raster-tables`, `lanes-compute-root`, `lanes-compute-root-recovery`, and `lanes-bindless-compute`. The shader translator GPU check passed on both. Results are in `build/check/results.json` on the machine that ran them. The new behaviour is covered by a translator GPU check. Same headless gamescope wrapper, Proton GE-Proton11-14, prefix `upstream-pr-checks`. `--compiler-dir` is the directory of Microsoft's x64 `dxcompiler.dll` and `dxil.dll`. `--dxc` is the native dxc executable, with dxv beside it. ```text gamescope --backend headless -w 1280 -h 720 --prefer-vk-device 10de:1e84 -- \ env WAYLAND_DISPLAY=$GAMESCOPE_WAYLAND_DISPLAY ENABLE_GAMESCOPE_WSI=0 \ python3 tools/check_translator_gpu.py \ --provider build/d3d12-smoke/d3d12_xs.dll \ --proton GE-Proton11-14 --prefix upstream-pr-checks \ --compiler-dir <dxc-dir> --dxc <native-dxc> --llvm-mc llvm-mc \ --adapter 10de:1e84 --work <fresh-work> --only bvh64-query ``` PASS on NVIDIA (10de:1e84). Hit bits `0000803f` (t = 1), 16 words. ```text gamescope --backend headless -w 1280 -h 720 --prefer-vk-device 1002:13c0 -- \ env WAYLAND_DISPLAY=$GAMESCOPE_WAYLAND_DISPLAY ENABLE_GAMESCOPE_WSI=0 \ python3 tools/check_translator_gpu.py \ --provider build/d3d12-smoke/d3d12_xs.dll \ --proton GE-Proton11-14 --prefix upstream-pr-checks \ --compiler-dir <dxc-dir> --dxc <native-dxc> --llvm-mc llvm-mc \ --adapter 1002:13c0 --work <fresh-work> --only bvh64-query ``` PASS on AMD (1002:13c0). Same hit, 16 words. _AI use: Claude Code ported the change and wrote the tests. The headless checks above were already recorded on both GPUs. This session added the BVH64 GPU check, ran it on both GPUs, and updated the branch._
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
brcly/TuxBox!425
No description provided.