Skip to content

d3d12_xs: mask console-only CreateCommandQueue flag bits before the PC forward - #8258

Open
Koro4e wants to merge 3 commits into
ItsNotRexed:mainfrom
Koro4e:queue-flags-console-mask
Open

Koro4e wants to merge 3 commits into
ItsNotRexed:mainfrom
Koro4e:queue-flags-console-mask

Conversation

@Koro4e

@Koro4e Koro4e commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

What and why

The retail title's second CreateCommandQueueX passes Flags=0x2, a bit the PC runtime does not define. Measured on this machine (boot runbook, --run): the PC runtime fails the call, the title checks the HRESULT and hits its own int3 at exe+0x2478866 — the stop posted to #7154 (comment).

Evidence, all static or from the shim's own trace, no game data:

  • The title builds its queue descs from constants and calls device slot 48 (call qword ptr [rax+0x180]) in a loop, asserting on every HRESULT (test esi,esi; jns ...; int3). Disassembly of the two call sites at exe+0x2478813 and exe+0x2478853:
    • first queue: Flags=D3D12_COMMAND_QUEUE_FLAG_DISABLE_GPU_TIMEOUT (0x1), Type=COPY — accepted;
    • second queue: Flags=0x2, Type=COPY — the PC runtime fails it (a C++ throw inside D3D12Core, first-chance, then E_INVALIDARG-shaped failure), title asserts.
  • PC CreateCommandQueue defines Flags NONE (0) and DISABLE_GPU_TIMEOUT (0x1) only.
  • With the mask, the same boot run passes the stop: both queues are created, the title moves on to device slot 73 (CreateCommandListX) — one stop deeper than the run without the fix (trace in Boot log for coding agents: where the executable stops and which PRs get past it #7154).

The change

proxy_create_command_queue copies the desc, masks Flags to the two PC-defined bits, logs the drop once, and forwards the copy. The caller's desc is untouched (const, and the mock now checks that).

Test

xs_proxy_mock_test records the desc the mock device receives (the shim forwards its own copy) and a new block drives slot 48 with Flags=0x2, expects the masked desc (NONE) at the real device, the caller's desc unchanged, and DISABLE_GPU_TIMEOUT surviving the mask. PASS.

Notes

…C forward

The retail title's second CreateCommandQueueX passes Flags=0x2, a bit the PC
runtime does not define (measured: static disassembly of the call sites at
exe+0x2478813 and exe+0x2478853; the first queue's Flags=0x1 is accepted, the
second's 0x2 fails, and the title checks the HRESULT and hits its own int3 at
exe+0x2478866). PC CreateCommandQueue defines Flags NONE (0) and
DISABLE_GPU_TIMEOUT (0x1) only, so the shim now drops the other bits before
forwarding and logs the drop once.

The mock records the desc it receives (the shim forwards its own copy) and a
new check drives slot 48 with a console-only flag bit, expects the masked
desc at the real device and the caller's desc untouched.

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

Verified via Tier 2 Free Cloud (Groq gpt-oss-120b): Masking console-only private flag bits from D3D12_COMMAND_QUEUE_DESC::Flags before invoking the host PC D3D12 CreateCommandQueue prevents E_INVALIDARG rejections by the standard Windows runtime while preserving console execution semantics.

@al3xar al3xar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested 0358e1388 on Windows 11 x64, MSVC 19.44.35230.0 (VS 2022 Build Tools), CMake + Ninja RelWithDebInfo, Windows SDK 10.0.26100.0 (no game files): build and existing tests pass, but code review found a null-dereference regression on desc == nullptr.

Verification

  • Merges cleanly onto upstream/main (dde82f27e).
  • Built device_proxy_test and xs_proxy_mock_test cleanly with zero warnings.
  • ctest -R "^(xs_proxy_mock|device_proxy)$" --output-on-failure: 2/2 passed.

Code review findings

  • Null-pointer dereference (runtime/shims/d3d12_xs_device.cpp:1146): D3D12_COMMAND_QUEUE_DESC pc_desc = *desc; dereferences desc unconditionally before calling self->real->CreateCommandQueue. On main, a null desc was forwarded to self->real->CreateCommandQueue(nullptr, ...) which returns an error HRESULT cleanly instead of access-violating (note that d3d12_method_variants_test specifically tests null-desc calls on the device). Forwarding desc unchanged when !desc (or returning E_INVALIDARG when !desc) avoids the crash:
    if (!desc) return self->real->CreateCommandQueue(nullptr, *riid, out); // or E_INVALIDARG
  • Minor: proxy_create_command_queue1 (slot 75, line 1236) does not apply the same flag mask if a console caller ever uses CreateCommandQueue1.

AI-assisted.

@MartinIndra02

Copy link
Copy Markdown

Independent build + test: the test passes, but a null desc now crashes (BUG)

AI-assisted (Claude Code). Windows 11 x64, MSVC 19.44.35220, Ninja RelWithDebInfo, NVIDIA GeForce RTX 3080 driver 621.24 / 32.0.16.2124.

Head 0358e1388, based on current main (dde82f27e).

Test Result
xs_proxy_mock_test.exe (unmodified PR) exit 0, xs_proxy_mock_test: PASS (9 allocations refused on purpose)

Bug: proxy_create_command_queue now dereferences desc before any null check.

d3d12_xs_device.cpp, proxy_create_command_queue: D3D12_COMMAND_QUEUE_DESC pc_desc = *desc; runs right after the riid check. Before, a null desc went to the real device, which refuses it. Host D3D12 returns E_INVALIDARG; d3d12_method_variants_test asserts that CreateCommandQueue(nullptr, ...) and CreateCommandQueue1(nullptr, ...) agree, and that the latter is E_INVALIDARG. Device slot 8 (CreateCommandQueue) and slot 48 (CreateCommandQueueX) both reach this function.

I added a temporary probe to check_xbox_slots that calls slots 8 and 48 with desc = nullptr under SEH:

PR shim:   REVIEW PROBE: slot 8 with desc=nullptr -> exception 0xc0000005, hr 0x00000000
           REVIEW PROBE: slot 48 with desc=nullptr -> exception 0xc0000005, hr 0x00000000
main shim: REVIEW PROBE: slot 8 with desc=nullptr -> exception 0x00000000, hr 0x00000000
           REVIEW PROBE: slot 48 with desc=nullptr -> exception 0x00000000, hr 0x00000000

(On main the mock itself accepts a null desc; with a real device the forward returns E_INVALIDARG.) Suggested fix: if (!desc) return self->real->CreateCommandQueue(nullptr, ...) (or return E_INVALIDARG) before the copy, or copy only when desc is non-null and forward desc ? &pc_desc : nullptr.

Other notes:

  • Device slot 75 CreateCommandQueue1 (the mock records it too, per the new last_queue_desc comment "slot 8/48/75") isn't masked. If the title ever reaches the PC CreateCommandQueue1 with console bits, the PC runtime will still fail it.
  • The new has_last_queue_desc member has no initializer. That's fine for the global g_pool, but bool has_last_queue_desc = false; would be safer if a Mock is ever created on the stack.

@tupacfan04 tupacfan04 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The console slot 48 masking works, but the shared helper changes PC behavior and a null desc now crashes.

  1. PC CreateCommandQueue now accepts invalid flags. runtime/shims/d3d12_xs_device.cpp:1145-1150 masks Flags unconditionally in proxy_create_command_queue; PC device slot 8 (:1513) and Xbox slot 48 (:1569) both call it, and the PC backend correctly rejects any flag other than DISABLE_GPU_TIMEOUT with E_INVALIDARG (d3d12_vulkan_device.cpp:5388). A PC caller using slot 8 with Flags = 0x2 should get E_INVALIDARG, but the helper masks it to NONE first and the call succeeds. The new test drives only slot 48 (tests/xs_proxy_mock_test.cpp:724-749); the mock's case 8 (:191-195) does not validate flags. Apply the console mask only on the slot 48 route (separate wrapper/flag), leaving PC slot 8 untouched.

  2. A null queue description crashes instead of returning an error. :1146 does D3D12_COMMAND_QUEUE_DESC pc_desc = *desc; before any null check. The original code forwarded desc to self->real->CreateCommandQueue, whose backend returns E_INVALIDARG for null (d3d12_vulkan_device.cpp:5381). raw(device, 8, 0, kQueueIid, &out) now dereferences null. Check desc before the copy and forward the null pointer (to preserve the real device's exact answer), then add a null-desc test for both slot 8 and the Xbox route.

Secondary: CreateCommandQueue1 (slot 75, :1235-1248) still forwards console-only bits; if the title uses that path, Flags=0x2 still fails. The PR body only covers slot 48, but the title is broader.

Correct: DISABLE_GPU_TIMEOUT survives, the caller's desc is copied not modified, console 0x2 reaches the real device as NONE with Type preserved, and the log-once atomic is thread-safe. Synthetic only; no game files. AI-assisted (OpenCode).

@tupacfan04

Copy link
Copy Markdown
Contributor

Correction to my review above: the null-desc crash and the slot 75 CreateCommandQueue1 asymmetry are already covered by al3xar's review and MartinIndra02's comment; I should not have repeated them.

The remaining unique issue is the shared PC route: proxy_create_command_queue (runtime/shims/d3d12_xs_device.cpp:1145-1150) masks Flags for PC device slot 8 as well as Xbox slot 48. PC slot 8 with Flags = 0x2 therefore succeeds through the proxy where the PC backend (d3d12_vulkan_device.cpp:5388) would return E_INVALIDARG. Apply the console mask only on the slot 48 route, and add a slot-8 Flags = 0x2 negative test (the current test drives only slot 48, and the mock's case 8 does not validate flags). AI-assisted (OpenCode).

…ep a null desc going through

Review fixes for ItsNotRexed#8258 (MartinIndra02's null-desc crash, tupacfan04's
slot-8 asymmetry):

- A null desc crashed: the mask copied *desc before any null check, while
  the pre-PR code passed a null desc to the real device, which refuses it
  (E_INVALIDARG, pinned by d3d12_method_variants_test's slot 8/75 agreement
  check). The desc now goes through as before when null.
- The mask applied to PC device slot 8 as well as Xbox slot 48, so a PC
  caller passing Flags=0x2 succeeded through the proxy where the PC backend
  returns E_INVALIDARG. proxy_create_command_queue now takes a
  console_route flag: slot 48 masks, slot 8 forwards the desc unchanged.

Tests: slot 8 with Flags=0x2 reaches the real device unmasked; null desc on
both routes forwards null and does not crash. xs_proxy_mock_test PASS,
device_proxy_test OK.
@Koro4e

Koro4e commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Pushed bb8c1291e with both fixes, thanks for the fast reviews:

  • Null desc (MartinIndra02): the mask no longer copies *desc unconditionally. A null desc goes through to the real device exactly as before the PR (the PC runtime refuses it; d3d12_method_variants_test's slot 8/75 agreement stays pinned), on both slot 8 and slot 48.
  • Slot 8 asymmetry (tupacfan04): proxy_create_command_queue takes a console_route flag — slot 48 masks, PC slot 8 forwards the desc unchanged, so a PC caller's undefined flag bit still gets the PC backend's E_INVALIDARG.

New checks in xs_proxy_mock_test: slot 8 with Flags=0x2 reaches the real device unmasked; null desc on both routes forwards null without dereferencing. xs_proxy_mock_test PASS, device_proxy_test OK. Both reviewers' probes should now come back clean — the review probe MartinIndra02 used (slots 8/48 with desc=nullptr under SEH) is exactly the case the new test covers.

@SirKingg

Copy link
Copy Markdown
Contributor

Independent Windows Sandbox comparison of bb8c1291e with #8379, #6582, #8461, #7216 and #6964 code/test hunks in a temporary checkout. Networking was disabled, game inputs were read-only and overlays were fresh.

  • Before this patch: 2/2 runs stopped after five D3D12 calls (four successful, one failed queue creation) at the published slot-48 queue-flags breakpoint.
  • With this patch: 2/2 reached 13 D3D12 calls (12 successful, one failed CreateCommandList), then a guest breakpoint. The existing static breakpoint analyzer identifies a slot-73 HRESULT guard, consistent with the separate command-list proxy work d3d12_xs: device slot 73 answers the console list IID with the console list proxy (depends on #6935, #2490) #7076; this check does not establish a regression in the queue-flags PR.
  • Windows 11 / MSVC 2022 RelWithDebInfo: device_proxy, xs_proxy_mock and gameinput CTests passed (3/3).

Only counts, error classes and public API/slot names are shared; traces stay local. AI-assisted.

@Pierrot1398

Copy link
Copy Markdown

Tested bb8c129 on NVIDIA GeForce RTX 5060 Ti, driver 621.24, Windows 11 Pro build 26300, VS 18 Build Tools (MSVC), Ninja, RelWithDebInfo: pass.

  • xs_proxy_mock and xs_proxy_mock_no_reserve: both passed 3/3 with ctest --repeat until-fail:3.

Built the PR head, not merged onto main. Synthetic only, no game files. AI-assisted (Claude Code).

@Koro4e

Koro4e commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Both findings are fixed in bb8c1291e (pushed after those reviews), and the branch now merges origin/main at 867d922f0.

  1. Null desc no longer crashes. The mask no longer copies *desc before a null check: a null desc is forwarded to the real device on both routes (PC slot 8 and Xbox slot 48), so its E_INVALIDARG answer is preserved exactly as before the PR. xs_proxy_mock_test now drives a null desc on both routes and asserts the device receives a null pointer.

  2. PC slot 8 keeps PC semantics. proxy_create_command_queue takes a console_route flag: only slot 48 (Xbox CreateCommandQueueX) masks, slot 8 forwards the caller's desc untouched, so Flags=0x2 still reaches the PC backend and its E_INVALIDARG is the answer. The test asserts the mock device receives 0x2 unmasked on slot 8, and DISABLE_GPU_TIMEOUT still survives the console mask.

  3. Slot 75 (CreateCommandQueue1) is the PC ID3D12Device9 entry on the PC vtable, not a console route: the console creates its queue through slot 48, and the title's two call sites (exe+0x2478813, exe+0x2478853) are both that route. Masking inside slot 75 would reintroduce exactly the PC-semantics change flagged in point 1 of the review, so it forwards unchanged. If you would rather pin that with an explicit test, say so and I will add one.

Verified locally: CMake + Ninja RelWithDebInfo, MSVC, ctest -R "^(xs_proxy_mock|device_proxy)$" --output-on-failure -> device_proxy passed (0.27 s), xs_proxy_mock passed (0.04 s), 2/2. Re-review welcome.

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.

7 participants