fix(shader): accept overwritten VGPR inputs in counted indexed writes #457
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/457"
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 jeremygold02 on 2026-11-24T03:39:34Z.
Shader lowering
A pixel shader can use
v_movreld_b32to initialize a range of VGPRs that held barycentric inputs at entry. The IR tracks the old value of every possible destination. On main,fill_phiscan reject a later color export withbarycentrics read directlyeven when the indexed writes cover that register before the first observable read.Allow an undefined incoming value when the translator can prove that an unguarded indexed move overwrites it on that edge or that a counted loop initializes the slot before its only exit. The loop case follows the SSA values for M0, the unit increment, the SCC comparison and the branch. It preserves the value carried on the backedge and requires that the old value has no other consumer.
This runs on the default translation path and requires no raw barycentric input in the emitted shader. Shaders that actually consume incoming barycentrics still receive the existing refusal. The raw-input paths proposed in #281, #442 and #453 address that separate use case.
Verification
[1.0, 0.0, 0.5, 0.5]bit for bit. Both emitted shaders passed Windows SDK DXIL validation. Main rejected the indexed shader. Ending the loop after one iteration still produces the expected refusal.Refs #97.
Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T06:19:07Z.
Review: APPROVED
Tested
efcd753on Windows 11, RTX 5070, MSVC:cargo test --workspace --no-fail-fastpasses (265 passed, 0 failed).victory translate <title exe> --validate --pipelinesgives the same counts before and after: 12 of 12 programs emitted, 12 validated, 12 pipelines. None of the 12 embedded programs uses this pattern.This only changes behaviour where
fill_phispreviously stopped with "barycentrics read directly". Every shader that translated before goes through the same code. That fits your 21,971 byte-identical outputs. The risk is limited to shaders that were refused before.The proof is deliberately narrow:
v_movreld_b32in the same block, with no DPP or SDWA, writing that register.s_mov_b32to a scalar phi whose start value on the edge is a constant.I followed the direct case in full. For the counted-loop case I read the checks, and the 13 refusal fixtures (partial EXEC, early exit, clobbered SCC, wrap, a backedge consumer) cover the ways it could be wrong.
Returning
undeffor the overwritten value is sound only if the proof holds. A bug in it would show up as wrong output in a shader that was refused until now, not as a regression in one that already worked.AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by towiice on 2026-11-24T11:45:06Z.
Review: COMMENTED
Tested:
stable-x86_64-pc-windows-gnullvm(llvm-mingw 23.1.6).cargo +stable-x86_64-pc-windows-gnullvm test -p victory-shaderemit::tests::indexed_move_initializes_an_input_before_its_first_use).Clean implementation and passes all unit tests.
Imported from Marvisak/VIctory. Originally posted by sebastianspicker on 2026-11-24T11:10:56Z.
Tested
efcd753against currentmainffe310e(macOS, Rust 1.98.1).The branch merges without conflicts, but the new test no longer compiles there. #566 changed
resource::trackto take the structured program as a fourth argument:Building
stfirst fixes it, the same waymainnow does inlowers:With that change, on the merge with
main:cargo test -p victory-shader: 97 passed, 1 ignored.indexed_move_initializes_an_input_before_its_first_usefails withmain'slower.rsand passes with this branch's.x86_64-pc-windows-msvc,--all-targets -D warnings) is clean.Container::parseplusemit::translatein 90 s, no panic.I haven't checked the hardware result or reviewed each refusal case in the fixture; this is only the build, test and regression side.
AI-assisted.
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T12:34:06Z.
Review: COMMENTED
Textually clean merge with current main (
ffe310e), but it fails to compile after merge — a semantic conflict: main'sresource::tracknow takes a 4th argument (Option<&structure::Structured>), and this PR's test call incrates/victory-shader/src/emit/mod.rs:661still passes 3:Needs a rebase onto current main plus updating that call site (pass
Noneor the structured data, whichever the new signature expects). I'll re-review once it's green.Imported from Marvisak/VIctory. Originally posted by alexdeliu on 2026-11-24T17:23:59Z.
Merged onto
main@ffe310eb, this PR (efcd753a) no longer compiles its tests.crates/victory-shader/src/emit/mod.rs:661callsresource::trackwith 3 arguments. Since6638098cit takes a 4th,lanes: Option<&Structured>; main's tests passSome(&st)withlet st = structure::structure(&p).unwrap();.Checked with CI's steps (both clippy runs with
-D warnings,cargo test --workspace) on Windows 11, AMD RX 9070. Every open PR: https://gist.github.com/alexdeliu/ef9ef0ebc1776ff104b5aa8eaea18e87Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-24T17:36:07Z.
@alexdeliu Thanks for catching this. I merged
mainatffe310ebinto this PR and fixed the fixture in08b681c2. It now computesstbefore callingresource::trackand passesSome(&st), matching the other tests on main.The focused regression test and both CI Clippy commands passed locally on Windows 11.
cargo test --workspace --lockedalso passed with 343 tests passed, 0 failed, and 6 ignored.Imported from Marvisak/VIctory. Originally posted by alexdeliu on 2026-11-24T17:46:11Z.
@jeremygold02 rechecked
08b681c2merged ontomain@ffe310ebon the RX 9070: both CI clippy runs are clean andcargo test --workspacepasses (343 tests).Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:19:18Z.
Automated triage for the maintainers.
Proposed close: already in
main. Your proof was ported onto the current lowering inf342dcf("Shaders: inputs a counted v_movreld loop overwrites first need no value", credited to this PR):Lower::overwritten_movreld_edgeandLower::counted_movreld_indexincrates/victory-shader/src/emit/lower.rs, used from the fill-phis arm, with your 15-case test asindexed_move_initializes_an_input_before_its_first_useincrates/victory-shader/src/emit/mod.rs. The latest push (d00ddae) is a merge ofmainthat leaves no difference frommain. Thank you for the work and the hardware verification; it made the bloom downsample shader translate.This PR will be closed in 48 hours unless you push a change that adds something
mainlacks or a maintainer removes the label.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-25T02:58:03Z.
@Marvisak I rebased this branch onto
mainat940d32f6and resolved the conflict inemit/lower.rs. The new head is2cc715e1. All 15 focused regression cases passed locally, including Windows SDK validation for both positive cases. GitHub now reports the branch merges cleanly. This is ready for the content review requested in triage. The CI run passed both Clippy configurations and the workspace tests.Pull request closed