Skip to content

d3d12_xs: accept console C-ABI GetDesc (out, proxy) on heap slot 8 and queue slot 18 - #8191

Closed
auswhalen999-debug wants to merge 2 commits into
ProjectLeonida:mainfrom
auswhalen999-debug:pr/xs-heap-queue-getdesc
Closed

auswhalen999-debug wants to merge 2 commits into
ProjectLeonida:mainfrom
auswhalen999-debug:pr/xs-heap-queue-getdesc

Conversation

@auswhalen999-debug

Copy link
Copy Markdown

Claimed in the coordination issue as: #8047 (comment)

What and why

Both D3D12_DESCRIPTOR_HEAP_DESC (16 B) and D3D12_COMMAND_QUEUE_DESC (16 B) exceed 8 bytes. Under the console x64 C-ABI struct-return convention, callers pass the hidden return buffer in RCX and the interface pointer in RDX (GetDesc(&out, proxy)), whereas PC C++ member calls pass (proxy in RCX, &out in RDX).

Previously, heap_slot<8> (ID3D12DescriptorHeap::GetDesc) and child_slot<ChildKind::queue, 18> (ID3D12CommandQueue::GetDesc) in
untime/shims/d3d12_xs_device.cpp forwarded (self->real, a1, ...) unconditionally, which faults when a console-ABI caller passes a stack return buffer in RCX and the proxy in RDX.

This change:

  • Adds static_assert coverage confirming both GetDesc structs are 16 bytes.
  • Adds console C-ABI detection (!is_heap_proxy(self) && is_heap_proxy(a1) in heap_slot<8>, and !is_child_proxyChildKind::queue(self) && is_child_proxyChildKind::queue(a1) in child_slot<ChildKind::queue, 18>) that translates (out, proxy) to PC (proxy->real, out), records slot stats and d3d12_trace, guards against a null out, and returns out in RAX.
  • Preserves existing PC C++ (proxy, &out) callers unchanged (short-circuiting on is_*_proxy(self) without touching �1).
  • Updates heap_slot_overridden(8) to return rue.
  • Leaves proxy_slot, device_slot_overridden, and kMaxSlots untouched and introduces no new function-local static guards.
  • Adds synthetic mock tests (
    untime/test/xs_proxy_mock_test.cpp) and real/Vulkan device tests (
    untime/test/device_proxy_test.cpp,
    untime/test/queue_proxy_test.cpp) exercising both console C-ABI and PC C++ forms, canary padding, null output handling, hit counters, and proxy integrity.

Tested

Built on Windows 11 x64 with clang-cl 23.1.6 + lld-link 23.1.6 + xwin-sdk 10.0.26100 (NVIDIA GeForce GTX 1070, driver 581.80, WARP, and Vulkan D3D12 backend):

  • Negative control on unpatched main (dde82f2): xs_proxy_mock_test fails on the new check_get_desc_c_abi assertions (exit 1).
  • After fix (0 compiler warnings in all modified files):
    • xs_proxy_mock_test: PASS across all 6 modes (default, --fail-virtualalloc, --fail-virtualprotect, --fail-veh, --env-slots, --env-slots-invalid).
    • device_proxy_test: PASS (0 failures) in both default and --trace-d3d12 modes (WARP).
    • queue_proxy_test: PASS (3 backend(s) passed — WARP, GTX 1070 hardware D3D12, and Vulkan D3D12) in both default and --trace-d3d12 modes.
    • gta6rt: built cleanly (--help verified).

AI-assisted: yes

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (N/A — D3D12.X proxy shim change only)

@tupacfan04

Copy link
Copy Markdown
Contributor

