popsUlfr / SDH-PauseGames

Decky Loader Plugin for Steam Deck to Pause and Resume games
GNU General Public License v3.0
76 stars 8 forks source link

Suggestion: Quick Resume like Xbox Series #1

Open lyndonguitar opened 1 year ago

lyndonguitar commented 1 year ago

I figured we are already halfway there with SteamOS's sleep/resume function, So I was wondering if it was possible to have a feature akin to the Xbox Series implementation of saving the whole game state into storage and then back in a few seconds.. a literal game changer.

And then I saw this plugin, and then I gasped at the sight of this in your "Future ideas"

checkpoint/restore support with CRIU to make it possible to dump and restore a game to/from disk (savestates

If I understand correctly, a feature similar to Xbox quick resume is what you are trying to achieve with this future idea above right?

I hope it is possible , even if you restrict the dumping from RAM to Storage into just the SSD to maintain fast speeds.

popsUlfr commented 1 year ago

Yes, I've done research and experiments excited at the prospect that there might be a way to get such a feature working for games (just like emulators can save their state to disk). But alas, I think there are important pieces missing in the kernel and CRIU to get something useful for complex applications like games. For "simple" apps it works in a containerized environment like docker/podman, but you see the great issue comes with open sockets relating to video and audio and more. You'd need to checkpoint the state of both ends and by doing so, you'd just end up checkpointing all the important host processes. If you don't do this and you try to resume the app, it would just crash immediately with a broken pipe. So, a very convoluted way to end up with the already existing whole system suspend.

I think the Xbox quick resume functionality is possible because of the mulit layer virtualization technique using hyper-v. The game runs in its own shim which makes it easy to suspend/resume/checkpoint/restore the instance just like a virtual machine. Also the games need to be in a specific format using specific APIs to run on Xbox, which is a huge help to make this layering more or less flawless.

A Steam Deck game could make itself checkpoint-friendly in theory just like the emulators allow to save their state (although they are emulating the hardware that the game expects so they are closer to the usual virtualization methods of isolated memory space but still optimized for the games and a ballooning ram usage just like a normal app) but it needs some very specific code aware of the platform.

I think it is ultimately possible to make something clever on the OS level in Linux to make checkpoint/restore work for complex apps, but it requires more restructuring.

One could try the Microsoft approach with the virtualization layer by going with QEMU/KVM on Linux. But the overhead and the not so ideal video acceleration are problematic.

lyndonguitar commented 1 year ago

Thank you for the detailed response/write-up.

I also found this on reddit so maybe Valve has plans on implementing some sort of this feature in the future.

One of a developer working on KDE Wayland support for Valve has talked about CRIU support on Wayland: https://www.youtube.com/watch?v=fRdnRwPBFBk so it's possible Valve wants to be able to do that at some point. But this may take a while.

Source

purrpurrn commented 1 week ago

This should be possible with Compositor Handoffs.