feat(texture): add GFX10 64 KiB tiling, XOR modes, mip tails, and 2D texture arrays (#14) #188

Closed
github-bot wants to merge 2 commits from gh-pr/188/head into gh-pr/188/base
Owner

@⁠Lewandox on GitHub · 2026-11-25 01:02 UTC · original
Lewandox:feat/texture-gfx10-64k-tiling → main · +1459 −25 · 9 files · 2 commits · closed without merging

Summary

Extends rust/anyxboxx-texture beyond SW_4K_S to support GFX10 / RDNA 2 64 KiB tiling, XOR swizzle modes (_T, _X, R_X, Z_X), 4 KiB / 64 KiB mip tails, and 2D texture arrays (Issue #14).

What changed

  • rust/anyxboxx-texture/src/gfx10_eq.rs:
    • Adds SwizzleMode (Linear, Sw256BS/D, Sw4KS/D, Sw64KS/D, Sw64KST/D_T, Sw4KSX/D_X, Sw64KSX/D_X, Sw64KRX, Sw64KZX) and PipeConfig (default SCARLETT 16 pipes / 8 PKRs, plus general power-of-two pipe/PKR configs and effective_pipe_bank_xor).
    • Implements RB+ 2D bit-equation generation (Equation::for_mode) derived from AMD's public MIT Mesa addrlib (src/amd/addrlib/src/gfx10/gfx10SwizzlePattern.h, gfx10addrlib.cpp), verified against all 900 RB+ entries across S/D/S_T/D_T/S_X/D_X (1..64 pipes, 1..32 PKRs, 1..16 BPE) plus the RB+ 16-pipe / 8-PKR tables for SW_64K_R_X and SW_64K_Z_X (1xAA).
  • rust/anyxboxx-texture/src/gfx10.rs:
    • Implements SurfaceDesc / SurfaceLayout (ComputeThinBlockDimension, GetMipTailDim, GetMaxNumMipsInTail, IsInMipTail with dsMipmapHtileFix for SW_64K_Z_X, smallest-first mip offsets, 4 KiB and 64 KiB mip tails up to 12 levels, and 2D texture array slicing).
    • Provides element_offset, detile_subresource, and tile_subresource.
  • rust/anyxboxx-texture/src/tiles.rs & src/main.rs:
    • Preserves all existing SW_4K_S helpers and --4k-s CLI flag unchanged.
    • Adds linearize_64k_s, linearize_64k_s_tail, linearize_bc7, and CLI options --64k-s, --mode <mode>, --xor <val>, --pipes <n>, --pkrs <n>, --mips <n>, --mip <i>, --array <n>, --slice <i> (rejecting unknown options explicitly).
  • THIRD_PARTY.md & 9 READMEs:
    • Credits AMD Mesa src/amd/addrlib (MIT) in THIRD_PARTY.md and updates the automated test count from 658 to 660 across all 9 READMEs.

Verification

  • cargo build --release --manifest-path rust/Cargo.toml -p anyxboxx-texture — clean build (0 warnings).
  • cargo test --release --manifest-path rust/Cargo.toml -p anyxboxx-texture — 13 passed, 0 failed (tests/bc7.rs: 5/5 unchanged digests; tests/gfx10_tiling.rs: 8/8 covering SW_4K_S parity, SW_64K_S, Mesa RB+ golden bit vectors, bijectivity across all 14 tiled modes × 5 BPEs × slices, 12-level 64 KiB mip tails, non-square XOR texture arrays, BC7 round-trip, and error paths).
  • python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools — passed.
  • python -m pytest -q — 459 passed, 201 skipped (tests/test_textures.py: 4/4 passed; tests/test_readme_sync.py: 660 tests synced across all 9 languages).

Refs #14

**@⁠Lewandox** on GitHub · 2026-11-25 01:02 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/188) `Lewandox:feat/texture-gfx10-64k-tiling` → `main` · +1459 −25 · 9 files · 2 commits · closed without merging ## Summary Extends `rust/anyxboxx-texture` beyond `SW_4K_S` to support GFX10 / RDNA 2 64 KiB tiling, XOR swizzle modes (`_T`, `_X`, `R_X`, `Z_X`), 4 KiB / 64 KiB mip tails, and 2D texture arrays (Issue #14). ### What changed - **`rust/anyxboxx-texture/src/gfx10_eq.rs`**: - Adds `SwizzleMode` (`Linear`, `Sw256BS/D`, `Sw4KS/D`, `Sw64KS/D`, `Sw64KST/D_T`, `Sw4KSX/D_X`, `Sw64KSX/D_X`, `Sw64KRX`, `Sw64KZX`) and `PipeConfig` (default `SCARLETT` 16 pipes / 8 PKRs, plus general power-of-two pipe/PKR configs and `effective_pipe_bank_xor`). - Implements RB+ 2D bit-equation generation (`Equation::for_mode`) derived from AMD's public MIT Mesa `addrlib` (`src/amd/addrlib/src/gfx10/gfx10SwizzlePattern.h`, `gfx10addrlib.cpp`), verified against all 900 RB+ entries across `S`/`D`/`S_T`/`D_T`/`S_X`/`D_X` (1..64 pipes, 1..32 PKRs, 1..16 BPE) plus the RB+ 16-pipe / 8-PKR tables for `SW_64K_R_X` and `SW_64K_Z_X` (1xAA). - **`rust/anyxboxx-texture/src/gfx10.rs`**: - Implements `SurfaceDesc` / `SurfaceLayout` (`ComputeThinBlockDimension`, `GetMipTailDim`, `GetMaxNumMipsInTail`, `IsInMipTail` with `dsMipmapHtileFix` for `SW_64K_Z_X`, smallest-first mip offsets, 4 KiB and 64 KiB mip tails up to 12 levels, and 2D texture array slicing). - Provides `element_offset`, `detile_subresource`, and `tile_subresource`. - **`rust/anyxboxx-texture/src/tiles.rs` & `src/main.rs`**: - Preserves all existing `SW_4K_S` helpers and `--4k-s` CLI flag unchanged. - Adds `linearize_64k_s`, `linearize_64k_s_tail`, `linearize_bc7`, and CLI options `--64k-s`, `--mode <mode>`, `--xor <val>`, `--pipes <n>`, `--pkrs <n>`, `--mips <n>`, `--mip <i>`, `--array <n>`, `--slice <i>` (rejecting unknown options explicitly). - **`THIRD_PARTY.md` & 9 READMEs**: - Credits AMD Mesa `src/amd/addrlib` (MIT) in `THIRD_PARTY.md` and updates the automated test count from `658` to `660` across all 9 READMEs. ### Verification - `cargo build --release --manifest-path rust/Cargo.toml -p anyxboxx-texture` — clean build (0 warnings). - `cargo test --release --manifest-path rust/Cargo.toml -p anyxboxx-texture` — **13 passed, 0 failed** (`tests/bc7.rs`: 5/5 unchanged digests; `tests/gfx10_tiling.rs`: 8/8 covering `SW_4K_S` parity, `SW_64K_S`, Mesa RB+ golden bit vectors, bijectivity across all 14 tiled modes × 5 BPEs × slices, 12-level 64 KiB mip tails, non-square XOR texture arrays, BC7 round-trip, and error paths). - `python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools` — passed. - `python -m pytest -q` — **459 passed, 201 skipped** (`tests/test_textures.py`: 4/4 passed; `tests/test_readme_sync.py`: 660 tests synced across all 9 languages). Refs #14
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:36:21 +00:00
github-bot closed this pull request 2026-11-26 05:36:21 +00:00
Author
Owner

@⁠Yoshi-233 on GitHub · 2026-11-25 02:47 UTC · original

I ran the texture crate at the actual PR head 22c1cf973e7e on Ubuntu 24.04.5 x86-64 with Rust 1.98.1:

cargo test --locked --manifest-path rust/Cargo.toml -p anyxboxx-texture

All 8 new tiling tests and all 5 existing BC7 tests passed. In particular, the twelve mip-tail levels stayed disjoint and round-tripped, the legacy 4 KiB S path matched byte for byte, and the BC7 round-trip through a 64 KiB XOR-tiled array passed. These are CPU layout/codec results from synthetic fixtures.

**@⁠Yoshi-233** on GitHub · 2026-11-25 02:47 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/188#issuecomment-7151190742) I ran the texture crate at the actual PR head `22c1cf973e7e` on Ubuntu 24.04.5 x86-64 with Rust 1.98.1: ```sh cargo test --locked --manifest-path rust/Cargo.toml -p anyxboxx-texture ``` All 8 new tiling tests and all 5 existing BC7 tests passed. In particular, the twelve mip-tail levels stayed disjoint and round-tripped, the legacy 4 KiB S path matched byte for byte, and the BC7 round-trip through a 64 KiB XOR-tiled array passed. These are CPU layout/codec results from synthetic fixtures.
Author
Owner

@⁠akimfomin on GitHub · 2026-11-25 03:02 UTC · original · edited 2026-11-25 04:17 UTC

Lewandox, I used PortBridge to try a follow-up on your exact 22c1cf9 GFX10 copy path. The candidate reuses the X side of the address equation across rows and the Y side across columns. I compared detiling and the entire tiled backing against your element_offset on 104 generated layouts, including higher pipe bits, arrays and mip tails. All eight upstream GFX10 tests and our three targeted tests passed in both arms.

On an i5-13600KF, four alternating warm CPU pairs for synthetic 1920×1080 RGBA8 XOR copies went from 35.62 → 2.51 ms for tiling and 36.34 → 3.71 ms for detiling. At 3840×2160 BC7 they went from 8.85 → 1.54 ms and 10.15 → 1.70 ms. A direct path kept the smallest mip copies near the old cost. All timed output hashes matched.

Patch, standalone fixture and raw pairs. These measure the generated texture copy on CPU, with the same input and output. No GPU or game-load effect was measured.

Separate BC7 export follow-up, source checked against main b92a71b9 and apply-checked on your 22c1cf97 head. The block decoder no longer allocates a vector for anchors, selects the weight tables once per block and copies visible rows into the image. The CPU output matched on 4,560 generated blocks and 400 image shapes. A 512-block image went from 513 allocations to 1. Four alternating warm CPU pairs measured 91.14 → 51.86 ms for 3840×2160 and 22.18 → 12.17 ms for cropped 1919×1079. This is a separate patch for BC7-to-RGBA conversion. Patch, oracle and raw samples. AI-assisted PortBridge engineering (OpenAI Codex).

The same patch was also checked against the actual synthetic BC7-to-PNG CLI path, with a new process for each arm. Full 3840×2160 export was 273.925 → 226.422 ms and 1919×1079 was 72.327 → 60.443 ms. All 16 files matched exactly within their shape and passed an independent PNG/CRC check. The OS page cache was not flushed. CLI runner and all samples.

**@⁠akimfomin** on GitHub · 2026-11-25 03:02 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/188#issuecomment-7151524901) · edited 2026-11-25 04:17 UTC Lewandox, I used [PortBridge](https://github.com/akimfomin/PortBridge) to try a follow-up on your exact `22c1cf9` GFX10 copy path. The candidate reuses the X side of the address equation across rows and the Y side across columns. I compared detiling and the entire tiled backing against your `element_offset` on 104 generated layouts, including higher pipe bits, arrays and mip tails. All eight upstream GFX10 tests and our three targeted tests passed in both arms. On an i5-13600KF, four alternating warm CPU pairs for synthetic 1920×1080 RGBA8 XOR copies went from 35.62 → 2.51 ms for tiling and 36.34 → 3.71 ms for detiling. At 3840×2160 BC7 they went from 8.85 → 1.54 ms and 10.15 → 1.70 ms. A direct path kept the smallest mip copies near the old cost. All timed output hashes matched. [Patch, standalone fixture and raw pairs](https://github.com/akimfomin/PortBridge/blob/4549dd07aa98a33246f90a438979e03dcfe5c4b6/research/rendering-night/anyxboxx-gfx10-copy/GFX10-COPY.md). These measure the generated texture copy on CPU, with the same input and output. No GPU or game-load effect was measured. Separate BC7 export follow-up, source checked against main `b92a71b9` and apply-checked on your `22c1cf97` head. The block decoder no longer allocates a vector for anchors, selects the weight tables once per block and copies visible rows into the image. The CPU output matched on 4,560 generated blocks and 400 image shapes. A 512-block image went from 513 allocations to 1. Four alternating warm CPU pairs measured 91.14 → 51.86 ms for 3840×2160 and 22.18 → 12.17 ms for cropped 1919×1079. This is a separate patch for BC7-to-RGBA conversion. [Patch, oracle and raw samples](https://github.com/akimfomin/PortBridge/blob/ec0bb3f53f2373567ac6d7027b87e11dd857ec48/research/rendering-night/anyxboxx-bc7-decode/BC7-DECODE.md). AI-assisted PortBridge engineering (OpenAI Codex). The same patch was also checked against the actual synthetic BC7-to-PNG CLI path, with a new process for each arm. Full 3840×2160 export was 273.925 → 226.422 ms and 1919×1079 was 72.327 → 60.443 ms. All 16 files matched exactly within their shape and passed an independent PNG/CRC check. The OS page cache was not flushed. [CLI runner and all samples](https://github.com/akimfomin/PortBridge/blob/36163aad4dcc320eb46910fc923e8492d127ac94/research/rendering-night/anyxboxx-bc7-cli/BC7-EXPORT-REVIEW.md).
Author
Owner

@⁠akimfomin on GitHub · 2026-11-25 08:16 UTC · original

Lewandox, I used PortBridge to check the earlier GFX10 copy change with the full locked texture crate on your unchanged 22c1cf9 head. All 13 original tests passed, as did all 16 with the GFX10 patch alone and all 17 with both patches applied. The GFX10 copy patch is now available by itself, with its exact address checks. The BC7 work also applies independently to current upstream main d02eee0 and passed all six texture tests there. If you'd like to take the copy change into #188, the first patch is ready to apply. Patches and verification

**@⁠akimfomin** on GitHub · 2026-11-25 08:16 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/188#issuecomment-7156830792) Lewandox, I used [PortBridge](https://github.com/akimfomin/PortBridge) to check the earlier GFX10 copy change with the full locked texture crate on your unchanged `22c1cf9` head. All 13 original tests passed, as did all 16 with the GFX10 patch alone and all 17 with both patches applied. The GFX10 copy patch is now available by itself, with its exact address checks. The BC7 work also applies independently to current upstream main `d02eee0` and passed all six texture tests there. If you'd like to take the copy change into #188, the first patch is ready to apply. [Patches and verification](https://github.com/akimfomin/PortBridge/tree/574821e4dcb32e63a06f76d6e8260b3035abd74b/research/anyxboxx-188-textures)
Author
Owner

@⁠akimfomin on GitHub · 2026-11-25 09:22 UTC · original · edited 2026-11-25 09:32 UTC

PortBridge found a separate address oracle for the GFX10 copy follow-up in Xbox2Windows #1469. On the unchanged #188 head 22c1cf9 and the GFX10-only candidate f2329f13, all 105 published Mesa 25.1.0/navi21 coordinates across 12 synthetic layouts matched both the expected offsets and the bytes copied in both directions, including selected BC7 mip-tail locations. This check used CPU fixtures and did not cover GPU execution or array layouts. Reproduction and exact results. It can be rerun with the GFX10-only patch on any later #188 head; no BC7 decoder change is needed.

Independent Ubuntu confirmation: Yoshi-233 tested the same pinned GFX10-only patch and 22c1cf9 base on Ubuntu 24.04.5 x86-64 with Rust/Cargo 1.98.1. The locked suite passed 16/16, including all three added GFX10 copy tests, with no failures or skips.

**@⁠akimfomin** on GitHub · 2026-11-25 09:22 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/188#issuecomment-7158233271) · edited 2026-11-25 09:32 UTC PortBridge found a separate address oracle for the GFX10 copy follow-up in Xbox2Windows #1469. On the unchanged #188 head `22c1cf9` and the GFX10-only candidate `f2329f13`, all 105 published Mesa 25.1.0/navi21 coordinates across 12 synthetic layouts matched both the expected offsets and the bytes copied in both directions, including selected BC7 mip-tail locations. This check used CPU fixtures and did not cover GPU execution or array layouts. [Reproduction and exact results](https://github.com/akimfomin/PortBridge/blob/8a0decf3d505384e9376d47df33fff4d9c662811/research/anyxboxx-188-textures/GFX10-INDEPENDENT.md). It can be rerun with the GFX10-only patch on any later #188 head; no BC7 decoder change is needed. Independent Ubuntu confirmation: [Yoshi-233 tested the same pinned GFX10-only patch and `22c1cf9` base](https://github.com/akimfomin/PortBridge/issues/61#issuecomment-7158341421) on Ubuntu 24.04.5 x86-64 with Rust/Cargo 1.98.1. The locked suite passed 16/16, including all three added GFX10 copy tests, with no failures or skips.
Author
Owner

@⁠Lewandox on GitHub · 2026-11-25 11:22 UTC · original

Thanks @⁠Yoshi-233 and @⁠akimfomin for the independent Ubuntu/Rust and Mesa 25.1.0 / Navi21 coordinate verifications!

Rebased onto latest main (d02eee0, synced all 9 READMEs to 667 tests) and added the separable X/Y/Z precomputation optimization to detile_subresource / tile_subresource:

  • Equation exposes eval_x, eval_y, and eval_z (eval_byte_offset(x, y, z) == eval_x(x) ^ eval_y(y) ^ eval_z(z)).
  • copy_tiled_subresource computes the slice Z term once per subresource, precomputes (x_blk, eval_x) once per column (keeping a zero-allocation direct path for small mips <= 64 elements), and computes (y_blk, eval_y ^ z_xor) once per row; SwizzleMode::Linear uses per-row slice copies.
  • Added fast_copy_matches_element_offset_across_linear_and_tiled_modes verifying byte-for-byte identity against element_offset across Linear, 4 KiB, 64 KiB, _T, _X, R_X, and Z_X modes with mip tails, texture arrays, and non-zero pipe_bank_xor (14/14 Rust tests + ruff + pytest passing).
**@⁠Lewandox** on GitHub · 2026-11-25 11:22 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/188#issuecomment-7160953584) Thanks @⁠Yoshi-233 and @⁠akimfomin for the independent Ubuntu/Rust and Mesa 25.1.0 / Navi21 coordinate verifications! Rebased onto latest `main` (`d02eee0`, synced all 9 READMEs to 667 tests) and added the separable X/Y/Z precomputation optimization to `detile_subresource` / `tile_subresource`: - `Equation` exposes `eval_x`, `eval_y`, and `eval_z` (`eval_byte_offset(x, y, z) == eval_x(x) ^ eval_y(y) ^ eval_z(z)`). - `copy_tiled_subresource` computes the slice Z term once per subresource, precomputes `(x_blk, eval_x)` once per column (keeping a zero-allocation direct path for small mips `<= 64` elements), and computes `(y_blk, eval_y ^ z_xor)` once per row; `SwizzleMode::Linear` uses per-row slice copies. - Added `fast_copy_matches_element_offset_across_linear_and_tiled_modes` verifying byte-for-byte identity against `element_offset` across `Linear`, 4 KiB, 64 KiB, `_T`, `_X`, `R_X`, and `Z_X` modes with mip tails, texture arrays, and non-zero `pipe_bank_xor` (14/14 Rust tests + `ruff` + `pytest` passing).
Author
Owner

@⁠akimfomin on GitHub · 2026-11-25 13:58 UTC · original

Lewandox, I independently reran the texture crate on your exact integrated head c5ca937c371d8b21e56feb36f3d009ecffe5765a with PortBridge. On Windows 11 with Rust 1.100.0 (gnullvm), cargo test --locked --manifest-path rust/Cargo.toml -p anyxboxx-texture returned 15 passed, 0 failed and 0 ignored. That includes all nine GFX10 tests and the new fast_copy_matches_element_offset_across_linear_and_tiled_modes check. The other six tests cover BC7. This was a CPU test run. AI use: OpenAI Codex prepared the clean checkout, ran the test and drafted this report.

**@⁠akimfomin** on GitHub · 2026-11-25 13:58 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/188#issuecomment-7164567766) Lewandox, I independently reran the texture crate on your exact integrated head `c5ca937c371d8b21e56feb36f3d009ecffe5765a` with [PortBridge](https://github.com/akimfomin/PortBridge). On Windows 11 with Rust 1.100.0 (gnullvm), `cargo test --locked --manifest-path rust/Cargo.toml -p anyxboxx-texture` returned 15 passed, 0 failed and 0 ignored. That includes all nine GFX10 tests and the new `fast_copy_matches_element_offset_across_linear_and_tiled_modes` check. The other six tests cover BC7. This was a CPU test run. AI use: OpenAI Codex prepared the clean checkout, ran the test and drafted this report.
Author
Owner

@⁠LooperSalty on GitHub · 2026-11-25 15:00 UTC · original

Closed by the maintainer during PR triage: since #199, VIctory lives in this repository and is what runs the game. It already has its own XMA decoder (third_party/victory/crates/victory-formats/src/xma.rs) and GFX10 texture tiling (victory-formats/src/texture.rs), while rust/anyxboxx-* is only used by a test. Improvements in this area should go to VIctory's crates instead. Thanks for the work.

**@⁠LooperSalty** on GitHub · 2026-11-25 15:00 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/188#issuecomment-7166158013) Closed by the maintainer during PR triage: since #199, VIctory lives in this repository and is what runs the game. It already has its own XMA decoder (`third_party/victory/crates/victory-formats/src/xma.rs`) and GFX10 texture tiling (`victory-formats/src/texture.rs`), while `rust/anyxboxx-*` is only used by a test. Improvements in this area should go to VIctory's crates instead. Thanks for the work.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.