Repository navigation
D3D12-FORMATS-TEXTURE-FAST-WALK: 1.22x-1.74x faster Layout::detile & tile via pre-divided u32 chunk offsets - #2695
Conversation
|
Checked by OreoFR on macOS 27.2.1, Apple M5 (arm64), Rust 1.98.1, main 1d22590, PR head 002f92a. MEASURED:
So on this arm64 host the change is within run-to-run noise (tile 1024x1024 +4-7 %, the rest ±3 %; the 256x256 cases swing more than that between two runs of the same main build). The 1.22x-1.74x in the title is not reproduced here; it may be an x86-64 result. Behaviour is unchanged as far as the crate's tests go. Merges cleanly with main, #2566 and #2690. AI-assisted: Claude Code |
|
Independent A/B of
The larger layouts are faster here. The regression on small levels is consistent with the new offset-table scan and allocation being paid once per walk, even when there are only a few rows over which to amortize it. Could we keep the previous copy path for small subresources and use the compressed table where it pays off? The 63×31 cases were already close to break-even on this host. These are synthetic per-subresource timings, so real mip/size distribution still determines the impact. AI-assisted. |
|
Thanks for catching that @lixonik! Eliminated the small-subresource |
|
Independent Windows allocation check for the small-mip update in A local synthetic test counted allocation and reallocation calls on the calling thread during
On both heads, tiled output matched a per-element AI-assisted with OpenAI Codex (GPT-6.2 Sol). |
|
Same-machine retest of the stack-buffer fix
The stack buffer eliminates the regression at 32×24 on this host and reduces the remaining 8×8 penalty to about 11–19% (12–21 ns). The larger cases still improve. This is synthetic CPU timing with a three-byte row pad. I measured time and byte parity here. Allocation counts and the runtime's mip mix are separate questions. AI-assisted. |
|
Independent CachyOS A/B of the stack-buffer revision
The two 8×8 cases retained a small absolute cost, about 11–13 ns, in every pair. The large cases consistently improved. At widths 125, 129, and 133 (31, 32, and 33 full body chunks in the 4-byte 64KB_D layout), detile was 21–22% faster and tile 19–22% faster by paired median. Both arms passed all 42 non-ignored release tests in AI-assisted with OpenAI Codex. |
…in Layout::walk (D3D12-FORMATS-TEXTURE-FAST-WALK) Speed up Layout::detile and Layout::tile (hot on texture refreshes and async texture read-backs) by: - Pre-dividing uniform chunk offsets into a compact Vec<u32> (4 B vs 24 B per run, 6x less L1 cache traffic per row). - Checking `base + max_chunk_off < tiled.len()` once per row so the inner loop copies without per-chunk bounds checks or per-chunk divisions. - Specializing 4-byte and 64-byte chunk sizes alongside 8, 16, and 32. Measured --release A/B on Ryzen 7 7800X3D across 8 64KB_S/64KB_D layouts: detile +21.6% to +74.3% (1.22x-1.74x), tile +5.8% to +62.7% (1.06x-1.63x), with zero regressions and 41/41 leonida-formats tests passing. AI-assisted: Antigravity (Gemini 4 Neon)
AI-assisted: Antigravity (Gemini 4 Neon)
d740cb1 to
74fdec2
Compare
Combined BCPack and texture-layout check with #2690MEASURED. I tested #2690 A local synthetic fixture generated 306 BCPack streams on All 15 replays matched the Scope: synthetic CPU correctness and copy-path coverage. AI-assisted: Codex (GPT-6.2 Sol). |
|
RUN - VERIFY-2695-RTX4060 - by MoonEyes (another person than the author) on head
Limits: one card, one run per arm, two arms only, the seven together. Values only, no game data. AI-assisted (Claude Code). |
|
Merging. Head AI-assisted (Claude Code). |
Problem
Layout::detileandLayout::tile(walk()ind3d12/crates/leonida-formats/src/texture.rs) copy texture rows usingruns: Vec<(usize, usize, usize)>(24 bytes per element). For uniform 8/16/32-byte tiled blocks:copy_runsperformed a per-chunk bounds check,slice::copy_from_slicedispatch, and a runtime(tiled_row + offset) / Ninteger division on every chunk across every row.8,16, and32byte chunk sizes had typed array-copy specializations (4and64fell back to slow generic slice copies).Fix
In
d3d12/crates/leonida-formats/src/texture.rs:offset / size) into compactu32offsets, using a zero-allocation[0u32; 32]stack buffer forbody.len() <= 32(no heap overhead on small subresources / mip levels) and aVec<u32>for wider rows (4 Bvs24 Bstride).copy_chunks::<N, DETILE>()which checksbase + max_chunk_off < tiled.len()once per row and copies fixed[u8; N]arrays using&tiled[base..]indexing with no per-chunk division or redundant inner bounds checks.4and64byte uniform chunk widths alongside8,16, and32.Verification
10.0.26200), Ryzen 7 7800X3D, pinnedrustc 1.98.1.cargo test -p leonida-formats --lib: 41 passed, 0 failed (6 ignored benchmarks/external fixture tests).cargo clippy -p leonida-formats --lib -- -D warnings: 0 warnings.--releasetexture_walk_benchon Ryzen 7 7800X3D (small mips + large textures):8x8_4B_64KB_S0.105 usdetile /0.100 ustile;32x24_4B_64KB_D0.356 us/0.317 us;256x256_4B_64KB_D_m50.104 us/0.102 us256x256_4B_64KB_S30,266 MB/sdetile /21,930 MB/stile;512x512_16B_64KB_D35,783 MB/s/35,427 MB/s;1024x1024_8B_64KB_D34,957 MB/s/33,332 MB/s.python -I scripts/check_no_game_data.py d3d12/crates/leonida-formats/src/texture.rs: PASS.Claimed in #2570 as
D3D12-FORMATS-TEXTURE-FAST-WALK.AI-assisted: Antigravity (Gemini 4 Neon)