perf(formats): add AVX2/SSE2 micro-tile texture detiler and DetilePool #191

Merged
Vladimir-Human merged 1 commit from upstream-pr/191 into main 2026-11-27 07:51:28 +00:00
Vladimir-Human commented 2026-11-27 07:31:37 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by Vladimir-Human on 2026-11-27T07:31:37Z.


Summary

  • Add crates/victory-formats/src/detile.rs: a thin tiled 256-byte micro-tile texture detiler/tiler with runtime-detected x86_64 AVX2/SSE2 kernels, portable fixed-width fallbacks, strict mutated-Layout geometry/bounds validation (including a 256-bit micro-tile disjointness proof), and a persistent worker pool (DetilePool, PARALLEL_MIN_BYTES = 2 MiB) with worker/caller panic and mutex-poison recovery.
  • Wire Layout::detile, Layout::tile, and TilingCache::tile (non-thick paths) in crates/victory-formats/src/texture.rs into the micro-tile implementation while preserving all existing public APIs, Layout::bytes_from (detile) vs Layout::size (tile) buffer requirements, overlapping depth-pitch rejection, and cached TilePlan tiling for thick 3D textures.
  • Bit-exact CPU parity / zero visual change: every addressable swizzle mode (LINEAR, SW_256B_*, SW_4KB_*, SW_64KB_*), element size (1–16 B), block size (1, 4), NPOT dimension, odd pitch, mip tail, bytes_from prefix buffer, TilingCache::tile, 1D/array/3D subresource, and parallel (2–4 MiB) / concurrent try_lock path is tested bit-for-bit against the pure scalar Layout::offset reference and pre-change chunked walk baseline. No rendering, shader, or visual output changes.

Benchmarks (x86_64 AVX2)

texture_layout_bench (Layout::new / Layout::offset non-regression)

cargo run --release -p victory-formats --example texture_layout_bench:

Case Before (70ac49d) After (447dbb1) Checksum
BC7 64KB_D 225.3 ns/layout 231.1 ns/layout 317445823744 (exact)
BC1 64KB_S 226.0 ns/layout 216.0 ns/layout 181077882496 (exact)
RGBA8 4KB_D 281.8 ns/layout 273.8 ns/layout 680375511872 (exact)
R8 64KB_S 222.9 ns/layout 225.0 ns/layout 316888273744 (exact)
RGBA8 volume 64KB_S 227.0 ns/layout 221.5 ns/layout 2957008742464 (exact)
RGBA8 linear 277.1 ns/layout 295.1 ns/layout 750198528576 (exact)

bench_detile_throughput (pre-change chunked walk vs AVX2/SSE2 + DetilePool)

cargo test --release -p victory-formats --locked -- --ignored --nocapture bench_detile_throughput:

Case Base ms Base MB/s Opt ms Opt MB/s vs Base vs Scalar
4K BC7 SW_64KB_D (16 MiB) 1.958 8173.4 0.729 21951.2 2.69x 11.35x
4K BC7 SW_64KB_S (16 MiB) 1.972 8115.6 0.574 27868.5 3.43x 17.07x
4K BC1 SW_64KB_D (8 MiB) 0.731 10943.3 0.140 57331.2 5.24x 57.27x
4K RGBA8 SW_64KB_D (64 MiB) 14.663 4364.9 3.885 16473.8 3.77x 33.10x
2K BC7 SW_64KB_D (4 MiB) 0.247 16163.7 0.100 40145.2 2.48x 19.94x
1K BC7 SW_64KB_D (1 MiB) 0.056 17980.4 0.050 19829.7 1.10x 8.66x
256 BC7 SW_64KB_D (64 KiB, ST) 0.002 25727.0 0.003 20963.7 0.81x 9.60x
4K BC7 MipChain (13 mips, 21.3 MiB) 2.319 9199.0 0.975 21880.2 2.38x 11.40x

Verification

  • cargo clippy -p victory-formats --all-targets --locked -- -D warnings (default & --all-features): 0 warnings.
  • cargo test -p victory-formats --release --locked -- --test-threads=1: 47 passed, 0 failed, 6 ignored.
  • cargo test -p victory-formats --locked detile::pool_tests -- --test-threads=1: 2 passed, 0 failed.
  • cargo test -p victory-formats --locked -- --test-threads=1: 47 passed, 0 failed, 6 ignored.
  • cargo run --locked -p xtask -- policy: asset policy: 304 files ok (cargo test --locked -p xtask -- --test-threads=1: 11 passed, 0 failed).
  • git diff --check origin/main..HEAD: clean.
<!-- greyfinch-sync:TaynanGT/Vice-Tay:issue:5522925019 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/191). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-27T07:31:37Z. --- ## Summary - Add `crates/victory-formats/src/detile.rs`: a thin tiled 256-byte micro-tile texture detiler/tiler with runtime-detected x86_64 AVX2/SSE2 kernels, portable fixed-width fallbacks, strict mutated-`Layout` geometry/bounds validation (including a 256-bit micro-tile disjointness proof), and a persistent worker pool (`DetilePool`, `PARALLEL_MIN_BYTES = 2 MiB`) with worker/caller panic and mutex-poison recovery. - Wire `Layout::detile`, `Layout::tile`, and `TilingCache::tile` (non-thick paths) in `crates/victory-formats/src/texture.rs` into the micro-tile implementation while preserving all existing public APIs, `Layout::bytes_from` (detile) vs `Layout::size` (tile) buffer requirements, overlapping depth-pitch rejection, and cached `TilePlan` tiling for thick 3D textures. - **Bit-exact CPU parity / zero visual change:** every addressable swizzle mode (`LINEAR`, `SW_256B_*`, `SW_4KB_*`, `SW_64KB_*`), element size (`1`–`16 B`), block size (`1`, `4`), NPOT dimension, odd pitch, mip tail, `bytes_from` prefix buffer, `TilingCache::tile`, 1D/array/3D subresource, and parallel (`2`–`4 MiB`) / concurrent `try_lock` path is tested bit-for-bit against the pure scalar `Layout::offset` reference and pre-change chunked `walk` baseline. No rendering, shader, or visual output changes. ## Benchmarks (x86_64 AVX2) ### `texture_layout_bench` (`Layout::new` / `Layout::offset` non-regression) `cargo run --release -p victory-formats --example texture_layout_bench`: | Case | Before (`70ac49d`) | After (`447dbb1`) | Checksum | |---|---:|---:|---:| | `BC7 64KB_D` | 225.3 ns/layout | 231.1 ns/layout | `317445823744` (exact) | | `BC1 64KB_S` | 226.0 ns/layout | 216.0 ns/layout | `181077882496` (exact) | | `RGBA8 4KB_D` | 281.8 ns/layout | 273.8 ns/layout | `680375511872` (exact) | | `R8 64KB_S` | 222.9 ns/layout | 225.0 ns/layout | `316888273744` (exact) | | `RGBA8 volume 64KB_S` | 227.0 ns/layout | 221.5 ns/layout | `2957008742464` (exact) | | `RGBA8 linear` | 277.1 ns/layout | 295.1 ns/layout | `750198528576` (exact) | ### `bench_detile_throughput` (pre-change chunked `walk` vs AVX2/SSE2 + `DetilePool`) `cargo test --release -p victory-formats --locked -- --ignored --nocapture bench_detile_throughput`: | Case | Base ms | Base MB/s | Opt ms | Opt MB/s | vs Base | vs Scalar | |---|---:|---:|---:|---:|---:|---:| | `4K BC7 SW_64KB_D (16 MiB)` | 1.958 | 8173.4 | 0.729 | 21951.2 | 2.69x | 11.35x | | `4K BC7 SW_64KB_S (16 MiB)` | 1.972 | 8115.6 | 0.574 | 27868.5 | 3.43x | 17.07x | | `4K BC1 SW_64KB_D (8 MiB)` | 0.731 | 10943.3 | 0.140 | 57331.2 | 5.24x | 57.27x | | `4K RGBA8 SW_64KB_D (64 MiB)` | 14.663 | 4364.9 | 3.885 | 16473.8 | 3.77x | 33.10x | | `2K BC7 SW_64KB_D (4 MiB)` | 0.247 | 16163.7 | 0.100 | 40145.2 | 2.48x | 19.94x | | `1K BC7 SW_64KB_D (1 MiB)` | 0.056 | 17980.4 | 0.050 | 19829.7 | 1.10x | 8.66x | | `256 BC7 SW_64KB_D (64 KiB, ST)` | 0.002 | 25727.0 | 0.003 | 20963.7 | 0.81x | 9.60x | | `4K BC7 MipChain (13 mips, 21.3 MiB)` | 2.319 | 9199.0 | 0.975 | 21880.2 | 2.38x | 11.40x | ## Verification - `cargo clippy -p victory-formats --all-targets --locked -- -D warnings` (default & `--all-features`): 0 warnings. - `cargo test -p victory-formats --release --locked -- --test-threads=1`: 47 passed, 0 failed, 6 ignored. - `cargo test -p victory-formats --locked detile::pool_tests -- --test-threads=1`: 2 passed, 0 failed. - `cargo test -p victory-formats --locked -- --test-threads=1`: 47 passed, 0 failed, 6 ignored. - `cargo run --locked -p xtask -- policy`: `asset policy: 304 files ok` (`cargo test --locked -p xtask -- --test-threads=1`: 11 passed, 0 failed). - `git diff --check origin/main..HEAD`: clean.
TaynanGT commented 2026-11-27 07:52:26 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-27T07:52:26Z.


@Vladimir-Human The Windows release formats suite passed with this revision: 47 passed and six were ignored as configured. The scalar parity, concurrent paths and worker-pool recovery checks all passed. CI confirmed the same commit, and it’s on main.

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7212903157 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/191#issuecomment-7212903157). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-27T07:52:26Z. --- @Vladimir-Human The Windows release formats suite passed with this revision: 47 passed and six were ignored as configured. The scalar parity, concurrent paths and worker-pool recovery checks all passed. CI confirmed the same commit, and it’s on `main`.
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
TaynanGT/Vice-Tay!191
No description provided.