Skip to content

Recompiler: pass and track explicit SRC_SCC in per-lane lowering - #2833

Draft
safesearch77 wants to merge 1 commit into
xcl-dev:mainfrom
safesearch77:fix/recomp-explicit-src-scc
Draft

safesearch77 wants to merge 1 commit into
xcl-dev:mainfrom
safesearch77:fix/recomp-explicit-src-scc

Conversation

@safesearch77

Copy link
Copy Markdown

Pass and track explicit SRC_SCC (253) scalar operands consistently across the per-lane and split-wave64 (WaveSize(32)) Direct DXIL recompiler (crates/xcl/src/gpu/recomp/{lane_masks.rs,lower.rs}).

Previously, per-lane lowering had three interlocking gaps whenever an RDNA2 instruction read SCC via scalar source code 253 (src_scc) rather than an implicit OPR_SSRC_SPECIAL_SCC operand:

  1. Lower::bridge (crates/xcl/src/gpu/recomp/lower.rs:1753) checked operand(true, "OPR_SSRC_SPECIAL_SCC"), omitting (Var::Scc, zext(s)) from Ir::foreign inputs and skipping self.read_scc(b) whenever a bridged instruction (V_CVT_F32_U32 v, src_scc, S_BFE_U32, V_ADD_CO_CI_U32, SDWA src_scc, etc.) encoded 253 explicitly. In compute, split-wave64, and graphics modes (ComputeInit / setup_gfx pre-seeding VAR_SCC = 0), DxilIr::foreign succeeded while Lw silently read 0 (or a stale block-local VAR_SCC written by an earlier bridged instruction) instead of the live Var::Scc; in kernel mode it failed with "it reads register 125 the per-lane form did not pass" unless masked by an earlier bridged instruction in the same block; and partial-block SCC writes read after reconvergence bypassed the stale check.
  2. lane_masks::reads_scc (lane_masks.rs:282) and lower::compute_scc_liveness (lower.rs:1188) only scanned primary encoding fields ["SSRC0", "SSRC1", "SRC0", "SRC1", "SRC2", "SOFFSET"]. For Variant::Sdwa (SRC0 = 0xF9), scalar src_scc is encoded in the SDWA extension dword (S0 == 1 && VSRC0 == 253 or S1 == 1 && VSRC1 == 253), so lane_masks missed divergent mask-op SCC reads in !wave_branches and compute_scc_liveness marked scc_live_after = false in wave_branches (including split-wave64 compute), causing mask_nonzero_scc to skip the whole-wave ballot and hardcode SCC = false. Scanning raw primary fields without checking d.ienc.operands also caused false positives on unused fields (e.g. SRC2 = 253 on a 1-source ENC_VOP3 instruction or OPR_ATTR on V_INTERP_*).
  3. Lower::src64 (lower.rs:785) and Lower::src_bit (lower.rs:475) rejected code 253 ("64-bit source code 253" / "mask source code 253") instead of zero-extending SCC ((zext(scc), 0) in src64 and (lane == 0) & scc in src_bit, matching dxil/lower.rs:732 and recomp/emit.rs:840).

Part of #1269

What is in it

  • crates/xcl/src/gpu/recomp/lane_masks.rs: make reads_scc pub(super), inspect SDWA S0/VSRC0 and S1/VSRC1 scalar sources via emit::ext_encoding, and restrict primary-word 253 checks to active non-implicit input operands (excluding non-plain SRC0, relative-source S_MOVRELS_* / S_MOVRELSD_2_B32 SSRC0, and OPR_ATTR / OPR_PARAM) (+24 / -5).
  • crates/xcl/src/gpu/recomp/lower.rs: use lane_masks::reads_scc in both Lower::bridge and compute_scc_liveness, and handle source code 253 in Lower::src_bit and Lower::src64 (+13 / -6).
  • crates/xcl/src/gpu/recomp/lane_masks.rs (tests::sdwa_and_vop3_src_scc_reads_are_classified_accurately): verifies non-uniform mask-op SCC rejection for SDWA S0 and S1 src_scc, acceptance when S0/S1 are 0 (v253) or after S_AND_SAVEEXEC_B64, and no false positive on unused ENC_VOP3 SRC2 = 253 (+48).
  • crates/xcl/src/gpu/recomp/lower.rs (tests::explicit_src_scc_in_salu_valu_bridge_and_wave_liveness): CPU execution and Ir::foreign verification across 64-bit SALU & per-lane mask ops (S_MOV_B64, S_CSELECT_B64, V_CNDMASK_B32, S_AND_B64), bridged explicit SRC_SCC (V_CVT_F32_U32, S_BFE_U32), partial-block stale SCC refusal across reconvergence, and split-wave64 compute_scc_liveness whole-wave ballot preservation before SDWA src_scc (+161).

