Commit graph

29 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
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 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 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 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 ec97db7746 Install the public header files.
Two header files (libglxabi.h and GLdispatchABI.h) are public -- intended to be
used by vendor libraries, while the other headers are all internal to libglvnd.

Move the public header files to a new directory, include/glvnd.

Add a makefile so that the public headers are installed by make install.
2016-01-13 16:04:40 -07:00
Kyle Brenneman a924afad34 libGLdispatch: Add a void* parameter to the getProcAddress callback.
The getProcAddress callback that libGLdispatch uses to populate the dispatch
table now takes an extra parameter, which contains arbitrary data used by the
callback.

This allows much better flexibility in a how window system library populates a
dispatch table.
2015-10-01 15:24:18 -06:00
Kyle Brenneman b9aa37bdf4 libGLdispatch: Remove __glDispatchGetOffset and __glDispatchSetEntry.
Removed __glDispatchGetOffset and __glDispatchSetEntry from libGLdispatch.
Neither one is used anywhere, and the dispatch offsets should be an internal
detail of libGLdispatch.

Removed the mutex from stub_find_dynamic. Anything that calls that function
should already be holding the GLdispatch lock.

Also removed the __GLdispatchGetOffsetHook, since nothing uses it anymore.
2015-09-10 14:28:48 -06:00
Kyle Brenneman 413e3cad1c libGLdispatch: Move internal variables out of __GLdispatchAPIState.
Move the vendorID and dispatch members from __GLdispatchAPIState to
__GLdispatchAPIStatePrivate.

How those variables are tracked and used is an internal detail of
libGLdispatch, so they shouldn't be part of the public interface.
2015-07-23 15:05:46 -06:00
Kyle Brenneman b078777443 libGLdispatch: Add a pointer for internal data to __GLdispatchAPIState.
__GLdispatchAPIState now has a pointer to an opaque structure, to be used for
arbitrary private data.

This will allow later versions of libGLdispatch to add data for each API state
without changing the binary interface to libGLX.

The struct is mostly empty, but later changes will add more to it.
2015-07-23 15:04:15 -06:00
Kyle Brenneman 870bfda185 Merge pull request #38 from kbrenneman/patch-entrypoint-rework
Patch entrypoint rework.
2015-07-22 14:32:08 -06:00
Kyle Brenneman 6ef4cce6ce libGLdispatch: Disallow __glDispatchMakeCurrent with a current API state.
__glDispatchMakeCurrent now fails if the current thread already has an API
state.

This removes the complication of dealing with switching directly from one vendor
to another, and makes it easier for __glDispatchMakeCurrent to avoid any side
effects if it fails.
2015-07-16 08:35:33 -06:00
Kyle Brenneman 503f347486 libGLdispatch: Add an ABI version number.
Add a version number for the interface between libGLX and libGLdispatch, which
libGLX checks during initialization.

The interface between libGLX and libGLdispatch can and should be a stable ABI,
so that it's more resiliant to version mismatches if they come from different
packages or installers.

The version number is mainly a sanity check in case some future version of
libGLdispatch does change the interface.
2015-07-10 16:01:50 -06:00
Kyle Brenneman 7eedc37e4f libGLdispatch: Cleanup the internal patching interface.
Added a __GLdispatchStubPatchCallbacks struct to hold the callback functions
that libGLdispatch uses to patch entrypoints in each DSO.
2015-06-23 11:47:52 -06:00
Kyle Brenneman a0618089e1 libGLdispatch: Remove the pthreads table from __glDispatchInit.
Change __glDispatchInit to take no arguments, instead of having it optionlly
fill in a GLVNDPthreadFuncs structure.
2015-06-15 15:42:27 -06:00
Kyle Brenneman 161f3f050c Remove __GLdispatchAPIState::context.
Remvoved the context member of __GLdispatchAPIState, and instead added a new
currentContext member to __GLXAPIState.

libGLdispatch only needs the API state pointer, not the window system's context
handle.

This also removes the ill-defined case where a thread could have a current API
state but not a current context.
2015-06-12 18:25:22 -06:00
Kyle Brenneman d351b4c14a Remove __GLdispatchAPIState::id.
The "id" member of __GLdispatchAPIState isn't used anywhere in libGLdispatch,
so it doesn't need to be part of libGLdispatch's interface.

