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

Manually merged
github merged 1 commit from gh-pr/435/head into gh-pr/435/base 2026-11-26 04:21:43 +00:00
Owner

@⁠Cattn on GitHub · 2026-11-24 00:15 UTC · original
Cattn:tiling-swizzle-table-size → main · +43 −1 · 1 files · 1 commits · merged 2026-11-24 02:34 UTC

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.
**@⁠Cattn** on GitHub · 2026-11-24 00:15 UTC · [original](https://github.com/xcl-dev/xcl/pull/435) `Cattn:tiling-swizzle-table-size` → `main` · +43 −1 · 1 files · 1 commits · merged 2026-11-24 02:34 UTC 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.
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).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:21:42 +00:00
github manually merged commit a94e1511e0 into gh-pr/435/base 2026-11-26 04:21:43 +00:00
Author
Owner

@⁠MesshM on GitHub · 2026-11-24 00:28 UTC · original

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.

**@⁠MesshM** on GitHub · 2026-11-24 00:28 UTC · [original](https://github.com/xcl-dev/xcl/pull/435#issuecomment-7118097423) 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.
Author
Owner

@⁠mastrr9 on GitHub · 2026-11-24 00:30 UTC · original

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.

**@⁠mastrr9** on GitHub · 2026-11-24 00:30 UTC · [original](https://github.com/xcl-dev/xcl/pull/435#issuecomment-7118144343) 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.*
Author
Owner

@⁠TheHoracio on GitHub · 2026-11-24 00:36 UTC · original

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.

**@⁠TheHoracio** on GitHub · 2026-11-24 00:36 UTC · [original](https://github.com/xcl-dev/xcl/pull/435#issuecomment-7118250112) 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.
Author
Owner

@⁠alpz1000 on GitHub · 2026-11-24 01:47 UTC · original

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.

**@⁠alpz1000** on GitHub · 2026-11-24 01:47 UTC · [original](https://github.com/xcl-dev/xcl/pull/435#issuecomment-7119445014) 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.
Author
Owner

@⁠imnicho on GitHub · 2026-11-24 02:05 UTC · original

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)
  • It is time as well as memory. In 12 thread dumps 7 s apart (150 s – 227 s) of the run without it, 10 had a title thread in gpu::tiling::Layout::from_bits (under Layout::new ← Chain::new_3d); the title presented almost no frame in that time, and in two earlier runs on that stack its null write (#232) came there.
  • The memory rows are from a walk of the process with VirtualQueryEx (committed regions by allocation; residency sampled at one page in 16 with QueryWorkingSetEx), not from XCL's counters. Allocations of up to 16 MB are where the process heap's segments are.
  • The run with #435 ended at 163 s with an access violation that is not this PR's: the title got that far for the first time here, and what stops it next is the texture computer's CopyFromSubresource, called with seven arguments (the fix is in #539; I had the same one locally).

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.

**@⁠imnicho** on GitHub · 2026-11-24 02:05 UTC · [original](https://github.com/xcl-dev/xcl/pull/435#issuecomment-7119743401) 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) | - **It is time as well as memory.** In 12 thread dumps 7 s apart (150 s – 227 s) of the run without it, 10 had a title thread in `gpu::tiling::Layout::from_bits` (under `Layout::new` ← `Chain::new_3d`); the title presented almost no frame in that time, and in two earlier runs on that stack its null write (#232) came there. - The memory rows are from a walk of the process with `VirtualQueryEx` (committed regions by allocation; residency sampled at one page in 16 with `QueryWorkingSetEx`), not from XCL's counters. Allocations of up to 16 MB are where the process heap's segments are. - The run with #435 ended at 163 s with an access violation that is not this PR's: the title got that far for the first time here, and what stops it next is the texture computer's `CopyFromSubresource`, called with seven arguments (the fix is in #539; I had the same one locally). **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.
This discussion has been locked. Commenting is limited to contributors.
No description provided.