[PR #1951] runtime: copy contiguous X micro-runs in TiledSurface2D::tile/detile #1958

Open
opened 2026-11-26 21:19:32 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1951
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: perf/rt-gfx10-tiling-fast-runs


📝 Commits (1)

  • 1e88ddb runtime: copy contiguous X micro-runs in TiledSurface2D::tile/detile

📊 Changes

2 files changed (+97 additions, -15 deletions)

View changed files

📝 runtime/src/gfx10_tiling.h (+92 -15)
📝 runtime/test/gfx10_tiling_test.cpp (+5 -0)

📄 Description

Item ID: RT-GFX10-TILING-FAST-RUNS (claimed in #1608 comment #7168111876).

Summary

Accelerates leonida::gfx10::TiledSurface2D::tile() and detile() (runtime/src/gfx10_tiling.h) by deriving each tiling pattern's contiguous X micro-run width and hoisting direction/tile-row work out of the innermost loop, preserving bit-exact output and untouched padding bytes:

  • Derived contiguous X micro-run width (run_elements_, run_bytes_):
    • Counts consecutive leading X address bits immediately after the element-byte zero bits in pattern_: 16 bytes for sw_4kb_s (all element sizes) and sw_64kb_d 2/4/8 BPE, 8 bytes for sw_64kb_d 1 BPE, and 32 bytes for sw_64kb_d 16 BPE.
  • Compile-time run copies & precomputed Y offsets (copy_runs<ToTiled, RunBytes>):
    • Precomputes y_offsets[min(height, tile_height)] once per call instead of recomputing the 12/16-bit Y swizzle on every scanline, and stores compact uint32_t run-granularity x_offsets (at most 64 entries across all 10 patterns).
    • Specialises ToTiled and RunBytes (8 / 16 / 32) at compile time so every full micro-run emits a fixed-width inline copy with zero per-element direction branch or runtime-length memcpy, and copies any non-aligned row tail in a single exact-length memcpy without touching padding in either buffer.
  • runtime/test/gfx10_tiling_test.cpp:
    • Expanded surface round-trip + padding-untouched bijection checks with sub-run, run-boundary, and tile_width + 1 / tile_height + 1 dimensions across both modes and all 5 element sizes (90 surfaces × 2 pitches).

A/B Benchmark (-O2, 2 runs, bit-exact FNV-64 hashes on all 7 cases)

Surface Base tile Head tile Tile speedup Base detile Head detile Detile speedup
4KB_S 1B (1024×1024) 1.609 / 1.212 ms 0.087 / 0.038 ms 18.5× – 31.9× 1.210 / 1.215 ms 0.051 / 0.024 ms 23.7× – 50.6×
4KB_S 4B (1024×1024) 1.933 / 1.935 ms 0.263 / 0.146 ms 7.3× – 13.3× 1.934 / 1.939 ms 0.166 / 0.107 ms 11.7× – 18.1×
64KB_D 1B (1024×1024) 1.217 / 1.218 ms 0.072 / 0.050 ms 16.9× – 24.4× 1.218 / 1.218 ms 0.050 / 0.037 ms 24.4× – 32.9×
64KB_D 4B (1024×1024) 1.935 / 1.938 ms 0.434 / 0.321 ms 4.5× – 6.0× 1.941 / 1.943 ms 0.183 / 0.162 ms 10.6× – 12.0×
64KB_D 8B (1024×1024) 1.696 / 1.692 ms 0.328 / 0.295 ms 5.2× – 5.7× 1.688 / 1.693 ms 0.240 / 0.227 ms 7.0× – 7.5×
64KB_D 16B (512×512) 0.483 / 0.486 ms 0.150 / 0.146 ms 3.2× – 3.3× 0.483 / 0.482 ms 0.110 / 0.109 ms 4.4×
64KB_D 4B (1021×769 odd) 1.452 / 1.452 ms 0.275 / 0.244 ms 5.3× – 6.0× 1.455 / 1.453 ms 0.122 / 0.121 ms 11.9× – 12.0×

Verification

  • AI-assisted: yes
  • GPUs tested: none (host-only portable C++ tests on macOS arm64; no game files used)
  • clang++ -std=c++20 -O1 -g -fsanitize=address,undefined -Wall -Wextra -Werror: gfx10_tiling_test PASS
  • clang++ -std=c++20 -O1 -g -fsanitize=thread -Wall -Wextra -Werror: gfx10_tiling_test PASS
  • clang++ -std=c++20 -O2 -Wall -Wextra -Werror: gfx10_tiling_test × 3 runs PASS
  • Hygiene: check_no_game_data.py PASS, tests/test_text_write_line_endings.py PASS (3/3)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1951 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `perf/rt-gfx10-tiling-fast-runs` --- ### 📝 Commits (1) - [`1e88ddb`](https://github.com/ubiquitarianism/leonida/commit/1e88ddb43666d9be6511f252fb27c9ed39b78df8) runtime: copy contiguous X micro-runs in TiledSurface2D::tile/detile ### 📊 Changes **2 files changed** (+97 additions, -15 deletions) <details> <summary>View changed files</summary> 📝 `runtime/src/gfx10_tiling.h` (+92 -15) 📝 `runtime/test/gfx10_tiling_test.cpp` (+5 -0) </details> ### 📄 Description Item ID: `RT-GFX10-TILING-FAST-RUNS` (claimed in #1608 comment #7168111876). ### Summary Accelerates `leonida::gfx10::TiledSurface2D::tile()` and `detile()` (`runtime/src/gfx10_tiling.h`) by deriving each tiling pattern's contiguous X micro-run width and hoisting direction/tile-row work out of the innermost loop, preserving bit-exact output and untouched padding bytes: - **Derived contiguous X micro-run width (`run_elements_`, `run_bytes_`)**: - Counts consecutive leading X address bits immediately after the element-byte zero bits in `pattern_`: 16 bytes for `sw_4kb_s` (all element sizes) and `sw_64kb_d` 2/4/8 BPE, 8 bytes for `sw_64kb_d` 1 BPE, and 32 bytes for `sw_64kb_d` 16 BPE. - **Compile-time run copies & precomputed Y offsets (`copy_runs<ToTiled, RunBytes>`)**: - Precomputes `y_offsets[min(height, tile_height)]` once per call instead of recomputing the 12/16-bit Y swizzle on every scanline, and stores compact `uint32_t` run-granularity `x_offsets` (at most 64 entries across all 10 patterns). - Specialises `ToTiled` and `RunBytes` (8 / 16 / 32) at compile time so every full micro-run emits a fixed-width inline copy with zero per-element direction branch or runtime-length `memcpy`, and copies any non-aligned row tail in a single exact-length `memcpy` without touching padding in either buffer. - **`runtime/test/gfx10_tiling_test.cpp`**: - Expanded surface round-trip + padding-untouched bijection checks with sub-run, run-boundary, and `tile_width + 1` / `tile_height + 1` dimensions across both modes and all 5 element sizes (90 surfaces × 2 pitches). ### A/B Benchmark (`-O2`, 2 runs, bit-exact FNV-64 hashes on all 7 cases) | Surface | Base `tile` | Head `tile` | Tile speedup | Base `detile` | Head `detile` | Detile speedup | |---|---:|---:|---:|---:|---:|---:| | `4KB_S 1B` (1024×1024) | 1.609 / 1.212 ms | **0.087 / 0.038 ms** | **18.5× – 31.9×** | 1.210 / 1.215 ms | **0.051 / 0.024 ms** | **23.7× – 50.6×** | | `4KB_S 4B` (1024×1024) | 1.933 / 1.935 ms | **0.263 / 0.146 ms** | **7.3× – 13.3×** | 1.934 / 1.939 ms | **0.166 / 0.107 ms** | **11.7× – 18.1×** | | `64KB_D 1B` (1024×1024) | 1.217 / 1.218 ms | **0.072 / 0.050 ms** | **16.9× – 24.4×** | 1.218 / 1.218 ms | **0.050 / 0.037 ms** | **24.4× – 32.9×** | | `64KB_D 4B` (1024×1024) | 1.935 / 1.938 ms | **0.434 / 0.321 ms** | **4.5× – 6.0×** | 1.941 / 1.943 ms | **0.183 / 0.162 ms** | **10.6× – 12.0×** | | `64KB_D 8B` (1024×1024) | 1.696 / 1.692 ms | **0.328 / 0.295 ms** | **5.2× – 5.7×** | 1.688 / 1.693 ms | **0.240 / 0.227 ms** | **7.0× – 7.5×** | | `64KB_D 16B` (512×512) | 0.483 / 0.486 ms | **0.150 / 0.146 ms** | **3.2× – 3.3×** | 0.483 / 0.482 ms | **0.110 / 0.109 ms** | **4.4×** | | `64KB_D 4B` (1021×769 odd) | 1.452 / 1.452 ms | **0.275 / 0.244 ms** | **5.3× – 6.0×** | 1.455 / 1.453 ms | **0.122 / 0.121 ms** | **11.9× – 12.0×** | ### Verification - AI-assisted: yes - GPUs tested: none (host-only portable C++ tests on macOS arm64; no game files used) - `clang++ -std=c++20 -O1 -g -fsanitize=address,undefined -Wall -Wextra -Werror`: `gfx10_tiling_test` PASS - `clang++ -std=c++20 -O1 -g -fsanitize=thread -Wall -Wextra -Werror`: `gfx10_tiling_test` PASS - `clang++ -std=c++20 -O2 -Wall -Wextra -Werror`: `gfx10_tiling_test` × 3 runs PASS - Hygiene: `check_no_game_data.py` PASS, `tests/test_text_write_line_endings.py` PASS (3/3) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#1958
No description provided.