shader: static Wave32 LDS hazard analysis for branched/disjoint compute (vitutu1#12 handover) #50
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/50"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-25T21:26:30Z.
Summary
AI-assisted handover of upstream
vitutu1/victory-perfwork (specifically original PR #12, since that repository is now unavailable) ontoPastiiJay/klbf-labbeta, with additional adversarial soundness hardening.Instead of blindly falling back to emulated 64-lane subgroup execution (
wave64) whenever LDS (ds_*) operations appear under conditional branches or per-lane offsets, this PR adds static Wave32 LDS alias/hazard proof analysis (crates/victory-shader/src/emit/lds.rs) so proven-safe compute shaders run natively in Wave32 on NVIDIA and other 32-wide GPUs.Key Details & Soundness Hardening
MAX_OFFSET = 1 MiB32-bit bounds (including<4-byte unaligned vs>=4-byte dword overlap guards, zero RMWs, acyclic!allregions, symmetric RAW/WAR/WAW).v_mbcntconsole_laneforgroup <= 64, alignment, sub-array splitting, non-wrapping group footprints, cross-cluster disjointness, and returning atomics / cyclic!all.dstverification ineval_inst,uniform_result_tz, andis_group_uniform_val(rejects VOP3Bv.carry/Reg::Sccconfusion).c < cs.user_sgprs()+Input::GroupId, refusingscratch_wave_offsetand uninitialized SGPRs).!allregion containss_barrier.c != 253) andOperand::Attras group-uniform.Verification (
0948a4fd5)cargo clippy -p victory-shader --all-targets -- -D warnings: exit 0, 0 warnings.VICTORY_REQUIRE_HW_GPU=1 cargo test -p victory-shader --lib lds -- --nocapture: 19 passed; 0 failed (all 13emit::lds::tests::*,lds_shared_returning_atomic_stays_wave64, and 3 hardware D3D12 Wave32 execution tests ran with no skip).cargo test -p victory-shader --all-targets: 241 passed; 0 failed; 3 ignored.Co-Authored-By: AI Assistant
Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-25T21:28:24Z.
Thanks a lot @Vladimir-Human, and thank you for bringing the original vitutu1/victory-perf #12 work over, with credit, now that its repository is gone. What we keep: instead of falling back to emulated 64-lane execution whenever LDS accesses sit under branches or per-lane offsets, the shader translator now proves which compute shaders are safe to run natively in Wave32, and refuses the cases it can't prove (barriers in divergent regions, returning atomics, unproven uniform inputs). The 19 LDS tests, including 3 on real D3D12 hardware, and the full
victory-shadersuite pass on your side.This is a large change (+3,056 lines) to how compute shaders are translated, so it will get a run of its own on the RX 9070 XT: same save, same run, fps and picture against our reference build, since a wrong proof would show up as image errors rather than a crash. Results will be posted here. The NVIDIA testers from #30 would be the best people to measure the Wave32 gain itself, if any of them has time.
Imported from PastiiJay/klbf-lab. Originally posted by HandshakeHackin on 2026-11-25T21:33:26Z.
The Windows SDK DXIL validator accepted all three new Wave32 fixtures at
0948a4f, both on this PR alone and after merging the shader optimizer from #41 (ba88ab0). The 16 other tests selected byldspassed in both builds. On Linux, the shader library suite passed 189 tests, with two ignored. Windows validation log for both revisionsOne limit for anyone reproducing this in hosted Windows CI: the runner’s WARP adapter reported a maximum wave width of 4. D3D12 rejected all three 32-lane pipelines at creation, before any dispatch. The log distinguishes that from a rejected DXIL blob. The three execution results in the PR description are the author’s physical-GPU results.
Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-25T21:34:16Z.
Thanks @HandshakeHackin, that's a very useful split. What we keep: the DXIL validator accepts all three new Wave32 fixtures, both on this PR alone and combined with the #41 shader optimizer, and the other LDS tests pass in both; on hosted CI, WARP only offers a wave width of 4, so the 32-lane pipelines can't be created there at all, and the execution results rest on real GPUs.
That makes our RX 9070 XT run the first independent execution check on hardware. We'll post it here, picture and fps.
Imported from PastiiJay/klbf-lab. Originally posted by Proudnoob4 on 2026-11-26T07:11:32Z.
Tested this PR on an RTX 4080 16 GB / Windows 10 in GTA 6 (
--console series-s, 10-minute runs, integrated alongsideVICTORY_LDS_FLAGS/lds_flag_regioninsidelds::meetings):Results
lds+wave64_testspass cleanly.6 → 10refused compute pipelines,0x80070057):lds_meetings+VICTORY_LDS_FLAGS, 6 refused):2da4beb386509b77,369cbe906ea72764,02384a60fda6f2d0,6b82bc7d22016cb5,5dc3b25986622949,6f225b641c5b0708#50(10 refused — same 6 PLUS 4 newly refused):89d08e561897d4e5(one of the character skinning passes noted incard_steps.rs!)55679a0547649d0b(another skinning pass noted incard_steps.rs!)1f1fbd86759b3da2caf96a3229145fa6Root Cause
In
lds.rs(else if writes[r] && !has_rmw[r]), the stricterhas_provable_shared_waw/region_has_cyclewrite-only check refuses write-only branched LDS regions that upstreamlds_meetingspreviously allowed in Wave32 (upstream explicitly carriedshortcut: two writes in one region are taken not to hit the same dword from both halves). On Wave32 GPUs (NVIDIA), refusing those 4 shaders sends them back toWaveSize(64), causingCreateComputePipelineStateto fail withE_INVALIDARGand dropping their dispatches completely (including two skinning shaders).Keeping
lds::meetings's exact read+write proofs (Refinement A/B) while relaxing write-only non-RMW regions (or gating the stricter write-only refusal behind a switch on 32-lane hosts) would avoid regressing those 4 GTA 6 compute passes on NVIDIA.Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-26T07:14:09Z.
Good catch, that is a real regression on 32-lane cards: 4 more compute pipelines refused (including two skinning passes) because the stricter write-only check sends them back to wave 64. Noted for this PR together with your suggested fix (keep the read+write proofs, relax or gate the write-only refusal on 32-lane hosts).
Imported from PastiiJay/klbf-lab. Originally posted by Proudnoob4 on 2026-11-26T08:08:27Z.
Follow-up from testing the fix live on RTX 4080 16 GB (Windows 10, Series S) — important detail before you patch this PR:
Relaxing only the
else if writes[r] && !has_rmw[r]branch was not enough: all 4 of those shaders (89d08e561897d4e5,55679a0547649d0b,1f1fbd86759b3da2,caf96a3229145fa6) were still refused (0x80070057) in our Pass 8/9 10-minute runs.Root cause
In
lds.rs:record_kind()sets bothreads[r] = trueandwrites[r] = true(plushas_rmw[r] = true) forKind::Rmw(LDS atomics).lds_meetingsonly setreads[r] = trueonname.starts_with("ds_read")— any non-ds_readLDS instruction (including atomics) only setwrites[r] = true.ds_read*in the!allregion,reads[r] && writes[r]becametrueand skipped the write-only branch entirely.Verified fix
Track
has_plain_read: Vec<bool>(set only whenkind == Kind::Read), and when opt-inVICTORY_LDS_WRITE_ONLY_OK=1is active on 32-lane hosts, acceptreads[r] && writes[r]when!has_plain_read[r](and keep the relaxed write-only branch):21/21emit::lds::testsstill pass unchanged (includingatomics_are_rmw_and_require_lane_privacy).89d08e561897d4e5— passed55679a0547649d0b— passed1f1fbd86759b3da2— passedcaf96a3229145fa6— passedImported from PastiiJay/klbf-lab. Originally posted by HandshakeHackin on 2026-11-26T08:16:36Z.
On
0948a4f,VICTORY_WAVE_WHY=1prints “an LDS read and write in one lane-branch region” even for two plain writes to the same dword, with no read in the shader.I put a diagnostic patch on top of this PR. It reports which check kept Wave64 and distinguishes a write/write overlap, an atomic with no plain LDS read, and a mixed region with an explicit read. A shared-address atomic with and without an explicit read still chose Wave64 in both tests. The lane-private atomic still chose Wave32. The before/after log checks and the full shader library suite passed. Diagnostic patch · CI and emitted messages
In a separate four-kernel check, relaxing only the write/write guard changed just the same-dword write-only case (64 → 32). Separate writes stayed at 32, overlapping reads/writes stayed at 64, and a read disjoint from both writes stayed at 32. This was synthetic shader lowering. @Proudnoob4’s Pass 10 above is the hardware evidence for the four game shaders. Four-kernel comparison
Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-26T09:46:55Z.
Thank you @Proudnoob4, @HandshakeHackin, and @PastiiJay for the live hardware testing, root-cause isolation, and diagnostic checks! Pushed follow-up commit
4fa24ffaddressing both findings:32-lane opt-in
VICTORY_LDS_WRITE_ONLY_OK=1+has_plain_read(emit/lds.rs):record_kind()now trackshas_plain_readstrictly onKind::Read(ds_read*), separate fromKind::Rmw(LDS atomics).lds_write_only_ok(), gated strictly onhost_max_wave() == 32andVICTORY_LDS_WRITE_ONLY_OK=1(always off by default and always disabled on 64-lane hosts).!allregions with no plainds_read*(write-only non-RMW regions and shared/unproven LDS atomics without a plain LDS read, matching the 4 newly refused compute shaders@Proudnoob4verified on RTX 4080) are accepted for Wave32. Divergents_barrier, unhandled DS ops (ds_nop, GDS, etc.), and mixed regions with an explicit plainds_read*(has_plain_read == true) remain refused. Default behavior when unset is unchanged.Specific
VICTORY_WAVE_WHY=1refusal diagnostics (emit/lds.rs,emit/lower.rs):"an LDS read and write in one lane-branch region"message with typedlds::Refusalvariants returned bylds::analyze(...)and reused directly bylog_wave64_why(no redundant analysis pass):"overlapping LDS writes in one lane-branch region""an LDS atomic with no plain LDS read in one lane-branch region"ds_read*:"an LDS read and write in one lane-branch region"Verification:
ds_read*(default vsVICTORY_LDS_WRITE_ONLY_OK=1on 32-lane and 64-lane hosts), all four synthetic lowering kernels (same-dword write-only 64 -> 32 under flag, separate writes 32, overlapping read+write 64, read disjoint from both writes 32), negatives_barrier/ds_nopchecks under the flag, and exactVICTORY_WAVE_WHYreason strings.cargo test -p victory-shader -- --test-threads=4: 243 passed; 0 failed; 3 ignored (including the 3 hardware D3D12 Wave32 LDS execution tests).cargo clippy -p victory-shader --all-targets -- -D warnings: 0 warnings.Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-26T10:41:59Z.
Thanks @Vladimir-Human, keeping the new behaviour opt-in on 32-lane cards is the right call. We'll try
VICTORY_LDS_WRITE_ONLY_OK=1in game on our Radeon as well.Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-26T12:50:54Z.
@Vladimir-Human, data from @seth1295 on an RTX 2080, head of this PR with
VICTORY_WAVE_WHY=1but without the opt-in (logs in #65, shader hashes redacted): 11 compute pipelines refused with0x80070057, against 7 on current beta. The most frequent WAVE64-WHY reasons are 64-thread groups with "an LDS read and write in one lane-branch region" or "an LDS atomic with no plain LDS read in one lane-branch region", often withmask as data,v_mbcntorv_readlane. He will rerun withVICTORY_LDS_WRITE_ONLY_OK=1and unredacted hashes after the weekend.Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-26T19:19:10Z.
Thanks @PastiiJay and @seth1295 — that 11 vs 7 delta without
VICTORY_LDS_WRITE_ONLY_OK=1matches the stricter default in4fa24ff:betaonly refused regions with both a plainds_read*and a write, whereasAtomicWithoutPlainReadnow conservatively catches unguarded LDS atomics with no plainds_read*until proven lane-private or opted in.Rerunning with
VICTORY_LDS_WRITE_ONLY_OK=1and unredacted hashes after the weekend will cleanly isolate those cases from genuineReadWriteOverlaphazards.Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-26T19:26:44Z.
Thanks @Vladimir-Human, that explains the 11 vs 7 gap neatly. We'll leave the default as it is for now and post seth1295's opt-in rerun here as soon as it lands, so the
AtomicWithoutPlainReadcases can be sorted one by one.Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-27T07:10:34Z.
Pushed soundness fix
a6883bffor cross-cluster footprint overlap incrates/victory-shader/src/emit/lds.rs(region_lane_private):ranges_may_overlap(a.min_lo, a.max_hi - a.min_lo, ...)call with direct half-open interval overlap(a.min_lo < b.max_hi && b.min_lo < a.max_hi)while preserving the((a.max_width >= 4 || b.max_width >= 4) && !align4)alignment guard. Passing aggregate footprint widths like33(n = 33..63partial-workgroup byte writes) intoranges_may_overlaprounded the upper bound down to a multiple of 4 on the aligned path and dropped trailing bytes, allowing cross-lane byte aliasing.emit/lds.rs):partial_workgroup_byte_alias_is_refused: teststhreads = [n, 1, 1]forn in [32, 33, 63, 64](unit + end-to-end lowering forn = 33, 63) and disjointoff = ncontrols.exhaustive_byte_access_oracle_has_zero_false_accepts: checksn = 32..=65,stride in [1, 2, 4],initial in 0..4,r in 0..=n*stride+4(48,212cases,0false accepts).VICTORY_D3D12_DEBUG=1):cargo clippy -p victory-shader --all-targets -- -D warnings: 0 warnings.cargo test -p victory-shader -- --test-threads=1: 245 passed; 0 failed; 3 ignored (all 17emit::lds::tests::*and 4emit::wave64_tests::lds_*tests passing).Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-27T09:52:36Z.
Thanks @Vladimir-Human, the exhaustive byte-access oracle with zero false accepts makes this fix easy to trust. We'll review it with the next beta batch. Could you rebase on the current head if it no longer merges cleanly by then?
Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-27T10:44:14Z.
Thanks @PastiiJay! Verified
a6883bfstill merges cleanly against currentbeta(6cce57e), and I will rebase promptly if the next beta batch introduces any conflict.Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-27T10:50:21Z.
Thanks @Vladimir-Human for the Wave32 analysis and the merge check against
beta(6cce57e). It's a big change, so we're going through it before anything lands. Could you list which compute shaders you tested the hazard analysis on?Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-27T10:52:01Z.
We'll take them onto the AMD line one at a time with an A/B bench. Thanks, the tests you added make that much easier.
Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-28T18:21:07Z.
Superseded by #183 targeting
stable-amd(v26.11.6): https://github.com/PastiiJay/klbf-lab/pull/183Pull request closed