diff options
author | José Fonseca <jfonseca@vmware.com> | 2014-07-17 20:42:35 +0100 |
---|---|---|
committer | José Fonseca <jfonseca@vmware.com> | 2014-07-23 11:50:02 +0100 |
commit | e91f5bc011868db5f5a1c1e10bf718a01c75992e (patch) | |
tree | 4613a6fa8009a31dd10299a30205bd18307ae591 /dispatch | |
parent | 790b5522362b90373c413692cae16a5035fa81c3 (diff) |
gldispatch: Don't inline dispatch of GL functions.
Inlining the dispatch functions lead to slow compilation times,
and probably slower runtime due to code bloat.
Diffstat (limited to 'dispatch')
-rw-r--r-- | dispatch/.gitignore | 1 | ||||
-rw-r--r-- | dispatch/CMakeLists.txt | 16 | ||||
-rw-r--r-- | dispatch/dispatch.py | 59 | ||||
-rw-r--r-- | dispatch/glproc.py | 72 | ||||
-rw-r--r-- | dispatch/glproc_gl.cpp | 1 |
5 files changed, 103 insertions, 46 deletions
diff --git a/dispatch/.gitignore b/dispatch/.gitignore index 213c471d..0cc522b3 100644 --- a/dispatch/.gitignore +++ b/dispatch/.gitignore @@ -1 +1,2 @@ glproc.hpp +glproc.cpp diff --git a/dispatch/CMakeLists.txt b/dispatch/CMakeLists.txt index 5892c700..64577baa 100644 --- a/dispatch/CMakeLists.txt +++ b/dispatch/CMakeLists.txt @@ -7,8 +7,13 @@ include_directories ( ) add_custom_command ( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp - COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glproc.py > ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp + OUTPUT + ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp + ${CMAKE_CURRENT_BINARY_DIR}/glproc.cpp + COMMAND ${PYTHON_EXECUTABLE} + ${CMAKE_CURRENT_SOURCE_DIR}/glproc.py + ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp + ${CMAKE_CURRENT_BINARY_DIR}/glproc.cpp DEPENDS glproc.py dispatch.py @@ -26,11 +31,15 @@ add_custom_command ( # Wrap glproc.hpp as a target to prevent the command from being executed # multiple times simulatenously, when the targets that depend on it are built # in parallel. -add_custom_target (glproc DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp) +add_custom_target (glproc DEPENDS + ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp + ${CMAKE_CURRENT_BINARY_DIR}/glproc.cpp +) add_convenience_library (glproc_gl EXCLUDE_FROM_ALL glproc_gl.cpp + ${CMAKE_CURRENT_BINARY_DIR}/glproc.cpp ) add_dependencies (glproc_gl glproc) @@ -38,6 +47,7 @@ add_dependencies (glproc_gl glproc) if (ENABLE_EGL) add_convenience_library (glproc_egl EXCLUDE_FROM_ALL glproc_egl.cpp + ${CMAKE_CURRENT_BINARY_DIR}/glproc.cpp ) add_dependencies (glproc_egl glproc) diff --git a/dispatch/dispatch.py b/dispatch/dispatch.py index 3ca3c568..9e778561 100644 --- a/dispatch/dispatch.py +++ b/dispatch/dispatch.py @@ -42,17 +42,18 @@ def function_pointer_type(function): def function_pointer_value(function): - return '_' + function.name + '_ptr' + return '_' + function.name class Dispatcher: - def header(self): - pass - def dispatchModule(self, module): + self.dispatchModuleDecl(module) + self.dispatchModuleImpl(module) + + def dispatchModuleDecl(self, module): for function in module.functions: - self.dispatchFunction(module, function) + self.dispatchFunctionDecl(module, function) # define standard name aliases for convenience, but only when not # tracing, as that would cause symbol clashing with the tracing @@ -62,24 +63,41 @@ class Dispatcher: print '#define %s _%s' % (function.name, function.name) print '#endif /* RETRACE */' print - - def dispatchFunction(self, module, function): + + def dispatchFunctionDecl(self, module, function): ptype = function_pointer_type(function) pvalue = function_pointer_value(function) print 'typedef ' + function.prototype('* %s' % ptype) + ';' - print 'static %s %s = NULL;' % (ptype, pvalue) + print 'extern %s %s;' % (ptype, pvalue) print - print 'static inline ' + function.prototype('_' + function.name) + ' {' - print ' const char *_name = "%s";' % function.name + + def dispatchModuleImpl(self, module): + for function in module.functions: + self.dispatchFunctionImpl(module, function) + + def dispatchFunctionImpl(self, module, function): + ptype = function_pointer_type(function) + pvalue = function_pointer_value(function) + if function.type is stdapi.Void: ret = '' else: ret = 'return ' + + print 'static ' + function.prototype('_fail_' + function.name) + ' {' + self.failFunction(function) + print '}' + print + + print 'static ' + function.prototype('_get_' + function.name) + ' {' self.invokeGetProcAddress(module, function) print ' %s%s(%s);' % (ret, pvalue, ', '.join([str(arg.name) for arg in function.args])) print '}' print + print '%s %s = &%s;' % (ptype, pvalue, '_get_' + function.name) + print + def getProcAddressName(self, module, function): raise NotImplementedError @@ -87,24 +105,25 @@ class Dispatcher: ptype = function_pointer_type(function) pvalue = function_pointer_value(function) getProcAddressName = self.getProcAddressName(module, function) - print ' if (!%s) {' % (pvalue,) - print ' %s = (%s)%s(_name);' % (pvalue, ptype, getProcAddressName) - print ' if (!%s) {' % (pvalue,) - self.failFunction(function) - print ' }' + print ' %s _ptr;' % (ptype,) + print ' _ptr = (%s)%s("%s");' % (ptype, getProcAddressName, function.name) + print ' if (!_ptr) {' + print ' _ptr = &%s;' % ('_fail_' + function.name) print ' }' + print ' %s = _ptr;' % (pvalue,) def failFunction(self, function): + print r' const char *_name = "%s";' % function.name if function.type is stdapi.Void or function.fail is not None: - print r' os::log("warning: ignoring call to unavailable function %s\n", _name);' + print r' os::log("warning: ignoring call to unavailable function %s\n", _name);' if function.type is stdapi.Void: assert function.fail is None - print ' return;' + print ' return;' else: assert function.fail is not None - print ' return %s;' % function.fail + print ' return %s;' % function.fail else: - print r' os::log("error: unavailable function %s\n", _name);' - print r' os::abort();' + print r' os::log("error: unavailable function %s\n", _name);' + print r' os::abort();' diff --git a/dispatch/glproc.py b/dispatch/glproc.py index 4ae97223..dd085c30 100644 --- a/dispatch/glproc.py +++ b/dispatch/glproc.py @@ -29,6 +29,8 @@ covers all the functions we support. """ +import sys + from dispatch import Dispatcher import specs.stdapi as stdapi from specs.glapi import glapi @@ -491,18 +493,6 @@ public_symbols.update([ class GlDispatcher(Dispatcher): - def header(self): - print ''' -#if defined(_WIN32) -extern HMODULE _libGlHandle; -#else -extern void * _libGlHandle; -#endif - -void * _getPublicProcAddress(const char *procName); -void * _getPrivateProcAddress(const char *procName); -''' - def isFunctionPublic(self, module, function): return function.name in public_symbols or function.name.startswith('CGL') @@ -540,37 +530,73 @@ void * _getPrivateProcAddress(const char *procName); if __name__ == '__main__': + decl, impl = sys.argv[1:] + + sys.stdout = open(decl, 'wt') print print '#ifndef _GLPROC_HPP_' print '#define _GLPROC_HPP_' - print + print print '#include "glimports.hpp"' - print '#include "os.hpp"' print - dispatcher = GlDispatcher() + print '#if defined(_WIN32)' + print 'extern HMODULE _libGlHandle;' + print '#else' + print 'extern void * _libGlHandle;' + print '#endif' print - dispatcher.header() + print 'void * _getPublicProcAddress(const char *procName);' + print 'void * _getPrivateProcAddress(const char *procName);' print - dispatcher.dispatchModule(eglapi) + dispatcher = GlDispatcher() + print + dispatcher.dispatchModuleDecl(eglapi) print print '#if defined(_WIN32)' print - dispatcher.dispatchModule(wglapi) + dispatcher.dispatchModuleDecl(wglapi) print print '#elif defined(__APPLE__)' print - dispatcher.dispatchModule(cglapi) + dispatcher.dispatchModuleDecl(cglapi) print print '#elif defined(HAVE_X11)' print - dispatcher.dispatchModule(glxapi) + dispatcher.dispatchModuleDecl(glxapi) print print '#endif' print - dispatcher.dispatchModule(glapi) + dispatcher.dispatchModuleDecl(glapi) print - dispatcher.dispatchModule(glesapi) + dispatcher.dispatchModuleDecl(glesapi) print - print '#endif /* !_GLPROC_HPP_ */' print + + sys.stdout = open(impl, 'wt') + print + print '#include "glproc.hpp"' + print '#include "os.hpp"' + print + dispatcher = GlDispatcher() + print + dispatcher.dispatchModuleImpl(eglapi) + print + print '#if defined(_WIN32)' + print + dispatcher.dispatchModuleImpl(wglapi) + print + print '#elif defined(__APPLE__)' + print + dispatcher.dispatchModuleImpl(cglapi) + print + print '#elif defined(HAVE_X11)' + print + dispatcher.dispatchModuleImpl(glxapi) + print + print '#endif' + print + dispatcher.dispatchModuleImpl(glapi) + print + dispatcher.dispatchModuleImpl(glesapi) + print diff --git a/dispatch/glproc_gl.cpp b/dispatch/glproc_gl.cpp index fdbea05c..8ae40d42 100644 --- a/dispatch/glproc_gl.cpp +++ b/dispatch/glproc_gl.cpp @@ -25,6 +25,7 @@ #include "glproc.hpp" +#include "os.hpp" #if !defined(_WIN32) |