blob: 01aafb6bc02f13880cf528bb70f1502d23aa62e3 [file] [log] [blame]
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001#!/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
28import sys
Tobin Ehlis6cd06372014-12-17 17:44:50 -070029import os
Tobin Ehlis92dbf802014-10-22 09:06:33 -060030
31import xgl
Tobin Ehlis6cd06372014-12-17 17:44:50 -070032import xgl_helper
Tobin Ehlis92dbf802014-10-22 09:06:33 -060033
34class Subcommand(object):
35 def __init__(self, argv):
36 self.argv = argv
Chia-I Wuec30dcb2015-01-01 08:46:31 +080037 self.headers = xgl.headers
38 self.protos = xgl.protos
Tobin Ehlis92dbf802014-10-22 09:06:33 -060039
40 def run(self):
Tobin Ehlis92dbf802014-10-22 09:06:33 -060041 print(self.generate())
42
43 def generate(self):
44 copyright = self.generate_copyright()
45 header = self.generate_header()
46 body = self.generate_body()
47 footer = self.generate_footer()
48
49 contents = []
50 if copyright:
51 contents.append(copyright)
52 if header:
53 contents.append(header)
54 if body:
55 contents.append(body)
56 if footer:
57 contents.append(footer)
58
59 return "\n\n".join(contents)
60
61 def generate_copyright(self):
62 return """/* THIS FILE IS GENERATED. DO NOT EDIT. */
63
64/*
65 * XGL
66 *
67 * Copyright (C) 2014 LunarG, Inc.
68 *
69 * Permission is hereby granted, free of charge, to any person obtaining a
70 * copy of this software and associated documentation files (the "Software"),
71 * to deal in the Software without restriction, including without limitation
72 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
73 * and/or sell copies of the Software, and to permit persons to whom the
74 * Software is furnished to do so, subject to the following conditions:
75 *
76 * The above copyright notice and this permission notice shall be included
77 * in all copies or substantial portions of the Software.
78 *
79 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
80 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
81 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
82 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
83 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
84 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
85 * DEALINGS IN THE SOFTWARE.
86 */"""
87
88 def generate_header(self):
89 return "\n".join(["#include <" + h + ">" for h in self.headers])
90
91 def generate_body(self):
92 pass
93
94 def generate_footer(self):
95 pass
96
97 # Return set of printf '%' qualifier and input to that qualifier
Tobin Ehlis434db7c2015-01-10 12:42:41 -070098 def _get_printf_params(self, xgl_type, name, output_param, cpp=False):
Tobin Ehlis92dbf802014-10-22 09:06:33 -060099 # TODO : Need ENUM and STRUCT checks here
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700100 if xgl_helper.is_type(xgl_type, 'enum'):#"_TYPE" in xgl_type: # TODO : This should be generic ENUM check
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600101 return ("%s", "string_%s(%s)" % (xgl_type.strip('const ').strip('*'), name))
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600102 if "char*" == xgl_type:
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600103 return ("%s", name)
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700104 if "uint64" in xgl_type:
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600105 if '*' in xgl_type:
106 return ("%lu", "*%s" % name)
107 return ("%lu", name)
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700108 if "size" in xgl_type:
Chia-I Wu54ed0792014-12-27 14:14:50 +0800109 if '*' in xgl_type:
110 return ("%zu", "*%s" % name)
111 return ("%zu", name)
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700112 if "float" in xgl_type:
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600113 if '[' in xgl_type: # handle array, current hard-coded to 4 (TODO: Make this dynamic)
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700114 if cpp:
115 return ("[%i, %i, %i, %i]", '"[" << %s[0] << "," << %s[1] << "," << %s[2] << "," << %s[3] << "]"' % (name, name, name, name))
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600116 return ("[%f, %f, %f, %f]", "%s[0], %s[1], %s[2], %s[3]" % (name, name, name, name))
117 return ("%f", name)
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700118 if "bool" in xgl_type or 'xcb_randr_crtc_t' in xgl_type:
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600119 return ("%u", name)
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700120 if True in [t in xgl_type for t in ["int", "FLAGS", "MASK", "xcb_window_t"]]:
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600121 if '[' in xgl_type: # handle array, current hard-coded to 4 (TODO: Make this dynamic)
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700122 if cpp:
123 return ("[%i, %i, %i, %i]", "%s[0] << %s[1] << %s[2] << %s[3]" % (name, name, name, name))
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600124 return ("[%i, %i, %i, %i]", "%s[0], %s[1], %s[2], %s[3]" % (name, name, name, name))
125 if '*' in xgl_type:
Tobin Ehlis1336c8d2015-02-04 15:15:11 -0700126 if 'pUserData' == name:
127 return ("%i", "((pUserData == 0) ? 0 : *(pUserData))")
Jon Ashburn1f7e2d72014-12-12 16:10:45 -0700128 return ("%i", "*(%s)" % name)
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600129 return ("%i", name)
Tobin Ehlis0a1e06d2014-11-11 17:28:22 -0700130 # TODO : This is special-cased as there's only one "format" param currently and it's nice to expand it
Jon Ashburn1f7e2d72014-12-12 16:10:45 -0700131 if "XGL_FORMAT" == xgl_type:
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700132 if cpp:
133 return ("%p", "&%s" % name)
134 return ("{%s.channelFormat = %%s, %s.numericFormat = %%s}" % (name, name), "string_XGL_CHANNEL_FORMAT(%s.channelFormat), string_XGL_NUM_FORMAT(%s.numericFormat)" % (name, name))
Tobin Ehlisa554dc32014-11-19 15:52:46 -0700135 if output_param:
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600136 return ("%p", "(void*)*%s" % name)
Jon Ashburn1f7e2d72014-12-12 16:10:45 -0700137 return ("%p", "(void*)(%s)" % name)
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600138
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700139 def _gen_layer_dbg_callback_register(self):
140 r_body = []
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600141 r_body.append('XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglDbgRegisterMsgCallback(XGL_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback, void* pUserData)')
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700142 r_body.append('{')
143 r_body.append(' // This layer intercepts callbacks')
144 r_body.append(' XGL_LAYER_DBG_FUNCTION_NODE *pNewDbgFuncNode = (XGL_LAYER_DBG_FUNCTION_NODE*)malloc(sizeof(XGL_LAYER_DBG_FUNCTION_NODE));')
145 r_body.append(' if (!pNewDbgFuncNode)')
146 r_body.append(' return XGL_ERROR_OUT_OF_MEMORY;')
147 r_body.append(' pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;')
148 r_body.append(' pNewDbgFuncNode->pUserData = pUserData;')
Jon Ashburn21001f62015-02-16 08:26:50 -0700149 r_body.append(' pNewDbgFuncNode->pNext = g_pDbgFunctionHead;')
150 r_body.append(' g_pDbgFunctionHead = pNewDbgFuncNode;')
Jon Ashburne4722392015-03-03 15:07:15 -0700151 r_body.append(' // force callbacks if DebugAction hasn\'t been set already other than initial value')
Ian Elliottc9473d92015-03-05 12:28:53 -0700152 r_body.append(' if (g_actionIsDefault) {')
Jon Ashburne4722392015-03-03 15:07:15 -0700153 r_body.append(' g_debugAction = XGL_DBG_LAYER_ACTION_CALLBACK;')
Ian Elliottc9473d92015-03-05 12:28:53 -0700154 r_body.append(' }')
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700155 r_body.append(' XGL_RESULT result = nextTable.DbgRegisterMsgCallback(pfnMsgCallback, pUserData);')
156 r_body.append(' return result;')
157 r_body.append('}')
158 return "\n".join(r_body)
159
160 def _gen_layer_dbg_callback_unregister(self):
161 ur_body = []
162 ur_body.append('XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglDbgUnregisterMsgCallback(XGL_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback)')
163 ur_body.append('{')
Jon Ashburn21001f62015-02-16 08:26:50 -0700164 ur_body.append(' XGL_LAYER_DBG_FUNCTION_NODE *pTrav = g_pDbgFunctionHead;')
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700165 ur_body.append(' XGL_LAYER_DBG_FUNCTION_NODE *pPrev = pTrav;')
166 ur_body.append(' while (pTrav) {')
167 ur_body.append(' if (pTrav->pfnMsgCallback == pfnMsgCallback) {')
168 ur_body.append(' pPrev->pNext = pTrav->pNext;')
Jon Ashburn21001f62015-02-16 08:26:50 -0700169 ur_body.append(' if (g_pDbgFunctionHead == pTrav)')
170 ur_body.append(' g_pDbgFunctionHead = pTrav->pNext;')
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700171 ur_body.append(' free(pTrav);')
172 ur_body.append(' break;')
173 ur_body.append(' }')
174 ur_body.append(' pPrev = pTrav;')
175 ur_body.append(' pTrav = pTrav->pNext;')
176 ur_body.append(' }')
Jon Ashburne4722392015-03-03 15:07:15 -0700177 ur_body.append(' if (g_pDbgFunctionHead == NULL)')
178 ur_body.append(' {')
179 ur_body.append(' if (g_actionIsDefault)')
180 ur_body.append(' g_debugAction = XGL_DBG_LAYER_ACTION_LOG_MSG;')
181 ur_body.append(' else')
182 ur_body.append(' g_debugAction &= ~XGL_DBG_LAYER_ACTION_CALLBACK;')
183 ur_body.append(' }')
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700184 ur_body.append(' XGL_RESULT result = nextTable.DbgUnregisterMsgCallback(pfnMsgCallback);')
185 ur_body.append(' return result;')
186 ur_body.append('}')
187 return "\n".join(ur_body)
188
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -0700189 def _generate_dispatch_entrypoints(self, qual="", layer="Generic", no_addr=False):
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600190 if qual:
191 qual += " "
192
Tobin Ehlis907a0522014-11-25 16:59:27 -0700193 layer_name = layer
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -0700194 if no_addr:
195 layer_name = "%sNoAddr" % layer
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700196 if 'Cpp' in layer_name:
197 layer_name = "APIDumpNoAddrCpp"
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600198 funcs = []
199 for proto in self.protos:
200 if proto.name != "GetProcAddr" and proto.name != "InitAndEnumerateGpus":
Tobin Ehlis907a0522014-11-25 16:59:27 -0700201 if "Generic" == layer:
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600202 decl = proto.c_func(prefix="xgl", attr="XGLAPI")
203 param0_name = proto.params[0].name
204 ret_val = ''
205 stmt = ''
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600206 if proto.ret != "void":
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600207 ret_val = "XGL_RESULT result = "
208 stmt = " return result;\n"
Ian Elliott81ac44c2015-01-13 17:52:38 -0700209 if 'WsiX11AssociateConnection' == proto.name:
Ian Elliotte977a6c2015-02-26 14:34:52 -0700210 funcs.append("#if defined(__linux__) || defined(XCB_NVIDIA)")
Jon Ashburn451c16f2014-11-25 11:08:42 -0700211 if proto.name == "EnumerateLayers":
212 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
213 funcs.append('%s%s\n'
214 '{\n'
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700215 ' char str[1024];\n'
Jon Ashburn451c16f2014-11-25 11:08:42 -0700216 ' if (gpu != NULL) {\n'
217 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700218 ' sprintf(str, "At start of layered %s\\n");\n'
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600219 ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpu, 0, 0, (char *) "GENERIC", (char *) str);\n'
Jon Ashburn451c16f2014-11-25 11:08:42 -0700220 ' pCurObj = gpuw;\n'
Jon Ashburn21001f62015-02-16 08:26:50 -0700221 ' loader_platform_thread_once(&tabOnce, init%s);\n'
Jon Ashburn451c16f2014-11-25 11:08:42 -0700222 ' %snextTable.%s;\n'
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700223 ' sprintf(str, "Completed layered %s\\n");\n'
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600224 ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpu, 0, 0, (char *) "GENERIC", (char *) str);\n'
Jon Ashburn451c16f2014-11-25 11:08:42 -0700225 ' fflush(stdout);\n'
226 ' %s'
227 ' } else {\n'
228 ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n'
229 ' return XGL_ERROR_INVALID_POINTER;\n'
230 ' // This layer compatible with all GPUs\n'
231 ' *pOutLayerCount = 1;\n'
Chia-I Wua837c522014-12-16 10:47:33 +0800232 ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n'
Jon Ashburn451c16f2014-11-25 11:08:42 -0700233 ' return XGL_SUCCESS;\n'
234 ' }\n'
Jon Ashburn21001f62015-02-16 08:26:50 -0700235 '}' % (qual, decl, proto.params[0].name, proto.name, layer_name, ret_val, c_call, proto.name, stmt, layer_name))
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700236 elif 'DbgRegisterMsgCallback' == proto.name:
237 funcs.append(self._gen_layer_dbg_callback_register())
238 elif 'DbgUnregisterMsgCallback' == proto.name:
239 funcs.append(self._gen_layer_dbg_callback_unregister())
Jon Ashburn451c16f2014-11-25 11:08:42 -0700240 elif proto.params[0].ty != "XGL_PHYSICAL_GPU":
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600241 funcs.append('%s%s\n'
242 '{\n'
243 ' %snextTable.%s;\n'
244 '%s'
245 '}' % (qual, decl, ret_val, proto.c_call(), stmt))
246 else:
247 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
248 funcs.append('%s%s\n'
249 '{\n'
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700250 ' char str[1024];'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600251 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700252 ' sprintf(str, "At start of layered %s\\n");\n'
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600253 ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpuw, 0, 0, (char *) "GENERIC", (char *) str);\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600254 ' pCurObj = gpuw;\n'
Jon Ashburn21001f62015-02-16 08:26:50 -0700255 ' loader_platform_thread_once(&tabOnce, init%s);\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600256 ' %snextTable.%s;\n'
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700257 ' sprintf(str, "Completed layered %s\\n");\n'
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600258 ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpuw, 0, 0, (char *) "GENERIC", (char *) str);\n'
Courtney Goeltzenleuchtere6094fc2014-11-18 10:40:29 -0700259 ' fflush(stdout);\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600260 '%s'
Jon Ashburn21001f62015-02-16 08:26:50 -0700261 '}' % (qual, decl, proto.params[0].name, proto.name, layer_name, ret_val, c_call, proto.name, stmt))
Ian Elliott81ac44c2015-01-13 17:52:38 -0700262 if 'WsiX11QueuePresent' == proto.name:
263 funcs.append("#endif")
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700264 elif "APIDumpCpp" in layer:
265 decl = proto.c_func(prefix="xgl", attr="XGLAPI")
266 param0_name = proto.params[0].name
267 ret_val = ''
268 stmt = ''
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700269 sp_param_dict = {} # Store 'index' for struct param to print, or an name of binding "Count" param for array to print
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700270 create_params = 0 # Num of params at end of function that are created and returned as output values
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700271 if 'WsiX11CreatePresentableImage' in proto.name or 'AllocDescriptorSets' in proto.name:
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700272 create_params = -2
273 elif 'Create' in proto.name or 'Alloc' in proto.name or 'MapMemory' in proto.name:
274 create_params = -1
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600275 if proto.ret != "void":
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700276 ret_val = "XGL_RESULT result = "
277 stmt = " return result;\n"
278 f_open = ''
279 f_close = ''
280 if "File" in layer:
281 file_mode = "a"
282 if 'CreateDevice' in proto.name:
283 file_mode = "w"
Ian Elliott81ac44c2015-01-13 17:52:38 -0700284 f_open = 'loader_platform_thread_lock_mutex(&printLock);\n pOutFile = fopen(outFileName, "%s");\n ' % (file_mode)
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700285 log_func = 'fprintf(pOutFile, "t{%%u} xgl%s(' % proto.name
Ian Elliott81ac44c2015-01-13 17:52:38 -0700286 f_close = '\n fclose(pOutFile);\n loader_platform_thread_unlock_mutex(&printLock);'
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700287 else:
Ian Elliott81ac44c2015-01-13 17:52:38 -0700288 f_open = 'loader_platform_thread_lock_mutex(&printLock);\n '
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700289 log_func = 'cout << "t{" << getTIDIndex() << "} xgl%s(' % proto.name
Ian Elliott81ac44c2015-01-13 17:52:38 -0700290 f_close = '\n loader_platform_thread_unlock_mutex(&printLock);'
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700291 pindex = 0
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700292 prev_count_name = ''
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700293 for p in proto.params:
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700294 cp = False
295 if 0 != create_params:
296 # If this is any of the N last params of the func, treat as output
297 for y in range(-1, create_params-1, -1):
298 if p.name == proto.params[y].name:
299 cp = True
300 (pft, pfi) = self._get_printf_params(p.ty, p.name, cp, cpp=True)
301 if no_addr and "%p" == pft:
302 (pft, pfi) = ("%s", '"addr"')
303 log_func += '%s = " << %s << ", ' % (p.name, pfi)
304 #print_vals += ', %s' % (pfi)
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700305 if prev_count_name != '' and (prev_count_name.strip('Count')[1:] in p.name or 'slotCount' == prev_count_name):
306 sp_param_dict[pindex] = prev_count_name
307 elif 'pDescriptorSets' == p.name and proto.params[-1].name == 'pCount':
308 sp_param_dict[pindex] = '*pCount'
Tobin Ehlisfc04b892015-01-22 12:29:31 -0700309 elif 'Wsi' not in proto.name and xgl_helper.is_type(p.ty.strip('*').strip('const '), 'struct'):
310 sp_param_dict[pindex] = 'index'
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700311 pindex += 1
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700312 if p.name.endswith('Count'):
313 if '*' in p.ty:
314 prev_count_name = "*%s" % p.name
315 else:
316 prev_count_name = p.name
317 else:
318 prev_count_name = ''
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700319 log_func = log_func.strip(', ')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600320 if proto.ret != "void":
Courtney Goeltzenleuchter224e1382015-02-26 11:40:39 -0700321 log_func += ') = " << string_XGL_RESULT((XGL_RESULT)result) << endl'
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700322 #print_vals += ', string_XGL_RESULT_CODE(result)'
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700323 else:
324 log_func += ')\\n"'
325 log_func += ';'
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700326 if len(sp_param_dict) > 0:
327 i_decl = False
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700328 log_func += '\n string tmp_str;'
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700329 for sp_index in sp_param_dict:
330 if 'index' == sp_param_dict[sp_index]:
331 cis_print_func = 'xgl_print_%s' % (proto.params[sp_index].ty.strip('const ').strip('*').lower())
332 log_func += '\n if (%s) {' % (proto.params[sp_index].name)
333 log_func += '\n tmp_str = %s(%s, " ");' % (cis_print_func, proto.params[sp_index].name)
334 if "File" in layer:
335 if no_addr:
336 log_func += '\n fprintf(pOutFile, " %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name)
337 else:
338 log_func += '\n fprintf(pOutFile, " %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name)
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700339 else:
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700340 if no_addr:
341 #log_func += '\n printf(" %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name)
342 log_func += '\n cout << " %s (addr)" << endl << tmp_str << endl;' % (proto.params[sp_index].name)
343 else:
344 #log_func += '\n printf(" %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name)
345 log_func += '\n cout << " %s (" << %s << ")" << endl << tmp_str << endl;' % (proto.params[sp_index].name, proto.params[sp_index].name)
346 #log_func += '\n fflush(stdout);'
347 log_func += '\n }'
348 else: # We have a count value stored to iterate over an array
349 print_cast = ''
350 print_func = ''
351 if xgl_helper.is_type(proto.params[sp_index].ty.strip('*').strip('const '), 'struct'):
352 print_cast = '&'
353 print_func = 'xgl_print_%s' % proto.params[sp_index].ty.strip('const ').strip('*').lower()
354 #cis_print_func = 'tmp_str = xgl_print_%s(&%s[i], " ");' % (proto.params[sp_index].ty.strip('const ').strip('*').lower(), proto.params[sp_index].name)
355# TODO : Need to display this address as a string
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700356 else:
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700357 print_cast = '(void*)'
358 print_func = 'string_convert_helper'
359 #cis_print_func = 'tmp_str = string_convert_helper((void*)%s[i], " ");' % proto.params[sp_index].name
360 cis_print_func = 'tmp_str = %s(%s%s[i], " ");' % (print_func, print_cast, proto.params[sp_index].name)
361# else:
362# cis_print_func = ''
363 if not i_decl:
364 log_func += '\n uint32_t i;'
365 i_decl = True
366 log_func += '\n for (i = 0; i < %s; i++) {' % (sp_param_dict[sp_index])
367 log_func += '\n %s' % (cis_print_func)
368 if "File" in layer:
369 if no_addr:
370 log_func += '\n fprintf(pOutFile, " %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name)
371 else:
372 log_func += '\n fprintf(pOutFile, " %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name)
373 else:
374 if no_addr:
375 #log_func += '\n printf(" %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name)
376 log_func += '\n cout << " %s[" << (uint32_t)i << "] (addr)" << endl << tmp_str << endl;' % (proto.params[sp_index].name)
377 else:
378 #log_func += '\n printf(" %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name)
379 #log_func += '\n cout << " %s[" << (uint32_t)i << "] (" << %s[i] << ")" << endl << tmp_str << endl;' % (proto.params[sp_index].name, proto.params[sp_index].name)
380 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)
381 #log_func += '\n fflush(stdout);'
382 log_func += '\n }'
Ian Elliott81ac44c2015-01-13 17:52:38 -0700383 if 'WsiX11AssociateConnection' == proto.name:
Ian Elliotte977a6c2015-02-26 14:34:52 -0700384 funcs.append("#if defined(__linux__) || defined(XCB_NVIDIA)")
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700385 if proto.name == "EnumerateLayers":
386 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
387 funcs.append('%s%s\n'
388 '{\n'
389 ' if (gpu != NULL) {\n'
390 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
391 ' pCurObj = gpuw;\n'
Jon Ashburn21001f62015-02-16 08:26:50 -0700392 ' loader_platform_thread_once(&tabOnce, init%s);\n'
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700393 ' %snextTable.%s;\n'
394 ' %s %s %s\n'
395 ' %s'
396 ' } else {\n'
397 ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n'
398 ' return XGL_ERROR_INVALID_POINTER;\n'
399 ' // This layer compatible with all GPUs\n'
400 ' *pOutLayerCount = 1;\n'
401 ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n'
402 ' return XGL_SUCCESS;\n'
403 ' }\n'
Jon Ashburn21001f62015-02-16 08:26:50 -0700404 '}' % (qual, decl, proto.params[0].name, layer_name, ret_val, c_call,f_open, log_func, f_close, stmt, layer_name))
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700405 elif proto.params[0].ty != "XGL_PHYSICAL_GPU":
406 funcs.append('%s%s\n'
407 '{\n'
408 ' %snextTable.%s;\n'
409 ' %s%s%s\n'
410 '%s'
411 '}' % (qual, decl, ret_val, proto.c_call(), f_open, log_func, f_close, stmt))
412 else:
413 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
414 funcs.append('%s%s\n'
415 '{\n'
416 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
417 ' pCurObj = gpuw;\n'
Jon Ashburn21001f62015-02-16 08:26:50 -0700418 ' loader_platform_thread_once(&tabOnce, init%s);\n'
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700419 ' %snextTable.%s;\n'
420 ' %s%s%s\n'
421 '%s'
Jon Ashburn21001f62015-02-16 08:26:50 -0700422 '}' % (qual, decl, proto.params[0].name, layer_name, ret_val, c_call, f_open, log_func, f_close, stmt))
Ian Elliott81ac44c2015-01-13 17:52:38 -0700423 if 'WsiX11QueuePresent' == proto.name:
424 funcs.append("#endif")
Tobin Ehlis907a0522014-11-25 16:59:27 -0700425 elif "APIDump" in layer:
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600426 decl = proto.c_func(prefix="xgl", attr="XGLAPI")
427 param0_name = proto.params[0].name
428 ret_val = ''
429 stmt = ''
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700430 sp_param_dict = {} # Store 'index' for struct param to print, or an name of binding "Count" param for array to print
Tobin Ehlisa554dc32014-11-19 15:52:46 -0700431 create_params = 0 # Num of params at end of function that are created and returned as output values
432 if 'WsiX11CreatePresentableImage' in proto.name:
433 create_params = -2
434 elif 'Create' in proto.name or 'Alloc' in proto.name or 'MapMemory' in proto.name:
435 create_params = -1
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600436 if proto.ret != "void":
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600437 ret_val = "XGL_RESULT result = "
438 stmt = " return result;\n"
Tobin Ehlis574b0142014-11-12 13:11:15 -0700439 f_open = ''
440 f_close = ''
Tobin Ehlis907a0522014-11-25 16:59:27 -0700441 if "File" in layer:
Tobin Ehlis1eba7792014-11-21 09:35:53 -0700442 file_mode = "a"
443 if 'CreateDevice' in proto.name:
444 file_mode = "w"
Ian Elliott81ac44c2015-01-13 17:52:38 -0700445 f_open = 'loader_platform_thread_lock_mutex(&printLock);\n pOutFile = fopen(outFileName, "%s");\n ' % (file_mode)
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700446 log_func = 'fprintf(pOutFile, "t{%%u} xgl%s(' % proto.name
Ian Elliott81ac44c2015-01-13 17:52:38 -0700447 f_close = '\n fclose(pOutFile);\n loader_platform_thread_unlock_mutex(&printLock);'
Tobin Ehlis574b0142014-11-12 13:11:15 -0700448 else:
Ian Elliott81ac44c2015-01-13 17:52:38 -0700449 f_open = 'loader_platform_thread_lock_mutex(&printLock);\n '
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700450 log_func = 'printf("t{%%u} xgl%s(' % proto.name
Ian Elliott81ac44c2015-01-13 17:52:38 -0700451 f_close = '\n loader_platform_thread_unlock_mutex(&printLock);'
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700452 print_vals = ', getTIDIndex()'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600453 pindex = 0
Tobin Ehlisc7e926b2014-12-18 15:20:05 -0700454 prev_count_name = ''
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600455 for p in proto.params:
Tobin Ehlisa554dc32014-11-19 15:52:46 -0700456 cp = False
457 if 0 != create_params:
458 # If this is any of the N last params of the func, treat as output
459 for y in range(-1, create_params-1, -1):
460 if p.name == proto.params[y].name:
461 cp = True
462 (pft, pfi) = self._get_printf_params(p.ty, p.name, cp)
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -0700463 if no_addr and "%p" == pft:
464 (pft, pfi) = ("%s", '"addr"')
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600465 log_func += '%s = %s, ' % (p.name, pft)
466 print_vals += ', %s' % (pfi)
Tobin Ehlisc7e926b2014-12-18 15:20:05 -0700467 # Catch array inputs that are bound by a "Count" param
468 if prev_count_name != '' and (prev_count_name.strip('Count')[1:] in p.name or 'slotCount' == prev_count_name):
469 sp_param_dict[pindex] = prev_count_name
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700470 elif 'pDescriptorSets' == p.name and proto.params[-1].name == 'pCount':
471 sp_param_dict[pindex] = '*pCount'
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700472 elif 'Wsi' not in proto.name and xgl_helper.is_type(p.ty.strip('*').strip('const '), 'struct'):
Tobin Ehlisc7e926b2014-12-18 15:20:05 -0700473 sp_param_dict[pindex] = 'index'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600474 pindex += 1
Tobin Ehlisc7e926b2014-12-18 15:20:05 -0700475 if p.name.endswith('Count'):
Courtney Goeltzenleuchter08cf7cc2015-01-13 15:32:18 -0700476 if '*' in p.ty:
477 prev_count_name = "*%s" % p.name
478 else:
479 prev_count_name = p.name
Tobin Ehlisc7e926b2014-12-18 15:20:05 -0700480 else:
481 prev_count_name = ''
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600482 log_func = log_func.strip(', ')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600483 if proto.ret != "void":
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600484 log_func += ') = %s\\n"'
Courtney Goeltzenleuchtere6094fc2014-11-18 10:40:29 -0700485 print_vals += ', string_XGL_RESULT(result)'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600486 else:
487 log_func += ')\\n"'
488 log_func = '%s%s);' % (log_func, print_vals)
Tobin Ehlisc7e926b2014-12-18 15:20:05 -0700489 if len(sp_param_dict) > 0:
490 i_decl = False
491 log_func += '\n char *pTmpStr = "";'
492 for sp_index in sorted(sp_param_dict):
493 # TODO : Clean this if/else block up, too much duplicated code
494 if 'index' == sp_param_dict[sp_index]:
495 cis_print_func = 'xgl_print_%s' % (proto.params[sp_index].ty.strip('const ').strip('*').lower())
496 log_func += '\n if (%s) {' % (proto.params[sp_index].name)
497 log_func += '\n pTmpStr = %s(%s, " ");' % (cis_print_func, proto.params[sp_index].name)
498 if "File" in layer:
499 if no_addr:
500 log_func += '\n fprintf(pOutFile, " %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name)
501 else:
502 log_func += '\n fprintf(pOutFile, " %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name)
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -0700503 else:
Tobin Ehlisc7e926b2014-12-18 15:20:05 -0700504 if no_addr:
505 log_func += '\n printf(" %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name)
506 else:
507 log_func += '\n printf(" %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name)
508 log_func += '\n fflush(stdout);'
509 log_func += '\n free(pTmpStr);\n }'
510 else: # should have a count value stored to iterate over array
511 if xgl_helper.is_type(proto.params[sp_index].ty.strip('*').strip('const '), 'struct'):
512 cis_print_func = 'pTmpStr = xgl_print_%s(&%s[i], " ");' % (proto.params[sp_index].ty.strip('const ').strip('*').lower(), proto.params[sp_index].name)
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -0700513 else:
Mike Stroyan491c23a2015-03-03 16:54:24 -0700514 cis_print_func = 'pTmpStr = (char*)malloc(32);\n sprintf(pTmpStr, " %%p", %s[i]);' % proto.params[sp_index].name
Tobin Ehlisc7e926b2014-12-18 15:20:05 -0700515 if not i_decl:
516 log_func += '\n uint32_t i;'
517 i_decl = True
Jon Ashburn48637592015-01-14 08:52:37 -0700518 log_func += '\n for (i = 0; i < %s; i++) {' % (sp_param_dict[sp_index])
Tobin Ehlisc7e926b2014-12-18 15:20:05 -0700519 log_func += '\n %s' % (cis_print_func)
520 if "File" in layer:
521 if no_addr:
522 log_func += '\n fprintf(pOutFile, " %s[%%i] (addr)\\n%%s\\n", i, pTmpStr);' % (proto.params[sp_index].name)
523 else:
524 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)
525 else:
526 if no_addr:
527 log_func += '\n printf(" %s[%%i] (addr)\\n%%s\\n", i, pTmpStr);' % (proto.params[sp_index].name)
528 else:
529 log_func += '\n printf(" %s[%%i] (%%p)\\n%%s\\n", i, (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name)
530 log_func += '\n fflush(stdout);'
531 log_func += '\n free(pTmpStr);\n }'
Ian Elliott81ac44c2015-01-13 17:52:38 -0700532 if 'WsiX11AssociateConnection' == proto.name:
Ian Elliotte977a6c2015-02-26 14:34:52 -0700533 funcs.append("#if defined(__linux__) || defined(XCB_NVIDIA)")
Jon Ashburn451c16f2014-11-25 11:08:42 -0700534 if proto.name == "EnumerateLayers":
535 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
536 funcs.append('%s%s\n'
537 '{\n'
538 ' if (gpu != NULL) {\n'
539 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
540 ' pCurObj = gpuw;\n'
Jon Ashburn21001f62015-02-16 08:26:50 -0700541 ' loader_platform_thread_once(&tabOnce, init%s);\n'
Jon Ashburn451c16f2014-11-25 11:08:42 -0700542 ' %snextTable.%s;\n'
543 ' %s %s %s\n'
544 ' %s'
545 ' } else {\n'
546 ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n'
547 ' return XGL_ERROR_INVALID_POINTER;\n'
548 ' // This layer compatible with all GPUs\n'
549 ' *pOutLayerCount = 1;\n'
Chia-I Wua837c522014-12-16 10:47:33 +0800550 ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n'
Jon Ashburn451c16f2014-11-25 11:08:42 -0700551 ' return XGL_SUCCESS;\n'
552 ' }\n'
Jon Ashburn21001f62015-02-16 08:26:50 -0700553 '}' % (qual, decl, proto.params[0].name, layer_name, ret_val, c_call,f_open, log_func, f_close, stmt, layer_name))
Jon Ashburn451c16f2014-11-25 11:08:42 -0700554 elif proto.params[0].ty != "XGL_PHYSICAL_GPU":
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600555 funcs.append('%s%s\n'
556 '{\n'
557 ' %snextTable.%s;\n'
Tobin Ehlis574b0142014-11-12 13:11:15 -0700558 ' %s%s%s\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600559 '%s'
Tobin Ehlis574b0142014-11-12 13:11:15 -0700560 '}' % (qual, decl, ret_val, proto.c_call(), f_open, log_func, f_close, stmt))
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600561 else:
562 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
563 funcs.append('%s%s\n'
564 '{\n'
565 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
566 ' pCurObj = gpuw;\n'
Jon Ashburn21001f62015-02-16 08:26:50 -0700567 ' loader_platform_thread_once(&tabOnce, init%s);\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600568 ' %snextTable.%s;\n'
Tobin Ehlis574b0142014-11-12 13:11:15 -0700569 ' %s%s%s\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600570 '%s'
Jon Ashburn21001f62015-02-16 08:26:50 -0700571 '}' % (qual, decl, proto.params[0].name, layer_name, ret_val, c_call, f_open, log_func, f_close, stmt))
Ian Elliott81ac44c2015-01-13 17:52:38 -0700572 if 'WsiX11QueuePresent' == proto.name:
573 funcs.append("#endif")
Tobin Ehlis907a0522014-11-25 16:59:27 -0700574 elif "ObjectTracker" == layer:
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700575 obj_type_mapping = {base_t : base_t.replace("XGL_", "XGL_OBJECT_TYPE_") for base_t in xgl.object_type_list}
576 # For the various "super-types" we have to use function to distinguish sub type
577 for obj_type in ["XGL_BASE_OBJECT", "XGL_OBJECT", "XGL_DYNAMIC_STATE_OBJECT"]:
578 obj_type_mapping[obj_type] = "ll_get_obj_type(object)"
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700579
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600580 decl = proto.c_func(prefix="xgl", attr="XGLAPI")
581 param0_name = proto.params[0].name
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700582 p0_type = proto.params[0].ty.strip('*').strip('const ')
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600583 create_line = ''
584 destroy_line = ''
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700585 if 'DbgRegisterMsgCallback' in proto.name:
586 using_line = ' // This layer intercepts callbacks\n'
587 using_line += ' XGL_LAYER_DBG_FUNCTION_NODE *pNewDbgFuncNode = (XGL_LAYER_DBG_FUNCTION_NODE*)malloc(sizeof(XGL_LAYER_DBG_FUNCTION_NODE));\n'
588 using_line += ' if (!pNewDbgFuncNode)\n'
589 using_line += ' return XGL_ERROR_OUT_OF_MEMORY;\n'
590 using_line += ' pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;\n'
591 using_line += ' pNewDbgFuncNode->pUserData = pUserData;\n'
Jon Ashburn21001f62015-02-16 08:26:50 -0700592 using_line += ' pNewDbgFuncNode->pNext = g_pDbgFunctionHead;\n'
593 using_line += ' g_pDbgFunctionHead = pNewDbgFuncNode;\n'
Jon Ashburne4722392015-03-03 15:07:15 -0700594 using_line += ' // force callbacks if DebugAction hasn\'t been set already other than initial value\n'
Ian Elliottc9473d92015-03-05 12:28:53 -0700595 using_line += ' if (g_actionIsDefault) {\n'
Jon Ashburne4722392015-03-03 15:07:15 -0700596 using_line += ' g_debugAction = XGL_DBG_LAYER_ACTION_CALLBACK;\n'
Ian Elliottc9473d92015-03-05 12:28:53 -0700597 using_line += ' }'
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700598 elif 'DbgUnregisterMsgCallback' in proto.name:
Jon Ashburn21001f62015-02-16 08:26:50 -0700599 using_line = ' XGL_LAYER_DBG_FUNCTION_NODE *pTrav = g_pDbgFunctionHead;\n'
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700600 using_line += ' XGL_LAYER_DBG_FUNCTION_NODE *pPrev = pTrav;\n'
601 using_line += ' while (pTrav) {\n'
602 using_line += ' if (pTrav->pfnMsgCallback == pfnMsgCallback) {\n'
603 using_line += ' pPrev->pNext = pTrav->pNext;\n'
Jon Ashburn21001f62015-02-16 08:26:50 -0700604 using_line += ' if (g_pDbgFunctionHead == pTrav)\n'
605 using_line += ' g_pDbgFunctionHead = pTrav->pNext;\n'
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700606 using_line += ' free(pTrav);\n'
607 using_line += ' break;\n'
608 using_line += ' }\n'
609 using_line += ' pPrev = pTrav;\n'
610 using_line += ' pTrav = pTrav->pNext;\n'
611 using_line += ' }\n'
Jon Ashburne4722392015-03-03 15:07:15 -0700612 using_line += ' if (g_pDbgFunctionHead == NULL)\n'
613 using_line += ' {\n'
614 using_line += ' if (g_actionIsDefault)\n'
615 using_line += ' g_debugAction = XGL_DBG_LAYER_ACTION_LOG_MSG;\n'
616 using_line += ' else\n'
617 using_line += ' g_debugAction &= ~XGL_DBG_LAYER_ACTION_CALLBACK;\n'
618 using_line += ' }\n'
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700619 # Special cases for API funcs that don't use an object as first arg
Courtney Goeltzenleuchterd3ebab42015-03-04 11:21:23 -0700620 elif True in [no_use_proto in proto.name for no_use_proto in ['GlobalOption', 'CreateInstance', 'QueueSubmit', 'QueueSetGlobalMemReferences', 'QueueWaitIdle', 'CreateDevice', 'GetGpuInfo', 'SignalQueueSemaphore', 'WaitQueueSemaphore', 'WsiX11QueuePresent']]:
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600621 using_line = ''
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700622 else:
Tobin Ehlis84a8a9b2015-02-23 14:09:16 -0700623 using_line = ' loader_platform_thread_lock_mutex(&objLock);\n'
624 using_line += ' ll_increment_use_count((void*)%s, %s);\n' % (param0_name, obj_type_mapping[p0_type])
625 using_line += ' loader_platform_thread_unlock_mutex(&objLock);\n'
Tobin Ehlis235c20e2015-01-16 08:56:30 -0700626 if 'QueueSubmit' in proto.name:
627 using_line += ' set_status((void*)fence, XGL_OBJECT_TYPE_FENCE, OBJSTATUS_FENCE_IS_SUBMITTED);\n'
Mark Lobodzinski4186e712015-02-03 11:52:26 -0600628 using_line += ' validate_memory_mapping_status(pMemRefs, memRefCount);\n'
Mark Lobodzinskie1d3f0c2015-02-09 10:20:53 -0600629 using_line += ' validate_mem_ref_count(memRefCount);\n'
Tobin Ehlis235c20e2015-01-16 08:56:30 -0700630 elif 'GetFenceStatus' in proto.name:
631 using_line += ' // Warn if submitted_flag is not set\n'
Mark Lobodzinski4186e712015-02-03 11:52:26 -0600632 using_line += ' validate_status((void*)fence, XGL_OBJECT_TYPE_FENCE, OBJSTATUS_FENCE_IS_SUBMITTED, OBJSTATUS_FENCE_IS_SUBMITTED, XGL_DBG_MSG_ERROR, OBJTRACK_INVALID_FENCE, "Status Requested for Unsubmitted Fence");\n'
Mark Lobodzinski01552702015-02-03 10:06:31 -0600633 elif 'EndCommandBuffer' in proto.name:
634 using_line += ' reset_status((void*)cmdBuffer, XGL_OBJECT_TYPE_CMD_BUFFER, (OBJSTATUS_VIEWPORT_BOUND |\n'
635 using_line += ' OBJSTATUS_RASTER_BOUND |\n'
636 using_line += ' OBJSTATUS_COLOR_BLEND_BOUND |\n'
637 using_line += ' OBJSTATUS_DEPTH_STENCIL_BOUND));\n'
638 elif 'CmdBindDynamicStateObject' in proto.name:
639 using_line += ' track_object_status((void*)cmdBuffer, stateBindPoint);\n'
640 elif 'CmdDraw' in proto.name:
641 using_line += ' validate_draw_state_flags((void *)cmdBuffer);\n'
Mark Lobodzinski4186e712015-02-03 11:52:26 -0600642 elif 'MapMemory' in proto.name:
643 using_line += ' set_status((void*)mem, XGL_OBJECT_TYPE_GPU_MEMORY, OBJSTATUS_GPU_MEM_MAPPED);\n'
644 elif 'UnmapMemory' in proto.name:
645 using_line += ' reset_status((void*)mem, XGL_OBJECT_TYPE_GPU_MEMORY, OBJSTATUS_GPU_MEM_MAPPED);\n'
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700646 if 'AllocDescriptor' in proto.name: # Allocates array of DSs
Ian Elliotteac469b2015-02-04 12:15:12 -0700647 create_line = ' for (uint32_t i = 0; i < *pCount; i++) {\n'
Tobin Ehlis84a8a9b2015-02-23 14:09:16 -0700648 create_line += ' loader_platform_thread_lock_mutex(&objLock);\n'
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700649 create_line += ' ll_insert_obj((void*)pDescriptorSets[i], XGL_OBJECT_TYPE_DESCRIPTOR_SET);\n'
Tobin Ehlis84a8a9b2015-02-23 14:09:16 -0700650 create_line += ' loader_platform_thread_unlock_mutex(&objLock);\n'
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700651 create_line += ' }\n'
Courtney Goeltzenleuchtere9ec87b2015-02-25 16:58:34 -0700652 elif 'CreatePresentableImage' in proto.name:
653 create_line = ' loader_platform_thread_lock_mutex(&objLock);\n'
654 create_line += ' ll_insert_obj((void*)*%s, %s);\n' % (proto.params[-2].name, obj_type_mapping[proto.params[-2].ty.strip('*').strip('const ')])
Mark Lobodzinskiacb93682015-03-05 12:39:33 -0600655 create_line += ' ll_insert_obj((void*)*pMem, XGL_OBJECT_TYPE_PRESENTABLE_IMAGE_MEMORY);\n'
656 # create_line += ' ll_insert_obj((void*)*%s, XGL_OBJECT_TYPE_PRESENTABLE_IMAGE_MEMORY);\n' % (obj_type_mapping[proto.params[-1].ty.strip('*').strip('const ')])
Courtney Goeltzenleuchtere9ec87b2015-02-25 16:58:34 -0700657 create_line += ' loader_platform_thread_unlock_mutex(&objLock);\n'
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700658 elif 'Create' in proto.name or 'Alloc' in proto.name:
Tobin Ehlis84a8a9b2015-02-23 14:09:16 -0700659 create_line = ' loader_platform_thread_lock_mutex(&objLock);\n'
660 create_line += ' ll_insert_obj((void*)*%s, %s);\n' % (proto.params[-1].name, obj_type_mapping[proto.params[-1].ty.strip('*').strip('const ')])
661 create_line += ' loader_platform_thread_unlock_mutex(&objLock);\n'
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700662 if 'DestroyObject' in proto.name:
Tobin Ehlis84a8a9b2015-02-23 14:09:16 -0700663 destroy_line = ' loader_platform_thread_lock_mutex(&objLock);\n'
664 destroy_line += ' ll_destroy_obj((void*)%s);\n' % (param0_name)
665 destroy_line += ' loader_platform_thread_unlock_mutex(&objLock);\n'
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700666 using_line = ''
667 else:
668 if 'Destroy' in proto.name or 'Free' in proto.name:
Tobin Ehlis84a8a9b2015-02-23 14:09:16 -0700669 destroy_line = ' loader_platform_thread_lock_mutex(&objLock);\n'
Mark Lobodzinski5121e2c2015-02-24 16:20:24 -0600670 destroy_line += ' ll_destroy_obj((void*)%s);\n' % (param0_name)
Tobin Ehlis84a8a9b2015-02-23 14:09:16 -0700671 destroy_line += ' loader_platform_thread_unlock_mutex(&objLock);\n'
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700672 using_line = ''
673 if 'DestroyDevice' in proto.name:
674 destroy_line += ' // Report any remaining objects in LL\n objNode *pTrav = pGlobalHead;\n while (pTrav) {\n'
Mark Lobodzinskiacb93682015-03-05 12:39:33 -0600675 destroy_line += ' if (pTrav->obj.objType == XGL_OBJECT_TYPE_PRESENTABLE_IMAGE_MEMORY) {\n'
676 destroy_line += ' objNode *pDel = pTrav;\n'
677 destroy_line += ' pTrav = pTrav->pNextGlobal;\n'
678 destroy_line += ' ll_destroy_obj((void*)(pDel->obj.pObj));\n'
679 destroy_line += ' } else {\n'
680 destroy_line += ' char str[1024];\n'
681 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'
682 destroy_line += ' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, device, 0, OBJTRACK_OBJECT_LEAK, "OBJTRACK", str);\n'
683 destroy_line += ' pTrav = pTrav->pNextGlobal;\n'
684 destroy_line += ' }\n'
685 destroy_line += ' }\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600686 ret_val = ''
687 stmt = ''
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600688 if proto.ret != "void":
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600689 ret_val = "XGL_RESULT result = "
690 stmt = " return result;\n"
Ian Elliott81ac44c2015-01-13 17:52:38 -0700691 if 'WsiX11AssociateConnection' == proto.name:
Ian Elliotte977a6c2015-02-26 14:34:52 -0700692 funcs.append("#if defined(__linux__) || defined(XCB_NVIDIA)")
Jon Ashburn451c16f2014-11-25 11:08:42 -0700693 if proto.name == "EnumerateLayers":
694 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
695 funcs.append('%s%s\n'
696 '{\n'
697 ' if (gpu != NULL) {\n'
698 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
699 ' %s'
700 ' pCurObj = gpuw;\n'
Jon Ashburn21001f62015-02-16 08:26:50 -0700701 ' loader_platform_thread_once(&tabOnce, init%s);\n'
Jon Ashburn451c16f2014-11-25 11:08:42 -0700702 ' %snextTable.%s;\n'
703 ' %s%s'
704 ' %s'
705 ' } else {\n'
706 ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n'
707 ' return XGL_ERROR_INVALID_POINTER;\n'
708 ' // This layer compatible with all GPUs\n'
709 ' *pOutLayerCount = 1;\n'
Chia-I Wua837c522014-12-16 10:47:33 +0800710 ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n'
Jon Ashburn451c16f2014-11-25 11:08:42 -0700711 ' return XGL_SUCCESS;\n'
712 ' }\n'
Jon Ashburn21001f62015-02-16 08:26:50 -0700713 '}' % (qual, decl, proto.params[0].name, using_line, layer_name, ret_val, c_call, create_line, destroy_line, stmt, layer_name))
Jon Ashburn451c16f2014-11-25 11:08:42 -0700714 elif proto.params[0].ty != "XGL_PHYSICAL_GPU":
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600715 funcs.append('%s%s\n'
716 '{\n'
717 '%s'
718 ' %snextTable.%s;\n'
719 '%s%s'
720 '%s'
721 '}' % (qual, decl, using_line, ret_val, proto.c_call(), create_line, destroy_line, stmt))
722 else:
723 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
Mark Lobodzinskie1d3f0c2015-02-09 10:20:53 -0600724 gpu_state = ''
725 if 'GetGpuInfo' in proto.name:
726 gpu_state = ' if (infoType == XGL_INFO_TYPE_PHYSICAL_GPU_PROPERTIES) {\n'
727 gpu_state += ' if (pData != NULL) {\n'
728 gpu_state += ' setGpuInfoState(pData);\n'
729 gpu_state += ' }\n'
730 gpu_state += ' }\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600731 funcs.append('%s%s\n'
732 '{\n'
733 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
734 '%s'
735 ' pCurObj = gpuw;\n'
Jon Ashburn21001f62015-02-16 08:26:50 -0700736 ' loader_platform_thread_once(&tabOnce, init%s);\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600737 ' %snextTable.%s;\n'
738 '%s%s'
739 '%s'
Mark Lobodzinskie1d3f0c2015-02-09 10:20:53 -0600740 '%s'
Jon Ashburn21001f62015-02-16 08:26:50 -0700741 '}' % (qual, decl, proto.params[0].name, using_line, layer_name, ret_val, c_call, create_line, destroy_line, gpu_state, stmt))
Ian Elliott81ac44c2015-01-13 17:52:38 -0700742 if 'WsiX11QueuePresent' == proto.name:
743 funcs.append("#endif")
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700744 elif "ParamChecker" == layer:
745 # TODO : Need to fix up the non-else cases below to do param checking as well
746 decl = proto.c_func(prefix="xgl", attr="XGLAPI")
747 param0_name = proto.params[0].name
748 ret_val = ''
749 stmt = ''
750 param_checks = []
751 # Add code to check enums and structs
752 # TODO : Currently only validating enum values, need to validate everything
753 str_decl = False
Tobin Ehlis773371f2014-12-18 13:51:21 -0700754 prev_count_name = ''
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700755 for p in proto.params:
756 if xgl_helper.is_type(p.ty.strip('*').strip('const '), 'enum'):
757 if not str_decl:
758 param_checks.append(' char str[1024];')
759 str_decl = True
760 param_checks.append(' if (!validate_%s(%s)) {' % (p.ty, p.name))
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700761 param_checks.append(' sprintf(str, "Parameter %s to function %s has invalid value of %%i.", (int)%s);' % (p.name, proto.name, p.name))
762 param_checks.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, 1, "PARAMCHECK", str);')
763 param_checks.append(' }')
764 elif xgl_helper.is_type(p.ty.strip('*').strip('const '), 'struct') and 'const' in p.ty:
Tobin Ehlis773371f2014-12-18 13:51:21 -0700765 is_array = False
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700766 if not str_decl:
767 param_checks.append(' char str[1024];')
768 str_decl = True
769 if '*' in p.ty: # First check for null ptr
Tobin Ehlis773371f2014-12-18 13:51:21 -0700770 # If this is an input array, parse over all of the array elements
771 if prev_count_name != '' and (prev_count_name.strip('Count')[1:] in p.name or 'slotCount' == prev_count_name):
772 #if 'pImageViews' in p.name:
773 is_array = True
774 param_checks.append(' uint32_t i;')
775 param_checks.append(' for (i = 0; i < %s; i++) {' % prev_count_name)
776 param_checks.append(' if (!xgl_validate_%s(&%s[i])) {' % (p.ty.strip('*').strip('const ').lower(), p.name))
777 param_checks.append(' sprintf(str, "Parameter %s[%%i] to function %s contains an invalid value.", i);' % (p.name, proto.name))
778 param_checks.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, 1, "PARAMCHECK", str);')
779 param_checks.append(' }')
780 param_checks.append(' }')
781 else:
782 param_checks.append(' if (!%s) {' % p.name)
783 param_checks.append(' sprintf(str, "Struct ptr parameter %s to function %s is NULL.");' % (p.name, proto.name))
784 param_checks.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, NULL, 0, 1, "PARAMCHECK", str);')
785 param_checks.append(' }')
786 param_checks.append(' else if (!xgl_validate_%s(%s)) {' % (p.ty.strip('*').strip('const ').lower(), p.name))
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700787 else:
788 param_checks.append(' if (!xgl_validate_%s(%s)) {' % (p.ty.strip('const ').lower(), p.name))
Tobin Ehlis773371f2014-12-18 13:51:21 -0700789 if not is_array:
790 param_checks.append(' sprintf(str, "Parameter %s to function %s contains an invalid value.");' % (p.name, proto.name))
791 param_checks.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, 1, "PARAMCHECK", str);')
792 param_checks.append(' }')
793 if p.name.endswith('Count'):
794 prev_count_name = p.name
795 else:
796 prev_count_name = ''
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600797 if proto.ret != "void":
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700798 ret_val = "XGL_RESULT result = "
799 stmt = " return result;\n"
Ian Elliott81ac44c2015-01-13 17:52:38 -0700800 if 'WsiX11AssociateConnection' == proto.name:
Ian Elliotte977a6c2015-02-26 14:34:52 -0700801 funcs.append("#if defined(__linux__) || defined(XCB_NVIDIA)")
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700802 if proto.name == "EnumerateLayers":
803 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
804 funcs.append('%s%s\n'
805 '{\n'
806 ' char str[1024];\n'
807 ' if (gpu != NULL) {\n'
808 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
809 ' sprintf(str, "At start of layered %s\\n");\n'
810 ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpu, 0, 0, "PARAMCHECK", str);\n'
811 ' pCurObj = gpuw;\n'
Jon Ashburn21001f62015-02-16 08:26:50 -0700812 ' loader_platform_thread_once(&tabOnce, init%s);\n'
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700813 ' %snextTable.%s;\n'
814 ' sprintf(str, "Completed layered %s\\n");\n'
815 ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpu, 0, 0, "PARAMCHECK", str);\n'
816 ' fflush(stdout);\n'
817 ' %s'
818 ' } else {\n'
819 ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n'
820 ' return XGL_ERROR_INVALID_POINTER;\n'
821 ' // This layer compatible with all GPUs\n'
822 ' *pOutLayerCount = 1;\n'
823 ' strncpy(pOutLayers[0], "%s", maxStringSize);\n'
824 ' return XGL_SUCCESS;\n'
825 ' }\n'
Jon Ashburn21001f62015-02-16 08:26:50 -0700826 '}' % (qual, decl, proto.params[0].name, proto.name, layer_name, ret_val, c_call, proto.name, stmt, layer_name))
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700827 elif 'DbgRegisterMsgCallback' == proto.name:
828 funcs.append(self._gen_layer_dbg_callback_register())
829 elif 'DbgUnregisterMsgCallback' == proto.name:
830 funcs.append(self._gen_layer_dbg_callback_unregister())
831 elif proto.params[0].ty != "XGL_PHYSICAL_GPU":
832 funcs.append('%s%s\n'
833 '{\n'
834 '%s\n'
835 ' %snextTable.%s;\n'
836 '%s'
837 '}' % (qual, decl, "\n".join(param_checks), ret_val, proto.c_call(), stmt))
838 else:
839 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
840 funcs.append('%s%s\n'
841 '{\n'
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700842 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700843 ' pCurObj = gpuw;\n'
Jon Ashburn21001f62015-02-16 08:26:50 -0700844 ' loader_platform_thread_once(&tabOnce, init%s);\n'
Tobin Ehlis9d139862014-12-18 08:44:01 -0700845 '%s\n'
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700846 ' %snextTable.%s;\n'
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700847 '%s'
Jon Ashburn21001f62015-02-16 08:26:50 -0700848 '}' % (qual, decl, proto.params[0].name, layer_name, "\n".join(param_checks), ret_val, c_call, stmt))
Ian Elliott81ac44c2015-01-13 17:52:38 -0700849 if 'WsiX11QueuePresent' == proto.name:
850 funcs.append("#endif")
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600851
852 return "\n\n".join(funcs)
853
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700854 def _generate_extensions(self):
855 exts = []
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600856 exts.append('uint64_t objTrackGetObjectCount(XGL_OBJECT_TYPE type)')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700857 exts.append('{')
858 exts.append(' return (type == XGL_OBJECT_TYPE_ANY) ? numTotalObjs : numObjs[type];')
859 exts.append('}')
860 exts.append('')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600861 exts.append('XGL_RESULT objTrackGetObjects(XGL_OBJECT_TYPE type, uint64_t objCount, OBJTRACK_NODE* pObjNodeArray)')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700862 exts.append('{')
863 exts.append(" // This bool flags if we're pulling all objs or just a single class of objs")
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600864 exts.append(' bool32_t bAllObjs = (type == XGL_OBJECT_TYPE_ANY);')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700865 exts.append(' // Check the count first thing')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600866 exts.append(' uint64_t maxObjCount = (bAllObjs) ? numTotalObjs : numObjs[type];')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700867 exts.append(' if (objCount > maxObjCount) {')
868 exts.append(' char str[1024];')
869 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));')
870 exts.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, 0, 0, OBJTRACK_OBJCOUNT_MAX_EXCEEDED, "OBJTRACK", str);')
871 exts.append(' return XGL_ERROR_INVALID_VALUE;')
872 exts.append(' }')
873 exts.append(' objNode* pTrav = (bAllObjs) ? pGlobalHead : pObjectHead[type];')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600874 exts.append(' for (uint64_t i = 0; i < objCount; i++) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700875 exts.append(' if (!pTrav) {')
876 exts.append(' char str[1024];')
877 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);')
878 exts.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, 0, 0, OBJTRACK_INTERNAL_ERROR, "OBJTRACK", str);')
879 exts.append(' return XGL_ERROR_UNKNOWN;')
880 exts.append(' }')
881 exts.append(' memcpy(&pObjNodeArray[i], pTrav, sizeof(OBJTRACK_NODE));')
882 exts.append(' pTrav = (bAllObjs) ? pTrav->pNextGlobal : pTrav->pNextObj;')
883 exts.append(' }')
884 exts.append(' return XGL_SUCCESS;')
885 exts.append('}')
886
887 return "\n".join(exts)
888
Jon Ashburn21001f62015-02-16 08:26:50 -0700889 def _generate_layer_gpa_function(self, layer, extensions=[]):
Chia-I Wu706533e2015-01-05 13:18:57 +0800890 func_body = ["#include \"xgl_generic_intercept_proc_helper.h\""]
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600891 func_body.append("XGL_LAYER_EXPORT void* XGLAPI xglGetProcAddr(XGL_PHYSICAL_GPU gpu, const char* funcName)\n"
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600892 "{\n"
893 " XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) gpu;\n"
Chia-I Wu706533e2015-01-05 13:18:57 +0800894 " void* addr;\n"
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600895 " if (gpu == NULL)\n"
896 " return NULL;\n"
897 " pCurObj = gpuw;\n"
Jon Ashburn21001f62015-02-16 08:26:50 -0700898 " loader_platform_thread_once(&tabOnce, init%s);\n\n"
Chia-I Wu706533e2015-01-05 13:18:57 +0800899 " addr = layer_intercept_proc(funcName);\n"
900 " if (addr)\n"
Jon Ashburn21001f62015-02-16 08:26:50 -0700901 " return addr;" % layer)
Chia-I Wu706533e2015-01-05 13:18:57 +0800902
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700903 if 0 != len(extensions):
904 for ext_name in extensions:
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800905 func_body.append(' else if (!strncmp("%s", funcName, sizeof("%s")))\n'
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700906 ' return %s;' % (ext_name, ext_name, ext_name))
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600907 func_body.append(" else {\n"
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600908 " if (gpuw->pGPA == NULL)\n"
909 " return NULL;\n"
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700910 " return gpuw->pGPA((XGL_PHYSICAL_GPU)gpuw->nextObject, funcName);\n"
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600911 " }\n"
912 "}\n")
913 return "\n".join(func_body)
914
Tobin Ehlis84a8a9b2015-02-23 14:09:16 -0700915 def _generate_layer_initialization(self, name, init_opts=False, prefix='xgl', lockname=None):
Chia-I Wu0f65b1e2015-01-04 23:11:43 +0800916 func_body = ["#include \"xgl_dispatch_table_helper.h\""]
Jon Ashburn21001f62015-02-16 08:26:50 -0700917 func_body.append('static void init%s(void)\n'
918 '{\n' % name)
919 if init_opts:
920 func_body.append(' const char *strOpt;')
921 func_body.append(' // initialize %s options' % name)
Ian Elliott7d0b5d22015-03-06 13:50:05 -0700922 func_body.append(' getLayerOptionEnum("%sReportLevel", (uint32_t *) &g_reportingLevel);' % name)
923 func_body.append(' g_actionIsDefault = getLayerOptionEnum("%sDebugAction", (uint32_t *) &g_debugAction);' % name)
Jon Ashburn21001f62015-02-16 08:26:50 -0700924 func_body.append('')
925 func_body.append(' if (g_debugAction & XGL_DBG_LAYER_ACTION_LOG_MSG)')
926 func_body.append(' {')
927 func_body.append(' strOpt = getLayerOption("%sLogFilename");' % name)
928 func_body.append(' if (strOpt)')
929 func_body.append(' {')
930 func_body.append(' g_logFile = fopen(strOpt, "w");')
931 func_body.append(' }')
932 func_body.append(' if (g_logFile == NULL)')
933 func_body.append(' g_logFile = stdout;')
934 func_body.append(' }')
935 func_body.append('')
936 func_body.append(' xglGetProcAddrType fpNextGPA;\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600937 ' fpNextGPA = pCurObj->pGPA;\n'
Jon Ashburn21001f62015-02-16 08:26:50 -0700938 ' assert(fpNextGPA);\n')
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600939
Chia-I Wu0f65b1e2015-01-04 23:11:43 +0800940 func_body.append(" layer_initialize_dispatch_table(&nextTable, fpNextGPA, (XGL_PHYSICAL_GPU) pCurObj->nextObject);")
Tobin Ehlis84a8a9b2015-02-23 14:09:16 -0700941 if lockname is not None:
942 func_body.append(" if (!%sLockInitialized)" % lockname)
943 func_body.append(" {")
944 func_body.append(" // TODO/TBD: Need to delete this mutex sometime. How???")
945 func_body.append(" loader_platform_thread_create_mutex(&%sLock);" % lockname)
946 func_body.append(" %sLockInitialized = 1;" % lockname)
947 func_body.append(" }")
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600948 func_body.append("}\n")
949 return "\n".join(func_body)
950
Jon Ashburn21001f62015-02-16 08:26:50 -0700951 def _generate_layer_initialization_with_lock(self, layer, prefix='xgl'):
Ian Elliott81ac44c2015-01-13 17:52:38 -0700952 func_body = ["#include \"xgl_dispatch_table_helper.h\""]
Jon Ashburn21001f62015-02-16 08:26:50 -0700953 func_body.append('static void init%s(void)\n'
Ian Elliott81ac44c2015-01-13 17:52:38 -0700954 '{\n'
955 ' xglGetProcAddrType fpNextGPA;\n'
956 ' fpNextGPA = pCurObj->pGPA;\n'
Jon Ashburn21001f62015-02-16 08:26:50 -0700957 ' assert(fpNextGPA);\n' % layer);
Ian Elliott81ac44c2015-01-13 17:52:38 -0700958
959 func_body.append(" layer_initialize_dispatch_table(&nextTable, fpNextGPA, (XGL_PHYSICAL_GPU) pCurObj->nextObject);\n")
960 func_body.append(" if (!printLockInitialized)")
961 func_body.append(" {")
962 func_body.append(" // TODO/TBD: Need to delete this mutex sometime. How???")
963 func_body.append(" loader_platform_thread_create_mutex(&printLock);")
964 func_body.append(" printLockInitialized = 1;")
965 func_body.append(" }")
966 func_body.append("}\n")
967 return "\n".join(func_body)
968
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600969class LayerFuncsSubcommand(Subcommand):
970 def generate_header(self):
971 return '#include <xglLayer.h>\n#include "loader.h"'
972
973 def generate_body(self):
974 return self._generate_dispatch_entrypoints("static", True)
975
976class LayerDispatchSubcommand(Subcommand):
977 def generate_header(self):
978 return '#include "layer_wrappers.h"'
979
980 def generate_body(self):
Jon Ashburn21001f62015-02-16 08:26:50 -0700981 return self._generate_layer_initialization()
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600982
983class GenericLayerSubcommand(Subcommand):
984 def generate_header(self):
Jon Ashburn7a2da4f2015-02-17 11:03:12 -0700985 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 Ehlis92dbf802014-10-22 09:06:33 -0600986
987 def generate_body(self):
Jon Ashburn21001f62015-02-16 08:26:50 -0700988 body = [self._generate_layer_initialization("Generic", True),
Tobin Ehlis907a0522014-11-25 16:59:27 -0700989 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "Generic"),
Jon Ashburn21001f62015-02-16 08:26:50 -0700990 self._generate_layer_gpa_function("Generic")]
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600991
992 return "\n\n".join(body)
993
994class ApiDumpSubcommand(Subcommand):
995 def generate_header(self):
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700996 header_txt = []
Ian Elliott81ac44c2015-01-13 17:52:38 -0700997 header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>')
998 header_txt.append('#include "loader_platform.h"')
999 header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper.h"\n')
Ian Elliott20f06872015-02-12 17:08:34 -07001000 header_txt.append('// The following is #included again to catch certain OS-specific functions being used:')
1001 header_txt.append('#include "loader_platform.h"')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001002 header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;')
1003 header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n')
1004 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
1005 header_txt.append('static int printLockInitialized = 0;')
1006 header_txt.append('static loader_platform_thread_mutex printLock;\n')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -07001007 header_txt.append('#define MAX_TID 513')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001008 header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -07001009 header_txt.append('static uint32_t maxTID = 0;')
1010 header_txt.append('// Map actual TID to an index value and return that index')
1011 header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs')
1012 header_txt.append('static uint32_t getTIDIndex() {')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001013 header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -07001014 header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {')
1015 header_txt.append(' if (tid == tidMapping[i])')
1016 header_txt.append(' return i;')
1017 header_txt.append(' }')
1018 header_txt.append(" // Don't yet have mapping, set it and return newly set index")
Ian Elliott81ac44c2015-01-13 17:52:38 -07001019 header_txt.append(' uint32_t retVal = (uint32_t) maxTID;')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -07001020 header_txt.append(' tidMapping[maxTID++] = tid;')
1021 header_txt.append(' assert(maxTID < MAX_TID);')
1022 header_txt.append(' return retVal;')
1023 header_txt.append('}')
1024 return "\n".join(header_txt)
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001025
1026 def generate_body(self):
Jon Ashburn21001f62015-02-16 08:26:50 -07001027 body = [self._generate_layer_initialization_with_lock("APIDump"),
Tobin Ehlis907a0522014-11-25 16:59:27 -07001028 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDump"),
Jon Ashburn21001f62015-02-16 08:26:50 -07001029 self._generate_layer_gpa_function("APIDump")]
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001030
1031 return "\n\n".join(body)
1032
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001033class ApiDumpCppSubcommand(Subcommand):
1034 def generate_header(self):
1035 header_txt = []
Ian Elliott81ac44c2015-01-13 17:52:38 -07001036 header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>')
1037 header_txt.append('#include "loader_platform.h"')
1038 header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper_cpp.h"\n')
Ian Elliott20f06872015-02-12 17:08:34 -07001039 header_txt.append('// The following is #included again to catch certain OS-specific functions being used:')
1040 header_txt.append('#include "loader_platform.h"')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001041 header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;')
1042 header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n')
1043 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
1044 header_txt.append('static int printLockInitialized = 0;')
1045 header_txt.append('static loader_platform_thread_mutex printLock;\n')
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001046 header_txt.append('#define MAX_TID 513')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001047 header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};')
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001048 header_txt.append('static uint32_t maxTID = 0;')
1049 header_txt.append('// Map actual TID to an index value and return that index')
1050 header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs')
1051 header_txt.append('static uint32_t getTIDIndex() {')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001052 header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();')
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001053 header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {')
1054 header_txt.append(' if (tid == tidMapping[i])')
1055 header_txt.append(' return i;')
1056 header_txt.append(' }')
1057 header_txt.append(" // Don't yet have mapping, set it and return newly set index")
Ian Elliott81ac44c2015-01-13 17:52:38 -07001058 header_txt.append(' uint32_t retVal = (uint32_t) maxTID;')
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001059 header_txt.append(' tidMapping[maxTID++] = tid;')
1060 header_txt.append(' assert(maxTID < MAX_TID);')
1061 header_txt.append(' return retVal;')
1062 header_txt.append('}')
1063 return "\n".join(header_txt)
1064
1065 def generate_body(self):
Jon Ashburn21001f62015-02-16 08:26:50 -07001066 body = [self._generate_layer_initialization_with_lock("APIDumpCpp"),
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001067 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDumpCpp"),
Jon Ashburn21001f62015-02-16 08:26:50 -07001068 self._generate_layer_gpa_function("APIDumpCpp")]
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001069
1070 return "\n\n".join(body)
1071
Tobin Ehlis574b0142014-11-12 13:11:15 -07001072class ApiDumpFileSubcommand(Subcommand):
1073 def generate_header(self):
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -07001074 header_txt = []
Ian Elliott81ac44c2015-01-13 17:52:38 -07001075 header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>')
1076 header_txt.append('#include "loader_platform.h"')
1077 header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper.h"\n')
Ian Elliott20f06872015-02-12 17:08:34 -07001078 header_txt.append('// The following is #included again to catch certain OS-specific functions being used:')
1079 header_txt.append('#include "loader_platform.h"')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001080 header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;')
1081 header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n')
1082 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
1083 header_txt.append('static int printLockInitialized = 0;')
1084 header_txt.append('static loader_platform_thread_mutex printLock;\n')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -07001085 header_txt.append('#define MAX_TID 513')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001086 header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -07001087 header_txt.append('static uint32_t maxTID = 0;')
1088 header_txt.append('// Map actual TID to an index value and return that index')
1089 header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs')
1090 header_txt.append('static uint32_t getTIDIndex() {')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001091 header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -07001092 header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {')
1093 header_txt.append(' if (tid == tidMapping[i])')
1094 header_txt.append(' return i;')
1095 header_txt.append(' }')
1096 header_txt.append(" // Don't yet have mapping, set it and return newly set index")
Ian Elliott81ac44c2015-01-13 17:52:38 -07001097 header_txt.append(' uint32_t retVal = (uint32_t) maxTID;')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -07001098 header_txt.append(' tidMapping[maxTID++] = tid;')
1099 header_txt.append(' assert(maxTID < MAX_TID);')
1100 header_txt.append(' return retVal;')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001101 header_txt.append('}\n')
1102 header_txt.append('static FILE* pOutFile;\nstatic char* outFileName = "xgl_apidump.txt";')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -07001103 return "\n".join(header_txt)
Tobin Ehlis574b0142014-11-12 13:11:15 -07001104
1105 def generate_body(self):
Jon Ashburn21001f62015-02-16 08:26:50 -07001106 body = [self._generate_layer_initialization_with_lock("APIDumpFile"),
Tobin Ehlis907a0522014-11-25 16:59:27 -07001107 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDumpFile"),
Jon Ashburn21001f62015-02-16 08:26:50 -07001108 self._generate_layer_gpa_function("APIDumpFile")]
Tobin Ehlis574b0142014-11-12 13:11:15 -07001109
1110 return "\n\n".join(body)
1111
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -07001112class ApiDumpNoAddrSubcommand(Subcommand):
1113 def generate_header(self):
1114 header_txt = []
Ian Elliott81ac44c2015-01-13 17:52:38 -07001115 header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>')
1116 header_txt.append('#include "loader_platform.h"')
1117 header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper_no_addr.h"\n')
Ian Elliott20f06872015-02-12 17:08:34 -07001118 header_txt.append('// The following is #included again to catch certain OS-specific functions being used:')
1119 header_txt.append('#include "loader_platform.h"')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001120 header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;')
1121 header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n')
1122 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
1123 header_txt.append('static int printLockInitialized = 0;')
1124 header_txt.append('static loader_platform_thread_mutex printLock;\n')
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -07001125 header_txt.append('#define MAX_TID 513')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001126 header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};')
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -07001127 header_txt.append('static uint32_t maxTID = 0;')
1128 header_txt.append('// Map actual TID to an index value and return that index')
1129 header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs')
1130 header_txt.append('static uint32_t getTIDIndex() {')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001131 header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();')
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -07001132 header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {')
1133 header_txt.append(' if (tid == tidMapping[i])')
1134 header_txt.append(' return i;')
1135 header_txt.append(' }')
1136 header_txt.append(" // Don't yet have mapping, set it and return newly set index")
Ian Elliott81ac44c2015-01-13 17:52:38 -07001137 header_txt.append(' uint32_t retVal = (uint32_t) maxTID;')
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -07001138 header_txt.append(' tidMapping[maxTID++] = tid;')
1139 header_txt.append(' assert(maxTID < MAX_TID);')
1140 header_txt.append(' return retVal;')
1141 header_txt.append('}')
1142 return "\n".join(header_txt)
1143
1144 def generate_body(self):
Jon Ashburn21001f62015-02-16 08:26:50 -07001145 body = [self._generate_layer_initialization_with_lock("APIDumpNoAddr"),
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -07001146 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDump", True),
Jon Ashburn21001f62015-02-16 08:26:50 -07001147 self._generate_layer_gpa_function("APIDumpNoAddr")]
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -07001148
1149 return "\n\n".join(body)
1150
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001151class ApiDumpNoAddrCppSubcommand(Subcommand):
1152 def generate_header(self):
1153 header_txt = []
Ian Elliott81ac44c2015-01-13 17:52:38 -07001154 header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>')
1155 header_txt.append('#include "loader_platform.h"')
1156 header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper_no_addr_cpp.h"\n')
Ian Elliott20f06872015-02-12 17:08:34 -07001157 header_txt.append('// The following is #included again to catch certain OS-specific functions being used:')
1158 header_txt.append('#include "loader_platform.h"')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001159 header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;')
1160 header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n')
1161 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
1162 header_txt.append('static int printLockInitialized = 0;')
1163 header_txt.append('static loader_platform_thread_mutex printLock;\n')
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001164 header_txt.append('#define MAX_TID 513')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001165 header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};')
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001166 header_txt.append('static uint32_t maxTID = 0;')
1167 header_txt.append('// Map actual TID to an index value and return that index')
1168 header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs')
1169 header_txt.append('static uint32_t getTIDIndex() {')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001170 header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();')
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001171 header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {')
1172 header_txt.append(' if (tid == tidMapping[i])')
1173 header_txt.append(' return i;')
1174 header_txt.append(' }')
1175 header_txt.append(" // Don't yet have mapping, set it and return newly set index")
Ian Elliott81ac44c2015-01-13 17:52:38 -07001176 header_txt.append(' uint32_t retVal = (uint32_t) maxTID;')
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001177 header_txt.append(' tidMapping[maxTID++] = tid;')
1178 header_txt.append(' assert(maxTID < MAX_TID);')
1179 header_txt.append(' return retVal;')
1180 header_txt.append('}')
1181 return "\n".join(header_txt)
1182
1183 def generate_body(self):
Jon Ashburn21001f62015-02-16 08:26:50 -07001184 body = [self._generate_layer_initialization_with_lock("APIDumpNoAddrCpp"),
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001185 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDumpCpp", True),
Jon Ashburn21001f62015-02-16 08:26:50 -07001186 self._generate_layer_gpa_function("APIDumpNoAddrCpp")]
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001187
1188 return "\n\n".join(body)
1189
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001190class ObjectTrackerSubcommand(Subcommand):
1191 def generate_header(self):
1192 header_txt = []
Ian Elliott81ac44c2015-01-13 17:52:38 -07001193 header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include "loader_platform.h"')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001194 header_txt.append('#include "object_track.h"\n\nstatic XGL_LAYER_DISPATCH_TABLE nextTable;\nstatic XGL_BASE_LAYER_OBJECT *pCurObj;')
Ian Elliott20f06872015-02-12 17:08:34 -07001195 header_txt.append('// The following is #included again to catch certain OS-specific functions being used:')
1196 header_txt.append('#include "loader_platform.h"')
Jon Ashburn7a2da4f2015-02-17 11:03:12 -07001197 header_txt.append('#include "layers_config.h"')
Jon Ashburn21001f62015-02-16 08:26:50 -07001198 header_txt.append('#include "layers_msg.h"')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001199 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
1200 header_txt.append('static long long unsigned int object_track_index = 0;')
Tobin Ehlis84a8a9b2015-02-23 14:09:16 -07001201 header_txt.append('static int objLockInitialized = 0;')
1202 header_txt.append('static loader_platform_thread_mutex objLock;')
Jon Ashburn21001f62015-02-16 08:26:50 -07001203 header_txt.append('')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001204 header_txt.append('// We maintain a "Global" list which links every object and a')
1205 header_txt.append('// per-Object list which just links objects of a given type')
1206 header_txt.append('// The object node has both pointers so the actual nodes are shared between the two lists')
1207 header_txt.append('typedef struct _objNode {')
1208 header_txt.append(' OBJTRACK_NODE obj;')
1209 header_txt.append(' struct _objNode *pNextObj;')
1210 header_txt.append(' struct _objNode *pNextGlobal;')
1211 header_txt.append('} objNode;')
1212 header_txt.append('static objNode *pObjectHead[XGL_NUM_OBJECT_TYPE] = {0};')
1213 header_txt.append('static objNode *pGlobalHead = NULL;')
1214 header_txt.append('static uint64_t numObjs[XGL_NUM_OBJECT_TYPE] = {0};')
1215 header_txt.append('static uint64_t numTotalObjs = 0;')
Mark Lobodzinskie1d3f0c2015-02-09 10:20:53 -06001216 header_txt.append('static uint32_t maxMemRefsPerSubmission = 0;')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001217 header_txt.append('// Debug function to print global list and each individual object list')
1218 header_txt.append('static void ll_print_lists()')
1219 header_txt.append('{')
1220 header_txt.append(' objNode* pTrav = pGlobalHead;')
1221 header_txt.append(' printf("=====GLOBAL OBJECT LIST (%lu total objs):\\n", numTotalObjs);')
1222 header_txt.append(' while (pTrav) {')
1223 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);')
1224 header_txt.append(' pTrav = pTrav->pNextGlobal;')
1225 header_txt.append(' }')
1226 header_txt.append(' for (uint32_t i = 0; i < XGL_NUM_OBJECT_TYPE; i++) {')
1227 header_txt.append(' pTrav = pObjectHead[i];')
1228 header_txt.append(' if (pTrav) {')
1229 header_txt.append(' printf("=====%s OBJECT LIST (%lu objs):\\n", string_XGL_OBJECT_TYPE(pTrav->obj.objType), numObjs[i]);')
1230 header_txt.append(' while (pTrav) {')
1231 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);')
1232 header_txt.append(' pTrav = pTrav->pNextObj;')
1233 header_txt.append(' }')
1234 header_txt.append(' }')
1235 header_txt.append(' }')
1236 header_txt.append('}')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001237 header_txt.append('static void ll_insert_obj(void* pObj, XGL_OBJECT_TYPE objType) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001238 header_txt.append(' char str[1024];')
1239 header_txt.append(' sprintf(str, "OBJ[%llu] : CREATE %s object %p", object_track_index++, string_XGL_OBJECT_TYPE(objType), (void*)pObj);')
1240 header_txt.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_NONE, "OBJTRACK", str);')
1241 header_txt.append(' objNode* pNewObjNode = (objNode*)malloc(sizeof(objNode));')
1242 header_txt.append(' pNewObjNode->obj.pObj = pObj;')
1243 header_txt.append(' pNewObjNode->obj.objType = objType;')
Mark Lobodzinski01552702015-02-03 10:06:31 -06001244 header_txt.append(' pNewObjNode->obj.status = OBJSTATUS_NONE;')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001245 header_txt.append(' pNewObjNode->obj.numUses = 0;')
1246 header_txt.append(' // insert at front of global list')
1247 header_txt.append(' pNewObjNode->pNextGlobal = pGlobalHead;')
1248 header_txt.append(' pGlobalHead = pNewObjNode;')
1249 header_txt.append(' // insert at front of object list')
1250 header_txt.append(' pNewObjNode->pNextObj = pObjectHead[objType];')
1251 header_txt.append(' pObjectHead[objType] = pNewObjNode;')
1252 header_txt.append(' // increment obj counts')
1253 header_txt.append(' numObjs[objType]++;')
1254 header_txt.append(' numTotalObjs++;')
1255 header_txt.append(' //sprintf(str, "OBJ_STAT : %lu total objs & %lu %s objs.", numTotalObjs, numObjs[objType], string_XGL_OBJECT_TYPE(objType));')
Chia-I Wudf142a32014-12-16 11:02:06 +08001256 header_txt.append(' if (0) ll_print_lists();')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001257 header_txt.append('}')
1258 header_txt.append('// Traverse global list and return type for given object')
1259 header_txt.append('static XGL_OBJECT_TYPE ll_get_obj_type(XGL_OBJECT object) {')
1260 header_txt.append(' objNode *pTrav = pGlobalHead;')
1261 header_txt.append(' while (pTrav) {')
1262 header_txt.append(' if (pTrav->obj.pObj == object)')
1263 header_txt.append(' return pTrav->obj.objType;')
1264 header_txt.append(' pTrav = pTrav->pNextGlobal;')
1265 header_txt.append(' }')
1266 header_txt.append(' char str[1024];')
1267 header_txt.append(' sprintf(str, "Attempting look-up on obj %p but it is NOT in the global list!", (void*)object);')
1268 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, object, 0, OBJTRACK_MISSING_OBJECT, "OBJTRACK", str);')
1269 header_txt.append(' return XGL_OBJECT_TYPE_UNKNOWN;')
1270 header_txt.append('}')
Chia-I Wudf142a32014-12-16 11:02:06 +08001271 header_txt.append('#if 0')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001272 header_txt.append('static uint64_t ll_get_obj_uses(void* pObj, XGL_OBJECT_TYPE objType) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001273 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
1274 header_txt.append(' while (pTrav) {')
1275 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1276 header_txt.append(' return pTrav->obj.numUses;')
1277 header_txt.append(' }')
1278 header_txt.append(' pTrav = pTrav->pNextObj;')
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001279 header_txt.append(' }')
1280 header_txt.append(' return 0;')
1281 header_txt.append('}')
Chia-I Wudf142a32014-12-16 11:02:06 +08001282 header_txt.append('#endif')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001283 header_txt.append('static void ll_increment_use_count(void* pObj, XGL_OBJECT_TYPE objType) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001284 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001285 header_txt.append(' while (pTrav) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001286 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1287 header_txt.append(' pTrav->obj.numUses++;')
1288 header_txt.append(' char str[1024];')
1289 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);')
1290 header_txt.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_NONE, "OBJTRACK", str);')
1291 header_txt.append(' return;')
1292 header_txt.append(' }')
1293 header_txt.append(' pTrav = pTrav->pNextObj;')
1294 header_txt.append(' }')
1295 header_txt.append(' // If we do not find obj, insert it and then increment count')
1296 header_txt.append(' char str[1024];')
1297 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));')
1298 header_txt.append(' layerCbMsg(XGL_DBG_MSG_WARNING, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
1299 header_txt.append('')
1300 header_txt.append(' ll_insert_obj(pObj, objType);')
1301 header_txt.append(' ll_increment_use_count(pObj, objType);')
1302 header_txt.append('}')
1303 header_txt.append('// We usually do not know Obj type when we destroy it so have to fetch')
1304 header_txt.append('// Type from global list w/ ll_destroy_obj()')
1305 header_txt.append('// and then do the full removal from both lists w/ ll_remove_obj_type()')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001306 header_txt.append('static void ll_remove_obj_type(void* pObj, XGL_OBJECT_TYPE objType) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001307 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
1308 header_txt.append(' objNode *pPrev = pObjectHead[objType];')
1309 header_txt.append(' while (pTrav) {')
1310 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1311 header_txt.append(' pPrev->pNextObj = pTrav->pNextObj;')
1312 header_txt.append(' // update HEAD of Obj list as needed')
1313 header_txt.append(' if (pObjectHead[objType] == pTrav)')
1314 header_txt.append(' pObjectHead[objType] = pTrav->pNextObj;')
1315 header_txt.append(' assert(numObjs[objType] > 0);')
1316 header_txt.append(' numObjs[objType]--;')
1317 header_txt.append(' char str[1024];')
1318 header_txt.append(' sprintf(str, "OBJ[%llu] : DESTROY %s object %p", object_track_index++, string_XGL_OBJECT_TYPE(objType), (void*)pObj);')
1319 header_txt.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_NONE, "OBJTRACK", str);')
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001320 header_txt.append(' return;')
1321 header_txt.append(' }')
1322 header_txt.append(' pPrev = pTrav;')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001323 header_txt.append(' pTrav = pTrav->pNextObj;')
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001324 header_txt.append(' }')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001325 header_txt.append(' char str[1024];')
1326 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));')
1327 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_INTERNAL_ERROR, "OBJTRACK", str);')
1328 header_txt.append('}')
1329 header_txt.append('// Parse global list to find obj type, then remove obj from obj type list, finally')
1330 header_txt.append('// remove obj from global list')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001331 header_txt.append('static void ll_destroy_obj(void* pObj) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001332 header_txt.append(' objNode *pTrav = pGlobalHead;')
1333 header_txt.append(' objNode *pPrev = pGlobalHead;')
1334 header_txt.append(' while (pTrav) {')
1335 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1336 header_txt.append(' ll_remove_obj_type(pObj, pTrav->obj.objType);')
1337 header_txt.append(' pPrev->pNextGlobal = pTrav->pNextGlobal;')
1338 header_txt.append(' // update HEAD of global list if needed')
1339 header_txt.append(' if (pGlobalHead == pTrav)')
1340 header_txt.append(' pGlobalHead = pTrav->pNextGlobal;')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001341 header_txt.append(' assert(numTotalObjs > 0);')
1342 header_txt.append(' numTotalObjs--;')
1343 header_txt.append(' char str[1024];')
1344 header_txt.append(' sprintf(str, "OBJ_STAT Removed %s obj %p that was used %lu times (%lu total objs & %lu %s objs).", string_XGL_OBJECT_TYPE(pTrav->obj.objType), pTrav->obj.pObj, pTrav->obj.numUses, numTotalObjs, numObjs[pTrav->obj.objType], string_XGL_OBJECT_TYPE(pTrav->obj.objType));')
1345 header_txt.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_NONE, "OBJTRACK", str);')
Tobin Ehlis84a8a9b2015-02-23 14:09:16 -07001346 header_txt.append(' free(pTrav);')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001347 header_txt.append(' return;')
1348 header_txt.append(' }')
1349 header_txt.append(' pPrev = pTrav;')
1350 header_txt.append(' pTrav = pTrav->pNextGlobal;')
1351 header_txt.append(' }')
1352 header_txt.append(' char str[1024];')
1353 header_txt.append(' sprintf(str, "Unable to remove obj %p. Was it created? Has it already been destroyed?", pObj);')
1354 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_DESTROY_OBJECT_FAILED, "OBJTRACK", str);')
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001355 header_txt.append('}')
Tobin Ehlis235c20e2015-01-16 08:56:30 -07001356 header_txt.append('// Set selected flag state for an object node')
1357 header_txt.append('static void set_status(void* pObj, XGL_OBJECT_TYPE objType, OBJECT_STATUS status_flag) {')
Mark Lobodzinskid11fcca2015-02-09 10:16:20 -06001358 header_txt.append(' if (pObj != NULL) {')
1359 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
1360 header_txt.append(' while (pTrav) {')
1361 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1362 header_txt.append(' pTrav->obj.status |= status_flag;')
1363 header_txt.append(' return;')
1364 header_txt.append(' }')
1365 header_txt.append(' pTrav = pTrav->pNextObj;')
Tobin Ehlis235c20e2015-01-16 08:56:30 -07001366 header_txt.append(' }')
Mark Lobodzinskid11fcca2015-02-09 10:16:20 -06001367 header_txt.append(' // If we do not find it print an error')
1368 header_txt.append(' char str[1024];')
1369 header_txt.append(' sprintf(str, "Unable to set status for non-existent object %p of %s type", pObj, string_XGL_OBJECT_TYPE(objType));')
1370 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
1371 header_txt.append(' }');
Tobin Ehlis235c20e2015-01-16 08:56:30 -07001372 header_txt.append('}')
1373 header_txt.append('')
Mark Lobodzinski01552702015-02-03 10:06:31 -06001374 header_txt.append('// Track selected state for an object node')
1375 header_txt.append('static void track_object_status(void* pObj, XGL_STATE_BIND_POINT stateBindPoint) {')
1376 header_txt.append(' objNode *pTrav = pObjectHead[XGL_OBJECT_TYPE_CMD_BUFFER];')
1377 header_txt.append('')
1378 header_txt.append(' while (pTrav) {')
1379 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1380 header_txt.append(' if (stateBindPoint == XGL_STATE_BIND_VIEWPORT) {')
1381 header_txt.append(' pTrav->obj.status |= OBJSTATUS_VIEWPORT_BOUND;')
1382 header_txt.append(' } else if (stateBindPoint == XGL_STATE_BIND_RASTER) {')
1383 header_txt.append(' pTrav->obj.status |= OBJSTATUS_RASTER_BOUND;')
1384 header_txt.append(' } else if (stateBindPoint == XGL_STATE_BIND_COLOR_BLEND) {')
1385 header_txt.append(' pTrav->obj.status |= OBJSTATUS_COLOR_BLEND_BOUND;')
1386 header_txt.append(' } else if (stateBindPoint == XGL_STATE_BIND_DEPTH_STENCIL) {')
1387 header_txt.append(' pTrav->obj.status |= OBJSTATUS_DEPTH_STENCIL_BOUND;')
1388 header_txt.append(' }')
1389 header_txt.append(' return;')
1390 header_txt.append(' }')
1391 header_txt.append(' pTrav = pTrav->pNextObj;')
1392 header_txt.append(' }')
1393 header_txt.append(' // If we do not find it print an error')
1394 header_txt.append(' char str[1024];')
1395 header_txt.append(' sprintf(str, "Unable to track status for non-existent Command Buffer object %p", pObj);')
1396 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
1397 header_txt.append('}')
1398 header_txt.append('')
1399 header_txt.append('// Reset selected flag state for an object node')
1400 header_txt.append('static void reset_status(void* pObj, XGL_OBJECT_TYPE objType, OBJECT_STATUS status_flag) {')
Tobin Ehlis235c20e2015-01-16 08:56:30 -07001401 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
1402 header_txt.append(' while (pTrav) {')
1403 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
Mark Lobodzinski01552702015-02-03 10:06:31 -06001404 header_txt.append(' pTrav->obj.status &= ~status_flag;')
1405 header_txt.append(' return;')
1406 header_txt.append(' }')
1407 header_txt.append(' pTrav = pTrav->pNextObj;')
1408 header_txt.append(' }')
1409 header_txt.append(' // If we do not find it print an error')
1410 header_txt.append(' char str[1024];')
1411 header_txt.append(' sprintf(str, "Unable to reset status for non-existent object %p of %s type", pObj, string_XGL_OBJECT_TYPE(objType));')
1412 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
1413 header_txt.append('}')
1414 header_txt.append('')
1415 header_txt.append('// Check object status for selected flag state')
Mark Lobodzinskiacb93682015-03-05 12:39:33 -06001416 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 Lobodzinski01552702015-02-03 10:06:31 -06001417 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
1418 header_txt.append(' while (pTrav) {')
1419 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
Mark Lobodzinski4186e712015-02-03 11:52:26 -06001420 header_txt.append(' if ((pTrav->obj.status & status_mask) != status_flag) {')
Tobin Ehlis235c20e2015-01-16 08:56:30 -07001421 header_txt.append(' char str[1024];')
1422 header_txt.append(' sprintf(str, "OBJECT VALIDATION WARNING: %s object %p: %s", string_XGL_OBJECT_TYPE(objType), (void*)pObj, fail_msg);')
Mark Lobodzinski01552702015-02-03 10:06:31 -06001423 header_txt.append(' layerCbMsg(error_level, XGL_VALIDATION_LEVEL_0, pObj, 0, error_code, "OBJTRACK", str);')
Mark Lobodzinskiacb93682015-03-05 12:39:33 -06001424 header_txt.append(' return XGL_FALSE;')
Tobin Ehlis235c20e2015-01-16 08:56:30 -07001425 header_txt.append(' }')
Mark Lobodzinskiacb93682015-03-05 12:39:33 -06001426 header_txt.append(' return XGL_TRUE;')
Tobin Ehlis235c20e2015-01-16 08:56:30 -07001427 header_txt.append(' }')
1428 header_txt.append(' pTrav = pTrav->pNextObj;')
1429 header_txt.append(' }')
Mark Lobodzinskiacb93682015-03-05 12:39:33 -06001430 header_txt.append(' if (objType != XGL_OBJECT_TYPE_PRESENTABLE_IMAGE_MEMORY) {')
1431 header_txt.append(' // If we do not find it print an error')
1432 header_txt.append(' char str[1024];')
1433 header_txt.append(' sprintf(str, "Unable to obtain status for non-existent object %p of %s type", pObj, string_XGL_OBJECT_TYPE(objType));')
1434 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
1435 header_txt.append(' }')
1436 header_txt.append(' return XGL_FALSE;')
Tobin Ehlis235c20e2015-01-16 08:56:30 -07001437 header_txt.append('}')
Mark Lobodzinski01552702015-02-03 10:06:31 -06001438 header_txt.append('')
1439 header_txt.append('static void validate_draw_state_flags(void* pObj) {')
Mark Lobodzinski4186e712015-02-03 11:52:26 -06001440 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");')
1441 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");')
1442 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");')
1443 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");')
1444 header_txt.append('}')
1445 header_txt.append('')
1446 header_txt.append('static void validate_memory_mapping_status(const XGL_MEMORY_REF* pMemRefs, uint32_t numRefs) {')
Ian Elliotteac469b2015-02-04 12:15:12 -07001447 header_txt.append(' uint32_t i;')
Mark Lobodzinski4186e712015-02-03 11:52:26 -06001448 header_txt.append(' for (i = 0; i < numRefs; i++) {')
Mark Lobodzinskiacb93682015-03-05 12:39:33 -06001449 header_txt.append(' if(pMemRefs[i].mem) {')
1450 header_txt.append(' // If mem reference is in presentable image memory list, skip the check of the GPU_MEMORY list')
1451 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)')
1452 header_txt.append(' {')
1453 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");')
1454 header_txt.append(' }')
1455 header_txt.append(' }')
Mark Lobodzinski4186e712015-02-03 11:52:26 -06001456 header_txt.append(' }')
Mark Lobodzinski01552702015-02-03 10:06:31 -06001457 header_txt.append('}')
Mark Lobodzinskie1d3f0c2015-02-09 10:20:53 -06001458 header_txt.append('')
1459 header_txt.append('static void validate_mem_ref_count(uint32_t numRefs) {')
1460 header_txt.append(' if (maxMemRefsPerSubmission == 0) {')
1461 header_txt.append(' char str[1024];')
1462 header_txt.append(' sprintf(str, "xglQueueSubmit called before calling xglGetGpuInfo");')
1463 header_txt.append(' layerCbMsg(XGL_DBG_MSG_WARNING, XGL_VALIDATION_LEVEL_0, NULL, 0, OBJTRACK_GETGPUINFO_NOT_CALLED, "OBJTRACK", str);')
1464 header_txt.append(' } else {')
1465 header_txt.append(' if (numRefs > maxMemRefsPerSubmission) {')
1466 header_txt.append(' char str[1024];')
1467 header_txt.append(' sprintf(str, "xglQueueSubmit Memory reference count (%d) exceeds allowable GPU limit (%d)", numRefs, maxMemRefsPerSubmission);')
1468 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, OBJTRACK_MEMREFCOUNT_MAX_EXCEEDED, "OBJTRACK", str);')
1469 header_txt.append(' }')
1470 header_txt.append(' }')
1471 header_txt.append('}')
1472 header_txt.append('')
1473 header_txt.append('static void setGpuInfoState(void *pData) {')
1474 header_txt.append(' maxMemRefsPerSubmission = ((XGL_PHYSICAL_GPU_PROPERTIES *)pData)->maxMemRefsPerSubmission;')
1475 header_txt.append('}')
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001476 return "\n".join(header_txt)
1477
1478 def generate_body(self):
Tobin Ehlis84a8a9b2015-02-23 14:09:16 -07001479 body = [self._generate_layer_initialization("ObjectTracker", True, lockname='obj'),
Tobin Ehlis907a0522014-11-25 16:59:27 -07001480 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "ObjectTracker"),
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001481 self._generate_extensions(),
Jon Ashburn21001f62015-02-16 08:26:50 -07001482 self._generate_layer_gpa_function("ObjectTracker", extensions=['objTrackGetObjectCount', 'objTrackGetObjects'])]
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001483
1484 return "\n\n".join(body)
Courtney Goeltzenleuchtere6094fc2014-11-18 10:40:29 -07001485
Tobin Ehlis6cd06372014-12-17 17:44:50 -07001486class ParamCheckerSubcommand(Subcommand):
1487 def generate_header(self):
Jon Ashburn21001f62015-02-16 08:26:50 -07001488 return '#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include "loader_platform.h"\n#include "xglLayer.h"\n#include "layers_config.h"\n#include "xgl_enum_validate_helper.h"\n#include "xgl_struct_validate_helper.h"\n//The following is #included again to catch certain OS-specific functions being used:\n#include "loader_platform.h"\n\n#include "layers_msg.h"\n\nstatic XGL_LAYER_DISPATCH_TABLE nextTable;\nstatic XGL_BASE_LAYER_OBJECT *pCurObj;\nstatic LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);\n\n'
Tobin Ehlis6cd06372014-12-17 17:44:50 -07001489
1490 def generate_body(self):
Jon Ashburn21001f62015-02-16 08:26:50 -07001491 body = [self._generate_layer_initialization("ParamChecker", True),
Tobin Ehlis6cd06372014-12-17 17:44:50 -07001492 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "ParamChecker"),
Jon Ashburn21001f62015-02-16 08:26:50 -07001493 self._generate_layer_gpa_function("ParamChecker")]
Tobin Ehlis6cd06372014-12-17 17:44:50 -07001494
1495 return "\n\n".join(body)
1496
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001497def main():
1498 subcommands = {
1499 "layer-funcs" : LayerFuncsSubcommand,
1500 "layer-dispatch" : LayerDispatchSubcommand,
Tobin Ehlis907a0522014-11-25 16:59:27 -07001501 "Generic" : GenericLayerSubcommand,
1502 "ApiDump" : ApiDumpSubcommand,
1503 "ApiDumpFile" : ApiDumpFileSubcommand,
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -07001504 "ApiDumpNoAddr" : ApiDumpNoAddrSubcommand,
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001505 "ApiDumpCpp" : ApiDumpCppSubcommand,
1506 "ApiDumpNoAddrCpp" : ApiDumpNoAddrCppSubcommand,
Tobin Ehlis907a0522014-11-25 16:59:27 -07001507 "ObjectTracker" : ObjectTrackerSubcommand,
Tobin Ehlis6cd06372014-12-17 17:44:50 -07001508 "ParamChecker" : ParamCheckerSubcommand,
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001509 }
1510
Tobin Ehlis6cd06372014-12-17 17:44:50 -07001511 if len(sys.argv) < 3 or sys.argv[1] not in subcommands or not os.path.exists(sys.argv[2]):
1512 print("Usage: %s <subcommand> <input_header> [options]" % sys.argv[0])
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001513 print
Tobin Ehlis2f3726c2015-01-15 17:51:52 -07001514 print("Available subcommands are: %s" % " ".join(subcommands))
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001515 exit(1)
1516
Tobin Ehlis6cd06372014-12-17 17:44:50 -07001517 hfp = xgl_helper.HeaderFileParser(sys.argv[2])
1518 hfp.parse()
1519 xgl_helper.enum_val_dict = hfp.get_enum_val_dict()
1520 xgl_helper.enum_type_dict = hfp.get_enum_type_dict()
1521 xgl_helper.struct_dict = hfp.get_struct_dict()
1522 xgl_helper.typedef_fwd_dict = hfp.get_typedef_fwd_dict()
1523 xgl_helper.typedef_rev_dict = hfp.get_typedef_rev_dict()
1524 xgl_helper.types_dict = hfp.get_types_dict()
1525
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001526 subcmd = subcommands[sys.argv[1]](sys.argv[2:])
1527 subcmd.run()
1528
1529if __name__ == "__main__":
1530 main()