Commit graph

99 commits

Author SHA1 Message Date
Félix Baylac Jacqué f4dff011f7 glx: introduce NIX_GLVND_GLX_PATH env variable
If NIX_GLVND_GLX_PATH is set, libglvnd will try to load the glx DSOs
from the directory it points at instead of loading them from LD_LIBRARY_PATH.
2022-11-15 16:27:16 +01:00
Kyle Brenneman a7bb6f4d19 Remove extra paragraph from license text.
Remove the "If only executable code is distributed..." paragraph from
the license text. Everything now uses a normal MIT license.

The only code from Khronos that's included in libglvnd is the EGL/GL
header and XML files, which do not contain that paragraph.

Fixes https://gitlab.freedesktop.org/glvnd/libglvnd/-/issues/221
2021-09-30 09:21:34 -06:00
Kyle Brenneman 4a08df7bdc GLX: Remove the XESetCloseDisplay callback during teardown.
When libGLX.so is unloaded, call XESetCloseDisplay to remove the display close
callback for any displays that still exist.

Otherwise, if libGLX.so is loaded using dlopen, and then unloaded while a
display is still open, then XCloseDisplay would try to call the (now dangling)
callback.
2021-06-16 11:32:26 -06:00
Kyle Brenneman dd2d28a033 GLX: Fix a potential deadlock in OnDisplayClosed.
In OnDisplayClosed, unlock the __glXDisplayInfoHash lock before locking
glxContextHashLock.

In CommonMakeCurrent, it holds glxContextHashLock while it tries to take the
__glXDisplayInfoHash lock, so if CommonMakeCurrent and OnDisplayClosed run at
the same time, they could deadlock.

To avoid that, OnDisplayClosed will set a new inTeardown flag in the
__GLXdisplayInfoHash, then it will unlock the display hash before calling
__glXDisplayClosed.

After __glXDisplayClosed is finished, OnDisplayClosed will lock
__glXDisplayInfoHash again long enough to remove the display from the
hashtable.

The inTeardown flag tells __glXLookupDisplay to return NULL, since after that
point, nothing should be trying to look up the display. In principle, we could
just remove the display from the hashtable up front, but then if something did
try to look up the display, then __glXLookupDisplay would try to create a new
__GLXdisplayInfo for it.

Fixes https://gitlab.freedesktop.org/glvnd/libglvnd/-/issues/213
2020-11-19 11:54:50 -07:00
Kyle Brenneman 60331f22d2 Add support for GLX_EXT_no_config_context.
Added a dispatch handler for glXCreateContextAttribsARB. It'll look for a
GLX_SCREEN attribute first if the caller provides one, and then the GLXFBConfig
handle if the caller doesn't.
2017-12-06 12:43:39 -07:00
Kyle Brenneman 75c77c4f9e GLX: Fix an error in handling GLX dispatch stubs.
In __glXGetGLXDispatchAddress, add a missing call to
__GLXapiImports::getProcAddress.
2017-07-25 08:46:47 -06:00
Kyle Brenneman 470fc824a3 Merge branch 'tests-glx-genentry'
Expand the unit tests to test the generated GLX entrypoints.
2016-10-27 13:07:58 -06:00
Kyle Brenneman 61bd107cc6 Fix a crash in process termination when EGL and GLX are both loaded.
Added a new function to libGLdispatch, __glDispatchForceUnpatch, which forces
it to unpatch the OpenGL entrypoints before libEGL or libGLX can unload the
vendor library that patched them.

If a vendor patches the OpenGL entrypoints, libGLdispatch doesn't unpatch them
when that vendor's context is no longer current, because that adds too much
overhead to repeated MakeCurrent+LoseCurrent calls. But, that also means that
the patch callbacks end up being dangling pointers after the vendor library is
unloaded.

This mainly shows up at process termination when a process loads both libEGL
and libGLX, because __glxFini and __eglFini will both call the vendor's
threadAttach callback.

Fixes https://github.com/NVIDIA/libglvnd/issues/103
2016-10-24 14:52:27 -06:00
Kyle Brenneman a77ce91f37 GLX: Add an environment variable to specify a vendor for a single screen.
When libGLX.so selects a vendor libray for an X screen, it will look for an
environment variable __GLX_FORCE_VENDOR_LIBRARY_<N>, where <N> is the screen
number.

