Commit graph

42 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 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 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 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 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 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 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 07ee773318 libGLX: Change ABI to support glXGetContextIDEXT.
Changed __GLXapiExports::vendorFromContext so that it only takes a GLXContext
parameter as input, and returns the display, screen, and vendor for the
context.

This is needed to support a dispatch function for glXGetContextIDEXT, since it
only takes a GLXContext handle, not a display.

In libglxmapping.c, the __GLXscreenPointerMappingHash struct now keeps the
display pointer along with the screen number.

Also added an error check for GLXFBConfigs to make sure that the display passed
from the caller matches the recorded one.
2015-10-26 16:01:44 -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 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
Kyle Brenneman 9382a4b4ad libGLX: Generate entrypoints for GLX extensions.
libGLX will now generate entrypoints for GLX extension functions if it can't
find a dispatch function from a vendor library.

The generated entrypoints will simply jump to a dispatch function. With the
extra layer of indirection, glXGetProcAddress can return a valid function
pointer for GLX extensions before it loads any vendor libraries.

Issue #34.
2015-05-27 09:11:19 -06:00
Kyle Brenneman 7ac0298d21 libGLX: Move the screen to vendor map to an array.
Removed the __GLXvendorScreenHash hashtable. Instead, the __GLXdisplayInfo now
has an array of vendors for each screen.
2015-05-15 12:07:04 -06:00
Kyle Brenneman 11435a8cdb libGLX: Fixes for when x11glvnd isn't available.
If the server doesn't support x11glvnd, then use the fallback vendor name
instead of trying to ask the server for a name.

Fix __glXVendorFromDrawable to work without x11glvnd. Since every screen will
use the same vendor in that case, it just returns the vendor from screen zero.

Fix __glXGetDrawableStaticDispatch. It now uses __glXVendorFromDrawable to look
up the vendor for a drawable.
2015-04-29 17:27:08 -06:00
Kyle Brenneman d1ae76448c libGLX: Move the (xid -> screen) map to be per-display.
Fixes issue #31.
2015-04-29 17:20:23 -06:00
Kyle Brenneman 1227d0bf65 glx: Fix a typedef error on some compilers.
Some compilers raise an error about a duplicate typedef with the forward
declaration of __GLXvendorInfo in libglxabi.h and the definition in
libglxmapping.h.
2015-04-29 10:19:51 -06:00
Kyle Brenneman a78372936a libGLX: Add visual to vendor mappings.
Add functions to __GLXapiExports to manage mappings from an XVisualInfo to a
vendor.

This should allow the same sort of arbitrary vendor selection for the GLX 1.2
XVisualInfo-based functions as for the GLXFBConfig-based ones.
2015-04-20 14:29:07 -06:00
Kyle Brenneman c0d23f55d3 libGLX: Rework the ABI for object-to-vendor mappings.
Change the functions in __GLXapiExports to map from objects (drawables,
contexts, FBConfigs) to (screen, vendor) pairs.

Internally, libGLX still uses an (object -> screen -> vendor) mapping, but now
that's an implementation detail.
2015-04-19 10:40:37 -06:00
Kyle Brenneman de0ff825bb Change glXGetClientString strings to be per-display.
Add a hashtable for keeping track of per-display data and move the client
strings into that table.
2015-04-14 11:58:43 -06:00
Brian Nguyen d39e01a307 Implement fork-handling and library teardown paths
- Define a function __glXThreadInitialize() which gets called when
entering any GLX entrypoint, or when __glXGetDynDispatch() is called
by a vendor-provided GLX extension entrypoint.  This function detects
if a fork occurred since the last entrypoint was called, and performs
fork recovery if needed.

- Implement __glXFini() so that libGLX cleans up allocated resources
when it is unloaded.

These paths make heavy use of the LKDHASH_TEARDOWN() macro that was
implemented in a previous commit.

Signed-off-by: Brian Nguyen <brnguyen@nvidia.com>
2014-10-28 15:37:28 -07: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 92dfd9c5fe Defer removing screen -> context mappings for current contexts
If glXDestroyContext() is called on a context that is current to a
thread, the GLX 1.4 spec states that "ctx is not destroyed until
it is no longer current".  Hence, we must assume the context ->
screen mapping is still valid until the context is no longer current
as well.

Add a hashtable to track current contexts in GLX, and add helper
functions {Track,Untrack}CurrentContext() to add/remove contexts from
this hashtable in glXMakeCurrent() and glXMakeContextCurrent().

Instead of calling __glXRemoveScreenContextMapping() directly, call
__glXNotifyContextDestroyed() to look up the context in the current
context hashtable and determine whether the mapping can be removed
immediately or when the context loses current.

Add IsContextCurrentToAnyOtherThread() and fail
glXMake{,Context}Current() early if this returns True, prior to
adding the context to the current context list.

Signed-off-by: Brian Nguyen <brnguyen@nvidia.com>
2013-11-25 15:32:12 -08:00
Brian Nguyen b459d25cd5 [GLX] Define GLdispatch API
Add a new header file, GLdispatch.h, which defines an API for
window-system libraries such as libGLX to manage core GL dispatch tables
as well as TLS. Refactor the __GLXAPIState to be derived from
__GLdispatchAPIState, make __GLXvendorInfo::glDispatch type
__GLdispatchTable, and implement make current/get current functionality
using this API.

At some point this API will be implemented in a shared library used by
both libGLX and libEGL.
2013-08-26 11:03:42 -07:00
Brian Nguyen 31817fbb9b [GLX] Define internal APIs needed for looking up mappings, getting current state
- libglxabipriv.h: This is a simple wrapper around libglxabi.h which
  defines the static dispatch table to be the same as the set of
  functions exported by the vendor (they could potentially differ).

- libglxcurrent.h: This defines a current "API state" struct which
  encapsulates the API library's knowledge of the current display,
  read/draw drawables, dispatch tables, and vendor (owning the current
  context).  The glXGetCurrent*() functions are implemented by
  retrieving various fields from this API state.

- libglxmapping.h: This defines a "vendor info" struct which contains
  information about a loaded vendor. It also provides accessor functions
  for retrieving the dispatch table given a screen, and functions for
  adding/removing mappings from various keys (Context, FBConfig,
  Drawable) to screens.

- libglx.c: Replace the dummy GetStaticDispatch() function with calls to
  the API in libglxmapping.h to retrieve the right dispatch table.
2013-08-26 11:03:41 -07:00
Andy Ritger d85ec3427d Add initial libGLX implementation 2013-08-26 10:29:08 -07:00