Skip to content

d3d12_xs: route device slots 86, 101, and 108 to PC Device2/Device5/Device8 - #7201

Open
justr4mzi wants to merge 4 commits into
ItsNotRexed:mainfrom
justr4mzi:d3d-xs-slots-86-101-108
Open

justr4mzi wants to merge 4 commits into
ItsNotRexed:mainfrom
justr4mzi:d3d-xs-slots-86-101-108

Conversation

@justr4mzi

Copy link
Copy Markdown
Contributor

Summary

  • Routes three Xbox d3d12_xs ID3D12Device vtable slots displaced by Xbox-specific ID3D12Device1..ID3D12Device4 methods to their PC ID3D12Device2 / ID3D12Device5 / ID3D12Device8 counterparts on DeviceProxy:
    • Slot 86 (CreatePipelineState(const D3D12_PIPELINE_STATE_STREAM_DESC*, REFIID, void**)) -> PC slot 47 (ID3D12Device2::CreatePipelineState), refusing with E_NOINTERFACE via refuse_beyond_device(86, self->slot_count) when self->slot_count <= 47, zeroing *out, and returning E_POINTER on null riid.
    • Slot 101 (CreateStateObject(const D3D12_STATE_OBJECT_DESC*, REFIID, void**)) -> PC slot 62 (ID3D12Device5::CreateStateObject, displaced on Xbox where slot 62 is the Xbox compute-PSO helper), refusing with E_NOINTERFACE when self->slot_count <= 62, zeroing *out, and returning E_POINTER on null riid.
    • Slot 108 (GetResourceAllocationInfo2(UINT visibleMask, UINT numResourceDescs, const D3D12_RESOURCE_DESC1* pResourceDescs, D3D12_RESOURCE_ALLOCATION_INFO1* pResourceAllocationInfo1)) -> PC slot 68 (ID3D12Device8::GetResourceAllocationInfo2). Accepts both the Xbox C-ABI struct return order (ret_buf in RCX, DeviceProxy* in RDX) and PC C++ member-function order (DeviceProxy* in RCX, ret_buf in RDX), copies each input descriptor's 56-byte D3D12_RESOURCE_DESC prefix into a zeroed D3D12_RESOURCE_DESC1 with SamplerFeedbackMipRegion = {}, normalizes Xbox-specific D3D12_TEXTURE_LAYOUT values above D3D12_TEXTURE_LAYOUT_64KB_STANDARD_SWIZZLE (0x101, 0x105, etc.) to ROW_MAJOR for buffers and UNKNOWN for textures, masks Flags to PC-valid bits (& 0x1FFu), forwards to real_vtable[68], and returns ret in RAX.
  • Updates slot_name() and device_slot_overridden() for slots 86, 101, and 108, and documents the three slot mappings in docs/d3d12_vulkan.md §3.1.
  • Adds mock and WARP-backed coverage in runtime/test/xs_proxy_mock_test.cpp and runtime/test/device_proxy_test.cpp (interface-level refusal on Device..Device7, forwarding on Device2/Device5/Device8, C-ABI and PC-order return buffer handling, and Xbox layout/flag normalization compared against direct ID3D12Device8::GetResourceAllocationInfo2 on WARP).

Claim: #7049 (comment)

Verification

  • Negative control on unmodified upstream/main (d239fd855):
    • xs_proxy_mock_test.exe fails (exit 1) at device_slot_overridden(86) / check_levels().
    • device_proxy_test.exe fails (6 failures, exit 1); calling slot 108 with C-ABI return order hits passthrough_83 and misreads self->slot_count from the caller's stack return buffer (slot 108 (<unknown>) beyond wrapped interface (3 slots) — refusing).
  • With this PR (dc29ee347) on Windows 11, MSVC 19.44.35230.0, AMD Radeon RX 6700 XT:
    • ctest --output-on-failure -R "^(xs_proxy_mock|device_proxy|d3d12_present|d3d12_draw|d3d12_translated_draw|d3d12_m2_textured)": 12/12 passed (2.37 s).
    • LEONIDA_VK_VALIDATION=1 ctest --output-on-failure -R "^(xs_proxy_mock|device_proxy|d3d12_present|d3d12_draw|d3d12_translated_draw|d3d12_m2_textured)": 12/12 passed (2.21 s, 0 validation errors).
    • python -I scripts/check_no_game_data.py: exit 0.
    • python -m unittest discover -s tests -p "test_docs*.py" -v: 36/36 OK.

AI-assisted (Gemini, Antigravity).

@tikD1337

Copy link
Copy Markdown
Contributor

