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 | 2614252 | 2015-03-27 11:39:30 -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: |
| 189 | if 'color' == p.name: |
| 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: |
| 202 | if 'color' == p.name: |
| 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;') |
Tobin Ehlis | f57562c | 2015-03-13 07:18:05 -0600 | [diff] [blame] | 512 | func_body.append(' CREATE_TRACE_PACKET(xglCreateRenderPass, get_struct_chain_size((void*)pCreateInfo) + sizeof(XGL_RENDER_PASS));') |
Jon Ashburn | 8e7dcd0 | 2015-02-04 08:50:35 -0700 | [diff] [blame] | 513 | elif 'CreateDynamicViewportState' == proto.name: |
Courtney Goeltzenleuchter | c6e32f9 | 2015-02-11 14:13:34 -0700 | [diff] [blame] | 514 | 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] | 515 | 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] | 516 | elif 'CreateDescriptorRegion' == proto.name: |
Tobin Ehlis | 5099051 | 2015-02-05 11:29:45 -0700 | [diff] [blame] | 517 | 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] | 518 | 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] | 519 | func_body.append(' %sreal_xgl%s;' % (return_txt, proto.c_call())) |
| 520 | else: |
Tobin Ehlis | 81b1b3d | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 521 | if (0 == len(packet_size)): |
| 522 | func_body.append(' CREATE_TRACE_PACKET(xgl%s, 0);' % (proto.name)) |
| 523 | else: |
| 524 | 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] | 525 | func_body.append(' %sreal_xgl%s;' % (return_txt, proto.c_call())) |
Jon Ashburn | 53f54a3 | 2015-02-11 09:32:29 -0700 | [diff] [blame] | 526 | if in_data_size: |
| 527 | func_body.append(' _dataSize = (pDataSize == NULL || pData == NULL) ? 0 : *pDataSize;') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 528 | func_body.append(' pPacket = interpret_body_as_xgl%s(pHeader);' % proto.name) |
Tobin Ehlis | 81b1b3d | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 529 | func_body.append('\n'.join(raw_packet_update_list)) |
Peter Lohrmann | 358d009 | 2015-04-03 12:03:44 -0700 | [diff] [blame^] | 530 | for pp_dict in ptr_packet_update_list: #buff_ptr_indices: |
| 531 | func_body.append(' %s;' % (pp_dict['add_txt'])) |
| 532 | if 'void' not in proto.ret or '*' in proto.ret: |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 533 | func_body.append(' pPacket->result = result;') |
Peter Lohrmann | 358d009 | 2015-04-03 12:03:44 -0700 | [diff] [blame^] | 534 | for pp_dict in ptr_packet_update_list: |
| 535 | 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): |
| 536 | func_body.append(' %s;' % (pp_dict['finalize_txt'])) |
| 537 | func_body.append(' FINISH_TRACE_PACKET();') |
| 538 | if 'AllocMemory' in proto.name: |
| 539 | func_body.append(' add_new_handle_to_mem_info(*pMem, pAllocInfo->allocationSize, NULL);') |
| 540 | elif 'FreeMemory' in proto.name: |
| 541 | func_body.append(' rm_handle_from_mem_info(mem);') |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 542 | if 'void' not in proto.ret or '*' in proto.ret: |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 543 | func_body.append(' return result;') |
| 544 | func_body.append('}\n') |
| 545 | return "\n".join(func_body) |
| 546 | |
| 547 | def _generate_trace_funcs_ext(self, func_class='Wsi'): |
| 548 | thread_once_funcs = ['DbgRegisterMsgCallback', 'DbgUnregisterMsgCallback', 'DbgSetGlobalOption'] |
| 549 | func_body = [] |
| 550 | for proto in self.protos: |
| 551 | if func_class in proto.name: |
| 552 | packet_update_txt = '' |
| 553 | return_txt = '' |
| 554 | packet_size = '' |
| 555 | buff_ptr_indices = [] |
| 556 | func_body.append('GLVTRACER_EXPORT %s XGLAPI __HOOKED_xgl%s(' % (proto.ret, proto.name)) |
| 557 | for p in proto.params: # TODO : For all of the ptr types, check them for NULL and return 0 is NULL |
| 558 | func_body.append(' %s %s,' % (p.ty, p.name)) |
| 559 | if 'Size' in p.name: |
| 560 | packet_size += p.name |
| 561 | if '*' in p.ty and 'pSysMem' != p.name: |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 562 | if 'char' in p.ty: |
Chia-I Wu | 7461fcf | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 563 | packet_size += '((%s != NULL) ? strlen(%s) + 1 : 0) + ' % (p.name, p.name) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 564 | elif 'Size' not in packet_size: |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 565 | packet_size += 'sizeof(%s) + ' % p.ty.strip('*').replace('const ', '') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 566 | buff_ptr_indices.append(proto.params.index(p)) |
| 567 | if 'pConnectionInfo' in p.name: |
| 568 | packet_size += '((pConnectionInfo->pConnection != NULL) ? sizeof(void *) : 0)' |
| 569 | else: |
| 570 | packet_update_txt += ' pPacket->%s = %s;\n' % (p.name, p.name) |
| 571 | if '' == packet_size: |
| 572 | packet_size = '0' |
| 573 | else: |
| 574 | packet_size = packet_size.strip(' + ') |
| 575 | func_body[-1] = func_body[-1].replace(',', ')') |
| 576 | func_body.append('{\n glv_trace_packet_header* pHeader;') |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 577 | if 'void' not in proto.ret or '*' in proto.ret: |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 578 | func_body.append(' %s result;' % proto.ret) |
| 579 | return_txt = 'result = ' |
| 580 | func_body.append(' struct_xgl%s* pPacket = NULL;' % proto.name) |
| 581 | if proto.name in thread_once_funcs: |
| 582 | func_body.append(' glv_platform_thread_once(&gInitOnce, InitTracer);') |
| 583 | func_body.append(' SEND_ENTRYPOINT_ID(xgl%s);' % proto.name) |
Ian Elliott | bc9ca5f | 2015-02-27 11:10:59 -0700 | [diff] [blame] | 584 | if 'DbgRegisterMsgCallback' in proto.name: |
| 585 | func_body.append(' CREATE_TRACE_PACKET(xgl%s, sizeof(char));' % proto.name) |
| 586 | else: |
| 587 | 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] | 588 | func_body.append(' %sreal_xgl%s;' % (return_txt, proto.c_call())) |
| 589 | func_body.append(' pPacket = interpret_body_as_xgl%s(pHeader);' % proto.name) |
| 590 | func_body.append(packet_update_txt.strip('\n')) |
| 591 | for idx in buff_ptr_indices: |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 592 | if 'char' in proto.params[idx].ty: |
Chia-I Wu | 7461fcf | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 593 | 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] | 594 | elif 'Size' in proto.params[idx-1].name: |
| 595 | 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] | 596 | elif 'DbgRegisterMsgCallback' in proto.name: |
| 597 | 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] | 598 | else: |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 599 | 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] | 600 | if 'WsiX11AssociateConnection' in proto.name: |
| 601 | func_body.append(' if (pConnectionInfo->pConnection != NULL) {') |
| 602 | func_body.append(' glv_add_buffer_to_trace_packet(pHeader, (void**) &(pPacket->pConnectionInfo->pConnection), sizeof(void *), pConnectionInfo->pConnection);') |
| 603 | func_body.append(' glv_finalize_buffer_address(pHeader, (void**) &(pPacket->pConnectionInfo->pConnection));') |
| 604 | func_body.append(' }') |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 605 | if 'void' not in proto.ret or '*' in proto.ret: |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 606 | func_body.append(' pPacket->result = result;') |
| 607 | for idx in buff_ptr_indices: |
| 608 | func_body.append(' glv_finalize_buffer_address(pHeader, (void**)&(pPacket->%s));' % (proto.params[idx].name)) |
| 609 | func_body.append(' FINISH_TRACE_PACKET();') |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 610 | if 'void' not in proto.ret or '*' in proto.ret: |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 611 | func_body.append(' return result;') |
| 612 | func_body.append('}\n') |
| 613 | return "\n".join(func_body) |
| 614 | |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 615 | def _generate_packet_id_enum(self): |
| 616 | pid_enum = [] |
| 617 | pid_enum.append('enum GLV_TRACE_PACKET_ID_XGL') |
| 618 | pid_enum.append('{') |
| 619 | first_func = True |
| 620 | for proto in self.protos: |
| 621 | if first_func: |
| 622 | first_func = False |
Jon Ashburn | e224839 | 2014-12-16 18:37:04 -0700 | [diff] [blame] | 623 | pid_enum.append(' GLV_TPI_XGL_xglApiVersion = GLV_TPI_BEGIN_API_HERE,') |
| 624 | pid_enum.append(' GLV_TPI_XGL_xgl%s,' % proto.name) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 625 | else: |
| 626 | pid_enum.append(' GLV_TPI_XGL_xgl%s,' % proto.name) |
| 627 | pid_enum.append('};\n') |
| 628 | return "\n".join(pid_enum) |
| 629 | |
| 630 | def _generate_stringify_func(self): |
| 631 | func_body = [] |
| 632 | func_body.append('static const char *stringify_xgl_packet_id(const enum GLV_TRACE_PACKET_ID_XGL id, const glv_trace_packet_header* pHeader)') |
| 633 | func_body.append('{') |
| 634 | func_body.append(' static char str[1024];') |
| 635 | func_body.append(' switch(id) {') |
Jon Ashburn | e224839 | 2014-12-16 18:37:04 -0700 | [diff] [blame] | 636 | func_body.append(' case GLV_TPI_XGL_xglApiVersion:') |
| 637 | func_body.append(' {') |
| 638 | func_body.append(' struct_xglApiVersion* pPacket = (struct_xglApiVersion*)(pHeader->pBody);') |
| 639 | func_body.append(' snprintf(str, 1024, "xglApiVersion = 0x%x", pPacket->version);') |
| 640 | func_body.append(' return str;') |
| 641 | func_body.append(' }') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 642 | for proto in self.protos: |
| 643 | func_body.append(' case GLV_TPI_XGL_xgl%s:' % proto.name) |
| 644 | func_body.append(' {') |
| 645 | func_str = 'xgl%s(' % proto.name |
| 646 | print_vals = '' |
| 647 | create_func = False |
| 648 | if 'Create' in proto.name or 'Alloc' in proto.name or 'MapMemory' in proto.name: |
| 649 | create_func = True |
| 650 | for p in proto.params: |
| 651 | last_param = False |
| 652 | if (p.name == proto.params[-1].name): |
| 653 | last_param = True |
| 654 | if last_param and create_func: # last param of create func |
Jon Ashburn | 8f44563 | 2015-02-12 10:38:36 -0700 | [diff] [blame] | 655 | (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] | 656 | else: |
Jon Ashburn | 8f44563 | 2015-02-12 10:38:36 -0700 | [diff] [blame] | 657 | (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] | 658 | if last_param == True: |
Jon Ashburn | 8f44563 | 2015-02-12 10:38:36 -0700 | [diff] [blame] | 659 | func_str += '%s%s = %s)' % (ptr, p.name, pft) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 660 | print_vals += ', %s' % (pfi) |
| 661 | else: |
Jon Ashburn | 8f44563 | 2015-02-12 10:38:36 -0700 | [diff] [blame] | 662 | func_str += '%s%s = %s, ' % (ptr, p.name, pft) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 663 | print_vals += ', %s' % (pfi) |
| 664 | func_body.append(' struct_xgl%s* pPacket = (struct_xgl%s*)(pHeader->pBody);' % (proto.name, proto.name)) |
| 665 | func_body.append(' snprintf(str, 1024, "%s"%s);' % (func_str, print_vals)) |
| 666 | func_body.append(' return str;') |
| 667 | func_body.append(' }') |
| 668 | func_body.append(' default:') |
| 669 | func_body.append(' return NULL;') |
| 670 | func_body.append(' }') |
| 671 | func_body.append('};\n') |
| 672 | return "\n".join(func_body) |
| 673 | |
| 674 | def _generate_interp_func(self): |
| 675 | interp_func_body = [] |
| 676 | interp_func_body.append('static glv_trace_packet_header* interpret_trace_packet_xgl(glv_trace_packet_header* pHeader)') |
| 677 | interp_func_body.append('{') |
| 678 | interp_func_body.append(' if (pHeader == NULL)') |
| 679 | interp_func_body.append(' {') |
| 680 | interp_func_body.append(' return NULL;') |
| 681 | interp_func_body.append(' }') |
| 682 | interp_func_body.append(' switch (pHeader->packet_id)') |
| 683 | interp_func_body.append(' {') |
Jon Ashburn | e224839 | 2014-12-16 18:37:04 -0700 | [diff] [blame] | 684 | interp_func_body.append(' case GLV_TPI_XGL_xglApiVersion:\n {') |
| 685 | 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] | 686 | for proto in self.protos: |
| 687 | interp_func_body.append(' case GLV_TPI_XGL_xgl%s:\n {' % proto.name) |
| 688 | header_prefix = 'h' |
| 689 | if 'Wsi' in proto.name or 'Dbg' in proto.name: |
| 690 | header_prefix = 'pH' |
| 691 | interp_func_body.append(' return interpret_body_as_xgl%s(pHeader)->%seader;\n }' % (proto.name, header_prefix)) |
| 692 | interp_func_body.append(' default:') |
| 693 | interp_func_body.append(' return NULL;') |
| 694 | interp_func_body.append(' }') |
| 695 | interp_func_body.append(' return NULL;') |
| 696 | interp_func_body.append('}') |
| 697 | return "\n".join(interp_func_body) |
| 698 | |
| 699 | def _generate_struct_util_funcs(self): |
| 700 | pid_enum = [] |
| 701 | pid_enum.append('//=============================================================================') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 702 | 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)') |
| 703 | pid_enum.append('{') |
| 704 | 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] | 705 | pid_enum.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)&((*ppStruct)->pAppName), strlen(pInStruct->pAppName) + 1, pInStruct->pAppName);') |
| 706 | 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] | 707 | pid_enum.append(' glv_finalize_buffer_address(pHeader, (void**)&((*ppStruct)->pAppName));') |
| 708 | pid_enum.append(' glv_finalize_buffer_address(pHeader, (void**)&((*ppStruct)->pEngineName));') |
| 709 | pid_enum.append(' glv_finalize_buffer_address(pHeader, (void**)&*ppStruct);') |
| 710 | pid_enum.append('};\n') |
| 711 | pid_enum.append('//=============================================================================\n') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 712 | 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)') |
| 713 | pid_enum.append('{') |
| 714 | pid_enum.append(' uint32_t i;') |
| 715 | 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] | 716 | 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] | 717 | pid_enum.append(' glv_finalize_buffer_address(pHeader, (void**)&(*ppStruct)->pRequestedQueues);') |
| 718 | pid_enum.append(' if (pInStruct->extensionCount > 0) ') |
| 719 | pid_enum.append(' {') |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 720 | 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] | 721 | pid_enum.append(' for (i = 0; i < pInStruct->extensionCount; i++)') |
| 722 | pid_enum.append(' {') |
Chia-I Wu | 7461fcf | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 723 | 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] | 724 | pid_enum.append(' glv_finalize_buffer_address(pHeader, (void**)(&((*ppStruct)->ppEnabledExtensionNames[i])));') |
| 725 | pid_enum.append(' }') |
| 726 | pid_enum.append(' glv_finalize_buffer_address(pHeader, (void **)&(*ppStruct)->ppEnabledExtensionNames);') |
| 727 | pid_enum.append(' }') |
Jon Ashburn | 780112b | 2015-01-09 17:30:41 -0700 | [diff] [blame] | 728 | pid_enum.append(' XGL_LAYER_CREATE_INFO *pNext = ( XGL_LAYER_CREATE_INFO *) pInStruct->pNext;') |
| 729 | pid_enum.append(' while (pNext != NULL)') |
| 730 | pid_enum.append(' {') |
| 731 | pid_enum.append(' if ((pNext->sType == XGL_STRUCTURE_TYPE_LAYER_CREATE_INFO) && pNext->layerCount > 0)') |
| 732 | pid_enum.append(' {') |
| 733 | pid_enum.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)(&((*ppStruct)->pNext)), sizeof(XGL_LAYER_CREATE_INFO), pNext);') |
| 734 | pid_enum.append(' glv_finalize_buffer_address(pHeader, (void**)(&((*ppStruct)->pNext)));') |
| 735 | 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] | 736 | 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] | 737 | pid_enum.append(' for (i = 0; i < pNext->layerCount; i++)') |
| 738 | pid_enum.append(' {') |
| 739 | pid_enum.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)(&((*ppOutStruct)->ppActiveLayerNames[i])), strlen(pNext->ppActiveLayerNames[i]) + 1, pNext->ppActiveLayerNames[i]);') |
| 740 | pid_enum.append(' glv_finalize_buffer_address(pHeader, (void**)(&((*ppOutStruct)->ppActiveLayerNames[i])));') |
| 741 | pid_enum.append(' }') |
| 742 | pid_enum.append(' glv_finalize_buffer_address(pHeader, (void **)&(*ppOutStruct)->ppActiveLayerNames);') |
| 743 | pid_enum.append(' }') |
| 744 | pid_enum.append(' pNext = ( XGL_LAYER_CREATE_INFO *) pNext->pNext;') |
| 745 | pid_enum.append(' }') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 746 | pid_enum.append(' glv_finalize_buffer_address(pHeader, (void**)ppStruct);') |
| 747 | pid_enum.append('}\n') |
| 748 | pid_enum.append('static XGL_DEVICE_CREATE_INFO* interpret_XGL_DEVICE_CREATE_INFO(glv_trace_packet_header* pHeader, intptr_t ptr_variable)') |
| 749 | pid_enum.append('{') |
| 750 | 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') |
| 751 | pid_enum.append(' if (pXGL_DEVICE_CREATE_INFO != NULL)') |
| 752 | pid_enum.append(' {') |
Jon Ashburn | 780112b | 2015-01-09 17:30:41 -0700 | [diff] [blame] | 753 | pid_enum.append(' uint32_t i;') |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 754 | pid_enum.append(' const char** pNames;') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 755 | 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') |
| 756 | pid_enum.append(' if (pXGL_DEVICE_CREATE_INFO->extensionCount > 0)') |
| 757 | pid_enum.append(' {') |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 758 | 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);') |
| 759 | pid_enum.append(' pNames = (const char**)pXGL_DEVICE_CREATE_INFO->ppEnabledExtensionNames;') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 760 | pid_enum.append(' for (i = 0; i < pXGL_DEVICE_CREATE_INFO->extensionCount; i++)') |
| 761 | pid_enum.append(' {') |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 762 | 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] | 763 | pid_enum.append(' }') |
| 764 | pid_enum.append(' }') |
Jon Ashburn | 780112b | 2015-01-09 17:30:41 -0700 | [diff] [blame] | 765 | 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);') |
| 766 | pid_enum.append(' while (pNext != NULL)') |
| 767 | pid_enum.append(' {') |
| 768 | pid_enum.append(' if ((pNext->sType == XGL_STRUCTURE_TYPE_LAYER_CREATE_INFO) && pNext->layerCount > 0)') |
| 769 | pid_enum.append(' {') |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 770 | pid_enum.append(' pNext->ppActiveLayerNames = (const char**) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)(pNext->ppActiveLayerNames));') |
| 771 | pid_enum.append(' pNames = (const char**)pNext->ppActiveLayerNames;') |
Jon Ashburn | 780112b | 2015-01-09 17:30:41 -0700 | [diff] [blame] | 772 | pid_enum.append(' for (i = 0; i < pNext->layerCount; 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)(pNext->ppActiveLayerNames[i]));') |
Jon Ashburn | 780112b | 2015-01-09 17:30:41 -0700 | [diff] [blame] | 775 | pid_enum.append(' }') |
| 776 | pid_enum.append(' }') |
| 777 | pid_enum.append(' pNext = ( XGL_LAYER_CREATE_INFO *) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);') |
| 778 | pid_enum.append(' }') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 779 | pid_enum.append(' }\n') |
| 780 | pid_enum.append(' return pXGL_DEVICE_CREATE_INFO;') |
| 781 | pid_enum.append('}\n') |
| 782 | pid_enum.append('static void interpret_pipeline_shader(glv_trace_packet_header* pHeader, XGL_PIPELINE_SHADER* pShader)') |
| 783 | pid_enum.append('{') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 784 | pid_enum.append(' if (pShader != NULL)') |
| 785 | pid_enum.append(' {') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 786 | pid_enum.append(' // constant buffers') |
| 787 | pid_enum.append(' if (pShader->linkConstBufferCount > 0)') |
| 788 | pid_enum.append(' {') |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 789 | pid_enum.append(' uint32_t i;') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 790 | pid_enum.append(' pShader->pLinkConstBufferInfo = (const XGL_LINK_CONST_BUFFER*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pShader->pLinkConstBufferInfo);') |
| 791 | pid_enum.append(' for (i = 0; i < pShader->linkConstBufferCount; i++)') |
| 792 | pid_enum.append(' {') |
| 793 | 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] | 794 | 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] | 795 | pid_enum.append(' }') |
| 796 | pid_enum.append(' }') |
| 797 | pid_enum.append(' }') |
| 798 | pid_enum.append('}\n') |
| 799 | pid_enum.append('//=============================================================================') |
| 800 | return "\n".join(pid_enum) |
| 801 | |
Tobin Ehlis | 5099051 | 2015-02-05 11:29:45 -0700 | [diff] [blame] | 802 | # Interpret functions used on replay to read in packets and interpret their contents |
Peter Lohrmann | 56782cd | 2015-03-27 12:57:10 -0700 | [diff] [blame] | 803 | # This code gets generated into glv_vk_vk_structs.h file |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 804 | def _generate_interp_funcs(self): |
| 805 | # 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] | 806 | # 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] | 807 | 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] | 808 | 'pInfo->pAppName = (const char*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pAppInfo->pAppName);\n', |
| 809 | '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] | 810 | 'CreateShader' : {'param': 'pCreateInfo', 'txt': ['XGL_SHADER_CREATE_INFO* pInfo = (XGL_SHADER_CREATE_INFO*)pPacket->pCreateInfo;\n', |
| 811 | '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] | 812 | 'CreateDynamicViewportState' : {'param': 'pCreateInfo', 'txt': ['XGL_DYNAMIC_VP_STATE_CREATE_INFO* pInfo = (XGL_DYNAMIC_VP_STATE_CREATE_INFO*)pPacket->pCreateInfo;\n', |
| 813 | 'pInfo->pViewports = (XGL_VIEWPORT*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pCreateInfo->pViewports);\n', |
| 814 | '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] | 815 | 'CreateFramebuffer' : {'param': 'pCreateInfo', 'txt': ['XGL_FRAMEBUFFER_CREATE_INFO* pInfo = (XGL_FRAMEBUFFER_CREATE_INFO*)pPacket->pCreateInfo;\n', |
| 816 | 'pInfo->pColorAttachments = (XGL_COLOR_ATTACHMENT_BIND_INFO*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pCreateInfo->pColorAttachments);\n', |
| 817 | 'pInfo->pDepthStencilAttachment = (XGL_DEPTH_STENCIL_BIND_INFO*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pCreateInfo->pDepthStencilAttachment);\n']}, |
| 818 | 'CreateRenderPass' : {'param': 'pCreateInfo', 'txt': ['XGL_RENDER_PASS_CREATE_INFO* pInfo = (XGL_RENDER_PASS_CREATE_INFO*)pPacket->pCreateInfo;\n', |
| 819 | 'pInfo->pColorLoadOps = (XGL_ATTACHMENT_LOAD_OP*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pCreateInfo->pColorLoadOps);\n', |
| 820 | 'pInfo->pColorStoreOps = (XGL_ATTACHMENT_STORE_OP*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pCreateInfo->pColorStoreOps);\n', |
| 821 | '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] | 822 | 'CreateDescriptorRegion' : {'param': 'pCreateInfo', 'txt': ['XGL_DESCRIPTOR_REGION_CREATE_INFO* pInfo = (XGL_DESCRIPTOR_REGION_CREATE_INFO*)pPacket->pCreateInfo;\n', |
| 823 | '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] | 824 | 'CmdWaitEvents' : {'param': 'pWaitInfo', 'txt': ['XGL_EVENT_WAIT_INFO* pInfo = (XGL_EVENT_WAIT_INFO*)pPacket->pWaitInfo;\n', |
| 825 | 'pInfo->pEvents = (XGL_EVENT*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pWaitInfo->pEvents);\n', |
| 826 | 'pInfo->ppMemBarriers = (const void**) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pWaitInfo->ppMemBarriers);\n', |
| 827 | 'uint32_t i;\n', |
| 828 | 'for (i = 0; i < pInfo->memBarrierCount; i++) {\n', |
| 829 | ' void** ppLocalMemBarriers = (void**)&pInfo->ppMemBarriers[i];\n', |
| 830 | ' *ppLocalMemBarriers = (void*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pInfo->ppMemBarriers[i]);\n', |
| 831 | '}']}, |
| 832 | 'CmdPipelineBarrier' : {'param': 'pBarrier', 'txt': ['XGL_PIPELINE_BARRIER* pBarrier = (XGL_PIPELINE_BARRIER*)pPacket->pBarrier;\n', |
| 833 | 'pBarrier->pEvents = (XGL_SET_EVENT*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pBarrier->pEvents);\n', |
| 834 | 'pBarrier->ppMemBarriers = (const void**) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pBarrier->ppMemBarriers);\n', |
| 835 | 'uint32_t i;\n', |
| 836 | 'for (i = 0; i < pBarrier->memBarrierCount; i++) {\n', |
| 837 | ' void** ppLocalMemBarriers = (void**)&pBarrier->ppMemBarriers[i];\n', |
| 838 | ' *ppLocalMemBarriers = (void*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pBarrier->ppMemBarriers[i]);\n', |
| 839 | '}']}, |
Peter Lohrmann | 7810957 | 2015-03-10 15:30:36 -0700 | [diff] [blame] | 840 | 'CreateDescriptorSetLayout' : {'param': 'pSetLayoutInfoList', 'txt': ['if (pPacket->pSetLayoutInfoList->sType == XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO) {\n', |
| 841 | ' // need to make a non-const pointer to the pointer so that we can properly change the original pointer to the interpretted one\n', |
| 842 | ' void** ppNextVoidPtr = (void**)&(pPacket->pSetLayoutInfoList->pNext);\n', |
| 843 | ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pSetLayoutInfoList->pNext);\n', |
| 844 | ' XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO* pNext = (XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO*)pPacket->pSetLayoutInfoList->pNext;\n', |
| 845 | ' while (NULL != pNext)\n', ' {\n', |
| 846 | ' switch(pNext->sType)\n', ' {\n', |
| 847 | ' case XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO:\n', |
| 848 | ' {\n' , |
| 849 | ' void** ppNextVoidPtr = (void**)&pNext->pNext;\n', |
| 850 | ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n', |
| 851 | ' break;\n', |
| 852 | ' }\n', |
| 853 | ' default:\n', |
| 854 | ' {\n', |
| 855 | ' glv_LogError("Encountered an unexpected type in descriptor set layout create list.\\n");\n', |
| 856 | ' pPacket->header = NULL;\n', |
| 857 | ' pNext->pNext = NULL;\n', |
| 858 | ' }\n', |
Jon Ashburn | 7fd7eff | 2015-02-04 10:55:47 -0700 | [diff] [blame] | 859 | ' }\n', |
Peter Lohrmann | 7810957 | 2015-03-10 15:30:36 -0700 | [diff] [blame] | 860 | ' pNext = (XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO*)pNext->pNext;\n', |
| 861 | ' }\n', |
| 862 | '} else {\n', |
| 863 | ' // This is unexpected.\n', |
| 864 | ' glv_LogError("CreateDescriptorSetLayout must have LayoutInfoList stype of XGL_STRCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO\\n");\n', |
| 865 | ' pPacket->header = NULL;\n', |
Jon Ashburn | 7fd7eff | 2015-02-04 10:55:47 -0700 | [diff] [blame] | 866 | '}']}, |
Peter Lohrmann | 7810957 | 2015-03-10 15:30:36 -0700 | [diff] [blame] | 867 | 'BeginCommandBuffer' : {'param': 'pBeginInfo', 'txt': ['if (pPacket->pBeginInfo->sType == XGL_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO) {\n', |
| 868 | ' // need to make a non-const pointer to the pointer so that we can properly change the original pointer to the interpretted one\n', |
| 869 | ' XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO** ppNext = (XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO**)&(pPacket->pBeginInfo->pNext);\n', |
| 870 | ' *ppNext = (XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pBeginInfo->pNext);\n', |
| 871 | ' XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO* pNext = *ppNext;\n', |
| 872 | ' while (NULL != pNext)\n', ' {\n', |
| 873 | ' switch(pNext->sType)\n', ' {\n', |
| 874 | ' case XGL_STRUCTURE_TYPE_CMD_BUFFER_GRAPHICS_BEGIN_INFO:\n', |
| 875 | ' {\n', |
| 876 | ' ppNext = (XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO**) &pNext->pNext;\n', |
| 877 | ' *ppNext = (XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n', |
| 878 | ' break;\n', |
| 879 | ' }\n', |
| 880 | ' default:\n', |
| 881 | ' {\n', |
| 882 | ' glv_LogError("Encountered an unexpected type in begin command buffer list.\\n");\n', |
| 883 | ' pPacket->header = NULL;\n', |
| 884 | ' pNext->pNext = NULL;\n', |
| 885 | ' }\n', |
Jon Ashburn | a02bc24 | 2015-01-02 18:28:26 -0700 | [diff] [blame] | 886 | ' }\n', |
Peter Lohrmann | 7810957 | 2015-03-10 15:30:36 -0700 | [diff] [blame] | 887 | ' pNext = (XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO*)pNext->pNext;\n', |
Jon Ashburn | a02bc24 | 2015-01-02 18:28:26 -0700 | [diff] [blame] | 888 | ' }\n', |
Peter Lohrmann | 7810957 | 2015-03-10 15:30:36 -0700 | [diff] [blame] | 889 | '} else {\n', |
| 890 | ' // This is unexpected.\n', |
| 891 | ' glv_LogError("BeginCommandBuffer must have BeginInfo stype of XGL_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO.\\n");\n', |
| 892 | ' pPacket->header = NULL;\n', |
Jon Ashburn | a02bc24 | 2015-01-02 18:28:26 -0700 | [diff] [blame] | 893 | '}']}, |
Peter Lohrmann | 7810957 | 2015-03-10 15:30:36 -0700 | [diff] [blame] | 894 | 'AllocMemory' : {'param': 'pAllocInfo', 'txt': ['if (pPacket->pAllocInfo->sType == XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO) {\n', |
| 895 | ' XGL_MEMORY_ALLOC_INFO** ppNext = (XGL_MEMORY_ALLOC_INFO**) &(pPacket->pAllocInfo->pNext);\n', |
| 896 | ' *ppNext = (XGL_MEMORY_ALLOC_INFO*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pAllocInfo->pNext);\n', |
| 897 | ' XGL_MEMORY_ALLOC_INFO* pNext = (XGL_MEMORY_ALLOC_INFO*) *ppNext;\n', |
| 898 | ' while (NULL != pNext)\n', ' {\n', |
| 899 | ' switch(pNext->sType)\n', ' {\n', |
| 900 | ' case XGL_STRUCTURE_TYPE_MEMORY_ALLOC_BUFFER_INFO:\n', |
| 901 | ' case XGL_STRUCTURE_TYPE_MEMORY_ALLOC_IMAGE_INFO:\n', |
| 902 | ' {\n', |
| 903 | ' ppNext = (XGL_MEMORY_ALLOC_INFO **) &(pNext->pNext);\n', |
| 904 | ' *ppNext = (XGL_MEMORY_ALLOC_INFO*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n', |
| 905 | ' break;\n', |
| 906 | ' }\n', |
| 907 | ' default:\n', |
| 908 | ' {\n', |
| 909 | ' glv_LogError("Encountered an unexpected type alloc memory list.\\n");\n', |
| 910 | ' pPacket->header = NULL;\n', |
| 911 | ' pNext->pNext = NULL;\n', |
| 912 | ' }\n', |
Jon Ashburn | 3039e9c | 2015-02-03 07:33:48 -0700 | [diff] [blame] | 913 | ' }\n', |
Peter Lohrmann | 7810957 | 2015-03-10 15:30:36 -0700 | [diff] [blame] | 914 | ' pNext = (XGL_MEMORY_ALLOC_INFO*)pNext->pNext;\n', |
Jon Ashburn | 3039e9c | 2015-02-03 07:33:48 -0700 | [diff] [blame] | 915 | ' }\n', |
Peter Lohrmann | 7810957 | 2015-03-10 15:30:36 -0700 | [diff] [blame] | 916 | '} else {\n', |
| 917 | ' // This is unexpected.\n', |
| 918 | ' glv_LogError("AllocMemory must have AllocInfo stype of XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO.\\n");\n', |
| 919 | ' pPacket->header = NULL;\n', |
Jon Ashburn | 3039e9c | 2015-02-03 07:33:48 -0700 | [diff] [blame] | 920 | '}']}, |
Tobin Ehlis | 9570fc4 | 2015-02-04 10:53:31 -0700 | [diff] [blame] | 921 | 'UpdateDescriptors' : {'param': 'pUpdateChain', 'txt': ['XGL_UPDATE_SAMPLERS* pNext = (XGL_UPDATE_SAMPLERS*)pPacket->pUpdateChain;\n', |
| 922 | 'while ((NULL != pNext) && (XGL_NULL_HANDLE != pNext))\n', '{\n', |
| 923 | ' switch(pNext->sType)\n', ' {\n', |
| 924 | ' case XGL_STRUCTURE_TYPE_UPDATE_AS_COPY:\n', |
| 925 | ' {\n', |
| 926 | ' void** ppNextVoidPtr = (void**)&pNext->pNext;\n', |
| 927 | ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n', |
| 928 | ' break;\n', |
| 929 | ' }\n', |
| 930 | ' case XGL_STRUCTURE_TYPE_UPDATE_SAMPLERS:\n', |
| 931 | ' {\n', |
| 932 | ' void** ppNextVoidPtr = (void**)&pNext->pNext;\n', |
| 933 | ' XGL_UPDATE_SAMPLERS* pUS = (XGL_UPDATE_SAMPLERS*)pNext;\n', |
| 934 | ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n', |
| 935 | ' pUS->pSamplers = (XGL_SAMPLER*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pUS->pSamplers);\n', |
| 936 | ' break;\n', |
| 937 | ' }\n', |
| 938 | ' case XGL_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:\n', |
| 939 | ' {\n', |
| 940 | ' void** ppNextVoidPtr = (void**)&pNext->pNext;\n', |
| 941 | ' XGL_UPDATE_SAMPLER_TEXTURES* pUST = (XGL_UPDATE_SAMPLER_TEXTURES*)pNext;\n', |
| 942 | ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n', |
| 943 | ' pUST->pSamplerImageViews = (XGL_SAMPLER_IMAGE_VIEW_INFO*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pUST->pSamplerImageViews);\n', |
| 944 | ' uint32_t i;\n', |
| 945 | ' for (i = 0; i < pUST->count; i++) {\n', |
| 946 | ' XGL_IMAGE_VIEW_ATTACH_INFO** ppLocalImageView = (XGL_IMAGE_VIEW_ATTACH_INFO**)&pUST->pSamplerImageViews[i].pImageView;\n', |
| 947 | ' *ppLocalImageView = (XGL_IMAGE_VIEW_ATTACH_INFO*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pUST->pSamplerImageViews[i].pImageView);\n', |
| 948 | ' }\n', |
| 949 | ' break;\n', |
| 950 | ' }\n', |
| 951 | ' case XGL_STRUCTURE_TYPE_UPDATE_IMAGES:\n', |
| 952 | ' {\n', |
| 953 | ' void** ppNextVoidPtr = (void**)&pNext->pNext;\n', |
| 954 | ' XGL_UPDATE_IMAGES* pUI = (XGL_UPDATE_IMAGES*)pNext;\n', |
| 955 | ' *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] | 956 | ' XGL_IMAGE_VIEW_ATTACH_INFO** ppLocalImageView = (XGL_IMAGE_VIEW_ATTACH_INFO**)&pUI->pImageViews;\n', |
| 957 | ' *ppLocalImageView = (XGL_IMAGE_VIEW_ATTACH_INFO*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pUI->pImageViews);\n', |
| 958 | ' uint32_t i;\n', |
| 959 | ' for (i = 0; i < pUI->count; i++) {\n', |
| 960 | ' XGL_IMAGE_VIEW_ATTACH_INFO** ppLocalImageViews = (XGL_IMAGE_VIEW_ATTACH_INFO**)&pUI->pImageViews[i];\n', |
| 961 | ' *ppLocalImageViews = (XGL_IMAGE_VIEW_ATTACH_INFO*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pUI->pImageViews[i]);\n', |
| 962 | ' }\n', |
Tobin Ehlis | 9570fc4 | 2015-02-04 10:53:31 -0700 | [diff] [blame] | 963 | ' break;\n', |
| 964 | ' }\n', |
| 965 | ' case XGL_STRUCTURE_TYPE_UPDATE_BUFFERS:\n', |
| 966 | ' {\n', |
| 967 | ' void** ppNextVoidPtr = (void**)&pNext->pNext;\n', |
| 968 | ' XGL_UPDATE_BUFFERS* pUB = (XGL_UPDATE_BUFFERS*)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_BUFFER_VIEW_ATTACH_INFO** ppLocalBufferView = (XGL_BUFFER_VIEW_ATTACH_INFO**)&pUB->pBufferViews;\n', |
| 971 | ' *ppLocalBufferView = (XGL_BUFFER_VIEW_ATTACH_INFO*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pUB->pBufferViews);\n', |
| 972 | ' uint32_t i;\n', |
| 973 | ' for (i = 0; i < pUB->count; i++) {\n', |
| 974 | ' XGL_BUFFER_VIEW_ATTACH_INFO** ppLocalBufferViews = (XGL_BUFFER_VIEW_ATTACH_INFO**)&pUB->pBufferViews[i];\n', |
| 975 | ' *ppLocalBufferViews = (XGL_BUFFER_VIEW_ATTACH_INFO*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pUB->pBufferViews[i]);\n', |
| 976 | ' }\n', |
Tobin Ehlis | 9570fc4 | 2015-02-04 10:53:31 -0700 | [diff] [blame] | 977 | ' break;\n', |
| 978 | ' }\n', |
| 979 | ' default:\n', |
Peter Lohrmann | 7810957 | 2015-03-10 15:30:36 -0700 | [diff] [blame] | 980 | ' {\n', |
| 981 | ' glv_LogError("Encountered an unexpected type in update descriptors pUpdateChain.\\n");\n', |
| 982 | ' pPacket->header = NULL;\n', |
| 983 | ' pNext->pNext = NULL;\n', |
| 984 | ' }\n', |
Tobin Ehlis | 9570fc4 | 2015-02-04 10:53:31 -0700 | [diff] [blame] | 985 | ' }\n', |
| 986 | ' pNext = (XGL_UPDATE_SAMPLERS*)pNext->pNext;\n', |
| 987 | '}']}, |
Peter Lohrmann | 7810957 | 2015-03-10 15:30:36 -0700 | [diff] [blame] | 988 | 'CreateGraphicsPipeline' : {'param': 'pCreateInfo', 'txt': ['if (pPacket->pCreateInfo->sType == XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO) {\n', |
| 989 | ' // need to make a non-const pointer to the pointer so that we can properly change the original pointer to the interpretted one\n', |
| 990 | ' void** ppNextVoidPtr = (void**)&pPacket->pCreateInfo->pNext;\n', |
| 991 | ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pCreateInfo->pNext);\n', |
| 992 | ' XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* pNext = (XGL_PIPELINE_SHADER_STAGE_CREATE_INFO*)pPacket->pCreateInfo->pNext;\n', |
| 993 | ' while ((NULL != pNext) && (XGL_NULL_HANDLE != pNext))\n', '{\n', |
| 994 | ' switch(pNext->sType)\n', ' {\n', |
| 995 | ' case XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO:\n', |
| 996 | ' case XGL_STRUCTURE_TYPE_PIPELINE_TESS_STATE_CREATE_INFO:\n', |
| 997 | ' case XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO:\n', |
| 998 | ' case XGL_STRUCTURE_TYPE_PIPELINE_VP_STATE_CREATE_INFO:\n', |
| 999 | ' case XGL_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO:\n', |
| 1000 | ' case XGL_STRUCTURE_TYPE_PIPELINE_DS_STATE_CREATE_INFO:\n', |
| 1001 | ' {\n', |
| 1002 | ' void** ppNextVoidPtr = (void**)&pNext->pNext;\n', |
| 1003 | ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n', |
| 1004 | ' break;\n', |
| 1005 | ' }\n', |
| 1006 | ' case XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO:\n', |
| 1007 | ' {\n', |
| 1008 | ' void** ppNextVoidPtr = (void**)&pNext->pNext;\n', |
| 1009 | ' XGL_PIPELINE_CB_STATE_CREATE_INFO *pCb = (XGL_PIPELINE_CB_STATE_CREATE_INFO *) pNext;\n', |
| 1010 | ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n', |
| 1011 | ' pCb->pAttachments = (XGL_PIPELINE_CB_ATTACHMENT_STATE*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pCb->pAttachments);\n', |
| 1012 | ' break;\n', |
| 1013 | ' }\n', |
| 1014 | ' case XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_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 | ' interpret_pipeline_shader(pHeader, &pNext->shader);\n', |
| 1019 | ' break;\n', |
| 1020 | ' }\n', |
| 1021 | ' case XGL_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO:\n', |
| 1022 | ' {\n', |
| 1023 | ' void** ppNextVoidPtr = (void**)&pNext->pNext;\n', |
| 1024 | ' XGL_PIPELINE_VERTEX_INPUT_CREATE_INFO *pVi = (XGL_PIPELINE_VERTEX_INPUT_CREATE_INFO *) pNext;\n', |
| 1025 | ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n', |
| 1026 | ' pVi->pVertexBindingDescriptions = (XGL_VERTEX_INPUT_BINDING_DESCRIPTION*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pVi->pVertexBindingDescriptions);\n', |
| 1027 | ' pVi->pVertexAttributeDescriptions = (XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pVi->pVertexAttributeDescriptions);\n', |
| 1028 | ' break;\n', |
| 1029 | ' }\n', |
| 1030 | ' default:\n', |
| 1031 | ' {\n', |
| 1032 | ' glv_LogError("Encountered an unexpected type in pipeline state list.\\n");\n', |
| 1033 | ' pPacket->header = NULL;\n', |
| 1034 | ' pNext->pNext = NULL;\n', |
| 1035 | ' }\n', |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1036 | ' }\n', |
Peter Lohrmann | 7810957 | 2015-03-10 15:30:36 -0700 | [diff] [blame] | 1037 | ' pNext = (XGL_PIPELINE_SHADER_STAGE_CREATE_INFO*)pNext->pNext;\n', |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1038 | ' }\n', |
Peter Lohrmann | 7810957 | 2015-03-10 15:30:36 -0700 | [diff] [blame] | 1039 | '} else {\n', |
| 1040 | ' // This is unexpected.\n', |
| 1041 | ' glv_LogError("CreateGraphicsPipeline must have CreateInfo stype of XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO.\\n");\n', |
| 1042 | ' pPacket->header = NULL;\n', |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1043 | '}']}, |
Tobin Ehlis | 45bc7f8 | 2015-01-16 15:13:34 -0700 | [diff] [blame] | 1044 | '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] | 1045 | if_body = [] |
Jon Ashburn | e224839 | 2014-12-16 18:37:04 -0700 | [diff] [blame] | 1046 | if_body.append('typedef struct struct_xglApiVersion {') |
| 1047 | if_body.append(' glv_trace_packet_header* header;') |
| 1048 | if_body.append(' uint32_t version;') |
| 1049 | if_body.append('} struct_xglApiVersion;\n') |
| 1050 | if_body.append('static struct_xglApiVersion* interpret_body_as_xglApiVersion(glv_trace_packet_header* pHeader, BOOL check_version)') |
| 1051 | if_body.append('{') |
| 1052 | if_body.append(' struct_xglApiVersion* pPacket = (struct_xglApiVersion*)pHeader->pBody;') |
| 1053 | if_body.append(' pPacket->header = pHeader;') |
| 1054 | if_body.append(' if (check_version && pPacket->version != XGL_API_VERSION)') |
| 1055 | 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);') |
| 1056 | if_body.append(' return pPacket;') |
| 1057 | if_body.append('}\n') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1058 | for proto in self.protos: |
| 1059 | if 'Wsi' not in proto.name and 'Dbg' not in proto.name: |
| 1060 | if 'UnmapMemory' == proto.name: |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1061 | proto.params.append(xgl.Param("void*", "pData")) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1062 | if_body.append('typedef struct struct_xgl%s {' % proto.name) |
| 1063 | if_body.append(' glv_trace_packet_header* header;') |
| 1064 | for p in proto.params: |
| 1065 | if '[4]' in p.ty: |
| 1066 | if_body.append(' %s %s[4];' % (p.ty.strip('[4]'), p.name)) |
| 1067 | else: |
| 1068 | if_body.append(' %s %s;' % (p.ty, p.name)) |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1069 | if 'void' != proto.ret: |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1070 | if_body.append(' %s result;' % proto.ret) |
| 1071 | if_body.append('} struct_xgl%s;\n' % proto.name) |
| 1072 | if_body.append('static struct_xgl%s* interpret_body_as_xgl%s(glv_trace_packet_header* pHeader)' % (proto.name, proto.name)) |
| 1073 | if_body.append('{') |
| 1074 | if_body.append(' struct_xgl%s* pPacket = (struct_xgl%s*)pHeader->pBody;' % (proto.name, proto.name)) |
| 1075 | if_body.append(' pPacket->header = pHeader;') |
| 1076 | for p in proto.params: |
| 1077 | if '*' in p.ty: |
| 1078 | if 'DEVICE_CREATE_INFO' in p.ty: |
| 1079 | if_body.append(' pPacket->%s = interpret_XGL_DEVICE_CREATE_INFO(pHeader, (intptr_t)pPacket->%s);' % (p.name, p.name)) |
| 1080 | else: |
| 1081 | 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] | 1082 | # TODO : Generalize this custom code to kill dict data struct above. |
| 1083 | # 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] | 1084 | if proto.name in custom_case_dict and p.name == custom_case_dict[proto.name]['param']: |
| 1085 | if_body.append(' if (pPacket->%s != NULL)' % custom_case_dict[proto.name]['param']) |
| 1086 | if_body.append(' {') |
| 1087 | if_body.append(' %s' % " ".join(custom_case_dict[proto.name]['txt'])) |
| 1088 | if_body.append(' }') |
| 1089 | if_body.append(' return pPacket;') |
| 1090 | if_body.append('}\n') |
| 1091 | return "\n".join(if_body) |
| 1092 | |
| 1093 | def _generate_interp_funcs_ext(self, func_class='Wsi'): |
| 1094 | if_body = [] |
| 1095 | for proto in self.protos: |
| 1096 | if func_class in proto.name: |
| 1097 | if_body.append('typedef struct struct_xgl%s {' % proto.name) |
| 1098 | if_body.append(' glv_trace_packet_header* pHeader;') |
| 1099 | for p in proto.params: |
| 1100 | if_body.append(' %s %s;' % (p.ty, p.name)) |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1101 | if 'void' != proto.ret: |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1102 | if_body.append(' %s result;' % proto.ret) |
| 1103 | if_body.append('} struct_xgl%s;\n' % proto.name) |
| 1104 | if_body.append('static struct_xgl%s* interpret_body_as_xgl%s(glv_trace_packet_header* pHeader)' % (proto.name, proto.name)) |
| 1105 | if_body.append('{') |
| 1106 | if_body.append(' struct_xgl%s* pPacket = (struct_xgl%s*)pHeader->pBody;' % (proto.name, proto.name)) |
| 1107 | if_body.append(' pPacket->pHeader = pHeader;') |
| 1108 | for p in proto.params: |
| 1109 | if '*' in p.ty: |
| 1110 | if_body.append(' pPacket->%s = (%s)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->%s);' % (p.name, p.ty, p.name)) |
| 1111 | if_body.append(' return pPacket;') |
| 1112 | if_body.append('}\n') |
| 1113 | return "\n".join(if_body) |
| 1114 | |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1115 | def _generate_replay_func_ptrs(self): |
| 1116 | xf_body = [] |
| 1117 | xf_body.append('struct xglFuncs {') |
| 1118 | xf_body.append(' void init_funcs(void * libHandle);') |
| 1119 | xf_body.append(' void *m_libHandle;\n') |
| 1120 | for proto in self.protos: |
| 1121 | xf_body.append(' typedef %s( XGLAPI * type_xgl%s)(' % (proto.ret, proto.name)) |
| 1122 | for p in proto.params: |
| 1123 | if '[4]' in p.ty: |
| 1124 | xf_body.append(' %s %s[4],' % (p.ty.strip('[4]'), p.name)) |
| 1125 | else: |
| 1126 | xf_body.append(' %s %s,' % (p.ty, p.name)) |
| 1127 | xf_body[-1] = xf_body[-1].replace(',', ');') |
| 1128 | xf_body.append(' type_xgl%s real_xgl%s;' % (proto.name, proto.name)) |
| 1129 | xf_body.append('};') |
| 1130 | return "\n".join(xf_body) |
| 1131 | |
| 1132 | def _map_decl(self, type1, type2, name): |
| 1133 | return ' std::map<%s, %s> %s;' % (type1, type2, name) |
| 1134 | |
| 1135 | def _add_to_map_decl(self, type1, type2, name): |
| 1136 | txt = ' void add_to_map(%s* pTraceVal, %s* pReplayVal)\n {\n' % (type1, type2) |
| 1137 | txt += ' assert(pTraceVal != NULL);\n' |
| 1138 | txt += ' assert(pReplayVal != NULL);\n' |
| 1139 | txt += ' %s[*pTraceVal] = *pReplayVal;\n }' % name |
| 1140 | return txt |
| 1141 | |
| 1142 | def _rm_from_map_decl(self, ty, name): |
| 1143 | txt = ' void rm_from_map(const %s& key)\n {\n' % (ty) |
| 1144 | txt += ' %s.erase(key);\n }' % name |
| 1145 | return txt |
| 1146 | |
| 1147 | def _remap_decl(self, ty, name): |
| 1148 | txt = ' %s remap(const %s& value)\n {\n' % (ty, ty) |
| 1149 | txt += ' std::map<%s, %s>::const_iterator q = %s.find(value);\n' % (ty, ty, name) |
| 1150 | txt += ' return (q == %s.end()) ? XGL_NULL_HANDLE : q->second;\n }' % name |
| 1151 | return txt |
| 1152 | |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1153 | def _generate_replay_objmapper_class(self): |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 1154 | # Create dict mapping member var names to XGL type (i.e. 'm_imageViews' : 'XGL_IMAGE_VIEW') |
| 1155 | obj_map_dict = {} |
| 1156 | for ty in xgl.object_type_list: |
| 1157 | if ty in xgl.object_parent_list: |
| 1158 | continue |
| 1159 | mem_var = ty.replace('XGL_', '').lower() |
| 1160 | mem_var_list = mem_var.split('_') |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 1161 | mem_var = 'm_%s%ss' % (mem_var_list[0], "".join([m.title() for m in mem_var_list[1:]])) |
| 1162 | obj_map_dict[mem_var] = ty |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1163 | rc_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1164 | rc_body.append('typedef struct _XGLAllocInfo {') |
| 1165 | rc_body.append(' XGL_GPU_SIZE size;') |
| 1166 | rc_body.append(' void *pData;') |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1167 | rc_body.append('} XGLAllocInfo;') |
| 1168 | rc_body.append('') |
| 1169 | rc_body.append('class xglReplayObjMapper {') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1170 | rc_body.append('public:') |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1171 | rc_body.append(' xglReplayObjMapper() {}') |
| 1172 | rc_body.append(' ~xglReplayObjMapper() {}') |
| 1173 | rc_body.append('') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1174 | rc_body.append(self._map_decl('XGL_GPU_MEMORY', 'XGLAllocInfo', 'm_mapData')) |
| 1175 | # Custom code for 1-off memory mapping functions |
| 1176 | rc_body.append(' void add_entry_to_mapData(XGL_GPU_MEMORY handle, XGL_GPU_SIZE size)') |
| 1177 | rc_body.append(' {') |
| 1178 | rc_body.append(' XGLAllocInfo info;') |
| 1179 | rc_body.append(' info.pData = NULL;') |
| 1180 | rc_body.append(' info.size = size;') |
| 1181 | rc_body.append(' m_mapData.insert(std::pair<XGL_GPU_MEMORY, XGLAllocInfo>(handle, info));') |
| 1182 | rc_body.append(' }') |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1183 | rc_body.append('') |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1184 | rc_body.append(' void add_mapping_to_mapData(XGL_GPU_MEMORY handle, void *pData)') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1185 | rc_body.append(' {') |
| 1186 | rc_body.append(' std::map<XGL_GPU_MEMORY,XGLAllocInfo>::iterator it = m_mapData.find(handle);') |
| 1187 | rc_body.append(' if (it == m_mapData.end())') |
| 1188 | rc_body.append(' {') |
| 1189 | rc_body.append(' glv_LogWarn("add_mapping_to_mapData() could not find entry\\n");') |
| 1190 | rc_body.append(' return;') |
| 1191 | rc_body.append(' }') |
| 1192 | rc_body.append(' XGLAllocInfo &info = it->second;') |
| 1193 | rc_body.append(' if (info.pData != NULL)') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1194 | rc_body.append(' glv_LogWarn("add_mapping_to_mapData() data already mapped overwrite old mapping\\n");') |
Jon Ashburn | ceb5ee5 | 2015-02-20 13:10:52 -0700 | [diff] [blame] | 1195 | rc_body.append(' else if (pData == NULL)') |
| 1196 | rc_body.append(' glv_LogWarn("add_mapping_to_mapData() adding NULL pointer\\n");') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1197 | rc_body.append(' info.pData = pData;') |
| 1198 | rc_body.append(' }') |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1199 | rc_body.append('') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1200 | rc_body.append(' void rm_entry_from_mapData(XGL_GPU_MEMORY handle)') |
| 1201 | rc_body.append(' {') |
| 1202 | rc_body.append(' std::map<XGL_GPU_MEMORY,XGLAllocInfo>::iterator it = m_mapData.find(handle);') |
| 1203 | rc_body.append(' if (it == m_mapData.end())') |
| 1204 | rc_body.append(' return;') |
| 1205 | rc_body.append(' m_mapData.erase(it);') |
| 1206 | rc_body.append(' }') |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1207 | rc_body.append('') |
Jon Ashburn | b99b4d7 | 2015-03-02 17:12:31 -0700 | [diff] [blame] | 1208 | rc_body.append(' void rm_mapping_from_mapData(XGL_GPU_MEMORY handle, void* pData)') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1209 | rc_body.append(' {') |
| 1210 | rc_body.append(' std::map<XGL_GPU_MEMORY,XGLAllocInfo>::iterator it = m_mapData.find(handle);') |
| 1211 | rc_body.append(' if (it == m_mapData.end())') |
| 1212 | rc_body.append(' return;\n') |
| 1213 | rc_body.append(' XGLAllocInfo &info = it->second;') |
Jon Ashburn | b99b4d7 | 2015-03-02 17:12:31 -0700 | [diff] [blame] | 1214 | rc_body.append(' if (!pData || !info.pData)') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1215 | rc_body.append(' {') |
Jon Ashburn | b99b4d7 | 2015-03-02 17:12:31 -0700 | [diff] [blame] | 1216 | rc_body.append(' if (!pData)') |
| 1217 | rc_body.append(' glv_LogWarn("rm_mapping_from_mapData() null src pointer\\n");') |
| 1218 | rc_body.append(' else') |
| 1219 | rc_body.append(' glv_LogWarn("rm_mapping_from_mapData() null dest pointer size=%u\\n", info.size);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1220 | rc_body.append(' info.pData = NULL;') |
| 1221 | rc_body.append(' return;') |
| 1222 | rc_body.append(' }') |
Jon Ashburn | b99b4d7 | 2015-03-02 17:12:31 -0700 | [diff] [blame] | 1223 | rc_body.append(' memcpy(info.pData, pData, info.size);') |
| 1224 | rc_body.append(' info.pData = NULL;') |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1225 | rc_body.append(' }') |
| 1226 | rc_body.append('') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1227 | rc_body.append(' /*std::map<XGL_PHYSICAL_GPU, XGL_PHYSICAL_GPU> m_gpus;') |
| 1228 | rc_body.append(' void add_to_map(XGL_PHYSICAL_GPU* pTraceGpu, XGL_PHYSICAL_GPU* pReplayGpu)') |
| 1229 | rc_body.append(' {') |
| 1230 | rc_body.append(' assert(pTraceGpu != NULL);') |
| 1231 | rc_body.append(' assert(pReplayGpu != NULL);') |
| 1232 | rc_body.append(' m_gpus[*pTraceGpu] = *pReplayGpu;') |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1233 | rc_body.append(' }') |
| 1234 | rc_body.append('') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1235 | rc_body.append(' XGL_PHYSICAL_GPU remap(const XGL_PHYSICAL_GPU& gpu)') |
| 1236 | rc_body.append(' {') |
| 1237 | rc_body.append(' std::map<XGL_PHYSICAL_GPU, XGL_PHYSICAL_GPU>::const_iterator q = m_gpus.find(gpu);') |
| 1238 | rc_body.append(' return (q == m_gpus.end()) ? XGL_NULL_HANDLE : q->second;') |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1239 | rc_body.append(' }*/') |
| 1240 | rc_body.append('') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1241 | rc_body.append(' void clear_all_map_handles()\n {') |
| 1242 | for var in sorted(obj_map_dict): |
| 1243 | rc_body.append(' %s.clear();' % var) |
| 1244 | rc_body.append(' }') |
| 1245 | for var in sorted(obj_map_dict): |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1246 | rc_body.append('') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1247 | rc_body.append(self._map_decl(obj_map_dict[var], obj_map_dict[var], var)) |
| 1248 | rc_body.append(self._add_to_map_decl(obj_map_dict[var], obj_map_dict[var], var)) |
| 1249 | rc_body.append(self._rm_from_map_decl(obj_map_dict[var], var)) |
| 1250 | rc_body.append(self._remap_decl(obj_map_dict[var], var)) |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 1251 | # XGL_DYNAMIC_STATE_OBJECT code |
| 1252 | state_obj_remap_types = xgl.object_dynamic_state_list |
| 1253 | rc_body.append(' XGL_DYNAMIC_STATE_OBJECT remap(const XGL_DYNAMIC_STATE_OBJECT& state)\n {') |
| 1254 | rc_body.append(' XGL_DYNAMIC_STATE_OBJECT obj;') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1255 | for t in state_obj_remap_types: |
| 1256 | rc_body.append(' if ((obj = remap(static_cast <%s> (state))) != XGL_NULL_HANDLE)' % t) |
| 1257 | rc_body.append(' return obj;') |
| 1258 | rc_body.append(' return XGL_NULL_HANDLE;\n }') |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 1259 | 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] | 1260 | for t in state_obj_remap_types: |
| 1261 | rc_body.append(' rm_from_map(static_cast <%s> (state));' % t) |
| 1262 | rc_body.append(' }') |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1263 | rc_body.append('') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1264 | # OBJECT code |
| 1265 | rc_body.append(' XGL_OBJECT remap(const XGL_OBJECT& object)\n {') |
| 1266 | rc_body.append(' XGL_OBJECT obj;') |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 1267 | obj_remap_types = xgl.object_list |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1268 | for var in obj_remap_types: |
| 1269 | rc_body.append(' if ((obj = remap(static_cast <%s> (object))) != XGL_NULL_HANDLE)' % (var)) |
| 1270 | rc_body.append(' return obj;') |
| 1271 | rc_body.append(' return XGL_NULL_HANDLE;\n }') |
| 1272 | rc_body.append(' void rm_from_map(const XGL_OBJECT & objKey)\n {') |
| 1273 | for var in obj_remap_types: |
| 1274 | rc_body.append(' rm_from_map(static_cast <%s> (objKey));' % (var)) |
| 1275 | rc_body.append(' }') |
| 1276 | rc_body.append(' XGL_BASE_OBJECT remap(const XGL_BASE_OBJECT& object)\n {') |
| 1277 | rc_body.append(' XGL_BASE_OBJECT obj;') |
| 1278 | base_obj_remap_types = ['XGL_DEVICE', 'XGL_QUEUE', 'XGL_GPU_MEMORY', 'XGL_OBJECT'] |
| 1279 | for t in base_obj_remap_types: |
| 1280 | rc_body.append(' if ((obj = remap(static_cast <%s> (object))) != XGL_NULL_HANDLE)' % t) |
| 1281 | rc_body.append(' return obj;') |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1282 | rc_body.append(' return XGL_NULL_HANDLE;') |
| 1283 | rc_body.append(' }\n') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1284 | rc_body.append('};') |
| 1285 | return "\n".join(rc_body) |
| 1286 | |
Jon Ashburn | b7b98a0 | 2014-12-18 17:03:34 -0700 | [diff] [blame] | 1287 | |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1288 | def _generate_replay_init_funcs(self): |
| 1289 | rif_body = [] |
| 1290 | rif_body.append('void xglFuncs::init_funcs(void * handle)\n{\n m_libHandle = handle;') |
| 1291 | for proto in self.protos: |
| 1292 | rif_body.append(' real_xgl%s = (type_xgl%s)(glv_platform_get_library_entrypoint(handle, "xgl%s"));' % (proto.name, proto.name, proto.name)) |
| 1293 | rif_body.append('}') |
| 1294 | return "\n".join(rif_body) |
| 1295 | |
| 1296 | def _get_packet_param(self, t, n): |
| 1297 | # list of types that require remapping |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 1298 | remap_list = xgl.object_type_list |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 1299 | param_exclude_list = ['p1', 'p2', 'pGpus', 'pDescriptorSets'] |
| 1300 | if t.strip('*').replace('const ', '') in remap_list and n not in param_exclude_list: |
| 1301 | if '*' in t: |
| 1302 | if 'const ' not in t: |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1303 | return 'm_objMapper.remap(*pPacket->%s)' % (n) |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 1304 | else: # TODO : Don't remap array ptrs? |
| 1305 | return 'pPacket->%s' % (n) |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1306 | return 'm_objMapper.remap(pPacket->%s)' % (n) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1307 | return 'pPacket->%s' % (n) |
| 1308 | |
Tobin Ehlis | 45bc7f8 | 2015-01-16 15:13:34 -0700 | [diff] [blame] | 1309 | def _gen_replay_enum_gpus(self): |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1310 | ieg_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1311 | ieg_body.append(' returnValue = manually_handle_xglEnumerateGpus(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1312 | return "\n".join(ieg_body) |
| 1313 | |
| 1314 | def _gen_replay_get_gpu_info(self): |
| 1315 | ggi_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1316 | ggi_body.append(' returnValue = manually_handle_xglGetGpuInfo(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1317 | return "\n".join(ggi_body) |
| 1318 | |
| 1319 | def _gen_replay_create_device(self): |
| 1320 | cd_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1321 | cd_body.append(' returnValue = manually_handle_xglCreateDevice(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1322 | return "\n".join(cd_body) |
| 1323 | |
| 1324 | def _gen_replay_get_extension_support(self): |
| 1325 | ges_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1326 | ges_body.append(' returnValue = manually_handle_xglGetExtensionSupport(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1327 | return "\n".join(ges_body) |
| 1328 | |
| 1329 | def _gen_replay_queue_submit(self): |
| 1330 | qs_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1331 | qs_body.append(' returnValue = manually_handle_xglQueueSubmit(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1332 | return "\n".join(qs_body) |
| 1333 | |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1334 | def _gen_replay_get_object_info(self): |
| 1335 | goi_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1336 | goi_body.append(' returnValue = manually_handle_xglGetObjectInfo(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1337 | return "\n".join(goi_body) |
| 1338 | |
| 1339 | def _gen_replay_get_format_info(self): |
| 1340 | gfi_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1341 | gfi_body.append(' returnValue = manually_handle_xglGetFormatInfo(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1342 | return "\n".join(gfi_body) |
| 1343 | |
| 1344 | def _gen_replay_get_image_subresource_info(self): |
| 1345 | isi_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1346 | isi_body.append(' returnValue = manually_handle_xglGetImageSubresourceInfo(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1347 | return "\n".join(isi_body) |
| 1348 | |
Tobin Ehlis | fc04b89 | 2015-01-22 12:29:31 -0700 | [diff] [blame] | 1349 | def _gen_replay_update_descriptors(self): |
| 1350 | ud_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1351 | ud_body.append(' returnValue = manually_handle_xglUpdateDescriptors(pPacket);') |
Tobin Ehlis | 8361b56 | 2015-02-03 14:41:26 -0700 | [diff] [blame] | 1352 | return "\n".join(ud_body) |
Tobin Ehlis | fc04b89 | 2015-01-22 12:29:31 -0700 | [diff] [blame] | 1353 | |
| 1354 | def _gen_replay_create_descriptor_set_layout(self): |
| 1355 | cdsl_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1356 | cdsl_body.append(' returnValue = manually_handle_xglCreateDescriptorSetLayout(pPacket);') |
Tobin Ehlis | 8361b56 | 2015-02-03 14:41:26 -0700 | [diff] [blame] | 1357 | return "\n".join(cdsl_body) |
Tobin Ehlis | fc04b89 | 2015-01-22 12:29:31 -0700 | [diff] [blame] | 1358 | |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1359 | def _gen_replay_create_graphics_pipeline(self): |
| 1360 | cgp_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1361 | cgp_body.append(' returnValue = manually_handle_xglCreateGraphicsPipeline(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1362 | return "\n".join(cgp_body) |
| 1363 | |
Tobin Ehlis | 5099051 | 2015-02-05 11:29:45 -0700 | [diff] [blame] | 1364 | def _gen_replay_cmd_wait_events(self): |
| 1365 | cwe_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1366 | cwe_body.append(' returnValue = manually_handle_xglCmdWaitEvents(pPacket);') |
Tobin Ehlis | 5099051 | 2015-02-05 11:29:45 -0700 | [diff] [blame] | 1367 | return "\n".join(cwe_body) |
| 1368 | |
Jon Ashburn | c46fc50 | 2015-02-10 10:36:22 -0700 | [diff] [blame] | 1369 | def _gen_replay_cmd_pipeline_barrier(self): |
| 1370 | cpb_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1371 | cpb_body.append(' returnValue = manually_handle_xglCmdPipelineBarrier(pPacket);') |
Jon Ashburn | c46fc50 | 2015-02-10 10:36:22 -0700 | [diff] [blame] | 1372 | return "\n".join(cpb_body) |
| 1373 | |
Jon Ashburn | a02bc24 | 2015-01-02 18:28:26 -0700 | [diff] [blame] | 1374 | def _gen_replay_create_framebuffer(self): |
| 1375 | cf_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1376 | cf_body.append(' returnValue = manually_handle_xglCreateFramebuffer(pPacket);') |
Jon Ashburn | a02bc24 | 2015-01-02 18:28:26 -0700 | [diff] [blame] | 1377 | return "\n".join(cf_body) |
| 1378 | |
| 1379 | def _gen_replay_create_renderpass(self): |
| 1380 | cr_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1381 | cr_body.append(' returnValue = manually_handle_xglCreateRenderPass(pPacket);') |
Jon Ashburn | a02bc24 | 2015-01-02 18:28:26 -0700 | [diff] [blame] | 1382 | return "\n".join(cr_body) |
| 1383 | |
| 1384 | def _gen_replay_begin_command_buffer(self): |
| 1385 | bcb_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1386 | bcb_body.append(' returnValue = manually_handle_xglBeginCommandBuffer(pPacket);') |
Jon Ashburn | a02bc24 | 2015-01-02 18:28:26 -0700 | [diff] [blame] | 1387 | return "\n".join(bcb_body) |
| 1388 | |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1389 | def _gen_replay_store_pipeline(self): |
| 1390 | sp_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1391 | sp_body.append(' returnValue = manually_handle_xglStorePipeline(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1392 | return "\n".join(sp_body) |
| 1393 | |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1394 | def _gen_replay_get_multi_gpu_compatibility(self): |
| 1395 | gmgc_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1396 | gmgc_body.append(' returnValue = manually_handle_xglGetMultiGpuCompatibility(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1397 | return "\n".join(gmgc_body) |
| 1398 | |
| 1399 | def _gen_replay_destroy_object(self): |
| 1400 | do_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1401 | do_body.append(' returnValue = manually_handle_xglDestroyObject(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1402 | return "\n".join(do_body) |
| 1403 | |
| 1404 | def _gen_replay_wait_for_fences(self): |
| 1405 | wf_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1406 | wf_body.append(' returnValue = manually_handle_xglWaitForFences(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1407 | return "\n".join(wf_body) |
| 1408 | |
| 1409 | def _gen_replay_wsi_associate_connection(self): |
| 1410 | wac_body = [] |
Peter Lohrmann | 95c369a | 2015-04-02 10:06:19 -0700 | [diff] [blame] | 1411 | wac_body.append(' returnValue = manually_handle_xglWsiX11AssociateConnection(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1412 | return "\n".join(wac_body) |
| 1413 | |
| 1414 | def _gen_replay_wsi_get_msc(self): |
| 1415 | wgm_body = [] |
Peter Lohrmann | 95c369a | 2015-04-02 10:06:19 -0700 | [diff] [blame] | 1416 | wgm_body.append(' returnValue = manually_handle_xglWsiX11GetMSC(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1417 | return "\n".join(wgm_body) |
| 1418 | |
| 1419 | def _gen_replay_wsi_create_presentable_image(self): |
| 1420 | cpi_body = [] |
Peter Lohrmann | 95c369a | 2015-04-02 10:06:19 -0700 | [diff] [blame] | 1421 | cpi_body.append(' returnValue = manually_handle_xglWsiX11CreatePresentableImage(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1422 | return "\n".join(cpi_body) |
| 1423 | |
| 1424 | def _gen_replay_wsi_queue_present(self): |
| 1425 | wqp_body = [] |
Peter Lohrmann | 95c369a | 2015-04-02 10:06:19 -0700 | [diff] [blame] | 1426 | wqp_body.append(' returnValue = manually_handle_xglWsiX11QueuePresent(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1427 | return "\n".join(wqp_body) |
| 1428 | |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1429 | def _gen_replay_free_memory(self): |
| 1430 | fm_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1431 | fm_body.append(' returnValue = manually_handle_xglFreeMemory(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1432 | return "\n".join(fm_body) |
| 1433 | |
| 1434 | def _gen_replay_map_memory(self): |
| 1435 | mm_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1436 | mm_body.append(' returnValue = manually_handle_xglMapMemory(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1437 | return "\n".join(mm_body) |
| 1438 | |
| 1439 | def _gen_replay_unmap_memory(self): |
| 1440 | um_body = [] |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1441 | um_body.append(' returnValue = manually_handle_xglUnmapMemory(pPacket);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1442 | return "\n".join(um_body) |
| 1443 | |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1444 | # 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] | 1445 | def _gen_replay_bind_dynamic_memory_view(self): |
| 1446 | bdmv_body = [] |
| 1447 | bdmv_body.append(' XGL_MEMORY_VIEW_ATTACH_INFO memView;') |
| 1448 | 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] | 1449 | bdmv_body.append(' memView.mem = m_objMapper.remap(pPacket->pMemView->mem);') |
| 1450 | 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] | 1451 | return "\n".join(bdmv_body) |
| 1452 | |
Tobin Ehlis | 5099051 | 2015-02-05 11:29:45 -0700 | [diff] [blame] | 1453 | # 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] | 1454 | def _generate_replay(self): |
| 1455 | # map protos to custom functions if body is fully custom |
Tobin Ehlis | 45bc7f8 | 2015-01-16 15:13:34 -0700 | [diff] [blame] | 1456 | custom_body_dict = {'EnumerateGpus': self._gen_replay_enum_gpus, |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1457 | 'GetGpuInfo': self._gen_replay_get_gpu_info, |
| 1458 | 'CreateDevice': self._gen_replay_create_device, |
| 1459 | 'GetExtensionSupport': self._gen_replay_get_extension_support, |
| 1460 | 'QueueSubmit': self._gen_replay_queue_submit, |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1461 | 'GetObjectInfo': self._gen_replay_get_object_info, |
| 1462 | 'GetFormatInfo': self._gen_replay_get_format_info, |
| 1463 | 'GetImageSubresourceInfo': self._gen_replay_get_image_subresource_info, |
| 1464 | 'CreateGraphicsPipeline': self._gen_replay_create_graphics_pipeline, |
Jon Ashburn | a02bc24 | 2015-01-02 18:28:26 -0700 | [diff] [blame] | 1465 | 'CreateFramebuffer': self._gen_replay_create_framebuffer, |
| 1466 | 'CreateRenderPass': self._gen_replay_create_renderpass, |
| 1467 | 'BeginCommandBuffer': self._gen_replay_begin_command_buffer, |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1468 | 'StorePipeline': self._gen_replay_store_pipeline, |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1469 | 'GetMultiGpuCompatibility': self._gen_replay_get_multi_gpu_compatibility, |
| 1470 | 'DestroyObject': self._gen_replay_destroy_object, |
| 1471 | 'WaitForFences': self._gen_replay_wait_for_fences, |
| 1472 | 'WsiX11AssociateConnection': self._gen_replay_wsi_associate_connection, |
| 1473 | 'WsiX11GetMSC': self._gen_replay_wsi_get_msc, |
| 1474 | 'WsiX11CreatePresentableImage': self._gen_replay_wsi_create_presentable_image, |
| 1475 | 'WsiX11QueuePresent': self._gen_replay_wsi_queue_present, |
| 1476 | 'FreeMemory': self._gen_replay_free_memory, |
| 1477 | 'MapMemory': self._gen_replay_map_memory, |
| 1478 | 'UnmapMemory': self._gen_replay_unmap_memory, |
Tobin Ehlis | 8361b56 | 2015-02-03 14:41:26 -0700 | [diff] [blame] | 1479 | 'CmdBindDynamicMemoryView': self._gen_replay_bind_dynamic_memory_view, |
| 1480 | 'UpdateDescriptors': self._gen_replay_update_descriptors, |
Tobin Ehlis | 5099051 | 2015-02-05 11:29:45 -0700 | [diff] [blame] | 1481 | 'CreateDescriptorSetLayout': self._gen_replay_create_descriptor_set_layout, |
Jon Ashburn | c46fc50 | 2015-02-10 10:36:22 -0700 | [diff] [blame] | 1482 | 'CmdWaitEvents': self._gen_replay_cmd_wait_events, |
| 1483 | 'CmdPipelineBarrier': self._gen_replay_cmd_pipeline_barrier} |
Tobin Ehlis | fc04b89 | 2015-01-22 12:29:31 -0700 | [diff] [blame] | 1484 | # TODO : Need to guard CreateInstance with "if (!m_display->m_initedXGL)" check |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1485 | # 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] | 1486 | custom_check_ret_val = ['EnumerateGpus', 'GetGpuInfo', 'CreateDevice', 'GetExtensionSupport', 'QueueSubmit', 'GetObjectInfo', |
| 1487 | 'GetFormatInfo', 'GetImageSubresourceInfo', 'CreateDescriptorSetLayout', 'CreateGraphicsPipeline', |
| 1488 | 'CreateFramebuffer', 'CreateRenderPass', 'BeginCommandBuffer', 'StorePipeline', 'GetMultiGpuCompatibility', |
Peter Lohrmann | 95c369a | 2015-04-02 10:06:19 -0700 | [diff] [blame] | 1489 | 'DestroyObject', 'WaitForFences', 'FreeMemory', 'MapMemory', 'UnmapMemory', |
| 1490 | 'WsiX11AssociateConnection', 'WsiX11GetMSC', 'WsiX11CreatePresentableImage', 'WsiX11QueuePresent'] |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1491 | # multi-gpu Open funcs w/ list of local params to create |
| 1492 | custom_open_params = {'OpenSharedMemory': (-1,), |
| 1493 | 'OpenSharedQueueSemaphore': (-1,), |
| 1494 | 'OpenPeerMemory': (-1,), |
| 1495 | 'OpenPeerImage': (-1, -2,)} |
| 1496 | # Functions that create views are unique from other create functions |
Jon Ashburn | b1b63ed | 2015-02-03 11:24:08 -0700 | [diff] [blame] | 1497 | create_view_list = ['CreateBufferView', 'CreateImageView', 'CreateColorAttachmentView', 'CreateDepthStencilView', 'CreateComputePipeline'] |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1498 | # 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] | 1499 | special_create_list = ['LoadPipeline', 'AllocMemory', 'GetDeviceQueue', 'PinSystemMemory', 'AllocDescriptorSets'] |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1500 | # A couple funcs use do while loops |
| 1501 | 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'} |
| 1502 | rbody = [] |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1503 | rbody.append('glv_replay::GLV_REPLAY_RESULT xglReplay::replay(glv_trace_packet_header *packet)') |
| 1504 | rbody.append('{') |
| 1505 | rbody.append(' glv_replay::GLV_REPLAY_RESULT returnValue = glv_replay::GLV_REPLAY_SUCCESS;') |
| 1506 | rbody.append(' XGL_RESULT replayResult = XGL_ERROR_UNKNOWN;') |
| 1507 | rbody.append(' switch (packet->packet_id)') |
| 1508 | rbody.append(' {') |
Jon Ashburn | 6f4b303 | 2015-02-03 08:57:28 -0700 | [diff] [blame] | 1509 | rbody.append(' case GLV_TPI_XGL_xglApiVersion:') |
| 1510 | rbody.append(' break; // nothing to replay on the version packet') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1511 | for proto in self.protos: |
| 1512 | ret_value = False |
| 1513 | create_view = False |
| 1514 | create_func = False |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 1515 | # TODO : How to handle void* return of GetProcAddr? |
| 1516 | 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] | 1517 | ret_value = True |
| 1518 | if proto.name in create_view_list: |
| 1519 | create_view = True |
| 1520 | elif 'Create' in proto.name or proto.name in special_create_list: |
| 1521 | create_func = True |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1522 | rbody.append(' case GLV_TPI_XGL_xgl%s:' % proto.name) |
| 1523 | rbody.append(' {') |
| 1524 | rbody.append(' struct_xgl%s* pPacket = (struct_xgl%s*)(packet->pBody);' % (proto.name, proto.name)) |
| 1525 | if proto.name in custom_body_dict: |
| 1526 | rbody.append(custom_body_dict[proto.name]()) |
| 1527 | else: |
| 1528 | if proto.name in custom_open_params: |
| 1529 | rbody.append(' XGL_DEVICE handle;') |
| 1530 | for pidx in custom_open_params[proto.name]: |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 1531 | 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] | 1532 | rbody.append(' handle = m_objMapper.remap(pPacket->device);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1533 | elif create_view: |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 1534 | rbody.append(' %s createInfo;' % (proto.params[1].ty.strip('*').replace('const ', ''))) |
| 1535 | 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] | 1536 | if 'CreateComputePipeline' == proto.name: |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1537 | rbody.append(' createInfo.cs.shader = m_objMapper.remap(pPacket->pCreateInfo->cs.shader);') |
Jon Ashburn | b1b63ed | 2015-02-03 11:24:08 -0700 | [diff] [blame] | 1538 | elif 'CreateBufferView' == proto.name: |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1539 | rbody.append(' createInfo.buffer = m_objMapper.remap(pPacket->pCreateInfo->buffer);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1540 | else: |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1541 | rbody.append(' createInfo.image = m_objMapper.remap(pPacket->pCreateInfo->image);') |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 1542 | 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] | 1543 | elif create_func: # Declare local var to store created handle into |
Tobin Ehlis | 2012fce | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 1544 | 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] | 1545 | if 'AllocDescriptorSets' == proto.name: |
Jon Ashburn | 200ccb5 | 2015-02-04 12:57:25 -0700 | [diff] [blame] | 1546 | rbody.append(' %s local_%s[100];' % (proto.params[-2].ty.strip('*').replace('const ', ''), proto.params[-2].name)) |
| 1547 | rbody.append(' XGL_DESCRIPTOR_SET_LAYOUT localDescSets[100];') |
| 1548 | rbody.append(' assert(pPacket->count <= 100);') |
| 1549 | rbody.append(' for (uint32_t i = 0; i < pPacket->count; i++)') |
| 1550 | rbody.append(' {') |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1551 | 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] | 1552 | rbody.append(' }') |
| 1553 | elif proto.name == 'ClearDescriptorSets': |
| 1554 | rbody.append(' XGL_DESCRIPTOR_SET localDescSets[100];') |
| 1555 | rbody.append(' assert(pPacket->count <= 100);') |
| 1556 | rbody.append(' for (uint32_t i = 0; i < pPacket->count; i++)') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1557 | rbody.append(' {') |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1558 | 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] | 1559 | rbody.append(' }') |
| 1560 | elif proto.name in do_while_dict: |
| 1561 | rbody.append(' do {') |
Jon Ashburn | ffd5f14 | 2015-02-03 13:39:05 -0700 | [diff] [blame] | 1562 | elif proto.name == 'EnumerateLayers': |
| 1563 | rbody.append(' char **bufptr = GLV_NEW_ARRAY(char *, pPacket->maxLayerCount);') |
| 1564 | rbody.append(' char **ptrLayers = (pPacket->pOutLayers == NULL) ? bufptr : (char **) pPacket->pOutLayers;') |
| 1565 | rbody.append(' for (unsigned int i = 0; i < pPacket->maxLayerCount; i++)') |
| 1566 | rbody.append(' bufptr[i] = GLV_NEW_ARRAY(char, pPacket->maxStringSize);') |
Jon Ashburn | d698ca2 | 2015-02-12 12:37:46 -0700 | [diff] [blame] | 1567 | elif proto.name == 'DestroyInstance': |
| 1568 | rbody.append(' xglDbgUnregisterMsgCallback(g_fpDbgMsgCallback);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1569 | rr_string = ' ' |
| 1570 | if ret_value: |
| 1571 | rr_string = ' replayResult = ' |
| 1572 | rr_string += 'm_xglFuncs.real_xgl%s(' % proto.name |
| 1573 | for p in proto.params: |
| 1574 | # For last param of Create funcs, pass address of param |
Tobin Ehlis | 377b462 | 2015-01-20 13:50:59 -0700 | [diff] [blame] | 1575 | if create_func: |
| 1576 | if p.name == proto.params[-1].name: |
| 1577 | rr_string += '&local_%s, ' % p.name |
| 1578 | elif proto.name == 'AllocDescriptorSets' and p.name == proto.params[-2].name: |
| 1579 | rr_string += 'local_%s, ' % p.name |
| 1580 | else: |
| 1581 | rr_string += '%s, ' % self._get_packet_param(p.ty, p.name) |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1582 | else: |
| 1583 | rr_string += '%s, ' % self._get_packet_param(p.ty, p.name) |
| 1584 | rr_string = '%s);' % rr_string[:-2] |
Jon Ashburn | 200ccb5 | 2015-02-04 12:57:25 -0700 | [diff] [blame] | 1585 | if proto.name in custom_open_params: |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1586 | rr_list = rr_string.split(', ') |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1587 | 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] | 1588 | for pidx in custom_open_params[proto.name]: |
| 1589 | rr_list[pidx] = '&local_%s' % proto.params[pidx].name |
| 1590 | rr_string = ', '.join(rr_list) |
| 1591 | rr_string += ');' |
| 1592 | elif create_view: |
| 1593 | rr_list = rr_string.split(', ') |
| 1594 | rr_list[-2] = '&createInfo' |
| 1595 | rr_list[-1] = '&local_%s);' % proto.params[-1].name |
| 1596 | rr_string = ', '.join(rr_list) |
| 1597 | # this is a sneaky shortcut to use generic create code below to add_to_map |
| 1598 | create_func = True |
Jon Ashburn | ffd5f14 | 2015-02-03 13:39:05 -0700 | [diff] [blame] | 1599 | elif proto.name == 'EnumerateLayers': |
| 1600 | rr_string = rr_string.replace('pPacket->pOutLayers', 'ptrLayers') |
Jon Ashburn | 200ccb5 | 2015-02-04 12:57:25 -0700 | [diff] [blame] | 1601 | elif proto.name == 'ClearDescriptorSets': |
| 1602 | rr_string = rr_string.replace('pPacket->pDescriptorSets', 'localDescSets') |
| 1603 | elif proto.name == 'AllocDescriptorSets': |
| 1604 | rr_string = rr_string.replace('pPacket->pSetLayouts', 'localDescSets') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1605 | rbody.append(rr_string) |
| 1606 | if 'DestroyDevice' in proto.name: |
| 1607 | rbody.append(' if (replayResult == XGL_SUCCESS)') |
| 1608 | rbody.append(' {') |
Peter Lohrmann | 53e8924 | 2015-02-27 15:35:15 -0800 | [diff] [blame] | 1609 | rbody.append(' m_pCBDump = NULL;') |
| 1610 | rbody.append(' m_pDSDump = NULL;') |
Peter Lohrmann | caf39d5 | 2015-03-24 17:19:24 -0700 | [diff] [blame] | 1611 | rbody.append(' m_pGlvSnapshotPrint = NULL;') |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1612 | rbody.append(' m_objMapper.rm_from_map(pPacket->device);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1613 | rbody.append(' m_display->m_initedXGL = false;') |
| 1614 | rbody.append(' }') |
Jon Ashburn | 6f4b303 | 2015-02-03 08:57:28 -0700 | [diff] [blame] | 1615 | if 'DestroyInstance' in proto.name: |
| 1616 | rbody.append(' if (replayResult == XGL_SUCCESS)') |
| 1617 | rbody.append(' {') |
Jon Ashburn | 6f58a16 | 2015-02-03 09:17:12 -0700 | [diff] [blame] | 1618 | rbody.append(' // TODO need to handle multiple instances and only clearing maps within an instance.') |
| 1619 | 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] | 1620 | rbody.append(' m_objMapper.clear_all_map_handles();') |
Jon Ashburn | 6f4b303 | 2015-02-03 08:57:28 -0700 | [diff] [blame] | 1621 | rbody.append(' }') |
Tobin Ehlis | 377b462 | 2015-01-20 13:50:59 -0700 | [diff] [blame] | 1622 | elif 'AllocDescriptorSets' in proto.name: |
| 1623 | rbody.append(' if (replayResult == XGL_SUCCESS)') |
| 1624 | rbody.append(' {') |
| 1625 | rbody.append(' for (uint32_t i = 0; i < local_pCount; i++) {') |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1626 | 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] | 1627 | rbody.append(' }') |
| 1628 | rbody.append(' }') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1629 | elif create_func: # save handle mapping if create successful |
| 1630 | rbody.append(' if (replayResult == XGL_SUCCESS)') |
| 1631 | rbody.append(' {') |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1632 | 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] | 1633 | if 'AllocMemory' == proto.name: |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1634 | 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] | 1635 | rbody.append(' }') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1636 | elif proto.name in do_while_dict: |
| 1637 | rbody[-1] = ' %s' % rbody[-1] |
| 1638 | rbody.append(' } while (%s);' % do_while_dict[proto.name]) |
Jon Ashburn | 8bead7a | 2015-02-23 11:07:30 -0700 | [diff] [blame] | 1639 | rbody.append(' if (pPacket->result != XGL_NOT_READY || replayResult != XGL_SUCCESS)') |
Jon Ashburn | ffd5f14 | 2015-02-03 13:39:05 -0700 | [diff] [blame] | 1640 | elif proto.name == 'EnumerateLayers': |
| 1641 | rbody.append(' for (unsigned int i = 0; i < pPacket->maxLayerCount; i++)') |
| 1642 | rbody.append(' GLV_DELETE(bufptr[i]);') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1643 | if ret_value: |
| 1644 | rbody.append(' CHECK_RETURN_VALUE(xgl%s);' % proto.name) |
| 1645 | if 'MsgCallback' in proto.name: |
| 1646 | rbody.pop() |
| 1647 | rbody.pop() |
| 1648 | rbody.pop() |
| 1649 | rbody.append(' // Just eating these calls as no way to restore dbg func ptr.') |
| 1650 | rbody.append(' break;') |
| 1651 | rbody.append(' }') |
| 1652 | rbody.append(' default:') |
| 1653 | rbody.append(' glv_LogWarn("Unrecognized packet_id %u, skipping\\n", packet->packet_id);') |
| 1654 | rbody.append(' returnValue = glv_replay::GLV_REPLAY_INVALID_ID;') |
| 1655 | rbody.append(' break;') |
| 1656 | rbody.append(' }') |
| 1657 | rbody.append(' return returnValue;') |
| 1658 | rbody.append('}') |
| 1659 | return "\n".join(rbody) |
| 1660 | |
| 1661 | class GlaveTraceHeader(Subcommand): |
| 1662 | def generate_header(self): |
| 1663 | header_txt = [] |
Peter Lohrmann | 56782cd | 2015-03-27 12:57:10 -0700 | [diff] [blame] | 1664 | header_txt.append('#include "glv_vk_vk_structs.h"') |
| 1665 | header_txt.append('#include "glv_vk_packet_id.h"\n') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1666 | header_txt.append('void AttachHooks();') |
| 1667 | header_txt.append('void DetachHooks();') |
Ian Elliott | bc9ca5f | 2015-02-27 11:10:59 -0700 | [diff] [blame] | 1668 | header_txt.append('void InitTracer(void);\n') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1669 | return "\n".join(header_txt) |
| 1670 | |
| 1671 | def generate_body(self): |
| 1672 | body = [self._generate_trace_func_ptrs(), |
Peter Lohrmann | 358d009 | 2015-04-03 12:03:44 -0700 | [diff] [blame^] | 1673 | self._generate_trace_func_protos(), |
| 1674 | self._generate_trace_real_func_ptr_protos()] |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1675 | |
| 1676 | return "\n".join(body) |
| 1677 | |
| 1678 | class GlaveTraceC(Subcommand): |
| 1679 | def generate_header(self): |
| 1680 | header_txt = [] |
| 1681 | header_txt.append('#include "glv_platform.h"') |
| 1682 | header_txt.append('#include "glv_common.h"') |
Peter Lohrmann | 358d009 | 2015-04-03 12:03:44 -0700 | [diff] [blame^] | 1683 | header_txt.append('#include "glvtrace_xgl_helpers.h"') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1684 | header_txt.append('#include "glvtrace_xgl_xgl.h"') |
| 1685 | header_txt.append('#include "glvtrace_xgl_xgldbg.h"') |
| 1686 | header_txt.append('#include "glvtrace_xgl_xglwsix11ext.h"') |
| 1687 | header_txt.append('#include "glv_interconnect.h"') |
| 1688 | header_txt.append('#include "glv_filelike.h"') |
Tobin Ehlis | ff765b0 | 2015-03-12 14:50:40 -0600 | [diff] [blame] | 1689 | header_txt.append('#include "xgl_struct_size_helper.h"') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1690 | header_txt.append('#ifdef WIN32') |
| 1691 | header_txt.append('#include "mhook/mhook-lib/mhook.h"') |
| 1692 | header_txt.append('#endif') |
| 1693 | header_txt.append('#include "glv_trace_packet_utils.h"') |
| 1694 | header_txt.append('#include <stdio.h>\n') |
| 1695 | return "\n".join(header_txt) |
| 1696 | |
| 1697 | def generate_body(self): |
| 1698 | body = [self._generate_func_ptr_assignments(), |
| 1699 | self._generate_attach_hooks(), |
| 1700 | self._generate_detach_hooks(), |
Jon Ashburn | e224839 | 2014-12-16 18:37:04 -0700 | [diff] [blame] | 1701 | self._generate_init_funcs(), |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1702 | self._generate_trace_funcs()] |
| 1703 | |
| 1704 | return "\n".join(body) |
| 1705 | |
| 1706 | class GlavePacketID(Subcommand): |
| 1707 | def generate_header(self): |
| 1708 | header_txt = [] |
| 1709 | header_txt.append('#pragma once\n') |
| 1710 | header_txt.append('#include "glv_trace_packet_utils.h"') |
| 1711 | header_txt.append('#include "glv_trace_packet_identifiers.h"') |
| 1712 | header_txt.append('#include "glv_interconnect.h"') |
Peter Lohrmann | 56782cd | 2015-03-27 12:57:10 -0700 | [diff] [blame] | 1713 | header_txt.append('#include "glv_vk_vk_structs.h"') |
| 1714 | header_txt.append('#include "glv_vk_vkdbg_structs.h"') |
| 1715 | header_txt.append('#include "glv_vk_vkwsix11ext_structs.h"') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1716 | header_txt.append('#include "xgl_enum_string_helper.h"') |
Piers Daniell | e2bca48 | 2015-02-24 13:58:47 -0700 | [diff] [blame] | 1717 | header_txt.append('#if defined(WIN32)') |
| 1718 | header_txt.append('#define snprintf _snprintf') |
| 1719 | header_txt.append('#endif') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1720 | header_txt.append('#define SEND_ENTRYPOINT_ID(entrypoint) ;') |
| 1721 | header_txt.append('//#define SEND_ENTRYPOINT_ID(entrypoint) glv_TraceInfo(#entrypoint "\\n");\n') |
| 1722 | header_txt.append('#define SEND_ENTRYPOINT_PARAMS(entrypoint, ...) ;') |
| 1723 | header_txt.append('//#define SEND_ENTRYPOINT_PARAMS(entrypoint, ...) glv_TraceInfo(entrypoint, __VA_ARGS__);\n') |
| 1724 | header_txt.append('#define CREATE_TRACE_PACKET(entrypoint, buffer_bytes_needed) \\') |
| 1725 | header_txt.append(' pHeader = glv_create_trace_packet(GLV_TID_XGL, GLV_TPI_XGL_##entrypoint, sizeof(struct_##entrypoint), buffer_bytes_needed);\n') |
| 1726 | header_txt.append('#define FINISH_TRACE_PACKET() \\') |
| 1727 | header_txt.append(' glv_finalize_trace_packet(pHeader); \\') |
| 1728 | header_txt.append(' glv_write_trace_packet(pHeader, glv_trace_get_trace_file()); \\') |
| 1729 | header_txt.append(' glv_delete_trace_packet(&pHeader);') |
| 1730 | return "\n".join(header_txt) |
| 1731 | |
| 1732 | def generate_body(self): |
| 1733 | body = [self._generate_packet_id_enum(), |
| 1734 | self._generate_stringify_func(), |
| 1735 | self._generate_interp_func()] |
| 1736 | |
| 1737 | return "\n".join(body) |
| 1738 | |
| 1739 | class GlaveCoreStructs(Subcommand): |
| 1740 | def generate_header(self): |
| 1741 | header_txt = [] |
| 1742 | header_txt.append('#pragma once\n') |
| 1743 | header_txt.append('#include "xgl.h"') |
| 1744 | header_txt.append('#include "glv_trace_packet_utils.h"\n') |
| 1745 | return "\n".join(header_txt) |
| 1746 | |
| 1747 | def generate_body(self): |
| 1748 | body = [self._generate_struct_util_funcs(), |
| 1749 | self._generate_interp_funcs()] |
| 1750 | |
| 1751 | return "\n".join(body) |
| 1752 | |
| 1753 | class GlaveWsiHeader(Subcommand): |
| 1754 | def generate_header(self): |
| 1755 | header_txt = [] |
| 1756 | header_txt.append('#pragma once\n') |
| 1757 | header_txt.append('#include "xgl.h"') |
Piers Daniell | e2bca48 | 2015-02-24 13:58:47 -0700 | [diff] [blame] | 1758 | header_txt.append('#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA)') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1759 | header_txt.append('#include "xglWsiX11Ext.h"\n') |
David Pinedo | 8e9cb3b | 2015-02-10 15:02:08 -0700 | [diff] [blame] | 1760 | header_txt.append('#else') |
| 1761 | header_txt.append('#include "xglWsiWinExt.h"') |
| 1762 | header_txt.append('#endif') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1763 | header_txt.append('void AttachHooks_xglwsix11ext();') |
| 1764 | header_txt.append('void DetachHooks_xglwsix11ext();') |
| 1765 | return "\n".join(header_txt) |
| 1766 | |
| 1767 | def generate_body(self): |
| 1768 | body = [self._generate_trace_func_ptrs_ext(), |
| 1769 | self._generate_trace_func_protos_ext()] |
| 1770 | |
| 1771 | return "\n".join(body) |
| 1772 | |
| 1773 | class GlaveWsiC(Subcommand): |
| 1774 | def generate_header(self): |
| 1775 | header_txt = [] |
| 1776 | header_txt.append('#include "glv_platform.h"') |
| 1777 | header_txt.append('#include "glv_common.h"') |
| 1778 | header_txt.append('#include "glvtrace_xgl_xglwsix11ext.h"') |
Peter Lohrmann | 56782cd | 2015-03-27 12:57:10 -0700 | [diff] [blame] | 1779 | header_txt.append('#include "glv_vk_vkwsix11ext_structs.h"') |
| 1780 | header_txt.append('#include "glv_vk_packet_id.h"') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1781 | header_txt.append('#ifdef WIN32') |
| 1782 | header_txt.append('#include "mhook/mhook-lib/mhook.h"') |
| 1783 | header_txt.append('#endif') |
| 1784 | return "\n".join(header_txt) |
| 1785 | |
| 1786 | def generate_body(self): |
| 1787 | body = [self._generate_func_ptr_assignments_ext(), |
| 1788 | self._generate_attach_hooks_ext(), |
| 1789 | self._generate_detach_hooks_ext(), |
| 1790 | self._generate_trace_funcs_ext()] |
| 1791 | |
| 1792 | return "\n".join(body) |
| 1793 | |
| 1794 | class GlaveWsiStructs(Subcommand): |
| 1795 | def generate_header(self): |
| 1796 | header_txt = [] |
| 1797 | header_txt.append('#pragma once\n') |
Piers Daniell | e2bca48 | 2015-02-24 13:58:47 -0700 | [diff] [blame] | 1798 | header_txt.append('#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA)') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1799 | header_txt.append('#include "xglWsiX11Ext.h"') |
David Pinedo | 8e9cb3b | 2015-02-10 15:02:08 -0700 | [diff] [blame] | 1800 | header_txt.append('#else') |
| 1801 | header_txt.append('#include "xglWsiWinExt.h"') |
| 1802 | header_txt.append('#endif') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1803 | header_txt.append('#include "glv_trace_packet_utils.h"\n') |
| 1804 | return "\n".join(header_txt) |
| 1805 | |
| 1806 | def generate_body(self): |
| 1807 | body = [self._generate_interp_funcs_ext()] |
| 1808 | |
| 1809 | return "\n".join(body) |
| 1810 | |
| 1811 | class GlaveDbgHeader(Subcommand): |
| 1812 | def generate_header(self): |
| 1813 | header_txt = [] |
| 1814 | header_txt.append('#pragma once\n') |
| 1815 | header_txt.append('#include "xgl.h"') |
| 1816 | header_txt.append('#include "xglDbg.h"\n') |
| 1817 | header_txt.append('void AttachHooks_xgldbg();') |
| 1818 | header_txt.append('void DetachHooks_xgldbg();') |
| 1819 | return "\n".join(header_txt) |
| 1820 | |
| 1821 | def generate_body(self): |
| 1822 | body = [self._generate_trace_func_ptrs_ext('Dbg'), |
| 1823 | self._generate_trace_func_protos_ext('Dbg')] |
| 1824 | |
| 1825 | return "\n".join(body) |
| 1826 | |
| 1827 | class GlaveDbgC(Subcommand): |
| 1828 | def generate_header(self): |
| 1829 | header_txt = [] |
| 1830 | header_txt.append('#include "glv_platform.h"') |
| 1831 | header_txt.append('#include "glv_common.h"') |
| 1832 | header_txt.append('#include "glvtrace_xgl_xgl.h"') |
| 1833 | header_txt.append('#include "glvtrace_xgl_xgldbg.h"') |
Peter Lohrmann | 56782cd | 2015-03-27 12:57:10 -0700 | [diff] [blame] | 1834 | header_txt.append('#include "glv_vk_vkdbg_structs.h"') |
| 1835 | header_txt.append('#include "glv_vk_packet_id.h"') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1836 | header_txt.append('#ifdef WIN32') |
| 1837 | header_txt.append('#include "mhook/mhook-lib/mhook.h"') |
| 1838 | header_txt.append('#endif') |
| 1839 | return "\n".join(header_txt) |
| 1840 | |
| 1841 | def generate_body(self): |
| 1842 | body = [self._generate_func_ptr_assignments_ext('Dbg'), |
| 1843 | self._generate_attach_hooks_ext('Dbg'), |
| 1844 | self._generate_detach_hooks_ext('Dbg'), |
| 1845 | self._generate_trace_funcs_ext('Dbg')] |
| 1846 | |
| 1847 | return "\n".join(body) |
| 1848 | |
| 1849 | class GlaveDbgStructs(Subcommand): |
| 1850 | def generate_header(self): |
| 1851 | header_txt = [] |
| 1852 | header_txt.append('#pragma once\n') |
| 1853 | header_txt.append('#include "xglDbg.h"') |
| 1854 | header_txt.append('#include "glv_trace_packet_utils.h"\n') |
| 1855 | return "\n".join(header_txt) |
| 1856 | |
| 1857 | def generate_body(self): |
| 1858 | body = [self._generate_interp_funcs_ext('Dbg')] |
| 1859 | |
| 1860 | return "\n".join(body) |
| 1861 | |
Peter Lohrmann | af44b45 | 2015-03-30 18:29:22 -0700 | [diff] [blame] | 1862 | class GlaveReplayXglFuncPtrs(Subcommand): |
| 1863 | def generate_header(self): |
| 1864 | header_txt = [] |
| 1865 | header_txt.append('#pragma once\n') |
| 1866 | header_txt.append('#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA)') |
| 1867 | header_txt.append('#include <xcb/xcb.h>\n') |
| 1868 | header_txt.append('#endif') |
| 1869 | header_txt.append('#include "xgl.h"') |
| 1870 | header_txt.append('#include "xglDbg.h"') |
| 1871 | header_txt.append('#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA)') |
| 1872 | header_txt.append('#include "xglWsiX11Ext.h"') |
| 1873 | header_txt.append('#else') |
| 1874 | header_txt.append('#include "xglWsiWinExt.h"') |
| 1875 | header_txt.append('#endif') |
| 1876 | |
| 1877 | def generate_body(self): |
| 1878 | body = [self._generate_replay_func_ptrs()] |
| 1879 | return "\n".join(body) |
| 1880 | |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1881 | class GlaveReplayObjMapperHeader(Subcommand): |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1882 | def generate_header(self): |
| 1883 | header_txt = [] |
| 1884 | header_txt.append('#pragma once\n') |
| 1885 | header_txt.append('#include <set>') |
| 1886 | header_txt.append('#include <map>') |
| 1887 | header_txt.append('#include <vector>') |
Tony Barbour | b30dcd4 | 2015-02-02 13:21:18 -0700 | [diff] [blame] | 1888 | header_txt.append('#include <string>') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1889 | header_txt.append('#include "xgl.h"') |
| 1890 | header_txt.append('#include "xglDbg.h"') |
Piers Daniell | e2bca48 | 2015-02-24 13:58:47 -0700 | [diff] [blame] | 1891 | header_txt.append('#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA)') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1892 | header_txt.append('#include "xglWsiX11Ext.h"') |
David Pinedo | 8e9cb3b | 2015-02-10 15:02:08 -0700 | [diff] [blame] | 1893 | header_txt.append('#else') |
| 1894 | header_txt.append('#include "xglWsiWinExt.h"') |
| 1895 | header_txt.append('#endif') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1896 | return "\n".join(header_txt) |
| 1897 | |
| 1898 | def generate_body(self): |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1899 | body = [self._generate_replay_objmapper_class()] |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1900 | |
| 1901 | return "\n".join(body) |
| 1902 | |
| 1903 | class GlaveReplayC(Subcommand): |
| 1904 | def generate_header(self): |
| 1905 | header_txt = [] |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1906 | header_txt.append('#include "glvreplay_xgl_xglreplay.h"\n') |
Jon Ashburn | b7b98a0 | 2014-12-18 17:03:34 -0700 | [diff] [blame] | 1907 | header_txt.append('#include "glvreplay_xgl.h"\n') |
Tony Barbour | b30dcd4 | 2015-02-02 13:21:18 -0700 | [diff] [blame] | 1908 | header_txt.append('#include "glvreplay_main.h"\n') |
| 1909 | header_txt.append('#include <algorithm>') |
Jon Ashburn | 013aa1c | 2015-02-13 11:25:53 -0700 | [diff] [blame] | 1910 | header_txt.append('#include <queue>') |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1911 | header_txt.append('\n') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1912 | header_txt.append('extern "C" {') |
Peter Lohrmann | 56782cd | 2015-03-27 12:57:10 -0700 | [diff] [blame] | 1913 | header_txt.append('#include "glv_vk_vk_structs.h"') |
| 1914 | header_txt.append('#include "glv_vk_vkdbg_structs.h"') |
| 1915 | header_txt.append('#include "glv_vk_vkwsix11ext_structs.h"') |
| 1916 | header_txt.append('#include "glv_vk_packet_id.h"') |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1917 | header_txt.append('#include "xgl_enum_string_helper.h"\n}\n') |
| 1918 | header_txt.append('#define APP_NAME "glvreplay_xgl"') |
| 1919 | header_txt.append('#define IDI_ICON 101\n') |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1920 | |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1921 | return "\n".join(header_txt) |
| 1922 | |
| 1923 | def generate_body(self): |
Peter Lohrmann | 3f0d697 | 2015-04-01 18:12:34 -0700 | [diff] [blame] | 1924 | body = [self._generate_replay_init_funcs(), |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1925 | self._generate_replay()] |
| 1926 | |
| 1927 | return "\n".join(body) |
| 1928 | |
| 1929 | def main(): |
| 1930 | subcommands = { |
| 1931 | "glave-trace-h" : GlaveTraceHeader, |
| 1932 | "glave-trace-c" : GlaveTraceC, |
| 1933 | "glave-packet-id" : GlavePacketID, |
| 1934 | "glave-core-structs" : GlaveCoreStructs, |
| 1935 | "glave-wsi-trace-h" : GlaveWsiHeader, |
| 1936 | "glave-wsi-trace-c" : GlaveWsiC, |
| 1937 | "glave-wsi-trace-structs" : GlaveWsiStructs, |
| 1938 | "glave-dbg-trace-h" : GlaveDbgHeader, |
| 1939 | "glave-dbg-trace-c" : GlaveDbgC, |
| 1940 | "glave-dbg-trace-structs" : GlaveDbgStructs, |
Peter Lohrmann | af44b45 | 2015-03-30 18:29:22 -0700 | [diff] [blame] | 1941 | "glave-replay-xgl-funcs" : GlaveReplayXglFuncPtrs, |
Peter Lohrmann | 7572822 | 2015-04-02 11:45:31 -0700 | [diff] [blame] | 1942 | "glave-replay-obj-mapper-h" : GlaveReplayObjMapperHeader, |
Tobin Ehlis | f5e1fc5 | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1943 | "glave-replay-c" : GlaveReplayC, |
| 1944 | } |
| 1945 | |
| 1946 | if len(sys.argv) < 2 or sys.argv[1] not in subcommands: |
| 1947 | print("Usage: %s <subcommand> [options]" % sys.argv[0]) |
| 1948 | print |
| 1949 | print("Available sucommands are: %s" % " ".join(subcommands)) |
| 1950 | exit(1) |
| 1951 | |
| 1952 | subcmd = subcommands[sys.argv[1]](sys.argv[2:]) |
| 1953 | subcmd.run() |
| 1954 | |
| 1955 | if __name__ == "__main__": |
| 1956 | main() |