diff --git a/runtime/shims/d3d12_xs_device.cpp b/runtime/shims/d3d12_xs_device.cpp index 187406e3d8..1e29c98957 100644 --- a/runtime/shims/d3d12_xs_device.cpp +++ b/runtime/shims/d3d12_xs_device.cpp @@ -23,6 +23,7 @@ // for a trace that disagrees. The frame-event calls answer from a per-device token counter: there is no vblank source // behind the device before a presenter exists, so WaitFrameEventX returns at once with a fresh non-zero token. #include "d3d12_xs_device.h" +#include "d3d12_com.h" // local: create_console_descriptor_heap #include "d3d12_trace.h" #include "../src/shader_library.h" // leonida::fspx_payload_from_parts for slot 67 @@ -977,6 +978,7 @@ inline void note_list_slot(unsigned slot, std::uint64_t a1 = 0, std::uint64_t a2 } inline bool is_list_iid(const IID& iid) { + if (IsEqualIID(iid, kConsoleListIID)) return true; return IsEqualIID(iid, __uuidof(IUnknown)) || IsEqualIID(iid, __uuidof(ID3D12Object)) || IsEqualIID(iid, __uuidof(ID3D12DeviceChild)) || IsEqualIID(iid, __uuidof(ID3D12CommandList)) || IsEqualIID(iid, __uuidof(ID3D12GraphicsCommandList)) || @@ -1015,7 +1017,8 @@ inline HRESULT list_query_interface(ListProxy* self, const IID* riid, void** out if (supports_iid(self->real, *riid)) log_refused_iid("list", *riid); return E_NOINTERFACE; } - if (!supports_iid(self->real, *riid)) return E_NOINTERFACE; + // No PC list answers the console interface; the proxy answers it itself. + if (!IsEqualIID(*riid, kConsoleListIID) && !supports_iid(self->real, *riid)) return E_NOINTERFACE; *out = self; list_add_ref(self); return S_OK; @@ -1361,9 +1364,27 @@ HRESULT proxy_create_command_queue(DeviceProxy* self, const D3D12_COMMAND_QUEUE_ // The caller's null output goes to the real device on purpose: its answer (S_FALSE, E_UNEXPECTED, ...) is the // one to give, although the SDK annotates the parameter as required. #pragma warning(suppress : 6387) + // The console desc starts with a PC D3D12_COMMAND_QUEUE_DESC and adds Xbox words after it + // (docs/retail_boot_chain.md 3.2). Only the PC prefix is read, and Flags is limited to the one PC flag: the + // console sets bits the PC device refuses, which made CreateCommandQueue fail and the title assert. + D3D12_COMMAND_QUEUE_DESC pc_desc{}; + if (desc) { + pc_desc = *desc; + pc_desc.Flags = static_cast(static_cast(pc_desc.Flags) & + D3D12_COMMAND_QUEUE_FLAG_DISABLE_GPU_TIMEOUT); + desc = &pc_desc; + } if (!out) return self->real->CreateCommandQueue(desc, *riid, nullptr); void* created = nullptr; const HRESULT hr = self->real->CreateCommandQueue(desc, __uuidof(ID3D12CommandQueue), &created); + { + static std::atomic logged{false}; + if (first_call(logged) || FAILED(hr)) + std::fprintf(stderr, + "[rt] queue: type=%d priority=%d flags=0x%x node=%u -> hr=0x%08lx\n", + static_cast(pc_desc.Type), pc_desc.Priority, static_cast(pc_desc.Flags), + pc_desc.NodeMask, static_cast(hr)); + } if (FAILED(hr)) return hr; return wrap_child(static_cast(created), self, riid, out); } @@ -1435,8 +1456,13 @@ 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); + // The layer (and any PC device behind the proxy) only knows the PC list interfaces. Hand a requested PC + // interface on as asked; for anything else (the title's own console list interface) create the base PC list and + // let wrap_list answer the requested IID with the proxy. Passing the console IID down made CreateCommandList + // answer E_NOINTERFACE, so every list came back null and the title read through it. + const IID pc_base = __uuidof(ID3D12GraphicsCommandList); + const IID* create_iid = supports_iid(self->real, *riid) ? riid : &pc_base; + 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/shims/d3d12_xs_device.h b/runtime/shims/d3d12_xs_device.h index ac0437215d..07d8a27fe7 100644 --- a/runtime/shims/d3d12_xs_device.h +++ b/runtime/shims/d3d12_xs_device.h @@ -150,6 +150,10 @@ bool command_object_tables_guarded(); // {7d0e6b51-34a2-4f0c-9a61-0c5b2e8f4a10}: the Vulkan layer's CommandAllocator answers it with its implementation. inline constexpr GUID kLeonidaCommandAllocatorTag{ 0x7d0e6b51, 0x34a2, 0x4f0c, {0x9a, 0x61, 0x0c, 0x5b, 0x2e, 0x8f, 0x4a, 0x10}}; +// The console's own command-list interface: CreateCommandListX (device slot 73) asks for it by name in the retail +// executable. No PC list answers it, so a command-list proxy answers it itself and maps its slots to the PC ones. +inline constexpr GUID kConsoleListIID{ + 0xc3827890, 0x4024, 0x474c, {0x98, 0xcf, 0x64, 0x5b, 0x51, 0xdc, 0x48, 0x74}}; bool is_allocator_proxy(const void* allocator); // The wrapped allocator (no reference added), or null when `allocator` is not an allocator proxy. ID3D12CommandAllocator* allocator_proxy_real_allocator(const void* allocator); diff --git a/runtime/test/xs_proxy_mock_test.cpp b/runtime/test/xs_proxy_mock_test.cpp index 6af7ad8046..c85da977b6 100644 --- a/runtime/test/xs_proxy_mock_test.cpp +++ b/runtime/test/xs_proxy_mock_test.cpp @@ -867,6 +867,20 @@ int check_xbox_slots() { EXPECT(mock->args[12][2] == word(real_allocator) && mock->args[12][3] == 0); EXPECT(mock->args[12][4] == word(&list_iid)); + // The same slot asked for the console's own list interface, {c3827890-4024-474c-98cf-645b51dc4874}, which no PC + // list answers. The proxy answers it itself; the layer receives the PC base interface. + const IID console_list_iid = xs::kConsoleListIID; + void* console_list = nullptr; + EXPECT(hr_of(raw(device, 73, word(&desc), word(allocator), 0, word(&console_list_iid), + word(&console_list))) == S_OK); + EXPECT(xs::is_command_list_proxy(console_list)); + EXPECT(std::memcmp(reinterpret_cast(mock->args[12][4]), &__uuidof(ID3D12GraphicsCommandList), + sizeof(IID)) == 0); + void* console_query = nullptr; + EXPECT(hr_of(raw(console_list, 0, word(&console_list_iid), word(&console_query))) == S_OK && + console_query == console_list); + EXPECT(release(console_list) == 0); + // Release the list before the refusal calls below: the COM convention (and the handler) nulls the caller's // output on failure, so an invalid call would clear this pointer. EXPECT(release(list) == 0);