Skip to content

Recompiler: pre-emission RDNA2 optimizer, dominator SMEM hoisting, and lane-local mask scalarization - #1630

Open
auswhalen999-debug wants to merge 2 commits into
xcl-dev:mainfrom
auswhalen999-debug:shader-opt-1269
Open

auswhalen999-debug wants to merge 2 commits into
xcl-dev:mainfrom
auswhalen999-debug:shader-opt-1269

Conversation

@auswhalen999-debug

@auswhalen999-debug auswhalen999-debug commented Nov 24, 2026 •

Copy link
Copy Markdown

Add a pre-emission RDNA2 CFG/liveness optimizer (opt.rs) and matching HLSL lowering improvements (emit.rs, mod.rs) that reduce basic-block explosion, redundant scalar memory loads, convergent wave ballots, and branchy HLSL 2021 helpers across large retail compute shaders. Part of #1269.

Measured across 12 stratified retail compute shaders (150 KB – 1.15 MB DXIL, 131,048 RDNA2 instructions) on an NVIDIA GeForce GTX 1070 with cold driver-cache salt (109.0x cold/warm verified): -31.2% cold driver CreateComputePipelineState time (281.84 s -> 194.01 s, 12/12 faster, up to -40.7%), -18.7% DXC compile time (177.52 s -> 144.39 s), -26.1% end-to-end compile time (460.12 s -> 339.87 s, 12/12 faster), and -13.6% DXIL size (8,400.1 KB -> 7,256.3 KB).

This PR is kept together as one cohesive optimizer pass because the dominator/reaching-def/liveness/hazard analysis in opt.rs directly drives the emitter lowering in emit.rs and early-exit CFG in mod.rs; splitting them would leave dead unexercised analysis code or lose the combined CFG/driver-compile reduction measured below (if review bandwidth prefers a stacked split of opt.rs ahead of emit.rs/mod.rs, happy to split on request).

Relationship to other #1269 PRs

  • Strictly complementary to Shaders: speed up translated pipeline compiles and add PSO measurements #1524 (dynamic-index format helpers): this PR intentionally leaves bits_at, put_bits, bvh_intersect, dst_sel, and xcl_lv untouched (0 lines changed on those helpers) so #1524 and #1630 stack cleanly without conflict or double-work.
  • Zero overlap with #680 (rebased onto 9e3831e and supports both default switch and heap_windows forms), #1356, #1380, #1439, #1345, #1315/#1316, #1043, #1111/#1596/#1597, or #1426 direct-DXIL.

