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 dae19ff67b core/vulkan: route the FS PGXP_DEPTH axis to a cbuffer scalar
Follow-up to 116a70e (C++ shadergen FS-side PGXP_DEPTH
routing) which brought D3D11 / D3D12 / OpenGL on. This commit
parallels it on the Vulkan path: collapses the PGXP_DEPTH
SPIR-V-structural axis from all 5 batch FS templates
(untextured + nearest + bilinear + jinc2 + xbr), making
gl_FragDepth always written with a runtime branch on
u_pgxp_depth.

Vulkan FS templates each had PGXP_DEPTH as one of their four
structural axes (3 interp x 2 persp x 2 dual x 2 pgxp = 24
blobs per template, 120 total batch FS blobs). After this
commit each template has 3 x 2 x 2 = 12 blobs, 60 total.

Routing for each template follows the same shape:

  GLSL UBO grows by u_pgxp_depth at offset 52. For the
  filter family (bilinear / jinc2 / xbr) the UBO previously
  declared the first 6 fields and stopped at offset 32; this
  commit adds a `layout(offset = 52) uint u_pgxp_depth;`
  trailing field to skip past the spec-const-handled
  intermediate slots (u_resolution_scale through
  u_interlacing). For Nearest the UBO already had
  u_uv_limits at offset 56; u_pgxp_depth slots in before it
  at offset 52. For the untextured template the UBO
  previously declared only the first 6 fields; same trailing
  layout(offset=52) treatment.

  GLSL FS body: drop the
    #if !defined(PGXP_DEPTH)
      gl_FragDepth = oalpha * gl_FragCoord.z;
    #endif
  block, replace with the unconditional
    gl_FragDepth = (u_pgxp_depth != 0u)
                     ? gl_FragCoord.z
                     : (oalpha * gl_FragCoord.z);
  Same expression shape as the C++ shadergen routing in
  116a70e but using Vulkan's gl_FragCoord.z (rasterizer-
  interpolated depth) instead of HLSL's v_pos.z.

  Regen tool: drop pgxp_axes from each of the three
  variant-generator helpers
  (_batch_fs_untextured_variants,
  _batch_fs_textured_nearest_variants,
  _batch_fs_textured_filter_variants - the last shared by
  bilinear / jinc2 / xbr). Filename suffix shortens from
  `_<interp>_<persp>_<dual>_<pgxp>` to
  `_<interp>_<persp>_<dual>`.

  embedded_spirv/: 120 obsolete files deleted (60 _pgxpoff
  + 60 _pgxpon, 24 per template), 60 new files added (12
  per template) carrying the runtime-branch SPIR-V. Total
  .inc count: 151 -> 91.

  embedded_shaders.{h,cpp}: 5 FS blob tables drop from [24]
  to [12]. 5 helper functions
  (GetBatch{Untextured,TexturedNearest,TexturedBilinear,
  TexturedJINC2,TexturedXBR}FragmentShaderBlob) drop the
  bool pgxp_depth parameter. Index encoding becomes
    index = interp*4 + persp*2 + dual  (0..11)
  (was: interp*8 + persp*4 + dual*2 + pgxp). 60 #include
  lines collapse to 60 (renamed, no count change for that
  block, just filename change).

  gpu_hw_vulkan.cpp: 5 FS lookup call sites
  (GetBatchUntexturedFragmentShaderBlob and the four
  textured filter variants in the switch on `filter`) drop
  their sixth argument (m_pgxp_depth_buffer).

