xg_xs: lay out console textures and serve the texture computer (RT-XG-TEXTURE-COMPUTER) #461

Manually merged
github merged 1 commit from gh-pr/461/head into gh-pr/461/base 2026-11-26 09:01:43 +00:00
Owner

@⁠oscarlosu-lab on GitHub · 2026-11-24 05:42 UTC · original
oscarlosu-lab:pr/xg-texture-computer → main · +1418 −93 · 4 files · 1 commits · merged 2026-11-25 02:33 UTC

Claimed in the coordination issue as: RT-XG-TEXTURE-COMPUTER

Summary

Implements the console texture layout model and XGCreateTextureComputer / XGSuggestSwizzleMode in runtime/shims/xg_xs.cpp on top of a GFX10 texture layout model (runtime/src/console_texture_layout.h), replacing the previous E_NOTIMPL stubs:

  • Implements texture computer slots 0 (AddRef), 1 (Release), 2 (layout structure), 6 (element offsets), 8 (copy into subresource), 9 (copy from subresource), and 10 (64 KiB tiling), while unsupported slots log once and return E_NOTIMPL.
  • Descriptions the model cannot lay out still hand out a stub computer in *out alongside E_INVALIDARG (preserving compatibility with measured callers that ignore the HRESULT).
  • Not modelled: compression metadata planes and XOR/MSAA addressing modes (return E_NOTIMPL).

Attribution

  • Layout rules, computer vtable layout, and layout structure ported from Marvisak/VIctory (GPL-3.0), crates/victory-formats/src/texture.rs and crates/victory-hle/src/modules/xg.rs at d2a4bae1f, credited in the file headers; AMD addrlib MIT notice preserved.

Verification

  • Built full runtime (cmake -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo --target gta6rt xg_xs_test) on Windows 11, MSVC 19.52 x64 (VS 2026): 0 warnings in the touched files.
  • xg_xs_test.exe: 106 checks, 0 failures (hand-checked addresses, mip tails, two-plane depth-stencil, bijection/round-trip across 10 layouts, and shim slot routing).
  • ctest -R xg_xs: 1/1 Test #50: xg_xs ... Passed (0.19 sec).
  • python -I scripts/check_no_game_data.py & python -I tests/test_docs_links.py: PASS (16/16 OK).

AI-assisted. No game files.

**@⁠oscarlosu-lab** on GitHub · 2026-11-24 05:42 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/461) `oscarlosu-lab:pr/xg-texture-computer` → `main` · +1418 −93 · 4 files · 1 commits · merged 2026-11-25 02:33 UTC Claimed in the coordination issue as: RT-XG-TEXTURE-COMPUTER ### Summary Implements the console texture layout model and `XGCreateTextureComputer` / `XGSuggestSwizzleMode` in `runtime/shims/xg_xs.cpp` on top of a GFX10 texture layout model (`runtime/src/console_texture_layout.h`), replacing the previous `E_NOTIMPL` stubs: - Implements texture computer slots `0` (`AddRef`), `1` (`Release`), `2` (layout structure), `6` (element offsets), `8` (copy into subresource), `9` (copy from subresource), and `10` (64 KiB tiling), while unsupported slots log once and return `E_NOTIMPL`. - Descriptions the model cannot lay out still hand out a stub computer in `*out` alongside `E_INVALIDARG` (preserving compatibility with measured callers that ignore the `HRESULT`). - Not modelled: compression metadata planes and XOR/MSAA addressing modes (return `E_NOTIMPL`). ### Attribution - Layout rules, computer vtable layout, and layout structure ported from `Marvisak/VIctory` (GPL-3.0), `crates/victory-formats/src/texture.rs` and `crates/victory-hle/src/modules/xg.rs` at `d2a4bae1f`, credited in the file headers; AMD `addrlib` MIT notice preserved. ### Verification - Built full runtime (`cmake -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo --target gta6rt xg_xs_test`) on Windows 11, MSVC 19.52 x64 (VS 2026): 0 warnings in the touched files. - `xg_xs_test.exe`: `106 checks, 0 failures` (hand-checked addresses, mip tails, two-plane depth-stencil, bijection/round-trip across 10 layouts, and shim slot routing). - `ctest -R xg_xs`: `1/1 Test #50: xg_xs ... Passed (0.19 sec)`. - `python -I scripts/check_no_game_data.py` & `python -I tests/test_docs_links.py`: PASS (`16/16 OK`). AI-assisted. No game files.
XGSuggestSwizzleMode and every texture-computer slot returned E_NOTIMPL, so the
title's texture layout and copy calls did nothing. They now run on a model of
the GFX10 texture layouts (runtime/src/console_texture_layout.h, AMD addrlib's
rules for the linear, 256 B, 4 KiB and 64 KiB modes): the suggested mode, the
layout structure (slot 2), element offsets (slot 6), copies into and out of a
subresource (slots 8 and 9) and the 64 KiB tiling (slot 10).

A description the model cannot lay out still gets a computer in *out (with
E_INVALIDARG), as before, because two measured callers use *out without
checking the HRESULT. Not modelled: compression metadata planes and the XOR
and MSAA modes' addressing (E_NOTIMPL).

The layout model, the computer's method table and the layout structure are
ported from Marvisak/VIctory (GPL-3.0), crates/victory-formats/src/texture.rs
and crates/victory-hle/src/modules/xg.rs at d2a4bae1f, credited in the files;
the addrlib notice is kept. xg_xs_test now checks the model (hand-checked
addresses, mip tails, a two-plane depth-stencil, a bijection and round trip
over every element of ten layouts) and the shim's slots: 106 checks, MSVC /W4.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:01:41 +00:00
github manually merged commit 77f44fbe3b into gh-pr/461/base 2026-11-26 09:01:43 +00:00
Author
Owner

@⁠VibeClauding on GitHub · 2026-11-24 08:45 UTC · original

Cross-check of this PR's layout model against an independently written one, with no game files: runtime/src/console_texture_layout.h here against src/gfx10_layout.h from Impre-visible/Leonida 116979c49f (Librett0's model, built from the measured docs/textures.md rule rather than ported from VIctory).

3,038 2D cases: modes linear, 256B_S/D, 4KB_S/D, 64KB_S/D; element sizes 1-16 bytes and 4x4 blocks of 8 and 16 bytes; 11 extents from 1x1 to 1920x1080 including odd ones (100x37, 3x1024, 1000x600); 1 and 3 slices; 1, 3 and full mip chains. Compared: total size, slice size, and the byte offset of every element of every mip and slice (every 7th row and column above 512).

  • Size and slice size: identical in all 3,038.
  • Element offsets in the tiled modes: identical wherever both models give a mip the same extent, mip tails included.
  • Two differences, and in both this PR matches AMD's addrlib, not the other model:
    1. Linear mip order. This PR stores linear mips smallest first; the other model stores them largest first. Mesa's gfx10addrlib.cpp Gfx10Lib::HwlComputeSurfaceInfoLinear walks for (i = numMipLevels - 1; i >= 0; i--) and accumulates sliceSize, so mip 0 is last: this PR is right.
    2. Odd extents. This PR's dim() halves texels rounding down (the D3D12 subresource size the title's linear rows have) and keeps addrlib's rounded-up padded_dim() for placement only; the other model uses the rounded-up extent for the data too (100x37 mip 1: 50x18 here, 50x19 there), which would make its copies read and write one row or column more than the title's rows. This PR's split is the safer one.

Also consistent with this PR: xcl's issue 662 (RX 9070 XT, retail title) measured that the title calls slot 9 with one argument more than VIctory's original xg.rs assumed, a zero/sample word before the tiled pointer, then row pitch and slice pitch (low 32 bits). copy_from here already takes (linear, plane, subresource, sample, tiled, row, depth), which is that order.

The harness is a 150-line standalone C++20 program including both headers, compiled with MSVC 19.44. I can attach it if useful. AI-assisted.

**@⁠VibeClauding** on GitHub · 2026-11-24 08:45 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/461#issuecomment-7126517130) Cross-check of this PR's layout model against an independently written one, with no game files: `runtime/src/console_texture_layout.h` here against `src/gfx10_layout.h` from Impre-visible/Leonida `116979c49f` (Librett0's model, built from the measured `docs/textures.md` rule rather than ported from VIctory). 3,038 2D cases: modes linear, 256B_S/D, 4KB_S/D, 64KB_S/D; element sizes 1-16 bytes and 4x4 blocks of 8 and 16 bytes; 11 extents from 1x1 to 1920x1080 including odd ones (100x37, 3x1024, 1000x600); 1 and 3 slices; 1, 3 and full mip chains. Compared: total size, slice size, and the byte offset of every element of every mip and slice (every 7th row and column above 512). - **Size and slice size: identical in all 3,038.** - **Element offsets in the tiled modes: identical** wherever both models give a mip the same extent, mip tails included. - **Two differences, and in both this PR matches AMD's addrlib**, not the other model: 1. *Linear mip order.* This PR stores linear mips smallest first; the other model stores them largest first. Mesa's `gfx10addrlib.cpp` `Gfx10Lib::HwlComputeSurfaceInfoLinear` walks `for (i = numMipLevels - 1; i >= 0; i--)` and accumulates `sliceSize`, so mip 0 is last: this PR is right. 2. *Odd extents.* This PR's `dim()` halves texels rounding down (the D3D12 subresource size the title's linear rows have) and keeps addrlib's rounded-up `padded_dim()` for placement only; the other model uses the rounded-up extent for the data too (100x37 mip 1: 50x18 here, 50x19 there), which would make its copies read and write one row or column more than the title's rows. This PR's split is the safer one. Also consistent with this PR: xcl's issue 662 (RX 9070 XT, retail title) measured that the title calls slot 9 with one argument more than VIctory's original `xg.rs` assumed, a zero/sample word before the tiled pointer, then row pitch and slice pitch (low 32 bits). `copy_from` here already takes `(linear, plane, subresource, sample, tiled, row, depth)`, which is that order. The harness is a 150-line standalone C++20 program including both headers, compiled with MSVC 19.44. I can attach it if useful. AI-assisted.
Author
Owner

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

