Repository navigation
Conversation
…omics in Wave32 regions
…d, and loop counters stepping by the group Three more cases trustno1-coder#43's analysis proves safe on 32-lane hosts: - A value made under a lane guard is known to an LDS instruction whose lanes all hold that guard (checked on the guards with `meet`, which answers no when it gives up). Before, any guarded definition left the address or data unknown, so `v_mov v11, 0; v_mov v14, 1; ds_write_b32 v11, v14` under one mask was "unproven". - A write-only region whose writes put a known constant at a constant address, the same constant wherever two writes meet, is accepted in a loop too: the bytes end the same in any order of the host halves. - A loop counter that starts at the thread's linear index and steps by a multiple of the (power-of-two) group size keeps each thread in its own slots modulo `n << shift`, in every pass, when the addresses are `(counter << shift) + off` with each `off % m` and width inside one slot. The counter's bits are followed through shifts, masks, bit-field extracts and ORs of disjoint bits. On the retail shaders with VICTORY_HOST_WAVE=32: water_shading CS_Classification_Water (0e366d15868e17bd) and indirect_light_probes CS_VarianceFilterAlpha (5964b734c70b91eb) translate again (37 -> 35 without a wave32 lowering), and four that translated take an earlier form (sr_tracing CS_Tiling_Generate_Water/Alpha leave the APPROXIMATE local waves). Every other program's output is unchanged; all emitted compute programs pass dxil.dll's validator. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r the threads that run it Two more proofs for trustno1-coder#1435, on top of trustno1-coder#2358 (commutative atomics) and trustno1-coder#1773 (own-mask values, one constant per dword, strided loop counters), whose commits come first here. - Refinement D: at most one thread of the group runs the region's LDS instructions (`if (tid == 0) { ... }`). One thread is in one host wave and makes its accesses in program order, so whatever it reads or writes, the halves cannot see each other's order. - Refinement E: over the threads that may run each access, no two threads touch one byte where one writes. `if (tid < 16) { lds[28 + 12 t]; lds[220 + 12 t]; }` overlaps over the whole group (thread 16's first slot is thread 0's second) but not over threads 0..15. Which threads may run an LDS instruction: for each thread, the lane compares in its block's reach and its guard whose operands are known per thread (constants and thread ids) take that thread's outcome, constant masks its bit, other atoms stay free (a walk of the decision diagram, with a node budget that answers "may run"). Free atoms only add threads, so both proofs err towards refusing. Groups of more than 1024 threads are not looked at. Not taken, on purpose: a lane-branch region where several lanes of one host half read what other lanes of it wrote with no barrier (a wave reduction under `tid < 32`). The console wave saw those writes in lockstep; the host has no order between its lanes there. That needs a lowering with a wave-level sync, not a proof. Tests: one thread at tid 0, 40 and 63, under a branch and under v_cmpx; two threads refused; an 8 x 8 group column refused; footprints accepted for 16 threads and refused for 17; a read of the next thread's slot refused (across the halves and within one); one or two atomic families in a lane loop (trustno1-coder#2358's proof). The trustno1-coder#1773 commit was cherry-picked onto main with its Access fields merged next to trustno1-coder#2358's (`atomic_alg` beside `data_const`, `strided`, `ds_off`) and both proofs in the read-write check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 29, 2026
Open
This was referenced Nov 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #1435, not all of it. Built on #2358 (nidea1) and #1773 (Remorce): their commits come first here, with their authorship kept. Once both are on main, this branch rebases to the third commit alone.
Rebased onto main 7995b81 (#2358 and #1773 are both still open, so all three commits stay): 80b451e, 8bac5b6 and a5ae292 below are now f0a4374, 934475b and 66da0fe, with the same patches (
git range-diffshows no change). The archive and synthetic measurements below were made on the 829188e base; thecargo testresults are on 66da0fe.What it changes
What was wrong. On a 32-lane host, #43's
lds::analyzelets a wave64 compute program run as two host waves only when it can prove that the program's lane-branch regions need no order between the halves. Without a proof the program falls back to another form. On 829188e the first retry is the folded form. On main since 5c262d7 and 05d1c56, the plain retries and the local-wave idiom run first, and folding comes before the wave-wide and approximate forms. 5c262d7 measured what folded programs cost in card time.On the title's shader archive at 829188e (2,682 compute programs,
VICTORY_HOST_WAVE=32), the analysis refuses 181 programs: 179 are folded and 2 take the wave-wide form. Two common shapes had no proof:if (tid == 0) { ... }), whatever it reads or writes;if (tid < 16) { lds[28 + 12 t] = ...; lds[220 + 12 t] = ...; }overlaps over the whole group, because thread 16's first slot is thread 0's second. It does not overlap over threads 0..15, which are the only threads that run it.These were refused as "an LDS read and write in one lane-branch region" or "unproven LDS writes in one lane-branch region".
What this does. a5ae292 adds two proofs to
crates/victory-shader/src/emit/lds.rs:AddrCtx::one_thread): at most one thread of the group runs the region's LDS instructions, and it is the same thread at each of them. One thread sits in one host wave and makes its accesses in program order, so the halves cannot see each other's order.AddrCtx::thread_footprints): over the threads that may run each access, no two threads touch the same byte where one of them writes. A dword access takes its whole dwords. The check refuses the region when it goes past 65,536 spans, 1,024 open spans or 1 MiB of offset.site_threads,may_hold): the check runs once per thread and looks at the block's reach and the instruction's guard. A lane compare whose operands are known per thread (constants and thread ids) takes that thread's outcome, and a constant mask gives the thread's bit. Any other atom stays free. The decision diagram is walked with a memo and a node budget, and past the budget the answer is "may run". Free atoms can only add threads, so both proofs err towards refusing. Groups of more than 1,024 threads are not looked at.VICTORY_LDS_WRITE_ONLY_OKandVICTORY_LDS_LAST_RESORTare unchanged: the write-only shortcut stays off by default, and the last resort keeps its default list of one program.tid < 32). The console wave saw those writes in lockstep, but the host has no order between its lanes there. That case needs a lowering with a wave-level sync, not a proof, and a test checks that it stays refused.Six tests are added to
emit::lds::tests:v_cmpx;Credit:
git patch-idmatches the PR's diff. It adds Refinement C: commutative non-returning 32-bit integer LDS atomics.Accessfields (data_const,strided,ds_off) merged next to shader: accept purely commutative non-returning 32-bit integer LDS atomics in Wave32 regions #2358'satomic_alg.git range-diffagainst the PR's commit 82221d1 shows only that merge. shader: accept purely commutative non-returning 32-bit integer LDS atomics in Wave32 regions #2358 and Water and Light Probe Shader Fix (Wave32 LDS Safety Proofs) #1773 conflict with each other inlds.rs, and each applies to main on its own. Whichever lands second needs the same small resolution.How it was tested
GPU and profile: no game run. Two kinds of checks were done:
VICTORY_HOST_WAVE=32;Archive, per compute program. The command was
VICTORY_HOST_WAVE=32 VICTORY_WAVE_WHY=1 victory translate --list --jobs 1 <archive>, with a local print (not in this branch) of each program's hash ahead of itsWAVElines. A program counts as refused when aWAVE64-WHY ... lds=trueline is printed. Its form is the lastWAVE64-RETRYline, or the split form when there is none.Before: the 829188e column above.
After, shader: accept purely commutative non-returning 32-bit integer LDS atomics in Wave32 regions #2358 + Water and Light Probe Shader Fix (Wave32 LDS Safety Proofs) #1773: 19 programs are no longer refused by the LDS analysis.
v_mbcnt,v_readlane.--jobs 8run on empty caches.--jobs 8runs,VICTORY_WAVE_WIDE_FALLBACK=0 VICTORY_LDS_LAST_RESORT=0 VICTORY_LDS_WRITE_ONLY_OK=0gives the same listing as the defaults, and no run printsno wave32 lowering.After, a5ae292: this run covered only the 162 programs that shader: accept purely commutative non-returning 32-bit integer LDS atomics in Wave32 regions #2358 + Water and Light Probe Shader Fix (Wave32 LDS Safety Proofs) #1773 still refuse (
VICTORY_TRANSLATE_ONLY, 162 translated, 162 compute programs emitted).All three commits together: 42 programs are no longer refused by the LDS analysis (181 to 139). Of those, 34 leave the folded form.
0e366d15868e17bdand5964b734c70b91ebleave the folded form, both through Water and Light Probe Shader Fix (Wave32 LDS Safety Proofs) #1773. The other 8 are still refused on this branch: 6 for a read and write in one region, 1 for a shared write in a loop, 1 for an atomic-only region.Synthetic cases, against wave64 hardware:
v_cmpxinside a wider branch) and 1 for Refinement E (16 threads with interleaved slots).dxil.dll's validator, and was dispatched on both cards. The 16 outputs x 64 lanes were compared with the same bodies run natively in wave64 on the gfx1036 iGPU through a local harness.cargo test -p victory-shader --lib local_lds1435 -- --ignored --nocapturewithVICTORY_ADAPTER=NVIDIAorRadeon,VICTORY_WAVE_WIDE_FALLBACK=0andVICTORY_WAVE_WHY=1.local_lds1435is a local test module that is not in this branch.WAVE64-RETRY).For shader changes, the wave sizes tested: wave64 console programs on 32-lane host waves (the case this analysis is for), on NVIDIA and AMD. The reference is native wave64 on the AMD iGPU. 64-lane hosts were not run.
cargo testpassed for the crates it touches: yes, apart from 3 tests that fail on main in the same way. On 66da0fe (main 7995b81 + the three commits), RTX 5080:cargo test -p victory-shader --lib lds: 51 passed, 0 failed, 1 ignored (430 filtered out). The 32 tests ofemit::lds::testsare among them.cargo test -p victory-shader --lib -- --test-threads=6: 470 passed, 3 failed, 9 ignored. The 3 failures areemit::barycentric_tests::first_half_values_render_on_hardware_and_warp,emit::rect::tests::rectangles_are_drawn_wholeandemit::rect::tests::the_rectangle_stage_is_a_geometry_shader, all withContainer part 'Pipeline State Validation' does not match expected for modulefrom the local DXIL validator. The same 3 fail the same way on main 7995b81 without this branch.cargo clippy -p victory-shader --all-targets -- -D warnings: fails on main's own code (unused imports inemit/lower/analysis.rs:6andemit/lower.rs:594,while_immutable_conditioninemit/lower/analysis.rs:467,too_many_argumentsinnative.rs:1655). None is inlds.rs.emit::lds::testsand 482#[test]functions in the crate's sources. shader: accept purely commutative non-returning 32-bit integer LDS atomics in Wave32 regions #2358's description reports 23 passed inemit::lds::testsat its head, and steven-seagull27 reported 24 passed at Water and Light Probe Shader Fix (Wave32 LDS Safety Proofs) #1773's head. Neither result covers this branch.Not tested:
cargo testwas). They come from a build of the working tree before the commit, with local debug prints. The commit adds rustfmt formatting, doc comments and the 1,024-open-span bound in the footprint check, which can only refuse more.--listwithout--validate(0 validated). The new DXIL of the 34 programs was emitted but not validated, and no pipeline was made from it. Only the 13 synthetic cases went through the validator and the cards.counter_bitstakes exponential time on a deeply shared OR chain. steven-seagull27's d6f46fd memoises it, and Remorce left it out of Water and Light Probe Shader Fix (Wave32 LDS Safety Proofs) #1773 for now. This branch carries Water and Light Probe Shader Fix (Wave32 LDS Safety Proofs) #1773 as it is. The new walk inmay_holdis memoised and has a node budget.In game: pending. An earlier in-game A/B is void: its build reused a stale victory-shader from a shared target dir. It is being redone and the result will be posted here.
Checked for overlap
829188e9..7995b81btoucheslds.rs, and the three commits apply to 7995b81 unchanged. 5c262d7 and 05d1c56 change when folding runs (fold.rs,emit/mod.rs).git merge-tree --write-tree vnv/mainon this branch is clean at fbe3dc2. Related:VICTORY_LDS_EXACT=1, off by default) #733 (open, conflicting): a separateemit::lds_exactmodule behindVICTORY_LDS_EXACT=1, tried after every other form. It also has a one-thread proof (entry edges onv_cmp_eq(thread id, k), 1-D groups) and a check that read and written ranges do not meet. This branch works inside shader: static Wave32 LDS alias and lane-private hazard analysis #43'slds::analyze, on by default. It handles 1-, 2- and 3-D groups up to 1,024 threads and checks per-thread footprints over the threads that run each access.lds.rs(with_last_resortthroughlower::with_flag), far from these hunks, with no overlap in what it does.emit/mod.rs. It is not an LDS proof, and 05d1c56 has since changed that order.6b82bc7d22016cb5throughlower.rs, which this branch does not take.AI use
Claude Code (Claude Opus 5.5) wrote a5ae292 (Refinements D and E and their tests). It cherry-picked #2358's and #1773's commits with their authorship kept, and merged #1773's
Accessfields next to #2358's. It also wrote the 13 synthetic cases and the local harness, ran the archive counts and the comparisons on both cards, and wrote this description. The first two commits are nidea1's and Remorce's own work.🤖 Generated with Claude Code