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 cd971cd1d2 core/d3d12: pre-bake the VRAM copy pixel shader
First multi-variant pre-bake, exercising the TEMPLATE_VARIANTS
infrastructure in tools/regen_d3d12_dxbc.py for the first time.
vram_copy_ps is the smallest cleanly-pre-bakeable non-batch shader
after the e56d4d4 RESOLUTION_SCALE refactor took it from
PGXP x N variants down to just PGXP (2 blobs). Pure body-branch
variant axis - no texture binding changes, no MSAA split, no
input-layout differences. Body is small (~30 lines) and the
runtime call site is one function (GetVRAMCopyPipeline) in one
backend.

Why pre-bake vram_copy_ps:

  * It's hit constantly during gameplay. Every PSX game uses
    VRAM-to-VRAM copies for sprite caching (Final Fantasy 7's
    pre-rendered backgrounds streaming sprites in, Tekken 3's
    text rendering between rounds, every fighting game's HUD
    composite, every JRPG's menu system).
  * After e56d4d4 the only variant axis is PGXP_DEPTH on/off, so
    2 blobs cover every (m_pgxp_depth_buffer, m_resolution_scale)
    combination - cleanest possible variant count.
  * It's the natural exercise for TEMPLATE_VARIANTS (which has
    sat empty since the regen tool was first scaffolded at
    ca8c9b0). Subsequent multi-variant pre-bakes (vram_write 4
    variants, vram_read M MSAA variants, display 12 x MSAA
    variants) reuse the same pattern.

Files added:

* data/shaders/d3d12/vram_copy.ps.hlsl: standalone HLSL source
  matching the GenerateVRAMCopyFragmentShader output for D3D12
  post-e56d4d4. The cbuffer layout matches VRAMCopyUBOData
  member-for-member (u_src_coords, u_dst_coords, u_end_coords,
  u_size, u_set_mask_bit, u_depth_value, u_resolution_scale,
  u_pad0 = 48 bytes). VRAM_SIZE alias inlined since the helper
  emission isn't accessible to standalone HLSL.
  PGXP_DEPTH variant is a single #if in the body controlling
  the o_depth assignment. MSAA path omitted entirely - vram_copy
  never runs in MSAA mode because the source texture is bound
  as both shader-resource AND framebuffer-output, which D3D12
  doesn't permit with an MSAA resource; the runtime uses the
  non-MSAA m_vram_read_texture shadow.

* src/common/d3d12/embedded_dxbc/vram_copy_ps_pgxp0.inc: DXBC
  blob for /DPGXP_DEPTH=0 (PGXP off, conditional o_depth).
  ~3.1 KB of bytecode.

* src/common/d3d12/embedded_dxbc/vram_copy_ps_pgxp1.inc: DXBC
  blob for /DPGXP_DEPTH=1 (PGXP on, o_depth = 1.0). ~3.0 KB.

Files modified:

* tools/regen_d3d12_dxbc.py: TEMPLATE_VARIANTS dict populated
  with the vram_copy.ps.hlsl entry. Two variant rows:
    ("pgxp0", ["PGXP_DEPTH=0"])
    ("pgxp1", ["PGXP_DEPTH=1"])
  The dispatch loop at line 232-238 (untouched, pre-existed
  from ca8c9b0) does the right thing: emit one .inc per row,
  identifier suffix from the variant_suffix string.

* src/common/d3d12/embedded_shaders.h: extern declarations
  added for the two new blobs (k_vram_copy_ps_pgxp0,
  k_vram_copy_ps_pgxp0_size_bytes, and pgxp1 pair). Each pair
  matches the regen tool's naming convention.

* src/common/d3d12/embedded_shaders.cpp: two #include lines
  added inside namespace D3D12::EmbeddedShaders, mirroring
  what was done for fullscreen_quad_vs + copy_ps. The .inc
  files define the storage; the prior extern declarations in
  the header give them external linkage.

* src/core/gpu_hw_d3d12.cpp GetVRAMCopyPipeline: dropped the
  shadergen-call + m_shader_cache.GetPixelShader path; replaced
  with an inline D3D12_SHADER_BYTECODE constructed from the
  embedded blob selected via m_pgxp_depth_buffer. Same PSO-
  creation flow downstream (gpbuilder, MSAA state, depth state,
  shader-cache PSO disk-cache via gpbuilder.Create). The
  m_shadergen-not-yet-constructed check is dropped for this
  path since the embedded blobs are statically linked - no
  ordering dependency on shadergen lifetime.

