Skip to content

shader: static Wave32 LDS hazard analysis for branched/disjoint compute (vitutu1#12 handover) - #50

Closed
Vladimir-Human wants to merge 86 commits into
PastiiJay:mainfrom
Vladimir-Human:shader/wave32-lds-disjoint
Closed

Vladimir-Human wants to merge 86 commits into
PastiiJay:mainfrom
Vladimir-Human:shader/wave32-lds-disjoint

Conversation

@Vladimir-Human

Copy link
Copy Markdown

Summary

AI-assisted handover of upstream vitutu1/victory-perf work (specifically original PR #12, since that repository is now unavailable) onto PastiiJay/klbf-lab beta, 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

  • Refinement A (Disjoint constant byte ranges): Proves cross-lane accesses on a shared group-uniform base use disjoint byte ranges within non-wrapping MAX_OFFSET = 1 MiB 32-bit bounds (including <4-byte unaligned vs >=4-byte dword overlap guards, zero RMWs, acyclic !all regions, symmetric RAW/WAR/WAW).
  • Refinement B (Injective per-lane private slots): Proves lane-private slots remain injective across all active workgroup dimensions and paired v_mbcnt console_lane for group <= 64, alignment, sub-array splitting, non-wrapping group footprints, cross-cluster disjointness, and returning atomics / cyclic !all.
  • Adversarial hardening added before handover:
    • Primary 1-dword dst verification in eval_inst, uniform_result_tz, and is_group_uniform_val (rejects VOP3B v.carry / Reg::Scc confusion).
    • Tightened SGPR input uniformity (c < cs.user_sgprs() + Input::GroupId, refusing scratch_wave_offset and uninitialized SGPRs).
    • Refuses execution refinement if any !all region contains s_barrier.
    • Refuses non-inline SOP special constants (c != 253) and Operand::Attr as 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 13 emit::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

fxceless and others added 30 commits November 24, 2026 13:48
- 59 of the 64 trace programs and the irradiance-cache shading program
  translate; 51 programs leave the approximate wave64 forms.
- The workspace passes the lint with warnings as errors in both feature sets;
  a few style lints are let through in Cargo.toml for this fork.
- README status updated (relay and in-place memory results);
  docs/fork-ray-tracing.md describes what the title does and what is built.
…astiiJay#1)

Co-authored-by: ZazaJr24 <218105339+ZazaJr24@users.noreply.github.com>
…ning

- Shader tests: a software adapter given as the default device is not taken
  for a hardware device, so the tests that need a real card skip there.
- Diagnostics: the stencil plane of dumped depth-stencil targets and the
  title's descriptions of its stencil views.
- README: the newest commits lose the GPU device shortly after start on the
  test machine; the cause is not found yet.
The update moved the particle light-atlas compute programs to a form that
puts group barriers inside branches and loops; a dispatch of them stood on
the card until the device was reset. That form is now off unless
VICTORY_WAVE_WIDE=1, and the shader cache key includes the wave switches.
Checked with a plain run of this tree on the test machine.
…apter

Hosted runners list a display stub first, so the default device there is the
software adapter; the tests that need a real card now skip it.
- Clean-up passes over each translated module (VICTORY_SHADER_OPT bits: dead
  code, folding, reuse, branch facts, loads within a block, wave64 first-lane
  exchange), part of the shader cache key. About 43 % fewer host instructions
  over the pack; about 20 ms less GPU time per frame on the test machine.
- translate: a census of the emitted code.
- Checked with plain game runs of this tree on the test machine.
…ative VGPR reads keep parked lanes (PastiiJay#11)

The console compiler parks a wave64 lane mask in two lanes of a spare VGPR
and may restore the halves with other instructions between the two
v_readlane_b32. The pair restore now looks ahead in the block (nothing between
may touch the second register, write the first, or save into the lanes), so
the mask comes back as a mask. This lets indirect_light_probes
CS_IrradianceCache_Shade / ShadeSecondary translate: they were dropped every
frame, leaving the irradiance cache unlit and everything in shadow black.

An M0-relative read (v_movrels_b32) names every VGPR from its base up, which
marked the parking VGPR as an ordinary one and turned unspilling off for the
whole program. Relative reads no longer count there (relative writes still
do). billboard_nobump CS_RaytracingResolve_a56bfb9c translates with it.

translate: VICTORY_TRANSLATE_ONLY=<hash prefixes> limits a run to those
containers; VICTORY_HOST_MAX_WAVE=32 translates as on a 32-lane host, so
--pipelines matches what the runtime creates on NVIDIA.
Comments, documents and descriptions now say "the title". No code changes.
Its programs translate and run, but on the test machine the lighting gain
could not be shown, it costs about 40 ms of GPU time per frame, and the
picture is being re-checked one change at a time from a known-good tree.
It may come back once that is settled.
The previous commit took it out; that was not wanted. The tree is again as
it was before that commit.
Double-precision shader instructions (v_cvt_f32_f64, v_add_f64 sums, the
makeDouble overload name and flag), a first half of a paired interpolation
read as data, sooner eviction of idle textures and caches under memory
pressure, a retried DirectStorage destination write, the texture catch-up
budget, VICTORY_FIRSTLANE_OWN, and zlib-rs in place of miniz_oxide.

Left out: the fork's personal launcher scripts and its readme.
…e commit)

Every host view heap ends at a null slot that view indices past the heap
read (a host that takes large heaps gets 2^21 views; one that caps them
keeps the capped heap), the cache key includes that limit, and
v_permlane16/x16 are lowered.

Both forks lower v_cvt_f32_f64. The IEEE form with its test is the one in
use; this branch's flush-to-zero form is kept beside it, unused, and its
test is ignored until the console's float mode for the instruction is
checked.
…acters' skin and hair without colour in most launches)

A texture a shader picks by index was uploaded once, when the title wrote
its view, and again only if the view was rewritten or the runtime told of
a remap. The title often fills the texture's memory only afterwards (its
streaming reads land later), so the host copy kept what the memory held at
the first look for the rest of the run: zeros. Which textures lost that
race changed from launch to launch; the main character's face came out
black and her hair pale in about three launches of four.

Now a texture uploaded whole is looked at again after 4, 12, 40, 120 and
400 frames (a fingerprint of 48 KiB of its memory); a changed one is
uploaded again and the looks start over. One test launch re-uploaded more
than 6,000 textures this way. VICTORY_HEAP_RECHECK=0 turns it off.

Known gap: the fingerprint samples the start, middle and end of the
memory, so a texture whose other parts arrive later is still missed.
… are on the card before the character bake; one host copy per placed texture

- The depth bounds test (PastiiJay#82 by Kaivyyy, as is): a pipeline that enables
  it is made from a DEPTH_STENCIL1 stream under its own library name, and
  the title's OMSetDepthBounds reaches the host list. Before, such draws
  passed at every depth. On the test machine (RTX 4070) the first room is
  lit by its lamp for the first time: walls, table, bunks.
- Defaults: what shaders wrote is copied back by a thread of its own
  (stage 2), wide copy-back, card copies from 1 MiB up to 1,024 MB, and
  256 lists in the air. About 230 ms a frame where it was about 400.
  Off: VICTORY_RELAY=0, VICTORY_WIDE_BACK=0, VICTORY_CARD_BUFFERS_MIN_MB=16
  VICTORY_CARD_BUFFERS_MB=512, VICTORY_LATE_WAIT_LISTS=128.
- Textures picked by index are uploaded while loading and before a draw of
  the title's decoration bake, which samples them by index and runs once
  (VICTORY_EARLY_TEXTURES_MS, VICTORY_BAKE_TEXTURES_MS; 0 turns each off).
- Placed textures are keyed without the filler words of their description:
  two views that differed only there each had a host copy
  (VICTORY_PLACED_FILLER=1 keeps the old key).
- VICTORY_TEXTURE_ROOM_PERCENT (90, unchanged) sets how full the card may
  get before textures picked by index wait.

Known: the first room's walls are still missing in some launches, and
shaded areas are too dark (the bounce light has no ray-tracing structure
to trace yet).
…freshed when the card is full

Two fixes for textures that shaders pick by index, both proven with a
slot listing before they were made:

- The title keeps only a texture's small levels and places the next
  texture in the address range of the absent large ones. Described at full
  size every neighbour overlapped, and each view written took the textures
  beside it out of the upload queue and made their host slots null (tens
  of thousands of slots a run). A newer view now makes an older one stale
  only when it starts within that one's first 4 KiB.
  VICTORY_STALE_TEXTURES=overlap: the old rule; =0: never. Unit tests on
  the span table alone. The first room is lit with its walls and the
  characters' textures in the first launch with it.
- With the card at its limit, a texture that already has its host copy is
  uploaded again when the title changed its memory (it took no new card
  memory, and was refused all the same).
  VICTORY_REUPLOAD_WHEN_FULL=0: as before.

Logging only, off unless asked for: both video memory groups and budget
moves; card accounting (VICTORY_CARD_ACCOUNTING=1); the slots a listed
draw's shaders read, with their state (VICTORY_LIST_SLOTS=); a trace for
the missing first-room walls (VICTORY_WALLS_TRACE=1 or 2). A card test of
what a bare command costs (ignored by default):
cargo test -p victory-gpu --release -- --ignored bare_command_cost --nocapture

Known: about 3 to 5 frames a second; more than half of the texture memory
on the card is held for levels the title has not loaded yet (next).
…rites counted; levels on demand (off); warm-up; card memory numbers

Memory sync:
- The guard over every view of a physical page (code by myokex, victory-amd
  c6dc4d8, after pull request PastiiJay#115 by Spexivus, its correction by joroyt and
  a part of VIctory #1122 by tightfall): the title shows one page at several
  addresses and a copy was guarded at one only. 0.8 to 1.0 million writes
  through another view in a five-minute run on the test machine.
  VICTORY_VIEW_GUARD=0 turns it off.
- Kernel reads into title memory are read beside and copied in (Joshua Odom,
  10ea38e).
- Writes of the storage layer into physical pages are counted where the
  title has the pages mapped and can open the guards there
  (VICTORY_PAGE_WRITES, off: counted only). Failed page-destination reads
  are retried.

Card memory:
- Levels on demand, off unless VICTORY_LEVELS_ON_DEMAND=1: a texture the
  title fills takes card memory for the levels the title holds; held levels
  get memory only while the card has room and are asked for again. Its test
  runs on the software adapter; not run on a card yet.
- Refused texture slots are held back so a pass reaches the slots behind
  them; room can be kept for card copies of title buffers (off).

Tools: translate --warm all; the shader cache is keyed on the translator's
source; counters for copy-back races, page writes and the copies the
texture sweep never lets go; a walls trace.

Game runs of these changes on an RTX 4070: five five-minute runs without a
device loss or a failed request. This merged tree was built; its test
suites were run on the tree the changes come from (gpu 129, hle 97).
…ored, views off their copy's elements get their own bytes, card room for the first world frame, levels on demand run on the card

- Descriptor records the title copies into its heap as bytes are mirrored
  before each submission (pull request #305 by Flyander, after upstream
  VIctory 86a5ed6), with a per-slot fingerprint so only records that
  changed are mirrored, the page read through the kernel, a switch
  (VICTORY_HEAP_SYNC=0) and a counter: about 40,000 records a frame on the
  test machine.
- A buffer view off its copy's elements gets a copy of its own bytes
  (after upstream 86a5ed6; VICTORY_VIEW_OWN_COPY=0: refused as before).
- Room on the card for the world's first-frame bursts: buffer copies
  (VICTORY_CARD_ROOM_FOR_BUFFERS, now on) and render targets
  (VICTORY_CARD_ROOM_FOR_TARGETS_MB, 3,072); a copy turned down gives its
  room up and is logged; the texture pass asks again every 32 MiB. 98
  buffer copies made (945 MB) where earlier runs made 1; 25 MB compared
  on the processor a frame where it was 550 to 710.
- Levels on demand: the fixes of pull request #747 by AscilCH. First run
  on a card (RTX 4070, VICTORY_LEVELS_ON_DEMAND=1): no device loss, 3.1 GB
  not allocated for levels the title does not hold. Still off by default.
- The guarded blocks under storage writes into physical pages are opened
  by default (VICTORY_PAGE_WRITES=0: counted only).
- Shaders: a program is translated with first-half interpolation pairs
  only if it was refused for one (with it on for every program 8,551
  working pixel programs came out changed); parked lane-mask pairs,
  f64 conversions and sums, lane permutations: 14 more programs translate.
- Counted, not fixed: an indirect compute pass asks for about 77,500
  groups in x and is cut to 65,535.

One five-minute game run of these changes on the test machine: no device
loss, no failed request. This merged tree was built; its test suites
were not run.
…c, draw-table slots left to their draws, no failing write-watch calls; card fetches inside their flights (off by default)

- Descriptor sync: a multiply-and-fold fingerprint of a record in place of
  BLAKE3 (35 to 42 ms a frame over 250,000 to 300,000 records), and slots
  that draws read through tables lately are left to their draws
  (VICTORY_HEAP_SYNC_TABLES=1 mirrors them too): the pass over the heap
  went from 70-220 ms a frame to about 3.
- Write watch: no kernel asking for memory the guards already hold as view
  memory (pull request #670 by Jonirulah).
- Card copies' flagged pieces can come down inside their own flights
  (pull request #648 by Jonirulah; VICTORY_CARD_FETCH_INFLIGHT=1, off by
  default). One game run with it on: no device loss, the copy-back
  thread's fetch wait 181 -> 0 ms a frame, the card busier; no frame-time
  gain claimed.
- Logging: the heap pass's texture part and buffer slots; indirect compute
  dispatches over 65,535 groups.
- README: what was measured, and that pull request #220 with
  VICTORY_INDIRECT_WINDOW=1 lost the device twice here and is not in.

One five-minute game run of this tree's source on an RTX 4070: no device
loss; the frame is still 250 to 380 ms (the card is the limit). This
merged tree was built; its test suites were not run.
…ompile never ends (39f0e9aeb156a61c, override with VICTORY_SKIP_PIPELINES)
…ke each half wave as a console wave

On a host that may run pixel programs in waves of 64 (AMD), ballots, v_mbcnt,
first-lane and computed lane reads of a console wave32 program are taken per
32-lane half: the upper half no longer sees the lower half's mask.
VICTORY_PS_HALVES=0 turns it off. VICTORY_HOST_WAVE=32 translates compute
programs as for a 32-lane host.
…rm-mode ftz)

The console's MODE and NVIDIA flush them; a host left to "any" (AMD) kept
them, so legacy 0*x tests and reciprocals saw tiny numbers instead of 0.
VICTORY_DENORM=any (or preserve) leaves the mode to the host; part of the
shader cache fingerprint.
…e hosts; denormal flush only on request

Whole-wave sums, minimums, maximums, bit reductions and sum prefixes of a
console wave32 pixel or vertex program run as two host reductions, one per
32-lane half, like its ballots. fp32-denorm-mode ftz drew a triangle-edge
pattern on AMD: it is now left to the host unless VICTORY_DENORM names a mode.
A float a pixel program exports to a colour target gets NaN as 0 and an
infinity as +-65504; typed image and buffer stores get the same for the NaN
the GPU makes (0x7FC00000) and infinities, so integer bits pass. One bad pixel
no longer stays in a history blended into every frame. VICTORY_NAN_GUARD=0
turns it off; part of the shader cache fingerprint.
…dwords; AMD orders a shared-dword i64 compare wrong)
…_TEXTURE_QUEUE_MB/MS), defaults 1024 MB / 1000 ms
…they touch, not all title memory (fxceless/victory-fork PastiiJay#95; VICTORY_MAPPING_RANGES=0 restores the global lock)
PastiiJay and others added 4 commits November 25, 2026 20:56
Replace the coarse read-plus-write refusal in divergent `!all` regions with
static LDS alias and hazard analysis (`emit/lds.rs`) when lowering Wave64
compute shaders to 32-lane host waves:
- Refinement A (disjoint byte ranges on a shared group-uniform base,
  non-wrapping bounds, zero RMW self-overlap, zero RAW/WAR/WAW overlap,
  acyclic `!all` regions only).
- Refinement B (lane-private per-thread slots injective across active group
  dimensions with alignment and cross-cluster footprint disjointness,
  supporting returning atomics and cyclic `!all` regions).
- Conservative refusal for unknown DS ops, `s_barrier` inside `!all`
  regions, non-uniform scalar CFG/SOP/SMEM sources (including non-inline
  SOP special constants, `scratch_wave_offset`/uninitialized SGPRs, and
  multi-write VALU carry-out outputs), shift/wrap overflow, half-only
  `v_mbcnt`, and shared WAW cycles.
- Add unit soundness coverage in `emit/lds.rs` and hardware D3D12 Wave32
  execution tests in `emit/wave64_tests.rs`.
@PastiiJay

Copy link
Copy Markdown
Owner

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-shader suite 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

Copy link
Copy Markdown
Contributor

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 by lds passed in both builds. On Linux, the shader library suite passed 189 tests, with two ignored. Windows validation log for both revisions

One 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

Copy link
Copy Markdown
Owner

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

Copy link
Copy Markdown

Tested this PR on an RTX 4080 16 GB / Windows 10 in GTA 6 (--console series-s, 10-minute runs, integrated alongside VICTORY_LDS_FLAGS / lds_flag_region inside lds::meetings):

Results

  • Unit tests: 21/21 lds + wave64_tests pass cleanly.
  • Real GTA 6 shader refusal regression on NVIDIA (6 → 10 refused compute pipelines, 0x80070057):
    • Baseline (lds_meetings + VICTORY_LDS_FLAGS, 6 refused):
      2da4beb386509b77, 369cbe906ea72764, 02384a60fda6f2d0, 6b82bc7d22016cb5, 5dc3b25986622949, 6f225b641c5b0708
    • With #50 (10 refused — same 6 PLUS 4 newly refused):
      • 89d08e561897d4e5 (one of the character skinning passes noted in card_steps.rs!)
      • 55679a0547649d0b (another skinning pass noted in card_steps.rs!)
      • 1f1fbd86759b3da2
      • caf96a3229145fa6

Root Cause

In lds.rs (else if writes[r] && !has_rmw[r]), the stricter has_provable_shared_waw / region_has_cycle write-only check refuses write-only branched LDS regions that upstream lds_meetings previously allowed in Wave32 (upstream explicitly carried shortcut: 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 to WaveSize(64), causing CreateComputePipelineState to fail with E_INVALIDARG and 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

Copy link
Copy Markdown
Owner

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

Copy link
Copy Markdown

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 both reads[r] = true and writes[r] = true (plus has_rmw[r] = true) for Kind::Rmw (LDS atomics).
  • Upstream lds_meetings only set reads[r] = true on name.starts_with("ds_read") — any non-ds_read LDS instruction (including atomics) only set writes[r] = true.
  • Because those 4 shaders have LDS atomics with no ds_read* in the !all region, reads[r] && writes[r] became true and skipped the write-only branch entirely.

Verified fix

Track has_plain_read: Vec<bool> (set only when kind == Kind::Read), and when opt-in VICTORY_LDS_WRITE_ONLY_OK=1 is active on 32-lane hosts, accept reads[r] && writes[r] when !has_plain_read[r] (and keep the relaxed write-only branch):

  • Unit tests (default / env unset): all 21/21 emit::lds::tests still pass unchanged (including atomics_are_rmw_and_require_lane_privacy).
  • Live RTX 4080 verification (Pass 10, currently running): all 4 shaders translated and bound cleanly as Wave32 host pipelines:
    • 89d08e561897d4e5 — passed
    • 55679a0547649d0b — passed
    • 1f1fbd86759b3da2 — passed
    • caf96a3229145fa6 — passed

@HandshakeHackin

Copy link
Copy Markdown
Contributor

On 0948a4f, VICTORY_WAVE_WHY=1 prints “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

Copy link
Copy Markdown
Author

Thank you @Proudnoob4, @HandshakeHackin, and @PastiiJay for the live hardware testing, root-cause isolation, and diagnostic checks! Pushed follow-up commit 4fa24ff addressing both findings:

  1. 32-lane opt-in VICTORY_LDS_WRITE_ONLY_OK=1 + has_plain_read (emit/lds.rs):

    • record_kind() now tracks has_plain_read strictly on Kind::Read (ds_read*), separate from Kind::Rmw (LDS atomics).
    • Added lds_write_only_ok(), gated strictly on host_max_wave() == 32 and VICTORY_LDS_WRITE_ONLY_OK=1 (always off by default and always disabled on 64-lane hosts).
    • When active on 32-lane hosts, !all regions with no plain ds_read* (write-only non-RMW regions and shared/unproven LDS atomics without a plain LDS read, matching the 4 newly refused compute shaders @Proudnoob4 verified on RTX 4080) are accepted for Wave32. Divergent s_barrier, unhandled DS ops (ds_nop, GDS, etc.), and mixed regions with an explicit plain ds_read* (has_plain_read == true) remain refused. Default behavior when unset is unchanged.
  2. Specific VICTORY_WAVE_WHY=1 refusal diagnostics (emit/lds.rs, emit/lower.rs):

    • Replaced the single generic "an LDS read and write in one lane-branch region" message with typed lds::Refusal variants returned by lds::analyze(...) and reused directly by log_wave64_why (no redundant analysis pass):
      • Write/write overlap: "overlapping LDS writes in one lane-branch region"
      • Atomic with no plain LDS read: "an LDS atomic with no plain LDS read in one lane-branch region"
      • Mixed region with explicit plain ds_read*: "an LDS read and write in one lane-branch region"
      • Divergent barrier / unhandled DS op / cyclic shared write each report their own specific reason.
  3. Verification:

    • Added unit tests covering shared atomics with/without plain ds_read* (default vs VICTORY_LDS_WRITE_ONLY_OK=1 on 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), negative s_barrier/ds_nop checks under the flag, and exact VICTORY_WAVE_WHY reason 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

Copy link
Copy Markdown
Owner

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=1 in game on our Radeon as well.

@PastiiJay

Copy link
Copy Markdown
Owner

@Vladimir-Human, data from @seth1295 on an RTX 2080, head of this PR with VICTORY_WAVE_WHY=1 but without the opt-in (logs in #65, shader hashes redacted): 11 compute pipelines refused with 0x80070057, 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 with mask as data, v_mbcnt or v_readlane. He will rerun with VICTORY_LDS_WRITE_ONLY_OK=1 and unredacted hashes after the weekend.

@Vladimir-Human

Copy link
Copy Markdown
Author

Thanks @PastiiJay and @seth1295 — that 11 vs 7 delta without VICTORY_LDS_WRITE_ONLY_OK=1 matches the stricter default in 4fa24ff: beta only refused regions with both a plain ds_read* and a write, whereas AtomicWithoutPlainRead now conservatively catches unguarded LDS atomics with no plain ds_read* until proven lane-private or opted in.
Rerunning with VICTORY_LDS_WRITE_ONLY_OK=1 and unredacted hashes after the weekend will cleanly isolate those cases from genuine ReadWriteOverlap hazards.

@PastiiJay

Copy link
Copy Markdown
Owner

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 AtomicWithoutPlainRead cases can be sorted one by one.

…ivate

Compare the already-computed half-open footprint bounds (`a.min_lo < b.max_hi && b.min_lo < a.max_hi`) directly across clusters instead of passing `max_hi - min_lo` into `ranges_may_overlap`, while preserving the existing `align4` guard for `>= 4`-byte widths.

`ranges_may_overlap` expects single-instruction widths and rounds non-4-multiple widths (such as `n = 33..63` partial-workgroup byte writes) down to a multiple of 4 on the aligned path, dropping trailing bytes and accepting cross-lane aliases.

Add regression tests covering:
- partial-workgroup byte aliases at `n = 33` and `n = 63` (unit + end-to-end lowering) plus `n = 32` / `64` and disjoint controls;
- bounded exhaustive byte-access oracle (`n = 32..=65`, `stride in [1, 2, 4]`, `initial in 0..4`, `r in 0..=n*stride+4`; 48,212 cases, 0 false accepts).
@Vladimir-Human

Copy link
Copy Markdown
Author

Pushed soundness fix a6883bf for cross-cluster footprint overlap in crates/victory-shader/src/emit/lds.rs (region_lane_private):

  1. Fix: Replaced the cross-cluster 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 like 33 (n = 33..63 partial-workgroup byte writes) into ranges_may_overlap rounded the upper bound down to a multiple of 4 on the aligned path and dropped trailing bytes, allowing cross-lane byte aliasing.
  2. Regression tests (emit/lds.rs):
    • partial_workgroup_byte_alias_is_refused: tests threads = [n, 1, 1] for n in [32, 33, 63, 64] (unit + end-to-end lowering for n = 33, 63) and disjoint off = n controls.
    • exhaustive_byte_access_oracle_has_zero_false_accepts: checks n = 32..=65, stride in [1, 2, 4], initial in 0..4, r in 0..=n*stride+4 (48,212 cases, 0 false accepts).
  3. Verification (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 17 emit::lds::tests::* and 4 emit::wave64_tests::lds_* tests passing).

@PastiiJay

Copy link
Copy Markdown
Owner

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?

@Vladimir-Human

Copy link
Copy Markdown
Author

Thanks @PastiiJay! Verified a6883bf still merges cleanly against current beta (6cce57e), and I will rebase promptly if the next beta batch introduces any conflict.

@PastiiJay

Copy link
Copy Markdown
Owner

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?

@PastiiJay

Copy link
Copy Markdown
Owner

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.

@PastiiJay
PastiiJay changed the base branch from beta to main November 28, 2026 11:05
Vladimir-Human pushed a commit to Vladimir-Human/klbf-lab that referenced this pull request Nov 28, 2026
Guard texture and XMA offsets against overflow
@Vladimir-Human

Copy link
Copy Markdown
Author

Superseded by #183 targeting stable-amd (v26.11.6): #183

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants