Skip to content

d3d12_xs: the title's XMem hooks, console render-target sizes and resource leases, again (RT-XMEM-LEASE) - #375

Merged
aslan2142 merged 11 commits into
ProjectLeonida:mainfrom
Mumogg:xmem-hooks-sizes-lease
Nov 24, 2026
Merged

aslan2142 merged 11 commits into
ProjectLeonida:mainfrom
Mumogg:xmem-hooks-sizes-lease

Conversation

@Mumogg

@Mumogg Mumogg commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Claimed in #14 as RT-XMEM-LEASE. Depends on: #349, #350, #356, #362, #369 (their commits come first here; this pull request is the last five commits).

What and why

After #369 the title stops on a budget check: it bump-allocates its first full-screen render targets out of a range it reserved, through its own __XMemAllocationHooks__, and asserts that less than 2 MiB of that range is left. On main nothing goes through those hooks, so the whole range is left. tools/int3_cause.py on the stop shows the comparison against 0x1fffff.

Clearing it takes three pieces that build on each other. All five commits are cherry-picked with -x and keep their authors; all are ancestors of main whose content is not in the tree.

Commit Author What
355201c51 Khuraie __XMemAllocationHooks__ honoured for descriptor heaps; device slots 17 to 24 translate CPU handles in the title's own range (old PR 7021)
889785539 tedin7 device slot 25 pads a render target to whole console tiles
c7ca0f2d1 tedin7 device slot 25 gives the PC device clean resource descriptions
359390833 tedin7 sizes follow each resource's alignment, slot 56 offsets, mip chains, saturating sums
ae322dafc Jackson committed resources (slots 76 and 127) lease their size through the hooks

What I changed while resolving conflicts, so a reviewer knows where to look:

  • Everywhere the conflicts were neighbours added on either side (slot lists, the mock's cases, the test's call list): both sides kept.
  • proxy_get_resource_allocation_info: c7ca0f2d1 and 359390833 come from two branches of the original series; I resolved them as the original merge commit (aeb253754) did, including the mock's helper block.
  • The lease commit computed its size with a helper that 359390833 removes. I used the later form from the same author's follow-up (d61755d4d): a render target's console tile size, else the PC size. The commit message says so.
  • My slot 25 test from d3d12_xs: device slot 25 takes the console's struct-return form too (RT-SLOT25) #362 is adapted to the series' own mock for slot 25 (the sizes it answers, and the proxy now passes the PC device a cleaned copy of the descriptions, so the test no longer compares the pointer).

Left out on purpose, to keep this to what the stop needs: b4d1ba179 (PC descriptor validation in slot 25), 4a8603436 (a depth-stencil texture with unordered access) and bee47186f.

One thing a maintainer should decide: 355201c51 is the title-backed descriptor heap model. main also has the slot 14 console-heap handler in the Vulkan layer. They did not conflict textually and the boot below runs with both present, but they are two answers to the same question and I have not worked out how they should share slot 14.

Measured

Linux (Nobara 44, kernel 7.3), Wine 11.21 staging, RTX 5070 Ti (driver 615.78.08), clang-cl 22.1.8 + xwin SDK 10.0.26100, own 1.0.2.1 copy, network off, on main ece4ba5b3, with #142 and #328 applied on top for the boot runs (they are not in this branch).

--run D3D12 calls Ends with
up to #369 1,639 the title's int3 on the 2 MiB budget check
+ this 1,655 the title's int3 after its device set-up returns false; the last new slot called is 41

