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