Commit 9a4d7572 authored by Jon Turney's avatar Jon Turney
Browse files

hw/xwin/glx: Rewrite WGL wrappers after Xserver conversion to direct GL dispatch



v1: Rewrite by Marc Haesen of the WGL wrapper function generation script to use
Khronos group XML.

v2: Remove -dispatchheader option, since dispatch.h doesn't exist anymore, use
the private glapi interface to construct the GL dispatch table for the native
WGL thunks.

v3:
Rewrite to generate shims for the OpenGL 1.2.1 (GL 1.2 + GL_ARB_imaging
+GL_ARB_multitexture + GL_ARB_texture_compression(?)) functions the server links
directly with rather than libGL.

These shims dispatch to either the mesa GL DLL, or a thunking DLL containing
cdecl-to-stcall wrapper functions for the native GL DLL.
Signed-off-by: Jon Turney's avatarJon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Adam Jackson's avatarAdam Jackson <ajax@redhat.com>
parent cb48877a
......@@ -2109,7 +2109,7 @@ if test "x$XWIN" = xyes; then
esac
XWIN_LIBS="$FB_LIB $MI_LIB $FIXES_LIB $XEXT_LIB $RANDR_LIB $RENDER_LIB $DBE_LIB $RECORD_LIB $GLX_LIBS $XKB_LIB $XKB_STUB_LIB $COMPOSITE_LIB $DAMAGE_LIB $PRESENT_LIB $MIEXT_SYNC_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $OS_LIB"
XWIN_SYS_LIBS="$XWIN_SYS_LIBS $XWINMODULES_LIBS $GLX_SYS_LIBS"
XWIN_SYS_LIBS="$XWIN_SYS_LIBS $XWINMODULES_LIBS"
AC_SUBST(XWIN_LIBS)
AC_SUBST(XWIN_SERVER_NAME)
AC_SUBST(XWIN_SYS_LIBS)
......@@ -2125,10 +2125,16 @@ if test "x$XWIN" = xyes; then
dnl XWin with AIGLX requires OpenGL spec files in order to generate wrapper code for native GL functions
if [test "x$XWIN" = xyes && test "x$AIGLX" = xyes] ; then
AC_CHECK_PROG(PYTHON, python, python)
if test -z "$PYTHON"; then
AC_MSG_ERROR([python not found])
AC_CHECK_PROG(PYTHON3, python3, python3)
if test -z "$PYTHON3"; then
AC_MSG_ERROR([python3 not found])
fi
AC_MSG_CHECKING(for python module lxml)
$PYTHON3 -c "import lxml;"
if test $? -ne 0 ; then
AC_MSG_ERROR([not found])
fi
AC_MSG_RESULT(yes)
if test "x$KHRONOS_SPEC_DIR" = "xauto" ; then
PKG_CHECK_MODULES([KHRONOS_OPENGL_REGISTRY], [khronos-opengl-registry])
KHRONOS_SPEC_DIR=`pkg-config khronos-opengl-registry --variable=specdir`
......
......@@ -157,7 +157,7 @@ XWIN_LIBS += $(top_builddir)/pseudoramiX/libPseudoramiX.la
XWin_DEPENDENCIES = $(MULTIWINDOWEXTWM_LIBS) $(XWIN_GLX_LIBS) $(XWIN_LIBS) $(XSERVER_LIBS)
XWin_LDADD = $(MULTIWINDOW_LIBS) $(MULTIWINDOWEXTWM_LIBS) $(XWIN_GLX_LIBS) $(XWIN_GLX_LINK_FLAGS) $(XWIN_LIBS) $(MAIN_LIB) $(XSERVER_LIBS) $(XSERVER_SYS_LIBS) $(XWIN_SYS_LIBS)
XWin_LDFLAGS = -mwindows -static
XWin_LDFLAGS = -mwindows -static -Wl,--disable-stdcall-fixup
.rc.o:
$(AM_V_GEN)$(WINDRES) --use-temp-file -i $< --input-format=rc -o $@ -O coff -I $(top_builddir)/include
......
noinst_LTLIBRARIES = libXwinGLX.la
lib_LTLIBRARIES = libnativeGLthunk.la
libXwinGLX_la_SOURCES = \
winpriv.c \
winpriv.h \
glwindows.h \
glwrap.c \
glshim.c \
indirect.c \
wgl_ext_api.c \
wgl_ext_api.h
libnativeGLthunk_la_SOURCES = \
glthunk.c
if XWIN_MULTIWINDOW
DEFS_MULTIWINDOW = -DXWIN_MULTIWINDOW
endif
......@@ -30,16 +34,32 @@ AM_CFLAGS = -DHAVE_XWIN_CONFIG_H $(DIX_CFLAGS) \
-I$(top_srcdir) \
-I$(top_srcdir)/hw/xwin/
libnativeGLthunk_la_CFLAGS = $(AM_CFLAGS) -Wno-unused-function -Wno-missing-prototypes -Wno-missing-declarations
libnativeGLthunk_la_LDFLAGS = -shared -no-undefined -avoid-version -lopengl32 -export-symbols generated_gl_thunks.def
EXTRA_libnativeGLthunk_la_DEPENDENCIES = generated_gl_thunks.def
if XWIN_GLX_WINDOWS
generated_gl_wrappers.c: gen_gl_wrappers.py $(KHRONOS_SPEC_DIR)/gl.spec $(KHRONOS_SPEC_DIR)/gl.tm
$(AM_V_GEN)$(PYTHON) $(srcdir)/gen_gl_wrappers.py --spec=$(KHRONOS_SPEC_DIR)/gl.spec --typemap=$(KHRONOS_SPEC_DIR)/gl.tm --dispatch-header=$(top_srcdir)/glx/dispatch.h --staticwrappers >generated_gl_wrappers.c
if DEBUG
GENGLWRAPPERSOPTS=""
else
GENGLWRAPPERSOPTS="-nodebug"
endif
generated_wgl_wrappers.c: $(srcdir)/gen_gl_wrappers.py $(KHRONOS_SPEC_DIR)/wgl.xml $(KHRONOS_SPEC_DIR)/reg.py
$(AM_V_GEN)PYTHONPATH=$(KHRONOS_SPEC_DIR) $(PYTHON3) $(srcdir)/gen_gl_wrappers.py -registry $(KHRONOS_SPEC_DIR)/wgl.xml -prefix wgl -wrapper -preresolve $(GENGLWRAPPERSOPTS) -outfile $@
generated_gl_shim.c: $(srcdir)/gen_gl_wrappers.py $(KHRONOS_SPEC_DIR)/gl.xml $(KHRONOS_SPEC_DIR)/reg.py
$(AM_V_GEN)PYTHONPATH=$(KHRONOS_SPEC_DIR) $(PYTHON3) $(srcdir)/gen_gl_wrappers.py -registry $(KHRONOS_SPEC_DIR)/gl.xml -shim $(GENGLWRAPPERSOPTS) -outfile $@
generated_gl_thunks.c: $(srcdir)/gen_gl_wrappers.py $(KHRONOS_SPEC_DIR)/gl.xml $(KHRONOS_SPEC_DIR)/reg.py
$(AM_V_GEN)PYTHONPATH=$(KHRONOS_SPEC_DIR) $(PYTHON3) $(srcdir)/gen_gl_wrappers.py -registry $(KHRONOS_SPEC_DIR)/gl.xml -thunk $(GENGLWRAPPERSOPTS) -outfile $@
generated_wgl_wrappers.c: gen_gl_wrappers.py $(KHRONOS_SPEC_DIR)/wglext.spec $(KHRONOS_SPEC_DIR)/wgl.tm
$(AM_V_GEN)$(PYTHON) $(srcdir)/gen_gl_wrappers.py --spec=$(KHRONOS_SPEC_DIR)/wglext.spec --typemap=$(KHRONOS_SPEC_DIR)/wgl.tm --prefix=wgl --preresolve >generated_wgl_wrappers.c
generated_gl_thunks.def: $(srcdir)/gen_gl_wrappers.py $(KHRONOS_SPEC_DIR)/gl.xml $(KHRONOS_SPEC_DIR)/reg.py
$(AM_V_GEN)PYTHONPATH=$(KHRONOS_SPEC_DIR) $(PYTHON3) $(srcdir)/gen_gl_wrappers.py -registry $(KHRONOS_SPEC_DIR)/gl.xml -thunkdefs $(GENGLWRAPPERSOPTS) -outfile $@
endif
BUILT_SOURCES = generated_gl_wrappers.c generated_wgl_wrappers.c
BUILT_SOURCES = generated_gl_shim.c generated_gl_thunks.c generated_gl_thunks.def generated_wgl_wrappers.c
CLEANFILES = $(BUILT_SOURCES)
EXTRA_DIST = gen_gl_wrappers.py
This diff is collapsed.
/*
* File: glshim.c
* Purpose: GL shim which redirects to a specified DLL
*
* Copyright (c) Jon TURNEY 2013
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
/*
A GL shim which redirects to a specified DLL
XWin is statically linked with this, rather than the system libGL, so that
GL calls can be directed to mesa cygGL-1.dll, or cygnativeGLthunk.dll
(which contains cdecl-to-stdcall thunks to the native openGL32.dll)
*/
#ifdef HAVE_XWIN_CONFIG_H
#include <xwin-config.h>
#endif
#define GL_GLEXT_LEGACY
#include <GL/gl.h>
#undef GL_ARB_imaging
#undef GL_VERSION_1_3
#include <GL/glext.h>
#include <X11/Xwindows.h>
#include <os.h>
#include "glwindows.h"
#include <glx/glxserver.h>
static HMODULE hMod = NULL;
/*
Implement the __glGetProcAddress function by just using GetProcAddress() on the selected DLL
*/
void *glXGetProcAddressARB(const char *symbol)
{
void *proc;
/* Default to the mesa GL implementation if one hasn't been selected yet */
if (!hMod)
glWinSelectImplementation(0);
proc = GetProcAddress(hMod, symbol);
if (glxWinDebugSettings.enableGLcallTrace)
ErrorF("glXGetProcAddressARB: Resolved '%s' in %p to %p\n", symbol, hMod, proc);
return proc;
}
/*
Select a GL implementation DLL
*/
int glWinSelectImplementation(int native)
{
const char *dllname;
if (native) {
dllname = "cygnativeGLthunk.dll";
}
else {
dllname = "cygGL-1.dll";
}
hMod = LoadLibraryEx(dllname, NULL, 0);
if (hMod == NULL) {
ErrorF("glWinSelectGLimplementation: Could not load '%s'\n", dllname);
return -1;
}
ErrorF("glWinSelectGLimplementation: Loaded '%s'\n", dllname);
/* Connect __glGetProcAddress() to our implementation of glXGetProcAddressARB() above */
__glXsetGetProcAddress((glx_gpa_proc)glXGetProcAddressARB);
return 0;
}
#define RESOLVE_RET(proctype, symbol, retval) \
proctype proc = (proctype)glXGetProcAddressARB(symbol); \
if (proc == NULL) return retval;
#define RESOLVE(proctype, symbol) RESOLVE_RET(proctype, symbol,)
#define RESOLVED_PROC proc
/* Include generated shims for direct linkage to GL functions which are in the ABI */
#include "generated_gl_shim.c"
/*
Special wrapper for glAddSwapHintRectWIN for copySubBuffers
Only used with native GL if the GL_WIN_swap_hint extension is present, so we enable
GLX_MESA_copy_sub_buffer
*/
typedef void (__stdcall * PFNGLADDSWAPHINTRECTWIN) (GLint x, GLint y,
GLsizei width,
GLsizei height);
void
glAddSwapHintRectWINWrapper(GLint x, GLint y, GLsizei width,
GLsizei height)
{
RESOLVE(PFNGLADDSWAPHINTRECTWIN, "glAddSwapHintRectWIN");
RESOLVED_PROC(x, y, width, height);
}
/*
* File: glwrap.c
* Purpose: Wrapper functions for Win32 OpenGL functions
*
* Authors: Alexander Gottwald
* Jon TURNEY
*
* Copyright (c) Jon TURNEY 2009
* Copyright (c) Alexander Gottwald 2004
* File: glthunk.c
* Purpose: cdecl thunk wrapper library for Win32 stdcall OpenGL library
*
* Copyright (c) Jon TURNEY 2009,2013
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
......@@ -37,34 +32,12 @@
#endif
#include <X11/Xwindows.h>
#define GL_GLEXT_LEGACY
#include <GL/gl.h>
#undef GL_ARB_imaging
#undef GL_VERSION_1_3
#include <GL/glext.h>
#include <glx/glxserver.h>
#include <glx/glxext.h>
#include <glx/glapi.h>
#include <glx/dispatch.h>
#include <glwindows.h>
static unsigned int glWinIndirectProcCalls = 0;
static unsigned int glWinDirectProcCalls = 0;
void
glWinCallDelta(void)
{
static unsigned int glWinIndirectProcCallsLast = 0;
static unsigned int glWinDirectProcCallsLast = 0;
if ((glWinIndirectProcCalls != glWinIndirectProcCallsLast) ||
(glWinDirectProcCalls != glWinDirectProcCallsLast)) {
if (glxWinDebugSettings.enableTrace) {
ErrorF("after %d direct and %d indirect GL calls\n",
glWinDirectProcCalls - glWinDirectProcCallsLast,
glWinIndirectProcCalls - glWinIndirectProcCallsLast);
}
glWinDirectProcCallsLast = glWinDirectProcCalls;
glWinIndirectProcCallsLast = glWinIndirectProcCalls;
}
}
static PROC
glWinResolveHelper(PROC * cache, const char *symbol)
......@@ -75,11 +48,9 @@ glWinResolveHelper(PROC * cache, const char *symbol)
if ((*cache) == NULL) {
proc = wglGetProcAddress(symbol);
if (proc == NULL) {
ErrorF("glwrap: Can't resolve \"%s\"\n", symbol);
(*cache) = (PROC) - 1;
}
else {
ErrorF("glwrap: Resolved \"%s\"\n", symbol);
(*cache) = proc;
}
}
......@@ -99,10 +70,8 @@ glWinResolveHelper(PROC * cache, const char *symbol)
static PROC cache = NULL; \
__stdcall proctype proc = (proctype)glWinResolveHelper(&cache, symbol); \
if (proc == NULL) { \
__glXErrorCallBack(0); \
return retval; \
} \
glWinIndirectProcCalls++;
}
#define RESOLVE(proctype, symbol) RESOLVE_RET(proctype, symbol,)
......@@ -113,34 +82,6 @@ glWinResolveHelper(PROC * cache, const char *symbol)
OpenGL 1.2 and upward is treated as extensions, function address must
found using wglGetProcAddress(), but also stdcall so still need wrappers...
Include generated dispatch table setup function
*/
#include "generated_gl_wrappers.c"
/*
Special non-static wrapper for glGetString for debug output
*/
const GLubyte *
glGetStringWrapperNonstatic(GLenum name)
{
return glGetString(name);
}
/*
Special non-static wrapper for glAddSwapHintRectWIN for copySubBuffers
*/
typedef void (__stdcall * PFNGLADDSWAPHINTRECTWIN) (GLint x, GLint y,
GLsizei width,
GLsizei height);
void
glAddSwapHintRectWINWrapperNonstatic(GLint x, GLint y, GLsizei width,
GLsizei height)
{
RESOLVE(PFNGLADDSWAPHINTRECTWIN, "glAddSwapHintRectWIN");
proc(x, y, width, height);
}
#include "generated_gl_thunks.c"
......@@ -42,12 +42,9 @@ typedef struct {
extern glxWinDebugSettingsRec glxWinDebugSettings;
void glWinCallDelta(void);
void glxWinPushNativeProvider(void);
const GLubyte *glGetStringWrapperNonstatic(GLenum name);
void glAddSwapHintRectWINWrapperNonstatic(GLint x, GLint y, GLsizei width,
GLsizei height);
void glWinSetupDispatchTable(void);
void glAddSwapHintRectWINWrapper(GLint x, GLint y, GLsizei width, GLsizei height);
int glWinSelectImplementation(int native);
#if 1
#define GLWIN_TRACE_MSG(msg, args...) if (glxWinDebugSettings.enableTrace) ErrorF(msg " [%s:%d]\n" , ##args , __FUNCTION__, __LINE__ )
......
......@@ -550,7 +550,9 @@ glxWinScreenProbe(ScreenPtr pScreen)
if (NULL == screen)
return NULL;
/* Dump out some useful information about the native renderer */
// Select the native GL implementation (WGL)
if (glWinSelectImplementation(1))
return NULL;
// create window class
#define WIN_GL_TEST_WINDOW_CLASS "XWinGLTest"
......@@ -597,11 +599,12 @@ glxWinScreenProbe(ScreenPtr pScreen)
// (but we need to have a current context for them to be resolvable)
wglResolveExtensionProcs();
ErrorF("GL_VERSION: %s\n", glGetStringWrapperNonstatic(GL_VERSION));
ErrorF("GL_VENDOR: %s\n", glGetStringWrapperNonstatic(GL_VENDOR));
gl_renderer = (const char *) glGetStringWrapperNonstatic(GL_RENDERER);
/* Dump out some useful information about the native renderer */
ErrorF("GL_VERSION: %s\n", glGetString(GL_VERSION));
ErrorF("GL_VENDOR: %s\n", glGetString(GL_VENDOR));
gl_renderer = (const char *) glGetString(GL_RENDERER);
ErrorF("GL_RENDERER: %s\n", gl_renderer);
gl_extensions = (const char *) glGetStringWrapperNonstatic(GL_EXTENSIONS);
gl_extensions = (const char *) glGetString(GL_EXTENSIONS);
wgl_extensions = wglGetExtensionsStringARBWrapper(hdc);
if (!wgl_extensions)
wgl_extensions = "";
......@@ -615,7 +618,7 @@ glxWinScreenProbe(ScreenPtr pScreen)
free(screen);
LogMessage(X_ERROR,
"AIGLX: Won't use generic native renderer as it is not accelerated\n");
return NULL;
goto error;
}
// Can you see the problem here? The extensions string is DC specific
......@@ -726,7 +729,7 @@ glxWinScreenProbe(ScreenPtr pScreen)
free(screen);
LogMessage(X_ERROR,
"AIGLX: No fbConfigs could be made from native OpenGL pixel formats\n");
return NULL;
goto error;
}
/* These will be set by __glXScreenInit */
......@@ -789,6 +792,13 @@ glxWinScreenProbe(ScreenPtr pScreen)
pScreen->CopyWindow = glxWinCopyWindow;
return &screen->base;
error:
// Something went wrong and we can't use the native GL implementation
// so make sure the mesa GL implementation is selected instead
glWinSelectImplementation(0);
return NULL;
}
/* ---------------------------------------------------------------------- */
......@@ -910,7 +920,7 @@ static void
glxWinDrawableCopySubBuffer(__GLXdrawable * drawable,
int x, int y, int w, int h)
{
glAddSwapHintRectWINWrapperNonstatic(x, y, w, h);
glAddSwapHintRectWINWrapper(x, y, w, h);
glxWinDrawableSwapBuffers(NULL, drawable);
}
......@@ -1458,7 +1468,6 @@ glxWinContextMakeCurrent(__GLXcontext * base)
GLWIN_TRACE_MSG("glxWinContextMakeCurrent context %p (native ctx %p)", gc,
gc->ctx);
glWinCallDelta();
/* Keep a note of the last active context in the drawable */
drawPriv = gc->base.drawPriv;
......@@ -1528,7 +1537,6 @@ glxWinContextLoseCurrent(__GLXcontext * base)
GLWIN_TRACE_MSG("glxWinContextLoseCurrent context %p (native ctx %p)", gc,
gc->ctx);
glWinCallDelta();
/*
An error seems to be reported if we try to make no context current
......@@ -1623,8 +1631,6 @@ glxWinCreateContext(__GLXscreen * screen,
context->ctx = NULL;
context->shareContext = shareContext;
glWinSetupDispatchTable();
GLWIN_DEBUG_MSG("GLXcontext %p created", context);
return &(context->base);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment