Skip to content

[upstream #1048] Textures: cache GFX10 tiling Layout offset tables - #100

Closed
ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/1048
Closed

ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/1048

Conversation

@ufoptg

@ufoptg ufoptg commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Part of xcl-dev#449 (item 2: cache gpu::tiling::Layout::from_bits offset tables).

Layout::new and Layout::new_3d previously recomputed the GF(2) bit-offset tables and allocated six Vec<u32>s on every call (CreatePlacedResourceX constructs xg::Texture::new twice per texture). Because the tables depend only on (is_3d, mode, elem_log2, pipe_cfg) and only base_xor varies per texture, this caches the immutable tables as &'static [u32] in a bounded RwLock<HashMap<...>> and makes Layout Copy.

Overlap note: touches only crates/xcl/src/gpu/tiling.rs lines 9-155 and adds one unit test at the end of tiling.rs — disjoint from xcl-dev#901 (detile / image_layout from line 178 onward).

What is in it

  • crates/xcl/src/gpu/tiling.rs:
    • Derive Hash on PipeConfig and Copy on Layout, changing private offset tables (ox/oy/oz/hx/hy/hz) from Vec<u32> to &'static [u32].
    • Add double-checked LAYOUT_CACHE (OnceLock<RwLock<HashMap<(bool, u32, u32, PipeConfig), Layout>>>) in cached_layout, canonicalizing PipeConfig for non-XOR modes (!is_xor(mode)) and caching only valid combinations (invalid calls return None without inserting or allocating).
    • Add unit test layout_cache_shares_tables_and_isolates_base_xor verifying pointer sharing, base_xor isolation across callers, non-XOR PipeConfig sharing, 2D vs 3D thick separation, and non-caching of invalid keys.

Measured speedup (--release, Intel Core i9-9900K, 4,000 calls, mode 25 / BC7)

  • Uncached GF(2) table rebuild alone (excluding the 6 Vec<u32> heap allocations/drops): 3.15 us/call (12,594 us for 4,000 calls)
  • Cached Layout::new(25, 4, cfg): 0.048 us/call (193 us for 4,000 calls) — 65.3x faster, 0 per-call heap allocations.

Tested

  • Hardware: Windows 11 Pro for Workstations (Build 26300), Intel Core i9-9900K, AMD Radeon RX 6800 (16337 MiB VRAM, driver 32.0.21045.29003), rustc 1.100.0 (x86_64-pc-windows-msvc), DXC 1.9.2602.17 (debug for tests, release for benchmark & smoke runs).
  • cargo test -p xcl --lib gpu::tiling::: 15 passed, 0 failed.
  • XCL_REQUIRE_GPU=wave64,mesh + cargo test --workspace --no-fail-fast -- --test-threads=4 on d9fcdce: 725 passed, 3 failed, 41 ignored, 0 GPU skipped (xcl lib: 683 passed / 3 failed / 21 ignored; integration/e2e: 42 passed / 0 failed / 20 ignored; XCL_SAMPLE_* unset).

Regression run
Both runs below on YouKnowWho (60 s, release):

main (09940bb87fa1):

xcl-smoke v1
commit: 09940bb87fa11bc394fd9e5de570c2b7cfd16323
gpu: AMD Radeon RX 6800
title: YouKnowWho
seconds: 60
exit: 0x0
frames shown: 405 (PresentX 405)
presents per 2 s (last 3): 11 12 11
device removals: 0
crashes: 0
peak commit: 15870 MB

PR head (d9fcdce14bb3):

xcl-smoke v1
commit: d9fcdce14bb3a2c3a98692fbfe512cf3ab55e8ae
gpu: AMD Radeon RX 6800
title: YouKnowWho
seconds: 60
exit: 0x0
frames shown: 974 (PresentX 974)
presents per 2 s (last 3): 49 43 22
device removals: 0
crashes: 0
peak commit: 10284 MB

Not tested

  • Sample-data tests (XCL_SAMPLE_* unset).

AI use

  • Implemented, benchmarked, tested, and verified with Antigravity (Gemini 4 Neon); every change and measurement reviewed by the author on local hardware.

Mirror of xcl-dev#1048 (auto-synced, do not edit).

…ze, and pipe config

Layout::new and Layout::new_3d previously recomputed the GF(2) offset tables
and allocated six Vec<u32>s on every call (called twice per placed texture in
CreatePlacedResourceX). Because the tables depend only on (is_3d, mode,
elem_log2, pipe_cfg) and only base_xor varies per texture, cache the immutable
tables as &'static [u32] in a bounded RwLock<HashMap<...>> and make Layout
Copy. Invalid combinations return None without inserting into the cache.

Measured in release mode on Intel Core i9-9900K (4,000 calls, mode 25 / BC7):
3.15 us/call (table rebuild alone, excluding 6 Vec allocs) -> 0.048 us/call
(65.3x faster, zero per-call heap allocations).

Part of xcl-dev#449.
Assisted-by: Antigravity (Gemini 4 Neon)
@ufoptg

ufoptg commented Nov 25, 2026

Copy link
Copy Markdown
Owner Author

Upstream PR xcl-dev#1048 was closed or merged.

@ufoptg ufoptg closed this Nov 25, 2026
@ufoptg
ufoptg deleted the upstream-pr/1048 branch November 25, 2026 00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants