frame: cache tiling swizzle tables and derive texture BPP from format table #197

Open
github-bot wants to merge 1 commit from github-bot/gh-197 into main AGit
Owner

@⁠Mhyster on GitHub · 2026-12-02 07:15 UTC · original
Mhyster:opt/frame-tiling-cache-and-bpp → main · +114 −20 · 2 files · 1 commits · open

What

Brings greenfield/frame/src/tiling.rs in sync with crates/victory-formats/src/texture.rs and fixes inaccurate texture size estimates in greenfield/frame/src/objects.rs:

  1. Share immutable swizzle tables in frame::tiling::Layout (greenfield/frame/src/tiling.rs shared_pattern, Layout::tiled):
    • Previously, every Layout::new allocated 6 Vec<u32> buffers (3 in pattern, 3 in spread) and recomputed the bit-scatter tables from scratch on every TextureInfo::build, level_ranges, hold_from, base_level, console_layout, and row_words call.
    • Now ports victory_formats::texture::shared_pattern (OnceLock table indexed by micro-tile kind, block size, and element log2), eliminating per-layout heap allocations and redundant bit-scatter work, and mirrors victory_formats's d.block == 1 check rejecting multisampled block-compressed layouts.
  2. Derive objects::bytes_per_pixel from crate::tiling::format and halve 3D mip depth (greenfield/frame/src/objects.rs bytes_per_pixel, texture_estimate):
    • Replaces the hand-written format match (which double-counted 26..=29 including R8G8B8A8_UNORM at 8 BPP instead of 4 BPP, quadruple-counted 97 BC7_TYPELESS at 4 BPP instead of 1 BPP, and missed 1, 115, 118..=120, and 190) with crate::tiling::format(f) (keeping 12 BPP for 96-bit RGB32 formats 5..=8), and halves 3D depth across mip levels in texture_estimate.

The reference

  • crates/victory-formats/src/texture.rs (shared_pattern, Layout::new, format): the root crate already caches immutable swizzle tables in a OnceLock array and validates d.block == 1 for multisampled textures; greenfield/frame/src/tiling.rs had drifted behind that optimization.

Evidence

  • Unit tests added in greenfield/frame:
    • tiling::format_tests::layouts_share_identical_swizzle_tables (std::ptr::eq on Layout::pattern)
    • tiling::format_tests::bc_formats_reject_multisampled_layouts
    • objects::heap_tests::texture_estimate_uses_format_table_and_halves_3d_depth
  • Local CI checks passed (Linux x86_64):
    • cargo test -p victory-shader -p victory-formats -p victory-core -p xtask --locked
    • (cd greenfield && cargo test -p umem -p frame -p vkback --lib --locked && cargo test -p vkback --test policy --locked) (16/16 frame, 22/22 umem, 168 passed / 3 ignored vkback, 6/6 policy)
    • cargo clippy --all-targets --locked -- -D warnings on root native crates, greenfield, greenfield/wine, and greenfield/vkback/translate.
  • Not run: live game / AMD GPU A/B frame timing (frames.py) and Vulkan validation run (house scene) could not be run in this session (no live game run performed); cargo xwin clippy runs in GitHub Actions CI.