What is in it

  • Pre-emission RDNA2 CFG analysis (crates/xcl/src/gpu/recomp/opt.rs, registered in crates/xcl/build.rs TRANSLATOR_SOURCES):
    • Exact backward liveness (scc, SGPRs, carry sdst, and conservative RMW VGPR liveness under divergent EXEC, preserving Mode::Kernel live-outs) for dead scc, dead carry-out WaveActiveBallot (including Dst::Null and wave64 pairs), and dead pure ALU elimination.
    • Cooper–Harvey–Kennedy dominator tree, CFG-wide SGPR reaching-def/constant propagation, and backwards-BFS memory-hazard reachability (loop-safe) for cross-block s_load_* and s_buffer_load_* CSE/hoisting (HoistedSmemGroup, HoistedSbufGroup), non-consecutive intra-block s_buffer_load_* grouping (IntraBlockSbufGroup), and known_zero_hi Window-0 fast paths (s[sbase+1] == 0 / (s[sbase+1] & 0xFFFF) == 0, with Mode::Kernel 4 GiB wrap guards).
    • Wave32 and native-Wave64 strictly intra-block lane-local bool mask scalarization (v_cmp_* / v_add_co* / v_sub_co* and dead-scc bitwise SALU chains consumed only per-lane by v_cndmask_b32 / carry-in ops, disabled in Mode::Kernel and split_wave64), with explicit convergence & EXEC-widening hazard model documented in opt.rs.
    • Whole-program 4-condition memory-coherence check (mem_coherent: zero GLC/DLC/SLC, zero memory atomics, zero cache inv/wb ops, and !(has_s_barrier && has_mem_store)).
    • Unit tests covering all analyses and soundness guardrails (opt::tests).
  • Recompiler HLSL lowering (crates/xcl/src/gpu/recomp/emit.rs):
    • Consumes ProgramOpt for dead scc / dead carry-out / dead pure-inst elision, hoisted/grouped SMEM & SBUF lowering (zero-loop single-switch in default switch mode, ResourceDescriptorHeap[MEM_HEAP_BASE + xcl_w] in heap_windows mode, direct Window-0 fast path using ResourceDescriptorHeap[0u] under heap_windows or xcl_mem0 under switch mode), and lane-local bool ml_* masks (avoiding convergent WaveActiveBallot).
    • Omits NonUniformResourceIndex on wave-uniform SGPR handles in Compute | Mesh | Geometry (and non-split Kernel), keeping it in Pixel, Vertex, and split Kernel; replaces img_cls FMT_INFO table lookup with constant bitmasks.
    • Conditional globallycoherent on Compute mem..mem3 (and heap_windows XCL_MW) gated on program_opt.mem_coherent; prunes non-ABI scratch SGPR io.Load() calls in Mode::Compute and dead exec_lo/exec_hi entry loads in non-Kernel modes.
    • Replaces HLSL 2021 short-circuit ?:/&&/|| diamonds in ALU/conversion helpers (fma_legacy, f32_to_f16_rm, cvt_norm_*, perm_b32, fclass*, sdwa_*, lanemask_lt_*, s_cmp_*_u64, s_bfm_*, v_ffbh/v_ffbl, etc.) with branch-free select/bitwise equivalents (leaving #1524's bits_at/put_bits/bvh_intersect/dst_sel untouched), and simplifies v_mul_legacy_f32 / float_compare on known constants while preserving -0.0f sign semantics.
    • Unit tests for bit-exact branchless helpers, img_cls, uniform_sgpr_handles, and heap_windows Window-0 descriptor-heap emission (emit::opt_helper_tests).
  • Structured/fallback CFG early-exit lowering (crates/xcl/src/gpu/recomp/mod.rs):
    • Wires opt::analyze into translate() and routes block emission through Em::emit_block_insts.
    • Emits direct return; ({ xcl_s_barrier_exit(); return; } when safe_barrier is active, return xo; for Vertex) on early s_endpgm in Compute | Mesh | Vertex (preserving xcl_skip_end in Kernel | Geometry | Pixel), extends structured_span past Term::End, and emits continue; / break; in emit_range loops.
  • GPU output-parity tests & assertion updates (crates/xcl/src/gpu/recomp/tests.rs):
    • Added gpu_opt_lane_local_mask_exec_restore_and_carry_parity (Wave32 & Wave64 real GPU dispatch verifying s_and_saveexec + v_cmp + s_or + EXEC restore + v_cndmask_b32 + 64-bit v_add_co -> v_add_co_ci carry chain with dead carry-out, bit-exact on every lane) and gpu_opt_hoisted_smem_store_hazard_and_branchless_helpers_parity (real GPU dispatch verifying hoisted/subsumed s_load_*, grouped s_buffer_load_* partial OOB, store-hazard non-hoisting, branchless fma_legacy(0, NaN, 7), and constant mul_legacy(2.0, -0.0) == +0.0).
    • Updated 4 existing HLSL string-count assertions where dead scc, dead final carry-out, and Dst::Null compare ballots are now elided.

Tested

  • Hardware & toolchain: NVIDIA GeForce GTX 1070 (driver 32.0.15.8180, Wave32, no HW mesh shaders), AMD Ryzen 5 3500X 6-Core Processor, Windows 11 (NT 10.0.26300.0), rustc 1.100.0 (0ef1bc386 2026-11-09), DXC 1.9.2609.5, release build.
  • cargo test --workspace --release -- --test-threads=4 (after cargo build --workspace --release, with XCL_DXC_DIR set) at 91ae2c6: 797 passed, 0 failed, 41 ignored (748 lib including both new GPU output-parity tests + 49 integration/e2e/oracle, including gpu_compute_e2e 4 passed, 0 failed and #680 heap_window_tests).
  • SKIPPED GPU tests on GTX 1070:
    • gpu::recomp::tests::gpu_geometry_mode_es_gs_strip: no mesh shaders
    • gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask: no wave64
    • gpu::recomp::tests::gpu_mesh_mode_two_passes: no mesh shaders
    • gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware: no wave64
  • Paired cold-PSO compile benchmark across 12 stratified retail compute shaders (150 KB – 1.15 MB DXIL, split_wave64=true, mem_windows=4, heap_windows=false, retail -O1/-O3 threshold, per-run non-DCE-able io.Load(508u) salt defeating %LOCALAPPDATA%\NVIDIA\DXCache, coldness self-check on #0: cold1=3788.3 ms, warm=35.6 ms, cold2=3882.6 ms, ratio 109.0x; note: compile-time benchmark only, as standalone retail CS expect live title UMA/descriptors — output parity is verified by the workspace GPU suite, gpu_compute_e2e, and the new GPU dispatch tests above):
# Hash (fnv64) Insts DXC base -> PR (ms) DXIL base -> PR (KB) Cold PSO base -> PR (ms) Cold PSO delta
0 0019989e 2,632 3,172 -> 2,724 (-14.1%) 204.0 -> 180.4 (-11.6%) 4,588 -> 3,788 -17.4%
1 00daa26e 4,497 7,273 (-O1) -> 7,511 (-O3)* 312.8 -> 254.9 (-18.5%) 8,454 -> 5,873 -30.5%
2 076191bb 5,187 9,114 -> 7,106 (-22.0%) 362.7 -> 302.0 (-16.7%) 10,365 -> 7,671 -26.0%
3 0526ab24 8,462 8,211 -> 6,355 (-22.6%) 526.1 -> 450.2 (-14.4%) 13,945 -> 10,097 -27.6%
4 0452488a 10,753 21,887 -> 17,103 (-21.9%) 539.6 -> 422.5 (-21.7%) 14,361 -> 9,768 -32.0%
5 1f04a85e 11,044 13,120 -> 10,491 (-20.0%) 618.1 -> 544.9 (-11.8%) 14,101 -> 11,983 -15.0%
6 001714bf 12,152 12,447 -> 9,083 (-27.0%) 784.3 -> 619.6 (-21.0%) 22,519 -> 15,647 -30.5%
7 0155621c 12,931 14,104 -> 11,356 (-19.5%) 858.7 -> 792.8 (-7.7%) 26,700 -> 19,983 -25.2%
8 0291d282 13,488 17,032 -> 11,944 (-29.9%) 909.3 -> 722.5 (-20.5%) 30,415 -> 20,939 -31.2%
9 008bfb7a 16,334 21,388 -> 14,837 (-30.6%) 1,055.0 -> 853.4 (-19.1%) 35,833 -> 24,425 -31.8%
10 008d625c 16,876 20,109 -> 16,293 (-19.0%) 1,092.9 -> 1,038.1 (-5.0%) 50,586 -> 30,020 -40.7%
11 04fd77f7 16,692 29,665 -> 29,588 (-0.3%) 1,136.7 -> 1,075.0 (-5.4%) 49,969 -> 33,812 -32.3%
TOTAL 12 CS 131,048 177,521 -> 144,390 (-18.7%) 8,400.1 -> 7,256.3 (-13.6%) 281,838 -> 194,007 -31.2%

*Note: #1 (00daa26e) shrank HLSL from 1,085.4 KB -> 978.4 KB, crossing dxc.rs's 1 MiB threshold from -O1 to -O3, and still reduced total E2E compile time by -14.8% (15.76 s -> 13.42 s). Across the 12 shaders, NonUniformResourceIndex dropped 2,500 -> 0, xcl_mLoad* calls dropped 8,506 -> 2,829 (-66.7%), entry io.Load dropped 1,248 -> 145 (-88.4%), and globallycoherent dropped 48 -> 16.

Regression run
main:

xcl-smoke v1
commit: 9e3831e1f570d3646e53ab753b19ec07eb8f1485
gpu: NVIDIA GeForce GTX 1070
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1055 (PresentX 1055)
presents per 2 s (last 3): 60 59 60
device removals: 0
crashes: 0
peak commit: 14086 MB

PR:

xcl-smoke v1
commit: 91ae2c62e89f049f241df4fed3d47295f19f2793
gpu: NVIDIA GeForce GTX 1070
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 938 (PresentX 938)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14197 MB

Not tested

  • Retail shader output-buffer comparison on the 12-shader compile benchmark corpus (standalone retail CS require live title UMA state/descriptors).
  • AMD RDNA / Intel GPUs, native hardware Wave64 (gpu_wave32_program_in_wave64_hardware, gpu_geometry_wave32_prefix_count_over_a_mask), and hardware mesh-shader tests (gpu_mesh_mode_two_passes, gpu_geometry_mode_es_gs_strip) on this machine — GTX 1070 is Pascal Wave32 without mesh shaders (independently verified on AMD Radeon native-wave64 + mesh at 17c0233 in comments below).
  • Paired cold-PSO timings under XCL_HEAP_WINDOWS=1 (functional unit/GPU coverage via heap_window_tests, gpu_compute_e2e, and heap_windows_window0_fast_paths_use_descriptor_heap passed).
  • Linux / Wine, XCL_SAMPLE_* tests, and retail gameplay past the 60 s smoke window.

AI use
Antigravity (Google DeepMind Gemini agent) — audited gpu/recomp/ and open PRs for zero overlap, profiled baseline DXIL IR and cold GTX 1070 PSO compile times, implemented opt.rs and the emit.rs/mod.rs/build.rs changes and unit/GPU parity tests, ran the workspace test suite, paired cold-PSO benchmarks, and scripts/smoke.ps1 runs, and drafted the commits and PR description.

@pickles976

Copy link
Copy Markdown

Measurements read as the best-designed perf post in this repo yet — stratified corpus (150 KB–1.15 MB, 131k instructions), cold-cache salt, per-shader distribution not just mean (12/12, up to −40.7%), and cold/warm verified at 109× so the cold number cannot be cache luck. And it lands directly on the thread that measured one helper pattern at 230 s→63 s (#1524): if both hold, the cold-run watchdog arithmetic changes materially — worth a cross-reference in each PR description so the reviewers of one know the other exists. Four review-lane points on a 7,298-line optimizer rather than a rubber stamp: ① correctness artifact, not speed artifact — the single most valuable addition is the boring one: state (or add) whether the 12-shader corpus compares outputs, not just times, before/after the pass, and whether the full gpu_compute_e2e suite ran at this head; for an optimizer whose failure mode is silently wrong pixels, "12/12 faster" and "12/12 bit-identical" are different sentences and the second is the merge prerequisite. ② The convergent-wave-ballot removal is the sharpest edge in the PR: wave intrinsics are convergence operations before they are values, so ballot dedup is only sound under a convergence-aware hazard model — name the model in the pass doc (which CFG shapes may the analysis move a ballot across, and what makes a region convergence-safe) so the next person extending opt.rs inherits the constraint, not just the code. ③ Review bandwidth is the known graveyard here (see the validated-but-unmerged data fix): if review stalls on size, the natural seam is analysis passes (opt.rs) landing before the HLSL lowering changes (emit.rs/mod.rs) if they are behavior-preserving without each other — but the cohesion argument is plausible as written, so this is Plan B, not a request. ④ emit.rs "branchy HLSL 2021 helpers" reduction intersects #1524 commit 1 (dynamic-index helpers) — please rebase against each other before merge so the two helper-lowering rewrites do not half-cancel.

@nnonno91

nnonno91 commented Nov 24, 2026 •

Copy link
Copy Markdown

Independent AMD native-wave64 and mesh coverage at 17c02330d8b5a78c938a1cc52f04874e1fb9087a.

Tested

  • AMD Radeon(TM) Graphics (Ryzen 7 9800X3D integrated GPU, driver 32.0.21042.62), Windows 11 25H2 build 26200.9974, Rust 1.100.0 MSVC, SDK DXC 1.8.2502.11, debug. XCL_ADAPTER='AMD Radeon'.
  • cargo build --workspace --locked and cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --show-output completed. The suite reported 795 passed, 0 failed, 41 ignored. One GPU skip was counted among the passes (heap_window_out_of_memory_falls_back_to_the_switch_form, heap windows off in this run). The bundled title test passed.
  • With XCL_REQUIRE_GPU=wave64,mesh, cargo test --locked -p xcl --lib -- gpu_geometry_mode_es_gs_strip gpu_geometry_wave32_prefix_count_over_a_mask gpu_mesh_mode_two_passes gpu_wave32_program_in_wave64_hardware gpu::recomp::opt::tests gpu::recomp::emit::opt_helper_tests --test-threads=1 --show-output gave 23 passed, 0 failed, 0 ignored, 0 skips. All four GPU tests skipped in the GTX 1070 run executed here.
  • With XCL_HEAP_WINDOWS=1, cargo test --locked -p xcl --test gpu_compute_e2e -- --test-threads=1 --show-output gave 4 passed, 0 failed, 0 ignored, 0 skips. The log confirmed use of the shared descriptor heap and a rebuild in switch form after the test injected an out-of-memory result.
  • For an output check specific to the new lane-local lowering, I ran the same temporary synthetic compute test at the PR head and its base 9e3831e1f570d3646e53ab753b19ec07eb8f1485: cargo test --locked -p xcl --test lane_mask_probe -- --exact native_wave64_mask_survives_exec_restore --nocapture --test-threads=1 (one pass each, no skips). A native wave64 group enabled only lanes 0–39 with s_and_saveexec_b64, compared lane < 48 into VCC, restored EXEC and wrote each lane's v_cndmask_b32 result to memory. The PR emitted a lane-local boolean guarded by the pre-restore EXEC bit. Both builds matched all 64 expected outputs (2 for lanes 0–39 and 1 for lanes 40–63, including the eight restored lanes that would otherwise satisfy the compare).

Not tested

Retail shader output parity, retail title smoke, performance, or other GPUs in this run.

AI use

OpenAI Codex (GPT-6 family, exact variant unavailable) wrote the temporary probe, ran the checks, and drafted this report.

Follow-up at 91ae2c62e89f049f241df4fed3d47295f19f2793

Tested

  • Windows 11 25H2 build 26200.9974, Ryzen 7 9800X3D, AMD Radeon(TM) Graphics (32.0.21042.62) and RTX 5090 (617.42 / 32.0.16.1742), Rust 1.100.0 MSVC, SDK DXC 1.8.2502.11, unoptimized debug/test builds with debug info disabled. Selected each adapter with XCL_ADAPTER and used separate caches.
  • cargo build --workspace --locked passed. cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --show-output reported 797 passed, 0 failed, 41 ignored on each adapter. The bundled title passed on both. Both pass counts include heap_window_out_of_memory_falls_back_to_the_switch_form (heap windows off). NVIDIA also counted two native-wave64 skips (gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware).
  • cargo test --locked -p xcl --lib -- gpu_opt_lane_local_mask_exec_restore_and_carry_parity gpu_opt_hoisted_smem_store_hazard_and_branchless_helpers_parity --test-threads=1 --nocapture with XCL_REQUIRE_GPU=mesh gave 2 passed, 0 failed, 0 ignored, 0 skips on each adapter. The earlier EXEC-restore scenario now runs in the permanent tests. It checked the restored mask and carry output on wave32 and native wave64 on AMD, and wave32 and split wave64 on the RTX 5090.
  • A temporary adaptation of the new memory fixture ran the same shader down both branch paths using the two inputs for s1 at DXC -O0 and -O3. cargo test --locked -p xcl --test hoist_branch_probe -- --exact hoisted_loads_agree_on_both_branch_paths --test-threads=1 --nocapture passed once per adapter, with no skips. All eight dispatches returned the same six expected words, including zero for the out-of-bounds word and 0xDEADBEEF for the read after the store.

Not tested in this follow-up

Retail shader output parity, retail title smoke, performance, or the optional heap-window mode.

AI use

OpenAI Codex (GPT-6 family, exact variant unavailable) adapted the temporary memory probe, ran the checks, and drafted the update.

@vitor127wt

Copy link
Copy Markdown

Independent cold compute PSO timings on Linux / Proton

This is the #1630 data point for campaign #1269 (A14).

Tested

  • PR head 17c02330d8b5a78c938a1cc52f04874e1fb9087a against its main base 9e3831e1f570d3646e53ab753b19ec07eb8f1485, using five shaders matched by container hash from the PR's sample.
  • Ryzen 7 9700X, 32 GB DDR5, RTX 5070 Ti (16 GB), NVIDIA 620.73.04, CachyOS 7.3.5-2-cachyos, Proton Experimental 11.0 (2026-11-12), DXC 1.9.2609.5. Rust 1.100.0, Windows x64 release build with LLVM-MinGW 20261117 (x86_64-pc-windows-gnullvm). vkd3d-proton ec207194 with the Wine kit Linux: docs/linux.md, scripts/linux and Wine start-up checks for vkd3d-proton and DXVK (#154, #241) #257 patch, dxil-spirv 7c048638.
  • The same temporary benchmark example in each checkout called XCL's recompiler and DXC wrapper with four switch-form memory windows, split wave64 and fixed -O1. Built with cargo build --locked -j 5 --target x86_64-pc-windows-gnullvm --release -p xcl --example shader_bench. Ran wine shader_bench.exe compile <record> -O1 <dxil> and wine shader_bench.exe pipeline <record> <dxil> with Proton's Wine. PSO time is the CreateComputePipelineState call using XCL's ABI root signature and the matching build's precompiled DXIL.
  • Three runs per shader and build. All 30 DXC compiles and 30 PSO creations succeeded. The vkd3d and NVIDIA disk caches were disabled, with no cached PSO blob and a fresh process per creation. Vulkan feedback confirmed no cache reuse for all 26 calls with feedback enabled. Feedback was off for the first 4 calls.
Sample (RDNA2 instructions) DXC (s), main → PR Cold PSO (s), main → PR DXIL bytes, main → PR
0019989e (2,632) 1.017 → 0.872 1.805 → 1.544 208,944 → 184,672
00daa26e (4,497) 2.829 → 2.059 4.104 → 2.763 320,056 → 261,652
076191bb (5,187) 3.593 → 2.857 5.384 → 4.263 371,216 → 309,032
0452488a (10,753) 8.717 → 6.718 8.584 → 5.293 552,296 → 432,420
04fd77f7 (16,692) 12.987 → 12.380 26.010 → 19.388 1,163,756 → 1,100,536
Total 29.142 → 24.887 45.887 → 33.251 2,616,268 → 2,288,312

Totals are sums of per-shader medians. DXC time fell 14.6%, cold PSO creation time fell 27.5%, and DXIL bytes fell 12.5%. All five PSOs were faster.

Not tested

Native Windows, gameplay or shader execution correctness, and the full workspace suite.

AI use — OpenAI Codex (GPT-6, exact variant unavailable) wrote the local benchmark example, ran the tests and prepared the report.

anoyarou added a commit to anoyarou/xcl that referenced this pull request Nov 24, 2026
…k reserve (xcl-dev#1630)

In structurable_uncached, Item::Block pattern previously used
Some(CONT | DIRECT_RET). Because '|' inside an expression pattern evaluates
as bitwise OR ((u64::MAX - 1) | (u64::MAX - 2) == u64::MAX == END), it matched
END instead of CONT or DIRECT_RET, breaking structured loop continuations on
all loops and causing stack overflow in the unstructured dispatcher fallback.
Change to Some(CONT) | Some(DIRECT_RET).

Also link xcl.exe with /STACK:67108864 in build.rs so PE header specifies
64 MiB default stack reserve under Wine/MSVC.

Assisted-by: Antigravity
@auswhalen999-debug

Copy link
Copy Markdown
Author

@pickles976 Thanks for the sharp review — followed through on all four points in 91ae2c6 (and updated the PR description + fresh xcl-smoke):

  1. Correctness artifact & gpu_compute_e2e: Clarified honestly that the 12-shader retail corpus measures compile time only (standalone retail CS need live title UMA/descriptors), and that gpu_compute_e2e ran and passed (4/4) in the workspace suite. Added two permanent GPU dispatch output-parity tests in crates/xcl/src/gpu/recomp/tests.rs:
    • gpu_opt_lane_local_mask_exec_restore_and_carry_parity (runs on both Wave32 and Wave64, testing s_and_saveexec -> v_cmp + s_or -> EXEC restore -> v_cndmask_b32 + 64-bit v_add_co -> v_add_co_ci with dead final carry-out, verifying bit-exact output on every lane and 0 ballot(and( on Wave32 / native Wave64).
    • gpu_opt_hoisted_smem_store_hazard_and_branchless_helpers_parity (real GPU dispatch verifying hoisted/subsumed s_load_*, grouped s_buffer_load_* partial OOB bounds, store-hazard non-hoisting across global_store_dword, branchless fma_legacy(0, NaN, 7), and constant mul_legacy(2.0, -0.0) == +0.0).
    • Full cargo test --workspace --release -- --test-threads=4 at 91ae2c6: 797 passed, 0 failed, 41 ignored.
  2. Convergence & hazard model in opt.rs: Documented the formal constraint explicitly in both the module header and analyze_lane_local_masks() — the pass never moves, hoists, or deduplicates WaveActiveBallot across CFG boundaries (strictly intra-block, dead at block exit !live_out_s[bi]), rejects any whole-mask/cross-lane consumer so lanebit(WaveActiveBallot(and(act, cond))) == and(act, cond) per lane identically, and sets needs_exec_mask = true whenever any EXEC-widening op can intervene between def and use.
  3. Plan B split seam: Noted in the PR body — happy to split opt.rs ahead of emit.rs/mod.rs as a 2-PR stack if maintainers prefer.
  4. Shaders: speed up translated pipeline compiles and add PSO measurements #1524 cross-reference & zero conflict: Cross-referenced Shaders: speed up translated pipeline compiles and add PSO measurements #1524 in the PR description and confirmed 0 lines of diff on Shaders: speed up translated pipeline compiles and add PSO measurements #1524 commit 1's helpers (bits_at, put_bits, bvh_intersect, dst_sel, xcl_lv were intentionally left untouched so both PRs stack cleanly).

@nnonno91 Huge thanks for the independent AMD native-Wave64, mesh, XCL_HEAP_WINDOWS=1, and EXEC-restore output-parity verification — promoted that exact EXEC-restore scenario into the permanent gpu_opt_lane_local_mask_exec_restore_and_carry_parity test in 91ae2c6!

@Flyander Flyander left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One correctness issue needs a fix; see the inline comment.

AI use: OpenAI Codex (GPT-6; exact variant unavailable).

let soff = rdna2::field_value(d.enc, &d.words, "SOFFSET").unwrap_or(125);
let raw_imm = fval(d, "OFFSET") as u32;
let imm_off = ((raw_imm << 11) as i32 >> 11) as i64;
let off_ok = if soff != 125 {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Preserve carry before selecting Window 0. This predicate proves only that the base high dword is zero. With dynamic SOFFSET, imm_off >= 0 does not prevent sbase_lo + imm + soff from carrying into the next 4-GiB window (for example, base 0x00000000_FFFFFFFC plus soff=4). The known_zero_hi emitter path then computes a 32-bit address and reads xcl_mem0, while the generic path forms a 64-bit effective address and selects the next window, so the loaded value differs when mem_windows > 1. The known_zero_hi_sbuf path has the same issue for d0 + off. Could both fast paths retain/select the carry or prove a bound, with parity coverage at the 4-GiB boundary?

@MatyEjsr

Copy link
Copy Markdown

Independent verification and code review of PR #1630 at commit 17c02330d8b5a78c938a1cc52f04874e1fb9087a.

Environment

  • OS: Windows 11 Pro for Workstations 10.0.26200 (Build 26200)
  • CPU: AMD Ryzen 7 7800X3D (8 cores)
  • GPU: NVIDIA GeForce RTX 3090 (24322 MiB VRAM, driver 617.42 / 32.0.16.1742, Wave32, hardware mesh shaders supported)
  • RAM: 31.4 GB
  • Toolchain: rustc 1.100.0 (0ef1bc386 2026-11-09) / cargo 1.100.0 (3acc79c0c 2026-11-05) stable-x86_64-pc-windows-msvc, debug build, DXC dxcompiler 1.9.2602.17 (21d28f72) / dxil 1.9.2602.17

Tested

  • cargo build --workspace -j 8: exit 0 (12.25s; only the 2 pre-existing Atomic::fetch_update deprecation warnings).
  • cargo test --workspace -j 8 -- --test-threads=8: 795 passed, 0 failed, 41 ignored (exit 0).
    • Explicit SKIPPED tests (counted as passed by libtest, not coverage):
      • gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask: no wave64
      • gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware: no wave64
      • heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows
      • test_title_draws_with_a_root_signature_under_the_debug_layer: no d3d12SDKLayers.dll
      • Sample-gated tests skipped with XCL_SAMPLE_* unset.
  • Hardware mesh-shader GPU verification (not covered on the PR's GTX 1070 run):
    • XCL_REQUIRE_GPU=mesh cargo test -p xcl --lib -- gpu_mesh_mode_two_passes gpu_geometry_mode_es_gs_strip gpu_bench_really_runs --nocapture --test-threads=1: 3 passed, 0 failed, 0 ignored, 0 SKIPPED (0.35s). Both gpu_mesh_mode_two_passes and gpu_geometry_mode_es_gs_strip ran on hardware and passed.
  • Full workspace suite under XCL_HEAP_WINDOWS=1:
    • XCL_HEAP_WINDOWS=1 cargo test --workspace -j 8 -- --test-threads=8: 795 passed, 0 failed, 41 ignored (exit 0), 3 explicit skips (no wave64 x2, no d3d12SDKLayers.dll x1). heap_window_out_of_memory_falls_back_to_the_switch_form, gpu_raw_window_view_reaches_its_top, gpu_heap_windows_reject_out_of_uma_aliasing, and all 4 gpu_compute_e2e tests ran and passed with no device removal.
  • Merge check against current origin/main (c160d86, after gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426): git merge-tree --write-tree origin/main 17c02330d8b5a78c938a1cc52f04874e1fb9087a exits 0 with no conflicts.

Review notes

  • PR size / split: At +7,293 / -206 lines across 5 files in one commit, several pieces are largely independent (branchless prelude helpers and img_cls, early s_endpgm direct return / emit_range continue/break, conditional globallycoherent, NonUniformResourceIndex elision, entry io.Load pruning) and would be much cheaper to review and bisect if split into stacked PRs.
  • Dynamic soff on known_zero_hi_sload / known_zero_hi_sbuf (opt.rs:3007-3020, emit.rs:1726, emit.rs:1815-1821): in non-Kernel modes, known_zero_hi_sload accepts dynamic soff != 125 when imm_off >= 0 (and known_zero_hi_sbuf accepts any soff) and lowers to 32-bit addition against Window 0. Because a runtime soff is unbounded, an overflowing base_lo + soff wraps within Window 0 rather than carrying into hi >= 1. Restricting the 32-bit Window-0 fast path to constant offsets (soff == 125), or adding a carry guard for dynamic soff, avoids 32-bit wrap aliasing.
  • GPU parity tests for new passes: All 19 new tests (opt::tests and emit::opt_helper_tests) check static analysis metadata or Rust-side helper math; adding small GPU execution tests for hoisted SMEM/SBUF groups (switch and heap_windows), intra-block SBUF subsumption with partial OOB bounds, lane-local bool mask chains (including EXEC widening), and early s_endpgm under safe_barrier would directly exercise the emitted HLSL on hardware.

Not tested

  • AMD RDNA / Intel GPUs and native hardware Wave64 (gpu_wave32_program_in_wave64_hardware, gpu_geometry_wave32_prefix_count_over_a_mask).
  • D3D12 debug-layer e2e (d3d12SDKLayers.dll not installed on this host).
  • Release-mode test run, cold-PSO compile timings, XCL_SAMPLE_* tests, and retail title / smoke runs.

AI use

  • agy with gemini-4-neon-high: checked out commit 17c02330d8b5a78c938a1cc52f04874e1fb9087a, ran the build and workspace test suites (default, XCL_REQUIRE_GPU=mesh, and XCL_HEAP_WINDOWS=1), reviewed the diff, and wrote this report from the captured logs.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

  • cargo test -p xcl --lib: all passed, 0 failed, ~22 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

@milesah3ad

Copy link
Copy Markdown

Native Windows Blackwell numbers for this head, on synthetic programs. Driver time and DXC time don't change for them. In the switch form, DXIL grows 15–27 % for the programs the optimizer changes, without costing the driver anything. The suite passes.

Setup: RTX 5080 16 GB, driver 621.24, Ryzen 7 9800X3D (16 threads), 64 GB, Windows 11 Pro 26300, rustc 1.100.0, DXC 1.9.2609.5. Head 91ae2c6 against its base 9e3831e, release for the probe, debug for the suite.

Tested

  • cargo build --workspace then cargo test --workspace --no-fail-fast -- --test-threads=4 on 91ae2c6: 797 passed, 0 failed, 41 ignored. SKIPPED: the two wave64-only tests, and heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • The nv680 synthetic compute programs (Recompiler: memory windows from the descriptor heap (no per-access switch) #680's probe: 128 threads, wave64 + split wave64, 4 memory windows; 5 shapes × 250 / 1000 rounds × 2 seeds), translated on both trees through translate at the runtime's DXC level. Then a cold CreateComputePipelineState per program in its own process, base and head alternating which goes first. New seeds, so no driver-cache hits.
form programs DXIL, base → head driver, base → head
switch (default) 20 9,842 → 10,994 KB (+11.7 %) 1,020.8 → 1,014.8 s (−0.6 %)
heap (XCL_HEAP_WINDOWS=1) 20 6,678 → 6,678 KB 224.3 → 221.4 s (−1.3 %)
  • Per program, the driver time is within −8 % … +3 % (noise level on this machine), and no shape moves as a group.
  • Byte-identical DXIL for every program with a memory atomic (atomic, atomic64, both forms). I'd expect that from mem_coherent turning off for them.
  • Switch form, base / loop / wave: DXIL +15 to +27 % (e.g. base 1000 rounds 592 → 746 KB, wave 975 → 1,129 KB). The HLSL is about 1 % smaller (globallycoherent off the four window buffers, select helpers), so the growth comes from DXC. The driver time for these is unchanged (1000-round means: 55.4 → 55.7 s, 72.1 → 70.2 s, 80.7 → 79.3 s).
  • DXC time: no change measured. Three alternating runs of atomic / base / wave at 1000 rounds, switch form: 15.9 → 15.4 s, 9.5 → 9.3 s, 21.0 → 21.5 s. (A first, non-alternating pass showed +29 %. That was drift from running all base programs first, so I'm not counting it.)

Reading: these shapes have none of the scalar loads, buffer loads, carry-outs or SDWA helpers this optimizer works on, so "no change" here doesn't contradict the GTX 1070 retail numbers. What they do show: on Blackwell, the optimizer doesn't cost driver time on programs it barely touches, and dropping globallycoherent in the switch form makes DXC's output noticeably bigger without making the driver slower.

Not tested

  • Retail programs or a title run; Ada / Ampere / AMD; the heap form with retail programs.
  • Whether the bigger switch-form DXIL comes from globallycoherent alone (I didn't bisect the emitter changes).

AI use

  • Claude Code (Claude Opus 5.5) ran the builds, tests and measurements and wrote this report; I checked the numbers against the logs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants