Skip to content

d3d12_xs: device slot 127 takes the resource's memory through the title's XMem hook (retail boot chain stop 17) - #7235

Closed
NiiRoZz wants to merge 5 commits into
ProjectLeonida:mainfrom
NiiRoZz:d3d12-xs/slot127-xmem-hook
Closed

NiiRoZz wants to merge 5 commits into
ProjectLeonida:mainfrom
NiiRoZz:d3d12-xs/slot127-xmem-hook

Conversation

@NiiRoZz

@NiiRoZz NiiRoZz commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in #7231 (comment)

Depends on: #7021 (the __XMemAllocationHooks__ bridge) and #7052 (device slot 127). This branch is #7021's head with #7052 merged in; only the last commit, f5dae9ff2, is this PR. #7021 currently conflicts with main, so the diff against main also shows both of them until they land.

What

After the PC device creates a committed resource for Xbox device slot 127, the proxy calls the title's installed XMem allocation hook for that resource's allocation size (from the PC GetResourceAllocationInfo). It passes the D3D allocator ID and page-size field 2 (kXmemCommittedResourceAttributes). The memory is attached to the resource with SetPrivateDataInterface, so it goes back through the hook's free when the resource dies. The PC resource is not backed by that memory; it only keeps the title's accounting the same as on the console. With no hook installed, if the hook refuses, or if the PC call fails, slot 127 behaves as before.

Why

