[PR #1965] perf(resource_detile): compile-time contiguous X micro-runs and macro-tile blocking for 64 KiB swizzle #1973

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

📋 Pull Request Information

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

Base: main ← Head: perf/rt-resource-detile-fast-runs


📝 Commits (1)

  • d4628fc perf(resource_detile): macro-tile blocking and compile-time contiguous micro-runs for 64 KiB GFX10 swizzle

📊 Changes

2 files changed (+170 additions, -41 deletions)

View changed files

📝 runtime/src/resource_detile.h (+109 -41)
📝 runtime/test/resource_detile_test.cpp (+61 -0)

📄 Description

Claim: RT-RESOURCE-DETILE-FAST-RUNS (claim comment #7168674568 on #1608).

Optimization (runtime/src/resource_detile.h)

Previously detile_typed<Bpe> and tile_typed<Bpe> copied a single element (1/2/4/8/16 bytes) per iteration with x / tile_w, x % tile_w, and lut_x lookup on every element while walking row-major across all tiles_x macro-tiles.

  1. Compile-time contiguous X micro-runs (SwizzleLut64K<Bpe>::lut_run_x):
    • In GFX10_SW_64K_D_RBPLUS_PATINFO, the lowest X coordinate bits form contiguous horizontal runs inside each 64 KiB tile (8×1B = 8B, 8×2B = 16B, 4×4B = 16B, 2×8B = 16B, 2×16B = 32B).
    • Added compile-time lut_run_x and static_assert(runs_valid()) proving for every Bpe in {1, 2, 4, 8, 16} that every micro-run is contiguous, aligned to run_bytes, and bit-disjoint from lut_y[y] (so tile_row + lut_run_x[r] replaces | without per-element division/modulo).
  2. Macro-tile blocking + exact-length contiguous tail copy (transfer_typed<Bpe, ToTiled>):
    • Processes one 64 KiB macro-tile at a time so the swizzled side stays within a single 64 KiB cache footprint.
    • Copies full micro-runs with compile-time constant run_bytes (8/16/32 bytes) and handles any partial last macro-tile remainder with a single exact-length contiguous tail memcpy (never writing past active bounds).
    • Consolidates duplicated tile/detile loops into one template.

Verification

  • AI-assisted: yes.
  • GPUs tested: none (host is macOS arm64; no retail files; 0 CMakeLists.txt changes).
  • Expanded runtime/test/resource_detile_test.cpp with test_oracle_exact<Bpe>() verifying bit-exact match against the scalar per-element LUT oracle and untouched 0xA5 padding bytes across every tail remainder (0..run_elems-1) and macro-tile boundary (tile_w-1, tile_w, tile_w+1, multi-tile, and BC1/BC7).
  • Ran resource_detile_test cleanly under:
    • clang++ -std=c++20 -O1 -g -fsanitize=address,undefined -Wall -Wextra -Werror
    • clang++ -std=c++20 -O1 -g -fsanitize=thread -Wall -Wextra -Werror
    • clang++ -std=c++20 -O2 -Wall -Wextra -Werror
  • Bit-exact A/B benchmark at -O2 vs main (best of 5 runs, Apple Silicon):
R8_1024x1024       tile:   424.9 ->   34.3 us (12.41x) | detile:   421.0 ->   33.8 us (12.46x)
R16_1024x1024      tile:   375.0 ->   48.0 us ( 7.81x) | detile:   384.0 ->   48.2 us ( 7.96x)
RGBA8_1080p        tile:   749.6 ->  191.2 us ( 3.92x) | detile:   762.0 ->  245.5 us ( 3.10x)
RGBA16F_1024x768   tile:   318.2 ->  147.8 us ( 2.15x) | detile:   290.7 ->  137.0 us ( 2.12x)
BC1_2048x2048      tile:    96.6 ->   48.9 us ( 1.97x) | detile:    95.5 ->   47.1 us ( 2.03x)
BC7_2048x1024      tile:    75.1 ->   48.3 us ( 1.56x) | detile:    54.3 ->   43.9 us ( 1.24x)
BC7_1920x1080      tile:    67.7 ->   42.4 us ( 1.60x) | detile:    55.1 ->   41.6 us ( 1.32x)
  • Ran python3 -I scripts/check_no_game_data.py on both files and python3 -I tests/test_text_write_line_endings.py: all passed.

🔄 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/1965 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `perf/rt-resource-detile-fast-runs` --- ### 📝 Commits (1) - [`d4628fc`](https://github.com/ubiquitarianism/leonida/commit/d4628fc665560d961a914ad66a50f544a512ff77) perf(resource_detile): macro-tile blocking and compile-time contiguous micro-runs for 64 KiB GFX10 swizzle ### 📊 Changes **2 files changed** (+170 additions, -41 deletions) <details> <summary>View changed files</summary> 📝 `runtime/src/resource_detile.h` (+109 -41) 📝 `runtime/test/resource_detile_test.cpp` (+61 -0) </details> ### 📄 Description Claim: `RT-RESOURCE-DETILE-FAST-RUNS` (claim comment `#7168674568` on #1608). ### Optimization (`runtime/src/resource_detile.h`) Previously `detile_typed<Bpe>` and `tile_typed<Bpe>` copied a single element (`1/2/4/8/16` bytes) per iteration with `x / tile_w`, `x % tile_w`, and `lut_x` lookup on every element while walking row-major across all `tiles_x` macro-tiles. 1. **Compile-time contiguous X micro-runs (`SwizzleLut64K<Bpe>::lut_run_x`)**: - In `GFX10_SW_64K_D_RBPLUS_PATINFO`, the lowest X coordinate bits form contiguous horizontal runs inside each 64 KiB tile (`8×1B = 8B`, `8×2B = 16B`, `4×4B = 16B`, `2×8B = 16B`, `2×16B = 32B`). - Added compile-time `lut_run_x` and `static_assert(runs_valid())` proving for every `Bpe` in `{1, 2, 4, 8, 16}` that every micro-run is contiguous, aligned to `run_bytes`, and bit-disjoint from `lut_y[y]` (so `tile_row + lut_run_x[r]` replaces `|` without per-element division/modulo). 2. **Macro-tile blocking + exact-length contiguous tail copy (`transfer_typed<Bpe, ToTiled>`)**: - Processes one 64 KiB macro-tile at a time so the swizzled side stays within a single 64 KiB cache footprint. - Copies full micro-runs with compile-time constant `run_bytes` (`8/16/32` bytes) and handles any partial last macro-tile remainder with a single exact-length contiguous tail `memcpy` (never writing past active bounds). - Consolidates duplicated tile/detile loops into one template. ### Verification - **AI-assisted**: yes. - **GPUs tested**: none (host is macOS arm64; no retail files; 0 `CMakeLists.txt` changes). - Expanded `runtime/test/resource_detile_test.cpp` with `test_oracle_exact<Bpe>()` verifying bit-exact match against the scalar per-element LUT oracle and untouched `0xA5` padding bytes across every tail remainder (`0..run_elems-1`) and macro-tile boundary (`tile_w-1`, `tile_w`, `tile_w+1`, multi-tile, and BC1/BC7). - Ran `resource_detile_test` cleanly under: - `clang++ -std=c++20 -O1 -g -fsanitize=address,undefined -Wall -Wextra -Werror` - `clang++ -std=c++20 -O1 -g -fsanitize=thread -Wall -Wextra -Werror` - `clang++ -std=c++20 -O2 -Wall -Wextra -Werror` - Bit-exact A/B benchmark at `-O2` vs `main` (best of 5 runs, Apple Silicon): ```text R8_1024x1024 tile: 424.9 -> 34.3 us (12.41x) | detile: 421.0 -> 33.8 us (12.46x) R16_1024x1024 tile: 375.0 -> 48.0 us ( 7.81x) | detile: 384.0 -> 48.2 us ( 7.96x) RGBA8_1080p tile: 749.6 -> 191.2 us ( 3.92x) | detile: 762.0 -> 245.5 us ( 3.10x) RGBA16F_1024x768 tile: 318.2 -> 147.8 us ( 2.15x) | detile: 290.7 -> 137.0 us ( 2.12x) BC1_2048x2048 tile: 96.6 -> 48.9 us ( 1.97x) | detile: 95.5 -> 47.1 us ( 2.03x) BC7_2048x1024 tile: 75.1 -> 48.3 us ( 1.56x) | detile: 54.3 -> 43.9 us ( 1.24x) BC7_1920x1080 tile: 67.7 -> 42.4 us ( 1.60x) | detile: 55.1 -> 41.6 us ( 1.32x) ``` - Ran `python3 -I scripts/check_no_game_data.py` on both files and `python3 -I tests/test_text_write_line_endings.py`: all passed. --- <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#1973
No description provided.