Commit graph

108 commits

Author SHA1 Message Date
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
Aaron Plattner 627cc6634c GLX: Work around 'X_GLXCreateContextAtrribsARB' typo fix API break
Older versions of glxproto.h contained a typo where "Attribs" was misspelled.
The typo was fixed in the xorgproto version of glxproto.h, breaking the API.

Fixes #149.
2018-02-12 09:45:39 -08: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 d850cdde46 GL: Use a table to look up core GLX functions. (#127)
libGL.so now looks up the GLX core functions using a simple table, so that it
doesn't have the overhead of looking them up by name every time it's loaded.

Removed the (mutex != NULL) checks from __glXGLLoadGLXFunction, since it's no
longer called without a mutex.

Removed __glXWrapperInit, since it doesn't do anything anymore. Also removed the header file libgl.h, which only contained the declaration for __glXWrapperInit.
2017-06-20 12:53:54 -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 f7fbc4bb8b GLX: Keep track of the displays passed to glXMakeCurrent.
In glXMakeCurrent, make sure to add the new display to libGLX's tracking, so
that it gets a callback if the display is closed.

This fixes a dangling pointer to the display in the __GLXThreadState struct if
the application closes the display while it's still current.
2016-08-19 12:50:05 -06:00
Kyle Brenneman bb63d820df GLX: Fix a deadlock in teardown
In __glXAPITeardown, use pthread_mutex_trylock to take the context hash mutex,
and just skip freeing the context data if the mutex isn't available.

In some cases, such as a multi-threaded program that hits an X11 I/O error,
another thread could be blocked in a glXMakeCurrent call, and so trying to take
the context list mutex would deadlock.

In addition, fix the current context bookkeeping in fork recovery. After a
fork, the contexts should still exist, but none of them will be current
anymore.
2016-07-19 11:57:02 -06:00
Kyle Brenneman b6a1d5a5b5 GLX: Fix a race condition in the glXGetProcAddress cache.
In cacheProcAddress, check if the function is already in the hashtable before
trying to add it. It's possible that another thread might have already called
glXGetProcAddress for the same function.

In addition, allocate each cache entry with a single malloc instead of a malloc
and a strdup.
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
Thomas Hindoe Paaboel Andersen b0b4e351b3 GLX: fix a read after free
In MergeExtensionStrings currentString was read after it was realloc'ed
to make space for the extra extensions.

This patch makes the function read the realloc'ed memory instead. To
allow that to work 'buf' has to be null terminated on after every
extra extension is written.
2016-04-24 22:50:40 +02:00
Kyle Brenneman 5a69af6f77 GLX: Ignore passing NULL to glXDestroyContext
If glXDestroyContext is called with NULL for the GLXContext, then it will now
report an error using glvndAppErrorCheckReportError but it won't generate a
GLXBadContext error.

Some existing drivers (NVIDIA, Mesa, and possibly others) will just silently
return in that case, and some applications depend on that behavior.
2016-04-06 10:49:47 -06:00
Kyle Brenneman cc0892bb1c GLX: Add app_error_check.c to libGLX.
Added app_error_check.c to libGLX, and initialize it from __glxInit.
2016-04-05 12:58:17 -06:00
Kyle Brenneman b7d7542967 GLX: Don't call into the vendor library from __glXFini.
By the time __glXFini is called, the destructors in the vendor libraries may
have already been called, so it's not safe to call any functions in the vendor
library.

__glXFini will now check for a fork and go through fork recovery, but it won't
call __glDispatchCheckMultithreaded. If there was a current context, then
__glDispatchCheckMultithreaded might call the vendor's thread attach callback.
2016-04-01 09:18:33 -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 95a5bfcdfb Merge pull request #74 from kbrenneman/libglx-abi-version-1.
Updates to libGLX vendor library interface.
2016-03-28 17:40:51 -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 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 5c8e632906 GLdispatch: Rename the API state structures.
Rename __GLdispatchAPIState to __GLdispatchThreadState, to make it clearer that
the structure contains thread-specific data.

Updated some out-of-date comments.
2016-03-24 11:22:33 -06:00
Kyle Brenneman 4ecdb3dd8c Fix an uninitialized variable in glXGetFBConfigs. 2016-03-14 13:55:16 -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 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 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 642fd89560 GLX: Fix a duplicate typedef.
Fix a duplicate typedef of __GLXcontextInfo in libglx.c and libglxcurrent.h.
That causes an error with some compilers.

Reviewed-by: Andy Ritger <aritger@nvidia.com>
2016-02-29 13:41:46 -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
Adam Jackson c0d322ff08 GLX: Refuse to transition directly from EGL to GLX contexts
This is not expected to be common, and is undefined at the Khronos level
in any case. Refuse such attempts with BadAccess.
2016-01-20 14:52:52 -05:00
Kyle Brenneman e5225e3da3 Merge pull request #50 from aaronp24/kde-clientstring-workaround
GLX: Return dummy strings for glXGetClientString(NULL, ...)
2016-01-08 15:12:43 -07:00
Aaron Plattner da090a2e38 GLX: Return dummy strings for glXGetClientString(NULL, ...)
KDE calls glXGetClientString with a NULL dpy argument, which crashes in the call
to XScreenCount(dpy).  Work around it by explicitly checking for this and
returning some static strings.

Note that one oddity is that querying the GLX_VERSION with a NULL dpy will
return the maximum version supported by libglvnd, but specifying a display will
return the maximum supported by any vendor on the display (up to libglvnd's
supported maximum).

Signed-off-by: Aaron Plattner <aplattner@nvidia.com>
2016-01-08 13:33:46 -08: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 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 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 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
Kyle Brenneman 273e11940e GLX: Add a missing lock.
In DisplayClosed, take the mutex for the current context hashtable before
calling UpdateCurrentContext.
2015-12-16 10:47:32 -07:00
Kyle Brenneman e4cdd1431b GLX: Fix a couple deadlocks.
Change the current context hash to use a recursive mutex instead of an rwlock.

In __glXLookupDisplay, don't take the lock until after InitDisplayInfoEntry
returns, so that it doesn't try to make any X calls while holding the lock.

If an X error occurs while holding a non-recursive lock, then the error handler
may call exit, which would in turn call __glXFini. That can cause a deadlock if
__glXFini tries to take the same lock.
2015-12-09 15:56:36 -07:00
Kyle Brenneman 71c96a71a7 GLX: Fix an error check in glXMakeCurrent.
In CommonMakeCurrent, if the new context is NULL and the drawables are not
None, then it should always generate a BadMatch error. But, if the old context
was NULL, then it would return before checking for the BadMatch error.
2015-12-02 11:52:26 -07:00
Kyle Brenneman 2f06c1656b GLX: A couple of minor fixes.
In MergeVersionStrings, deal with a zero return value from glvnd_asprintf. Zero
is technically a successful return value from glvnd_asprintf, even though none
of the format strings could produce it.

Remove a bit of dead code from AtomicDecrementClampAtZero. The only way for the
if(newVal < 0) branch to be taken is if (oldVal <= 0), which it can't be at
that point.
2015-11-23 12:04:39 -07:00
Kyle Brenneman 9796473c98 libGL: Add entrypoint stubs for GLX extension functions.
Added a new script to generate the GLX entrypoints in libGL. The new script
uses Khronos's glx.xml file for a function list.

Checked in a copy of Khronos's glx.xml, from revision 32184.
2015-10-30 14:57:29 -06:00
Kyle Brenneman e4e60c407d libGLX: Add support for GLX_EXT_import_context.
Added dispatch functions to libGLX for glXImportContextEXT and
glXFreeContextEXT, since both of them are difficult to implement as a dispatch
function from a vendor library.

Since glXImportContextEXT doesn't take any parameters that directly specify a
screen, it will query the server manually to figure out a screen number.
2015-10-22 10:39:31 -06:00
Kyle Brenneman d568f63e9c libGLX: Add support for reporting X errors.
libGLX will now report any X errors that it generates directly, instead of
relying on a vendor library to report them.

For simply reporting errors, the notifyError callback in every vendor library
is functionally identical, so there's no reason to require every vendor to
implement it.

As a notification, it falls apart in glXMakeContextCurrent, which could have
two different vendor libraries if the drawables are on different screens. In
that case, libGLX has to arbitrarily pick one vendor to notify.

Add a __glXSendError function to libglx.c (based on the same function from
Mesa) to report X errors.

The __GLXapiImports::notifyError callback no longer has to report the X error.
It's mostly a notificaiton, although it returns a boolean value to tell libGLX
whether to report or ignore the error.

In glXMakeCurrent/glXMakeContextCurrent, it will report an error to whatever
vendor library owns the current context (if any), instead of the vendor
libraries for the two drawables. The rest of the function looks to the context
to select a vendor, and the old context is the only one that's valid in this
case.
2015-10-19 15:19:36 -06:00
Kyle Brenneman 745f5cf35f libGLX: Query the GLX extension when first initializing a display.
libGLX will now call XQueryExtension to check the GLX extension the first time
it sees a display.

Add the GLX opcode and error base to __GLXdisplayInfo.
2015-10-14 11:21:40 -06:00
Kyle Brenneman a511f3eccb libGLX: Don't leak __GLXAPIState structs.
libGLX only gets a callback at thread termination if it has a current context.
If there isn't a current context, then it will leave the thread's __GLXAPIState
in the hashtable until teardown.

Now, libGLX will only keep a __GLXAPIState when it has a current
context. When glXMakeCurrent is called to release the current context, it will
free the __GLXAPIState.

Removed the hashtable for keeping track of the __GLXAPIStates and replaced it
with a linked list.
2015-10-07 19:07:21 -06:00
Kyle Brenneman 38e9f8fb40 libGLX: Remove the GLX 1.4 functions from the ABI.
Removed the __GLX14EntryPoints structure from the vendor library ABI. Instead,
libGLX will use the getProcAddress callback to look up each function after
loading the library.

Moved the contents of __GLXvendorCallbacks into __GLXapiImports.

Changed __GLXdispatchTableStatic to be a separate struct from __GLXapiImports.
It now contains all of the GLX 1.4 function pointers, replacing __GLX14EntryPoints.
2015-09-25 14:29:14 -06:00