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 e64fc28a7f core: route RESOLUTION_SCALE through display_ps cbuffer
Last shader in the non-batch RESOLUTION_SCALE arc. Same refactor
as e56d4d4 / 9d2b49d / 2980961, applied to display_ps - the
fragment shader that composites the upscaled VRAM texture into
the host display framebuffer every frame.

display_ps body uses RESOLUTION_SCALE / VRAM_SIZE in two distinct
spots driven by the DEPTH_24BIT preprocessor variant:

  * 24-bit colour path (FMV playback, true-colour framebuffer
    games): SampleVRAM24 helper multiplies native VRAM coords by
    RESOLUTION_SCALE to map into the upscaled VRAM texture:
        LoadVRAM(int2((vram_coords % clamp_size) * RESOLUTION_SCALE))
    Hit twice per output pixel (left + right 16-bit packed
    texel pair).
  * 16-bit colour path (common case, every game's standard
    framebuffer present): VRAM_SIZE used for upscaled-coord
    modulo wrap:
        LoadVRAM(int2((icoords + u_vram_offset) % VRAM_SIZE))

Both expand to the same #define aliases as u_resolution_scale-
derived arithmetic after this commit. Per-pixel cost difference
vs the literal-baked version is negligible - the multiplication
with a cbuffer-loaded uint operates at the same throughput as
with a constant, and the modulo wrap was always a real ALU op
not a folded constant.

Subtle but important: this commit pushes m_resolution_scale to
u_resolution_scale, NOT the local `resolution_scale` variable
in each backend's UpdateDisplay scope. The local is
   const uint32_t resolution_scale =
     m_GPUSTAT.display_area_color_depth_24 ? 1 : m_resolution_scale;
which forces 1 in 24-bit mode to keep u_vram_offset / u_crop_left
in NATIVE coords (the 24-bit display path runs the viewport at
native size, not upscaled - see scaled_display_width =
display_width * resolution_scale at the call site). The shader's
RESOLUTION_SCALE macro has always been the session m_resolution_scale
because SampleVRAM24's `vram_coords * RESOLUTION_SCALE` needs to
map native VRAM coords into the upscaled VRAM texture regardless
of how the display target itself is sized. Pushing the local
resolution_scale (=1 in 24-bit) would break SampleVRAM24's
upscale mapping and produce wrong 24-bit colour output (would
sample VRAM at native coords instead of upscaled ones).

Files:

* gpu_hw_shadergen.cpp: GenerateDisplayFragmentShader reordered
  so DeclareUniformBuffer runs before WriteCommonFunctions(ss,
  true). u_resolution_scale + u_pad0 appended to the cbuffer
  member list (after u_field_offset). WriteCBufferResolutionScaleAliases
  call inserted between cbuffer and WriteCommonFunctions.
* gpu_hw_d3d11.cpp / gpu_hw_d3d12.cpp / gpu_hw_vulkan.cpp /
  gpu_hw_opengl.cpp: each backend's UpdateDisplay constructs an
  inline uniforms[] array at its present site. All four grow
  from uniforms[4] (u_vram_offset.xy + u_crop_left + u_field_offset)
  to uniforms[6] (adding u_resolution_scale + u_pad0).
  D3D11 / D3D12 / Vulkan share the same form; OpenGL keeps its
  scaled_flipped_vram_offset_y for lower-left origin handling
  and gets m_resolution_scale + u_pad0 appended in parallel.
  Push-constants ceiling check: 6 DWORDs = 24 bytes, well under
  MAX_PUSH_CONSTANTS_SIZE = 64 on both D3D12 and Vulkan.

Variant axis dropped: display_ps had depth_24bit (2) x
interlace_mode (3) x smooth_chroma (2) x MSAA (M) x
m_resolution_scale (N) variants. After this commit it's 2 x 3 x
2 x M = 12 x M variants, with the scale dimension fully gone.
Pre-bake for display_ps becomes viable in a follow-up - 12
blobs (or 12 x M with MSAA still as a variant axis), which is
manageable. Multi-variant pre-bake exercises TEMPLATE_VARIANTS
in regen_d3d12_dxbc.py for the first time.

Shader-cache invalidation: display_ps's source string changes
on every backend. First boot after this lands re-compiles all
12 (depth_24 x interlace x smooth_chroma) variants once for
each MSAA count the user has enabled; subsequent boots hit the
regenerated cache entries.

Test:
  - Build under each backend succeeds.
  - Render a normal 16-bit framebuffer game (any normal title)
    at every resolution scale (1x, 2x, 4x, 8x). The frame
    composite uses the 16-bit path's `% VRAM_SIZE` for wrap-
    around handling - if u_resolution_scale weren't populated
    correctly, the modulo would be off by a factor and the
    presented image would either be the wrong region of VRAM
    or wrap onto itself with visible tearing. Visible immediately.
  - Render a 24-bit framebuffer source (FMV playback in any
    game with pre-rendered videos - the bookend Sony intro, FF7
    cutscenes, MGS pre-render scenes, etc.) at every resolution
    scale. The SampleVRAM24 path's `vram_coords * RESOLUTION_SCALE`
    is the heaviest user; if it weren't populated, FMVs would
    show garbled pixels sourced from the wrong upscaled VRAM
    location.
  - Toggle resolution scale at runtime (1x -> 2x -> 4x -> 1x).
    Each switch triggers an UpdateDisplay; if the cbuffer field
    didn't track the change, the display would freeze on the
    previous scale's coords or render at wrong size.

This concludes the non-batch RESOLUTION_SCALE refactor arc. After
this lands, every non-batch shader that referenced RESOLUTION_SCALE
or VRAM_SIZE in its body now reads u_resolution_scale from its
own cbuffer, identical pattern to what 7b575a3 did for batch
shaders. The only remaining literal-RESOLUTION_SCALE consumers
are the adaptive_downsample_* shader family, which is a separate
concern - those shaders take a u_rcp_resolution cbuffer field
already, and they use RCP_VRAM_SIZE differently (for mip-level
sampling derivatives, not just coord scaling), so they'd need
a slightly different refactor pattern.

Next on the pre-bake side: with the scale axis removed from
vram_copy / vram_write / vram_read / display, each one becomes
a candidate for offline DXBC pre-bake. Smallest first:
vram_update_depth (2 MSAA variants, body has no RESOLUTION_SCALE
reference so doesn't need this refactor at all) is the natural
TEMPLATE_VARIANTS exercise.
2026-05-18 21:36:00 +02:00
CMakeModules Remove unused files 2023-03-25 17:43:35 +01:00
data/shaders core/d3d12: pre-bake the copy/blit pixel shader 2026-05-18 20:22:17 +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: route RESOLUTION_SCALE through display_ps cbuffer 2026-05-18 21:36:00 +02:00
tools core/d3d12: scaffolding for pre-baked DXBC blobs 2026-05-18 09:14:52 +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 core/d3d12: scaffolding for pre-baked DXBC blobs 2026-05-18 09:14:52 +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.