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

Open
AscilCH wants to merge 1 commit from upstream-pr/677 into main
AscilCH commented 2026-11-25 04:20:52 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by AscilCH on 2026-11-25T04:20:52Z.


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.)

<!-- greyfinch-sync:fxceless/victory-fork:issue:6597134559 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/677). Originally posted by [AscilCH](https://github.com/AscilCH) on 2026-11-25T04:20:52Z. --- ### 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.)*
JRamos1993 commented 2026-11-25 06:06:38 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by JRamos1993 on 2026-11-25T05:27:29Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7153793994 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/677#issuecomment-7153793994). Originally posted by [JRamos1993](https://github.com/JRamos1993) on 2026-11-25T05:27:29Z. --- **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 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/677:upstream-pr/677'
git switch 'upstream-pr/677'

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/677'
git switch 'upstream-pr/677'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/677'
git switch 'upstream-pr/677'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/677'
git switch 'main'
git merge --squash 'upstream-pr/677'
git switch 'main'
git merge --ff-only 'upstream-pr/677'
git switch 'main'
git merge 'upstream-pr/677'
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!677
No description provided.