Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using XCB event processing is incompatible with GLX on DRI2 #47

Closed
jlindgren90 opened this issue Nov 10, 2018 · 16 comments

Comments

2 participants
@jlindgren90
Copy link

commented Nov 10, 2018

Platform

Arch Linux

GPU, drivers, and screen setup

Intel graphics (Skylake), modesetting driver, mesa 18.2.4

name of display: :0.0
display: :0 screen: 0
direct rendering: Yes
Extended renderer info (GLX_MESA_query_renderer):
Vendor: Intel Open Source Technology Center (0x8086)
Device: Mesa DRI Intel(R) HD Graphics 520 (Skylake GT2) (0x1916)
Version: 18.2.4
Accelerated: yes
Video memory: 3072MB
Unified memory: yes
Preferred profile: core (0x1)
Max core profile version: 4.5
Max compat profile version: 3.0
Max GLES1 profile version: 1.1
Max GLES[23] profile version: 3.2
OpenGL vendor string: Intel Open Source Technology Center
OpenGL renderer string: Mesa DRI Intel(R) HD Graphics 520 (Skylake GT2)
OpenGL core profile version string: 4.5 (Core Profile) Mesa 18.2.4
OpenGL core profile shading language version string: 4.50
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile

OpenGL version string: 3.0 Mesa 18.2.4
OpenGL shading language version string: 1.30
OpenGL context flags: (none)

OpenGL ES profile version string: OpenGL ES 3.2 Mesa 18.2.4
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20

Environment

XFCE

Compton version

Version: v4-rc1-6-gb18d46b

Extensions:

  • Name Pixmap: Yes
  • Shape: Yes
  • XRandR: Yes
  • Present: Present

Misc:

  • Use Overlay: Yes

Compton configuration:

backend = "glx";
vsync = "opengl-swc";
detect-client-opacity = true;
paint-on-overlay = true;

Steps of reproduction

  1. Start compton

Expected behavior

Screen does not flicker horribly

Current Behavior

Screen flickers horribly

Other details

Bisected:

# bad: [403d170f326e7d11d73bd89c687ee312f715c8f6] Merge branch 'next'
# good: [316eac0613bf342ff91cc645a6c3c80e6b9083fb] GitHub: Add an issue template
git bisect start 'master' '316eac0613bf342ff91cc645a6c3c80e6b9083fb'
# bad: [18022181ee8f198146fe26479cf56af382af015d] Make sure to clear the rectangles
git bisect bad 18022181ee8f198146fe26479cf56af382af015d
# bad: [209b751b2524ce7eb93fa3c50aebe823ddf800ab] Port more stuff to xcb
git bisect bad 209b751b2524ce7eb93fa3c50aebe823ddf800ab
# good: [cac8094ce12cd40706fb48f9ab35354d9ee7c48f] Update manpage
git bisect good cac8094ce12cd40706fb48f9ab35354d9ee7c48f
# good: [c37c6c41edd3008f1cf0c663688ae058f6b65deb] Fix Makefile dependency
git bisect good c37c6c41edd3008f1cf0c663688ae058f6b65deb
# good: [2adfdfa897a43dbd1466e172eca6e0b7783328fe] Clear prototypes
git bisect good 2adfdfa897a43dbd1466e172eca6e0b7783328fe
# good: [967d9f32eaadb64961ec6638cc478ca3403b0329] Workaround for what seems to be a race in Xserver
git bisect good 967d9f32eaadb64961ec6638cc478ca3403b0329
# bad: [7af815a0aaaffc02e114e1d0adccb5f87dcc3548] Proper fix for screen freeze
git bisect bad 7af815a0aaaffc02e114e1d0adccb5f87dcc3548
# skip: [43f3744fea075e5fdc6e01a0e66a00b15833cddb] Revert "Workaround for what seems to be a race in Xserver"
git bisect skip 43f3744fea075e5fdc6e01a0e66a00b15833cddb
# only skipped commits left to test
# possible first bad commit: [7af815a0aaaffc02e114e1d0adccb5f87dcc3548] Proper fix for screen freeze
# possible first bad commit: [43f3744fea075e5fdc6e01a0e66a00b15833cddb] Revert "Workaround for what seems to be a race in Xserver"
@jlindgren90

This comment has been minimized.

Copy link
Author

commented Nov 10, 2018

Note: skipped commit 43f3744 because it fails to build:

src/compton.c: In function ‘session_init’:
src/compton.c:5417:5: warning: implicit declaration of function ‘XSetEventQueueOwner’; did you mean ‘XSetSelectionOwner’? [-Wimplicit-function-declaration]
     XSetEventQueueOwner(ps->dpy, XCBOwnsEventQueue);
     ^~~~~~~~~~~~~~~~~~~
     XSetSelectionOwner
src/compton.c:5417:34: error: ‘XCBOwnsEventQueue’ undeclared (first use in this function); did you mean ‘XEventsQueued’?
     XSetEventQueueOwner(ps->dpy, XCBOwnsEventQueue);
                                  ^~~~~~~~~~~~~~~~~
                                  XEventsQueued
src/compton.c:5417:34: note: each undeclared identifier is reported only once for each function it appears in
@jlindgren90

This comment has been minimized.

Copy link
Author

commented Nov 10, 2018

Here is a video in case it's not obvious what horrible flickering looks like:
https://share.mailbox.org/ajax/share/087aa4490975e54f861e77e975e547e9b7380de25d1890f3/1/8/NDA/NDAvNjI

@yshui

This comment has been minimized.

Copy link
Owner

commented Nov 10, 2018

@jlindgren90 Probably a duplication of #34

@jlindgren90

This comment has been minimized.

Copy link
Author

commented Nov 10, 2018

@yshui Maybe, seems very similar to #33 as well (that one is with nouveau but reports exactly the same issue with the same bisect result).

This part is interesting, it's exactly the same as what I see:

it switches back and forth between the first frame ever shown at session startup (black screen when starting from startx, or display manager's wallpaper) and the current real frame.

@yshui

This comment has been minimized.

Copy link
Owner

commented Nov 10, 2018

@jlindgren90 This is likely to be different from #33. In #33 the flickering seems to happen even when compton is not rendering (compton only renders a frame when contents of the screen is updated). While in #34 and here, the flickering happens when compton renders a frame.

@jlindgren90

This comment has been minimized.

Copy link
Author

commented Nov 10, 2018

@yshui I investigated this a bit more this morning and it seems to be specific to DRI2. With DRI3 or software rendering (LIBGL_ALWAYS_SOFTWARE=1), the flickering goes away.

Looking at mesa source (dri2.c), one can see that it is in fact incompatible with xcb event processing due to usage of XESetWireToEvent()/XESetEventToWire(), which hook into the traditional Xlib event processing. Without Xlib in the loop, DRI2 misses its Invalidate events and the result is that glXSwapBuffers() doesn't work as expected. (Take a look at dri2_glx.c - dri2XcbSwapBuffers() contains an explicit XSync() call to wait for Invalidate events, which it never gets.)

So it seems that by switching to xcb event processing, you have in effect made compton no longer work on DRI2 setups. I guess it's up to you whether you care about this or not. Personally, I will give DRI3 a try again and see if it is more stable than the last time I experimented with it. If not, I guess I can continue using an older version of compton.

@yshui

This comment has been minimized.

Copy link
Owner

commented Nov 10, 2018

I investigated this a bit more this morning and it seems to be specific to DRI2

Yes, That is consistent with #34

Looking at mesa source (dri2.c), one can see that it is in fact incompatible with xcb event processing

Excellent observation.

I guess one have to use the Xlib event processing to use GLX then... This is quite annoying.

I wonder if we can push rendering into its own thread, but that will also make things much more complicated. (I don't think this is possible.)

@yshui yshui changed the title [regression] Unusable screen flickering on intel/modesetting Using XCB event processing is incompatible with DRI2 Nov 10, 2018

@yshui yshui changed the title Using XCB event processing is incompatible with DRI2 Using XCB event processing is incompatible with GLX on DRI2 Nov 10, 2018

@yshui yshui added bug driver and removed bug labels Nov 10, 2018

@yshui yshui added this to To do in Investigation Nov 10, 2018

@yshui

This comment has been minimized.

Copy link
Owner

commented Nov 10, 2018

I guess it's up to you whether you care about this or not.

Of course, I wish to make compton compatible with as many setups as reasonably possible. We switched from Xlib event processing to xcb because there is a bug in Xlib that caused screen freeze in compton. And I don't have enough faith in Xlib to believe this kind of problem won't happen again.

But then this bug happened. Now I'm not sure what is the best thing to do here.

@yshui

This comment has been minimized.

Copy link
Owner

commented Nov 10, 2018

I think #33 is probably also related, since nouveau by default doesn't have dri3

@jlindgren90

This comment has been minimized.

Copy link
Author

commented Nov 10, 2018

I was about to say that requiring DRI3 might be a reasonable option -- but if nouveau is still on DRI2 by default, that's less than ideal.

I am not sure what to suggest here either. Maybe it would be good to start by at least filing a bug/feature request against Mesa (to update DRI2 to work properly with xcb), and see what the response is.

Edit: I added a comment to your nouveau bug with some of my analysis, hopefully that helps:
https://bugs.freedesktop.org/show_bug.cgi?id=108651#c5

@yshui

This comment has been minimized.

Copy link
Owner

commented Nov 10, 2018

@jlindgren90 Found a workaround in mesa bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=35945#c4

Will try implementing it later today.

@jlindgren90

This comment has been minimized.

Copy link
Author

commented Nov 10, 2018

Ugh, it gets worse than that. Here is the full workaround in Qt:
https://github.com/qt/qtbase/blob/0dae641331bbd21207f6c74a7a34e0c74103d61e/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxintegration.cpp#L128

It would be much better for this to be fixed on the mesa side.

@yshui

This comment has been minimized.

Copy link
Owner

commented Nov 10, 2018

@jlindgren90 This has been known for at least 6 years, and isn't fixed yet...

Fix this in Mesa might require some coordinated effort from both libxcb and Mesa, I don't know how hard it is.

BTW, we don't need most of the Qt workaround code, since they are just dealing with Qt internal event handling.

@yshui

This comment has been minimized.

Copy link
Owner

commented Nov 10, 2018

I added the hack in the dri2-hack branch, can you test?

@jlindgren90

This comment has been minimized.

Copy link
Author

commented Nov 11, 2018

Fixes the flickering here. Thank you for your work on compton and for addressing this so quickly!

@yshui

This comment has been minimized.

Copy link
Owner

commented Nov 11, 2018

Great!

But I think we still need to follow up on Mesa side to get a proper fix.

@yshui yshui closed this Nov 11, 2018

yshui added a commit that referenced this issue Nov 11, 2018

Merge pull request #52 from yshui/dri2-hack
Workaround the incompatibility between DRI2 and xcb

Fixes #33 #34 #47

@yshui yshui added the revisit label Nov 13, 2018

@yshui yshui moved this from To do to Done in Investigation Feb 27, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.