Bug 415286 - X11s HiddenPreviews option loaded in Wayland and causes rendering issues
Summary: X11s HiddenPreviews option loaded in Wayland and causes rendering issues
Status: RESOLVED WORKSFORME
Alias: None
Product: kwin
Classification: Plasma
Component: compositing (show other bugs)
Version: git master
Platform: Compiled Sources Linux
: LO normal
Target Milestone: ---
Assignee: Roman Gilg
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-12-17 13:31 UTC by tempel.julian
Modified: 2024-07-07 03:47 UTC (History)
8 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description tempel.julian 2019-12-17 13:31:24 UTC
SUMMARY
KWin compositing makes Proton fullscreen games freeze with a black window after alt + tabing out of the game window and back into it.

STEPS TO REPRODUCE
1. Keep compositing enabled and start a game via Steam Proton, e.g. Dishonored 2 with Proton 4.11-10.
2. Switch to another window via alt + tab.
3. Switch back to the game window.

OBSERVED RESULT
It just stays black and the process has to be killed.

EXPECTED RESULT
The game window should continue unaffected by the focus switch.
This is the case when KWin compositing is manually disabled before the game is started. It doesn't matter if "Allow applications to block compositing" is enabled or not. It also breaks when manually turning compositing on again after the game was minimized, as at seems to receive focus in that moment.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Arch Linux 5.4.3
(available in About System)
KDE Plasma Version: recent / self-compiled git-master as dependency for kwin-git
KDE Frameworks Version: recent / self-compiled git-master kwin-git
Qt Version: 5.13.2
GPU: RX 570 with recent mesa 20 git-master

ADDITIONAL INFORMATION
Happens also on Wayland. Doesn't happen with other compositors.
Might be related to the Proton fullscreen hack that prevents unnecessary modeline switches and provides upscaling resolutions to games. It can't be disabled.
Comment 1 David Edmundson 2019-12-17 17:54:51 UTC
>This is the case when KWin compositing is manually disabled before the game is started. 

So if compositing is off, and stays off the game still breaks?
Comment 2 tempel.julian 2019-12-17 18:28:02 UTC
(In reply to David Edmundson from comment #1)
> So if compositing is off, and stays off the game still breaks?
Then it doesn't break. :)
Comment 3 Roman Gilg 2019-12-18 01:28:15 UTC
Info was provided.
Comment 4 David Edmundson 2019-12-18 10:07:37 UTC
Ok, so it only breaks if compositing toggles.

That will almost certainly be the fault of the game not handling that well. You only see it in kwin as that's one of the few window managers that support toggling.

Please report to the game devs / proton.
Comment 5 tempel.julian 2019-12-18 10:14:33 UTC
I think you misunderstood: It's unrelated to toggling compositing. It also breaks as long as compositing is just enabled, compositing is never toggled during the process.
Comment 6 Roman Gilg 2019-12-18 10:42:34 UTC
(In reply to tempel.julian from comment #5)
> I think you misunderstood: It's unrelated to toggling compositing. It also
> breaks as long as compositing is just enabled, compositing is never toggled
> during the process.

Normally on games composition is auto-toggled (as you know instead of unredirect) so you are sure composition does not get toggled off automatically?

Anyway I will investigate a bit more later today. I don't think it's necessarily the game's fault.
Comment 7 tempel.julian 2019-12-18 10:51:05 UTC
(In reply to Roman Gilg from comment #6)
> Normally on games composition is auto-toggled (as you know instead of
> unredirect) so you are sure composition does not get toggled off
> automatically?
That's why I checked whether "Allow applications to block compositing" makes a difference. :)
I think it should never toggle with the option turned off?

Even though it would be really unfortunate if toggling would be additionally problematic, as I really would like to have the option to use compositing when minimizing a game for a longer period of time (e.g. game's matchmaking taking very long etc.).

There unfortunately is a bit more oddness involved though: Not every game inside Proton necessarily triggers the issue, even though if they all use DXVK/D9VK. However, some games like Dishonored 2 always trigger it.
Comment 8 tempel.julian 2019-12-18 11:24:31 UTC
Found the cause of the issue: It sits in front of my PC.
The issue is caused by setting KWin to always keep window thumbnails, not just for shown windows.

At this occasion, I also found out that the Proton fullscreen hack also automatically tells KWin to resume compositing when minimizing a game.
Though e.g. the native Linux port of Shadow of the Tomb Raider by Feral doesn't do this.
Comment 9 Roman Gilg 2019-12-18 11:37:09 UTC
(In reply to tempel.julian from comment #8)
> Found the cause of the issue: It sits in front of my PC.
> The issue is caused by setting KWin to always keep window thumbnails, not
> just for shown windows.

Good find. It's still an issue but this restricts the search area and it might make sense to ignore the issue since it is a rather special case. But does this issue also occur without the recent compositing overhaul? If no, we should try to fix the regression for sure.
 
> At this occasion, I also found out that the Proton fullscreen hack also
> automatically tells KWin to resume compositing when minimizing a game.
> Though e.g. the native Linux port of Shadow of the Tomb Raider by Feral
> doesn't do this.

Also interesting. Didn't know that Proton does this automatically but other (major) players like Feral don't.
Comment 10 Kai Krakow 2019-12-21 10:49:42 UTC
(In reply to Roman Gilg from comment #9)
> > At this occasion, I also found out that the Proton fullscreen hack also
> > automatically tells KWin to resume compositing when minimizing a game.
> > Though e.g. the native Linux port of Shadow of the Tomb Raider by Feral
> > doesn't do this.
> 
> Also interesting. Didn't know that Proton does this automatically but other
> (major) players like Feral don't.

This patch was actually contributed by me: If the wine surface switches to full screen resolution, it will set the "bypass compositor" hint via a X11 protocol flag. This reduced game stuttering a lot for me (a real lot). The DXVK author jumped in and confirmed my patch: The kwin compositor (and compositors in general) are a potential source of stutters in games. I think this is mostly due to compositors putting their own vsync routine and the game engine doesn't know of this. May work fine sometimes (some reports even say games are tear-free then), but most other times it breaks smoothness.

I haven't seen the freezing problem in a long time now. But actually seeing the relation to window thumbnails here: Yes, I turned off keeping current thumbnails for all windows also a while ago because it seems to improve game performance. So I tend to confirm that kwin window thumbnails may be the issue. BTW: I was also able to freeze native Linux games that way when run under kwin but that's a few years back.
Comment 11 tempel.julian 2019-12-21 13:19:18 UTC
Thanks for your improvements to the fullscreen hack, it really is a game changer for me!

Though I think Proton might be the positive exception here. With unredirect we wouldn't need to worry about whether an application is willing to cooperate or not. In the kwin-lowlatency fork there also is a window rule option to keep compositing enabled for single applications that would work better that way (e.g. browsers).
Comment 12 tempel.julian 2019-12-21 13:20:30 UTC
Forgot to add: The Proton fullscreen application also freezes with KWin's default settings when executing "kwin_x11 --replace" while the application is running.
Comment 13 Roman Gilg 2019-12-26 20:14:06 UTC
I tried it out now with https://phabricator.kde.org/D26216 being applied on top of master and alt-tabbing in and out of Dishonored 2 worked without problems for me in the tutorial starting area.

System was an AMD RX 5700 XT, MESA (close to) master, Linux kernel 5.4.6.

This was independent of me enabling that apps can block compositing or switching on/off compositing mid-game.

Could you test if there are still problems for you with the above patch applied?
Comment 14 Roman Gilg 2019-12-26 20:20:54 UTC
(In reply to tempel.julian from comment #12)
> Forgot to add: The Proton fullscreen application also freezes with KWin's
> default settings when executing "kwin_x11 --replace" while the application
> is running.

This in contrast is still happening to me. But taking away the compositor while the game is running is quite drastic and handling that is probably not been done correctly in Proton in this case (and I don't think it's worth for them to look into fixing that).

On another note: I didn't notice any performance difference between having the compositor block compositing and with full compositing still going on while in-game, what would point to the compositing rework being done right. Can you confirm?
Comment 15 tempel.julian 2019-12-26 20:37:20 UTC
With the default setting of keeping window thumbnails only for shown windows, the issue completely disappeared for me. Thanks to your rework and Proton's intelligent use of compositor suspend, I can finally really enjoy KWin compositing for the first time.

With the patch you provided, the game still freezes with a black window when setting it to "always" and then alt + tabbing, so it has not changed.

The same btw. happens also on Wayland, but not just with Plasma, also with Sway. So the issue might indeed lie in the Proton fullscreen hack, and not the compositors. For some reason it works with Gnome though.
Workarounds are to switch to borderless mode in the Windows games or use a Wine virtual desktop.

Regarding performance: In Heroes of the Storm, it's 154fps without compositor vs. 147fps with kwin-git. So it's a ~4.5% loss, which I think is fine. Windows DWM performs very similarly. I think KWin Wayland and Sway are a tiny bit faster though.
But I personally really disdain compositor vsync in games in general, I can't stand the added input latency and uneven frame output due to repeated/discarded frames vs. direct tearing. ;)
Comment 16 Nowa Ammerlaan 2022-11-19 11:23:34 UTC
> The issue is caused by setting KWin to always keep window thumbnails, not just for shown windows.

This problem is still present, and on wayland this setting is missing from the compositor settings so the solution might not be immediately obvious. However, switching to an X session, changing this setting, and then switching back to wayland does actually fix the problem. 

So somehow even though the setting is not show in wayland it does actually have an effect on wayland sessions (possibly because the proton games are running in Xwayland?). This might be a reason to unhide the setting in wayland sessions (See also Bug 446709)
Comment 17 Aleksey Gavrilov 2024-06-03 01:12:24 UTC
How is this not higher priority, when Wayland is the default now?

I was going mad trying to figure out why can't I alt-tab out of games on Plasma 6 anymore.

FTR, it's not necessary to relogin to X11 session to turn this off, you can just run
    kwriteconfig6 --file kwinrc --group Compositing --key HiddenPreviews --delete
    qdbus org.kde.KWin /KWin reconfigure
Comment 18 David Edmundson 2024-06-03 08:36:58 UTC
Git commit 1c3a987d7436edf746ca64557f8d5cc553ffe719 by David Edmundson.
Committed on 03/06/2024 at 08:36.
Pushed by davidedmundson into branch 'master'.

wayland: Only load HiddenPreviews options in X11

HiddenPreviews was a hack to not inform X11 that windows were minimised,
so that their previews kept working.

On wayland the user facing setting is not visible but the value is
loaded which is a bad combination.

M  +13   -11   src/options.cpp

https://invent.kde.org/plasma/kwin/-/commit/1c3a987d7436edf746ca64557f8d5cc553ffe719
Comment 19 Bug Janitor Service 2024-06-03 09:24:37 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kwin/-/merge_requests/5814
Comment 20 David Edmundson 2024-06-03 09:34:32 UTC
Git commit 6b0fb5e3ae0b84e1708b6c8df63e68607079d1c8 by David Edmundson.
Committed on 03/06/2024 at 09:34.
Pushed by davidedmundson into branch 'Plasma/6.1'.

wayland: Only load HiddenPreviews options in X11

HiddenPreviews was a hack to not inform X11 that windows were minimised,
so that their previews kept working.

On wayland the user facing setting is not visible but the value is
loaded which is a bad combination.


(cherry picked from commit 1c3a987d7436edf746ca64557f8d5cc553ffe719)

2cb8a700 wayland: Only load HiddenPreviews options in X11

M  +13   -11   src/options.cpp

https://invent.kde.org/plasma/kwin/-/commit/6b0fb5e3ae0b84e1708b6c8df63e68607079d1c8
Comment 21 David Edmundson 2024-06-07 07:56:10 UTC
I fixed this setting being loaded on Wayland. 

I am slightly lost by the former discussion, is there still an issue on X11 and is that still valid?
Comment 22 Bug Janitor Service 2024-06-22 03:47:33 UTC
Dear Bug Submitter,

This bug has been in NEEDSINFO status with no change for at least
15 days. Please provide the requested information as soon as
possible and set the bug status as REPORTED. Due to regular bug
tracker maintenance, if the bug is still in NEEDSINFO status with
no change in 30 days the bug will be closed as RESOLVED > WORKSFORME
due to lack of needed information.

For more information about our bug triaging procedures please read the
wiki located here:
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

If you have already provided the requested information, please
mark the bug as REPORTED so that the KDE team knows that the bug is
ready to be confirmed.

Thank you for helping us make KDE software even better for everyone!
Comment 23 Bug Janitor Service 2024-07-07 03:47:20 UTC
This bug has been in NEEDSINFO status with no change for at least
30 days. The bug is now closed as RESOLVED > WORKSFORME
due to lack of needed information.

For more information about our bug triaging procedures please read the
wiki located here:
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

Thank you for helping us make KDE software even better for everyone!