- C++ 58%
- C 36.4%
- Rust 2.8%
- HLSL 0.7%
- GLSL 0.6%
- Other 1.4%
This is the final backend in the swanstation_GPU_ShaderPrecompile
rollout. OpenGL is structurally different from the other three:
the libretro hardware-renderer protocol gives the core a single
GL context bound to the runloop thread, with no way to spin up a
worker thread that shares the context (no second context, no
glShareLists hand-off path). So OpenGL's 'Lazy' mode degrades to
the same shape as 'Disabled' - compile each batch program on the
runloop the first time the game dispatches a draw using it, then
cache it. No worker thread, no mutex, no atomic; everything runs
on one thread.
Adds GetBatchProgram(render_mode, texture_mode, dithering,
interlacing) as the single fault-in path, mirroring the
GetBatchPixelShader / GetBatchPipeline helpers on the other
backends. The matrix is the existing m_render_programs (array of
GL::Program, move-only); slots start as default-constructed
(m_program_id = 0) and GetBatchProgram fills them lazily.
The Reserved_*Direct16Bit dedup is handled differently from the
other three backends - GL::Program is move-only and owns its
GLuint via glDeleteProgram in its destructor, so we can't share
a single handle between two array slots without a double-delete
hazard. Instead, the helper feeds the canonical (lookup_mode)
fragment-shader source string into GetProgram for both slots.
The disk-backed program cache hits on the second call and
reloads the linked binary instead of recompiling, so the
duplicate is cheap (one glProgramBinary call rather than a full
GLSL compile + link).
Mode behaviour:
- Enabled: synchronous walk of the matrix at CompilePrograms
time, calling GetBatchProgram on each cell.
- Lazy / Disabled: matrix stays default-constructed at
CompilePrograms time; each slot is filled by DrawBatchVertices
-> GetBatchProgram on first use of that combination.
Two small infrastructure additions to support the lazy path:
- GL::Program::IsValid() accessor ('return m_program_id != 0').
GetBatchProgram uses it to distinguish a never-touched slot
from a compiled one. glUseProgram(0) un-binds; calling
prog->Bind() on a slot with id 0 would silently un-bind the
previous program and break rendering, so the explicit
validity check is required.
- GL::ShaderCache::IsOpen() accessor, mirroring D3D11 / D3D12
parity. The shader cache becomes a member (m_shader_cache)
so the lazy helper can reach it at draw time on
UpdateSettings round-trips; without IsOpen the second Open()
call would re-read the index and double-count entries.
GPU_HW_ShaderGen becomes a member (m_shadergen, unique_ptr since
the class is non-default-constructible) so GetBatchProgram can
generate batch shader source at draw time.
use_binding_layout is captured into m_use_binding_layout because
GetBatchProgram's link-callback needs it.
CompilePrograms now explicitly resets the m_render_programs
matrix at function entry. Without that, an UpdateSettings round-
trip (which calls CompilePrograms with new texture_filter /
scale / etc. without an explicit DestroyPrograms step) would
leave the previous programs in place; the lazy fault-in path's
IsValid() short-circuit would return them as if they were fresh,
and the game would render through programs built for the old
settings. The synchronous 'Enabled' precompile loop has the same
short-circuit so it needs the same guarantee. The reset is a
default-assign loop which invokes GL::Program's move-assign
operator, which calls Destroy() (i.e. glDeleteProgram) on each
slot before resetting to id = 0.
DrawBatchVertices routes its m_render_programs lookup through
GetBatchProgram so all three modes share the same fault-in path.
The OpenGL backend has historically had the longest cold-compile
stall in some configurations (long GLSL -> driver compile
pipeline on some Intel / Mesa stacks, no async API in core
OpenGL until ARB_parallel_shader_compile which not all drivers
implement). With 'Lazy' as the default mode, that stall moves
from CompilePrograms-on-init / CompilePrograms-on-settings-change
to a stutter on the first draw that touches each combination -
one per cell, capped at ~144 cells total over the session, often
only a handful in practice for most games. The trade-off is
preferable because it makes the UI feel responsive (RetroArch
keeps drawing frames while gameplay progresses) rather than
froze for the whole compile.
This commit completes the four-backend rollout. All of D3D11,
D3D12, Vulkan, and OpenGL now honour
swanstation_GPU_ShaderPrecompile = Lazy / Enabled / Disabled.
Build verification: linux platform=unix (which DOES compile
gpu_hw_opengl.cpp, unlike the D3D11/D3D12 cases): zero warnings,
zero errors. .so size 8040104 (+4240 vs commit a29d202's
8035864). The growth is the GetBatchProgram body, the matrix-
reset loop at CompilePrograms entry, and the persistent member
storage for the shader cache and shadergen. 25 retro_* exports
unchanged.
Files touched:
- src/common/gl/program.h: IsValid() accessor.
- src/common/gl/shader_cache.h: IsOpen() accessor.
- src/core/gpu_hw_opengl.h: includes, m_shader_cache,
m_shadergen, m_use_binding_layout members, GetBatchProgram
declaration.
- src/core/gpu_hw_opengl.cpp: CompilePrograms resets the matrix
at entry, uses persistent member shader_cache / shadergen,
three-way precompile branch; GetBatchProgram helper added;
DrawBatchVertices routes through the helper.
|
||
|---|---|---|
| CMakeModules | ||
| dep | ||
| src | ||
| .clang-format | ||
| .gitattributes | ||
| .gitignore | ||
| .gitlab-ci.yml | ||
| CMakeLists.txt | ||
| libretro.osx.def | ||
| LICENSE | ||
| link.T | ||
| Makefile.libretro | ||
| README.md | ||
| TODO | ||
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.