Repository navigation
xshader: lower constant-lane v_readlane_b32 for Wave32 and portable Wave64 - #185
Vladimir-Human wants to merge 4 commits into
Conversation
…ave64 Lower non-spill constant-lane and upper-bound-proven SGPR v_readlane_b32 instructions in compute shaders with exact RDNA2 EXEC-ignoring semantics: - Separate SGPR spill VGPRs (written by v_writelane_b32) from cross-lane VGPR broadcasts so shaders with both spills and constant readlanes compile. - On 1D Wave32 groups where forward CFG analysis proves all lanes active in EXEC and uniform control flow/selector, emit zero-overhead WaveReadLaneAt with [WaveSize(32)]. - When EXEC may have disabled the target lane, on 2D/3D or partial groups, or for portable Wave64 running on Wave32 hosts, stage through groupshared tb_swizzle hoisted outside skip guards using the guest wave stride (32 or 64) without requiring [WaveSize(64)]. - Verify structured CFG and loop uniformity before allowing barrier/wave exchanges, and explicitly refuse out-of-range lanes, unproven dynamic SGPR selectors, non-uniform loops, interleaved loops, and early s_endpgm.
- F1: Reject non-uniform forward branches skipping an entire enclosing barrier loop (from < l && to > l), and reject barrier loops following non-uniform loops that could desync the function-wide tb_guard counter. - F2: Couple analyze_uniformity with control dependence so any SGPR/SCC written inside a non-uniform branch or loop span is tainted to fixpoint. - F3: Check dst reads on SOP1 RMW ops (s_bitset0/1, s_cmov), invert SCC tracking to explicit preserve/write allowlists (defaulting unknown ops to tainted SCC), and restrict uniform SMEM to loads with NULL/SGPR soffset. - F4: Match all 32/64-bit scalar ops touching EXEC in wave-width marker detection and enforce conflict/width checks on count <= 32 groups too. - F5: Restrict the indexed_lane tb_lane v_mbcnt fast path to -1 masks, preserving WaveActiveBallot for Wave32 EXEC masks (with WaveSize(32)) and refusing unmodeled lane-mask v_mbcnt under indexed_lane. - F6: Guard hoisted emit_indexed_read loads on active skip flags while keeping both barriers unconditional so skipped lanes never read OOB on partial groups. - Minor: Reject incomplete or CLAMP/OMOD-flagged VOP3 v_readlane_b32.
|
Thanks for this. I trial-merged it onto Before merging, I'd like to understand a tail latency change in the Lanes benchmark. I ran
The medians match, but frame p99 went over 450 µs in 5 of 15 runs with this PR and 0 of 15 on
The full check's own benchmark run on the merged tree also read 725.6 µs. The runs for each build were done in blocks (5, then 10), not strictly alternated. I haven't found the cause. The new wake-up path for waiting queues is the first place I'd look, but that's a guess. Could you check whether you see the same spread over repeated runs, and either fix it or explain it? On the elision logic: from reading it, only monotone waits at list start are skipped, and only with no tracked or in-flight write to the address. I found draws, dispatches, copies, markers, queries and bundles all recording writes. One case I don't see covered is the CPU lowering a label between submission and GPU execution. Is that something you considered? I didn't test this in a retail title. Host: NVIDIA GeForce RTX 4070 Ti SUPER ( |
|
This ended up being noise, ignore me. will merge this and others soon. thank you. |
…rrier fence, W14-07 CAS stores, W14-08 wave64 readlane Implements Wave 14 Lane 14C shader stability fixes: - W14-01 (--store-page-guard, adapted from ethan00013/keylime@650550ffa, GPL-3.0): emit lazy %store_addr_valid(heap_base, va) checking the 64 KiB page-validity bitmap at heap_base+0x170000 and GPBM control header at heap_base+0x180000 (runtime/src/gpu_page_bitmap.h) on PSB stores/atomics; default off, zero bloat on read-only shaders. - W14-05 (adapted from ethan00013/keylime@0afb8154c5, GPL-3.0): per-function tripped flag in add_loop_guards so hitting a nested inner loop cap breaks enclosing loops instead of multiplying limit*limit. - W14-06 (adapted from Marvisak/VIctory#1799 & five-star-recomp@320612a4d7, GPL-3.0): downgrade s_barrier inside switch/dispatch form, divergent guards, or non-top-level mesh blocks to OpMemoryBarrier while preserving uniform top-level CS OpControlBarrier. - W14-07 (adapted from Marvisak/VIctory#2208, GPL-3.0): replace OpAtomicAnd+OpAtomicOr in global_sub and buffer_sub with OpAtomicCompareExchange CAS loops. - W14-08 (adapted from fxceless/victory-fork#354 GPL-3.0 & brcly/TuxBox#185 Apache-2.0): tighten uniform_vgprs/wave64_halves implicit-read tracking (DPP mods, vlist, block-0 back-edges, v_fmac_f64, v_dot*c_u32_*, v_cndmask_b16) and constant-lane/uniform v_readlane_b32 lowering. - Add synthetic semantic & spirv-val regression suite tests/semantic/test_w14_shader_stability.py (zero game data).
|
Automated review against current main found blocking correctness risks before merge: (1) wave width is inferred from b32/b64 EXEC operand width, which is not conclusive and can silently select Wave32 for a Wave64 program; (2) the unproven-selector fallback can use a hardcoded 64-lane base without bounds checks and can read stale values for branch-skipped lanes; (3) new readlane refusals may be swallowed by the lone-lane retry; (4) scalar memory loads are treated as workgroup-uniform for loop-convergence proofs, which can introduce barrier deadlocks. Please address these with regressions before merging. |
- Wave width inference: remove inconclusive 32-bit EXEC_LO heuristic from has_wave32_markers, treat any ExecHi operand as a Wave64 marker, and refuse ambiguous 32-bit EXEC_LO operations lacking conclusive Wave32/Wave64 proof. - Unproven-selector fallback: gate swizzle_group_reads / GROUP_READ strictly on complete 64-lane groups (count % 64 == 0, guest_width == 64, structured compute swizzle), publish every lane's actual VGPR unconditionally before the barrier in emit_compute_swizzle(GROUP_READ), guard only the load on active skip flags, and mask the selector with & 63u. - Lone-lane retry: propagate cross-lane v_readlane_b32 refusals directly in translate_outputs instead of falling back to lone_lane::retry. - SMEM uniformity: treat Enc::Smem scalar loads conservatively as non-uniform in analyze_uniformity_pass so mutable/coherent scalar loads cannot feed barrier loops enclosing v_readlane_b32.
|
@tsunderejay Thank you for the detailed review — pushed monotonic fix commit
Verification (
|
|
The 128 lost shaders are mostly from the early return in translate_outputs for has_non_spill_readlane: disabling it leaves 4 lost and 26 changed, with none gained. Please suppress the fallbacks only when the lane read itself is what failed, and fall back for the 4 that lack a lane bound. On recorded requests the PR doesn’t translate any of the 278 shaders refused for lane reads, so could you show a case it fixes, ideally a GPU check where main computes the wrong result? |
AI-assisted PR.
Summary
Lowers constant-lane
v_readlane_b32wave reductions intools/shader-compiler:WaveReadLaneAtwhen the wave execution context and SGPR/SCC/Exec operands are proven uniform across a dataflow + control-dependence fixpoint, falling back cleanly to VGPR-indexedtb_swizzleLDS exchange otherwise.s_bitset*/s_cmov*/Sopk/Smemuniformity rules,ExecLo/ExecHiconflict checks,v_mbcnt[WaveSize(32)]WaveActiveBallothandling, guarded partial-group OOB loads between unconditional barriers, andtb_guardloop checks rejecting preceding/nested non-uniform loops.<= 1,200lines with zero inline#[cfg(test)]modules (exec_group.rsuntouched).Verification (commit
4ecbc63c)test_repository_hygiene.py,test_translator_checks.py,test_wave_extrema.py,test_dpp8_exchange.py): 13 passed, 0 failedcargo test --manifest-path tools/shader-compiler/Cargo.toml: 318 passed, 0 failed, 0 ignored (316 lib + 2 integration)cs_6_6/cs_6_0) + hardware D3D12 readback (RTX 4070 SUPER,10de:2783,readlane_probe+compute.cpp): 15/15 cases passed, 5,760/5,760 words exactgit merge-tree --write-treeclean againstorigin/mainand PR#176.