Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
| 3 | # XGL |
| 4 | # |
| 5 | # Copyright (C) 2014 LunarG, Inc. |
| 6 | # |
| 7 | # Permission is hereby granted, free of charge, to any person obtaining a |
| 8 | # copy of this software and associated documentation files (the "Software"), |
| 9 | # to deal in the Software without restriction, including without limitation |
| 10 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 11 | # and/or sell copies of the Software, and to permit persons to whom the |
| 12 | # Software is furnished to do so, subject to the following conditions: |
| 13 | # |
| 14 | # The above copyright notice and this permission notice shall be included |
| 15 | # in all copies or substantial portions of the Software. |
| 16 | # |
| 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 20 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 22 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 23 | # DEALINGS IN THE SOFTWARE. |
| 24 | # |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 25 | |
Peter Lohrmann | d221ea1 | 2015-03-25 21:35:32 -0700 | [diff] [blame] | 26 | import os, sys |
| 27 | |
| 28 | # add main repo directory so xgl.py can be imported. This needs to be a complete path. |
| 29 | glv_scripts_path = os.path.dirname(os.path.abspath(__file__)) |
| 30 | main_path = os.path.abspath(glv_scripts_path + "/../../../") |
| 31 | sys.path.append(main_path) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 32 | |
| 33 | import xgl |
| 34 | |
| 35 | class Subcommand(object): |
| 36 | def __init__(self, argv): |
| 37 | self.argv = argv |
Chia-I Wu | ec30dcb | 2015-01-01 08:46:31 +0800 | [diff] [blame] | 38 | self.headers = xgl.headers |
| 39 | self.protos = xgl.protos |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 40 | |
| 41 | def run(self): |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 42 | print(self.generate()) |
| 43 | |
| 44 | def generate(self): |
| 45 | copyright = self.generate_copyright() |
| 46 | header = self.generate_header() |
| 47 | body = self.generate_body() |
| 48 | footer = self.generate_footer() |
| 49 | |
| 50 | contents = [] |
| 51 | if copyright: |
| 52 | contents.append(copyright) |
| 53 | if header: |
| 54 | contents.append(header) |
| 55 | if body: |
| 56 | contents.append(body) |
| 57 | if footer: |
| 58 | contents.append(footer) |
| 59 | |
| 60 | return "\n\n".join(contents) |
| 61 | |
| 62 | def generate_copyright(self): |
| 63 | return """/* THIS FILE IS GENERATED. DO NOT EDIT. */ |
| 64 | |
| 65 | /* |
| 66 | * XGL |
| 67 | * |
| 68 | * Copyright (C) 2014 LunarG, Inc. |
| 69 | * |
| 70 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 71 | * copy of this software and associated documentation files (the "Software"), |
| 72 | * to deal in the Software without restriction, including without limitation |
| 73 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 74 | * and/or sell copies of the Software, and to permit persons to whom the |
| 75 | * Software is furnished to do so, subject to the following conditions: |
| 76 | * |
| 77 | * The above copyright notice and this permission notice shall be included |
| 78 | * in all copies or substantial portions of the Software. |
| 79 | * |
| 80 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 81 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 82 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 83 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 84 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 85 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 86 | * DEALINGS IN THE SOFTWARE. |
| 87 | */""" |
| 88 | |
| 89 | def generate_header(self): |
| 90 | return "\n".join(["#include <" + h + ">" for h in self.headers]) |
| 91 | |
| 92 | def generate_body(self): |
| 93 | pass |
| 94 | |
| 95 | def generate_footer(self): |
| 96 | pass |
| 97 | |
Jon Ashburn | 8f44563 | 2015-02-12 10:38:36 -0700 | [diff] [blame] | 98 | # Return set of printf '%' qualifier, input to that qualifier, and any dereference |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 99 | def _get_printf_params(self, xgl_type, name, output_param): |
Jon Ashburn | 8f44563 | 2015-02-12 10:38:36 -0700 | [diff] [blame] | 100 | deref = "" |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 101 | # TODO : Need ENUM and STRUCT checks here |
| 102 | if "_TYPE" in xgl_type: # TODO : This should be generic ENUM check |
Jon Ashburn | 8f44563 | 2015-02-12 10:38:36 -0700 | [diff] [blame] | 103 | return ("%s", "string_%s(%s)" % (xgl_type.replace('const ', '').strip('*'), name), deref) |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 104 | if "char*" == xgl_type: |
Jon Ashburn | 8f44563 | 2015-02-12 10:38:36 -0700 | [diff] [blame] | 105 | return ("%s", name, "*") |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 106 | if "uint64_t" in xgl_type: |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 107 | if '*' in xgl_type: |
Jon Ashburn | 8f44563 | 2015-02-12 10:38:36 -0700 | [diff] [blame] | 108 | return ("%lu", "(%s == NULL) ? 0 : *(%s)" % (name, name), "*") |
| 109 | return ("%lu", name, deref) |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 110 | if "size_t" in xgl_type: |
Chia-I Wu | 54ed079 | 2014-12-27 14:14:50 +0800 | [diff] [blame] | 111 | if '*' in xgl_type: |
Jon Ashburn | 8f44563 | 2015-02-12 10:38:36 -0700 | [diff] [blame] | 112 | return ("%zu", "(%s == NULL) ? 0 : *(%s)" % (name, name), "*") |
| 113 | return ("%zu", name, deref) |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 114 | if "float" in xgl_type: |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 115 | if '[' in xgl_type: # handle array, current hard-coded to 4 (TODO: Make this dynamic) |
Jon Ashburn | 8f44563 | 2015-02-12 10:38:36 -0700 | [diff] [blame] | 116 | return ("[%f, %f, %f, %f]", "%s[0], %s[1], %s[2], %s[3]" % (name, name, name, name), deref) |
| 117 | return ("%f", name, deref) |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 118 | if "bool" in xgl_type or 'xcb_randr_crtc_t' in xgl_type: |
Jon Ashburn | 8f44563 | 2015-02-12 10:38:36 -0700 | [diff] [blame] | 119 | return ("%u", name, deref) |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 120 | if True in [t in xgl_type for t in ["int", "FLAGS", "MASK", "xcb_window_t"]]: |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 121 | if '[' in xgl_type: # handle array, current hard-coded to 4 (TODO: Make this dynamic) |
Jon Ashburn | 8f44563 | 2015-02-12 10:38:36 -0700 | [diff] [blame] | 122 | return ("[%i, %i, %i, %i]", "%s[0], %s[1], %s[2], %s[3]" % (name, name, name, name), deref) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 123 | if '*' in xgl_type: |
Jon Ashburn | 8f44563 | 2015-02-12 10:38:36 -0700 | [diff] [blame] | 124 | return ("%i", "(%s == NULL) ? 0 : *(%s)" % (name, name), "*") |
| 125 | return ("%i", name, deref) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 126 | if output_param: |
Jon Ashburn | 8f44563 | 2015-02-12 10:38:36 -0700 | [diff] [blame] | 127 | return ("%p", "(void*)%s" % name, deref) |
| 128 | return ("%p", "(void*)(%s)" % name, deref) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 129 | |
| 130 | def _generate_trace_func_ptrs(self): |
| 131 | func_ptrs = [] |
| 132 | func_ptrs.append('// Pointers to real functions and declarations of hooked functions') |
| 133 | func_ptrs.append('#ifdef WIN32') |
| 134 | func_ptrs.append('extern INIT_ONCE gInitOnce;') |
| 135 | for proto in self.protos: |
| 136 | if True not in [skip_str in proto.name for skip_str in ['Dbg', 'Wsi']]: #Dbg' not in proto.name and 'Wsi' not in proto.name: |
| 137 | func_ptrs.append('#define __HOOKED_xgl%s hooked_xgl%s' % (proto.name, proto.name)) |
| 138 | |
| 139 | func_ptrs.append('\n#elif defined(PLATFORM_LINUX)') |
| 140 | func_ptrs.append('extern pthread_once_t gInitOnce;') |
| 141 | for proto in self.protos: |
| 142 | if True not in [skip_str in proto.name for skip_str in ['Dbg', 'Wsi']]: |
| 143 | func_ptrs.append('#define __HOOKED_xgl%s xgl%s' % (proto.name, proto.name)) |
| 144 | |
| 145 | func_ptrs.append('#endif\n') |
| 146 | return "\n".join(func_ptrs) |
| 147 | |
| 148 | def _generate_trace_func_ptrs_ext(self, func_class='Wsi'): |
| 149 | func_ptrs = [] |
| 150 | func_ptrs.append('#ifdef WIN32') |
| 151 | for proto in self.protos: |
| 152 | if func_class in proto.name: |
| 153 | func_ptrs.append('#define __HOOKED_xgl%s hooked_xgl%s' % (proto.name, proto.name)) |
| 154 | |
| 155 | func_ptrs.append('#elif defined(__linux__)') |
| 156 | for proto in self.protos: |
| 157 | if func_class in proto.name: |
| 158 | func_ptrs.append('#define __HOOKED_xgl%s xgl%s' % (proto.name, proto.name)) |
| 159 | |
| 160 | func_ptrs.append('#endif\n') |
| 161 | return "\n".join(func_ptrs) |
| 162 | |
| 163 | def _generate_trace_func_protos(self): |
| 164 | func_protos = [] |
| 165 | func_protos.append('// Hooked function prototypes\n') |
| 166 | for proto in self.protos: |
| 167 | if 'Dbg' not in proto.name and 'Wsi' not in proto.name: |
Ian Elliott | e5a22a7 | 2015-02-26 17:01:30 -0700 | [diff] [blame] | 168 | func_protos.append('GLVTRACER_EXPORT %s;' % proto.c_func(prefix="__HOOKED_xgl", attr="XGLAPI")) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 169 | |
| 170 | return "\n".join(func_protos) |
| 171 | |
| 172 | def _generate_trace_func_protos_ext(self, func_class='Wsi'): |
| 173 | func_protos = [] |
| 174 | func_protos.append('// Hooked function prototypes\n') |
| 175 | for proto in self.protos: |
| 176 | if func_class in proto.name: |
Ian Elliott | e5a22a7 | 2015-02-26 17:01:30 -0700 | [diff] [blame] | 177 | func_protos.append('GLVTRACER_EXPORT %s;' % proto.c_func(prefix="__HOOKED_xgl", attr="XGLAPI")) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 178 | |
| 179 | return "\n".join(func_protos) |
| 180 | |
| 181 | |
Peter Lohrmann | 358d009 | 2015-04-03 12:03:44 -0700 | [diff] [blame] | 182 | def _generate_trace_real_func_ptr_protos(self): |
| 183 | func_ptr_assign = [] |
| 184 | func_ptr_assign.append('') |
| 185 | for proto in self.protos: |
| 186 | if 'Dbg' not in proto.name and 'Wsi' not in proto.name: |
| 187 | func_ptr_assign.append('extern %s( XGLAPI * real_xgl%s)(' % (proto.ret, proto.name)) |
| 188 | for p in proto.params: |
Courtney Goeltzenleuchter | 3ffda65 | 2015-04-13 14:33:40 -0600 | [diff] [blame] | 189 | if 'color' == p.name and 'XGL_CLEAR_COLOR' != p.ty: |
Peter Lohrmann | 358d009 | 2015-04-03 12:03:44 -0700 | [diff] [blame] | 190 | func_ptr_assign.append(' %s %s[4],' % (p.ty.replace('[4]', ''), p.name)) |
| 191 | else: |
| 192 | func_ptr_assign.append(' %s %s,' % (p.ty, p.name)) |
| 193 | func_ptr_assign[-1] = func_ptr_assign[-1].replace(',', ');\n') |
| 194 | return "\n".join(func_ptr_assign) |
| 195 | |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 196 | def _generate_func_ptr_assignments(self): |
| 197 | func_ptr_assign = [] |
| 198 | for proto in self.protos: |
| 199 | if 'Dbg' not in proto.name and 'Wsi' not in proto.name: |
Peter Lohrmann | 358d009 | 2015-04-03 12:03:44 -0700 | [diff] [blame] | 200 | func_ptr_assign.append('%s( XGLAPI * real_xgl%s)(' % (proto.ret, proto.name)) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 201 | for p in proto.params: |
Courtney Goeltzenleuchter | 9a1ded8 | 2015-04-03 16:35:32 -0600 | [diff] [blame] | 202 | if 'color' == p.name and 'XGL_CLEAR_COLOR' != p.ty: |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 203 | func_ptr_assign.append(' %s %s[4],' % (p.ty.replace('[4]', ''), p.name)) |
| 204 | else: |
| 205 | func_ptr_assign.append(' %s %s,' % (p.ty, p.name)) |
| 206 | func_ptr_assign[-1] = func_ptr_assign[-1].replace(',', ') = xgl%s;\n' % (proto.name)) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 207 | return "\n".join(func_ptr_assign) |
| 208 | |
Peter Lohrmann | 358d009 | 2015-04-03 12:03:44 -0700 | [diff] [blame] | 209 | |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 210 | def _generate_func_ptr_assignments_ext(self, func_class='Wsi'): |
| 211 | func_ptr_assign = [] |
| 212 | for proto in self.protos: |
| 213 | if func_class in proto.name: |
| 214 | func_ptr_assign.append('static %s( XGLAPI * real_xgl%s)(' % (proto.ret, proto.name)) |
| 215 | for p in proto.params: |
| 216 | func_ptr_assign.append(' %s %s,' % (p.ty, p.name)) |
| 217 | func_ptr_assign[-1] = func_ptr_assign[-1].replace(',', ') = xgl%s;\n' % (proto.name)) |
| 218 | return "\n".join(func_ptr_assign) |
| 219 | |
| 220 | def _generate_attach_hooks(self): |
| 221 | hooks_txt = [] |
Peter Lohrmann | 358d009 | 2015-04-03 12:03:44 -0700 | [diff] [blame] | 222 | hooks_txt.append('// declared as extern in glvtrace_xgl_helpers.h') |
| 223 | hooks_txt.append('BOOL isHooked = FALSE;\n') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 224 | hooks_txt.append('void AttachHooks()\n{\n BOOL hookSuccess = TRUE;\n#if defined(WIN32)') |
| 225 | hooks_txt.append(' Mhook_BeginMultiOperation(FALSE);') |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 226 | # TODO : Verify if CreateInstance is appropriate to key off of here |
| 227 | hooks_txt.append(' if (real_xglCreateInstance != NULL)') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 228 | hooks_txt.append(' {\n isHooked = TRUE;') |
| 229 | hook_operator = '=' |
| 230 | for proto in self.protos: |
| 231 | if 'Dbg' not in proto.name and 'Wsi' not in proto.name: |
| 232 | hooks_txt.append(' hookSuccess %s Mhook_SetHook((PVOID*)&real_xgl%s, hooked_xgl%s);' % (hook_operator, proto.name, proto.name)) |
| 233 | hook_operator = '&=' |
| 234 | hooks_txt.append(' }\n') |
| 235 | hooks_txt.append(' if (!hookSuccess)\n {') |
| 236 | hooks_txt.append(' glv_LogError("Failed to hook XGL.");\n }\n') |
| 237 | hooks_txt.append(' Mhook_EndMultiOperation();\n') |
| 238 | hooks_txt.append('#elif defined(__linux__)') |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 239 | hooks_txt.append(' if (real_xglCreateInstance == xglCreateInstance)') |
| 240 | hooks_txt.append(' hookSuccess = glv_platform_get_next_lib_sym((PVOID*)&real_xglCreateInstance,"xglCreateInstance");') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 241 | hooks_txt.append(' isHooked = TRUE;') |
| 242 | for proto in self.protos: |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 243 | if 'Dbg' not in proto.name and 'Wsi' not in proto.name and 'CreateInstance' not in proto.name: |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 244 | hooks_txt.append(' hookSuccess %s glv_platform_get_next_lib_sym((PVOID*)&real_xgl%s, "xgl%s");' % (hook_operator, proto.name, proto.name)) |
| 245 | hooks_txt.append(' if (!hookSuccess)\n {') |
| 246 | hooks_txt.append(' glv_LogError("Failed to hook XGL.");\n }\n') |
| 247 | hooks_txt.append('#endif\n}\n') |
| 248 | return "\n".join(hooks_txt) |
| 249 | |
| 250 | def _generate_attach_hooks_ext(self, func_class='Wsi'): |
| 251 | func_ext_dict = {'Wsi': '_xglwsix11ext', 'Dbg': '_xgldbg'} |
| 252 | first_proto_dict = {'Wsi': 'WsiX11AssociateConnection', 'Dbg': 'DbgSetValidationLevel'} |
| 253 | hooks_txt = [] |
| 254 | hooks_txt.append('void AttachHooks%s()\n{\n BOOL hookSuccess = TRUE;\n#if defined(WIN32)' % func_ext_dict[func_class]) |
| 255 | hooks_txt.append(' Mhook_BeginMultiOperation(FALSE);') |
| 256 | hooks_txt.append(' if (real_xgl%s != NULL)' % first_proto_dict[func_class]) |
| 257 | hooks_txt.append(' {') |
| 258 | hook_operator = '=' |
| 259 | for proto in self.protos: |
| 260 | if func_class in proto.name: |
| 261 | hooks_txt.append(' hookSuccess %s Mhook_SetHook((PVOID*)&real_xgl%s, hooked_xgl%s);' % (hook_operator, proto.name, proto.name)) |
| 262 | hook_operator = '&=' |
| 263 | hooks_txt.append(' }\n') |
| 264 | hooks_txt.append(' if (!hookSuccess)\n {') |
| 265 | hooks_txt.append(' glv_LogError("Failed to hook XGL ext %s.");\n }\n' % func_class) |
| 266 | hooks_txt.append(' Mhook_EndMultiOperation();\n') |
| 267 | hooks_txt.append('#elif defined(__linux__)') |
| 268 | hooks_txt.append(' hookSuccess = glv_platform_get_next_lib_sym((PVOID*)&real_xgl%s, "xgl%s");' % (first_proto_dict[func_class], first_proto_dict[func_class])) |
| 269 | for proto in self.protos: |
| 270 | if func_class in proto.name and first_proto_dict[func_class] not in proto.name: |
| 271 | hooks_txt.append(' hookSuccess %s glv_platform_get_next_lib_sym((PVOID*)&real_xgl%s, "xgl%s");' % (hook_operator, proto.name, proto.name)) |
| 272 | hooks_txt.append(' if (!hookSuccess)\n {') |
| 273 | hooks_txt.append(' glv_LogError("Failed to hook XGL ext %s.");\n }\n' % func_class) |
| 274 | hooks_txt.append('#endif\n}\n') |
| 275 | return "\n".join(hooks_txt) |
| 276 | |
| 277 | def _generate_detach_hooks(self): |
| 278 | hooks_txt = [] |
| 279 | hooks_txt.append('void DetachHooks()\n{\n#ifdef __linux__\n return;\n#elif defined(WIN32)') |
| 280 | hooks_txt.append(' BOOL unhookSuccess = TRUE;\n if (real_xglGetGpuInfo != NULL)\n {') |
| 281 | hook_operator = '=' |
| 282 | for proto in self.protos: |
| 283 | if 'Dbg' not in proto.name and 'Wsi' not in proto.name: |
| 284 | hooks_txt.append(' unhookSuccess %s Mhook_Unhook((PVOID*)&real_xgl%s);' % (hook_operator, proto.name)) |
| 285 | hook_operator = '&=' |
| 286 | hooks_txt.append(' }\n isHooked = FALSE;') |
| 287 | hooks_txt.append(' if (!unhookSuccess)\n {') |
| 288 | hooks_txt.append(' glv_LogError("Failed to unhook XGL.");\n }') |
| 289 | hooks_txt.append('#endif\n}') |
| 290 | hooks_txt.append('#ifdef WIN32\nINIT_ONCE gInitOnce = INIT_ONCE_STATIC_INIT;\n#elif defined(PLATFORM_LINUX)\npthread_once_t gInitOnce = PTHREAD_ONCE_INIT;\n#endif\n') |
| 291 | return "\n".join(hooks_txt) |
| 292 | |
| 293 | def _generate_detach_hooks_ext(self, func_class='Wsi'): |
| 294 | func_ext_dict = {'Wsi': '_xglwsix11ext', 'Dbg': '_xgldbg'} |
| 295 | first_proto_dict = {'Wsi': 'WsiX11AssociateConnection', 'Dbg': 'DbgSetValidationLevel'} |
| 296 | hooks_txt = [] |
| 297 | hooks_txt.append('void DetachHooks%s()\n{\n#ifdef WIN32' % func_ext_dict[func_class]) |
| 298 | hooks_txt.append(' BOOL unhookSuccess = TRUE;\n if (real_xgl%s != NULL)\n {' % first_proto_dict[func_class]) |
| 299 | hook_operator = '=' |
| 300 | for proto in self.protos: |
| 301 | if func_class in proto.name: |
| 302 | hooks_txt.append(' unhookSuccess %s Mhook_Unhook((PVOID*)&real_xgl%s);' % (hook_operator, proto.name)) |
| 303 | hook_operator = '&=' |
| 304 | hooks_txt.append(' }') |
| 305 | hooks_txt.append(' if (!unhookSuccess)\n {') |
| 306 | hooks_txt.append(' glv_LogError("Failed to unhook XGL ext %s.");\n }' % func_class) |
| 307 | hooks_txt.append('#elif defined(__linux__)\n return;\n#endif\n}\n') |
| 308 | return "\n".join(hooks_txt) |
| 309 | |
Jon Ashburn | e224839 | 2014-12-16 18:37:04 -0700 | [diff] [blame] | 310 | def _generate_init_funcs(self): |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 311 | init_tracer = [] |
Jon Ashburn | e224839 | 2014-12-16 18:37:04 -0700 | [diff] [blame] | 312 | init_tracer.append('void send_xgl_api_version_packet()\n{') |
| 313 | init_tracer.append(' struct_xglApiVersion* pPacket;') |
| 314 | init_tracer.append(' glv_trace_packet_header* pHeader;') |
| 315 | init_tracer.append(' pHeader = glv_create_trace_packet(GLV_TID_XGL, GLV_TPI_XGL_xglApiVersion, sizeof(struct_xglApiVersion), 0);') |
| 316 | init_tracer.append(' pPacket = interpret_body_as_xglApiVersion(pHeader, FALSE);') |
| 317 | init_tracer.append(' pPacket->version = XGL_API_VERSION;') |
| 318 | init_tracer.append(' FINISH_TRACE_PACKET();\n}\n') |
| 319 | |
Peter Lohrmann | 358d009 | 2015-04-03 12:03:44 -0700 | [diff] [blame] | 320 | init_tracer.append('extern GLV_CRITICAL_SECTION g_memInfoLock;') |
Ian Elliott | bc9ca5f | 2015-02-27 11:10:59 -0700 | [diff] [blame] | 321 | init_tracer.append('void InitTracer(void)\n{') |
Jon Ashburn | 1ba771d | 2015-02-19 17:04:06 -0700 | [diff] [blame] | 322 | init_tracer.append(' char *ipAddr = glv_get_global_var("GLVLIB_TRACE_IPADDR");') |
| 323 | init_tracer.append(' if (ipAddr == NULL)') |
| 324 | init_tracer.append(' ipAddr = "127.0.0.1";') |
Jon Ashburn | 0fed675 | 2015-01-09 17:36:10 -0700 | [diff] [blame] | 325 | init_tracer.append(' gMessageStream = glv_MessageStream_create(FALSE, ipAddr, GLV_BASE_PORT + GLV_TID_XGL);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 326 | init_tracer.append(' glv_trace_set_trace_file(glv_FileLike_create_msg(gMessageStream));') |
| 327 | init_tracer.append('// glv_tracelog_set_log_file(glv_FileLike_create_file(fopen("glv_log_traceside.txt","w")));') |
Jon Ashburn | e224839 | 2014-12-16 18:37:04 -0700 | [diff] [blame] | 328 | init_tracer.append(' glv_tracelog_set_tracer_id(GLV_TID_XGL);') |
Jon Ashburn | 1ba771d | 2015-02-19 17:04:06 -0700 | [diff] [blame] | 329 | init_tracer.append(' glv_create_critical_section(&g_memInfoLock);') |
Jon Ashburn | e224839 | 2014-12-16 18:37:04 -0700 | [diff] [blame] | 330 | init_tracer.append(' send_xgl_api_version_packet();\n}\n') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 331 | return "\n".join(init_tracer) |
| 332 | |
Tobin Ehlis | 1d3dd2b | 2015-03-11 17:19:54 -0600 | [diff] [blame] | 333 | # Take a list of params and return a list of dicts w/ ptr param details |
| 334 | def _get_packet_ptr_param_list(self, params): |
| 335 | ptr_param_list = [] |
| 336 | # TODO : This is a slightly nicer way to handle custom cases than initial code, however |
| 337 | # this can still be further generalized to eliminate more custom code |
| 338 | # big case to handle is when ptrs to structs have embedded data that needs to be accounted for in packet |
| 339 | custom_ptr_dict = {'XGL_DEVICE_CREATE_INFO': {'add_txt': 'add_XGL_DEVICE_CREATE_INFO_to_packet(pHeader, (XGL_DEVICE_CREATE_INFO**) &(pPacket->pCreateInfo), pCreateInfo)', |
| 340 | 'finalize_txt': ''}, |
| 341 | 'XGL_APPLICATION_INFO': {'add_txt': 'add_XGL_APPLICATION_INFO_to_packet(pHeader, (XGL_APPLICATION_INFO**)&(pPacket->pAppInfo), pAppInfo)', |
| 342 | 'finalize_txt': ''}, |
| 343 | 'XGL_PHYSICAL_GPU': {'add_txt': 'glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->pGpus), *pGpuCount*sizeof(XGL_PHYSICAL_GPU), pGpus)', |
| 344 | 'finalize_txt': 'default'}, |
| 345 | 'pDataSize': {'add_txt': 'glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->pDataSize), sizeof(size_t), &_dataSize)', |
| 346 | 'finalize_txt': 'glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pDataSize))'}, |
| 347 | 'pData': {'add_txt': 'glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->pData), _dataSize, pData)', |
| 348 | 'finalize_txt': 'default'}, |
| 349 | 'pName': {'add_txt': 'glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->pName), ((pName != NULL) ? strlen(pName) + 1 : 0), pName)', |
| 350 | 'finalize_txt': 'default'}, |
| 351 | 'pExtName': {'add_txt': 'glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->pExtName), ((pExtName != NULL) ? strlen(pExtName) + 1 : 0), pExtName)', |
| 352 | 'finalize_txt': 'default'}, |
| 353 | 'pDescriptorSets': {'add_txt': 'glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->pDescriptorSets), customSize, pDescriptorSets)', |
| 354 | 'finalize_txt': 'default'}, |
| 355 | 'pUpdateChain': {'add_txt': 'add_update_descriptors_to_trace_packet(pHeader, (void**)&(pPacket->pUpdateChain), pUpdateChain)', |
| 356 | 'finalize_txt': 'default'}, |
| 357 | 'XGL_SHADER_CREATE_INFO': {'add_txt': 'glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->pCreateInfo), sizeof(XGL_SHADER_CREATE_INFO), pCreateInfo);\n glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->pCreateInfo->pCode), ((pCreateInfo != NULL) ? pCreateInfo->codeSize : 0), pCreateInfo->pCode)', |
| 358 | 'finalize_txt': 'glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pCreateInfo->pCode));\n glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pCreateInfo))'}, |
| 359 | 'XGL_FRAMEBUFFER_CREATE_INFO': {'add_txt': 'glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->pCreateInfo), sizeof(XGL_FRAMEBUFFER_CREATE_INFO), pCreateInfo);\n glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->pCreateInfo->pColorAttachments), colorCount * sizeof(XGL_COLOR_ATTACHMENT_BIND_INFO), pCreateInfo->pColorAttachments);\n glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->pCreateInfo->pDepthStencilAttachment), dsSize, pCreateInfo->pDepthStencilAttachment)', |
| 360 | 'finalize_txt': 'glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pCreateInfo->pColorAttachments));\n glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pCreateInfo->pDepthStencilAttachment));\n glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pCreateInfo))'}, |
| 361 | 'XGL_RENDER_PASS_CREATE_INFO': {'add_txt': 'glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->pCreateInfo), sizeof(XGL_RENDER_PASS_CREATE_INFO), pCreateInfo);\n glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->pCreateInfo->pColorLoadOps), colorCount * sizeof(XGL_ATTACHMENT_LOAD_OP), pCreateInfo->pColorLoadOps);\n glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->pCreateInfo->pColorStoreOps), colorCount * sizeof(XGL_ATTACHMENT_STORE_OP), pCreateInfo->pColorStoreOps);\n glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->pCreateInfo->pColorLoadClearValues), colorCount * sizeof(XGL_CLEAR_COLOR), pCreateInfo->pColorLoadClearValues)', |
| 362 | 'finalize_txt': 'glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pCreateInfo->pColorLoadOps));\n glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pCreateInfo->pColorStoreOps));\n glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pCreateInfo->pColorLoadClearValues));\n glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pCreateInfo))'}, |
| 363 | 'XGL_CMD_BUFFER_BEGIN_INFO': {'add_txt': 'glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->pBeginInfo), sizeof(XGL_CMD_BUFFER_BEGIN_INFO), pBeginInfo);\n add_begin_cmdbuf_to_trace_packet(pHeader, (void**)&(pPacket->pBeginInfo->pNext), pBeginInfo->pNext)', |
| 364 | 'finalize_txt': 'glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pBeginInfo))'}, |
| 365 | 'XGL_DYNAMIC_VP_STATE_CREATE_INFO': {'add_txt': 'glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->pCreateInfo), sizeof(XGL_DYNAMIC_VP_STATE_CREATE_INFO), pCreateInfo);\n glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->pCreateInfo->pViewports), vpsCount * sizeof(XGL_VIEWPORT), pCreateInfo->pViewports);\n glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->pCreateInfo->pScissors), vpsCount * sizeof(XGL_RECT), pCreateInfo->pScissors)', |
| 366 | 'finalize_txt': 'glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pCreateInfo->pViewports));\n glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pCreateInfo->pScissors));\n glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pCreateInfo))'}, |
| 367 | 'XGL_MEMORY_ALLOC_INFO': {'add_txt': 'glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->pAllocInfo), sizeof(XGL_MEMORY_ALLOC_INFO), pAllocInfo);\n add_alloc_memory_to_trace_packet(pHeader, (void**)&(pPacket->pAllocInfo->pNext), pAllocInfo->pNext)', |
| 368 | 'finalize_txt': 'glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pAllocInfo))'}, |
| 369 | 'XGL_GRAPHICS_PIPELINE_CREATE_INFO': {'add_txt': 'glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->pCreateInfo), sizeof(XGL_GRAPHICS_PIPELINE_CREATE_INFO), pCreateInfo);\n add_pipeline_state_to_trace_packet(pHeader, (void**)&(pPacket->pCreateInfo->pNext), pCreateInfo->pNext)', |
| 370 | 'finalize_txt': 'glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pCreateInfo))'}, |
| 371 | 'XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO': {'add_txt': 'glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->pSetLayoutInfoList), sizeof(XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO), pSetLayoutInfoList);\n if (pSetLayoutInfoList)\n add_create_ds_layout_to_trace_packet(pHeader, (void**)&(pPacket->pSetLayoutInfoList->pNext), pSetLayoutInfoList->pNext)', |
| 372 | 'finalize_txt': 'glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pSetLayoutInfoList))'}, |
| 373 | 'XGL_DESCRIPTOR_REGION_CREATE_INFO': {'add_txt': 'glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->pCreateInfo), sizeof(XGL_DESCRIPTOR_REGION_CREATE_INFO), pCreateInfo);\n glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->pCreateInfo->pTypeCount), rgCount * sizeof(XGL_DESCRIPTOR_TYPE_COUNT), pCreateInfo->pTypeCount)', |
| 374 | 'finalize_txt': 'glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pCreateInfo->pTypeCount));\n glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pCreateInfo))'}, |
| 375 | 'XGL_COMPUTE_PIPELINE_CREATE_INFO': {'add_txt': 'glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->pCreateInfo), sizeof(XGL_COMPUTE_PIPELINE_CREATE_INFO), pCreateInfo);\n add_pipeline_state_to_trace_packet(pHeader, (void**)&(pPacket->pCreateInfo->pNext), pCreateInfo->pNext);\n add_pipeline_shader_to_trace_packet(pHeader, (XGL_PIPELINE_SHADER*)&pPacket->pCreateInfo->cs, &pCreateInfo->cs)', |
| 376 | 'finalize_txt': 'finalize_pipeline_shader_address(pHeader, &pPacket->pCreateInfo->cs);\n glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pCreateInfo))'}, |
| 377 | } |
| 378 | for p in params: |
| 379 | pp_dict = {} |
| 380 | if '*' in p.ty and p.name not in ['pSysMem', 'pReserved']: |
| 381 | if 'const' in p.ty.lower() and 'count' in params[params.index(p)-1].name.lower(): |
| 382 | pp_dict['add_txt'] = 'glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->%s), %s*sizeof(%s), %s)' % (p.name, params[params.index(p)-1].name, p.ty.strip('*').replace('const ', ''), p.name) |
| 383 | elif p.ty.strip('*').replace('const ', '') in custom_ptr_dict: |
| 384 | pp_dict['add_txt'] = custom_ptr_dict[p.ty.strip('*').replace('const ', '')]['add_txt'] |
| 385 | pp_dict['finalize_txt'] = custom_ptr_dict[p.ty.strip('*').replace('const ', '')]['finalize_txt'] |
| 386 | elif p.name in custom_ptr_dict: |
| 387 | pp_dict['add_txt'] = custom_ptr_dict[p.name]['add_txt'] |
| 388 | pp_dict['finalize_txt'] = custom_ptr_dict[p.name]['finalize_txt'] |
| 389 | # TODO : This is custom hack to account for 2 pData items with dataSize param for sizing |
| 390 | if 'pData' == p.name and 'dataSize' == params[params.index(p)-1].name: |
| 391 | pp_dict['add_txt'] = pp_dict['add_txt'].replace('_dataSize', 'dataSize') |
| 392 | else: |
| 393 | pp_dict['add_txt'] = 'glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->%s), sizeof(%s), %s)' % (p.name, p.ty.strip('*').replace('const ', ''), p.name) |
| 394 | if 'finalize_txt' not in pp_dict or 'default' == pp_dict['finalize_txt']: |
| 395 | pp_dict['finalize_txt'] = 'glv_finalize_buffer_address(pHeader, (void**)&(pPacket->%s))' % (p.name) |
| 396 | pp_dict['index'] = params.index(p) |
| 397 | ptr_param_list.append(pp_dict) |
| 398 | return ptr_param_list |
| 399 | |
Tobin Ehlis | 81b1b3d | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 400 | # Take a list of params and return a list of packet size elements |
| 401 | def _get_packet_size(self, params): |
Tobin Ehlis | f57562c | 2015-03-13 07:18:05 -0600 | [diff] [blame] | 402 | ps = [] # List of elements to be added together to account for packet size for given params |
Tobin Ehlis | 81b1b3d | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 403 | skip_list = [] # store params that are already accounted for so we don't count them twice |
| 404 | # Dict of specific params with unique custom sizes |
Tobin Ehlis | f57562c | 2015-03-13 07:18:05 -0600 | [diff] [blame] | 405 | custom_size_dict = {'pSetBindPoints': '(XGL_SHADER_STAGE_COMPUTE * sizeof(uint32_t))', # Accounting for largest possible array |
| 406 | } |
Tobin Ehlis | 81b1b3d | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 407 | for p in params: |
| 408 | #First handle custom cases |
Tobin Ehlis | f57562c | 2015-03-13 07:18:05 -0600 | [diff] [blame] | 409 | if p.name in ['pCreateInfo', 'pUpdateChain', 'pSetLayoutInfoList', 'pBeginInfo', 'pAllocInfo']: |
| 410 | ps.append('get_struct_chain_size((void*)%s)' % p.name) |
Tobin Ehlis | 81b1b3d | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 411 | skip_list.append(p.name) |
| 412 | elif p.name in custom_size_dict: |
| 413 | ps.append(custom_size_dict[p.name]) |
| 414 | skip_list.append(p.name) |
| 415 | # Skip any params already handled |
| 416 | if p.name in skip_list: |
| 417 | continue |
| 418 | # Now check to identify dynamic arrays which depend on two params |
| 419 | if 'count' in p.name.lower(): |
| 420 | next_idx = params.index(p)+1 |
| 421 | # If next element is a const *, then multiply count and array type |
| 422 | if next_idx < len(params) and '*' in params[next_idx].ty and 'const' in params[next_idx].ty.lower(): |
| 423 | if '*' in p.ty: |
| 424 | ps.append('*%s*sizeof(%s)' % (p.name, params[next_idx].ty.strip('*').replace('const ', ''))) |
| 425 | else: |
| 426 | ps.append('%s*sizeof(%s)' % (p.name, params[next_idx].ty.strip('*').replace('const ', ''))) |
| 427 | skip_list.append(params[next_idx].name) |
| 428 | elif '*' in p.ty and p.name not in ['pSysMem', 'pReserved']: |
| 429 | if 'pData' == p.name: |
| 430 | if 'dataSize' == params[params.index(p)-1].name: |
| 431 | ps.append('dataSize') |
| 432 | elif 'counterCount' == params[params.index(p)-1].name: |
| 433 | ps.append('sizeof(%s)' % p.ty.strip('*').replace('const ', '')) |
| 434 | else: |
| 435 | ps.append('((pDataSize != NULL && pData != NULL) ? *pDataSize : 0)') |
| 436 | elif '**' in p.ty and 'void' in p.ty: |
| 437 | ps.append('sizeof(void*)') |
| 438 | elif 'void' in p.ty: |
| 439 | ps.append('sizeof(%s)' % p.name) |
| 440 | elif 'char' in p.ty: |
| 441 | ps.append('((%s != NULL) ? strlen(%s) + 1 : 0)' % (p.name, p.name)) |
Tobin Ehlis | 81b1b3d | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 442 | elif 'pDataSize' in p.name: |
| 443 | ps.append('((pDataSize != NULL) ? sizeof(size_t) : 0)') |
| 444 | elif 'IMAGE_SUBRESOURCE' in p.ty and 'pSubresource' == p.name: |
| 445 | ps.append('((pSubresource != NULL) ? sizeof(XGL_IMAGE_SUBRESOURCE) : 0)') |
| 446 | else: |
| 447 | ps.append('sizeof(%s)' % (p.ty.strip('*').replace('const ', ''))) |
| 448 | return ps |
| 449 | |
Tobin Ehlis | 5099051 | 2015-02-05 11:29:45 -0700 | [diff] [blame] | 450 | # Generate functions used to trace API calls and store the input and result data into a packet |
Tobin Ehlis | 81b1b3d | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 451 | # Here's the general flow of code insertion w/ option items flagged w/ "?" |
| 452 | # Result decl? |
| 453 | # Packet struct decl |
| 454 | # ?Special case : setup call to function first and do custom API call time tracking |
| 455 | # CREATE_PACKET |
| 456 | # Call (w/ result?) |
| 457 | # Assign packet values |
| 458 | # FINISH packet |
| 459 | # return result? |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 460 | def _generate_trace_funcs(self): |
| 461 | func_body = [] |
Peter Lohrmann | 358d009 | 2015-04-03 12:03:44 -0700 | [diff] [blame] | 462 | manually_written_hooked_funcs = ['CreateInstance', 'EnumerateLayers', 'EnumerateGpus', |
| 463 | 'AllocDescriptorSets', 'MapMemory', 'UnmapMemory', |
| 464 | 'CmdPipelineBarrier', 'CmdWaitEvents'] |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 465 | for proto in self.protos: |
Peter Lohrmann | 358d009 | 2015-04-03 12:03:44 -0700 | [diff] [blame] | 466 | if proto.name in manually_written_hooked_funcs: |
| 467 | func_body.append( '// __HOOKED_xgl%s is manually written. Look in glvtrace_xgl_trace.c\n' % proto.name) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 468 | elif 'Dbg' not in proto.name and 'Wsi' not in proto.name: |
Tobin Ehlis | 81b1b3d | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 469 | raw_packet_update_list = [] # non-ptr elements placed directly into packet |
Tobin Ehlis | 1d3dd2b | 2015-03-11 17:19:54 -0600 | [diff] [blame] | 470 | ptr_packet_update_list = [] # ptr elements to be updated into packet |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 471 | return_txt = '' |
Tobin Ehlis | 81b1b3d | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 472 | packet_size = [] |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 473 | in_data_size = False # flag when we need to capture local input size variable for in/out size |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 474 | func_body.append('GLVTRACER_EXPORT %s XGLAPI __HOOKED_xgl%s(' % (proto.ret, proto.name)) |
Tobin Ehlis | 81b1b3d | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 475 | for p in proto.params: # TODO : For all of the ptr types, check them for NULL and return 0 if NULL |
| 476 | if '[' in p.ty: # Correctly declare static arrays in function parameters |
| 477 | func_body.append(' %s %s[%s],' % (p.ty[:p.ty.find('[')], p.name, p.ty[p.ty.find('[')+1:p.ty.find(']')])) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 478 | else: |
| 479 | func_body.append(' %s %s,' % (p.ty, p.name)) |
Tobin Ehlis | 81b1b3d | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 480 | if '*' in p.ty and p.name not in ['pSysMem', 'pReserved']: |
| 481 | if 'pDataSize' in p.name: |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 482 | in_data_size = True; |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 483 | else: |
Tobin Ehlis | 81b1b3d | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 484 | if '[' in p.ty: |
Tobin Ehlis | 8a5a85b | 2015-02-25 11:30:27 -0700 | [diff] [blame] | 485 | array_str = p.ty[p.ty.find('[')+1:p.ty.find(']')] |
Tobin Ehlis | 81b1b3d | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 486 | raw_packet_update_list.append(' memcpy((void*)pPacket->color, color, %s * sizeof(%s));' % (array_str, p.ty.strip('*').replace('const ', '').replace('[%s]' % array_str, ''))) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 487 | else: |
Tobin Ehlis | 81b1b3d | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 488 | raw_packet_update_list.append(' pPacket->%s = %s;' % (p.name, p.name)) |
| 489 | # Get list of packet size modifiers due to ptr params |
| 490 | packet_size = self._get_packet_size(proto.params) |
Tobin Ehlis | 1d3dd2b | 2015-03-11 17:19:54 -0600 | [diff] [blame] | 491 | ptr_packet_update_list = self._get_packet_ptr_param_list(proto.params) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 492 | func_body[-1] = func_body[-1].replace(',', ')') |
Tobin Ehlis | 81b1b3d | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 493 | # End of function declaration portion, begin function body |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 494 | func_body.append('{\n glv_trace_packet_header* pHeader;') |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 495 | if 'void' not in proto.ret or '*' in proto.ret: |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 496 | func_body.append(' %s result;' % proto.ret) |
| 497 | return_txt = 'result = ' |
| 498 | if in_data_size: |
Jon Ashburn | 53f54a3 | 2015-02-11 09:32:29 -0700 | [diff] [blame] | 499 | func_body.append(' size_t _dataSize;') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 500 | func_body.append(' struct_xgl%s* pPacket = NULL;' % proto.name) |
Jon Ashburn | 8cb39a3 | 2015-02-02 12:39:24 -0700 | [diff] [blame] | 501 | # functions that have non-standard sequence of packet creation and calling real function |
Tobin Ehlis | 81b1b3d | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 502 | # NOTE: Anytime we call the function before CREATE_TRACE_PACKET, need to add custom code for correctly tracking API call time |
Peter Lohrmann | 358d009 | 2015-04-03 12:03:44 -0700 | [diff] [blame] | 503 | if proto.name in ['CreateFramebuffer', 'CreateRenderPass', 'CreateDynamicViewportState', |
| 504 | 'CreateDescriptorRegion']: |
Tobin Ehlis | f57562c | 2015-03-13 07:18:05 -0600 | [diff] [blame] | 505 | # these are regular case as far as sequence of tracing but have some custom size element |
Tobin Ehlis | 81b1b3d | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 506 | if 'CreateFramebuffer' == proto.name: |
Jon Ashburn | a02bc24 | 2015-01-02 18:28:26 -0700 | [diff] [blame] | 507 | func_body.append(' int dsSize = (pCreateInfo != NULL && pCreateInfo->pDepthStencilAttachment != NULL) ? sizeof(XGL_DEPTH_STENCIL_BIND_INFO) : 0;') |
Tobin Ehlis | 5099051 | 2015-02-05 11:29:45 -0700 | [diff] [blame] | 508 | func_body.append(' uint32_t colorCount = (pCreateInfo != NULL && pCreateInfo->pColorAttachments != NULL) ? pCreateInfo->colorAttachmentCount : 0;') |
Tobin Ehlis | f57562c | 2015-03-13 07:18:05 -0600 | [diff] [blame] | 509 | func_body.append(' CREATE_TRACE_PACKET(xglCreateFramebuffer, get_struct_chain_size((void*)pCreateInfo) + sizeof(XGL_FRAMEBUFFER));') |
Jon Ashburn | a02bc24 | 2015-01-02 18:28:26 -0700 | [diff] [blame] | 510 | elif 'CreateRenderPass' == proto.name: |
Jon Ashburn | ec7dcb4 | 2015-02-20 10:30:32 -0700 | [diff] [blame] | 511 | func_body.append(' uint32_t colorCount = (pCreateInfo != NULL && (pCreateInfo->pColorLoadOps != NULL || pCreateInfo->pColorStoreOps != NULL || pCreateInfo->pColorLoadClearValues != NULL)) ? pCreateInfo->colorAttachmentCount : 0;') |
Jon Ashburn | 615b6ce | 2015-03-09 12:39:26 -0600 | [diff] [blame] | 512 | func_body.append(' size_t customSize;') |
| 513 | func_body.append(' customSize = colorCount * ((pCreateInfo->pColorFormats != NULL) ? sizeof(XGL_FORMAT) : 0);') |
| 514 | func_body.append(' customSize += colorCount * ((pCreateInfo->pColorLayouts != NULL) ? sizeof(XGL_IMAGE_LAYOUT) : 0);') |
| 515 | func_body.append(' customSize += colorCount * ((pCreateInfo->pColorLoadOps != NULL) ? sizeof(XGL_ATTACHMENT_LOAD_OP) : 0);') |
| 516 | func_body.append(' customSize += colorCount * ((pCreateInfo->pColorStoreOps != NULL) ? sizeof(XGL_ATTACHMENT_STORE_OP) : 0);') |
| 517 | func_body.append(' customSize += colorCount * ((pCreateInfo->pColorLoadClearValues != NULL) ? sizeof(XGL_CLEAR_COLOR) : 0);') |
| 518 | func_body.append(' CREATE_TRACE_PACKET(xglCreateRenderPass, sizeof(XGL_RENDER_PASS_CREATE_INFO) + sizeof(XGL_RENDER_PASS) + customSize);') |
| 519 | elif 'BeginCommandBuffer' == proto.name: |
| 520 | func_body.append(' customSize = calculate_begin_cmdbuf_size(pBeginInfo->pNext);') |
| 521 | func_body.append(' CREATE_TRACE_PACKET(xglBeginCommandBuffer, sizeof(XGL_CMD_BUFFER_BEGIN_INFO) + customSize);') |
Jon Ashburn | 8e7dcd0 | 2015-02-04 08:50:35 -0700 | [diff] [blame] | 522 | elif 'CreateDynamicViewportState' == proto.name: |
Courtney Goeltzenleuchter | c6e32f9 | 2015-02-11 14:13:34 -0700 | [diff] [blame] | 523 | func_body.append(' uint32_t vpsCount = (pCreateInfo != NULL && pCreateInfo->pViewports != NULL) ? pCreateInfo->viewportAndScissorCount : 0;') |
Tobin Ehlis | f57562c | 2015-03-13 07:18:05 -0600 | [diff] [blame] | 524 | func_body.append(' CREATE_TRACE_PACKET(xglCreateDynamicViewportState, get_struct_chain_size((void*)pCreateInfo) + sizeof(XGL_DYNAMIC_VP_STATE_OBJECT));') |
Jon Ashburn | fb3769a | 2015-02-04 09:32:59 -0700 | [diff] [blame] | 525 | elif 'CreateDescriptorRegion' == proto.name: |
Tobin Ehlis | 5099051 | 2015-02-05 11:29:45 -0700 | [diff] [blame] | 526 | func_body.append(' uint32_t rgCount = (pCreateInfo != NULL && pCreateInfo->pTypeCount != NULL) ? pCreateInfo->count : 0;') |
Tobin Ehlis | f57562c | 2015-03-13 07:18:05 -0600 | [diff] [blame] | 527 | func_body.append(' CREATE_TRACE_PACKET(xglCreateDescriptorRegion, get_struct_chain_size((void*)pCreateInfo) + sizeof(XGL_DESCRIPTOR_REGION));') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 528 | func_body.append(' %sreal_xgl%s;' % (return_txt, proto.c_call())) |
| 529 | else: |
Tobin Ehlis | 81b1b3d | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 530 | if (0 == len(packet_size)): |
| 531 | func_body.append(' CREATE_TRACE_PACKET(xgl%s, 0);' % (proto.name)) |
| 532 | else: |
| 533 | func_body.append(' CREATE_TRACE_PACKET(xgl%s, %s);' % (proto.name, ' + '.join(packet_size))) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 534 | func_body.append(' %sreal_xgl%s;' % (return_txt, proto.c_call())) |
Jon Ashburn | 53f54a3 | 2015-02-11 09:32:29 -0700 | [diff] [blame] | 535 | if in_data_size: |
| 536 | func_body.append(' _dataSize = (pDataSize == NULL || pData == NULL) ? 0 : *pDataSize;') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 537 | func_body.append(' pPacket = interpret_body_as_xgl%s(pHeader);' % proto.name) |
Tobin Ehlis | 81b1b3d | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 538 | func_body.append('\n'.join(raw_packet_update_list)) |
Peter Lohrmann | 358d009 | 2015-04-03 12:03:44 -0700 | [diff] [blame] | 539 | for pp_dict in ptr_packet_update_list: #buff_ptr_indices: |
| 540 | func_body.append(' %s;' % (pp_dict['add_txt'])) |
| 541 | if 'void' not in proto.ret or '*' in proto.ret: |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 542 | func_body.append(' pPacket->result = result;') |
Peter Lohrmann | 358d009 | 2015-04-03 12:03:44 -0700 | [diff] [blame] | 543 | for pp_dict in ptr_packet_update_list: |
| 544 | if ('DEVICE_CREATE_INFO' not in proto.params[pp_dict['index']].ty) and ('APPLICATION_INFO' not in proto.params[pp_dict['index']].ty) and ('pUpdateChain' != proto.params[pp_dict['index']].name): |
| 545 | func_body.append(' %s;' % (pp_dict['finalize_txt'])) |
| 546 | func_body.append(' FINISH_TRACE_PACKET();') |
| 547 | if 'AllocMemory' in proto.name: |
| 548 | func_body.append(' add_new_handle_to_mem_info(*pMem, pAllocInfo->allocationSize, NULL);') |
| 549 | elif 'FreeMemory' in proto.name: |
| 550 | func_body.append(' rm_handle_from_mem_info(mem);') |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 551 | if 'void' not in proto.ret or '*' in proto.ret: |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 552 | func_body.append(' return result;') |
| 553 | func_body.append('}\n') |
| 554 | return "\n".join(func_body) |
| 555 | |
| 556 | def _generate_trace_funcs_ext(self, func_class='Wsi'): |
| 557 | thread_once_funcs = ['DbgRegisterMsgCallback', 'DbgUnregisterMsgCallback', 'DbgSetGlobalOption'] |
| 558 | func_body = [] |
| 559 | for proto in self.protos: |
| 560 | if func_class in proto.name: |
| 561 | packet_update_txt = '' |
| 562 | return_txt = '' |
| 563 | packet_size = '' |
| 564 | buff_ptr_indices = [] |
| 565 | func_body.append('GLVTRACER_EXPORT %s XGLAPI __HOOKED_xgl%s(' % (proto.ret, proto.name)) |
| 566 | for p in proto.params: # TODO : For all of the ptr types, check them for NULL and return 0 is NULL |
| 567 | func_body.append(' %s %s,' % (p.ty, p.name)) |
| 568 | if 'Size' in p.name: |
| 569 | packet_size += p.name |
| 570 | if '*' in p.ty and 'pSysMem' != p.name: |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 571 | if 'char' in p.ty: |
Chia-I Wu | 7461fcf | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 572 | packet_size += '((%s != NULL) ? strlen(%s) + 1 : 0) + ' % (p.name, p.name) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 573 | elif 'Size' not in packet_size: |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 574 | packet_size += 'sizeof(%s) + ' % p.ty.strip('*').replace('const ', '') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 575 | buff_ptr_indices.append(proto.params.index(p)) |
| 576 | if 'pConnectionInfo' in p.name: |
| 577 | packet_size += '((pConnectionInfo->pConnection != NULL) ? sizeof(void *) : 0)' |
| 578 | else: |
| 579 | packet_update_txt += ' pPacket->%s = %s;\n' % (p.name, p.name) |
| 580 | if '' == packet_size: |
| 581 | packet_size = '0' |
| 582 | else: |
| 583 | packet_size = packet_size.strip(' + ') |
| 584 | func_body[-1] = func_body[-1].replace(',', ')') |
| 585 | func_body.append('{\n glv_trace_packet_header* pHeader;') |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 586 | if 'void' not in proto.ret or '*' in proto.ret: |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 587 | func_body.append(' %s result;' % proto.ret) |
| 588 | return_txt = 'result = ' |
| 589 | func_body.append(' struct_xgl%s* pPacket = NULL;' % proto.name) |
| 590 | if proto.name in thread_once_funcs: |
| 591 | func_body.append(' glv_platform_thread_once(&gInitOnce, InitTracer);') |
| 592 | func_body.append(' SEND_ENTRYPOINT_ID(xgl%s);' % proto.name) |
Ian Elliott | bc9ca5f | 2015-02-27 11:10:59 -0700 | [diff] [blame] | 593 | if 'DbgRegisterMsgCallback' in proto.name: |
| 594 | func_body.append(' CREATE_TRACE_PACKET(xgl%s, sizeof(char));' % proto.name) |
| 595 | else: |
| 596 | func_body.append(' CREATE_TRACE_PACKET(xgl%s, %s);' % (proto.name, packet_size)) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 597 | func_body.append(' %sreal_xgl%s;' % (return_txt, proto.c_call())) |
| 598 | func_body.append(' pPacket = interpret_body_as_xgl%s(pHeader);' % proto.name) |
| 599 | func_body.append(packet_update_txt.strip('\n')) |
| 600 | for idx in buff_ptr_indices: |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 601 | if 'char' in proto.params[idx].ty: |
Chia-I Wu | 7461fcf | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 602 | func_body.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->%s), ((%s != NULL) ? strlen(%s) + 1 : 0), %s);' % (proto.params[idx].name, proto.params[idx].name, proto.params[idx].name, proto.params[idx].name)) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 603 | elif 'Size' in proto.params[idx-1].name: |
| 604 | func_body.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->%s), %s, %s);' % (proto.params[idx].name, proto.params[idx-1].name, proto.params[idx].name)) |
Ian Elliott | bc9ca5f | 2015-02-27 11:10:59 -0700 | [diff] [blame] | 605 | elif 'DbgRegisterMsgCallback' in proto.name: |
| 606 | func_body.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->%s), sizeof(%s), %s);' % (proto.params[idx].name, 'char', proto.params[idx].name)) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 607 | else: |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 608 | func_body.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->%s), sizeof(%s), %s);' % (proto.params[idx].name, proto.params[idx].ty.strip('*').replace('const ', ''), proto.params[idx].name)) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 609 | if 'WsiX11AssociateConnection' in proto.name: |
| 610 | func_body.append(' if (pConnectionInfo->pConnection != NULL) {') |
| 611 | func_body.append(' glv_add_buffer_to_trace_packet(pHeader, (void**) &(pPacket->pConnectionInfo->pConnection), sizeof(void *), pConnectionInfo->pConnection);') |
| 612 | func_body.append(' glv_finalize_buffer_address(pHeader, (void**) &(pPacket->pConnectionInfo->pConnection));') |
| 613 | func_body.append(' }') |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 614 | if 'void' not in proto.ret or '*' in proto.ret: |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 615 | func_body.append(' pPacket->result = result;') |
| 616 | for idx in buff_ptr_indices: |
| 617 | func_body.append(' glv_finalize_buffer_address(pHeader, (void**)&(pPacket->%s));' % (proto.params[idx].name)) |
| 618 | func_body.append(' FINISH_TRACE_PACKET();') |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 619 | if 'void' not in proto.ret or '*' in proto.ret: |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 620 | func_body.append(' return result;') |
| 621 | func_body.append('}\n') |
| 622 | return "\n".join(func_body) |
| 623 | |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 624 | def _generate_packet_id_enum(self): |
| 625 | pid_enum = [] |
| 626 | pid_enum.append('enum GLV_TRACE_PACKET_ID_XGL') |
| 627 | pid_enum.append('{') |
| 628 | first_func = True |
| 629 | for proto in self.protos: |
| 630 | if first_func: |
| 631 | first_func = False |
Jon Ashburn | e224839 | 2014-12-16 18:37:04 -0700 | [diff] [blame] | 632 | pid_enum.append(' GLV_TPI_XGL_xglApiVersion = GLV_TPI_BEGIN_API_HERE,') |
| 633 | pid_enum.append(' GLV_TPI_XGL_xgl%s,' % proto.name) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 634 | else: |
| 635 | pid_enum.append(' GLV_TPI_XGL_xgl%s,' % proto.name) |
| 636 | pid_enum.append('};\n') |
| 637 | return "\n".join(pid_enum) |
| 638 | |
| 639 | def _generate_stringify_func(self): |
| 640 | func_body = [] |
| 641 | func_body.append('static const char *stringify_xgl_packet_id(const enum GLV_TRACE_PACKET_ID_XGL id, const glv_trace_packet_header* pHeader)') |
| 642 | func_body.append('{') |
| 643 | func_body.append(' static char str[1024];') |
| 644 | func_body.append(' switch(id) {') |
Jon Ashburn | e224839 | 2014-12-16 18:37:04 -0700 | [diff] [blame] | 645 | func_body.append(' case GLV_TPI_XGL_xglApiVersion:') |
| 646 | func_body.append(' {') |
| 647 | func_body.append(' struct_xglApiVersion* pPacket = (struct_xglApiVersion*)(pHeader->pBody);') |
| 648 | func_body.append(' snprintf(str, 1024, "xglApiVersion = 0x%x", pPacket->version);') |
| 649 | func_body.append(' return str;') |
| 650 | func_body.append(' }') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 651 | for proto in self.protos: |
| 652 | func_body.append(' case GLV_TPI_XGL_xgl%s:' % proto.name) |
| 653 | func_body.append(' {') |
| 654 | func_str = 'xgl%s(' % proto.name |
| 655 | print_vals = '' |
| 656 | create_func = False |
| 657 | if 'Create' in proto.name or 'Alloc' in proto.name or 'MapMemory' in proto.name: |
| 658 | create_func = True |
| 659 | for p in proto.params: |
| 660 | last_param = False |
| 661 | if (p.name == proto.params[-1].name): |
| 662 | last_param = True |
| 663 | if last_param and create_func: # last param of create func |
Jon Ashburn | 8f44563 | 2015-02-12 10:38:36 -0700 | [diff] [blame] | 664 | (pft, pfi, ptr) = self._get_printf_params(p.ty,'pPacket->%s' % p.name, True) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 665 | else: |
Jon Ashburn | 8f44563 | 2015-02-12 10:38:36 -0700 | [diff] [blame] | 666 | (pft, pfi, ptr) = self._get_printf_params(p.ty, 'pPacket->%s' % p.name, False) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 667 | if last_param == True: |
Jon Ashburn | 8f44563 | 2015-02-12 10:38:36 -0700 | [diff] [blame] | 668 | func_str += '%s%s = %s)' % (ptr, p.name, pft) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 669 | print_vals += ', %s' % (pfi) |
Courtney Goeltzenleuchter | 9a1ded8 | 2015-04-03 16:35:32 -0600 | [diff] [blame] | 670 | elif 'XGL_CLEAR_COLOR' == p.ty: |
| 671 | func_str += '%s%s = %s, ' % (ptr, p.name, pft) |
| 672 | print_vals += ', (void *) &pPacket->%s' % (p.name) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 673 | else: |
Jon Ashburn | 8f44563 | 2015-02-12 10:38:36 -0700 | [diff] [blame] | 674 | func_str += '%s%s = %s, ' % (ptr, p.name, pft) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 675 | print_vals += ', %s' % (pfi) |
| 676 | func_body.append(' struct_xgl%s* pPacket = (struct_xgl%s*)(pHeader->pBody);' % (proto.name, proto.name)) |
| 677 | func_body.append(' snprintf(str, 1024, "%s"%s);' % (func_str, print_vals)) |
| 678 | func_body.append(' return str;') |
| 679 | func_body.append(' }') |
| 680 | func_body.append(' default:') |
| 681 | func_body.append(' return NULL;') |
| 682 | func_body.append(' }') |
| 683 | func_body.append('};\n') |
| 684 | return "\n".join(func_body) |
| 685 | |
| 686 | def _generate_interp_func(self): |
| 687 | interp_func_body = [] |
| 688 | interp_func_body.append('static glv_trace_packet_header* interpret_trace_packet_xgl(glv_trace_packet_header* pHeader)') |
| 689 | interp_func_body.append('{') |
| 690 | interp_func_body.append(' if (pHeader == NULL)') |
| 691 | interp_func_body.append(' {') |
| 692 | interp_func_body.append(' return NULL;') |
| 693 | interp_func_body.append(' }') |
| 694 | interp_func_body.append(' switch (pHeader->packet_id)') |
| 695 | interp_func_body.append(' {') |
Jon Ashburn | e224839 | 2014-12-16 18:37:04 -0700 | [diff] [blame] | 696 | interp_func_body.append(' case GLV_TPI_XGL_xglApiVersion:\n {') |
| 697 | interp_func_body.append(' return interpret_body_as_xglApiVersion(pHeader, TRUE)->header;\n }') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 698 | for proto in self.protos: |
| 699 | interp_func_body.append(' case GLV_TPI_XGL_xgl%s:\n {' % proto.name) |
| 700 | header_prefix = 'h' |
| 701 | if 'Wsi' in proto.name or 'Dbg' in proto.name: |
| 702 | header_prefix = 'pH' |
| 703 | interp_func_body.append(' return interpret_body_as_xgl%s(pHeader)->%seader;\n }' % (proto.name, header_prefix)) |
| 704 | interp_func_body.append(' default:') |
| 705 | interp_func_body.append(' return NULL;') |
| 706 | interp_func_body.append(' }') |
| 707 | interp_func_body.append(' return NULL;') |
| 708 | interp_func_body.append('}') |
| 709 | return "\n".join(interp_func_body) |
| 710 | |
| 711 | def _generate_struct_util_funcs(self): |
| 712 | pid_enum = [] |
| 713 | pid_enum.append('//=============================================================================') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 714 | pid_enum.append('static void add_XGL_APPLICATION_INFO_to_packet(glv_trace_packet_header* pHeader, XGL_APPLICATION_INFO** ppStruct, const XGL_APPLICATION_INFO *pInStruct)') |
| 715 | pid_enum.append('{') |
| 716 | pid_enum.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)ppStruct, sizeof(XGL_APPLICATION_INFO), pInStruct);') |
Chia-I Wu | 7461fcf | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 717 | pid_enum.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)&((*ppStruct)->pAppName), strlen(pInStruct->pAppName) + 1, pInStruct->pAppName);') |
| 718 | pid_enum.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)&((*ppStruct)->pEngineName), strlen(pInStruct->pEngineName) + 1, pInStruct->pEngineName);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 719 | pid_enum.append(' glv_finalize_buffer_address(pHeader, (void**)&((*ppStruct)->pAppName));') |
| 720 | pid_enum.append(' glv_finalize_buffer_address(pHeader, (void**)&((*ppStruct)->pEngineName));') |
| 721 | pid_enum.append(' glv_finalize_buffer_address(pHeader, (void**)&*ppStruct);') |
| 722 | pid_enum.append('};\n') |
| 723 | pid_enum.append('//=============================================================================\n') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 724 | pid_enum.append('static void add_XGL_DEVICE_CREATE_INFO_to_packet(glv_trace_packet_header* pHeader, XGL_DEVICE_CREATE_INFO** ppStruct, const XGL_DEVICE_CREATE_INFO *pInStruct)') |
| 725 | pid_enum.append('{') |
| 726 | pid_enum.append(' uint32_t i;') |
| 727 | pid_enum.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)ppStruct, sizeof(XGL_DEVICE_CREATE_INFO), pInStruct);') |
Tobin Ehlis | f57562c | 2015-03-13 07:18:05 -0600 | [diff] [blame] | 728 | pid_enum.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)&(*ppStruct)->pRequestedQueues, pInStruct->queueRecordCount*sizeof(XGL_DEVICE_QUEUE_CREATE_INFO), pInStruct->pRequestedQueues);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 729 | pid_enum.append(' glv_finalize_buffer_address(pHeader, (void**)&(*ppStruct)->pRequestedQueues);') |
| 730 | pid_enum.append(' if (pInStruct->extensionCount > 0) ') |
| 731 | pid_enum.append(' {') |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 732 | pid_enum.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)(&(*ppStruct)->ppEnabledExtensionNames), pInStruct->extensionCount * sizeof(char *), pInStruct->ppEnabledExtensionNames);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 733 | pid_enum.append(' for (i = 0; i < pInStruct->extensionCount; i++)') |
| 734 | pid_enum.append(' {') |
Chia-I Wu | 7461fcf | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 735 | pid_enum.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)(&((*ppStruct)->ppEnabledExtensionNames[i])), strlen(pInStruct->ppEnabledExtensionNames[i]) + 1, pInStruct->ppEnabledExtensionNames[i]);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 736 | pid_enum.append(' glv_finalize_buffer_address(pHeader, (void**)(&((*ppStruct)->ppEnabledExtensionNames[i])));') |
| 737 | pid_enum.append(' }') |
| 738 | pid_enum.append(' glv_finalize_buffer_address(pHeader, (void **)&(*ppStruct)->ppEnabledExtensionNames);') |
| 739 | pid_enum.append(' }') |
Jon Ashburn | 780112b | 2015-01-09 17:30:41 -0700 | [diff] [blame] | 740 | pid_enum.append(' XGL_LAYER_CREATE_INFO *pNext = ( XGL_LAYER_CREATE_INFO *) pInStruct->pNext;') |
| 741 | pid_enum.append(' while (pNext != NULL)') |
| 742 | pid_enum.append(' {') |
| 743 | pid_enum.append(' if ((pNext->sType == XGL_STRUCTURE_TYPE_LAYER_CREATE_INFO) && pNext->layerCount > 0)') |
| 744 | pid_enum.append(' {') |
| 745 | pid_enum.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)(&((*ppStruct)->pNext)), sizeof(XGL_LAYER_CREATE_INFO), pNext);') |
| 746 | pid_enum.append(' glv_finalize_buffer_address(pHeader, (void**)(&((*ppStruct)->pNext)));') |
| 747 | pid_enum.append(' XGL_LAYER_CREATE_INFO **ppOutStruct = (XGL_LAYER_CREATE_INFO **) &((*ppStruct)->pNext);') |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 748 | pid_enum.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)(&(*ppOutStruct)->ppActiveLayerNames), pNext->layerCount * sizeof(char *), pNext->ppActiveLayerNames);') |
Jon Ashburn | 780112b | 2015-01-09 17:30:41 -0700 | [diff] [blame] | 749 | pid_enum.append(' for (i = 0; i < pNext->layerCount; i++)') |
| 750 | pid_enum.append(' {') |
| 751 | pid_enum.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)(&((*ppOutStruct)->ppActiveLayerNames[i])), strlen(pNext->ppActiveLayerNames[i]) + 1, pNext->ppActiveLayerNames[i]);') |
| 752 | pid_enum.append(' glv_finalize_buffer_address(pHeader, (void**)(&((*ppOutStruct)->ppActiveLayerNames[i])));') |
| 753 | pid_enum.append(' }') |
| 754 | pid_enum.append(' glv_finalize_buffer_address(pHeader, (void **)&(*ppOutStruct)->ppActiveLayerNames);') |
| 755 | pid_enum.append(' }') |
| 756 | pid_enum.append(' pNext = ( XGL_LAYER_CREATE_INFO *) pNext->pNext;') |
| 757 | pid_enum.append(' }') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 758 | pid_enum.append(' glv_finalize_buffer_address(pHeader, (void**)ppStruct);') |
| 759 | pid_enum.append('}\n') |
| 760 | pid_enum.append('static XGL_DEVICE_CREATE_INFO* interpret_XGL_DEVICE_CREATE_INFO(glv_trace_packet_header* pHeader, intptr_t ptr_variable)') |
| 761 | pid_enum.append('{') |
| 762 | pid_enum.append(' XGL_DEVICE_CREATE_INFO* pXGL_DEVICE_CREATE_INFO = (XGL_DEVICE_CREATE_INFO*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)ptr_variable);\n') |
| 763 | pid_enum.append(' if (pXGL_DEVICE_CREATE_INFO != NULL)') |
| 764 | pid_enum.append(' {') |
Jon Ashburn | 780112b | 2015-01-09 17:30:41 -0700 | [diff] [blame] | 765 | pid_enum.append(' uint32_t i;') |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 766 | pid_enum.append(' const char** pNames;') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 767 | pid_enum.append(' pXGL_DEVICE_CREATE_INFO->pRequestedQueues = (const XGL_DEVICE_QUEUE_CREATE_INFO*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pXGL_DEVICE_CREATE_INFO->pRequestedQueues);\n') |
| 768 | pid_enum.append(' if (pXGL_DEVICE_CREATE_INFO->extensionCount > 0)') |
| 769 | pid_enum.append(' {') |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 770 | pid_enum.append(' pXGL_DEVICE_CREATE_INFO->ppEnabledExtensionNames = (const char *const*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pXGL_DEVICE_CREATE_INFO->ppEnabledExtensionNames);') |
| 771 | pid_enum.append(' pNames = (const char**)pXGL_DEVICE_CREATE_INFO->ppEnabledExtensionNames;') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 772 | pid_enum.append(' for (i = 0; i < pXGL_DEVICE_CREATE_INFO->extensionCount; i++)') |
| 773 | pid_enum.append(' {') |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 774 | pid_enum.append(' pNames[i] = (const char*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)(pXGL_DEVICE_CREATE_INFO->ppEnabledExtensionNames[i]));') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 775 | pid_enum.append(' }') |
| 776 | pid_enum.append(' }') |
Jon Ashburn | 780112b | 2015-01-09 17:30:41 -0700 | [diff] [blame] | 777 | pid_enum.append(' XGL_LAYER_CREATE_INFO *pNext = ( XGL_LAYER_CREATE_INFO *) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pXGL_DEVICE_CREATE_INFO->pNext);') |
| 778 | pid_enum.append(' while (pNext != NULL)') |
| 779 | pid_enum.append(' {') |
| 780 | pid_enum.append(' if ((pNext->sType == XGL_STRUCTURE_TYPE_LAYER_CREATE_INFO) && pNext->layerCount > 0)') |
| 781 | pid_enum.append(' {') |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 782 | pid_enum.append(' pNext->ppActiveLayerNames = (const char**) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)(pNext->ppActiveLayerNames));') |
| 783 | pid_enum.append(' pNames = (const char**)pNext->ppActiveLayerNames;') |
Jon Ashburn | 780112b | 2015-01-09 17:30:41 -0700 | [diff] [blame] | 784 | pid_enum.append(' for (i = 0; i < pNext->layerCount; i++)') |
| 785 | pid_enum.append(' {') |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 786 | pid_enum.append(' pNames[i] = (const char*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)(pNext->ppActiveLayerNames[i]));') |
Jon Ashburn | 780112b | 2015-01-09 17:30:41 -0700 | [diff] [blame] | 787 | pid_enum.append(' }') |
| 788 | pid_enum.append(' }') |
| 789 | pid_enum.append(' pNext = ( XGL_LAYER_CREATE_INFO *) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);') |
| 790 | pid_enum.append(' }') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 791 | pid_enum.append(' }\n') |
| 792 | pid_enum.append(' return pXGL_DEVICE_CREATE_INFO;') |
| 793 | pid_enum.append('}\n') |
| 794 | pid_enum.append('static void interpret_pipeline_shader(glv_trace_packet_header* pHeader, XGL_PIPELINE_SHADER* pShader)') |
| 795 | pid_enum.append('{') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 796 | pid_enum.append(' if (pShader != NULL)') |
| 797 | pid_enum.append(' {') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 798 | pid_enum.append(' // constant buffers') |
| 799 | pid_enum.append(' if (pShader->linkConstBufferCount > 0)') |
| 800 | pid_enum.append(' {') |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 801 | pid_enum.append(' uint32_t i;') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 802 | pid_enum.append(' pShader->pLinkConstBufferInfo = (const XGL_LINK_CONST_BUFFER*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pShader->pLinkConstBufferInfo);') |
| 803 | pid_enum.append(' for (i = 0; i < pShader->linkConstBufferCount; i++)') |
| 804 | pid_enum.append(' {') |
| 805 | pid_enum.append(' XGL_LINK_CONST_BUFFER* pBuffer = (XGL_LINK_CONST_BUFFER*)pShader->pLinkConstBufferInfo;') |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 806 | pid_enum.append(' pBuffer[i].pBufferData = (const void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pShader->pLinkConstBufferInfo[i].pBufferData);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 807 | pid_enum.append(' }') |
| 808 | pid_enum.append(' }') |
| 809 | pid_enum.append(' }') |
| 810 | pid_enum.append('}\n') |
| 811 | pid_enum.append('//=============================================================================') |
| 812 | return "\n".join(pid_enum) |
| 813 | |
Tobin Ehlis | 5099051 | 2015-02-05 11:29:45 -0700 | [diff] [blame] | 814 | # Interpret functions used on replay to read in packets and interpret their contents |
Peter Lohrmann | cde614c | 2015-03-27 12:57:10 -0700 | [diff] [blame] | 815 | # This code gets generated into glv_vk_vk_structs.h file |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 816 | def _generate_interp_funcs(self): |
| 817 | # Custom txt for given function and parameter. First check if param is NULL, then insert txt if not |
Tobin Ehlis | 5099051 | 2015-02-05 11:29:45 -0700 | [diff] [blame] | 818 | # TODO : This code is now too large and complex, need to make codegen smarter for pointers embedded in struct params to handle those cases automatically |
Tobin Ehlis | 45bc7f8 | 2015-01-16 15:13:34 -0700 | [diff] [blame] | 819 | custom_case_dict = { 'CreateInstance' : {'param': 'pAppInfo', 'txt': ['XGL_APPLICATION_INFO* pInfo = (XGL_APPLICATION_INFO*)pPacket->pAppInfo;\n', |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 820 | 'pInfo->pAppName = (const char*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pAppInfo->pAppName);\n', |
| 821 | 'pInfo->pEngineName = (const char*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pAppInfo->pEngineName);']}, |
Jon Ashburn | a02bc24 | 2015-01-02 18:28:26 -0700 | [diff] [blame] | 822 | 'CreateShader' : {'param': 'pCreateInfo', 'txt': ['XGL_SHADER_CREATE_INFO* pInfo = (XGL_SHADER_CREATE_INFO*)pPacket->pCreateInfo;\n', |
| 823 | 'pInfo->pCode = glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pCreateInfo->pCode);']}, |
Jon Ashburn | 8e7dcd0 | 2015-02-04 08:50:35 -0700 | [diff] [blame] | 824 | 'CreateDynamicViewportState' : {'param': 'pCreateInfo', 'txt': ['XGL_DYNAMIC_VP_STATE_CREATE_INFO* pInfo = (XGL_DYNAMIC_VP_STATE_CREATE_INFO*)pPacket->pCreateInfo;\n', |
| 825 | 'pInfo->pViewports = (XGL_VIEWPORT*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pCreateInfo->pViewports);\n', |
| 826 | 'pInfo->pScissors = (XGL_RECT*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pCreateInfo->pScissors);']}, |
Jon Ashburn | a02bc24 | 2015-01-02 18:28:26 -0700 | [diff] [blame] | 827 | 'CreateFramebuffer' : {'param': 'pCreateInfo', 'txt': ['XGL_FRAMEBUFFER_CREATE_INFO* pInfo = (XGL_FRAMEBUFFER_CREATE_INFO*)pPacket->pCreateInfo;\n', |
| 828 | 'pInfo->pColorAttachments = (XGL_COLOR_ATTACHMENT_BIND_INFO*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pCreateInfo->pColorAttachments);\n', |
| 829 | 'pInfo->pDepthStencilAttachment = (XGL_DEPTH_STENCIL_BIND_INFO*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pCreateInfo->pDepthStencilAttachment);\n']}, |
| 830 | 'CreateRenderPass' : {'param': 'pCreateInfo', 'txt': ['XGL_RENDER_PASS_CREATE_INFO* pInfo = (XGL_RENDER_PASS_CREATE_INFO*)pPacket->pCreateInfo;\n', |
Jon Ashburn | 615b6ce | 2015-03-09 12:39:26 -0600 | [diff] [blame] | 831 | 'pInfo->pColorFormats = (XGL_FORMAT*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pCreateInfo->pColorFormats);\n', |
| 832 | 'pInfo->pColorLayouts = (XGL_IMAGE_LAYOUT*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pCreateInfo->pColorLayouts);\n', |
Jon Ashburn | a02bc24 | 2015-01-02 18:28:26 -0700 | [diff] [blame] | 833 | 'pInfo->pColorLoadOps = (XGL_ATTACHMENT_LOAD_OP*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pCreateInfo->pColorLoadOps);\n', |
| 834 | 'pInfo->pColorStoreOps = (XGL_ATTACHMENT_STORE_OP*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pCreateInfo->pColorStoreOps);\n', |
| 835 | 'pInfo->pColorLoadClearValues = (XGL_CLEAR_COLOR*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pCreateInfo->pColorLoadClearValues);\n']}, |
Jon Ashburn | fb3769a | 2015-02-04 09:32:59 -0700 | [diff] [blame] | 836 | 'CreateDescriptorRegion' : {'param': 'pCreateInfo', 'txt': ['XGL_DESCRIPTOR_REGION_CREATE_INFO* pInfo = (XGL_DESCRIPTOR_REGION_CREATE_INFO*)pPacket->pCreateInfo;\n', |
| 837 | 'pInfo->pTypeCount = (XGL_DESCRIPTOR_TYPE_COUNT*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pCreateInfo->pTypeCount);\n']}, |
Tobin Ehlis | 5099051 | 2015-02-05 11:29:45 -0700 | [diff] [blame] | 838 | 'CmdWaitEvents' : {'param': 'pWaitInfo', 'txt': ['XGL_EVENT_WAIT_INFO* pInfo = (XGL_EVENT_WAIT_INFO*)pPacket->pWaitInfo;\n', |
| 839 | 'pInfo->pEvents = (XGL_EVENT*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pWaitInfo->pEvents);\n', |
| 840 | 'pInfo->ppMemBarriers = (const void**) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pWaitInfo->ppMemBarriers);\n', |
| 841 | 'uint32_t i;\n', |
| 842 | 'for (i = 0; i < pInfo->memBarrierCount; i++) {\n', |
| 843 | ' void** ppLocalMemBarriers = (void**)&pInfo->ppMemBarriers[i];\n', |
| 844 | ' *ppLocalMemBarriers = (void*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pInfo->ppMemBarriers[i]);\n', |
| 845 | '}']}, |
| 846 | 'CmdPipelineBarrier' : {'param': 'pBarrier', 'txt': ['XGL_PIPELINE_BARRIER* pBarrier = (XGL_PIPELINE_BARRIER*)pPacket->pBarrier;\n', |
Courtney Goeltzenleuchter | aa86e0e | 2015-03-24 18:02:34 -0600 | [diff] [blame] | 847 | 'pBarrier->pEvents = (XGL_PIPE_EVENT*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pBarrier->pEvents);\n', |
Tobin Ehlis | 5099051 | 2015-02-05 11:29:45 -0700 | [diff] [blame] | 848 | 'pBarrier->ppMemBarriers = (const void**) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pBarrier->ppMemBarriers);\n', |
| 849 | 'uint32_t i;\n', |
| 850 | 'for (i = 0; i < pBarrier->memBarrierCount; i++) {\n', |
| 851 | ' void** ppLocalMemBarriers = (void**)&pBarrier->ppMemBarriers[i];\n', |
| 852 | ' *ppLocalMemBarriers = (void*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pBarrier->ppMemBarriers[i]);\n', |
| 853 | '}']}, |
Peter Lohrmann | 7810957 | 2015-03-10 15:30:36 -0700 | [diff] [blame] | 854 | 'CreateDescriptorSetLayout' : {'param': 'pSetLayoutInfoList', 'txt': ['if (pPacket->pSetLayoutInfoList->sType == XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO) {\n', |
| 855 | ' // need to make a non-const pointer to the pointer so that we can properly change the original pointer to the interpretted one\n', |
| 856 | ' void** ppNextVoidPtr = (void**)&(pPacket->pSetLayoutInfoList->pNext);\n', |
| 857 | ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pSetLayoutInfoList->pNext);\n', |
| 858 | ' XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO* pNext = (XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO*)pPacket->pSetLayoutInfoList->pNext;\n', |
| 859 | ' while (NULL != pNext)\n', ' {\n', |
| 860 | ' switch(pNext->sType)\n', ' {\n', |
| 861 | ' case XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO:\n', |
| 862 | ' {\n' , |
| 863 | ' void** ppNextVoidPtr = (void**)&pNext->pNext;\n', |
| 864 | ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n', |
| 865 | ' break;\n', |
| 866 | ' }\n', |
| 867 | ' default:\n', |
| 868 | ' {\n', |
| 869 | ' glv_LogError("Encountered an unexpected type in descriptor set layout create list.\\n");\n', |
| 870 | ' pPacket->header = NULL;\n', |
| 871 | ' pNext->pNext = NULL;\n', |
| 872 | ' }\n', |
Jon Ashburn | 7fd7eff | 2015-02-04 10:55:47 -0700 | [diff] [blame] | 873 | ' }\n', |
Peter Lohrmann | 7810957 | 2015-03-10 15:30:36 -0700 | [diff] [blame] | 874 | ' pNext = (XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO*)pNext->pNext;\n', |
| 875 | ' }\n', |
| 876 | '} else {\n', |
| 877 | ' // This is unexpected.\n', |
| 878 | ' glv_LogError("CreateDescriptorSetLayout must have LayoutInfoList stype of XGL_STRCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO\\n");\n', |
| 879 | ' pPacket->header = NULL;\n', |
Jon Ashburn | 7fd7eff | 2015-02-04 10:55:47 -0700 | [diff] [blame] | 880 | '}']}, |
Peter Lohrmann | 7810957 | 2015-03-10 15:30:36 -0700 | [diff] [blame] | 881 | 'BeginCommandBuffer' : {'param': 'pBeginInfo', 'txt': ['if (pPacket->pBeginInfo->sType == XGL_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO) {\n', |
| 882 | ' // need to make a non-const pointer to the pointer so that we can properly change the original pointer to the interpretted one\n', |
| 883 | ' XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO** ppNext = (XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO**)&(pPacket->pBeginInfo->pNext);\n', |
| 884 | ' *ppNext = (XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pBeginInfo->pNext);\n', |
| 885 | ' XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO* pNext = *ppNext;\n', |
| 886 | ' while (NULL != pNext)\n', ' {\n', |
| 887 | ' switch(pNext->sType)\n', ' {\n', |
| 888 | ' case XGL_STRUCTURE_TYPE_CMD_BUFFER_GRAPHICS_BEGIN_INFO:\n', |
| 889 | ' {\n', |
| 890 | ' ppNext = (XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO**) &pNext->pNext;\n', |
| 891 | ' *ppNext = (XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n', |
| 892 | ' break;\n', |
| 893 | ' }\n', |
| 894 | ' default:\n', |
| 895 | ' {\n', |
| 896 | ' glv_LogError("Encountered an unexpected type in begin command buffer list.\\n");\n', |
| 897 | ' pPacket->header = NULL;\n', |
| 898 | ' pNext->pNext = NULL;\n', |
| 899 | ' }\n', |
Jon Ashburn | a02bc24 | 2015-01-02 18:28:26 -0700 | [diff] [blame] | 900 | ' }\n', |
Peter Lohrmann | 7810957 | 2015-03-10 15:30:36 -0700 | [diff] [blame] | 901 | ' pNext = (XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO*)pNext->pNext;\n', |
Jon Ashburn | a02bc24 | 2015-01-02 18:28:26 -0700 | [diff] [blame] | 902 | ' }\n', |
Peter Lohrmann | 7810957 | 2015-03-10 15:30:36 -0700 | [diff] [blame] | 903 | '} else {\n', |
| 904 | ' // This is unexpected.\n', |
| 905 | ' glv_LogError("BeginCommandBuffer must have BeginInfo stype of XGL_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO.\\n");\n', |
| 906 | ' pPacket->header = NULL;\n', |
Jon Ashburn | a02bc24 | 2015-01-02 18:28:26 -0700 | [diff] [blame] | 907 | '}']}, |
Peter Lohrmann | 7810957 | 2015-03-10 15:30:36 -0700 | [diff] [blame] | 908 | 'AllocMemory' : {'param': 'pAllocInfo', 'txt': ['if (pPacket->pAllocInfo->sType == XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO) {\n', |
| 909 | ' XGL_MEMORY_ALLOC_INFO** ppNext = (XGL_MEMORY_ALLOC_INFO**) &(pPacket->pAllocInfo->pNext);\n', |
| 910 | ' *ppNext = (XGL_MEMORY_ALLOC_INFO*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pAllocInfo->pNext);\n', |
| 911 | ' XGL_MEMORY_ALLOC_INFO* pNext = (XGL_MEMORY_ALLOC_INFO*) *ppNext;\n', |
| 912 | ' while (NULL != pNext)\n', ' {\n', |
| 913 | ' switch(pNext->sType)\n', ' {\n', |
| 914 | ' case XGL_STRUCTURE_TYPE_MEMORY_ALLOC_BUFFER_INFO:\n', |
| 915 | ' case XGL_STRUCTURE_TYPE_MEMORY_ALLOC_IMAGE_INFO:\n', |
| 916 | ' {\n', |
| 917 | ' ppNext = (XGL_MEMORY_ALLOC_INFO **) &(pNext->pNext);\n', |
| 918 | ' *ppNext = (XGL_MEMORY_ALLOC_INFO*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n', |
| 919 | ' break;\n', |
| 920 | ' }\n', |
| 921 | ' default:\n', |
| 922 | ' {\n', |
| 923 | ' glv_LogError("Encountered an unexpected type alloc memory list.\\n");\n', |
| 924 | ' pPacket->header = NULL;\n', |
| 925 | ' pNext->pNext = NULL;\n', |
| 926 | ' }\n', |
Jon Ashburn | 3039e9c | 2015-02-03 07:33:48 -0700 | [diff] [blame] | 927 | ' }\n', |
Peter Lohrmann | 7810957 | 2015-03-10 15:30:36 -0700 | [diff] [blame] | 928 | ' pNext = (XGL_MEMORY_ALLOC_INFO*)pNext->pNext;\n', |
Jon Ashburn | 3039e9c | 2015-02-03 07:33:48 -0700 | [diff] [blame] | 929 | ' }\n', |
Peter Lohrmann | 7810957 | 2015-03-10 15:30:36 -0700 | [diff] [blame] | 930 | '} else {\n', |
| 931 | ' // This is unexpected.\n', |
| 932 | ' glv_LogError("AllocMemory must have AllocInfo stype of XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO.\\n");\n', |
| 933 | ' pPacket->header = NULL;\n', |
Jon Ashburn | 3039e9c | 2015-02-03 07:33:48 -0700 | [diff] [blame] | 934 | '}']}, |
Tobin Ehlis | 9570fc4 | 2015-02-04 10:53:31 -0700 | [diff] [blame] | 935 | 'UpdateDescriptors' : {'param': 'pUpdateChain', 'txt': ['XGL_UPDATE_SAMPLERS* pNext = (XGL_UPDATE_SAMPLERS*)pPacket->pUpdateChain;\n', |
| 936 | 'while ((NULL != pNext) && (XGL_NULL_HANDLE != pNext))\n', '{\n', |
| 937 | ' switch(pNext->sType)\n', ' {\n', |
| 938 | ' case XGL_STRUCTURE_TYPE_UPDATE_AS_COPY:\n', |
| 939 | ' {\n', |
| 940 | ' void** ppNextVoidPtr = (void**)&pNext->pNext;\n', |
| 941 | ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n', |
| 942 | ' break;\n', |
| 943 | ' }\n', |
| 944 | ' case XGL_STRUCTURE_TYPE_UPDATE_SAMPLERS:\n', |
| 945 | ' {\n', |
| 946 | ' void** ppNextVoidPtr = (void**)&pNext->pNext;\n', |
| 947 | ' XGL_UPDATE_SAMPLERS* pUS = (XGL_UPDATE_SAMPLERS*)pNext;\n', |
| 948 | ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n', |
| 949 | ' pUS->pSamplers = (XGL_SAMPLER*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pUS->pSamplers);\n', |
| 950 | ' break;\n', |
| 951 | ' }\n', |
| 952 | ' case XGL_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:\n', |
| 953 | ' {\n', |
| 954 | ' void** ppNextVoidPtr = (void**)&pNext->pNext;\n', |
| 955 | ' XGL_UPDATE_SAMPLER_TEXTURES* pUST = (XGL_UPDATE_SAMPLER_TEXTURES*)pNext;\n', |
| 956 | ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n', |
| 957 | ' pUST->pSamplerImageViews = (XGL_SAMPLER_IMAGE_VIEW_INFO*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pUST->pSamplerImageViews);\n', |
| 958 | ' uint32_t i;\n', |
| 959 | ' for (i = 0; i < pUST->count; i++) {\n', |
| 960 | ' XGL_IMAGE_VIEW_ATTACH_INFO** ppLocalImageView = (XGL_IMAGE_VIEW_ATTACH_INFO**)&pUST->pSamplerImageViews[i].pImageView;\n', |
| 961 | ' *ppLocalImageView = (XGL_IMAGE_VIEW_ATTACH_INFO*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pUST->pSamplerImageViews[i].pImageView);\n', |
| 962 | ' }\n', |
| 963 | ' break;\n', |
| 964 | ' }\n', |
| 965 | ' case XGL_STRUCTURE_TYPE_UPDATE_IMAGES:\n', |
| 966 | ' {\n', |
| 967 | ' void** ppNextVoidPtr = (void**)&pNext->pNext;\n', |
| 968 | ' XGL_UPDATE_IMAGES* pUI = (XGL_UPDATE_IMAGES*)pNext;\n', |
| 969 | ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n', |
Jon Ashburn | 755ad03 | 2015-02-04 16:26:30 -0700 | [diff] [blame] | 970 | ' XGL_IMAGE_VIEW_ATTACH_INFO** ppLocalImageView = (XGL_IMAGE_VIEW_ATTACH_INFO**)&pUI->pImageViews;\n', |
| 971 | ' *ppLocalImageView = (XGL_IMAGE_VIEW_ATTACH_INFO*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pUI->pImageViews);\n', |
| 972 | ' uint32_t i;\n', |
| 973 | ' for (i = 0; i < pUI->count; i++) {\n', |
| 974 | ' XGL_IMAGE_VIEW_ATTACH_INFO** ppLocalImageViews = (XGL_IMAGE_VIEW_ATTACH_INFO**)&pUI->pImageViews[i];\n', |
| 975 | ' *ppLocalImageViews = (XGL_IMAGE_VIEW_ATTACH_INFO*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pUI->pImageViews[i]);\n', |
| 976 | ' }\n', |
Tobin Ehlis | 9570fc4 | 2015-02-04 10:53:31 -0700 | [diff] [blame] | 977 | ' break;\n', |
| 978 | ' }\n', |
| 979 | ' case XGL_STRUCTURE_TYPE_UPDATE_BUFFERS:\n', |
| 980 | ' {\n', |
| 981 | ' void** ppNextVoidPtr = (void**)&pNext->pNext;\n', |
| 982 | ' XGL_UPDATE_BUFFERS* pUB = (XGL_UPDATE_BUFFERS*)pNext;\n', |
| 983 | ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n', |
Jon Ashburn | 755ad03 | 2015-02-04 16:26:30 -0700 | [diff] [blame] | 984 | ' XGL_BUFFER_VIEW_ATTACH_INFO** ppLocalBufferView = (XGL_BUFFER_VIEW_ATTACH_INFO**)&pUB->pBufferViews;\n', |
| 985 | ' *ppLocalBufferView = (XGL_BUFFER_VIEW_ATTACH_INFO*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pUB->pBufferViews);\n', |
| 986 | ' uint32_t i;\n', |
| 987 | ' for (i = 0; i < pUB->count; i++) {\n', |
| 988 | ' XGL_BUFFER_VIEW_ATTACH_INFO** ppLocalBufferViews = (XGL_BUFFER_VIEW_ATTACH_INFO**)&pUB->pBufferViews[i];\n', |
| 989 | ' *ppLocalBufferViews = (XGL_BUFFER_VIEW_ATTACH_INFO*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pUB->pBufferViews[i]);\n', |
| 990 | ' }\n', |
Tobin Ehlis | 9570fc4 | 2015-02-04 10:53:31 -0700 | [diff] [blame] | 991 | ' break;\n', |
| 992 | ' }\n', |
| 993 | ' default:\n', |
Peter Lohrmann | 7810957 | 2015-03-10 15:30:36 -0700 | [diff] [blame] | 994 | ' {\n', |
| 995 | ' glv_LogError("Encountered an unexpected type in update descriptors pUpdateChain.\\n");\n', |
| 996 | ' pPacket->header = NULL;\n', |
| 997 | ' pNext->pNext = NULL;\n', |
| 998 | ' }\n', |
Tobin Ehlis | 9570fc4 | 2015-02-04 10:53:31 -0700 | [diff] [blame] | 999 | ' }\n', |
| 1000 | ' pNext = (XGL_UPDATE_SAMPLERS*)pNext->pNext;\n', |
| 1001 | '}']}, |
Peter Lohrmann | 7810957 | 2015-03-10 15:30:36 -0700 | [diff] [blame] | 1002 | 'CreateGraphicsPipeline' : {'param': 'pCreateInfo', 'txt': ['if (pPacket->pCreateInfo->sType == XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO) {\n', |
| 1003 | ' // need to make a non-const pointer to the pointer so that we can properly change the original pointer to the interpretted one\n', |
| 1004 | ' void** ppNextVoidPtr = (void**)&pPacket->pCreateInfo->pNext;\n', |
| 1005 | ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pCreateInfo->pNext);\n', |
| 1006 | ' XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* pNext = (XGL_PIPELINE_SHADER_STAGE_CREATE_INFO*)pPacket->pCreateInfo->pNext;\n', |
| 1007 | ' while ((NULL != pNext) && (XGL_NULL_HANDLE != pNext))\n', '{\n', |
| 1008 | ' switch(pNext->sType)\n', ' {\n', |
| 1009 | ' case XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO:\n', |
| 1010 | ' case XGL_STRUCTURE_TYPE_PIPELINE_TESS_STATE_CREATE_INFO:\n', |
| 1011 | ' case XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO:\n', |
| 1012 | ' case XGL_STRUCTURE_TYPE_PIPELINE_VP_STATE_CREATE_INFO:\n', |
| 1013 | ' case XGL_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO:\n', |
| 1014 | ' case XGL_STRUCTURE_TYPE_PIPELINE_DS_STATE_CREATE_INFO:\n', |
| 1015 | ' {\n', |
| 1016 | ' void** ppNextVoidPtr = (void**)&pNext->pNext;\n', |
| 1017 | ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n', |
| 1018 | ' break;\n', |
| 1019 | ' }\n', |
| 1020 | ' case XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO:\n', |
| 1021 | ' {\n', |
| 1022 | ' void** ppNextVoidPtr = (void**)&pNext->pNext;\n', |
| 1023 | ' XGL_PIPELINE_CB_STATE_CREATE_INFO *pCb = (XGL_PIPELINE_CB_STATE_CREATE_INFO *) pNext;\n', |
| 1024 | ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n', |
| 1025 | ' pCb->pAttachments = (XGL_PIPELINE_CB_ATTACHMENT_STATE*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pCb->pAttachments);\n', |
| 1026 | ' break;\n', |
| 1027 | ' }\n', |
| 1028 | ' case XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO:\n', |
| 1029 | ' {\n', |
| 1030 | ' void** ppNextVoidPtr = (void**)&pNext->pNext;\n', |
| 1031 | ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n', |
| 1032 | ' interpret_pipeline_shader(pHeader, &pNext->shader);\n', |
| 1033 | ' break;\n', |
| 1034 | ' }\n', |
| 1035 | ' case XGL_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO:\n', |
| 1036 | ' {\n', |
| 1037 | ' void** ppNextVoidPtr = (void**)&pNext->pNext;\n', |
| 1038 | ' XGL_PIPELINE_VERTEX_INPUT_CREATE_INFO *pVi = (XGL_PIPELINE_VERTEX_INPUT_CREATE_INFO *) pNext;\n', |
| 1039 | ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n', |
| 1040 | ' pVi->pVertexBindingDescriptions = (XGL_VERTEX_INPUT_BINDING_DESCRIPTION*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pVi->pVertexBindingDescriptions);\n', |
| 1041 | ' pVi->pVertexAttributeDescriptions = (XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pVi->pVertexAttributeDescriptions);\n', |
| 1042 | ' break;\n', |
| 1043 | ' }\n', |
| 1044 | ' default:\n', |
| 1045 | ' {\n', |
| 1046 | ' glv_LogError("Encountered an unexpected type in pipeline state list.\\n");\n', |
| 1047 | ' pPacket->header = NULL;\n', |
| 1048 | ' pNext->pNext = NULL;\n', |
| 1049 | ' }\n', |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1050 | ' }\n', |
Peter Lohrmann | 7810957 | 2015-03-10 15:30:36 -0700 | [diff] [blame] | 1051 | ' pNext = (XGL_PIPELINE_SHADER_STAGE_CREATE_INFO*)pNext->pNext;\n', |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1052 | ' }\n', |
Peter Lohrmann | 7810957 | 2015-03-10 15:30:36 -0700 | [diff] [blame] | 1053 | '} else {\n', |
| 1054 | ' // This is unexpected.\n', |
| 1055 | ' glv_LogError("CreateGraphicsPipeline must have CreateInfo stype of XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO.\\n");\n', |
| 1056 | ' pPacket->header = NULL;\n', |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1057 | '}']}, |
Tobin Ehlis | 45bc7f8 | 2015-01-16 15:13:34 -0700 | [diff] [blame] | 1058 | 'CreateComputePipeline' : {'param': 'pCreateInfo', 'txt': ['interpret_pipeline_shader(pHeader, (XGL_PIPELINE_SHADER*)(&pPacket->pCreateInfo->cs));']}} |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1059 | if_body = [] |
Jon Ashburn | e224839 | 2014-12-16 18:37:04 -0700 | [diff] [blame] | 1060 | if_body.append('typedef struct struct_xglApiVersion {') |
| 1061 | if_body.append(' glv_trace_packet_header* header;') |
| 1062 | if_body.append(' uint32_t version;') |
| 1063 | if_body.append('} struct_xglApiVersion;\n') |
| 1064 | if_body.append('static struct_xglApiVersion* interpret_body_as_xglApiVersion(glv_trace_packet_header* pHeader, BOOL check_version)') |
| 1065 | if_body.append('{') |
| 1066 | if_body.append(' struct_xglApiVersion* pPacket = (struct_xglApiVersion*)pHeader->pBody;') |
| 1067 | if_body.append(' pPacket->header = pHeader;') |
| 1068 | if_body.append(' if (check_version && pPacket->version != XGL_API_VERSION)') |
| 1069 | if_body.append(' glv_LogError("Trace file from older XGL version 0x%x, xgl replayer built from version 0x%x, replayer may fail\\n", pPacket->version, XGL_API_VERSION);') |
| 1070 | if_body.append(' return pPacket;') |
| 1071 | if_body.append('}\n') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1072 | for proto in self.protos: |
| 1073 | if 'Wsi' not in proto.name and 'Dbg' not in proto.name: |
| 1074 | if 'UnmapMemory' == proto.name: |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1075 | proto.params.append(xgl.Param("void*", "pData")) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1076 | if_body.append('typedef struct struct_xgl%s {' % proto.name) |
| 1077 | if_body.append(' glv_trace_packet_header* header;') |
| 1078 | for p in proto.params: |
| 1079 | if '[4]' in p.ty: |
| 1080 | if_body.append(' %s %s[4];' % (p.ty.strip('[4]'), p.name)) |
| 1081 | else: |
| 1082 | if_body.append(' %s %s;' % (p.ty, p.name)) |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1083 | if 'void' != proto.ret: |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1084 | if_body.append(' %s result;' % proto.ret) |
| 1085 | if_body.append('} struct_xgl%s;\n' % proto.name) |
| 1086 | if_body.append('static struct_xgl%s* interpret_body_as_xgl%s(glv_trace_packet_header* pHeader)' % (proto.name, proto.name)) |
| 1087 | if_body.append('{') |
| 1088 | if_body.append(' struct_xgl%s* pPacket = (struct_xgl%s*)pHeader->pBody;' % (proto.name, proto.name)) |
| 1089 | if_body.append(' pPacket->header = pHeader;') |
| 1090 | for p in proto.params: |
| 1091 | if '*' in p.ty: |
| 1092 | if 'DEVICE_CREATE_INFO' in p.ty: |
| 1093 | if_body.append(' pPacket->%s = interpret_XGL_DEVICE_CREATE_INFO(pHeader, (intptr_t)pPacket->%s);' % (p.name, p.name)) |
| 1094 | else: |
| 1095 | if_body.append(' pPacket->%s = (%s)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->%s);' % (p.name, p.ty, p.name)) |
Tobin Ehlis | 81b1b3d | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 1096 | # TODO : Generalize this custom code to kill dict data struct above. |
| 1097 | # Really the point of this block is to catch params w/ embedded ptrs to structs and chains of structs |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1098 | if proto.name in custom_case_dict and p.name == custom_case_dict[proto.name]['param']: |
| 1099 | if_body.append(' if (pPacket->%s != NULL)' % custom_case_dict[proto.name]['param']) |
| 1100 | if_body.append(' {') |
| 1101 | if_body.append(' %s' % " ".join(custom_case_dict[proto.name]['txt'])) |
| 1102 | if_body.append(' }') |
| 1103 | if_body.append(' return pPacket;') |
| 1104 | if_body.append('}\n') |
| 1105 | return "\n".join(if_body) |
| 1106 | |
| 1107 | def _generate_interp_funcs_ext(self, func_class='Wsi'): |
| 1108 | if_body = [] |
| 1109 | for proto in self.protos: |
| 1110 | if func_class in proto.name: |
| 1111 | if_body.append('typedef struct struct_xgl%s {' % proto.name) |
| 1112 | if_body.append(' glv_trace_packet_header* pHeader;') |
| 1113 | for p in proto.params: |
| 1114 | if_body.append(' %s %s;' % (p.ty, p.name)) |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1115 | if 'void' != proto.ret: |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1116 | if_body.append(' %s result;' % proto.ret) |
| 1117 | if_body.append('} struct_xgl%s;\n' % proto.name) |
| 1118 | if_body.append('static struct_xgl%s* interpret_body_as_xgl%s(glv_trace_packet_header* pHeader)' % (proto.name, proto.name)) |
| 1119 | if_body.append('{') |
| 1120 | if_body.append(' struct_xgl%s* pPacket = (struct_xgl%s*)pHeader->pBody;' % (proto.name, proto.name)) |
| 1121 | if_body.append(' pPacket->pHeader = pHeader;') |
| 1122 | for p in proto.params: |
| 1123 | if '*' in p.ty: |
| 1124 | if_body.append(' pPacket->%s = (%s)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->%s);' % (p.name, p.ty, p.name)) |
| 1125 | if_body.append(' return pPacket;') |
| 1126 | if_body.append('}\n') |
| 1127 | return "\n".join(if_body) |
| 1128 | |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1129 | def _generate_replay_func_ptrs(self): |
| 1130 | xf_body = [] |
| 1131 | xf_body.append('struct xglFuncs {') |
| 1132 | xf_body.append(' void init_funcs(void * libHandle);') |
| 1133 | xf_body.append(' void *m_libHandle;\n') |
| 1134 | for proto in self.protos: |
| 1135 | xf_body.append(' typedef %s( XGLAPI * type_xgl%s)(' % (proto.ret, proto.name)) |
| 1136 | for p in proto.params: |
| 1137 | if '[4]' in p.ty: |
| 1138 | xf_body.append(' %s %s[4],' % (p.ty.strip('[4]'), p.name)) |
| 1139 | else: |
| 1140 | xf_body.append(' %s %s,' % (p.ty, p.name)) |
| 1141 | xf_body[-1] = xf_body[-1].replace(',', ');') |
| 1142 | xf_body.append(' type_xgl%s real_xgl%s;' % (proto.name, proto.name)) |
| 1143 | xf_body.append('};') |
| 1144 | return "\n".join(xf_body) |
| 1145 | |
| 1146 | def _map_decl(self, type1, type2, name): |
| 1147 | return ' std::map<%s, %s> %s;' % (type1, type2, name) |
| 1148 | |
| 1149 | def _add_to_map_decl(self, type1, type2, name): |
| 1150 | txt = ' void add_to_map(%s* pTraceVal, %s* pReplayVal)\n {\n' % (type1, type2) |
| 1151 | txt += ' assert(pTraceVal != NULL);\n' |
| 1152 | txt += ' assert(pReplayVal != NULL);\n' |
Jon Ashburn | 7f8acc7 | 2015-03-23 09:27:33 -0600 | [diff] [blame] | 1153 | txt += ' %s[*pTraceVal] = *pReplayVal;\n }\n' % name |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1154 | return txt |
| 1155 | |
| 1156 | def _rm_from_map_decl(self, ty, name): |
| 1157 | txt = ' void rm_from_map(const %s& key)\n {\n' % (ty) |
Jon Ashburn | 7f8acc7 | 2015-03-23 09:27:33 -0600 | [diff] [blame] | 1158 | txt += ' %s.erase(key);\n }\n' % name |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1159 | return txt |
| 1160 | |
| 1161 | def _remap_decl(self, ty, name): |
| 1162 | txt = ' %s remap(const %s& value)\n {\n' % (ty, ty) |
| 1163 | txt += ' std::map<%s, %s>::const_iterator q = %s.find(value);\n' % (ty, ty, name) |
Jon Ashburn | 7f8acc7 | 2015-03-23 09:27:33 -0600 | [diff] [blame] | 1164 | txt += ' return (q == %s.end()) ? XGL_NULL_HANDLE : q->second;\n }\n' % name |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1165 | return txt |
| 1166 | |
Peter Lohrmann | e59ba28 | 2015-04-06 14:14:44 -0700 | [diff] [blame] | 1167 | def _generate_replay_objMemory_funcs(self): |
| 1168 | rof_body = [] |
| 1169 | # Custom code for memory mapping functions for app writes into mapped memory |
| 1170 | rof_body.append('// memory mapping functions for app writes into mapped memory') |
| 1171 | rof_body.append(' bool isPendingAlloc()') |
| 1172 | rof_body.append(' {') |
| 1173 | rof_body.append(' return m_pendingAlloc;') |
| 1174 | rof_body.append(' }') |
| 1175 | rof_body.append('') |
| 1176 | rof_body.append(' void setAllocInfo(const XGL_MEMORY_ALLOC_INFO *info, const bool pending)') |
| 1177 | rof_body.append(' {') |
| 1178 | rof_body.append(' m_pendingAlloc = pending;') |
| 1179 | rof_body.append(' m_allocInfo = *info;') |
| 1180 | rof_body.append(' }') |
| 1181 | rof_body.append('') |
| 1182 | rof_body.append(' void setMemoryDataAddr(void *pBuf)') |
| 1183 | rof_body.append(' {') |
| 1184 | rof_body.append(' if (m_mapRange.empty())') |
| 1185 | rof_body.append(' {') |
| 1186 | rof_body.append(' glv_LogError("gpuMemory::setMemoryDataAddr() m_mapRange is empty\\n");') |
| 1187 | rof_body.append(' return;') |
| 1188 | rof_body.append(' }') |
| 1189 | rof_body.append(' MapRange mr = m_mapRange.back();') |
| 1190 | rof_body.append(' if (mr.pData != NULL)') |
| 1191 | rof_body.append(' glv_LogWarn("gpuMemory::setMemoryDataAddr() data already mapped overwrite old mapping\\n");') |
| 1192 | rof_body.append(' else if (pBuf == NULL)') |
| 1193 | rof_body.append(' glv_LogWarn("gpuMemory::setMemoryDataAddr() adding NULL pointer\\n");') |
| 1194 | rof_body.append(' mr.pData = pBuf;') |
| 1195 | rof_body.append(' }') |
| 1196 | rof_body.append('') |
| 1197 | rof_body.append(' void setMemoryMapRange(void *pBuf, const size_t size, const size_t offset, const bool pending)') |
| 1198 | rof_body.append(' {') |
| 1199 | rof_body.append(' MapRange mr;') |
| 1200 | rof_body.append(' mr.pData = pBuf;') |
| 1201 | rof_body.append(' mr.size = size;') |
| 1202 | rof_body.append(' mr.offset = offset;') |
| 1203 | rof_body.append(' mr.pending = pending;') |
| 1204 | rof_body.append(' m_mapRange.push_back(mr);') |
| 1205 | rof_body.append(' }') |
| 1206 | rof_body.append('') |
| 1207 | rof_body.append(' void copyMappingData(const void* pSrcData)') |
| 1208 | rof_body.append(' {') |
| 1209 | rof_body.append(' if (m_mapRange.empty())') |
| 1210 | rof_body.append(' {') |
| 1211 | rof_body.append(' glv_LogError("gpuMemory::copyMappingData() m_mapRange is empty\\n");') |
| 1212 | rof_body.append(' return;') |
| 1213 | rof_body.append(' }') |
| 1214 | rof_body.append(' MapRange mr = m_mapRange.back();') |
| 1215 | rof_body.append(' if (!pSrcData || !mr.pData)') |
| 1216 | rof_body.append(' {') |
| 1217 | rof_body.append(' if (!pSrcData)') |
| 1218 | rof_body.append(' glv_LogError("gpuMemory::copyMappingData() null src pointer\\n");') |
| 1219 | rof_body.append(' else') |
| 1220 | rof_body.append(' glv_LogError("gpuMemory::copyMappingData() null dest pointer size=%u\\n", m_allocInfo.allocationSize);') |
| 1221 | rof_body.append(' m_mapRange.pop_back();') |
| 1222 | rof_body.append(' return;') |
| 1223 | rof_body.append(' }') |
| 1224 | rof_body.append(' memcpy(mr.pData, pSrcData, m_allocInfo.allocationSize);') |
| 1225 | rof_body.append(' if (!mr.pending)') |
| 1226 | rof_body.append(' m_mapRange.pop_back();') |
| 1227 | rof_body.append(' }') |
| 1228 | rof_body.append('') |
| 1229 | rof_body.append(' size_t getMemoryMapSize()') |
| 1230 | rof_body.append(' {') |
| 1231 | rof_body.append(' return (!m_mapRange.empty()) ? m_mapRange.back().size : 0;') |
| 1232 | rof_body.append(' }\n') |
| 1233 | return "\n".join(rof_body) |
| 1234 | |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1235 | def _generate_replay_objmapper_class(self): |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 1236 | # Create dict mapping member var names to XGL type (i.e. 'm_imageViews' : 'XGL_IMAGE_VIEW') |
| 1237 | obj_map_dict = {} |
| 1238 | for ty in xgl.object_type_list: |
| 1239 | if ty in xgl.object_parent_list: |
| 1240 | continue |
| 1241 | mem_var = ty.replace('XGL_', '').lower() |
| 1242 | mem_var_list = mem_var.split('_') |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 1243 | mem_var = 'm_%s%ss' % (mem_var_list[0], "".join([m.title() for m in mem_var_list[1:]])) |
| 1244 | obj_map_dict[mem_var] = ty |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1245 | rc_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1246 | rc_body.append('typedef struct _XGLAllocInfo {') |
| 1247 | rc_body.append(' XGL_GPU_SIZE size;') |
| 1248 | rc_body.append(' void *pData;') |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1249 | rc_body.append('} XGLAllocInfo;') |
| 1250 | rc_body.append('') |
Peter Lohrmann | e59ba28 | 2015-04-06 14:14:44 -0700 | [diff] [blame] | 1251 | rc_body.append('class objMemory {') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1252 | rc_body.append('public:') |
Peter Lohrmann | e59ba28 | 2015-04-06 14:14:44 -0700 | [diff] [blame] | 1253 | rc_body.append(' objMemory() : m_numAllocations(0), m_pMemReqs(NULL) {}') |
| 1254 | rc_body.append(' ~objMemory() { free(m_pMemReqs);}') |
| 1255 | rc_body.append(' void setCount(const uint32_t num)') |
| 1256 | rc_body.append(' {') |
| 1257 | rc_body.append(' m_numAllocations = num;') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1258 | rc_body.append(' }\n') |
Peter Lohrmann | e59ba28 | 2015-04-06 14:14:44 -0700 | [diff] [blame] | 1259 | rc_body.append(' void setReqs(const XGL_MEMORY_REQUIREMENTS *pReqs, const uint32_t num)') |
| 1260 | rc_body.append(' {') |
| 1261 | rc_body.append(' if (m_numAllocations != num && m_numAllocations != 0)') |
| 1262 | rc_body.append(' glv_LogError("objMemory::setReqs, internal mismatch on number of allocations");') |
| 1263 | rc_body.append(' if (m_pMemReqs == NULL && pReqs != NULL)') |
| 1264 | rc_body.append(' {') |
| 1265 | rc_body.append(' m_pMemReqs = (XGL_MEMORY_REQUIREMENTS *) glv_malloc(num * sizeof(XGL_MEMORY_REQUIREMENTS));') |
| 1266 | rc_body.append(' if (m_pMemReqs == NULL)') |
| 1267 | rc_body.append(' {') |
| 1268 | rc_body.append(' glv_LogError("objMemory::setReqs out of memory");') |
| 1269 | rc_body.append(' return;') |
| 1270 | rc_body.append(' }') |
| 1271 | rc_body.append(' memcpy(m_pMemReqs, pReqs, num);') |
| 1272 | rc_body.append(' }') |
| 1273 | rc_body.append(' }\n') |
| 1274 | rc_body.append('private:') |
| 1275 | rc_body.append(' uint32_t m_numAllocations;') |
| 1276 | rc_body.append(' XGL_MEMORY_REQUIREMENTS *m_pMemReqs;') |
| 1277 | rc_body.append('};') |
| 1278 | rc_body.append('') |
| 1279 | rc_body.append('class gpuMemory {') |
| 1280 | rc_body.append('public:') |
| 1281 | rc_body.append(' gpuMemory() : m_pendingAlloc(false) {m_allocInfo.allocationSize = 0;}') |
| 1282 | rc_body.append(' ~gpuMemory() {}') |
| 1283 | rc_body.append(self._generate_replay_objMemory_funcs()) |
| 1284 | # rc_body.append(' bool isPendingAlloc();') |
| 1285 | # rc_body.append(' void setAllocInfo(const XGL_MEMORY_ALLOC_INFO *info, const bool pending);') |
| 1286 | # rc_body.append(' void setMemoryDataAddr(void* pBuf);') |
| 1287 | # rc_body.append(' void setMemoryMapRange(void* pBuf, const size_t size, const size_t offset, const bool pending);') |
| 1288 | # rc_body.append(' void copyMappingData(const void *pSrcData);') |
| 1289 | # rc_body.append(' size_t getMemoryMapSize();') |
| 1290 | rc_body.append('private:') |
| 1291 | rc_body.append(' bool m_pendingAlloc;') |
| 1292 | rc_body.append(' struct MapRange {') |
| 1293 | rc_body.append(' bool pending;') |
| 1294 | rc_body.append(' size_t size;') |
| 1295 | rc_body.append(' size_t offset;') |
| 1296 | rc_body.append(' void* pData;') |
| 1297 | rc_body.append(' };') |
| 1298 | rc_body.append(' std::vector<MapRange> m_mapRange;') |
| 1299 | rc_body.append(' XGL_MEMORY_ALLOC_INFO m_allocInfo;') |
| 1300 | rc_body.append('};') |
| 1301 | rc_body.append('') |
| 1302 | rc_body.append('typedef struct _imageObj {') |
| 1303 | rc_body.append(' objMemory imageMem;') |
| 1304 | rc_body.append(' XGL_IMAGE replayImage;') |
| 1305 | rc_body.append(' } imageObj;') |
| 1306 | rc_body.append('') |
| 1307 | rc_body.append('typedef struct _bufferObj {') |
| 1308 | rc_body.append(' objMemory bufferMem;') |
| 1309 | rc_body.append(' XGL_BUFFER replayBuffer;') |
| 1310 | rc_body.append(' } bufferObj;') |
| 1311 | rc_body.append('') |
| 1312 | rc_body.append('typedef struct _gpuMemObj {') |
| 1313 | rc_body.append(' gpuMemory *pGpuMem;') |
| 1314 | rc_body.append(' XGL_GPU_MEMORY replayGpuMem;') |
| 1315 | rc_body.append(' } gpuMemObj;') |
| 1316 | rc_body.append('') |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1317 | rc_body.append('class xglReplayObjMapper {') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1318 | rc_body.append('public:') |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1319 | rc_body.append(' xglReplayObjMapper() {}') |
| 1320 | rc_body.append(' ~xglReplayObjMapper() {}') |
| 1321 | rc_body.append('') |
Peter Lohrmann | e59ba28 | 2015-04-06 14:14:44 -0700 | [diff] [blame] | 1322 | rc_body.append(' bool m_adjustForGPU; // true if replay adjusts behavior based on GPU') |
| 1323 | # Code for memory objects for handling replay GPU != trace GPU object memory requirements |
| 1324 | rc_body.append(' void init_objMemCount(const XGL_BASE_OBJECT& object, const uint32_t &num)\n {') |
| 1325 | rc_body.append(' XGL_IMAGE img = static_cast <XGL_IMAGE> (object);') |
| 1326 | rc_body.append(' std::map<XGL_IMAGE, imageObj>::const_iterator it = m_images.find(img);') |
| 1327 | rc_body.append(' if (it != m_images.end())') |
| 1328 | rc_body.append(' {') |
| 1329 | rc_body.append(' objMemory obj = it->second.imageMem;') |
| 1330 | rc_body.append(' obj.setCount(num);') |
| 1331 | rc_body.append(' return;') |
| 1332 | rc_body.append(' }') |
| 1333 | rc_body.append(' XGL_BUFFER buf = static_cast <XGL_BUFFER> (object);') |
| 1334 | rc_body.append(' std::map<XGL_BUFFER, bufferObj>::const_iterator itb = m_buffers.find(buf);') |
| 1335 | rc_body.append(' if (itb != m_buffers.end())') |
| 1336 | rc_body.append(' {') |
| 1337 | rc_body.append(' objMemory obj = itb->second.bufferMem;') |
| 1338 | rc_body.append(' obj.setCount(num);') |
| 1339 | rc_body.append(' return;') |
| 1340 | rc_body.append(' }') |
| 1341 | rc_body.append(' return;') |
| 1342 | rc_body.append(' }\n') |
Jon Ashburn | 7f8acc7 | 2015-03-23 09:27:33 -0600 | [diff] [blame] | 1343 | rc_body.append(' void init_objMemReqs(const XGL_BASE_OBJECT& object, const XGL_MEMORY_REQUIREMENTS *pMemReqs, const unsigned int num)\n {') |
| 1344 | rc_body.append(' XGL_IMAGE img = static_cast <XGL_IMAGE> (object);') |
Peter Lohrmann | e59ba28 | 2015-04-06 14:14:44 -0700 | [diff] [blame] | 1345 | rc_body.append(' std::map<XGL_IMAGE, imageObj>::const_iterator it = m_images.find(img);') |
Jon Ashburn | 7f8acc7 | 2015-03-23 09:27:33 -0600 | [diff] [blame] | 1346 | rc_body.append(' if (it != m_images.end())') |
| 1347 | rc_body.append(' {') |
| 1348 | rc_body.append(' objMemory obj = it->second.imageMem;') |
| 1349 | rc_body.append(' obj.setReqs(pMemReqs, num);') |
| 1350 | rc_body.append(' return;') |
| 1351 | rc_body.append(' }') |
| 1352 | rc_body.append(' XGL_BUFFER buf = static_cast <XGL_BUFFER> (object);') |
Peter Lohrmann | e59ba28 | 2015-04-06 14:14:44 -0700 | [diff] [blame] | 1353 | rc_body.append(' std::map<XGL_BUFFER, bufferObj>::const_iterator itb = m_buffers.find(buf);') |
Jon Ashburn | 7f8acc7 | 2015-03-23 09:27:33 -0600 | [diff] [blame] | 1354 | rc_body.append(' if (itb != m_buffers.end())') |
| 1355 | rc_body.append(' {') |
| 1356 | rc_body.append(' objMemory obj = itb->second.bufferMem;') |
| 1357 | rc_body.append(' obj.setReqs(pMemReqs, num);') |
| 1358 | rc_body.append(' return;') |
| 1359 | rc_body.append(' }') |
| 1360 | rc_body.append(' return;') |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1361 | rc_body.append(' }') |
| 1362 | rc_body.append('') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1363 | rc_body.append(' void clear_all_map_handles()\n {') |
| 1364 | for var in sorted(obj_map_dict): |
| 1365 | rc_body.append(' %s.clear();' % var) |
Jon Ashburn | 7f8acc7 | 2015-03-23 09:27:33 -0600 | [diff] [blame] | 1366 | rc_body.append(' }\n') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1367 | for var in sorted(obj_map_dict): |
Jon Ashburn | 7f8acc7 | 2015-03-23 09:27:33 -0600 | [diff] [blame] | 1368 | if obj_map_dict[var] == 'XGL_IMAGE': |
Peter Lohrmann | e59ba28 | 2015-04-06 14:14:44 -0700 | [diff] [blame] | 1369 | rc_body.append(self._map_decl(obj_map_dict[var], 'imageObj', var)) |
| 1370 | rc_body.append(self._add_to_map_decl(obj_map_dict[var], 'imageObj', var)) |
Jon Ashburn | 7f8acc7 | 2015-03-23 09:27:33 -0600 | [diff] [blame] | 1371 | rc_body.append(self._rm_from_map_decl(obj_map_dict[var], var)) |
| 1372 | rc_body.append(' XGL_IMAGE remap(const XGL_IMAGE& value)') |
| 1373 | rc_body.append(' {') |
Peter Lohrmann | e59ba28 | 2015-04-06 14:14:44 -0700 | [diff] [blame] | 1374 | rc_body.append(' std::map<XGL_IMAGE, imageObj>::const_iterator q = m_images.find(value);') |
Jon Ashburn | 7f8acc7 | 2015-03-23 09:27:33 -0600 | [diff] [blame] | 1375 | rc_body.append(' return (q == m_images.end()) ? XGL_NULL_HANDLE : q->second.replayImage;') |
| 1376 | rc_body.append(' }\n') |
| 1377 | elif obj_map_dict[var] == 'XGL_BUFFER': |
Peter Lohrmann | e59ba28 | 2015-04-06 14:14:44 -0700 | [diff] [blame] | 1378 | rc_body.append(self._map_decl(obj_map_dict[var], 'bufferObj', var)) |
| 1379 | rc_body.append(self._add_to_map_decl(obj_map_dict[var], 'bufferObj', var)) |
Jon Ashburn | 7f8acc7 | 2015-03-23 09:27:33 -0600 | [diff] [blame] | 1380 | rc_body.append(self._rm_from_map_decl(obj_map_dict[var], var)) |
| 1381 | rc_body.append(' XGL_BUFFER remap(const XGL_BUFFER& value)') |
| 1382 | rc_body.append(' {') |
Peter Lohrmann | e59ba28 | 2015-04-06 14:14:44 -0700 | [diff] [blame] | 1383 | rc_body.append(' std::map<XGL_BUFFER, bufferObj>::const_iterator q = m_buffers.find(value);') |
Jon Ashburn | 7f8acc7 | 2015-03-23 09:27:33 -0600 | [diff] [blame] | 1384 | rc_body.append(' return (q == m_buffers.end()) ? XGL_NULL_HANDLE : q->second.replayBuffer;') |
| 1385 | rc_body.append(' }\n') |
Jon Ashburn | 16239cd | 2015-03-24 11:05:02 -0600 | [diff] [blame] | 1386 | elif obj_map_dict[var] == 'XGL_GPU_MEMORY': |
Peter Lohrmann | e59ba28 | 2015-04-06 14:14:44 -0700 | [diff] [blame] | 1387 | rc_body.append(self._map_decl(obj_map_dict[var], 'gpuMemObj', var)) |
| 1388 | rc_body.append(self._add_to_map_decl(obj_map_dict[var], 'gpuMemObj', var)) |
Jon Ashburn | 16239cd | 2015-03-24 11:05:02 -0600 | [diff] [blame] | 1389 | rc_body.append(self._rm_from_map_decl(obj_map_dict[var], var)) |
| 1390 | rc_body.append(' XGL_GPU_MEMORY remap(const XGL_GPU_MEMORY& value)') |
| 1391 | rc_body.append(' {') |
Peter Lohrmann | e59ba28 | 2015-04-06 14:14:44 -0700 | [diff] [blame] | 1392 | rc_body.append(' std::map<XGL_GPU_MEMORY, gpuMemObj>::const_iterator q = m_gpuMemorys.find(value);') |
Jon Ashburn | 16239cd | 2015-03-24 11:05:02 -0600 | [diff] [blame] | 1393 | rc_body.append(' return (q == m_gpuMemorys.end()) ? XGL_NULL_HANDLE : q->second.replayGpuMem;') |
| 1394 | rc_body.append(' }\n') |
Jon Ashburn | 7f8acc7 | 2015-03-23 09:27:33 -0600 | [diff] [blame] | 1395 | else: |
| 1396 | rc_body.append(self._map_decl(obj_map_dict[var], obj_map_dict[var], var)) |
| 1397 | rc_body.append(self._add_to_map_decl(obj_map_dict[var], obj_map_dict[var], var)) |
| 1398 | rc_body.append(self._rm_from_map_decl(obj_map_dict[var], var)) |
| 1399 | rc_body.append(self._remap_decl(obj_map_dict[var], var)) |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 1400 | # XGL_DYNAMIC_STATE_OBJECT code |
| 1401 | state_obj_remap_types = xgl.object_dynamic_state_list |
| 1402 | rc_body.append(' XGL_DYNAMIC_STATE_OBJECT remap(const XGL_DYNAMIC_STATE_OBJECT& state)\n {') |
| 1403 | rc_body.append(' XGL_DYNAMIC_STATE_OBJECT obj;') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1404 | for t in state_obj_remap_types: |
| 1405 | rc_body.append(' if ((obj = remap(static_cast <%s> (state))) != XGL_NULL_HANDLE)' % t) |
| 1406 | rc_body.append(' return obj;') |
| 1407 | rc_body.append(' return XGL_NULL_HANDLE;\n }') |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 1408 | rc_body.append(' void rm_from_map(const XGL_DYNAMIC_STATE_OBJECT& state)\n {') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1409 | for t in state_obj_remap_types: |
| 1410 | rc_body.append(' rm_from_map(static_cast <%s> (state));' % t) |
| 1411 | rc_body.append(' }') |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1412 | rc_body.append('') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1413 | # OBJECT code |
| 1414 | rc_body.append(' XGL_OBJECT remap(const XGL_OBJECT& object)\n {') |
| 1415 | rc_body.append(' XGL_OBJECT obj;') |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 1416 | obj_remap_types = xgl.object_list |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1417 | for var in obj_remap_types: |
| 1418 | rc_body.append(' if ((obj = remap(static_cast <%s> (object))) != XGL_NULL_HANDLE)' % (var)) |
| 1419 | rc_body.append(' return obj;') |
| 1420 | rc_body.append(' return XGL_NULL_HANDLE;\n }') |
| 1421 | rc_body.append(' void rm_from_map(const XGL_OBJECT & objKey)\n {') |
| 1422 | for var in obj_remap_types: |
| 1423 | rc_body.append(' rm_from_map(static_cast <%s> (objKey));' % (var)) |
| 1424 | rc_body.append(' }') |
| 1425 | rc_body.append(' XGL_BASE_OBJECT remap(const XGL_BASE_OBJECT& object)\n {') |
| 1426 | rc_body.append(' XGL_BASE_OBJECT obj;') |
| 1427 | base_obj_remap_types = ['XGL_DEVICE', 'XGL_QUEUE', 'XGL_GPU_MEMORY', 'XGL_OBJECT'] |
| 1428 | for t in base_obj_remap_types: |
| 1429 | rc_body.append(' if ((obj = remap(static_cast <%s> (object))) != XGL_NULL_HANDLE)' % t) |
| 1430 | rc_body.append(' return obj;') |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1431 | rc_body.append(' return XGL_NULL_HANDLE;') |
Tony Barbour | b30dcd4 | 2015-02-02 13:21:18 -0700 | [diff] [blame] | 1432 | rc_body.append(' }') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1433 | rc_body.append('};') |
| 1434 | return "\n".join(rc_body) |
| 1435 | |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1436 | def _generate_replay_init_funcs(self): |
| 1437 | rif_body = [] |
| 1438 | rif_body.append('void xglFuncs::init_funcs(void * handle)\n{\n m_libHandle = handle;') |
| 1439 | for proto in self.protos: |
| 1440 | rif_body.append(' real_xgl%s = (type_xgl%s)(glv_platform_get_library_entrypoint(handle, "xgl%s"));' % (proto.name, proto.name, proto.name)) |
| 1441 | rif_body.append('}') |
| 1442 | return "\n".join(rif_body) |
| 1443 | |
| 1444 | def _get_packet_param(self, t, n): |
| 1445 | # list of types that require remapping |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 1446 | remap_list = xgl.object_type_list |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 1447 | param_exclude_list = ['p1', 'p2', 'pGpus', 'pDescriptorSets'] |
| 1448 | if t.strip('*').replace('const ', '') in remap_list and n not in param_exclude_list: |
| 1449 | if '*' in t: |
| 1450 | if 'const ' not in t: |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1451 | return 'm_objMapper.remap(*pPacket->%s)' % (n) |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 1452 | else: # TODO : Don't remap array ptrs? |
| 1453 | return 'pPacket->%s' % (n) |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1454 | return 'm_objMapper.remap(pPacket->%s)' % (n) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1455 | return 'pPacket->%s' % (n) |
| 1456 | |
Tobin Ehlis | 45bc7f8 | 2015-01-16 15:13:34 -0700 | [diff] [blame] | 1457 | def _gen_replay_enum_gpus(self): |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1458 | ieg_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1459 | ieg_body.append(' returnValue = manually_handle_xglEnumerateGpus(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1460 | return "\n".join(ieg_body) |
| 1461 | |
| 1462 | def _gen_replay_get_gpu_info(self): |
| 1463 | ggi_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1464 | ggi_body.append(' returnValue = manually_handle_xglGetGpuInfo(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1465 | return "\n".join(ggi_body) |
| 1466 | |
| 1467 | def _gen_replay_create_device(self): |
| 1468 | cd_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1469 | cd_body.append(' returnValue = manually_handle_xglCreateDevice(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1470 | return "\n".join(cd_body) |
| 1471 | |
| 1472 | def _gen_replay_get_extension_support(self): |
| 1473 | ges_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1474 | ges_body.append(' returnValue = manually_handle_xglGetExtensionSupport(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1475 | return "\n".join(ges_body) |
| 1476 | |
| 1477 | def _gen_replay_queue_submit(self): |
| 1478 | qs_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1479 | qs_body.append(' returnValue = manually_handle_xglQueueSubmit(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1480 | return "\n".join(qs_body) |
| 1481 | |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1482 | def _gen_replay_get_object_info(self): |
| 1483 | goi_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1484 | goi_body.append(' returnValue = manually_handle_xglGetObjectInfo(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1485 | return "\n".join(goi_body) |
| 1486 | |
| 1487 | def _gen_replay_get_format_info(self): |
| 1488 | gfi_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1489 | gfi_body.append(' returnValue = manually_handle_xglGetFormatInfo(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1490 | return "\n".join(gfi_body) |
| 1491 | |
Jon Ashburn | 7f8acc7 | 2015-03-23 09:27:33 -0600 | [diff] [blame] | 1492 | def _gen_replay_create_image(self): |
| 1493 | ci_body = [] |
Peter Lohrmann | e59ba28 | 2015-04-06 14:14:44 -0700 | [diff] [blame] | 1494 | ci_body.append(' imageObj local_imageObj;') |
| 1495 | ci_body.append(' replayResult = m_xglFuncs.real_xglCreateImage(m_objMapper.remap(pPacket->device), pPacket->pCreateInfo, &local_imageObj.replayImage);') |
Jon Ashburn | 7f8acc7 | 2015-03-23 09:27:33 -0600 | [diff] [blame] | 1496 | ci_body.append(' if (replayResult == XGL_SUCCESS)') |
| 1497 | ci_body.append(' {') |
Peter Lohrmann | e59ba28 | 2015-04-06 14:14:44 -0700 | [diff] [blame] | 1498 | ci_body.append(' m_objMapper.add_to_map(pPacket->pImage, &local_imageObj);') |
Jon Ashburn | 7f8acc7 | 2015-03-23 09:27:33 -0600 | [diff] [blame] | 1499 | ci_body.append(' }') |
| 1500 | return "\n".join(ci_body) |
| 1501 | |
| 1502 | def _gen_replay_create_buffer(self): |
| 1503 | cb_body = [] |
Peter Lohrmann | e59ba28 | 2015-04-06 14:14:44 -0700 | [diff] [blame] | 1504 | cb_body.append(' bufferObj local_bufferObj;') |
| 1505 | cb_body.append(' replayResult = m_xglFuncs.real_xglCreateBuffer(m_objMapper.remap(pPacket->device), pPacket->pCreateInfo, &local_bufferObj.replayBuffer);') |
Jon Ashburn | 7f8acc7 | 2015-03-23 09:27:33 -0600 | [diff] [blame] | 1506 | cb_body.append(' if (replayResult == XGL_SUCCESS)') |
| 1507 | cb_body.append(' {') |
Peter Lohrmann | e59ba28 | 2015-04-06 14:14:44 -0700 | [diff] [blame] | 1508 | cb_body.append(' m_objMapper.add_to_map(pPacket->pBuffer, &local_bufferObj);') |
Jon Ashburn | 7f8acc7 | 2015-03-23 09:27:33 -0600 | [diff] [blame] | 1509 | cb_body.append(' }') |
| 1510 | return "\n".join(cb_body) |
| 1511 | |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1512 | def _gen_replay_get_image_subresource_info(self): |
| 1513 | isi_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1514 | isi_body.append(' returnValue = manually_handle_xglGetImageSubresourceInfo(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1515 | return "\n".join(isi_body) |
| 1516 | |
Tobin Ehlis | fc04b89 | 2015-01-22 12:29:31 -0700 | [diff] [blame] | 1517 | def _gen_replay_update_descriptors(self): |
| 1518 | ud_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1519 | ud_body.append(' returnValue = manually_handle_xglUpdateDescriptors(pPacket);') |
Tobin Ehlis | 8361b56 | 2015-02-03 14:41:26 -0700 | [diff] [blame] | 1520 | return "\n".join(ud_body) |
Tobin Ehlis | fc04b89 | 2015-01-22 12:29:31 -0700 | [diff] [blame] | 1521 | |
| 1522 | def _gen_replay_create_descriptor_set_layout(self): |
| 1523 | cdsl_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1524 | cdsl_body.append(' returnValue = manually_handle_xglCreateDescriptorSetLayout(pPacket);') |
Tobin Ehlis | 8361b56 | 2015-02-03 14:41:26 -0700 | [diff] [blame] | 1525 | return "\n".join(cdsl_body) |
Tobin Ehlis | fc04b89 | 2015-01-22 12:29:31 -0700 | [diff] [blame] | 1526 | |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1527 | def _gen_replay_create_graphics_pipeline(self): |
| 1528 | cgp_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1529 | cgp_body.append(' returnValue = manually_handle_xglCreateGraphicsPipeline(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1530 | return "\n".join(cgp_body) |
| 1531 | |
Tobin Ehlis | 5099051 | 2015-02-05 11:29:45 -0700 | [diff] [blame] | 1532 | def _gen_replay_cmd_wait_events(self): |
| 1533 | cwe_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1534 | cwe_body.append(' returnValue = manually_handle_xglCmdWaitEvents(pPacket);') |
Tobin Ehlis | 5099051 | 2015-02-05 11:29:45 -0700 | [diff] [blame] | 1535 | return "\n".join(cwe_body) |
| 1536 | |
Jon Ashburn | c46fc50 | 2015-02-10 10:36:22 -0700 | [diff] [blame] | 1537 | def _gen_replay_cmd_pipeline_barrier(self): |
| 1538 | cpb_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1539 | cpb_body.append(' returnValue = manually_handle_xglCmdPipelineBarrier(pPacket);') |
Jon Ashburn | c46fc50 | 2015-02-10 10:36:22 -0700 | [diff] [blame] | 1540 | return "\n".join(cpb_body) |
| 1541 | |
Jon Ashburn | a02bc24 | 2015-01-02 18:28:26 -0700 | [diff] [blame] | 1542 | def _gen_replay_create_framebuffer(self): |
| 1543 | cf_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1544 | cf_body.append(' returnValue = manually_handle_xglCreateFramebuffer(pPacket);') |
Jon Ashburn | a02bc24 | 2015-01-02 18:28:26 -0700 | [diff] [blame] | 1545 | return "\n".join(cf_body) |
| 1546 | |
| 1547 | def _gen_replay_create_renderpass(self): |
| 1548 | cr_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1549 | cr_body.append(' returnValue = manually_handle_xglCreateRenderPass(pPacket);') |
Jon Ashburn | a02bc24 | 2015-01-02 18:28:26 -0700 | [diff] [blame] | 1550 | return "\n".join(cr_body) |
| 1551 | |
| 1552 | def _gen_replay_begin_command_buffer(self): |
| 1553 | bcb_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1554 | bcb_body.append(' returnValue = manually_handle_xglBeginCommandBuffer(pPacket);') |
Jon Ashburn | a02bc24 | 2015-01-02 18:28:26 -0700 | [diff] [blame] | 1555 | return "\n".join(bcb_body) |
| 1556 | |
Jon Ashburn | 615b6ce | 2015-03-09 12:39:26 -0600 | [diff] [blame] | 1557 | def _gen_replay_begin_render_pass(self): |
| 1558 | cbrp_body = [] |
| 1559 | cbrp_body.append(' XGL_RENDER_PASS_BEGIN savedRPB, *pRPB = (XGL_RENDER_PASS_BEGIN *) pPacket->pRenderPassBegin;') |
| 1560 | cbrp_body.append(' savedRPB = *(pPacket->pRenderPassBegin);') |
Courtney Goeltzenleuchter | aa86e0e | 2015-03-24 18:02:34 -0600 | [diff] [blame] | 1561 | cbrp_body.append(' pRPB->renderPass = m_objMapper.remap(savedRPB.renderPass);') |
| 1562 | cbrp_body.append(' pRPB->framebuffer = m_objMapper.remap(savedRPB.framebuffer);') |
| 1563 | cbrp_body.append(' m_xglFuncs.real_xglCmdBeginRenderPass(m_objMapper.remap(pPacket->cmdBuffer), pPacket->pRenderPassBegin);') |
Jon Ashburn | 615b6ce | 2015-03-09 12:39:26 -0600 | [diff] [blame] | 1564 | cbrp_body.append(' *pRPB = savedRPB;') |
| 1565 | return "\n".join(cbrp_body) |
| 1566 | |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1567 | def _gen_replay_store_pipeline(self): |
| 1568 | sp_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1569 | sp_body.append(' returnValue = manually_handle_xglStorePipeline(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1570 | return "\n".join(sp_body) |
| 1571 | |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1572 | def _gen_replay_get_multi_gpu_compatibility(self): |
| 1573 | gmgc_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1574 | gmgc_body.append(' returnValue = manually_handle_xglGetMultiGpuCompatibility(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1575 | return "\n".join(gmgc_body) |
| 1576 | |
| 1577 | def _gen_replay_destroy_object(self): |
| 1578 | do_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1579 | do_body.append(' returnValue = manually_handle_xglDestroyObject(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1580 | return "\n".join(do_body) |
| 1581 | |
| 1582 | def _gen_replay_wait_for_fences(self): |
| 1583 | wf_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1584 | wf_body.append(' returnValue = manually_handle_xglWaitForFences(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1585 | return "\n".join(wf_body) |
| 1586 | |
| 1587 | def _gen_replay_wsi_associate_connection(self): |
| 1588 | wac_body = [] |
Peter Lohrmann | 95c369a | 2015-04-02 10:06:19 -0700 | [diff] [blame] | 1589 | wac_body.append(' returnValue = manually_handle_xglWsiX11AssociateConnection(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1590 | return "\n".join(wac_body) |
| 1591 | |
| 1592 | def _gen_replay_wsi_get_msc(self): |
| 1593 | wgm_body = [] |
Peter Lohrmann | 95c369a | 2015-04-02 10:06:19 -0700 | [diff] [blame] | 1594 | wgm_body.append(' returnValue = manually_handle_xglWsiX11GetMSC(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1595 | return "\n".join(wgm_body) |
| 1596 | |
| 1597 | def _gen_replay_wsi_create_presentable_image(self): |
| 1598 | cpi_body = [] |
Peter Lohrmann | 95c369a | 2015-04-02 10:06:19 -0700 | [diff] [blame] | 1599 | cpi_body.append(' returnValue = manually_handle_xglWsiX11CreatePresentableImage(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1600 | return "\n".join(cpi_body) |
| 1601 | |
| 1602 | def _gen_replay_wsi_queue_present(self): |
| 1603 | wqp_body = [] |
Peter Lohrmann | 95c369a | 2015-04-02 10:06:19 -0700 | [diff] [blame] | 1604 | wqp_body.append(' returnValue = manually_handle_xglWsiX11QueuePresent(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1605 | return "\n".join(wqp_body) |
| 1606 | |
Jon Ashburn | 16239cd | 2015-03-24 11:05:02 -0600 | [diff] [blame] | 1607 | def _gen_replay_alloc_memory(self): |
| 1608 | am_body = [] |
Peter Lohrmann | e59ba28 | 2015-04-06 14:14:44 -0700 | [diff] [blame] | 1609 | am_body.append(' gpuMemObj local_mem;') |
| 1610 | am_body.append(' if (!m_objMapper.m_adjustForGPU)') |
| 1611 | am_body.append(' replayResult = m_xglFuncs.real_xglAllocMemory(m_objMapper.remap(pPacket->device), pPacket->pAllocInfo, &local_mem.replayGpuMem);') |
| 1612 | am_body.append(' if (replayResult == XGL_SUCCESS || m_objMapper.m_adjustForGPU)') |
Jon Ashburn | 16239cd | 2015-03-24 11:05:02 -0600 | [diff] [blame] | 1613 | am_body.append(' {') |
Jon Ashburn | cce1cb5 | 2015-03-26 16:15:18 -0600 | [diff] [blame] | 1614 | am_body.append(' local_mem.pGpuMem = new (gpuMemory);') |
| 1615 | am_body.append(' if (local_mem.pGpuMem)') |
Peter Lohrmann | e59ba28 | 2015-04-06 14:14:44 -0700 | [diff] [blame] | 1616 | am_body.append(' local_mem.pGpuMem->setAllocInfo(pPacket->pAllocInfo, m_objMapper.m_adjustForGPU);') |
| 1617 | am_body.append(' m_objMapper.add_to_map(pPacket->pMem, &local_mem);') |
Jon Ashburn | 16239cd | 2015-03-24 11:05:02 -0600 | [diff] [blame] | 1618 | am_body.append(' }') |
| 1619 | return "\n".join(am_body) |
| 1620 | |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1621 | def _gen_replay_free_memory(self): |
| 1622 | fm_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1623 | fm_body.append(' returnValue = manually_handle_xglFreeMemory(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1624 | return "\n".join(fm_body) |
| 1625 | |
| 1626 | def _gen_replay_map_memory(self): |
| 1627 | mm_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1628 | mm_body.append(' returnValue = manually_handle_xglMapMemory(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1629 | return "\n".join(mm_body) |
| 1630 | |
| 1631 | def _gen_replay_unmap_memory(self): |
| 1632 | um_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1633 | um_body.append(' returnValue = manually_handle_xglUnmapMemory(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1634 | return "\n".join(um_body) |
| 1635 | |
Jon Ashburn | 16239cd | 2015-03-24 11:05:02 -0600 | [diff] [blame] | 1636 | def _gen_replay_pin_system_memory(self): |
| 1637 | psm_body = [] |
Peter Lohrmann | e59ba28 | 2015-04-06 14:14:44 -0700 | [diff] [blame] | 1638 | psm_body.append(' gpuMemObj local_mem;') |
Jon Ashburn | d4daf59 | 2015-03-27 16:23:47 -0600 | [diff] [blame] | 1639 | psm_body.append(' /* TODO do we need to skip (make pending) this call for m_adjustForGPU */') |
Peter Lohrmann | e59ba28 | 2015-04-06 14:14:44 -0700 | [diff] [blame] | 1640 | psm_body.append(' replayResult = m_xglFuncs.real_xglPinSystemMemory(m_objMapper.remap(pPacket->device), pPacket->pSysMem, pPacket->memSize, &local_mem.replayGpuMem);') |
Jon Ashburn | 16239cd | 2015-03-24 11:05:02 -0600 | [diff] [blame] | 1641 | psm_body.append(' if (replayResult == XGL_SUCCESS)') |
Peter Lohrmann | e59ba28 | 2015-04-06 14:14:44 -0700 | [diff] [blame] | 1642 | psm_body.append(' m_objMapper.add_to_map(pPacket->pMem, &local_mem);') |
Jon Ashburn | 16239cd | 2015-03-24 11:05:02 -0600 | [diff] [blame] | 1643 | return "\n".join(psm_body) |
| 1644 | |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1645 | # I don't think this function is being generated anymore (ie, it may have been removed from XGL) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1646 | def _gen_replay_bind_dynamic_memory_view(self): |
| 1647 | bdmv_body = [] |
| 1648 | bdmv_body.append(' XGL_MEMORY_VIEW_ATTACH_INFO memView;') |
| 1649 | bdmv_body.append(' memcpy(&memView, pPacket->pMemView, sizeof(XGL_MEMORY_VIEW_ATTACH_INFO));') |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1650 | bdmv_body.append(' memView.mem = m_objMapper.remap(pPacket->pMemView->mem);') |
| 1651 | bdmv_body.append(' m_xglFuncs.real_xglCmdBindDynamicMemoryView(m_objMapper.remap(pPacket->cmdBuffer), pPacket->pipelineBindPoint, &memView);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1652 | return "\n".join(bdmv_body) |
| 1653 | |
Tobin Ehlis | 5099051 | 2015-02-05 11:29:45 -0700 | [diff] [blame] | 1654 | # Generate main replay case statements where actual replay API call is dispatched based on input packet data |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1655 | def _generate_replay(self): |
| 1656 | # map protos to custom functions if body is fully custom |
Tobin Ehlis | 45bc7f8 | 2015-01-16 15:13:34 -0700 | [diff] [blame] | 1657 | custom_body_dict = {'EnumerateGpus': self._gen_replay_enum_gpus, |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1658 | 'GetGpuInfo': self._gen_replay_get_gpu_info, |
| 1659 | 'CreateDevice': self._gen_replay_create_device, |
| 1660 | 'GetExtensionSupport': self._gen_replay_get_extension_support, |
| 1661 | 'QueueSubmit': self._gen_replay_queue_submit, |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1662 | 'GetObjectInfo': self._gen_replay_get_object_info, |
| 1663 | 'GetFormatInfo': self._gen_replay_get_format_info, |
Jon Ashburn | 7f8acc7 | 2015-03-23 09:27:33 -0600 | [diff] [blame] | 1664 | 'CreateImage': self._gen_replay_create_image, |
| 1665 | 'CreateBuffer': self._gen_replay_create_buffer, |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1666 | 'GetImageSubresourceInfo': self._gen_replay_get_image_subresource_info, |
| 1667 | 'CreateGraphicsPipeline': self._gen_replay_create_graphics_pipeline, |
Jon Ashburn | a02bc24 | 2015-01-02 18:28:26 -0700 | [diff] [blame] | 1668 | 'CreateFramebuffer': self._gen_replay_create_framebuffer, |
| 1669 | 'CreateRenderPass': self._gen_replay_create_renderpass, |
| 1670 | 'BeginCommandBuffer': self._gen_replay_begin_command_buffer, |
Jon Ashburn | 615b6ce | 2015-03-09 12:39:26 -0600 | [diff] [blame] | 1671 | 'CmdBeginRenderPass': self._gen_replay_begin_render_pass, |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1672 | 'StorePipeline': self._gen_replay_store_pipeline, |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1673 | 'GetMultiGpuCompatibility': self._gen_replay_get_multi_gpu_compatibility, |
| 1674 | 'DestroyObject': self._gen_replay_destroy_object, |
| 1675 | 'WaitForFences': self._gen_replay_wait_for_fences, |
| 1676 | 'WsiX11AssociateConnection': self._gen_replay_wsi_associate_connection, |
| 1677 | 'WsiX11GetMSC': self._gen_replay_wsi_get_msc, |
| 1678 | 'WsiX11CreatePresentableImage': self._gen_replay_wsi_create_presentable_image, |
| 1679 | 'WsiX11QueuePresent': self._gen_replay_wsi_queue_present, |
Jon Ashburn | 16239cd | 2015-03-24 11:05:02 -0600 | [diff] [blame] | 1680 | 'AllocMemory': self._gen_replay_alloc_memory, |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1681 | 'FreeMemory': self._gen_replay_free_memory, |
| 1682 | 'MapMemory': self._gen_replay_map_memory, |
| 1683 | 'UnmapMemory': self._gen_replay_unmap_memory, |
Jon Ashburn | 16239cd | 2015-03-24 11:05:02 -0600 | [diff] [blame] | 1684 | 'PinSystemMemory': self._gen_replay_pin_system_memory, |
Tobin Ehlis | 8361b56 | 2015-02-03 14:41:26 -0700 | [diff] [blame] | 1685 | 'CmdBindDynamicMemoryView': self._gen_replay_bind_dynamic_memory_view, |
| 1686 | 'UpdateDescriptors': self._gen_replay_update_descriptors, |
Tobin Ehlis | 5099051 | 2015-02-05 11:29:45 -0700 | [diff] [blame] | 1687 | 'CreateDescriptorSetLayout': self._gen_replay_create_descriptor_set_layout, |
Jon Ashburn | c46fc50 | 2015-02-10 10:36:22 -0700 | [diff] [blame] | 1688 | 'CmdWaitEvents': self._gen_replay_cmd_wait_events, |
| 1689 | 'CmdPipelineBarrier': self._gen_replay_cmd_pipeline_barrier} |
Tobin Ehlis | fc04b89 | 2015-01-22 12:29:31 -0700 | [diff] [blame] | 1690 | # TODO : Need to guard CreateInstance with "if (!m_display->m_initedXGL)" check |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1691 | # Despite returning a value, don't check these funcs b/c custom code includes check already |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1692 | custom_check_ret_val = ['EnumerateGpus', 'GetGpuInfo', 'CreateDevice', 'GetExtensionSupport', 'QueueSubmit', 'GetObjectInfo', |
| 1693 | 'GetFormatInfo', 'GetImageSubresourceInfo', 'CreateDescriptorSetLayout', 'CreateGraphicsPipeline', |
| 1694 | 'CreateFramebuffer', 'CreateRenderPass', 'BeginCommandBuffer', 'StorePipeline', 'GetMultiGpuCompatibility', |
Peter Lohrmann | 95c369a | 2015-04-02 10:06:19 -0700 | [diff] [blame] | 1695 | 'DestroyObject', 'WaitForFences', 'FreeMemory', 'MapMemory', 'UnmapMemory', |
| 1696 | 'WsiX11AssociateConnection', 'WsiX11GetMSC', 'WsiX11CreatePresentableImage', 'WsiX11QueuePresent'] |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1697 | # multi-gpu Open funcs w/ list of local params to create |
| 1698 | custom_open_params = {'OpenSharedMemory': (-1,), |
| 1699 | 'OpenSharedQueueSemaphore': (-1,), |
| 1700 | 'OpenPeerMemory': (-1,), |
| 1701 | 'OpenPeerImage': (-1, -2,)} |
| 1702 | # Functions that create views are unique from other create functions |
Jon Ashburn | b1b63ed | 2015-02-03 11:24:08 -0700 | [diff] [blame] | 1703 | create_view_list = ['CreateBufferView', 'CreateImageView', 'CreateColorAttachmentView', 'CreateDepthStencilView', 'CreateComputePipeline'] |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1704 | # Functions to treat as "Create' that don't have 'Create' in the name |
Tobin Ehlis | 377b462 | 2015-01-20 13:50:59 -0700 | [diff] [blame] | 1705 | special_create_list = ['LoadPipeline', 'AllocMemory', 'GetDeviceQueue', 'PinSystemMemory', 'AllocDescriptorSets'] |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1706 | # A couple funcs use do while loops |
| 1707 | do_while_dict = {'GetFenceStatus': 'replayResult != pPacket->result && pPacket->result == XGL_SUCCESS', 'GetEventStatus': '(pPacket->result == XGL_EVENT_SET || pPacket->result == XGL_EVENT_RESET) && replayResult != pPacket->result'} |
| 1708 | rbody = [] |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1709 | rbody.append('glv_replay::GLV_REPLAY_RESULT xglReplay::replay(glv_trace_packet_header *packet)') |
| 1710 | rbody.append('{') |
| 1711 | rbody.append(' glv_replay::GLV_REPLAY_RESULT returnValue = glv_replay::GLV_REPLAY_SUCCESS;') |
| 1712 | rbody.append(' XGL_RESULT replayResult = XGL_ERROR_UNKNOWN;') |
| 1713 | rbody.append(' switch (packet->packet_id)') |
| 1714 | rbody.append(' {') |
Jon Ashburn | 6f4b303 | 2015-02-03 08:57:28 -0700 | [diff] [blame] | 1715 | rbody.append(' case GLV_TPI_XGL_xglApiVersion:') |
| 1716 | rbody.append(' break; // nothing to replay on the version packet') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1717 | for proto in self.protos: |
| 1718 | ret_value = False |
| 1719 | create_view = False |
| 1720 | create_func = False |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 1721 | # TODO : How to handle void* return of GetProcAddr? |
| 1722 | if ('void' not in proto.ret) and (proto.name not in custom_check_ret_val): |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1723 | ret_value = True |
| 1724 | if proto.name in create_view_list: |
| 1725 | create_view = True |
| 1726 | elif 'Create' in proto.name or proto.name in special_create_list: |
| 1727 | create_func = True |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1728 | rbody.append(' case GLV_TPI_XGL_xgl%s:' % proto.name) |
| 1729 | rbody.append(' {') |
| 1730 | rbody.append(' struct_xgl%s* pPacket = (struct_xgl%s*)(packet->pBody);' % (proto.name, proto.name)) |
| 1731 | if proto.name in custom_body_dict: |
| 1732 | rbody.append(custom_body_dict[proto.name]()) |
| 1733 | else: |
| 1734 | if proto.name in custom_open_params: |
| 1735 | rbody.append(' XGL_DEVICE handle;') |
| 1736 | for pidx in custom_open_params[proto.name]: |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 1737 | rbody.append(' %s local_%s;' % (proto.params[pidx].ty.replace('const ', '').strip('*'), proto.params[pidx].name)) |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1738 | rbody.append(' handle = m_objMapper.remap(pPacket->device);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1739 | elif create_view: |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 1740 | rbody.append(' %s createInfo;' % (proto.params[1].ty.strip('*').replace('const ', ''))) |
| 1741 | rbody.append(' memcpy(&createInfo, pPacket->pCreateInfo, sizeof(%s));' % (proto.params[1].ty.strip('*').replace('const ', ''))) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1742 | if 'CreateComputePipeline' == proto.name: |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1743 | rbody.append(' createInfo.cs.shader = m_objMapper.remap(pPacket->pCreateInfo->cs.shader);') |
Jon Ashburn | b1b63ed | 2015-02-03 11:24:08 -0700 | [diff] [blame] | 1744 | elif 'CreateBufferView' == proto.name: |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1745 | rbody.append(' createInfo.buffer = m_objMapper.remap(pPacket->pCreateInfo->buffer);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1746 | else: |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1747 | rbody.append(' createInfo.image = m_objMapper.remap(pPacket->pCreateInfo->image);') |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 1748 | rbody.append(' %s local_%s;' % (proto.params[-1].ty.strip('*').replace('const ', ''), proto.params[-1].name)) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1749 | elif create_func: # Declare local var to store created handle into |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 1750 | rbody.append(' %s local_%s;' % (proto.params[-1].ty.strip('*').replace('const ', ''), proto.params[-1].name)) |
Tobin Ehlis | 377b462 | 2015-01-20 13:50:59 -0700 | [diff] [blame] | 1751 | if 'AllocDescriptorSets' == proto.name: |
Jon Ashburn | 200ccb5 | 2015-02-04 12:57:25 -0700 | [diff] [blame] | 1752 | rbody.append(' %s local_%s[100];' % (proto.params[-2].ty.strip('*').replace('const ', ''), proto.params[-2].name)) |
| 1753 | rbody.append(' XGL_DESCRIPTOR_SET_LAYOUT localDescSets[100];') |
| 1754 | rbody.append(' assert(pPacket->count <= 100);') |
| 1755 | rbody.append(' for (uint32_t i = 0; i < pPacket->count; i++)') |
| 1756 | rbody.append(' {') |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1757 | rbody.append(' localDescSets[i] = m_objMapper.remap(pPacket->%s[i]);' % (proto.params[-3].name)) |
Jon Ashburn | 200ccb5 | 2015-02-04 12:57:25 -0700 | [diff] [blame] | 1758 | rbody.append(' }') |
| 1759 | elif proto.name == 'ClearDescriptorSets': |
| 1760 | rbody.append(' XGL_DESCRIPTOR_SET localDescSets[100];') |
| 1761 | rbody.append(' assert(pPacket->count <= 100);') |
| 1762 | rbody.append(' for (uint32_t i = 0; i < pPacket->count; i++)') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1763 | rbody.append(' {') |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1764 | rbody.append(' localDescSets[i] = m_objMapper.remap(pPacket->%s[i]);' % (proto.params[-1].name)) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1765 | rbody.append(' }') |
| 1766 | elif proto.name in do_while_dict: |
| 1767 | rbody.append(' do {') |
Jon Ashburn | ffd5f14 | 2015-02-03 13:39:05 -0700 | [diff] [blame] | 1768 | elif proto.name == 'EnumerateLayers': |
| 1769 | rbody.append(' char **bufptr = GLV_NEW_ARRAY(char *, pPacket->maxLayerCount);') |
| 1770 | rbody.append(' char **ptrLayers = (pPacket->pOutLayers == NULL) ? bufptr : (char **) pPacket->pOutLayers;') |
| 1771 | rbody.append(' for (unsigned int i = 0; i < pPacket->maxLayerCount; i++)') |
| 1772 | rbody.append(' bufptr[i] = GLV_NEW_ARRAY(char, pPacket->maxStringSize);') |
Jon Ashburn | d698ca2 | 2015-02-12 12:37:46 -0700 | [diff] [blame] | 1773 | elif proto.name == 'DestroyInstance': |
Courtney Goeltzenleuchter | bef7272 | 2015-04-13 14:59:46 -0600 | [diff] [blame] | 1774 | rbody.append(' xglDbgUnregisterMsgCallback(m_objMapper.remap(pPacket->instance), g_fpDbgMsgCallback);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1775 | rr_string = ' ' |
| 1776 | if ret_value: |
| 1777 | rr_string = ' replayResult = ' |
| 1778 | rr_string += 'm_xglFuncs.real_xgl%s(' % proto.name |
| 1779 | for p in proto.params: |
| 1780 | # For last param of Create funcs, pass address of param |
Tobin Ehlis | 377b462 | 2015-01-20 13:50:59 -0700 | [diff] [blame] | 1781 | if create_func: |
| 1782 | if p.name == proto.params[-1].name: |
| 1783 | rr_string += '&local_%s, ' % p.name |
| 1784 | elif proto.name == 'AllocDescriptorSets' and p.name == proto.params[-2].name: |
| 1785 | rr_string += 'local_%s, ' % p.name |
| 1786 | else: |
| 1787 | rr_string += '%s, ' % self._get_packet_param(p.ty, p.name) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1788 | else: |
| 1789 | rr_string += '%s, ' % self._get_packet_param(p.ty, p.name) |
| 1790 | rr_string = '%s);' % rr_string[:-2] |
Jon Ashburn | 200ccb5 | 2015-02-04 12:57:25 -0700 | [diff] [blame] | 1791 | if proto.name in custom_open_params: |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1792 | rr_list = rr_string.split(', ') |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1793 | rr_list[0] = rr_list[0].replace('m_objMapper.remap(pPacket->device)', 'handle') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1794 | for pidx in custom_open_params[proto.name]: |
| 1795 | rr_list[pidx] = '&local_%s' % proto.params[pidx].name |
| 1796 | rr_string = ', '.join(rr_list) |
| 1797 | rr_string += ');' |
| 1798 | elif create_view: |
| 1799 | rr_list = rr_string.split(', ') |
| 1800 | rr_list[-2] = '&createInfo' |
| 1801 | rr_list[-1] = '&local_%s);' % proto.params[-1].name |
| 1802 | rr_string = ', '.join(rr_list) |
| 1803 | # this is a sneaky shortcut to use generic create code below to add_to_map |
| 1804 | create_func = True |
Jon Ashburn | ffd5f14 | 2015-02-03 13:39:05 -0700 | [diff] [blame] | 1805 | elif proto.name == 'EnumerateLayers': |
| 1806 | rr_string = rr_string.replace('pPacket->pOutLayers', 'ptrLayers') |
Jon Ashburn | 200ccb5 | 2015-02-04 12:57:25 -0700 | [diff] [blame] | 1807 | elif proto.name == 'ClearDescriptorSets': |
| 1808 | rr_string = rr_string.replace('pPacket->pDescriptorSets', 'localDescSets') |
| 1809 | elif proto.name == 'AllocDescriptorSets': |
| 1810 | rr_string = rr_string.replace('pPacket->pSetLayouts', 'localDescSets') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1811 | rbody.append(rr_string) |
| 1812 | if 'DestroyDevice' in proto.name: |
| 1813 | rbody.append(' if (replayResult == XGL_SUCCESS)') |
| 1814 | rbody.append(' {') |
Peter Lohrmann | 53e8924 | 2015-02-27 15:35:15 -0800 | [diff] [blame] | 1815 | rbody.append(' m_pCBDump = NULL;') |
| 1816 | rbody.append(' m_pDSDump = NULL;') |
Peter Lohrmann | caf39d5 | 2015-03-24 17:19:24 -0700 | [diff] [blame] | 1817 | rbody.append(' m_pGlvSnapshotPrint = NULL;') |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1818 | rbody.append(' m_objMapper.rm_from_map(pPacket->device);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1819 | rbody.append(' m_display->m_initedXGL = false;') |
| 1820 | rbody.append(' }') |
Jon Ashburn | 6f4b303 | 2015-02-03 08:57:28 -0700 | [diff] [blame] | 1821 | if 'DestroyInstance' in proto.name: |
| 1822 | rbody.append(' if (replayResult == XGL_SUCCESS)') |
| 1823 | rbody.append(' {') |
Jon Ashburn | 6f58a16 | 2015-02-03 09:17:12 -0700 | [diff] [blame] | 1824 | rbody.append(' // TODO need to handle multiple instances and only clearing maps within an instance.') |
| 1825 | rbody.append(' // TODO this only works with a single instance used at any given time.') |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1826 | rbody.append(' m_objMapper.clear_all_map_handles();') |
Jon Ashburn | 6f4b303 | 2015-02-03 08:57:28 -0700 | [diff] [blame] | 1827 | rbody.append(' }') |
Tobin Ehlis | 377b462 | 2015-01-20 13:50:59 -0700 | [diff] [blame] | 1828 | elif 'AllocDescriptorSets' in proto.name: |
| 1829 | rbody.append(' if (replayResult == XGL_SUCCESS)') |
| 1830 | rbody.append(' {') |
| 1831 | rbody.append(' for (uint32_t i = 0; i < local_pCount; i++) {') |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1832 | rbody.append(' m_objMapper.add_to_map(&pPacket->%s[i], &local_%s[i]);' % (proto.params[-2].name, proto.params[-2].name)) |
Tobin Ehlis | 377b462 | 2015-01-20 13:50:59 -0700 | [diff] [blame] | 1833 | rbody.append(' }') |
| 1834 | rbody.append(' }') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1835 | elif create_func: # save handle mapping if create successful |
| 1836 | rbody.append(' if (replayResult == XGL_SUCCESS)') |
| 1837 | rbody.append(' {') |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1838 | rbody.append(' m_objMapper.add_to_map(pPacket->%s, &local_%s);' % (proto.params[-1].name, proto.params[-1].name)) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1839 | if 'AllocMemory' == proto.name: |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1840 | rbody.append(' m_objMapper.add_entry_to_mapData(local_%s, pPacket->pAllocInfo->allocationSize);' % (proto.params[-1].name)) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1841 | rbody.append(' }') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1842 | elif proto.name in do_while_dict: |
| 1843 | rbody[-1] = ' %s' % rbody[-1] |
| 1844 | rbody.append(' } while (%s);' % do_while_dict[proto.name]) |
Jon Ashburn | 8bead7a | 2015-02-23 11:07:30 -0700 | [diff] [blame] | 1845 | rbody.append(' if (pPacket->result != XGL_NOT_READY || replayResult != XGL_SUCCESS)') |
Jon Ashburn | ffd5f14 | 2015-02-03 13:39:05 -0700 | [diff] [blame] | 1846 | elif proto.name == 'EnumerateLayers': |
| 1847 | rbody.append(' for (unsigned int i = 0; i < pPacket->maxLayerCount; i++)') |
| 1848 | rbody.append(' GLV_DELETE(bufptr[i]);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1849 | if ret_value: |
| 1850 | rbody.append(' CHECK_RETURN_VALUE(xgl%s);' % proto.name) |
| 1851 | if 'MsgCallback' in proto.name: |
| 1852 | rbody.pop() |
| 1853 | rbody.pop() |
| 1854 | rbody.pop() |
| 1855 | rbody.append(' // Just eating these calls as no way to restore dbg func ptr.') |
| 1856 | rbody.append(' break;') |
| 1857 | rbody.append(' }') |
| 1858 | rbody.append(' default:') |
| 1859 | rbody.append(' glv_LogWarn("Unrecognized packet_id %u, skipping\\n", packet->packet_id);') |
| 1860 | rbody.append(' returnValue = glv_replay::GLV_REPLAY_INVALID_ID;') |
| 1861 | rbody.append(' break;') |
| 1862 | rbody.append(' }') |
| 1863 | rbody.append(' return returnValue;') |
| 1864 | rbody.append('}') |
| 1865 | return "\n".join(rbody) |
| 1866 | |
| 1867 | class GlaveTraceHeader(Subcommand): |
| 1868 | def generate_header(self): |
| 1869 | header_txt = [] |
Peter Lohrmann | cde614c | 2015-03-27 12:57:10 -0700 | [diff] [blame] | 1870 | header_txt.append('#include "glv_vk_vk_structs.h"') |
| 1871 | header_txt.append('#include "glv_vk_packet_id.h"\n') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1872 | header_txt.append('void AttachHooks();') |
| 1873 | header_txt.append('void DetachHooks();') |
Ian Elliott | bc9ca5f | 2015-02-27 11:10:59 -0700 | [diff] [blame] | 1874 | header_txt.append('void InitTracer(void);\n') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1875 | return "\n".join(header_txt) |
| 1876 | |
| 1877 | def generate_body(self): |
| 1878 | body = [self._generate_trace_func_ptrs(), |
Peter Lohrmann | 358d009 | 2015-04-03 12:03:44 -0700 | [diff] [blame] | 1879 | self._generate_trace_func_protos(), |
| 1880 | self._generate_trace_real_func_ptr_protos()] |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1881 | |
| 1882 | return "\n".join(body) |
| 1883 | |
| 1884 | class GlaveTraceC(Subcommand): |
| 1885 | def generate_header(self): |
| 1886 | header_txt = [] |
| 1887 | header_txt.append('#include "glv_platform.h"') |
| 1888 | header_txt.append('#include "glv_common.h"') |
Peter Lohrmann | 358d009 | 2015-04-03 12:03:44 -0700 | [diff] [blame] | 1889 | header_txt.append('#include "glvtrace_xgl_helpers.h"') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1890 | header_txt.append('#include "glvtrace_xgl_xgl.h"') |
| 1891 | header_txt.append('#include "glvtrace_xgl_xgldbg.h"') |
| 1892 | header_txt.append('#include "glvtrace_xgl_xglwsix11ext.h"') |
| 1893 | header_txt.append('#include "glv_interconnect.h"') |
| 1894 | header_txt.append('#include "glv_filelike.h"') |
Tobin Ehlis | ff765b0 | 2015-03-12 14:50:40 -0600 | [diff] [blame] | 1895 | header_txt.append('#include "xgl_struct_size_helper.h"') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1896 | header_txt.append('#ifdef WIN32') |
| 1897 | header_txt.append('#include "mhook/mhook-lib/mhook.h"') |
| 1898 | header_txt.append('#endif') |
| 1899 | header_txt.append('#include "glv_trace_packet_utils.h"') |
| 1900 | header_txt.append('#include <stdio.h>\n') |
| 1901 | return "\n".join(header_txt) |
| 1902 | |
| 1903 | def generate_body(self): |
| 1904 | body = [self._generate_func_ptr_assignments(), |
| 1905 | self._generate_attach_hooks(), |
| 1906 | self._generate_detach_hooks(), |
Jon Ashburn | e224839 | 2014-12-16 18:37:04 -0700 | [diff] [blame] | 1907 | self._generate_init_funcs(), |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1908 | self._generate_trace_funcs()] |
| 1909 | |
| 1910 | return "\n".join(body) |
| 1911 | |
| 1912 | class GlavePacketID(Subcommand): |
| 1913 | def generate_header(self): |
| 1914 | header_txt = [] |
| 1915 | header_txt.append('#pragma once\n') |
| 1916 | header_txt.append('#include "glv_trace_packet_utils.h"') |
| 1917 | header_txt.append('#include "glv_trace_packet_identifiers.h"') |
| 1918 | header_txt.append('#include "glv_interconnect.h"') |
Peter Lohrmann | cde614c | 2015-03-27 12:57:10 -0700 | [diff] [blame] | 1919 | header_txt.append('#include "glv_vk_vk_structs.h"') |
| 1920 | header_txt.append('#include "glv_vk_vkdbg_structs.h"') |
| 1921 | header_txt.append('#include "glv_vk_vkwsix11ext_structs.h"') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1922 | header_txt.append('#include "xgl_enum_string_helper.h"') |
Piers Daniell | e2bca48 | 2015-02-24 13:58:47 -0700 | [diff] [blame] | 1923 | header_txt.append('#if defined(WIN32)') |
| 1924 | header_txt.append('#define snprintf _snprintf') |
| 1925 | header_txt.append('#endif') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1926 | header_txt.append('#define SEND_ENTRYPOINT_ID(entrypoint) ;') |
| 1927 | header_txt.append('//#define SEND_ENTRYPOINT_ID(entrypoint) glv_TraceInfo(#entrypoint "\\n");\n') |
| 1928 | header_txt.append('#define SEND_ENTRYPOINT_PARAMS(entrypoint, ...) ;') |
| 1929 | header_txt.append('//#define SEND_ENTRYPOINT_PARAMS(entrypoint, ...) glv_TraceInfo(entrypoint, __VA_ARGS__);\n') |
| 1930 | header_txt.append('#define CREATE_TRACE_PACKET(entrypoint, buffer_bytes_needed) \\') |
| 1931 | header_txt.append(' pHeader = glv_create_trace_packet(GLV_TID_XGL, GLV_TPI_XGL_##entrypoint, sizeof(struct_##entrypoint), buffer_bytes_needed);\n') |
| 1932 | header_txt.append('#define FINISH_TRACE_PACKET() \\') |
| 1933 | header_txt.append(' glv_finalize_trace_packet(pHeader); \\') |
| 1934 | header_txt.append(' glv_write_trace_packet(pHeader, glv_trace_get_trace_file()); \\') |
| 1935 | header_txt.append(' glv_delete_trace_packet(&pHeader);') |
| 1936 | return "\n".join(header_txt) |
| 1937 | |
| 1938 | def generate_body(self): |
| 1939 | body = [self._generate_packet_id_enum(), |
| 1940 | self._generate_stringify_func(), |
| 1941 | self._generate_interp_func()] |
| 1942 | |
| 1943 | return "\n".join(body) |
| 1944 | |
| 1945 | class GlaveCoreStructs(Subcommand): |
| 1946 | def generate_header(self): |
| 1947 | header_txt = [] |
| 1948 | header_txt.append('#pragma once\n') |
| 1949 | header_txt.append('#include "xgl.h"') |
| 1950 | header_txt.append('#include "glv_trace_packet_utils.h"\n') |
| 1951 | return "\n".join(header_txt) |
| 1952 | |
| 1953 | def generate_body(self): |
| 1954 | body = [self._generate_struct_util_funcs(), |
| 1955 | self._generate_interp_funcs()] |
| 1956 | |
| 1957 | return "\n".join(body) |
| 1958 | |
| 1959 | class GlaveWsiHeader(Subcommand): |
| 1960 | def generate_header(self): |
| 1961 | header_txt = [] |
| 1962 | header_txt.append('#pragma once\n') |
| 1963 | header_txt.append('#include "xgl.h"') |
Piers Daniell | e2bca48 | 2015-02-24 13:58:47 -0700 | [diff] [blame] | 1964 | header_txt.append('#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA)') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1965 | header_txt.append('#include "xglWsiX11Ext.h"\n') |
David Pinedo | 8e9cb3b | 2015-02-10 15:02:08 -0700 | [diff] [blame] | 1966 | header_txt.append('#else') |
| 1967 | header_txt.append('#include "xglWsiWinExt.h"') |
| 1968 | header_txt.append('#endif') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1969 | header_txt.append('void AttachHooks_xglwsix11ext();') |
| 1970 | header_txt.append('void DetachHooks_xglwsix11ext();') |
| 1971 | return "\n".join(header_txt) |
| 1972 | |
| 1973 | def generate_body(self): |
| 1974 | body = [self._generate_trace_func_ptrs_ext(), |
| 1975 | self._generate_trace_func_protos_ext()] |
| 1976 | |
| 1977 | return "\n".join(body) |
| 1978 | |
| 1979 | class GlaveWsiC(Subcommand): |
| 1980 | def generate_header(self): |
| 1981 | header_txt = [] |
| 1982 | header_txt.append('#include "glv_platform.h"') |
| 1983 | header_txt.append('#include "glv_common.h"') |
| 1984 | header_txt.append('#include "glvtrace_xgl_xglwsix11ext.h"') |
Peter Lohrmann | cde614c | 2015-03-27 12:57:10 -0700 | [diff] [blame] | 1985 | header_txt.append('#include "glv_vk_vkwsix11ext_structs.h"') |
| 1986 | header_txt.append('#include "glv_vk_packet_id.h"') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1987 | header_txt.append('#ifdef WIN32') |
| 1988 | header_txt.append('#include "mhook/mhook-lib/mhook.h"') |
| 1989 | header_txt.append('#endif') |
| 1990 | return "\n".join(header_txt) |
| 1991 | |
| 1992 | def generate_body(self): |
| 1993 | body = [self._generate_func_ptr_assignments_ext(), |
| 1994 | self._generate_attach_hooks_ext(), |
| 1995 | self._generate_detach_hooks_ext(), |
| 1996 | self._generate_trace_funcs_ext()] |
| 1997 | |
| 1998 | return "\n".join(body) |
| 1999 | |
| 2000 | class GlaveWsiStructs(Subcommand): |
| 2001 | def generate_header(self): |
| 2002 | header_txt = [] |
| 2003 | header_txt.append('#pragma once\n') |
Piers Daniell | e2bca48 | 2015-02-24 13:58:47 -0700 | [diff] [blame] | 2004 | header_txt.append('#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA)') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2005 | header_txt.append('#include "xglWsiX11Ext.h"') |
David Pinedo | 8e9cb3b | 2015-02-10 15:02:08 -0700 | [diff] [blame] | 2006 | header_txt.append('#else') |
| 2007 | header_txt.append('#include "xglWsiWinExt.h"') |
| 2008 | header_txt.append('#endif') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2009 | header_txt.append('#include "glv_trace_packet_utils.h"\n') |
| 2010 | return "\n".join(header_txt) |
| 2011 | |
| 2012 | def generate_body(self): |
| 2013 | body = [self._generate_interp_funcs_ext()] |
| 2014 | |
| 2015 | return "\n".join(body) |
| 2016 | |
| 2017 | class GlaveDbgHeader(Subcommand): |
| 2018 | def generate_header(self): |
| 2019 | header_txt = [] |
| 2020 | header_txt.append('#pragma once\n') |
| 2021 | header_txt.append('#include "xgl.h"') |
| 2022 | header_txt.append('#include "xglDbg.h"\n') |
| 2023 | header_txt.append('void AttachHooks_xgldbg();') |
| 2024 | header_txt.append('void DetachHooks_xgldbg();') |
| 2025 | return "\n".join(header_txt) |
| 2026 | |
| 2027 | def generate_body(self): |
| 2028 | body = [self._generate_trace_func_ptrs_ext('Dbg'), |
| 2029 | self._generate_trace_func_protos_ext('Dbg')] |
| 2030 | |
| 2031 | return "\n".join(body) |
| 2032 | |
| 2033 | class GlaveDbgC(Subcommand): |
| 2034 | def generate_header(self): |
| 2035 | header_txt = [] |
| 2036 | header_txt.append('#include "glv_platform.h"') |
| 2037 | header_txt.append('#include "glv_common.h"') |
| 2038 | header_txt.append('#include "glvtrace_xgl_xgl.h"') |
| 2039 | header_txt.append('#include "glvtrace_xgl_xgldbg.h"') |
Peter Lohrmann | cde614c | 2015-03-27 12:57:10 -0700 | [diff] [blame] | 2040 | header_txt.append('#include "glv_vk_vkdbg_structs.h"') |
| 2041 | header_txt.append('#include "glv_vk_packet_id.h"') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2042 | header_txt.append('#ifdef WIN32') |
| 2043 | header_txt.append('#include "mhook/mhook-lib/mhook.h"') |
| 2044 | header_txt.append('#endif') |
| 2045 | return "\n".join(header_txt) |
| 2046 | |
| 2047 | def generate_body(self): |
| 2048 | body = [self._generate_func_ptr_assignments_ext('Dbg'), |
| 2049 | self._generate_attach_hooks_ext('Dbg'), |
| 2050 | self._generate_detach_hooks_ext('Dbg'), |
| 2051 | self._generate_trace_funcs_ext('Dbg')] |
| 2052 | |
| 2053 | return "\n".join(body) |
| 2054 | |
| 2055 | class GlaveDbgStructs(Subcommand): |
| 2056 | def generate_header(self): |
| 2057 | header_txt = [] |
| 2058 | header_txt.append('#pragma once\n') |
| 2059 | header_txt.append('#include "xglDbg.h"') |
| 2060 | header_txt.append('#include "glv_trace_packet_utils.h"\n') |
| 2061 | return "\n".join(header_txt) |
| 2062 | |
| 2063 | def generate_body(self): |
| 2064 | body = [self._generate_interp_funcs_ext('Dbg')] |
| 2065 | |
| 2066 | return "\n".join(body) |
| 2067 | |
Peter Lohrmann | af44b45 | 2015-03-30 18:29:22 -0700 | [diff] [blame] | 2068 | class GlaveReplayXglFuncPtrs(Subcommand): |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2069 | def generate_header(self): |
| 2070 | header_txt = [] |
| 2071 | header_txt.append('#pragma once\n') |
Piers Daniell | e2bca48 | 2015-02-24 13:58:47 -0700 | [diff] [blame] | 2072 | header_txt.append('#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA)') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2073 | header_txt.append('#include <xcb/xcb.h>\n') |
David Pinedo | 8e9cb3b | 2015-02-10 15:02:08 -0700 | [diff] [blame] | 2074 | header_txt.append('#endif') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2075 | header_txt.append('#include "xgl.h"') |
| 2076 | header_txt.append('#include "xglDbg.h"') |
Piers Daniell | e2bca48 | 2015-02-24 13:58:47 -0700 | [diff] [blame] | 2077 | header_txt.append('#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA)') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2078 | header_txt.append('#include "xglWsiX11Ext.h"') |
David Pinedo | 8e9cb3b | 2015-02-10 15:02:08 -0700 | [diff] [blame] | 2079 | header_txt.append('#else') |
| 2080 | header_txt.append('#include "xglWsiWinExt.h"') |
| 2081 | header_txt.append('#endif') |
Peter Lohrmann | af44b45 | 2015-03-30 18:29:22 -0700 | [diff] [blame] | 2082 | |
| 2083 | def generate_body(self): |
| 2084 | body = [self._generate_replay_func_ptrs()] |
| 2085 | return "\n".join(body) |
| 2086 | |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 2087 | class GlaveReplayObjMapperHeader(Subcommand): |
Jon Ashburn | 013aa1c | 2015-02-13 11:25:53 -0700 | [diff] [blame] | 2088 | def generate_header(self): |
Ian Elliott | 91e681e | 2015-02-18 15:35:00 -0700 | [diff] [blame] | 2089 | header_txt = [] |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2090 | header_txt.append('#pragma once\n') |
| 2091 | header_txt.append('#include <set>') |
| 2092 | header_txt.append('#include <map>') |
| 2093 | header_txt.append('#include <vector>') |
| 2094 | header_txt.append('#include <string>') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2095 | header_txt.append('#include "xgl.h"') |
| 2096 | header_txt.append('#include "xglDbg.h"') |
Jon Ashburn | 1590877 | 2015-02-17 13:28:11 -0700 | [diff] [blame] | 2097 | header_txt.append('#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA)') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2098 | header_txt.append('#include "xglWsiX11Ext.h"') |
| 2099 | header_txt.append('#else') |
| 2100 | header_txt.append('#include "xglWsiWinExt.h"') |
| 2101 | header_txt.append('#endif') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2102 | return "\n".join(header_txt) |
| 2103 | |
| 2104 | def generate_body(self): |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 2105 | body = [self._generate_replay_objmapper_class()] |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2106 | |
| 2107 | return "\n".join(body) |
| 2108 | |
| 2109 | class GlaveReplayC(Subcommand): |
| 2110 | def generate_header(self): |
| 2111 | header_txt = [] |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 2112 | header_txt.append('#include "glvreplay_xgl_xglreplay.h"\n') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2113 | header_txt.append('#include "glvreplay_xgl.h"\n') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2114 | header_txt.append('#include "glvreplay_main.h"\n') |
| 2115 | header_txt.append('#include <algorithm>') |
| 2116 | header_txt.append('#include <queue>') |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 2117 | header_txt.append('\n') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2118 | header_txt.append('extern "C" {') |
Peter Lohrmann | cde614c | 2015-03-27 12:57:10 -0700 | [diff] [blame] | 2119 | header_txt.append('#include "glv_vk_vk_structs.h"') |
| 2120 | header_txt.append('#include "glv_vk_vkdbg_structs.h"') |
| 2121 | header_txt.append('#include "glv_vk_vkwsix11ext_structs.h"') |
| 2122 | header_txt.append('#include "glv_vk_packet_id.h"') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2123 | header_txt.append('#include "xgl_enum_string_helper.h"\n}\n') |
| 2124 | header_txt.append('#define APP_NAME "glvreplay_xgl"') |
| 2125 | header_txt.append('#define IDI_ICON 101\n') |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 2126 | |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2127 | return "\n".join(header_txt) |
| 2128 | |
| 2129 | def generate_body(self): |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 2130 | body = [self._generate_replay_init_funcs(), |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2131 | self._generate_replay()] |
| 2132 | |
| 2133 | return "\n".join(body) |
| 2134 | |
| 2135 | def main(): |
| 2136 | subcommands = { |
| 2137 | "glave-trace-h" : GlaveTraceHeader, |
| 2138 | "glave-trace-c" : GlaveTraceC, |
| 2139 | "glave-packet-id" : GlavePacketID, |
| 2140 | "glave-core-structs" : GlaveCoreStructs, |
| 2141 | "glave-wsi-trace-h" : GlaveWsiHeader, |
| 2142 | "glave-wsi-trace-c" : GlaveWsiC, |
| 2143 | "glave-wsi-trace-structs" : GlaveWsiStructs, |
| 2144 | "glave-dbg-trace-h" : GlaveDbgHeader, |
| 2145 | "glave-dbg-trace-c" : GlaveDbgC, |
| 2146 | "glave-dbg-trace-structs" : GlaveDbgStructs, |
Peter Lohrmann | af44b45 | 2015-03-30 18:29:22 -0700 | [diff] [blame] | 2147 | "glave-replay-xgl-funcs" : GlaveReplayXglFuncPtrs, |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 2148 | "glave-replay-obj-mapper-h" : GlaveReplayObjMapperHeader, |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2149 | "glave-replay-c" : GlaveReplayC, |
| 2150 | } |
| 2151 | |
| 2152 | if len(sys.argv) < 2 or sys.argv[1] not in subcommands: |
| 2153 | print("Usage: %s <subcommand> [options]" % sys.argv[0]) |
| 2154 | print |
| 2155 | print("Available sucommands are: %s" % " ".join(subcommands)) |
| 2156 | exit(1) |
| 2157 | |
| 2158 | subcmd = subcommands[sys.argv[1]](sys.argv[2:]) |
| 2159 | subcmd.run() |
| 2160 | |
| 2161 | if __name__ == "__main__": |
| 2162 | main() |