Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Vulkan |
| 3 | * |
| 4 | * Copyright (C) 2014 LunarG, Inc. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included |
| 14 | * in all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 | * DEALINGS IN THE SOFTWARE. |
| 23 | */ |
| 24 | |
| 25 | #include <stdio.h> |
| 26 | #include <stdlib.h> |
| 27 | #include <string.h> |
| 28 | |
| 29 | #include <iostream> |
| 30 | #include <string> |
| 31 | #include <sstream> |
| 32 | #include <unordered_map> |
Tobin Ehlis | ad8c446 | 2015-09-21 15:20:28 -0600 | [diff] [blame] | 33 | #include <memory> |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 34 | |
Tobin Ehlis | ad8c446 | 2015-09-21 15:20:28 -0600 | [diff] [blame] | 35 | #include "image.h" |
Tobin Ehlis | b835d1b | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 36 | #include "vk_loader_platform.h" |
Tobin Ehlis | 0c6f9ee | 2015-07-03 09:42:57 -0600 | [diff] [blame] | 37 | #include "vk_layer.h" |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 38 | #include "vk_enum_validate_helper.h" |
| 39 | #include "vk_struct_validate_helper.h" |
| 40 | //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] | 41 | #include "vk_loader_platform.h" |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 42 | |
Tobin Ehlis | a0cb02e | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 43 | #include "vk_layer_table.h" |
| 44 | #include "vk_layer_data.h" |
Courtney Goeltzenleuchter | 426e187 | 2015-07-07 11:18:30 -0600 | [diff] [blame] | 45 | #include "vk_layer_extension_utils.h" |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 46 | |
Tobin Ehlis | ad8c446 | 2015-09-21 15:20:28 -0600 | [diff] [blame] | 47 | using namespace std; |
| 48 | |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 49 | typedef struct _layer_data { |
| 50 | debug_report_data *report_data; |
| 51 | VkDbgMsgCallback logging_callback; |
Chris Forbes | bc0bb77 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 52 | VkPhysicalDevice physicalDevice; |
Tobin Ehlis | ad8c446 | 2015-09-21 15:20:28 -0600 | [diff] [blame] | 53 | unordered_map<uint64_t, unique_ptr<VkImageCreateInfo>> imageMap; |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 54 | } layer_data; |
| 55 | |
Tobin Ehlis | ad8c446 | 2015-09-21 15:20:28 -0600 | [diff] [blame] | 56 | static unordered_map<void*, layer_data*> layer_data_map; |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 57 | static device_table_map image_device_table_map; |
| 58 | static instance_table_map image_instance_table_map; |
| 59 | |
| 60 | // "my device data" |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 61 | debug_report_data *mdd(const void* object) |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 62 | { |
| 63 | dispatch_key key = get_dispatch_key(object); |
| 64 | layer_data *data = get_my_data_ptr(key, layer_data_map); |
| 65 | #if DISPATCH_MAP_DEBUG |
| 66 | fprintf(stderr, "MDD: map: %p, object: %p, key: %p, data: %p\n", &layer_data_map, object, key, data); |
| 67 | #endif |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 68 | return data->report_data; |
| 69 | } |
| 70 | |
| 71 | // "my instance data" |
| 72 | debug_report_data *mid(VkInstance object) |
| 73 | { |
| 74 | dispatch_key key = get_dispatch_key(object); |
Courtney Goeltzenleuchter | a8fd5a5 | 2015-06-22 16:19:14 -0600 | [diff] [blame] | 75 | layer_data *data = get_my_data_ptr(key, layer_data_map); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 76 | #if DISPATCH_MAP_DEBUG |
| 77 | fprintf(stderr, "MID: map: %p, object: %p, key: %p, data: %p\n", &layer_data_map, object, key, data); |
| 78 | #endif |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 79 | return data->report_data; |
| 80 | } |
| 81 | |
| 82 | static void InitImage(layer_data *data) |
| 83 | { |
| 84 | uint32_t report_flags = getLayerOptionFlags("ImageReportFlags", 0); |
| 85 | |
| 86 | uint32_t debug_action = 0; |
| 87 | getLayerOptionEnum("ImageDebugAction", (uint32_t *) &debug_action); |
| 88 | if(debug_action & VK_DBG_LAYER_ACTION_LOG_MSG) |
| 89 | { |
| 90 | FILE *log_output = NULL; |
| 91 | const char* option_str = getLayerOption("ImageLogFilename"); |
Tobin Ehlis | b1df55e | 2015-09-15 09:55:54 -0600 | [diff] [blame] | 92 | log_output = getLayerLogOutput(option_str, "Image"); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 93 | layer_create_msg_callback(data->report_data, report_flags, log_callback, (void*)log_output, &data->logging_callback); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback( |
| 98 | VkInstance instance, |
| 99 | VkFlags msgFlags, |
| 100 | const PFN_vkDbgMsgCallback pfnMsgCallback, |
| 101 | void* pUserData, |
| 102 | VkDbgMsgCallback* pMsgCallback) |
| 103 | { |
| 104 | VkLayerInstanceDispatchTable *pTable = get_dispatch_table(image_instance_table_map, instance); |
| 105 | VkResult res = pTable->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback); |
| 106 | if (res == VK_SUCCESS) { |
| 107 | layer_data *data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
| 108 | |
| 109 | res = layer_create_msg_callback(data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback); |
| 110 | } |
| 111 | return res; |
| 112 | } |
| 113 | |
| 114 | VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback( |
| 115 | VkInstance instance, |
| 116 | VkDbgMsgCallback msgCallback) |
| 117 | { |
| 118 | VkLayerInstanceDispatchTable *pTable = get_dispatch_table(image_instance_table_map, instance); |
| 119 | VkResult res = pTable->DbgDestroyMsgCallback(instance, msgCallback); |
| 120 | |
| 121 | layer_data *data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
| 122 | layer_destroy_msg_callback(data->report_data, msgCallback); |
| 123 | |
| 124 | return res; |
| 125 | } |
| 126 | |
| 127 | VK_LAYER_EXPORT VkResult VKAPI vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, VkInstance* pInstance) |
| 128 | { |
| 129 | VkLayerInstanceDispatchTable *pTable = get_dispatch_table(image_instance_table_map, *pInstance); |
| 130 | VkResult result = pTable->CreateInstance(pCreateInfo, pInstance); |
| 131 | |
| 132 | if (result == VK_SUCCESS) { |
| 133 | layer_data *data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map); |
| 134 | data->report_data = debug_report_create_instance(pTable, *pInstance, pCreateInfo->extensionCount, |
Courtney Goeltzenleuchter | 426e187 | 2015-07-07 11:18:30 -0600 | [diff] [blame] | 135 | pCreateInfo->ppEnabledExtensionNames); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 136 | |
| 137 | InitImage(data); |
| 138 | } |
| 139 | |
| 140 | return result; |
| 141 | } |
| 142 | |
Mark Lobodzinski | 2141f65 | 2015-09-07 13:59:43 -0600 | [diff] [blame] | 143 | VK_LAYER_EXPORT void VKAPI vkDestroyInstance(VkInstance instance) |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 144 | { |
| 145 | // Grab the key before the instance is destroyed. |
| 146 | dispatch_key key = get_dispatch_key(instance); |
| 147 | VkLayerInstanceDispatchTable *pTable = get_dispatch_table(image_instance_table_map, instance); |
Mark Lobodzinski | 2141f65 | 2015-09-07 13:59:43 -0600 | [diff] [blame] | 148 | pTable->DestroyInstance(instance); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 149 | |
| 150 | // Clean up logging callback, if any |
| 151 | layer_data *data = get_my_data_ptr(key, layer_data_map); |
| 152 | if(data->logging_callback) |
| 153 | { |
| 154 | layer_destroy_msg_callback(data->report_data, data->logging_callback); |
| 155 | } |
| 156 | |
| 157 | layer_debug_report_destroy_instance(mid(instance)); |
| 158 | layer_data_map.erase(pTable); |
| 159 | |
| 160 | image_instance_table_map.erase(key); |
| 161 | assert(image_instance_table_map.size() == 0 && "Should not have any instance mappings hanging around"); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice) |
| 165 | { |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 166 | VkLayerDispatchTable *pTable = get_dispatch_table(image_device_table_map, *pDevice); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 167 | VkResult result = pTable->CreateDevice(physicalDevice, pCreateInfo, pDevice); |
| 168 | if(result == VK_SUCCESS) |
| 169 | { |
| 170 | layer_data *instance_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
| 171 | layer_data *device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map); |
| 172 | device_data->report_data = layer_debug_report_create_device(instance_data->report_data, *pDevice); |
Chris Forbes | bc0bb77 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 173 | device_data->physicalDevice = physicalDevice; |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | return result; |
| 177 | } |
| 178 | |
Mark Lobodzinski | 2141f65 | 2015-09-07 13:59:43 -0600 | [diff] [blame] | 179 | VK_LAYER_EXPORT void VKAPI vkDestroyDevice(VkDevice device) |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 180 | { |
| 181 | layer_debug_report_destroy_device(device); |
| 182 | |
| 183 | dispatch_key key = get_dispatch_key(device); |
| 184 | #if DISPATCH_MAP_DEBUG |
| 185 | fprintf(stderr, "Device: %p, key: %p\n", device, key); |
| 186 | #endif |
| 187 | |
Mark Lobodzinski | 2141f65 | 2015-09-07 13:59:43 -0600 | [diff] [blame] | 188 | get_dispatch_table(image_device_table_map, device)->DestroyDevice(device); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 189 | image_device_table_map.erase(key); |
| 190 | assert(image_device_table_map.size() == 0 && "Should not have any instance mappings hanging around"); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 191 | } |
| 192 | |
Courtney Goeltzenleuchter | 426e187 | 2015-07-07 11:18:30 -0600 | [diff] [blame] | 193 | static const VkLayerProperties pc_global_layers[] = { |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 194 | { |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 195 | "Image", |
Courtney Goeltzenleuchter | 426e187 | 2015-07-07 11:18:30 -0600 | [diff] [blame] | 196 | VK_API_VERSION, |
| 197 | VK_MAKE_VERSION(0, 1, 0), |
| 198 | "Validation layer: Image ParamChecker", |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 199 | } |
| 200 | }; |
| 201 | |
Courtney Goeltzenleuchter | 35985f6 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 202 | VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceExtensionProperties( |
Courtney Goeltzenleuchter | 426e187 | 2015-07-07 11:18:30 -0600 | [diff] [blame] | 203 | const char *pLayerName, |
| 204 | uint32_t *pCount, |
| 205 | VkExtensionProperties* pProperties) |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 206 | { |
Courtney Goeltzenleuchter | 426e187 | 2015-07-07 11:18:30 -0600 | [diff] [blame] | 207 | /* ParamChecker does not have any global extensions */ |
| 208 | return util_GetExtensionProperties(0, NULL, pCount, pProperties); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 209 | } |
| 210 | |
Courtney Goeltzenleuchter | 35985f6 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 211 | VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceLayerProperties( |
Courtney Goeltzenleuchter | 426e187 | 2015-07-07 11:18:30 -0600 | [diff] [blame] | 212 | uint32_t *pCount, |
| 213 | VkLayerProperties* pProperties) |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 214 | { |
Courtney Goeltzenleuchter | 426e187 | 2015-07-07 11:18:30 -0600 | [diff] [blame] | 215 | return util_GetLayerProperties(ARRAY_SIZE(pc_global_layers), |
| 216 | pc_global_layers, |
| 217 | pCount, pProperties); |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 218 | } |
| 219 | |
Courtney Goeltzenleuchter | 35985f6 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 220 | VK_LAYER_EXPORT VkResult VKAPI vkEnumerateDeviceExtensionProperties( |
Courtney Goeltzenleuchter | 426e187 | 2015-07-07 11:18:30 -0600 | [diff] [blame] | 221 | VkPhysicalDevice physicalDevice, |
| 222 | const char* pLayerName, |
| 223 | uint32_t* pCount, |
| 224 | VkExtensionProperties* pProperties) |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 225 | { |
Courtney Goeltzenleuchter | 426e187 | 2015-07-07 11:18:30 -0600 | [diff] [blame] | 226 | /* ParamChecker does not have any physical device extensions */ |
| 227 | return util_GetExtensionProperties(0, NULL, pCount, pProperties); |
| 228 | } |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 229 | |
Courtney Goeltzenleuchter | 35985f6 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 230 | VK_LAYER_EXPORT VkResult VKAPI vkEnumerateDeviceLayerProperties( |
Courtney Goeltzenleuchter | 426e187 | 2015-07-07 11:18:30 -0600 | [diff] [blame] | 231 | VkPhysicalDevice physicalDevice, |
| 232 | uint32_t* pCount, |
| 233 | VkLayerProperties* pProperties) |
| 234 | { |
| 235 | /* ParamChecker's physical device layers are the same as global */ |
| 236 | return util_GetLayerProperties(ARRAY_SIZE(pc_global_layers), pc_global_layers, |
| 237 | pCount, pProperties); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 238 | } |
| 239 | |
Mark Lobodzinski | 2fd634c | 2015-07-29 09:21:22 -0600 | [diff] [blame] | 240 | // Start of the Image layer proper |
| 241 | |
| 242 | // Returns TRUE if a format is a depth-compatible format |
| 243 | bool is_depth_format(VkFormat format) |
| 244 | { |
| 245 | bool result = VK_FALSE; |
| 246 | switch (format) { |
| 247 | case VK_FORMAT_D16_UNORM: |
Courtney Goeltzenleuchter | 286fb5f | 2015-09-10 17:17:43 -0600 | [diff] [blame] | 248 | case VK_FORMAT_D24_UNORM_X8: |
Mark Lobodzinski | 2fd634c | 2015-07-29 09:21:22 -0600 | [diff] [blame] | 249 | case VK_FORMAT_D32_SFLOAT: |
| 250 | case VK_FORMAT_S8_UINT: |
| 251 | case VK_FORMAT_D16_UNORM_S8_UINT: |
| 252 | case VK_FORMAT_D24_UNORM_S8_UINT: |
| 253 | case VK_FORMAT_D32_SFLOAT_S8_UINT: |
| 254 | result = VK_TRUE; |
| 255 | break; |
| 256 | default: |
| 257 | break; |
| 258 | } |
| 259 | return result; |
| 260 | } |
| 261 | |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 262 | VK_LAYER_EXPORT VkResult VKAPI vkCreateImage(VkDevice device, const VkImageCreateInfo* pCreateInfo, VkImage* pImage) |
| 263 | { |
Tobin Ehlis | dea0095 | 2015-09-22 08:40:52 -0600 | [diff] [blame^] | 264 | VkBool32 skipCall = VK_FALSE; |
Tobin Ehlis | ad8c446 | 2015-09-21 15:20:28 -0600 | [diff] [blame] | 265 | layer_data *device_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 266 | if(pCreateInfo->format != VK_FORMAT_UNDEFINED) |
| 267 | { |
| 268 | VkFormatProperties properties; |
Courtney Goeltzenleuchter | c729b3a | 2015-07-12 12:40:29 -0600 | [diff] [blame] | 269 | VkResult result = get_dispatch_table(image_instance_table_map, device_data->physicalDevice)->GetPhysicalDeviceFormatProperties( |
Chris Forbes | bc0bb77 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 270 | device_data->physicalDevice, pCreateInfo->format, &properties); |
Tobin Ehlis | ad8c446 | 2015-09-21 15:20:28 -0600 | [diff] [blame] | 271 | if(result != VK_SUCCESS) { |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 272 | char const str[] = "vkCreateImage parameter, VkFormat pCreateInfo->format, cannot be validated"; |
Tobin Ehlis | dea0095 | 2015-09-22 08:40:52 -0600 | [diff] [blame^] | 273 | skipCall |= log_msg(device_data->report_data, VK_DBG_REPORT_WARN_BIT, (VkDbgObjectType)0, 0, 0, IMAGE_FORMAT_UNSUPPORTED, "IMAGE", str); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | if((properties.linearTilingFeatures) == 0 && (properties.optimalTilingFeatures == 0)) |
| 277 | { |
| 278 | char const str[] = "vkCreateImage parameter, VkFormat pCreateInfo->format, contains unsupported format"; |
Tobin Ehlis | dea0095 | 2015-09-22 08:40:52 -0600 | [diff] [blame^] | 279 | skipCall |= log_msg(device_data->report_data, VK_DBG_REPORT_WARN_BIT, (VkDbgObjectType)0, 0, 0, IMAGE_FORMAT_UNSUPPORTED, "IMAGE", str); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 280 | } |
| 281 | } |
Tobin Ehlis | dea0095 | 2015-09-22 08:40:52 -0600 | [diff] [blame^] | 282 | if (skipCall) |
| 283 | return VK_ERROR_VALIDATION_FAILED; |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 284 | |
| 285 | VkResult result = get_dispatch_table(image_device_table_map, device)->CreateImage(device, pCreateInfo, pImage); |
| 286 | |
Tobin Ehlis | ad8c446 | 2015-09-21 15:20:28 -0600 | [diff] [blame] | 287 | if(result == VK_SUCCESS) { |
| 288 | device_data->imageMap[pImage->handle] = unique_ptr<VkImageCreateInfo>(new VkImageCreateInfo(*pCreateInfo)); |
| 289 | } |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 290 | return result; |
| 291 | } |
| 292 | |
Tobin Ehlis | ad8c446 | 2015-09-21 15:20:28 -0600 | [diff] [blame] | 293 | VK_LAYER_EXPORT void VKAPI vkDestroyImage(VkDevice device, VkImage image) |
| 294 | { |
| 295 | layer_data *device_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
| 296 | device_data->imageMap.erase(image.handle); |
| 297 | get_dispatch_table(image_device_table_map, device)->DestroyImage(device, image); |
| 298 | } |
| 299 | |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 300 | VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, VkRenderPass* pRenderPass) |
| 301 | { |
Tobin Ehlis | dea0095 | 2015-09-22 08:40:52 -0600 | [diff] [blame^] | 302 | VkBool32 skipCall = VK_FALSE; |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 303 | for(uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 304 | { |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 305 | if(pCreateInfo->pAttachments[i].format != VK_FORMAT_UNDEFINED) |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 306 | { |
Courtney Goeltzenleuchter | a8fd5a5 | 2015-06-22 16:19:14 -0600 | [diff] [blame] | 307 | layer_data *device_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 308 | VkFormatProperties properties; |
Courtney Goeltzenleuchter | c729b3a | 2015-07-12 12:40:29 -0600 | [diff] [blame] | 309 | VkResult result = get_dispatch_table(image_instance_table_map, device_data->physicalDevice)->GetPhysicalDeviceFormatProperties( |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 310 | device_data->physicalDevice, pCreateInfo->pAttachments[i].format, &properties); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 311 | if(result != VK_SUCCESS) |
| 312 | { |
| 313 | std::stringstream ss; |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 314 | ss << "vkCreateRenderPass parameter, VkFormat in pCreateInfo->pAttachments[" << i << "], cannot be validated"; |
Tobin Ehlis | dea0095 | 2015-09-22 08:40:52 -0600 | [diff] [blame^] | 315 | skipCall |= log_msg(mdd(device), VK_DBG_REPORT_WARN_BIT, (VkDbgObjectType)0, 0, 0, IMAGE_FORMAT_UNSUPPORTED, "IMAGE", ss.str().c_str()); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 316 | continue; |
| 317 | } |
| 318 | |
| 319 | if((properties.linearTilingFeatures) == 0 && (properties.optimalTilingFeatures == 0)) |
| 320 | { |
| 321 | std::stringstream ss; |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 322 | ss << "vkCreateRenderPass parameter, VkFormat in pCreateInfo->pAttachments[" << i << "], contains unsupported format"; |
Tobin Ehlis | dea0095 | 2015-09-22 08:40:52 -0600 | [diff] [blame^] | 323 | skipCall |= log_msg(mdd(device), VK_DBG_REPORT_WARN_BIT, (VkDbgObjectType)0, 0, 0, IMAGE_FORMAT_UNSUPPORTED, "IMAGE", ss.str().c_str()); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 324 | } |
| 325 | } |
| 326 | } |
| 327 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 328 | for(uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 329 | { |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 330 | if(!validate_VkImageLayout(pCreateInfo->pAttachments[i].initialLayout) || |
| 331 | !validate_VkImageLayout(pCreateInfo->pAttachments[i].finalLayout)) |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 332 | { |
| 333 | std::stringstream ss; |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 334 | ss << "vkCreateRenderPass parameter, VkImageLayout in pCreateInfo->pAttachments[" << i << "], is unrecognized"; |
Tobin Ehlis | dea0095 | 2015-09-22 08:40:52 -0600 | [diff] [blame^] | 335 | skipCall |= log_msg(mdd(device), VK_DBG_REPORT_WARN_BIT, (VkDbgObjectType)0, 0, 0, IMAGE_RENDERPASS_INVALID_ATTACHMENT, "IMAGE", ss.str().c_str()); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 336 | } |
| 337 | } |
| 338 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 339 | for(uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 340 | { |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 341 | if(!validate_VkAttachmentLoadOp(pCreateInfo->pAttachments[i].loadOp)) |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 342 | { |
| 343 | std::stringstream ss; |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 344 | ss << "vkCreateRenderPass parameter, VkAttachmentLoadOp in pCreateInfo->pAttachments[" << i << "], is unrecognized"; |
Tobin Ehlis | dea0095 | 2015-09-22 08:40:52 -0600 | [diff] [blame^] | 345 | skipCall |= log_msg(mdd(device), VK_DBG_REPORT_WARN_BIT, (VkDbgObjectType)0, 0, 0, IMAGE_RENDERPASS_INVALID_ATTACHMENT, "IMAGE", ss.str().c_str()); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 346 | } |
| 347 | } |
| 348 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 349 | for(uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 350 | { |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 351 | if(!validate_VkAttachmentStoreOp(pCreateInfo->pAttachments[i].storeOp)) |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 352 | { |
| 353 | std::stringstream ss; |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 354 | ss << "vkCreateRenderPass parameter, VkAttachmentStoreOp in pCreateInfo->pAttachments[" << i << "], is unrecognized"; |
Tobin Ehlis | dea0095 | 2015-09-22 08:40:52 -0600 | [diff] [blame^] | 355 | skipCall |= log_msg(mdd(device), VK_DBG_REPORT_WARN_BIT, (VkDbgObjectType)0, 0, 0, IMAGE_RENDERPASS_INVALID_ATTACHMENT, "IMAGE", ss.str().c_str()); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 356 | } |
| 357 | } |
| 358 | |
Mark Lobodzinski | 2fd634c | 2015-07-29 09:21:22 -0600 | [diff] [blame] | 359 | // Any depth buffers specified as attachments? |
| 360 | bool depthFormatPresent = VK_FALSE; |
| 361 | for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) |
| 362 | { |
| 363 | depthFormatPresent |= is_depth_format(pCreateInfo->pAttachments[i].format); |
| 364 | } |
| 365 | |
| 366 | if (depthFormatPresent == VK_FALSE) { |
| 367 | // No depth attachment is present, validate that subpasses set depthStencilAttachment to VK_ATTACHMENT_UNUSED; |
| 368 | for (uint32_t i = 0; i < pCreateInfo->subpassCount; i++) { |
| 369 | if (pCreateInfo->pSubpasses[i].depthStencilAttachment.attachment != VK_ATTACHMENT_UNUSED) { |
| 370 | std::stringstream ss; |
| 371 | ss << "vkCreateRenderPass has no depth/stencil attachment, yet subpass[" << i << "] has VkSubpassDescription::depthStencilAttachment value that is not VK_ATTACHMENT_UNUSED"; |
Tobin Ehlis | dea0095 | 2015-09-22 08:40:52 -0600 | [diff] [blame^] | 372 | skipCall |= log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, IMAGE_RENDERPASS_INVALID_DS_ATTACHMENT, "IMAGE", ss.str().c_str()); |
Mark Lobodzinski | 2fd634c | 2015-07-29 09:21:22 -0600 | [diff] [blame] | 373 | } |
| 374 | } |
| 375 | } |
Tobin Ehlis | dea0095 | 2015-09-22 08:40:52 -0600 | [diff] [blame^] | 376 | if (skipCall) |
| 377 | return VK_ERROR_VALIDATION_FAILED; |
Mark Lobodzinski | 2fd634c | 2015-07-29 09:21:22 -0600 | [diff] [blame] | 378 | |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 379 | VkResult result = get_dispatch_table(image_device_table_map, device)->CreateRenderPass(device, pCreateInfo, pRenderPass); |
| 380 | |
| 381 | return result; |
| 382 | } |
| 383 | |
Tobin Ehlis | ad8c446 | 2015-09-21 15:20:28 -0600 | [diff] [blame] | 384 | VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView) |
| 385 | { |
| 386 | VkBool32 skipCall = VK_FALSE; |
| 387 | layer_data *device_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
| 388 | auto imageEntry = device_data->imageMap.find(pCreateInfo->image.handle); |
| 389 | if (imageEntry != device_data->imageMap.end()) { |
| 390 | if (pCreateInfo->subresourceRange.baseMipLevel >= imageEntry->second->mipLevels) { |
| 391 | std::stringstream ss; |
| 392 | ss << "vkCreateImageView called with baseMipLevel " << pCreateInfo->subresourceRange.baseMipLevel << " for image " << pCreateInfo->image.handle << " that only has " << imageEntry->second->mipLevels << " mip levels."; |
| 393 | skipCall |= log_msg(device_data->report_data, VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, IMAGE_VIEW_CREATE_ERROR, "IMAGE", ss.str().c_str()); |
| 394 | } |
| 395 | if (pCreateInfo->subresourceRange.baseArrayLayer >= imageEntry->second->arraySize) { |
| 396 | std::stringstream ss; |
| 397 | ss << "vkCreateImageView called with baseArrayLayer " << pCreateInfo->subresourceRange.baseArrayLayer << " for image " << pCreateInfo->image.handle << " that only has " << imageEntry->second->arraySize << " mip levels."; |
| 398 | skipCall |= log_msg(device_data->report_data, VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, IMAGE_VIEW_CREATE_ERROR, "IMAGE", ss.str().c_str()); |
| 399 | } |
| 400 | if (!pCreateInfo->subresourceRange.mipLevels) { |
| 401 | std::stringstream ss; |
| 402 | ss << "vkCreateImageView called with 0 in pCreateInfo->subresourceRange.mipLevels."; |
| 403 | skipCall |= log_msg(device_data->report_data, VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, IMAGE_VIEW_CREATE_ERROR, "IMAGE", ss.str().c_str()); |
| 404 | } |
| 405 | if (!pCreateInfo->subresourceRange.arraySize) { |
| 406 | std::stringstream ss; |
| 407 | ss << "vkCreateImageView called with 0 in pCreateInfo->subresourceRange.arraySize."; |
| 408 | skipCall |= log_msg(device_data->report_data, VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, IMAGE_VIEW_CREATE_ERROR, "IMAGE", ss.str().c_str()); |
| 409 | } |
| 410 | } |
| 411 | if (skipCall) |
| 412 | return VK_ERROR_VALIDATION_FAILED; |
Tobin Ehlis | dea0095 | 2015-09-22 08:40:52 -0600 | [diff] [blame^] | 413 | |
Tobin Ehlis | ad8c446 | 2015-09-21 15:20:28 -0600 | [diff] [blame] | 414 | VkResult result = get_dispatch_table(image_device_table_map, device)->CreateImageView(device, pCreateInfo, pView); |
| 415 | return result; |
| 416 | } |
| 417 | |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 418 | VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice device, const char* funcName) |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 419 | { |
| 420 | if (device == NULL) { |
| 421 | return NULL; |
| 422 | } |
| 423 | |
| 424 | /* loader uses this to force layer initialization; device object is wrapped */ |
| 425 | if (!strcmp(funcName, "vkGetDeviceProcAddr")) { |
| 426 | initDeviceTable(image_device_table_map, (const VkBaseLayerObject *) device); |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 427 | return (PFN_vkVoidFunction) vkGetDeviceProcAddr; |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 428 | } |
| 429 | |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 430 | if (!strcmp(funcName, "vkCreateDevice")) |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 431 | return (PFN_vkVoidFunction) vkCreateDevice; |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 432 | if (!strcmp(funcName, "vkDestroyDevice")) |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 433 | return (PFN_vkVoidFunction) vkDestroyDevice; |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 434 | if (!strcmp(funcName, "vkCreateImage")) |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 435 | return (PFN_vkVoidFunction) vkCreateImage; |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 436 | if (!strcmp(funcName, "vkCreateRenderPass")) |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 437 | return (PFN_vkVoidFunction) vkCreateRenderPass; |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 438 | |
| 439 | { |
| 440 | if (get_dispatch_table(image_device_table_map, device)->GetDeviceProcAddr == NULL) |
| 441 | return NULL; |
| 442 | return get_dispatch_table(image_device_table_map, device)->GetDeviceProcAddr(device, funcName); |
| 443 | } |
| 444 | } |
| 445 | |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 446 | VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName) |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 447 | { |
| 448 | if (instance == NULL) { |
| 449 | return NULL; |
| 450 | } |
| 451 | |
| 452 | /* loader uses this to force layer initialization; instance object is wrapped */ |
| 453 | if (!strcmp(funcName, "vkGetInstanceProcAddr")) { |
| 454 | initInstanceTable(image_instance_table_map, (const VkBaseLayerObject *) instance); |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 455 | return (PFN_vkVoidFunction) vkGetInstanceProcAddr; |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | if (!strcmp(funcName, "vkCreateInstance")) |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 459 | return (PFN_vkVoidFunction) vkCreateInstance; |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 460 | if (!strcmp(funcName, "vkDestroyInstance")) |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 461 | return (PFN_vkVoidFunction) vkDestroyInstance; |
Courtney Goeltzenleuchter | 35985f6 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 462 | if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties")) |
| 463 | return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties; |
| 464 | if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties")) |
| 465 | return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties; |
| 466 | if (!strcmp(funcName, "vkEnumerateDeviceLayerProperties")) |
| 467 | return (PFN_vkVoidFunction) vkEnumerateDeviceLayerProperties; |
| 468 | if (!strcmp(funcName, "vkEnumerateDeviceExtensionProperties")) |
| 469 | return (PFN_vkVoidFunction) vkEnumerateDeviceExtensionProperties; |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 470 | |
| 471 | layer_data *data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 472 | PFN_vkVoidFunction fptr = debug_report_get_instance_proc_addr(data->report_data, funcName); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 473 | if(fptr) |
| 474 | return fptr; |
| 475 | |
| 476 | { |
| 477 | if (get_dispatch_table(image_instance_table_map, instance)->GetInstanceProcAddr == NULL) |
| 478 | return NULL; |
| 479 | return get_dispatch_table(image_instance_table_map, instance)->GetInstanceProcAddr(instance, funcName); |
| 480 | } |
| 481 | } |