blob: 5746ea7f61362a9a74be95e07432d0ca3e6937ce [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
29
30import xgl
31
32class Subcommand(object):
33 def __init__(self, argv):
34 self.argv = argv
35 self.protos = ()
36 self.headers = ()
37
38 def run(self):
39 self.protos = xgl.core + xgl.ext_wsi_x11
40 self.headers = xgl.core_headers + xgl.ext_wsi_x11_headers
41 print(self.generate())
42
43 def generate(self):
44 copyright = self.generate_copyright()
45 header = self.generate_header()
46 body = self.generate_body()
47 footer = self.generate_footer()
48
49 contents = []
50 if copyright:
51 contents.append(copyright)
52 if header:
53 contents.append(header)
54 if body:
55 contents.append(body)
56 if footer:
57 contents.append(footer)
58
59 return "\n\n".join(contents)
60
61 def generate_copyright(self):
62 return """/* THIS FILE IS GENERATED. DO NOT EDIT. */
63
64/*
65 * XGL
66 *
67 * Copyright (C) 2014 LunarG, Inc.
68 *
69 * Permission is hereby granted, free of charge, to any person obtaining a
70 * copy of this software and associated documentation files (the "Software"),
71 * to deal in the Software without restriction, including without limitation
72 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
73 * and/or sell copies of the Software, and to permit persons to whom the
74 * Software is furnished to do so, subject to the following conditions:
75 *
76 * The above copyright notice and this permission notice shall be included
77 * in all copies or substantial portions of the Software.
78 *
79 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
80 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
81 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
82 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
83 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
84 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
85 * DEALINGS IN THE SOFTWARE.
86 */"""
87
88 def generate_header(self):
89 return "\n".join(["#include <" + h + ">" for h in self.headers])
90
91 def generate_body(self):
92 pass
93
94 def generate_footer(self):
95 pass
96
97 # Return set of printf '%' qualifier and input to that qualifier
Tobin Ehlisa554dc32014-11-19 15:52:46 -070098 def _get_printf_params(self, xgl_type, name, output_param):
Tobin Ehlis92dbf802014-10-22 09:06:33 -060099 # TODO : Need ENUM and STRUCT checks here
100 if "_TYPE" in xgl_type: # TODO : This should be generic ENUM check
101 return ("%s", "string_%s(%s)" % (xgl_type.strip('const ').strip('*'), name))
102 if "XGL_CHAR*" == xgl_type:
103 return ("%s", name)
104 if "UINT64" in xgl_type:
105 if '*' in xgl_type:
106 return ("%lu", "*%s" % name)
107 return ("%lu", name)
108 if "FLOAT" in xgl_type:
109 if '[' in xgl_type: # handle array, current hard-coded to 4 (TODO: Make this dynamic)
110 return ("[%f, %f, %f, %f]", "%s[0], %s[1], %s[2], %s[3]" % (name, name, name, name))
111 return ("%f", name)
Tobin Ehlis0a1e06d2014-11-11 17:28:22 -0700112 if "BOOL" in xgl_type or 'xcb_randr_crtc_t' in xgl_type:
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600113 return ("%u", name)
Tobin Ehlis0a1e06d2014-11-11 17:28:22 -0700114 if True in [t in xgl_type for t in ["INT", "SIZE", "FLAGS", "MASK", "xcb_window_t"]]:
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600115 if '[' in xgl_type: # handle array, current hard-coded to 4 (TODO: Make this dynamic)
116 return ("[%i, %i, %i, %i]", "%s[0], %s[1], %s[2], %s[3]" % (name, name, name, name))
117 if '*' in xgl_type:
118 return ("%i", "*%s" % name)
119 return ("%i", name)
Tobin Ehlis0a1e06d2014-11-11 17:28:22 -0700120 # TODO : This is special-cased as there's only one "format" param currently and it's nice to expand it
121 if "XGL_FORMAT" == xgl_type and "format" == name:
122 return ("{format.channelFormat = %s, format.numericFormat = %s}", "string_XGL_CHANNEL_FORMAT(format.channelFormat), string_XGL_NUM_FORMAT(format.numericFormat)")
Tobin Ehlisa554dc32014-11-19 15:52:46 -0700123 if output_param:
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600124 return ("%p", "(void*)*%s" % name)
125 return ("%p", "(void*)%s" % name)
126
127 def _generate_icd_dispatch_table(self):
128 proto_map = {}
129 for proto in self.protos:
130 proto_map[proto.name] = proto
131
132 entries = []
133 for name in xgl.icd_dispatch_table:
134 proto = proto_map[name]
135 entries.append(proto.c_typedef(attr="XGLAPI"))
136
137 return """struct icd_dispatch_table {
138 %s;
139};""" % ";\n ".join(entries)
140
141 def _generate_dispatch_entrypoints(self, qual="", layer="generic"):
142 if qual:
143 qual += " "
144
145 funcs = []
146 for proto in self.protos:
147 if proto.name != "GetProcAddr" and proto.name != "InitAndEnumerateGpus":
148 if "generic" == layer:
149 decl = proto.c_func(prefix="xgl", attr="XGLAPI")
150 param0_name = proto.params[0].name
151 ret_val = ''
152 stmt = ''
153 if proto.ret != "XGL_VOID":
154 ret_val = "XGL_RESULT result = "
155 stmt = " return result;\n"
156 if proto.params[0].ty != "XGL_PHYSICAL_GPU":
157 funcs.append('%s%s\n'
158 '{\n'
159 ' %snextTable.%s;\n'
160 '%s'
161 '}' % (qual, decl, ret_val, proto.c_call(), stmt))
162 else:
163 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
164 funcs.append('%s%s\n'
165 '{\n'
166 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
167 ' printf("At start of layered %s\\n");\n'
168 ' pCurObj = gpuw;\n'
169 ' pthread_once(&tabOnce, initLayerTable);\n'
170 ' %snextTable.%s;\n'
171 ' printf("Completed layered %s\\n");\n'
Courtney Goeltzenleuchtere6094fc2014-11-18 10:40:29 -0700172 ' fflush(stdout);\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600173 '%s'
174 '}' % (qual, decl, proto.params[0].name, proto.name, ret_val, c_call, proto.name, stmt))
Tobin Ehlis574b0142014-11-12 13:11:15 -0700175 elif "apidump" in layer:
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600176 decl = proto.c_func(prefix="xgl", attr="XGLAPI")
177 param0_name = proto.params[0].name
178 ret_val = ''
179 stmt = ''
Tobin Ehlis73ff5672014-10-23 08:19:47 -0600180 cis_param_index = [] # Store list of indices when func has struct params
Tobin Ehlisa554dc32014-11-19 15:52:46 -0700181 create_params = 0 # Num of params at end of function that are created and returned as output values
182 if 'WsiX11CreatePresentableImage' in proto.name:
183 create_params = -2
184 elif 'Create' in proto.name or 'Alloc' in proto.name or 'MapMemory' in proto.name:
185 create_params = -1
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600186 if proto.ret != "XGL_VOID":
187 ret_val = "XGL_RESULT result = "
188 stmt = " return result;\n"
Tobin Ehlis574b0142014-11-12 13:11:15 -0700189 f_open = ''
190 f_close = ''
191 if "file" in layer:
Tobin Ehlis1eba7792014-11-21 09:35:53 -0700192 file_mode = "a"
193 if 'CreateDevice' in proto.name:
194 file_mode = "w"
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700195 f_open = 'unsigned int tid = pthread_self();\n pthread_mutex_lock( &file_lock );\n pOutFile = fopen(outFileName, "%s");\n ' % (file_mode)
196 log_func = 'fprintf(pOutFile, "t{%%u} xgl%s(' % proto.name
Tobin Ehlis1aa7d3e2014-11-20 12:18:45 -0700197 f_close = '\n fclose(pOutFile);\n pthread_mutex_unlock( &file_lock );'
Tobin Ehlis574b0142014-11-12 13:11:15 -0700198 else:
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700199 f_open = 'unsigned int tid = pthread_self();\n pthread_mutex_lock( &print_lock );\n '
200 log_func = 'printf("t{%%u} xgl%s(' % proto.name
Tobin Ehlis1aa7d3e2014-11-20 12:18:45 -0700201 f_close = '\n pthread_mutex_unlock( &print_lock );'
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700202 print_vals = ', getTIDIndex()'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600203 pindex = 0
204 for p in proto.params:
Tobin Ehlisa554dc32014-11-19 15:52:46 -0700205 # TODO : Need to handle xglWsiX11CreatePresentableImage for which the last 2 params are returned vals
206 cp = False
207 if 0 != create_params:
208 # If this is any of the N last params of the func, treat as output
209 for y in range(-1, create_params-1, -1):
210 if p.name == proto.params[y].name:
211 cp = True
212 (pft, pfi) = self._get_printf_params(p.ty, p.name, cp)
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600213 log_func += '%s = %s, ' % (p.name, pft)
214 print_vals += ', %s' % (pfi)
Tobin Ehlis73ff5672014-10-23 08:19:47 -0600215 # TODO : Just want this to be simple check for params of STRUCT type
216 if "pCreateInfo" in p.name or ('const' in p.ty and '*' in p.ty and False not in [tmp_ty not in p.ty for tmp_ty in ['XGL_CHAR', 'XGL_VOID', 'XGL_CMD_BUFFER', 'XGL_QUEUE_SEMAPHORE', 'XGL_FENCE', 'XGL_SAMPLER', 'XGL_UINT32']]):
Tobin Ehlis0a1e06d2014-11-11 17:28:22 -0700217 if 'Wsi' not in proto.name:
218 cis_param_index.append(pindex)
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600219 pindex += 1
220 log_func = log_func.strip(', ')
221 if proto.ret != "XGL_VOID":
222 log_func += ') = %s\\n"'
Courtney Goeltzenleuchtere6094fc2014-11-18 10:40:29 -0700223 print_vals += ', string_XGL_RESULT(result)'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600224 else:
225 log_func += ')\\n"'
226 log_func = '%s%s);' % (log_func, print_vals)
Tobin Ehlis73ff5672014-10-23 08:19:47 -0600227 if len(cis_param_index) > 0:
228 log_func += '\n char *pTmpStr;'
229 for sp_index in cis_param_index:
230 cis_print_func = 'xgl_print_%s' % (proto.params[sp_index].ty.strip('const ').strip('*').lower())
231 log_func += '\n if (%s) {' % (proto.params[sp_index].name)
232 log_func += '\n pTmpStr = %s(%s, " ");' % (cis_print_func, proto.params[sp_index].name)
Tobin Ehlis574b0142014-11-12 13:11:15 -0700233 if "file" in layer:
234 log_func += '\n fprintf(pOutFile, " %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name)
235 else:
236 log_func += '\n printf(" %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name)
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700237 log_func += '\n fflush(stdout);'
Tobin Ehlis73ff5672014-10-23 08:19:47 -0600238 log_func += '\n free(pTmpStr);\n }'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600239 if proto.params[0].ty != "XGL_PHYSICAL_GPU":
240 funcs.append('%s%s\n'
241 '{\n'
242 ' %snextTable.%s;\n'
Tobin Ehlis574b0142014-11-12 13:11:15 -0700243 ' %s%s%s\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600244 '%s'
Tobin Ehlis574b0142014-11-12 13:11:15 -0700245 '}' % (qual, decl, ret_val, proto.c_call(), f_open, log_func, f_close, stmt))
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600246 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'
250 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
251 ' pCurObj = gpuw;\n'
252 ' pthread_once(&tabOnce, initLayerTable);\n'
253 ' %snextTable.%s;\n'
Tobin Ehlis574b0142014-11-12 13:11:15 -0700254 ' %s%s%s\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600255 '%s'
Tobin Ehlis574b0142014-11-12 13:11:15 -0700256 '}' % (qual, decl, proto.params[0].name, ret_val, c_call, f_open, log_func, f_close, stmt))
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600257 elif "objecttracker" == layer:
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700258 obj_type_mapping = {"XGL_PHYSICAL_GPU" : "XGL_OBJECT_TYPE_PHYSICAL_GPU", "XGL_DEVICE" : "XGL_OBJECT_TYPE_DEVICE",
259 "XGL_QUEUE" : "XGL_OBJECT_TYPE_QUEUE", "XGL_QUEUE_SEMAPHORE" : "XGL_OBJECT_TYPE_QUEUE_SEMAPHORE",
260 "XGL_GPU_MEMORY" : "XGL_OBJECT_TYPE_GPU_MEMORY", "XGL_FENCE" : "XGL_OBJECT_TYPE_FENCE",
261 "XGL_QUERY_POOL" : "XGL_OBJECT_TYPE_QUERY_POOL", "XGL_EVENT" : "XGL_OBJECT_TYPE_EVENT",
262 "XGL_IMAGE" : "XGL_OBJECT_TYPE_IMAGE", "XGL_DESCRIPTOR_SET" : "XGL_OBJECT_TYPE_DESCRIPTOR_SET",
263 "XGL_CMD_BUFFER" : "XGL_OBJECT_TYPE_CMD_BUFFER", "XGL_SAMPLER" : "XGL_OBJECT_TYPE_SAMPLER",
264 "XGL_PIPELINE" : "XGL_OBJECT_TYPE_PIPELINE", "XGL_PIPELINE_DELTA" : "XGL_OBJECT_TYPE_PIPELINE_DELTA",
265 "XGL_SHADER" : "XGL_OBJECT_TYPE_SHADER", "XGL_IMAGE_VIEW" : "XGL_OBJECT_TYPE_IMAGE_VIEW",
266 "XGL_COLOR_ATTACHMENT_VIEW" : "XGL_OBJECT_TYPE_COLOR_ATTACHMENT_VIEW", "XGL_DEPTH_STENCIL_VIEW" : "XGL_OBJECT_TYPE_DEPTH_STENCIL_VIEW",
267 "XGL_VIEWPORT_STATE_OBJECT" : "XGL_OBJECT_TYPE_VIEWPORT_STATE", "XGL_RASTER_STATE_OBJECT" : "XGL_OBJECT_TYPE_RASTER_STATE",
268 "XGL_MSAA_STATE_OBJECT" : "XGL_OBJECT_TYPE_MSAA_STATE", "XGL_COLOR_BLEND_STATE_OBJECT" : "XGL_OBJECT_TYPE_COLOR_BLEND_STATE",
269 "XGL_DEPTH_STENCIL_STATE_OBJECT" : "XGL_OBJECT_TYPE_DEPTH_STENCIL_STATE", "XGL_BASE_OBJECT" : "ll_get_obj_type(object)",
270 "XGL_OBJECT" : "ll_get_obj_type(object)"}
271
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600272 decl = proto.c_func(prefix="xgl", attr="XGLAPI")
273 param0_name = proto.params[0].name
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700274 p0_type = proto.params[0].ty
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600275 create_line = ''
276 destroy_line = ''
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700277 if 'DbgRegisterMsgCallback' in proto.name:
278 using_line = ' // This layer intercepts callbacks\n'
279 using_line += ' XGL_LAYER_DBG_FUNCTION_NODE *pNewDbgFuncNode = (XGL_LAYER_DBG_FUNCTION_NODE*)malloc(sizeof(XGL_LAYER_DBG_FUNCTION_NODE));\n'
280 using_line += ' if (!pNewDbgFuncNode)\n'
281 using_line += ' return XGL_ERROR_OUT_OF_MEMORY;\n'
282 using_line += ' pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;\n'
283 using_line += ' pNewDbgFuncNode->pUserData = pUserData;\n'
284 using_line += ' pNewDbgFuncNode->pNext = pDbgFunctionHead;\n'
285 using_line += ' pDbgFunctionHead = pNewDbgFuncNode;\n'
286 elif 'DbgUnregisterMsgCallback' in proto.name:
287 using_line = ' XGL_LAYER_DBG_FUNCTION_NODE *pTrav = pDbgFunctionHead;\n'
288 using_line += ' XGL_LAYER_DBG_FUNCTION_NODE *pPrev = pTrav;\n'
289 using_line += ' while (pTrav) {\n'
290 using_line += ' if (pTrav->pfnMsgCallback == pfnMsgCallback) {\n'
291 using_line += ' pPrev->pNext = pTrav->pNext;\n'
292 using_line += ' if (pDbgFunctionHead == pTrav)\n'
293 using_line += ' pDbgFunctionHead = pTrav->pNext;\n'
294 using_line += ' free(pTrav);\n'
295 using_line += ' break;\n'
296 using_line += ' }\n'
297 using_line += ' pPrev = pTrav;\n'
298 using_line += ' pTrav = pTrav->pNext;\n'
299 using_line += ' }\n'
300 elif 'GlobalOption' in proto.name:
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600301 using_line = ''
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700302 else:
303 using_line = ' ll_increment_use_count((XGL_VOID*)%s, %s);\n' % (param0_name, obj_type_mapping[p0_type])
304 if 'Create' in proto.name or 'Alloc' in proto.name:
305 create_line = ' ll_insert_obj((XGL_VOID*)*%s, %s);\n' % (proto.params[-1].name, obj_type_mapping[proto.params[-1].ty.strip('*')])
306 if 'DestroyObject' in proto.name:
307 destroy_line = ' ll_destroy_obj((XGL_VOID*)%s);\n' % (param0_name)
308 using_line = ''
309 else:
310 if 'Destroy' in proto.name or 'Free' in proto.name:
311 destroy_line = ' ll_remove_obj_type((XGL_VOID*)%s, %s);\n' % (param0_name, obj_type_mapping[p0_type])
312 using_line = ''
313 if 'DestroyDevice' in proto.name:
314 destroy_line += ' // Report any remaining objects in LL\n objNode *pTrav = pGlobalHead;\n while (pTrav) {\n'
315 destroy_line += ' char str[1024];\n'
316 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'
317 destroy_line += ' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, device, 0, OBJTRACK_OBJECT_LEAK, "OBJTRACK", str);\n'
318 destroy_line += ' pTrav = pTrav->pNextGlobal;\n }\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600319 ret_val = ''
320 stmt = ''
321 if proto.ret != "XGL_VOID":
322 ret_val = "XGL_RESULT result = "
323 stmt = " return result;\n"
324 if proto.params[0].ty != "XGL_PHYSICAL_GPU":
325 funcs.append('%s%s\n'
326 '{\n'
327 '%s'
328 ' %snextTable.%s;\n'
329 '%s%s'
330 '%s'
331 '}' % (qual, decl, using_line, ret_val, proto.c_call(), create_line, destroy_line, stmt))
332 else:
333 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
334 funcs.append('%s%s\n'
335 '{\n'
336 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
337 '%s'
338 ' pCurObj = gpuw;\n'
339 ' pthread_once(&tabOnce, initLayerTable);\n'
340 ' %snextTable.%s;\n'
341 '%s%s'
342 '%s'
343 '}' % (qual, decl, proto.params[0].name, using_line, ret_val, c_call, create_line, destroy_line, stmt))
344
345 # TODO : Put this code somewhere so it gets called at the end if objects not deleted :
346 # // Report any remaining objects in LL
347 # objNode *pTrav = pObjLLHead;
348 # while (pTrav) {
349 # printf("WARN : %s object %p has not been destroyed.\n", pTrav->objType, pTrav->pObj);
350 # }
351
352 return "\n\n".join(funcs)
353
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700354 def _generate_extensions(self):
355 exts = []
356 exts.append('XGL_UINT64 objTrackGetObjectCount(XGL_OBJECT_TYPE type)')
357 exts.append('{')
358 exts.append(' return (type == XGL_OBJECT_TYPE_ANY) ? numTotalObjs : numObjs[type];')
359 exts.append('}')
360 exts.append('')
361 exts.append('XGL_RESULT objTrackGetObjects(XGL_OBJECT_TYPE type, XGL_UINT64 objCount, OBJTRACK_NODE* pObjNodeArray)')
362 exts.append('{')
363 exts.append(" // This bool flags if we're pulling all objs or just a single class of objs")
364 exts.append(' XGL_BOOL bAllObjs = (type == XGL_OBJECT_TYPE_ANY);')
365 exts.append(' // Check the count first thing')
366 exts.append(' XGL_UINT64 maxObjCount = (bAllObjs) ? numTotalObjs : numObjs[type];')
367 exts.append(' if (objCount > maxObjCount) {')
368 exts.append(' char str[1024];')
369 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));')
370 exts.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, 0, 0, OBJTRACK_OBJCOUNT_MAX_EXCEEDED, "OBJTRACK", str);')
371 exts.append(' return XGL_ERROR_INVALID_VALUE;')
372 exts.append(' }')
373 exts.append(' objNode* pTrav = (bAllObjs) ? pGlobalHead : pObjectHead[type];')
374 exts.append(' for (XGL_UINT64 i = 0; i < objCount; i++) {')
375 exts.append(' if (!pTrav) {')
376 exts.append(' char str[1024];')
377 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);')
378 exts.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, 0, 0, OBJTRACK_INTERNAL_ERROR, "OBJTRACK", str);')
379 exts.append(' return XGL_ERROR_UNKNOWN;')
380 exts.append(' }')
381 exts.append(' memcpy(&pObjNodeArray[i], pTrav, sizeof(OBJTRACK_NODE));')
382 exts.append(' pTrav = (bAllObjs) ? pTrav->pNextGlobal : pTrav->pNextObj;')
383 exts.append(' }')
384 exts.append(' return XGL_SUCCESS;')
385 exts.append('}')
386
387 return "\n".join(exts)
388
389 def _generate_layer_gpa_function(self, prefix="xgl", extensions=[]):
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600390 func_body = []
391 func_body.append("XGL_LAYER_EXPORT XGL_VOID* XGLAPI xglGetProcAddr(XGL_PHYSICAL_GPU gpu, const XGL_CHAR* funcName)\n"
392 "{\n"
393 " XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) gpu;\n"
394 " if (gpu == NULL)\n"
395 " return NULL;\n"
396 " pCurObj = gpuw;\n"
397 " pthread_once(&tabOnce, initLayerTable);\n\n"
398 ' if (!strncmp("xglGetProcAddr", (const char *) funcName, sizeof("xglGetProcAddr")))\n'
399 ' return xglGetProcAddr;')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700400 if 0 != len(extensions):
401 for ext_name in extensions:
402 func_body.append(' else if (!strncmp("%s", (const char *) funcName, sizeof("%s")))\n'
403 ' return %s;' % (ext_name, ext_name, ext_name))
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600404 for name in xgl.icd_dispatch_table:
405 if name == "GetProcAddr":
406 continue
407 if name == "InitAndEnumerateGpus":
408 func_body.append(' else if (!strncmp("%s%s", (const char *) funcName, sizeof("%s%s")))\n'
409 ' return nextTable.%s;' % (prefix, name, prefix, name, name))
410 else:
411 func_body.append(' else if (!strncmp("%s%s", (const char *) funcName, sizeof("%s%s")))\n'
412 ' return %s%s;' % (prefix, name, prefix, name, prefix, name))
413
414 func_body.append(" else {\n"
415 " XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) gpu;\n"
416 " if (gpuw->pGPA == NULL)\n"
417 " return NULL;\n"
418 " return gpuw->pGPA(gpuw->nextObject, funcName);\n"
419 " }\n"
420 "}\n")
421 return "\n".join(func_body)
422
423 def _generate_layer_dispatch_table(self, prefix='xgl'):
424 func_body = []
425 func_body.append('static void initLayerTable()\n'
426 '{\n'
427 ' GetProcAddrType fpNextGPA;\n'
428 ' fpNextGPA = pCurObj->pGPA;\n'
429 ' assert(fpNextGPA);\n');
430
431 for name in xgl.icd_dispatch_table:
432 func_body.append(' %sType fp%s = fpNextGPA((XGL_PHYSICAL_GPU) pCurObj->nextObject, (XGL_CHAR *) "%s%s");\n'
433 ' nextTable.%s = fp%s;' % (name, name, prefix, name, name, name))
434
435 func_body.append("}\n")
436 return "\n".join(func_body)
437
438class LayerFuncsSubcommand(Subcommand):
439 def generate_header(self):
440 return '#include <xglLayer.h>\n#include "loader.h"'
441
442 def generate_body(self):
443 return self._generate_dispatch_entrypoints("static", True)
444
445class LayerDispatchSubcommand(Subcommand):
446 def generate_header(self):
447 return '#include "layer_wrappers.h"'
448
449 def generate_body(self):
450 return self._generate_layer_dispatch_table()
451
452class GenericLayerSubcommand(Subcommand):
453 def generate_header(self):
454 return '#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <assert.h>\n#include <pthread.h>\n#include "xglLayer.h"\n\nstatic XGL_LAYER_DISPATCH_TABLE nextTable;\nstatic XGL_BASE_LAYER_OBJECT *pCurObj;\nstatic pthread_once_t tabOnce = PTHREAD_ONCE_INIT;\n'
455
456 def generate_body(self):
457 body = [self._generate_layer_dispatch_table(),
458 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "generic"),
459 self._generate_layer_gpa_function()]
460
461 return "\n\n".join(body)
462
463class ApiDumpSubcommand(Subcommand):
464 def generate_header(self):
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700465 header_txt = []
466 header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <assert.h>\n#include <pthread.h>\n#include "xglLayer.h"\n#include "xgl_struct_string_helper.h"\n\nstatic XGL_LAYER_DISPATCH_TABLE nextTable;\nstatic XGL_BASE_LAYER_OBJECT *pCurObj;\nstatic pthread_once_t tabOnce = PTHREAD_ONCE_INIT;\npthread_mutex_t print_lock = PTHREAD_MUTEX_INITIALIZER;\n')
467 header_txt.append('#define MAX_TID 513')
468 header_txt.append('static pthread_t tidMapping[MAX_TID] = {0};')
469 header_txt.append('static uint32_t maxTID = 0;')
470 header_txt.append('// Map actual TID to an index value and return that index')
471 header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs')
472 header_txt.append('static uint32_t getTIDIndex() {')
473 header_txt.append(' pthread_t tid = pthread_self();')
474 header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {')
475 header_txt.append(' if (tid == tidMapping[i])')
476 header_txt.append(' return i;')
477 header_txt.append(' }')
478 header_txt.append(" // Don't yet have mapping, set it and return newly set index")
479 header_txt.append(' uint32_t retVal = (uint32_t)maxTID;')
480 header_txt.append(' tidMapping[maxTID++] = tid;')
481 header_txt.append(' assert(maxTID < MAX_TID);')
482 header_txt.append(' return retVal;')
483 header_txt.append('}')
484 return "\n".join(header_txt)
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600485
486 def generate_body(self):
487 body = [self._generate_layer_dispatch_table(),
488 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "apidump"),
489 self._generate_layer_gpa_function()]
490
491 return "\n\n".join(body)
492
Tobin Ehlis574b0142014-11-12 13:11:15 -0700493class ApiDumpFileSubcommand(Subcommand):
494 def generate_header(self):
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700495 header_txt = []
496 header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <assert.h>\n#include <pthread.h>\n#include "xglLayer.h"\n#include "xgl_struct_string_helper.h"\n\nstatic XGL_LAYER_DISPATCH_TABLE nextTable;\nstatic XGL_BASE_LAYER_OBJECT *pCurObj;\nstatic pthread_once_t tabOnce = PTHREAD_ONCE_INIT;\n\nstatic FILE* pOutFile;\nstatic char* outFileName = "xgl_apidump.txt";\npthread_mutex_t file_lock = PTHREAD_MUTEX_INITIALIZER;\n')
497 header_txt.append('#define MAX_TID 513')
498 header_txt.append('static pthread_t tidMapping[MAX_TID] = {0};')
499 header_txt.append('static uint32_t maxTID = 0;')
500 header_txt.append('// Map actual TID to an index value and return that index')
501 header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs')
502 header_txt.append('static uint32_t getTIDIndex() {')
503 header_txt.append(' pthread_t tid = pthread_self();')
504 header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {')
505 header_txt.append(' if (tid == tidMapping[i])')
506 header_txt.append(' return i;')
507 header_txt.append(' }')
508 header_txt.append(" // Don't yet have mapping, set it and return newly set index")
509 header_txt.append(' uint32_t retVal = (uint32_t)maxTID;')
510 header_txt.append(' tidMapping[maxTID++] = tid;')
511 header_txt.append(' assert(maxTID < MAX_TID);')
512 header_txt.append(' return retVal;')
513 header_txt.append('}')
514 return "\n".join(header_txt)
Tobin Ehlis574b0142014-11-12 13:11:15 -0700515
516 def generate_body(self):
517 body = [self._generate_layer_dispatch_table(),
518 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "apidump-file"),
519 self._generate_layer_gpa_function()]
520
521 return "\n\n".join(body)
522
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600523class ObjectTrackerSubcommand(Subcommand):
524 def generate_header(self):
525 header_txt = []
526 header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <assert.h>\n#include <pthread.h>')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700527 header_txt.append('#include "object_track.h"\n\nstatic XGL_LAYER_DISPATCH_TABLE nextTable;\nstatic XGL_BASE_LAYER_OBJECT *pCurObj;')
528 header_txt.append('static pthread_once_t tabOnce = PTHREAD_ONCE_INIT;\nstatic long long unsigned int object_track_index = 0;')
529 header_txt.append('// Ptr to LL of dbg functions')
530 header_txt.append('static XGL_LAYER_DBG_FUNCTION_NODE *pDbgFunctionHead = NULL;')
531 header_txt.append('// Utility function to handle reporting')
532 header_txt.append('// If callbacks are enabled, use them, otherwise use printf')
533 header_txt.append('static XGL_VOID layerCbMsg(XGL_DBG_MSG_TYPE msgType,')
534 header_txt.append(' XGL_VALIDATION_LEVEL validationLevel,')
535 header_txt.append(' XGL_BASE_OBJECT srcObject,')
536 header_txt.append(' XGL_SIZE location,')
537 header_txt.append(' XGL_INT msgCode,')
538 header_txt.append(' const XGL_CHAR* pLayerPrefix,')
539 header_txt.append(' const XGL_CHAR* pMsg)')
540 header_txt.append('{')
541 header_txt.append(' XGL_LAYER_DBG_FUNCTION_NODE *pTrav = pDbgFunctionHead;')
542 header_txt.append(' if (pTrav) {')
543 header_txt.append(' while (pTrav) {')
544 header_txt.append(' pTrav->pfnMsgCallback(msgType, validationLevel, srcObject, location, msgCode, pMsg, pTrav->pUserData);')
545 header_txt.append(' pTrav = pTrav->pNext;')
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600546 header_txt.append(' }')
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600547 header_txt.append(' }')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700548 header_txt.append(' else {')
549 header_txt.append(' switch (msgType) {')
550 header_txt.append(' case XGL_DBG_MSG_ERROR:')
551 header_txt.append(' printf("{%s}ERROR : %s\\n", pLayerPrefix, pMsg);')
552 header_txt.append(' break;')
553 header_txt.append(' case XGL_DBG_MSG_WARNING:')
554 header_txt.append(' printf("{%s}WARN : %s\\n", pLayerPrefix, pMsg);')
555 header_txt.append(' break;')
556 header_txt.append(' case XGL_DBG_MSG_PERF_WARNING:')
557 header_txt.append(' printf("{%s}PERF_WARN : %s\\n", pLayerPrefix, pMsg);')
558 header_txt.append(' break;')
559 header_txt.append(' default:')
560 header_txt.append(' printf("{%s}INFO : %s\\n", pLayerPrefix, pMsg);')
561 header_txt.append(' break;')
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600562 header_txt.append(' }')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700563 header_txt.append(' }')
564 header_txt.append('}')
565 header_txt.append('// We maintain a "Global" list which links every object and a')
566 header_txt.append('// per-Object list which just links objects of a given type')
567 header_txt.append('// The object node has both pointers so the actual nodes are shared between the two lists')
568 header_txt.append('typedef struct _objNode {')
569 header_txt.append(' OBJTRACK_NODE obj;')
570 header_txt.append(' struct _objNode *pNextObj;')
571 header_txt.append(' struct _objNode *pNextGlobal;')
572 header_txt.append('} objNode;')
573 header_txt.append('static objNode *pObjectHead[XGL_NUM_OBJECT_TYPE] = {0};')
574 header_txt.append('static objNode *pGlobalHead = NULL;')
575 header_txt.append('static uint64_t numObjs[XGL_NUM_OBJECT_TYPE] = {0};')
576 header_txt.append('static uint64_t numTotalObjs = 0;')
577 header_txt.append('// Debug function to print global list and each individual object list')
578 header_txt.append('static void ll_print_lists()')
579 header_txt.append('{')
580 header_txt.append(' objNode* pTrav = pGlobalHead;')
581 header_txt.append(' printf("=====GLOBAL OBJECT LIST (%lu total objs):\\n", numTotalObjs);')
582 header_txt.append(' while (pTrav) {')
583 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);')
584 header_txt.append(' pTrav = pTrav->pNextGlobal;')
585 header_txt.append(' }')
586 header_txt.append(' for (uint32_t i = 0; i < XGL_NUM_OBJECT_TYPE; i++) {')
587 header_txt.append(' pTrav = pObjectHead[i];')
588 header_txt.append(' if (pTrav) {')
589 header_txt.append(' printf("=====%s OBJECT LIST (%lu objs):\\n", string_XGL_OBJECT_TYPE(pTrav->obj.objType), numObjs[i]);')
590 header_txt.append(' while (pTrav) {')
591 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);')
592 header_txt.append(' pTrav = pTrav->pNextObj;')
593 header_txt.append(' }')
594 header_txt.append(' }')
595 header_txt.append(' }')
596 header_txt.append('}')
597 header_txt.append('static void ll_insert_obj(XGL_VOID* pObj, XGL_OBJECT_TYPE objType) {')
598 header_txt.append(' char str[1024];')
599 header_txt.append(' sprintf(str, "OBJ[%llu] : CREATE %s object %p", object_track_index++, string_XGL_OBJECT_TYPE(objType), (void*)pObj);')
600 header_txt.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_NONE, "OBJTRACK", str);')
601 header_txt.append(' objNode* pNewObjNode = (objNode*)malloc(sizeof(objNode));')
602 header_txt.append(' pNewObjNode->obj.pObj = pObj;')
603 header_txt.append(' pNewObjNode->obj.objType = objType;')
604 header_txt.append(' pNewObjNode->obj.numUses = 0;')
605 header_txt.append(' // insert at front of global list')
606 header_txt.append(' pNewObjNode->pNextGlobal = pGlobalHead;')
607 header_txt.append(' pGlobalHead = pNewObjNode;')
608 header_txt.append(' // insert at front of object list')
609 header_txt.append(' pNewObjNode->pNextObj = pObjectHead[objType];')
610 header_txt.append(' pObjectHead[objType] = pNewObjNode;')
611 header_txt.append(' // increment obj counts')
612 header_txt.append(' numObjs[objType]++;')
613 header_txt.append(' numTotalObjs++;')
614 header_txt.append(' //sprintf(str, "OBJ_STAT : %lu total objs & %lu %s objs.", numTotalObjs, numObjs[objType], string_XGL_OBJECT_TYPE(objType));')
615 header_txt.append(' //ll_print_lists();')
616 header_txt.append('}')
617 header_txt.append('// Traverse global list and return type for given object')
618 header_txt.append('static XGL_OBJECT_TYPE ll_get_obj_type(XGL_OBJECT object) {')
619 header_txt.append(' objNode *pTrav = pGlobalHead;')
620 header_txt.append(' while (pTrav) {')
621 header_txt.append(' if (pTrav->obj.pObj == object)')
622 header_txt.append(' return pTrav->obj.objType;')
623 header_txt.append(' pTrav = pTrav->pNextGlobal;')
624 header_txt.append(' }')
625 header_txt.append(' char str[1024];')
626 header_txt.append(' sprintf(str, "Attempting look-up on obj %p but it is NOT in the global list!", (void*)object);')
627 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, object, 0, OBJTRACK_MISSING_OBJECT, "OBJTRACK", str);')
628 header_txt.append(' return XGL_OBJECT_TYPE_UNKNOWN;')
629 header_txt.append('}')
630 header_txt.append('static uint64_t ll_get_obj_uses(XGL_VOID* pObj, XGL_OBJECT_TYPE objType) {')
631 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
632 header_txt.append(' while (pTrav) {')
633 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
634 header_txt.append(' return pTrav->obj.numUses;')
635 header_txt.append(' }')
636 header_txt.append(' pTrav = pTrav->pNextObj;')
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600637 header_txt.append(' }')
638 header_txt.append(' return 0;')
639 header_txt.append('}')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700640 header_txt.append('static void ll_increment_use_count(XGL_VOID* pObj, XGL_OBJECT_TYPE objType) {')
641 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600642 header_txt.append(' while (pTrav) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700643 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
644 header_txt.append(' pTrav->obj.numUses++;')
645 header_txt.append(' char str[1024];')
646 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);')
647 header_txt.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_NONE, "OBJTRACK", str);')
648 header_txt.append(' return;')
649 header_txt.append(' }')
650 header_txt.append(' pTrav = pTrav->pNextObj;')
651 header_txt.append(' }')
652 header_txt.append(' // If we do not find obj, insert it and then increment count')
653 header_txt.append(' char str[1024];')
654 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));')
655 header_txt.append(' layerCbMsg(XGL_DBG_MSG_WARNING, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
656 header_txt.append('')
657 header_txt.append(' ll_insert_obj(pObj, objType);')
658 header_txt.append(' ll_increment_use_count(pObj, objType);')
659 header_txt.append('}')
660 header_txt.append('// We usually do not know Obj type when we destroy it so have to fetch')
661 header_txt.append('// Type from global list w/ ll_destroy_obj()')
662 header_txt.append('// and then do the full removal from both lists w/ ll_remove_obj_type()')
663 header_txt.append('static void ll_remove_obj_type(XGL_VOID* pObj, XGL_OBJECT_TYPE objType) {')
664 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
665 header_txt.append(' objNode *pPrev = pObjectHead[objType];')
666 header_txt.append(' while (pTrav) {')
667 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
668 header_txt.append(' pPrev->pNextObj = pTrav->pNextObj;')
669 header_txt.append(' // update HEAD of Obj list as needed')
670 header_txt.append(' if (pObjectHead[objType] == pTrav)')
671 header_txt.append(' pObjectHead[objType] = pTrav->pNextObj;')
672 header_txt.append(' assert(numObjs[objType] > 0);')
673 header_txt.append(' numObjs[objType]--;')
674 header_txt.append(' char str[1024];')
675 header_txt.append(' sprintf(str, "OBJ[%llu] : DESTROY %s object %p", object_track_index++, string_XGL_OBJECT_TYPE(objType), (void*)pObj);')
676 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 -0600677 header_txt.append(' return;')
678 header_txt.append(' }')
679 header_txt.append(' pPrev = pTrav;')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700680 header_txt.append(' pTrav = pTrav->pNextObj;')
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600681 header_txt.append(' }')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700682 header_txt.append(' char str[1024];')
683 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));')
684 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_INTERNAL_ERROR, "OBJTRACK", str);')
685 header_txt.append('}')
686 header_txt.append('// Parse global list to find obj type, then remove obj from obj type list, finally')
687 header_txt.append('// remove obj from global list')
688 header_txt.append('static void ll_destroy_obj(XGL_VOID* pObj) {')
689 header_txt.append(' objNode *pTrav = pGlobalHead;')
690 header_txt.append(' objNode *pPrev = pGlobalHead;')
691 header_txt.append(' while (pTrav) {')
692 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
693 header_txt.append(' ll_remove_obj_type(pObj, pTrav->obj.objType);')
694 header_txt.append(' pPrev->pNextGlobal = pTrav->pNextGlobal;')
695 header_txt.append(' // update HEAD of global list if needed')
696 header_txt.append(' if (pGlobalHead == pTrav)')
697 header_txt.append(' pGlobalHead = pTrav->pNextGlobal;')
698 header_txt.append(' free(pTrav);')
699 header_txt.append(' assert(numTotalObjs > 0);')
700 header_txt.append(' numTotalObjs--;')
701 header_txt.append(' char str[1024];')
702 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));')
703 header_txt.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_NONE, "OBJTRACK", str);')
704 header_txt.append(' return;')
705 header_txt.append(' }')
706 header_txt.append(' pPrev = pTrav;')
707 header_txt.append(' pTrav = pTrav->pNextGlobal;')
708 header_txt.append(' }')
709 header_txt.append(' char str[1024];')
710 header_txt.append(' sprintf(str, "Unable to remove obj %p. Was it created? Has it already been destroyed?", pObj);')
711 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 -0600712 header_txt.append('}')
713
714 return "\n".join(header_txt)
715
716 def generate_body(self):
717 body = [self._generate_layer_dispatch_table(),
718 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "objecttracker"),
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700719 self._generate_extensions(),
720 self._generate_layer_gpa_function(extensions=['objTrackGetObjectCount', 'objTrackGetObjects'])]
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600721
722 return "\n\n".join(body)
Courtney Goeltzenleuchtere6094fc2014-11-18 10:40:29 -0700723
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600724def main():
725 subcommands = {
726 "layer-funcs" : LayerFuncsSubcommand,
727 "layer-dispatch" : LayerDispatchSubcommand,
728 "generic-layer" : GenericLayerSubcommand,
729 "api-dump" : ApiDumpSubcommand,
Tobin Ehlis574b0142014-11-12 13:11:15 -0700730 "api-dump-file" : ApiDumpFileSubcommand,
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600731 "object-tracker" : ObjectTrackerSubcommand,
732 }
733
734 if len(sys.argv) < 2 or sys.argv[1] not in subcommands:
735 print("Usage: %s <subcommand> [options]" % sys.argv[0])
736 print
737 print("Available sucommands are: %s" % " ".join(subcommands))
738 exit(1)
739
740 subcmd = subcommands[sys.argv[1]](sys.argv[2:])
741 subcmd.run()
742
743if __name__ == "__main__":
744 main()