Outcome on the narrow stack (1944be581 + #6891 xg_xs applied locally), which matches the console-ABI case this PR targets:

  • 0 unimplemented: xg_xs.dll lines; both XGSuggestSwizzleMode and XGCreateTextureComputer are served.
  • 0 runtime unimplemented: lines (19 non-xg_xs imports remain unserved in the import table).
  • Last API: ID3D12CommandQueue::GetDesc (queue slot 18), D3D12 trace tools: export a skinned GLB from the ped skin streams #2288 of 2288; unhandled 0xC000001D immediately after it, 23.54 s.
  • The translated-shader index.json was still absent during the run (CreatePipelineState failed repeatedly but execution continued), so this crash is not the shader library.

So the next stop really is the console (out, proxy) GetDesc shape, and this PR is the right place to fix it. I’m testing the head locally on the stack and will report the next outcome; no game data.

AI-assisted (OpenCode).

@beamdotdev

Copy link
Copy Markdown

Tested on a boot stack: Pipodi's boot-integration@b2e606620 + #7111 + #7516 + #7201 + this PR. Windows 11, RTX 3070 (NVIDIA 621.01), i5-9600K, own 1.0.2.1 copy, LEONIDA_D3D12=vulkan.

The retail title's first queue slot 18 call is not GetDesc. It arrives in PC order, with the queue proxy in RCX and RDX pointing to an 8-byte local the caller zeroes before the call, while the queue layout is still undetected. After the call, the title tests EAX as an HRESULT, reads the local as a 64-bit integer, converts it to float and divides a constant by it. That's the newer layout's GetTimestampFrequency (PC slot 16), not GetDesc.

With this PR, the PC-order branch runs before the layout logic, so GetDesc writes 16 bytes into that 8-byte local and returns the buffer pointer where an HRESULT is expected. Without the PR, the existing unknown-layout rule (slot 18 → frequency getter) already answers it correctly. Suggest keeping the C-ABI branch (RDX is a queue proxy) and leaving the PC-order case to the layout detection.

AI-assisted (Claude Code).

@tupacfan04

Copy link
Copy Markdown
Contributor

Tested the head on the narrow stack (1944be581 + the local #6891 xg_xs + #8191). The targeted tests pass, but the retail boot still exits 0xC000001D immediately after XboxID3D12CommandQueue::GetDesc.

Diagnosis (temporary local logging, no game data):

  • The real call is the PC form: self is the queue proxy (is_child_proxy<queue>(self) == 1), a1 is the out pointer (is_child_proxy<queue>(a1) == 0). The console branch is not entered.
  • In this stack, slot 18 with an unknown layout defaults to the newer frequency getter (runtime/shims/d3d12_xs_device.cpp:1350-1356, real_vtable[16]). That writes 8 bytes into the caller's 16-byte D3D12_COMMAND_QUEUE_DESC; the title then faults at its own offset (0x144E8AA70, same as before) after the trace line.
  • So d3d12_xs: accept console C-ABI GetDesc (out, proxy) on heap slot 8 and queue slot 18 #8191 is correct for console-form callers but does not address this PC-form path. The layout default is the boot stop: an unknown/older layout must use the older GetDesc path; only a proven-newer device may take the frequency getter.

I’ve changed the local stack to require a proven-newer layout for the frequency path and am retesting. Suggest at least adding a PC-form GetDesc case to this PR’s coverage if the PR is meant to cover both ABI forms. AI-assisted (OpenCode).

@tupacfan04

Copy link
Copy Markdown
Contributor

Retraction: the retail boot's 0xC000001D is not the queue desc. A full run with the shader index loaded (26,503 main + 10 exe entries) still faults at the same title-side offset, and the stack agent identified it as the title executing a Zen 2 instruction the Intel i9-14900F lacks (INSERTQ/EXTRQ, CLZERO, MONITORX/MWAITX or CLWB). ID3D12CommandQueue::GetDesc is only the last API before that instruction; the fault address is inside the mapped title image, not gta6rt.

The slot-18 frequency/layout theory in my earlier comment was wrong; the local layout fix did not change the crash. Please disregard it. The real fix is #7111 (RT-500: gta6rt emulates the Zen 2 instructions an Intel CPU lacks, depends on #7013), not this PR. #8191 remains correct for the console C-ABI form but is not the boot blocker. AI-assisted (OpenCode).

@auswhalen999-debug

Copy link
Copy Markdown
Author

Thanks @beamdotdev for catching that on the boot stack!

Fixed in fb31ff1ef (pr/xs-heap-queue-getdesc):

  • Moved the queue slot 18 console C-ABI check (!is_child_proxy<ChildKind::queue>(self) && is_child_proxy<ChildKind::queue>(a1) → queue_get_desc_console) inside the generic else branch of child_slot and removed the separate else if constexpr (K == ChildKind::queue && Slot == 18) PC-order GetDesc interception.
  • PC-order calls (queue proxy in RCX) now fall straight through to the standard queue forwarding / layout-detection path, leaving undetected-layout GetTimestampFrequency handling intact while preserving console C-ABI (&desc, queue) translation.
  • Added a regression test in runtime/test/xs_proxy_mock_test.cpp verifying PC-order slot 18 falls through to the generic forwarder with all argument words preserved while console C-ABI (&desc, queue) and (nullptr, queue) continue to translate cleanly.

Re-verified (clang-cl 23.1.6 + lld-link 23.1.6 + Windows SDK 10.0.26100, Windows 11, GTX 1070 driver 581.80):

  • xs_proxy_mock_test.exe (all 6 modes: default, --fail-virtualalloc, --fail-virtualprotect, --fail-veh, --env-slots, --env-slots-invalid): PASS
  • device_proxy_test.exe (default + --trace-d3d12): PASS
  • queue_proxy_test.exe: PASS (3 backend(s) passed: WARP, host GTX 1070 D3D12, Vulkan D3D12)

AI-assisted.

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

Independent native Windows/MSVC check of fb31ff1ef0f679e3e6b1da09a3fe182089c7da7b: 9/9 focused CTests passed, none skipped.

Windows 11 build 26200, MSVC 19.44.35230, Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0, RTX 3070 driver 610.88. Built the exact head unchanged and ran device_proxy (+ trace), all six xs_proxy_mock modes, and queue_proxy. The queue test passed WARP, native NVIDIA D3D12 and Vulkan; Vulkan validation was enabled with no validation-error diagnostics. Existing host-invalid-pointer exclusions and unsupported Vulkan shared-fence coverage remain as reported by the test.

The current mock test linked against previous-head cbe5febb source fails at line 961 on the PC-order slot-18 argument-preservation assertion; the current source passes. That directly confirms the latest forwarding correction. The original dde82f27e base also fails the new heap slot-8 override check. Current console/PC GetDesc, canary, null-output and proxy-integrity checks pass. No actionable issue found in the changed code.

Built with Ninja / RelWithDebInfo, Vulkan enabled and SDL3 disabled: cmake --build <build> --parallel 4 --target device_proxy_test xs_proxy_mock_test queue_proxy_test, then ctest --test-dir <build> -V -R '^(device_proxy(_trace)?|xs_proxy_mock.*|queue_proxy)$'. No warnings in changed files; the build emitted the existing C4189 warning in vulkan_present.h.

Synthetic inputs only, no game files. This is focused native coverage, not a full runtime suite, retail boot or a test of the title's queue-layout detection on an integration stack. AI-assisted (Codex).

Claim: #9235 (comment)

@YordiLorenzo

Copy link
Copy Markdown

Tested fb31ff1 on RTX 4070 SUPER, NVIDIA 621.01, Windows 11 Pro: pass

  • Build RelWithDebInfo, MSVC + Ninja, Vulkan SDK: ok
  • ctest -R "device_proxy|queue_proxy|xs_proxy_mock" with LEONIDA_VK_VALIDATION=1: 9 passed
  • Negative control, the three changed tests on main 867d922: 4 of 9 fail, device_proxy, device_proxy_trace and queue_proxy crash (access violation), xs_proxy_mock fails at line 866 (heap slot 8 not overridden)

dadnotdaddy pushed a commit to dadnotdaddy/Leonida that referenced this pull request Nov 23, 2026
…(out, proxy) on heap slot 8 and queue slot 18

Squashed from ItsNotRexed#8191 by auswhalen999-debug, head fb31ff1 (security scan PASS).

Applied as the PR's own diff (gh pr diff); head fb31ff1 as rescanned. Against ItsNotRexed#2490's queue proxy: the console C-ABI GetDesc check (out in RCX, queue proxy in RDX) runs first in the queue dispatch, before note_child_slot and ItsNotRexed#2490's layout detection, which would otherwise read the caller's buffer as a proxy; a proxy in RCX still takes ItsNotRexed#2490's slot-18 path (newer-layout frequency getter, or PC GetDesc). Mock: Kind keeps heap and list; the heap slot 8 and queue slot 18 GetDesc cases follow the existing heap/queue cases; check_get_desc_c_abi joins the list.
dadnotdaddy pushed a commit to dadnotdaddy/Leonida that referenced this pull request Nov 23, 2026
…ins the older queue layout first (ItsNotRexed#8191 x ItsNotRexed#2490)

ItsNotRexed#8191 was written against a queue proxy without ItsNotRexed#2490's layout detection. With it, an undetected queue answers PC-order slot 18 as the newer layout's frequency getter, which writes 8 bytes and cannot overrun the caller (ItsNotRexed#2490's rule, kept). The check now calls slot 16 with an out pointer first, which pins the older layout, where PC-order slot 18 is GetDesc. The console C-ABI GetDesc path that the retail title takes is unchanged.
@itsRevela

Copy link
Copy Markdown
Contributor

Tested fb31ff1e merged onto main 867d922f on an NVIDIA GeForce RTX 3070 Ti (driver 610.88), Windows 11, MSVC 19.44 + Ninja, RelWithDebInfo: pass.

Full runtime ctest (267 tests): queue_proxy, xs_proxy_mock and device_proxy pass. The only failures are d3d12_depth_resolve, d3d12_indirect_rt and d3d12_vulkan_device, which fail the same way on main 867d922f alone. No new failure against that main.

AI-assisted (Claude Code).

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