Tobin Ehlis | 5d57bca | 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 | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 25 | |
| 26 | import sys |
| 27 | |
| 28 | import xgl |
| 29 | |
| 30 | class Subcommand(object): |
| 31 | def __init__(self, argv): |
| 32 | self.argv = argv |
Chia-I Wu | c4f24e8 | 2015-01-01 08:46:31 +0800 | [diff] [blame] | 33 | self.headers = xgl.headers |
| 34 | self.protos = xgl.protos |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 35 | |
| 36 | def run(self): |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 37 | print(self.generate()) |
| 38 | |
| 39 | def generate(self): |
| 40 | copyright = self.generate_copyright() |
| 41 | header = self.generate_header() |
| 42 | body = self.generate_body() |
| 43 | footer = self.generate_footer() |
| 44 | |
| 45 | contents = [] |
| 46 | if copyright: |
| 47 | contents.append(copyright) |
| 48 | if header: |
| 49 | contents.append(header) |
| 50 | if body: |
| 51 | contents.append(body) |
| 52 | if footer: |
| 53 | contents.append(footer) |
| 54 | |
| 55 | return "\n\n".join(contents) |
| 56 | |
| 57 | def generate_copyright(self): |
| 58 | return """/* THIS FILE IS GENERATED. DO NOT EDIT. */ |
| 59 | |
| 60 | /* |
| 61 | * XGL |
| 62 | * |
| 63 | * Copyright (C) 2014 LunarG, Inc. |
| 64 | * |
| 65 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 66 | * copy of this software and associated documentation files (the "Software"), |
| 67 | * to deal in the Software without restriction, including without limitation |
| 68 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 69 | * and/or sell copies of the Software, and to permit persons to whom the |
| 70 | * Software is furnished to do so, subject to the following conditions: |
| 71 | * |
| 72 | * The above copyright notice and this permission notice shall be included |
| 73 | * in all copies or substantial portions of the Software. |
| 74 | * |
| 75 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 76 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 77 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 78 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 79 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 80 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 81 | * DEALINGS IN THE SOFTWARE. |
| 82 | */""" |
| 83 | |
| 84 | def generate_header(self): |
| 85 | return "\n".join(["#include <" + h + ">" for h in self.headers]) |
| 86 | |
| 87 | def generate_body(self): |
| 88 | pass |
| 89 | |
| 90 | def generate_footer(self): |
| 91 | pass |
| 92 | |
Jon Ashburn | 9ef8beb | 2015-02-12 10:38:36 -0700 | [diff] [blame] | 93 | # Return set of printf '%' qualifier, input to that qualifier, and any dereference |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 94 | def _get_printf_params(self, xgl_type, name, output_param): |
Jon Ashburn | 9ef8beb | 2015-02-12 10:38:36 -0700 | [diff] [blame] | 95 | deref = "" |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 96 | # TODO : Need ENUM and STRUCT checks here |
| 97 | if "_TYPE" in xgl_type: # TODO : This should be generic ENUM check |
Jon Ashburn | 9ef8beb | 2015-02-12 10:38:36 -0700 | [diff] [blame] | 98 | return ("%s", "string_%s(%s)" % (xgl_type.replace('const ', '').strip('*'), name), deref) |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 99 | if "char*" == xgl_type: |
Jon Ashburn | 9ef8beb | 2015-02-12 10:38:36 -0700 | [diff] [blame] | 100 | return ("%s", name, "*") |
Tobin Ehlis | bf967aa | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 101 | if "uint64_t" in xgl_type: |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 102 | if '*' in xgl_type: |
Jon Ashburn | 9ef8beb | 2015-02-12 10:38:36 -0700 | [diff] [blame] | 103 | return ("%lu", "(%s == NULL) ? 0 : *(%s)" % (name, name), "*") |
| 104 | return ("%lu", name, deref) |
Tobin Ehlis | bf967aa | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 105 | if "size_t" in xgl_type: |
Chia-I Wu | 99ff89d | 2014-12-27 14:14:50 +0800 | [diff] [blame] | 106 | if '*' in xgl_type: |
Jon Ashburn | 9ef8beb | 2015-02-12 10:38:36 -0700 | [diff] [blame] | 107 | return ("%zu", "(%s == NULL) ? 0 : *(%s)" % (name, name), "*") |
| 108 | return ("%zu", name, deref) |
Tobin Ehlis | bf967aa | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 109 | if "float" in xgl_type: |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 110 | if '[' in xgl_type: # handle array, current hard-coded to 4 (TODO: Make this dynamic) |
Jon Ashburn | 9ef8beb | 2015-02-12 10:38:36 -0700 | [diff] [blame] | 111 | return ("[%f, %f, %f, %f]", "%s[0], %s[1], %s[2], %s[3]" % (name, name, name, name), deref) |
| 112 | return ("%f", name, deref) |
Tobin Ehlis | bf967aa | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 113 | if "bool" in xgl_type or 'xcb_randr_crtc_t' in xgl_type: |
Jon Ashburn | 9ef8beb | 2015-02-12 10:38:36 -0700 | [diff] [blame] | 114 | return ("%u", name, deref) |
Tobin Ehlis | bf967aa | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 115 | if True in [t in xgl_type for t in ["int", "FLAGS", "MASK", "xcb_window_t"]]: |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 116 | if '[' in xgl_type: # handle array, current hard-coded to 4 (TODO: Make this dynamic) |
Jon Ashburn | 9ef8beb | 2015-02-12 10:38:36 -0700 | [diff] [blame] | 117 | return ("[%i, %i, %i, %i]", "%s[0], %s[1], %s[2], %s[3]" % (name, name, name, name), deref) |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 118 | if '*' in xgl_type: |
Jon Ashburn | 9ef8beb | 2015-02-12 10:38:36 -0700 | [diff] [blame] | 119 | return ("%i", "(%s == NULL) ? 0 : *(%s)" % (name, name), "*") |
| 120 | return ("%i", name, deref) |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 121 | if output_param: |
Jon Ashburn | 9ef8beb | 2015-02-12 10:38:36 -0700 | [diff] [blame] | 122 | return ("%p", "(void*)%s" % name, deref) |
| 123 | return ("%p", "(void*)(%s)" % name, deref) |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 124 | |
| 125 | def _generate_trace_func_ptrs(self): |
| 126 | func_ptrs = [] |
| 127 | func_ptrs.append('// Pointers to real functions and declarations of hooked functions') |
| 128 | func_ptrs.append('#ifdef WIN32') |
| 129 | func_ptrs.append('extern INIT_ONCE gInitOnce;') |
| 130 | for proto in self.protos: |
| 131 | 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: |
| 132 | func_ptrs.append('#define __HOOKED_xgl%s hooked_xgl%s' % (proto.name, proto.name)) |
| 133 | |
| 134 | func_ptrs.append('\n#elif defined(PLATFORM_LINUX)') |
| 135 | func_ptrs.append('extern pthread_once_t gInitOnce;') |
| 136 | for proto in self.protos: |
| 137 | if True not in [skip_str in proto.name for skip_str in ['Dbg', 'Wsi']]: |
| 138 | func_ptrs.append('#define __HOOKED_xgl%s xgl%s' % (proto.name, proto.name)) |
| 139 | |
| 140 | func_ptrs.append('#endif\n') |
| 141 | return "\n".join(func_ptrs) |
| 142 | |
| 143 | def _generate_trace_func_ptrs_ext(self, func_class='Wsi'): |
| 144 | func_ptrs = [] |
| 145 | func_ptrs.append('#ifdef WIN32') |
| 146 | for proto in self.protos: |
| 147 | if func_class in proto.name: |
| 148 | func_ptrs.append('#define __HOOKED_xgl%s hooked_xgl%s' % (proto.name, proto.name)) |
| 149 | |
| 150 | func_ptrs.append('#elif defined(__linux__)') |
| 151 | for proto in self.protos: |
| 152 | if func_class in proto.name: |
| 153 | func_ptrs.append('#define __HOOKED_xgl%s xgl%s' % (proto.name, proto.name)) |
| 154 | |
| 155 | func_ptrs.append('#endif\n') |
| 156 | return "\n".join(func_ptrs) |
| 157 | |
| 158 | def _generate_trace_func_protos(self): |
| 159 | func_protos = [] |
| 160 | func_protos.append('// Hooked function prototypes\n') |
| 161 | for proto in self.protos: |
| 162 | if 'Dbg' not in proto.name and 'Wsi' not in proto.name: |
Ian Elliott | c4e3e0f | 2015-02-26 17:01:30 -0700 | [diff] [blame] | 163 | func_protos.append('GLVTRACER_EXPORT %s;' % proto.c_func(prefix="__HOOKED_xgl", attr="XGLAPI")) |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 164 | |
| 165 | return "\n".join(func_protos) |
| 166 | |
| 167 | def _generate_trace_func_protos_ext(self, func_class='Wsi'): |
| 168 | func_protos = [] |
| 169 | func_protos.append('// Hooked function prototypes\n') |
| 170 | for proto in self.protos: |
| 171 | if func_class in proto.name: |
Ian Elliott | c4e3e0f | 2015-02-26 17:01:30 -0700 | [diff] [blame] | 172 | func_protos.append('GLVTRACER_EXPORT %s;' % proto.c_func(prefix="__HOOKED_xgl", attr="XGLAPI")) |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 173 | |
| 174 | return "\n".join(func_protos) |
| 175 | |
| 176 | |
| 177 | def _generate_func_ptr_assignments(self): |
| 178 | func_ptr_assign = [] |
| 179 | for proto in self.protos: |
| 180 | if 'Dbg' not in proto.name and 'Wsi' not in proto.name: |
| 181 | func_ptr_assign.append('static %s( XGLAPI * real_xgl%s)(' % (proto.ret, proto.name)) |
| 182 | for p in proto.params: |
| 183 | if 'color' == p.name: |
| 184 | func_ptr_assign.append(' %s %s[4],' % (p.ty.replace('[4]', ''), p.name)) |
| 185 | else: |
| 186 | func_ptr_assign.append(' %s %s,' % (p.ty, p.name)) |
| 187 | func_ptr_assign[-1] = func_ptr_assign[-1].replace(',', ') = xgl%s;\n' % (proto.name)) |
| 188 | func_ptr_assign.append('static BOOL isHooked = FALSE;\n') |
| 189 | return "\n".join(func_ptr_assign) |
| 190 | |
| 191 | def _generate_func_ptr_assignments_ext(self, func_class='Wsi'): |
| 192 | func_ptr_assign = [] |
| 193 | for proto in self.protos: |
| 194 | if func_class in proto.name: |
| 195 | func_ptr_assign.append('static %s( XGLAPI * real_xgl%s)(' % (proto.ret, proto.name)) |
| 196 | for p in proto.params: |
| 197 | func_ptr_assign.append(' %s %s,' % (p.ty, p.name)) |
| 198 | func_ptr_assign[-1] = func_ptr_assign[-1].replace(',', ') = xgl%s;\n' % (proto.name)) |
| 199 | return "\n".join(func_ptr_assign) |
| 200 | |
| 201 | def _generate_attach_hooks(self): |
| 202 | hooks_txt = [] |
| 203 | hooks_txt.append('void AttachHooks()\n{\n BOOL hookSuccess = TRUE;\n#if defined(WIN32)') |
| 204 | hooks_txt.append(' Mhook_BeginMultiOperation(FALSE);') |
Tobin Ehlis | bf967aa | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 205 | # TODO : Verify if CreateInstance is appropriate to key off of here |
| 206 | hooks_txt.append(' if (real_xglCreateInstance != NULL)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 207 | hooks_txt.append(' {\n isHooked = TRUE;') |
| 208 | hook_operator = '=' |
| 209 | for proto in self.protos: |
| 210 | if 'Dbg' not in proto.name and 'Wsi' not in proto.name: |
| 211 | hooks_txt.append(' hookSuccess %s Mhook_SetHook((PVOID*)&real_xgl%s, hooked_xgl%s);' % (hook_operator, proto.name, proto.name)) |
| 212 | hook_operator = '&=' |
| 213 | hooks_txt.append(' }\n') |
| 214 | hooks_txt.append(' if (!hookSuccess)\n {') |
| 215 | hooks_txt.append(' glv_LogError("Failed to hook XGL.");\n }\n') |
| 216 | hooks_txt.append(' Mhook_EndMultiOperation();\n') |
| 217 | hooks_txt.append('#elif defined(__linux__)') |
Tobin Ehlis | bf967aa | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 218 | hooks_txt.append(' if (real_xglCreateInstance == xglCreateInstance)') |
| 219 | hooks_txt.append(' hookSuccess = glv_platform_get_next_lib_sym((PVOID*)&real_xglCreateInstance,"xglCreateInstance");') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 220 | hooks_txt.append(' isHooked = TRUE;') |
| 221 | for proto in self.protos: |
Tobin Ehlis | bf967aa | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 222 | if 'Dbg' not in proto.name and 'Wsi' not in proto.name and 'CreateInstance' not in proto.name: |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 223 | hooks_txt.append(' hookSuccess %s glv_platform_get_next_lib_sym((PVOID*)&real_xgl%s, "xgl%s");' % (hook_operator, proto.name, proto.name)) |
| 224 | hooks_txt.append(' if (!hookSuccess)\n {') |
| 225 | hooks_txt.append(' glv_LogError("Failed to hook XGL.");\n }\n') |
| 226 | hooks_txt.append('#endif\n}\n') |
| 227 | return "\n".join(hooks_txt) |
| 228 | |
| 229 | def _generate_attach_hooks_ext(self, func_class='Wsi'): |
| 230 | func_ext_dict = {'Wsi': '_xglwsix11ext', 'Dbg': '_xgldbg'} |
| 231 | first_proto_dict = {'Wsi': 'WsiX11AssociateConnection', 'Dbg': 'DbgSetValidationLevel'} |
| 232 | hooks_txt = [] |
| 233 | hooks_txt.append('void AttachHooks%s()\n{\n BOOL hookSuccess = TRUE;\n#if defined(WIN32)' % func_ext_dict[func_class]) |
| 234 | hooks_txt.append(' Mhook_BeginMultiOperation(FALSE);') |
| 235 | hooks_txt.append(' if (real_xgl%s != NULL)' % first_proto_dict[func_class]) |
| 236 | hooks_txt.append(' {') |
| 237 | hook_operator = '=' |
| 238 | for proto in self.protos: |
| 239 | if func_class in proto.name: |
| 240 | hooks_txt.append(' hookSuccess %s Mhook_SetHook((PVOID*)&real_xgl%s, hooked_xgl%s);' % (hook_operator, proto.name, proto.name)) |
| 241 | hook_operator = '&=' |
| 242 | hooks_txt.append(' }\n') |
| 243 | hooks_txt.append(' if (!hookSuccess)\n {') |
| 244 | hooks_txt.append(' glv_LogError("Failed to hook XGL ext %s.");\n }\n' % func_class) |
| 245 | hooks_txt.append(' Mhook_EndMultiOperation();\n') |
| 246 | hooks_txt.append('#elif defined(__linux__)') |
| 247 | 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])) |
| 248 | for proto in self.protos: |
| 249 | if func_class in proto.name and first_proto_dict[func_class] not in proto.name: |
| 250 | hooks_txt.append(' hookSuccess %s glv_platform_get_next_lib_sym((PVOID*)&real_xgl%s, "xgl%s");' % (hook_operator, proto.name, proto.name)) |
| 251 | hooks_txt.append(' if (!hookSuccess)\n {') |
| 252 | hooks_txt.append(' glv_LogError("Failed to hook XGL ext %s.");\n }\n' % func_class) |
| 253 | hooks_txt.append('#endif\n}\n') |
| 254 | return "\n".join(hooks_txt) |
| 255 | |
| 256 | def _generate_detach_hooks(self): |
| 257 | hooks_txt = [] |
| 258 | hooks_txt.append('void DetachHooks()\n{\n#ifdef __linux__\n return;\n#elif defined(WIN32)') |
| 259 | hooks_txt.append(' BOOL unhookSuccess = TRUE;\n if (real_xglGetGpuInfo != NULL)\n {') |
| 260 | hook_operator = '=' |
| 261 | for proto in self.protos: |
| 262 | if 'Dbg' not in proto.name and 'Wsi' not in proto.name: |
| 263 | hooks_txt.append(' unhookSuccess %s Mhook_Unhook((PVOID*)&real_xgl%s);' % (hook_operator, proto.name)) |
| 264 | hook_operator = '&=' |
| 265 | hooks_txt.append(' }\n isHooked = FALSE;') |
| 266 | hooks_txt.append(' if (!unhookSuccess)\n {') |
| 267 | hooks_txt.append(' glv_LogError("Failed to unhook XGL.");\n }') |
| 268 | hooks_txt.append('#endif\n}') |
| 269 | 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') |
| 270 | return "\n".join(hooks_txt) |
| 271 | |
| 272 | def _generate_detach_hooks_ext(self, func_class='Wsi'): |
| 273 | func_ext_dict = {'Wsi': '_xglwsix11ext', 'Dbg': '_xgldbg'} |
| 274 | first_proto_dict = {'Wsi': 'WsiX11AssociateConnection', 'Dbg': 'DbgSetValidationLevel'} |
| 275 | hooks_txt = [] |
| 276 | hooks_txt.append('void DetachHooks%s()\n{\n#ifdef WIN32' % func_ext_dict[func_class]) |
| 277 | hooks_txt.append(' BOOL unhookSuccess = TRUE;\n if (real_xgl%s != NULL)\n {' % first_proto_dict[func_class]) |
| 278 | hook_operator = '=' |
| 279 | for proto in self.protos: |
| 280 | if func_class in proto.name: |
| 281 | hooks_txt.append(' unhookSuccess %s Mhook_Unhook((PVOID*)&real_xgl%s);' % (hook_operator, proto.name)) |
| 282 | hook_operator = '&=' |
| 283 | hooks_txt.append(' }') |
| 284 | hooks_txt.append(' if (!unhookSuccess)\n {') |
| 285 | hooks_txt.append(' glv_LogError("Failed to unhook XGL ext %s.");\n }' % func_class) |
| 286 | hooks_txt.append('#elif defined(__linux__)\n return;\n#endif\n}\n') |
| 287 | return "\n".join(hooks_txt) |
| 288 | |
Jon Ashburn | 15161e4 | 2014-12-16 18:37:04 -0700 | [diff] [blame] | 289 | def _generate_init_funcs(self): |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 290 | init_tracer = [] |
Jon Ashburn | 15161e4 | 2014-12-16 18:37:04 -0700 | [diff] [blame] | 291 | init_tracer.append('void send_xgl_api_version_packet()\n{') |
| 292 | init_tracer.append(' struct_xglApiVersion* pPacket;') |
| 293 | init_tracer.append(' glv_trace_packet_header* pHeader;') |
| 294 | init_tracer.append(' pHeader = glv_create_trace_packet(GLV_TID_XGL, GLV_TPI_XGL_xglApiVersion, sizeof(struct_xglApiVersion), 0);') |
| 295 | init_tracer.append(' pPacket = interpret_body_as_xglApiVersion(pHeader, FALSE);') |
| 296 | init_tracer.append(' pPacket->version = XGL_API_VERSION;') |
| 297 | init_tracer.append(' FINISH_TRACE_PACKET();\n}\n') |
| 298 | |
Jon Ashburn | f7ab1a0 | 2015-02-19 17:04:06 -0700 | [diff] [blame] | 299 | init_tracer.append('static GLV_CRITICAL_SECTION g_memInfoLock;') |
Ian Elliott | 5890a77 | 2015-02-27 11:10:59 -0700 | [diff] [blame] | 300 | init_tracer.append('void InitTracer(void)\n{') |
Jon Ashburn | f7ab1a0 | 2015-02-19 17:04:06 -0700 | [diff] [blame] | 301 | init_tracer.append(' char *ipAddr = glv_get_global_var("GLVLIB_TRACE_IPADDR");') |
| 302 | init_tracer.append(' if (ipAddr == NULL)') |
| 303 | init_tracer.append(' ipAddr = "127.0.0.1";') |
Jon Ashburn | d27ce94 | 2015-01-09 17:36:10 -0700 | [diff] [blame] | 304 | init_tracer.append(' gMessageStream = glv_MessageStream_create(FALSE, ipAddr, GLV_BASE_PORT + GLV_TID_XGL);') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 305 | init_tracer.append(' glv_trace_set_trace_file(glv_FileLike_create_msg(gMessageStream));') |
| 306 | init_tracer.append('// glv_tracelog_set_log_file(glv_FileLike_create_file(fopen("glv_log_traceside.txt","w")));') |
Jon Ashburn | 15161e4 | 2014-12-16 18:37:04 -0700 | [diff] [blame] | 307 | init_tracer.append(' glv_tracelog_set_tracer_id(GLV_TID_XGL);') |
Jon Ashburn | f7ab1a0 | 2015-02-19 17:04:06 -0700 | [diff] [blame] | 308 | init_tracer.append(' glv_create_critical_section(&g_memInfoLock);') |
Jon Ashburn | 15161e4 | 2014-12-16 18:37:04 -0700 | [diff] [blame] | 309 | init_tracer.append(' send_xgl_api_version_packet();\n}\n') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 310 | return "\n".join(init_tracer) |
| 311 | |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 312 | def _gen_unmap_memory(self): |
| 313 | um_body = [] |
| 314 | um_body.append('GLVTRACER_EXPORT XGL_RESULT XGLAPI __HOOKED_xglUnmapMemory(') |
| 315 | um_body.append(' XGL_GPU_MEMORY mem)') |
| 316 | um_body.append('{') |
| 317 | um_body.append(' glv_trace_packet_header* pHeader;') |
| 318 | um_body.append(' XGL_RESULT result;') |
| 319 | um_body.append(' struct_xglUnmapMemory* pPacket;') |
| 320 | um_body.append(' XGLAllocInfo *entry;') |
Jon Ashburn | 290dcb1 | 2015-03-02 17:12:31 -0700 | [diff] [blame] | 321 | um_body.append(' SEND_ENTRYPOINT_PARAMS("xglUnmapMemory(mem %p)\\n", mem);') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 322 | um_body.append(' // insert into packet the data that was written by CPU between the xglMapMemory call and here') |
| 323 | um_body.append(' // Note must do this prior to the real xglUnMap() or else may get a FAULT') |
Jon Ashburn | 9c1f807 | 2015-02-25 13:51:07 -0700 | [diff] [blame] | 324 | um_body.append(' glv_enter_critical_section(&g_memInfoLock);') |
| 325 | um_body.append(' entry = find_mem_info_entry(mem);') |
Jon Ashburn | 290dcb1 | 2015-03-02 17:12:31 -0700 | [diff] [blame] | 326 | um_body.append(' CREATE_TRACE_PACKET(xglUnmapMemory, (entry) ? entry->size : 0);') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 327 | um_body.append(' pPacket = interpret_body_as_xglUnmapMemory(pHeader);') |
Jon Ashburn | 290dcb1 | 2015-03-02 17:12:31 -0700 | [diff] [blame] | 328 | um_body.append(' if (entry)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 329 | um_body.append(' {') |
| 330 | um_body.append(' assert(entry->handle == mem);') |
Jon Ashburn | 290dcb1 | 2015-03-02 17:12:31 -0700 | [diff] [blame] | 331 | um_body.append(' glv_add_buffer_to_trace_packet(pHeader, (void**) &(pPacket->pData), entry->size, entry->pData);') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 332 | um_body.append(' glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pData));') |
| 333 | um_body.append(' entry->pData = NULL;') |
Jon Ashburn | 290dcb1 | 2015-03-02 17:12:31 -0700 | [diff] [blame] | 334 | um_body.append(' } else') |
| 335 | um_body.append(' {') |
| 336 | um_body.append(' glv_LogError("Failed to copy app memory into trace packet (idx = %u) on xglUnmapMemory\\n", pHeader->global_packet_index);') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 337 | um_body.append(' }') |
Jon Ashburn | 9c1f807 | 2015-02-25 13:51:07 -0700 | [diff] [blame] | 338 | um_body.append(' glv_leave_critical_section(&g_memInfoLock);') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 339 | um_body.append(' result = real_xglUnmapMemory(mem);') |
| 340 | um_body.append(' pPacket->mem = mem;') |
| 341 | um_body.append(' pPacket->result = result;') |
| 342 | um_body.append(' FINISH_TRACE_PACKET();') |
| 343 | um_body.append(' return result;') |
| 344 | um_body.append('}\n') |
| 345 | return "\n".join(um_body) |
| 346 | |
Tobin Ehlis | 14be4f8 | 2015-03-11 17:19:54 -0600 | [diff] [blame] | 347 | # Take a list of params and return a list of dicts w/ ptr param details |
| 348 | def _get_packet_ptr_param_list(self, params): |
| 349 | ptr_param_list = [] |
| 350 | # TODO : This is a slightly nicer way to handle custom cases than initial code, however |
| 351 | # this can still be further generalized to eliminate more custom code |
| 352 | # big case to handle is when ptrs to structs have embedded data that needs to be accounted for in packet |
| 353 | custom_ptr_dict = {'XGL_DEVICE_CREATE_INFO': {'add_txt': 'add_XGL_DEVICE_CREATE_INFO_to_packet(pHeader, (XGL_DEVICE_CREATE_INFO**) &(pPacket->pCreateInfo), pCreateInfo)', |
| 354 | 'finalize_txt': ''}, |
| 355 | 'XGL_APPLICATION_INFO': {'add_txt': 'add_XGL_APPLICATION_INFO_to_packet(pHeader, (XGL_APPLICATION_INFO**)&(pPacket->pAppInfo), pAppInfo)', |
| 356 | 'finalize_txt': ''}, |
| 357 | 'XGL_PHYSICAL_GPU': {'add_txt': 'glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->pGpus), *pGpuCount*sizeof(XGL_PHYSICAL_GPU), pGpus)', |
| 358 | 'finalize_txt': 'default'}, |
| 359 | 'pDataSize': {'add_txt': 'glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->pDataSize), sizeof(size_t), &_dataSize)', |
| 360 | 'finalize_txt': 'glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pDataSize))'}, |
| 361 | 'pData': {'add_txt': 'glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->pData), _dataSize, pData)', |
| 362 | 'finalize_txt': 'default'}, |
| 363 | 'pName': {'add_txt': 'glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->pName), ((pName != NULL) ? strlen(pName) + 1 : 0), pName)', |
| 364 | 'finalize_txt': 'default'}, |
| 365 | 'pExtName': {'add_txt': 'glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->pExtName), ((pExtName != NULL) ? strlen(pExtName) + 1 : 0), pExtName)', |
| 366 | 'finalize_txt': 'default'}, |
| 367 | 'pDescriptorSets': {'add_txt': 'glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->pDescriptorSets), customSize, pDescriptorSets)', |
| 368 | 'finalize_txt': 'default'}, |
| 369 | 'pUpdateChain': {'add_txt': 'add_update_descriptors_to_trace_packet(pHeader, (void**)&(pPacket->pUpdateChain), pUpdateChain)', |
| 370 | 'finalize_txt': 'default'}, |
| 371 | '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)', |
| 372 | 'finalize_txt': 'glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pCreateInfo->pCode));\n glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pCreateInfo))'}, |
| 373 | '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)', |
| 374 | '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))'}, |
| 375 | '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)', |
| 376 | '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))'}, |
| 377 | '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)', |
| 378 | 'finalize_txt': 'glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pBeginInfo))'}, |
| 379 | '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)', |
| 380 | '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))'}, |
| 381 | '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)', |
| 382 | 'finalize_txt': 'glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pAllocInfo))'}, |
| 383 | '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)', |
| 384 | 'finalize_txt': 'glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pCreateInfo))'}, |
| 385 | '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)', |
| 386 | 'finalize_txt': 'glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pSetLayoutInfoList))'}, |
| 387 | '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)', |
| 388 | 'finalize_txt': 'glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pCreateInfo->pTypeCount));\n glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pCreateInfo))'}, |
| 389 | '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)', |
| 390 | 'finalize_txt': 'finalize_pipeline_shader_address(pHeader, &pPacket->pCreateInfo->cs);\n glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pCreateInfo))'}, |
| 391 | } |
| 392 | for p in params: |
| 393 | pp_dict = {} |
| 394 | if '*' in p.ty and p.name not in ['pSysMem', 'pReserved']: |
| 395 | if 'const' in p.ty.lower() and 'count' in params[params.index(p)-1].name.lower(): |
| 396 | 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) |
| 397 | elif p.ty.strip('*').replace('const ', '') in custom_ptr_dict: |
| 398 | pp_dict['add_txt'] = custom_ptr_dict[p.ty.strip('*').replace('const ', '')]['add_txt'] |
| 399 | pp_dict['finalize_txt'] = custom_ptr_dict[p.ty.strip('*').replace('const ', '')]['finalize_txt'] |
| 400 | elif p.name in custom_ptr_dict: |
| 401 | pp_dict['add_txt'] = custom_ptr_dict[p.name]['add_txt'] |
| 402 | pp_dict['finalize_txt'] = custom_ptr_dict[p.name]['finalize_txt'] |
| 403 | # TODO : This is custom hack to account for 2 pData items with dataSize param for sizing |
| 404 | if 'pData' == p.name and 'dataSize' == params[params.index(p)-1].name: |
| 405 | pp_dict['add_txt'] = pp_dict['add_txt'].replace('_dataSize', 'dataSize') |
| 406 | else: |
| 407 | 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) |
| 408 | if 'finalize_txt' not in pp_dict or 'default' == pp_dict['finalize_txt']: |
| 409 | pp_dict['finalize_txt'] = 'glv_finalize_buffer_address(pHeader, (void**)&(pPacket->%s))' % (p.name) |
| 410 | pp_dict['index'] = params.index(p) |
| 411 | ptr_param_list.append(pp_dict) |
| 412 | return ptr_param_list |
| 413 | |
Tobin Ehlis | dedfa07 | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 414 | # Take a list of params and return a list of packet size elements |
| 415 | def _get_packet_size(self, params): |
Tobin Ehlis | bd6a916 | 2015-03-13 07:18:05 -0600 | [diff] [blame] | 416 | ps = [] # List of elements to be added together to account for packet size for given params |
Tobin Ehlis | dedfa07 | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 417 | skip_list = [] # store params that are already accounted for so we don't count them twice |
| 418 | # Dict of specific params with unique custom sizes |
Tobin Ehlis | bd6a916 | 2015-03-13 07:18:05 -0600 | [diff] [blame] | 419 | custom_size_dict = {'pSetBindPoints': '(XGL_SHADER_STAGE_COMPUTE * sizeof(uint32_t))', # Accounting for largest possible array |
| 420 | } |
Tobin Ehlis | dedfa07 | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 421 | for p in params: |
| 422 | #First handle custom cases |
Tobin Ehlis | bd6a916 | 2015-03-13 07:18:05 -0600 | [diff] [blame] | 423 | if p.name in ['pCreateInfo', 'pUpdateChain', 'pSetLayoutInfoList', 'pBeginInfo', 'pAllocInfo']: |
| 424 | ps.append('get_struct_chain_size((void*)%s)' % p.name) |
Tobin Ehlis | dedfa07 | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 425 | skip_list.append(p.name) |
| 426 | elif p.name in custom_size_dict: |
| 427 | ps.append(custom_size_dict[p.name]) |
| 428 | skip_list.append(p.name) |
| 429 | # Skip any params already handled |
| 430 | if p.name in skip_list: |
| 431 | continue |
| 432 | # Now check to identify dynamic arrays which depend on two params |
| 433 | if 'count' in p.name.lower(): |
| 434 | next_idx = params.index(p)+1 |
| 435 | # If next element is a const *, then multiply count and array type |
| 436 | if next_idx < len(params) and '*' in params[next_idx].ty and 'const' in params[next_idx].ty.lower(): |
| 437 | if '*' in p.ty: |
| 438 | ps.append('*%s*sizeof(%s)' % (p.name, params[next_idx].ty.strip('*').replace('const ', ''))) |
| 439 | else: |
| 440 | ps.append('%s*sizeof(%s)' % (p.name, params[next_idx].ty.strip('*').replace('const ', ''))) |
| 441 | skip_list.append(params[next_idx].name) |
| 442 | elif '*' in p.ty and p.name not in ['pSysMem', 'pReserved']: |
| 443 | if 'pData' == p.name: |
| 444 | if 'dataSize' == params[params.index(p)-1].name: |
| 445 | ps.append('dataSize') |
| 446 | elif 'counterCount' == params[params.index(p)-1].name: |
| 447 | ps.append('sizeof(%s)' % p.ty.strip('*').replace('const ', '')) |
| 448 | else: |
| 449 | ps.append('((pDataSize != NULL && pData != NULL) ? *pDataSize : 0)') |
| 450 | elif '**' in p.ty and 'void' in p.ty: |
| 451 | ps.append('sizeof(void*)') |
| 452 | elif 'void' in p.ty: |
| 453 | ps.append('sizeof(%s)' % p.name) |
| 454 | elif 'char' in p.ty: |
| 455 | ps.append('((%s != NULL) ? strlen(%s) + 1 : 0)' % (p.name, p.name)) |
Tobin Ehlis | dedfa07 | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 456 | elif 'pDataSize' in p.name: |
| 457 | ps.append('((pDataSize != NULL) ? sizeof(size_t) : 0)') |
| 458 | elif 'IMAGE_SUBRESOURCE' in p.ty and 'pSubresource' == p.name: |
| 459 | ps.append('((pSubresource != NULL) ? sizeof(XGL_IMAGE_SUBRESOURCE) : 0)') |
| 460 | else: |
| 461 | ps.append('sizeof(%s)' % (p.ty.strip('*').replace('const ', ''))) |
| 462 | return ps |
| 463 | |
Tobin Ehlis | a8f6afe | 2015-02-05 11:29:45 -0700 | [diff] [blame] | 464 | # Generate functions used to trace API calls and store the input and result data into a packet |
Tobin Ehlis | dedfa07 | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 465 | # Here's the general flow of code insertion w/ option items flagged w/ "?" |
| 466 | # Result decl? |
| 467 | # Packet struct decl |
| 468 | # ?Special case : setup call to function first and do custom API call time tracking |
| 469 | # CREATE_PACKET |
| 470 | # Call (w/ result?) |
| 471 | # Assign packet values |
| 472 | # FINISH packet |
| 473 | # return result? |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 474 | def _generate_trace_funcs(self): |
| 475 | func_body = [] |
| 476 | for proto in self.protos: |
Tobin Ehlis | bf967aa | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 477 | if 'UnmapMemory' == proto.name: |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 478 | func_body.append(self._gen_unmap_memory()) |
| 479 | elif 'Dbg' not in proto.name and 'Wsi' not in proto.name: |
Tobin Ehlis | dedfa07 | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 480 | raw_packet_update_list = [] # non-ptr elements placed directly into packet |
Tobin Ehlis | 14be4f8 | 2015-03-11 17:19:54 -0600 | [diff] [blame] | 481 | ptr_packet_update_list = [] # ptr elements to be updated into packet |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 482 | return_txt = '' |
Tobin Ehlis | dedfa07 | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 483 | packet_size = [] |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 484 | in_data_size = False # flag when we need to capture local input size variable for in/out size |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 485 | func_body.append('GLVTRACER_EXPORT %s XGLAPI __HOOKED_xgl%s(' % (proto.ret, proto.name)) |
Tobin Ehlis | dedfa07 | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 486 | for p in proto.params: # TODO : For all of the ptr types, check them for NULL and return 0 if NULL |
| 487 | if '[' in p.ty: # Correctly declare static arrays in function parameters |
| 488 | func_body.append(' %s %s[%s],' % (p.ty[:p.ty.find('[')], p.name, p.ty[p.ty.find('[')+1:p.ty.find(']')])) |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 489 | else: |
| 490 | func_body.append(' %s %s,' % (p.ty, p.name)) |
Tobin Ehlis | dedfa07 | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 491 | if '*' in p.ty and p.name not in ['pSysMem', 'pReserved']: |
| 492 | if 'pDataSize' in p.name: |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 493 | in_data_size = True; |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 494 | else: |
Tobin Ehlis | dedfa07 | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 495 | if '[' in p.ty: |
Tobin Ehlis | f9a7e25 | 2015-02-25 11:30:27 -0700 | [diff] [blame] | 496 | array_str = p.ty[p.ty.find('[')+1:p.ty.find(']')] |
Tobin Ehlis | dedfa07 | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 497 | 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 | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 498 | else: |
Tobin Ehlis | dedfa07 | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 499 | raw_packet_update_list.append(' pPacket->%s = %s;' % (p.name, p.name)) |
| 500 | # Get list of packet size modifiers due to ptr params |
| 501 | packet_size = self._get_packet_size(proto.params) |
Tobin Ehlis | 14be4f8 | 2015-03-11 17:19:54 -0600 | [diff] [blame] | 502 | ptr_packet_update_list = self._get_packet_ptr_param_list(proto.params) |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 503 | func_body[-1] = func_body[-1].replace(',', ')') |
Tobin Ehlis | dedfa07 | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 504 | # End of function declaration portion, begin function body |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 505 | func_body.append('{\n glv_trace_packet_header* pHeader;') |
Tobin Ehlis | bf967aa | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 506 | if 'void' not in proto.ret or '*' in proto.ret: |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 507 | func_body.append(' %s result;' % proto.ret) |
| 508 | return_txt = 'result = ' |
| 509 | if in_data_size: |
Jon Ashburn | e3a667c | 2015-02-11 09:32:29 -0700 | [diff] [blame] | 510 | func_body.append(' size_t _dataSize;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 511 | func_body.append(' struct_xgl%s* pPacket = NULL;' % proto.name) |
Jon Ashburn | 04baf7a | 2015-02-02 12:39:24 -0700 | [diff] [blame] | 512 | # functions that have non-standard sequence of packet creation and calling real function |
Tobin Ehlis | dedfa07 | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 513 | # NOTE: Anytime we call the function before CREATE_TRACE_PACKET, need to add custom code for correctly tracking API call time |
Jon Ashburn | 04baf7a | 2015-02-02 12:39:24 -0700 | [diff] [blame] | 514 | if 'CreateInstance' == proto.name: |
Tobin Ehlis | f6f8cd4 | 2015-02-03 14:41:26 -0700 | [diff] [blame] | 515 | func_body.append(' uint64_t startTime;') |
Jon Ashburn | 04baf7a | 2015-02-02 12:39:24 -0700 | [diff] [blame] | 516 | func_body.append(' glv_platform_thread_once(&gInitOnce, InitTracer);') |
| 517 | func_body.append(' SEND_ENTRYPOINT_ID(xgl%s);' % proto.name) |
| 518 | func_body.append(' if (real_xglCreateInstance == xglCreateInstance)') |
| 519 | func_body.append(' {') |
| 520 | func_body.append(' glv_platform_get_next_lib_sym((void **) &real_xglCreateInstance,"xglCreateInstance");') |
| 521 | func_body.append(' }') |
Tobin Ehlis | f6f8cd4 | 2015-02-03 14:41:26 -0700 | [diff] [blame] | 522 | func_body.append(' startTime = glv_get_time();') |
| 523 | func_body.append(' %sreal_xgl%s;' % (return_txt, proto.c_call())) |
Tobin Ehlis | 43c67ad | 2015-03-16 08:21:33 -0600 | [diff] [blame] | 524 | func_body.append(' CREATE_TRACE_PACKET(xgl%s, sizeof(XGL_INSTANCE) + get_struct_chain_size((void*)pAppInfo) + ((pAllocCb == NULL) ? 0 :sizeof(XGL_ALLOC_CALLBACKS)));' % (proto.name)) |
Tobin Ehlis | f6f8cd4 | 2015-02-03 14:41:26 -0700 | [diff] [blame] | 525 | func_body.append(' pHeader->entrypoint_begin_time = startTime;') |
Jon Ashburn | 04baf7a | 2015-02-02 12:39:24 -0700 | [diff] [blame] | 526 | func_body.append(' if (isHooked == FALSE) {') |
| 527 | func_body.append(' AttachHooks();') |
| 528 | func_body.append(' AttachHooks_xgldbg();') |
| 529 | func_body.append(' AttachHooks_xglwsix11ext();') |
| 530 | func_body.append(' }') |
Jon Ashburn | 04baf7a | 2015-02-02 12:39:24 -0700 | [diff] [blame] | 531 | elif 'EnumerateGpus' == proto.name: |
| 532 | func_body.append(' uint64_t startTime;') |
| 533 | func_body.append(' SEND_ENTRYPOINT_ID(xgl%s);' % proto.name) |
| 534 | func_body.append(' startTime = glv_get_time();') |
| 535 | func_body.append(' %sreal_xgl%s;' % (return_txt, proto.c_call())) |
| 536 | func_body.append(' CREATE_TRACE_PACKET(xglEnumerateGpus, sizeof(uint32_t) + ((pGpus && pGpuCount) ? *pGpuCount * sizeof(XGL_PHYSICAL_GPU) : 0));') |
| 537 | func_body.append(' pHeader->entrypoint_begin_time = startTime;') |
| 538 | elif 'EnumerateLayers' == proto.name: |
| 539 | func_body.append(' uint64_t startTime;') |
| 540 | func_body.append(' SEND_ENTRYPOINT_ID(xgl%s);' % proto.name) |
| 541 | func_body.append(' startTime = glv_get_time();') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 542 | func_body.append(' %sreal_xgl%s;' % (return_txt, proto.c_call())) |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 543 | func_body.append(' size_t totStringSize = 0;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 544 | func_body.append(' uint32_t i = 0;') |
| 545 | func_body.append(' for (i = 0; i < *pOutLayerCount; i++)') |
Chia-I Wu | f1a5a74 | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 546 | func_body.append(' totStringSize += (pOutLayers[i] != NULL) ? strlen(pOutLayers[i]) + 1: 0;') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 547 | func_body.append(' CREATE_TRACE_PACKET(xgl%s, totStringSize + sizeof(size_t));' % (proto.name)) |
Jon Ashburn | 04baf7a | 2015-02-02 12:39:24 -0700 | [diff] [blame] | 548 | func_body.append(' pHeader->entrypoint_begin_time = startTime;') |
Tobin Ehlis | 271e51d | 2015-01-20 13:50:59 -0700 | [diff] [blame] | 549 | elif 'AllocDescriptorSets' == proto.name: |
Jon Ashburn | 04baf7a | 2015-02-02 12:39:24 -0700 | [diff] [blame] | 550 | func_body.append(' uint64_t startTime;') |
| 551 | func_body.append(' SEND_ENTRYPOINT_ID(xgl%s);' % proto.name) |
| 552 | func_body.append(' startTime = glv_get_time();') |
Tobin Ehlis | 271e51d | 2015-01-20 13:50:59 -0700 | [diff] [blame] | 553 | func_body.append(' %sreal_xgl%s;' % (return_txt, proto.c_call())) |
| 554 | func_body.append(' size_t customSize = (*pCount <= 0) ? (sizeof(XGL_DESCRIPTOR_SET)) : (*pCount * sizeof(XGL_DESCRIPTOR_SET));') |
| 555 | func_body.append(' CREATE_TRACE_PACKET(xglAllocDescriptorSets, sizeof(XGL_DESCRIPTOR_SET_LAYOUT) + customSize + sizeof(uint32_t));') |
Jon Ashburn | 04baf7a | 2015-02-02 12:39:24 -0700 | [diff] [blame] | 556 | func_body.append(' pHeader->entrypoint_begin_time = startTime;') |
Tobin Ehlis | dedfa07 | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 557 | elif proto.name in ['CreateFramebuffer', 'CreateRenderPass', 'CreateDynamicViewportState', |
Tobin Ehlis | a8f6afe | 2015-02-05 11:29:45 -0700 | [diff] [blame] | 558 | 'CreateDescriptorRegion', 'CmdWaitEvents', 'CmdPipelineBarrier']: |
Tobin Ehlis | bd6a916 | 2015-03-13 07:18:05 -0600 | [diff] [blame] | 559 | # these are regular case as far as sequence of tracing but have some custom size element |
Tobin Ehlis | dedfa07 | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 560 | if 'CreateFramebuffer' == proto.name: |
Jon Ashburn | 38349d0 | 2015-01-02 18:28:26 -0700 | [diff] [blame] | 561 | func_body.append(' int dsSize = (pCreateInfo != NULL && pCreateInfo->pDepthStencilAttachment != NULL) ? sizeof(XGL_DEPTH_STENCIL_BIND_INFO) : 0;') |
Tobin Ehlis | a8f6afe | 2015-02-05 11:29:45 -0700 | [diff] [blame] | 562 | func_body.append(' uint32_t colorCount = (pCreateInfo != NULL && pCreateInfo->pColorAttachments != NULL) ? pCreateInfo->colorAttachmentCount : 0;') |
Tobin Ehlis | bd6a916 | 2015-03-13 07:18:05 -0600 | [diff] [blame] | 563 | func_body.append(' CREATE_TRACE_PACKET(xglCreateFramebuffer, get_struct_chain_size((void*)pCreateInfo) + sizeof(XGL_FRAMEBUFFER));') |
Jon Ashburn | 38349d0 | 2015-01-02 18:28:26 -0700 | [diff] [blame] | 564 | elif 'CreateRenderPass' == proto.name: |
Jon Ashburn | 002e863 | 2015-02-20 10:30:32 -0700 | [diff] [blame] | 565 | func_body.append(' uint32_t colorCount = (pCreateInfo != NULL && (pCreateInfo->pColorLoadOps != NULL || pCreateInfo->pColorStoreOps != NULL || pCreateInfo->pColorLoadClearValues != NULL)) ? pCreateInfo->colorAttachmentCount : 0;') |
Tobin Ehlis | bd6a916 | 2015-03-13 07:18:05 -0600 | [diff] [blame] | 566 | func_body.append(' CREATE_TRACE_PACKET(xglCreateRenderPass, get_struct_chain_size((void*)pCreateInfo) + sizeof(XGL_RENDER_PASS));') |
Jon Ashburn | 459a137 | 2015-02-04 08:50:35 -0700 | [diff] [blame] | 567 | elif 'CreateDynamicViewportState' == proto.name: |
Courtney Goeltzenleuchter | bbe3cc5 | 2015-02-11 14:13:34 -0700 | [diff] [blame] | 568 | func_body.append(' uint32_t vpsCount = (pCreateInfo != NULL && pCreateInfo->pViewports != NULL) ? pCreateInfo->viewportAndScissorCount : 0;') |
Tobin Ehlis | bd6a916 | 2015-03-13 07:18:05 -0600 | [diff] [blame] | 569 | func_body.append(' CREATE_TRACE_PACKET(xglCreateDynamicViewportState, get_struct_chain_size((void*)pCreateInfo) + sizeof(XGL_DYNAMIC_VP_STATE_OBJECT));') |
Jon Ashburn | 4622454 | 2015-02-04 09:32:59 -0700 | [diff] [blame] | 570 | elif 'CreateDescriptorRegion' == proto.name: |
Tobin Ehlis | a8f6afe | 2015-02-05 11:29:45 -0700 | [diff] [blame] | 571 | func_body.append(' uint32_t rgCount = (pCreateInfo != NULL && pCreateInfo->pTypeCount != NULL) ? pCreateInfo->count : 0;') |
Tobin Ehlis | bd6a916 | 2015-03-13 07:18:05 -0600 | [diff] [blame] | 572 | func_body.append(' CREATE_TRACE_PACKET(xglCreateDescriptorRegion, get_struct_chain_size((void*)pCreateInfo) + sizeof(XGL_DESCRIPTOR_REGION));') |
Tobin Ehlis | dedfa07 | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 573 | else: # ['CmdWaitEvents', 'CmdPipelineBarrier']: |
Tobin Ehlis | bd6a916 | 2015-03-13 07:18:05 -0600 | [diff] [blame] | 574 | func_body.append(' size_t customSize;') |
Tobin Ehlis | a8f6afe | 2015-02-05 11:29:45 -0700 | [diff] [blame] | 575 | event_array_type = 'XGL_EVENT' |
| 576 | if 'CmdPipelineBarrier' == proto.name: |
| 577 | event_array_type = 'XGL_SET_EVENT' |
| 578 | func_body.append(' uint32_t eventCount = (%s != NULL && %s->pEvents != NULL) ? %s->eventCount : 0;' % (proto.params[-1].name, proto.params[-1].name, proto.params[-1].name)) |
| 579 | func_body.append(' uint32_t mbCount = (%s != NULL && %s->ppMemBarriers != NULL) ? %s->memBarrierCount : 0;' % (proto.params[-1].name, proto.params[-1].name, proto.params[-1].name)) |
Jon Ashburn | 308cc4c | 2015-02-10 13:49:30 -0700 | [diff] [blame] | 580 | func_body.append(' customSize = (eventCount * sizeof(%s)) + mbCount * sizeof(void*) + calculate_memory_barrier_size(mbCount, %s->ppMemBarriers);' % (event_array_type, proto.params[-1].name)) |
Tobin Ehlis | a8f6afe | 2015-02-05 11:29:45 -0700 | [diff] [blame] | 581 | func_body.append(' CREATE_TRACE_PACKET(xgl%s, sizeof(%s) + customSize);' % (proto.name, proto.params[-1].ty.strip('*').replace('const ', ''))) |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 582 | func_body.append(' %sreal_xgl%s;' % (return_txt, proto.c_call())) |
| 583 | else: |
Tobin Ehlis | dedfa07 | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 584 | if (0 == len(packet_size)): |
| 585 | func_body.append(' CREATE_TRACE_PACKET(xgl%s, 0);' % (proto.name)) |
| 586 | else: |
| 587 | func_body.append(' CREATE_TRACE_PACKET(xgl%s, %s);' % (proto.name, ' + '.join(packet_size))) |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 588 | func_body.append(' %sreal_xgl%s;' % (return_txt, proto.c_call())) |
Jon Ashburn | e3a667c | 2015-02-11 09:32:29 -0700 | [diff] [blame] | 589 | if in_data_size: |
| 590 | func_body.append(' _dataSize = (pDataSize == NULL || pData == NULL) ? 0 : *pDataSize;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 591 | func_body.append(' pPacket = interpret_body_as_xgl%s(pHeader);' % proto.name) |
Tobin Ehlis | dedfa07 | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 592 | func_body.append('\n'.join(raw_packet_update_list)) |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 593 | if 'MapMemory' == proto.name: # Custom code for MapMem case |
| 594 | func_body.append(' if (ppData != NULL)') |
| 595 | func_body.append(' {') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 596 | func_body.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->ppData), sizeof(void*), *ppData);') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 597 | func_body.append(' glv_finalize_buffer_address(pHeader, (void**)&(pPacket->ppData));') |
| 598 | func_body.append(' add_data_to_mem_info(mem, *ppData);') |
| 599 | func_body.append(' }') |
| 600 | func_body.append(' pPacket->result = result;') |
| 601 | func_body.append(' FINISH_TRACE_PACKET();') |
| 602 | elif 'EnumerateLayers' == proto.name: #custom code for EnumerateLayers case |
| 603 | func_body.append(' pPacket->gpu = gpu;') |
| 604 | func_body.append(' pPacket->maxLayerCount = maxLayerCount;') |
| 605 | func_body.append(' pPacket->maxStringSize = maxStringSize;') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 606 | func_body.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->pOutLayerCount), sizeof(size_t), pOutLayerCount);') |
Mark Lobodzinski | 391bb6d | 2015-01-09 15:12:03 -0600 | [diff] [blame] | 607 | func_body.append(' glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pOutLayerCount));') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 608 | func_body.append(' for (i = 0; i < *pOutLayerCount; i++) {') |
Chia-I Wu | f1a5a74 | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 609 | func_body.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->pOutLayers[i]), ((pOutLayers[i] != NULL) ? strlen(pOutLayers[i]) + 1 : 0), pOutLayers[i]);') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 610 | func_body.append(' glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pOutLayers[i]));') |
| 611 | func_body.append(' }') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 612 | |
| 613 | func_body.append(' pPacket->pReserved = pReserved;') |
| 614 | func_body.append(' pPacket->result = result;') |
| 615 | func_body.append(' FINISH_TRACE_PACKET();') |
| 616 | else: |
Tobin Ehlis | 14be4f8 | 2015-03-11 17:19:54 -0600 | [diff] [blame] | 617 | for pp_dict in ptr_packet_update_list: #buff_ptr_indices: |
| 618 | func_body.append(' %s;' % (pp_dict['add_txt'])) |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 619 | # Some custom add_* and finalize_* function calls for Create* API calls |
Tobin Ehlis | 14be4f8 | 2015-03-11 17:19:54 -0600 | [diff] [blame] | 620 | if proto.name in ['CmdWaitEvents', 'CmdPipelineBarrier']: |
| 621 | event_array_type = 'XGL_EVENT' |
| 622 | if 'CmdPipelineBarrier' == proto.name: |
| 623 | event_array_type = 'XGL_SET_EVENT' |
| 624 | func_body.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->%s->pEvents), eventCount * sizeof(%s), %s->pEvents);' % (proto.params[-1].name, event_array_type, proto.params[-1].name)) |
| 625 | func_body.append(' glv_finalize_buffer_address(pHeader, (void**)&(pPacket->%s->pEvents));' % (proto.params[-1].name)) |
| 626 | func_body.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->%s->ppMemBarriers), mbCount * sizeof(void*), %s->ppMemBarriers);' % (proto.params[-1].name, proto.params[-1].name)) |
| 627 | func_body.append(' uint32_t i, siz;') |
| 628 | func_body.append(' for (i = 0; i < mbCount; i++) {') |
| 629 | func_body.append(' XGL_MEMORY_BARRIER *pNext = (XGL_MEMORY_BARRIER *) %s->ppMemBarriers[i];' % proto.params[-1].name) |
| 630 | func_body.append(' switch (pNext->sType) {') |
| 631 | func_body.append(' case XGL_STRUCTURE_TYPE_MEMORY_BARRIER:') |
| 632 | func_body.append(' siz = sizeof(XGL_MEMORY_BARRIER);') |
| 633 | func_body.append(' break;') |
| 634 | func_body.append(' case XGL_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER:') |
| 635 | func_body.append(' siz = sizeof(XGL_BUFFER_MEMORY_BARRIER);') |
| 636 | func_body.append(' break;') |
| 637 | func_body.append(' case XGL_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER:') |
| 638 | func_body.append(' siz = sizeof(XGL_IMAGE_MEMORY_BARRIER);') |
| 639 | func_body.append(' break;') |
| 640 | func_body.append(' default:') |
| 641 | func_body.append(' assert(0);') |
| 642 | func_body.append(' siz = 0;') |
| 643 | func_body.append(' break;') |
| 644 | func_body.append(' }') |
| 645 | func_body.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)&(pPacket->%s->ppMemBarriers[i]), siz, %s->ppMemBarriers[i]);' % (proto.params[-1].name, proto.params[-1].name)) |
| 646 | func_body.append(' glv_finalize_buffer_address(pHeader, (void**)&(pPacket->%s->ppMemBarriers[i]));' % (proto.params[-1].name)) |
| 647 | func_body.append(' }') |
| 648 | func_body.append(' glv_finalize_buffer_address(pHeader, (void**)&(pPacket->%s->ppMemBarriers));' % (proto.params[-1].name)) |
Tobin Ehlis | bf967aa | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 649 | if 'void' not in proto.ret or '*' in proto.ret: |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 650 | func_body.append(' pPacket->result = result;') |
Tobin Ehlis | 14be4f8 | 2015-03-11 17:19:54 -0600 | [diff] [blame] | 651 | for pp_dict in ptr_packet_update_list: |
| 652 | 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): |
| 653 | func_body.append(' %s;' % (pp_dict['finalize_txt'])) |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 654 | func_body.append(' FINISH_TRACE_PACKET();') |
| 655 | if 'AllocMemory' in proto.name: |
| 656 | func_body.append(' add_new_handle_to_mem_info(*pMem, pAllocInfo->allocationSize, NULL);') |
| 657 | elif 'FreeMemory' in proto.name: |
| 658 | func_body.append(' rm_handle_from_mem_info(mem);') |
Tobin Ehlis | bf967aa | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 659 | if 'void' not in proto.ret or '*' in proto.ret: |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 660 | func_body.append(' return result;') |
| 661 | func_body.append('}\n') |
| 662 | return "\n".join(func_body) |
| 663 | |
| 664 | def _generate_trace_funcs_ext(self, func_class='Wsi'): |
| 665 | thread_once_funcs = ['DbgRegisterMsgCallback', 'DbgUnregisterMsgCallback', 'DbgSetGlobalOption'] |
| 666 | func_body = [] |
| 667 | for proto in self.protos: |
| 668 | if func_class in proto.name: |
| 669 | packet_update_txt = '' |
| 670 | return_txt = '' |
| 671 | packet_size = '' |
| 672 | buff_ptr_indices = [] |
| 673 | func_body.append('GLVTRACER_EXPORT %s XGLAPI __HOOKED_xgl%s(' % (proto.ret, proto.name)) |
| 674 | for p in proto.params: # TODO : For all of the ptr types, check them for NULL and return 0 is NULL |
| 675 | func_body.append(' %s %s,' % (p.ty, p.name)) |
| 676 | if 'Size' in p.name: |
| 677 | packet_size += p.name |
| 678 | if '*' in p.ty and 'pSysMem' != p.name: |
Tobin Ehlis | bf967aa | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 679 | if 'char' in p.ty: |
Chia-I Wu | f1a5a74 | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 680 | packet_size += '((%s != NULL) ? strlen(%s) + 1 : 0) + ' % (p.name, p.name) |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 681 | elif 'Size' not in packet_size: |
Tobin Ehlis | bf967aa | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 682 | packet_size += 'sizeof(%s) + ' % p.ty.strip('*').replace('const ', '') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 683 | buff_ptr_indices.append(proto.params.index(p)) |
| 684 | if 'pConnectionInfo' in p.name: |
| 685 | packet_size += '((pConnectionInfo->pConnection != NULL) ? sizeof(void *) : 0)' |
| 686 | else: |
| 687 | packet_update_txt += ' pPacket->%s = %s;\n' % (p.name, p.name) |
| 688 | if '' == packet_size: |
| 689 | packet_size = '0' |
| 690 | else: |
| 691 | packet_size = packet_size.strip(' + ') |
| 692 | func_body[-1] = func_body[-1].replace(',', ')') |
| 693 | func_body.append('{\n glv_trace_packet_header* pHeader;') |
Tobin Ehlis | bf967aa | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 694 | if 'void' not in proto.ret or '*' in proto.ret: |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 695 | func_body.append(' %s result;' % proto.ret) |
| 696 | return_txt = 'result = ' |
| 697 | func_body.append(' struct_xgl%s* pPacket = NULL;' % proto.name) |
| 698 | if proto.name in thread_once_funcs: |
| 699 | func_body.append(' glv_platform_thread_once(&gInitOnce, InitTracer);') |
| 700 | func_body.append(' SEND_ENTRYPOINT_ID(xgl%s);' % proto.name) |
Ian Elliott | 5890a77 | 2015-02-27 11:10:59 -0700 | [diff] [blame] | 701 | if 'DbgRegisterMsgCallback' in proto.name: |
| 702 | func_body.append(' CREATE_TRACE_PACKET(xgl%s, sizeof(char));' % proto.name) |
| 703 | else: |
| 704 | func_body.append(' CREATE_TRACE_PACKET(xgl%s, %s);' % (proto.name, packet_size)) |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 705 | func_body.append(' %sreal_xgl%s;' % (return_txt, proto.c_call())) |
| 706 | func_body.append(' pPacket = interpret_body_as_xgl%s(pHeader);' % proto.name) |
| 707 | func_body.append(packet_update_txt.strip('\n')) |
| 708 | for idx in buff_ptr_indices: |
Tobin Ehlis | bf967aa | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 709 | if 'char' in proto.params[idx].ty: |
Chia-I Wu | f1a5a74 | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 710 | 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 | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 711 | elif 'Size' in proto.params[idx-1].name: |
| 712 | 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 | 5890a77 | 2015-02-27 11:10:59 -0700 | [diff] [blame] | 713 | elif 'DbgRegisterMsgCallback' in proto.name: |
| 714 | 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 | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 715 | else: |
Tobin Ehlis | bf967aa | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 716 | 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 | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 717 | if 'WsiX11AssociateConnection' in proto.name: |
| 718 | func_body.append(' if (pConnectionInfo->pConnection != NULL) {') |
| 719 | func_body.append(' glv_add_buffer_to_trace_packet(pHeader, (void**) &(pPacket->pConnectionInfo->pConnection), sizeof(void *), pConnectionInfo->pConnection);') |
| 720 | func_body.append(' glv_finalize_buffer_address(pHeader, (void**) &(pPacket->pConnectionInfo->pConnection));') |
| 721 | func_body.append(' }') |
Tobin Ehlis | bf967aa | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 722 | if 'void' not in proto.ret or '*' in proto.ret: |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 723 | func_body.append(' pPacket->result = result;') |
| 724 | for idx in buff_ptr_indices: |
| 725 | func_body.append(' glv_finalize_buffer_address(pHeader, (void**)&(pPacket->%s));' % (proto.params[idx].name)) |
| 726 | func_body.append(' FINISH_TRACE_PACKET();') |
Tobin Ehlis | bf967aa | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 727 | if 'void' not in proto.ret or '*' in proto.ret: |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 728 | func_body.append(' return result;') |
| 729 | func_body.append('}\n') |
| 730 | return "\n".join(func_body) |
| 731 | |
| 732 | def _generate_helper_funcs(self): |
| 733 | hf_body = [] |
| 734 | hf_body.append('// Support for shadowing CPU mapped memory') |
| 735 | hf_body.append('typedef struct _XGLAllocInfo {') |
| 736 | hf_body.append(' XGL_GPU_SIZE size;') |
| 737 | hf_body.append(' XGL_GPU_MEMORY handle;') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 738 | hf_body.append(' void *pData;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 739 | hf_body.append(' BOOL valid;') |
| 740 | hf_body.append('} XGLAllocInfo;') |
| 741 | hf_body.append('typedef struct _XGLMemInfo {') |
| 742 | hf_body.append(' unsigned int numEntrys;') |
| 743 | hf_body.append(' XGLAllocInfo *pEntrys;') |
| 744 | hf_body.append(' XGLAllocInfo *pLastMapped;') |
| 745 | hf_body.append(' unsigned int capacity;') |
| 746 | hf_body.append('} XGLMemInfo;') |
| 747 | hf_body.append('') |
Jon Ashburn | f7ab1a0 | 2015-02-19 17:04:06 -0700 | [diff] [blame] | 748 | hf_body.append('static XGLMemInfo g_memInfo = {0, NULL, NULL, 0};') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 749 | hf_body.append('') |
| 750 | hf_body.append('static void init_mem_info_entrys(XGLAllocInfo *ptr, const unsigned int num)') |
| 751 | hf_body.append('{') |
Jon Ashburn | 290dcb1 | 2015-03-02 17:12:31 -0700 | [diff] [blame] | 752 | hf_body.append(' unsigned int i;') |
| 753 | hf_body.append(' for (i = 0; i < num; i++)') |
| 754 | hf_body.append(' {') |
| 755 | hf_body.append(' XGLAllocInfo *entry = ptr + i;') |
| 756 | hf_body.append(' entry->pData = NULL;') |
| 757 | hf_body.append(' entry->size = 0;') |
| 758 | hf_body.append(' entry->handle = NULL;') |
| 759 | hf_body.append(' entry->valid = FALSE;') |
| 760 | hf_body.append(' }') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 761 | hf_body.append('}') |
| 762 | hf_body.append('') |
Jon Ashburn | f7ab1a0 | 2015-02-19 17:04:06 -0700 | [diff] [blame] | 763 | hf_body.append('// caller must hold the g_memInfoLock') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 764 | hf_body.append('static void init_mem_info()') |
| 765 | hf_body.append('{') |
Jon Ashburn | f7ab1a0 | 2015-02-19 17:04:06 -0700 | [diff] [blame] | 766 | hf_body.append(' g_memInfo.numEntrys = 0;') |
Jon Ashburn | a95f438 | 2015-02-20 14:48:27 -0700 | [diff] [blame] | 767 | hf_body.append(' g_memInfo.capacity = 4096;') |
Jon Ashburn | f7ab1a0 | 2015-02-19 17:04:06 -0700 | [diff] [blame] | 768 | hf_body.append(' g_memInfo.pLastMapped = NULL;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 769 | hf_body.append('') |
Jon Ashburn | f7ab1a0 | 2015-02-19 17:04:06 -0700 | [diff] [blame] | 770 | hf_body.append(' g_memInfo.pEntrys = GLV_NEW_ARRAY(XGLAllocInfo, g_memInfo.capacity);') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 771 | hf_body.append('') |
Jon Ashburn | f7ab1a0 | 2015-02-19 17:04:06 -0700 | [diff] [blame] | 772 | hf_body.append(' if (g_memInfo.pEntrys == NULL)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 773 | hf_body.append(' glv_LogError("init_mem_info() malloc failed\\n");') |
| 774 | hf_body.append(' else') |
Jon Ashburn | f7ab1a0 | 2015-02-19 17:04:06 -0700 | [diff] [blame] | 775 | hf_body.append(' init_mem_info_entrys(g_memInfo.pEntrys, g_memInfo.capacity);') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 776 | hf_body.append('}') |
| 777 | hf_body.append('') |
Jon Ashburn | f7ab1a0 | 2015-02-19 17:04:06 -0700 | [diff] [blame] | 778 | hf_body.append('// caller must hold the g_memInfoLock') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 779 | hf_body.append('static void delete_mem_info()') |
| 780 | hf_body.append('{') |
Jon Ashburn | f7ab1a0 | 2015-02-19 17:04:06 -0700 | [diff] [blame] | 781 | hf_body.append(' GLV_DELETE(g_memInfo.pEntrys);') |
| 782 | hf_body.append(' g_memInfo.pEntrys = NULL;') |
| 783 | hf_body.append(' g_memInfo.numEntrys = 0;') |
| 784 | hf_body.append(' g_memInfo.capacity = 0;') |
| 785 | hf_body.append(' g_memInfo.pLastMapped = NULL;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 786 | hf_body.append('}') |
| 787 | hf_body.append('') |
Jon Ashburn | f7ab1a0 | 2015-02-19 17:04:06 -0700 | [diff] [blame] | 788 | hf_body.append('// caller must hold the g_memInfoLock') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 789 | hf_body.append('static XGLAllocInfo * get_mem_info_entry()') |
| 790 | hf_body.append('{') |
| 791 | hf_body.append(' unsigned int i;') |
| 792 | hf_body.append(' XGLAllocInfo *entry;') |
Jon Ashburn | f7ab1a0 | 2015-02-19 17:04:06 -0700 | [diff] [blame] | 793 | hf_body.append(' if (g_memInfo.numEntrys > g_memInfo.capacity)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 794 | hf_body.append(' {') |
Jon Ashburn | a95f438 | 2015-02-20 14:48:27 -0700 | [diff] [blame] | 795 | hf_body.append(' glv_LogError("get_mem_info_entry() bad internal state numEntrys %u\\n", g_memInfo.numEntrys);') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 796 | hf_body.append(' return NULL;') |
| 797 | hf_body.append(' }') |
| 798 | hf_body.append('') |
Jon Ashburn | a95f438 | 2015-02-20 14:48:27 -0700 | [diff] [blame] | 799 | hf_body.append(' entry = g_memInfo.pEntrys;') |
| 800 | hf_body.append(' for (i = 0; i < g_memInfo.numEntrys; i++)') |
| 801 | hf_body.append(' {') |
| 802 | hf_body.append(' if ((entry + i)->valid == FALSE)') |
| 803 | hf_body.append(' return entry + i;') |
| 804 | hf_body.append(' }') |
Jon Ashburn | f7ab1a0 | 2015-02-19 17:04:06 -0700 | [diff] [blame] | 805 | hf_body.append(' if (g_memInfo.numEntrys == g_memInfo.capacity)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 806 | hf_body.append(' { // grow the array 2x') |
Jon Ashburn | f7ab1a0 | 2015-02-19 17:04:06 -0700 | [diff] [blame] | 807 | hf_body.append(' g_memInfo.capacity *= 2;') |
| 808 | hf_body.append(' g_memInfo.pEntrys = (XGLAllocInfo *) GLV_REALLOC(g_memInfo.pEntrys, g_memInfo.capacity * sizeof(XGLAllocInfo));') |
Jon Ashburn | a95f438 | 2015-02-20 14:48:27 -0700 | [diff] [blame] | 809 | hf_body.append(' if (g_memInfo.pEntrys == NULL)') |
| 810 | hf_body.append(' glv_LogError("get_mem_info_entry() realloc failed\\n");') |
| 811 | hf_body.append(' //glv_LogInfo("realloc memInfo from %u to %u\\n", g_memInfo.capacity /2, g_memInfo.capacity);') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 812 | hf_body.append(' //init the newly added entrys') |
Jon Ashburn | f7ab1a0 | 2015-02-19 17:04:06 -0700 | [diff] [blame] | 813 | hf_body.append(' init_mem_info_entrys(g_memInfo.pEntrys + g_memInfo.capacity / 2, g_memInfo.capacity / 2);') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 814 | hf_body.append(' }') |
| 815 | hf_body.append('') |
Jon Ashburn | f7ab1a0 | 2015-02-19 17:04:06 -0700 | [diff] [blame] | 816 | hf_body.append(' assert(g_memInfo.numEntrys < g_memInfo.capacity);') |
Jon Ashburn | a95f438 | 2015-02-20 14:48:27 -0700 | [diff] [blame] | 817 | hf_body.append(' entry = g_memInfo.pEntrys + g_memInfo.numEntrys;') |
| 818 | hf_body.append(' g_memInfo.numEntrys++;') |
| 819 | hf_body.append(' assert(entry->valid == FALSE);') |
| 820 | hf_body.append(' return entry;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 821 | hf_body.append('}') |
| 822 | hf_body.append('') |
Jon Ashburn | f7ab1a0 | 2015-02-19 17:04:06 -0700 | [diff] [blame] | 823 | hf_body.append('// caller must hold the g_memInfoLock') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 824 | hf_body.append('static XGLAllocInfo * find_mem_info_entry(const XGL_GPU_MEMORY handle)') |
| 825 | hf_body.append('{') |
Jon Ashburn | f7ab1a0 | 2015-02-19 17:04:06 -0700 | [diff] [blame] | 826 | hf_body.append(' XGLAllocInfo *entry;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 827 | hf_body.append(' unsigned int i;') |
Jon Ashburn | f7ab1a0 | 2015-02-19 17:04:06 -0700 | [diff] [blame] | 828 | hf_body.append(' entry = g_memInfo.pEntrys;') |
| 829 | hf_body.append(' if (g_memInfo.pLastMapped && g_memInfo.pLastMapped->handle == handle && g_memInfo.pLastMapped->valid)') |
| 830 | hf_body.append(' {') |
| 831 | hf_body.append(' return g_memInfo.pLastMapped;') |
| 832 | hf_body.append(' }') |
| 833 | hf_body.append(' for (i = 0; i < g_memInfo.numEntrys; i++)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 834 | hf_body.append(' {') |
| 835 | hf_body.append(' if ((entry + i)->valid && (handle == (entry + i)->handle))') |
Jon Ashburn | f7ab1a0 | 2015-02-19 17:04:06 -0700 | [diff] [blame] | 836 | hf_body.append(' {') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 837 | hf_body.append(' return entry + i;') |
Jon Ashburn | f7ab1a0 | 2015-02-19 17:04:06 -0700 | [diff] [blame] | 838 | hf_body.append(' }') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 839 | hf_body.append(' }') |
| 840 | hf_body.append('') |
| 841 | hf_body.append(' return NULL;') |
| 842 | hf_body.append('}') |
| 843 | hf_body.append('') |
Jon Ashburn | f7ab1a0 | 2015-02-19 17:04:06 -0700 | [diff] [blame] | 844 | hf_body.append('static XGLAllocInfo * find_mem_info_entry_lock(const XGL_GPU_MEMORY handle)') |
| 845 | hf_body.append('{') |
| 846 | hf_body.append(' XGLAllocInfo *res;') |
| 847 | hf_body.append(' glv_enter_critical_section(&g_memInfoLock);') |
| 848 | hf_body.append(' res = find_mem_info_entry(handle);') |
| 849 | hf_body.append(' glv_leave_critical_section(&g_memInfoLock);') |
| 850 | hf_body.append(' return res;') |
| 851 | hf_body.append('}') |
| 852 | hf_body.append('') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 853 | hf_body.append('static void add_new_handle_to_mem_info(const XGL_GPU_MEMORY handle, XGL_GPU_SIZE size, void *pData)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 854 | hf_body.append('{') |
| 855 | hf_body.append(' XGLAllocInfo *entry;') |
| 856 | hf_body.append('') |
Jon Ashburn | f7ab1a0 | 2015-02-19 17:04:06 -0700 | [diff] [blame] | 857 | hf_body.append(' glv_enter_critical_section(&g_memInfoLock);') |
| 858 | hf_body.append(' if (g_memInfo.capacity == 0)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 859 | hf_body.append(' init_mem_info();') |
| 860 | hf_body.append('') |
| 861 | hf_body.append(' entry = get_mem_info_entry();') |
| 862 | hf_body.append(' if (entry)') |
| 863 | hf_body.append(' {') |
| 864 | hf_body.append(' entry->valid = TRUE;') |
| 865 | hf_body.append(' entry->handle = handle;') |
| 866 | hf_body.append(' entry->size = size;') |
| 867 | hf_body.append(' entry->pData = pData; // NOTE: xglFreeMemory will free this mem, so no malloc()') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 868 | hf_body.append(' }') |
Jon Ashburn | f7ab1a0 | 2015-02-19 17:04:06 -0700 | [diff] [blame] | 869 | hf_body.append(' glv_leave_critical_section(&g_memInfoLock);') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 870 | hf_body.append('}') |
| 871 | hf_body.append('') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 872 | hf_body.append('static void add_data_to_mem_info(const XGL_GPU_MEMORY handle, void *pData)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 873 | hf_body.append('{') |
Jon Ashburn | f7ab1a0 | 2015-02-19 17:04:06 -0700 | [diff] [blame] | 874 | hf_body.append(' XGLAllocInfo *entry;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 875 | hf_body.append('') |
Jon Ashburn | f7ab1a0 | 2015-02-19 17:04:06 -0700 | [diff] [blame] | 876 | hf_body.append(' glv_enter_critical_section(&g_memInfoLock);') |
| 877 | hf_body.append(' entry = find_mem_info_entry(handle);') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 878 | hf_body.append(' if (entry)') |
| 879 | hf_body.append(' {') |
| 880 | hf_body.append(' entry->pData = pData;') |
| 881 | hf_body.append(' }') |
Jon Ashburn | f7ab1a0 | 2015-02-19 17:04:06 -0700 | [diff] [blame] | 882 | hf_body.append(' g_memInfo.pLastMapped = entry;') |
| 883 | hf_body.append(' glv_leave_critical_section(&g_memInfoLock);') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 884 | hf_body.append('}') |
| 885 | hf_body.append('') |
| 886 | hf_body.append('static void rm_handle_from_mem_info(const XGL_GPU_MEMORY handle)') |
| 887 | hf_body.append('{') |
Jon Ashburn | f7ab1a0 | 2015-02-19 17:04:06 -0700 | [diff] [blame] | 888 | hf_body.append(' XGLAllocInfo *entry;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 889 | hf_body.append('') |
Jon Ashburn | f7ab1a0 | 2015-02-19 17:04:06 -0700 | [diff] [blame] | 890 | hf_body.append(' glv_enter_critical_section(&g_memInfoLock);') |
| 891 | hf_body.append(' entry = find_mem_info_entry(handle);') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 892 | hf_body.append(' if (entry)') |
| 893 | hf_body.append(' {') |
| 894 | hf_body.append(' entry->valid = FALSE;') |
| 895 | hf_body.append(' entry->pData = NULL;') |
| 896 | hf_body.append(' entry->size = 0;') |
| 897 | hf_body.append(' entry->handle = NULL;') |
| 898 | hf_body.append('') |
Jon Ashburn | f7ab1a0 | 2015-02-19 17:04:06 -0700 | [diff] [blame] | 899 | hf_body.append(' if (entry == g_memInfo.pLastMapped)') |
| 900 | hf_body.append(' g_memInfo.pLastMapped = NULL;') |
Jon Ashburn | a20b67b | 2015-02-26 11:45:28 -0700 | [diff] [blame] | 901 | hf_body.append(' // adjust numEntrys to be last valid entry in list') |
| 902 | hf_body.append(' do {') |
| 903 | hf_body.append(' entry = g_memInfo.pEntrys + g_memInfo.numEntrys - 1;') |
| 904 | hf_body.append(' if (entry->valid == FALSE)') |
| 905 | hf_body.append(' g_memInfo.numEntrys--;') |
| 906 | hf_body.append(' } while ((entry->valid == FALSE) && (g_memInfo.numEntrys > 0));') |
Jon Ashburn | f7ab1a0 | 2015-02-19 17:04:06 -0700 | [diff] [blame] | 907 | hf_body.append(' if (g_memInfo.numEntrys == 0)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 908 | hf_body.append(' delete_mem_info();') |
| 909 | hf_body.append(' }') |
Jon Ashburn | f7ab1a0 | 2015-02-19 17:04:06 -0700 | [diff] [blame] | 910 | hf_body.append(' glv_leave_critical_section(&g_memInfoLock);') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 911 | hf_body.append('}') |
| 912 | hf_body.append('') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 913 | hf_body.append('static void add_begin_cmdbuf_to_trace_packet(glv_trace_packet_header* pHeader, void** ppOut, const void* pIn)') |
Jon Ashburn | 38349d0 | 2015-01-02 18:28:26 -0700 | [diff] [blame] | 914 | hf_body.append('{') |
| 915 | hf_body.append(' const XGL_CMD_BUFFER_BEGIN_INFO* pInNow = pIn;') |
| 916 | hf_body.append(' XGL_CMD_BUFFER_BEGIN_INFO** ppOutNext = (XGL_CMD_BUFFER_BEGIN_INFO**)ppOut;') |
| 917 | hf_body.append(' while (pInNow != NULL)') |
| 918 | hf_body.append(' {') |
| 919 | hf_body.append(' XGL_CMD_BUFFER_BEGIN_INFO** ppOutNow = ppOutNext;') |
| 920 | hf_body.append(' ppOutNext = NULL;') |
| 921 | hf_body.append('') |
| 922 | hf_body.append(' switch (pInNow->sType)') |
| 923 | hf_body.append(' {') |
| 924 | hf_body.append(' case XGL_STRUCTURE_TYPE_CMD_BUFFER_GRAPHICS_BEGIN_INFO:') |
| 925 | hf_body.append(' {') |
| 926 | hf_body.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)(ppOutNow), sizeof(XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO), pInNow);') |
| 927 | hf_body.append(' ppOutNext = (XGL_CMD_BUFFER_BEGIN_INFO**)&(*ppOutNow)->pNext;') |
| 928 | hf_body.append(' glv_finalize_buffer_address(pHeader, (void**)(ppOutNow));') |
| 929 | hf_body.append(' break;') |
| 930 | hf_body.append(' }') |
| 931 | hf_body.append(' default:') |
Jon Ashburn | c95d41b | 2015-02-03 07:33:48 -0700 | [diff] [blame] | 932 | hf_body.append(' assert(!"Encountered an unexpected type in cmdbuffer_begin_info list");') |
Jon Ashburn | 38349d0 | 2015-01-02 18:28:26 -0700 | [diff] [blame] | 933 | hf_body.append(' }') |
| 934 | hf_body.append(' pInNow = (XGL_CMD_BUFFER_BEGIN_INFO*)pInNow->pNext;') |
| 935 | hf_body.append(' }') |
| 936 | hf_body.append(' return;') |
| 937 | hf_body.append('}') |
Tobin Ehlis | f29cc37 | 2015-01-22 12:29:31 -0700 | [diff] [blame] | 938 | hf_body.append('') |
Jon Ashburn | c95d41b | 2015-02-03 07:33:48 -0700 | [diff] [blame] | 939 | hf_body.append('static void add_alloc_memory_to_trace_packet(glv_trace_packet_header* pHeader, void** ppOut, const void* pIn)') |
| 940 | hf_body.append('{') |
| 941 | hf_body.append(' const XGL_MEMORY_ALLOC_INFO* pInNow = pIn;') |
| 942 | hf_body.append(' XGL_MEMORY_ALLOC_INFO** ppOutNext = (XGL_MEMORY_ALLOC_INFO**)ppOut;') |
| 943 | hf_body.append(' while (pInNow != NULL)') |
| 944 | hf_body.append(' {') |
| 945 | hf_body.append(' XGL_MEMORY_ALLOC_INFO** ppOutNow = ppOutNext;') |
| 946 | hf_body.append(' ppOutNext = NULL;') |
| 947 | hf_body.append('') |
| 948 | hf_body.append(' switch (pInNow->sType)') |
| 949 | hf_body.append(' {') |
| 950 | hf_body.append(' case XGL_STRUCTURE_TYPE_MEMORY_ALLOC_BUFFER_INFO:') |
| 951 | hf_body.append(' {') |
| 952 | hf_body.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)(ppOutNow), sizeof(XGL_MEMORY_ALLOC_BUFFER_INFO), pInNow);') |
| 953 | hf_body.append(' ppOutNext = (XGL_MEMORY_ALLOC_INFO**)&(*ppOutNow)->pNext;') |
| 954 | hf_body.append(' glv_finalize_buffer_address(pHeader, (void**)(ppOutNow));') |
| 955 | hf_body.append(' break;') |
| 956 | hf_body.append(' }') |
| 957 | hf_body.append(' case XGL_STRUCTURE_TYPE_MEMORY_ALLOC_IMAGE_INFO:') |
| 958 | hf_body.append(' {') |
| 959 | hf_body.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)(ppOutNow), sizeof(XGL_MEMORY_ALLOC_IMAGE_INFO), pInNow);') |
| 960 | hf_body.append(' ppOutNext = (XGL_MEMORY_ALLOC_INFO**)&(*ppOutNow)->pNext;') |
| 961 | hf_body.append(' glv_finalize_buffer_address(pHeader, (void**)(ppOutNow));') |
| 962 | hf_body.append(' break;') |
| 963 | hf_body.append(' }') |
| 964 | hf_body.append(' default:') |
| 965 | hf_body.append(' assert(!"Encountered an unexpected type in memory_alloc_info list");') |
| 966 | hf_body.append(' }') |
| 967 | hf_body.append(' pInNow = (XGL_MEMORY_ALLOC_INFO*)pInNow->pNext;') |
| 968 | hf_body.append(' }') |
| 969 | hf_body.append(' return;') |
| 970 | hf_body.append('}') |
| 971 | hf_body.append('') |
Jon Ashburn | 308cc4c | 2015-02-10 13:49:30 -0700 | [diff] [blame] | 972 | hf_body.append('static size_t calculate_memory_barrier_size(uint32_t mbCount, const void** ppMemBarriers)') |
| 973 | hf_body.append('{') |
| 974 | hf_body.append(' uint32_t i, siz=0;') |
| 975 | hf_body.append(' for (i = 0; i < mbCount; i++) {') |
| 976 | hf_body.append(' XGL_MEMORY_BARRIER *pNext = (XGL_MEMORY_BARRIER *) ppMemBarriers[i];') |
| 977 | hf_body.append(' switch (pNext->sType) {') |
| 978 | hf_body.append(' case XGL_STRUCTURE_TYPE_MEMORY_BARRIER:') |
| 979 | hf_body.append(' siz += sizeof(XGL_MEMORY_BARRIER);') |
| 980 | hf_body.append(' break;') |
| 981 | hf_body.append(' case XGL_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER:') |
| 982 | hf_body.append(' siz += sizeof(XGL_BUFFER_MEMORY_BARRIER);') |
| 983 | hf_body.append(' break;') |
| 984 | hf_body.append(' case XGL_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER:') |
| 985 | hf_body.append(' siz += sizeof(XGL_IMAGE_MEMORY_BARRIER);') |
| 986 | hf_body.append(' break;') |
| 987 | hf_body.append(' default:') |
| 988 | hf_body.append(' assert(0);') |
| 989 | hf_body.append(' break;') |
| 990 | hf_body.append(' }') |
| 991 | hf_body.append(' }') |
| 992 | hf_body.append(' return siz;') |
| 993 | hf_body.append('}') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 994 | hf_body.append('') |
| 995 | hf_body.append('static void add_pipeline_shader_to_trace_packet(glv_trace_packet_header* pHeader, XGL_PIPELINE_SHADER* packetShader, const XGL_PIPELINE_SHADER* paramShader)') |
| 996 | hf_body.append('{') |
Tobin Ehlis | 1077703 | 2015-01-16 15:13:34 -0700 | [diff] [blame] | 997 | hf_body.append(' uint32_t i;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 998 | hf_body.append(' // constant buffers') |
| 999 | hf_body.append(' if (paramShader->linkConstBufferCount > 0 && paramShader->pLinkConstBufferInfo != NULL)') |
| 1000 | hf_body.append(' {') |
| 1001 | hf_body.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)&(packetShader->pLinkConstBufferInfo), sizeof(XGL_LINK_CONST_BUFFER) * paramShader->linkConstBufferCount, paramShader->pLinkConstBufferInfo);') |
| 1002 | hf_body.append(' for (i = 0; i < paramShader->linkConstBufferCount; i++)') |
| 1003 | hf_body.append(' {') |
| 1004 | hf_body.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)&(packetShader->pLinkConstBufferInfo[i].pBufferData), packetShader->pLinkConstBufferInfo[i].bufferSize, paramShader->pLinkConstBufferInfo[i].pBufferData);') |
| 1005 | hf_body.append(' }') |
| 1006 | hf_body.append(' }') |
| 1007 | hf_body.append('}') |
| 1008 | hf_body.append('') |
| 1009 | hf_body.append('static void finalize_pipeline_shader_address(glv_trace_packet_header* pHeader, const XGL_PIPELINE_SHADER* packetShader)') |
| 1010 | hf_body.append('{') |
Tobin Ehlis | 1077703 | 2015-01-16 15:13:34 -0700 | [diff] [blame] | 1011 | hf_body.append(' uint32_t i;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1012 | hf_body.append(' // constant buffers') |
| 1013 | hf_body.append(' if (packetShader->linkConstBufferCount > 0 && packetShader->pLinkConstBufferInfo != NULL)') |
| 1014 | hf_body.append(' {') |
| 1015 | hf_body.append(' for (i = 0; i < packetShader->linkConstBufferCount; i++)') |
| 1016 | hf_body.append(' {') |
| 1017 | hf_body.append(' glv_finalize_buffer_address(pHeader, (void**)&(packetShader->pLinkConstBufferInfo[i].pBufferData));') |
| 1018 | hf_body.append(' }') |
| 1019 | hf_body.append(' glv_finalize_buffer_address(pHeader, (void**)&(packetShader->pLinkConstBufferInfo));') |
| 1020 | hf_body.append(' }') |
| 1021 | hf_body.append('}') |
| 1022 | hf_body.append('') |
Tobin Ehlis | f6f8cd4 | 2015-02-03 14:41:26 -0700 | [diff] [blame] | 1023 | hf_body.append('static void add_create_ds_layout_to_trace_packet(glv_trace_packet_header* pHeader, void** ppOut, const void* pIn)') |
| 1024 | hf_body.append('{') |
| 1025 | hf_body.append(' const XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO* pInNow = pIn;') |
| 1026 | hf_body.append(' XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO** ppOutNext = (XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO**)ppOut;') |
| 1027 | hf_body.append(' while (pInNow != NULL)') |
| 1028 | hf_body.append(' {') |
| 1029 | hf_body.append(' XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO** ppOutNow = ppOutNext;') |
| 1030 | hf_body.append(' ppOutNext = NULL;') |
| 1031 | hf_body.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)(ppOutNow), sizeof(XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO), pInNow);') |
| 1032 | hf_body.append(' ppOutNext = (XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO**)&(*ppOutNow)->pNext;') |
| 1033 | hf_body.append(' glv_finalize_buffer_address(pHeader, (void**)(ppOutNow));') |
| 1034 | hf_body.append(' pInNow = (XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO*)pInNow->pNext;') |
| 1035 | hf_body.append(' }') |
| 1036 | hf_body.append(' return;') |
| 1037 | hf_body.append('}') |
| 1038 | hf_body.append('') |
Tobin Ehlis | f6f8cd4 | 2015-02-03 14:41:26 -0700 | [diff] [blame] | 1039 | hf_body.append('static void add_update_descriptors_to_trace_packet(glv_trace_packet_header* pHeader, void** ppOut, const void* pIn)') |
| 1040 | hf_body.append('{') |
| 1041 | hf_body.append(' const XGL_UPDATE_SAMPLERS* pInNow = pIn;') |
| 1042 | hf_body.append(' XGL_UPDATE_SAMPLERS** ppOutNext = (XGL_UPDATE_SAMPLERS**)ppOut;') |
| 1043 | hf_body.append(' while (pInNow != NULL)') |
| 1044 | hf_body.append(' {') |
| 1045 | hf_body.append(' XGL_UPDATE_SAMPLERS** ppOutNow = ppOutNext;') |
| 1046 | hf_body.append(' ppOutNext = NULL;') |
| 1047 | hf_body.append(' switch (pInNow->sType)') |
| 1048 | hf_body.append(' {') |
| 1049 | hf_body.append(' case XGL_STRUCTURE_TYPE_UPDATE_SAMPLERS:') |
| 1050 | hf_body.append(' {') |
| 1051 | hf_body.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)(ppOutNow), sizeof(XGL_UPDATE_SAMPLERS), pInNow);') |
Jon Ashburn | 23438a7 | 2015-02-03 17:47:58 -0700 | [diff] [blame] | 1052 | hf_body.append(' XGL_UPDATE_SAMPLERS* pPacket = (XGL_UPDATE_SAMPLERS*)*ppOutNow;') |
Tobin Ehlis | f6f8cd4 | 2015-02-03 14:41:26 -0700 | [diff] [blame] | 1053 | hf_body.append(' glv_add_buffer_to_trace_packet(pHeader, (void **) &pPacket->pSamplers, ((XGL_UPDATE_SAMPLERS*)pInNow)->count * sizeof(XGL_SAMPLER), ((XGL_UPDATE_SAMPLERS*)pInNow)->pSamplers);') |
| 1054 | hf_body.append(' glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pSamplers));') |
| 1055 | hf_body.append(' ppOutNext = (XGL_UPDATE_SAMPLERS**)&(*ppOutNow)->pNext;') |
| 1056 | hf_body.append(' glv_finalize_buffer_address(pHeader, (void**)(ppOutNow));') |
| 1057 | hf_body.append(' break;') |
| 1058 | hf_body.append(' }') |
| 1059 | hf_body.append(' case XGL_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:') |
| 1060 | hf_body.append(' {') |
| 1061 | #hf_body.append(' totalUpdateSize += sizeof(XGL_UPDATE_SAMPLER_TEXTURES) + ((XGL_UPDATE_SAMPLER_TEXTURES*)pNext)->count * (sizeof(XGL_SAMPLER_IMAGE_VIEW_INFO) + sizeof(XGL_IMAGE_VIEW_ATTACH_INFO));') |
Jon Ashburn | 23438a7 | 2015-02-03 17:47:58 -0700 | [diff] [blame] | 1062 | hf_body.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)(ppOutNow), sizeof(XGL_UPDATE_SAMPLER_TEXTURES), pInNow);') |
| 1063 | hf_body.append(' XGL_UPDATE_SAMPLER_TEXTURES* pPacket = (XGL_UPDATE_SAMPLER_TEXTURES*)*ppOutNow;') |
Tobin Ehlis | f6f8cd4 | 2015-02-03 14:41:26 -0700 | [diff] [blame] | 1064 | hf_body.append(' glv_add_buffer_to_trace_packet(pHeader, (void **) &pPacket->pSamplerImageViews, ((XGL_UPDATE_SAMPLER_TEXTURES*)pInNow)->count * sizeof(XGL_SAMPLER_IMAGE_VIEW_INFO), ((XGL_UPDATE_SAMPLER_TEXTURES*)pInNow)->pSamplerImageViews);') |
Tobin Ehlis | f6f8cd4 | 2015-02-03 14:41:26 -0700 | [diff] [blame] | 1065 | # TODO : This is still broken. How to update the original XGL_SAMPLER_IMAGE_VIEW_INFO struct ptrs to have correct address for newly added XGL_IMAGE_VIEW_ATTACH_INFO blocks below? |
| 1066 | hf_body.append(' uint32_t i;') |
| 1067 | hf_body.append(' for (i = 0; i < ((XGL_UPDATE_SAMPLER_TEXTURES*)pInNow)->count; i++) {') |
Jon Ashburn | 9c246bc | 2015-02-04 12:57:25 -0700 | [diff] [blame] | 1068 | hf_body.append(' glv_add_buffer_to_trace_packet(pHeader, (void **) &pPacket->pSamplerImageViews[i].pImageView, sizeof(XGL_IMAGE_VIEW_ATTACH_INFO), ((XGL_UPDATE_SAMPLER_TEXTURES*)pInNow)->pSamplerImageViews[i].pImageView);') |
Jon Ashburn | 23438a7 | 2015-02-03 17:47:58 -0700 | [diff] [blame] | 1069 | hf_body.append(' glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pSamplerImageViews[i].pImageView));') |
Tobin Ehlis | f6f8cd4 | 2015-02-03 14:41:26 -0700 | [diff] [blame] | 1070 | hf_body.append(' }') |
Jon Ashburn | 23438a7 | 2015-02-03 17:47:58 -0700 | [diff] [blame] | 1071 | hf_body.append(' glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pSamplerImageViews));') |
Tobin Ehlis | f6f8cd4 | 2015-02-03 14:41:26 -0700 | [diff] [blame] | 1072 | hf_body.append(' ppOutNext = (XGL_UPDATE_SAMPLERS**)&(*ppOutNow)->pNext;') |
| 1073 | hf_body.append(' glv_finalize_buffer_address(pHeader, (void**)(ppOutNow));') |
| 1074 | hf_body.append(' break;') |
| 1075 | hf_body.append(' }') |
| 1076 | hf_body.append(' case XGL_STRUCTURE_TYPE_UPDATE_IMAGES:') |
| 1077 | hf_body.append(' {') |
| 1078 | hf_body.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)(ppOutNow), sizeof(XGL_UPDATE_IMAGES), pInNow);') |
Jon Ashburn | 23438a7 | 2015-02-03 17:47:58 -0700 | [diff] [blame] | 1079 | hf_body.append(' XGL_UPDATE_IMAGES* pPacket = (XGL_UPDATE_IMAGES*)*ppOutNow;') |
Jon Ashburn | a04529d | 2015-02-04 16:26:30 -0700 | [diff] [blame] | 1080 | hf_body.append(' uint32_t i;') |
| 1081 | hf_body.append(' glv_add_buffer_to_trace_packet(pHeader, (void **) &pPacket->pImageViews, ((XGL_UPDATE_IMAGES*)pInNow)->count * sizeof(XGL_IMAGE_VIEW_ATTACH_INFO *), ((XGL_UPDATE_IMAGES*)pInNow)->pImageViews);') |
| 1082 | hf_body.append(' for (i = 0; i < ((XGL_UPDATE_IMAGES*)pInNow)->count; i++) {') |
| 1083 | hf_body.append(' glv_add_buffer_to_trace_packet(pHeader, (void **) &pPacket->pImageViews[i], sizeof(XGL_IMAGE_VIEW_ATTACH_INFO), ((XGL_UPDATE_IMAGES*)pInNow)->pImageViews[i]);') |
| 1084 | hf_body.append(' glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pImageViews[i]));') |
| 1085 | hf_body.append(' }') |
Tobin Ehlis | f6f8cd4 | 2015-02-03 14:41:26 -0700 | [diff] [blame] | 1086 | hf_body.append(' glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pImageViews));') |
| 1087 | hf_body.append(' ppOutNext = (XGL_UPDATE_SAMPLERS**)&(*ppOutNow)->pNext;') |
| 1088 | hf_body.append(' glv_finalize_buffer_address(pHeader, (void**)(ppOutNow));') |
| 1089 | hf_body.append(' break;') |
| 1090 | hf_body.append(' }') |
| 1091 | hf_body.append(' case XGL_STRUCTURE_TYPE_UPDATE_BUFFERS:') |
| 1092 | hf_body.append(' {') |
| 1093 | hf_body.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)(ppOutNow), sizeof(XGL_UPDATE_BUFFERS), pInNow);') |
Jon Ashburn | 23438a7 | 2015-02-03 17:47:58 -0700 | [diff] [blame] | 1094 | hf_body.append(' XGL_UPDATE_BUFFERS* pPacket = (XGL_UPDATE_BUFFERS*)*ppOutNow;') |
Jon Ashburn | a04529d | 2015-02-04 16:26:30 -0700 | [diff] [blame] | 1095 | hf_body.append(' glv_add_buffer_to_trace_packet(pHeader, (void **) &pPacket->pBufferViews, ((XGL_UPDATE_BUFFERS*)pInNow)->count * sizeof(XGL_BUFFER_VIEW_ATTACH_INFO *), ((XGL_UPDATE_BUFFERS*)pInNow)->pBufferViews);') |
| 1096 | hf_body.append(' uint32_t i;') |
| 1097 | hf_body.append(' for (i = 0; i < ((XGL_UPDATE_BUFFERS*)pInNow)->count; i++) {') |
| 1098 | hf_body.append(' glv_add_buffer_to_trace_packet(pHeader, (void **) &pPacket->pBufferViews[i], sizeof(XGL_BUFFER_VIEW_ATTACH_INFO), ((XGL_UPDATE_BUFFERS*)pInNow)->pBufferViews[i]);') |
| 1099 | hf_body.append(' glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pBufferViews[i]));') |
| 1100 | hf_body.append(' }') |
Tobin Ehlis | f6f8cd4 | 2015-02-03 14:41:26 -0700 | [diff] [blame] | 1101 | hf_body.append(' glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pBufferViews));') |
| 1102 | hf_body.append(' ppOutNext = (XGL_UPDATE_SAMPLERS**)&(*ppOutNow)->pNext;') |
| 1103 | hf_body.append(' glv_finalize_buffer_address(pHeader, (void**)(ppOutNow));') |
| 1104 | hf_body.append(' break;') |
| 1105 | hf_body.append(' }') |
| 1106 | hf_body.append(' case XGL_STRUCTURE_TYPE_UPDATE_AS_COPY:') |
| 1107 | hf_body.append(' {') |
| 1108 | hf_body.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)(ppOutNow), sizeof(XGL_UPDATE_AS_COPY), pInNow);') |
| 1109 | hf_body.append(' ppOutNext = (XGL_UPDATE_SAMPLERS**)&(*ppOutNow)->pNext;') |
| 1110 | hf_body.append(' glv_finalize_buffer_address(pHeader, (void**)(ppOutNow));') |
| 1111 | hf_body.append(' break;') |
| 1112 | hf_body.append(' }') |
| 1113 | hf_body.append(' default:') |
| 1114 | hf_body.append(' assert(0);') |
| 1115 | hf_body.append(' }') |
| 1116 | hf_body.append(' pInNow = (XGL_UPDATE_SAMPLERS*)pInNow->pNext;') |
| 1117 | hf_body.append(' }') |
| 1118 | hf_body.append(' return;') |
| 1119 | hf_body.append('}') |
| 1120 | hf_body.append('') |
Tobin Ehlis | bf967aa | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 1121 | pipe_state_list = ['IA_STATE_CREATE_INFO', |
| 1122 | 'TESS_STATE_CREATE_INFO', |
| 1123 | 'RS_STATE_CREATE_INFO', |
| 1124 | 'DS_STATE_CREATE_INFO', |
Tobin Ehlis | bf967aa | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 1125 | 'VP_STATE_CREATE_INFO', |
| 1126 | 'MS_STATE_CREATE_INFO' |
| 1127 | ] |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1128 | hf_body.append('static void add_pipeline_state_to_trace_packet(glv_trace_packet_header* pHeader, void** ppOut, const void* pIn)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1129 | hf_body.append('{') |
| 1130 | hf_body.append(' const XGL_GRAPHICS_PIPELINE_CREATE_INFO* pInNow = pIn;') |
| 1131 | hf_body.append(' XGL_GRAPHICS_PIPELINE_CREATE_INFO** ppOutNext = (XGL_GRAPHICS_PIPELINE_CREATE_INFO**)ppOut;') |
| 1132 | hf_body.append(' while (pInNow != NULL)') |
| 1133 | hf_body.append(' {') |
| 1134 | hf_body.append(' XGL_GRAPHICS_PIPELINE_CREATE_INFO** ppOutNow = ppOutNext;') |
| 1135 | hf_body.append(' ppOutNext = NULL;') |
| 1136 | hf_body.append('') |
| 1137 | hf_body.append(' switch (pInNow->sType)') |
| 1138 | hf_body.append(' {') |
Tobin Ehlis | bf967aa | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 1139 | for pipe_state in pipe_state_list: |
| 1140 | hf_body.append(' case XGL_STRUCTURE_TYPE_PIPELINE_%s:' % pipe_state) |
| 1141 | hf_body.append(' {') |
| 1142 | hf_body.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)(ppOutNow), sizeof(XGL_PIPELINE_%s), pInNow);' % pipe_state) |
| 1143 | hf_body.append(' ppOutNext = (XGL_GRAPHICS_PIPELINE_CREATE_INFO**)&(*ppOutNow)->pNext;') |
| 1144 | hf_body.append(' glv_finalize_buffer_address(pHeader, (void**)(ppOutNow));') |
| 1145 | hf_body.append(' break;') |
| 1146 | hf_body.append(' }') |
Jon Ashburn | 23438a7 | 2015-02-03 17:47:58 -0700 | [diff] [blame] | 1147 | hf_body.append(' case XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO:') |
| 1148 | hf_body.append(' {') |
| 1149 | hf_body.append(' XGL_PIPELINE_CB_STATE_CREATE_INFO *pPacket = NULL;') |
| 1150 | hf_body.append(' XGL_PIPELINE_CB_STATE_CREATE_INFO *pIn = NULL;') |
| 1151 | hf_body.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)(ppOutNow), sizeof(XGL_PIPELINE_CB_STATE_CREATE_INFO), pInNow);') |
| 1152 | hf_body.append(' pPacket = (XGL_PIPELINE_CB_STATE_CREATE_INFO*) *ppOutNow;') |
| 1153 | hf_body.append(' pIn = (XGL_PIPELINE_CB_STATE_CREATE_INFO*) pInNow;') |
| 1154 | hf_body.append(' glv_add_buffer_to_trace_packet(pHeader, (void **) &pPacket->pAttachments, pIn->attachmentCount * sizeof(XGL_PIPELINE_CB_ATTACHMENT_STATE), pIn->pAttachments);') |
| 1155 | hf_body.append(' glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pAttachments));') |
| 1156 | hf_body.append(' ppOutNext = (XGL_GRAPHICS_PIPELINE_CREATE_INFO**)&(*ppOutNow)->pNext;') |
| 1157 | hf_body.append(' glv_finalize_buffer_address(pHeader, (void**)(ppOutNow));') |
| 1158 | hf_body.append(' break;') |
| 1159 | hf_body.append(' }') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1160 | hf_body.append(' case XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO:') |
| 1161 | hf_body.append(' {') |
| 1162 | hf_body.append(' XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* pPacket = NULL;') |
| 1163 | hf_body.append(' XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* pInPacket = NULL;') |
| 1164 | hf_body.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)(ppOutNow), sizeof(XGL_PIPELINE_SHADER_STAGE_CREATE_INFO), pInNow);') |
| 1165 | hf_body.append(' pPacket = (XGL_PIPELINE_SHADER_STAGE_CREATE_INFO*) *ppOutNow;') |
| 1166 | hf_body.append(' pInPacket = (XGL_PIPELINE_SHADER_STAGE_CREATE_INFO*) pInNow;') |
| 1167 | hf_body.append(' add_pipeline_shader_to_trace_packet(pHeader, &pPacket->shader, &pInPacket->shader);') |
| 1168 | hf_body.append(' finalize_pipeline_shader_address(pHeader, &pPacket->shader);') |
| 1169 | hf_body.append(' ppOutNext = (XGL_GRAPHICS_PIPELINE_CREATE_INFO**)&(*ppOutNow)->pNext;') |
| 1170 | hf_body.append(' glv_finalize_buffer_address(pHeader, (void**)(ppOutNow));') |
| 1171 | hf_body.append(' break;') |
| 1172 | hf_body.append(' }') |
| 1173 | hf_body.append(' case XGL_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO:') |
| 1174 | hf_body.append(' {') |
| 1175 | hf_body.append(' XGL_PIPELINE_VERTEX_INPUT_CREATE_INFO *pPacket = NULL;') |
| 1176 | hf_body.append(' XGL_PIPELINE_VERTEX_INPUT_CREATE_INFO *pIn = NULL;') |
| 1177 | hf_body.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)(ppOutNow), sizeof(XGL_PIPELINE_VERTEX_INPUT_CREATE_INFO), pInNow);') |
| 1178 | hf_body.append(' pPacket = (XGL_PIPELINE_VERTEX_INPUT_CREATE_INFO*) *ppOutNow;') |
| 1179 | hf_body.append(' pIn = (XGL_PIPELINE_VERTEX_INPUT_CREATE_INFO*) pInNow;') |
| 1180 | hf_body.append(' glv_add_buffer_to_trace_packet(pHeader, (void **) &pPacket->pVertexBindingDescriptions, pIn->bindingCount * sizeof(XGL_VERTEX_INPUT_BINDING_DESCRIPTION), pIn->pVertexBindingDescriptions);') |
| 1181 | hf_body.append(' glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pVertexBindingDescriptions));') |
| 1182 | hf_body.append(' glv_add_buffer_to_trace_packet(pHeader, (void **) &pPacket->pVertexAttributeDescriptions, pIn->attributeCount * sizeof(XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION), pIn->pVertexAttributeDescriptions);') |
| 1183 | hf_body.append(' glv_finalize_buffer_address(pHeader, (void**)&(pPacket->pVertexAttributeDescriptions));') |
| 1184 | hf_body.append(' ppOutNext = (XGL_GRAPHICS_PIPELINE_CREATE_INFO**)&(*ppOutNow)->pNext;') |
| 1185 | hf_body.append(' glv_finalize_buffer_address(pHeader, (void**)(ppOutNow));') |
| 1186 | hf_body.append(' break;') |
| 1187 | hf_body.append(' }') |
| 1188 | hf_body.append(' default:') |
| 1189 | hf_body.append(' assert(!"Encountered an unexpected type in pipeline state list");') |
| 1190 | hf_body.append(' }') |
| 1191 | hf_body.append(' pInNow = (XGL_GRAPHICS_PIPELINE_CREATE_INFO*)pInNow->pNext;') |
| 1192 | hf_body.append(' }') |
| 1193 | hf_body.append(' return;') |
| 1194 | hf_body.append('}') |
| 1195 | return "\n".join(hf_body) |
| 1196 | |
| 1197 | def _generate_packet_id_enum(self): |
| 1198 | pid_enum = [] |
| 1199 | pid_enum.append('enum GLV_TRACE_PACKET_ID_XGL') |
| 1200 | pid_enum.append('{') |
| 1201 | first_func = True |
| 1202 | for proto in self.protos: |
| 1203 | if first_func: |
| 1204 | first_func = False |
Jon Ashburn | 15161e4 | 2014-12-16 18:37:04 -0700 | [diff] [blame] | 1205 | pid_enum.append(' GLV_TPI_XGL_xglApiVersion = GLV_TPI_BEGIN_API_HERE,') |
| 1206 | pid_enum.append(' GLV_TPI_XGL_xgl%s,' % proto.name) |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1207 | else: |
| 1208 | pid_enum.append(' GLV_TPI_XGL_xgl%s,' % proto.name) |
| 1209 | pid_enum.append('};\n') |
| 1210 | return "\n".join(pid_enum) |
| 1211 | |
| 1212 | def _generate_stringify_func(self): |
| 1213 | func_body = [] |
| 1214 | func_body.append('static const char *stringify_xgl_packet_id(const enum GLV_TRACE_PACKET_ID_XGL id, const glv_trace_packet_header* pHeader)') |
| 1215 | func_body.append('{') |
| 1216 | func_body.append(' static char str[1024];') |
| 1217 | func_body.append(' switch(id) {') |
Jon Ashburn | 15161e4 | 2014-12-16 18:37:04 -0700 | [diff] [blame] | 1218 | func_body.append(' case GLV_TPI_XGL_xglApiVersion:') |
| 1219 | func_body.append(' {') |
| 1220 | func_body.append(' struct_xglApiVersion* pPacket = (struct_xglApiVersion*)(pHeader->pBody);') |
| 1221 | func_body.append(' snprintf(str, 1024, "xglApiVersion = 0x%x", pPacket->version);') |
| 1222 | func_body.append(' return str;') |
| 1223 | func_body.append(' }') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1224 | for proto in self.protos: |
| 1225 | func_body.append(' case GLV_TPI_XGL_xgl%s:' % proto.name) |
| 1226 | func_body.append(' {') |
| 1227 | func_str = 'xgl%s(' % proto.name |
| 1228 | print_vals = '' |
| 1229 | create_func = False |
| 1230 | if 'Create' in proto.name or 'Alloc' in proto.name or 'MapMemory' in proto.name: |
| 1231 | create_func = True |
| 1232 | for p in proto.params: |
| 1233 | last_param = False |
| 1234 | if (p.name == proto.params[-1].name): |
| 1235 | last_param = True |
| 1236 | if last_param and create_func: # last param of create func |
Jon Ashburn | 9ef8beb | 2015-02-12 10:38:36 -0700 | [diff] [blame] | 1237 | (pft, pfi, ptr) = self._get_printf_params(p.ty,'pPacket->%s' % p.name, True) |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1238 | else: |
Jon Ashburn | 9ef8beb | 2015-02-12 10:38:36 -0700 | [diff] [blame] | 1239 | (pft, pfi, ptr) = self._get_printf_params(p.ty, 'pPacket->%s' % p.name, False) |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1240 | if last_param == True: |
Jon Ashburn | 9ef8beb | 2015-02-12 10:38:36 -0700 | [diff] [blame] | 1241 | func_str += '%s%s = %s)' % (ptr, p.name, pft) |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1242 | print_vals += ', %s' % (pfi) |
| 1243 | else: |
Jon Ashburn | 9ef8beb | 2015-02-12 10:38:36 -0700 | [diff] [blame] | 1244 | func_str += '%s%s = %s, ' % (ptr, p.name, pft) |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1245 | print_vals += ', %s' % (pfi) |
| 1246 | func_body.append(' struct_xgl%s* pPacket = (struct_xgl%s*)(pHeader->pBody);' % (proto.name, proto.name)) |
| 1247 | func_body.append(' snprintf(str, 1024, "%s"%s);' % (func_str, print_vals)) |
| 1248 | func_body.append(' return str;') |
| 1249 | func_body.append(' }') |
| 1250 | func_body.append(' default:') |
| 1251 | func_body.append(' return NULL;') |
| 1252 | func_body.append(' }') |
| 1253 | func_body.append('};\n') |
| 1254 | return "\n".join(func_body) |
| 1255 | |
| 1256 | def _generate_interp_func(self): |
| 1257 | interp_func_body = [] |
| 1258 | interp_func_body.append('static glv_trace_packet_header* interpret_trace_packet_xgl(glv_trace_packet_header* pHeader)') |
| 1259 | interp_func_body.append('{') |
| 1260 | interp_func_body.append(' if (pHeader == NULL)') |
| 1261 | interp_func_body.append(' {') |
| 1262 | interp_func_body.append(' return NULL;') |
| 1263 | interp_func_body.append(' }') |
| 1264 | interp_func_body.append(' switch (pHeader->packet_id)') |
| 1265 | interp_func_body.append(' {') |
Jon Ashburn | 15161e4 | 2014-12-16 18:37:04 -0700 | [diff] [blame] | 1266 | interp_func_body.append(' case GLV_TPI_XGL_xglApiVersion:\n {') |
| 1267 | interp_func_body.append(' return interpret_body_as_xglApiVersion(pHeader, TRUE)->header;\n }') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1268 | for proto in self.protos: |
| 1269 | interp_func_body.append(' case GLV_TPI_XGL_xgl%s:\n {' % proto.name) |
| 1270 | header_prefix = 'h' |
| 1271 | if 'Wsi' in proto.name or 'Dbg' in proto.name: |
| 1272 | header_prefix = 'pH' |
| 1273 | interp_func_body.append(' return interpret_body_as_xgl%s(pHeader)->%seader;\n }' % (proto.name, header_prefix)) |
| 1274 | interp_func_body.append(' default:') |
| 1275 | interp_func_body.append(' return NULL;') |
| 1276 | interp_func_body.append(' }') |
| 1277 | interp_func_body.append(' return NULL;') |
| 1278 | interp_func_body.append('}') |
| 1279 | return "\n".join(interp_func_body) |
| 1280 | |
| 1281 | def _generate_struct_util_funcs(self): |
| 1282 | pid_enum = [] |
| 1283 | pid_enum.append('//=============================================================================') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1284 | 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)') |
| 1285 | pid_enum.append('{') |
| 1286 | pid_enum.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)ppStruct, sizeof(XGL_APPLICATION_INFO), pInStruct);') |
Chia-I Wu | f1a5a74 | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 1287 | pid_enum.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)&((*ppStruct)->pAppName), strlen(pInStruct->pAppName) + 1, pInStruct->pAppName);') |
| 1288 | pid_enum.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)&((*ppStruct)->pEngineName), strlen(pInStruct->pEngineName) + 1, pInStruct->pEngineName);') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1289 | pid_enum.append(' glv_finalize_buffer_address(pHeader, (void**)&((*ppStruct)->pAppName));') |
| 1290 | pid_enum.append(' glv_finalize_buffer_address(pHeader, (void**)&((*ppStruct)->pEngineName));') |
| 1291 | pid_enum.append(' glv_finalize_buffer_address(pHeader, (void**)&*ppStruct);') |
| 1292 | pid_enum.append('};\n') |
| 1293 | pid_enum.append('//=============================================================================\n') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1294 | 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)') |
| 1295 | pid_enum.append('{') |
| 1296 | pid_enum.append(' uint32_t i;') |
| 1297 | pid_enum.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)ppStruct, sizeof(XGL_DEVICE_CREATE_INFO), pInStruct);') |
Tobin Ehlis | bd6a916 | 2015-03-13 07:18:05 -0600 | [diff] [blame] | 1298 | 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 | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1299 | pid_enum.append(' glv_finalize_buffer_address(pHeader, (void**)&(*ppStruct)->pRequestedQueues);') |
| 1300 | pid_enum.append(' if (pInStruct->extensionCount > 0) ') |
| 1301 | pid_enum.append(' {') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1302 | pid_enum.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)(&(*ppStruct)->ppEnabledExtensionNames), pInStruct->extensionCount * sizeof(char *), pInStruct->ppEnabledExtensionNames);') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1303 | pid_enum.append(' for (i = 0; i < pInStruct->extensionCount; i++)') |
| 1304 | pid_enum.append(' {') |
Chia-I Wu | f1a5a74 | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 1305 | pid_enum.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)(&((*ppStruct)->ppEnabledExtensionNames[i])), strlen(pInStruct->ppEnabledExtensionNames[i]) + 1, pInStruct->ppEnabledExtensionNames[i]);') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1306 | pid_enum.append(' glv_finalize_buffer_address(pHeader, (void**)(&((*ppStruct)->ppEnabledExtensionNames[i])));') |
| 1307 | pid_enum.append(' }') |
| 1308 | pid_enum.append(' glv_finalize_buffer_address(pHeader, (void **)&(*ppStruct)->ppEnabledExtensionNames);') |
| 1309 | pid_enum.append(' }') |
Jon Ashburn | 75dd04b | 2015-01-09 17:30:41 -0700 | [diff] [blame] | 1310 | pid_enum.append(' XGL_LAYER_CREATE_INFO *pNext = ( XGL_LAYER_CREATE_INFO *) pInStruct->pNext;') |
| 1311 | pid_enum.append(' while (pNext != NULL)') |
| 1312 | pid_enum.append(' {') |
| 1313 | pid_enum.append(' if ((pNext->sType == XGL_STRUCTURE_TYPE_LAYER_CREATE_INFO) && pNext->layerCount > 0)') |
| 1314 | pid_enum.append(' {') |
| 1315 | pid_enum.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)(&((*ppStruct)->pNext)), sizeof(XGL_LAYER_CREATE_INFO), pNext);') |
| 1316 | pid_enum.append(' glv_finalize_buffer_address(pHeader, (void**)(&((*ppStruct)->pNext)));') |
| 1317 | pid_enum.append(' XGL_LAYER_CREATE_INFO **ppOutStruct = (XGL_LAYER_CREATE_INFO **) &((*ppStruct)->pNext);') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1318 | pid_enum.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)(&(*ppOutStruct)->ppActiveLayerNames), pNext->layerCount * sizeof(char *), pNext->ppActiveLayerNames);') |
Jon Ashburn | 75dd04b | 2015-01-09 17:30:41 -0700 | [diff] [blame] | 1319 | pid_enum.append(' for (i = 0; i < pNext->layerCount; i++)') |
| 1320 | pid_enum.append(' {') |
| 1321 | pid_enum.append(' glv_add_buffer_to_trace_packet(pHeader, (void**)(&((*ppOutStruct)->ppActiveLayerNames[i])), strlen(pNext->ppActiveLayerNames[i]) + 1, pNext->ppActiveLayerNames[i]);') |
| 1322 | pid_enum.append(' glv_finalize_buffer_address(pHeader, (void**)(&((*ppOutStruct)->ppActiveLayerNames[i])));') |
| 1323 | pid_enum.append(' }') |
| 1324 | pid_enum.append(' glv_finalize_buffer_address(pHeader, (void **)&(*ppOutStruct)->ppActiveLayerNames);') |
| 1325 | pid_enum.append(' }') |
| 1326 | pid_enum.append(' pNext = ( XGL_LAYER_CREATE_INFO *) pNext->pNext;') |
| 1327 | pid_enum.append(' }') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1328 | pid_enum.append(' glv_finalize_buffer_address(pHeader, (void**)ppStruct);') |
| 1329 | pid_enum.append('}\n') |
| 1330 | pid_enum.append('static XGL_DEVICE_CREATE_INFO* interpret_XGL_DEVICE_CREATE_INFO(glv_trace_packet_header* pHeader, intptr_t ptr_variable)') |
| 1331 | pid_enum.append('{') |
| 1332 | 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') |
| 1333 | pid_enum.append(' if (pXGL_DEVICE_CREATE_INFO != NULL)') |
| 1334 | pid_enum.append(' {') |
Jon Ashburn | 75dd04b | 2015-01-09 17:30:41 -0700 | [diff] [blame] | 1335 | pid_enum.append(' uint32_t i;') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1336 | pid_enum.append(' const char** pNames;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1337 | 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') |
| 1338 | pid_enum.append(' if (pXGL_DEVICE_CREATE_INFO->extensionCount > 0)') |
| 1339 | pid_enum.append(' {') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1340 | 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);') |
| 1341 | pid_enum.append(' pNames = (const char**)pXGL_DEVICE_CREATE_INFO->ppEnabledExtensionNames;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1342 | pid_enum.append(' for (i = 0; i < pXGL_DEVICE_CREATE_INFO->extensionCount; i++)') |
| 1343 | pid_enum.append(' {') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1344 | pid_enum.append(' pNames[i] = (const char*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)(pXGL_DEVICE_CREATE_INFO->ppEnabledExtensionNames[i]));') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1345 | pid_enum.append(' }') |
| 1346 | pid_enum.append(' }') |
Jon Ashburn | 75dd04b | 2015-01-09 17:30:41 -0700 | [diff] [blame] | 1347 | 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);') |
| 1348 | pid_enum.append(' while (pNext != NULL)') |
| 1349 | pid_enum.append(' {') |
| 1350 | pid_enum.append(' if ((pNext->sType == XGL_STRUCTURE_TYPE_LAYER_CREATE_INFO) && pNext->layerCount > 0)') |
| 1351 | pid_enum.append(' {') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1352 | pid_enum.append(' pNext->ppActiveLayerNames = (const char**) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)(pNext->ppActiveLayerNames));') |
| 1353 | pid_enum.append(' pNames = (const char**)pNext->ppActiveLayerNames;') |
Jon Ashburn | 75dd04b | 2015-01-09 17:30:41 -0700 | [diff] [blame] | 1354 | pid_enum.append(' for (i = 0; i < pNext->layerCount; i++)') |
| 1355 | pid_enum.append(' {') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1356 | pid_enum.append(' pNames[i] = (const char*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)(pNext->ppActiveLayerNames[i]));') |
Jon Ashburn | 75dd04b | 2015-01-09 17:30:41 -0700 | [diff] [blame] | 1357 | pid_enum.append(' }') |
| 1358 | pid_enum.append(' }') |
| 1359 | pid_enum.append(' pNext = ( XGL_LAYER_CREATE_INFO *) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);') |
| 1360 | pid_enum.append(' }') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1361 | pid_enum.append(' }\n') |
| 1362 | pid_enum.append(' return pXGL_DEVICE_CREATE_INFO;') |
| 1363 | pid_enum.append('}\n') |
| 1364 | pid_enum.append('static void interpret_pipeline_shader(glv_trace_packet_header* pHeader, XGL_PIPELINE_SHADER* pShader)') |
| 1365 | pid_enum.append('{') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1366 | pid_enum.append(' if (pShader != NULL)') |
| 1367 | pid_enum.append(' {') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1368 | pid_enum.append(' // constant buffers') |
| 1369 | pid_enum.append(' if (pShader->linkConstBufferCount > 0)') |
| 1370 | pid_enum.append(' {') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1371 | pid_enum.append(' uint32_t i;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1372 | pid_enum.append(' pShader->pLinkConstBufferInfo = (const XGL_LINK_CONST_BUFFER*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pShader->pLinkConstBufferInfo);') |
| 1373 | pid_enum.append(' for (i = 0; i < pShader->linkConstBufferCount; i++)') |
| 1374 | pid_enum.append(' {') |
| 1375 | pid_enum.append(' XGL_LINK_CONST_BUFFER* pBuffer = (XGL_LINK_CONST_BUFFER*)pShader->pLinkConstBufferInfo;') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1376 | pid_enum.append(' pBuffer[i].pBufferData = (const void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pShader->pLinkConstBufferInfo[i].pBufferData);') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1377 | pid_enum.append(' }') |
| 1378 | pid_enum.append(' }') |
| 1379 | pid_enum.append(' }') |
| 1380 | pid_enum.append('}\n') |
| 1381 | pid_enum.append('//=============================================================================') |
| 1382 | return "\n".join(pid_enum) |
| 1383 | |
Tobin Ehlis | a8f6afe | 2015-02-05 11:29:45 -0700 | [diff] [blame] | 1384 | # Interpret functions used on replay to read in packets and interpret their contents |
Tobin Ehlis | dedfa07 | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 1385 | # This code gets generated into glvtrace_xgl_xgl_structs.h file |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1386 | def _generate_interp_funcs(self): |
| 1387 | # Custom txt for given function and parameter. First check if param is NULL, then insert txt if not |
Tobin Ehlis | a8f6afe | 2015-02-05 11:29:45 -0700 | [diff] [blame] | 1388 | # 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 | 1077703 | 2015-01-16 15:13:34 -0700 | [diff] [blame] | 1389 | custom_case_dict = { 'CreateInstance' : {'param': 'pAppInfo', 'txt': ['XGL_APPLICATION_INFO* pInfo = (XGL_APPLICATION_INFO*)pPacket->pAppInfo;\n', |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1390 | 'pInfo->pAppName = (const char*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pAppInfo->pAppName);\n', |
| 1391 | 'pInfo->pEngineName = (const char*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pAppInfo->pEngineName);']}, |
Jon Ashburn | 38349d0 | 2015-01-02 18:28:26 -0700 | [diff] [blame] | 1392 | 'CreateShader' : {'param': 'pCreateInfo', 'txt': ['XGL_SHADER_CREATE_INFO* pInfo = (XGL_SHADER_CREATE_INFO*)pPacket->pCreateInfo;\n', |
| 1393 | 'pInfo->pCode = glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pCreateInfo->pCode);']}, |
Jon Ashburn | 459a137 | 2015-02-04 08:50:35 -0700 | [diff] [blame] | 1394 | 'CreateDynamicViewportState' : {'param': 'pCreateInfo', 'txt': ['XGL_DYNAMIC_VP_STATE_CREATE_INFO* pInfo = (XGL_DYNAMIC_VP_STATE_CREATE_INFO*)pPacket->pCreateInfo;\n', |
| 1395 | 'pInfo->pViewports = (XGL_VIEWPORT*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pCreateInfo->pViewports);\n', |
| 1396 | 'pInfo->pScissors = (XGL_RECT*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pCreateInfo->pScissors);']}, |
Jon Ashburn | 38349d0 | 2015-01-02 18:28:26 -0700 | [diff] [blame] | 1397 | 'CreateFramebuffer' : {'param': 'pCreateInfo', 'txt': ['XGL_FRAMEBUFFER_CREATE_INFO* pInfo = (XGL_FRAMEBUFFER_CREATE_INFO*)pPacket->pCreateInfo;\n', |
| 1398 | 'pInfo->pColorAttachments = (XGL_COLOR_ATTACHMENT_BIND_INFO*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pCreateInfo->pColorAttachments);\n', |
| 1399 | 'pInfo->pDepthStencilAttachment = (XGL_DEPTH_STENCIL_BIND_INFO*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pCreateInfo->pDepthStencilAttachment);\n']}, |
| 1400 | 'CreateRenderPass' : {'param': 'pCreateInfo', 'txt': ['XGL_RENDER_PASS_CREATE_INFO* pInfo = (XGL_RENDER_PASS_CREATE_INFO*)pPacket->pCreateInfo;\n', |
| 1401 | 'pInfo->pColorLoadOps = (XGL_ATTACHMENT_LOAD_OP*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pCreateInfo->pColorLoadOps);\n', |
| 1402 | 'pInfo->pColorStoreOps = (XGL_ATTACHMENT_STORE_OP*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pCreateInfo->pColorStoreOps);\n', |
| 1403 | 'pInfo->pColorLoadClearValues = (XGL_CLEAR_COLOR*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pCreateInfo->pColorLoadClearValues);\n']}, |
Jon Ashburn | 4622454 | 2015-02-04 09:32:59 -0700 | [diff] [blame] | 1404 | 'CreateDescriptorRegion' : {'param': 'pCreateInfo', 'txt': ['XGL_DESCRIPTOR_REGION_CREATE_INFO* pInfo = (XGL_DESCRIPTOR_REGION_CREATE_INFO*)pPacket->pCreateInfo;\n', |
| 1405 | 'pInfo->pTypeCount = (XGL_DESCRIPTOR_TYPE_COUNT*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pCreateInfo->pTypeCount);\n']}, |
Tobin Ehlis | a8f6afe | 2015-02-05 11:29:45 -0700 | [diff] [blame] | 1406 | 'CmdWaitEvents' : {'param': 'pWaitInfo', 'txt': ['XGL_EVENT_WAIT_INFO* pInfo = (XGL_EVENT_WAIT_INFO*)pPacket->pWaitInfo;\n', |
| 1407 | 'pInfo->pEvents = (XGL_EVENT*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pWaitInfo->pEvents);\n', |
| 1408 | 'pInfo->ppMemBarriers = (const void**) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pWaitInfo->ppMemBarriers);\n', |
| 1409 | 'uint32_t i;\n', |
| 1410 | 'for (i = 0; i < pInfo->memBarrierCount; i++) {\n', |
| 1411 | ' void** ppLocalMemBarriers = (void**)&pInfo->ppMemBarriers[i];\n', |
| 1412 | ' *ppLocalMemBarriers = (void*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pInfo->ppMemBarriers[i]);\n', |
| 1413 | '}']}, |
| 1414 | 'CmdPipelineBarrier' : {'param': 'pBarrier', 'txt': ['XGL_PIPELINE_BARRIER* pBarrier = (XGL_PIPELINE_BARRIER*)pPacket->pBarrier;\n', |
| 1415 | 'pBarrier->pEvents = (XGL_SET_EVENT*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pBarrier->pEvents);\n', |
| 1416 | 'pBarrier->ppMemBarriers = (const void**) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pBarrier->ppMemBarriers);\n', |
| 1417 | 'uint32_t i;\n', |
| 1418 | 'for (i = 0; i < pBarrier->memBarrierCount; i++) {\n', |
| 1419 | ' void** ppLocalMemBarriers = (void**)&pBarrier->ppMemBarriers[i];\n', |
| 1420 | ' *ppLocalMemBarriers = (void*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pBarrier->ppMemBarriers[i]);\n', |
| 1421 | '}']}, |
Peter Lohrmann | 5d95a19 | 2015-03-10 15:30:36 -0700 | [diff] [blame] | 1422 | 'CreateDescriptorSetLayout' : {'param': 'pSetLayoutInfoList', 'txt': ['if (pPacket->pSetLayoutInfoList->sType == XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO) {\n', |
| 1423 | ' // need to make a non-const pointer to the pointer so that we can properly change the original pointer to the interpretted one\n', |
| 1424 | ' void** ppNextVoidPtr = (void**)&(pPacket->pSetLayoutInfoList->pNext);\n', |
| 1425 | ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pSetLayoutInfoList->pNext);\n', |
| 1426 | ' XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO* pNext = (XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO*)pPacket->pSetLayoutInfoList->pNext;\n', |
| 1427 | ' while (NULL != pNext)\n', ' {\n', |
| 1428 | ' switch(pNext->sType)\n', ' {\n', |
| 1429 | ' case XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO:\n', |
| 1430 | ' {\n' , |
| 1431 | ' void** ppNextVoidPtr = (void**)&pNext->pNext;\n', |
| 1432 | ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n', |
| 1433 | ' break;\n', |
| 1434 | ' }\n', |
| 1435 | ' default:\n', |
| 1436 | ' {\n', |
| 1437 | ' glv_LogError("Encountered an unexpected type in descriptor set layout create list.\\n");\n', |
| 1438 | ' pPacket->header = NULL;\n', |
| 1439 | ' pNext->pNext = NULL;\n', |
| 1440 | ' }\n', |
Jon Ashburn | 629f800 | 2015-02-04 10:55:47 -0700 | [diff] [blame] | 1441 | ' }\n', |
Peter Lohrmann | 5d95a19 | 2015-03-10 15:30:36 -0700 | [diff] [blame] | 1442 | ' pNext = (XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO*)pNext->pNext;\n', |
| 1443 | ' }\n', |
| 1444 | '} else {\n', |
| 1445 | ' // This is unexpected.\n', |
| 1446 | ' glv_LogError("CreateDescriptorSetLayout must have LayoutInfoList stype of XGL_STRCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO\\n");\n', |
| 1447 | ' pPacket->header = NULL;\n', |
Jon Ashburn | 629f800 | 2015-02-04 10:55:47 -0700 | [diff] [blame] | 1448 | '}']}, |
Peter Lohrmann | 5d95a19 | 2015-03-10 15:30:36 -0700 | [diff] [blame] | 1449 | 'BeginCommandBuffer' : {'param': 'pBeginInfo', 'txt': ['if (pPacket->pBeginInfo->sType == XGL_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO) {\n', |
| 1450 | ' // need to make a non-const pointer to the pointer so that we can properly change the original pointer to the interpretted one\n', |
| 1451 | ' XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO** ppNext = (XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO**)&(pPacket->pBeginInfo->pNext);\n', |
| 1452 | ' *ppNext = (XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pBeginInfo->pNext);\n', |
| 1453 | ' XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO* pNext = *ppNext;\n', |
| 1454 | ' while (NULL != pNext)\n', ' {\n', |
| 1455 | ' switch(pNext->sType)\n', ' {\n', |
| 1456 | ' case XGL_STRUCTURE_TYPE_CMD_BUFFER_GRAPHICS_BEGIN_INFO:\n', |
| 1457 | ' {\n', |
| 1458 | ' ppNext = (XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO**) &pNext->pNext;\n', |
| 1459 | ' *ppNext = (XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n', |
| 1460 | ' break;\n', |
| 1461 | ' }\n', |
| 1462 | ' default:\n', |
| 1463 | ' {\n', |
| 1464 | ' glv_LogError("Encountered an unexpected type in begin command buffer list.\\n");\n', |
| 1465 | ' pPacket->header = NULL;\n', |
| 1466 | ' pNext->pNext = NULL;\n', |
| 1467 | ' }\n', |
Jon Ashburn | 38349d0 | 2015-01-02 18:28:26 -0700 | [diff] [blame] | 1468 | ' }\n', |
Peter Lohrmann | 5d95a19 | 2015-03-10 15:30:36 -0700 | [diff] [blame] | 1469 | ' pNext = (XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO*)pNext->pNext;\n', |
Jon Ashburn | 38349d0 | 2015-01-02 18:28:26 -0700 | [diff] [blame] | 1470 | ' }\n', |
Peter Lohrmann | 5d95a19 | 2015-03-10 15:30:36 -0700 | [diff] [blame] | 1471 | '} else {\n', |
| 1472 | ' // This is unexpected.\n', |
| 1473 | ' glv_LogError("BeginCommandBuffer must have BeginInfo stype of XGL_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO.\\n");\n', |
| 1474 | ' pPacket->header = NULL;\n', |
Jon Ashburn | 38349d0 | 2015-01-02 18:28:26 -0700 | [diff] [blame] | 1475 | '}']}, |
Peter Lohrmann | 5d95a19 | 2015-03-10 15:30:36 -0700 | [diff] [blame] | 1476 | 'AllocMemory' : {'param': 'pAllocInfo', 'txt': ['if (pPacket->pAllocInfo->sType == XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO) {\n', |
| 1477 | ' XGL_MEMORY_ALLOC_INFO** ppNext = (XGL_MEMORY_ALLOC_INFO**) &(pPacket->pAllocInfo->pNext);\n', |
| 1478 | ' *ppNext = (XGL_MEMORY_ALLOC_INFO*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pAllocInfo->pNext);\n', |
| 1479 | ' XGL_MEMORY_ALLOC_INFO* pNext = (XGL_MEMORY_ALLOC_INFO*) *ppNext;\n', |
| 1480 | ' while (NULL != pNext)\n', ' {\n', |
| 1481 | ' switch(pNext->sType)\n', ' {\n', |
| 1482 | ' case XGL_STRUCTURE_TYPE_MEMORY_ALLOC_BUFFER_INFO:\n', |
| 1483 | ' case XGL_STRUCTURE_TYPE_MEMORY_ALLOC_IMAGE_INFO:\n', |
| 1484 | ' {\n', |
| 1485 | ' ppNext = (XGL_MEMORY_ALLOC_INFO **) &(pNext->pNext);\n', |
| 1486 | ' *ppNext = (XGL_MEMORY_ALLOC_INFO*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n', |
| 1487 | ' break;\n', |
| 1488 | ' }\n', |
| 1489 | ' default:\n', |
| 1490 | ' {\n', |
| 1491 | ' glv_LogError("Encountered an unexpected type alloc memory list.\\n");\n', |
| 1492 | ' pPacket->header = NULL;\n', |
| 1493 | ' pNext->pNext = NULL;\n', |
| 1494 | ' }\n', |
Jon Ashburn | c95d41b | 2015-02-03 07:33:48 -0700 | [diff] [blame] | 1495 | ' }\n', |
Peter Lohrmann | 5d95a19 | 2015-03-10 15:30:36 -0700 | [diff] [blame] | 1496 | ' pNext = (XGL_MEMORY_ALLOC_INFO*)pNext->pNext;\n', |
Jon Ashburn | c95d41b | 2015-02-03 07:33:48 -0700 | [diff] [blame] | 1497 | ' }\n', |
Peter Lohrmann | 5d95a19 | 2015-03-10 15:30:36 -0700 | [diff] [blame] | 1498 | '} else {\n', |
| 1499 | ' // This is unexpected.\n', |
| 1500 | ' glv_LogError("AllocMemory must have AllocInfo stype of XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO.\\n");\n', |
| 1501 | ' pPacket->header = NULL;\n', |
Jon Ashburn | c95d41b | 2015-02-03 07:33:48 -0700 | [diff] [blame] | 1502 | '}']}, |
Tobin Ehlis | 7e62676 | 2015-02-04 10:53:31 -0700 | [diff] [blame] | 1503 | 'UpdateDescriptors' : {'param': 'pUpdateChain', 'txt': ['XGL_UPDATE_SAMPLERS* pNext = (XGL_UPDATE_SAMPLERS*)pPacket->pUpdateChain;\n', |
| 1504 | 'while ((NULL != pNext) && (XGL_NULL_HANDLE != pNext))\n', '{\n', |
| 1505 | ' switch(pNext->sType)\n', ' {\n', |
| 1506 | ' case XGL_STRUCTURE_TYPE_UPDATE_AS_COPY:\n', |
| 1507 | ' {\n', |
| 1508 | ' void** ppNextVoidPtr = (void**)&pNext->pNext;\n', |
| 1509 | ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n', |
| 1510 | ' break;\n', |
| 1511 | ' }\n', |
| 1512 | ' case XGL_STRUCTURE_TYPE_UPDATE_SAMPLERS:\n', |
| 1513 | ' {\n', |
| 1514 | ' void** ppNextVoidPtr = (void**)&pNext->pNext;\n', |
| 1515 | ' XGL_UPDATE_SAMPLERS* pUS = (XGL_UPDATE_SAMPLERS*)pNext;\n', |
| 1516 | ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n', |
| 1517 | ' pUS->pSamplers = (XGL_SAMPLER*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pUS->pSamplers);\n', |
| 1518 | ' break;\n', |
| 1519 | ' }\n', |
| 1520 | ' case XGL_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:\n', |
| 1521 | ' {\n', |
| 1522 | ' void** ppNextVoidPtr = (void**)&pNext->pNext;\n', |
| 1523 | ' XGL_UPDATE_SAMPLER_TEXTURES* pUST = (XGL_UPDATE_SAMPLER_TEXTURES*)pNext;\n', |
| 1524 | ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n', |
| 1525 | ' pUST->pSamplerImageViews = (XGL_SAMPLER_IMAGE_VIEW_INFO*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pUST->pSamplerImageViews);\n', |
| 1526 | ' uint32_t i;\n', |
| 1527 | ' for (i = 0; i < pUST->count; i++) {\n', |
| 1528 | ' XGL_IMAGE_VIEW_ATTACH_INFO** ppLocalImageView = (XGL_IMAGE_VIEW_ATTACH_INFO**)&pUST->pSamplerImageViews[i].pImageView;\n', |
| 1529 | ' *ppLocalImageView = (XGL_IMAGE_VIEW_ATTACH_INFO*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pUST->pSamplerImageViews[i].pImageView);\n', |
| 1530 | ' }\n', |
| 1531 | ' break;\n', |
| 1532 | ' }\n', |
| 1533 | ' case XGL_STRUCTURE_TYPE_UPDATE_IMAGES:\n', |
| 1534 | ' {\n', |
| 1535 | ' void** ppNextVoidPtr = (void**)&pNext->pNext;\n', |
| 1536 | ' XGL_UPDATE_IMAGES* pUI = (XGL_UPDATE_IMAGES*)pNext;\n', |
| 1537 | ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n', |
Jon Ashburn | a04529d | 2015-02-04 16:26:30 -0700 | [diff] [blame] | 1538 | ' XGL_IMAGE_VIEW_ATTACH_INFO** ppLocalImageView = (XGL_IMAGE_VIEW_ATTACH_INFO**)&pUI->pImageViews;\n', |
| 1539 | ' *ppLocalImageView = (XGL_IMAGE_VIEW_ATTACH_INFO*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pUI->pImageViews);\n', |
| 1540 | ' uint32_t i;\n', |
| 1541 | ' for (i = 0; i < pUI->count; i++) {\n', |
| 1542 | ' XGL_IMAGE_VIEW_ATTACH_INFO** ppLocalImageViews = (XGL_IMAGE_VIEW_ATTACH_INFO**)&pUI->pImageViews[i];\n', |
| 1543 | ' *ppLocalImageViews = (XGL_IMAGE_VIEW_ATTACH_INFO*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pUI->pImageViews[i]);\n', |
| 1544 | ' }\n', |
Tobin Ehlis | 7e62676 | 2015-02-04 10:53:31 -0700 | [diff] [blame] | 1545 | ' break;\n', |
| 1546 | ' }\n', |
| 1547 | ' case XGL_STRUCTURE_TYPE_UPDATE_BUFFERS:\n', |
| 1548 | ' {\n', |
| 1549 | ' void** ppNextVoidPtr = (void**)&pNext->pNext;\n', |
| 1550 | ' XGL_UPDATE_BUFFERS* pUB = (XGL_UPDATE_BUFFERS*)pNext;\n', |
| 1551 | ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n', |
Jon Ashburn | a04529d | 2015-02-04 16:26:30 -0700 | [diff] [blame] | 1552 | ' XGL_BUFFER_VIEW_ATTACH_INFO** ppLocalBufferView = (XGL_BUFFER_VIEW_ATTACH_INFO**)&pUB->pBufferViews;\n', |
| 1553 | ' *ppLocalBufferView = (XGL_BUFFER_VIEW_ATTACH_INFO*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pUB->pBufferViews);\n', |
| 1554 | ' uint32_t i;\n', |
| 1555 | ' for (i = 0; i < pUB->count; i++) {\n', |
| 1556 | ' XGL_BUFFER_VIEW_ATTACH_INFO** ppLocalBufferViews = (XGL_BUFFER_VIEW_ATTACH_INFO**)&pUB->pBufferViews[i];\n', |
| 1557 | ' *ppLocalBufferViews = (XGL_BUFFER_VIEW_ATTACH_INFO*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pUB->pBufferViews[i]);\n', |
| 1558 | ' }\n', |
Tobin Ehlis | 7e62676 | 2015-02-04 10:53:31 -0700 | [diff] [blame] | 1559 | ' break;\n', |
| 1560 | ' }\n', |
| 1561 | ' default:\n', |
Peter Lohrmann | 5d95a19 | 2015-03-10 15:30:36 -0700 | [diff] [blame] | 1562 | ' {\n', |
| 1563 | ' glv_LogError("Encountered an unexpected type in update descriptors pUpdateChain.\\n");\n', |
| 1564 | ' pPacket->header = NULL;\n', |
| 1565 | ' pNext->pNext = NULL;\n', |
| 1566 | ' }\n', |
Tobin Ehlis | 7e62676 | 2015-02-04 10:53:31 -0700 | [diff] [blame] | 1567 | ' }\n', |
| 1568 | ' pNext = (XGL_UPDATE_SAMPLERS*)pNext->pNext;\n', |
| 1569 | '}']}, |
Peter Lohrmann | 5d95a19 | 2015-03-10 15:30:36 -0700 | [diff] [blame] | 1570 | 'CreateGraphicsPipeline' : {'param': 'pCreateInfo', 'txt': ['if (pPacket->pCreateInfo->sType == XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO) {\n', |
| 1571 | ' // need to make a non-const pointer to the pointer so that we can properly change the original pointer to the interpretted one\n', |
| 1572 | ' void** ppNextVoidPtr = (void**)&pPacket->pCreateInfo->pNext;\n', |
| 1573 | ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->pCreateInfo->pNext);\n', |
| 1574 | ' XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* pNext = (XGL_PIPELINE_SHADER_STAGE_CREATE_INFO*)pPacket->pCreateInfo->pNext;\n', |
| 1575 | ' while ((NULL != pNext) && (XGL_NULL_HANDLE != pNext))\n', '{\n', |
| 1576 | ' switch(pNext->sType)\n', ' {\n', |
| 1577 | ' case XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO:\n', |
| 1578 | ' case XGL_STRUCTURE_TYPE_PIPELINE_TESS_STATE_CREATE_INFO:\n', |
| 1579 | ' case XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO:\n', |
| 1580 | ' case XGL_STRUCTURE_TYPE_PIPELINE_VP_STATE_CREATE_INFO:\n', |
| 1581 | ' case XGL_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO:\n', |
| 1582 | ' case XGL_STRUCTURE_TYPE_PIPELINE_DS_STATE_CREATE_INFO:\n', |
| 1583 | ' {\n', |
| 1584 | ' void** ppNextVoidPtr = (void**)&pNext->pNext;\n', |
| 1585 | ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n', |
| 1586 | ' break;\n', |
| 1587 | ' }\n', |
| 1588 | ' case XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO:\n', |
| 1589 | ' {\n', |
| 1590 | ' void** ppNextVoidPtr = (void**)&pNext->pNext;\n', |
| 1591 | ' XGL_PIPELINE_CB_STATE_CREATE_INFO *pCb = (XGL_PIPELINE_CB_STATE_CREATE_INFO *) pNext;\n', |
| 1592 | ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n', |
| 1593 | ' pCb->pAttachments = (XGL_PIPELINE_CB_ATTACHMENT_STATE*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pCb->pAttachments);\n', |
| 1594 | ' break;\n', |
| 1595 | ' }\n', |
| 1596 | ' case XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO:\n', |
| 1597 | ' {\n', |
| 1598 | ' void** ppNextVoidPtr = (void**)&pNext->pNext;\n', |
| 1599 | ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n', |
| 1600 | ' interpret_pipeline_shader(pHeader, &pNext->shader);\n', |
| 1601 | ' break;\n', |
| 1602 | ' }\n', |
| 1603 | ' case XGL_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO:\n', |
| 1604 | ' {\n', |
| 1605 | ' void** ppNextVoidPtr = (void**)&pNext->pNext;\n', |
| 1606 | ' XGL_PIPELINE_VERTEX_INPUT_CREATE_INFO *pVi = (XGL_PIPELINE_VERTEX_INPUT_CREATE_INFO *) pNext;\n', |
| 1607 | ' *ppNextVoidPtr = (void*)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pNext->pNext);\n', |
| 1608 | ' pVi->pVertexBindingDescriptions = (XGL_VERTEX_INPUT_BINDING_DESCRIPTION*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pVi->pVertexBindingDescriptions);\n', |
| 1609 | ' pVi->pVertexAttributeDescriptions = (XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION*) glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pVi->pVertexAttributeDescriptions);\n', |
| 1610 | ' break;\n', |
| 1611 | ' }\n', |
| 1612 | ' default:\n', |
| 1613 | ' {\n', |
| 1614 | ' glv_LogError("Encountered an unexpected type in pipeline state list.\\n");\n', |
| 1615 | ' pPacket->header = NULL;\n', |
| 1616 | ' pNext->pNext = NULL;\n', |
| 1617 | ' }\n', |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1618 | ' }\n', |
Peter Lohrmann | 5d95a19 | 2015-03-10 15:30:36 -0700 | [diff] [blame] | 1619 | ' pNext = (XGL_PIPELINE_SHADER_STAGE_CREATE_INFO*)pNext->pNext;\n', |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1620 | ' }\n', |
Peter Lohrmann | 5d95a19 | 2015-03-10 15:30:36 -0700 | [diff] [blame] | 1621 | '} else {\n', |
| 1622 | ' // This is unexpected.\n', |
| 1623 | ' glv_LogError("CreateGraphicsPipeline must have CreateInfo stype of XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO.\\n");\n', |
| 1624 | ' pPacket->header = NULL;\n', |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1625 | '}']}, |
Tobin Ehlis | 1077703 | 2015-01-16 15:13:34 -0700 | [diff] [blame] | 1626 | 'CreateComputePipeline' : {'param': 'pCreateInfo', 'txt': ['interpret_pipeline_shader(pHeader, (XGL_PIPELINE_SHADER*)(&pPacket->pCreateInfo->cs));']}} |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1627 | if_body = [] |
Jon Ashburn | 15161e4 | 2014-12-16 18:37:04 -0700 | [diff] [blame] | 1628 | if_body.append('typedef struct struct_xglApiVersion {') |
| 1629 | if_body.append(' glv_trace_packet_header* header;') |
| 1630 | if_body.append(' uint32_t version;') |
| 1631 | if_body.append('} struct_xglApiVersion;\n') |
| 1632 | if_body.append('static struct_xglApiVersion* interpret_body_as_xglApiVersion(glv_trace_packet_header* pHeader, BOOL check_version)') |
| 1633 | if_body.append('{') |
| 1634 | if_body.append(' struct_xglApiVersion* pPacket = (struct_xglApiVersion*)pHeader->pBody;') |
| 1635 | if_body.append(' pPacket->header = pHeader;') |
| 1636 | if_body.append(' if (check_version && pPacket->version != XGL_API_VERSION)') |
| 1637 | 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);') |
| 1638 | if_body.append(' return pPacket;') |
| 1639 | if_body.append('}\n') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1640 | for proto in self.protos: |
| 1641 | if 'Wsi' not in proto.name and 'Dbg' not in proto.name: |
| 1642 | if 'UnmapMemory' == proto.name: |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1643 | proto.params.append(xgl.Param("void*", "pData")) |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1644 | if_body.append('typedef struct struct_xgl%s {' % proto.name) |
| 1645 | if_body.append(' glv_trace_packet_header* header;') |
| 1646 | for p in proto.params: |
| 1647 | if '[4]' in p.ty: |
| 1648 | if_body.append(' %s %s[4];' % (p.ty.strip('[4]'), p.name)) |
| 1649 | else: |
| 1650 | if_body.append(' %s %s;' % (p.ty, p.name)) |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1651 | if 'void' != proto.ret: |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1652 | if_body.append(' %s result;' % proto.ret) |
| 1653 | if_body.append('} struct_xgl%s;\n' % proto.name) |
| 1654 | if_body.append('static struct_xgl%s* interpret_body_as_xgl%s(glv_trace_packet_header* pHeader)' % (proto.name, proto.name)) |
| 1655 | if_body.append('{') |
| 1656 | if_body.append(' struct_xgl%s* pPacket = (struct_xgl%s*)pHeader->pBody;' % (proto.name, proto.name)) |
| 1657 | if_body.append(' pPacket->header = pHeader;') |
| 1658 | for p in proto.params: |
| 1659 | if '*' in p.ty: |
| 1660 | if 'DEVICE_CREATE_INFO' in p.ty: |
| 1661 | if_body.append(' pPacket->%s = interpret_XGL_DEVICE_CREATE_INFO(pHeader, (intptr_t)pPacket->%s);' % (p.name, p.name)) |
| 1662 | else: |
| 1663 | 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 | dedfa07 | 2015-03-10 11:04:17 -0600 | [diff] [blame] | 1664 | # TODO : Generalize this custom code to kill dict data struct above. |
| 1665 | # Really the point of this block is to catch params w/ embedded ptrs to structs and chains of structs |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1666 | if proto.name in custom_case_dict and p.name == custom_case_dict[proto.name]['param']: |
| 1667 | if_body.append(' if (pPacket->%s != NULL)' % custom_case_dict[proto.name]['param']) |
| 1668 | if_body.append(' {') |
| 1669 | if_body.append(' %s' % " ".join(custom_case_dict[proto.name]['txt'])) |
| 1670 | if_body.append(' }') |
| 1671 | if_body.append(' return pPacket;') |
| 1672 | if_body.append('}\n') |
| 1673 | return "\n".join(if_body) |
| 1674 | |
| 1675 | def _generate_interp_funcs_ext(self, func_class='Wsi'): |
| 1676 | if_body = [] |
| 1677 | for proto in self.protos: |
| 1678 | if func_class in proto.name: |
| 1679 | if_body.append('typedef struct struct_xgl%s {' % proto.name) |
| 1680 | if_body.append(' glv_trace_packet_header* pHeader;') |
| 1681 | for p in proto.params: |
| 1682 | if_body.append(' %s %s;' % (p.ty, p.name)) |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1683 | if 'void' != proto.ret: |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1684 | if_body.append(' %s result;' % proto.ret) |
| 1685 | if_body.append('} struct_xgl%s;\n' % proto.name) |
| 1686 | if_body.append('static struct_xgl%s* interpret_body_as_xgl%s(glv_trace_packet_header* pHeader)' % (proto.name, proto.name)) |
| 1687 | if_body.append('{') |
| 1688 | if_body.append(' struct_xgl%s* pPacket = (struct_xgl%s*)pHeader->pBody;' % (proto.name, proto.name)) |
| 1689 | if_body.append(' pPacket->pHeader = pHeader;') |
| 1690 | for p in proto.params: |
| 1691 | if '*' in p.ty: |
| 1692 | if_body.append(' pPacket->%s = (%s)glv_trace_packet_interpret_buffer_pointer(pHeader, (intptr_t)pPacket->%s);' % (p.name, p.ty, p.name)) |
| 1693 | if_body.append(' return pPacket;') |
| 1694 | if_body.append('}\n') |
| 1695 | return "\n".join(if_body) |
| 1696 | |
| 1697 | def _generate_replay_class_decls(self): |
| 1698 | cd_body = [] |
| 1699 | cd_body.append('class ApiReplay {') |
| 1700 | cd_body.append('public:') |
| 1701 | cd_body.append(' virtual ~ApiReplay() { }') |
| 1702 | cd_body.append(' virtual enum glv_replay::GLV_REPLAY_RESULT replay(glv_trace_packet_header * packet) = 0;') |
| 1703 | cd_body.append(' virtual int init(glv_replay::Display & disp) = 0;') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1704 | cd_body.append(' virtual void push_validation_msg(XGL_VALIDATION_LEVEL validationLevel, XGL_BASE_OBJECT srcObject, size_t location, int32_t msgCode, const char* pMsg) = 0;') |
Jon Ashburn | ce66ab8 | 2014-12-18 17:03:34 -0700 | [diff] [blame] | 1705 | cd_body.append(' virtual glv_replay::GLV_REPLAY_RESULT pop_validation_msgs() = 0;') |
Jon Ashburn | 8ef49b1 | 2015-02-17 13:28:11 -0700 | [diff] [blame] | 1706 | cd_body.append(' virtual int dump_validation_data() = 0;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1707 | cd_body.append('};\n') |
| 1708 | cd_body.append('class xglDisplay: public glv_replay::DisplayImp {') |
| 1709 | cd_body.append('friend class xglReplay;') |
| 1710 | cd_body.append('public:') |
| 1711 | cd_body.append(' xglDisplay();') |
| 1712 | cd_body.append(' ~xglDisplay();') |
| 1713 | cd_body.append(' int init(const unsigned int gpu_idx);') |
| 1714 | cd_body.append(' int set_window(glv_window_handle hWindow, unsigned int width, unsigned int height);') |
| 1715 | cd_body.append(' int create_window(const unsigned int width, const unsigned int height);') |
| 1716 | cd_body.append(' void resize_window(const unsigned int width, const unsigned int height);') |
| 1717 | cd_body.append(' void process_event();') |
| 1718 | cd_body.append(' // XGL_DEVICE get_device() { return m_dev[m_gpuIdx];}') |
Piers Daniell | 188f820 | 2015-02-24 13:58:47 -0700 | [diff] [blame] | 1719 | cd_body.append('#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1720 | cd_body.append(' xcb_window_t get_window_handle() { return m_XcbWindow; }') |
Piers Daniell | 188f820 | 2015-02-24 13:58:47 -0700 | [diff] [blame] | 1721 | cd_body.append('#elif defined(WIN32)') |
| 1722 | cd_body.append(' HWND get_window_handle() { return m_windowHandle; }') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1723 | cd_body.append('#endif') |
| 1724 | cd_body.append('private:') |
| 1725 | cd_body.append(' XGL_RESULT init_xgl(const unsigned int gpu_idx);') |
| 1726 | cd_body.append(' bool m_initedXGL;') |
Piers Daniell | 188f820 | 2015-02-24 13:58:47 -0700 | [diff] [blame] | 1727 | cd_body.append('#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1728 | cd_body.append(' XGL_WSI_X11_CONNECTION_INFO m_WsiConnection;') |
| 1729 | cd_body.append(' xcb_screen_t *m_pXcbScreen;') |
| 1730 | cd_body.append(' xcb_window_t m_XcbWindow;') |
Piers Daniell | 188f820 | 2015-02-24 13:58:47 -0700 | [diff] [blame] | 1731 | cd_body.append('#elif defined(WIN32)') |
| 1732 | cd_body.append(' HWND m_windowHandle;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1733 | cd_body.append('#endif') |
| 1734 | cd_body.append(' unsigned int m_windowWidth;') |
| 1735 | cd_body.append(' unsigned int m_windowHeight;') |
Tony Barbour | 5d5bc99 | 2015-02-02 13:21:18 -0700 | [diff] [blame] | 1736 | cd_body.append(' unsigned int m_frameNumber;') |
Tony Barbour | a7390a0 | 2015-02-05 09:46:17 -0700 | [diff] [blame] | 1737 | cd_body.append(' std::vector<uint32_t> imageWidth;') |
| 1738 | cd_body.append(' std::vector<uint32_t> imageHeight;') |
| 1739 | cd_body.append(' std::vector<XGL_IMAGE> imageHandles;') |
| 1740 | cd_body.append(' std::vector<XGL_GPU_MEMORY> imageMemory;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1741 | cd_body.append('#if 0') |
| 1742 | cd_body.append(' XGL_DEVICE m_dev[XGL_MAX_PHYSICAL_GPUS];') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1743 | cd_body.append(' uint32_t m_gpuCount;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1744 | cd_body.append(' unsigned int m_gpuIdx;') |
| 1745 | cd_body.append(' XGL_PHYSICAL_GPU m_gpus[XGL_MAX_PHYSICAL_GPUS];') |
| 1746 | cd_body.append(' XGL_PHYSICAL_GPU_PROPERTIES m_gpuProps[XGL_MAX_PHYSICAL_GPUS];') |
| 1747 | cd_body.append('#endif') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1748 | cd_body.append(' std::vector<char *>m_extensions;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1749 | cd_body.append('};\n') |
| 1750 | cd_body.append('typedef struct _XGLAllocInfo {') |
| 1751 | cd_body.append(' XGL_GPU_SIZE size;') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1752 | cd_body.append(' void *pData;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1753 | cd_body.append('} XGLAllocInfo;') |
| 1754 | return "\n".join(cd_body) |
| 1755 | |
| 1756 | def _generate_replay_func_ptrs(self): |
| 1757 | xf_body = [] |
| 1758 | xf_body.append('struct xglFuncs {') |
| 1759 | xf_body.append(' void init_funcs(void * libHandle);') |
| 1760 | xf_body.append(' void *m_libHandle;\n') |
| 1761 | for proto in self.protos: |
| 1762 | xf_body.append(' typedef %s( XGLAPI * type_xgl%s)(' % (proto.ret, proto.name)) |
| 1763 | for p in proto.params: |
| 1764 | if '[4]' in p.ty: |
| 1765 | xf_body.append(' %s %s[4],' % (p.ty.strip('[4]'), p.name)) |
| 1766 | else: |
| 1767 | xf_body.append(' %s %s,' % (p.ty, p.name)) |
| 1768 | xf_body[-1] = xf_body[-1].replace(',', ');') |
| 1769 | xf_body.append(' type_xgl%s real_xgl%s;' % (proto.name, proto.name)) |
| 1770 | xf_body.append('};') |
| 1771 | return "\n".join(xf_body) |
| 1772 | |
| 1773 | def _map_decl(self, type1, type2, name): |
| 1774 | return ' std::map<%s, %s> %s;' % (type1, type2, name) |
| 1775 | |
| 1776 | def _add_to_map_decl(self, type1, type2, name): |
| 1777 | txt = ' void add_to_map(%s* pTraceVal, %s* pReplayVal)\n {\n' % (type1, type2) |
| 1778 | txt += ' assert(pTraceVal != NULL);\n' |
| 1779 | txt += ' assert(pReplayVal != NULL);\n' |
| 1780 | txt += ' %s[*pTraceVal] = *pReplayVal;\n }' % name |
| 1781 | return txt |
| 1782 | |
| 1783 | def _rm_from_map_decl(self, ty, name): |
| 1784 | txt = ' void rm_from_map(const %s& key)\n {\n' % (ty) |
| 1785 | txt += ' %s.erase(key);\n }' % name |
| 1786 | return txt |
| 1787 | |
| 1788 | def _remap_decl(self, ty, name): |
| 1789 | txt = ' %s remap(const %s& value)\n {\n' % (ty, ty) |
| 1790 | txt += ' std::map<%s, %s>::const_iterator q = %s.find(value);\n' % (ty, ty, name) |
| 1791 | txt += ' return (q == %s.end()) ? XGL_NULL_HANDLE : q->second;\n }' % name |
| 1792 | return txt |
| 1793 | |
| 1794 | def _generate_replay_class(self): |
Tobin Ehlis | bf967aa | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 1795 | # Create dict mapping member var names to XGL type (i.e. 'm_imageViews' : 'XGL_IMAGE_VIEW') |
| 1796 | obj_map_dict = {} |
| 1797 | for ty in xgl.object_type_list: |
| 1798 | if ty in xgl.object_parent_list: |
| 1799 | continue |
| 1800 | mem_var = ty.replace('XGL_', '').lower() |
| 1801 | mem_var_list = mem_var.split('_') |
Tobin Ehlis | bf967aa | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 1802 | mem_var = 'm_%s%ss' % (mem_var_list[0], "".join([m.title() for m in mem_var_list[1:]])) |
| 1803 | obj_map_dict[mem_var] = ty |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1804 | rc_body = [] |
| 1805 | rc_body.append('class xglReplay : public ApiReplay {') |
| 1806 | rc_body.append('public:') |
| 1807 | rc_body.append(' ~xglReplay();') |
Ian Elliott | eca1638 | 2015-02-18 15:35:00 -0700 | [diff] [blame] | 1808 | rc_body.append(' xglReplay(glvreplay_settings *pReplaySettings);\n') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1809 | rc_body.append(' int init(glv_replay::Display & disp);') |
| 1810 | rc_body.append(' xglDisplay * get_display() {return m_display;}') |
| 1811 | rc_body.append(' glv_replay::GLV_REPLAY_RESULT replay(glv_trace_packet_header *packet);') |
| 1812 | rc_body.append(' glv_replay::GLV_REPLAY_RESULT handle_replay_errors(const char* entrypointName, const XGL_RESULT resCall, const XGL_RESULT resTrace, const glv_replay::GLV_REPLAY_RESULT resIn);\n') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1813 | rc_body.append(' void push_validation_msg(XGL_VALIDATION_LEVEL validationLevel, XGL_BASE_OBJECT srcObject, size_t location, int32_t msgCode, const char* pMsg);') |
Jon Ashburn | ce66ab8 | 2014-12-18 17:03:34 -0700 | [diff] [blame] | 1814 | rc_body.append(' glv_replay::GLV_REPLAY_RESULT pop_validation_msgs();') |
Jon Ashburn | 8ef49b1 | 2015-02-17 13:28:11 -0700 | [diff] [blame] | 1815 | rc_body.append(' int dump_validation_data();') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1816 | rc_body.append('private:') |
| 1817 | rc_body.append(' struct xglFuncs m_xglFuncs;') |
Jon Ashburn | 8ef49b1 | 2015-02-17 13:28:11 -0700 | [diff] [blame] | 1818 | rc_body.append(' DRAW_STATE_DUMP_DOT_FILE m_pDSDump;') |
Jeremy Hayes | 2c98e53 | 2015-02-26 15:59:19 -0700 | [diff] [blame] | 1819 | rc_body.append(' DRAW_STATE_DUMP_COMMAND_BUFFER_DOT_FILE m_pCBDump;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1820 | rc_body.append(' xglDisplay *m_display;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1821 | rc_body.append(' struct shaderPair {') |
| 1822 | rc_body.append(' XGL_SHADER *addr;') |
| 1823 | rc_body.append(' XGL_SHADER val;') |
| 1824 | rc_body.append(' };') |
Jon Ashburn | ce66ab8 | 2014-12-18 17:03:34 -0700 | [diff] [blame] | 1825 | rc_body.append(' struct validationMsg {') |
| 1826 | rc_body.append(' XGL_VALIDATION_LEVEL validationLevel;') |
| 1827 | rc_body.append(' XGL_BASE_OBJECT srcObject;') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1828 | rc_body.append(' size_t location;') |
| 1829 | rc_body.append(' int32_t msgCode;') |
Jon Ashburn | ce66ab8 | 2014-12-18 17:03:34 -0700 | [diff] [blame] | 1830 | rc_body.append(' char msg[256];') |
| 1831 | rc_body.append(' };') |
| 1832 | rc_body.append(' std::vector<struct validationMsg> m_validationMsgs;') |
Tony Barbour | a7390a0 | 2015-02-05 09:46:17 -0700 | [diff] [blame] | 1833 | rc_body.append(' std::vector<int> m_screenshotFrames;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1834 | rc_body.append(self._map_decl('XGL_GPU_MEMORY', 'XGLAllocInfo', 'm_mapData')) |
| 1835 | # Custom code for 1-off memory mapping functions |
| 1836 | rc_body.append(' void add_entry_to_mapData(XGL_GPU_MEMORY handle, XGL_GPU_SIZE size)') |
| 1837 | rc_body.append(' {') |
| 1838 | rc_body.append(' XGLAllocInfo info;') |
| 1839 | rc_body.append(' info.pData = NULL;') |
| 1840 | rc_body.append(' info.size = size;') |
| 1841 | rc_body.append(' m_mapData.insert(std::pair<XGL_GPU_MEMORY, XGLAllocInfo>(handle, info));') |
| 1842 | rc_body.append(' }') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1843 | rc_body.append(' void add_mapping_to_mapData(XGL_GPU_MEMORY handle, void *pData)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1844 | rc_body.append(' {') |
| 1845 | rc_body.append(' std::map<XGL_GPU_MEMORY,XGLAllocInfo>::iterator it = m_mapData.find(handle);') |
| 1846 | rc_body.append(' if (it == m_mapData.end())') |
| 1847 | rc_body.append(' {') |
| 1848 | rc_body.append(' glv_LogWarn("add_mapping_to_mapData() could not find entry\\n");') |
| 1849 | rc_body.append(' return;') |
| 1850 | rc_body.append(' }') |
| 1851 | rc_body.append(' XGLAllocInfo &info = it->second;') |
| 1852 | rc_body.append(' if (info.pData != NULL)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1853 | rc_body.append(' glv_LogWarn("add_mapping_to_mapData() data already mapped overwrite old mapping\\n");') |
Jon Ashburn | a915cb1 | 2015-02-20 13:10:52 -0700 | [diff] [blame] | 1854 | rc_body.append(' else if (pData == NULL)') |
| 1855 | rc_body.append(' glv_LogWarn("add_mapping_to_mapData() adding NULL pointer\\n");') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1856 | rc_body.append(' info.pData = pData;') |
| 1857 | rc_body.append(' }') |
| 1858 | rc_body.append(' void rm_entry_from_mapData(XGL_GPU_MEMORY handle)') |
| 1859 | rc_body.append(' {') |
| 1860 | rc_body.append(' std::map<XGL_GPU_MEMORY,XGLAllocInfo>::iterator it = m_mapData.find(handle);') |
| 1861 | rc_body.append(' if (it == m_mapData.end())') |
| 1862 | rc_body.append(' return;') |
| 1863 | rc_body.append(' m_mapData.erase(it);') |
| 1864 | rc_body.append(' }') |
Jon Ashburn | 290dcb1 | 2015-03-02 17:12:31 -0700 | [diff] [blame] | 1865 | rc_body.append(' void rm_mapping_from_mapData(XGL_GPU_MEMORY handle, void* pData)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1866 | rc_body.append(' {') |
| 1867 | rc_body.append(' std::map<XGL_GPU_MEMORY,XGLAllocInfo>::iterator it = m_mapData.find(handle);') |
| 1868 | rc_body.append(' if (it == m_mapData.end())') |
| 1869 | rc_body.append(' return;\n') |
| 1870 | rc_body.append(' XGLAllocInfo &info = it->second;') |
Jon Ashburn | 290dcb1 | 2015-03-02 17:12:31 -0700 | [diff] [blame] | 1871 | rc_body.append(' if (!pData || !info.pData)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1872 | rc_body.append(' {') |
Jon Ashburn | 290dcb1 | 2015-03-02 17:12:31 -0700 | [diff] [blame] | 1873 | rc_body.append(' if (!pData)') |
| 1874 | rc_body.append(' glv_LogWarn("rm_mapping_from_mapData() null src pointer\\n");') |
| 1875 | rc_body.append(' else') |
| 1876 | rc_body.append(' glv_LogWarn("rm_mapping_from_mapData() null dest pointer size=%u\\n", info.size);') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1877 | rc_body.append(' info.pData = NULL;') |
| 1878 | rc_body.append(' return;') |
| 1879 | rc_body.append(' }') |
Jon Ashburn | 290dcb1 | 2015-03-02 17:12:31 -0700 | [diff] [blame] | 1880 | rc_body.append(' memcpy(info.pData, pData, info.size);') |
| 1881 | rc_body.append(' info.pData = NULL;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1882 | rc_body.append(' }\n') |
| 1883 | rc_body.append(' /*std::map<XGL_PHYSICAL_GPU, XGL_PHYSICAL_GPU> m_gpus;') |
| 1884 | rc_body.append(' void add_to_map(XGL_PHYSICAL_GPU* pTraceGpu, XGL_PHYSICAL_GPU* pReplayGpu)') |
| 1885 | rc_body.append(' {') |
| 1886 | rc_body.append(' assert(pTraceGpu != NULL);') |
| 1887 | rc_body.append(' assert(pReplayGpu != NULL);') |
| 1888 | rc_body.append(' m_gpus[*pTraceGpu] = *pReplayGpu;') |
| 1889 | rc_body.append(' }\n') |
| 1890 | rc_body.append(' XGL_PHYSICAL_GPU remap(const XGL_PHYSICAL_GPU& gpu)') |
| 1891 | rc_body.append(' {') |
| 1892 | rc_body.append(' std::map<XGL_PHYSICAL_GPU, XGL_PHYSICAL_GPU>::const_iterator q = m_gpus.find(gpu);') |
| 1893 | rc_body.append(' return (q == m_gpus.end()) ? XGL_NULL_HANDLE : q->second;') |
| 1894 | rc_body.append(' }*/\n') |
| 1895 | rc_body.append(' void clear_all_map_handles()\n {') |
| 1896 | for var in sorted(obj_map_dict): |
| 1897 | rc_body.append(' %s.clear();' % var) |
| 1898 | rc_body.append(' }') |
| 1899 | for var in sorted(obj_map_dict): |
| 1900 | rc_body.append(self._map_decl(obj_map_dict[var], obj_map_dict[var], var)) |
| 1901 | rc_body.append(self._add_to_map_decl(obj_map_dict[var], obj_map_dict[var], var)) |
| 1902 | rc_body.append(self._rm_from_map_decl(obj_map_dict[var], var)) |
| 1903 | rc_body.append(self._remap_decl(obj_map_dict[var], var)) |
Tobin Ehlis | bf967aa | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 1904 | # XGL_DYNAMIC_STATE_OBJECT code |
| 1905 | state_obj_remap_types = xgl.object_dynamic_state_list |
| 1906 | rc_body.append(' XGL_DYNAMIC_STATE_OBJECT remap(const XGL_DYNAMIC_STATE_OBJECT& state)\n {') |
| 1907 | rc_body.append(' XGL_DYNAMIC_STATE_OBJECT obj;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1908 | for t in state_obj_remap_types: |
| 1909 | rc_body.append(' if ((obj = remap(static_cast <%s> (state))) != XGL_NULL_HANDLE)' % t) |
| 1910 | rc_body.append(' return obj;') |
| 1911 | rc_body.append(' return XGL_NULL_HANDLE;\n }') |
Tobin Ehlis | bf967aa | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 1912 | rc_body.append(' void rm_from_map(const XGL_DYNAMIC_STATE_OBJECT& state)\n {') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1913 | for t in state_obj_remap_types: |
| 1914 | rc_body.append(' rm_from_map(static_cast <%s> (state));' % t) |
| 1915 | rc_body.append(' }') |
| 1916 | # OBJECT code |
| 1917 | rc_body.append(' XGL_OBJECT remap(const XGL_OBJECT& object)\n {') |
| 1918 | rc_body.append(' XGL_OBJECT obj;') |
Tobin Ehlis | bf967aa | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 1919 | obj_remap_types = xgl.object_list |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1920 | for var in obj_remap_types: |
| 1921 | rc_body.append(' if ((obj = remap(static_cast <%s> (object))) != XGL_NULL_HANDLE)' % (var)) |
| 1922 | rc_body.append(' return obj;') |
| 1923 | rc_body.append(' return XGL_NULL_HANDLE;\n }') |
| 1924 | rc_body.append(' void rm_from_map(const XGL_OBJECT & objKey)\n {') |
| 1925 | for var in obj_remap_types: |
| 1926 | rc_body.append(' rm_from_map(static_cast <%s> (objKey));' % (var)) |
| 1927 | rc_body.append(' }') |
| 1928 | rc_body.append(' XGL_BASE_OBJECT remap(const XGL_BASE_OBJECT& object)\n {') |
| 1929 | rc_body.append(' XGL_BASE_OBJECT obj;') |
| 1930 | base_obj_remap_types = ['XGL_DEVICE', 'XGL_QUEUE', 'XGL_GPU_MEMORY', 'XGL_OBJECT'] |
| 1931 | for t in base_obj_remap_types: |
| 1932 | rc_body.append(' if ((obj = remap(static_cast <%s> (object))) != XGL_NULL_HANDLE)' % t) |
| 1933 | rc_body.append(' return obj;') |
| 1934 | rc_body.append(' return XGL_NULL_HANDLE;\n }') |
Tony Barbour | a7390a0 | 2015-02-05 09:46:17 -0700 | [diff] [blame] | 1935 | rc_body.append('void process_screenshot_list(const char *list)') |
Tony Barbour | 5d5bc99 | 2015-02-02 13:21:18 -0700 | [diff] [blame] | 1936 | rc_body.append('{') |
| 1937 | rc_body.append(' std::string spec(list), word;') |
| 1938 | rc_body.append(' size_t start = 0, comma = 0;\n') |
| 1939 | rc_body.append(' while (start < spec.size()) {') |
| 1940 | rc_body.append(' comma = spec.find(\',\', start);\n') |
| 1941 | rc_body.append(' if (comma == std::string::npos)') |
| 1942 | rc_body.append(' word = std::string(spec, start);') |
| 1943 | rc_body.append(' else') |
| 1944 | rc_body.append(' word = std::string(spec, start, comma - start);\n') |
Tony Barbour | cb273e7 | 2015-02-05 13:55:03 -0700 | [diff] [blame] | 1945 | rc_body.append(' m_screenshotFrames.push_back(atoi(word.c_str()));') |
Tony Barbour | 5d5bc99 | 2015-02-02 13:21:18 -0700 | [diff] [blame] | 1946 | rc_body.append(' if (comma == std::string::npos)') |
| 1947 | rc_body.append(' break;\n') |
| 1948 | rc_body.append(' start = comma + 1;\n') |
Tony Barbour | 5d5bc99 | 2015-02-02 13:21:18 -0700 | [diff] [blame] | 1949 | rc_body.append(' }') |
| 1950 | rc_body.append('}') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1951 | rc_body.append('};') |
| 1952 | return "\n".join(rc_body) |
| 1953 | |
| 1954 | def _generate_replay_display_init_xgl(self): |
| 1955 | dix_body = [] |
| 1956 | dix_body.append('XGL_RESULT xglDisplay::init_xgl(unsigned int gpu_idx)') |
| 1957 | dix_body.append('{') |
| 1958 | dix_body.append('#if 0') |
| 1959 | dix_body.append(' XGL_APPLICATION_INFO appInfo = {};') |
| 1960 | dix_body.append(' appInfo.pAppName = APP_NAME;') |
| 1961 | dix_body.append(' appInfo.pEngineName = "";') |
| 1962 | dix_body.append(' appInfo.apiVersion = XGL_API_VERSION;') |
| 1963 | dix_body.append(' XGL_RESULT res = xglInitAndEnumerateGpus(&appInfo, NULL, XGL_MAX_PHYSICAL_GPUS, &m_gpuCount, m_gpus);') |
| 1964 | dix_body.append(' if ( res == XGL_SUCCESS ) {') |
| 1965 | dix_body.append(' // retrieve the GPU information for all GPUs') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1966 | dix_body.append(' for( uint32_t gpu = 0; gpu < m_gpuCount; gpu++)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1967 | dix_body.append(' {') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1968 | dix_body.append(' size_t gpuInfoSize = sizeof(m_gpuProps[0]);\n') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1969 | dix_body.append(' // get the GPU physical properties:') |
| 1970 | dix_body.append(' res = xglGetGpuInfo( m_gpus[gpu], XGL_INFO_TYPE_PHYSICAL_GPU_PROPERTIES, &gpuInfoSize, &m_gpuProps[gpu]);') |
| 1971 | dix_body.append(' if (res != XGL_SUCCESS)') |
| 1972 | dix_body.append(' glv_LogWarn("Failed to retrieve properties for gpu[%d] result %d\\n", gpu, res);') |
| 1973 | dix_body.append(' }') |
| 1974 | dix_body.append(' res = XGL_SUCCESS;') |
| 1975 | dix_body.append(' } else if ((gpu_idx + 1) > m_gpuCount) {') |
| 1976 | dix_body.append(' glv_LogError("xglInitAndEnumerate number of gpus does not include requested index: num %d, requested %d\\n", m_gpuCount, gpu_idx);') |
| 1977 | dix_body.append(' return -1;') |
| 1978 | dix_body.append(' } else {') |
| 1979 | dix_body.append(' glv_LogError("xglInitAndEnumerate failed\\n");') |
| 1980 | dix_body.append(' return res;') |
| 1981 | dix_body.append(' }') |
| 1982 | dix_body.append(' // TODO add multi-gpu support always use gpu[gpu_idx] for now') |
| 1983 | dix_body.append(' // get all extensions supported by this device gpu[gpu_idx]') |
| 1984 | dix_body.append(' // first check if extensions are available and save a list of them') |
| 1985 | dix_body.append(' bool foundWSIExt = false;') |
| 1986 | dix_body.append(' for( int ext = 0; ext < sizeof( extensions ) / sizeof( extensions[0] ); ext++)') |
| 1987 | dix_body.append(' {') |
| 1988 | dix_body.append(' res = xglGetExtensionSupport( m_gpus[gpu_idx], extensions[ext] );') |
| 1989 | dix_body.append(' if (res == XGL_SUCCESS) {') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1990 | dix_body.append(' m_extensions.push_back((char *) extensions[ext]);') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 1991 | dix_body.append(' if (!strcmp(extensions[ext], "XGL_WSI_WINDOWS"))') |
| 1992 | dix_body.append(' foundWSIExt = true;') |
| 1993 | dix_body.append(' }') |
| 1994 | dix_body.append(' }') |
| 1995 | dix_body.append(' if (!foundWSIExt) {') |
| 1996 | dix_body.append(' glv_LogError("XGL_WSI_WINDOWS extension not supported by gpu[%d]\\n", gpu_idx);') |
| 1997 | dix_body.append(' return XGL_ERROR_INCOMPATIBLE_DEVICE;') |
| 1998 | dix_body.append(' }') |
| 1999 | dix_body.append(' // TODO generalize this: use one universal queue for now') |
| 2000 | dix_body.append(' XGL_DEVICE_QUEUE_CREATE_INFO dqci = {};') |
| 2001 | dix_body.append(' dqci.queueCount = 1;') |
| 2002 | dix_body.append(' dqci.queueType = XGL_QUEUE_UNIVERSAL;') |
| 2003 | dix_body.append(' // create the device enabling validation level 4') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 2004 | dix_body.append(' const char * const * extNames = &m_extensions[0];') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2005 | dix_body.append(' XGL_DEVICE_CREATE_INFO info = {};') |
| 2006 | dix_body.append(' info.queueRecordCount = 1;') |
| 2007 | dix_body.append(' info.pRequestedQueues = &dqci;') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 2008 | dix_body.append(' info.extensionCount = static_cast <uint32_t> (m_extensions.size());') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2009 | dix_body.append(' info.ppEnabledExtensionNames = extNames;') |
| 2010 | dix_body.append(' info.flags = XGL_DEVICE_CREATE_VALIDATION;') |
| 2011 | dix_body.append(' info.maxValidationLevel = XGL_VALIDATION_LEVEL_4;') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 2012 | dix_body.append(' bool32_t xglTrue = XGL_TRUE;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2013 | dix_body.append(' res = xglDbgSetGlobalOption( XGL_DBG_OPTION_BREAK_ON_ERROR, sizeof( xglTrue ), &xglTrue );') |
| 2014 | dix_body.append(' if (res != XGL_SUCCESS)') |
| 2015 | dix_body.append(' glv_LogWarn("Could not set debug option break on error\\n");') |
| 2016 | dix_body.append(' res = xglCreateDevice( m_gpus[0], &info, &m_dev[gpu_idx]);') |
| 2017 | dix_body.append(' return res;') |
| 2018 | dix_body.append('#else') |
| 2019 | dix_body.append(' return XGL_ERROR_INITIALIZATION_FAILED;') |
| 2020 | dix_body.append('#endif') |
| 2021 | dix_body.append('}') |
| 2022 | return "\n".join(dix_body) |
| 2023 | |
| 2024 | def _generate_replay_display_init(self): |
| 2025 | di_body = [] |
| 2026 | di_body.append('int xglDisplay::init(const unsigned int gpu_idx)') |
| 2027 | di_body.append('{') |
| 2028 | di_body.append(' //m_gpuIdx = gpu_idx;') |
| 2029 | di_body.append('#if 0') |
| 2030 | di_body.append(' XGL_RESULT result = init_xgl(gpu_idx);') |
| 2031 | di_body.append(' if (result != XGL_SUCCESS) {') |
| 2032 | di_body.append(' glv_LogError("could not init xgl library");') |
| 2033 | di_body.append(' return -1;') |
| 2034 | di_body.append(' } else {') |
| 2035 | di_body.append(' m_initedXGL = true;') |
| 2036 | di_body.append(' }') |
| 2037 | di_body.append('#endif') |
Piers Daniell | 188f820 | 2015-02-24 13:58:47 -0700 | [diff] [blame] | 2038 | di_body.append('#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2039 | di_body.append(' const xcb_setup_t *setup;') |
| 2040 | di_body.append(' xcb_screen_iterator_t iter;') |
| 2041 | di_body.append(' int scr;') |
| 2042 | di_body.append(' xcb_connection_t *pConnection;') |
| 2043 | di_body.append(' pConnection = xcb_connect(NULL, &scr);') |
| 2044 | di_body.append(' setup = xcb_get_setup(pConnection);') |
| 2045 | di_body.append(' iter = xcb_setup_roots_iterator(setup);') |
| 2046 | di_body.append(' while (scr-- > 0)') |
| 2047 | di_body.append(' xcb_screen_next(&iter);') |
| 2048 | di_body.append(' m_pXcbScreen = iter.data;') |
| 2049 | di_body.append(' m_WsiConnection.pConnection = pConnection;') |
| 2050 | di_body.append(' m_WsiConnection.root = m_pXcbScreen->root;') |
| 2051 | di_body.append('#endif') |
| 2052 | di_body.append(' return 0;') |
| 2053 | di_body.append('}') |
| 2054 | return "\n".join(di_body) |
| 2055 | |
| 2056 | def _generate_replay_display_structors(self): |
| 2057 | ds_body = [] |
| 2058 | ds_body.append('xglDisplay::xglDisplay()') |
| 2059 | ds_body.append(' : m_initedXGL(false),') |
| 2060 | ds_body.append(' m_windowWidth(0),') |
| 2061 | ds_body.append(' m_windowHeight(0)') |
| 2062 | ds_body.append('{') |
Piers Daniell | 188f820 | 2015-02-24 13:58:47 -0700 | [diff] [blame] | 2063 | ds_body.append('#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2064 | ds_body.append(' m_WsiConnection.pConnection = NULL;') |
| 2065 | ds_body.append(' m_WsiConnection.root = 0;') |
| 2066 | ds_body.append(' m_WsiConnection.provider = 0;') |
| 2067 | ds_body.append(' m_pXcbScreen = NULL;') |
| 2068 | ds_body.append(' m_XcbWindow = 0;') |
Piers Daniell | 188f820 | 2015-02-24 13:58:47 -0700 | [diff] [blame] | 2069 | ds_body.append('#elif defined(WIN32)') |
| 2070 | ds_body.append(' m_windowHandle = NULL;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2071 | ds_body.append('#endif') |
| 2072 | ds_body.append('}') |
| 2073 | ds_body.append('xglDisplay::~xglDisplay()') |
| 2074 | ds_body.append('{') |
Piers Daniell | 188f820 | 2015-02-24 13:58:47 -0700 | [diff] [blame] | 2075 | ds_body.append('#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2076 | ds_body.append(' if (m_XcbWindow != 0)') |
| 2077 | ds_body.append(' {') |
| 2078 | ds_body.append(' xcb_destroy_window(m_WsiConnection.pConnection, m_XcbWindow);') |
| 2079 | ds_body.append(' }') |
| 2080 | ds_body.append(' if (m_WsiConnection.pConnection != NULL)') |
| 2081 | ds_body.append(' {') |
| 2082 | ds_body.append(' xcb_disconnect(m_WsiConnection.pConnection);') |
| 2083 | ds_body.append(' }') |
| 2084 | ds_body.append('#endif') |
| 2085 | ds_body.append('}') |
| 2086 | return "\n".join(ds_body) |
| 2087 | |
| 2088 | def _generate_replay_display_window(self): |
| 2089 | dw_body = [] |
| 2090 | dw_body.append('#if defined(WIN32)') |
| 2091 | dw_body.append('LRESULT WINAPI WindowProcXgl( HWND window, unsigned int msg, WPARAM wp, LPARAM lp)') |
| 2092 | dw_body.append('{') |
| 2093 | dw_body.append(' switch(msg)') |
| 2094 | dw_body.append(' {') |
| 2095 | dw_body.append(' case WM_CLOSE:') |
| 2096 | dw_body.append(' DestroyWindow( window);') |
| 2097 | dw_body.append(' // fall-thru') |
| 2098 | dw_body.append(' case WM_DESTROY:') |
| 2099 | dw_body.append(' PostQuitMessage(0) ;') |
| 2100 | dw_body.append(' return 0L ;') |
| 2101 | dw_body.append(' default:') |
| 2102 | dw_body.append(' return DefWindowProc( window, msg, wp, lp ) ;') |
| 2103 | dw_body.append(' }') |
| 2104 | dw_body.append('}') |
| 2105 | dw_body.append('#endif') |
| 2106 | dw_body.append('int xglDisplay::set_window(glv_window_handle hWindow, unsigned int width, unsigned int height)') |
| 2107 | dw_body.append('{') |
Piers Daniell | 188f820 | 2015-02-24 13:58:47 -0700 | [diff] [blame] | 2108 | dw_body.append('#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2109 | dw_body.append(' m_XcbWindow = hWindow;') |
Piers Daniell | 188f820 | 2015-02-24 13:58:47 -0700 | [diff] [blame] | 2110 | dw_body.append('#elif defined(WIN32)') |
| 2111 | dw_body.append(' m_windowHandle = hWindow;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2112 | dw_body.append('#endif') |
| 2113 | dw_body.append(' m_windowWidth = width;') |
| 2114 | dw_body.append(' m_windowHeight = height;') |
| 2115 | dw_body.append(' return 0;') |
| 2116 | dw_body.append('}\n') |
| 2117 | dw_body.append('int xglDisplay::create_window(const unsigned int width, const unsigned int height)') |
| 2118 | dw_body.append('{') |
Piers Daniell | 188f820 | 2015-02-24 13:58:47 -0700 | [diff] [blame] | 2119 | dw_body.append('#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA)\n') |
| 2120 | dw_body.append(' uint32_t value_mask, value_list[32];') |
| 2121 | dw_body.append(' m_XcbWindow = xcb_generate_id(m_WsiConnection.pConnection);\n') |
| 2122 | dw_body.append(' value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;') |
| 2123 | dw_body.append(' value_list[0] = m_pXcbScreen->black_pixel;') |
| 2124 | dw_body.append(' value_list[1] = XCB_EVENT_MASK_KEY_RELEASE |') |
| 2125 | dw_body.append(' XCB_EVENT_MASK_EXPOSURE;\n') |
| 2126 | dw_body.append(' xcb_create_window(m_WsiConnection.pConnection,') |
| 2127 | dw_body.append(' XCB_COPY_FROM_PARENT,') |
| 2128 | dw_body.append(' m_XcbWindow, m_WsiConnection.root,') |
| 2129 | dw_body.append(' 0, 0, width, height, 0,') |
| 2130 | dw_body.append(' XCB_WINDOW_CLASS_INPUT_OUTPUT,') |
| 2131 | dw_body.append(' m_pXcbScreen->root_visual,') |
| 2132 | dw_body.append(' value_mask, value_list);\n') |
| 2133 | dw_body.append(' xcb_map_window(m_WsiConnection.pConnection, m_XcbWindow);') |
| 2134 | dw_body.append(' xcb_flush(m_WsiConnection.pConnection);') |
| 2135 | dw_body.append(' return 0;') |
| 2136 | dw_body.append('#elif defined(WIN32)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2137 | dw_body.append(' // Register Window class') |
| 2138 | dw_body.append(' WNDCLASSEX wcex = {};') |
| 2139 | dw_body.append(' wcex.cbSize = sizeof( WNDCLASSEX);') |
| 2140 | dw_body.append(' wcex.style = CS_HREDRAW | CS_VREDRAW;') |
| 2141 | dw_body.append(' wcex.lpfnWndProc = WindowProcXgl;') |
| 2142 | dw_body.append(' wcex.cbClsExtra = 0;') |
| 2143 | dw_body.append(' wcex.cbWndExtra = 0;') |
| 2144 | dw_body.append(' wcex.hInstance = GetModuleHandle(0);') |
| 2145 | dw_body.append(' wcex.hIcon = LoadIcon(wcex.hInstance, MAKEINTRESOURCE( IDI_ICON));') |
| 2146 | dw_body.append(' wcex.hCursor = LoadCursor( NULL, IDC_ARROW);') |
| 2147 | dw_body.append(' wcex.hbrBackground = ( HBRUSH )( COLOR_WINDOW + 1);') |
| 2148 | dw_body.append(' wcex.lpszMenuName = NULL;') |
| 2149 | dw_body.append(' wcex.lpszClassName = APP_NAME;') |
| 2150 | dw_body.append(' wcex.hIconSm = LoadIcon( wcex.hInstance, MAKEINTRESOURCE( IDI_ICON));') |
| 2151 | dw_body.append(' if( !RegisterClassEx( &wcex))') |
| 2152 | dw_body.append(' {') |
| 2153 | dw_body.append(' glv_LogError("Failed to register windows class\\n");') |
| 2154 | dw_body.append(' return -1;') |
| 2155 | dw_body.append(' }\n') |
| 2156 | dw_body.append(' // create the window') |
| 2157 | dw_body.append(' m_windowHandle = CreateWindow(APP_NAME, APP_NAME, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU, 0, 0,') |
| 2158 | dw_body.append(' width, height, NULL, NULL, wcex.hInstance, NULL);\n') |
| 2159 | dw_body.append(' if (m_windowHandle)') |
| 2160 | dw_body.append(' {') |
| 2161 | dw_body.append(' ShowWindow( m_windowHandle, SW_SHOWDEFAULT);') |
| 2162 | dw_body.append(' m_windowWidth = width;') |
| 2163 | dw_body.append(' m_windowHeight = height;') |
| 2164 | dw_body.append(' } else {') |
| 2165 | dw_body.append(' glv_LogError("Failed to create window\\n");') |
| 2166 | dw_body.append(' return -1;') |
| 2167 | dw_body.append(' }') |
| 2168 | dw_body.append(' return 0;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2169 | dw_body.append('#endif') |
| 2170 | dw_body.append('}\n') |
| 2171 | dw_body.append('void xglDisplay::resize_window(const unsigned int width, const unsigned int height)') |
| 2172 | dw_body.append('{') |
Piers Daniell | 188f820 | 2015-02-24 13:58:47 -0700 | [diff] [blame] | 2173 | dw_body.append('#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2174 | dw_body.append(' if (width != m_windowWidth || height != m_windowHeight)') |
| 2175 | dw_body.append(' {') |
| 2176 | dw_body.append(' uint32_t values[2];') |
| 2177 | dw_body.append(' values[0] = width;') |
| 2178 | dw_body.append(' values[1] = height;') |
| 2179 | dw_body.append(' xcb_configure_window(m_WsiConnection.pConnection, m_XcbWindow, XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, values);') |
| 2180 | dw_body.append(' m_windowWidth = width;') |
| 2181 | dw_body.append(' m_windowHeight = height;') |
| 2182 | dw_body.append(' }') |
Piers Daniell | 188f820 | 2015-02-24 13:58:47 -0700 | [diff] [blame] | 2183 | dw_body.append('#elif defined(WIN32)') |
| 2184 | dw_body.append(' if (width != m_windowWidth || height != m_windowHeight)') |
| 2185 | dw_body.append(' {') |
| 2186 | dw_body.append(' SetWindowPos(get_window_handle(), HWND_TOP, 0, 0, width, height, SWP_NOMOVE);') |
| 2187 | dw_body.append(' m_windowWidth = width;') |
| 2188 | dw_body.append(' m_windowHeight = height;') |
| 2189 | dw_body.append(' }') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2190 | dw_body.append('#endif') |
| 2191 | dw_body.append('}\n') |
| 2192 | dw_body.append('void xglDisplay::process_event()') |
| 2193 | dw_body.append('{') |
| 2194 | dw_body.append('}') |
| 2195 | return "\n".join(dw_body) |
| 2196 | |
| 2197 | def _generate_replay_structors(self): |
| 2198 | rs_body = [] |
Ian Elliott | eca1638 | 2015-02-18 15:35:00 -0700 | [diff] [blame] | 2199 | rs_body.append('xglReplay::xglReplay(glvreplay_settings *pReplaySettings)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2200 | rs_body.append('{') |
Ian Elliott | eca1638 | 2015-02-18 15:35:00 -0700 | [diff] [blame] | 2201 | rs_body.append(' g_pReplaySettings = pReplaySettings;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2202 | rs_body.append(' m_display = new xglDisplay();') |
Peter Lohrmann | bd3950f | 2015-02-26 10:51:36 -0800 | [diff] [blame] | 2203 | rs_body.append(' m_pDSDump = NULL;') |
Peter Lohrmann | d2e8485 | 2015-02-27 15:35:15 -0800 | [diff] [blame] | 2204 | rs_body.append(' m_pCBDump = NULL;') |
Jon Ashburn | c7fd978 | 2015-02-05 13:42:38 -0700 | [diff] [blame] | 2205 | rs_body.append(' if (g_pReplaySettings && g_pReplaySettings->screenshotList) {') |
| 2206 | rs_body.append(' process_screenshot_list(g_pReplaySettings->screenshotList);') |
Tony Barbour | a7390a0 | 2015-02-05 09:46:17 -0700 | [diff] [blame] | 2207 | rs_body.append(' }') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2208 | rs_body.append('}\n') |
| 2209 | rs_body.append('xglReplay::~xglReplay()') |
| 2210 | rs_body.append('{') |
| 2211 | rs_body.append(' delete m_display;') |
| 2212 | rs_body.append(' glv_platform_close_library(m_xglFuncs.m_libHandle);') |
| 2213 | rs_body.append('}') |
| 2214 | return "\n".join(rs_body) |
| 2215 | |
| 2216 | def _generate_replay_init(self): |
| 2217 | ri_body = [] |
| 2218 | ri_body.append('int xglReplay::init(glv_replay::Display & disp)') |
| 2219 | ri_body.append('{') |
| 2220 | ri_body.append(' int err;') |
David Pinedo | 5350930 | 2015-02-10 15:02:08 -0700 | [diff] [blame] | 2221 | ri_body.append('#if defined PLATFORM_LINUX') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2222 | ri_body.append(' void * handle = dlopen("libXGL.so", RTLD_LAZY);') |
David Pinedo | 5350930 | 2015-02-10 15:02:08 -0700 | [diff] [blame] | 2223 | ri_body.append('#else') |
| 2224 | ri_body.append(' HMODULE handle = LoadLibrary("xgl.dll" );') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2225 | ri_body.append('#endif\n') |
| 2226 | ri_body.append(' if (handle == NULL) {') |
| 2227 | ri_body.append(' glv_LogError("Failed to open xgl library.\\n");') |
| 2228 | ri_body.append(' return -1;') |
| 2229 | ri_body.append(' }') |
| 2230 | ri_body.append(' m_xglFuncs.init_funcs(handle);') |
| 2231 | ri_body.append(' disp.set_implementation(m_display);') |
| 2232 | ri_body.append(' if ((err = m_display->init(disp.get_gpu())) != 0) {') |
| 2233 | ri_body.append(' glv_LogError("Failed to init XGL display.\\n");') |
| 2234 | ri_body.append(' return err;') |
| 2235 | ri_body.append(' }') |
| 2236 | ri_body.append(' if (disp.get_window_handle() == 0)') |
| 2237 | ri_body.append(' {') |
| 2238 | ri_body.append(' if ((err = m_display->create_window(disp.get_width(), disp.get_height())) != 0) {') |
| 2239 | ri_body.append(' glv_LogError("Failed to create Window\\n");') |
| 2240 | ri_body.append(' return err;') |
| 2241 | ri_body.append(' }') |
| 2242 | ri_body.append(' }') |
| 2243 | ri_body.append(' else') |
| 2244 | ri_body.append(' {') |
| 2245 | ri_body.append(' if ((err = m_display->set_window(disp.get_window_handle(), disp.get_width(), disp.get_height())) != 0)') |
| 2246 | ri_body.append(' {') |
| 2247 | ri_body.append(' glv_LogError("Failed to set Window\\n");') |
| 2248 | ri_body.append(' return err;') |
| 2249 | ri_body.append(' }') |
| 2250 | ri_body.append(' }') |
| 2251 | ri_body.append(' return 0;') |
| 2252 | ri_body.append('}') |
| 2253 | return "\n".join(ri_body) |
| 2254 | |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2255 | def _generate_replay_errors(self): |
| 2256 | re_body = [] |
| 2257 | re_body.append('glv_replay::GLV_REPLAY_RESULT xglReplay::handle_replay_errors(const char* entrypointName, const XGL_RESULT resCall, const XGL_RESULT resTrace, const glv_replay::GLV_REPLAY_RESULT resIn)') |
| 2258 | re_body.append('{') |
| 2259 | re_body.append(' glv_replay::GLV_REPLAY_RESULT res = resIn;') |
| 2260 | re_body.append(' if (resCall != resTrace) {') |
| 2261 | re_body.append(' glv_LogWarn("Mismatched return from API call (%s) traced result %s, replay result %s\\n", entrypointName,') |
Tobin Ehlis | bf967aa | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 2262 | re_body.append(' string_XGL_RESULT((XGL_RESULT)resTrace), string_XGL_RESULT((XGL_RESULT)resCall));') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2263 | re_body.append(' res = glv_replay::GLV_REPLAY_BAD_RETURN;') |
| 2264 | re_body.append(' }') |
| 2265 | re_body.append('#if 0') |
| 2266 | re_body.append(' if (resCall != XGL_SUCCESS) {') |
| 2267 | re_body.append(' glv_LogWarn("API call (%s) returned failed result %s\\n", entrypointName, string_XGL_RESULT(resCall));') |
| 2268 | re_body.append(' }') |
| 2269 | re_body.append('#endif') |
| 2270 | re_body.append(' return res;') |
| 2271 | re_body.append('}') |
| 2272 | return "\n".join(re_body) |
| 2273 | |
Jon Ashburn | ce66ab8 | 2014-12-18 17:03:34 -0700 | [diff] [blame] | 2274 | def _generate_replay_validation_funcs(self): |
| 2275 | rvf_body = [] |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 2276 | rvf_body.append('void xglReplay::push_validation_msg(XGL_VALIDATION_LEVEL validationLevel, XGL_BASE_OBJECT srcObject, size_t location, int32_t msgCode, const char * pMsg)') |
Jon Ashburn | ce66ab8 | 2014-12-18 17:03:34 -0700 | [diff] [blame] | 2277 | rvf_body.append('{') |
| 2278 | rvf_body.append(' struct validationMsg msgObj;') |
| 2279 | rvf_body.append(' msgObj.validationLevel = validationLevel;') |
| 2280 | rvf_body.append(' msgObj.srcObject = srcObject;') |
| 2281 | rvf_body.append(' msgObj.location = location;') |
| 2282 | rvf_body.append(' msgObj.msgCode = msgCode;') |
| 2283 | rvf_body.append(' strncpy(msgObj.msg, pMsg, 256);') |
| 2284 | rvf_body.append(" msgObj.msg[255] = '\\0';") |
| 2285 | rvf_body.append(' m_validationMsgs.push_back(msgObj);') |
| 2286 | rvf_body.append('}\n') |
| 2287 | rvf_body.append('glv_replay::GLV_REPLAY_RESULT xglReplay::pop_validation_msgs()') |
| 2288 | rvf_body.append('{') |
| 2289 | rvf_body.append(' if (m_validationMsgs.size() == 0)') |
| 2290 | rvf_body.append(' return glv_replay::GLV_REPLAY_SUCCESS;') |
| 2291 | rvf_body.append(' m_validationMsgs.clear();') |
| 2292 | rvf_body.append(' return glv_replay::GLV_REPLAY_VALIDATION_ERROR;') |
| 2293 | rvf_body.append('}') |
Jon Ashburn | 8ef49b1 | 2015-02-17 13:28:11 -0700 | [diff] [blame] | 2294 | rvf_body.append('int xglReplay::dump_validation_data()') |
| 2295 | rvf_body.append('{') |
Jeremy Hayes | 2c98e53 | 2015-02-26 15:59:19 -0700 | [diff] [blame] | 2296 | rvf_body.append(' if (!m_pDSDump || !m_pCBDump)') |
Jon Ashburn | 8ef49b1 | 2015-02-17 13:28:11 -0700 | [diff] [blame] | 2297 | rvf_body.append(' {') |
Jeremy Hayes | 2c98e53 | 2015-02-26 15:59:19 -0700 | [diff] [blame] | 2298 | rvf_body.append(' return -1;') |
Jon Ashburn | 8ef49b1 | 2015-02-17 13:28:11 -0700 | [diff] [blame] | 2299 | rvf_body.append(' }') |
Jeremy Hayes | 2c98e53 | 2015-02-26 15:59:19 -0700 | [diff] [blame] | 2300 | rvf_body.append(' m_pDSDump((char *) "pipeline_dump.dot");') |
| 2301 | rvf_body.append(' m_pCBDump((char *) "cb_dump.dot");') |
| 2302 | rvf_body.append(' return 0;') |
Jon Ashburn | 8ef49b1 | 2015-02-17 13:28:11 -0700 | [diff] [blame] | 2303 | rvf_body.append('}') |
Jon Ashburn | ce66ab8 | 2014-12-18 17:03:34 -0700 | [diff] [blame] | 2304 | return "\n".join(rvf_body) |
| 2305 | |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2306 | def _generate_replay_init_funcs(self): |
| 2307 | rif_body = [] |
| 2308 | rif_body.append('void xglFuncs::init_funcs(void * handle)\n{\n m_libHandle = handle;') |
| 2309 | for proto in self.protos: |
| 2310 | rif_body.append(' real_xgl%s = (type_xgl%s)(glv_platform_get_library_entrypoint(handle, "xgl%s"));' % (proto.name, proto.name, proto.name)) |
| 2311 | rif_body.append('}') |
| 2312 | return "\n".join(rif_body) |
| 2313 | |
| 2314 | def _get_packet_param(self, t, n): |
| 2315 | # list of types that require remapping |
Tobin Ehlis | bf967aa | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 2316 | remap_list = xgl.object_type_list |
Tobin Ehlis | bf967aa | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 2317 | param_exclude_list = ['p1', 'p2', 'pGpus', 'pDescriptorSets'] |
| 2318 | if t.strip('*').replace('const ', '') in remap_list and n not in param_exclude_list: |
| 2319 | if '*' in t: |
| 2320 | if 'const ' not in t: |
| 2321 | return 'remap(*pPacket->%s)' % (n) |
| 2322 | else: # TODO : Don't remap array ptrs? |
| 2323 | return 'pPacket->%s' % (n) |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2324 | return 'remap(pPacket->%s)' % (n) |
| 2325 | return 'pPacket->%s' % (n) |
| 2326 | |
Tobin Ehlis | 1077703 | 2015-01-16 15:13:34 -0700 | [diff] [blame] | 2327 | def _gen_replay_enum_gpus(self): |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2328 | ieg_body = [] |
| 2329 | ieg_body.append(' if (!m_display->m_initedXGL)') |
| 2330 | ieg_body.append(' {') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 2331 | ieg_body.append(' uint32_t gpuCount;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2332 | ieg_body.append(' XGL_PHYSICAL_GPU gpus[XGL_MAX_PHYSICAL_GPUS];') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 2333 | ieg_body.append(' uint32_t maxGpus = (pPacket->maxGpus < XGL_MAX_PHYSICAL_GPUS) ? pPacket->maxGpus : XGL_MAX_PHYSICAL_GPUS;') |
Tobin Ehlis | 1077703 | 2015-01-16 15:13:34 -0700 | [diff] [blame] | 2334 | ieg_body.append(' replayResult = m_xglFuncs.real_xglEnumerateGpus(remap(pPacket->instance), maxGpus, &gpuCount, &gpus[0]);') |
| 2335 | ieg_body.append(' CHECK_RETURN_VALUE(xglEnumerateGpus);') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2336 | ieg_body.append(' //TODO handle different number of gpus in trace versus replay') |
| 2337 | ieg_body.append(' if (gpuCount != *(pPacket->pGpuCount))') |
| 2338 | ieg_body.append(' {') |
| 2339 | ieg_body.append(' glv_LogWarn("number of gpus mismatched in replay %u versus trace %u\\n", gpuCount, *(pPacket->pGpuCount));') |
| 2340 | ieg_body.append(' }') |
| 2341 | ieg_body.append(' else if (gpuCount == 0)') |
| 2342 | ieg_body.append(' {') |
Tobin Ehlis | 1077703 | 2015-01-16 15:13:34 -0700 | [diff] [blame] | 2343 | ieg_body.append(' glv_LogError("xglEnumerateGpus number of gpus is zero\\n");') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2344 | ieg_body.append(' }') |
| 2345 | ieg_body.append(' else') |
| 2346 | ieg_body.append(' {') |
| 2347 | ieg_body.append(' glv_LogInfo("Enumerated %d GPUs in the system\\n", gpuCount);') |
| 2348 | ieg_body.append(' }') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2349 | ieg_body.append(' // TODO handle enumeration results in a different order from trace to replay') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 2350 | ieg_body.append(' for (uint32_t i = 0; i < gpuCount; i++)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2351 | ieg_body.append(' {') |
| 2352 | ieg_body.append(' if (pPacket->pGpus)') |
| 2353 | ieg_body.append(' add_to_map(&(pPacket->pGpus[i]), &(gpus[i]));') |
| 2354 | ieg_body.append(' }') |
| 2355 | ieg_body.append(' }') |
| 2356 | return "\n".join(ieg_body) |
| 2357 | |
| 2358 | def _gen_replay_get_gpu_info(self): |
| 2359 | ggi_body = [] |
| 2360 | ggi_body.append(' if (!m_display->m_initedXGL)') |
| 2361 | ggi_body.append(' {') |
| 2362 | ggi_body.append(' switch (pPacket->infoType) {') |
| 2363 | ggi_body.append(' case XGL_INFO_TYPE_PHYSICAL_GPU_PROPERTIES:') |
| 2364 | ggi_body.append(' {') |
| 2365 | ggi_body.append(' XGL_PHYSICAL_GPU_PROPERTIES gpuProps;') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 2366 | ggi_body.append(' size_t dataSize = sizeof(XGL_PHYSICAL_GPU_PROPERTIES);') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2367 | ggi_body.append(' replayResult = m_xglFuncs.real_xglGetGpuInfo(remap(pPacket->gpu), pPacket->infoType, &dataSize,') |
| 2368 | ggi_body.append(' (pPacket->pData == NULL) ? NULL : &gpuProps);') |
| 2369 | ggi_body.append(' if (pPacket->pData != NULL)') |
| 2370 | ggi_body.append(' {') |
| 2371 | ggi_body.append(' glv_LogInfo("Replay Gpu Properties\\n");') |
| 2372 | ggi_body.append(' glv_LogInfo("Vendor ID %x, Device ID %x, name %s\\n",gpuProps.vendorId, gpuProps.deviceId, gpuProps.gpuName);') |
| 2373 | ggi_body.append(' glv_LogInfo("API version %u, Driver version %u, gpu Type %u\\n",gpuProps.apiVersion, gpuProps.driverVersion, gpuProps.gpuType);') |
| 2374 | ggi_body.append(' }') |
| 2375 | ggi_body.append(' break;') |
| 2376 | ggi_body.append(' }') |
| 2377 | ggi_body.append(' case XGL_INFO_TYPE_PHYSICAL_GPU_PERFORMANCE:') |
| 2378 | ggi_body.append(' {') |
| 2379 | ggi_body.append(' XGL_PHYSICAL_GPU_PERFORMANCE gpuPerfs;') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 2380 | ggi_body.append(' size_t dataSize = sizeof(XGL_PHYSICAL_GPU_PERFORMANCE);') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2381 | ggi_body.append(' replayResult = m_xglFuncs.real_xglGetGpuInfo(remap(pPacket->gpu), pPacket->infoType, &dataSize,') |
| 2382 | ggi_body.append(' (pPacket->pData == NULL) ? NULL : &gpuPerfs);') |
| 2383 | ggi_body.append(' if (pPacket->pData != NULL)') |
| 2384 | ggi_body.append(' {') |
| 2385 | ggi_body.append(' glv_LogInfo("Replay Gpu Performance\\n");') |
| 2386 | ggi_body.append(' glv_LogInfo("Max GPU clock %f, max shader ALUs/clock %f, max texel fetches/clock %f\\n",gpuPerfs.maxGpuClock, gpuPerfs.aluPerClock, gpuPerfs.texPerClock);') |
| 2387 | ggi_body.append(' glv_LogInfo("Max primitives/clock %f, Max pixels/clock %f\\n",gpuPerfs.primsPerClock, gpuPerfs.pixelsPerClock);') |
| 2388 | ggi_body.append(' }') |
| 2389 | ggi_body.append(' break;') |
| 2390 | ggi_body.append(' }') |
| 2391 | ggi_body.append(' case XGL_INFO_TYPE_PHYSICAL_GPU_QUEUE_PROPERTIES:') |
| 2392 | ggi_body.append(' {') |
| 2393 | ggi_body.append(' XGL_PHYSICAL_GPU_QUEUE_PROPERTIES *pGpuQueue, *pQ;') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 2394 | ggi_body.append(' size_t dataSize = sizeof(XGL_PHYSICAL_GPU_QUEUE_PROPERTIES);') |
| 2395 | ggi_body.append(' size_t numQueues = 1;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2396 | ggi_body.append(' assert(pPacket->pDataSize);') |
| 2397 | ggi_body.append(' if ((*(pPacket->pDataSize) % dataSize) != 0)') |
| 2398 | ggi_body.append(' glv_LogWarn("xglGetGpuInfo() for GPU_QUEUE_PROPERTIES not an integral data size assuming 1\\n");') |
| 2399 | ggi_body.append(' else') |
| 2400 | ggi_body.append(' numQueues = *(pPacket->pDataSize) / dataSize;') |
| 2401 | ggi_body.append(' dataSize = numQueues * dataSize;') |
| 2402 | ggi_body.append(' pQ = static_cast < XGL_PHYSICAL_GPU_QUEUE_PROPERTIES *> (glv_malloc(dataSize));') |
| 2403 | ggi_body.append(' pGpuQueue = pQ;') |
| 2404 | ggi_body.append(' replayResult = m_xglFuncs.real_xglGetGpuInfo(remap(pPacket->gpu), pPacket->infoType, &dataSize,') |
| 2405 | ggi_body.append(' (pPacket->pData == NULL) ? NULL : pGpuQueue);') |
| 2406 | ggi_body.append(' if (pPacket->pData != NULL)') |
| 2407 | ggi_body.append(' {') |
| 2408 | ggi_body.append(' for (unsigned int i = 0; i < numQueues; i++)') |
| 2409 | ggi_body.append(' {') |
| 2410 | ggi_body.append(' glv_LogInfo("Replay Gpu Queue Property for index %d, flags %u\\n", i, pGpuQueue->queueFlags);') |
| 2411 | ggi_body.append(' glv_LogInfo("Max available count %u, max atomic counters %u, supports timestamps %u\\n",pGpuQueue->queueCount, pGpuQueue->maxAtomicCounters, pGpuQueue->supportsTimestamps);') |
| 2412 | ggi_body.append(' pGpuQueue++;') |
| 2413 | ggi_body.append(' }') |
| 2414 | ggi_body.append(' }') |
| 2415 | ggi_body.append(' glv_free(pQ);') |
| 2416 | ggi_body.append(' break;') |
| 2417 | ggi_body.append(' }') |
| 2418 | ggi_body.append(' default:') |
| 2419 | ggi_body.append(' {') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 2420 | ggi_body.append(' size_t size = 0;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2421 | ggi_body.append(' void* pData = NULL;') |
| 2422 | ggi_body.append(' if (pPacket->pData != NULL && pPacket->pDataSize != NULL)') |
| 2423 | ggi_body.append(' {') |
| 2424 | ggi_body.append(' size = *pPacket->pDataSize;') |
| 2425 | ggi_body.append(' pData = glv_malloc(*pPacket->pDataSize);') |
| 2426 | ggi_body.append(' }') |
| 2427 | ggi_body.append(' replayResult = m_xglFuncs.real_xglGetGpuInfo(remap(pPacket->gpu), pPacket->infoType, &size, pData);') |
| 2428 | ggi_body.append(' if (replayResult == XGL_SUCCESS)') |
| 2429 | ggi_body.append(' {') |
Jon Ashburn | e3a667c | 2015-02-11 09:32:29 -0700 | [diff] [blame] | 2430 | ggi_body.append(' if (size != *pPacket->pDataSize && pData != NULL)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2431 | ggi_body.append(' {') |
| 2432 | ggi_body.append(' glv_LogWarn("xglGetGpuInfo returned a differing data size: replay (%d bytes) vs trace (%d bytes)\\n", size, *pPacket->pDataSize);') |
| 2433 | ggi_body.append(' }') |
| 2434 | ggi_body.append(' else if (pData != NULL && memcmp(pData, pPacket->pData, size) != 0)') |
| 2435 | ggi_body.append(' {') |
| 2436 | ggi_body.append(' glv_LogWarn("xglGetGpuInfo returned differing data contents than the trace file contained.\\n");') |
| 2437 | ggi_body.append(' }') |
| 2438 | ggi_body.append(' }') |
| 2439 | ggi_body.append(' glv_free(pData);') |
| 2440 | ggi_body.append(' break;') |
| 2441 | ggi_body.append(' }') |
| 2442 | ggi_body.append(' };') |
| 2443 | ggi_body.append(' CHECK_RETURN_VALUE(xglGetGpuInfo);') |
| 2444 | ggi_body.append(' }') |
| 2445 | return "\n".join(ggi_body) |
| 2446 | |
| 2447 | def _gen_replay_create_device(self): |
| 2448 | cd_body = [] |
| 2449 | cd_body.append(' if (!m_display->m_initedXGL)') |
| 2450 | cd_body.append(' {') |
| 2451 | cd_body.append(' XGL_DEVICE device;') |
Peter Lohrmann | 25643b7 | 2015-01-08 19:47:03 -0800 | [diff] [blame] | 2452 | cd_body.append(' if (g_xglReplaySettings.debugLevel > 0)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2453 | cd_body.append(' {') |
Jon Ashburn | 449bfbd | 2014-12-19 12:31:19 -0700 | [diff] [blame] | 2454 | cd_body.append(' XGL_DEVICE_CREATE_INFO cInfo, *ci, *pCreateInfoSaved;') |
Peter Lohrmann | 7699374 | 2015-01-09 12:34:50 -0800 | [diff] [blame] | 2455 | cd_body.append(' unsigned int numLayers = 0;') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 2456 | cd_body.append(' char ** layersStr = get_enableLayers_list(&numLayers);') |
Jon Ashburn | 68dc68e | 2015-01-13 17:24:49 -0700 | [diff] [blame] | 2457 | cd_body.append(' apply_layerSettings_overrides();') |
Jon Ashburn | ce66ab8 | 2014-12-18 17:03:34 -0700 | [diff] [blame] | 2458 | cd_body.append(' XGL_LAYER_CREATE_INFO layerInfo;') |
Jon Ashburn | 449bfbd | 2014-12-19 12:31:19 -0700 | [diff] [blame] | 2459 | cd_body.append(' pCreateInfoSaved = (XGL_DEVICE_CREATE_INFO *) pPacket->pCreateInfo;') |
Jon Ashburn | ce66ab8 | 2014-12-18 17:03:34 -0700 | [diff] [blame] | 2460 | cd_body.append(' ci = (XGL_DEVICE_CREATE_INFO *) pPacket->pCreateInfo;') |
Peter Lohrmann | 7699374 | 2015-01-09 12:34:50 -0800 | [diff] [blame] | 2461 | |
| 2462 | cd_body.append(' if (layersStr != NULL && numLayers > 0)') |
| 2463 | cd_body.append(' {') |
| 2464 | cd_body.append(' while (ci->pNext != NULL)') |
| 2465 | cd_body.append(' ci = (XGL_DEVICE_CREATE_INFO *) ci->pNext;') |
| 2466 | cd_body.append(' ci->pNext = &layerInfo;') |
| 2467 | cd_body.append(' layerInfo.sType = XGL_STRUCTURE_TYPE_LAYER_CREATE_INFO;') |
| 2468 | cd_body.append(' layerInfo.pNext = 0;') |
| 2469 | cd_body.append(' layerInfo.layerCount = numLayers;') |
| 2470 | cd_body.append(' layerInfo.ppActiveLayerNames = layersStr;') |
| 2471 | cd_body.append(' }') |
| 2472 | |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2473 | cd_body.append(' memcpy(&cInfo, pPacket->pCreateInfo, sizeof(XGL_DEVICE_CREATE_INFO));') |
| 2474 | cd_body.append(' cInfo.flags = pPacket->pCreateInfo->flags | XGL_DEVICE_CREATE_VALIDATION_BIT;') |
Tobin Ehlis | bf967aa | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 2475 | cd_body.append(' cInfo.maxValidationLevel = (XGL_VALIDATION_LEVEL)((g_xglReplaySettings.debugLevel <= 4) ? (unsigned int) XGL_VALIDATION_LEVEL_0 + g_xglReplaySettings.debugLevel : (unsigned int) XGL_VALIDATION_LEVEL_0);') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2476 | cd_body.append(' pPacket->pCreateInfo = &cInfo;') |
Jon Ashburn | ce66ab8 | 2014-12-18 17:03:34 -0700 | [diff] [blame] | 2477 | cd_body.append(' replayResult = m_xglFuncs.real_xglCreateDevice(remap(pPacket->gpu), pPacket->pCreateInfo, &device);') |
Jon Ashburn | 449bfbd | 2014-12-19 12:31:19 -0700 | [diff] [blame] | 2478 | cd_body.append(' // restore the packet for next replay') |
| 2479 | cd_body.append(' ci->pNext = NULL;') |
| 2480 | cd_body.append(' pPacket->pCreateInfo = pCreateInfoSaved;') |
Peter Lohrmann | 7699374 | 2015-01-09 12:34:50 -0800 | [diff] [blame] | 2481 | cd_body.append(' release_enableLayer_list(layersStr);') |
Jon Ashburn | ce66ab8 | 2014-12-18 17:03:34 -0700 | [diff] [blame] | 2482 | cd_body.append(' if (xglDbgRegisterMsgCallback(g_fpDbgMsgCallback, NULL) != XGL_SUCCESS)') |
| 2483 | cd_body.append(' glv_LogError("Failed to register xgl callback for replayer error handling\\n");') |
Ian Elliott | a34353f | 2015-03-03 09:50:57 -0700 | [diff] [blame] | 2484 | cd_body.append('#if !defined(_WIN32)') |
Jon Ashburn | 8ef49b1 | 2015-02-17 13:28:11 -0700 | [diff] [blame] | 2485 | cd_body.append(' m_pDSDump = (DRAW_STATE_DUMP_DOT_FILE) m_xglFuncs.real_xglGetProcAddr(remap(pPacket->gpu), "drawStateDumpDotFile");') |
Jeremy Hayes | 2c98e53 | 2015-02-26 15:59:19 -0700 | [diff] [blame] | 2486 | cd_body.append(' m_pCBDump = (DRAW_STATE_DUMP_COMMAND_BUFFER_DOT_FILE) m_xglFuncs.real_xglGetProcAddr(remap(pPacket->gpu), "drawStateDumpCommandBufferDotFile");') |
Ian Elliott | a34353f | 2015-03-03 09:50:57 -0700 | [diff] [blame] | 2487 | cd_body.append('#endif') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2488 | cd_body.append(' }') |
Jon Ashburn | ce66ab8 | 2014-12-18 17:03:34 -0700 | [diff] [blame] | 2489 | cd_body.append(' else ') |
| 2490 | cd_body.append(' replayResult = m_xglFuncs.real_xglCreateDevice(remap(pPacket->gpu), pPacket->pCreateInfo, &device);') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2491 | cd_body.append(' CHECK_RETURN_VALUE(xglCreateDevice);') |
| 2492 | cd_body.append(' if (replayResult == XGL_SUCCESS)') |
| 2493 | cd_body.append(' {') |
| 2494 | cd_body.append(' add_to_map(pPacket->pDevice, &device);') |
| 2495 | cd_body.append(' }') |
| 2496 | cd_body.append(' }') |
| 2497 | return "\n".join(cd_body) |
| 2498 | |
| 2499 | def _gen_replay_get_extension_support(self): |
| 2500 | ges_body = [] |
| 2501 | ges_body.append(' if (!m_display->m_initedXGL) {') |
| 2502 | ges_body.append(' replayResult = m_xglFuncs.real_xglGetExtensionSupport(remap(pPacket->gpu), pPacket->pExtName);') |
| 2503 | ges_body.append(' CHECK_RETURN_VALUE(xglGetExtensionSupport);') |
| 2504 | ges_body.append(' if (replayResult == XGL_SUCCESS) {') |
| 2505 | ges_body.append(' for (unsigned int ext = 0; ext < sizeof(g_extensions) / sizeof(g_extensions[0]); ext++)') |
| 2506 | ges_body.append(' {') |
Chia-I Wu | f1a5a74 | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 2507 | ges_body.append(' if (!strncmp(g_extensions[ext], pPacket->pExtName, strlen(g_extensions[ext]))) {') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2508 | ges_body.append(' bool extInList = false;') |
| 2509 | ges_body.append(' for (unsigned int j = 0; j < m_display->m_extensions.size(); ++j) {') |
Chia-I Wu | f1a5a74 | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 2510 | ges_body.append(' if (!strncmp(m_display->m_extensions[j], g_extensions[ext], strlen(g_extensions[ext])))') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2511 | ges_body.append(' extInList = true;') |
| 2512 | ges_body.append(' break;') |
| 2513 | ges_body.append(' }') |
| 2514 | ges_body.append(' if (!extInList)') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 2515 | ges_body.append(' m_display->m_extensions.push_back((char *) g_extensions[ext]);') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2516 | ges_body.append(' break;') |
| 2517 | ges_body.append(' }') |
| 2518 | ges_body.append(' }') |
| 2519 | ges_body.append(' }') |
| 2520 | ges_body.append(' }') |
| 2521 | return "\n".join(ges_body) |
| 2522 | |
| 2523 | def _gen_replay_queue_submit(self): |
| 2524 | qs_body = [] |
| 2525 | qs_body.append(' XGL_CMD_BUFFER *remappedBuffers = NULL;') |
| 2526 | qs_body.append(' if (pPacket->pCmdBuffers != NULL)') |
| 2527 | qs_body.append(' {') |
| 2528 | qs_body.append(' remappedBuffers = GLV_NEW_ARRAY( XGL_CMD_BUFFER, pPacket->cmdBufferCount);') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 2529 | qs_body.append(' for (uint32_t i = 0; i < pPacket->cmdBufferCount; i++)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2530 | qs_body.append(' {') |
| 2531 | qs_body.append(' *(remappedBuffers + i) = remap(*(pPacket->pCmdBuffers + i));') |
| 2532 | qs_body.append(' }') |
| 2533 | qs_body.append(' }') |
| 2534 | qs_body.append(' XGL_MEMORY_REF* memRefs = NULL;') |
| 2535 | qs_body.append(' if (pPacket->pMemRefs != NULL)') |
| 2536 | qs_body.append(' {') |
| 2537 | qs_body.append(' memRefs = GLV_NEW_ARRAY(XGL_MEMORY_REF, pPacket->memRefCount);') |
| 2538 | qs_body.append(' memcpy(memRefs, pPacket->pMemRefs, sizeof(XGL_MEMORY_REF) * pPacket->memRefCount);') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 2539 | qs_body.append(' for (uint32_t i = 0; i < pPacket->memRefCount; i++)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2540 | qs_body.append(' {') |
| 2541 | qs_body.append(' memRefs[i].mem = remap(pPacket->pMemRefs[i].mem);') |
| 2542 | qs_body.append(' }') |
| 2543 | qs_body.append(' }') |
| 2544 | qs_body.append(' replayResult = m_xglFuncs.real_xglQueueSubmit(remap(pPacket->queue), pPacket->cmdBufferCount, remappedBuffers, pPacket->memRefCount,') |
| 2545 | qs_body.append(' memRefs, remap(pPacket->fence));') |
| 2546 | qs_body.append(' GLV_DELETE(remappedBuffers);') |
| 2547 | qs_body.append(' GLV_DELETE(memRefs);') |
| 2548 | return "\n".join(qs_body) |
| 2549 | |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2550 | def _gen_replay_get_object_info(self): |
| 2551 | goi_body = [] |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 2552 | goi_body.append(' size_t size = 0;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2553 | goi_body.append(' void* pData = NULL;') |
| 2554 | goi_body.append(' if (pPacket->pData != NULL && pPacket->pDataSize != NULL)') |
| 2555 | goi_body.append(' {') |
| 2556 | goi_body.append(' size = *pPacket->pDataSize;') |
| 2557 | goi_body.append(' pData = glv_malloc(*pPacket->pDataSize);') |
| 2558 | goi_body.append(' memcpy(pData, pPacket->pData, *pPacket->pDataSize);') |
| 2559 | goi_body.append(' }') |
| 2560 | goi_body.append(' replayResult = m_xglFuncs.real_xglGetObjectInfo(remap(pPacket->object), pPacket->infoType, &size, pData);') |
| 2561 | goi_body.append(' if (replayResult == XGL_SUCCESS)') |
| 2562 | goi_body.append(' {') |
Jon Ashburn | e3a667c | 2015-02-11 09:32:29 -0700 | [diff] [blame] | 2563 | goi_body.append(' if (size != *pPacket->pDataSize && pData != NULL)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2564 | goi_body.append(' {') |
| 2565 | goi_body.append(' glv_LogWarn("xglGetObjectInfo returned a differing data size: replay (%d bytes) vs trace (%d bytes)\\n", size, *pPacket->pDataSize);') |
| 2566 | goi_body.append(' }') |
| 2567 | goi_body.append(' else if (pData != NULL && memcmp(pData, pPacket->pData, size) != 0)') |
| 2568 | goi_body.append(' {') |
| 2569 | goi_body.append(' glv_LogWarn("xglGetObjectInfo returned differing data contents than the trace file contained.\\n");') |
| 2570 | goi_body.append(' }') |
| 2571 | goi_body.append(' }') |
| 2572 | goi_body.append(' glv_free(pData);') |
| 2573 | return "\n".join(goi_body) |
| 2574 | |
| 2575 | def _gen_replay_get_format_info(self): |
| 2576 | gfi_body = [] |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 2577 | gfi_body.append(' size_t size = 0;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2578 | gfi_body.append(' void* pData = NULL;') |
| 2579 | gfi_body.append(' if (pPacket->pData != NULL && pPacket->pDataSize != NULL)') |
| 2580 | gfi_body.append(' {') |
| 2581 | gfi_body.append(' size = *pPacket->pDataSize;') |
| 2582 | gfi_body.append(' pData = glv_malloc(*pPacket->pDataSize);') |
| 2583 | gfi_body.append(' }') |
| 2584 | gfi_body.append(' replayResult = m_xglFuncs.real_xglGetFormatInfo(remap(pPacket->device), pPacket->format, pPacket->infoType, &size, pData);') |
| 2585 | gfi_body.append(' if (replayResult == XGL_SUCCESS)') |
| 2586 | gfi_body.append(' {') |
Jon Ashburn | e3a667c | 2015-02-11 09:32:29 -0700 | [diff] [blame] | 2587 | gfi_body.append(' if (size != *pPacket->pDataSize && pData != NULL)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2588 | gfi_body.append(' {') |
| 2589 | gfi_body.append(' glv_LogWarn("xglGetFormatInfo returned a differing data size: replay (%d bytes) vs trace (%d bytes)\\n", size, *pPacket->pDataSize);') |
| 2590 | gfi_body.append(' }') |
| 2591 | gfi_body.append(' else if (pData != NULL && memcmp(pData, pPacket->pData, size) != 0)') |
| 2592 | gfi_body.append(' {') |
| 2593 | gfi_body.append(' glv_LogWarn("xglGetFormatInfo returned differing data contents than the trace file contained.\\n");') |
| 2594 | gfi_body.append(' }') |
| 2595 | gfi_body.append(' }') |
| 2596 | gfi_body.append(' glv_free(pData);') |
| 2597 | return "\n".join(gfi_body) |
| 2598 | |
| 2599 | def _gen_replay_get_image_subresource_info(self): |
| 2600 | isi_body = [] |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 2601 | isi_body.append(' size_t size = 0;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2602 | isi_body.append(' void* pData = NULL;') |
| 2603 | isi_body.append(' if (pPacket->pData != NULL && pPacket->pDataSize != NULL)') |
| 2604 | isi_body.append(' {') |
| 2605 | isi_body.append(' size = *pPacket->pDataSize;') |
| 2606 | isi_body.append(' pData = glv_malloc(*pPacket->pDataSize);') |
| 2607 | isi_body.append(' }') |
| 2608 | isi_body.append(' replayResult = m_xglFuncs.real_xglGetImageSubresourceInfo(remap(pPacket->image), pPacket->pSubresource, pPacket->infoType, &size, pData);') |
| 2609 | isi_body.append(' if (replayResult == XGL_SUCCESS)') |
| 2610 | isi_body.append(' {') |
Jon Ashburn | e3a667c | 2015-02-11 09:32:29 -0700 | [diff] [blame] | 2611 | isi_body.append(' if (size != *pPacket->pDataSize && pData != NULL)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2612 | isi_body.append(' {') |
| 2613 | isi_body.append(' glv_LogWarn("xglGetImageSubresourceInfo returned a differing data size: replay (%d bytes) vs trace (%d bytes)\\n", size, *pPacket->pDataSize);') |
| 2614 | isi_body.append(' }') |
| 2615 | isi_body.append(' else if (pData != NULL && memcmp(pData, pPacket->pData, size) != 0)') |
| 2616 | isi_body.append(' {') |
| 2617 | isi_body.append(' glv_LogWarn("xglGetImageSubresourceInfo returned differing data contents than the trace file contained.\\n");') |
| 2618 | isi_body.append(' }') |
| 2619 | isi_body.append(' }') |
| 2620 | isi_body.append(' glv_free(pData);') |
| 2621 | return "\n".join(isi_body) |
| 2622 | |
Tobin Ehlis | f29cc37 | 2015-01-22 12:29:31 -0700 | [diff] [blame] | 2623 | def _gen_replay_update_descriptors(self): |
| 2624 | ud_body = [] |
Jon Ashburn | 19cedb4 | 2015-02-13 11:25:53 -0700 | [diff] [blame] | 2625 | # We have to remap handles internal to the structures so save the handles prior to remap and then restore |
| 2626 | # Rather than doing a deep memcpy of the entire struct and fixing any intermediate pointers, do save and restores via STL queue |
Tobin Ehlis | f6f8cd4 | 2015-02-03 14:41:26 -0700 | [diff] [blame] | 2627 | ud_body.append(' XGL_UPDATE_SAMPLERS* pUpdateChain = (XGL_UPDATE_SAMPLERS*)pPacket->pUpdateChain;') |
Jon Ashburn | 19cedb4 | 2015-02-13 11:25:53 -0700 | [diff] [blame] | 2628 | ud_body.append(' std::queue<XGL_SAMPLER> saveSamplers;') |
| 2629 | ud_body.append(' std::queue<XGL_BUFFER_VIEW> saveBufferViews;') |
| 2630 | ud_body.append(' std::queue<XGL_IMAGE_VIEW> saveImageViews;') |
| 2631 | ud_body.append(' std::queue<XGL_DESCRIPTOR_SET> saveDescSets;') |
Tobin Ehlis | f6f8cd4 | 2015-02-03 14:41:26 -0700 | [diff] [blame] | 2632 | ud_body.append(' while (pUpdateChain) {') |
| 2633 | ud_body.append(' switch(pUpdateChain->sType)') |
| 2634 | ud_body.append(' {') |
| 2635 | ud_body.append(' case XGL_STRUCTURE_TYPE_UPDATE_SAMPLERS:') |
Jon Ashburn | 19cedb4 | 2015-02-13 11:25:53 -0700 | [diff] [blame] | 2636 | ud_body.append(' for (uint32_t i = 0; i < ((XGL_UPDATE_SAMPLERS*)pUpdateChain)->count; i++) {') |
| 2637 | ud_body.append(' XGL_SAMPLER* pLocalSampler = (XGL_SAMPLER*) &((XGL_UPDATE_SAMPLERS*)pUpdateChain)->pSamplers[i];') |
| 2638 | ud_body.append(' saveSamplers.push(*pLocalSampler);') |
Tobin Ehlis | 49c3ddd | 2015-02-04 14:57:24 -0700 | [diff] [blame] | 2639 | ud_body.append(' *pLocalSampler = remap(((XGL_UPDATE_SAMPLERS*)pUpdateChain)->pSamplers[i]);') |
Tobin Ehlis | f6f8cd4 | 2015-02-03 14:41:26 -0700 | [diff] [blame] | 2640 | ud_body.append(' }') |
| 2641 | ud_body.append(' break;') |
| 2642 | ud_body.append(' case XGL_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:') |
Jon Ashburn | 19cedb4 | 2015-02-13 11:25:53 -0700 | [diff] [blame] | 2643 | ud_body.append(' {') |
| 2644 | ud_body.append(' XGL_UPDATE_SAMPLER_TEXTURES *pUST = (XGL_UPDATE_SAMPLER_TEXTURES *) pUpdateChain;') |
| 2645 | ud_body.append(' for (uint32_t i = 0; i < pUST->count; i++) {') |
| 2646 | ud_body.append(' XGL_SAMPLER *pLocalSampler = (XGL_SAMPLER *) &pUST->pSamplerImageViews[i].pSampler;') |
| 2647 | ud_body.append(' saveSamplers.push(*pLocalSampler);') |
| 2648 | ud_body.append(' *pLocalSampler = remap(pUST->pSamplerImageViews[i].pSampler);') |
| 2649 | ud_body.append(' XGL_IMAGE_VIEW *pLocalView = (XGL_IMAGE_VIEW *) &pUST->pSamplerImageViews[i].pImageView->view;') |
| 2650 | ud_body.append(' saveImageViews.push(*pLocalView);') |
| 2651 | ud_body.append(' *pLocalView = remap(pUST->pSamplerImageViews[i].pImageView->view);') |
Tobin Ehlis | f6f8cd4 | 2015-02-03 14:41:26 -0700 | [diff] [blame] | 2652 | ud_body.append(' }') |
| 2653 | ud_body.append(' break;') |
Jon Ashburn | 19cedb4 | 2015-02-13 11:25:53 -0700 | [diff] [blame] | 2654 | ud_body.append(' }') |
Tobin Ehlis | f6f8cd4 | 2015-02-03 14:41:26 -0700 | [diff] [blame] | 2655 | ud_body.append(' case XGL_STRUCTURE_TYPE_UPDATE_IMAGES:') |
Jon Ashburn | 19cedb4 | 2015-02-13 11:25:53 -0700 | [diff] [blame] | 2656 | ud_body.append(' {') |
| 2657 | ud_body.append(' XGL_UPDATE_IMAGES *pUI = (XGL_UPDATE_IMAGES*) pUpdateChain;') |
| 2658 | ud_body.append(' for (uint32_t i = 0; i < pUI->count; i++) {') |
| 2659 | ud_body.append(' XGL_IMAGE_VIEW* pLocalView = (XGL_IMAGE_VIEW*) &pUI->pImageViews[i]->view;') |
| 2660 | ud_body.append(' saveImageViews.push(*pLocalView);') |
| 2661 | ud_body.append(' *pLocalView = remap(pUI->pImageViews[i]->view);') |
Tobin Ehlis | f6f8cd4 | 2015-02-03 14:41:26 -0700 | [diff] [blame] | 2662 | ud_body.append(' }') |
| 2663 | ud_body.append(' break;') |
Jon Ashburn | 19cedb4 | 2015-02-13 11:25:53 -0700 | [diff] [blame] | 2664 | ud_body.append(' }') |
Tobin Ehlis | f6f8cd4 | 2015-02-03 14:41:26 -0700 | [diff] [blame] | 2665 | ud_body.append(' case XGL_STRUCTURE_TYPE_UPDATE_BUFFERS:') |
Jon Ashburn | 19cedb4 | 2015-02-13 11:25:53 -0700 | [diff] [blame] | 2666 | ud_body.append(' {') |
| 2667 | ud_body.append(' XGL_UPDATE_BUFFERS *pUB = (XGL_UPDATE_BUFFERS *) pUpdateChain;') |
| 2668 | ud_body.append(' for (uint32_t i = 0; i < pUB->count; i++) {') |
| 2669 | ud_body.append(' XGL_BUFFER_VIEW* pLocalView = (XGL_BUFFER_VIEW*) &pUB->pBufferViews[i]->view;') |
| 2670 | ud_body.append(' saveBufferViews.push(*pLocalView);') |
| 2671 | ud_body.append(' *pLocalView = remap(pUB->pBufferViews[i]->view);') |
Tobin Ehlis | f6f8cd4 | 2015-02-03 14:41:26 -0700 | [diff] [blame] | 2672 | ud_body.append(' }') |
| 2673 | ud_body.append(' break;') |
Jon Ashburn | 19cedb4 | 2015-02-13 11:25:53 -0700 | [diff] [blame] | 2674 | ud_body.append(' }') |
Tobin Ehlis | f6f8cd4 | 2015-02-03 14:41:26 -0700 | [diff] [blame] | 2675 | ud_body.append(' case XGL_STRUCTURE_TYPE_UPDATE_AS_COPY:') |
Jon Ashburn | 19cedb4 | 2015-02-13 11:25:53 -0700 | [diff] [blame] | 2676 | ud_body.append(' saveDescSets.push(((XGL_UPDATE_AS_COPY*)pUpdateChain)->descriptorSet);') |
| 2677 | ud_body.append(' ((XGL_UPDATE_AS_COPY*)pUpdateChain)->descriptorSet = remap(((XGL_UPDATE_AS_COPY*)pUpdateChain)->descriptorSet);') |
Tobin Ehlis | f6f8cd4 | 2015-02-03 14:41:26 -0700 | [diff] [blame] | 2678 | ud_body.append(' break;') |
| 2679 | ud_body.append(' default:') |
Jon Ashburn | 19cedb4 | 2015-02-13 11:25:53 -0700 | [diff] [blame] | 2680 | ud_body.append(' assert(0);') |
Tobin Ehlis | f6f8cd4 | 2015-02-03 14:41:26 -0700 | [diff] [blame] | 2681 | ud_body.append(' break;') |
| 2682 | ud_body.append(' }') |
Jon Ashburn | 19cedb4 | 2015-02-13 11:25:53 -0700 | [diff] [blame] | 2683 | ud_body.append(' pUpdateChain = (XGL_UPDATE_SAMPLERS*) pUpdateChain->pNext;') |
Tobin Ehlis | f6f8cd4 | 2015-02-03 14:41:26 -0700 | [diff] [blame] | 2684 | ud_body.append(' }') |
Jon Ashburn | 19cedb4 | 2015-02-13 11:25:53 -0700 | [diff] [blame] | 2685 | ud_body.append(' m_xglFuncs.real_xglUpdateDescriptors(remap(pPacket->descriptorSet), pPacket->pUpdateChain);') |
| 2686 | ud_body.append(' pUpdateChain = (XGL_UPDATE_SAMPLERS*) pPacket->pUpdateChain;') |
| 2687 | ud_body.append(' while (pUpdateChain) {') |
| 2688 | ud_body.append(' switch(pUpdateChain->sType)') |
Tobin Ehlis | f6f8cd4 | 2015-02-03 14:41:26 -0700 | [diff] [blame] | 2689 | ud_body.append(' {') |
| 2690 | ud_body.append(' case XGL_STRUCTURE_TYPE_UPDATE_SAMPLERS:') |
Jon Ashburn | 19cedb4 | 2015-02-13 11:25:53 -0700 | [diff] [blame] | 2691 | ud_body.append(' for (uint32_t i = 0; i < ((XGL_UPDATE_SAMPLERS*)pUpdateChain)->count; i++) {') |
| 2692 | ud_body.append(' XGL_SAMPLER* pLocalSampler = (XGL_SAMPLER*) &((XGL_UPDATE_SAMPLERS*)pUpdateChain)->pSamplers[i];') |
| 2693 | ud_body.append(' *pLocalSampler = saveSamplers.front();') |
| 2694 | ud_body.append(' saveSamplers.pop();') |
| 2695 | ud_body.append(' }') |
| 2696 | ud_body.append(' break;') |
Tobin Ehlis | f6f8cd4 | 2015-02-03 14:41:26 -0700 | [diff] [blame] | 2697 | ud_body.append(' case XGL_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:') |
Jon Ashburn | 19cedb4 | 2015-02-13 11:25:53 -0700 | [diff] [blame] | 2698 | ud_body.append(' {') |
| 2699 | ud_body.append(' XGL_UPDATE_SAMPLER_TEXTURES *pUST = (XGL_UPDATE_SAMPLER_TEXTURES *) pUpdateChain;') |
| 2700 | ud_body.append(' for (uint32_t i = 0; i < pUST->count; i++) {') |
| 2701 | ud_body.append(' XGL_SAMPLER *plocalSampler = (XGL_SAMPLER *) &pUST->pSamplerImageViews[i].pSampler;') |
| 2702 | ud_body.append(' *plocalSampler = saveSamplers.front();') |
| 2703 | ud_body.append(' saveSamplers.pop();') |
| 2704 | ud_body.append(' XGL_IMAGE_VIEW *pLocalView = (XGL_IMAGE_VIEW *) &pUST->pSamplerImageViews[i].pImageView->view;') |
| 2705 | ud_body.append(' *pLocalView = saveImageViews.front();') |
| 2706 | ud_body.append(' saveImageViews.pop();') |
| 2707 | ud_body.append(' }') |
| 2708 | ud_body.append(' break;') |
| 2709 | ud_body.append(' }') |
| 2710 | ud_body.append(' case XGL_STRUCTURE_TYPE_UPDATE_IMAGES:') |
| 2711 | ud_body.append(' {') |
| 2712 | ud_body.append(' XGL_UPDATE_IMAGES *pUI = (XGL_UPDATE_IMAGES*) pUpdateChain;') |
| 2713 | ud_body.append(' for (uint32_t i = 0; i < pUI->count; i++) {') |
| 2714 | ud_body.append(' XGL_IMAGE_VIEW* pLocalView = (XGL_IMAGE_VIEW*) &pUI->pImageViews[i]->view;') |
| 2715 | ud_body.append(' *pLocalView = saveImageViews.front();') |
| 2716 | ud_body.append(' saveImageViews.pop();') |
| 2717 | ud_body.append(' }') |
| 2718 | ud_body.append(' break;') |
| 2719 | ud_body.append(' }') |
| 2720 | ud_body.append(' case XGL_STRUCTURE_TYPE_UPDATE_BUFFERS:') |
| 2721 | ud_body.append(' {') |
| 2722 | ud_body.append(' XGL_UPDATE_BUFFERS *pUB = (XGL_UPDATE_BUFFERS *) pUpdateChain;') |
| 2723 | ud_body.append(' for (uint32_t i = 0; i < pUB->count; i++) {') |
| 2724 | ud_body.append(' XGL_BUFFER_VIEW* pLocalView = (XGL_BUFFER_VIEW*) &pUB->pBufferViews[i]->view;') |
| 2725 | ud_body.append(' *pLocalView = saveBufferViews.front();') |
| 2726 | ud_body.append(' saveBufferViews.pop();') |
| 2727 | ud_body.append(' }') |
| 2728 | ud_body.append(' break;') |
| 2729 | ud_body.append(' }') |
| 2730 | ud_body.append(' case XGL_STRUCTURE_TYPE_UPDATE_AS_COPY:') |
| 2731 | ud_body.append(' ((XGL_UPDATE_AS_COPY*)pUpdateChain)->descriptorSet = saveDescSets.front();') |
| 2732 | ud_body.append(' saveDescSets.pop();') |
| 2733 | ud_body.append(' //pFreeMe = (XGL_UPDATE_SAMPLERS*)pLocalUpdateChain;') |
| 2734 | ud_body.append(' //pLocalUpdateChain = (void*)((XGL_UPDATE_SAMPLERS*)pLocalUpdateChain)->pNext;') |
| 2735 | ud_body.append(' //free(pFreeMe);') |
Tobin Ehlis | f6f8cd4 | 2015-02-03 14:41:26 -0700 | [diff] [blame] | 2736 | ud_body.append(' break;') |
| 2737 | ud_body.append(' default:') |
Jon Ashburn | 19cedb4 | 2015-02-13 11:25:53 -0700 | [diff] [blame] | 2738 | ud_body.append(' assert(0);') |
Tobin Ehlis | f6f8cd4 | 2015-02-03 14:41:26 -0700 | [diff] [blame] | 2739 | ud_body.append(' break;') |
| 2740 | ud_body.append(' }') |
Jon Ashburn | 19cedb4 | 2015-02-13 11:25:53 -0700 | [diff] [blame] | 2741 | ud_body.append(' pUpdateChain = (XGL_UPDATE_SAMPLERS*) pUpdateChain->pNext;') |
Tobin Ehlis | f6f8cd4 | 2015-02-03 14:41:26 -0700 | [diff] [blame] | 2742 | ud_body.append(' }') |
| 2743 | return "\n".join(ud_body) |
Tobin Ehlis | f29cc37 | 2015-01-22 12:29:31 -0700 | [diff] [blame] | 2744 | |
| 2745 | def _gen_replay_create_descriptor_set_layout(self): |
| 2746 | cdsl_body = [] |
Jon Ashburn | 05cfe26 | 2015-02-10 14:32:23 -0700 | [diff] [blame] | 2747 | cdsl_body.append(' XGL_SAMPLER saveSampler;') |
| 2748 | cdsl_body.append(' if (pPacket->pSetLayoutInfoList != NULL) {') |
| 2749 | cdsl_body.append(' XGL_SAMPLER *pSampler = (XGL_SAMPLER *) &pPacket->pSetLayoutInfoList->immutableSampler;') |
| 2750 | cdsl_body.append(' saveSampler = pPacket->pSetLayoutInfoList->immutableSampler;') |
| 2751 | cdsl_body.append(' *pSampler = remap(saveSampler);') |
| 2752 | cdsl_body.append(' }') |
Tobin Ehlis | f6f8cd4 | 2015-02-03 14:41:26 -0700 | [diff] [blame] | 2753 | cdsl_body.append(' XGL_DESCRIPTOR_SET_LAYOUT setLayout;') |
Jon Ashburn | 05cfe26 | 2015-02-10 14:32:23 -0700 | [diff] [blame] | 2754 | cdsl_body.append(' replayResult = m_xglFuncs.real_xglCreateDescriptorSetLayout(remap(pPacket->device), pPacket->stageFlags, pPacket->pSetBindPoints, remap(pPacket->priorSetLayout), pPacket->pSetLayoutInfoList, &setLayout);') |
Tobin Ehlis | f6f8cd4 | 2015-02-03 14:41:26 -0700 | [diff] [blame] | 2755 | cdsl_body.append(' if (replayResult == XGL_SUCCESS)') |
| 2756 | cdsl_body.append(' {') |
| 2757 | cdsl_body.append(' add_to_map(pPacket->pSetLayout, &setLayout);') |
| 2758 | cdsl_body.append(' }') |
Jon Ashburn | 05cfe26 | 2015-02-10 14:32:23 -0700 | [diff] [blame] | 2759 | cdsl_body.append(' if (pPacket->pSetLayoutInfoList != NULL) {') |
| 2760 | cdsl_body.append(' XGL_SAMPLER *pSampler = (XGL_SAMPLER *) &pPacket->pSetLayoutInfoList->immutableSampler;') |
| 2761 | cdsl_body.append(' *pSampler = saveSampler;') |
| 2762 | cdsl_body.append(' }') |
Tobin Ehlis | f6f8cd4 | 2015-02-03 14:41:26 -0700 | [diff] [blame] | 2763 | return "\n".join(cdsl_body) |
Tobin Ehlis | f29cc37 | 2015-01-22 12:29:31 -0700 | [diff] [blame] | 2764 | |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2765 | def _gen_replay_create_graphics_pipeline(self): |
| 2766 | cgp_body = [] |
| 2767 | cgp_body.append(' XGL_GRAPHICS_PIPELINE_CREATE_INFO createInfo;') |
| 2768 | cgp_body.append(' struct shaderPair saveShader[10];') |
| 2769 | cgp_body.append(' unsigned int idx = 0;') |
| 2770 | cgp_body.append(' memcpy(&createInfo, pPacket->pCreateInfo, sizeof(XGL_GRAPHICS_PIPELINE_CREATE_INFO));') |
Jon Ashburn | 23438a7 | 2015-02-03 17:47:58 -0700 | [diff] [blame] | 2771 | cgp_body.append(' createInfo.lastSetLayout = remap(createInfo.lastSetLayout);') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2772 | cgp_body.append(' // Cast to shader type, as those are of primariy interest and all structs in LL have same header w/ sType & pNext') |
| 2773 | cgp_body.append(' XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* pPacketNext = (XGL_PIPELINE_SHADER_STAGE_CREATE_INFO*)pPacket->pCreateInfo->pNext;') |
| 2774 | cgp_body.append(' XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* pNext = (XGL_PIPELINE_SHADER_STAGE_CREATE_INFO*)createInfo.pNext;') |
| 2775 | cgp_body.append(' while (XGL_NULL_HANDLE != pPacketNext)') |
| 2776 | cgp_body.append(' {') |
| 2777 | cgp_body.append(' if (XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO == pNext->sType)') |
| 2778 | cgp_body.append(' {') |
| 2779 | cgp_body.append(' saveShader[idx].val = pNext->shader.shader;') |
| 2780 | cgp_body.append(' saveShader[idx++].addr = &(pNext->shader.shader);') |
| 2781 | cgp_body.append(' pNext->shader.shader = remap(pPacketNext->shader.shader);') |
| 2782 | cgp_body.append(' }') |
| 2783 | cgp_body.append(' pPacketNext = (XGL_PIPELINE_SHADER_STAGE_CREATE_INFO*)pPacketNext->pNext;') |
| 2784 | cgp_body.append(' pNext = (XGL_PIPELINE_SHADER_STAGE_CREATE_INFO*)pNext->pNext;') |
| 2785 | cgp_body.append(' }') |
| 2786 | cgp_body.append(' XGL_PIPELINE pipeline;') |
| 2787 | cgp_body.append(' replayResult = m_xglFuncs.real_xglCreateGraphicsPipeline(remap(pPacket->device), &createInfo, &pipeline);') |
| 2788 | cgp_body.append(' if (replayResult == XGL_SUCCESS)') |
| 2789 | cgp_body.append(' {') |
| 2790 | cgp_body.append(' add_to_map(pPacket->pPipeline, &pipeline);') |
| 2791 | cgp_body.append(' }') |
| 2792 | cgp_body.append(' for (unsigned int i = 0; i < idx; i++)') |
| 2793 | cgp_body.append(' *(saveShader[i].addr) = saveShader[i].val;') |
| 2794 | return "\n".join(cgp_body) |
| 2795 | |
Tobin Ehlis | a8f6afe | 2015-02-05 11:29:45 -0700 | [diff] [blame] | 2796 | def _gen_replay_cmd_wait_events(self): |
| 2797 | cwe_body = [] |
Jon Ashburn | 67c6580 | 2015-02-10 10:36:22 -0700 | [diff] [blame] | 2798 | cwe_body.append(' XGL_EVENT saveEvent[100];') |
| 2799 | cwe_body.append(' uint32_t idx, numRemapBuf=0, numRemapImg=0;') |
Tobin Ehlis | a8f6afe | 2015-02-05 11:29:45 -0700 | [diff] [blame] | 2800 | cwe_body.append(' assert(pPacket->pWaitInfo && pPacket->pWaitInfo->eventCount <= 100);') |
| 2801 | cwe_body.append(' for (idx = 0; idx < pPacket->pWaitInfo->eventCount; idx++)') |
| 2802 | cwe_body.append(' {') |
Jon Ashburn | 67c6580 | 2015-02-10 10:36:22 -0700 | [diff] [blame] | 2803 | cwe_body.append(' XGL_EVENT *pEvent = (XGL_EVENT *) &(pPacket->pWaitInfo->pEvents[idx]);') |
| 2804 | cwe_body.append(' saveEvent[idx] = pPacket->pWaitInfo->pEvents[idx];') |
| 2805 | cwe_body.append(' *pEvent = remap(pPacket->pWaitInfo->pEvents[idx]);') |
| 2806 | cwe_body.append(' }') |
| 2807 | cwe_body.append('') |
| 2808 | cwe_body.append(' XGL_BUFFER saveBuf[100];') |
| 2809 | cwe_body.append(' XGL_IMAGE saveImg[100];') |
| 2810 | cwe_body.append(' for (idx = 0; idx < pPacket->pWaitInfo->memBarrierCount; idx++)') |
| 2811 | cwe_body.append(' {') |
| 2812 | cwe_body.append(' XGL_MEMORY_BARRIER *pNext = (XGL_MEMORY_BARRIER *) pPacket->pWaitInfo->ppMemBarriers[idx];') |
| 2813 | cwe_body.append(' assert(pNext);') |
| 2814 | cwe_body.append(' if (pNext->sType == XGL_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER) {') |
| 2815 | cwe_body.append(' XGL_BUFFER_MEMORY_BARRIER *pNextBuf = (XGL_BUFFER_MEMORY_BARRIER *) pPacket->pWaitInfo->ppMemBarriers[idx];') |
| 2816 | cwe_body.append(' assert(numRemapBuf < 100);') |
| 2817 | cwe_body.append(' saveBuf[numRemapBuf++] = pNextBuf->buffer;') |
| 2818 | cwe_body.append(' pNextBuf->buffer = remap(pNextBuf->buffer);') |
| 2819 | cwe_body.append(' } else if (pNext->sType == XGL_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {') |
| 2820 | cwe_body.append(' XGL_IMAGE_MEMORY_BARRIER *pNextImg = (XGL_IMAGE_MEMORY_BARRIER *) pPacket->pWaitInfo->ppMemBarriers[idx];') |
| 2821 | cwe_body.append(' assert(numRemapImg < 100);') |
| 2822 | cwe_body.append(' saveImg[numRemapImg++] = pNextImg->image;') |
| 2823 | cwe_body.append(' pNextImg->image = remap(pNextImg->image);') |
| 2824 | cwe_body.append(' }') |
Tobin Ehlis | a8f6afe | 2015-02-05 11:29:45 -0700 | [diff] [blame] | 2825 | cwe_body.append(' }') |
| 2826 | cwe_body.append(' m_xglFuncs.real_xglCmdWaitEvents(remap(pPacket->cmdBuffer), pPacket->pWaitInfo);') |
Jon Ashburn | 67c6580 | 2015-02-10 10:36:22 -0700 | [diff] [blame] | 2827 | cwe_body.append(' for (idx = 0; idx < pPacket->pWaitInfo->memBarrierCount; idx++) {') |
| 2828 | cwe_body.append(' XGL_MEMORY_BARRIER *pNext = (XGL_MEMORY_BARRIER *) pPacket->pWaitInfo->ppMemBarriers[idx];') |
| 2829 | cwe_body.append(' if (pNext->sType == XGL_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER) {') |
| 2830 | cwe_body.append(' XGL_BUFFER_MEMORY_BARRIER *pNextBuf = (XGL_BUFFER_MEMORY_BARRIER *) pPacket->pWaitInfo->ppMemBarriers[idx];') |
| 2831 | cwe_body.append(' pNextBuf->buffer = saveBuf[idx];') |
| 2832 | cwe_body.append(' } else if (pNext->sType == XGL_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {') |
| 2833 | cwe_body.append(' XGL_IMAGE_MEMORY_BARRIER *pNextImg = (XGL_IMAGE_MEMORY_BARRIER *) pPacket->pWaitInfo->ppMemBarriers[idx];') |
| 2834 | cwe_body.append(' pNextImg->image = saveImg[idx];') |
| 2835 | cwe_body.append(' }') |
| 2836 | cwe_body.append(' }') |
| 2837 | cwe_body.append(' for (idx = 0; idx < pPacket->pWaitInfo->eventCount; idx++) {') |
| 2838 | cwe_body.append(' XGL_EVENT *pEvent = (XGL_EVENT *) &(pPacket->pWaitInfo->pEvents[idx]);') |
| 2839 | cwe_body.append(' *pEvent = saveEvent[idx];') |
| 2840 | cwe_body.append(' }') |
Tobin Ehlis | a8f6afe | 2015-02-05 11:29:45 -0700 | [diff] [blame] | 2841 | return "\n".join(cwe_body) |
| 2842 | |
Jon Ashburn | 67c6580 | 2015-02-10 10:36:22 -0700 | [diff] [blame] | 2843 | def _gen_replay_cmd_pipeline_barrier(self): |
| 2844 | cpb_body = [] |
| 2845 | cpb_body.append(' uint32_t idx, numRemapBuf=0, numRemapImg=0;') |
| 2846 | cpb_body.append(' XGL_BUFFER saveBuf[100];') |
| 2847 | cpb_body.append(' XGL_IMAGE saveImg[100];') |
| 2848 | cpb_body.append(' for (idx = 0; idx < pPacket->pBarrier->memBarrierCount; idx++)') |
| 2849 | cpb_body.append(' {') |
| 2850 | cpb_body.append(' XGL_MEMORY_BARRIER *pNext = (XGL_MEMORY_BARRIER *) pPacket->pBarrier->ppMemBarriers[idx];') |
| 2851 | cpb_body.append(' assert(pNext);') |
| 2852 | cpb_body.append(' if (pNext->sType == XGL_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER) {') |
| 2853 | cpb_body.append(' XGL_BUFFER_MEMORY_BARRIER *pNextBuf = (XGL_BUFFER_MEMORY_BARRIER *) pPacket->pBarrier->ppMemBarriers[idx];') |
| 2854 | cpb_body.append(' assert(numRemapBuf < 100);') |
| 2855 | cpb_body.append(' saveBuf[numRemapBuf++] = pNextBuf->buffer;') |
| 2856 | cpb_body.append(' pNextBuf->buffer = remap(pNextBuf->buffer);') |
| 2857 | cpb_body.append(' } else if (pNext->sType == XGL_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {') |
| 2858 | cpb_body.append(' XGL_IMAGE_MEMORY_BARRIER *pNextImg = (XGL_IMAGE_MEMORY_BARRIER *) pPacket->pBarrier->ppMemBarriers[idx];') |
| 2859 | cpb_body.append(' assert(numRemapImg < 100);') |
| 2860 | cpb_body.append(' saveImg[numRemapImg++] = pNextImg->image;') |
| 2861 | cpb_body.append(' pNextImg->image = remap(pNextImg->image);') |
| 2862 | cpb_body.append(' }') |
| 2863 | cpb_body.append(' }') |
| 2864 | cpb_body.append(' m_xglFuncs.real_xglCmdPipelineBarrier(remap(pPacket->cmdBuffer), pPacket->pBarrier);') |
| 2865 | cpb_body.append(' for (idx = 0; idx < pPacket->pBarrier->memBarrierCount; idx++) {') |
| 2866 | cpb_body.append(' XGL_MEMORY_BARRIER *pNext = (XGL_MEMORY_BARRIER *) pPacket->pBarrier->ppMemBarriers[idx];') |
| 2867 | cpb_body.append(' if (pNext->sType == XGL_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER) {') |
| 2868 | cpb_body.append(' XGL_BUFFER_MEMORY_BARRIER *pNextBuf = (XGL_BUFFER_MEMORY_BARRIER *) pPacket->pBarrier->ppMemBarriers[idx];') |
| 2869 | cpb_body.append(' pNextBuf->buffer = saveBuf[idx];') |
| 2870 | cpb_body.append(' } else if (pNext->sType == XGL_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {') |
| 2871 | cpb_body.append(' XGL_IMAGE_MEMORY_BARRIER *pNextImg = (XGL_IMAGE_MEMORY_BARRIER *) pPacket->pBarrier->ppMemBarriers[idx];') |
| 2872 | cpb_body.append(' pNextImg->image = saveImg[idx];') |
| 2873 | cpb_body.append(' }') |
| 2874 | cpb_body.append(' }') |
| 2875 | return "\n".join(cpb_body) |
| 2876 | |
Jon Ashburn | 38349d0 | 2015-01-02 18:28:26 -0700 | [diff] [blame] | 2877 | def _gen_replay_create_framebuffer(self): |
| 2878 | cf_body = [] |
| 2879 | cf_body.append(' XGL_FRAMEBUFFER_CREATE_INFO *pInfo = (XGL_FRAMEBUFFER_CREATE_INFO *) pPacket->pCreateInfo;') |
| 2880 | cf_body.append(' XGL_COLOR_ATTACHMENT_BIND_INFO *pColorAttachments, *pSavedColor = (XGL_COLOR_ATTACHMENT_BIND_INFO*)pInfo->pColorAttachments;') |
| 2881 | cf_body.append(' bool allocatedColorAttachments = false;') |
| 2882 | cf_body.append(' if (pSavedColor != NULL)') |
| 2883 | cf_body.append(' {') |
| 2884 | cf_body.append(' allocatedColorAttachments = true;') |
| 2885 | cf_body.append(' pColorAttachments = GLV_NEW_ARRAY(XGL_COLOR_ATTACHMENT_BIND_INFO, pInfo->colorAttachmentCount);') |
| 2886 | cf_body.append(' memcpy(pColorAttachments, pSavedColor, sizeof(XGL_COLOR_ATTACHMENT_BIND_INFO) * pInfo->colorAttachmentCount);') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 2887 | cf_body.append(' for (uint32_t i = 0; i < pInfo->colorAttachmentCount; i++)') |
Jon Ashburn | 38349d0 | 2015-01-02 18:28:26 -0700 | [diff] [blame] | 2888 | cf_body.append(' {') |
| 2889 | cf_body.append(' pColorAttachments[i].view = remap(pInfo->pColorAttachments[i].view);') |
| 2890 | cf_body.append(' }') |
| 2891 | cf_body.append(' pInfo->pColorAttachments = pColorAttachments;') |
| 2892 | cf_body.append(' }') |
| 2893 | cf_body.append(' // remap depth stencil target') |
Tobin Ehlis | bf967aa | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 2894 | cf_body.append(' const XGL_DEPTH_STENCIL_BIND_INFO *pSavedDS = pInfo->pDepthStencilAttachment;') |
Jon Ashburn | 38349d0 | 2015-01-02 18:28:26 -0700 | [diff] [blame] | 2895 | cf_body.append(' XGL_DEPTH_STENCIL_BIND_INFO depthTarget;') |
| 2896 | cf_body.append(' if (pSavedDS != NULL)') |
| 2897 | cf_body.append(' {') |
| 2898 | cf_body.append(' memcpy(&depthTarget, pSavedDS, sizeof(XGL_DEPTH_STENCIL_BIND_INFO));') |
| 2899 | cf_body.append(' depthTarget.view = remap(pSavedDS->view);') |
| 2900 | cf_body.append(' pInfo->pDepthStencilAttachment = &depthTarget;') |
| 2901 | cf_body.append(' }') |
| 2902 | cf_body.append(' XGL_FRAMEBUFFER local_framebuffer;') |
| 2903 | cf_body.append(' replayResult = m_xglFuncs.real_xglCreateFramebuffer(remap(pPacket->device), pPacket->pCreateInfo, &local_framebuffer);') |
| 2904 | cf_body.append(' pInfo->pColorAttachments = pSavedColor;') |
| 2905 | cf_body.append(' pInfo->pDepthStencilAttachment = pSavedDS;') |
| 2906 | cf_body.append(' if (replayResult == XGL_SUCCESS)') |
| 2907 | cf_body.append(' {') |
| 2908 | cf_body.append(' add_to_map(pPacket->pFramebuffer, &local_framebuffer);') |
| 2909 | cf_body.append(' }') |
| 2910 | cf_body.append(' if (allocatedColorAttachments)') |
| 2911 | cf_body.append(' {') |
| 2912 | cf_body.append(' GLV_DELETE((void*)pColorAttachments);') |
| 2913 | cf_body.append(' }') |
| 2914 | return "\n".join(cf_body) |
| 2915 | |
| 2916 | def _gen_replay_create_renderpass(self): |
| 2917 | cr_body = [] |
| 2918 | cr_body.append(' XGL_RENDER_PASS_CREATE_INFO *pInfo = (XGL_RENDER_PASS_CREATE_INFO *) pPacket->pCreateInfo;') |
| 2919 | cr_body.append(' // remap framebuffer') |
Jon Ashburn | 5fec47e | 2015-03-09 11:33:40 -0600 | [diff] [blame] | 2920 | cr_body.append(' XGL_FRAMEBUFFER savedFB = 0, *pFB = &(pInfo->framebuffer);') |
Jon Ashburn | 38349d0 | 2015-01-02 18:28:26 -0700 | [diff] [blame] | 2921 | cr_body.append(' if (*pFB != NULL)') |
| 2922 | cr_body.append(' {') |
| 2923 | cr_body.append(' savedFB = pInfo->framebuffer;') |
| 2924 | cr_body.append(' *pFB = remap(pInfo->framebuffer);') |
| 2925 | cr_body.append(' }') |
| 2926 | cr_body.append(' XGL_RENDER_PASS local_renderpass;') |
| 2927 | cr_body.append(' replayResult = m_xglFuncs.real_xglCreateRenderPass(remap(pPacket->device), pPacket->pCreateInfo, &local_renderpass);') |
Jon Ashburn | 5fec47e | 2015-03-09 11:33:40 -0600 | [diff] [blame] | 2928 | cr_body.append(' if (*pFB != NULL)') |
| 2929 | cr_body.append(' pInfo->framebuffer = savedFB;') |
Jon Ashburn | 38349d0 | 2015-01-02 18:28:26 -0700 | [diff] [blame] | 2930 | cr_body.append(' if (replayResult == XGL_SUCCESS)') |
| 2931 | cr_body.append(' {') |
| 2932 | cr_body.append(' add_to_map(pPacket->pRenderPass, &local_renderpass);') |
| 2933 | cr_body.append(' }') |
| 2934 | return "\n".join(cr_body) |
| 2935 | |
| 2936 | def _gen_replay_begin_command_buffer(self): |
| 2937 | bcb_body = [] |
| 2938 | bcb_body.append(' XGL_CMD_BUFFER_BEGIN_INFO* pInfo = (XGL_CMD_BUFFER_BEGIN_INFO*)pPacket->pBeginInfo;') |
| 2939 | bcb_body.append(' // assume only zero or one graphics_begin_info in the chain') |
| 2940 | bcb_body.append(' XGL_RENDER_PASS savedRP, *pRP;') |
| 2941 | bcb_body.append(' XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO *pGInfo = NULL;') |
| 2942 | bcb_body.append(' while (pInfo != NULL)') |
| 2943 | bcb_body.append(' {') |
| 2944 | bcb_body.append('') |
| 2945 | bcb_body.append(' if (pInfo->sType == XGL_STRUCTURE_TYPE_CMD_BUFFER_GRAPHICS_BEGIN_INFO)') |
| 2946 | bcb_body.append(' {') |
| 2947 | bcb_body.append(' pGInfo = (XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO *) pInfo;') |
| 2948 | bcb_body.append(' savedRP = pGInfo->renderPass;') |
| 2949 | bcb_body.append(' pRP = &(pGInfo->renderPass);') |
| 2950 | bcb_body.append(' *pRP = remap(pGInfo->renderPass);') |
| 2951 | bcb_body.append(' break;') |
| 2952 | bcb_body.append(' }') |
| 2953 | bcb_body.append(' pInfo = (XGL_CMD_BUFFER_BEGIN_INFO*) pInfo->pNext;') |
| 2954 | bcb_body.append(' }') |
| 2955 | bcb_body.append(' replayResult = m_xglFuncs.real_xglBeginCommandBuffer(remap(pPacket->cmdBuffer), pPacket->pBeginInfo);') |
| 2956 | bcb_body.append(' if (pGInfo != NULL)') |
| 2957 | bcb_body.append(' pGInfo->renderPass = savedRP;') |
| 2958 | return "\n".join(bcb_body) |
| 2959 | |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2960 | def _gen_replay_store_pipeline(self): |
| 2961 | sp_body = [] |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 2962 | sp_body.append(' size_t size = 0;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2963 | sp_body.append(' void* pData = NULL;') |
| 2964 | sp_body.append(' if (pPacket->pData != NULL && pPacket->pDataSize != NULL)') |
| 2965 | sp_body.append(' {') |
| 2966 | sp_body.append(' size = *pPacket->pDataSize;') |
| 2967 | sp_body.append(' pData = glv_malloc(*pPacket->pDataSize);') |
| 2968 | sp_body.append(' }') |
| 2969 | sp_body.append(' replayResult = m_xglFuncs.real_xglStorePipeline(remap(pPacket->pipeline), &size, pData);') |
| 2970 | sp_body.append(' if (replayResult == XGL_SUCCESS)') |
| 2971 | sp_body.append(' {') |
Jon Ashburn | e3a667c | 2015-02-11 09:32:29 -0700 | [diff] [blame] | 2972 | sp_body.append(' if (size != *pPacket->pDataSize && pData != NULL)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2973 | sp_body.append(' {') |
| 2974 | sp_body.append(' glv_LogWarn("xglStorePipeline returned a differing data size: replay (%d bytes) vs trace (%d bytes)\\n", size, *pPacket->pDataSize);') |
| 2975 | sp_body.append(' }') |
| 2976 | sp_body.append(' else if (pData != NULL && memcmp(pData, pPacket->pData, size) != 0)') |
| 2977 | sp_body.append(' {') |
| 2978 | sp_body.append(' glv_LogWarn("xglStorePipeline returned differing data contents than the trace file contained.\\n");') |
| 2979 | sp_body.append(' }') |
| 2980 | sp_body.append(' }') |
| 2981 | sp_body.append(' glv_free(pData);') |
| 2982 | return "\n".join(sp_body) |
| 2983 | |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 2984 | def _gen_replay_get_multi_gpu_compatibility(self): |
| 2985 | gmgc_body = [] |
| 2986 | gmgc_body.append(' XGL_GPU_COMPATIBILITY_INFO cInfo;') |
| 2987 | gmgc_body.append(' XGL_PHYSICAL_GPU handle0, handle1;') |
| 2988 | gmgc_body.append(' handle0 = remap(pPacket->gpu0);') |
| 2989 | gmgc_body.append(' handle1 = remap(pPacket->gpu1);') |
| 2990 | gmgc_body.append(' replayResult = m_xglFuncs.real_xglGetMultiGpuCompatibility(handle0, handle1, &cInfo);') |
| 2991 | return "\n".join(gmgc_body) |
| 2992 | |
| 2993 | def _gen_replay_destroy_object(self): |
| 2994 | do_body = [] |
| 2995 | do_body.append(' XGL_OBJECT object = remap(pPacket->object);') |
| 2996 | do_body.append(' if (object != XGL_NULL_HANDLE)') |
| 2997 | do_body.append(' replayResult = m_xglFuncs.real_xglDestroyObject(object);') |
| 2998 | do_body.append(' if (replayResult == XGL_SUCCESS)') |
| 2999 | do_body.append(' rm_from_map(pPacket->object);') |
| 3000 | return "\n".join(do_body) |
| 3001 | |
| 3002 | def _gen_replay_wait_for_fences(self): |
| 3003 | wf_body = [] |
| 3004 | wf_body.append(' XGL_FENCE *pFence = GLV_NEW_ARRAY(XGL_FENCE, pPacket->fenceCount);') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 3005 | wf_body.append(' for (uint32_t i = 0; i < pPacket->fenceCount; i++)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3006 | wf_body.append(' {') |
| 3007 | wf_body.append(' *(pFence + i) = remap(*(pPacket->pFences + i));') |
| 3008 | wf_body.append(' }') |
| 3009 | wf_body.append(' replayResult = m_xglFuncs.real_xglWaitForFences(remap(pPacket->device), pPacket->fenceCount, pFence, pPacket->waitAll, pPacket->timeout);') |
| 3010 | wf_body.append(' GLV_DELETE(pFence);') |
| 3011 | return "\n".join(wf_body) |
| 3012 | |
| 3013 | def _gen_replay_wsi_associate_connection(self): |
| 3014 | wac_body = [] |
Piers Daniell | 188f820 | 2015-02-24 13:58:47 -0700 | [diff] [blame] | 3015 | wac_body.append('#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3016 | wac_body.append(' //associate with the replayers Wsi connection rather than tracers') |
| 3017 | wac_body.append(' replayResult = m_xglFuncs.real_xglWsiX11AssociateConnection(remap(pPacket->gpu), &(m_display->m_WsiConnection));') |
Piers Daniell | 188f820 | 2015-02-24 13:58:47 -0700 | [diff] [blame] | 3018 | wac_body.append('#elif defined(WIN32)') |
| 3019 | wac_body.append(' //TBD') |
| 3020 | wac_body.append(' replayResult = XGL_SUCCESS;') |
David Pinedo | 5350930 | 2015-02-10 15:02:08 -0700 | [diff] [blame] | 3021 | wac_body.append('#endif') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3022 | return "\n".join(wac_body) |
| 3023 | |
| 3024 | def _gen_replay_wsi_get_msc(self): |
| 3025 | wgm_body = [] |
Piers Daniell | 188f820 | 2015-02-24 13:58:47 -0700 | [diff] [blame] | 3026 | wgm_body.append('#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA)') |
| 3027 | wgm_body.append(' xcb_window_t window = m_display->m_XcbWindow;') |
| 3028 | wgm_body.append(' replayResult = m_xglFuncs.real_xglWsiX11GetMSC(remap(pPacket->device), window, pPacket->crtc, pPacket->pMsc);') |
| 3029 | wgm_body.append('#elif defined(WIN32)') |
David Pinedo | 5350930 | 2015-02-10 15:02:08 -0700 | [diff] [blame] | 3030 | wgm_body.append(' //TBD') |
| 3031 | wgm_body.append(' replayResult = XGL_SUCCESS;') |
| 3032 | wgm_body.append('#else') |
Piers Daniell | 188f820 | 2015-02-24 13:58:47 -0700 | [diff] [blame] | 3033 | |
David Pinedo | 5350930 | 2015-02-10 15:02:08 -0700 | [diff] [blame] | 3034 | wgm_body.append('#endif') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3035 | return "\n".join(wgm_body) |
| 3036 | |
| 3037 | def _gen_replay_wsi_create_presentable_image(self): |
| 3038 | cpi_body = [] |
Piers Daniell | 188f820 | 2015-02-24 13:58:47 -0700 | [diff] [blame] | 3039 | cpi_body.append('#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3040 | cpi_body.append(' XGL_IMAGE img;') |
| 3041 | cpi_body.append(' XGL_GPU_MEMORY mem;') |
Tony Barbour | a7390a0 | 2015-02-05 09:46:17 -0700 | [diff] [blame] | 3042 | cpi_body.append(' m_display->imageHeight.push_back(pPacket->pCreateInfo->extent.height);') |
| 3043 | cpi_body.append(' m_display->imageWidth.push_back(pPacket->pCreateInfo->extent.width);') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3044 | cpi_body.append(' replayResult = m_xglFuncs.real_xglWsiX11CreatePresentableImage(remap(pPacket->device), pPacket->pCreateInfo, &img, &mem);') |
| 3045 | cpi_body.append(' if (replayResult == XGL_SUCCESS)') |
| 3046 | cpi_body.append(' {') |
| 3047 | cpi_body.append(' if (pPacket->pImage != NULL)') |
| 3048 | cpi_body.append(' add_to_map(pPacket->pImage, &img);') |
| 3049 | cpi_body.append(' if(pPacket->pMem != NULL)') |
| 3050 | cpi_body.append(' add_to_map(pPacket->pMem, &mem);') |
Tony Barbour | a7390a0 | 2015-02-05 09:46:17 -0700 | [diff] [blame] | 3051 | cpi_body.append(' m_display->imageHandles.push_back(img);') |
| 3052 | cpi_body.append(' m_display->imageMemory.push_back(mem);') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3053 | cpi_body.append(' }') |
Piers Daniell | 188f820 | 2015-02-24 13:58:47 -0700 | [diff] [blame] | 3054 | cpi_body.append('#elif defined(WIN32)') |
| 3055 | cpi_body.append(' //TBD') |
| 3056 | cpi_body.append(' replayResult = XGL_SUCCESS;') |
David Pinedo | 5350930 | 2015-02-10 15:02:08 -0700 | [diff] [blame] | 3057 | cpi_body.append('#endif') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3058 | return "\n".join(cpi_body) |
| 3059 | |
| 3060 | def _gen_replay_wsi_queue_present(self): |
| 3061 | wqp_body = [] |
Piers Daniell | 188f820 | 2015-02-24 13:58:47 -0700 | [diff] [blame] | 3062 | wqp_body.append('#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3063 | wqp_body.append(' XGL_WSI_X11_PRESENT_INFO pInfo;') |
Tony Barbour | 5d5bc99 | 2015-02-02 13:21:18 -0700 | [diff] [blame] | 3064 | wqp_body.append(' std::vector<int>::iterator it;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3065 | wqp_body.append(' memcpy(&pInfo, pPacket->pPresentInfo, sizeof(XGL_WSI_X11_PRESENT_INFO));') |
| 3066 | wqp_body.append(' pInfo.srcImage = remap(pPacket->pPresentInfo->srcImage);') |
| 3067 | wqp_body.append(' // use replayers Xcb window') |
| 3068 | wqp_body.append(' pInfo.destWindow = m_display->m_XcbWindow;') |
| 3069 | wqp_body.append(' replayResult = m_xglFuncs.real_xglWsiX11QueuePresent(remap(pPacket->queue), &pInfo, remap(pPacket->fence));') |
Tony Barbour | a7390a0 | 2015-02-05 09:46:17 -0700 | [diff] [blame] | 3070 | wqp_body.append(' it = std::find(m_screenshotFrames.begin(), m_screenshotFrames.end(), m_display->m_frameNumber);') |
| 3071 | wqp_body.append(' if (it != m_screenshotFrames.end())') |
Tony Barbour | 5d5bc99 | 2015-02-02 13:21:18 -0700 | [diff] [blame] | 3072 | wqp_body.append(' {') |
Tony Barbour | a7390a0 | 2015-02-05 09:46:17 -0700 | [diff] [blame] | 3073 | wqp_body.append(' for(unsigned int i=0; i<m_display->imageHandles.size(); i++)') |
Tony Barbour | 5d5bc99 | 2015-02-02 13:21:18 -0700 | [diff] [blame] | 3074 | wqp_body.append(' {') |
Tony Barbour | a7390a0 | 2015-02-05 09:46:17 -0700 | [diff] [blame] | 3075 | wqp_body.append(' if (m_display->imageHandles[i] == pInfo.srcImage)') |
Tony Barbour | 5d5bc99 | 2015-02-02 13:21:18 -0700 | [diff] [blame] | 3076 | wqp_body.append(' {') |
| 3077 | wqp_body.append(' char frameName[32];') |
| 3078 | wqp_body.append(' sprintf(frameName, "%d",m_display->m_frameNumber);') |
Tony Barbour | a7390a0 | 2015-02-05 09:46:17 -0700 | [diff] [blame] | 3079 | wqp_body.append(' glvWritePPM(frameName, m_display->imageWidth[i], m_display->imageHeight[i],') |
| 3080 | wqp_body.append(' m_display->imageHandles[i], m_display->imageMemory[i], &m_xglFuncs);') |
Tony Barbour | 5d5bc99 | 2015-02-02 13:21:18 -0700 | [diff] [blame] | 3081 | wqp_body.append(' break;') |
| 3082 | wqp_body.append(' }') |
| 3083 | wqp_body.append(' }') |
| 3084 | wqp_body.append(' }') |
Piers Daniell | 188f820 | 2015-02-24 13:58:47 -0700 | [diff] [blame] | 3085 | wqp_body.append('#elif defined(WIN32)') |
| 3086 | wqp_body.append(' //TBD') |
| 3087 | wqp_body.append(' replayResult = XGL_SUCCESS;') |
David Pinedo | 5350930 | 2015-02-10 15:02:08 -0700 | [diff] [blame] | 3088 | wqp_body.append('#endif') |
Tony Barbour | 5d5bc99 | 2015-02-02 13:21:18 -0700 | [diff] [blame] | 3089 | wqp_body.append(' m_display->m_frameNumber++;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3090 | return "\n".join(wqp_body) |
| 3091 | |
| 3092 | # I don't like making these 3 mem functions 'fully' custom, but just doing it for now to avoid being too cute |
| 3093 | def _gen_replay_free_memory(self): |
| 3094 | fm_body = [] |
| 3095 | fm_body.append(' XGL_GPU_MEMORY handle = remap(pPacket->mem);') |
| 3096 | fm_body.append(' replayResult = m_xglFuncs.real_xglFreeMemory(handle);') |
| 3097 | fm_body.append(' if (replayResult == XGL_SUCCESS) ') |
| 3098 | fm_body.append(' {') |
| 3099 | fm_body.append(' rm_entry_from_mapData(handle);') |
| 3100 | fm_body.append(' rm_from_map(pPacket->mem);') |
| 3101 | fm_body.append(' }') |
| 3102 | return "\n".join(fm_body) |
| 3103 | |
| 3104 | def _gen_replay_map_memory(self): |
| 3105 | mm_body = [] |
| 3106 | mm_body.append(' XGL_GPU_MEMORY handle = remap(pPacket->mem);') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 3107 | mm_body.append(' void* pData;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3108 | mm_body.append(' replayResult = m_xglFuncs.real_xglMapMemory(handle, pPacket->flags, &pData);') |
| 3109 | mm_body.append(' if (replayResult == XGL_SUCCESS)') |
| 3110 | mm_body.append(' add_mapping_to_mapData(handle, pData);') |
| 3111 | return "\n".join(mm_body) |
| 3112 | |
| 3113 | def _gen_replay_unmap_memory(self): |
| 3114 | um_body = [] |
| 3115 | um_body.append(' XGL_GPU_MEMORY handle = remap(pPacket->mem);') |
Jon Ashburn | 290dcb1 | 2015-03-02 17:12:31 -0700 | [diff] [blame] | 3116 | um_body.append(' rm_mapping_from_mapData(handle, pPacket->pData); // copies data from packet into memory buffer') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3117 | um_body.append(' replayResult = m_xglFuncs.real_xglUnmapMemory(handle);') |
| 3118 | return "\n".join(um_body) |
| 3119 | |
| 3120 | def _gen_replay_bind_dynamic_memory_view(self): |
| 3121 | bdmv_body = [] |
| 3122 | bdmv_body.append(' XGL_MEMORY_VIEW_ATTACH_INFO memView;') |
| 3123 | bdmv_body.append(' memcpy(&memView, pPacket->pMemView, sizeof(XGL_MEMORY_VIEW_ATTACH_INFO));') |
| 3124 | bdmv_body.append(' memView.mem = remap(pPacket->pMemView->mem);') |
| 3125 | bdmv_body.append(' m_xglFuncs.real_xglCmdBindDynamicMemoryView(remap(pPacket->cmdBuffer), pPacket->pipelineBindPoint, &memView);') |
| 3126 | return "\n".join(bdmv_body) |
| 3127 | |
Tobin Ehlis | a8f6afe | 2015-02-05 11:29:45 -0700 | [diff] [blame] | 3128 | # Generate main replay case statements where actual replay API call is dispatched based on input packet data |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3129 | def _generate_replay(self): |
| 3130 | # map protos to custom functions if body is fully custom |
Tobin Ehlis | 1077703 | 2015-01-16 15:13:34 -0700 | [diff] [blame] | 3131 | custom_body_dict = {'EnumerateGpus': self._gen_replay_enum_gpus, |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3132 | 'GetGpuInfo': self._gen_replay_get_gpu_info, |
| 3133 | 'CreateDevice': self._gen_replay_create_device, |
| 3134 | 'GetExtensionSupport': self._gen_replay_get_extension_support, |
| 3135 | 'QueueSubmit': self._gen_replay_queue_submit, |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3136 | 'GetObjectInfo': self._gen_replay_get_object_info, |
| 3137 | 'GetFormatInfo': self._gen_replay_get_format_info, |
| 3138 | 'GetImageSubresourceInfo': self._gen_replay_get_image_subresource_info, |
| 3139 | 'CreateGraphicsPipeline': self._gen_replay_create_graphics_pipeline, |
Jon Ashburn | 38349d0 | 2015-01-02 18:28:26 -0700 | [diff] [blame] | 3140 | 'CreateFramebuffer': self._gen_replay_create_framebuffer, |
| 3141 | 'CreateRenderPass': self._gen_replay_create_renderpass, |
| 3142 | 'BeginCommandBuffer': self._gen_replay_begin_command_buffer, |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3143 | 'StorePipeline': self._gen_replay_store_pipeline, |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3144 | 'GetMultiGpuCompatibility': self._gen_replay_get_multi_gpu_compatibility, |
| 3145 | 'DestroyObject': self._gen_replay_destroy_object, |
| 3146 | 'WaitForFences': self._gen_replay_wait_for_fences, |
| 3147 | 'WsiX11AssociateConnection': self._gen_replay_wsi_associate_connection, |
| 3148 | 'WsiX11GetMSC': self._gen_replay_wsi_get_msc, |
| 3149 | 'WsiX11CreatePresentableImage': self._gen_replay_wsi_create_presentable_image, |
| 3150 | 'WsiX11QueuePresent': self._gen_replay_wsi_queue_present, |
| 3151 | 'FreeMemory': self._gen_replay_free_memory, |
| 3152 | 'MapMemory': self._gen_replay_map_memory, |
| 3153 | 'UnmapMemory': self._gen_replay_unmap_memory, |
Tobin Ehlis | f6f8cd4 | 2015-02-03 14:41:26 -0700 | [diff] [blame] | 3154 | 'CmdBindDynamicMemoryView': self._gen_replay_bind_dynamic_memory_view, |
| 3155 | 'UpdateDescriptors': self._gen_replay_update_descriptors, |
Tobin Ehlis | a8f6afe | 2015-02-05 11:29:45 -0700 | [diff] [blame] | 3156 | 'CreateDescriptorSetLayout': self._gen_replay_create_descriptor_set_layout, |
Jon Ashburn | 67c6580 | 2015-02-10 10:36:22 -0700 | [diff] [blame] | 3157 | 'CmdWaitEvents': self._gen_replay_cmd_wait_events, |
| 3158 | 'CmdPipelineBarrier': self._gen_replay_cmd_pipeline_barrier} |
Tobin Ehlis | f29cc37 | 2015-01-22 12:29:31 -0700 | [diff] [blame] | 3159 | # TODO : Need to guard CreateInstance with "if (!m_display->m_initedXGL)" check |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3160 | # Despite returning a value, don't check these funcs b/c custom code includes check already |
Jon Ashburn | 03d0bcc | 2015-02-03 11:24:08 -0700 | [diff] [blame] | 3161 | custom_check_ret_val = ['EnumerateGpus', 'GetGpuInfo', 'CreateDevice', 'GetExtensionSupport'] |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3162 | # multi-gpu Open funcs w/ list of local params to create |
| 3163 | custom_open_params = {'OpenSharedMemory': (-1,), |
| 3164 | 'OpenSharedQueueSemaphore': (-1,), |
| 3165 | 'OpenPeerMemory': (-1,), |
| 3166 | 'OpenPeerImage': (-1, -2,)} |
| 3167 | # Functions that create views are unique from other create functions |
Jon Ashburn | 03d0bcc | 2015-02-03 11:24:08 -0700 | [diff] [blame] | 3168 | create_view_list = ['CreateBufferView', 'CreateImageView', 'CreateColorAttachmentView', 'CreateDepthStencilView', 'CreateComputePipeline'] |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3169 | # Functions to treat as "Create' that don't have 'Create' in the name |
Tobin Ehlis | 271e51d | 2015-01-20 13:50:59 -0700 | [diff] [blame] | 3170 | special_create_list = ['LoadPipeline', 'AllocMemory', 'GetDeviceQueue', 'PinSystemMemory', 'AllocDescriptorSets'] |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3171 | # A couple funcs use do while loops |
| 3172 | 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'} |
| 3173 | rbody = [] |
| 3174 | rbody.append('#define CHECK_RETURN_VALUE(entrypoint) returnValue = handle_replay_errors(#entrypoint, replayResult, pPacket->result, returnValue);\n') |
| 3175 | rbody.append('glv_replay::GLV_REPLAY_RESULT xglReplay::replay(glv_trace_packet_header *packet)') |
| 3176 | rbody.append('{') |
| 3177 | rbody.append(' glv_replay::GLV_REPLAY_RESULT returnValue = glv_replay::GLV_REPLAY_SUCCESS;') |
| 3178 | rbody.append(' XGL_RESULT replayResult = XGL_ERROR_UNKNOWN;') |
| 3179 | rbody.append(' switch (packet->packet_id)') |
| 3180 | rbody.append(' {') |
Jon Ashburn | d07dfef | 2015-02-03 08:57:28 -0700 | [diff] [blame] | 3181 | rbody.append(' case GLV_TPI_XGL_xglApiVersion:') |
| 3182 | rbody.append(' break; // nothing to replay on the version packet') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3183 | for proto in self.protos: |
| 3184 | ret_value = False |
| 3185 | create_view = False |
| 3186 | create_func = False |
Tobin Ehlis | bf967aa | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 3187 | # TODO : How to handle void* return of GetProcAddr? |
| 3188 | if ('void' not in proto.ret) and (proto.name not in custom_check_ret_val): |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3189 | ret_value = True |
| 3190 | if proto.name in create_view_list: |
| 3191 | create_view = True |
| 3192 | elif 'Create' in proto.name or proto.name in special_create_list: |
| 3193 | create_func = True |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3194 | rbody.append(' case GLV_TPI_XGL_xgl%s:' % proto.name) |
| 3195 | rbody.append(' {') |
| 3196 | rbody.append(' struct_xgl%s* pPacket = (struct_xgl%s*)(packet->pBody);' % (proto.name, proto.name)) |
| 3197 | if proto.name in custom_body_dict: |
| 3198 | rbody.append(custom_body_dict[proto.name]()) |
| 3199 | else: |
| 3200 | if proto.name in custom_open_params: |
| 3201 | rbody.append(' XGL_DEVICE handle;') |
| 3202 | for pidx in custom_open_params[proto.name]: |
Tobin Ehlis | bf967aa | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 3203 | rbody.append(' %s local_%s;' % (proto.params[pidx].ty.replace('const ', '').strip('*'), proto.params[pidx].name)) |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3204 | rbody.append(' handle = remap(pPacket->device);') |
| 3205 | elif create_view: |
Tobin Ehlis | bf967aa | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 3206 | rbody.append(' %s createInfo;' % (proto.params[1].ty.strip('*').replace('const ', ''))) |
| 3207 | rbody.append(' memcpy(&createInfo, pPacket->pCreateInfo, sizeof(%s));' % (proto.params[1].ty.strip('*').replace('const ', ''))) |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3208 | if 'CreateComputePipeline' == proto.name: |
| 3209 | rbody.append(' createInfo.cs.shader = remap(pPacket->pCreateInfo->cs.shader);') |
Jon Ashburn | 03d0bcc | 2015-02-03 11:24:08 -0700 | [diff] [blame] | 3210 | elif 'CreateBufferView' == proto.name: |
| 3211 | rbody.append(' createInfo.buffer = remap(pPacket->pCreateInfo->buffer);') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3212 | else: |
| 3213 | rbody.append(' createInfo.image = remap(pPacket->pCreateInfo->image);') |
Tobin Ehlis | bf967aa | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 3214 | rbody.append(' %s local_%s;' % (proto.params[-1].ty.strip('*').replace('const ', ''), proto.params[-1].name)) |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3215 | elif create_func: # Declare local var to store created handle into |
Tobin Ehlis | bf967aa | 2015-01-15 17:53:54 -0700 | [diff] [blame] | 3216 | rbody.append(' %s local_%s;' % (proto.params[-1].ty.strip('*').replace('const ', ''), proto.params[-1].name)) |
Tobin Ehlis | 271e51d | 2015-01-20 13:50:59 -0700 | [diff] [blame] | 3217 | if 'AllocDescriptorSets' == proto.name: |
Jon Ashburn | 9c246bc | 2015-02-04 12:57:25 -0700 | [diff] [blame] | 3218 | rbody.append(' %s local_%s[100];' % (proto.params[-2].ty.strip('*').replace('const ', ''), proto.params[-2].name)) |
| 3219 | rbody.append(' XGL_DESCRIPTOR_SET_LAYOUT localDescSets[100];') |
| 3220 | rbody.append(' assert(pPacket->count <= 100);') |
| 3221 | rbody.append(' for (uint32_t i = 0; i < pPacket->count; i++)') |
| 3222 | rbody.append(' {') |
| 3223 | rbody.append(' localDescSets[i] = remap(pPacket->%s[i]);' % (proto.params[-3].name)) |
| 3224 | rbody.append(' }') |
| 3225 | elif proto.name == 'ClearDescriptorSets': |
| 3226 | rbody.append(' XGL_DESCRIPTOR_SET localDescSets[100];') |
| 3227 | rbody.append(' assert(pPacket->count <= 100);') |
| 3228 | rbody.append(' for (uint32_t i = 0; i < pPacket->count; i++)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3229 | rbody.append(' {') |
Jon Ashburn | 9c246bc | 2015-02-04 12:57:25 -0700 | [diff] [blame] | 3230 | rbody.append(' localDescSets[i] = remap(pPacket->%s[i]);' % (proto.params[-1].name)) |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3231 | rbody.append(' }') |
| 3232 | elif proto.name in do_while_dict: |
| 3233 | rbody.append(' do {') |
Jon Ashburn | c579882 | 2015-02-03 13:39:05 -0700 | [diff] [blame] | 3234 | elif proto.name == 'EnumerateLayers': |
| 3235 | rbody.append(' char **bufptr = GLV_NEW_ARRAY(char *, pPacket->maxLayerCount);') |
| 3236 | rbody.append(' char **ptrLayers = (pPacket->pOutLayers == NULL) ? bufptr : (char **) pPacket->pOutLayers;') |
| 3237 | rbody.append(' for (unsigned int i = 0; i < pPacket->maxLayerCount; i++)') |
| 3238 | rbody.append(' bufptr[i] = GLV_NEW_ARRAY(char, pPacket->maxStringSize);') |
Jon Ashburn | 5cc4635 | 2015-02-12 12:37:46 -0700 | [diff] [blame] | 3239 | elif proto.name == 'DestroyInstance': |
| 3240 | rbody.append(' xglDbgUnregisterMsgCallback(g_fpDbgMsgCallback);') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3241 | rr_string = ' ' |
| 3242 | if ret_value: |
| 3243 | rr_string = ' replayResult = ' |
| 3244 | rr_string += 'm_xglFuncs.real_xgl%s(' % proto.name |
| 3245 | for p in proto.params: |
| 3246 | # For last param of Create funcs, pass address of param |
Tobin Ehlis | 271e51d | 2015-01-20 13:50:59 -0700 | [diff] [blame] | 3247 | if create_func: |
| 3248 | if p.name == proto.params[-1].name: |
| 3249 | rr_string += '&local_%s, ' % p.name |
| 3250 | elif proto.name == 'AllocDescriptorSets' and p.name == proto.params[-2].name: |
| 3251 | rr_string += 'local_%s, ' % p.name |
| 3252 | else: |
| 3253 | rr_string += '%s, ' % self._get_packet_param(p.ty, p.name) |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3254 | else: |
| 3255 | rr_string += '%s, ' % self._get_packet_param(p.ty, p.name) |
| 3256 | rr_string = '%s);' % rr_string[:-2] |
Jon Ashburn | 9c246bc | 2015-02-04 12:57:25 -0700 | [diff] [blame] | 3257 | if proto.name in custom_open_params: |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3258 | rr_list = rr_string.split(', ') |
| 3259 | rr_list[0] = rr_list[0].replace('remap(pPacket->device)', 'handle') |
| 3260 | for pidx in custom_open_params[proto.name]: |
| 3261 | rr_list[pidx] = '&local_%s' % proto.params[pidx].name |
| 3262 | rr_string = ', '.join(rr_list) |
| 3263 | rr_string += ');' |
| 3264 | elif create_view: |
| 3265 | rr_list = rr_string.split(', ') |
| 3266 | rr_list[-2] = '&createInfo' |
| 3267 | rr_list[-1] = '&local_%s);' % proto.params[-1].name |
| 3268 | rr_string = ', '.join(rr_list) |
| 3269 | # this is a sneaky shortcut to use generic create code below to add_to_map |
| 3270 | create_func = True |
Jon Ashburn | c579882 | 2015-02-03 13:39:05 -0700 | [diff] [blame] | 3271 | elif proto.name == 'EnumerateLayers': |
| 3272 | rr_string = rr_string.replace('pPacket->pOutLayers', 'ptrLayers') |
Jon Ashburn | 9c246bc | 2015-02-04 12:57:25 -0700 | [diff] [blame] | 3273 | elif proto.name == 'ClearDescriptorSets': |
| 3274 | rr_string = rr_string.replace('pPacket->pDescriptorSets', 'localDescSets') |
| 3275 | elif proto.name == 'AllocDescriptorSets': |
| 3276 | rr_string = rr_string.replace('pPacket->pSetLayouts', 'localDescSets') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3277 | rbody.append(rr_string) |
| 3278 | if 'DestroyDevice' in proto.name: |
| 3279 | rbody.append(' if (replayResult == XGL_SUCCESS)') |
| 3280 | rbody.append(' {') |
Peter Lohrmann | d2e8485 | 2015-02-27 15:35:15 -0800 | [diff] [blame] | 3281 | rbody.append(' m_pCBDump = NULL;') |
| 3282 | rbody.append(' m_pDSDump = NULL;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3283 | rbody.append(' rm_from_map(pPacket->device);') |
| 3284 | rbody.append(' m_display->m_initedXGL = false;') |
| 3285 | rbody.append(' }') |
Jon Ashburn | d07dfef | 2015-02-03 08:57:28 -0700 | [diff] [blame] | 3286 | if 'DestroyInstance' in proto.name: |
| 3287 | rbody.append(' if (replayResult == XGL_SUCCESS)') |
| 3288 | rbody.append(' {') |
Jon Ashburn | 6e9ca2b | 2015-02-03 09:17:12 -0700 | [diff] [blame] | 3289 | rbody.append(' // TODO need to handle multiple instances and only clearing maps within an instance.') |
| 3290 | rbody.append(' // TODO this only works with a single instance used at any given time.') |
| 3291 | rbody.append(' clear_all_map_handles();') |
Jon Ashburn | d07dfef | 2015-02-03 08:57:28 -0700 | [diff] [blame] | 3292 | rbody.append(' }') |
Tobin Ehlis | 271e51d | 2015-01-20 13:50:59 -0700 | [diff] [blame] | 3293 | elif 'AllocDescriptorSets' in proto.name: |
| 3294 | rbody.append(' if (replayResult == XGL_SUCCESS)') |
| 3295 | rbody.append(' {') |
| 3296 | rbody.append(' for (uint32_t i = 0; i < local_pCount; i++) {') |
Tobin Ehlis | f29cc37 | 2015-01-22 12:29:31 -0700 | [diff] [blame] | 3297 | rbody.append(' add_to_map(&pPacket->%s[i], &local_%s[i]);' % (proto.params[-2].name, proto.params[-2].name)) |
Tobin Ehlis | 271e51d | 2015-01-20 13:50:59 -0700 | [diff] [blame] | 3298 | rbody.append(' }') |
| 3299 | rbody.append(' }') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3300 | elif create_func: # save handle mapping if create successful |
| 3301 | rbody.append(' if (replayResult == XGL_SUCCESS)') |
| 3302 | rbody.append(' {') |
| 3303 | rbody.append(' add_to_map(pPacket->%s, &local_%s);' % (proto.params[-1].name, proto.params[-1].name)) |
| 3304 | if 'AllocMemory' == proto.name: |
| 3305 | rbody.append(' add_entry_to_mapData(local_%s, pPacket->pAllocInfo->allocationSize);' % (proto.params[-1].name)) |
| 3306 | rbody.append(' }') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3307 | elif proto.name in do_while_dict: |
| 3308 | rbody[-1] = ' %s' % rbody[-1] |
| 3309 | rbody.append(' } while (%s);' % do_while_dict[proto.name]) |
Jon Ashburn | 0a57611 | 2015-02-23 11:07:30 -0700 | [diff] [blame] | 3310 | rbody.append(' if (pPacket->result != XGL_NOT_READY || replayResult != XGL_SUCCESS)') |
Jon Ashburn | c579882 | 2015-02-03 13:39:05 -0700 | [diff] [blame] | 3311 | elif proto.name == 'EnumerateLayers': |
| 3312 | rbody.append(' for (unsigned int i = 0; i < pPacket->maxLayerCount; i++)') |
| 3313 | rbody.append(' GLV_DELETE(bufptr[i]);') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3314 | if ret_value: |
| 3315 | rbody.append(' CHECK_RETURN_VALUE(xgl%s);' % proto.name) |
| 3316 | if 'MsgCallback' in proto.name: |
| 3317 | rbody.pop() |
| 3318 | rbody.pop() |
| 3319 | rbody.pop() |
| 3320 | rbody.append(' // Just eating these calls as no way to restore dbg func ptr.') |
| 3321 | rbody.append(' break;') |
| 3322 | rbody.append(' }') |
| 3323 | rbody.append(' default:') |
| 3324 | rbody.append(' glv_LogWarn("Unrecognized packet_id %u, skipping\\n", packet->packet_id);') |
| 3325 | rbody.append(' returnValue = glv_replay::GLV_REPLAY_INVALID_ID;') |
| 3326 | rbody.append(' break;') |
| 3327 | rbody.append(' }') |
| 3328 | rbody.append(' return returnValue;') |
| 3329 | rbody.append('}') |
| 3330 | return "\n".join(rbody) |
| 3331 | |
| 3332 | class GlaveTraceHeader(Subcommand): |
| 3333 | def generate_header(self): |
| 3334 | header_txt = [] |
| 3335 | header_txt.append('#include "glvtrace_xgl_xgl_structs.h"') |
| 3336 | header_txt.append('#include "glvtrace_xgl_packet_id.h"\n') |
| 3337 | header_txt.append('void AttachHooks();') |
| 3338 | header_txt.append('void DetachHooks();') |
Ian Elliott | 5890a77 | 2015-02-27 11:10:59 -0700 | [diff] [blame] | 3339 | header_txt.append('void InitTracer(void);\n') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3340 | return "\n".join(header_txt) |
| 3341 | |
| 3342 | def generate_body(self): |
| 3343 | body = [self._generate_trace_func_ptrs(), |
| 3344 | self._generate_trace_func_protos()] |
| 3345 | |
| 3346 | return "\n".join(body) |
| 3347 | |
| 3348 | class GlaveTraceC(Subcommand): |
| 3349 | def generate_header(self): |
| 3350 | header_txt = [] |
| 3351 | header_txt.append('#include "glv_platform.h"') |
| 3352 | header_txt.append('#include "glv_common.h"') |
| 3353 | header_txt.append('#include "glvtrace_xgl_xgl.h"') |
| 3354 | header_txt.append('#include "glvtrace_xgl_xgldbg.h"') |
| 3355 | header_txt.append('#include "glvtrace_xgl_xglwsix11ext.h"') |
| 3356 | header_txt.append('#include "glv_interconnect.h"') |
| 3357 | header_txt.append('#include "glv_filelike.h"') |
Tobin Ehlis | 6035477 | 2015-03-12 14:50:40 -0600 | [diff] [blame] | 3358 | header_txt.append('#include "xgl_struct_size_helper.h"') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3359 | header_txt.append('#ifdef WIN32') |
| 3360 | header_txt.append('#include "mhook/mhook-lib/mhook.h"') |
| 3361 | header_txt.append('#endif') |
| 3362 | header_txt.append('#include "glv_trace_packet_utils.h"') |
| 3363 | header_txt.append('#include <stdio.h>\n') |
| 3364 | return "\n".join(header_txt) |
| 3365 | |
| 3366 | def generate_body(self): |
| 3367 | body = [self._generate_func_ptr_assignments(), |
| 3368 | self._generate_attach_hooks(), |
| 3369 | self._generate_detach_hooks(), |
Jon Ashburn | 15161e4 | 2014-12-16 18:37:04 -0700 | [diff] [blame] | 3370 | self._generate_init_funcs(), |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3371 | self._generate_helper_funcs(), |
| 3372 | self._generate_trace_funcs()] |
| 3373 | |
| 3374 | return "\n".join(body) |
| 3375 | |
| 3376 | class GlavePacketID(Subcommand): |
| 3377 | def generate_header(self): |
| 3378 | header_txt = [] |
| 3379 | header_txt.append('#pragma once\n') |
| 3380 | header_txt.append('#include "glv_trace_packet_utils.h"') |
| 3381 | header_txt.append('#include "glv_trace_packet_identifiers.h"') |
| 3382 | header_txt.append('#include "glv_interconnect.h"') |
| 3383 | header_txt.append('#include "glvtrace_xgl_xgl_structs.h"') |
| 3384 | header_txt.append('#include "glvtrace_xgl_xgldbg_structs.h"') |
| 3385 | header_txt.append('#include "glvtrace_xgl_xglwsix11ext_structs.h"') |
| 3386 | header_txt.append('#include "xgl_enum_string_helper.h"') |
Piers Daniell | 188f820 | 2015-02-24 13:58:47 -0700 | [diff] [blame] | 3387 | header_txt.append('#if defined(WIN32)') |
| 3388 | header_txt.append('#define snprintf _snprintf') |
| 3389 | header_txt.append('#endif') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3390 | header_txt.append('#define SEND_ENTRYPOINT_ID(entrypoint) ;') |
| 3391 | header_txt.append('//#define SEND_ENTRYPOINT_ID(entrypoint) glv_TraceInfo(#entrypoint "\\n");\n') |
| 3392 | header_txt.append('#define SEND_ENTRYPOINT_PARAMS(entrypoint, ...) ;') |
| 3393 | header_txt.append('//#define SEND_ENTRYPOINT_PARAMS(entrypoint, ...) glv_TraceInfo(entrypoint, __VA_ARGS__);\n') |
| 3394 | header_txt.append('#define CREATE_TRACE_PACKET(entrypoint, buffer_bytes_needed) \\') |
| 3395 | header_txt.append(' pHeader = glv_create_trace_packet(GLV_TID_XGL, GLV_TPI_XGL_##entrypoint, sizeof(struct_##entrypoint), buffer_bytes_needed);\n') |
| 3396 | header_txt.append('#define FINISH_TRACE_PACKET() \\') |
| 3397 | header_txt.append(' glv_finalize_trace_packet(pHeader); \\') |
| 3398 | header_txt.append(' glv_write_trace_packet(pHeader, glv_trace_get_trace_file()); \\') |
| 3399 | header_txt.append(' glv_delete_trace_packet(&pHeader);') |
| 3400 | return "\n".join(header_txt) |
| 3401 | |
| 3402 | def generate_body(self): |
| 3403 | body = [self._generate_packet_id_enum(), |
| 3404 | self._generate_stringify_func(), |
| 3405 | self._generate_interp_func()] |
| 3406 | |
| 3407 | return "\n".join(body) |
| 3408 | |
| 3409 | class GlaveCoreStructs(Subcommand): |
| 3410 | def generate_header(self): |
| 3411 | header_txt = [] |
| 3412 | header_txt.append('#pragma once\n') |
| 3413 | header_txt.append('#include "xgl.h"') |
| 3414 | header_txt.append('#include "glv_trace_packet_utils.h"\n') |
| 3415 | return "\n".join(header_txt) |
| 3416 | |
| 3417 | def generate_body(self): |
| 3418 | body = [self._generate_struct_util_funcs(), |
| 3419 | self._generate_interp_funcs()] |
| 3420 | |
| 3421 | return "\n".join(body) |
| 3422 | |
| 3423 | class GlaveWsiHeader(Subcommand): |
| 3424 | def generate_header(self): |
| 3425 | header_txt = [] |
| 3426 | header_txt.append('#pragma once\n') |
| 3427 | header_txt.append('#include "xgl.h"') |
Piers Daniell | 188f820 | 2015-02-24 13:58:47 -0700 | [diff] [blame] | 3428 | header_txt.append('#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3429 | header_txt.append('#include "xglWsiX11Ext.h"\n') |
David Pinedo | 5350930 | 2015-02-10 15:02:08 -0700 | [diff] [blame] | 3430 | header_txt.append('#else') |
| 3431 | header_txt.append('#include "xglWsiWinExt.h"') |
| 3432 | header_txt.append('#endif') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3433 | header_txt.append('void AttachHooks_xglwsix11ext();') |
| 3434 | header_txt.append('void DetachHooks_xglwsix11ext();') |
| 3435 | return "\n".join(header_txt) |
| 3436 | |
| 3437 | def generate_body(self): |
| 3438 | body = [self._generate_trace_func_ptrs_ext(), |
| 3439 | self._generate_trace_func_protos_ext()] |
| 3440 | |
| 3441 | return "\n".join(body) |
| 3442 | |
| 3443 | class GlaveWsiC(Subcommand): |
| 3444 | def generate_header(self): |
| 3445 | header_txt = [] |
| 3446 | header_txt.append('#include "glv_platform.h"') |
| 3447 | header_txt.append('#include "glv_common.h"') |
| 3448 | header_txt.append('#include "glvtrace_xgl_xglwsix11ext.h"') |
| 3449 | header_txt.append('#include "glvtrace_xgl_xglwsix11ext_structs.h"') |
| 3450 | header_txt.append('#include "glvtrace_xgl_packet_id.h"') |
| 3451 | header_txt.append('#ifdef WIN32') |
| 3452 | header_txt.append('#include "mhook/mhook-lib/mhook.h"') |
| 3453 | header_txt.append('#endif') |
| 3454 | return "\n".join(header_txt) |
| 3455 | |
| 3456 | def generate_body(self): |
| 3457 | body = [self._generate_func_ptr_assignments_ext(), |
| 3458 | self._generate_attach_hooks_ext(), |
| 3459 | self._generate_detach_hooks_ext(), |
| 3460 | self._generate_trace_funcs_ext()] |
| 3461 | |
| 3462 | return "\n".join(body) |
| 3463 | |
| 3464 | class GlaveWsiStructs(Subcommand): |
| 3465 | def generate_header(self): |
| 3466 | header_txt = [] |
| 3467 | header_txt.append('#pragma once\n') |
Piers Daniell | 188f820 | 2015-02-24 13:58:47 -0700 | [diff] [blame] | 3468 | header_txt.append('#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3469 | header_txt.append('#include "xglWsiX11Ext.h"') |
David Pinedo | 5350930 | 2015-02-10 15:02:08 -0700 | [diff] [blame] | 3470 | header_txt.append('#else') |
| 3471 | header_txt.append('#include "xglWsiWinExt.h"') |
| 3472 | header_txt.append('#endif') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3473 | header_txt.append('#include "glv_trace_packet_utils.h"\n') |
| 3474 | return "\n".join(header_txt) |
| 3475 | |
| 3476 | def generate_body(self): |
| 3477 | body = [self._generate_interp_funcs_ext()] |
| 3478 | |
| 3479 | return "\n".join(body) |
| 3480 | |
| 3481 | class GlaveDbgHeader(Subcommand): |
| 3482 | def generate_header(self): |
| 3483 | header_txt = [] |
| 3484 | header_txt.append('#pragma once\n') |
| 3485 | header_txt.append('#include "xgl.h"') |
| 3486 | header_txt.append('#include "xglDbg.h"\n') |
| 3487 | header_txt.append('void AttachHooks_xgldbg();') |
| 3488 | header_txt.append('void DetachHooks_xgldbg();') |
| 3489 | return "\n".join(header_txt) |
| 3490 | |
| 3491 | def generate_body(self): |
| 3492 | body = [self._generate_trace_func_ptrs_ext('Dbg'), |
| 3493 | self._generate_trace_func_protos_ext('Dbg')] |
| 3494 | |
| 3495 | return "\n".join(body) |
| 3496 | |
| 3497 | class GlaveDbgC(Subcommand): |
| 3498 | def generate_header(self): |
| 3499 | header_txt = [] |
| 3500 | header_txt.append('#include "glv_platform.h"') |
| 3501 | header_txt.append('#include "glv_common.h"') |
| 3502 | header_txt.append('#include "glvtrace_xgl_xgl.h"') |
| 3503 | header_txt.append('#include "glvtrace_xgl_xgldbg.h"') |
| 3504 | header_txt.append('#include "glvtrace_xgl_xgldbg_structs.h"') |
| 3505 | header_txt.append('#include "glvtrace_xgl_packet_id.h"') |
| 3506 | header_txt.append('#ifdef WIN32') |
| 3507 | header_txt.append('#include "mhook/mhook-lib/mhook.h"') |
| 3508 | header_txt.append('#endif') |
| 3509 | return "\n".join(header_txt) |
| 3510 | |
| 3511 | def generate_body(self): |
| 3512 | body = [self._generate_func_ptr_assignments_ext('Dbg'), |
| 3513 | self._generate_attach_hooks_ext('Dbg'), |
| 3514 | self._generate_detach_hooks_ext('Dbg'), |
| 3515 | self._generate_trace_funcs_ext('Dbg')] |
| 3516 | |
| 3517 | return "\n".join(body) |
| 3518 | |
| 3519 | class GlaveDbgStructs(Subcommand): |
| 3520 | def generate_header(self): |
| 3521 | header_txt = [] |
| 3522 | header_txt.append('#pragma once\n') |
| 3523 | header_txt.append('#include "xglDbg.h"') |
| 3524 | header_txt.append('#include "glv_trace_packet_utils.h"\n') |
| 3525 | return "\n".join(header_txt) |
| 3526 | |
| 3527 | def generate_body(self): |
| 3528 | body = [self._generate_interp_funcs_ext('Dbg')] |
| 3529 | |
| 3530 | return "\n".join(body) |
| 3531 | |
| 3532 | class GlaveReplayHeader(Subcommand): |
| 3533 | def generate_header(self): |
| 3534 | header_txt = [] |
| 3535 | header_txt.append('#pragma once\n') |
| 3536 | header_txt.append('#include <set>') |
| 3537 | header_txt.append('#include <map>') |
| 3538 | header_txt.append('#include <vector>') |
Tony Barbour | 5d5bc99 | 2015-02-02 13:21:18 -0700 | [diff] [blame] | 3539 | header_txt.append('#include <string>') |
Piers Daniell | 188f820 | 2015-02-24 13:58:47 -0700 | [diff] [blame] | 3540 | header_txt.append('#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3541 | header_txt.append('#include <xcb/xcb.h>\n') |
David Pinedo | 5350930 | 2015-02-10 15:02:08 -0700 | [diff] [blame] | 3542 | header_txt.append('#endif') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3543 | header_txt.append('#include "glvreplay_window.h"') |
| 3544 | header_txt.append('#include "glvreplay_factory.h"') |
| 3545 | header_txt.append('#include "glv_trace_packet_identifiers.h"\n') |
| 3546 | header_txt.append('#include "xgl.h"') |
| 3547 | header_txt.append('#include "xglDbg.h"') |
Piers Daniell | 188f820 | 2015-02-24 13:58:47 -0700 | [diff] [blame] | 3548 | header_txt.append('#if defined(PLATFORM_LINUX) || defined(XCB_NVIDIA)') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3549 | header_txt.append('#include "xglWsiX11Ext.h"') |
David Pinedo | 5350930 | 2015-02-10 15:02:08 -0700 | [diff] [blame] | 3550 | header_txt.append('#else') |
| 3551 | header_txt.append('#include "xglWsiWinExt.h"') |
| 3552 | header_txt.append('#endif') |
Jon Ashburn | 8ef49b1 | 2015-02-17 13:28:11 -0700 | [diff] [blame] | 3553 | header_txt.append('#include "draw_state.h"') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3554 | return "\n".join(header_txt) |
| 3555 | |
| 3556 | def generate_body(self): |
| 3557 | body = [self._generate_replay_class_decls(), |
| 3558 | self._generate_replay_func_ptrs(), |
| 3559 | self._generate_replay_class()] |
| 3560 | |
| 3561 | return "\n".join(body) |
| 3562 | |
| 3563 | class GlaveReplayC(Subcommand): |
| 3564 | def generate_header(self): |
| 3565 | header_txt = [] |
| 3566 | header_txt.append('#include "glvreplay_xgl_replay.h"\n') |
Jon Ashburn | ce66ab8 | 2014-12-18 17:03:34 -0700 | [diff] [blame] | 3567 | header_txt.append('#include "glvreplay_xgl.h"\n') |
Tony Barbour | 5d5bc99 | 2015-02-02 13:21:18 -0700 | [diff] [blame] | 3568 | header_txt.append('#include "glvreplay_xgl_write_ppm.h"\n') |
| 3569 | header_txt.append('#include "glvreplay_main.h"\n') |
| 3570 | header_txt.append('#include <algorithm>') |
Jon Ashburn | 19cedb4 | 2015-02-13 11:25:53 -0700 | [diff] [blame] | 3571 | header_txt.append('#include <queue>') |
Ian Elliott | eca1638 | 2015-02-18 15:35:00 -0700 | [diff] [blame] | 3572 | header_txt.append('glvreplay_settings *g_pReplaySettings;') |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3573 | header_txt.append('extern "C" {') |
| 3574 | header_txt.append('#include "glvtrace_xgl_xgl_structs.h"') |
| 3575 | header_txt.append('#include "glvtrace_xgl_xgldbg_structs.h"') |
| 3576 | header_txt.append('#include "glvtrace_xgl_xglwsix11ext_structs.h"') |
| 3577 | header_txt.append('#include "glvtrace_xgl_packet_id.h"') |
| 3578 | header_txt.append('#include "xgl_enum_string_helper.h"\n}\n') |
| 3579 | header_txt.append('#define APP_NAME "glvreplay_xgl"') |
| 3580 | header_txt.append('#define IDI_ICON 101\n') |
| 3581 | header_txt.append('static const char* g_extensions[] =') |
| 3582 | header_txt.append('{') |
| 3583 | header_txt.append(' "XGL_WSI_WINDOWS",') |
| 3584 | header_txt.append(' "XGL_TIMER_QUEUE",') |
| 3585 | header_txt.append(' "XGL_GPU_TIMESTAMP_CALIBRATION",') |
| 3586 | header_txt.append(' "XGL_DMA_QUEUE",') |
| 3587 | header_txt.append(' "XGL_COMMAND_BUFFER_CONTROL_FLOW",') |
| 3588 | header_txt.append(' "XGL_COPY_OCCLUSION_QUERY_DATA",') |
| 3589 | header_txt.append(' "XGL_ADVANCED_MULTISAMPLING",') |
| 3590 | header_txt.append(' "XGL_BORDER_COLOR_PALETTE"') |
| 3591 | header_txt.append('};') |
| 3592 | return "\n".join(header_txt) |
| 3593 | |
| 3594 | def generate_body(self): |
| 3595 | body = [self._generate_replay_display_init_xgl(), |
| 3596 | self._generate_replay_display_init(), |
| 3597 | self._generate_replay_display_structors(), |
| 3598 | self._generate_replay_display_window(), |
| 3599 | self._generate_replay_structors(), |
| 3600 | self._generate_replay_init(), |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3601 | self._generate_replay_errors(), |
Jon Ashburn | ce66ab8 | 2014-12-18 17:03:34 -0700 | [diff] [blame] | 3602 | self._generate_replay_validation_funcs(), |
Tobin Ehlis | 5d57bca | 2014-12-15 18:14:12 -0700 | [diff] [blame] | 3603 | self._generate_replay_init_funcs(), |
| 3604 | self._generate_replay()] |
| 3605 | |
| 3606 | return "\n".join(body) |
| 3607 | |
| 3608 | def main(): |
| 3609 | subcommands = { |
| 3610 | "glave-trace-h" : GlaveTraceHeader, |
| 3611 | "glave-trace-c" : GlaveTraceC, |
| 3612 | "glave-packet-id" : GlavePacketID, |
| 3613 | "glave-core-structs" : GlaveCoreStructs, |
| 3614 | "glave-wsi-trace-h" : GlaveWsiHeader, |
| 3615 | "glave-wsi-trace-c" : GlaveWsiC, |
| 3616 | "glave-wsi-trace-structs" : GlaveWsiStructs, |
| 3617 | "glave-dbg-trace-h" : GlaveDbgHeader, |
| 3618 | "glave-dbg-trace-c" : GlaveDbgC, |
| 3619 | "glave-dbg-trace-structs" : GlaveDbgStructs, |
| 3620 | "glave-replay-h" : GlaveReplayHeader, |
| 3621 | "glave-replay-c" : GlaveReplayC, |
| 3622 | } |
| 3623 | |
| 3624 | if len(sys.argv) < 2 or sys.argv[1] not in subcommands: |
| 3625 | print("Usage: %s <subcommand> [options]" % sys.argv[0]) |
| 3626 | print |
| 3627 | print("Available sucommands are: %s" % " ".join(subcommands)) |
| 3628 | exit(1) |
| 3629 | |
| 3630 | subcmd = subcommands[sys.argv[1]](sys.argv[2:]) |
| 3631 | subcmd.run() |
| 3632 | |
| 3633 | if __name__ == "__main__": |
| 3634 | main() |