Skip to content

Recompiler: propagate half-local masks through 64-bit bitwise ops and EXEC - #1875

Closed
certified-retart wants to merge 1 commit into
xcl-dev:mainfrom
certified-retart:recomp/x64-masks-bitwise-exec
Closed

certified-retart wants to merge 1 commit into
xcl-dev:mainfrom
certified-retart:recomp/x64-masks-bitwise-exec

Conversation

@certified-retart

Copy link
Copy Markdown
Contributor

Part of #1269, #1598, and #675.

In split-wave64 mode (NVIDIA / 32-lane wave GPUs), x64_masks::whole_live_out previously treated every scalar read of a 64-bit mask register—and every read or write of EXEC—as requiring the whole 64-bit mask across both 32-lane halves. As a result, any v_cmp_* / v_cmpx_* feeding a 64-bit bitwise mask chain (s_and_b64, s_or_b64, s_xor_b64, s_andn2_b64, s_not_b64, s_mov_b64, s_cselect_b64, s_*_saveexec_b64, s_*_wrexec_b64, etc.) or feeding EXEC for branchless predication emitted a full cross-half xcl_x_ballot (LDS write + two GroupMemoryBarrierWithGroupSync barriers + LDS read) even when neither the resulting mask nor its SCC was ever observed across halves.

Summary of changes

  • crates/xcl/src/gpu/recomp/x64_masks.rs:
    • Track internal SCC whole-liveness (bit 125, stripped before returning from whole_live_out) and propagate half-local liveness backward through bit-parallel 64-bit SALU ops (S_MOV_B64, S_CMOV_B64, S_NOT_B64, S_WQM_B64, S_CSELECT_B64, S_{AND,OR,XOR,ANDN2,ORN2,NAND,NOR,XNOR}_B64, S_*_SAVEEXEC_B64, and S_*_WREXEC_B64) on even-aligned 64-bit pairs.
    • Because each half holds its own 32 bits in its lane-matched half register (s_{2k} in half 0, s_{2k+1} in half 1), bit-parallel ops preserve half-exactness when neither the destination pair nor a live SCC is observed whole; whenever either is whole-live (or when src_vccz/src_execz/SCC is read), all inputs are forced whole.
    • Replace unconditional EXEC whole-liveness with demand-driven EXEC liveness: EXEC is marked whole-live at cross-half observations (S_CBRANCH_EXECZ/NZ, src_execz, V_READFIRSTLANE_B32, DS_BPERMUTE_B32, DS_PERMUTE_B32, S_MOVREL*, non-bit-parallel scalar reads of EXEC, indirect jumps, and end_reads_all), while in-half reads (act(), DPP, V_PERMLANE(X)16, DS_SWIZZLE) remain half-local.
    • Preserve pub fn uses(d: &Decoded) unchanged for lane_masks and recomp::lower.
    • Expand gpu::recomp::x64_masks::tests to 19 unit tests covering bit-parallel propagation, SCC soundness, SAVEEXEC/WREXEC patterns, EXEC cross-half reads (S_CBRANCH_EXECZ, V_READFIRSTLANE_B32, DS_BPERMUTE_B32), and loop/back-edge propagation.
  • crates/xcl/src/gpu/recomp/emit.rs & crates/xcl/src/gpu/dxil/lower.rs:
    • Allow write_mask to use the half-local ballot when writing EXEC (n <= 126 && n % 2 == 0 instead of n < 126) whenever EXEC is not whole-live after the write.
  • crates/xcl/src/gpu/dxil/kernel.rs:
    • Bump TRANSLATOR_VERSION from 7 to 8.
  • crates/xcl/src/gpu/recomp/tests.rs:
    • Add gpu_split_wave64_bit_parallel_and_exec_masks verifying both HLSL and Direct DXIL execution on GPU: bit-parallel mask chains, branchless s_and_saveexec_b64 / s_andn2_b64 if/else, restored outer EXEC, half-local v_cmpx, and cross-half soundness with upper-half-only active lanes (45..63) for SCC, v_readfirstlane_b32, s_cbranch_execz, and ds_bpermute_b32.

Measured impact (split-wave64 compute shaders)

Across 200 retail compute shaders (>= 64 KB HLSL) exported with --split 1:

  • 134 wave64 compute shaders with ballots; 62 improved, 0 regressed.
  • Aggregate cross-half xcl_x_ballot calls: 10,286 → 6,734 (-3,552 exchanges, -34.5%, removing 7,104 group memory barriers).
  • Aggregate half-local xcl_x_ballot_local calls: 7,725 → 11,277.

Sample large wave64 compute shaders compiled with DXC (-E main -T cs_6_6 -HV 2021 -O1, dxcompiler 1.9.2602.17):

Compute shader HLSL size xcl_x_ballot (main → PR) DXIL bytes (main → PR) DXC time (main → PR)
Shader A 1.9 MB 422 → 252 (-40.3%) 529,708 → 463,652 (-12.5%) 3,932 ms → 3,281 ms (-16.6%)
Shader B 3.8 MB 354 → 258 (-27.1%) 1,128,896 → 1,089,396 (-3.5%) 11,679 ms → 10,903 ms (-6.6%)
Shader C 4.2 MB 398 → 290 (-27.1%) 1,216,592 → 1,172,664 (-3.6%) 13,660 ms → 13,231 ms (-3.1%)

Direct DXIL sweep with XCL_FORCE_SPLIT_WAVE64=1 (--direct --sample 1000 --max-bytes 65536 --validate): 977 / 977 (100.0%) translated and validated by dxil.dll 1.9.2602.17 with 0 validator errors, 0 panics, and 0 timeouts.

Regression run

Baseline (origin/main):

xcl-smoke v1
commit: 689f2db477c3c062cf162649781640ef8a977c18
gpu: NVIDIA GeForce RTX 5070
title: 6ca5cab7
seconds: 60
exit: 0x0
frames shown: 1676 (PresentX 1676)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15119 MB

PR (recomp/x64-masks-bitwise-exec):

xcl-smoke v1
commit: b478b4ebe585f9f090855261b13ea5e089272425
gpu: NVIDIA GeForce RTX 5070
title: 6ca5cab7
seconds: 60
exit: 0x0
frames shown: 1683 (PresentX 1683)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15047 MB

Tested

  • Windows 11 x64, NVIDIA GeForce RTX 5070 12 GB (32-lane waves), DXC / dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100.0), Rust MSVC toolchain.
  • cargo test --workspace -- --test-threads=4 — full suite passed (0 failed), including all 19 gpu::recomp::x64_masks::tests unit tests and the new GPU test gpu_split_wave64_bit_parallel_and_exec_masks.
  • XCL_DIRECT_DXIL=1 cargo test -p xcl --lib "gpu::dxil::" and gpu_split_wave64 — 100/100 Direct DXIL tests (including fuzz suites) and 6/6 split-wave64 GPU tests passed.
  • Direct DXIL corpus validation (XCL_FORCE_SPLIT_WAVE64=1, 1,000 sampled records, <= 64 KB): 977/977 validated with 0 errors.
  • Matched 60 s retail smoke run (scripts/smoke.ps1) on origin/main (689f2db) vs PR head (b478b4e).

Not tested

  • Native wave64 hardware (AMD RDNA2+ GPU — split-wave64 is inactive on native wave64 devices).
  • Cache-disabled NVIDIA CreateComputePipelineState timing via --measure-pso (Windows Developer Mode is disabled on this machine).

AI use

  • Implemented, tested, and drafted with Antigravity (Gemini 4 Neon). All changes, soundness invariants, and test results were verified locally before opening this PR.

@certified-retart

Copy link
Copy Markdown
Contributor Author

Closing in favor of #1596 and #1597, which already cover split-wave64 EXEC and bitwise mask propagation (I missed them in the open PR list before opening this). Note: if #1596 wants Direct DXIL parity as well, \crates/xcl/src/gpu/dxil/lower.rs\ has the same
< 126\ check in \write_mask\ as \emit.rs.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

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.

2 participants