Skip to content

d3d12_xs: the device and queue proxies follow the console method order, not the PC one, so a console method no longer lands on a wrong PC method (XValkyrie B4/B5) - #7490

Open
tedin7 wants to merge 11 commits into
ItsNotRexed:mainfrom
tedin7:xv-b4b5

Conversation

@tedin7

@tedin7 tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Claimed in #6750 (comment)

@ItsNotRexed: an exe PR, as you asked.

What

The device and queue proxies follow the console vtable order instead of the PC one.

  • runtime/shims/d3d12_xs_console_slots.h (new): the console device order (0-42 public; console methods at 43-82 and 104;
    the public ID3D12Device1..5 at 83-103 and Device6..8 at 105-112, forwarded 39 or 40 slots lower) and the two known
    queue layouts (kit2020 and the later kit, which moves everything from Signal on by 2).
  • Device: 43 GetAdapterLuid with the LUID in RAX; 44 CreatePlacedResourceX (committed stand-in, every call logged);
    60 CreateGraphicsPipelineStateX (console flag bits removed); 61 CreateSamplerX (84-byte console sampler); 68
    GetGpuHardwareConfigurationX; 74/75 Register/UnregisterPagePoolX; 81 GetFrameStatisticsX (count 0, S_FALSE);
    111 the feedback UAV with the console argument order; 49-54, 58, 69, 72 accepted with no effect. Anything else
    is refused with E_NOTIMPL and never reaches a PC method.
  • d3d12_xs: route the public HLE's Xbox device slots 48/73/78/79/80 #6935's routes (48/73/78-80) run first, unchanged; the table refuses those slots only when LEONIDA_XS_*_SLOT
    moves a route away.
  • Queue: the layout is decided once, from the first Signal/Wait/SignalX given a fence proxy (14/15/23 vs 16/17/25)
    or a call at 32/33; the word is checked with VirtualQuery first. Until then a layout-dependent slot does nothing.
  • Diagnostics: every slot not forwarded is counted, and its first call is logged with the caller as module+RVA and
    four argument words, so the first boot names every console method the exe uses.

Why

In PC order, console methods at 44-82 land on PC Device1..14 methods (#6498: slot 78 reached
CreateReservedResource2). The queue sent 16-18 to GetTimestampFrequency/GetClockCalibration/GetDesc, which the
console queue does not have there. This gets the exe past device and queue calls that went to the wrong method.

Tested

