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