From 0fbf68fa1530f3b868ec507b8489f350e4c4e8ad Mon Sep 17 00:00:00 2001 From: Takoroka <137927095+Takoroka@users.noreply.github.com> Date: Tue, 27 Oct 2026 19:49:20 -0400 Subject: [PATCH] Switch 2: vi2 present/cancel replies and syncpt QueryCounter vi2 229/228 (PresentClientBuffer/CancelClientBuffer) reply with the mask of slots the client may acquire next; syncpt 103 (QueryCounter) returns the host1x value of ~counter. Names and reply shapes from changes.patch. Title 4 now runs its render loop, presenting window images 1-3 in turn (730 GPU submissions in 60 s); nothing is shown yet. --- src/core/hle/service/nx2_gsv.h | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/core/hle/service/nx2_gsv.h b/src/core/hle/service/nx2_gsv.h index c409c39ff8..b17c8b6d12 100644 --- a/src/core/hle/service/nx2_gsv.h +++ b/src/core/hle/service/nx2_gsv.h @@ -102,6 +102,7 @@ public: {0, &INx2SyncptSession::Handshake, "Handshake"}, {1, &INx2SyncptSession::GetCount, "GetCount (guessed)"}, {22, &INx2SyncptSession::GetSlotEvent, "GetSlotEvent (guessed)"}, + {103, &INx2SyncptSession::QueryCounter, "QueryCounter"}, {201, &INx2SyncptSession::RequestSlotEvent, "RequestSlotEvent (guessed)"}, {202, &INx2SyncptSession::CancelSlotEvent, "CancelSlotEvent (guessed)"}, }); @@ -129,6 +130,16 @@ private: TipcReplyWords(ctx, {32}); } + // From changes.patch: the counter is the bitwise NOT of the host1x syncpoint id. + void QueryCounter(HLERequestContext& ctx) { + const u32 syncpoint = ~ctx.CommandBuffer()[2]; + const u64 value = syncpoint < HostSyncpoints + ? system.Host1x().GetSyncpointManager().GetGuestSyncpointValue(syncpoint) + : 0; + LOG_DEBUG(Service, "nx2:syncpt 103 syncpoint={} value={:#x}", syncpoint, value); + TipcReplyWords(ctx, {static_cast(value), static_cast(value >> 32), 0}); + } + void GetSlotEvent(HLERequestContext& ctx) { const u32 slot = ctx.CommandBuffer()[2]; LOG_WARNING(Service, "(STUBBED) nx2:syncpt TIPC 22 slot={:#x}, returning an event", slot); @@ -403,6 +414,8 @@ public: {11, &INx2Vi2Session::ReturnEvent, "Unknown11"}, {31, &INx2Vi2Session::ReturnEvent, "Unknown31"}, {32, &INx2Vi2Session::ReturnEvent, "Unknown32"}, + {228, &INx2Vi2Session::CancelClientBuffer, "CancelClientBuffer"}, + {229, &INx2Vi2Session::PresentClientBuffer, "PresentClientBuffer"}, }); } @@ -413,6 +426,28 @@ public: } private: + // 229(u64 client token, u32 slot, u32 image, ...fences): result, u64 mask of buffer slots the + // client may acquire next, four zero words. Nothing is shown yet; every slot is handed back + // at once (changes.patch's default mask is 0x7fff). + void PresentClientBuffer(HLERequestContext& ctx) { + const auto* w = ctx.CommandBuffer(); + ++m_presents; + if (m_presents <= 4 || (m_presents % 600) == 0) { + LOG_INFO(Service, "nx2:vi2 229 present #{} token={:#x} slot={} image={}", m_presents, + u64{w[2]} | (u64{w[3]} << 32), w[4], w[5]); + } + constexpr u64 AvailableSlots = 0x7fff; + TipcReplyWords(ctx, {static_cast(AvailableSlots), + static_cast(AvailableSlots >> 32), 0, 0, 0, 0}); + } + + // 228(u64 token, u32 slot): return a buffer without presenting it. + void CancelClientBuffer(HLERequestContext& ctx) { + constexpr u64 AvailableSlots = 0x7fff; + TipcReplyWords(ctx, {static_cast(AvailableSlots), + static_cast(AvailableSlots >> 32), 0, 0, 0, 0}); + } + void ReturnOne(HLERequestContext& ctx) { LOG_WARNING(Service, "(STUBBED) nx2:vi2 TIPC {}, returning 1", ctx.GetCommand()); TipcReplyWords(ctx, {1}); @@ -436,6 +471,7 @@ private: KernelHelpers::ServiceContext m_context; std::vector m_events; + u64 m_presents{}; }; // Native memory and images handed out by the Switch 2 graphics server (gsv 111/114/423/429/315),