Copy equal-length tile pieces with a constant length when detiling #37

Closed
github-bot wants to merge 1 commit from github-bot/gh-37 into main AGit
Owner

@⁠romainhedouin on GitHub · 2026-11-25 12:33 UTC · original
romainhedouin:perf/detile-runs → main · +33 −2 · 1 files · 1 commits · closed without merging

Textures the title changes are detiled on the CPU, before they go to the GPU. For the common tile modes a texture row is a long series of 8, 16 or 32-byte pieces, and each piece was copied with a general memcpy call of variable length. Now, when all pieces of a row have the same length (all but the last, which the width can cut short), they are copied with that length as a constant, so each copy is a few moves. The last piece and any other case take the old path. Tiling (the reverse) gets the same.

Release mode, on a Mac, mip 0 Detile before → after Tile before → after
BC7 4096², 64K_S 3,431 → 8,215 MB/s (4.9 → 2.0 ms) 4,123 → 8,707 MB/s
BC7 4096², 64K_D 5,959 → 12,402 MB/s 6,669 → 12,092 MB/s
BC1 4096², 64K_S 3,814 → 12,210 MB/s 4,142 → 9,195 MB/s
RGBA8 2048², 64K_D 3,803 → 10,247 MB/s 3,238 → 5,005 MB/s

Output is byte-for-byte identical to the old code in 339 comparisons (several element sizes, BC1/BC7, every addressable tile mode, odd widths, all mips, padded pitches, 3D). cargo test -p victory-formats passes; clippy for Windows reports no new warnings. No signature changes.

🤖 Generated with Claude Code

**@⁠romainhedouin** on GitHub · 2026-11-25 12:33 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/37) `romainhedouin:perf/detile-runs` → `main` · +33 −2 · 1 files · 1 commits · closed without merging Textures the title changes are detiled on the CPU, before they go to the GPU. For the common tile modes a texture row is a long series of 8, 16 or 32-byte pieces, and each piece was copied with a general `memcpy` call of variable length. Now, when all pieces of a row have the same length (all but the last, which the width can cut short), they are copied with that length as a constant, so each copy is a few moves. The last piece and any other case take the old path. Tiling (the reverse) gets the same. | Release mode, on a Mac, mip 0 | Detile before → after | Tile before → after | |---|---|---| | BC7 4096², 64K_S | 3,431 → 8,215 MB/s (4.9 → 2.0 ms) | 4,123 → 8,707 MB/s | | BC7 4096², 64K_D | 5,959 → 12,402 MB/s | 6,669 → 12,092 MB/s | | BC1 4096², 64K_S | 3,814 → 12,210 MB/s | 4,142 → 9,195 MB/s | | RGBA8 2048², 64K_D | 3,803 → 10,247 MB/s | 3,238 → 5,005 MB/s | Output is byte-for-byte identical to the old code in 339 comparisons (several element sizes, BC1/BC7, every addressable tile mode, odd widths, all mips, padded pitches, 3D). `cargo test -p victory-formats` passes; clippy for Windows reports no new warnings. No signature changes. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:34:14 +00:00
Author
Owner

@⁠lcg007xd-c on GitHub · 2026-11-25 21:21 UTC · original · approved these changes

Verified on Linux (Rust 1.98.1)

  • cargo test -p victory-formats --lib on 1e2006c: 24 passed, 0 failed, 4 ignored. The same with the PR merged into current main (--no-commit).
  • cargo clippy -p victory-formats --target x86_64-pc-windows-msvc: 0 warnings, same as main.
  • git merge --no-commit --no-ff into main: clean. It also merges cleanly on top of #21, which edits the same walk function.
  • An independent equivalence check, as a throwaway test that was not committed. I ran it in release mode on main and on this PR. It goes over 16 swizzle modes × 7 element sizes (1–16 bytes, including 4×4 blocks of 8 and 16 bytes) × 5 shapes (odd widths, 3D with depth 3 and 5) × every mip. It uses detile and then tile with padded row and depth pitches, and hashes the results and both buffers. 4,144 cases give the same hash on main and on the PR (55cb57aecc5c86ff).
  • Throughput on this machine (x86_64). The build is release with the same profile on both sides: current main against main with this PR merged, so both have main's thin LTO. Mip 0, 40 iterations, two runs each, min–max:
