A Rust and egui based front-end for the SwanStation PS1 Libretro core
  • C++ 58.5%
  • C 36.8%
  • Rust 2%
  • HLSL 0.7%
  • GLSL 0.6%
  • Other 1.2%
Find a file
LibretroAdmin e07ce046f0 core: pre-bake the textured xBR batch FS slice
Fifth and final batch FS template to be pre-baked, after
batch_untextured (9e6f933 + b6d1903 + c01f8ae),
batch_textured_nearest (9e4c33d + a7f5717),
batch_textured_bilinear (269a2a0 + f2ae92a), and
batch_textured_jinc2 (17a0c66 + 6afe8c2). Adds the HLSL template
+ regen recipe + 144 DXBC blobs for the (texture_mode !=
GPUTextureMode::Disabled AND m_texture_filter in {xBR,
xBRBinAlpha}) slice. No C++ wiring yet - the activation commit
lands next and completes the batch FS pre-bake arc.

Variant matrix is identical in shape to Bilinear / JINC2:

  * 6 (tex_mode) x 2 (dual) x 3 (interp) x 2 (persp) x 2 (BinAlpha)
    = 144 blobs.

Only the FilteredSampleFromVRAM body differs. xBR (eXtended Block
Resampling) is an edge-detection-based scaling algorithm:

  - Samples a 5x5 neighbourhood around each source texel via the
    P() helper macro that wraps SampleFromVRAM with UV-limit
    clamping.
  - Carries a per-texel "non-transparent" flag in the W field,
    repurposed from the VRAM "0000h" sentinel test.
  - Computes YCbCr distances (DistYCbCr) between adjacent samples
    using the rec.2020 W_YCBCR weights (0.2627, 0.6780, 0.0593,
    0.5).
  - For each of 4 quadrants (x = upper-left, y = upper-right, z =
    lower-right, w = lower-left), decides blend level: BLEND_NONE,
    BLEND_NORMAL, or BLEND_DOMINANT. The decision is gated by a
    gradient comparison: if the sum of YCbCr distances along one
    diagonal beats the sum along the other by
    DOMINANT_DIRECTION_THRESHOLD (3.6x), the dominant blend
    applies; otherwise normal blend.
  - Per-quadrant line-blend special case: if the gradient pattern
    matches a steep or shallow line shape (filtered by
    STEEP_DIRECTION_THRESHOLD = 2.2), adjust origin + direction
    vectors for the get_left_ratio mix factor.
  - Final colour is a per-quadrant lerp from E (centre) toward
    the chosen blend pixel, weighted by get_left_ratio which
    uses smoothstep on the projected distance to the blend line.

One documented behavioural quirk is preserved byte-for-byte: the
"non-transparent" flag for the I sample (lower-right of the 3x3)
is computed from H's vec4 rather than I's. This is a longstanding
shadergen bug in the original PCSX2 xBR implementation; we
reproduce it so the pre-baked DXBC matches the runtime
D3DCompile output exactly. Fixing it would be a semantic change
to xBR's visual output and is out of scope for the pre-bake arc.

The HLSL body is the largest of any filter template:
~250 lines of FilteredSampleFromVRAM body + helper functions,
producing ~50 KiB DXBC per variant on average (48-60 KiB across
the texture-mode / dual / persp / binalpha axis combos).
144 x ~50 KiB = ~7 MiB on disk and ~7 MiB embedded DXBC. Per-
variant compile time on Linux+wine is ~1s; the full 144-variant
regen takes 3-4 minutes uninterrupted (the wine-flake retry
logic at 269a2a0 catches transient misses).

Without the c532a34 TRANSPARENCY routing, this template would
have been 144 x 4 = 576 variants on the [render_mode] axis. Same
4x saving as Bilinear / JINC2.

Files in this commit (146 total, no C++ touched):

  data/shaders/d3d_common/batch_textured_xbr.ps.hlsl
    Hand-translated mirror of shadergen's textured-xBR-family
    output. Preamble identical to Bilinear / JINC2: BatchUBOData
    cbuffer, Texture2D + SamplerState bindings at register t0/s0,
    ApplyDithering / ApplyTextureWindow / ApplyUpscaledTextureWindow /
    FloatToIntegerCoords / RGBA8ToRGBA5551 / SampleFromVRAM
    helpers. FilteredSampleFromVRAM swaps in xBR's algorithm:
    DistYCbCr, IsPixEqual, get_left_ratio helpers + the 4-quadrant
    blend decision tree + per-quadrant blend application loops.
    main() is structurally identical to Bilinear / JINC2 - same
    `ialpha < 0.5` discard, same UV-limits unconditional clamp,
    same render_mode / pgxp_depth cbuffer-driven runtime branches.

  tools/regen_d3d_common_dxbc.py
    TEMPLATE_VARIANTS gains a batch_textured_xbr.ps.hlsl entry
    with all 144 variant tuples positioned after the JINC2 entry
    (chronological foundation-commit order: nearest, bilinear,
    jinc2, xbr, then the downsample templates). Variant suffix
    encoding identical to Bilinear / JINC2:
      pXrY_d{0,1}_{none,centroid,sample}_n{0,1}_b{0,1}
    where the b{0,1} digit encodes BINALPHA (0 = xBR,
    1 = xBRBinAlpha). Alphabetical sort matches the natural
    nested-loop iteration order in the matching picker.

  src/common/d3d_common/embedded_dxbc/batch_textured_xbr_ps_*.inc
    144 new .inc files, ~48-60 KiB DXBC per variant (~50 KiB
    average), totalling ~7 MiB on disk and ~7 MiB embedded DXBC
    in the .so. Per-variant size is the largest of any pre-baked
    batch FS template:
      Untextured:                 ~2-3 KiB
      Nearest:                    ~5 KiB
      Bilinear:                   ~6 KiB
      JINC2:                      ~17-24 KiB
      xBR:                        ~48-60 KiB
    The 5x5 sample fan-out + 4-quadrant blend decision tree + 4
    per-quadrant blend application blocks dominate the bytecode
    size; fxc /O3 cannot fold the data-dependent control flow
    even though many of the boolean inputs are compile-time
    constants from the BINALPHA macro.

