From f2f70e5df8c8252d3f6860541d50e176a74619aa Mon Sep 17 00:00:00 2001 From: Exzap <13877693+Exzap@users.noreply.github.com> Date: Mon, 23 Mar 2026 17:11:49 +0100 Subject: [PATCH] GX2: Fix several missing/incorrect cmd reserve calls --- src/Cafe/OS/libs/gx2/GX2.cpp | 2 ++ src/Cafe/OS/libs/gx2/GX2_Draw.cpp | 2 +- src/Cafe/OS/libs/gx2/GX2_Event.cpp | 2 +- src/Cafe/OS/libs/gx2/GX2_Misc.cpp | 1 + src/Cafe/OS/libs/gx2/GX2_State.cpp | 1 + 5 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Cafe/OS/libs/gx2/GX2.cpp b/src/Cafe/OS/libs/gx2/GX2.cpp index b5e75b90..dcaa240b 100644 --- a/src/Cafe/OS/libs/gx2/GX2.cpp +++ b/src/Cafe/OS/libs/gx2/GX2.cpp @@ -294,6 +294,8 @@ void gx2Export_GX2SetSemaphore(PPCInterpreter_t* hCPU) } uint32 semaphoreControl = (SEM_SEL << 29); semaphoreControl |= 0x1000; // WAIT_ON_SIGNAL + + GX2::GX2ReserveCmdSpace(3); gx2WriteGather_submitU32AsBE(pm4HeaderType3(IT_MEM_SEMAPHORE, 2)); gx2WriteGather_submitU32AsBE(memory_virtualToPhysical(semaphoreMPTR)); // semaphore physical address gx2WriteGather_submitU32AsBE(semaphoreControl); // control diff --git a/src/Cafe/OS/libs/gx2/GX2_Draw.cpp b/src/Cafe/OS/libs/gx2/GX2_Draw.cpp index 958978e1..3a5fff5b 100644 --- a/src/Cafe/OS/libs/gx2/GX2_Draw.cpp +++ b/src/Cafe/OS/libs/gx2/GX2_Draw.cpp @@ -56,7 +56,7 @@ namespace GX2 void GX2DrawIndexedEx2(GX2PrimitiveMode2 primitiveMode, uint32 count, GX2IndexType indexType, void* indexData, uint32 baseVertex, uint32 numInstances, uint32 baseInstance) { - GX2ReserveCmdSpace(3 + 3 + 2 + 2 + 6); + GX2ReserveCmdSpace(3 + 3 + 3 + 2 + 2 + 6 + 3); gx2WriteGather_submit( // IT_SET_CTL_CONST pm4HeaderType3(IT_SET_CTL_CONST, 2), 0, diff --git a/src/Cafe/OS/libs/gx2/GX2_Event.cpp b/src/Cafe/OS/libs/gx2/GX2_Event.cpp index 3bb8e6a2..338b7d79 100644 --- a/src/Cafe/OS/libs/gx2/GX2_Event.cpp +++ b/src/Cafe/OS/libs/gx2/GX2_Event.cpp @@ -38,7 +38,7 @@ namespace GX2 void GX2SubmitUserTimeStamp(uint64* timestampOut, uint64 value, GX2PipeEventType eventType, uint32 triggerInterrupt) { - GX2ReserveCmdSpace(7); + GX2ReserveCmdSpace(11); MPTR physTimestampAddr = memory_virtualToPhysical(memory_getVirtualOffsetFromPointer(timestampOut)); uint32 valHigh = (uint32)(value >> 32); diff --git a/src/Cafe/OS/libs/gx2/GX2_Misc.cpp b/src/Cafe/OS/libs/gx2/GX2_Misc.cpp index 564b787e..ada03b2d 100644 --- a/src/Cafe/OS/libs/gx2/GX2_Misc.cpp +++ b/src/Cafe/OS/libs/gx2/GX2_Misc.cpp @@ -69,6 +69,7 @@ void gx2Export_GX2SampleBottomGPUCycle(PPCInterpreter_t* hCPU) // Whats a good solution here? Should we implement it correctly and instead rely on graphic pack patches to patch out the dynamic scaling? // some known affected games: Wind Waker HD, Super Mario 3D World + GX2::GX2ReserveCmdSpace(2); gx2WriteGather_submitU32AsBE(pm4HeaderType3(IT_HLE_SAMPLE_TIMER, 1)); gx2WriteGather_submitU32AsBE(hCPU->gpr[3]); osLib_returnFromFunction(hCPU, 0); diff --git a/src/Cafe/OS/libs/gx2/GX2_State.cpp b/src/Cafe/OS/libs/gx2/GX2_State.cpp index 795ff527..a85b5dce 100644 --- a/src/Cafe/OS/libs/gx2/GX2_State.cpp +++ b/src/Cafe/OS/libs/gx2/GX2_State.cpp @@ -648,6 +648,7 @@ namespace GX2 else { // legacy style + GX2ReserveCmdSpace(3); gx2WriteGather_submitU32AsBE(pm4HeaderType3(IT_HLE_SPECIAL_STATE, 2)); gx2WriteGather_submitU32AsBE((uint32)stateId); // state id gx2WriteGather_submitU32AsBE(isEnabled); // enable/disable bool