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

Manually merged
github merged 1 commit from github-bot/gh-191 into main 2026-11-27 07:52:44 +00:00 AGit
Owner

@⁠Vladimir-Human on GitHub · 2026-11-27 07:31 UTC · original
Vladimir-Human:perf/simd-detile-avx2-pool → main · +2981 −10 · 3 files · 1 commits · merged 2026-11-27 07:51 UTC

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.
**@⁠Vladimir-Human** on GitHub · 2026-11-27 07:31 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/191) `Vladimir-Human:perf/simd-detile-avx2-pool` → `main` · +2981 −10 · 3 files · 1 commits · merged 2026-11-27 07:51 UTC ## 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.
Add a thin tiled 256-byte micro-tile detiler/tiler (`crates/victory-formats/src/detile.rs`)
with runtime-detected x86_64 AVX2/SSE2 kernels, portable fixed-width fallbacks,
strict geometry/bounds validation for mutated public `Layout` fields, and a
persistent worker pool (`PARALLEL_MIN_BYTES = 2 MiB`) with panic and mutex-poison
recovery.

Wire `Layout::detile`, `Layout::tile`, and `TilingCache::tile` (non-thick paths)
into the micro-tile implementation while preserving `Layout::bytes_from`,
overlapping depth-pitch rejection, thick 3D cached tiling, and all existing APIs.

Add exhaustive bit-exact scalar-reference parity tests covering all addressable
swizzle modes, element sizes (1-16 B), NPOT extents, odd pitches, 1D/array/3D
subresources, sub-threshold (1 MiB), boundary (2 MiB), and parallel (> 2 MiB,
up to 4 MiB) pool paths, concurrent `try_lock` callers, pool panic recovery,
and a release throughput benchmark (`bench_detile_throughput`).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 07:36:54 +00:00
github manually merged commit 41cfc5e897 into main 2026-11-27 07:52:44 +00:00
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-27 07:52 UTC · original

@⁠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.

**@⁠TaynanGT** on GitHub · 2026-11-27 07:52 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/191#issuecomment-7212903157) @⁠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`.
This discussion has been locked. Commenting is limited to contributors.
No description provided.