What does NOT change in this commit:

  - The Vulkan batch VS still uses PGXP_DEPTH as a spec
    constant (id=3, declared in batch.vert.glsl, set via
    vs_spec.AddBool(3, m_pgxp_depth_buffer) at pipeline
    build). The C++ shadergen VS was routed to u_pgxp_depth
    in 49c0f82 but the Vulkan VS still has spec const
    PGXP_DEPTH. A separate small follow-up can route the VS
    GLSL through u_pgxp_depth too; the cost matters less on
    Vulkan because spec consts don't fork SPIR-V (one VS
    blob, two pipelines per PGXP value), only PSO assembly,
    and Vulkan already has depth_test as a PSO matrix dim
    that swaps the depth comparison func at draw time
    without rebuild.

  - The non-batch FS spec const id=3 PGXP_DEPTH sites
    (gpu_hw_vulkan.cpp lines 2477, 2523, 2581 - the
    vram_fill, vram_copy, vram_write_* paths) are
    unrelated to the batch FS arc. Those shaders genuinely
    declare PGXP_DEPTH as a spec const
    (data/shaders/vulkan/vram_fill.frag.glsl:80 etc.) and
    have their own pre-bake plans.

  - m_pgxp_depth_buffer STAYS in shader_source_changed
    across all backends. The Vulkan FS bytecode is now
    invariant under it but the C++ shadergen FS still has
    PSO-state dependency (gpu_hw_d3d12.cpp:1317-1319 picks
    LESS_EQUAL vs GREATER_EQUAL based on
    m_pgxp_depth_buffer at PSO build time), so PSO rebuild
    on flip is still required for D3D11 / D3D12 / OpenGL.
    Vulkan handles the depth-comp swap via its depth_test
    PSO matrix dim (depth_test=1 GREATER_OR_EQUAL,
    depth_test=2 LESS_OR_EQUAL - see
    gpu_hw_vulkan.cpp:2233's depth_test_values array) so
    Vulkan doesn't actually need a rebuild on flip
    post-this-commit. Decoupling the cross-backend
    rebuild trigger from Vulkan's no-longer-needing-it
    is a separate cleanup.

Variant-count delta:

  Per-template Vulkan FS: 24 -> 12 SPIR-V blobs.
  Across 5 templates: 120 -> 60 SPIR-V blobs.
  Pipeline cache footprint drops by 60 FS pipelines per
  (filter, render, texture) cell - actual PSO count depends
  on how many of those cells get exercised in practice but
  the savings are proportional.

Disk SPIR-V footprint:

  Before: 151 .inc files, ~11.3 MiB.
  After:  91 .inc files, ~7.5 MiB. (-60 files, ~3.8 MiB.
          The new files are slightly larger than the old
          _pgxpoff ones - they always emit the gl_FragDepth
          write and the runtime branch - but smaller than
          two old files combined, so net footprint drops.)

Cost matrix delta (Vulkan):

  Per-session m_pgxp_depth_buffer flip:
    Pre-commit: 60 batch FS pipelines per (filter, render,
                texture) cell rebuilt to swap from
                _pgxpoff -> _pgxpon. Tens of ms on cold
                pipeline cache, ~0 with warm cache.
    Post-commit: 0 FS pipeline rebuilds. The u_pgxp_depth
                 UBO write picks up at next FlushRender;
                 the FS bytecode is invariant across the
                 flip. The PSO depth-comp swap is handled
                 by Vulkan's depth_test matrix axis (and
                 the C++ side passes the right
                 depth_test index based on
                 m_pgxp_depth_buffer at draw time).

  Cold launch precompile pass on Vulkan: 60 fewer batch FS
  pipelines to enumerate / create.

  Steady-state runtime cost (Vulkan batch FS):
    + 4-byte UBO read on every fragment.
    + One uniform branch on u_pgxp_depth (cbuffer scalar,
      uniform across the warp) - resolves to a predicated
      select on modern hardware.
    + The early-Z TEST trade discussed in 116a70e's commit
      message applies: pre-commit, the _pgxpon variants on
      Vulkan retained early-Z TEST (no FS depth write);
      post-commit those variants always write gl_FragDepth
      so early-Z TEST is disabled. For PSX content on
      modern GPUs the cost is sub-noise (low overdraw,
      cheap FS, painter's-sorted geometry, depth values
      that are essentially random and Hi-Z can't compress).

Test:
  - Build: tools/regen_vulkan_spirv.py runs cleanly,
    producing 91 blobs. Embedded_shaders.cpp compiles
    against the smaller tables. gpu_hw_vulkan.cpp links
    clean.
  - Boot any PSX title on Vulkan with PGXP-depth off:
    u_pgxp_depth=0, the FS ternary picks oalpha *
    gl_FragCoord.z. Output identical to pre-commit.
  - Toggle PGXP-depth on: u_pgxp_depth flips to 1 via the
    existing UpdateHWSettings cbuffer push. The depth_test
    index passed to the PSO lookup also changes to select
    the LESS_OR_EQUAL pipeline. FS picks the
    gl_FragCoord.z pass-through path. No pipeline rebuild
    fired on Vulkan. Output identical to pre-commit
    PGXP-on state.
  - Mask-bit-heavy titles (Crash 1/2/3, Final Fantasy
    combat backgrounds, Silent Hill 1 fog plane): visual
    sanity check that the mask-bit-depth-encode path still
    works at all 5 filters (Nearest baseline, Bilinear,
    JINC2, xBR, BilinearBinAlpha).
  - PGXP-corrected titles (Tekken 3, Tomb Raider 1/2,
    Soul Blade): visual sanity that the pass-through write
    is value-equivalent to the omit-gl_FragDepth-declaration
    pre-routing behaviour. Watch for z-fighting on
    co-planar stage geometry.

Next:
  - Optionally route the Vulkan VS PGXP_DEPTH spec const
    through u_pgxp_depth for parity (small follow-up; cuts
    one spec const per VS pipeline build).
  - per_sample / dcp collapse decisions.
  - Pre-bake the resulting D3D12 FS matrix.
2026-05-19 04:14:04 +02:00
CMakeModules Remove unused files 2023-03-25 17:43:35 +01:00
data/shaders core/vulkan: route the FS PGXP_DEPTH axis to a cbuffer scalar 2026-05-19 04:14:04 +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: route the FS PGXP_DEPTH axis to a cbuffer scalar 2026-05-19 04:14:04 +02:00
tools core/vulkan: route the FS PGXP_DEPTH axis to a cbuffer scalar 2026-05-19 04:14:04 +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.