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

Closed
romainhedouin wants to merge 1 commit from upstream-pr/37 into main
romainhedouin commented 2026-11-25 12:33:17 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by romainhedouin on 2026-11-25T12:33:17Z.


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

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:issue:5491395378 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/37). Originally posted by [romainhedouin](https://github.com/romainhedouin) on 2026-11-25T12:33:17Z. --- 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)
lcg007xd-c commented 2026-11-25 21:21:22 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by lcg007xd-c on 2026-11-25T21:21:22Z.

Review: APPROVED


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.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:review:6065150646 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/37#pullrequestreview-6065150646). Originally posted by [lcg007xd-c](https://github.com/lcg007xd-c) on 2026-11-25T21:21:22Z. **Review:** APPROVED --- ### 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.
romainhedouin commented 2026-11-26 22:25:59 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by romainhedouin on 2026-11-26T22:25:59Z.


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.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7204672747 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/37#issuecomment-7204672747). Originally posted by [romainhedouin](https://github.com/romainhedouin) on 2026-11-26T22:25:59Z. --- 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

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
Belobug/VIctory-Belobug-AMD!37
No description provided.