mesa/include
Gregory Hainaut fa84f6225b dri: Extend __DRIbackgroundCallableExtensionRec to include a callback that checks for thread safety
DRI-drivers could call Xlib functions, for example to allocate a new back
buffer.

When glthread is enabled, the driver runs mostly on a separate thread.
Therefore we need to guarantee the thread safety between libX11 calls
from the applications (not aware of the extra thread) and the ones from
the driver.

See discussion thread:
   https://lists.freedesktop.org/archives/mesa-dev/2017-April/152547.html

Fortunately, Xlib allows to lock display to ensure thread safety but
XInitThreads must be called first by the application to initialize the lock
function pointer. This patch will allow to check XInitThreads was called
to allow glthread on GLX or EGL platform.

Note: a tentative was done to port libX11 code to XCB but it didn't solve fully
thread safety.
See discussion thread:
   https://lists.freedesktop.org/archives/mesa-dev/2017-April/153137.html

Note: Nvidia forces the driver to call XInitThreads. Quoting their manpage:
"The NVIDIA OpenGL driver will automatically attempt to enable Xlib
thread-safe mode if needed. However, it might not be possible in some
situations, such as when the NVIDIA OpenGL driver library is dynamically
loaded after Xlib has been loaded and initialized. If that is the case,
threaded optimizations will stay disabled unless the application is
modified to call XInitThreads() before initializing Xlib or to link
directly against the NVIDIA OpenGL driver library. Alternatively, using
the LD_PRELOAD environment variable to include the NVIDIA OpenGL driver
library should also achieve the desired result."

v2: based on Nicolai and Matt feedback
Use C style comment

v3: based on Emil feedback
split the patch in 3
s/isGlThreadSafe/isThreadSafe/

v5: based on Marek comment
Add a comment that isThreadSafe is supported by extension v2

Signed-off-by: Gregory Hainaut <gregory.hainaut@gmail.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
2017-05-29 17:06:37 +01:00
..
c11 c11/threads: rework Windows thrd_current() comment 2017-05-04 18:00:23 +01:00
CL clover: Update OpenCL headers to version 1.2 from Khronos. 2014-04-29 13:01:10 +02:00
D3D9 Introduce .editorconfig 2016-08-31 17:06:54 -07:00
d3dadapter d3dadapter/present: Add precision for WaitBufferReleased 2016-12-20 23:44:21 +01:00
EGL eglmesaext: add new enums for EGL_MESA_drm_image_formats 2017-02-06 17:41:28 +01:00
GL dri: Extend __DRIbackgroundCallableExtensionRec to include a callback that checks for thread safety 2017-05-29 17:06:37 +01:00
GLES gles: Update glext.h to revision 20798. 2013-07-29 10:34:42 -07:00
GLES2 Remove GL_GLEXT_PROTOTYPES guards from non-ext headers. 2016-09-12 16:52:43 +01:00
GLES3 Remove GL_GLEXT_PROTOTYPES guards from non-ext headers. 2016-09-12 16:52:43 +01:00
HaikuGL include/haiku: fix comment typo 2014-08-28 21:41:29 -04:00
KHR egl: import platform headers from registry (v2) 2015-06-05 19:44:33 +02:00
pci_ids radeonsi/gfx9: add support for Raven 2017-05-15 13:00:26 +02:00
vulkan vulkan: Update registry and headers to 1.0.49 2017-05-16 08:38:34 -07:00
c99_alloca.h c99_alloca.h: Also use <alloca.h> for cygwin 2015-03-07 18:18:32 +00:00
c99_compat.h scons: set HAVE_FUNC_ATTRIBUTE_ALIAS 2017-01-18 16:01:14 +00:00
c99_math.h math: Import isinf and others to global namespace 2016-04-18 11:10:25 +01:00
no_extern_c.h include: Add helper header to help trap includes inside extern C. 2015-03-06 12:38:55 +00:00