This is mainly for testing and debugging. It allows unit tests to force
different vendors on different screens, and it allows tests to avoid preloading
the dummy vendor library.
2016-10-18 13:46:15 -06:00
Kyle Brenneman 1cd6a43122 Factor out some common extension string functions.
Moved the UnionExtensionStrings and IntersectionExtensionStrings functions from
EGL to utils_misc.c.

Changed libGLX to use the common UnionExtensionStrings and IsTokenInString
functions instead of its own versions of them.

Moved ParseClientVersionString to libglx.c near where it's used, and deleted
libglxstring.c and libglxstring.h.
2016-10-13 13:22:13 -06:00
Kyle Brenneman d0ced9a2e3 GLX: Fix a couple of errors.
Moved the unlock in __glXLookupVendorByName to after the calls to update the
GLX entrypoints.

Fixed a typo in GLXEntrypointUpdateCallback.
2016-05-27 13:05:40 -06:00
Kyle Brenneman 17f5566087 GLX: Some additional cleanup for the GLX dispatch table.
Added a license+copyright comment to winsys_dispatch.[ch].

Renamed __GLVNDwinsysDispatchIndexHash to __GLVNDwinsysDispatchIndexEntry,
since it's not a hashtable anymore.

In __glXLookupVendorByName, only call __glvndWinsysDispatchGetCount once
instead of on every loop iteration.

Removed the locks for the GLX dispatch index list and the generated GLX
dispatch stubs. Instead, the vendor hashtable's lock is used for all three.

There's enough overlap between when the three locks are taken that using
separte locks has very little benefit and increases the risk of deadlocks.
2016-05-17 10:32:41 -06:00
Kyle Brenneman 968349de93 GLX: Move the vendor GLX dispatch table to winsys_dispatch.c.
Remove the __GLXvendorInfo::dynDispatchHash hashtable, and replace it with a
dispatch table from winsys_dispatch.
2016-05-17 10:32:41 -06:00
Kyle Brenneman 39070d4e59 GLX: Clean up __glXFetchDispatchEntry.
Some minor cleanup of __glXFetchDispatchEntry.

Handle the various failure cases more directly: If we can't find a name, or if
the vendor library doesn't support a function, then return early.

If we can't allocate a cache entry for the function, then return the dispatch
stub anyway. It can try to store the stub again next time.
2016-05-17 10:32:41 -06:00
Kyle Brenneman 774c9b25cb GLX: Assign indices to the GLX dispatch functions defined in libGLX.
The dispatch functions in libGLX are now added to the GLX dispatch list just
like vendor-provided dispatch functions would be.

The function name cache in glXGetProcAddress is no longer required for
correctness, because it can look up a locally-defined dispatch stub in the same
list as the vendor-provided stubs.

In addition to simplifying glXGetProcAddress, this allows vendor libraries to
look up all GLX functions by index. In particular, this would allow a vendor
to look up glXDestroyContext, which would let it recover properly if it fails
to add a new context to the context-to-vendor mapping.
2016-05-17 10:32:40 -06:00
Kyle Brenneman 8167e35e53 GLX: Use winsys_dispatch to keep track of GLX dispatch stubs.
Remove the __GLXdispatchIndexHash table, and use the list in winsys_dispatch.c
to keep track of the function indices, names, and dispatch stubs.

If libGLX generates a GLX dispatch stub, then it will now assign an index to it
when it generates the stub, not when it fills in the stub. That lets it treat
generated stubs the same way regardless of whether they've been filled in or
not.

When assigning an index, it will now call the setDispatchIndex callback for
every vendor library, not just the vendor that provided the dispatch stub.

When loading a vendor library, it will call the new vendor's setDispatchIndex
callback for every existing GLX dispatch function.
2016-05-17 10:32:40 -06:00
Kyle Brenneman 26cfae955b GLX: Remove references to __glXDispatchNoopPtr.
Removed the functions __glXGetCurrentDispatch and __glXGetStaticDispatch.
Everything that used either one now looks up the __GLXvendorInfo pointer
instead.

Also removed __glXGetGLDispatch, since it's not used anywhere.

Reviewed-by: aplattner@nvidia.com
2016-05-04 11:43:04 -06:00
Kyle Brenneman d7f4370dde Merge pull request #79 from kbrenneman/replace-x11glvnd-v2.
Replace x11glvnd with GLX_EXT_libglvnd extension.
2016-03-28 17:44:05 -06:00
Kyle Brenneman 547daaf228 GLX: Use GLX_EXT_libglvnd instead of x11glvnd.
Reworked libGLX.so to use the GLX_EXT_libglvnd extension instead of x11glvnd.

In __glXLookupVendorByScreen, use __glXQueryServerString to look up the vendor
name string, and then split it up with strtok_r.
2016-03-24 12:46:41 -06:00
Kyle Brenneman 3f2f59cb0e GLX: Move the display pointer to __GLXdisplayInfo.
Move the display pointer from __GLXdisplayInfoHash to __GLXdisplayInfo, so that
we don't have to pass around both the Display and __GLXdisplayInfo pointers to
a function that needs both of them.
2016-03-24 12:44:25 -06:00
Kyle Brenneman 3c6d7d753c GLX: Remove __glXFreeDisplay.
__glXFreeDisplay is defined but not used anywhere.
2016-03-24 12:44:25 -06:00
Kyle Brenneman 3f4674f8f6 GLX: Use XESetCloseDisplay for the close display callback.
libGLX will now use XAddExtension and XESetCloseDisplay to register a callback
when a display is closed.

Removed XGLVRegisterCloseDisplayCallback and
XGLVUnregisterCloseDisplayCallbacks from the x11glvnd client library.

This is in preparation for removing the x11glvnd extension.
2016-03-24 12:44:25 -06:00
Kyle Brenneman 3a84276f63 GLX: Add the patch callbacks directly to __GLXapiImports.
Added the function pointers for entrypoint rewriting as members of
__GLXapiImports, instead of using a separate __GLdispatchPatchCallbacks
pointer.

Moved the __GLdispatchPatchCallbacks struct to GLdispatch.h.
2016-03-10 16:57:34 -07:00
Kyle Brenneman da7ae346e3 GLX: Change __glx_Main to use the libGLX-allocated __GLXapiImports table.
__glx_Main now takes a pointer to the __GLXapiImports struct and fills it in.

The __GLXapiImports struct is now allocated and zeroed by libGLX. This makes it
possible to add an optional element to the end of the struct without breaking
backward compatibility.
2016-03-10 16:11:47 -07:00
Kyle Brenneman 3887b8e90e GLX: Change libGLX to use its own copy of the __GLXapiImports struct.
libGLX now allocates its own copy of the __GLXapiImports struct for each vendor
library. This is in preparation for providing an allocated and zeroed struct to
__glx_Main to fill in.
2016-03-03 13:50:24 -07:00
Kyle Brenneman 58d8dcaeb0 GLX: Change the __glx_Main function prototype.
Removed the vendorID and vendorName parameters from the __glx_Main function,
since neither one is useful to a vendor.

Instead, __glx_Main now takes the __GLXvendorInfo pointer as a parameter. We
can use that to look up any additional per-vendor information that might be
added in the future.
2016-03-03 11:11:11 -07:00
Kyle Brenneman ba1c58a558 Rename a couple of functions in the ABI's.
Renamed __GLdispatchPatchCallbacks::checkPatchSupported to isPatchSupported,
and renamed __GLXapiImports::checkSupportsScreen to isScreenSupported.
2016-02-29 13:50:39 -07:00
Kyle Brenneman 88807b95b9 GLX: Change the mapping functions to return a vendor directly.
Changed vendorFromContext, vendorFromFBConfig, and vendorFromDrawable to return
the vendor pointer as its return value instead of using a pointer.

Returning by pointer was necessary when the functions would also return a
screen number. But, GLX objects are now associated directly with a vendor,
not with any particular screen or display.
2016-02-29 13:50:38 -07:00
Kyle Brenneman e59233a1a9 GLX: Remove the XVisualInfo to vendor mapping.
Removed addScreenVisualMapping, removeScreenVisualMapping, and vendorFromVisual
from __GLXapiExports.

