Save states

A state is the whole game at one moment, in the Switch's state file (src/nx/runtime/state_file.h): the header and the 320 by 180 thumbnail the launcher and the game's menu read, then a section for each part, each with a hash of the names and types of what it holds (src/vita/runtime/state.c):

SectionWhat it holds
PROCESSthe threads with their registers, waits and fibers, the objects, the memory blocks, the display, the dialogs
LINKSthe threads running and pacing the frames, and each thread's place in the module_start chain, as indices
TIMEthe times kept by the host's clock (the start, the next vblank, the threads' deadlines, the sound ports' play), counted from the save: a load counts them from its own
MEMORYthe image's segments, the runtime's page with the threads' TLS, the imported variables' slots, every memory block
IOeach file and folder open, as its host path, sceIoOpen's flags and its place, and the FIOS2 archives mounted (hle/io.c)
GXMsceGxm's contexts, programs, targets, mappings and display queue (hle/gxm.c)
AUDIO, NGS, TROPHYthe sound ports, SceNgs's racks and voices, the trophy contexts (hle/audio.c, ngs.c, trophy.c)
AUDIODECeach audio decoder (AAC, ATRAC9) as its configuration, an ATRAC9 superframe not all handed out yet, the codec engine's blocks (hle/audiodec.c)

A save waits for the GPU, so what it wrote is in guest memory and what sceGxm notes is written; a load makes the renderer again, which draws from the GXPs and surfaces in memory as at the game's start. A file open is opened again at its place, never truncated: the game's save data and what it wrote since stay, as a Switch game's files do. An audio decoder is made again from its configuration: what FFmpeg's decoder keeps of the frames before (the overlap of their transforms) starts empty, so the first frame it decodes after a load differs from the console's, a click of one frame at most, and the frames after it are the same. The game is its title ID and its image's segments. A load reads and checks every section before it changes anything, and refuses another game's state (both named), another SNX_VITA_STATE_VERSION (both versions), a section of another layout (both hashes), a damaged file and one naming a file that is gone. A save is refused, saying what, while a thread runs, while one is inside a call of the runtime's into the game (a sort's comparison, a callback), while a scene is being drawn, and while the game plays a movie (an mp4 file or a video decoder: the demuxer's place and the pictures H.264 decodes the next ones from can't be put back) or has sockets open, which a state can't keep. The threads run by the host's clock, so vita_state (tests/vita_state.c) checks what a load puts back of a process the test drives through the imports, and that a save right after it is the same, rather than frames; vita_state_gpu (tests/vita_state_gpu.c) that a save holds the GPU's work it waited for (a scene, a copy) and that the renderer a load makes draws from the state's memory, on a device that imports guest memory and on one that copies it.


Made from docs/platforms/vita/README.md at 69237645142c. GPL-3.0-or-later.