2024-12-07

Fixing Steam Games on Wayland + Nvidia by Using Gamescope

So, I have this game called "Phasmophobia". It's a horror game, but also very puzzle-y. I like this game. On the other hand, there's this display backend for Linux called "Wayland". It is much smoother than its old counterpart "X11".

They can't coexist

Phasmophobia is a game made in Unity, and it only has support for Windows. That's not the real problem though, thanks to Valve's "Proton", which allows Windows game to run on Linux.

The problem lies within the fact that I have an Nvidia GPU.

If you have ever used Linux with an Nvidia card, you know how much of a pain it is to get Nvidia working on your computer. Support has been improved recently, but there's still some way to go. Specifically, Wayland support is still not as mature as X11 for Nvidia.

Because of this, for some reason, Phasmophobia is extremely laggy in Wayland session. It almost feels like it's trying to render with my CPU. Beyond that, I also notice screen tearing. So just, in general, not a great experience.

I can totally just switch back to X11 for playing the game, but then the desktop becomes laggy instead. This demotivates me from playing Phasmo, which isn't great cuz I paid good money for that!

Gamescope saves the day

For a while, I have been trying to find a solution to this problem. I even tried "Glorious Eggroll Proton", and that didn't really help.

Since I know the problem can be fixed by using X11, I have been wondering if I can run X11 on top of Wayland. And then I recall I have seen |Gamescope| before, but back then I didn't know how to use it. I took a look at the [Gamescope GitHub repository](https://github.com/ValveSoftware/gamescope) again. It is said to be a compositor.

"Hmm... That seems close enough to what I was trying to do."

Due to me tweaking game launch parameters before because I also stream, I actually know how to set it up properly this time. So I tried it again. I set the width and height to 1920x1080 and frame-rate to 60 Hz (my monitor runs at 1920x1080@120Hz). I noticed that the screen tearing was gone!

It is still kind of laggy, but this is great result! So I tried another time with frame-rate of 120Hz and guess what, it's now even smoother than X11. Here's the command I ran (`PULSE_SINK=out_game` already exists before I added Gamescope):

`PULSE_SINK=out_game gamescope -h 1080 -H 1080 -w 1920 -W 1920 -r 120 -f -- %command%`

Anyway, the lag is fixed and I'm now happy :>