Skip to content

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

Closed
enzoduarte1 wants to merge 1 commit into
Marvisak:mainfrom
enzoduarte1:gpu/shader-cache-root-codes
Closed

enzoduarte1 wants to merge 1 commit into
Marvisak:mainfrom
enzoduarte1:gpu/shader-cache-root-codes

Conversation

@enzoduarte1

Copy link
Copy Markdown
Contributor

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 Chore: clear two workspace Clippy errors #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.

@jeremygold02

Copy link
Copy Markdown
Contributor

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.

@mercuryVM mercuryVM left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Owner

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

geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
…ndmask-415-111a

Shaders: track uniform and constant masks for v_cndmask (Marvisak#415)
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026
@Marvisak

Copy link
Copy Markdown
Owner

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 Marvisak closed this Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants