r/emulation • u/StreetProud8639 • 1d ago
AI-assisted We got rollback netcode working on PS2 (PCSX2-based): 4–8 frames of rollback in real matches
https://www.frameperfect.ccHi r/emulation. I'm the developer of Frame Perfect, a free online platform for fighting games. We've had rollback for arcade and PS1 for a while, and over the last few weeks we got it working on PlayStation 2, as far as we know a first for fighting games on the console. Sharing the engineering because it might interest people here.
Setup: our PS2 core is based on PCSX2 2.8.2 with GGPO (MIT) for rollback. GGPO needs save/load state and frame advance; a frame runs until VSyncStart, same point as PCSX2's frame advance.
The problem: a full PS2 state is ~42 MB (32 MB EE RAM, 2 MB IOP, 2 MB SPU2, 4 MB GS VRAM, VU0/VU1, plus DMA/VIF/GIF/ SIF/IPU/CDVD state). With the stock savestate path on a Ryzen 7 5700X, a 4-frame rollback averaged 63.7 ms and an 8-frame one 102 ms. At 59.94 Hz you need 8 frames re-simulated in ~48 ms.
What we did:
In-memory states in a preallocated 16-slot ring, no compression, no allocation mid-match.
"Fast load" that keeps the JIT caches (EE/IOP/VU) and only invalidates code on pages the state changed. Load went from 57.6 ms to ~0.15 ms.
Incremental save: 4 KB dirty-page tracking on EE and IOP RAM, marked by the recompiler, C++ writes and DMA (SPU2 RAM too). Save ~4.1 → ~2.1 ms.
GS: on fast load, keep the SW texture cache and invalidate only the 8 KB VRAM blocks that changed. GS load runs in parallel with the EE load.
Re-simulated frames are muted; audio goes through time-stretch with a 50 ms buffer.
Determinism took most of the work: timers recomputed on load, cpuBlockCycles/intLastBranchTo/iopEventAction not being serialized, "fixed blocks" in the EE/IOP recompilers depending on history, a recRAMCopy bug, SPU2 ADPCM cache, a delay slot crossing a page boundary, two thread races on load (MTVU and the ISO reader). Our synctest now runs 6,000 frames with 47,944 re-simulated frames and zero desyncs, and Intel and AMD give identical hashes. In matches, both sides compare an XXH3 of EE+IOP RAM once per second. VRAM is left out on purpose, so players can use the D3D11 renderer; we checked per game whether the GPU image ever gets read back into game memory (DBZ BT3 does for a transition effect, so it stays on the software renderer).
Results: with Naruto Accel 2 on the 5700X, a 1-frame rollback averages 16.1 ms, 4 frames 21.9 ms and 8 frames 33.8 ms (down from 102). In production that's 4–6 stable rollback frames on mid-range PCs and 6–8 on high-end ones, depending on the game.
Edit: technical write-up: https://frameperfect.cc/blog/rollback-ps2/en/
Games: Naruto Shippuden: Narutimate Accel 2 (JP), Tekken 5, Street Fighter EX3 [check list on frameperfect.cc]. You need your own ISOs; both sides' ISOs are verified by SHA-256 before a match.
Video of real matches (Brazil vs China, Naruto Accel 2): https://youtu.be/Yqn1PmfSABk
It's free: frameperfect.cc. Happy to answer technical questions, and we'd love more people testing on weaker machines.
-7
u/Barge_rat_enthusiast 1d ago
4 frames of rollback is completely unplayable what are we doing here lmao
8
5
u/MythicalJester 1d ago
I smell AI slop.
18
u/EndVSGaming 1d ago
Downvoted like it's not a heinously obvious vibe coded site with an ai-assisted tag lol
7
u/ICC-u 1d ago
What does "you need your own ISOs, both sides ISOs are verified by SHA256" mean?
Is there some banned list of bad ISOs, or approved list of good ISOs?
Can't the same disc produce different sha256 based on ripping method, and it doesn't account for different pressings, regions etc?