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

Closed
github-bot wants to merge 1 commit from gh-pr/415/head into gh-pr/415/base
Owner

@⁠enzoduarte1 on GitHub · 2026-11-24 03:08 UTC · original
enzoduarte1:gpu/shader-cache-root-codes → main · +33 −10 · 1 files · 1 commits · closed without merging

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.
**@⁠enzoduarte1** on GitHub · 2026-11-24 03:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/415) `enzoduarte1:gpu/shader-cache-root-codes` → `main` · +33 −10 · 1 files · 1 commits · closed without merging ## 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:03:00 +00:00
github-bot closed this pull request 2026-11-26 04:03:00 +00:00
Author
Owner

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

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.

**@⁠jeremygold02** on GitHub · 2026-11-24 04:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/415#issuecomment-7122177267) 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:28 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 00:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/415#issuecomment-7148553202) <!-- 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)_
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 21:58 UTC · original

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.

**@⁠Marvisak** on GitHub · 2026-11-25 21:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/415#issuecomment-7175779997) 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

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