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

Merged
oscarlosu-lab merged 1 commit from upstream-pr/461 into main 2026-11-25 02:33:48 +00:00
oscarlosu-lab commented 2026-11-24 05:42:57 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by oscarlosu-lab on 2026-11-24T05:42:57Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5466805235 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/461). Originally posted by [oscarlosu-lab](https://github.com/oscarlosu-lab) on 2026-11-24T05:42:57Z. --- 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.
VibeClauding commented 2026-11-24 08:45:06 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by VibeClauding on 2026-11-24T08:45:06Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7126517130 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/461#issuecomment-7126517130). Originally posted by [VibeClauding](https://github.com/VibeClauding) on 2026-11-24T08:45:06Z. --- 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.
DesertGamer commented 2026-11-24 13:56:00 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DesertGamer on 2026-11-24T13:56:00Z.


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://github.com/ubiquitarianism/leonida/pull/641#issuecomment-7132879890). 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)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7133557543 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/461#issuecomment-7133557543). Originally posted by [DesertGamer](https://github.com/DesertGamer) on 2026-11-24T13:56:00Z. --- 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://github.com/ubiquitarianism/leonida/pull/641#issuecomment-7132879890). 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)
SweatierKey commented 2026-11-24 16:00:20 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by SweatierKey on 2026-11-24T16:00:20Z.

Review: APPROVED


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

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6042795202 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/461#pullrequestreview-6042795202). Originally posted by [SweatierKey](https://github.com/SweatierKey) on 2026-11-24T16:00:20Z. **Review:** APPROVED --- 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
oscarlosu-lab commented 2026-11-24 18:16:18 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by oscarlosu-lab on 2026-11-24T18:16:18Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7140405317 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/461#issuecomment-7140405317). Originally posted by [oscarlosu-lab](https://github.com/oscarlosu-lab) on 2026-11-24T18:16:18Z. --- 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.
x2Tweek commented 2026-11-24 22:50:51 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by x2Tweek on 2026-11-24T22:50:51Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7146713859 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/461#issuecomment-7146713859). Originally posted by [x2Tweek](https://github.com/x2Tweek) on 2026-11-24T22:50:51Z. --- 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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!461
No description provided.