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 a7ee3aefe7 common, core, libretro: dead-code sweep, round 2
Nine independent audits collapsed into one commit. All
mechanically distinct and individually verified at build
time; landing them together rather than as separate commits
since each cleanup is small and they touch independent files
or independent surfaces within the same file. Build clean at
every intermediate step on Makefile.libretro platform=unix.

swanstation_libretro.so cumulative size delta:
7949736 -> 7937464 bytes (-12272, ~0.15%). The reductions
come almost entirely from removed dynsym entries plus the
larger drops in common/gl/program (36 Uniform method
bodies) and common/byte_stream (5 SeekRelative overrides);
the template-method dead surface in heap_array / bitfield /
rectangle / types / page_fault_handler / iso_reader yielded
zero codegen change since the templates were never
instantiated. 25 retro_* exports preserved.

== common/gl/program: 36 dead Uniform overloads and BindDefaultAttributes ==

GL::Program declared 42 Uniform setter overloads - 21 by-index
and 21 by-name. Only three are called by gpu_hw_opengl.cpp:

  Uniform1i(int, int32_t)              4 callsites
  Uniform1i(const char*, int32_t)      7 callsites (samp0 binds)
  Uniform4f(int, float, float, float, float)
                                       2 callsites (cursor/display
                                       quad transforms at lines
                                       477 / 562)

The other 39 overloads are decl + def with zero call sites
anywhere. BindDefaultAttributes() (a three-line wrapper around
BindAttribute) likewise has zero callers - every gpu_hw_opengl
shader binds attributes by name directly.

program.h:   105 -> 64  lines
program.cpp: 600 -> 332 lines
.so: -6392 bytes

== common: dead CacheIndexKey::operator!= in all four shader_cache backends ==

All four ShaderCache implementations (GL, D3D11, D3D12, Vulkan)
declare both operator== and operator!= on their CacheIndexKey
structs. The keys are stored in std::unordered_map<CacheIndexKey,
CacheIndexData, CacheIndexEntryHasher> which uses operator== for
collision resolution and never operator!=. No caller in src/
compares two cache keys with != either. Drop the decl from each
header and the body from each cpp.

d3d11 and d3d12 only build on Windows under the Makefile.libretro
win32 guard, so the platform=unix build verifies GL and Vulkan
only. The d3d drops are mechanically symmetric with the verified
ones.

8 files, 32 deletions. .so: -4240 bytes.

== common: ByteStream::SeekRelative, FIFOQueue accessors, FileSystem::rferror ==

ByteStream::SeekRelative was a pure-virtual base method with
five concrete overrides (FileByteStream Windows + POSIX, plus
the three memory subclasses). Zero callers anywhere. Save/load
paths use SeekAbsolute exclusively, CD-image readers use their
own buffered position tracking, and cheat / texture-replacement
serializers rewind via SeekAbsolute(0). Drop the base virtual
and all five overrides.

FIFOQueue::GetDataPointer (both const and non-const overloads)
and GetCapacity() - three inline accessors with zero callers.
Real consumers go through Push / Pop / Peek / PushRange /
PopRange / GetReadPointer / GetWritePointer.

FileSystem::rferror - thin extern "C" wrapper around
filestream_error(). Decl + def with zero callers; nothing in
the libretro core has ever queried a file-stream error state
through this. The other r*-family wrappers stay.

.so: -296 bytes.

== common/heap_array: dead methods AND broken copy paths ==

Of the dozen methods on HeapArray<T, SIZE>, only data() (both
overloads), size(), operator[], and fill() have callers. The
rest are inline accessors with zero call sites: capacity, empty,
begin, end, cbegin, cend, front (both), back (both).

The copy ctor and operator=(const this_type&) were defined but
silently broken: both wrote through rhs.cbegin() (a
const_pointer destination), which would fail to compile if any
caller invoked them. The six relational operators expanded by
the RELATIONAL_OPERATOR macro all had a missing 'return true'
on the loop-success path - falling off a non-void function is
UB if invoked. All seven of these dead methods would have
crashed or miscompiled the first time anyone tried to use them;
the absence of any caller is the only reason this code survived.

Replace the copy ctor and copy operator= with '= delete' so any
future attempt to copy a HeapArray fails at compile time rather
than silently corrupts.

heap_array.h: 102 -> 60 lines.

== common/rectangle: dead relational and arithmetic operators ==

