From e7b32cd9196611bd0eb606fe9c57e31cf9eead36 Mon Sep 17 00:00:00 2001 From: andretuta Date: Tue, 24 Nov 2026 00:53:30 -0300 Subject: [PATCH 1/4] d3d12_xs_device: handle Xbox struct-return ABI (slots 25/26/58), slot 48 desc sanitize and slot 73 IID fallback (RT-XS-DEVICE-STOPS-7-9) --- runtime/shims/d3d12_xs_device.cpp | 100 +++++++++++++++++++++++++--- runtime/shims/d3d12_xs_device.h | 8 +-- runtime/test/xs_proxy_mock_test.cpp | 81 +++++++++++++++++++++- 3 files changed, 176 insertions(+), 13 deletions(-) diff --git a/runtime/shims/d3d12_xs_device.cpp b/runtime/shims/d3d12_xs_device.cpp index 1045b86fb9..b7085a2ece 100644 --- a/runtime/shims/d3d12_xs_device.cpp +++ b/runtime/shims/d3d12_xs_device.cpp @@ -134,7 +134,9 @@ const char* slot_name(unsigned slot) { case 14: return "CreateDescriptorHeap"; case 16: return "CreateRootSignature"; case 25: return "GetResourceAllocationInfo"; + case 26: return "GetCustomHeapProperties"; case 27: return "CreateCommittedResource (PC slot 27)"; + case 58: return "GetResourceAllocationInfo1"; case 31: return "CreateSharedHandle (proxies unwrapped)"; case 32: return "OpenSharedHandle (a fence comes back wrapped)"; case 34: return "MakeResident (proxies unwrapped)"; @@ -1438,8 +1440,21 @@ HRESULT proxy_create_command_list_x(DeviceProxy* self, std::uint64_t desc_word, if (!allocator) allocator = reinterpret_cast(allocator_word); auto* initial_state = reinterpret_cast(initial_state_word); void* created = nullptr; - const HRESULT hr = self->real->CreateCommandList(0, type, allocator, initial_state, - *riid, &created); + const IID pc_list_iid = __uuidof(ID3D12GraphicsCommandList); + HRESULT hr = self->real->CreateCommandList(0, type, allocator, initial_state, *riid, &created); + if (hr == E_NOINTERFACE) { + // Console command-list IIDs are not exposed by PC/Vulkan devices (docs/retail_boot_chain.md §3.3); fall back + // to the base PC graphics command list and wrap it in the console list proxy. + static std::atomic iid_fallback_logged{false}; + if (first_call(iid_fallback_logged)) { + std::fprintf(stderr, + "[rt] d3d12_xs: slot 73 CreateCommandListX: console list IID rejected with E_NOINTERFACE; " + "falling back to ID3D12GraphicsCommandList\n"); + } + hr = self->real->CreateCommandList(0, type, allocator, initial_state, pc_list_iid, &created); + if (FAILED(hr)) return hr; + return wrap_list(static_cast(created), self, &pc_list_iid, out); + } if (FAILED(hr)) return hr; return wrap_list(static_cast(created), self, riid, out); } @@ -1817,6 +1832,38 @@ HRESULT proxy_create_placed_resource_x(DeviceProxy* self, void* va, const D3D12_ return handler(self->real, va, pc_desc, state, *riid, out); } +void** get_vtable(); + +// Xbox device slot 48 (CreateCommandQueueX): console queue descriptions can carry extra Xbox flag bits, non-PC +// priority words or node masks past 1 (docs/retail_boot_chain.md §3.2). Clean PC descriptions are passed through +// unchanged so callers and tests observe the original pointer; console-extended ones are sanitized into a PC copy. +HRESULT proxy_create_command_queue_x(DeviceProxy* self, const D3D12_COMMAND_QUEUE_DESC* raw, const IID* riid, + void** out) { + if (!raw) return proxy_create_command_queue(self, nullptr, riid, out); + const auto raw_flags = static_cast(raw->Flags); + const auto pc_flags = static_cast( + raw_flags & static_cast(D3D12_COMMAND_QUEUE_FLAG_DISABLE_GPU_TIMEOUT)); + const bool valid_priority = raw->Priority == D3D12_COMMAND_QUEUE_PRIORITY_NORMAL || + raw->Priority == D3D12_COMMAND_QUEUE_PRIORITY_HIGH || + raw->Priority == D3D12_COMMAND_QUEUE_PRIORITY_GLOBAL_REALTIME; + const bool needs_sanitize = (pc_flags != raw->Flags) || !valid_priority || raw->NodeMask > 1; + if (!needs_sanitize) return proxy_create_command_queue(self, raw, riid, out); + + D3D12_COMMAND_QUEUE_DESC sanitized = *raw; + sanitized.Flags = pc_flags; + if (!valid_priority) sanitized.Priority = D3D12_COMMAND_QUEUE_PRIORITY_NORMAL; + if (sanitized.NodeMask > 1) sanitized.NodeMask = 0; + static std::atomic logged{false}; + if (first_call(logged)) { + std::fprintf(stderr, + "[rt] d3d12_xs: slot 48 CreateCommandQueueX sanitized console desc " + "(type=%d priority=%d->%d flags=0x%x->0x%x node=%u->%u)\n", + static_cast(raw->Type), raw->Priority, sanitized.Priority, raw_flags, + static_cast(sanitized.Flags), raw->NodeMask, sanitized.NodeMask); + } + return proxy_create_command_queue(self, &sanitized, riid, out); +} + template std::uint64_t WINAPI proxy_slot(DeviceProxy* self, std::uint64_t a1, std::uint64_t a2, std::uint64_t a3, std::uint64_t a4, std::uint64_t a5, std::uint64_t a6, std::uint64_t a7, @@ -1829,6 +1876,43 @@ std::uint64_t WINAPI proxy_slot(DeviceProxy* self, std::uint64_t a1, std::uint64 return proxy_add_ref(self); } else if constexpr (Slot == 2) { return proxy_release(self); + } else if constexpr (Slot == 25 || Slot == 26 || Slot == 58) { + // Struct-returning device methods (docs/retail_boot_chain.md §3.1): Xbox callers pass + // (return_buffer, this, ...) in RCX/RDX, whereas PC MSVC expects (this, return_buffer, ...). Detect the + // swapped form by checking which of the first two registers holds the device proxy vtable. + DeviceProxy* proxy = self; + std::uint64_t ret_buf = a1; + void** const expected_vtbl = get_vtable(); + if (!readable_range(proxy, sizeof(void*)) || proxy->vtable != expected_vtbl) { + auto* candidate = reinterpret_cast(a1); + if (readable_range(candidate, sizeof(void*)) && candidate->vtable == expected_vtbl) { + ret_buf = reinterpret_cast(self); + proxy = candidate; + static std::atomic swap_logged[3]; + const unsigned idx = Slot == 25 ? 0u : (Slot == 26 ? 1u : 2u); + if (first_call(swap_logged[idx])) { + std::fprintf(stderr, + "[rt] d3d12_xs: device slot %u (%s) swapped (return_buffer, this) -> PC ABI\n", + Slot, slot_name(Slot)); + } + } + } + note_slot(Slot); + if (!proxy || Slot >= proxy->slot_count) { + if (proxy) refuse_beyond_device(Slot, proxy->slot_count); + return ret_buf; + } + if constexpr (Slot == 26) { + using Fn4 = std::uint64_t(WINAPI*)(void*, std::uint64_t, std::uint64_t, std::uint64_t); + return reinterpret_cast(proxy->real_vtable[26])(proxy->real, ret_buf, a2, a3); + } else if constexpr (Slot == 25) { + using Fn5 = std::uint64_t(WINAPI*)(void*, std::uint64_t, std::uint64_t, std::uint64_t, std::uint64_t); + return reinterpret_cast(proxy->real_vtable[25])(proxy->real, ret_buf, a2, a3, a4); + } else { + using Fn6 = std::uint64_t(WINAPI*)(void*, std::uint64_t, std::uint64_t, std::uint64_t, std::uint64_t, + std::uint64_t); + return reinterpret_cast(proxy->real_vtable[58])(proxy->real, ret_buf, a2, a3, a4, a5); + } } else if constexpr (Slot == 8) { return hr_to_u64(proxy_create_command_queue(self, reinterpret_cast(a1), reinterpret_cast(a2), reinterpret_cast(a3))); @@ -1903,9 +1987,9 @@ std::uint64_t WINAPI proxy_slot(DeviceProxy* self, std::uint64_t a1, std::uint64 } if (Slot == routes.queue_x) { log_xbox_route_once(Slot, "CreateCommandQueueX", a1, a2, a3, a4, a5); - return hr_to_u64(proxy_create_command_queue(self, reinterpret_cast(a1), - reinterpret_cast(a2), - reinterpret_cast(a3))); + return hr_to_u64(proxy_create_command_queue_x(self, reinterpret_cast(a1), + reinterpret_cast(a2), + reinterpret_cast(a3))); } if (Slot == routes.list_x) { log_xbox_route_once(Slot, "CreateCommandListX", a1, a2, a3, a4, a5); @@ -2070,9 +2154,9 @@ ID3D12Device* device_proxy_real_device(const void* device) { } bool device_slot_overridden(unsigned slot) { - if (slot <= 2 || slot == 8 || slot == 9 || slot == 14 || slot == 31 || slot == 32 || slot == 34 || slot == 35 || - slot == 36 || slot == 45 || slot == 46 || slot == 50 || slot == 62 || slot == 67 || - slot == 75 || slot == 76 || slot == 133) + if (slot <= 2 || slot == 8 || slot == 9 || slot == 14 || slot == 25 || slot == 26 || slot == 31 || slot == 32 || + slot == 34 || slot == 35 || slot == 36 || slot == 45 || slot == 46 || slot == 50 || slot == 58 || + slot == 62 || slot == 67 || slot == 75 || slot == 76 || slot == 133) return true; const XboxDeviceSlotRoutes& routes = xbox_device_slot_routes(); return slot == routes.frame_interval || slot == routes.schedule_event || slot == routes.wait_event || diff --git a/runtime/shims/d3d12_xs_device.h b/runtime/shims/d3d12_xs_device.h index 20ed4afc15..3db992657b 100644 --- a/runtime/shims/d3d12_xs_device.h +++ b/runtime/shims/d3d12_xs_device.h @@ -118,10 +118,10 @@ using ConsoleDescriptorHeapHandler = HRESULT (*)(ID3D12Device* real, const D3D12 void set_console_descriptor_heap_handler(ConsoleDescriptorHeapHandler handler); // True for slots the proxy handles itself rather than forwarding verbatim: IUnknown (0-2), 8 and 75 (queue -// proxies), 9 (allocator proxies), 14, 31/34/35/45/46/50 (proxies unwrapped), 32 and 36 (fence proxies), 48/73 and -// 78/79/80 (the Xbox slots above, at their configured indices), 62, 67 and 76. Slot 10 is intentionally false: the -// measured 9/10 handle conversion is on the heap proxy, and device slot 9 is CreateCommandAllocator, which the proxy -// handles for the allocator proxy. +// proxies), 9 (allocator proxies), 14, 25/26/58 (struct-returning ABI swap), 31/34/35/45/46/50 (proxies unwrapped), +// 32 and 36 (fence proxies), 48/73 and 78/79/80 (the Xbox slots above, at their configured indices), 62, 67, 76 and +// 133. Slot 10 is intentionally false: the measured 9/10 handle conversion is on the heap proxy, and device slot 9 +// is CreateCommandAllocator, which the proxy handles for the allocator proxy. bool device_slot_overridden(unsigned slot); // Queue and fence proxies created by device slots 8/75 and 36. The real_* accessors return the wrapped object diff --git a/runtime/test/xs_proxy_mock_test.cpp b/runtime/test/xs_proxy_mock_test.cpp index 6af7ad8046..fd280adc88 100644 --- a/runtime/test/xs_proxy_mock_test.cpp +++ b/runtime/test/xs_proxy_mock_test.cpp @@ -208,6 +208,7 @@ std::uint64_t mock_call(Mock* m, unsigned slot, const std::uint64_t* words) { if (a1 == kFenceHandle) return static_cast(mock_create(m, Kind::fence, a2, a3)); if (a1 == kResourceHandle) return static_cast(mock_create(m, Kind::resource, a2, a3)); return static_cast(E_INVALIDARG); + case 25: case 26: case 58: return a1; // struct-returning PC methods return their hidden buffer pointer case 34: case 35: case 46: copy_array(m, slot, a2, a1); break; // (count, objects, ...) case 45: copy_array(m, slot, a1, a3); break; // (fences, values, count, ...) case 50: copy_array(m, slot, a3, a2); break; // (flags, count, objects, fence, value) @@ -1239,6 +1240,83 @@ int check_console_command_list() { return 0; } +// ---- 11. Retail boot stops 7–9: struct-returning ABI swap (25/26/58), slot 48 desc sanitization, slot 73 IID fallback ---- + +int check_boot_stops_7_9() { + Mock* mock = nullptr; + void* device = make_device(mock, 11, true); + EXPECT(device != nullptr); + xs::reset_device_proxy_stats(); + + EXPECT(xs::device_slot_overridden(25) && xs::device_slot_overridden(26) && xs::device_slot_overridden(58)); + + // Stop 7: slots 25, 26, and 58 accept both PC (this, ret_buf, ...) and Xbox swapped (ret_buf, this, ...) order. + D3D12_HEAP_PROPERTIES heap_out{}; + D3D12_RESOURCE_ALLOCATION_INFO alloc_out{}; + D3D12_RESOURCE_ALLOCATION_INFO1 alloc1_out{}; + using Raw4 = std::uint64_t(WINAPI*)(std::uint64_t, std::uint64_t, std::uint64_t, std::uint64_t); + using Raw5 = std::uint64_t(WINAPI*)(std::uint64_t, std::uint64_t, std::uint64_t, std::uint64_t, std::uint64_t); + using Raw6 = std::uint64_t(WINAPI*)(std::uint64_t, std::uint64_t, std::uint64_t, std::uint64_t, std::uint64_t, + std::uint64_t); + void** const vtbl = *static_cast(device); + + // PC order on slot 26: (device, &heap_out, node_mask, heap_type) + EXPECT(reinterpret_cast(vtbl[26])(word(device), word(&heap_out), 1, D3D12_HEAP_TYPE_DEFAULT) == + word(&heap_out)); + EXPECT(mock->calls[26] == 1 && mock->args[26][0] == word(&heap_out) && mock->args[26][1] == 1 && + mock->args[26][2] == static_cast(D3D12_HEAP_TYPE_DEFAULT)); + + // Xbox swapped order on slot 26: (&heap_out, device, node_mask, heap_type) + EXPECT(reinterpret_cast(vtbl[26])(word(&heap_out), word(device), 0, D3D12_HEAP_TYPE_UPLOAD) == + word(&heap_out)); + EXPECT(mock->calls[26] == 2 && mock->args[26][0] == word(&heap_out) && mock->args[26][1] == 0 && + mock->args[26][2] == static_cast(D3D12_HEAP_TYPE_UPLOAD)); + + // Xbox swapped order on slot 25: (&alloc_out, device, visible_mask, count, descs) + EXPECT(reinterpret_cast(vtbl[25])(word(&alloc_out), word(device), 0, 1, 0x1234) == word(&alloc_out)); + EXPECT(mock->calls[25] == 1 && mock->args[25][0] == word(&alloc_out) && mock->args[25][1] == 0 && + mock->args[25][2] == 1 && mock->args[25][3] == 0x1234); + + // Xbox swapped order on slot 58: (&alloc_out, device, visible_mask, count, descs, &alloc1_out) + EXPECT(reinterpret_cast(vtbl[58])(word(&alloc_out), word(device), 1, 2, 0x5678, word(&alloc1_out)) == + word(&alloc_out)); + EXPECT(mock->calls[58] == 1 && mock->args[58][0] == word(&alloc_out) && mock->args[58][1] == 1 && + mock->args[58][2] == 2 && mock->args[58][3] == 0x5678 && mock->args[58][4] == word(&alloc1_out)); + + // Stop 8: slot 48 sanitizes Xbox flags, non-PC priority, and NodeMask > 1 into a valid PC queue desc. + D3D12_COMMAND_QUEUE_DESC console_qdesc{}; + console_qdesc.Type = D3D12_COMMAND_LIST_TYPE_COMPUTE; + console_qdesc.Priority = 0x1234; // non-PC priority word + console_qdesc.Flags = static_cast(0x80000001u); // extra console bit + DISABLE_GPU_TIMEOUT + console_qdesc.NodeMask = 7; + void* queue = nullptr; + const IID queue_iid = __uuidof(ID3D12CommandQueue); + EXPECT(hr_of(raw(device, 48, word(&console_qdesc), word(&queue_iid), word(&queue))) == S_OK); + EXPECT(xs::is_queue_proxy(queue) && mock->calls[8] == 1 && mock->args[8][0] != word(&console_qdesc)); + EXPECT(release(queue) == 0); + + // Stop 9: slot 73 falls back to ID3D12GraphicsCommandList when the real device refuses a console command-list IID. + void* allocator = nullptr; + const IID alloc_iid = __uuidof(ID3D12CommandAllocator); + EXPECT(hr_of(raw(device, 9, 0, word(&alloc_iid), word(&allocator))) == S_OK); + struct { + std::uint32_t type, reserved; + } list_desc{static_cast(D3D12_COMMAND_LIST_TYPE_DIRECT), 0}; + // Synthetic console-only IID unknown to the mock device (distinct from any PC IID). + const IID synthetic_console_list_iid{0x22222222, 0x3333, 0x4444, {0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc}}; + void* list_proxy = nullptr; + EXPECT(hr_of(raw(device, 73, word(&list_desc), word(allocator), 0, word(&synthetic_console_list_iid), + word(&list_proxy))) == S_OK); + EXPECT(xs::is_command_list_proxy(list_proxy)); + EXPECT(mock->calls[12] == 2); // first attempt returned E_NOINTERFACE, fallback succeeded with ID3D12GraphicsCommandList + EXPECT(release(list_proxy) == 0); + EXPECT(release(allocator) == 0); + EXPECT(release(device) == 0 && mock->refs == 0); + + std::printf("%s: stops 7-9 (struct-return swap 25/26/58, slot 48 sanitize, slot 73 IID fallback) passed\n", g_label); + return 0; +} + int main(int argc, char** argv) { no_dialogs(); std::setvbuf(stdout, nullptr, _IONBF, 0); @@ -1249,7 +1327,8 @@ int main(int argc, char** argv) { } if (argc != 1) return 2; if (check_tail(true) || check_levels() || check_fence1() || check_create_failures() || check_open_shared() || - check_alloc_failures() || check_allocators() || check_xbox_slots() || check_console_command_list()) + check_alloc_failures() || check_allocators() || check_xbox_slots() || check_console_command_list() || + check_boot_stops_7_9()) return 1; std::printf("xs_proxy_mock_test: PASS (%d allocations refused on purpose)\n", g_failed_news); return 0; From f423c904624add9a6254ff97bc32feb1d42d44c3 Mon Sep 17 00:00:00 2001 From: andretuta Date: Tue, 24 Nov 2026 03:03:10 -0300 Subject: [PATCH 2/4] d3d12_xs_device: slot 73 retries a console list IID as ID3D12GraphicsCommandList Reduced to what main does not already have: slots 25/26 (struct return) and 48 (queue desc sanitize) landed on main, and the slot 58 forwarder is dropped (PC vtable slot 58 is ID3D12Device5::RemoveDevice, not GetResourceAllocationInfo1, and no call to Xbox slot 58 is measured). CreateCommandListX passes the title's console command-list IID, which the PC device does not know (docs/retail_boot_chain.md 3.3). On E_NOINTERFACE for an IID that is not a PC list IID, create the list once more as ID3D12GraphicsCommandList and hand out the console list proxy. A PC list IID the device refuses still fails as before. AI-assisted. Tested: xs_proxy_mock_test new checks with clang 23 / mingw x64 (a pre-existing kLong allocation-injection check does not fire under mingw, so the full run needs MSVC/CI). Co-Authored-By: Claude Opus 5.5 --- runtime/shims/d3d12_xs_device.cpp | 16 ++++++++++++++-- runtime/test/xs_proxy_mock_test.cpp | 23 +++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/runtime/shims/d3d12_xs_device.cpp b/runtime/shims/d3d12_xs_device.cpp index 7f7040fdd9..64aa8a9f80 100644 --- a/runtime/shims/d3d12_xs_device.cpp +++ b/runtime/shims/d3d12_xs_device.cpp @@ -1442,8 +1442,20 @@ HRESULT proxy_create_command_list_x(DeviceProxy* self, std::uint64_t desc_word, if (!allocator) allocator = reinterpret_cast(allocator_word); auto* initial_state = reinterpret_cast(initial_state_word); void* created = nullptr; - const HRESULT hr = self->real->CreateCommandList(0, type, allocator, initial_state, - *riid, &created); + HRESULT hr = self->real->CreateCommandList(0, type, allocator, initial_state, *riid, &created); + // The console list IID is not in the PC SDK, so the PC device rejects it (docs/retail_boot_chain.md §3.3). + // Retry once with the PC list IID and wrap the list under that IID. + if (hr == E_NOINTERFACE && !is_list_iid(*riid)) { + static std::atomic retried{false}; + if (first_call(retried)) + std::fprintf(stderr, "[rt] d3d12_xs: slot 73 console list IID not known to the PC device; retrying as " + "ID3D12GraphicsCommandList\n"); + const IID pc_iid = __uuidof(ID3D12GraphicsCommandList); + created = nullptr; + hr = self->real->CreateCommandList(0, type, allocator, initial_state, pc_iid, &created); + if (FAILED(hr)) return hr; + return wrap_list(static_cast(created), self, &pc_iid, out); + } if (FAILED(hr)) return hr; return wrap_list(static_cast(created), self, riid, out); } diff --git a/runtime/test/xs_proxy_mock_test.cpp b/runtime/test/xs_proxy_mock_test.cpp index 224030247c..ff445ee7dc 100644 --- a/runtime/test/xs_proxy_mock_test.cpp +++ b/runtime/test/xs_proxy_mock_test.cpp @@ -91,6 +91,8 @@ struct Mock { bool allocator_tag; // allocator: answers kLeonidaCommandAllocatorTag; device: the allocators it makes do bool create_null; // device: creation returns create_result with no object HRESULT create_result; // device: what creation returns (S_OK makes the object) + bool list_refuse; // device: CreateCommandList refuses every riid with E_NOINTERFACE + IID create_riid; // device: copy of the riid its last CreateCommandList got (the caller's may be a local) Mock* last_child; // device: the object its last creation or open made unsigned calls[kMockSlots]; std::uint64_t args[kMockSlots][5]; @@ -276,8 +278,10 @@ HRESULT WINAPI mock_create_command_list(Mock* self, std::uint64_t node_mask, std self->args[12][2] = allocator; self->args[12][3] = initial_state; self->args[12][4] = reinterpret_cast(riid); + if (riid) self->create_riid = *riid; if (!out) return S_FALSE; *out = nullptr; + if (self->list_refuse) return E_NOINTERFACE; if (self->create_null || FAILED(self->create_result)) return self->create_result; Mock* child = new_mock(Kind::command_list); child->list_level = self->list_level; @@ -1504,6 +1508,25 @@ int check_console_command_list() { EXPECT(real_queue->array[10][0] == word(unwrapped_list)); EXPECT(real_queue->array[10][1] == word(real_list)); + // 5b. A console list IID the PC device does not know (docs/retail_boot_chain.md §3.3): E_NOINTERFACE from the PC + // device, then one retry as ID3D12GraphicsCommandList, which succeeds and wraps the list under that IID. + const IID console_iid = {0x12345678, 0x1234, 0x1234, {1, 2, 3, 4, 5, 6, 7, 8}}; + const unsigned calls12_before = mock_device->calls[12]; + void* console_list = nullptr; + EXPECT(hr_of(raw(device, 73, word(&desc), word(allocator), 0, word(&console_iid), word(&console_list))) == S_OK); + EXPECT(xs::is_command_list_proxy(console_list) && mock_device->calls[12] == calls12_before + 2); + EXPECT(IsEqualIID(mock_device->create_riid, __uuidof(ID3D12GraphicsCommandList))); + EXPECT(release(console_list) == 0); + + // The PC device refuses even ID3D12GraphicsCommandList for a PC IID: E_NOINTERFACE comes back as is, no retry. + mock_device->list_refuse = true; + const unsigned calls12_refused = mock_device->calls[12]; + console_list = nullptr; + EXPECT(hr_of(raw(device, 73, word(&desc), word(allocator), 0, word(&list_iid), word(&console_list))) == + E_NOINTERFACE); + EXPECT(!console_list && mock_device->calls[12] == calls12_refused + 1); + mock_device->list_refuse = false; + // 6. Test with list_level = 7 (supporting ID3D12GraphicsCommandList7, 81 slots) mock_device->list_level = 7; void* list7_proxy = nullptr; From d52ab6b5b3e77007e9811b494d93d618460a31c0 Mon Sep 17 00:00:00 2001 From: andretuta Date: Tue, 24 Nov 2026 08:15:02 -0300 Subject: [PATCH 3/4] d3d12_xs_device: map only the measured console list IID at slot 73 The slot 73 fallback retried every IID the PC device refused, so asking for a public list revision the backend lacks (ID3D12GraphicsCommandList9 on a revision-8 device) returned S_OK and a base list instead of E_NOINTERFACE (review on #359). Only the console ID3D12GraphicsCommandListX IID {c3827890-4024-474c-98cf-645b51dc4874} (#445) is now created as ID3D12GraphicsCommandList, in one call, and the list proxy answers QueryInterface for it. Every other IID reaches the device unchanged. Tested: xs_proxy_mock (List9 and an unknown IID keep E_NOINTERFACE with a null output; the console IID is created once and is queryable) and d3d12_vulkan_device with MSVC 14.44 / SDK 10.0.26100; docs tests. Co-Authored-By: Claude Opus 5.5 --- docs/retail_boot_chain.md | 2 +- runtime/shims/d3d12_xs_device.cpp | 27 +++++++++++---------------- runtime/test/xs_proxy_mock_test.cpp | 22 ++++++++++++++++++---- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/docs/retail_boot_chain.md b/docs/retail_boot_chain.md index cbe29cf831..fd07905be9 100644 --- a/docs/retail_boot_chain.md +++ b/docs/retail_boot_chain.md @@ -79,7 +79,7 @@ queues come from this slot, the first of them a compute queue. The first queue c Xbox device slot 73 is `(desc, allocator, pso, riid, out)`. `desc` is 16 bytes and its first word reads as the `D3D12_COMMAND_LIST_TYPE`. `riid` is a console command-list IID that is not in the PC SDK (#3520 records that the -package doesn't export it). The shim's unknown-IID log names it on the player's machine. Creating an +package doesn't export it). A retail run logged it as `{c3827890-4024-474c-98cf-645b51dc4874}` (#445). Creating an `ID3D12GraphicsCommandList` of that type and handing out #2490's console list proxy gets all 581 lists created and closed. diff --git a/runtime/shims/d3d12_xs_device.cpp b/runtime/shims/d3d12_xs_device.cpp index 64aa8a9f80..dfe22d9897 100644 --- a/runtime/shims/d3d12_xs_device.cpp +++ b/runtime/shims/d3d12_xs_device.cpp @@ -983,6 +983,9 @@ inline void note_list_slot(unsigned slot, std::uint64_t a1 = 0, std::uint64_t a2 static_cast(a3), static_cast(a4)); } +// The console ID3D12GraphicsCommandListX IID the title passes to slot 73 (docs/retail_boot_chain.md §3.3). +constexpr IID kXboxGraphicsCommandListX = {0xc3827890, 0x4024, 0x474c, {0x98, 0xcf, 0x64, 0x5b, 0x51, 0xdc, 0x48, 0x74}}; + inline bool is_list_iid(const IID& iid) { return IsEqualIID(iid, __uuidof(IUnknown)) || IsEqualIID(iid, __uuidof(ID3D12Object)) || IsEqualIID(iid, __uuidof(ID3D12DeviceChild)) || IsEqualIID(iid, __uuidof(ID3D12CommandList)) || @@ -1018,11 +1021,12 @@ inline HRESULT list_query_interface(ListProxy* self, const IID* riid, void** out if (!out) return E_POINTER; *out = nullptr; if (!riid) return E_POINTER; - if (!is_list_iid(*riid)) { + const IID& pc_iid = IsEqualIID(*riid, kXboxGraphicsCommandListX) ? __uuidof(ID3D12GraphicsCommandList) : *riid; + if (!is_list_iid(pc_iid)) { if (supports_iid(self->real, *riid)) log_refused_iid("list", *riid); return E_NOINTERFACE; } - if (!supports_iid(self->real, *riid)) return E_NOINTERFACE; + if (!supports_iid(self->real, pc_iid)) return E_NOINTERFACE; *out = self; list_add_ref(self); return S_OK; @@ -1442,20 +1446,11 @@ HRESULT proxy_create_command_list_x(DeviceProxy* self, std::uint64_t desc_word, if (!allocator) allocator = reinterpret_cast(allocator_word); auto* initial_state = reinterpret_cast(initial_state_word); void* created = nullptr; - HRESULT hr = self->real->CreateCommandList(0, type, allocator, initial_state, *riid, &created); - // The console list IID is not in the PC SDK, so the PC device rejects it (docs/retail_boot_chain.md §3.3). - // Retry once with the PC list IID and wrap the list under that IID. - if (hr == E_NOINTERFACE && !is_list_iid(*riid)) { - static std::atomic retried{false}; - if (first_call(retried)) - std::fprintf(stderr, "[rt] d3d12_xs: slot 73 console list IID not known to the PC device; retrying as " - "ID3D12GraphicsCommandList\n"); - const IID pc_iid = __uuidof(ID3D12GraphicsCommandList); - created = nullptr; - hr = self->real->CreateCommandList(0, type, allocator, initial_state, pc_iid, &created); - if (FAILED(hr)) return hr; - return wrap_list(static_cast(created), self, &pc_iid, out); - } + // The PC device does not know the console list IID: create the PC base list for it. Any other IID, including a + // public list revision the device lacks, goes through unchanged so its E_NOINTERFACE is kept. + const IID& create_iid = + IsEqualIID(*riid, kXboxGraphicsCommandListX) ? __uuidof(ID3D12GraphicsCommandList) : *riid; + const HRESULT hr = self->real->CreateCommandList(0, type, allocator, initial_state, create_iid, &created); if (FAILED(hr)) return hr; return wrap_list(static_cast(created), self, riid, out); } diff --git a/runtime/test/xs_proxy_mock_test.cpp b/runtime/test/xs_proxy_mock_test.cpp index ff445ee7dc..9235962d26 100644 --- a/runtime/test/xs_proxy_mock_test.cpp +++ b/runtime/test/xs_proxy_mock_test.cpp @@ -1508,14 +1508,28 @@ int check_console_command_list() { EXPECT(real_queue->array[10][0] == word(unwrapped_list)); EXPECT(real_queue->array[10][1] == word(real_list)); - // 5b. A console list IID the PC device does not know (docs/retail_boot_chain.md §3.3): E_NOINTERFACE from the PC - // device, then one retry as ID3D12GraphicsCommandList, which succeeds and wraps the list under that IID. - const IID console_iid = {0x12345678, 0x1234, 0x1234, {1, 2, 3, 4, 5, 6, 7, 8}}; + // 5b. Public list revisions the proxy does not model and unknown private IIDs must not trigger a retry. + // Spell out the Windows SDK's ID3D12GraphicsCommandList9 IID so this also builds with older headers. + const IID list9_iid = {0x34ed2808, 0xffe6, 0x4c2b, {0xb1, 0x1a, 0xca, 0xbd, 0x2b, 0x0c, 0x59, 0xe1}}; + const IID unknown_iid = {0x12345678, 0x1234, 0x1234, {1, 2, 3, 4, 5, 6, 7, 8}}; + for (const IID* iid : {&list9_iid, &unknown_iid}) { + const unsigned calls_before = mock_device->calls[12]; + void* unsupported_list = list_proxy; + EXPECT(hr_of(raw(device, 73, word(&desc), word(allocator), 0, word(iid), word(&unsupported_list))) == + E_NOINTERFACE); + EXPECT(!unsupported_list && mock_device->calls[12] == calls_before + 1); + } + + // The measured Xbox list IID is created as ID3D12GraphicsCommandList in one call and stays queryable on the proxy. + const IID console_iid = {0xc3827890, 0x4024, 0x474c, {0x98, 0xcf, 0x64, 0x5b, 0x51, 0xdc, 0x48, 0x74}}; const unsigned calls12_before = mock_device->calls[12]; void* console_list = nullptr; EXPECT(hr_of(raw(device, 73, word(&desc), word(allocator), 0, word(&console_iid), word(&console_list))) == S_OK); - EXPECT(xs::is_command_list_proxy(console_list) && mock_device->calls[12] == calls12_before + 2); + EXPECT(xs::is_command_list_proxy(console_list) && mock_device->calls[12] == calls12_before + 1); EXPECT(IsEqualIID(mock_device->create_riid, __uuidof(ID3D12GraphicsCommandList))); + void* console_list_qi = nullptr; + EXPECT(hr_of(raw(console_list, 0, word(&console_iid), word(&console_list_qi))) == S_OK); + EXPECT(console_list_qi == console_list && release(console_list_qi) == 1); EXPECT(release(console_list) == 0); // The PC device refuses even ID3D12GraphicsCommandList for a PC IID: E_NOINTERFACE comes back as is, no retry. From c1707025a195cf02f4beff0c218d2c645b2ba158 Mon Sep 17 00:00:00 2001 From: andretuta Date: Tue, 24 Nov 2026 09:12:44 -0300 Subject: [PATCH 4/4] d3d12_xs_device: take #445's slot 73 mapping verbatim #445 makes the same slot 73 change (map the console ID3D12GraphicsCommandListX IID to ID3D12GraphicsCommandList on creation and QueryInterface). Use its exact text in d3d12_xs_device.cpp so the two pull requests merge cleanly in either order; this one keeps the regression checks (ID3D12GraphicsCommandList9 and an unknown IID keep E_NOINTERFACE with a null output) and the docs line. Tested: xs_proxy_mock and d3d12_vulkan_device with MSVC 14.44 / SDK 10.0.26100, on this branch and on this branch merged with #445's head 386d6ac5d. Co-Authored-By: Claude Opus 5.5 --- runtime/shims/d3d12_xs_device.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/runtime/shims/d3d12_xs_device.cpp b/runtime/shims/d3d12_xs_device.cpp index dfe22d9897..d962fd10fe 100644 --- a/runtime/shims/d3d12_xs_device.cpp +++ b/runtime/shims/d3d12_xs_device.cpp @@ -983,8 +983,9 @@ inline void note_list_slot(unsigned slot, std::uint64_t a1 = 0, std::uint64_t a2 static_cast(a3), static_cast(a4)); } -// The console ID3D12GraphicsCommandListX IID the title passes to slot 73 (docs/retail_boot_chain.md §3.3). -constexpr IID kXboxGraphicsCommandListX = {0xc3827890, 0x4024, 0x474c, {0x98, 0xcf, 0x64, 0x5b, 0x51, 0xdc, 0x48, 0x74}}; +// Measured Xbox ID3D12GraphicsCommandListX IID passed to device slot 73 (CreateCommandListX). +constexpr IID kXboxGraphicsCommandListXIid = { + 0xc3827890, 0x4024, 0x474c, {0x98, 0xcf, 0x64, 0x5b, 0x51, 0xdc, 0x48, 0x74}}; inline bool is_list_iid(const IID& iid) { return IsEqualIID(iid, __uuidof(IUnknown)) || IsEqualIID(iid, __uuidof(ID3D12Object)) || @@ -997,7 +998,8 @@ inline bool is_list_iid(const IID& iid) { IsEqualIID(iid, __uuidof(ID3D12GraphicsCommandList5)) || IsEqualIID(iid, __uuidof(ID3D12GraphicsCommandList6)) || IsEqualIID(iid, __uuidof(ID3D12GraphicsCommandList7)) || - IsEqualIID(iid, __uuidof(ID3D12GraphicsCommandList8)); + IsEqualIID(iid, __uuidof(ID3D12GraphicsCommandList8)) || + IsEqualIID(iid, kXboxGraphicsCommandListXIid); } inline unsigned long list_add_ref(ListProxy* self) { return self->refs.fetch_add(1, std::memory_order_relaxed) + 1; } @@ -1021,12 +1023,14 @@ inline HRESULT list_query_interface(ListProxy* self, const IID* riid, void** out if (!out) return E_POINTER; *out = nullptr; if (!riid) return E_POINTER; - const IID& pc_iid = IsEqualIID(*riid, kXboxGraphicsCommandListX) ? __uuidof(ID3D12GraphicsCommandList) : *riid; - if (!is_list_iid(pc_iid)) { + if (!is_list_iid(*riid)) { if (supports_iid(self->real, *riid)) log_refused_iid("list", *riid); return E_NOINTERFACE; } - if (!supports_iid(self->real, pc_iid)) return E_NOINTERFACE; + const IID real_iid = IsEqualIID(*riid, kXboxGraphicsCommandListXIid) + ? __uuidof(ID3D12GraphicsCommandList) + : *riid; + if (!supports_iid(self->real, real_iid)) return E_NOINTERFACE; *out = self; list_add_ref(self); return S_OK; @@ -1446,11 +1450,11 @@ HRESULT proxy_create_command_list_x(DeviceProxy* self, std::uint64_t desc_word, if (!allocator) allocator = reinterpret_cast(allocator_word); auto* initial_state = reinterpret_cast(initial_state_word); void* created = nullptr; - // The PC device does not know the console list IID: create the PC base list for it. Any other IID, including a - // public list revision the device lacks, goes through unchanged so its E_NOINTERFACE is kept. - const IID& create_iid = - IsEqualIID(*riid, kXboxGraphicsCommandListX) ? __uuidof(ID3D12GraphicsCommandList) : *riid; - const HRESULT hr = self->real->CreateCommandList(0, type, allocator, initial_state, create_iid, &created); + const IID& create_iid = IsEqualIID(*riid, kXboxGraphicsCommandListXIid) + ? __uuidof(ID3D12GraphicsCommandList) + : *riid; + const HRESULT hr = self->real->CreateCommandList(0, type, allocator, initial_state, + create_iid, &created); if (FAILED(hr)) return hr; return wrap_list(static_cast(created), self, riid, out); }