Repository navigation
Recompiler: pre-emission RDNA2 optimizer, dominator SMEM hoisting, and lane-local mask scalarization - #1630
Recompiler: pre-emission RDNA2 optimizer, dominator SMEM hoisting, and lane-local mask scalarization#1630auswhalen999-debug wants to merge 2 commits into
Conversation
…d lane-local mask scalarization
|
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 |
|
Independent AMD native-wave64 and mesh coverage at Tested
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
|
|
Independent cold compute PSO timings on Linux / Proton This is the #1630 data point for campaign #1269 (A14). Tested
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. |
…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
|
@pickles976 Thanks for the sharp review — followed through on all four points in
@nnonno91 Huge thanks for the independent AMD native-Wave64, mesh, |
Flyander
left a comment
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
[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?
|
Independent verification and code review of PR #1630 at commit Environment
Tested
Review notes
Not tested
AI use
|
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
|
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 Tested
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 Not tested
AI use
|
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 MBDXIL,131,048RDNA2 instructions) on an NVIDIA GeForce GTX 1070 with cold driver-cache salt (109.0xcold/warm verified): -31.2% cold driverCreateComputePipelineStatetime (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.rsdirectly drives the emitter lowering inemit.rsand early-exit CFG inmod.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 ofopt.rsahead ofemit.rs/mod.rs, happy to split on request).Relationship to other
#1269PRsbits_at,put_bits,bvh_intersect,dst_sel, andxcl_lvuntouched (0 lines changed on those helpers) so#1524and#1630stack cleanly without conflict or double-work.#680(rebased onto9e3831eand supports both default switch andheap_windowsforms),#1356,#1380,#1439,#1345,#1315/#1316,#1043,#1111/#1596/#1597, or#1426direct-DXIL.What is in it
crates/xcl/src/gpu/recomp/opt.rs, registered incrates/xcl/build.rsTRANSLATOR_SOURCES):scc, SGPRs, carrysdst, and conservative RMW VGPR liveness under divergentEXEC, preservingMode::Kernellive-outs) for deadscc, dead carry-outWaveActiveBallot(includingDst::Nulland wave64 pairs), and dead pure ALU elimination.s_load_*ands_buffer_load_*CSE/hoisting (HoistedSmemGroup,HoistedSbufGroup), non-consecutive intra-blocks_buffer_load_*grouping (IntraBlockSbufGroup), andknown_zero_hiWindow-0 fast paths (s[sbase+1] == 0/(s[sbase+1] & 0xFFFF) == 0, withMode::Kernel4 GiB wrap guards).boolmask scalarization (v_cmp_*/v_add_co*/v_sub_co*and dead-sccbitwise SALU chains consumed only per-lane byv_cndmask_b32/ carry-in ops, disabled inMode::Kernelandsplit_wave64), with explicit convergence &EXEC-widening hazard model documented inopt.rs.mem_coherent: zeroGLC/DLC/SLC, zero memory atomics, zero cache inv/wb ops, and!(has_s_barrier && has_mem_store)).opt::tests).crates/xcl/src/gpu/recomp/emit.rs):ProgramOptfor deadscc/ 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]inheap_windowsmode, direct Window-0 fast path usingResourceDescriptorHeap[0u]underheap_windowsorxcl_mem0under switch mode), and lane-localbool ml_*masks (avoiding convergentWaveActiveBallot).NonUniformResourceIndexon wave-uniform SGPR handles inCompute | Mesh | Geometry(and non-splitKernel), keeping it inPixel,Vertex, and splitKernel; replacesimg_clsFMT_INFOtable lookup with constant bitmasks.globallycoherenton Computemem..mem3(andheap_windowsXCL_MW) gated onprogram_opt.mem_coherent; prunes non-ABI scratch SGPRio.Load()calls inMode::Computeand deadexec_lo/exec_hientry loads in non-Kernelmodes.?:/&&/||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-freeselect/bitwise equivalents (leaving#1524'sbits_at/put_bits/bvh_intersect/dst_seluntouched), and simplifiesv_mul_legacy_f32/float_compareon known constants while preserving-0.0fsign semantics.img_cls,uniform_sgpr_handles, andheap_windowsWindow-0 descriptor-heap emission (emit::opt_helper_tests).crates/xcl/src/gpu/recomp/mod.rs):opt::analyzeintotranslate()and routes block emission throughEm::emit_block_insts.return;({ xcl_s_barrier_exit(); return; }whensafe_barrieris active,return xo;forVertex) on earlys_endpgminCompute | Mesh | Vertex(preservingxcl_skip_endinKernel | Geometry | Pixel), extendsstructured_spanpastTerm::End, and emitscontinue;/break;inemit_rangeloops.crates/xcl/src/gpu/recomp/tests.rs):gpu_opt_lane_local_mask_exec_restore_and_carry_parity(Wave32 & Wave64 real GPU dispatch verifyings_and_saveexec+v_cmp+s_or+EXECrestore +v_cndmask_b32+ 64-bitv_add_co->v_add_co_cicarry chain with dead carry-out, bit-exact on every lane) andgpu_opt_hoisted_smem_store_hazard_and_branchless_helpers_parity(real GPU dispatch verifying hoisted/subsumeds_load_*, groupeds_buffer_load_*partial OOB, store-hazard non-hoisting, branchlessfma_legacy(0, NaN, 7), and constantmul_legacy(2.0, -0.0) == +0.0).scc, dead final carry-out, andDst::Nullcompare ballots are now elided.Tested
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), DXC1.9.2609.5, release build.cargo test --workspace --release -- --test-threads=4(aftercargo build --workspace --release, withXCL_DXC_DIRset) at91ae2c6: 797 passed, 0 failed, 41 ignored (748lib including both new GPU output-parity tests +49integration/e2e/oracle, includinggpu_compute_e2e4 passed, 0 failed and#680heap_window_tests).SKIPPEDGPU tests on GTX 1070:gpu::recomp::tests::gpu_geometry_mode_es_gs_strip: no mesh shadersgpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask: no wave64gpu::recomp::tests::gpu_mesh_mode_two_passes: no mesh shadersgpu::recomp::tests::gpu_wave32_program_in_wave64_hardware: no wave64150 KB – 1.15 MBDXIL,split_wave64=true,mem_windows=4,heap_windows=false, retail-O1/-O3threshold, per-run non-DCE-ableio.Load(508u)salt defeating%LOCALAPPDATA%\NVIDIA\DXCache, coldness self-check on#0:cold1=3788.3 ms,warm=35.6 ms,cold2=3882.6 ms, ratio109.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):fnv64)0019989e00daa26e-O1) -> 7,511 (-O3)*076191bb0526ab240452488a1f04a85e001714bf0155621c0291d282008bfb7a008d625c04fd77f7*Note:
#1(00daa26e) shrank HLSL from1,085.4 KB -> 978.4 KB, crossingdxc.rs's 1 MiB threshold from-O1to-O3, and still reduced total E2E compile time by-14.8%(15.76 s -> 13.42 s). Across the 12 shaders,NonUniformResourceIndexdropped2,500 -> 0,xcl_mLoad*calls dropped8,506 -> 2,829(-66.7%), entryio.Loaddropped1,248 -> 145(-88.4%), andgloballycoherentdropped48 -> 16.Regression run
main:
PR:
Not tested
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 at17c0233in comments below).XCL_HEAP_WINDOWS=1(functional unit/GPU coverage viaheap_window_tests,gpu_compute_e2e, andheap_windows_window0_fast_paths_use_descriptor_heappassed).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, implementedopt.rsand theemit.rs/mod.rs/build.rschanges and unit/GPU parity tests, ran the workspace test suite, paired cold-PSO benchmarks, andscripts/smoke.ps1runs, and drafted the commits and PR description.