What does NOT change in this commit:

  - GPU_HW_D3D12::GetBatchPipeline still routes xBR / xBRBinAlpha
    through the shadergen + D3DCompile fallback arm (the else
    branch at gpu_hw_d3d12.cpp after the JINC2 activation). The
    144 pre-baked xBR blobs are not yet consulted - they sit on
    disk waiting for the activation commit.

  - GPU_HW_D3D11::GetBatchPixelShader same: still falls through
    to the tmp_shadergen + D3DCompile path for xBR / xBRBinAlpha.

  - src/common/d3d_common/embedded_shaders.{h,cpp} untouched -
    they need 288 new extern declarations / includes to surface
    the .inc blob symbols to the C++ linker; the activation
    commit adds them along with the xBR-family picker.

  - m_texture_filter == xBR / xBRBinAlpha sessions still go
    through D3DCompile on both D3D11 and D3D12 backends until
    the activation commit lands.

  - The shadergen-fallback else arm in GetBatchPipeline and
    GetBatchPixelShader still exists. After the next activation
    commit it becomes unreachable and is deleted, together with
    the tmp_shadergen helper construction on the D3D11 side.

Test:
  - python3 tools/regen_d3d_common_dxbc.py --fxc /tmp/fxc_lite/
    fxc_lite.exe --wine /usr/bin/wine: 614 .inc files generated
    (470 pre-existing + 144 new xBR). Wine flakiness on Linux
    triggered transient retry warnings on the larger xBR variants
    (their longer fxc compile time leaves more room for wineserver
    state to drift); the retry logic added in 269a2a0 caught them.
  - Hand-compile of representative variants:
      no /D (p0r0_d0_none_n0_b0):                    49 692 bytes
      /D PALETTE_4_BIT=1:                            60 020 bytes
      /D PALETTE_4_BIT=1 /D BINALPHA=1:              60 048 bytes
      /D PALETTE_8_BIT=1 /D BINALPHA=1 /D RAW_TEXTURE=1
        /D USE_DUAL_SOURCE=1:                        58 912 bytes
      /D RAW_TEXTURE=1 /D INTERP_SAMPLE=1 /D NOPERSP=1
        /D BINALPHA=1 /D USE_DUAL_SOURCE=1:          48 584 bytes
    All compile cleanly; no fxc warnings or errors. Palette modes
    are noticeably larger than direct modes for the same reason
    as JINC2: the palette-index lookup adds another half-dozen
    SampleFromVRAM-equivalent dependent texture fetches per texel
    even after fxc's dead-code elimination, and xBR's 5x5
    neighbourhood multiplies the cost.

Cumulative pre-bake variant count for D3D batch FS:

  Pre-arc:                                    75 264 (every axis a -D)
  Post-cbuffer-routing arc:                   1 176
  Post-c01f8ae / a7f5717 (Untextured + Nearest, both backends):
                                              168 cell-equivalents
  Post-2fcf4cc (D3D11 downsample live):       22 additional cells
  Post-269a2a0 + f2ae92a (Bilinear-family live):
                                              +288 cell-equivalents
  Post-17a0c66 + 6afe8c2 (JINC2-family live):
                                              +288 cell-equivalents
  Post-this-commit (xBR slice on disk):       +144 baked
    (consumers wired in the activation commit)

Next:
  - Activation: 288 extern decls + 144 #include lines in
    embedded_shaders.{h,cpp}, plus a PickBatchTexturedXBRFS helper
    that takes the additional `binalpha` parameter, and the
    GetBatchPipeline / GetBatchPixelShader branches that route
    m_texture_filter in {xBR, xBRBinAlpha} + texture_mode !=
    Disabled to the new picker. Parallel to f2ae92a (Bilinear
    activation) and 6afe8c2 (JINC2 activation), but additionally
    this activation will:
      - Delete the now-unreachable shadergen-fallback else arm
        from GetBatchPipeline (D3D12) and GetBatchPixelShader
        (D3D11).
      - Delete the tmp_shadergen helper construction on the
        D3D11 side and the GetBatchFragmentShader call on the
        D3D12 side, since neither has any remaining consumer.
      - Tighten the D3D11 m_batch_pixel_shaders matrix
        dimensions if the [dithering] / [interlacing] dims
        become unused post-cbuffer-routing - they should, but
        the dim collapse is a separate concern from picker
        wiring and may land in a follow-up.
  - Independent: Phase 2 D3D12 downsample port - PSOs, explicit
    resource barriers, texture / mip-view creation. Uses the
    pre-baked blobs from 251e457 + the d3d_common rename at
    0ed7261.
2026-05-20 05:08:52 +02:00
CMakeModules Remove unused files 2023-03-25 17:43:35 +01:00
data/shaders core: pre-bake the textured xBR batch FS slice 2026-05-20 05:08:52 +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: pre-bake the textured xBR batch FS slice 2026-05-20 05:08:52 +02:00
tools core: pre-bake the textured xBR batch FS slice 2026-05-20 05:08: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: move embedded DXBC infrastructure to src/common/d3d_common 2026-05-19 09:49:08 +02:00
README.md Documentation OpenBIOS usage in the README. 2026-04-02 10:46:10 +01:00
TODO Update TODO 2026-05-19 07:48:16 +02: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.