Retail check of the texture computer on a second native-Windows machine, which also shows that the title really calls it. Windows 11, RTX 5070, driver 617.14, LEONIDA_D3D12=vulkan, own 1.0.2.1 copy.

Stack without this pull request: main 21625bca8 + #641 + #427 + #727 (the rebased #219) + #602 + #387 + #357 + #432, which reaches the frame loop (400,154 PresentX ok in 200 s, #641). On that stack the title calls, before the loop, XGSuggestSwizzleMode, XGCreateTextureComputer and texture computer slots 8 and 10, and the shim answers each with the no console texture layout on the PC; E_NOTIMPL line (four lines, one per call site).

The same stack with this pull request merged on top (clean merge): 464,933 PresentX ok and 16,802,252 D3D12 calls in 200 s, no exception, and in a second 45 s run with stderr kept there is not one no console texture layout line and no xg_xs line at all, so the title reached no slot the shim still refuses. The frame loop is reached as before; I make no claim about the frames, which are still black on this stack.

What I did not check: xg_xs_test (the unit target) on my side; whether the layouts the title asks for are right (nothing here compares a texture byte for byte); runs past 200 s.

AI-assisted: yes (Claude Code, Sonnet 5.5)

**@⁠DesertGamer** on GitHub · 2026-11-24 13:56 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/461#issuecomment-7133557543) Retail check of the texture computer on a second native-Windows machine, which also shows that the title really calls it. Windows 11, RTX 5070, driver 617.14, `LEONIDA_D3D12=vulkan`, own 1.0.2.1 copy. Stack without this pull request: `main` 21625bca8 + #641 + #427 + #727 (the rebased #219) + #602 + #387 + #357 + #432, which reaches the frame loop (400,154 `PresentX ok` in 200 s, https://git.gtahub.st/github/ubiquitarianism--leonida/pulls/641). On that stack the title calls, before the loop, `XGSuggestSwizzleMode`, `XGCreateTextureComputer` and texture computer slots 8 and 10, and the shim answers each with the `no console texture layout on the PC; E_NOTIMPL` line (four lines, one per call site). The same stack with this pull request merged on top (clean merge): 464,933 `PresentX ok` and 16,802,252 D3D12 calls in 200 s, no exception, and in a second 45 s run with stderr kept there is not one `no console texture layout` line and no `xg_xs` line at all, so the title reached no slot the shim still refuses. The frame loop is reached as before; I make no claim about the frames, which are still black on this stack. What I did not check: `xg_xs_test` (the unit target) on my side; whether the layouts the title asks for are right (nothing here compares a texture byte for byte); runs past 200 s. AI-assisted: yes (Claude Code, Sonnet 5.5)
Author
Owner

@⁠SweatierKey on GitHub · 2026-11-24 16:00 UTC · original · approved these changes

Independent verification on Windows 11 against origin/main@1504c1af6:

  • Cross-compiled xg_xs_test.exe (clang-cl + xwin SDK 10.0.26100) and ran natively on Windows 11:
    • 106 checks, 0 failures (rc=0), including layout/offset/copy/tiling checks and stub-computer compatibility for unmodelled descriptions.
  • python3 -I scripts/check_no_game_data.py: clean.

AI-assisted: yes

**@⁠SweatierKey** on GitHub · 2026-11-24 16:00 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/461#pullrequestreview-6042795202) · **approved these changes** Independent verification on Windows 11 against `origin/main@1504c1af6`: - Cross-compiled `xg_xs_test.exe` (`clang-cl` + xwin SDK 10.0.26100) and ran natively on Windows 11: - `106 checks, 0 failures` (`rc=0`), including layout/offset/copy/tiling checks and stub-computer compatibility for unmodelled descriptions. - `python3 -I scripts/check_no_game_data.py`: clean. AI-assisted: yes
Author
Owner

@⁠oscarlosu-lab on GitHub · 2026-11-24 18:16 UTC · original

Overlap note: #984 (RT-PROTON-STORY-LOAD, the integration branch that boots through the story load) carries its own runtime/shims/xg_xs.cpp with xg_xs_layout.h, also from AMD addrlib's GFX10 rules and cross-checked against Marvisak/VIctory's xg.rs. The two touch the same file and serve the same slots, so they will conflict.

I have no preference for which one stays. If #984 is carved into smaller PRs and its texture computer goes in, I'll close this one; if this one goes in first, its layout model and xg_xs_test (106 checks: hand-checked addresses, mip tails, depth-stencil planes, a bijection and round trip over ten layouts) are there for #984's to be compared against. On an RTX 3060 under #984 the texture computer path logged no errors through the story load.

**@⁠oscarlosu-lab** on GitHub · 2026-11-24 18:16 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/461#issuecomment-7140405317) Overlap note: #984 (RT-PROTON-STORY-LOAD, the integration branch that boots through the story load) carries its own `runtime/shims/xg_xs.cpp` with `xg_xs_layout.h`, also from AMD addrlib's GFX10 rules and cross-checked against Marvisak/VIctory's `xg.rs`. The two touch the same file and serve the same slots, so they will conflict. I have no preference for which one stays. If #984 is carved into smaller PRs and its texture computer goes in, I'll close this one; if this one goes in first, its layout model and `xg_xs_test` (106 checks: hand-checked addresses, mip tails, depth-stencil planes, a bijection and round trip over ten layouts) are there for #984's to be compared against. On an RTX 3060 under #984 the texture computer path logged no errors through the story load.
Author
Owner

@⁠x2Tweek on GitHub · 2026-11-24 22:50 UTC · original · edited 2026-11-24 23:00 UTC

Windows result for this PR on the frame-loop stack of #321 (head e0d4fd2b8 with three small local changes: the build_runtime.ps1 fix, #526's window commit and a compile-progress display; own 1.0.2.1 copy, MSVC, NVIDIA RTX 5090, driver 621.24, Windows 11, LEONIDA_D3D12=vulkan, 3-minute runs, counts only).

Baseline, #321 alone: every frame has two of its three command lists refused (ExecuteCommandLists failed: unknown resource, 136 refusals in 70 frames).

With this PR's commit (71e2cb90b) cherry-picked on that base, two runs gave 0 and 22 refusals, so on its own it does not remove them every time. With #489 added on top (de191a941), the run had 0 refusals, 68 ExecuteCommandLists ok and 0 failed, about 97 DrawInstanced calls and 34 presents.

The picture does not change: the seven frames dumped in that last run (LEONIDA_PRESENT_DUMP, every 5th frame) are entirely RGBA 0,0,0,0 (transparent black), as without this PR. So the refusals are removed or reduced, but the next blocker is elsewhere in what the title draws or presents.

AI-assisted.

**@⁠x2Tweek** on GitHub · 2026-11-24 22:50 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/461#issuecomment-7146713859) · edited 2026-11-24 23:00 UTC Windows result for this PR on the frame-loop stack of #321 (head e0d4fd2b8 with three small local changes: the `build_runtime.ps1` fix, #526's window commit and a compile-progress display; own 1.0.2.1 copy, MSVC, NVIDIA RTX 5090, driver 621.24, Windows 11, `LEONIDA_D3D12=vulkan`, 3-minute runs, counts only). Baseline, #321 alone: every frame has two of its three command lists refused (`ExecuteCommandLists failed: unknown resource`, 136 refusals in 70 frames). With this PR's commit (71e2cb90b) cherry-picked on that base, two runs gave 0 and 22 refusals, so on its own it does not remove them every time. With #489 added on top (de191a941), the run had 0 refusals, 68 `ExecuteCommandLists` ok and 0 failed, about 97 `DrawInstanced` calls and 34 presents. The picture does not change: the seven frames dumped in that last run (`LEONIDA_PRESENT_DUMP`, every 5th frame) are entirely RGBA 0,0,0,0 (transparent black), as without this PR. So the refusals are removed or reduced, but the next blocker is elsewhere in what the title draws or presents. AI-assisted.
This discussion has been locked. Commenting is limited to contributors.
No description provided.