diff --git a/renderdoc/driver/gl/gen_dispatch_table.py b/renderdoc/driver/gl/gen_dispatch_table.py index 2f2c50570..747f98a04 100644 --- a/renderdoc/driver/gl/gen_dispatch_table.py +++ b/renderdoc/driver/gl/gen_dispatch_table.py @@ -13,14 +13,18 @@ parser.add_argument('-m', '--maxparam', type=int, default=17, parsed_args = parser.parse_args() -# on msys, print crlf output +# on msys, use crlf output +nl = None if sys.platform == 'msys': - sys.stdout = io.TextIOWrapper(sys.stdout.buffer, newline="\r\n") + nl = "\r\n" # Get the file, relative to this script's location (same directory) # that way we're not sensitive to CWD pathname = os.path.abspath(os.path.dirname(sys.argv[0])) + os.path.sep +# open the file for write +f = open(pathname + 'gl_dispatch_table_defs.h', mode='w', newline = nl) + # Finding definitions in the dispatch table header def_regex = re.compile('(?PPFN.*PROC) (?P.*);(\s*\/\/ aliases +)?(?P[a-zA-Z0-9_ ,]*)?') @@ -109,8 +113,8 @@ for line in official_headers: typedefs[typedef]['args'] = args -# Print the file, starting with a template header -print(''' +# f.write the file, starting with a template header +f.write(''' /****************************************************************************** * The MIT License (MIT) * @@ -139,29 +143,30 @@ print(''' // This file is autogenerated with gen_dispatch_table.py - any changes will be overwritten next time // that script is run. -// $ ./gen_dispatch_table.py > gl_dispatch_table_defs.h +// $ ./gen_dispatch_table.py // We need to disable clang-format since this struct is programmatically generated // clang-format off + '''.lstrip()) -# Print the 'definitions' of these hooks - can be used for stringification or doing +# f.write the 'definitions' of these hooks - can be used for stringification or doing # GetProcAddress style 'check name, return function' -print('#define ForEachSupported(FUNC) \\') +f.write('#define ForEachSupported(FUNC) \\\n') for hook in hooks: - print(' FUNC({}, {}); \\'.format(hook['name'], hook['name'])) + f.write(' FUNC({}, {}); \\\n'.format(hook['name'], hook['name'])) for a in hook['aliases']: - print(' FUNC({}, {}); \\'.format(hook['name'], a)) + f.write(' FUNC({}, {}); \\\n'.format(hook['name'], a)) -print("\n\n\n") +f.write("\n\n\n\n") -# Print the actual definitions - used to forward into FuncWrapperN/AliasWrapperN to define exported +# f.write the actual definitions - used to forward into FuncWrapperN/AliasWrapperN to define exported # hook implementations -print('#define DefineSupportedHooks() \\') +f.write('#define DefineSupportedHooks() \\\n') for hook in hooks: typedef = typedefs[hook['typedef']] @@ -172,32 +177,32 @@ for hook in hooks: for arg in typedef['args']: arglist += ', {}, {}'.format(arg[0], arg[1]) - print(' FuncWrapper{}({}, {}{}); \\'.format(num, typedef['return'], hook['name'], arglist)) + f.write(' FuncWrapper{}({}, {}{}); \\\n'.format(num, typedef['return'], hook['name'], arglist)) for a in hook['aliases']: - print(' AliasWrapper{}({}, {}, {}{}); \\'.format(num, typedef['return'], a, hook['name'], arglist)) + f.write(' AliasWrapper{}({}, {}, {}{}); \\\n'.format(num, typedef['return'], a, hook['name'], arglist)) -print("\n\n\n") +f.write("\n\n\n\n") -print('#define ForEachUnsupported(FUNC) \\') +f.write('#define ForEachUnsupported(FUNC) \\\n') for key in OrderedDict(sorted(typedefs.items())): typedef = typedefs[key] - # Don't print for functions we support, or wgl/etc functions + # Don't f.write for functions we support, or wgl/etc functions if typedef['used'] or typedef['function'][0:2] != 'gl': continue - print(' FUNC({}); \\'.format(typedef['function'])) + f.write(' FUNC({}); \\\n'.format(typedef['function'])) -print("\n\n\n") +f.write("\n\n\n\n") # For all typedefs not in the hooks, define them as unsupported -print('#define DefineUnsupportedHooks() \\') +f.write('#define DefineUnsupportedHooks() \\\n') for key in OrderedDict(sorted(typedefs.items())): typedef = typedefs[key] - # Don't print for functions we support, or wgl/etc functions + # Don't f.write for functions we support, or wgl/etc functions if typedef['used'] or typedef['function'][0:2] != 'gl': continue @@ -207,10 +212,10 @@ for key in OrderedDict(sorted(typedefs.items())): for arg in typedef['args']: arglist += ', {}, {}'.format(arg[0], arg[1]) - print(' UnsupportedWrapper{}({}, {}{}); \\'.format(num, typedef['return'], typedef['function'], arglist)) + f.write(' UnsupportedWrapper{}({}, {}{}); \\\n'.format(num, typedef['return'], typedef['function'], arglist)) # Now generate wrapper macros -print(''' +f.write(''' // the _renderdoc_hooked variants are to make sure we always have a function symbol exported that we @@ -219,6 +224,7 @@ print(''' // leave the 'naked' versions for applications trying to import those symbols, and declare the // _renderdoc_hooked for returning as a func pointer. The raw version calls directly into the hooked // version to hopefully allow the linker to tail-call optimise and reduce the overhead. + ''') template = ''' @@ -269,6 +275,7 @@ template = ''' return CONCAT(function, _renderdoc_hooked)({argpass}); \\ }} \\ HOOK_EXPORT ret HOOK_CC function({argdecl}); + ''' for num in range(parsed_args.maxparam+1): @@ -278,5 +285,7 @@ for num in range(parsed_args.maxparam+1): macroargs = ', ' + macroargs if num > 0 else macroargs - print(template.format(num=num, macroargs=macroargs, + f.write(template.format(num=num, macroargs=macroargs, argdecl=argdecl, argpass=argpass)) + +f.close() diff --git a/renderdoc/driver/gl/gl_dispatch_table_defs.h b/renderdoc/driver/gl/gl_dispatch_table_defs.h index ed2caf2d0..4f41af162 100644 --- a/renderdoc/driver/gl/gl_dispatch_table_defs.h +++ b/renderdoc/driver/gl/gl_dispatch_table_defs.h @@ -26,7 +26,7 @@ // This file is autogenerated with gen_dispatch_table.py - any changes will be overwritten next time // that script is run. -// $ ./gen_dispatch_table.py > gl_dispatch_table_defs.h +// $ ./gen_dispatch_table.py // We need to disable clang-format since this struct is programmatically generated // clang-format off