Repository navigation
Shaders: include v_readfirstlane_b32 in wave64 exchange and check implicit reads in lane_uniform - #354
Shaders: include v_readfirstlane_b32 in wave64 exchange and check implicit reads in lane_uniform#354AscilCH wants to merge 1 commit into
Conversation
…licit reads in lane_uniform Fix two wave64-on-wave32 soundness bugs in `crates/victory-shader/src/emit/lower.rs`: 1. `v_readfirstlane_b32` (when not a per-lane waterfall descriptor read) was omitted from `console_lanes`, `crosses`, and `VICTORY_WAVE_WHY` in `Lower::new`. A console wave64 compute shader whose cross-lane reads only used `v_readfirstlane_b32` (or paired it with half-local ops such as `ds_swizzle`/DPP) did not allocate half-wave `exchange` LDS, causing lanes 32..63 on 32-lane hosts to read lane 32's half instead of the 64-lane wave's first active lane. 2. `lane_uniform` only inspected explicit `v.src` operands and ignored implicit register reads in `inst.reads` (such as the accumulator VGPR of `v_fmac_*`/`v_mac_*`/`v_dot*c_*`, preserved destination halves on 16-bit writes, and implicit `VCC` on VOP2 `v_cndmask_b32`/`v_add_co_ci_u32`/ `v_div_fmas_f32`), and did not exclude `movrel*`. A per-lane accumulator or `VCC`-selected VGPR whose explicit sources were uniform was falsely marked uniform, causing `v_readfirstlane_b32` to skip half-wave exchange. Inspect all `inst.reads` entries directly and exclude `movrel*`. Add `wave64_readfirstlane_exchanges_across_halves_on_32_lane_host` and `wave64_implicit_reads_are_not_marked_lane_uniform` in `emit::wave64_tests`.
…licit reads in lane_uniform (fxceless#354)
|
Offline check on a 32-lane card. On current Tested
Each of the 10 goes from
None of the programs that My guess, which I haven't checked: these programs already pass through Not tested: in the title (offline the result is already worse on this card), other GPUs, and the PR on its own base ( AI use: Claude Code (Claude Opus 5.5) built and ran the check on my machine, compared the listings and wrote this comment. |
|
RX 7900 XTX (RDNA3), Windows 10 + #402 for SM 6.6, main |
…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).
|
There is one more ordinary two-result case worth covering in the uniformity analysis here: I tested the actual v_mov_b32 v5, v0
v_mov_b32 v6, 42
v_swap_b32 v5, v6
s_endpgmHere
All four controls (both varying or both uniform, in both register orders) agree with the oracle in all three builds. The two focused tests on each uncorrected revision return 1 pass / 1 intended assertion failure; on the corrected receiver both pass. The existing native library suite gives 171 passed / 3 ignored before and after, with identical named outcomes. The historical #354 head gives 170 passed / 2 ignored. All builds completed successfully. Exact tested revisions: main Strict Clippy for the corrected non-test library also exits 0. Strict native The narrow correction I tested is to retain the existing VALU and guard eligibility checks, handle this instruction before the generic if name == "v_swap_b32" {
if let (Some(&Operand::Vector { reg: src, .. }), Some(Operand::Vector { reg: dst, .. })) =
(v.src.first(), v.dst)
{
for (out, input) in [(Reg::V(dst), Reg::V(src)), (Reg::V(src), Reg::V(dst))] {
if inst.read(input).is_some_and(|x| same.contains(&x)) {
same.extend(inst.write(out));
}
}
}
continue;
}For #354 this needs to be before the generic implicit-read/overwritten-destination filtering. Simply requiring both old values to be uniform would avoid the false positive but still miss the uniform output of a mixed swap. The tested main's ascending-register read selection also makes the two register orders differ. The per-result rule handles both tested orders while retaining the existing guard eligibility checks. This matters because Main advanced to AI assistance: Hermes Agent, working on behalf of ArturoWolff. (GPT 6.2 Sol Max). |
Problem
Two wave64-on-wave32 soundness bugs in
crates/victory-shader/src/emit/lower.rs:exchangeforv_readfirstlane_b32(Lower::new):console_lanes,crosses, andVICTORY_WAVE_WHYcheckedv_readlane_b32andv_writelane_b32but omittedv_readfirstlane_b32. On 32-lane hosts, a console wave64 compute shader usingv_readfirstlane_b32without another full-wave crossing op did not set upexchangeLDS, so lanes 32..63 executedWaveReadLaneFirston their own 32-lane half instead of across all 64 lanes.lane_uniform:lane_uniformonly checkedv.srcand ignored implicit reads ininst.reads(e.g., accumulator VGPRs inv_fmac_*/v_mac_*/v_dot*c_*, preserved 16-bit destination halves, and implicitVCCin VOP2v_cndmask_b32/v_add_co_ci_u32/v_div_fmas_f32) as well asmovrel*. Whenever explicit sources were uniform, the per-lane result was falsely added toself.uniform, causingv_readfirstlane_b32to skipexchange_halves.Fix
v_readfirstlane_b32toconsole_lanes,crosses, andVICTORY_WAVE_WHY(leaving waterfall descriptor reads unaffected since those lower per-lane).(reg, val)ininst.readsinsidelane_uniform(and excludemovrel*) so implicit VGPR andVCCdependencies are properly tracked.wave64_readfirstlane_exchanges_across_halves_on_32_lane_hostandwave64_implicit_reads_are_not_marked_lane_uniforminemit::wave64_tests(assertingwave_size == Some(32)andhalf_exchanges> 0 for standalonev_readfirstlane_b32,v_fmac_f32, and VOP2v_cndmask_b32,half_exchanges == 0for truly uniformv_mov_b32, validated bydxil.dll, and executed on 32-lane hardware when supported).Verification
cargo test -p victory-shader --locked wave64: 9 passed, 0 failed (dxil.dllvalidation +wave_size/half_exchangesassertions; note Intel UHD adapter 0 skips[WaveSize(32)]compute execution as with the existingwave64_tests)cargo test -p victory-shader --locked waterfall: 21 passed, 0 failed (verified waterfall wave64 unaffected)cargo xtask policy: 169 files okcargo clippy -p victory-shader --all-targets --locked -- -D warnings: cleancargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings: clean(AI-assisted; synthetic tests only, no game data.)