Request changes. The three explicit routes and their interface-version guards are consistent with the existing proxy design, but slot 108 has two descriptor-handling problems that should be resolved before merging.

  1. [P1] The advertised 56-byte descriptor support uses the wrong array stride.
    In runtime/shims/d3d12_xs_device.cpp:1547–1548, the loop copies sizeof(D3D12_RESOURCE_DESC) bytes while advancing the input by sizeof(D3D12_RESOURCE_DESC1). On Windows x64 those sizes are 56 and 64 bytes respectively.

    For a packed, two-element D3D12_RESOURCE_DESC array—the legacy input representation the new comment says this handles—the second descriptor starts at byte 56, but the implementation reads bytes [64, 120) from a 112-byte allocation. That both misinterprets the second descriptor and reads eight bytes beyond the allocation. A focused, game-free python -I/ctypes reproduction confirmed the offset mismatch; a second descriptor with Width = 8192 was read as Width = 1.

    Please establish the Xbox input element stride and represent that layout explicitly before expanding it into PC D3D12_RESOURCE_DESC1 entries. Simply changing every source stride to 56 would also be incorrect for actual DESC1 arrays. The current tests use individual DESC1 objects with count == 1, so they cannot expose this problem. Add a synthetic multi-element case for the supported Xbox representation. Whether the retail caller supplies a packed 56-byte array remains unverified; the defect is in the implementation’s claimed support for that representation.

  2. [P2] Counts above 1024 silently bypass all Xbox descriptor conversion.
    In runtime/shims/d3d12_xs_device.cpp:1542–1565, descs_to_pass initially points to the original input, and normalization happens only when count <= 1024. Consequently, a 1025-element request forwards Xbox layout values such as 0x105, console flag bits, and any incompatible descriptor representation directly to the PC method. The same descriptor therefore receives different treatment solely because the array crossed this threshold.

    The public method takes a descriptor array and its count; its documented contract does not specify a 1024-element conversion boundary. See Microsoft’s GetResourceAllocationInfo2 documentation. Normalize the whole supported request, or return a defined failure before forwarding if the shim intentionally imposes a limit. Add boundary coverage for 1024 and 1025 descriptors, including verification of what the PC mock receives.

The remaining routing changes are well structured:

  • Xbox slots 86 → PC 47, 101 → PC 62, and 108 → PC 68 are intercepted before generic forwarding and its Xbox-slot bounds rejection.
  • The destination guards match the existing detected table sizes: Device2 exposes 48 slots, Device5 exposes 65, and Device8 exposes 73. Older interfaces are refused before indexing the destination.
  • The two creation routes clear a supplied output before failure, reject a null IID, and preserve the destination HRESULT.
  • Slot 108 explicitly handles both proposed argument orders, returns the caller’s result pointer, and uses {UINT64_MAX, 0} when the destination interface is unavailable. For requests entering the conversion branch, changes are confined to a private descriptor copy.
  • Slot names, override reporting, header documentation, and the runtime guide are updated consistently.

The new retail slot identities, return-buffer ordering, and descriptor interpretation still need traceable reverse-engineering evidence: executable/module identity plus call-site RVA or offset, especially for the array stride. Synthetic tests establish behavior under the proposed ABI; they do not independently establish the retail ABI. Document unsupported measurements as hypotheses.

Verification supplied by the harness on Windows 11 / CPython 3.13, without game files:

Check Result
git diff --check PASS
Python compileall PASS
check_no_game_data.py PASS
make_game.py --help PASS
Targeted tests NOT RUN — harness reported no matching test file

I did not rerun those checks. The additional focused Python reproduction checked descriptor sizes, offsets, and the conversion boundary; it did not execute the C++ proxy. The PR adds cases to device_proxy_test.cpp and xs_proxy_mock_test.cpp, registered as device_proxy and xs_proxy_mock in CMake, but neither is reported as executed. No MSVC/Ninja build, WARP execution, GPU/driver validation, or retail runtime validation is established here.

The reviewed changes contain no game payloads, keys, decryption or protection workarounds, or Xbox Live/Rockstar service access. They implement explicit routes rather than adding shader skip lists. No translator rule changes, so the shader contract-table and handwritten .asm fixture requirements are not triggered.

AI-assisted.

@Pipodi

Pipodi commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested dc29ee347 on the retail boot: pass for slot 108. Own 1.0.2.1 copy, Windows 11, RTX 4090 / 617.42, LEONIDA_D3D12=vulkan, on boot-integration plus #7115, #6891 and a local DirectStorage zlib stage (the #7180 idea).

  • Without this PR, the title's first slot 108 call got E_NOTIMPL (beyond the PC vtable), and the title hit an assert right after it.
  • With it, slot 108 goes through to PC GetResourceAllocationInfo2, that assert is gone, and the run reaches 1,675 D3D12 calls, against 1,662 before. The call uses the console order (return buffer first).
  • Slots 86 and 101 weren't reached in this run.
  • On this stack, the conflicts were only with the slot-route table from d3d12_xs: route the public HLE's Xbox device slots 48/73/78/79/80 #6935 (device_slot_overridden, the slot-name switch and the header comment). I took only the 86/101/108 parts.

AI-assisted (Claude Code).

@justr4mzi

Copy link
Copy Markdown
Contributor Author

Thanks @tikD1337 and @Pipodi!

Both points from the review are addressed in 6ef716f71:

  1. 56-byte D3D12_RESOURCE_DESC input array stride: Verified against the retail executable's descriptor builder for the slot 108 caller — it populates 56-byte D3D12_RESOURCE_DESC entries (up to Flags at +0x30, with no SamplerFeedbackMipRegion). proxy_get_resource_allocation_info2 now indexes raw_descs as const D3D12_RESOURCE_DESC* (56-byte stride) and expands each entry into a zero-initialized D3D12_RESOURCE_DESC1 with SamplerFeedbackMipRegion = {}. Added a 2-element packed D3D12_RESOURCE_DESC[2] test in both xs_proxy_mock_test.cpp and device_proxy_test.cpp (WARP).
  2. Removed the 1024-descriptor cap: All count > 0 requests now go through the conversion loop (returning {UINT64_MAX, 0} on allocation failure instead of forwarding uncleaned Xbox descriptors), with a 1025-descriptor batch test in xs_proxy_mock_test.cpp verifying that element 1024 is normalized.

Re-verified on Windows 11 / MSVC 19.44.35230.0 / AMD Radeon RX 6700 XT: xs_proxy_mock_test.exe and device_proxy_test.exe both pass (exit 0).

AI-assisted (Gemini, Antigravity).

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