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).

@LooperSalty

LooperSalty commented Nov 23, 2026 •

Copy link
Copy Markdown

Static support for the slot 86 mapping, from the retail 1.0.2.1 executable (my own copy; Ghidra/capstone on targeted functions): the title's call at game+0x2479a87 (call [rax+0x2b0], device global game+0x75df000) builds { SizeInBytes = 0x2b0, pPipelineStateSubobjectStream } on the stack, passes the ID3D12PipelineState IID (765a30f3-…) and an out pointer, so it is the PC D3D12_PIPELINE_STATE_STREAM_DESC shape this PR forwards to PC slot 47.

The 0x2b0-byte stream uses PC subobject types: ROOT_SIGNATURE (0) at +0, VS (1) +0x10, PS (2) +0x28, DS (3) +0x40, HS (4) +0x58, GS (5) +0x70, BLEND (8) +0x88 (0x148 bytes), SAMPLE_MASK (9), RASTERIZER (10), DEPTH_STENCIL1 (0x15), SAMPLE_DESC (0x11) +0x250, INPUT_LAYOUT (0xc) +0x260, PRIMITIVE_TOPOLOGY (0xe), RENDER_TARGET_FORMATS (0xf) +0x280, DEPTH_STENCIL_FORMAT (0x10) +0x2a8. Correction (measured later on the retail boot): some streams retype +0x10 as type 0x18 (24) and +0x58 as 0x17 (23). I first read these as AS/MS; they are not mesh pipelines: those PSOs carry a PS and a triangle topology and no MS, and 24 behaves as the console VS (and 23 as HS, per TreXito's read in #8186). Note that 23 is not a PC subobject type and PC MS is 25. On failure (hr < 0) this site returns quietly and leaves the title's PSO pointer null (no int3 there); it is called 6 times in a row from game+0x19f4df0 right after retail stop 21. The offsets of the later subobjects and the mesh retyping are read from the code, not run. AI-assisted (Claude Code).

@eizispark

Copy link
Copy Markdown

Tested 8e76568 (merged cleanly with main 23fc0c9a) on AMD Radeon RX 9070 XT, Adrenalin 26.11.1 (LLPC / Vulkan 1.4.359), Windows 11: pass (ctest 12/12 passed: device_proxy, device_proxy_trace, xs_proxy_mock, xs_proxy_mock_no_reserve, xs_proxy_mock_no_protect, xs_proxy_mock_no_handler, xs_proxy_mock_env_slots, xs_proxy_mock_env_slots_invalid, d3d12_present, d3d12_translated_draw, d3d12_m2_textured, d3d12_draw; gta6rt build clean; scripts/check_no_game_data.py passed). AI-assisted.

@TheHoracio

Copy link
Copy Markdown
Contributor

Tested 8e765684c on AMD Radeon RX 7800 XT (RDNA3), Windows 11, MSVC 2022 RelWithDebInfo: pass. scripts/build_runtime.ps1 and the device/proxy subset of ctest (incl. xs_proxy_mock, device_proxy): 26/26. No game files. (AI-assisted run.)

Integration note: the 86 → 47, 101 → 62 and 108 → 68 mappings match #7490's console order (Device1..5 forwarded 39 lower, Device6..8 40 lower), so the two agree on these three slots.

@justrealyme

Copy link
Copy Markdown

Tested 8e76568 on NVIDIA GeForce RTX 5070 Ti, driver 617.42, Windows 11 build 26300, VS 2022 Build Tools (MSVC 19.44), Windows SDK 10.0.26100, RelWithDebInfo: pass.

Built device_proxy_test and xs_proxy_mock_test and ran ctest -R "^device_proxy|^xs_proxy_mock": all 8 passed (device_proxy, device_proxy_trace, xs_proxy_mock and its no_reserve, no_protect, no_handler, env_slots, env_slots_invalid variants).

AI-assisted (Claude Code).

@garuspl

garuspl commented Nov 23, 2026

Copy link
Copy Markdown

Tested 8e765684c merged onto main 7ef2fdd46 (clean merge) on NVIDIA GeForce RTX 4090, driver 617.42, Windows 11 Pro 26300, MSVC 19.44.35230.0 (VS 2022 Build Tools), RelWithDebInfo, Vulkan SDK 1.4.363.0: pass. AI-assisted (Claude Code), no game files.

  • ctest -R "^(xs_proxy_mock|device_proxy|d3d12_present|d3d12_draw|d3d12_translated_draw|d3d12_m2_textured)": 12/12 passed, and 12/12 with LEONIDA_VK_VALIDATION=1 (0 validation messages).
  • Full ctest -j 8: 270/272. The two failures are the ones main has on this card, with the same output: d3d12_vulkan_device (line 6564: tiles == 1, d3d12_vulkan_device: check PC CreateReservedResource2 behind the Xbox proxy, not through slot 78 #7125) and d3d12_indirect_dispatch_count (layer 0/0, d3d12_indirect_dispatch_count_test: its compute fixture reads the root UAV at s4:s5 (D3D-448 layout) #5792).
  • Negative control: the PR's device_proxy_test.cpp and xs_proxy_mock_test.cpp built against main 3d2185263's unchanged shim fail as expected. The override checks for slots 86, 101 and 108 fail, slot 86 creates no PSO, slot 101 doesn't null its output, and slot 108 reaches forwarded.
  • Code read: I found no blocking defect. is_device_proxy reads only the first word of its argument, and in the C-ABI order that is the caller's return buffer, which is safe. The 0x1FF flag mask matches SDK 10.0.26100's last PC flag (RAYTRACING_ACCELERATION_STRUCTURE = 0x100). sizeof(D3D12_RESOURCE_DESC) is 56 on x64, which fits the 56-byte stride. One small point that isn't a blocker: slot 108 passes a null descriptor array to the PC call when count > 0 but pResourceDescs is null, where refusing with {UINT64_MAX, 0} the way the other bad-input paths do would be safer.

@Jadiac5

Jadiac5 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 8e76568 on Windows 11, AMD Radeon RX 9070 XT (RDNA4), driver 32.0.32029.2010: pass

  • MSVC 19.44 (VS 2022 Build Tools), Ninja, RelWithDebInfo. Built xs_proxy_mock_test, device_proxy_test, d3d12_present_test, d3d12_draw_test, d3d12_translated_draw_test and d3d12_m2_textured_test.
  • ctest -R "^(xs_proxy_mock|device_proxy|d3d12_present|d3d12_draw|d3d12_translated_draw|d3d12_m2_textured)": 12/12 pass with LEONIDA_VK_VALIDATION=0 and 12/12 with =1 (this includes the six xs_proxy_mock* cases, device_proxy, device_proxy_trace, and the 1025-descriptor slot 108 check).
  • Negative control: runtime/shims/d3d12_xs_device.cpp and .h put back to the merge base (d239fd8), tests kept. xs_proxy_mock fails at xs_proxy_mock_test.cpp:411 (slot 86 is E_NOTIMPL, not forwarded to PC slot 47) and device_proxy crashes (SEGFAULT). Both pass again with the PR's files.
  • The AMD run in the thread (RX 6700 XT) names 6ef716f71, which is not a commit of this PR. This run is on the current head, the first on this exact head with an AMD card.
  • Not done: slot 86/101/108 against the retail boot (needs the game). Not run against the retail executable.

AI-assisted (Claude Code).

@Zunraz

Zunraz commented Nov 23, 2026

Copy link
Copy Markdown

Independent native Windows integration of 8e765684ce6a4c9a8c511d0662ec939c4b50e850 into the RT-5 startup stack (main 8575d36ed plus #4313/#6919/#4348/#6991, #6964/#7037/#7076/#6953, #7218 310773a01, #7021/#7066/#7078/#7110 with its integer-layout compile fix, and RT-488 cache change):

Windows build 26300, RTX 5090 / 32.0.16.2124, clang-cl 21.1.8 + xwin SDK 10.0.26100, static CRT. Validation unavailable. Retail socket creation/DNS/transmission debugger-guarded. No game data, raw trace or title offsets attached. AI-assisted (Codex).

@Zunraz

Zunraz commented Nov 23, 2026

Copy link
Copy Markdown

Additional retail coverage for the earlier integration report: after #7330/#7163/#7115 and the provisional slot-74 handler #7323, device slot 86 is now reached. With 10 locally translated executable-embedded shader programs added to the 52 builder programs, six ID3D12Device2::CreatePipelineState calls succeed through that route. Before supplying those 10 programs the same six calls failed for a missing translated vertex shader; this was a local library setup issue.

The next stop is the unimplemented XGSuggestSwizzleMode import (1,666 traced D3D12 calls), still no frame/menu. This adds retail coverage of slot 86 only; it does not establish that retail exercised 101 or 108. Eight combined proxy mock modes pass after the slot-74 addition. No shader data shared.

Windows 11 build 26300, RTX 5090 / driver 32.0.16.2124, clang-cl 21.1.8 + xwin SDK 10.0.26100, static CRT, Vulkan backend. Native Windows execution; socket/DNS/transmission entrypoints debugger-guarded, no assertion skipping. No Vulkan validation layer available. Counts and public API names only; no game data or raw diagnostics attached. AI-assisted (Codex).

@myokex

myokex commented Nov 23, 2026

Copy link
Copy Markdown

Tested 8e765684c on Windows 11, AMD Radeon RX 7800 XT (RDNA3, driver 32.0.32029.2010), MSVC 2022 RelWithDebInfo, CMake 4.4.4, Vulkan SDK 1.4.363.0; merged alone onto main 042c5f378, full ctest -j8; synthetic, no game files: pass. device_proxy, device_proxy_trace, xs_proxy_mock and its five variants pass. The failures main itself has on this card (d3d12_vulkan_device, d3d12_texture_tiles, d3d12_indirect_dispatch_count, d3d12_pipeline_library_host, and vk_queue_query_sync in most runs; see #166) are unchanged. d3d12_bindless_churn failed once in this run; it is a flake under parallel ctest -j8 on this card (it fails with unrelated PRs too, and passes 10/10 alone on main), not this PR. AI-assisted (Claude Code).

@Hiiva

Hiiva commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Review finding at 8e765684ce6a4c9a8c511d0662ec939c4b50e850: slots 86, 101 and 108 must call the interface returned by QueryInterface.

create_device_proxy stores the original ID3D12Device* and vtable. detect_slot_count queries newer interfaces only to test support, then releases them. The new handlers nevertheless index slots 47, 62 and 68 on the original pointer.

Wholly synthetic native MSVC 19.44 / SDK 10.0.26100 diagnostic: one COM identity exposes the base device at one pointer and Device2/5/8 at another. Direct calls through the queried pointer pass. The proxy detects 73 slots, but all three calls reach the base receiver: base counts 1,1,1, queried-interface counts 0,0,0. The base table has counting padding, so this reports the wrong receiver without crashing. The existing nine combined proxy/WARP tests pass and do not cover this case.

The narrow correction is to acquire Device2, Device5 or Device8 for the respective call, call through that returned interface, and balance its reference. I am preparing that follow-up with the distinct-interface regression. Synthetic fixtures only; no game files or GPU execution.

@Yoshi-OOF

Copy link
Copy Markdown

Independent retail check on Windows 11 x64 (build 26300), MSVC 19.44, RTX 5070 Ti / 621.24, with a local integration of existing boot patches. Before adapting slot 108, the first Xbox C-ABI call fell through to the generic forwarder and faulted. After routing it to Device8's allocation-info method with the 56-byte descriptor stride, both observed calls succeeded and startup continued to CLZERO on the Intel CPU. With the existing CPU emulation integrated separately, the boot then submitted a command list and returned success from its first PresentX. This checks the ABI fix, not rendered content or the complete PR in isolation. No game data or traces attached. AI-assisted: yes.

tibzejoker added a commit to tibzejoker/Leonida that referenced this pull request Nov 23, 2026
Slots 86/101/108 handlers, names, checks and chain entries added beside the existing ones.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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.