blob: e3e205c271e34065ca400d64f61a2849b459f00b [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'
Mark Lobodzinski4186e712015-02-03 11:52:26 -0600644 using_line += ' validate_memory_mapping_status(pMemRefs, memRefCount);\n'
Tobin Ehlis235c20e2015-01-16 08:56:30 -0700645 elif 'GetFenceStatus' in proto.name:
646 using_line += ' // Warn if submitted_flag is not set\n'
Mark Lobodzinski4186e712015-02-03 11:52:26 -0600647 using_line += ' validate_status((void*)fence, XGL_OBJECT_TYPE_FENCE, OBJSTATUS_FENCE_IS_SUBMITTED, OBJSTATUS_FENCE_IS_SUBMITTED, XGL_DBG_MSG_ERROR, OBJTRACK_INVALID_FENCE, "Status Requested for Unsubmitted Fence");\n'
Mark Lobodzinski01552702015-02-03 10:06:31 -0600648 elif 'EndCommandBuffer' in proto.name:
649 using_line += ' reset_status((void*)cmdBuffer, XGL_OBJECT_TYPE_CMD_BUFFER, (OBJSTATUS_VIEWPORT_BOUND |\n'
650 using_line += ' OBJSTATUS_RASTER_BOUND |\n'
651 using_line += ' OBJSTATUS_COLOR_BLEND_BOUND |\n'
652 using_line += ' OBJSTATUS_DEPTH_STENCIL_BOUND));\n'
653 elif 'CmdBindDynamicStateObject' in proto.name:
654 using_line += ' track_object_status((void*)cmdBuffer, stateBindPoint);\n'
655 elif 'CmdDraw' in proto.name:
656 using_line += ' validate_draw_state_flags((void *)cmdBuffer);\n'
Mark Lobodzinski4186e712015-02-03 11:52:26 -0600657 elif 'MapMemory' in proto.name:
658 using_line += ' set_status((void*)mem, XGL_OBJECT_TYPE_GPU_MEMORY, OBJSTATUS_GPU_MEM_MAPPED);\n'
659 elif 'UnmapMemory' in proto.name:
660 using_line += ' reset_status((void*)mem, XGL_OBJECT_TYPE_GPU_MEMORY, OBJSTATUS_GPU_MEM_MAPPED);\n'
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700661 if 'AllocDescriptor' in proto.name: # Allocates array of DSs
662 create_line = ' for (uint32_t i; i < *pCount; i++) {\n'
663 create_line += ' ll_insert_obj((void*)pDescriptorSets[i], XGL_OBJECT_TYPE_DESCRIPTOR_SET);\n'
664 create_line += ' }\n'
665 elif 'Create' in proto.name or 'Alloc' in proto.name:
666 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 -0700667 if 'DestroyObject' in proto.name:
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600668 destroy_line = ' ll_destroy_obj((void*)%s);\n' % (param0_name)
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700669 using_line = ''
670 else:
671 if 'Destroy' in proto.name or 'Free' in proto.name:
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600672 destroy_line = ' ll_remove_obj_type((void*)%s, %s);\n' % (param0_name, obj_type_mapping[p0_type])
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700673 using_line = ''
674 if 'DestroyDevice' in proto.name:
675 destroy_line += ' // Report any remaining objects in LL\n objNode *pTrav = pGlobalHead;\n while (pTrav) {\n'
676 destroy_line += ' char str[1024];\n'
677 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'
678 destroy_line += ' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, device, 0, OBJTRACK_OBJECT_LEAK, "OBJTRACK", str);\n'
679 destroy_line += ' pTrav = pTrav->pNextGlobal;\n }\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600680 ret_val = ''
681 stmt = ''
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600682 if proto.ret != "void":
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600683 ret_val = "XGL_RESULT result = "
684 stmt = " return result;\n"
Ian Elliott81ac44c2015-01-13 17:52:38 -0700685 if 'WsiX11AssociateConnection' == proto.name:
686 funcs.append("#if !defined(_WIN32)")
Jon Ashburn451c16f2014-11-25 11:08:42 -0700687 if proto.name == "EnumerateLayers":
688 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
689 funcs.append('%s%s\n'
690 '{\n'
691 ' if (gpu != NULL) {\n'
692 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
693 ' %s'
694 ' pCurObj = gpuw;\n'
Ian Elliott81ac44c2015-01-13 17:52:38 -0700695 ' loader_platform_thread_once(&tabOnce, initLayerTable);\n'
Jon Ashburn451c16f2014-11-25 11:08:42 -0700696 ' %snextTable.%s;\n'
697 ' %s%s'
698 ' %s'
699 ' } else {\n'
700 ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n'
701 ' return XGL_ERROR_INVALID_POINTER;\n'
702 ' // This layer compatible with all GPUs\n'
703 ' *pOutLayerCount = 1;\n'
Chia-I Wua837c522014-12-16 10:47:33 +0800704 ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n'
Jon Ashburn451c16f2014-11-25 11:08:42 -0700705 ' return XGL_SUCCESS;\n'
706 ' }\n'
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -0700707 '}' % (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 -0700708 elif proto.params[0].ty != "XGL_PHYSICAL_GPU":
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600709 funcs.append('%s%s\n'
710 '{\n'
711 '%s'
712 ' %snextTable.%s;\n'
713 '%s%s'
714 '%s'
715 '}' % (qual, decl, using_line, ret_val, proto.c_call(), create_line, destroy_line, stmt))
716 else:
717 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
718 funcs.append('%s%s\n'
719 '{\n'
720 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
721 '%s'
722 ' pCurObj = gpuw;\n'
Ian Elliott81ac44c2015-01-13 17:52:38 -0700723 ' loader_platform_thread_once(&tabOnce, initLayerTable);\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600724 ' %snextTable.%s;\n'
725 '%s%s'
726 '%s'
727 '}' % (qual, decl, proto.params[0].name, using_line, ret_val, c_call, create_line, destroy_line, stmt))
Ian Elliott81ac44c2015-01-13 17:52:38 -0700728 if 'WsiX11QueuePresent' == proto.name:
729 funcs.append("#endif")
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700730 elif "ParamChecker" == layer:
731 # TODO : Need to fix up the non-else cases below to do param checking as well
732 decl = proto.c_func(prefix="xgl", attr="XGLAPI")
733 param0_name = proto.params[0].name
734 ret_val = ''
735 stmt = ''
736 param_checks = []
737 # Add code to check enums and structs
738 # TODO : Currently only validating enum values, need to validate everything
739 str_decl = False
Tobin Ehlis773371f2014-12-18 13:51:21 -0700740 prev_count_name = ''
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700741 for p in proto.params:
742 if xgl_helper.is_type(p.ty.strip('*').strip('const '), 'enum'):
743 if not str_decl:
744 param_checks.append(' char str[1024];')
745 str_decl = True
746 param_checks.append(' if (!validate_%s(%s)) {' % (p.ty, p.name))
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700747 param_checks.append(' sprintf(str, "Parameter %s to function %s has invalid value of %%i.", (int)%s);' % (p.name, proto.name, p.name))
748 param_checks.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, 1, "PARAMCHECK", str);')
749 param_checks.append(' }')
750 elif xgl_helper.is_type(p.ty.strip('*').strip('const '), 'struct') and 'const' in p.ty:
Tobin Ehlis773371f2014-12-18 13:51:21 -0700751 is_array = False
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700752 if not str_decl:
753 param_checks.append(' char str[1024];')
754 str_decl = True
755 if '*' in p.ty: # First check for null ptr
Tobin Ehlis773371f2014-12-18 13:51:21 -0700756 # If this is an input array, parse over all of the array elements
757 if prev_count_name != '' and (prev_count_name.strip('Count')[1:] in p.name or 'slotCount' == prev_count_name):
758 #if 'pImageViews' in p.name:
759 is_array = True
760 param_checks.append(' uint32_t i;')
761 param_checks.append(' for (i = 0; i < %s; i++) {' % prev_count_name)
762 param_checks.append(' if (!xgl_validate_%s(&%s[i])) {' % (p.ty.strip('*').strip('const ').lower(), p.name))
763 param_checks.append(' sprintf(str, "Parameter %s[%%i] to function %s contains an invalid value.", i);' % (p.name, proto.name))
764 param_checks.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, 1, "PARAMCHECK", str);')
765 param_checks.append(' }')
766 param_checks.append(' }')
767 else:
768 param_checks.append(' if (!%s) {' % p.name)
769 param_checks.append(' sprintf(str, "Struct ptr parameter %s to function %s is NULL.");' % (p.name, proto.name))
770 param_checks.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, NULL, 0, 1, "PARAMCHECK", str);')
771 param_checks.append(' }')
772 param_checks.append(' else if (!xgl_validate_%s(%s)) {' % (p.ty.strip('*').strip('const ').lower(), p.name))
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700773 else:
774 param_checks.append(' if (!xgl_validate_%s(%s)) {' % (p.ty.strip('const ').lower(), p.name))
Tobin Ehlis773371f2014-12-18 13:51:21 -0700775 if not is_array:
776 param_checks.append(' sprintf(str, "Parameter %s to function %s contains an invalid value.");' % (p.name, proto.name))
777 param_checks.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, 1, "PARAMCHECK", str);')
778 param_checks.append(' }')
779 if p.name.endswith('Count'):
780 prev_count_name = p.name
781 else:
782 prev_count_name = ''
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600783 if proto.ret != "void":
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700784 ret_val = "XGL_RESULT result = "
785 stmt = " return result;\n"
Ian Elliott81ac44c2015-01-13 17:52:38 -0700786 if 'WsiX11AssociateConnection' == proto.name:
787 funcs.append("#if !defined(_WIN32)")
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700788 if proto.name == "EnumerateLayers":
789 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
790 funcs.append('%s%s\n'
791 '{\n'
792 ' char str[1024];\n'
793 ' if (gpu != NULL) {\n'
794 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
795 ' sprintf(str, "At start of layered %s\\n");\n'
796 ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpu, 0, 0, "PARAMCHECK", str);\n'
797 ' pCurObj = gpuw;\n'
Ian Elliott81ac44c2015-01-13 17:52:38 -0700798 ' loader_platform_thread_once(&tabOnce, initLayerTable);\n'
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700799 ' %snextTable.%s;\n'
800 ' sprintf(str, "Completed layered %s\\n");\n'
801 ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpu, 0, 0, "PARAMCHECK", str);\n'
802 ' fflush(stdout);\n'
803 ' %s'
804 ' } else {\n'
805 ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n'
806 ' return XGL_ERROR_INVALID_POINTER;\n'
807 ' // This layer compatible with all GPUs\n'
808 ' *pOutLayerCount = 1;\n'
809 ' strncpy(pOutLayers[0], "%s", maxStringSize);\n'
810 ' return XGL_SUCCESS;\n'
811 ' }\n'
812 '}' % (qual, decl, proto.params[0].name, proto.name, ret_val, c_call, proto.name, stmt, layer_name))
813 elif 'DbgRegisterMsgCallback' == proto.name:
814 funcs.append(self._gen_layer_dbg_callback_register())
815 elif 'DbgUnregisterMsgCallback' == proto.name:
816 funcs.append(self._gen_layer_dbg_callback_unregister())
817 elif proto.params[0].ty != "XGL_PHYSICAL_GPU":
818 funcs.append('%s%s\n'
819 '{\n'
820 '%s\n'
821 ' %snextTable.%s;\n'
822 '%s'
823 '}' % (qual, decl, "\n".join(param_checks), ret_val, proto.c_call(), stmt))
824 else:
825 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
826 funcs.append('%s%s\n'
827 '{\n'
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700828 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700829 ' pCurObj = gpuw;\n'
Ian Elliott81ac44c2015-01-13 17:52:38 -0700830 ' loader_platform_thread_once(&tabOnce, initLayerTable);\n'
Tobin Ehlis9d139862014-12-18 08:44:01 -0700831 '%s\n'
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700832 ' %snextTable.%s;\n'
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700833 '%s'
Tobin Ehlis9d139862014-12-18 08:44:01 -0700834 '}' % (qual, decl, proto.params[0].name, "\n".join(param_checks), ret_val, c_call, stmt))
Ian Elliott81ac44c2015-01-13 17:52:38 -0700835 if 'WsiX11QueuePresent' == proto.name:
836 funcs.append("#endif")
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600837
838 return "\n\n".join(funcs)
839
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700840 def _generate_extensions(self):
841 exts = []
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600842 exts.append('uint64_t objTrackGetObjectCount(XGL_OBJECT_TYPE type)')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700843 exts.append('{')
844 exts.append(' return (type == XGL_OBJECT_TYPE_ANY) ? numTotalObjs : numObjs[type];')
845 exts.append('}')
846 exts.append('')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600847 exts.append('XGL_RESULT objTrackGetObjects(XGL_OBJECT_TYPE type, uint64_t objCount, OBJTRACK_NODE* pObjNodeArray)')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700848 exts.append('{')
849 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 -0600850 exts.append(' bool32_t bAllObjs = (type == XGL_OBJECT_TYPE_ANY);')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700851 exts.append(' // Check the count first thing')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600852 exts.append(' uint64_t maxObjCount = (bAllObjs) ? numTotalObjs : numObjs[type];')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700853 exts.append(' if (objCount > maxObjCount) {')
854 exts.append(' char str[1024];')
855 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));')
856 exts.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, 0, 0, OBJTRACK_OBJCOUNT_MAX_EXCEEDED, "OBJTRACK", str);')
857 exts.append(' return XGL_ERROR_INVALID_VALUE;')
858 exts.append(' }')
859 exts.append(' objNode* pTrav = (bAllObjs) ? pGlobalHead : pObjectHead[type];')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600860 exts.append(' for (uint64_t i = 0; i < objCount; i++) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700861 exts.append(' if (!pTrav) {')
862 exts.append(' char str[1024];')
863 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);')
864 exts.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, 0, 0, OBJTRACK_INTERNAL_ERROR, "OBJTRACK", str);')
865 exts.append(' return XGL_ERROR_UNKNOWN;')
866 exts.append(' }')
867 exts.append(' memcpy(&pObjNodeArray[i], pTrav, sizeof(OBJTRACK_NODE));')
868 exts.append(' pTrav = (bAllObjs) ? pTrav->pNextGlobal : pTrav->pNextObj;')
869 exts.append(' }')
870 exts.append(' return XGL_SUCCESS;')
871 exts.append('}')
872
873 return "\n".join(exts)
874
Chia-I Wu706533e2015-01-05 13:18:57 +0800875 def _generate_layer_gpa_function(self, extensions=[]):
876 func_body = ["#include \"xgl_generic_intercept_proc_helper.h\""]
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600877 func_body.append("XGL_LAYER_EXPORT void* XGLAPI xglGetProcAddr(XGL_PHYSICAL_GPU gpu, const char* funcName)\n"
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600878 "{\n"
879 " XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) gpu;\n"
Chia-I Wu706533e2015-01-05 13:18:57 +0800880 " void* addr;\n"
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600881 " if (gpu == NULL)\n"
882 " return NULL;\n"
883 " pCurObj = gpuw;\n"
Ian Elliott81ac44c2015-01-13 17:52:38 -0700884 " loader_platform_thread_once(&tabOnce, initLayerTable);\n\n"
Chia-I Wu706533e2015-01-05 13:18:57 +0800885 " addr = layer_intercept_proc(funcName);\n"
886 " if (addr)\n"
887 " return addr;")
888
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700889 if 0 != len(extensions):
890 for ext_name in extensions:
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800891 func_body.append(' else if (!strncmp("%s", funcName, sizeof("%s")))\n'
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700892 ' return %s;' % (ext_name, ext_name, ext_name))
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600893 func_body.append(" else {\n"
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600894 " if (gpuw->pGPA == NULL)\n"
895 " return NULL;\n"
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700896 " return gpuw->pGPA((XGL_PHYSICAL_GPU)gpuw->nextObject, funcName);\n"
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600897 " }\n"
898 "}\n")
899 return "\n".join(func_body)
900
901 def _generate_layer_dispatch_table(self, prefix='xgl'):
Chia-I Wu0f65b1e2015-01-04 23:11:43 +0800902 func_body = ["#include \"xgl_dispatch_table_helper.h\""]
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600903 func_body.append('static void initLayerTable()\n'
904 '{\n'
Mark Lobodzinski953a1692015-01-09 15:12:03 -0600905 ' xglGetProcAddrType fpNextGPA;\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600906 ' fpNextGPA = pCurObj->pGPA;\n'
907 ' assert(fpNextGPA);\n');
908
Chia-I Wu0f65b1e2015-01-04 23:11:43 +0800909 func_body.append(" layer_initialize_dispatch_table(&nextTable, fpNextGPA, (XGL_PHYSICAL_GPU) pCurObj->nextObject);")
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600910 func_body.append("}\n")
911 return "\n".join(func_body)
912
Ian Elliott81ac44c2015-01-13 17:52:38 -0700913 def _generate_layer_dispatch_table_with_lock(self, prefix='xgl'):
914 func_body = ["#include \"xgl_dispatch_table_helper.h\""]
915 func_body.append('static void initLayerTable()\n'
916 '{\n'
917 ' xglGetProcAddrType fpNextGPA;\n'
918 ' fpNextGPA = pCurObj->pGPA;\n'
919 ' assert(fpNextGPA);\n');
920
921 func_body.append(" layer_initialize_dispatch_table(&nextTable, fpNextGPA, (XGL_PHYSICAL_GPU) pCurObj->nextObject);\n")
922 func_body.append(" if (!printLockInitialized)")
923 func_body.append(" {")
924 func_body.append(" // TODO/TBD: Need to delete this mutex sometime. How???")
925 func_body.append(" loader_platform_thread_create_mutex(&printLock);")
926 func_body.append(" printLockInitialized = 1;")
927 func_body.append(" }")
928 func_body.append("}\n")
929 return "\n".join(func_body)
930
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600931class LayerFuncsSubcommand(Subcommand):
932 def generate_header(self):
933 return '#include <xglLayer.h>\n#include "loader.h"'
934
935 def generate_body(self):
936 return self._generate_dispatch_entrypoints("static", True)
937
938class LayerDispatchSubcommand(Subcommand):
939 def generate_header(self):
940 return '#include "layer_wrappers.h"'
941
942 def generate_body(self):
943 return self._generate_layer_dispatch_table()
944
945class GenericLayerSubcommand(Subcommand):
946 def generate_header(self):
Ian Elliott81ac44c2015-01-13 17:52:38 -0700947 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 -0600948
949 def generate_body(self):
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700950 body = [self._gen_layer_dbg_callback_header(),
951 self._generate_layer_dispatch_table(),
Tobin Ehlis907a0522014-11-25 16:59:27 -0700952 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "Generic"),
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600953 self._generate_layer_gpa_function()]
954
955 return "\n\n".join(body)
956
957class ApiDumpSubcommand(Subcommand):
958 def generate_header(self):
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700959 header_txt = []
Ian Elliott81ac44c2015-01-13 17:52:38 -0700960 header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>')
961 header_txt.append('#include "loader_platform.h"')
962 header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper.h"\n')
963 header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;')
964 header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n')
965 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
966 header_txt.append('static int printLockInitialized = 0;')
967 header_txt.append('static loader_platform_thread_mutex printLock;\n')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700968 header_txt.append('#define MAX_TID 513')
Ian Elliott81ac44c2015-01-13 17:52:38 -0700969 header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700970 header_txt.append('static uint32_t maxTID = 0;')
971 header_txt.append('// Map actual TID to an index value and return that index')
972 header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs')
973 header_txt.append('static uint32_t getTIDIndex() {')
Ian Elliott81ac44c2015-01-13 17:52:38 -0700974 header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700975 header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {')
976 header_txt.append(' if (tid == tidMapping[i])')
977 header_txt.append(' return i;')
978 header_txt.append(' }')
979 header_txt.append(" // Don't yet have mapping, set it and return newly set index")
Ian Elliott81ac44c2015-01-13 17:52:38 -0700980 header_txt.append(' uint32_t retVal = (uint32_t) maxTID;')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700981 header_txt.append(' tidMapping[maxTID++] = tid;')
982 header_txt.append(' assert(maxTID < MAX_TID);')
983 header_txt.append(' return retVal;')
984 header_txt.append('}')
985 return "\n".join(header_txt)
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600986
987 def generate_body(self):
Ian Elliott81ac44c2015-01-13 17:52:38 -0700988 body = [self._generate_layer_dispatch_table_with_lock(),
Tobin Ehlis907a0522014-11-25 16:59:27 -0700989 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDump"),
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600990 self._generate_layer_gpa_function()]
991
992 return "\n\n".join(body)
993
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700994class ApiDumpCppSubcommand(Subcommand):
995 def generate_header(self):
996 header_txt = []
Ian Elliott81ac44c2015-01-13 17:52:38 -0700997 header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>')
998 header_txt.append('#include "loader_platform.h"')
999 header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper_cpp.h"\n')
1000 header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;')
1001 header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n')
1002 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
1003 header_txt.append('static int printLockInitialized = 0;')
1004 header_txt.append('static loader_platform_thread_mutex printLock;\n')
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001005 header_txt.append('#define MAX_TID 513')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001006 header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};')
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001007 header_txt.append('static uint32_t maxTID = 0;')
1008 header_txt.append('// Map actual TID to an index value and return that index')
1009 header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs')
1010 header_txt.append('static uint32_t getTIDIndex() {')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001011 header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();')
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001012 header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {')
1013 header_txt.append(' if (tid == tidMapping[i])')
1014 header_txt.append(' return i;')
1015 header_txt.append(' }')
1016 header_txt.append(" // Don't yet have mapping, set it and return newly set index")
Ian Elliott81ac44c2015-01-13 17:52:38 -07001017 header_txt.append(' uint32_t retVal = (uint32_t) maxTID;')
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001018 header_txt.append(' tidMapping[maxTID++] = tid;')
1019 header_txt.append(' assert(maxTID < MAX_TID);')
1020 header_txt.append(' return retVal;')
1021 header_txt.append('}')
1022 return "\n".join(header_txt)
1023
1024 def generate_body(self):
Ian Elliott81ac44c2015-01-13 17:52:38 -07001025 body = [self._generate_layer_dispatch_table_with_lock(),
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001026 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDumpCpp"),
1027 self._generate_layer_gpa_function()]
1028
1029 return "\n\n".join(body)
1030
Tobin Ehlis574b0142014-11-12 13:11:15 -07001031class ApiDumpFileSubcommand(Subcommand):
1032 def generate_header(self):
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -07001033 header_txt = []
Ian Elliott81ac44c2015-01-13 17:52:38 -07001034 header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>')
1035 header_txt.append('#include "loader_platform.h"')
1036 header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper.h"\n')
1037 header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;')
1038 header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n')
1039 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
1040 header_txt.append('static int printLockInitialized = 0;')
1041 header_txt.append('static loader_platform_thread_mutex printLock;\n')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -07001042 header_txt.append('#define MAX_TID 513')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001043 header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -07001044 header_txt.append('static uint32_t maxTID = 0;')
1045 header_txt.append('// Map actual TID to an index value and return that index')
1046 header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs')
1047 header_txt.append('static uint32_t getTIDIndex() {')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001048 header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -07001049 header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {')
1050 header_txt.append(' if (tid == tidMapping[i])')
1051 header_txt.append(' return i;')
1052 header_txt.append(' }')
1053 header_txt.append(" // Don't yet have mapping, set it and return newly set index")
Ian Elliott81ac44c2015-01-13 17:52:38 -07001054 header_txt.append(' uint32_t retVal = (uint32_t) maxTID;')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -07001055 header_txt.append(' tidMapping[maxTID++] = tid;')
1056 header_txt.append(' assert(maxTID < MAX_TID);')
1057 header_txt.append(' return retVal;')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001058 header_txt.append('}\n')
1059 header_txt.append('static FILE* pOutFile;\nstatic char* outFileName = "xgl_apidump.txt";')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -07001060 return "\n".join(header_txt)
Tobin Ehlis574b0142014-11-12 13:11:15 -07001061
1062 def generate_body(self):
Ian Elliott81ac44c2015-01-13 17:52:38 -07001063 body = [self._generate_layer_dispatch_table_with_lock(),
Tobin Ehlis907a0522014-11-25 16:59:27 -07001064 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDumpFile"),
Tobin Ehlis574b0142014-11-12 13:11:15 -07001065 self._generate_layer_gpa_function()]
1066
1067 return "\n\n".join(body)
1068
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -07001069class ApiDumpNoAddrSubcommand(Subcommand):
1070 def generate_header(self):
1071 header_txt = []
Ian Elliott81ac44c2015-01-13 17:52:38 -07001072 header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>')
1073 header_txt.append('#include "loader_platform.h"')
1074 header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper_no_addr.h"\n')
1075 header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;')
1076 header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n')
1077 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
1078 header_txt.append('static int printLockInitialized = 0;')
1079 header_txt.append('static loader_platform_thread_mutex printLock;\n')
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -07001080 header_txt.append('#define MAX_TID 513')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001081 header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};')
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -07001082 header_txt.append('static uint32_t maxTID = 0;')
1083 header_txt.append('// Map actual TID to an index value and return that index')
1084 header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs')
1085 header_txt.append('static uint32_t getTIDIndex() {')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001086 header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();')
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -07001087 header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {')
1088 header_txt.append(' if (tid == tidMapping[i])')
1089 header_txt.append(' return i;')
1090 header_txt.append(' }')
1091 header_txt.append(" // Don't yet have mapping, set it and return newly set index")
Ian Elliott81ac44c2015-01-13 17:52:38 -07001092 header_txt.append(' uint32_t retVal = (uint32_t) maxTID;')
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -07001093 header_txt.append(' tidMapping[maxTID++] = tid;')
1094 header_txt.append(' assert(maxTID < MAX_TID);')
1095 header_txt.append(' return retVal;')
1096 header_txt.append('}')
1097 return "\n".join(header_txt)
1098
1099 def generate_body(self):
Ian Elliott81ac44c2015-01-13 17:52:38 -07001100 body = [self._generate_layer_dispatch_table_with_lock(),
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -07001101 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDump", True),
1102 self._generate_layer_gpa_function()]
1103
1104 return "\n\n".join(body)
1105
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001106class ApiDumpNoAddrCppSubcommand(Subcommand):
1107 def generate_header(self):
1108 header_txt = []
Ian Elliott81ac44c2015-01-13 17:52:38 -07001109 header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>')
1110 header_txt.append('#include "loader_platform.h"')
1111 header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper_no_addr_cpp.h"\n')
1112 header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;')
1113 header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n')
1114 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
1115 header_txt.append('static int printLockInitialized = 0;')
1116 header_txt.append('static loader_platform_thread_mutex printLock;\n')
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001117 header_txt.append('#define MAX_TID 513')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001118 header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};')
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001119 header_txt.append('static uint32_t maxTID = 0;')
1120 header_txt.append('// Map actual TID to an index value and return that index')
1121 header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs')
1122 header_txt.append('static uint32_t getTIDIndex() {')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001123 header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();')
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001124 header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {')
1125 header_txt.append(' if (tid == tidMapping[i])')
1126 header_txt.append(' return i;')
1127 header_txt.append(' }')
1128 header_txt.append(" // Don't yet have mapping, set it and return newly set index")
Ian Elliott81ac44c2015-01-13 17:52:38 -07001129 header_txt.append(' uint32_t retVal = (uint32_t) maxTID;')
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001130 header_txt.append(' tidMapping[maxTID++] = tid;')
1131 header_txt.append(' assert(maxTID < MAX_TID);')
1132 header_txt.append(' return retVal;')
1133 header_txt.append('}')
1134 return "\n".join(header_txt)
1135
1136 def generate_body(self):
Ian Elliott81ac44c2015-01-13 17:52:38 -07001137 body = [self._generate_layer_dispatch_table_with_lock(),
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001138 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDumpCpp", True),
1139 self._generate_layer_gpa_function()]
1140
1141 return "\n\n".join(body)
1142
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001143class ObjectTrackerSubcommand(Subcommand):
1144 def generate_header(self):
1145 header_txt = []
Ian Elliott81ac44c2015-01-13 17:52:38 -07001146 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 -07001147 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 -07001148 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
1149 header_txt.append('static long long unsigned int object_track_index = 0;')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001150 header_txt.append('// Ptr to LL of dbg functions')
1151 header_txt.append('static XGL_LAYER_DBG_FUNCTION_NODE *pDbgFunctionHead = NULL;')
1152 header_txt.append('// Utility function to handle reporting')
1153 header_txt.append('// If callbacks are enabled, use them, otherwise use printf')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001154 header_txt.append('static void layerCbMsg(XGL_DBG_MSG_TYPE msgType,')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001155 header_txt.append(' XGL_VALIDATION_LEVEL validationLevel,')
1156 header_txt.append(' XGL_BASE_OBJECT srcObject,')
Tobin Ehlis2f3726c2015-01-15 17:51:52 -07001157 header_txt.append(' size_t location,')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001158 header_txt.append(' int32_t msgCode,')
Chia-I Wua837c522014-12-16 10:47:33 +08001159 header_txt.append(' const char* pLayerPrefix,')
1160 header_txt.append(' const char* pMsg)')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001161 header_txt.append('{')
1162 header_txt.append(' XGL_LAYER_DBG_FUNCTION_NODE *pTrav = pDbgFunctionHead;')
1163 header_txt.append(' if (pTrav) {')
1164 header_txt.append(' while (pTrav) {')
Chia-I Wu7461fcf2014-12-27 15:16:07 +08001165 header_txt.append(' pTrav->pfnMsgCallback(msgType, validationLevel, srcObject, location, msgCode, pMsg, pTrav->pUserData);')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001166 header_txt.append(' pTrav = pTrav->pNext;')
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001167 header_txt.append(' }')
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001168 header_txt.append(' }')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001169 header_txt.append(' else {')
1170 header_txt.append(' switch (msgType) {')
1171 header_txt.append(' case XGL_DBG_MSG_ERROR:')
1172 header_txt.append(' printf("{%s}ERROR : %s\\n", pLayerPrefix, pMsg);')
1173 header_txt.append(' break;')
1174 header_txt.append(' case XGL_DBG_MSG_WARNING:')
1175 header_txt.append(' printf("{%s}WARN : %s\\n", pLayerPrefix, pMsg);')
1176 header_txt.append(' break;')
1177 header_txt.append(' case XGL_DBG_MSG_PERF_WARNING:')
1178 header_txt.append(' printf("{%s}PERF_WARN : %s\\n", pLayerPrefix, pMsg);')
1179 header_txt.append(' break;')
1180 header_txt.append(' default:')
1181 header_txt.append(' printf("{%s}INFO : %s\\n", pLayerPrefix, pMsg);')
1182 header_txt.append(' break;')
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001183 header_txt.append(' }')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001184 header_txt.append(' }')
1185 header_txt.append('}')
1186 header_txt.append('// We maintain a "Global" list which links every object and a')
1187 header_txt.append('// per-Object list which just links objects of a given type')
1188 header_txt.append('// The object node has both pointers so the actual nodes are shared between the two lists')
1189 header_txt.append('typedef struct _objNode {')
1190 header_txt.append(' OBJTRACK_NODE obj;')
1191 header_txt.append(' struct _objNode *pNextObj;')
1192 header_txt.append(' struct _objNode *pNextGlobal;')
1193 header_txt.append('} objNode;')
1194 header_txt.append('static objNode *pObjectHead[XGL_NUM_OBJECT_TYPE] = {0};')
1195 header_txt.append('static objNode *pGlobalHead = NULL;')
1196 header_txt.append('static uint64_t numObjs[XGL_NUM_OBJECT_TYPE] = {0};')
1197 header_txt.append('static uint64_t numTotalObjs = 0;')
1198 header_txt.append('// Debug function to print global list and each individual object list')
1199 header_txt.append('static void ll_print_lists()')
1200 header_txt.append('{')
1201 header_txt.append(' objNode* pTrav = pGlobalHead;')
1202 header_txt.append(' printf("=====GLOBAL OBJECT LIST (%lu total objs):\\n", numTotalObjs);')
1203 header_txt.append(' while (pTrav) {')
1204 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);')
1205 header_txt.append(' pTrav = pTrav->pNextGlobal;')
1206 header_txt.append(' }')
1207 header_txt.append(' for (uint32_t i = 0; i < XGL_NUM_OBJECT_TYPE; i++) {')
1208 header_txt.append(' pTrav = pObjectHead[i];')
1209 header_txt.append(' if (pTrav) {')
1210 header_txt.append(' printf("=====%s OBJECT LIST (%lu objs):\\n", string_XGL_OBJECT_TYPE(pTrav->obj.objType), numObjs[i]);')
1211 header_txt.append(' while (pTrav) {')
1212 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);')
1213 header_txt.append(' pTrav = pTrav->pNextObj;')
1214 header_txt.append(' }')
1215 header_txt.append(' }')
1216 header_txt.append(' }')
1217 header_txt.append('}')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001218 header_txt.append('static void ll_insert_obj(void* pObj, XGL_OBJECT_TYPE objType) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001219 header_txt.append(' char str[1024];')
1220 header_txt.append(' sprintf(str, "OBJ[%llu] : CREATE %s object %p", object_track_index++, string_XGL_OBJECT_TYPE(objType), (void*)pObj);')
1221 header_txt.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_NONE, "OBJTRACK", str);')
1222 header_txt.append(' objNode* pNewObjNode = (objNode*)malloc(sizeof(objNode));')
1223 header_txt.append(' pNewObjNode->obj.pObj = pObj;')
1224 header_txt.append(' pNewObjNode->obj.objType = objType;')
Mark Lobodzinski01552702015-02-03 10:06:31 -06001225 header_txt.append(' pNewObjNode->obj.status = OBJSTATUS_NONE;')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001226 header_txt.append(' pNewObjNode->obj.numUses = 0;')
1227 header_txt.append(' // insert at front of global list')
1228 header_txt.append(' pNewObjNode->pNextGlobal = pGlobalHead;')
1229 header_txt.append(' pGlobalHead = pNewObjNode;')
1230 header_txt.append(' // insert at front of object list')
1231 header_txt.append(' pNewObjNode->pNextObj = pObjectHead[objType];')
1232 header_txt.append(' pObjectHead[objType] = pNewObjNode;')
1233 header_txt.append(' // increment obj counts')
1234 header_txt.append(' numObjs[objType]++;')
1235 header_txt.append(' numTotalObjs++;')
1236 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 +08001237 header_txt.append(' if (0) ll_print_lists();')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001238 header_txt.append('}')
1239 header_txt.append('// Traverse global list and return type for given object')
1240 header_txt.append('static XGL_OBJECT_TYPE ll_get_obj_type(XGL_OBJECT object) {')
1241 header_txt.append(' objNode *pTrav = pGlobalHead;')
1242 header_txt.append(' while (pTrav) {')
1243 header_txt.append(' if (pTrav->obj.pObj == object)')
1244 header_txt.append(' return pTrav->obj.objType;')
1245 header_txt.append(' pTrav = pTrav->pNextGlobal;')
1246 header_txt.append(' }')
1247 header_txt.append(' char str[1024];')
1248 header_txt.append(' sprintf(str, "Attempting look-up on obj %p but it is NOT in the global list!", (void*)object);')
1249 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, object, 0, OBJTRACK_MISSING_OBJECT, "OBJTRACK", str);')
1250 header_txt.append(' return XGL_OBJECT_TYPE_UNKNOWN;')
1251 header_txt.append('}')
Chia-I Wudf142a32014-12-16 11:02:06 +08001252 header_txt.append('#if 0')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001253 header_txt.append('static uint64_t ll_get_obj_uses(void* pObj, XGL_OBJECT_TYPE objType) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001254 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
1255 header_txt.append(' while (pTrav) {')
1256 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1257 header_txt.append(' return pTrav->obj.numUses;')
1258 header_txt.append(' }')
1259 header_txt.append(' pTrav = pTrav->pNextObj;')
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001260 header_txt.append(' }')
1261 header_txt.append(' return 0;')
1262 header_txt.append('}')
Chia-I Wudf142a32014-12-16 11:02:06 +08001263 header_txt.append('#endif')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001264 header_txt.append('static void ll_increment_use_count(void* pObj, XGL_OBJECT_TYPE objType) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001265 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001266 header_txt.append(' while (pTrav) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001267 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1268 header_txt.append(' pTrav->obj.numUses++;')
1269 header_txt.append(' char str[1024];')
1270 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);')
1271 header_txt.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_NONE, "OBJTRACK", str);')
1272 header_txt.append(' return;')
1273 header_txt.append(' }')
1274 header_txt.append(' pTrav = pTrav->pNextObj;')
1275 header_txt.append(' }')
1276 header_txt.append(' // If we do not find obj, insert it and then increment count')
1277 header_txt.append(' char str[1024];')
1278 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));')
1279 header_txt.append(' layerCbMsg(XGL_DBG_MSG_WARNING, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
1280 header_txt.append('')
1281 header_txt.append(' ll_insert_obj(pObj, objType);')
1282 header_txt.append(' ll_increment_use_count(pObj, objType);')
1283 header_txt.append('}')
1284 header_txt.append('// We usually do not know Obj type when we destroy it so have to fetch')
1285 header_txt.append('// Type from global list w/ ll_destroy_obj()')
1286 header_txt.append('// and then do the full removal from both lists w/ ll_remove_obj_type()')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001287 header_txt.append('static void ll_remove_obj_type(void* pObj, XGL_OBJECT_TYPE objType) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001288 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
1289 header_txt.append(' objNode *pPrev = pObjectHead[objType];')
1290 header_txt.append(' while (pTrav) {')
1291 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1292 header_txt.append(' pPrev->pNextObj = pTrav->pNextObj;')
1293 header_txt.append(' // update HEAD of Obj list as needed')
1294 header_txt.append(' if (pObjectHead[objType] == pTrav)')
1295 header_txt.append(' pObjectHead[objType] = pTrav->pNextObj;')
1296 header_txt.append(' assert(numObjs[objType] > 0);')
1297 header_txt.append(' numObjs[objType]--;')
1298 header_txt.append(' char str[1024];')
1299 header_txt.append(' sprintf(str, "OBJ[%llu] : DESTROY %s object %p", object_track_index++, string_XGL_OBJECT_TYPE(objType), (void*)pObj);')
1300 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 -06001301 header_txt.append(' return;')
1302 header_txt.append(' }')
1303 header_txt.append(' pPrev = pTrav;')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001304 header_txt.append(' pTrav = pTrav->pNextObj;')
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001305 header_txt.append(' }')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001306 header_txt.append(' char str[1024];')
1307 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));')
1308 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_INTERNAL_ERROR, "OBJTRACK", str);')
1309 header_txt.append('}')
1310 header_txt.append('// Parse global list to find obj type, then remove obj from obj type list, finally')
1311 header_txt.append('// remove obj from global list')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001312 header_txt.append('static void ll_destroy_obj(void* pObj) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001313 header_txt.append(' objNode *pTrav = pGlobalHead;')
1314 header_txt.append(' objNode *pPrev = pGlobalHead;')
1315 header_txt.append(' while (pTrav) {')
1316 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1317 header_txt.append(' ll_remove_obj_type(pObj, pTrav->obj.objType);')
1318 header_txt.append(' pPrev->pNextGlobal = pTrav->pNextGlobal;')
1319 header_txt.append(' // update HEAD of global list if needed')
1320 header_txt.append(' if (pGlobalHead == pTrav)')
1321 header_txt.append(' pGlobalHead = pTrav->pNextGlobal;')
1322 header_txt.append(' free(pTrav);')
1323 header_txt.append(' assert(numTotalObjs > 0);')
1324 header_txt.append(' numTotalObjs--;')
1325 header_txt.append(' char str[1024];')
1326 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));')
1327 header_txt.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_NONE, "OBJTRACK", str);')
1328 header_txt.append(' return;')
1329 header_txt.append(' }')
1330 header_txt.append(' pPrev = pTrav;')
1331 header_txt.append(' pTrav = pTrav->pNextGlobal;')
1332 header_txt.append(' }')
1333 header_txt.append(' char str[1024];')
1334 header_txt.append(' sprintf(str, "Unable to remove obj %p. Was it created? Has it already been destroyed?", pObj);')
1335 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 -06001336 header_txt.append('}')
Tobin Ehlis235c20e2015-01-16 08:56:30 -07001337 header_txt.append('// Set selected flag state for an object node')
1338 header_txt.append('static void set_status(void* pObj, XGL_OBJECT_TYPE objType, OBJECT_STATUS status_flag) {')
1339 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
1340 header_txt.append(' while (pTrav) {')
1341 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1342 header_txt.append(' pTrav->obj.status |= status_flag;')
1343 header_txt.append(' return;')
1344 header_txt.append(' }')
1345 header_txt.append(' pTrav = pTrav->pNextObj;')
1346 header_txt.append(' }')
1347 header_txt.append(' // If we do not find it print an error')
1348 header_txt.append(' char str[1024];')
1349 header_txt.append(' sprintf(str, "Unable to set status for non-existent object %p of %s type", pObj, string_XGL_OBJECT_TYPE(objType));')
1350 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
1351 header_txt.append('}')
1352 header_txt.append('')
Mark Lobodzinski01552702015-02-03 10:06:31 -06001353 header_txt.append('// Track selected state for an object node')
1354 header_txt.append('static void track_object_status(void* pObj, XGL_STATE_BIND_POINT stateBindPoint) {')
1355 header_txt.append(' objNode *pTrav = pObjectHead[XGL_OBJECT_TYPE_CMD_BUFFER];')
1356 header_txt.append('')
1357 header_txt.append(' while (pTrav) {')
1358 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1359 header_txt.append(' if (stateBindPoint == XGL_STATE_BIND_VIEWPORT) {')
1360 header_txt.append(' pTrav->obj.status |= OBJSTATUS_VIEWPORT_BOUND;')
1361 header_txt.append(' } else if (stateBindPoint == XGL_STATE_BIND_RASTER) {')
1362 header_txt.append(' pTrav->obj.status |= OBJSTATUS_RASTER_BOUND;')
1363 header_txt.append(' } else if (stateBindPoint == XGL_STATE_BIND_COLOR_BLEND) {')
1364 header_txt.append(' pTrav->obj.status |= OBJSTATUS_COLOR_BLEND_BOUND;')
1365 header_txt.append(' } else if (stateBindPoint == XGL_STATE_BIND_DEPTH_STENCIL) {')
1366 header_txt.append(' pTrav->obj.status |= OBJSTATUS_DEPTH_STENCIL_BOUND;')
1367 header_txt.append(' }')
1368 header_txt.append(' return;')
1369 header_txt.append(' }')
1370 header_txt.append(' pTrav = pTrav->pNextObj;')
1371 header_txt.append(' }')
1372 header_txt.append(' // If we do not find it print an error')
1373 header_txt.append(' char str[1024];')
1374 header_txt.append(' sprintf(str, "Unable to track status for non-existent Command Buffer object %p", pObj);')
1375 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
1376 header_txt.append('}')
1377 header_txt.append('')
1378 header_txt.append('// Reset selected flag state for an object node')
1379 header_txt.append('static void reset_status(void* pObj, XGL_OBJECT_TYPE objType, OBJECT_STATUS status_flag) {')
Tobin Ehlis235c20e2015-01-16 08:56:30 -07001380 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
1381 header_txt.append(' while (pTrav) {')
1382 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
Mark Lobodzinski01552702015-02-03 10:06:31 -06001383 header_txt.append(' pTrav->obj.status &= ~status_flag;')
1384 header_txt.append(' return;')
1385 header_txt.append(' }')
1386 header_txt.append(' pTrav = pTrav->pNextObj;')
1387 header_txt.append(' }')
1388 header_txt.append(' // If we do not find it print an error')
1389 header_txt.append(' char str[1024];')
1390 header_txt.append(' sprintf(str, "Unable to reset status for non-existent object %p of %s type", pObj, string_XGL_OBJECT_TYPE(objType));')
1391 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
1392 header_txt.append('}')
1393 header_txt.append('')
1394 header_txt.append('// Check object status for selected flag state')
Mark Lobodzinski4186e712015-02-03 11:52:26 -06001395 header_txt.append('static void validate_status(void* pObj, XGL_OBJECT_TYPE objType, OBJECT_STATUS status_mask, OBJECT_STATUS status_flag, XGL_DBG_MSG_TYPE error_level, OBJECT_TRACK_ERROR error_code, char* fail_msg) {')
Mark Lobodzinski01552702015-02-03 10:06:31 -06001396 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
1397 header_txt.append(' while (pTrav) {')
1398 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
Mark Lobodzinski4186e712015-02-03 11:52:26 -06001399 header_txt.append(' if ((pTrav->obj.status & status_mask) != status_flag) {')
Tobin Ehlis235c20e2015-01-16 08:56:30 -07001400 header_txt.append(' char str[1024];')
1401 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 -06001402 header_txt.append(' layerCbMsg(error_level, XGL_VALIDATION_LEVEL_0, pObj, 0, error_code, "OBJTRACK", str);')
Tobin Ehlis235c20e2015-01-16 08:56:30 -07001403 header_txt.append(' }')
1404 header_txt.append(' return;')
1405 header_txt.append(' }')
1406 header_txt.append(' pTrav = pTrav->pNextObj;')
1407 header_txt.append(' }')
1408 header_txt.append(' // If we do not find it print an error')
1409 header_txt.append(' char str[1024];')
1410 header_txt.append(' sprintf(str, "Unable to obtain status for non-existent object %p of %s type", pObj, string_XGL_OBJECT_TYPE(objType));')
1411 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
1412 header_txt.append('}')
Mark Lobodzinski01552702015-02-03 10:06:31 -06001413 header_txt.append('')
1414 header_txt.append('static void validate_draw_state_flags(void* pObj) {')
Mark Lobodzinski4186e712015-02-03 11:52:26 -06001415 header_txt.append(' validate_status((void*)pObj, XGL_OBJECT_TYPE_CMD_BUFFER, OBJSTATUS_VIEWPORT_BOUND, OBJSTATUS_VIEWPORT_BOUND, XGL_DBG_MSG_ERROR, OBJTRACK_VIEWPORT_NOT_BOUND, "Viewport object not bound to this command buffer");')
1416 header_txt.append(' validate_status((void*)pObj, XGL_OBJECT_TYPE_CMD_BUFFER, OBJSTATUS_RASTER_BOUND, OBJSTATUS_RASTER_BOUND, XGL_DBG_MSG_ERROR, OBJTRACK_RASTER_NOT_BOUND, "Raster object not bound to this command buffer");')
1417 header_txt.append(' validate_status((void*)pObj, XGL_OBJECT_TYPE_CMD_BUFFER, OBJSTATUS_COLOR_BLEND_BOUND, OBJSTATUS_COLOR_BLEND_BOUND, XGL_DBG_MSG_UNKNOWN, OBJTRACK_COLOR_BLEND_NOT_BOUND, "Color-blend object not bound to this command buffer");')
1418 header_txt.append(' validate_status((void*)pObj, XGL_OBJECT_TYPE_CMD_BUFFER, OBJSTATUS_DEPTH_STENCIL_BOUND, OBJSTATUS_DEPTH_STENCIL_BOUND, XGL_DBG_MSG_UNKNOWN, OBJTRACK_DEPTH_STENCIL_NOT_BOUND, "Depth-stencil object not bound to this command buffer");')
1419 header_txt.append('}')
1420 header_txt.append('')
1421 header_txt.append('static void validate_memory_mapping_status(const XGL_MEMORY_REF* pMemRefs, uint32_t numRefs) {')
1422 header_txt.append(' int32_t i;')
1423 header_txt.append(' for (i = 0; i < numRefs; i++) {')
1424 header_txt.append(' validate_status((void *)pMemRefs[i].mem, XGL_OBJECT_TYPE_GPU_MEMORY, OBJSTATUS_GPU_MEM_MAPPED, OBJSTATUS_NONE, XGL_DBG_MSG_ERROR, OBJTRACK_GPU_MEM_MAPPED, "A Mapped Memory Object was referenced in a command buffer");')
1425 header_txt.append(' }')
Mark Lobodzinski01552702015-02-03 10:06:31 -06001426 header_txt.append('}')
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001427 return "\n".join(header_txt)
1428
1429 def generate_body(self):
1430 body = [self._generate_layer_dispatch_table(),
Tobin Ehlis907a0522014-11-25 16:59:27 -07001431 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "ObjectTracker"),
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001432 self._generate_extensions(),
1433 self._generate_layer_gpa_function(extensions=['objTrackGetObjectCount', 'objTrackGetObjects'])]
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001434
1435 return "\n\n".join(body)
Courtney Goeltzenleuchtere6094fc2014-11-18 10:40:29 -07001436
Tobin Ehlis6cd06372014-12-17 17:44:50 -07001437class ParamCheckerSubcommand(Subcommand):
1438 def generate_header(self):
Ian Elliott81ac44c2015-01-13 17:52:38 -07001439 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 -07001440
1441 def generate_body(self):
1442 body = [self._gen_layer_dbg_callback_header(),
1443 self._generate_layer_dispatch_table(),
1444 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "ParamChecker"),
1445 self._generate_layer_gpa_function()]
1446
1447 return "\n\n".join(body)
1448
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001449def main():
1450 subcommands = {
1451 "layer-funcs" : LayerFuncsSubcommand,
1452 "layer-dispatch" : LayerDispatchSubcommand,
Tobin Ehlis907a0522014-11-25 16:59:27 -07001453 "Generic" : GenericLayerSubcommand,
1454 "ApiDump" : ApiDumpSubcommand,
1455 "ApiDumpFile" : ApiDumpFileSubcommand,
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -07001456 "ApiDumpNoAddr" : ApiDumpNoAddrSubcommand,
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001457 "ApiDumpCpp" : ApiDumpCppSubcommand,
1458 "ApiDumpNoAddrCpp" : ApiDumpNoAddrCppSubcommand,
Tobin Ehlis907a0522014-11-25 16:59:27 -07001459 "ObjectTracker" : ObjectTrackerSubcommand,
Tobin Ehlis6cd06372014-12-17 17:44:50 -07001460 "ParamChecker" : ParamCheckerSubcommand,
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001461 }
1462
Tobin Ehlis6cd06372014-12-17 17:44:50 -07001463 if len(sys.argv) < 3 or sys.argv[1] not in subcommands or not os.path.exists(sys.argv[2]):
1464 print("Usage: %s <subcommand> <input_header> [options]" % sys.argv[0])
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001465 print
Tobin Ehlis2f3726c2015-01-15 17:51:52 -07001466 print("Available subcommands are: %s" % " ".join(subcommands))
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001467 exit(1)
1468
Tobin Ehlis6cd06372014-12-17 17:44:50 -07001469 hfp = xgl_helper.HeaderFileParser(sys.argv[2])
1470 hfp.parse()
1471 xgl_helper.enum_val_dict = hfp.get_enum_val_dict()
1472 xgl_helper.enum_type_dict = hfp.get_enum_type_dict()
1473 xgl_helper.struct_dict = hfp.get_struct_dict()
1474 xgl_helper.typedef_fwd_dict = hfp.get_typedef_fwd_dict()
1475 xgl_helper.typedef_rev_dict = hfp.get_typedef_rev_dict()
1476 xgl_helper.types_dict = hfp.get_types_dict()
1477
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001478 subcmd = subcommands[sys.argv[1]](sys.argv[2:])
1479 subcmd.run()
1480
1481if __name__ == "__main__":
1482 main()