mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 22:50:53 +01:00
[PR #146] resource_detile: strip-mined cache-line micro-tile copies, 1.2x-14.6x faster, bit-identical (PERF-RESOURCE-DETILE) #198
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#198
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/146
Author: @Andretuta
Created: 11/24/2026
Status: 🔄 Open
Base:
main← Head:old-pr/9879📝 Commits (1)
8df2051resource_detile: strip-mined cache-line micro-tile copies (1.2x-14.6x faster, bit-identical)📊 Changes
2 files changed (+330 additions, -43 deletions)
View changed files
📝
runtime/src/resource_detile.h(+235 -43)📝
runtime/test/resource_detile_test.cpp(+95 -0)📄 Description
Original description (mentions and
#Nreferences are disabled; the numbers refer to the old repository):Claimed in the coordination issue as: https://github.com/ProjectLeonida/Leonida/issues/9677#issuecomment-7116739617
(Resubmission of
#9399, which was closed during the repo transfer cleanup after 6 independent verification passes; cleanly rebased ontoProjectLeonida/Leonidamain7e39a81eaand re-verified.)Summary
detile_surface_64k()andtile_surface_64k()inruntime/src/resource_detile.hpreviously copied one element at a time in row-major order across all 64 KiB macro-tiles, recomputingx / tile_w,x % tile_w,lut_x[...]andtx * 65536per element and touching each tiled cache line repeatedly across separate scanlines.Every GFX10
SW_64KB_Dbit pattern (Mesa addrlib GFX10_SW_64K_D_RBPLUS_PATINFO) maps an aligned micro-tile directly into contiguous 64-byte cache lines in tiled memory:8x80,2,1,3,4,6,5,7)8x44x44x24x4Sweeping
yin strips ofmicro_hrows and streamingxsequentially across macro-tiles touches each tiled cache line completely in one pass, keeps linear memory streaming sequentially (avoiding power-of-two linear-stride L1 set conflicts), and cuts LUT lookups by 8x–64x — with 100% bit-identical output and pure portable ISO C++20 (no intrinsics or compiler extensions).Changes
runtime/src/resource_detile.h:detile_typed()/tile_typed()loops with a sharedcopy_surface_64k_typed<Bpe, ToTiled>()implementation using strip-mined 64 B / 256 B micro-tile transfers plus overflow-safe right-edge and bottom-edge tails.constexpr bool verify_microtile_layout_64k<Bpe>()andstatic_assertproofs for all five BPEs (1, 2, 4, 8, 16), proving at compile time againstSwizzleLut64K<Bpe>that X and Y bit masks are disjoint across the full 64 KiB tile and every micro-tile / contiguous-run offset matches the scalar LUT exactly.runtime/test/resource_detile_test.cpp:test_exact_against_scalar<Bpe>()andtest_all_edge_remainders<Bpe>()comparing bothtile_surface_64k()anddetile_surface_64k()byte-for-byte against an independent scalarSwizzleLut64K<Bpe>reference across all 5 BPEs, all edge remainders modulo micro-tile and 64 KiB tile dimensions, and BCn (block_dim = 4) surfaces, while verifying all inactive0xCCpadding bytes stay untouched.Benchmark (Windows 11 x64, MSVC 19.50.35721
/O2, median of 5 trials, bit-identical verified)detile_surface_64k(before -> after)tile_surface_64k(before -> after)512x512 R8 (1B)0.25 MiB0.272 -> 0.022 ms(12.47x)0.249 -> 0.017 ms(14.64x)512x512 R16 (2B)0.50 MiB0.235 -> 0.033 ms(7.06x)0.251 -> 0.031 ms(8.12x)512x512 RGBA8 (4B)1.00 MiB0.312 -> 0.074 ms(4.22x)0.356 -> 0.075 ms(4.73x)1024x1024 BC1 (8B)0.50 MiB0.071 -> 0.033 ms(2.16x)0.071 -> 0.024 ms(3.01x)1024x1024 BC7 (16B)1.00 MiB0.088 -> 0.075 ms(1.16x)0.096 -> 0.051 ms(1.87x)1920x1080 RGBA87.91 MiB4.114 -> 2.176 ms(1.89x)3.290 -> 2.081 ms(1.58x)4096x4096 R8 (1B)16.00 MiB27.133 -> 6.574 ms(4.13x)17.464 -> 5.048 ms(3.46x)4096x4096 R16 (2B)32.00 MiB29.900 -> 13.476 ms(2.22x)20.299 -> 10.261 ms(1.98x)4096x4096 RGBA864.00 MiB34.829 -> 17.721 ms(1.97x)25.407 -> 16.901 ms(1.50x)4096x4096 BC1 (8B)8.00 MiB3.508 -> 2.733 ms(1.28x)3.622 -> 2.645 ms(1.37x)4096x4096 BC7 (16B)16.00 MiB8.106 -> 6.164 ms(1.32x)7.126 -> 4.969 ms(1.43x)Verification (rebased onto
7e39a81ea)cmake --build runtime/build --config Release --target resource_detile_test-> clean build (all 5static_assertlayout proofs pass).ctest --test-dir runtime/build -C Release -R ^resource_detile$ --output-on-failure -V-> 1/1 passed (0.19 sec)./std:c++20 /W4 /WX /permissive- /utf-8-> 0 warnings, 0 errors.-std=c++20 -O2 -Wall -Wextra -Werror -Wpedantic-> 0 warnings, 0 errors, test passed.python -I scripts/check_no_game_data.py runtime/src/resource_detile.h runtime/test/resource_detile_test.cpp-> exit0.git diff origin/main..HEAD --check-> exit0;0CR (\r) bytes.Clean-room & disclosure
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.