diff options
author | Gregory Hainaut <[email protected]> | 2017-05-29 13:18:25 +0200 |
---|---|---|
committer | Emil Velikov <[email protected]> | 2017-05-29 17:06:37 +0100 |
commit | fa84f6225b1342dbe564962f639de50c5e9029d3 (patch) | |
tree | af2a0ecf59e778d0add6a14fabcd59b2f37cfae7 /include | |
parent | 5cb16e07ab9fc9a2e3d900ed4e978c787314c8ba (diff) |
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 <[email protected]>
Reviewed-by: Emil Velikov <[email protected]>
Diffstat (limited to 'include')
-rw-r--r-- | include/GL/internal/dri_interface.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/include/GL/internal/dri_interface.h b/include/GL/internal/dri_interface.h index c83056aa702..ffe99499fca 100644 --- a/include/GL/internal/dri_interface.h +++ b/include/GL/internal/dri_interface.h @@ -1721,6 +1721,19 @@ struct __DRIbackgroundCallableExtensionRec { * operations (e.g. it should just set a thread-local variable). */ void (*setBackgroundContext)(void *loaderPrivate); + + /** + * Indicate that it is multithread safe to use glthread. For GLX/EGL + * platforms using Xlib, that involves calling XInitThreads, before + * opening an X display. + * + * Note: only supported if extension version is at least 2. + * + * \param loaderPrivate is the value that was passed to to the driver when + * the context was created. This can be used by the loader to identify + * which context any callbacks are associated with. + */ + GLboolean (*isThreadSafe)(void *loaderPrivate); }; #endif |