Instead, libGLX now stores the thread ID in __GLXAPIState::tid.
2015-06-12 14:38:39 -06:00
Kyle Brenneman 302595a5e5 Remove the TSD key from libGLX.
Added a pointer to a callback function __GLdispatchAPIState to notify the
window system library of thread termination.

Removed tsdContextKey from libglx.c. It now uses the API state stored in
libGLdispatch and the callback function in __GLdispatchAPIState instead.

libGLX will now free the __GLXAPIState struct for a thread when the thread
terminates, instead of waiting until __glXAPITeardown.

Fixes issue #35
2015-06-08 16:06:25 -06:00
Kyle Brenneman d39c400611 libGLdispatch: Add a TSD key for the current context.
Add a glvnd_key_t key to GLdispatch.c to hold the current API state.

__glDispatchGetCurrentAPIState and __glDispatchGetCurrentContext are now normal
exported functions instead of wrappers around _glapi_get_current.

Removed _glapi_get_current, _glapi_set_current, _glapi_get_context,
_glapi_set_context, and their associated functions in u_current.c.

Removed the U_CURRENT_* constants and replaced them with the corresponding
GLAPI_CURRENT_* constants.

Removed the GLAPI_CURRENT_* enums except for GLAPI_CURRENT_DISPATCH.
2015-06-05 16:08:18 -06:00
Kyle Brenneman dc090d8d2a GLdispatch: Fix the x86 TSD build to work with multiple threads.
Added a __glDispatchCheckMultithreaded function to tell libGLdispatch to check
for multiple threads.

libGLX will now check for a second thread in __glXThreadInitialize.

When ThreadSafe is true, u_current_get_index no longer returns a stale value
from u_current.
2015-04-01 16:55:39 -06:00
Brian Nguyen 81523012da Add __glDispatch{Fini,Reset}()
__glDispatchFini() is called by a GLdispatch client to clean up
GLdispatch-internal state when the client is done using GLdispatch
functionality.

__glDispatchReset() is called by a GLdispatch client to determine
whether fork recovery is needed, and handle the fork if necessary.

Signed-off-by: Brian Nguyen <brnguyen@nvidia.com>
2014-10-28 15:37:28 -07:00
Brian Nguyen 3fa81a5f70 [GLdispatch] Patch entrypoints on make current
Modify __glDispatchMakeCurrent() to take a pointer to the patch
callbacks for the vendor library whose context is about to be current.

Implement GLdispatch.c:PatchEntrypoints() and helpers.  This contains
the logic for determining whether it is safe to patch entrypoints, and
using the provided vendor callbacks to actually do the entrypoint
patching.  Call this from __glDispatchMakeCurrent() with the provided
patch callbacks.

Also implement GLdispatch.c:CurrentEntrypointsSafeToUse(), which
determines based on the current vendor ID whether the current top-level
code is safe to use with that vendor.  If this check fails, the make
current operation fails.

Allow users to disable entrypoint rewriting functionality by setting the
environment variable __GLVND_DISALLOW_PATCHING=1.

When losing current, also attempt to restore the default libglvnd
entrypoints so other vendors can potentially use them.
2014-01-23 20:16:33 -08:00
Brian Nguyen 8225879ab0 [GLdispatch] Implement API for registering top-level dispatch stubs
This allows vendor libraries to potentially overwrite the static
entrypoints of wrapper libraries (such as libGL and libOpenGL) at make
current time, in addition to the main GLdispatch entrypoints.
2014-01-23 20:16:33 -08:00
Brian Nguyen a033f25bf0 Register vendors with GLdispatch
This implements the notion of a "vendor ID" that is unique to each
vendor library instance loaded in a process.  When entrypoint rewriting
is implemented, this will be used by libglvnd to determine whether a
given entrypoint implementation is compatible with a given context, by
comparing the vendor owning the context with the vendor owning the
implementation.

This changes the function prototype of __glDispatchMakeCurrent()
to include the vendorID as an argument, which will be saved off in the
API state, and return a boolean value to indicate whether make current
succeeded.
2014-01-23 20:16:33 -08:00
Brian Nguyen 7a25ae5456 Simplify vendor-library ABI for libglx
- Pull GL dispatch callback typedefs into GLdispatchABI.h.  This is
  a common header which will be shared between the libGLX and libEGL
  ABIs.

