Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 3 | # VK |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 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 | |
| 28 | import sys |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 29 | import os |
Mark Lobodzinski | 7c75b85 | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 30 | import re |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 31 | |
Courtney Goeltzenleuchter | f53c3cb | 2015-04-14 14:55:44 -0600 | [diff] [blame] | 32 | import vulkan |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 33 | import vk_helper |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 34 | from source_line_info import sourcelineinfo |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 35 | from collections import defaultdict |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 36 | |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 37 | def proto_is_global(proto): |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 38 | if proto.params[0].ty == "VkInstance" or proto.params[0].ty == "VkPhysicalDevice" or proto.name == "CreateInstance" or proto.name == "GetGlobalLayerProperties" or proto.name == "GetGlobalExtensionProperties" or proto.name == "GetPhysicalDeviceLayerProperties" or proto.name == "GetPhysicalDeviceExtensionProperties": |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 39 | return True |
| 40 | else: |
| 41 | return False |
| 42 | |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 43 | def generate_get_proc_addr_check(name): |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 44 | return " if (!%s || %s[0] != 'v' || %s[1] != 'k')\n" \ |
| 45 | " return NULL;" % ((name,) * 3) |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 46 | |
Mark Lobodzinski | 7c75b85 | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 47 | def ucc_to_U_C_C(CamelCase): |
| 48 | temp = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', CamelCase) |
| 49 | return re.sub('([a-z0-9])([A-Z])', r'\1_\2', temp).upper() |
| 50 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 51 | class Subcommand(object): |
| 52 | def __init__(self, argv): |
| 53 | self.argv = argv |
Courtney Goeltzenleuchter | f53c3cb | 2015-04-14 14:55:44 -0600 | [diff] [blame] | 54 | self.headers = vulkan.headers |
| 55 | self.protos = vulkan.protos |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 56 | self.no_addr = False |
| 57 | self.layer_name = "" |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 58 | self.lineinfo = sourcelineinfo() |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 59 | |
| 60 | def run(self): |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 61 | print(self.generate()) |
| 62 | |
| 63 | def generate(self): |
| 64 | copyright = self.generate_copyright() |
| 65 | header = self.generate_header() |
| 66 | body = self.generate_body() |
| 67 | footer = self.generate_footer() |
| 68 | |
| 69 | contents = [] |
| 70 | if copyright: |
| 71 | contents.append(copyright) |
| 72 | if header: |
| 73 | contents.append(header) |
| 74 | if body: |
| 75 | contents.append(body) |
| 76 | if footer: |
| 77 | contents.append(footer) |
| 78 | |
| 79 | return "\n\n".join(contents) |
| 80 | |
| 81 | def generate_copyright(self): |
| 82 | return """/* THIS FILE IS GENERATED. DO NOT EDIT. */ |
| 83 | |
| 84 | /* |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 85 | * Vulkan |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 86 | * |
| 87 | * Copyright (C) 2014 LunarG, Inc. |
| 88 | * |
| 89 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 90 | * copy of this software and associated documentation files (the "Software"), |
| 91 | * to deal in the Software without restriction, including without limitation |
| 92 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 93 | * and/or sell copies of the Software, and to permit persons to whom the |
| 94 | * Software is furnished to do so, subject to the following conditions: |
| 95 | * |
| 96 | * The above copyright notice and this permission notice shall be included |
| 97 | * in all copies or substantial portions of the Software. |
| 98 | * |
| 99 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 100 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 101 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 102 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 103 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 104 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 105 | * DEALINGS IN THE SOFTWARE. |
| 106 | */""" |
| 107 | |
| 108 | def generate_header(self): |
| 109 | return "\n".join(["#include <" + h + ">" for h in self.headers]) |
| 110 | |
| 111 | def generate_body(self): |
| 112 | pass |
| 113 | |
| 114 | def generate_footer(self): |
| 115 | pass |
| 116 | |
| 117 | # Return set of printf '%' qualifier and input to that qualifier |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 118 | def _get_printf_params(self, vk_type, name, output_param, cpp=False): |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 119 | # TODO : Need ENUM and STRUCT checks here |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 120 | if vk_helper.is_type(vk_type, 'enum'):#"_TYPE" in vk_type: # TODO : This should be generic ENUM check |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 121 | return ("%s", "string_%s(%s)" % (vk_type.replace('const ', '').strip('*'), name)) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 122 | if "char*" == vk_type: |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 123 | return ("%s", name) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 124 | if "uint64" in vk_type: |
| 125 | if '*' in vk_type: |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 126 | return ("%lu", "*%s" % name) |
| 127 | return ("%lu", name) |
Tobin Ehlis | a30e7e5 | 2015-07-06 14:02:36 -0600 | [diff] [blame] | 128 | if vk_type.strip('*') in vulkan.object_non_dispatch_list: |
| 129 | if '*' in vk_type: |
| 130 | return ("%lu", "%s->handle" % name) |
| 131 | return ("%lu", "%s.handle" % name) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 132 | if "size" in vk_type: |
| 133 | if '*' in vk_type: |
Chia-I Wu | 99ff89d | 2014-12-27 14:14:50 +0800 | [diff] [blame] | 134 | return ("%zu", "*%s" % name) |
| 135 | return ("%zu", name) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 136 | if "float" in vk_type: |
| 137 | if '[' in vk_type: # handle array, current hard-coded to 4 (TODO: Make this dynamic) |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 138 | if cpp: |
| 139 | return ("[%i, %i, %i, %i]", '"[" << %s[0] << "," << %s[1] << "," << %s[2] << "," << %s[3] << "]"' % (name, name, name, name)) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 140 | return ("[%f, %f, %f, %f]", "%s[0], %s[1], %s[2], %s[3]" % (name, name, name, name)) |
| 141 | return ("%f", name) |
Courtney Goeltzenleuchter | cd2a099 | 2015-07-09 11:44:38 -0600 | [diff] [blame] | 142 | if "bool" in vk_type.lower() or 'xcb_randr_crtc_t' in vk_type: |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 143 | return ("%u", name) |
Tobin Ehlis | b870cbb | 2015-04-15 07:46:12 -0600 | [diff] [blame] | 144 | if True in [t in vk_type.lower() for t in ["int", "flags", "mask", "xcb_window_t"]]: |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 145 | if '[' in vk_type: # handle array, current hard-coded to 4 (TODO: Make this dynamic) |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 146 | if cpp: |
| 147 | return ("[%i, %i, %i, %i]", "%s[0] << %s[1] << %s[2] << %s[3]" % (name, name, name, name)) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 148 | return ("[%i, %i, %i, %i]", "%s[0], %s[1], %s[2], %s[3]" % (name, name, name, name)) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 149 | if '*' in vk_type: |
Tobin Ehlis | d2b88e8 | 2015-02-04 15:15:11 -0700 | [diff] [blame] | 150 | if 'pUserData' == name: |
| 151 | return ("%i", "((pUserData == 0) ? 0 : *(pUserData))") |
Tobin Ehlis | c62cb89 | 2015-04-17 13:26:33 -0600 | [diff] [blame] | 152 | if 'const' in vk_type.lower(): |
| 153 | return ("%p", "(void*)(%s)" % name) |
Jon Ashburn | 52f79b5 | 2014-12-12 16:10:45 -0700 | [diff] [blame] | 154 | return ("%i", "*(%s)" % name) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 155 | return ("%i", name) |
Tobin Ehlis | 3a1cc8d | 2014-11-11 17:28:22 -0700 | [diff] [blame] | 156 | # TODO : This is special-cased as there's only one "format" param currently and it's nice to expand it |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 157 | if "VkFormat" == vk_type: |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 158 | if cpp: |
| 159 | return ("%p", "&%s" % name) |
Courtney Goeltzenleuchter | c729b3a | 2015-07-12 12:40:29 -0600 | [diff] [blame] | 160 | return ("{%s.channelFormat = %%s, %s.numericFormat = %%s}" % (name, name), "string_VK_CHANNEL_FORMAT(%s.channelFormat), string_VK_FORMAT_NUM(%s.numericFormat)" % (name, name)) |
Tobin Ehlis | e727157 | 2014-11-19 15:52:46 -0700 | [diff] [blame] | 161 | if output_param: |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 162 | return ("%p", "(void*)*%s" % name) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 163 | if vk_helper.is_type(vk_type, 'struct') and '*' not in vk_type: |
Courtney Goeltzenleuchter | d462fba | 2015-04-03 16:35:32 -0600 | [diff] [blame] | 164 | return ("%p", "(void*)(&%s)" % name) |
Jon Ashburn | 52f79b5 | 2014-12-12 16:10:45 -0700 | [diff] [blame] | 165 | return ("%p", "(void*)(%s)" % name) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 166 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 167 | def _gen_create_msg_callback(self): |
Tobin Ehlis | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 168 | r_body = [] |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 169 | r_body.append('%s' % self.lineinfo.get()) |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 170 | r_body.append('VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(VkInstance instance, VkFlags msgFlags, const PFN_vkDbgMsgCallback pfnMsgCallback, void* pUserData, VkDbgMsgCallback* pMsgCallback)') |
Tobin Ehlis | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 171 | r_body.append('{') |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 172 | # Switch to this code section for the new per-instance storage and debug callbacks |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 173 | if self.layer_name == 'ObjectTracker' or self.layer_name == 'Threading': |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 174 | r_body.append(' VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(%s_instance_table_map, instance);' % self.layer_name ) |
| 175 | r_body.append(' VkResult result = pInstanceTable->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);') |
| 176 | r_body.append(' if (VK_SUCCESS == result) {') |
| 177 | r_body.append(' layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);') |
| 178 | r_body.append(' result = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);') |
| 179 | r_body.append(' }') |
| 180 | r_body.append(' return result;') |
| 181 | else: |
| 182 | # Old version of callbacks for compatibility |
| 183 | r_body.append(' return layer_create_msg_callback(instance, instance_dispatch_table(instance), msgFlags, pfnMsgCallback, pUserData, pMsgCallback);') |
Tobin Ehlis | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 184 | r_body.append('}') |
| 185 | return "\n".join(r_body) |
| 186 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 187 | def _gen_destroy_msg_callback(self): |
| 188 | r_body = [] |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 189 | r_body.append('%s' % self.lineinfo.get()) |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 190 | r_body.append('VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(VkInstance instance, VkDbgMsgCallback msgCallback)') |
| 191 | r_body.append('{') |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 192 | # Switch to this code section for the new per-instance storage and debug callbacks |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 193 | if self.layer_name == 'ObjectTracker' or self.layer_name == 'Threading': |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 194 | r_body.append(' VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(%s_instance_table_map, instance);' % self.layer_name ) |
| 195 | r_body.append(' VkResult result = pInstanceTable->DbgDestroyMsgCallback(instance, msgCallback);') |
| 196 | r_body.append(' layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);') |
| 197 | r_body.append(' layer_destroy_msg_callback(my_data->report_data, msgCallback);') |
| 198 | r_body.append(' return result;') |
| 199 | else: |
| 200 | # Old version of callbacks for compatibility |
| 201 | r_body.append(' return layer_destroy_msg_callback(instance, instance_dispatch_table(instance), msgCallback);') |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 202 | r_body.append('}') |
| 203 | return "\n".join(r_body) |
Tobin Ehlis | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 204 | |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 205 | def _gen_layer_get_global_extension_props(self, layer="Generic"): |
| 206 | ggep_body = [] |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 207 | # generated layers do not provide any global extensions |
| 208 | ggep_body.append('%s' % self.lineinfo.get()) |
| 209 | |
| 210 | ggep_body.append('') |
| 211 | ggep_body.append('VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionProperties(const char *pLayerName, uint32_t *pCount, VkExtensionProperties* pProperties)') |
| 212 | ggep_body.append('{') |
| 213 | ggep_body.append(' return util_GetExtensionProperties(0, NULL, pCount, pProperties);') |
| 214 | ggep_body.append('}') |
| 215 | return "\n".join(ggep_body) |
| 216 | |
| 217 | def _gen_layer_get_global_layer_props(self, layer="Generic"): |
| 218 | ggep_body = [] |
| 219 | if layer == 'Generic': |
| 220 | # Do nothing, extension definition part of generic.h |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 221 | ggep_body.append('%s' % self.lineinfo.get()) |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 222 | else: |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 223 | ggep_body.append('%s' % self.lineinfo.get()) |
Courtney Goeltzenleuchter | 79a5a96 | 2015-07-07 17:51:45 -0600 | [diff] [blame] | 224 | ggep_body.append('static const VkLayerProperties globalLayerProps[] = {') |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 225 | ggep_body.append(' {') |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 226 | ggep_body.append(' "%s",' % layer) |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 227 | ggep_body.append(' VK_API_VERSION, // specVersion') |
| 228 | ggep_body.append(' VK_MAKE_VERSION(0, 1, 0), // implVersion') |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 229 | ggep_body.append(' "layer: %s",' % layer) |
| 230 | ggep_body.append(' }') |
| 231 | ggep_body.append('};') |
| 232 | ggep_body.append('') |
| 233 | ggep_body.append('%s' % self.lineinfo.get()) |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 234 | ggep_body.append('') |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 235 | ggep_body.append('VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalLayerProperties(uint32_t *pCount, VkLayerProperties* pProperties)') |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 236 | ggep_body.append('{') |
Courtney Goeltzenleuchter | 79a5a96 | 2015-07-07 17:51:45 -0600 | [diff] [blame] | 237 | ggep_body.append(' return util_GetLayerProperties(ARRAY_SIZE(globalLayerProps), globalLayerProps, pCount, pProperties);') |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 238 | ggep_body.append('}') |
| 239 | return "\n".join(ggep_body) |
| 240 | |
Courtney Goeltzenleuchter | 3f9f7c4 | 2015-07-06 09:11:12 -0600 | [diff] [blame] | 241 | def _gen_layer_get_physical_device_layer_props(self, layer="Generic"): |
| 242 | gpdlp_body = [] |
| 243 | if layer == 'Generic': |
| 244 | # Do nothing, extension definition part of generic.h |
| 245 | gpdlp_body.append('%s' % self.lineinfo.get()) |
| 246 | else: |
| 247 | gpdlp_body.append('%s' % self.lineinfo.get()) |
Courtney Goeltzenleuchter | 79a5a96 | 2015-07-07 17:51:45 -0600 | [diff] [blame] | 248 | gpdlp_body.append('static const VkLayerProperties deviceLayerProps[] = {') |
Courtney Goeltzenleuchter | 3f9f7c4 | 2015-07-06 09:11:12 -0600 | [diff] [blame] | 249 | gpdlp_body.append(' {') |
| 250 | gpdlp_body.append(' "%s",' % layer) |
| 251 | gpdlp_body.append(' VK_API_VERSION,') |
| 252 | gpdlp_body.append(' VK_MAKE_VERSION(0, 1, 0),') |
| 253 | gpdlp_body.append(' "layer: %s",' % layer) |
| 254 | gpdlp_body.append(' }') |
| 255 | gpdlp_body.append('};') |
| 256 | gpdlp_body.append('VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount, VkLayerProperties* pProperties)') |
| 257 | gpdlp_body.append('{') |
Courtney Goeltzenleuchter | 79a5a96 | 2015-07-07 17:51:45 -0600 | [diff] [blame] | 258 | gpdlp_body.append(' return util_GetLayerProperties(ARRAY_SIZE(deviceLayerProps), deviceLayerProps, pCount, pProperties);') |
Courtney Goeltzenleuchter | 3f9f7c4 | 2015-07-06 09:11:12 -0600 | [diff] [blame] | 259 | gpdlp_body.append('}') |
| 260 | gpdlp_body.append('') |
| 261 | return "\n".join(gpdlp_body) |
| 262 | |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 263 | def _generate_dispatch_entrypoints(self, qual=""): |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 264 | if qual: |
| 265 | qual += " " |
| 266 | |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 267 | funcs = [] |
| 268 | intercepted = [] |
| 269 | for proto in self.protos: |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 270 | if proto.name == "GetDeviceProcAddr" or proto.name == "GetInstanceProcAddr": |
Jon Ashburn | 8fd0825 | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 271 | continue |
Mike Stroyan | 70c05e8 | 2015-04-08 10:27:43 -0600 | [diff] [blame] | 272 | else: |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 273 | intercept = self.generate_intercept(proto, qual) |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 274 | if intercept is None: |
| 275 | # fill in default intercept for certain entrypoints |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 276 | if 'DbgCreateMsgCallback' == proto.name: |
| 277 | intercept = self._gen_layer_dbg_create_msg_callback() |
| 278 | elif 'DbgDestroyMsgCallback' == proto.name: |
| 279 | intercept = self._gen_layer_dbg_destroy_msg_callback() |
| 280 | elif 'CreateDevice' == proto.name: |
| 281 | funcs.append('/* CreateDevice HERE */') |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 282 | elif 'GetGlobalExtensionProperties' == proto.name: |
| 283 | intercept = self._gen_layer_get_global_extension_props(self.layer_name) |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 284 | elif 'GetGlobalLayerProperties' == proto.name: |
| 285 | intercept = self._gen_layer_get_global_layer_props(self.layer_name) |
| 286 | elif 'GetPhysicalDeviceLayerProperties' == proto.name: |
| 287 | intercept = self._gen_layer_get_physical_device_layer_props(self.layer_name) |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 288 | |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 289 | if intercept is not None: |
| 290 | funcs.append(intercept) |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 291 | if not "KHR" in proto.name: |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 292 | intercepted.append(proto) |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 293 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 294 | prefix="vk" |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 295 | lookups = [] |
| 296 | for proto in intercepted: |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 297 | lookups.append("if (!strcmp(name, \"%s\"))" % proto.name) |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 298 | lookups.append(" return (PFN_vkVoidFunction) %s%s;" % |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 299 | (prefix, proto.name)) |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 300 | |
| 301 | # add customized layer_intercept_proc |
| 302 | body = [] |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 303 | body.append('%s' % self.lineinfo.get()) |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 304 | body.append("static inline PFN_vkVoidFunction layer_intercept_proc(const char *name)") |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 305 | body.append("{") |
| 306 | body.append(generate_get_proc_addr_check("name")) |
| 307 | body.append("") |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 308 | body.append(" name += 2;") |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 309 | body.append(" %s" % "\n ".join(lookups)) |
| 310 | body.append("") |
| 311 | body.append(" return NULL;") |
| 312 | body.append("}") |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 313 | # add layer_intercept_instance_proc |
| 314 | lookups = [] |
| 315 | for proto in self.protos: |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 316 | if not proto_is_global(proto): |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 317 | continue |
| 318 | |
| 319 | if not proto in intercepted: |
| 320 | continue |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 321 | if proto.name == "CreateDevice": |
| 322 | continue |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 323 | lookups.append("if (!strcmp(name, \"%s\"))" % proto.name) |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 324 | lookups.append(" return (PFN_vkVoidFunction) %s%s;" % (prefix, proto.name)) |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 325 | |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 326 | body.append("static inline PFN_vkVoidFunction layer_intercept_instance_proc(const char *name)") |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 327 | body.append("{") |
| 328 | body.append(generate_get_proc_addr_check("name")) |
| 329 | body.append("") |
| 330 | body.append(" name += 2;") |
| 331 | body.append(" %s" % "\n ".join(lookups)) |
| 332 | body.append("") |
| 333 | body.append(" return NULL;") |
| 334 | body.append("}") |
| 335 | |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 336 | funcs.append("\n".join(body)) |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 337 | return "\n\n".join(funcs) |
| 338 | |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 339 | def _generate_extensions(self): |
| 340 | exts = [] |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 341 | exts.append('%s' % self.lineinfo.get()) |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 342 | exts.append(self._gen_create_msg_callback()) |
| 343 | exts.append(self._gen_destroy_msg_callback()) |
Tobin Ehlis | b870cbb | 2015-04-15 07:46:12 -0600 | [diff] [blame] | 344 | return "\n".join(exts) |
| 345 | |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 346 | def _generate_layer_gpa_function(self, extensions=[], instance_extensions=[]): |
Jon Ashburn | bacb0f5 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 347 | func_body = [] |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 348 | # |
Courtney Goeltzenleuchter | 3f9f7c4 | 2015-07-06 09:11:12 -0600 | [diff] [blame] | 349 | # New style of GPA Functions for the new layer_data/layer_logging changes |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 350 | # |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 351 | if self.layer_name == 'ObjectTracker' or self.layer_name == 'Threading': |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 352 | func_body.append("VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice device, const char* funcName)\n" |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 353 | "{\n" |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 354 | " PFN_vkVoidFunction addr;\n" |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 355 | " if (device == VK_NULL_HANDLE) {\n" |
| 356 | " return NULL;\n" |
| 357 | " }\n" |
| 358 | " /* loader uses this to force layer initialization; device object is wrapped */\n" |
| 359 | " if (!strcmp(\"vkGetDeviceProcAddr\", funcName)) {\n" |
| 360 | " initDeviceTable(%s_device_table_map, (const VkBaseLayerObject *) device);\n" |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 361 | " return (PFN_vkVoidFunction) vkGetDeviceProcAddr;\n" |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 362 | " }\n\n" |
| 363 | " addr = layer_intercept_proc(funcName);\n" |
| 364 | " if (addr)\n" |
| 365 | " return addr;" % self.layer_name) |
| 366 | if 0 != len(extensions): |
Courtney Goeltzenleuchter | 3f9f7c4 | 2015-07-06 09:11:12 -0600 | [diff] [blame] | 367 | func_body.append('%s' % self.lineinfo.get()) |
| 368 | func_body.append(' layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);') |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 369 | for (ext_enable, ext_list) in extensions: |
| 370 | extra_space = "" |
| 371 | if 0 != len(ext_enable): |
Courtney Goeltzenleuchter | 3f9f7c4 | 2015-07-06 09:11:12 -0600 | [diff] [blame] | 372 | func_body.append(' if (my_device_data->%s) {' % ext_enable) |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 373 | extra_space = " " |
| 374 | for ext_name in ext_list: |
| 375 | func_body.append(' %sif (!strcmp("%s", funcName))\n' |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 376 | ' %sreturn reinterpret_cast<PFN_vkVoidFunction>(%s);' % (extra_space, ext_name, extra_space, ext_name)) |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 377 | if 0 != len(ext_enable): |
| 378 | func_body.append(' }\n') |
| 379 | func_body.append("\n if (get_dispatch_table(%s_device_table_map, device)->GetDeviceProcAddr == NULL)\n" |
| 380 | " return NULL;\n" |
| 381 | " return get_dispatch_table(%s_device_table_map, device)->GetDeviceProcAddr(device, funcName);\n" |
| 382 | "}\n" % (self.layer_name, self.layer_name)) |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 383 | func_body.append("VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)\n" |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 384 | "{\n" |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 385 | " PFN_vkVoidFunction addr;\n" |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 386 | " if (instance == VK_NULL_HANDLE) {\n" |
| 387 | " return NULL;\n" |
| 388 | " }\n" |
| 389 | " /* loader uses this to force layer initialization; instance object is wrapped */\n" |
| 390 | " if (!strcmp(\"vkGetInstanceProcAddr\", funcName)) {\n" |
| 391 | " initInstanceTable(%s_instance_table_map, (const VkBaseLayerObject *) instance);\n" |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 392 | " return (PFN_vkVoidFunction) vkGetInstanceProcAddr;\n" |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 393 | " }\n\n" |
| 394 | " addr = layer_intercept_instance_proc(funcName);\n" |
| 395 | " if (addr) {\n" |
| 396 | " return addr;" |
| 397 | " }\n" % self.layer_name) |
Jon Ashburn | bacb0f5 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 398 | |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 399 | if 0 != len(instance_extensions): |
| 400 | for ext_name in instance_extensions: |
| 401 | func_body.append(" layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);\n" |
| 402 | " addr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);\n" |
| 403 | " if (addr) {\n" |
| 404 | " return addr;\n" |
| 405 | " }\n" |
| 406 | " if (get_dispatch_table(%s_instance_table_map, instance)->GetInstanceProcAddr == NULL) {\n" |
| 407 | " return NULL;\n" |
| 408 | " }\n" |
| 409 | " return get_dispatch_table(%s_instance_table_map, instance)->GetInstanceProcAddr(instance, funcName);\n" |
| 410 | "}\n" % (self.layer_name, self.layer_name)) |
| 411 | return "\n".join(func_body) |
| 412 | else: |
| 413 | # |
| 414 | # TODO:: Old-style GPA Functions -- no local storage, no new logging mechanism. Left for compatibility. |
| 415 | # |
| 416 | func_body.append('%s' % self.lineinfo.get()) |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 417 | func_body.append("VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice device, const char* funcName)\n" |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 418 | "{\n" |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 419 | " PFN_vkVoidFunction addr;\n" |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 420 | " if (device == VK_NULL_HANDLE) {\n" |
| 421 | " return NULL;\n" |
| 422 | " }\n" |
| 423 | " loader_platform_thread_once(&initOnce, init%s);\n\n" |
| 424 | " /* loader uses this to force layer initialization; device object is wrapped */\n" |
| 425 | " if (!strcmp(\"vkGetDeviceProcAddr\", funcName)) {\n" |
| 426 | " initDeviceTable((const VkBaseLayerObject *) device);\n" |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 427 | " return (PFN_vkVoidFunction) vkGetDeviceProcAddr;\n" |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 428 | " }\n\n" |
| 429 | " addr = layer_intercept_proc(funcName);\n" |
| 430 | " if (addr)\n" |
| 431 | " return addr;" % self.layer_name) |
| 432 | func_body.append('') |
| 433 | func_body.append(' VkLayerDispatchTable *pDisp = device_dispatch_table(device);') |
| 434 | if 0 != len(extensions): |
| 435 | extra_space = "" |
| 436 | for (ext_enable, ext_list) in extensions: |
| 437 | if 0 != len(ext_enable): |
| 438 | func_body.append(' if (deviceExtMap.size() == 0 || deviceExtMap[pDisp].%s)' % ext_enable) |
| 439 | func_body.append(' {') |
| 440 | extra_space = " " |
| 441 | for ext_name in ext_list: |
| 442 | func_body.append(' %sif (!strcmp("%s", funcName))\n' |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 443 | ' return reinterpret_cast<PFN_vkVoidFunction>(%s);' % (extra_space, ext_name, ext_name)) |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 444 | if 0 != len(ext_enable): |
| 445 | func_body.append(' }') |
| 446 | func_body.append('%s' % self.lineinfo.get()) |
| 447 | func_body.append(" {\n" |
| 448 | " if (pDisp->GetDeviceProcAddr == NULL)\n" |
| 449 | " return NULL;\n" |
| 450 | " return pDisp->GetDeviceProcAddr(device, funcName);\n" |
| 451 | " }\n" |
| 452 | "}\n") |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 453 | func_body.append("VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)\n" |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 454 | "{\n" |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 455 | " PFN_vkVoidFunction addr;\n" |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 456 | " if (instance == VK_NULL_HANDLE) {\n" |
| 457 | " return NULL;\n" |
| 458 | " }\n" |
| 459 | " loader_platform_thread_once(&initOnce, init%s);\n\n" |
| 460 | " /* loader uses this to force layer initialization; instance object is wrapped */\n" |
| 461 | " if (!strcmp(\"vkGetInstanceProcAddr\", funcName)) {\n" |
| 462 | " initInstanceTable((const VkBaseLayerObject *) instance);\n" |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 463 | " return (PFN_vkVoidFunction) vkGetInstanceProcAddr;\n" |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 464 | " }\n\n" |
| 465 | " addr = layer_intercept_instance_proc(funcName);\n" |
| 466 | " if (addr)\n" |
| 467 | " return addr;" % self.layer_name) |
| 468 | if 0 != len(instance_extensions): |
| 469 | for ext_name in instance_extensions: |
| 470 | func_body.append(" {\n" |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 471 | " PFN_vkVoidFunction fptr;\n" |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 472 | " fptr = %s(funcName);\n" |
| 473 | " if (fptr) return fptr;\n" |
| 474 | " }\n" % ext_name) |
| 475 | func_body.append(" VkLayerInstanceDispatchTable* pTable = instance_dispatch_table(instance);\n" |
| 476 | " if (pTable->GetInstanceProcAddr == NULL)\n" |
| 477 | " return NULL;\n" |
| 478 | " return pTable->GetInstanceProcAddr(instance, funcName);\n" |
| 479 | "}\n") |
| 480 | return "\n".join(func_body) |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 481 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 482 | |
Mike Stroyan | ed238bb | 2015-05-15 08:50:57 -0600 | [diff] [blame] | 483 | def _generate_layer_initialization(self, init_opts=False, prefix='vk', lockname=None, condname=None): |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 484 | func_body = ["#include \"vk_dispatch_table_helper.h\""] |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 485 | func_body.append('%s' % self.lineinfo.get()) |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 486 | func_body.append('static void init%s(void)\n' |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 487 | '{\n' % self.layer_name) |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 488 | if init_opts: |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 489 | func_body.append('%s' % self.lineinfo.get()) |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 490 | func_body.append(' const char *strOpt;') |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 491 | func_body.append(' // initialize %s options' % self.layer_name) |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 492 | func_body.append(' getLayerOptionEnum("%sReportLevel", (uint32_t *) &g_reportFlags);' % self.layer_name) |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 493 | func_body.append(' g_actionIsDefault = getLayerOptionEnum("%sDebugAction", (uint32_t *) &g_debugAction);' % self.layer_name) |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 494 | func_body.append('') |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 495 | func_body.append(' if (g_debugAction & VK_DBG_LAYER_ACTION_LOG_MSG)') |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 496 | func_body.append(' {') |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 497 | func_body.append(' strOpt = getLayerOption("%sLogFilename");' % self.layer_name) |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 498 | func_body.append(' if (strOpt)') |
| 499 | func_body.append(' {') |
| 500 | func_body.append(' g_logFile = fopen(strOpt, "w");') |
| 501 | func_body.append(' }') |
| 502 | func_body.append(' if (g_logFile == NULL)') |
| 503 | func_body.append(' g_logFile = stdout;') |
| 504 | func_body.append(' }') |
| 505 | func_body.append('') |
Tobin Ehlis | 36f1b46 | 2015-02-23 14:09:16 -0700 | [diff] [blame] | 506 | if lockname is not None: |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 507 | func_body.append('%s' % self.lineinfo.get()) |
Tobin Ehlis | 36f1b46 | 2015-02-23 14:09:16 -0700 | [diff] [blame] | 508 | func_body.append(" if (!%sLockInitialized)" % lockname) |
| 509 | func_body.append(" {") |
| 510 | func_body.append(" // TODO/TBD: Need to delete this mutex sometime. How???") |
| 511 | func_body.append(" loader_platform_thread_create_mutex(&%sLock);" % lockname) |
Mike Stroyan | ed238bb | 2015-05-15 08:50:57 -0600 | [diff] [blame] | 512 | if condname is not None: |
| 513 | func_body.append(" loader_platform_thread_init_cond(&%sCond);" % condname) |
Tobin Ehlis | 36f1b46 | 2015-02-23 14:09:16 -0700 | [diff] [blame] | 514 | func_body.append(" %sLockInitialized = 1;" % lockname) |
| 515 | func_body.append(" }") |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 516 | func_body.append("}\n") |
Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 517 | func_body.append('') |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 518 | return "\n".join(func_body) |
| 519 | |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 520 | def _generate_new_layer_initialization(self, init_opts=False, prefix='vk', lockname=None, condname=None): |
| 521 | func_body = ["#include \"vk_dispatch_table_helper.h\""] |
| 522 | func_body.append('%s' % self.lineinfo.get()) |
| 523 | func_body.append('static void init%s(layer_data *my_data)\n' |
| 524 | '{\n' % self.layer_name) |
| 525 | if init_opts: |
| 526 | func_body.append('%s' % self.lineinfo.get()) |
| 527 | func_body.append(' uint32_t report_flags = 0;') |
| 528 | func_body.append(' uint32_t debug_action = 0;') |
| 529 | func_body.append(' FILE *log_output = NULL;') |
| 530 | func_body.append(' const char *strOpt;') |
| 531 | func_body.append(' // initialize %s options' % self.layer_name) |
| 532 | func_body.append(' report_flags = getLayerOptionFlags("%sReportFlags", 0);' % self.layer_name) |
| 533 | func_body.append(' g_actionIsDefault = getLayerOptionEnum("%sDebugAction", (uint32_t *) &debug_action);' % self.layer_name) |
| 534 | func_body.append('') |
| 535 | func_body.append(' if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)') |
| 536 | func_body.append(' {') |
| 537 | func_body.append(' strOpt = getLayerOption("%sLogFilename");' % self.layer_name) |
| 538 | func_body.append(' if (strOpt)') |
| 539 | func_body.append(' {') |
| 540 | func_body.append(' log_output = fopen(strOpt, "w");') |
| 541 | func_body.append(' }') |
| 542 | func_body.append(' if (log_output == NULL)') |
| 543 | func_body.append(' log_output = stdout;') |
| 544 | func_body.append(' layer_create_msg_callback(my_data->report_data, report_flags, log_callback, (void *) log_output, &my_data->logging_callback);') |
| 545 | func_body.append(' }') |
| 546 | func_body.append('') |
| 547 | if lockname is not None: |
| 548 | func_body.append('%s' % self.lineinfo.get()) |
| 549 | func_body.append(" if (!%sLockInitialized)" % lockname) |
| 550 | func_body.append(" {") |
| 551 | func_body.append(" // TODO/TBD: Need to delete this mutex sometime. How???") |
| 552 | func_body.append(" loader_platform_thread_create_mutex(&%sLock);" % lockname) |
| 553 | if condname is not None: |
| 554 | func_body.append(" loader_platform_thread_init_cond(&%sCond);" % condname) |
| 555 | func_body.append(" %sLockInitialized = 1;" % lockname) |
| 556 | func_body.append(" }") |
| 557 | func_body.append("}\n") |
| 558 | func_body.append('') |
| 559 | return "\n".join(func_body) |
| 560 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 561 | class LayerFuncsSubcommand(Subcommand): |
| 562 | def generate_header(self): |
Tobin Ehlis | 0c6f9ee | 2015-07-03 09:42:57 -0600 | [diff] [blame] | 563 | return '#include <vk_layer.h>\n#include "loader.h"' |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 564 | |
| 565 | def generate_body(self): |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 566 | return self._generate_dispatch_entrypoints("static") |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 567 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 568 | class GenericLayerSubcommand(Subcommand): |
| 569 | def generate_header(self): |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 570 | gen_header = [] |
Courtney Goeltzenleuchter | 79a5a96 | 2015-07-07 17:51:45 -0600 | [diff] [blame] | 571 | gen_header.append('%s' % self.lineinfo.get()) |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 572 | gen_header.append('#include <stdio.h>') |
| 573 | gen_header.append('#include <stdlib.h>') |
| 574 | gen_header.append('#include <string.h>') |
| 575 | gen_header.append('#include <unordered_map>') |
Tobin Ehlis | b835d1b | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 576 | gen_header.append('#include "vk_loader_platform.h"') |
Tobin Ehlis | 0c6f9ee | 2015-07-03 09:42:57 -0600 | [diff] [blame] | 577 | gen_header.append('#include "vk_layer.h"') |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 578 | gen_header.append('//The following is #included again to catch certain OS-specific functions being used:') |
| 579 | gen_header.append('') |
Tobin Ehlis | b835d1b | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 580 | gen_header.append('#include "vk_loader_platform.h"') |
Tobin Ehlis | a0cb02e | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 581 | gen_header.append('#include "vk_layer_config.h"') |
| 582 | gen_header.append('#include "vk_layer_msg.h"') |
| 583 | gen_header.append('#include "vk_layer_table.h"') |
Courtney Goeltzenleuchter | 3f9f7c4 | 2015-07-06 09:11:12 -0600 | [diff] [blame] | 584 | gen_header.append('#include "vk_layer_extension_utils.h"') |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 585 | gen_header.append('') |
Courtney Goeltzenleuchter | 79a5a96 | 2015-07-07 17:51:45 -0600 | [diff] [blame] | 586 | gen_header.append('#include "generic.h"') |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 587 | gen_header.append('') |
Tobin Ehlis | a30e7e5 | 2015-07-06 14:02:36 -0600 | [diff] [blame] | 588 | gen_header.append('%s' % self.lineinfo.get()) |
| 589 | gen_header.append('#define LAYER_EXT_ARRAY_SIZE 1') |
| 590 | gen_header.append('#define LAYER_DEV_EXT_ARRAY_SIZE 1') |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 591 | gen_header.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(initOnce);') |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 592 | gen_header.append('struct devExts {') |
Ian Elliott | 1064fe3 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 593 | gen_header.append(' bool wsi_enabled;') |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 594 | gen_header.append('};') |
| 595 | gen_header.append('static std::unordered_map<void *, struct devExts> deviceExtMap;') |
| 596 | gen_header.append('') |
| 597 | gen_header.append('static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)') |
| 598 | gen_header.append('{') |
Tony Barbour | 3b4732f | 2015-07-13 13:37:24 -0600 | [diff] [blame] | 599 | gen_header.append(' uint32_t i;') |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 600 | gen_header.append(' VkLayerDispatchTable *pDisp = device_dispatch_table(device);') |
Ian Elliott | 1064fe3 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 601 | gen_header.append(' deviceExtMap[pDisp].wsi_enabled = false;') |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 602 | gen_header.append(' for (i = 0; i < pCreateInfo->extensionCount; i++) {') |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 603 | gen_header.append(' if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_EXT_KHR_SWAPCHAIN_EXTENSION_NAME) == 0)') |
Ian Elliott | 1064fe3 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 604 | gen_header.append(' deviceExtMap[pDisp].wsi_enabled = true;') |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 605 | gen_header.append('') |
| 606 | gen_header.append(' }') |
| 607 | gen_header.append('}') |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 608 | gen_header.append('') |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 609 | return "\n".join(gen_header) |
Tobin Ehlis | 7a314ea | 2015-07-07 11:02:44 -0600 | [diff] [blame] | 610 | |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 611 | def generate_intercept(self, proto, qual): |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 612 | if proto.name in [ 'GetGlobalLayerProperties', 'GetGlobalExtensionProperties', 'GetPhysicalDeviceLayerProperties', 'GetPhysicalDeviceExtensionProperties' ]: |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 613 | # use default version |
| 614 | return None |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 615 | decl = proto.c_func(prefix="vk", attr="VKAPI") |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 616 | ret_val = '' |
| 617 | stmt = '' |
| 618 | funcs = [] |
Jon Ashburn | 71836d9 | 2015-05-12 17:23:55 -0600 | [diff] [blame] | 619 | table = '' |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 620 | if proto_is_global(proto): |
Jon Ashburn | 71836d9 | 2015-05-12 17:23:55 -0600 | [diff] [blame] | 621 | table = 'Instance' |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 622 | if proto.ret != "void": |
Courtney Goeltzenleuchter | 0de9e21 | 2015-06-26 15:07:53 -0600 | [diff] [blame] | 623 | funcs.append('%s' % self.lineinfo.get()) |
Jon Ashburn | b0fbe91 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 624 | ret_val = "%s result = " % proto.ret |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 625 | stmt = " return result;\n" |
Jon Ashburn | 8ced421 | 2015-05-22 12:01:50 -0600 | [diff] [blame] | 626 | if proto.name == "CreateDevice": |
Courtney Goeltzenleuchter | 0de9e21 | 2015-06-26 15:07:53 -0600 | [diff] [blame] | 627 | funcs.append('%s' % self.lineinfo.get()) |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 628 | funcs.append('%s%s\n' |
| 629 | '{\n' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 630 | ' char str[1024];\n' |
| 631 | ' sprintf(str, "At start of layered %s\\n");\n' |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 632 | ' layerCbMsg(VK_DBG_REPORT_INFO_BIT,VK_OBJECT_TYPE_PHYSICAL_DEVICE, (uint64_t)physicalDevice, 0, 0, (char *) "GENERIC", (char *) str);\n' |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 633 | ' %sdevice_dispatch_table(*pDevice)->%s;\n' |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 634 | ' if (result == VK_SUCCESS) {\n' |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 635 | ' enable_debug_report(pCreateInfo->extensionCount, pCreateInfo->ppEnabledExtensionNames);\n' |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 636 | ' createDeviceRegisterExtensions(pCreateInfo, *pDevice);\n' |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 637 | ' }\n' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 638 | ' sprintf(str, "Completed layered %s\\n");\n' |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 639 | ' layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, (uint64_t)physicalDevice, 0, 0, (char *) "GENERIC", (char *) str);\n' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 640 | ' fflush(stdout);\n' |
| 641 | ' %s' |
| 642 | '}' % (qual, decl, proto.name, ret_val, proto.c_call(), proto.name, stmt)) |
| 643 | elif proto.name == "DestroyDevice": |
Courtney Goeltzenleuchter | 0de9e21 | 2015-06-26 15:07:53 -0600 | [diff] [blame] | 644 | funcs.append('%s' % self.lineinfo.get()) |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 645 | funcs.append('%s%s\n' |
| 646 | '{\n' |
Courtney Goeltzenleuchter | 0daf228 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 647 | ' dispatch_key key = get_dispatch_key(device);\n' |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 648 | ' VkLayerDispatchTable *pDisp = device_dispatch_table(device);\n' |
| 649 | ' VkResult res = pDisp->DestroyDevice(device);\n' |
| 650 | ' deviceExtMap.erase(pDisp);\n' |
Courtney Goeltzenleuchter | 0daf228 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 651 | ' destroy_device_dispatch_table(key);\n' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 652 | ' return res;\n' |
| 653 | '}\n' % (qual, decl)) |
| 654 | elif proto.name == "DestroyInstance": |
Courtney Goeltzenleuchter | 0de9e21 | 2015-06-26 15:07:53 -0600 | [diff] [blame] | 655 | funcs.append('%s' % self.lineinfo.get()) |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 656 | funcs.append('%s%s\n' |
| 657 | '{\n' |
Courtney Goeltzenleuchter | 0daf228 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 658 | ' dispatch_key key = get_dispatch_key(instance);\n' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 659 | ' VkResult res = instance_dispatch_table(instance)->DestroyInstance(instance);\n' |
Courtney Goeltzenleuchter | 0daf228 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 660 | ' destroy_instance_dispatch_table(key);\n' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 661 | ' return res;\n' |
| 662 | '}\n' % (qual, decl)) |
Jon Ashburn | 4d9f465 | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 663 | else: |
Courtney Goeltzenleuchter | 0de9e21 | 2015-06-26 15:07:53 -0600 | [diff] [blame] | 664 | funcs.append('%s' % self.lineinfo.get()) |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 665 | # CreateInstance needs to use the second parm instead of the first to set the correct dispatch table |
| 666 | dispatch_param = proto.params[0].name |
| 667 | # Must use 'instance' table for these APIs, 'device' table otherwise |
| 668 | table_type = "" |
| 669 | if proto_is_global(proto): |
| 670 | table_type = "instance" |
| 671 | else: |
| 672 | table_type = "device" |
| 673 | if 'CreateInstance' in proto.name: |
| 674 | dispatch_param = '*' + proto.params[1].name |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 675 | funcs.append('%s%s\n' |
| 676 | '{\n' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 677 | ' %s%s_dispatch_table(%s)->%s;\n' |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 678 | '%s' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 679 | '}' % (qual, decl, ret_val, table_type, dispatch_param, proto.c_call(), stmt)) |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 680 | return "\n\n".join(funcs) |
| 681 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 682 | def generate_body(self): |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 683 | self.layer_name = "Generic" |
Ian Elliott | 1064fe3 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 684 | extensions=[('wsi_enabled', |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 685 | ['vkCreateSwapchainKHR', 'vkDestroySwapchainKHR', |
| 686 | 'vkGetSwapchainImagesKHR', 'vkQueuePresentKHR'])] |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 687 | body = [self._generate_layer_initialization(True), |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 688 | self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"), |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 689 | self._gen_create_msg_callback(), |
| 690 | self._gen_destroy_msg_callback(), |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 691 | self._generate_layer_gpa_function(extensions)] |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 692 | |
| 693 | return "\n\n".join(body) |
| 694 | |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 695 | class APIDumpSubcommand(Subcommand): |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 696 | def generate_header(self): |
Tobin Ehlis | d009bae | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 697 | header_txt = [] |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 698 | header_txt.append('%s' % self.lineinfo.get()) |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 699 | header_txt.append('#include <fstream>') |
| 700 | header_txt.append('#include <iostream>') |
| 701 | header_txt.append('#include <string>') |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 702 | header_txt.append('#include <string.h>') |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 703 | header_txt.append('') |
Tobin Ehlis | 80d048e | 2015-08-28 09:57:53 -0600 | [diff] [blame] | 704 | header_txt.append('#include "vk_loader_platform.h"') |
| 705 | header_txt.append('#include "vk_layer.h"') |
| 706 | header_txt.append('#include "vk_struct_string_helper_cpp.h"') |
| 707 | header_txt.append('#include "vk_layer_table.h"') |
| 708 | header_txt.append('#include "vk_layer_extension_utils.h"') |
| 709 | header_txt.append('#include <unordered_map>') |
| 710 | header_txt.append('') |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 711 | header_txt.append('static std::ofstream fileStream;') |
| 712 | header_txt.append('static std::string fileName = "vk_apidump.txt";') |
| 713 | header_txt.append('std::ostream* outputStream = NULL;') |
| 714 | header_txt.append('void ConfigureOutputStream(bool writeToFile, bool flushAfterWrite)') |
| 715 | header_txt.append('{') |
| 716 | header_txt.append(' if(writeToFile)') |
| 717 | header_txt.append(' {') |
| 718 | header_txt.append(' fileStream.open(fileName);') |
Tobin Ehlis | 80d048e | 2015-08-28 09:57:53 -0600 | [diff] [blame] | 719 | header_txt.append(' if ((fileStream.rdstate() & fileStream.failbit) != 0) {') |
| 720 | header_txt.append(' outputStream = &std::cout;') |
| 721 | header_txt.append(' (*outputStream) << endl << "APIDump ERROR: Bad output filename specified: " << fileName << ". Writing to STDOUT instead" << endl << endl;') |
| 722 | header_txt.append(' }') |
| 723 | header_txt.append(' else') |
| 724 | header_txt.append(' outputStream = &fileStream;') |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 725 | header_txt.append(' }') |
| 726 | header_txt.append(' else') |
| 727 | header_txt.append(' {') |
| 728 | header_txt.append(' outputStream = &std::cout;') |
| 729 | header_txt.append(' }') |
| 730 | header_txt.append('') |
| 731 | header_txt.append(' if(flushAfterWrite)') |
| 732 | header_txt.append(' {') |
| 733 | header_txt.append(' outputStream->sync_with_stdio(true);') |
| 734 | header_txt.append(' }') |
| 735 | header_txt.append(' else') |
| 736 | header_txt.append(' {') |
| 737 | header_txt.append(' outputStream->sync_with_stdio(false);') |
| 738 | header_txt.append(' }') |
| 739 | header_txt.append('}') |
| 740 | header_txt.append('') |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 741 | header_txt.append('%s' % self.lineinfo.get()) |
Ian Elliott | 655cad7 | 2015-02-12 17:08:34 -0700 | [diff] [blame] | 742 | header_txt.append('// The following is #included again to catch certain OS-specific functions being used:') |
Tobin Ehlis | b835d1b | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 743 | header_txt.append('#include "vk_loader_platform.h"') |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 744 | header_txt.append('') |
Jon Ashburn | bacb0f5 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 745 | header_txt.append('static VkBaseLayerObject *pCurObj;') |
Tobin Ehlis | a2b199c | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 746 | header_txt.append('static bool g_APIDumpDetailed = true;') |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 747 | header_txt.append('') |
Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 748 | header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(initOnce);') |
Mark Lobodzinski | 4c7ac0a | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 749 | header_txt.append('') |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 750 | header_txt.append('static int printLockInitialized = 0;') |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 751 | header_txt.append('static loader_platform_thread_mutex printLock;') |
| 752 | header_txt.append('') |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 753 | header_txt.append('%s' % self.lineinfo.get()) |
Tobin Ehlis | a30e7e5 | 2015-07-06 14:02:36 -0600 | [diff] [blame] | 754 | header_txt.append('#define LAYER_EXT_ARRAY_SIZE 1') |
| 755 | header_txt.append('#define LAYER_DEV_EXT_ARRAY_SIZE 1') |
Tobin Ehlis | d009bae | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 756 | header_txt.append('#define MAX_TID 513') |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 757 | header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};') |
Tobin Ehlis | d009bae | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 758 | header_txt.append('static uint32_t maxTID = 0;') |
| 759 | header_txt.append('// Map actual TID to an index value and return that index') |
| 760 | header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs') |
| 761 | header_txt.append('static uint32_t getTIDIndex() {') |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 762 | header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();') |
Tobin Ehlis | d009bae | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 763 | header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {') |
| 764 | header_txt.append(' if (tid == tidMapping[i])') |
| 765 | header_txt.append(' return i;') |
| 766 | header_txt.append(' }') |
| 767 | header_txt.append(" // Don't yet have mapping, set it and return newly set index") |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 768 | header_txt.append(' uint32_t retVal = (uint32_t) maxTID;') |
Tobin Ehlis | d009bae | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 769 | header_txt.append(' tidMapping[maxTID++] = tid;') |
| 770 | header_txt.append(' assert(maxTID < MAX_TID);') |
| 771 | header_txt.append(' return retVal;') |
| 772 | header_txt.append('}') |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 773 | header_txt.append('struct devExts {') |
Ian Elliott | 1064fe3 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 774 | header_txt.append(' bool wsi_enabled;') |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 775 | header_txt.append('};') |
| 776 | header_txt.append('') |
| 777 | header_txt.append('static std::unordered_map<void *, struct devExts> deviceExtMap;') |
| 778 | header_txt.append('') |
| 779 | header_txt.append('static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)') |
| 780 | header_txt.append('{') |
Tony Barbour | 3b4732f | 2015-07-13 13:37:24 -0600 | [diff] [blame] | 781 | header_txt.append(' uint32_t i;') |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 782 | header_txt.append(' VkLayerDispatchTable *pDisp = device_dispatch_table(device);') |
Ian Elliott | 1064fe3 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 783 | header_txt.append(' deviceExtMap[pDisp].wsi_enabled = false;') |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 784 | header_txt.append(' for (i = 0; i < pCreateInfo->extensionCount; i++) {') |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 785 | header_txt.append(' if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_EXT_KHR_SWAPCHAIN_EXTENSION_NAME) == 0)') |
Ian Elliott | 1064fe3 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 786 | header_txt.append(' deviceExtMap[pDisp].wsi_enabled = true;') |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 787 | header_txt.append('') |
| 788 | header_txt.append(' }') |
| 789 | header_txt.append('}') |
Mark Lobodzinski | 4c7ac0a | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 790 | header_txt.append('') |
Mark Lobodzinski | b9143d8 | 2015-07-30 10:11:32 -0600 | [diff] [blame] | 791 | header_txt.append('void interpret_memBarriers(const void* const* ppMemBarriers, uint32_t memBarrierCount)') |
| 792 | header_txt.append('{') |
| 793 | header_txt.append(' if (ppMemBarriers) {') |
| 794 | header_txt.append(' string tmp_str;') |
Mark Lobodzinski | 29bfb20 | 2015-07-31 13:47:42 -0600 | [diff] [blame] | 795 | header_txt.append(' for (uint32_t i = 0; i < memBarrierCount; i++) {') |
| 796 | header_txt.append(' switch(*(VkStructureType*)ppMemBarriers[i])') |
Mark Lobodzinski | b9143d8 | 2015-07-30 10:11:32 -0600 | [diff] [blame] | 797 | header_txt.append(' {') |
| 798 | header_txt.append(' case VK_STRUCTURE_TYPE_MEMORY_BARRIER:') |
Mark Lobodzinski | 29bfb20 | 2015-07-31 13:47:42 -0600 | [diff] [blame] | 799 | header_txt.append(' tmp_str = vk_print_vkmemorybarrier((VkMemoryBarrier*)ppMemBarriers[i], " ");') |
Mark Lobodzinski | b9143d8 | 2015-07-30 10:11:32 -0600 | [diff] [blame] | 800 | header_txt.append(' break;') |
| 801 | header_txt.append(' case VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER:') |
Mark Lobodzinski | 29bfb20 | 2015-07-31 13:47:42 -0600 | [diff] [blame] | 802 | header_txt.append(' tmp_str = vk_print_vkbuffermemorybarrier((VkBufferMemoryBarrier*)ppMemBarriers[i], " ");') |
Mark Lobodzinski | b9143d8 | 2015-07-30 10:11:32 -0600 | [diff] [blame] | 803 | header_txt.append(' break;') |
| 804 | header_txt.append(' case VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER:') |
Mark Lobodzinski | 29bfb20 | 2015-07-31 13:47:42 -0600 | [diff] [blame] | 805 | header_txt.append(' tmp_str = vk_print_vkimagememorybarrier((VkImageMemoryBarrier*)ppMemBarriers[i], " ");') |
Mark Lobodzinski | b9143d8 | 2015-07-30 10:11:32 -0600 | [diff] [blame] | 806 | header_txt.append(' break;') |
| 807 | header_txt.append(' default:') |
| 808 | header_txt.append(' break;') |
| 809 | header_txt.append(' }') |
| 810 | header_txt.append('') |
| 811 | header_txt.append(' if (StreamControl::writeAddress == true) {') |
| 812 | header_txt.append(' (*outputStream) << " ppMemBarriers[" << i << "] (" << &ppMemBarriers[i] << ")" << endl << tmp_str << endl;') |
| 813 | header_txt.append(' } else {') |
| 814 | header_txt.append(' (*outputStream) << " ppMemBarriers[" << i << "] (address)" << endl << " address" << endl;') |
| 815 | header_txt.append(' }') |
| 816 | header_txt.append(' }') |
| 817 | header_txt.append(' }') |
| 818 | header_txt.append('}') |
| 819 | header_txt.append('') |
Tobin Ehlis | d009bae | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 820 | return "\n".join(header_txt) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 821 | |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 822 | def generate_init(self): |
| 823 | func_body = [] |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 824 | func_body.append('%s' % self.lineinfo.get()) |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 825 | func_body.append('#include "vk_dispatch_table_helper.h"') |
Tobin Ehlis | a0cb02e | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 826 | func_body.append('#include "vk_layer_config.h"') |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 827 | func_body.append('') |
| 828 | func_body.append('static void init%s(void)' % self.layer_name) |
| 829 | func_body.append('{') |
| 830 | func_body.append(' using namespace StreamControl;') |
| 831 | func_body.append('') |
Tobin Ehlis | a870097 | 2015-08-26 16:18:52 -0600 | [diff] [blame] | 832 | func_body.append(' char const*const logName = getLayerOption("APIDumpLogFilename");') |
| 833 | func_body.append(' if(logName != NULL)') |
| 834 | func_body.append(' {') |
| 835 | func_body.append(' fileName = logName;') |
| 836 | func_body.append(' }') |
| 837 | func_body.append('') |
Tobin Ehlis | a2b199c | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 838 | func_body.append(' char const*const detailedStr = getLayerOption("APIDumpDetailed");') |
| 839 | func_body.append(' if(detailedStr != NULL)') |
| 840 | func_body.append(' {') |
| 841 | func_body.append(' if(strcmp(detailedStr, "TRUE") == 0)') |
| 842 | func_body.append(' {') |
| 843 | func_body.append(' g_APIDumpDetailed = true;') |
| 844 | func_body.append(' }') |
| 845 | func_body.append(' else if(strcmp(detailedStr, "FALSE") == 0)') |
| 846 | func_body.append(' {') |
| 847 | func_body.append(' g_APIDumpDetailed = false;') |
| 848 | func_body.append(' }') |
| 849 | func_body.append(' }') |
| 850 | func_body.append('') |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 851 | func_body.append(' char const*const writeToFileStr = getLayerOption("APIDumpFile");') |
| 852 | func_body.append(' bool writeToFile = false;') |
| 853 | func_body.append(' if(writeToFileStr != NULL)') |
| 854 | func_body.append(' {') |
| 855 | func_body.append(' if(strcmp(writeToFileStr, "TRUE") == 0)') |
| 856 | func_body.append(' {') |
| 857 | func_body.append(' writeToFile = true;') |
| 858 | func_body.append(' }') |
| 859 | func_body.append(' else if(strcmp(writeToFileStr, "FALSE") == 0)') |
| 860 | func_body.append(' {') |
| 861 | func_body.append(' writeToFile = false;') |
| 862 | func_body.append(' }') |
| 863 | func_body.append(' }') |
| 864 | func_body.append('') |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 865 | func_body.append('%s' % self.lineinfo.get()) |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 866 | func_body.append(' char const*const noAddrStr = getLayerOption("APIDumpNoAddr");') |
| 867 | func_body.append(' if(noAddrStr != NULL)') |
| 868 | func_body.append(' {') |
| 869 | func_body.append(' if(strcmp(noAddrStr, "FALSE") == 0)') |
| 870 | func_body.append(' {') |
| 871 | func_body.append(' StreamControl::writeAddress = true;') |
| 872 | func_body.append(' }') |
| 873 | func_body.append(' else if(strcmp(noAddrStr, "TRUE") == 0)') |
| 874 | func_body.append(' {') |
| 875 | func_body.append(' StreamControl::writeAddress = false;') |
| 876 | func_body.append(' }') |
| 877 | func_body.append(' }') |
| 878 | func_body.append('') |
| 879 | func_body.append(' char const*const flushAfterWriteStr = getLayerOption("APIDumpFlush");') |
| 880 | func_body.append(' bool flushAfterWrite = false;') |
| 881 | func_body.append(' if(flushAfterWriteStr != NULL)') |
| 882 | func_body.append(' {') |
| 883 | func_body.append(' if(strcmp(flushAfterWriteStr, "TRUE") == 0)') |
| 884 | func_body.append(' {') |
| 885 | func_body.append(' flushAfterWrite = true;') |
| 886 | func_body.append(' }') |
| 887 | func_body.append(' else if(strcmp(flushAfterWriteStr, "FALSE") == 0)') |
| 888 | func_body.append(' {') |
| 889 | func_body.append(' flushAfterWrite = false;') |
| 890 | func_body.append(' }') |
| 891 | func_body.append(' }') |
| 892 | func_body.append('') |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 893 | func_body.append('%s' % self.lineinfo.get()) |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 894 | func_body.append(' ConfigureOutputStream(writeToFile, flushAfterWrite);') |
| 895 | func_body.append('') |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 896 | func_body.append(' if (!printLockInitialized)') |
| 897 | func_body.append(' {') |
| 898 | func_body.append(' // TODO/TBD: Need to delete this mutex sometime. How???') |
| 899 | func_body.append(' loader_platform_thread_create_mutex(&printLock);') |
| 900 | func_body.append(' printLockInitialized = 1;') |
| 901 | func_body.append(' }') |
| 902 | func_body.append('}') |
| 903 | func_body.append('') |
| 904 | return "\n".join(func_body) |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 905 | |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 906 | def generate_intercept(self, proto, qual): |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 907 | if proto.name in [ 'GetGlobalLayerProperties','GetGlobalExtensionProperties','GetPhysicalDeviceLayerProperties','GetPhysicalDeviceExtensionProperties']: |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 908 | return None |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 909 | decl = proto.c_func(prefix="vk", attr="VKAPI") |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 910 | ret_val = '' |
| 911 | stmt = '' |
| 912 | funcs = [] |
| 913 | sp_param_dict = {} # Store 'index' for struct param to print, or an name of binding "Count" param for array to print |
| 914 | create_params = 0 # Num of params at end of function that are created and returned as output values |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 915 | if 'AllocDescriptorSets' in proto.name: |
Cody Northrop | 1e4f802 | 2015-08-03 12:47:29 -0600 | [diff] [blame] | 916 | create_params = -1 |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 917 | elif 'Create' in proto.name or 'Alloc' in proto.name or 'MapMemory' in proto.name: |
| 918 | create_params = -1 |
| 919 | if proto.ret != "void": |
Jon Ashburn | b0fbe91 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 920 | ret_val = "%s result = " % proto.ret |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 921 | stmt = " return result;\n" |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 922 | f_open = 'loader_platform_thread_lock_mutex(&printLock);\n ' |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 923 | log_func = '%s\n' % self.lineinfo.get() |
| 924 | log_func += ' if (StreamControl::writeAddress == true) {' |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 925 | log_func += '\n (*outputStream) << "t{" << getTIDIndex() << "} vk%s(' % proto.name |
| 926 | log_func_no_addr = '\n (*outputStream) << "t{" << getTIDIndex() << "} vk%s(' % proto.name |
| 927 | f_close = '\n loader_platform_thread_unlock_mutex(&printLock);' |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 928 | pindex = 0 |
| 929 | prev_count_name = '' |
| 930 | for p in proto.params: |
| 931 | cp = False |
| 932 | if 0 != create_params: |
| 933 | # If this is any of the N last params of the func, treat as output |
| 934 | for y in range(-1, create_params-1, -1): |
| 935 | if p.name == proto.params[y].name: |
| 936 | cp = True |
| 937 | (pft, pfi) = self._get_printf_params(p.ty, p.name, cp, cpp=True) |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 938 | if p.name == "pSwapchain": |
Ian Elliott | 1064fe3 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 939 | log_func += '%s = " << %s->handle << ", ' % (p.name, p.name) |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 940 | elif p.name == "swapchain": |
Ian Elliott | 1064fe3 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 941 | log_func += '%s = " << %s.handle << ", ' % (p.name, p.name) |
| 942 | else: |
| 943 | log_func += '%s = " << %s << ", ' % (p.name, pfi) |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 944 | if "%p" == pft: |
| 945 | log_func_no_addr += '%s = address, ' % (p.name) |
| 946 | else: |
| 947 | log_func_no_addr += '%s = " << %s << ", ' % (p.name, pfi) |
Tobin Ehlis | 0854174 | 2015-04-16 15:56:11 -0600 | [diff] [blame] | 948 | if prev_count_name != '' and (prev_count_name.replace('Count', '')[1:] in p.name): |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 949 | sp_param_dict[pindex] = prev_count_name |
Tobin Ehlis | 0854174 | 2015-04-16 15:56:11 -0600 | [diff] [blame] | 950 | prev_count_name = '' |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 951 | elif vk_helper.is_type(p.ty.strip('*').replace('const ', ''), 'struct'): |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 952 | sp_param_dict[pindex] = 'index' |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 953 | if p.name.endswith('Count'): |
| 954 | if '*' in p.ty: |
| 955 | prev_count_name = "*%s" % p.name |
| 956 | else: |
| 957 | prev_count_name = p.name |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 958 | pindex += 1 |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 959 | log_func = log_func.strip(', ') |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 960 | log_func_no_addr = log_func_no_addr.strip(', ') |
Jon Ashburn | b0fbe91 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 961 | if proto.ret == "VkResult": |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 962 | log_func += ') = " << string_VkResult((VkResult)result) << endl' |
| 963 | log_func_no_addr += ') = " << string_VkResult((VkResult)result) << endl' |
Jon Ashburn | b0fbe91 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 964 | elif proto.ret == "void*": |
| 965 | log_func += ') = " << result << endl' |
| 966 | log_func_no_addr += ') = " << result << endl' |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 967 | else: |
| 968 | log_func += ')\\n"' |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 969 | log_func_no_addr += ')\\n"' |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 970 | log_func += ';' |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 971 | log_func_no_addr += ';' |
Tobin Ehlis | a30e7e5 | 2015-07-06 14:02:36 -0600 | [diff] [blame] | 972 | log_func += '\n }\n else {%s\n }' % log_func_no_addr; |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 973 | log_func += '\n%s' % self.lineinfo.get() |
Tobin Ehlis | b870cbb | 2015-04-15 07:46:12 -0600 | [diff] [blame] | 974 | #print("Proto %s has param_dict: %s" % (proto.name, sp_param_dict)) |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 975 | if len(sp_param_dict) > 0: |
Tobin Ehlis | a2b199c | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 976 | indent = ' ' |
| 977 | log_func += '\n%sif (g_APIDumpDetailed) {' % indent |
| 978 | indent += ' ' |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 979 | i_decl = False |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 980 | log_func += '\n%s' % self.lineinfo.get() |
Tobin Ehlis | a2b199c | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 981 | log_func += '\n%sstring tmp_str;' % indent |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 982 | for sp_index in sp_param_dict: |
Tobin Ehlis | b870cbb | 2015-04-15 07:46:12 -0600 | [diff] [blame] | 983 | #print("sp_index: %s" % str(sp_index)) |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 984 | if 'index' == sp_param_dict[sp_index]: |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 985 | cis_print_func = 'vk_print_%s' % (proto.params[sp_index].ty.replace('const ', '').strip('*').lower()) |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 986 | local_name = proto.params[sp_index].name |
| 987 | if '*' not in proto.params[sp_index].ty: |
| 988 | local_name = '&%s' % proto.params[sp_index].name |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 989 | log_func += '\n%s' % self.lineinfo.get() |
Tobin Ehlis | a2b199c | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 990 | log_func += '\n%sif (%s) {' % (indent, local_name) |
| 991 | indent += ' ' |
| 992 | log_func += '\n%stmp_str = %s(%s, " ");' % (indent, cis_print_func, local_name) |
| 993 | log_func += '\n%s(*outputStream) << " %s (" << %s << ")" << endl << tmp_str << endl;' % (indent, local_name, local_name) |
| 994 | indent = indent[4:] |
| 995 | log_func += '\n%s}' % (indent) |
Mark Lobodzinski | b9143d8 | 2015-07-30 10:11:32 -0600 | [diff] [blame] | 996 | elif 'memBarrierCount' == sp_param_dict[sp_index]: # call helper function |
| 997 | log_func += '\n%sif (ppMemBarriers) {' % (indent) |
| 998 | log_func += '\n%s interpret_memBarriers(ppMemBarriers, memBarrierCount);' % (indent) |
| 999 | log_func += '\n%s}' % (indent) |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 1000 | else: # We have a count value stored to iterate over an array |
| 1001 | print_cast = '' |
| 1002 | print_func = '' |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 1003 | if vk_helper.is_type(proto.params[sp_index].ty.strip('*').replace('const ', ''), 'struct'): |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 1004 | print_cast = '&' |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 1005 | print_func = 'vk_print_%s' % proto.params[sp_index].ty.replace('const ', '').strip('*').lower() |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 1006 | else: |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 1007 | print_cast = '' |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 1008 | print_func = 'string_convert_helper' |
| 1009 | #cis_print_func = 'tmp_str = string_convert_helper((void*)%s[i], " ");' % proto.params[sp_index].name |
Tobin Ehlis | a30e7e5 | 2015-07-06 14:02:36 -0600 | [diff] [blame] | 1010 | if proto.params[sp_index].ty.strip('*').replace('const ', '') in vulkan.object_non_dispatch_list: |
| 1011 | cis_print_func = 'tmp_str = %s(%s%s[i].handle, " ");' % (print_func, print_cast, proto.params[sp_index].name) |
| 1012 | else: |
| 1013 | cis_print_func = 'tmp_str = %s(%s%s[i], " ");' % (print_func, print_cast, proto.params[sp_index].name) |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 1014 | if not i_decl: |
Tobin Ehlis | a2b199c | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 1015 | log_func += '\n%suint32_t i;' % (indent) |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 1016 | i_decl = True |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1017 | log_func += '\n%sif (%s) {' % (indent, proto.params[sp_index].name) |
| 1018 | indent += ' ' |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1019 | log_func += '\n%s' % self.lineinfo.get() |
Tobin Ehlis | a2b199c | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 1020 | log_func += '\n%sfor (i = 0; i < %s; i++) {' % (indent, sp_param_dict[sp_index]) |
| 1021 | indent += ' ' |
| 1022 | log_func += '\n%s%s' % (indent, cis_print_func) |
Tobin Ehlis | 45a23a8 | 2015-04-28 10:58:20 -0600 | [diff] [blame] | 1023 | log_func += '\n%sif (StreamControl::writeAddress == true) {' % (indent) |
| 1024 | indent += ' ' |
Tobin Ehlis | a2b199c | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 1025 | log_func += '\n%s(*outputStream) << " %s[" << i << "] (" << %s%s[i] << ")" << endl << tmp_str << endl;' % (indent, proto.params[sp_index].name, '&', proto.params[sp_index].name) |
| 1026 | indent = indent[4:] |
Tobin Ehlis | 45a23a8 | 2015-04-28 10:58:20 -0600 | [diff] [blame] | 1027 | log_func += '\n%s} else {' % (indent) |
| 1028 | indent += ' ' |
| 1029 | log_func += '\n%s(*outputStream) << " %s[" << i << "] (address)" << endl << " address" << endl;' % (indent, proto.params[sp_index].name) |
| 1030 | indent = indent[4:] |
| 1031 | log_func += '\n%s}' % (indent) |
| 1032 | indent = indent[4:] |
Tobin Ehlis | a2b199c | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 1033 | log_func += '\n%s}' % (indent) |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1034 | indent = indent[4:] |
| 1035 | log_func += '\n%s}' % (indent) |
Tobin Ehlis | a2b199c | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 1036 | indent = indent[4:] |
| 1037 | log_func += '\n%s}' % (indent) |
Mark Lobodzinski | 4c7ac0a | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 1038 | table_type = '' |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 1039 | if proto_is_global(proto): |
Mark Lobodzinski | 4c7ac0a | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 1040 | table_type = 'instance' |
| 1041 | else: |
| 1042 | table_type = 'device' |
Jon Ashburn | 71836d9 | 2015-05-12 17:23:55 -0600 | [diff] [blame] | 1043 | |
Mark Lobodzinski | 4c7ac0a | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 1044 | if proto.name == "CreateInstance": |
| 1045 | dispatch_param = '*' + proto.params[1].name |
| 1046 | else: |
| 1047 | dispatch_param = proto.params[0].name |
| 1048 | |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 1049 | if proto.name == "CreateDevice": |
Courtney Goeltzenleuchter | 0de9e21 | 2015-06-26 15:07:53 -0600 | [diff] [blame] | 1050 | funcs.append('%s\n' % self.lineinfo.get()) |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 1051 | funcs.append('%s%s\n' |
| 1052 | '{\n' |
| 1053 | ' using namespace StreamControl;\n' |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 1054 | ' %sdevice_dispatch_table(*pDevice)->%s;\n' |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 1055 | ' if (result == VK_SUCCESS)\n' |
| 1056 | ' createDeviceRegisterExtensions(pCreateInfo, *pDevice);\n' |
| 1057 | ' %s%s%s\n' |
| 1058 | '%s' |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 1059 | '}' % (qual, decl, ret_val, proto.c_call(), f_open, log_func, f_close, stmt)) |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 1060 | elif proto.name == "DestroyDevice": |
Mark Lobodzinski | 4c7ac0a | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 1061 | funcs.append('%s%s\n' |
| 1062 | '{\n' |
| 1063 | ' using namespace StreamControl;\n' |
Courtney Goeltzenleuchter | 0daf228 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 1064 | ' dispatch_key key = get_dispatch_key(device);\n' |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 1065 | ' VkLayerDispatchTable *pDisp = %s_dispatch_table(%s);\n' |
| 1066 | ' %spDisp->%s;\n' |
| 1067 | ' deviceExtMap.erase(pDisp);\n' |
Courtney Goeltzenleuchter | 0daf228 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 1068 | ' destroy_device_dispatch_table(key);\n' |
Mark Lobodzinski | 4c7ac0a | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 1069 | ' %s%s%s\n' |
| 1070 | '%s' |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 1071 | '}' % (qual, decl, table_type, dispatch_param, ret_val, proto.c_call(), f_open, log_func, f_close, stmt)) |
Mark Lobodzinski | 4c7ac0a | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 1072 | elif proto.name == "DestroyInstance": |
| 1073 | funcs.append('%s%s\n' |
| 1074 | '{\n' |
| 1075 | ' using namespace StreamControl;\n' |
Courtney Goeltzenleuchter | 0daf228 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 1076 | ' dispatch_key key = get_dispatch_key(instance);\n' |
Mark Lobodzinski | 4c7ac0a | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 1077 | ' %s%s_dispatch_table(%s)->%s;\n' |
Courtney Goeltzenleuchter | 0daf228 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 1078 | ' destroy_instance_dispatch_table(key);\n' |
Mark Lobodzinski | 4c7ac0a | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 1079 | ' %s%s%s\n' |
| 1080 | '%s' |
| 1081 | '}' % (qual, decl, ret_val, table_type, dispatch_param, proto.c_call(), f_open, log_func, f_close, stmt)) |
| 1082 | else: |
| 1083 | funcs.append('%s%s\n' |
| 1084 | '{\n' |
| 1085 | ' using namespace StreamControl;\n' |
| 1086 | ' %s%s_dispatch_table(%s)->%s;\n' |
Jon Ashburn | bacb0f5 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 1087 | ' %s%s%s\n' |
| 1088 | '%s' |
Mark Lobodzinski | 4c7ac0a | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 1089 | '}' % (qual, decl, ret_val, table_type, dispatch_param, proto.c_call(), f_open, log_func, f_close, stmt)) |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 1090 | return "\n\n".join(funcs) |
| 1091 | |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1092 | def generate_body(self): |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 1093 | self.layer_name = "APIDump" |
Ian Elliott | 1064fe3 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 1094 | extensions=[('wsi_enabled', |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 1095 | ['vkCreateSwapchainKHR', 'vkDestroySwapchainKHR', |
| 1096 | 'vkGetSwapchainImagesKHR', 'vkQueuePresentKHR'])] |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 1097 | body = [self.generate_init(), |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1098 | self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"), |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 1099 | self._generate_layer_gpa_function(extensions)] |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1100 | return "\n\n".join(body) |
| 1101 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1102 | class ObjectTrackerSubcommand(Subcommand): |
| 1103 | def generate_header(self): |
| 1104 | header_txt = [] |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1105 | header_txt.append('%s' % self.lineinfo.get()) |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1106 | header_txt.append('#include <stdio.h>') |
| 1107 | header_txt.append('#include <stdlib.h>') |
| 1108 | header_txt.append('#include <string.h>') |
| 1109 | header_txt.append('#include <inttypes.h>') |
| 1110 | header_txt.append('') |
| 1111 | header_txt.append('#include "vulkan.h"') |
Tobin Ehlis | b835d1b | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 1112 | header_txt.append('#include "vk_loader_platform.h"') |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1113 | header_txt.append('') |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1114 | header_txt.append('#include <unordered_map>') |
| 1115 | header_txt.append('using namespace std;') |
Ian Elliott | 655cad7 | 2015-02-12 17:08:34 -0700 | [diff] [blame] | 1116 | header_txt.append('// The following is #included again to catch certain OS-specific functions being used:') |
Tobin Ehlis | b835d1b | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 1117 | header_txt.append('#include "vk_loader_platform.h"') |
Tobin Ehlis | a0cb02e | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 1118 | header_txt.append('#include "vk_layer_config.h"') |
| 1119 | header_txt.append('#include "vk_layer_msg.h"') |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1120 | header_txt.append('#include "vk_debug_report_lunarg.h"') |
Tobin Ehlis | a0cb02e | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 1121 | header_txt.append('#include "vk_layer_table.h"') |
| 1122 | header_txt.append('#include "vk_layer_data.h"') |
| 1123 | header_txt.append('#include "vk_layer_logging.h"') |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1124 | header_txt.append('') |
| 1125 | # NOTE: The non-autoGenerated code is in the object_track.h header file |
| 1126 | header_txt.append('#include "object_track.h"') |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1127 | header_txt.append('') |
Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 1128 | header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(initOnce);') |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1129 | header_txt.append('') |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1130 | return "\n".join(header_txt) |
| 1131 | |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1132 | def generate_maps(self): |
| 1133 | maps_txt = [] |
| 1134 | for o in vulkan.core.objects: |
| 1135 | maps_txt.append('unordered_map<const void*, OBJTRACK_NODE*> %sMap;' % (o)) |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 1136 | maps_txt.append('unordered_map<const void*, OBJTRACK_NODE*> VkSwapchainKHRMap;') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1137 | return "\n".join(maps_txt) |
| 1138 | |
| 1139 | def generate_procs(self): |
| 1140 | procs_txt = [] |
| 1141 | for o in vulkan.core.objects: |
| 1142 | procs_txt.append('%s' % self.lineinfo.get()) |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1143 | if o in vulkan.object_dispatch_list: |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1144 | procs_txt.append('static void create_obj(%s dispatchable_object, %s vkObj, VkDbgObjectType objType)' % (o, o)) |
| 1145 | procs_txt.append('{') |
Courtney Goeltzenleuchter | dee721d | 2015-08-26 15:09:25 -0600 | [diff] [blame] | 1146 | procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_INFO_BIT, objType, reinterpret_cast<uint64_t>(vkObj), 0, OBJTRACK_NONE, "OBJTRACK",') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1147 | procs_txt.append(' "OBJ[%llu] : CREATE %s object 0x%" PRIxLEAST64 , object_track_index++, string_VkDbgObjectType(objType),') |
Courtney Goeltzenleuchter | dee721d | 2015-08-26 15:09:25 -0600 | [diff] [blame] | 1148 | procs_txt.append(' reinterpret_cast<uint64_t>(vkObj));') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1149 | else: |
| 1150 | procs_txt.append('static void create_obj(VkDevice dispatchable_object, %s vkObj, VkDbgObjectType objType)' % (o)) |
| 1151 | procs_txt.append('{') |
| 1152 | procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_INFO_BIT, objType, vkObj.handle, 0, OBJTRACK_NONE, "OBJTRACK",') |
| 1153 | procs_txt.append(' "OBJ[%llu] : CREATE %s object 0x%" PRIxLEAST64 , object_track_index++, string_VkDbgObjectType(objType),') |
Tony Barbour | 343d621 | 2015-07-10 18:32:33 -0600 | [diff] [blame] | 1154 | procs_txt.append(' vkObj.handle);') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1155 | procs_txt.append('') |
| 1156 | procs_txt.append(' OBJTRACK_NODE* pNewObjNode = new OBJTRACK_NODE;') |
| 1157 | procs_txt.append(' pNewObjNode->objType = objType;') |
| 1158 | procs_txt.append(' pNewObjNode->status = OBJSTATUS_NONE;') |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1159 | if o in vulkan.object_dispatch_list: |
Courtney Goeltzenleuchter | dee721d | 2015-08-26 15:09:25 -0600 | [diff] [blame] | 1160 | procs_txt.append(' pNewObjNode->vkObj = reinterpret_cast<uint64_t>(vkObj);') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1161 | procs_txt.append(' %sMap[vkObj] = pNewObjNode;' % (o)) |
| 1162 | else: |
Tony Barbour | 343d621 | 2015-07-10 18:32:33 -0600 | [diff] [blame] | 1163 | procs_txt.append(' pNewObjNode->vkObj = vkObj.handle;') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1164 | procs_txt.append(' %sMap[(void*)vkObj.handle] = pNewObjNode;' % (o)) |
| 1165 | procs_txt.append(' uint32_t objIndex = objTypeToIndex(objType);') |
| 1166 | procs_txt.append(' numObjs[objIndex]++;') |
| 1167 | procs_txt.append(' numTotalObjs++;') |
| 1168 | procs_txt.append('}') |
| 1169 | procs_txt.append('') |
| 1170 | procs_txt.append('%s' % self.lineinfo.get()) |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1171 | if o in vulkan.object_dispatch_list: |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1172 | procs_txt.append('static void validate_object(%s dispatchable_object, %s object)' % (o, o)) |
| 1173 | else: |
| 1174 | procs_txt.append('static void validate_object(VkDevice dispatchable_object, %s object)' % (o)) |
| 1175 | procs_txt.append('{') |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1176 | if o in vulkan.object_dispatch_list: |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1177 | procs_txt.append(' if (%sMap.find(object) == %sMap.end()) {' % (o, o)) |
Courtney Goeltzenleuchter | dee721d | 2015-08-26 15:09:25 -0600 | [diff] [blame] | 1178 | procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, reinterpret_cast<uint64_t>(object), 0, OBJTRACK_INVALID_OBJECT, "OBJTRACK",') |
| 1179 | procs_txt.append(' "Invalid %s Object %%p",reinterpret_cast<uint64_t>(object));' % o) |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1180 | else: |
| 1181 | procs_txt.append(' if (%sMap.find((void*)object.handle) == %sMap.end()) {' % (o, o)) |
| 1182 | procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, object.handle, 0, OBJTRACK_INVALID_OBJECT, "OBJTRACK",') |
Tony Barbour | 343d621 | 2015-07-10 18:32:33 -0600 | [diff] [blame] | 1183 | procs_txt.append(' "Invalid %s Object %%p", object.handle);' % o) |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1184 | procs_txt.append(' }') |
| 1185 | procs_txt.append('}') |
| 1186 | procs_txt.append('') |
| 1187 | procs_txt.append('') |
| 1188 | procs_txt.append('%s' % self.lineinfo.get()) |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1189 | if o in vulkan.object_dispatch_list: |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1190 | procs_txt.append('static void destroy_obj(%s dispatchable_object, %s object)' % (o, o)) |
| 1191 | else: |
| 1192 | procs_txt.append('static void destroy_obj(VkDevice dispatchable_object, %s object)' % (o)) |
| 1193 | procs_txt.append('{') |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1194 | if o in vulkan.object_dispatch_list: |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1195 | procs_txt.append(' if (%sMap.find(object) != %sMap.end()) {' % (o, o)) |
| 1196 | procs_txt.append(' OBJTRACK_NODE* pNode = %sMap[object];' % (o)) |
| 1197 | else: |
| 1198 | procs_txt.append(' if (%sMap.find((void*)object.handle) != %sMap.end()) {' % (o, o)) |
| 1199 | procs_txt.append(' OBJTRACK_NODE* pNode = %sMap[(void*)object.handle];' % (o)) |
| 1200 | procs_txt.append(' uint32_t objIndex = objTypeToIndex(pNode->objType);') |
| 1201 | procs_txt.append(' assert(numTotalObjs > 0);') |
| 1202 | procs_txt.append(' numTotalObjs--;') |
| 1203 | procs_txt.append(' assert(numObjs[objIndex] > 0);') |
| 1204 | procs_txt.append(' numObjs[objIndex]--;') |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1205 | if o in vulkan.object_dispatch_list: |
Courtney Goeltzenleuchter | dee721d | 2015-08-26 15:09:25 -0600 | [diff] [blame] | 1206 | procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_INFO_BIT, pNode->objType, reinterpret_cast<uint64_t>(object), 0, OBJTRACK_NONE, "OBJTRACK",') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1207 | procs_txt.append(' "OBJ_STAT Destroy %s obj 0x%" PRIxLEAST64 " (%lu total objs remain & %lu %s objs).",') |
Courtney Goeltzenleuchter | dee721d | 2015-08-26 15:09:25 -0600 | [diff] [blame] | 1208 | procs_txt.append(' string_VkDbgObjectType(pNode->objType), reinterpret_cast<uint64_t>(object), numTotalObjs, numObjs[objIndex],') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1209 | else: |
| 1210 | procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_INFO_BIT, pNode->objType, object.handle, 0, OBJTRACK_NONE, "OBJTRACK",') |
| 1211 | procs_txt.append(' "OBJ_STAT Destroy %s obj 0x%" PRIxLEAST64 " (%lu total objs remain & %lu %s objs).",') |
Tony Barbour | 343d621 | 2015-07-10 18:32:33 -0600 | [diff] [blame] | 1212 | procs_txt.append(' string_VkDbgObjectType(pNode->objType), object.handle, numTotalObjs, numObjs[objIndex],') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1213 | procs_txt.append(' string_VkDbgObjectType(pNode->objType));') |
| 1214 | procs_txt.append(' delete pNode;') |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1215 | if o in vulkan.object_dispatch_list: |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1216 | procs_txt.append(' %sMap.erase(object);' % (o)) |
| 1217 | procs_txt.append(' } else {') |
Courtney Goeltzenleuchter | dee721d | 2015-08-26 15:09:25 -0600 | [diff] [blame] | 1218 | procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, reinterpret_cast<uint64_t>(object), 0, OBJTRACK_NONE, "OBJTRACK",') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1219 | procs_txt.append(' "Unable to remove obj 0x%" PRIxLEAST64 ". Was it created? Has it already been destroyed?",') |
Courtney Goeltzenleuchter | dee721d | 2015-08-26 15:09:25 -0600 | [diff] [blame] | 1220 | procs_txt.append(' reinterpret_cast<uint64_t>(object));') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1221 | procs_txt.append(' }') |
| 1222 | else: |
| 1223 | procs_txt.append(' %sMap.erase((void*)object.handle);' % (o)) |
| 1224 | procs_txt.append(' } else {') |
| 1225 | procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, object.handle, 0, OBJTRACK_NONE, "OBJTRACK",') |
| 1226 | procs_txt.append(' "Unable to remove obj 0x%" PRIxLEAST64 ". Was it created? Has it already been destroyed?",') |
Tony Barbour | 343d621 | 2015-07-10 18:32:33 -0600 | [diff] [blame] | 1227 | procs_txt.append(' object.handle);') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1228 | procs_txt.append(' }') |
| 1229 | procs_txt.append('}') |
| 1230 | procs_txt.append('') |
| 1231 | procs_txt.append('%s' % self.lineinfo.get()) |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1232 | if o in vulkan.object_dispatch_list: |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1233 | procs_txt.append('static void set_status(%s dispatchable_object, %s object, VkDbgObjectType objType, ObjectStatusFlags status_flag)' % (o, o)) |
| 1234 | procs_txt.append('{') |
| 1235 | procs_txt.append(' if (object != VK_NULL_HANDLE) {') |
| 1236 | procs_txt.append(' if (%sMap.find(object) != %sMap.end()) {' % (o, o)) |
| 1237 | procs_txt.append(' OBJTRACK_NODE* pNode = %sMap[object];' % (o)) |
| 1238 | else: |
| 1239 | procs_txt.append('static void set_status(VkDevice dispatchable_object, %s object, VkDbgObjectType objType, ObjectStatusFlags status_flag)' % (o)) |
| 1240 | procs_txt.append('{') |
Dana Jansens | 10dddd7 | 2015-07-30 13:21:41 -0700 | [diff] [blame] | 1241 | procs_txt.append(' if (object != VK_NULL_HANDLE) {') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1242 | procs_txt.append(' if (%sMap.find((void*)object.handle) != %sMap.end()) {' % (o, o)) |
| 1243 | procs_txt.append(' OBJTRACK_NODE* pNode = %sMap[(void*)object.handle];' % (o)) |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1244 | procs_txt.append(' pNode->status |= status_flag;') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1245 | procs_txt.append(' return;') |
| 1246 | procs_txt.append(' }') |
| 1247 | procs_txt.append(' else {') |
| 1248 | procs_txt.append(' // If we do not find it print an error') |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1249 | if o in vulkan.object_dispatch_list: |
Courtney Goeltzenleuchter | dee721d | 2015-08-26 15:09:25 -0600 | [diff] [blame] | 1250 | procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, reinterpret_cast<uint64_t>(object), 0, OBJTRACK_NONE, "OBJTRACK",') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1251 | procs_txt.append(' "Unable to set status for non-existent object 0x%" PRIxLEAST64 " of %s type",') |
Courtney Goeltzenleuchter | dee721d | 2015-08-26 15:09:25 -0600 | [diff] [blame] | 1252 | procs_txt.append(' reinterpret_cast<uint64_t>(object), string_VkDbgObjectType(objType));') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1253 | else: |
| 1254 | procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, object.handle, 0, OBJTRACK_NONE, "OBJTRACK",') |
| 1255 | procs_txt.append(' "Unable to set status for non-existent object 0x%" PRIxLEAST64 " of %s type",') |
Tony Barbour | 343d621 | 2015-07-10 18:32:33 -0600 | [diff] [blame] | 1256 | procs_txt.append(' object.handle, string_VkDbgObjectType(objType));') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1257 | procs_txt.append(' }') |
| 1258 | procs_txt.append(' }') |
| 1259 | procs_txt.append('}') |
| 1260 | procs_txt.append('') |
| 1261 | procs_txt.append('%s' % self.lineinfo.get()) |
| 1262 | procs_txt.append('static VkBool32 validate_status(') |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1263 | if o in vulkan.object_dispatch_list: |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1264 | procs_txt.append('%s dispatchable_object, %s object,' % (o, o)) |
| 1265 | else: |
| 1266 | procs_txt.append('VkDevice dispatchable_object, %s object,' % (o)) |
| 1267 | procs_txt.append(' VkDbgObjectType objType,') |
| 1268 | procs_txt.append(' ObjectStatusFlags status_mask,') |
| 1269 | procs_txt.append(' ObjectStatusFlags status_flag,') |
| 1270 | procs_txt.append(' VkFlags msg_flags,') |
| 1271 | procs_txt.append(' OBJECT_TRACK_ERROR error_code,') |
| 1272 | procs_txt.append(' const char *fail_msg)') |
| 1273 | procs_txt.append('{') |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1274 | if o in vulkan.object_dispatch_list: |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1275 | procs_txt.append(' if (%sMap.find(object) != %sMap.end()) {' % (o, o)) |
| 1276 | procs_txt.append(' OBJTRACK_NODE* pNode = %sMap[object];' % (o)) |
| 1277 | else: |
| 1278 | procs_txt.append(' if (%sMap.find((void*)object.handle) != %sMap.end()) {' % (o, o)) |
| 1279 | procs_txt.append(' OBJTRACK_NODE* pNode = %sMap[(void*)object.handle];' % (o)) |
| 1280 | procs_txt.append(' if ((pNode->status & status_mask) != status_flag) {') |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1281 | if o in vulkan.object_dispatch_list: |
Courtney Goeltzenleuchter | dee721d | 2015-08-26 15:09:25 -0600 | [diff] [blame] | 1282 | procs_txt.append(' log_msg(mdd(dispatchable_object), msg_flags, pNode->objType, reinterpret_cast<uint64_t>(object), 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK",') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1283 | procs_txt.append(' "OBJECT VALIDATION WARNING: %s object 0x%" PRIxLEAST64 ": %s", string_VkDbgObjectType(objType),') |
Courtney Goeltzenleuchter | dee721d | 2015-08-26 15:09:25 -0600 | [diff] [blame] | 1284 | procs_txt.append(' reinterpret_cast<uint64_t>(object), fail_msg);') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1285 | else: |
| 1286 | procs_txt.append(' log_msg(mdd(dispatchable_object), msg_flags, pNode->objType, object.handle, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK",') |
| 1287 | procs_txt.append(' "OBJECT VALIDATION WARNING: %s object 0x%" PRIxLEAST64 ": %s", string_VkDbgObjectType(objType),') |
Tony Barbour | 343d621 | 2015-07-10 18:32:33 -0600 | [diff] [blame] | 1288 | procs_txt.append(' object.handle, fail_msg);') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1289 | procs_txt.append(' return VK_FALSE;') |
| 1290 | procs_txt.append(' }') |
| 1291 | procs_txt.append(' return VK_TRUE;') |
| 1292 | procs_txt.append(' }') |
| 1293 | procs_txt.append(' else {') |
| 1294 | procs_txt.append(' // If we do not find it print an error') |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1295 | if o in vulkan.object_dispatch_list: |
Courtney Goeltzenleuchter | dee721d | 2015-08-26 15:09:25 -0600 | [diff] [blame] | 1296 | procs_txt.append(' log_msg(mdd(dispatchable_object), msg_flags, (VkDbgObjectType) 0, reinterpret_cast<uint64_t>(object), 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK",') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1297 | procs_txt.append(' "Unable to obtain status for non-existent object 0x%" PRIxLEAST64 " of %s type",') |
Courtney Goeltzenleuchter | dee721d | 2015-08-26 15:09:25 -0600 | [diff] [blame] | 1298 | procs_txt.append(' reinterpret_cast<uint64_t>(object), string_VkDbgObjectType(objType));') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1299 | else: |
| 1300 | procs_txt.append(' log_msg(mdd(dispatchable_object), msg_flags, (VkDbgObjectType) 0, object.handle, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK",') |
| 1301 | procs_txt.append(' "Unable to obtain status for non-existent object 0x%" PRIxLEAST64 " of %s type",') |
Tony Barbour | 343d621 | 2015-07-10 18:32:33 -0600 | [diff] [blame] | 1302 | procs_txt.append(' object.handle, string_VkDbgObjectType(objType));') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1303 | procs_txt.append(' return VK_FALSE;') |
| 1304 | procs_txt.append(' }') |
| 1305 | procs_txt.append('}') |
| 1306 | procs_txt.append('') |
| 1307 | procs_txt.append('%s' % self.lineinfo.get()) |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1308 | if o in vulkan.object_dispatch_list: |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1309 | procs_txt.append('static void reset_status(%s dispatchable_object, %s object, VkDbgObjectType objType, ObjectStatusFlags status_flag)' % (o, o)) |
| 1310 | procs_txt.append('{') |
| 1311 | procs_txt.append(' if (%sMap.find(object) != %sMap.end()) {' % (o, o)) |
| 1312 | procs_txt.append(' OBJTRACK_NODE* pNode = %sMap[object];' % (o)) |
| 1313 | else: |
| 1314 | procs_txt.append('static void reset_status(VkDevice dispatchable_object, %s object, VkDbgObjectType objType, ObjectStatusFlags status_flag)' % (o)) |
| 1315 | procs_txt.append('{') |
| 1316 | procs_txt.append(' if (%sMap.find((void*)object.handle) != %sMap.end()) {' % (o, o)) |
| 1317 | procs_txt.append(' OBJTRACK_NODE* pNode = %sMap[(void*)object.handle];' % (o)) |
| 1318 | procs_txt.append(' pNode->status &= ~status_flag;') |
| 1319 | procs_txt.append(' return;') |
| 1320 | procs_txt.append(' }') |
| 1321 | procs_txt.append(' else {') |
| 1322 | procs_txt.append(' // If we do not find it print an error') |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1323 | if o in vulkan.object_dispatch_list: |
Courtney Goeltzenleuchter | dee721d | 2015-08-26 15:09:25 -0600 | [diff] [blame] | 1324 | procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_ERROR_BIT, objType, reinterpret_cast<uint64_t>(object), 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK",') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1325 | procs_txt.append(' "Unable to reset status for non-existent object 0x%" PRIxLEAST64 " of %s type",') |
Courtney Goeltzenleuchter | dee721d | 2015-08-26 15:09:25 -0600 | [diff] [blame] | 1326 | procs_txt.append(' reinterpret_cast<uint64_t>(object), string_VkDbgObjectType(objType));') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1327 | else: |
| 1328 | procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_ERROR_BIT, objType, object.handle, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK",') |
| 1329 | procs_txt.append(' "Unable to reset status for non-existent object 0x%" PRIxLEAST64 " of %s type",') |
Tony Barbour | 343d621 | 2015-07-10 18:32:33 -0600 | [diff] [blame] | 1330 | procs_txt.append(' object.handle, string_VkDbgObjectType(objType));') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1331 | procs_txt.append(' }') |
| 1332 | procs_txt.append('}') |
| 1333 | procs_txt.append('') |
| 1334 | return "\n".join(procs_txt) |
| 1335 | |
Mark Lobodzinski | 64d5775 | 2015-07-17 11:51:24 -0600 | [diff] [blame] | 1336 | def generate_destroy_instance(self): |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1337 | gedi_txt = [] |
| 1338 | gedi_txt.append('%s' % self.lineinfo.get()) |
Mark Lobodzinski | 64d5775 | 2015-07-17 11:51:24 -0600 | [diff] [blame] | 1339 | gedi_txt.append('VkResult vkDestroyInstance(') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1340 | gedi_txt.append('VkInstance instance)') |
| 1341 | gedi_txt.append('{') |
| 1342 | gedi_txt.append(' loader_platform_thread_lock_mutex(&objLock);') |
| 1343 | gedi_txt.append(' validate_object(instance, instance);') |
| 1344 | gedi_txt.append('') |
| 1345 | gedi_txt.append(' destroy_obj(instance, instance);') |
| 1346 | gedi_txt.append(' // Report any remaining objects in LL') |
| 1347 | for o in vulkan.core.objects: |
| 1348 | if o in ['VkPhysicalDevice', 'VkQueue']: |
| 1349 | continue |
| 1350 | gedi_txt.append(' for (auto it = %sMap.begin(); it != %sMap.end(); ++it) {' % (o, o)) |
| 1351 | gedi_txt.append(' OBJTRACK_NODE* pNode = it->second;') |
| 1352 | gedi_txt.append(' log_msg(mid(instance), VK_DBG_REPORT_ERROR_BIT, pNode->objType, pNode->vkObj, 0, OBJTRACK_OBJECT_LEAK, "OBJTRACK",') |
| 1353 | gedi_txt.append(' "OBJ ERROR : %s object 0x%" PRIxLEAST64 " has not been destroyed.", string_VkDbgObjectType(pNode->objType),') |
Tony Barbour | 343d621 | 2015-07-10 18:32:33 -0600 | [diff] [blame] | 1354 | gedi_txt.append(' pNode->vkObj);') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1355 | gedi_txt.append(' }') |
| 1356 | gedi_txt.append('') |
| 1357 | gedi_txt.append(' dispatch_key key = get_dispatch_key(instance);') |
| 1358 | gedi_txt.append(' VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(ObjectTracker_instance_table_map, instance);') |
| 1359 | gedi_txt.append(' VkResult result = pInstanceTable->DestroyInstance(instance);') |
| 1360 | gedi_txt.append('') |
| 1361 | gedi_txt.append(' // Clean up logging callback, if any') |
| 1362 | gedi_txt.append(' layer_data *my_data = get_my_data_ptr(key, layer_data_map);') |
| 1363 | gedi_txt.append(' if (my_data->logging_callback) {') |
| 1364 | gedi_txt.append(' layer_destroy_msg_callback(my_data->report_data, my_data->logging_callback);') |
| 1365 | gedi_txt.append(' }') |
| 1366 | gedi_txt.append('') |
| 1367 | gedi_txt.append(' layer_debug_report_destroy_instance(mid(instance));') |
| 1368 | gedi_txt.append(' layer_data_map.erase(pInstanceTable);') |
| 1369 | gedi_txt.append('') |
| 1370 | gedi_txt.append(' ObjectTracker_instance_table_map.erase(key);') |
| 1371 | gedi_txt.append(' assert(ObjectTracker_instance_table_map.size() == 0 && "Should not have any instance mappings hanging around");') |
| 1372 | gedi_txt.append('') |
| 1373 | gedi_txt.append(' loader_platform_thread_unlock_mutex(&objLock);') |
| 1374 | gedi_txt.append(' return result;') |
| 1375 | gedi_txt.append('}') |
| 1376 | gedi_txt.append('') |
| 1377 | return "\n".join(gedi_txt) |
| 1378 | |
Mark Lobodzinski | 64d5775 | 2015-07-17 11:51:24 -0600 | [diff] [blame] | 1379 | def generate_destroy_device(self): |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1380 | gedd_txt = [] |
| 1381 | gedd_txt.append('%s' % self.lineinfo.get()) |
Mark Lobodzinski | 64d5775 | 2015-07-17 11:51:24 -0600 | [diff] [blame] | 1382 | gedd_txt.append('VkResult vkDestroyDevice(') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1383 | gedd_txt.append('VkDevice device)') |
| 1384 | gedd_txt.append('{') |
| 1385 | gedd_txt.append(' loader_platform_thread_lock_mutex(&objLock);') |
| 1386 | gedd_txt.append(' validate_object(device, device);') |
| 1387 | gedd_txt.append('') |
| 1388 | gedd_txt.append(' destroy_obj(device, device);') |
| 1389 | gedd_txt.append(' // Report any remaining objects in LL') |
| 1390 | for o in vulkan.core.objects: |
Mark Lobodzinski | 64d5775 | 2015-07-17 11:51:24 -0600 | [diff] [blame] | 1391 | if o in ['VkInstance', 'VkPhysicalDevice', 'VkQueue']: |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1392 | continue |
| 1393 | gedd_txt.append(' for (auto it = %sMap.begin(); it != %sMap.end(); ++it) {' % (o, o)) |
| 1394 | gedd_txt.append(' OBJTRACK_NODE* pNode = it->second;') |
| 1395 | gedd_txt.append(' log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, pNode->objType, pNode->vkObj, 0, OBJTRACK_OBJECT_LEAK, "OBJTRACK",') |
| 1396 | gedd_txt.append(' "OBJ ERROR : %s object 0x%" PRIxLEAST64 " has not been destroyed.", string_VkDbgObjectType(pNode->objType),') |
Tony Barbour | 343d621 | 2015-07-10 18:32:33 -0600 | [diff] [blame] | 1397 | gedd_txt.append(' pNode->vkObj);') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1398 | gedd_txt.append(' }') |
| 1399 | gedd_txt.append('') |
| 1400 | gedd_txt.append(" // Clean up Queue's MemRef Linked Lists") |
| 1401 | gedd_txt.append(' destroyQueueMemRefLists();') |
| 1402 | gedd_txt.append('') |
| 1403 | gedd_txt.append(' loader_platform_thread_unlock_mutex(&objLock);') |
| 1404 | gedd_txt.append('') |
| 1405 | gedd_txt.append(' dispatch_key key = get_dispatch_key(device);') |
| 1406 | gedd_txt.append(' VkLayerDispatchTable *pDisp = get_dispatch_table(ObjectTracker_device_table_map, device);') |
| 1407 | gedd_txt.append(' VkResult result = pDisp->DestroyDevice(device);') |
| 1408 | gedd_txt.append(' ObjectTracker_device_table_map.erase(key);') |
| 1409 | gedd_txt.append(' assert(ObjectTracker_device_table_map.size() == 0 && "Should not have any instance mappings hanging around");') |
| 1410 | gedd_txt.append('') |
| 1411 | gedd_txt.append(' return result;') |
| 1412 | gedd_txt.append('}') |
| 1413 | gedd_txt.append('') |
| 1414 | return "\n".join(gedd_txt) |
| 1415 | |
| 1416 | def generate_command_buffer_validates(self): |
| 1417 | cbv_txt = [] |
| 1418 | cbv_txt.append('%s' % self.lineinfo.get()) |
Cody Northrop | 271ba75 | 2015-08-26 10:01:32 -0600 | [diff] [blame] | 1419 | for o in ['VkPipeline', 'VkDynamicViewportState', 'VkDynamicLineWidthState', 'VkDynamicDepthBiasState', 'VkDynamicBlendState', 'VkDynamicDepthBoundsState', 'VkDynamicStencilState', |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1420 | 'VkPipelineLayout', 'VkBuffer', 'VkEvent', 'VkQueryPool', 'VkRenderPass', 'VkFramebuffer']: |
| 1421 | cbv_txt.append('static void validate_object(VkCmdBuffer dispatchable_object, %s object)' % (o)) |
| 1422 | cbv_txt.append('{') |
| 1423 | cbv_txt.append(' if (%sMap.find((void*)object.handle) == %sMap.end()) {' % (o, o)) |
| 1424 | cbv_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, object.handle, 0, OBJTRACK_INVALID_OBJECT, "OBJTRACK",') |
Tony Barbour | 343d621 | 2015-07-10 18:32:33 -0600 | [diff] [blame] | 1425 | cbv_txt.append(' "Invalid %s Object %%p", object.handle);' % (o)) |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1426 | cbv_txt.append(' }') |
| 1427 | cbv_txt.append('}') |
| 1428 | cbv_txt.append('') |
| 1429 | return "\n".join(cbv_txt) |
| 1430 | |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 1431 | def generate_intercept(self, proto, qual): |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1432 | if proto.name in [ 'DbgCreateMsgCallback', 'GetGlobalLayerProperties', 'GetGlobalExtensionProperties','GetPhysicalDeviceLayerProperties', 'GetPhysicalDeviceExtensionProperties' ]: |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1433 | # use default version |
| 1434 | return None |
Mark Lobodzinski | 7c75b85 | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 1435 | |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1436 | # Create map of object names to object type enums of the form VkName : VkObjectTypeName |
| 1437 | obj_type_mapping = {base_t : base_t.replace("Vk", "VkObjectType") for base_t in vulkan.object_type_list} |
Mark Lobodzinski | 7c75b85 | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 1438 | # Convert object type enum names from UpperCamelCase to UPPER_CASE_WITH_UNDERSCORES |
| 1439 | for objectName, objectTypeEnum in obj_type_mapping.items(): |
| 1440 | obj_type_mapping[objectName] = ucc_to_U_C_C(objectTypeEnum); |
| 1441 | # Command Buffer Object doesn't follow the rule. |
| 1442 | obj_type_mapping['VkCmdBuffer'] = "VK_OBJECT_TYPE_COMMAND_BUFFER" |
Courtney Goeltzenleuchter | ee4027d | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 1443 | obj_type_mapping['VkShaderModule'] = "VK_OBJECT_TYPE_SHADER_MODULE" |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1444 | |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1445 | explicit_object_tracker_functions = [ |
| 1446 | "CreateInstance", |
Cody Northrop | d080288 | 2015-08-03 17:04:53 -0600 | [diff] [blame] | 1447 | "GetPhysicalDeviceQueueFamilyProperties", |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1448 | "CreateDevice", |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1449 | "GetDeviceQueue", |
| 1450 | "QueueSubmit", |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1451 | "QueueBindSparseImageMemory", |
| 1452 | "QueueBindSparseBufferMemory", |
| 1453 | "GetFenceStatus", |
| 1454 | "WaitForFences", |
| 1455 | "AllocDescriptorSets", |
Tony Barbour | 770f80d | 2015-07-20 10:52:13 -0600 | [diff] [blame] | 1456 | "FreeDescriptorSets", |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1457 | "MapMemory", |
| 1458 | "UnmapMemory", |
| 1459 | "FreeMemory", |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 1460 | "DestroySwapchainKHR" |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1461 | ] |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1462 | decl = proto.c_func(prefix="vk", attr="VKAPI") |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1463 | param0_name = proto.params[0].name |
Mark Lobodzinski | 48bd16d | 2015-05-08 09:12:28 -0500 | [diff] [blame] | 1464 | using_line = '' |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1465 | create_line = '' |
Mark Lobodzinski | 64d5775 | 2015-07-17 11:51:24 -0600 | [diff] [blame] | 1466 | destroy_line = '' |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1467 | # Dict below tracks params that are vk objects. Dict is "loop count"->["params w/ that loop count"] where '0' is params that aren't in an array |
| 1468 | loop_params = defaultdict(list) # Dict uses loop count as key to make final code generation cleaner so params shared in single loop where needed |
Tobin Ehlis | 2717d13 | 2015-07-10 18:25:07 -0600 | [diff] [blame] | 1469 | # TODO : For now skipping objs that can be NULL. Really should check these and have special case that allows them to be NULL |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1470 | # or better yet, these should be encoded into an API json definition and we generate checks from there |
| 1471 | # Until then, this is a dict where each func name is a list of object params that can be null (so don't need to be validated) |
| 1472 | # param names may be directly passed to the function, or may be a field in a struct param |
| 1473 | valid_null_object_names = {'CreateGraphicsPipelines' : ['basePipelineHandle'], |
| 1474 | 'CreateComputePipelines' : ['basePipelineHandle'], |
| 1475 | 'BeginCommandBuffer' : ['renderPass', 'framebuffer'], |
| 1476 | } |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1477 | # TODO : A few of the skipped types are just "hard" cases that need some more work to support |
| 1478 | # Need to handle NULL fences on queue submit, binding null memory, and WSI Image objects |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1479 | param_count = 'NONE' # keep track of arrays passed directly into API functions |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1480 | for p in proto.params: |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1481 | if 'count' in p.name.lower(): |
| 1482 | param_count = p.name |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1483 | if p.ty in vulkan.core.objects and p.ty not in ['VkPhysicalDevice', 'VkQueue', 'VkFence', 'VkImage', 'VkDeviceMemory']: |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1484 | if proto.name not in valid_null_object_names or p.name not in valid_null_object_names[proto.name]: |
| 1485 | loop_params[0].append(p.name) |
Tobin Ehlis | 9d67594 | 2015-06-30 14:32:16 -0600 | [diff] [blame] | 1486 | elif vk_helper.is_type(p.ty.replace('const ', '').strip('*'), 'struct'): |
| 1487 | struct_type = p.ty.replace('const ', '').strip('*') |
| 1488 | if vk_helper.typedef_rev_dict[struct_type] in vk_helper.struct_dict: |
| 1489 | struct_type = vk_helper.typedef_rev_dict[struct_type] |
| 1490 | for m in sorted(vk_helper.struct_dict[struct_type]): |
| 1491 | if vk_helper.struct_dict[struct_type][m]['type'] in vulkan.core.objects and vk_helper.struct_dict[struct_type][m]['type'] not in ['VkPhysicalDevice', 'VkQueue', 'VkFence', 'VkImage', 'VkDeviceMemory']: |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1492 | if proto.name not in valid_null_object_names or vk_helper.struct_dict[struct_type][m]['name'] not in valid_null_object_names[proto.name]: |
| 1493 | # If we have a count and this param is a ptr w/ last letter 's', then this is a dynamically sized array param |
| 1494 | # This is not great, but gets the job done for now |
| 1495 | if param_count != 'NONE' and '*' in p.ty and 's' == p.name[-1]: |
| 1496 | param_name = '%s[i].%s' % (p.name, vk_helper.struct_dict[struct_type][m]['name']) |
Tobin Ehlis | 46d5362 | 2015-07-10 11:10:21 -0600 | [diff] [blame] | 1497 | else: |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1498 | param_name = '%s->%s' % (p.name, vk_helper.struct_dict[struct_type][m]['name']) |
| 1499 | if vk_helper.struct_dict[struct_type][m]['dyn_array']: |
| 1500 | loop_count = '%s->%s' % (p.name, vk_helper.struct_dict[struct_type][m]['array_size']) |
| 1501 | loop_params[loop_count].append(param_name) |
| 1502 | else: |
| 1503 | if '[' in param_name: # dynamic array param, set size |
| 1504 | loop_params[param_count].append(param_name) |
| 1505 | else: |
| 1506 | loop_params[0].append(param_name) |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1507 | funcs = [] |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1508 | mutex_unlock = False |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1509 | funcs.append('%s\n' % self.lineinfo.get()) |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1510 | if proto.name in explicit_object_tracker_functions: |
Jon Ashburn | 4d9f465 | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 1511 | funcs.append('%s%s\n' |
| 1512 | '{\n' |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1513 | ' return explicit_%s;\n' |
| 1514 | '}' % (qual, decl, proto.c_call())) |
| 1515 | return "".join(funcs) |
Mark Lobodzinski | 64d5775 | 2015-07-17 11:51:24 -0600 | [diff] [blame] | 1516 | elif 'DestroyInstance' in proto.name or 'DestroyDevice' in proto.name: |
| 1517 | return "" |
Jon Ashburn | 4d9f465 | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 1518 | else: |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1519 | if 'Create' in proto.name or 'Alloc' in proto.name: |
| 1520 | create_line = ' loader_platform_thread_lock_mutex(&objLock);\n' |
| 1521 | create_line += ' if (result == VK_SUCCESS) {\n' |
| 1522 | create_line += ' create_obj(%s, *%s, %s);\n' % (param0_name, proto.params[-1].name, obj_type_mapping[proto.params[-1].ty.strip('*').replace('const ', '')]) |
| 1523 | create_line += ' }\n' |
| 1524 | create_line += ' loader_platform_thread_unlock_mutex(&objLock);\n' |
Mark Lobodzinski | 64d5775 | 2015-07-17 11:51:24 -0600 | [diff] [blame] | 1525 | if 'Destroy' in proto.name: |
| 1526 | destroy_line = ' loader_platform_thread_lock_mutex(&objLock);\n' |
| 1527 | destroy_line += ' if (result == VK_SUCCESS) {\n' |
| 1528 | if 'DestroyCommandBuffer' in proto.name: |
| 1529 | destroy_line += ' destroy_obj(%s, %s);\n' % (proto.params[-1].name, proto.params[-1].name) |
| 1530 | else: |
| 1531 | destroy_line += ' destroy_obj(%s, %s);\n' % (param0_name, proto.params[-1].name) |
| 1532 | destroy_line += ' }\n' |
| 1533 | destroy_line += ' loader_platform_thread_unlock_mutex(&objLock);\n' |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1534 | if len(loop_params) > 0: |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1535 | if not mutex_unlock: |
| 1536 | using_line += ' loader_platform_thread_lock_mutex(&objLock);\n' |
| 1537 | mutex_unlock = True |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1538 | for lc in loop_params: |
| 1539 | if 0 == lc: # No looping required for these params |
| 1540 | for opn in loop_params[lc]: |
| 1541 | if '->' in opn: |
| 1542 | using_line += ' if (%s)\n' % (opn.split('-')[0]) |
| 1543 | using_line += ' validate_object(%s, %s);\n' % (param0_name, opn) |
| 1544 | else: |
| 1545 | using_line += ' validate_object(%s, %s);\n' % (param0_name, opn) |
Tobin Ehlis | 9d67594 | 2015-06-30 14:32:16 -0600 | [diff] [blame] | 1546 | else: |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1547 | base_param = loop_params[lc][0].split('-')[0].split('[')[0] |
| 1548 | using_line += ' if (%s) {\n' % base_param |
| 1549 | using_line += ' for (uint32_t i=0; i<%s; i++) {\n' % lc |
| 1550 | for opn in loop_params[lc]: |
| 1551 | if '[' in opn: # API func param is array |
| 1552 | using_line += ' validate_object(%s, %s);\n' % (param0_name, opn) |
| 1553 | else: # struct element is array |
| 1554 | using_line += ' validate_object(%s, %s[i]);\n' % (param0_name, opn) |
| 1555 | using_line += ' }\n' |
| 1556 | using_line += ' }\n' |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1557 | if mutex_unlock: |
| 1558 | using_line += ' loader_platform_thread_unlock_mutex(&objLock);\n' |
| 1559 | ret_val = '' |
| 1560 | stmt = '' |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1561 | if proto.ret != "void": |
| 1562 | ret_val = "%s result = " % proto.ret |
| 1563 | stmt = " return result;\n" |
| 1564 | |
| 1565 | dispatch_param = proto.params[0].name |
| 1566 | if 'CreateInstance' in proto.name: |
| 1567 | dispatch_param = '*' + proto.params[1].name |
| 1568 | |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1569 | # Must use 'instance' table for these APIs, 'device' table otherwise |
| 1570 | table_type = "" |
| 1571 | if proto_is_global(proto): |
| 1572 | table_type = "instance" |
| 1573 | else: |
| 1574 | table_type = "device" |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1575 | funcs.append('%s%s\n' |
| 1576 | '{\n' |
| 1577 | '%s' |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1578 | ' %sget_dispatch_table(ObjectTracker_%s_table_map, %s)->%s;\n' |
Mark Lobodzinski | 64d5775 | 2015-07-17 11:51:24 -0600 | [diff] [blame] | 1579 | '%s%s' |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1580 | '%s' |
Mark Lobodzinski | 64d5775 | 2015-07-17 11:51:24 -0600 | [diff] [blame] | 1581 | '}' % (qual, decl, using_line, ret_val, table_type, dispatch_param, proto.c_call(), create_line, destroy_line, stmt)) |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1582 | return "\n\n".join(funcs) |
| 1583 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1584 | def generate_body(self): |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 1585 | self.layer_name = "ObjectTracker" |
Ian Elliott | 1064fe3 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 1586 | extensions=[('wsi_enabled', |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 1587 | ['vkCreateSwapchainKHR', 'vkDestroySwapchainKHR', |
| 1588 | 'vkGetSwapchainImagesKHR', 'vkQueuePresentKHR'])] |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1589 | body = [self.generate_maps(), |
| 1590 | self.generate_procs(), |
Mark Lobodzinski | 64d5775 | 2015-07-17 11:51:24 -0600 | [diff] [blame] | 1591 | self.generate_destroy_instance(), |
| 1592 | self.generate_destroy_device(), |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1593 | self.generate_command_buffer_validates(), |
| 1594 | self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"), |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1595 | self._generate_extensions(), |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 1596 | self._generate_layer_gpa_function(extensions, |
Courtney Goeltzenleuchter | 1727417 | 2015-06-01 14:52:57 -0600 | [diff] [blame] | 1597 | instance_extensions=['msg_callback_get_proc_addr'])] |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1598 | return "\n\n".join(body) |
Courtney Goeltzenleuchter | b412d21 | 2014-11-18 10:40:29 -0700 | [diff] [blame] | 1599 | |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1600 | class ThreadingSubcommand(Subcommand): |
Mike Stroyan | be2b5d8 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1601 | thread_check_dispatchable_objects = [ |
| 1602 | "VkQueue", |
| 1603 | "VkCmdBuffer", |
| 1604 | ] |
| 1605 | thread_check_nondispatchable_objects = [ |
| 1606 | "VkDeviceMemory", |
| 1607 | "VkBuffer", |
| 1608 | "VkImage", |
| 1609 | "VkDescriptorSet", |
| 1610 | "VkDescriptorPool", |
| 1611 | "VkSemaphore" |
| 1612 | ] |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1613 | thread_check_object_types = { |
| 1614 | 'VkInstance' : 'VK_OBJECT_TYPE_INSTANCE', |
| 1615 | 'VkPhysicalDevice' : 'VK_OBJECT_TYPE_PHYSICAL_DEVICE', |
| 1616 | 'VkDevice' : 'VK_OBJECT_TYPE_DEVICE', |
| 1617 | 'VkQueue' : 'VK_OBJECT_TYPE_QUEUE', |
| 1618 | 'VkCmdBuffer' : 'VK_OBJECT_TYPE_COMMAND_BUFFER', |
| 1619 | 'VkFence' : 'VK_OBJECT_TYPE_FENCE', |
| 1620 | 'VkDeviceMemory' : 'VK_OBJECT_TYPE_DEVICE_MEMORY', |
| 1621 | 'VkBuffer' : 'VK_OBJECT_TYPE_BUFFER', |
| 1622 | 'VkImage' : 'VK_OBJECT_TYPE_IMAGE', |
| 1623 | 'VkSemaphore' : 'VK_OBJECT_TYPE_SEMAPHORE', |
| 1624 | 'VkEvent' : 'VK_OBJECT_TYPE_EVENT', |
| 1625 | 'VkQueryPool' : 'VK_OBJECT_TYPE_QUERY_POOL', |
| 1626 | 'VkBufferView' : 'VK_OBJECT_TYPE_BUFFER_VIEW', |
| 1627 | 'VkImageView' : 'VK_OBJECT_TYPE_IMAGE_VIEW', |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1628 | 'VkShaderModule' : 'VK_OBJECT_TYPE_SHADER_MODULE', |
| 1629 | 'VkShader' : 'VK_OBJECT_TYPE_SHADER', |
| 1630 | 'VkPipelineCache' : 'VK_OBJECT_TYPE_PIPELINE_CACHE', |
| 1631 | 'VkPipelineLayout' : 'VK_OBJECT_TYPE_PIPELINE_LAYOUT', |
| 1632 | 'VkRenderPass' : 'VK_OBJECT_TYPE_RENDER_PASS', |
| 1633 | 'VkPipeline' : 'VK_OBJECT_TYPE_PIPELINE', |
| 1634 | 'VkDescriptorSetLayout' : 'VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT', |
| 1635 | 'VkSampler' : 'VK_OBJECT_TYPE_SAMPLER', |
| 1636 | 'VkDescriptorPool' : 'VK_OBJECT_TYPE_DESCRIPTOR_POOL', |
| 1637 | 'VkDescriptorSet' : 'VK_OBJECT_TYPE_DESCRIPTOR_SET', |
| 1638 | 'VkDynamicViewportState' : 'VK_OBJECT_TYPE_DYNAMIC_VIEWPORT_STATE', |
Cody Northrop | 271ba75 | 2015-08-26 10:01:32 -0600 | [diff] [blame] | 1639 | 'VkDynamicLineWidthState' : 'VK_OBJECT_TYPE_DYNAMIC_LINE_WIDTH_STATE', |
| 1640 | 'VkDynamicDepthBiasState' : 'VK_OBJECT_TYPE_DYNAMIC_DEPTH_BIAS_STATE', |
| 1641 | 'VkDynamicBlendState' : 'VK_OBJECT_TYPE_DYNAMIC_BLEND_STATE', |
| 1642 | 'VkDynamicDepthBoundsState' : 'VK_OBJECT_TYPE_DYNAMIC_DEPTH_BOUNDS_STATE', |
Cody Northrop | 82485a8 | 2015-08-18 15:21:16 -0600 | [diff] [blame] | 1643 | 'VkDynamicStencilState' : 'VK_OBJECT_TYPE_DYNAMIC_STENCIL_STATE', |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1644 | 'VkFramebuffer' : 'VK_OBJECT_TYPE_FRAMEBUFFER', |
| 1645 | 'VkCmdPool' : 'VK_OBJECT_TYPE_CMD_POOL', |
| 1646 | } |
| 1647 | def generate_useObject(self, ty): |
| 1648 | obj_type = self.thread_check_object_types[ty] |
| 1649 | if ty in self.thread_check_dispatchable_objects: |
| 1650 | key = "object" |
Courtney Goeltzenleuchter | dee721d | 2015-08-26 15:09:25 -0600 | [diff] [blame] | 1651 | msg_object = "reinterpret_cast<uint64_t>(object)" |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1652 | else: |
| 1653 | key = "object.handle" |
| 1654 | msg_object = "object.handle" |
Mike Stroyan | be2b5d8 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1655 | header_txt = [] |
| 1656 | header_txt.append('%s' % self.lineinfo.get()) |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1657 | header_txt.append('static void useObject(const void* dispatchable_object, %s object)' % ty) |
Mike Stroyan | be2b5d8 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1658 | header_txt.append('{') |
| 1659 | header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();') |
| 1660 | header_txt.append(' loader_platform_thread_lock_mutex(&threadingLock);') |
| 1661 | header_txt.append(' if (%sObjectsInUse.find(%s) == %sObjectsInUse.end()) {' % (ty, key, ty)) |
| 1662 | header_txt.append(' %sObjectsInUse[%s] = tid;' % (ty, key)) |
| 1663 | header_txt.append(' } else {') |
| 1664 | header_txt.append(' if (%sObjectsInUse[%s] != tid) {' % (ty, key)) |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1665 | header_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_ERROR_BIT, %s, %s,' % (obj_type, msg_object)) |
| 1666 | header_txt.append(' /*location*/ 0, THREADING_CHECKER_MULTIPLE_THREADS, "THREADING",') |
| 1667 | header_txt.append(' "THREADING ERROR : object of type %s is simultaneously used in thread %%ld and thread %%ld",' % (ty)) |
| 1668 | header_txt.append(' %sObjectsInUse[%s], tid);' % (ty, key)) |
Mike Stroyan | be2b5d8 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1669 | header_txt.append(' // Wait for thread-safe access to object') |
| 1670 | header_txt.append(' while (%sObjectsInUse.find(%s) != %sObjectsInUse.end()) {' % (ty, key, ty)) |
| 1671 | header_txt.append(' loader_platform_thread_cond_wait(&threadingCond, &threadingLock);') |
| 1672 | header_txt.append(' }') |
| 1673 | header_txt.append(' %sObjectsInUse[%s] = tid;' % (ty, key)) |
| 1674 | header_txt.append(' } else {') |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1675 | header_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_ERROR_BIT, %s, %s,' % (obj_type, msg_object)) |
| 1676 | header_txt.append(' /*location*/ 0, THREADING_CHECKER_MULTIPLE_THREADS, "THREADING",') |
| 1677 | header_txt.append(' "THREADING ERROR : object of type %s is recursively used in thread %%ld",' % (ty)) |
| 1678 | header_txt.append(' tid);') |
Mike Stroyan | be2b5d8 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1679 | header_txt.append(' }') |
| 1680 | header_txt.append(' }') |
| 1681 | header_txt.append(' loader_platform_thread_unlock_mutex(&threadingLock);') |
| 1682 | header_txt.append('}') |
| 1683 | return "\n".join(header_txt) |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1684 | def generate_finishUsingObject(self, ty): |
| 1685 | if ty in self.thread_check_dispatchable_objects: |
| 1686 | key = "object" |
| 1687 | else: |
| 1688 | key = "object.handle" |
Mike Stroyan | be2b5d8 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1689 | header_txt = [] |
| 1690 | header_txt.append('%s' % self.lineinfo.get()) |
| 1691 | header_txt.append('static void finishUsingObject(%s object)' % ty) |
| 1692 | header_txt.append('{') |
| 1693 | header_txt.append(' // Object is no longer in use') |
| 1694 | header_txt.append(' loader_platform_thread_lock_mutex(&threadingLock);') |
| 1695 | header_txt.append(' %sObjectsInUse.erase(%s);' % (ty, key)) |
| 1696 | header_txt.append(' loader_platform_thread_cond_broadcast(&threadingCond);') |
| 1697 | header_txt.append(' loader_platform_thread_unlock_mutex(&threadingLock);') |
| 1698 | header_txt.append('}') |
| 1699 | return "\n".join(header_txt) |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1700 | def generate_header(self): |
| 1701 | header_txt = [] |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1702 | header_txt.append('%s' % self.lineinfo.get()) |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1703 | header_txt.append('#include <stdio.h>') |
| 1704 | header_txt.append('#include <stdlib.h>') |
| 1705 | header_txt.append('#include <string.h>') |
| 1706 | header_txt.append('#include <unordered_map>') |
Tobin Ehlis | b835d1b | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 1707 | header_txt.append('#include "vk_loader_platform.h"') |
Tobin Ehlis | 0c6f9ee | 2015-07-03 09:42:57 -0600 | [diff] [blame] | 1708 | header_txt.append('#include "vk_layer.h"') |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1709 | header_txt.append('#include "threading.h"') |
Tobin Ehlis | a0cb02e | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 1710 | header_txt.append('#include "vk_layer_config.h"') |
Courtney Goeltzenleuchter | 3f9f7c4 | 2015-07-06 09:11:12 -0600 | [diff] [blame] | 1711 | header_txt.append('#include "vk_layer_extension_utils.h"') |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1712 | header_txt.append('#include "vk_enum_validate_helper.h"') |
| 1713 | header_txt.append('#include "vk_struct_validate_helper.h"') |
| 1714 | header_txt.append('//The following is #included again to catch certain OS-specific functions being used:') |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1715 | header_txt.append('#include "vk_loader_platform.h"') |
| 1716 | header_txt.append('#include "vk_layer_msg.h"') |
| 1717 | header_txt.append('#include "vk_layer_table.h"') |
| 1718 | header_txt.append('#include "vk_layer_logging.h"') |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1719 | header_txt.append('') |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1720 | header_txt.append('') |
| 1721 | header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(initOnce);') |
| 1722 | header_txt.append('') |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1723 | header_txt.append('using namespace std;') |
Mike Stroyan | be2b5d8 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1724 | for ty in self.thread_check_dispatchable_objects: |
| 1725 | header_txt.append('static unordered_map<%s, loader_platform_thread_id> %sObjectsInUse;' % (ty, ty)) |
| 1726 | for ty in self.thread_check_nondispatchable_objects: |
| 1727 | header_txt.append('static unordered_map<uint64_t, loader_platform_thread_id> %sObjectsInUse;' % ty) |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1728 | header_txt.append('static int threadingLockInitialized = 0;') |
| 1729 | header_txt.append('static loader_platform_thread_mutex threadingLock;') |
Mike Stroyan | ed238bb | 2015-05-15 08:50:57 -0600 | [diff] [blame] | 1730 | header_txt.append('static loader_platform_thread_cond threadingCond;') |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1731 | header_txt.append('%s' % self.lineinfo.get()) |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1732 | for ty in self.thread_check_dispatchable_objects + self.thread_check_nondispatchable_objects: |
| 1733 | header_txt.append(self.generate_useObject(ty)) |
| 1734 | header_txt.append(self.generate_finishUsingObject(ty)) |
Mike Stroyan | be2b5d8 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1735 | header_txt.append('%s' % self.lineinfo.get()) |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1736 | return "\n".join(header_txt) |
| 1737 | |
| 1738 | def generate_intercept(self, proto, qual): |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1739 | if proto.name in [ 'DbgCreateMsgCallback' ]: |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1740 | # use default version |
| 1741 | return None |
| 1742 | decl = proto.c_func(prefix="vk", attr="VKAPI") |
| 1743 | ret_val = '' |
| 1744 | stmt = '' |
| 1745 | funcs = [] |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1746 | table = 'device' |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1747 | if proto.ret != "void": |
Jon Ashburn | b0fbe91 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 1748 | ret_val = "%s result = " % proto.ret |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1749 | stmt = " return result;\n" |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 1750 | if proto_is_global(proto): |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1751 | table = 'instance' |
Jon Ashburn | 71836d9 | 2015-05-12 17:23:55 -0600 | [diff] [blame] | 1752 | |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1753 | # Memory range calls are special in needed thread checking within structs |
| 1754 | if proto.name in ["FlushMappedMemoryRanges","InvalidateMappedMemoryRanges"]: |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1755 | funcs.append('%s' % self.lineinfo.get()) |
| 1756 | funcs.append('%s%s\n' % (qual, decl) + |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1757 | '{\n' |
Tony Barbour | 92503c6 | 2015-07-13 15:28:47 -0600 | [diff] [blame] | 1758 | ' for (uint32_t i=0; i<memRangeCount; i++) {\n' |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1759 | ' useObject((const void *) %s, pMemRanges[i].mem);\n' % proto.params[0].name + |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1760 | ' }\n' |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1761 | ' VkLayerDispatchTable *pDeviceTable = get_dispatch_table(Threading_%s_table_map, %s);\n' % (table, proto.params[0].name) + |
| 1762 | ' %s pDeviceTable->%s;\n' % (ret_val, proto.c_call()) + |
Tony Barbour | 92503c6 | 2015-07-13 15:28:47 -0600 | [diff] [blame] | 1763 | ' for (uint32_t i=0; i<memRangeCount; i++) {\n' |
Mike Stroyan | be2b5d8 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1764 | ' finishUsingObject(pMemRanges[i].mem);\n' |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1765 | ' }\n' |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1766 | '%s' % (stmt) + |
| 1767 | '}') |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1768 | return "\n".join(funcs) |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1769 | # All functions that do a Get are thread safe |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1770 | if 'Get' in proto.name: |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1771 | return None |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1772 | # All WSI functions are thread safe |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 1773 | if 'KHR' in proto.name: |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1774 | return None |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1775 | # Initialize in early calls |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 1776 | if proto.name == "CreateDevice": |
| 1777 | funcs.append('%s' % self.lineinfo.get()) |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1778 | funcs.append('%s%s\n' % (qual, decl) + |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 1779 | '{\n' |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1780 | ' VkLayerDispatchTable *pDeviceTable = get_dispatch_table(Threading_device_table_map, (void *) *pDevice);\n' |
| 1781 | ' VkResult result = pDeviceTable->%s;\n' % (proto.c_call()) + |
| 1782 | ' if (result == VK_SUCCESS) {\n' |
| 1783 | ' layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(%s), layer_data_map);\n' % proto.params[0].name + |
| 1784 | ' layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);\n' |
| 1785 | ' my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);\n' |
| 1786 | ' }\n' |
| 1787 | '\n' |
| 1788 | ' return result;' |
| 1789 | '}') |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 1790 | return "\n".join(funcs) |
| 1791 | elif proto.params[0].ty == "VkPhysicalDevice": |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1792 | return None |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1793 | # Functions changing command buffers need thread safe use of first parameter |
| 1794 | if proto.params[0].ty == "VkCmdBuffer": |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1795 | funcs.append('%s' % self.lineinfo.get()) |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1796 | funcs.append('%s%s\n' % (qual, decl) + |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1797 | '{\n' |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1798 | ' useObject((const void *) %s, %s);\n' % (proto.params[0].name, proto.params[0].name) + |
| 1799 | ' VkLayerDispatchTable *pDeviceTable = get_dispatch_table(Threading_%s_table_map, %s);\n' % (table, proto.params[0].name) + |
| 1800 | ' %spDeviceTable->%s;\n' % (ret_val, proto.c_call()) + |
| 1801 | ' finishUsingObject(%s);\n' % proto.params[0].name + |
| 1802 | '%s' % stmt + |
| 1803 | '}') |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1804 | return "\n".join(funcs) |
| 1805 | # Non-Cmd functions that do a Wait are thread safe |
| 1806 | if 'Wait' in proto.name: |
| 1807 | return None |
| 1808 | # Watch use of certain types of objects passed as any parameter |
| 1809 | checked_params = [] |
| 1810 | for param in proto.params: |
Mike Stroyan | be2b5d8 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1811 | if param.ty in self.thread_check_dispatchable_objects or param.ty in self.thread_check_nondispatchable_objects: |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1812 | checked_params.append(param) |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1813 | if proto.name == "DestroyDevice": |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1814 | funcs.append('%s%s\n' % (qual, decl) + |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1815 | '{\n' |
Courtney Goeltzenleuchter | 0daf228 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 1816 | ' dispatch_key key = get_dispatch_key(device);\n' |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1817 | ' VkLayerDispatchTable *pDeviceTable = get_dispatch_table(Threading_%s_table_map, %s);\n' % (table, proto.params[0].name) + |
| 1818 | ' %spDeviceTable->%s;\n' % (ret_val, proto.c_call()) + |
| 1819 | ' Threading_device_table_map.erase(key);\n' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1820 | ' return result;\n' |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1821 | '}\n') |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1822 | return "\n".join(funcs); |
| 1823 | elif proto.name == "DestroyInstance": |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1824 | funcs.append('%s%s\n' % (qual, decl) + |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1825 | '{\n' |
Courtney Goeltzenleuchter | 0daf228 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 1826 | ' dispatch_key key = get_dispatch_key(instance);\n' |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1827 | ' VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(Threading_instance_table_map, %s);\n' % proto.params[0].name + |
| 1828 | ' %spInstanceTable->%s;\n' % (ret_val, proto.c_call()) + |
Courtney Goeltzenleuchter | 0daf228 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 1829 | ' destroy_instance_dispatch_table(key);\n' |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1830 | '\n' |
| 1831 | ' // Clean up logging callback, if any\n' |
| 1832 | ' layer_data *my_data = get_my_data_ptr(key, layer_data_map);\n' |
| 1833 | ' if (my_data->logging_callback) {\n' |
| 1834 | ' layer_destroy_msg_callback(my_data->report_data, my_data->logging_callback);\n' |
| 1835 | ' }\n' |
| 1836 | '\n' |
| 1837 | ' layer_debug_report_destroy_instance(my_data->report_data);\n' |
| 1838 | ' layer_data_map.erase(pInstanceTable);\n' |
| 1839 | '\n' |
| 1840 | ' Threading_instance_table_map.erase(key);\n' |
| 1841 | '\n' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1842 | ' return result;\n' |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1843 | '}\n') |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1844 | return "\n".join(funcs); |
Courtney Goeltzenleuchter | d02a964 | 2015-06-08 14:58:39 -0600 | [diff] [blame] | 1845 | elif proto.name == "CreateInstance": |
| 1846 | funcs.append('%s%s\n' |
| 1847 | '{\n' |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1848 | ' VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(Threading_instance_table_map, *pInstance);\n' |
| 1849 | ' VkResult result = pInstanceTable->CreateInstance(pCreateInfo, pInstance);\n' |
Courtney Goeltzenleuchter | d02a964 | 2015-06-08 14:58:39 -0600 | [diff] [blame] | 1850 | '\n' |
| 1851 | ' if (result == VK_SUCCESS) {\n' |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1852 | ' layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);\n' |
| 1853 | ' my_data->report_data = debug_report_create_instance(\n' |
| 1854 | ' pInstanceTable,\n' |
| 1855 | ' *pInstance,\n' |
| 1856 | ' pCreateInfo->extensionCount,\n' |
| 1857 | ' pCreateInfo->ppEnabledExtensionNames);\n' |
| 1858 | ' initThreading(my_data);\n' |
Courtney Goeltzenleuchter | d02a964 | 2015-06-08 14:58:39 -0600 | [diff] [blame] | 1859 | ' }\n' |
| 1860 | ' return result;\n' |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1861 | '}\n' % (qual, decl)) |
Courtney Goeltzenleuchter | d02a964 | 2015-06-08 14:58:39 -0600 | [diff] [blame] | 1862 | return "\n".join(funcs); |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1863 | if len(checked_params) == 0: |
| 1864 | return None |
| 1865 | # Surround call with useObject and finishUsingObject for each checked_param |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1866 | funcs.append('%s' % self.lineinfo.get()) |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1867 | funcs.append('%s%s' % (qual, decl)) |
| 1868 | funcs.append('{') |
| 1869 | for param in checked_params: |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1870 | funcs.append(' useObject((const void *) %s, %s);' % (proto.params[0].name, param.name)) |
| 1871 | funcs.append(' VkLayerDispatchTable *pDeviceTable = get_dispatch_table(Threading_%s_table_map, %s);' % (table, proto.params[0].name)); |
| 1872 | funcs.append(' %spDeviceTable->%s;' % (ret_val, proto.c_call())) |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1873 | for param in checked_params: |
Mike Stroyan | be2b5d8 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1874 | funcs.append(' finishUsingObject(%s);' % param.name) |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1875 | funcs.append('%s' |
| 1876 | '}' % stmt) |
| 1877 | return "\n".join(funcs) |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1878 | |
| 1879 | def generate_body(self): |
| 1880 | self.layer_name = "Threading" |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1881 | body = [self._generate_new_layer_initialization(True, lockname='threading', condname='threading'), |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1882 | self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"), |
Courtney Goeltzenleuchter | 1727417 | 2015-06-01 14:52:57 -0600 | [diff] [blame] | 1883 | self._generate_layer_gpa_function(extensions=[], |
| 1884 | instance_extensions=['msg_callback_get_proc_addr']), |
| 1885 | self._gen_create_msg_callback(), |
| 1886 | self._gen_destroy_msg_callback()] |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1887 | return "\n\n".join(body) |
| 1888 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1889 | def main(): |
| 1890 | subcommands = { |
| 1891 | "layer-funcs" : LayerFuncsSubcommand, |
Tobin Ehlis | a363cfa | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 1892 | "Generic" : GenericLayerSubcommand, |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 1893 | "APIDump" : APIDumpSubcommand, |
Tobin Ehlis | a363cfa | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 1894 | "ObjectTracker" : ObjectTrackerSubcommand, |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1895 | "Threading" : ThreadingSubcommand, |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1896 | } |
| 1897 | |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1898 | if len(sys.argv) < 3 or sys.argv[1] not in subcommands or not os.path.exists(sys.argv[2]): |
| 1899 | print("Usage: %s <subcommand> <input_header> [options]" % sys.argv[0]) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1900 | print |
Tobin Ehlis | 7e65d75 | 2015-01-15 17:51:52 -0700 | [diff] [blame] | 1901 | print("Available subcommands are: %s" % " ".join(subcommands)) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1902 | exit(1) |
| 1903 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1904 | hfp = vk_helper.HeaderFileParser(sys.argv[2]) |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1905 | hfp.parse() |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1906 | vk_helper.enum_val_dict = hfp.get_enum_val_dict() |
| 1907 | vk_helper.enum_type_dict = hfp.get_enum_type_dict() |
| 1908 | vk_helper.struct_dict = hfp.get_struct_dict() |
| 1909 | vk_helper.typedef_fwd_dict = hfp.get_typedef_fwd_dict() |
| 1910 | vk_helper.typedef_rev_dict = hfp.get_typedef_rev_dict() |
| 1911 | vk_helper.types_dict = hfp.get_types_dict() |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1912 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1913 | subcmd = subcommands[sys.argv[1]](sys.argv[2:]) |
| 1914 | subcmd.run() |
| 1915 | |
| 1916 | if __name__ == "__main__": |
| 1917 | main() |