Bug 437573 - Acquire EGL stream frame fails persistently with EGL_BAD_ACCESS in eglstreams backend for some applications
Summary: Acquire EGL stream frame fails persistently with EGL_BAD_ACCESS in eglstreams...
Status: RESOLVED FIXED
Alias: None
Product: kwin
Classification: Plasma
Component: wayland-generic (show other bugs)
Version: git master
Platform: Manjaro Linux
: NOR normal
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords:
: 437366 (view as bug list)
Depends on:
Blocks:
 
Reported: 2021-05-23 20:11 UTC by Simon Spinner
Modified: 2021-05-29 04:40 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In: 5.22


Attachments
Session log with custom debug output (213.05 KB, text/x-log)
2021-05-23 20:11 UTC, Simon Spinner
Details
Diff of added debug output (4.99 KB, patch)
2021-05-24 09:50 UTC, Simon Spinner
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Spinner 2021-05-23 20:11:58 UTC
Created attachment 138714 [details]
Session log with custom debug output

SUMMARY
9 out of 10 times the plasma desktop background and latte are not rendered at all in a wayland session on my computer with NVIDIA proprietary driver. Instead of seeing the expected desktop background with icons and the latte dock, only black background is visible. Context menus, etc. of the desktop and latte dock work perfectly. Application windows are rendered correctly.

When observing this behavior, the wayland-session.log contains many messages saying:

kwin_wayland_drm: Failed to acquire EGL stream frame

These messages are not logged in the rare case that plasma desktop background and latte dock are visible in a wayland session. The behavior is stable for a complete session, i.e., if a session starts without desktop/latte visible, it stays that way the complete session.

INITIAL ANALYSIS
Added additional debug output in egl_stream_backend.cpp:

kwin_wayland_drm: Failed to acquire EGL stream frame (rc= 12290 ) 

The return code 12290 corresponds to EGL_BAD_ACCESS. The documentation of the function  "eglStreamConsumerAcquireAttribNV/eglStreamConsumerAcquireKHR" says:

- EGL_BAD_ACCESS is generated if there is no GL context
  current to the calling thread, or if the GL context current
  to the calling thread does not contain a texture that is
  connected as the consumer of the EGLStream.

Here is an excerpt of the debug messages I added for the texture/stream handling:
kwin_wayland_drm: (tid= 30525 , ctx= 0x5611b6d51011 ) Attach stream consumer for  30568  ( "/home/simon/kde/usr/bin/plasmashell" )
kwin_wayland_drm: (tid= 30525 , ctx= 0x5611b6d51011 ) Bind texture  40  of stream consumer for  30568  ( "/home/simon/kde/usr/bin/plasmashell" )
[...]
kwin_wayland_drm: (tid= 30525 , ctx= 0x5611b5f84691 ) Create texture  40  for  30568  ( "/home/simon/kde/usr/bin/plasmashell" )
kwin_wayland_drm: Failed to acquire EGL stream frame (rc= 12290 )

ctx=xxx is the pointer to GL context. The first two debug messages are added to EglStreamBackend::attachStreamConsumer and the third message in EglStreamSurfaceTextureWayland::create(). It looks like the texture is bound in a different GL context then the acquire is performed later on which would explain the 
error code. No idea why the contexts are different. 

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: 
(available in About System)
KDE Plasma Version: 5.21.5 or git master 
KDE Frameworks Version: 5.82.0 
Qt Version: 5.15.2
Comment 1 David Edmundson 2021-05-23 20:51:08 UTC
Thanks for the thorough investigation!
Comment 2 Bug Janitor Service 2021-05-23 21:02:31 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kwin/-/merge_requests/1030
Comment 3 David Edmundson 2021-05-23 21:06:06 UTC
Could you attach your diff with your debug, it'll help your comments line up.
Comment 4 Simon Spinner 2021-05-24 09:50:30 UTC
Created attachment 138734 [details]
Diff of added debug output

Here are the changes I made for debugging.
Comment 5 Simon Spinner 2021-05-24 13:48:02 UTC
Tested the merge request on my machine and I can confirm that it prevents the EGL stream frame failures from happening. Started a couple of wayland sessions with your fix and desktop + latte came up correctly each time. The latte dock still has an annoying black box behind it, but the session log does not contain the warning anymore, so I assume it is a different issue (see also my bug report 437366).

Thanks a lot for the quick fix.
Comment 6 David Edmundson 2021-05-24 13:51:39 UTC
Git commit 600c1e0a543554eb44d79e526873c6ebbfcecb72 by David Edmundson.
Committed on 24/05/2021 at 13:51.
Pushed by davidedmundson into branch 'master'.

platforms/drm: Make context current before EGLStreams calls

attachStreamConsumer and resetOutput are not called as part of the scene
render and as such the context might not be set.

All credit goes to Simon Spinner for his investigation.

M  +6    -0    src/plugins/platforms/drm/egl_stream_backend.cpp

https://invent.kde.org/plasma/kwin/commit/600c1e0a543554eb44d79e526873c6ebbfcecb72
Comment 7 David Edmundson 2021-05-24 13:52:01 UTC
Git commit 849bc70853e0cda631ca01c6a3c46947d3f64d94 by David Edmundson.
Committed on 24/05/2021 at 13:51.
Pushed by davidedmundson into branch 'Plasma/5.22'.

platforms/drm: Make context current before EGLStreams calls

attachStreamConsumer and resetOutput are not called as part of the scene
render and as such the context might not be set.

All credit goes to Simon Spinner for his investigation.


(cherry picked from commit 600c1e0a543554eb44d79e526873c6ebbfcecb72)

M  +6    -0    src/plugins/platforms/drm/egl_stream_backend.cpp

https://invent.kde.org/plasma/kwin/commit/849bc70853e0cda631ca01c6a3c46947d3f64d94
Comment 8 Michail Vourlakos 2021-05-29 04:40:31 UTC
*** Bug 437366 has been marked as a duplicate of this bug. ***