From bc44865cdafb60947a9a9e2fca59688ae3fa080c Mon Sep 17 00:00:00 2001 From: Stephen Miller <56742918+StevenMiller123@users.noreply.github.com> Date: Mon, 3 Nov 2025 13:06:26 -0600 Subject: [PATCH] Implement sceGnmDrawInitToDefaultContextStateInternal functions (#3770) These are used by LLE libSceVideodec. From decompiling the two GnmDriver libraries, it seems like sceGnmDrawInitToDefaultContextStateInternalCommand inlines a call to sceGnmDrawInitToDefaultContextState, so I've replaced that with an actual call to the function for readability. sceGnmDrawInitToDefaultContextStateInternalSize is one to one with decomp. --- src/core/libraries/gnmdriver/gnmdriver.cpp | 23 ++++++++++++++-------- src/core/libraries/gnmdriver/gnmdriver.h | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/core/libraries/gnmdriver/gnmdriver.cpp b/src/core/libraries/gnmdriver/gnmdriver.cpp index c3cf4554d..1181f6299 100644 --- a/src/core/libraries/gnmdriver/gnmdriver.cpp +++ b/src/core/libraries/gnmdriver/gnmdriver.cpp @@ -7,6 +7,7 @@ #include "common/assert.h" #include "common/config.h" #include "common/debug.h" +#include "common/elf_info.h" #include "common/logging/log.h" #include "common/slot_vector.h" #include "core/address_space.h" @@ -68,7 +69,7 @@ std::condition_variable cv_lock{}; std::mutex m_submission{}; static u64 frames_submitted{}; // frame counter static bool send_init_packet{true}; // initialize HW state before first game's submit in a frame -static int sdk_version{0}; +static s32 sdk_version{0}; static u32 asc_next_offs_dw[Liverpool::NumComputeRings]; @@ -2199,9 +2200,9 @@ int PS4_SYSV_ABI sceGnmSubmitCommandBuffersForWorkload(u32 workload, u32 count, } if (send_init_packet) { - if (sdk_version <= 0x1ffffffu) { + if (sdk_version < Common::ElfInfo::FW_20) { liverpool->SubmitGfx(InitSequence, {}); - } else if (sdk_version <= 0x3ffffffu) { + } else if (sdk_version < Common::ElfInfo::FW_40) { if (sceKernelIsNeoMode()) { if (!UseNeoCompatSequences) { liverpool->SubmitGfx(InitSequence200Neo, {}); @@ -2780,14 +2781,20 @@ int PS4_SYSV_ABI Func_C4C328B7CF3B4171() { return ORBIS_OK; } -int PS4_SYSV_ABI sceGnmDrawInitToDefaultContextStateInternalCommand() { - LOG_ERROR(Lib_GnmDriver, "(STUBBED) called"); - return ORBIS_OK; +int PS4_SYSV_ABI sceGnmDrawInitToDefaultContextStateInternalCommand(u32* cmdbuf, u32 size) { + LOG_TRACE(Lib_GnmDriver, "called"); + if (sdk_version >= Common::ElfInfo::FW_40) { + return sceGnmDrawInitToDefaultContextState400(cmdbuf, size); + } + return sceGnmDrawInitToDefaultContextState(cmdbuf, size); } int PS4_SYSV_ABI sceGnmDrawInitToDefaultContextStateInternalSize() { - LOG_ERROR(Lib_GnmDriver, "(STUBBED) called"); - return ORBIS_OK; + LOG_TRACE(Lib_GnmDriver, "called"); + if (sdk_version >= Common::ElfInfo::FW_40) { + return 0x100; + } + return 0x20; } int PS4_SYSV_ABI sceGnmFindResources() { diff --git a/src/core/libraries/gnmdriver/gnmdriver.h b/src/core/libraries/gnmdriver/gnmdriver.h index 1bb084b77..4001f4661 100644 --- a/src/core/libraries/gnmdriver/gnmdriver.h +++ b/src/core/libraries/gnmdriver/gnmdriver.h @@ -286,7 +286,7 @@ int PS4_SYSV_ABI Func_ECB4C6BA41FE3350(); int PS4_SYSV_ABI sceGnmDebugModuleReset(); int PS4_SYSV_ABI sceGnmDebugReset(); int PS4_SYSV_ABI Func_C4C328B7CF3B4171(); -int PS4_SYSV_ABI sceGnmDrawInitToDefaultContextStateInternalCommand(); +int PS4_SYSV_ABI sceGnmDrawInitToDefaultContextStateInternalCommand(u32* cmdbuf, u32 size); int PS4_SYSV_ABI sceGnmDrawInitToDefaultContextStateInternalSize(); int PS4_SYSV_ABI sceGnmFindResources(); int PS4_SYSV_ABI sceGnmGetResourceRegistrationBuffers();