Tested

  • Linux x86_64 host, Rust stable (repo toolchain), cross-checked for x86_64-pc-windows-gnu: cargo check --offline --workspace --tests gave 0 errors and 0 new warnings (only the 3 pre-existing baseline warnings on 8b957bec, none in gpu/).
  • Linux x86_64 host native rustc --edition=2021 --test harness compiling gpu::{rdna2_spec, rdna2_xbox, rdna2} and gpu::recomp::{x64_masks, ssa, upper_lanes, lane_masks, lower} (with Windows D3D12/DXC runner plumbing stubbed; no lowering or analysis code modified):
    • On unmodified 8b957bec: all 4 red_green_scc_tests fail (0 passed; 4 failed: "unsupported V_CVT_F32_U32 (it reads register 125 the per-lane form did not pass)", missing lane_masks refusal on SDWA S0=1, VSRC0=253, ballots == 0 on split-wave64 S_AND_SAVEEXEC_B64 before SDWA src_scc, and "64-bit source code 253").
    • With f5a352c3: 107 passed; 0 failed; 1 ignored across all rdna2, x64_masks, ssa, upper_lanes, lane_masks, lower, and red_green_scc_tests unit tests.

Regression run

  • None yet. The paired Windows xcl-smoke blocks (8b957bec and f5a352c3) must be attached from a Windows GPU retail run before marking ready for review.

Not tested

  • Windows cargo test --workspace -- --test-threads=4 GPU execution suite (including D3D12 wave32 / split-wave64 / native wave64 dispatch and DXC dxcompiler.dll validation) and paired Windows scripts/smoke.ps1 retail runs. Prepared on a Linux CPU host without a Windows GPU or retail title.

AI use

  • Antigravity with Gemini 4 Carbon High (verified by Gemini 4 Hydrogen XHigh): identified the Lower::bridge, reads_scc / compute_scc_liveness, and src64 / src_bit SRC_SCC (253) defects, implemented the fix and unit tests, ran the Linux rustc --test RED-to-GREEN harness and x86_64-pc-windows-gnu workspace checks, and drafted this PR description.

Fix three gaps in per-lane (and split-wave64) explicit SRC_SCC (253) handling:
- Lower::bridge checked only implicit OPR_SSRC_SPECIAL_SCC operands, omitting Var::Scc from Ir::foreign inputs and skipping read_scc stale tracking when a bridged instruction encoded SRC_SCC (253) explicitly.
- lane_masks::reads_scc and compute_scc_liveness missed SDWA scalar SRC_SCC sources (S0=1/VSRC0=253, S1=1/VSRC1=253) and scanned unused primary encoding fields instead of active non-implicit input operands.
- Lower::src64 and Lower::src_bit rejected code 253 instead of zero-extending SCC ((zext(scc), 0) and (lane == 0) & scc).
@Smokeyqdqd

Copy link
Copy Markdown

Independent parent/head comparison on Windows 11 build 26200, Ryzen 7 5800X, RTX 3060 12 GB (NVIDIA 610.88), rustc 1.100.0 MSVC, DXC 1.9.2602.17, debug.

