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