Skip to content

Textures: a layout's high-coordinate tables hold one period, not 65536 entries - #435

Merged
theaustinayers merged 1 commit into
xcl-dev:mainfrom
Cattn:tiling-swizzle-table-size
Nov 24, 2026
Merged

theaustinayers merged 1 commit into
xcl-dev:mainfrom
Cattn:tiling-swizzle-table-size

Conversation

@Cattn

@Cattn Cattn commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Part of #248 (memory while a title streams its world).

Every xg::Texture builds its own gpu::tiling::Layout, and Layout::from_bits built the tables for the coordinates above a block (hx, hy, hz) over the whole 16-bit coordinate range. For a 2D surface the z table alone is 65,536 u32 entries, so 256 KiB of CPU memory per live tiled title texture. The entries depend only on the coordinate bits the block's pattern masks actually use, which is 1 to 32 entries. Each table now covers the power of two above the highest such bit, or one entry when none is used. offset_z already indexes the tables modulo their length, so every offset is unchanged.

What is in it

  • crates/xcl/src/gpu/tiling.rs: Layout::from_bits sizes each high-coordinate table from the OR of the masks bits[..blk] use on that axis, above the in-block bits.
  • New test high_coordinate_tables_keep_their_offsets_at_one_period. Every 2D mode and thick 3D mode, element size and pipe configuration in the existing test sets is compared against tables of the full 16-bit range, for coordinates up to 2^18 and past 32 bits. It fails before the change ("2D mode 1 e 0 …: 65536 z entries").

Tested

  • RTX 4070 12 GB (driver 617.42), Ryzen 7 7800X3D, 32 GB RAM, Windows 11 26200, rustc 1.93.1.
  • cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4: 677 passed, 0 failed, 41 ignored.
  • SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • cargo test --release -p xcl --lib tiling: 12 passed. The new test fails with the old table size.

Regression run

main:

xcl-smoke v1
commit: a6f5f7a74cc620c1f88a9e3669a633d10c3c8212
gpu: NVIDIA GeForce RTX 4070
title: 2615684f
seconds: 60
exit: 0x0
frames shown: 417 (PresentX 417)
presents per 2 s (last 3): 7 8 7
device removals: 0
crashes: 0
peak commit: 15076 MB

PR:

xcl-smoke v1
commit: a94e1511e0a5f378ff10e4daf701ebaa9da506eb
gpu: NVIDIA GeForce RTX 4070
title: 2615684f
seconds: 60
exit: 0x0
frames shown: 874 (PresentX 875)
presents per 2 s (last 3): 7 8 7
device removals: 0
crashes: 0
peak commit: 14911 MB

The main run was the first after a fresh build of a new main and filled the shader cache; I don't attribute the frame difference to this change.

Not tested

  • The memory saved in a retail run. The 60 s smoke run stays at the first menu with few tiled textures. One longer world-streaming comparison on a larger local stack wasn't aligned enough to read the saving from process commit. The per-texture size is from the test: a 2D z table goes from 256 KiB to 4–128 bytes.
  • AMD GPUs.

AI use

  • Claude Code (Claude Opus 5.5): wrote the change, the test and this description. The table size was found by a gpt-6.2-astra research subagent reading the code. I ran the builds, tests and smoke runs above on the hardware named.

…6 entries

Layout::from_bits built the tables for the coordinates above a block (hx, hy,
hz) over the whole 16-bit range. For a 2D surface the z table alone is
65536 u32 entries – 256 KiB – and every xg::Texture builds its own Layout,
so each live tiled title texture carried about 256 KiB of CPU memory.

The entries depend only on the coordinate bits the block's pattern masks use.
Each table now covers the power of two above the highest such bit (one
entry when no bit is used); offset_z already indexes the tables modulo their
length, so every offset is unchanged.

The test compares every 2D and thick 3D mode, element size and pipe
configuration against the full-range tables, for coordinates up to and past
16 bits, and fails before the change (a 2D z table of 65536 entries).
@MesshM

MesshM commented Nov 24, 2026

Copy link
Copy Markdown

Test run of a94e1511e0a5f378ff10e4daf701ebaa9da506eb on AMD (RDNA4), which Not tested lists.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4), driver 32.0.32029.2010; XCL picked it (backend 'real' – AMD Radeon RX 9060 XT (16191 MiB VRAM))
  • Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4): 677 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 637 passed, 0 failed, 21 ignored
  • 0 SKIPPED on this adapter, so the two wave64 tests skipped on the RTX 4070 ran and passed here
  • same machine on main a6f5f7a: 676 passed, 0 failed, 41 ignored; the only difference is the new test
  • with only the Layout::from_bits change reverted, cargo test -p xcl --lib high_coordinate_tables: 0 passed, 1 failed (2D mode 1 e 0 PipeConfig { pipes_log2: 0, pkrs_log2: 0 }: 65536 z entries), as the description says

Review of the change: the high-coordinate tables are read only in offset_z (tiling.rs:176), always as t[(c / b) % t.len()]. The new size is a power of two above the highest mask bit used on that axis, so it divides the old length and every lookup gives the same entry; with no bit used the table has one entry, as before. I found nothing to change.

Not tested: no retail title or regression run (I have no unpacked game), no XCL_SAMPLE_* tests, release build, memory use not measured.

Run and report by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.

@mastrr9

mastrr9 commented Nov 24, 2026

Copy link
Copy Markdown

Code audit + NVIDIA RTX 5080 test run on a94e1511e0a5f378ff10e4daf701ebaa9da506eb:

Review

