perf(formats): add AVX2/SSE2 256B micro-tile texture detiler and DetilePool #42
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/42"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-25T21:01:18Z.
AI-assisted clean-room contribution (
victory-formats, unit tests + synthetic throughput benchmark only — no title files used).Summary
Adds an AVX2/SSE2 SIMD + portable 256-byte micro-tile texture detiler/tiler and persistent worker pool (
DetilePool) incrates/victory-formats/src/{detile.rs, lib.rs, texture.rs}(victory-gpuuntouched):pipe_bank_xoralignment fromflipsandxordirectly (SW_256B_*,SW_4KB_*,SW_64KB_*,*_T,*_X,SW_64KB_R_X, andSW_64KB_Z_X4B/16B viaR8x32Z4Morton kernel), withcopy_fallbackhandling thick 3D and remaining modes cleanly while preserving existingLayout::{new, for_gpu, detile, tile, bytes_from}APIs.pub Layoutsoundness:prepare_thin_geometry -> Option<ThinGeometry>falls back safely tocopy_fallbackon any inconsistent mutatedpubLayoutfields, with checkedu64/usize/u32offset math,pitch_blocks >= blocks_xmacro-row disjointness, tail bounds, GF(2) injectivity check onlayout.blockflips, and zero-dim /element_bytesPOT<= 16checks.is_x86_feature_detected!("avx2")dispatch with#[target_feature(enable = "avx2")], unaligned loads/stores, separateConstSendPtr/MutSendPtr, worker/caller panic propagation and mutex poison recovery (DetilePool), and zero overlap with existingklbf-labcrates (git merge-treeclean againstbetaand sibling shader work).Verification (
betae328c88)cargo clippy -p victory-formats --all-targets -- -D warnings: 0 warnings.cargo test -p victory-formats --all-targets: 37 passed, 0 failed (7 ignored), including exhaustive scalar vs AVX2 vs portable parity across all 15 addressable swizzle modes (Series X & S, non-zeropipe_bank_xor, BPE 1..16, NPOT dims, odd pitches, mip tails, 1D/arrays/3D), 4-threadtry_lockfallback,DetilePoolpanic recovery, and release-modemutated_public_layout_fields_never_enter_unsound_fast_path.detile_speedup_benchmark(during parallel build load; uncontested benchmark follow-up planned): 2.21x–8.35x vs baseline (19.4x–90.7x vs scalar), e.g., 4K BC7SW_64KB_D25.8 GB/s(3.07x), 4K BC1SW_64KB_D45.4 GB/s(4.56x), 4K RGBA8SW_64KB_Z_X17.0 GB/s(8.35x).Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-25T21:07:58Z.
Thanks a lot @Vladimir-Human! We test one change at a time on the RX 9070 XT (same save, same 7-minute run, fps and picture compared with our reference build), so this one goes into that queue on its own. Results will be posted here, then we merge or report back what we saw.
Imported from PastiiJay/klbf-lab. Originally posted by HandshakeHackin on 2026-11-25T21:17:13Z.
I checked
853852eon Linux x86-64 (AMD EPYC 9V74, 9 logical CPUs available). The formats suite passed all 37 active tests, including the scalar-reference, odd-pitch, partial-mip and concurrent-caller comparisons. Seven tests were ignored. The combined Windows suite with #41, #43 and the queued beta fixes also passed (608 passed, 16 ignored). Windows CIOne size is worth a look before tuning the worker pool. I ran the PR’s release
detile_speedup_benchmarkfive times per build, alternating the order. The experimental build changed onlyPARALLEL_MIN_BYTESfrom 512 KiB to 2 MiB. Median milliseconds per BC7SW_64KB_Dtexture on this machine:The 1 MiB case benefited from staying on the calling thread here. The 4K case retained the same speedup with either threshold. Each benchmark checked the output against the old walker before timing. These are CPU texture-conversion timings.
Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-25T21:18:13Z.
Thanks @HandshakeHackin, that's a very useful check. What we keep: all 37 formats tests pass, the combined Windows suite with #41 and #43 is green (608 passed), the output matches the old walker byte for byte, and the 4K speedup (~6x on BC7
SW_64KB_D) holds with either threshold, while 1 MiB textures do better staying on the calling thread with a 2 MiBPARALLEL_MIN_BYTES.When this PR's turn comes in our RX 9070 XT queue, we'll run it as-is first, then with the 2 MiB threshold as a separate run, and post both results here. @Vladimir-Human, feel free to weigh in on the threshold if you had a reason for 512 KiB.
Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-26T00:05:00Z.
@PastiiJay @HandshakeHackin Thanks for running those cross-CPU EPYC 9V74 numbers! 512 KiB was an initial conservative threshold before seeing virtualized/multi-CCX pool-wake latency across CPUs.
I tested raising PARALLEL_MIN_BYTES from 512 KiB to 2 MiB on idle i5-13400F (--release detile_speedup_benchmark):
Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-26T00:05:18Z.
Thanks for checking it on your side too @Vladimir-Human. We'll keep the plan: one run with the PR as-is and one with the 2 MiB threshold, and post both here.
Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-27T07:04:44Z.
Follow-up test coverage update in
276d0b3: after raisingPARALLEL_MIN_BYTESto2 MiB, the existing1 MiBcases ran inline and only the exact2 MiBcases hit the worker pool. Added three strictly> 2 MiBcases toparallel_threshold_and_concurrent_callers_match_scalar_referencecovering both non-XOR and XOR pool paths (2048x2048 BC7 SW_64KB_D4 MiB POT,2056x1544 BC7 SW_64KB_R_X3 MiB NPOT + remainders, and2048x2048 BC7 SW_64KB_Z_X4 MiB POT) and updated the stale>= 512 KiBcomments.Re-verified on
276d0b3:cargo clippy -p victory-formats --all-targets(0 warnings),cargo test -p victory-formats --release -- --test-threads=1(37 passed, 0 failed, 7 ignored), and debugparallel_threshold_and_concurrent_callers_match_scalar_reference(passed).Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-27T09:52:34Z.
Thanks @Vladimir-Human, the extra cases above 2 MiB cover the pool path properly now. We'll review it with the next beta batch. Could you rebase on the current head if it no longer merges cleanly by then?
Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-27T10:44:16Z.
Thanks @PastiiJay! Verified
276d0b3still merges cleanly against currentbeta(6cce57e), and I will rebase promptly if the next beta batch introduces any conflict.Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-27T10:50:20Z.
Thanks @Vladimir-Human for keeping this rebased-ready and for checking it against
beta. We're reviewing the detiler diff now; no merge timing yet. Could you tell us which CPU and whether you saw any texture change on your side?Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-27T10:52:00Z.
We'll take them onto the AMD line one at a time with an A/B bench. Thanks, the tests you added make that much easier.
Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-28T18:07:27Z.
Superseded by #178 targeting
stable-amd(v26.11.6): https://github.com/PastiiJay/klbf-lab/pull/178Pull request closed