A Rust and egui based front-end for the SwanStation PS1 Libretro core
  • C++ 57.9%
  • C 36.4%
  • Rust 2.8%
  • HLSL 0.7%
  • GLSL 0.6%
  • Other 1.5%
Find a file
LibretroAdmin 7ebd5175e5 core/opengl: skip structurally unreachable cells in batch precompile loop
OpenGL parity port of the IsBatchShaderReachable filter used by
the D3D11 / D3D12 / Vulkan precompile_sync loops and their
background workers. Same motivation: cells that the runtime can
never select at draw time (NeedsTwoPassRendering short-circuits,
Reserved_*Direct16Bit dedup, single-pass dual-source on hardware
without dual-source support) burn glCompileShader + glLinkProgram
for nothing.

The three structurally unreachable cell classes are documented in
IsBatchShaderReachable's comment in gpu_hw.h. For the OpenGL
backend specifically:

  - Reserved_Direct16Bit (texture_mode 3) and
    Reserved_RawDirect16Bit (texture_mode 7) collapse to canonical
    modes 2 / 6 inside GetBatchProgram via the lookup_mode
    remapping, but unlike the D3D / Vulkan backends which alias
    the canonical slot's handle into the reserved slot at the
    matrix level, OpenGL's GL::Program is move-only and can't be
    shared - GetBatchProgram instead RE-LINKS the canonical source
    string into a fresh program object. The disk-backed program
    cache makes the second link cheap (it reloads the linked
    binary via glProgramBinary instead of recompiling from source),
    but 'cheap' is not 'free' - 8 reserved-mode cells * 2 dither *
    2 interlace = 32 program-cache lookups + glLinkProgram calls.

  - OnlyOpaque / OnlyTransparent with texture_mode == Disabled: 4
    cells each, 8 total. NeedsTwoPassRendering short-circuits on
    (texture_mode != Disabled), so untextured polys never reach
    the two-pass fallback.

  - TransparentAndOpaque with texture_mode != Disabled on hardware
    without dual-source blend: up to 28 cells, 0 on common
    desktop hardware that supports dual-source blend.

Reachable cell count on dual-source hardware: 144 - 32 - 8 = 104.
On hardware without dual-source: 144 - 32 - 8 - 28 = 76. The
shader cache absorbs most of the cost on warm boots, but cold
boots and shader cache invalidations (driver / GPU change, version
bump via SHADER_CACHE_VERSION) re-pay the full glCompileShader /
glLinkProgram cost on each unreachable cell, so this is a real
init-time win at the moments the user is most likely to notice.

batch_progress_units switches to CountReachableBatchShaders() so
the progress bar lands at 100% on the new walk count. The other
progress increments (display, vram_fill, vram_read, vram_write,
vram_update_depth, vram_copy, downsample) are unchanged - the
sizing constants (2*3 + 2*2 + 1+1+1+1+1) only cover the non-batch
helpers.

There's no background worker on OpenGL (single-threaded GL
context per the libretro hardware-renderer protocol), so this is
the only place reachability filtering needs to land - GetBatchProgram
on the runloop lazy-fault path doesn't filter because the runtime
can only ask for cells it actually intends to use.

Cost change on a cold cache (Enabled mode, dual-source hardware):
~104 / 144 = ~28% fewer glLinkProgram calls. At ~50-100 ms per
cold link, that's ~2-4 seconds off OpenGL's initial CompilePrograms
pass. On hardware without dual-source blend the win is larger
(~47%).

Test:
  - OpenGL, shader_precompile = Enabled. Cold shader cache. Boot
    progress bar reaches 100% at the end of the batch walk, no
    overshoot, no undershoot. Walk count matches
    CountReachableBatchShaders(m_supports_dual_source_blend).
  - Same boot warm cache: progress bar still aligned, all walked
    cells hit cache, no glProgramBinary fallback.
  - Game uses every texture_mode (Tekken 3 cycles through all
    palette / direct paths): no missing-program errors at draw
    time from the cells the loop now skips. The skipped cells
    are unreachable by construction, so a runtime lookup against
    one of them would be a bug elsewhere in the GPU front-end,
    not in this filter.
2026-05-18 08:19:43 +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 structurally unreachable cells in batch precompile loop 2026-05-18 08:19:43 +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.