Skip to content

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

Open
auswhalen999-debug wants to merge 1 commit into
ItsNotRexed:mainfrom
auswhalen999-debug:pr/xs-heap-queue-getdesc
Open

auswhalen999-debug wants to merge 1 commit into
ItsNotRexed: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).

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.

3 participants