Skip to content

wave64: halve programs whose every LDS access names only its own lane's words - #158

Open
Koro4e wants to merge 2 commits into
fxceless:mainfrom
Koro4e:wave64-lds-private
Open

Koro4e wants to merge 2 commits into
fxceless:mainfrom
Koro4e:wave64-lds-private

Conversation

@Koro4e

@Koro4e Koro4e commented Nov 24, 2026

Copy link
Copy Markdown

What

Adds an analysis (lds_lane_private) that lets a console wave64 program run in host waves of 32 even when the group is over 32 threads and LDS is in play — provided every LDS access's address derives only from per-lane values (the entry VGPRs, i.e. the thread id) plus uniforms and constants, and never from memory or another lane's LDS word. Such accesses need no ordering between the host waves: each console lane touches only the words its own address names.

Wired into the halving decision next to lds_ok/lds_meetings. VICTORY_WAVE_LDS_ASSUME=1 force-enables it for programs the analysis cannot follow (quarantine keeps a wrong guess contained).

Why

Programs with a group over 32 and LDS otherwise stay at WaveSize 64, which a 32-lane host refuses — on NVIDIA these pipelines never come up.

Measured

  • Offline, over 1 163 dumped compute programs: 37 more programs now emit WaveSize 32 than did before (probe: wave_why; verified with dxc -dumpbin on the emitted container).
  • Live, in one session on an RTX 3060: 20+ programs took the new path at runtime (logged as WAVE64-LDS-PRIVATE), where they would have been refused before.

The four structure-builder programs are not among them — their LDS is genuinely shared across the console wave (a lane writes a flag at a fixed word, the rest read it) inside divergent regions, so they still need the full treatment. Notes on that, and on everything above, are in docs/wave64-notes.md.

Probes added

  • lds_dump — decodes a dumped console shader and prints every LDS access with the address computation.
  • validate_dump — validates dumped containers with dxil.dll.
  • wave_why — explains why a program keeps 64-lane waves.

No game data of any kind is included — the probes take a file path at runtime.

@ericomeehan

Copy link
Copy Markdown

Thanks for going after the wave64 LDS refusals: they are one of the clearest blockers on 32-lane cards, and wave_why/lds_dump look useful.

