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

Merged
ozimchuk merged 2 commits from upstream-pr/146 into main 2026-11-23 21:08:36 +00:00
ozimchuk commented 2026-11-23 15:27:23 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by ozimchuk on 2026-11-23T15:27:23Z.


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

<!-- greyfinch-sync:ivall/xcl:issue:6562677388 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/146). Originally posted by [ozimchuk](https://github.com/ozimchuk) on 2026-11-23T15:27:23Z. --- `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)
upstream-sync closed this pull request 2026-11-24 06:57:23 +00:00
ivall commented 2026-11-24 07:04:20 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by ivall on 2026-11-23T21:09:02Z.


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).

<!-- greyfinch-sync:ivall/xcl:comment:7114072286 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/146#issuecomment-7114072286). Originally posted by [ivall](https://github.com/ivall) on 2026-11-23T21:09:02Z. --- 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).
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
xcl-dev/xcl!143
No description provided.