Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions psprecomp/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ All under `runtime/` (headers in `runtime/include/`, sources in `runtime/src/`):
| HLE | `src/hle/psp_hle_*.cpp` | Firmware NID implementations: io, kernel (thread/sema/mutex/lwmutex/eventflag/memory), display, ge, ctrl, power, utility, adhoc (own row below); `sceUtilitySavedata` is PPSSPP-compatible: `psp_savedata_crypto.{h,cpp}` (sceChnnlsv/KIRK CMD4/7 AES scheme, per-file MAC in `SAVEDATA_FILE_LIST`, `SAVEDATA_PARAMS` signing) and `psp_savedata_dialog.{h,cpp}` (LISTLOAD/LISTSAVE list state machine + software-rendered overlay laid out in 480x272 design units but rasterised at an integer scale (1..4, `set_output_scale` set by `present_blit` from the output size) with FreeType text from OFL fonts embedded at build time (`assets/fonts`, `assets/embed_fonts.cmake`; Cinzel + Crimson Text) as the generic look, or, when a game module installs an `SdTheme` (`set_theme` / `set_theme_provider`: background image, 9-slice/mirrored-cap sprites for tab, selection bar, normal bar, corner ornaments, cursor, button glyphs, colours, optional TTF for body text; sprite pixels map 1:1 to design units and are bilinear-scaled by the canvas scale), the same layout drawn from that game's own UI textures — the Dissidia module builds one lazily from `menu/en/menu_lpk_label_gim_0.bin` + `menu/menu_pk_label_gim_0.bin` (`games/dissidia/runtime/savedata_theme.cpp`, `gim_decode.{h,cpp}`, read through `read_asset` so loose-file mods restyle it; `PSPRECOMP_SDTHEME=0` disables), ICON0.PNG/PARAM.SFO/size shown per row, blitted by `present_dialog_overlay` in `psp_ge_draw.cpp`; `PSPRECOMP_SAVEDATA_AUTO=1` keeps the headless auto-select); the list has a Triangle key opening **Manage saves** (`psp_savemgr_ui.{h,cpp}`: import / export of PSP save folders from PPSSPP, memory sticks or a typed path, with region retargeting + re-signing and `.bak` backups outside `SAVEDATA`; the copy logic is `psp_savemgr.{h,cpp}`, shared with `tools/savemgr`; `PSPRECOMP_SAVEMGR=0` disables; see games/dissidia/docs/savedata.md); host tests `runtime/tests/run_savedata_*.sh`, `test_savedata_hle`, `test_savemgr`; name-based registration wired to the generated `syscall_table.cpp` stub addresses via dispatch overrides (issue #40 — no per-game stub addresses in the runtime; unbound stubs get a loud per-NID unimplemented no-op that returns a deterministic `v0 = 0`; NID→stub lookup for runtime code via `psp_hle_stub_addr_for_nid`) |
| GE list processor | `psp_ge.cpp` | Display-list interpretation, including SIGNAL flow-control behaviors 0x10–0x12 (JUMP/CALL/RET) |
| Renderer | `psp_ge_draw.cpp`, `psp_ge_vertex.cpp`, `psp_ge_texture.cpp`, `psp_ge_shader.cpp` | Vertex decode/transform (column-major PSP matrices), CLUT/texture decode, shaders, GL draw — deep-dive in [docs/GRAPHICS.md](docs/GRAPHICS.md). Default draw path is the batched GPU-skinning one (state-keyed batches, ring VBO synchronised by orphaning, GL 3.3 core only); `PSPRECOMP_GE_FAST=0` selects the per-PRIM CPU-skinning path. `psp_gl_stats.cpp` wraps glad's function pointers for `PSPRECOMP_GL_STATS` (call counters / per-call `glGetError`); `PSPRECOMP_GE_AB` renders every PRIM on both paths into twin targets and diffs them per present (see DEBUGGING.md) |
| Present sync | `psp_present_sync.cpp` | Vertical sync (setting / `PSPRECOMP_VSYNC`: swap interval or Vulkan present mode, switched live at the next swap), the Android display refresh request (`ANativeWindow_setFrameRate` with the game's frame rate) and `[PRESENT_STATS]` present timing; called around every swap by `psp_gl_swap` (issue #67) |
| Render queue | `psp_render_queue.cpp` | Condvar request queue — the only path by which GL work reaches the main thread |
| Event loop | `psp_event_loop.cpp` | SDL2 event pump, quit handling, render-queue drain; routes events to the settings menu first and gates the game's input through it. Controllers are read in the background (`SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS`) but `publish_input()` mutes their buttons and sticks while no window of this process has the keyboard focus, so several instances on one machine do not share a pad (`PSPRECOMP_PAD_BACKGROUND=1` restores the old behaviour); pad state is still tracked, so held buttons are right on refocus |
| Settings menu | `psp_settings.{h,cpp}`, `src/hle/psp_settings_render.inc` (via `psp_savedata_dialog.cpp`), `include/psp_touch.h` | In-game menu (Esc / F1, Guide, L3+R3, the touch menu button, or `psp_settings_request_open()` from a game module's own menu entry). A category sidebar (Display, Graphics, Image, Effects, Controls (only with a touch screen), Network, Cloud, System, Drivers (only where `psp_gpu::supported`), Debug), a scrolling list of captioned rows (toggles, choices, sliders, actions, text fields, sub-menus: Image > HDR, Effects > Ray Tracing) and a description panel whose text scrolls by itself when long. `psp_settings.cpp` owns the state, applies and persists choices (`settings.ini`, exported as `PSPRECOMP_*` at the top of `main()`), and turns the page's `Row`s into a `psp_sddialog::SetScene`; `SettingsView` (`psp_settings_render.inc`, same painter, fonts and `SdTheme` as the save dialog) draws it at ~60 fps with animation (iris open / close, staggered panel slide, gliding selection and sliders, value pulses, drifting crystal motes) into the second overlay slot that `overlay_fetch` prefers, and remembers the geometry it drew (`SetGeom`) so pad, keyboard, mouse (hover, click, wheel, scroll-bar and slider drags, right click = Back) and touch (tap, drag-scroll with fling, sliders) hit-test the exact same rectangles; pointer positions are mapped through the picture rectangle (`ge_draw_overlay_rect`). While the menu is open the on-screen touch controls are hidden and let go (`psp_touch.cpp`), so fingers drive the menu directly. The frosted panels are drawn once per canvas scale into cached premultiplied layers and composited per frame, and the canvas scale drops automatically when a frame takes over 20 ms. Text entry (server, room, peers, sync folder, WebDAV) is an on-screen keyboard modal (pad, mouse, touch, or the host keyboard typing directly). While open the game is paused (guest threads wait in the vblank HLE, `psp_settings_guest_wait`), sees no input (and none until released after closing; the close animation keeps the game paused until it ends), and the main thread presents the last frame plus the menu (`ge_draw_present_overlay_now`). Render-scale changes resize every pool target in place, keeping its picture (`ge_draw_set_render_scale`), once a guest thread has parked, so no display list is mid-way. Frame rate is a game capability: a module registers `PspFrameRateHook` (Dissidia: `games/dissidia/runtime/framerate.cpp`); without one the row is hidden. Host test: `runtime/tests/run_settings_ui.sh` (`DUMP_SETTINGS=<dir>` writes PPM frames). Game modules open it from the game's own menus (Dissidia: `games/dissidia/runtime/menu_settings.cpp`, which adds rows to the title, start and pause menus); elements they add to the game's screens are drawn on the game layer (`ge_draw_set_game_layer`, `psp_ge_draw.h`), a translucent image over the PSP picture under dialogs and touch controls that expires 0.15 s after the module stops sending it, with optional copies of parts of the game's own picture under it (`ge_draw_set_game_layer_copies`); `psp_texpack_watch` hands a module the HD image (either pack kind) the game got for a texture so added elements match the active texture pack |
Expand Down
9 changes: 9 additions & 0 deletions psprecomp/docs/ENV_FLAGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ backend is not built in or no device is usable the runtime stops at start-up (se
`PSPRECOMP_VK_SUBMIT_EVERY=<draws>` (early GPU submits; 0 = only at sync points), `PSPRECOMP_VK_NO_PRESENT=1` (benchmark: never present),
`PSPRECOMP_VK_NO_MULTIDRAW=1`, `PSPRECOMP_VK_TRACE=1` (log every draw). `[VKGL]` lines in the log give draws, pipelines, GPU time and CPU cost per frame.

### `PSPRECOMP_VSYNC`
`0` (default on desktops) or `1` (default on Android). Vertical sync: with `1` each frame waits for the display (Vulkan FIFO present mode, GL
swap interval -1 where the driver offers adaptive sync, else 1), so the picture never tears, and on a variable refresh rate display
(FreeSync, G-Sync, HDMI VRR) the refresh follows the game's frame rate. With `0` frames are shown at once (Vulkan IMMEDIATE / MAILBOX, GL
swap interval 0). Also Settings > Display > Vertical Sync (saved as `vsync=0|1`, changes at the next frame, wins over this variable).
`runtime/src/psp_present_sync.cpp`, issue #67. `PSPRECOMP_PRESENT_STATS=1` logs present-to-present timing every 5 s (`[PRESENT_STATS]`:
mean, standard deviation, median, p99, max and the frames shown for more than 1.5x the median). Android also asks the display for a
refresh rate that matches the game's frame rate (`ANativeWindow_setFrameRate`, Android 11+; `[PRESENT] asked the display for ...`).

### `PSPRECOMP_DISC0`
- **Read in:** `runtime/src/main.cpp`
- **Type:** env (path string).
Expand Down
8 changes: 6 additions & 2 deletions psprecomp/docs/GRAPHICS.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,12 @@ Two consequences of how this is implemented:
framebuffer (software rendering, `sceGeEdram` writes) is invisible; only GE-rendered FBO
content is shown. Double-buffer flips via `sceDisplaySetFrameBuf` all present the same FBO.
- Frame pacing is driven by the *guest*, not the renderer: `sceDisplayWaitVblankStart` sleeps
16.667 ms on the game thread to simulate the 60 Hz vblank. No `SDL_GL_SetSwapInterval` is
called, so vsync is whatever the platform defaults to.
on the game thread to the next simulated vblank (60 Hz, or the battle frame rate above 60).
Whether the swap then waits for the display is the Vertical Sync setting
(`runtime/src/psp_present_sync.cpp`, `PSPRECOMP_VSYNC`): off = Vulkan IMMEDIATE / MAILBOX or
GL swap interval 0, on = FIFO / swap interval -1 or 1, which on a VRR display lets the refresh
follow the game. It can change while running: the Vulkan layer rebuilds its swapchain at the
next swap (the same path as the HDR switch), GL changes the swap interval on the presenting thread.

### Present-time post-processing

Expand Down
6 changes: 3 additions & 3 deletions psprecomp/games/dissidia/docs/steamdeck.md
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 +471,9 @@ ghidra-allegrex v21.3, see the top-level README), or `--skip-analyze` to reuse e
* Music is ATRAC3/3+ decoded via libavcodec; a build without `libavcodec-dev` has no music.
* The European PSN image (`ULES01505`) is the one tested in depth; the US UMD (`ULUS10566`) has been tried
briefly (it works).
* No driver vsync: the guest's 60 Hz vblank is simulated and the window is swapped without waiting, so tearing is
possible outside gamescope (gamescope composites whole frames). `PSPRECOMP_VSYNC=1` turns the driver's vsync on at
the risk of stalling the render thread.
* Vertical sync is off by default: the guest's vblank is simulated and the window is swapped without waiting, so tearing
is possible outside gamescope (gamescope composites whole frames). Settings > Display > Vertical Sync (or
`PSPRECOMP_VSYNC=1`) makes each frame wait for the display; with an external VRR monitor the refresh then follows the game.

## Tested on a Deck

Expand Down
12 changes: 12 additions & 0 deletions psprecomp/games/dissidia/docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,15 @@ Added with `psp_settings_add_debug_toggle` (runtime/include/psp_settings.h: a ga
- The game's own pressed test (`FUN_08AB399C`, the press latch's hook) returned no edges for the scripted Jecht chain presses at 30 or 120 Hz in test runs (`press latch: ... 0 edges` in the `[FPS]` line), so the press latch may not be doing anything for these inputs; not investigated.

- Jecht's Circle / Square are handed to the game on a 30 Hz grid above 30 fps (`jecht_grid_filter`, `PSPRECOMP_JECHT_GRID=0` to turn it off): the Jecht Combo Timing helper above therefore sees each press on a grid update, and a press can reach the game up to one 30 Hz frame after you pressed it. Details and measurements: docs/frame-rate.md "Jecht timed windows on the 30 Hz grid".

## Frame pacing and vertical sync (issue #67)

`PSPRECOMP_PRESENT_STATS=1` logs `[PRESENT_STATS]` every 5 s: present-to-present mean, standard deviation, median, p99, max and
"uneven" (frames shown for more than 1.5x the median). The test-script command `vsync <0|1>` switches vertical sync in the middle of a
run (A/B of the same fight); `BT_DISPLAY_MODE=fullscreen` makes `battle_test.py` run fullscreen, the way players do. Measure on a real,
lit display: with the screen locked or powered off the compositor throttles a waiting (FIFO) swap to 60 Hz, which looks like a pacing
bug and is not. Measured on a 3440x1440 175 Hz VRR monitor (GNOME 50 Wayland, VRR mode on, AMD, Vulkan), 150 fps fight
(`~/dissidia/vrr_run.sh` on the desktop), per 5 s window: vertical sync off (MAILBOX) 6.67 ms, standard deviation 0.14-0.75; on
(FIFO) 6.67 ms, standard deviation 0.14-0.63, at most 2 uneven frames. On a fixed 175 Hz refresh FIFO would put 150 fps frames on a
5.71 ms grid (5.7 / 11.4 ms); even 6.67 ms frames mean the refresh followed the game. Both modes show a single 20-26 ms frame every
few seconds: that comes from the game side, not from presenting.
7 changes: 7 additions & 0 deletions psprecomp/games/dissidia/runtime/framerate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "hle/psp_hle_adhoc.h"
#include "psp_ge_draw.h"
#include "psp_screenfx.h"
#include "psp_present_sync.h"
#include <algorithm>
#ifdef __linux__
#include <sys/prctl.h>
Expand Down Expand Up @@ -271,6 +272,9 @@ void parse_script(std::istream& in, std::vector<TestEvent>& ev) {
} else if (cmd == "fxlights") { // fxlights <0|1>: lights from glowing effects off / on (psp_fx_lights_set), for an A/B of the same trial in one run
int v = 1; ss >> v;
ev.push_back({t, 16, static_cast<uint32_t>(v), 0, "", rel});
} else if (cmd == "vsync") { // vsync <0|1>: vertical sync off / on while running (psp_vsync_set), for pacing A/B in one run
int v = 1; ss >> v;
ev.push_back({t, 30, static_cast<uint32_t>(v), 0, "", rel});
} else if (cmd == "poke") { // poke <player|cpu> <hex offset into the fighter> <int value>: write one word of a fighter (finding which stat a number on the HUD comes from)
std::string who = "player", off; long v = 0; ss >> who >> off >> v;
ev.push_back({t, 15, static_cast<uint32_t>(std::strtoul(off.c_str(), nullptr, 16)), static_cast<uint32_t>(v), who, rel});
Expand Down Expand Up @@ -568,6 +572,7 @@ void testdrive_frame(uint8_t* rdram, recomp_context* ctx) {
g_injected_ranalog_deadline_ms.store(e.b == 0x8080u ? 0 : INT64_MAX, std::memory_order_relaxed);
continue;
}
if (e.kind == 30) { psp_vsync_set(e.a != 0); continue; }
if (e.kind == 15) {
const uint32_t a = test_fighter(e.text == "cpu" ? 1u : 0u);
if (a) { w32(a + e.a, e.b); std::fprintf(stderr, "[TEST] gt=%.0f poke %s +%X = %d\n", g_gt_ms, e.text.c_str(), e.a, static_cast<int>(e.b)); }
Expand Down Expand Up @@ -1947,6 +1952,7 @@ void fps_set(int fps) {
fps = fps < 30 ? 30 : fps > 240 ? 240 : (fps + 15) / 30 * 30; // a multiple of 30
if (g_target.exchange(fps) != fps) std::fprintf(stderr, "[FPS] target frame rate %d\n", fps);
psp_adhoc_set_local_fps(fps); // told to the other players
psp_present_set_target_fps(fps); // Android: ask the display for a matching refresh rate
}
const int k_rates[] = {30, 60, 90, 120, 150, 180, 210, 240};

Expand Down Expand Up @@ -2111,5 +2117,6 @@ void dissidia_framerate_install(uint8_t* rdram) {
fx_install();
psp_settings_set_frame_rate_hook({k_rates, static_cast<int>(std::size(k_rates)), fps_get, fps_set});
psp_adhoc_set_local_fps(g_target.load());
psp_present_set_target_fps(g_target.load());
std::fprintf(stderr, "[FPS] frame rate %d (battle logic; scope %s)\n", g_target.load(), g_scope_all ? "all" : "battle");
}
4 changes: 3 additions & 1 deletion psprecomp/games/dissidia/tools/battle_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ def start(self):
shutil.copytree(os.path.join(self.work, 'ms0'), ms0)
ini = os.path.join(self.out, 'settings_%d.ini' % self.fps)
with open(ini, 'w') as f:
f.write('display=window\nfps=%d\nrender_scale=%d\nwidescreen=%d\nvoice=en\ncheck_updates=0\nhd_textures=%d\n' % (self.fps, self.render_scale, self.widescreen, 1 if os.environ.get('PSPRECOMP_TEXPACK') else 0))
f.write('display=%s\nfps=%d\nrender_scale=%d\nwidescreen=%d\nvoice=en\ncheck_updates=0\nhd_textures=%d\n' % (
os.environ.get('BT_DISPLAY_MODE', 'window'), # BT_DISPLAY_MODE=fullscreen: a real-display test the way players run (VRR, pacing)
self.fps, self.render_scale, self.widescreen, 1 if os.environ.get('PSPRECOMP_TEXPACK') else 0))
env = dict(os.environ, DISPLAY=self.display, PSPRECOMP_SETTINGS=ini, PSPRECOMP_MS0=ms0, PSPRECOMP_FIGHTER_LOG='1',
PSPRECOMP_DEBUG_PORT=str(self.port), PSPRECOMP_SAVEDATA_AUTO='0', PSPRECOMP_TEST_FREEZE_CPU='1')
env.pop('PSPRECOMP_FPS', None)
Expand Down
1 change: 1 addition & 0 deletions psprecomp/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ set(RUNTIME_SOURCES
src/psp_scheduler.cpp
src/psp_render_queue.cpp
src/psp_event_loop.cpp
src/psp_present_sync.cpp
src/psp_settings.cpp
src/psp_ge.cpp
src/psp_ge_vertex.cpp
Expand Down
5 changes: 4 additions & 1 deletion psprecomp/runtime/include/psp_gl_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// (PSPRECOMP_RENDERER=vulkan, src/vk/) the window has no GL context, so these go through the Vulkan layer.
#pragma once
#include <SDL.h>
#include "psp_present_sync.h"
#ifdef __ANDROID__
#include "psp_android.h"
#endif
Expand All @@ -19,8 +20,10 @@ inline void psp_gl_swap(SDL_Window* w) {
#ifdef __ANDROID__
psp_android_frame_hint();
#endif
psp_present_before_swap(w); // vertical sync changed in the settings, display refresh hint (psp_present_sync.cpp)
#if defined(PSPRECOMP_HAVE_VKGL)
if (vkgl::active()) { vkgl::swap(); return; }
if (vkgl::active()) { vkgl::swap(); psp_present_after_swap(); return; }
#endif
SDL_GL_SwapWindow(w);
psp_present_after_swap();
}
24 changes: 24 additions & 0 deletions psprecomp/runtime/include/psp_present_sync.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Vertical sync, variable refresh rate and display refresh hints (issue #67).
//
// The game paces itself (the simulated vblank in psp_hle_display.cpp); this decides how a finished frame reaches the
// screen. Off: present at once (lowest latency, may tear outside a compositor). On: wait for the display (Vulkan FIFO,
// GL swap interval -1 / 1); on a FreeSync / G-Sync / HDMI VRR display that is what lets the refresh follow the game.
//
// PSPRECOMP_VSYNC=0|1 (unset = off on desktops; Android sets 1), saved as `vsync` by the settings menu.
// PSPRECOMP_PRESENT_STATS=1 logs present-to-present timing every 5 s ([PRESENT_STATS]).
#pragma once
#include <SDL.h>

/// 1 when vertical sync is wanted (the setting / PSPRECOMP_VSYNC), 0 when not.
int psp_vsync_wanted();
/// Change it while running (settings menu): applied by the presenting thread at the next swap.
void psp_vsync_set(int on);
/// Apply the current choice to a GL context (call on the GL thread; the Vulkan backend reads psp_vsync_wanted()).
void psp_vsync_apply_gl();

/// The frame rate the game is set to (battles; menus run at 30). Android asks the display for a matching refresh rate.
void psp_present_set_target_fps(int fps);

/// Called by psp_gl_swap on the presenting thread, right before / after the swap.
void psp_present_before_swap(SDL_Window* w);
void psp_present_after_swap();
8 changes: 4 additions & 4 deletions psprecomp/runtime/src/psp_event_loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ int psp_runtime_init_sdl() {
#endif
if (use_vk) {
std::string verr;
if (!vkgl::init(g_window, std::getenv("PSPRECOMP_VSYNC") != nullptr, &verr)) {
if (!vkgl::init(g_window, psp_vsync_wanted() != 0, &verr)) {
std::fprintf(stderr, "[RT] Vulkan backend unavailable: %s\n", verr.c_str());
SDL_DestroyWindow(g_window);
SDL_Quit();
Expand All @@ -700,9 +700,9 @@ int psp_runtime_init_sdl() {

gl_stats_install(); // PSPRECOMP_GL_STATS=1 call counters (psp_gl_stats.cpp)

// No driver-side vsync: the guest's vblank is simulated (hle display) and
// a blocking swap would stall the render thread for up to a refresh.
if (!use_vk) SDL_GL_SetSwapInterval(std::getenv("PSPRECOMP_VSYNC") ? 1 : 0);
// Vertical sync is a setting (off by default on desktops): the guest's vblank is simulated (hle display), so
// without it the swap never waits; with it the swap waits for the display, which on a VRR display follows the game.
if (!use_vk) psp_vsync_apply_gl();

// 6. Print GL info for diagnostics
std::fprintf(stderr, "[RT] GL: %s\n",
Expand Down
Loading
Loading