Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 3 | # VK |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 4 | # |
| 5 | # Copyright (C) 2014 LunarG, Inc. |
| 6 | # |
| 7 | # Permission is hereby granted, free of charge, to any person obtaining a |
| 8 | # copy of this software and associated documentation files (the "Software"), |
| 9 | # to deal in the Software without restriction, including without limitation |
| 10 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 11 | # and/or sell copies of the Software, and to permit persons to whom the |
| 12 | # Software is furnished to do so, subject to the following conditions: |
| 13 | # |
| 14 | # The above copyright notice and this permission notice shall be included |
| 15 | # in all copies or substantial portions of the Software. |
| 16 | # |
| 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 20 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 22 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 23 | # DEALINGS IN THE SOFTWARE. |
| 24 | # |
| 25 | # Authors: |
| 26 | # Chia-I Wu <olv@lunarg.com> |
| 27 | |
| 28 | import sys |
Tobin Ehlis | 6cd0637 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 29 | import os |
Mark Lobodzinski | 4e5016f | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 30 | import re |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 31 | |
Courtney Goeltzenleuchter | a8c0628 | 2015-04-14 14:55:44 -0600 | [diff] [blame] | 32 | import vulkan |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 33 | import vk_helper |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 34 | from source_line_info import sourcelineinfo |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 35 | |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 36 | def proto_is_global(proto): |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 37 | if proto.params[0].ty == "VkInstance" or proto.params[0].ty == "VkPhysicalDevice" or proto.name == "CreateInstance" or proto.name == "GetGlobalExtensionCount" or proto.name == "GetGlobalExtensionProperties" or proto.name == "GetPhysicalDeviceExtensionCount" or proto.name == "GetPhysicalDeviceExtensionProperties": |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 38 | return True |
| 39 | else: |
| 40 | return False |
| 41 | |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 42 | def generate_get_proc_addr_check(name): |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 43 | return " if (!%s || %s[0] != 'v' || %s[1] != 'k')\n" \ |
| 44 | " return NULL;" % ((name,) * 3) |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 45 | |
Mark Lobodzinski | 4e5016f | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 46 | def ucc_to_U_C_C(CamelCase): |
| 47 | temp = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', CamelCase) |
| 48 | return re.sub('([a-z0-9])([A-Z])', r'\1_\2', temp).upper() |
| 49 | |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 50 | class Subcommand(object): |
| 51 | def __init__(self, argv): |
| 52 | self.argv = argv |
Courtney Goeltzenleuchter | a8c0628 | 2015-04-14 14:55:44 -0600 | [diff] [blame] | 53 | self.headers = vulkan.headers |
| 54 | self.protos = vulkan.protos |
Mike Stroyan | 3aecdb4 | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 55 | self.no_addr = False |
| 56 | self.layer_name = "" |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 57 | self.lineinfo = sourcelineinfo() |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 58 | |
| 59 | def run(self): |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 60 | print(self.generate()) |
| 61 | |
| 62 | def generate(self): |
| 63 | copyright = self.generate_copyright() |
| 64 | header = self.generate_header() |
| 65 | body = self.generate_body() |
| 66 | footer = self.generate_footer() |
| 67 | |
| 68 | contents = [] |
| 69 | if copyright: |
| 70 | contents.append(copyright) |
| 71 | if header: |
| 72 | contents.append(header) |
| 73 | if body: |
| 74 | contents.append(body) |
| 75 | if footer: |
| 76 | contents.append(footer) |
| 77 | |
| 78 | return "\n\n".join(contents) |
| 79 | |
| 80 | def generate_copyright(self): |
| 81 | return """/* THIS FILE IS GENERATED. DO NOT EDIT. */ |
| 82 | |
| 83 | /* |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 84 | * Vulkan |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 85 | * |
| 86 | * Copyright (C) 2014 LunarG, Inc. |
| 87 | * |
| 88 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 89 | * copy of this software and associated documentation files (the "Software"), |
| 90 | * to deal in the Software without restriction, including without limitation |
| 91 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 92 | * and/or sell copies of the Software, and to permit persons to whom the |
| 93 | * Software is furnished to do so, subject to the following conditions: |
| 94 | * |
| 95 | * The above copyright notice and this permission notice shall be included |
| 96 | * in all copies or substantial portions of the Software. |
| 97 | * |
| 98 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 99 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 100 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 101 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 102 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 103 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 104 | * DEALINGS IN THE SOFTWARE. |
| 105 | */""" |
| 106 | |
| 107 | def generate_header(self): |
| 108 | return "\n".join(["#include <" + h + ">" for h in self.headers]) |
| 109 | |
| 110 | def generate_body(self): |
| 111 | pass |
| 112 | |
| 113 | def generate_footer(self): |
| 114 | pass |
| 115 | |
| 116 | # Return set of printf '%' qualifier and input to that qualifier |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 117 | def _get_printf_params(self, vk_type, name, output_param, cpp=False): |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 118 | # TODO : Need ENUM and STRUCT checks here |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 119 | if vk_helper.is_type(vk_type, 'enum'):#"_TYPE" in vk_type: # TODO : This should be generic ENUM check |
Courtney Goeltzenleuchter | ddcb619 | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 120 | return ("%s", "string_%s(%s)" % (vk_type.replace('const ', '').strip('*'), name)) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 121 | if "char*" == vk_type: |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 122 | return ("%s", name) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 123 | if "uint64" in vk_type: |
| 124 | if '*' in vk_type: |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 125 | return ("%lu", "*%s" % name) |
| 126 | return ("%lu", name) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 127 | if "size" in vk_type: |
| 128 | if '*' in vk_type: |
Chia-I Wu | 54ed079 | 2014-12-27 14:14:50 +0800 | [diff] [blame] | 129 | return ("%zu", "*%s" % name) |
| 130 | return ("%zu", name) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 131 | if "float" in vk_type: |
| 132 | if '[' in vk_type: # handle array, current hard-coded to 4 (TODO: Make this dynamic) |
Tobin Ehlis | 434db7c | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 133 | if cpp: |
| 134 | return ("[%i, %i, %i, %i]", '"[" << %s[0] << "," << %s[1] << "," << %s[2] << "," << %s[3] << "]"' % (name, name, name, name)) |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 135 | return ("[%f, %f, %f, %f]", "%s[0], %s[1], %s[2], %s[3]" % (name, name, name, name)) |
| 136 | return ("%f", name) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 137 | if "bool" in vk_type or 'xcb_randr_crtc_t' in vk_type: |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 138 | return ("%u", name) |
Tobin Ehlis | f29da38 | 2015-04-15 07:46:12 -0600 | [diff] [blame] | 139 | if True in [t in vk_type.lower() for t in ["int", "flags", "mask", "xcb_window_t"]]: |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 140 | if '[' in vk_type: # handle array, current hard-coded to 4 (TODO: Make this dynamic) |
Tobin Ehlis | 434db7c | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 141 | if cpp: |
| 142 | return ("[%i, %i, %i, %i]", "%s[0] << %s[1] << %s[2] << %s[3]" % (name, name, name, name)) |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 143 | return ("[%i, %i, %i, %i]", "%s[0], %s[1], %s[2], %s[3]" % (name, name, name, name)) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 144 | if '*' in vk_type: |
Tobin Ehlis | 1336c8d | 2015-02-04 15:15:11 -0700 | [diff] [blame] | 145 | if 'pUserData' == name: |
| 146 | return ("%i", "((pUserData == 0) ? 0 : *(pUserData))") |
Tobin Ehlis | a74d53a | 2015-04-17 13:26:33 -0600 | [diff] [blame] | 147 | if 'const' in vk_type.lower(): |
| 148 | return ("%p", "(void*)(%s)" % name) |
Jon Ashburn | 1f7e2d7 | 2014-12-12 16:10:45 -0700 | [diff] [blame] | 149 | return ("%i", "*(%s)" % name) |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 150 | return ("%i", name) |
Tobin Ehlis | 0a1e06d | 2014-11-11 17:28:22 -0700 | [diff] [blame] | 151 | # TODO : This is special-cased as there's only one "format" param currently and it's nice to expand it |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 152 | if "VkFormat" == vk_type: |
Tobin Ehlis | 434db7c | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 153 | if cpp: |
| 154 | return ("%p", "&%s" % name) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 155 | return ("{%s.channelFormat = %%s, %s.numericFormat = %%s}" % (name, name), "string_VK_CHANNEL_FORMAT(%s.channelFormat), string_VK_NUM_FORMAT(%s.numericFormat)" % (name, name)) |
Tobin Ehlis | a554dc3 | 2014-11-19 15:52:46 -0700 | [diff] [blame] | 156 | if output_param: |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 157 | return ("%p", "(void*)*%s" % name) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 158 | if vk_helper.is_type(vk_type, 'struct') and '*' not in vk_type: |
Courtney Goeltzenleuchter | 9a1ded8 | 2015-04-03 16:35:32 -0600 | [diff] [blame] | 159 | return ("%p", "(void*)(&%s)" % name) |
Jon Ashburn | 1f7e2d7 | 2014-12-12 16:10:45 -0700 | [diff] [blame] | 160 | return ("%p", "(void*)(%s)" % name) |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 161 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 162 | def _gen_create_msg_callback(self): |
Tobin Ehlis | c54139f | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 163 | r_body = [] |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 164 | r_body.append('%s' % self.lineinfo.get()) |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 165 | r_body.append('VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(VkInstance instance, VkFlags msgFlags, const PFN_vkDbgMsgCallback pfnMsgCallback, void* pUserData, VkDbgMsgCallback* pMsgCallback)') |
Tobin Ehlis | c54139f | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 166 | r_body.append('{') |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 167 | # Switch to this code section for the new per-instance storage and debug callbacks |
| 168 | if self.layer_name == 'ObjectTracker': |
| 169 | r_body.append(' VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(%s_instance_table_map, instance);' % self.layer_name ) |
| 170 | r_body.append(' VkResult result = pInstanceTable->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);') |
| 171 | r_body.append(' if (VK_SUCCESS == result) {') |
| 172 | r_body.append(' layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);') |
| 173 | r_body.append(' result = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);') |
| 174 | r_body.append(' }') |
| 175 | r_body.append(' return result;') |
| 176 | else: |
| 177 | # Old version of callbacks for compatibility |
| 178 | r_body.append(' return layer_create_msg_callback(instance, instance_dispatch_table(instance), msgFlags, pfnMsgCallback, pUserData, pMsgCallback);') |
Tobin Ehlis | c54139f | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 179 | r_body.append('}') |
| 180 | return "\n".join(r_body) |
| 181 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 182 | def _gen_destroy_msg_callback(self): |
| 183 | r_body = [] |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 184 | r_body.append('%s' % self.lineinfo.get()) |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 185 | r_body.append('VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(VkInstance instance, VkDbgMsgCallback msgCallback)') |
| 186 | r_body.append('{') |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 187 | # Switch to this code section for the new per-instance storage and debug callbacks |
| 188 | if self.layer_name == 'ObjectTracker': |
| 189 | r_body.append(' VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(%s_instance_table_map, instance);' % self.layer_name ) |
| 190 | r_body.append(' VkResult result = pInstanceTable->DbgDestroyMsgCallback(instance, msgCallback);') |
| 191 | r_body.append(' layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);') |
| 192 | r_body.append(' layer_destroy_msg_callback(my_data->report_data, msgCallback);') |
| 193 | r_body.append(' return result;') |
| 194 | else: |
| 195 | # Old version of callbacks for compatibility |
| 196 | r_body.append(' return layer_destroy_msg_callback(instance, instance_dispatch_table(instance), msgCallback);') |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 197 | r_body.append('}') |
| 198 | return "\n".join(r_body) |
Tobin Ehlis | c54139f | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 199 | |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 200 | def _gen_layer_get_global_extension_props(self, layer="Generic"): |
| 201 | ggep_body = [] |
Courtney Goeltzenleuchter | ea2025a | 2015-06-07 17:24:20 -0600 | [diff] [blame] | 202 | if layer == 'APIDump' or layer == 'Generic': |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 203 | ggep_body.append('%s' % self.lineinfo.get()) |
| 204 | ggep_body.append('#define LAYER_EXT_ARRAY_SIZE 1') |
| 205 | ggep_body.append('static const VkExtensionProperties layerExts[LAYER_EXT_ARRAY_SIZE] = {') |
| 206 | ggep_body.append(' {') |
| 207 | ggep_body.append(' VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES,') |
| 208 | ggep_body.append(' "%s",' % layer) |
| 209 | ggep_body.append(' 0x10,') |
| 210 | ggep_body.append(' "layer: %s",' % layer) |
| 211 | ggep_body.append(' }') |
| 212 | ggep_body.append('};') |
Courtney Goeltzenleuchter | 23b5f8d | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 213 | else: |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 214 | ggep_body.append('%s' % self.lineinfo.get()) |
| 215 | ggep_body.append('#define LAYER_EXT_ARRAY_SIZE 2') |
| 216 | ggep_body.append('static const VkExtensionProperties layerExts[LAYER_EXT_ARRAY_SIZE] = {') |
| 217 | ggep_body.append(' {') |
| 218 | ggep_body.append(' VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES,') |
| 219 | ggep_body.append(' "%s",' % layer) |
| 220 | ggep_body.append(' 0x10,') |
| 221 | ggep_body.append(' "layer: %s",' % layer) |
| 222 | ggep_body.append(' },') |
| 223 | ggep_body.append(' {') |
| 224 | ggep_body.append(' VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES,') |
| 225 | ggep_body.append(' "Validation",') |
| 226 | ggep_body.append(' 0x10,') |
| 227 | ggep_body.append(' "layer: %s",' % layer) |
| 228 | ggep_body.append(' }') |
| 229 | ggep_body.append('};') |
| 230 | ggep_body.append('') |
| 231 | ggep_body.append('%s' % self.lineinfo.get()) |
Jon Ashburn | 2556635 | 2015-04-02 12:06:28 -0600 | [diff] [blame] | 232 | |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 233 | ggep_body.append('') |
| 234 | ggep_body.append('VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionProperties(uint32_t extensionIndex, VkExtensionProperties* pProperties)') |
| 235 | ggep_body.append('{') |
| 236 | ggep_body.append(' if (extensionIndex >= LAYER_EXT_ARRAY_SIZE)') |
| 237 | ggep_body.append(' return VK_ERROR_INVALID_VALUE;') |
| 238 | ggep_body.append(' memcpy(pProperties, &layerExts[extensionIndex], sizeof(VkExtensionProperties));') |
| 239 | ggep_body.append(' return VK_SUCCESS;') |
| 240 | ggep_body.append('}') |
| 241 | return "\n".join(ggep_body) |
| 242 | |
| 243 | def _gen_layer_get_global_extension_count(self, layer="Generic"): |
| 244 | ggec_body = [] |
| 245 | ggec_body.append('VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionCount(uint32_t* pCount)') |
| 246 | ggec_body.append('{') |
| 247 | ggec_body.append(' *pCount = LAYER_EXT_ARRAY_SIZE;') |
| 248 | ggec_body.append(' return VK_SUCCESS;') |
| 249 | ggec_body.append('}') |
| 250 | return "\n".join(ggec_body) |
| 251 | |
| 252 | def _gen_layer_get_physical_device_extension_props(self, layer="Generic"): |
| 253 | gpdep_body = [] |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 254 | if layer == 'APIDump' or layer == 'Generic': |
Courtney Goeltzenleuchter | e7a901e | 2015-06-26 16:43:44 -0600 | [diff] [blame^] | 255 | gpdep_body.append('#define LAYER_DEV_EXT_ARRAY_SIZE 1') |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 256 | gpdep_body.append('static const VkExtensionProperties layerDevExts[LAYER_DEV_EXT_ARRAY_SIZE] = {') |
| 257 | gpdep_body.append(' {') |
| 258 | gpdep_body.append(' VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES,') |
| 259 | gpdep_body.append(' "%s",' % layer) |
| 260 | gpdep_body.append(' 0x10,') |
| 261 | gpdep_body.append(' "layer: %s",' % layer) |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 262 | gpdep_body.append(' }') |
| 263 | gpdep_body.append('};') |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 264 | elif layer == 'ObjectTracker': |
Courtney Goeltzenleuchter | e7a901e | 2015-06-26 16:43:44 -0600 | [diff] [blame^] | 265 | gpdep_body.append('#define LAYER_DEV_EXT_ARRAY_SIZE 2') |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 266 | gpdep_body.append('static const VkExtensionProperties layerDevExts[LAYER_DEV_EXT_ARRAY_SIZE] = {') |
| 267 | gpdep_body.append(' {') |
| 268 | gpdep_body.append(' VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES,') |
| 269 | gpdep_body.append(' "%s",' % layer) |
| 270 | gpdep_body.append(' 0x10,') |
| 271 | gpdep_body.append(' "layer: %s",' % layer) |
| 272 | gpdep_body.append(' },') |
| 273 | gpdep_body.append(' {') |
| 274 | gpdep_body.append(' VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES,') |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 275 | gpdep_body.append(' "Validation",') |
| 276 | gpdep_body.append(' 0x10,') |
| 277 | gpdep_body.append(' "layer: %s",' % layer) |
| 278 | gpdep_body.append(' }') |
| 279 | gpdep_body.append('};') |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 280 | else: |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 281 | gpdep_body.append('#define LAYER_DEV_EXT_ARRAY_SIZE 2') |
| 282 | gpdep_body.append('static const VkExtensionProperties layerDevExts[LAYER_DEV_EXT_ARRAY_SIZE] = {') |
| 283 | gpdep_body.append(' {') |
| 284 | gpdep_body.append(' VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES,') |
| 285 | gpdep_body.append(' "%s",' % layer) |
| 286 | gpdep_body.append(' 0x10,') |
| 287 | gpdep_body.append(' "layer: %s",' % layer) |
| 288 | gpdep_body.append(' },') |
| 289 | gpdep_body.append(' {') |
| 290 | gpdep_body.append(' VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES,') |
| 291 | gpdep_body.append(' "Validation",') |
| 292 | gpdep_body.append(' 0x10,') |
| 293 | gpdep_body.append(' "layer: %s",' % layer) |
| 294 | gpdep_body.append(' }') |
| 295 | gpdep_body.append('};') |
| 296 | gpdep_body.append('VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceExtensionProperties(VkPhysicalDevice physicalDevice, uint32_t extensionIndex, VkExtensionProperties* pProperties)') |
| 297 | gpdep_body.append('{') |
| 298 | gpdep_body.append(' if (extensionIndex >= LAYER_DEV_EXT_ARRAY_SIZE)') |
| 299 | gpdep_body.append(' return VK_ERROR_INVALID_VALUE;') |
| 300 | gpdep_body.append(' memcpy(pProperties, &layerDevExts[extensionIndex], sizeof(VkExtensionProperties));') |
| 301 | gpdep_body.append(' return VK_SUCCESS;') |
| 302 | gpdep_body.append('}') |
| 303 | gpdep_body.append('') |
| 304 | return "\n".join(gpdep_body) |
| 305 | |
| 306 | def _gen_layer_get_physical_device_extension_count(self, layer="Generic"): |
| 307 | gpdec_body = [] |
| 308 | gpdec_body.append('VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceExtensionCount(VkPhysicalDevice physicalDevice, uint32_t* pCount)') |
| 309 | gpdec_body.append('{') |
| 310 | gpdec_body.append(' *pCount = LAYER_DEV_EXT_ARRAY_SIZE;') |
| 311 | gpdec_body.append(' return VK_SUCCESS;') |
| 312 | gpdec_body.append('}') |
| 313 | gpdec_body.append('') |
| 314 | return "\n".join(gpdec_body) |
| 315 | |
Courtney Goeltzenleuchter | 23b5f8d | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 316 | |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 317 | def _generate_dispatch_entrypoints(self, qual=""): |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 318 | if qual: |
| 319 | qual += " " |
| 320 | |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 321 | funcs = [] |
| 322 | intercepted = [] |
| 323 | for proto in self.protos: |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 324 | if proto.name == "GetDeviceProcAddr" or proto.name == "GetInstanceProcAddr": |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 325 | continue |
Mike Stroyan | 88f0ecf | 2015-04-08 10:27:43 -0600 | [diff] [blame] | 326 | else: |
Mike Stroyan | 3aecdb4 | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 327 | intercept = self.generate_intercept(proto, qual) |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 328 | if intercept is None: |
| 329 | # fill in default intercept for certain entrypoints |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 330 | if 'DbgCreateMsgCallback' == proto.name: |
| 331 | intercept = self._gen_layer_dbg_create_msg_callback() |
| 332 | elif 'DbgDestroyMsgCallback' == proto.name: |
| 333 | intercept = self._gen_layer_dbg_destroy_msg_callback() |
| 334 | elif 'CreateDevice' == proto.name: |
| 335 | funcs.append('/* CreateDevice HERE */') |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 336 | elif 'GetGlobalExtensionProperties' == proto.name: |
| 337 | intercept = self._gen_layer_get_global_extension_props(self.layer_name) |
| 338 | elif 'GetGlobalExtensionCount' == proto.name: |
| 339 | intercept = self._gen_layer_get_global_extension_count(self.layer_name) |
| 340 | elif 'GetPhysicalDeviceExtensionProperties' == proto.name: |
| 341 | intercept = self._gen_layer_get_physical_device_extension_props(self.layer_name) |
| 342 | elif 'GetPhysicalDeviceExtensionCount' == proto.name: |
| 343 | intercept = self._gen_layer_get_physical_device_extension_count(self.layer_name) |
| 344 | |
| 345 | |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 346 | if intercept is not None: |
| 347 | funcs.append(intercept) |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 348 | if not "WSI" in proto.name: |
| 349 | intercepted.append(proto) |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 350 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 351 | prefix="vk" |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 352 | lookups = [] |
| 353 | for proto in intercepted: |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 354 | lookups.append("if (!strcmp(name, \"%s\"))" % proto.name) |
| 355 | lookups.append(" return (void*) %s%s;" % |
| 356 | (prefix, proto.name)) |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 357 | |
| 358 | # add customized layer_intercept_proc |
| 359 | body = [] |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 360 | body.append('%s' % self.lineinfo.get()) |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 361 | body.append("static inline void* layer_intercept_proc(const char *name)") |
| 362 | body.append("{") |
| 363 | body.append(generate_get_proc_addr_check("name")) |
| 364 | body.append("") |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 365 | body.append(" name += 2;") |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 366 | body.append(" %s" % "\n ".join(lookups)) |
| 367 | body.append("") |
| 368 | body.append(" return NULL;") |
| 369 | body.append("}") |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 370 | # add layer_intercept_instance_proc |
| 371 | lookups = [] |
| 372 | for proto in self.protos: |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 373 | if not proto_is_global(proto): |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 374 | continue |
| 375 | |
| 376 | if not proto in intercepted: |
| 377 | continue |
| 378 | lookups.append("if (!strcmp(name, \"%s\"))" % proto.name) |
| 379 | lookups.append(" return (void*) %s%s;" % (prefix, proto.name)) |
| 380 | |
| 381 | body.append("static inline void* layer_intercept_instance_proc(const char *name)") |
| 382 | body.append("{") |
| 383 | body.append(generate_get_proc_addr_check("name")) |
| 384 | body.append("") |
| 385 | body.append(" name += 2;") |
| 386 | body.append(" %s" % "\n ".join(lookups)) |
| 387 | body.append("") |
| 388 | body.append(" return NULL;") |
| 389 | body.append("}") |
| 390 | |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 391 | funcs.append("\n".join(body)) |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 392 | return "\n\n".join(funcs) |
| 393 | |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 394 | def _generate_extensions(self): |
| 395 | exts = [] |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 396 | exts.append('%s' % self.lineinfo.get()) |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 397 | exts.append(self._gen_create_msg_callback()) |
| 398 | exts.append(self._gen_destroy_msg_callback()) |
Tobin Ehlis | f29da38 | 2015-04-15 07:46:12 -0600 | [diff] [blame] | 399 | return "\n".join(exts) |
| 400 | |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 401 | def _generate_layer_gpa_function(self, extensions=[], instance_extensions=[]): |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 402 | func_body = [] |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 403 | # |
| 404 | # New style fo GPA Functions for the new layer_data/layer_logging changes |
| 405 | # |
| 406 | if self.layer_name == 'ObjectTracker': |
| 407 | func_body.append("VK_LAYER_EXPORT void* VKAPI vkGetDeviceProcAddr(VkDevice device, const char* funcName)\n" |
| 408 | "{\n" |
| 409 | " void* addr;\n" |
| 410 | " if (device == VK_NULL_HANDLE) {\n" |
| 411 | " return NULL;\n" |
| 412 | " }\n" |
| 413 | " /* loader uses this to force layer initialization; device object is wrapped */\n" |
| 414 | " if (!strcmp(\"vkGetDeviceProcAddr\", funcName)) {\n" |
| 415 | " initDeviceTable(%s_device_table_map, (const VkBaseLayerObject *) device);\n" |
| 416 | " return (void *) vkGetDeviceProcAddr;\n" |
| 417 | " }\n\n" |
| 418 | " addr = layer_intercept_proc(funcName);\n" |
| 419 | " if (addr)\n" |
| 420 | " return addr;" % self.layer_name) |
| 421 | if 0 != len(extensions): |
| 422 | for (ext_enable, ext_list) in extensions: |
| 423 | extra_space = "" |
| 424 | if 0 != len(ext_enable): |
| 425 | func_body.append(' if (deviceExtMap.size() == 0 || deviceExtMap[get_dispatch_table(ObjectTracker_device_table_map, device)].%s)' % ext_enable) |
| 426 | func_body.append(' {') |
| 427 | extra_space = " " |
| 428 | for ext_name in ext_list: |
| 429 | func_body.append(' %sif (!strcmp("%s", funcName))\n' |
| 430 | ' %sreturn reinterpret_cast<void*>(%s);' % (extra_space, ext_name, extra_space, ext_name)) |
| 431 | if 0 != len(ext_enable): |
| 432 | func_body.append(' }\n') |
| 433 | func_body.append("\n if (get_dispatch_table(%s_device_table_map, device)->GetDeviceProcAddr == NULL)\n" |
| 434 | " return NULL;\n" |
| 435 | " return get_dispatch_table(%s_device_table_map, device)->GetDeviceProcAddr(device, funcName);\n" |
| 436 | "}\n" % (self.layer_name, self.layer_name)) |
| 437 | func_body.append("VK_LAYER_EXPORT void* VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)\n" |
| 438 | "{\n" |
| 439 | " void* addr;\n" |
| 440 | " if (instance == VK_NULL_HANDLE) {\n" |
| 441 | " return NULL;\n" |
| 442 | " }\n" |
| 443 | " /* loader uses this to force layer initialization; instance object is wrapped */\n" |
| 444 | " if (!strcmp(\"vkGetInstanceProcAddr\", funcName)) {\n" |
| 445 | " initInstanceTable(%s_instance_table_map, (const VkBaseLayerObject *) instance);\n" |
| 446 | " return (void *) vkGetInstanceProcAddr;\n" |
| 447 | " }\n\n" |
| 448 | " addr = layer_intercept_instance_proc(funcName);\n" |
| 449 | " if (addr) {\n" |
| 450 | " return addr;" |
| 451 | " }\n" % self.layer_name) |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 452 | |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 453 | if 0 != len(instance_extensions): |
| 454 | for ext_name in instance_extensions: |
| 455 | func_body.append(" layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);\n" |
| 456 | " addr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);\n" |
| 457 | " if (addr) {\n" |
| 458 | " return addr;\n" |
| 459 | " }\n" |
| 460 | " if (get_dispatch_table(%s_instance_table_map, instance)->GetInstanceProcAddr == NULL) {\n" |
| 461 | " return NULL;\n" |
| 462 | " }\n" |
| 463 | " return get_dispatch_table(%s_instance_table_map, instance)->GetInstanceProcAddr(instance, funcName);\n" |
| 464 | "}\n" % (self.layer_name, self.layer_name)) |
| 465 | return "\n".join(func_body) |
| 466 | else: |
| 467 | # |
| 468 | # TODO:: Old-style GPA Functions -- no local storage, no new logging mechanism. Left for compatibility. |
| 469 | # |
| 470 | func_body.append('%s' % self.lineinfo.get()) |
| 471 | func_body.append("VK_LAYER_EXPORT void* VKAPI vkGetDeviceProcAddr(VkDevice device, const char* funcName)\n" |
| 472 | "{\n" |
| 473 | " void* addr;\n" |
| 474 | " if (device == VK_NULL_HANDLE) {\n" |
| 475 | " return NULL;\n" |
| 476 | " }\n" |
| 477 | " loader_platform_thread_once(&initOnce, init%s);\n\n" |
| 478 | " /* loader uses this to force layer initialization; device object is wrapped */\n" |
| 479 | " if (!strcmp(\"vkGetDeviceProcAddr\", funcName)) {\n" |
| 480 | " initDeviceTable((const VkBaseLayerObject *) device);\n" |
| 481 | " return (void *) vkGetDeviceProcAddr;\n" |
| 482 | " }\n\n" |
| 483 | " addr = layer_intercept_proc(funcName);\n" |
| 484 | " if (addr)\n" |
| 485 | " return addr;" % self.layer_name) |
| 486 | func_body.append('') |
| 487 | func_body.append(' VkLayerDispatchTable *pDisp = device_dispatch_table(device);') |
| 488 | if 0 != len(extensions): |
| 489 | extra_space = "" |
| 490 | for (ext_enable, ext_list) in extensions: |
| 491 | if 0 != len(ext_enable): |
| 492 | func_body.append(' if (deviceExtMap.size() == 0 || deviceExtMap[pDisp].%s)' % ext_enable) |
| 493 | func_body.append(' {') |
| 494 | extra_space = " " |
| 495 | for ext_name in ext_list: |
| 496 | func_body.append(' %sif (!strcmp("%s", funcName))\n' |
| 497 | ' return reinterpret_cast<void*>(%s);' % (extra_space, ext_name, ext_name)) |
| 498 | if 0 != len(ext_enable): |
| 499 | func_body.append(' }') |
| 500 | func_body.append('%s' % self.lineinfo.get()) |
| 501 | func_body.append(" {\n" |
| 502 | " if (pDisp->GetDeviceProcAddr == NULL)\n" |
| 503 | " return NULL;\n" |
| 504 | " return pDisp->GetDeviceProcAddr(device, funcName);\n" |
| 505 | " }\n" |
| 506 | "}\n") |
| 507 | func_body.append("VK_LAYER_EXPORT void* VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)\n" |
| 508 | "{\n" |
| 509 | " void* addr;\n" |
| 510 | " if (instance == VK_NULL_HANDLE) {\n" |
| 511 | " return NULL;\n" |
| 512 | " }\n" |
| 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" |
| 517 | " return (void *) vkGetInstanceProcAddr;\n" |
| 518 | " }\n\n" |
| 519 | " addr = layer_intercept_instance_proc(funcName);\n" |
| 520 | " if (addr)\n" |
| 521 | " return addr;" % self.layer_name) |
| 522 | if 0 != len(instance_extensions): |
| 523 | for ext_name in instance_extensions: |
| 524 | func_body.append(" {\n" |
| 525 | " void *fptr;\n" |
| 526 | " fptr = %s(funcName);\n" |
| 527 | " if (fptr) return fptr;\n" |
| 528 | " }\n" % ext_name) |
| 529 | func_body.append(" VkLayerInstanceDispatchTable* pTable = instance_dispatch_table(instance);\n" |
| 530 | " if (pTable->GetInstanceProcAddr == NULL)\n" |
| 531 | " return NULL;\n" |
| 532 | " return pTable->GetInstanceProcAddr(instance, funcName);\n" |
| 533 | "}\n") |
| 534 | return "\n".join(func_body) |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 535 | |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 536 | |
Mike Stroyan | 354ed67 | 2015-05-15 08:50:57 -0600 | [diff] [blame] | 537 | def _generate_layer_initialization(self, init_opts=False, prefix='vk', lockname=None, condname=None): |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 538 | func_body = ["#include \"vk_dispatch_table_helper.h\""] |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 539 | func_body.append('%s' % self.lineinfo.get()) |
Jon Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 540 | func_body.append('static void init%s(void)\n' |
Mike Stroyan | 3aecdb4 | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 541 | '{\n' % self.layer_name) |
Jon Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 542 | if init_opts: |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 543 | func_body.append('%s' % self.lineinfo.get()) |
Jon Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 544 | func_body.append(' const char *strOpt;') |
Mike Stroyan | 3aecdb4 | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 545 | func_body.append(' // initialize %s options' % self.layer_name) |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 546 | func_body.append(' getLayerOptionEnum("%sReportLevel", (uint32_t *) &g_reportFlags);' % self.layer_name) |
Mike Stroyan | 3aecdb4 | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 547 | func_body.append(' g_actionIsDefault = getLayerOptionEnum("%sDebugAction", (uint32_t *) &g_debugAction);' % self.layer_name) |
Jon Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 548 | func_body.append('') |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 549 | func_body.append(' if (g_debugAction & VK_DBG_LAYER_ACTION_LOG_MSG)') |
Jon Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 550 | func_body.append(' {') |
Mike Stroyan | 3aecdb4 | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 551 | func_body.append(' strOpt = getLayerOption("%sLogFilename");' % self.layer_name) |
Jon Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 552 | func_body.append(' if (strOpt)') |
| 553 | func_body.append(' {') |
| 554 | func_body.append(' g_logFile = fopen(strOpt, "w");') |
| 555 | func_body.append(' }') |
| 556 | func_body.append(' if (g_logFile == NULL)') |
| 557 | func_body.append(' g_logFile = stdout;') |
| 558 | func_body.append(' }') |
| 559 | func_body.append('') |
Tobin Ehlis | 84a8a9b | 2015-02-23 14:09:16 -0700 | [diff] [blame] | 560 | if lockname is not None: |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 561 | func_body.append('%s' % self.lineinfo.get()) |
Tobin Ehlis | 84a8a9b | 2015-02-23 14:09:16 -0700 | [diff] [blame] | 562 | func_body.append(" if (!%sLockInitialized)" % lockname) |
| 563 | func_body.append(" {") |
| 564 | func_body.append(" // TODO/TBD: Need to delete this mutex sometime. How???") |
| 565 | func_body.append(" loader_platform_thread_create_mutex(&%sLock);" % lockname) |
Mike Stroyan | 354ed67 | 2015-05-15 08:50:57 -0600 | [diff] [blame] | 566 | if condname is not None: |
| 567 | func_body.append(" loader_platform_thread_init_cond(&%sCond);" % condname) |
Tobin Ehlis | 84a8a9b | 2015-02-23 14:09:16 -0700 | [diff] [blame] | 568 | func_body.append(" %sLockInitialized = 1;" % lockname) |
| 569 | func_body.append(" }") |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 570 | func_body.append("}\n") |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 571 | func_body.append('') |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 572 | return "\n".join(func_body) |
| 573 | |
| 574 | class LayerFuncsSubcommand(Subcommand): |
| 575 | def generate_header(self): |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 576 | return '#include <vkLayer.h>\n#include "loader.h"' |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 577 | |
| 578 | def generate_body(self): |
Mike Stroyan | 3aecdb4 | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 579 | return self._generate_dispatch_entrypoints("static") |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 580 | |
| 581 | class LayerDispatchSubcommand(Subcommand): |
| 582 | def generate_header(self): |
| 583 | return '#include "layer_wrappers.h"' |
| 584 | |
| 585 | def generate_body(self): |
Jon Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 586 | return self._generate_layer_initialization() |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 587 | |
| 588 | class GenericLayerSubcommand(Subcommand): |
| 589 | def generate_header(self): |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 590 | gen_header = [] |
| 591 | gen_header.append('#include <stdio.h>') |
| 592 | gen_header.append('#include <stdlib.h>') |
| 593 | gen_header.append('#include <string.h>') |
| 594 | gen_header.append('#include <unordered_map>') |
| 595 | gen_header.append('#include "loader_platform.h"') |
| 596 | gen_header.append('#include "vkLayer.h"') |
| 597 | gen_header.append('//The following is #included again to catch certain OS-specific functions being used:') |
| 598 | gen_header.append('') |
| 599 | gen_header.append('#include "loader_platform.h"') |
| 600 | gen_header.append('#include "layers_config.h"') |
| 601 | gen_header.append('#include "layers_msg.h"') |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 602 | gen_header.append('#include "layers_table.h"') |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 603 | gen_header.append('') |
| 604 | gen_header.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(initOnce);') |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 605 | gen_header.append('struct devExts {') |
| 606 | gen_header.append(' bool wsi_lunarg_enabled;') |
| 607 | gen_header.append('};') |
| 608 | gen_header.append('static std::unordered_map<void *, struct devExts> deviceExtMap;') |
| 609 | gen_header.append('') |
| 610 | gen_header.append('static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)') |
| 611 | gen_header.append('{') |
| 612 | gen_header.append(' uint32_t i, ext_idx;') |
| 613 | gen_header.append(' VkLayerDispatchTable *pDisp = device_dispatch_table(device);') |
| 614 | gen_header.append(' deviceExtMap[pDisp].wsi_lunarg_enabled = false;') |
| 615 | gen_header.append(' for (i = 0; i < pCreateInfo->extensionCount; i++) {') |
| 616 | gen_header.append(' if (strcmp(pCreateInfo->pEnabledExtensions[i].name, VK_WSI_LUNARG_EXTENSION_NAME) == 0)') |
| 617 | gen_header.append(' deviceExtMap[pDisp].wsi_lunarg_enabled = true;') |
| 618 | gen_header.append('') |
| 619 | gen_header.append(' }') |
| 620 | gen_header.append('}') |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 621 | gen_header.append('') |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 622 | return "\n".join(gen_header) |
Mike Stroyan | 3aecdb4 | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 623 | def generate_intercept(self, proto, qual): |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 624 | if proto.name in [ 'GetGlobalExtensionCount', 'GetGlobalExtensionProperties', 'GetPhysicalDeviceExtensionCount', 'GetPhysicalDeviceExtensionProperties' ]: |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 625 | # use default version |
| 626 | return None |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 627 | decl = proto.c_func(prefix="vk", attr="VKAPI") |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 628 | ret_val = '' |
| 629 | stmt = '' |
| 630 | funcs = [] |
Jon Ashburn | 52c1d73 | 2015-05-12 17:23:55 -0600 | [diff] [blame] | 631 | table = '' |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 632 | if proto_is_global(proto): |
Jon Ashburn | 52c1d73 | 2015-05-12 17:23:55 -0600 | [diff] [blame] | 633 | table = 'Instance' |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 634 | if proto.ret != "void": |
Courtney Goeltzenleuchter | 4843dda | 2015-06-26 15:07:53 -0600 | [diff] [blame] | 635 | funcs.append('%s' % self.lineinfo.get()) |
Jon Ashburn | 53c1677 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 636 | ret_val = "%s result = " % proto.ret |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 637 | stmt = " return result;\n" |
Jon Ashburn | 7cdb8c3 | 2015-05-22 12:01:50 -0600 | [diff] [blame] | 638 | if proto.name == "CreateDevice": |
Courtney Goeltzenleuchter | 4843dda | 2015-06-26 15:07:53 -0600 | [diff] [blame] | 639 | funcs.append('%s' % self.lineinfo.get()) |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 640 | funcs.append('%s%s\n' |
| 641 | '{\n' |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 642 | ' char str[1024];\n' |
| 643 | ' sprintf(str, "At start of layered %s\\n");\n' |
| 644 | ' layerCbMsg(VK_DBG_REPORT_INFO_BIT,VK_OBJECT_TYPE_PHYSICAL_DEVICE, gpu, 0, 0, (char *) "GENERIC", (char *) str);\n' |
| 645 | ' %sinstance_dispatch_table(gpu)->%s;\n' |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 646 | ' if (result == VK_SUCCESS) {\n' |
| 647 | ' enable_debug_report(pCreateInfo->extensionCount, pCreateInfo->pEnabledExtensions);\n' |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 648 | ' createDeviceRegisterExtensions(pCreateInfo, *pDevice);\n' |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 649 | ' }\n' |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 650 | ' sprintf(str, "Completed layered %s\\n");\n' |
| 651 | ' layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, gpu, 0, 0, (char *) "GENERIC", (char *) str);\n' |
| 652 | ' fflush(stdout);\n' |
| 653 | ' %s' |
| 654 | '}' % (qual, decl, proto.name, ret_val, proto.c_call(), proto.name, stmt)) |
| 655 | elif proto.name == "DestroyDevice": |
Courtney Goeltzenleuchter | 4843dda | 2015-06-26 15:07:53 -0600 | [diff] [blame] | 656 | funcs.append('%s' % self.lineinfo.get()) |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 657 | funcs.append('%s%s\n' |
| 658 | '{\n' |
Courtney Goeltzenleuchter | 9f17194 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 659 | ' dispatch_key key = get_dispatch_key(device);\n' |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 660 | ' VkLayerDispatchTable *pDisp = device_dispatch_table(device);\n' |
| 661 | ' VkResult res = pDisp->DestroyDevice(device);\n' |
| 662 | ' deviceExtMap.erase(pDisp);\n' |
Courtney Goeltzenleuchter | 9f17194 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 663 | ' destroy_device_dispatch_table(key);\n' |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 664 | ' return res;\n' |
| 665 | '}\n' % (qual, decl)) |
| 666 | elif proto.name == "DestroyInstance": |
Courtney Goeltzenleuchter | 4843dda | 2015-06-26 15:07:53 -0600 | [diff] [blame] | 667 | funcs.append('%s' % self.lineinfo.get()) |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 668 | funcs.append('%s%s\n' |
| 669 | '{\n' |
Courtney Goeltzenleuchter | 9f17194 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 670 | ' dispatch_key key = get_dispatch_key(instance);\n' |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 671 | ' VkResult res = instance_dispatch_table(instance)->DestroyInstance(instance);\n' |
Courtney Goeltzenleuchter | 9f17194 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 672 | ' destroy_instance_dispatch_table(key);\n' |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 673 | ' return res;\n' |
| 674 | '}\n' % (qual, decl)) |
Jon Ashburn | 630e44f | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 675 | else: |
Courtney Goeltzenleuchter | 4843dda | 2015-06-26 15:07:53 -0600 | [diff] [blame] | 676 | funcs.append('%s' % self.lineinfo.get()) |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 677 | # CreateInstance needs to use the second parm instead of the first to set the correct dispatch table |
| 678 | dispatch_param = proto.params[0].name |
| 679 | # Must use 'instance' table for these APIs, 'device' table otherwise |
| 680 | table_type = "" |
| 681 | if proto_is_global(proto): |
| 682 | table_type = "instance" |
| 683 | else: |
| 684 | table_type = "device" |
| 685 | if 'CreateInstance' in proto.name: |
| 686 | dispatch_param = '*' + proto.params[1].name |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 687 | funcs.append('%s%s\n' |
| 688 | '{\n' |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 689 | ' %s%s_dispatch_table(%s)->%s;\n' |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 690 | '%s' |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 691 | '}' % (qual, decl, ret_val, table_type, dispatch_param, proto.c_call(), stmt)) |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 692 | return "\n\n".join(funcs) |
| 693 | |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 694 | def generate_body(self): |
Mike Stroyan | 3aecdb4 | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 695 | self.layer_name = "Generic" |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 696 | extensions=[('wsi_lunarg_enabled', |
| 697 | ['vkCreateSwapChainWSI', 'vkDestroySwapChainWSI', |
| 698 | 'vkGetSwapChainInfoWSI', 'vkQueuePresentWSI'])] |
Mike Stroyan | 3aecdb4 | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 699 | body = [self._generate_layer_initialization(True), |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 700 | self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"), |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 701 | self._gen_create_msg_callback(), |
| 702 | self._gen_destroy_msg_callback(), |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 703 | self._generate_layer_gpa_function(extensions)] |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 704 | |
| 705 | return "\n\n".join(body) |
| 706 | |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 707 | class APIDumpSubcommand(Subcommand): |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 708 | def generate_header(self): |
Tobin Ehlis | 0c68c9c | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 709 | header_txt = [] |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 710 | header_txt.append('%s' % self.lineinfo.get()) |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 711 | header_txt.append('#include <fstream>') |
| 712 | header_txt.append('#include <iostream>') |
| 713 | header_txt.append('#include <string>') |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 714 | header_txt.append('#include <string.h>') |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 715 | header_txt.append('') |
| 716 | header_txt.append('static std::ofstream fileStream;') |
| 717 | header_txt.append('static std::string fileName = "vk_apidump.txt";') |
| 718 | header_txt.append('std::ostream* outputStream = NULL;') |
| 719 | header_txt.append('void ConfigureOutputStream(bool writeToFile, bool flushAfterWrite)') |
| 720 | header_txt.append('{') |
| 721 | header_txt.append(' if(writeToFile)') |
| 722 | header_txt.append(' {') |
| 723 | header_txt.append(' fileStream.open(fileName);') |
| 724 | header_txt.append(' outputStream = &fileStream;') |
| 725 | header_txt.append(' }') |
| 726 | header_txt.append(' else') |
| 727 | header_txt.append(' {') |
| 728 | header_txt.append(' outputStream = &std::cout;') |
| 729 | header_txt.append(' }') |
| 730 | header_txt.append('') |
| 731 | header_txt.append(' if(flushAfterWrite)') |
| 732 | header_txt.append(' {') |
| 733 | header_txt.append(' outputStream->sync_with_stdio(true);') |
| 734 | header_txt.append(' }') |
| 735 | header_txt.append(' else') |
| 736 | header_txt.append(' {') |
| 737 | header_txt.append(' outputStream->sync_with_stdio(false);') |
| 738 | header_txt.append(' }') |
| 739 | header_txt.append('}') |
| 740 | header_txt.append('') |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 741 | header_txt.append('%s' % self.lineinfo.get()) |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 742 | header_txt.append('#include "loader_platform.h"') |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 743 | header_txt.append('#include "vkLayer.h"') |
| 744 | header_txt.append('#include "vk_struct_string_helper_cpp.h"') |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 745 | header_txt.append('#include "layers_table.h"') |
Mark Lobodzinski | bf7c700 | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 746 | header_txt.append('#include <unordered_map>') |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 747 | header_txt.append('') |
Ian Elliott | 20f0687 | 2015-02-12 17:08:34 -0700 | [diff] [blame] | 748 | header_txt.append('// The following is #included again to catch certain OS-specific functions being used:') |
| 749 | header_txt.append('#include "loader_platform.h"') |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 750 | header_txt.append('') |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 751 | header_txt.append('static VkBaseLayerObject *pCurObj;') |
Tobin Ehlis | 55c4041 | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 752 | header_txt.append('static bool g_APIDumpDetailed = true;') |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 753 | header_txt.append('') |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 754 | header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(initOnce);') |
Mark Lobodzinski | bf7c700 | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 755 | header_txt.append('') |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 756 | header_txt.append('static int printLockInitialized = 0;') |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 757 | header_txt.append('static loader_platform_thread_mutex printLock;') |
| 758 | header_txt.append('') |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 759 | header_txt.append('%s' % self.lineinfo.get()) |
Tobin Ehlis | 0c68c9c | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 760 | header_txt.append('#define MAX_TID 513') |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 761 | header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};') |
Tobin Ehlis | 0c68c9c | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 762 | header_txt.append('static uint32_t maxTID = 0;') |
| 763 | header_txt.append('// Map actual TID to an index value and return that index') |
| 764 | header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs') |
| 765 | header_txt.append('static uint32_t getTIDIndex() {') |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 766 | header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();') |
Tobin Ehlis | 0c68c9c | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 767 | header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {') |
| 768 | header_txt.append(' if (tid == tidMapping[i])') |
| 769 | header_txt.append(' return i;') |
| 770 | header_txt.append(' }') |
| 771 | header_txt.append(" // Don't yet have mapping, set it and return newly set index") |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 772 | header_txt.append(' uint32_t retVal = (uint32_t) maxTID;') |
Tobin Ehlis | 0c68c9c | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 773 | header_txt.append(' tidMapping[maxTID++] = tid;') |
| 774 | header_txt.append(' assert(maxTID < MAX_TID);') |
| 775 | header_txt.append(' return retVal;') |
| 776 | header_txt.append('}') |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 777 | header_txt.append('struct devExts {') |
| 778 | header_txt.append(' bool wsi_lunarg_enabled;') |
| 779 | header_txt.append('};') |
| 780 | header_txt.append('') |
| 781 | header_txt.append('static std::unordered_map<void *, struct devExts> deviceExtMap;') |
| 782 | header_txt.append('') |
| 783 | header_txt.append('static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)') |
| 784 | header_txt.append('{') |
| 785 | header_txt.append(' uint32_t i, ext_idx;') |
| 786 | header_txt.append(' VkLayerDispatchTable *pDisp = device_dispatch_table(device);') |
| 787 | header_txt.append(' deviceExtMap[pDisp].wsi_lunarg_enabled = false;') |
| 788 | header_txt.append(' for (i = 0; i < pCreateInfo->extensionCount; i++) {') |
| 789 | header_txt.append(' if (strcmp(pCreateInfo->pEnabledExtensions[i].name, VK_WSI_LUNARG_EXTENSION_NAME) == 0)') |
| 790 | header_txt.append(' deviceExtMap[pDisp].wsi_lunarg_enabled = true;') |
| 791 | header_txt.append('') |
| 792 | header_txt.append(' }') |
| 793 | header_txt.append('}') |
Mark Lobodzinski | bf7c700 | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 794 | header_txt.append('') |
Tobin Ehlis | 0c68c9c | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 795 | return "\n".join(header_txt) |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 796 | |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 797 | def generate_init(self): |
| 798 | func_body = [] |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 799 | func_body.append('%s' % self.lineinfo.get()) |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 800 | func_body.append('#include "vk_dispatch_table_helper.h"') |
| 801 | func_body.append('#include "layers_config.h"') |
| 802 | func_body.append('') |
| 803 | func_body.append('static void init%s(void)' % self.layer_name) |
| 804 | func_body.append('{') |
| 805 | func_body.append(' using namespace StreamControl;') |
| 806 | func_body.append('') |
Tobin Ehlis | 55c4041 | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 807 | func_body.append(' char const*const detailedStr = getLayerOption("APIDumpDetailed");') |
| 808 | func_body.append(' if(detailedStr != NULL)') |
| 809 | func_body.append(' {') |
| 810 | func_body.append(' if(strcmp(detailedStr, "TRUE") == 0)') |
| 811 | func_body.append(' {') |
| 812 | func_body.append(' g_APIDumpDetailed = true;') |
| 813 | func_body.append(' }') |
| 814 | func_body.append(' else if(strcmp(detailedStr, "FALSE") == 0)') |
| 815 | func_body.append(' {') |
| 816 | func_body.append(' g_APIDumpDetailed = false;') |
| 817 | func_body.append(' }') |
| 818 | func_body.append(' }') |
| 819 | func_body.append('') |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 820 | func_body.append(' char const*const writeToFileStr = getLayerOption("APIDumpFile");') |
| 821 | func_body.append(' bool writeToFile = false;') |
| 822 | func_body.append(' if(writeToFileStr != NULL)') |
| 823 | func_body.append(' {') |
| 824 | func_body.append(' if(strcmp(writeToFileStr, "TRUE") == 0)') |
| 825 | func_body.append(' {') |
| 826 | func_body.append(' writeToFile = true;') |
| 827 | func_body.append(' }') |
| 828 | func_body.append(' else if(strcmp(writeToFileStr, "FALSE") == 0)') |
| 829 | func_body.append(' {') |
| 830 | func_body.append(' writeToFile = false;') |
| 831 | func_body.append(' }') |
| 832 | func_body.append(' }') |
| 833 | func_body.append('') |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 834 | func_body.append('%s' % self.lineinfo.get()) |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 835 | func_body.append(' char const*const noAddrStr = getLayerOption("APIDumpNoAddr");') |
| 836 | func_body.append(' if(noAddrStr != NULL)') |
| 837 | func_body.append(' {') |
| 838 | func_body.append(' if(strcmp(noAddrStr, "FALSE") == 0)') |
| 839 | func_body.append(' {') |
| 840 | func_body.append(' StreamControl::writeAddress = true;') |
| 841 | func_body.append(' }') |
| 842 | func_body.append(' else if(strcmp(noAddrStr, "TRUE") == 0)') |
| 843 | func_body.append(' {') |
| 844 | func_body.append(' StreamControl::writeAddress = false;') |
| 845 | func_body.append(' }') |
| 846 | func_body.append(' }') |
| 847 | func_body.append('') |
| 848 | func_body.append(' char const*const flushAfterWriteStr = getLayerOption("APIDumpFlush");') |
| 849 | func_body.append(' bool flushAfterWrite = false;') |
| 850 | func_body.append(' if(flushAfterWriteStr != NULL)') |
| 851 | func_body.append(' {') |
| 852 | func_body.append(' if(strcmp(flushAfterWriteStr, "TRUE") == 0)') |
| 853 | func_body.append(' {') |
| 854 | func_body.append(' flushAfterWrite = true;') |
| 855 | func_body.append(' }') |
| 856 | func_body.append(' else if(strcmp(flushAfterWriteStr, "FALSE") == 0)') |
| 857 | func_body.append(' {') |
| 858 | func_body.append(' flushAfterWrite = false;') |
| 859 | func_body.append(' }') |
| 860 | func_body.append(' }') |
| 861 | func_body.append('') |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 862 | func_body.append('%s' % self.lineinfo.get()) |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 863 | func_body.append(' ConfigureOutputStream(writeToFile, flushAfterWrite);') |
| 864 | func_body.append('') |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 865 | func_body.append(' if (!printLockInitialized)') |
| 866 | func_body.append(' {') |
| 867 | func_body.append(' // TODO/TBD: Need to delete this mutex sometime. How???') |
| 868 | func_body.append(' loader_platform_thread_create_mutex(&printLock);') |
| 869 | func_body.append(' printLockInitialized = 1;') |
| 870 | func_body.append(' }') |
| 871 | func_body.append('}') |
| 872 | func_body.append('') |
| 873 | return "\n".join(func_body) |
Tobin Ehlis | 434db7c | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 874 | |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 875 | def generate_intercept(self, proto, qual): |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 876 | if proto.name in [ 'GetGlobalExtensionCount','GetGlobalExtensionProperties','GetPhysicalDeviceExtensionCount','GetPhysicalDeviceExtensionProperties']: |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 877 | return None |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 878 | decl = proto.c_func(prefix="vk", attr="VKAPI") |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 879 | ret_val = '' |
| 880 | stmt = '' |
| 881 | funcs = [] |
| 882 | sp_param_dict = {} # Store 'index' for struct param to print, or an name of binding "Count" param for array to print |
| 883 | create_params = 0 # Num of params at end of function that are created and returned as output values |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 884 | if 'AllocDescriptorSets' in proto.name: |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 885 | create_params = -2 |
| 886 | elif 'Create' in proto.name or 'Alloc' in proto.name or 'MapMemory' in proto.name: |
| 887 | create_params = -1 |
| 888 | if proto.ret != "void": |
Jon Ashburn | 53c1677 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 889 | ret_val = "%s result = " % proto.ret |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 890 | stmt = " return result;\n" |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 891 | f_open = 'loader_platform_thread_lock_mutex(&printLock);\n ' |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 892 | log_func = '%s\n' % self.lineinfo.get() |
| 893 | log_func += ' if (StreamControl::writeAddress == true) {' |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 894 | log_func += '\n (*outputStream) << "t{" << getTIDIndex() << "} vk%s(' % proto.name |
| 895 | log_func_no_addr = '\n (*outputStream) << "t{" << getTIDIndex() << "} vk%s(' % proto.name |
| 896 | f_close = '\n loader_platform_thread_unlock_mutex(&printLock);' |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 897 | pindex = 0 |
| 898 | prev_count_name = '' |
| 899 | for p in proto.params: |
| 900 | cp = False |
| 901 | if 0 != create_params: |
| 902 | # If this is any of the N last params of the func, treat as output |
| 903 | for y in range(-1, create_params-1, -1): |
| 904 | if p.name == proto.params[y].name: |
| 905 | cp = True |
| 906 | (pft, pfi) = self._get_printf_params(p.ty, p.name, cp, cpp=True) |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 907 | log_func += '%s = " << %s << ", ' % (p.name, pfi) |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 908 | if "%p" == pft: |
| 909 | log_func_no_addr += '%s = address, ' % (p.name) |
| 910 | else: |
| 911 | log_func_no_addr += '%s = " << %s << ", ' % (p.name, pfi) |
Tobin Ehlis | c99cb0d | 2015-04-16 15:56:11 -0600 | [diff] [blame] | 912 | if prev_count_name != '' and (prev_count_name.replace('Count', '')[1:] in p.name): |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 913 | sp_param_dict[pindex] = prev_count_name |
Tobin Ehlis | c99cb0d | 2015-04-16 15:56:11 -0600 | [diff] [blame] | 914 | prev_count_name = '' |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 915 | elif 'pDescriptorSets' == p.name and proto.params[-1].name == 'pCount': |
| 916 | sp_param_dict[pindex] = '*pCount' |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 917 | elif vk_helper.is_type(p.ty.strip('*').replace('const ', ''), 'struct'): |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 918 | sp_param_dict[pindex] = 'index' |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 919 | if p.name.endswith('Count'): |
| 920 | if '*' in p.ty: |
| 921 | prev_count_name = "*%s" % p.name |
| 922 | else: |
| 923 | prev_count_name = p.name |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 924 | pindex += 1 |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 925 | log_func = log_func.strip(', ') |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 926 | log_func_no_addr = log_func_no_addr.strip(', ') |
Jon Ashburn | 53c1677 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 927 | if proto.ret == "VkResult": |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 928 | log_func += ') = " << string_VkResult((VkResult)result) << endl' |
| 929 | log_func_no_addr += ') = " << string_VkResult((VkResult)result) << endl' |
Jon Ashburn | 53c1677 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 930 | elif proto.ret == "void*": |
| 931 | log_func += ') = " << result << endl' |
| 932 | log_func_no_addr += ') = " << result << endl' |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 933 | else: |
| 934 | log_func += ')\\n"' |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 935 | log_func_no_addr += ')\\n"' |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 936 | log_func += ';' |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 937 | log_func_no_addr += ';' |
| 938 | log_func += '\n }\n else {%s;\n }' % log_func_no_addr; |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 939 | log_func += '\n%s' % self.lineinfo.get() |
Tobin Ehlis | f29da38 | 2015-04-15 07:46:12 -0600 | [diff] [blame] | 940 | #print("Proto %s has param_dict: %s" % (proto.name, sp_param_dict)) |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 941 | if len(sp_param_dict) > 0: |
Tobin Ehlis | 55c4041 | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 942 | indent = ' ' |
| 943 | log_func += '\n%sif (g_APIDumpDetailed) {' % indent |
| 944 | indent += ' ' |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 945 | i_decl = False |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 946 | log_func += '\n%s' % self.lineinfo.get() |
Tobin Ehlis | 55c4041 | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 947 | log_func += '\n%sstring tmp_str;' % indent |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 948 | for sp_index in sp_param_dict: |
Tobin Ehlis | f29da38 | 2015-04-15 07:46:12 -0600 | [diff] [blame] | 949 | #print("sp_index: %s" % str(sp_index)) |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 950 | if 'index' == sp_param_dict[sp_index]: |
Courtney Goeltzenleuchter | ddcb619 | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 951 | cis_print_func = 'vk_print_%s' % (proto.params[sp_index].ty.replace('const ', '').strip('*').lower()) |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 952 | local_name = proto.params[sp_index].name |
| 953 | if '*' not in proto.params[sp_index].ty: |
| 954 | local_name = '&%s' % proto.params[sp_index].name |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 955 | log_func += '\n%s' % self.lineinfo.get() |
Tobin Ehlis | 55c4041 | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 956 | log_func += '\n%sif (%s) {' % (indent, local_name) |
| 957 | indent += ' ' |
| 958 | log_func += '\n%stmp_str = %s(%s, " ");' % (indent, cis_print_func, local_name) |
| 959 | log_func += '\n%s(*outputStream) << " %s (" << %s << ")" << endl << tmp_str << endl;' % (indent, local_name, local_name) |
| 960 | indent = indent[4:] |
| 961 | log_func += '\n%s}' % (indent) |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 962 | else: # We have a count value stored to iterate over an array |
| 963 | print_cast = '' |
| 964 | print_func = '' |
Courtney Goeltzenleuchter | ddcb619 | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 965 | if vk_helper.is_type(proto.params[sp_index].ty.strip('*').replace('const ', ''), 'struct'): |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 966 | print_cast = '&' |
Courtney Goeltzenleuchter | ddcb619 | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 967 | print_func = 'vk_print_%s' % proto.params[sp_index].ty.replace('const ', '').strip('*').lower() |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 968 | else: |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 969 | print_cast = '' |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 970 | print_func = 'string_convert_helper' |
| 971 | #cis_print_func = 'tmp_str = string_convert_helper((void*)%s[i], " ");' % proto.params[sp_index].name |
| 972 | cis_print_func = 'tmp_str = %s(%s%s[i], " ");' % (print_func, print_cast, proto.params[sp_index].name) |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 973 | if not i_decl: |
Tobin Ehlis | 55c4041 | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 974 | log_func += '\n%suint32_t i;' % (indent) |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 975 | i_decl = True |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 976 | log_func += '\n%sif (%s) {' % (indent, proto.params[sp_index].name) |
| 977 | indent += ' ' |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 978 | log_func += '\n%s' % self.lineinfo.get() |
Tobin Ehlis | 55c4041 | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 979 | log_func += '\n%sfor (i = 0; i < %s; i++) {' % (indent, sp_param_dict[sp_index]) |
| 980 | indent += ' ' |
| 981 | log_func += '\n%s%s' % (indent, cis_print_func) |
Tobin Ehlis | 8ad1574 | 2015-04-28 10:58:20 -0600 | [diff] [blame] | 982 | log_func += '\n%sif (StreamControl::writeAddress == true) {' % (indent) |
| 983 | indent += ' ' |
Tobin Ehlis | 55c4041 | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 984 | 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) |
| 985 | indent = indent[4:] |
Tobin Ehlis | 8ad1574 | 2015-04-28 10:58:20 -0600 | [diff] [blame] | 986 | log_func += '\n%s} else {' % (indent) |
| 987 | indent += ' ' |
| 988 | log_func += '\n%s(*outputStream) << " %s[" << i << "] (address)" << endl << " address" << endl;' % (indent, proto.params[sp_index].name) |
| 989 | indent = indent[4:] |
| 990 | log_func += '\n%s}' % (indent) |
| 991 | indent = indent[4:] |
Tobin Ehlis | 55c4041 | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 992 | log_func += '\n%s}' % (indent) |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 993 | indent = indent[4:] |
| 994 | log_func += '\n%s}' % (indent) |
Tobin Ehlis | 55c4041 | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 995 | indent = indent[4:] |
| 996 | log_func += '\n%s}' % (indent) |
Mark Lobodzinski | bf7c700 | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 997 | table_type = '' |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 998 | if proto_is_global(proto): |
Mark Lobodzinski | bf7c700 | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 999 | table_type = 'instance' |
| 1000 | else: |
| 1001 | table_type = 'device' |
Jon Ashburn | 52c1d73 | 2015-05-12 17:23:55 -0600 | [diff] [blame] | 1002 | |
Mark Lobodzinski | bf7c700 | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 1003 | if proto.name == "CreateInstance": |
| 1004 | dispatch_param = '*' + proto.params[1].name |
| 1005 | else: |
| 1006 | dispatch_param = proto.params[0].name |
| 1007 | |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 1008 | if proto.name == "CreateDevice": |
Courtney Goeltzenleuchter | 4843dda | 2015-06-26 15:07:53 -0600 | [diff] [blame] | 1009 | funcs.append('%s\n' % self.lineinfo.get()) |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 1010 | funcs.append('%s%s\n' |
| 1011 | '{\n' |
| 1012 | ' using namespace StreamControl;\n' |
| 1013 | ' %s%s_dispatch_table(%s)->%s;\n' |
| 1014 | ' if (result == VK_SUCCESS)\n' |
| 1015 | ' createDeviceRegisterExtensions(pCreateInfo, *pDevice);\n' |
| 1016 | ' %s%s%s\n' |
| 1017 | '%s' |
| 1018 | '}' % (qual, decl, ret_val, table_type, dispatch_param, proto.c_call(), f_open, log_func, f_close, stmt)) |
| 1019 | elif proto.name == "DestroyDevice": |
Mark Lobodzinski | bf7c700 | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 1020 | funcs.append('%s%s\n' |
| 1021 | '{\n' |
| 1022 | ' using namespace StreamControl;\n' |
Courtney Goeltzenleuchter | 9f17194 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 1023 | ' dispatch_key key = get_dispatch_key(device);\n' |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 1024 | ' VkLayerDispatchTable *pDisp = %s_dispatch_table(%s);\n' |
| 1025 | ' %spDisp->%s;\n' |
| 1026 | ' deviceExtMap.erase(pDisp);\n' |
Courtney Goeltzenleuchter | 9f17194 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 1027 | ' destroy_device_dispatch_table(key);\n' |
Mark Lobodzinski | bf7c700 | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 1028 | ' %s%s%s\n' |
| 1029 | '%s' |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 1030 | '}' % (qual, decl, table_type, dispatch_param, ret_val, proto.c_call(), f_open, log_func, f_close, stmt)) |
Mark Lobodzinski | bf7c700 | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 1031 | elif proto.name == "DestroyInstance": |
| 1032 | funcs.append('%s%s\n' |
| 1033 | '{\n' |
| 1034 | ' using namespace StreamControl;\n' |
Courtney Goeltzenleuchter | 9f17194 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 1035 | ' dispatch_key key = get_dispatch_key(instance);\n' |
Mark Lobodzinski | bf7c700 | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 1036 | ' %s%s_dispatch_table(%s)->%s;\n' |
Courtney Goeltzenleuchter | 9f17194 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 1037 | ' destroy_instance_dispatch_table(key);\n' |
Mark Lobodzinski | bf7c700 | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 1038 | ' %s%s%s\n' |
| 1039 | '%s' |
| 1040 | '}' % (qual, decl, ret_val, table_type, dispatch_param, proto.c_call(), f_open, log_func, f_close, stmt)) |
| 1041 | else: |
| 1042 | funcs.append('%s%s\n' |
| 1043 | '{\n' |
| 1044 | ' using namespace StreamControl;\n' |
| 1045 | ' %s%s_dispatch_table(%s)->%s;\n' |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 1046 | ' %s%s%s\n' |
| 1047 | '%s' |
Mark Lobodzinski | bf7c700 | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 1048 | '}' % (qual, decl, ret_val, table_type, dispatch_param, proto.c_call(), f_open, log_func, f_close, stmt)) |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 1049 | return "\n\n".join(funcs) |
| 1050 | |
Tobin Ehlis | 434db7c | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1051 | def generate_body(self): |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 1052 | self.layer_name = "APIDump" |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 1053 | extensions=[('wsi_lunarg_enabled', |
| 1054 | ['vkCreateSwapChainWSI', 'vkDestroySwapChainWSI', |
| 1055 | 'vkGetSwapChainInfoWSI', 'vkQueuePresentWSI'])] |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 1056 | body = [self.generate_init(), |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1057 | self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"), |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 1058 | self._generate_layer_gpa_function(extensions)] |
Tobin Ehlis | 434db7c | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1059 | return "\n\n".join(body) |
| 1060 | |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1061 | class ObjectTrackerSubcommand(Subcommand): |
| 1062 | def generate_header(self): |
| 1063 | header_txt = [] |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1064 | header_txt.append('%s' % self.lineinfo.get()) |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1065 | header_txt.append('#include <stdio.h>') |
| 1066 | header_txt.append('#include <stdlib.h>') |
| 1067 | header_txt.append('#include <string.h>') |
| 1068 | header_txt.append('#include <inttypes.h>') |
| 1069 | header_txt.append('') |
| 1070 | header_txt.append('#include "vulkan.h"') |
| 1071 | header_txt.append('#include "loader_platform.h"') |
| 1072 | header_txt.append('') |
Tobin Ehlis | 586aa01 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1073 | header_txt.append('#include <unordered_map>') |
| 1074 | header_txt.append('using namespace std;') |
Ian Elliott | 20f0687 | 2015-02-12 17:08:34 -0700 | [diff] [blame] | 1075 | header_txt.append('// The following is #included again to catch certain OS-specific functions being used:') |
| 1076 | header_txt.append('#include "loader_platform.h"') |
Jon Ashburn | 7a2da4f | 2015-02-17 11:03:12 -0700 | [diff] [blame] | 1077 | header_txt.append('#include "layers_config.h"') |
Jon Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 1078 | header_txt.append('#include "layers_msg.h"') |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1079 | header_txt.append('#include "vk_debug_report_lunarg.h"') |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 1080 | header_txt.append('#include "layers_table.h"') |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1081 | header_txt.append('#include "layer_data.h"') |
| 1082 | header_txt.append('#include "layer_logging.h"') |
| 1083 | header_txt.append('') |
| 1084 | # NOTE: The non-autoGenerated code is in the object_track.h header file |
| 1085 | header_txt.append('#include "object_track.h"') |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1086 | header_txt.append('') |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 1087 | header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(initOnce);') |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1088 | header_txt.append('') |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1089 | return "\n".join(header_txt) |
| 1090 | |
Mike Stroyan | 3aecdb4 | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 1091 | def generate_intercept(self, proto, qual): |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 1092 | if proto.name in [ 'DbgCreateMsgCallback', 'GetGlobalExtensionCount', 'GetGlobalExtensionProperties','GetPhysicalDeviceExtensionCount', 'GetPhysicalDeviceExtensionProperties' ]: |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1093 | # use default version |
| 1094 | return None |
Mark Lobodzinski | 4e5016f | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 1095 | |
| 1096 | # Create map of object names to object type enums of the form VkName : VkObjectTypeName |
Tobin Ehlis | f29da38 | 2015-04-15 07:46:12 -0600 | [diff] [blame] | 1097 | obj_type_mapping = {base_t : base_t.replace("Vk", "VkObjectType") for base_t in vulkan.object_type_list} |
Mark Lobodzinski | 4e5016f | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 1098 | # Convert object type enum names from UpperCamelCase to UPPER_CASE_WITH_UNDERSCORES |
| 1099 | for objectName, objectTypeEnum in obj_type_mapping.items(): |
| 1100 | obj_type_mapping[objectName] = ucc_to_U_C_C(objectTypeEnum); |
| 1101 | # Command Buffer Object doesn't follow the rule. |
| 1102 | obj_type_mapping['VkCmdBuffer'] = "VK_OBJECT_TYPE_COMMAND_BUFFER" |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1103 | |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1104 | explicit_object_tracker_functions = [ |
| 1105 | "CreateInstance", |
| 1106 | "DestroyInstance", |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 1107 | "GetPhysicalDeviceQueueProperties", |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1108 | "CreateDevice", |
| 1109 | "DestroyDevice", |
| 1110 | "GetDeviceQueue", |
| 1111 | "QueueSubmit", |
| 1112 | "DestroyObject", |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 1113 | "GetObjectMemoryRequirements", |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1114 | "QueueBindSparseImageMemory", |
| 1115 | "QueueBindSparseBufferMemory", |
| 1116 | "GetFenceStatus", |
| 1117 | "WaitForFences", |
| 1118 | "AllocDescriptorSets", |
| 1119 | "MapMemory", |
| 1120 | "UnmapMemory", |
| 1121 | "FreeMemory", |
| 1122 | "DestroySwapChainWSI" |
| 1123 | ] |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1124 | decl = proto.c_func(prefix="vk", attr="VKAPI") |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1125 | param0_name = proto.params[0].name |
Mark Lobodzinski | c44a5a1 | 2015-05-08 09:12:28 -0500 | [diff] [blame] | 1126 | using_line = '' |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1127 | create_line = '' |
Tobin Ehlis | 586aa01 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1128 | object_params = [] |
| 1129 | # TODO : Should also check through struct params & add any objects embedded in struct chains |
| 1130 | # TODO : A few of the skipped types are just "hard" cases that need some more work to support |
| 1131 | # Need to handle NULL fences on queue submit, binding null memory, and WSI Image objects |
| 1132 | for p in proto.params: |
| 1133 | if p.ty in vulkan.core.objects and p.ty not in ['VkPhysicalDevice', 'VkQueue', 'VkFence', 'VkImage', 'VkDeviceMemory']: |
| 1134 | object_params.append(p.name) |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1135 | funcs = [] |
Tobin Ehlis | 586aa01 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1136 | mutex_unlock = False |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1137 | if proto.name in explicit_object_tracker_functions: |
Jon Ashburn | 630e44f | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 1138 | funcs.append('%s%s\n' |
| 1139 | '{\n' |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1140 | ' return explicit_%s;\n' |
| 1141 | '}' % (qual, decl, proto.c_call())) |
| 1142 | return "".join(funcs) |
Jon Ashburn | 630e44f | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 1143 | else: |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1144 | if 'Create' in proto.name or 'Alloc' in proto.name: |
| 1145 | create_line = ' loader_platform_thread_lock_mutex(&objLock);\n' |
| 1146 | create_line += ' if (result == VK_SUCCESS) {\n' |
| 1147 | create_line += ' create_obj(%s, *%s, %s);\n' % (param0_name, proto.params[-1].name, obj_type_mapping[proto.params[-1].ty.strip('*').replace('const ', '')]) |
| 1148 | create_line += ' }\n' |
| 1149 | create_line += ' loader_platform_thread_unlock_mutex(&objLock);\n' |
| 1150 | if len(object_params) > 0: |
| 1151 | if not mutex_unlock: |
| 1152 | using_line += ' loader_platform_thread_lock_mutex(&objLock);\n' |
| 1153 | mutex_unlock = True |
| 1154 | for opn in object_params: |
| 1155 | using_line += ' validate_object(%s, %s);\n' % (param0_name, opn) |
| 1156 | if mutex_unlock: |
| 1157 | using_line += ' loader_platform_thread_unlock_mutex(&objLock);\n' |
| 1158 | ret_val = '' |
| 1159 | stmt = '' |
| 1160 | table = '' |
| 1161 | if proto.ret != "void": |
| 1162 | ret_val = "%s result = " % proto.ret |
| 1163 | stmt = " return result;\n" |
| 1164 | |
| 1165 | dispatch_param = proto.params[0].name |
| 1166 | if 'CreateInstance' in proto.name: |
| 1167 | dispatch_param = '*' + proto.params[1].name |
| 1168 | |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1169 | # Must use 'instance' table for these APIs, 'device' table otherwise |
| 1170 | table_type = "" |
| 1171 | if proto_is_global(proto): |
| 1172 | table_type = "instance" |
| 1173 | else: |
| 1174 | table_type = "device" |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1175 | funcs.append('%s%s\n' |
| 1176 | '{\n' |
| 1177 | '%s' |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1178 | ' %sget_dispatch_table(ObjectTracker_%s_table_map, %s)->%s;\n' |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1179 | '%s' |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1180 | '%s' |
| 1181 | '}' % (qual, decl, using_line, ret_val, table_type, dispatch_param, proto.c_call(), create_line, stmt)) |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1182 | return "\n\n".join(funcs) |
| 1183 | |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1184 | def generate_body(self): |
Mike Stroyan | 3aecdb4 | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 1185 | self.layer_name = "ObjectTracker" |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 1186 | extensions=[('wsi_lunarg_enabled', |
| 1187 | ['vkCreateSwapChainWSI', 'vkDestroySwapChainWSI', |
| 1188 | 'vkGetSwapChainInfoWSI', 'vkQueuePresentWSI']), |
| 1189 | ('', |
| 1190 | ['objTrackGetObjectsCount', 'objTrackGetObjects', |
| 1191 | 'objTrackGetObjectsOfTypeCount', 'objTrackGetObjectsOfType'])] |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1192 | body = [self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"), |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1193 | self._generate_extensions(), |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 1194 | self._generate_layer_gpa_function(extensions, |
Courtney Goeltzenleuchter | ce445ad | 2015-06-01 14:52:57 -0600 | [diff] [blame] | 1195 | instance_extensions=['msg_callback_get_proc_addr'])] |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1196 | return "\n\n".join(body) |
Courtney Goeltzenleuchter | e6094fc | 2014-11-18 10:40:29 -0700 | [diff] [blame] | 1197 | |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1198 | class ThreadingSubcommand(Subcommand): |
| 1199 | def generate_header(self): |
| 1200 | header_txt = [] |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1201 | header_txt.append('%s' % self.lineinfo.get()) |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1202 | header_txt.append('#include <stdio.h>') |
| 1203 | header_txt.append('#include <stdlib.h>') |
| 1204 | header_txt.append('#include <string.h>') |
| 1205 | header_txt.append('#include <unordered_map>') |
| 1206 | header_txt.append('#include "loader_platform.h"') |
| 1207 | header_txt.append('#include "vkLayer.h"') |
| 1208 | header_txt.append('#include "threading.h"') |
| 1209 | header_txt.append('#include "layers_config.h"') |
| 1210 | header_txt.append('#include "vk_enum_validate_helper.h"') |
| 1211 | header_txt.append('#include "vk_struct_validate_helper.h"') |
| 1212 | header_txt.append('//The following is #included again to catch certain OS-specific functions being used:') |
| 1213 | header_txt.append('#include "loader_platform.h"\n') |
| 1214 | header_txt.append('#include "layers_msg.h"\n') |
Jon Ashburn | 5a10d21 | 2015-06-01 10:02:09 -0600 | [diff] [blame] | 1215 | header_txt.append('#include "layers_table.h"\n') |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1216 | header_txt.append('') |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1217 | header_txt.append('') |
| 1218 | header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(initOnce);') |
| 1219 | header_txt.append('') |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1220 | header_txt.append('using namespace std;') |
| 1221 | header_txt.append('static unordered_map<int, void*> proxy_objectsInUse;\n') |
| 1222 | header_txt.append('static unordered_map<VkObject, loader_platform_thread_id> objectsInUse;\n') |
| 1223 | header_txt.append('static int threadingLockInitialized = 0;') |
| 1224 | header_txt.append('static loader_platform_thread_mutex threadingLock;') |
Mike Stroyan | 354ed67 | 2015-05-15 08:50:57 -0600 | [diff] [blame] | 1225 | header_txt.append('static loader_platform_thread_cond threadingCond;') |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1226 | header_txt.append('static int printLockInitialized = 0;') |
| 1227 | header_txt.append('static loader_platform_thread_mutex printLock;\n') |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1228 | header_txt.append('%s' % self.lineinfo.get()) |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1229 | header_txt.append('static void useObject(VkObject object, const char* type)') |
| 1230 | header_txt.append('{') |
| 1231 | header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();') |
| 1232 | header_txt.append(' loader_platform_thread_lock_mutex(&threadingLock);') |
| 1233 | header_txt.append(' if (objectsInUse.find(object) == objectsInUse.end()) {') |
| 1234 | header_txt.append(' objectsInUse[object] = tid;') |
| 1235 | header_txt.append(' } else {') |
Mike Stroyan | ae0eafd | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1236 | header_txt.append(' if (objectsInUse[object] != tid) {') |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1237 | header_txt.append(' char str[1024];') |
| 1238 | header_txt.append(' sprintf(str, "THREADING ERROR : object of type %s is simultaneously used in thread %ld and thread %ld", type, objectsInUse[object], tid);') |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1239 | header_txt.append(' layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, 0, 0, THREADING_CHECKER_MULTIPLE_THREADS, "THREADING", str);') |
Mike Stroyan | 354ed67 | 2015-05-15 08:50:57 -0600 | [diff] [blame] | 1240 | header_txt.append(' // Wait for thread-safe access to object') |
| 1241 | header_txt.append(' while (objectsInUse.find(object) != objectsInUse.end()) {') |
| 1242 | header_txt.append(' loader_platform_thread_cond_wait(&threadingCond, &threadingLock);') |
| 1243 | header_txt.append(' }') |
| 1244 | header_txt.append(' objectsInUse[object] = tid;') |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1245 | header_txt.append(' } else {') |
| 1246 | header_txt.append(' char str[1024];') |
| 1247 | header_txt.append(' sprintf(str, "THREADING ERROR : object of type %s is recursively used in thread %ld", type, tid);') |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1248 | header_txt.append(' layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, 0, 0, THREADING_CHECKER_SINGLE_THREAD_REUSE, "THREADING", str);') |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1249 | header_txt.append(' }') |
| 1250 | header_txt.append(' }') |
| 1251 | header_txt.append(' loader_platform_thread_unlock_mutex(&threadingLock);') |
| 1252 | header_txt.append('}') |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1253 | header_txt.append('%s' % self.lineinfo.get()) |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1254 | header_txt.append('static void finishUsingObject(VkObject object)') |
| 1255 | header_txt.append('{') |
| 1256 | header_txt.append(' // Object is no longer in use') |
| 1257 | header_txt.append(' loader_platform_thread_lock_mutex(&threadingLock);') |
| 1258 | header_txt.append(' objectsInUse.erase(object);') |
Mike Stroyan | 354ed67 | 2015-05-15 08:50:57 -0600 | [diff] [blame] | 1259 | header_txt.append(' loader_platform_thread_cond_broadcast(&threadingCond);') |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1260 | header_txt.append(' loader_platform_thread_unlock_mutex(&threadingLock);') |
| 1261 | header_txt.append('}') |
| 1262 | return "\n".join(header_txt) |
| 1263 | |
| 1264 | def generate_intercept(self, proto, qual): |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1265 | if proto.name in [ 'DbgCreateMsgCallback' ]: |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1266 | # use default version |
| 1267 | return None |
| 1268 | decl = proto.c_func(prefix="vk", attr="VKAPI") |
Mike Stroyan | ae0eafd | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1269 | thread_check_objects = [ |
| 1270 | "VkQueue", |
| 1271 | "VkDeviceMemory", |
| 1272 | "VkObject", |
| 1273 | "VkBuffer", |
| 1274 | "VkImage", |
| 1275 | "VkDescriptorSet", |
| 1276 | "VkDescriptorPool", |
| 1277 | "VkCmdBuffer", |
| 1278 | "VkSemaphore" |
| 1279 | ] |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1280 | ret_val = '' |
| 1281 | stmt = '' |
| 1282 | funcs = [] |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1283 | table = 'device' |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1284 | if proto.ret != "void": |
Jon Ashburn | 53c1677 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 1285 | ret_val = "%s result = " % proto.ret |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1286 | stmt = " return result;\n" |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 1287 | if proto_is_global(proto): |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1288 | table = 'instance' |
Jon Ashburn | 52c1d73 | 2015-05-12 17:23:55 -0600 | [diff] [blame] | 1289 | |
Mike Stroyan | ae0eafd | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1290 | # Memory range calls are special in needed thread checking within structs |
| 1291 | if proto.name in ["FlushMappedMemoryRanges","InvalidateMappedMemoryRanges"]: |
| 1292 | funcs.append('%s%s\n' |
| 1293 | '{\n' |
| 1294 | ' for (int i=0; i<memRangeCount; i++) {\n' |
| 1295 | ' useObject((VkObject) pMemRanges[i].mem, "VkDeviceMemory");\n' |
| 1296 | ' }\n' |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1297 | ' %s%s_dispatch_table(%s)->%s;\n' |
Mike Stroyan | ae0eafd | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1298 | ' for (int i=0; i<memRangeCount; i++) {\n' |
| 1299 | ' finishUsingObject((VkObject) pMemRanges[i].mem);\n' |
| 1300 | ' }\n' |
| 1301 | '%s' |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1302 | '}' % (qual, decl, ret_val, table, proto.params[0].name, proto.c_call(), stmt)) |
Mike Stroyan | ae0eafd | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1303 | return "\n".join(funcs) |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1304 | # All functions that do a Get are thread safe |
Mike Stroyan | ae0eafd | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1305 | if 'Get' in proto.name: |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1306 | return None |
Mike Stroyan | ae0eafd | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1307 | # All WSI functions are thread safe |
| 1308 | if 'WSI' in proto.name: |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1309 | return None |
Mike Stroyan | ae0eafd | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1310 | # Initialize in early calls |
| 1311 | if proto.params[0].ty == "VkPhysicalDevice": |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1312 | funcs.append('%s' % self.lineinfo.get()) |
Mike Stroyan | ae0eafd | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1313 | funcs.append('%s%s\n' |
| 1314 | '{\n' |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1315 | ' %s%s_dispatch_table(%s)->%s;\n' |
Mike Stroyan | ae0eafd | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1316 | '%s' |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1317 | '}' % (qual, decl, ret_val, table, proto.params[0].name, proto.c_call(), stmt)) |
Mike Stroyan | ae0eafd | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1318 | return "\n".join(funcs) |
| 1319 | # Functions changing command buffers need thread safe use of first parameter |
| 1320 | if proto.params[0].ty == "VkCmdBuffer": |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1321 | funcs.append('%s' % self.lineinfo.get()) |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1322 | funcs.append('%s%s\n' |
| 1323 | '{\n' |
| 1324 | ' useObject((VkObject) %s, "%s");\n' |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1325 | ' %s%s_dispatch_table(%s)->%s;\n' |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1326 | ' finishUsingObject((VkObject) %s);\n' |
| 1327 | '%s' |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1328 | '}' % (qual, decl, proto.params[0].name, proto.params[0].ty, ret_val, table, proto.params[0].name, proto.c_call(), proto.params[0].name, stmt)) |
Mike Stroyan | ae0eafd | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1329 | return "\n".join(funcs) |
| 1330 | # Non-Cmd functions that do a Wait are thread safe |
| 1331 | if 'Wait' in proto.name: |
| 1332 | return None |
| 1333 | # Watch use of certain types of objects passed as any parameter |
| 1334 | checked_params = [] |
| 1335 | for param in proto.params: |
| 1336 | if param.ty in thread_check_objects: |
| 1337 | checked_params.append(param) |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1338 | if proto.name == "DestroyDevice": |
| 1339 | funcs.append('%s%s\n' |
| 1340 | '{\n' |
Courtney Goeltzenleuchter | 9f17194 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 1341 | ' dispatch_key key = get_dispatch_key(device);\n' |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1342 | ' %s%s_dispatch_table(%s)->%s;\n' |
Courtney Goeltzenleuchter | 9f17194 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 1343 | ' destroy_device_dispatch_table(key);\n' |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1344 | ' return result;\n' |
| 1345 | '}\n' % (qual, decl, ret_val, table, proto.params[0].name, proto.c_call())) |
| 1346 | return "\n".join(funcs); |
| 1347 | elif proto.name == "DestroyInstance": |
| 1348 | funcs.append('%s%s\n' |
| 1349 | '{\n' |
Courtney Goeltzenleuchter | 9f17194 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 1350 | ' dispatch_key key = get_dispatch_key(instance);\n' |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1351 | ' %s%s_dispatch_table(%s)->%s;\n' |
Courtney Goeltzenleuchter | 9f17194 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 1352 | ' destroy_instance_dispatch_table(key);\n' |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1353 | ' return result;\n' |
| 1354 | '}\n' % (qual, decl, ret_val, table, proto.params[0].name, proto.c_call())) |
| 1355 | return "\n".join(funcs); |
Courtney Goeltzenleuchter | f4a2eba | 2015-06-08 14:58:39 -0600 | [diff] [blame] | 1356 | elif proto.name == "CreateInstance": |
| 1357 | funcs.append('%s%s\n' |
| 1358 | '{\n' |
| 1359 | ' loader_platform_thread_once(&initOnce, initThreading);\n' |
| 1360 | '\n' |
| 1361 | ' %s %s_dispatch_table(*pInstance)->CreateInstance(pCreateInfo, pInstance);\n' |
| 1362 | '\n' |
| 1363 | ' if (result == VK_SUCCESS) {\n' |
| 1364 | ' enable_debug_report(pCreateInfo->extensionCount, pCreateInfo->pEnabledExtensions);\n' |
| 1365 | ' VkLayerInstanceDispatchTable *pTable = instance_dispatch_table(*pInstance);\n' |
| 1366 | ' debug_report_init_instance_extension_dispatch_table(\n' |
| 1367 | ' pTable,\n' |
| 1368 | ' pTable->GetInstanceProcAddr,\n' |
| 1369 | ' *pInstance);\n' |
| 1370 | ' }\n' |
| 1371 | ' return result;\n' |
| 1372 | '}\n' % (qual, decl, ret_val, table)) |
| 1373 | return "\n".join(funcs); |
Mike Stroyan | ae0eafd | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1374 | if len(checked_params) == 0: |
| 1375 | return None |
| 1376 | # Surround call with useObject and finishUsingObject for each checked_param |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1377 | funcs.append('%s' % self.lineinfo.get()) |
Mike Stroyan | ae0eafd | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1378 | funcs.append('%s%s' % (qual, decl)) |
| 1379 | funcs.append('{') |
| 1380 | for param in checked_params: |
| 1381 | funcs.append(' useObject((VkObject) %s, "%s");' % (param.name, param.ty)) |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1382 | funcs.append(' %s%s_dispatch_table(%s)->%s;' % (ret_val, table, proto.params[0].name, proto.c_call())) |
Mike Stroyan | ae0eafd | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1383 | for param in checked_params: |
| 1384 | funcs.append(' finishUsingObject((VkObject) %s);' % param.name) |
| 1385 | funcs.append('%s' |
| 1386 | '}' % stmt) |
| 1387 | return "\n".join(funcs) |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1388 | |
| 1389 | def generate_body(self): |
| 1390 | self.layer_name = "Threading" |
Mike Stroyan | 354ed67 | 2015-05-15 08:50:57 -0600 | [diff] [blame] | 1391 | body = [self._generate_layer_initialization(True, lockname='threading', condname='threading'), |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1392 | self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"), |
Courtney Goeltzenleuchter | ce445ad | 2015-06-01 14:52:57 -0600 | [diff] [blame] | 1393 | self._generate_layer_gpa_function(extensions=[], |
| 1394 | instance_extensions=['msg_callback_get_proc_addr']), |
| 1395 | self._gen_create_msg_callback(), |
| 1396 | self._gen_destroy_msg_callback()] |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1397 | return "\n\n".join(body) |
| 1398 | |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1399 | def main(): |
| 1400 | subcommands = { |
| 1401 | "layer-funcs" : LayerFuncsSubcommand, |
| 1402 | "layer-dispatch" : LayerDispatchSubcommand, |
Tobin Ehlis | 907a052 | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 1403 | "Generic" : GenericLayerSubcommand, |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 1404 | "APIDump" : APIDumpSubcommand, |
Tobin Ehlis | 907a052 | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 1405 | "ObjectTracker" : ObjectTrackerSubcommand, |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1406 | "Threading" : ThreadingSubcommand, |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1407 | } |
| 1408 | |
Tobin Ehlis | 6cd0637 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1409 | if len(sys.argv) < 3 or sys.argv[1] not in subcommands or not os.path.exists(sys.argv[2]): |
| 1410 | print("Usage: %s <subcommand> <input_header> [options]" % sys.argv[0]) |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1411 | print |
Tobin Ehlis | 2f3726c | 2015-01-15 17:51:52 -0700 | [diff] [blame] | 1412 | print("Available subcommands are: %s" % " ".join(subcommands)) |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1413 | exit(1) |
| 1414 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1415 | hfp = vk_helper.HeaderFileParser(sys.argv[2]) |
Tobin Ehlis | 6cd0637 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1416 | hfp.parse() |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1417 | vk_helper.enum_val_dict = hfp.get_enum_val_dict() |
| 1418 | vk_helper.enum_type_dict = hfp.get_enum_type_dict() |
| 1419 | vk_helper.struct_dict = hfp.get_struct_dict() |
| 1420 | vk_helper.typedef_fwd_dict = hfp.get_typedef_fwd_dict() |
| 1421 | vk_helper.typedef_rev_dict = hfp.get_typedef_rev_dict() |
| 1422 | vk_helper.types_dict = hfp.get_types_dict() |
Tobin Ehlis | 6cd0637 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1423 | |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1424 | subcmd = subcommands[sys.argv[1]](sys.argv[2:]) |
| 1425 | subcmd.run() |
| 1426 | |
| 1427 | if __name__ == "__main__": |
| 1428 | main() |