Shaders/io+native: prioritize VS fetched attributes over hardware IDs, check VGPR overflow, and clamp thread_id_vgprs #677

Open
github-bot wants to merge 1 commit from github-bot/gh-677 into main AGit
Owner

@⁠AscilCH on GitHub · 2026-11-25 04:20 UTC · original
AscilCH:fix/shader-vs-input-shadowing-vgpr-overflow-and-tidig-clamp → main · +122 −7 · 2 files · 1 commits · open

Summary

Fixes three I/O-raising and shader-metadata bugs in crates/victory-shader:

  1. Silent VS attribute shadowing by hardware IDs (crates/victory-shader/src/io.rs):

    • On RDNA2, the fetch shader runs before the VS body and loads vertex attributes into VsInput.vgpr + channel, legitimately reusing v0..v3 when SV_VertexID/SV_InstanceID are not needed afterwards.
    • io::raise previously appended fetched inputs after (V(0), VertexId), (V(2), PrimitiveId), (V(3), InstanceId) while looking up with first-match loaded.iter().find(...), silently lowering fetched attributes in v0/v3 as SV_VertexID/SV_InstanceID and aborting on v2 (Input::PrimitiveId).
    • Fetched inputs are now registered before the hardware fallback VGPRs.
  2. Unchecked u8 VGPR overflow on malformed FSSM (crates/victory-shader/src/io.rs):

    • i.vgpr + channel could panic in debug or wrap in release when vgpr >= 253 with upper mask bits set. Replaced with checked_add, returning Err(ShaderError::Malformed("vertex input VGPR out of range")).
  3. Out-of-range 4th thread-ID dimension (crates/victory-shader/src/native.rs):

    • ComputeIo::thread_id_vgprs() returned 4 when 2-bit TIDIG_COMP_CNT was 3, emitting invalid Input::ThreadIdInGroup(3) (dx.op.threadIdInGroup(95, 3)). Clamped via ((self.rsrc2 >> 11 & 3) as u8).min(2) + 1 to match its 1..=3 contract.

Verification

  • cargo test -p victory-shader --lib --locked -- io::tests native::tests — 18 passed, 0 failed (including new vs_fetched_attributes_in_v0_to_v3_override_hardware_ids_and_reject_vgpr_overflow and compute_thread_id_vgprs_is_clamped_to_three_dimensions)
  • cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings — clean (0 warnings)
  • cargo xtask policy — asset policy: 169 files ok

(AI-assisted; synthetic unit tests only, no game data.)

