Skip to content

d3d12_xs: device slot 25 cleans the Xbox layout word and flag bits on a copy before the PC GetResourceAllocationInfo (retail boot chain stop 16) - #7110

Open
tedin7 wants to merge 16 commits into
ItsNotRexed:mainfrom
tedin7:fast-desc-clean
Open

tedin7 wants to merge 16 commits into
ItsNotRexed:mainfrom
tedin7:fast-desc-clean

Conversation

@tedin7

@tedin7 tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Claimed in #7049 (comment)

@ItsNotRexed: an exe PR, as you asked.

Depends on #7078 (slot 25 render target sizes), which depends on #6973 (the C-ABI struct return of slots 25/26). This branch is stacked on #7078's head 889785539; until they merge the diff here also shows their commits. Only the last commit is this PR.

What

Why

Stop 16 of the retail boot chain (#6982, section 3.7): the title's slot 25 call carries console descriptions (the layout word 0x101, and bits above the PC Flags). The PC device cannot take them as they are.

Tested

Cross-built with clang-cl and run under Wine (pod, xs_proxy_mock_test, no GPU, no game files). New check: slot 25 called in the retail form with a texture (layout 0x101, RENDER_TARGET | UNORDERED_ACCESS plus two Xbox bits) and a buffer (layout 0x1, only Xbox bits):

AI-assisted: yes

sneylol and others added 6 commits November 23, 2026 16:32
The retail executable calls GetCustomHeapProperties (device slot 26) with the
C convention: the hidden return buffer in RCX and the device in RDX. The
proxy's generic forwarder assumed the PC C++ form (this in RCX, buffer in
RDX), took the buffer for the device and crashed on its vtable right after
D3D12XboxCreateDevice.

Slots 25 (GetResourceAllocationInfo, same rule, inferred) and 26 (measured)
now get thunks that accept either form: whichever of the first two arguments
is the device proxy is `this`. The runtime's own code still calls the proxy
through d3d12.h in the PC form. device_proxy_test calls both slots in both
forms against WARP.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The retail executable calls GetCustomHeapProperties with the return buffer in RCX and the device in RDX. The forwarder took RCX for the proxy and faulted.

AI-assisted.
…(RT-5 stop 17)

The retail title asserts when its first full-screen render targets leave more than 2 MiB of a fixed budget unused (docs/retail_boot_chain.md, ItsNotRexed#6982). The PC size is about width x height x element bytes; the console takes whole RDNA2 SW_64KB tiles. Slot 25 adds the difference per render target description and never lowers a size. Depends on ItsNotRexed#6973.
…ons (RT-5 stop 16)

The title's descriptions carry the Xbox layout word and flag bits above the PC ones. Slot 25 now passes a copy with PC flags and a PC layout; the title's array is not written. Depends on ItsNotRexed#7078.
@tikD1337

Copy link
Copy Markdown
Contributor

Review: PR #7110 — slot 25 cleans the Xbox layout word and flag bits before the PC GetResourceAllocationInfo (retail boot chain stop 16)

Environment: Windows 11, CPython 3.13; the runtime is built with MSVC and Ninja against Windows SDK 10.0.26100 d3d12.h.

Scope

The title describes one change, but the diff holds three commits, which are also the top of the branch:

Commit Content
5dbc30bed Slots 25 and 26 accept the title's C-ABI struct return (return buffer in RCX, device in RDX).
889785539 Slot 25 pads single-sample 2D render targets to whole SW_64KB_D tiles (stop 17).
c7ca0f2d1 Slot 25 hands the PC device a cleaned copy of each description: PC flags only, ROW_MAJOR for a buffer, UNKNOWN for a texture (stop 16, the subject of this PR).

If the first two are separate pull requests, add Depends on: #N for each and rebase so this diff shows only d3d12_xs_desc_clean.h and the clean-copy block in proxy_get_resource_allocation_info. If they belong here, the title should say so. Either way, put the item ID from the coordination issue in the description.

Code analysis

C-ABI dispatch (struct_return_call). Slot 26 is measured on the retail executable as rcx = buffer, rdx = device. That matches the Microsoft x64 rule for C: a struct wider than 8 bytes comes back through a hidden first argument, and the buffer is returned in RAX. Slot 25 (a 16-byte D3D12_RESOURCE_ALLOCATION_INFO) follows the same rule, but no call site is measured yet. The code comment says so, and it should also be marked as an inference in the design.md paragraph. Accepting both forms by checking which argument points at the proxy vtable is the same pattern the heap proxy uses for slots 9/10. Leaving slot 43 (8-byte LUID) on the PC path until it is measured is the right call.

  • Nit: the check reads only a0. A C-form return buffer is uninitialised caller stack, so a stale copy of the proxy vtable pointer there would send the call down the PC path. That would then write through a garbage pointer. This is unlikely, but cheap to close: also require *(void***)a1 != vtable before choosing the PC form, or check a1 first, since the title's form is the one on the hot path.
  • count and visible_mask arrive as 64-bit registers carrying 32-bit UINT arguments, so their upper halves are undefined under the x64 ABI. Truncating them with static_cast<UINT> before any use is correct, and it is done consistently.

Description cleaning (d3d12_xs_desc_clean.h).

  1. Flag mask drops 0x400, which the PC layer accepts. kPcResourceFlagsMask covers 0x1FF. But d3d12_vulkan_device.cpp:1542-1546 measures that the host accepts 0x400 on buffers and textures, and its validator allow-list includes it. The SDK header just doesn't name it (it is D3D12_RESOURCE_FLAG_USE_TIGHT_ALIGNMENT in newer Agility headers). Two problems follow:

    • If the console uses 0x400 for a console-only meaning, stripping it is correct, but that should be stated and sourced.
    • The runtime's own PC-form callers reach slot 25 through the same thunk, so a PC caller passing 0x400 gets a size for a different (non-tight) resource than the one it will create.

    Please either add 0x400 to the mask with the same comment the Vulkan device has, or quote the docs/retail_boot_chain.md: stops 13-17 (descriptor heap at an address, device slots 70, 127, 25) #6982 §3.7 measurement showing the title sets 0x400 with a console meaning.

  2. Textures are forced to UNKNOWN even when the layout is already a PC value. pc_resource_desc replaces every texture layout with UNKNOWN. For the title that is fine, because 0x101 is not a PC value. But a PC-form caller passing D3D12_TEXTURE_LAYOUT_64KB_STANDARD_SWIZZLE or a ROW_MAJOR cross-adapter texture now gets the size of a different resource. Suggest replacing the layout only when it is not a PC value: Layout > D3D12_TEXTURE_LAYOUT_64KB_STANDARD_SWIZZLE, or the measured 0x101/0x1 words.

  3. The docs overstate how much slot 76 shares this. docs/d3d12_vulkan.md says this is "the same cleaning as slot 76", and the header comment says slot 76 "replaces the layout word the same way". In fact slot 76 (d3d12_xs_device.cpp:1311-1313) replaces only the layout. It does not mask flags, and it does not call pc_resource_desc. So a console flag bit that slot 25 now strips still reaches CreateCommittedResource, where the Vulkan layer rejects it as "resource flags". Either move slot 76 onto pc_resource_desc in this PR, which removes the duplicate logic and keeps the size query and the creation consistent, or reword the docs and post a finding: for the follow-up.

  4. Alignment and the console extension words past byte 56 are not touched. That is consistent with slot 76. Worth one sentence in the header saying the measurement found no console values in Alignment; otherwise call it a hypothesis.

  5. Allocation failure of the temporary copy (new (std::nothrow)) returns {UINT64_MAX, 64 KiB}, which is the PC answer for an invalid description. That is reasonable.

Render-target padding (d3d12_xs_alloc_size.h).

  • The arithmetic checks out. 1920×1080 RGBA8 at 128×128 per tile is 15 × 9 = 135 tiles, and 135 × 64 KiB = 8,847,360 B. Overflow is guarded both on the width-to-size_t narrowing and on the slice × array multiply, and the 32-mip loop cap is defensive.
  • The padding is computed from the cleaned descriptions. That matters: the masked flags keep ALLOW_RENDER_TARGET, so the rule still fires.
  • The PR states clearly that the console tile shapes, and the absence of DCC/CMask memory, are an assumption, and that the size is only ever raised. Good.
  • Approximation to note: the extra amount is console − PC size of that description alone. For arrays of several descriptions this ignores the PC's inter-resource alignment padding, so the total can overshoot slightly. That is safe for stop 17's "more than 2 MiB left over" assert direction only if overshooting is benign, so please state that in the comment.
  • Cost: each render-target description triggers one more GetResourceAllocationInfo call on the PC device. That is fine at boot, but worth caching if slot 25 turns up in per-frame paths.
  • kSizeSaturated duplicates the PC layer's saturation constant. Consider sharing it from one header so the two cannot drift.

Test results

These need no game files:

  • git diff --check: pass
  • python -m compileall -q make_game.py tools tests: pass
  • python -I tools/check_no_game_data.py: pass
  • python -I make_game.py --help: pass
  • Targeted Python tests: none selected (empty set, so trivially passing). This PR is C++ only.

Not run in this verification: the runtime build and the GPU-backed C++ tests that exercise this code (device_proxy_test with the new raw C-form calls to slots 25/26, and xs_proxy_mock_test with the padding cases). In the PR description, please report the GPU and driver those passed on, as AGENTS.md asks. A case that would be worth adding to xs_proxy_mock_test: a description with a console flag bit and the 0x101 layout. Assert that the PC mock receives the masked flags and UNKNOWN, and that the caller's array is bit-identical afterwards. That pins the "the title's array is never written" claim.

Adherence

  • No game data: none. The new headers and tests use hand-written descriptions only, and the retail call-site measurement is described in prose without bytes, disassembly or addresses from the executable.
  • No keys, decryption or protection workarounds: none. This is ABI translation and size arithmetic.
  • Nothing online: no network code, no Xbox Live or Rockstar endpoints.
  • Fix, don't disable: satisfied. Console values are translated, not skipped, and the padding only ever raises a size. The open assumptions (slot 25's calling convention, tile shapes without DCC/CMask) are labelled as such in the docs.

Verdict

Approve once these are addressed:

  1. Decide on 0x400 in kPcResourceFlagsMask, with a source.
  2. Replace only non-PC layout values.
  3. Make slot 76 use pc_resource_desc, or correct the "same cleaning as slot 76" wording.
  4. Fix the PR's scope and title, and add Depends on:.

The vtable-check hardening and the shared saturation constant are nits.

AI-assisted.

…t, slot 56 offsets, full mip chains, rounded-up mip extents, B5G5R5A1, saturating sums

@devnull34 devnull34 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

device_proxy_test.exe fails on slot 25 (CTest #24 and #25 device_proxy and device_proxy_trace):

FAIL slot 25 (C ABI) writes the PC device's GetResourceAllocationInfo into the caller's buffer
FAIL slot 25 still answers the PC (C++) form
device_proxy_test: FAILED (2 failures)

Root cause:
In runtime/test/device_proxy_test.cpp:225-238, desc = buffer_desc() has desc.Layout = 0x101.
When real->GetResourceAllocationInfo(0, 1, &desc) is called directly on the PC WARP device, 0x101 is rejected as an invalid texture layout and returns SizeInBytes = UINT64_MAX.
However, proxy slot 25 now cleans desc to D3D12_TEXTURE_LAYOUT_ROW_MAJOR via pc_resource_desc(), successfully returning the actual allocation size (65536). Because device_proxy_test.cpp compares got with calling real with uncleaned desc, got.SizeInBytes == want.SizeInBytes fails.

device_proxy_test.cpp needs to pass a clean description to real (or pc_resource_desc(desc)) when computing want.

@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

#7078 changed under this PR, so I merged fast-rtbudget into fast-desc-clean (aeb2537). The conflict was in slot 25: the description copy from this PR stays, and the sizes now come from #7078's new layout (each resource at its own alignment, 16 MiB for the mixed 4 MiB case, saturating sums).

AI-assisted.

@LooperSalty

Copy link
Copy Markdown

Tested c7ca0f2d1 (the head before aeb253754, which I have not run) on Windows 11 10.0.26300, RTX 4070 SUPER (driver 610.88), MSVC (VS 2026) RelWithDebInfo, LEONIDA_D3D12=vulkan, own 1.0.2.1 copy (exe SHA-256 starts e95020b2), gta6rt --run with LEONIDA_UNIMPLEMENTED=stop and log, 2 runs.

Base: main ec0e01c5 + #6919, #6582, #4313, #4348, #6964, #6954, #6953, #2490, #7076, #7075, #7021 and #7066 merged locally (several conflicts resolved by hand).

Merge note: this PR and #6964 both define proxy_get_custom_heap_properties in d3d12_xs_device.cpp. Merged together, the file does not compile (C2440, an overloaded name used as a function pointer). I renamed #6964's helper locally to build. This PR's slot 25/26 code makes #6964's slot 26 branch redundant.

Exit codes, RVAs and slot numbers only. AI-assisted (Claude Code).

…cription, the PC device's answer for the console layout word is UINT64_MAX (found by devnull34 on ItsNotRexed#7110)
@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@devnull34 thanks, the diagnosis is exact. Fixed in d7451f9: device_proxy_test now computes the expected value from real->GetResourceAllocationInfo on pc_resource_desc(desc), the same cleaned description the proxy passes. The raw 0x101 layout makes WARP answer UINT64_MAX, which is what this PR is about. It builds on our pod, but WARP isn't available under Wine there (skip 77), so a Windows rerun of device_proxy / device_proxy_trace would confirm it. AI-assisted.

@TripleJ160

Copy link
Copy Markdown

Independent Windows validation on RTX 5090 (616.92) and Ryzen 7 9800X3D Radeon iGPU (AMD 25.10.30), MSVC 19.44 and Vulkan SDK 1.4.363.0.

At aeb253754 the GPU test d3d12_vulkan_device failed at allocation parity on both GPUs. Slot 25 rewrote ordinary PC descriptors before the device could validate them, including a tiled buffer and a buffer with an unknown flag. Your WARP oracle fix at d7451f9d9 handles the separate raw Xbox descriptor expectation.

I opened a small follow-up against your branch: tedin7#2. It keeps host validation for PC descriptors and preserves Xbox normalization, with a regression in xs_proxy_mock. Both GPUs get past allocation parity. With the separate #7125 test fix on the #7240 stack, all 10 focused CTests pass per GPU with Vulkan validation enabled. Synthetic tests only, AI-assisted.

@umnitus

umnitus commented Nov 23, 2026

Copy link
Copy Markdown

Independent native Windows clang-cl/xwin check at d7451f9. All eight xs_proxy_mock and device_proxy CTests passed, including both WARP cases with the corrected slot-25 cleaned-description reference. AI-assisted testing.

@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@TripleJ160 thanks, good catch and a clean fix. I merged your tedin7#2 into this branch (77878e3). Console-form calls, and any description with the Xbox 0x101 layout, are normalized. Other PC-form descriptions reach the host unchanged, so it can still reject an invalid one, and d3d12_vulkan_device's allocation parity holds again. @umnitus, thanks for the clang-cl/xwin run at d7451f9. AI-assisted.

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.

8 participants