Formats: share immutable texture swizzle tables #993

Manually merged
github merged 1 commit from gh-pr/993/head into gh-pr/993/base 2026-11-26 04:16:21 +00:00
Owner

@⁠TG0000 on GitHub · 2026-11-24 14:45 UTC · original
TG0000:perf/shared-texture-swizzle-tables → main · +147 −6 · 2 files · 1 commits · merged 2026-11-25 00:12 UTC

Summary

Texture::new built the three swizzle tables of its layout on every call, although they depend only on the micro-tile kind, the block size and the element size. This shares one immutable table set per key through OnceLocks (at most 45 keys); extents, mips and array slices still only affect the base address. No layout changes: linear and unsupported modes keep an empty table.

Measured

cargo run --release -p victory-formats --example texture_layout_bench (included), Ryzen 9 5900X, Windows 11. Three processes per side, interleaved, median of the three; other builds were running, so treat these as approximate. ns per layout:

Layout main this PR
BC7 64KB_D 1049 298
BC1 64KB_S 1205 236
RGBA8 4KB_D 950 357
R8 64KB_S 3034 260
RGBA8 volume 64KB_S 980 308
RGBA8 linear (no table; unchanged code path) 339 370

The linear rows are within run-to-run noise (273-427 ns on main, 321-445 here). The bench's checksums are identical on both sides. This is a microbenchmark of layout creation; in-game frame time was not measured.

Verification

Rust 1.98.1 MSVC, base ffe310e:

  • cargo test --workspace --locked --no-fail-fast: all pass, 343 passed, 0 failed. An earlier run on a fully loaded PC failed frame::tests::waits_end_on_ticks_and_count_frames in victory-gpu, which this PR does not touch; #174 and #689 are about that kind of wait.
  • cargo clippy --workspace --all-targets --locked -- -D warnings, with and without --all-features: clean.
  • The new test compares every shared table with a freshly built one for 8 modes and 5 element sizes, and checks that two layouts of the same key share the same table.

Overlap

#603 inlines micro-tile copies when detiling, and #263, #315, #351 and #629 also edit texture.rs. #603 changes the detile loop, not table construction.

AI-assisted: written by GPT 6.2 Sol, benchmarked and checked by Claude Opus 5.5. No game data.

🤖 Generated with Claude Code

**@⁠TG0000** on GitHub · 2026-11-24 14:45 UTC · [original](https://github.com/Marvisak/VIctory/pull/993) `TG0000:perf/shared-texture-swizzle-tables` → `main` · +147 −6 · 2 files · 1 commits · merged 2026-11-25 00:12 UTC ## Summary `Texture::new` built the three swizzle tables of its layout on every call, although they depend only on the micro-tile kind, the block size and the element size. This shares one immutable table set per key through `OnceLock`s (at most 45 keys); extents, mips and array slices still only affect the base address. No layout changes: linear and unsupported modes keep an empty table. ## Measured `cargo run --release -p victory-formats --example texture_layout_bench` (included), Ryzen 9 5900X, Windows 11. Three processes per side, interleaved, median of the three; other builds were running, so treat these as approximate. ns per layout: | Layout | main | this PR | |---|---|---| | BC7 64KB_D | 1049 | 298 | | BC1 64KB_S | 1205 | 236 | | RGBA8 4KB_D | 950 | 357 | | R8 64KB_S | 3034 | 260 | | RGBA8 volume 64KB_S | 980 | 308 | | RGBA8 linear (no table; unchanged code path) | 339 | 370 | The linear rows are within run-to-run noise (273-427 ns on main, 321-445 here). The bench's checksums are identical on both sides. This is a microbenchmark of layout creation; **in-game frame time was not measured**. ## Verification Rust 1.98.1 MSVC, base `ffe310e`: - `cargo test --workspace --locked --no-fail-fast`: all pass, 343 passed, 0 failed. An earlier run on a fully loaded PC failed `frame::tests::waits_end_on_ticks_and_count_frames` in `victory-gpu`, which this PR does not touch; #174 and #689 are about that kind of wait. - `cargo clippy --workspace --all-targets --locked -- -D warnings`, with and without `--all-features`: clean. - The new test compares every shared table with a freshly built one for 8 modes and 5 element sizes, and checks that two layouts of the same key share the same table. ## Overlap #603 inlines micro-tile copies when detiling, and #263, #315, #351 and #629 also edit `texture.rs`. #603 changes the detile loop, not table construction. AI-assisted: written by GPT 6.2 Sol, benchmarked and checked by Claude Opus 5.5. No game data. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:16:20 +00:00
github manually merged commit 64b80c3109 into gh-pr/993/base 2026-11-26 04:16:21 +00:00
Author
Owner

@⁠MichaelSmithAI on GitHub · 2026-11-24 15:00 UTC · original

We applied the table-sharing change to our staged texture branch and compared the tiled output with its parent. Across ten synthetic 137×75 layouts, all 4,307,968 bytes matched. The cases included BC1 and BC7, mip tails, array slices, 3D volumes, separate depth and stencil planes, and a linear control. Each build also detiled every patterned subresource back to its input, including preservation of row padding.

The victory-formats suite passed 24 tests at the exact PR head (64b80c3) and 27 on the integrated branch, with four ignored on each. This checks byte compatibility on the staged texture code. We did not measure title frame time.

**@⁠MichaelSmithAI** on GitHub · 2026-11-24 15:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/993#issuecomment-7135303264) We applied the table-sharing change to our staged texture branch and compared the tiled output with its parent. Across ten synthetic 137×75 layouts, all 4,307,968 bytes matched. The cases included BC1 and BC7, mip tails, array slices, 3D volumes, separate depth and stencil planes, and a linear control. Each build also detiled every patterned subresource back to its input, including preservation of row padding. The victory-formats suite passed 24 tests at the exact PR head (64b80c3) and 27 on the integrated branch, with four ignored on each. This checks byte compatibility on the staged texture code. We did not measure title frame time.
Author
Owner

@⁠TG0000 on GitHub · 2026-11-24 15:07 UTC · original

Thanks for the byte comparison and the integrated run.

**@⁠TG0000** on GitHub · 2026-11-24 15:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/993#issuecomment-7135507999) Thanks for the byte comparison and the integrated run.
Author
Owner

@⁠Zipettte on GitHub · 2026-11-24 15:13 UTC · original

Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 64b80c3: cargo test -p victory-formats passes, 24 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

**@⁠Zipettte** on GitHub · 2026-11-24 15:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/993#issuecomment-7135649787) Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 64b80c3: `cargo test -p victory-formats` passes, 24 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
Author
Owner

@⁠TG0000 on GitHub · 2026-11-24 16:01 UTC · original

Thanks for the review. On (1): both are array indexing, so a value out of range panics at the lookup (an underflow of block_index gives an index far out of range) and cannot read another table. I left the head unchanged; I can add the debug_asserts if the maintainer prefers them.

**@⁠TG0000** on GitHub · 2026-11-24 16:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/993#issuecomment-7136984175) Thanks for the review. On (1): both are array indexing, so a value out of range panics at the lookup (an underflow of `block_index` gives an index far out of range) and cannot read another table. I left the head unchanged; I can add the `debug_assert`s if the maintainer prefers them.
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!993
No description provided.