With this the log shows the first calls of device slot 16 (CreateRootSignature) and slot 62 (the console's compute pipeline creation), and the shader library loads (28,215 translated shaders here). The next stop looks like device slot 41, CreateCommandSignature, forwarded as it is.

xs_proxy_mock_test under Wine passes with every case of the five commits: descriptor heap hooks, render-target sizes, cleaned descriptions, render-target layout and committed-resource leases.

Not built with MSVC and not run on Windows. device_proxy_test also gets cases from 355201c51; I cannot run it here (it stops at D3D12XboxCreateDevice returns a device under Wine, on main too).

AI-assisted (Claude Code); built and run on the machine above.

🤖 Generated with Claude Code

https://claude.ai/code/session_01HxBQf4pXH8PWpC5oZsM4bt

@ubiquitarianism

Copy link
Copy Markdown
Collaborator

Holding this. #362 and #369 are merged. With this PR on top of them, a Windows MSVC build (AMD RX 6800, WARP for the proxy test) fails three checks that pass without it:

device_proxy_test:
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
d3d12_vulkan_device_test:
line 5525: allocation_mismatches <= 0

The console tile sizes for slots 25 and 56 change what GetResourceAllocationInfo returns, so it no longer matches the PC device these tests compare against. Either scope the console sizes to the title's resources, or update the tests to state the new contract, with a reason.

Follow-ups from review, not blocking on their own:

  • proxy_create_descriptor_heap applies the hook-backed address even when main's console-extended handler created the heap. It should require !console_extended.
  • translate_cpu_descriptor_handle has no callers, so command-list CPU handles (OMSetRenderTargets, Clear*View) aren't translated for title-backed heaps.
  • Committed resources from slots 76/127 also allocate their full size through the hooks, and that memory is never used.

#377 and the PRs stacked on it wait on this and on the ExecuteIndirect fix noted there.

@fiestorra

Copy link
Copy Markdown
Contributor

Tested your change against the retail title on today's main. Base d42773d07. Windows build 26300, MSVC RelWithDebInfo, LEONIDA_D3D12=vulkan on a Radeon 780M integrated GPU (gfx1036), 1.0.2.1 executable and package. Written with an AI assistant.

Good news first: the five commits are now clean on top of main. The parts of your branch that are not in main (0a714544d, 856334399, 584ef36fa, f1a68eeff, 35e687f2a) cherry-pick onto d42773d07 one after another with no conflicts — 11 files, +1419/−40 — and the build succeeds. #349, #350, #356, #362 and #369 have all landed since you opened this, so the neighbours you were resolving against on both sides are gone. A rebase onto the current main looks mechanical.

What you fix is now behind a wall this pull request does not cross. On d42773d07 with your five commits applied, the title stops exactly where it stops without them: 13 recorded D3D12 calls, device slot 73 CreateCommandListX refused for the console command-list IID, and the title's own assert 0x80000003 at game_scarlett_master.exe+0x2478b7b. Nothing in your change is reachable until one of #142, #359 or #445 answers that IID, so I would add one of them to your "depends on" list — as written, a reviewer following your dependency chain cannot get this far on today's main.

With the IID answered, your change clears the budget check you describe. I added #445's mapping on top (nothing else) and re-ran: the assert your body describes is gone. That check is visible in the executable — add rax, …; cmp rax,1FFFFFh; jbe <ok>; int 3 at game_scarlett_master.exe+0x247af2d, inside the function the title reaches from a call at +0x247942b, so it is a span the title requires to stay under 2 MiB. In the earlier run that call faults; with your commits applied the same call returns and the title continues to +0x247944f, which is where the run ends now. The XMem events in the startup trace also grow from 7 to 9, which fits your hooks being used.

And here is what it hands over, which I could not fix and am reporting rather than claiming. The run ends with a C++ exception, 0xe06d7363 (a throw, not an assert), thrown from inside XboxBvhBuilder.dll:

stack: host:KERNELBASE.dll+0xc56ca, host:VCRUNTIME140.dll+0x55a9,
       XboxBvhBuilder.dll+0xc525, +0x204bc, +0xd8a1, +0x213a1,
       game_scarlett_master.exe+0x2479455, +0x19f4f54, …

The title got there through the call at +0x247944f, which is call qword ptr [game_scarlett_master+0x6793f78] — a function pointer the title holds in its own data, not an import-table entry (I walked the image's import directory and that address is not in it, so it was filled at run time). The D3D12 side is otherwise unchanged from the run without your commits: same 1639 recorded calls, 1619 ok, ending on ID3D12Device::CreateUnorderedAccessView. So on this machine your change moves the stop from the title's 2 MiB span assert to the title asking the BVH builder to do something and the BVH builder throwing. What it was asked to build, and why that throws, I have not established.

Limits, so you know what this evidence does and does not cover: one machine (integrated Radeon 780M, gfx1036), no Vulkan NVIDIA comparison for this part. I did not run xs_proxy_mock_test.cpp or device_proxy_test.cpp from your branch — I tested by running the title. Combined with #445's mapping only, not with #359's retry form.

@VibeClauding

Copy link
Copy Markdown
Contributor

Same three failures on NVIDIA (RTX 3070, driver 610.88, Windows 11, MSVC), with #432's stack merged onto main 8f481cf16 and on #432's branch alone. Bisected over the stack with device_proxy as the test: the first bad commit is 584ef36fa ("device slot 25 gives the PC device clean resource descriptions"); 0a714544d and 856334399 before it pass. d3d12_vulkan_device's allocation_mismatches check fails on the same stack (not bisected separately). AI-assisted.

Khuraie and others added 9 commits November 24, 2026 03:47
…(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, #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 #6973.

(cherry picked from commit 8897855)
…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 #7078.

(cherry picked from commit c7ca0f2)
…t, slot 56 offsets, full mip chains, rounded-up mip extents, B5G5R5A1, saturating sums

(cherry picked from commit 3593908)
…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>
(cherry picked from commit ae322da)

Adapted to main by Mumogg: the lease size is the later form of this series (d61755d, a render target's console
tile size, else the PC size), since console_render_target_extra is gone after 3593908.
…g-cl rejects 0x101 for the unfixed enum)

Reported by YaBulochka and sovljanskii on #7154; #7110's current head has the same form.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit bee4718)
…console-form calls only

With the console tile sizes applied to every caller, a PC-form call through the proxy no longer answered what the
PC device answers, and the code that compares the two failed on Windows: device_proxy_test's two slot 25 checks
and d3d12_vulkan_device_test's allocation_mismatches (reported on ProjectLeonida#375 from MSVC builds on AMD and NVIDIA, the
first bad commit being the one that cleans the descriptions). Together with b4d1ba1, which scopes the cleaning
the same way, a PC-form caller now gets the PC device's own answer for its own description; the title's call,
which comes in the console form, gets the cleaned description and the console sizes as before.

xs_proxy_mock_test: the PC-form slot 25 case expects the mock device's size (it expected the console size), and
the mixed slot 56 case is asked in the console form. device_proxy_test includes d3d12_xs_desc_clean.h for the
cleaned description b4d1ba1's check compares with.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HxBQf4pXH8PWpC5oZsM4bt
…ole-extended heap

A heap that main's console-extended handler created already sits at the address the title named, so
proxy_create_descriptor_heap asks the title's XMem hooks for a backing address only when the heap came from a
plain PC description (follow-up asked for in review on ProjectLeonida#375).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HxBQf4pXH8PWpC5oZsM4bt
@Mumogg
Mumogg force-pushed the xmem-hooks-sizes-lease branch from 35e687f to 0c5a146 Compare November 24, 2026 09:54
@Mumogg

Mumogg commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Updated: rebased on main d7576d56a (so the branch is now only its own commits) with four more on top.

The three failing checks. I took the first option, scoping the console behaviour to the title's calls:

  • b4d1ba179 (Johan John Joji, -x, from the integration history): slot 25 cleans the description only for a console-form call or the console tiled layout; a PC-form caller's flags and layout reach the host unchanged. Plus the one-line clang-cl fix that follows it there (inline const for the 0x101 layout).
  • Mine: the console render-target sizes of slots 25 and 56 are applied to console-form calls only. A PC-form caller gets the PC device's own answer, so code that compares the proxy with the PC device agrees again. The title calls in the console form, so its sizes are unchanged. xs_proxy_mock_test states the new contract: its PC-form slot 25 case now expects the mock device's size, and the mixed slot 56 case is asked in the console form.

What I could and could not verify here. device_proxy_test needs WARP, which Wine does not have (D3D12CreateDevice fails, "no device"), so I cannot run the two slot 25 checks that failed for you; the change follows from reading them, and they need a Windows run. d3d12_vulkan_device, xs_proxy_mock, queue_proxy and allocator_proxy pass under Wine (RTX 5070 Ti, driver 615.78.08, clang-cl 22.1.8). d3d12_vulkan_device reaches the proxy in the PC form, so it should be covered, but I did not reproduce its failure before the change, so I am not claiming I fixed it. Thanks to VibeClauding for the bisect.

Follow-ups.

  • !console_extended: done, in its own commit.
  • translate_cpu_descriptor_handle without callers: d3d12_xs: the list proxy translates title-owned CPU descriptor handles (RT-LIST-HANDLES) #416 is the commit that gives the list proxy its callers (console list slots 50 to 54).
  • Committed resources leasing their whole size through the hooks, never used: true, and not changed here. That lease is what gets the title past its span check; I would rather record it as a known stand-in than guess a smaller size. Tell me if you want it out of this pull request.

The title's retail run with the whole stack is in #602. To fiestorra: thank you for the Windows run; the XboxBvhBuilder throw is outside what this branch touches and I have not looked at it.

AI-assisted.

@DesertGamer

Copy link
Copy Markdown
Contributor

Check on a second NVIDIA machine (Windows 11, RTX 5070, driver 617.14, LEONIDA_D3D12=vulkan, own 1.0.2.1 copy): this pull request merged on top of main 21625bc + #641 + #427 + #727 + #602 + #387 + #357 + #432, which reaches the frame loop, keeps it there: 549,783 PresentX ok and 19,857,246 D3D12 calls in 200 s, no exception, merged without conflicts. I did not check what the resource leases and render-target sizes do to the frames (still black on this stack).

AI-assisted: yes (Claude Code, Sonnet 5.5)

@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 24, 2026
One conflict, runtime/test/xs_proxy_mock_test.cpp, neighbours added on both
sides, both kept: the mock's `held` (this branch, slot 5 private data for the
committed-resource leases) next to main's `max_level` (FEATURE_LEVELS answer),
and this branch's five checks in main()'s list before main's
check_presentation_wiring().

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

Copy link
Copy Markdown
Collaborator

@Mumogg this PR is the gate for main's current stop (1,639 D3D12 calls, the title's 2 MiB budget check), so we want it in. We'll merge it as soon as it's rebased and the three held checks are confirmed.

  • Rebase: it conflicts with main again since your 09:54 update. Could you rebase onto current main?
  • The three device_proxy_test checks from the hold: your update scopes the console behaviour to the title's calls, and you said you couldn't run that test. I'm building this branch merged with current main now and will run device_proxy and the related tests under Wine (clang-cl with the xwin SDK), then post the results here.
  • A real-Windows run would settle it faster. @VibeClauding, you bisected the three failures with MSVC: could you re-run device_proxy on 0c5a14659, or on the rebased head once it's up?
  • If you're short on time, say so and I'll carry the rebase forward with your commits and credit.

