Skip to content

Runtime: Xbox-ABI proxy for the command allocator (device slot 9) - #1795

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
AimLogin:claim/D3D-allocator-proxy
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
AimLogin:claim/D3D-allocator-proxy

Conversation

@AimLogin

@AimLogin AimLogin commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

New D3D item, claim, status. This is the fourth command object, after BUILD-231's queue and fence (#1270, merged) and D3D-136's list (#1325, @quackottu).

What

Device slot 9 (CreateCommandAllocator) used to hand the title the bare PC or Vulkan-layer allocator with the SDK vtable, so a console-only allocator method jumped past it. It now returns an allocator proxy, built with the same code as the queue and fence proxies:

  • Public chain forwarded: 9 slots, the base chain and Reset at 8.
  • Refused tail: a slot past the public chain, up to the end of a 64-slot table, is logged once with its first argument words and returns E_NOTIMPL.
  • Guard region: the table sits in its own guard region, so a read past it faults at the vtable read and the fault logger names the slot.
  • Identity: QueryInterface answers only the base chain and ID3D12CommandAllocator, and GetDevice returns the device proxy. Private data goes to the real allocator. The real object and the Vulkan layer's private tag stay hidden.
  • Residency: an allocator is a pageable, so MakeResident/Evict/SetResidencyPriority/EnqueueMakeResident unwrap allocator proxies through proxy_real_object(), like heap, queue and fence proxies.

Where it can be wrapped

A list takes the title's allocator in CreateCommandList and Reset, so a proxy is only safe where the list side resolves it:

  • Vulkan layer: wrapped. Slot 9 wraps an allocator only when it answers kLeonidaCommandAllocatorTag. That tag moves from d3d12_com.cpp's CommandAllocator::kTag to d3d12_xs_device.h with the same value. CommandAllocator::from() resolves the proxy, which covers CreateCommandList, CreateCommandList1 and list Reset in one place, with the same pattern as queue_proxy_real_queue there.
  • Host PC runtime: not wrapped. Slot 9 returns the PC allocator unchanged and logs this once, because the PC runtime's lists would take a proxy for their own allocator. A command-list proxy that unwraps at Reset (Runtime: console-order command-list proxy at device slots 12/51 (D3D-136, Depends on #1270) #1325) is what would let the host backend wrap allocators too. That would be a small follow-up there, to coordinate with @quackottu. This PR does not touch device slot 12.

Xbox ABI

The console allocator's slots past the public 9 are not measured (docs/d3d12_command_objects.md §1.3, §3.5). None are guessed: they are the refused tail, so a title calling one shows up in the log with its slot and argument words instead of jumping through memory. Keeping the public chain's order on the console is the same assumption as for the queue and fence slots.

Tests

On 89b047cd (current main at the time), Windows 11 26200, RTX 4060 Ti 16 GB, driver 621.01, Vulkan SDK 1.4.363.1, MSVC 19.50:

Check Result
allocator_proxy_test (new): host WARP, host RTX 4060 Ti, Vulkan device, with LEONIDA_VK_VALIDATION=1 and sync validation 3 backends passed
Vulkan part of it: forwarding, slots 9–63 refused and counted, guard-region faults at the exact address, QueryInterface/GetDevice/private-data identity, D3D12's rules through the proxy (Reset while a list records: E_FAIL; a second list on a busy allocator: E_INVALIDARG), a list created and Reset on the proxy with two GPU copies through the queue and fence proxies read back byte for byte, residency HRESULTs equal to the real allocator's pass
Host part of it: slot 9 returns the PC allocator unwrapped, and the same copies work pass
Negative control: CommandAllocator::from() without the proxy resolution fails at CreateCommandList, as it should
xs_proxy_mock_test (extended): allocators with and without the tag, Reset forwarded, tail refused, residency unwrapped, null IID/output, failing and empty creation, refused IID, a refused allocation, plus the 3 guard-setup fault modes (they now cover three tables) pass
device_proxy_test (slot 9 is now overridden, and a WARP allocator stays unwrapped) pass
Full ctest, LEONIDA_VK_VALIDATION=1 with implicit layers off, and with VK_LAYER_VALIDATE_SYNC=1 98/99 each; main 89b047c: 97/98
Validation messages, same modes 2 on both branch and main
AddressSanitizer: allocator_proxy_test, mock test 0 reports
/W4 /analyze: d3d12_xs_device.cpp the same single warning as on main (C6387 in the slot-14 path)
/W4 /analyze: allocator_proxy_test.cpp, d3d12_com.cpp no warning in the files themselves
/W4 /WX /analyze: xs_proxy_mock_test.cpp clean

Known baseline failure: d3d12_draw fails on both this branch and unchanged main 89b047c in every mode, so it is not caused by this PR.

Not tested: Wine, other GPU vendors, and the host backend with wrapped allocators (that needs #1325).

AI disclosure

Written with AI assistance (Claude Code). I reviewed it, and the results above come from local runs on the hardware listed.

🤖 Generated with [Claude Code]

Device slot 9 (CreateCommandAllocator) now returns an allocator proxy,
the fourth command object after the queue and fence (BUILD-231) and the
list (D3D-136): the public chain (9 slots, Reset at 8) is forwarded, a
slot past it up to the end of a 64-slot table is logged and refused with
E_NOTIMPL, and a read past the table faults in its own guard region. The
console allocator's extra methods are not measured and not guessed.

A list takes the title's allocator in CreateCommandList and Reset, so a
proxy is only safe where the list side resolves it. Slot 9 therefore
wraps an allocator only when it answers kLeonidaCommandAllocatorTag (the
Vulkan layer's CommandAllocator, whose from() resolves the proxy for both
calls); a PC runtime allocator is handed out unchanged, logged once,
until a command-list proxy unwraps it at Reset. Allocator proxies are
unwrapped in the residency calls like heap, queue and fence proxies.
Device slot 12 is not touched.

Tests: allocator_proxy_test (WARP, a hardware adapter, the Vulkan device:
forwarding, refused tail, guard region, identity, D3D12's allocator rules,
a list created and Reset on the proxy with GPU copies through the queue
and fence proxies read back), mock cases for allocators with and without
the tag and their failure paths, and device_proxy_test's slot-9
expectations. No game files.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

2 participants