Last active 1719781480

00.gamescope_tips.md Raw

gamescope

Preface

I'm using endeavourOS, KDE Plasma 6.1, a RTX 3080, nvidia-open-dkms 555.58-2, Wayland.

My main monitor is a Samsung Odyssey Neo G7 (3840x2160 165hz "HDR10") and my second is a Acer Predator XB271HU (1440x2560 165hz)


Ideally, these are my launch options for each game:

gamescope -W 3840 -H 2160 -r 165 --hdr-enabled --hdr-itm-enable --hdr-itm-sdr-nits 300 --hdr-sdr-content-nits 300 -f -e --mangoapp -- gamemoderun %command%

There are some issues with it:

  • Steam overlay and input won't work (-e flag is broken)
  • --mangoapp won't show some info
  • xwayland might crash or game might freeze
  • Performance is incredibly low after a while

and the workarounds...

Steam overlay and input

GitHub issue

Creating a gamescope window on the terminal and attaching the game to it will work, but HDR will be broken.

First I run this on a terminal:

gamescope -W 3840 -H 2160 -r 165 --hdr-enabled --hdr-itm-enable --hdr-itm-sdr-nits 300 --hdr-sdr-content-nits 300 -f --mangoapp

I take note of the window's number on wlserver: [xwayland/server.c:107] Starting Xwayland on :2, then set the game's launch options:

DISPLAY=:x gamemoderun %command%

Where x is the display number. The game might take a while to open up and also to completely exit, but it works just fine, except for HDR.

Apparently this is needed for HDR to work this way: https://github.com/Zamundaaa/VK_hdr_layer, and adding ENABLE_GAMESCOPE_WSI=1 DXVK_HDR=1 on the game's launch parameters, before gamemoderun

mangohud and --mangoapp

It is recommended to run --mangoapp if using gamescope, however it won't display any GPU info. Running it as mangohud before %command% will show GPU info, but might have some other issues down the line. On both ways, information like HDR, FSR, gamemoderun status won't be displayed at all.

Crashes and freezes

From time to time xwayland will crash in many ways. When there's a lot going on in my games and performance might be taking a hit, the game and Steam will simply close immediately. This is the softest of the crashes because I can simply reopen Steam and the game without issues.

Sometimes the game will freeze or my entire desktop will freeze (this one also happens randomly when I'm dragging a window or starting a game). I have to restart my PC in this case.

There are some bug reports about these issues on bugs.kde.org, gamescope GitHub, NVIDIA drivers GitHub and forums, but no one knows why or how it happens, and many times it's hard to get logs. If you happen to have these issues and can provide logs or useful information, please do so on the proper channels.

Performance

When you run gamescope, you might notice on the terminal something like

No CAP_SYS_NICE, falling back to regular-priority compute and threads. Performance will be affected.

Performance WILL be affected. After a while, your game will look like a slideshow, but your frame counter will still display the FPS as normal.

That means you have to set the niceness of gamescope. Run, as sudo:

setcap 'CAP_SYS_NICE=eip' $(which gamescope)`

It seems that after a while it loses its niceness, so I made a systemd service that runs on login, checking if the niceness is set, and setting it if it's not. Check the 01.gamescope-niceness.service

VRR

VRR (adaptive sync, GSYNC) will not work on NVIDIA cards if you have more than one monitor enabled. There are no solutions, no workarounds, and I don't think NVIDIA has even recognised this issue.

While this is not a problem related to gamescope, mangohud or gamemoderun, I've added this section because it might come in handy.

By disabling any extra monitor, VRR will work again. I've made the 02.start-gamescope.sh script to be run as a launch parameter on the game, it'll start a gamescope window, turn off my extra display and start the game with gamemoderun and connecting it to the window. When quitting the game, the script turns the extra monitor back on and properly disposes of the gamescope window.

Run it by marking the script as executable chmod +x start-gamescope.sh and setting your game's launch parameter as

/path/to/your/start-gamescope.sh %command%
01.gamescope-niceness.service Raw
1[Unit]
2Description=Check gamescope niceness and set it if needed
3After=network.target
4
5[Service]
6Type=oneshot
7User=root
8ExecStart=/bin/bash -c 'if getcap $(which gamescope) | grep -q "cap_sys_nice=eip"; then exit 0; else setcap "CAP_SYS_NICE=eip" $(which gamescope); fi'
9RemainAfterExit=yes
10
11ProtectSystem=full
12ProtectHome=read-only
13PrivateTmp=true
14NoNewPrivileges=true
15
16[Install]
17WantedBy=default.target
02.start-gamescope.sh Raw
1#!/bin/sh
2
3echo "########## Starting a gamescope window"
4# change where necessary, like the resolution an refresh rate
5gamescope -W 3840 -H 2160 -r 165 --hdr-enabled --hdr-itm-enable --hdr-itm-sdr-nits 300 --hdr-sdr-content-nits 300 -f &
6
7# trying to trap the gamescope window so it can properly quit after exiting the game
8export gamescope_pid=$!
9trap "echo \"########## Killing gamescope window\" && kill -- -$gamescope_pid" SIGINT SIGTERM EXIT
10
11sleep 1s
12
13if [ -n "$WAYLAND_DISPLAY" ] || [ "$XDG_SESSION_TYPE" == "wayland" ]; then
14 echo "########## We're Running on wayland"
15 export WLND=1
16fi
17
18sleep 1s
19
20echo "########## Disabling secondary monitor."
21if [ $WLND ]; then
22 # run kscreeen-doctor and check your displays arrangement
23 # and change where necessary
24 kscreen-doctor output.DP-1.disable &>/dev/null
25fi
26
27sleep 1s
28
29# I know that gamescope will always create a display on 2 for me
30# run the gamescope window on a terminal and take note of which number it is
31DISPLAY=:2 mangohud gamemoderun "$@"
32
33# the script will "pause" here while the game is running
34# and will resume from the next `sleep` after you quit the game
35
36sleep 1s
37
38echo "########## Enabling secondary monitor."
39if [ $WLND ]; then
40 # again, run kscreen-doctor and check the display arrangement
41 kscreen-doctor output.DP-1.enable &>/dev/null
42 kscreen-doctor output.DP-1.position.0,0 output.DP-3.position.1440,200 &>/dev/null
43fi
44