Libretro: Correctly update the boot process

Made untested changes after #20183 - surprise, it didn't work.

Thanks @Duarte475 for reporting.

Fixes #20189
This commit is contained in:
Henrik Rydgård 2025-03-31 14:16:17 +02:00
parent 08dddbe470
commit 940e2375aa
3 changed files with 42 additions and 28 deletions

View file

@ -512,8 +512,6 @@ bool PSP_InitStart(const CoreParameter &coreParam) {
return false;
}
_dbg_assert_(coreState != CORE_POWERUP);
coreState = CORE_POWERUP;
g_bootState = BootState::Booting;
@ -616,6 +614,7 @@ BootState PSP_InitUpdate(std::string *error_string) {
if (!gpu) { // should be!
INFO_LOG(Log::System, "Starting graphics...");
Draw::DrawContext *draw = g_CoreParameter.graphicsContext ? g_CoreParameter.graphicsContext->GetDrawContext() : nullptr;
// This set the `gpu` global.
bool success = GPU_Init(g_CoreParameter.graphicsContext, draw);
if (!success) {
*error_string = "Unable to initialize rendering engine.";

View file

@ -8,13 +8,16 @@ You can probably really skip most of the packages but you need make:
pacman -S make
"Install" the plugin in Retroarch.
Start Retroarch ones to create the cores directory.
Then use the following in msys:
cd libretro
> cd libretro
> make platform=windows_msvc2019_desktop_x64 -j32 && cp ppsspp_libretro.* /d/retroarch/cores
make platform=windows_msvc2019_desktop_x64 -j32 && cp ppsspp_libretro.* /d/retroarch/cores
To make a debug build:
> make DEBUG=1 platform=windows_msvc2019_desktop_x64 -j32
Note that the latter part copies the DLL/PDB into wherever retroarch reads it from. Might need to adjust the path,
and adjust -j32 depending on your number of logical CPUs - might not need that many threads (or you might need more...).
@ -23,8 +26,8 @@ Also, the "2019" part has no significance, it seems - it's fine even if you're o
(plain make without a platform parameter doesn't work - g++ isn't able to build the D3D11 stuff, or at least it fails to link).
To debug from within MSVC, open retroarch.exe (or retroarch_debug.exe) as a Project/Solution, then open a few of the cpp files,
set some breakpoints and just launch using F5.
To debug from within MSVC, open retroarch.exe (or retroarch_debug.exe) as a Project/Solution (important! Not as File), then open a few of the cpp files,
set some breakpoints and just launch using F5. Then just choose the core and game in retroarch.
Useful libretro/vulkan sample code:

View file

@ -104,6 +104,8 @@ namespace Libretro
static retro_input_state_t input_state_cb;
static retro_log_printf_t log_cb;
bool g_pendingBoot = false;
static bool detectVsyncSwapInterval = false;
static bool detectVsyncSwapIntervalOptShown = true;
static bool softwareRenderInitHack = false;
@ -1326,12 +1328,14 @@ namespace Libretro
if (ctx->GetDrawContext())
ctx->GetDrawContext()->BeginFrame(Draw::DebugFlags::NONE);
gpu->BeginHostFrame();
if (gpu)
gpu->BeginHostFrame();
coreState = CORE_RUNNING_CPU;
PSP_RunLoopWhileState();
gpu->EndHostFrame();
if (gpu)
gpu->EndHostFrame();
if (ctx->GetDrawContext()) {
ctx->GetDrawContext()->EndFrame();
@ -1473,6 +1477,8 @@ bool retro_load_game(const struct retro_game_info *game)
// set cpuCore from libretro setting variable
coreParam.cpuCore = (CPUCore)g_Config.iCpuCore;
g_pendingBoot = true;
std::string error_string;
if (!PSP_InitStart(coreParam)) {
// Can't really fail, the errors happen later during InitUpdate
@ -1497,6 +1503,8 @@ bool retro_load_game(const struct retro_game_info *game)
set_variable_visibility();
// NOTE: At this point we haven't really booted yet, but "in-game" we'll just keep polling
// PSP_InitUpdate until done.
return true;
}
@ -1626,28 +1634,32 @@ static void retro_input(void)
void retro_run(void)
{
if (PSP_GetBootState() != BootState::Complete)
{
if (g_pendingBoot) {
std::string error_string;
while (true) {
BootState state = PSP_InitUpdate(&error_string);
if (state == BootState::Failed) {
ERROR_LOG(Log::Boot, "%s", error_string.c_str());
environ_cb(RETRO_ENVIRONMENT_SHUTDOWN, nullptr);
return;
} else if (state == BootState::Complete) {
break;
}
sleep_ms(4, "libretro-init-poll");
BootState state = PSP_InitUpdate(&error_string);
if (state == BootState::Failed) {
g_pendingBoot = false;
ERROR_LOG(Log::Boot, "%s", error_string.c_str());
environ_cb(RETRO_ENVIRONMENT_SHUTDOWN, nullptr);
return;
} else if (state == BootState::Booting) {
// Not done yet. Do maintenance stuff and bail.
retro_input();
ctx->SwapBuffers();
return;
}
if (softwareRenderInitHack)
{
log_cb(RETRO_LOG_DEBUG, "Software rendering init hack for opengl triggered.\n");
softwareRenderInitHack = false;
g_Config.bSoftwareRendering = true;
retro_reset();
}
// Here's where we finish the boot process.
g_pendingBoot = false;
}
// TODO: This seems dubious.
if (softwareRenderInitHack)
{
log_cb(RETRO_LOG_DEBUG, "Software rendering init hack for opengl triggered.\n");
softwareRenderInitHack = false;
g_Config.bSoftwareRendering = true;
retro_reset();
}
check_variables(PSP_CoreParameter());