DXIL: fix compact SGPR liveness for RMW/CMOV SALU and Wave32 masks #2604

Open
github-bot wants to merge 1 commit from github-bot/gh-2604 into amd-dev AGit
Owner

@⁠AlpPesen on GitHub · 2026-11-26 01:27 UTC · original
AlpPesen:amd-dev/fix-compact-sgpr-liveness → amd-dev · +66 −9 · 1 files · 1 commits · open

Fixes two SGPR liveness bugs in amd-dev's compact DXIL micro-block emitter (crates/xcl/src/gpu/dxil/compact.rs):

  1. Conditional-write and RMW SALU ops dropped from use / killed in def: inst_sreg_scc_use_def only treated S_CMOVK_I32 as a conditional write. In rdna2_spec.rs, S_CMOV_B32, S_CMOV_B64, S_ADDK_I32, S_MULK_I32, S_BITSET0_B32/B64, and S_BITSET1_B32/B64 declare SDST with input: false, output: true, so predecessor micro-blocks could elide storing SDST to its alloca slot and feed stale/zero data into the successor.
  2. Wave32 64-bit VALU mask writers over-killed s[v + 1]: VALU mask writers (V_CMP_*, V_ADD_CO_*, etc.) declare size: 64 in rdna2_spec.rs, but in Wave32 (!wave64) they only write the low SGPR and leave s[v + 1] intact.

What is in it

  • Thread lw.wave64 into compute_live_out and inst_sreg_scc_use_def in crates/xcl/src/gpu/dxil/compact.rs.
  • Treat all S_CMOV* as conditional writes (add SDST to u, omit from def) and S_ADDK_I32 / S_MULK_I32 / S_BITSET{0,1}_B{32,64} as read-modify-write (add SDST to both u and def).
  • Clamp def width to 1 SGPR for non-S_* 64-bit mask outputs when !wave64.
  • Add unit test cmov_and_rmw_salu_read_sdst_and_wave32_valu_keeps_hi_sgpr in compact::liveness_tests.

Tested

  • Hardware: Intel Core i9-9900K, 32 GB RAM, AMD Radeon RX 6800 (16337 MiB VRAM, RDNA2, driver 32.0.21045.29003), Windows 11 Pro build 26300, rustc 1.100.0, DXC 1.9.2602.17.
  • cargo test -p xcl --lib gpu::dxil::compact: 12 passed, 0 failed, 0 ignored, 0 skipped.

Not tested

  • NVIDIA or Intel GPUs, wave32-only hardware, or Linux/Wine.

Regression run

xcl-smoke v1
commit: e1d84b7d9153f86a97d2ec5d209d196046fc0bea
gpu: AMD Radeon RX 6800
title: 6ca5cab7
seconds: 60
exit: 0x0
frames shown: 1499 (PresentX 1499)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13951 MB
xcl-smoke v1
commit: 6a0bb5b4f294b0729771ed457af1f96c01f5c06b
gpu: AMD Radeon RX 6800
title: 6ca5cab7
seconds: 60
exit: 0x0
frames shown: 1540 (PresentX 1540)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14734 MB
xcl-smoke v1
commit: 281d8f0c73b9024a00609b5974e44accfa17c659
gpu: AMD Radeon RX 6800
title: 6ca5cab7
seconds: 60
exit: 0x0
frames shown: 1520 (PresentX 1520)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14742 MB

AI use

  • Antigravity (Gemini 4 Neon): audited amd-dev compact.rs liveness, implemented the fix and unit test, ran the tests and paired scripts/smoke.ps1 runs, and drafted this PR description.