Pod p2 (RTX 4090), clang-cl + xwin, Wine, DISPLAY=:99.

  • xs_console_slots_test (new), 3 modes (default, --later, --present-32): pass. On origin/main's proxy it fails
    at line 257 (a console slot reached a PC Device1+ method), and the two layout modes exit 5. Negative controls:
    26 public Device1..8 slots must reach PC 44-72, and 44-82, 104 and 113-127 must reach none.
  • 40 ctest tests over the proxy: 32 pass, 7 skip (need host D3D12 or the package), 1 fails the same way on main
    (d3d12_fence_timing check_luid: the test device's LUID is zero, line 248 on main).
  • Fixed to call the real objects or the console slots, checks kept: d3d12_vulkan_device, d3d12_debug_markers,
    d3d12_fence_timing, dxgi_device, d3d12_mesh, queue_proxy, device_proxy, xs_proxy_mock (d3d12_xs: route the public HLE's Xbox device slots 48/73/78/79/80 #6935's env tests now
    expect the console order: a moved route leaves 78 refused; a public method at 86 reaches PC 47).
    Shared helper: runtime/test/xs_console_call.h.
  • Timeouts on main too, not from this PR: queue_proxy and xbox_present time out at 600 s on main under Wine
    (queue_proxy's child-runner check hangs). With that one check skipped locally, queue_proxy's Vulkan run passes
    on this branch (31 differential cases, all 128 queue and 64 fence slots covered); on main it stops at its guard
    check. device_proxy skips on both (no host D3D12 under Wine).
  • Merges cleanly with d3d12_xs: the device proxy table covers slot 133, so slots past the PC vtable refuse instead of jumping to 0 #6953 (git merge-tree): the merged tree, with 192 slots and its slot-133 check, passes
    xs_proxy_mock (6 modes) and xs_console_slots (3 modes).

What xvalkyrie gave

Facts only, from sammwyy/xvalkyrie (GPL-3.0) at commit 53af7df77c10: src/runtime/modules/d3d12x/device.cpp:4196-4262
(device order, names and argument shapes of 43, 44, 48, 49-55, 58, 60, 61, 68, 69, 72-75, 78-81 and the
Device1..8 positions), device.cpp:2036-2186 (the two queue layouts) and docs/research/d3d12x.md. The sampler
layout is the kit's as xvalkyrie read it. No code was copied. Checked against Leonida's own measurements
(docs/d3d12_vulkan.md §7, docs/d3d12_command_objects.md §3.5a): device slots 1, 14-16, 18, 19, 27, 38 in PC order
and 62/67/76 console-only all fit. Where they differ, ours is kept: xvalkyrie leaves 67 unknown, and its
CreateCommandQueueX has three arguments where docs/d3d12_xs_surface.md inferred a shader-queue parameter (recorded,
not used). docs/d3d12_command_objects.md §5.2a has the full table.

Overlaps

Open PRs touching the same dispatcher: #7201 (86/101/108 to PC Device2/5/8: the same mapping, a subset of this
one), #7115 (61), #7187 (caller logging), #7066 (70), #7235 (127), #7218/#7075/#7183 (133). Slots 70, 127 and 133
stay refused here for their owners. #7218 names 133 CreatePlacedResourceX; xvalkyrie puts that method at 44.

Known limits

  • Until the title's queue layout is detected, GetDesc (queue slots 26/28) answers S_OK without writing the return buffer. Those slots are a different method in the other console layout, so writing through the first argument could corrupt memory; this PR leaves it open on purpose.
  • Slot 44 (CreatePlacedResourceX) is a committed stand-in, as its comment and the first-call log line say: the title's memory at that address is not shared with the resource.

AI-assisted: yes

Device slots 43-82 and 104 are console methods (handled, accepted or refused,
every call counted and reported with its caller); ID3D12Device1..8 are
forwarded from 83-103 and 105-112. The queue proxy decides between the two
known console layouts from the first fence call. Facts from xvalkyrie
53af7df77c10, checked against docs/d3d12_vulkan.md section 7.

WIP: tests that use the proxy as a PC device still need moving.
@Silliana

Copy link
Copy Markdown

Measured in a local integration on main 9f53c50: the focused slot PRs compose into two working stacks - #6964 (26), #6954 (48), #7076 (73), #7066 (70), #7110 (25), #7052 (127), #7218+#6953 (133) - reaching 1,181 ok D3D12 calls in one stack and the descriptor heap / slot 70 / slot 133 / slot 25 sequence in another.

This PR restructures all of those slots at once, so every one of them collides: runtime/shims/d3d12_xs_device.cpp, runtime/shims/d3d12_xs_device.h and runtime/test/xs_proxy_mock_test.cpp.

Suggestion: split by slot, or rebase on the focused set and keep the slot table as the single shared change. Reviewing 7 small diffs is easier than re-verifying one large one, and a slot that regresses then has an obvious owner.

@AwkGrep256

Copy link
Copy Markdown
Contributor

An AI review of c69debd (Claude Code ultrareview, multi-agent with a verification pass; I checked the main claims against the head before posting). Four findings, most important first:

  1. normal: a queue proxy passed to ResizeBuffers1 (dxgi_com.cpp 121-124, 369). is_direct_present_queue QIs the title-supplied queue for ID3D12CommandQueue and calls GetDesc().Type. On a queue proxy, PC slot 18 is now a console slot that answers S_OK without writing the struct (and PC 16/17 no longer reach GetTimestampFrequency/GetClockCalibration either), so Type is uninitialized and ResizeBuffers1 can return DXGI_ERROR_INVALID_CALL. Fix: unwrap with d3d12_xs::queue_proxy_real_queue first, as d3d12_com.cpp already does at 1851/1874.
  2. pre-existing, made reachable here: struct-returning GetDesc while the queue layout is undecided (queue slot 26/28). It returns S_OK (0) in RAX, but the x64 ABI returns the hidden buffer pointer there, and MSVC callers often copy the result through RAX (movups xmm0,[rax]), a null read. A title reading its queue type right after CreateCommandQueue, before the first Signal, would crash. The "Known limits" note mentions the unwritten buffer, not the null RAX. Suggestion: return a1 (the caller's hidden pointer) for undecided struct returns, which still never writes through an uncertain argument.
  3. nit: LEONIDA_XS_*_SLOT moved onto a newly handled slot is silently ignored. env_device_slot accepts 3..127, but the if constexpr branches for 43, 44, 60, 61, 68, 74, 75, 81, 111 and the console 84/85/89 return before the routes block, so a moved route there is never taken while the "moved" log line says it is. Check routes first, or refuse those slots in env_device_slot, and update the comment that says a moved route still wins.
  4. nit: create_queue's comment says console slot 48 (CreateCommandQueueX) "ends here too, with its description translated", but the slot-48 route calls proxy_create_command_queue, which counts it as note_slot(8) and passes the console argument through untranslated. Fold it back, or give slot 48 its own note_slot(48) and make the comment match.

AI-assisted.

@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @AwkGrep256 for the review, all four points confirmed and handled in 416cd348b: (1) is_direct_present_queue now unwraps the queue proxy first (queue_proxy_real_queue), (2) undecided struct returns on queue slots 26/28 now return the hidden buffer pointer in RAX and still write nothing, (3) a LEONIDA_XS_*_SLOT override on a newly handled slot keeps the default with a warning, (4) the create_queue comment matches the code. Pod (Wine, RTX 4090): xs_console_slots_test, xs_proxy_mock_test exit 0; dxgi_swapchain_test PASS (with the Wine host-comparison line neutralised in the pod copy). Not yet covered: a copy-queue proxy through ResizeBuffers1. AI-assisted.

@sgonzalez-glitch

Copy link
Copy Markdown

Tested 416cd348b on main dde82f27e, native Windows 11 (so the host D3D12 comparisons run, unlike under Wine), NVIDIA GeForce RTX 2080, driver 621.24 (32.0.16.2124), MSVC 19.44 RelWithDebInfo: 2 tests that pass on main fail with this PR. Same result at c69debd78.

  • queue_proxy: host WARP: the PC device outlives its proxies, right after 12 rounds of device proxy, 3 queues and 3 fences in both release orders, no leak. The real device still holds a reference once every proxy is released.
  • d3d12_vulkan_device: line 5524, allocation_mismatches <= 0. Through the device proxy, GetResourceAllocationInfo1 returns size 46530759836 / alignment 140706027235612 and GetResourceAllocationInfo2 size 10000000 / alignment 5, against host 65536 / 65536, then Device4/Device8 per-resource layout wrong (total 0/0). It looks like the PC Device4 / Device8 methods called through the proxy now land on console slots, as slot 78 did before d3d12_vulkan_device: check PC CreateReservedResource2 behind the Xbox proxy, not through slot 78 #7125. On main this check passes, and the test stops later, at tiles == 1.
  • The new xs_console_slots tests (default, --later, --present-32) pass. Apart from the two above, the full ctest (259/264 pass, 11 skipped) fails only where main already does.

AI-assisted: yes

@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @sgonzalez-glitch, that run was exactly what was missing (my pod is Wine, no host D3D12). Pushed a46c4511d + 9392e1e5f. (1) GetResourceAllocationInfo1/2 and the other PC ID3D12Device4/Device8 methods through the proxy: confirmed in the code, a PC caller hit console slots (PC slot 56 refused, slot 68 wrote Xbox timer data into the allocation result). Extended interfaces now use PC slots for host callers and Xbox slots only for a mapped guest caller, and a console query no longer advertises Device9..Device14. New mock checks: 65,536-byte size and alignment, residency forwarding, shared COM identity, both release orders. (2) queue_proxy "the PC device outlives its proxies": I could NOT find the cause. The 12-round check passes on my side and a read of the code shows no unmatched reference, so this one is still open; if you can, please re-run queue_proxy at 9392e1e5f and tell me whether it still fails. Pod (Wine, RTX 4090): xs_proxy_mock_test, xs_console_slots_test exit 0, dxgi_swapchain_test PASS. AI-assisted.

@optinium51-bot

Copy link
Copy Markdown

Tested 416cd348b on NVIDIA GeForce RTX 3060 (driver 616.92), Windows 11 26200, MSVC 14.52 (VS 2026), RelWithDebInfo + Ninja: queue_proxy fails, at this head (3/3) and merged onto main 47428cc22 (4/4, plus the full suite); main alone passes (2/2). The rest of the suite passes apart from the two failures main has too (d3d12_vulkan_device, #7125; d3d12_depth_resolve, #7905): xs_console_slots*, xs_proxy_mock*, device_proxy*, dxgi_device and dxgi_swapchain* pass.

The failure is host WARP: the PC device outlives its proxies, from the host D3D12 section (skipped under Wine).

Cause: this PR removes CreateCommandQueue1, no output (index 9) from kDiffCases, but is_isolated_diff_case() still uses the old indices, so every isolated index after 9 now picks the case after the intended one. SetEventOnMultipleFenceCompletion, null entry (now 24), which faults on the PC runtime, then runs in-process, and the fault leaves a reference on the PC device: counting the references after each in-process case gives 2 up to it and 3 from it on.

Shifting the indices (17-20 to 16-19, 25 to 24, 26-29 to 25-28, 30/31 to 29/30) makes queue_proxy pass 3/3 here. Marking isolation on the case itself (a flag in DiffCase) rather than by index would keep the next added or removed case from shifting them again.

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

…andQueue1 case (a null fence entry no longer runs in-process and leaks a PC device reference)
@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@optinium51-bot thank you, that is the cause I could not find: removing CreateCommandQueue1, no output shifted every later case but is_isolated_diff_case() kept the old indices. Pushed the shift you measured (17-20 to 16-19, 25 to 24, 26-29 to 25-28, 30/31 to 29/30). I cannot run the host section here (Wine), so please re-run queue_proxy at the new head. Your suggestion to mark isolation on the case itself instead of by index is better; I will do that as a follow-up commit if the shift confirms the diagnosis. AI-assisted.

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.

5 participants