Looks clean and mathematically exact:

  • offset_z indexes high-coordinate tables with (c / b) % t.len(), and used = OR_{i < blk} ((bits[i] >> shift) & 0xFFFF) >> l.min(16) masks every bit of c / b that can affect any parity term.
  • 1 << (32 - used.leading_zeros()) is always a power of two in 1..=1 << (16 - l.min(16)) (1 when used == 0, e.g. 2D hz), preserving exact periodicity while shrinking 2D hz tables from 256 KiB to 4 bytes.

Tested

  • Hardware / OS / toolchain: NVIDIA GeForce RTX 5080 (driver 617.42), AMD Ryzen 7 9800X3D, Windows 11 25H2 (build 26200.9711), rustc 1.100.0 (MSVC), debug build.
  • cargo build --workspace && cargo test --workspace -- --test-threads=4: 677 passed, 0 failed, 41 ignored.
  • New test gpu::tiling::tests::high_coordinate_tables_keep_their_offsets_at_one_period: passed.
  • SKIPPED GPU tests (2, wave32-only adapter): gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask: no wave64, gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware: no wave64.

Not tested

  • Retail title / scripts/smoke.ps1 run (test suite only).
  • AMD / Intel GPUs.

AI use: code review and test run orchestrated with Antigravity (Gemini 4 Neon) on the hardware listed above.

@TheHoracio

Copy link
Copy Markdown
Contributor

Test report on AMD RDNA3: RX 7800 XT (16 GB), driver 32.0.32015.7029, Ryzen 7 9800X3D, Windows 11 Pro 10.0.26300, Rust 1.100.0 MSVC, DXC 1.9.2602.17, debug build. No retail data was used.

Tested: the PR head a94e151 as it is (on its base a6f5f7a, not merged onto current main).

  • cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4: 677 passed, 0 failed, 41 ignored, no SKIPPED tests.
  • The new high_coordinate_tables_keep_their_offsets_at_one_period passes. This covers the AMD GPUs item under Not tested for RDNA3, for the test suite only.

Not tested: a regression run on a title, a release build, and the head merged onto current main.

AI use: Claude Code ran the commands and drafted this comment; the runs are real runs on the hardware above.

@alpz1000

Copy link
Copy Markdown

Independent CPU-side layout construction benchmark on an Intel Core i5-8400, Windows 11 Home 26200.9974, Rust 1.100.0 x86_64-pc-windows-msvc. Compared base a6f5f7a74cc620c1f88a9e3669a633d10c3c8212 with PR head a94e1511e0a5f378ff10e4daf701ebaa9da506eb.

Tested: identical temporary release-mode Cargo example calling Layout::new(mode, 2, PipeConfig { pipes_log2: 0, pkrs_log2: 0 }). Timings include construction and drop. Each process measured the median of ten batches of 200 layouts after one warm-up batch. Process order was base, PR, PR, base.

Mode Base medians (µs/layout) PR medians (µs/layout)
1 835.811 / 869.306 0.627 / 0.622
9 1325.961 / 1340.721 7.589 / 7.585

cargo test --locked --release -p xcl --lib gpu::tiling::tests also passed 12/12, including the high-coordinate offset regression. The temporary example was removed afterward.

Not tested: retail performance, memory savings in a running title, or the full workspace suite. This benchmark measures only synthetic layout construction, with no GPU or game files needed.

AI use: OpenAI Codex (GPT-6) wrote the temporary benchmark, ran both builds and the tests, and drafted the report.

@imnicho

imnicho commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Test report on a retail title streaming its world – the run listed under Not tested. a94e151 merged onto main 2997c9a, release; #334, #266 and #490 are merged in both builds as well (this PC does not get to the world's streaming in a useful time without them).

Machine: Intel Core i7-7700K (4 cores / 8 threads), 16 GB RAM, NVIDIA GeForce RTX 5080 16 GB (driver 610.47), Windows 10 22H2 (19045), rustc 1.100.0. The newer retail title of the README, the same pad script (XCL_PRESS_AT) for both, one run each.

without #435 with #435
16 384 textures kept in step at 111 s 99 s
32 768 textures kept in step at 169 s 113 s
the title starts setting up its world's graphics at 299 s 161 s
committed in allocations of up to 16 MB, 150 s into the run 5 867 MB in 457 allocations, 4 677 MB of it resident 2 740 MB in 276, 697 MB resident
the same, 205 s into the run 10 068 MB in 724, 6 200 MB resident (run over, see below)

Not tested: AMD and Intel GPUs; more than one run of each build; the frame rate in the world (not reached).

AI use: Claude Code with Claude Fable 5.2 ran the builds and runs and wrote this report; every number is from a run on the machine named. No game files are attached.

@theaustinayers
theaustinayers merged commit 3db536e into xcl-dev:main Nov 24, 2026
2 checks passed
theaustinayers added a commit to theaustinayers/xcl that referenced this pull request Nov 24, 2026
…l#486, ivall#574, ivall#602, ivall#634, ivall#636

Upstream's texture detiling and uploads replace the fork's (ivall#440 and the threaded detile); its disk cache of driver blobs (ivall#634) replaces the fork's first version.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
mastrr9 added a commit to mastrr9/xcl that referenced this pull request Nov 24, 2026
Check every tiling mode, element size and pipe configuration: offsets
one-to-one and in bounds, equal to addrlib's swizzle equations across
the full coordinate range (guarding xcl-dev#435), tile / detile round trips,
the detile fast paths from xcl-dev#451 and xcl-dev#602 against a texel-by-texel
reader, mip chains and volumes without overlaps, and invalid input
giving None.

Assisted-by: Claude Code (Claude Opus 5.5)
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.

7 participants