**@⁠AlpPesen** on GitHub · 2026-11-26 01:27 UTC · [original](https://github.com/xcl-dev/xcl/pull/2604) `AlpPesen:amd-dev/fix-compact-sgpr-liveness` → `amd-dev` · +66 −9 · 1 files · 1 commits · open Fixes two SGPR liveness bugs in `amd-dev`'s compact DXIL micro-block emitter (`crates/xcl/src/gpu/dxil/compact.rs`): 1. **Conditional-write and RMW SALU ops dropped from `use` / killed in `def`:** `inst_sreg_scc_use_def` only treated `S_CMOVK_I32` as a conditional write. In `rdna2_spec.rs`, `S_CMOV_B32`, `S_CMOV_B64`, `S_ADDK_I32`, `S_MULK_I32`, `S_BITSET0_B32/B64`, and `S_BITSET1_B32/B64` declare `SDST` with `input: false, output: true`, so predecessor micro-blocks could elide storing `SDST` to its alloca slot and feed stale/zero data into the successor. 2. **Wave32 64-bit VALU mask writers over-killed `s[v + 1]`:** VALU mask writers (`V_CMP_*`, `V_ADD_CO_*`, etc.) declare `size: 64` in `rdna2_spec.rs`, but in Wave32 (`!wave64`) they only write the low SGPR and leave `s[v + 1]` intact. **What is in it** - Thread `lw.wave64` into `compute_live_out` and `inst_sreg_scc_use_def` in `crates/xcl/src/gpu/dxil/compact.rs`. - Treat all `S_CMOV*` as conditional writes (add `SDST` to `u`, omit from `def`) and `S_ADDK_I32` / `S_MULK_I32` / `S_BITSET{0,1}_B{32,64}` as read-modify-write (add `SDST` to both `u` and `def`). - Clamp `def` width to 1 SGPR for non-`S_*` 64-bit mask outputs when `!wave64`. - Add unit test `cmov_and_rmw_salu_read_sdst_and_wave32_valu_keeps_hi_sgpr` in `compact::liveness_tests`. **Tested** - Hardware: Intel Core i9-9900K, 32 GB RAM, AMD Radeon RX 6800 (16337 MiB VRAM, RDNA2, driver 32.0.21045.29003), Windows 11 Pro build 26300, `rustc 1.100.0`, DXC `1.9.2602.17`. - `cargo test -p xcl --lib gpu::dxil::compact`: 12 passed, 0 failed, 0 ignored, 0 skipped. **Not tested** - NVIDIA or Intel GPUs, wave32-only hardware, or Linux/Wine. **Regression run** ``` xcl-smoke v1 commit: e1d84b7d9153f86a97d2ec5d209d196046fc0bea gpu: AMD Radeon RX 6800 title: 6ca5cab7 seconds: 60 exit: 0x0 frames shown: 1499 (PresentX 1499) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 13951 MB ``` ``` xcl-smoke v1 commit: 6a0bb5b4f294b0729771ed457af1f96c01f5c06b gpu: AMD Radeon RX 6800 title: 6ca5cab7 seconds: 60 exit: 0x0 frames shown: 1540 (PresentX 1540) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14734 MB ``` ``` xcl-smoke v1 commit: 281d8f0c73b9024a00609b5974e44accfa17c659 gpu: AMD Radeon RX 6800 title: 6ca5cab7 seconds: 60 exit: 0x0 frames shown: 1520 (PresentX 1520) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14742 MB ``` **AI use** - Antigravity (Gemini 4 Neon): audited `amd-dev` `compact.rs` liveness, implemented the fix and unit test, ran the tests and paired `scripts/smoke.ps1` runs, and drafted this PR description.
inst_sreg_scc_use_def now treats all S_CMOV* as conditional writes and
S_ADDK_I32/S_MULK_I32/S_BITSET* as read-modify-write on SDST, and clamps
Wave32 VALU 64-bit mask defs to 1 SGPR so live s[v+1] slots are not killed.

Assisted-by: Antigravity (Gemini 4 Neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:34:44 +00:00
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-26 01:56 UTC · original

Verification on RTX 3060 Ti (Windows 11), head merged with current main:

  • cargo test -p xcl --lib: the parallel run aborts (0xc0000409) and the --test-threads=1 rerun finishes with 10 real failures (1528 passed / 10 failed / 27 ignored):
gpu::dxil::kernel::dispatch_chain_native_wave64_builds_whole
gpu::recomp::lower_dxil::tests::a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier
gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu            (f32 rounding wave32: 0x3f800000 vs 0x3f7fffff)
hle::d3d12x::bind::tests::two_pass_binds_set_the_shared_view_heap
hle::d3d12x::list_x::tests::a_dispatch_with_a_pipeline_still_building_waits_at_the_submit
hle::d3d12x::list_x::tests::a_put_off_dispatch_runs_at_the_submit_when_its_build_outlasts_the_wait_budget
hle::d3d12x::list_x::tests::bitset_runs_emit_exact_contiguous_page_ranges   ((0,130) vs (0,128))
hle::d3d12x::real::big_compile_tests::giant_driver_compiles_have_their_own_lane
hle::d3d12x::title_textures::tests::title_bytes_are_used_in_place_when_all_are_readable
hle::kernelx::tests::physical_home_without_sparse_windows_uses_coherent_window

Note the branch carries ~19 commits on top of main (stacked work incl. the frame-wait-window, sparse lazy-commit and texture-cache changes), so the failures may belong to an earlier layer rather than the compact-SGPR fix itself — but the merged head does not pass as it stands.

— Devin

**@⁠DavidM1911** on GitHub · 2026-11-26 01:56 UTC · [original](https://github.com/xcl-dev/xcl/pull/2604#issuecomment-7180297602) Verification on RTX 3060 Ti (Windows 11), head merged with current `main`: - `cargo test -p xcl --lib`: the parallel run aborts (0xc0000409) and the `--test-threads=1` rerun finishes with **10 real failures** (1528 passed / 10 failed / 27 ignored): ``` gpu::dxil::kernel::dispatch_chain_native_wave64_builds_whole gpu::recomp::lower_dxil::tests::a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu (f32 rounding wave32: 0x3f800000 vs 0x3f7fffff) hle::d3d12x::bind::tests::two_pass_binds_set_the_shared_view_heap hle::d3d12x::list_x::tests::a_dispatch_with_a_pipeline_still_building_waits_at_the_submit hle::d3d12x::list_x::tests::a_put_off_dispatch_runs_at_the_submit_when_its_build_outlasts_the_wait_budget hle::d3d12x::list_x::tests::bitset_runs_emit_exact_contiguous_page_ranges ((0,130) vs (0,128)) hle::d3d12x::real::big_compile_tests::giant_driver_compiles_have_their_own_lane hle::d3d12x::title_textures::tests::title_bytes_are_used_in_place_when_all_are_readable hle::kernelx::tests::physical_home_without_sparse_windows_uses_coherent_window ``` Note the branch carries ~19 commits on top of `main` (stacked work incl. the frame-wait-window, sparse lazy-commit and texture-cache changes), so the failures may belong to an earlier layer rather than the compact-SGPR fix itself — but the merged head does not pass as it stands. — Devin
Author
Owner

@⁠DarkPanda69 on GitHub · 2026-11-26 02:00 UTC · original

NVIDIA wave32-only run (listed as untested), plus an RX 9070 XT: the new test passes on both, and nothing else changes against amd-dev in the direct-DXIL GPU suite.

Head 281d8f0 applied on amd-dev b5c0275, debug, Windows 11 Pro 26200, XCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- gpu:: --test-threads=4 on amd-dev and with the PR, card chosen with XCL_ADAPTER:

amd-dev this PR
RTX 3060 (Ampere, 32-lane waves only, 32.0.16.1088) 748 passed, 4 failed, 20 SKIPPED 749 passed, 4 failed, 20 SKIPPED
RX 9070 XT (RDNA4, 32.0.32029.2010) 746 passed, 6 failed, 4 SKIPPED 747 passed, 6 failed, 4 SKIPPED

On both cards, the only result change is the new cmov_and_rmw_salu_read_sdst_and_wave32_valu_keeps_hi_sgpr (ok), with no new skips. All the failures are the same on amd-dev without this PR:

  • both cards: dispatch_chain_native_wave64_builds_whole, a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier, f32_programs_on_the_gpu;
  • RTX 3060 only: gpu_fract_f32_edges;
  • RX 9070 XT only: fuzz_validate_and_gpu_1 (#2115), gpu_f32_compares_with_nan, gpu_float_compares_random.

Not tested: Intel, Linux / Wine, a title.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

**@⁠DarkPanda69** on GitHub · 2026-11-26 02:00 UTC · [original](https://github.com/xcl-dev/xcl/pull/2604#issuecomment-7180371960) NVIDIA wave32-only run (listed as untested), plus an RX 9070 XT: the new test passes on both, and nothing else changes against `amd-dev` in the direct-DXIL GPU suite. Head `281d8f0` applied on `amd-dev` `b5c0275`, debug, Windows 11 Pro 26200, `XCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- gpu:: --test-threads=4` on `amd-dev` and with the PR, card chosen with `XCL_ADAPTER`: | | `amd-dev` | this PR | |---|---|---| | RTX 3060 (Ampere, 32-lane waves only, 32.0.16.1088) | 748 passed, 4 failed, 20 SKIPPED | 749 passed, 4 failed, 20 SKIPPED | | RX 9070 XT (RDNA4, 32.0.32029.2010) | 746 passed, 6 failed, 4 SKIPPED | 747 passed, 6 failed, 4 SKIPPED | On both cards, the only result change is the new `cmov_and_rmw_salu_read_sdst_and_wave32_valu_keeps_hi_sgpr` (ok), with no new skips. All the failures are the same on `amd-dev` without this PR: - both cards: `dispatch_chain_native_wave64_builds_whole`, `a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier`, `f32_programs_on_the_gpu`; - RTX 3060 only: `gpu_fract_f32_edges`; - RX 9070 XT only: `fuzz_validate_and_gpu_1` (#2115), `gpu_f32_compares_with_nan`, `gpu_float_compares_random`. Not tested: Intel, Linux / Wine, a title. AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2604/head:github-bot/gh-2604'
git switch 'github-bot/gh-2604'

Merge

Merge the changes and update on Forgejo.
git switch 'amd-dev'
git merge --no-ff 'github-bot/gh-2604'
git switch 'github-bot/gh-2604'
git rebase 'amd-dev'
git switch 'amd-dev'
git merge --ff-only 'github-bot/gh-2604'
git switch 'github-bot/gh-2604'
git rebase 'amd-dev'
git switch 'amd-dev'
git merge --no-ff 'github-bot/gh-2604'
git switch 'amd-dev'
git merge --squash 'github-bot/gh-2604'
git switch 'amd-dev'
git merge --ff-only 'github-bot/gh-2604'
git switch 'amd-dev'
git merge 'github-bot/gh-2604'
git push origin 'amd-dev'
This discussion has been locked. Commenting is limited to contributors.
No description provided.