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 |
Tobin Ehlis | 7e65d75 | 2015-01-15 17:51:52 -0700 | [diff] [blame] | 100 | if xgl_helper.is_type(xgl_type, 'enum'):#"_TYPE" in xgl_type: # TODO : This should be generic ENUM check |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 101 | return ("%s", "string_%s(%s)" % (xgl_type.strip('const ').strip('*'), name)) |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 102 | if "char*" == xgl_type: |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 103 | return ("%s", name) |
Tobin Ehlis | 7e65d75 | 2015-01-15 17:51:52 -0700 | [diff] [blame] | 104 | if "uint64" in xgl_type: |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 105 | if '*' in xgl_type: |
| 106 | return ("%lu", "*%s" % name) |
| 107 | return ("%lu", name) |
Tobin Ehlis | 7e65d75 | 2015-01-15 17:51:52 -0700 | [diff] [blame] | 108 | if "size" in xgl_type: |
Chia-I Wu | 99ff89d | 2014-12-27 14:14:50 +0800 | [diff] [blame] | 109 | if '*' in xgl_type: |
| 110 | return ("%zu", "*%s" % name) |
| 111 | return ("%zu", name) |
Tobin Ehlis | 7e65d75 | 2015-01-15 17:51:52 -0700 | [diff] [blame] | 112 | if "float" in xgl_type: |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 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 | 7e65d75 | 2015-01-15 17:51:52 -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) |
Tobin Ehlis | 7e65d75 | 2015-01-15 17:51:52 -0700 | [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: |
Tobin Ehlis | d2b88e8 | 2015-02-04 15:15:11 -0700 | [diff] [blame] | 126 | if 'pUserData' == name: |
| 127 | return ("%i", "((pUserData == 0) ? 0 : *(pUserData))") |
Jon Ashburn | 52f79b5 | 2014-12-12 16:10:45 -0700 | [diff] [blame] | 128 | return ("%i", "*(%s)" % name) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 129 | return ("%i", name) |
Tobin Ehlis | 3a1cc8d | 2014-11-11 17:28:22 -0700 | [diff] [blame] | 130 | # 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] | 131 | if "XGL_FORMAT" == xgl_type: |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 132 | if cpp: |
| 133 | return ("%p", "&%s" % name) |
| 134 | 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] | 135 | if output_param: |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 136 | return ("%p", "(void*)*%s" % name) |
Courtney Goeltzenleuchter | d462fba | 2015-04-03 16:35:32 -0600 | [diff] [blame] | 137 | if xgl_helper.is_type(xgl_type, 'struct') and '*' not in xgl_type: |
| 138 | return ("%p", "(void*)(&%s)" % name) |
Jon Ashburn | 52f79b5 | 2014-12-12 16:10:45 -0700 | [diff] [blame] | 139 | return ("%p", "(void*)(%s)" % name) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 140 | |
Tobin Ehlis | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 141 | def _gen_layer_dbg_callback_register(self): |
| 142 | r_body = [] |
Courtney Goeltzenleuchter | c80a557 | 2015-04-13 14:10:06 -0600 | [diff] [blame] | 143 | r_body.append('XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglDbgRegisterMsgCallback(XGL_INSTANCE instance, XGL_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback, void* pUserData)') |
Tobin Ehlis | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 144 | r_body.append('{') |
| 145 | r_body.append(' // This layer intercepts callbacks') |
| 146 | r_body.append(' XGL_LAYER_DBG_FUNCTION_NODE *pNewDbgFuncNode = (XGL_LAYER_DBG_FUNCTION_NODE*)malloc(sizeof(XGL_LAYER_DBG_FUNCTION_NODE));') |
| 147 | r_body.append(' if (!pNewDbgFuncNode)') |
| 148 | r_body.append(' return XGL_ERROR_OUT_OF_MEMORY;') |
| 149 | r_body.append(' pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;') |
| 150 | r_body.append(' pNewDbgFuncNode->pUserData = pUserData;') |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 151 | r_body.append(' pNewDbgFuncNode->pNext = g_pDbgFunctionHead;') |
| 152 | r_body.append(' g_pDbgFunctionHead = pNewDbgFuncNode;') |
Jon Ashburn | a8aa837 | 2015-03-03 15:07:15 -0700 | [diff] [blame] | 153 | r_body.append(' // force callbacks if DebugAction hasn\'t been set already other than initial value') |
Ian Elliott | 6d9e41e | 2015-03-05 12:28:53 -0700 | [diff] [blame] | 154 | r_body.append(' if (g_actionIsDefault) {') |
Jon Ashburn | a8aa837 | 2015-03-03 15:07:15 -0700 | [diff] [blame] | 155 | r_body.append(' g_debugAction = XGL_DBG_LAYER_ACTION_CALLBACK;') |
Ian Elliott | 6d9e41e | 2015-03-05 12:28:53 -0700 | [diff] [blame] | 156 | r_body.append(' }') |
Courtney Goeltzenleuchter | c80a557 | 2015-04-13 14:10:06 -0600 | [diff] [blame] | 157 | r_body.append(' XGL_RESULT result = nextTable.DbgRegisterMsgCallback(instance, pfnMsgCallback, pUserData);') |
Tobin Ehlis | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 158 | r_body.append(' return result;') |
| 159 | r_body.append('}') |
| 160 | return "\n".join(r_body) |
| 161 | |
| 162 | def _gen_layer_dbg_callback_unregister(self): |
| 163 | ur_body = [] |
Courtney Goeltzenleuchter | c80a557 | 2015-04-13 14:10:06 -0600 | [diff] [blame] | 164 | ur_body.append('XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglDbgUnregisterMsgCallback(XGL_INSTANCE instance, XGL_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback)') |
Tobin Ehlis | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 165 | ur_body.append('{') |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 166 | ur_body.append(' XGL_LAYER_DBG_FUNCTION_NODE *pTrav = g_pDbgFunctionHead;') |
Tobin Ehlis | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 167 | ur_body.append(' XGL_LAYER_DBG_FUNCTION_NODE *pPrev = pTrav;') |
| 168 | ur_body.append(' while (pTrav) {') |
| 169 | ur_body.append(' if (pTrav->pfnMsgCallback == pfnMsgCallback) {') |
| 170 | ur_body.append(' pPrev->pNext = pTrav->pNext;') |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 171 | ur_body.append(' if (g_pDbgFunctionHead == pTrav)') |
| 172 | ur_body.append(' g_pDbgFunctionHead = pTrav->pNext;') |
Tobin Ehlis | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 173 | ur_body.append(' free(pTrav);') |
| 174 | ur_body.append(' break;') |
| 175 | ur_body.append(' }') |
| 176 | ur_body.append(' pPrev = pTrav;') |
| 177 | ur_body.append(' pTrav = pTrav->pNext;') |
| 178 | ur_body.append(' }') |
Jon Ashburn | a8aa837 | 2015-03-03 15:07:15 -0700 | [diff] [blame] | 179 | ur_body.append(' if (g_pDbgFunctionHead == NULL)') |
| 180 | ur_body.append(' {') |
| 181 | ur_body.append(' if (g_actionIsDefault)') |
| 182 | ur_body.append(' g_debugAction = XGL_DBG_LAYER_ACTION_LOG_MSG;') |
| 183 | ur_body.append(' else') |
| 184 | ur_body.append(' g_debugAction &= ~XGL_DBG_LAYER_ACTION_CALLBACK;') |
| 185 | ur_body.append(' }') |
Courtney Goeltzenleuchter | c80a557 | 2015-04-13 14:10:06 -0600 | [diff] [blame] | 186 | ur_body.append(' XGL_RESULT result = nextTable.DbgUnregisterMsgCallback(instance, pfnMsgCallback);') |
Tobin Ehlis | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 187 | ur_body.append(' return result;') |
| 188 | ur_body.append('}') |
| 189 | return "\n".join(ur_body) |
| 190 | |
Tobin Ehlis | d49efcb | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 191 | def _generate_dispatch_entrypoints(self, qual="", layer="Generic", no_addr=False): |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 192 | if qual: |
| 193 | qual += " " |
| 194 | |
Tobin Ehlis | a363cfa | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 195 | layer_name = layer |
Tobin Ehlis | d49efcb | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 196 | if no_addr: |
| 197 | layer_name = "%sNoAddr" % layer |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 198 | if 'Cpp' in layer_name: |
| 199 | layer_name = "APIDumpNoAddrCpp" |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 200 | funcs = [] |
| 201 | for proto in self.protos: |
| 202 | if proto.name != "GetProcAddr" and proto.name != "InitAndEnumerateGpus": |
Tobin Ehlis | a363cfa | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 203 | if "Generic" == layer: |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 204 | decl = proto.c_func(prefix="xgl", attr="XGLAPI") |
| 205 | param0_name = proto.params[0].name |
| 206 | ret_val = '' |
| 207 | stmt = '' |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 208 | if proto.ret != "void": |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 209 | ret_val = "XGL_RESULT result = " |
| 210 | stmt = " return result;\n" |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 211 | if 'WsiX11AssociateConnection' == proto.name: |
Ian Elliott | d1597d2 | 2015-02-26 14:34:52 -0700 | [diff] [blame] | 212 | funcs.append("#if defined(__linux__) || defined(XCB_NVIDIA)") |
Jon Ashburn | f7a0874 | 2014-11-25 11:08:42 -0700 | [diff] [blame] | 213 | if proto.name == "EnumerateLayers": |
| 214 | c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1) |
| 215 | funcs.append('%s%s\n' |
| 216 | '{\n' |
Tobin Ehlis | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 217 | ' char str[1024];\n' |
Jon Ashburn | f7a0874 | 2014-11-25 11:08:42 -0700 | [diff] [blame] | 218 | ' if (gpu != NULL) {\n' |
| 219 | ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n' |
Tobin Ehlis | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 220 | ' sprintf(str, "At start of layered %s\\n");\n' |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 221 | ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpu, 0, 0, (char *) "GENERIC", (char *) str);\n' |
Jon Ashburn | f7a0874 | 2014-11-25 11:08:42 -0700 | [diff] [blame] | 222 | ' pCurObj = gpuw;\n' |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 223 | ' loader_platform_thread_once(&tabOnce, init%s);\n' |
Jon Ashburn | f7a0874 | 2014-11-25 11:08:42 -0700 | [diff] [blame] | 224 | ' %snextTable.%s;\n' |
Tobin Ehlis | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 225 | ' sprintf(str, "Completed layered %s\\n");\n' |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 226 | ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpu, 0, 0, (char *) "GENERIC", (char *) str);\n' |
Jon Ashburn | f7a0874 | 2014-11-25 11:08:42 -0700 | [diff] [blame] | 227 | ' fflush(stdout);\n' |
| 228 | ' %s' |
| 229 | ' } else {\n' |
| 230 | ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n' |
| 231 | ' return XGL_ERROR_INVALID_POINTER;\n' |
| 232 | ' // This layer compatible with all GPUs\n' |
| 233 | ' *pOutLayerCount = 1;\n' |
Chia-I Wu | 1da4b9f | 2014-12-16 10:47:33 +0800 | [diff] [blame] | 234 | ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n' |
Jon Ashburn | f7a0874 | 2014-11-25 11:08:42 -0700 | [diff] [blame] | 235 | ' return XGL_SUCCESS;\n' |
| 236 | ' }\n' |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 237 | '}' % (qual, decl, proto.params[0].name, proto.name, layer_name, ret_val, c_call, proto.name, stmt, layer_name)) |
Tobin Ehlis | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 238 | elif 'DbgRegisterMsgCallback' == proto.name: |
| 239 | funcs.append(self._gen_layer_dbg_callback_register()) |
| 240 | elif 'DbgUnregisterMsgCallback' == proto.name: |
| 241 | funcs.append(self._gen_layer_dbg_callback_unregister()) |
Jon Ashburn | f7a0874 | 2014-11-25 11:08:42 -0700 | [diff] [blame] | 242 | elif proto.params[0].ty != "XGL_PHYSICAL_GPU": |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 243 | funcs.append('%s%s\n' |
| 244 | '{\n' |
| 245 | ' %snextTable.%s;\n' |
| 246 | '%s' |
| 247 | '}' % (qual, decl, ret_val, proto.c_call(), stmt)) |
| 248 | else: |
| 249 | c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1) |
| 250 | funcs.append('%s%s\n' |
| 251 | '{\n' |
Tobin Ehlis | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 252 | ' char str[1024];' |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 253 | ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n' |
Tobin Ehlis | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 254 | ' sprintf(str, "At start of layered %s\\n");\n' |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 255 | ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpuw, 0, 0, (char *) "GENERIC", (char *) str);\n' |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 256 | ' pCurObj = gpuw;\n' |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 257 | ' loader_platform_thread_once(&tabOnce, init%s);\n' |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 258 | ' %snextTable.%s;\n' |
Tobin Ehlis | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 259 | ' sprintf(str, "Completed layered %s\\n");\n' |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 260 | ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpuw, 0, 0, (char *) "GENERIC", (char *) str);\n' |
Courtney Goeltzenleuchter | b412d21 | 2014-11-18 10:40:29 -0700 | [diff] [blame] | 261 | ' fflush(stdout);\n' |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 262 | '%s' |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 263 | '}' % (qual, decl, proto.params[0].name, proto.name, layer_name, ret_val, c_call, proto.name, stmt)) |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 264 | if 'WsiX11QueuePresent' == proto.name: |
| 265 | funcs.append("#endif") |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 266 | elif "APIDumpCpp" in layer: |
| 267 | decl = proto.c_func(prefix="xgl", attr="XGLAPI") |
| 268 | param0_name = proto.params[0].name |
| 269 | ret_val = '' |
| 270 | stmt = '' |
Tobin Ehlis | 291cd70 | 2015-01-20 09:48:48 -0700 | [diff] [blame] | 271 | sp_param_dict = {} # Store 'index' for struct param to print, or an name of binding "Count" param for array to print |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 272 | create_params = 0 # Num of params at end of function that are created and returned as output values |
Tobin Ehlis | 291cd70 | 2015-01-20 09:48:48 -0700 | [diff] [blame] | 273 | if 'WsiX11CreatePresentableImage' in proto.name or 'AllocDescriptorSets' in proto.name: |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 274 | create_params = -2 |
| 275 | elif 'Create' in proto.name or 'Alloc' in proto.name or 'MapMemory' in proto.name: |
| 276 | create_params = -1 |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 277 | if proto.ret != "void": |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 278 | ret_val = "XGL_RESULT result = " |
| 279 | stmt = " return result;\n" |
| 280 | f_open = '' |
| 281 | f_close = '' |
| 282 | if "File" in layer: |
| 283 | file_mode = "a" |
| 284 | if 'CreateDevice' in proto.name: |
| 285 | file_mode = "w" |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 286 | f_open = 'loader_platform_thread_lock_mutex(&printLock);\n pOutFile = fopen(outFileName, "%s");\n ' % (file_mode) |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 287 | log_func = 'fprintf(pOutFile, "t{%%u} xgl%s(' % proto.name |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 288 | f_close = '\n fclose(pOutFile);\n loader_platform_thread_unlock_mutex(&printLock);' |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 289 | else: |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 290 | f_open = 'loader_platform_thread_lock_mutex(&printLock);\n ' |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 291 | log_func = 'cout << "t{" << getTIDIndex() << "} xgl%s(' % proto.name |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 292 | f_close = '\n loader_platform_thread_unlock_mutex(&printLock);' |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 293 | pindex = 0 |
Tobin Ehlis | 291cd70 | 2015-01-20 09:48:48 -0700 | [diff] [blame] | 294 | prev_count_name = '' |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 295 | for p in proto.params: |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 296 | cp = False |
| 297 | if 0 != create_params: |
| 298 | # If this is any of the N last params of the func, treat as output |
| 299 | for y in range(-1, create_params-1, -1): |
| 300 | if p.name == proto.params[y].name: |
| 301 | cp = True |
| 302 | (pft, pfi) = self._get_printf_params(p.ty, p.name, cp, cpp=True) |
| 303 | if no_addr and "%p" == pft: |
| 304 | (pft, pfi) = ("%s", '"addr"') |
| 305 | log_func += '%s = " << %s << ", ' % (p.name, pfi) |
| 306 | #print_vals += ', %s' % (pfi) |
Tobin Ehlis | 291cd70 | 2015-01-20 09:48:48 -0700 | [diff] [blame] | 307 | if prev_count_name != '' and (prev_count_name.strip('Count')[1:] in p.name or 'slotCount' == prev_count_name): |
| 308 | sp_param_dict[pindex] = prev_count_name |
| 309 | elif 'pDescriptorSets' == p.name and proto.params[-1].name == 'pCount': |
| 310 | sp_param_dict[pindex] = '*pCount' |
Tobin Ehlis | f29cc37 | 2015-01-22 12:29:31 -0700 | [diff] [blame] | 311 | elif 'Wsi' not in proto.name and xgl_helper.is_type(p.ty.strip('*').strip('const '), 'struct'): |
| 312 | sp_param_dict[pindex] = 'index' |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 313 | pindex += 1 |
Tobin Ehlis | 291cd70 | 2015-01-20 09:48:48 -0700 | [diff] [blame] | 314 | if p.name.endswith('Count'): |
| 315 | if '*' in p.ty: |
| 316 | prev_count_name = "*%s" % p.name |
| 317 | else: |
| 318 | prev_count_name = p.name |
| 319 | else: |
| 320 | prev_count_name = '' |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 321 | log_func = log_func.strip(', ') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 322 | if proto.ret != "void": |
Courtney Goeltzenleuchter | b7f22da | 2015-02-26 11:40:39 -0700 | [diff] [blame] | 323 | log_func += ') = " << string_XGL_RESULT((XGL_RESULT)result) << endl' |
Tobin Ehlis | 7e65d75 | 2015-01-15 17:51:52 -0700 | [diff] [blame] | 324 | #print_vals += ', string_XGL_RESULT_CODE(result)' |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 325 | else: |
| 326 | log_func += ')\\n"' |
| 327 | log_func += ';' |
Tobin Ehlis | 291cd70 | 2015-01-20 09:48:48 -0700 | [diff] [blame] | 328 | if len(sp_param_dict) > 0: |
| 329 | i_decl = False |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 330 | log_func += '\n string tmp_str;' |
Tobin Ehlis | 291cd70 | 2015-01-20 09:48:48 -0700 | [diff] [blame] | 331 | for sp_index in sp_param_dict: |
| 332 | if 'index' == sp_param_dict[sp_index]: |
| 333 | cis_print_func = 'xgl_print_%s' % (proto.params[sp_index].ty.strip('const ').strip('*').lower()) |
Courtney Goeltzenleuchter | d462fba | 2015-04-03 16:35:32 -0600 | [diff] [blame] | 334 | var_name = proto.params[sp_index].name |
| 335 | if proto.params[sp_index].name != 'color': |
| 336 | log_func += '\n if (%s) {' % (proto.params[sp_index].name) |
| 337 | else: |
| 338 | var_name = '&%s' % (proto.params[sp_index].name) |
| 339 | log_func += '\n tmp_str = %s(%s, " ");' % (cis_print_func, var_name) |
Tobin Ehlis | 291cd70 | 2015-01-20 09:48:48 -0700 | [diff] [blame] | 340 | if "File" in layer: |
| 341 | if no_addr: |
| 342 | log_func += '\n fprintf(pOutFile, " %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name) |
| 343 | else: |
Courtney Goeltzenleuchter | d462fba | 2015-04-03 16:35:32 -0600 | [diff] [blame] | 344 | log_func += '\n fprintf(pOutFile, " %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, var_name) |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 345 | else: |
Tobin Ehlis | 291cd70 | 2015-01-20 09:48:48 -0700 | [diff] [blame] | 346 | if no_addr: |
| 347 | #log_func += '\n printf(" %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name) |
| 348 | log_func += '\n cout << " %s (addr)" << endl << tmp_str << endl;' % (proto.params[sp_index].name) |
| 349 | else: |
| 350 | #log_func += '\n printf(" %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name) |
Courtney Goeltzenleuchter | d462fba | 2015-04-03 16:35:32 -0600 | [diff] [blame] | 351 | log_func += '\n cout << " %s (" << %s << ")" << endl << tmp_str << endl;' % (proto.params[sp_index].name, var_name) |
Tobin Ehlis | 291cd70 | 2015-01-20 09:48:48 -0700 | [diff] [blame] | 352 | #log_func += '\n fflush(stdout);' |
Courtney Goeltzenleuchter | d462fba | 2015-04-03 16:35:32 -0600 | [diff] [blame] | 353 | if proto.params[sp_index].name != 'color': |
| 354 | log_func += '\n }' |
Tobin Ehlis | 291cd70 | 2015-01-20 09:48:48 -0700 | [diff] [blame] | 355 | else: # We have a count value stored to iterate over an array |
| 356 | print_cast = '' |
| 357 | print_func = '' |
| 358 | if xgl_helper.is_type(proto.params[sp_index].ty.strip('*').strip('const '), 'struct'): |
| 359 | print_cast = '&' |
| 360 | print_func = 'xgl_print_%s' % proto.params[sp_index].ty.strip('const ').strip('*').lower() |
| 361 | #cis_print_func = 'tmp_str = xgl_print_%s(&%s[i], " ");' % (proto.params[sp_index].ty.strip('const ').strip('*').lower(), proto.params[sp_index].name) |
| 362 | # TODO : Need to display this address as a string |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 363 | else: |
Tobin Ehlis | 291cd70 | 2015-01-20 09:48:48 -0700 | [diff] [blame] | 364 | print_cast = '(void*)' |
| 365 | print_func = 'string_convert_helper' |
| 366 | #cis_print_func = 'tmp_str = string_convert_helper((void*)%s[i], " ");' % proto.params[sp_index].name |
| 367 | cis_print_func = 'tmp_str = %s(%s%s[i], " ");' % (print_func, print_cast, proto.params[sp_index].name) |
| 368 | # else: |
| 369 | # cis_print_func = '' |
| 370 | if not i_decl: |
| 371 | log_func += '\n uint32_t i;' |
| 372 | i_decl = True |
| 373 | log_func += '\n for (i = 0; i < %s; i++) {' % (sp_param_dict[sp_index]) |
| 374 | log_func += '\n %s' % (cis_print_func) |
| 375 | if "File" in layer: |
| 376 | if no_addr: |
| 377 | log_func += '\n fprintf(pOutFile, " %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name) |
| 378 | else: |
| 379 | log_func += '\n fprintf(pOutFile, " %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name) |
| 380 | else: |
| 381 | if no_addr: |
| 382 | #log_func += '\n printf(" %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name) |
| 383 | log_func += '\n cout << " %s[" << (uint32_t)i << "] (addr)" << endl << tmp_str << endl;' % (proto.params[sp_index].name) |
| 384 | else: |
| 385 | #log_func += '\n printf(" %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name) |
| 386 | #log_func += '\n cout << " %s[" << (uint32_t)i << "] (" << %s[i] << ")" << endl << tmp_str << endl;' % (proto.params[sp_index].name, proto.params[sp_index].name) |
| 387 | log_func += '\n cout << " %s[" << i << "] (" << %s%s[i] << ")" << endl << tmp_str << endl;' % (proto.params[sp_index].name, print_cast, proto.params[sp_index].name) |
| 388 | #log_func += '\n fflush(stdout);' |
| 389 | log_func += '\n }' |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 390 | if 'WsiX11AssociateConnection' == proto.name: |
Ian Elliott | d1597d2 | 2015-02-26 14:34:52 -0700 | [diff] [blame] | 391 | funcs.append("#if defined(__linux__) || defined(XCB_NVIDIA)") |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 392 | if proto.name == "EnumerateLayers": |
| 393 | c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1) |
| 394 | funcs.append('%s%s\n' |
| 395 | '{\n' |
| 396 | ' if (gpu != NULL) {\n' |
| 397 | ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n' |
| 398 | ' pCurObj = gpuw;\n' |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 399 | ' loader_platform_thread_once(&tabOnce, init%s);\n' |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 400 | ' %snextTable.%s;\n' |
| 401 | ' %s %s %s\n' |
| 402 | ' %s' |
| 403 | ' } else {\n' |
| 404 | ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n' |
| 405 | ' return XGL_ERROR_INVALID_POINTER;\n' |
| 406 | ' // This layer compatible with all GPUs\n' |
| 407 | ' *pOutLayerCount = 1;\n' |
| 408 | ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n' |
| 409 | ' return XGL_SUCCESS;\n' |
| 410 | ' }\n' |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 411 | '}' % (qual, decl, proto.params[0].name, layer_name, ret_val, c_call,f_open, log_func, f_close, stmt, layer_name)) |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 412 | elif proto.params[0].ty != "XGL_PHYSICAL_GPU": |
| 413 | funcs.append('%s%s\n' |
| 414 | '{\n' |
| 415 | ' %snextTable.%s;\n' |
| 416 | ' %s%s%s\n' |
| 417 | '%s' |
| 418 | '}' % (qual, decl, ret_val, proto.c_call(), f_open, log_func, f_close, stmt)) |
| 419 | else: |
| 420 | c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1) |
| 421 | funcs.append('%s%s\n' |
| 422 | '{\n' |
| 423 | ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n' |
| 424 | ' pCurObj = gpuw;\n' |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 425 | ' loader_platform_thread_once(&tabOnce, init%s);\n' |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 426 | ' %snextTable.%s;\n' |
| 427 | ' %s%s%s\n' |
| 428 | '%s' |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 429 | '}' % (qual, decl, proto.params[0].name, layer_name, ret_val, c_call, f_open, log_func, f_close, stmt)) |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 430 | if 'WsiX11QueuePresent' == proto.name: |
| 431 | funcs.append("#endif") |
Tobin Ehlis | a363cfa | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 432 | elif "APIDump" in layer: |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 433 | decl = proto.c_func(prefix="xgl", attr="XGLAPI") |
| 434 | param0_name = proto.params[0].name |
| 435 | ret_val = '' |
| 436 | stmt = '' |
Tobin Ehlis | 291cd70 | 2015-01-20 09:48:48 -0700 | [diff] [blame] | 437 | sp_param_dict = {} # Store 'index' for struct param to print, or an name of binding "Count" param for array to print |
Tobin Ehlis | e727157 | 2014-11-19 15:52:46 -0700 | [diff] [blame] | 438 | create_params = 0 # Num of params at end of function that are created and returned as output values |
| 439 | if 'WsiX11CreatePresentableImage' in proto.name: |
| 440 | create_params = -2 |
| 441 | elif 'Create' in proto.name or 'Alloc' in proto.name or 'MapMemory' in proto.name: |
| 442 | create_params = -1 |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 443 | if proto.ret != "void": |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 444 | ret_val = "XGL_RESULT result = " |
| 445 | stmt = " return result;\n" |
Tobin Ehlis | ea3d21b | 2014-11-12 13:11:15 -0700 | [diff] [blame] | 446 | f_open = '' |
| 447 | f_close = '' |
Tobin Ehlis | a363cfa | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 448 | if "File" in layer: |
Tobin Ehlis | dbcd257 | 2014-11-21 09:35:53 -0700 | [diff] [blame] | 449 | file_mode = "a" |
| 450 | if 'CreateDevice' in proto.name: |
| 451 | file_mode = "w" |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 452 | f_open = 'loader_platform_thread_lock_mutex(&printLock);\n pOutFile = fopen(outFileName, "%s");\n ' % (file_mode) |
Tobin Ehlis | d009bae | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 453 | log_func = 'fprintf(pOutFile, "t{%%u} xgl%s(' % proto.name |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 454 | f_close = '\n fclose(pOutFile);\n loader_platform_thread_unlock_mutex(&printLock);' |
Tobin Ehlis | ea3d21b | 2014-11-12 13:11:15 -0700 | [diff] [blame] | 455 | else: |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 456 | f_open = 'loader_platform_thread_lock_mutex(&printLock);\n ' |
Tobin Ehlis | d009bae | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 457 | log_func = 'printf("t{%%u} xgl%s(' % proto.name |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 458 | f_close = '\n loader_platform_thread_unlock_mutex(&printLock);' |
Tobin Ehlis | d009bae | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 459 | print_vals = ', getTIDIndex()' |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 460 | pindex = 0 |
Tobin Ehlis | 3bd868a | 2014-12-18 15:20:05 -0700 | [diff] [blame] | 461 | prev_count_name = '' |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 462 | for p in proto.params: |
Tobin Ehlis | e727157 | 2014-11-19 15:52:46 -0700 | [diff] [blame] | 463 | cp = False |
| 464 | if 0 != create_params: |
| 465 | # If this is any of the N last params of the func, treat as output |
| 466 | for y in range(-1, create_params-1, -1): |
| 467 | if p.name == proto.params[y].name: |
| 468 | cp = True |
| 469 | (pft, pfi) = self._get_printf_params(p.ty, p.name, cp) |
Tobin Ehlis | d49efcb | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 470 | if no_addr and "%p" == pft: |
| 471 | (pft, pfi) = ("%s", '"addr"') |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 472 | log_func += '%s = %s, ' % (p.name, pft) |
| 473 | print_vals += ', %s' % (pfi) |
Tobin Ehlis | 3bd868a | 2014-12-18 15:20:05 -0700 | [diff] [blame] | 474 | # Catch array inputs that are bound by a "Count" param |
| 475 | if prev_count_name != '' and (prev_count_name.strip('Count')[1:] in p.name or 'slotCount' == prev_count_name): |
| 476 | sp_param_dict[pindex] = prev_count_name |
Tobin Ehlis | 291cd70 | 2015-01-20 09:48:48 -0700 | [diff] [blame] | 477 | elif 'pDescriptorSets' == p.name and proto.params[-1].name == 'pCount': |
| 478 | sp_param_dict[pindex] = '*pCount' |
Tobin Ehlis | 7e65d75 | 2015-01-15 17:51:52 -0700 | [diff] [blame] | 479 | elif 'Wsi' not in proto.name and xgl_helper.is_type(p.ty.strip('*').strip('const '), 'struct'): |
Tobin Ehlis | 3bd868a | 2014-12-18 15:20:05 -0700 | [diff] [blame] | 480 | sp_param_dict[pindex] = 'index' |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 481 | pindex += 1 |
Tobin Ehlis | 3bd868a | 2014-12-18 15:20:05 -0700 | [diff] [blame] | 482 | if p.name.endswith('Count'): |
Courtney Goeltzenleuchter | 1b587b1 | 2015-01-13 15:32:18 -0700 | [diff] [blame] | 483 | if '*' in p.ty: |
| 484 | prev_count_name = "*%s" % p.name |
| 485 | else: |
| 486 | prev_count_name = p.name |
Tobin Ehlis | 3bd868a | 2014-12-18 15:20:05 -0700 | [diff] [blame] | 487 | else: |
| 488 | prev_count_name = '' |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 489 | log_func = log_func.strip(', ') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 490 | if proto.ret != "void": |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 491 | log_func += ') = %s\\n"' |
Courtney Goeltzenleuchter | b412d21 | 2014-11-18 10:40:29 -0700 | [diff] [blame] | 492 | print_vals += ', string_XGL_RESULT(result)' |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 493 | else: |
| 494 | log_func += ')\\n"' |
| 495 | log_func = '%s%s);' % (log_func, print_vals) |
Tobin Ehlis | 3bd868a | 2014-12-18 15:20:05 -0700 | [diff] [blame] | 496 | if len(sp_param_dict) > 0: |
| 497 | i_decl = False |
| 498 | log_func += '\n char *pTmpStr = "";' |
| 499 | for sp_index in sorted(sp_param_dict): |
| 500 | # TODO : Clean this if/else block up, too much duplicated code |
| 501 | if 'index' == sp_param_dict[sp_index]: |
| 502 | cis_print_func = 'xgl_print_%s' % (proto.params[sp_index].ty.strip('const ').strip('*').lower()) |
Courtney Goeltzenleuchter | d462fba | 2015-04-03 16:35:32 -0600 | [diff] [blame] | 503 | var_name = proto.params[sp_index].name |
| 504 | if proto.params[sp_index].name != 'color': |
| 505 | log_func += '\n if (%s) {' % (proto.params[sp_index].name) |
| 506 | else: |
| 507 | var_name = "&%s" % proto.params[sp_index].name |
| 508 | log_func += '\n pTmpStr = %s(%s, " ");' % (cis_print_func, var_name) |
Tobin Ehlis | 3bd868a | 2014-12-18 15:20:05 -0700 | [diff] [blame] | 509 | if "File" in layer: |
| 510 | if no_addr: |
Courtney Goeltzenleuchter | d462fba | 2015-04-03 16:35:32 -0600 | [diff] [blame] | 511 | log_func += '\n fprintf(pOutFile, " %s (addr)\\n%%s\\n", pTmpStr);' % (var_name) |
Tobin Ehlis | 3bd868a | 2014-12-18 15:20:05 -0700 | [diff] [blame] | 512 | else: |
Courtney Goeltzenleuchter | d462fba | 2015-04-03 16:35:32 -0600 | [diff] [blame] | 513 | log_func += '\n fprintf(pOutFile, " %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (var_name, var_name) |
Tobin Ehlis | d49efcb | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 514 | else: |
Tobin Ehlis | 3bd868a | 2014-12-18 15:20:05 -0700 | [diff] [blame] | 515 | if no_addr: |
| 516 | log_func += '\n printf(" %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name) |
| 517 | else: |
Courtney Goeltzenleuchter | d462fba | 2015-04-03 16:35:32 -0600 | [diff] [blame] | 518 | log_func += '\n printf(" %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, var_name) |
Tobin Ehlis | 3bd868a | 2014-12-18 15:20:05 -0700 | [diff] [blame] | 519 | log_func += '\n fflush(stdout);' |
Courtney Goeltzenleuchter | d462fba | 2015-04-03 16:35:32 -0600 | [diff] [blame] | 520 | log_func += '\n free(pTmpStr);' |
| 521 | if proto.params[sp_index].name != 'color': |
| 522 | log_func += '\n }' |
Tobin Ehlis | 3bd868a | 2014-12-18 15:20:05 -0700 | [diff] [blame] | 523 | else: # should have a count value stored to iterate over array |
| 524 | if xgl_helper.is_type(proto.params[sp_index].ty.strip('*').strip('const '), 'struct'): |
| 525 | cis_print_func = 'pTmpStr = xgl_print_%s(&%s[i], " ");' % (proto.params[sp_index].ty.strip('const ').strip('*').lower(), proto.params[sp_index].name) |
Tobin Ehlis | d49efcb | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 526 | else: |
Mike Stroyan | b30f3ed | 2015-03-03 16:54:24 -0700 | [diff] [blame] | 527 | cis_print_func = 'pTmpStr = (char*)malloc(32);\n sprintf(pTmpStr, " %%p", %s[i]);' % proto.params[sp_index].name |
Tobin Ehlis | 3bd868a | 2014-12-18 15:20:05 -0700 | [diff] [blame] | 528 | if not i_decl: |
| 529 | log_func += '\n uint32_t i;' |
| 530 | i_decl = True |
Jon Ashburn | 8219c04 | 2015-01-14 08:52:37 -0700 | [diff] [blame] | 531 | log_func += '\n for (i = 0; i < %s; i++) {' % (sp_param_dict[sp_index]) |
Tobin Ehlis | 3bd868a | 2014-12-18 15:20:05 -0700 | [diff] [blame] | 532 | log_func += '\n %s' % (cis_print_func) |
| 533 | if "File" in layer: |
| 534 | if no_addr: |
| 535 | log_func += '\n fprintf(pOutFile, " %s[%%i] (addr)\\n%%s\\n", i, pTmpStr);' % (proto.params[sp_index].name) |
| 536 | else: |
| 537 | log_func += '\n fprintf(pOutFile, " %s[%%i] (%%p)\\n%%s\\n", i, (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name) |
| 538 | else: |
| 539 | if no_addr: |
| 540 | log_func += '\n printf(" %s[%%i] (addr)\\n%%s\\n", i, pTmpStr);' % (proto.params[sp_index].name) |
| 541 | else: |
| 542 | log_func += '\n printf(" %s[%%i] (%%p)\\n%%s\\n", i, (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name) |
| 543 | log_func += '\n fflush(stdout);' |
| 544 | log_func += '\n free(pTmpStr);\n }' |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 545 | if 'WsiX11AssociateConnection' == proto.name: |
Ian Elliott | d1597d2 | 2015-02-26 14:34:52 -0700 | [diff] [blame] | 546 | funcs.append("#if defined(__linux__) || defined(XCB_NVIDIA)") |
Jon Ashburn | f7a0874 | 2014-11-25 11:08:42 -0700 | [diff] [blame] | 547 | if proto.name == "EnumerateLayers": |
| 548 | c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1) |
| 549 | funcs.append('%s%s\n' |
| 550 | '{\n' |
| 551 | ' if (gpu != NULL) {\n' |
| 552 | ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n' |
| 553 | ' pCurObj = gpuw;\n' |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 554 | ' loader_platform_thread_once(&tabOnce, init%s);\n' |
Jon Ashburn | f7a0874 | 2014-11-25 11:08:42 -0700 | [diff] [blame] | 555 | ' %snextTable.%s;\n' |
| 556 | ' %s %s %s\n' |
| 557 | ' %s' |
| 558 | ' } else {\n' |
| 559 | ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n' |
| 560 | ' return XGL_ERROR_INVALID_POINTER;\n' |
| 561 | ' // This layer compatible with all GPUs\n' |
| 562 | ' *pOutLayerCount = 1;\n' |
Chia-I Wu | 1da4b9f | 2014-12-16 10:47:33 +0800 | [diff] [blame] | 563 | ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n' |
Jon Ashburn | f7a0874 | 2014-11-25 11:08:42 -0700 | [diff] [blame] | 564 | ' return XGL_SUCCESS;\n' |
| 565 | ' }\n' |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 566 | '}' % (qual, decl, proto.params[0].name, layer_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] | 567 | elif proto.params[0].ty != "XGL_PHYSICAL_GPU": |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 568 | funcs.append('%s%s\n' |
| 569 | '{\n' |
| 570 | ' %snextTable.%s;\n' |
Tobin Ehlis | ea3d21b | 2014-11-12 13:11:15 -0700 | [diff] [blame] | 571 | ' %s%s%s\n' |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 572 | '%s' |
Tobin Ehlis | ea3d21b | 2014-11-12 13:11:15 -0700 | [diff] [blame] | 573 | '}' % (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] | 574 | else: |
| 575 | c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1) |
| 576 | funcs.append('%s%s\n' |
| 577 | '{\n' |
| 578 | ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n' |
| 579 | ' pCurObj = gpuw;\n' |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 580 | ' loader_platform_thread_once(&tabOnce, init%s);\n' |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 581 | ' %snextTable.%s;\n' |
Tobin Ehlis | ea3d21b | 2014-11-12 13:11:15 -0700 | [diff] [blame] | 582 | ' %s%s%s\n' |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 583 | '%s' |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 584 | '}' % (qual, decl, proto.params[0].name, layer_name, ret_val, c_call, f_open, log_func, f_close, stmt)) |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 585 | if 'WsiX11QueuePresent' == proto.name: |
| 586 | funcs.append("#endif") |
Tobin Ehlis | a363cfa | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 587 | elif "ObjectTracker" == layer: |
Tobin Ehlis | 7e65d75 | 2015-01-15 17:51:52 -0700 | [diff] [blame] | 588 | obj_type_mapping = {base_t : base_t.replace("XGL_", "XGL_OBJECT_TYPE_") for base_t in xgl.object_type_list} |
| 589 | # For the various "super-types" we have to use function to distinguish sub type |
| 590 | for obj_type in ["XGL_BASE_OBJECT", "XGL_OBJECT", "XGL_DYNAMIC_STATE_OBJECT"]: |
| 591 | obj_type_mapping[obj_type] = "ll_get_obj_type(object)" |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 592 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 593 | decl = proto.c_func(prefix="xgl", attr="XGLAPI") |
| 594 | param0_name = proto.params[0].name |
Tobin Ehlis | 7e65d75 | 2015-01-15 17:51:52 -0700 | [diff] [blame] | 595 | p0_type = proto.params[0].ty.strip('*').strip('const ') |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 596 | create_line = '' |
| 597 | destroy_line = '' |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 598 | if 'DbgRegisterMsgCallback' in proto.name: |
| 599 | using_line = ' // This layer intercepts callbacks\n' |
| 600 | using_line += ' XGL_LAYER_DBG_FUNCTION_NODE *pNewDbgFuncNode = (XGL_LAYER_DBG_FUNCTION_NODE*)malloc(sizeof(XGL_LAYER_DBG_FUNCTION_NODE));\n' |
| 601 | using_line += ' if (!pNewDbgFuncNode)\n' |
| 602 | using_line += ' return XGL_ERROR_OUT_OF_MEMORY;\n' |
| 603 | using_line += ' pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;\n' |
| 604 | using_line += ' pNewDbgFuncNode->pUserData = pUserData;\n' |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 605 | using_line += ' pNewDbgFuncNode->pNext = g_pDbgFunctionHead;\n' |
| 606 | using_line += ' g_pDbgFunctionHead = pNewDbgFuncNode;\n' |
Jon Ashburn | a8aa837 | 2015-03-03 15:07:15 -0700 | [diff] [blame] | 607 | using_line += ' // force callbacks if DebugAction hasn\'t been set already other than initial value\n' |
Ian Elliott | 6d9e41e | 2015-03-05 12:28:53 -0700 | [diff] [blame] | 608 | using_line += ' if (g_actionIsDefault) {\n' |
Jon Ashburn | a8aa837 | 2015-03-03 15:07:15 -0700 | [diff] [blame] | 609 | using_line += ' g_debugAction = XGL_DBG_LAYER_ACTION_CALLBACK;\n' |
Ian Elliott | 6d9e41e | 2015-03-05 12:28:53 -0700 | [diff] [blame] | 610 | using_line += ' }' |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 611 | elif 'DbgUnregisterMsgCallback' in proto.name: |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 612 | using_line = ' XGL_LAYER_DBG_FUNCTION_NODE *pTrav = g_pDbgFunctionHead;\n' |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 613 | using_line += ' XGL_LAYER_DBG_FUNCTION_NODE *pPrev = pTrav;\n' |
| 614 | using_line += ' while (pTrav) {\n' |
| 615 | using_line += ' if (pTrav->pfnMsgCallback == pfnMsgCallback) {\n' |
| 616 | using_line += ' pPrev->pNext = pTrav->pNext;\n' |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 617 | using_line += ' if (g_pDbgFunctionHead == pTrav)\n' |
| 618 | using_line += ' g_pDbgFunctionHead = pTrav->pNext;\n' |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 619 | using_line += ' free(pTrav);\n' |
| 620 | using_line += ' break;\n' |
| 621 | using_line += ' }\n' |
| 622 | using_line += ' pPrev = pTrav;\n' |
| 623 | using_line += ' pTrav = pTrav->pNext;\n' |
| 624 | using_line += ' }\n' |
Jon Ashburn | a8aa837 | 2015-03-03 15:07:15 -0700 | [diff] [blame] | 625 | using_line += ' if (g_pDbgFunctionHead == NULL)\n' |
| 626 | using_line += ' {\n' |
| 627 | using_line += ' if (g_actionIsDefault)\n' |
| 628 | using_line += ' g_debugAction = XGL_DBG_LAYER_ACTION_LOG_MSG;\n' |
| 629 | using_line += ' else\n' |
| 630 | using_line += ' g_debugAction &= ~XGL_DBG_LAYER_ACTION_CALLBACK;\n' |
| 631 | using_line += ' }\n' |
Tobin Ehlis | 7e65d75 | 2015-01-15 17:51:52 -0700 | [diff] [blame] | 632 | # Special cases for API funcs that don't use an object as first arg |
Courtney Goeltzenleuchter | ebb9584 | 2015-03-25 17:14:29 -0600 | [diff] [blame] | 633 | elif True in [no_use_proto in proto.name for no_use_proto in ['GlobalOption', 'CreateInstance', 'QueueSubmit', 'QueueSetGlobalMemReferences', 'QueueWaitIdle', 'CreateDevice', 'GetGpuInfo', 'QueueSignalSemaphore', 'QueueWaitSemaphore', 'WsiX11QueuePresent']]: |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 634 | using_line = '' |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 635 | else: |
Tobin Ehlis | 36f1b46 | 2015-02-23 14:09:16 -0700 | [diff] [blame] | 636 | using_line = ' loader_platform_thread_lock_mutex(&objLock);\n' |
| 637 | using_line += ' ll_increment_use_count((void*)%s, %s);\n' % (param0_name, obj_type_mapping[p0_type]) |
| 638 | using_line += ' loader_platform_thread_unlock_mutex(&objLock);\n' |
Tobin Ehlis | 91ce77e | 2015-01-16 08:56:30 -0700 | [diff] [blame] | 639 | if 'QueueSubmit' in proto.name: |
| 640 | using_line += ' set_status((void*)fence, XGL_OBJECT_TYPE_FENCE, OBJSTATUS_FENCE_IS_SUBMITTED);\n' |
Mark Lobodzinski | 4988dea | 2015-02-03 11:52:26 -0600 | [diff] [blame] | 641 | using_line += ' validate_memory_mapping_status(pMemRefs, memRefCount);\n' |
Mark Lobodzinski | aae93e5 | 2015-02-09 10:20:53 -0600 | [diff] [blame] | 642 | using_line += ' validate_mem_ref_count(memRefCount);\n' |
Tobin Ehlis | 91ce77e | 2015-01-16 08:56:30 -0700 | [diff] [blame] | 643 | elif 'GetFenceStatus' in proto.name: |
| 644 | using_line += ' // Warn if submitted_flag is not set\n' |
Mark Lobodzinski | 4988dea | 2015-02-03 11:52:26 -0600 | [diff] [blame] | 645 | using_line += ' validate_status((void*)fence, XGL_OBJECT_TYPE_FENCE, OBJSTATUS_FENCE_IS_SUBMITTED, OBJSTATUS_FENCE_IS_SUBMITTED, XGL_DBG_MSG_ERROR, OBJTRACK_INVALID_FENCE, "Status Requested for Unsubmitted Fence");\n' |
Mark Lobodzinski | 4037087 | 2015-02-03 10:06:31 -0600 | [diff] [blame] | 646 | elif 'EndCommandBuffer' in proto.name: |
| 647 | using_line += ' reset_status((void*)cmdBuffer, XGL_OBJECT_TYPE_CMD_BUFFER, (OBJSTATUS_VIEWPORT_BOUND |\n' |
| 648 | using_line += ' OBJSTATUS_RASTER_BOUND |\n' |
| 649 | using_line += ' OBJSTATUS_COLOR_BLEND_BOUND |\n' |
| 650 | using_line += ' OBJSTATUS_DEPTH_STENCIL_BOUND));\n' |
| 651 | elif 'CmdBindDynamicStateObject' in proto.name: |
| 652 | using_line += ' track_object_status((void*)cmdBuffer, stateBindPoint);\n' |
| 653 | elif 'CmdDraw' in proto.name: |
| 654 | using_line += ' validate_draw_state_flags((void *)cmdBuffer);\n' |
Mark Lobodzinski | 4988dea | 2015-02-03 11:52:26 -0600 | [diff] [blame] | 655 | elif 'MapMemory' in proto.name: |
| 656 | using_line += ' set_status((void*)mem, XGL_OBJECT_TYPE_GPU_MEMORY, OBJSTATUS_GPU_MEM_MAPPED);\n' |
| 657 | elif 'UnmapMemory' in proto.name: |
| 658 | using_line += ' reset_status((void*)mem, XGL_OBJECT_TYPE_GPU_MEMORY, OBJSTATUS_GPU_MEM_MAPPED);\n' |
Tobin Ehlis | 7e65d75 | 2015-01-15 17:51:52 -0700 | [diff] [blame] | 659 | if 'AllocDescriptor' in proto.name: # Allocates array of DSs |
Ian Elliott | a83a58a | 2015-02-04 12:15:12 -0700 | [diff] [blame] | 660 | create_line = ' for (uint32_t i = 0; i < *pCount; i++) {\n' |
Tobin Ehlis | 36f1b46 | 2015-02-23 14:09:16 -0700 | [diff] [blame] | 661 | create_line += ' loader_platform_thread_lock_mutex(&objLock);\n' |
Tobin Ehlis | 7e65d75 | 2015-01-15 17:51:52 -0700 | [diff] [blame] | 662 | create_line += ' ll_insert_obj((void*)pDescriptorSets[i], XGL_OBJECT_TYPE_DESCRIPTOR_SET);\n' |
Tobin Ehlis | 36f1b46 | 2015-02-23 14:09:16 -0700 | [diff] [blame] | 663 | create_line += ' loader_platform_thread_unlock_mutex(&objLock);\n' |
Tobin Ehlis | 7e65d75 | 2015-01-15 17:51:52 -0700 | [diff] [blame] | 664 | create_line += ' }\n' |
Courtney Goeltzenleuchter | be1c898 | 2015-02-25 16:58:34 -0700 | [diff] [blame] | 665 | elif 'CreatePresentableImage' in proto.name: |
| 666 | create_line = ' loader_platform_thread_lock_mutex(&objLock);\n' |
| 667 | create_line += ' ll_insert_obj((void*)*%s, %s);\n' % (proto.params[-2].name, obj_type_mapping[proto.params[-2].ty.strip('*').strip('const ')]) |
Mark Lobodzinski | 78a2197 | 2015-03-05 12:39:33 -0600 | [diff] [blame] | 668 | create_line += ' ll_insert_obj((void*)*pMem, XGL_OBJECT_TYPE_PRESENTABLE_IMAGE_MEMORY);\n' |
| 669 | # create_line += ' ll_insert_obj((void*)*%s, XGL_OBJECT_TYPE_PRESENTABLE_IMAGE_MEMORY);\n' % (obj_type_mapping[proto.params[-1].ty.strip('*').strip('const ')]) |
Courtney Goeltzenleuchter | be1c898 | 2015-02-25 16:58:34 -0700 | [diff] [blame] | 670 | create_line += ' loader_platform_thread_unlock_mutex(&objLock);\n' |
Tobin Ehlis | 7e65d75 | 2015-01-15 17:51:52 -0700 | [diff] [blame] | 671 | elif 'Create' in proto.name or 'Alloc' in proto.name: |
Tobin Ehlis | 36f1b46 | 2015-02-23 14:09:16 -0700 | [diff] [blame] | 672 | create_line = ' loader_platform_thread_lock_mutex(&objLock);\n' |
| 673 | create_line += ' ll_insert_obj((void*)*%s, %s);\n' % (proto.params[-1].name, obj_type_mapping[proto.params[-1].ty.strip('*').strip('const ')]) |
| 674 | create_line += ' loader_platform_thread_unlock_mutex(&objLock);\n' |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 675 | if 'DestroyObject' in proto.name: |
Tobin Ehlis | 36f1b46 | 2015-02-23 14:09:16 -0700 | [diff] [blame] | 676 | destroy_line = ' loader_platform_thread_lock_mutex(&objLock);\n' |
| 677 | destroy_line += ' ll_destroy_obj((void*)%s);\n' % (param0_name) |
| 678 | destroy_line += ' loader_platform_thread_unlock_mutex(&objLock);\n' |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 679 | using_line = '' |
| 680 | else: |
| 681 | if 'Destroy' in proto.name or 'Free' in proto.name: |
Tobin Ehlis | 36f1b46 | 2015-02-23 14:09:16 -0700 | [diff] [blame] | 682 | destroy_line = ' loader_platform_thread_lock_mutex(&objLock);\n' |
Mark Lobodzinski | aadd4c8 | 2015-02-24 16:20:24 -0600 | [diff] [blame] | 683 | destroy_line += ' ll_destroy_obj((void*)%s);\n' % (param0_name) |
Tobin Ehlis | 36f1b46 | 2015-02-23 14:09:16 -0700 | [diff] [blame] | 684 | destroy_line += ' loader_platform_thread_unlock_mutex(&objLock);\n' |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 685 | using_line = '' |
| 686 | if 'DestroyDevice' in proto.name: |
| 687 | destroy_line += ' // Report any remaining objects in LL\n objNode *pTrav = pGlobalHead;\n while (pTrav) {\n' |
Mark Lobodzinski | 78a2197 | 2015-03-05 12:39:33 -0600 | [diff] [blame] | 688 | destroy_line += ' if (pTrav->obj.objType == XGL_OBJECT_TYPE_PRESENTABLE_IMAGE_MEMORY) {\n' |
| 689 | destroy_line += ' objNode *pDel = pTrav;\n' |
| 690 | destroy_line += ' pTrav = pTrav->pNextGlobal;\n' |
| 691 | destroy_line += ' ll_destroy_obj((void*)(pDel->obj.pObj));\n' |
| 692 | destroy_line += ' } else {\n' |
| 693 | destroy_line += ' char str[1024];\n' |
| 694 | 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' |
| 695 | destroy_line += ' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, device, 0, OBJTRACK_OBJECT_LEAK, "OBJTRACK", str);\n' |
| 696 | destroy_line += ' pTrav = pTrav->pNextGlobal;\n' |
| 697 | destroy_line += ' }\n' |
| 698 | destroy_line += ' }\n' |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 699 | ret_val = '' |
| 700 | stmt = '' |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 701 | if proto.ret != "void": |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 702 | ret_val = "XGL_RESULT result = " |
| 703 | stmt = " return result;\n" |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 704 | if 'WsiX11AssociateConnection' == proto.name: |
Ian Elliott | d1597d2 | 2015-02-26 14:34:52 -0700 | [diff] [blame] | 705 | funcs.append("#if defined(__linux__) || defined(XCB_NVIDIA)") |
Jon Ashburn | f7a0874 | 2014-11-25 11:08:42 -0700 | [diff] [blame] | 706 | if proto.name == "EnumerateLayers": |
| 707 | c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1) |
| 708 | funcs.append('%s%s\n' |
| 709 | '{\n' |
| 710 | ' if (gpu != NULL) {\n' |
| 711 | ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n' |
| 712 | ' %s' |
| 713 | ' pCurObj = gpuw;\n' |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 714 | ' loader_platform_thread_once(&tabOnce, init%s);\n' |
Jon Ashburn | f7a0874 | 2014-11-25 11:08:42 -0700 | [diff] [blame] | 715 | ' %snextTable.%s;\n' |
| 716 | ' %s%s' |
| 717 | ' %s' |
| 718 | ' } else {\n' |
| 719 | ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n' |
| 720 | ' return XGL_ERROR_INVALID_POINTER;\n' |
| 721 | ' // This layer compatible with all GPUs\n' |
| 722 | ' *pOutLayerCount = 1;\n' |
Chia-I Wu | 1da4b9f | 2014-12-16 10:47:33 +0800 | [diff] [blame] | 723 | ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n' |
Jon Ashburn | f7a0874 | 2014-11-25 11:08:42 -0700 | [diff] [blame] | 724 | ' return XGL_SUCCESS;\n' |
| 725 | ' }\n' |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 726 | '}' % (qual, decl, proto.params[0].name, using_line, layer_name, ret_val, c_call, create_line, destroy_line, stmt, layer_name)) |
Jon Ashburn | f7a0874 | 2014-11-25 11:08:42 -0700 | [diff] [blame] | 727 | elif proto.params[0].ty != "XGL_PHYSICAL_GPU": |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 728 | funcs.append('%s%s\n' |
| 729 | '{\n' |
| 730 | '%s' |
| 731 | ' %snextTable.%s;\n' |
| 732 | '%s%s' |
| 733 | '%s' |
| 734 | '}' % (qual, decl, using_line, ret_val, proto.c_call(), create_line, destroy_line, stmt)) |
| 735 | else: |
| 736 | c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1) |
Mark Lobodzinski | aae93e5 | 2015-02-09 10:20:53 -0600 | [diff] [blame] | 737 | gpu_state = '' |
| 738 | if 'GetGpuInfo' in proto.name: |
| 739 | gpu_state = ' if (infoType == XGL_INFO_TYPE_PHYSICAL_GPU_PROPERTIES) {\n' |
| 740 | gpu_state += ' if (pData != NULL) {\n' |
| 741 | gpu_state += ' setGpuInfoState(pData);\n' |
| 742 | gpu_state += ' }\n' |
| 743 | gpu_state += ' }\n' |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 744 | funcs.append('%s%s\n' |
| 745 | '{\n' |
| 746 | ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n' |
| 747 | '%s' |
| 748 | ' pCurObj = gpuw;\n' |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 749 | ' loader_platform_thread_once(&tabOnce, init%s);\n' |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 750 | ' %snextTable.%s;\n' |
| 751 | '%s%s' |
| 752 | '%s' |
Mark Lobodzinski | aae93e5 | 2015-02-09 10:20:53 -0600 | [diff] [blame] | 753 | '%s' |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 754 | '}' % (qual, decl, proto.params[0].name, using_line, layer_name, ret_val, c_call, create_line, destroy_line, gpu_state, stmt)) |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 755 | if 'WsiX11QueuePresent' == proto.name: |
| 756 | funcs.append("#endif") |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 757 | elif "ParamChecker" == layer: |
| 758 | # TODO : Need to fix up the non-else cases below to do param checking as well |
| 759 | decl = proto.c_func(prefix="xgl", attr="XGLAPI") |
| 760 | param0_name = proto.params[0].name |
| 761 | ret_val = '' |
| 762 | stmt = '' |
| 763 | param_checks = [] |
| 764 | # Add code to check enums and structs |
| 765 | # TODO : Currently only validating enum values, need to validate everything |
| 766 | str_decl = False |
Tobin Ehlis | c6d256a | 2014-12-18 13:51:21 -0700 | [diff] [blame] | 767 | prev_count_name = '' |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 768 | for p in proto.params: |
| 769 | if xgl_helper.is_type(p.ty.strip('*').strip('const '), 'enum'): |
| 770 | if not str_decl: |
| 771 | param_checks.append(' char str[1024];') |
| 772 | str_decl = True |
| 773 | param_checks.append(' if (!validate_%s(%s)) {' % (p.ty, p.name)) |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 774 | param_checks.append(' sprintf(str, "Parameter %s to function %s has invalid value of %%i.", (int)%s);' % (p.name, proto.name, p.name)) |
| 775 | param_checks.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, 1, "PARAMCHECK", str);') |
| 776 | param_checks.append(' }') |
| 777 | 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] | 778 | is_array = False |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 779 | if not str_decl: |
| 780 | param_checks.append(' char str[1024];') |
| 781 | str_decl = True |
| 782 | if '*' in p.ty: # First check for null ptr |
Tobin Ehlis | c6d256a | 2014-12-18 13:51:21 -0700 | [diff] [blame] | 783 | # If this is an input array, parse over all of the array elements |
| 784 | if prev_count_name != '' and (prev_count_name.strip('Count')[1:] in p.name or 'slotCount' == prev_count_name): |
| 785 | #if 'pImageViews' in p.name: |
| 786 | is_array = True |
| 787 | param_checks.append(' uint32_t i;') |
| 788 | param_checks.append(' for (i = 0; i < %s; i++) {' % prev_count_name) |
| 789 | param_checks.append(' if (!xgl_validate_%s(&%s[i])) {' % (p.ty.strip('*').strip('const ').lower(), p.name)) |
| 790 | param_checks.append(' sprintf(str, "Parameter %s[%%i] to function %s contains an invalid value.", i);' % (p.name, proto.name)) |
| 791 | param_checks.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, 1, "PARAMCHECK", str);') |
| 792 | param_checks.append(' }') |
| 793 | param_checks.append(' }') |
| 794 | else: |
| 795 | param_checks.append(' if (!%s) {' % p.name) |
| 796 | param_checks.append(' sprintf(str, "Struct ptr parameter %s to function %s is NULL.");' % (p.name, proto.name)) |
| 797 | param_checks.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, NULL, 0, 1, "PARAMCHECK", str);') |
| 798 | param_checks.append(' }') |
| 799 | 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] | 800 | else: |
| 801 | 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] | 802 | if not is_array: |
| 803 | param_checks.append(' sprintf(str, "Parameter %s to function %s contains an invalid value.");' % (p.name, proto.name)) |
| 804 | param_checks.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, 1, "PARAMCHECK", str);') |
| 805 | param_checks.append(' }') |
| 806 | if p.name.endswith('Count'): |
| 807 | prev_count_name = p.name |
| 808 | else: |
| 809 | prev_count_name = '' |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 810 | if proto.ret != "void": |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 811 | ret_val = "XGL_RESULT result = " |
| 812 | stmt = " return result;\n" |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 813 | if 'WsiX11AssociateConnection' == proto.name: |
Ian Elliott | d1597d2 | 2015-02-26 14:34:52 -0700 | [diff] [blame] | 814 | funcs.append("#if defined(__linux__) || defined(XCB_NVIDIA)") |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 815 | if proto.name == "EnumerateLayers": |
| 816 | c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1) |
| 817 | funcs.append('%s%s\n' |
| 818 | '{\n' |
| 819 | ' char str[1024];\n' |
| 820 | ' if (gpu != NULL) {\n' |
| 821 | ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n' |
| 822 | ' sprintf(str, "At start of layered %s\\n");\n' |
| 823 | ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpu, 0, 0, "PARAMCHECK", str);\n' |
| 824 | ' pCurObj = gpuw;\n' |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 825 | ' loader_platform_thread_once(&tabOnce, init%s);\n' |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 826 | ' %snextTable.%s;\n' |
| 827 | ' sprintf(str, "Completed layered %s\\n");\n' |
| 828 | ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpu, 0, 0, "PARAMCHECK", str);\n' |
| 829 | ' fflush(stdout);\n' |
| 830 | ' %s' |
| 831 | ' } else {\n' |
| 832 | ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n' |
| 833 | ' return XGL_ERROR_INVALID_POINTER;\n' |
| 834 | ' // This layer compatible with all GPUs\n' |
| 835 | ' *pOutLayerCount = 1;\n' |
| 836 | ' strncpy(pOutLayers[0], "%s", maxStringSize);\n' |
| 837 | ' return XGL_SUCCESS;\n' |
| 838 | ' }\n' |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 839 | '}' % (qual, decl, proto.params[0].name, proto.name, layer_name, ret_val, c_call, proto.name, stmt, layer_name)) |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 840 | elif 'DbgRegisterMsgCallback' == proto.name: |
| 841 | funcs.append(self._gen_layer_dbg_callback_register()) |
| 842 | elif 'DbgUnregisterMsgCallback' == proto.name: |
| 843 | funcs.append(self._gen_layer_dbg_callback_unregister()) |
| 844 | elif proto.params[0].ty != "XGL_PHYSICAL_GPU": |
| 845 | funcs.append('%s%s\n' |
| 846 | '{\n' |
| 847 | '%s\n' |
| 848 | ' %snextTable.%s;\n' |
| 849 | '%s' |
| 850 | '}' % (qual, decl, "\n".join(param_checks), ret_val, proto.c_call(), stmt)) |
| 851 | else: |
| 852 | c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1) |
| 853 | funcs.append('%s%s\n' |
| 854 | '{\n' |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 855 | ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n' |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 856 | ' pCurObj = gpuw;\n' |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 857 | ' loader_platform_thread_once(&tabOnce, init%s);\n' |
Tobin Ehlis | bf4c4de | 2014-12-18 08:44:01 -0700 | [diff] [blame] | 858 | '%s\n' |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 859 | ' %snextTable.%s;\n' |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 860 | '%s' |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 861 | '}' % (qual, decl, proto.params[0].name, layer_name, "\n".join(param_checks), ret_val, c_call, stmt)) |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 862 | if 'WsiX11QueuePresent' == proto.name: |
| 863 | funcs.append("#endif") |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 864 | |
| 865 | return "\n\n".join(funcs) |
| 866 | |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 867 | def _generate_extensions(self): |
| 868 | exts = [] |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 869 | exts.append('uint64_t objTrackGetObjectCount(XGL_OBJECT_TYPE type)') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 870 | exts.append('{') |
| 871 | exts.append(' return (type == XGL_OBJECT_TYPE_ANY) ? numTotalObjs : numObjs[type];') |
| 872 | exts.append('}') |
| 873 | exts.append('') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 874 | exts.append('XGL_RESULT objTrackGetObjects(XGL_OBJECT_TYPE type, uint64_t objCount, OBJTRACK_NODE* pObjNodeArray)') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 875 | exts.append('{') |
| 876 | exts.append(" // This bool flags if we're pulling all objs or just a single class of objs") |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 877 | exts.append(' bool32_t bAllObjs = (type == XGL_OBJECT_TYPE_ANY);') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 878 | exts.append(' // Check the count first thing') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 879 | exts.append(' uint64_t maxObjCount = (bAllObjs) ? numTotalObjs : numObjs[type];') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 880 | exts.append(' if (objCount > maxObjCount) {') |
| 881 | exts.append(' char str[1024];') |
| 882 | 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));') |
| 883 | exts.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, 0, 0, OBJTRACK_OBJCOUNT_MAX_EXCEEDED, "OBJTRACK", str);') |
| 884 | exts.append(' return XGL_ERROR_INVALID_VALUE;') |
| 885 | exts.append(' }') |
| 886 | exts.append(' objNode* pTrav = (bAllObjs) ? pGlobalHead : pObjectHead[type];') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 887 | exts.append(' for (uint64_t i = 0; i < objCount; i++) {') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 888 | exts.append(' if (!pTrav) {') |
| 889 | exts.append(' char str[1024];') |
| 890 | 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);') |
| 891 | exts.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, 0, 0, OBJTRACK_INTERNAL_ERROR, "OBJTRACK", str);') |
| 892 | exts.append(' return XGL_ERROR_UNKNOWN;') |
| 893 | exts.append(' }') |
| 894 | exts.append(' memcpy(&pObjNodeArray[i], pTrav, sizeof(OBJTRACK_NODE));') |
| 895 | exts.append(' pTrav = (bAllObjs) ? pTrav->pNextGlobal : pTrav->pNextObj;') |
| 896 | exts.append(' }') |
| 897 | exts.append(' return XGL_SUCCESS;') |
| 898 | exts.append('}') |
| 899 | |
| 900 | return "\n".join(exts) |
| 901 | |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 902 | def _generate_layer_gpa_function(self, layer, extensions=[]): |
Chia-I Wu | 4d11dcc | 2015-01-05 13:18:57 +0800 | [diff] [blame] | 903 | func_body = ["#include \"xgl_generic_intercept_proc_helper.h\""] |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 904 | func_body.append("XGL_LAYER_EXPORT void* XGLAPI xglGetProcAddr(XGL_PHYSICAL_GPU gpu, const char* funcName)\n" |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 905 | "{\n" |
| 906 | " XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) gpu;\n" |
Chia-I Wu | 4d11dcc | 2015-01-05 13:18:57 +0800 | [diff] [blame] | 907 | " void* addr;\n" |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 908 | " if (gpu == NULL)\n" |
| 909 | " return NULL;\n" |
| 910 | " pCurObj = gpuw;\n" |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 911 | " loader_platform_thread_once(&tabOnce, init%s);\n\n" |
Chia-I Wu | 4d11dcc | 2015-01-05 13:18:57 +0800 | [diff] [blame] | 912 | " addr = layer_intercept_proc(funcName);\n" |
| 913 | " if (addr)\n" |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 914 | " return addr;" % layer) |
Chia-I Wu | 4d11dcc | 2015-01-05 13:18:57 +0800 | [diff] [blame] | 915 | |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 916 | if 0 != len(extensions): |
| 917 | for ext_name in extensions: |
Chia-I Wu | f1a5a74 | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 918 | func_body.append(' else if (!strncmp("%s", funcName, sizeof("%s")))\n' |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 919 | ' return %s;' % (ext_name, ext_name, ext_name)) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 920 | func_body.append(" else {\n" |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 921 | " if (gpuw->pGPA == NULL)\n" |
| 922 | " return NULL;\n" |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 923 | " return gpuw->pGPA((XGL_PHYSICAL_GPU)gpuw->nextObject, funcName);\n" |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 924 | " }\n" |
| 925 | "}\n") |
| 926 | return "\n".join(func_body) |
| 927 | |
Tobin Ehlis | 36f1b46 | 2015-02-23 14:09:16 -0700 | [diff] [blame] | 928 | def _generate_layer_initialization(self, name, init_opts=False, prefix='xgl', lockname=None): |
Chia-I Wu | aa4121f | 2015-01-04 23:11:43 +0800 | [diff] [blame] | 929 | func_body = ["#include \"xgl_dispatch_table_helper.h\""] |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 930 | func_body.append('static void init%s(void)\n' |
| 931 | '{\n' % name) |
| 932 | if init_opts: |
| 933 | func_body.append(' const char *strOpt;') |
| 934 | func_body.append(' // initialize %s options' % name) |
Ian Elliott | e782671 | 2015-03-06 13:50:05 -0700 | [diff] [blame] | 935 | func_body.append(' getLayerOptionEnum("%sReportLevel", (uint32_t *) &g_reportingLevel);' % name) |
| 936 | func_body.append(' g_actionIsDefault = getLayerOptionEnum("%sDebugAction", (uint32_t *) &g_debugAction);' % name) |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 937 | func_body.append('') |
| 938 | func_body.append(' if (g_debugAction & XGL_DBG_LAYER_ACTION_LOG_MSG)') |
| 939 | func_body.append(' {') |
| 940 | func_body.append(' strOpt = getLayerOption("%sLogFilename");' % name) |
| 941 | func_body.append(' if (strOpt)') |
| 942 | func_body.append(' {') |
| 943 | func_body.append(' g_logFile = fopen(strOpt, "w");') |
| 944 | func_body.append(' }') |
| 945 | func_body.append(' if (g_logFile == NULL)') |
| 946 | func_body.append(' g_logFile = stdout;') |
| 947 | func_body.append(' }') |
| 948 | func_body.append('') |
| 949 | func_body.append(' xglGetProcAddrType fpNextGPA;\n' |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 950 | ' fpNextGPA = pCurObj->pGPA;\n' |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 951 | ' assert(fpNextGPA);\n') |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 952 | |
Chia-I Wu | aa4121f | 2015-01-04 23:11:43 +0800 | [diff] [blame] | 953 | func_body.append(" layer_initialize_dispatch_table(&nextTable, fpNextGPA, (XGL_PHYSICAL_GPU) pCurObj->nextObject);") |
Tobin Ehlis | 36f1b46 | 2015-02-23 14:09:16 -0700 | [diff] [blame] | 954 | if lockname is not None: |
| 955 | func_body.append(" if (!%sLockInitialized)" % lockname) |
| 956 | func_body.append(" {") |
| 957 | func_body.append(" // TODO/TBD: Need to delete this mutex sometime. How???") |
| 958 | func_body.append(" loader_platform_thread_create_mutex(&%sLock);" % lockname) |
| 959 | func_body.append(" %sLockInitialized = 1;" % lockname) |
| 960 | func_body.append(" }") |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 961 | func_body.append("}\n") |
| 962 | return "\n".join(func_body) |
| 963 | |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 964 | def _generate_layer_initialization_with_lock(self, layer, prefix='xgl'): |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 965 | func_body = ["#include \"xgl_dispatch_table_helper.h\""] |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 966 | func_body.append('static void init%s(void)\n' |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 967 | '{\n' |
| 968 | ' xglGetProcAddrType fpNextGPA;\n' |
| 969 | ' fpNextGPA = pCurObj->pGPA;\n' |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 970 | ' assert(fpNextGPA);\n' % layer); |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 971 | |
| 972 | func_body.append(" layer_initialize_dispatch_table(&nextTable, fpNextGPA, (XGL_PHYSICAL_GPU) pCurObj->nextObject);\n") |
| 973 | func_body.append(" if (!printLockInitialized)") |
| 974 | func_body.append(" {") |
| 975 | func_body.append(" // TODO/TBD: Need to delete this mutex sometime. How???") |
| 976 | func_body.append(" loader_platform_thread_create_mutex(&printLock);") |
| 977 | func_body.append(" printLockInitialized = 1;") |
| 978 | func_body.append(" }") |
| 979 | func_body.append("}\n") |
| 980 | return "\n".join(func_body) |
| 981 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 982 | class LayerFuncsSubcommand(Subcommand): |
| 983 | def generate_header(self): |
| 984 | return '#include <xglLayer.h>\n#include "loader.h"' |
| 985 | |
| 986 | def generate_body(self): |
| 987 | return self._generate_dispatch_entrypoints("static", True) |
| 988 | |
| 989 | class LayerDispatchSubcommand(Subcommand): |
| 990 | def generate_header(self): |
| 991 | return '#include "layer_wrappers.h"' |
| 992 | |
| 993 | def generate_body(self): |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 994 | return self._generate_layer_initialization() |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 995 | |
| 996 | class GenericLayerSubcommand(Subcommand): |
| 997 | def generate_header(self): |
Jon Ashburn | 9a7f9a2 | 2015-02-17 11:03:12 -0700 | [diff] [blame] | 998 | return '#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include "loader_platform.h"\n#include "xglLayer.h"\n//The following is #included again to catch certain OS-specific functions being used:\n#include "loader_platform.h"\n\n#include "layers_config.h"\n#include "layers_msg.h"\n\nstatic XGL_LAYER_DISPATCH_TABLE nextTable;\nstatic XGL_BASE_LAYER_OBJECT *pCurObj;\n\nstatic LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);' |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 999 | |
| 1000 | def generate_body(self): |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 1001 | body = [self._generate_layer_initialization("Generic", True), |
Tobin Ehlis | a363cfa | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 1002 | self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "Generic"), |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 1003 | self._generate_layer_gpa_function("Generic")] |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1004 | |
| 1005 | return "\n\n".join(body) |
| 1006 | |
| 1007 | class ApiDumpSubcommand(Subcommand): |
| 1008 | def generate_header(self): |
Tobin Ehlis | d009bae | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 1009 | header_txt = [] |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1010 | header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>') |
| 1011 | header_txt.append('#include "loader_platform.h"') |
| 1012 | header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper.h"\n') |
Ian Elliott | 655cad7 | 2015-02-12 17:08:34 -0700 | [diff] [blame] | 1013 | header_txt.append('// The following is #included again to catch certain OS-specific functions being used:') |
| 1014 | header_txt.append('#include "loader_platform.h"') |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1015 | header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;') |
| 1016 | header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n') |
| 1017 | header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);') |
| 1018 | header_txt.append('static int printLockInitialized = 0;') |
| 1019 | header_txt.append('static loader_platform_thread_mutex printLock;\n') |
Tobin Ehlis | d009bae | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 1020 | header_txt.append('#define MAX_TID 513') |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1021 | header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};') |
Tobin Ehlis | d009bae | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 1022 | header_txt.append('static uint32_t maxTID = 0;') |
| 1023 | header_txt.append('// Map actual TID to an index value and return that index') |
| 1024 | header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs') |
| 1025 | header_txt.append('static uint32_t getTIDIndex() {') |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1026 | header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();') |
Tobin Ehlis | d009bae | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 1027 | header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {') |
| 1028 | header_txt.append(' if (tid == tidMapping[i])') |
| 1029 | header_txt.append(' return i;') |
| 1030 | header_txt.append(' }') |
| 1031 | header_txt.append(" // Don't yet have mapping, set it and return newly set index") |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1032 | header_txt.append(' uint32_t retVal = (uint32_t) maxTID;') |
Tobin Ehlis | d009bae | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 1033 | header_txt.append(' tidMapping[maxTID++] = tid;') |
| 1034 | header_txt.append(' assert(maxTID < MAX_TID);') |
| 1035 | header_txt.append(' return retVal;') |
| 1036 | header_txt.append('}') |
| 1037 | return "\n".join(header_txt) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1038 | |
| 1039 | def generate_body(self): |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 1040 | body = [self._generate_layer_initialization_with_lock("APIDump"), |
Tobin Ehlis | a363cfa | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 1041 | self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDump"), |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 1042 | self._generate_layer_gpa_function("APIDump")] |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1043 | |
| 1044 | return "\n\n".join(body) |
| 1045 | |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1046 | class ApiDumpCppSubcommand(Subcommand): |
| 1047 | def generate_header(self): |
| 1048 | header_txt = [] |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1049 | header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>') |
| 1050 | header_txt.append('#include "loader_platform.h"') |
| 1051 | header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper_cpp.h"\n') |
Ian Elliott | 655cad7 | 2015-02-12 17:08:34 -0700 | [diff] [blame] | 1052 | header_txt.append('// The following is #included again to catch certain OS-specific functions being used:') |
| 1053 | header_txt.append('#include "loader_platform.h"') |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1054 | header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;') |
| 1055 | header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n') |
| 1056 | header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);') |
| 1057 | header_txt.append('static int printLockInitialized = 0;') |
| 1058 | header_txt.append('static loader_platform_thread_mutex printLock;\n') |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1059 | header_txt.append('#define MAX_TID 513') |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1060 | header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};') |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1061 | header_txt.append('static uint32_t maxTID = 0;') |
| 1062 | header_txt.append('// Map actual TID to an index value and return that index') |
| 1063 | header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs') |
| 1064 | header_txt.append('static uint32_t getTIDIndex() {') |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1065 | header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();') |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1066 | header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {') |
| 1067 | header_txt.append(' if (tid == tidMapping[i])') |
| 1068 | header_txt.append(' return i;') |
| 1069 | header_txt.append(' }') |
| 1070 | header_txt.append(" // Don't yet have mapping, set it and return newly set index") |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1071 | header_txt.append(' uint32_t retVal = (uint32_t) maxTID;') |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1072 | header_txt.append(' tidMapping[maxTID++] = tid;') |
| 1073 | header_txt.append(' assert(maxTID < MAX_TID);') |
| 1074 | header_txt.append(' return retVal;') |
| 1075 | header_txt.append('}') |
| 1076 | return "\n".join(header_txt) |
| 1077 | |
| 1078 | def generate_body(self): |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 1079 | body = [self._generate_layer_initialization_with_lock("APIDumpCpp"), |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1080 | self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDumpCpp"), |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 1081 | self._generate_layer_gpa_function("APIDumpCpp")] |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1082 | |
| 1083 | return "\n\n".join(body) |
| 1084 | |
Tobin Ehlis | ea3d21b | 2014-11-12 13:11:15 -0700 | [diff] [blame] | 1085 | class ApiDumpFileSubcommand(Subcommand): |
| 1086 | def generate_header(self): |
Tobin Ehlis | d009bae | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 1087 | header_txt = [] |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1088 | header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>') |
| 1089 | header_txt.append('#include "loader_platform.h"') |
| 1090 | header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper.h"\n') |
Ian Elliott | 655cad7 | 2015-02-12 17:08:34 -0700 | [diff] [blame] | 1091 | header_txt.append('// The following is #included again to catch certain OS-specific functions being used:') |
| 1092 | header_txt.append('#include "loader_platform.h"') |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1093 | header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;') |
| 1094 | header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n') |
| 1095 | header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);') |
| 1096 | header_txt.append('static int printLockInitialized = 0;') |
| 1097 | header_txt.append('static loader_platform_thread_mutex printLock;\n') |
Tobin Ehlis | d009bae | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 1098 | header_txt.append('#define MAX_TID 513') |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1099 | header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};') |
Tobin Ehlis | d009bae | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 1100 | header_txt.append('static uint32_t maxTID = 0;') |
| 1101 | header_txt.append('// Map actual TID to an index value and return that index') |
| 1102 | header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs') |
| 1103 | header_txt.append('static uint32_t getTIDIndex() {') |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1104 | header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();') |
Tobin Ehlis | d009bae | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 1105 | header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {') |
| 1106 | header_txt.append(' if (tid == tidMapping[i])') |
| 1107 | header_txt.append(' return i;') |
| 1108 | header_txt.append(' }') |
| 1109 | header_txt.append(" // Don't yet have mapping, set it and return newly set index") |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1110 | header_txt.append(' uint32_t retVal = (uint32_t) maxTID;') |
Tobin Ehlis | d009bae | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 1111 | header_txt.append(' tidMapping[maxTID++] = tid;') |
| 1112 | header_txt.append(' assert(maxTID < MAX_TID);') |
| 1113 | header_txt.append(' return retVal;') |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1114 | header_txt.append('}\n') |
| 1115 | header_txt.append('static FILE* pOutFile;\nstatic char* outFileName = "xgl_apidump.txt";') |
Tobin Ehlis | d009bae | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 1116 | return "\n".join(header_txt) |
Tobin Ehlis | ea3d21b | 2014-11-12 13:11:15 -0700 | [diff] [blame] | 1117 | |
| 1118 | def generate_body(self): |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 1119 | body = [self._generate_layer_initialization_with_lock("APIDumpFile"), |
Tobin Ehlis | a363cfa | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 1120 | self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDumpFile"), |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 1121 | self._generate_layer_gpa_function("APIDumpFile")] |
Tobin Ehlis | ea3d21b | 2014-11-12 13:11:15 -0700 | [diff] [blame] | 1122 | |
| 1123 | return "\n\n".join(body) |
| 1124 | |
Tobin Ehlis | d49efcb | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 1125 | class ApiDumpNoAddrSubcommand(Subcommand): |
| 1126 | def generate_header(self): |
| 1127 | header_txt = [] |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1128 | header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>') |
| 1129 | header_txt.append('#include "loader_platform.h"') |
| 1130 | header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper_no_addr.h"\n') |
Ian Elliott | 655cad7 | 2015-02-12 17:08:34 -0700 | [diff] [blame] | 1131 | header_txt.append('// The following is #included again to catch certain OS-specific functions being used:') |
| 1132 | header_txt.append('#include "loader_platform.h"') |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1133 | header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;') |
| 1134 | header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n') |
| 1135 | header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);') |
| 1136 | header_txt.append('static int printLockInitialized = 0;') |
| 1137 | header_txt.append('static loader_platform_thread_mutex printLock;\n') |
Tobin Ehlis | d49efcb | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 1138 | header_txt.append('#define MAX_TID 513') |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1139 | header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};') |
Tobin Ehlis | d49efcb | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 1140 | header_txt.append('static uint32_t maxTID = 0;') |
| 1141 | header_txt.append('// Map actual TID to an index value and return that index') |
| 1142 | header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs') |
| 1143 | header_txt.append('static uint32_t getTIDIndex() {') |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1144 | header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();') |
Tobin Ehlis | d49efcb | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 1145 | header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {') |
| 1146 | header_txt.append(' if (tid == tidMapping[i])') |
| 1147 | header_txt.append(' return i;') |
| 1148 | header_txt.append(' }') |
| 1149 | header_txt.append(" // Don't yet have mapping, set it and return newly set index") |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1150 | header_txt.append(' uint32_t retVal = (uint32_t) maxTID;') |
Tobin Ehlis | d49efcb | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 1151 | header_txt.append(' tidMapping[maxTID++] = tid;') |
| 1152 | header_txt.append(' assert(maxTID < MAX_TID);') |
| 1153 | header_txt.append(' return retVal;') |
| 1154 | header_txt.append('}') |
| 1155 | return "\n".join(header_txt) |
| 1156 | |
| 1157 | def generate_body(self): |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 1158 | body = [self._generate_layer_initialization_with_lock("APIDumpNoAddr"), |
Tobin Ehlis | d49efcb | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 1159 | self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDump", True), |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 1160 | self._generate_layer_gpa_function("APIDumpNoAddr")] |
Tobin Ehlis | d49efcb | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 1161 | |
| 1162 | return "\n\n".join(body) |
| 1163 | |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1164 | class ApiDumpNoAddrCppSubcommand(Subcommand): |
| 1165 | def generate_header(self): |
| 1166 | header_txt = [] |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1167 | header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>') |
| 1168 | header_txt.append('#include "loader_platform.h"') |
| 1169 | header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper_no_addr_cpp.h"\n') |
Ian Elliott | 655cad7 | 2015-02-12 17:08:34 -0700 | [diff] [blame] | 1170 | header_txt.append('// The following is #included again to catch certain OS-specific functions being used:') |
| 1171 | header_txt.append('#include "loader_platform.h"') |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1172 | header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;') |
| 1173 | header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n') |
| 1174 | header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);') |
| 1175 | header_txt.append('static int printLockInitialized = 0;') |
| 1176 | header_txt.append('static loader_platform_thread_mutex printLock;\n') |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1177 | header_txt.append('#define MAX_TID 513') |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1178 | header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};') |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1179 | header_txt.append('static uint32_t maxTID = 0;') |
| 1180 | header_txt.append('// Map actual TID to an index value and return that index') |
| 1181 | header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs') |
| 1182 | header_txt.append('static uint32_t getTIDIndex() {') |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1183 | header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();') |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1184 | header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {') |
| 1185 | header_txt.append(' if (tid == tidMapping[i])') |
| 1186 | header_txt.append(' return i;') |
| 1187 | header_txt.append(' }') |
| 1188 | header_txt.append(" // Don't yet have mapping, set it and return newly set index") |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1189 | header_txt.append(' uint32_t retVal = (uint32_t) maxTID;') |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1190 | header_txt.append(' tidMapping[maxTID++] = tid;') |
| 1191 | header_txt.append(' assert(maxTID < MAX_TID);') |
| 1192 | header_txt.append(' return retVal;') |
| 1193 | header_txt.append('}') |
| 1194 | return "\n".join(header_txt) |
| 1195 | |
| 1196 | def generate_body(self): |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 1197 | body = [self._generate_layer_initialization_with_lock("APIDumpNoAddrCpp"), |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1198 | self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDumpCpp", True), |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 1199 | self._generate_layer_gpa_function("APIDumpNoAddrCpp")] |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1200 | |
| 1201 | return "\n\n".join(body) |
| 1202 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1203 | class ObjectTrackerSubcommand(Subcommand): |
| 1204 | def generate_header(self): |
| 1205 | header_txt = [] |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1206 | header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include "loader_platform.h"') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1207 | header_txt.append('#include "object_track.h"\n\nstatic XGL_LAYER_DISPATCH_TABLE nextTable;\nstatic XGL_BASE_LAYER_OBJECT *pCurObj;') |
Ian Elliott | 655cad7 | 2015-02-12 17:08:34 -0700 | [diff] [blame] | 1208 | header_txt.append('// The following is #included again to catch certain OS-specific functions being used:') |
| 1209 | header_txt.append('#include "loader_platform.h"') |
Jon Ashburn | 9a7f9a2 | 2015-02-17 11:03:12 -0700 | [diff] [blame] | 1210 | header_txt.append('#include "layers_config.h"') |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 1211 | header_txt.append('#include "layers_msg.h"') |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1212 | header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);') |
| 1213 | header_txt.append('static long long unsigned int object_track_index = 0;') |
Tobin Ehlis | 36f1b46 | 2015-02-23 14:09:16 -0700 | [diff] [blame] | 1214 | header_txt.append('static int objLockInitialized = 0;') |
| 1215 | header_txt.append('static loader_platform_thread_mutex objLock;') |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 1216 | header_txt.append('') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1217 | header_txt.append('// We maintain a "Global" list which links every object and a') |
| 1218 | header_txt.append('// per-Object list which just links objects of a given type') |
| 1219 | header_txt.append('// The object node has both pointers so the actual nodes are shared between the two lists') |
| 1220 | header_txt.append('typedef struct _objNode {') |
| 1221 | header_txt.append(' OBJTRACK_NODE obj;') |
| 1222 | header_txt.append(' struct _objNode *pNextObj;') |
| 1223 | header_txt.append(' struct _objNode *pNextGlobal;') |
| 1224 | header_txt.append('} objNode;') |
| 1225 | header_txt.append('static objNode *pObjectHead[XGL_NUM_OBJECT_TYPE] = {0};') |
| 1226 | header_txt.append('static objNode *pGlobalHead = NULL;') |
| 1227 | header_txt.append('static uint64_t numObjs[XGL_NUM_OBJECT_TYPE] = {0};') |
| 1228 | header_txt.append('static uint64_t numTotalObjs = 0;') |
Mark Lobodzinski | aae93e5 | 2015-02-09 10:20:53 -0600 | [diff] [blame] | 1229 | header_txt.append('static uint32_t maxMemRefsPerSubmission = 0;') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1230 | header_txt.append('// Debug function to print global list and each individual object list') |
| 1231 | header_txt.append('static void ll_print_lists()') |
| 1232 | header_txt.append('{') |
| 1233 | header_txt.append(' objNode* pTrav = pGlobalHead;') |
| 1234 | header_txt.append(' printf("=====GLOBAL OBJECT LIST (%lu total objs):\\n", numTotalObjs);') |
| 1235 | header_txt.append(' while (pTrav) {') |
| 1236 | 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);') |
| 1237 | header_txt.append(' pTrav = pTrav->pNextGlobal;') |
| 1238 | header_txt.append(' }') |
| 1239 | header_txt.append(' for (uint32_t i = 0; i < XGL_NUM_OBJECT_TYPE; i++) {') |
| 1240 | header_txt.append(' pTrav = pObjectHead[i];') |
| 1241 | header_txt.append(' if (pTrav) {') |
| 1242 | header_txt.append(' printf("=====%s OBJECT LIST (%lu objs):\\n", string_XGL_OBJECT_TYPE(pTrav->obj.objType), numObjs[i]);') |
| 1243 | header_txt.append(' while (pTrav) {') |
| 1244 | 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);') |
| 1245 | header_txt.append(' pTrav = pTrav->pNextObj;') |
| 1246 | header_txt.append(' }') |
| 1247 | header_txt.append(' }') |
| 1248 | header_txt.append(' }') |
| 1249 | header_txt.append('}') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1250 | header_txt.append('static void ll_insert_obj(void* pObj, XGL_OBJECT_TYPE objType) {') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1251 | header_txt.append(' char str[1024];') |
| 1252 | header_txt.append(' sprintf(str, "OBJ[%llu] : CREATE %s object %p", object_track_index++, string_XGL_OBJECT_TYPE(objType), (void*)pObj);') |
| 1253 | header_txt.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_NONE, "OBJTRACK", str);') |
| 1254 | header_txt.append(' objNode* pNewObjNode = (objNode*)malloc(sizeof(objNode));') |
| 1255 | header_txt.append(' pNewObjNode->obj.pObj = pObj;') |
| 1256 | header_txt.append(' pNewObjNode->obj.objType = objType;') |
Mark Lobodzinski | 4037087 | 2015-02-03 10:06:31 -0600 | [diff] [blame] | 1257 | header_txt.append(' pNewObjNode->obj.status = OBJSTATUS_NONE;') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1258 | header_txt.append(' pNewObjNode->obj.numUses = 0;') |
| 1259 | header_txt.append(' // insert at front of global list') |
| 1260 | header_txt.append(' pNewObjNode->pNextGlobal = pGlobalHead;') |
| 1261 | header_txt.append(' pGlobalHead = pNewObjNode;') |
| 1262 | header_txt.append(' // insert at front of object list') |
| 1263 | header_txt.append(' pNewObjNode->pNextObj = pObjectHead[objType];') |
| 1264 | header_txt.append(' pObjectHead[objType] = pNewObjNode;') |
| 1265 | header_txt.append(' // increment obj counts') |
| 1266 | header_txt.append(' numObjs[objType]++;') |
| 1267 | header_txt.append(' numTotalObjs++;') |
| 1268 | 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] | 1269 | header_txt.append(' if (0) ll_print_lists();') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1270 | header_txt.append('}') |
| 1271 | header_txt.append('// Traverse global list and return type for given object') |
| 1272 | header_txt.append('static XGL_OBJECT_TYPE ll_get_obj_type(XGL_OBJECT object) {') |
| 1273 | header_txt.append(' objNode *pTrav = pGlobalHead;') |
| 1274 | header_txt.append(' while (pTrav) {') |
| 1275 | header_txt.append(' if (pTrav->obj.pObj == object)') |
| 1276 | header_txt.append(' return pTrav->obj.objType;') |
| 1277 | header_txt.append(' pTrav = pTrav->pNextGlobal;') |
| 1278 | header_txt.append(' }') |
| 1279 | header_txt.append(' char str[1024];') |
| 1280 | header_txt.append(' sprintf(str, "Attempting look-up on obj %p but it is NOT in the global list!", (void*)object);') |
| 1281 | header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, object, 0, OBJTRACK_MISSING_OBJECT, "OBJTRACK", str);') |
| 1282 | header_txt.append(' return XGL_OBJECT_TYPE_UNKNOWN;') |
| 1283 | header_txt.append('}') |
Chia-I Wu | 85763e5 | 2014-12-16 11:02:06 +0800 | [diff] [blame] | 1284 | header_txt.append('#if 0') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1285 | header_txt.append('static uint64_t ll_get_obj_uses(void* pObj, XGL_OBJECT_TYPE objType) {') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1286 | header_txt.append(' objNode *pTrav = pObjectHead[objType];') |
| 1287 | header_txt.append(' while (pTrav) {') |
| 1288 | header_txt.append(' if (pTrav->obj.pObj == pObj) {') |
| 1289 | header_txt.append(' return pTrav->obj.numUses;') |
| 1290 | header_txt.append(' }') |
| 1291 | header_txt.append(' pTrav = pTrav->pNextObj;') |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1292 | header_txt.append(' }') |
| 1293 | header_txt.append(' return 0;') |
| 1294 | header_txt.append('}') |
Chia-I Wu | 85763e5 | 2014-12-16 11:02:06 +0800 | [diff] [blame] | 1295 | header_txt.append('#endif') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1296 | header_txt.append('static void ll_increment_use_count(void* pObj, XGL_OBJECT_TYPE objType) {') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1297 | header_txt.append(' objNode *pTrav = pObjectHead[objType];') |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1298 | header_txt.append(' while (pTrav) {') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1299 | header_txt.append(' if (pTrav->obj.pObj == pObj) {') |
| 1300 | header_txt.append(' pTrav->obj.numUses++;') |
| 1301 | header_txt.append(' char str[1024];') |
| 1302 | 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);') |
| 1303 | header_txt.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_NONE, "OBJTRACK", str);') |
| 1304 | header_txt.append(' return;') |
| 1305 | header_txt.append(' }') |
| 1306 | header_txt.append(' pTrav = pTrav->pNextObj;') |
| 1307 | header_txt.append(' }') |
| 1308 | header_txt.append(' // If we do not find obj, insert it and then increment count') |
| 1309 | header_txt.append(' char str[1024];') |
| 1310 | 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));') |
| 1311 | header_txt.append(' layerCbMsg(XGL_DBG_MSG_WARNING, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);') |
| 1312 | header_txt.append('') |
| 1313 | header_txt.append(' ll_insert_obj(pObj, objType);') |
| 1314 | header_txt.append(' ll_increment_use_count(pObj, objType);') |
| 1315 | header_txt.append('}') |
| 1316 | header_txt.append('// We usually do not know Obj type when we destroy it so have to fetch') |
| 1317 | header_txt.append('// Type from global list w/ ll_destroy_obj()') |
| 1318 | header_txt.append('// and then do the full removal from both lists w/ ll_remove_obj_type()') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1319 | header_txt.append('static void ll_remove_obj_type(void* pObj, XGL_OBJECT_TYPE objType) {') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1320 | header_txt.append(' objNode *pTrav = pObjectHead[objType];') |
| 1321 | header_txt.append(' objNode *pPrev = pObjectHead[objType];') |
| 1322 | header_txt.append(' while (pTrav) {') |
| 1323 | header_txt.append(' if (pTrav->obj.pObj == pObj) {') |
| 1324 | header_txt.append(' pPrev->pNextObj = pTrav->pNextObj;') |
| 1325 | header_txt.append(' // update HEAD of Obj list as needed') |
| 1326 | header_txt.append(' if (pObjectHead[objType] == pTrav)') |
| 1327 | header_txt.append(' pObjectHead[objType] = pTrav->pNextObj;') |
| 1328 | header_txt.append(' assert(numObjs[objType] > 0);') |
| 1329 | header_txt.append(' numObjs[objType]--;') |
| 1330 | header_txt.append(' char str[1024];') |
| 1331 | header_txt.append(' sprintf(str, "OBJ[%llu] : DESTROY %s object %p", object_track_index++, string_XGL_OBJECT_TYPE(objType), (void*)pObj);') |
| 1332 | 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] | 1333 | header_txt.append(' return;') |
| 1334 | header_txt.append(' }') |
| 1335 | header_txt.append(' pPrev = pTrav;') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1336 | header_txt.append(' pTrav = pTrav->pNextObj;') |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1337 | header_txt.append(' }') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1338 | header_txt.append(' char str[1024];') |
| 1339 | 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));') |
| 1340 | header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_INTERNAL_ERROR, "OBJTRACK", str);') |
| 1341 | header_txt.append('}') |
| 1342 | header_txt.append('// Parse global list to find obj type, then remove obj from obj type list, finally') |
| 1343 | header_txt.append('// remove obj from global list') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1344 | header_txt.append('static void ll_destroy_obj(void* pObj) {') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1345 | header_txt.append(' objNode *pTrav = pGlobalHead;') |
| 1346 | header_txt.append(' objNode *pPrev = pGlobalHead;') |
| 1347 | header_txt.append(' while (pTrav) {') |
| 1348 | header_txt.append(' if (pTrav->obj.pObj == pObj) {') |
| 1349 | header_txt.append(' ll_remove_obj_type(pObj, pTrav->obj.objType);') |
| 1350 | header_txt.append(' pPrev->pNextGlobal = pTrav->pNextGlobal;') |
| 1351 | header_txt.append(' // update HEAD of global list if needed') |
| 1352 | header_txt.append(' if (pGlobalHead == pTrav)') |
| 1353 | header_txt.append(' pGlobalHead = pTrav->pNextGlobal;') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1354 | header_txt.append(' assert(numTotalObjs > 0);') |
| 1355 | header_txt.append(' numTotalObjs--;') |
| 1356 | header_txt.append(' char str[1024];') |
Courtney Goeltzenleuchter | 9d9da10 | 2015-03-26 16:16:16 -0600 | [diff] [blame] | 1357 | header_txt.append(' sprintf(str, "OBJ_STAT Removed %s obj %p that was used %lu times (%lu total objs remain & %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));') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1358 | header_txt.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_NONE, "OBJTRACK", str);') |
Tobin Ehlis | 36f1b46 | 2015-02-23 14:09:16 -0700 | [diff] [blame] | 1359 | header_txt.append(' free(pTrav);') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1360 | header_txt.append(' return;') |
| 1361 | header_txt.append(' }') |
| 1362 | header_txt.append(' pPrev = pTrav;') |
| 1363 | header_txt.append(' pTrav = pTrav->pNextGlobal;') |
| 1364 | header_txt.append(' }') |
| 1365 | header_txt.append(' char str[1024];') |
| 1366 | header_txt.append(' sprintf(str, "Unable to remove obj %p. Was it created? Has it already been destroyed?", pObj);') |
| 1367 | 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] | 1368 | header_txt.append('}') |
Tobin Ehlis | 91ce77e | 2015-01-16 08:56:30 -0700 | [diff] [blame] | 1369 | header_txt.append('// Set selected flag state for an object node') |
| 1370 | header_txt.append('static void set_status(void* pObj, XGL_OBJECT_TYPE objType, OBJECT_STATUS status_flag) {') |
Mark Lobodzinski | 709e16d | 2015-02-09 10:16:20 -0600 | [diff] [blame] | 1371 | header_txt.append(' if (pObj != NULL) {') |
| 1372 | header_txt.append(' objNode *pTrav = pObjectHead[objType];') |
| 1373 | header_txt.append(' while (pTrav) {') |
| 1374 | header_txt.append(' if (pTrav->obj.pObj == pObj) {') |
| 1375 | header_txt.append(' pTrav->obj.status |= status_flag;') |
| 1376 | header_txt.append(' return;') |
| 1377 | header_txt.append(' }') |
| 1378 | header_txt.append(' pTrav = pTrav->pNextObj;') |
Tobin Ehlis | 91ce77e | 2015-01-16 08:56:30 -0700 | [diff] [blame] | 1379 | header_txt.append(' }') |
Mark Lobodzinski | 709e16d | 2015-02-09 10:16:20 -0600 | [diff] [blame] | 1380 | header_txt.append(' // If we do not find it print an error') |
| 1381 | header_txt.append(' char str[1024];') |
| 1382 | header_txt.append(' sprintf(str, "Unable to set status for non-existent object %p of %s type", pObj, string_XGL_OBJECT_TYPE(objType));') |
| 1383 | header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);') |
| 1384 | header_txt.append(' }'); |
Tobin Ehlis | 91ce77e | 2015-01-16 08:56:30 -0700 | [diff] [blame] | 1385 | header_txt.append('}') |
| 1386 | header_txt.append('') |
Mark Lobodzinski | 4037087 | 2015-02-03 10:06:31 -0600 | [diff] [blame] | 1387 | header_txt.append('// Track selected state for an object node') |
| 1388 | header_txt.append('static void track_object_status(void* pObj, XGL_STATE_BIND_POINT stateBindPoint) {') |
| 1389 | header_txt.append(' objNode *pTrav = pObjectHead[XGL_OBJECT_TYPE_CMD_BUFFER];') |
| 1390 | header_txt.append('') |
| 1391 | header_txt.append(' while (pTrav) {') |
| 1392 | header_txt.append(' if (pTrav->obj.pObj == pObj) {') |
| 1393 | header_txt.append(' if (stateBindPoint == XGL_STATE_BIND_VIEWPORT) {') |
| 1394 | header_txt.append(' pTrav->obj.status |= OBJSTATUS_VIEWPORT_BOUND;') |
| 1395 | header_txt.append(' } else if (stateBindPoint == XGL_STATE_BIND_RASTER) {') |
| 1396 | header_txt.append(' pTrav->obj.status |= OBJSTATUS_RASTER_BOUND;') |
| 1397 | header_txt.append(' } else if (stateBindPoint == XGL_STATE_BIND_COLOR_BLEND) {') |
| 1398 | header_txt.append(' pTrav->obj.status |= OBJSTATUS_COLOR_BLEND_BOUND;') |
| 1399 | header_txt.append(' } else if (stateBindPoint == XGL_STATE_BIND_DEPTH_STENCIL) {') |
| 1400 | header_txt.append(' pTrav->obj.status |= OBJSTATUS_DEPTH_STENCIL_BOUND;') |
| 1401 | header_txt.append(' }') |
| 1402 | header_txt.append(' return;') |
| 1403 | header_txt.append(' }') |
| 1404 | header_txt.append(' pTrav = pTrav->pNextObj;') |
| 1405 | header_txt.append(' }') |
| 1406 | header_txt.append(' // If we do not find it print an error') |
| 1407 | header_txt.append(' char str[1024];') |
| 1408 | header_txt.append(' sprintf(str, "Unable to track status for non-existent Command Buffer object %p", pObj);') |
| 1409 | header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);') |
| 1410 | header_txt.append('}') |
| 1411 | header_txt.append('') |
| 1412 | header_txt.append('// Reset selected flag state for an object node') |
| 1413 | header_txt.append('static void reset_status(void* pObj, XGL_OBJECT_TYPE objType, OBJECT_STATUS status_flag) {') |
Tobin Ehlis | 91ce77e | 2015-01-16 08:56:30 -0700 | [diff] [blame] | 1414 | header_txt.append(' objNode *pTrav = pObjectHead[objType];') |
| 1415 | header_txt.append(' while (pTrav) {') |
| 1416 | header_txt.append(' if (pTrav->obj.pObj == pObj) {') |
Mark Lobodzinski | 4037087 | 2015-02-03 10:06:31 -0600 | [diff] [blame] | 1417 | header_txt.append(' pTrav->obj.status &= ~status_flag;') |
| 1418 | header_txt.append(' return;') |
| 1419 | header_txt.append(' }') |
| 1420 | header_txt.append(' pTrav = pTrav->pNextObj;') |
| 1421 | header_txt.append(' }') |
| 1422 | header_txt.append(' // If we do not find it print an error') |
| 1423 | header_txt.append(' char str[1024];') |
| 1424 | header_txt.append(' sprintf(str, "Unable to reset status for non-existent object %p of %s type", pObj, string_XGL_OBJECT_TYPE(objType));') |
| 1425 | header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);') |
| 1426 | header_txt.append('}') |
| 1427 | header_txt.append('') |
| 1428 | header_txt.append('// Check object status for selected flag state') |
Mark Lobodzinski | 78a2197 | 2015-03-05 12:39:33 -0600 | [diff] [blame] | 1429 | header_txt.append('static bool32_t validate_status(void* pObj, XGL_OBJECT_TYPE objType, OBJECT_STATUS status_mask, OBJECT_STATUS status_flag, XGL_DBG_MSG_TYPE error_level, OBJECT_TRACK_ERROR error_code, char* fail_msg) {') |
Mark Lobodzinski | 4037087 | 2015-02-03 10:06:31 -0600 | [diff] [blame] | 1430 | header_txt.append(' objNode *pTrav = pObjectHead[objType];') |
| 1431 | header_txt.append(' while (pTrav) {') |
| 1432 | header_txt.append(' if (pTrav->obj.pObj == pObj) {') |
Mark Lobodzinski | 4988dea | 2015-02-03 11:52:26 -0600 | [diff] [blame] | 1433 | header_txt.append(' if ((pTrav->obj.status & status_mask) != status_flag) {') |
Tobin Ehlis | 91ce77e | 2015-01-16 08:56:30 -0700 | [diff] [blame] | 1434 | header_txt.append(' char str[1024];') |
| 1435 | header_txt.append(' sprintf(str, "OBJECT VALIDATION WARNING: %s object %p: %s", string_XGL_OBJECT_TYPE(objType), (void*)pObj, fail_msg);') |
Mark Lobodzinski | 4037087 | 2015-02-03 10:06:31 -0600 | [diff] [blame] | 1436 | header_txt.append(' layerCbMsg(error_level, XGL_VALIDATION_LEVEL_0, pObj, 0, error_code, "OBJTRACK", str);') |
Mark Lobodzinski | 78a2197 | 2015-03-05 12:39:33 -0600 | [diff] [blame] | 1437 | header_txt.append(' return XGL_FALSE;') |
Tobin Ehlis | 91ce77e | 2015-01-16 08:56:30 -0700 | [diff] [blame] | 1438 | header_txt.append(' }') |
Mark Lobodzinski | 78a2197 | 2015-03-05 12:39:33 -0600 | [diff] [blame] | 1439 | header_txt.append(' return XGL_TRUE;') |
Tobin Ehlis | 91ce77e | 2015-01-16 08:56:30 -0700 | [diff] [blame] | 1440 | header_txt.append(' }') |
| 1441 | header_txt.append(' pTrav = pTrav->pNextObj;') |
| 1442 | header_txt.append(' }') |
Mark Lobodzinski | 78a2197 | 2015-03-05 12:39:33 -0600 | [diff] [blame] | 1443 | header_txt.append(' if (objType != XGL_OBJECT_TYPE_PRESENTABLE_IMAGE_MEMORY) {') |
| 1444 | header_txt.append(' // If we do not find it print an error') |
| 1445 | header_txt.append(' char str[1024];') |
| 1446 | header_txt.append(' sprintf(str, "Unable to obtain status for non-existent object %p of %s type", pObj, string_XGL_OBJECT_TYPE(objType));') |
| 1447 | header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);') |
| 1448 | header_txt.append(' }') |
| 1449 | header_txt.append(' return XGL_FALSE;') |
Tobin Ehlis | 91ce77e | 2015-01-16 08:56:30 -0700 | [diff] [blame] | 1450 | header_txt.append('}') |
Mark Lobodzinski | 4037087 | 2015-02-03 10:06:31 -0600 | [diff] [blame] | 1451 | header_txt.append('') |
| 1452 | header_txt.append('static void validate_draw_state_flags(void* pObj) {') |
Mark Lobodzinski | 4988dea | 2015-02-03 11:52:26 -0600 | [diff] [blame] | 1453 | header_txt.append(' validate_status((void*)pObj, XGL_OBJECT_TYPE_CMD_BUFFER, OBJSTATUS_VIEWPORT_BOUND, OBJSTATUS_VIEWPORT_BOUND, XGL_DBG_MSG_ERROR, OBJTRACK_VIEWPORT_NOT_BOUND, "Viewport object not bound to this command buffer");') |
| 1454 | header_txt.append(' validate_status((void*)pObj, XGL_OBJECT_TYPE_CMD_BUFFER, OBJSTATUS_RASTER_BOUND, OBJSTATUS_RASTER_BOUND, XGL_DBG_MSG_ERROR, OBJTRACK_RASTER_NOT_BOUND, "Raster object not bound to this command buffer");') |
| 1455 | header_txt.append(' validate_status((void*)pObj, XGL_OBJECT_TYPE_CMD_BUFFER, OBJSTATUS_COLOR_BLEND_BOUND, OBJSTATUS_COLOR_BLEND_BOUND, XGL_DBG_MSG_UNKNOWN, OBJTRACK_COLOR_BLEND_NOT_BOUND, "Color-blend object not bound to this command buffer");') |
| 1456 | header_txt.append(' validate_status((void*)pObj, XGL_OBJECT_TYPE_CMD_BUFFER, OBJSTATUS_DEPTH_STENCIL_BOUND, OBJSTATUS_DEPTH_STENCIL_BOUND, XGL_DBG_MSG_UNKNOWN, OBJTRACK_DEPTH_STENCIL_NOT_BOUND, "Depth-stencil object not bound to this command buffer");') |
| 1457 | header_txt.append('}') |
| 1458 | header_txt.append('') |
| 1459 | header_txt.append('static void validate_memory_mapping_status(const XGL_MEMORY_REF* pMemRefs, uint32_t numRefs) {') |
Ian Elliott | a83a58a | 2015-02-04 12:15:12 -0700 | [diff] [blame] | 1460 | header_txt.append(' uint32_t i;') |
Mark Lobodzinski | 4988dea | 2015-02-03 11:52:26 -0600 | [diff] [blame] | 1461 | header_txt.append(' for (i = 0; i < numRefs; i++) {') |
Mark Lobodzinski | 78a2197 | 2015-03-05 12:39:33 -0600 | [diff] [blame] | 1462 | header_txt.append(' if(pMemRefs[i].mem) {') |
| 1463 | header_txt.append(' // If mem reference is in presentable image memory list, skip the check of the GPU_MEMORY list') |
| 1464 | header_txt.append(' if (!validate_status((void *)pMemRefs[i].mem, XGL_OBJECT_TYPE_PRESENTABLE_IMAGE_MEMORY, OBJSTATUS_NONE, OBJSTATUS_NONE, XGL_DBG_MSG_UNKNOWN, OBJTRACK_NONE, NULL) == XGL_TRUE)') |
| 1465 | header_txt.append(' {') |
| 1466 | header_txt.append(' validate_status((void *)pMemRefs[i].mem, XGL_OBJECT_TYPE_GPU_MEMORY, OBJSTATUS_GPU_MEM_MAPPED, OBJSTATUS_NONE, XGL_DBG_MSG_ERROR, OBJTRACK_GPU_MEM_MAPPED, "A Mapped Memory Object was referenced in a command buffer");') |
| 1467 | header_txt.append(' }') |
| 1468 | header_txt.append(' }') |
Mark Lobodzinski | 4988dea | 2015-02-03 11:52:26 -0600 | [diff] [blame] | 1469 | header_txt.append(' }') |
Mark Lobodzinski | 4037087 | 2015-02-03 10:06:31 -0600 | [diff] [blame] | 1470 | header_txt.append('}') |
Mark Lobodzinski | aae93e5 | 2015-02-09 10:20:53 -0600 | [diff] [blame] | 1471 | header_txt.append('') |
| 1472 | header_txt.append('static void validate_mem_ref_count(uint32_t numRefs) {') |
| 1473 | header_txt.append(' if (maxMemRefsPerSubmission == 0) {') |
| 1474 | header_txt.append(' char str[1024];') |
| 1475 | header_txt.append(' sprintf(str, "xglQueueSubmit called before calling xglGetGpuInfo");') |
| 1476 | header_txt.append(' layerCbMsg(XGL_DBG_MSG_WARNING, XGL_VALIDATION_LEVEL_0, NULL, 0, OBJTRACK_GETGPUINFO_NOT_CALLED, "OBJTRACK", str);') |
| 1477 | header_txt.append(' } else {') |
| 1478 | header_txt.append(' if (numRefs > maxMemRefsPerSubmission) {') |
| 1479 | header_txt.append(' char str[1024];') |
| 1480 | header_txt.append(' sprintf(str, "xglQueueSubmit Memory reference count (%d) exceeds allowable GPU limit (%d)", numRefs, maxMemRefsPerSubmission);') |
| 1481 | header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, OBJTRACK_MEMREFCOUNT_MAX_EXCEEDED, "OBJTRACK", str);') |
| 1482 | header_txt.append(' }') |
| 1483 | header_txt.append(' }') |
| 1484 | header_txt.append('}') |
| 1485 | header_txt.append('') |
| 1486 | header_txt.append('static void setGpuInfoState(void *pData) {') |
| 1487 | header_txt.append(' maxMemRefsPerSubmission = ((XGL_PHYSICAL_GPU_PROPERTIES *)pData)->maxMemRefsPerSubmission;') |
| 1488 | header_txt.append('}') |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1489 | return "\n".join(header_txt) |
| 1490 | |
| 1491 | def generate_body(self): |
Tobin Ehlis | 36f1b46 | 2015-02-23 14:09:16 -0700 | [diff] [blame] | 1492 | body = [self._generate_layer_initialization("ObjectTracker", True, lockname='obj'), |
Tobin Ehlis | a363cfa | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 1493 | self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "ObjectTracker"), |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1494 | self._generate_extensions(), |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 1495 | self._generate_layer_gpa_function("ObjectTracker", extensions=['objTrackGetObjectCount', 'objTrackGetObjects'])] |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1496 | |
| 1497 | return "\n\n".join(body) |
Courtney Goeltzenleuchter | b412d21 | 2014-11-18 10:40:29 -0700 | [diff] [blame] | 1498 | |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1499 | class ParamCheckerSubcommand(Subcommand): |
| 1500 | def generate_header(self): |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 1501 | return '#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include "loader_platform.h"\n#include "xglLayer.h"\n#include "layers_config.h"\n#include "xgl_enum_validate_helper.h"\n#include "xgl_struct_validate_helper.h"\n//The following is #included again to catch certain OS-specific functions being used:\n#include "loader_platform.h"\n\n#include "layers_msg.h"\n\nstatic XGL_LAYER_DISPATCH_TABLE nextTable;\nstatic XGL_BASE_LAYER_OBJECT *pCurObj;\nstatic LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);\n\n' |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1502 | |
| 1503 | def generate_body(self): |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 1504 | body = [self._generate_layer_initialization("ParamChecker", True), |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1505 | self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "ParamChecker"), |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 1506 | self._generate_layer_gpa_function("ParamChecker")] |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1507 | |
| 1508 | return "\n\n".join(body) |
| 1509 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1510 | def main(): |
| 1511 | subcommands = { |
| 1512 | "layer-funcs" : LayerFuncsSubcommand, |
| 1513 | "layer-dispatch" : LayerDispatchSubcommand, |
Tobin Ehlis | a363cfa | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 1514 | "Generic" : GenericLayerSubcommand, |
| 1515 | "ApiDump" : ApiDumpSubcommand, |
| 1516 | "ApiDumpFile" : ApiDumpFileSubcommand, |
Tobin Ehlis | d49efcb | 2014-11-25 17:43:26 -0700 | [diff] [blame] | 1517 | "ApiDumpNoAddr" : ApiDumpNoAddrSubcommand, |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1518 | "ApiDumpCpp" : ApiDumpCppSubcommand, |
| 1519 | "ApiDumpNoAddrCpp" : ApiDumpNoAddrCppSubcommand, |
Tobin Ehlis | a363cfa | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 1520 | "ObjectTracker" : ObjectTrackerSubcommand, |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1521 | "ParamChecker" : ParamCheckerSubcommand, |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1522 | } |
| 1523 | |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1524 | if len(sys.argv) < 3 or sys.argv[1] not in subcommands or not os.path.exists(sys.argv[2]): |
| 1525 | print("Usage: %s <subcommand> <input_header> [options]" % sys.argv[0]) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1526 | print |
Tobin Ehlis | 7e65d75 | 2015-01-15 17:51:52 -0700 | [diff] [blame] | 1527 | print("Available subcommands are: %s" % " ".join(subcommands)) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1528 | exit(1) |
| 1529 | |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1530 | hfp = xgl_helper.HeaderFileParser(sys.argv[2]) |
| 1531 | hfp.parse() |
| 1532 | xgl_helper.enum_val_dict = hfp.get_enum_val_dict() |
| 1533 | xgl_helper.enum_type_dict = hfp.get_enum_type_dict() |
| 1534 | xgl_helper.struct_dict = hfp.get_struct_dict() |
| 1535 | xgl_helper.typedef_fwd_dict = hfp.get_typedef_fwd_dict() |
| 1536 | xgl_helper.typedef_rev_dict = hfp.get_typedef_rev_dict() |
| 1537 | xgl_helper.types_dict = hfp.get_types_dict() |
| 1538 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1539 | subcmd = subcommands[sys.argv[1]](sys.argv[2:]) |
| 1540 | subcmd.run() |
| 1541 | |
| 1542 | if __name__ == "__main__": |
| 1543 | main() |