From afe9b09278a365d260d2e40a020f6bb20ae79894 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 27 Jul 2026 10:44:36 +0200 Subject: [PATCH] Headless: make ApplyToConfig() the final authority over g_Config Reordered main() to: g_Config.RestoreDefaults() -> headless's own hardcoded overrides for deterministic test execution -> cmdLineOptions.ApplyToConfig() -> CoreParameter setup -> launch. Previously ApplyToConfig() ran first and got silently overwritten by both RestoreDefaults() and the hardcoded overrides, so no command-line flag touching a g_Config setting actually took effect for a real run (this is what required the "set iRemoteISOPort again" workaround for --debugger=PORT, now removed). The two hardcoded lines that used to read coreParameter.renderScaleFactor/ gpuCore now compute the same values directly from cmdLineOptions/glWorking/ gpuCore instead, since CoreParameter is no longer built yet at that point - it's now constructed after ApplyToConfig(), which is what let those two comments' "above"/"below" wording get corrected too. Verified: --debugger=PORT still binds the exact requested port and pauses the CPU, and a normal --compare test run (cpu_alu) still passes. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01XDNwPPuidmNxQGRJxBuRL6 --- headless/Headless.cpp | 54 ++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/headless/Headless.cpp b/headless/Headless.cpp index 468566d9d8..b35e9915b7 100644 --- a/headless/Headless.cpp +++ b/headless/Headless.cpp @@ -544,7 +544,7 @@ int main(int argc, const char* argv[]) { g_logManager.EnableOutput(LogOutput::Printf); } - cmdLineOptions.ApplyToConfig(); + g_Config.RestoreDefaults(RestoreSettingsBits::SETTINGS | RestoreSettingsBits::CONTROLS | RestoreSettingsBits::RECENT, true); // Needs to be after log so we don't interfere with test output. g_threadManager.Init(cpu_info.num_cores, cpu_info.logical_cpu_count); @@ -556,26 +556,12 @@ int main(int argc, const char* argv[]) { GraphicsContext *graphicsContext = nullptr; bool glWorking = headlessHost->InitGraphics(&error_string, &graphicsContext, gpuCore); - CoreParameter coreParameter; - coreParameter.cpuCore = cpuCore; // apprently this gets overwritten somehow by g_Config below. - coreParameter.gpuCore = glWorking ? gpuCore : GPUCORE_SOFTWARE; - coreParameter.graphicsContext = graphicsContext; - coreParameter.enableSound = false; - coreParameter.mountIso = mountIso.empty() ? Path() : Path(mountIso); - coreParameter.mountRoot = mountRoot.empty() ? Path() : Path(mountRoot); - coreParameter.startBreak = false; - coreParameter.headLess = true; - coreParameter.renderScaleFactor = cmdLineOptions.resolutionScale.value_or(1); - coreParameter.renderWidth = 480 * coreParameter.renderScaleFactor; - coreParameter.renderHeight = 272 * coreParameter.renderScaleFactor; - coreParameter.pixelWidth = 480 * coreParameter.renderScaleFactor; - coreParameter.pixelHeight = 272 * coreParameter.renderScaleFactor; - coreParameter.fastForward = true; - - g_Config.RestoreDefaults(RestoreSettingsBits::SETTINGS | RestoreSettingsBits::CONTROLS | RestoreSettingsBits::RECENT, true); - + // Force known values for deterministic test execution. This happens before + // ApplyToConfig() below, so a matching command line flag can still override any of it - + // ApplyToConfig() always has the final say on the settings in g_Config. + // // Somehow this affects the test execution of pspautotests/tests/gpu/vertices/morph.prx, even though - // we actually set the cpu core in CoreParameter above. Probably because we end up using the JIT vs non-JIT + // we actually set the cpu core in CoreParameter below. Probably because we end up using the JIT vs non-JIT // vertex decoder. g_Config.iCpuCore = 0; @@ -600,10 +586,10 @@ int main(int argc, const char* argv[]) { g_Config.iDateFormat = PSP_SYSTEMPARAM_DATE_FORMAT_DDMMYYYY; g_Config.iButtonPreference = PSP_SYSTEMPARAM_BUTTON_CROSS; g_Config.iLockParentalLevel = 9; - g_Config.iInternalResolution = coreParameter.renderScaleFactor; + g_Config.iInternalResolution = cmdLineOptions.resolutionScale.value_or(1); g_Config.bEnableLogging = (fullLog || outputDebugStringLog); g_Config.bVertexDecoderJit = true; - g_Config.bSoftwareRendering = coreParameter.gpuCore == GPUCORE_SOFTWARE; + g_Config.bSoftwareRendering = (glWorking ? gpuCore : GPUCORE_SOFTWARE) == GPUCORE_SOFTWARE; g_Config.bSoftwareRenderingJit = true; g_Config.iSplineBezierQuality = 2; g_Config.bHighQualityDepth = true; @@ -619,6 +605,28 @@ int main(int argc, const char* argv[]) { g_Config.bUseOldAtrac = oldAtrac; g_Config.iForceEnableHLE = 0xFFFFFFFF; // Run all modules as HLE. We don't have anything to load in this context. + // ApplyToConfig() has the final say, applied after RestoreDefaults() and the headless + // overrides above, so a matching command line flag always wins. + cmdLineOptions.ApplyToConfig(); + + // TODO: This whole function should be refactored to set up CoreParameter in one place, + // but not now. + CoreParameter coreParameter; + coreParameter.cpuCore = cpuCore; // apprently this gets overwritten somehow by g_Config above. + coreParameter.gpuCore = glWorking ? gpuCore : GPUCORE_SOFTWARE; + coreParameter.graphicsContext = graphicsContext; + coreParameter.enableSound = false; + coreParameter.mountIso = mountIso.empty() ? Path() : Path(mountIso); + coreParameter.mountRoot = mountRoot.empty() ? Path() : Path(mountRoot); + coreParameter.startBreak = false; + coreParameter.headLess = true; + coreParameter.renderScaleFactor = cmdLineOptions.resolutionScale.value_or(1); + coreParameter.renderWidth = 480 * coreParameter.renderScaleFactor; + coreParameter.renderHeight = 272 * coreParameter.renderScaleFactor; + coreParameter.pixelWidth = 480 * coreParameter.renderScaleFactor; + coreParameter.pixelHeight = 272 * coreParameter.renderScaleFactor; + coreParameter.fastForward = true; + Path exePath = File::GetExeDirectory(); g_Config.flash0Directory = exePath / "assets/flash0"; @@ -672,8 +680,6 @@ int main(int argc, const char* argv[]) { UpdateUIState(UISTATE_INGAME); if (cmdLineOptions.debuggerPort.has_value()) { - // RestoreDefaults() above wiped what ApplyToConfig() set, so set it again here. - g_Config.iRemoteISOPort = cmdLineOptions.debuggerPort.value(); coreParameter.startBreak = true; StartWebServer(WebServerFlags::DEBUGGER); }