Shaders: allow redundant masked v_mov_b32 writes after per-lane descriptor joins (fixes #750) #3298
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3298"
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?
Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-26T16:22:24Z.
Summary
Allows redundant masked
v_mov_b32writes after a per-lane descriptor join when every active lane writes the exact value its register already held (fixes #750).Root Cause
In
crates/victory-shader/src/resource.rs,Tracer::lane_valuecalledTracer::runs(site, known)?on every VGPR copy and rejected any masked write where some lanes inknowncould skipsite, even when the active lanes wrote back the same value they already held from the prior SSA definition (such as aphiarm).Changes
crates/victory-shader/src/resource.rs:Tracer::redundant_mov_priorandTracer::same_under: whenruns(site, known)fails on av_mov_b32, checks whether the prior SSA value of that VGPR in the block agrees with the written value on all active lanes (known + reach + guard). If so,lane_valuecontinues tracing through the prior value so both active and skipping lanes remain consistent.joined_descriptor_redundant_partial_write(from #750) and negative testjoined_descriptor_non_redundant_partial_write_fails.Testing & Verification
joined_descriptor_redundant_partial_writeandjoined_descriptor_non_redundant_partial_write_failsincrates/victory-shader/src/resource.rs.No game files used.
AI-assisted: yes (Gemini 4 Neon)
Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T16:50:48Z.
Review: COMMENTED
Ran local verification on Windows 11 x64 (
origin/main63bcca4merged with this PR):cargo test -p victory-shader --lib resource::tests:: -- --test-threads=1: 36 passed, 1 failed — the newly added testresource::tests::joined_descriptor_redundant_partial_writefails:cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-26T18:24:27Z.
WARP verification of #3298 (synthetic tests only, no game files, no physical GPU).
Result: the PR's new positive test
joined_descriptor_redundant_partial_writefails on the PR head.Commits
e95add4b2f6129935f6b2e4fda0d54292ccb0c1563bcca43c6a00a758510398fa43096ce7e4f7df0Environment
d3d10warp.dll10.0.26100.9818,dxil.dll1.8.2502.11 (Windows SDK 10.0.26100.0 x64)VICTORY_WARP=1,VICTORY_D3D12_WARP=1New tests, head vs control
Control =
63bcca43with only the PR's two tests applied.resource::tests::joined_descriptor_redundant_partial_writeresource::tests::joined_descriptor_non_redundant_partial_write_failsBoth sides fail with the same error at
waterfall(&words, false).unwrap():Unsupported { offset: 264, what: "a per-lane descriptor written where some lanes may keep the old one" }.It is deterministic: it failed on a parallel run and on
--test-threads=1. These tests are pure shader tracing and do not touch the GPU, so WARP is not a factor. As the tests are written here, the PR's change does not make the redundant masked write accepted. The negative test passes both before and after, so it does not show the change.Full
cargo test -p victory-shader --libon head: 299 passed, 5 failed, 3 ignored (307 total, 1955 s).emit::synthetic_tests::*failures that also fail on unmodified63bcca43. They arepermutes_read_the_lane_named_and_zero_from_lanes_left_out,permutes_mask_high_address_bits_and_divergent_branches,gathers_at_a_level_match_the_hardwareanda_mask_joined_with_data_at_a_uniform_loop_is_its_number.Not tested
xtask policy.AI use: Claude Code (Claude Sonnet 5.5)
Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-26T18:46:05Z.
@Marvisak Please review and merge this PR. Testers, kindly run on untested GPU models. AI‑assisted ✅ Gemini‑4 Neon
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T18:59:20Z.
I reproduced the positive test failure on
e95add4before any DXIL or GPU work.8b404f4is a follow-up on that exact head.The redundancy proof needs the incoming branch condition as well as the predecessor’s reach condition. With that condition, the two copies of the integer comparison also need to be recognized as the same per-lane predicate. Their explicit operands agree, while the implicit EXEC SSA value was redefined when EXEC was restored. The follow-up reuses the existing edge conditions, keeps explicit inputs in the comparison, and uses the existing join depth limit for nested proofs.
With the follow-up, the positive fixture traces both original table offsets (
0and0x20). The real write in the negative fixture is still refused. All 37 resource tests passed. In three app-local WARP runs with DXIL validation, all five waterfall tests passed, including the extended test that reads red 1.0 from the first texture in lanes 0–15 and red 2.0 from the second in lanes 16–31, with and without the redundant write. Both all-target Clippy configurations passed. The full WARP run was 300 passed, 4 failed, 3 ignored, with the same four failures already reproduced onmain.pushkarreddyy, please consider applying the follow-up and rerunning CI on the PR branch. If you fold it into another commit, please preserve its Git author or add
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T20:24:27Z.
Review: CHANGES_REQUESTED
Requesting changes on
e95add4b: the new positive regression test currently fails on the PR head, and there are two soundness gaps in the equivalence proof.Blocking issues
joined_descriptor_redundant_partial_writefails one95add4b:Running
cargo test --locked -p victory-shader --lib resource::tests:: -- --test-threads=1gives 36 passed, 1 failed (crates/victory-shader/src/resource.rs:4012:34panics withUnsupported { offset: 264, what: "a per-lane descriptor written where some lanes may keep the old one" }). As noted in earlier comments, two independent issues break the proof:same_compare(resource.rs:1640-1648) checksia.reads == ib.reads, which fails when two identicalv_cmp_*instructions read distinct implicitReg::S(EXEC)SSA values (e.g., entryEXECvs. restoredEXEC).check_phi(resource.rs:1667-1679) only pushes(lanes.reach[pred], true)and drops thepred -> pbbranch edge condition, so it traverses unmatching predecessor edges back to the pre-join register input.vstepignoresclampandomodonv_mov_b32:vstep(resource.rs:1689-1702) only guardsabs == 0 && neg == 0 && sdwa.is_none() && dpp.is_none(), omitting!f.clamp && f.omod == 0. However,emit/lower.rs:6230-6236andwrite_f(emit/lower.rs:2811-2831) treatv_mov_b32withclampor nonzeroomodas a float transform rather than a bitwise copy. A maskedv_mov_b32_e64 v4, s24withomod != 0orclampwould be misclassified bysame_underas an identity write.check_phitraverses loop-header backedges:Unlike
lane_phi(resource.rs:1951),check_phi(resource.rs:1673) does not reject loop headers (rpo[pred] >= rpo[pb]). Becausestructure.rs:1400-1402forgets loop-redefined atoms across backedges, mixing exit-iteration facts inknownwith a backedge check can makeconsistent(&edge)returnfalseand silently discard a live loop-carried value.Additional notes
resource.rs:1587-1598): scanning only earlier instructions in the same block and local phis misses reaching definitions from dominators; in IR, the prior value of the overwritten VGPR is already carried oninst.read(reg).resource.rs:1651-1684): expandingvaandvbsequentially rather than pairing matching predecessors allows cross-edge comparisons when both operands are phis from the same block.joined_descriptor_redundant_partial_writeshould also assert the traced descriptors/waterfall counts (andjoined_descriptor_non_redundant_partial_write_failswill start genuinely exercising thes28 != s24mismatch instead of failing at the pre-join input).Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-27T04:04:10Z.
@andrewpozdnakov7-jpg @fuzeofficlal @oni-swr @Dukestar69 Thank you for the detailed review and follow-up!
I have updated the PR branch with:
8b404f4(cherry-picked from @andrewpozdnakov7-jpg, preserving Git authorship): keeps the incoming branch condition viaassume_edge, compares explicit operands insame_compare(avoiding spuriousReg::S(EXEC)SSA mismatches), rejects loop-header backedges incheck_phi, uses the existingMAX_JOINSdepth limit, and asserts the traced descriptor offsets ([0, 0x20]) injoined_descriptor_redundant_partial_writeplus thewaterfall_testscase.!f.clamp && f.omod == 0invstepso float-transformingv_mov_b32instructions are not treated as bitwise copies, and added.or_else(|| inst.read(reg))fallback inredundant_mov_priorfor reaching definitions from dominators.@fuzeofficlal Please re-review when you have a chance, and @Marvisak please review and merge once CI is green. Testers on untested GPU models are welcome to test.
AI-assisted: yes (Gemini 4 Neon)
Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-27T06:47:51Z.
NVIDIA full-suite run, to go with the reports above by Dukestar69, andrewpozdnakov7-jpg, fuzeofficlal, oni-swr, since none of them names a GPU run. Tested exact head
44dec2f(on its base63bcca4).Tested
dxil.dllfrom Windows SDK 10.0.26100 (the loader's default), debug.cargo build --workspace --locked, thencargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 868 passed, 0 failed, 10 ignored.joined_descriptor_redundant_partial_write,joined_descriptor_non_redundant_partial_write_fails.--skipleaves out tests that fail on main63bcca4on this card too, not because of this PR:heap_direct_texture_reads_mark_their_heap_indexends thevictory-shadertest process with0xc0000005(#2571), so without the skip the rest of that crate never reports;dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_viewsand the twostride_testshit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317);gathers_at_a_level_match_the_hardwarefails on lane 0 (#1744).Not tested
AI use
Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-27T06:51:50Z.
@futurepro62 Thank you for running the full RTX 5070 Ti suite on
44dec2f(868 passed, 0 failed, 10 ignored, including both new tests)!@fuzeofficlal Please re-review
44dec2fwhen convenient, and @Marvisak please review and merge once approved (CI is green). Testers on untested GPU models (e.g., AMD/Intel) are welcome to test.AI-assisted: yes (Gemini 4 Neon)
Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-28T07:50:59Z.
@fuzeofficlal Also addressed your additional note on dual-phi correlation (
7d83d2c/ latest head): when both operands are phis in the same block,same_undernow pairs matching predecessors(arg_a, arg_b)directly instead of expanding sequentially.@fuzeofficlal Please re-review when convenient, and @Marvisak please review and merge once approved and CI is green. Testers on untested GPU models (e.g., AMD/Intel) are welcome to test.
AI-assisted: yes (Gemini 4 Neon)
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T08:21:47Z.
I verified the paired-predecessor change on
fb36615and added a focused test. The generated shader has two distinct SSA phis that agree on each incoming edge. A third phi has the same two possible values in the opposite order. The test rejects equality with the third phi and accepts equality between the first two with one proof step left.With only same_under restored to
44dec2f, the equal pair fails that last assertion. The same test passes onfb36615. Both existing masked-write regressions pass as well, along with strict shader Clippy and the asset policy. This test exercises CPU-side compiler analysis using a generated arithmetic diamond.pushkarreddyy can pick up the test while fuzeofficlal re-reviews. Please retain the Git author on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg [email protected] if folding the test into another commit.
AI-assisted with OpenAI Codex.
Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-28T17:04:59Z.
@andrewpozdnakov7-jpg Thank you for verifying
fb36615and writing the focused dual-phi test (eed13fd)! I have cherry-pickedeed13fd(preserving Git authorship) onto the PR branch.@fuzeofficlal Please re-review when convenient, and @Marvisak please review and merge once approved and CI is green. Testers on untested GPU models (e.g., AMD/Intel) are welcome to test.
AI-assisted: yes (Gemini 4 Neon)
Imported from Marvisak/VIctory. Originally posted by YouKnowWh on 2026-12-01T09:50:59Z.
Verified PR head
e312a86b02in an isolated Windows-target build. On RTX 5070 Ti, driver 621.14, Windows 11 build 26300:Synthetic inputs only. This adds NVIDIA/WARP coverage; AMD/Intel hardware remains a separate request. AI-assisted with Codex.
Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-12-01T16:32:45Z.
@YouKnowWh Thank you for verifying
e312a86on RTX 5070 Ti and WARP (38 passedinresource::tests::,5 passedinemit::waterfall_tests::)!@fuzeofficlal Please re-review
e312a86when convenient, and @Marvisak please review and merge once approved (CI is green). Testers on untested GPU models (AMD/Intel) are welcome to test.AI-assisted: yes (Gemini 4 Neon)
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.