Shaders: refuse per-lane reads of mesh v5 in v5 writes and after joins #659
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!659
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-659"
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:mesh-group-input-guard→main· +96 −8 · 2 files · 1 commits · openWhat
In a mesh program, v5 holds the group input. Only the first lane's value is right, so
io::raiserefuses any per-lane read of it other thanv_readfirstlane_b32("the mesh group input read per lane").The guard skipped every instruction that writes v5. That exemption exists because the IR adds a VGPR's old value to the reads of every write to it (lanes outside EXEC keep it). But
readsis deduplicated, so the exemption also covered instructions that read v5 as a real operand. The guard also compared against the input value only, so a read of a phi that merges it was missed. On main, all of these mesh programs translate without an error:v_add_nc_u32 v5, v5, v1v_cvt_f32_u32 v5, v5global_load_dword v5, v5, s[0:1]v_swap_b32 v5, v1s_cmp_eq_u32 s1, 0/s_cbranch_scc1/v_mov_b32 v5, 0/ then, after the join,v_mov_b32 v1, v5Lowering (
Input::MeshGroup) then gives every lanegroupId * mesh_stride, the first lane's value. Each lane after lane 0 computes a wrong value, with no diagnostic.Change:
ir.rs:buildadds the old-value read of written VGPRs, instead ofeffects. The resultingreadsare the same as before. The newir::operand_readsreturns whateffectsgives, so it covers VALU sources,v_swap_b32, memory addresses and data, and exports.io.rs: the guard now tracks the group input plus every phi that may carry it (to a fixpoint). It does not follow a phi argument that arrives over the EXEC-zero edge ofs_cbranch_execz(taken) ors_cbranch_execnz(not taken): no lane is active there, so it is the same case as a partial-EXEC write. It exempts a write to v5 only when v5 is not one of its operand reads.Still not refused, noted as a
shortcut:comment: writes that may keep the old v5 in active lanes (v_fmac_f32's accumulator, a 16-bit half or d16 load,v_writelane_b32,v_movreld_b32, DPP that leaves lanes unwritten) and writes to v5 under a partial EXEC. I chose not to add per-opcode or EXEC checks for these to keep the guard small. Refusing every write under a possibly partial EXEC would also refuse the normal case where v5 is reused afterv_readfirstlane_b32, inside a divergent if.Verification
io::tests::mesh_inputs_and_primitive_export: the five programs above must be refused. Two must still be accepted:v_mov_b32 v5, 0; v_mov_b32 v1, v5(v5 overwritten, then read), and a wave64 program that reuses v5 afterv_readfirstlane_b32inside a divergent if (s_and_saveexec_b64+s_cbranch_execz,v_mov_b32 v5, 0,s_or_b64 exec) and reads it under the same mask in a second if. Main accepts that one too. Without the EXEC-zero edge rule it is refused at offset 32. The words were checked withllvm-mc -mcpu=gfx1030.d2a4baeplus the test):CARGO_TARGET_DIR=/home/eric/src/VIctory/target cargo test -p victory-shader --lib mesh_inputs_and_primitive_exportfails withaccepted: [[4A0A0305, BF810000], [7E0A0D05, BF810000], [DC308000, 05000005, BF810000], [7E0ACB01, BF810000], [BF068001, BF850001, 7E0A0280, 7E020305, BF810000]].cargo test -p victory-shadergives 56 passed, 0 failed. The binary was built from this branch (its test list matches this branch's tests).cargo clippy -p victory-shader --tests --target x86_64-pc-windows-msvc, with and without--features host,diagnostics: no warnings.rustfmt --edition 2024 --checkonio.rsandir.rs: clean.victory-gpu,victory-hle,apps/victory), and no real mesh shaders. I don't know how often shipped console shaders read v5 per lane.No game data used.
🤖 Generated with Claude Code
@Parakeet-Wheat on GitHub · 2026-11-24 10:51 UTC · original
Retail shader check for
98fe8fe, merged locally ontomainffe310e(clean):610.88), Ryzen 5 5600X, Rust 1.98.1 (x86_64-pc-windows-msvc),dxil.dll1.8.2502, title 1.0.2.1.victory translate <exe> shaders.rpf --list --validate,mainvs this PR: no program changes outcome (21,736 validated, 4,003 failed, 162 rejected on both).cargo test -p victory-shader --locked: 120 passed, 0 failed, 1 ignored, includingmesh_inputs_and_primitive_export.Offline translation and validation only; no shader contents or extracted data included. AI-assisted (Claude Code); run on my machine.
@Marvisak on GitHub · 2026-11-25 00:33 UTC · original
Automated triage for the maintainers.
Needs rebase. This PR does not merge cleanly into current
main(ac2525d). Conflicting files:crates/victory-shader/src/ir.rs.The content has not been reviewed yet; it will be once the branch is rebased onto
main.Generated by Claude Code
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.