Stop 17 of the retail boot chain (#6982): a fatal assert right after the title's first full-screen render targets. Measured locally at the title's call sites, it isn't a size check against our answers:

Limits: the object type of a resource allocation is not measured, so it is 0. Only slot 127 does this; the other committed-resource paths (slots 27, 53, 76) can follow once a title is seen counting them.

Tested

Windows 11, MSVC 2022 (14.44, RelWithDebInfo, Ninja), RTX 5090:

AI-assisted: yes (Claude Code)

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. Only public API names, XMem attribute fields, resource shapes and counts; no addresses, offsets, disassembly, strings or bytes from the executable.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

🤖 Generated with Claude Code

Khuraie and others added 5 commits November 23, 2026 23:42
…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 ProjectLeonida#6982.
…nment, refuses null heap properties; tests pin heap flags, session and reference counts

Review of ProjectLeonida#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.
…(XMem allocation hooks for descriptor heaps)
…le's XMem hook (retail boot chain stop 17)

The console D3D runtime allocates a committed resource's memory with XMemAlloc, so a title's
__XMemAllocationHooks__ see it. Around its first full-screen render targets the title installs a hook
that bump-allocates allocations with page-size field 2 from a fixed arena and then asserts that little
of the arena is left unused; with no call reaching the hook, nothing is counted and the assert fires.

After the PC device creates the resource, slot 127 calls the installed hook (the one ProjectLeonida#7021 bridges for
descriptor heaps) with the PC allocation size and the D3D allocator ID, page-size field 2, and attaches
the memory to the resource as private data, so it goes back through the hook's free when the resource
dies. The PC resource is not backed by it.

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

Copy link
Copy Markdown

Retail Linux integration result on RX 9070 XT / Mesa RADV 26.3.1 / Wine 11.22. With #7052, #7078 and #7110, both 3840×2160 RGBA8 render targets were created. The host and tiled sizes agreed at 33,423,360 bytes per target. The last three traced calls created the SRV, RTV and UAV for the second target. The title then stopped.

With this PR’s slot 127 hook and #5680’s catalogue loader added, the same title reached Xbox slot 62 (CreateComputePipelineState) and loaded 26,584 translated shader entries from my local work folder. After that the trace shows four more committed resources, command lists, a descriptor heap and two more SRVs. It still ends during System Init, frame 0. The integration also contains #7075’s independent resource and #7066’s null view, so this measures startup progression only.

A separate synthetic test on Wine / lavapipe created two render targets. Each allocation hook was called once for 65,536 bytes, and the matching free ran on the last Release of each resource. No game data or shader artifacts are attached.

@controldebils

Copy link
Copy Markdown
Contributor

@NiiRoZz measured on the AMD Windows driver: f5dae9ff2 overruns the title's 64 MiB arena at stop 17, the same way #7240 does (details there: #7240 (comment)).

RX 6900 XT (gfx1030), AMD 26.11.2, Windows 11, MSVC, LEONIDA_D3D12=vulkan, own 1.0.2.1 copy, main plus the open boot-chain PRs, with this PR merged:

Suggestion: hand the hook the console tile size for render targets, not the PC size.

AI-assisted (Claude Code).

@justr4mzi

Copy link
Copy Markdown
Contributor

Independent native Windows 11 / MSVC 19.44.35230.0 / AMD Radeon RX 6700 XT (gfx1031, Vulkan 1.4.335, driver 2.0.372) verification of f5dae9ff2:

  • Build & CTest (standard and LEONIDA_VK_VALIDATION=1):
    • ctest --output-on-failure -R "^(xs_proxy_mock|device_proxy|d3d12_present|d3d12_draw)$": 8/8 passed (2.24 s standard, 1.58 s with LEONIDA_VK_VALIDATION=1, 0 validation errors).
    • xs_proxy_mock_test.exe (all 6 modes, including the slot 127 __XMemAllocationHooks__ 33,423,360-byte lease and release check) and device_proxy_test.exe (WARP): PASS (0 failures).
  • Negative control:
    • Reverting runtime/shims/d3d12_xs_device.cpp to parent 00722628a while keeping xs_proxy_mock_test.cpp at f5dae9ff2 fails at xs_proxy_mock line 1283: g_heap_hook.alloc_calls == 1 && g_heap_hook.last_alloc_size == kSize (exit 1). Restoring f5dae9ff2 passes (exit 0).

AI-assisted (Gemini, Antigravity).

@LooperSalty

Copy link
Copy Markdown

Tested f5dae9ff2 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. pass on NVIDIA: stop 17 is cleared.

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

  • Before: int3 at game+0x247af2d, right after the first two slot 127 render targets and slot 20.
  • With it: slot 127 resource memory through the title's XMem hook: 33423360 bytes, allocated. No budget assert. The title goes on to slot 16 (CreateRootSignature), slot 62 (compute pipeline), then an uncaught C++ exception (0xE06D7363) from XboxBvhBuilder.dll (stop 18). 6.5 s, 688 MB peak.

On this GPU slot 25 already answers with the tile size, so the lease is 33,423,360 B per target, as @controldebils expected for NVIDIA and RADV. The AMD overrun does not show here. Exit codes, module offsets and slot numbers only. AI-assisted (Claude Code).

@hiddenblur

Copy link
Copy Markdown

A note from reviewing #7240, which leases the same slot-127 render targets: at f5dae9ff2 this PR leases the PC GetResourceAllocationInfo size (info.SizeInBytes), with no console tile rounding.

On AMD's Windows driver that size is larger than the console's. @controldebils measured 33,619,968 B (513 × 64 KiB) for a 3840 × 2160 R8G8B8A8_UNORM target against 33,423,360 B for its 30 × 17 SW_64KB_D tiles, and two such leases (67,239,936 B) overran the title's 64 MiB arena: an int3 inside the title's hook during the second target (#7240 (comment) and the comments above it). #7240 fixed it in d61755d4d by leasing console_render_target_size for listed render-target shapes. NVIDIA answers the tile size already, which is why the NVIDIA runs here pass.

I read the code; I haven't run this PR on AMD hardware.

AI-assisted. No game files.

@zohaiblazuli

Copy link
Copy Markdown

Tested f5dae9ff2 (with #7052 and #7021) on the retail executable: pass.

Retail Xbox Series 1.0.2.1 package + executable (sizes match game/xbox-1.0.2.1.json), Windows 11 10.0.26300, MSVC 14.50, GeForce RTX 3060 (driver 32.0.16.1742). Vulkan backend (LEONIDA_D3D12=vulkan, Vulkan SDK 1.4.363). gta6rt --run with --overlay to a scratch folder, outbound network blocked, LEONIDA_UNIMPLEMENTED=stop. Base: main 8575d36ed plus my local console-queue-flag and struct-return (slots 25/26/43) changes, with these PRs merged in this order: #6953, #7187, #7076, #7075, #7021, #7066, #7235 (which carries #7052). Conflicts resolved locally.

  • Slot 127 creates its resources through the PC CreateCommittedResource3, and the memory is taken through the title's XMem hook. The boot continues through view and root-signature creation to the first CreateComputePipelineState (slot 62).
  • The stop there is local: this machine has no translated shaders yet, so the Vulkan device cannot build the pipeline. Not this PR.
  • Merge note: d3d12_xs: device slot 73 answers the console list IID with the console list proxy (depends on #6935, #2490) #7076 renamed the mock's Kind::command_list to Kind::list; I kept both names. xs_proxy_mock_test, queue_proxy_test and device_proxy_test pass.

Outcomes only; no game data.

@jimokulou2-ops

Copy link
Copy Markdown

Tested f5dae9ff2 with the retail executable (own 1.0.2.1 copy) on AMD Radeon RX 9070 XT (RDNA4), AMD Windows driver 32.0.32029.2010 (26.11.2), Windows 11 Pro 26300, MSVC 19.44 RelWithDebInfo, LEONIDA_D3D12=vulkan: past stop 17 on this card, unlike the RX 6900 XT result in #7240.

Base: main@51e7c9dc8 + #6919 36936f3bf + #4313 (IAmNotSiob:tls-4313-rebased bd71d37b7) + #6582 (IAmNotSiob:xerr-check b928f0290) + #4348 45c39cf6f + #7078 3ace9869d + #6954 72ab7623e + #2490 5be2fd287 + #7183 e7b3fade2 + #7218 c3fe82529 + #7492 7e8e3c1db + #7021 355201c51 + #7066 1d8d1d355 + #7052 9ec92918a + stop-16 (IAmNotSiob:stop16-on-7078 8177c85db) + this PR.

  • Without this PR: 1,640 D3D12 calls, then the title's int3 right after the first slot-127 render targets (stop 17), 2/2 runs.
  • With this PR: the lease logs 33423360 bytes, allocated, and the title goes on to device slot 16 (CreateRootSignature) and slot 62 (compute pipeline). There it stops only because I had not set LEONIDA_SHADERS yet ("no translated shaders"). 1/1 run so far.
  • Why it differs from the RX 6900 XT: @controldebils measured AMD's slot-25 answer on RDNA2 as 33,619,968 B (513 × 64 KiB), so two leases overrun the 64 MiB arena. On RDNA4 the same driver version answers 33,423,360 B, which is the console tile size (510 tiles). So the lease fits here by luck of the driver's answer. The suggestion in 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 to lease console_render_target_size is still needed for RDNA2 on AMD's Windows driver.

Not checked: a second run, and the stops after the pipelines (that needs the translated corpus).

No game data: only sizes, slot numbers and counts.

AI-assisted (Claude Code).

ramenbellic added a commit to ramenbellic/Leonida that referenced this pull request Nov 23, 2026
ramenbellic added a commit to ramenbellic/Leonida that referenced this pull request Nov 23, 2026
@XIIYAZ

XIIYAZ commented Nov 23, 2026

Copy link
Copy Markdown

Retail boot test (RT-5): own 1.0.2.1 copy, Windows 11, i9-12900KF, RTX 3070 (NVIDIA 617.42), MSVC 2022 RelWithDebInfo, LEONIDA_D3D12=vulkan, network shimmed (#6943). Local branch on main dde82f27e + #6943 #7125 #6010 #7133 #4313 #6582 #4348 #6964 #6953 #6954 #2490 #7218 #7021 #7066 #7110(+#7078 #6973) #7052, then the PRs named below. Counts and outcomes only.

Result: clears stop 17 on NVIDIA. The lease logs slot 127 resource memory through the title's XMem hook: 33423360 bytes, allocated (the console tile size, like the RX 9070 XT report, unlike RDNA2/RADV's 33,619,968). The title then creates its root signature and first Xbox compute pipeline (slot 62). Without this PR: the stop-17 int3 after 1,640 calls.

Merge notes: conflicts only in device_slot_overridden, the mock enum and mock_call. With #7110's mock also answering slot 25 there is a duplicate case 25; using allocation_size when a test sets it and mock_allocation_info otherwise keeps both PRs' checks green.

AI-assisted test run.

@aidity

aidity commented Nov 23, 2026

Copy link
Copy Markdown

Windows 11, i7-10700F, RX 580 (driver 31.0.21924.61), MSVC 14.44 integration validation: all eight device/mock variants pass after combining this with the startup stack, including #7052 and #7110. The combined mock keeps the explicit allocation_size override only for the accounting test; all other allocation-info tests retain #7110's description-based mock response.

Normal retail startup now logs successful slot-127 resource allocation through the title hook, passes the earlier accounting assertion, and reaches CreateRootSignature and the first CreateComputePipelineState. This GPU reports maxPushConstantsSize=128, so the current 144-byte pipeline contract is the next stop; testing #2402 next. No assertion skipping or debugger parameter rewriting; no game bytes, addresses or logs included.

ramenbellic added a commit to ramenbellic/Leonida that referenced this pull request Nov 23, 2026
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
…ource's memory through the title's XMem hook (retail boot chain stop 17)

Squashed from ItsNotRexed#7235 by NiiRoZz, head f5dae9f (security scan PASS).

Contains ItsNotRexed#7021 and ItsNotRexed#7052. registry.cpp stays on the SRWLOCK form adopted for ItsNotRexed#7021 here (this PR's copy of ItsNotRexed#7021 re-adds the function-local statics). The mock's slot 25 stays on ItsNotRexed#7078's description-based mock_allocation_info; this PR's mock_call case 25 (a fixed allocation_size) is dropped. Union of slot lists, check lists and the slot-18 null description as before.
dadnotdaddy pushed a commit to dadnotdaddy/Leonida that referenced this pull request Nov 23, 2026
… memory the title's XMem hook gives (slots 27, 53, 76, 127)

Squashed from ItsNotRexed#7411 by garuspl, head 9335d6b (security scan PASS).

Taken as its own commit 9335d6b on top of ItsNotRexed#7235 and the newer ItsNotRexed#7218 already here: the branch merges an older ItsNotRexed#7218 head, whose slot-133 code and Vulkan-device import would undo ItsNotRexed#7218's review fixes. The proxy file's reorder keeps slot 26 and the route_xbox_device_slot helper ahead of the committed-resource code, places ItsNotRexed#7218's current slot-133 handler where this PR's copy was (g_placed_at_va declared once, above), and keeps the slot 25/26/48/56/70/133 entries in the slot names, device_slot_overridden, the header and the mock test's check list.
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
…ress of a completed value that stays live (retail executable, past the PC fence chain)

Squashed from ItsNotRexed#7290 by TreXito, head 04fdf37 (security scan PASS).

Conflicts in xs_proxy_mock_test only: the Mock struct keeps ItsNotRexed#7235's allocation_size/private_data next to this PR's fence fields; the fence switch replaces the fixed GetCompletedValue line, with the resource SetPrivateDataInterface and heap 9/10 cases kept after it; the check list takes the union.
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).
Impre-visible pushed a commit to Impre-visible/Leonida that referenced this pull request Nov 23, 2026
…e resource of a slot 70 view of that address

Device slot 70 makes a shader-resource view from a description and a console
address, with no resource object. It asked only the device behind the proxy
for a buffer at that address, and that device knows the buffer by the title's
address only when it could put the buffer on the title's own pages. When it
could not (the import is refused, or the device is a PC one), the slot 133
buffer has an address of its own, nothing was found, and the title's
descriptor got the null view.

The proxy now remembers every buffer a slot 133 call made by the range the
title placed it at, whichever way it was made (the placed-at-VA handler, PC
CreateCommittedResource3 or CreateCommittedResource), and slot 70 asks there
first, then the device's provider. An entry holds no reference. An object
attached to the resource as private data removes the entry when the resource
dies, and a device proxy's entries go with it. The newest buffer over an
address answers, so a range the title places again is the new buffer's.

xs_proxy_mock_test: check_slot70_placed_buffer covers both creation paths
and the handler path, the element range, the cut at the buffer's end, the
addresses around two buffers, a texture, the provider fallback and its
order, a range placed twice, a released buffer and a released device. The
check of the placed-at-VA handler in check_levels hands out a mock resource
instead of a made-up pointer, since the proxy now asks the object for
ID3D12Resource.

Depends on: ItsNotRexed#7066 (slot 70), ItsNotRexed#7218 or ItsNotRexed#7075 (slot 133), ItsNotRexed#6953 (the table
reaches slot 133), and ItsNotRexed#7235 for the mock's SetPrivateDataInterface.

(cherry picked from commit 7387445)
Signed-off-by: local <local@localhost>
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.