One concern with lds_lane_private as it stands (from reading the diff; I haven't run it): it accepts an address if it depends on the thread id at all (taint & 1 != 0), which doesn't yet show that each lane touches only its own words. For example (tid ^ 32) * 4, (tid + 32) * 4 or (tid & 31) * 4 all pass, and each makes a lane read or write a word owned by a lane in the other 32-lane half. On the console those lanes run in lockstep and need no barrier; split into two host waves they race, and the result is silently wrong LDS data rather than a fault. Wave-synchronous LDS reductions have exactly this shape. Because taint ORs its bits, offset_loaded_from_memory + tid also passes (bits 1|4).

A tighter rule could accept only uniform + tid * k with k at least the access size, the same form for every access, and no unknown bit. With that, and the path behind an off-by-default VICTORY_* switch (keyed into the shader cache, as #98 does for VICTORY_PORTABLE_HEAP), it would be much easier to trust. Two small things: the new function sits between lds_meetings and its doc comment, so that comment now documents lds_lane_private; and the eprintln!s could be tracing.

Written with an AI assistant (Claude).

@m335671

m335671 commented Nov 24, 2026

Copy link
Copy Markdown

Test on an RTX 4070 (32-lane waves): this PR makes the driver create one of the compute pipelines that every 32-lane NVIDIA run refuses, 2da4beb386509b77, and changes nothing else in the pack.

Tested

Not tested: that run only reached the profile screen: my scripted presses didn't get past it, and the pipeline was made by the early-start warm-up. So I have not seen this program dispatched in the world, or its output. Other GPUs not tested either.

AI use: the runs were done on my machine. Claude Code (Claude Opus 5.5) built and ran them, compared the outputs and wrote this comment.

@FrancescoGelosoEterea

Copy link
Copy Markdown

Tested on NVIDIA (32-lane host): this brings up one of the wave64 compute pipelines that this card refused (#7, #11).

Setup: RTX 5070 Ti, driver 621.24, Windows 11, Ryzen 7 9800X3D. Own 1.0.2.1 copy, Series X profile, diagnostics build: 4e17478 + #51 + 15 other open PRs, then #95, #220, this PR (3478875), #187, #234 and #141. The same run script was used before and after, with no VICTORY_WAVE_LDS_ASSUME.

compute pipeline before with this PR
2da4beb386509b77 refused (E_INVALIDARG), 63 lines created, first bound at frame 2420
02384a60fda6f2d0, 2cc4c197ee29e291, 369cbe906ea72764, 6b82bc7d22016cb5 refused still refused
host pipeline shaders=[compute 2da4beb386509b77]
first bind ... stage="compute" size=4920 hash=2da4beb386509b77

There was no device removal and no crash in a 7-minute run in the world, and the walls and lighting in the prologue room render. The four that are still refused presumably fail the lane-private LDS analysis. If it helps, I can rerun with VICTORY_WAVE_LDS_ASSUME=1 and report whether they come up and render correctly.

The fps numbers are not a clean A/B, because other PRs changed in the same build, so I am leaving them out.

@FrancescoGelosoEterea

Copy link
Copy Markdown

A follow-up on lds_lane_private. I think it can call a shared LDS word "per-lane".

taint follows every register an instruction reads. For a VALU instruction that writes a VGPR, the IR also lists the destination's old value among its reads, for the lanes outside EXEC that keep it. So v_mov_b32 v1, 0 reads the old v1. Every VGPR that is not written yet at entry is a program input, so that read gets taint 1. The constant address 0 then comes out "per-lane", and a word every lane shares runs without the barriers.

I hit it while writing a test: 64 threads, v_mov_b32 v1, 0, then ds_write_b32 v1, … and ds_read_b32 …, v1 in a lane branch. This prints WAVE64-LDS-PRIVATE group=64 lds=128 and lowers to WaveSize(32) with no barriers. Using v9 for the address gives the same result.

A fix that worked for me: in taint, skip a read of a VGPR that the instruction also writes, when it is a whole-dword VALU write and none of its source operands names that register. That excludes DPP, SDWA, mac, lane and 16-bit ops. That read is only the kept value.

let old_only = |reg: Reg| match (&inst.fields, reg) {
    (Fields::Valu(valu), Reg::V(x)) => {
        inst.write(reg).is_some()
            && valu.dpp.is_none()
            && valu.sdwa.is_none()
            && !name.contains("mac")
            && !name.contains("lane")
            && !name.contains("16")
            && !valu.src.iter().any(|op| matches!(*op, Operand::Vector { reg, dwords }
                if (u16::from(reg)..u16::from(reg) + u16::from(dwords.max(1))).contains(&u16::from(x))))
    }
    _ => false,
};
// ... in the loop over inst.reads:
if old_only(reg) { continue; }

With it, 2da4beb386509b77 (CS_AlphTransmissionPrefilterMip) is still created on the RTX 5070 Ti, so the program this PR is for keeps working.

@Koro4e

Koro4e commented Nov 25, 2026

Copy link
Copy Markdown
Author

Thanks @ericomeehan, @m335671 and @FrancescoGelosoEterea — the RTX 4070 and RTX 5070 Ti runs are exactly what this needed: the pipeline this PR brings up on a 32-lane host (2da4beb386509b77, #7, #11) matches what we see on an RTX 3060 12 GB, where it is created and the world runs without a crash in a 7-minute session.

On both review points: taint is gone. You are both right that it could call a shared LDS word "per-lane", and the pushed commit (452ef2d) replaces the taint walk with a strict form rule:

  • every LDS access address must be uniform + c·tid + const, all accesses in one form;
  • c ≥ the largest access size, and the spread of the uniform bases ≤ c, so two lanes — and the two host waves — never touch the same dword;
  • exactly one vector input (the 1D thread id). Any value whose definition is not visible is Unknown, so @FrancescoGelosoEterea your case (the destination's old value read for the lanes outside EXEC, an unwritten VGPR acting as an input) can no longer pass: the rule never looks at taint and never accepts a value it cannot see a definition of;
  • v_lshl_add_u32 joined the supported ops (the real shaders compute base + (index << c) with it), and v_lshlrev_b32 now checks that the constant operand is really the shift;
  • still off by default behind VICTORY_WAVE_LDS_PRIVATE=1, and the switch is part of the shader cache key (upstream's translation fingerprint picks it up from the source now).

Honest numbers, so nobody has to find them out the hard way: an offline scan of the 1,163 dumped compute shaders with the strict rule enabled lets 0 of the 37 programs through that the old taint rule passed. The dumps (lds_dump) show why: the real addresses come from loop-carried bump allocators — v0 = (v1 << 3) + v0, masked with 0x3FFFFFFF — which no per-value form rule can prove private. So the strict rule is sound and currently covers nothing; the next step is a loop-carried analysis (a monotone per-lane index with a bounded window), which is a bigger change and belongs in its own PR rather than in a widening of this one.

Practical effect of this PR as it stands: wave64 compute without LDS — or with LDS the meetings rule already orders — now runs on 32-lane cards; the LDS-heavy programs keep the old path until the loop analysis lands.

1 similar comment
@Koro4e

Koro4e commented Nov 25, 2026

Copy link
Copy Markdown
Author

Thanks @ericomeehan, @m335671 and @FrancescoGelosoEterea — the RTX 4070 and RTX 5070 Ti runs are exactly what this needed: the pipeline this PR brings up on a 32-lane host (2da4beb386509b77, #7, #11) matches what we see on an RTX 3060 12 GB, where it is created and the world runs without a crash in a 7-minute session.

On both review points: taint is gone. You are both right that it could call a shared LDS word "per-lane", and the pushed commit (452ef2d) replaces the taint walk with a strict form rule:

  • every LDS access address must be uniform + c·tid + const, all accesses in one form;
  • c ≥ the largest access size, and the spread of the uniform bases ≤ c, so two lanes — and the two host waves — never touch the same dword;
  • exactly one vector input (the 1D thread id). Any value whose definition is not visible is Unknown, so @FrancescoGelosoEterea your case (the destination's old value read for the lanes outside EXEC, an unwritten VGPR acting as an input) can no longer pass: the rule never looks at taint and never accepts a value it cannot see a definition of;
  • v_lshl_add_u32 joined the supported ops (the real shaders compute base + (index << c) with it), and v_lshlrev_b32 now checks that the constant operand is really the shift;
  • still off by default behind VICTORY_WAVE_LDS_PRIVATE=1, and the switch is part of the shader cache key (upstream's translation fingerprint picks it up from the source now).

Honest numbers, so nobody has to find them out the hard way: an offline scan of the 1,163 dumped compute shaders with the strict rule enabled lets 0 of the 37 programs through that the old taint rule passed. The dumps (lds_dump) show why: the real addresses come from loop-carried bump allocators — v0 = (v1 << 3) + v0, masked with 0x3FFFFFFF — which no per-value form rule can prove private. So the strict rule is sound and currently covers nothing; the next step is a loop-carried analysis (a monotone per-lane index with a bounded window), which is a bigger change and belongs in its own PR rather than in a widening of this one.

Practical effect of this PR as it stands: wave64 compute without LDS — or with LDS the meetings rule already orders — now runs on 32-lane cards; the LDS-heavy programs keep the old path until the loop analysis lands.

@m335671

m335671 commented Nov 25, 2026

Copy link
Copy Markdown

Offline check of 452ef2d on a 32-lane card. With the strict rule, 2da4beb386509b77 is refused again, with or without VICTORY_WAVE_LDS_PRIVATE=1. That fits your scan.

Note: 452ef2d isn't on this PR's branch yet. The PR still shows 3478875 as its head, so I fetched the commit from your fork by its hash.

Tested

  • RTX 4070 12 GB, driver 32.0.16.2124, Windows 11 Pro 26300, release build of 452ef2d as it is, on 4e17478.
  • VICTORY_HOST_MAX_WAVE=32 victory translate --list --pipelines over the title's whole shader pack, once without the switch and once with VICTORY_WAVE_LDS_PRIVATE=1.
refused pipelines 2da4beb386509b77
3478875 (old taint rule, yesterday) 23 created
452ef2d, switch off 24 pipeline: The parameter is incorrect.
452ef2d, VICTORY_WAVE_LDS_PRIVATE=1 24 pipeline: The parameter is incorrect.

The two 452ef2d listings are the same program by program. With the switch on, nothing passes that didn't pass with it off. So as you said, the PR currently brings up nothing on this card, and CS_AlphTransmissionPrefilterMip waits for the loop-carried analysis. I didn't run it in the title, because offline nothing changes.

AI use: Claude Code (Claude Opus 5.5) built and ran the check on my machine, compared the listings and wrote this comment.

@Daolyap

Daolyap commented Nov 25, 2026

Copy link
Copy Markdown

A heads-up from combining this with #592 and #500 on f85101b.

Alone, this PR is the biggest gain of the three: on a 32-lane host (VICTORY_HOST_WAVE=32 VICTORY_WAVE_WHY=1) the corpus goes from 386 compute programs kept at 64 lanes to 354.

But with #592 merged as well, #592's test emit::wave64_tests::a_branch_that_writes_lds_two_different_values_keeps_64_lanes fails (the program comes out at 32 lanes instead of 64). It passes with #592 alone and with #500 + #592, so the change in behaviour comes from this PR. That test's program writes a flag at a constant LDS address in a lane branch, reads it, then writes a second, different value. Splitting that into two host waves lets one wave read the other's write out of order.

From reading lds_lane_private: it takes a program as private when every LDS address has a per-lane taint (t & 1). Two things there may be worth a look:

  • an address whose taint also has the "unknown" bit (t == 5) still passes, though the comment says unknown isn't provable;
  • a per-lane taint doesn't show that each lane touches its own word (tid >> 5 or tid & 0 are per-lane-derived but shared).

I haven't pinned down which path makes the test program split, so treat this as a pointer rather than a diagnosis.

AI-assisted (Claude Code).

e4glevlr added a commit to e4glevlr/victory-fork that referenced this pull request Nov 26, 2026
…haders

2.1 fxceless f5c03f3 (PR fxceless#999), texback.rs: textures of the water
    kinds that shaders write are copied into read-back buffers when the
    list closes and tiled back into title memory once it has run, so
    the CPU's ocean sampling (boats) reads what the GPU wrote. ON by
    default here: VICTORY_TEXTURE_BACK unset or 1 takes the four water
    kinds, 0 turns it off, a list of <w>x<h>f<format> picks others.
    Merged with this tree's in-place write ranges (Deferred::placed):
    flights now carry both their placed ranges and their readback
    ranges.

2.2 fxceless a35c557, VICTORY_TARGET_VARIANTS (on unless =0): a draw
    into a render target whose format differs from what its pipeline
    declares for that slot gets a pipeline of the same state for the
    bound formats. Adapted to this tree's blending: host_blend() still
    turns blending off per format at creation, and
    integer_targets_unblended() now keeps the title's blend state
    (blend_as_given) for variants to start from. RTV records and
    pipeline states both carry stand-in formats (target_format), so
    they compare like for like. fxceless 025b042 (integer targets do
    not blend) was already here as e92dbb4; not ported again.

2.3 Marvisak 842b0cb7 (fxceless#158) not ported: the depth bounds test already
    reaches the host here (c96b4f2, fxceless#82: OMSetDepthBounds, adapter
    check, DEPTH_STENCIL1 for vertex and mesh streams, replay, test).

2.4 fxceless PR fxceless#808: v_dot4_i32_i8 / v_dot4c_i32_i8 / v_dot4_u32_u8 and
    v_dot2* lower to DXIL dot4AddPacked and fmad (emit/dot.rs, listed
    in sources(); Module::eval_u32 for constant operands). Only the
    PR's lowering and its new test were taken; the PR also deleted
    unrelated valu tests (cvt_f32_f64, permlane16), which stay.
    byte_dot_products_match_the_hardware is no longer ignored.

2.5 Shader correctness batch:
    - fxceless PR fxceless#1041: resource::track visits blocks in reverse
      postorder.
    - fxceless PR fxceless#1042: saturating clamp on packed 16-bit integer ops,
      with its tests (its clamp-taking vop3p helper kept; fxceless#808's test
      uses its own vop3p_dot).
    - Marvisak f3578e3 (#2493): f16 inline float constants in
      whole-wave v_add_f16 simulation; its test expects this tree's
      Shape::Active instead of Marvisak's Shape::Half.
    - justr4mzi 6ba165b2 (fxceless fxceless#1030): a ds_swizzle source lane
      outside EXEC reads zero. Restricted to console wave32 compute
      (no exchange, no twin), where the host lane is the console lane;
      the wave64 forms on 32-lane hosts keep the plain read, since a
      host ballot does not see the console's upper 32 lanes.
    - justr4mzi 640262ee (fxceless fxceless#1024): image_get_lod on cubes in
      pixel shaders (lower_image.rs), with its test.
    - justr4mzi a15e95d8 (fxceless fxceless#1019): typed half loads keep NaN
      payloads (widened through a finite half), with its test.
    - Skipped, not in this tree: Marvisak e815cef (#2484, the dirty
      bitmap of its memory view; ours is a page directory of copies),
      366a978 (#2468, no dead_on_edge here), 120233c (#2448, no
      Lower::konst here).
    - Skipped on purpose: justr4mzi 6c9a9032 (fxceless fxceless#1026) makes
      v_mac/v_mad_legacy_f32 fused with flushed sources. Neither
      upstream has merged it, and the semantics reference here and in
      Marvisak/VIctory still takes the legacy multiply-add unfused; it
      is the title's most used arithmetic, so it waits for a hardware
      measurement.

Gate: Windows check, diagnostics check, clippy -D warnings (default and
all features), tests 342 passed / 0 failed / 8 ignored, policy 230 files
ok, viz. The semantics and valu tests (and the new victory-gpu tests)
are Windows-only: built and linted here, not run; pc-home is offline.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

5 participants