Compute dispatches: a shader takes no more arguments from user SGPRs than it has (XboxBvhBuilder builds empty BLAS / TLAS) #146

Manually merged
github merged 2 commits from gh-pr/146/head into gh-pr/146/base 2026-11-26 04:12:30 +00:00
Owner

@⁠ozimchuk on GitHub · 2026-11-23 15:27 UTC · original
ozimchuk:console-list-user-sgprs → main · +116 −6 · 5 files · 2 commits · merged 2026-11-23 21:08 UTC

xbox_bvh_builder_builds_on_the_gpu and xbox_bvh_builder_builds_a_tlas_on_the_gpu fail on main: every ray that should hit misses, and the TLAS header is all zeros. They only do anything with XCL_PROBE_BVH_GPU / XCL_PROBE_BVH_TLAS set, so a normal cargo test stays green.

Cause

Since 18cb400 the root arguments of a compute dispatch go into user SGPRs s4… while they fit, and the rest into the table at s[0:1] (console_list::layout_from_blob). That is what the console's compiler emits now. The shaders inside XboxBvhBuilder.dll were built the earlier way, the one HANDOFF describes first ("determined on 52 shaders of XboxBvhBuilder.dll"): four user SGPRs whatever the root signature, s4 the group id, every argument read from the table.

The builder's first dispatch has a root signature of two descriptors and 16 constants. XCL puts the descriptors in s4…s7 and the constants in the table. The shader starts:

s_and_b32  s3, s1, 0xff
s_mov_b32  s2, s0
v_lshl_add_u32 v0, s4, 5, v0        ; s4 = group id
s_load_dword s5, s[2:3], 0x10       ; its count: table +0x10
v_cmpx_gt_u32 s5, v0
s_cbranch_execz …                   ; nothing to do
s_load_dwordx2 s[0:1], s[2:3], 0x0  ; a buffer's address: table +0

At +0x10 of the table it finds a constant that is 0, and leaves. All ten dispatches of a build run, none writes: after the list the destination and the scratch buffer are untouched.

Change

The number of user SGPRs is in each shader (COMPUTE_PGM_RSRC2, which CsInterface already reads to place the group id). It is now kept per translated compute pipeline (real::pso_user_sgprs) and caps the inline part (console_list::inline_for): never more bytes in registers than the shader has registers above s3. Used in both places that lay arguments out, the console list replay and bind_abi (with only the first, the BLAS test passed and the TLAS test did not). Parameters stay whole (the inline part ends where the last parameter that fits ends), and the entry is forgotten with the pipeline, like its root signature. A shader the rule fits gets what it got before; with the count unknown the rule applies as before.

Tests

New, no GPU: xbox_bvh_builder_shaders_get_no_argument_in_a_register_they_do_not_have (needs XCL_SAMPLE_DLLS). It finds every compute shader in XboxBvhBuilder.dll by its DXBC header and compares the user SGPRs of its stage descriptor with the layout from its own RTS0:

XboxBvhBuilder.dll: 52 compute shaders; by the layout's rule alone 48 would get arguments in registers they do not have

The same line on Windows 11 (26200) and under Wine. Also a unit test for inline_for.

With XCL_CONSOLE_LISTS=1 XCL_PROBE_BVH_GPU=1 XCL_PROBE_BVH_TLAS=1, on main at 484dd57:

main this branch
…builds_on_the_gpu, AMD iGPU (RADV) round 1: ray … left: None, right: Some(38) 64 and 200 triangles: 500 rays match brute force each (91 / 257 hits)
…builds_a_tlas_on_the_gpu, AMD iGPU header [0, 0, …], left: None, right: Some((38, 110)) 800 rays match brute force (69 hits)
both, RTX 5060 Ti (split wave64) the same failures the same passes

