xshader: lower inline BVH32 ray-query loops to native TraceRayInline #477

Merged
glovepost merged 1 commit from upstream-pr/477 into main 2026-11-29 14:44:47 +00:00
glovepost commented 2026-11-29 13:42:29 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by glovepost on 2026-11-29T13:42:29Z.


Summary

Extends tools/shader-compiler/src/hlsl/ray_query/ (splitting ray_query.rs into ray_query/mod.rs and ray_query/bvh32.rs) to recognise and lower inline RDNA2 BVH32 (image_bvh_intersect_ray) ray-query loops to native HLSL RayQuery / TraceRayInline, alongside the existing BVH64 (image_bvh64_intersect_ray) lowering.

The BVH32 planner recovers the scene descriptor capture, root-node load, ray operands, instance mask (constant or dynamic SGPR), triangle cull mode, and closest-hit or first-hit outputs, and leaves walks with external memory traffic or external loop entries untouched. Synthetic instruction rewrites in ray_query/mod.rs (s_nop, tb_bvh64_ray_query, tb_bvh64_ray_attr, and root_loads s_mov_b32) now normalise dwords, raw, and aux, and wave_loops::full_mask_program allowlists tb_bvh64_ray_query and tb_bvh64_ray_attr, so inline ray queries inside mixed-lane Wave32 compute programs preserve whole-wave uniform dispatch.

Adds six unit tests covering BVH32 lowering, non-acceleration-structure refusal, external-memory and external-entry rejection, instance-mask/cull-mode/hit variants, mixed-lane Wave32 uniform dispatch, and a GPU capture test, and registers bvh32-query in tools/check_translator_gpu.py.

Lanes does not build a raytracing acceleration structure or dispatch inline RDNA2 image_bvh_intersect_ray walks; bvh32-query in tools/check_translator_gpu.py executes the translated RayQuery shader against a real D3D12 acceleration structure on both GPUs and verifies the hit distance readback.

Prepared with AI coding assistance and verified by the checks below.

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. Otherwise, say which vendor still needs to run them:

GPU, driver and backend:

  • NVIDIA GeForce RTX 2070 SUPER (10de:1e84), driver 620.73.04, GE-Proton11-14 (proton)
  • AMD Ryzen 7 9800X3D integrated GPU (1002:13c0, RADV RAPHAEL_MENDOCINO), Mesa 26.3.1-arch3.5, GE-Proton11-14 (proton)

Commands run and their results:

python tuxbox.py check --no-gpu
-> 7/7 passed (Build the shader compiler, 602 Python tests, 580 shader-compiler tests, 88 DXBC tests, 17 XG layout tests / 1 ignored, 18 storage codec tests, D3D12 Windows typecheck)

cargo test --target x86_64-unknown-linux-gnu --manifest-path tools/shader-compiler/Cargo.toml ray_query
-> 12 passed; 0 failed

python tools/check_translator_gpu.py --provider build/d3d12-smoke/d3d12_xs.dll --proton <proton> --prefix <prefix> --compiler-dir <windows-dxc> --dxc <dxc> --adapter 10de:1e84 --work <work>
-> 64/64 PASS (bvh32-query and bvh64-query both True hit 0000803f words 16)

python tuxbox.py verify --backend proton --proton <proton> --prefix <prefix> --adapter 10de:1e84 --only lanes-shader-cache --only lanes-raster-tables --only lanes-compute-root --only lanes-compute-root-recovery --only lanes-bindless-compute --output <output>
-> 33/33 PASS (pci=10de:1e84)

python tools/check_translator_gpu.py --provider build/d3d12-smoke/d3d12_xs.dll --proton <proton> --prefix <prefix> --compiler-dir <windows-dxc> --dxc <dxc> --adapter 1002:13c0 --work <work>
-> 64/64 PASS (bvh32-query and bvh64-query both True hit 0000803f words 16)

python tuxbox.py verify --backend proton --proton <proton> --prefix <prefix> --adapter 1002:13c0 --only lanes-shader-cache --only lanes-raster-tables --only lanes-compute-root --only lanes-compute-root-recovery --only lanes-bindless-compute --output <output>
-> 33/33 PASS (pci=1002:13c0)

Checks

CI runs the Python unit tests, the shader compiler, DXBC, and XG layout tests, and a Windows typecheck of tuxbox-d3d12.

If this pull request changes evidence JSON, regenerate the results table and the progress map and include both files:

python tuxbox.py status > docs/RESULTS.md
python tuxbox.py status --svg docs/progress.svg
<!-- greyfinch-sync:brcly/TuxBox:issue:5551290415 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/477). Originally posted by [glovepost](https://github.com/glovepost) on 2026-11-29T13:42:29Z. --- ## Summary Extends `tools/shader-compiler/src/hlsl/ray_query/` (splitting `ray_query.rs` into `ray_query/mod.rs` and `ray_query/bvh32.rs`) to recognise and lower inline RDNA2 BVH32 (`image_bvh_intersect_ray`) ray-query loops to native HLSL `RayQuery` / `TraceRayInline`, alongside the existing BVH64 (`image_bvh64_intersect_ray`) lowering. The BVH32 planner recovers the scene descriptor capture, root-node load, ray operands, instance mask (constant or dynamic SGPR), triangle cull mode, and closest-hit or first-hit outputs, and leaves walks with external memory traffic or external loop entries untouched. Synthetic instruction rewrites in `ray_query/mod.rs` (`s_nop`, `tb_bvh64_ray_query`, `tb_bvh64_ray_attr`, and `root_loads` `s_mov_b32`) now normalise `dwords`, `raw`, and `aux`, and `wave_loops::full_mask_program` allowlists `tb_bvh64_ray_query` and `tb_bvh64_ray_attr`, so inline ray queries inside mixed-lane Wave32 compute programs preserve whole-wave uniform dispatch. Adds six unit tests covering BVH32 lowering, non-acceleration-structure refusal, external-memory and external-entry rejection, instance-mask/cull-mode/hit variants, mixed-lane Wave32 uniform dispatch, and a GPU capture test, and registers `bvh32-query` in `tools/check_translator_gpu.py`. Lanes does not build a raytracing acceleration structure or dispatch inline RDNA2 `image_bvh_intersect_ray` walks; `bvh32-query` in `tools/check_translator_gpu.py` executes the translated `RayQuery` shader against a real D3D12 acceleration structure on both GPUs and verifies the hit distance readback. Prepared with AI coding assistance and verified by the checks below. ## 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. Otherwise, say which vendor still needs to run them: GPU, driver and backend: - NVIDIA GeForce RTX 2070 SUPER (`10de:1e84`), driver `620.73.04`, GE-Proton11-14 (`proton`) - AMD Ryzen 7 9800X3D integrated GPU (`1002:13c0`, RADV RAPHAEL_MENDOCINO), Mesa `26.3.1-arch3.5`, GE-Proton11-14 (`proton`) Commands run and their results: ```text python tuxbox.py check --no-gpu -> 7/7 passed (Build the shader compiler, 602 Python tests, 580 shader-compiler tests, 88 DXBC tests, 17 XG layout tests / 1 ignored, 18 storage codec tests, D3D12 Windows typecheck) cargo test --target x86_64-unknown-linux-gnu --manifest-path tools/shader-compiler/Cargo.toml ray_query -> 12 passed; 0 failed python tools/check_translator_gpu.py --provider build/d3d12-smoke/d3d12_xs.dll --proton <proton> --prefix <prefix> --compiler-dir <windows-dxc> --dxc <dxc> --adapter 10de:1e84 --work <work> -> 64/64 PASS (bvh32-query and bvh64-query both True hit 0000803f words 16) python tuxbox.py verify --backend proton --proton <proton> --prefix <prefix> --adapter 10de:1e84 --only lanes-shader-cache --only lanes-raster-tables --only lanes-compute-root --only lanes-compute-root-recovery --only lanes-bindless-compute --output <output> -> 33/33 PASS (pci=10de:1e84) python tools/check_translator_gpu.py --provider build/d3d12-smoke/d3d12_xs.dll --proton <proton> --prefix <prefix> --compiler-dir <windows-dxc> --dxc <dxc> --adapter 1002:13c0 --work <work> -> 64/64 PASS (bvh32-query and bvh64-query both True hit 0000803f words 16) python tuxbox.py verify --backend proton --proton <proton> --prefix <prefix> --adapter 1002:13c0 --only lanes-shader-cache --only lanes-raster-tables --only lanes-compute-root --only lanes-compute-root-recovery --only lanes-bindless-compute --output <output> -> 33/33 PASS (pci=1002:13c0) ``` ## Checks CI runs the Python unit tests, the shader compiler, DXBC, and XG layout tests, and a Windows typecheck of `tuxbox-d3d12`. If this pull request changes evidence JSON, regenerate the results table and the progress map and include both files: ```sh python tuxbox.py status > docs/RESULTS.md python tuxbox.py status --svg docs/progress.svg ```
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!477
No description provided.