From 11a946cbf5ebd4ba79915ab06434847ae2581e47 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Fri, 28 Mar 2014 14:27:29 -0700 Subject: [PATCH] Prefer non-aliased functions when resolving. This increases the size of the library, but avoids some of the concerns that have been brought up with the library silently switching you from glWhateverEXT() to glWhatever() if there might be slight behavior differences between the two that hadn't been identified. The downside is that it means we can't share the resolver functions among aliases. --- src/gen_dispatch.py | 29 +++++----- test/.gitignore | 1 + test/Makefile.am | 7 ++- test/glx_alias_prefer_same_name.c | 93 +++++++++++++++++++++++++++++++ 4 files changed, 115 insertions(+), 15 deletions(-) create mode 100644 test/glx_alias_prefer_same_name.c diff --git a/src/gen_dispatch.py b/src/gen_dispatch.py index 6aba85d..aee4308 100755 --- a/src/gen_dispatch.py +++ b/src/gen_dispatch.py @@ -540,9 +540,12 @@ class Generator(object): providers = [] # Make a local list of all the providers for this alias group - for provider in func.providers.values(): + alias_root = func; + if func.alias_func: + alias_root = func.alias_func + for provider in alias_root.providers.values(): providers.append(provider) - for alias_func in func.alias_exts: + for alias_func in alias_root.alias_exts: for provider in alias_func.providers.values(): providers.append(provider) @@ -562,6 +565,10 @@ class Generator(object): for provider in alias_func.providers.values(): providers.append(provider) + def provider_sort(provider): + return (provider.name != func.name, provider.name) + providers.sort(key=provider_sort); + if len(providers) != 1: self.outln(' static const enum {0}_provider providers[] = {{'.format(self.target)) for provider in providers: @@ -591,7 +598,7 @@ class Generator(object): # Writes out the thunk that fetches the (win32) dispatch table # and calls through its entrypoint. - dispatch_table_entry = 'dispatch_table->p{0}'.format(func.alias_name) + dispatch_table_entry = 'dispatch_table->p{0}'.format(func.name) self.outln('static __stdcall {0}'.format(func.ret_type)) self.outln('epoxy_{0}_dispatch_table_thunk({1})'.format(func.wrapped_name, func.args_decl)) @@ -637,7 +644,7 @@ class Generator(object): func.args_decl)) self.outln('{') self.outln(' epoxy_{0} = (void *)epoxy_{1}_resolver();'.format(func.wrapped_name, - func.alias_name)) + func.name)) if func.ret_type == 'void': self.outln(' epoxy_{0}({1});'.format(func.wrapped_name, @@ -772,9 +779,7 @@ class Generator(object): self.outln('struct dispatch_table {') for func in self.sorted_functions: - # Aliases don't get their own slot, since they use a shared resolver. - if func.alias_name == func.name: - self.outln(' {0} p{1};'.format(func.ptr_type, func.name)) + self.outln(' {0} p{1};'.format(func.ptr_type, func.name)) self.outln('};') self.outln('') @@ -794,23 +799,19 @@ class Generator(object): self.write_provider_resolver() for func in self.sorted_functions: - if not func.alias_func: - self.write_function_ptr_resolver(func) + self.write_function_ptr_resolver(func) self.outln('#if USING_DISPATCH_TABLE') for func in self.sorted_functions: - if not func.alias_func: - self.write_dispatch_table_rewrite_stub(func) + self.write_dispatch_table_rewrite_stub(func) for func in self.sorted_functions: self.write_dispatch_table_thunk(func) self.outln('static struct dispatch_table resolver_table = {') for func in self.sorted_functions: - # Aliases don't get their own slot, since they use a shared resolver. - if func.alias_name == func.name: - self.outln(' .p{0} = epoxy_{0}_rewrite_stub,'.format(func.name)) + self.outln(' .p{0} = epoxy_{0}_rewrite_stub,'.format(func.name)) self.outln('};') self.outln('') diff --git a/test/.gitignore b/test/.gitignore index f280858..4a0d22f 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -4,6 +4,7 @@ egl_and_glx_different_pointers_glx egl_has_extension_nocontext egl_gles1_without_glx egl_gles2_without_glx +glx_alias_prefer_same_name glx_beginend glx_gles2 glx_glxgetprocaddress_nocontext diff --git a/test/Makefile.am b/test/Makefile.am index f462fbe..5a8c49a 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -94,10 +94,11 @@ endif endif GLX_TESTS = \ - glx_gles2 \ + glx_alias_prefer_same_name \ glx_beginend \ glx_public_api \ glx_public_api_core \ + glx_gles2 \ glx_glxgetprocaddress_nocontext \ glx_has_extension_nocontext \ glx_static \ @@ -143,6 +144,10 @@ egl_and_glx_different_pointers_egl_glx_LDADD = libegl_common.la libglx_common.la egl_and_glx_different_pointers_egl_glx_LDFLAGS = -rdynamic egl_and_glx_different_pointers_egl_glx_CPPFLAGS = $(AM_CPPFLAGS) -DUSE_EGL -DUSE_GLX +glx_alias_prefer_same_name_SOURCES = glx_gles2.c dlwrap.c dlwrap.h +glx_alias_prefer_same_name_LDFLAGS = -rdynamic +glx_alias_prefer_same_name_LDADD = $(EPOXY) libglx_common.la $(X11_LIBS) -ldl + glx_beginend_LDADD = $(EPOXY) libglx_common.la $(GL_LIBS) $(X11_LIBS) glx_gles2_SOURCES = glx_gles2.c dlwrap.c dlwrap.h diff --git a/test/glx_alias_prefer_same_name.c b/test/glx_alias_prefer_same_name.c new file mode 100644 index 0000000..e28db8e --- /dev/null +++ b/test/glx_alias_prefer_same_name.c @@ -0,0 +1,93 @@ +/* + * Copyright © 2013 Intel Corporation + * + * 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 (including the next + * paragraph) 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 AUTHORS OR COPYRIGHT HOLDERS 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. + */ + +/** + * @file glx_gles2.c + * + * Catches a bug where a GLES2 context using + * GLX_EXT_create_context_es2_profile would try to find the symbols in + * libGLESv2.so.2 instead of libGL.so.1. + */ + +#include +#include +#include +#include "epoxy/gl.h" +#include "epoxy/glx.h" +#include + +#include "glx_common.h" + +static Display *dpy; + +static int last_call; + +#define CORE_FUNC_VAL 100 +#define EXT_FUNC_VAL 101 + +void +override_GL_glBindTexture(GLenum target, GLenum texture); +void +override_GL_glBindTextureEXT(GLenum target, GLenum texture); + +void +override_GL_glBindTexture(GLenum target) +{ + last_call = CORE_FUNC_VAL; +} + +void +override_GL_glBindTexture(GLenum target) +{ + last_call = EXT_FUNC_VAL; +} + +int +main(int argc, char **argv) +{ + bool pass = true; + XVisualInfo *vis; + Window win; + GLXContext ctx; + GLXFBConfig config; + int context_attribs[] = { + GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_ES2_PROFILE_BIT_EXT, + GLX_CONTEXT_MAJOR_VERSION_ARB, 2, + GLX_CONTEXT_MINOR_VERSION_ARB, 0, + 0 + }; + GLuint shader; + + dpy = get_display_or_skip(); + make_glx_context_current_or_skip(dpy); + + if (!epoxy_has_gl_extension(dpy, 0, "GLX_EXT_texture_object")) + errx(77, "Test requires GLX_EXT_texture_object"); + + glBindTexture(GL_TEXTURE_2D, 1); + pass = pass && last_call == CORE_VAL; + glBindTextureEXT(GL_TEXTURE_2D, 1); + pass = pass && last_call == EXT_VAL; + + return pass != true; +}