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