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 4f6edc295f core/vulkan: skip batch matrix rebuild on chroma_smoothing-only flip
Vulkan parity port of the chroma_smoothing partial-clear that
landed for D3D12 in 57ac62e, D3D11 in 93e5db5, and OpenGL in
722e98a. Same motivation: SMOOTH_CHROMA is constant_id=103 inside
the display FS (see GetDisplayPipeline at gpu_hw_vulkan.cpp:2688)
and that spec const is referenced nowhere else. Every other PSO -
the 1164-cell m_batch_pipelines matrix and its FS modules, the
VRAM ops PSOs (vram_fill / vram_read / vram_write / vram_copy /
vram_update_depth / vram_readback), and the downsample PSOs - is
invariant under chroma_smoothing, but the previous Vulkan path
kept chroma_smoothing in the non_dim_diff set that triggered the
full-flush branch, so a chroma toggle drove the full
DestroyPipelines + CompilePipelines round trip and walked every
reachable cell of the batch matrix synchronously when
shader_precompile_mode = Enabled.

Reuses the display_only_source_changed signal added by 57ac62e
- no API change to UpdateHWSettings, just an extended call site
that requests the new out-parameter. GPU_HW_Vulkan::UpdateSettings
checks it first inside the shaders_changed gate, before
only_dim_changed and the full-flush branch.

The display-only branch destroys just m_display_pipelines (6
VkPipeline slots) via the existing enumerate +
Vulkan::Util::SafeDestroyPipeline pattern that DestroyPipelines
already uses. GetDisplayPipeline lazy-faults a fresh pipeline
with the new SMOOTH_CHROMA spec const on the next UpdateDisplay
- display pipelines are always lazy-built on Vulkan (no
precompile pre-fill path for them in any mode), so there's no
synchronous rebuild required here either; the next UpdateDisplay
call from the runloop allocates and binds the new pipeline
inline. The 6 VkShaderModule fragment shader handles are
released inside GetDisplayPipeline immediately after each
pipeline creates (the SPIR-V blob is embedded so module
construction is cheap), so there's no module leak to chase.

The background batch warm-up worker that StopShaderCompileThread
joined at the top of UpdateSettings needs to be relaunched on
this branch - it doesn't go through CompilePipelines so the
launch site near line ~1929 isn't reached. The worker only walks
m_batch_pipelines, which doesn't carry SMOOTH_CHROMA in its spec
const set anywhere, so keeping it stopped would just starve a
mid-warmup session of further background fill. The relaunch
gate matches the CompilePipelines launch verbatim - Lazy AND
Enabled both run the worker on Vulkan (Enabled's first pass over
the current filter sub-cube hits the lock-free fast-return path
since precompile_sync already filled it, then warms the other
six sub-cubes; that asymmetry between Vulkan and D3D11 / D3D12
exists for unrelated reasons and stays put here).

Resource ordering safety: UpdateSettings calls
g_vulkan_context->ExecuteCommandBuffer(true) at line 812 BEFORE
the shaders_changed block, so the GPU is idle by the time we
reach the m_display_pipelines.enumerate call - no command buffer
in flight is referencing the old display pipelines. The render
passes and pipeline layouts the display pipelines were built
against (m_display_load_render_pass, m_single_sampler_pipeline_
layout) are unchanged on a chroma toggle; the new pipelines on
lazy-fault reuse those handles.

The comment block on the full-flush branch is updated to drop
chroma_smoothing from the list of settings that hit that path -
chroma now routes through display_only_source_changed instead.
The other settings on that list (resolution scale, MSAA, per-
sample shading, UV limits, PGXP depth, colour perspective,
precompile mode) genuinely do invalidate every sub-cube and
still hit DestroyPipelines + CompilePipelines.

Cost matrix after this patch (Vulkan,
shader_precompile_mode = Enabled, 1164 reachable batch PSO cells):

  Toggle                  Before              After this patch
  chroma_smoothing        ~1 min              ~0 sec
                          (full matrix walk   (1 PSO lazy-faulted
                          + DestroyPipelines)  on next UpdateDisplay)
  texture_filter (warm)   instant             unchanged
  texture_filter (cold)   ~1 min              unchanged (necessary,
                                              new filter sub-cube)
  true_color (warm)       instant             unchanged
  true_color (cold)       ~1 min              unchanged (necessary,
                                              new tuple sub-cube)
  scaled_dithering        same as true_color  unchanged
  resolution_scale        ~1 min              unchanged (per-session
                                              spec const)
  multisamples            ~1 min              unchanged (structural
                                              SPIR-V choice)
  per_sample_shading      ~1 min              unchanged (necessary)
  uv_limits               ~1 min              unchanged (necessary)
  pgxp_depth              ~1 min              unchanged (necessary)
  disable_color_persp.    ~1 min              unchanged (necessary)
  shader_precompile_mode  ~1 min              unchanged (intentional)

Vulkan's absolute cost on chroma flip drops from ~1 min (the worst
case in the matrix, because Vulkan's PSO count is 8x D3D11's batch
shader count) to effectively zero - one VkPipeline create on the
next UpdateDisplay. After this patch, every backend's
UpdateSettings cost matrix has the same shape: only the toggles
that genuinely invalidate batch state pay the per-cell rebuild
cost.

Test:
  - Vulkan, shader_precompile = Enabled. Toggle 24-bit chroma
    smoothing on / off: no progress OSD spike, no audible runloop
    hitch. Next UpdateDisplay lazy-builds one VkPipeline for the
    current (depth_24, interlace_mode) cell with the new
    SMOOTH_CHROMA spec const. Subsequent UpdateDisplay calls hit
    populated slots for any other (depth_24, interlace_mode)
    combinations the game reaches.
  - Same toggle under Lazy: identical behaviour to Enabled here -
    display pipelines are always lazy-faulted, only the worker
    relaunch differs (relaunched against the same m_batch_pipelines
    state it left, so cells already in flight or warmed stay
    populated).
  - Same toggle under Disabled: identical to the above but the
    worker isn't relaunched (Disabled never starts one).
  - Toggle chroma_smoothing AT THE SAME TIME as another non-dim
    setting via batch reload: display_only_source_changed returns
    false (other_source_diff is true), the full-flush branch fires
    with the new chroma value picked up by every regenerated
    display pipeline at GetDisplayPipeline time.
  - Cycle chroma on -> off -> on: each toggle clears
    m_display_pipelines and re-lazy-faults one pipeline. The
    on-state and off-state SPIR-V binaries are both cached in the
    Vulkan pipeline cache after the first cycle, so subsequent
    chroma flips create the corresponding VkPipeline from cache
    (microseconds) rather than re-compiling the SPIR-V.
2026-05-18 08:13:35 +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/vulkan: skip batch matrix rebuild on chroma_smoothing-only flip 2026-05-18 08:13:35 +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.