blob: bf17f6826652249baa8da9522a98c161cdff64b9 [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_header(self):
140 cbh_body = []
141 cbh_body.append('static XGL_LAYER_DBG_FUNCTION_NODE *pDbgFunctionHead = NULL;')
142 cbh_body.append('// Utility function to handle reporting')
143 cbh_body.append('// If callbacks are enabled, use them, otherwise use printf')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600144 cbh_body.append('static void layerCbMsg(XGL_DBG_MSG_TYPE msgType,')
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700145 cbh_body.append(' XGL_VALIDATION_LEVEL validationLevel,')
146 cbh_body.append(' XGL_BASE_OBJECT srcObject,')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600147 cbh_body.append(' size_t location,')
148 cbh_body.append(' int32_t msgCode,')
149 cbh_body.append(' const char* pLayerPrefix,')
150 cbh_body.append(' const char* pMsg)')
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700151 cbh_body.append('{')
152 cbh_body.append(' XGL_LAYER_DBG_FUNCTION_NODE *pTrav = pDbgFunctionHead;')
153 cbh_body.append(' if (pTrav) {')
154 cbh_body.append(' while (pTrav) {')
155 cbh_body.append(' pTrav->pfnMsgCallback(msgType, validationLevel, srcObject, location, msgCode, pMsg, pTrav->pUserData);')
156 cbh_body.append(' pTrav = pTrav->pNext;')
157 cbh_body.append(' }')
158 cbh_body.append(' }')
159 cbh_body.append(' else {')
160 cbh_body.append(' switch (msgType) {')
161 cbh_body.append(' case XGL_DBG_MSG_ERROR:')
162 cbh_body.append(' printf("{%s}ERROR : %s\\n", pLayerPrefix, pMsg);')
163 cbh_body.append(' break;')
164 cbh_body.append(' case XGL_DBG_MSG_WARNING:')
165 cbh_body.append(' printf("{%s}WARN : %s\\n", pLayerPrefix, pMsg);')
166 cbh_body.append(' break;')
167 cbh_body.append(' case XGL_DBG_MSG_PERF_WARNING:')
168 cbh_body.append(' printf("{%s}PERF_WARN : %s\\n", pLayerPrefix, pMsg);')
169 cbh_body.append(' break;')
170 cbh_body.append(' default:')
171 cbh_body.append(' printf("{%s}INFO : %s\\n", pLayerPrefix, pMsg);')
172 cbh_body.append(' break;')
173 cbh_body.append(' }')
174 cbh_body.append(' }')
175 cbh_body.append('}')
176 return "\n".join(cbh_body)
177
178 def _gen_layer_dbg_callback_register(self):
179 r_body = []
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600180 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 -0700181 r_body.append('{')
182 r_body.append(' // This layer intercepts callbacks')
183 r_body.append(' XGL_LAYER_DBG_FUNCTION_NODE *pNewDbgFuncNode = (XGL_LAYER_DBG_FUNCTION_NODE*)malloc(sizeof(XGL_LAYER_DBG_FUNCTION_NODE));')
184 r_body.append(' if (!pNewDbgFuncNode)')
185 r_body.append(' return XGL_ERROR_OUT_OF_MEMORY;')
186 r_body.append(' pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;')
187 r_body.append(' pNewDbgFuncNode->pUserData = pUserData;')
188 r_body.append(' pNewDbgFuncNode->pNext = pDbgFunctionHead;')
189 r_body.append(' pDbgFunctionHead = pNewDbgFuncNode;')
190 r_body.append(' XGL_RESULT result = nextTable.DbgRegisterMsgCallback(pfnMsgCallback, pUserData);')
191 r_body.append(' return result;')
192 r_body.append('}')
193 return "\n".join(r_body)
194
195 def _gen_layer_dbg_callback_unregister(self):
196 ur_body = []
197 ur_body.append('XGL_LAYER_EXPORT XGL_RESULT XGLAPI xglDbgUnregisterMsgCallback(XGL_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback)')
198 ur_body.append('{')
199 ur_body.append(' XGL_LAYER_DBG_FUNCTION_NODE *pTrav = pDbgFunctionHead;')
200 ur_body.append(' XGL_LAYER_DBG_FUNCTION_NODE *pPrev = pTrav;')
201 ur_body.append(' while (pTrav) {')
202 ur_body.append(' if (pTrav->pfnMsgCallback == pfnMsgCallback) {')
203 ur_body.append(' pPrev->pNext = pTrav->pNext;')
204 ur_body.append(' if (pDbgFunctionHead == pTrav)')
205 ur_body.append(' pDbgFunctionHead = pTrav->pNext;')
206 ur_body.append(' free(pTrav);')
207 ur_body.append(' break;')
208 ur_body.append(' }')
209 ur_body.append(' pPrev = pTrav;')
210 ur_body.append(' pTrav = pTrav->pNext;')
211 ur_body.append(' }')
212 ur_body.append(' XGL_RESULT result = nextTable.DbgUnregisterMsgCallback(pfnMsgCallback);')
213 ur_body.append(' return result;')
214 ur_body.append('}')
215 return "\n".join(ur_body)
216
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -0700217 def _generate_dispatch_entrypoints(self, qual="", layer="Generic", no_addr=False):
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600218 if qual:
219 qual += " "
220
Tobin Ehlis907a0522014-11-25 16:59:27 -0700221 layer_name = layer
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -0700222 if no_addr:
223 layer_name = "%sNoAddr" % layer
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700224 if 'Cpp' in layer_name:
225 layer_name = "APIDumpNoAddrCpp"
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600226 funcs = []
227 for proto in self.protos:
228 if proto.name != "GetProcAddr" and proto.name != "InitAndEnumerateGpus":
Tobin Ehlis907a0522014-11-25 16:59:27 -0700229 if "Generic" == layer:
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600230 decl = proto.c_func(prefix="xgl", attr="XGLAPI")
231 param0_name = proto.params[0].name
232 ret_val = ''
233 stmt = ''
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600234 if proto.ret != "void":
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600235 ret_val = "XGL_RESULT result = "
236 stmt = " return result;\n"
Ian Elliott81ac44c2015-01-13 17:52:38 -0700237 if 'WsiX11AssociateConnection' == proto.name:
238 funcs.append("#if !defined(_WIN32)")
Jon Ashburn451c16f2014-11-25 11:08:42 -0700239 if proto.name == "EnumerateLayers":
240 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
241 funcs.append('%s%s\n'
242 '{\n'
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700243 ' char str[1024];\n'
Jon Ashburn451c16f2014-11-25 11:08:42 -0700244 ' if (gpu != NULL) {\n'
245 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700246 ' sprintf(str, "At start of layered %s\\n");\n'
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600247 ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpu, 0, 0, (char *) "GENERIC", (char *) str);\n'
Jon Ashburn451c16f2014-11-25 11:08:42 -0700248 ' pCurObj = gpuw;\n'
Ian Elliott81ac44c2015-01-13 17:52:38 -0700249 ' loader_platform_thread_once(&tabOnce, initLayerTable);\n'
Jon Ashburn451c16f2014-11-25 11:08:42 -0700250 ' %snextTable.%s;\n'
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700251 ' sprintf(str, "Completed layered %s\\n");\n'
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600252 ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpu, 0, 0, (char *) "GENERIC", (char *) str);\n'
Jon Ashburn451c16f2014-11-25 11:08:42 -0700253 ' fflush(stdout);\n'
254 ' %s'
255 ' } else {\n'
256 ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n'
257 ' return XGL_ERROR_INVALID_POINTER;\n'
258 ' // This layer compatible with all GPUs\n'
259 ' *pOutLayerCount = 1;\n'
Chia-I Wua837c522014-12-16 10:47:33 +0800260 ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n'
Jon Ashburn451c16f2014-11-25 11:08:42 -0700261 ' return XGL_SUCCESS;\n'
262 ' }\n'
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -0700263 '}' % (qual, decl, proto.params[0].name, proto.name, ret_val, c_call, proto.name, stmt, layer_name))
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700264 elif 'DbgRegisterMsgCallback' == proto.name:
265 funcs.append(self._gen_layer_dbg_callback_register())
266 elif 'DbgUnregisterMsgCallback' == proto.name:
267 funcs.append(self._gen_layer_dbg_callback_unregister())
Jon Ashburn451c16f2014-11-25 11:08:42 -0700268 elif proto.params[0].ty != "XGL_PHYSICAL_GPU":
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600269 funcs.append('%s%s\n'
270 '{\n'
271 ' %snextTable.%s;\n'
272 '%s'
273 '}' % (qual, decl, ret_val, proto.c_call(), stmt))
274 else:
275 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
276 funcs.append('%s%s\n'
277 '{\n'
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700278 ' char str[1024];'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600279 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700280 ' sprintf(str, "At start of layered %s\\n");\n'
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600281 ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpuw, 0, 0, (char *) "GENERIC", (char *) str);\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600282 ' pCurObj = gpuw;\n'
Ian Elliott81ac44c2015-01-13 17:52:38 -0700283 ' loader_platform_thread_once(&tabOnce, initLayerTable);\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600284 ' %snextTable.%s;\n'
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700285 ' sprintf(str, "Completed layered %s\\n");\n'
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600286 ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpuw, 0, 0, (char *) "GENERIC", (char *) str);\n'
Courtney Goeltzenleuchtere6094fc2014-11-18 10:40:29 -0700287 ' fflush(stdout);\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600288 '%s'
289 '}' % (qual, decl, proto.params[0].name, proto.name, ret_val, c_call, proto.name, stmt))
Ian Elliott81ac44c2015-01-13 17:52:38 -0700290 if 'WsiX11QueuePresent' == proto.name:
291 funcs.append("#endif")
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700292 elif "APIDumpCpp" in layer:
293 decl = proto.c_func(prefix="xgl", attr="XGLAPI")
294 param0_name = proto.params[0].name
295 ret_val = ''
296 stmt = ''
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700297 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 -0700298 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 -0700299 if 'WsiX11CreatePresentableImage' in proto.name or 'AllocDescriptorSets' in proto.name:
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700300 create_params = -2
301 elif 'Create' in proto.name or 'Alloc' in proto.name or 'MapMemory' in proto.name:
302 create_params = -1
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600303 if proto.ret != "void":
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700304 ret_val = "XGL_RESULT result = "
305 stmt = " return result;\n"
306 f_open = ''
307 f_close = ''
308 if "File" in layer:
309 file_mode = "a"
310 if 'CreateDevice' in proto.name:
311 file_mode = "w"
Ian Elliott81ac44c2015-01-13 17:52:38 -0700312 f_open = 'loader_platform_thread_lock_mutex(&printLock);\n pOutFile = fopen(outFileName, "%s");\n ' % (file_mode)
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700313 log_func = 'fprintf(pOutFile, "t{%%u} xgl%s(' % proto.name
Ian Elliott81ac44c2015-01-13 17:52:38 -0700314 f_close = '\n fclose(pOutFile);\n loader_platform_thread_unlock_mutex(&printLock);'
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700315 else:
Ian Elliott81ac44c2015-01-13 17:52:38 -0700316 f_open = 'loader_platform_thread_lock_mutex(&printLock);\n '
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700317 log_func = 'cout << "t{" << getTIDIndex() << "} xgl%s(' % proto.name
Ian Elliott81ac44c2015-01-13 17:52:38 -0700318 f_close = '\n loader_platform_thread_unlock_mutex(&printLock);'
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700319 pindex = 0
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700320 prev_count_name = ''
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700321 for p in proto.params:
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700322 cp = False
323 if 0 != create_params:
324 # If this is any of the N last params of the func, treat as output
325 for y in range(-1, create_params-1, -1):
326 if p.name == proto.params[y].name:
327 cp = True
328 (pft, pfi) = self._get_printf_params(p.ty, p.name, cp, cpp=True)
329 if no_addr and "%p" == pft:
330 (pft, pfi) = ("%s", '"addr"')
331 log_func += '%s = " << %s << ", ' % (p.name, pfi)
332 #print_vals += ', %s' % (pfi)
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700333 if prev_count_name != '' and (prev_count_name.strip('Count')[1:] in p.name or 'slotCount' == prev_count_name):
334 sp_param_dict[pindex] = prev_count_name
335 elif 'pDescriptorSets' == p.name and proto.params[-1].name == 'pCount':
336 sp_param_dict[pindex] = '*pCount'
Tobin Ehlisfc04b892015-01-22 12:29:31 -0700337 elif 'Wsi' not in proto.name and xgl_helper.is_type(p.ty.strip('*').strip('const '), 'struct'):
338 sp_param_dict[pindex] = 'index'
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700339 pindex += 1
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700340 if p.name.endswith('Count'):
341 if '*' in p.ty:
342 prev_count_name = "*%s" % p.name
343 else:
344 prev_count_name = p.name
345 else:
346 prev_count_name = ''
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700347 log_func = log_func.strip(', ')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600348 if proto.ret != "void":
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700349 log_func += ') = " << string_XGL_RESULT((XGL_RESULT)result) << "\\n"'
350 #print_vals += ', string_XGL_RESULT_CODE(result)'
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700351 else:
352 log_func += ')\\n"'
353 log_func += ';'
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700354 if len(sp_param_dict) > 0:
355 i_decl = False
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700356 log_func += '\n string tmp_str;'
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700357 for sp_index in sp_param_dict:
358 if 'index' == sp_param_dict[sp_index]:
359 cis_print_func = 'xgl_print_%s' % (proto.params[sp_index].ty.strip('const ').strip('*').lower())
360 log_func += '\n if (%s) {' % (proto.params[sp_index].name)
361 log_func += '\n tmp_str = %s(%s, " ");' % (cis_print_func, proto.params[sp_index].name)
362 if "File" in layer:
363 if no_addr:
364 log_func += '\n fprintf(pOutFile, " %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name)
365 else:
366 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 -0700367 else:
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700368 if no_addr:
369 #log_func += '\n printf(" %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name)
370 log_func += '\n cout << " %s (addr)" << endl << tmp_str << endl;' % (proto.params[sp_index].name)
371 else:
372 #log_func += '\n printf(" %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name)
373 log_func += '\n cout << " %s (" << %s << ")" << endl << tmp_str << endl;' % (proto.params[sp_index].name, proto.params[sp_index].name)
374 #log_func += '\n fflush(stdout);'
375 log_func += '\n }'
376 else: # We have a count value stored to iterate over an array
377 print_cast = ''
378 print_func = ''
379 if xgl_helper.is_type(proto.params[sp_index].ty.strip('*').strip('const '), 'struct'):
380 print_cast = '&'
381 print_func = 'xgl_print_%s' % proto.params[sp_index].ty.strip('const ').strip('*').lower()
382 #cis_print_func = 'tmp_str = xgl_print_%s(&%s[i], " ");' % (proto.params[sp_index].ty.strip('const ').strip('*').lower(), proto.params[sp_index].name)
383# TODO : Need to display this address as a string
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700384 else:
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700385 print_cast = '(void*)'
386 print_func = 'string_convert_helper'
387 #cis_print_func = 'tmp_str = string_convert_helper((void*)%s[i], " ");' % proto.params[sp_index].name
388 cis_print_func = 'tmp_str = %s(%s%s[i], " ");' % (print_func, print_cast, proto.params[sp_index].name)
389# else:
390# cis_print_func = ''
391 if not i_decl:
392 log_func += '\n uint32_t i;'
393 i_decl = True
394 log_func += '\n for (i = 0; i < %s; i++) {' % (sp_param_dict[sp_index])
395 log_func += '\n %s' % (cis_print_func)
396 if "File" in layer:
397 if no_addr:
398 log_func += '\n fprintf(pOutFile, " %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name)
399 else:
400 log_func += '\n fprintf(pOutFile, " %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name)
401 else:
402 if no_addr:
403 #log_func += '\n printf(" %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name)
404 log_func += '\n cout << " %s[" << (uint32_t)i << "] (addr)" << endl << tmp_str << endl;' % (proto.params[sp_index].name)
405 else:
406 #log_func += '\n printf(" %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name)
407 #log_func += '\n cout << " %s[" << (uint32_t)i << "] (" << %s[i] << ")" << endl << tmp_str << endl;' % (proto.params[sp_index].name, proto.params[sp_index].name)
408 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)
409 #log_func += '\n fflush(stdout);'
410 log_func += '\n }'
Ian Elliott81ac44c2015-01-13 17:52:38 -0700411 if 'WsiX11AssociateConnection' == proto.name:
412 funcs.append("#if !defined(_WIN32)")
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700413 if proto.name == "EnumerateLayers":
414 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
415 funcs.append('%s%s\n'
416 '{\n'
417 ' if (gpu != NULL) {\n'
418 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
419 ' pCurObj = gpuw;\n'
Ian Elliott81ac44c2015-01-13 17:52:38 -0700420 ' loader_platform_thread_once(&tabOnce, initLayerTable);\n'
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700421 ' %snextTable.%s;\n'
422 ' %s %s %s\n'
423 ' %s'
424 ' } else {\n'
425 ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n'
426 ' return XGL_ERROR_INVALID_POINTER;\n'
427 ' // This layer compatible with all GPUs\n'
428 ' *pOutLayerCount = 1;\n'
429 ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n'
430 ' return XGL_SUCCESS;\n'
431 ' }\n'
432 '}' % (qual, decl, proto.params[0].name, ret_val, c_call,f_open, log_func, f_close, stmt, layer_name))
433 elif proto.params[0].ty != "XGL_PHYSICAL_GPU":
434 funcs.append('%s%s\n'
435 '{\n'
436 ' %snextTable.%s;\n'
437 ' %s%s%s\n'
438 '%s'
439 '}' % (qual, decl, ret_val, proto.c_call(), f_open, log_func, f_close, stmt))
440 else:
441 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
442 funcs.append('%s%s\n'
443 '{\n'
444 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
445 ' pCurObj = gpuw;\n'
Ian Elliott81ac44c2015-01-13 17:52:38 -0700446 ' loader_platform_thread_once(&tabOnce, initLayerTable);\n'
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700447 ' %snextTable.%s;\n'
448 ' %s%s%s\n'
449 '%s'
450 '}' % (qual, decl, proto.params[0].name, ret_val, c_call, f_open, log_func, f_close, stmt))
Ian Elliott81ac44c2015-01-13 17:52:38 -0700451 if 'WsiX11QueuePresent' == proto.name:
452 funcs.append("#endif")
Tobin Ehlis907a0522014-11-25 16:59:27 -0700453 elif "APIDump" in layer:
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600454 decl = proto.c_func(prefix="xgl", attr="XGLAPI")
455 param0_name = proto.params[0].name
456 ret_val = ''
457 stmt = ''
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700458 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 -0700459 create_params = 0 # Num of params at end of function that are created and returned as output values
460 if 'WsiX11CreatePresentableImage' in proto.name:
461 create_params = -2
462 elif 'Create' in proto.name or 'Alloc' in proto.name or 'MapMemory' in proto.name:
463 create_params = -1
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600464 if proto.ret != "void":
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600465 ret_val = "XGL_RESULT result = "
466 stmt = " return result;\n"
Tobin Ehlis574b0142014-11-12 13:11:15 -0700467 f_open = ''
468 f_close = ''
Tobin Ehlis907a0522014-11-25 16:59:27 -0700469 if "File" in layer:
Tobin Ehlis1eba7792014-11-21 09:35:53 -0700470 file_mode = "a"
471 if 'CreateDevice' in proto.name:
472 file_mode = "w"
Ian Elliott81ac44c2015-01-13 17:52:38 -0700473 f_open = 'loader_platform_thread_lock_mutex(&printLock);\n pOutFile = fopen(outFileName, "%s");\n ' % (file_mode)
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700474 log_func = 'fprintf(pOutFile, "t{%%u} xgl%s(' % proto.name
Ian Elliott81ac44c2015-01-13 17:52:38 -0700475 f_close = '\n fclose(pOutFile);\n loader_platform_thread_unlock_mutex(&printLock);'
Tobin Ehlis574b0142014-11-12 13:11:15 -0700476 else:
Ian Elliott81ac44c2015-01-13 17:52:38 -0700477 f_open = 'loader_platform_thread_lock_mutex(&printLock);\n '
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700478 log_func = 'printf("t{%%u} xgl%s(' % proto.name
Ian Elliott81ac44c2015-01-13 17:52:38 -0700479 f_close = '\n loader_platform_thread_unlock_mutex(&printLock);'
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700480 print_vals = ', getTIDIndex()'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600481 pindex = 0
Tobin Ehlisc7e926b2014-12-18 15:20:05 -0700482 prev_count_name = ''
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600483 for p in proto.params:
Tobin Ehlisa554dc32014-11-19 15:52:46 -0700484 cp = False
485 if 0 != create_params:
486 # If this is any of the N last params of the func, treat as output
487 for y in range(-1, create_params-1, -1):
488 if p.name == proto.params[y].name:
489 cp = True
490 (pft, pfi) = self._get_printf_params(p.ty, p.name, cp)
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -0700491 if no_addr and "%p" == pft:
492 (pft, pfi) = ("%s", '"addr"')
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600493 log_func += '%s = %s, ' % (p.name, pft)
494 print_vals += ', %s' % (pfi)
Tobin Ehlisc7e926b2014-12-18 15:20:05 -0700495 # Catch array inputs that are bound by a "Count" param
496 if prev_count_name != '' and (prev_count_name.strip('Count')[1:] in p.name or 'slotCount' == prev_count_name):
497 sp_param_dict[pindex] = prev_count_name
Tobin Ehlisd204b1a2015-01-20 09:48:48 -0700498 elif 'pDescriptorSets' == p.name and proto.params[-1].name == 'pCount':
499 sp_param_dict[pindex] = '*pCount'
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700500 elif 'Wsi' not in proto.name and xgl_helper.is_type(p.ty.strip('*').strip('const '), 'struct'):
Tobin Ehlisc7e926b2014-12-18 15:20:05 -0700501 sp_param_dict[pindex] = 'index'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600502 pindex += 1
Tobin Ehlisc7e926b2014-12-18 15:20:05 -0700503 if p.name.endswith('Count'):
Courtney Goeltzenleuchter08cf7cc2015-01-13 15:32:18 -0700504 if '*' in p.ty:
505 prev_count_name = "*%s" % p.name
506 else:
507 prev_count_name = p.name
Tobin Ehlisc7e926b2014-12-18 15:20:05 -0700508 else:
509 prev_count_name = ''
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600510 log_func = log_func.strip(', ')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600511 if proto.ret != "void":
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600512 log_func += ') = %s\\n"'
Courtney Goeltzenleuchtere6094fc2014-11-18 10:40:29 -0700513 print_vals += ', string_XGL_RESULT(result)'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600514 else:
515 log_func += ')\\n"'
516 log_func = '%s%s);' % (log_func, print_vals)
Tobin Ehlisc7e926b2014-12-18 15:20:05 -0700517 if len(sp_param_dict) > 0:
518 i_decl = False
519 log_func += '\n char *pTmpStr = "";'
520 for sp_index in sorted(sp_param_dict):
521 # TODO : Clean this if/else block up, too much duplicated code
522 if 'index' == sp_param_dict[sp_index]:
523 cis_print_func = 'xgl_print_%s' % (proto.params[sp_index].ty.strip('const ').strip('*').lower())
524 log_func += '\n if (%s) {' % (proto.params[sp_index].name)
525 log_func += '\n pTmpStr = %s(%s, " ");' % (cis_print_func, proto.params[sp_index].name)
526 if "File" in layer:
527 if no_addr:
528 log_func += '\n fprintf(pOutFile, " %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name)
529 else:
530 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 -0700531 else:
Tobin Ehlisc7e926b2014-12-18 15:20:05 -0700532 if no_addr:
533 log_func += '\n printf(" %s (addr)\\n%%s\\n", pTmpStr);' % (proto.params[sp_index].name)
534 else:
535 log_func += '\n printf(" %s (%%p)\\n%%s\\n", (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name)
536 log_func += '\n fflush(stdout);'
537 log_func += '\n free(pTmpStr);\n }'
538 else: # should have a count value stored to iterate over array
539 if xgl_helper.is_type(proto.params[sp_index].ty.strip('*').strip('const '), 'struct'):
540 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 -0700541 else:
Tobin Ehlisc7e926b2014-12-18 15:20:05 -0700542 cis_print_func = 'pTmpStr = (char*)malloc(sizeof(char));\n sprintf(pTmpStr, " %%p", %s[i]);' % proto.params[sp_index].name
543 if not i_decl:
544 log_func += '\n uint32_t i;'
545 i_decl = True
Jon Ashburn48637592015-01-14 08:52:37 -0700546 log_func += '\n for (i = 0; i < %s; i++) {' % (sp_param_dict[sp_index])
Tobin Ehlisc7e926b2014-12-18 15:20:05 -0700547 log_func += '\n %s' % (cis_print_func)
548 if "File" in layer:
549 if no_addr:
550 log_func += '\n fprintf(pOutFile, " %s[%%i] (addr)\\n%%s\\n", i, pTmpStr);' % (proto.params[sp_index].name)
551 else:
552 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)
553 else:
554 if no_addr:
555 log_func += '\n printf(" %s[%%i] (addr)\\n%%s\\n", i, pTmpStr);' % (proto.params[sp_index].name)
556 else:
557 log_func += '\n printf(" %s[%%i] (%%p)\\n%%s\\n", i, (void*)%s, pTmpStr);' % (proto.params[sp_index].name, proto.params[sp_index].name)
558 log_func += '\n fflush(stdout);'
559 log_func += '\n free(pTmpStr);\n }'
Ian Elliott81ac44c2015-01-13 17:52:38 -0700560 if 'WsiX11AssociateConnection' == proto.name:
561 funcs.append("#if !defined(_WIN32)")
Jon Ashburn451c16f2014-11-25 11:08:42 -0700562 if proto.name == "EnumerateLayers":
563 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
564 funcs.append('%s%s\n'
565 '{\n'
566 ' if (gpu != NULL) {\n'
567 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
568 ' pCurObj = gpuw;\n'
Ian Elliott81ac44c2015-01-13 17:52:38 -0700569 ' loader_platform_thread_once(&tabOnce, initLayerTable);\n'
Jon Ashburn451c16f2014-11-25 11:08:42 -0700570 ' %snextTable.%s;\n'
571 ' %s %s %s\n'
572 ' %s'
573 ' } else {\n'
574 ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n'
575 ' return XGL_ERROR_INVALID_POINTER;\n'
576 ' // This layer compatible with all GPUs\n'
577 ' *pOutLayerCount = 1;\n'
Chia-I Wua837c522014-12-16 10:47:33 +0800578 ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n'
Jon Ashburn451c16f2014-11-25 11:08:42 -0700579 ' return XGL_SUCCESS;\n'
580 ' }\n'
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -0700581 '}' % (qual, decl, proto.params[0].name, ret_val, c_call,f_open, log_func, f_close, stmt, layer_name))
Jon Ashburn451c16f2014-11-25 11:08:42 -0700582 elif proto.params[0].ty != "XGL_PHYSICAL_GPU":
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600583 funcs.append('%s%s\n'
584 '{\n'
585 ' %snextTable.%s;\n'
Tobin Ehlis574b0142014-11-12 13:11:15 -0700586 ' %s%s%s\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600587 '%s'
Tobin Ehlis574b0142014-11-12 13:11:15 -0700588 '}' % (qual, decl, ret_val, proto.c_call(), f_open, log_func, f_close, stmt))
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600589 else:
590 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
591 funcs.append('%s%s\n'
592 '{\n'
593 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
594 ' pCurObj = gpuw;\n'
Ian Elliott81ac44c2015-01-13 17:52:38 -0700595 ' loader_platform_thread_once(&tabOnce, initLayerTable);\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600596 ' %snextTable.%s;\n'
Tobin Ehlis574b0142014-11-12 13:11:15 -0700597 ' %s%s%s\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600598 '%s'
Tobin Ehlis574b0142014-11-12 13:11:15 -0700599 '}' % (qual, decl, proto.params[0].name, ret_val, c_call, f_open, log_func, f_close, stmt))
Ian Elliott81ac44c2015-01-13 17:52:38 -0700600 if 'WsiX11QueuePresent' == proto.name:
601 funcs.append("#endif")
Tobin Ehlis907a0522014-11-25 16:59:27 -0700602 elif "ObjectTracker" == layer:
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700603 obj_type_mapping = {base_t : base_t.replace("XGL_", "XGL_OBJECT_TYPE_") for base_t in xgl.object_type_list}
604 # For the various "super-types" we have to use function to distinguish sub type
605 for obj_type in ["XGL_BASE_OBJECT", "XGL_OBJECT", "XGL_DYNAMIC_STATE_OBJECT"]:
606 obj_type_mapping[obj_type] = "ll_get_obj_type(object)"
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700607
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600608 decl = proto.c_func(prefix="xgl", attr="XGLAPI")
609 param0_name = proto.params[0].name
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700610 p0_type = proto.params[0].ty.strip('*').strip('const ')
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600611 create_line = ''
612 destroy_line = ''
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700613 if 'DbgRegisterMsgCallback' in proto.name:
614 using_line = ' // This layer intercepts callbacks\n'
615 using_line += ' XGL_LAYER_DBG_FUNCTION_NODE *pNewDbgFuncNode = (XGL_LAYER_DBG_FUNCTION_NODE*)malloc(sizeof(XGL_LAYER_DBG_FUNCTION_NODE));\n'
616 using_line += ' if (!pNewDbgFuncNode)\n'
617 using_line += ' return XGL_ERROR_OUT_OF_MEMORY;\n'
618 using_line += ' pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;\n'
619 using_line += ' pNewDbgFuncNode->pUserData = pUserData;\n'
620 using_line += ' pNewDbgFuncNode->pNext = pDbgFunctionHead;\n'
621 using_line += ' pDbgFunctionHead = pNewDbgFuncNode;\n'
622 elif 'DbgUnregisterMsgCallback' in proto.name:
623 using_line = ' XGL_LAYER_DBG_FUNCTION_NODE *pTrav = pDbgFunctionHead;\n'
624 using_line += ' XGL_LAYER_DBG_FUNCTION_NODE *pPrev = pTrav;\n'
625 using_line += ' while (pTrav) {\n'
626 using_line += ' if (pTrav->pfnMsgCallback == pfnMsgCallback) {\n'
627 using_line += ' pPrev->pNext = pTrav->pNext;\n'
628 using_line += ' if (pDbgFunctionHead == pTrav)\n'
629 using_line += ' pDbgFunctionHead = pTrav->pNext;\n'
630 using_line += ' free(pTrav);\n'
631 using_line += ' break;\n'
632 using_line += ' }\n'
633 using_line += ' pPrev = pTrav;\n'
634 using_line += ' pTrav = pTrav->pNext;\n'
635 using_line += ' }\n'
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700636 # Special cases for API funcs that don't use an object as first arg
637 elif True in [no_use_proto in proto.name for no_use_proto in ['GlobalOption', 'CreateInstance']]:
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600638 using_line = ''
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700639 else:
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600640 using_line = ' ll_increment_use_count((void*)%s, %s);\n' % (param0_name, obj_type_mapping[p0_type])
Tobin Ehlis235c20e2015-01-16 08:56:30 -0700641 if 'QueueSubmit' in proto.name:
642 using_line += ' set_status((void*)fence, XGL_OBJECT_TYPE_FENCE, OBJSTATUS_FENCE_IS_SUBMITTED);\n'
Mark Lobodzinski4186e712015-02-03 11:52:26 -0600643 using_line += ' validate_memory_mapping_status(pMemRefs, memRefCount);\n'
Mark Lobodzinskie1d3f0c2015-02-09 10:20:53 -0600644 using_line += ' validate_mem_ref_count(memRefCount);\n'
Tobin Ehlis235c20e2015-01-16 08:56:30 -0700645 elif 'GetFenceStatus' in proto.name:
646 using_line += ' // Warn if submitted_flag is not set\n'
Mark Lobodzinski4186e712015-02-03 11:52:26 -0600647 using_line += ' validate_status((void*)fence, XGL_OBJECT_TYPE_FENCE, OBJSTATUS_FENCE_IS_SUBMITTED, OBJSTATUS_FENCE_IS_SUBMITTED, XGL_DBG_MSG_ERROR, OBJTRACK_INVALID_FENCE, "Status Requested for Unsubmitted Fence");\n'
Mark Lobodzinski01552702015-02-03 10:06:31 -0600648 elif 'EndCommandBuffer' in proto.name:
649 using_line += ' reset_status((void*)cmdBuffer, XGL_OBJECT_TYPE_CMD_BUFFER, (OBJSTATUS_VIEWPORT_BOUND |\n'
650 using_line += ' OBJSTATUS_RASTER_BOUND |\n'
651 using_line += ' OBJSTATUS_COLOR_BLEND_BOUND |\n'
652 using_line += ' OBJSTATUS_DEPTH_STENCIL_BOUND));\n'
653 elif 'CmdBindDynamicStateObject' in proto.name:
654 using_line += ' track_object_status((void*)cmdBuffer, stateBindPoint);\n'
655 elif 'CmdDraw' in proto.name:
656 using_line += ' validate_draw_state_flags((void *)cmdBuffer);\n'
Mark Lobodzinski4186e712015-02-03 11:52:26 -0600657 elif 'MapMemory' in proto.name:
658 using_line += ' set_status((void*)mem, XGL_OBJECT_TYPE_GPU_MEMORY, OBJSTATUS_GPU_MEM_MAPPED);\n'
659 elif 'UnmapMemory' in proto.name:
660 using_line += ' reset_status((void*)mem, XGL_OBJECT_TYPE_GPU_MEMORY, OBJSTATUS_GPU_MEM_MAPPED);\n'
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700661 if 'AllocDescriptor' in proto.name: # Allocates array of DSs
Ian Elliotteac469b2015-02-04 12:15:12 -0700662 create_line = ' for (uint32_t i = 0; i < *pCount; i++) {\n'
Tobin Ehlis2f3726c2015-01-15 17:51:52 -0700663 create_line += ' ll_insert_obj((void*)pDescriptorSets[i], XGL_OBJECT_TYPE_DESCRIPTOR_SET);\n'
664 create_line += ' }\n'
665 elif 'Create' in proto.name or 'Alloc' in proto.name:
666 create_line = ' ll_insert_obj((void*)*%s, %s);\n' % (proto.params[-1].name, obj_type_mapping[proto.params[-1].ty.strip('*').strip('const ')])
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700667 if 'DestroyObject' in proto.name:
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600668 destroy_line = ' ll_destroy_obj((void*)%s);\n' % (param0_name)
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700669 using_line = ''
670 else:
671 if 'Destroy' in proto.name or 'Free' in proto.name:
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600672 destroy_line = ' ll_remove_obj_type((void*)%s, %s);\n' % (param0_name, obj_type_mapping[p0_type])
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700673 using_line = ''
674 if 'DestroyDevice' in proto.name:
675 destroy_line += ' // Report any remaining objects in LL\n objNode *pTrav = pGlobalHead;\n while (pTrav) {\n'
676 destroy_line += ' char str[1024];\n'
677 destroy_line += ' sprintf(str, "OBJ ERROR : %s object %p has not been destroyed (was used %lu times).", string_XGL_OBJECT_TYPE(pTrav->obj.objType), pTrav->obj.pObj, pTrav->obj.numUses);\n'
678 destroy_line += ' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, device, 0, OBJTRACK_OBJECT_LEAK, "OBJTRACK", str);\n'
679 destroy_line += ' pTrav = pTrav->pNextGlobal;\n }\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600680 ret_val = ''
681 stmt = ''
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600682 if proto.ret != "void":
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600683 ret_val = "XGL_RESULT result = "
684 stmt = " return result;\n"
Ian Elliott81ac44c2015-01-13 17:52:38 -0700685 if 'WsiX11AssociateConnection' == proto.name:
686 funcs.append("#if !defined(_WIN32)")
Jon Ashburn451c16f2014-11-25 11:08:42 -0700687 if proto.name == "EnumerateLayers":
688 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
689 funcs.append('%s%s\n'
690 '{\n'
691 ' if (gpu != NULL) {\n'
692 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
693 ' %s'
694 ' pCurObj = gpuw;\n'
Ian Elliott81ac44c2015-01-13 17:52:38 -0700695 ' loader_platform_thread_once(&tabOnce, initLayerTable);\n'
Jon Ashburn451c16f2014-11-25 11:08:42 -0700696 ' %snextTable.%s;\n'
697 ' %s%s'
698 ' %s'
699 ' } else {\n'
700 ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n'
701 ' return XGL_ERROR_INVALID_POINTER;\n'
702 ' // This layer compatible with all GPUs\n'
703 ' *pOutLayerCount = 1;\n'
Chia-I Wua837c522014-12-16 10:47:33 +0800704 ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n'
Jon Ashburn451c16f2014-11-25 11:08:42 -0700705 ' return XGL_SUCCESS;\n'
706 ' }\n'
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -0700707 '}' % (qual, decl, proto.params[0].name, using_line, ret_val, c_call, create_line, destroy_line, stmt, layer_name))
Jon Ashburn451c16f2014-11-25 11:08:42 -0700708 elif proto.params[0].ty != "XGL_PHYSICAL_GPU":
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600709 funcs.append('%s%s\n'
710 '{\n'
711 '%s'
712 ' %snextTable.%s;\n'
713 '%s%s'
714 '%s'
715 '}' % (qual, decl, using_line, ret_val, proto.c_call(), create_line, destroy_line, stmt))
716 else:
717 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
Mark Lobodzinskie1d3f0c2015-02-09 10:20:53 -0600718 gpu_state = ''
719 if 'GetGpuInfo' in proto.name:
720 gpu_state = ' if (infoType == XGL_INFO_TYPE_PHYSICAL_GPU_PROPERTIES) {\n'
721 gpu_state += ' if (pData != NULL) {\n'
722 gpu_state += ' setGpuInfoState(pData);\n'
723 gpu_state += ' }\n'
724 gpu_state += ' }\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600725 funcs.append('%s%s\n'
726 '{\n'
727 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
728 '%s'
729 ' pCurObj = gpuw;\n'
Ian Elliott81ac44c2015-01-13 17:52:38 -0700730 ' loader_platform_thread_once(&tabOnce, initLayerTable);\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600731 ' %snextTable.%s;\n'
732 '%s%s'
733 '%s'
Mark Lobodzinskie1d3f0c2015-02-09 10:20:53 -0600734 '%s'
735 '}' % (qual, decl, proto.params[0].name, using_line, ret_val, c_call, create_line, destroy_line, gpu_state, stmt))
Ian Elliott81ac44c2015-01-13 17:52:38 -0700736 if 'WsiX11QueuePresent' == proto.name:
737 funcs.append("#endif")
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700738 elif "ParamChecker" == layer:
739 # TODO : Need to fix up the non-else cases below to do param checking as well
740 decl = proto.c_func(prefix="xgl", attr="XGLAPI")
741 param0_name = proto.params[0].name
742 ret_val = ''
743 stmt = ''
744 param_checks = []
745 # Add code to check enums and structs
746 # TODO : Currently only validating enum values, need to validate everything
747 str_decl = False
Tobin Ehlis773371f2014-12-18 13:51:21 -0700748 prev_count_name = ''
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700749 for p in proto.params:
750 if xgl_helper.is_type(p.ty.strip('*').strip('const '), 'enum'):
751 if not str_decl:
752 param_checks.append(' char str[1024];')
753 str_decl = True
754 param_checks.append(' if (!validate_%s(%s)) {' % (p.ty, p.name))
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700755 param_checks.append(' sprintf(str, "Parameter %s to function %s has invalid value of %%i.", (int)%s);' % (p.name, proto.name, p.name))
756 param_checks.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, 1, "PARAMCHECK", str);')
757 param_checks.append(' }')
758 elif xgl_helper.is_type(p.ty.strip('*').strip('const '), 'struct') and 'const' in p.ty:
Tobin Ehlis773371f2014-12-18 13:51:21 -0700759 is_array = False
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700760 if not str_decl:
761 param_checks.append(' char str[1024];')
762 str_decl = True
763 if '*' in p.ty: # First check for null ptr
Tobin Ehlis773371f2014-12-18 13:51:21 -0700764 # If this is an input array, parse over all of the array elements
765 if prev_count_name != '' and (prev_count_name.strip('Count')[1:] in p.name or 'slotCount' == prev_count_name):
766 #if 'pImageViews' in p.name:
767 is_array = True
768 param_checks.append(' uint32_t i;')
769 param_checks.append(' for (i = 0; i < %s; i++) {' % prev_count_name)
770 param_checks.append(' if (!xgl_validate_%s(&%s[i])) {' % (p.ty.strip('*').strip('const ').lower(), p.name))
771 param_checks.append(' sprintf(str, "Parameter %s[%%i] to function %s contains an invalid value.", i);' % (p.name, proto.name))
772 param_checks.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, 1, "PARAMCHECK", str);')
773 param_checks.append(' }')
774 param_checks.append(' }')
775 else:
776 param_checks.append(' if (!%s) {' % p.name)
777 param_checks.append(' sprintf(str, "Struct ptr parameter %s to function %s is NULL.");' % (p.name, proto.name))
778 param_checks.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, NULL, 0, 1, "PARAMCHECK", str);')
779 param_checks.append(' }')
780 param_checks.append(' else if (!xgl_validate_%s(%s)) {' % (p.ty.strip('*').strip('const ').lower(), p.name))
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700781 else:
782 param_checks.append(' if (!xgl_validate_%s(%s)) {' % (p.ty.strip('const ').lower(), p.name))
Tobin Ehlis773371f2014-12-18 13:51:21 -0700783 if not is_array:
784 param_checks.append(' sprintf(str, "Parameter %s to function %s contains an invalid value.");' % (p.name, proto.name))
785 param_checks.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, 1, "PARAMCHECK", str);')
786 param_checks.append(' }')
787 if p.name.endswith('Count'):
788 prev_count_name = p.name
789 else:
790 prev_count_name = ''
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600791 if proto.ret != "void":
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700792 ret_val = "XGL_RESULT result = "
793 stmt = " return result;\n"
Ian Elliott81ac44c2015-01-13 17:52:38 -0700794 if 'WsiX11AssociateConnection' == proto.name:
795 funcs.append("#if !defined(_WIN32)")
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700796 if proto.name == "EnumerateLayers":
797 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
798 funcs.append('%s%s\n'
799 '{\n'
800 ' char str[1024];\n'
801 ' if (gpu != NULL) {\n'
802 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
803 ' sprintf(str, "At start of layered %s\\n");\n'
804 ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpu, 0, 0, "PARAMCHECK", str);\n'
805 ' pCurObj = gpuw;\n'
Ian Elliott81ac44c2015-01-13 17:52:38 -0700806 ' loader_platform_thread_once(&tabOnce, initLayerTable);\n'
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700807 ' %snextTable.%s;\n'
808 ' sprintf(str, "Completed layered %s\\n");\n'
809 ' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, gpu, 0, 0, "PARAMCHECK", str);\n'
810 ' fflush(stdout);\n'
811 ' %s'
812 ' } else {\n'
813 ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n'
814 ' return XGL_ERROR_INVALID_POINTER;\n'
815 ' // This layer compatible with all GPUs\n'
816 ' *pOutLayerCount = 1;\n'
817 ' strncpy(pOutLayers[0], "%s", maxStringSize);\n'
818 ' return XGL_SUCCESS;\n'
819 ' }\n'
820 '}' % (qual, decl, proto.params[0].name, proto.name, ret_val, c_call, proto.name, stmt, layer_name))
821 elif 'DbgRegisterMsgCallback' == proto.name:
822 funcs.append(self._gen_layer_dbg_callback_register())
823 elif 'DbgUnregisterMsgCallback' == proto.name:
824 funcs.append(self._gen_layer_dbg_callback_unregister())
825 elif proto.params[0].ty != "XGL_PHYSICAL_GPU":
826 funcs.append('%s%s\n'
827 '{\n'
828 '%s\n'
829 ' %snextTable.%s;\n'
830 '%s'
831 '}' % (qual, decl, "\n".join(param_checks), ret_val, proto.c_call(), stmt))
832 else:
833 c_call = proto.c_call().replace("(" + proto.params[0].name, "((XGL_PHYSICAL_GPU)gpuw->nextObject", 1)
834 funcs.append('%s%s\n'
835 '{\n'
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700836 ' XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) %s;\n'
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700837 ' pCurObj = gpuw;\n'
Ian Elliott81ac44c2015-01-13 17:52:38 -0700838 ' loader_platform_thread_once(&tabOnce, initLayerTable);\n'
Tobin Ehlis9d139862014-12-18 08:44:01 -0700839 '%s\n'
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700840 ' %snextTable.%s;\n'
Tobin Ehlis6cd06372014-12-17 17:44:50 -0700841 '%s'
Tobin Ehlis9d139862014-12-18 08:44:01 -0700842 '}' % (qual, decl, proto.params[0].name, "\n".join(param_checks), ret_val, c_call, stmt))
Ian Elliott81ac44c2015-01-13 17:52:38 -0700843 if 'WsiX11QueuePresent' == proto.name:
844 funcs.append("#endif")
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600845
846 return "\n\n".join(funcs)
847
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700848 def _generate_extensions(self):
849 exts = []
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600850 exts.append('uint64_t objTrackGetObjectCount(XGL_OBJECT_TYPE type)')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700851 exts.append('{')
852 exts.append(' return (type == XGL_OBJECT_TYPE_ANY) ? numTotalObjs : numObjs[type];')
853 exts.append('}')
854 exts.append('')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600855 exts.append('XGL_RESULT objTrackGetObjects(XGL_OBJECT_TYPE type, uint64_t objCount, OBJTRACK_NODE* pObjNodeArray)')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700856 exts.append('{')
857 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 -0600858 exts.append(' bool32_t bAllObjs = (type == XGL_OBJECT_TYPE_ANY);')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700859 exts.append(' // Check the count first thing')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600860 exts.append(' uint64_t maxObjCount = (bAllObjs) ? numTotalObjs : numObjs[type];')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700861 exts.append(' if (objCount > maxObjCount) {')
862 exts.append(' char str[1024];')
863 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));')
864 exts.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, 0, 0, OBJTRACK_OBJCOUNT_MAX_EXCEEDED, "OBJTRACK", str);')
865 exts.append(' return XGL_ERROR_INVALID_VALUE;')
866 exts.append(' }')
867 exts.append(' objNode* pTrav = (bAllObjs) ? pGlobalHead : pObjectHead[type];')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600868 exts.append(' for (uint64_t i = 0; i < objCount; i++) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700869 exts.append(' if (!pTrav) {')
870 exts.append(' char str[1024];')
871 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);')
872 exts.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, 0, 0, OBJTRACK_INTERNAL_ERROR, "OBJTRACK", str);')
873 exts.append(' return XGL_ERROR_UNKNOWN;')
874 exts.append(' }')
875 exts.append(' memcpy(&pObjNodeArray[i], pTrav, sizeof(OBJTRACK_NODE));')
876 exts.append(' pTrav = (bAllObjs) ? pTrav->pNextGlobal : pTrav->pNextObj;')
877 exts.append(' }')
878 exts.append(' return XGL_SUCCESS;')
879 exts.append('}')
880
881 return "\n".join(exts)
882
Chia-I Wu706533e2015-01-05 13:18:57 +0800883 def _generate_layer_gpa_function(self, extensions=[]):
884 func_body = ["#include \"xgl_generic_intercept_proc_helper.h\""]
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600885 func_body.append("XGL_LAYER_EXPORT void* XGLAPI xglGetProcAddr(XGL_PHYSICAL_GPU gpu, const char* funcName)\n"
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600886 "{\n"
887 " XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) gpu;\n"
Chia-I Wu706533e2015-01-05 13:18:57 +0800888 " void* addr;\n"
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600889 " if (gpu == NULL)\n"
890 " return NULL;\n"
891 " pCurObj = gpuw;\n"
Ian Elliott81ac44c2015-01-13 17:52:38 -0700892 " loader_platform_thread_once(&tabOnce, initLayerTable);\n\n"
Chia-I Wu706533e2015-01-05 13:18:57 +0800893 " addr = layer_intercept_proc(funcName);\n"
894 " if (addr)\n"
895 " return addr;")
896
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700897 if 0 != len(extensions):
898 for ext_name in extensions:
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800899 func_body.append(' else if (!strncmp("%s", funcName, sizeof("%s")))\n'
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700900 ' return %s;' % (ext_name, ext_name, ext_name))
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600901 func_body.append(" else {\n"
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600902 " if (gpuw->pGPA == NULL)\n"
903 " return NULL;\n"
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700904 " return gpuw->pGPA((XGL_PHYSICAL_GPU)gpuw->nextObject, funcName);\n"
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600905 " }\n"
906 "}\n")
907 return "\n".join(func_body)
908
909 def _generate_layer_dispatch_table(self, prefix='xgl'):
Chia-I Wu0f65b1e2015-01-04 23:11:43 +0800910 func_body = ["#include \"xgl_dispatch_table_helper.h\""]
Ian Elliotteac469b2015-02-04 12:15:12 -0700911 func_body.append('static void initLayerTable(void)\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600912 '{\n'
Mark Lobodzinski953a1692015-01-09 15:12:03 -0600913 ' xglGetProcAddrType fpNextGPA;\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600914 ' fpNextGPA = pCurObj->pGPA;\n'
915 ' assert(fpNextGPA);\n');
916
Chia-I Wu0f65b1e2015-01-04 23:11:43 +0800917 func_body.append(" layer_initialize_dispatch_table(&nextTable, fpNextGPA, (XGL_PHYSICAL_GPU) pCurObj->nextObject);")
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600918 func_body.append("}\n")
919 return "\n".join(func_body)
920
Ian Elliott81ac44c2015-01-13 17:52:38 -0700921 def _generate_layer_dispatch_table_with_lock(self, prefix='xgl'):
922 func_body = ["#include \"xgl_dispatch_table_helper.h\""]
Ian Elliotteac469b2015-02-04 12:15:12 -0700923 func_body.append('static void initLayerTable(void)\n'
Ian Elliott81ac44c2015-01-13 17:52:38 -0700924 '{\n'
925 ' xglGetProcAddrType fpNextGPA;\n'
926 ' fpNextGPA = pCurObj->pGPA;\n'
927 ' assert(fpNextGPA);\n');
928
929 func_body.append(" layer_initialize_dispatch_table(&nextTable, fpNextGPA, (XGL_PHYSICAL_GPU) pCurObj->nextObject);\n")
930 func_body.append(" if (!printLockInitialized)")
931 func_body.append(" {")
932 func_body.append(" // TODO/TBD: Need to delete this mutex sometime. How???")
933 func_body.append(" loader_platform_thread_create_mutex(&printLock);")
934 func_body.append(" printLockInitialized = 1;")
935 func_body.append(" }")
936 func_body.append("}\n")
937 return "\n".join(func_body)
938
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600939class LayerFuncsSubcommand(Subcommand):
940 def generate_header(self):
941 return '#include <xglLayer.h>\n#include "loader.h"'
942
943 def generate_body(self):
944 return self._generate_dispatch_entrypoints("static", True)
945
946class LayerDispatchSubcommand(Subcommand):
947 def generate_header(self):
948 return '#include "layer_wrappers.h"'
949
950 def generate_body(self):
951 return self._generate_layer_dispatch_table()
952
953class GenericLayerSubcommand(Subcommand):
954 def generate_header(self):
Ian Elliott81ac44c2015-01-13 17:52:38 -0700955 return '#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include "loader_platform.h"\n#include "xglLayer.h"\n\nstatic XGL_LAYER_DISPATCH_TABLE nextTable;\nstatic XGL_BASE_LAYER_OBJECT *pCurObj;\n\nstatic LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600956
957 def generate_body(self):
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700958 body = [self._gen_layer_dbg_callback_header(),
959 self._generate_layer_dispatch_table(),
Tobin Ehlis907a0522014-11-25 16:59:27 -0700960 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "Generic"),
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600961 self._generate_layer_gpa_function()]
962
963 return "\n\n".join(body)
964
965class ApiDumpSubcommand(Subcommand):
966 def generate_header(self):
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700967 header_txt = []
Ian Elliott81ac44c2015-01-13 17:52:38 -0700968 header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>')
969 header_txt.append('#include "loader_platform.h"')
970 header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper.h"\n')
971 header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;')
972 header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n')
973 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
974 header_txt.append('static int printLockInitialized = 0;')
975 header_txt.append('static loader_platform_thread_mutex printLock;\n')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700976 header_txt.append('#define MAX_TID 513')
Ian Elliott81ac44c2015-01-13 17:52:38 -0700977 header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700978 header_txt.append('static uint32_t maxTID = 0;')
979 header_txt.append('// Map actual TID to an index value and return that index')
980 header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs')
981 header_txt.append('static uint32_t getTIDIndex() {')
Ian Elliott81ac44c2015-01-13 17:52:38 -0700982 header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700983 header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {')
984 header_txt.append(' if (tid == tidMapping[i])')
985 header_txt.append(' return i;')
986 header_txt.append(' }')
987 header_txt.append(" // Don't yet have mapping, set it and return newly set index")
Ian Elliott81ac44c2015-01-13 17:52:38 -0700988 header_txt.append(' uint32_t retVal = (uint32_t) maxTID;')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700989 header_txt.append(' tidMapping[maxTID++] = tid;')
990 header_txt.append(' assert(maxTID < MAX_TID);')
991 header_txt.append(' return retVal;')
992 header_txt.append('}')
993 return "\n".join(header_txt)
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600994
995 def generate_body(self):
Ian Elliott81ac44c2015-01-13 17:52:38 -0700996 body = [self._generate_layer_dispatch_table_with_lock(),
Tobin Ehlis907a0522014-11-25 16:59:27 -0700997 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDump"),
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600998 self._generate_layer_gpa_function()]
999
1000 return "\n\n".join(body)
1001
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001002class ApiDumpCppSubcommand(Subcommand):
1003 def generate_header(self):
1004 header_txt = []
Ian Elliott81ac44c2015-01-13 17:52:38 -07001005 header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>')
1006 header_txt.append('#include "loader_platform.h"')
1007 header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper_cpp.h"\n')
1008 header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;')
1009 header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n')
1010 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
1011 header_txt.append('static int printLockInitialized = 0;')
1012 header_txt.append('static loader_platform_thread_mutex printLock;\n')
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001013 header_txt.append('#define MAX_TID 513')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001014 header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};')
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001015 header_txt.append('static uint32_t maxTID = 0;')
1016 header_txt.append('// Map actual TID to an index value and return that index')
1017 header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs')
1018 header_txt.append('static uint32_t getTIDIndex() {')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001019 header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();')
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001020 header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {')
1021 header_txt.append(' if (tid == tidMapping[i])')
1022 header_txt.append(' return i;')
1023 header_txt.append(' }')
1024 header_txt.append(" // Don't yet have mapping, set it and return newly set index")
Ian Elliott81ac44c2015-01-13 17:52:38 -07001025 header_txt.append(' uint32_t retVal = (uint32_t) maxTID;')
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001026 header_txt.append(' tidMapping[maxTID++] = tid;')
1027 header_txt.append(' assert(maxTID < MAX_TID);')
1028 header_txt.append(' return retVal;')
1029 header_txt.append('}')
1030 return "\n".join(header_txt)
1031
1032 def generate_body(self):
Ian Elliott81ac44c2015-01-13 17:52:38 -07001033 body = [self._generate_layer_dispatch_table_with_lock(),
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001034 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDumpCpp"),
1035 self._generate_layer_gpa_function()]
1036
1037 return "\n\n".join(body)
1038
Tobin Ehlis574b0142014-11-12 13:11:15 -07001039class ApiDumpFileSubcommand(Subcommand):
1040 def generate_header(self):
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -07001041 header_txt = []
Ian Elliott81ac44c2015-01-13 17:52:38 -07001042 header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>')
1043 header_txt.append('#include "loader_platform.h"')
1044 header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper.h"\n')
1045 header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;')
1046 header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n')
1047 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
1048 header_txt.append('static int printLockInitialized = 0;')
1049 header_txt.append('static loader_platform_thread_mutex printLock;\n')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -07001050 header_txt.append('#define MAX_TID 513')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001051 header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -07001052 header_txt.append('static uint32_t maxTID = 0;')
1053 header_txt.append('// Map actual TID to an index value and return that index')
1054 header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs')
1055 header_txt.append('static uint32_t getTIDIndex() {')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001056 header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -07001057 header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {')
1058 header_txt.append(' if (tid == tidMapping[i])')
1059 header_txt.append(' return i;')
1060 header_txt.append(' }')
1061 header_txt.append(" // Don't yet have mapping, set it and return newly set index")
Ian Elliott81ac44c2015-01-13 17:52:38 -07001062 header_txt.append(' uint32_t retVal = (uint32_t) maxTID;')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -07001063 header_txt.append(' tidMapping[maxTID++] = tid;')
1064 header_txt.append(' assert(maxTID < MAX_TID);')
1065 header_txt.append(' return retVal;')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001066 header_txt.append('}\n')
1067 header_txt.append('static FILE* pOutFile;\nstatic char* outFileName = "xgl_apidump.txt";')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -07001068 return "\n".join(header_txt)
Tobin Ehlis574b0142014-11-12 13:11:15 -07001069
1070 def generate_body(self):
Ian Elliott81ac44c2015-01-13 17:52:38 -07001071 body = [self._generate_layer_dispatch_table_with_lock(),
Tobin Ehlis907a0522014-11-25 16:59:27 -07001072 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDumpFile"),
Tobin Ehlis574b0142014-11-12 13:11:15 -07001073 self._generate_layer_gpa_function()]
1074
1075 return "\n\n".join(body)
1076
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -07001077class ApiDumpNoAddrSubcommand(Subcommand):
1078 def generate_header(self):
1079 header_txt = []
Ian Elliott81ac44c2015-01-13 17:52:38 -07001080 header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>')
1081 header_txt.append('#include "loader_platform.h"')
1082 header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper_no_addr.h"\n')
1083 header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;')
1084 header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n')
1085 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
1086 header_txt.append('static int printLockInitialized = 0;')
1087 header_txt.append('static loader_platform_thread_mutex printLock;\n')
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -07001088 header_txt.append('#define MAX_TID 513')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001089 header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};')
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -07001090 header_txt.append('static uint32_t maxTID = 0;')
1091 header_txt.append('// Map actual TID to an index value and return that index')
1092 header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs')
1093 header_txt.append('static uint32_t getTIDIndex() {')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001094 header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();')
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -07001095 header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {')
1096 header_txt.append(' if (tid == tidMapping[i])')
1097 header_txt.append(' return i;')
1098 header_txt.append(' }')
1099 header_txt.append(" // Don't yet have mapping, set it and return newly set index")
Ian Elliott81ac44c2015-01-13 17:52:38 -07001100 header_txt.append(' uint32_t retVal = (uint32_t) maxTID;')
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -07001101 header_txt.append(' tidMapping[maxTID++] = tid;')
1102 header_txt.append(' assert(maxTID < MAX_TID);')
1103 header_txt.append(' return retVal;')
1104 header_txt.append('}')
1105 return "\n".join(header_txt)
1106
1107 def generate_body(self):
Ian Elliott81ac44c2015-01-13 17:52:38 -07001108 body = [self._generate_layer_dispatch_table_with_lock(),
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -07001109 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDump", True),
1110 self._generate_layer_gpa_function()]
1111
1112 return "\n\n".join(body)
1113
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001114class ApiDumpNoAddrCppSubcommand(Subcommand):
1115 def generate_header(self):
1116 header_txt = []
Ian Elliott81ac44c2015-01-13 17:52:38 -07001117 header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>')
1118 header_txt.append('#include "loader_platform.h"')
1119 header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper_no_addr_cpp.h"\n')
1120 header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;')
1121 header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n')
1122 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
1123 header_txt.append('static int printLockInitialized = 0;')
1124 header_txt.append('static loader_platform_thread_mutex printLock;\n')
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001125 header_txt.append('#define MAX_TID 513')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001126 header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};')
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001127 header_txt.append('static uint32_t maxTID = 0;')
1128 header_txt.append('// Map actual TID to an index value and return that index')
1129 header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs')
1130 header_txt.append('static uint32_t getTIDIndex() {')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001131 header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();')
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001132 header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {')
1133 header_txt.append(' if (tid == tidMapping[i])')
1134 header_txt.append(' return i;')
1135 header_txt.append(' }')
1136 header_txt.append(" // Don't yet have mapping, set it and return newly set index")
Ian Elliott81ac44c2015-01-13 17:52:38 -07001137 header_txt.append(' uint32_t retVal = (uint32_t) maxTID;')
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001138 header_txt.append(' tidMapping[maxTID++] = tid;')
1139 header_txt.append(' assert(maxTID < MAX_TID);')
1140 header_txt.append(' return retVal;')
1141 header_txt.append('}')
1142 return "\n".join(header_txt)
1143
1144 def generate_body(self):
Ian Elliott81ac44c2015-01-13 17:52:38 -07001145 body = [self._generate_layer_dispatch_table_with_lock(),
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001146 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "APIDumpCpp", True),
1147 self._generate_layer_gpa_function()]
1148
1149 return "\n\n".join(body)
1150
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001151class ObjectTrackerSubcommand(Subcommand):
1152 def generate_header(self):
1153 header_txt = []
Ian Elliott81ac44c2015-01-13 17:52:38 -07001154 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 -07001155 header_txt.append('#include "object_track.h"\n\nstatic XGL_LAYER_DISPATCH_TABLE nextTable;\nstatic XGL_BASE_LAYER_OBJECT *pCurObj;')
Ian Elliott81ac44c2015-01-13 17:52:38 -07001156 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
1157 header_txt.append('static long long unsigned int object_track_index = 0;')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001158 header_txt.append('// Ptr to LL of dbg functions')
1159 header_txt.append('static XGL_LAYER_DBG_FUNCTION_NODE *pDbgFunctionHead = NULL;')
1160 header_txt.append('// Utility function to handle reporting')
1161 header_txt.append('// If callbacks are enabled, use them, otherwise use printf')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001162 header_txt.append('static void layerCbMsg(XGL_DBG_MSG_TYPE msgType,')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001163 header_txt.append(' XGL_VALIDATION_LEVEL validationLevel,')
1164 header_txt.append(' XGL_BASE_OBJECT srcObject,')
Mark Lobodzinskid11fcca2015-02-09 10:16:20 -06001165 header_txt.append(' size_t location,')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001166 header_txt.append(' int32_t msgCode,')
Chia-I Wua837c522014-12-16 10:47:33 +08001167 header_txt.append(' const char* pLayerPrefix,')
1168 header_txt.append(' const char* pMsg)')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001169 header_txt.append('{')
1170 header_txt.append(' XGL_LAYER_DBG_FUNCTION_NODE *pTrav = pDbgFunctionHead;')
1171 header_txt.append(' if (pTrav) {')
1172 header_txt.append(' while (pTrav) {')
Chia-I Wu7461fcf2014-12-27 15:16:07 +08001173 header_txt.append(' pTrav->pfnMsgCallback(msgType, validationLevel, srcObject, location, msgCode, pMsg, pTrav->pUserData);')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001174 header_txt.append(' pTrav = pTrav->pNext;')
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001175 header_txt.append(' }')
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001176 header_txt.append(' }')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001177 header_txt.append(' else {')
1178 header_txt.append(' switch (msgType) {')
1179 header_txt.append(' case XGL_DBG_MSG_ERROR:')
1180 header_txt.append(' printf("{%s}ERROR : %s\\n", pLayerPrefix, pMsg);')
1181 header_txt.append(' break;')
1182 header_txt.append(' case XGL_DBG_MSG_WARNING:')
1183 header_txt.append(' printf("{%s}WARN : %s\\n", pLayerPrefix, pMsg);')
1184 header_txt.append(' break;')
1185 header_txt.append(' case XGL_DBG_MSG_PERF_WARNING:')
1186 header_txt.append(' printf("{%s}PERF_WARN : %s\\n", pLayerPrefix, pMsg);')
1187 header_txt.append(' break;')
1188 header_txt.append(' default:')
1189 header_txt.append(' printf("{%s}INFO : %s\\n", pLayerPrefix, pMsg);')
1190 header_txt.append(' break;')
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001191 header_txt.append(' }')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001192 header_txt.append(' }')
1193 header_txt.append('}')
1194 header_txt.append('// We maintain a "Global" list which links every object and a')
1195 header_txt.append('// per-Object list which just links objects of a given type')
1196 header_txt.append('// The object node has both pointers so the actual nodes are shared between the two lists')
1197 header_txt.append('typedef struct _objNode {')
1198 header_txt.append(' OBJTRACK_NODE obj;')
1199 header_txt.append(' struct _objNode *pNextObj;')
1200 header_txt.append(' struct _objNode *pNextGlobal;')
1201 header_txt.append('} objNode;')
1202 header_txt.append('static objNode *pObjectHead[XGL_NUM_OBJECT_TYPE] = {0};')
1203 header_txt.append('static objNode *pGlobalHead = NULL;')
1204 header_txt.append('static uint64_t numObjs[XGL_NUM_OBJECT_TYPE] = {0};')
1205 header_txt.append('static uint64_t numTotalObjs = 0;')
Mark Lobodzinskie1d3f0c2015-02-09 10:20:53 -06001206 header_txt.append('static uint32_t maxMemRefsPerSubmission = 0;')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001207 header_txt.append('// Debug function to print global list and each individual object list')
1208 header_txt.append('static void ll_print_lists()')
1209 header_txt.append('{')
1210 header_txt.append(' objNode* pTrav = pGlobalHead;')
1211 header_txt.append(' printf("=====GLOBAL OBJECT LIST (%lu total objs):\\n", numTotalObjs);')
1212 header_txt.append(' while (pTrav) {')
1213 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);')
1214 header_txt.append(' pTrav = pTrav->pNextGlobal;')
1215 header_txt.append(' }')
1216 header_txt.append(' for (uint32_t i = 0; i < XGL_NUM_OBJECT_TYPE; i++) {')
1217 header_txt.append(' pTrav = pObjectHead[i];')
1218 header_txt.append(' if (pTrav) {')
1219 header_txt.append(' printf("=====%s OBJECT LIST (%lu objs):\\n", string_XGL_OBJECT_TYPE(pTrav->obj.objType), numObjs[i]);')
1220 header_txt.append(' while (pTrav) {')
1221 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);')
1222 header_txt.append(' pTrav = pTrav->pNextObj;')
1223 header_txt.append(' }')
1224 header_txt.append(' }')
1225 header_txt.append(' }')
1226 header_txt.append('}')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001227 header_txt.append('static void ll_insert_obj(void* pObj, XGL_OBJECT_TYPE objType) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001228 header_txt.append(' char str[1024];')
1229 header_txt.append(' sprintf(str, "OBJ[%llu] : CREATE %s object %p", object_track_index++, string_XGL_OBJECT_TYPE(objType), (void*)pObj);')
1230 header_txt.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_NONE, "OBJTRACK", str);')
1231 header_txt.append(' objNode* pNewObjNode = (objNode*)malloc(sizeof(objNode));')
1232 header_txt.append(' pNewObjNode->obj.pObj = pObj;')
1233 header_txt.append(' pNewObjNode->obj.objType = objType;')
Mark Lobodzinski01552702015-02-03 10:06:31 -06001234 header_txt.append(' pNewObjNode->obj.status = OBJSTATUS_NONE;')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001235 header_txt.append(' pNewObjNode->obj.numUses = 0;')
1236 header_txt.append(' // insert at front of global list')
1237 header_txt.append(' pNewObjNode->pNextGlobal = pGlobalHead;')
1238 header_txt.append(' pGlobalHead = pNewObjNode;')
1239 header_txt.append(' // insert at front of object list')
1240 header_txt.append(' pNewObjNode->pNextObj = pObjectHead[objType];')
1241 header_txt.append(' pObjectHead[objType] = pNewObjNode;')
1242 header_txt.append(' // increment obj counts')
1243 header_txt.append(' numObjs[objType]++;')
1244 header_txt.append(' numTotalObjs++;')
1245 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 +08001246 header_txt.append(' if (0) ll_print_lists();')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001247 header_txt.append('}')
1248 header_txt.append('// Traverse global list and return type for given object')
1249 header_txt.append('static XGL_OBJECT_TYPE ll_get_obj_type(XGL_OBJECT object) {')
1250 header_txt.append(' objNode *pTrav = pGlobalHead;')
1251 header_txt.append(' while (pTrav) {')
1252 header_txt.append(' if (pTrav->obj.pObj == object)')
1253 header_txt.append(' return pTrav->obj.objType;')
1254 header_txt.append(' pTrav = pTrav->pNextGlobal;')
1255 header_txt.append(' }')
1256 header_txt.append(' char str[1024];')
1257 header_txt.append(' sprintf(str, "Attempting look-up on obj %p but it is NOT in the global list!", (void*)object);')
1258 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, object, 0, OBJTRACK_MISSING_OBJECT, "OBJTRACK", str);')
1259 header_txt.append(' return XGL_OBJECT_TYPE_UNKNOWN;')
1260 header_txt.append('}')
Chia-I Wudf142a32014-12-16 11:02:06 +08001261 header_txt.append('#if 0')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001262 header_txt.append('static uint64_t ll_get_obj_uses(void* pObj, XGL_OBJECT_TYPE objType) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001263 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
1264 header_txt.append(' while (pTrav) {')
1265 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1266 header_txt.append(' return pTrav->obj.numUses;')
1267 header_txt.append(' }')
1268 header_txt.append(' pTrav = pTrav->pNextObj;')
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001269 header_txt.append(' }')
1270 header_txt.append(' return 0;')
1271 header_txt.append('}')
Chia-I Wudf142a32014-12-16 11:02:06 +08001272 header_txt.append('#endif')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001273 header_txt.append('static void ll_increment_use_count(void* pObj, XGL_OBJECT_TYPE objType) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001274 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001275 header_txt.append(' while (pTrav) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001276 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1277 header_txt.append(' pTrav->obj.numUses++;')
1278 header_txt.append(' char str[1024];')
1279 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);')
1280 header_txt.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_NONE, "OBJTRACK", str);')
1281 header_txt.append(' return;')
1282 header_txt.append(' }')
1283 header_txt.append(' pTrav = pTrav->pNextObj;')
1284 header_txt.append(' }')
1285 header_txt.append(' // If we do not find obj, insert it and then increment count')
1286 header_txt.append(' char str[1024];')
1287 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));')
1288 header_txt.append(' layerCbMsg(XGL_DBG_MSG_WARNING, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
1289 header_txt.append('')
1290 header_txt.append(' ll_insert_obj(pObj, objType);')
1291 header_txt.append(' ll_increment_use_count(pObj, objType);')
1292 header_txt.append('}')
1293 header_txt.append('// We usually do not know Obj type when we destroy it so have to fetch')
1294 header_txt.append('// Type from global list w/ ll_destroy_obj()')
1295 header_txt.append('// and then do the full removal from both lists w/ ll_remove_obj_type()')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001296 header_txt.append('static void ll_remove_obj_type(void* pObj, XGL_OBJECT_TYPE objType) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001297 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
1298 header_txt.append(' objNode *pPrev = pObjectHead[objType];')
1299 header_txt.append(' while (pTrav) {')
1300 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1301 header_txt.append(' pPrev->pNextObj = pTrav->pNextObj;')
1302 header_txt.append(' // update HEAD of Obj list as needed')
1303 header_txt.append(' if (pObjectHead[objType] == pTrav)')
1304 header_txt.append(' pObjectHead[objType] = pTrav->pNextObj;')
1305 header_txt.append(' assert(numObjs[objType] > 0);')
1306 header_txt.append(' numObjs[objType]--;')
1307 header_txt.append(' char str[1024];')
1308 header_txt.append(' sprintf(str, "OBJ[%llu] : DESTROY %s object %p", object_track_index++, string_XGL_OBJECT_TYPE(objType), (void*)pObj);')
1309 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 -06001310 header_txt.append(' return;')
1311 header_txt.append(' }')
1312 header_txt.append(' pPrev = pTrav;')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001313 header_txt.append(' pTrav = pTrav->pNextObj;')
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001314 header_txt.append(' }')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001315 header_txt.append(' char str[1024];')
1316 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));')
1317 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_INTERNAL_ERROR, "OBJTRACK", str);')
1318 header_txt.append('}')
1319 header_txt.append('// Parse global list to find obj type, then remove obj from obj type list, finally')
1320 header_txt.append('// remove obj from global list')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001321 header_txt.append('static void ll_destroy_obj(void* pObj) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001322 header_txt.append(' objNode *pTrav = pGlobalHead;')
1323 header_txt.append(' objNode *pPrev = pGlobalHead;')
1324 header_txt.append(' while (pTrav) {')
1325 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1326 header_txt.append(' ll_remove_obj_type(pObj, pTrav->obj.objType);')
1327 header_txt.append(' pPrev->pNextGlobal = pTrav->pNextGlobal;')
1328 header_txt.append(' // update HEAD of global list if needed')
1329 header_txt.append(' if (pGlobalHead == pTrav)')
1330 header_txt.append(' pGlobalHead = pTrav->pNextGlobal;')
1331 header_txt.append(' free(pTrav);')
1332 header_txt.append(' assert(numTotalObjs > 0);')
1333 header_txt.append(' numTotalObjs--;')
1334 header_txt.append(' char str[1024];')
1335 header_txt.append(' sprintf(str, "OBJ_STAT Removed %s obj %p that was used %lu times (%lu total objs & %lu %s objs).", string_XGL_OBJECT_TYPE(pTrav->obj.objType), pTrav->obj.pObj, pTrav->obj.numUses, numTotalObjs, numObjs[pTrav->obj.objType], string_XGL_OBJECT_TYPE(pTrav->obj.objType));')
1336 header_txt.append(' layerCbMsg(XGL_DBG_MSG_UNKNOWN, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_NONE, "OBJTRACK", str);')
1337 header_txt.append(' return;')
1338 header_txt.append(' }')
1339 header_txt.append(' pPrev = pTrav;')
1340 header_txt.append(' pTrav = pTrav->pNextGlobal;')
1341 header_txt.append(' }')
1342 header_txt.append(' char str[1024];')
1343 header_txt.append(' sprintf(str, "Unable to remove obj %p. Was it created? Has it already been destroyed?", pObj);')
1344 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 -06001345 header_txt.append('}')
Tobin Ehlis235c20e2015-01-16 08:56:30 -07001346 header_txt.append('// Set selected flag state for an object node')
1347 header_txt.append('static void set_status(void* pObj, XGL_OBJECT_TYPE objType, OBJECT_STATUS status_flag) {')
Mark Lobodzinskid11fcca2015-02-09 10:16:20 -06001348 header_txt.append(' if (pObj != NULL) {')
1349 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
1350 header_txt.append(' while (pTrav) {')
1351 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1352 header_txt.append(' pTrav->obj.status |= status_flag;')
1353 header_txt.append(' return;')
1354 header_txt.append(' }')
1355 header_txt.append(' pTrav = pTrav->pNextObj;')
Tobin Ehlis235c20e2015-01-16 08:56:30 -07001356 header_txt.append(' }')
Mark Lobodzinskid11fcca2015-02-09 10:16:20 -06001357 header_txt.append(' // If we do not find it print an error')
1358 header_txt.append(' char str[1024];')
1359 header_txt.append(' sprintf(str, "Unable to set status for non-existent object %p of %s type", pObj, string_XGL_OBJECT_TYPE(objType));')
1360 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
1361 header_txt.append(' }');
Tobin Ehlis235c20e2015-01-16 08:56:30 -07001362 header_txt.append('}')
1363 header_txt.append('')
Mark Lobodzinski01552702015-02-03 10:06:31 -06001364 header_txt.append('// Track selected state for an object node')
1365 header_txt.append('static void track_object_status(void* pObj, XGL_STATE_BIND_POINT stateBindPoint) {')
1366 header_txt.append(' objNode *pTrav = pObjectHead[XGL_OBJECT_TYPE_CMD_BUFFER];')
1367 header_txt.append('')
1368 header_txt.append(' while (pTrav) {')
1369 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1370 header_txt.append(' if (stateBindPoint == XGL_STATE_BIND_VIEWPORT) {')
1371 header_txt.append(' pTrav->obj.status |= OBJSTATUS_VIEWPORT_BOUND;')
1372 header_txt.append(' } else if (stateBindPoint == XGL_STATE_BIND_RASTER) {')
1373 header_txt.append(' pTrav->obj.status |= OBJSTATUS_RASTER_BOUND;')
1374 header_txt.append(' } else if (stateBindPoint == XGL_STATE_BIND_COLOR_BLEND) {')
1375 header_txt.append(' pTrav->obj.status |= OBJSTATUS_COLOR_BLEND_BOUND;')
1376 header_txt.append(' } else if (stateBindPoint == XGL_STATE_BIND_DEPTH_STENCIL) {')
1377 header_txt.append(' pTrav->obj.status |= OBJSTATUS_DEPTH_STENCIL_BOUND;')
1378 header_txt.append(' }')
1379 header_txt.append(' return;')
1380 header_txt.append(' }')
1381 header_txt.append(' pTrav = pTrav->pNextObj;')
1382 header_txt.append(' }')
1383 header_txt.append(' // If we do not find it print an error')
1384 header_txt.append(' char str[1024];')
1385 header_txt.append(' sprintf(str, "Unable to track status for non-existent Command Buffer object %p", pObj);')
1386 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
1387 header_txt.append('}')
1388 header_txt.append('')
1389 header_txt.append('// Reset selected flag state for an object node')
1390 header_txt.append('static void reset_status(void* pObj, XGL_OBJECT_TYPE objType, OBJECT_STATUS status_flag) {')
Tobin Ehlis235c20e2015-01-16 08:56:30 -07001391 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
1392 header_txt.append(' while (pTrav) {')
1393 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
Mark Lobodzinski01552702015-02-03 10:06:31 -06001394 header_txt.append(' pTrav->obj.status &= ~status_flag;')
1395 header_txt.append(' return;')
1396 header_txt.append(' }')
1397 header_txt.append(' pTrav = pTrav->pNextObj;')
1398 header_txt.append(' }')
1399 header_txt.append(' // If we do not find it print an error')
1400 header_txt.append(' char str[1024];')
1401 header_txt.append(' sprintf(str, "Unable to reset status for non-existent object %p of %s type", pObj, string_XGL_OBJECT_TYPE(objType));')
1402 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
1403 header_txt.append('}')
1404 header_txt.append('')
1405 header_txt.append('// Check object status for selected flag state')
Mark Lobodzinski4186e712015-02-03 11:52:26 -06001406 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 -06001407 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
1408 header_txt.append(' while (pTrav) {')
1409 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
Mark Lobodzinski4186e712015-02-03 11:52:26 -06001410 header_txt.append(' if ((pTrav->obj.status & status_mask) != status_flag) {')
Tobin Ehlis235c20e2015-01-16 08:56:30 -07001411 header_txt.append(' char str[1024];')
1412 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 -06001413 header_txt.append(' layerCbMsg(error_level, XGL_VALIDATION_LEVEL_0, pObj, 0, error_code, "OBJTRACK", str);')
Tobin Ehlis235c20e2015-01-16 08:56:30 -07001414 header_txt.append(' }')
1415 header_txt.append(' return;')
1416 header_txt.append(' }')
1417 header_txt.append(' pTrav = pTrav->pNextObj;')
1418 header_txt.append(' }')
1419 header_txt.append(' // If we do not find it print an error')
1420 header_txt.append(' char str[1024];')
1421 header_txt.append(' sprintf(str, "Unable to obtain status for non-existent object %p of %s type", pObj, string_XGL_OBJECT_TYPE(objType));')
1422 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
1423 header_txt.append('}')
Mark Lobodzinski01552702015-02-03 10:06:31 -06001424 header_txt.append('')
1425 header_txt.append('static void validate_draw_state_flags(void* pObj) {')
Mark Lobodzinski4186e712015-02-03 11:52:26 -06001426 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");')
1427 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");')
1428 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");')
1429 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");')
1430 header_txt.append('}')
1431 header_txt.append('')
1432 header_txt.append('static void validate_memory_mapping_status(const XGL_MEMORY_REF* pMemRefs, uint32_t numRefs) {')
Ian Elliotteac469b2015-02-04 12:15:12 -07001433 header_txt.append(' uint32_t i;')
Mark Lobodzinski4186e712015-02-03 11:52:26 -06001434 header_txt.append(' for (i = 0; i < numRefs; i++) {')
1435 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");')
1436 header_txt.append(' }')
Mark Lobodzinski01552702015-02-03 10:06:31 -06001437 header_txt.append('}')
Mark Lobodzinskie1d3f0c2015-02-09 10:20:53 -06001438 header_txt.append('')
1439 header_txt.append('static void validate_mem_ref_count(uint32_t numRefs) {')
1440 header_txt.append(' if (maxMemRefsPerSubmission == 0) {')
1441 header_txt.append(' char str[1024];')
1442 header_txt.append(' sprintf(str, "xglQueueSubmit called before calling xglGetGpuInfo");')
1443 header_txt.append(' layerCbMsg(XGL_DBG_MSG_WARNING, XGL_VALIDATION_LEVEL_0, NULL, 0, OBJTRACK_GETGPUINFO_NOT_CALLED, "OBJTRACK", str);')
1444 header_txt.append(' } else {')
1445 header_txt.append(' if (numRefs > maxMemRefsPerSubmission) {')
1446 header_txt.append(' char str[1024];')
1447 header_txt.append(' sprintf(str, "xglQueueSubmit Memory reference count (%d) exceeds allowable GPU limit (%d)", numRefs, maxMemRefsPerSubmission);')
1448 header_txt.append(' layerCbMsg(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, OBJTRACK_MEMREFCOUNT_MAX_EXCEEDED, "OBJTRACK", str);')
1449 header_txt.append(' }')
1450 header_txt.append(' }')
1451 header_txt.append('}')
1452 header_txt.append('')
1453 header_txt.append('static void setGpuInfoState(void *pData) {')
1454 header_txt.append(' maxMemRefsPerSubmission = ((XGL_PHYSICAL_GPU_PROPERTIES *)pData)->maxMemRefsPerSubmission;')
1455 header_txt.append('}')
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001456 return "\n".join(header_txt)
1457
1458 def generate_body(self):
1459 body = [self._generate_layer_dispatch_table(),
Tobin Ehlis907a0522014-11-25 16:59:27 -07001460 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "ObjectTracker"),
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001461 self._generate_extensions(),
1462 self._generate_layer_gpa_function(extensions=['objTrackGetObjectCount', 'objTrackGetObjects'])]
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001463
1464 return "\n\n".join(body)
Courtney Goeltzenleuchtere6094fc2014-11-18 10:40:29 -07001465
Tobin Ehlis6cd06372014-12-17 17:44:50 -07001466class ParamCheckerSubcommand(Subcommand):
1467 def generate_header(self):
Ian Elliott81ac44c2015-01-13 17:52:38 -07001468 return '#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include "loader_platform.h"\n#include "xglLayer.h"\n#include "xgl_enum_validate_helper.h"\n#include "xgl_struct_validate_helper.h"\n\nstatic XGL_LAYER_DISPATCH_TABLE nextTable;\nstatic XGL_BASE_LAYER_OBJECT *pCurObj;\nstatic LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);\n\n'
Tobin Ehlis6cd06372014-12-17 17:44:50 -07001469
1470 def generate_body(self):
1471 body = [self._gen_layer_dbg_callback_header(),
1472 self._generate_layer_dispatch_table(),
1473 self._generate_dispatch_entrypoints("XGL_LAYER_EXPORT", "ParamChecker"),
1474 self._generate_layer_gpa_function()]
1475
1476 return "\n\n".join(body)
1477
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001478def main():
1479 subcommands = {
1480 "layer-funcs" : LayerFuncsSubcommand,
1481 "layer-dispatch" : LayerDispatchSubcommand,
Tobin Ehlis907a0522014-11-25 16:59:27 -07001482 "Generic" : GenericLayerSubcommand,
1483 "ApiDump" : ApiDumpSubcommand,
1484 "ApiDumpFile" : ApiDumpFileSubcommand,
Tobin Ehlis07fe9ab2014-11-25 17:43:26 -07001485 "ApiDumpNoAddr" : ApiDumpNoAddrSubcommand,
Tobin Ehlis434db7c2015-01-10 12:42:41 -07001486 "ApiDumpCpp" : ApiDumpCppSubcommand,
1487 "ApiDumpNoAddrCpp" : ApiDumpNoAddrCppSubcommand,
Tobin Ehlis907a0522014-11-25 16:59:27 -07001488 "ObjectTracker" : ObjectTrackerSubcommand,
Tobin Ehlis6cd06372014-12-17 17:44:50 -07001489 "ParamChecker" : ParamCheckerSubcommand,
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001490 }
1491
Tobin Ehlis6cd06372014-12-17 17:44:50 -07001492 if len(sys.argv) < 3 or sys.argv[1] not in subcommands or not os.path.exists(sys.argv[2]):
1493 print("Usage: %s <subcommand> <input_header> [options]" % sys.argv[0])
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001494 print
Tobin Ehlis2f3726c2015-01-15 17:51:52 -07001495 print("Available subcommands are: %s" % " ".join(subcommands))
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001496 exit(1)
1497
Tobin Ehlis6cd06372014-12-17 17:44:50 -07001498 hfp = xgl_helper.HeaderFileParser(sys.argv[2])
1499 hfp.parse()
1500 xgl_helper.enum_val_dict = hfp.get_enum_val_dict()
1501 xgl_helper.enum_type_dict = hfp.get_enum_type_dict()
1502 xgl_helper.struct_dict = hfp.get_struct_dict()
1503 xgl_helper.typedef_fwd_dict = hfp.get_typedef_fwd_dict()
1504 xgl_helper.typedef_rev_dict = hfp.get_typedef_rev_dict()
1505 xgl_helper.types_dict = hfp.get_types_dict()
1506
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001507 subcmd = subcommands[sys.argv[1]](sys.argv[2:])
1508 subcmd.run()
1509
1510if __name__ == "__main__":
1511 main()