blob: 86e19d8b34cc8840b664e315b16350fde7e2aa4c [file] [log] [blame]
Tobin Ehlis12076fc2014-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 Ehlis14ff0852014-12-17 17:44:50 -070029import os
Tobin Ehlis12076fc2014-10-22 09:06:33 -060030
31import xgl
Tobin Ehlis14ff0852014-12-17 17:44:50 -070032import xgl_helper
Tobin Ehlis12076fc2014-10-22 09:06:33 -060033
34class Subcommand(object):
35 def __init__(self, argv):
36 self.argv = argv
Chia-I Wuc4f24e82015-01-01 08:46:31 +080037 self.headers = xgl.headers
38 self.protos = xgl.protos
Tobin Ehlis12076fc2014-10-22 09:06:33 -060039
40 def run(self):
Tobin Ehlis12076fc2014-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 Ehlis99f88672015-01-10 12:42:41 -070098 def _get_printf_params(self, xgl_type, name, output_param, cpp=False):
Tobin Ehlis12076fc2014-10-22 09:06:33 -060099 # TODO : Need ENUM and STRUCT checks here
Tobin Ehlis7e65d752015-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 Ehlis12076fc2014-10-22 09:06:33 -0600101 return ("%s", "string_%s(%s)" % (xgl_type.strip('const ').strip('*'), name))
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600102 if "char*" == xgl_type:
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600103 return ("%s", name)
Tobin Ehlis7e65d752015-01-15 17:51:52 -0700104 if "uint64" in xgl_type:
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600105 if '*' in xgl_type:
106 return ("%lu", "*%s" % name)
107 return ("%lu", name)
Tobin Ehlis7e65d752015-01-15 17:51:52 -0700108 if "size" in xgl_type:
Chia-I Wu99ff89d2014-12-27 14:14:50 +0800109 if '*' in xgl_type:
110 return ("%zu", "*%s" % name)
111 return ("%zu", name)
Tobin Ehlis7e65d752015-01-15 17:51:52 -0700112 if "float" in xgl_type:
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600113 if '[' in xgl_type: # handle array, current hard-coded to 4 (TODO: Make this dynamic)
Tobin Ehlis99f88672015-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 Ehlis12076fc2014-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 Ehlis7e65d752015-01-15 17:51:52 -0700118 if "bool" in xgl_type or 'xcb_randr_crtc_t' in xgl_type:
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600119 return ("%u", name)
Tobin Ehlis7e65d752015-01-15 17:51:52 -0700120 if True in [t in xgl_type for t in ["int", "FLAGS", "MASK", "xcb_window_t"]]:
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600121 if '[' in xgl_type: # handle array, current hard-coded to 4 (TODO: Make this dynamic)
Tobin Ehlis99f88672015-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 Ehlis12076fc2014-10-22 09:06:33 -0600124 return ("[%i, %i, %i, %i]", "%s[0], %s[1], %s[2], %s[3]" % (name, name, name, name))
125 if '*' in xgl_type:
Tobin Ehlisd2b88e82015-02-04 15:15:11 -0700126 if 'pUserData' == name:
127 return ("%i", "((pUserData == 0) ? 0 : *(pUserData))")
Jon Ashburn52f79b52014-12-12 16:10:45 -0700128 return ("%i", "*(%s)" % name)
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600129 return ("%i", name)
Tobin Ehlis3a1cc8d2014-11-11 17:28:22 -0700130 # TODO : This is special-cased as there's only one "format" param currently and it's nice to expand it
Jon Ashburn52f79b52014-12-12 16:10:45 -0700131 if "XGL_FORMAT" == xgl_type:
Tobin Ehlis99f88672015-01-10 12:42:41 -0700132 if cpp:
133 return ("%p", "&%s" % name)
134 return ("{%s.channelFormat = %%s, %s.numericFormat = %%s}" % (name, name), "string_XGL_CHANNEL_FORMAT(%s.channelFormat), string_XGL_NUM_FORMAT(%s.numericFormat)" % (name, name))
Tobin Ehlise7271572014-11-19 15:52:46 -0700135 if output_param:
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600136 return ("%p", "(void*)*%s" % name)
Jon Ashburn52f79b52014-12-12 16:10:45 -0700137 return ("%p", "(void*)(%s)" % name)
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600138
Tobin Ehlise8185062014-12-17 08:01:59 -0700139 def _gen_layer_dbg_callback_register(self):
140 r_body = []
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600141 r_body.append('XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglDbgRegisterMsgCallback(XGL_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback, void* pUserData)')
Tobin Ehlise8185062014-12-17 08:01:59 -0700142 r_body.append('{')
143 r_body.append(' // This layer intercepts callbacks')
144 r_body.append(' XGL_LAYER_DBG_FUNCTION_NODE *pNewDbgFuncNode = (XGL_LAYER_DBG_FUNCTION_NODE*)malloc(sizeof(XGL_LAYER_DBG_FUNCTION_NODE));')
145 r_body.append(' if (!pNewDbgFuncNode)')
146 r_body.append(' return XGL_ERROR_OUT_OF_MEMORY;')
147 r_body.append(' pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;')
148 r_body.append(' pNewDbgFuncNode->pUserData = pUserData;')
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700149 r_body.append(' pNewDbgFuncNode->pNext = g_pDbgFunctionHead;')
150 r_body.append(' g_pDbgFunctionHead = pNewDbgFuncNode;')
Jon Ashburna8aa8372015-03-03 15:07:15 -0700151 r_body.append(' // force callbacks if DebugAction hasn\'t been set already other than initial value')
Ian Elliott6d9e41e2015-03-05 12:28:53 -0700152 r_body.append(' if (g_actionIsDefault) {')
Jon Ashburna8aa8372015-03-03 15:07:15 -0700153 r_body.append(' g_debugAction = XGL_DBG_LAYER_ACTION_CALLBACK;')
Ian Elliott6d9e41e2015-03-05 12:28:53 -0700154 r_body.append(' }')
Tobin Ehlise8185062014-12-17 08:01:59 -0700155 r_body.append(' XGL_RESULT result = nextTable.DbgRegisterMsgCallback(pfnMsgCallback, pUserData);')
156 r_body.append(' return result;')
157 r_body.append('}')
158 return "\n".join(r_body)
159
160 def _gen_layer_dbg_callback_unregister(self):
161 ur_body = []
162 ur_body.append('XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglDbgUnregisterMsgCallback(XGL_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback)')
163 ur_body.append('{')
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700164 ur_body.append(' XGL_LAYER_DBG_FUNCTION_NODE *pTrav = g_pDbgFunctionHead;')
Tobin Ehlise8185062014-12-17 08:01:59 -0700165 ur_body.append(' XGL_LAYER_DBG_FUNCTION_NODE *pPrev = pTrav;')
166 ur_body.append(' while (pTrav) {')
167 ur_body.append(' if (pTrav->pfnMsgCallback == pfnMsgCallback) {')
168 ur_body.append(' pPrev->pNext = pTrav->pNext;')
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700169 ur_body.append(' if (g_pDbgFunctionHead == pTrav)')
170 ur_body.append(' g_pDbgFunctionHead = pTrav->pNext;')
Tobin Ehlise8185062014-12-17 08:01:59 -0700171 ur_body.append(' free(pTrav);')
172 ur_body.append(' break;')
173 ur_body.append(' }')
174 ur_body.append(' pPrev = pTrav;')
175 ur_body.append(' pTrav = pTrav->pNext;')
176 ur_body.append(' }')
Jon Ashburna8aa8372015-03-03 15:07:15 -0700177 ur_body.append(' if (g_pDbgFunctionHead == NULL)')
178 ur_body.append(' {')
179 ur_body.append(' if (g_actionIsDefault)')
180 ur_body.append(' g_debugAction = XGL_DBG_LAYER_ACTION_LOG_MSG;')
181 ur_body.append(' else')
182 ur_body.append(' g_debugAction &= ~XGL_DBG_LAYER_ACTION_CALLBACK;')
183 ur_body.append(' }')
Tobin Ehlise8185062014-12-17 08:01:59 -0700184 ur_body.append(' XGL_RESULT result = nextTable.DbgUnregisterMsgCallback(pfnMsgCallback);')
185 ur_body.append(' return result;')
186 ur_body.append('}')
187 return "\n".join(ur_body)
188
Tobin Ehlisd49efcb2014-11-25 17:43:26 -0700189 def _generate_dispatch_entrypoints(self, qual="", layer="Generic", no_addr=False):
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600190 if qual:
191 qual += " "
192
Tobin Ehlisa363cfa2014-11-25 16:59:27 -0700193 layer_name = layer
Tobin Ehlisd49efcb2014-11-25 17:43:26 -0700194 if no_addr:
195 layer_name = "%sNoAddr" % layer
Tobin Ehlis99f88672015-01-10 12:42:41 -0700196 if 'Cpp' in layer_name:
197 layer_name = "APIDumpNoAddrCpp"
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600198 funcs = []
199 for proto in self.protos:
200 if proto.name != "GetProcAddr" and proto.name != "InitAndEnumerateGpus":
Tobin Ehlisa363cfa2014-11-25 16:59:27 -0700201 if "Generic" == layer:
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600202 decl = proto.c_func(prefix="xgl", attr="XGLAPI")
203 param0_name = proto.params[0].name
204 ret_val = ''
205 stmt = ''
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600206 if proto.ret != "void":
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600207 ret_val = "XGL_RESULT result = "
208 stmt = " return result;\n"
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700209 if 'WsiX11AssociateConnection' == proto.name:
Ian Elliottd1597d22015-02-26 14:34:52 -0700210 funcs.append("#if defined(__linux__) || defined(XCB_NVIDIA)")
Jon Ashburnf7a08742014-11-25 11:08:42 -0700211 if proto.name == "EnumerateLayers":
212 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
213 funcs.append('%s%s\n'
214 '{\n'
Tobin Ehlise8185062014-12-17 08:01:59 -0700215 ' char str[1024];\n'
Jon Ashburnf7a08742014-11-25 11:08:42 -0700216 ' if (gpu != NULL) {\n'
217 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
Tobin Ehlise8185062014-12-17 08:01:59 -0700218 ' sprintf(str, "At start of layered %s\\n");\n'
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600219 ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpu, 0, 0, (char *) "GENERIC", (char *) str);\n'
Jon Ashburnf7a08742014-11-25 11:08:42 -0700220 ' pCurObj = gpuw;\n'
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700221 ' loader_platform_thread_once(&tabOnce, init%s);\n'
Jon Ashburnf7a08742014-11-25 11:08:42 -0700222 ' %snextTable.%s;\n'
Tobin Ehlise8185062014-12-17 08:01:59 -0700223 ' sprintf(str, "Completed layered %s\\n");\n'
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600224 ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpu, 0, 0, (char *) "GENERIC", (char *) str);\n'
Jon Ashburnf7a08742014-11-25 11:08:42 -0700225 ' fflush(stdout);\n'
226 ' %s'
227 ' } else {\n'
228 ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n'
229 ' return XGL_ERROR_INVALID_POINTER;\n'
230 ' // This layer compatible with all GPUs\n'
231 ' *pOutLayerCount = 1;\n'
Chia-I Wu1da4b9f2014-12-16 10:47:33 +0800232 ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n'
Jon Ashburnf7a08742014-11-25 11:08:42 -0700233 ' return XGL_SUCCESS;\n'
234 ' }\n'
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700235 '}' % (qual, decl, proto.params[0].name, proto.name, layer_name, ret_val, c_call, proto.name, stmt, layer_name))
Tobin Ehlise8185062014-12-17 08:01:59 -0700236 elif 'DbgRegisterMsgCallback' == proto.name:
237 funcs.append(self._gen_layer_dbg_callback_register())
238 elif 'DbgUnregisterMsgCallback' == proto.name:
239 funcs.append(self._gen_layer_dbg_callback_unregister())
Jon Ashburnf7a08742014-11-25 11:08:42 -0700240 elif proto.params[0].ty != "XGL_PHYSICAL_GPU":
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600241 funcs.append('%s%s\n'
242 '{\n'
243 ' %snextTable.%s;\n'
244 '%s'
245 '}' % (qual, decl, ret_val, proto.c_call(), stmt))
246 else:
247 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
248 funcs.append('%s%s\n'
249 '{\n'
Tobin Ehlise8185062014-12-17 08:01:59 -0700250 ' char str[1024];'
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600251 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
Tobin Ehlise8185062014-12-17 08:01:59 -0700252 ' sprintf(str, "At start of layered %s\\n");\n'
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600253 ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpuw, 0, 0, (char *) "GENERIC", (char *) str);\n'
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600254 ' pCurObj = gpuw;\n'
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700255 ' loader_platform_thread_once(&tabOnce, init%s);\n'
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600256 ' %snextTable.%s;\n'
Tobin Ehlise8185062014-12-17 08:01:59 -0700257 ' sprintf(str, "Completed layered %s\\n");\n'
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600258 ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpuw, 0, 0, (char *) "GENERIC", (char *) str);\n'
Courtney Goeltzenleuchterb412d212014-11-18 10:40:29 -0700259 ' fflush(stdout);\n'
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600260 '%s'
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700261 '}' % (qual, decl, proto.params[0].name, proto.name, layer_name, ret_val, c_call, proto.name, stmt))
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700262 if 'WsiX11QueuePresent' == proto.name:
263 funcs.append("#endif")
Tobin Ehlis99f88672015-01-10 12:42:41 -0700264 elif "APIDumpCpp" in layer:
265 decl = proto.c_func(prefix="xgl", attr="XGLAPI")
266 param0_name = proto.params[0].name
267 ret_val = ''
268 stmt = ''
Tobin Ehlis291cd702015-01-20 09:48:48 -0700269 sp_param_dict = {} # Store 'index' for struct param to print, or an name of binding "Count" param for array to print
Tobin Ehlis99f88672015-01-10 12:42:41 -0700270 create_params = 0 # Num of params at end of function that are created and returned as output values
Tobin Ehlis291cd702015-01-20 09:48:48 -0700271 if 'WsiX11CreatePresentableImage' in proto.name or 'AllocDescriptorSets' in proto.name:
Tobin Ehlis99f88672015-01-10 12:42:41 -0700272 create_params = -2
273 elif 'Create' in proto.name or 'Alloc' in proto.name or 'MapMemory' in proto.name:
274 create_params = -1
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600275 if proto.ret != "void":
Tobin Ehlis99f88672015-01-10 12:42:41 -0700276 ret_val = "XGL_RESULT result = "
277 stmt = " return result;\n"
278 f_open = ''
279 f_close = ''
280 if "File" in layer:
281 file_mode = "a"
282 if 'CreateDevice' in proto.name:
283 file_mode = "w"
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700284 f_open = 'loader_platform_thread_lock_mutex(&printLock);\n pOutFile = fopen(outFileName, "%s");\n ' % (file_mode)
Tobin Ehlis99f88672015-01-10 12:42:41 -0700285 log_func = 'fprintf(pOutFile, "t{%%u} xgl%s(' % proto.name
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700286 f_close = '\n fclose(pOutFile);\n loader_platform_thread_unlock_mutex(&printLock);'
Tobin Ehlis99f88672015-01-10 12:42:41 -0700287 else:
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700288 f_open = 'loader_platform_thread_lock_mutex(&printLock);\n '
Tobin Ehlis99f88672015-01-10 12:42:41 -0700289 log_func = 'cout << "t{" << getTIDIndex() << "} xgl%s(' % proto.name
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700290 f_close = '\n loader_platform_thread_unlock_mutex(&printLock);'
Tobin Ehlis99f88672015-01-10 12:42:41 -0700291 pindex = 0
Tobin Ehlis291cd702015-01-20 09:48:48 -0700292 prev_count_name = ''
Tobin Ehlis99f88672015-01-10 12:42:41 -0700293 for p in proto.params:
Tobin Ehlis99f88672015-01-10 12:42:41 -0700294 cp = False
295 if 0 != create_params:
296 # If this is any of the N last params of the func, treat as output
297 for y in range(-1, create_params-1, -1):
298 if p.name == proto.params[y].name:
299 cp = True
300 (pft, pfi) = self._get_printf_params(p.ty, p.name, cp, cpp=True)
301 if no_addr and "%p" == pft:
302 (pft, pfi) = ("%s", '"addr"')
303 log_func += '%s = " << %s << ", ' % (p.name, pfi)
304 #print_vals += ', %s' % (pfi)
Tobin Ehlis291cd702015-01-20 09:48:48 -0700305 if prev_count_name != '' and (prev_count_name.strip('Count')[1:] in p.name or 'slotCount' == prev_count_name):
306 sp_param_dict[pindex] = prev_count_name
307 elif 'pDescriptorSets' == p.name and proto.params[-1].name == 'pCount':
308 sp_param_dict[pindex] = '*pCount'
Tobin Ehlisf29cc372015-01-22 12:29:31 -0700309 elif 'Wsi' not in proto.name and xgl_helper.is_type(p.ty.strip('*').strip('const '), 'struct'):
310 sp_param_dict[pindex] = 'index'
Tobin Ehlis99f88672015-01-10 12:42:41 -0700311 pindex += 1
Tobin Ehlis291cd702015-01-20 09:48:48 -0700312 if p.name.endswith('Count'):
313 if '*' in p.ty:
314 prev_count_name = "*%s" % p.name
315 else:
316 prev_count_name = p.name
317 else:
318 prev_count_name = ''
Tobin Ehlis99f88672015-01-10 12:42:41 -0700319 log_func = log_func.strip(', ')
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600320 if proto.ret != "void":
Courtney Goeltzenleuchterb7f22da2015-02-26 11:40:39 -0700321 log_func += ') = " << string_XGL_RESULT((XGL_RESULT)result) << endl'
Tobin Ehlis7e65d752015-01-15 17:51:52 -0700322 #print_vals += ', string_XGL_RESULT_CODE(result)'
Tobin Ehlis99f88672015-01-10 12:42:41 -0700323 else:
324 log_func += ')\\n"'
325 log_func += ';'
Tobin Ehlis291cd702015-01-20 09:48:48 -0700326 if len(sp_param_dict) > 0:
327 i_decl = False
Tobin Ehlis99f88672015-01-10 12:42:41 -0700328 log_func += '\n string tmp_str;'
Tobin Ehlis291cd702015-01-20 09:48:48 -0700329 for sp_index in sp_param_dict:
330 if 'index' == sp_param_dict[sp_index]:
331 cis_print_func = 'xgl_print_%s' % (proto.params[sp_index].ty.strip('const ').strip('*').lower())
332 log_func += '\n if (%s) {' % (proto.params[sp_index].name)
333 log_func += '\n tmp_str = %s(%s, " ");' % (cis_print_func, proto.params[sp_index].name)
334 if "File" in layer:
335 if no_addr:
336 log_func += '\n fprintf(pOutFile, " %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name)
337 else:
338 log_func += '\n fprintf(pOutFile, " %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name)
Tobin Ehlis99f88672015-01-10 12:42:41 -0700339 else:
Tobin Ehlis291cd702015-01-20 09:48:48 -0700340 if no_addr:
341 #log_func += '\n printf(" %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name)
342 log_func += '\n cout << " %s (addr)" << endl << tmp_str << endl;' % (proto.params[sp_index].name)
343 else:
344 #log_func += '\n printf(" %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name)
345 log_func += '\n cout << " %s (" << %s << ")" << endl << tmp_str << endl;' % (proto.params[sp_index].name, proto.params[sp_index].name)
346 #log_func += '\n fflush(stdout);'
347 log_func += '\n }'
348 else: # We have a count value stored to iterate over an array
349 print_cast = ''
350 print_func = ''
351 if xgl_helper.is_type(proto.params[sp_index].ty.strip('*').strip('const '), 'struct'):
352 print_cast = '&'
353 print_func = 'xgl_print_%s' % proto.params[sp_index].ty.strip('const ').strip('*').lower()
354 #cis_print_func = 'tmp_str = xgl_print_%s(&%s[i], " ");' % (proto.params[sp_index].ty.strip('const ').strip('*').lower(), proto.params[sp_index].name)
355# TODO : Need to display this address as a string
Tobin Ehlis99f88672015-01-10 12:42:41 -0700356 else:
Tobin Ehlis291cd702015-01-20 09:48:48 -0700357 print_cast = '(void*)'
358 print_func = 'string_convert_helper'
359 #cis_print_func = 'tmp_str = string_convert_helper((void*)%s[i], " ");' % proto.params[sp_index].name
360 cis_print_func = 'tmp_str = %s(%s%s[i], " ");' % (print_func, print_cast, proto.params[sp_index].name)
361# else:
362# cis_print_func = ''
363 if not i_decl:
364 log_func += '\n uint32_t i;'
365 i_decl = True
366 log_func += '\n for (i = 0; i < %s; i++) {' % (sp_param_dict[sp_index])
367 log_func += '\n %s' % (cis_print_func)
368 if "File" in layer:
369 if no_addr:
370 log_func += '\n fprintf(pOutFile, " %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name)
371 else:
372 log_func += '\n fprintf(pOutFile, " %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name)
373 else:
374 if no_addr:
375 #log_func += '\n printf(" %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name)
376 log_func += '\n cout << " %s[" << (uint32_t)i << "] (addr)" << endl << tmp_str << endl;' % (proto.params[sp_index].name)
377 else:
378 #log_func += '\n printf(" %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name)
379 #log_func += '\n cout << " %s[" << (uint32_t)i << "] (" << %s[i] << ")" << endl << tmp_str << endl;' % (proto.params[sp_index].name, proto.params[sp_index].name)
380 log_func += '\n cout << " %s[" << i << "] (" << %s%s[i] << ")" << endl << tmp_str << endl;' % (proto.params[sp_index].name, print_cast, proto.params[sp_index].name)
381 #log_func += '\n fflush(stdout);'
382 log_func += '\n }'
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700383 if 'WsiX11AssociateConnection' == proto.name:
Ian Elliottd1597d22015-02-26 14:34:52 -0700384 funcs.append("#if defined(__linux__) || defined(XCB_NVIDIA)")
Tobin Ehlis99f88672015-01-10 12:42:41 -0700385 if proto.name == "EnumerateLayers":
386 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
387 funcs.append('%s%s\n'
388 '{\n'
389 ' if (gpu != NULL) {\n'
390 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
391 ' pCurObj = gpuw;\n'
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700392 ' loader_platform_thread_once(&tabOnce, init%s);\n'
Tobin Ehlis99f88672015-01-10 12:42:41 -0700393 ' %snextTable.%s;\n'
394 ' %s %s %s\n'
395 ' %s'
396 ' } else {\n'
397 ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n'
398 ' return XGL_ERROR_INVALID_POINTER;\n'
399 ' // This layer compatible with all GPUs\n'
400 ' *pOutLayerCount = 1;\n'
401 ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n'
402 ' return XGL_SUCCESS;\n'
403 ' }\n'
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700404 '}' % (qual, decl, proto.params[0].name, layer_name, ret_val, c_call,f_open, log_func, f_close, stmt, layer_name))
Tobin Ehlis99f88672015-01-10 12:42:41 -0700405 elif proto.params[0].ty != "XGL_PHYSICAL_GPU":
406 funcs.append('%s%s\n'
407 '{\n'
408 ' %snextTable.%s;\n'
409 ' %s%s%s\n'
410 '%s'
411 '}' % (qual, decl, ret_val, proto.c_call(), f_open, log_func, f_close, stmt))
412 else:
413 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
414 funcs.append('%s%s\n'
415 '{\n'
416 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
417 ' pCurObj = gpuw;\n'
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700418 ' loader_platform_thread_once(&tabOnce, init%s);\n'
Tobin Ehlis99f88672015-01-10 12:42:41 -0700419 ' %snextTable.%s;\n'
420 ' %s%s%s\n'
421 '%s'
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700422 '}' % (qual, decl, proto.params[0].name, layer_name, ret_val, c_call, f_open, log_func, f_close, stmt))
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700423 if 'WsiX11QueuePresent' == proto.name:
424 funcs.append("#endif")
Tobin Ehlisa363cfa2014-11-25 16:59:27 -0700425 elif "APIDump" in layer:
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600426 decl = proto.c_func(prefix="xgl", attr="XGLAPI")
427 param0_name = proto.params[0].name
428 ret_val = ''
429 stmt = ''
Tobin Ehlis291cd702015-01-20 09:48:48 -0700430 sp_param_dict = {} # Store 'index' for struct param to print, or an name of binding "Count" param for array to print
Tobin Ehlise7271572014-11-19 15:52:46 -0700431 create_params = 0 # Num of params at end of function that are created and returned as output values
432 if 'WsiX11CreatePresentableImage' in proto.name:
433 create_params = -2
434 elif 'Create' in proto.name or 'Alloc' in proto.name or 'MapMemory' in proto.name:
435 create_params = -1
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600436 if proto.ret != "void":
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600437 ret_val = "XGL_RESULT result = "
438 stmt = " return result;\n"
Tobin Ehlisea3d21b2014-11-12 13:11:15 -0700439 f_open = ''
440 f_close = ''
Tobin Ehlisa363cfa2014-11-25 16:59:27 -0700441 if "File" in layer:
Tobin Ehlisdbcd2572014-11-21 09:35:53 -0700442 file_mode = "a"
443 if 'CreateDevice' in proto.name:
444 file_mode = "w"
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700445 f_open = 'loader_platform_thread_lock_mutex(&printLock);\n pOutFile = fopen(outFileName, "%s");\n ' % (file_mode)
Tobin Ehlisd009bae2014-11-24 15:46:55 -0700446 log_func = 'fprintf(pOutFile, "t{%%u} xgl%s(' % proto.name
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700447 f_close = '\n fclose(pOutFile);\n loader_platform_thread_unlock_mutex(&printLock);'
Tobin Ehlisea3d21b2014-11-12 13:11:15 -0700448 else:
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700449 f_open = 'loader_platform_thread_lock_mutex(&printLock);\n '
Tobin Ehlisd009bae2014-11-24 15:46:55 -0700450 log_func = 'printf("t{%%u} xgl%s(' % proto.name
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700451 f_close = '\n loader_platform_thread_unlock_mutex(&printLock);'
Tobin Ehlisd009bae2014-11-24 15:46:55 -0700452 print_vals = ', getTIDIndex()'
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600453 pindex = 0
Tobin Ehlis3bd868a2014-12-18 15:20:05 -0700454 prev_count_name = ''
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600455 for p in proto.params:
Tobin Ehlise7271572014-11-19 15:52:46 -0700456 cp = False
457 if 0 != create_params:
458 # If this is any of the N last params of the func, treat as output
459 for y in range(-1, create_params-1, -1):
460 if p.name == proto.params[y].name:
461 cp = True
462 (pft, pfi) = self._get_printf_params(p.ty, p.name, cp)
Tobin Ehlisd49efcb2014-11-25 17:43:26 -0700463 if no_addr and "%p" == pft:
464 (pft, pfi) = ("%s", '"addr"')
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600465 log_func += '%s = %s, ' % (p.name, pft)
466 print_vals += ', %s' % (pfi)
Tobin Ehlis3bd868a2014-12-18 15:20:05 -0700467 # Catch array inputs that are bound by a "Count" param
468 if prev_count_name != '' and (prev_count_name.strip('Count')[1:] in p.name or 'slotCount' == prev_count_name):
469 sp_param_dict[pindex] = prev_count_name
Tobin Ehlis291cd702015-01-20 09:48:48 -0700470 elif 'pDescriptorSets' == p.name and proto.params[-1].name == 'pCount':
471 sp_param_dict[pindex] = '*pCount'
Tobin Ehlis7e65d752015-01-15 17:51:52 -0700472 elif 'Wsi' not in proto.name and xgl_helper.is_type(p.ty.strip('*').strip('const '), 'struct'):
Tobin Ehlis3bd868a2014-12-18 15:20:05 -0700473 sp_param_dict[pindex] = 'index'
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600474 pindex += 1
Tobin Ehlis3bd868a2014-12-18 15:20:05 -0700475 if p.name.endswith('Count'):
Courtney Goeltzenleuchter1b587b12015-01-13 15:32:18 -0700476 if '*' in p.ty:
477 prev_count_name = "*%s" % p.name
478 else:
479 prev_count_name = p.name
Tobin Ehlis3bd868a2014-12-18 15:20:05 -0700480 else:
481 prev_count_name = ''
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600482 log_func = log_func.strip(', ')
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600483 if proto.ret != "void":
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600484 log_func += ') = %s\\n"'
Courtney Goeltzenleuchterb412d212014-11-18 10:40:29 -0700485 print_vals += ', string_XGL_RESULT(result)'
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600486 else:
487 log_func += ')\\n"'
488 log_func = '%s%s);' % (log_func, print_vals)
Tobin Ehlis3bd868a2014-12-18 15:20:05 -0700489 if len(sp_param_dict) > 0:
490 i_decl = False
491 log_func += '\n char *pTmpStr = "";'
492 for sp_index in sorted(sp_param_dict):
493 # TODO : Clean this if/else block up, too much duplicated code
494 if 'index' == sp_param_dict[sp_index]:
495 cis_print_func = 'xgl_print_%s' % (proto.params[sp_index].ty.strip('const ').strip('*').lower())
496 log_func += '\n if (%s) {' % (proto.params[sp_index].name)
497 log_func += '\n pTmpStr = %s(%s, " ");' % (cis_print_func, proto.params[sp_index].name)
498 if "File" in layer:
499 if no_addr:
500 log_func += '\n fprintf(pOutFile, " %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name)
501 else:
502 log_func += '\n fprintf(pOutFile, " %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name)
Tobin Ehlisd49efcb2014-11-25 17:43:26 -0700503 else:
Tobin Ehlis3bd868a2014-12-18 15:20:05 -0700504 if no_addr:
505 log_func += '\n printf(" %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name)
506 else:
507 log_func += '\n printf(" %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name)
508 log_func += '\n fflush(stdout);'
509 log_func += '\n free(pTmpStr);\n }'
510 else: # should have a count value stored to iterate over array
511 if xgl_helper.is_type(proto.params[sp_index].ty.strip('*').strip('const '), 'struct'):
512 cis_print_func = 'pTmpStr = xgl_print_%s(&%s[i], " ");' % (proto.params[sp_index].ty.strip('const ').strip('*').lower(), proto.params[sp_index].name)
Tobin Ehlisd49efcb2014-11-25 17:43:26 -0700513 else:
Mike Stroyanb30f3ed2015-03-03 16:54:24 -0700514 cis_print_func = 'pTmpStr = (char*)malloc(32);\n sprintf(pTmpStr, " %%p", %s[i]);' % proto.params[sp_index].name
Tobin Ehlis3bd868a2014-12-18 15:20:05 -0700515 if not i_decl:
516 log_func += '\n uint32_t i;'
517 i_decl = True
Jon Ashburn8219c042015-01-14 08:52:37 -0700518 log_func += '\n for (i = 0; i < %s; i++) {' % (sp_param_dict[sp_index])
Tobin Ehlis3bd868a2014-12-18 15:20:05 -0700519 log_func += '\n %s' % (cis_print_func)
520 if "File" in layer:
521 if no_addr:
522 log_func += '\n fprintf(pOutFile, " %s[%%i] (addr)\\n%%s\\n", i, pTmpStr);' % (proto.params[sp_index].name)
523 else:
524 log_func += '\n fprintf(pOutFile, " %s[%%i] (%%p)\\n%%s\\n", i, (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name)
525 else:
526 if no_addr:
527 log_func += '\n printf(" %s[%%i] (addr)\\n%%s\\n", i, pTmpStr);' % (proto.params[sp_index].name)
528 else:
529 log_func += '\n printf(" %s[%%i] (%%p)\\n%%s\\n", i, (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name)
530 log_func += '\n fflush(stdout);'
531 log_func += '\n free(pTmpStr);\n }'
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700532 if 'WsiX11AssociateConnection' == proto.name:
Ian Elliottd1597d22015-02-26 14:34:52 -0700533 funcs.append("#if defined(__linux__) || defined(XCB_NVIDIA)")
Jon Ashburnf7a08742014-11-25 11:08:42 -0700534 if proto.name == "EnumerateLayers":
535 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
536 funcs.append('%s%s\n'
537 '{\n'
538 ' if (gpu != NULL) {\n'
539 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
540 ' pCurObj = gpuw;\n'
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700541 ' loader_platform_thread_once(&tabOnce, init%s);\n'
Jon Ashburnf7a08742014-11-25 11:08:42 -0700542 ' %snextTable.%s;\n'
543 ' %s %s %s\n'
544 ' %s'
545 ' } else {\n'
546 ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n'
547 ' return XGL_ERROR_INVALID_POINTER;\n'
548 ' // This layer compatible with all GPUs\n'
549 ' *pOutLayerCount = 1;\n'
Chia-I Wu1da4b9f2014-12-16 10:47:33 +0800550 ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n'
Jon Ashburnf7a08742014-11-25 11:08:42 -0700551 ' return XGL_SUCCESS;\n'
552 ' }\n'
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700553 '}' % (qual, decl, proto.params[0].name, layer_name, ret_val, c_call,f_open, log_func, f_close, stmt, layer_name))
Jon Ashburnf7a08742014-11-25 11:08:42 -0700554 elif proto.params[0].ty != "XGL_PHYSICAL_GPU":
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600555 funcs.append('%s%s\n'
556 '{\n'
557 ' %snextTable.%s;\n'
Tobin Ehlisea3d21b2014-11-12 13:11:15 -0700558 ' %s%s%s\n'
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600559 '%s'
Tobin Ehlisea3d21b2014-11-12 13:11:15 -0700560 '}' % (qual, decl, ret_val, proto.c_call(), f_open, log_func, f_close, stmt))
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600561 else:
562 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
563 funcs.append('%s%s\n'
564 '{\n'
565 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
566 ' pCurObj = gpuw;\n'
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700567 ' loader_platform_thread_once(&tabOnce, init%s);\n'
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600568 ' %snextTable.%s;\n'
Tobin Ehlisea3d21b2014-11-12 13:11:15 -0700569 ' %s%s%s\n'
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600570 '%s'
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700571 '}' % (qual, decl, proto.params[0].name, layer_name, ret_val, c_call, f_open, log_func, f_close, stmt))
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700572 if 'WsiX11QueuePresent' == proto.name:
573 funcs.append("#endif")
Tobin Ehlisa363cfa2014-11-25 16:59:27 -0700574 elif "ObjectTracker" == layer:
Tobin Ehlis7e65d752015-01-15 17:51:52 -0700575 obj_type_mapping = {base_t : base_t.replace("XGL_", "XGL_OBJECT_TYPE_") for base_t in xgl.object_type_list}
576 # For the various "super-types" we have to use function to distinguish sub type
577 for obj_type in ["XGL_BASE_OBJECT", "XGL_OBJECT", "XGL_DYNAMIC_STATE_OBJECT"]:
578 obj_type_mapping[obj_type] = "ll_get_obj_type(object)"
Tobin Ehlisca915872014-11-18 11:28:33 -0700579
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600580 decl = proto.c_func(prefix="xgl", attr="XGLAPI")
581 param0_name = proto.params[0].name
Tobin Ehlis7e65d752015-01-15 17:51:52 -0700582 p0_type = proto.params[0].ty.strip('*').strip('const ')
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600583 create_line = ''
584 destroy_line = ''
Tobin Ehlisca915872014-11-18 11:28:33 -0700585 if 'DbgRegisterMsgCallback' in proto.name:
586 using_line = ' // This layer intercepts callbacks\n'
587 using_line += ' XGL_LAYER_DBG_FUNCTION_NODE *pNewDbgFuncNode = (XGL_LAYER_DBG_FUNCTION_NODE*)malloc(sizeof(XGL_LAYER_DBG_FUNCTION_NODE));\n'
588 using_line += ' if (!pNewDbgFuncNode)\n'
589 using_line += ' return XGL_ERROR_OUT_OF_MEMORY;\n'
590 using_line += ' pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;\n'
591 using_line += ' pNewDbgFuncNode->pUserData = pUserData;\n'
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700592 using_line += ' pNewDbgFuncNode->pNext = g_pDbgFunctionHead;\n'
593 using_line += ' g_pDbgFunctionHead = pNewDbgFuncNode;\n'
Jon Ashburna8aa8372015-03-03 15:07:15 -0700594 using_line += ' // force callbacks if DebugAction hasn\'t been set already other than initial value\n'
Ian Elliott6d9e41e2015-03-05 12:28:53 -0700595 using_line += ' if (g_actionIsDefault) {\n'
Jon Ashburna8aa8372015-03-03 15:07:15 -0700596 using_line += ' g_debugAction = XGL_DBG_LAYER_ACTION_CALLBACK;\n'
Ian Elliott6d9e41e2015-03-05 12:28:53 -0700597 using_line += ' }'
Tobin Ehlisca915872014-11-18 11:28:33 -0700598 elif 'DbgUnregisterMsgCallback' in proto.name:
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700599 using_line = ' XGL_LAYER_DBG_FUNCTION_NODE *pTrav = g_pDbgFunctionHead;\n'
Tobin Ehlisca915872014-11-18 11:28:33 -0700600 using_line += ' XGL_LAYER_DBG_FUNCTION_NODE *pPrev = pTrav;\n'
601 using_line += ' while (pTrav) {\n'
602 using_line += ' if (pTrav->pfnMsgCallback == pfnMsgCallback) {\n'
603 using_line += ' pPrev->pNext = pTrav->pNext;\n'
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700604 using_line += ' if (g_pDbgFunctionHead == pTrav)\n'
605 using_line += ' g_pDbgFunctionHead = pTrav->pNext;\n'
Tobin Ehlisca915872014-11-18 11:28:33 -0700606 using_line += ' free(pTrav);\n'
607 using_line += ' break;\n'
608 using_line += ' }\n'
609 using_line += ' pPrev = pTrav;\n'
610 using_line += ' pTrav = pTrav->pNext;\n'
611 using_line += ' }\n'
Jon Ashburna8aa8372015-03-03 15:07:15 -0700612 using_line += ' if (g_pDbgFunctionHead == NULL)\n'
613 using_line += ' {\n'
614 using_line += ' if (g_actionIsDefault)\n'
615 using_line += ' g_debugAction = XGL_DBG_LAYER_ACTION_LOG_MSG;\n'
616 using_line += ' else\n'
617 using_line += ' g_debugAction &= ~XGL_DBG_LAYER_ACTION_CALLBACK;\n'
618 using_line += ' }\n'
Tobin Ehlis7e65d752015-01-15 17:51:52 -0700619 # Special cases for API funcs that don't use an object as first arg
Courtney Goeltzenleuchter5a78b7f2015-03-04 11:21:23 -0700620 elif True in [no_use_proto in proto.name for no_use_proto in ['GlobalOption', 'CreateInstance', 'QueueSubmit', 'QueueSetGlobalMemReferences', 'QueueWaitIdle', 'CreateDevice', 'GetGpuInfo', 'SignalQueueSemaphore', 'WaitQueueSemaphore', 'WsiX11QueuePresent']]:
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600621 using_line = ''
Tobin Ehlisca915872014-11-18 11:28:33 -0700622 else:
Tobin Ehlis36f1b462015-02-23 14:09:16 -0700623 using_line = ' loader_platform_thread_lock_mutex(&objLock);\n'
624 using_line += ' ll_increment_use_count((void*)%s, %s);\n' % (param0_name, obj_type_mapping[p0_type])
625 using_line += ' loader_platform_thread_unlock_mutex(&objLock);\n'
Tobin Ehlis91ce77e2015-01-16 08:56:30 -0700626 if 'QueueSubmit' in proto.name:
627 using_line += ' set_status((void*)fence, XGL_OBJECT_TYPE_FENCE, OBJSTATUS_FENCE_IS_SUBMITTED);\n'
Mark Lobodzinski4988dea2015-02-03 11:52:26 -0600628 using_line += ' validate_memory_mapping_status(pMemRefs, memRefCount);\n'
Mark Lobodzinskiaae93e52015-02-09 10:20:53 -0600629 using_line += ' validate_mem_ref_count(memRefCount);\n'
Tobin Ehlis91ce77e2015-01-16 08:56:30 -0700630 elif 'GetFenceStatus' in proto.name:
631 using_line += ' // Warn if submitted_flag is not set\n'
Mark Lobodzinski4988dea2015-02-03 11:52:26 -0600632 using_line += ' validate_status((void*)fence, XGL_OBJECT_TYPE_FENCE, OBJSTATUS_FENCE_IS_SUBMITTED, OBJSTATUS_FENCE_IS_SUBMITTED, XGL_DBG_MSG_ERROR, OBJTRACK_INVALID_FENCE, "Status Requested for Unsubmitted Fence");\n'
Mark Lobodzinski40370872015-02-03 10:06:31 -0600633 elif 'EndCommandBuffer' in proto.name:
634 using_line += ' reset_status((void*)cmdBuffer, XGL_OBJECT_TYPE_CMD_BUFFER, (OBJSTATUS_VIEWPORT_BOUND |\n'
635 using_line += ' OBJSTATUS_RASTER_BOUND |\n'
636 using_line += ' OBJSTATUS_COLOR_BLEND_BOUND |\n'
637 using_line += ' OBJSTATUS_DEPTH_STENCIL_BOUND));\n'
638 elif 'CmdBindDynamicStateObject' in proto.name:
639 using_line += ' track_object_status((void*)cmdBuffer, stateBindPoint);\n'
640 elif 'CmdDraw' in proto.name:
641 using_line += ' validate_draw_state_flags((void *)cmdBuffer);\n'
Mark Lobodzinski4988dea2015-02-03 11:52:26 -0600642 elif 'MapMemory' in proto.name:
643 using_line += ' set_status((void*)mem, XGL_OBJECT_TYPE_GPU_MEMORY, OBJSTATUS_GPU_MEM_MAPPED);\n'
644 elif 'UnmapMemory' in proto.name:
645 using_line += ' reset_status((void*)mem, XGL_OBJECT_TYPE_GPU_MEMORY, OBJSTATUS_GPU_MEM_MAPPED);\n'
Tobin Ehlis7e65d752015-01-15 17:51:52 -0700646 if 'AllocDescriptor' in proto.name: # Allocates array of DSs
Ian Elliotta83a58a2015-02-04 12:15:12 -0700647 create_line = ' for (uint32_t i = 0; i < *pCount; i++) {\n'
Tobin Ehlis36f1b462015-02-23 14:09:16 -0700648 create_line += ' loader_platform_thread_lock_mutex(&objLock);\n'
Tobin Ehlis7e65d752015-01-15 17:51:52 -0700649 create_line += ' ll_insert_obj((void*)pDescriptorSets[i], XGL_OBJECT_TYPE_DESCRIPTOR_SET);\n'
Tobin Ehlis36f1b462015-02-23 14:09:16 -0700650 create_line += ' loader_platform_thread_unlock_mutex(&objLock);\n'
Tobin Ehlis7e65d752015-01-15 17:51:52 -0700651 create_line += ' }\n'
Courtney Goeltzenleuchterbe1c8982015-02-25 16:58:34 -0700652 elif 'CreatePresentableImage' in proto.name:
653 create_line = ' loader_platform_thread_lock_mutex(&objLock);\n'
654 create_line += ' ll_insert_obj((void*)*%s, %s);\n' % (proto.params[-2].name, obj_type_mapping[proto.params[-2].ty.strip('*').strip('const ')])
655 create_line += ' loader_platform_thread_unlock_mutex(&objLock);\n'
Tobin Ehlis7e65d752015-01-15 17:51:52 -0700656 elif 'Create' in proto.name or 'Alloc' in proto.name:
Tobin Ehlis36f1b462015-02-23 14:09:16 -0700657 create_line = ' loader_platform_thread_lock_mutex(&objLock);\n'
658 create_line += ' ll_insert_obj((void*)*%s, %s);\n' % (proto.params[-1].name, obj_type_mapping[proto.params[-1].ty.strip('*').strip('const ')])
659 create_line += ' loader_platform_thread_unlock_mutex(&objLock);\n'
Tobin Ehlisca915872014-11-18 11:28:33 -0700660 if 'DestroyObject' in proto.name:
Tobin Ehlis36f1b462015-02-23 14:09:16 -0700661 destroy_line = ' loader_platform_thread_lock_mutex(&objLock);\n'
662 destroy_line += ' ll_destroy_obj((void*)%s);\n' % (param0_name)
663 destroy_line += ' loader_platform_thread_unlock_mutex(&objLock);\n'
Tobin Ehlisca915872014-11-18 11:28:33 -0700664 using_line = ''
665 else:
666 if 'Destroy' in proto.name or 'Free' in proto.name:
Tobin Ehlis36f1b462015-02-23 14:09:16 -0700667 destroy_line = ' loader_platform_thread_lock_mutex(&objLock);\n'
Mark Lobodzinskiaadd4c82015-02-24 16:20:24 -0600668 destroy_line += ' ll_destroy_obj((void*)%s);\n' % (param0_name)
Tobin Ehlis36f1b462015-02-23 14:09:16 -0700669 destroy_line += ' loader_platform_thread_unlock_mutex(&objLock);\n'
Tobin Ehlisca915872014-11-18 11:28:33 -0700670 using_line = ''
671 if 'DestroyDevice' in proto.name:
672 destroy_line += ' // Report any remaining objects in LL\n objNode *pTrav = pGlobalHead;\n while (pTrav) {\n'
673 destroy_line += ' char str[1024];\n'
674 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'
675 destroy_line += ' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, device, 0, OBJTRACK_OBJECT_LEAK, "OBJTRACK", str);\n'
676 destroy_line += ' pTrav = pTrav->pNextGlobal;\n }\n'
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600677 ret_val = ''
678 stmt = ''
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600679 if proto.ret != "void":
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600680 ret_val = "XGL_RESULT result = "
681 stmt = " return result;\n"
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700682 if 'WsiX11AssociateConnection' == proto.name:
Ian Elliottd1597d22015-02-26 14:34:52 -0700683 funcs.append("#if defined(__linux__) || defined(XCB_NVIDIA)")
Jon Ashburnf7a08742014-11-25 11:08:42 -0700684 if proto.name == "EnumerateLayers":
685 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
686 funcs.append('%s%s\n'
687 '{\n'
688 ' if (gpu != NULL) {\n'
689 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
690 ' %s'
691 ' pCurObj = gpuw;\n'
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700692 ' loader_platform_thread_once(&tabOnce, init%s);\n'
Jon Ashburnf7a08742014-11-25 11:08:42 -0700693 ' %snextTable.%s;\n'
694 ' %s%s'
695 ' %s'
696 ' } else {\n'
697 ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n'
698 ' return XGL_ERROR_INVALID_POINTER;\n'
699 ' // This layer compatible with all GPUs\n'
700 ' *pOutLayerCount = 1;\n'
Chia-I Wu1da4b9f2014-12-16 10:47:33 +0800701 ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n'
Jon Ashburnf7a08742014-11-25 11:08:42 -0700702 ' return XGL_SUCCESS;\n'
703 ' }\n'
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700704 '}' % (qual, decl, proto.params[0].name, using_line, layer_name, ret_val, c_call, create_line, destroy_line, stmt, layer_name))
Jon Ashburnf7a08742014-11-25 11:08:42 -0700705 elif proto.params[0].ty != "XGL_PHYSICAL_GPU":
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600706 funcs.append('%s%s\n'
707 '{\n'
708 '%s'
709 ' %snextTable.%s;\n'
710 '%s%s'
711 '%s'
712 '}' % (qual, decl, using_line, ret_val, proto.c_call(), create_line, destroy_line, stmt))
713 else:
714 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
Mark Lobodzinskiaae93e52015-02-09 10:20:53 -0600715 gpu_state = ''
716 if 'GetGpuInfo' in proto.name:
717 gpu_state = ' if (infoType == XGL_INFO_TYPE_PHYSICAL_GPU_PROPERTIES) {\n'
718 gpu_state += ' if (pData != NULL) {\n'
719 gpu_state += ' setGpuInfoState(pData);\n'
720 gpu_state += ' }\n'
721 gpu_state += ' }\n'
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600722 funcs.append('%s%s\n'
723 '{\n'
724 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
725 '%s'
726 ' pCurObj = gpuw;\n'
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700727 ' loader_platform_thread_once(&tabOnce, init%s);\n'
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600728 ' %snextTable.%s;\n'
729 '%s%s'
730 '%s'
Mark Lobodzinskiaae93e52015-02-09 10:20:53 -0600731 '%s'
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700732 '}' % (qual, decl, proto.params[0].name, using_line, layer_name, ret_val, c_call, create_line, destroy_line, gpu_state, stmt))
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700733 if 'WsiX11QueuePresent' == proto.name:
734 funcs.append("#endif")
Tobin Ehlis14ff0852014-12-17 17:44:50 -0700735 elif "ParamChecker" == layer:
736 # TODO : Need to fix up the non-else cases below to do param checking as well
737 decl = proto.c_func(prefix="xgl", attr="XGLAPI")
738 param0_name = proto.params[0].name
739 ret_val = ''
740 stmt = ''
741 param_checks = []
742 # Add code to check enums and structs
743 # TODO : Currently only validating enum values, need to validate everything
744 str_decl = False
Tobin Ehlisc6d256a2014-12-18 13:51:21 -0700745 prev_count_name = ''
Tobin Ehlis14ff0852014-12-17 17:44:50 -0700746 for p in proto.params:
747 if xgl_helper.is_type(p.ty.strip('*').strip('const '), 'enum'):
748 if not str_decl:
749 param_checks.append(' char str[1024];')
750 str_decl = True
751 param_checks.append(' if (!validate_%s(%s)) {' % (p.ty, p.name))
Tobin Ehlis14ff0852014-12-17 17:44:50 -0700752 param_checks.append(' sprintf(str, "Parameter %s to function %s has invalid value of %%i.", (int)%s);' % (p.name, proto.name, p.name))
753 param_checks.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, 1, "PARAMCHECK", str);')
754 param_checks.append(' }')
755 elif xgl_helper.is_type(p.ty.strip('*').strip('const '), 'struct') and 'const' in p.ty:
Tobin Ehlisc6d256a2014-12-18 13:51:21 -0700756 is_array = False
Tobin Ehlis14ff0852014-12-17 17:44:50 -0700757 if not str_decl:
758 param_checks.append(' char str[1024];')
759 str_decl = True
760 if '*' in p.ty: # First check for null ptr
Tobin Ehlisc6d256a2014-12-18 13:51:21 -0700761 # If this is an input array, parse over all of the array elements
762 if prev_count_name != '' and (prev_count_name.strip('Count')[1:] in p.name or 'slotCount' == prev_count_name):
763 #if 'pImageViews' in p.name:
764 is_array = True
765 param_checks.append(' uint32_t i;')
766 param_checks.append(' for (i = 0; i < %s; i++) {' % prev_count_name)
767 param_checks.append(' if (!xgl_validate_%s(&%s[i])) {' % (p.ty.strip('*').strip('const ').lower(), p.name))
768 param_checks.append(' sprintf(str, "Parameter %s[%%i] to function %s contains an invalid value.", i);' % (p.name, proto.name))
769 param_checks.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, 1, "PARAMCHECK", str);')
770 param_checks.append(' }')
771 param_checks.append(' }')
772 else:
773 param_checks.append(' if (!%s) {' % p.name)
774 param_checks.append(' sprintf(str, "Struct ptr parameter %s to function %s is NULL.");' % (p.name, proto.name))
775 param_checks.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, NULL, 0, 1, "PARAMCHECK", str);')
776 param_checks.append(' }')
777 param_checks.append(' else if (!xgl_validate_%s(%s)) {' % (p.ty.strip('*').strip('const ').lower(), p.name))
Tobin Ehlis14ff0852014-12-17 17:44:50 -0700778 else:
779 param_checks.append(' if (!xgl_validate_%s(%s)) {' % (p.ty.strip('const ').lower(), p.name))
Tobin Ehlisc6d256a2014-12-18 13:51:21 -0700780 if not is_array:
781 param_checks.append(' sprintf(str, "Parameter %s to function %s contains an invalid value.");' % (p.name, proto.name))
782 param_checks.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, 1, "PARAMCHECK", str);')
783 param_checks.append(' }')
784 if p.name.endswith('Count'):
785 prev_count_name = p.name
786 else:
787 prev_count_name = ''
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600788 if proto.ret != "void":
Tobin Ehlis14ff0852014-12-17 17:44:50 -0700789 ret_val = "XGL_RESULT result = "
790 stmt = " return result;\n"
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700791 if 'WsiX11AssociateConnection' == proto.name:
Ian Elliottd1597d22015-02-26 14:34:52 -0700792 funcs.append("#if defined(__linux__) || defined(XCB_NVIDIA)")
Tobin Ehlis14ff0852014-12-17 17:44:50 -0700793 if proto.name == "EnumerateLayers":
794 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
795 funcs.append('%s%s\n'
796 '{\n'
797 ' char str[1024];\n'
798 ' if (gpu != NULL) {\n'
799 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
800 ' sprintf(str, "At start of layered %s\\n");\n'
801 ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpu, 0, 0, "PARAMCHECK", str);\n'
802 ' pCurObj = gpuw;\n'
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700803 ' loader_platform_thread_once(&tabOnce, init%s);\n'
Tobin Ehlis14ff0852014-12-17 17:44:50 -0700804 ' %snextTable.%s;\n'
805 ' sprintf(str, "Completed layered %s\\n");\n'
806 ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpu, 0, 0, "PARAMCHECK", str);\n'
807 ' fflush(stdout);\n'
808 ' %s'
809 ' } else {\n'
810 ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n'
811 ' return XGL_ERROR_INVALID_POINTER;\n'
812 ' // This layer compatible with all GPUs\n'
813 ' *pOutLayerCount = 1;\n'
814 ' strncpy(pOutLayers[0], "%s", maxStringSize);\n'
815 ' return XGL_SUCCESS;\n'
816 ' }\n'
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700817 '}' % (qual, decl, proto.params[0].name, proto.name, layer_name, ret_val, c_call, proto.name, stmt, layer_name))
Tobin Ehlis14ff0852014-12-17 17:44:50 -0700818 elif 'DbgRegisterMsgCallback' == proto.name:
819 funcs.append(self._gen_layer_dbg_callback_register())
820 elif 'DbgUnregisterMsgCallback' == proto.name:
821 funcs.append(self._gen_layer_dbg_callback_unregister())
822 elif proto.params[0].ty != "XGL_PHYSICAL_GPU":
823 funcs.append('%s%s\n'
824 '{\n'
825 '%s\n'
826 ' %snextTable.%s;\n'
827 '%s'
828 '}' % (qual, decl, "\n".join(param_checks), ret_val, proto.c_call(), stmt))
829 else:
830 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
831 funcs.append('%s%s\n'
832 '{\n'
Tobin Ehlis14ff0852014-12-17 17:44:50 -0700833 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
Tobin Ehlis14ff0852014-12-17 17:44:50 -0700834 ' pCurObj = gpuw;\n'
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700835 ' loader_platform_thread_once(&tabOnce, init%s);\n'
Tobin Ehlisbf4c4de2014-12-18 08:44:01 -0700836 '%s\n'
Tobin Ehlis14ff0852014-12-17 17:44:50 -0700837 ' %snextTable.%s;\n'
Tobin Ehlis14ff0852014-12-17 17:44:50 -0700838 '%s'
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700839 '}' % (qual, decl, proto.params[0].name, layer_name, "\n".join(param_checks), ret_val, c_call, stmt))
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700840 if 'WsiX11QueuePresent' == proto.name:
841 funcs.append("#endif")
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600842
843 return "\n\n".join(funcs)
844
Tobin Ehlisca915872014-11-18 11:28:33 -0700845 def _generate_extensions(self):
846 exts = []
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600847 exts.append('uint64_t objTrackGetObjectCount(XGL_OBJECT_TYPE type)')
Tobin Ehlisca915872014-11-18 11:28:33 -0700848 exts.append('{')
849 exts.append(' return (type == XGL_OBJECT_TYPE_ANY) ? numTotalObjs : numObjs[type];')
850 exts.append('}')
851 exts.append('')
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600852 exts.append('XGL_RESULT objTrackGetObjects(XGL_OBJECT_TYPE type, uint64_t objCount, OBJTRACK_NODE* pObjNodeArray)')
Tobin Ehlisca915872014-11-18 11:28:33 -0700853 exts.append('{')
854 exts.append(" // This bool flags if we're pulling all objs or just a single class of objs")
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600855 exts.append(' bool32_t bAllObjs = (type == XGL_OBJECT_TYPE_ANY);')
Tobin Ehlisca915872014-11-18 11:28:33 -0700856 exts.append(' // Check the count first thing')
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600857 exts.append(' uint64_t maxObjCount = (bAllObjs) ? numTotalObjs : numObjs[type];')
Tobin Ehlisca915872014-11-18 11:28:33 -0700858 exts.append(' if (objCount > maxObjCount) {')
859 exts.append(' char str[1024];')
860 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));')
861 exts.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, 0, 0, OBJTRACK_OBJCOUNT_MAX_EXCEEDED, "OBJTRACK", str);')
862 exts.append(' return XGL_ERROR_INVALID_VALUE;')
863 exts.append(' }')
864 exts.append(' objNode* pTrav = (bAllObjs) ? pGlobalHead : pObjectHead[type];')
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600865 exts.append(' for (uint64_t i = 0; i < objCount; i++) {')
Tobin Ehlisca915872014-11-18 11:28:33 -0700866 exts.append(' if (!pTrav) {')
867 exts.append(' char str[1024];')
868 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);')
869 exts.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, 0, 0, OBJTRACK_INTERNAL_ERROR, "OBJTRACK", str);')
870 exts.append(' return XGL_ERROR_UNKNOWN;')
871 exts.append(' }')
872 exts.append(' memcpy(&pObjNodeArray[i], pTrav, sizeof(OBJTRACK_NODE));')
873 exts.append(' pTrav = (bAllObjs) ? pTrav->pNextGlobal : pTrav->pNextObj;')
874 exts.append(' }')
875 exts.append(' return XGL_SUCCESS;')
876 exts.append('}')
877
878 return "\n".join(exts)
879
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700880 def _generate_layer_gpa_function(self, layer, extensions=[]):
Chia-I Wu4d11dcc2015-01-05 13:18:57 +0800881 func_body = ["#include \"xgl_generic_intercept_proc_helper.h\""]
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600882 func_body.append("XGL_LAYER_EXPORT void* XGLAPI xglGetProcAddr(XGL_PHYSICAL_GPU gpu, const char* funcName)\n"
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600883 "{\n"
884 " XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) gpu;\n"
Chia-I Wu4d11dcc2015-01-05 13:18:57 +0800885 " void* addr;\n"
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600886 " if (gpu == NULL)\n"
887 " return NULL;\n"
888 " pCurObj = gpuw;\n"
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700889 " loader_platform_thread_once(&tabOnce, init%s);\n\n"
Chia-I Wu4d11dcc2015-01-05 13:18:57 +0800890 " addr = layer_intercept_proc(funcName);\n"
891 " if (addr)\n"
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700892 " return addr;" % layer)
Chia-I Wu4d11dcc2015-01-05 13:18:57 +0800893
Tobin Ehlisca915872014-11-18 11:28:33 -0700894 if 0 != len(extensions):
895 for ext_name in extensions:
Chia-I Wuf1a5a742014-12-27 15:16:07 +0800896 func_body.append(' else if (!strncmp("%s", funcName, sizeof("%s")))\n'
Tobin Ehlisca915872014-11-18 11:28:33 -0700897 ' return %s;' % (ext_name, ext_name, ext_name))
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600898 func_body.append(" else {\n"
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600899 " if (gpuw->pGPA == NULL)\n"
900 " return NULL;\n"
Tobin Ehlis99f88672015-01-10 12:42:41 -0700901 " return gpuw->pGPA((XGL_PHYSICAL_GPU)gpuw->nextObject, funcName);\n"
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600902 " }\n"
903 "}\n")
904 return "\n".join(func_body)
905
Tobin Ehlis36f1b462015-02-23 14:09:16 -0700906 def _generate_layer_initialization(self, name, init_opts=False, prefix='xgl', lockname=None):
Chia-I Wuaa4121f2015-01-04 23:11:43 +0800907 func_body = ["#include \"xgl_dispatch_table_helper.h\""]
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700908 func_body.append('static void init%s(void)\n'
909 '{\n' % name)
910 if init_opts:
911 func_body.append(' const char *strOpt;')
912 func_body.append(' // initialize %s options' % name)
Jon Ashburna8aa8372015-03-03 15:07:15 -0700913 func_body.append(' getLayerOptionEnum("%sReportLevel", &g_reportingLevel);' % name)
914 func_body.append(' g_actionIsDefault = getLayerOptionEnum("%sDebugAction", &g_debugAction);' % name)
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700915 func_body.append('')
916 func_body.append(' if (g_debugAction & XGL_DBG_LAYER_ACTION_LOG_MSG)')
917 func_body.append(' {')
918 func_body.append(' strOpt = getLayerOption("%sLogFilename");' % name)
919 func_body.append(' if (strOpt)')
920 func_body.append(' {')
921 func_body.append(' g_logFile = fopen(strOpt, "w");')
922 func_body.append(' }')
923 func_body.append(' if (g_logFile == NULL)')
924 func_body.append(' g_logFile = stdout;')
925 func_body.append(' }')
926 func_body.append('')
927 func_body.append(' xglGetProcAddrType fpNextGPA;\n'
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600928 ' fpNextGPA = pCurObj->pGPA;\n'
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700929 ' assert(fpNextGPA);\n')
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600930
Chia-I Wuaa4121f2015-01-04 23:11:43 +0800931 func_body.append(" layer_initialize_dispatch_table(&nextTable, fpNextGPA, (XGL_PHYSICAL_GPU) pCurObj->nextObject);")
Tobin Ehlis36f1b462015-02-23 14:09:16 -0700932 if lockname is not None:
933 func_body.append(" if (!%sLockInitialized)" % lockname)
934 func_body.append(" {")
935 func_body.append(" // TODO/TBD: Need to delete this mutex sometime. How???")
936 func_body.append(" loader_platform_thread_create_mutex(&%sLock);" % lockname)
937 func_body.append(" %sLockInitialized = 1;" % lockname)
938 func_body.append(" }")
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600939 func_body.append("}\n")
940 return "\n".join(func_body)
941
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700942 def _generate_layer_initialization_with_lock(self, layer, prefix='xgl'):
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700943 func_body = ["#include \"xgl_dispatch_table_helper.h\""]
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700944 func_body.append('static void init%s(void)\n'
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700945 '{\n'
946 ' xglGetProcAddrType fpNextGPA;\n'
947 ' fpNextGPA = pCurObj->pGPA;\n'
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700948 ' assert(fpNextGPA);\n' % layer);
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700949
950 func_body.append(" layer_initialize_dispatch_table(&nextTable, fpNextGPA, (XGL_PHYSICAL_GPU) pCurObj->nextObject);\n")
951 func_body.append(" if (!printLockInitialized)")
952 func_body.append(" {")
953 func_body.append(" // TODO/TBD: Need to delete this mutex sometime. How???")
954 func_body.append(" loader_platform_thread_create_mutex(&printLock);")
955 func_body.append(" printLockInitialized = 1;")
956 func_body.append(" }")
957 func_body.append("}\n")
958 return "\n".join(func_body)
959
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600960class LayerFuncsSubcommand(Subcommand):
961 def generate_header(self):
962 return '#include <xglLayer.h>\n#include "loader.h"'
963
964 def generate_body(self):
965 return self._generate_dispatch_entrypoints("static", True)
966
967class LayerDispatchSubcommand(Subcommand):
968 def generate_header(self):
969 return '#include "layer_wrappers.h"'
970
971 def generate_body(self):
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700972 return self._generate_layer_initialization()
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600973
974class GenericLayerSubcommand(Subcommand):
975 def generate_header(self):
Jon Ashburn9a7f9a22015-02-17 11:03:12 -0700976 return '#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include "loader_platform.h"\n#include "xglLayer.h"\n//The following is #included again to catch certain OS-specific functions being used:\n#include "loader_platform.h"\n\n#include "layers_config.h"\n#include "layers_msg.h"\n\nstatic XGL_LAYER_DISPATCH_TABLE nextTable;\nstatic XGL_BASE_LAYER_OBJECT *pCurObj;\n\nstatic LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);'
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600977
978 def generate_body(self):
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700979 body = [self._generate_layer_initialization("Generic", True),
Tobin Ehlisa363cfa2014-11-25 16:59:27 -0700980 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "Generic"),
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700981 self._generate_layer_gpa_function("Generic")]
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600982
983 return "\n\n".join(body)
984
985class ApiDumpSubcommand(Subcommand):
986 def generate_header(self):
Tobin Ehlisd009bae2014-11-24 15:46:55 -0700987 header_txt = []
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700988 header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>')
989 header_txt.append('#include "loader_platform.h"')
990 header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper.h"\n')
Ian Elliott655cad72015-02-12 17:08:34 -0700991 header_txt.append('// The following is #included again to catch certain OS-specific functions being used:')
992 header_txt.append('#include "loader_platform.h"')
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700993 header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;')
994 header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n')
995 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
996 header_txt.append('static int printLockInitialized = 0;')
997 header_txt.append('static loader_platform_thread_mutex printLock;\n')
Tobin Ehlisd009bae2014-11-24 15:46:55 -0700998 header_txt.append('#define MAX_TID 513')
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700999 header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};')
Tobin Ehlisd009bae2014-11-24 15:46:55 -07001000 header_txt.append('static uint32_t maxTID = 0;')
1001 header_txt.append('// Map actual TID to an index value and return that index')
1002 header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs')
1003 header_txt.append('static uint32_t getTIDIndex() {')
Ian Elliott2d4ab1e2015-01-13 17:52:38 -07001004 header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();')
Tobin Ehlisd009bae2014-11-24 15:46:55 -07001005 header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {')
1006 header_txt.append(' if (tid == tidMapping[i])')
1007 header_txt.append(' return i;')
1008 header_txt.append(' }')
1009 header_txt.append(" // Don't yet have mapping, set it and return newly set index")
Ian Elliott2d4ab1e2015-01-13 17:52:38 -07001010 header_txt.append(' uint32_t retVal = (uint32_t) maxTID;')
Tobin Ehlisd009bae2014-11-24 15:46:55 -07001011 header_txt.append(' tidMapping[maxTID++] = tid;')
1012 header_txt.append(' assert(maxTID < MAX_TID);')
1013 header_txt.append(' return retVal;')
1014 header_txt.append('}')
1015 return "\n".join(header_txt)
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001016
1017 def generate_body(self):
Jon Ashburnd6badbc2015-02-16 08:26:50 -07001018 body = [self._generate_layer_initialization_with_lock("APIDump"),
Tobin Ehlisa363cfa2014-11-25 16:59:27 -07001019 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDump"),
Jon Ashburnd6badbc2015-02-16 08:26:50 -07001020 self._generate_layer_gpa_function("APIDump")]
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001021
1022 return "\n\n".join(body)
1023
Tobin Ehlis99f88672015-01-10 12:42:41 -07001024class ApiDumpCppSubcommand(Subcommand):
1025 def generate_header(self):
1026 header_txt = []
Ian Elliott2d4ab1e2015-01-13 17:52:38 -07001027 header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>')
1028 header_txt.append('#include "loader_platform.h"')
1029 header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper_cpp.h"\n')
Ian Elliott655cad72015-02-12 17:08:34 -07001030 header_txt.append('// The following is #included again to catch certain OS-specific functions being used:')
1031 header_txt.append('#include "loader_platform.h"')
Ian Elliott2d4ab1e2015-01-13 17:52:38 -07001032 header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;')
1033 header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n')
1034 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
1035 header_txt.append('static int printLockInitialized = 0;')
1036 header_txt.append('static loader_platform_thread_mutex printLock;\n')
Tobin Ehlis99f88672015-01-10 12:42:41 -07001037 header_txt.append('#define MAX_TID 513')
Ian Elliott2d4ab1e2015-01-13 17:52:38 -07001038 header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};')
Tobin Ehlis99f88672015-01-10 12:42:41 -07001039 header_txt.append('static uint32_t maxTID = 0;')
1040 header_txt.append('// Map actual TID to an index value and return that index')
1041 header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs')
1042 header_txt.append('static uint32_t getTIDIndex() {')
Ian Elliott2d4ab1e2015-01-13 17:52:38 -07001043 header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();')
Tobin Ehlis99f88672015-01-10 12:42:41 -07001044 header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {')
1045 header_txt.append(' if (tid == tidMapping[i])')
1046 header_txt.append(' return i;')
1047 header_txt.append(' }')
1048 header_txt.append(" // Don't yet have mapping, set it and return newly set index")
Ian Elliott2d4ab1e2015-01-13 17:52:38 -07001049 header_txt.append(' uint32_t retVal = (uint32_t) maxTID;')
Tobin Ehlis99f88672015-01-10 12:42:41 -07001050 header_txt.append(' tidMapping[maxTID++] = tid;')
1051 header_txt.append(' assert(maxTID < MAX_TID);')
1052 header_txt.append(' return retVal;')
1053 header_txt.append('}')
1054 return "\n".join(header_txt)
1055
1056 def generate_body(self):
Jon Ashburnd6badbc2015-02-16 08:26:50 -07001057 body = [self._generate_layer_initialization_with_lock("APIDumpCpp"),
Tobin Ehlis99f88672015-01-10 12:42:41 -07001058 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDumpCpp"),
Jon Ashburnd6badbc2015-02-16 08:26:50 -07001059 self._generate_layer_gpa_function("APIDumpCpp")]
Tobin Ehlis99f88672015-01-10 12:42:41 -07001060
1061 return "\n\n".join(body)
1062
Tobin Ehlisea3d21b2014-11-12 13:11:15 -07001063class ApiDumpFileSubcommand(Subcommand):
1064 def generate_header(self):
Tobin Ehlisd009bae2014-11-24 15:46:55 -07001065 header_txt = []
Ian Elliott2d4ab1e2015-01-13 17:52:38 -07001066 header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>')
1067 header_txt.append('#include "loader_platform.h"')
1068 header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper.h"\n')
Ian Elliott655cad72015-02-12 17:08:34 -07001069 header_txt.append('// The following is #included again to catch certain OS-specific functions being used:')
1070 header_txt.append('#include "loader_platform.h"')
Ian Elliott2d4ab1e2015-01-13 17:52:38 -07001071 header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;')
1072 header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n')
1073 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
1074 header_txt.append('static int printLockInitialized = 0;')
1075 header_txt.append('static loader_platform_thread_mutex printLock;\n')
Tobin Ehlisd009bae2014-11-24 15:46:55 -07001076 header_txt.append('#define MAX_TID 513')
Ian Elliott2d4ab1e2015-01-13 17:52:38 -07001077 header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};')
Tobin Ehlisd009bae2014-11-24 15:46:55 -07001078 header_txt.append('static uint32_t maxTID = 0;')
1079 header_txt.append('// Map actual TID to an index value and return that index')
1080 header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs')
1081 header_txt.append('static uint32_t getTIDIndex() {')
Ian Elliott2d4ab1e2015-01-13 17:52:38 -07001082 header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();')
Tobin Ehlisd009bae2014-11-24 15:46:55 -07001083 header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {')
1084 header_txt.append(' if (tid == tidMapping[i])')
1085 header_txt.append(' return i;')
1086 header_txt.append(' }')
1087 header_txt.append(" // Don't yet have mapping, set it and return newly set index")
Ian Elliott2d4ab1e2015-01-13 17:52:38 -07001088 header_txt.append(' uint32_t retVal = (uint32_t) maxTID;')
Tobin Ehlisd009bae2014-11-24 15:46:55 -07001089 header_txt.append(' tidMapping[maxTID++] = tid;')
1090 header_txt.append(' assert(maxTID < MAX_TID);')
1091 header_txt.append(' return retVal;')
Ian Elliott2d4ab1e2015-01-13 17:52:38 -07001092 header_txt.append('}\n')
1093 header_txt.append('static FILE* pOutFile;\nstatic char* outFileName = "xgl_apidump.txt";')
Tobin Ehlisd009bae2014-11-24 15:46:55 -07001094 return "\n".join(header_txt)
Tobin Ehlisea3d21b2014-11-12 13:11:15 -07001095
1096 def generate_body(self):
Jon Ashburnd6badbc2015-02-16 08:26:50 -07001097 body = [self._generate_layer_initialization_with_lock("APIDumpFile"),
Tobin Ehlisa363cfa2014-11-25 16:59:27 -07001098 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDumpFile"),
Jon Ashburnd6badbc2015-02-16 08:26:50 -07001099 self._generate_layer_gpa_function("APIDumpFile")]
Tobin Ehlisea3d21b2014-11-12 13:11:15 -07001100
1101 return "\n\n".join(body)
1102
Tobin Ehlisd49efcb2014-11-25 17:43:26 -07001103class ApiDumpNoAddrSubcommand(Subcommand):
1104 def generate_header(self):
1105 header_txt = []
Ian Elliott2d4ab1e2015-01-13 17:52:38 -07001106 header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>')
1107 header_txt.append('#include "loader_platform.h"')
1108 header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper_no_addr.h"\n')
Ian Elliott655cad72015-02-12 17:08:34 -07001109 header_txt.append('// The following is #included again to catch certain OS-specific functions being used:')
1110 header_txt.append('#include "loader_platform.h"')
Ian Elliott2d4ab1e2015-01-13 17:52:38 -07001111 header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;')
1112 header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n')
1113 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
1114 header_txt.append('static int printLockInitialized = 0;')
1115 header_txt.append('static loader_platform_thread_mutex printLock;\n')
Tobin Ehlisd49efcb2014-11-25 17:43:26 -07001116 header_txt.append('#define MAX_TID 513')
Ian Elliott2d4ab1e2015-01-13 17:52:38 -07001117 header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};')
Tobin Ehlisd49efcb2014-11-25 17:43:26 -07001118 header_txt.append('static uint32_t maxTID = 0;')
1119 header_txt.append('// Map actual TID to an index value and return that index')
1120 header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs')
1121 header_txt.append('static uint32_t getTIDIndex() {')
Ian Elliott2d4ab1e2015-01-13 17:52:38 -07001122 header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();')
Tobin Ehlisd49efcb2014-11-25 17:43:26 -07001123 header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {')
1124 header_txt.append(' if (tid == tidMapping[i])')
1125 header_txt.append(' return i;')
1126 header_txt.append(' }')
1127 header_txt.append(" // Don't yet have mapping, set it and return newly set index")
Ian Elliott2d4ab1e2015-01-13 17:52:38 -07001128 header_txt.append(' uint32_t retVal = (uint32_t) maxTID;')
Tobin Ehlisd49efcb2014-11-25 17:43:26 -07001129 header_txt.append(' tidMapping[maxTID++] = tid;')
1130 header_txt.append(' assert(maxTID < MAX_TID);')
1131 header_txt.append(' return retVal;')
1132 header_txt.append('}')
1133 return "\n".join(header_txt)
1134
1135 def generate_body(self):
Jon Ashburnd6badbc2015-02-16 08:26:50 -07001136 body = [self._generate_layer_initialization_with_lock("APIDumpNoAddr"),
Tobin Ehlisd49efcb2014-11-25 17:43:26 -07001137 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDump", True),
Jon Ashburnd6badbc2015-02-16 08:26:50 -07001138 self._generate_layer_gpa_function("APIDumpNoAddr")]
Tobin Ehlisd49efcb2014-11-25 17:43:26 -07001139
1140 return "\n\n".join(body)
1141
Tobin Ehlis99f88672015-01-10 12:42:41 -07001142class ApiDumpNoAddrCppSubcommand(Subcommand):
1143 def generate_header(self):
1144 header_txt = []
Ian Elliott2d4ab1e2015-01-13 17:52:38 -07001145 header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>')
1146 header_txt.append('#include "loader_platform.h"')
1147 header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper_no_addr_cpp.h"\n')
Ian Elliott655cad72015-02-12 17:08:34 -07001148 header_txt.append('// The following is #included again to catch certain OS-specific functions being used:')
1149 header_txt.append('#include "loader_platform.h"')
Ian Elliott2d4ab1e2015-01-13 17:52:38 -07001150 header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;')
1151 header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n')
1152 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
1153 header_txt.append('static int printLockInitialized = 0;')
1154 header_txt.append('static loader_platform_thread_mutex printLock;\n')
Tobin Ehlis99f88672015-01-10 12:42:41 -07001155 header_txt.append('#define MAX_TID 513')
Ian Elliott2d4ab1e2015-01-13 17:52:38 -07001156 header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};')
Tobin Ehlis99f88672015-01-10 12:42:41 -07001157 header_txt.append('static uint32_t maxTID = 0;')
1158 header_txt.append('// Map actual TID to an index value and return that index')
1159 header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs')
1160 header_txt.append('static uint32_t getTIDIndex() {')
Ian Elliott2d4ab1e2015-01-13 17:52:38 -07001161 header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();')
Tobin Ehlis99f88672015-01-10 12:42:41 -07001162 header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {')
1163 header_txt.append(' if (tid == tidMapping[i])')
1164 header_txt.append(' return i;')
1165 header_txt.append(' }')
1166 header_txt.append(" // Don't yet have mapping, set it and return newly set index")
Ian Elliott2d4ab1e2015-01-13 17:52:38 -07001167 header_txt.append(' uint32_t retVal = (uint32_t) maxTID;')
Tobin Ehlis99f88672015-01-10 12:42:41 -07001168 header_txt.append(' tidMapping[maxTID++] = tid;')
1169 header_txt.append(' assert(maxTID < MAX_TID);')
1170 header_txt.append(' return retVal;')
1171 header_txt.append('}')
1172 return "\n".join(header_txt)
1173
1174 def generate_body(self):
Jon Ashburnd6badbc2015-02-16 08:26:50 -07001175 body = [self._generate_layer_initialization_with_lock("APIDumpNoAddrCpp"),
Tobin Ehlis99f88672015-01-10 12:42:41 -07001176 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDumpCpp", True),
Jon Ashburnd6badbc2015-02-16 08:26:50 -07001177 self._generate_layer_gpa_function("APIDumpNoAddrCpp")]
Tobin Ehlis99f88672015-01-10 12:42:41 -07001178
1179 return "\n\n".join(body)
1180
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001181class ObjectTrackerSubcommand(Subcommand):
1182 def generate_header(self):
1183 header_txt = []
Ian Elliott2d4ab1e2015-01-13 17:52:38 -07001184 header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include "loader_platform.h"')
Tobin Ehlisca915872014-11-18 11:28:33 -07001185 header_txt.append('#include "object_track.h"\n\nstatic XGL_LAYER_DISPATCH_TABLE nextTable;\nstatic XGL_BASE_LAYER_OBJECT *pCurObj;')
Ian Elliott655cad72015-02-12 17:08:34 -07001186 header_txt.append('// The following is #included again to catch certain OS-specific functions being used:')
1187 header_txt.append('#include "loader_platform.h"')
Jon Ashburn9a7f9a22015-02-17 11:03:12 -07001188 header_txt.append('#include "layers_config.h"')
Jon Ashburnd6badbc2015-02-16 08:26:50 -07001189 header_txt.append('#include "layers_msg.h"')
Ian Elliott2d4ab1e2015-01-13 17:52:38 -07001190 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
1191 header_txt.append('static long long unsigned int object_track_index = 0;')
Tobin Ehlis36f1b462015-02-23 14:09:16 -07001192 header_txt.append('static int objLockInitialized = 0;')
1193 header_txt.append('static loader_platform_thread_mutex objLock;')
Jon Ashburnd6badbc2015-02-16 08:26:50 -07001194 header_txt.append('')
Tobin Ehlisca915872014-11-18 11:28:33 -07001195 header_txt.append('// We maintain a "Global" list which links every object and a')
1196 header_txt.append('// per-Object list which just links objects of a given type')
1197 header_txt.append('// The object node has both pointers so the actual nodes are shared between the two lists')
1198 header_txt.append('typedef struct _objNode {')
1199 header_txt.append(' OBJTRACK_NODE obj;')
1200 header_txt.append(' struct _objNode *pNextObj;')
1201 header_txt.append(' struct _objNode *pNextGlobal;')
1202 header_txt.append('} objNode;')
1203 header_txt.append('static objNode *pObjectHead[XGL_NUM_OBJECT_TYPE] = {0};')
1204 header_txt.append('static objNode *pGlobalHead = NULL;')
1205 header_txt.append('static uint64_t numObjs[XGL_NUM_OBJECT_TYPE] = {0};')
1206 header_txt.append('static uint64_t numTotalObjs = 0;')
Mark Lobodzinskiaae93e52015-02-09 10:20:53 -06001207 header_txt.append('static uint32_t maxMemRefsPerSubmission = 0;')
Tobin Ehlisca915872014-11-18 11:28:33 -07001208 header_txt.append('// Debug function to print global list and each individual object list')
1209 header_txt.append('static void ll_print_lists()')
1210 header_txt.append('{')
1211 header_txt.append(' objNode* pTrav = pGlobalHead;')
1212 header_txt.append(' printf("=====GLOBAL OBJECT LIST (%lu total objs):\\n", numTotalObjs);')
1213 header_txt.append(' while (pTrav) {')
1214 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);')
1215 header_txt.append(' pTrav = pTrav->pNextGlobal;')
1216 header_txt.append(' }')
1217 header_txt.append(' for (uint32_t i = 0; i < XGL_NUM_OBJECT_TYPE; i++) {')
1218 header_txt.append(' pTrav = pObjectHead[i];')
1219 header_txt.append(' if (pTrav) {')
1220 header_txt.append(' printf("=====%s OBJECT LIST (%lu objs):\\n", string_XGL_OBJECT_TYPE(pTrav->obj.objType), numObjs[i]);')
1221 header_txt.append(' while (pTrav) {')
1222 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);')
1223 header_txt.append(' pTrav = pTrav->pNextObj;')
1224 header_txt.append(' }')
1225 header_txt.append(' }')
1226 header_txt.append(' }')
1227 header_txt.append('}')
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001228 header_txt.append('static void ll_insert_obj(void* pObj, XGL_OBJECT_TYPE objType) {')
Tobin Ehlisca915872014-11-18 11:28:33 -07001229 header_txt.append(' char str[1024];')
1230 header_txt.append(' sprintf(str, "OBJ[%llu] : CREATE %s object %p", object_track_index++, string_XGL_OBJECT_TYPE(objType), (void*)pObj);')
1231 header_txt.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_NONE, "OBJTRACK", str);')
1232 header_txt.append(' objNode* pNewObjNode = (objNode*)malloc(sizeof(objNode));')
1233 header_txt.append(' pNewObjNode->obj.pObj = pObj;')
1234 header_txt.append(' pNewObjNode->obj.objType = objType;')
Mark Lobodzinski40370872015-02-03 10:06:31 -06001235 header_txt.append(' pNewObjNode->obj.status = OBJSTATUS_NONE;')
Tobin Ehlisca915872014-11-18 11:28:33 -07001236 header_txt.append(' pNewObjNode->obj.numUses = 0;')
1237 header_txt.append(' // insert at front of global list')
1238 header_txt.append(' pNewObjNode->pNextGlobal = pGlobalHead;')
1239 header_txt.append(' pGlobalHead = pNewObjNode;')
1240 header_txt.append(' // insert at front of object list')
1241 header_txt.append(' pNewObjNode->pNextObj = pObjectHead[objType];')
1242 header_txt.append(' pObjectHead[objType] = pNewObjNode;')
1243 header_txt.append(' // increment obj counts')
1244 header_txt.append(' numObjs[objType]++;')
1245 header_txt.append(' numTotalObjs++;')
1246 header_txt.append(' //sprintf(str, "OBJ_STAT : %lu total objs & %lu %s objs.", numTotalObjs, numObjs[objType], string_XGL_OBJECT_TYPE(objType));')
Chia-I Wu85763e52014-12-16 11:02:06 +08001247 header_txt.append(' if (0) ll_print_lists();')
Tobin Ehlisca915872014-11-18 11:28:33 -07001248 header_txt.append('}')
1249 header_txt.append('// Traverse global list and return type for given object')
1250 header_txt.append('static XGL_OBJECT_TYPE ll_get_obj_type(XGL_OBJECT object) {')
1251 header_txt.append(' objNode *pTrav = pGlobalHead;')
1252 header_txt.append(' while (pTrav) {')
1253 header_txt.append(' if (pTrav->obj.pObj == object)')
1254 header_txt.append(' return pTrav->obj.objType;')
1255 header_txt.append(' pTrav = pTrav->pNextGlobal;')
1256 header_txt.append(' }')
1257 header_txt.append(' char str[1024];')
1258 header_txt.append(' sprintf(str, "Attempting look-up on obj %p but it is NOT in the global list!", (void*)object);')
1259 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, object, 0, OBJTRACK_MISSING_OBJECT, "OBJTRACK", str);')
1260 header_txt.append(' return XGL_OBJECT_TYPE_UNKNOWN;')
1261 header_txt.append('}')
Chia-I Wu85763e52014-12-16 11:02:06 +08001262 header_txt.append('#if 0')
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001263 header_txt.append('static uint64_t ll_get_obj_uses(void* pObj, XGL_OBJECT_TYPE objType) {')
Tobin Ehlisca915872014-11-18 11:28:33 -07001264 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
1265 header_txt.append(' while (pTrav) {')
1266 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1267 header_txt.append(' return pTrav->obj.numUses;')
1268 header_txt.append(' }')
1269 header_txt.append(' pTrav = pTrav->pNextObj;')
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001270 header_txt.append(' }')
1271 header_txt.append(' return 0;')
1272 header_txt.append('}')
Chia-I Wu85763e52014-12-16 11:02:06 +08001273 header_txt.append('#endif')
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001274 header_txt.append('static void ll_increment_use_count(void* pObj, XGL_OBJECT_TYPE objType) {')
Tobin Ehlisca915872014-11-18 11:28:33 -07001275 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001276 header_txt.append(' while (pTrav) {')
Tobin Ehlisca915872014-11-18 11:28:33 -07001277 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1278 header_txt.append(' pTrav->obj.numUses++;')
1279 header_txt.append(' char str[1024];')
1280 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);')
1281 header_txt.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_NONE, "OBJTRACK", str);')
1282 header_txt.append(' return;')
1283 header_txt.append(' }')
1284 header_txt.append(' pTrav = pTrav->pNextObj;')
1285 header_txt.append(' }')
1286 header_txt.append(' // If we do not find obj, insert it and then increment count')
1287 header_txt.append(' char str[1024];')
1288 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));')
1289 header_txt.append(' layerCbMsg(XGL_DBG_MSG_WARNING, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
1290 header_txt.append('')
1291 header_txt.append(' ll_insert_obj(pObj, objType);')
1292 header_txt.append(' ll_increment_use_count(pObj, objType);')
1293 header_txt.append('}')
1294 header_txt.append('// We usually do not know Obj type when we destroy it so have to fetch')
1295 header_txt.append('// Type from global list w/ ll_destroy_obj()')
1296 header_txt.append('// and then do the full removal from both lists w/ ll_remove_obj_type()')
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001297 header_txt.append('static void ll_remove_obj_type(void* pObj, XGL_OBJECT_TYPE objType) {')
Tobin Ehlisca915872014-11-18 11:28:33 -07001298 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
1299 header_txt.append(' objNode *pPrev = pObjectHead[objType];')
1300 header_txt.append(' while (pTrav) {')
1301 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1302 header_txt.append(' pPrev->pNextObj = pTrav->pNextObj;')
1303 header_txt.append(' // update HEAD of Obj list as needed')
1304 header_txt.append(' if (pObjectHead[objType] == pTrav)')
1305 header_txt.append(' pObjectHead[objType] = pTrav->pNextObj;')
1306 header_txt.append(' assert(numObjs[objType] > 0);')
1307 header_txt.append(' numObjs[objType]--;')
1308 header_txt.append(' char str[1024];')
1309 header_txt.append(' sprintf(str, "OBJ[%llu] : DESTROY %s object %p", object_track_index++, string_XGL_OBJECT_TYPE(objType), (void*)pObj);')
1310 header_txt.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_NONE, "OBJTRACK", str);')
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001311 header_txt.append(' return;')
1312 header_txt.append(' }')
1313 header_txt.append(' pPrev = pTrav;')
Tobin Ehlisca915872014-11-18 11:28:33 -07001314 header_txt.append(' pTrav = pTrav->pNextObj;')
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001315 header_txt.append(' }')
Tobin Ehlisca915872014-11-18 11:28:33 -07001316 header_txt.append(' char str[1024];')
1317 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));')
1318 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_INTERNAL_ERROR, "OBJTRACK", str);')
1319 header_txt.append('}')
1320 header_txt.append('// Parse global list to find obj type, then remove obj from obj type list, finally')
1321 header_txt.append('// remove obj from global list')
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001322 header_txt.append('static void ll_destroy_obj(void* pObj) {')
Tobin Ehlisca915872014-11-18 11:28:33 -07001323 header_txt.append(' objNode *pTrav = pGlobalHead;')
1324 header_txt.append(' objNode *pPrev = pGlobalHead;')
1325 header_txt.append(' while (pTrav) {')
1326 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1327 header_txt.append(' ll_remove_obj_type(pObj, pTrav->obj.objType);')
1328 header_txt.append(' pPrev->pNextGlobal = pTrav->pNextGlobal;')
1329 header_txt.append(' // update HEAD of global list if needed')
1330 header_txt.append(' if (pGlobalHead == pTrav)')
1331 header_txt.append(' pGlobalHead = pTrav->pNextGlobal;')
Tobin Ehlisca915872014-11-18 11:28:33 -07001332 header_txt.append(' assert(numTotalObjs > 0);')
1333 header_txt.append(' numTotalObjs--;')
1334 header_txt.append(' char str[1024];')
1335 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));')
1336 header_txt.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_NONE, "OBJTRACK", str);')
Tobin Ehlis36f1b462015-02-23 14:09:16 -07001337 header_txt.append(' free(pTrav);')
Tobin Ehlisca915872014-11-18 11:28:33 -07001338 header_txt.append(' return;')
1339 header_txt.append(' }')
1340 header_txt.append(' pPrev = pTrav;')
1341 header_txt.append(' pTrav = pTrav->pNextGlobal;')
1342 header_txt.append(' }')
1343 header_txt.append(' char str[1024];')
1344 header_txt.append(' sprintf(str, "Unable to remove obj %p. Was it created? Has it already been destroyed?", pObj);')
1345 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_DESTROY_OBJECT_FAILED, "OBJTRACK", str);')
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001346 header_txt.append('}')
Tobin Ehlis91ce77e2015-01-16 08:56:30 -07001347 header_txt.append('// Set selected flag state for an object node')
1348 header_txt.append('static void set_status(void* pObj, XGL_OBJECT_TYPE objType, OBJECT_STATUS status_flag) {')
Mark Lobodzinski709e16d2015-02-09 10:16:20 -06001349 header_txt.append(' if (pObj != NULL) {')
1350 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
1351 header_txt.append(' while (pTrav) {')
1352 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1353 header_txt.append(' pTrav->obj.status |= status_flag;')
1354 header_txt.append(' return;')
1355 header_txt.append(' }')
1356 header_txt.append(' pTrav = pTrav->pNextObj;')
Tobin Ehlis91ce77e2015-01-16 08:56:30 -07001357 header_txt.append(' }')
Mark Lobodzinski709e16d2015-02-09 10:16:20 -06001358 header_txt.append(' // If we do not find it print an error')
1359 header_txt.append(' char str[1024];')
1360 header_txt.append(' sprintf(str, "Unable to set status for non-existent object %p of %s type", pObj, string_XGL_OBJECT_TYPE(objType));')
1361 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
1362 header_txt.append(' }');
Tobin Ehlis91ce77e2015-01-16 08:56:30 -07001363 header_txt.append('}')
1364 header_txt.append('')
Mark Lobodzinski40370872015-02-03 10:06:31 -06001365 header_txt.append('// Track selected state for an object node')
1366 header_txt.append('static void track_object_status(void* pObj, XGL_STATE_BIND_POINT stateBindPoint) {')
1367 header_txt.append(' objNode *pTrav = pObjectHead[XGL_OBJECT_TYPE_CMD_BUFFER];')
1368 header_txt.append('')
1369 header_txt.append(' while (pTrav) {')
1370 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1371 header_txt.append(' if (stateBindPoint == XGL_STATE_BIND_VIEWPORT) {')
1372 header_txt.append(' pTrav->obj.status |= OBJSTATUS_VIEWPORT_BOUND;')
1373 header_txt.append(' } else if (stateBindPoint == XGL_STATE_BIND_RASTER) {')
1374 header_txt.append(' pTrav->obj.status |= OBJSTATUS_RASTER_BOUND;')
1375 header_txt.append(' } else if (stateBindPoint == XGL_STATE_BIND_COLOR_BLEND) {')
1376 header_txt.append(' pTrav->obj.status |= OBJSTATUS_COLOR_BLEND_BOUND;')
1377 header_txt.append(' } else if (stateBindPoint == XGL_STATE_BIND_DEPTH_STENCIL) {')
1378 header_txt.append(' pTrav->obj.status |= OBJSTATUS_DEPTH_STENCIL_BOUND;')
1379 header_txt.append(' }')
1380 header_txt.append(' return;')
1381 header_txt.append(' }')
1382 header_txt.append(' pTrav = pTrav->pNextObj;')
1383 header_txt.append(' }')
1384 header_txt.append(' // If we do not find it print an error')
1385 header_txt.append(' char str[1024];')
1386 header_txt.append(' sprintf(str, "Unable to track status for non-existent Command Buffer object %p", pObj);')
1387 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
1388 header_txt.append('}')
1389 header_txt.append('')
1390 header_txt.append('// Reset selected flag state for an object node')
1391 header_txt.append('static void reset_status(void* pObj, XGL_OBJECT_TYPE objType, OBJECT_STATUS status_flag) {')
Tobin Ehlis91ce77e2015-01-16 08:56:30 -07001392 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
1393 header_txt.append(' while (pTrav) {')
1394 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
Mark Lobodzinski40370872015-02-03 10:06:31 -06001395 header_txt.append(' pTrav->obj.status &= ~status_flag;')
1396 header_txt.append(' return;')
1397 header_txt.append(' }')
1398 header_txt.append(' pTrav = pTrav->pNextObj;')
1399 header_txt.append(' }')
1400 header_txt.append(' // If we do not find it print an error')
1401 header_txt.append(' char str[1024];')
1402 header_txt.append(' sprintf(str, "Unable to reset status for non-existent object %p of %s type", pObj, string_XGL_OBJECT_TYPE(objType));')
1403 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
1404 header_txt.append('}')
1405 header_txt.append('')
1406 header_txt.append('// Check object status for selected flag state')
Mark Lobodzinski4988dea2015-02-03 11:52:26 -06001407 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 Lobodzinski40370872015-02-03 10:06:31 -06001408 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
1409 header_txt.append(' while (pTrav) {')
1410 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
Mark Lobodzinski4988dea2015-02-03 11:52:26 -06001411 header_txt.append(' if ((pTrav->obj.status & status_mask) != status_flag) {')
Tobin Ehlis91ce77e2015-01-16 08:56:30 -07001412 header_txt.append(' char str[1024];')
1413 header_txt.append(' sprintf(str, "OBJECT VALIDATION WARNING: %s object %p: %s", string_XGL_OBJECT_TYPE(objType), (void*)pObj, fail_msg);')
Mark Lobodzinski40370872015-02-03 10:06:31 -06001414 header_txt.append(' layerCbMsg(error_level, XGL_VALIDATION_LEVEL_0, pObj, 0, error_code, "OBJTRACK", str);')
Tobin Ehlis91ce77e2015-01-16 08:56:30 -07001415 header_txt.append(' }')
1416 header_txt.append(' return;')
1417 header_txt.append(' }')
1418 header_txt.append(' pTrav = pTrav->pNextObj;')
1419 header_txt.append(' }')
1420 header_txt.append(' // If we do not find it print an error')
1421 header_txt.append(' char str[1024];')
1422 header_txt.append(' sprintf(str, "Unable to obtain status for non-existent object %p of %s type", pObj, string_XGL_OBJECT_TYPE(objType));')
1423 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
1424 header_txt.append('}')
Mark Lobodzinski40370872015-02-03 10:06:31 -06001425 header_txt.append('')
1426 header_txt.append('static void validate_draw_state_flags(void* pObj) {')
Mark Lobodzinski4988dea2015-02-03 11:52:26 -06001427 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");')
1428 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");')
1429 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");')
1430 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");')
1431 header_txt.append('}')
1432 header_txt.append('')
1433 header_txt.append('static void validate_memory_mapping_status(const XGL_MEMORY_REF* pMemRefs, uint32_t numRefs) {')
Ian Elliotta83a58a2015-02-04 12:15:12 -07001434 header_txt.append(' uint32_t i;')
Mark Lobodzinski4988dea2015-02-03 11:52:26 -06001435 header_txt.append(' for (i = 0; i < numRefs; i++) {')
Tobin Ehlis4cae4772015-02-20 12:05:30 -07001436 header_txt.append(' if(pMemRefs[i].mem)')
1437 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");')
Mark Lobodzinski4988dea2015-02-03 11:52:26 -06001438 header_txt.append(' }')
Mark Lobodzinski40370872015-02-03 10:06:31 -06001439 header_txt.append('}')
Mark Lobodzinskiaae93e52015-02-09 10:20:53 -06001440 header_txt.append('')
1441 header_txt.append('static void validate_mem_ref_count(uint32_t numRefs) {')
1442 header_txt.append(' if (maxMemRefsPerSubmission == 0) {')
1443 header_txt.append(' char str[1024];')
1444 header_txt.append(' sprintf(str, "xglQueueSubmit called before calling xglGetGpuInfo");')
1445 header_txt.append(' layerCbMsg(XGL_DBG_MSG_WARNING, XGL_VALIDATION_LEVEL_0, NULL, 0, OBJTRACK_GETGPUINFO_NOT_CALLED, "OBJTRACK", str);')
1446 header_txt.append(' } else {')
1447 header_txt.append(' if (numRefs > maxMemRefsPerSubmission) {')
1448 header_txt.append(' char str[1024];')
1449 header_txt.append(' sprintf(str, "xglQueueSubmit Memory reference count (%d) exceeds allowable GPU limit (%d)", numRefs, maxMemRefsPerSubmission);')
1450 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, OBJTRACK_MEMREFCOUNT_MAX_EXCEEDED, "OBJTRACK", str);')
1451 header_txt.append(' }')
1452 header_txt.append(' }')
1453 header_txt.append('}')
1454 header_txt.append('')
1455 header_txt.append('static void setGpuInfoState(void *pData) {')
1456 header_txt.append(' maxMemRefsPerSubmission = ((XGL_PHYSICAL_GPU_PROPERTIES *)pData)->maxMemRefsPerSubmission;')
1457 header_txt.append('}')
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001458 return "\n".join(header_txt)
1459
1460 def generate_body(self):
Tobin Ehlis36f1b462015-02-23 14:09:16 -07001461 body = [self._generate_layer_initialization("ObjectTracker", True, lockname='obj'),
Tobin Ehlisa363cfa2014-11-25 16:59:27 -07001462 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "ObjectTracker"),
Tobin Ehlisca915872014-11-18 11:28:33 -07001463 self._generate_extensions(),
Jon Ashburnd6badbc2015-02-16 08:26:50 -07001464 self._generate_layer_gpa_function("ObjectTracker", extensions=['objTrackGetObjectCount', 'objTrackGetObjects'])]
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001465
1466 return "\n\n".join(body)
Courtney Goeltzenleuchterb412d212014-11-18 10:40:29 -07001467
Tobin Ehlis14ff0852014-12-17 17:44:50 -07001468class ParamCheckerSubcommand(Subcommand):
1469 def generate_header(self):
Jon Ashburnd6badbc2015-02-16 08:26:50 -07001470 return '#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include "loader_platform.h"\n#include "xglLayer.h"\n#include "layers_config.h"\n#include "xgl_enum_validate_helper.h"\n#include "xgl_struct_validate_helper.h"\n//The following is #included again to catch certain OS-specific functions being used:\n#include "loader_platform.h"\n\n#include "layers_msg.h"\n\nstatic XGL_LAYER_DISPATCH_TABLE nextTable;\nstatic XGL_BASE_LAYER_OBJECT *pCurObj;\nstatic LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);\n\n'
Tobin Ehlis14ff0852014-12-17 17:44:50 -07001471
1472 def generate_body(self):
Jon Ashburnd6badbc2015-02-16 08:26:50 -07001473 body = [self._generate_layer_initialization("ParamChecker", True),
Tobin Ehlis14ff0852014-12-17 17:44:50 -07001474 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "ParamChecker"),
Jon Ashburnd6badbc2015-02-16 08:26:50 -07001475 self._generate_layer_gpa_function("ParamChecker")]
Tobin Ehlis14ff0852014-12-17 17:44:50 -07001476
1477 return "\n\n".join(body)
1478
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001479def main():
1480 subcommands = {
1481 "layer-funcs" : LayerFuncsSubcommand,
1482 "layer-dispatch" : LayerDispatchSubcommand,
Tobin Ehlisa363cfa2014-11-25 16:59:27 -07001483 "Generic" : GenericLayerSubcommand,
1484 "ApiDump" : ApiDumpSubcommand,
1485 "ApiDumpFile" : ApiDumpFileSubcommand,
Tobin Ehlisd49efcb2014-11-25 17:43:26 -07001486 "ApiDumpNoAddr" : ApiDumpNoAddrSubcommand,
Tobin Ehlis99f88672015-01-10 12:42:41 -07001487 "ApiDumpCpp" : ApiDumpCppSubcommand,
1488 "ApiDumpNoAddrCpp" : ApiDumpNoAddrCppSubcommand,
Tobin Ehlisa363cfa2014-11-25 16:59:27 -07001489 "ObjectTracker" : ObjectTrackerSubcommand,
Tobin Ehlis14ff0852014-12-17 17:44:50 -07001490 "ParamChecker" : ParamCheckerSubcommand,
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001491 }
1492
Tobin Ehlis14ff0852014-12-17 17:44:50 -07001493 if len(sys.argv) < 3 or sys.argv[1] not in subcommands or not os.path.exists(sys.argv[2]):
1494 print("Usage: %s <subcommand> <input_header> [options]" % sys.argv[0])
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001495 print
Tobin Ehlis7e65d752015-01-15 17:51:52 -07001496 print("Available subcommands are: %s" % " ".join(subcommands))
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001497 exit(1)
1498
Tobin Ehlis14ff0852014-12-17 17:44:50 -07001499 hfp = xgl_helper.HeaderFileParser(sys.argv[2])
1500 hfp.parse()
1501 xgl_helper.enum_val_dict = hfp.get_enum_val_dict()
1502 xgl_helper.enum_type_dict = hfp.get_enum_type_dict()
1503 xgl_helper.struct_dict = hfp.get_struct_dict()
1504 xgl_helper.typedef_fwd_dict = hfp.get_typedef_fwd_dict()
1505 xgl_helper.typedef_rev_dict = hfp.get_typedef_rev_dict()
1506 xgl_helper.types_dict = hfp.get_types_dict()
1507
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001508 subcmd = subcommands[sys.argv[1]](sys.argv[2:])
1509 subcmd.run()
1510
1511if __name__ == "__main__":
1512 main()