Toolchain confirmation:
  Built with Wine's d3dcompiler_47.dll via /tmp/fxc_lite/fxc_lite.exe
  on the contributor side (same tooling as 77b255f / 443a2a1).
  DXBC magic verified at regen time (the 'DXBC' signature in the
  first 4 bytes; the regen tool aborts the build if that doesn't
  match).

Cost matrix delta (D3D12 specifically):
  vram_copy_ps D3DCompile cost on cold-cache flip: ~50 ms each
  for the two PGXP variants -> 0 ms after this commit. The PSO
  compile itself still runs through gpbuilder.Create (~10 ms),
  so total cold-flip-of-PGXP cost drops by ~50 ms per variant.
  Disk-cache-warm cost was already in the noise (~1 ms cache
  lookup); now it's literally zero.

  Progress tracker: non_batch_progress_units stays at 17 - we
  still tick once per (depth_test) GetVRAMCopyPipeline call
  inside the precompile_sync loop. PSO compile is still the
  unit; we just stopped doing the D3DCompile half of that
  work.

Variant count after this commit, for the cold-flip cost matrix
columns we care about, for vram_copy specifically:
  * resolution_scale  : 0 ms (cbuffer-routed since e56d4d4)
  * pgxp_depth        : 0 ms D3DCompile + ~10 ms PSO compile
  * multisamples      : 0 (not a vram_copy variant axis)
  * filter / chroma   : 0 (no relationship to vram_copy)

The shadergen GenerateVRAMCopyFragmentShader function is left
intact in gpu_hw_shadergen.cpp - the other three backends
(D3D11, OpenGL, Vulkan) still call it through their runtime
shader-cache paths. Only the D3D12 backend bypasses it now.
Future per-backend pre-bake work could extend the pattern
to those backends too (Vulkan via SPIR-V pre-bake, OpenGL via
something else - GLSL doesn't have a comparable offline-
compiled bytecode format; SPIR-V cross would be the route).

Test:
  - Build: D3D12 backend should link without unresolved symbols.
    The shadergen->GenerateVRAMCopyFragmentShader path is no
    longer reachable through GetVRAMCopyPipeline on D3D12 but
    the function is still defined and used by other backends.
  - Runtime: every VRAM copy that previously worked must still
    work. Concrete test - FF7 menu navigation (uses VRAM copy
    for menu sprite composition heavily), Tekken 3 round-
    transition text rendering (VRAM copy each frame to splat
    the round number / TOTAL DMG sprites). If the embedded
    blob were wrong, sprites and menu text would garble within
    a second of entering a menu or starting a round.
  - PGXP toggle: flip the "PGXP CPU mode" option on and off
    in RetroArch's core options. The first flip recompiles
    PSOs; the embedded blob path picks blob[1] vs blob[0] and
    builds fresh PSOs. Subsequent same-direction flips hit the
    PSO cache.
  - Resolution scale toggle: 1x <-> 4x. No PSO recompile (since
    the blob is scale-independent now); CopyVRAM next frame
    just pushes a different u_resolution_scale value through
    the cbuffer.

This is the first non-batch FRAGMENT pre-bake on top of the
RESOLUTION_SCALE refactor. Following the same template:
vram_write_ps (4 variants: PGXP x use_ssbo), vram_fill_ps (8
variants: PGXP x wrapped x interlaced, no refactor needed
since the body doesn't reference RESOLUTION_SCALE), and
vram_update_depth_ps (2 MSAA variants, exercises MSAA
texture-binding variant for the first time).
2026-05-18 21:48:20 +02:00
CMakeModules Remove unused files 2023-03-25 17:43:35 +01:00
data/shaders core/d3d12: pre-bake the VRAM copy pixel shader 2026-05-18 21:48:20 +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/d3d12: pre-bake the VRAM copy pixel shader 2026-05-18 21:48:20 +02:00
tools core/d3d12: pre-bake the VRAM copy pixel shader 2026-05-18 21:48:20 +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.