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