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
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.
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.
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
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.
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.
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.
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.
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.
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.
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.
Remove the __GLXdispatchTableDynamic struct. Move the hashtable that it
contained to be a member of __GLXvendorInfo instead.
Reviewed-by: Andy Ritger <aritger@nvidia.com>
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>
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.
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.
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.
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.
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.
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.
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.
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.
Some compilers raise an error about a duplicate typedef with the forward
declaration of __GLXvendorInfo in libglxabi.h and the definition in
libglxmapping.h.
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.
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.
- 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>
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.
- 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>
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>
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.
- 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.