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 |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 29 | import os |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 30 | |
| 31 | import xgl |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 32 | import xgl_helper |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 33 | |
| 34 | class Subcommand(object): |
| 35 | def __init__(self, argv): |
| 36 | self.argv = argv |
Chia-I Wu | c4f24e8 | 2015-01-01 08:46:31 +0800 | [diff] [blame] | 37 | self.headers = xgl.headers |
| 38 | self.protos = xgl.protos |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 39 | |
| 40 | def run(self): |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 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 | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 98 | def _get_printf_params(self, xgl_type, name, output_param, cpp=False): |
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) |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 114 | if cpp: |
| 115 | return ("[%i, %i, %i, %i]", '"[" << %s[0] << "," << %s[1] << "," << %s[2] << "," << %s[3] << "]"' % (name, name, name, name)) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 116 | return ("[%f, %f, %f, %f]", "%s[0], %s[1], %s[2], %s[3]" % (name, name, name, name)) |
| 117 | return ("%f", name) |
Tobin Ehlis | 3a1cc8d | 2014-11-11 17:28:22 -0700 | [diff] [blame] | 118 | 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] | 119 | return ("%u", name) |
Chia-I Wu | 99ff89d | 2014-12-27 14:14:50 +0800 | [diff] [blame] | 120 | 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] | 121 | if '[' in xgl_type: # handle array, current hard-coded to 4 (TODO: Make this dynamic) |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 122 | if cpp: |
| 123 | return ("[%i, %i, %i, %i]", "%s[0] << %s[1] << %s[2] << %s[3]" % (name, name, name, name)) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 124 | return ("[%i, %i, %i, %i]", "%s[0], %s[1], %s[2], %s[3]" % (name, name, name, name)) |
| 125 | if '*' in xgl_type: |
Jon Ashburn | 52f79b5 | 2014-12-12 16:10:45 -0700 | [diff] [blame] | 126 | return ("%i", "*(%s)" % name) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 127 | return ("%i", name) |
Tobin Ehlis | 3a1cc8d | 2014-11-11 17:28:22 -0700 | [diff] [blame] | 128 | # 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] | 129 | if "XGL_FORMAT" == xgl_type: |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 130 | if cpp: |
| 131 | return ("%p", "&%s" % name) |
| 132 | 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] | 133 | if output_param: |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 134 | return ("%p", "(void*)*%s" % name) |
Jon Ashburn | 52f79b5 | 2014-12-12 16:10:45 -0700 | [diff] [blame] | 135 | return ("%p", "(void*)(%s)" % name) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 136 | |
Tobin Ehlis | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 137 | def _gen_layer_dbg_callback_header(self): |
| 138 | cbh_body = [] |
| 139 | cbh_body.append('static XGL_LAYER_DBG_FUNCTION_NODE *pDbgFunctionHead = NULL;') |
| 140 | cbh_body.append('// Utility function to handle reporting') |
| 141 | cbh_body.append('// If callbacks are enabled, use them, otherwise use printf') |
| 142 | cbh_body.append('static XGL_VOID layerCbMsg(XGL_DBG_MSG_TYPE msgType,') |
| 143 | cbh_body.append(' XGL_VALIDATION_LEVEL validationLevel,') |
| 144 | cbh_body.append(' XGL_BASE_OBJECT srcObject,') |
| 145 | cbh_body.append(' XGL_SIZE location,') |
| 146 | cbh_body.append(' XGL_INT msgCode,') |
| 147 | cbh_body.append(' const XGL_CHAR* pLayerPrefix,') |
| 148 | cbh_body.append(' const XGL_CHAR* pMsg)') |
| 149 | cbh_body.append('{') |
| 150 | cbh_body.append(' XGL_LAYER_DBG_FUNCTION_NODE *pTrav = pDbgFunctionHead;') |
| 151 | cbh_body.append(' if (pTrav) {') |
| 152 | cbh_body.append(' while (pTrav) {') |
| 153 | cbh_body.append(' pTrav->pfnMsgCallback(msgType, validationLevel, srcObject, location, msgCode, pMsg, pTrav->pUserData);') |
| 154 | cbh_body.append(' pTrav = pTrav->pNext;') |
| 155 | cbh_body.append(' }') |
| 156 | cbh_body.append(' }') |
| 157 | cbh_body.append(' else {') |
| 158 | cbh_body.append(' switch (msgType) {') |
| 159 | cbh_body.append(' case XGL_DBG_MSG_ERROR:') |
| 160 | cbh_body.append(' printf("{%s}ERROR : %s\\n", pLayerPrefix, pMsg);') |
| 161 | cbh_body.append(' break;') |
| 162 | cbh_body.append(' case XGL_DBG_MSG_WARNING:') |
| 163 | cbh_body.append(' printf("{%s}WARN : %s\\n", pLayerPrefix, pMsg);') |
| 164 | cbh_body.append(' break;') |
| 165 | cbh_body.append(' case XGL_DBG_MSG_PERF_WARNING:') |
| 166 | cbh_body.append(' printf("{%s}PERF_WARN : %s\\n", pLayerPrefix, pMsg);') |
| 167 | cbh_body.append(' break;') |
| 168 | cbh_body.append(' default:') |
| 169 | cbh_body.append(' printf("{%s}INFO : %s\\n", pLayerPrefix, pMsg);') |
| 170 | cbh_body.append(' break;') |
| 171 | cbh_body.append(' }') |
| 172 | cbh_body.append(' }') |
| 173 | cbh_body.append('}') |
| 174 | return "\n".join(cbh_body) |
| 175 | |
| 176 | def _gen_layer_dbg_callback_register(self): |
| 177 | r_body = [] |
| 178 | r_body.append('XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglDbgRegisterMsgCallback(XGL_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback, XGL_VOID* pUserData)') |
| 179 | r_body.append('{') |
| 180 | r_body.append(' // This layer intercepts callbacks') |
| 181 | r_body.append(' XGL_LAYER_DBG_FUNCTION_NODE *pNewDbgFuncNode = (XGL_LAYER_DBG_FUNCTION_NODE*)malloc(sizeof(XGL_LAYER_DBG_FUNCTION_NODE));') |
| 182 | r_body.append(' if (!pNewDbgFuncNode)') |
| 183 | r_body.append(' return XGL_ERROR_OUT_OF_MEMORY;') |
| 184 | r_body.append(' pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;') |
| 185 | r_body.append(' pNewDbgFuncNode->pUserData = pUserData;') |
| 186 | r_body.append(' pNewDbgFuncNode->pNext = pDbgFunctionHead;') |
| 187 | r_body.append(' pDbgFunctionHead = pNewDbgFuncNode;') |
| 188 | r_body.append(' XGL_RESULT result = nextTable.DbgRegisterMsgCallback(pfnMsgCallback, pUserData);') |
| 189 | r_body.append(' return result;') |
| 190 | r_body.append('}') |
| 191 | return "\n".join(r_body) |
| 192 | |
| 193 | def _gen_layer_dbg_callback_unregister(self): |
| 194 | ur_body = [] |
| 195 | ur_body.append('XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglDbgUnregisterMsgCallback(XGL_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback)') |
| 196 | ur_body.append('{') |
| 197 | ur_body.append(' XGL_LAYER_DBG_FUNCTION_NODE *pTrav = pDbgFunctionHead;') |
| 198 | ur_body.append(' XGL_LAYER_DBG_FUNCTION_NODE *pPrev = pTrav;') |
| 199 | ur_body.append(' while (pTrav) {') |
| 200 | ur_body.append(' if (pTrav->pfnMsgCallback == pfnMsgCallback) {') |
| 201 | ur_body.append(' pPrev->pNext = pTrav->pNext;') |
| 202 | ur_body.append(' if (pDbgFunctionHead == pTrav)') |
| 203 | ur_body.append(' pDbgFunctionHead = pTrav->pNext;') |
| 204 | ur_body.append(' free(pTrav);') |
| 205 | ur_body.append(' break;') |
| 206 | ur_body.append(' }') |
| 207 | ur_body.append(' pPrev = pTrav;') |
| 208 | ur_body.append(' pTrav = pTrav->pNext;') |
| 209 | ur_body.append(' }') |
| 210 | ur_body.append(' XGL_RESULT result = nextTable.DbgUnregisterMsgCallback(pfnMsgCallback);') |
| 211 | ur_body.append(' return result;') |
| 212 | ur_body.append('}') |
| 213 | return "\n".join(ur_body) |
| 214 | |
Tobin Ehlis | d49efcb | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 215 | def _generate_dispatch_entrypoints(self, qual="", layer="Generic", no_addr=False): |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 216 | if qual: |
| 217 | qual += " " |
| 218 | |
Tobin Ehlis | a363cfa | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 219 | layer_name = layer |
Tobin Ehlis | d49efcb | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 220 | if no_addr: |
| 221 | layer_name = "%sNoAddr" % layer |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 222 | if 'Cpp' in layer_name: |
| 223 | layer_name = "APIDumpNoAddrCpp" |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 224 | funcs = [] |
| 225 | for proto in self.protos: |
| 226 | if proto.name != "GetProcAddr" and proto.name != "InitAndEnumerateGpus": |
Tobin Ehlis | a363cfa | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 227 | if "Generic" == layer: |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 228 | decl = proto.c_func(prefix="xgl", attr="XGLAPI") |
| 229 | param0_name = proto.params[0].name |
| 230 | ret_val = '' |
| 231 | stmt = '' |
| 232 | if proto.ret != "XGL_VOID": |
| 233 | ret_val = "XGL_RESULT result = " |
| 234 | stmt = " return result;\n" |
Jon Ashburn | f7a0874 | 2014-11-25 11:08:42 -0700 | [diff] [blame] | 235 | if proto.name == "EnumerateLayers": |
| 236 | c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1) |
| 237 | funcs.append('%s%s\n' |
| 238 | '{\n' |
Tobin Ehlis | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 239 | ' char str[1024];\n' |
Jon Ashburn | f7a0874 | 2014-11-25 11:08:42 -0700 | [diff] [blame] | 240 | ' if (gpu != NULL) {\n' |
| 241 | ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n' |
Tobin Ehlis | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 242 | ' sprintf(str, "At start of layered %s\\n");\n' |
Jon Ashburn | a5cbf0c | 2014-12-17 12:08:37 -0700 | [diff] [blame] | 243 | ' 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] | 244 | ' pCurObj = gpuw;\n' |
| 245 | ' pthread_once(&tabOnce, initLayerTable);\n' |
| 246 | ' %snextTable.%s;\n' |
Tobin Ehlis | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 247 | ' sprintf(str, "Completed layered %s\\n");\n' |
Jon Ashburn | a5cbf0c | 2014-12-17 12:08:37 -0700 | [diff] [blame] | 248 | ' 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] | 249 | ' fflush(stdout);\n' |
| 250 | ' %s' |
| 251 | ' } else {\n' |
| 252 | ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n' |
| 253 | ' return XGL_ERROR_INVALID_POINTER;\n' |
| 254 | ' // This layer compatible with all GPUs\n' |
| 255 | ' *pOutLayerCount = 1;\n' |
Chia-I Wu | 1da4b9f | 2014-12-16 10:47:33 +0800 | [diff] [blame] | 256 | ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n' |
Jon Ashburn | f7a0874 | 2014-11-25 11:08:42 -0700 | [diff] [blame] | 257 | ' return XGL_SUCCESS;\n' |
| 258 | ' }\n' |
Tobin Ehlis | d49efcb | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 259 | '}' % (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] | 260 | elif 'DbgRegisterMsgCallback' == proto.name: |
| 261 | funcs.append(self._gen_layer_dbg_callback_register()) |
| 262 | elif 'DbgUnregisterMsgCallback' == proto.name: |
| 263 | funcs.append(self._gen_layer_dbg_callback_unregister()) |
Jon Ashburn | f7a0874 | 2014-11-25 11:08:42 -0700 | [diff] [blame] | 264 | elif proto.params[0].ty != "XGL_PHYSICAL_GPU": |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 265 | funcs.append('%s%s\n' |
| 266 | '{\n' |
| 267 | ' %snextTable.%s;\n' |
| 268 | '%s' |
| 269 | '}' % (qual, decl, ret_val, proto.c_call(), stmt)) |
| 270 | else: |
| 271 | c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1) |
| 272 | funcs.append('%s%s\n' |
| 273 | '{\n' |
Tobin Ehlis | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 274 | ' char str[1024];' |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 275 | ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n' |
Tobin Ehlis | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 276 | ' sprintf(str, "At start of layered %s\\n");\n' |
Jon Ashburn | a5cbf0c | 2014-12-17 12:08:37 -0700 | [diff] [blame] | 277 | ' 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] | 278 | ' pCurObj = gpuw;\n' |
| 279 | ' pthread_once(&tabOnce, initLayerTable);\n' |
| 280 | ' %snextTable.%s;\n' |
Tobin Ehlis | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 281 | ' sprintf(str, "Completed layered %s\\n");\n' |
Jon Ashburn | a5cbf0c | 2014-12-17 12:08:37 -0700 | [diff] [blame] | 282 | ' 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] | 283 | ' fflush(stdout);\n' |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 284 | '%s' |
| 285 | '}' % (qual, decl, proto.params[0].name, proto.name, ret_val, c_call, proto.name, stmt)) |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 286 | elif "APIDumpCpp" in layer: |
| 287 | decl = proto.c_func(prefix="xgl", attr="XGLAPI") |
| 288 | param0_name = proto.params[0].name |
| 289 | ret_val = '' |
| 290 | stmt = '' |
| 291 | cis_param_index = [] # Store list of indices when func has struct params |
| 292 | create_params = 0 # Num of params at end of function that are created and returned as output values |
| 293 | if 'WsiX11CreatePresentableImage' in proto.name: |
| 294 | create_params = -2 |
| 295 | elif 'Create' in proto.name or 'Alloc' in proto.name or 'MapMemory' in proto.name: |
| 296 | create_params = -1 |
| 297 | if proto.ret != "XGL_VOID": |
| 298 | ret_val = "XGL_RESULT result = " |
| 299 | stmt = " return result;\n" |
| 300 | f_open = '' |
| 301 | f_close = '' |
| 302 | if "File" in layer: |
| 303 | file_mode = "a" |
| 304 | if 'CreateDevice' in proto.name: |
| 305 | file_mode = "w" |
| 306 | f_open = 'pthread_mutex_lock( &file_lock );\n pOutFile = fopen(outFileName, "%s");\n ' % (file_mode) |
| 307 | log_func = 'fprintf(pOutFile, "t{%%u} xgl%s(' % proto.name |
| 308 | f_close = '\n fclose(pOutFile);\n pthread_mutex_unlock( &file_lock );' |
| 309 | else: |
| 310 | f_open = 'pthread_mutex_lock( &print_lock );\n ' |
| 311 | log_func = 'cout << "t{" << getTIDIndex() << "} xgl%s(' % proto.name |
| 312 | f_close = '\n pthread_mutex_unlock( &print_lock );' |
| 313 | pindex = 0 |
| 314 | for p in proto.params: |
| 315 | # TODO : Need to handle xglWsiX11CreatePresentableImage for which the last 2 params are returned vals |
| 316 | cp = False |
| 317 | if 0 != create_params: |
| 318 | # If this is any of the N last params of the func, treat as output |
| 319 | for y in range(-1, create_params-1, -1): |
| 320 | if p.name == proto.params[y].name: |
| 321 | cp = True |
| 322 | (pft, pfi) = self._get_printf_params(p.ty, p.name, cp, cpp=True) |
| 323 | if no_addr and "%p" == pft: |
| 324 | (pft, pfi) = ("%s", '"addr"') |
| 325 | log_func += '%s = " << %s << ", ' % (p.name, pfi) |
| 326 | #print_vals += ', %s' % (pfi) |
| 327 | # TODO : Just want this to be simple check for params of STRUCT type |
| 328 | 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']]): |
| 329 | if 'Wsi' not in proto.name: |
| 330 | cis_param_index.append(pindex) |
| 331 | pindex += 1 |
| 332 | log_func = log_func.strip(', ') |
| 333 | if proto.ret != "XGL_VOID": |
| 334 | log_func += ') = " << string_XGL_RESULT(result) << "\\n"' |
| 335 | #print_vals += ', string_XGL_RESULT(result)' |
| 336 | else: |
| 337 | log_func += ')\\n"' |
| 338 | log_func += ';' |
| 339 | if len(cis_param_index) > 0: |
| 340 | log_func += '\n string tmp_str;' |
| 341 | for sp_index in cis_param_index: |
| 342 | cis_print_func = 'xgl_print_%s' % (proto.params[sp_index].ty.strip('const ').strip('*').lower()) |
| 343 | log_func += '\n if (%s) {' % (proto.params[sp_index].name) |
| 344 | log_func += '\n tmp_str = %s(%s, " ");' % (cis_print_func, proto.params[sp_index].name) |
| 345 | if "File" in layer: |
| 346 | if no_addr: |
| 347 | log_func += '\n fprintf(pOutFile, " %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name) |
| 348 | else: |
| 349 | log_func += '\n fprintf(pOutFile, " %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name) |
| 350 | else: |
| 351 | if no_addr: |
| 352 | #log_func += '\n printf(" %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name) |
| 353 | log_func += '\n cout << " %s (addr)" << endl << tmp_str << endl;' % (proto.params[sp_index].name) |
| 354 | else: |
| 355 | #log_func += '\n printf(" %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name) |
| 356 | log_func += '\n cout << " %s (" << %s << ")" << endl << tmp_str << endl;' % (proto.params[sp_index].name, proto.params[sp_index].name) |
| 357 | #log_func += '\n fflush(stdout);' |
| 358 | log_func += '\n }' |
| 359 | if proto.name == "EnumerateLayers": |
| 360 | c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1) |
| 361 | funcs.append('%s%s\n' |
| 362 | '{\n' |
| 363 | ' if (gpu != NULL) {\n' |
| 364 | ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n' |
| 365 | ' pCurObj = gpuw;\n' |
| 366 | ' pthread_once(&tabOnce, initLayerTable);\n' |
| 367 | ' %snextTable.%s;\n' |
| 368 | ' %s %s %s\n' |
| 369 | ' %s' |
| 370 | ' } else {\n' |
| 371 | ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n' |
| 372 | ' return XGL_ERROR_INVALID_POINTER;\n' |
| 373 | ' // This layer compatible with all GPUs\n' |
| 374 | ' *pOutLayerCount = 1;\n' |
| 375 | ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n' |
| 376 | ' return XGL_SUCCESS;\n' |
| 377 | ' }\n' |
| 378 | '}' % (qual, decl, proto.params[0].name, ret_val, c_call,f_open, log_func, f_close, stmt, layer_name)) |
| 379 | elif proto.params[0].ty != "XGL_PHYSICAL_GPU": |
| 380 | funcs.append('%s%s\n' |
| 381 | '{\n' |
| 382 | ' %snextTable.%s;\n' |
| 383 | ' %s%s%s\n' |
| 384 | '%s' |
| 385 | '}' % (qual, decl, ret_val, proto.c_call(), f_open, log_func, f_close, stmt)) |
| 386 | else: |
| 387 | c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1) |
| 388 | funcs.append('%s%s\n' |
| 389 | '{\n' |
| 390 | ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n' |
| 391 | ' pCurObj = gpuw;\n' |
| 392 | ' pthread_once(&tabOnce, initLayerTable);\n' |
| 393 | ' %snextTable.%s;\n' |
| 394 | ' %s%s%s\n' |
| 395 | '%s' |
| 396 | '}' % (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] | 397 | elif "APIDump" in layer: |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 398 | decl = proto.c_func(prefix="xgl", attr="XGLAPI") |
| 399 | param0_name = proto.params[0].name |
| 400 | ret_val = '' |
| 401 | stmt = '' |
Tobin Ehlis | 083e906 | 2014-10-23 08:19:47 -0600 | [diff] [blame] | 402 | cis_param_index = [] # Store list of indices when func has struct params |
Tobin Ehlis | e727157 | 2014-11-19 15:52:46 -0700 | [diff] [blame] | 403 | create_params = 0 # Num of params at end of function that are created and returned as output values |
| 404 | if 'WsiX11CreatePresentableImage' in proto.name: |
| 405 | create_params = -2 |
| 406 | elif 'Create' in proto.name or 'Alloc' in proto.name or 'MapMemory' in proto.name: |
| 407 | create_params = -1 |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 408 | if proto.ret != "XGL_VOID": |
| 409 | ret_val = "XGL_RESULT result = " |
| 410 | stmt = " return result;\n" |
Tobin Ehlis | ea3d21b | 2014-11-12 13:11:15 -0700 | [diff] [blame] | 411 | f_open = '' |
| 412 | f_close = '' |
Tobin Ehlis | a363cfa | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 413 | if "File" in layer: |
Tobin Ehlis | dbcd257 | 2014-11-21 09:35:53 -0700 | [diff] [blame] | 414 | file_mode = "a" |
| 415 | if 'CreateDevice' in proto.name: |
| 416 | file_mode = "w" |
Chia-I Wu | 3bf80a6 | 2014-12-16 00:36:58 +0800 | [diff] [blame] | 417 | 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] | 418 | log_func = 'fprintf(pOutFile, "t{%%u} xgl%s(' % proto.name |
Tobin Ehlis | 2b9313e | 2014-11-20 12:18:45 -0700 | [diff] [blame] | 419 | f_close = '\n fclose(pOutFile);\n pthread_mutex_unlock( &file_lock );' |
Tobin Ehlis | ea3d21b | 2014-11-12 13:11:15 -0700 | [diff] [blame] | 420 | else: |
Chia-I Wu | 3bf80a6 | 2014-12-16 00:36:58 +0800 | [diff] [blame] | 421 | f_open = 'pthread_mutex_lock( &print_lock );\n ' |
Tobin Ehlis | d009bae | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 422 | log_func = 'printf("t{%%u} xgl%s(' % proto.name |
Tobin Ehlis | 2b9313e | 2014-11-20 12:18:45 -0700 | [diff] [blame] | 423 | f_close = '\n pthread_mutex_unlock( &print_lock );' |
Tobin Ehlis | d009bae | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 424 | print_vals = ', getTIDIndex()' |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 425 | pindex = 0 |
| 426 | for p in proto.params: |
Tobin Ehlis | e727157 | 2014-11-19 15:52:46 -0700 | [diff] [blame] | 427 | cp = False |
| 428 | if 0 != create_params: |
| 429 | # If this is any of the N last params of the func, treat as output |
| 430 | for y in range(-1, create_params-1, -1): |
| 431 | if p.name == proto.params[y].name: |
| 432 | cp = True |
| 433 | (pft, pfi) = self._get_printf_params(p.ty, p.name, cp) |
Tobin Ehlis | d49efcb | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 434 | if no_addr and "%p" == pft: |
| 435 | (pft, pfi) = ("%s", '"addr"') |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 436 | log_func += '%s = %s, ' % (p.name, pft) |
| 437 | print_vals += ', %s' % (pfi) |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 438 | # 'format' gets special treatment as a small struct that we print inline |
| 439 | if 'Wsi' not in proto.name and 'format' != p.name and xgl_helper.is_type(p.ty.strip('*').strip('const '), 'struct'): |
| 440 | cis_param_index.append(pindex) |
Tobin Ehlis | 12076fc | 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 | b412d21 | 2014-11-18 10:40:29 -0700 | [diff] [blame] | 445 | print_vals += ', string_XGL_RESULT(result)' |
Tobin Ehlis | 12076fc | 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 | 083e906 | 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 | d49efcb | 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 | ea3d21b | 2014-11-12 13:11:15 -0700 | [diff] [blame] | 460 | else: |
Tobin Ehlis | d49efcb | 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 | d009bae | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 465 | log_func += '\n fflush(stdout);' |
Tobin Ehlis | 083e906 | 2014-10-23 08:19:47 -0600 | [diff] [blame] | 466 | log_func += '\n free(pTmpStr);\n }' |
Jon Ashburn | f7a0874 | 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 | 1da4b9f | 2014-12-16 10:47:33 +0800 | [diff] [blame] | 483 | ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n' |
Jon Ashburn | f7a0874 | 2014-11-25 11:08:42 -0700 | [diff] [blame] | 484 | ' return XGL_SUCCESS;\n' |
| 485 | ' }\n' |
Tobin Ehlis | d49efcb | 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 | f7a0874 | 2014-11-25 11:08:42 -0700 | [diff] [blame] | 487 | elif proto.params[0].ty != "XGL_PHYSICAL_GPU": |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 488 | funcs.append('%s%s\n' |
| 489 | '{\n' |
| 490 | ' %snextTable.%s;\n' |
Tobin Ehlis | ea3d21b | 2014-11-12 13:11:15 -0700 | [diff] [blame] | 491 | ' %s%s%s\n' |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 492 | '%s' |
Tobin Ehlis | ea3d21b | 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 | 12076fc | 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 | ea3d21b | 2014-11-12 13:11:15 -0700 | [diff] [blame] | 502 | ' %s%s%s\n' |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 503 | '%s' |
Tobin Ehlis | ea3d21b | 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 | a363cfa | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 505 | elif "ObjectTracker" == layer: |
Chia-I Wu | d9cc975 | 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 | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 533 | |
Tobin Ehlis | 12076fc | 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 | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 536 | p0_type = proto.params[0].ty |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 537 | create_line = '' |
| 538 | destroy_line = '' |
Tobin Ehlis | ca91587 | 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 | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 563 | using_line = '' |
Tobin Ehlis | ca91587 | 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 | 12076fc | 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 | f7a0874 | 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 | 1da4b9f | 2014-12-16 10:47:33 +0800 | [diff] [blame] | 603 | ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n' |
Jon Ashburn | f7a0874 | 2014-11-25 11:08:42 -0700 | [diff] [blame] | 604 | ' return XGL_SUCCESS;\n' |
| 605 | ' }\n' |
Tobin Ehlis | d49efcb | 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 | f7a0874 | 2014-11-25 11:08:42 -0700 | [diff] [blame] | 607 | elif proto.params[0].ty != "XGL_PHYSICAL_GPU": |
Tobin Ehlis | 12076fc | 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)) |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 627 | elif "ParamChecker" == layer: |
| 628 | # TODO : Need to fix up the non-else cases below to do param checking as well |
| 629 | decl = proto.c_func(prefix="xgl", attr="XGLAPI") |
| 630 | param0_name = proto.params[0].name |
| 631 | ret_val = '' |
| 632 | stmt = '' |
| 633 | param_checks = [] |
| 634 | # Add code to check enums and structs |
| 635 | # TODO : Currently only validating enum values, need to validate everything |
| 636 | str_decl = False |
Tobin Ehlis | c6d256a | 2014-12-18 13:51:21 -0700 | [diff] [blame^] | 637 | prev_count_name = '' |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 638 | for p in proto.params: |
| 639 | if xgl_helper.is_type(p.ty.strip('*').strip('const '), 'enum'): |
| 640 | if not str_decl: |
| 641 | param_checks.append(' char str[1024];') |
| 642 | str_decl = True |
| 643 | param_checks.append(' if (!validate_%s(%s)) {' % (p.ty, p.name)) |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 644 | param_checks.append(' sprintf(str, "Parameter %s to function %s has invalid value of %%i.", (int)%s);' % (p.name, proto.name, p.name)) |
| 645 | param_checks.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, 1, "PARAMCHECK", str);') |
| 646 | param_checks.append(' }') |
| 647 | elif xgl_helper.is_type(p.ty.strip('*').strip('const '), 'struct') and 'const' in p.ty: |
Tobin Ehlis | c6d256a | 2014-12-18 13:51:21 -0700 | [diff] [blame^] | 648 | is_array = False |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 649 | if not str_decl: |
| 650 | param_checks.append(' char str[1024];') |
| 651 | str_decl = True |
| 652 | if '*' in p.ty: # First check for null ptr |
Tobin Ehlis | c6d256a | 2014-12-18 13:51:21 -0700 | [diff] [blame^] | 653 | # If this is an input array, parse over all of the array elements |
| 654 | if prev_count_name != '' and (prev_count_name.strip('Count')[1:] in p.name or 'slotCount' == prev_count_name): |
| 655 | #if 'pImageViews' in p.name: |
| 656 | is_array = True |
| 657 | param_checks.append(' uint32_t i;') |
| 658 | param_checks.append(' for (i = 0; i < %s; i++) {' % prev_count_name) |
| 659 | param_checks.append(' if (!xgl_validate_%s(&%s[i])) {' % (p.ty.strip('*').strip('const ').lower(), p.name)) |
| 660 | param_checks.append(' sprintf(str, "Parameter %s[%%i] to function %s contains an invalid value.", i);' % (p.name, proto.name)) |
| 661 | param_checks.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, 1, "PARAMCHECK", str);') |
| 662 | param_checks.append(' }') |
| 663 | param_checks.append(' }') |
| 664 | else: |
| 665 | param_checks.append(' if (!%s) {' % p.name) |
| 666 | param_checks.append(' sprintf(str, "Struct ptr parameter %s to function %s is NULL.");' % (p.name, proto.name)) |
| 667 | param_checks.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, NULL, 0, 1, "PARAMCHECK", str);') |
| 668 | param_checks.append(' }') |
| 669 | param_checks.append(' else if (!xgl_validate_%s(%s)) {' % (p.ty.strip('*').strip('const ').lower(), p.name)) |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 670 | else: |
| 671 | param_checks.append(' if (!xgl_validate_%s(%s)) {' % (p.ty.strip('const ').lower(), p.name)) |
Tobin Ehlis | c6d256a | 2014-12-18 13:51:21 -0700 | [diff] [blame^] | 672 | if not is_array: |
| 673 | param_checks.append(' sprintf(str, "Parameter %s to function %s contains an invalid value.");' % (p.name, proto.name)) |
| 674 | param_checks.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, 1, "PARAMCHECK", str);') |
| 675 | param_checks.append(' }') |
| 676 | if p.name.endswith('Count'): |
| 677 | prev_count_name = p.name |
| 678 | else: |
| 679 | prev_count_name = '' |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 680 | if proto.ret != "XGL_VOID": |
| 681 | ret_val = "XGL_RESULT result = " |
| 682 | stmt = " return result;\n" |
| 683 | if proto.name == "EnumerateLayers": |
| 684 | c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1) |
| 685 | funcs.append('%s%s\n' |
| 686 | '{\n' |
| 687 | ' char str[1024];\n' |
| 688 | ' if (gpu != NULL) {\n' |
| 689 | ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n' |
| 690 | ' sprintf(str, "At start of layered %s\\n");\n' |
| 691 | ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpu, 0, 0, "PARAMCHECK", str);\n' |
| 692 | ' pCurObj = gpuw;\n' |
| 693 | ' pthread_once(&tabOnce, initLayerTable);\n' |
| 694 | ' %snextTable.%s;\n' |
| 695 | ' sprintf(str, "Completed layered %s\\n");\n' |
| 696 | ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpu, 0, 0, "PARAMCHECK", str);\n' |
| 697 | ' fflush(stdout);\n' |
| 698 | ' %s' |
| 699 | ' } else {\n' |
| 700 | ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n' |
| 701 | ' return XGL_ERROR_INVALID_POINTER;\n' |
| 702 | ' // This layer compatible with all GPUs\n' |
| 703 | ' *pOutLayerCount = 1;\n' |
| 704 | ' strncpy(pOutLayers[0], "%s", maxStringSize);\n' |
| 705 | ' return XGL_SUCCESS;\n' |
| 706 | ' }\n' |
| 707 | '}' % (qual, decl, proto.params[0].name, proto.name, ret_val, c_call, proto.name, stmt, layer_name)) |
| 708 | elif 'DbgRegisterMsgCallback' == proto.name: |
| 709 | funcs.append(self._gen_layer_dbg_callback_register()) |
| 710 | elif 'DbgUnregisterMsgCallback' == proto.name: |
| 711 | funcs.append(self._gen_layer_dbg_callback_unregister()) |
| 712 | elif proto.params[0].ty != "XGL_PHYSICAL_GPU": |
| 713 | funcs.append('%s%s\n' |
| 714 | '{\n' |
| 715 | '%s\n' |
| 716 | ' %snextTable.%s;\n' |
| 717 | '%s' |
| 718 | '}' % (qual, decl, "\n".join(param_checks), ret_val, proto.c_call(), stmt)) |
| 719 | else: |
| 720 | c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1) |
| 721 | funcs.append('%s%s\n' |
| 722 | '{\n' |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 723 | ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n' |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 724 | ' pCurObj = gpuw;\n' |
| 725 | ' pthread_once(&tabOnce, initLayerTable);\n' |
Tobin Ehlis | bf4c4de | 2014-12-18 08:44:01 -0700 | [diff] [blame] | 726 | '%s\n' |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 727 | ' %snextTable.%s;\n' |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 728 | '%s' |
Tobin Ehlis | bf4c4de | 2014-12-18 08:44:01 -0700 | [diff] [blame] | 729 | '}' % (qual, decl, proto.params[0].name, "\n".join(param_checks), ret_val, c_call, stmt)) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 730 | |
| 731 | return "\n\n".join(funcs) |
| 732 | |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 733 | def _generate_extensions(self): |
| 734 | exts = [] |
| 735 | exts.append('XGL_UINT64 objTrackGetObjectCount(XGL_OBJECT_TYPE type)') |
| 736 | exts.append('{') |
| 737 | exts.append(' return (type == XGL_OBJECT_TYPE_ANY) ? numTotalObjs : numObjs[type];') |
| 738 | exts.append('}') |
| 739 | exts.append('') |
| 740 | exts.append('XGL_RESULT objTrackGetObjects(XGL_OBJECT_TYPE type, XGL_UINT64 objCount, OBJTRACK_NODE* pObjNodeArray)') |
| 741 | exts.append('{') |
| 742 | exts.append(" // This bool flags if we're pulling all objs or just a single class of objs") |
| 743 | exts.append(' XGL_BOOL bAllObjs = (type == XGL_OBJECT_TYPE_ANY);') |
| 744 | exts.append(' // Check the count first thing') |
| 745 | exts.append(' XGL_UINT64 maxObjCount = (bAllObjs) ? numTotalObjs : numObjs[type];') |
| 746 | exts.append(' if (objCount > maxObjCount) {') |
| 747 | exts.append(' char str[1024];') |
| 748 | 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));') |
| 749 | exts.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, 0, 0, OBJTRACK_OBJCOUNT_MAX_EXCEEDED, "OBJTRACK", str);') |
| 750 | exts.append(' return XGL_ERROR_INVALID_VALUE;') |
| 751 | exts.append(' }') |
| 752 | exts.append(' objNode* pTrav = (bAllObjs) ? pGlobalHead : pObjectHead[type];') |
| 753 | exts.append(' for (XGL_UINT64 i = 0; i < objCount; i++) {') |
| 754 | exts.append(' if (!pTrav) {') |
| 755 | exts.append(' char str[1024];') |
| 756 | 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);') |
| 757 | exts.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, 0, 0, OBJTRACK_INTERNAL_ERROR, "OBJTRACK", str);') |
| 758 | exts.append(' return XGL_ERROR_UNKNOWN;') |
| 759 | exts.append(' }') |
| 760 | exts.append(' memcpy(&pObjNodeArray[i], pTrav, sizeof(OBJTRACK_NODE));') |
| 761 | exts.append(' pTrav = (bAllObjs) ? pTrav->pNextGlobal : pTrav->pNextObj;') |
| 762 | exts.append(' }') |
| 763 | exts.append(' return XGL_SUCCESS;') |
| 764 | exts.append('}') |
| 765 | |
| 766 | return "\n".join(exts) |
| 767 | |
Chia-I Wu | 4d11dcc | 2015-01-05 13:18:57 +0800 | [diff] [blame] | 768 | def _generate_layer_gpa_function(self, extensions=[]): |
| 769 | func_body = ["#include \"xgl_generic_intercept_proc_helper.h\""] |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 770 | func_body.append("XGL_LAYER_EXPORT XGL_VOID* XGLAPI xglGetProcAddr(XGL_PHYSICAL_GPU gpu, const XGL_CHAR* funcName)\n" |
| 771 | "{\n" |
| 772 | " XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) gpu;\n" |
Chia-I Wu | 4d11dcc | 2015-01-05 13:18:57 +0800 | [diff] [blame] | 773 | " void* addr;\n" |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 774 | " if (gpu == NULL)\n" |
| 775 | " return NULL;\n" |
| 776 | " pCurObj = gpuw;\n" |
| 777 | " pthread_once(&tabOnce, initLayerTable);\n\n" |
Chia-I Wu | 4d11dcc | 2015-01-05 13:18:57 +0800 | [diff] [blame] | 778 | " addr = layer_intercept_proc(funcName);\n" |
| 779 | " if (addr)\n" |
| 780 | " return addr;") |
| 781 | |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 782 | if 0 != len(extensions): |
| 783 | for ext_name in extensions: |
Chia-I Wu | f1a5a74 | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 784 | func_body.append(' else if (!strncmp("%s", funcName, sizeof("%s")))\n' |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 785 | ' return %s;' % (ext_name, ext_name, ext_name)) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 786 | func_body.append(" else {\n" |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 787 | " if (gpuw->pGPA == NULL)\n" |
| 788 | " return NULL;\n" |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 789 | " return gpuw->pGPA((XGL_PHYSICAL_GPU)gpuw->nextObject, funcName);\n" |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 790 | " }\n" |
| 791 | "}\n") |
| 792 | return "\n".join(func_body) |
| 793 | |
| 794 | def _generate_layer_dispatch_table(self, prefix='xgl'): |
Chia-I Wu | aa4121f | 2015-01-04 23:11:43 +0800 | [diff] [blame] | 795 | func_body = ["#include \"xgl_dispatch_table_helper.h\""] |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 796 | func_body.append('static void initLayerTable()\n' |
| 797 | '{\n' |
Mark Lobodzinski | 391bb6d | 2015-01-09 15:12:03 -0600 | [diff] [blame] | 798 | ' xglGetProcAddrType fpNextGPA;\n' |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 799 | ' fpNextGPA = pCurObj->pGPA;\n' |
| 800 | ' assert(fpNextGPA);\n'); |
| 801 | |
Chia-I Wu | aa4121f | 2015-01-04 23:11:43 +0800 | [diff] [blame] | 802 | func_body.append(" layer_initialize_dispatch_table(&nextTable, fpNextGPA, (XGL_PHYSICAL_GPU) pCurObj->nextObject);") |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 803 | func_body.append("}\n") |
| 804 | return "\n".join(func_body) |
| 805 | |
| 806 | class LayerFuncsSubcommand(Subcommand): |
| 807 | def generate_header(self): |
| 808 | return '#include <xglLayer.h>\n#include "loader.h"' |
| 809 | |
| 810 | def generate_body(self): |
| 811 | return self._generate_dispatch_entrypoints("static", True) |
| 812 | |
| 813 | class LayerDispatchSubcommand(Subcommand): |
| 814 | def generate_header(self): |
| 815 | return '#include "layer_wrappers.h"' |
| 816 | |
| 817 | def generate_body(self): |
| 818 | return self._generate_layer_dispatch_table() |
| 819 | |
| 820 | class GenericLayerSubcommand(Subcommand): |
| 821 | def generate_header(self): |
| 822 | 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' |
| 823 | |
| 824 | def generate_body(self): |
Tobin Ehlis | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 825 | body = [self._gen_layer_dbg_callback_header(), |
| 826 | self._generate_layer_dispatch_table(), |
Tobin Ehlis | a363cfa | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 827 | self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "Generic"), |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 828 | self._generate_layer_gpa_function()] |
| 829 | |
| 830 | return "\n\n".join(body) |
| 831 | |
| 832 | class ApiDumpSubcommand(Subcommand): |
| 833 | def generate_header(self): |
Tobin Ehlis | d009bae | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 834 | header_txt = [] |
| 835 | 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') |
| 836 | header_txt.append('#define MAX_TID 513') |
| 837 | header_txt.append('static pthread_t tidMapping[MAX_TID] = {0};') |
| 838 | header_txt.append('static uint32_t maxTID = 0;') |
| 839 | header_txt.append('// Map actual TID to an index value and return that index') |
| 840 | header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs') |
| 841 | header_txt.append('static uint32_t getTIDIndex() {') |
| 842 | header_txt.append(' pthread_t tid = pthread_self();') |
| 843 | header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {') |
| 844 | header_txt.append(' if (tid == tidMapping[i])') |
| 845 | header_txt.append(' return i;') |
| 846 | header_txt.append(' }') |
| 847 | header_txt.append(" // Don't yet have mapping, set it and return newly set index") |
| 848 | header_txt.append(' uint32_t retVal = (uint32_t)maxTID;') |
| 849 | header_txt.append(' tidMapping[maxTID++] = tid;') |
| 850 | header_txt.append(' assert(maxTID < MAX_TID);') |
| 851 | header_txt.append(' return retVal;') |
| 852 | header_txt.append('}') |
| 853 | return "\n".join(header_txt) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 854 | |
| 855 | def generate_body(self): |
| 856 | body = [self._generate_layer_dispatch_table(), |
Tobin Ehlis | a363cfa | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 857 | self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDump"), |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 858 | self._generate_layer_gpa_function()] |
| 859 | |
| 860 | return "\n\n".join(body) |
| 861 | |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 862 | class ApiDumpCppSubcommand(Subcommand): |
| 863 | def generate_header(self): |
| 864 | header_txt = [] |
| 865 | 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') |
| 866 | header_txt.append('#define MAX_TID 513') |
| 867 | header_txt.append('static pthread_t tidMapping[MAX_TID] = {0};') |
| 868 | header_txt.append('static uint32_t maxTID = 0;') |
| 869 | header_txt.append('// Map actual TID to an index value and return that index') |
| 870 | header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs') |
| 871 | header_txt.append('static uint32_t getTIDIndex() {') |
| 872 | header_txt.append(' pthread_t tid = pthread_self();') |
| 873 | header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {') |
| 874 | header_txt.append(' if (tid == tidMapping[i])') |
| 875 | header_txt.append(' return i;') |
| 876 | header_txt.append(' }') |
| 877 | header_txt.append(" // Don't yet have mapping, set it and return newly set index") |
| 878 | header_txt.append(' uint32_t retVal = (uint32_t)maxTID;') |
| 879 | header_txt.append(' tidMapping[maxTID++] = tid;') |
| 880 | header_txt.append(' assert(maxTID < MAX_TID);') |
| 881 | header_txt.append(' return retVal;') |
| 882 | header_txt.append('}') |
| 883 | return "\n".join(header_txt) |
| 884 | |
| 885 | def generate_body(self): |
| 886 | body = [self._generate_layer_dispatch_table(), |
| 887 | self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDumpCpp"), |
| 888 | self._generate_layer_gpa_function()] |
| 889 | |
| 890 | return "\n\n".join(body) |
| 891 | |
Tobin Ehlis | ea3d21b | 2014-11-12 13:11:15 -0700 | [diff] [blame] | 892 | class ApiDumpFileSubcommand(Subcommand): |
| 893 | def generate_header(self): |
Tobin Ehlis | d009bae | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 894 | header_txt = [] |
| 895 | 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') |
| 896 | header_txt.append('#define MAX_TID 513') |
| 897 | header_txt.append('static pthread_t tidMapping[MAX_TID] = {0};') |
| 898 | header_txt.append('static uint32_t maxTID = 0;') |
| 899 | header_txt.append('// Map actual TID to an index value and return that index') |
| 900 | header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs') |
| 901 | header_txt.append('static uint32_t getTIDIndex() {') |
| 902 | header_txt.append(' pthread_t tid = pthread_self();') |
| 903 | header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {') |
| 904 | header_txt.append(' if (tid == tidMapping[i])') |
| 905 | header_txt.append(' return i;') |
| 906 | header_txt.append(' }') |
| 907 | header_txt.append(" // Don't yet have mapping, set it and return newly set index") |
| 908 | header_txt.append(' uint32_t retVal = (uint32_t)maxTID;') |
| 909 | header_txt.append(' tidMapping[maxTID++] = tid;') |
| 910 | header_txt.append(' assert(maxTID < MAX_TID);') |
| 911 | header_txt.append(' return retVal;') |
| 912 | header_txt.append('}') |
| 913 | return "\n".join(header_txt) |
Tobin Ehlis | ea3d21b | 2014-11-12 13:11:15 -0700 | [diff] [blame] | 914 | |
| 915 | def generate_body(self): |
| 916 | body = [self._generate_layer_dispatch_table(), |
Tobin Ehlis | a363cfa | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 917 | self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDumpFile"), |
Tobin Ehlis | ea3d21b | 2014-11-12 13:11:15 -0700 | [diff] [blame] | 918 | self._generate_layer_gpa_function()] |
| 919 | |
| 920 | return "\n\n".join(body) |
| 921 | |
Tobin Ehlis | d49efcb | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 922 | class ApiDumpNoAddrSubcommand(Subcommand): |
| 923 | def generate_header(self): |
| 924 | header_txt = [] |
| 925 | 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') |
| 926 | header_txt.append('#define MAX_TID 513') |
| 927 | header_txt.append('static pthread_t tidMapping[MAX_TID] = {0};') |
| 928 | header_txt.append('static uint32_t maxTID = 0;') |
| 929 | header_txt.append('// Map actual TID to an index value and return that index') |
| 930 | header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs') |
| 931 | header_txt.append('static uint32_t getTIDIndex() {') |
| 932 | header_txt.append(' pthread_t tid = pthread_self();') |
| 933 | header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {') |
| 934 | header_txt.append(' if (tid == tidMapping[i])') |
| 935 | header_txt.append(' return i;') |
| 936 | header_txt.append(' }') |
| 937 | header_txt.append(" // Don't yet have mapping, set it and return newly set index") |
| 938 | header_txt.append(' uint32_t retVal = (uint32_t)maxTID;') |
| 939 | header_txt.append(' tidMapping[maxTID++] = tid;') |
| 940 | header_txt.append(' assert(maxTID < MAX_TID);') |
| 941 | header_txt.append(' return retVal;') |
| 942 | header_txt.append('}') |
| 943 | return "\n".join(header_txt) |
| 944 | |
| 945 | def generate_body(self): |
| 946 | body = [self._generate_layer_dispatch_table(), |
| 947 | self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDump", True), |
| 948 | self._generate_layer_gpa_function()] |
| 949 | |
| 950 | return "\n\n".join(body) |
| 951 | |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 952 | class ApiDumpNoAddrCppSubcommand(Subcommand): |
| 953 | def generate_header(self): |
| 954 | header_txt = [] |
| 955 | 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') |
| 956 | header_txt.append('#define MAX_TID 513') |
| 957 | header_txt.append('static pthread_t tidMapping[MAX_TID] = {0};') |
| 958 | header_txt.append('static uint32_t maxTID = 0;') |
| 959 | header_txt.append('// Map actual TID to an index value and return that index') |
| 960 | header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs') |
| 961 | header_txt.append('static uint32_t getTIDIndex() {') |
| 962 | header_txt.append(' pthread_t tid = pthread_self();') |
| 963 | header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {') |
| 964 | header_txt.append(' if (tid == tidMapping[i])') |
| 965 | header_txt.append(' return i;') |
| 966 | header_txt.append(' }') |
| 967 | header_txt.append(" // Don't yet have mapping, set it and return newly set index") |
| 968 | header_txt.append(' uint32_t retVal = (uint32_t)maxTID;') |
| 969 | header_txt.append(' tidMapping[maxTID++] = tid;') |
| 970 | header_txt.append(' assert(maxTID < MAX_TID);') |
| 971 | header_txt.append(' return retVal;') |
| 972 | header_txt.append('}') |
| 973 | return "\n".join(header_txt) |
| 974 | |
| 975 | def generate_body(self): |
| 976 | body = [self._generate_layer_dispatch_table(), |
| 977 | self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDumpCpp", True), |
| 978 | self._generate_layer_gpa_function()] |
| 979 | |
| 980 | return "\n\n".join(body) |
| 981 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 982 | class ObjectTrackerSubcommand(Subcommand): |
| 983 | def generate_header(self): |
| 984 | header_txt = [] |
| 985 | 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] | 986 | header_txt.append('#include "object_track.h"\n\nstatic XGL_LAYER_DISPATCH_TABLE nextTable;\nstatic XGL_BASE_LAYER_OBJECT *pCurObj;') |
| 987 | header_txt.append('static pthread_once_t tabOnce = PTHREAD_ONCE_INIT;\nstatic long long unsigned int object_track_index = 0;') |
| 988 | header_txt.append('// Ptr to LL of dbg functions') |
| 989 | header_txt.append('static XGL_LAYER_DBG_FUNCTION_NODE *pDbgFunctionHead = NULL;') |
| 990 | header_txt.append('// Utility function to handle reporting') |
| 991 | header_txt.append('// If callbacks are enabled, use them, otherwise use printf') |
| 992 | header_txt.append('static XGL_VOID layerCbMsg(XGL_DBG_MSG_TYPE msgType,') |
| 993 | header_txt.append(' XGL_VALIDATION_LEVEL validationLevel,') |
| 994 | header_txt.append(' XGL_BASE_OBJECT srcObject,') |
| 995 | header_txt.append(' XGL_SIZE location,') |
| 996 | header_txt.append(' XGL_INT msgCode,') |
Chia-I Wu | 1da4b9f | 2014-12-16 10:47:33 +0800 | [diff] [blame] | 997 | header_txt.append(' const char* pLayerPrefix,') |
| 998 | header_txt.append(' const char* pMsg)') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 999 | header_txt.append('{') |
| 1000 | header_txt.append(' XGL_LAYER_DBG_FUNCTION_NODE *pTrav = pDbgFunctionHead;') |
| 1001 | header_txt.append(' if (pTrav) {') |
| 1002 | header_txt.append(' while (pTrav) {') |
Chia-I Wu | f1a5a74 | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 1003 | header_txt.append(' pTrav->pfnMsgCallback(msgType, validationLevel, srcObject, location, msgCode, pMsg, pTrav->pUserData);') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1004 | header_txt.append(' pTrav = pTrav->pNext;') |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1005 | header_txt.append(' }') |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1006 | header_txt.append(' }') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1007 | header_txt.append(' else {') |
| 1008 | header_txt.append(' switch (msgType) {') |
| 1009 | header_txt.append(' case XGL_DBG_MSG_ERROR:') |
| 1010 | header_txt.append(' printf("{%s}ERROR : %s\\n", pLayerPrefix, pMsg);') |
| 1011 | header_txt.append(' break;') |
| 1012 | header_txt.append(' case XGL_DBG_MSG_WARNING:') |
| 1013 | header_txt.append(' printf("{%s}WARN : %s\\n", pLayerPrefix, pMsg);') |
| 1014 | header_txt.append(' break;') |
| 1015 | header_txt.append(' case XGL_DBG_MSG_PERF_WARNING:') |
| 1016 | header_txt.append(' printf("{%s}PERF_WARN : %s\\n", pLayerPrefix, pMsg);') |
| 1017 | header_txt.append(' break;') |
| 1018 | header_txt.append(' default:') |
| 1019 | header_txt.append(' printf("{%s}INFO : %s\\n", pLayerPrefix, pMsg);') |
| 1020 | header_txt.append(' break;') |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1021 | header_txt.append(' }') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1022 | header_txt.append(' }') |
| 1023 | header_txt.append('}') |
| 1024 | header_txt.append('// We maintain a "Global" list which links every object and a') |
| 1025 | header_txt.append('// per-Object list which just links objects of a given type') |
| 1026 | header_txt.append('// The object node has both pointers so the actual nodes are shared between the two lists') |
| 1027 | header_txt.append('typedef struct _objNode {') |
| 1028 | header_txt.append(' OBJTRACK_NODE obj;') |
| 1029 | header_txt.append(' struct _objNode *pNextObj;') |
| 1030 | header_txt.append(' struct _objNode *pNextGlobal;') |
| 1031 | header_txt.append('} objNode;') |
| 1032 | header_txt.append('static objNode *pObjectHead[XGL_NUM_OBJECT_TYPE] = {0};') |
| 1033 | header_txt.append('static objNode *pGlobalHead = NULL;') |
| 1034 | header_txt.append('static uint64_t numObjs[XGL_NUM_OBJECT_TYPE] = {0};') |
| 1035 | header_txt.append('static uint64_t numTotalObjs = 0;') |
| 1036 | header_txt.append('// Debug function to print global list and each individual object list') |
| 1037 | header_txt.append('static void ll_print_lists()') |
| 1038 | header_txt.append('{') |
| 1039 | header_txt.append(' objNode* pTrav = pGlobalHead;') |
| 1040 | header_txt.append(' printf("=====GLOBAL OBJECT LIST (%lu total objs):\\n", numTotalObjs);') |
| 1041 | header_txt.append(' while (pTrav) {') |
| 1042 | 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);') |
| 1043 | header_txt.append(' pTrav = pTrav->pNextGlobal;') |
| 1044 | header_txt.append(' }') |
| 1045 | header_txt.append(' for (uint32_t i = 0; i < XGL_NUM_OBJECT_TYPE; i++) {') |
| 1046 | header_txt.append(' pTrav = pObjectHead[i];') |
| 1047 | header_txt.append(' if (pTrav) {') |
| 1048 | header_txt.append(' printf("=====%s OBJECT LIST (%lu objs):\\n", string_XGL_OBJECT_TYPE(pTrav->obj.objType), numObjs[i]);') |
| 1049 | header_txt.append(' while (pTrav) {') |
| 1050 | 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);') |
| 1051 | header_txt.append(' pTrav = pTrav->pNextObj;') |
| 1052 | header_txt.append(' }') |
| 1053 | header_txt.append(' }') |
| 1054 | header_txt.append(' }') |
| 1055 | header_txt.append('}') |
| 1056 | header_txt.append('static void ll_insert_obj(XGL_VOID* pObj, XGL_OBJECT_TYPE objType) {') |
| 1057 | header_txt.append(' char str[1024];') |
| 1058 | header_txt.append(' sprintf(str, "OBJ[%llu] : CREATE %s object %p", object_track_index++, string_XGL_OBJECT_TYPE(objType), (void*)pObj);') |
| 1059 | header_txt.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_NONE, "OBJTRACK", str);') |
| 1060 | header_txt.append(' objNode* pNewObjNode = (objNode*)malloc(sizeof(objNode));') |
| 1061 | header_txt.append(' pNewObjNode->obj.pObj = pObj;') |
| 1062 | header_txt.append(' pNewObjNode->obj.objType = objType;') |
| 1063 | header_txt.append(' pNewObjNode->obj.numUses = 0;') |
| 1064 | header_txt.append(' // insert at front of global list') |
| 1065 | header_txt.append(' pNewObjNode->pNextGlobal = pGlobalHead;') |
| 1066 | header_txt.append(' pGlobalHead = pNewObjNode;') |
| 1067 | header_txt.append(' // insert at front of object list') |
| 1068 | header_txt.append(' pNewObjNode->pNextObj = pObjectHead[objType];') |
| 1069 | header_txt.append(' pObjectHead[objType] = pNewObjNode;') |
| 1070 | header_txt.append(' // increment obj counts') |
| 1071 | header_txt.append(' numObjs[objType]++;') |
| 1072 | header_txt.append(' numTotalObjs++;') |
| 1073 | 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] | 1074 | header_txt.append(' if (0) ll_print_lists();') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1075 | header_txt.append('}') |
| 1076 | header_txt.append('// Traverse global list and return type for given object') |
| 1077 | header_txt.append('static XGL_OBJECT_TYPE ll_get_obj_type(XGL_OBJECT object) {') |
| 1078 | header_txt.append(' objNode *pTrav = pGlobalHead;') |
| 1079 | header_txt.append(' while (pTrav) {') |
| 1080 | header_txt.append(' if (pTrav->obj.pObj == object)') |
| 1081 | header_txt.append(' return pTrav->obj.objType;') |
| 1082 | header_txt.append(' pTrav = pTrav->pNextGlobal;') |
| 1083 | header_txt.append(' }') |
| 1084 | header_txt.append(' char str[1024];') |
| 1085 | header_txt.append(' sprintf(str, "Attempting look-up on obj %p but it is NOT in the global list!", (void*)object);') |
| 1086 | header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, object, 0, OBJTRACK_MISSING_OBJECT, "OBJTRACK", str);') |
| 1087 | header_txt.append(' return XGL_OBJECT_TYPE_UNKNOWN;') |
| 1088 | header_txt.append('}') |
Chia-I Wu | 85763e5 | 2014-12-16 11:02:06 +0800 | [diff] [blame] | 1089 | header_txt.append('#if 0') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1090 | header_txt.append('static uint64_t ll_get_obj_uses(XGL_VOID* pObj, XGL_OBJECT_TYPE objType) {') |
| 1091 | header_txt.append(' objNode *pTrav = pObjectHead[objType];') |
| 1092 | header_txt.append(' while (pTrav) {') |
| 1093 | header_txt.append(' if (pTrav->obj.pObj == pObj) {') |
| 1094 | header_txt.append(' return pTrav->obj.numUses;') |
| 1095 | header_txt.append(' }') |
| 1096 | header_txt.append(' pTrav = pTrav->pNextObj;') |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1097 | header_txt.append(' }') |
| 1098 | header_txt.append(' return 0;') |
| 1099 | header_txt.append('}') |
Chia-I Wu | 85763e5 | 2014-12-16 11:02:06 +0800 | [diff] [blame] | 1100 | header_txt.append('#endif') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1101 | header_txt.append('static void ll_increment_use_count(XGL_VOID* pObj, XGL_OBJECT_TYPE objType) {') |
| 1102 | header_txt.append(' objNode *pTrav = pObjectHead[objType];') |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1103 | header_txt.append(' while (pTrav) {') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1104 | header_txt.append(' if (pTrav->obj.pObj == pObj) {') |
| 1105 | header_txt.append(' pTrav->obj.numUses++;') |
| 1106 | header_txt.append(' char str[1024];') |
| 1107 | 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);') |
| 1108 | header_txt.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_NONE, "OBJTRACK", str);') |
| 1109 | header_txt.append(' return;') |
| 1110 | header_txt.append(' }') |
| 1111 | header_txt.append(' pTrav = pTrav->pNextObj;') |
| 1112 | header_txt.append(' }') |
| 1113 | header_txt.append(' // If we do not find obj, insert it and then increment count') |
| 1114 | header_txt.append(' char str[1024];') |
| 1115 | 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));') |
| 1116 | header_txt.append(' layerCbMsg(XGL_DBG_MSG_WARNING, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);') |
| 1117 | header_txt.append('') |
| 1118 | header_txt.append(' ll_insert_obj(pObj, objType);') |
| 1119 | header_txt.append(' ll_increment_use_count(pObj, objType);') |
| 1120 | header_txt.append('}') |
| 1121 | header_txt.append('// We usually do not know Obj type when we destroy it so have to fetch') |
| 1122 | header_txt.append('// Type from global list w/ ll_destroy_obj()') |
| 1123 | header_txt.append('// and then do the full removal from both lists w/ ll_remove_obj_type()') |
| 1124 | header_txt.append('static void ll_remove_obj_type(XGL_VOID* pObj, XGL_OBJECT_TYPE objType) {') |
| 1125 | header_txt.append(' objNode *pTrav = pObjectHead[objType];') |
| 1126 | header_txt.append(' objNode *pPrev = pObjectHead[objType];') |
| 1127 | header_txt.append(' while (pTrav) {') |
| 1128 | header_txt.append(' if (pTrav->obj.pObj == pObj) {') |
| 1129 | header_txt.append(' pPrev->pNextObj = pTrav->pNextObj;') |
| 1130 | header_txt.append(' // update HEAD of Obj list as needed') |
| 1131 | header_txt.append(' if (pObjectHead[objType] == pTrav)') |
| 1132 | header_txt.append(' pObjectHead[objType] = pTrav->pNextObj;') |
| 1133 | header_txt.append(' assert(numObjs[objType] > 0);') |
| 1134 | header_txt.append(' numObjs[objType]--;') |
| 1135 | header_txt.append(' char str[1024];') |
| 1136 | header_txt.append(' sprintf(str, "OBJ[%llu] : DESTROY %s object %p", object_track_index++, string_XGL_OBJECT_TYPE(objType), (void*)pObj);') |
| 1137 | 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] | 1138 | header_txt.append(' return;') |
| 1139 | header_txt.append(' }') |
| 1140 | header_txt.append(' pPrev = pTrav;') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1141 | header_txt.append(' pTrav = pTrav->pNextObj;') |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1142 | header_txt.append(' }') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1143 | header_txt.append(' char str[1024];') |
| 1144 | 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));') |
| 1145 | header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_INTERNAL_ERROR, "OBJTRACK", str);') |
| 1146 | header_txt.append('}') |
| 1147 | header_txt.append('// Parse global list to find obj type, then remove obj from obj type list, finally') |
| 1148 | header_txt.append('// remove obj from global list') |
| 1149 | header_txt.append('static void ll_destroy_obj(XGL_VOID* pObj) {') |
| 1150 | header_txt.append(' objNode *pTrav = pGlobalHead;') |
| 1151 | header_txt.append(' objNode *pPrev = pGlobalHead;') |
| 1152 | header_txt.append(' while (pTrav) {') |
| 1153 | header_txt.append(' if (pTrav->obj.pObj == pObj) {') |
| 1154 | header_txt.append(' ll_remove_obj_type(pObj, pTrav->obj.objType);') |
| 1155 | header_txt.append(' pPrev->pNextGlobal = pTrav->pNextGlobal;') |
| 1156 | header_txt.append(' // update HEAD of global list if needed') |
| 1157 | header_txt.append(' if (pGlobalHead == pTrav)') |
| 1158 | header_txt.append(' pGlobalHead = pTrav->pNextGlobal;') |
| 1159 | header_txt.append(' free(pTrav);') |
| 1160 | header_txt.append(' assert(numTotalObjs > 0);') |
| 1161 | header_txt.append(' numTotalObjs--;') |
| 1162 | header_txt.append(' char str[1024];') |
| 1163 | 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));') |
| 1164 | header_txt.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_NONE, "OBJTRACK", str);') |
| 1165 | header_txt.append(' return;') |
| 1166 | header_txt.append(' }') |
| 1167 | header_txt.append(' pPrev = pTrav;') |
| 1168 | header_txt.append(' pTrav = pTrav->pNextGlobal;') |
| 1169 | header_txt.append(' }') |
| 1170 | header_txt.append(' char str[1024];') |
| 1171 | header_txt.append(' sprintf(str, "Unable to remove obj %p. Was it created? Has it already been destroyed?", pObj);') |
| 1172 | 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] | 1173 | header_txt.append('}') |
| 1174 | |
| 1175 | return "\n".join(header_txt) |
| 1176 | |
| 1177 | def generate_body(self): |
| 1178 | body = [self._generate_layer_dispatch_table(), |
Tobin Ehlis | a363cfa | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 1179 | self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "ObjectTracker"), |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1180 | self._generate_extensions(), |
| 1181 | self._generate_layer_gpa_function(extensions=['objTrackGetObjectCount', 'objTrackGetObjects'])] |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1182 | |
| 1183 | return "\n\n".join(body) |
Courtney Goeltzenleuchter | b412d21 | 2014-11-18 10:40:29 -0700 | [diff] [blame] | 1184 | |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1185 | class ParamCheckerSubcommand(Subcommand): |
| 1186 | def generate_header(self): |
| 1187 | 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#include "xgl_enum_validate_helper.h"\n#include "xgl_struct_validate_helper.h"\n\nstatic XGL_LAYER_DISPATCH_TABLE nextTable;\nstatic XGL_BASE_LAYER_OBJECT *pCurObj;\nstatic pthread_once_t tabOnce = PTHREAD_ONCE_INIT;\n' |
| 1188 | |
| 1189 | def generate_body(self): |
| 1190 | body = [self._gen_layer_dbg_callback_header(), |
| 1191 | self._generate_layer_dispatch_table(), |
| 1192 | self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "ParamChecker"), |
| 1193 | self._generate_layer_gpa_function()] |
| 1194 | |
| 1195 | return "\n\n".join(body) |
| 1196 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1197 | def main(): |
| 1198 | subcommands = { |
| 1199 | "layer-funcs" : LayerFuncsSubcommand, |
| 1200 | "layer-dispatch" : LayerDispatchSubcommand, |
Tobin Ehlis | a363cfa | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 1201 | "Generic" : GenericLayerSubcommand, |
| 1202 | "ApiDump" : ApiDumpSubcommand, |
| 1203 | "ApiDumpFile" : ApiDumpFileSubcommand, |
Tobin Ehlis | d49efcb | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 1204 | "ApiDumpNoAddr" : ApiDumpNoAddrSubcommand, |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1205 | "ApiDumpCpp" : ApiDumpCppSubcommand, |
| 1206 | "ApiDumpNoAddrCpp" : ApiDumpNoAddrCppSubcommand, |
Tobin Ehlis | a363cfa | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 1207 | "ObjectTracker" : ObjectTrackerSubcommand, |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1208 | "ParamChecker" : ParamCheckerSubcommand, |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1209 | } |
| 1210 | |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1211 | if len(sys.argv) < 3 or sys.argv[1] not in subcommands or not os.path.exists(sys.argv[2]): |
| 1212 | print("Usage: %s <subcommand> <input_header> [options]" % sys.argv[0]) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1213 | print |
| 1214 | print("Available sucommands are: %s" % " ".join(subcommands)) |
| 1215 | exit(1) |
| 1216 | |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1217 | hfp = xgl_helper.HeaderFileParser(sys.argv[2]) |
| 1218 | hfp.parse() |
| 1219 | xgl_helper.enum_val_dict = hfp.get_enum_val_dict() |
| 1220 | xgl_helper.enum_type_dict = hfp.get_enum_type_dict() |
| 1221 | xgl_helper.struct_dict = hfp.get_struct_dict() |
| 1222 | xgl_helper.typedef_fwd_dict = hfp.get_typedef_fwd_dict() |
| 1223 | xgl_helper.typedef_rev_dict = hfp.get_typedef_rev_dict() |
| 1224 | xgl_helper.types_dict = hfp.get_types_dict() |
| 1225 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1226 | subcmd = subcommands[sys.argv[1]](sys.argv[2:]) |
| 1227 | subcmd.run() |
| 1228 | |
| 1229 | if __name__ == "__main__": |
| 1230 | main() |