A Rust and egui based front-end for the SwanStation PS1 Libretro core
  • C++ 58.4%
  • C 36.7%
  • Rust 2.2%
  • HLSL 0.7%
  • GLSL 0.6%
  • Other 1.2%
Find a file
LibretroAdmin 5490cdfb10 core/opengl: skip non-batch program rebuild on filter-only flip
OpenGL parity port of the non-batch-skip optimisation that
landed for D3D11 in the previous commit. Same motivation: the
dim cache port from f8b4a41 made the only_dim_changed fast
path in UpdateSettings preserve the previous filter's sub-cube
of m_render_programs, but it still called CompilePrograms
(with clear_existing_render_programs=false), which rebuilt the
filter-independent non-batch programs (display via
RebuildDisplayPrograms / vram_fill / vram_read / vram_write /
vram_copy / vram_update_depth / downsample) on every filter
flip. None of those read m_texture_filter inside shadergen -
GenerateBatchFragmentShader and the WriteBatchTextureFilter
helper at gpu_hw_shadergen.cpp:706, 728, 839 are the only
places m_texture_filter is referenced.

So the post-dim-cache only_dim_changed branch was making ~14
GL::Programs via the disk-backed program cache - cache hits
that reload the linked binary via glProgramBinary, plus the
shader cache lookup machinery and the GL::Program move-assign
that calls glDeleteProgram on the previous slot tenant. Measured
cost ~10-100ms per filter toggle of pure GL::Program churn,
which on OpenGL is wider than the D3D11 equivalent because the
OpenGL non-batch program set is slightly larger (m_downsample_*
adds entries the D3D11 backend handles in a different layer) and
because glProgramBinary reload has more driver overhead than
CreatePixelShader from a DXBC blob.

Factor the precompile_sync block out of CompilePrograms into a
new private helper:

  bool GPU_HW_OpenGL::PrecompileBatchPrograms(
      ShaderCompileProgressTracker& progress);

CompilePrograms calls this for its initial / full-rebuild pass;
the only_dim_changed branch in UpdateSettings calls it directly
after reconstructing m_shadergen and building a progress tracker
sized for just the batch matrix (CountReachableBatchShaders). The
non-batch builds (display + vram ops + downsample + the
m_use_binding_layout flag) are simply skipped on the fast path -
the existing GL::Program handles in those slots stay valid
because filter is the only setting that changed and none of them
read it.

Unlike the D3D11 version, this helper has no worker-launch
component: OpenGL is single-threaded by the libretro hardware-
renderer protocol (one GL context bound to the runloop), so
'Lazy' degrades to 'Disabled' shape on this backend. The helper
walks the matrix synchronously in Enabled and does nothing in
Lazy / Disabled - filter cycling under Lazy / Disabled just
faults each new sub-cube cell on first use via GetBatchProgram
at draw time, same as the original behaviour.

m_shadergen is reconstructed on the only_dim_changed branch even
though no shadergen consumer currently reads filter from it
(GetBatchProgram uses per-call tmp_shadergen post-dim-cache,
RebuildDisplayPrograms' GenerateDisplayFragmentShader is filter-
independent, the other non-batch generators ignore filter
entirely). The reconstruction is cheap (POD copies in the
GPU_HW_ShaderGen ctor) and forecloses any latent bug if a future
code path adds a shadergen consumer that DOES read m_texture_filter
from there. Same defensive bias as the D3D11 port.

Cleanup: the clear_existing_render_programs parameter on
CompilePrograms is now dead - both remaining callers (Initialize
and UpdateSettings' full-rebuild branch) want the clean-slate
behaviour. Drop the parameter; CompilePrograms always clears
m_render_programs at the top now. Reverts the dim-cache fast
path's intermediate API from f8b4a41 cleanly (the dim-cache
fast path itself isn't reverted - it just moves out of
CompilePrograms entirely and into the new direct
PrecompileBatchPrograms call site in UpdateSettings).

Cost matrix after this patch (OpenGL,
shader_precompile_mode = Enabled, 144 reachable batch shader
cells, warm program cache):

  Toggle                  Before          After this patch
  texture_filter (warm)   ~10-100 ms      instant
                          (non-batch
                           cache hits)
  texture_filter (cold)   ~5-15 sec       ~5-15 sec - ~10-100 ms
                          + ~10-100 ms    (necessary, new sub-cube,
                                          non-batch overhead gone)
  All other toggles       unchanged       unchanged

The cold-flip win is small in relative terms (the new filter sub-
cube glLinkProgram pass dominates) but the warm-flip win is the
real one: cycling Nearest -> Bilinear -> Nearest -> Bilinear is
now bounded by GL context overhead rather than by the per-toggle
non-batch cache walk.

Test:
  - OpenGL, shader_precompile = Enabled. Toggle texture filter
    Nearest -> Bilinear -> Nearest. First Nearest -> Bilinear
    pays the new-sub-cube cost minus the ~10-100ms; subsequent
    cycle-backs hit instant. No flicker / regression on display
    output between toggles - m_display_programs aren't dropped.
  - Toggle filter under Lazy: helper returns immediately (no
    worker on this backend), next batch draw lazy-faults the
    cell from GetBatchProgram. Same as Disabled in shape.
  - Toggle filter under Disabled: helper returns immediately,
    next batch draw lazy-faults.
  - Toggle a non-dim source-affecting setting (multisamples /
    per_sample_shading / uv_limits / pgxp_depth / colour
    perspective): full-rebuild branch fires, CompilePrograms
    clears all sub-cubes and walks the current filter's sub-
    cube. The new helper path is bypassed and the existing
    full-rebuild behaviour is unchanged.
  - Toggle chroma_smoothing: display_only_source_changed branch
    fires, RebuildDisplayPrograms rebuilds the 6 display
    programs, the helper path is not entered. Unchanged from
    722e98a.
  - Initialize: calls CompilePrograms(), which clears (no-op on
    default-constructed m_render_programs) and walks the full
    init flow including PrecompileBatchPrograms for the current
    filter sub-cube. Same as before, just with the parameter
    gone from the call site.
2026-05-18 08:58:55 +02:00
CMakeModules Remove unused files 2023-03-25 17:43:35 +01:00
data/shaders/vulkan common/vulkan, core: pre-bake remaining batch FS texture filters (Bilinear / JINC2 / xBR families, 72 blobs total) 2026-05-18 02:04:30 +02:00
dep dep, common/vulkan, core, build: remove dep/glslang and the Vulkan ShaderCompiler infrastructure 2026-05-18 02:21:53 +02:00
src core/opengl: skip non-batch program rebuild on filter-only flip 2026-05-18 08:58:55 +02:00
tools common/vulkan, core: pre-bake remaining batch FS texture filters (Bilinear / JINC2 / xBR families, 72 blobs total) 2026-05-18 02:04:30 +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 dep, common/vulkan, core, build: remove dep/glslang and the Vulkan ShaderCompiler infrastructure 2026-05-18 02:21:53 +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.