cargo test -p xcl --lib on the AMD GPU: 369 passed / 6 failed on main, 370 / the same 6 here (the new unit test). The six are not about this: two are my packaging (tests/data/llvm-amdgpu not next to the binary), three are RADV's ACO (gpu_format_stores_atomics_global_lds, gpu_f64_roots, gpu_f64_math_random: they pass with RADV_DEBUG=llvm and on NVIDIA), one is Wine (get_proc_address_and_load_library_ex_reject_null_name: last error 87, not 127); gpu_pso_e2e (6 / 6 with a retail shader pack), gpu_compute_e2e and the test title are unchanged.

What I could not check

The GPU runs are on Linux: Wine with vkd3d-proton, GNU toolchain build, and a vkd3d-proton patched to accept the objects whose vtable XCL replaces (a separate topic). On Windows only the no-GPU test was run. Since the argument layout is XCL's own code I expect the two GPU tests to fail on main and pass here on Windows as well; could you run them with the probe variables set?

AI-assisted.

🤖 Generated with Claude Code

**@⁠ozimchuk** on GitHub · 2026-11-23 15:27 UTC · [original](https://github.com/xcl-dev/xcl/pull/146) `ozimchuk:console-list-user-sgprs` → `main` · +116 −6 · 5 files · 2 commits · merged 2026-11-23 21:08 UTC `xbox_bvh_builder_builds_on_the_gpu` and `xbox_bvh_builder_builds_a_tlas_on_the_gpu` fail on `main`: every ray that should hit misses, and the TLAS header is all zeros. They only do anything with `XCL_PROBE_BVH_GPU` / `XCL_PROBE_BVH_TLAS` set, so a normal `cargo test` stays green. ## Cause Since 18cb400 the root arguments of a compute dispatch go into user SGPRs s4… while they fit, and the rest into the table at s[0:1] (`console_list::layout_from_blob`). That is what the console's compiler emits now. The shaders inside XboxBvhBuilder.dll were built the earlier way, the one HANDOFF describes first ("determined on 52 shaders of XboxBvhBuilder.dll"): four user SGPRs whatever the root signature, s4 the group id, every argument read from the table. The builder's first dispatch has a root signature of two descriptors and 16 constants. XCL puts the descriptors in s4…s7 and the constants in the table. The shader starts: ``` s_and_b32 s3, s1, 0xff s_mov_b32 s2, s0 v_lshl_add_u32 v0, s4, 5, v0 ; s4 = group id s_load_dword s5, s[2:3], 0x10 ; its count: table +0x10 v_cmpx_gt_u32 s5, v0 s_cbranch_execz … ; nothing to do s_load_dwordx2 s[0:1], s[2:3], 0x0 ; a buffer's address: table +0 ``` At +0x10 of the table it finds a constant that is 0, and leaves. All ten dispatches of a build run, none writes: after the list the destination and the scratch buffer are untouched. ## Change The number of user SGPRs is in each shader (COMPUTE_PGM_RSRC2, which `CsInterface` already reads to place the group id). It is now kept per translated compute pipeline (`real::pso_user_sgprs`) and caps the inline part (`console_list::inline_for`): never more bytes in registers than the shader has registers above s3. Used in both places that lay arguments out, the console list replay and `bind_abi` (with only the first, the BLAS test passed and the TLAS test did not). Parameters stay whole (the inline part ends where the last parameter that fits ends), and the entry is forgotten with the pipeline, like its root signature. A shader the rule fits gets what it got before; with the count unknown the rule applies as before. ## Tests New, no GPU: `xbox_bvh_builder_shaders_get_no_argument_in_a_register_they_do_not_have` (needs `XCL_SAMPLE_DLLS`). It finds every compute shader in XboxBvhBuilder.dll by its DXBC header and compares the user SGPRs of its stage descriptor with the layout from its own RTS0: ``` XboxBvhBuilder.dll: 52 compute shaders; by the layout's rule alone 48 would get arguments in registers they do not have ``` The same line on Windows 11 (26200) and under Wine. Also a unit test for `inline_for`. With `XCL_CONSOLE_LISTS=1 XCL_PROBE_BVH_GPU=1 XCL_PROBE_BVH_TLAS=1`, on `main` at 484dd57: | | `main` | this branch | |---|---|---| | `…builds_on_the_gpu`, AMD iGPU (RADV) | round 1: ray … left: None, right: Some(38) | 64 and 200 triangles: 500 rays match brute force each (91 / 257 hits) | | `…builds_a_tlas_on_the_gpu`, AMD iGPU | header [0, 0, …], left: None, right: Some((38, 110)) | 800 rays match brute force (69 hits) | | both, RTX 5060 Ti (split wave64) | the same failures | the same passes | `cargo test -p xcl --lib` on the AMD GPU: 369 passed / 6 failed on `main`, 370 / the same 6 here (the new unit test). The six are not about this: two are my packaging (`tests/data/llvm-amdgpu` not next to the binary), three are RADV's ACO (`gpu_format_stores_atomics_global_lds`, `gpu_f64_roots`, `gpu_f64_math_random`: they pass with `RADV_DEBUG=llvm` and on NVIDIA), one is Wine (`get_proc_address_and_load_library_ex_reject_null_name`: last error 87, not 127); `gpu_pso_e2e` (6 / 6 with a retail shader pack), `gpu_compute_e2e` and the test title are unchanged. ## What I could not check The GPU runs are on Linux: Wine with vkd3d-proton, GNU toolchain build, and a vkd3d-proton patched to accept the objects whose vtable XCL replaces (a separate topic). On Windows only the no-GPU test was run. Since the argument layout is XCL's own code I expect the two GPU tests to fail on `main` and pass here on Windows as well; could you run them with the probe variables set? AI-assisted. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Root arguments of a compute dispatch go into user SGPRs s4… while they fit
and the rest into the table at s[0:1] (18cb400, measured on the console
compiler's output). XboxBvhBuilder.dll's shaders were built differently:
four user SGPRs whatever the root signature, s4 the group id, every
argument read from the table. For a root signature of two descriptors and
16 constants XCL put the descriptors in s4…s7 and the constants in the
table; the builder's first shader then read a constant where its count is
(`s_load_dword s5, s[2:3], 0x10`), found 0 and left. All of its dispatches
ran and none wrote: the BLAS and TLAS came out empty.

The number of user SGPRs is in each shader (COMPUTE_PGM_RSRC2, already
read for the group id's place). It is now kept per translated compute
pipeline (`real::pso_user_sgprs`, forgotten with the pipeline) and caps
the inline part (`console_list::inline_for`) in both places that lay
arguments out: the console list replay and `bind_abi`. Parameters stay
whole. A shader the rule fits is unaffected, and so is one whose count is
not known.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Every compute shader inside XboxBvhBuilder.dll (XCL_SAMPLE_DLLS), found by
its DXBC header: the user SGPRs its stage descriptor gives against the
argument layout from its own RTS0 part. All 52 have four user SGPRs; by
the layout's rule alone 48 of them would get arguments in s4 and up.
Runs in milliseconds and needs no device.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:12:28 +00:00
github manually merged commit 1ffa570b3c into gh-pr/146/base 2026-11-26 04:12:30 +00:00
Author
Owner

@⁠ivall on GitHub · 2026-11-23 21:09 UTC · original

Merged (main 6da33fa). Checked on an RX 9070 (RDNA4) with the 22 PRs merged together on main eaa36b6: cargo build --workspace && cargo test --workspace -- --test-threads=4 - 582 unit tests passed, 0 failed (20 ignored), the integration and e2e tests passed too; and the retail game still reaches its first menu (646 frames in 30 s, no device removal).

**@⁠ivall** on GitHub · 2026-11-23 21:09 UTC · [original](https://github.com/xcl-dev/xcl/pull/146#issuecomment-7114072286) Merged (main 6da33fa). Checked on an RX 9070 (RDNA4) with the 22 PRs merged together on main eaa36b6: `cargo build --workspace && cargo test --workspace -- --test-threads=4` - 582 unit tests passed, 0 failed (20 ignored), the integration and e2e tests passed too; and the retail game still reaches its first menu (646 frames in 30 s, no device removal).
This discussion has been locked. Commenting is limited to contributors.
No description provided.