blob: 6e0d8850a26f921ba93d03f42915e9d0b1e6bd0f [file] [log] [blame]
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001#!/usr/bin/env python3
2#
3# XGL
4#
5# Copyright (C) 2014 LunarG, Inc.
6#
7# Permission is hereby granted, free of charge, to any person obtaining a
8# copy of this software and associated documentation files (the "Software"),
9# to deal in the Software without restriction, including without limitation
10# the rights to use, copy, modify, merge, publish, distribute, sublicense,
11# and/or sell copies of the Software, and to permit persons to whom the
12# Software is furnished to do so, subject to the following conditions:
13#
14# The above copyright notice and this permission notice shall be included
15# in all copies or substantial portions of the Software.
16#
17# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23# DEALINGS IN THE SOFTWARE.
24#
25# Authors:
26# Chia-I Wu <olv@lunarg.com>
27
28import sys
Tobin Ehlis6cd06372014-12-17 17:44:50 -070029import os
Tobin Ehlis92dbf802014-10-22 09:06:33 -060030
31import xgl
Tobin Ehlis6cd06372014-12-17 17:44:50 -070032import xgl_helper
Tobin Ehlis92dbf802014-10-22 09:06:33 -060033
34class Subcommand(object):
35 def __init__(self, argv):
36 self.argv = argv
Chia-I Wuec30dcb2015-01-01 08:46:31 +080037 self.headers = xgl.headers
38 self.protos = xgl.protos
Tobin Ehlis92dbf802014-10-22 09:06:33 -060039
40 def run(self):
Tobin Ehlis92dbf802014-10-22 09:06:33 -060041 print(self.generate())
42
43 def generate(self):
44 copyright = self.generate_copyright()
45 header = self.generate_header()
46 body = self.generate_body()
47 footer = self.generate_footer()
48
49 contents = []
50 if copyright:
51 contents.append(copyright)
52 if header:
53 contents.append(header)
54 if body:
55 contents.append(body)
56 if footer:
57 contents.append(footer)
58
59 return "\n\n".join(contents)
60
61 def generate_copyright(self):
62 return """/* THIS FILE IS GENERATED. DO NOT EDIT. */
63
64/*
65 * XGL
66 *
67 * Copyright (C) 2014 LunarG, Inc.
68 *
69 * Permission is hereby granted, free of charge, to any person obtaining a
70 * copy of this software and associated documentation files (the "Software"),
71 * to deal in the Software without restriction, including without limitation
72 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
73 * and/or sell copies of the Software, and to permit persons to whom the
74 * Software is furnished to do so, subject to the following conditions:
75 *
76 * The above copyright notice and this permission notice shall be included
77 * in all copies or substantial portions of the Software.
78 *
79 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
80 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
81 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
82 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
83 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
84 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
85 * DEALINGS IN THE SOFTWARE.
86 */"""
87
88 def generate_header(self):
89 return "\n".join(["#include <" + h + ">" for h in self.headers])
90
91 def generate_body(self):
92 pass
93
94 def generate_footer(self):
95 pass
96
97 # Return set of printf '%' qualifier and input to that qualifier
Tobin Ehlis434db7c2015-01-10 12:42:41 -070098 def _get_printf_params(self, xgl_type, name, output_param, cpp=False):
Tobin Ehlis92dbf802014-10-22 09:06:33 -060099 # TODO : Need ENUM and STRUCT checks here
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700100 if xgl_helper.is_type(xgl_type, 'enum'):#"_TYPE" in xgl_type: # TODO : This should be generic ENUM check
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600101 return ("%s", "string_%s(%s)" % (xgl_type.strip('const ').strip('*'), name))
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600102 if "char*" == xgl_type:
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600103 return ("%s", name)
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700104 if "uint64" in xgl_type:
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600105 if '*' in xgl_type:
106 return ("%lu", "*%s" % name)
107 return ("%lu", name)
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700108 if "size" in xgl_type:
Chia-I Wu54ed0792014-12-27 14:14:50 +0800109 if '*' in xgl_type:
110 return ("%zu", "*%s" % name)
111 return ("%zu", name)
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700112 if "float" in xgl_type:
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600113 if '[' in xgl_type: # handle array, current hard-coded to 4 (TODO: Make this dynamic)
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700114 if cpp:
115 return ("[%i, %i, %i, %i]", '"[" << %s[0] << "," << %s[1] << "," << %s[2] << "," << %s[3] << "]"' % (name, name, name, name))
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600116 return ("[%f, %f, %f, %f]", "%s[0], %s[1], %s[2], %s[3]" % (name, name, name, name))
117 return ("%f", name)
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700118 if "bool" in xgl_type or 'xcb_randr_crtc_t' in xgl_type:
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600119 return ("%u", name)
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700120 if True in [t in xgl_type for t in ["int", "FLAGS", "MASK", "xcb_window_t"]]:
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600121 if '[' in xgl_type: # handle array, current hard-coded to 4 (TODO: Make this dynamic)
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700122 if cpp:
123 return ("[%i, %i, %i, %i]", "%s[0] << %s[1] << %s[2] << %s[3]" % (name, name, name, name))
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600124 return ("[%i, %i, %i, %i]", "%s[0], %s[1], %s[2], %s[3]" % (name, name, name, name))
125 if '*' in xgl_type:
Tobin Ehlis1336c8d2015-02-04 15:15:11 -0700126 if 'pUserData' == name:
127 return ("%i", "((pUserData == 0) ? 0 : *(pUserData))")
Jon Ashburn1f7e2d72014-12-12 16:10:45 -0700128 return ("%i", "*(%s)" % name)
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600129 return ("%i", name)
Tobin Ehlis0a1e06d2014-11-11 17:28:22 -0700130 # TODO : This is special-cased as there's only one "format" param currently and it's nice to expand it
Jon Ashburn1f7e2d72014-12-12 16:10:45 -0700131 if "XGL_FORMAT" == xgl_type:
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700132 if cpp:
133 return ("%p", "&%s" % name)
134 return ("{%s.channelFormat = %%s, %s.numericFormat = %%s}" % (name, name), "string_XGL_CHANNEL_FORMAT(%s.channelFormat), string_XGL_NUM_FORMAT(%s.numericFormat)" % (name, name))
Tobin Ehlisa554dc32014-11-19 15:52:46 -0700135 if output_param:
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600136 return ("%p", "(void*)*%s" % name)
Jon Ashburn1f7e2d72014-12-12 16:10:45 -0700137 return ("%p", "(void*)(%s)" % name)
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600138
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700139 def _gen_layer_dbg_callback_register(self):
140 r_body = []
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600141 r_body.append('XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglDbgRegisterMsgCallback(XGL_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback, void* pUserData)')
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700142 r_body.append('{')
143 r_body.append(' // This layer intercepts callbacks')
144 r_body.append(' XGL_LAYER_DBG_FUNCTION_NODE *pNewDbgFuncNode = (XGL_LAYER_DBG_FUNCTION_NODE*)malloc(sizeof(XGL_LAYER_DBG_FUNCTION_NODE));')
145 r_body.append(' if (!pNewDbgFuncNode)')
146 r_body.append(' return XGL_ERROR_OUT_OF_MEMORY;')
147 r_body.append(' pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;')
148 r_body.append(' pNewDbgFuncNode->pUserData = pUserData;')
Jon Ashburn21001f62015-02-16 08:26:50 -0700149 r_body.append(' pNewDbgFuncNode->pNext = g_pDbgFunctionHead;')
150 r_body.append(' g_pDbgFunctionHead = pNewDbgFuncNode;')
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700151 r_body.append(' XGL_RESULT result = nextTable.DbgRegisterMsgCallback(pfnMsgCallback, pUserData);')
152 r_body.append(' return result;')
153 r_body.append('}')
154 return "\n".join(r_body)
155
156 def _gen_layer_dbg_callback_unregister(self):
157 ur_body = []
158 ur_body.append('XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglDbgUnregisterMsgCallback(XGL_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback)')
159 ur_body.append('{')
Jon Ashburn21001f62015-02-16 08:26:50 -0700160 ur_body.append(' XGL_LAYER_DBG_FUNCTION_NODE *pTrav = g_pDbgFunctionHead;')
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700161 ur_body.append(' XGL_LAYER_DBG_FUNCTION_NODE *pPrev = pTrav;')
162 ur_body.append(' while (pTrav) {')
163 ur_body.append(' if (pTrav->pfnMsgCallback == pfnMsgCallback) {')
164 ur_body.append(' pPrev->pNext = pTrav->pNext;')
Jon Ashburn21001f62015-02-16 08:26:50 -0700165 ur_body.append(' if (g_pDbgFunctionHead == pTrav)')
166 ur_body.append(' g_pDbgFunctionHead = pTrav->pNext;')
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700167 ur_body.append(' free(pTrav);')
168 ur_body.append(' break;')
169 ur_body.append(' }')
170 ur_body.append(' pPrev = pTrav;')
171 ur_body.append(' pTrav = pTrav->pNext;')
172 ur_body.append(' }')
173 ur_body.append(' XGL_RESULT result = nextTable.DbgUnregisterMsgCallback(pfnMsgCallback);')
174 ur_body.append(' return result;')
175 ur_body.append('}')
176 return "\n".join(ur_body)
177
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -0700178 def _generate_dispatch_entrypoints(self, qual="", layer="Generic", no_addr=False):
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600179 if qual:
180 qual += " "
181
Tobin Ehlis907a0522014-11-25 16:59:27 -0700182 layer_name = layer
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -0700183 if no_addr:
184 layer_name = "%sNoAddr" % layer
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700185 if 'Cpp' in layer_name:
186 layer_name = "APIDumpNoAddrCpp"
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600187 funcs = []
188 for proto in self.protos:
189 if proto.name != "GetProcAddr" and proto.name != "InitAndEnumerateGpus":
Tobin Ehlis907a0522014-11-25 16:59:27 -0700190 if "Generic" == layer:
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600191 decl = proto.c_func(prefix="xgl", attr="XGLAPI")
192 param0_name = proto.params[0].name
193 ret_val = ''
194 stmt = ''
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600195 if proto.ret != "void":
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600196 ret_val = "XGL_RESULT result = "
197 stmt = " return result;\n"
Ian Elliott81ac44c2015-01-13 17:52:38 -0700198 if 'WsiX11AssociateConnection' == proto.name:
199 funcs.append("#if !defined(_WIN32)")
Jon Ashburn451c16f2014-11-25 11:08:42 -0700200 if proto.name == "EnumerateLayers":
201 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
202 funcs.append('%s%s\n'
203 '{\n'
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700204 ' char str[1024];\n'
Jon Ashburn451c16f2014-11-25 11:08:42 -0700205 ' if (gpu != NULL) {\n'
206 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700207 ' sprintf(str, "At start of layered %s\\n");\n'
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600208 ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpu, 0, 0, (char *) "GENERIC", (char *) str);\n'
Jon Ashburn451c16f2014-11-25 11:08:42 -0700209 ' pCurObj = gpuw;\n'
Jon Ashburn21001f62015-02-16 08:26:50 -0700210 ' loader_platform_thread_once(&tabOnce, init%s);\n'
Jon Ashburn451c16f2014-11-25 11:08:42 -0700211 ' %snextTable.%s;\n'
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700212 ' sprintf(str, "Completed layered %s\\n");\n'
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600213 ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpu, 0, 0, (char *) "GENERIC", (char *) str);\n'
Jon Ashburn451c16f2014-11-25 11:08:42 -0700214 ' fflush(stdout);\n'
215 ' %s'
216 ' } else {\n'
217 ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n'
218 ' return XGL_ERROR_INVALID_POINTER;\n'
219 ' // This layer compatible with all GPUs\n'
220 ' *pOutLayerCount = 1;\n'
Chia-I Wua837c522014-12-16 10:47:33 +0800221 ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n'
Jon Ashburn451c16f2014-11-25 11:08:42 -0700222 ' return XGL_SUCCESS;\n'
223 ' }\n'
Jon Ashburn21001f62015-02-16 08:26:50 -0700224 '}' % (qual, decl, proto.params[0].name, proto.name, layer_name, ret_val, c_call, proto.name, stmt, layer_name))
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700225 elif 'DbgRegisterMsgCallback' == proto.name:
226 funcs.append(self._gen_layer_dbg_callback_register())
227 elif 'DbgUnregisterMsgCallback' == proto.name:
228 funcs.append(self._gen_layer_dbg_callback_unregister())
Jon Ashburn451c16f2014-11-25 11:08:42 -0700229 elif proto.params[0].ty != "XGL_PHYSICAL_GPU":
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600230 funcs.append('%s%s\n'
231 '{\n'
232 ' %snextTable.%s;\n'
233 '%s'
234 '}' % (qual, decl, ret_val, proto.c_call(), stmt))
235 else:
236 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
237 funcs.append('%s%s\n'
238 '{\n'
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700239 ' char str[1024];'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600240 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700241 ' sprintf(str, "At start of layered %s\\n");\n'
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600242 ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpuw, 0, 0, (char *) "GENERIC", (char *) str);\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600243 ' pCurObj = gpuw;\n'
Jon Ashburn21001f62015-02-16 08:26:50 -0700244 ' loader_platform_thread_once(&tabOnce, init%s);\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600245 ' %snextTable.%s;\n'
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700246 ' sprintf(str, "Completed layered %s\\n");\n'
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600247 ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpuw, 0, 0, (char *) "GENERIC", (char *) str);\n'
Courtney Goeltzenleuchtere6094fc2014-11-18 10:40:29 -0700248 ' fflush(stdout);\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600249 '%s'
Jon Ashburn21001f62015-02-16 08:26:50 -0700250 '}' % (qual, decl, proto.params[0].name, proto.name, layer_name, ret_val, c_call, proto.name, stmt))
Ian Elliott81ac44c2015-01-13 17:52:38 -0700251 if 'WsiX11QueuePresent' == proto.name:
252 funcs.append("#endif")
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700253 elif "APIDumpCpp" in layer:
254 decl = proto.c_func(prefix="xgl", attr="XGLAPI")
255 param0_name = proto.params[0].name
256 ret_val = ''
257 stmt = ''
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700258 sp_param_dict = {} # Store 'index' for struct param to print, or an name of binding "Count" param for array to print
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700259 create_params = 0 # Num of params at end of function that are created and returned as output values
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700260 if 'WsiX11CreatePresentableImage' in proto.name or 'AllocDescriptorSets' in proto.name:
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700261 create_params = -2
262 elif 'Create' in proto.name or 'Alloc' in proto.name or 'MapMemory' in proto.name:
263 create_params = -1
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600264 if proto.ret != "void":
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700265 ret_val = "XGL_RESULT result = "
266 stmt = " return result;\n"
267 f_open = ''
268 f_close = ''
269 if "File" in layer:
270 file_mode = "a"
271 if 'CreateDevice' in proto.name:
272 file_mode = "w"
Ian Elliott81ac44c2015-01-13 17:52:38 -0700273 f_open = 'loader_platform_thread_lock_mutex(&printLock);\n pOutFile = fopen(outFileName, "%s");\n ' % (file_mode)
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700274 log_func = 'fprintf(pOutFile, "t{%%u} xgl%s(' % proto.name
Ian Elliott81ac44c2015-01-13 17:52:38 -0700275 f_close = '\n fclose(pOutFile);\n loader_platform_thread_unlock_mutex(&printLock);'
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700276 else:
Ian Elliott81ac44c2015-01-13 17:52:38 -0700277 f_open = 'loader_platform_thread_lock_mutex(&printLock);\n '
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700278 log_func = 'cout << "t{" << getTIDIndex() << "} xgl%s(' % proto.name
Ian Elliott81ac44c2015-01-13 17:52:38 -0700279 f_close = '\n loader_platform_thread_unlock_mutex(&printLock);'
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700280 pindex = 0
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700281 prev_count_name = ''
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700282 for p in proto.params:
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700283 cp = False
284 if 0 != create_params:
285 # If this is any of the N last params of the func, treat as output
286 for y in range(-1, create_params-1, -1):
287 if p.name == proto.params[y].name:
288 cp = True
289 (pft, pfi) = self._get_printf_params(p.ty, p.name, cp, cpp=True)
290 if no_addr and "%p" == pft:
291 (pft, pfi) = ("%s", '"addr"')
292 log_func += '%s = " << %s << ", ' % (p.name, pfi)
293 #print_vals += ', %s' % (pfi)
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700294 if prev_count_name != '' and (prev_count_name.strip('Count')[1:] in p.name or 'slotCount' == prev_count_name):
295 sp_param_dict[pindex] = prev_count_name
296 elif 'pDescriptorSets' == p.name and proto.params[-1].name == 'pCount':
297 sp_param_dict[pindex] = '*pCount'
Tobin Ehlisfc04b892015-01-22 12:29:31 -0700298 elif 'Wsi' not in proto.name and xgl_helper.is_type(p.ty.strip('*').strip('const '), 'struct'):
299 sp_param_dict[pindex] = 'index'
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700300 pindex += 1
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700301 if p.name.endswith('Count'):
302 if '*' in p.ty:
303 prev_count_name = "*%s" % p.name
304 else:
305 prev_count_name = p.name
306 else:
307 prev_count_name = ''
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700308 log_func = log_func.strip(', ')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600309 if proto.ret != "void":
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700310 log_func += ') = " << string_XGL_RESULT((XGL_RESULT)result) << "\\n"'
311 #print_vals += ', string_XGL_RESULT_CODE(result)'
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700312 else:
313 log_func += ')\\n"'
314 log_func += ';'
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700315 if len(sp_param_dict) > 0:
316 i_decl = False
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700317 log_func += '\n string tmp_str;'
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700318 for sp_index in sp_param_dict:
319 if 'index' == sp_param_dict[sp_index]:
320 cis_print_func = 'xgl_print_%s' % (proto.params[sp_index].ty.strip('const ').strip('*').lower())
321 log_func += '\n if (%s) {' % (proto.params[sp_index].name)
322 log_func += '\n tmp_str = %s(%s, " ");' % (cis_print_func, proto.params[sp_index].name)
323 if "File" in layer:
324 if no_addr:
325 log_func += '\n fprintf(pOutFile, " %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name)
326 else:
327 log_func += '\n fprintf(pOutFile, " %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name)
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700328 else:
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700329 if no_addr:
330 #log_func += '\n printf(" %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name)
331 log_func += '\n cout << " %s (addr)" << endl << tmp_str << endl;' % (proto.params[sp_index].name)
332 else:
333 #log_func += '\n printf(" %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name)
334 log_func += '\n cout << " %s (" << %s << ")" << endl << tmp_str << endl;' % (proto.params[sp_index].name, proto.params[sp_index].name)
335 #log_func += '\n fflush(stdout);'
336 log_func += '\n }'
337 else: # We have a count value stored to iterate over an array
338 print_cast = ''
339 print_func = ''
340 if xgl_helper.is_type(proto.params[sp_index].ty.strip('*').strip('const '), 'struct'):
341 print_cast = '&'
342 print_func = 'xgl_print_%s' % proto.params[sp_index].ty.strip('const ').strip('*').lower()
343 #cis_print_func = 'tmp_str = xgl_print_%s(&%s[i], " ");' % (proto.params[sp_index].ty.strip('const ').strip('*').lower(), proto.params[sp_index].name)
344# TODO : Need to display this address as a string
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700345 else:
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700346 print_cast = '(void*)'
347 print_func = 'string_convert_helper'
348 #cis_print_func = 'tmp_str = string_convert_helper((void*)%s[i], " ");' % proto.params[sp_index].name
349 cis_print_func = 'tmp_str = %s(%s%s[i], " ");' % (print_func, print_cast, proto.params[sp_index].name)
350# else:
351# cis_print_func = ''
352 if not i_decl:
353 log_func += '\n uint32_t i;'
354 i_decl = True
355 log_func += '\n for (i = 0; i < %s; i++) {' % (sp_param_dict[sp_index])
356 log_func += '\n %s' % (cis_print_func)
357 if "File" in layer:
358 if no_addr:
359 log_func += '\n fprintf(pOutFile, " %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name)
360 else:
361 log_func += '\n fprintf(pOutFile, " %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name)
362 else:
363 if no_addr:
364 #log_func += '\n printf(" %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name)
365 log_func += '\n cout << " %s[" << (uint32_t)i << "] (addr)" << endl << tmp_str << endl;' % (proto.params[sp_index].name)
366 else:
367 #log_func += '\n printf(" %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name)
368 #log_func += '\n cout << " %s[" << (uint32_t)i << "] (" << %s[i] << ")" << endl << tmp_str << endl;' % (proto.params[sp_index].name, proto.params[sp_index].name)
369 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)
370 #log_func += '\n fflush(stdout);'
371 log_func += '\n }'
Ian Elliott81ac44c2015-01-13 17:52:38 -0700372 if 'WsiX11AssociateConnection' == proto.name:
373 funcs.append("#if !defined(_WIN32)")
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700374 if proto.name == "EnumerateLayers":
375 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
376 funcs.append('%s%s\n'
377 '{\n'
378 ' if (gpu != NULL) {\n'
379 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
380 ' pCurObj = gpuw;\n'
Jon Ashburn21001f62015-02-16 08:26:50 -0700381 ' loader_platform_thread_once(&tabOnce, init%s);\n'
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700382 ' %snextTable.%s;\n'
383 ' %s %s %s\n'
384 ' %s'
385 ' } else {\n'
386 ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n'
387 ' return XGL_ERROR_INVALID_POINTER;\n'
388 ' // This layer compatible with all GPUs\n'
389 ' *pOutLayerCount = 1;\n'
390 ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n'
391 ' return XGL_SUCCESS;\n'
392 ' }\n'
Jon Ashburn21001f62015-02-16 08:26:50 -0700393 '}' % (qual, decl, proto.params[0].name, layer_name, ret_val, c_call,f_open, log_func, f_close, stmt, layer_name))
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700394 elif proto.params[0].ty != "XGL_PHYSICAL_GPU":
395 funcs.append('%s%s\n'
396 '{\n'
397 ' %snextTable.%s;\n'
398 ' %s%s%s\n'
399 '%s'
400 '}' % (qual, decl, ret_val, proto.c_call(), f_open, log_func, f_close, stmt))
401 else:
402 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
403 funcs.append('%s%s\n'
404 '{\n'
405 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
406 ' pCurObj = gpuw;\n'
Jon Ashburn21001f62015-02-16 08:26:50 -0700407 ' loader_platform_thread_once(&tabOnce, init%s);\n'
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700408 ' %snextTable.%s;\n'
409 ' %s%s%s\n'
410 '%s'
Jon Ashburn21001f62015-02-16 08:26:50 -0700411 '}' % (qual, decl, proto.params[0].name, layer_name, ret_val, c_call, f_open, log_func, f_close, stmt))
Ian Elliott81ac44c2015-01-13 17:52:38 -0700412 if 'WsiX11QueuePresent' == proto.name:
413 funcs.append("#endif")
Tobin Ehlis907a0522014-11-25 16:59:27 -0700414 elif "APIDump" in layer:
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600415 decl = proto.c_func(prefix="xgl", attr="XGLAPI")
416 param0_name = proto.params[0].name
417 ret_val = ''
418 stmt = ''
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700419 sp_param_dict = {} # Store 'index' for struct param to print, or an name of binding "Count" param for array to print
Tobin Ehlisa554dc32014-11-19 15:52:46 -0700420 create_params = 0 # Num of params at end of function that are created and returned as output values
421 if 'WsiX11CreatePresentableImage' in proto.name:
422 create_params = -2
423 elif 'Create' in proto.name or 'Alloc' in proto.name or 'MapMemory' in proto.name:
424 create_params = -1
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600425 if proto.ret != "void":
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600426 ret_val = "XGL_RESULT result = "
427 stmt = " return result;\n"
Tobin Ehlis574b0142014-11-12 13:11:15 -0700428 f_open = ''
429 f_close = ''
Tobin Ehlis907a0522014-11-25 16:59:27 -0700430 if "File" in layer:
Tobin Ehlis1eba7792014-11-21 09:35:53 -0700431 file_mode = "a"
432 if 'CreateDevice' in proto.name:
433 file_mode = "w"
Ian Elliott81ac44c2015-01-13 17:52:38 -0700434 f_open = 'loader_platform_thread_lock_mutex(&printLock);\n pOutFile = fopen(outFileName, "%s");\n ' % (file_mode)
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700435 log_func = 'fprintf(pOutFile, "t{%%u} xgl%s(' % proto.name
Ian Elliott81ac44c2015-01-13 17:52:38 -0700436 f_close = '\n fclose(pOutFile);\n loader_platform_thread_unlock_mutex(&printLock);'
Tobin Ehlis574b0142014-11-12 13:11:15 -0700437 else:
Ian Elliott81ac44c2015-01-13 17:52:38 -0700438 f_open = 'loader_platform_thread_lock_mutex(&printLock);\n '
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700439 log_func = 'printf("t{%%u} xgl%s(' % proto.name
Ian Elliott81ac44c2015-01-13 17:52:38 -0700440 f_close = '\n loader_platform_thread_unlock_mutex(&printLock);'
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700441 print_vals = ', getTIDIndex()'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600442 pindex = 0
Tobin Ehlisc7e926b2014-12-18 15:20:05 -0700443 prev_count_name = ''
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600444 for p in proto.params:
Tobin Ehlisa554dc32014-11-19 15:52:46 -0700445 cp = False
446 if 0 != create_params:
447 # If this is any of the N last params of the func, treat as output
448 for y in range(-1, create_params-1, -1):
449 if p.name == proto.params[y].name:
450 cp = True
451 (pft, pfi) = self._get_printf_params(p.ty, p.name, cp)
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -0700452 if no_addr and "%p" == pft:
453 (pft, pfi) = ("%s", '"addr"')
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600454 log_func += '%s = %s, ' % (p.name, pft)
455 print_vals += ', %s' % (pfi)
Tobin Ehlisc7e926b2014-12-18 15:20:05 -0700456 # Catch array inputs that are bound by a "Count" param
457 if prev_count_name != '' and (prev_count_name.strip('Count')[1:] in p.name or 'slotCount' == prev_count_name):
458 sp_param_dict[pindex] = prev_count_name
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700459 elif 'pDescriptorSets' == p.name and proto.params[-1].name == 'pCount':
460 sp_param_dict[pindex] = '*pCount'
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700461 elif 'Wsi' not in proto.name and xgl_helper.is_type(p.ty.strip('*').strip('const '), 'struct'):
Tobin Ehlisc7e926b2014-12-18 15:20:05 -0700462 sp_param_dict[pindex] = 'index'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600463 pindex += 1
Tobin Ehlisc7e926b2014-12-18 15:20:05 -0700464 if p.name.endswith('Count'):
Courtney Goeltzenleuchter08cf7cc2015-01-13 15:32:18 -0700465 if '*' in p.ty:
466 prev_count_name = "*%s" % p.name
467 else:
468 prev_count_name = p.name
Tobin Ehlisc7e926b2014-12-18 15:20:05 -0700469 else:
470 prev_count_name = ''
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600471 log_func = log_func.strip(', ')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600472 if proto.ret != "void":
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600473 log_func += ') = %s\\n"'
Courtney Goeltzenleuchtere6094fc2014-11-18 10:40:29 -0700474 print_vals += ', string_XGL_RESULT(result)'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600475 else:
476 log_func += ')\\n"'
477 log_func = '%s%s);' % (log_func, print_vals)
Tobin Ehlisc7e926b2014-12-18 15:20:05 -0700478 if len(sp_param_dict) > 0:
479 i_decl = False
480 log_func += '\n char *pTmpStr = "";'
481 for sp_index in sorted(sp_param_dict):
482 # TODO : Clean this if/else block up, too much duplicated code
483 if 'index' == sp_param_dict[sp_index]:
484 cis_print_func = 'xgl_print_%s' % (proto.params[sp_index].ty.strip('const ').strip('*').lower())
485 log_func += '\n if (%s) {' % (proto.params[sp_index].name)
486 log_func += '\n pTmpStr = %s(%s, " ");' % (cis_print_func, proto.params[sp_index].name)
487 if "File" in layer:
488 if no_addr:
489 log_func += '\n fprintf(pOutFile, " %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name)
490 else:
491 log_func += '\n fprintf(pOutFile, " %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name)
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -0700492 else:
Tobin Ehlisc7e926b2014-12-18 15:20:05 -0700493 if no_addr:
494 log_func += '\n printf(" %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name)
495 else:
496 log_func += '\n printf(" %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name)
497 log_func += '\n fflush(stdout);'
498 log_func += '\n free(pTmpStr);\n }'
499 else: # should have a count value stored to iterate over array
500 if xgl_helper.is_type(proto.params[sp_index].ty.strip('*').strip('const '), 'struct'):
501 cis_print_func = 'pTmpStr = xgl_print_%s(&%s[i], " ");' % (proto.params[sp_index].ty.strip('const ').strip('*').lower(), proto.params[sp_index].name)
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -0700502 else:
Tobin Ehlisc7e926b2014-12-18 15:20:05 -0700503 cis_print_func = 'pTmpStr = (char*)malloc(sizeof(char));\n sprintf(pTmpStr, " %%p", %s[i]);' % proto.params[sp_index].name
504 if not i_decl:
505 log_func += '\n uint32_t i;'
506 i_decl = True
Jon Ashburn48637592015-01-14 08:52:37 -0700507 log_func += '\n for (i = 0; i < %s; i++) {' % (sp_param_dict[sp_index])
Tobin Ehlisc7e926b2014-12-18 15:20:05 -0700508 log_func += '\n %s' % (cis_print_func)
509 if "File" in layer:
510 if no_addr:
511 log_func += '\n fprintf(pOutFile, " %s[%%i] (addr)\\n%%s\\n", i, pTmpStr);' % (proto.params[sp_index].name)
512 else:
513 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)
514 else:
515 if no_addr:
516 log_func += '\n printf(" %s[%%i] (addr)\\n%%s\\n", i, pTmpStr);' % (proto.params[sp_index].name)
517 else:
518 log_func += '\n printf(" %s[%%i] (%%p)\\n%%s\\n", i, (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name)
519 log_func += '\n fflush(stdout);'
520 log_func += '\n free(pTmpStr);\n }'
Ian Elliott81ac44c2015-01-13 17:52:38 -0700521 if 'WsiX11AssociateConnection' == proto.name:
522 funcs.append("#if !defined(_WIN32)")
Jon Ashburn451c16f2014-11-25 11:08:42 -0700523 if proto.name == "EnumerateLayers":
524 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
525 funcs.append('%s%s\n'
526 '{\n'
527 ' if (gpu != NULL) {\n'
528 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
529 ' pCurObj = gpuw;\n'
Jon Ashburn21001f62015-02-16 08:26:50 -0700530 ' loader_platform_thread_once(&tabOnce, init%s);\n'
Jon Ashburn451c16f2014-11-25 11:08:42 -0700531 ' %snextTable.%s;\n'
532 ' %s %s %s\n'
533 ' %s'
534 ' } else {\n'
535 ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n'
536 ' return XGL_ERROR_INVALID_POINTER;\n'
537 ' // This layer compatible with all GPUs\n'
538 ' *pOutLayerCount = 1;\n'
Chia-I Wua837c522014-12-16 10:47:33 +0800539 ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n'
Jon Ashburn451c16f2014-11-25 11:08:42 -0700540 ' return XGL_SUCCESS;\n'
541 ' }\n'
Jon Ashburn21001f62015-02-16 08:26:50 -0700542 '}' % (qual, decl, proto.params[0].name, layer_name, ret_val, c_call,f_open, log_func, f_close, stmt, layer_name))
Jon Ashburn451c16f2014-11-25 11:08:42 -0700543 elif proto.params[0].ty != "XGL_PHYSICAL_GPU":
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600544 funcs.append('%s%s\n'
545 '{\n'
546 ' %snextTable.%s;\n'
Tobin Ehlis574b0142014-11-12 13:11:15 -0700547 ' %s%s%s\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600548 '%s'
Tobin Ehlis574b0142014-11-12 13:11:15 -0700549 '}' % (qual, decl, ret_val, proto.c_call(), f_open, log_func, f_close, stmt))
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600550 else:
551 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
552 funcs.append('%s%s\n'
553 '{\n'
554 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
555 ' pCurObj = gpuw;\n'
Jon Ashburn21001f62015-02-16 08:26:50 -0700556 ' loader_platform_thread_once(&tabOnce, init%s);\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600557 ' %snextTable.%s;\n'
Tobin Ehlis574b0142014-11-12 13:11:15 -0700558 ' %s%s%s\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600559 '%s'
Jon Ashburn21001f62015-02-16 08:26:50 -0700560 '}' % (qual, decl, proto.params[0].name, layer_name, ret_val, c_call, f_open, log_func, f_close, stmt))
Ian Elliott81ac44c2015-01-13 17:52:38 -0700561 if 'WsiX11QueuePresent' == proto.name:
562 funcs.append("#endif")
Tobin Ehlis907a0522014-11-25 16:59:27 -0700563 elif "ObjectTracker" == layer:
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700564 obj_type_mapping = {base_t : base_t.replace("XGL_", "XGL_OBJECT_TYPE_") for base_t in xgl.object_type_list}
565 # For the various "super-types" we have to use function to distinguish sub type
566 for obj_type in ["XGL_BASE_OBJECT", "XGL_OBJECT", "XGL_DYNAMIC_STATE_OBJECT"]:
567 obj_type_mapping[obj_type] = "ll_get_obj_type(object)"
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700568
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600569 decl = proto.c_func(prefix="xgl", attr="XGLAPI")
570 param0_name = proto.params[0].name
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700571 p0_type = proto.params[0].ty.strip('*').strip('const ')
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600572 create_line = ''
573 destroy_line = ''
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700574 if 'DbgRegisterMsgCallback' in proto.name:
575 using_line = ' // This layer intercepts callbacks\n'
576 using_line += ' XGL_LAYER_DBG_FUNCTION_NODE *pNewDbgFuncNode = (XGL_LAYER_DBG_FUNCTION_NODE*)malloc(sizeof(XGL_LAYER_DBG_FUNCTION_NODE));\n'
577 using_line += ' if (!pNewDbgFuncNode)\n'
578 using_line += ' return XGL_ERROR_OUT_OF_MEMORY;\n'
579 using_line += ' pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;\n'
580 using_line += ' pNewDbgFuncNode->pUserData = pUserData;\n'
Jon Ashburn21001f62015-02-16 08:26:50 -0700581 using_line += ' pNewDbgFuncNode->pNext = g_pDbgFunctionHead;\n'
582 using_line += ' g_pDbgFunctionHead = pNewDbgFuncNode;\n'
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700583 elif 'DbgUnregisterMsgCallback' in proto.name:
Jon Ashburn21001f62015-02-16 08:26:50 -0700584 using_line = ' XGL_LAYER_DBG_FUNCTION_NODE *pTrav = g_pDbgFunctionHead;\n'
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700585 using_line += ' XGL_LAYER_DBG_FUNCTION_NODE *pPrev = pTrav;\n'
586 using_line += ' while (pTrav) {\n'
587 using_line += ' if (pTrav->pfnMsgCallback == pfnMsgCallback) {\n'
588 using_line += ' pPrev->pNext = pTrav->pNext;\n'
Jon Ashburn21001f62015-02-16 08:26:50 -0700589 using_line += ' if (g_pDbgFunctionHead == pTrav)\n'
590 using_line += ' g_pDbgFunctionHead = pTrav->pNext;\n'
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700591 using_line += ' free(pTrav);\n'
592 using_line += ' break;\n'
593 using_line += ' }\n'
594 using_line += ' pPrev = pTrav;\n'
595 using_line += ' pTrav = pTrav->pNext;\n'
596 using_line += ' }\n'
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700597 # Special cases for API funcs that don't use an object as first arg
598 elif True in [no_use_proto in proto.name for no_use_proto in ['GlobalOption', 'CreateInstance']]:
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600599 using_line = ''
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700600 else:
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600601 using_line = ' ll_increment_use_count((void*)%s, %s);\n' % (param0_name, obj_type_mapping[p0_type])
Tobin Ehlis235c20e2015-01-16 08:56:30 -0700602 if 'QueueSubmit' in proto.name:
603 using_line += ' set_status((void*)fence, XGL_OBJECT_TYPE_FENCE, OBJSTATUS_FENCE_IS_SUBMITTED);\n'
Mark Lobodzinski4186e712015-02-03 11:52:26 -0600604 using_line += ' validate_memory_mapping_status(pMemRefs, memRefCount);\n'
Mark Lobodzinskie1d3f0c2015-02-09 10:20:53 -0600605 using_line += ' validate_mem_ref_count(memRefCount);\n'
Tobin Ehlis235c20e2015-01-16 08:56:30 -0700606 elif 'GetFenceStatus' in proto.name:
607 using_line += ' // Warn if submitted_flag is not set\n'
Mark Lobodzinski4186e712015-02-03 11:52:26 -0600608 using_line += ' validate_status((void*)fence, XGL_OBJECT_TYPE_FENCE, OBJSTATUS_FENCE_IS_SUBMITTED, OBJSTATUS_FENCE_IS_SUBMITTED, XGL_DBG_MSG_ERROR, OBJTRACK_INVALID_FENCE, "Status Requested for Unsubmitted Fence");\n'
Mark Lobodzinski01552702015-02-03 10:06:31 -0600609 elif 'EndCommandBuffer' in proto.name:
610 using_line += ' reset_status((void*)cmdBuffer, XGL_OBJECT_TYPE_CMD_BUFFER, (OBJSTATUS_VIEWPORT_BOUND |\n'
611 using_line += ' OBJSTATUS_RASTER_BOUND |\n'
612 using_line += ' OBJSTATUS_COLOR_BLEND_BOUND |\n'
613 using_line += ' OBJSTATUS_DEPTH_STENCIL_BOUND));\n'
614 elif 'CmdBindDynamicStateObject' in proto.name:
615 using_line += ' track_object_status((void*)cmdBuffer, stateBindPoint);\n'
616 elif 'CmdDraw' in proto.name:
617 using_line += ' validate_draw_state_flags((void *)cmdBuffer);\n'
Mark Lobodzinski4186e712015-02-03 11:52:26 -0600618 elif 'MapMemory' in proto.name:
619 using_line += ' set_status((void*)mem, XGL_OBJECT_TYPE_GPU_MEMORY, OBJSTATUS_GPU_MEM_MAPPED);\n'
620 elif 'UnmapMemory' in proto.name:
621 using_line += ' reset_status((void*)mem, XGL_OBJECT_TYPE_GPU_MEMORY, OBJSTATUS_GPU_MEM_MAPPED);\n'
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700622 if 'AllocDescriptor' in proto.name: # Allocates array of DSs
Ian Elliotteac469b2015-02-04 12:15:12 -0700623 create_line = ' for (uint32_t i = 0; i < *pCount; i++) {\n'
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700624 create_line += ' ll_insert_obj((void*)pDescriptorSets[i], XGL_OBJECT_TYPE_DESCRIPTOR_SET);\n'
625 create_line += ' }\n'
626 elif 'Create' in proto.name or 'Alloc' in proto.name:
627 create_line = ' ll_insert_obj((void*)*%s, %s);\n' % (proto.params[-1].name, obj_type_mapping[proto.params[-1].ty.strip('*').strip('const ')])
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700628 if 'DestroyObject' in proto.name:
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600629 destroy_line = ' ll_destroy_obj((void*)%s);\n' % (param0_name)
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700630 using_line = ''
631 else:
632 if 'Destroy' in proto.name or 'Free' in proto.name:
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600633 destroy_line = ' ll_remove_obj_type((void*)%s, %s);\n' % (param0_name, obj_type_mapping[p0_type])
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700634 using_line = ''
635 if 'DestroyDevice' in proto.name:
636 destroy_line += ' // Report any remaining objects in LL\n objNode *pTrav = pGlobalHead;\n while (pTrav) {\n'
637 destroy_line += ' char str[1024];\n'
638 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'
639 destroy_line += ' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, device, 0, OBJTRACK_OBJECT_LEAK, "OBJTRACK", str);\n'
640 destroy_line += ' pTrav = pTrav->pNextGlobal;\n }\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600641 ret_val = ''
642 stmt = ''
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600643 if proto.ret != "void":
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600644 ret_val = "XGL_RESULT result = "
645 stmt = " return result;\n"
Ian Elliott81ac44c2015-01-13 17:52:38 -0700646 if 'WsiX11AssociateConnection' == proto.name:
647 funcs.append("#if !defined(_WIN32)")
Jon Ashburn451c16f2014-11-25 11:08:42 -0700648 if proto.name == "EnumerateLayers":
649 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
650 funcs.append('%s%s\n'
651 '{\n'
652 ' if (gpu != NULL) {\n'
653 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
654 ' %s'
655 ' pCurObj = gpuw;\n'
Jon Ashburn21001f62015-02-16 08:26:50 -0700656 ' loader_platform_thread_once(&tabOnce, init%s);\n'
Jon Ashburn451c16f2014-11-25 11:08:42 -0700657 ' %snextTable.%s;\n'
658 ' %s%s'
659 ' %s'
660 ' } else {\n'
661 ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n'
662 ' return XGL_ERROR_INVALID_POINTER;\n'
663 ' // This layer compatible with all GPUs\n'
664 ' *pOutLayerCount = 1;\n'
Chia-I Wua837c522014-12-16 10:47:33 +0800665 ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n'
Jon Ashburn451c16f2014-11-25 11:08:42 -0700666 ' return XGL_SUCCESS;\n'
667 ' }\n'
Jon Ashburn21001f62015-02-16 08:26:50 -0700668 '}' % (qual, decl, proto.params[0].name, using_line, layer_name, ret_val, c_call, create_line, destroy_line, stmt, layer_name))
Jon Ashburn451c16f2014-11-25 11:08:42 -0700669 elif proto.params[0].ty != "XGL_PHYSICAL_GPU":
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600670 funcs.append('%s%s\n'
671 '{\n'
672 '%s'
673 ' %snextTable.%s;\n'
674 '%s%s'
675 '%s'
676 '}' % (qual, decl, using_line, ret_val, proto.c_call(), create_line, destroy_line, stmt))
677 else:
678 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
Mark Lobodzinskie1d3f0c2015-02-09 10:20:53 -0600679 gpu_state = ''
680 if 'GetGpuInfo' in proto.name:
681 gpu_state = ' if (infoType == XGL_INFO_TYPE_PHYSICAL_GPU_PROPERTIES) {\n'
682 gpu_state += ' if (pData != NULL) {\n'
683 gpu_state += ' setGpuInfoState(pData);\n'
684 gpu_state += ' }\n'
685 gpu_state += ' }\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600686 funcs.append('%s%s\n'
687 '{\n'
688 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
689 '%s'
690 ' pCurObj = gpuw;\n'
Jon Ashburn21001f62015-02-16 08:26:50 -0700691 ' loader_platform_thread_once(&tabOnce, init%s);\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600692 ' %snextTable.%s;\n'
693 '%s%s'
694 '%s'
Mark Lobodzinskie1d3f0c2015-02-09 10:20:53 -0600695 '%s'
Jon Ashburn21001f62015-02-16 08:26:50 -0700696 '}' % (qual, decl, proto.params[0].name, using_line, layer_name, ret_val, c_call, create_line, destroy_line, gpu_state, stmt))
Ian Elliott81ac44c2015-01-13 17:52:38 -0700697 if 'WsiX11QueuePresent' == proto.name:
698 funcs.append("#endif")
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700699 elif "ParamChecker" == layer:
700 # TODO : Need to fix up the non-else cases below to do param checking as well
701 decl = proto.c_func(prefix="xgl", attr="XGLAPI")
702 param0_name = proto.params[0].name
703 ret_val = ''
704 stmt = ''
705 param_checks = []
706 # Add code to check enums and structs
707 # TODO : Currently only validating enum values, need to validate everything
708 str_decl = False
Tobin Ehlis773371f2014-12-18 13:51:21 -0700709 prev_count_name = ''
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700710 for p in proto.params:
711 if xgl_helper.is_type(p.ty.strip('*').strip('const '), 'enum'):
712 if not str_decl:
713 param_checks.append(' char str[1024];')
714 str_decl = True
715 param_checks.append(' if (!validate_%s(%s)) {' % (p.ty, p.name))
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700716 param_checks.append(' sprintf(str, "Parameter %s to function %s has invalid value of %%i.", (int)%s);' % (p.name, proto.name, p.name))
717 param_checks.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, 1, "PARAMCHECK", str);')
718 param_checks.append(' }')
719 elif xgl_helper.is_type(p.ty.strip('*').strip('const '), 'struct') and 'const' in p.ty:
Tobin Ehlis773371f2014-12-18 13:51:21 -0700720 is_array = False
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700721 if not str_decl:
722 param_checks.append(' char str[1024];')
723 str_decl = True
724 if '*' in p.ty: # First check for null ptr
Tobin Ehlis773371f2014-12-18 13:51:21 -0700725 # If this is an input array, parse over all of the array elements
726 if prev_count_name != '' and (prev_count_name.strip('Count')[1:] in p.name or 'slotCount' == prev_count_name):
727 #if 'pImageViews' in p.name:
728 is_array = True
729 param_checks.append(' uint32_t i;')
730 param_checks.append(' for (i = 0; i < %s; i++) {' % prev_count_name)
731 param_checks.append(' if (!xgl_validate_%s(&%s[i])) {' % (p.ty.strip('*').strip('const ').lower(), p.name))
732 param_checks.append(' sprintf(str, "Parameter %s[%%i] to function %s contains an invalid value.", i);' % (p.name, proto.name))
733 param_checks.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, 1, "PARAMCHECK", str);')
734 param_checks.append(' }')
735 param_checks.append(' }')
736 else:
737 param_checks.append(' if (!%s) {' % p.name)
738 param_checks.append(' sprintf(str, "Struct ptr parameter %s to function %s is NULL.");' % (p.name, proto.name))
739 param_checks.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, NULL, 0, 1, "PARAMCHECK", str);')
740 param_checks.append(' }')
741 param_checks.append(' else if (!xgl_validate_%s(%s)) {' % (p.ty.strip('*').strip('const ').lower(), p.name))
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700742 else:
743 param_checks.append(' if (!xgl_validate_%s(%s)) {' % (p.ty.strip('const ').lower(), p.name))
Tobin Ehlis773371f2014-12-18 13:51:21 -0700744 if not is_array:
745 param_checks.append(' sprintf(str, "Parameter %s to function %s contains an invalid value.");' % (p.name, proto.name))
746 param_checks.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, 1, "PARAMCHECK", str);')
747 param_checks.append(' }')
748 if p.name.endswith('Count'):
749 prev_count_name = p.name
750 else:
751 prev_count_name = ''
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600752 if proto.ret != "void":
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700753 ret_val = "XGL_RESULT result = "
754 stmt = " return result;\n"
Ian Elliott81ac44c2015-01-13 17:52:38 -0700755 if 'WsiX11AssociateConnection' == proto.name:
756 funcs.append("#if !defined(_WIN32)")
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700757 if proto.name == "EnumerateLayers":
758 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
759 funcs.append('%s%s\n'
760 '{\n'
761 ' char str[1024];\n'
762 ' if (gpu != NULL) {\n'
763 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
764 ' sprintf(str, "At start of layered %s\\n");\n'
765 ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpu, 0, 0, "PARAMCHECK", str);\n'
766 ' pCurObj = gpuw;\n'
Jon Ashburn21001f62015-02-16 08:26:50 -0700767 ' loader_platform_thread_once(&tabOnce, init%s);\n'
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700768 ' %snextTable.%s;\n'
769 ' sprintf(str, "Completed layered %s\\n");\n'
770 ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpu, 0, 0, "PARAMCHECK", str);\n'
771 ' fflush(stdout);\n'
772 ' %s'
773 ' } else {\n'
774 ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n'
775 ' return XGL_ERROR_INVALID_POINTER;\n'
776 ' // This layer compatible with all GPUs\n'
777 ' *pOutLayerCount = 1;\n'
778 ' strncpy(pOutLayers[0], "%s", maxStringSize);\n'
779 ' return XGL_SUCCESS;\n'
780 ' }\n'
Jon Ashburn21001f62015-02-16 08:26:50 -0700781 '}' % (qual, decl, proto.params[0].name, proto.name, layer_name, ret_val, c_call, proto.name, stmt, layer_name))
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700782 elif 'DbgRegisterMsgCallback' == proto.name:
783 funcs.append(self._gen_layer_dbg_callback_register())
784 elif 'DbgUnregisterMsgCallback' == proto.name:
785 funcs.append(self._gen_layer_dbg_callback_unregister())
786 elif proto.params[0].ty != "XGL_PHYSICAL_GPU":
787 funcs.append('%s%s\n'
788 '{\n'
789 '%s\n'
790 ' %snextTable.%s;\n'
791 '%s'
792 '}' % (qual, decl, "\n".join(param_checks), ret_val, proto.c_call(), stmt))
793 else:
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'
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700797 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700798 ' pCurObj = gpuw;\n'
Jon Ashburn21001f62015-02-16 08:26:50 -0700799 ' loader_platform_thread_once(&tabOnce, init%s);\n'
Tobin Ehlis9d139862014-12-18 08:44:01 -0700800 '%s\n'
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700801 ' %snextTable.%s;\n'
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700802 '%s'
Jon Ashburn21001f62015-02-16 08:26:50 -0700803 '}' % (qual, decl, proto.params[0].name, layer_name, "\n".join(param_checks), ret_val, c_call, stmt))
Ian Elliott81ac44c2015-01-13 17:52:38 -0700804 if 'WsiX11QueuePresent' == proto.name:
805 funcs.append("#endif")
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600806
807 return "\n\n".join(funcs)
808
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700809 def _generate_extensions(self):
810 exts = []
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600811 exts.append('uint64_t objTrackGetObjectCount(XGL_OBJECT_TYPE type)')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700812 exts.append('{')
813 exts.append(' return (type == XGL_OBJECT_TYPE_ANY) ? numTotalObjs : numObjs[type];')
814 exts.append('}')
815 exts.append('')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600816 exts.append('XGL_RESULT objTrackGetObjects(XGL_OBJECT_TYPE type, uint64_t objCount, OBJTRACK_NODE* pObjNodeArray)')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700817 exts.append('{')
818 exts.append(" // This bool flags if we're pulling all objs or just a single class of objs")
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600819 exts.append(' bool32_t bAllObjs = (type == XGL_OBJECT_TYPE_ANY);')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700820 exts.append(' // Check the count first thing')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600821 exts.append(' uint64_t maxObjCount = (bAllObjs) ? numTotalObjs : numObjs[type];')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700822 exts.append(' if (objCount > maxObjCount) {')
823 exts.append(' char str[1024];')
824 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));')
825 exts.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, 0, 0, OBJTRACK_OBJCOUNT_MAX_EXCEEDED, "OBJTRACK", str);')
826 exts.append(' return XGL_ERROR_INVALID_VALUE;')
827 exts.append(' }')
828 exts.append(' objNode* pTrav = (bAllObjs) ? pGlobalHead : pObjectHead[type];')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600829 exts.append(' for (uint64_t i = 0; i < objCount; i++) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700830 exts.append(' if (!pTrav) {')
831 exts.append(' char str[1024];')
832 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);')
833 exts.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, 0, 0, OBJTRACK_INTERNAL_ERROR, "OBJTRACK", str);')
834 exts.append(' return XGL_ERROR_UNKNOWN;')
835 exts.append(' }')
836 exts.append(' memcpy(&pObjNodeArray[i], pTrav, sizeof(OBJTRACK_NODE));')
837 exts.append(' pTrav = (bAllObjs) ? pTrav->pNextGlobal : pTrav->pNextObj;')
838 exts.append(' }')
839 exts.append(' return XGL_SUCCESS;')
840 exts.append('}')
841
842 return "\n".join(exts)
843
Jon Ashburn21001f62015-02-16 08:26:50 -0700844 def _generate_layer_gpa_function(self, layer, extensions=[]):
Chia-I Wu706533e2015-01-05 13:18:57 +0800845 func_body = ["#include \"xgl_generic_intercept_proc_helper.h\""]
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600846 func_body.append("XGL_LAYER_EXPORT void* XGLAPI xglGetProcAddr(XGL_PHYSICAL_GPU gpu, const char* funcName)\n"
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600847 "{\n"
848 " XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) gpu;\n"
Chia-I Wu706533e2015-01-05 13:18:57 +0800849 " void* addr;\n"
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600850 " if (gpu == NULL)\n"
851 " return NULL;\n"
852 " pCurObj = gpuw;\n"
Jon Ashburn21001f62015-02-16 08:26:50 -0700853 " loader_platform_thread_once(&tabOnce, init%s);\n\n"
Chia-I Wu706533e2015-01-05 13:18:57 +0800854 " addr = layer_intercept_proc(funcName);\n"
855 " if (addr)\n"
Jon Ashburn21001f62015-02-16 08:26:50 -0700856 " return addr;" % layer)
Chia-I Wu706533e2015-01-05 13:18:57 +0800857
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700858 if 0 != len(extensions):
859 for ext_name in extensions:
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800860 func_body.append(' else if (!strncmp("%s", funcName, sizeof("%s")))\n'
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700861 ' return %s;' % (ext_name, ext_name, ext_name))
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600862 func_body.append(" else {\n"
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600863 " if (gpuw->pGPA == NULL)\n"
864 " return NULL;\n"
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700865 " return gpuw->pGPA((XGL_PHYSICAL_GPU)gpuw->nextObject, funcName);\n"
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600866 " }\n"
867 "}\n")
868 return "\n".join(func_body)
869
Jon Ashburn21001f62015-02-16 08:26:50 -0700870 def _generate_layer_initialization(self, name, init_opts=False, prefix='xgl'):
Chia-I Wu0f65b1e2015-01-04 23:11:43 +0800871 func_body = ["#include \"xgl_dispatch_table_helper.h\""]
Jon Ashburn21001f62015-02-16 08:26:50 -0700872 func_body.append('static void init%s(void)\n'
873 '{\n' % name)
874 if init_opts:
875 func_body.append(' const char *strOpt;')
876 func_body.append(' // initialize %s options' % name)
877 func_body.append(' strOpt = getLayerOption("%sReportLevel");' % name)
878 func_body.append(' if (strOpt != NULL)')
879 func_body.append(' g_reportingLevel = atoi(strOpt);')
880 func_body.append('')
881 func_body.append(' strOpt = getLayerOption("%sDebugAction");' % name)
882 func_body.append(' if (strOpt != NULL)')
883 func_body.append(' g_debugAction = atoi(strOpt);')
884 func_body.append('')
885 func_body.append(' if (g_debugAction & XGL_DBG_LAYER_ACTION_LOG_MSG)')
886 func_body.append(' {')
887 func_body.append(' strOpt = getLayerOption("%sLogFilename");' % name)
888 func_body.append(' if (strOpt)')
889 func_body.append(' {')
890 func_body.append(' g_logFile = fopen(strOpt, "w");')
891 func_body.append(' }')
892 func_body.append(' if (g_logFile == NULL)')
893 func_body.append(' g_logFile = stdout;')
894 func_body.append(' }')
895 func_body.append('')
896 func_body.append(' xglGetProcAddrType fpNextGPA;\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600897 ' fpNextGPA = pCurObj->pGPA;\n'
Jon Ashburn21001f62015-02-16 08:26:50 -0700898 ' assert(fpNextGPA);\n')
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600899
Chia-I Wu0f65b1e2015-01-04 23:11:43 +0800900 func_body.append(" layer_initialize_dispatch_table(&nextTable, fpNextGPA, (XGL_PHYSICAL_GPU) pCurObj->nextObject);")
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600901 func_body.append("}\n")
902 return "\n".join(func_body)
903
Jon Ashburn21001f62015-02-16 08:26:50 -0700904 def _generate_layer_initialization_with_lock(self, layer, prefix='xgl'):
Ian Elliott81ac44c2015-01-13 17:52:38 -0700905 func_body = ["#include \"xgl_dispatch_table_helper.h\""]
Jon Ashburn21001f62015-02-16 08:26:50 -0700906 func_body.append('static void init%s(void)\n'
Ian Elliott81ac44c2015-01-13 17:52:38 -0700907 '{\n'
908 ' xglGetProcAddrType fpNextGPA;\n'
909 ' fpNextGPA = pCurObj->pGPA;\n'
Jon Ashburn21001f62015-02-16 08:26:50 -0700910 ' assert(fpNextGPA);\n' % layer);
Ian Elliott81ac44c2015-01-13 17:52:38 -0700911
912 func_body.append(" layer_initialize_dispatch_table(&nextTable, fpNextGPA, (XGL_PHYSICAL_GPU) pCurObj->nextObject);\n")
913 func_body.append(" if (!printLockInitialized)")
914 func_body.append(" {")
915 func_body.append(" // TODO/TBD: Need to delete this mutex sometime. How???")
916 func_body.append(" loader_platform_thread_create_mutex(&printLock);")
917 func_body.append(" printLockInitialized = 1;")
918 func_body.append(" }")
919 func_body.append("}\n")
920 return "\n".join(func_body)
921
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600922class LayerFuncsSubcommand(Subcommand):
923 def generate_header(self):
924 return '#include <xglLayer.h>\n#include "loader.h"'
925
926 def generate_body(self):
927 return self._generate_dispatch_entrypoints("static", True)
928
929class LayerDispatchSubcommand(Subcommand):
930 def generate_header(self):
931 return '#include "layer_wrappers.h"'
932
933 def generate_body(self):
Jon Ashburn21001f62015-02-16 08:26:50 -0700934 return self._generate_layer_initialization()
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600935
936class GenericLayerSubcommand(Subcommand):
937 def generate_header(self):
Jon Ashburn7a2da4f2015-02-17 11:03:12 -0700938 return '#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include "loader_platform.h"\n#include "xglLayer.h"\n//The following is #included again to catch certain OS-specific functions being used:\n#include "loader_platform.h"\n\n#include "layers_config.h"\n#include "layers_msg.h"\n\nstatic XGL_LAYER_DISPATCH_TABLE nextTable;\nstatic XGL_BASE_LAYER_OBJECT *pCurObj;\n\nstatic LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600939
940 def generate_body(self):
Jon Ashburn21001f62015-02-16 08:26:50 -0700941 body = [self._generate_layer_initialization("Generic", True),
Tobin Ehlis907a0522014-11-25 16:59:27 -0700942 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "Generic"),
Jon Ashburn21001f62015-02-16 08:26:50 -0700943 self._generate_layer_gpa_function("Generic")]
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600944
945 return "\n\n".join(body)
946
947class ApiDumpSubcommand(Subcommand):
948 def generate_header(self):
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700949 header_txt = []
Ian Elliott81ac44c2015-01-13 17:52:38 -0700950 header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>')
951 header_txt.append('#include "loader_platform.h"')
952 header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper.h"\n')
Ian Elliott20f06872015-02-12 17:08:34 -0700953 header_txt.append('// The following is #included again to catch certain OS-specific functions being used:')
954 header_txt.append('#include "loader_platform.h"')
Ian Elliott81ac44c2015-01-13 17:52:38 -0700955 header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;')
956 header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n')
957 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
958 header_txt.append('static int printLockInitialized = 0;')
959 header_txt.append('static loader_platform_thread_mutex printLock;\n')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700960 header_txt.append('#define MAX_TID 513')
Ian Elliott81ac44c2015-01-13 17:52:38 -0700961 header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700962 header_txt.append('static uint32_t maxTID = 0;')
963 header_txt.append('// Map actual TID to an index value and return that index')
964 header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs')
965 header_txt.append('static uint32_t getTIDIndex() {')
Ian Elliott81ac44c2015-01-13 17:52:38 -0700966 header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700967 header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {')
968 header_txt.append(' if (tid == tidMapping[i])')
969 header_txt.append(' return i;')
970 header_txt.append(' }')
971 header_txt.append(" // Don't yet have mapping, set it and return newly set index")
Ian Elliott81ac44c2015-01-13 17:52:38 -0700972 header_txt.append(' uint32_t retVal = (uint32_t) maxTID;')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700973 header_txt.append(' tidMapping[maxTID++] = tid;')
974 header_txt.append(' assert(maxTID < MAX_TID);')
975 header_txt.append(' return retVal;')
976 header_txt.append('}')
977 return "\n".join(header_txt)
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600978
979 def generate_body(self):
Jon Ashburn21001f62015-02-16 08:26:50 -0700980 body = [self._generate_layer_initialization_with_lock("APIDump"),
Tobin Ehlis907a0522014-11-25 16:59:27 -0700981 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDump"),
Jon Ashburn21001f62015-02-16 08:26:50 -0700982 self._generate_layer_gpa_function("APIDump")]
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600983
984 return "\n\n".join(body)
985
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700986class ApiDumpCppSubcommand(Subcommand):
987 def generate_header(self):
988 header_txt = []
Ian Elliott81ac44c2015-01-13 17:52:38 -0700989 header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>')
990 header_txt.append('#include "loader_platform.h"')
991 header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper_cpp.h"\n')
Ian Elliott20f06872015-02-12 17:08:34 -0700992 header_txt.append('// The following is #included again to catch certain OS-specific functions being used:')
993 header_txt.append('#include "loader_platform.h"')
Ian Elliott81ac44c2015-01-13 17:52:38 -0700994 header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;')
995 header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n')
996 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
997 header_txt.append('static int printLockInitialized = 0;')
998 header_txt.append('static loader_platform_thread_mutex printLock;\n')
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700999 header_txt.append('#define MAX_TID 513')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001000 header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};')
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001001 header_txt.append('static uint32_t maxTID = 0;')
1002 header_txt.append('// Map actual TID to an index value and return that index')
1003 header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs')
1004 header_txt.append('static uint32_t getTIDIndex() {')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001005 header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();')
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001006 header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {')
1007 header_txt.append(' if (tid == tidMapping[i])')
1008 header_txt.append(' return i;')
1009 header_txt.append(' }')
1010 header_txt.append(" // Don't yet have mapping, set it and return newly set index")
Ian Elliott81ac44c2015-01-13 17:52:38 -07001011 header_txt.append(' uint32_t retVal = (uint32_t) maxTID;')
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001012 header_txt.append(' tidMapping[maxTID++] = tid;')
1013 header_txt.append(' assert(maxTID < MAX_TID);')
1014 header_txt.append(' return retVal;')
1015 header_txt.append('}')
1016 return "\n".join(header_txt)
1017
1018 def generate_body(self):
Jon Ashburn21001f62015-02-16 08:26:50 -07001019 body = [self._generate_layer_initialization_with_lock("APIDumpCpp"),
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001020 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDumpCpp"),
Jon Ashburn21001f62015-02-16 08:26:50 -07001021 self._generate_layer_gpa_function("APIDumpCpp")]
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001022
1023 return "\n\n".join(body)
1024
Tobin Ehlis574b0142014-11-12 13:11:15 -07001025class ApiDumpFileSubcommand(Subcommand):
1026 def generate_header(self):
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -07001027 header_txt = []
Ian Elliott81ac44c2015-01-13 17:52:38 -07001028 header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>')
1029 header_txt.append('#include "loader_platform.h"')
1030 header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper.h"\n')
Ian Elliott20f06872015-02-12 17:08:34 -07001031 header_txt.append('// The following is #included again to catch certain OS-specific functions being used:')
1032 header_txt.append('#include "loader_platform.h"')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001033 header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;')
1034 header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n')
1035 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
1036 header_txt.append('static int printLockInitialized = 0;')
1037 header_txt.append('static loader_platform_thread_mutex printLock;\n')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -07001038 header_txt.append('#define MAX_TID 513')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001039 header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -07001040 header_txt.append('static uint32_t maxTID = 0;')
1041 header_txt.append('// Map actual TID to an index value and return that index')
1042 header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs')
1043 header_txt.append('static uint32_t getTIDIndex() {')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001044 header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -07001045 header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {')
1046 header_txt.append(' if (tid == tidMapping[i])')
1047 header_txt.append(' return i;')
1048 header_txt.append(' }')
1049 header_txt.append(" // Don't yet have mapping, set it and return newly set index")
Ian Elliott81ac44c2015-01-13 17:52:38 -07001050 header_txt.append(' uint32_t retVal = (uint32_t) maxTID;')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -07001051 header_txt.append(' tidMapping[maxTID++] = tid;')
1052 header_txt.append(' assert(maxTID < MAX_TID);')
1053 header_txt.append(' return retVal;')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001054 header_txt.append('}\n')
1055 header_txt.append('static FILE* pOutFile;\nstatic char* outFileName = "xgl_apidump.txt";')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -07001056 return "\n".join(header_txt)
Tobin Ehlis574b0142014-11-12 13:11:15 -07001057
1058 def generate_body(self):
Jon Ashburn21001f62015-02-16 08:26:50 -07001059 body = [self._generate_layer_initialization_with_lock("APIDumpFile"),
Tobin Ehlis907a0522014-11-25 16:59:27 -07001060 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDumpFile"),
Jon Ashburn21001f62015-02-16 08:26:50 -07001061 self._generate_layer_gpa_function("APIDumpFile")]
Tobin Ehlis574b0142014-11-12 13:11:15 -07001062
1063 return "\n\n".join(body)
1064
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -07001065class ApiDumpNoAddrSubcommand(Subcommand):
1066 def generate_header(self):
1067 header_txt = []
Ian Elliott81ac44c2015-01-13 17:52:38 -07001068 header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>')
1069 header_txt.append('#include "loader_platform.h"')
1070 header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper_no_addr.h"\n')
Ian Elliott20f06872015-02-12 17:08:34 -07001071 header_txt.append('// The following is #included again to catch certain OS-specific functions being used:')
1072 header_txt.append('#include "loader_platform.h"')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001073 header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;')
1074 header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n')
1075 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
1076 header_txt.append('static int printLockInitialized = 0;')
1077 header_txt.append('static loader_platform_thread_mutex printLock;\n')
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -07001078 header_txt.append('#define MAX_TID 513')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001079 header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};')
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -07001080 header_txt.append('static uint32_t maxTID = 0;')
1081 header_txt.append('// Map actual TID to an index value and return that index')
1082 header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs')
1083 header_txt.append('static uint32_t getTIDIndex() {')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001084 header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();')
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -07001085 header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {')
1086 header_txt.append(' if (tid == tidMapping[i])')
1087 header_txt.append(' return i;')
1088 header_txt.append(' }')
1089 header_txt.append(" // Don't yet have mapping, set it and return newly set index")
Ian Elliott81ac44c2015-01-13 17:52:38 -07001090 header_txt.append(' uint32_t retVal = (uint32_t) maxTID;')
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -07001091 header_txt.append(' tidMapping[maxTID++] = tid;')
1092 header_txt.append(' assert(maxTID < MAX_TID);')
1093 header_txt.append(' return retVal;')
1094 header_txt.append('}')
1095 return "\n".join(header_txt)
1096
1097 def generate_body(self):
Jon Ashburn21001f62015-02-16 08:26:50 -07001098 body = [self._generate_layer_initialization_with_lock("APIDumpNoAddr"),
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -07001099 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDump", True),
Jon Ashburn21001f62015-02-16 08:26:50 -07001100 self._generate_layer_gpa_function("APIDumpNoAddr")]
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -07001101
1102 return "\n\n".join(body)
1103
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001104class ApiDumpNoAddrCppSubcommand(Subcommand):
1105 def generate_header(self):
1106 header_txt = []
Ian Elliott81ac44c2015-01-13 17:52:38 -07001107 header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>')
1108 header_txt.append('#include "loader_platform.h"')
1109 header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper_no_addr_cpp.h"\n')
Ian Elliott20f06872015-02-12 17:08:34 -07001110 header_txt.append('// The following is #included again to catch certain OS-specific functions being used:')
1111 header_txt.append('#include "loader_platform.h"')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001112 header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;')
1113 header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n')
1114 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
1115 header_txt.append('static int printLockInitialized = 0;')
1116 header_txt.append('static loader_platform_thread_mutex printLock;\n')
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001117 header_txt.append('#define MAX_TID 513')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001118 header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};')
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001119 header_txt.append('static uint32_t maxTID = 0;')
1120 header_txt.append('// Map actual TID to an index value and return that index')
1121 header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs')
1122 header_txt.append('static uint32_t getTIDIndex() {')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001123 header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();')
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001124 header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {')
1125 header_txt.append(' if (tid == tidMapping[i])')
1126 header_txt.append(' return i;')
1127 header_txt.append(' }')
1128 header_txt.append(" // Don't yet have mapping, set it and return newly set index")
Ian Elliott81ac44c2015-01-13 17:52:38 -07001129 header_txt.append(' uint32_t retVal = (uint32_t) maxTID;')
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001130 header_txt.append(' tidMapping[maxTID++] = tid;')
1131 header_txt.append(' assert(maxTID < MAX_TID);')
1132 header_txt.append(' return retVal;')
1133 header_txt.append('}')
1134 return "\n".join(header_txt)
1135
1136 def generate_body(self):
Jon Ashburn21001f62015-02-16 08:26:50 -07001137 body = [self._generate_layer_initialization_with_lock("APIDumpNoAddrCpp"),
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001138 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDumpCpp", True),
Jon Ashburn21001f62015-02-16 08:26:50 -07001139 self._generate_layer_gpa_function("APIDumpNoAddrCpp")]
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001140
1141 return "\n\n".join(body)
1142
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001143class ObjectTrackerSubcommand(Subcommand):
1144 def generate_header(self):
1145 header_txt = []
Ian Elliott81ac44c2015-01-13 17:52:38 -07001146 header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include "loader_platform.h"')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001147 header_txt.append('#include "object_track.h"\n\nstatic XGL_LAYER_DISPATCH_TABLE nextTable;\nstatic XGL_BASE_LAYER_OBJECT *pCurObj;')
Ian Elliott20f06872015-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"')
Jon Ashburn7a2da4f2015-02-17 11:03:12 -07001150 header_txt.append('#include "layers_config.h"')
Jon Ashburn21001f62015-02-16 08:26:50 -07001151 header_txt.append('#include "layers_msg.h"')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001152 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
1153 header_txt.append('static long long unsigned int object_track_index = 0;')
Jon Ashburn21001f62015-02-16 08:26:50 -07001154 header_txt.append('')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001155 header_txt.append('// We maintain a "Global" list which links every object and a')
1156 header_txt.append('// per-Object list which just links objects of a given type')
1157 header_txt.append('// The object node has both pointers so the actual nodes are shared between the two lists')
1158 header_txt.append('typedef struct _objNode {')
1159 header_txt.append(' OBJTRACK_NODE obj;')
1160 header_txt.append(' struct _objNode *pNextObj;')
1161 header_txt.append(' struct _objNode *pNextGlobal;')
1162 header_txt.append('} objNode;')
1163 header_txt.append('static objNode *pObjectHead[XGL_NUM_OBJECT_TYPE] = {0};')
1164 header_txt.append('static objNode *pGlobalHead = NULL;')
1165 header_txt.append('static uint64_t numObjs[XGL_NUM_OBJECT_TYPE] = {0};')
1166 header_txt.append('static uint64_t numTotalObjs = 0;')
Mark Lobodzinskie1d3f0c2015-02-09 10:20:53 -06001167 header_txt.append('static uint32_t maxMemRefsPerSubmission = 0;')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001168 header_txt.append('// Debug function to print global list and each individual object list')
1169 header_txt.append('static void ll_print_lists()')
1170 header_txt.append('{')
1171 header_txt.append(' objNode* pTrav = pGlobalHead;')
1172 header_txt.append(' printf("=====GLOBAL OBJECT LIST (%lu total objs):\\n", numTotalObjs);')
1173 header_txt.append(' while (pTrav) {')
1174 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);')
1175 header_txt.append(' pTrav = pTrav->pNextGlobal;')
1176 header_txt.append(' }')
1177 header_txt.append(' for (uint32_t i = 0; i < XGL_NUM_OBJECT_TYPE; i++) {')
1178 header_txt.append(' pTrav = pObjectHead[i];')
1179 header_txt.append(' if (pTrav) {')
1180 header_txt.append(' printf("=====%s OBJECT LIST (%lu objs):\\n", string_XGL_OBJECT_TYPE(pTrav->obj.objType), numObjs[i]);')
1181 header_txt.append(' while (pTrav) {')
1182 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);')
1183 header_txt.append(' pTrav = pTrav->pNextObj;')
1184 header_txt.append(' }')
1185 header_txt.append(' }')
1186 header_txt.append(' }')
1187 header_txt.append('}')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001188 header_txt.append('static void ll_insert_obj(void* pObj, XGL_OBJECT_TYPE objType) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001189 header_txt.append(' char str[1024];')
1190 header_txt.append(' sprintf(str, "OBJ[%llu] : CREATE %s object %p", object_track_index++, string_XGL_OBJECT_TYPE(objType), (void*)pObj);')
1191 header_txt.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_NONE, "OBJTRACK", str);')
1192 header_txt.append(' objNode* pNewObjNode = (objNode*)malloc(sizeof(objNode));')
1193 header_txt.append(' pNewObjNode->obj.pObj = pObj;')
1194 header_txt.append(' pNewObjNode->obj.objType = objType;')
Mark Lobodzinski01552702015-02-03 10:06:31 -06001195 header_txt.append(' pNewObjNode->obj.status = OBJSTATUS_NONE;')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001196 header_txt.append(' pNewObjNode->obj.numUses = 0;')
1197 header_txt.append(' // insert at front of global list')
1198 header_txt.append(' pNewObjNode->pNextGlobal = pGlobalHead;')
1199 header_txt.append(' pGlobalHead = pNewObjNode;')
1200 header_txt.append(' // insert at front of object list')
1201 header_txt.append(' pNewObjNode->pNextObj = pObjectHead[objType];')
1202 header_txt.append(' pObjectHead[objType] = pNewObjNode;')
1203 header_txt.append(' // increment obj counts')
1204 header_txt.append(' numObjs[objType]++;')
1205 header_txt.append(' numTotalObjs++;')
1206 header_txt.append(' //sprintf(str, "OBJ_STAT : %lu total objs & %lu %s objs.", numTotalObjs, numObjs[objType], string_XGL_OBJECT_TYPE(objType));')
Chia-I Wudf142a32014-12-16 11:02:06 +08001207 header_txt.append(' if (0) ll_print_lists();')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001208 header_txt.append('}')
1209 header_txt.append('// Traverse global list and return type for given object')
1210 header_txt.append('static XGL_OBJECT_TYPE ll_get_obj_type(XGL_OBJECT object) {')
1211 header_txt.append(' objNode *pTrav = pGlobalHead;')
1212 header_txt.append(' while (pTrav) {')
1213 header_txt.append(' if (pTrav->obj.pObj == object)')
1214 header_txt.append(' return pTrav->obj.objType;')
1215 header_txt.append(' pTrav = pTrav->pNextGlobal;')
1216 header_txt.append(' }')
1217 header_txt.append(' char str[1024];')
1218 header_txt.append(' sprintf(str, "Attempting look-up on obj %p but it is NOT in the global list!", (void*)object);')
1219 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, object, 0, OBJTRACK_MISSING_OBJECT, "OBJTRACK", str);')
1220 header_txt.append(' return XGL_OBJECT_TYPE_UNKNOWN;')
1221 header_txt.append('}')
Chia-I Wudf142a32014-12-16 11:02:06 +08001222 header_txt.append('#if 0')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001223 header_txt.append('static uint64_t ll_get_obj_uses(void* pObj, XGL_OBJECT_TYPE objType) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001224 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
1225 header_txt.append(' while (pTrav) {')
1226 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1227 header_txt.append(' return pTrav->obj.numUses;')
1228 header_txt.append(' }')
1229 header_txt.append(' pTrav = pTrav->pNextObj;')
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001230 header_txt.append(' }')
1231 header_txt.append(' return 0;')
1232 header_txt.append('}')
Chia-I Wudf142a32014-12-16 11:02:06 +08001233 header_txt.append('#endif')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001234 header_txt.append('static void ll_increment_use_count(void* pObj, XGL_OBJECT_TYPE objType) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001235 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001236 header_txt.append(' while (pTrav) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001237 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1238 header_txt.append(' pTrav->obj.numUses++;')
1239 header_txt.append(' char str[1024];')
1240 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);')
1241 header_txt.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_NONE, "OBJTRACK", str);')
1242 header_txt.append(' return;')
1243 header_txt.append(' }')
1244 header_txt.append(' pTrav = pTrav->pNextObj;')
1245 header_txt.append(' }')
1246 header_txt.append(' // If we do not find obj, insert it and then increment count')
1247 header_txt.append(' char str[1024];')
1248 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));')
1249 header_txt.append(' layerCbMsg(XGL_DBG_MSG_WARNING, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
1250 header_txt.append('')
1251 header_txt.append(' ll_insert_obj(pObj, objType);')
1252 header_txt.append(' ll_increment_use_count(pObj, objType);')
1253 header_txt.append('}')
1254 header_txt.append('// We usually do not know Obj type when we destroy it so have to fetch')
1255 header_txt.append('// Type from global list w/ ll_destroy_obj()')
1256 header_txt.append('// and then do the full removal from both lists w/ ll_remove_obj_type()')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001257 header_txt.append('static void ll_remove_obj_type(void* pObj, XGL_OBJECT_TYPE objType) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001258 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
1259 header_txt.append(' objNode *pPrev = pObjectHead[objType];')
1260 header_txt.append(' while (pTrav) {')
1261 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1262 header_txt.append(' pPrev->pNextObj = pTrav->pNextObj;')
1263 header_txt.append(' // update HEAD of Obj list as needed')
1264 header_txt.append(' if (pObjectHead[objType] == pTrav)')
1265 header_txt.append(' pObjectHead[objType] = pTrav->pNextObj;')
1266 header_txt.append(' assert(numObjs[objType] > 0);')
1267 header_txt.append(' numObjs[objType]--;')
1268 header_txt.append(' char str[1024];')
1269 header_txt.append(' sprintf(str, "OBJ[%llu] : DESTROY %s object %p", object_track_index++, string_XGL_OBJECT_TYPE(objType), (void*)pObj);')
1270 header_txt.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_NONE, "OBJTRACK", str);')
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001271 header_txt.append(' return;')
1272 header_txt.append(' }')
1273 header_txt.append(' pPrev = pTrav;')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001274 header_txt.append(' pTrav = pTrav->pNextObj;')
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001275 header_txt.append(' }')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001276 header_txt.append(' char str[1024];')
1277 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));')
1278 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_INTERNAL_ERROR, "OBJTRACK", str);')
1279 header_txt.append('}')
1280 header_txt.append('// Parse global list to find obj type, then remove obj from obj type list, finally')
1281 header_txt.append('// remove obj from global list')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001282 header_txt.append('static void ll_destroy_obj(void* pObj) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001283 header_txt.append(' objNode *pTrav = pGlobalHead;')
1284 header_txt.append(' objNode *pPrev = pGlobalHead;')
1285 header_txt.append(' while (pTrav) {')
1286 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1287 header_txt.append(' ll_remove_obj_type(pObj, pTrav->obj.objType);')
1288 header_txt.append(' pPrev->pNextGlobal = pTrav->pNextGlobal;')
1289 header_txt.append(' // update HEAD of global list if needed')
1290 header_txt.append(' if (pGlobalHead == pTrav)')
1291 header_txt.append(' pGlobalHead = pTrav->pNextGlobal;')
1292 header_txt.append(' free(pTrav);')
1293 header_txt.append(' assert(numTotalObjs > 0);')
1294 header_txt.append(' numTotalObjs--;')
1295 header_txt.append(' char str[1024];')
1296 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));')
1297 header_txt.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_NONE, "OBJTRACK", str);')
1298 header_txt.append(' return;')
1299 header_txt.append(' }')
1300 header_txt.append(' pPrev = pTrav;')
1301 header_txt.append(' pTrav = pTrav->pNextGlobal;')
1302 header_txt.append(' }')
1303 header_txt.append(' char str[1024];')
1304 header_txt.append(' sprintf(str, "Unable to remove obj %p. Was it created? Has it already been destroyed?", pObj);')
1305 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_DESTROY_OBJECT_FAILED, "OBJTRACK", str);')
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001306 header_txt.append('}')
Tobin Ehlis235c20e2015-01-16 08:56:30 -07001307 header_txt.append('// Set selected flag state for an object node')
1308 header_txt.append('static void set_status(void* pObj, XGL_OBJECT_TYPE objType, OBJECT_STATUS status_flag) {')
Mark Lobodzinskid11fcca2015-02-09 10:16:20 -06001309 header_txt.append(' if (pObj != NULL) {')
1310 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
1311 header_txt.append(' while (pTrav) {')
1312 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1313 header_txt.append(' pTrav->obj.status |= status_flag;')
1314 header_txt.append(' return;')
1315 header_txt.append(' }')
1316 header_txt.append(' pTrav = pTrav->pNextObj;')
Tobin Ehlis235c20e2015-01-16 08:56:30 -07001317 header_txt.append(' }')
Mark Lobodzinskid11fcca2015-02-09 10:16:20 -06001318 header_txt.append(' // If we do not find it print an error')
1319 header_txt.append(' char str[1024];')
1320 header_txt.append(' sprintf(str, "Unable to set status for non-existent object %p of %s type", pObj, string_XGL_OBJECT_TYPE(objType));')
1321 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
1322 header_txt.append(' }');
Tobin Ehlis235c20e2015-01-16 08:56:30 -07001323 header_txt.append('}')
1324 header_txt.append('')
Mark Lobodzinski01552702015-02-03 10:06:31 -06001325 header_txt.append('// Track selected state for an object node')
1326 header_txt.append('static void track_object_status(void* pObj, XGL_STATE_BIND_POINT stateBindPoint) {')
1327 header_txt.append(' objNode *pTrav = pObjectHead[XGL_OBJECT_TYPE_CMD_BUFFER];')
1328 header_txt.append('')
1329 header_txt.append(' while (pTrav) {')
1330 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1331 header_txt.append(' if (stateBindPoint == XGL_STATE_BIND_VIEWPORT) {')
1332 header_txt.append(' pTrav->obj.status |= OBJSTATUS_VIEWPORT_BOUND;')
1333 header_txt.append(' } else if (stateBindPoint == XGL_STATE_BIND_RASTER) {')
1334 header_txt.append(' pTrav->obj.status |= OBJSTATUS_RASTER_BOUND;')
1335 header_txt.append(' } else if (stateBindPoint == XGL_STATE_BIND_COLOR_BLEND) {')
1336 header_txt.append(' pTrav->obj.status |= OBJSTATUS_COLOR_BLEND_BOUND;')
1337 header_txt.append(' } else if (stateBindPoint == XGL_STATE_BIND_DEPTH_STENCIL) {')
1338 header_txt.append(' pTrav->obj.status |= OBJSTATUS_DEPTH_STENCIL_BOUND;')
1339 header_txt.append(' }')
1340 header_txt.append(' return;')
1341 header_txt.append(' }')
1342 header_txt.append(' pTrav = pTrav->pNextObj;')
1343 header_txt.append(' }')
1344 header_txt.append(' // If we do not find it print an error')
1345 header_txt.append(' char str[1024];')
1346 header_txt.append(' sprintf(str, "Unable to track status for non-existent Command Buffer object %p", pObj);')
1347 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
1348 header_txt.append('}')
1349 header_txt.append('')
1350 header_txt.append('// Reset selected flag state for an object node')
1351 header_txt.append('static void reset_status(void* pObj, XGL_OBJECT_TYPE objType, OBJECT_STATUS status_flag) {')
Tobin Ehlis235c20e2015-01-16 08:56:30 -07001352 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
1353 header_txt.append(' while (pTrav) {')
1354 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
Mark Lobodzinski01552702015-02-03 10:06:31 -06001355 header_txt.append(' pTrav->obj.status &= ~status_flag;')
1356 header_txt.append(' return;')
1357 header_txt.append(' }')
1358 header_txt.append(' pTrav = pTrav->pNextObj;')
1359 header_txt.append(' }')
1360 header_txt.append(' // If we do not find it print an error')
1361 header_txt.append(' char str[1024];')
1362 header_txt.append(' sprintf(str, "Unable to reset status for non-existent object %p of %s type", pObj, string_XGL_OBJECT_TYPE(objType));')
1363 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
1364 header_txt.append('}')
1365 header_txt.append('')
1366 header_txt.append('// Check object status for selected flag state')
Mark Lobodzinski4186e712015-02-03 11:52:26 -06001367 header_txt.append('static void validate_status(void* pObj, XGL_OBJECT_TYPE objType, OBJECT_STATUS status_mask, OBJECT_STATUS status_flag, XGL_DBG_MSG_TYPE error_level, OBJECT_TRACK_ERROR error_code, char* fail_msg) {')
Mark Lobodzinski01552702015-02-03 10:06:31 -06001368 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
1369 header_txt.append(' while (pTrav) {')
1370 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
Mark Lobodzinski4186e712015-02-03 11:52:26 -06001371 header_txt.append(' if ((pTrav->obj.status & status_mask) != status_flag) {')
Tobin Ehlis235c20e2015-01-16 08:56:30 -07001372 header_txt.append(' char str[1024];')
1373 header_txt.append(' sprintf(str, "OBJECT VALIDATION WARNING: %s object %p: %s", string_XGL_OBJECT_TYPE(objType), (void*)pObj, fail_msg);')
Mark Lobodzinski01552702015-02-03 10:06:31 -06001374 header_txt.append(' layerCbMsg(error_level, XGL_VALIDATION_LEVEL_0, pObj, 0, error_code, "OBJTRACK", str);')
Tobin Ehlis235c20e2015-01-16 08:56:30 -07001375 header_txt.append(' }')
1376 header_txt.append(' return;')
1377 header_txt.append(' }')
1378 header_txt.append(' pTrav = pTrav->pNextObj;')
1379 header_txt.append(' }')
1380 header_txt.append(' // If we do not find it print an error')
1381 header_txt.append(' char str[1024];')
1382 header_txt.append(' sprintf(str, "Unable to obtain status for non-existent object %p of %s type", pObj, string_XGL_OBJECT_TYPE(objType));')
1383 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
1384 header_txt.append('}')
Mark Lobodzinski01552702015-02-03 10:06:31 -06001385 header_txt.append('')
1386 header_txt.append('static void validate_draw_state_flags(void* pObj) {')
Mark Lobodzinski4186e712015-02-03 11:52:26 -06001387 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");')
1388 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");')
1389 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");')
1390 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");')
1391 header_txt.append('}')
1392 header_txt.append('')
1393 header_txt.append('static void validate_memory_mapping_status(const XGL_MEMORY_REF* pMemRefs, uint32_t numRefs) {')
Ian Elliotteac469b2015-02-04 12:15:12 -07001394 header_txt.append(' uint32_t i;')
Mark Lobodzinski4186e712015-02-03 11:52:26 -06001395 header_txt.append(' for (i = 0; i < numRefs; i++) {')
1396 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");')
1397 header_txt.append(' }')
Mark Lobodzinski01552702015-02-03 10:06:31 -06001398 header_txt.append('}')
Mark Lobodzinskie1d3f0c2015-02-09 10:20:53 -06001399 header_txt.append('')
1400 header_txt.append('static void validate_mem_ref_count(uint32_t numRefs) {')
1401 header_txt.append(' if (maxMemRefsPerSubmission == 0) {')
1402 header_txt.append(' char str[1024];')
1403 header_txt.append(' sprintf(str, "xglQueueSubmit called before calling xglGetGpuInfo");')
1404 header_txt.append(' layerCbMsg(XGL_DBG_MSG_WARNING, XGL_VALIDATION_LEVEL_0, NULL, 0, OBJTRACK_GETGPUINFO_NOT_CALLED, "OBJTRACK", str);')
1405 header_txt.append(' } else {')
1406 header_txt.append(' if (numRefs > maxMemRefsPerSubmission) {')
1407 header_txt.append(' char str[1024];')
1408 header_txt.append(' sprintf(str, "xglQueueSubmit Memory reference count (%d) exceeds allowable GPU limit (%d)", numRefs, maxMemRefsPerSubmission);')
1409 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, OBJTRACK_MEMREFCOUNT_MAX_EXCEEDED, "OBJTRACK", str);')
1410 header_txt.append(' }')
1411 header_txt.append(' }')
1412 header_txt.append('}')
1413 header_txt.append('')
1414 header_txt.append('static void setGpuInfoState(void *pData) {')
1415 header_txt.append(' maxMemRefsPerSubmission = ((XGL_PHYSICAL_GPU_PROPERTIES *)pData)->maxMemRefsPerSubmission;')
1416 header_txt.append('}')
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001417 return "\n".join(header_txt)
1418
1419 def generate_body(self):
Jon Ashburn21001f62015-02-16 08:26:50 -07001420 body = [self._generate_layer_initialization("ObjectTracker", True),
Tobin Ehlis907a0522014-11-25 16:59:27 -07001421 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "ObjectTracker"),
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001422 self._generate_extensions(),
Jon Ashburn21001f62015-02-16 08:26:50 -07001423 self._generate_layer_gpa_function("ObjectTracker", extensions=['objTrackGetObjectCount', 'objTrackGetObjects'])]
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001424
1425 return "\n\n".join(body)
Courtney Goeltzenleuchtere6094fc2014-11-18 10:40:29 -07001426
Tobin Ehlis6cd06372014-12-17 17:44:50 -07001427class ParamCheckerSubcommand(Subcommand):
1428 def generate_header(self):
Jon Ashburn21001f62015-02-16 08:26:50 -07001429 return '#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include "loader_platform.h"\n#include "xglLayer.h"\n#include "layers_config.h"\n#include "xgl_enum_validate_helper.h"\n#include "xgl_struct_validate_helper.h"\n//The following is #included again to catch certain OS-specific functions being used:\n#include "loader_platform.h"\n\n#include "layers_msg.h"\n\nstatic XGL_LAYER_DISPATCH_TABLE nextTable;\nstatic XGL_BASE_LAYER_OBJECT *pCurObj;\nstatic LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);\n\n'
Tobin Ehlis6cd06372014-12-17 17:44:50 -07001430
1431 def generate_body(self):
Jon Ashburn21001f62015-02-16 08:26:50 -07001432 body = [self._generate_layer_initialization("ParamChecker", True),
Tobin Ehlis6cd06372014-12-17 17:44:50 -07001433 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "ParamChecker"),
Jon Ashburn21001f62015-02-16 08:26:50 -07001434 self._generate_layer_gpa_function("ParamChecker")]
Tobin Ehlis6cd06372014-12-17 17:44:50 -07001435
1436 return "\n\n".join(body)
1437
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001438def main():
1439 subcommands = {
1440 "layer-funcs" : LayerFuncsSubcommand,
1441 "layer-dispatch" : LayerDispatchSubcommand,
Tobin Ehlis907a0522014-11-25 16:59:27 -07001442 "Generic" : GenericLayerSubcommand,
1443 "ApiDump" : ApiDumpSubcommand,
1444 "ApiDumpFile" : ApiDumpFileSubcommand,
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -07001445 "ApiDumpNoAddr" : ApiDumpNoAddrSubcommand,
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001446 "ApiDumpCpp" : ApiDumpCppSubcommand,
1447 "ApiDumpNoAddrCpp" : ApiDumpNoAddrCppSubcommand,
Tobin Ehlis907a0522014-11-25 16:59:27 -07001448 "ObjectTracker" : ObjectTrackerSubcommand,
Tobin Ehlis6cd06372014-12-17 17:44:50 -07001449 "ParamChecker" : ParamCheckerSubcommand,
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001450 }
1451
Tobin Ehlis6cd06372014-12-17 17:44:50 -07001452 if len(sys.argv) < 3 or sys.argv[1] not in subcommands or not os.path.exists(sys.argv[2]):
1453 print("Usage: %s <subcommand> <input_header> [options]" % sys.argv[0])
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001454 print
Tobin Ehlis2f3726c2015-01-15 17:51:52 -07001455 print("Available subcommands are: %s" % " ".join(subcommands))
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001456 exit(1)
1457
Tobin Ehlis6cd06372014-12-17 17:44:50 -07001458 hfp = xgl_helper.HeaderFileParser(sys.argv[2])
1459 hfp.parse()
1460 xgl_helper.enum_val_dict = hfp.get_enum_val_dict()
1461 xgl_helper.enum_type_dict = hfp.get_enum_type_dict()
1462 xgl_helper.struct_dict = hfp.get_struct_dict()
1463 xgl_helper.typedef_fwd_dict = hfp.get_typedef_fwd_dict()
1464 xgl_helper.typedef_rev_dict = hfp.get_typedef_rev_dict()
1465 xgl_helper.types_dict = hfp.get_types_dict()
1466
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001467 subcmd = subcommands[sys.argv[1]](sys.argv[2:])
1468 subcmd.run()
1469
1470if __name__ == "__main__":
1471 main()