**@⁠AscilCH** on GitHub · 2026-11-25 04:20 UTC · [original](https://github.com/fxceless/victory-fork/pull/677) `AscilCH:fix/shader-vs-input-shadowing-vgpr-overflow-and-tidig-clamp` → `main` · +122 −7 · 2 files · 1 commits · open ### Summary Fixes three I/O-raising and shader-metadata bugs in `crates/victory-shader`: 1. **Silent VS attribute shadowing by hardware IDs (`crates/victory-shader/src/io.rs`)**: - On RDNA2, the fetch shader runs before the VS body and loads vertex attributes into `VsInput.vgpr + channel`, legitimately reusing `v0..v3` when `SV_VertexID`/`SV_InstanceID` are not needed afterwards. - `io::raise` previously appended fetched `inputs` *after* `(V(0), VertexId)`, `(V(2), PrimitiveId)`, `(V(3), InstanceId)` while looking up with first-match `loaded.iter().find(...)`, silently lowering fetched attributes in `v0`/`v3` as `SV_VertexID`/`SV_InstanceID` and aborting on `v2` (`Input::PrimitiveId`). - Fetched `inputs` are now registered before the hardware fallback VGPRs. 2. **Unchecked `u8` VGPR overflow on malformed FSSM (`crates/victory-shader/src/io.rs`)**: - `i.vgpr + channel` could panic in debug or wrap in release when `vgpr >= 253` with upper mask bits set. Replaced with `checked_add`, returning `Err(ShaderError::Malformed("vertex input VGPR out of range"))`. 3. **Out-of-range 4th thread-ID dimension (`crates/victory-shader/src/native.rs`)**: - `ComputeIo::thread_id_vgprs()` returned `4` when 2-bit `TIDIG_COMP_CNT` was `3`, emitting invalid `Input::ThreadIdInGroup(3)` (`dx.op.threadIdInGroup(95, 3)`). Clamped via `((self.rsrc2 >> 11 & 3) as u8).min(2) + 1` to match its `1..=3` contract. ### Verification - `cargo test -p victory-shader --lib --locked -- io::tests native::tests` — **18 passed, 0 failed** (including new `vs_fetched_attributes_in_v0_to_v3_override_hardware_ids_and_reject_vgpr_overflow` and `compute_thread_id_vgprs_is_clamped_to_three_dimensions`) - `cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings` — **clean (0 warnings)** - `cargo xtask policy` — **asset policy: 169 files ok** *(AI-assisted; synthetic unit tests only, no game data.)*
Three fixes in `crates/victory-shader/src/{io.rs, native.rs}`:

1. `io::raise` (`StageIo::Vs`):
   `loaded` previously inserted `(V(0), VertexId)`, `(V(2), PrimitiveId)`,
   `(V(3), InstanceId)` *before* the fetch-shader `inputs`, and matched with
   first-match `loaded.iter().find(...)`. When the fetch shader overwrites
   `v0..v3` with fetched vertex attributes (because the VS does not need
   `SV_VertexID`/`SV_InstanceID` after vertex fetch), those attributes were
   silently shadowed as `VertexId`/`InstanceId` or aborted translation on
   `PrimitiveId`. Register fetched `inputs` before the hardware fallbacks.

2. `io::raise` (`StageIo::Vs` VGPR overflow):
   `VsInput.vgpr` is an arbitrary `u8` (`0..=255`) from the FSSM table, so
   `i.vgpr + channel` panicked in debug or wrapped to `v0..v2` in release for
   `vgpr >= 253` with upper channel bits set. Use `checked_add` and return
   `ShaderError::Malformed("vertex input VGPR out of range")`.

3. `ComputeIo::thread_id_vgprs` (`native.rs`):
   `(self.rsrc2 >> 11 & 3) as u8 + 1` returned `4` when the 2-bit
   `TIDIG_COMP_CNT` field was `3`, contradicting its `1..=3` contract and
   producing an invalid `Input::ThreadIdInGroup(3)` -> DXIL
   `threadIdInGroup(95, 3)`. Clamp with `.min(2) + 1`.

Add `io::tests::vs_fetched_attributes_in_v0_to_v3_override_hardware_ids_and_reject_vgpr_overflow`
and `native::tests::compute_thread_id_vgprs_is_clamped_to_three_dimensions`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:48:47 +00:00
Author
Owner

@⁠JRamos1993 on GitHub · 2026-11-25 05:27 UTC · original

Offline check on the retail shader pack: this changes no emitted shader of the title.

victory translate --validate --list over the title's full shader pack (26,084 programs, 14,247 vertex and pixel programs with I/O raised) on an RTX 5090, main 310c6eb against this head merged onto it:

  • Validated: 25,382 in both, none lost.
  • DXIL: with a local hash on each validated line, 0 programs' DXIL differs.

So in this title no vertex program's fetched attributes land in v0–v3 where the order would matter. The batch tool raises I/O from each container's own data, so this covers the containers as shipped, not anything a pipeline adds at run time.

AI use: Claude Code with Claude Opus 5.5 ran the pack and wrote this. Nothing from the title is in it.

**@⁠JRamos1993** on GitHub · 2026-11-25 05:27 UTC · [original](https://github.com/fxceless/victory-fork/pull/677#issuecomment-7153793994) **Offline check on the retail shader pack: this changes no emitted shader of the title.** `victory translate --validate --list` over the title's full shader pack (26,084 programs, 14,247 vertex and pixel programs with I/O raised) on an RTX 5090, `main` `310c6eb` against this head merged onto it: - **Validated:** 25,382 in both, none lost. - **DXIL:** with a local hash on each validated line, **0 programs' DXIL differs**. So in this title no vertex program's fetched attributes land in `v0`–`v3` where the order would matter. The batch tool raises I/O from each container's own data, so this covers the containers as shipped, not anything a pipeline adds at run time. AI use: Claude Code with Claude Opus 5.5 ran the pack and wrote this. Nothing from the title is in it.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/677/head:github-bot/gh-677'
git switch 'github-bot/gh-677'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-677'
git switch 'github-bot/gh-677'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-677'
git switch 'github-bot/gh-677'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-677'
git switch 'main'
git merge --squash 'github-bot/gh-677'
git switch 'main'
git merge --ff-only 'github-bot/gh-677'
git switch 'main'
git merge 'github-bot/gh-677'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.