Shaders: refuse per-lane reads of mesh v5 in v5 writes and after joins #659
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from Marvisak/VIctory. Originally posted by coderanonymus on 2026-11-24T06:24:25Z.
What
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
Imported from Marvisak/VIctory. Originally posted by LAKSHYA-cmd-tech on 2026-11-24T06:26:41Z.
Review: APPROVED
LGTM! Tested on Windows 11 with MSVC Rust 1.98.1. All 69 tests in ictory-shader passed cleanly, including the new regression cases in mesh_inputs_and_primitive_export. The fixpoint phi tracking and ir::operand_reads differentiation cleanly protect mesh group inputs from illegal per-lane reads.
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T09:37:36Z.
Review: APPROVED
Merges cleanly with main; macOS arm64, rustc 1.98.1,
cargo test -p victory-shader --lockedwith the PR merged into main8e79c80→ 70 passed / 0 failed / 1 ignored.Mesh v5 (the group index) is uniform only as
v_readfirstlane_b32reads it; this PR closes the per-lane-read holes: the group value now propagates through phis across joins (with thes_cbranch_execz/_execnzno-lane edges carved out), writes to v5 count as reads of the old value via the newoperand_reads, and the five refusal cases plus the two acceptance cases are tested with real encodings.The
ir.rschange is the subtle part and it's right:effects()no longer folds written VGPRs intoreads(that's now done inbuild()for the IR's old-value semantics), whileoperand_reads()exposes the true operand reads for the mesh check — sov_add_nc_u32 v5, v5, v1is refused (v5 is an operand) butv_mov_b32 v5, 0followed by a read is accepted (only lanes outside EXEC keep the old value). The shortcut comment honestly lists the write forms still accepted (fmac accumulator, d16 loads, writelane, DPP) — acceptable as documented follow-up scope.Note for CI: the interesting cases are structural/IR-level and run on macOS (they did); no GPU needed.
Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T10:56:48Z.
Review: APPROVED
Tested
98fe8feon Windows 11, RTX 5070, MSVC:cargo test -p victory-shader -- --test-threads=169 passed, including the new per-lane cases.cargo clippy -p victory-shader --all-targetsis clean. The local title executable has no mesh programs, sotranslate --pipelinescan't exercise this.operand_reads) is the precise fix for the deduplicated-readsproblem:v_add_nc_u32 v5, v5, v1is now refused andv_mov_b32 v5, 0still passes.groupthrough phis until a fixed point catches the join case, and excluding the EXEC-zero edge ofs_cbranch_execz/execnzavoids refusing the guarded-skip pattern that is actually safe.shortcut:comment lists the remaining partial writes that still pass (fmac accumulator, d16, writelane, movreld, DPP). Good that it's explicit.AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by Parakeet-Wheat on 2026-11-24T10:51:18Z.
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.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:33:02Z.
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
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.