D19867: [X11] Force glXSwapBuffers to block with NVIDIA driver
Erik Kurzinger <[email protected]>
| Newsgroups | gmane.comp.kde.devel.kwin |
|---|---|
| Message-ID | <[email protected]> |
ekurzinger created this revision. ekurzinger added a reviewer: KWin. ekurzinger added a project: KWin. Herald added a subscriber: kwin. ekurzinger requested review of this revision. REVISION SUMMARY The NVIDIA implementation of glXSwapBuffers will, by default, queue up to two frames for presentation before blocking. KWin's compositor, however, assumes that calls to glXSwapBuffers will always block until the next vblank when rendering double buffered. This assumption isn't valid, as glXSwapBuffers is specified as being an implicit glFlush, not an implicit glFinish, and so it isn't required to block. When this assumption is violated, KWin's frame timing logic will break. Specifically, there will be extraneous calls to setCompositeTimer with a waitTime of 0 after the non-blocking buffer swaps, dramatically reducing desktop responsiveness. To remedy this, a call to glXWaitGL was added by Thomas Luebking after glXSwapBuffers in 2015 (see bug 346275, commit 8bea96d7018d02dff9462326ca9456f48e9fe9fb <https://phabricator.kde.org/R108:8bea96d7018d02dff9462326ca9456f48e9fe9fb>). That glXWaitGL call is equivalent to a glFinish call in direct rendering, so it was a good way to make glXSwapBuffers behave as though it implied a glFinish call. However, the NVIDIA driver will by default do a busy wait in glFinish, for reduced latency. Therefore that change dramatically increased CPU usage. __GL_YIELD can be set to USLEEP (case insensitive) to change the behavior and use usleep instead. When using the NVIDIA driver, KWin will disable vsync entirely if __GL_YIELD isn't set to USLEEP (case sensitive, a bug in KWin). However, the NVIDIA driver supports another environment variable, __GL_MaxFramesAllowed, which can be used to control how many frames may be queued by glXSwapBuffers. If this is set to 1 the function will always block until retrace, in line with KWin's expectations. This allows the now-unnecessary call to glXWaitGL to be removed along with the logic to conditionally disable vsync, providing a better experience on NVIDIA hardware. TEST PLAN Run KWin using the X11 backend with the proprietary NVIDIA driver. Ensure the TripleBuffer option is not set to true in Xorg's configuration file. Ensure vsync has not been manually disabled (either in NVIDIA's or KWin's settings). - Moving windows should not exhibit significant lag - CPU usage should never be excessively high - No screen tearing should be observed REPOSITORY R108 KWin REVISION DETAIL https://phabricator.kde.org/D19867 AFFECTED FILES plugins/platforms/x11/standalone/glxbackend.cpp To: ekurzinger, #kwin Cc: kwin, jraleigh, GB_2, mkulinski, ragreen, jackyalcine, Pitel, iodelay, bwowk, ZrenBot, ngraham, alexeymin, lesliezhai, ali-mohamed, hardening, jensreuterberg, abetts, sebas, apol, mart