Skip to content

d3d12_xs: GetResourceAllocationInfo answers streamed textures with their console size (RT-ALLOC-INFO-CONSOLE) - #971

Closed
DadaCap wants to merge 4 commits into
ProjectLeonida:mainfrom
DadaCap:alloc-info-console
Closed

DadaCap wants to merge 4 commits into
ProjectLeonida:mainfrom
DadaCap:alloc-info-console

Conversation

@DadaCap

@DadaCap DadaCap commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Depends on: #461

Claim: RT-ALLOC-INFO-CONSOLE (#14 (comment)). Only the last commit is this pull request; the rest is #461.

The retail title sizes its streamed textures with device slot 25, GetResourceAllocationInfo, with layout 0, and computes offsets and lengths inside its texture archives from the answers. The runtime forwarded the call, so it answered with the PC GPU's sizes and the title asked DirectStorage for a part of a compressed chunk. It asserts on that: the int3 at game_scarlett_master.exe+0x4ffd879 (1.0.2.1) right after the start screen, also seen on an RTX 5070 (#14, DesertGamer).

Two of the textures it asserted on: 128x4 R16G16B16A16_UNORM, answered 2 pages of 4 KiB where the archive's chunk is 4; 128x128 BC1 with 6 mips, answered 4 where the chunk is 3. #461's layout gives 4 and 3 in the 4 KiB mode XGSuggestSwizzleMode picks for both.

Slot 25 now answers from #461's layout when every description is a texture with a swizzle mode (0x100 | mode) or layout 0, and not a render or depth target. Anything else keeps the PC answer for the whole list. It goes through a pointer, so the proxy does not link the xg_xs shim.

Not covered: slot 108 (GetResourceAllocationInfo2, #219), which needs the same two lines once it lands; arrays, 3D and targets are not measured on the title.

Tested

  • xs_proxy_mock_test: exit 0 (new: one and two textures, the alignment between them, and five lists that keep the PC answer). xg_xs_test: 0 failures (new: the sizes above). Windows 11, MSVC.
  • Retail package, in my prototype stack (not on this branch alone; RTX 5080, driver 621.24, Windows 11): with the rule for slots 25 and 108 the assert is gone and in a 240 s run no DirectStorage request failed; without it 24 and more did.
  • No game data.

AI-assisted (Claude Code, Opus 5.5).

🤖 Generated with Claude Code

oscarlosu-lab and others added 3 commits November 24, 2026 06:32
…-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>
…eir console size (RT-ALLOC-INFO-CONSOLE)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tiguan26

Copy link
Copy Markdown
Contributor

Checked 9f89522 merged into current main (4a50caf): it merges cleanly. Cross-built with clang-cl 19 + xwin (MSVC CRT / SDK 10.0.26100) and run under Wine 11.22 on llvmpipe. No game files, so this checks the shim and the tests, not the retail assert.

  • xs_proxy_mock and xg_xs pass, with the new cases: one and two textures and the alignment between them, the five lists that keep the PC answer, and the two measured sizes.
  • console_texture_sizes() reads right to me. Each texture is placed at its own alignment and the total is rounded to the largest, as D3D12 lays out a multi-description query. One buffer, render or depth target, or layout outside 0/0x100 | mode anywhere in the list keeps the PC answer for the whole list.
  • Wiring: xg_xs.cpp and d3d12_xs_device.cpp are both direct sources of gta6rt, not a static library, so g_texture_size_set can't be dropped and the hook is set in the real process. The mock test sets rt::xg::texture_size_fn itself, though, so nothing checks that the initializer runs. A one-line rt::xg::texture_size_fn != nullptr in xg_xs_test (which links xg_xs.cpp) would cover it.

One question, not a blocker: the console answer brings the console's alignment (4 KiB for the mode XGSuggestSwizzleMode picks here), while the Vulkan device's CreatePlacedResource refuses a texture whose heap offset is not a multiple of its own PC alignment (heap_offset % alloc.Alignment, 64 KiB for most textures that are not small resources). If the title places these streamed textures through the PC-style CreatePlacedResource at offsets computed from the console answer, larger textures would be refused there. If it places them through CreatePlacedResourceX (slot 133, by VA), as the archive offsets suggest, this doesn't come up. Your 240 s run with no failed DirectStorage requests suggests the latter.

AI-assisted (Claude).

@DadaCap

DadaCap commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

@tiguan26 thank you for the check, and for cross-building it.

  • The initializer: xg_xs_test already has that line, check(rt::xg::texture_size_fn != nullptr, "the shim offers its sizes"); (runtime/test/xg_xs_test.cpp:279 on this head), before the four size cases that call through the pointer. It links xg_xs.cpp, so it fails if g_texture_size_set does not run.
  • Your question: on the retail title the streamed textures do not come through the PC-style CreatePlacedResource. In my runs they are described by address: slot 133 (CreatePlacedResourceX, by VA) and, far more often, the raw views of device slots 70/71 (a resource description plus a GPU address, no resource object), about 58,000 texture descriptions in a 240 s run that reaches the world phase, with no failed DirectStorage request. So the console alignment never meets the heap_offset % alloc.Alignment check there. Not checked: whether the PC slot is ever called for a texture at all; I only know it is not what the streaming uses.

Measured on Windows 11, RTX 5080 (NVIDIA 621.24), with a local stack on top of main; counts only, no game data. AI-assisted (Claude Code).

@tiguan26

Copy link
Copy Markdown
Contributor

@DadaCap you're right, line 279 already checks it and I missed it (I only read the mock test's diff). Thanks also for the slot 70/71 and 133 counts: that settles the alignment question for the streaming path.

@tiguan26 tiguan26 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.

Approving 9f89522 (the RT-ALLOC-INFO-CONSOLE commit; #461 underneath as the PR says). My checks are in the comment above: merged cleanly into main 4a50caf, cross-built with clang-cl 19 + xwin, xs_proxy_mock and xg_xs pass under Wine 11.22, and the multi-description layout reads right. My two points are answered: the initializer is checked at xg_xs_test.cpp:279, and the streamed textures go through slots 70/71/133 by address, not the PC-style CreatePlacedResource, so the console alignment never meets that check.

AI-assisted (Claude).

@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 24, 2026
…e-form calls, as main's render-target sizes

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@DadaCap

DadaCap commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Merged current main (698b650ed and later, with #375) into the branch; no force-push.

One conflict, in proxy_get_resource_allocation_info: main now cleans the descriptions in a copy and gives the console sizes of render targets to console-form calls only. The streamed-texture sizes of this PR follow the same rule: console_texture_sizes is asked first, for a call in the console form (the return buffer first), and a PC-form caller keeps the PC device's answer. The retail title calls slot 25 in the console form, so its sizes are unchanged.

xs_proxy_mock_test changed with it: the texture cases call slot 25 in the console form, a PC-form call of the same description is checked to get the mock device's answer, and the "anything else" cases check that the PC device is asked (main's mock answers a size computed from the description now, and adds its console render-target sizes after, so the old marker value is gone).

On the merged head, Windows 11, VS 18 RelWithDebInfo: xs_proxy_mock_test PASS, xg_xs_test 111 checks, 0 failures. Not run: the whole ctest set, GPU tests (this change has none).

AI-assisted (Claude Code).

@github-actions github-actions Bot removed the needs rebase Conflicts with the base branch: rebase it on main label Nov 25, 2026
@DadaCap

DadaCap commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Closing this one as well: main has the rule since #984, on its own texture layout code.

  • runtime/shims/d3d12_xs_alloc_size.h on main has console_texture_layout(): a texture nothing renders or stores to gets XG's size and alignment (xg_xs_layout.h), and slots 25 and 56 use it through console_placement. Its comment gives the same reason this pull request was written for (the title reads exactly that many bytes through DirectStorage and stops at game+0x4ffd879 when the size is the PC's).
  • This branch brings a second layout model (console_texture_layout.h, 610 lines) and a second xg_xs.cpp for the same answer, and conflicts with main's in 4 files. Nothing in it is missing on main.

@tiguan26 thank you for the review; the points you raised went into the branch before this. AI-assisted (Claude Code).

@DadaCap DadaCap closed this Nov 25, 2026
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.

3 participants