blob: 10f7489df01fd584b4db9c4639d4f8e834ee64b5 [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:
Jon Ashburn1f7e2d72014-12-12 16:10:45 -0700126 return ("%i", "*(%s)" % name)
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600127 return ("%i", name)
Tobin Ehlis0a1e06d2014-11-11 17:28:22 -0700128 # 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 -0700129 if "XGL_FORMAT" == xgl_type:
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700130 if cpp:
131 return ("%p", "&%s" % name)
132 return ("{%s.channelFormat = %%s, %s.numericFormat = %%s}" % (name, name), "string_XGL_CHANNEL_FORMAT(%s.channelFormat), string_XGL_NUM_FORMAT(%s.numericFormat)" % (name, name))
Tobin Ehlisa554dc32014-11-19 15:52:46 -0700133 if output_param:
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600134 return ("%p", "(void*)*%s" % name)
Jon Ashburn1f7e2d72014-12-12 16:10:45 -0700135 return ("%p", "(void*)(%s)" % name)
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600136
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700137 def _gen_layer_dbg_callback_header(self):
138 cbh_body = []
139 cbh_body.append('static XGL_LAYER_DBG_FUNCTION_NODE *pDbgFunctionHead = NULL;')
140 cbh_body.append('// Utility function to handle reporting')
141 cbh_body.append('// If callbacks are enabled, use them, otherwise use printf')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600142 cbh_body.append('static void layerCbMsg(XGL_DBG_MSG_TYPE msgType,')
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700143 cbh_body.append(' XGL_VALIDATION_LEVEL validationLevel,')
144 cbh_body.append(' XGL_BASE_OBJECT srcObject,')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600145 cbh_body.append(' size_t location,')
146 cbh_body.append(' int32_t msgCode,')
147 cbh_body.append(' const char* pLayerPrefix,')
148 cbh_body.append(' const char* pMsg)')
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700149 cbh_body.append('{')
150 cbh_body.append(' XGL_LAYER_DBG_FUNCTION_NODE *pTrav = pDbgFunctionHead;')
151 cbh_body.append(' if (pTrav) {')
152 cbh_body.append(' while (pTrav) {')
153 cbh_body.append(' pTrav->pfnMsgCallback(msgType, validationLevel, srcObject, location, msgCode, pMsg, pTrav->pUserData);')
154 cbh_body.append(' pTrav = pTrav->pNext;')
155 cbh_body.append(' }')
156 cbh_body.append(' }')
157 cbh_body.append(' else {')
158 cbh_body.append(' switch (msgType) {')
159 cbh_body.append(' case XGL_DBG_MSG_ERROR:')
160 cbh_body.append(' printf("{%s}ERROR : %s\\n", pLayerPrefix, pMsg);')
161 cbh_body.append(' break;')
162 cbh_body.append(' case XGL_DBG_MSG_WARNING:')
163 cbh_body.append(' printf("{%s}WARN : %s\\n", pLayerPrefix, pMsg);')
164 cbh_body.append(' break;')
165 cbh_body.append(' case XGL_DBG_MSG_PERF_WARNING:')
166 cbh_body.append(' printf("{%s}PERF_WARN : %s\\n", pLayerPrefix, pMsg);')
167 cbh_body.append(' break;')
168 cbh_body.append(' default:')
169 cbh_body.append(' printf("{%s}INFO : %s\\n", pLayerPrefix, pMsg);')
170 cbh_body.append(' break;')
171 cbh_body.append(' }')
172 cbh_body.append(' }')
173 cbh_body.append('}')
174 return "\n".join(cbh_body)
175
176 def _gen_layer_dbg_callback_register(self):
177 r_body = []
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600178 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 -0700179 r_body.append('{')
180 r_body.append(' // This layer intercepts callbacks')
181 r_body.append(' XGL_LAYER_DBG_FUNCTION_NODE *pNewDbgFuncNode = (XGL_LAYER_DBG_FUNCTION_NODE*)malloc(sizeof(XGL_LAYER_DBG_FUNCTION_NODE));')
182 r_body.append(' if (!pNewDbgFuncNode)')
183 r_body.append(' return XGL_ERROR_OUT_OF_MEMORY;')
184 r_body.append(' pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;')
185 r_body.append(' pNewDbgFuncNode->pUserData = pUserData;')
186 r_body.append(' pNewDbgFuncNode->pNext = pDbgFunctionHead;')
187 r_body.append(' pDbgFunctionHead = pNewDbgFuncNode;')
188 r_body.append(' XGL_RESULT result = nextTable.DbgRegisterMsgCallback(pfnMsgCallback, pUserData);')
189 r_body.append(' return result;')
190 r_body.append('}')
191 return "\n".join(r_body)
192
193 def _gen_layer_dbg_callback_unregister(self):
194 ur_body = []
195 ur_body.append('XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglDbgUnregisterMsgCallback(XGL_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback)')
196 ur_body.append('{')
197 ur_body.append(' XGL_LAYER_DBG_FUNCTION_NODE *pTrav = pDbgFunctionHead;')
198 ur_body.append(' XGL_LAYER_DBG_FUNCTION_NODE *pPrev = pTrav;')
199 ur_body.append(' while (pTrav) {')
200 ur_body.append(' if (pTrav->pfnMsgCallback == pfnMsgCallback) {')
201 ur_body.append(' pPrev->pNext = pTrav->pNext;')
202 ur_body.append(' if (pDbgFunctionHead == pTrav)')
203 ur_body.append(' pDbgFunctionHead = pTrav->pNext;')
204 ur_body.append(' free(pTrav);')
205 ur_body.append(' break;')
206 ur_body.append(' }')
207 ur_body.append(' pPrev = pTrav;')
208 ur_body.append(' pTrav = pTrav->pNext;')
209 ur_body.append(' }')
210 ur_body.append(' XGL_RESULT result = nextTable.DbgUnregisterMsgCallback(pfnMsgCallback);')
211 ur_body.append(' return result;')
212 ur_body.append('}')
213 return "\n".join(ur_body)
214
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -0700215 def _generate_dispatch_entrypoints(self, qual="", layer="Generic", no_addr=False):
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600216 if qual:
217 qual += " "
218
Tobin Ehlis907a0522014-11-25 16:59:27 -0700219 layer_name = layer
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -0700220 if no_addr:
221 layer_name = "%sNoAddr" % layer
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700222 if 'Cpp' in layer_name:
223 layer_name = "APIDumpNoAddrCpp"
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600224 funcs = []
225 for proto in self.protos:
226 if proto.name != "GetProcAddr" and proto.name != "InitAndEnumerateGpus":
Tobin Ehlis907a0522014-11-25 16:59:27 -0700227 if "Generic" == layer:
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600228 decl = proto.c_func(prefix="xgl", attr="XGLAPI")
229 param0_name = proto.params[0].name
230 ret_val = ''
231 stmt = ''
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600232 if proto.ret != "void":
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600233 ret_val = "XGL_RESULT result = "
234 stmt = " return result;\n"
Ian Elliott81ac44c2015-01-13 17:52:38 -0700235 if 'WsiX11AssociateConnection' == proto.name:
236 funcs.append("#if !defined(_WIN32)")
Jon Ashburn451c16f2014-11-25 11:08:42 -0700237 if proto.name == "EnumerateLayers":
238 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
239 funcs.append('%s%s\n'
240 '{\n'
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700241 ' char str[1024];\n'
Jon Ashburn451c16f2014-11-25 11:08:42 -0700242 ' if (gpu != NULL) {\n'
243 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700244 ' sprintf(str, "At start of layered %s\\n");\n'
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600245 ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpu, 0, 0, (char *) "GENERIC", (char *) str);\n'
Jon Ashburn451c16f2014-11-25 11:08:42 -0700246 ' pCurObj = gpuw;\n'
Ian Elliott81ac44c2015-01-13 17:52:38 -0700247 ' loader_platform_thread_once(&tabOnce, initLayerTable);\n'
Jon Ashburn451c16f2014-11-25 11:08:42 -0700248 ' %snextTable.%s;\n'
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700249 ' sprintf(str, "Completed layered %s\\n");\n'
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600250 ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpu, 0, 0, (char *) "GENERIC", (char *) str);\n'
Jon Ashburn451c16f2014-11-25 11:08:42 -0700251 ' fflush(stdout);\n'
252 ' %s'
253 ' } else {\n'
254 ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n'
255 ' return XGL_ERROR_INVALID_POINTER;\n'
256 ' // This layer compatible with all GPUs\n'
257 ' *pOutLayerCount = 1;\n'
Chia-I Wua837c522014-12-16 10:47:33 +0800258 ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n'
Jon Ashburn451c16f2014-11-25 11:08:42 -0700259 ' return XGL_SUCCESS;\n'
260 ' }\n'
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -0700261 '}' % (qual, decl, proto.params[0].name, proto.name, ret_val, c_call, proto.name, stmt, layer_name))
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700262 elif 'DbgRegisterMsgCallback' == proto.name:
263 funcs.append(self._gen_layer_dbg_callback_register())
264 elif 'DbgUnregisterMsgCallback' == proto.name:
265 funcs.append(self._gen_layer_dbg_callback_unregister())
Jon Ashburn451c16f2014-11-25 11:08:42 -0700266 elif proto.params[0].ty != "XGL_PHYSICAL_GPU":
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600267 funcs.append('%s%s\n'
268 '{\n'
269 ' %snextTable.%s;\n'
270 '%s'
271 '}' % (qual, decl, ret_val, proto.c_call(), stmt))
272 else:
273 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
274 funcs.append('%s%s\n'
275 '{\n'
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700276 ' char str[1024];'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600277 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700278 ' sprintf(str, "At start of layered %s\\n");\n'
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600279 ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpuw, 0, 0, (char *) "GENERIC", (char *) str);\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600280 ' pCurObj = gpuw;\n'
Ian Elliott81ac44c2015-01-13 17:52:38 -0700281 ' loader_platform_thread_once(&tabOnce, initLayerTable);\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600282 ' %snextTable.%s;\n'
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700283 ' sprintf(str, "Completed layered %s\\n");\n'
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600284 ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpuw, 0, 0, (char *) "GENERIC", (char *) str);\n'
Courtney Goeltzenleuchtere6094fc2014-11-18 10:40:29 -0700285 ' fflush(stdout);\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600286 '%s'
287 '}' % (qual, decl, proto.params[0].name, proto.name, ret_val, c_call, proto.name, stmt))
Ian Elliott81ac44c2015-01-13 17:52:38 -0700288 if 'WsiX11QueuePresent' == proto.name:
289 funcs.append("#endif")
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700290 elif "APIDumpCpp" in layer:
291 decl = proto.c_func(prefix="xgl", attr="XGLAPI")
292 param0_name = proto.params[0].name
293 ret_val = ''
294 stmt = ''
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700295 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 -0700296 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 -0700297 if 'WsiX11CreatePresentableImage' in proto.name or 'AllocDescriptorSets' in proto.name:
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700298 create_params = -2
299 elif 'Create' in proto.name or 'Alloc' in proto.name or 'MapMemory' in proto.name:
300 create_params = -1
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600301 if proto.ret != "void":
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700302 ret_val = "XGL_RESULT result = "
303 stmt = " return result;\n"
304 f_open = ''
305 f_close = ''
306 if "File" in layer:
307 file_mode = "a"
308 if 'CreateDevice' in proto.name:
309 file_mode = "w"
Ian Elliott81ac44c2015-01-13 17:52:38 -0700310 f_open = 'loader_platform_thread_lock_mutex(&printLock);\n pOutFile = fopen(outFileName, "%s");\n ' % (file_mode)
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700311 log_func = 'fprintf(pOutFile, "t{%%u} xgl%s(' % proto.name
Ian Elliott81ac44c2015-01-13 17:52:38 -0700312 f_close = '\n fclose(pOutFile);\n loader_platform_thread_unlock_mutex(&printLock);'
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700313 else:
Ian Elliott81ac44c2015-01-13 17:52:38 -0700314 f_open = 'loader_platform_thread_lock_mutex(&printLock);\n '
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700315 log_func = 'cout << "t{" << getTIDIndex() << "} xgl%s(' % proto.name
Ian Elliott81ac44c2015-01-13 17:52:38 -0700316 f_close = '\n loader_platform_thread_unlock_mutex(&printLock);'
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700317 pindex = 0
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700318 prev_count_name = ''
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700319 for p in proto.params:
320 # TODO : Need to handle xglWsiX11CreatePresentableImage for which the last 2 params are returned vals
321 cp = False
322 if 0 != create_params:
323 # If this is any of the N last params of the func, treat as output
324 for y in range(-1, create_params-1, -1):
325 if p.name == proto.params[y].name:
326 cp = True
327 (pft, pfi) = self._get_printf_params(p.ty, p.name, cp, cpp=True)
328 if no_addr and "%p" == pft:
329 (pft, pfi) = ("%s", '"addr"')
330 log_func += '%s = " << %s << ", ' % (p.name, pfi)
331 #print_vals += ', %s' % (pfi)
332 # TODO : Just want this to be simple check for params of STRUCT type
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700333 #if "pCreateInfo" in p.name or ('const' in p.ty and '*' in p.ty and False not in [tmp_ty not in p.ty for tmp_ty in ['char', 'void', 'int', 'XGL_CMD_BUFFER', 'XGL_QUEUE_SEMAPHORE', 'XGL_FENCE', 'XGL_SAMPLER']]):
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700334 if prev_count_name != '' and (prev_count_name.strip('Count')[1:] in p.name or 'slotCount' == prev_count_name):
335 sp_param_dict[pindex] = prev_count_name
336 elif 'pDescriptorSets' == p.name and proto.params[-1].name == 'pCount':
337 sp_param_dict[pindex] = '*pCount'
Tobin Ehlisfc04b892015-01-22 12:29:31 -0700338 elif 'Wsi' not in proto.name and xgl_helper.is_type(p.ty.strip('*').strip('const '), 'struct'):
339 sp_param_dict[pindex] = 'index'
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700340 pindex += 1
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700341 if p.name.endswith('Count'):
342 if '*' in p.ty:
343 prev_count_name = "*%s" % p.name
344 else:
345 prev_count_name = p.name
346 else:
347 prev_count_name = ''
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700348 log_func = log_func.strip(', ')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600349 if proto.ret != "void":
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700350 log_func += ') = " << string_XGL_RESULT((XGL_RESULT)result) << "\\n"'
351 #print_vals += ', string_XGL_RESULT_CODE(result)'
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700352 else:
353 log_func += ')\\n"'
354 log_func += ';'
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700355 if len(sp_param_dict) > 0:
356 i_decl = False
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700357 log_func += '\n string tmp_str;'
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700358 for sp_index in sp_param_dict:
359 if 'index' == sp_param_dict[sp_index]:
360 cis_print_func = 'xgl_print_%s' % (proto.params[sp_index].ty.strip('const ').strip('*').lower())
361 log_func += '\n if (%s) {' % (proto.params[sp_index].name)
362 log_func += '\n tmp_str = %s(%s, " ");' % (cis_print_func, proto.params[sp_index].name)
363 if "File" in layer:
364 if no_addr:
365 log_func += '\n fprintf(pOutFile, " %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name)
366 else:
367 log_func += '\n fprintf(pOutFile, " %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name)
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700368 else:
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700369 if no_addr:
370 #log_func += '\n printf(" %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name)
371 log_func += '\n cout << " %s (addr)" << endl << tmp_str << endl;' % (proto.params[sp_index].name)
372 else:
373 #log_func += '\n printf(" %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name)
374 log_func += '\n cout << " %s (" << %s << ")" << endl << tmp_str << endl;' % (proto.params[sp_index].name, proto.params[sp_index].name)
375 #log_func += '\n fflush(stdout);'
376 log_func += '\n }'
377 else: # We have a count value stored to iterate over an array
378 print_cast = ''
379 print_func = ''
380 if xgl_helper.is_type(proto.params[sp_index].ty.strip('*').strip('const '), 'struct'):
381 print_cast = '&'
382 print_func = 'xgl_print_%s' % proto.params[sp_index].ty.strip('const ').strip('*').lower()
383 #cis_print_func = 'tmp_str = xgl_print_%s(&%s[i], " ");' % (proto.params[sp_index].ty.strip('const ').strip('*').lower(), proto.params[sp_index].name)
384# TODO : Need to display this address as a string
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700385 else:
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700386 print_cast = '(void*)'
387 print_func = 'string_convert_helper'
388 #cis_print_func = 'tmp_str = string_convert_helper((void*)%s[i], " ");' % proto.params[sp_index].name
389 cis_print_func = 'tmp_str = %s(%s%s[i], " ");' % (print_func, print_cast, proto.params[sp_index].name)
390# else:
391# cis_print_func = ''
392 if not i_decl:
393 log_func += '\n uint32_t i;'
394 i_decl = True
395 log_func += '\n for (i = 0; i < %s; i++) {' % (sp_param_dict[sp_index])
396 log_func += '\n %s' % (cis_print_func)
397 if "File" in layer:
398 if no_addr:
399 log_func += '\n fprintf(pOutFile, " %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name)
400 else:
401 log_func += '\n fprintf(pOutFile, " %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name)
402 else:
403 if no_addr:
404 #log_func += '\n printf(" %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name)
405 log_func += '\n cout << " %s[" << (uint32_t)i << "] (addr)" << endl << tmp_str << endl;' % (proto.params[sp_index].name)
406 else:
407 #log_func += '\n printf(" %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name)
408 #log_func += '\n cout << " %s[" << (uint32_t)i << "] (" << %s[i] << ")" << endl << tmp_str << endl;' % (proto.params[sp_index].name, proto.params[sp_index].name)
409 log_func += '\n cout << " %s[" << i << "] (" << %s%s[i] << ")" << endl << tmp_str << endl;' % (proto.params[sp_index].name, print_cast, proto.params[sp_index].name)
410 #log_func += '\n fflush(stdout);'
411 log_func += '\n }'
Ian Elliott81ac44c2015-01-13 17:52:38 -0700412 if 'WsiX11AssociateConnection' == proto.name:
413 funcs.append("#if !defined(_WIN32)")
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700414 if proto.name == "EnumerateLayers":
415 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
416 funcs.append('%s%s\n'
417 '{\n'
418 ' if (gpu != NULL) {\n'
419 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
420 ' pCurObj = gpuw;\n'
Ian Elliott81ac44c2015-01-13 17:52:38 -0700421 ' loader_platform_thread_once(&tabOnce, initLayerTable);\n'
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700422 ' %snextTable.%s;\n'
423 ' %s %s %s\n'
424 ' %s'
425 ' } else {\n'
426 ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n'
427 ' return XGL_ERROR_INVALID_POINTER;\n'
428 ' // This layer compatible with all GPUs\n'
429 ' *pOutLayerCount = 1;\n'
430 ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n'
431 ' return XGL_SUCCESS;\n'
432 ' }\n'
433 '}' % (qual, decl, proto.params[0].name, ret_val, c_call,f_open, log_func, f_close, stmt, layer_name))
434 elif proto.params[0].ty != "XGL_PHYSICAL_GPU":
435 funcs.append('%s%s\n'
436 '{\n'
437 ' %snextTable.%s;\n'
438 ' %s%s%s\n'
439 '%s'
440 '}' % (qual, decl, ret_val, proto.c_call(), f_open, log_func, f_close, stmt))
441 else:
442 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
443 funcs.append('%s%s\n'
444 '{\n'
445 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
446 ' pCurObj = gpuw;\n'
Ian Elliott81ac44c2015-01-13 17:52:38 -0700447 ' loader_platform_thread_once(&tabOnce, initLayerTable);\n'
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700448 ' %snextTable.%s;\n'
449 ' %s%s%s\n'
450 '%s'
451 '}' % (qual, decl, proto.params[0].name, ret_val, c_call, f_open, log_func, f_close, stmt))
Ian Elliott81ac44c2015-01-13 17:52:38 -0700452 if 'WsiX11QueuePresent' == proto.name:
453 funcs.append("#endif")
Tobin Ehlis907a0522014-11-25 16:59:27 -0700454 elif "APIDump" in layer:
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600455 decl = proto.c_func(prefix="xgl", attr="XGLAPI")
456 param0_name = proto.params[0].name
457 ret_val = ''
458 stmt = ''
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700459 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 -0700460 create_params = 0 # Num of params at end of function that are created and returned as output values
461 if 'WsiX11CreatePresentableImage' in proto.name:
462 create_params = -2
463 elif 'Create' in proto.name or 'Alloc' in proto.name or 'MapMemory' in proto.name:
464 create_params = -1
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600465 if proto.ret != "void":
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600466 ret_val = "XGL_RESULT result = "
467 stmt = " return result;\n"
Tobin Ehlis574b0142014-11-12 13:11:15 -0700468 f_open = ''
469 f_close = ''
Tobin Ehlis907a0522014-11-25 16:59:27 -0700470 if "File" in layer:
Tobin Ehlis1eba7792014-11-21 09:35:53 -0700471 file_mode = "a"
472 if 'CreateDevice' in proto.name:
473 file_mode = "w"
Ian Elliott81ac44c2015-01-13 17:52:38 -0700474 f_open = 'loader_platform_thread_lock_mutex(&printLock);\n pOutFile = fopen(outFileName, "%s");\n ' % (file_mode)
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700475 log_func = 'fprintf(pOutFile, "t{%%u} xgl%s(' % proto.name
Ian Elliott81ac44c2015-01-13 17:52:38 -0700476 f_close = '\n fclose(pOutFile);\n loader_platform_thread_unlock_mutex(&printLock);'
Tobin Ehlis574b0142014-11-12 13:11:15 -0700477 else:
Ian Elliott81ac44c2015-01-13 17:52:38 -0700478 f_open = 'loader_platform_thread_lock_mutex(&printLock);\n '
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700479 log_func = 'printf("t{%%u} xgl%s(' % proto.name
Ian Elliott81ac44c2015-01-13 17:52:38 -0700480 f_close = '\n loader_platform_thread_unlock_mutex(&printLock);'
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700481 print_vals = ', getTIDIndex()'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600482 pindex = 0
Tobin Ehlisc7e926b2014-12-18 15:20:05 -0700483 prev_count_name = ''
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600484 for p in proto.params:
Tobin Ehlisa554dc32014-11-19 15:52:46 -0700485 cp = False
486 if 0 != create_params:
487 # If this is any of the N last params of the func, treat as output
488 for y in range(-1, create_params-1, -1):
489 if p.name == proto.params[y].name:
490 cp = True
491 (pft, pfi) = self._get_printf_params(p.ty, p.name, cp)
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -0700492 if no_addr and "%p" == pft:
493 (pft, pfi) = ("%s", '"addr"')
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600494 log_func += '%s = %s, ' % (p.name, pft)
495 print_vals += ', %s' % (pfi)
Tobin Ehlisc7e926b2014-12-18 15:20:05 -0700496 # Catch array inputs that are bound by a "Count" param
497 if prev_count_name != '' and (prev_count_name.strip('Count')[1:] in p.name or 'slotCount' == prev_count_name):
498 sp_param_dict[pindex] = prev_count_name
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700499 elif 'pDescriptorSets' == p.name and proto.params[-1].name == 'pCount':
500 sp_param_dict[pindex] = '*pCount'
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700501 elif 'Wsi' not in proto.name and xgl_helper.is_type(p.ty.strip('*').strip('const '), 'struct'):
Tobin Ehlisc7e926b2014-12-18 15:20:05 -0700502 sp_param_dict[pindex] = 'index'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600503 pindex += 1
Tobin Ehlisc7e926b2014-12-18 15:20:05 -0700504 if p.name.endswith('Count'):
Courtney Goeltzenleuchter08cf7cc2015-01-13 15:32:18 -0700505 if '*' in p.ty:
506 prev_count_name = "*%s" % p.name
507 else:
508 prev_count_name = p.name
Tobin Ehlisc7e926b2014-12-18 15:20:05 -0700509 else:
510 prev_count_name = ''
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600511 log_func = log_func.strip(', ')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600512 if proto.ret != "void":
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600513 log_func += ') = %s\\n"'
Courtney Goeltzenleuchtere6094fc2014-11-18 10:40:29 -0700514 print_vals += ', string_XGL_RESULT(result)'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600515 else:
516 log_func += ')\\n"'
517 log_func = '%s%s);' % (log_func, print_vals)
Tobin Ehlisc7e926b2014-12-18 15:20:05 -0700518 if len(sp_param_dict) > 0:
519 i_decl = False
520 log_func += '\n char *pTmpStr = "";'
521 for sp_index in sorted(sp_param_dict):
522 # TODO : Clean this if/else block up, too much duplicated code
523 if 'index' == sp_param_dict[sp_index]:
524 cis_print_func = 'xgl_print_%s' % (proto.params[sp_index].ty.strip('const ').strip('*').lower())
525 log_func += '\n if (%s) {' % (proto.params[sp_index].name)
526 log_func += '\n pTmpStr = %s(%s, " ");' % (cis_print_func, proto.params[sp_index].name)
527 if "File" in layer:
528 if no_addr:
529 log_func += '\n fprintf(pOutFile, " %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name)
530 else:
531 log_func += '\n fprintf(pOutFile, " %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name)
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -0700532 else:
Tobin Ehlisc7e926b2014-12-18 15:20:05 -0700533 if no_addr:
534 log_func += '\n printf(" %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name)
535 else:
536 log_func += '\n printf(" %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name)
537 log_func += '\n fflush(stdout);'
538 log_func += '\n free(pTmpStr);\n }'
539 else: # should have a count value stored to iterate over array
540 if xgl_helper.is_type(proto.params[sp_index].ty.strip('*').strip('const '), 'struct'):
541 cis_print_func = 'pTmpStr = xgl_print_%s(&%s[i], " ");' % (proto.params[sp_index].ty.strip('const ').strip('*').lower(), proto.params[sp_index].name)
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -0700542 else:
Tobin Ehlisc7e926b2014-12-18 15:20:05 -0700543 cis_print_func = 'pTmpStr = (char*)malloc(sizeof(char));\n sprintf(pTmpStr, " %%p", %s[i]);' % proto.params[sp_index].name
544 if not i_decl:
545 log_func += '\n uint32_t i;'
546 i_decl = True
Jon Ashburn48637592015-01-14 08:52:37 -0700547 log_func += '\n for (i = 0; i < %s; i++) {' % (sp_param_dict[sp_index])
Tobin Ehlisc7e926b2014-12-18 15:20:05 -0700548 log_func += '\n %s' % (cis_print_func)
549 if "File" in layer:
550 if no_addr:
551 log_func += '\n fprintf(pOutFile, " %s[%%i] (addr)\\n%%s\\n", i, pTmpStr);' % (proto.params[sp_index].name)
552 else:
553 log_func += '\n fprintf(pOutFile, " %s[%%i] (%%p)\\n%%s\\n", i, (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name)
554 else:
555 if no_addr:
556 log_func += '\n printf(" %s[%%i] (addr)\\n%%s\\n", i, pTmpStr);' % (proto.params[sp_index].name)
557 else:
558 log_func += '\n printf(" %s[%%i] (%%p)\\n%%s\\n", i, (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name)
559 log_func += '\n fflush(stdout);'
560 log_func += '\n free(pTmpStr);\n }'
Ian Elliott81ac44c2015-01-13 17:52:38 -0700561 if 'WsiX11AssociateConnection' == proto.name:
562 funcs.append("#if !defined(_WIN32)")
Jon Ashburn451c16f2014-11-25 11:08:42 -0700563 if proto.name == "EnumerateLayers":
564 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
565 funcs.append('%s%s\n'
566 '{\n'
567 ' if (gpu != NULL) {\n'
568 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
569 ' pCurObj = gpuw;\n'
Ian Elliott81ac44c2015-01-13 17:52:38 -0700570 ' loader_platform_thread_once(&tabOnce, initLayerTable);\n'
Jon Ashburn451c16f2014-11-25 11:08:42 -0700571 ' %snextTable.%s;\n'
572 ' %s %s %s\n'
573 ' %s'
574 ' } else {\n'
575 ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n'
576 ' return XGL_ERROR_INVALID_POINTER;\n'
577 ' // This layer compatible with all GPUs\n'
578 ' *pOutLayerCount = 1;\n'
Chia-I Wua837c522014-12-16 10:47:33 +0800579 ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n'
Jon Ashburn451c16f2014-11-25 11:08:42 -0700580 ' return XGL_SUCCESS;\n'
581 ' }\n'
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -0700582 '}' % (qual, decl, proto.params[0].name, ret_val, c_call,f_open, log_func, f_close, stmt, layer_name))
Jon Ashburn451c16f2014-11-25 11:08:42 -0700583 elif proto.params[0].ty != "XGL_PHYSICAL_GPU":
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600584 funcs.append('%s%s\n'
585 '{\n'
586 ' %snextTable.%s;\n'
Tobin Ehlis574b0142014-11-12 13:11:15 -0700587 ' %s%s%s\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600588 '%s'
Tobin Ehlis574b0142014-11-12 13:11:15 -0700589 '}' % (qual, decl, ret_val, proto.c_call(), f_open, log_func, f_close, stmt))
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600590 else:
591 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
592 funcs.append('%s%s\n'
593 '{\n'
594 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
595 ' pCurObj = gpuw;\n'
Ian Elliott81ac44c2015-01-13 17:52:38 -0700596 ' loader_platform_thread_once(&tabOnce, initLayerTable);\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600597 ' %snextTable.%s;\n'
Tobin Ehlis574b0142014-11-12 13:11:15 -0700598 ' %s%s%s\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600599 '%s'
Tobin Ehlis574b0142014-11-12 13:11:15 -0700600 '}' % (qual, decl, proto.params[0].name, ret_val, c_call, f_open, log_func, f_close, stmt))
Ian Elliott81ac44c2015-01-13 17:52:38 -0700601 if 'WsiX11QueuePresent' == proto.name:
602 funcs.append("#endif")
Tobin Ehlis907a0522014-11-25 16:59:27 -0700603 elif "ObjectTracker" == layer:
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700604 obj_type_mapping = {base_t : base_t.replace("XGL_", "XGL_OBJECT_TYPE_") for base_t in xgl.object_type_list}
605 # For the various "super-types" we have to use function to distinguish sub type
606 for obj_type in ["XGL_BASE_OBJECT", "XGL_OBJECT", "XGL_DYNAMIC_STATE_OBJECT"]:
607 obj_type_mapping[obj_type] = "ll_get_obj_type(object)"
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700608
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600609 decl = proto.c_func(prefix="xgl", attr="XGLAPI")
610 param0_name = proto.params[0].name
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700611 p0_type = proto.params[0].ty.strip('*').strip('const ')
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600612 create_line = ''
613 destroy_line = ''
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700614 if 'DbgRegisterMsgCallback' in proto.name:
615 using_line = ' // This layer intercepts callbacks\n'
616 using_line += ' XGL_LAYER_DBG_FUNCTION_NODE *pNewDbgFuncNode = (XGL_LAYER_DBG_FUNCTION_NODE*)malloc(sizeof(XGL_LAYER_DBG_FUNCTION_NODE));\n'
617 using_line += ' if (!pNewDbgFuncNode)\n'
618 using_line += ' return XGL_ERROR_OUT_OF_MEMORY;\n'
619 using_line += ' pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;\n'
620 using_line += ' pNewDbgFuncNode->pUserData = pUserData;\n'
621 using_line += ' pNewDbgFuncNode->pNext = pDbgFunctionHead;\n'
622 using_line += ' pDbgFunctionHead = pNewDbgFuncNode;\n'
623 elif 'DbgUnregisterMsgCallback' in proto.name:
624 using_line = ' XGL_LAYER_DBG_FUNCTION_NODE *pTrav = pDbgFunctionHead;\n'
625 using_line += ' XGL_LAYER_DBG_FUNCTION_NODE *pPrev = pTrav;\n'
626 using_line += ' while (pTrav) {\n'
627 using_line += ' if (pTrav->pfnMsgCallback == pfnMsgCallback) {\n'
628 using_line += ' pPrev->pNext = pTrav->pNext;\n'
629 using_line += ' if (pDbgFunctionHead == pTrav)\n'
630 using_line += ' pDbgFunctionHead = pTrav->pNext;\n'
631 using_line += ' free(pTrav);\n'
632 using_line += ' break;\n'
633 using_line += ' }\n'
634 using_line += ' pPrev = pTrav;\n'
635 using_line += ' pTrav = pTrav->pNext;\n'
636 using_line += ' }\n'
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700637 # Special cases for API funcs that don't use an object as first arg
638 elif True in [no_use_proto in proto.name for no_use_proto in ['GlobalOption', 'CreateInstance']]:
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600639 using_line = ''
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700640 else:
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600641 using_line = ' ll_increment_use_count((void*)%s, %s);\n' % (param0_name, obj_type_mapping[p0_type])
Tobin Ehlis235c20e2015-01-16 08:56:30 -0700642 if 'QueueSubmit' in proto.name:
643 using_line += ' set_status((void*)fence, XGL_OBJECT_TYPE_FENCE, OBJSTATUS_FENCE_IS_SUBMITTED);\n'
644 elif 'GetFenceStatus' in proto.name:
645 using_line += ' // Warn if submitted_flag is not set\n'
Mark Lobodzinski01552702015-02-03 10:06:31 -0600646 using_line += ' validate_status((void*)fence, XGL_OBJECT_TYPE_FENCE, OBJSTATUS_FENCE_IS_SUBMITTED, XGL_DBG_MSG_ERROR, OBJTRACK_INVALID_FENCE, "Status Requested for Unsubmitted Fence");\n'
647 elif 'EndCommandBuffer' in proto.name:
648 using_line += ' reset_status((void*)cmdBuffer, XGL_OBJECT_TYPE_CMD_BUFFER, (OBJSTATUS_VIEWPORT_BOUND |\n'
649 using_line += ' OBJSTATUS_RASTER_BOUND |\n'
650 using_line += ' OBJSTATUS_COLOR_BLEND_BOUND |\n'
651 using_line += ' OBJSTATUS_DEPTH_STENCIL_BOUND));\n'
652 elif 'CmdBindDynamicStateObject' in proto.name:
653 using_line += ' track_object_status((void*)cmdBuffer, stateBindPoint);\n'
654 elif 'CmdDraw' in proto.name:
655 using_line += ' validate_draw_state_flags((void *)cmdBuffer);\n'
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700656 if 'AllocDescriptor' in proto.name: # Allocates array of DSs
657 create_line = ' for (uint32_t i; i < *pCount; i++) {\n'
658 create_line += ' ll_insert_obj((void*)pDescriptorSets[i], XGL_OBJECT_TYPE_DESCRIPTOR_SET);\n'
659 create_line += ' }\n'
660 elif 'Create' in proto.name or 'Alloc' in proto.name:
661 create_line = ' ll_insert_obj((void*)*%s, %s);\n' % (proto.params[-1].name, obj_type_mapping[proto.params[-1].ty.strip('*').strip('const ')])
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700662 if 'DestroyObject' in proto.name:
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600663 destroy_line = ' ll_destroy_obj((void*)%s);\n' % (param0_name)
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700664 using_line = ''
665 else:
666 if 'Destroy' in proto.name or 'Free' in proto.name:
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600667 destroy_line = ' ll_remove_obj_type((void*)%s, %s);\n' % (param0_name, obj_type_mapping[p0_type])
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700668 using_line = ''
669 if 'DestroyDevice' in proto.name:
670 destroy_line += ' // Report any remaining objects in LL\n objNode *pTrav = pGlobalHead;\n while (pTrav) {\n'
671 destroy_line += ' char str[1024];\n'
672 destroy_line += ' sprintf(str, "OBJ ERROR : %s object %p has not been destroyed (was used %lu times).", string_XGL_OBJECT_TYPE(pTrav->obj.objType), pTrav->obj.pObj, pTrav->obj.numUses);\n'
673 destroy_line += ' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, device, 0, OBJTRACK_OBJECT_LEAK, "OBJTRACK", str);\n'
674 destroy_line += ' pTrav = pTrav->pNextGlobal;\n }\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600675 ret_val = ''
676 stmt = ''
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600677 if proto.ret != "void":
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600678 ret_val = "XGL_RESULT result = "
679 stmt = " return result;\n"
Ian Elliott81ac44c2015-01-13 17:52:38 -0700680 if 'WsiX11AssociateConnection' == proto.name:
681 funcs.append("#if !defined(_WIN32)")
Jon Ashburn451c16f2014-11-25 11:08:42 -0700682 if proto.name == "EnumerateLayers":
683 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
684 funcs.append('%s%s\n'
685 '{\n'
686 ' if (gpu != NULL) {\n'
687 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
688 ' %s'
689 ' pCurObj = gpuw;\n'
Ian Elliott81ac44c2015-01-13 17:52:38 -0700690 ' loader_platform_thread_once(&tabOnce, initLayerTable);\n'
Jon Ashburn451c16f2014-11-25 11:08:42 -0700691 ' %snextTable.%s;\n'
692 ' %s%s'
693 ' %s'
694 ' } else {\n'
695 ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n'
696 ' return XGL_ERROR_INVALID_POINTER;\n'
697 ' // This layer compatible with all GPUs\n'
698 ' *pOutLayerCount = 1;\n'
Chia-I Wua837c522014-12-16 10:47:33 +0800699 ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n'
Jon Ashburn451c16f2014-11-25 11:08:42 -0700700 ' return XGL_SUCCESS;\n'
701 ' }\n'
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -0700702 '}' % (qual, decl, proto.params[0].name, using_line, ret_val, c_call, create_line, destroy_line, stmt, layer_name))
Jon Ashburn451c16f2014-11-25 11:08:42 -0700703 elif proto.params[0].ty != "XGL_PHYSICAL_GPU":
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600704 funcs.append('%s%s\n'
705 '{\n'
706 '%s'
707 ' %snextTable.%s;\n'
708 '%s%s'
709 '%s'
710 '}' % (qual, decl, using_line, ret_val, proto.c_call(), create_line, destroy_line, stmt))
711 else:
712 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
713 funcs.append('%s%s\n'
714 '{\n'
715 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
716 '%s'
717 ' pCurObj = gpuw;\n'
Ian Elliott81ac44c2015-01-13 17:52:38 -0700718 ' loader_platform_thread_once(&tabOnce, initLayerTable);\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600719 ' %snextTable.%s;\n'
720 '%s%s'
721 '%s'
722 '}' % (qual, decl, proto.params[0].name, using_line, ret_val, c_call, create_line, destroy_line, stmt))
Ian Elliott81ac44c2015-01-13 17:52:38 -0700723 if 'WsiX11QueuePresent' == proto.name:
724 funcs.append("#endif")
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700725 elif "ParamChecker" == layer:
726 # TODO : Need to fix up the non-else cases below to do param checking as well
727 decl = proto.c_func(prefix="xgl", attr="XGLAPI")
728 param0_name = proto.params[0].name
729 ret_val = ''
730 stmt = ''
731 param_checks = []
732 # Add code to check enums and structs
733 # TODO : Currently only validating enum values, need to validate everything
734 str_decl = False
Tobin Ehlis773371f2014-12-18 13:51:21 -0700735 prev_count_name = ''
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700736 for p in proto.params:
737 if xgl_helper.is_type(p.ty.strip('*').strip('const '), 'enum'):
738 if not str_decl:
739 param_checks.append(' char str[1024];')
740 str_decl = True
741 param_checks.append(' if (!validate_%s(%s)) {' % (p.ty, p.name))
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700742 param_checks.append(' sprintf(str, "Parameter %s to function %s has invalid value of %%i.", (int)%s);' % (p.name, proto.name, p.name))
743 param_checks.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, 1, "PARAMCHECK", str);')
744 param_checks.append(' }')
745 elif xgl_helper.is_type(p.ty.strip('*').strip('const '), 'struct') and 'const' in p.ty:
Tobin Ehlis773371f2014-12-18 13:51:21 -0700746 is_array = False
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700747 if not str_decl:
748 param_checks.append(' char str[1024];')
749 str_decl = True
750 if '*' in p.ty: # First check for null ptr
Tobin Ehlis773371f2014-12-18 13:51:21 -0700751 # If this is an input array, parse over all of the array elements
752 if prev_count_name != '' and (prev_count_name.strip('Count')[1:] in p.name or 'slotCount' == prev_count_name):
753 #if 'pImageViews' in p.name:
754 is_array = True
755 param_checks.append(' uint32_t i;')
756 param_checks.append(' for (i = 0; i < %s; i++) {' % prev_count_name)
757 param_checks.append(' if (!xgl_validate_%s(&%s[i])) {' % (p.ty.strip('*').strip('const ').lower(), p.name))
758 param_checks.append(' sprintf(str, "Parameter %s[%%i] to function %s contains an invalid value.", i);' % (p.name, proto.name))
759 param_checks.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, 1, "PARAMCHECK", str);')
760 param_checks.append(' }')
761 param_checks.append(' }')
762 else:
763 param_checks.append(' if (!%s) {' % p.name)
764 param_checks.append(' sprintf(str, "Struct ptr parameter %s to function %s is NULL.");' % (p.name, proto.name))
765 param_checks.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, NULL, 0, 1, "PARAMCHECK", str);')
766 param_checks.append(' }')
767 param_checks.append(' else if (!xgl_validate_%s(%s)) {' % (p.ty.strip('*').strip('const ').lower(), p.name))
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700768 else:
769 param_checks.append(' if (!xgl_validate_%s(%s)) {' % (p.ty.strip('const ').lower(), p.name))
Tobin Ehlis773371f2014-12-18 13:51:21 -0700770 if not is_array:
771 param_checks.append(' sprintf(str, "Parameter %s to function %s contains an invalid value.");' % (p.name, proto.name))
772 param_checks.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, 1, "PARAMCHECK", str);')
773 param_checks.append(' }')
774 if p.name.endswith('Count'):
775 prev_count_name = p.name
776 else:
777 prev_count_name = ''
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600778 if proto.ret != "void":
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700779 ret_val = "XGL_RESULT result = "
780 stmt = " return result;\n"
Ian Elliott81ac44c2015-01-13 17:52:38 -0700781 if 'WsiX11AssociateConnection' == proto.name:
782 funcs.append("#if !defined(_WIN32)")
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700783 if proto.name == "EnumerateLayers":
784 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
785 funcs.append('%s%s\n'
786 '{\n'
787 ' char str[1024];\n'
788 ' if (gpu != NULL) {\n'
789 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
790 ' sprintf(str, "At start of layered %s\\n");\n'
791 ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpu, 0, 0, "PARAMCHECK", str);\n'
792 ' pCurObj = gpuw;\n'
Ian Elliott81ac44c2015-01-13 17:52:38 -0700793 ' loader_platform_thread_once(&tabOnce, initLayerTable);\n'
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700794 ' %snextTable.%s;\n'
795 ' sprintf(str, "Completed layered %s\\n");\n'
796 ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpu, 0, 0, "PARAMCHECK", str);\n'
797 ' fflush(stdout);\n'
798 ' %s'
799 ' } else {\n'
800 ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n'
801 ' return XGL_ERROR_INVALID_POINTER;\n'
802 ' // This layer compatible with all GPUs\n'
803 ' *pOutLayerCount = 1;\n'
804 ' strncpy(pOutLayers[0], "%s", maxStringSize);\n'
805 ' return XGL_SUCCESS;\n'
806 ' }\n'
807 '}' % (qual, decl, proto.params[0].name, proto.name, ret_val, c_call, proto.name, stmt, layer_name))
808 elif 'DbgRegisterMsgCallback' == proto.name:
809 funcs.append(self._gen_layer_dbg_callback_register())
810 elif 'DbgUnregisterMsgCallback' == proto.name:
811 funcs.append(self._gen_layer_dbg_callback_unregister())
812 elif proto.params[0].ty != "XGL_PHYSICAL_GPU":
813 funcs.append('%s%s\n'
814 '{\n'
815 '%s\n'
816 ' %snextTable.%s;\n'
817 '%s'
818 '}' % (qual, decl, "\n".join(param_checks), ret_val, proto.c_call(), stmt))
819 else:
820 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
821 funcs.append('%s%s\n'
822 '{\n'
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700823 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700824 ' pCurObj = gpuw;\n'
Ian Elliott81ac44c2015-01-13 17:52:38 -0700825 ' loader_platform_thread_once(&tabOnce, initLayerTable);\n'
Tobin Ehlis9d139862014-12-18 08:44:01 -0700826 '%s\n'
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700827 ' %snextTable.%s;\n'
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700828 '%s'
Tobin Ehlis9d139862014-12-18 08:44:01 -0700829 '}' % (qual, decl, proto.params[0].name, "\n".join(param_checks), ret_val, c_call, stmt))
Ian Elliott81ac44c2015-01-13 17:52:38 -0700830 if 'WsiX11QueuePresent' == proto.name:
831 funcs.append("#endif")
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600832
833 return "\n\n".join(funcs)
834
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700835 def _generate_extensions(self):
836 exts = []
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600837 exts.append('uint64_t objTrackGetObjectCount(XGL_OBJECT_TYPE type)')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700838 exts.append('{')
839 exts.append(' return (type == XGL_OBJECT_TYPE_ANY) ? numTotalObjs : numObjs[type];')
840 exts.append('}')
841 exts.append('')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600842 exts.append('XGL_RESULT objTrackGetObjects(XGL_OBJECT_TYPE type, uint64_t objCount, OBJTRACK_NODE* pObjNodeArray)')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700843 exts.append('{')
844 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 -0600845 exts.append(' bool32_t bAllObjs = (type == XGL_OBJECT_TYPE_ANY);')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700846 exts.append(' // Check the count first thing')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600847 exts.append(' uint64_t maxObjCount = (bAllObjs) ? numTotalObjs : numObjs[type];')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700848 exts.append(' if (objCount > maxObjCount) {')
849 exts.append(' char str[1024];')
850 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));')
851 exts.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, 0, 0, OBJTRACK_OBJCOUNT_MAX_EXCEEDED, "OBJTRACK", str);')
852 exts.append(' return XGL_ERROR_INVALID_VALUE;')
853 exts.append(' }')
854 exts.append(' objNode* pTrav = (bAllObjs) ? pGlobalHead : pObjectHead[type];')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600855 exts.append(' for (uint64_t i = 0; i < objCount; i++) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700856 exts.append(' if (!pTrav) {')
857 exts.append(' char str[1024];')
858 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);')
859 exts.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, 0, 0, OBJTRACK_INTERNAL_ERROR, "OBJTRACK", str);')
860 exts.append(' return XGL_ERROR_UNKNOWN;')
861 exts.append(' }')
862 exts.append(' memcpy(&pObjNodeArray[i], pTrav, sizeof(OBJTRACK_NODE));')
863 exts.append(' pTrav = (bAllObjs) ? pTrav->pNextGlobal : pTrav->pNextObj;')
864 exts.append(' }')
865 exts.append(' return XGL_SUCCESS;')
866 exts.append('}')
867
868 return "\n".join(exts)
869
Chia-I Wu706533e2015-01-05 13:18:57 +0800870 def _generate_layer_gpa_function(self, extensions=[]):
871 func_body = ["#include \"xgl_generic_intercept_proc_helper.h\""]
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600872 func_body.append("XGL_LAYER_EXPORT void* XGLAPI xglGetProcAddr(XGL_PHYSICAL_GPU gpu, const char* funcName)\n"
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600873 "{\n"
874 " XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) gpu;\n"
Chia-I Wu706533e2015-01-05 13:18:57 +0800875 " void* addr;\n"
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600876 " if (gpu == NULL)\n"
877 " return NULL;\n"
878 " pCurObj = gpuw;\n"
Ian Elliott81ac44c2015-01-13 17:52:38 -0700879 " loader_platform_thread_once(&tabOnce, initLayerTable);\n\n"
Chia-I Wu706533e2015-01-05 13:18:57 +0800880 " addr = layer_intercept_proc(funcName);\n"
881 " if (addr)\n"
882 " return addr;")
883
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700884 if 0 != len(extensions):
885 for ext_name in extensions:
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800886 func_body.append(' else if (!strncmp("%s", funcName, sizeof("%s")))\n'
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700887 ' return %s;' % (ext_name, ext_name, ext_name))
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600888 func_body.append(" else {\n"
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600889 " if (gpuw->pGPA == NULL)\n"
890 " return NULL;\n"
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700891 " return gpuw->pGPA((XGL_PHYSICAL_GPU)gpuw->nextObject, funcName);\n"
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600892 " }\n"
893 "}\n")
894 return "\n".join(func_body)
895
896 def _generate_layer_dispatch_table(self, prefix='xgl'):
Chia-I Wu0f65b1e2015-01-04 23:11:43 +0800897 func_body = ["#include \"xgl_dispatch_table_helper.h\""]
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600898 func_body.append('static void initLayerTable()\n'
899 '{\n'
Mark Lobodzinski953a1692015-01-09 15:12:03 -0600900 ' xglGetProcAddrType fpNextGPA;\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600901 ' fpNextGPA = pCurObj->pGPA;\n'
902 ' assert(fpNextGPA);\n');
903
Chia-I Wu0f65b1e2015-01-04 23:11:43 +0800904 func_body.append(" layer_initialize_dispatch_table(&nextTable, fpNextGPA, (XGL_PHYSICAL_GPU) pCurObj->nextObject);")
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600905 func_body.append("}\n")
906 return "\n".join(func_body)
907
Ian Elliott81ac44c2015-01-13 17:52:38 -0700908 def _generate_layer_dispatch_table_with_lock(self, prefix='xgl'):
909 func_body = ["#include \"xgl_dispatch_table_helper.h\""]
910 func_body.append('static void initLayerTable()\n'
911 '{\n'
912 ' xglGetProcAddrType fpNextGPA;\n'
913 ' fpNextGPA = pCurObj->pGPA;\n'
914 ' assert(fpNextGPA);\n');
915
916 func_body.append(" layer_initialize_dispatch_table(&nextTable, fpNextGPA, (XGL_PHYSICAL_GPU) pCurObj->nextObject);\n")
917 func_body.append(" if (!printLockInitialized)")
918 func_body.append(" {")
919 func_body.append(" // TODO/TBD: Need to delete this mutex sometime. How???")
920 func_body.append(" loader_platform_thread_create_mutex(&printLock);")
921 func_body.append(" printLockInitialized = 1;")
922 func_body.append(" }")
923 func_body.append("}\n")
924 return "\n".join(func_body)
925
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600926class LayerFuncsSubcommand(Subcommand):
927 def generate_header(self):
928 return '#include <xglLayer.h>\n#include "loader.h"'
929
930 def generate_body(self):
931 return self._generate_dispatch_entrypoints("static", True)
932
933class LayerDispatchSubcommand(Subcommand):
934 def generate_header(self):
935 return '#include "layer_wrappers.h"'
936
937 def generate_body(self):
938 return self._generate_layer_dispatch_table()
939
940class GenericLayerSubcommand(Subcommand):
941 def generate_header(self):
Ian Elliott81ac44c2015-01-13 17:52:38 -0700942 return '#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include "loader_platform.h"\n#include "xglLayer.h"\n\nstatic XGL_LAYER_DISPATCH_TABLE nextTable;\nstatic XGL_BASE_LAYER_OBJECT *pCurObj;\n\nstatic LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600943
944 def generate_body(self):
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700945 body = [self._gen_layer_dbg_callback_header(),
946 self._generate_layer_dispatch_table(),
Tobin Ehlis907a0522014-11-25 16:59:27 -0700947 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "Generic"),
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600948 self._generate_layer_gpa_function()]
949
950 return "\n\n".join(body)
951
952class ApiDumpSubcommand(Subcommand):
953 def generate_header(self):
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700954 header_txt = []
Ian Elliott81ac44c2015-01-13 17:52:38 -0700955 header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>')
956 header_txt.append('#include "loader_platform.h"')
957 header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper.h"\n')
958 header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;')
959 header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n')
960 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
961 header_txt.append('static int printLockInitialized = 0;')
962 header_txt.append('static loader_platform_thread_mutex printLock;\n')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700963 header_txt.append('#define MAX_TID 513')
Ian Elliott81ac44c2015-01-13 17:52:38 -0700964 header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700965 header_txt.append('static uint32_t maxTID = 0;')
966 header_txt.append('// Map actual TID to an index value and return that index')
967 header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs')
968 header_txt.append('static uint32_t getTIDIndex() {')
Ian Elliott81ac44c2015-01-13 17:52:38 -0700969 header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700970 header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {')
971 header_txt.append(' if (tid == tidMapping[i])')
972 header_txt.append(' return i;')
973 header_txt.append(' }')
974 header_txt.append(" // Don't yet have mapping, set it and return newly set index")
Ian Elliott81ac44c2015-01-13 17:52:38 -0700975 header_txt.append(' uint32_t retVal = (uint32_t) maxTID;')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700976 header_txt.append(' tidMapping[maxTID++] = tid;')
977 header_txt.append(' assert(maxTID < MAX_TID);')
978 header_txt.append(' return retVal;')
979 header_txt.append('}')
980 return "\n".join(header_txt)
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600981
982 def generate_body(self):
Ian Elliott81ac44c2015-01-13 17:52:38 -0700983 body = [self._generate_layer_dispatch_table_with_lock(),
Tobin Ehlis907a0522014-11-25 16:59:27 -0700984 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDump"),
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600985 self._generate_layer_gpa_function()]
986
987 return "\n\n".join(body)
988
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700989class ApiDumpCppSubcommand(Subcommand):
990 def generate_header(self):
991 header_txt = []
Ian Elliott81ac44c2015-01-13 17:52:38 -0700992 header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>')
993 header_txt.append('#include "loader_platform.h"')
994 header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper_cpp.h"\n')
995 header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;')
996 header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n')
997 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
998 header_txt.append('static int printLockInitialized = 0;')
999 header_txt.append('static loader_platform_thread_mutex printLock;\n')
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001000 header_txt.append('#define MAX_TID 513')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001001 header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};')
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001002 header_txt.append('static uint32_t maxTID = 0;')
1003 header_txt.append('// Map actual TID to an index value and return that index')
1004 header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs')
1005 header_txt.append('static uint32_t getTIDIndex() {')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001006 header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();')
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001007 header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {')
1008 header_txt.append(' if (tid == tidMapping[i])')
1009 header_txt.append(' return i;')
1010 header_txt.append(' }')
1011 header_txt.append(" // Don't yet have mapping, set it and return newly set index")
Ian Elliott81ac44c2015-01-13 17:52:38 -07001012 header_txt.append(' uint32_t retVal = (uint32_t) maxTID;')
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001013 header_txt.append(' tidMapping[maxTID++] = tid;')
1014 header_txt.append(' assert(maxTID < MAX_TID);')
1015 header_txt.append(' return retVal;')
1016 header_txt.append('}')
1017 return "\n".join(header_txt)
1018
1019 def generate_body(self):
Ian Elliott81ac44c2015-01-13 17:52:38 -07001020 body = [self._generate_layer_dispatch_table_with_lock(),
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001021 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDumpCpp"),
1022 self._generate_layer_gpa_function()]
1023
1024 return "\n\n".join(body)
1025
Tobin Ehlis574b0142014-11-12 13:11:15 -07001026class ApiDumpFileSubcommand(Subcommand):
1027 def generate_header(self):
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -07001028 header_txt = []
Ian Elliott81ac44c2015-01-13 17:52:38 -07001029 header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>')
1030 header_txt.append('#include "loader_platform.h"')
1031 header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper.h"\n')
1032 header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;')
1033 header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n')
1034 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
1035 header_txt.append('static int printLockInitialized = 0;')
1036 header_txt.append('static loader_platform_thread_mutex printLock;\n')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -07001037 header_txt.append('#define MAX_TID 513')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001038 header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -07001039 header_txt.append('static uint32_t maxTID = 0;')
1040 header_txt.append('// Map actual TID to an index value and return that index')
1041 header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs')
1042 header_txt.append('static uint32_t getTIDIndex() {')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001043 header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -07001044 header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {')
1045 header_txt.append(' if (tid == tidMapping[i])')
1046 header_txt.append(' return i;')
1047 header_txt.append(' }')
1048 header_txt.append(" // Don't yet have mapping, set it and return newly set index")
Ian Elliott81ac44c2015-01-13 17:52:38 -07001049 header_txt.append(' uint32_t retVal = (uint32_t) maxTID;')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -07001050 header_txt.append(' tidMapping[maxTID++] = tid;')
1051 header_txt.append(' assert(maxTID < MAX_TID);')
1052 header_txt.append(' return retVal;')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001053 header_txt.append('}\n')
1054 header_txt.append('static FILE* pOutFile;\nstatic char* outFileName = "xgl_apidump.txt";')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -07001055 return "\n".join(header_txt)
Tobin Ehlis574b0142014-11-12 13:11:15 -07001056
1057 def generate_body(self):
Ian Elliott81ac44c2015-01-13 17:52:38 -07001058 body = [self._generate_layer_dispatch_table_with_lock(),
Tobin Ehlis907a0522014-11-25 16:59:27 -07001059 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDumpFile"),
Tobin Ehlis574b0142014-11-12 13:11:15 -07001060 self._generate_layer_gpa_function()]
1061
1062 return "\n\n".join(body)
1063
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -07001064class ApiDumpNoAddrSubcommand(Subcommand):
1065 def generate_header(self):
1066 header_txt = []
Ian Elliott81ac44c2015-01-13 17:52:38 -07001067 header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>')
1068 header_txt.append('#include "loader_platform.h"')
1069 header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper_no_addr.h"\n')
1070 header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;')
1071 header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n')
1072 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
1073 header_txt.append('static int printLockInitialized = 0;')
1074 header_txt.append('static loader_platform_thread_mutex printLock;\n')
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -07001075 header_txt.append('#define MAX_TID 513')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001076 header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};')
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -07001077 header_txt.append('static uint32_t maxTID = 0;')
1078 header_txt.append('// Map actual TID to an index value and return that index')
1079 header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs')
1080 header_txt.append('static uint32_t getTIDIndex() {')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001081 header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();')
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -07001082 header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {')
1083 header_txt.append(' if (tid == tidMapping[i])')
1084 header_txt.append(' return i;')
1085 header_txt.append(' }')
1086 header_txt.append(" // Don't yet have mapping, set it and return newly set index")
Ian Elliott81ac44c2015-01-13 17:52:38 -07001087 header_txt.append(' uint32_t retVal = (uint32_t) maxTID;')
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -07001088 header_txt.append(' tidMapping[maxTID++] = tid;')
1089 header_txt.append(' assert(maxTID < MAX_TID);')
1090 header_txt.append(' return retVal;')
1091 header_txt.append('}')
1092 return "\n".join(header_txt)
1093
1094 def generate_body(self):
Ian Elliott81ac44c2015-01-13 17:52:38 -07001095 body = [self._generate_layer_dispatch_table_with_lock(),
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -07001096 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDump", True),
1097 self._generate_layer_gpa_function()]
1098
1099 return "\n\n".join(body)
1100
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001101class ApiDumpNoAddrCppSubcommand(Subcommand):
1102 def generate_header(self):
1103 header_txt = []
Ian Elliott81ac44c2015-01-13 17:52:38 -07001104 header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>')
1105 header_txt.append('#include "loader_platform.h"')
1106 header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper_no_addr_cpp.h"\n')
1107 header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;')
1108 header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n')
1109 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
1110 header_txt.append('static int printLockInitialized = 0;')
1111 header_txt.append('static loader_platform_thread_mutex printLock;\n')
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001112 header_txt.append('#define MAX_TID 513')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001113 header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};')
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001114 header_txt.append('static uint32_t maxTID = 0;')
1115 header_txt.append('// Map actual TID to an index value and return that index')
1116 header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs')
1117 header_txt.append('static uint32_t getTIDIndex() {')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001118 header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();')
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001119 header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {')
1120 header_txt.append(' if (tid == tidMapping[i])')
1121 header_txt.append(' return i;')
1122 header_txt.append(' }')
1123 header_txt.append(" // Don't yet have mapping, set it and return newly set index")
Ian Elliott81ac44c2015-01-13 17:52:38 -07001124 header_txt.append(' uint32_t retVal = (uint32_t) maxTID;')
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001125 header_txt.append(' tidMapping[maxTID++] = tid;')
1126 header_txt.append(' assert(maxTID < MAX_TID);')
1127 header_txt.append(' return retVal;')
1128 header_txt.append('}')
1129 return "\n".join(header_txt)
1130
1131 def generate_body(self):
Ian Elliott81ac44c2015-01-13 17:52:38 -07001132 body = [self._generate_layer_dispatch_table_with_lock(),
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001133 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDumpCpp", True),
1134 self._generate_layer_gpa_function()]
1135
1136 return "\n\n".join(body)
1137
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001138class ObjectTrackerSubcommand(Subcommand):
1139 def generate_header(self):
1140 header_txt = []
Ian Elliott81ac44c2015-01-13 17:52:38 -07001141 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 -07001142 header_txt.append('#include "object_track.h"\n\nstatic XGL_LAYER_DISPATCH_TABLE nextTable;\nstatic XGL_BASE_LAYER_OBJECT *pCurObj;')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001143 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
1144 header_txt.append('static long long unsigned int object_track_index = 0;')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001145 header_txt.append('// Ptr to LL of dbg functions')
1146 header_txt.append('static XGL_LAYER_DBG_FUNCTION_NODE *pDbgFunctionHead = NULL;')
1147 header_txt.append('// Utility function to handle reporting')
1148 header_txt.append('// If callbacks are enabled, use them, otherwise use printf')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001149 header_txt.append('static void layerCbMsg(XGL_DBG_MSG_TYPE msgType,')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001150 header_txt.append(' XGL_VALIDATION_LEVEL validationLevel,')
1151 header_txt.append(' XGL_BASE_OBJECT srcObject,')
Tobin Ehlis2f3726c2015-01-15 17:51:52 -07001152 header_txt.append(' size_t location,')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001153 header_txt.append(' int32_t msgCode,')
Chia-I Wua837c522014-12-16 10:47:33 +08001154 header_txt.append(' const char* pLayerPrefix,')
1155 header_txt.append(' const char* pMsg)')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001156 header_txt.append('{')
1157 header_txt.append(' XGL_LAYER_DBG_FUNCTION_NODE *pTrav = pDbgFunctionHead;')
1158 header_txt.append(' if (pTrav) {')
1159 header_txt.append(' while (pTrav) {')
Chia-I Wu7461fcf2014-12-27 15:16:07 +08001160 header_txt.append(' pTrav->pfnMsgCallback(msgType, validationLevel, srcObject, location, msgCode, pMsg, pTrav->pUserData);')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001161 header_txt.append(' pTrav = pTrav->pNext;')
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001162 header_txt.append(' }')
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001163 header_txt.append(' }')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001164 header_txt.append(' else {')
1165 header_txt.append(' switch (msgType) {')
1166 header_txt.append(' case XGL_DBG_MSG_ERROR:')
1167 header_txt.append(' printf("{%s}ERROR : %s\\n", pLayerPrefix, pMsg);')
1168 header_txt.append(' break;')
1169 header_txt.append(' case XGL_DBG_MSG_WARNING:')
1170 header_txt.append(' printf("{%s}WARN : %s\\n", pLayerPrefix, pMsg);')
1171 header_txt.append(' break;')
1172 header_txt.append(' case XGL_DBG_MSG_PERF_WARNING:')
1173 header_txt.append(' printf("{%s}PERF_WARN : %s\\n", pLayerPrefix, pMsg);')
1174 header_txt.append(' break;')
1175 header_txt.append(' default:')
1176 header_txt.append(' printf("{%s}INFO : %s\\n", pLayerPrefix, pMsg);')
1177 header_txt.append(' break;')
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001178 header_txt.append(' }')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001179 header_txt.append(' }')
1180 header_txt.append('}')
1181 header_txt.append('// We maintain a "Global" list which links every object and a')
1182 header_txt.append('// per-Object list which just links objects of a given type')
1183 header_txt.append('// The object node has both pointers so the actual nodes are shared between the two lists')
1184 header_txt.append('typedef struct _objNode {')
1185 header_txt.append(' OBJTRACK_NODE obj;')
1186 header_txt.append(' struct _objNode *pNextObj;')
1187 header_txt.append(' struct _objNode *pNextGlobal;')
1188 header_txt.append('} objNode;')
1189 header_txt.append('static objNode *pObjectHead[XGL_NUM_OBJECT_TYPE] = {0};')
1190 header_txt.append('static objNode *pGlobalHead = NULL;')
1191 header_txt.append('static uint64_t numObjs[XGL_NUM_OBJECT_TYPE] = {0};')
1192 header_txt.append('static uint64_t numTotalObjs = 0;')
1193 header_txt.append('// Debug function to print global list and each individual object list')
1194 header_txt.append('static void ll_print_lists()')
1195 header_txt.append('{')
1196 header_txt.append(' objNode* pTrav = pGlobalHead;')
1197 header_txt.append(' printf("=====GLOBAL OBJECT LIST (%lu total objs):\\n", numTotalObjs);')
1198 header_txt.append(' while (pTrav) {')
1199 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);')
1200 header_txt.append(' pTrav = pTrav->pNextGlobal;')
1201 header_txt.append(' }')
1202 header_txt.append(' for (uint32_t i = 0; i < XGL_NUM_OBJECT_TYPE; i++) {')
1203 header_txt.append(' pTrav = pObjectHead[i];')
1204 header_txt.append(' if (pTrav) {')
1205 header_txt.append(' printf("=====%s OBJECT LIST (%lu objs):\\n", string_XGL_OBJECT_TYPE(pTrav->obj.objType), numObjs[i]);')
1206 header_txt.append(' while (pTrav) {')
1207 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);')
1208 header_txt.append(' pTrav = pTrav->pNextObj;')
1209 header_txt.append(' }')
1210 header_txt.append(' }')
1211 header_txt.append(' }')
1212 header_txt.append('}')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001213 header_txt.append('static void ll_insert_obj(void* pObj, XGL_OBJECT_TYPE objType) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001214 header_txt.append(' char str[1024];')
1215 header_txt.append(' sprintf(str, "OBJ[%llu] : CREATE %s object %p", object_track_index++, string_XGL_OBJECT_TYPE(objType), (void*)pObj);')
1216 header_txt.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_NONE, "OBJTRACK", str);')
1217 header_txt.append(' objNode* pNewObjNode = (objNode*)malloc(sizeof(objNode));')
1218 header_txt.append(' pNewObjNode->obj.pObj = pObj;')
1219 header_txt.append(' pNewObjNode->obj.objType = objType;')
Mark Lobodzinski01552702015-02-03 10:06:31 -06001220 header_txt.append(' pNewObjNode->obj.status = OBJSTATUS_NONE;')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001221 header_txt.append(' pNewObjNode->obj.numUses = 0;')
1222 header_txt.append(' // insert at front of global list')
1223 header_txt.append(' pNewObjNode->pNextGlobal = pGlobalHead;')
1224 header_txt.append(' pGlobalHead = pNewObjNode;')
1225 header_txt.append(' // insert at front of object list')
1226 header_txt.append(' pNewObjNode->pNextObj = pObjectHead[objType];')
1227 header_txt.append(' pObjectHead[objType] = pNewObjNode;')
1228 header_txt.append(' // increment obj counts')
1229 header_txt.append(' numObjs[objType]++;')
1230 header_txt.append(' numTotalObjs++;')
1231 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 +08001232 header_txt.append(' if (0) ll_print_lists();')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001233 header_txt.append('}')
1234 header_txt.append('// Traverse global list and return type for given object')
1235 header_txt.append('static XGL_OBJECT_TYPE ll_get_obj_type(XGL_OBJECT object) {')
1236 header_txt.append(' objNode *pTrav = pGlobalHead;')
1237 header_txt.append(' while (pTrav) {')
1238 header_txt.append(' if (pTrav->obj.pObj == object)')
1239 header_txt.append(' return pTrav->obj.objType;')
1240 header_txt.append(' pTrav = pTrav->pNextGlobal;')
1241 header_txt.append(' }')
1242 header_txt.append(' char str[1024];')
1243 header_txt.append(' sprintf(str, "Attempting look-up on obj %p but it is NOT in the global list!", (void*)object);')
1244 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, object, 0, OBJTRACK_MISSING_OBJECT, "OBJTRACK", str);')
1245 header_txt.append(' return XGL_OBJECT_TYPE_UNKNOWN;')
1246 header_txt.append('}')
Chia-I Wudf142a32014-12-16 11:02:06 +08001247 header_txt.append('#if 0')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001248 header_txt.append('static uint64_t ll_get_obj_uses(void* pObj, XGL_OBJECT_TYPE objType) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001249 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
1250 header_txt.append(' while (pTrav) {')
1251 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1252 header_txt.append(' return pTrav->obj.numUses;')
1253 header_txt.append(' }')
1254 header_txt.append(' pTrav = pTrav->pNextObj;')
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001255 header_txt.append(' }')
1256 header_txt.append(' return 0;')
1257 header_txt.append('}')
Chia-I Wudf142a32014-12-16 11:02:06 +08001258 header_txt.append('#endif')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001259 header_txt.append('static void ll_increment_use_count(void* pObj, XGL_OBJECT_TYPE objType) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001260 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001261 header_txt.append(' while (pTrav) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001262 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1263 header_txt.append(' pTrav->obj.numUses++;')
1264 header_txt.append(' char str[1024];')
1265 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);')
1266 header_txt.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_NONE, "OBJTRACK", str);')
1267 header_txt.append(' return;')
1268 header_txt.append(' }')
1269 header_txt.append(' pTrav = pTrav->pNextObj;')
1270 header_txt.append(' }')
1271 header_txt.append(' // If we do not find obj, insert it and then increment count')
1272 header_txt.append(' char str[1024];')
1273 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));')
1274 header_txt.append(' layerCbMsg(XGL_DBG_MSG_WARNING, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
1275 header_txt.append('')
1276 header_txt.append(' ll_insert_obj(pObj, objType);')
1277 header_txt.append(' ll_increment_use_count(pObj, objType);')
1278 header_txt.append('}')
1279 header_txt.append('// We usually do not know Obj type when we destroy it so have to fetch')
1280 header_txt.append('// Type from global list w/ ll_destroy_obj()')
1281 header_txt.append('// and then do the full removal from both lists w/ ll_remove_obj_type()')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001282 header_txt.append('static void ll_remove_obj_type(void* pObj, XGL_OBJECT_TYPE objType) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001283 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
1284 header_txt.append(' objNode *pPrev = pObjectHead[objType];')
1285 header_txt.append(' while (pTrav) {')
1286 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1287 header_txt.append(' pPrev->pNextObj = pTrav->pNextObj;')
1288 header_txt.append(' // update HEAD of Obj list as needed')
1289 header_txt.append(' if (pObjectHead[objType] == pTrav)')
1290 header_txt.append(' pObjectHead[objType] = pTrav->pNextObj;')
1291 header_txt.append(' assert(numObjs[objType] > 0);')
1292 header_txt.append(' numObjs[objType]--;')
1293 header_txt.append(' char str[1024];')
1294 header_txt.append(' sprintf(str, "OBJ[%llu] : DESTROY %s object %p", object_track_index++, string_XGL_OBJECT_TYPE(objType), (void*)pObj);')
1295 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 -06001296 header_txt.append(' return;')
1297 header_txt.append(' }')
1298 header_txt.append(' pPrev = pTrav;')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001299 header_txt.append(' pTrav = pTrav->pNextObj;')
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001300 header_txt.append(' }')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001301 header_txt.append(' char str[1024];')
1302 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));')
1303 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_INTERNAL_ERROR, "OBJTRACK", str);')
1304 header_txt.append('}')
1305 header_txt.append('// Parse global list to find obj type, then remove obj from obj type list, finally')
1306 header_txt.append('// remove obj from global list')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001307 header_txt.append('static void ll_destroy_obj(void* pObj) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001308 header_txt.append(' objNode *pTrav = pGlobalHead;')
1309 header_txt.append(' objNode *pPrev = pGlobalHead;')
1310 header_txt.append(' while (pTrav) {')
1311 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1312 header_txt.append(' ll_remove_obj_type(pObj, pTrav->obj.objType);')
1313 header_txt.append(' pPrev->pNextGlobal = pTrav->pNextGlobal;')
1314 header_txt.append(' // update HEAD of global list if needed')
1315 header_txt.append(' if (pGlobalHead == pTrav)')
1316 header_txt.append(' pGlobalHead = pTrav->pNextGlobal;')
1317 header_txt.append(' free(pTrav);')
1318 header_txt.append(' assert(numTotalObjs > 0);')
1319 header_txt.append(' numTotalObjs--;')
1320 header_txt.append(' char str[1024];')
1321 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));')
1322 header_txt.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_NONE, "OBJTRACK", str);')
1323 header_txt.append(' return;')
1324 header_txt.append(' }')
1325 header_txt.append(' pPrev = pTrav;')
1326 header_txt.append(' pTrav = pTrav->pNextGlobal;')
1327 header_txt.append(' }')
1328 header_txt.append(' char str[1024];')
1329 header_txt.append(' sprintf(str, "Unable to remove obj %p. Was it created? Has it already been destroyed?", pObj);')
1330 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 -06001331 header_txt.append('}')
Tobin Ehlis235c20e2015-01-16 08:56:30 -07001332 header_txt.append('// Set selected flag state for an object node')
1333 header_txt.append('static void set_status(void* pObj, XGL_OBJECT_TYPE objType, OBJECT_STATUS status_flag) {')
1334 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
1335 header_txt.append(' while (pTrav) {')
1336 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1337 header_txt.append(' pTrav->obj.status |= status_flag;')
1338 header_txt.append(' return;')
1339 header_txt.append(' }')
1340 header_txt.append(' pTrav = pTrav->pNextObj;')
1341 header_txt.append(' }')
1342 header_txt.append(' // If we do not find it print an error')
1343 header_txt.append(' char str[1024];')
1344 header_txt.append(' sprintf(str, "Unable to set status for non-existent object %p of %s type", pObj, string_XGL_OBJECT_TYPE(objType));')
1345 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
1346 header_txt.append('}')
1347 header_txt.append('')
Mark Lobodzinski01552702015-02-03 10:06:31 -06001348 header_txt.append('// Track selected state for an object node')
1349 header_txt.append('static void track_object_status(void* pObj, XGL_STATE_BIND_POINT stateBindPoint) {')
1350 header_txt.append(' objNode *pTrav = pObjectHead[XGL_OBJECT_TYPE_CMD_BUFFER];')
1351 header_txt.append('')
1352 header_txt.append(' while (pTrav) {')
1353 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1354 header_txt.append(' if (stateBindPoint == XGL_STATE_BIND_VIEWPORT) {')
1355 header_txt.append(' pTrav->obj.status |= OBJSTATUS_VIEWPORT_BOUND;')
1356 header_txt.append(' } else if (stateBindPoint == XGL_STATE_BIND_RASTER) {')
1357 header_txt.append(' pTrav->obj.status |= OBJSTATUS_RASTER_BOUND;')
1358 header_txt.append(' } else if (stateBindPoint == XGL_STATE_BIND_COLOR_BLEND) {')
1359 header_txt.append(' pTrav->obj.status |= OBJSTATUS_COLOR_BLEND_BOUND;')
1360 header_txt.append(' } else if (stateBindPoint == XGL_STATE_BIND_DEPTH_STENCIL) {')
1361 header_txt.append(' pTrav->obj.status |= OBJSTATUS_DEPTH_STENCIL_BOUND;')
1362 header_txt.append(' }')
1363 header_txt.append(' return;')
1364 header_txt.append(' }')
1365 header_txt.append(' pTrav = pTrav->pNextObj;')
1366 header_txt.append(' }')
1367 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 track status for non-existent Command Buffer object %p", pObj);')
1370 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
1371 header_txt.append('}')
1372 header_txt.append('')
1373 header_txt.append('// Reset selected flag state for an object node')
1374 header_txt.append('static void reset_status(void* pObj, XGL_OBJECT_TYPE objType, OBJECT_STATUS status_flag) {')
Tobin Ehlis235c20e2015-01-16 08:56:30 -07001375 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
1376 header_txt.append(' while (pTrav) {')
1377 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
Mark Lobodzinski01552702015-02-03 10:06:31 -06001378 header_txt.append(' pTrav->obj.status &= ~status_flag;')
1379 header_txt.append(' return;')
1380 header_txt.append(' }')
1381 header_txt.append(' pTrav = pTrav->pNextObj;')
1382 header_txt.append(' }')
1383 header_txt.append(' // If we do not find it print an error')
1384 header_txt.append(' char str[1024];')
1385 header_txt.append(' sprintf(str, "Unable to reset status for non-existent object %p of %s type", pObj, string_XGL_OBJECT_TYPE(objType));')
1386 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
1387 header_txt.append('}')
1388 header_txt.append('')
1389 header_txt.append('// Check object status for selected flag state')
1390 header_txt.append('static void validate_status(void* pObj, XGL_OBJECT_TYPE objType, OBJECT_STATUS status_flag, XGL_DBG_MSG_TYPE error_level, OBJECT_TRACK_ERROR error_code, char* fail_msg) {')
1391 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
1392 header_txt.append(' while (pTrav) {')
1393 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1394 header_txt.append(' if ((pTrav->obj.status & status_flag) != status_flag) {')
Tobin Ehlis235c20e2015-01-16 08:56:30 -07001395 header_txt.append(' char str[1024];')
1396 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 -06001397 header_txt.append(' layerCbMsg(error_level, XGL_VALIDATION_LEVEL_0, pObj, 0, error_code, "OBJTRACK", str);')
Tobin Ehlis235c20e2015-01-16 08:56:30 -07001398 header_txt.append(' }')
1399 header_txt.append(' return;')
1400 header_txt.append(' }')
1401 header_txt.append(' pTrav = pTrav->pNextObj;')
1402 header_txt.append(' }')
1403 header_txt.append(' // If we do not find it print an error')
1404 header_txt.append(' char str[1024];')
1405 header_txt.append(' sprintf(str, "Unable to obtain status for non-existent object %p of %s type", pObj, string_XGL_OBJECT_TYPE(objType));')
1406 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
1407 header_txt.append('}')
Mark Lobodzinski01552702015-02-03 10:06:31 -06001408 header_txt.append('')
1409 header_txt.append('static void validate_draw_state_flags(void* pObj) {')
1410 header_txt.append(' validate_status((void*)pObj, XGL_OBJECT_TYPE_CMD_BUFFER, OBJSTATUS_VIEWPORT_BOUND, XGL_DBG_MSG_ERROR, OBJTRACK_VIEWPORT_NOT_BOUND, "Viewport object not bound to this command buffer");')
1411 header_txt.append(' validate_status((void*)pObj, XGL_OBJECT_TYPE_CMD_BUFFER, OBJSTATUS_RASTER_BOUND, XGL_DBG_MSG_ERROR, OBJTRACK_RASTER_NOT_BOUND, "Raster object not bound to this command buffer");')
1412 header_txt.append(' validate_status((void*)pObj, XGL_OBJECT_TYPE_CMD_BUFFER, OBJSTATUS_COLOR_BLEND_BOUND, XGL_DBG_MSG_UNKNOWN, OBJTRACK_COLOR_BLEND_NOT_BOUND, "Color-blend object not bound to this command buffer");')
1413 header_txt.append(' validate_status((void*)pObj, XGL_OBJECT_TYPE_CMD_BUFFER, OBJSTATUS_DEPTH_STENCIL_BOUND, XGL_DBG_MSG_UNKNOWN, OBJTRACK_DEPTH_STENCIL_NOT_BOUND, "Depth-stencil object not bound to this command buffer");')
1414 header_txt.append('}')
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001415 return "\n".join(header_txt)
1416
1417 def generate_body(self):
1418 body = [self._generate_layer_dispatch_table(),
Tobin Ehlis907a0522014-11-25 16:59:27 -07001419 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "ObjectTracker"),
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001420 self._generate_extensions(),
1421 self._generate_layer_gpa_function(extensions=['objTrackGetObjectCount', 'objTrackGetObjects'])]
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001422
1423 return "\n\n".join(body)
Courtney Goeltzenleuchtere6094fc2014-11-18 10:40:29 -07001424
Tobin Ehlis6cd06372014-12-17 17:44:50 -07001425class ParamCheckerSubcommand(Subcommand):
1426 def generate_header(self):
Ian Elliott81ac44c2015-01-13 17:52:38 -07001427 return '#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include "loader_platform.h"\n#include "xglLayer.h"\n#include "xgl_enum_validate_helper.h"\n#include "xgl_struct_validate_helper.h"\n\nstatic XGL_LAYER_DISPATCH_TABLE nextTable;\nstatic XGL_BASE_LAYER_OBJECT *pCurObj;\nstatic LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);\n\n'
Tobin Ehlis6cd06372014-12-17 17:44:50 -07001428
1429 def generate_body(self):
1430 body = [self._gen_layer_dbg_callback_header(),
1431 self._generate_layer_dispatch_table(),
1432 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "ParamChecker"),
1433 self._generate_layer_gpa_function()]
1434
1435 return "\n\n".join(body)
1436
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001437def main():
1438 subcommands = {
1439 "layer-funcs" : LayerFuncsSubcommand,
1440 "layer-dispatch" : LayerDispatchSubcommand,
Tobin Ehlis907a0522014-11-25 16:59:27 -07001441 "Generic" : GenericLayerSubcommand,
1442 "ApiDump" : ApiDumpSubcommand,
1443 "ApiDumpFile" : ApiDumpFileSubcommand,
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -07001444 "ApiDumpNoAddr" : ApiDumpNoAddrSubcommand,
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001445 "ApiDumpCpp" : ApiDumpCppSubcommand,
1446 "ApiDumpNoAddrCpp" : ApiDumpNoAddrCppSubcommand,
Tobin Ehlis907a0522014-11-25 16:59:27 -07001447 "ObjectTracker" : ObjectTrackerSubcommand,
Tobin Ehlis6cd06372014-12-17 17:44:50 -07001448 "ParamChecker" : ParamCheckerSubcommand,
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001449 }
1450
Tobin Ehlis6cd06372014-12-17 17:44:50 -07001451 if len(sys.argv) < 3 or sys.argv[1] not in subcommands or not os.path.exists(sys.argv[2]):
1452 print("Usage: %s <subcommand> <input_header> [options]" % sys.argv[0])
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001453 print
Tobin Ehlis2f3726c2015-01-15 17:51:52 -07001454 print("Available subcommands are: %s" % " ".join(subcommands))
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001455 exit(1)
1456
Tobin Ehlis6cd06372014-12-17 17:44:50 -07001457 hfp = xgl_helper.HeaderFileParser(sys.argv[2])
1458 hfp.parse()
1459 xgl_helper.enum_val_dict = hfp.get_enum_val_dict()
1460 xgl_helper.enum_type_dict = hfp.get_enum_type_dict()
1461 xgl_helper.struct_dict = hfp.get_struct_dict()
1462 xgl_helper.typedef_fwd_dict = hfp.get_typedef_fwd_dict()
1463 xgl_helper.typedef_rev_dict = hfp.get_typedef_rev_dict()
1464 xgl_helper.types_dict = hfp.get_types_dict()
1465
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001466 subcmd = subcommands[sys.argv[1]](sys.argv[2:])
1467 subcmd.run()
1468
1469if __name__ == "__main__":
1470 main()