Commit graph

537 commits

Author SHA1 Message Date
Kyle Brenneman f42d89dd99 EGL: Rework the current rendering API.
libEGL will now forward calls to eglBindAPI to the vendor libraries.

Defined as part of the interface that libEGL only supports OpenGL and GLES.

This should simplify the task of porting a driver to EGL, since the eglBindAPI
behavior is closer to a non-glvnd driver.
2016-08-01 13:06:10 -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 7dabba8940 util: Add trylock functions to glnvd_pthread.
Add pointers for pthread_mutex_trylock, pthread_rwlock_tryrdlock, and
pthread_rwlock_trywrlock to the GLVNDPthreadFuncs table.
2016-07-13 09:57:16 -06:00
Kyle Brenneman 013285314c GLdispatch: Remove an incorrect assert.
In __glDispatchFini, remove the assert that the current context list is empty.
Even though libGLX/libEGL will clear out the current context for the current
thread, another thread may still have a current context.
2016-07-13 09:30:57 -06:00
Kyle Brenneman 31c5e7f602 EGL: Implement EGL_KHR_debug.
Implemented the EGL_KHR_debug extension in libEGL.

Updated the error reporting throughout libEGL to call the debug callback.

This requires that all vendor libraries also support EGL_KHR_debug. The reason
is that the debug callback has to be called every time an EGL error is
generated, and vendor libraries are still responsible for keeping track of EGL
errors on their own.

libEGL should be able to cope with a vendor library that doens't support
EGL_KHR_debug, but if that vendor library is used, then the extension won't
work correctly.
2016-06-22 16:15:32 -06:00
Kyle Brenneman b72018f59a EGL: Initial implementation of libEGL.
The implementation is mostly based off of libGLX.

Unlike GLX, libEGL will load all vendor libraries up front. This is necessary
for dealing with eglGetPlatformDisplay, as well as many client extensions.

Dispatching EGL functions is generally simpler than GLX. All display extension
functions by definition can be dispatched based on an EGLDisplay handle, so
it doesn't need to provide lookup functions for contexts or surfaces, and
vendor libraries don't have to add any EGL objects to tracking.

Only OpenGL and OpenGL ES and a handful of client extensions are supported so
far.
2016-06-22 16:14:16 -06:00
Kyle Brenneman 382eb05efa Checked in a copy of the cJSON library.
This will be used to parse JSON config files that will describe the available
vendor libraries for EGL.
2016-06-22 16:13:35 -06:00
Kyle Brenneman 82c37ca46b util: Add functions for splitting a string into tokens. 2016-06-22 16:13:20 -06:00
Kyle Brenneman fc61f5488f util: Add a local implementation of vsprintf(3). 2016-06-14 15:39:11 -06:00
Kyle Brenneman 1b30d15333 GLdispatch: Don't unpatch entrypoints in __glDispatchLoseCurrent.
In __glDispatchLoseCurrent, don't try to restore the default entrypoints.
Instead, __glDispatchMakeCurrent will check if it's using a different vendor
library, and if so, it will unpatch and repatch the entrypoints then. If it's
using the same vendor library (which will usually be the case), then it can
leave them patched and skip the patch overhead.

Some applications will call glXMakeCurrent to release and bind the same context
every frame, sometimes multiples times. Each patch and unpatch sequnce can chew
up 1-2 milliseconds. That's enough to significantly reduce the framerate of
some applications.

Reviewed-by: James Jones <jajones@nvidia.com>
2016-05-31 14:49:16 -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 edd36498c5 Add functions to keep track of a vendor library's GLX functions.
Added functions to create and manage a per-vendor dispatch table for
window-system functions.

These will replace the __GLXdispatchFuncHash hashtable in GLX.
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 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 4d20b1826b Add helper functions for keeping track of the window-system dispatch stubs.
Added a new file, winsys_dispatch.c, with functions for keeping track of the
indices, names, and dispatch stubs for window-system functions.

This will replace the __GLXdispatchIndexHash hashtable in GLX.

It's independant of the window system, so it should be usable for EGL as well.
2016-05-17 10:32:34 -06:00
Kyle Brenneman 509de0dbc8 Remove the reference to glx.h from libopengl.c.
libOpenGL doesn't contain anything GLX-specific, so it doesn't need anything
defined in glx.h.
2016-05-11 13:37:58 -06:00
Kyle Brenneman d41548599e Merge pull request #84 from kbrenneman/fix-automake-warnings
Fix the warnings that autogen.sh spits out.

Added libtool convenience libraries for the source files in src/util instead of
including them directly in other makefiles. This avoids a bunch of
subdir-objects warnings.

Added libtool convenience libraries for each of the glapi builds.

Flattened the vnd-glapi directory. In theory, just setting the subdir-objects
flag should be enough, but that causes failures where "make distcheck" doesn't
build all of the source files.
2016-05-11 11:16:57 -06:00
Kyle Brenneman 2f27586a4e Remove unused file src/OpenGL/entrypoint_common.mk. 2016-05-04 12:11:30 -06:00
Kyle Brenneman a635c722a5 GLX: Remove __glXDispatchNoopPtr.
Removed the header file and the script to generate the __glXDispatchNoopPtr
table.

Also removed the dependency on Perl from configure.ac, since the rest of the
scripts are in Python.

