gamescope icon indicating copy to clipboard operation
gamescope copied to clipboard

KWin Direct Scanout does not work with gamescope

Open NjlsShade opened this issue 1 year ago • 16 comments

When running gamescope in a fullscreen window using KDE Plasma 6, direct scanout does not work. Is it possible to get it functioning, or is there compositing going on in a way that just won't allow it though kwin?

I've tried using the -f flag, as well as using kwin to make the standard gamescope window boarderless fullscreen. Nothing else is overlaying the window when testing.

NjlsShade avatar Jul 17 '24 19:07 NjlsShade

Can you give some more information? What exact version of Plasma are you on, do you have HDR enabled, do you have an ICC profile set or the built-in profile, is the screen rotated? Also, what are you doing to check if you get direct scanout?

Zamundaaa avatar Jul 17 '24 20:07 Zamundaaa

I'm running Plasma 6.1.2 on Fedora 40, however, it's been an issue since Plasma 5. I'm not using HDR, monitor is using built-in color profile, screen is in default landscape orientation and gamescope is matching the resolution 1:1 (2560x1440).

I can show that direct scanout is not working because MangoHud's current FPS stats will reset when the compositor enables/disables it for the parent window, and there is also a telltale stutter during this process. I've attached a video to show how it looks when it's functioning properly (stutter is not noticeable at the video's frame rate, but MangoHud is). You'll notice that when something is composited over the window (the microphone mute indicator in this case) it disables direct scanout during the duration, then re-enables it.

Thanks!

https://github.com/user-attachments/assets/9ee2c30b-bac1-4da0-9305-ed043bb59402

NjlsShade avatar Jul 17 '24 22:07 NjlsShade

monitor is using built-in color profile

In Plasma 6.1 that forces compositing; offloading volor management to KMS has only been implemented recently, for 6.2. If you set the color profile to "none", that should make direct scanout work again

Zamundaaa avatar Jul 17 '24 22:07 Zamundaaa

monitor is using built-in color profile

In Plasma 6.1 that forces compositing; offloading volor management to KMS has only been implemented recently, for 6.2. If you set the color profile to "none", that should make direct scanout work again

I apologize, my statement that the monitor was using the "Built-in" profile was ignorant (thought None referred to the built-in one). The option in KDE's settings is currently set to "None"

Screenshot_20240717_183943

Note that direct scanout also works just fine in games, as long as I'm not using gamescope.

NjlsShade avatar Jul 17 '24 22:07 NjlsShade

Okay, interesting. Direct scanout does work for me in Plasma 6.1 FWIW. Maybe it depends on the GPU? I'm on a rx 7900XTX

Zamundaaa avatar Jul 17 '24 22:07 Zamundaaa

Thanks for the info! I'm running gamescope with:

gamescope -w 2560 -h 1440 -f

Are there any extra flags needed to allow this, and how are you testing if it's working for you?

NjlsShade avatar Jul 17 '24 23:07 NjlsShade

I can show that direct scanout is not working because MangoHud's current FPS stats will reset when the compositor enables/disables it for the parent window, and there is also a telltale stutter during this process. 

I don't think that would happen with Gamescope, so perhaps your testing methodology for knowing if direct scanout is enabled is what is wrong here?

misyltoad avatar Jul 17 '24 23:07 misyltoad

Worth noting that --mangoapp also uses a separate wl_surface to display, which would stop direct scanout on KWin right now as it only uses the primary plane fwiu.

The DRM Gamescope backend aggressively uses planes.

misyltoad avatar Jul 17 '24 23:07 misyltoad

I can show that direct scanout is not working because MangoHud's current FPS stats will reset when the compositor enables/disables it for the parent window, and there is also a telltale stutter during this process. 

I don't think that would happen with Gamescope, so perhaps your testing methodology for knowing if direct scanout is enabled is what is wrong here?

Yeah, you are definitely right there, as MangoHud is running within the scope of gamescope. I'd imagine that I'd still see a stutter when overlaying content like the microphone mute indicator though (maybe I'm wrong, maybe it's not a stutter in KWin but the game itself during the switch so it would not be visible in this setup?), and I'm not seeing that when using gamescope, even without MangoHud running. You familiar with any way I can test outside these methods?

I know that's kind of outside the scope of this issue tracker, but Plasma has a bug where animations will get stuck and break direct scanout occasionally, and having an easy way to know if it's broken would be nice so I can be sure it's not a given game just acting up, and to let me for sure know this issue is resolved. haha

NjlsShade avatar Jul 18 '24 00:07 NjlsShade

You can check if direct scanout is kicking in with drm_info. KWin uses buffer formats with alpha, and games generally use formats without alpha. On my desktop:

drm_info | grep Format:
    │   │   │   ├───Format: ABGR2101010 (0x30334241)
    │       │   ├───Format: ABGR2101010 (0x30334241)

With doom eternal in gamescope:

sleep 5; drm_info | grep Format:
    │   │   │   ├───Format: XBGR2101010 (0x30334258)
    │       │   ├───Format: XBGR2101010 (0x30334258)

Zamundaaa avatar Jul 18 '24 15:07 Zamundaaa

Replying to https://github.com/ValveSoftware/gamescope/issues/1423#issuecomment-2236810356

Thanks for that information! Using that as a method to check, I can confirm that direct scanout is still not working with gamescope for me, even with no overlays enabled. Just running: gamescope -w 2560 -h 1440 -f -- %command%

I have the terminal running on a different monitor, and it does show working for games outside gamescope, so It's not interfering in any way. May I ask how you are running gamescope, and what your launch options are?

NjlsShade avatar Jul 18 '24 21:07 NjlsShade

I don't use any special flags except for enabling HDR, just gamescope -W 5120 -H 1440 -f --hdr-enabled -- %command%

Zamundaaa avatar Jul 19 '24 12:07 Zamundaaa

I don't use any special flags except for enabling HDR, just gamescope -W 5120 -H 1440 -f --hdr-enabled -- %command%

Do you recall if you were using X11 at the time you did this testing? From what I gather, direct scanout should not work with Gamescope running under KWin+Wayland as of now. Just trying to confirm this if possible.

NjlsShade avatar Jan 19 '25 01:01 NjlsShade

I was not using X11.

From what I gather, direct scanout should not work with Gamescope running under KWin+Wayland as of now.

No, it most definitely should work.

Zamundaaa avatar Jan 19 '25 02:01 Zamundaaa

I definitely don't want to drag you into anything if you don't want, but it's been quite a minute and I now have completely new hardware, and a fresh Fedora 41 installation using KWin 6.2.5, native Steam, and gamescope 3.15.9-23-gd317492. However, I'm still unable to get direct scanout to function with gamescope.

Running a game without gamescope sets the format "XBGR", running with gamescope sets it to "ABGR" and I can visually see lost frames due to the compositing not keeping up in certain situations. If you can think of anything I can try that might get me closer to why this might be, I'd greatly appreciate it!

Running gamescope with no overlays: gamescope -f -w 2560 -h 1440 -- %command%

NjlsShade avatar Jan 19 '25 06:01 NjlsShade

I'm not sure, but 6.3 contains some changes so that KWin's more lenient about color management stuff when it comes to direct scanout, which might help.

FYI since 6.2 you can much more conveniently check for direct scanout, by enabling the "show compositing" effect in the desktop effect settings.

Zamundaaa avatar Jan 20 '25 15:01 Zamundaaa