GPU: use native root type codes in the shader cache #415

Closed
enzoduarte1 wants to merge 1 commit from upstream-pr/415 into main
enzoduarte1 commented 2026-11-24 03:08:34 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by enzoduarte1 on 2026-11-24T03:08:34Z.


What

shader_cache.rs encoded RootType with its own numbering that disagreed with the one the console shader uses (RootType::from_raw in victory-shader/src/native.rs):

  • raw 2 is Other(2) in the native parser, but the cache decoded it as Table;
  • Other(x) was written as 6 + x, which overflows in debug builds and wraps into a known code in release builds for any x >= u32::MAX - 5. The native parser reads that value straight from shader bytes, so it is reachable.

The cache now stores the native raw values directly, making encode/decode bijective for every value the parser can produce. The cache key already includes the executable's BLAKE3, so entries written by an older build are not reused. A round-trip test covers all native codes plus Other(u32::MAX).

Tested

  • Windows 11, Rust 1.98.1, x86_64-pc-windows-gnu (no MSVC linker on this machine).
  • cargo test -p victory-gpu --lib shader_cache::: 3 passed.
  • cargo test --workspace --exclude victory-loader -- --test-threads=1: all suites passed.
  • cargo clippy -p victory-gpu --all-targets -- -A clippy::undocumented_unsafe_blocks -D warnings: clean. The allowed lint is the pre-existing warning fixed by PR #355.
  • rustfmt --edition 2024 --check crates/victory-gpu/src/shader_cache.rs and git diff --check: clean.
  • cargo xtask policy: 151 files ok. No game files or data taken from them were added.
  • Not tested: cargo test -p victory-loader --test load_probe. Its fixture passes MSVC's /DELAYLOAD flag, which MinGW rejects here; the same failure occurs on unmodified main. cargo fmt --all --check also has unrelated pre-existing diffs, so no other files were reformatted.

