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