Commit Graph
120 Commits
Author SHA1 Message Date
libretroadmin c60feaede6 Include the standard headers that newer code uses directly
These files use std::function, std::map, std::deque, std::unique_ptr or std::string_view and got
the header through others, which MSVC's standard library doesn't always do.
2026-10-09 09:46:15 +02:00
libretroadmin 3f225d06c1 Recycle MpscQueue nodes and keep host time out of emulated state
A drained MpscQueue node goes onto a free stack shared by every queue of the same type, and a
producer takes that stack whole when its own thread's list runs dry, so once warmed up a push
no longer allocates. That takes the heap allocation back off memory block notifications, the
CPU queue, Vulkan deletes and the GL render queue. A unit test runs several producers against
one consumer over two rounds.

The NpSignin dialog's delays run on emulated time and are saved with the state, so the dialog
behaves the same at any speed and under run-ahead. The time since the last save and savestate
goes; only the standalone frontends' exit prompts read it.
2026-10-09 08:28:29 +02:00
libretroadmin f1208a7a5a Make threading lock-free
The core and the headless tools no longer use mutexes, condition variables,
spinlocks, std::atomic, std::thread or volatile flags. Threads hand off through
libretro-common's retro_atomic and rthreads plus a few small pieces on top of
them in Common/Thread: Thread, MpscQueue, EventCounter, ParkingLot waits and
ReaderGate. Every wait blocks until it's woken; nothing polls on a timer.

State that only one thread touches just loses its lock. The PSP filesystem,
sceIo and the savedata dialog now belong to the emulation thread: async reads
and writes run when they're queued and complete later in emulated time, and
the IO and savedata threads are gone. The friend finder only talks to the
adhoc server and hands what it gets to the emulation thread. GPU init always
runs on the thread that starts the game.

The Vulkan render and compile queues, pipeline and render pass caches, delete
list and SPIR-V cache, the GL render queue, the software renderer's jit caches,
the file loader caches, the web debugger, UPnP, input, savestates, logging and
the GE debugger all hand off through queues and atomics. The IR jit's spinning
profiler thread goes.

A CPU thread with nothing to run now sleeps until work is queued instead of
spinning. Headless with --debugger waits for a client while stopped, and ends
the run once every client that connected has left. Web server shutdown keeps
servicing the CPU queue until the server has finished.
2026-10-09 04:56:16 +02:00
libretroadmin f0b97a2e90 Remove the standalone frontends
The libretro core is the frontend, and the headless tools are the test and
debugging hosts. The Windows, UWP, Android, iOS, macOS and SDL apps, the UI
framework and imgui go, along with what only they used: the Win32 debugger
hooks (g_frameMutex, the shutdown lock), JNI thread attachment, the Android
text drawer, RAIntegration, Discord, recent files, game installs, tilt input,
the audio resamplers, the control mapper, memstick moving and the remote ISO
and upload server modes. The web server keeps the debugger. The MSVC, Gradle
and ndk-build projects go too.
2026-10-09 04:56:10 +02:00
libretroadmin 9f13f0f051 Remove sleeps and timed polling from the emulation and render paths
The core no longer sleeps to pace itself: the frontend runs retro_run at
its own rate, so the frame throttle, the idle-vblank delay and the real
clock sync event (and its core option) are gone, and a stepping CPU hands
straight back instead of waiting 2 ms. Waits that polled now park on a
lock-free eventcount through Common/Thread/ParkingLot and are woken by
whoever changes the state: a paused GL emu thread, which also queues a
marker behind its last frame so pausing runs the render queue up to it
instead of polling; async I/O results; the software renderer when its
queue is full; Vulkan pipeline compiles; and debugger requests once
stepping ends. Boot joins the loader thread, cache shutdown joins its
read-ahead thread, and the slow-I/O simulation is removed.

