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