Water and Light Probe Shader Fix (Wave32 LDS Safety Proofs) #1773
No reviewers
Labels
No labels
AMD
audio
bug
confirmed
crash
cutscene
dlss
documentation
duplicate
enhancement
fixed-on-main
frame-generation
good first issue
help wanted
input
INTEL
invalid
lighting
linux-proton
memory
needs-info
needs-logs
needs-rebase
NVIDIA
performance
pr-diagnostics
pr-docs
pr-feature
pr-fix
pr-performance
pr-refactor
pr-tests
question
RAYTRACING
rendering
report
series-s
shaders
spam
startup
upstream
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/trustno1-coder--VIctory-NVIDIA!1773
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1773"
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?
@Remorce on GitHub · 2026-11-29 00:03 UTC · original
Remorce:fix/wave32-lds-safety-proofs→main· +469 −11 · 1 files · 1 commits · merged 2026-11-30 14:12 UTCFollow-up to #43. On NVIDIA (32-lane waves), #43 requires proof that a wave64 program's LDS accesses are safe before splitting it across two 32-lane host waves. The water classification and light-probe variance filter shaders use safe patterns the analysis couldn't prove yet. On current main they translate only through a last-resort fallback: the wave-wide form, or failing that the write-only shortcut from before #43. This adds three proofs to #43's analysis that cover those patterns. With them, both shaders are lowered by exact proof in the normal split form and no longer go through the wave-wide fallback or the write-only shortcut. Every other shader's output is unchanged.
Summary
emit/lds.rs:VICTORY_LDS_WRITE_ONLY_OKis untouched.Details
Values made under the write's own lane mask
eval_valtreats any guarded definition as unknown. Sov_mov v11, 0; v_mov v14, 1; ds_write_b32 v11, v14 offset:4under onev_cmpxmask leaves the address and data unknown, and the region is "unproven".A guarded definition now counts as known when every lane of the LDS instruction holds its guard. This is checked with
Bools::meet, which answers "may meet" when it runs out of budget, so the check fails safe. The eval memo is keyed by the lanes looked at.One constant per dword
Take a write-only region where every write puts a known constant at a constant address, with the same constant wherever two writes meet. It ends with the same bytes in any order of the two host halves, however often a loop repeats it, and nothing in the region reads those bytes. Such a region is now accepted even when it contains a loop. This is the "any lane sets the flag" idiom in
CS_Classification_Water.Loop counters stepping by the group
CS_VarianceFilterAlphaloads a tile into LDS withi = tid; while (...) { lds[(i << 2) + 0] = ...; lds[(i << 2) + 1280] = ...; i += 64 }.The proof: for a counter that starts at the thread's linear index and steps by a multiple of the group size
n(a power of two), threadt's counter staystmodulon. With addresses of the form(counter << s) + off, takem = n << s. If eachoff % mand width fit in one slot, threadtonly touches bytes[t << s, (t + 1) << s)modulom, in every pass.mdivides 2^32.The shader rebuilds
ifrom three bit fields before shifting it. The counter's bits are followed through shifts, masks,v_bfe_u32and ORs of disjoint bits, so that reshuffle resolves toi << 2.What stays refused
In
InstanceCulling:CS_Tree_BatchCull*andvfx_proj_decal_vbuffer:CS_ProjDecalReduceClassification_Scalarized, one lane-divergent region covers most of the program. It has an LDS atomic early on and a read of the same address later, with nowhere to put a barrier. One half can read before the other half's atomics land. That looks like a real hazard rather than a gap in the proof, so they stay refused by default.Results
Retail shaders,
victory translate <game dir> --listwithVICTORY_HOST_WAVE=32, from nick0451's run with this PR merged onto maind148613.Now lowered by proof, no longer through the wave-wide or write-only fallback:
water_shading:CS_Classification_Water(0e366d15868e17bd)indirect_light_probes:CS_VarianceFilterAlpha(5964b734c70b91eb)Take an earlier, exact form:
sr_tracing:CS_Tiling_Generate_Waterand_Alpha: from local waves (APPROXIMATE) to local waves (idiom).water_shading:CS_VolumePortalTiling_Generate: from the "without skips" retry to "without early-outs".TAA2:CS_TAA2_PrepareFrameStats: accepted as lane-private, the same loop pattern as the light probes.Unchanged: the other 2,669 programs' emitted output, byte-for-byte.
Validation: every emitted compute program passes
dxil.dll's validator. In game (RTX 3090, balcony save over open water), both shaders are translated and bound, the same 4 shaders are refused with and without this PR, and frame rate and visuals match.Tests
Three new tests in
emit::lds::tests, each with cases that must be accepted and cases that must be refused. All three accept cases fail on current main.cargo test -p victory-shader --libpasses (351), and clippy is clean for the change.@steven-seagull27 on GitHub · 2026-11-29 00:50 UTC · original
Independent synthetic verification on Windows 11 x64, NVIDIA GeForce RTX 5080 (32-lane waves), Rust 1.98.1 MSVC, exact PR head
82221d1:cargo test -p victory-shader --lib --locked emit::lds::tests -- --nocapture --test-threads=1: 24 passed, 0 failed (all 3 new safety-proof tests pass:a_write_under_its_own_lane_mask_reads_the_constants_made_under_it,the_same_constant_written_in_a_lane_loop_is_accepted_and_two_constants_are_not, anda_loop_counter_stepping_by_the_group_keeps_each_thread_in_its_own_slots).cargo test -p victory-shader --lib --locked -- --test-threads=1(skipping pre-existing NVIDIAheap_direct_texture_reads_mark_their_heap_index): 351 passed, 0 failed, 8 ignored.main(f9dfb76) with zero conflicts and zero compiler warnings inlds.rs.AI-assisted. Synthetic tests only.
@NotADonky43 on GitHub · 2026-11-29 01:43 UTC · original
RTX 5070 Ti / Windows / Series X: cherry-picked #1773 alone onto
f9dfb76fand ran its LDS analysis tests (24 passed). Took the 12 distinct compute shaders that an actual warmed opening on f9 logged as refusing Wave32 translation. With the blanket LDS fallback left off, the patch recovered 1 of these 12 in offline translation. Then compared the corresponding 12 recorded PSO recipes in isolated caches with the same adapter, profile, sampler ordering and quarantine: stock 0/12 host pipelines made; with #1773 1/12. No worker crashed. This goes one step beyond translation success; it is not a shader-output parity, gameplay FPS or visual claim. The earlier 12 are runtime refusal samples, not the entire shader corpus. No title files or raw logs attached. Newer NVIDIA main has subsequently changed wave lowering; these numbers apply to f9.@nick0451 on GitHub · 2026-11-29 02:46 UTC · original
Tested against current main, where things have moved since this PR was opened. RTX 3090 (32-lane), Windows 11, this PR merged onto main
d148613.victory translate <game dir> --listwithVICTORY_HOST_WAVE=32, main against this PR, every shader compared by output hash: of 2,675 shaders, exactly 6 differ, the ones the PR names. Every other output is byte-identical, as claimed.d148613water_shading:CS_Classification_Water0e366d15868e17bd4418d484…4cc19109…indirect_light_probes:CS_VarianceFilterAlpha5964b734c70b91ebe40ec28c…88bc2d9b…sr_tracing:CS_Tiling_Generate_Water/_Alphawater_shading:CS_VolumePortalTiling_GenerateTAA2:CS_TAA2_PrepareFrameStatsNote: on current main the two headline shaders already translate. They're no longer refused, presumably through main's newer wave64 fallbacks (
9bba2a2wave-wide form,3302735). So against today's main, this PR changes how those 6 are lowered (by its proofs, not the fallback) rather than bringing back dropped draws.In game (balcony save, looking at open water, 2 rounds each after a warm-up): both shaders are translated and bound in both builds, with 4 refused shaders in both, the same set. 25.0 fps against main's 25.6 (inside the 2-3% noise). The water and sky look the same by eye in the screenshots. No crash.
🤖 Generated with Claude Code
@Melow-code on GitHub · 2026-11-29 04:59 UTC · original · reviewed
Read the proofs and ran them on Linux,
82221d1merged onto main568c5e5d. One finding, in analysis time. I found no accepted program that is unsafe.Finding:
counter_bitstakes exponential time on a shared DAG (emit/lds.rs, thev_or_b32andv_or3_b32arms). It is not memoized, unlikeeval_val, and eachv_or_b32evaluates both operands. An OR of all-zero bits succeeds, sov_mov_b32 v2, 0then N timesv_or_b32 v2, v2, v2ahead of ads_write_b32makes about 2^N calls;depth > 32does not bound that usefully.run_analyzeon that body, debug build, best of three:568c5e5dA chain from a value that is not zero is refused at the first level, and stays fast (2.3 ms at 20).
shared_dag_eval_val_stays_linear_timeguards the same thing foreval_val. I have no real program with such a chain; it is a synthetic case. The memo I tried is aRefCell<HashMap<(Value, Option<Bool>), Option<(Option<Value>, [u8; 32])>>>aroundcounter_bits, keyed by the value anduse_lanes. The 28emit::ldstests pass with it, three of them mine, and the check below accepts the same number of programs. (It also remembers aNonethat came from the depth limit, which only refuses more.) A test, to sit beside the existing one:The strided proof held against brute force: 20,000 random loops (groups of 32, 64, 96 and 128, in one and two dimensions; one to three shifts, masks and ORs on the counter; random step, start and offsets; accesses of 1, 4, 8 and 16 bytes). 1,222 were accepted. Simulating 24 passes of every thread, none of them lets two threads touch one byte; 16,419 of the 18,778 refused ones do. A step or a start that only some lanes take is refused.
Also:
cargo test -p victory-formats -p victory-shader --lib: 57 and 279 passed (three of them mine), 0 failed.Not run: Windows, any card, the game's shaders. The same-constant and lane-mask proofs were read, not fuzzed.
AI-assisted review (Claude Code).
@steven-seagull27 on GitHub · 2026-11-29 08:26 UTC · original
To help address @Melow-code's
counter_bitsshared-DAG finding, I put together a 1-commit fast-forward patch directly on top of82221d1that you can cherry-pick or fast-forward into this PR:steven-seagull27/VIctory-NVIDIA@fix/1773-counter-bits-memod6f46fdWhat it changes (
crates/victory-shader/src/emit/lds.rs)counter_bits_memo: RefCell<HashMap<(Value, Option<Bool>), Option<CounterBits>>>toAddrCtxalongsidevisiting/hit_cycleguards (mirroringeval_val), memoizingcounter_bitsacrossv_or_b32,v_or3_b32,v_lshl_or_b32, andv_and_or_b32.shared_dag_counter_bits_stays_linear_timecovering 20-level and 40-levelv_or_b32DAGs (including pastdepth > 32) and a 20-levelv_or3_b32DAG.Synthetic before / after timings (debug build, Windows x64)
run_analyze)82221d1(before)d6f46fd(with memo)v_or_b32 v2, v2, v2(2^20 calls)v_or_b32 v2, v2, v2(crossesdepth > 32)v_or3_b32 v2, v2, v2, v2(3^13 calls)v_or3_b32 v2, v2, v2, v2(3^20 calls)Verification
cargo test --locked -p victory-shader --lib -- emit::lds::tests --test-threads=1: 25 passed, 0 failed (0.17 s).cargo clippy --locked -p victory-shader --lib --tests: zero warnings inlds.rs.AI-assisted. Synthetic tests only.
@Melow-code on GitHub · 2026-11-29 12:52 UTC · original
Checked d6f46fd: the finding from my review is fixed.
v_mov_b32 v2, 0, then N timesv_or_b32 v2, v2, v2): 1.3 to 3.7 ms from 8 to 20 levels (debug build, Linux, best of three; 5.8 s at 20 levels on82221d1).cargo test -p victory-shader --lib emit::lds: 29 passed (three of them mine), 0 failed.Read only: the cycle guard. A
Nonefrom the depth limit is remembered too, which can only refuse more.Not run: Windows, any card, the game's shaders.
AI-assisted (Claude Code).
@Remorce on GitHub · 2026-11-29 12:53 UTC · original
@Melow-code @steven-seagull27 I've left the memo out for now, but I'm open to bringing it in and would like your view before this is merged.
My concern is whether this case is realistic for the game. The chain in the test is the same register ORed with itself 20 times, which I wouldn't expect a compiler to emit, and the full retail set (2,675 programs) translates through this PR without stalling. Even if a shader did hit it, the cost would be a one-time translation delay, not wrong output.
Have either of you seen address math in a real shader, from this title or another, that shares values deeply enough for this to matter? If so, I'm glad to bring it in here. If not, I'd lean towards landing it on its own later, next to the
eval_valguard.Apologies if I've misunderstood anything.
@Melow-code on GitHub · 2026-11-29 13:00 UTC · original
@Remorc-e no, I have not seen it in a real shader, from this title or another. I do not have the title's programs, and my case was synthetic, made by reading the code. You read it right: it can only cost translation time, not a wrong result.
With the 2,675 programs translating without a stall, leaving it out here and landing it later next to the
eval_valguard is fine with me. My check of d6f46fd above stands for whenever it is wanted.AI-assisted (Claude Code).
@Lyrnc on GitHub · 2026-11-29 23:23 UTC · original
Hardware check of this PR's pattern on a gfx1036 oracle (native wave64), against the 32-lane result on an RTX 5080 and a Radeon 680M. Hand-written wave64 cases matched in every case. On main those cases only translated through the folded form; with this PR they go to the plain split. Rebased onto current main together with the other LDS proof PR, the
ldstests pass (51), and so does the full victory-shader lib apart from 3 failures that main has too.#3441 is built on this PR and #2358/#1773 (the two conflict with each other; the resolution is in #3441). It adds two more proofs and takes the refused/folded count from 181 (main) via 162 (this pair) to 139.
AI use: Claude Code (Claude Opus 5.5).