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

Closed
tedin7 wants to merge 19 commits into
ProjectLeonida:mainfrom
tedin7:fast-desc-clean
Closed

tedin7 wants to merge 19 commits into
ProjectLeonida: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.

NiiRoZz added a commit to NiiRoZz/Leonida that referenced this pull request Nov 23, 2026
ItsNotRexed#7110 now drops unordered access from depth-format textures in pc_resource_desc itself; this branch keeps
without_depth_stencil_uav for slot 76 and drops its own pc_resource_flags.

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

optinium51-bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Tested 2f2fb2fbb merged onto main f837d4fe9 (clean merge) on NVIDIA GeForce RTX 3060 (driver 616.92), Windows 11 26200, MSVC 14.52 (VS 2026), RelWithDebInfo + Ninja: pass.

No game files. AI-assisted (Claude Code).

@pvfreis

pvfreis commented Nov 23, 2026

Copy link
Copy Markdown

checked: #71102f2fb2f | with: cmake --build <b> --target xs_proxy_mock_test device_proxy_test, ctest -R "^(xs_proxy_mock|device_proxy)" | on: Windows 11 26H2 (26300), MSVC 19.44.35229 (v143) + Ninja, RelWithDebInfo, RTX 3060 617.14 | result: pass, 8/8 (device_proxy, device_proxy_trace, all 6 xs_proxy_mock variants)
negative control: d3d12_xs_device.cpp and .h reverted to the merge-base 867d922f0, the new tests kept | result: 3/8 fail: device_proxy (FAIL device slot 25 is the C-ABI GetResourceAllocationInfo override), device_proxy_trace and xs_proxy_mock (SegFault), so the tests catch the change
note: merged onto main with #6964 (slot 26), the two PRs' slot 25/26 prose in docs/d3d12_vulkan.md and the device_slot_overridden lines conflict; whichever lands second needs a rebase (the code merges without a conflict)

AI-assisted (Claude Code).

@aidity

aidity commented Nov 23, 2026

Copy link
Copy Markdown

Windows MSVC 14.44 / RX 580 driver 31.0.21924.61 validation: integrated this over the local startup stack (#6964, #8258, #7076, #7218, #7021, #7111, #8225, #7066). All eight device/mock tests pass, including the new allocation-description/layout/size checks. A normal startup that previously AV'd in proxy_slot<25> now passes slot 25 and reaches slot 127, which is not yet implemented in that test build. Testing #7052 next. No assertion skipping or debugger argument rewriting; no rendered frame or gameplay claim. No game data, title addresses or logs included.

@KevinPratap

Copy link
Copy Markdown

Tested 2f2fb2fbb on RTX 4050 Laptop (NVIDIA 592.82), Windows 11, MSVC 14.44 RelWithDebInfo, LEONIDA_D3D12=vulkan, own 1.0.2.1 copy, gta6rt --run offline, no asserts stepped over: pass. It clears the title int3 that stops the boot after about 12,000 D3D12 calls.

Merged onto @tibzejoker's rt5-integration 5fef1f1b1 plus #7746, #7922 and #7880, with the 52 builder programs in pipeline_cache.bin (#8858). The one conflict is in docs/d3d12_vulkan.md; I kept the stack's text.

  • Before (the stack had an older head of this PR): the title asserts right after a device slot 25 call. The disassembly at the int3 shows the title calling GetResourceAllocationInfo through slot 25, copying the 16-byte answer and asserting that the high dword of SizeInBytes is zero. A local log of slot 25 showed the PC answer SizeInBytes = UINT64_MAX for a TEXTURE2D 2560×1440 R32G8X24_TYPELESS description. The console flags were 0x80300006, which cleaned to ALLOW_DEPTH_STENCIL | ALLOW_UNORDERED_ACCESS, a pair the PC refuses.
  • With this head, pc_resource_desc drops the UAV bit from the depth format, slot 25 answers a real size, and the run reaches 62,564 D3D12 calls. The next stop is fence slot 12 (d3d12_xs: fence slot 12 returns the address of a completed value that stays live (retail executable, past the PC fence chain) #7290).

Traces stay local; only outcomes, slot numbers and public formats here. AI-assisted (Claude Code).

ramenbellic added a commit to ramenbellic/Leonida that referenced this pull request Nov 23, 2026
dadnotdaddy pushed a commit to dadnotdaddy/Leonida that referenced this pull request Nov 23, 2026
…x layout word and flag bits on a copy before the PC GetResourceAllocationInfo (retail boot chain stop 16)

Squashed from ItsNotRexed#7110 by tedin7, head 77878e3 (security scan PASS).

Conflicts with ItsNotRexed#6954 (slot 48): the header comment and d3d12_xs_device.h keep the slot 48 text, the mock test's check list keeps check_slot48; everything slot 25 takes this PR's version (it contains ItsNotRexed#7078).
dadnotdaddy pushed a commit to dadnotdaddy/Leonida that referenced this pull request Nov 23, 2026
…l builds d3d12_xs_desc_clean.h

From ItsNotRexed#7110: constexpr static_cast<D3D12_TEXTURE_LAYOUT>(0x101) is out of the enum's range, which clang-cl rejects in a constant expression (reported by several reviewers of ItsNotRexed#7110). The word is compared as a uint32 at both uses.
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.