AI-assisted (Claude Code, Claude Fable 5.2).

One conflict, runtime/shims/d3d12_xs.cpp: functions added after
create_root_signature_deserializer on both sides, both kept: main's
create_versioned_root_signature_deserializer, then this branch's
xmem_descriptor_heap_alloc/free (the bridge to the title's XMem hooks that
D3D12XboxCreateDevice installs).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Mouad-Scriptz-0

Copy link
Copy Markdown

This conflicts with main, and it's first on the path to the frame loop, so here's a rebase to save a step: rebased/pr375 (799d93d8d). It has the same 9 commits and authors on main 4a50cafc7. git range-diff against this branch shows no commit's own change was altered; only the surrounding context moved.

Every conflict was an add/add. I kept both sides:

  • runtime/shims/d3d12_xs.cpp: main's new create_versioned_root_signature_deserializer, then this PR's xmem_descriptor_heap_alloc / xmem_descriptor_heap_free.
  • runtime/test/xs_proxy_mock_test.cpp, mock struct: main's max_level and this PR's held. Both live in the zero-initialized g_pool and are set by name, so their order doesn't matter.
  • runtime/test/xs_proxy_mock_test.cpp, main()'s check chain: main's check_presentation_wiring() followed by all five of this PR's checks (check_descriptor_heap_hooks, check_render_target_sizes, check_allocation_descriptions_cleaned, check_render_target_layout, check_committed_resource_leases).

Not compiled or run here: I have no Windows SDK on this machine, so CI is the first build.

To take it (maintainer edits are on):

git fetch https://github.com/Mouad-Scriptz-0/leonida rebased/pr375
git push --force-with-lease=xmem-hooks-sizes-lease:0c5a14659 https://github.com/Mumogg/leonida-continued FETCH_HEAD:xmem-hooks-sizes-lease

AI-assisted.

@aslan2142
aslan2142 merged commit 9f25f1e into ProjectLeonida:main Nov 24, 2026
5 checks passed
@aslan2142

Copy link
Copy Markdown
Collaborator

Merged. Mumogg has been away since this morning and this PR is the gate for main's current stop (1,639 D3D12 calls, the title's 2 MiB budget check), so, as agreed among the maintainers, I brought the branch up to date myself: two merge commits of main on top of 0c5a14659 (94f2773c1, then d15a91601 for main 4a50cafc7). Mumogg's nine commits and their authors are untouched, and nothing was force-pushed.

Conflicts: three, each from additions on both sides, both kept.

Thanks @Mouad-Scriptz-0 for the independent rebase: it resolves the same three places the same way, and differs from this branch only in the order of two lines in the test.

The three checks behind the hold:

  • device_proxy, both slot 25 checks: with the four commits since the hold reverted, both fail under Wine (which has a WARP adapter here); with them, both pass. GitHub's Windows job also passed device_proxy on this PR merged with main, on real WARP.
  • d3d12_vulkan_device allocation_mismatches: not measured. The host comparison is skipped under Wine, and CI skips the test (no Vulkan). From the code it should pass: a PC-form call reaches the Vulkan device exactly as on main, and no case in compare_allocation_info uses 0x101. A run on Windows with a Vulkan GPU would settle it: ctest -R "^d3d12_vulkan_device$" -V should print no allocation info lines and not skip the comparison. If it is red, I'll fix it forward or revert.