- Add extern "C" blocks to libglxabi.h and GLdispatchABI.h so these
  headers may be used with vendor libraries that are built C++.

- Remove support for auxiliary dispatch table management
  (libglxgldispatch.[ch] and __GLdispatchExports).  This can be added
  back in later on if it proves useful.

- In libglxmappings.c, replace static initialization of glxExportsTable
  with one-time runtime initialization of the table.

- In libglxmappings.c, use __glDispatchCreateTable() directly to create
  the initial dispatch table.

- In libglxnoopdefs.h, remove unnecessary includes of libglxabipriv.h
  and libglxnoop.h.

- Add screen mapping functions to the GLX exports table.  Some extension
  functions not implemented by libglvnd, e.g. glXCreateContextAttribsARB()
  from GLX_ARB_create_context, may need to update the mappings from
  context or drawable to screen that are managed by libglvnd in order to
  work properly.  Additionally, dispatch functions implemented by vendor
  libraries for GLX extension functions may want to query these mappings
  in order to properly dispatch the call.

- Remove the getDispatchProto() vendor callback.  This is not needed by
  libglvnd since libglvnd does not support mapping more than one
  entrypoint to a single dispatch stub.  See GLdispatch.c for the
  rationale behind this decision.

- Remove redundant typedefs to prevent build errors.

- Delete the vendorData parameter from the getProcAddress() vendor
  callback, which isn't useful if there is no support for more than one
  libglvnd dispatch table per context.  Add the isClientAPI parameter,
  which can be used to distinguish between getProcAddress() requests for
  GLX functions versus getProcAddress() requests for client API
  functions.

- Remove the "screen" argument from Remove.*Mapping() functions.  This
  is unnecessary, as the hash key used to lookup the mapping object in
  libglvnd's hashtables doesn't depend on the screen (which is the hash
  value).  It's problematic since in some cases we don't actually know
  the value of the screen mapped to by a key.

Signed-off-by: Brian Nguyen <brnguyen@nvidia.com>
2013-11-26 18:38:07 -08:00
Brian Nguyen 4628149a0b Add context, dispatch parameters to __glDispatchMakeCurrent()
When making current, assign the API state's new context and dispatch table
in GLdispatch rather than GLX.  This avoids consistency issues if the API state
is unchanged but the current dispatch or context may have changed.

Update the __glDispatchMakeCurrent() call in
__glXMakeGLDispatchCurrent() to get libglvnd building for now; a later change
will remove libglxgldispatch.c altogether.

Signed-off-by: Brian Nguyen <brnguyen@nvidia.com>
2013-11-25 15:32:12 -08:00
Brian Nguyen efa8ca15c5 [mapi] Implement _glapi_{set,get}_current()
This replaces the _glapi_tls_{Dispatch,Context} symbols with a single
symbol, _glapi_tls_Current, which references an array of type (void*).
This allows us to easily extend mapi to accomodate additional TLS
entries, which will be necessary for storing current API state and
allowing vendors to utilize TLS entries for their own purposes.

This change is rather messy. It requires modification to both the
dispatch stub generation code and mapi's compatibility #defines in
u_current.h. This could probably be cleaned up in later changes. It's
not clear whether _glapi_{set,get}_{dispatch,context}() are even needed
anymore, but they are kept in place for backwards compatibility and to
keep this change as self-contained as possible.
2013-08-26 11:03:42 -07:00
Brian Nguyen 810c434324 [GLdispatch] Write pseudo-code implementations of API
This adds comments and (incomplete) code to describe the general
strategy which will be taken to implement the GLdispatch API. This
is still a WIP.
2013-08-26 11:03:42 -07:00
Brian Nguyen 8b3953b2f7 Add GLdispatch DSO
Move the GLdispatch header file to its own directory in src/GLdispatch,
and build a real DSO that GLX will depend on. In GLdispatch.c, add stub
functions which will later be fleshed out.
2013-08-26 11:03:42 -07:00
Renamed from src/GLX/GLdispatch.h (Browse further)