Shaders: drop a wave64 mask whose low dword is seen with two high dwords #660
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!660
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-660"
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?
@coderanonymus on GitHub · 2026-11-24 06:24 UTC · original
coderanonymus:wave64-mask-pairs→main· +196 −9 · 2 files · 1 commits · openWhat
In wave64 a lane mask is an SGPR pair. Structurisation tracks masks by the pair, but it exports
Structured::masks,highsandactiveby the low dword alone. When code rewrites only the high dword, two pairs share one low dword, and lowering finds the wrong pair's mask.v_cmp_eq_u32 vcc, 0, v0; s_mov_b32 vcc_hi, 0; v_cndmask_b32 v1, 0, v2, vcc:masks[vcc_lo]was still the compare. The select picked src1 by the compare's bit in lanes 32-63, where the hardware has VCC_HI = 0 and picks src0.emitreturned Ok.v_add_co_ci_u32reads its carry-in the same way.s_mov_b32 exec_hi, 0; v_mov_b32 v1, 7; buffer_store_dword ...: the guard isOpaque(exec_lo), and lowering took the high dword of EXEC on entry. Lanes 32-63 stored, although the new EXEC disables them.emitreturned Ok. With ans_mov_b64 s[2:3], execfirst,mainalready refuses the same program ("a lane mask whose lanes depend on its own value").The code changes are in
structure.rs:finishleaves a low dword out ofmasks,highsandactivewhen it was seen with two high dwords. Lowering then refuses what reads it ("a select on an untracked mask", "a carry-in from an untracked mask", or for the EXEC case "a hardware SGPR input") when that low dword has no value of its own (EXEC, compare results). See "Still open" for one that holds a number.steprecords the carry-in pair ofv_*_co_ci_u32. Before, it was never recorded, so the check above could not see it. It is only recorded, not resolved throughmaskas thev_cndmask_b32condition is, so a carry-in on a join of compares is still refused, as onmain.joinrecords the pairs it takes over back edges. Lowering looks phi arguments up by low dword too, and those pairs never go throughmask.emit/mod.rsgets astores_v1test helper, two tests, and a doc comment update.Still open, marked as a
shortcut:inmask:Atom::Opaquenames its pair by the low dword. Lowering takes the high dword written beside it. This is wrong for a mask whose halves were written apart when the low dword holds a number: twos_mov_b32, ors_mov_b64 s[4:5], kthens_mov_b32 s5, 0, where lowering takes the stales5. So the PR does not refuse every wave64 mask whose high dword was rewritten alone. When the low dword has no value (EXEC, compare results), lowering now refuses. The full fix is an opaque atom that carries both dwords, which needs a change toemit/lower.rs. I left that out of this PR.In wave32 both halves of a key are the same value, so no low dword is ever split and no mask is dropped. Wave32 is unchanged.
Found in review, not fixed here (it is on
maintoo): a select on a join of compares after a divergent branch translates wrongly. Inv_cmp_eq_u32 vcc, 0, v0; s_andn1_saveexec_b64 s[2:3], vcc; s_cbranch_execz; v_cmp_eq_u32 vcc, 1, v0; s_or_b64 exec, exec, s[2:3]; v_cndmask_b32 v1, 0, v2, vcc, the join resolves to a per-lane phi. Lane 0 skips the inner block, so the phi gives it the first compare's bit. The hardware has 0 there whenever some lane runs the inner block, because VOPC clears the bits of inactive lanes. This is why the carry-in is only recorded: resolving it the same way turnedmain's refusal of the carry-in version into this wrong code. Compiled code is unlikely to hit it: LLVM merges an i1 across such a join withs_andn2/s_and/s_oron EXEC, which the per-lane join already gets right. A check at the join that refused the raw form also refused LLVM's own if/else lowering and uniform branches inside a divergent if, so a fix needs a different model of mask joins, not a check. I left it.Overlap with open PRs:
v_cndmask_b32block instepand fixes the select case another way (a select mask keyed by the select's destination, from the exact pair it reads). Whichever lands second needs a rebase there.joinhandles back edges. The back-edge recording here sits in the loop it changes, so the two may conflict.othersexport keyed by(lo, _). It needs the same split filter asmasks.Rebased on main (
ffe310e)mainnow buildspaired_masks(exact pairs, for the waterfall proof) from the same map.finishtakes it before dropping split low dwords: an exact pair stays right when its low dword is split, so the waterfall proof sees the same pairs as before. Thestores_v1test helper now passes the structure toresource::track, which takes it since main changed.After the rebase:
cargo test -p victory-shader100 passed;cargo clippy -p victory-shader --all-targets --all-features --target x86_64-pc-windows-msvc -- -D warningsclean.Verification
All run on Linux. The target dir is shared, so I passed
--config profile.dev.package.<crate>.codegen-units=251(for each workspace crate built) to force a fresh build of this worktree.main(tests only):cargo test -p victory-shader --lib -- a_mask_ a_carry_instructure::tests::a_mask_whose_high_dword_is_rewritten_is_not_the_compareFAILED:0x2020480: vcc_hi was zeroed after the compare, left and right bothSome((Lane(Value(5)), Bool(0), Bool(1))). The carry-in program fails the same way.structure::tests::a_mask_joined_over_a_back_edge_with_a_rewritten_high_dword_is_not_the_compareFAILED: left and right bothSome((Lane(Value(16)), Bool(0), Bool(1))).emit::tests::a_mask_whose_high_dword_is_rewritten_is_refusedFAILED: the vcc_hi select program translated, and so did the vcc_hi carry-in program (checked on its own). Theexec_hiprogram also translated (Ok). Its last program (exec_hiafters_mov_b64 s[2:3], exec) already refuses onmain, so it adds no regression coverage; it stays as a guard.emit::tests::a_carry_in_from_a_divergent_join_is_refusedpasses onmain(it refuses with "a carry-in from an untracked mask"). It fails if the carry-in goes throughmasklike the select (emit returns Ok), which is what it guards.emit::tests::an_exec_high_write_does_not_overflow_the_stack(existing) now goes another way: the guard's low dword is split and has no mask, so thev_mov_b32no longer needs the mask's own value.emitstill returns Ok, since nothing with a side effect reads it. I updated its doc comment.cargo test -p victory-formats -p victory-shader -p victory-pipeline -p victory-core -p xtask: all pass (victory-shader 60 passed).cargo clippy -p victory-shader --tests --target x86_64-pc-windows-msvc: no warnings.rustfmt --edition 2024 --checkon both touched files: clean.Not run: Windows-only crates and tests, and no game shaders. How often console code writes one half of a mask outside a whole-wave section was not measured.
No game data used.
🤖 Generated with Claude Code
@fuzeofficlal on GitHub · 2026-11-24 06:43 UTC · original
I tested the remaining opaque numeric-mask case on
d92ebe9. A synthetic Wave64 compute program writes two scalar words, rewrites only the high word, and ANDs the pair into EXEC before a per-lane output store. Both baseline shaders pass SDK DXIL validation. On the Radeon iGPU the readback matches 32/64 lanes in each case, because lanes 32–63 use the old high word.Keeping both SSA word identities in the opaque guard gives 64/64 expected values for both variants. At lanes 31/32, clearing the high word changes
7/7to7/0, and setting it changes0/0to0/7. Both candidates pass SDK DXIL validation. The serial shader suite reports 74 passed, including the earlier refusal tests and a new structural test distinguishing two guards with the same low word.Incremental source change on this head
@qntic on GitHub · 2026-11-24 11:13 UTC · original
tested on rx 6600 xt. the select pattern after vcc_hi = 0 silently produces incorrect values in 16 out of 64 lanes on main. with this pr the unsafe translation is correctly rejected instead of producing incorrect results.
hardware tests:
https://github.com/qntic/VIctory/tree/hwtest/compute-lanes
@rpmaster2 on GitHub · 2026-11-24 11:02 UTC · original · edited 2026-11-24 12:31 UTC
Independent test on RDNA4: this PR alone, on
main@58fed37, diag build, DRED on, 300 s from an identical restored save.Counting unique
stage/hashpairs whose pipelines are dropped withshader does not translate:main(two runs)main+ this PRBoth mask reasons disappear entirely with this PR:
a select on an untracked mask(95-96 log lines on main) anda lane mask holding lanes elsewhere read as data(80-81) go to 0. Remaining reasons here:a descriptor read only as data(24 lines),a structured buffer of unknown stride(8),a descriptor's address or format read as data(1).Interesting detail: the 33 hashes left are exactly the same set that #585 alone leaves, even though #585 only touches
emit/lower.rsand this PR touchesemit/mod.rsandstructure.rs. So on this title the two PRs each unblock the same set from different sides; either one is enough to get every pixel/vertex/mesh shader translated.What this PR does not change: the world is still black (6 black-frame warnings, ~1 fps, 150 draws/frame) and the run still loses the device at frame 1143 with the same
page fault ... inside freed [texture ...]signature that everymainrun shows. So it is not a stability fix, only a translation one.Note on method: my first run of this PR stayed in the front end and measured nothing (16 draws/frame, 30 fps); the numbers above are from a retry with later key timings that reached the world. Not tested:
cargo test, clippy, other GPUs.No game data: counts, shader hashes, driver version and error strings only.
AI-assisted: written by DeepSeek (OpenCode harness) from my run logs and observations; the hardware, the dump and the runs are mine.
@rpmaster2 on GitHub · 2026-11-24 11:43 UTC · original · edited 2026-11-24 12:31 UTC
Correction to my earlier comment: offline translation shows no change from this PR, so the in-game difference I reported is not evidence for it and I withdraw that claim.
victory translate --pipelinesover the whole dump (26,148 programs, same input per build):main@58fed37main+ this PRThe in-game "440 -> 33 refused" I posted came from runs that covered different amounts of world content (a
mainrun reached 2,220 draws/frame at frame 1500, this PR's run 152 draws/frame at frame 1171), so fewer shaders were requested and fewer failures appear. Not something this PR can take credit for.No regression either: the same programs emit, and the one world run I have ended the same way as
main(device removed at frame 1143, page fault inside a freed texture), so on this host it changes neither coverage nor stability.If your intent is the wave64 mask pairs, the remaining mask refusals offline are
a lane mask holding lanes elsewhere read as data(285 programs) anda lane mask read as data(266), plus 22a lane-mask join of an untracked mask- so there is still room, but this title's failing set is dominated by other reasons.No game data: counts, driver version and error strings only.
AI-assisted: written by DeepSeek (OpenCode harness) from my run logs and observations; the hardware, the dump and the runs are mine.
@molodayamama on GitHub · 2026-11-24 14:03 UTC · original
Independent Windows check of
d92ebe9c9dc9eda57fdf54681a2b21f4058a4265(Windows 10 22H2 19045, Rust 1.98.1, MSVC x64).cargo test -p victory-shader --locked --lib a_mask_whose_high_dword_is_rewritten -- --test-threads=1 --nocapture: 2 passed.cargo test -p victory-shader --locked --lib a_mask_joined_over_a_back_edge -- --test-threads=1 --nocapture: 1 passed.cargo test -p victory-shader --locked --lib a_carry_in_from_a_divergent_join -- --test-threads=1 --nocapture: 1 passed.The shader fixtures checked that rewriting a high dword invalidates the corresponding mask through a later use and across a loop back edge. The divergent carry-in refusal also passed.
Only source-built synthetic fixtures were used. AI-assisted verification.
@Marvisak on GitHub · 2026-11-25 01:24 UTC · original
Automated triage for the maintainers.
Needs work. The fix is worth having, but it needs a rebase for a new export on
main.What it does: in
structure.rs(Lanes::finish), a low dword seen with two high dwords is dropped frommasks,highsandactive. Carry-in pairs (step) and back-edge pairs (join) are also recorded. Lowering then refuses a wave64 mask whose high dword was rewritten alone (s_mov_b32 vcc_hi/exec_hi) instead of reading lanes 32-63 from the stale pair. This only adds refusals. The thread backs it with an RX 6600 XT hardware run showing the silent miscompile onmain, and an offline corpus run with no coverage change.Blocking: since this branch was cut,
mainmerged #1221, which addsStructured::other. It is exported by low dword infinishand is now read when lowering av_cndmask_b32. Your description already names this case ("anothersexport keyed by(lo, _)needs the same split filter"). It still merges cleanly, butself.otheris not filtered there, so a split low dword can still reach the select throughother. Please rebase, apply thesplitfilter toother, and confirma_mask_whose_high_dword_is_rewritten_is_refusedstill passes on the result.CI: no checks have run on this head.
Generated by Claude Code
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.