Checklist

  • cargo fmt, cargo clippy --workspace --all-targets and cargo test --workspace pass — see the toolchain limitations above; the changed crate is clean.
  • cargo xtask policy passes. The change adds no game files or data taken from them (docs/asset-policy.md).
  • If an AI tool wrote part of this change, the description says so: an AI tool assisted with the code and test; I reviewed and ran them.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6573723295 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/415). Originally posted by [enzoduarte1](https://github.com/enzoduarte1) on 2026-11-24T03:08:34Z. --- ## What `shader_cache.rs` encoded `RootType` with its own numbering that disagreed with the one the console shader uses (`RootType::from_raw` in `victory-shader/src/native.rs`): - raw `2` is `Other(2)` in the native parser, but the cache decoded it as `Table`; - `Other(x)` was written as `6 + x`, which **overflows in debug builds** and wraps into a known code in release builds for any `x >= u32::MAX - 5`. The native parser reads that value straight from shader bytes, so it is reachable. The cache now stores the native raw values directly, making encode/decode bijective for every value the parser can produce. The cache key already includes the executable's BLAKE3, so entries written by an older build are not reused. A round-trip test covers all native codes plus `Other(u32::MAX)`. ## Tested - Windows 11, Rust 1.98.1, `x86_64-pc-windows-gnu` (no MSVC linker on this machine). - `cargo test -p victory-gpu --lib shader_cache::`: 3 passed. - `cargo test --workspace --exclude victory-loader -- --test-threads=1`: all suites passed. - `cargo clippy -p victory-gpu --all-targets -- -A clippy::undocumented_unsafe_blocks -D warnings`: clean. The allowed lint is the pre-existing warning fixed by PR #355. - `rustfmt --edition 2024 --check crates/victory-gpu/src/shader_cache.rs` and `git diff --check`: clean. - `cargo xtask policy`: 151 files ok. No game files or data taken from them were added. - Not tested: `cargo test -p victory-loader --test load_probe`. Its fixture passes MSVC's `/DELAYLOAD` flag, which MinGW rejects here; the same failure occurs on unmodified `main`. `cargo fmt --all --check` also has unrelated pre-existing diffs, so no other files were reformatted. ## Checklist - [ ] `cargo fmt`, `cargo clippy --workspace --all-targets` and `cargo test --workspace` pass — see the toolchain limitations above; the changed crate is clean. - [x] `cargo xtask policy` passes. The change adds no game files or data taken from them (`docs/asset-policy.md`). - [x] If an AI tool wrote part of this change, the description says so: an AI tool assisted with the code and test; I reviewed and ran them.
mercuryVM commented 2026-11-24 06:52:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T05:35:40Z.

Review: APPROVED


Tested 6924b09 on Windows 11, RTX 5070, MSVC: cargo test --workspace --no-fail-fast passes (265 passed, 0 failed).

  • Checked against RootType::from_raw in victory-shader/src/native.rs. It maps 0/1/3/4/5/6 to the named variants and everything else to Other(n), so the new root_code/root_type are exact inverses for every value from_raw can produce. The old 6 + x could overflow on Other(x).
  • Old cache entries: shader_cache.rs keys on the BLAKE3 of our own current_exe(). Any build with this change has a different fingerprint, so entries written with the old numbering are never decoded with the new one.

No issues found.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6034217916 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/415#pullrequestreview-6034217916). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T05:35:40Z. **Review:** APPROVED --- Tested 6924b09 on Windows 11, RTX 5070, MSVC: `cargo test --workspace --no-fail-fast` passes (265 passed, 0 failed). - Checked against `RootType::from_raw` in `victory-shader/src/native.rs`. It maps 0/1/3/4/5/6 to the named variants and everything else to `Other(n)`, so the new `root_code`/`root_type` are exact inverses for every value `from_raw` can produce. The old `6 + x` could overflow on `Other(x)`. - Old cache entries: `shader_cache.rs` keys on the BLAKE3 of our own `current_exe()`. Any build with this change has a different fingerprint, so entries written with the old numbering are never decoded with the new one. No issues found. AI-assisted (Claude Code).
jeremygold02 commented 2026-11-24 06:55:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-24T04:36:40Z.


Thanks @enzoduarte1 for aligning cached root types with their native codes. I tested head 6924b095e3bfc128a3c85b3edc3332cd94274f5a with:

cargo test --locked -p victory-gpu --lib shader_cache:: -- --test-threads=1

Result: 3 passed, 0 failed (42 filtered out). The tests check native root-type code round trips, cache entry encoding/decoding with damaged-entry rejection, and reuse of cached translations. These are cache-format unit tests; they do not exercise a title’s shader workload.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7122177267 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/415#issuecomment-7122177267). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-24T04:36:40Z. --- Thanks @enzoduarte1 for aligning cached root types with their native codes. I tested head `6924b095e3bfc128a3c85b3edc3332cd94274f5a` with: ``` cargo test --locked -p victory-gpu --lib shader_cache:: -- --test-threads=1 ``` Result: 3 passed, 0 failed (42 filtered out). The tests check native root-type code round trips, cache entry encoding/decoding with damaged-entry rejection, and reuse of cached translations. These are cache-format unit tests; they do not exercise a title’s shader workload.
Marvisak commented 2026-11-25 01:07:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:28:52Z.


Automated triage for the maintainers.

Merge candidate. root_code in crates/victory-gpu/src/shader_cache.rs computed 6 + x for RootType::Other(x), while native.rs builds RootType::from_raw(le32(e, 0)) from a full u32, so x >= u32::MAX - 5 panics in debug builds and wraps to the wrong variant in release. Writing the raw codes directly fixes it, and the round-trip test covers it. One correction to the description: the old mapping did not decode raw 2 as Table (Other(2) was written as 8 and read back as Other(2)); only the overflow was wrong.

CI: no check runs on the head commit.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148553202 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/415#issuecomment-7148553202). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:28:52Z. --- <!-- victory-triage v1 head=6924b095e3bfc128a3c85b3edc3332cd94274f5a verdict=merge-candidate at=2026-11-25T00:22:34Z --> Automated triage for the maintainers. **Merge candidate.** `root_code` in `crates/victory-gpu/src/shader_cache.rs` computed `6 + x` for `RootType::Other(x)`, while `native.rs` builds `RootType::from_raw(le32(e, 0))` from a full u32, so `x >= u32::MAX - 5` panics in debug builds and wraps to the wrong variant in release. Writing the raw codes directly fixes it, and the round-trip test covers it. One correction to the description: the old mapping did not decode raw `2` as `Table` (`Other(2)` was written as 8 and read back as `Other(2)`); only the overflow was wrong. CI: no check runs on the head commit. --- _Generated by [Claude Code](https://claude.ai/code)_
upstream-sync closed this pull request 2026-11-25 22:02:38 +00:00
Marvisak commented 2026-11-25 22:04:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T21:58:39Z.


Automated triage for the maintainers, second look (a review against current main, with builds and tests where they could change the verdict).

Closing because the overflow it guards against cannot occur, and the change has a cost. root_code is applied only to HostShader::user_data entries, which the translator builds with roots Constants, Table or Descriptor only, so RootType::Other never reaches the cache and the current encoding round-trips every value that does. Editing shader_cache.rs changes the shader-cache key, so merging this would retranslate every shader for no change in output. It also collides with #1931's use of code 6.

If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7175779997 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/415#issuecomment-7175779997). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T21:58:39Z. --- Automated triage for the maintainers, second look (a review against current `main`, with builds and tests where they could change the verdict). Closing because the overflow it guards against cannot occur, and the change has a cost. `root_code` is applied only to `HostShader::user_data` entries, which the translator builds with roots `Constants`, `Table` or `Descriptor` only, so `RootType::Other` never reaches the cache and the current encoding round-trips every value that does. Editing `shader_cache.rs` changes the shader-cache key, so merging this would retranslate every shader for no change in output. It also collides with #1931's use of code 6. If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.

Pull request closed

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
Marvisak/VIctory!415
No description provided.