Checklist (docs/AGENTS.md)

  • One topic (rule 31); docs/TASKS.md not edited, the fixed item named above (rule 29)
  • "Allow edits by maintainers" on; after review, no force-push and no close-and-reopen (it drops the maintainers' commits)
  • No fallback or second path for a case that can't happen, in title data or in our own setup (rule 33); unexpected input fails loudly (rule 9)
  • Constants come from the console, the hardware or the title's data, not tuned by eye or ear (rule 9b)
  • Every switch is listed, read in one place, and a bad value stops the start (rule 2)
  • Queues and other externally synchronized Vulkan objects are used under their lock (rule 35)
  • Every unsafe block has a // SAFETY: comment; no raw pointer around the borrow checker (rule 36)
  • Clippy clean; tests call the production code; TRANSLATOR_VERSION bumped if the translator's output changes (rule 27)
  • Comments say what is true now and name functions, not line numbers (rule 3)
  • Nothing from the title, and no pointers to where non-free data can be found (hard constraints)
**@⁠Mhyster** on GitHub · 2026-12-02 07:15 UTC · [original](https://github.com/vktory6/VKtory/pull/197) `Mhyster:opt/frame-tiling-cache-and-bpp` → `main` · +114 −20 · 2 files · 1 commits · open ## What Brings `greenfield/frame/src/tiling.rs` in sync with `crates/victory-formats/src/texture.rs` and fixes inaccurate texture size estimates in `greenfield/frame/src/objects.rs`: 1. **Share immutable swizzle tables in `frame::tiling::Layout`** (`greenfield/frame/src/tiling.rs` `shared_pattern`, `Layout::tiled`): - Previously, every `Layout::new` allocated 6 `Vec<u32>` buffers (3 in `pattern`, 3 in `spread`) and recomputed the bit-scatter tables from scratch on every `TextureInfo::build`, `level_ranges`, `hold_from`, `base_level`, `console_layout`, and `row_words` call. - Now ports `victory_formats::texture::shared_pattern` (`OnceLock` table indexed by micro-tile kind, block size, and element log2), eliminating per-layout heap allocations and redundant bit-scatter work, and mirrors `victory_formats`'s `d.block == 1` check rejecting multisampled block-compressed layouts. 2. **Derive `objects::bytes_per_pixel` from `crate::tiling::format` and halve 3D mip depth** (`greenfield/frame/src/objects.rs` `bytes_per_pixel`, `texture_estimate`): - Replaces the hand-written format match (which double-counted `26..=29` including `R8G8B8A8_UNORM` at 8 BPP instead of 4 BPP, quadruple-counted `97` `BC7_TYPELESS` at 4 BPP instead of 1 BPP, and missed `1`, `115`, `118..=120`, and `190`) with `crate::tiling::format(f)` (keeping 12 BPP for 96-bit RGB32 formats `5..=8`), and halves 3D `depth` across mip levels in `texture_estimate`. ## The reference - `crates/victory-formats/src/texture.rs` (`shared_pattern`, `Layout::new`, `format`): the root crate already caches immutable swizzle tables in a `OnceLock` array and validates `d.block == 1` for multisampled textures; `greenfield/frame/src/tiling.rs` had drifted behind that optimization. ## Evidence - Unit tests added in `greenfield/frame`: - `tiling::format_tests::layouts_share_identical_swizzle_tables` (`std::ptr::eq` on `Layout::pattern`) - `tiling::format_tests::bc_formats_reject_multisampled_layouts` - `objects::heap_tests::texture_estimate_uses_format_table_and_halves_3d_depth` - Local CI checks passed (Linux x86_64): - `cargo test -p victory-shader -p victory-formats -p victory-core -p xtask --locked` - `(cd greenfield && cargo test -p umem -p frame -p vkback --lib --locked && cargo test -p vkback --test policy --locked)` (16/16 frame, 22/22 umem, 168 passed / 3 ignored vkback, 6/6 policy) - `cargo clippy --all-targets --locked -- -D warnings` on root native crates, `greenfield`, `greenfield/wine`, and `greenfield/vkback/translate`. - **Not run**: live game / AMD GPU A/B frame timing (`frames.py`) and Vulkan validation run (house scene) could not be run in this session (no live game run performed); `cargo xwin clippy` runs in GitHub Actions CI. ## Checklist (docs/AGENTS.md) - [x] One topic (rule 31); `docs/TASKS.md` not edited, the fixed item named above (rule 29) - [x] "Allow edits by maintainers" on; after review, no force-push and no close-and-reopen (it drops the maintainers' commits) - [x] No fallback or second path for a case that can't happen, in title data or in our own setup (rule 33); unexpected input fails loudly (rule 9) - [x] Constants come from the console, the hardware or the title's data, not tuned by eye or ear (rule 9b) - [x] Every switch is listed, read in one place, and a bad value stops the start (rule 2) - [x] Queues and other externally synchronized Vulkan objects are used under their lock (rule 35) - [x] Every `unsafe` block has a `// SAFETY:` comment; no raw pointer around the borrow checker (rule 36) - [x] Clippy clean; tests call the production code; `TRANSLATOR_VERSION` bumped if the translator's output changes (rule 27) - [x] Comments say what is true now and name functions, not line numbers (rule 3) - [x] Nothing from the title, and no pointers to where non-free data can be found (hard constraints)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 07:19:12 +00:00
Author
Owner

@⁠vktory6 on GitHub · 2026-12-02 15:28 UTC · original

Thanks. Two topics here:

  • The swizzle-table cache copies shared_pattern into frame/tiling.rs, which is the duplicate of victory-formats/texture.rs. The TASKS item "One tiling and format table" says to remove that copy, not extend it. Taking that task would give you the cache for free. The speed claim is also unmeasured so far.
  • The bytes-per-pixel fix is correct (format 28 is 4 B, BC7 1 B, 3D depth halves per mip). As its own PR, it should derive from victory-formats' table.
**@⁠vktory6** on GitHub · 2026-12-02 15:28 UTC · [original](https://github.com/vktory6/VKtory/pull/197#issuecomment-7350391121) Thanks. Two topics here: - **The swizzle-table cache** copies `shared_pattern` into `frame/tiling.rs`, which is the duplicate of `victory-formats/texture.rs`. The TASKS item "One tiling and format table" says to remove that copy, not extend it. Taking that task would give you the cache for free. The speed claim is also unmeasured so far. - **The bytes-per-pixel fix** is correct (format 28 is 4 B, BC7 1 B, 3D depth halves per mip). As its own PR, it should derive from victory-formats' table.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/197/head:github-bot/gh-197'
git switch 'github-bot/gh-197'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-197'
git switch 'github-bot/gh-197'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-197'
git switch 'github-bot/gh-197'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-197'
git switch 'main'
git merge --squash 'github-bot/gh-197'
git switch 'main'
git merge --ff-only 'github-bot/gh-197'
git switch 'main'
git merge 'github-bot/gh-197'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.