The path browser, the HTTP and WebSocket servers, the Windows console and
the game info cache are left out of the core build. libretro/test gains
lrgltest, which drives the GL backend on a surfaceless EGL context through
every path that pauses or stops the emu thread; run.sh and the image
checks CI job run it on llvmpipe.
2026-10-08 17:58:42 +02:00
Henrik RydgårdandClaude Sonnet 5 0f792defb4 CountingBarrier: use notify_all instead of chained notify_one
The notify_one chain (each waiter wakes exactly one more) was correct
but fragile and non-obvious. notify_all is simpler and just as cheap
here since Arrive() is not a hot path.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L4QAoxV2KY7ek4PcZw3WvY
2026-08-09 19:03:28 +02:00
Henrik RydgårdandClaude Sonnet 5 973a10473a ParallelLoop: make loop tasks cancellable to avoid hang on Teardown
SimpleParallelTask/LoopRangeTask never overrode Cancellable(), so a
ThreadManager::Teardown() racing with an in-flight parallel loop would
drop them without ever calling counter_->Count(), leaving anyone
blocked in WaitableCounter::Wait() stuck forever. Cancel() now counts
down the same as a normal completion.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L4QAoxV2KY7ek4PcZw3WvY
2026-08-09 19:03:28 +02:00
Henrik RydgårdandClaude Sonnet 5 ceb3e9a0ad ThreadManager: fix teardown crash and task leak, remove dead code
- ~ThreadManager() never stopped worker threads before freeing the
  global context. If Teardown() wasn't reached before process exit
  (e.g. an early return between Init() and a caller's shutdown path),
  the still-running threads kept touching freed mutexes/queues/condvars,
  causing intermittent crashes on exit. The destructor now tears down
  if still initialized.
- Teardown() silently leaked any non-cancellable task still sitting in
  a queue (global or per-thread) at shutdown time - such tasks were
  never run nor released, since nothing drains those queues once the
  worker threads have been marked cancelled/joined. Now every queued
  task is properly cancelled-or-warned and released.
- Added an assert against a divide-by-zero in EnqueueTask's round-robin
  fallback, which would trigger if Init() were ever called with zero
  compute threads.
- Removed Task::id()/Kind() and ThreadManager::TryCancelTask(), which
  were unused dead code (TryCancelTask was a no-op with no callers).
- Fixed a stale comment on EnqueueTaskOnThread referencing a parameter
  that doesn't exist, and an auto-typed ternary that misleadingly read
  like a deque array copy (it's a pointer, not a copy).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L4QAoxV2KY7ek4PcZw3WvY
2026-08-09 19:03:08 +02:00
Henrik Rydgård e59aa11987 Raise the limits for when we use parallelism in ParallelMemcpy 2026-08-07 11:44:01 +02:00
Henrik Rydgård 00a566514e Buildfixes 2026-07-21 14:00:02 +02:00
Herman Semenoff fc0812061e threadmanager: remove detect cpu max 16 threads for compute
Removing restrictions greatly improves performance software rendering on multi-core systems above 16 threads.
2026-03-23 02:56:46 +03:00
Henrik Rydgård 2c0bdcf678 InstallZipScreen improvements, small cleanup 2026-02-10 11:34:59 +01:00
Henrik Rydgård 7fe30d6f2d Fix OpenGL exit hang on Windows 2025-08-31 11:37:05 +02:00
Henrik Rydgård 93638c8826 Test fix 2025-08-24 15:46:35 +02:00
Henrik Rydgård f6050a442c Fix serving the remote debugger locally, add a setting for the auto-launcher 2025-08-24 11:17:19 +02:00
Henrik Rydgård 70f1edb28f Misc sanity checks 2025-06-14 08:45:02 +02:00
Henrik Rydgård 435f523997 Replacement textures: Don't spend frame time waiting for a texture to be finished
It's better to finish rendering the frame and have the texture ready for
the next one, without wasting CPU.

However, if the user set their texture load speed to "Instant", that
means they never want to see any original textures. So in that case, we
do still wait.

Fixes #20519
2025-06-13 23:31:02 +02:00
Henrik Rydgård 44d06ec42f Add some sanity checks guided by Android crash reports 2025-06-07 16:35:19 +02:00
Henrik Rydgård 6b987fa4ac MemstickScreen: Cleanly cancel instead of blocking the back button if space calculation is underway 2025-05-28 15:27:00 +02:00
Henrik Rydgård 8e206d891f Add some paranoid checking to avoid a weird crash seen in logs 2025-05-15 20:40:26 +02:00
Henrik Rydgård fba2489c79 Remove dubious parallelization in ELF loading, initialize a var, add some checks 2025-05-15 09:48:23 +02:00
Henrik Rydgård acad90a041 More work on the lua console 2025-03-27 14:26:48 +01:00
Henrik Rydgård e5d00ce493 Fix startup on Android, oops
Forgot that we can't create android-compatible threads in global
constructors, for JNI reasons.
2025-03-27 01:58:53 +01:00
Henrik Rydgård a3a7807aac Fix crash when taking screenshots on a thread
Forgot that we only enable android JNI on "I/O" threads.

Fixes #20139
2025-03-21 19:12:54 +01:00
Henrik Rydgård b421c0791f Perform screenshot processing (including image encode) on background tasks 2025-03-20 20:48:51 +01:00
Henrik Rydgård cb1df4056c Remove almost-empty files ThreadPools.cpp/h 2025-03-20 17:21:20 +01:00
oltolm 9566065455 make compile on mingw-w64 2025-01-11 01:25:27 +01:00
Henrik Rydgård 3743b5dea6 Add new minimal-overhead RunParallel function 2024-12-29 10:48:00 +01:00
Henrik Rydgård 080798b5dd Move out two more functions from Core.cpp. Clean up Windows includes 2024-12-08 12:12:02 +01:00
Henrik Rydgård 7cbb60fd22 Bypass the PSP file system when calculating the savedata size to avoid a lock 2024-11-29 14:43:13 +01:00
Henrik Rydgård e01ca5b057 Logging API change (refactor) (#19324)
* Rename LogType to Log

* Explicitly use the Log:: enum when logging. Allows for autocomplete when editing.

* Mac/ARM64 buildfix

* Do the same with the hle result log macros

* Rename the log names to mixed case while at it.

* iOS buildfix

* Qt buildfix attempt, ARM32 buildfix
2024-07-14 14:42:59 +02:00
Henrik Rydgård 3802d4ee16 Try to resolve another race condition. Improve an assert. 2024-02-03 10:54:16 +01:00
Henrik Rydgård ee62ffdb02 Audit our use of condition variables, fix some minor issues 2024-01-29 11:09:08 +01:00
Henrik Rydgård 622aeaab6d Hopefully robustify some logic in EmuScreen enough 2024-01-24 00:06:01 +01:00
Henrik Rydgård c1a7235767 Fix another shutdown race condition in the Vulkan backend 2024-01-15 17:06:00 +01:00
Henrik Rydgård f8927df9a6 Load savestate screenshots in the background 2023-12-13 12:07:23 +01:00
Henrik Rydgård 6a8f65b566 Some assert paranoia, remove unused "failed_" variable 2023-09-23 10:09:32 +02:00
Henrik Rydgård f0f96750b1 After picking a task from the global queue, gotta break from the loop. 2023-03-15 22:31:24 +01:00
Henrik Rydgård 1cf4e83824 Show thread name in assert messagebox caption on Windows. Minor cleanup 2023-03-15 22:26:58 +01:00
Henrik Rydgård e625727543 Fix debug symbols for ThreadContext by renaming it (was clashing with something else)
Also reorder the fields.
2023-03-15 12:06:32 +01:00
Henrik Rydgård 1860a73d58 Address feedback from previous PR 2023-03-12 23:15:09 +01:00
Unknown W. Brackets c690b12669 ThreadManager: Use priority across global/thread. 2023-02-02 17:08:24 -08:00
Unknown W. Brackets 0971555e51 ThreadManager: Add simple priority queues.
This allows basic differentiation of priorities.
2023-02-02 17:08:24 -08:00
Unknown W. Brackets 88ba003f46 ThreadManager: Add a simple priority field.
Currently, not actually respected.
2023-02-02 17:08:24 -08:00
Henrik Rydgård 6b0903f566 Add facility to run tasks on dedicated threads using the ThreadManager interface.
Useful for things that should be run ASAP even if the threadpool is full,
at a small extra cost. (Not recommended for very small tasks).

Considering using this to resolve the deadlocks in #16802.
2023-01-31 11:07:40 +01:00
Unknown W. Brackets 3a6fa9b4ba ThreadManager: Don't allow reordering of queue.
Allowing a priority item is faster, but can cause confusion when you
expect things to run in the same sequence they're enqueued.
2023-01-14 16:35:01 -08:00
Henrik Rydgård 7672556e5c Better pipeline descriptions in shader viewer (shorter in overview, longer after click) 2023-01-09 11:22:35 +01:00
Henrik Rydgård ab6fafb6eb Invert dependency to avoid compile issues 2023-01-05 08:38:53 +01:00
Henrik Rydgård 7e374c9324 Address feedback, more fixes 2023-01-05 08:38:53 +01:00
Henrik Rydgård b56eef487c Strict mode checking - no way to forget detaching now.
And if we forget to attach, boom. Hopefully I caught all of them.
2023-01-05 08:38:52 +01:00