Tests, the merged branch against main on the same commit (Linux; clang-cl with the xwin SDK; Wine, headless; llvmpipe and an RDNA2 iGPU):

  • Linux portable ctest: 74/74 on both.
  • Full Windows suite under Wine on both devices: no failure on the branch that main doesn't also have. device_proxy, device_proxy_trace, xs_proxy_mock*, d3d12_vulkan_device, queue_proxy, allocator_proxy, the loader tests and d3d12_close_parity pass on both.
  • Not run here: MSVC, native Windows, and the game itself. The runs others posted with this PR (NVIDIA, a Radeon 780M, an RX 9070 XT) report the 2 MiB stop cleared.

Next: #546 reads the same export with its own struct and conflicts with this in pe_loader.cpp; it fits on top of this PR using its registry. #377 is the next rung of the stack.

AI-assisted (Claude Code, Claude Fable 5.2 and Claude Opus 5.5).

@Diegobecker07

Copy link
Copy Markdown

The check left open above, measured on Windows with a Vulkan GPU, plus the retail boot after this merge.

Setup: main 51a6074d2 (contains this PR). Built with scripts\build_runtime.ps1 (MSVC 19.44, CMake 3.31.6 + Ninja). NVIDIA GeForce RTX 5070 Ti, driver 621.24, Vulkan 1.4.357, Windows 11 Pro 26300, Ryzen 9 5900X, 48 GB.

ctest -R "^d3d12_vulkan_device$" -V: passed (20.7 s), and the comparison ran against the host device.

  • No GetResourceAllocationInfo: no host D3D12 device to compare with, skipped line.
  • No mismatch line from compare_allocation_info (the stderr form allocation info <case>: ours size … alignment …, host size … alignment …).
  • It does print 46 allocation info <case>: alignment …, size ours … host … lines: that is the informational printf for every case with a top-mip size, so "no allocation info lines" can't be the criterion on a run with a host device. In 45 of them the sizes are equal. The one difference is 64x64 BC1 small (alignment 4096, ours 8192, host 4096), which the case's rule accepts (same alignment, a multiple of it, at least the top mip).
  • device_proxy, xs_proxy_mock, pe_loader: passed, 6 runs each.

Retail boot (own 1.0.2.1 copy, LEONIDA_D3D12=vulkan, --trace, --trace-d3d12, overlay outside the package):

  • Before this PR: every run stopped at the budget check after 1,639 D3D12 calls (two identical runs).
  • After it: the check passes (committed resources lease their size through the title's XMem hooks (first: 33423360 B)), and the title goes on to XboxBvhBuilder.dll's first CreateRootSignature and CreateComputePipelineState.
    • Without translated shaders on disk, it ends there in a C++ throw inside XboxBvhBuilder.dll (the stop 18 shape in docs/retail_boot_intel_host.md).
    • With them (26,576 modules loaded; the pipeline library's compute programs not translated yet), no further D3D12 call is traced, and about 27 s later the title's own fail-fast path ends the run (a deliberate write to address 0) on the same worker thread. I have not looked into what it reports.
  • xmem: wire executable __XMemAllocationHooks__ export into XMemAlloc/X… #546 alone, on main before this PR, left the budget stop unchanged.

AI-assisted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs rebase Conflicts with the base branch: rebase it on main

Projects

None yet

Development

Successfully merging this pull request may close these issues.