Common::Rectangle<T> had 6 relational operators (==, !=, <, <=,
>, >=) and 19 arithmetic operators (10 compound and 9
non-compound, generated by the ARITHMETIC_OPERATOR macro for
+, -, *, /, %, >>, <<, |, &, ^). Of all these, exactly one is
called: operator*(T amount), used by every gpu_hw_* backend
once per VRAM readback to scale m_vram_dirty_rect by
m_resolution_scale. The other 24 operators have zero callers.

Bonus: the compound 'operator op##=' bodies in the macro never
'return *this;' - same UB-if-invoked pattern as HeapArray.

Also dropped:
  Include(T x, T y)         the 2-arg point-include form; all
                            dirty-rect growth uses the 4-arg form
  Clamp(x1, y1, x2, y2)     in-place; callers use Clamped()
                            (returns-new) instead

Keep operator*(const T amount) as a standalone constexpr member
with a comment explaining why it survives.

rectangle.h: 155 -> 95 lines.

== common/bitfield: dead ++, --, *= and >>= operators ==

Walked all 319 BitField field declarations in src/core/*.h
through grep for each compound op. The full list of dead
operators on BitField<...>:

  operator++()           0 hits across all 319 fields
  operator++(int)        0 hits
  operator--()           0 hits
  operator--(int)        0 hits
  operator*=             0 hits
  operator>>=            0 hits

The other compound ops (+=, -=, /=, &=, |=, ^=, <<=) all have
real callers and stay.

bitfield.h: 143 -> 99 lines.

== common/types: dead operator^ and operator^= in enum bitwise macro ==

IMPLEMENT_ENUM_CLASS_BITWISE_OPERATORS is instantiated four
times (CDImage::OpenFlags, HostRegState, ValueFlags,
GPUTextureMode). Of the seven operators the macro generates,
six have real callers (&, |, ~, &=, |=) but operator^ and
operator^= have zero hits across all four enums. XOR is just
not part of the way these flag-style enums are used: callers
union with |, subtract with & ~, or test with single-bit &.

types.h: 125 -> 115 lines.

== common, libretro: small finds in four files ==

CDSubChannelReplacement::AddReplacementSubChannelQ
  Zero callers. The replacement map is populated by LoadSBI()
  reading the .sbi file directly into emplace().

CDSubChannelReplacement::GetReplacementSubChannelQ(uint8_t,
                                                   uint8_t,
                                                   uint8_t, ...)
  Zero external callers; only forwarded into by its sibling
  LBA-keyed overload. All ten cd_image_* backends call the
  LBA-keyed variant directly with start_lba_on_disc + lba_in_index.

PageFaultHandler::Handle  decl-only alias, never named.

ISOReader::GetImage()     one-line inline accessor, zero
                          callers. ISO consumers in system.cpp
                          use GetPVD() and Open() only.

LibretroSettingsInterface::GetStringList()
  Builds a one-element vector from a comma-less string variable.
  Zero callers - the settings load path uses GetBoolValue /
  GetIntValue / GetFloatValue / GetStringValue at libretro_host_
  interface.cpp:1017,1236. Dropped decl, impl, and the <vector>
  include in the header.

.so: -1056 bytes.

== common, core: CDImage::Seek(const Position&), RegisterCache helpers ==

CDImage::Seek(const Position& pos)
  Single-arg MSF-Seek overload. Decl + def only, zero callers.
  Anyone wanting MSF-keyed seek can write Seek(p.ToLBA()).

  Found-but-kept: the two-arg Seek(uint32_t track, const Position&)
  initially looked dead but the eight cd_image_* backends call it
  as bare Seek(1, Position{0,0,0}) from inside their own subclass
  Open() methods. Build flagged the mistake immediately.

RegisterCache::IsUsableHostReg(HostReg)         0 callers
RegisterCache::GetUsedHostRegisters()           0 callers
RegisterCache::GetFreeHostRegisters()           0 callers
  Stat-counting helpers. Codegen never asks for a count; it
  checks whether a specific register is in use
  (IsHostRegInUse) or whether the free pool is non-empty
  (HasFreeHostRegister).

  Found-but-kept: Value::FromScratch(...) initially looked
  dead, but build flagged three internal callers via bare
  FromScratch(...) member-context calls. Reverted that drop.

.so: -304 bytes.
2026-05-14 19:13:49 +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 common, core, libretro: dead-code sweep, round 2 2026-05-14 19:13:49 +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.