detile MB/s tile MB/s
BC7 4096², 64K_S 3,874–4,301 → 5,583–5,951 3,990–4,057 → 6,953–7,294
BC7 4096², 64K_D 4,883–6,154 → 7,658–7,874 8,361–8,798 → 12,554–12,600
BC1 4096², 64K_S 5,113–5,122 → 9,398–10,079 4,425–4,778 → 8,456–8,650
RGBA8 2048², 64K_D 3,049–3,759 → 6,209–6,322 4,530–4,842 → 7,433–7,686

That's a 1.3–2× speedup on x86_64, the same direction as the Mac numbers.

Review notes

  • The change is equivalent by construction. copy_runs::<N> with N != 0 is only called on whole, and every run in whole has length same == N. Single-run rows (whole empty) and mixed lengths go through N = 0 as before, and the last, shorter run is always copied with its own length.
  • I found no defects.

Not verified

  • Windows/MSVC codegen and throughput, and the in-game texture upload path.

Reviewed with Claude Code.

**@⁠lcg007xd-c** on GitHub · 2026-11-25 21:21 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/37#pullrequestreview-6065150646) · **approved these changes** ### Verified on Linux (Rust 1.98.1) - `cargo test -p victory-formats --lib` on 1e2006c: 24 passed, 0 failed, 4 ignored. The same with the PR merged into current main (`--no-commit`). - `cargo clippy -p victory-formats --target x86_64-pc-windows-msvc`: 0 warnings, same as main. - `git merge --no-commit --no-ff` into main: clean. It also merges cleanly on top of #21, which edits the same `walk` function. - An independent equivalence check, as a throwaway test that was not committed. I ran it in release mode on main and on this PR. It goes over 16 swizzle modes × 7 element sizes (1–16 bytes, including 4×4 blocks of 8 and 16 bytes) × 5 shapes (odd widths, 3D with depth 3 and 5) × every mip. It uses `detile` and then `tile` with padded row and depth pitches, and hashes the results and both buffers. 4,144 cases give the **same hash** on main and on the PR (`55cb57aecc5c86ff`). - Throughput on this machine (x86_64). The build is release with the same profile on both sides: current main against main with this PR merged, so both have main's thin LTO. Mip 0, 40 iterations, two runs each, min–max: | | detile MB/s | tile MB/s | |---|---|---| | BC7 4096², 64K_S | 3,874–4,301 → 5,583–5,951 | 3,990–4,057 → 6,953–7,294 | | BC7 4096², 64K_D | 4,883–6,154 → 7,658–7,874 | 8,361–8,798 → 12,554–12,600 | | BC1 4096², 64K_S | 5,113–5,122 → 9,398–10,079 | 4,425–4,778 → 8,456–8,650 | | RGBA8 2048², 64K_D | 3,049–3,759 → 6,209–6,322 | 4,530–4,842 → 7,433–7,686 | That's a 1.3–2× speedup on x86_64, the same direction as the Mac numbers. ### Review notes - The change is equivalent by construction. `copy_runs::<N>` with `N != 0` is only called on `whole`, and every run in `whole` has length `same == N`. Single-run rows (`whole` empty) and mixed lengths go through `N = 0` as before, and the last, shorter run is always copied with its own length. - I found no defects. ### Not verified - Windows/MSVC codegen and throughput, and the in-game texture upload path. Reviewed with Claude Code.
github-bot closed this pull request 2026-11-27 01:00:15 +00:00
Author
Owner

@⁠romainhedouin on GitHub · 2026-11-26 22:25 UTC · original

Closing: a-publier already copies equal-length tile pieces with a constant length, through copy_runs::<N, DETILE> for 8, 16 and 32 bytes, tiling included (texture.rs:783). Thanks for the equivalence check and the x86 numbers.

**@⁠romainhedouin** on GitHub · 2026-11-26 22:25 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/37#issuecomment-7204672747) Closing: `a-publier` already copies equal-length tile pieces with a constant length, through `copy_runs::<N, DETILE>` for 8, 16 and 32 bytes, tiling included (texture.rs:783). Thanks for the equivalence check and the x86 numbers.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.