runtime: copy contiguous X micro-runs in TiledSurface2D::tile/detile #1951

Closed
leonida/mandy
quietfold wants to merge 0 commits from perf/rt-gfx10-tiling-fast-runs into main

Pull request closed

This pull request cannot be reopened because the branch was deleted.

quietfold commented 2026-11-25 16:33:52 +00:00

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)
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)
copilot-pull-request-reviewer[bot] reviewed 2026-11-25 16:41:42 +00:00
copilot-pull-request-reviewer[bot] left a comment
No description provided.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
zmasi commented 2026-11-28 12:17:28 +00:00

#1951 | head 1e88ddb43666d9be6511f252fb27c9ed39b78df8 (merged cleanly with main d48a957bb9988afce424552a3c0c8d01ef12320f) | ctest --test-dir runtime/build -C RelWithDebInfo -R "^(gfx10_tiling|resource_tiling|d3d12_mapped_plane_async)$" --output-on-failure (LEONIDA_VK_VALIDATION=1) + A/B 1024x1024 sw_64kb_d 4B tile+detile round-trip timing | baseline on main: gfx10_tiling passes (5.997 ms per round-trip) | green on PR+main: 3/3 CTests pass (gfx10_tiling 0.478 ms per round-trip — 12.55x faster on MSVC RelWithDebInfo with bit-exact output across all 40 surface round trips + padded bijections + 30 Python offsets, resource_tiling, and d3d12_mapped_plane_async) on RTX 3090 with 0 Khronos validation errors; check_no_game_data.py 0 violations | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yes

#1951 | head 1e88ddb43666d9be6511f252fb27c9ed39b78df8 (merged cleanly with main d48a957bb9988afce424552a3c0c8d01ef12320f) | `ctest --test-dir runtime/build -C RelWithDebInfo -R "^(gfx10_tiling|resource_tiling|d3d12_mapped_plane_async)$" --output-on-failure` (`LEONIDA_VK_VALIDATION=1`) + A/B `1024x1024` `sw_64kb_d` 4B `tile`+`detile` round-trip timing | baseline on main: `gfx10_tiling` passes (`5.997 ms` per round-trip) | green on PR+main: 3/3 CTests pass (`gfx10_tiling` `0.478 ms` per round-trip — **12.55x faster** on MSVC `RelWithDebInfo` with bit-exact output across all 40 surface round trips + padded bijections + 30 Python offsets, `resource_tiling`, and `d3d12_mapped_plane_async`) on RTX 3090 with `0` Khronos validation errors; `check_no_game_data.py` `0` violations | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yes
OreoFR commented 2026-11-28 21:56:23 +00:00

Verified by OreoFR

  • Base: main c1ecf04ed + PR head 1e88ddb43; green run in a merge package of 15 PRs, no new ctest failure vs main
  • Test: ctest -R ^gfx10_tiling$
  • Red on main: OK
  • Green with the PR: OK
  • Verdict: NO RED (tile/detile optimisation; the added test also passes on main)
  • Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11

AI-assisted (Claude Code, Claude Opus 5.5).

**Verified by OreoFR** - Base: main `c1ecf04ed` + PR head `1e88ddb43`; green run in a merge package of 15 PRs, no new ctest failure vs main - Test: `ctest -R ^gfx10_tiling$` - Red on main: OK - Green with the PR: OK - Verdict: NO RED (tile/detile optimisation; the added test also passes on main) - Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11 AI-assisted (Claude Code, Claude Opus 5.5).
aslan2142 commented 2026-12-01 16:40:10 +00:00

Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.
Sign in to join this conversation.
No description provided.