A Rust and egui based front-end for the SwanStation PS1 Libretro core
  • C++ 58%
  • C 36.4%
  • Rust 2.8%
  • HLSL 0.7%
  • GLSL 0.6%
  • Other 1.4%
Find a file
LibretroAdmin 7db7d2527d gpu_hw_d3d11 + gpu_hw_d3d12 + gpu_hw_vulkan: lower background shader-compile worker priority
The three backends with a background worker thread for shader
precompilation (D3D11, D3D12, Vulkan) currently spawn the worker
at default priority and let it run flat-out until the matrix is
filled. On a high-core-count machine with spare cycles this is
fine - the OS scheduler just gives the worker an unused core. But
on more constrained hardware the worker competes directly with
the runloop, CPU emulator, audio mixer, and frontend render
thread, all at the same priority. The OS time-slices between
them; with a heavy texture filter and a 144-2160 cell matrix
that's tens of seconds of contention immediately after boot or
texture-filter change. Even though the lock-free fast-path
commits (3d9d624, a29d202) eliminated the mutex-contention stall
on the draw side, raw CPU pressure can still cause frame drops
and audio glitches on low-spec setups.

Adds a tiny portable helper, common/thread_priority.h, with a
single LowerCurrentThreadPriority() function that drops the
calling thread to a 'below normal' scheduling class. Wired into
all three workers' entry points - it's the first thing they do.

Platform support:

  Windows: SetThreadPriority(GetCurrentThread(),
    THREAD_PRIORITY_BELOW_NORMAL). Straightforward, per-thread,
    well-supported.

  Linux: setpriority(PRIO_PROCESS, 0, +5). On Linux/NPTL this
    targets the calling THREAD rather than the whole process - a
    long-standing Linux deviation from POSIX, documented in
    setpriority(2). Verified empirically on this machine: a
    worker that called the helper saw its nice rise 0 -> 5 while
    the main thread it forked from stayed at 0. +5 is the
    conventional 'background work' offset, far below the default
    20 RLIMIT_NICE ceiling so no privileges needed.
    pthread_setschedparam with SCHED_OTHER is deliberately NOT
    used on Linux - SCHED_OTHER only accepts priority 0 there, so
    it would be a no-op.

  macOS / *BSD: pthread_setschedparam with SCHED_OTHER, target
    priority halfway between current and sched_get_priority_min.
    Halfway rather than absolute minimum because going all the
    way to min has historically caused priority-inversion
    deadlocks when a low-priority thread holds a mutex a
    high-priority thread is waiting on. BELOW_NORMAL-ish, not
    idle. Per-thread by virtue of pthread_setschedparam targeting
    pthread_self().

  Other Unices: same path as macOS/BSDs. Reasonable best-effort
    default; failure (return false) keeps the worker at default
    priority - no incorrect behaviour.

We deliberately avoid the POSIX-portable setpriority() with
PRIO_PROCESS on non-Linux platforms because POSIX defines it as
a per-process attribute, which would lower the priority of the
runloop and audio threads too - the exact opposite of what we
want.

All variants return bool. Failure is silent - the worker just
keeps running at whatever priority the platform gave it. The
helper has no side effects beyond the priority change itself.

OpenGL backend is intentionally unchanged: it has no background
worker thread (the libretro hardware-renderer protocol exposes
a single GL context bound to the runloop, so 'Lazy' mode degrades
to 'Disabled' per commit 5c9cf3e). Lowering the runloop's
priority would obviously be bad.

Build verification:
  - linux platform=unix: clean, zero warnings, .so 8040152
    (+48 bytes for the setpriority PLT call and the inline
    helper body in the Vulkan worker). 25 retro_* exports
    unchanged.
  - x86_64-w64-mingw32-g++ -fsyntax-only on gpu_hw_d3d11.cpp,
    gpu_hw_d3d12.cpp (with the existing ID3D12Debug stub
    workaround), and gpu_hw_vulkan.cpp: all clean. The
    WIN32_LEAN_AND_MEAN define is guarded with ifndef to avoid
    redefinition against windows_headers.h which defines it as 1.
  - Runtime smoke test on Linux: spawned a worker that called
    LowerCurrentThreadPriority(), confirmed worker nice 0 -> 5
    while main thread nice stayed at 0. Per-thread granularity
    validated.

Files added/touched:
  - src/common/thread_priority.h: new header, single inline
    function. Self-contained, no other dependencies.
  - src/core/gpu_hw_vulkan.cpp: include + call at top of
    ShaderCompileThreadEntryPoint.
  - src/core/gpu_hw_d3d11.cpp: include + call at top of
    ShaderCompileThreadEntryPoint.
  - src/core/gpu_hw_d3d12.cpp: include + call at top of
    ShaderCompileThreadEntryPoint.
2026-05-11 20:09:04 +02:00
CMakeModules Remove unused files 2023-03-25 17:43:35 +01:00
dep Make OpenBIOS a built-in fallback. 2026-03-28 10:43:30 +00:00
src gpu_hw_d3d11 + gpu_hw_d3d12 + gpu_hw_vulkan: lower background shader-compile worker priority 2026-05-11 20:09:04 +02:00
.clang-format clang-format: Enable brace wrapping after case label 2020-01-24 14:49:43 +10:00
.gitattributes Initial commit 2019-09-11 14:00:42 +10:00
.gitignore Sync Android strings 2021-07-17 20:14:40 +10:00
.gitlab-ci.yml Merge pull request #167 from cscd98/webos-ci 2026-04-10 05:12:17 +02:00
CMakeLists.txt build: add MSB_FIRST opt-in flag for big-endian hosts 2026-05-08 00:32:03 +02:00
libretro.osx.def libretro: add static Makefile.libretro build 2026-05-07 21:32:02 +02:00
LICENSE Initial commit 2019-09-11 14:00:42 +10:00
link.T libretro: add static Makefile.libretro build 2026-05-07 21:32:02 +02:00
Makefile.libretro audio: devirtualize AudioStream, fold NullAudioStream into LibretroAudioStream 2026-05-08 15:07:36 +02:00
README.md Documentation OpenBIOS usage in the README. 2026-04-02 10:46:10 +01:00
TODO Update TODO (#132) 2025-01-17 16:28:45 +01:00

SwanStation - PlayStation 1, aka. PSX Emulator

Features | System Requirements | Disclaimers

SwanStation is a hard fork and open-source Libretro core implementation of DuckStation, which is an emulator of the Sony PlayStation(TM) console, focusing on playability, speed, and long-term maintainability. The goal is to be as accurate as possible while maintaining performance suitable for low-end devices. "Hack" options are discouraged, the default configuration should support all playable games with only some of the enhancements having compatibility issues.

A "BIOS" ROM image can be used, but is not required. You can use an image from any hardware version or region, although mismatching game regions and BIOS regions may have compatibility issues. A ROM image is not provided with the emulator for legal reasons, you should dump this from your own console using Caetla or other means. If no ROM image is provided, OpenBIOS will be used instead.

Features

SwanStation features include:

  • CPU Recompiler/JIT (x86-64, armv7/AArch32 and AArch64)
  • Hardware (D3D11, OpenGL, Vulkan) and software rendering
  • Upscaling, texture filtering, and true colour (24-bit) in hardware renderers
  • PGXP for geometry precision, texture correction, and depth buffer emulation
  • Adaptive downsampling filter
  • Post processing shader chains
  • "Fast boot" for skipping BIOS splash/intro
  • Save state support
  • Supports bin/cue images, raw bin/img files, MAME CHD, single-track ECM, MDS/MDF, and unencrypted PBP formats.
  • Direct booting of homebrew executables
  • Direct loading of Portable Sound Format (psf) files
  • Digital and analog controllers for input (rumble is forwarded to host)
  • Namco GunCon lightgun support (simulated with mouse)
  • NeGcon support
  • Emulated CPU overclocking
  • Multitap controllers (up to 8 devices)
  • RetroAchievements
  • Automatic loading/applying of PPF patches

System Requirements

  • A CPU faster than a potato. But it needs to be x86_64, AArch32/armv7, or AArch64/ARMv8, otherwise you won't get a recompiler and it'll be slow.
  • For the hardware renderers, a GPU capable of OpenGL 3.1/OpenGL ES 3.0/Direct3D 11 Feature Level 10.0 (or Vulkan 1.0) and above. So, basically anything made in 2013 or later.

Region detection and BIOS images

By default, SwanStation will emulate the region check present in the CD-ROM controller of the console. This means that when the region of the console does not match the disc, it will refuse to boot, giving a "Please insert PlayStation CD-ROM" message. SwanStation supports automatic detection disc regions, and if you set the console region to auto-detect as well, this should never be a problem.

The region checking can be disabled in the console options tab. This is the only way to play unlicensed games or homebrew which does not supply a correct region string on the disc, aside from using fastboot which skips the check entirely.

Mismatching the disc and console regions with the check disabled is supported, but may break games if they are patching the BIOS and expecting specific content.

LibCrypt protection and SBI files

A number of PAL region games use LibCrypt protection, requiring additional CD subchannel information to run properly. libcrypt not functioning usually manifests as hanging or crashing, but can sometimes affect gameplay too, depending on how the game implemented it.

For these games, make sure that the CD image and its corresponding SBI (.sbi) file have the same name and are placed in the same directory. SwanStation will automatically load the SBI file when it is found next to the CD image.

For example, if your disc image was named Spyro3.cue, you would place the SBI file in the same directory, and name it Spyro3.sbi.

Tests

  • Passes amidog's CPU and GTE tests in both interpreter and recompiler modes, partial passing of CPX tests

Disclaimers

"PlayStation" and "PSX" are registered trademarks of Sony Interactive Entertainment Europe Limited. This project is not affiliated in any way with Sony Interactive Entertainment.