The XVisualInfo to vendor mapping is a no-op, since it just uses the screen number
to select a vendor.

It might be useful in the future at some point to provide a mechanism for
selecting between multiple vendors on a single X screen, but such an option
would more likely be used with the GLXFBConfig-based functions, not with the
XVisualInfo-based ones.
2016-02-29 13:50:36 -07:00
Kyle Brenneman b8e2cec4b4 GLX: Return failures from the addVendor*Mapping functions.
The addVendorContextMapping, addVendorFBConfigMapping, and
addVendorDrawableMapping functions in __GLXapiExports now return an int to
indicate success or failure.

Updated the various GLX functions so that they will deal with those failures.
In the case of context and drawable creations functions, it will call back into
the vendor library to destroy the object before returning.
2016-02-29 13:50:35 -07:00
Kyle Brenneman beb204dcac GLX: Remove the __GLXdispatchTableDynamic struct.
Remove the __GLXdispatchTableDynamic struct. Move the hashtable that it
contained to be a member of __GLXvendorInfo instead.

Reviewed-by: Andy Ritger <aritger@nvidia.com>
2016-02-29 13:37:01 -07:00
Kyle Brenneman d715387a44 GLX: Cleanup vendor library loading.
The __GLXvendorNameHash, __GLXvendorInfo, and vendor name are now allocated in
a single malloc.

Remove some duplicated cleanup code between TeardownVendor and
__glXLookupVendorByName.

Merge TeardownVendor into CleanupVendorNameInto.

In __glXLookupVendorByName, simplify the cleanup path on error. Remove the
local variables that are just copies of the __GLXvendorInfo members.

Remove InitExportsTable and statically initialize the glxExportsTable struct.

Reviewed-by: Andy Ritger <aritger@nvidia.com>
2016-02-29 13:36:51 -07:00
Kyle Brenneman cd9c312718 GLX: Add support for GLX_MESA_multithread_makecurrent.
Rework the context tracking in libGLX.so so that it can handle a context that's
current to more than one thread at a time.

There's now a single hashtable to keep track of contexts, which replaces both
the (context -> vendor) map and the current context map.

The new __GLXcontextInfo struct keeps track of the number of threads where the
context is current, and whether the context is marked for deletion.

This also provides a workaround of sorts for some broken applications, which
try (and fail) to make a context current on two threads at the same time, and
aren't prepared to deal with the resulting BadAccess error. Moving the
duplicate context check into the vendor library allows it to preserve that
pre-libglvnd behavior for apps that depend on it.

Reviewed-by: Andy Ritger <aritger@nvidia.com>
2016-02-26 13:08:24 -07:00
Kyle Brenneman 431ea8f709 Remove the GLVNDPthreadFuncs parameter from the lkdhash.h macros.
The macros in lkdhash.h now just use the __glvndPthreadFuncs table, instead of
taking a GLVNDPthreadFuncs parameter.

Reviewed-by: Andy Ritger <aritger@nvidia.com>
2016-02-25 12:54:17 -07:00
Kyle Brenneman 6c2a02b25d Move the GLVNDPthreadFuncs struct into glvnd_pthread.c.
glvnd_pthread.h and glvnd_pthread.c now declare and define a GLVNDPthreadFuncs
struct, instead of having a separate declaration in libGLX and libGLdispatch.

This mostly just simplifies initialization a bit, but it will also make it
easier to have common code that uses pthreads functions.

Reviewed-by: Andy Ritger <aritger@nvidia.com>
2016-02-25 12:54:05 -07:00
Kyle Brenneman ba0b05a569 GLDispatch: Initialize the dispatch table from __glDispatchCheckMultithreaded.
__glDispatchCheckMultithreaded will now check if the thread's current dispatch
table is NULL, and if it is, it will plug in the no-op table.

This is a workaround for some broken applications which try to call OpenGL
functions without a current context. As long as the thread calls a GLX function
first, any OpenGL calls it makes later will call a no-op stub instead of just
crashing.

Added calls to __glXThreadInitialize to some of the functions in
__GLXapiExports, so that GLX extension functions will still call
__glXThreadInitialize.
2016-01-21 15:19:57 -07:00
Kyle Brenneman c254ef4ada GLX: Use an assert to check for mismatched handle-to-vendor mappings.
In AddVendorPointerMapping and AddVendorXIDMapping, if there is an existing
mapping, then add an assert that the new vendor library matches the old one.

Handles have to map to at most one vendor, so if we get two different vendors
then there's a bug either in libGLX or in the vendor libraries.
2016-01-06 10:23:32 -07:00
Kyle Brenneman 6d8d0efb3f GLX: Fix a bunch of outdated names.
Renamed a bunch of structures and functions to reflect the fact that libGLX
maintains mappings of most objects directly to vendors now, not objects to
screens.
2016-01-04 15:17:30 -07:00
Kyle Brenneman 5c27a7817f GLX: Don't record the display pointer for contexts and configs.
Remove the Display pointer from __GLXscreenPointerMappingHash. It's no longer
needed for anything in libGLX.so. Dispatch functions can find a vendor library
given only the GLXContext handle itself, so functions like glXGetContextIDEXT
don't need the display either.
2016-01-04 15:10:04 -07:00
Kyle Brenneman bedb59a580 GLX: Use separate hashtables for contexts and configs.
libGLX now uses a separate hashtable for mapping GLXContext and GLXFBConfig
handles to vendor libraries.

Updated the ABI documentation to define requirements for GLXContext and
GLXFBConfig values, to ensure that there aren't ever any duplicate handles
between vendor libraries.
2016-01-04 14:55:36 -07:00
Kyle Brenneman 903ea20962 GLX: Remove the screen number from the pointer-to-vendor hashtable. 2016-01-04 13:40:15 -07:00
Kyle Brenneman 45aa814b11 GLX: Remove the screen from the GLXFBConfig map in the ABI.
Removed the screen number parameter from the GLXFBConfig mapping functions in
__GLXapiExports.
2016-01-04 13:20:46 -07:00
Kyle Brenneman 6116a24fec GLX: Remove the screen from the context map in the ABI.
Removed the screen number parameter from the context mapping functions in
__GLXapiExports.
2016-01-04 13:05:09 -07:00
Kyle Brenneman 973174c921 GLX: Add the vendor pointer to the context/config mapping. 2016-01-04 12:52:14 -07:00
Kyle Brenneman 161c6cb649 GLX: Remove the screen from the drawable map in the ABI.
Removed the screen parameter from the drawable mapping functions in
__GLXapiExports.
2016-01-04 12:37:08 -07:00
Kyle Brenneman 164c157ea2 GLX: Remove the screen from the XID mapping.
libGLX now only keeps track of the vendor library for each drawable, not the
screen number.

__glXVendorFromDrawable will now always return -1 for the screen. The screen
parameter will be removed in a later change.
2016-01-04 12:23:29 -07:00
Kyle Brenneman 83c9a70b7b GLX: Add a pointer to the vendor in the drawable mapping.
This is in preparation for removing the screen number entirely from the config,
context, and drawable mappings in the ABI.
2016-01-04 12:20:53 -07:00
Kyle Brenneman 362c3591aa GLX: Generate errors for invalid GLXFBConfigs.
When dispatching a function based on a GLXFBConfig, generate a GLXBadFBConfig
error if the config is invalid.
2015-12-18 13:28:24 -07:00
Kyle Brenneman 644caa3409 GLX: Generate errors for invalid contexts.
When dispatching a function based on a GLXContext, generate a GLXBadContext
error if the context is invalid.
2015-12-18 13:28:24 -07:00
Kyle Brenneman a627c5d166 GLX: Generate errors for invalid drawables.
When dispatching a function based on a GLXDrawable, generate an X error if the
drawable is invalid.

Added a helper function CommonDispatchDrawable to handle initialization,
looking up a vendor for a drawable, and reporting an error if it can't find
a vendor.

Removed __glXGetDrawableStaticDispatch, and replaced it with
CommonDispatchDrawable.

Removed the unused function __glXScreenFromDrawable.
2015-12-18 13:27:45 -07:00