From 8ba15dd44960a21167f975affb04370c721a103d Mon Sep 17 00:00:00 2001 From: Mumogg <104529023+Mumogg@users.noreply.github.com> Date: Mon, 23 Nov 2026 22:45:09 -0600 Subject: [PATCH 1/6] d3d12_xs: the queue's console slot 32 is PresentX, wired to the presentation core The retail title presents through command-queue slot 32, past the PC queue's 19 slots, so main refused it with E_NOTIMPL and nothing could be shown. The slot now calls XboxPresentation::PresentX (xbox_present.h) with the title's plane count, planes and parameters. The first call on a device builds a window and the Vulkan layer's presenter for it, once; a device that cannot present answers S_OK and shows nothing, so the title's frame loop runs either way. The mock and COM builds of this file have no presenter and answer S_OK. The wiring follows old PR 2490's (Nolan Cotter, 2be25cee2), written again for main's queue proxy, where that commit does not apply. Not carried over: the queue layout detection (the older layout has PresentX at slot 30) and presenting into the title's own window (old PR 8591); the window here is one this layer creates. Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_01HxBQf4pXH8PWpC5oZsM4bt --- runtime/shims/d3d12_xs_device.cpp | 96 ++++++++++++++++++++++++++++++- 1 file changed, 95 insertions(+), 1 deletion(-) diff --git a/runtime/shims/d3d12_xs_device.cpp b/runtime/shims/d3d12_xs_device.cpp index 827b00e776..bd98965f7c 100644 --- a/runtime/shims/d3d12_xs_device.cpp +++ b/runtime/shims/d3d12_xs_device.cpp @@ -29,6 +29,12 @@ #include "d3d12_xs_desc_clean.h" #include "../src/shader_library.h" // leonida::fspx_payload_from_parts for slot 67 +#ifdef LEONIDA_VULKAN_DEVICE +// PresentX wiring: the queue's console slot lands on the Xbox presentation core, which needs the Vulkan layer's +// WindowPresenter. Other builds of this file (the mock and COM tests) have no presenter and answer S_OK. +#include "xbox_present.h" +#endif + #include #include #include // _ReturnAddress: slot 61 serves a console caller differently from a host one @@ -83,8 +89,13 @@ struct DeviceProxy { std::atomic frame_latency{1}; std::atomic frame_event_scheduled{false}; std::atomic frame_next_token{1}; + // The PresentX state (window, presenter, XboxPresentation) the first queue PresentX builds on this device, + // destroyed with the proxy. Opaque here: PresentState is defined with the queue proxy. + void* present_state = nullptr; }; +void destroy_present_state(void* present_state); + constexpr unsigned kHeapSlots = 11; // IUnknown + ID3D12Object + DeviceChild + Pageable + GetDesc + 2 handles struct HeapProxy { @@ -379,6 +390,7 @@ unsigned long proxy_release(DeviceProxy* self) { const unsigned long refs = self->refs.fetch_sub(1, std::memory_order_acq_rel) - 1; if (refs == 0) { ID3D12Device* real = self->real; + destroy_present_state(self->present_state); // the presenter goes before the device it draws with delete self; if (real) real->Release(); } @@ -1326,6 +1338,85 @@ LONG CALLBACK table_overrun_handler(EXCEPTION_POINTERS* info) { return EXCEPTION_CONTINUE_SEARCH; // diagnostics only: the fault goes on to the title's handlers or the crash } +// ---- PresentX (console queue slot 32) ---- +// +// The retail title presents through command-queue slot 32, past the PC queue's 19 slots: PresentX(plane count, +// planes, parameters), the call the Xbox presentation core (xbox_present.h) implements. The first call on a device +// builds a window and the Vulkan layer's presenter for it, once; a device that cannot present (no presenter, no +// window) answers S_OK and shows nothing, so the title's frame loop keeps running either way. +// ASSUMPTION: the window is one this layer creates. The title has a window of its own; presenting into that one is +// a separate piece of work (old PR 8591). +constexpr unsigned kQueuePresentX = 32; + +#ifdef LEONIDA_VULKAN_DEVICE + +struct PresentState { + ~PresentState() { + xbox.reset(); + if (window) DestroyWindow(window); + } + HWND window = nullptr; + std::unique_ptr xbox; +}; + +void destroy_present_state(void* present_state) { delete static_cast(present_state); } + +LRESULT CALLBACK present_window_proc(HWND window, UINT message, WPARAM wparam, LPARAM lparam) { + return DefWindowProcW(window, message, wparam, lparam); +} + +// Builds the window, presenter and XboxPresentation once per device. Returns the state even when `xbox` stays null: +// the failure is logged once and not retried. +PresentState* present_state_for(DeviceProxy* device) { + static std::mutex mutex; + const std::lock_guard lock(mutex); + if (auto* state = static_cast(device->present_state)) return state; + auto* state = new (std::nothrow) PresentState; + if (!state) return nullptr; + device->present_state = state; + WNDCLASSW window_class{}; + window_class.lpfnWndProc = present_window_proc; + window_class.hInstance = GetModuleHandleW(nullptr); + window_class.lpszClassName = L"LeonidaPresentX"; + if (!RegisterClassW(&window_class) && GetLastError() != ERROR_CLASS_ALREADY_EXISTS) { + std::fprintf(stderr, "[rt] d3d12_xs: PresentX window class failed (error %lu)\n", GetLastError()); + return state; + } + state->window = CreateWindowExW(0, window_class.lpszClassName, L"Leonida", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, + CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, nullptr, nullptr, + window_class.hInstance, nullptr); + if (!state->window) { + std::fprintf(stderr, "[rt] d3d12_xs: PresentX window failed (error %lu)\n", GetLastError()); + return state; + } + ShowWindow(state->window, SW_SHOWNOACTIVATE); + auto presenter = rt::d3d12::create_window_presenter(device->real, state->window); + if (!presenter) { + std::fprintf(stderr, "[rt] d3d12_xs: no window presenter on this device; PresentX shows nothing\n"); + return state; + } + state->xbox = std::make_unique(std::move(presenter)); + std::fprintf(stderr, "[rt] d3d12_xs: PresentX ready (window %p)\n", static_cast(state->window)); + return state; +} + +std::uint64_t queue_present_x(ChildProxy* self, std::uint64_t plane_count, std::uint64_t planes, + std::uint64_t params) { + PresentState* state = self->device ? present_state_for(self->device) : nullptr; + if (!state || !state->xbox) return hr_to_u64(S_OK); // the title still runs with nothing presented + return hr_to_u64(state->xbox->PresentX( + static_cast(plane_count), reinterpret_cast(planes), + reinterpret_cast(params))); +} + +#else // !LEONIDA_VULKAN_DEVICE: this translation unit stands alone (the mock and COM tests) + +void destroy_present_state(void*) {} + +std::uint64_t queue_present_x(ChildProxy*, std::uint64_t, std::uint64_t, std::uint64_t) { return hr_to_u64(S_OK); } + +#endif + std::uint64_t queue_execute_command_lists(ChildProxy* self, std::uint64_t count_word, std::uint64_t lists_word) { // The array holds what the title got from the proxy: list proxies are replaced by the real lists in a copy, as // for every other array of objects the real device or queue reads. @@ -1363,6 +1454,9 @@ std::uint64_t WINAPI child_slot(ChildProxy* self, std::uint64_t a1, std::uint64_ d3d12_trace::record(child_trace_name(Slot)); return queue_execute_command_lists(self, a1, a2); } + if constexpr (K == ChildKind::queue && Slot == kQueuePresentX) { + return queue_present_x(self, a1, a2, a3); // XboxPresentation::PresentX writes the trace line + } if constexpr (K == ChildKind::allocator && Slot == 9) { // Console-only ID3D12CommandAllocator::SetAllocatorCallbackX(callback, context, ...), observed past the // 9-slot PC chain on the retail executable (call shape: function pointer, context, plus trailing words). @@ -2981,7 +3075,7 @@ unsigned fence_proxy_table_size() { return kFenceSlots; } bool queue_slot_overridden(unsigned slot) { return slot <= 2 || slot == 7 || slot == kQueueSignal || slot == kQueueWait || - slot == kQueueExecuteCommandListsX; + slot == kQueueExecuteCommandListsX || slot == kQueuePresentX; } unsigned allocator_proxy_table_size() { return kAllocatorSlots; } unsigned allocator_proxy_slot_count(const void* allocator) { From af8c42bb1aa19db773a3fee2607ec0f4218f864b Mon Sep 17 00:00:00 2001 From: Logan Date: Mon, 23 Nov 2026 12:16:11 -0500 Subject: [PATCH 2/6] PresentX: device-side WaitFrameEventX and the frame pacer share one token source Device slot 80 (WaitFrameEventX, from #6935) numbered its tokens with a counter of its own, while XboxPresentation's pacer refuses any token above the ones it issued itself. A title that waits through the device and presents through the device's XboxPresentation therefore had every PresentX refused with E_INVALIDARG once its tokens ran ahead of the pacer's. leonida::FrameTokenSource is now the counter both use: a pacer takes an optional shared source (a standalone pacer still owns its own and numbers as before), the device proxy owns one and exposes it through rt::d3d12_xs::device_frame_tokens, and XboxPresentation passes a given source to its pacer. A token that was never issued is still refused. Reported by rafaelpssz in #7496. (cherry picked from commit afb14d56c6a1683fae4345702c874a62d9234e71) Adapted to main by Mumogg: main's uncapped pacer path issues its token from the shared source too, the device proxy keeps the PresentX state next to the token source, and the queue's PresentX hands the device's source to its XboxPresentation, which is what makes the title's tokens valid there. --- runtime/shims/d3d12_xs_device.cpp | 15 ++++++++++----- runtime/shims/d3d12_xs_device.h | 7 +++++++ runtime/shims/xbox_present.cpp | 5 +++-- runtime/shims/xbox_present.h | 3 ++- runtime/src/frame_pacer.h | 25 +++++++++++++++++++------ runtime/test/device_proxy_test.cpp | 5 +++++ runtime/test/frame_pacer_test.cpp | 19 +++++++++++++++++++ runtime/test/xbox_present_test.cpp | 20 +++++++++++++++++++- 8 files changed, 84 insertions(+), 15 deletions(-) diff --git a/runtime/shims/d3d12_xs_device.cpp b/runtime/shims/d3d12_xs_device.cpp index bd98965f7c..ccf166db36 100644 --- a/runtime/shims/d3d12_xs_device.cpp +++ b/runtime/shims/d3d12_xs_device.cpp @@ -27,6 +27,7 @@ #include "d3d12_trace.h" #include "d3d12_xs_alloc_size.h" #include "d3d12_xs_desc_clean.h" +#include "../src/frame_pacer.h" #include "../src/shader_library.h" // leonida::fspx_payload_from_parts for slot 67 #ifdef LEONIDA_VULKAN_DEVICE @@ -88,7 +89,7 @@ struct DeviceProxy { std::atomic frame_interval_us{0}; std::atomic frame_latency{1}; std::atomic frame_event_scheduled{false}; - std::atomic frame_next_token{1}; + std::shared_ptr frame_tokens = std::make_shared(); // The PresentX state (window, presenter, XboxPresentation) the first queue PresentX builds on this device, // destroyed with the proxy. Opaque here: PresentState is defined with the queue proxy. void* present_state = nullptr; @@ -1395,7 +1396,8 @@ PresentState* present_state_for(DeviceProxy* device) { std::fprintf(stderr, "[rt] d3d12_xs: no window presenter on this device; PresentX shows nothing\n"); return state; } - state->xbox = std::make_unique(std::move(presenter)); + state->xbox = std::make_unique(std::move(presenter), nullptr, device->frame_tokens); + // The device's token source: the title takes its frame tokens from device slot 80 and presents them here. std::fprintf(stderr, "[rt] d3d12_xs: PresentX ready (window %p)\n", static_cast(state->window)); return state; } @@ -1685,9 +1687,7 @@ HRESULT proxy_wait_frame_event_x(DeviceProxy* self, std::uint64_t event, std::ui (void)flags; auto* token = reinterpret_cast(token_word); if (!token) return E_POINTER; - std::uint64_t value = self->frame_next_token.fetch_add(1, std::memory_order_relaxed); - if (value == 0) value = self->frame_next_token.fetch_add(1, std::memory_order_relaxed); // skip the null token - *token = value; + *token = self->frame_tokens->issue(); return S_OK; } @@ -3033,6 +3033,11 @@ ID3D12Device* device_proxy_real_device(const void* device) { return static_cast(device)->real; } +std::shared_ptr device_frame_tokens(const void* device) { + if (!is_device_proxy(device)) return nullptr; + return static_cast(device)->frame_tokens; +} + bool device_slot_overridden(unsigned slot) { if (slot <= 2 || slot == 8 || slot == 9 || slot == 14 || (slot >= 17 && slot <= 24) || slot == 25 || slot == 26 || slot == 31 || slot == 32 || slot == 34 || slot == 35 || slot == 36 || slot == 41 || slot == 45 || slot == 46 || slot == 50 || slot == 56 || slot == 61 || slot == 74 || slot == 62 || slot == 67 || diff --git a/runtime/shims/d3d12_xs_device.h b/runtime/shims/d3d12_xs_device.h index b9062ff202..6ae5200341 100644 --- a/runtime/shims/d3d12_xs_device.h +++ b/runtime/shims/d3d12_xs_device.h @@ -73,6 +73,11 @@ #include #include +#include + +namespace leonida { +class FrameTokenSource; +} namespace rt::d3d12_xs { @@ -153,6 +158,8 @@ using ConsoleDescriptorHeapHandler = HRESULT (*)(ID3D12Device* real, const D3D12 REFIID riid, void** out); void set_console_descriptor_heap_handler(ConsoleDescriptorHeapHandler handler); +std::shared_ptr device_frame_tokens(const void* device); + // True for slots the proxy handles itself rather than forwarding verbatim: IUnknown (0-2), 8 and 75 (queue // proxies), 9 (allocator proxies), 14 (descriptor heap proxy), 17-24 (CPU descriptor handle translation), 26 (the // console's struct-return form), diff --git a/runtime/shims/xbox_present.cpp b/runtime/shims/xbox_present.cpp index dd5f810cf7..f41f2c4680 100644 --- a/runtime/shims/xbox_present.cpp +++ b/runtime/shims/xbox_present.cpp @@ -28,10 +28,11 @@ void log_once(bool& done, const char* text) { } // namespace -XboxPresentation::XboxPresentation(std::unique_ptr presenter, leonida::FrameClock* clock) +XboxPresentation::XboxPresentation(std::unique_ptr presenter, leonida::FrameClock* clock, + std::shared_ptr tokens) : presenter_(std::move(presenter)), own_clock_(clock ? nullptr : std::make_unique()), - pacer_(clock ? *clock : *own_clock_) { + pacer_(clock ? *clock : *own_clock_, std::move(tokens)) { // A present waiting for a swapchain image gives up once SuspendX has been called. presenter_->set_abort([this] { return pacer_.suspended(); }); // LEONIDA_SDR_EOTF=gamma22 (or 2.2, any case) decodes SDR with a pure power of 2.2 instead of piecewise sRGB; "srgb" or diff --git a/runtime/shims/xbox_present.h b/runtime/shims/xbox_present.h index 60a317beec..914d707a3d 100644 --- a/runtime/shims/xbox_present.h +++ b/runtime/shims/xbox_present.h @@ -100,7 +100,8 @@ class XboxPresentation { public: // `clock` null: real time (a steady high-resolution timer). Tests pass a leonida::ManualFrameClock, which must // outlive this object. `presenter` is what create_window_presenter returned. - explicit XboxPresentation(std::unique_ptr presenter, leonida::FrameClock* clock = nullptr); + explicit XboxPresentation(std::unique_ptr presenter, leonida::FrameClock* clock = nullptr, + std::shared_ptr tokens = nullptr); ~XboxPresentation(); XboxPresentation(const XboxPresentation&) = delete; XboxPresentation& operator=(const XboxPresentation&) = delete; diff --git a/runtime/src/frame_pacer.h b/runtime/src/frame_pacer.h index fa9c20df1d..5de8e9b79d 100644 --- a/runtime/src/frame_pacer.h +++ b/runtime/src/frame_pacer.h @@ -37,7 +37,9 @@ #include #include #include +#include #include +#include namespace leonida { @@ -143,9 +145,19 @@ struct FrameStatistic { float percent_scanned = 0.0f; // display entries: where the scan was when the frame came up (0 at a vblank) }; +class FrameTokenSource { +public: + std::uint64_t issue() { return last_.fetch_add(1, std::memory_order_acq_rel) + 1; } + std::uint64_t issued() const { return last_.load(std::memory_order_acquire); } + +private: + std::atomic last_{0}; +}; + class FramePacer { public: - explicit FramePacer(FrameClock& clock) : clock_(clock) { + explicit FramePacer(FrameClock& clock, std::shared_ptr tokens = nullptr) + : clock_(clock), tokens_(tokens ? std::move(tokens) : std::make_shared()) { clock_.set_wake([this] { { std::lock_guard guard(mutex_); } cv_.notify_all(); @@ -263,7 +275,7 @@ class FramePacer { std::lock_guard guard(mutex_); if (issue) *issue = TokenIssue::none; if (suspended_) return pacer_hr::invalid_state; - if (token > issued_) return pacer_hr::invalid_arg; + if (token > tokens_->issued()) return pacer_hr::invalid_arg; if (issue) { if (token == 0) *issue = TokenIssue::null_token; else if (token == last_presented_) *issue = TokenIssue::repeated; @@ -357,7 +369,8 @@ class FramePacer { } bool suspended() const { std::lock_guard guard(mutex_); return suspended_; } - std::uint64_t tokens_issued() const { std::lock_guard guard(mutex_); return issued_; } + std::uint64_t tokens_issued() const { return tokens_->issued(); } + const std::shared_ptr& token_source() const { return tokens_; } std::uint32_t frames_in_flight() { std::lock_guard guard(mutex_); retire_locked(clock_.now_us()); @@ -408,7 +421,7 @@ class FramePacer { const std::uint64_t now = clock_.now_us(); retire_locked(now); if (uncapped_) { // no vblank grid and no latency throttle: a token at once, due now - *token = ++issued_; + *token = tokens_->issue(); Record record; record.token = *token; record.origin_us = now; @@ -426,7 +439,7 @@ class FramePacer { const std::int64_t newest = std::int64_t((now - first) / period_us_); const std::int64_t origin = std::max(next, newest); last_origin_ = origin; - *token = ++issued_; + *token = tokens_->issue(); Record record; record.token = *token; record.origin_us = first + std::uint64_t(origin) * period_us_; @@ -457,7 +470,7 @@ class FramePacer { std::uint32_t offset_us_ = 0; std::uint64_t epoch_us_ = 0; std::int64_t last_origin_ = 0; // origin 0 is the epoch itself, which has passed - std::uint64_t issued_ = 0; + std::shared_ptr tokens_; std::uint64_t last_presented_ = 0; std::uint64_t immediate_presents_ = 0; std::deque pending_; diff --git a/runtime/test/device_proxy_test.cpp b/runtime/test/device_proxy_test.cpp index 6242d1b526..933674952f 100644 --- a/runtime/test/device_proxy_test.cpp +++ b/runtime/test/device_proxy_test.cpp @@ -26,6 +26,7 @@ #include "d3d12_xs_desc_clean.h" #include "d3d12_xs_device.h" #include "shims.h" +#include "../src/frame_pacer.h" namespace { @@ -433,6 +434,10 @@ int main(int argc, char** argv) { check(hr == S_OK && token2 != 0 && token2 != token, "slot 80 returns a fresh token on the next wait"); hr = reinterpret_cast(proxy_vtbl[80])(device.Get(), 0, 0, nullptr, 0, nullptr); check(hr == E_POINTER, "slot 80 refuses a null token with E_POINTER"); + const auto tokens = rt::d3d12_xs::device_frame_tokens(device.Get()); + check(tokens && tokens->issued() == token2 && token2 == token + 1, + "slot 80 tokens come from the device's frame token source"); + check(!rt::d3d12_xs::device_frame_tokens(nullptr), "a non-proxy has no frame token source"); check(rt::d3d12_xs::device_slot_hits(78) == 1 && rt::d3d12_xs::device_slot_hits(79) == 1 && rt::d3d12_xs::device_slot_hits(80) == 3, "slots 78/79/80 hit counters are 1/1/3"); diff --git a/runtime/test/frame_pacer_test.cpp b/runtime/test/frame_pacer_test.cpp index 8d089acdaf..e86c6f560a 100644 --- a/runtime/test/frame_pacer_test.cpp +++ b/runtime/test/frame_pacer_test.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include using namespace leonida; @@ -86,6 +87,24 @@ int main() { EXPECT(pacer.tokens_issued() == 2); } + { + ManualFrameClock clock; + auto tokens = std::make_shared(); + FramePacer pacer(clock, tokens); + EXPECT(pacer.token_source() == tokens); + const std::uint64_t outside = tokens->issue(); + EXPECT(outside == 1 && pacer.tokens_issued() == 1); + EXPECT(pacer.check_present_token(outside) == pacer_hr::ok); + EXPECT(pacer.check_present_token(outside + 1) == pacer_hr::invalid_arg); + EXPECT(setup(pacer, 1)); + clock.advance_us(period); + std::uint64_t token = 0; + EXPECT(pacer.wait_frame_event(frame_event_origin, 0, 0, &token) == pacer_hr::ok && token == outside + 1); + EXPECT(tokens->issue() == outside + 2); + EXPECT(pacer.check_present_token(outside + 2) == pacer_hr::ok); + EXPECT(pacer.check_present_token(outside + 3) == pacer_hr::invalid_arg); + } + // An offset delays the event inside the period: origin n comes at n * period + offset. { ManualFrameClock clock; diff --git a/runtime/test/xbox_present_test.cpp b/runtime/test/xbox_present_test.cpp index 1526f87a7a..adbb75e6a5 100644 --- a/runtime/test/xbox_present_test.cpp +++ b/runtime/test/xbox_present_test.cpp @@ -375,8 +375,10 @@ int main() { EXPECT(presenter->enable_capture()); leonida::ManualFrameClock clock; - auto owner = std::make_unique(std::move(presenter), &clock); + auto owner = std::make_unique(std::move(presenter), &clock, + rt::d3d12_xs::device_frame_tokens(device.p)); rt::d3d12::XboxPresentation& xbox = *owner; + EXPECT(xbox.pacer().token_source() == rt::d3d12_xs::device_frame_tokens(device.p)); D3D12_COMMAND_QUEUE_DESC queue_desc{}; Ref queue; @@ -665,6 +667,22 @@ int main() { EXPECT(region_is(frame, 0, 0, width, height, {51, 153, 230})); EXPECT(xbox.presents() == presented_before + 3); + using DeviceWaitFrameEventFn = HRESULT(WINAPI*)(void*, UINT, UINT, void*, UINT, std::uint64_t*); + const auto device_wait = + reinterpret_cast((*reinterpret_cast(device.p))[80]); + std::uint64_t device_token = 0; + EXPECT(device_wait(device.p, rt::d3d12::xbox_frame_event_origin, 0, nullptr, 0, &device_token) == S_OK); + EXPECT(device_token != 0 && device_token == xbox.pacer().tokens_issued()); + plane = plane_of(second, device_token + 1); + EXPECT(xbox.PresentX(1, &plane, nullptr) == E_INVALIDARG); + EXPECT(xbox.presents() == presented_before + 3); + plane = plane_of(rgba, device_token); + EXPECT(xbox.PresentX(1, &plane, nullptr) == S_OK); + EXPECT(xbox.presents() == presented_before + 4); + EXPECT(grab(frame)); + EXPECT(region_is(frame, 0, 0, width, height, {51, 153, 230})); + std::printf("a token from device slot 80 (WaitFrameEventX) presents: ok\n"); + // Sources the GPU cannot blit are refused with DXGI_ERROR_UNSUPPORTED and present nothing: multisampled, // integer and block-compressed. The last frame stays on screen and the token is still usable afterwards. { From 77c801c82f5c0d7e222512ef7d1d0a927895f7a4 Mon Sep 17 00:00:00 2001 From: Mumogg <104529023+Mumogg@users.noreply.github.com> Date: Mon, 23 Nov 2026 23:03:47 -0600 Subject: [PATCH 3/6] queue_proxy_test: the PresentX slot is called and counted The coverage gate asks for every queue slot to have been called, and skips the overridden ones in its sweep of the refused tail. Slot 32 is overridden since the PresentX wiring, so nothing called it and the gate failed ("queue slot 32 never called"). The test now calls it where it calls the console ExecuteCommandLists slot: this build of the proxy has no presenter, so the answer is S_OK. Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_01HxBQf4pXH8PWpC5oZsM4bt --- runtime/test/queue_proxy_test.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/runtime/test/queue_proxy_test.cpp b/runtime/test/queue_proxy_test.cpp index 967313d53a..674a8cf2ed 100644 --- a/runtime/test/queue_proxy_test.cpp +++ b/runtime/test/queue_proxy_test.cpp @@ -277,6 +277,12 @@ int check_slots(const Backend& b) { const std::uint64_t before35 = qhits(35); EXPECT(raw_call(queue.p, 35, 1, reinterpret_cast(lists)) == 0); EXPECT(qhits(35) == before35 + 1 && xs::queue_slot_first_call_seen(35)); + // Console slot 32, PresentX. This test's build of the proxy has no presenter (the wiring is in gta6rt's, + // LEONIDA_VULKAN_DEVICE), so the slot answers S_OK and reaches no PC slot; it is counted like any other. + EXPECT(xs::queue_slot_overridden(32)); + const std::uint64_t before32 = qhits(32); + EXPECT(static_cast(raw_call(queue.p, 32, 0, 0, 0)) == static_cast(S_OK)); + EXPECT(qhits(32) == before32 + 1); EXPECT(SUCCEEDED(queue->Signal(fence.p, 7))); if (wait_for(label, fence.p, 7)) return 1; if (b.vulkan) { From adc4f314ba5b54579d91d5dbb7921901efe7a7f7 Mon Sep 17 00:00:00 2001 From: Mumogg <104529023+Mumogg@users.noreply.github.com> Date: Mon, 23 Nov 2026 22:49:35 -0600 Subject: [PATCH 4/6] d3d12_xs: the list proxy translates title-owned CPU descriptor handles (console list slots 50 to 54) Device slots 17 to 24 translate a CPU descriptor handle in the title's own range (__XMemAllocationHooks__) to the real heap's. The five command-list methods that take such handles did not: OMSetRenderTargets (console slot 50), ClearDepthStencilView (51), ClearRenderTargetView (52) and the two ClearUnorderedAccessView (53, 54) went to the real list with the title's address, which is no descriptor there. On the retail boot the first ClearRenderTargetView made the list's Close fail. They translate now, in copies: the caller's arrays are not written, and a handle outside the range is passed as it is. Slot 51 gets a typed thunk, because its depth is a FLOAT in XMM3, which the all-integer list thunk loses. This is 0aba6c361 (LeonidaBringup) written again for main's list proxy, where that commit does not apply (it sits on old PR 2490's list proxy). xs_proxy_mock_test: the five slots with a handle inside the range, one outside it, and the caller's arrays unchanged. Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_01HxBQf4pXH8PWpC5oZsM4bt --- runtime/shims/d3d12_xs_device.cpp | 70 +++++++++++++++++++++++++++++ runtime/test/xs_proxy_mock_test.cpp | 49 ++++++++++++++++++++ 2 files changed, 119 insertions(+) diff --git a/runtime/shims/d3d12_xs_device.cpp b/runtime/shims/d3d12_xs_device.cpp index ccf166db36..2f0b547d8b 100644 --- a/runtime/shims/d3d12_xs_device.cpp +++ b/runtime/shims/d3d12_xs_device.cpp @@ -1040,6 +1040,11 @@ bool is_child_proxy(const void* object) { constexpr unsigned kListSlots = 160; constexpr unsigned kConsoleSetDescriptorHeaps = 32; constexpr unsigned kConsoleExecuteBundle = 31; +constexpr unsigned kConsoleOMSetRenderTargets = 50; +constexpr unsigned kConsoleClearDepthStencilView = 51; +constexpr unsigned kConsoleClearRenderTargetView = 52; +constexpr unsigned kConsoleClearUavUint = 53; +constexpr unsigned kConsoleClearUavFloat = 54; constexpr unsigned kConsoleBarrier = 146; struct ListProxy { @@ -1247,6 +1252,43 @@ std::uint64_t WINAPI list_slot(ListProxy* self, std::uint64_t a1, std::uint64_t } else if constexpr (Slot == kConsoleSetDescriptorHeaps) { if (!heaps.fill(a2, a1)) return 0; if (heaps.data()) a2 = heaps.data(); + } else if constexpr (Slot == kConsoleOMSetRenderTargets) { + // OMSetRenderTargets(count, render target handles, single range, depth-stencil handle): the handles + // may be in the title's own descriptor range (__XMemAllocationHooks__), which only this proxy can + // translate. Copies are translated; the caller's arrays are not written. + const UINT count = static_cast(a1); + const auto* in_rtvs = reinterpret_cast(a2); + const BOOL single_range = static_cast(a3); + const auto* in_dsv = reinterpret_cast(a4); + D3D12_CPU_DESCRIPTOR_HANDLE rtvs[D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT]{}; + const D3D12_CPU_DESCRIPTOR_HANDLE* out_rtvs = in_rtvs; + if (in_rtvs && count > 0) { + if (single_range) { + rtvs[0] = translate_cpu_handle(self->device, in_rtvs[0]); + out_rtvs = rtvs; + } else if (count <= D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT) { + for (UINT i = 0; i < count; ++i) rtvs[i] = translate_cpu_handle(self->device, in_rtvs[i]); + out_rtvs = rtvs; + } + } + D3D12_CPU_DESCRIPTOR_HANDLE dsv{}; + const D3D12_CPU_DESCRIPTOR_HANDLE* out_dsv = in_dsv; + if (in_dsv) { + dsv = translate_cpu_handle(self->device, *in_dsv); + out_dsv = &dsv; + } + return reinterpret_cast(real_vtable[pc])( + self->real, a1, reinterpret_cast(out_rtvs), a3, + reinterpret_cast(out_dsv), a5, a6, a7, a8, a9, a10, a11, a12, a13, a14); + } else if constexpr (Slot == kConsoleClearRenderTargetView) { + // ClearRenderTargetView(view, colour, rect count, rects): the view handle is translated. + a1 = static_cast( + translate_cpu_handle(self->device, D3D12_CPU_DESCRIPTOR_HANDLE{static_cast(a1)}).ptr); + } else if constexpr (Slot == kConsoleClearUavUint || Slot == kConsoleClearUavFloat) { + // ClearUnorderedAccessViewUint/Float(GPU handle, CPU handle, resource, values, rect count, rects): + // the CPU handle is translated, the GPU handle is kept. + a2 = static_cast( + translate_cpu_handle(self->device, D3D12_CPU_DESCRIPTOR_HANDLE{static_cast(a2)}).ptr); } return reinterpret_cast(real_vtable[pc])(self->real, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14); @@ -1254,9 +1296,37 @@ std::uint64_t WINAPI list_slot(ListProxy* self, std::uint64_t a1, std::uint64_t } } +// ClearDepthStencilView (console slot 51 -> PC slot 47) takes FLOAT Depth as its fourth argument, in XMM3 on the +// Windows x64 ABI. The all-integer list_slot thunk reads R9 there and loses the depth, so this slot has a typed +// thunk that keeps it and translates a title-owned CPU descriptor handle. +void WINAPI list_clear_depth_stencil_view(ListProxy* self, D3D12_CPU_DESCRIPTOR_HANDLE dsv, + D3D12_CLEAR_FLAGS flags, FLOAT depth, UINT8 stencil, UINT num_rects, + const D3D12_RECT* rects) { + std::uint32_t depth_bits = 0; + std::memcpy(&depth_bits, &depth, sizeof(depth_bits)); + note_list_slot(kConsoleClearDepthStencilView, static_cast(dsv.ptr), + static_cast(flags), depth_bits, stencil); + constexpr unsigned pc = console_to_pc_list_slot(kConsoleClearDepthStencilView); + if (pc >= self->pc_slot_count) { + static std::atomic beyond_warned{false}; + bool expected = false; + if (beyond_warned.compare_exchange_strong(expected, true, std::memory_order_relaxed)) + std::fprintf(stderr, + "[rt] d3d12_xs: list slot %u maps to PC slot %u, beyond the real list's %u slots\n", + kConsoleClearDepthStencilView, pc, self->pc_slot_count); + return; + } + const D3D12_CPU_DESCRIPTOR_HANDLE translated = translate_cpu_handle(self->device, dsv); + using ClearDsvFn = void(WINAPI*)(ID3D12GraphicsCommandList*, D3D12_CPU_DESCRIPTOR_HANDLE, D3D12_CLEAR_FLAGS, + FLOAT, UINT8, UINT, const D3D12_RECT*); + auto** const real_vtable = *reinterpret_cast(self->real); + reinterpret_cast(real_vtable[pc])(self->real, translated, flags, depth, stencil, num_rects, rects); +} + template void fill_list_vtable(void** vtable, std::index_sequence) { ((vtable[I] = reinterpret_cast(&list_slot(I)>)), ...); + vtable[kConsoleClearDepthStencilView] = reinterpret_cast(&list_clear_depth_stencil_view); } void** get_list_vtable() { diff --git a/runtime/test/xs_proxy_mock_test.cpp b/runtime/test/xs_proxy_mock_test.cpp index 4e0b509e8a..3f447a2236 100644 --- a/runtime/test/xs_proxy_mock_test.cpp +++ b/runtime/test/xs_proxy_mock_test.cpp @@ -308,6 +308,7 @@ std::uint64_t mock_call(Mock* m, unsigned slot, const std::uint64_t* words) { if (m->kind == Kind::fence && slot == 8) return kCompletedValue; // GetCompletedValue if (m->kind == Kind::queue && slot == 10) copy_array(m, slot, a2, a1); // ExecuteCommandLists(count, lists) if (m->kind == Kind::command_list && slot == 28) copy_array(m, slot, a2, a1); // SetDescriptorHeaps(count, heaps) + if (m->kind == Kind::command_list && slot == 46) copy_array(m, slot, a2, a1); // OMSetRenderTargets(count, handles) if (m->kind == Kind::heap && slot == 9) { if (a1) reinterpret_cast(a1)->ptr = kMockHeapCpuStart; return kMockHeapCpuStart; @@ -1786,6 +1787,54 @@ int check_descriptor_heap_hooks() { EXPECT(real->array[24][0] == kMockHeapCpuStart + off7 && real->array[24][1] == 0x99990000ull); } + // The command-list methods that take CPU descriptor handles translate the same range: console slots 50 + // (OMSetRenderTargets), 51 (ClearDepthStencilView), 52 (ClearRenderTargetView), 53 and 54 (the two + // ClearUnorderedAccessView). A handle outside the range is passed as it is, and the caller's arrays are not written. + { + const IID alloc_iid = __uuidof(ID3D12CommandAllocator); + const IID list_iid = __uuidof(ID3D12GraphicsCommandList); + void* allocator = nullptr; + EXPECT(hr_of(raw(device, 9, 0, word(&alloc_iid), word(&allocator))) == S_OK); + struct { + std::uint32_t type, node_mask; + std::uint64_t reserved[2]; + } list_desc{static_cast(D3D12_COMMAND_LIST_TYPE_DIRECT), 0, {0, 0}}; + void* list = nullptr; + EXPECT(hr_of(raw(device, 73, word(&list_desc), word(allocator), 0, word(&list_iid), word(&list))) == S_OK); + EXPECT(xs::is_command_list_proxy(list)); + Mock* const real_list = reinterpret_cast(xs::command_list_proxy_real_list(list)); + + raw(list, 52, kCustomBase + off3, 0x1234, 0, 0); // ClearRenderTargetView + EXPECT(real_list->calls[48] == 1 && real_list->args[48][0] == kMockHeapCpuStart + off3); + raw(list, 52, outside, 0x1234, 0, 0); + EXPECT(real_list->calls[48] == 2 && real_list->args[48][0] == outside); + raw(list, 53, kMockHeapGpuStart + off7, kCustomBase + off7, 0x55, 0x66, 0, 0); // ClearUnorderedAccessViewUint + EXPECT(real_list->args[49][0] == kMockHeapGpuStart + off7 && real_list->args[49][1] == kMockHeapCpuStart + off7); + raw(list, 54, kMockHeapGpuStart + off3, kCustomBase + off3, 0x55, 0x66, 0, 0); // ClearUnorderedAccessViewFloat + EXPECT(real_list->args[50][0] == kMockHeapGpuStart + off3 && real_list->args[50][1] == kMockHeapCpuStart + off3); + + D3D12_CPU_DESCRIPTOR_HANDLE targets[2] = {{kCustomBase + off3}, {outside}}; + D3D12_CPU_DESCRIPTOR_HANDLE depth{kCustomBase + off7}; + raw(list, 50, 2, word(targets), 0, word(&depth)); // OMSetRenderTargets + EXPECT(real_list->calls[46] == 1 && real_list->args[46][0] == 2); + EXPECT(real_list->args[46][1] != word(targets) && real_list->args[46][3] != word(&depth)); + EXPECT(real_list->array[46][0] == kMockHeapCpuStart + off3 && real_list->array[46][1] == outside); + EXPECT(targets[0].ptr == kCustomBase + off3 && targets[1].ptr == outside && depth.ptr == kCustomBase + off7); + + // Slot 51 has a typed thunk, because its depth is a FLOAT in XMM3. The mock's integer prototype cannot see + // the float; what it can see is that the call arrives at PC slot 47 with the translated handle and flags. + using ClearDsvFn = void(WINAPI*)(void*, D3D12_CPU_DESCRIPTOR_HANDLE, D3D12_CLEAR_FLAGS, FLOAT, UINT8, UINT, + const D3D12_RECT*); + void* const* list_vtable = *reinterpret_cast(list); + reinterpret_cast(list_vtable[51])(list, D3D12_CPU_DESCRIPTOR_HANDLE{kCustomBase + off7}, + D3D12_CLEAR_FLAG_DEPTH, 0.5f, 3, 0, nullptr); + EXPECT(real_list->calls[47] == 1 && real_list->args[47][0] == kMockHeapCpuStart + off7 && + static_cast(real_list->args[47][1]) == D3D12_CLEAR_FLAG_DEPTH); + + EXPECT(release(list) == 0); + EXPECT(release(allocator) == 0); + } + // Releasing the heap unregisters the range and invokes the free callback with the same attribute word. EXPECT(raw(heap, 2) == 0); EXPECT(g_heap_hook.free_calls == 1); From 89fdb83e06965864fd57f98c18af716df39fe75c Mon Sep 17 00:00:00 2001 From: NiiRoZz Date: Mon, 23 Nov 2026 18:14:31 +0100 Subject: [PATCH 5/6] d3d12_xs: a console depth-stencil texture with unordered access is sized and created without it (stand-in) The console allows ALLOW_DEPTH_STENCIL | ALLOW_UNORDERED_ACCESS on a texture; the PC runtime refuses the pair and slot 25 answered UINT64_MAX for it. pc_resource_flags drops the UAV bit from depth-stencil textures (slot 25 through pc_resource_desc, and slot 76). Their UAV views then write no descriptor. Co-Authored-By: Claude Opus 5.5 (cherry picked from commit 4a86034367eacdfca77298d89e37a5bc8545e4e5) Adapted to main by Mumogg: the conflict is with b4d1ba179, which is applied before it here: slot 25 keeps that commit's scoped cleaning, and this one adds the flag rule and its log line. --- runtime/shims/d3d12_xs_desc_clean.h | 19 ++++++++++++++- runtime/shims/d3d12_xs_device.cpp | 12 +++++++++ runtime/test/device_proxy_test.cpp | 38 +++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/runtime/shims/d3d12_xs_desc_clean.h b/runtime/shims/d3d12_xs_desc_clean.h index ba51184a4d..77f7e32817 100644 --- a/runtime/shims/d3d12_xs_desc_clean.h +++ b/runtime/shims/d3d12_xs_desc_clean.h @@ -24,6 +24,23 @@ constexpr std::uint32_t kPcResourceFlagsMask = // Not constexpr: 0x101 is outside the unfixed enum's value range, which clang-cl rejects in a constant expression. inline const auto kXboxTiledResourceLayout = static_cast(0x101); +// The console allows a depth-stencil texture to allow unordered access too (measured locally at a title's call sites: +// a 2D R32G8X24_TYPELESS texture with ALLOW_DEPTH_STENCIL | ALLOW_UNORDERED_ACCESS, sized through slot 25), but the PC +// runtime refuses that pair, and Vulkan has no depth format with storage support to make it with. Stand-in: such a +// texture is a depth-stencil texture without unordered access. Its unordered-access views write no descriptor (the PC +// layer refuses a UAV of a texture without the flag), so what a shader writes through them goes nowhere and their +// reads see whatever the descriptor held. +inline std::uint32_t without_depth_stencil_uav(D3D12_RESOURCE_DIMENSION dimension, std::uint32_t flags) { + if (dimension != D3D12_RESOURCE_DIMENSION_BUFFER && (flags & D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL)) + flags &= ~static_cast(D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS); + return flags; +} + +// The PC flags of a console description: the PC bits only, without unordered access on a depth-stencil texture. +inline std::uint32_t pc_resource_flags(D3D12_RESOURCE_DIMENSION dimension, std::uint32_t xbox_flags) { + return without_depth_stencil_uav(dimension, xbox_flags & kPcResourceFlagsMask); +} + // Strip Xbox-only flags and translate the Xbox tiled layout. Preserve all other layouts so the host can validate them. inline D3D12_RESOURCE_DESC pc_resource_desc(const D3D12_RESOURCE_DESC& xbox) { D3D12_RESOURCE_DESC pc = xbox; @@ -31,7 +48,7 @@ inline D3D12_RESOURCE_DESC pc_resource_desc(const D3D12_RESOURCE_DESC& xbox) { pc.Layout = pc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER ? D3D12_TEXTURE_LAYOUT_ROW_MAJOR : D3D12_TEXTURE_LAYOUT_UNKNOWN; } - pc.Flags = static_cast(static_cast(xbox.Flags) & kPcResourceFlagsMask); + pc.Flags = static_cast(pc_resource_flags(xbox.Dimension, static_cast(xbox.Flags))); return pc; } diff --git a/runtime/shims/d3d12_xs_device.cpp b/runtime/shims/d3d12_xs_device.cpp index 2f0b547d8b..a016fd203e 100644 --- a/runtime/shims/d3d12_xs_device.cpp +++ b/runtime/shims/d3d12_xs_device.cpp @@ -2441,6 +2441,10 @@ HRESULT proxy_create_resource(DeviceProxy* self, const D3D12_HEAP_PROPERTIES* he const auto xbox_layout = static_cast(pc_desc.Layout); pc_desc.Layout = pc_desc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER ? D3D12_TEXTURE_LAYOUT_ROW_MAJOR : D3D12_TEXTURE_LAYOUT_UNKNOWN; + // A console depth-stencil texture may allow unordered access; the PC one may not (without_depth_stencil_uav, the + // slot 25 stand-in). Only that bit is dropped here: the other flag bits go on as they came. + pc_desc.Flags = static_cast( + without_depth_stencil_uav(pc_desc.Dimension, static_cast(pc_desc.Flags))); static std::atomic logged{false}; if (!logged.exchange(true, std::memory_order_relaxed)) { @@ -2904,6 +2908,14 @@ void* WINAPI proxy_get_resource_allocation_info(std::uint64_t a0, std::uint64_t for (UINT i = 0; i < desc_count; ++i) { const auto& desc = descs[i]; clean[i] = call.console_abi || desc.Layout == kXboxTiledResourceLayout ? pc_resource_desc(desc) : desc; + static std::atomic uav_dropped{false}; + if (((static_cast(desc.Flags) & ~static_cast(clean[i].Flags)) & + D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS) && + first_call(uav_dropped)) + std::fprintf(stderr, + "[rt] d3d12_xs: slot 25: depth-stencil texture (format %d) sized without unordered " + "access, which the PC refuses with it (stand-in)\n", + static_cast(desc.Format)); } descs = clean.get(); } diff --git a/runtime/test/device_proxy_test.cpp b/runtime/test/device_proxy_test.cpp index 933674952f..1c6ff1fabb 100644 --- a/runtime/test/device_proxy_test.cpp +++ b/runtime/test/device_proxy_test.cpp @@ -244,6 +244,44 @@ int main(int argc, char** argv) { const D3D12_RESOURCE_ALLOCATION_INFO pc_info = device->GetResourceAllocationInfo(0, 1, &desc); check(pc_info.SizeInBytes == want.SizeInBytes && pc_info.Alignment == want.Alignment, "slot 25 still answers the PC (C++) form"); + + // A console depth-stencil texture that allows unordered access too, as a title sizes one: a 2D + // R32G8X24_TYPELESS texture with ALLOW_DEPTH_STENCIL | ALLOW_UNORDERED_ACCESS and the console layout word. The + // PC device refuses the flag pair (negative control); slot 25 sizes it as the depth-stencil texture alone. + D3D12_RESOURCE_DESC ds_uav{}; + ds_uav.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; + ds_uav.Width = 2560; + ds_uav.Height = 1440; + ds_uav.DepthOrArraySize = 1; + ds_uav.MipLevels = 1; + ds_uav.Format = DXGI_FORMAT_R32G8X24_TYPELESS; + ds_uav.SampleDesc.Count = 1; + ds_uav.Layout = static_cast(0x101); + ds_uav.Flags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL | D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; + D3D12_RESOURCE_DESC pc_pair = ds_uav; + pc_pair.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN; + check(real->GetResourceAllocationInfo(0, 1, &pc_pair).SizeInBytes == UINT64_MAX, + "the PC device refuses a depth-stencil texture with unordered access (negative control)"); + D3D12_RESOURCE_DESC ds_only = pc_pair; + ds_only.Flags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL; + const D3D12_RESOURCE_ALLOCATION_INFO ds_want = real->GetResourceAllocationInfo(0, 1, &ds_only); + check(ds_want.SizeInBytes != UINT64_MAX, "WARP sizes the depth-stencil texture without unordered access"); + const D3D12_RESOURCE_DESC ds_clean = rt::d3d12_xs::pc_resource_desc(ds_uav); + check(ds_clean.Flags == D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL, + "pc_resource_desc drops unordered access from a depth-stencil texture"); + D3D12_RESOURCE_DESC uav_buffer = buffer_desc(); + uav_buffer.Flags = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; + D3D12_RESOURCE_DESC rt_uav = ds_only; + rt_uav.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + rt_uav.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; + check(rt::d3d12_xs::pc_resource_desc(uav_buffer).Flags == D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS && + rt::d3d12_xs::pc_resource_desc(rt_uav).Flags == rt_uav.Flags, + "pc_resource_desc keeps unordered access on buffers and color textures"); + D3D12_RESOURCE_ALLOCATION_INFO ds_got{~0ull, ~0ull}; + get_alloc_info(&ds_got, device.Get(), 0, 1, &ds_uav); + check(ds_got.SizeInBytes != UINT64_MAX && ds_got.SizeInBytes >= ds_want.SizeInBytes && + (ds_got.SizeInBytes >> 32) == 0, + "slot 25 (C ABI) sizes a console depth-stencil texture with unordered access"); } D3D12_RESOURCE_DESC reserved_desc = buffer_desc(); From 028a414fade7058a96e5933d1325f374a0026588 Mon Sep 17 00:00:00 2001 From: Mumogg <104529023+Mumogg@users.noreply.github.com> Date: Mon, 23 Nov 2026 23:00:37 -0600 Subject: [PATCH 6/6] d3d12_xs: the title's queue slots 16 and 17 with a fence are Signal and Wait Queue slots 16 and 17 are GetTimestampFrequency(UINT64*) and GetClockCalibration(UINT64*, UINT64*) on the PC: both write through their first argument. The retail title calls slot 16 with one of its fences and a value, the shape of Signal(fence, value). On the console queue Signal and Wait sit two later than on the PC, at 16 and 17, as the frequency getter does at 18. Forwarded by number, the call wrote the frequency over the first word of the fence proxy, its vtable pointer; the title's next call on that fence went through a null pointer. The title's call (set_console_caller) whose first argument is a fence proxy now goes to the PC Signal or Wait with the real fence. A host caller keeps the PC getters, and so does a title call whose first argument is no object of this proxy, which cannot be a Signal. Same family as the slot 18 change: the console queue order of old PR 2490 (Nolan Cotter), as one rule for main's queue proxy. xs_proxy_mock_test: both slots with a fence reach the mock queue's slots 14 and 15 with the real fence, the fence proxy's first word is unchanged, and the non-fence and host calls reach slot 16. Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_01HxBQf4pXH8PWpC5oZsM4bt --- runtime/shims/d3d12_xs_device.cpp | 16 ++++++++++++++++ runtime/test/xs_proxy_mock_test.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/runtime/shims/d3d12_xs_device.cpp b/runtime/shims/d3d12_xs_device.cpp index a016fd203e..37cf880548 100644 --- a/runtime/shims/d3d12_xs_device.cpp +++ b/runtime/shims/d3d12_xs_device.cpp @@ -1565,6 +1565,22 @@ 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 == kQueueSignal + 2 || Slot == kQueueWait + 2)) { + // Queue slots 16 and 17 are GetTimestampFrequency(UINT64*) and GetClockCalibration(UINT64*, UINT64*) on + // the PC: they write through their first argument. The retail title calls slot 16 with one of its fences + // and a value, the shape of Signal(fence, value): on the console queue Signal and Wait sit at 16 and 17, + // two later than on the PC, as the frequency getter does at 18 (above). Forwarded by number, the call + // wrote the frequency over the fence proxy's first word, its vtable pointer, and the title's next call on + // that fence went through a null pointer. The title's call with a fence proxy therefore goes to the PC + // Signal or Wait with the real fence. A host caller keeps the PC methods, and so does a call whose first + // argument is no object of this proxy, which cannot be a Signal. + if (is_console_caller(_ReturnAddress())) { + if (IUnknown* fence = proxy_real_object(reinterpret_cast(a1))) { + using Fn = HRESULT(WINAPI*)(void*, IUnknown*, UINT64); + return hr_to_u64(reinterpret_cast(self->real_vtable[Slot - 2])(self->real, fence, 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*), diff --git a/runtime/test/xs_proxy_mock_test.cpp b/runtime/test/xs_proxy_mock_test.cpp index 3f447a2236..dab757b974 100644 --- a/runtime/test/xs_proxy_mock_test.cpp +++ b/runtime/test/xs_proxy_mock_test.cpp @@ -1194,6 +1194,31 @@ int check_xbox_queue_slots() { raw(queue, 18, word(&host_desc)); EXPECT(queue_mock->calls[16] == 1 && queue_mock->calls[18] == 2); + // Queue slots 16 and 17. The title's call with one of its fences is Signal or Wait, PC slots 14 and 15, with + // the real fence, and never the PC slots 16 and 17, which write through their first argument (the frequency + // went over the fence proxy's vtable pointer). A host caller keeps the PC getters, and so does a title call + // whose first argument is no proxy. + void* fence = make_fence(device); + EXPECT(fence); + Mock* const fence_mock = reinterpret_cast(xs::fence_proxy_real_fence(fence)); + void* const fence_vtable_before = *reinterpret_cast(fence); + xs::set_console_caller([](std::uint64_t) { return true; }); + const std::uint64_t signal14 = queue_mock->calls[14], wait15 = queue_mock->calls[15]; + raw(queue, 16, word(fence), 7); + EXPECT(queue_mock->calls[14] == signal14 + 1 && queue_mock->calls[16] == 1); + EXPECT(queue_mock->args[14][0] == word(fence_mock) && queue_mock->args[14][1] == 7); + raw(queue, 17, word(fence), 9); + EXPECT(queue_mock->calls[15] == wait15 + 1 && queue_mock->calls[17] == 0); + EXPECT(queue_mock->args[15][0] == word(fence_mock) && queue_mock->args[15][1] == 9); + EXPECT(*reinterpret_cast(fence) == fence_vtable_before); + std::uint64_t out16 = 0; + raw(queue, 16, word(&out16)); // the title, but no fence: the PC getter + EXPECT(queue_mock->calls[16] == 2 && queue_mock->args[16][0] == word(&out16)); + xs::set_console_caller(nullptr); + raw(queue, 16, word(&out16)); // a host caller + EXPECT(queue_mock->calls[16] == 3 && queue_mock->calls[14] == signal14 + 1); + EXPECT(release(fence) == 0); + 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);