Shaders: recompute ISG1 input usage and barycentrics flag after bitcode opt #122

Open
davi713albano-coder wants to merge 1 commit from upstream-pr/122 into main
davi713albano-coder commented 2026-11-24 21:39:31 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by davi713albano-coder on 2026-11-24T21:39:31Z.


Summary

In Shader::finish() (crates/victory-shader/src/emit/shader.rs), self.m.optimise(passes) runs dead-code elimination (opt::DEAD) before writing dx.entryPoints and ISG1. Because dx.op.loadInput.* and dx.op.attributeAtVertex.* are declared Attr::ReadNone (Effect::Pure), dead input reads can be eliminated during clean-up. Previously Shader::finish() recomputed self.flags via self.m.usage(), but left self.inputs[id].usage (and flags::BARYCENTRICS) at their pre-optimization values, so ISG1 could still mark eliminated channels as read (see #53).

Changes

  • crates/victory-shader/src/emit/bitcode/opt.rs:
    • Track barycentrics (dx.op.attributeAtVertex.*) in Module::usage().
    • Add Module::input_usage(count) to compute the surviving per-element read bitmask from reachable dx.op.loadInput.* and dx.op.attributeAtVertex.* calls.
  • crates/victory-shader/src/emit/shader.rs:
    • After self.m.optimise(passes), refresh self.inputs[id].usage from self.m.input_usage(...) and clear flags::BARYCENTRICS if neither attributeAtVertex nor an SV_Barycentrics (kind == 28) input remains.
  • crates/victory-shader/src/emit/mod.rs:
    • Add synthetic pixel-shader test dead_input_read_is_cleared_from_isg1_after_opt verifying that an unused interpolated channel is cleared from ISG1's ReadWriteMask and passes dxil.dll validation.

Verification

  • Fork CI (windows-latest): https://github.com/davi713albano-coder/victory-fork/actions/runs/45491513609
    • cargo clippy --workspace --all-targets --locked -- -D warnings: passed
    • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passed
    • cargo test --workspace --locked (including xtask asset-policy check and dxil.dll validation): 497 passed, 0 failed (emit::barycentric_tests::dead_input_read_is_cleared_from_isg1_after_opt ... ok)

(No title data used. AI-assisted.)

<!-- greyfinch-sync:fxceless/victory-fork:issue:6591945016 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/122). Originally posted by [davi713albano-coder](https://github.com/davi713albano-coder) on 2026-11-24T21:39:31Z. --- ### Summary In `Shader::finish()` (`crates/victory-shader/src/emit/shader.rs`), `self.m.optimise(passes)` runs dead-code elimination (`opt::DEAD`) before writing `dx.entryPoints` and `ISG1`. Because `dx.op.loadInput.*` and `dx.op.attributeAtVertex.*` are declared `Attr::ReadNone` (`Effect::Pure`), dead input reads can be eliminated during clean-up. Previously `Shader::finish()` recomputed `self.flags` via `self.m.usage()`, but left `self.inputs[id].usage` (and `flags::BARYCENTRICS`) at their pre-optimization values, so `ISG1` could still mark eliminated channels as read (see #53). ### Changes - `crates/victory-shader/src/emit/bitcode/opt.rs`: - Track `barycentrics` (`dx.op.attributeAtVertex.*`) in `Module::usage()`. - Add `Module::input_usage(count)` to compute the surviving per-element read bitmask from reachable `dx.op.loadInput.*` and `dx.op.attributeAtVertex.*` calls. - `crates/victory-shader/src/emit/shader.rs`: - After `self.m.optimise(passes)`, refresh `self.inputs[id].usage` from `self.m.input_usage(...)` and clear `flags::BARYCENTRICS` if neither `attributeAtVertex` nor an `SV_Barycentrics` (`kind == 28`) input remains. - `crates/victory-shader/src/emit/mod.rs`: - Add synthetic pixel-shader test `dead_input_read_is_cleared_from_isg1_after_opt` verifying that an unused interpolated channel is cleared from `ISG1`'s `ReadWriteMask` and passes `dxil.dll` validation. ### Verification - Fork CI (`windows-latest`): https://github.com/davi713albano-coder/victory-fork/actions/runs/45491513609 - `cargo clippy --workspace --all-targets --locked -- -D warnings`: passed - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: passed - `cargo test --workspace --locked` (including `xtask` asset-policy check and `dxil.dll` validation): 497 passed, 0 failed (`emit::barycentric_tests::dead_input_read_is_cleared_from_isg1_after_opt ... ok`) *(No title data used. AI-assisted.)*
adriaespii commented 2026-11-24 22:07:37 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by adriaespii on 2026-11-24T21:52:04Z.


Independent test run on commit 442d7c2 (AMD RDNA4):

  • Hardware: AMD Radeon RX 9070 (driver 32.0.32015.7029), AMD Ryzen 5 7600, Windows 11 Pro, Rust 1.98.1 (x86_64-pc-windows-msvc)
  • cargo clippy --workspace --all-targets -- -D warnings: 0 warnings
  • cargo test --workspace: 497 passed, 0 failed, 7 ignored (victory-shader: 211 passed, 0 failed, 2 ignored; victory-gpu: 110 passed, 0 failed, 1 ignored)
  • Not tested: retail shader pack / live game run (no game files on this machine)

AI use: Antigravity (Gemini 4 Neon) ran clippy/tests locally and wrote this report.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7145493858 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/122#issuecomment-7145493858). Originally posted by [adriaespii](https://github.com/adriaespii) on 2026-11-24T21:52:04Z. --- Independent test run on commit `442d7c2` (AMD RDNA4): - **Hardware:** AMD Radeon RX 9070 (driver 32.0.32015.7029), AMD Ryzen 5 7600, Windows 11 Pro, Rust 1.98.1 (`x86_64-pc-windows-msvc`) - `cargo clippy --workspace --all-targets -- -D warnings`: 0 warnings - `cargo test --workspace`: 497 passed, 0 failed, 7 ignored (`victory-shader`: 211 passed, 0 failed, 2 ignored; `victory-gpu`: 110 passed, 0 failed, 1 ignored) - **Not tested:** retail shader pack / live game run (no game files on this machine) *AI use: Antigravity (Gemini 4 Neon) ran clippy/tests locally and wrote this report.*
arminkhaleghirod commented 2026-11-24 23:09:35 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by arminkhaleghirod on 2026-11-24T22:23:51Z.


Merged onto main 90228a7 and ran victory translate --validate over the full title (26,148 programs) on Windows 11 / RTX 4080.

No change: every failure count matches main, and no new reason appears. What it changes at run time isn't covered by this check.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7146178166 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/122#issuecomment-7146178166). Originally posted by [arminkhaleghirod](https://github.com/arminkhaleghirod) on 2026-11-24T22:23:51Z. --- Merged onto main 90228a7 and ran `victory translate --validate` over the full title (26,148 programs) on Windows 11 / RTX 4080. No change: every failure count matches main, and no new reason appears. What it changes at run time isn't covered by this check.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/122:upstream-pr/122'
git switch 'upstream-pr/122'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/122'
git switch 'upstream-pr/122'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/122'
git switch 'upstream-pr/122'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/122'
git switch 'main'
git merge --squash 'upstream-pr/122'
git switch 'main'
git merge --ff-only 'upstream-pr/122'
git switch 'main'
git merge 'upstream-pr/122'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
fxceless/victory-fork!122
No description provided.