Repository navigation
fix(shader): accept overwritten VGPR inputs in counted indexed writes - #457
jeremygold02 wants to merge 2 commits into
Conversation
mercuryVM
left a comment
There was a problem hiding this comment.
Tested efcd753 on Windows 11, RTX 5070, MSVC: cargo test --workspace --no-fail-fast passes (265 passed, 0 failed). victory translate <title exe> --validate --pipelines gives 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:
- The incoming value has exactly one consumer, an unguarded
v_movreld_b32in the same block, with no DPP or SDWA, writing that register. - M0 traces back through
s_mov_b32to a scalar phi whose start value on the edge is a constant. - For the loop case, a unit increment, an SCC compare and a branch exit are checked.
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.
- The incoming value has exactly one consumer, an unguarded
-
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).
…inputs in counted indexed writes Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Tested The branch merges without conflicts, but the new test no longer compiles there. #566 changed Building let st = structure::structure(&p).unwrap();
let res = resource::track(&p, &native.layout, native.stage, Some(&st)).unwrap();
let io = io::raise(&p, &native).unwrap();With that change, on the merge with
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. |
towiice
left a comment
There was a problem hiding this comment.
Tested:
- Hardware: NVIDIA GeForce GTX 1650 SUPER (Turing TU116, 4 GB VRAM, 32-wide subgroups / wave32, driver 610.88), Windows 11 x64 (26H2 / 10.0.26300), toolchain
stable-x86_64-pc-windows-gnullvm(llvm-mingw 23.1.6). - Test command:
cargo +stable-x86_64-pc-windows-gnullvm test -p victory-shader - Result: 70 passed, 0 failed (including
emit::tests::indexed_move_initializes_an_input_before_its_first_use).- Correctly verifies that an indexed move loop overwriting VGPR inputs prior to observable reads accepts incoming undefined states without triggering false-positive barycentric read refusals.
Clean implementation and passes all unit tests.
- Correctly verifies that an indexed move loop overwriting VGPR inputs prior to observable reads accepts incoming undefined states without triggering false-positive barycentric read refusals.
catminou4
left a comment
There was a problem hiding this comment.
Textually clean merge with current main (ffe310e), but it fails to compile after merge — a semantic conflict: main's resource::track now takes a 4th argument (Option<&structure::Structured>), and this PR's test call in crates/victory-shader/src/emit/mod.rs:661 still passes 3:
error[E0061]: this function takes 4 arguments but 3 arguments were supplied
--> crates/victory-shader/src/emit/mod.rs:661:23
= note: argument #4 of type `Option<&structure::Structured>` is missing
Needs a rebase onto current main plus updating that call site (pass None or the structured data, whichever the new signature expects). I'll re-review once it's green.
|
Merged onto Checked with CI's steps (both clippy runs with |
|
@alexdeliu Thanks for catching this. I merged The focused regression test and both CI Clippy commands passed locally on Windows 11. |
|
@jeremygold02 rechecked |
|
Automated triage for the maintainers. Proposed close: already in This PR will be closed in 48 hours unless you push a change that adds something Generated by Claude Code |
Allow an incoming raw barycentric value to remain undefined only when an unguarded indexed move is proven to initialize the register before any use. Preserve the loop-carried register and reject incomplete or ambiguous initialization. Refs: Marvisak#97
08b681c to
2cc715e
Compare
|
@Marvisak I rebased this branch onto |
…unted indexed writes
`PS_DownSampleBloomFilter(Karis)_557ae3d7` (the bloom downsample, 3 draws
a frame in the intro cutscene) fills a register array v0.. with
`v_movreld` in a uniform loop counted from a constant start to an `eq`
bound. v0/v1 hold the raw barycentrics on entry, which have no host form
("barycentrics read directly"), so the loop header's phi refused the
program although no lane ever reads those values: the loop's first passes
overwrite them.
PR #457's proof, ported onto the current lowering: the loop-carried
register's only use is the unguarded `v_movreld` at index M0, M0 a copy
of a scalar phi starting at a constant and stepping by 1 to an `s_cmp_eq`
bound that exits through the one exit block; the register's slot lies in
[start, bound), so the move writes it before anything can read it, and
the entry edge's value is undefined. Every other shape keeps the refusal
(the PR's 15-case test: wrong start, skipped slot, decrement, wrap,
unknown start, short loop, clobbered SCC, early or divergent exit, masked
write, old value as source, reads before the write or on the back edge).
Shader list against f6cd0144: 0 newly failing; `PS_DownSampleBloomFilter
Karis_557ae3d7` and `PS_DownSampleBloomFilter_557ae3d7` emit, validate and
make pipelines (1-2 s, under 0.1 GB).
Ported from PR #457 (efcd753, 08b681c, Jeremy Goldberg): the fill-phis
arm now takes the edge's liveness from `live_edges`.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…unted indexed writes
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.