From af72713272e2001d0f4ee3d34ae264592c9ea96a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 10 Oct 2026 12:45:47 +0200 Subject: [PATCH] SoftGPU: Pick the drawing thread count and lingering per platform Measured on an M1: lingering cost wall time at every length tried, as waking a thread is cheap on macOS, and seven or eight drawing threads beat six. So Apple platforms use eight and don't linger, and Android doesn't linger either (spinning costs battery). Windows and Linux keep six and lingering, which was measured under WSL2 only. Co-Authored-By: Claude Opus 5.5 (1M context) --- GPU/Software/BinManager.cpp | 2 ++ GPU/Software/BinManager.h | 20 +++++++++++++++++--- GPU/Software/TransformUnit.cpp | 2 ++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/GPU/Software/BinManager.cpp b/GPU/Software/BinManager.cpp index 89263806e2..81c1405c74 100644 --- a/GPU/Software/BinManager.cpp +++ b/GPU/Software/BinManager.cpp @@ -791,6 +791,8 @@ void BinManager::MakeRoom() { // It looks at the tiles again only when distributed_ says there's new work: reading their heads and tails over // and over took cache lines from the emulation thread, which writes the tails. void BinManager::LingerForWork(int start) { + if (!THREADS_LINGER) + return; double until = time_now_d() + LINGER_SECONDS; while (!waitingForIdle_.load(std::memory_order_relaxed)) { // Read before the look at the tiles, so work distributed during it isn't missed. diff --git a/GPU/Software/BinManager.h b/GPU/Software/BinManager.h index 0749026489..4757835ecb 100644 --- a/GPU/Software/BinManager.h +++ b/GPU/Software/BinManager.h @@ -17,6 +17,8 @@ #pragma once +#include "ppsspp_config.h" + #include #include #include "GPU/Software/Rasterizer.h" @@ -212,10 +214,22 @@ public: ~BinManager(); // More threads drawing slow the emulation thread down more than they help it, by taking from its core's - // share of power and clock speed (and with SMT, the core): in God of War and Wipeout on a 16 core Ryzen, - // six beat four, eight and all 31 the thread manager has. Under WSL2, where waking threads costs more than on - // bare metal: measure again there. + // share of power and clock speed (and with SMT, the core): in God of War and Wipeout on a 16 core Ryzen under + // WSL2, six beat four, eight and all 31 the thread manager has. An M1 does best with seven or eight. +#if PPSSPP_PLATFORM(MAC) || PPSSPP_PLATFORM(IOS) + static constexpr int MAX_DRAW_THREADS = 8; +#else static constexpr int MAX_DRAW_THREADS = 6; +#endif + // Whether drawing and transform threads out of work wait a moment for more, spinning, rather than end their + // tasks. Under WSL2, where waking a thread costs the waker about 15 us, it saved 4-8% of wall time; on macOS, + // where it's cheap, it cost wall time at every length tried. Not on Android either, where spinning costs + // battery. Unmeasured on native Windows and Linux. +#if (PPSSPP_PLATFORM(WINDOWS) || PPSSPP_PLATFORM(LINUX)) && !PPSSPP_PLATFORM(ANDROID) + static constexpr bool THREADS_LINGER = true; +#else + static constexpr bool THREADS_LINGER = false; +#endif void UpdateState(); void UpdateClut(const void *src); diff --git a/GPU/Software/TransformUnit.cpp b/GPU/Software/TransformUnit.cpp index b6e7b08bdc..c7db7bd840 100644 --- a/GPU/Software/TransformUnit.cpp +++ b/GPU/Software/TransformUnit.cpp @@ -89,6 +89,8 @@ struct TransformUnit::RunJob { } // A run after lastGen with chunks left to take, within the time a helper waits for one. bool WaitForRun(uint32_t lastGen, uint32_t *newGen) { + if (!BinManager::THREADS_LINGER) + return false; const double until = time_now_d() + LINGER_SECONDS; do { const uint64_t v = claim.load(std::memory_order_acquire);