VideoCommon: shader compiler workers below the emulation threads

The shader compiler's worker threads run at a lower priority than the
threads that emulate, on Windows (below normal) and Linux (nice 5): on
a machine with fewer cores than busy threads, what compiles in the
background waits, not the frame being emulated. Common gets
LowerCurrentThreadPriority for it.
This commit is contained in:
LibretroAdmin authored and libretroadmin committed 2026-11-06 23:45:19 +01:00
1 parent cd384472e6
commit 2dd80c5c2e
3 files changed
+23

No files matched your search

+15
View File
@@ -11,6 +11,11 @@
#include <unistd.h>
#endif
#ifdef __linux__
#include <sys/resource.h>
#include <sys/syscall.h>
#endif
#ifdef __APPLE__
#include <mach/mach.h>
#elif defined BSD4_4 || defined __FreeBSD__ || defined __OpenBSD__
@@ -43,6 +48,16 @@ void SetCurrentThreadName(const char* name)
sthread_setname(name);
}
void LowerCurrentThreadPriority()
{
#ifdef _WIN32
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_BELOW_NORMAL);
#elif defined(__linux__)
/* Linux keeps a nice value per thread: this one only */
setpriority(PRIO_PROCESS, (id_t)syscall(SYS_gettid), 5);
#endif
}
#ifndef _WIN32
/* A thread's stack does not move: asked once per thread, as glibc's
+5
View File
@@ -25,6 +25,11 @@ int CurrentThreadId();
void SetCurrentThreadName(const char* name);
// Below the threads that emulate, where the OS allows it: Windows and Linux.
// For background work, which then takes no time from a frame while one is
// being emulated, only what is left over.
void LowerCurrentThreadPriority();
// An sthread entry point that calls F on the object passed as the thread's userdata:
// m_thread = sthread_create(Common::ThreadEntry<&Foo::Run>, this);
template <auto F>
@@ -271,6 +271,9 @@ void AsyncShaderCompiler::WorkerThreadStart(void* worker)
void AsyncShaderCompiler::WorkerThreadEntryPoint(Worker* worker)
{
Common::SetCurrentThreadName("AsyncShaderCompiler Worker");
/* what is compiled in the background waits; the frame being emulated
* does not, on a machine with fewer cores than busy threads */
Common::LowerCurrentThreadPriority();
// Initialize worker thread with backend-specific method.
if (!WorkerThreadInitWorkerThread(worker->param))