Merge pull request #403 from Mumogg/queue-slot18-frequency

d3d12_xs: the title's queue slot 18 is the frequency getter, not PC GetDesc (RT-QUEUE18)
This commit is contained in:
aslan2142
2026-11-25 01:13:57 +01:00
committed by GitHub
2 changed files with 31 additions and 0 deletions

View File

@ -834,6 +834,8 @@ static_assert(kQueueSlots * sizeof(void*) <= 4096 && kFenceSlots * sizeof(void*)
constexpr unsigned kQueueExecuteCommandLists = 10; // (UINT, ID3D12CommandList* const*)
constexpr unsigned kQueueSignal = 14, kQueueWait = 15; // (ID3D12Fence*, UINT64)
constexpr unsigned kQueueGetTimestampFrequency = 16, kQueueGetDesc = 18; // the PC slots
bool is_console_caller(const void* address); // defined with the device proxy
constexpr unsigned kQueueExecuteCommandListsX = 35; // console ExecuteCommandLists(count, lists) variant
static_assert(kQueueExecuteCommandLists < kQueuePublicSlots && kQueueExecuteCommandListsX < kQueueSlots,
"queue execution slots must stay within their respective tables");
@ -1489,6 +1491,19 @@ std::uint64_t WINAPI child_slot(ChildProxy* self, std::uint64_t a1, std::uint64_
if constexpr (K == ChildKind::queue && Slot == kQueueExecuteCommandLists) {
return queue_execute_command_lists(self, a1, a2);
}
if constexpr (K == ChildKind::queue && Slot == kQueueGetDesc) {
// Queue slot 18 is GetDesc on the PC: a struct return, 16 bytes written through the hidden pointer. The
// retail title calls slot 18 with one pointer to 8 bytes, the shape of GetTimestampFrequency(UINT64*),
// which the console layout with two methods inserted at 14/15 has there (PC slot 16). Forwarded as
// GetDesc it wrote a whole description over the title's 8 bytes and what follows them. The title's call
// therefore goes to the frequency getter, the only reading that cannot overrun its argument; a host
// caller (set_console_caller, as device slots 61 and 74) keeps the PC GetDesc.
if (is_console_caller(_ReturnAddress())) {
using Fn = HRESULT(WINAPI*)(void*, UINT64*);
return hr_to_u64(reinterpret_cast<Fn>(self->real_vtable[kQueueGetTimestampFrequency])(
self->real, reinterpret_cast<UINT64*>(a1)));
}
}
if constexpr (K == ChildKind::queue && (Slot == kQueueSignal || Slot == kQueueWait)) a1 = unwrap_object(a1);
UnwrappedArray unwrapped_lists;
if constexpr (K == ChildKind::queue && Slot == 10) {

View File

@ -1393,6 +1393,22 @@ int check_xbox_queue_slots() {
EXPECT(xs::queue_slot_hits(35) == 2 && queue_mock->calls[35] == 0 && queue_mock->calls[10] == 2);
EXPECT(queue_mock->args[10][0] == 0 && queue_mock->args[10][1] == 0);
// Queue slot 18. The title's call (one pointer to 8 bytes) is the frequency getter, PC slot 16, and never the
// PC slot 18 (GetDesc), which would write a 16-byte description through that pointer. A host caller, under a
// classifier and with none installed, keeps the PC slot 18.
std::uint64_t frequency[3] = {0xA5A5A5A5A5A5A5A5ull, 0xA5A5A5A5A5A5A5A5ull, 0xA5A5A5A5A5A5A5A5ull};
xs::set_console_caller([](std::uint64_t) { return true; });
raw(queue, 18, word(&frequency[1]));
EXPECT(queue_mock->calls[16] == 1 && queue_mock->calls[18] == 0 && queue_mock->args[16][0] == word(&frequency[1]));
EXPECT(frequency[0] == 0xA5A5A5A5A5A5A5A5ull && frequency[2] == 0xA5A5A5A5A5A5A5A5ull);
xs::set_console_caller([](std::uint64_t) { return false; });
D3D12_COMMAND_QUEUE_DESC host_desc{};
raw(queue, 18, word(&host_desc));
EXPECT(queue_mock->calls[16] == 1 && queue_mock->calls[18] == 1 && queue_mock->args[18][0] == word(&host_desc));
xs::set_console_caller(nullptr);
raw(queue, 18, word(&host_desc));
EXPECT(queue_mock->calls[16] == 1 && queue_mock->calls[18] == 2);
EXPECT(release(queue) == 0 && release(device) == 0 && mock->refs == 0);
std::printf("%s: queue slot 35 routes ExecuteCommandLists(count, lists) to PC slot 10 with UINT count masking\n",
g_label);