Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [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 | # |
| 25 | # Authors: |
| 26 | # Chia-I Wu <olv@lunarg.com> |
| 27 | |
| 28 | import sys |
| 29 | |
| 30 | import xgl |
| 31 | |
| 32 | class Subcommand(object): |
| 33 | def __init__(self, argv): |
| 34 | self.argv = argv |
Chia-I Wu | ec30dcb | 2015-01-01 08:46:31 +0800 | [diff] [blame] | 35 | self.headers = xgl.headers |
| 36 | self.protos = xgl.protos |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 37 | |
| 38 | def run(self): |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 39 | print(self.generate()) |
| 40 | |
| 41 | def generate(self): |
| 42 | copyright = self.generate_copyright() |
| 43 | header = self.generate_header() |
| 44 | body = self.generate_body() |
| 45 | footer = self.generate_footer() |
| 46 | |
| 47 | contents = [] |
| 48 | if copyright: |
| 49 | contents.append(copyright) |
| 50 | if header: |
| 51 | contents.append(header) |
| 52 | if body: |
| 53 | contents.append(body) |
| 54 | if footer: |
| 55 | contents.append(footer) |
| 56 | |
| 57 | return "\n\n".join(contents) |
| 58 | |
| 59 | def generate_copyright(self): |
| 60 | return """/* THIS FILE IS GENERATED. DO NOT EDIT. */ |
| 61 | |
| 62 | /* |
| 63 | * XGL |
| 64 | * |
| 65 | * Copyright (C) 2014 LunarG, Inc. |
| 66 | * |
| 67 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 68 | * copy of this software and associated documentation files (the "Software"), |
| 69 | * to deal in the Software without restriction, including without limitation |
| 70 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 71 | * and/or sell copies of the Software, and to permit persons to whom the |
| 72 | * Software is furnished to do so, subject to the following conditions: |
| 73 | * |
| 74 | * The above copyright notice and this permission notice shall be included |
| 75 | * in all copies or substantial portions of the Software. |
| 76 | * |
| 77 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 78 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 79 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 80 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 81 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 82 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 83 | * DEALINGS IN THE SOFTWARE. |
| 84 | */""" |
| 85 | |
| 86 | def generate_header(self): |
| 87 | return "\n".join(["#include <" + h + ">" for h in self.headers]) |
| 88 | |
| 89 | def generate_body(self): |
| 90 | pass |
| 91 | |
| 92 | def generate_footer(self): |
| 93 | pass |
| 94 | |
| 95 | # Return set of printf '%' qualifier and input to that qualifier |
Tobin Ehlis | 434db7c | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 96 | def _get_printf_params(self, xgl_type, name, output_param, cpp=False): |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 97 | # TODO : Need ENUM and STRUCT checks here |
| 98 | if "_TYPE" in xgl_type: # TODO : This should be generic ENUM check |
| 99 | return ("%s", "string_%s(%s)" % (xgl_type.strip('const ').strip('*'), name)) |
| 100 | if "XGL_CHAR*" == xgl_type: |
| 101 | return ("%s", name) |
| 102 | if "UINT64" in xgl_type: |
| 103 | if '*' in xgl_type: |
| 104 | return ("%lu", "*%s" % name) |
| 105 | return ("%lu", name) |
Chia-I Wu | 54ed079 | 2014-12-27 14:14:50 +0800 | [diff] [blame] | 106 | if "SIZE" in xgl_type: |
| 107 | if '*' in xgl_type: |
| 108 | return ("%zu", "*%s" % name) |
| 109 | return ("%zu", name) |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 110 | if "FLOAT" in xgl_type: |
| 111 | if '[' in xgl_type: # handle array, current hard-coded to 4 (TODO: Make this dynamic) |
Tobin Ehlis | 434db7c | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 112 | if cpp: |
| 113 | return ("[%i, %i, %i, %i]", '"[" << %s[0] << "," << %s[1] << "," << %s[2] << "," << %s[3] << "]"' % (name, name, name, name)) |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 114 | return ("[%f, %f, %f, %f]", "%s[0], %s[1], %s[2], %s[3]" % (name, name, name, name)) |
| 115 | return ("%f", name) |
Tobin Ehlis | 0a1e06d | 2014-11-11 17:28:22 -0700 | [diff] [blame] | 116 | if "BOOL" in xgl_type or 'xcb_randr_crtc_t' in xgl_type: |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 117 | return ("%u", name) |
Chia-I Wu | 54ed079 | 2014-12-27 14:14:50 +0800 | [diff] [blame] | 118 | if True in [t in xgl_type for t in ["INT", "FLAGS", "MASK", "xcb_window_t"]]: |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 119 | if '[' in xgl_type: # handle array, current hard-coded to 4 (TODO: Make this dynamic) |
Tobin Ehlis | 434db7c | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 120 | if cpp: |
| 121 | return ("[%i, %i, %i, %i]", "%s[0] << %s[1] << %s[2] << %s[3]" % (name, name, name, name)) |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 122 | return ("[%i, %i, %i, %i]", "%s[0], %s[1], %s[2], %s[3]" % (name, name, name, name)) |
| 123 | if '*' in xgl_type: |
Jon Ashburn | 1f7e2d7 | 2014-12-12 16:10:45 -0700 | [diff] [blame] | 124 | return ("%i", "*(%s)" % name) |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 125 | return ("%i", name) |
Tobin Ehlis | 0a1e06d | 2014-11-11 17:28:22 -0700 | [diff] [blame] | 126 | # TODO : This is special-cased as there's only one "format" param currently and it's nice to expand it |
Jon Ashburn | 1f7e2d7 | 2014-12-12 16:10:45 -0700 | [diff] [blame] | 127 | if "XGL_FORMAT" == xgl_type: |
Tobin Ehlis | 434db7c | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 128 | if cpp: |
| 129 | return ("%p", "&%s" % name) |
| 130 | return ("{%s.channelFormat = %%s, %s.numericFormat = %%s}" % (name, name), "string_XGL_CHANNEL_FORMAT(%s.channelFormat), string_XGL_NUM_FORMAT(%s.numericFormat)" % (name, name)) |
Tobin Ehlis | a554dc3 | 2014-11-19 15:52:46 -0700 | [diff] [blame] | 131 | if output_param: |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 132 | return ("%p", "(void*)*%s" % name) |
Jon Ashburn | 1f7e2d7 | 2014-12-12 16:10:45 -0700 | [diff] [blame] | 133 | return ("%p", "(void*)(%s)" % name) |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 134 | |
Tobin Ehlis | c54139f | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 135 | def _gen_layer_dbg_callback_header(self): |
| 136 | cbh_body = [] |
| 137 | cbh_body.append('static XGL_LAYER_DBG_FUNCTION_NODE *pDbgFunctionHead = NULL;') |
| 138 | cbh_body.append('// Utility function to handle reporting') |
| 139 | cbh_body.append('// If callbacks are enabled, use them, otherwise use printf') |
| 140 | cbh_body.append('static XGL_VOID layerCbMsg(XGL_DBG_MSG_TYPE msgType,') |
| 141 | cbh_body.append(' XGL_VALIDATION_LEVEL validationLevel,') |
| 142 | cbh_body.append(' XGL_BASE_OBJECT srcObject,') |
| 143 | cbh_body.append(' XGL_SIZE location,') |
| 144 | cbh_body.append(' XGL_INT msgCode,') |
| 145 | cbh_body.append(' const XGL_CHAR* pLayerPrefix,') |
| 146 | cbh_body.append(' const XGL_CHAR* pMsg)') |
| 147 | cbh_body.append('{') |
| 148 | cbh_body.append(' XGL_LAYER_DBG_FUNCTION_NODE *pTrav = pDbgFunctionHead;') |
| 149 | cbh_body.append(' if (pTrav) {') |
| 150 | cbh_body.append(' while (pTrav) {') |
| 151 | cbh_body.append(' pTrav->pfnMsgCallback(msgType, validationLevel, srcObject, location, msgCode, pMsg, pTrav->pUserData);') |
| 152 | cbh_body.append(' pTrav = pTrav->pNext;') |
| 153 | cbh_body.append(' }') |
| 154 | cbh_body.append(' }') |
| 155 | cbh_body.append(' else {') |
| 156 | cbh_body.append(' switch (msgType) {') |
| 157 | cbh_body.append(' case XGL_DBG_MSG_ERROR:') |
| 158 | cbh_body.append(' printf("{%s}ERROR : %s\\n", pLayerPrefix, pMsg);') |
| 159 | cbh_body.append(' break;') |
| 160 | cbh_body.append(' case XGL_DBG_MSG_WARNING:') |
| 161 | cbh_body.append(' printf("{%s}WARN : %s\\n", pLayerPrefix, pMsg);') |
| 162 | cbh_body.append(' break;') |
| 163 | cbh_body.append(' case XGL_DBG_MSG_PERF_WARNING:') |
| 164 | cbh_body.append(' printf("{%s}PERF_WARN : %s\\n", pLayerPrefix, pMsg);') |
| 165 | cbh_body.append(' break;') |
| 166 | cbh_body.append(' default:') |
| 167 | cbh_body.append(' printf("{%s}INFO : %s\\n", pLayerPrefix, pMsg);') |
| 168 | cbh_body.append(' break;') |
| 169 | cbh_body.append(' }') |
| 170 | cbh_body.append(' }') |
| 171 | cbh_body.append('}') |
| 172 | return "\n".join(cbh_body) |
| 173 | |
| 174 | def _gen_layer_dbg_callback_register(self): |
| 175 | r_body = [] |
| 176 | r_body.append('XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglDbgRegisterMsgCallback(XGL_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback, XGL_VOID* pUserData)') |
| 177 | r_body.append('{') |
| 178 | r_body.append(' // This layer intercepts callbacks') |
| 179 | r_body.append(' XGL_LAYER_DBG_FUNCTION_NODE *pNewDbgFuncNode = (XGL_LAYER_DBG_FUNCTION_NODE*)malloc(sizeof(XGL_LAYER_DBG_FUNCTION_NODE));') |
| 180 | r_body.append(' if (!pNewDbgFuncNode)') |
| 181 | r_body.append(' return XGL_ERROR_OUT_OF_MEMORY;') |
| 182 | r_body.append(' pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;') |
| 183 | r_body.append(' pNewDbgFuncNode->pUserData = pUserData;') |
| 184 | r_body.append(' pNewDbgFuncNode->pNext = pDbgFunctionHead;') |
| 185 | r_body.append(' pDbgFunctionHead = pNewDbgFuncNode;') |
| 186 | r_body.append(' XGL_RESULT result = nextTable.DbgRegisterMsgCallback(pfnMsgCallback, pUserData);') |
| 187 | r_body.append(' return result;') |
| 188 | r_body.append('}') |
| 189 | return "\n".join(r_body) |
| 190 | |
| 191 | def _gen_layer_dbg_callback_unregister(self): |
| 192 | ur_body = [] |
| 193 | ur_body.append('XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglDbgUnregisterMsgCallback(XGL_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback)') |
| 194 | ur_body.append('{') |
| 195 | ur_body.append(' XGL_LAYER_DBG_FUNCTION_NODE *pTrav = pDbgFunctionHead;') |
| 196 | ur_body.append(' XGL_LAYER_DBG_FUNCTION_NODE *pPrev = pTrav;') |
| 197 | ur_body.append(' while (pTrav) {') |
| 198 | ur_body.append(' if (pTrav->pfnMsgCallback == pfnMsgCallback) {') |
| 199 | ur_body.append(' pPrev->pNext = pTrav->pNext;') |
| 200 | ur_body.append(' if (pDbgFunctionHead == pTrav)') |
| 201 | ur_body.append(' pDbgFunctionHead = pTrav->pNext;') |
| 202 | ur_body.append(' free(pTrav);') |
| 203 | ur_body.append(' break;') |
| 204 | ur_body.append(' }') |
| 205 | ur_body.append(' pPrev = pTrav;') |
| 206 | ur_body.append(' pTrav = pTrav->pNext;') |
| 207 | ur_body.append(' }') |
| 208 | ur_body.append(' XGL_RESULT result = nextTable.DbgUnregisterMsgCallback(pfnMsgCallback);') |
| 209 | ur_body.append(' return result;') |
| 210 | ur_body.append('}') |
| 211 | return "\n".join(ur_body) |
| 212 | |
Tobin Ehlis | 07fe9ab | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 213 | def _generate_dispatch_entrypoints(self, qual="", layer="Generic", no_addr=False): |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 214 | if qual: |
| 215 | qual += " " |
| 216 | |
Tobin Ehlis | 907a052 | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 217 | layer_name = layer |
Tobin Ehlis | 07fe9ab | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 218 | if no_addr: |
| 219 | layer_name = "%sNoAddr" % layer |
Tobin Ehlis | 434db7c | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 220 | if 'Cpp' in layer_name: |
| 221 | layer_name = "APIDumpNoAddrCpp" |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 222 | funcs = [] |
| 223 | for proto in self.protos: |
| 224 | if proto.name != "GetProcAddr" and proto.name != "InitAndEnumerateGpus": |
Tobin Ehlis | 907a052 | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 225 | if "Generic" == layer: |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 226 | decl = proto.c_func(prefix="xgl", attr="XGLAPI") |
| 227 | param0_name = proto.params[0].name |
| 228 | ret_val = '' |
| 229 | stmt = '' |
| 230 | if proto.ret != "XGL_VOID": |
| 231 | ret_val = "XGL_RESULT result = " |
| 232 | stmt = " return result;\n" |
Jon Ashburn | 451c16f | 2014-11-25 11:08:42 -0700 | [diff] [blame] | 233 | if proto.name == "EnumerateLayers": |
| 234 | c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1) |
| 235 | funcs.append('%s%s\n' |
| 236 | '{\n' |
Tobin Ehlis | c54139f | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 237 | ' char str[1024];\n' |
Jon Ashburn | 451c16f | 2014-11-25 11:08:42 -0700 | [diff] [blame] | 238 | ' if (gpu != NULL) {\n' |
| 239 | ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n' |
Tobin Ehlis | c54139f | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 240 | ' sprintf(str, "At start of layered %s\\n");\n' |
Jon Ashburn | 8aa3290 | 2014-12-17 12:08:37 -0700 | [diff] [blame] | 241 | ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpu, 0, 0, (XGL_CHAR *) "GENERIC", (XGL_CHAR *) str);\n' |
Jon Ashburn | 451c16f | 2014-11-25 11:08:42 -0700 | [diff] [blame] | 242 | ' pCurObj = gpuw;\n' |
| 243 | ' pthread_once(&tabOnce, initLayerTable);\n' |
| 244 | ' %snextTable.%s;\n' |
Tobin Ehlis | c54139f | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 245 | ' sprintf(str, "Completed layered %s\\n");\n' |
Jon Ashburn | 8aa3290 | 2014-12-17 12:08:37 -0700 | [diff] [blame] | 246 | ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpu, 0, 0, (XGL_CHAR *) "GENERIC", (XGL_CHAR *) str);\n' |
Jon Ashburn | 451c16f | 2014-11-25 11:08:42 -0700 | [diff] [blame] | 247 | ' fflush(stdout);\n' |
| 248 | ' %s' |
| 249 | ' } else {\n' |
| 250 | ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n' |
| 251 | ' return XGL_ERROR_INVALID_POINTER;\n' |
| 252 | ' // This layer compatible with all GPUs\n' |
| 253 | ' *pOutLayerCount = 1;\n' |
Chia-I Wu | a837c52 | 2014-12-16 10:47:33 +0800 | [diff] [blame] | 254 | ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n' |
Jon Ashburn | 451c16f | 2014-11-25 11:08:42 -0700 | [diff] [blame] | 255 | ' return XGL_SUCCESS;\n' |
| 256 | ' }\n' |
Tobin Ehlis | 07fe9ab | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 257 | '}' % (qual, decl, proto.params[0].name, proto.name, ret_val, c_call, proto.name, stmt, layer_name)) |
Tobin Ehlis | c54139f | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 258 | elif 'DbgRegisterMsgCallback' == proto.name: |
| 259 | funcs.append(self._gen_layer_dbg_callback_register()) |
| 260 | elif 'DbgUnregisterMsgCallback' == proto.name: |
| 261 | funcs.append(self._gen_layer_dbg_callback_unregister()) |
Jon Ashburn | 451c16f | 2014-11-25 11:08:42 -0700 | [diff] [blame] | 262 | elif proto.params[0].ty != "XGL_PHYSICAL_GPU": |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 263 | funcs.append('%s%s\n' |
| 264 | '{\n' |
| 265 | ' %snextTable.%s;\n' |
| 266 | '%s' |
| 267 | '}' % (qual, decl, ret_val, proto.c_call(), stmt)) |
| 268 | else: |
| 269 | c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1) |
| 270 | funcs.append('%s%s\n' |
| 271 | '{\n' |
Tobin Ehlis | c54139f | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 272 | ' char str[1024];' |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 273 | ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n' |
Tobin Ehlis | c54139f | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 274 | ' sprintf(str, "At start of layered %s\\n");\n' |
Jon Ashburn | 8aa3290 | 2014-12-17 12:08:37 -0700 | [diff] [blame] | 275 | ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpuw, 0, 0, (XGL_CHAR *) "GENERIC", (XGL_CHAR *) str);\n' |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 276 | ' pCurObj = gpuw;\n' |
| 277 | ' pthread_once(&tabOnce, initLayerTable);\n' |
| 278 | ' %snextTable.%s;\n' |
Tobin Ehlis | c54139f | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 279 | ' sprintf(str, "Completed layered %s\\n");\n' |
Jon Ashburn | 8aa3290 | 2014-12-17 12:08:37 -0700 | [diff] [blame] | 280 | ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpuw, 0, 0, (XGL_CHAR *) "GENERIC", (XGL_CHAR *) str);\n' |
Courtney Goeltzenleuchter | e6094fc | 2014-11-18 10:40:29 -0700 | [diff] [blame] | 281 | ' fflush(stdout);\n' |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 282 | '%s' |
| 283 | '}' % (qual, decl, proto.params[0].name, proto.name, ret_val, c_call, proto.name, stmt)) |
Tobin Ehlis | 434db7c | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 284 | elif "APIDumpCpp" in layer: |
| 285 | decl = proto.c_func(prefix="xgl", attr="XGLAPI") |
| 286 | param0_name = proto.params[0].name |
| 287 | ret_val = '' |
| 288 | stmt = '' |
| 289 | cis_param_index = [] # Store list of indices when func has struct params |
| 290 | create_params = 0 # Num of params at end of function that are created and returned as output values |
| 291 | if 'WsiX11CreatePresentableImage' in proto.name: |
| 292 | create_params = -2 |
| 293 | elif 'Create' in proto.name or 'Alloc' in proto.name or 'MapMemory' in proto.name: |
| 294 | create_params = -1 |
| 295 | if proto.ret != "XGL_VOID": |
| 296 | ret_val = "XGL_RESULT result = " |
| 297 | stmt = " return result;\n" |
| 298 | f_open = '' |
| 299 | f_close = '' |
| 300 | if "File" in layer: |
| 301 | file_mode = "a" |
| 302 | if 'CreateDevice' in proto.name: |
| 303 | file_mode = "w" |
| 304 | f_open = 'pthread_mutex_lock( &file_lock );\n pOutFile = fopen(outFileName, "%s");\n ' % (file_mode) |
| 305 | log_func = 'fprintf(pOutFile, "t{%%u} xgl%s(' % proto.name |
| 306 | f_close = '\n fclose(pOutFile);\n pthread_mutex_unlock( &file_lock );' |
| 307 | else: |
| 308 | f_open = 'pthread_mutex_lock( &print_lock );\n ' |
| 309 | log_func = 'cout << "t{" << getTIDIndex() << "} xgl%s(' % proto.name |
| 310 | f_close = '\n pthread_mutex_unlock( &print_lock );' |
| 311 | pindex = 0 |
| 312 | for p in proto.params: |
| 313 | # TODO : Need to handle xglWsiX11CreatePresentableImage for which the last 2 params are returned vals |
| 314 | cp = False |
| 315 | if 0 != create_params: |
| 316 | # If this is any of the N last params of the func, treat as output |
| 317 | for y in range(-1, create_params-1, -1): |
| 318 | if p.name == proto.params[y].name: |
| 319 | cp = True |
| 320 | (pft, pfi) = self._get_printf_params(p.ty, p.name, cp, cpp=True) |
| 321 | if no_addr and "%p" == pft: |
| 322 | (pft, pfi) = ("%s", '"addr"') |
| 323 | log_func += '%s = " << %s << ", ' % (p.name, pfi) |
| 324 | #print_vals += ', %s' % (pfi) |
| 325 | # TODO : Just want this to be simple check for params of STRUCT type |
| 326 | if "pCreateInfo" in p.name or ('const' in p.ty and '*' in p.ty and False not in [tmp_ty not in p.ty for tmp_ty in ['XGL_CHAR', 'XGL_VOID', 'XGL_CMD_BUFFER', 'XGL_QUEUE_SEMAPHORE', 'XGL_FENCE', 'XGL_SAMPLER', 'XGL_UINT32']]): |
| 327 | if 'Wsi' not in proto.name: |
| 328 | cis_param_index.append(pindex) |
| 329 | pindex += 1 |
| 330 | log_func = log_func.strip(', ') |
| 331 | if proto.ret != "XGL_VOID": |
| 332 | log_func += ') = " << string_XGL_RESULT(result) << "\\n"' |
| 333 | #print_vals += ', string_XGL_RESULT(result)' |
| 334 | else: |
| 335 | log_func += ')\\n"' |
| 336 | log_func += ';' |
| 337 | if len(cis_param_index) > 0: |
| 338 | log_func += '\n string tmp_str;' |
| 339 | for sp_index in cis_param_index: |
| 340 | cis_print_func = 'xgl_print_%s' % (proto.params[sp_index].ty.strip('const ').strip('*').lower()) |
| 341 | log_func += '\n if (%s) {' % (proto.params[sp_index].name) |
| 342 | log_func += '\n tmp_str = %s(%s, " ");' % (cis_print_func, proto.params[sp_index].name) |
| 343 | if "File" in layer: |
| 344 | if no_addr: |
| 345 | log_func += '\n fprintf(pOutFile, " %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name) |
| 346 | else: |
| 347 | log_func += '\n fprintf(pOutFile, " %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name) |
| 348 | else: |
| 349 | if no_addr: |
| 350 | #log_func += '\n printf(" %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name) |
| 351 | log_func += '\n cout << " %s (addr)" << endl << tmp_str << endl;' % (proto.params[sp_index].name) |
| 352 | else: |
| 353 | #log_func += '\n printf(" %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name) |
| 354 | log_func += '\n cout << " %s (" << %s << ")" << endl << tmp_str << endl;' % (proto.params[sp_index].name, proto.params[sp_index].name) |
| 355 | #log_func += '\n fflush(stdout);' |
| 356 | log_func += '\n }' |
| 357 | if proto.name == "EnumerateLayers": |
| 358 | c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1) |
| 359 | funcs.append('%s%s\n' |
| 360 | '{\n' |
| 361 | ' if (gpu != NULL) {\n' |
| 362 | ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n' |
| 363 | ' pCurObj = gpuw;\n' |
| 364 | ' pthread_once(&tabOnce, initLayerTable);\n' |
| 365 | ' %snextTable.%s;\n' |
| 366 | ' %s %s %s\n' |
| 367 | ' %s' |
| 368 | ' } else {\n' |
| 369 | ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n' |
| 370 | ' return XGL_ERROR_INVALID_POINTER;\n' |
| 371 | ' // This layer compatible with all GPUs\n' |
| 372 | ' *pOutLayerCount = 1;\n' |
| 373 | ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n' |
| 374 | ' return XGL_SUCCESS;\n' |
| 375 | ' }\n' |
| 376 | '}' % (qual, decl, proto.params[0].name, ret_val, c_call,f_open, log_func, f_close, stmt, layer_name)) |
| 377 | elif proto.params[0].ty != "XGL_PHYSICAL_GPU": |
| 378 | funcs.append('%s%s\n' |
| 379 | '{\n' |
| 380 | ' %snextTable.%s;\n' |
| 381 | ' %s%s%s\n' |
| 382 | '%s' |
| 383 | '}' % (qual, decl, ret_val, proto.c_call(), f_open, log_func, f_close, stmt)) |
| 384 | else: |
| 385 | c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1) |
| 386 | funcs.append('%s%s\n' |
| 387 | '{\n' |
| 388 | ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n' |
| 389 | ' pCurObj = gpuw;\n' |
| 390 | ' pthread_once(&tabOnce, initLayerTable);\n' |
| 391 | ' %snextTable.%s;\n' |
| 392 | ' %s%s%s\n' |
| 393 | '%s' |
| 394 | '}' % (qual, decl, proto.params[0].name, ret_val, c_call, f_open, log_func, f_close, stmt)) |
Tobin Ehlis | 907a052 | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 395 | elif "APIDump" in layer: |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 396 | decl = proto.c_func(prefix="xgl", attr="XGLAPI") |
| 397 | param0_name = proto.params[0].name |
| 398 | ret_val = '' |
| 399 | stmt = '' |
Tobin Ehlis | 73ff567 | 2014-10-23 08:19:47 -0600 | [diff] [blame] | 400 | cis_param_index = [] # Store list of indices when func has struct params |
Tobin Ehlis | a554dc3 | 2014-11-19 15:52:46 -0700 | [diff] [blame] | 401 | create_params = 0 # Num of params at end of function that are created and returned as output values |
| 402 | if 'WsiX11CreatePresentableImage' in proto.name: |
| 403 | create_params = -2 |
| 404 | elif 'Create' in proto.name or 'Alloc' in proto.name or 'MapMemory' in proto.name: |
| 405 | create_params = -1 |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 406 | if proto.ret != "XGL_VOID": |
| 407 | ret_val = "XGL_RESULT result = " |
| 408 | stmt = " return result;\n" |
Tobin Ehlis | 574b014 | 2014-11-12 13:11:15 -0700 | [diff] [blame] | 409 | f_open = '' |
| 410 | f_close = '' |
Tobin Ehlis | 907a052 | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 411 | if "File" in layer: |
Tobin Ehlis | 1eba779 | 2014-11-21 09:35:53 -0700 | [diff] [blame] | 412 | file_mode = "a" |
| 413 | if 'CreateDevice' in proto.name: |
| 414 | file_mode = "w" |
Chia-I Wu | 81f4667 | 2014-12-16 00:36:58 +0800 | [diff] [blame] | 415 | f_open = 'pthread_mutex_lock( &file_lock );\n pOutFile = fopen(outFileName, "%s");\n ' % (file_mode) |
Tobin Ehlis | 0c68c9c | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 416 | log_func = 'fprintf(pOutFile, "t{%%u} xgl%s(' % proto.name |
Tobin Ehlis | 1aa7d3e | 2014-11-20 12:18:45 -0700 | [diff] [blame] | 417 | f_close = '\n fclose(pOutFile);\n pthread_mutex_unlock( &file_lock );' |
Tobin Ehlis | 574b014 | 2014-11-12 13:11:15 -0700 | [diff] [blame] | 418 | else: |
Chia-I Wu | 81f4667 | 2014-12-16 00:36:58 +0800 | [diff] [blame] | 419 | f_open = 'pthread_mutex_lock( &print_lock );\n ' |
Tobin Ehlis | 0c68c9c | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 420 | log_func = 'printf("t{%%u} xgl%s(' % proto.name |
Tobin Ehlis | 1aa7d3e | 2014-11-20 12:18:45 -0700 | [diff] [blame] | 421 | f_close = '\n pthread_mutex_unlock( &print_lock );' |
Tobin Ehlis | 0c68c9c | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 422 | print_vals = ', getTIDIndex()' |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 423 | pindex = 0 |
| 424 | for p in proto.params: |
Tobin Ehlis | a554dc3 | 2014-11-19 15:52:46 -0700 | [diff] [blame] | 425 | # TODO : Need to handle xglWsiX11CreatePresentableImage for which the last 2 params are returned vals |
| 426 | cp = False |
| 427 | if 0 != create_params: |
| 428 | # If this is any of the N last params of the func, treat as output |
| 429 | for y in range(-1, create_params-1, -1): |
| 430 | if p.name == proto.params[y].name: |
| 431 | cp = True |
| 432 | (pft, pfi) = self._get_printf_params(p.ty, p.name, cp) |
Tobin Ehlis | 07fe9ab | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 433 | if no_addr and "%p" == pft: |
| 434 | (pft, pfi) = ("%s", '"addr"') |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 435 | log_func += '%s = %s, ' % (p.name, pft) |
| 436 | print_vals += ', %s' % (pfi) |
Tobin Ehlis | 73ff567 | 2014-10-23 08:19:47 -0600 | [diff] [blame] | 437 | # TODO : Just want this to be simple check for params of STRUCT type |
| 438 | if "pCreateInfo" in p.name or ('const' in p.ty and '*' in p.ty and False not in [tmp_ty not in p.ty for tmp_ty in ['XGL_CHAR', 'XGL_VOID', 'XGL_CMD_BUFFER', 'XGL_QUEUE_SEMAPHORE', 'XGL_FENCE', 'XGL_SAMPLER', 'XGL_UINT32']]): |
Tobin Ehlis | 0a1e06d | 2014-11-11 17:28:22 -0700 | [diff] [blame] | 439 | if 'Wsi' not in proto.name: |
| 440 | cis_param_index.append(pindex) |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 441 | pindex += 1 |
| 442 | log_func = log_func.strip(', ') |
| 443 | if proto.ret != "XGL_VOID": |
| 444 | log_func += ') = %s\\n"' |
Courtney Goeltzenleuchter | e6094fc | 2014-11-18 10:40:29 -0700 | [diff] [blame] | 445 | print_vals += ', string_XGL_RESULT(result)' |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 446 | else: |
| 447 | log_func += ')\\n"' |
| 448 | log_func = '%s%s);' % (log_func, print_vals) |
Tobin Ehlis | 73ff567 | 2014-10-23 08:19:47 -0600 | [diff] [blame] | 449 | if len(cis_param_index) > 0: |
| 450 | log_func += '\n char *pTmpStr;' |
| 451 | for sp_index in cis_param_index: |
| 452 | cis_print_func = 'xgl_print_%s' % (proto.params[sp_index].ty.strip('const ').strip('*').lower()) |
| 453 | log_func += '\n if (%s) {' % (proto.params[sp_index].name) |
| 454 | log_func += '\n pTmpStr = %s(%s, " ");' % (cis_print_func, proto.params[sp_index].name) |
Tobin Ehlis | 07fe9ab | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 455 | if "File" in layer: |
| 456 | if no_addr: |
| 457 | log_func += '\n fprintf(pOutFile, " %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name) |
| 458 | else: |
| 459 | log_func += '\n fprintf(pOutFile, " %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name) |
Tobin Ehlis | 574b014 | 2014-11-12 13:11:15 -0700 | [diff] [blame] | 460 | else: |
Tobin Ehlis | 07fe9ab | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 461 | if no_addr: |
| 462 | log_func += '\n printf(" %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name) |
| 463 | else: |
| 464 | log_func += '\n printf(" %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name) |
Tobin Ehlis | 0c68c9c | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 465 | log_func += '\n fflush(stdout);' |
Tobin Ehlis | 73ff567 | 2014-10-23 08:19:47 -0600 | [diff] [blame] | 466 | log_func += '\n free(pTmpStr);\n }' |
Jon Ashburn | 451c16f | 2014-11-25 11:08:42 -0700 | [diff] [blame] | 467 | if proto.name == "EnumerateLayers": |
| 468 | c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1) |
| 469 | funcs.append('%s%s\n' |
| 470 | '{\n' |
| 471 | ' if (gpu != NULL) {\n' |
| 472 | ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n' |
| 473 | ' pCurObj = gpuw;\n' |
| 474 | ' pthread_once(&tabOnce, initLayerTable);\n' |
| 475 | ' %snextTable.%s;\n' |
| 476 | ' %s %s %s\n' |
| 477 | ' %s' |
| 478 | ' } else {\n' |
| 479 | ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n' |
| 480 | ' return XGL_ERROR_INVALID_POINTER;\n' |
| 481 | ' // This layer compatible with all GPUs\n' |
| 482 | ' *pOutLayerCount = 1;\n' |
Chia-I Wu | a837c52 | 2014-12-16 10:47:33 +0800 | [diff] [blame] | 483 | ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n' |
Jon Ashburn | 451c16f | 2014-11-25 11:08:42 -0700 | [diff] [blame] | 484 | ' return XGL_SUCCESS;\n' |
| 485 | ' }\n' |
Tobin Ehlis | 07fe9ab | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 486 | '}' % (qual, decl, proto.params[0].name, ret_val, c_call,f_open, log_func, f_close, stmt, layer_name)) |
Jon Ashburn | 451c16f | 2014-11-25 11:08:42 -0700 | [diff] [blame] | 487 | elif proto.params[0].ty != "XGL_PHYSICAL_GPU": |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 488 | funcs.append('%s%s\n' |
| 489 | '{\n' |
| 490 | ' %snextTable.%s;\n' |
Tobin Ehlis | 574b014 | 2014-11-12 13:11:15 -0700 | [diff] [blame] | 491 | ' %s%s%s\n' |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 492 | '%s' |
Tobin Ehlis | 574b014 | 2014-11-12 13:11:15 -0700 | [diff] [blame] | 493 | '}' % (qual, decl, ret_val, proto.c_call(), f_open, log_func, f_close, stmt)) |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 494 | else: |
| 495 | c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1) |
| 496 | funcs.append('%s%s\n' |
| 497 | '{\n' |
| 498 | ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n' |
| 499 | ' pCurObj = gpuw;\n' |
| 500 | ' pthread_once(&tabOnce, initLayerTable);\n' |
| 501 | ' %snextTable.%s;\n' |
Tobin Ehlis | 574b014 | 2014-11-12 13:11:15 -0700 | [diff] [blame] | 502 | ' %s%s%s\n' |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 503 | '%s' |
Tobin Ehlis | 574b014 | 2014-11-12 13:11:15 -0700 | [diff] [blame] | 504 | '}' % (qual, decl, proto.params[0].name, ret_val, c_call, f_open, log_func, f_close, stmt)) |
Tobin Ehlis | 907a052 | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 505 | elif "ObjectTracker" == layer: |
Chia-I Wu | df2efbd | 2015-01-05 14:37:39 +0800 | [diff] [blame] | 506 | obj_type_mapping = { |
| 507 | "XGL_PHYSICAL_GPU" : "XGL_OBJECT_TYPE_PHYSICAL_GPU", |
| 508 | "XGL_DEVICE" : "XGL_OBJECT_TYPE_DEVICE", |
| 509 | "XGL_QUEUE" : "XGL_OBJECT_TYPE_QUEUE", |
| 510 | "XGL_QUEUE_SEMAPHORE" : "XGL_OBJECT_TYPE_QUEUE_SEMAPHORE", |
| 511 | "XGL_GPU_MEMORY" : "XGL_OBJECT_TYPE_GPU_MEMORY", |
| 512 | "XGL_FENCE" : "XGL_OBJECT_TYPE_FENCE", |
| 513 | "XGL_QUERY_POOL" : "XGL_OBJECT_TYPE_QUERY_POOL", |
| 514 | "XGL_EVENT" : "XGL_OBJECT_TYPE_EVENT", |
| 515 | "XGL_IMAGE" : "XGL_OBJECT_TYPE_IMAGE", |
| 516 | "XGL_DESCRIPTOR_SET" : "XGL_OBJECT_TYPE_DESCRIPTOR_SET", |
| 517 | "XGL_CMD_BUFFER" : "XGL_OBJECT_TYPE_CMD_BUFFER", |
| 518 | "XGL_SAMPLER" : "XGL_OBJECT_TYPE_SAMPLER", |
| 519 | "XGL_PIPELINE" : "XGL_OBJECT_TYPE_PIPELINE", |
| 520 | "XGL_PIPELINE_DELTA" : "XGL_OBJECT_TYPE_PIPELINE_DELTA", |
| 521 | "XGL_SHADER" : "XGL_OBJECT_TYPE_SHADER", |
| 522 | "XGL_IMAGE_VIEW" : "XGL_OBJECT_TYPE_IMAGE_VIEW", |
| 523 | "XGL_COLOR_ATTACHMENT_VIEW" : "XGL_OBJECT_TYPE_COLOR_ATTACHMENT_VIEW", |
| 524 | "XGL_DEPTH_STENCIL_VIEW" : "XGL_OBJECT_TYPE_DEPTH_STENCIL_VIEW", |
| 525 | "XGL_VIEWPORT_STATE_OBJECT" : "XGL_OBJECT_TYPE_VIEWPORT_STATE", |
| 526 | "XGL_RASTER_STATE_OBJECT" : "XGL_OBJECT_TYPE_RASTER_STATE", |
| 527 | "XGL_MSAA_STATE_OBJECT" : "XGL_OBJECT_TYPE_MSAA_STATE", |
| 528 | "XGL_COLOR_BLEND_STATE_OBJECT" : "XGL_OBJECT_TYPE_COLOR_BLEND_STATE", |
| 529 | "XGL_DEPTH_STENCIL_STATE_OBJECT" : "XGL_OBJECT_TYPE_DEPTH_STENCIL_STATE", |
| 530 | "XGL_BASE_OBJECT" : "ll_get_obj_type(object)", |
| 531 | "XGL_OBJECT" : "ll_get_obj_type(object)" |
| 532 | } |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 533 | |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 534 | decl = proto.c_func(prefix="xgl", attr="XGLAPI") |
| 535 | param0_name = proto.params[0].name |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 536 | p0_type = proto.params[0].ty |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 537 | create_line = '' |
| 538 | destroy_line = '' |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 539 | if 'DbgRegisterMsgCallback' in proto.name: |
| 540 | using_line = ' // This layer intercepts callbacks\n' |
| 541 | using_line += ' XGL_LAYER_DBG_FUNCTION_NODE *pNewDbgFuncNode = (XGL_LAYER_DBG_FUNCTION_NODE*)malloc(sizeof(XGL_LAYER_DBG_FUNCTION_NODE));\n' |
| 542 | using_line += ' if (!pNewDbgFuncNode)\n' |
| 543 | using_line += ' return XGL_ERROR_OUT_OF_MEMORY;\n' |
| 544 | using_line += ' pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;\n' |
| 545 | using_line += ' pNewDbgFuncNode->pUserData = pUserData;\n' |
| 546 | using_line += ' pNewDbgFuncNode->pNext = pDbgFunctionHead;\n' |
| 547 | using_line += ' pDbgFunctionHead = pNewDbgFuncNode;\n' |
| 548 | elif 'DbgUnregisterMsgCallback' in proto.name: |
| 549 | using_line = ' XGL_LAYER_DBG_FUNCTION_NODE *pTrav = pDbgFunctionHead;\n' |
| 550 | using_line += ' XGL_LAYER_DBG_FUNCTION_NODE *pPrev = pTrav;\n' |
| 551 | using_line += ' while (pTrav) {\n' |
| 552 | using_line += ' if (pTrav->pfnMsgCallback == pfnMsgCallback) {\n' |
| 553 | using_line += ' pPrev->pNext = pTrav->pNext;\n' |
| 554 | using_line += ' if (pDbgFunctionHead == pTrav)\n' |
| 555 | using_line += ' pDbgFunctionHead = pTrav->pNext;\n' |
| 556 | using_line += ' free(pTrav);\n' |
| 557 | using_line += ' break;\n' |
| 558 | using_line += ' }\n' |
| 559 | using_line += ' pPrev = pTrav;\n' |
| 560 | using_line += ' pTrav = pTrav->pNext;\n' |
| 561 | using_line += ' }\n' |
| 562 | elif 'GlobalOption' in proto.name: |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 563 | using_line = '' |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 564 | else: |
| 565 | using_line = ' ll_increment_use_count((XGL_VOID*)%s, %s);\n' % (param0_name, obj_type_mapping[p0_type]) |
| 566 | if 'Create' in proto.name or 'Alloc' in proto.name: |
| 567 | create_line = ' ll_insert_obj((XGL_VOID*)*%s, %s);\n' % (proto.params[-1].name, obj_type_mapping[proto.params[-1].ty.strip('*')]) |
| 568 | if 'DestroyObject' in proto.name: |
| 569 | destroy_line = ' ll_destroy_obj((XGL_VOID*)%s);\n' % (param0_name) |
| 570 | using_line = '' |
| 571 | else: |
| 572 | if 'Destroy' in proto.name or 'Free' in proto.name: |
| 573 | destroy_line = ' ll_remove_obj_type((XGL_VOID*)%s, %s);\n' % (param0_name, obj_type_mapping[p0_type]) |
| 574 | using_line = '' |
| 575 | if 'DestroyDevice' in proto.name: |
| 576 | destroy_line += ' // Report any remaining objects in LL\n objNode *pTrav = pGlobalHead;\n while (pTrav) {\n' |
| 577 | destroy_line += ' char str[1024];\n' |
| 578 | destroy_line += ' sprintf(str, "OBJ ERROR : %s object %p has not been destroyed (was used %lu times).", string_XGL_OBJECT_TYPE(pTrav->obj.objType), pTrav->obj.pObj, pTrav->obj.numUses);\n' |
| 579 | destroy_line += ' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, device, 0, OBJTRACK_OBJECT_LEAK, "OBJTRACK", str);\n' |
| 580 | destroy_line += ' pTrav = pTrav->pNextGlobal;\n }\n' |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 581 | ret_val = '' |
| 582 | stmt = '' |
| 583 | if proto.ret != "XGL_VOID": |
| 584 | ret_val = "XGL_RESULT result = " |
| 585 | stmt = " return result;\n" |
Jon Ashburn | 451c16f | 2014-11-25 11:08:42 -0700 | [diff] [blame] | 586 | if proto.name == "EnumerateLayers": |
| 587 | c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1) |
| 588 | funcs.append('%s%s\n' |
| 589 | '{\n' |
| 590 | ' if (gpu != NULL) {\n' |
| 591 | ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n' |
| 592 | ' %s' |
| 593 | ' pCurObj = gpuw;\n' |
| 594 | ' pthread_once(&tabOnce, initLayerTable);\n' |
| 595 | ' %snextTable.%s;\n' |
| 596 | ' %s%s' |
| 597 | ' %s' |
| 598 | ' } else {\n' |
| 599 | ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n' |
| 600 | ' return XGL_ERROR_INVALID_POINTER;\n' |
| 601 | ' // This layer compatible with all GPUs\n' |
| 602 | ' *pOutLayerCount = 1;\n' |
Chia-I Wu | a837c52 | 2014-12-16 10:47:33 +0800 | [diff] [blame] | 603 | ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n' |
Jon Ashburn | 451c16f | 2014-11-25 11:08:42 -0700 | [diff] [blame] | 604 | ' return XGL_SUCCESS;\n' |
| 605 | ' }\n' |
Tobin Ehlis | 07fe9ab | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 606 | '}' % (qual, decl, proto.params[0].name, using_line, ret_val, c_call, create_line, destroy_line, stmt, layer_name)) |
Jon Ashburn | 451c16f | 2014-11-25 11:08:42 -0700 | [diff] [blame] | 607 | elif proto.params[0].ty != "XGL_PHYSICAL_GPU": |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 608 | funcs.append('%s%s\n' |
| 609 | '{\n' |
| 610 | '%s' |
| 611 | ' %snextTable.%s;\n' |
| 612 | '%s%s' |
| 613 | '%s' |
| 614 | '}' % (qual, decl, using_line, ret_val, proto.c_call(), create_line, destroy_line, stmt)) |
| 615 | else: |
| 616 | c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1) |
| 617 | funcs.append('%s%s\n' |
| 618 | '{\n' |
| 619 | ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n' |
| 620 | '%s' |
| 621 | ' pCurObj = gpuw;\n' |
| 622 | ' pthread_once(&tabOnce, initLayerTable);\n' |
| 623 | ' %snextTable.%s;\n' |
| 624 | '%s%s' |
| 625 | '%s' |
| 626 | '}' % (qual, decl, proto.params[0].name, using_line, ret_val, c_call, create_line, destroy_line, stmt)) |
| 627 | |
| 628 | # TODO : Put this code somewhere so it gets called at the end if objects not deleted : |
| 629 | # // Report any remaining objects in LL |
| 630 | # objNode *pTrav = pObjLLHead; |
| 631 | # while (pTrav) { |
| 632 | # printf("WARN : %s object %p has not been destroyed.\n", pTrav->objType, pTrav->pObj); |
| 633 | # } |
| 634 | |
| 635 | return "\n\n".join(funcs) |
| 636 | |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 637 | def _generate_extensions(self): |
| 638 | exts = [] |
| 639 | exts.append('XGL_UINT64 objTrackGetObjectCount(XGL_OBJECT_TYPE type)') |
| 640 | exts.append('{') |
| 641 | exts.append(' return (type == XGL_OBJECT_TYPE_ANY) ? numTotalObjs : numObjs[type];') |
| 642 | exts.append('}') |
| 643 | exts.append('') |
| 644 | exts.append('XGL_RESULT objTrackGetObjects(XGL_OBJECT_TYPE type, XGL_UINT64 objCount, OBJTRACK_NODE* pObjNodeArray)') |
| 645 | exts.append('{') |
| 646 | exts.append(" // This bool flags if we're pulling all objs or just a single class of objs") |
| 647 | exts.append(' XGL_BOOL bAllObjs = (type == XGL_OBJECT_TYPE_ANY);') |
| 648 | exts.append(' // Check the count first thing') |
| 649 | exts.append(' XGL_UINT64 maxObjCount = (bAllObjs) ? numTotalObjs : numObjs[type];') |
| 650 | exts.append(' if (objCount > maxObjCount) {') |
| 651 | exts.append(' char str[1024];') |
| 652 | exts.append(' sprintf(str, "OBJ ERROR : Received objTrackGetObjects() request for %lu objs, but there are only %lu objs of type %s", objCount, maxObjCount, string_XGL_OBJECT_TYPE(type));') |
| 653 | exts.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, 0, 0, OBJTRACK_OBJCOUNT_MAX_EXCEEDED, "OBJTRACK", str);') |
| 654 | exts.append(' return XGL_ERROR_INVALID_VALUE;') |
| 655 | exts.append(' }') |
| 656 | exts.append(' objNode* pTrav = (bAllObjs) ? pGlobalHead : pObjectHead[type];') |
| 657 | exts.append(' for (XGL_UINT64 i = 0; i < objCount; i++) {') |
| 658 | exts.append(' if (!pTrav) {') |
| 659 | exts.append(' char str[1024];') |
| 660 | exts.append(' sprintf(str, "OBJ INTERNAL ERROR : Ran out of %s objs! Should have %lu, but only copied %lu and not the requested %lu.", string_XGL_OBJECT_TYPE(type), maxObjCount, i, objCount);') |
| 661 | exts.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, 0, 0, OBJTRACK_INTERNAL_ERROR, "OBJTRACK", str);') |
| 662 | exts.append(' return XGL_ERROR_UNKNOWN;') |
| 663 | exts.append(' }') |
| 664 | exts.append(' memcpy(&pObjNodeArray[i], pTrav, sizeof(OBJTRACK_NODE));') |
| 665 | exts.append(' pTrav = (bAllObjs) ? pTrav->pNextGlobal : pTrav->pNextObj;') |
| 666 | exts.append(' }') |
| 667 | exts.append(' return XGL_SUCCESS;') |
| 668 | exts.append('}') |
| 669 | |
| 670 | return "\n".join(exts) |
| 671 | |
Chia-I Wu | 706533e | 2015-01-05 13:18:57 +0800 | [diff] [blame] | 672 | def _generate_layer_gpa_function(self, extensions=[]): |
| 673 | func_body = ["#include \"xgl_generic_intercept_proc_helper.h\""] |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 674 | func_body.append("XGL_LAYER_EXPORT XGL_VOID* XGLAPI xglGetProcAddr(XGL_PHYSICAL_GPU gpu, const XGL_CHAR* funcName)\n" |
| 675 | "{\n" |
| 676 | " XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) gpu;\n" |
Chia-I Wu | 706533e | 2015-01-05 13:18:57 +0800 | [diff] [blame] | 677 | " void* addr;\n" |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 678 | " if (gpu == NULL)\n" |
| 679 | " return NULL;\n" |
| 680 | " pCurObj = gpuw;\n" |
| 681 | " pthread_once(&tabOnce, initLayerTable);\n\n" |
Chia-I Wu | 706533e | 2015-01-05 13:18:57 +0800 | [diff] [blame] | 682 | " addr = layer_intercept_proc(funcName);\n" |
| 683 | " if (addr)\n" |
| 684 | " return addr;") |
| 685 | |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 686 | if 0 != len(extensions): |
| 687 | for ext_name in extensions: |
Chia-I Wu | 7461fcf | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 688 | func_body.append(' else if (!strncmp("%s", funcName, sizeof("%s")))\n' |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 689 | ' return %s;' % (ext_name, ext_name, ext_name)) |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 690 | func_body.append(" else {\n" |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 691 | " if (gpuw->pGPA == NULL)\n" |
| 692 | " return NULL;\n" |
Tobin Ehlis | 434db7c | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 693 | " return gpuw->pGPA((XGL_PHYSICAL_GPU)gpuw->nextObject, funcName);\n" |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 694 | " }\n" |
| 695 | "}\n") |
| 696 | return "\n".join(func_body) |
| 697 | |
| 698 | def _generate_layer_dispatch_table(self, prefix='xgl'): |
Chia-I Wu | 0f65b1e | 2015-01-04 23:11:43 +0800 | [diff] [blame] | 699 | func_body = ["#include \"xgl_dispatch_table_helper.h\""] |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 700 | func_body.append('static void initLayerTable()\n' |
| 701 | '{\n' |
Mark Lobodzinski | 953a169 | 2015-01-09 15:12:03 -0600 | [diff] [blame^] | 702 | ' xglGetProcAddrType fpNextGPA;\n' |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 703 | ' fpNextGPA = pCurObj->pGPA;\n' |
| 704 | ' assert(fpNextGPA);\n'); |
| 705 | |
Chia-I Wu | 0f65b1e | 2015-01-04 23:11:43 +0800 | [diff] [blame] | 706 | func_body.append(" layer_initialize_dispatch_table(&nextTable, fpNextGPA, (XGL_PHYSICAL_GPU) pCurObj->nextObject);") |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 707 | func_body.append("}\n") |
| 708 | return "\n".join(func_body) |
| 709 | |
| 710 | class LayerFuncsSubcommand(Subcommand): |
| 711 | def generate_header(self): |
| 712 | return '#include <xglLayer.h>\n#include "loader.h"' |
| 713 | |
| 714 | def generate_body(self): |
| 715 | return self._generate_dispatch_entrypoints("static", True) |
| 716 | |
| 717 | class LayerDispatchSubcommand(Subcommand): |
| 718 | def generate_header(self): |
| 719 | return '#include "layer_wrappers.h"' |
| 720 | |
| 721 | def generate_body(self): |
| 722 | return self._generate_layer_dispatch_table() |
| 723 | |
| 724 | class GenericLayerSubcommand(Subcommand): |
| 725 | def generate_header(self): |
| 726 | return '#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <assert.h>\n#include <pthread.h>\n#include "xglLayer.h"\n\nstatic XGL_LAYER_DISPATCH_TABLE nextTable;\nstatic XGL_BASE_LAYER_OBJECT *pCurObj;\nstatic pthread_once_t tabOnce = PTHREAD_ONCE_INIT;\n' |
| 727 | |
| 728 | def generate_body(self): |
Tobin Ehlis | c54139f | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 729 | body = [self._gen_layer_dbg_callback_header(), |
| 730 | self._generate_layer_dispatch_table(), |
Tobin Ehlis | 907a052 | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 731 | self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "Generic"), |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 732 | self._generate_layer_gpa_function()] |
| 733 | |
| 734 | return "\n\n".join(body) |
| 735 | |
| 736 | class ApiDumpSubcommand(Subcommand): |
| 737 | def generate_header(self): |
Tobin Ehlis | 0c68c9c | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 738 | header_txt = [] |
| 739 | header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <assert.h>\n#include <pthread.h>\n#include "xglLayer.h"\n#include "xgl_struct_string_helper.h"\n\nstatic XGL_LAYER_DISPATCH_TABLE nextTable;\nstatic XGL_BASE_LAYER_OBJECT *pCurObj;\nstatic pthread_once_t tabOnce = PTHREAD_ONCE_INIT;\npthread_mutex_t print_lock = PTHREAD_MUTEX_INITIALIZER;\n') |
| 740 | header_txt.append('#define MAX_TID 513') |
| 741 | header_txt.append('static pthread_t tidMapping[MAX_TID] = {0};') |
| 742 | header_txt.append('static uint32_t maxTID = 0;') |
| 743 | header_txt.append('// Map actual TID to an index value and return that index') |
| 744 | header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs') |
| 745 | header_txt.append('static uint32_t getTIDIndex() {') |
| 746 | header_txt.append(' pthread_t tid = pthread_self();') |
| 747 | header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {') |
| 748 | header_txt.append(' if (tid == tidMapping[i])') |
| 749 | header_txt.append(' return i;') |
| 750 | header_txt.append(' }') |
| 751 | header_txt.append(" // Don't yet have mapping, set it and return newly set index") |
| 752 | header_txt.append(' uint32_t retVal = (uint32_t)maxTID;') |
| 753 | header_txt.append(' tidMapping[maxTID++] = tid;') |
| 754 | header_txt.append(' assert(maxTID < MAX_TID);') |
| 755 | header_txt.append(' return retVal;') |
| 756 | header_txt.append('}') |
| 757 | return "\n".join(header_txt) |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 758 | |
| 759 | def generate_body(self): |
| 760 | body = [self._generate_layer_dispatch_table(), |
Tobin Ehlis | 907a052 | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 761 | self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDump"), |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 762 | self._generate_layer_gpa_function()] |
| 763 | |
| 764 | return "\n\n".join(body) |
| 765 | |
Tobin Ehlis | 434db7c | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 766 | class ApiDumpCppSubcommand(Subcommand): |
| 767 | def generate_header(self): |
| 768 | header_txt = [] |
| 769 | header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <assert.h>\n#include <pthread.h>\n#include "xglLayer.h"\n#include "xgl_struct_string_helper_cpp.h"\n\nstatic XGL_LAYER_DISPATCH_TABLE nextTable;\nstatic XGL_BASE_LAYER_OBJECT *pCurObj;\nstatic pthread_once_t tabOnce = PTHREAD_ONCE_INIT;\npthread_mutex_t print_lock = PTHREAD_MUTEX_INITIALIZER;\n') |
| 770 | header_txt.append('#define MAX_TID 513') |
| 771 | header_txt.append('static pthread_t tidMapping[MAX_TID] = {0};') |
| 772 | header_txt.append('static uint32_t maxTID = 0;') |
| 773 | header_txt.append('// Map actual TID to an index value and return that index') |
| 774 | header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs') |
| 775 | header_txt.append('static uint32_t getTIDIndex() {') |
| 776 | header_txt.append(' pthread_t tid = pthread_self();') |
| 777 | header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {') |
| 778 | header_txt.append(' if (tid == tidMapping[i])') |
| 779 | header_txt.append(' return i;') |
| 780 | header_txt.append(' }') |
| 781 | header_txt.append(" // Don't yet have mapping, set it and return newly set index") |
| 782 | header_txt.append(' uint32_t retVal = (uint32_t)maxTID;') |
| 783 | header_txt.append(' tidMapping[maxTID++] = tid;') |
| 784 | header_txt.append(' assert(maxTID < MAX_TID);') |
| 785 | header_txt.append(' return retVal;') |
| 786 | header_txt.append('}') |
| 787 | return "\n".join(header_txt) |
| 788 | |
| 789 | def generate_body(self): |
| 790 | body = [self._generate_layer_dispatch_table(), |
| 791 | self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDumpCpp"), |
| 792 | self._generate_layer_gpa_function()] |
| 793 | |
| 794 | return "\n\n".join(body) |
| 795 | |
Tobin Ehlis | 574b014 | 2014-11-12 13:11:15 -0700 | [diff] [blame] | 796 | class ApiDumpFileSubcommand(Subcommand): |
| 797 | def generate_header(self): |
Tobin Ehlis | 0c68c9c | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 798 | header_txt = [] |
| 799 | header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <assert.h>\n#include <pthread.h>\n#include "xglLayer.h"\n#include "xgl_struct_string_helper.h"\n\nstatic XGL_LAYER_DISPATCH_TABLE nextTable;\nstatic XGL_BASE_LAYER_OBJECT *pCurObj;\nstatic pthread_once_t tabOnce = PTHREAD_ONCE_INIT;\n\nstatic FILE* pOutFile;\nstatic char* outFileName = "xgl_apidump.txt";\npthread_mutex_t file_lock = PTHREAD_MUTEX_INITIALIZER;\n') |
| 800 | header_txt.append('#define MAX_TID 513') |
| 801 | header_txt.append('static pthread_t tidMapping[MAX_TID] = {0};') |
| 802 | header_txt.append('static uint32_t maxTID = 0;') |
| 803 | header_txt.append('// Map actual TID to an index value and return that index') |
| 804 | header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs') |
| 805 | header_txt.append('static uint32_t getTIDIndex() {') |
| 806 | header_txt.append(' pthread_t tid = pthread_self();') |
| 807 | header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {') |
| 808 | header_txt.append(' if (tid == tidMapping[i])') |
| 809 | header_txt.append(' return i;') |
| 810 | header_txt.append(' }') |
| 811 | header_txt.append(" // Don't yet have mapping, set it and return newly set index") |
| 812 | header_txt.append(' uint32_t retVal = (uint32_t)maxTID;') |
| 813 | header_txt.append(' tidMapping[maxTID++] = tid;') |
| 814 | header_txt.append(' assert(maxTID < MAX_TID);') |
| 815 | header_txt.append(' return retVal;') |
| 816 | header_txt.append('}') |
| 817 | return "\n".join(header_txt) |
Tobin Ehlis | 574b014 | 2014-11-12 13:11:15 -0700 | [diff] [blame] | 818 | |
| 819 | def generate_body(self): |
| 820 | body = [self._generate_layer_dispatch_table(), |
Tobin Ehlis | 907a052 | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 821 | self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDumpFile"), |
Tobin Ehlis | 574b014 | 2014-11-12 13:11:15 -0700 | [diff] [blame] | 822 | self._generate_layer_gpa_function()] |
| 823 | |
| 824 | return "\n\n".join(body) |
| 825 | |
Tobin Ehlis | 07fe9ab | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 826 | class ApiDumpNoAddrSubcommand(Subcommand): |
| 827 | def generate_header(self): |
| 828 | header_txt = [] |
| 829 | header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <assert.h>\n#include <pthread.h>\n#include "xglLayer.h"\n#include "xgl_struct_string_helper_no_addr.h"\n\nstatic XGL_LAYER_DISPATCH_TABLE nextTable;\nstatic XGL_BASE_LAYER_OBJECT *pCurObj;\nstatic pthread_once_t tabOnce = PTHREAD_ONCE_INIT;\npthread_mutex_t print_lock = PTHREAD_MUTEX_INITIALIZER;\n') |
| 830 | header_txt.append('#define MAX_TID 513') |
| 831 | header_txt.append('static pthread_t tidMapping[MAX_TID] = {0};') |
| 832 | header_txt.append('static uint32_t maxTID = 0;') |
| 833 | header_txt.append('// Map actual TID to an index value and return that index') |
| 834 | header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs') |
| 835 | header_txt.append('static uint32_t getTIDIndex() {') |
| 836 | header_txt.append(' pthread_t tid = pthread_self();') |
| 837 | header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {') |
| 838 | header_txt.append(' if (tid == tidMapping[i])') |
| 839 | header_txt.append(' return i;') |
| 840 | header_txt.append(' }') |
| 841 | header_txt.append(" // Don't yet have mapping, set it and return newly set index") |
| 842 | header_txt.append(' uint32_t retVal = (uint32_t)maxTID;') |
| 843 | header_txt.append(' tidMapping[maxTID++] = tid;') |
| 844 | header_txt.append(' assert(maxTID < MAX_TID);') |
| 845 | header_txt.append(' return retVal;') |
| 846 | header_txt.append('}') |
| 847 | return "\n".join(header_txt) |
| 848 | |
| 849 | def generate_body(self): |
| 850 | body = [self._generate_layer_dispatch_table(), |
| 851 | self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDump", True), |
| 852 | self._generate_layer_gpa_function()] |
| 853 | |
| 854 | return "\n\n".join(body) |
| 855 | |
Tobin Ehlis | 434db7c | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 856 | class ApiDumpNoAddrCppSubcommand(Subcommand): |
| 857 | def generate_header(self): |
| 858 | header_txt = [] |
| 859 | header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <assert.h>\n#include <pthread.h>\n#include "xglLayer.h"\n#include "xgl_struct_string_helper_no_addr_cpp.h"\n\nstatic XGL_LAYER_DISPATCH_TABLE nextTable;\nstatic XGL_BASE_LAYER_OBJECT *pCurObj;\nstatic pthread_once_t tabOnce = PTHREAD_ONCE_INIT;\npthread_mutex_t print_lock = PTHREAD_MUTEX_INITIALIZER;\n') |
| 860 | header_txt.append('#define MAX_TID 513') |
| 861 | header_txt.append('static pthread_t tidMapping[MAX_TID] = {0};') |
| 862 | header_txt.append('static uint32_t maxTID = 0;') |
| 863 | header_txt.append('// Map actual TID to an index value and return that index') |
| 864 | header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs') |
| 865 | header_txt.append('static uint32_t getTIDIndex() {') |
| 866 | header_txt.append(' pthread_t tid = pthread_self();') |
| 867 | header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {') |
| 868 | header_txt.append(' if (tid == tidMapping[i])') |
| 869 | header_txt.append(' return i;') |
| 870 | header_txt.append(' }') |
| 871 | header_txt.append(" // Don't yet have mapping, set it and return newly set index") |
| 872 | header_txt.append(' uint32_t retVal = (uint32_t)maxTID;') |
| 873 | header_txt.append(' tidMapping[maxTID++] = tid;') |
| 874 | header_txt.append(' assert(maxTID < MAX_TID);') |
| 875 | header_txt.append(' return retVal;') |
| 876 | header_txt.append('}') |
| 877 | return "\n".join(header_txt) |
| 878 | |
| 879 | def generate_body(self): |
| 880 | body = [self._generate_layer_dispatch_table(), |
| 881 | self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDumpCpp", True), |
| 882 | self._generate_layer_gpa_function()] |
| 883 | |
| 884 | return "\n\n".join(body) |
| 885 | |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 886 | class ObjectTrackerSubcommand(Subcommand): |
| 887 | def generate_header(self): |
| 888 | header_txt = [] |
| 889 | header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <assert.h>\n#include <pthread.h>') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 890 | header_txt.append('#include "object_track.h"\n\nstatic XGL_LAYER_DISPATCH_TABLE nextTable;\nstatic XGL_BASE_LAYER_OBJECT *pCurObj;') |
| 891 | header_txt.append('static pthread_once_t tabOnce = PTHREAD_ONCE_INIT;\nstatic long long unsigned int object_track_index = 0;') |
| 892 | header_txt.append('// Ptr to LL of dbg functions') |
| 893 | header_txt.append('static XGL_LAYER_DBG_FUNCTION_NODE *pDbgFunctionHead = NULL;') |
| 894 | header_txt.append('// Utility function to handle reporting') |
| 895 | header_txt.append('// If callbacks are enabled, use them, otherwise use printf') |
| 896 | header_txt.append('static XGL_VOID layerCbMsg(XGL_DBG_MSG_TYPE msgType,') |
| 897 | header_txt.append(' XGL_VALIDATION_LEVEL validationLevel,') |
| 898 | header_txt.append(' XGL_BASE_OBJECT srcObject,') |
| 899 | header_txt.append(' XGL_SIZE location,') |
| 900 | header_txt.append(' XGL_INT msgCode,') |
Chia-I Wu | a837c52 | 2014-12-16 10:47:33 +0800 | [diff] [blame] | 901 | header_txt.append(' const char* pLayerPrefix,') |
| 902 | header_txt.append(' const char* pMsg)') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 903 | header_txt.append('{') |
| 904 | header_txt.append(' XGL_LAYER_DBG_FUNCTION_NODE *pTrav = pDbgFunctionHead;') |
| 905 | header_txt.append(' if (pTrav) {') |
| 906 | header_txt.append(' while (pTrav) {') |
Chia-I Wu | 7461fcf | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 907 | header_txt.append(' pTrav->pfnMsgCallback(msgType, validationLevel, srcObject, location, msgCode, pMsg, pTrav->pUserData);') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 908 | header_txt.append(' pTrav = pTrav->pNext;') |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 909 | header_txt.append(' }') |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 910 | header_txt.append(' }') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 911 | header_txt.append(' else {') |
| 912 | header_txt.append(' switch (msgType) {') |
| 913 | header_txt.append(' case XGL_DBG_MSG_ERROR:') |
| 914 | header_txt.append(' printf("{%s}ERROR : %s\\n", pLayerPrefix, pMsg);') |
| 915 | header_txt.append(' break;') |
| 916 | header_txt.append(' case XGL_DBG_MSG_WARNING:') |
| 917 | header_txt.append(' printf("{%s}WARN : %s\\n", pLayerPrefix, pMsg);') |
| 918 | header_txt.append(' break;') |
| 919 | header_txt.append(' case XGL_DBG_MSG_PERF_WARNING:') |
| 920 | header_txt.append(' printf("{%s}PERF_WARN : %s\\n", pLayerPrefix, pMsg);') |
| 921 | header_txt.append(' break;') |
| 922 | header_txt.append(' default:') |
| 923 | header_txt.append(' printf("{%s}INFO : %s\\n", pLayerPrefix, pMsg);') |
| 924 | header_txt.append(' break;') |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 925 | header_txt.append(' }') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 926 | header_txt.append(' }') |
| 927 | header_txt.append('}') |
| 928 | header_txt.append('// We maintain a "Global" list which links every object and a') |
| 929 | header_txt.append('// per-Object list which just links objects of a given type') |
| 930 | header_txt.append('// The object node has both pointers so the actual nodes are shared between the two lists') |
| 931 | header_txt.append('typedef struct _objNode {') |
| 932 | header_txt.append(' OBJTRACK_NODE obj;') |
| 933 | header_txt.append(' struct _objNode *pNextObj;') |
| 934 | header_txt.append(' struct _objNode *pNextGlobal;') |
| 935 | header_txt.append('} objNode;') |
| 936 | header_txt.append('static objNode *pObjectHead[XGL_NUM_OBJECT_TYPE] = {0};') |
| 937 | header_txt.append('static objNode *pGlobalHead = NULL;') |
| 938 | header_txt.append('static uint64_t numObjs[XGL_NUM_OBJECT_TYPE] = {0};') |
| 939 | header_txt.append('static uint64_t numTotalObjs = 0;') |
| 940 | header_txt.append('// Debug function to print global list and each individual object list') |
| 941 | header_txt.append('static void ll_print_lists()') |
| 942 | header_txt.append('{') |
| 943 | header_txt.append(' objNode* pTrav = pGlobalHead;') |
| 944 | header_txt.append(' printf("=====GLOBAL OBJECT LIST (%lu total objs):\\n", numTotalObjs);') |
| 945 | header_txt.append(' while (pTrav) {') |
| 946 | header_txt.append(' printf(" ObjNode (%p) w/ %s obj %p has pNextGlobal %p\\n", (void*)pTrav, string_XGL_OBJECT_TYPE(pTrav->obj.objType), pTrav->obj.pObj, (void*)pTrav->pNextGlobal);') |
| 947 | header_txt.append(' pTrav = pTrav->pNextGlobal;') |
| 948 | header_txt.append(' }') |
| 949 | header_txt.append(' for (uint32_t i = 0; i < XGL_NUM_OBJECT_TYPE; i++) {') |
| 950 | header_txt.append(' pTrav = pObjectHead[i];') |
| 951 | header_txt.append(' if (pTrav) {') |
| 952 | header_txt.append(' printf("=====%s OBJECT LIST (%lu objs):\\n", string_XGL_OBJECT_TYPE(pTrav->obj.objType), numObjs[i]);') |
| 953 | header_txt.append(' while (pTrav) {') |
| 954 | header_txt.append(' printf(" ObjNode (%p) w/ %s obj %p has pNextObj %p\\n", (void*)pTrav, string_XGL_OBJECT_TYPE(pTrav->obj.objType), pTrav->obj.pObj, (void*)pTrav->pNextObj);') |
| 955 | header_txt.append(' pTrav = pTrav->pNextObj;') |
| 956 | header_txt.append(' }') |
| 957 | header_txt.append(' }') |
| 958 | header_txt.append(' }') |
| 959 | header_txt.append('}') |
| 960 | header_txt.append('static void ll_insert_obj(XGL_VOID* pObj, XGL_OBJECT_TYPE objType) {') |
| 961 | header_txt.append(' char str[1024];') |
| 962 | header_txt.append(' sprintf(str, "OBJ[%llu] : CREATE %s object %p", object_track_index++, string_XGL_OBJECT_TYPE(objType), (void*)pObj);') |
| 963 | header_txt.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_NONE, "OBJTRACK", str);') |
| 964 | header_txt.append(' objNode* pNewObjNode = (objNode*)malloc(sizeof(objNode));') |
| 965 | header_txt.append(' pNewObjNode->obj.pObj = pObj;') |
| 966 | header_txt.append(' pNewObjNode->obj.objType = objType;') |
| 967 | header_txt.append(' pNewObjNode->obj.numUses = 0;') |
| 968 | header_txt.append(' // insert at front of global list') |
| 969 | header_txt.append(' pNewObjNode->pNextGlobal = pGlobalHead;') |
| 970 | header_txt.append(' pGlobalHead = pNewObjNode;') |
| 971 | header_txt.append(' // insert at front of object list') |
| 972 | header_txt.append(' pNewObjNode->pNextObj = pObjectHead[objType];') |
| 973 | header_txt.append(' pObjectHead[objType] = pNewObjNode;') |
| 974 | header_txt.append(' // increment obj counts') |
| 975 | header_txt.append(' numObjs[objType]++;') |
| 976 | header_txt.append(' numTotalObjs++;') |
| 977 | header_txt.append(' //sprintf(str, "OBJ_STAT : %lu total objs & %lu %s objs.", numTotalObjs, numObjs[objType], string_XGL_OBJECT_TYPE(objType));') |
Chia-I Wu | df142a3 | 2014-12-16 11:02:06 +0800 | [diff] [blame] | 978 | header_txt.append(' if (0) ll_print_lists();') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 979 | header_txt.append('}') |
| 980 | header_txt.append('// Traverse global list and return type for given object') |
| 981 | header_txt.append('static XGL_OBJECT_TYPE ll_get_obj_type(XGL_OBJECT object) {') |
| 982 | header_txt.append(' objNode *pTrav = pGlobalHead;') |
| 983 | header_txt.append(' while (pTrav) {') |
| 984 | header_txt.append(' if (pTrav->obj.pObj == object)') |
| 985 | header_txt.append(' return pTrav->obj.objType;') |
| 986 | header_txt.append(' pTrav = pTrav->pNextGlobal;') |
| 987 | header_txt.append(' }') |
| 988 | header_txt.append(' char str[1024];') |
| 989 | header_txt.append(' sprintf(str, "Attempting look-up on obj %p but it is NOT in the global list!", (void*)object);') |
| 990 | header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, object, 0, OBJTRACK_MISSING_OBJECT, "OBJTRACK", str);') |
| 991 | header_txt.append(' return XGL_OBJECT_TYPE_UNKNOWN;') |
| 992 | header_txt.append('}') |
Chia-I Wu | df142a3 | 2014-12-16 11:02:06 +0800 | [diff] [blame] | 993 | header_txt.append('#if 0') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 994 | header_txt.append('static uint64_t ll_get_obj_uses(XGL_VOID* pObj, XGL_OBJECT_TYPE objType) {') |
| 995 | header_txt.append(' objNode *pTrav = pObjectHead[objType];') |
| 996 | header_txt.append(' while (pTrav) {') |
| 997 | header_txt.append(' if (pTrav->obj.pObj == pObj) {') |
| 998 | header_txt.append(' return pTrav->obj.numUses;') |
| 999 | header_txt.append(' }') |
| 1000 | header_txt.append(' pTrav = pTrav->pNextObj;') |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1001 | header_txt.append(' }') |
| 1002 | header_txt.append(' return 0;') |
| 1003 | header_txt.append('}') |
Chia-I Wu | df142a3 | 2014-12-16 11:02:06 +0800 | [diff] [blame] | 1004 | header_txt.append('#endif') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1005 | header_txt.append('static void ll_increment_use_count(XGL_VOID* pObj, XGL_OBJECT_TYPE objType) {') |
| 1006 | header_txt.append(' objNode *pTrav = pObjectHead[objType];') |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1007 | header_txt.append(' while (pTrav) {') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1008 | header_txt.append(' if (pTrav->obj.pObj == pObj) {') |
| 1009 | header_txt.append(' pTrav->obj.numUses++;') |
| 1010 | header_txt.append(' char str[1024];') |
| 1011 | header_txt.append(' sprintf(str, "OBJ[%llu] : USING %s object %p (%lu total uses)", object_track_index++, string_XGL_OBJECT_TYPE(objType), (void*)pObj, pTrav->obj.numUses);') |
| 1012 | header_txt.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_NONE, "OBJTRACK", str);') |
| 1013 | header_txt.append(' return;') |
| 1014 | header_txt.append(' }') |
| 1015 | header_txt.append(' pTrav = pTrav->pNextObj;') |
| 1016 | header_txt.append(' }') |
| 1017 | header_txt.append(' // If we do not find obj, insert it and then increment count') |
| 1018 | header_txt.append(' char str[1024];') |
| 1019 | header_txt.append(' sprintf(str, "Unable to increment count for obj %p, will add to list as %s type and increment count", pObj, string_XGL_OBJECT_TYPE(objType));') |
| 1020 | header_txt.append(' layerCbMsg(XGL_DBG_MSG_WARNING, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);') |
| 1021 | header_txt.append('') |
| 1022 | header_txt.append(' ll_insert_obj(pObj, objType);') |
| 1023 | header_txt.append(' ll_increment_use_count(pObj, objType);') |
| 1024 | header_txt.append('}') |
| 1025 | header_txt.append('// We usually do not know Obj type when we destroy it so have to fetch') |
| 1026 | header_txt.append('// Type from global list w/ ll_destroy_obj()') |
| 1027 | header_txt.append('// and then do the full removal from both lists w/ ll_remove_obj_type()') |
| 1028 | header_txt.append('static void ll_remove_obj_type(XGL_VOID* pObj, XGL_OBJECT_TYPE objType) {') |
| 1029 | header_txt.append(' objNode *pTrav = pObjectHead[objType];') |
| 1030 | header_txt.append(' objNode *pPrev = pObjectHead[objType];') |
| 1031 | header_txt.append(' while (pTrav) {') |
| 1032 | header_txt.append(' if (pTrav->obj.pObj == pObj) {') |
| 1033 | header_txt.append(' pPrev->pNextObj = pTrav->pNextObj;') |
| 1034 | header_txt.append(' // update HEAD of Obj list as needed') |
| 1035 | header_txt.append(' if (pObjectHead[objType] == pTrav)') |
| 1036 | header_txt.append(' pObjectHead[objType] = pTrav->pNextObj;') |
| 1037 | header_txt.append(' assert(numObjs[objType] > 0);') |
| 1038 | header_txt.append(' numObjs[objType]--;') |
| 1039 | header_txt.append(' char str[1024];') |
| 1040 | header_txt.append(' sprintf(str, "OBJ[%llu] : DESTROY %s object %p", object_track_index++, string_XGL_OBJECT_TYPE(objType), (void*)pObj);') |
| 1041 | header_txt.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_NONE, "OBJTRACK", str);') |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1042 | header_txt.append(' return;') |
| 1043 | header_txt.append(' }') |
| 1044 | header_txt.append(' pPrev = pTrav;') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1045 | header_txt.append(' pTrav = pTrav->pNextObj;') |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1046 | header_txt.append(' }') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1047 | header_txt.append(' char str[1024];') |
| 1048 | header_txt.append(' sprintf(str, "OBJ INTERNAL ERROR : Obj %p was in global list but not in %s list", pObj, string_XGL_OBJECT_TYPE(objType));') |
| 1049 | header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_INTERNAL_ERROR, "OBJTRACK", str);') |
| 1050 | header_txt.append('}') |
| 1051 | header_txt.append('// Parse global list to find obj type, then remove obj from obj type list, finally') |
| 1052 | header_txt.append('// remove obj from global list') |
| 1053 | header_txt.append('static void ll_destroy_obj(XGL_VOID* pObj) {') |
| 1054 | header_txt.append(' objNode *pTrav = pGlobalHead;') |
| 1055 | header_txt.append(' objNode *pPrev = pGlobalHead;') |
| 1056 | header_txt.append(' while (pTrav) {') |
| 1057 | header_txt.append(' if (pTrav->obj.pObj == pObj) {') |
| 1058 | header_txt.append(' ll_remove_obj_type(pObj, pTrav->obj.objType);') |
| 1059 | header_txt.append(' pPrev->pNextGlobal = pTrav->pNextGlobal;') |
| 1060 | header_txt.append(' // update HEAD of global list if needed') |
| 1061 | header_txt.append(' if (pGlobalHead == pTrav)') |
| 1062 | header_txt.append(' pGlobalHead = pTrav->pNextGlobal;') |
| 1063 | header_txt.append(' free(pTrav);') |
| 1064 | header_txt.append(' assert(numTotalObjs > 0);') |
| 1065 | header_txt.append(' numTotalObjs--;') |
| 1066 | header_txt.append(' char str[1024];') |
| 1067 | header_txt.append(' sprintf(str, "OBJ_STAT Removed %s obj %p that was used %lu times (%lu total objs & %lu %s objs).", string_XGL_OBJECT_TYPE(pTrav->obj.objType), pTrav->obj.pObj, pTrav->obj.numUses, numTotalObjs, numObjs[pTrav->obj.objType], string_XGL_OBJECT_TYPE(pTrav->obj.objType));') |
| 1068 | header_txt.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_NONE, "OBJTRACK", str);') |
| 1069 | header_txt.append(' return;') |
| 1070 | header_txt.append(' }') |
| 1071 | header_txt.append(' pPrev = pTrav;') |
| 1072 | header_txt.append(' pTrav = pTrav->pNextGlobal;') |
| 1073 | header_txt.append(' }') |
| 1074 | header_txt.append(' char str[1024];') |
| 1075 | header_txt.append(' sprintf(str, "Unable to remove obj %p. Was it created? Has it already been destroyed?", pObj);') |
| 1076 | header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_DESTROY_OBJECT_FAILED, "OBJTRACK", str);') |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1077 | header_txt.append('}') |
| 1078 | |
| 1079 | return "\n".join(header_txt) |
| 1080 | |
| 1081 | def generate_body(self): |
| 1082 | body = [self._generate_layer_dispatch_table(), |
Tobin Ehlis | 907a052 | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 1083 | self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "ObjectTracker"), |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1084 | self._generate_extensions(), |
| 1085 | self._generate_layer_gpa_function(extensions=['objTrackGetObjectCount', 'objTrackGetObjects'])] |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1086 | |
| 1087 | return "\n\n".join(body) |
Courtney Goeltzenleuchter | e6094fc | 2014-11-18 10:40:29 -0700 | [diff] [blame] | 1088 | |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1089 | def main(): |
| 1090 | subcommands = { |
| 1091 | "layer-funcs" : LayerFuncsSubcommand, |
| 1092 | "layer-dispatch" : LayerDispatchSubcommand, |
Tobin Ehlis | 907a052 | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 1093 | "Generic" : GenericLayerSubcommand, |
| 1094 | "ApiDump" : ApiDumpSubcommand, |
| 1095 | "ApiDumpFile" : ApiDumpFileSubcommand, |
Tobin Ehlis | 07fe9ab | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 1096 | "ApiDumpNoAddr" : ApiDumpNoAddrSubcommand, |
Tobin Ehlis | 434db7c | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1097 | "ApiDumpCpp" : ApiDumpCppSubcommand, |
| 1098 | "ApiDumpNoAddrCpp" : ApiDumpNoAddrCppSubcommand, |
Tobin Ehlis | 907a052 | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 1099 | "ObjectTracker" : ObjectTrackerSubcommand, |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1100 | } |
| 1101 | |
| 1102 | if len(sys.argv) < 2 or sys.argv[1] not in subcommands: |
| 1103 | print("Usage: %s <subcommand> [options]" % sys.argv[0]) |
| 1104 | print |
| 1105 | print("Available sucommands are: %s" % " ".join(subcommands)) |
| 1106 | exit(1) |
| 1107 | |
| 1108 | subcmd = subcommands[sys.argv[1]](sys.argv[2:]) |
| 1109 | subcmd.run() |
| 1110 | |
| 1111 | if __name__ == "__main__": |
| 1112 | main() |