Reviewed-by: aplattner@nvidia.com
2016-05-04 11:43:24 -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
Thomas Hindoe Paaboel Andersen ca02a90f22 GLdispatch: trivial indentation fix 2016-04-23 20:45:57 +02:00
Kyle Brenneman fa2add82a0 Move vnd-glapi/mapi/* to vnd-glapi.
Moved everything under src/GLdispatch/vnd-glapi/mapi/ to
src/GLdispatch/vnd-glapi.

Removed the subdir-objects flag.

Using subdir-objects causes errors when you do a make followed by a
"make distcheck", because for some reason the distcheck doesn't build all of
the source files.
2016-04-19 12:48:47 -06:00
Kyle Brenneman 65440c051e GLESv1: Statically export glPointSizePointerOES.
Add GL_OES_point_size_array to the set of features and extensions that are
exported from libGLESv1_CM.so.

According to the OpenGL ES 1.1 spec, all required extensions are supposed to be
statically exported from the library. GL_OES_point_size_array is the only
required extension that defines any functions.
2016-04-07 13:08:34 -06:00
Kyle Brenneman 87ce484d49 Move trace.[ch] into the src/utils directory.
Move trace.c and trace.h into the src/utils directory instead of a
subdirectory.
2016-04-06 11:00:32 -06:00
Kyle Brenneman 56cb81e164 Fix the remaining subdir-objects warnings.
Added the subdir-objects option to the vnd-glapi makefile. Changed all of the
_SOURCES variables in that makefile to use relative paths.
2016-04-06 10:57:23 -06:00
Kyle Brenneman 8ade0512f7 Remove the MAPI_PREFIX variable from configure.ac.
Moved the MAPI_PREFIX variable from configure.ac to the vnd-glapi makefile.

Removed the MAPI_MESA_PREFIX variable entirely.
2016-04-06 10:57:23 -06:00
Kyle Brenneman 79e5a1cef8 Move the vnd-glapi builds into the vnd-glapi Makefile.
Move the various vnd-glapi builds into individual .la files in the vnd-glapi
makefile, instead of defining them in the OpenGL, GL, GLESv1, and GLESv2
makefiles.
2016-04-06 10:57:23 -06:00
Kyle Brenneman d79a1484ac Fix some autoconf warnings.
Fixed a few order and variable name warnings.

Defined convenience libraries for the source files under src/util, to avoid the
subdir-objects warning from them.
2016-04-06 10:57:23 -06: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
Eric Engestrom 3c87d939aa Fix spelling mistakes 2016-04-03 16:14:15 +01: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 3402e11588 Merge pull request #80 from kbrenneman/app-error-check-setting
Add support for reporting application errors.
2016-03-30 12:49:35 -06:00
Kyle Brenneman c4d3d7ee15 Merge pull request #77 from nwnk/public_entry_visibility
GLdispatch: Emit public_entry_{start,end} as hidden symbols
2016-03-30 12:47:25 -06:00
Kyle Brenneman e2d44985d8 Add support for reporting application errors.
The libglvnd libraries will now check for a new environment variable,
__GLVND_APP_ERROR_CHECKING. If it's set to a non-zero value, then libglvnd will
check for and report some application errors.

Many non-libglvnd implementations of libGL.so have been fairly tolerant of
certain application bugs. Libglvnd has to be similarly tolerant to support
existing apps that the developers can't or won't fix.

The new __GLVND_APP_ERROR_CHECKING provides a way to check for some of those
errors, so that hopefully there will be fewer broken apps in the future.

In addition to the setting itself, this updates the no-op stubs in
libGLdispatch to report an error when the app tries to call an OpenGL function
without a current context. Later changes will likely add other error checks.
2016-03-29 10:18:02 -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 1d7ab91b76 Remove the x11glvnd extension.
Delete the x11glvnd directory.

Commented out the two tests that depend on it, testx11glvndproto and
testglxnscreens. Eventually, they should be rewritten to use the
GLX_EXT_libglvnd extension instead.
2016-03-24 12:46:41 -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 4c7a1b18e6 GLX: Add functions for the GLX_EXT_libglvnd extension.
Add some functions to handle requests for looking up vendor names and screen
numbers using the GLX_EXT_libglvnd extension.
2016-03-24 12:44:25 -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 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 af2aeb0b42 Merge pull request #71 from evelikov/use-glproto
build: use system glproto headers
2016-03-21 14:47:05 -06:00
Kyle Brenneman ca26fee143 Merge pull request #72 from evelikov/remove-elf-filtering 2016-03-21 14:44:47 -06:00
Kyle Brenneman 4ecdb3dd8c Fix an uninitialized variable in glXGetFBConfigs. 2016-03-14 13:55:16 -06:00
Kyle Brenneman f1c345f3a3 Merge pull request #70 from evelikov/build-cleanups-round2
Build cleanups.
2016-03-14 11:27:55 -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
Adam Jackson 1c72d7a730 GLdispatch: Emit public_entry_{start,end} as hidden symbols 2016-03-09 15:04:04 -05: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
Emil Velikov f3d64458cb Remove auxiliary ELF symbol filtering
The code was disabled due to a glibc bug 16272. which as of this point
remains open.

As n alternative solution is already in place and fix for the mentioned
issue is unlikely to land in order distributions, it does not make it a
viable solution that we can use (in the near future).

Drop the code for now, to prevent anyone building a completely broken
library.

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
2016-03-02 11:31:51 +00:00
Emil Velikov b07853c4fe Add missing files to .gitignore thoughout the project
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
2016-03-02 11:22:12 +00:00
Emil Velikov db3a046fd4 configure.ac: make use of MKDIR_P macro
... as opposed to hardcoding it. While we're here tweak the whole
command to use the standard - AM_V_at and @D, as opposed to @ and dir $@

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
2016-03-02 11:18:28 +00:00
Kyle Brenneman f95e3ae00d GLdispatch: Change the stub type enums.
Removed the distinction between TSD and TLS stubs, since that doesn't matter to
a vendor library. There's now a single type for the x86 stubs and a single type
for the x86-64 stubs.

Added a separate type enum for normal ARM and thumb stubs. As with x86, there's
no distinction between TLS and TSD.

Changed the __GLDISPATCH_STUB_PURE_C enum to a more generic
__GLDISPATCH_STUB_UNKNOWN.

Also removed the internal ENTRY_* enums and changed everything to use the
__GLDISPATCH_STUB_* enums instead.
2016-02-29 13:50:40 -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 233b274be1 Add a threadAttach callback for entrypoint patching.
The threadAttach callback is used so that a vendor library can go through any
thread initialization it needs to in order to deal with any later OpenGL calls.

This allows a vendor library to work around broken applications that try to
call OpenGL functions without a current context.
2016-02-29 13:50:34 -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 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
Emil Velikov 35ef968cab build: use system glproto headers
As pointed out with commit d5bc0866a8 "Check for glproto in
configure.ac" we want to rely on the upstream/distribution provided
package. Thus lets remove the in-tree copy.

Also make sure we use the headers (add the missing CFLAGS).

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
2016-02-29 14:46:32 +00: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 dc267e2da5 Fix the 32-bit build.
Added some missing includes to u_current_tsd.c.

Fixes #69.
2016-02-26 09:17:55 -07:00
Kyle Brenneman dcc1c9ca33 Remove the makefile for glvnd_pthread.
Moved glvnd_pthread.h and glvnd_pthread.c into src/utils, and removed the
separate makefile for them. The other makefiles now just grab the source file
directly instead.

Reviewed-by: Andy Ritger <aritger@nvidia.com>
2016-02-25 12:54:29 -07:00
Kyle Brenneman 26b22048c7 GLdispatch: Remove u_thread.h.
Removed u_thread.h. The few places that used it before now use glvnd_pthread.h
instead.

Reviewed-by: Andy Ritger <aritger@nvidia.com>
2016-02-25 12:54:26 -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
Aaron Plattner 4d977ea389 x11glvndserver: Use MODULEVERSIONSTRING instead of hard-coding "NVIDIA Corporation"
The X headers define MODULEVENDORSTRING like so:

  #ifndef MODULEVENDORSTRING
  #define MODULEVENDORSTRING      "X.Org Foundation"
  #endif

This allows module vendors such as NVIDIA to override the vendor string at build
time, rather than hard-coding "NVIDIA Corporation" in the sources.

Signed-off-by: Aaron Plattner <aplattner@nvidia.com>
Reviewed-by: Kyle Brenneman <kbrenneman@nvidia.com>
Fixes #48.
2016-02-16 13:09:08 -08:00
Nicolas Chauvet dd92b51948 Use -avoid-version for x11glvnd in x11glvnd_la_LDFLAGS
This patch also removes the -shared LDFLAGS
redundant with the libtool -module option
(in-sync with others x11 module/drivers)
2016-02-14 20:54:52 +01:00
Luca Boccassi efad8926d8 Remove autogenerated sources and .pyc on clean 2016-02-09 16:48:03 +00:00
Robert Morell 22aae7170f libGLdispatch: Fix PIC on x86_64 TSD.
This makes the built-in x86_64 TSD stubs use RIP-relative addressing so
that the linker doesn't have to generate relocations of text sections,
which breaks PIC.

Fixes #53
2016-01-25 12:40:45 -08: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 59be159c9b Remove a bunch of unused files.
Removed several header files that were copied from Mesa but aren't used in
libglvnd.

Removed everything under src/arch, also copied from Mesa but unused.
2016-01-14 09:42:05 -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 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 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
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 4038efca1f Implement GLESv1.
Added a Makefile to build libGLESv1_CM.so. It's copied and adapted from the one
for libOpenGL.so.

The GLESv1 library currently exports all of the core functions in gl.xml for
GLES version 1.0.
2015-11-20 14:44:25 -07:00
Kyle Brenneman c0d9bbf184 Factor out the common makefile code in libGLESv2 and libOpenGL.
Moved the duplicated makefile code for libOpenGL and libGLES to a new
file, entrypoint_common.mk.
2015-11-13 16:23:01 -07:00
Kyle Brenneman 2e8f77c11b Implement GLESv2.
Added a Makefile to build libGLESv2.so. It's copied and adapted from the one
for libOpenGL.so.

The GLESv2 library currently exports all of the core functions in gl.xml for
GLES versions 2.0 through 3.2, inclusive.
2015-11-13 16:22:42 -07:00
Kyle Brenneman 41c8dc023b Generalize the export list generation scripts.
In genCommon.py, change getLibOpenGLNamesFromRoots so that it accepts a target
parameter. Defined separate targets for each library, including libGLdispatch.

gen_libOpenGL_exports.py now takes a target parameter just like
gen_gldispatch_mapi.py does.

This is in preparation for adding function lists for the libGLES libraries.
2015-11-13 16:22:02 -07:00
Kyle Brenneman 31947394c7 libGLdispatch: Enable entrypoint patching for the x86 TSD build.
Rewrote the x86 TSD stubs to follow the same pattern and use the same common
functions as the x86-64 stubs.

Aside from being shorter and simpler with less code duplicaiton, this will
allow entrypoint patching to work in the x86 build.

Fixed some errors in the entrypoint patching in the unit tests. The
libGLX_dummy.so library was patching in PC-relative addresses for the MOV
instructions, but those instructions expect absolute addresses.
2015-11-13 11:40:22 -07:00
Kyle Brenneman 97f8039fcd Merge pull request #47 from kwizart/make-dist
Add few missing files and directory for make dist
2015-11-11 12:21:55 -07:00
Kyle Brenneman 63d95dda78 Remove the execute flags from gl.xml and glx.xml.
The XML files are obviously not executable, but the flag was set from when I
copied them from the Khronos SVN repository.
2015-11-11 11:17:56 -07:00
Kyle Brenneman 08f3208a08 libGLdispatch: Update the documentation for entry_get_public.
Add a documentation comment to entry_get_public, and change the name of the
parameter to indicate that it takes an array index instead of a dispatch table
slot.
2015-11-11 10:58:12 -07:00
Kyle Brenneman 0626538361 libOpenGL.so: Only generate the entrypoints that we're going to export.
gen_gldispatch_mapi.py now takes an extra parameter to specify which library
it's building, so that it can generate the correct function list for that
library. For libOpenGL.so, it will only generate the functions that it's going
to export.

Updated the makefiles for libOpenGL.so, libGL.so, and libGLdispatch.so to
generate the correct set of entrypoints for each library.

Moved the code to figure out the libOpenGL.so function names to genCommon.py.
2015-11-11 10:58:04 -07:00
Nicolas Chauvet 48255183c5 Add few missing files and directory for make dist 2015-11-10 22:37:02 +01:00
Kyle Brenneman 81bbbaeae9 libGLdispatch.so: Fixes for the public stub array.
Fix a couple of places that assume that the public stub array (as defined in
entry*.c) is in the same order as the dispatch table.

stub_get_addr will now calculate the index of the stub instead of assuming that
the slot and index are the same.

In stubRestoreFuncsInternal, it will run through the length of the public_stubs
array instead of assuming that the array is of length MAPI_TABLE_NUM_STATIC.

This will allow us to remove all the entrypoints in libOpenGL.so that we're
not going to export.
2015-11-09 09:48:02 -07:00
Kyle Brenneman 746a71dc1a libGLX: Fix a segfault when libGLX can't find a vendor for a screen.
In __glXLookupVendorByScreen, check to make sure the vendor returned by
__glXLookupVendorByName is not NULL before trying to dereference it.
2015-11-04 16:52:08 -07:00
Kyle Brenneman e356f84554 libGLdispatch: Remove the old code generation scripts.
The old scripts have been replaced with the scripts under src/generate,
so the old ones aren't used or needed anymore.
2015-10-30 16:31:38 -06:00
Kyle Brenneman fd5c500b4c libGLdispatch: Don't export the OpenGL entrypoints.
Added an export list for libGLdispatch.so, so that it doesn't export the OpenGL
entrypoints.

The OpenGL entrypoints should only be exposed through libGL.so or libOpenGL.so,
not through libGLdispatch.so.
2015-10-30 14:58:37 -06:00
Kyle Brenneman e6c4fb579a libGL/libGLdispatch: Added missing entrypoints.
Added two additional XML files which contain additional GL and GLX functions
that are exported from existing libGL.so implementations but are missing from
the Khronos XML files.

Adjusted the scripts so that they can take a list of XML files instead of just
one.
2015-10-30 14:58:12 -06: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 da1b8075b0 libOpenGL: Add a script to generate an export list for libOpenGL.
Added the gen_libOpenGL_exports.py script, which will generate an export list
for building libOpenGL.so.

With this, libOpenGL.so will only export OpenGL core functions up through
OpenGL 4.5.
2015-10-30 14:54:31 -06:00
Kyle Brenneman f1c8b6049d libGLdispatch: Add new code generation scripts.
Add new scripts to replace the GLAPI code generation scripts, using the
Khronos gl.xml file.

All of the scripts are rewritten from scratch, but intended to produce similar
output files to the original scripts:

gen_gldispatch_mapi.py replaces mapi_abi.py, originally from Mesa's mapi_abi.py.

gl_inittable.py and gl_table.py replace the scripts of the same name in
GLdispatch/vnd-glapi/mapi/glapi/gen. Both are originally derived from
Mesa's gl_gentable.py and gl_table.py.

Checked in a copy of Khronos's gl.xml, from revision 32184.

Added a typedef for GLDEBUGPROCKHR to the scripts that need it, so that the
GLES versions of GL_khr_debug will compile.

libGL.so and libOpenGL.so now export the full set of OpenGL functions,
including any extensions.
2015-10-30 14:54:09 -06: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 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 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 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 3d43071413 GLdispatch: Rename _glapi_get_dispatch and _glapi_set_dispatch.
Rename the functions _glapi_get_dispatch and _glapi_set_dispatch to
_glapi_get_current and _glapi_set_current.

Aside from better consistency with _glapi_Current and _glapi_tls_Current, this
should make it easier to avoid name clashes with Mesa's GLAPI functions.
2015-09-23 12:32:38 -06:00
Kyle Brenneman 14241c6706 libGLdispatch: Remove entry_patch.
Remove the entry_patch functions from GLAPI, since they're no longer used.
2015-09-10 14:45:03 -06:00
Kyle Brenneman a55324d57d libGLdispatch: Assign offsets to dynamic stubs up front.
_glapi_get_proc_address (and stub_add_dynamic) will now assign an offset to a
new dynamic stub when it's first generated, instead of waiting until
_glapi_add_dispatch.

Deferring it until _glapi_add_dispatch is only useful for handling aliases
(where multiple functions are assigned to the same dispatch table slot), but
libGLdispatch does not use aliases.

Removed the newProcList list in GLdispatch.c. It'll now add all functions
directly to extProcList.

Removed _glapi_add_dispatch and stub_fix_dynamic.
2015-09-10 14:29:08 -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 543cf987d4 libGLdispatch: Free the memory used for generating stub functions. 2015-08-11 16:49:05 -06:00
Kyle Brenneman 2e65db590a libGLdispatch: Free the TSD keys from __glDispatchFini.
When the last client calls __glDispatchFini, it will now free all of the TSD
keys that it created in __glDispatchInit.
2015-08-11 16:48:57 -06:00
Kyle Brenneman 7dce9384fa libGLdispatch: Fix multiple calls to __glDispatchInit/Fini.
In libGLdispatch, initialize the pthreads table in a constructor function so
that we can use the dispatch mutex in __glDispatchInit.

In __glDispatchFini, check whether clientRefcount has dropped to zero before
tearing everything down.

libGL and libOpenGL will now call __glDispatchFini when they're unloaded, since
they also call __glDispatchInit.
2015-08-11 16:48:45 -06:00
Kyle Brenneman 15083485d4 libGLdispatch: Factor out most of the x86-64 and ARMv7 stub code.
Moved most of the code for the x86-64 TSD, x86-64 TLS, and ARMv7 TSD stubs into
a separate file.
2015-08-11 16:41:57 -06:00
Kyle Brenneman 15b375e6be libGLdispatch: Put the different entrypoint types into different C files.
Changed all of the entry_*.h files to be source files instead. The configure
script now figures out which files to use.
2015-08-11 16:41:57 -06:00
Kyle Brenneman 603bc5eb60 Split u_current.c into separate TLS and TSD files. 2015-08-11 16:41:56 -06:00
Kyle Brenneman 0f6db7930c libGLdispatch: Clean up the entry code.
Removed some unused files and functions.

Removed _GLAPI_EXPORT on a bunch of functions that don't need to be exported.

Removed some unnecessary macros:

Removed the macro u_current, and replaced all references to it with
_glapi_Current or _glapi_tls_Current.

Removed the mapi_table macro, and replaced it with _glapi_table.

Removed the ENTRY_CURRENT_TABLE and ENTRY_CURRENT_TABLE_GET macros.

Cleaned up the code related to storing the current dispatch table:

Rearranged things so that _glapi_* variables and functions are the public
interface to everything else, and the u_current_* functions are the internal
implementation.

Changed _glapi_Current to use the same definition on all builds.

Removed the existing u_current_get and replaced it with u_current_get_internal,
to match u_current_set.

Made _glapi_get_dispatch into a separate (exported) function, rather than a
macro for u_current_get_internal.

Consolidated most of the code for keeping track of the current dispatch table
into u_current.c. Rearranged the file to use a single #if/#else block to
separate the TLS and TSD versions.

Removed all of the non-pthread code. There's no reason to keep it around, since
the rest of libglvnd won't build without pthreads.

Removed most of the contents of u_thread.h, and replaced it with direct calls
to the pthreads functions.
2015-08-11 16:41:56 -06:00
Kyle Brenneman 02397eb927 Merge pull request #42 from kbrenneman/glx-vendor-support-screen
libGLX: Add a function to check if a vendor library supports a screen.
2015-08-10 14:44:30 -06:00
Kyle Brenneman ecfeb53368 libGLdispatch: Use separate write and execute mappings.
Change libGLdispatch so that it will use separate writable and executable
mappings when it generates dispatch stubs.

Added a function, u_execmem_get_writable that will hand back a writable pointer
for an executable pointer. That avoids having to rework everything else in
libGLdispatch to keep track of both pointers.

The static x86-64 dispatch stubs are now marked as read+execute instead of
read+write+execute. Before patching them, it will call mprotect to make them
writable.

Change __GLdispatchStubPatchCallbacks::restoreFuncs so that it returns a flag
to indicate success or failure.

Issue #37
2015-07-31 16:15:08 -06:00
Kyle Brenneman 6540671659 libOpenGL: Fix the linker flags for libOpenGL.
Fixed a couple lines in the libOpenGL makefile where it was using the wrong
variable name.

Added an explicit -version-info flag for libGLdispatch and libGLX.

Added the --no-undefined linker flag for libOpenGL, libGL, libGLdispatch, and
libGLX on systems where it's available.
2015-07-31 11:29:33 -06:00
Damien Leone 66f478867c libglvnd: Add support for ARMv7
This commit adds static and dynamic TSD stubs generation support for ARMv7.

Testing coverage includes all ARM / Thumb mode combinations between
libglvnd and a vendor implementation.
2015-07-29 13:16:14 -07:00
Kyle Brenneman 1b0246239c libGLX: Add a function to check if a vendor library supports a given screen.
Add a new callback, __GLXvendorCallbacks::checkSupportsScreen to the vendor
library ABI. The callback is used to check if a vendor library can support a
given X screen.

If the vendor library reports that it doesn't support a screen, then libGLX
will use the indirect rendering library instead.

Issue #39.
2015-07-29 11:07:16 -06:00
Kyle Brenneman 59aef8dacc libGLdispatch: Copy the function name for dynamic stubs.
In stub_add_dynamic, make a copy of the function name to store in the mapi_stub
struct. The name from the caller is the same pointer that the app passed to
glXGetProcAddress, so the app could modify or free it afterward.
2015-07-24 14:07:58 -06:00
Kyle Brenneman 0e46dfc6d2 libGLdispatch: Fix a typo in GLdispatch.c. 2015-07-24 12:49:33 -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 6697d9f8db libGLX: Disallow '/' characters in vendor names. 2015-07-17 12:57:45 -06:00
Kyle Brenneman cce5479b75 utils: Try using O_TMPFILE to create a temp file in AllocExecPages.
In AllocExecPages and OpenTempFile, it will first try creating a temp file by
calling open(2) with the O_TMPFILE flag. If that doesn't work, then it'll fall
back to using mkstemp.
2015-07-16 15:42:13 -06:00
Kyle Brenneman 6a3791f808 utils: Don't use any environment variables in a setuid process.
In a setuid process, GetTempDirs will only return /tmp, ignoring the TMPDIR and
HOME environment variables.
2015-07-16 13:53:54 -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 fb33201b65 libGLX: Simplify UpdateCurrentContext.
UpdateCurrentContext will now re-use the existing hashtable entry if it's
switching between two contexts, so there's no longer a possibility of malloc
failing. The only case where it can fail now is if there is a new context but
not an old context.

UpdateCurrentContext will handle removing the old context from the context to
screen mapping as appropriate.

In CommonMakeCurrent, when releasing a context or switching between two
contexts with the same vendor, it will now call UpdateCurrentContext once at
the end, since UpdateCurrentContext can't fail in those cases.
2015-07-16 08:35:33 -06:00
Kyle Brenneman 983bb3497a libGLX: Clean up MakeCurrent handling.
Change the code for glXMakeCurrent/glXMakeCurrentContext to better handle
different changes.

If it switches between two contexts that use the same vendor, it will not call
into libGLdispatch, since it would just be switching to all the same
parameters.

If it switches between two contexts that use different vendors, then it will
fully release the current context before making the new context current.

This makes it easier to ensure that libGLX and the vendor libraries stay in a
consistent state, even when recovering from a failure in the vendor library or
in libGLdispatch.

This also means that __glDispatchMakeCurrent is only called when the current
thread has no current API context, so libGLdispatch doesn't need to deal with
switching between two different API states.
2015-07-16 08:35:32 -06:00
Kyle Brenneman 46753980cc Changed AllocExecPages to create separate writable and executable mappings.
AllocExecPages will now try to create a temp file and map it twice, once
writable and once executable. This will allow it to work on systems that don't
allow the same page to be writable and executable.

Issue #37
2015-07-15 18:05:54 -06:00
Kyle Brenneman 4b5be8b8b6 Change glvnd_genentry.c to use separate write and execute mappings.
glvnd_genentry.c now uses AllocExecPages and FreeExecPages to allocate
executable memory for generating stubs.
2015-07-15 13:58:39 -06:00
Kyle Brenneman e930f443b7 Add a new functions for allocating executable memory.
Added two new functions, AllocExecPages and FreeExecPages, for allocating
executable memory for generating stub functions.

It uses a single mmap right now, but it's set up to return two pointers, so it
will be able to return separate writable and executable mappings. That will let
it work on systems that don't allow pages to be both writable and executable.

The new functions are in utils_misc.c, since it will be needed in both libGLX
and libGLXdispatch.
2015-07-15 13:58:18 -06:00
Damien Leone 5d7a898cb2 libglvnd: Allow for generating dynamic stubs for any entry point
This removes the assumption that OpenGL entry points are necessarily prefixed
by 'gl'.
2015-07-14 10:40:32 -07:00
Damien Leone 0720c44429 libglvnd_pthread: Properly initialize the key 2015-07-14 10:40:28 -07:00
Kyle Brenneman 308f5506f5 libGLX: Remove the isClientAPI flag.
Remove the isClientAPI parameter from __GLXvendorCallbacksRec::getProcAddress.

The only thing that libGLX can use to determine the the isClientAPI flag is the
function name, which a vendor library could implement just as easily. In
addition, since it would be possible for a GL entrypoint to start with "glX",
the isClientAPI flag isn't always reliable.
2015-07-13 14:45:53 -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 f7a918130d Moved glvnd_asprintf to src/util/utils_misc.c.
Moved the function glvnd_asprintf to a new file, src/util/utils_misc.c, so that
it can be used from other components besides libGLX.
2015-07-10 15:41:48 -06:00
Kyle Brenneman 9b64a5ab75 Add an --enable-debug configure option.
Use the AX_CHECK_ENABLE_DEBUG macro to add an --enable-debug option to the
configure script.

Silence an unused variable warning in libglx.c. A variable in CommonMakeCurrent
is only used in asserts, so setting NDEBUG means it's set but never used.

Remove the dbg_configure.sh script.
2015-07-08 15:03:30 -06:00
Kyle Brenneman 656fe83f00 libGLX: Change the fallback vendor name to "indirect".
The only place where the fallback vendor library should ever be used is with
indirect rendering, so "indirect" is a more appropriate name.

In addition, we'll hopefully have a dedicated vendor library for indirect
rendering at some point, instead of having to use another vendor library.
2015-06-29 16:47:50 -06:00
Kyle Brenneman c7f6bf974c Fix the single-thread versions of get/setspecific.
Changed st_setspecific and st_getspecific so that they will store and return a
single pointer.
2015-06-23 14:00:44 -06:00
Kyle Brenneman c7091414ae libGLdispatch: Rework the __GLdispatchPatchCallbacks interface.
Reworked the __GLdispatchPatchCallbacks interface, mostly toward fixing issue
37.

__GLdispatchPatchCallbacks::initiatePatch now handles the entire patching
process, instead of splitting it between initiatePatch, getOffsetHook, and
finalizePatch.

Added callbacks to __GLdispatchStubPatchCallbacks that are called before and
after calling into the vendor library to patch the entrypoints.

Changed the documentation to say that the vendor library can only change the
entrypoints during the call to initiatePatch. That'll allow libGLdispatch to
change the memory protection before and after the app is finished modifying
the entrypoints.

The callback that a vendor library calls to fetch an entrypoint now returns
separate writable and executable addresses.
2015-06-23 11:47:53 -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 71c4ec80b4 libGLX: Initialize __glXPthreadFuncs in libGLX instead of libGLdispatch.
libGLX will now initialize its __glXPthreadFuncs table on its own instead of
getting the table from libGLdispatch.
2015-06-15 15:42:26 -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 085fb651aa Remove pthreadFuncs from libgl.c and libopengl.c.
Anything that references the pthreadFuncs table is now #ifdef'd out in libGL
and libOpenGL, so it's safe to remove again.
2015-06-11 13:41:29 -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 8e8f12f1f4 libGLdispatch: Remove stub_init_once.
Removed stub_init_once. Instead, _glapi_init will call entry_init_public
directly.
2015-06-05 16:08:18 -06:00
Kyle Brenneman b4a45f4c50 libGLdispatch: Clean up GLAPI initialization.
Add a _glapi_init function to perform any initialization for the GLAPI layer.

u_current_init will now initialize the TSD keys, instead of trying to create
them when they're first used.

Moved the check to multiple threads to __glDispatchCheckMultithreaded. The
GLAPI layer now just has a _glapi_set_multithread function to tell it to
switch to multi-threaded mode.

Removed glapi/glthread.h, since nothing in it was used anywhere.
2015-06-05 16:08:17 -06:00
Kyle Brenneman 51fdc214ef Add an explicit null thread ID.
Changed glvnd_thread_t to have a "valid" flag to specify an invalid thread ID.

mt_equal will check the valid flag before calling pthread_equal. It will
consider any invalid glvnd_thread_t values as equal, ignoring the pthread_t
handles.

Added a GLVND_THREAD_NULL constant that you can pass to
GLVNDPthreadFuncs.equal.
2015-06-05 16:08:17 -06:00
Kyle Brenneman fe2d0d189f libGLX: Clean up MakeCurrent.
Moved the logic in glXMakeCurrent and glXMakeContextCurrent to a common
function, CommonMakeCurrent.

glXMakeCurrent/glXMakeContextCurrent will now return early if the old and
new context and drawables are the same.

UpdateCurrentContext no longer tries to look up the current context from TSD.
The MakeCurrent functions already look up the current context, so they just
pass the old context to UpdateCurrentContext.
2015-06-05 12:39:46 -06:00
Kyle Brenneman 2c300bceef libGLdispatch: Fix memory protection for the x86-64 TSD entrypoints.
Remove a stray ".text" directive so that the x86-64 TSD entrypoints are
writable.
2015-06-04 11:43:42 -06:00
Kyle Brenneman 7b5b55271a libGLdispatch: Finish x86-64 TSD stubs.
Implement the assembly code for the x86-64 TSD stubs.

In u_execmem.c, allocate enough space for 64-byte stubs, which is the size of
the new x86-64 TSD stubs.

The new stubs don't fit in 32 bytes, because they have to hold two movabs
instructions to deal with 64-bit addresses, plus push and pop instructions to
preserve the six registers that are used for passing arguments.
2015-05-28 10:41:29 -06:00
Kyle Brenneman a1ede5d162 libGLdispatch: Work on adding x86-64 TSD stubs.
Remove the x86 assembly code from entry_x86-64_tsd.h.

Rearranged it to use the same general structure as entry_x86-64_tls.h, so that
it'll work with vendor library patching.
2015-05-28 10:15:18 -06:00
Kyle Brenneman cb304fe56b libGLdispatch: Work on adding x86-64 TSD stubs.
Added a new file entry_x86-64_tsd.h. It's just a copy of entry_x86_tsd.h for
now, since that's the interface that it has to match.

Updated entry.c to use the new file depending on the GLX_USE_TLS macro, just
like it does for x86.

Added a __GLDISPATCH_STUB_X86_64_TSD enum to GLdispatchABI.h, and a
matching ENTRY_X86_64_TSD enum to entry.h.

Added a "--disable-tls" flag to the configure script to tell it not to use a
TLS version.
2015-05-28 10:15:18 -06:00
Kyle Brenneman 8f0286103a Fix newlines in a few files.
Change a handful of files from CRLF newlines to LF.
2015-05-27 09:21:09 -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 e59b468e98 libGL/libOpenGL: Remove glapitemp.h.
glapitemp.h isn't used for anything, so remove it from the makefiles.
2015-05-15 14:47:42 -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 6c7e235564 libGLX: Define a fallback vendor name.
Add a fallback vendor name to use when we can't otherwise find a vendor for a
screen.
2015-04-29 17:21:16 -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 84b8bdbe04 libGLX: Remove a redundant check for NULL. 2015-04-29 17:19:32 -06:00
Kyle Brenneman a74abb9705 libGLX: Free display info on teardown.
Added functions for allocating and freeing the __GLXdisplayInfoHash structures.

Added an LKDHASH_TEARDOWN call to free the __glXDisplayInfoHash hashtable.
2015-04-29 17:19:31 -06:00
Kyle Brenneman fe5ebf9d70 Add the pthreadFuncs variable to libGL and libOpenGL.
The pthreadFuncs variable is actually referenced from the files that go into
libGL and libOpenGL, even though none of the functions that reference it are
used. That can lead to unresolved symbol errors.
2015-04-29 14:31:29 -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 7f36bafdb1 Merge pull request #30 from kbrenneman/libglx-direct-vendor-mapping
libGLX: Rework the ABI for object-to-vendor mappings.
2015-04-29 08:40:09 -06:00
Kyle Brenneman 7380453b65 x11glvnd: Check ABI_VIDEODRV_VERSION on init.
All of the #ifdefs for dealing with different ABI versions are based on
ABI_VIDEODRV_VERSION, not ABI_EXTENSION_VERSION, so that's what glvSetup should
check.
2015-04-28 13:19:39 -06:00
Kyle Brenneman 04bd3348e9 x11glvnd: Add a check to deal with the server module being loaded more than once. 2015-04-22 16:23:10 -06:00
Kyle Brenneman de8332a36a x11glvnd: Export x11glvndModuleData from the server module. 2015-04-22 16:22:25 -06:00
Kyle Brenneman f3bc3c27c0 x11glvnd: Fix the swaps/swapl macros for ABI < 12.
With ABI versions before 12, the swaps and swapl macros need an extra
variable as a second argument.
2015-04-22 13:32:11 -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 efcfd7eebf libGLX: Fix an uninitialized variable. 2015-04-17 16:30:35 -06:00
Kyle Brenneman f3ce741d55 x11glvnd: Fix the return value for XGLVQueryExtension. 2015-04-17 14:37:38 -06:00
Kyle Brenneman 751ad7ea30 x11glvnd: Fix the return values of XGLVQueryVersion. 2015-04-17 14:21:27 -06:00
Kyle Brenneman 55a1d42b5d libglvnd: Add XGLVQueryExtension, fixes for XGLVQueryVersion.
Added a XGLVQueryExtension function, and changed XGLVQueryVersion to generate
an error if the extension isn't supported by the server, so that they match
the behavior of other X extensions.

Fixed the padding in the reply structures so that they're all 32 bytes long.

Fixed the order of the request handler array in the server.
2015-04-17 13:22:39 -06:00
Kyle Brenneman 8df2024fc4 x11glvnd: Add a QueryVersion request.
The new QueryVersion request uses request 0, bumping the two existing requests
by one.
2015-04-16 10:48:56 -06:00
Kyle Brenneman 17de9e2174 Merge pull request #25 from kbrenneman/gldispatch-pthreads
Threading-related fixes for GLdispatch
2015-04-14 15:27:21 -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
Kyle Brenneman 2fc973366b More fixes for glXGetClientString.
glXGetClientString will now allocate a buffer for the string and will merge
the strings from multiple vendor libraries.

For GLX_VENDOR, it will return each vendor library's string, separated by
commas.

For GLX_VERSION, it will report the highest version number of any vendor
library, up to the GLX version that libglvnd itself supports (currently 1.4).

For GLX_EXTENSIONS, it will return the union of all extensions advertised by
all vendor libraries.
2015-04-13 16:28:33 -06:00
Kyle Brenneman f553bd4d6a Fix glXGetClientString when there's only one screen.
In glXGetClientString, if there's only one screen, then just return the
vendor's string unmodified.
2015-04-13 13:42:14 -06:00
Kyle Brenneman d3c6adcfb1 Merge pull request #21 from nwnk/client-string
glXGetClientString fixes
2015-04-13 12:37:05 -06:00
Kyle Brenneman c91738df01 Merge pull request #26 from kbrenneman/x11-abi-fixes
Add support for other X server ABI versions.
2015-04-03 14:52:44 -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
Kyle Brenneman 72823dd180 Merge branch 'master' into gldispatch-pthreads 2015-04-01 15:04:14 -06:00
Kyle Brenneman c2c82c54bf Added an #ifdef for USE_ATTRIBUTE_CONSTRUCTOR to libopengl.c. 2015-03-31 11:45:00 -06:00
Kyle Brenneman e1bc9afe21 Fixed a couple of config messages.
Added #ifdefs for the assembler implementations for the __sync intrinsics.

Check the return value of malloc in glvnd_asprintf.

Change x11glvndclient.c back to using a (const char *) for the extension name.
2015-03-30 17:00:14 -06:00
Kyle Brenneman 1e6cb1a3b5 Add support for other X server ABI versions. 2015-03-30 11:57:19 -06:00
Kyle Brenneman df94626ddb Replace a pthreads_once call with a glvnd_pthread call. 2015-03-27 16:33:23 -06:00
Kyle Brenneman 42246b6acb Change u_thread.h to use glvnd_pthread for pthreads. 2015-03-27 14:32:30 -06:00
Kyle Brenneman 0d990b6143 Build fixes, mostly for old systems and compilers.
- Add a config check for ((constructor)) and ((destructor)) funciton
  attributes.
- Add missing GL/glxmd.h header.
- For sufficiently old gcc versions, revert to inline asm
  implementations of Atomic{Increment,Swap,CompareAndSwap}()
- Add a local implementation of asprintf.
- entry_x86_tsd.h: Add missing cast to (char *) in entry_get_public
- glvnd_pthread.[ch]: Only use pthread_rwlock_t if it's available, and fall
  back to pthread_mutex_t otherwise.
- trace.c: Add missing _GNU_SOURCE define
- uthash.h: Fix a -Wcast-qual warning
- x11glvndclient.c: Fix a -Wcast-qual warning by using a writable
  array for storing the XGLV_EXTENSION_NAME

Based on a patch by Brian Nguyen.
2015-03-27 11:46:27 -06:00
Kyle Brenneman 5ef4105e3d mapi/glapi: Fix the CALL address in entry_x86_tsd.h. 2015-03-25 16:19:44 -06:00
Kyle Brenneman b7162e070f mapi/glapi: Fix a few errors in entry_x86_tls.h
Partly fixes #18
2015-03-19 12:33:56 -06:00
Adam Jackson bbb622dfe0 [libglx] Fix a thread-safety bug in glXGetClientString
The problem with allocating a mutex on the stack is that every thread
that enters the function is going to get their own copy of the mutex,
which sort of defeats any mutual exclusion you might have been hoping
for.

Signed-off-by: Adam Jackson <ajax@redhat.com>
2015-03-18 13:06:40 -04:00
Adam Jackson cd18cc1e96 [libglx] Bump client string storage size
Mesa already needs ~700 bytes here.  Obviously this still wants to be a
proper union operation, but this gets me non-truncated output in
glxinfo for now.

Signed-off-by: Adam Jackson <ajax@redhat.com>
2015-03-18 12:51:20 -04:00
Kyle Brenneman ac2e70af02 Merge pull request #19 from nwnk/makecurrent-null-fb
[libglx] Don't throw an error for glXMakeContextCurrent(ctx, None, None)
2015-03-17 17:28:21 -06:00
Kyle Brenneman 62a880495d Update the GLX makefile so that you can run configure and make from any directory. 2015-03-11 15:54:59 -06:00
Kyle Brenneman 29d6979d89 mapi/glapi: to use ElementTree instead of libxml2.
Applied the diff from MESA commit 2de70fe23f320ce4f559e37057fe07b7af99cf5a.

Signed-off-by: Kyle Brenneman <kbrenneman@nvidia.com>
2015-03-10 16:55:02 -06:00
Adam Jackson 4d032fbb41 [libglx] Don't throw an error for glXMakeContextCurrent(ctx, None, None)
GLX_ARB_create_context explicitly allows this for GL 3.0+ contexts, the
context is made current but not bound to a default framebuffer.

Signed-off-by: Adam Jackson <ajax@redhat.com>
2015-03-03 13:58:28 -05:00
Brian Nguyen ec6969bf92 [GLdispatch] Widen dispatchStubListGeneration to 64-bit
There is a theoretical problem of wrapping if an application frequently
loads and unloads an API library which registers its entrypoints with
GLdispatch.  Proactively prevent this from being an issue by widening
dispatchStubListGeneration, and the corresponding stubGeneration
argument in the __GLdispatchPatchCallbacks API in GLdispatchABI.h, to
64-bit.
2015-02-06 09:48:54 -08:00
Brian Nguyen 22e12667cf [x11glvnd] Return a lower-case vendor name from XGLVQueryScreenVendorMapping()
This should help make the GLVendor X configuration option slightly
easier to use, and also resolve issues where falling back to the driver
name doesn't quite work because the name is differently-cased (but
otherwise the same).
2015-02-03 14:03:41 -08:00
Brian Nguyen 248440f968 s/X?GLVendor/x11glvnd/ for consistency 2015-02-03 13:49:18 -08:00
Brian Nguyen 4f1a13cbda [GLdispatchABI.h] Add a new releasePatch() entrypoint patching callback
This callback notifies vendors when they no longer "own" patched
top-level libglvnd entrypoints.  This allows vendors to safely
take advantage of optimizations which may modify entrypoint code
outside of the finalizePatch() callback.
2015-01-29 15:44:21 -08:00
Brian Nguyen 39656dd52e [libglxmapping] Don't clear out mapping hashtables on a fork
Mappings defined in the parent should remain valid in the child process,
so don't clear out mappings after a fork since they may be needed for
GLX calls made in the child.

Signed-off-by: Brian Nguyen <brnguyen@nvidia.com>
2014-10-29 14:33:41 -07:00
Brian Nguyen cb9afbace9 [libglx] Update ABI to notify vendors of X errors, fix spec compliance issue
This commit adds a new vendor callback, notifyError(), for notifying a
vendor library when an X error should be generated.  This allows the
vendor to perform any needed error recovery and to generate the error.

In MakeContextCurrentInternal(), check for:

    (context && (draw == None || read == None)) ||
    (!context && (draw != None || read != None))

and call notifyError() on an appropriate vendor to generate BadMatch
before returning False.

Signed-off-by: Brian Nguyen <brnguyen@nvidia.com>
2014-10-29 14:33:36 -07:00
Brian Nguyen b7f44ea20b [libglx] Replace {Track,Untrack}CurrentContext() with UpdateCurrentContext()
Instead of using separate functions to add and remove functions from the
global hash table of current contexts, use a single function which
handles:

- adding the new context and removing the old context from the global
  hash table
- initializing the tsdContextKey (if called for the first time) and
  updating the tsdContextKey for this thread to contain the new context

This function does _not_ handle removing a screen <-> context mapping if
the old context will be destroyed after it loses current; instead, it
simply returns a flag, needsUnmap, which is expected to be handled by
the caller.

Also, update __glXAPITeardown() to clean up screen <-> context mappings
as needed while entries are being removed from the current context hash.

Signed-off-by: Brian Nguyen <brnguyen@nvidia.com>
2014-10-29 13:59:51 -07: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 dc2f27980a Don't pass a NULL filename into dlopen(3).
Signed-off-by: Brian Nguyen <brnguyen@nvidia.com>
2014-10-28 15:37:28 -07:00
Brian Nguyen f9b084b67e Fix issues with {Track,Untrack}CurrentContext()
- Don't clear the current TSD entry when UntrackCurrentContext() is
  called.  The TSD entry already contains the correct current context when
  it is set by TrackCurrentContext() prior to the call to
  UntrackCurrentContext().

- In the comment above UntrackCurrentContext(), delete an obsolete TODO.

- If make current fails, re-track the old context before returning.

Signed-off-by: Brian Nguyen <brnguyen@nvidia.com>
2014-10-28 15:37:28 -07:00
Brian Nguyen 27d91186e3 Call into GLdispatch to lose current before a thread is destroyed
Without this, the current context accounting in GLdispatch can get
confused if a thread is destroyed while a context is still current
to that thread.

Signed-off-by: Brian Nguyen <brnguyen@nvidia.com>
2014-10-28 15:37:28 -07: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 4ccb62cd13 Track number of clients using GLdispatch
Theoretically multiple clients (libGLX and a future libEGL) may call
into __glDispatchInit() to set up dispatching, and we will want to
refcount GLdispatch to determine when dispatch teardown should occur.
So replace the global boolean 'initialized' with a counter
'clientRefcount' which tracks the number of clients using GLdispatch.

Signed-off-by: Brian Nguyen <brnguyen@nvidia.com>
2014-10-28 15:37:28 -07:00
Brian Nguyen 6ed1294e20 Remove a duplicate declaration
dispatchStubListGeneration was declared twice in GLdispatch.c,
so delete one of the declarations.

Signed-off-by: Brian Nguyen <brnguyen@nvidia.com>
2014-10-28 15:37:28 -07:00
Brian Nguyen 077214e478 Add XGLVUnregisterCloseDisplayCallbacks()
This will be called by x11glvnd clients to clean up any installed
callbacks on library teardown.

Signed-off-by: Brian Nguyen <brnguyen@nvidia.com>
2014-10-28 15:37:28 -07:00
Brian Nguyen f2ed2b87ba Add rwlock_destroy and mutex_{init,destroy} imports
Signed-off-by: Brian Nguyen <brnguyen@nvidia.com>
2014-10-06 11:10:27 -07:00
Brian Nguyen 7ff53ca956 [libGL, libOpenGL] Register stub callbacks with GLdispatch
This allows vendor libraries to re-write dispatch stubs in these wrapper
libraries.
2014-01-23 20:16:33 -08: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 fdf67a7dcd Define driver ABI for patching libglvnd entrypoints
This defines several callbacks to be used by vendor libraries for
rewriting top-level entrypoints defined in libglvnd:

- initiatePatch(): libglvnd calls into this function at make current
  time to determine whether entrypoint patching is possible with the
  given stub type and code size.  The vendor library will notify
  libglvnd whether offsets are needed based on a generation number.
- getOffsetHook(): libglvnd calls into the vendor library with this hook
  for each loaded interface library so the vendor can lookup the stub
  locations for rewriting.
- finalizePatch(): libglvnd calls into this function after the vendor
  library has updated its stub locations to complete the patch.
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