Textures: cache GFX10 tiling Layout offset tables #1048

Manually merged
github merged 1 commit from gh-pr/1048/head into gh-pr/1048/base 2026-11-26 04:41:46 +00:00
Owner

@⁠AlpPesen on GitHub · 2026-11-24 10:52 UTC · original
AlpPesen:perf/cache-tiling-layout → main · +83 −23 · 1 files · 1 commits · merged 2026-11-25 10:49 UTC

Part of #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 #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).
    • The 3 failures are exclusively the pre-existing AMD RDNA2 packed-mip failure in placed_title_textures_share_vram_and_preserve_pixels (3D 64x64x64 4 mips: subresource 2 mismatch, fixed by open PR #470) plus its 2 VRAM_TEST_LOCK PoisonError cascades.

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.
**@⁠AlpPesen** on GitHub · 2026-11-24 10:52 UTC · [original](https://github.com/xcl-dev/xcl/pull/1048) `AlpPesen:perf/cache-tiling-layout` → `main` · +83 −23 · 1 files · 1 commits · merged 2026-11-25 10:49 UTC Part of #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 #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). - The 3 failures are exclusively the pre-existing AMD RDNA2 packed-mip failure in `placed_title_textures_share_vram_and_preserve_pixels` (`3D 64x64x64 4 mips: subresource 2 mismatch`, fixed by open PR #470) plus its 2 `VRAM_TEST_LOCK` `PoisonError` cascades. **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.
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 #449.
Assisted-by: Antigravity (Gemini 4 Neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:41:45 +00:00
github manually merged commit d9fcdce14b into gh-pr/1048/base 2026-11-26 04:41:46 +00:00
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 11:13 UTC · original

Independent verification, merged onto current main 384f7f7 locally (clean merge).

Machine: Windows 11, Ryzen 9 7900X Radeon iGPU (gfx1036 RDNA2) + RTX 3060 Ti; Rust stable MSVC, debug.

  • cargo test -p xcl --lib tiling: 15 passed, 0 failed — includes the new layout_cache_shares_tables_and_isolates_base_xor.
  • XCL_ADAPTER=radeon cargo test -p xcl --lib texture -- --test-threads=4: 29 passed, 0 failed — real placed-resource/title-texture paths on the Radeon exercise the cached Layout tables.

AI use: test runs by Devin (Cognition, SWE-2); no code changes.

**@⁠DavidM1911** on GitHub · 2026-11-24 11:13 UTC · [original](https://github.com/xcl-dev/xcl/pull/1048#issuecomment-7129814211) Independent verification, merged onto current `main` `384f7f7` locally (clean merge). **Machine:** Windows 11, Ryzen 9 7900X Radeon iGPU (gfx1036 RDNA2) + RTX 3060 Ti; Rust stable MSVC, debug. - `cargo test -p xcl --lib tiling`: **15 passed, 0 failed** — includes the new `layout_cache_shares_tables_and_isolates_base_xor`. - `XCL_ADAPTER=radeon cargo test -p xcl --lib texture -- --test-threads=4`: **29 passed, 0 failed** — real placed-resource/title-texture paths on the Radeon exercise the cached `Layout` tables. AI use: test runs by Devin (Cognition, SWE-2); no code changes.
Author
Owner

@⁠raylitebull on GitHub · 2026-11-25 01:08 UTC · original

Diff audit passed (tiling.rs LAYOUT_CACHE sharing &'static [u32] tables across non-XOR PipeConfig keys while preserving per-texture base_xor + Build and test + PR description green), with strong AMD RX 6800 + RDNA2 iGPU results.

Remaining before merge: one quick NVIDIA run on d9fcdce (or merged onto main) confirming gpu::tiling:: + gpu::texture:: / workspace suite pass there too.

**@⁠raylitebull** on GitHub · 2026-11-25 01:08 UTC · [original](https://github.com/xcl-dev/xcl/pull/1048#issuecomment-7149246837) Diff audit passed (`tiling.rs` `LAYOUT_CACHE` sharing `&'static [u32]` tables across non-XOR `PipeConfig` keys while preserving per-texture `base_xor` + `Build and test` + `PR description` green), with strong AMD RX 6800 + RDNA2 iGPU results. **Remaining before merge:** one quick **NVIDIA** run on `d9fcdce` (or merged onto `main`) confirming `gpu::tiling::` + `gpu::texture::` / workspace suite pass there too.
Author
Owner

@⁠AmateurWizrd on GitHub · 2026-11-25 03:07 UTC · original

NVIDIA run on d9fcdce (the PR head as it is): gpu::tiling:: 15 passed and gpu::texture:: 12 passed, 0 failed; the xcl crate's test binaries 727 passed, 1 failed (an access-rights failure of the test account, not this PR), 41 ignored. This is the run asked for in #1048.

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (32-lane waves only), driver 621.01; AMD Ryzen 7 7800X3D; 32 GB RAM; Windows 11 build 26200; Rust 1.100.0; debug test profile
  • PR head d9fcdce14bb3a2c3a98692fbfe512cf3ab55e8ae, clean checkout, cargo test --workspace --locked --offline --no-run, then each test binary of the xcl crate run with --test-threads=4
  • gpu::tiling::: 15 passed, 0 failed, 0 ignored, including layout_cache_shares_tables_and_isolates_base_xor
  • gpu::texture::: 12 passed, 0 failed, 0 ignored
  • All xcl crate test binaries: 727 passed, 1 failed, 41 ignored. SKIPPED GPU tests: gpu_geometry_wave32_prefix_count_over_a_mask and gpu_wave32_program_in_wave64_hardware (no wave64)
  • The 1 failure: test_title_runs_and_game_folder_is_untouched panics at e2e.rs:46 with "Access is denied", because the tests ran under a local account that may not write to that folder. It fails the same way on other commits here.

Not tested

  • The PR merged onto current main; the other workspace crates; a retail-title smoke pair (not asked for; the PR's base is older than current main)

AI use: omp. Claude Fable 5.2 ran the tests and wrote this report; Claude Opus 5.5 reviewed the diff before the build.

**@⁠AmateurWizrd** on GitHub · 2026-11-25 03:07 UTC · [original](https://github.com/xcl-dev/xcl/pull/1048#issuecomment-7151606878) **NVIDIA run on `d9fcdce` (the PR head as it is): `gpu::tiling::` 15 passed and `gpu::texture::` 12 passed, 0 failed; the `xcl` crate's test binaries 727 passed, 1 failed (an access-rights failure of the test account, not this PR), 41 ignored.** This is the run asked for in https://git.gtahub.st/github/xcl-dev--xcl/pulls/1048. **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (32-lane waves only), driver 621.01; AMD Ryzen 7 7800X3D; 32 GB RAM; Windows 11 build 26200; Rust 1.100.0; debug test profile - PR head `d9fcdce14bb3a2c3a98692fbfe512cf3ab55e8ae`, clean checkout, `cargo test --workspace --locked --offline --no-run`, then each test binary of the `xcl` crate run with `--test-threads=4` - `gpu::tiling::`: 15 passed, 0 failed, 0 ignored, including `layout_cache_shares_tables_and_isolates_base_xor` - `gpu::texture::`: 12 passed, 0 failed, 0 ignored - All `xcl` crate test binaries: 727 passed, 1 failed, 41 ignored. SKIPPED GPU tests: `gpu_geometry_wave32_prefix_count_over_a_mask` and `gpu_wave32_program_in_wave64_hardware` (no wave64) - The 1 failure: `test_title_runs_and_game_folder_is_untouched` panics at `e2e.rs:46` with "Access is denied", because the tests ran under a local account that may not write to that folder. It fails the same way on other commits here. **Not tested** - The PR merged onto current `main`; the other workspace crates; a retail-title smoke pair (not asked for; the PR's base is older than current `main`) **AI use**: omp. Claude Fable 5.2 ran the tests and wrote this report; Claude Opus 5.5 reviewed the diff before the build.
Author
Owner

@⁠thehollowedone on GitHub · 2026-11-25 08:54 UTC · original

Independent full workspace run on d9fcdce, clean detached checkout. Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (621.35), Rust 1.99.1 MSVC, Windows SDK 10.0.26100.0 / DXC 1.8.2502.11.

  • cargo build --workspace --offline --locked -j 4 passed.
  • cargo test --workspace --offline --locked --no-fail-fast -j 4 -- --nocapture --test-threads=4 finished with 728 passed, 0 failed, 41 ignored. Cargo's pass count includes two runtime skips for unavailable native wave64.
  • layout_cache_shares_tables_and_isolates_base_xor and test_title_runs_and_game_folder_is_untouched both passed.

This run used the workspace fixtures. Retail smoke and performance were outside its scope. AI use: Codex (GPT-6, exact variant unspecified) ran the suite and drafted this report.

**@⁠thehollowedone** on GitHub · 2026-11-25 08:54 UTC · [original](https://github.com/xcl-dev/xcl/pull/1048#issuecomment-7157614073) Independent full workspace run on [d9fcdce](https://github.com/xcl-dev/xcl/commit/d9fcdce14bb3a2c3a98692fbfe512cf3ab55e8ae), clean detached checkout. Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (621.35), Rust 1.99.1 MSVC, Windows SDK 10.0.26100.0 / DXC 1.8.2502.11. - `cargo build --workspace --offline --locked -j 4` passed. - `cargo test --workspace --offline --locked --no-fail-fast -j 4 -- --nocapture --test-threads=4` finished with **728 passed, 0 failed, 41 ignored**. Cargo's pass count includes two runtime skips for unavailable native wave64. - `layout_cache_shares_tables_and_isolates_base_xor` and `test_title_runs_and_game_folder_is_untouched` both passed. This run used the workspace fixtures. Retail smoke and performance were outside its scope. AI use: Codex (GPT-6, exact variant unspecified) ran the suite and drafted this report.
This discussion has been locked. Commenting is limited to contributors.
No description provided.