With XCL_ADAPTER=3060 and XCL_DIRECT_DXIL=1, I ran cargo test --offline --locked -p xcl --lib -- src_scc gpu_split_wave64_ gpu_scalar_loop_and_scc --test-threads=1 --nocapture on each revision.

  • Parent 8b957bec6f82495aec940944c6bf47faa02db590, with only the two new test hunks added: 8 passed, 2 failed, 0 ignored. The failures were sdwa_and_vop3_src_scc_reads_are_classified_accurately and explicit_src_scc_in_salu_valu_bridge_and_wave_liveness.
  • Clean PR head f5a352c3455bbc2bc0b1951f6e01636ddb311f0a: 10 passed, 0 failed, 0 ignored.

Neither run printed SKIPPED. Both new compiler tests distinguish the revisions. The scalar-loop GPU test and the six split-wave64 GPU regression tests passed on both. Scope was this filtered suite only.

AI use: Codex (GPT-6.2 Astra) ran the tests, checked the logs and drafted the report.

@SzczepanGrela

Copy link
Copy Markdown

RX 9070 / Wine per-lane SCC check at f5a352c3455bbc2bc0b1951f6e01636ddb311f0a against main 8b957bec6f82495aec940944c6bf47faa02db590. Head executes 30 per-lane combinations refused by main in this fixture. Six combinations remain translation refusals. All executed matrix outputs matched the independent expected values.

Tested

RX 9070 16 GB, RADV GFX1201 / Mesa 26.3.1-arch3.5 (mesa and vulkan-radeon packages 3:26.3.1-5), Ryzen 7 7700, CachyOS 7.3.0-5-cachyos, GE-Proton11-12 Wine 11.0 Staging with ntsync. Native d3d12/d3d12core/dxgi; vkd3d-proton 8293130ebe370b1+, local assertions-disabled build; DXC/DXIL 1.9.2602.17, Rust 1.97.1, release x86_64-pc-windows-gnu.

Exact pinned source copies, with both new CPU test functions copied unchanged to main and an identical local cfg(test) GPU fixture appended to lower_dxil.rs in both copies. All original source hashes reconstruct after removing the additions. No original assertion was changed. These were instrumented source copies, not clean Git checkouts.

cargo test --offline --locked --release --target x86_64-pc-windows-gnu -p xcl --lib --no-run
wine <libtest.exe> gpu::recomp::lane_masks::tests:: gpu::recomp::lower::tests::explicit_src_scc_in_salu_valu_bridge_and_wave_liveness --nocapture --test-threads=N
wine <libtest.exe> gpu::recomp::lower_dxil::workflow_scc_matrix::kernel_scc_paths --exact --nocapture --test-threads=1
wine <libtest.exe> gpu::recomp::lower_dxil::workflow_scc_matrix::compute_scc_paths --exact --nocapture --test-threads=1

XCL_NETWORK=0, XCL_ADAPTER="AMD Radeon RX 9070", XCL_REQUIRE_GPU=wave64, XCL_DXC_THREADS=1, XCL_DIRECT_DXIL=1, XCL_PER_LANE=1, XCL_DIRECT_COMPACT=0, native DLL overrides and private enabled caches per process. The local fixture explicitly calls lower_dxil::kernel, kernel_split and compute_with; it records refusals without automatic fallback. Each accepted shader was validated with DXC validator 1.9 before GPU submission.

  • Original CPU selection at N=1 and N=4: head 15 passed / 0 failed / 0 ignored, main 13/2/0 per invocation. Both new tests fail on main.
  • Four existing GPU controls at both thread counts, on both revisions: 4/0/0 per invocation. Filters under gpu::recomp::lower_dxil::tests::: a_per_lane_compute_program_runs_on_the_gpu, split_wave64_dead_scc_skips_exchange_barrier, a_bridged_v_cmpx_keeps_the_lanes_outside_exec_out, the_runtime_path_takes_the_split_form.

The local fixture checks native Wave32, native Wave64 and split Wave64 using two hardware Wave32s. Kernel inputs cover zero-extended SCC in scalar/mask sources, true/false/true V_CVT_F32_U32 refresh, and SDWA S0/S1 SCC reads. Compute inputs additionally select the upper half with S_AND_SAVEEXEC_B64, restore EXEC, then consume SCC via SDWA. Empty-mask and overwritten-SCC controls check zero. In the native64/split64 upper-half cases, all 64 stored values equal lane + 1; empty/overwritten controls equal lane. Guard words remain intact.

Three fresh processes per entry/revision, alternating revision order, gave identical per-case outcomes:

Per process main per-lane executed / refused head per-lane executed / refused HLSL and instruction-DXIL controls, either revision
Kernel 0 / 12 11 / 1 24 executed, 0 refused
Compute 0 / 24 19 / 5 48 executed, 0 refused

Main reports 64-bit source code 253 in the native scalar/mask kernel cases; the bridged cases report it reads register 125 the per-lane form did not pass. On head, the native32 combined scalar/mask program still refuses S_AND_B64 with s126: a mask read as a number. Five native32 compute sequences still refuse S_AND_SAVEEXEC_B64 with writes EXEC, the same message as main. These sequences retain the B64 encoding in the native32 arm.

The local collection tests assert on any refusal, so each reports 0 passed / 1 failed / 0 ignored on both revisions, despite the increased coverage on head. Refused cases were never submitted to the GPU. Across 20 final harness invocations there were 0 ignored and 0 capability skips. The matrix evaluated 648 records and performed 522 validated GPU dispatches. Independently recomputed 16,608 kernel lane values, 336 scalar values and 71,760 compute words, including guards: zero mismatches. All 72 HLSL/instruction control shader containers matched byte-for-byte between revisions; each emitted case repeated byte-identically across its three runs.

Not tested

Graphics entry points, every explicit SCC consumer/encoding, partial-launch EXEC, more than one compute group or logical wave per group in the local matrix, end-to-end fallback, full workspace suite, native Windows, other adapters, retail data, scripts/smoke.ps1, FPS or compilation-time effects. No console-hardware oracle was used.

AI use

OpenAI Codex (GPT-6; exact serving variant not exposed) audited the diff, wrote local test-only fixtures, ran the paired tests, independently verified raw outputs/source/executable hashes, and drafted this report. Publication authorized by the account owner.

rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
…RC_SCC tracking, wave32 VALU read64-skip)

xcl-dev#2833 (f5a52c3): lane_masks::reads_scc goes pub(super) with SDWA S0/S1
refinement (VSRC 253 only when the S-bit selects the scalar source;
v253 VGPR reads excluded), movrels/VOP3-unused-SRC2 exclusions, and
implicit-field filtering; lower.rs src_bit/src64 gain the 253 arm
(zext(scc) & lane==0), compute_scc_liveness and bridged-SCC input both
delegate to lane_masks::reads_scc. Tests:
sdwa_and_vop3_src_scc_reads_are_classified_accurately +
explicit_src_scc_in_salu_valu_bridge_and_wave_liveness, verbatim.

xcl-dev#2834 (653f8f1): Direct DXIL wave32 VALU lane-mask sources skip the
64-bit read (read + 0 instead of read64) for OPR_SREG/OPR_VCC 64-bit
operands; 279-line wave32_mask_src_tests module added with one twin
delta: #[cfg(all(test, windows))] instead of #[cfg(test)], because
validate/runner are Windows-only in this tree until the Phase-D
SPIR-V backend lands (same bucket as the other dxil translation test
modules in dxil/mod.rs).

xcl-dev#2832 (e2ecdfa) triaged SKIP: single-file d3d12x/pso_async.rs
need_by_submit wanted-cap change, Windows-only, zero Linux twin.

Gates: both checks 0 errors; lib 780/0/1 threads=4 (+2, zero
regressions); title e2e 4 passed/1 failed by design, 12 unique FAILs
all D3D12.X, 0 non-GPU; retail HOLDS (exit 139 SIGSEGV exe+0x2237320,
stubs 20, xgr exactly XAsync/XNetworking/XUser). Lock audit: 0 new
lock().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants