Skip to content

d3d12_xs: committed resources lease their size through the title's XMem hooks, so the first render targets pass the budget check (retail boot chain stop 17) - #7240

Closed
jacksonslab wants to merge 11 commits into
ProjectLeonida:mainfrom
jacksonslab:rt5-stop17-title-hook-leases
Closed

jacksonslab wants to merge 11 commits into
ProjectLeonida:mainfrom
jacksonslab:rt5-stop17-title-hook-leases

Conversation

@jacksonslab

Copy link
Copy Markdown

Claimed in the coordination issue: #7049 (comment) (RT-5 stop 17).

Depends on: #7021 (the title's __XMemAllocationHooks__ plumbing), #7052 (slot 127) and #7110 (slot 25, stacked on #7078 and #6973). This branch merges their heads, so until they land the diff also shows their commits; only the last commit, d3d12_xs: committed resources lease their size ..., is this PR. At run time the title's hook chain ends in XMemAllocDefault, so the retail boot also needs a PR that serves it (#6919, or any other).

What and why

Stop 17 of the retail boot chain (#6982's numbering; @KkelebekK's 17 in #6910): right after the first two slot-127 render targets, a soft assert fires because more than 2 MiB of a fixed budget is left over. #7078 approached it through the sizes slot 25 reports. On the retail executable that isn't enough, because the budget isn't compared with those sizes directly:

  • Around those targets the title registers a per-thread hook in the same registry as stop 13. It bump-allocates out of a range the title reserved, taking any allocation whose XALLOC page-size field (bits 14..15) is 2, rounded to 64 KiB, and passes everything else down the chain. After the targets it asserts that less than 2 MiB of the range is left.
  • On the console, the D3D runtime allocates a committed resource's memory with XMemAlloc, so it reaches that hook. On the PC, no resource ever allocated through the hooks, so the whole range was always left over, whatever slot 25 answered.

This PR:

Tested

Windows 11, Intel Core i7-14700K, NVIDIA RTX 4070 SUPER, MSVC 2022 (14.44) RelWithDebInfo, Visual Studio generator.

No game data: only export, API and SDK names, attribute values, slot numbers, sizes of synthetic descriptions and counts.

AI-assisted: yes (Claude Code).

🤖 Generated with Claude Code

sneylol and others added 10 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>
…ttedResource3 with Xbox descriptors, RT-5 stop 15)

Slot 127 is past the PC device vtable and was refused with E_NOTIMPL. It has the argument list of ID3D12Device10::CreateCommittedResource3; the proxy now calls the PC device's with the Xbox layout word and flag bits cleaned as slot 76 does. Measured in ItsNotRexed#6982.
…(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.
…nment, refuses null heap properties; tests pin heap flags, session and reference counts

Review of ItsNotRexed#7052: dispatch and release through the ID3D12Device10 interface pointer (not the base device's vtable); keep every PC-valid resource flag bit, 0x400 included; null heap properties return E_POINTER; the test now passes non-zero heap flags and a protected session, checks the single release returns 0 for texture and buffer, and covers a distinct Device10 pointer.
# Conflicts:
#	runtime/shims/d3d12_xs_device.cpp
#	runtime/shims/d3d12_xs_device.h
#	runtime/test/xs_proxy_mock_test.cpp
# Conflicts:
#	runtime/shims/d3d12_xs_device.h
#	runtime/test/xs_proxy_mock_test.cpp
# Conflicts:
#	runtime/shims/d3d12_xs_device.cpp
#	runtime/shims/d3d12_xs_device.h
#	runtime/test/xs_proxy_mock_test.cpp
…em hooks (RT-5 stop 17)

On the console a committed resource's memory is allocated with XMemAlloc, so it goes
through the title's __XMemAllocationHooks__. The retail title budgets its first
full-screen render targets with a per-thread hook that bump-allocates out of a range it
reserved and asserts that less than 2 MiB is left; PC resources never allocated through
the hooks, so the assert always fired. Slots 76 and 127 now allocate the slot-25 size of
each resource through the hooks, held by the resource with SetPrivateDataInterface and
freed when it is destroyed.

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

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

@jacksonslab nice, and measured on the retail exe. I had a branch for the same thing (fast-rt-hooks, slot 127 plus hooks plus private data), built from kapitche's and rafaelpssz's data points but not run on the exe. Yours gets past the assert, so I'm dropping mine and won't open a competing PR.

Two things from our version and its Codex review that may help here:

  • Page-size field: we also found the title's matcher only takes allocations whose XALLOC page-size field (bits 14..15) is 2, while slot 14's descriptor-heap attributes leave it at 0. If you reuse d3d12_xs: honour __XMemAllocationHooks__ for descriptor heaps and translate CPU handles #7021's attribute word, check that resources set that field.
  • Getting the object for SetPrivateDataInterface: the review flagged casting the created interface straight to ID3D12Object as unsafe when riid isn't a resource interface laid out that way. QueryInterface(IID_ID3D12Object), then Release, is the safe form.

On sizes: #7078 makes slot 25 answer the console tile sizes, so your lease takes 8,847,360 B for a 1080p RGBA8 target instead of the PC's about 8,323,072. Both are fine for the 2 MiB check as you measured. With #7078 the leases also match the console's own sums. AI-assisted.

@jlric

jlric commented Nov 23, 2026

Copy link
Copy Markdown

Retail A/B on CachyOS / Wine 11.22, RTX 4070 (620.73.04): applying the runtime delta from ae322dafc to the same local boot stack clears stop 17. Both render-target creations succeed and boot reaches the first XboxBvhBuilder compute PSO with shaders unset. Baseline stops at the render-budget breakpoint. AI-assisted testing.

@controldebils

Copy link
Copy Markdown
Contributor

@jacksonslab hook leasing clears stop 17 on RDNA2 too, but only when the lease is the console tile size. As written, this PR leases slot 25's PC size plus #7078's extra, and on the AMD Windows driver that size is larger than the tile size, enough to overrun the 64 MiB arena.

RX 6900 XT (gfx1030), AMD driver 26.11.2, Windows 11, MSVC, LEONIDA_D3D12=vulkan, own 1.0.2.1 copy, the stack from my #7049 note plus #7021, #7066, #7052, #7110 and #7078:

Not run: this PR's own branch. The overrun is from the sizes above, not from a run of ae322dafc.

Suggestion: for listed render-target shapes, lease the console tile size itself, not max(PC, console). The PC size can stay what slot 25 returns to the title. @NiiRoZz, #7235 leases the PC GetResourceAllocationInfo size, so the same applies there.

AI-assisted (Claude Code).

@controldebils

Copy link
Copy Markdown
Contributor

@jacksonslab follow-up to my comment above, now measured: a retail A/B of ae322dafc on the RX 6900 XT (AMD 26.11.2, Windows 11, MSVC, LEONIDA_D3D12=vulkan, same stack, our local stop-17 patch reverted).

  • This PR as is: it logs committed resources lease their size through the title's XMem hooks (first: 33619968 B), which is slot 25's AMD answer (513 x 64 KiB). The run then stops on an int3 inside the title's hook, called from the lease during the second 3840x2160 RGBA8 target. That's the arena overrun: 2 x 33,619,968 = 67,239,936 B > 64 MiB.
  • Same build, lease = console_render_target_size (33,423,360 B, 510 tiles): both leases succeed, no assert, and the boot continues past stop 17 into the stops after it.

Suggestion: when the render-target rule applies, lease the console tile size itself (console_render_target_size), not console_allocation_size's PC size + extra; keep the PC size for everything else. NVIDIA and RADV are unaffected, since their slot 25 answer already equals the tile size.

AI-assisted (Claude Code).

…answer (ItsNotRexed#7240 review)

The title's stop-17 range holds two 3840x2160 RGBA8 targets at 510 SW_64KB_D tiles each.
AMD's Windows driver answers 513 x 64 KiB for that target, so leasing max(PC, console)
overran the range and hit an int3 inside the title's hook (measured by controldebils on
an RX 6900 XT). A listed render-target shape now leases its whole tiles; anything else
leases the PC size. The mock gets a driver bias to reproduce the AMD answer.

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

Copy link
Copy Markdown
Author

@controldebils thanks for the measurement and the A/B. Fixed in d61755d4d, as you suggested: a listed render-target shape now leases console_render_target_size (its whole tiles), and anything else leases the PC size. A larger PC answer is no longer used. xs_proxy_mock_test gets a mock driver that answers 513 x 64 KiB for 3840 x 2160 RGBA8 (your AMD figure), and the lease comes out at 510 tiles (33,423,360 B). PASS on Windows/MSVC. The docs paragraph says the same.

@jlric, @tedin7: thanks for the Wine A/B and for dropping the duplicate branch.

AI-assisted (Claude Code).

@TripleJ160

Copy link
Copy Markdown

Independent Windows synthetic integration result for ae322dafc. On this pinned head, WARP reproduced both slot-25 assertions (3/3 runs) and d3d12_vulkan_device failed at allocation parity on RTX 5090 (616.92) and Ryzen 7 9800X3D Radeon iGPU (AMD 25.10.30).

Applying the slot-25 validation follow-up (tedin7#2) and the separate #7125 test patch gave 10/10 focused CTests on each adapter with Vulkan validation enabled: device_proxy, device_proxy_trace, six xs_proxy_mock variants, d3d12_vulkan_device, and d3d12_m2_formats. MSVC 19.44, Vulkan SDK 1.4.363.0, Windows 11 build 26200. No retail run. AI-assisted.

@umnitus

umnitus commented Nov 23, 2026

Copy link
Copy Markdown

Independent native Windows clang-cl/xwin check at d61755d. All six xs_proxy_mock cases passed, including the 513-tile PC answer / 510-tile lease regression.

Stock device_proxy and device_proxy_trace reproduced the two documented slot-25 expectation failures each. Applying only the cleaned-description reference check from #7110 to the local test brought the full set to 8/8. The runtime was unchanged. #7110 at d7451f9 also passed all eight cases on this setup. Synthetic mock and WARP coverage. AI-assisted testing.

@hiddenblur

Copy link
Copy Markdown

Reviewed d61755d4d (this PR's two commits on top of 28766ea6f) on Windows 11 with MSVC (VS 18, /std:c++20 /W4 /permissive- /utf-8 /EHsc, the CMake targets' sources).

  • xs_proxy_mock_test: passes, including committed resources lease their slot-25 size through the title's XMem hooks until destroyed.
  • device_proxy_test: the same two slot-25 failures at this head and at 28766ea6f, so they're pre-existing as you say.
  • Two things I checked that are fine: slots 76 and 127 both return E_POINTER for a null output before the new *out read, so the CreateCommittedResource capability-check form can't reach it; and the Vulkan layer's Resource (d3d12_vulkan_device.cpp) answers ID3D12Object, so SetPrivateDataInterface really holds the lease there.

One design question: slot 76 now leases every committed resource it creates, for the whole run, while the budget check was measured only around the two slot-127 targets. When no title matcher takes a lease, the chain ends in XMemAllocDefault, so each lease is an extra full-size host allocation that's never used, adding commit charge of about the total size of slot 76's resources. And any other bump-allocating matcher on the thread that takes page-size field 2 would see these too, the AMD failure mode in general. Is slot 76 needed for stop 17, or could it wait until a title is seen counting it, as #7235 does by leasing only slot 127?

For whoever compares the two: #7235 (f5dae9ff2) leases slot 127 at the PC GetResourceAllocationInfo size, with no console_render_target_size, so it still has the 513-tile AMD overrun @controldebils measured and d61755d4d fixes here.

Nit: ae322dafc adds three /W4 warnings in xs_proxy_mock_test.cpp: C4244 at line 361 (uint64_t → HRESULT return) and C4389 at 1307 and 1313 (signed/unsigned ==). The parent builds clean.

AI-assisted. Synthetic tests only, no game files, no GPU run.

@controldebils

Copy link
Copy Markdown
Contributor

@jacksonslab confirmed on the real AMD Windows driver, not just the mock: d61755d4d passes stop 17 on an RX 6900 XT (gfx1030, AMD 26.11.2, Windows 11, MSVC, LEONIDA_D3D12=vulkan, own 1.0.2.1 copy; same stack as my A/B above, our local stop-17 patch reverted).

  • The log shows committed resources lease their size through the title's XMem hooks (first: 33423360 B), the console tile size, where ae322dafc leased 33,619,968 B.
  • The budget assert never fires; the run continues to the page-pool init after it.

Thanks for the quick fix.

AI-assisted (Claude Code).

@Scotmelonball

Copy link
Copy Markdown

Retail run of d61755d4d on the executable, own 1.0.2.1 copy: stop 17 cleared on NVIDIA/Windows.

Setup: Windows 11, RTX 3070 Ti (NVIDIA 610.88), Ryzen 7 5800X, MSVC 14.51, Vulkan SDK 1.4.341, LEONIDA_D3D12=vulkan. Integration tree: main 26e56f5 plus #6582, #6709, #3390, #4531, #4313, #4348, #6973, #7009, #6792, #7076, #7183, #6953, #7075, #7066, #7052, #7110, #7021, #7078 (at 889785539, not yet 359390833), this PR and #5680, with a local stand-in for the xmem physical pages and placeholder carves (stops 6, 10 and 11).

AI-assisted (Claude Code).

tibzejoker added a commit to tibzejoker/Leonida that referenced this pull request Nov 23, 2026
Slots 27/53 map the console initial state 0x6 (pc_initial_state_word); slot 76 maps it too and keeps ItsNotRexed#7240's lease. No same-slot clash: 27/53 were plain forwards. The mock keeps one slot-27 entry (creating, with a words-only mode for this PR's checks) and the PR's entry for 53.

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

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

checked: #7240 | with: clang-cl cross-build (xwin SDK, ninja, ccache) of runtime target xs_proxy_mock_test, run under Wine | on: Ubuntu, Wine 9.0 (x86_64 prefix), main@867d922f0 + #7240 (merges cleanly, no conflicts) | result: build ok, xs_proxy_mock_test prints PASS (exit 0), including the committed-resource lease checks (first lease 8,847,360 B = 135 tiles for 1920x1080 RGBA8 as the doc says); negative control: with lease_title_resource_memory() made to return at once in runtime/shims/d3d12_xs_device.cpp, the test fails at xs_proxy_mock_test.cpp line 1264 (g_heap_hook.alloc_calls == 1 && last_alloc_size == 8847360) and exits 1; NOT tested: device_proxy_test (needs a real D3D12/DXGI device, not run), real Windows, the retail title's hook (the attribute word 0x80<<16 | 2<<14 stays an assumption as the PR says), AMD driver sizes

Details:

  • Read against docs/d3d12_vulkan.md and docs/design.md of the PR: the lease size rule (listed render-target shape = whole SW_64KB_D tiles, never the PC size; otherwise the PC size), the free on resource destruction through SetPrivateDataInterface, and slot 25/26 behaviour match the code. No defect found in the lease (reference count is balanced: one reference kept by the resource, ours dropped; null out pointer is rejected before the lease path; hooks absent or returning null leave creation untouched).
  • Small doc mismatch, not a bug: docs/d3d12_vulkan.md says slot 25's description cleaning is "the same cleaning as slot 76", but slot 76 (proxy_create_resource) still only replaces the layout word and passes the title's flag bits through; only slot 25 uses pc_resource_desc() (d3d12_xs_desc_clean.h, used at d3d12_xs_device.cpp ~2096). The lease size is computed from that uncleaned slot-76 description, which is harmless for the listed shapes (it only reads ALLOW_RENDER_TARGET).

agent: yes

@akimfomin

Copy link
Copy Markdown

Native Windows WARP follow-up on the slot-25 test expectation at d61755d4. This independently confirms SoRadGaming’s normalization diagnosis. I built the exact production proxy with portable Clang and compared documented ROW_MAJOR host buffers, synthetic guest buffers through both proxy call forms, and a host-layout proxy control. All three trials at each width agreed: 4,096 B → 65,536 B and 69,632 B → 131,072 B, both with 65,536 B alignment. The original guest descriptor and both return-storage pointers stayed unchanged.

The stock test’s expected value should call the host with a copy of desc whose Layout is D3D12_TEXTURE_LAYOUT_ROW_MAJOR. Keep the original guest descriptor for both proxy calls and assert the host size is finite before comparing. The test-only edit compiled. I ran the focused WARP harness, without linking/running the full stock device test or CTest. Synthetic only. AI-assisted (Codex).

@pvfreis

pvfreis commented Nov 23, 2026

Copy link
Copy Markdown

checked: #7240d61755d | with: 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: the PR's own test passes; 6/8 overall: device_proxy and device_proxy_trace fail the two slot-25 checks (slot 25 (C ABI) writes the PC device's GetResourceAllocationInfo into the caller's buffer, slot 25 still answers the PC (C++) form) that the description already names
negative control: this branch also merges #7052, #7021 and #7110, so only this PR's two commits were removed: d3d12_xs_device.cpp reverted to the last merge commit 28766ea6, tests kept | result: xs_proxy_mock fails, so the test catches the change; the two device_proxy failures are identical without this PR, so they are not caused by it

AI-assisted (Claude Code).

@SirKingg

Copy link
Copy Markdown
Contributor

Independent Windows/MSVC check of head d61755d in a temporary integration with the existing slot-25/56, slot-127, descriptor and startup work: 13/13 targeted tests passed, including lease/free behavior and normalized descriptor sizing.

With Vulkan in Windows Sandbox configured with networking disabled and guest network checks, dry-run and init succeeded. The retail run logged a committed-resource lease through the title hooks, passed the prior breakpoint after the two committed resources, reached CreateRootSignature and CreateComputePipelineState, and then raised a C++ exception after the runtime reported that LEONIDA_SHADERS was not set. This experiment supplies no translated shader directory and does not establish a rendered frame or retail memory coherence.

dadnotdaddy pushed a commit to dadnotdaddy/Leonida that referenced this pull request Nov 23, 2026
…wers console tile sizes for 2D render targets (slot 25 return-buffer form; sizes ItsNotRexed#7240 leases at stop 17)

Squashed from ItsNotRexed#7078 by tedin7, head 3ace986 (security scan PASS).

Conflicts with ItsNotRexed#6954 (slot 48): header comment, slot overview in d3d12_xs_device.h and the mock test's check list keep both PRs' slots; slot 25/26/56 text and device_slot_overridden take this PR's form (it contains ItsNotRexed#6964).
dadnotdaddy pushed a commit to dadnotdaddy/Leonida that referenced this pull request Nov 23, 2026
…get size (from ItsNotRexed#7240)

Wave 2 port of the sizing half of ItsNotRexed#7240 (by jacksonslab) onto ItsNotRexed#7235/ItsNotRexed#7411's xmem_size: a listed 2D render target asks the title's XMem hook for its whole console tiles (console_render_target_size, slot 25's answer), not the PC GetResourceAllocationInfo size. On AMD (RDNA2, RADV too) the PC answers 33,619,968 B for each 3840x2160 RGBA8 target, so the two stop-17 targets overran the title's 64 MiB arena; the console size is 33,423,360 B (reviewers of ItsNotRexed#7235). ItsNotRexed#7240's own lease is not taken: it would ask the hook a second time for every slot 76/127 resource that ItsNotRexed#7411 already allocates through it.
dadnotdaddy pushed a commit to dadnotdaddy/Leonida that referenced this pull request Nov 23, 2026
…or heaps (ItsNotRexed#7021 review)

With ItsNotRexed#7021, a descriptor heap whose memory the title's XMem hook gives hands the title CPU handles in that memory, and device slots 17-24 translate them to the layer's own slots. The layer's command list dereferences CPU handles itself in OMSetRenderTargets, ClearRenderTargetView, ClearDepthStencilView and the UAV clears, so a handle in the title's range read memory the view was never written to (reported as a blocker on ItsNotRexed#7021, d3d12_com.cpp). Those four entry points now go through translate_cpu_descriptor_handle, which returns other handles unchanged and costs one atomic load while no title-backed heap exists. Also shortens the xmem_size comment of the ItsNotRexed#7240 sizing port.
dadnotdaddy pushed a commit to dadnotdaddy/Leonida that referenced this pull request Nov 23, 2026
…t expectations)

ItsNotRexed#7759 carries ItsNotRexed#7201's slot 86/101/108 handlers; its squash added them a second time next to ItsNotRexed#7201's copy (the 101/108 bodies are identical, and ItsNotRexed#7759's slot 86 keeps the PSO stream for slot 55), so ItsNotRexed#7201's copy is removed.

xs_proxy_mock_test: the check_xbox_slots summary line merged for ItsNotRexed#7163 had its \n written as a line break; ItsNotRexed#7235's slot-127 hook check now expects no PC slot 25 call for a listed render target (the console-size port from ItsNotRexed#7240 sizes it, same 33,423,360 B); ItsNotRexed#7821's check_view_heap_cap releases the heaps it makes, since its CreateDescriptorHeap mock case is now ItsNotRexed#7021's, which makes a heap proxy holding the device.

d3d12_vulkan_device_test: the meta-command checks run on the device behind the Xbox proxy, as ItsNotRexed#7125 does for CreateReservedResource2: proxy slot 61 is the title's CreateSamplerX (ItsNotRexed#7115).

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

This is the stop 17 fix to take over #7235 (and over the PC-size lease that #8072 and #8831 carry). Leasing the console tile size is the only form reported to clear stop 17 on both NVIDIA and AMD; leasing the PC answer overran the title's range on AMD's Windows driver.

The two open problems at d61755d4d both come from carrying an older copy of #7110 instead of its current head:

  • runtime/shims/d3d12_xs_alloc_size.h:77 still reads MipLevels 0 as one mip, as @tupacfan04 found. #7110's head already fixes it in the same header (d3d12_xs_alloc_size.h:84, full_chain).
  • The two device_proxy slot 25 failures come from the expected value being computed on the uncleaned description. #7110's head has the cleaned-description check that a commenter here applied to get 8/8.

git merge-tree of this head with #7110's head (2f2fb2fbb) conflicts in d3d12_xs_device.cpp, d3d12_xs_device.h, xs_proxy_mock_test.cpp and docs/d3d12_vulkan.md. Rebasing onto #7110's head as it is now should fix both points without new code here. lease_size (d3d12_xs_device.cpp:1710) then gets the full chain through console_render_target_size.

AI-assisted review (Opus 5.5). Read the diff against main; not built. Merge checks with git merge-tree against main and #7110's head.

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.