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 00cf11f5d0 core/d3d11: port filter dim cache from D3D12 backend
D3D11 parity port of the dim cache that landed for D3D12 in
10c53b8. Same motivation: after 418eb14 the cbuffer-refactor
series made resolution_scale / true_color / scaled_dithering
toggles instant on D3D11, but a texture_filter flip still drove
DestroyShaders + CompileShaders and recompiled the whole 144-cell
batch pixel shader matrix (plus state objects, but those are a
handful of cheap CreateBlendState / CreateRasterizerState calls).

Add GPUTextureFilter::Count (7) as the outermost dimension of
m_batch_pixel_shaders and m_batch_pixel_shader_fastpath:

  std::array<...<ComPtr<ID3D11PixelShader>, 2>, 2>, 9>, 4>, 7>
                                                        ^
                                                     filter

(D3D11 keeps its existing nested-std::array style rather than
switching to DimensionalArray; matching the D3D12 backend's
DimensionalArray<..., 7> at the indexing level is what matters,
not the underlying container.)

GetBatchPixelShader gains a GPUTextureFilter filter parameter as
the first argument, indexes both arrays with [filter_idx][...],
and constructs a per-call GPU_HW_ShaderGen against the requested
filter rather than reusing m_shadergen (which stays bound to the
runtime-current m_texture_filtering for the non-batch helpers
called elsewhere - they don't depend on filter so rebuilding
m_shadergen on every batch shader compile would be pure overhead).
Filter is the only ctor input that differs between m_shadergen
and the per-call shadergen; all other inputs come from member
state that's single-valued per session. The expensive work
(GenerateBatchFragmentShader call + D3DCompile +
CreatePixelShader) is unchanged from the pre-dim-cache path. The
error-log thread-safety check on m_shadergen is dropped because
the per-call shadergen makes the helper independent of
CompileShaders having constructed m_shadergen first; all call
sites still go through CompileShaders or its descendants so the
invariant is preserved structurally.

CompileShaders's precompile_sync block snapshots cur_filter =
m_texture_filtering once and walks only that sub-cube. Same
pattern for ShaderCompileThreadEntryPoint - the worker captures
cur_filter at launch and walks just that sub-cube. UpdateSettings
calls StopShaderCompileThread BEFORE UpdateHWSettings writes
m_texture_filtering, so the snapshot the worker takes always
matches the filter it's supposed to be warming. The next
CompileShaders pass after a filter flip launches a fresh worker
captured to the new filter. Mirrors the D3D12 ordering verbatim.

DrawBatchVertices passes m_texture_filtering as the first arg to
GetBatchPixelShader so the lookup hits the active sub-cube.

UpdateSettings's rebuild gate gains the only_dim_changed branch:

  if (shader_source_changed) {
    if (only_dim_changed) {
      // Filter sub-cube changed; others stay valid.
      // CompileShaders lazy-populates the new filter on top.
      // State objects are filter-independent so CreateStateObjects
      // can be skipped on this path - blend states key on
      // transparency_mode, depth-stencil on depth-test mode,
      // input layout on uv_limits (handled by non_dim_diff above).
      CompileShaders();
    } else {
      // Non-dim shader change (MSAA / per-sample / UV limits /
      // chroma smoothing / PGXP depth / colour perspective /
      // precompile mode): every sub-cube is invalidated.
      DestroyShaders();
      DestroyStateObjects();
      CreateStateObjects();
      CompileShaders();
    }
  }

Cycling back to a previously-visited filter (Nearest -> Bilinear
-> Nearest) is now instant on D3D11 in any precompile mode - the
second Nearest hit walks the precompile_sync loop and the
fast-path atomic-load wins on every cell, no D3DCompile, no
CreatePixelShader. A fresh-cold filter flip (first time visiting
Bilinear) still pays the full matrix walk to populate the new
sub-cube, but the OLD filter's shaders stay alive in their slots
and are reachable via an atomic load the moment the user flips
back.

DestroyShaders's fast-path-clear loop gains a fifth level of
nesting to match the new 5-D shape.

Cost matrix after this patch (D3D11, default settings,
shader_precompile_mode = Enabled, 144 reachable batch shader
cells):

  Toggle                  Before        After this patch
  texture_filter (cold)   ~5-15 sec     ~5-15 sec (necessary,
                                        new sub-cube)
  texture_filter (warm)   ~5-15 sec     instant (atomic load)
  resolution_scale        zero          unchanged
  true_color              zero          unchanged
  scaled_dithering        zero          unchanged
  multisamples            ~5-15 sec     unchanged (necessary -
                                        invalidates every filter
                                        sub-cube)
  per_sample_shading      ~5-15 sec     unchanged (necessary)
  uv_limits               ~5-15 sec     unchanged (necessary)
  pgxp_depth              ~5-15 sec     unchanged (necessary)
  disable_color_persp.    ~5-15 sec     unchanged (necessary)
  chroma_smoothing        ~5-15 sec     unchanged (suboptimal,
                                        same as D3D12 pre-57ac62e
                                        - splittable as a
                                        follow-up)
  shader_precompile_mode  ~5-15 sec     unchanged (intentional)

D3D11 is fewer-tens-of-seconds than D3D12 in absolute terms
because D3D11 has 144 batch shader cells vs D3D12's 1164 PSO
cells (PSO state combinatorics inflate the count), but the
relative improvement on warm filter cycling is the same.

Test:
  - D3D11, shader_precompile = Enabled. First boot: matrix walks
    only Nearest's sub-cube. Shader compile count and progress
    bar match pre-patch.
  - Toggle texture filter Nearest -> Bilinear: precompile_sync
    walks Bilinear's sub-cube. Bilinear pixel shaders build for
    the first time. Old Nearest sub-cube stays populated.
  - Toggle back Bilinear -> Nearest: precompile_sync loop hits
    every Nearest slot on its fast-path atomic load and returns
    instantly. No D3DCompile, no progress OSD.
  - Toggle Nearest -> Bilinear again: every Bilinear slot is
    already populated. Instant.
  - Toggle resolution scale / true_color / scaled_dithering:
    still pays zero per 418eb14, unchanged.
  - Toggle MSAA / per_sample / UV limits / PGXP depth / colour
    perspective: DestroyShaders clears all sub-cubes, full
    rebuild walks the current filter's sub-cube. Same cost as
    pre-patch.
  - shader_precompile_mode = Lazy: worker captures
    m_texture_filtering at launch, walks just that sub-cube.
    Filter toggle joins worker, restarts with new filter
    snapshot, walks new sub-cube. Main thread can fault any
    cell ahead of the worker via GetBatchPixelShader.
2026-05-18 07:16:41 +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/d3d11: port filter dim cache from D3D12 backend 2026-05-18 07:16:41 +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.