diff --git a/runtime/shims/d3d12_xs_command_list_iid.h b/runtime/shims/d3d12_xs_command_list_iid.h new file mode 100644 index 0000000000..fc149cea90 --- /dev/null +++ b/runtime/shims/d3d12_xs_command_list_iid.h @@ -0,0 +1,68 @@ +// Console command-list interface IDs for device slot 73 (CreateCommandListX). The console passes an IID whose PC +// counterpart is a different GUID with the same first 32 bits, so a call that asks for it fails on the PC device +// with E_NOINTERFACE. Only measured pairs go in the table: +// - console c3827890-4024-474c-98cf-645b51dc4874: the riid the 1.0.2.1 executable passes to slot 73 (its only GUID +// of that form in .rdata); also in TomBox's console QueryInterface list (crates/compat/d3d12_xs/src/perfctr_xs.rs +// line 230, commit f89e4106fe of omonkeyz/xbox-emulator, GPL-3.0); +// - PC ID3D12GraphicsCommandList6, c3827890-e548-4cfa-96cf-5689a9370f80 (Windows SDK 10.0.26100.0 d3d12.h). +// Matching is on the whole GUID. An IID that is not in the table is forwarded unchanged, and logged once. +#pragma once + +#include +#include +#include + +#include +#include + +namespace rt::d3d12_xs { + +struct CommandListIidPair { + GUID console; + GUID pc; +}; + +inline constexpr CommandListIidPair kCommandListIidPairs[] = { + // ID3D12GraphicsCommandList6 + {{0xc3827890, 0x4024, 0x474c, {0x98, 0xcf, 0x64, 0x5b, 0x51, 0xdc, 0x48, 0x74}}, + {0xc3827890, 0xe548, 0x4cfa, {0x96, 0xcf, 0x56, 0x89, 0xa9, 0x37, 0x0f, 0x80}}}, +}; + +// True for the PC command-list IIDs a title may also pass (ID3D12CommandList, ID3D12GraphicsCommandList..7): those +// need no mapping and no log line. +inline bool is_pc_command_list_iid(const GUID& iid) { + static const GUID kPcIids[] = { + __uuidof(ID3D12CommandList), __uuidof(ID3D12GraphicsCommandList), + __uuidof(ID3D12GraphicsCommandList1), __uuidof(ID3D12GraphicsCommandList2), + __uuidof(ID3D12GraphicsCommandList3), __uuidof(ID3D12GraphicsCommandList4), + __uuidof(ID3D12GraphicsCommandList5), __uuidof(ID3D12GraphicsCommandList6), + __uuidof(ID3D12GraphicsCommandList7), + }; + for (const GUID& pc : kPcIids) { + if (IsEqualGUID(pc, iid)) return true; + } + return false; +} + +// The PC IID for a console command-list IID in the table; `requested` itself otherwise. `mapped` (optional) reports +// whether a substitution was made. +inline const GUID& command_list_iid_for_pc(const GUID& requested, bool* mapped = nullptr) { + for (const CommandListIidPair& pair : kCommandListIidPairs) { + if (IsEqualGUID(pair.console, requested)) { + if (mapped) *mapped = true; + return pair.pc; + } + } + if (mapped) *mapped = false; + if (is_pc_command_list_iid(requested)) return requested; // already a PC IID: nothing to report + static std::atomic logged{false}; + if (!logged.exchange(true)) { + std::fprintf(stderr, + "[rt] d3d12_xs: command list IID %08lx-%04x-%04x is not in the console table; forwarded unchanged\n", + static_cast(requested.Data1), static_cast(requested.Data2), + static_cast(requested.Data3)); + } + return requested; +} + +} // namespace rt::d3d12_xs diff --git a/runtime/shims/d3d12_xs_device.cpp b/runtime/shims/d3d12_xs_device.cpp index 7f7040fdd9..9f0a3f99de 100644 --- a/runtime/shims/d3d12_xs_device.cpp +++ b/runtime/shims/d3d12_xs_device.cpp @@ -42,6 +42,8 @@ #include #include +#include "d3d12_xs_command_list_iid.h" + namespace rt::d3d12_xs { namespace { @@ -1018,11 +1020,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; - if (!is_list_iid(*riid)) { - if (supports_iid(self->real, *riid)) log_refused_iid("list", *riid); + // A console title asks for the console command-list IID (device slot 73 forwards it): it maps to a PC IID the + // real list answers, and the caller gets this console-shaped object back. + const IID& pc_iid = command_list_iid_for_pc(*riid); + if (!is_list_iid(pc_iid)) { + if (supports_iid(self->real, pc_iid)) 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; @@ -1443,7 +1448,7 @@ HRESULT proxy_create_command_list_x(DeviceProxy* self, std::uint64_t desc_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); + command_list_iid_for_pc(*riid), &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 224030247c..10aed6a8e8 100644 --- a/runtime/test/xs_proxy_mock_test.cpp +++ b/runtime/test/xs_proxy_mock_test.cpp @@ -959,6 +959,22 @@ int check_xbox_slots() { // output on failure, so an invalid call would clear this pointer. EXPECT(release(list) == 0); + // The measured console list IID maps to ID3D12GraphicsCommandList6: slot 73 answers it, the PC call gets the + // mapped IID, and a QueryInterface for the console IID on the proxy returns the proxy. + mock->list_level = 7; // the real list must answer the mapped PC IID + const IID console_list_iid = {0xc3827890, 0x4024, 0x474c, {0x98, 0xcf, 0x64, 0x5b, 0x51, 0xdc, 0x48, 0x74}}; + 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)); + IID mapped_iid{}; + std::memcpy(&mapped_iid, reinterpret_cast(mock->args[12][4]), sizeof(IID)); + EXPECT(IsEqualIID(mapped_iid, __uuidof(ID3D12GraphicsCommandList6))); + void* console_qi = nullptr; + EXPECT(hr_of(raw(console_list, 0, word(&console_list_iid), word(&console_qi))) == S_OK && + console_qi == console_list); + EXPECT(release(console_qi) == 1); + EXPECT(release(console_list) == 0); + // Missing description, allocator or output: E_INVALIDARG/E_POINTER before the real device is called. EXPECT(hr_of(raw(device, 73, 0, word(allocator), 0, word(&list_iid), word(&list))) == E_INVALIDARG); EXPECT(hr_of(raw(device, 73, word(&desc), 0, 0, word(&list_iid), word(&list))) == E_INVALIDARG);