Skip to content

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

Merged
aslan2142 merged 1 commit into
ProjectLeonida:mainfrom
oscarlosu-lab:pr/xg-texture-computer
Nov 25, 2026
Merged

aslan2142 merged 1 commit into
ProjectLeonida:mainfrom
oscarlosu-lab:pr/xg-texture-computer

Conversation

@oscarlosu-lab

@oscarlosu-lab oscarlosu-lab commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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.

…-TEXTURE-COMPUTER)

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 <noreply@anthropic.com>
demoz53 added a commit to demoz53/leonida that referenced this pull request Nov 24, 2026
…y out console textures and serve the texture computer (RT-XG-TEXTURE-COMPUTER) [oscarlosu-lab]
@VibeClauding

Copy link
Copy Markdown
Contributor

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.

LloydNicholson added a commit to LloydNicholson/leonida-cont that referenced this pull request Nov 24, 2026
… lazy PSOs, console formats, XG, title memory)

Measured on the retail boot under Wine 11.22 (RX 9060 XT, RADV): it now creates 10,000+ slot 57 pipelines, runs
its loading frame loop at ~2.5-4 GB, and, with the hang check held off (LEONIDA_SLOW_STARTUP=1), starts real
rendering at ~120 s. Frames are still black, and that run stops at game+0x13360a3 (a game object with a garbage
vtable; not caused by anything below that was tested).

From open pull requests (applied as patches, conflicts resolved here):
- ProjectLeonida#511 (VibeClauding): LEONIDA_LAZY_PSO=1, pipelines built at first draw/dispatch. Local fix on top: the rect-list
  path's VS words were cleared before rect_list_geometry read them, refusing every rectangle-list PSO; the compute
  compile keeps this branch's host-stall scope.
- ProjectLeonida#496 (Rüzgar Koray Genç): console pipeline-stream numbering (24 = mesh shader).
- ProjectLeonida#461 (oscarlosu-lab): xg_xs texture layout and computer (ported from Marvisak/VIctory, GPL-3.0).
- Draft ProjectLeonida#321 (Mumogg, 237f9e0): vertex/index views in title CPU memory copied into a ring (title_memory).

Local fixes:
- Slot 57 pipeline blob elements: +0x00 is SemanticIndex, +0x08 InputSlot (swapped before; docs/fspx.md and the
  device_proxy test updated). ~4,900 "input layout does not feed COLOR1" refusals were this.
- FSPX graphics stages that read their code base use the kind-6 program as code (was empty -> E_OUTOFMEMORY).
- Console formats 118/119/120 (hypothesis: D16_UNORM_S8_UINT family) aliased to the D24S8 family at the device's
  entry points.
- Depth-stencil + UAV stand-in extended to slots 108, 127 and the slot-133 texture fallback; a UAV initial state on
  such a texture starts in COMMON. Slot 108 logs refusals (the title asserts its answer is below 4 GiB).
- 8-bit RGBA/BGRA render targets accept a UNORM/sRGB view without a castable list.
- Fence slot 12 mirrors refreshed by one poller thread (LEONIDA_FENCE_MIRROR=tp keeps the thread-pool waits, which
  queued on Wine's wait-queue lock); xs_proxy_mock tests run in tp mode.
- Slot-133 shadow buffers keep their VirtualQuery layout between refreshes (178 MB: 70 ms -> ~8.5 ms) and the
  refresh counts as a host stall.

Diagnostics and experiments (off unless noted):
- LEONIDA_DRAW_DIAG=1: per-present draw counts and per-draw pipeline/target/depth/viewport/vb0 for early frames.
- Slot 57 refusal layout dump and created/failed totals; refused RTV and committed-resource details; failed
  ExecuteCommandLists names its vulkan_replay.h line (on by default, test-branch lines).
- LEONIDA_SLOW_STARTUP=1: guest Sleep of 1-2.1 s lasts 2.1 s, so the startup hang check never counts (hides hangs).
- LEONIDA_XG_NO_COPY=1: texture computer slots 8/9 copy nothing.

Co-authored-by: VibeClauding <360230414+VibeClauding@users.noreply.github.com>
Co-authored-by: Rüzgar Koray Genç <koray_genc1@hotmail.com>
Co-authored-by: oscarlosu-lab <251827664+oscarlosu-lab@users.noreply.github.com>
Co-authored-by: Mumogg <104529023+Mumogg@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DesertGamer

Copy link
Copy Markdown
Contributor

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 21625bc + #641 + #427 + #727 (the rebased #219) + #602 + #387 + #357 + #432, which reaches the frame loop (400,154 PresentX ok in 200 s, #641 (comment)). 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 SweatierKey left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

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

x2Tweek commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Windows result for this PR on the frame-loop stack of #321 (head e0d4fd2 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 (de191a9), 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.

@aslan2142
aslan2142 merged commit 65b8569 into ProjectLeonida:main Nov 25, 2026
1 check passed
aslan2142 pushed a commit that referenced this pull request Nov 25, 2026
…first-run UI

Build on the public frame-loop integration in #321. Carry the texture-view and depth work from #213 and #261, the layout provider from #461, the responsive window from #526, and the rectangle generator from #682. Integrate the Xbox constant-buffer row addressing measured in #513 and the draw-time rectangle selection in #722. Keep all fixtures synthetic.

The Windows GPU path resolves title-owned shader objects, retires geometry uploads per submission, materializes texture views on use, maps linear surfaces, and delivers completed GPU label writes. A first-run UI launch selects the tested settings for these paths.
@oscarlosu-lab
oscarlosu-lab deleted the pr/xg-texture-computer branch November 26, 2026 14:50
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.

6 participants