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