fix(shader): accept overwritten VGPR inputs in counted indexed writes #457

Open
github-bot wants to merge 2 commits from github-bot/gh-457 into main AGit
Owner

@⁠jeremygold02 on GitHub · 2026-11-24 03:39 UTC · original
jeremygold02:codex/counted-movreld-phi → main · +0 −0 · 0 files · 2 commits · open

Shader lowering

A pixel shader can use v_movreld_b32 to initialize a range of VGPRs that held barycentric inputs at entry. The IR tracks the old value of every possible destination. On main, fill_phis can reject a later color export with barycentrics read directly even 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

  • Compared a two-iteration native pixel shader with a direct-write reference on a physical RTX 5070. Iteration one writes 0.0 to the first slot, and iteration two writes 1.0 to the second. After fence completion, all 64 RGBA32F texels from each shader matched the expected [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.
  • The in-tree regression fixture covers two accepted cases and thirteen refusals, including partial EXEC, an early exit, a clobbered SCC, a wrapping counter and a value consumed on the backedge.
  • Replayed eleven previously refused shaders against main and this branch using separate builds. One newly passed the Windows SDK validator. The other ten retained their original refusal reasons and offsets.
  • Compared 25,694 distinct supported shader inputs across four stages in separate builds of main and this commit. SDK-valid outputs increased from 21,971 to 21,973. All 21,971 previously valid DXIL outputs were byte-identical. Both new successes had previously failed emission, and the SDK rejection count stayed at 185.
  • Repeated a bounded Windows 11 title run on the same RTX 5070 and starting pipeline cache as the previous run. VIctory translated the pixel shader that failed in two earlier runs, wrote it to the shader cache, and created a host graphics PSO for the same vertex and pixel shader pair. The tester still saw a black screen with audio. Execution of a draw using that PSO remains unverified.
  • All 58 CPU-side shader library tests passed. The separate RTX draw above exercised the changed path. Package formatting and Clippy with warnings denied also passed.

Refs #97.

**@⁠jeremygold02** on GitHub · 2026-11-24 03:39 UTC · [original](https://github.com/Marvisak/VIctory/pull/457) `jeremygold02:codex/counted-movreld-phi` → `main` · +0 −0 · 0 files · 2 commits · open ## Shader lowering A pixel shader can use `v_movreld_b32` to initialize a range of VGPRs that held barycentric inputs at entry. The IR tracks the old value of every possible destination. On main, `fill_phis` can reject a later color export with `barycentrics read directly` even 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 - Compared a two-iteration native pixel shader with a direct-write reference on a physical RTX 5070. Iteration one writes 0.0 to the first slot, and iteration two writes 1.0 to the second. After fence completion, all 64 RGBA32F texels from each shader matched the expected `[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. - The in-tree regression fixture covers two accepted cases and thirteen refusals, including partial EXEC, an early exit, a clobbered SCC, a wrapping counter and a value consumed on the backedge. - Replayed eleven previously refused shaders against main and this branch using separate builds. One newly passed the Windows SDK validator. The other ten retained their original refusal reasons and offsets. - Compared 25,694 distinct supported shader inputs across four stages in separate builds of main and this commit. SDK-valid outputs increased from 21,971 to 21,973. All 21,971 previously valid DXIL outputs were byte-identical. Both new successes had previously failed emission, and the SDK rejection count stayed at 185. - Repeated a bounded Windows 11 title run on the same RTX 5070 and starting pipeline cache as the previous run. VIctory translated the pixel shader that failed in two earlier runs, wrote it to the shader cache, and created a host graphics PSO for the same vertex and pixel shader pair. The tester still saw a black screen with audio. Execution of a draw using that PSO remains unverified. - All 58 CPU-side shader library tests passed. The separate RTX draw above exercised the changed path. Package formatting and Clippy with warnings denied also passed. Refs #97.
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: #97
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:04:46 +00:00
Author
Owner

@⁠sebastianspicker on GitHub · 2026-11-24 11:10 UTC · original

Tested efcd753 against current main ffe310e (macOS, Rust 1.98.1).

The branch merges without conflicts, but the new test no longer compiles there. #566 changed resource::track to take the structured program as a fourth argument:

error[E0061]: this function takes 4 arguments but 3 arguments were supplied
   --> crates/victory-shader/src/emit/mod.rs:661:23

Building st first fixes it, the same way main now does in lowers:

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 main:

  • cargo test -p victory-shader: 97 passed, 1 ignored. indexed_move_initializes_an_input_before_its_first_use fails with main's lower.rs and passes with this branch's.
  • Windows-target clippy (x86_64-pc-windows-msvc, --all-targets -D warnings) is clean.
  • A 48-program synthetic corpus (scalar, VOP1/2/3, VOPC and carry ops) still translates.
  • 4.8 million libFuzzer inputs through Container::parse plus emit::translate in 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.

**@⁠sebastianspicker** on GitHub · 2026-11-24 11:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/457#issuecomment-7129763186) Tested `efcd753` against current `main` `ffe310e` (macOS, Rust 1.98.1). The branch merges without conflicts, but the new test no longer compiles there. #566 changed `resource::track` to take the structured program as a fourth argument: ``` error[E0061]: this function takes 4 arguments but 3 arguments were supplied --> crates/victory-shader/src/emit/mod.rs:661:23 ``` Building `st` first fixes it, the same way `main` now does in `lowers`: ```rust 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 `main`: - `cargo test -p victory-shader`: 97 passed, 1 ignored. `indexed_move_initializes_an_input_before_its_first_use` fails with `main`'s `lower.rs` and passes with this branch's. - Windows-target clippy (`x86_64-pc-windows-msvc`, `--all-targets -D warnings`) is clean. - A 48-program synthetic corpus (scalar, VOP1/2/3, VOPC and carry ops) still translates. - 4.8 million libFuzzer inputs through `Container::parse` plus `emit::translate` in 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.
Author
Owner

@⁠alexdeliu on GitHub · 2026-11-24 17:23 UTC · original

Merged onto main @ ffe310eb, this PR (efcd753a) no longer compiles its tests. crates/victory-shader/src/emit/mod.rs:661 calls resource::track with 3 arguments. Since 6638098c it takes a 4th, lanes: Option<&Structured>; main's tests pass Some(&st) with let 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/ef9ef0ebc1776ff104b5aa8eaea18e87

**@⁠alexdeliu** on GitHub · 2026-11-24 17:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/457#issuecomment-7139135122) Merged onto `main` @ `ffe310eb`, this PR (`efcd753a`) no longer compiles its tests. `crates/victory-shader/src/emit/mod.rs:661` calls `resource::track` with 3 arguments. Since 6638098c it takes a 4th, `lanes: Option<&Structured>`; main's tests pass `Some(&st)` with `let st = structure::structure(&p).unwrap();`. <sub>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/ef9ef0ebc1776ff104b5aa8eaea18e87</sub>
Author
Owner

@⁠jeremygold02 on GitHub · 2026-11-24 17:36 UTC · original

@⁠alexdeliu Thanks for catching this. I merged main at ffe310eb into this PR and fixed the fixture in 08b681c2. It now computes st before calling resource::track and passes Some(&st), matching the other tests on main.

The focused regression test and both CI Clippy commands passed locally on Windows 11. cargo test --workspace --locked also passed with 343 tests passed, 0 failed, and 6 ignored.

**@⁠jeremygold02** on GitHub · 2026-11-24 17:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/457#issuecomment-7139435758) @⁠alexdeliu Thanks for catching this. I merged `main` at `ffe310eb` into this PR and fixed the fixture in `08b681c2`. It now computes `st` before calling `resource::track` and passes `Some(&st)`, matching the other tests on main. The focused regression test and both CI Clippy commands passed locally on Windows 11. `cargo test --workspace --locked` also passed with 343 tests passed, 0 failed, and 6 ignored.
Author
Owner

@⁠alexdeliu on GitHub · 2026-11-24 17:46 UTC · original

@⁠jeremygold02 rechecked 08b681c2 merged onto main @ ffe310eb on the RX 9070: both CI clippy runs are clean and cargo test --workspace passes (343 tests).

**@⁠alexdeliu** on GitHub · 2026-11-24 17:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/457#issuecomment-7139677965) @⁠jeremygold02 rechecked `08b681c2` merged onto `main` @ `ffe310eb` on the RX 9070: both CI clippy runs are clean and `cargo test --workspace` passes (343 tests).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:19 UTC · original · edited 2026-11-26 01:22 UTC

Automated triage for the maintainers.

Proposed close: already in main. Your proof was ported onto the current lowering in f342dcf ("Shaders: inputs a counted v_movreld loop overwrites first need no value", credited to this PR): Lower::overwritten_movreld_edge and Lower::counted_movreld_index in crates/victory-shader/src/emit/lower.rs, used from the fill-phis arm, with your 15-case test as indexed_move_initializes_an_input_before_its_first_use in crates/victory-shader/src/emit/mod.rs. The latest push (d00ddae) is a merge of main that leaves no difference from main. 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 main lacks or a maintainer removes the label.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 00:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/457#issuecomment-7148386497) · edited 2026-11-26 01:22 UTC <!-- victory-triage v1 head=d00ddaec04a709ab206f3481f937654eff3a6336 verdict=proposed-close at=2026-11-26T01:22:48Z --> Automated triage for the maintainers. **Proposed close: already in `main`.** Your proof was ported onto the current lowering in `f342dcf` ("Shaders: inputs a counted v_movreld loop overwrites first need no value", credited to this PR): `Lower::overwritten_movreld_edge` and `Lower::counted_movreld_index` in `crates/victory-shader/src/emit/lower.rs`, used from the fill-phis arm, with your 15-case test as `indexed_move_initializes_an_input_before_its_first_use` in `crates/victory-shader/src/emit/mod.rs`. The latest push (`d00ddae`) is a merge of `main` that leaves no difference from `main`. 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 `main` lacks or a maintainer removes the label. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠jeremygold02 on GitHub · 2026-11-25 02:58 UTC · original

@⁠Marvisak I rebased this branch onto main at 940d32f6 and resolved the conflict in emit/lower.rs. The new head is 2cc715e1. 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.

**@⁠jeremygold02** on GitHub · 2026-11-25 02:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/457#issuecomment-7151433880) @⁠Marvisak I rebased this branch onto `main` at `940d32f6` and resolved the conflict in `emit/lower.rs`. The new head is `2cc715e1`. 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](https://github.com/Marvisak/VIctory/actions/runs/45536342851) passed both Clippy configurations and the workspace tests.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
The changes on this branch are already on the target branch. This will be an empty commit.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/457/head:github-bot/gh-457'
git switch 'github-bot/gh-457'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-457'
git switch 'github-bot/gh-457'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-457'
git switch 'github-bot/gh-457'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-457'
git switch 'main'
git merge --squash 'github-bot/gh-457'
git switch 'main'
git merge --ff-only 'github-bot/gh-457'
git switch 'main'
git merge 'github-bot/gh-457'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!457
No description provided.