shader: static Wave32 LDS hazard analysis for branched/disjoint compute (vitutu1#12 handover) #50
No reviewers
Labels
No labels
accessibility
bench-bm-v1
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/PastiiJay--klbf-lab!50
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@Vladimir-Human on GitHub · 2026-11-25 21:26 UTC · original
Vladimir-Human:shader/wave32-lds-disjoint→beta· +3441 −110 · 4 files · 2 commits · openSummary
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
@PastiiJay on GitHub · 2026-11-25 21:28 UTC · original
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.
@HandshakeHackin on GitHub · 2026-11-25 21:33 UTC · original
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.
@PastiiJay on GitHub · 2026-11-25 21:34 UTC · original
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.
@Proudnoob4 on GitHub · 2026-11-26 07:11 UTC · original
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.@PastiiJay on GitHub · 2026-11-26 07:14 UTC · original
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).
@Proudnoob4 on GitHub · 2026-11-26 08:08 UTC · original
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— passed@HandshakeHackin on GitHub · 2026-11-26 08:16 UTC · original
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
@Vladimir-Human on GitHub · 2026-11-26 09:46 UTC · original
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.@PastiiJay on GitHub · 2026-11-26 10:41 UTC · original
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.@PastiiJay on GitHub · 2026-11-26 12:50 UTC · original
@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.@Vladimir-Human on GitHub · 2026-11-26 19:19 UTC · original
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.@PastiiJay on GitHub · 2026-11-26 19:26 UTC · original
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.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.