Bug: GLX direct rendering is blocked by GrabServer even when the client is impervious to grabs by XTestGrabControl

I need to capture and encode the screen contents continuously even when the X-Server is grabbed with XGrabServer. (capturing is done using GLX, encoding is done using NVENC)

The documented way to do this in X is to use the XTestGrabControl function which can make an application impervious to server grabs.
However this does not work with the NVidia driver and GLX direct rendering. (it works with the Nouveau driver and GLX direct rendering, but Nouveau does not support NVENC and my customer probably will insist on using the NVidia drivers anyway.)
This seems to be a bug in the NVidia driver.
I have reported it at
https://devtalk.nvidia.com/default/topic/1063864/drivers/bug-in-linux-driver-430-50-glx-direct-rendering-is-blocked-by-grabserver-even-when-the-client-is-impervious-to-grabs-by-xtestgrabcontrol/
and at

My questions/reqpests:

  • I'd appreciate when you can fix this in one of the next driver releases. (the sooner the better of course) This is important for a project with a big customer who plans to use hundreds of NVIdia cards.
  • Or Is there a workaround? Or does NVidia provide another API for making an application impervious to a server grab? Or is it possible to access some NVidia APIs directly, without any intervention or control by the X-Server? (e.g. NVENC and OpenGL, or the Capture API, ...)

Any help or pointers where to continue looking at are appreciated.


To reproduce, run the attached program. (ImperviousToServerGrabsGLX2.c, built with the included Makefile)

Then grab the server, e.g. using (GrabServer.c )

Then the program ImperviousToServerGrabsGLX2 stops drawing while the server is grabbed.

If you switch to indirect drawing by changing the /* direct = / True to / direct = */ False in the call to glXCreateContext line 78 of ImperviousToServerGrabsGLX2.c, then it works correctly, i.e., the drawing continues even when the server is grabbed.
(Be sure to enable indirect drawing in xorg.conf for testing that.)

I.e. XTestGrabControl works for indirect GLX rendering, but it doesn’t work for direct GLX rendering (but should work for direct rendering, too)

This has been reproduced on CentOS7 64bit with Xorg 1.20.1 and Nvidia driver 410.78.
and on RHEL 7.7 with Xorg 1.20.4 and Nvidia driver 430.50, 64 bit.
I am not sure whether the cause is in Xorg or in the Nvidia driver or in some other component of the DRI infrastructure.

This problem does not occur when using the Nouveau driver instead of the NVidia driver.

This probably means that the bug is in the NVidia driver and not in the X-Server.

I reproduced it with a Quadro P600 card, but I guess that it also will happen with other cards.

Thanks,

Chris
nvidia-bug-report.log.gz (893 KB)
ImperviousToServerGrabsGLX2.tar.gz (1.26 KB)
GrabServer.tar.gz (686 Bytes)

I have changed the start of this thread from a question for workarounds to a bugreport,
and I have included everything needed to reproduce that, rather than
just linking to my report at gitlab.freedesktop.org.

I hope this helps you to find the cause of the bug, and enables you to fix it.

Thank you,

Chris