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> |
| 33 | |
Tobin Ehlis | b835d1b | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 34 | #include "vk_loader_platform.h" |
Tobin Ehlis | 0c6f9ee | 2015-07-03 09:42:57 -0600 | [diff] [blame] | 35 | #include "vk_layer.h" |
Tobin Ehlis | a0cb02e | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 36 | #include "vk_layer_config.h" |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 37 | #include "vk_enum_validate_helper.h" |
| 38 | #include "vk_struct_validate_helper.h" |
| 39 | //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] | 40 | #include "vk_loader_platform.h" |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 41 | |
Tobin Ehlis | a0cb02e | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 42 | #include "vk_layer_table.h" |
| 43 | #include "vk_layer_data.h" |
| 44 | #include "vk_layer_logging.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 | |
| 47 | typedef struct _layer_data { |
| 48 | debug_report_data *report_data; |
| 49 | VkDbgMsgCallback logging_callback; |
Chris Forbes | bc0bb77 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 50 | VkPhysicalDevice physicalDevice; |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 51 | } layer_data; |
| 52 | |
| 53 | static std::unordered_map<void*, layer_data*> layer_data_map; |
| 54 | static device_table_map image_device_table_map; |
| 55 | static instance_table_map image_instance_table_map; |
| 56 | |
| 57 | // "my device data" |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 58 | debug_report_data *mdd(const void* object) |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 59 | { |
| 60 | dispatch_key key = get_dispatch_key(object); |
| 61 | layer_data *data = get_my_data_ptr(key, layer_data_map); |
| 62 | #if DISPATCH_MAP_DEBUG |
| 63 | fprintf(stderr, "MDD: map: %p, object: %p, key: %p, data: %p\n", &layer_data_map, object, key, data); |
| 64 | #endif |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 65 | return data->report_data; |
| 66 | } |
| 67 | |
| 68 | // "my instance data" |
| 69 | debug_report_data *mid(VkInstance object) |
| 70 | { |
| 71 | dispatch_key key = get_dispatch_key(object); |
Courtney Goeltzenleuchter | a8fd5a5 | 2015-06-22 16:19:14 -0600 | [diff] [blame] | 72 | layer_data *data = get_my_data_ptr(key, layer_data_map); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 73 | #if DISPATCH_MAP_DEBUG |
| 74 | fprintf(stderr, "MID: map: %p, object: %p, key: %p, data: %p\n", &layer_data_map, object, key, data); |
| 75 | #endif |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 76 | return data->report_data; |
| 77 | } |
| 78 | |
| 79 | static void InitImage(layer_data *data) |
| 80 | { |
| 81 | uint32_t report_flags = getLayerOptionFlags("ImageReportFlags", 0); |
| 82 | |
| 83 | uint32_t debug_action = 0; |
| 84 | getLayerOptionEnum("ImageDebugAction", (uint32_t *) &debug_action); |
| 85 | if(debug_action & VK_DBG_LAYER_ACTION_LOG_MSG) |
| 86 | { |
| 87 | FILE *log_output = NULL; |
| 88 | const char* option_str = getLayerOption("ImageLogFilename"); |
| 89 | if(option_str) |
| 90 | { |
| 91 | log_output = fopen(option_str, "w"); |
| 92 | } |
| 93 | if(log_output == NULL) |
| 94 | { |
| 95 | log_output = stdout; |
| 96 | } |
| 97 | |
| 98 | layer_create_msg_callback(data->report_data, report_flags, log_callback, (void*)log_output, &data->logging_callback); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback( |
| 103 | VkInstance instance, |
| 104 | VkFlags msgFlags, |
| 105 | const PFN_vkDbgMsgCallback pfnMsgCallback, |
| 106 | void* pUserData, |
| 107 | VkDbgMsgCallback* pMsgCallback) |
| 108 | { |
| 109 | VkLayerInstanceDispatchTable *pTable = get_dispatch_table(image_instance_table_map, instance); |
| 110 | VkResult res = pTable->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback); |
| 111 | if (res == VK_SUCCESS) { |
| 112 | layer_data *data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
| 113 | |
| 114 | res = layer_create_msg_callback(data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback); |
| 115 | } |
| 116 | return res; |
| 117 | } |
| 118 | |
| 119 | VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback( |
| 120 | VkInstance instance, |
| 121 | VkDbgMsgCallback msgCallback) |
| 122 | { |
| 123 | VkLayerInstanceDispatchTable *pTable = get_dispatch_table(image_instance_table_map, instance); |
| 124 | VkResult res = pTable->DbgDestroyMsgCallback(instance, msgCallback); |
| 125 | |
| 126 | layer_data *data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
| 127 | layer_destroy_msg_callback(data->report_data, msgCallback); |
| 128 | |
| 129 | return res; |
| 130 | } |
| 131 | |
| 132 | VK_LAYER_EXPORT VkResult VKAPI vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, VkInstance* pInstance) |
| 133 | { |
| 134 | VkLayerInstanceDispatchTable *pTable = get_dispatch_table(image_instance_table_map, *pInstance); |
| 135 | VkResult result = pTable->CreateInstance(pCreateInfo, pInstance); |
| 136 | |
| 137 | if (result == VK_SUCCESS) { |
| 138 | layer_data *data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map); |
| 139 | data->report_data = debug_report_create_instance(pTable, *pInstance, pCreateInfo->extensionCount, |
Courtney Goeltzenleuchter | 426e187 | 2015-07-07 11:18:30 -0600 | [diff] [blame] | 140 | pCreateInfo->ppEnabledExtensionNames); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 141 | |
| 142 | InitImage(data); |
| 143 | } |
| 144 | |
| 145 | return result; |
| 146 | } |
| 147 | |
| 148 | VK_LAYER_EXPORT VkResult VKAPI vkDestroyInstance(VkInstance instance) |
| 149 | { |
| 150 | // Grab the key before the instance is destroyed. |
| 151 | dispatch_key key = get_dispatch_key(instance); |
| 152 | VkLayerInstanceDispatchTable *pTable = get_dispatch_table(image_instance_table_map, instance); |
| 153 | VkResult result = pTable->DestroyInstance(instance); |
| 154 | |
| 155 | // Clean up logging callback, if any |
| 156 | layer_data *data = get_my_data_ptr(key, layer_data_map); |
| 157 | if(data->logging_callback) |
| 158 | { |
| 159 | layer_destroy_msg_callback(data->report_data, data->logging_callback); |
| 160 | } |
| 161 | |
| 162 | layer_debug_report_destroy_instance(mid(instance)); |
| 163 | layer_data_map.erase(pTable); |
| 164 | |
| 165 | image_instance_table_map.erase(key); |
| 166 | assert(image_instance_table_map.size() == 0 && "Should not have any instance mappings hanging around"); |
| 167 | |
| 168 | return result; |
| 169 | } |
| 170 | |
| 171 | VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice) |
| 172 | { |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 173 | VkLayerDispatchTable *pTable = get_dispatch_table(image_device_table_map, *pDevice); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 174 | VkResult result = pTable->CreateDevice(physicalDevice, pCreateInfo, pDevice); |
| 175 | if(result == VK_SUCCESS) |
| 176 | { |
| 177 | layer_data *instance_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
| 178 | layer_data *device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map); |
| 179 | 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] | 180 | device_data->physicalDevice = physicalDevice; |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | return result; |
| 184 | } |
| 185 | |
| 186 | VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device) |
| 187 | { |
| 188 | layer_debug_report_destroy_device(device); |
| 189 | |
| 190 | dispatch_key key = get_dispatch_key(device); |
| 191 | #if DISPATCH_MAP_DEBUG |
| 192 | fprintf(stderr, "Device: %p, key: %p\n", device, key); |
| 193 | #endif |
| 194 | |
| 195 | VkResult result = get_dispatch_table(image_device_table_map, device)->DestroyDevice(device); |
| 196 | image_device_table_map.erase(key); |
| 197 | assert(image_device_table_map.size() == 0 && "Should not have any instance mappings hanging around"); |
| 198 | |
| 199 | return result; |
| 200 | } |
| 201 | |
Courtney Goeltzenleuchter | 426e187 | 2015-07-07 11:18:30 -0600 | [diff] [blame] | 202 | static const VkLayerProperties pc_global_layers[] = { |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 203 | { |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 204 | "Image", |
Courtney Goeltzenleuchter | 426e187 | 2015-07-07 11:18:30 -0600 | [diff] [blame] | 205 | VK_API_VERSION, |
| 206 | VK_MAKE_VERSION(0, 1, 0), |
| 207 | "Validation layer: Image ParamChecker", |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 208 | } |
| 209 | }; |
| 210 | |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 211 | VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionProperties( |
Courtney Goeltzenleuchter | 426e187 | 2015-07-07 11:18:30 -0600 | [diff] [blame] | 212 | const char *pLayerName, |
| 213 | uint32_t *pCount, |
| 214 | VkExtensionProperties* pProperties) |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 215 | { |
Courtney Goeltzenleuchter | 426e187 | 2015-07-07 11:18:30 -0600 | [diff] [blame] | 216 | /* ParamChecker does not have any global extensions */ |
| 217 | return util_GetExtensionProperties(0, NULL, pCount, pProperties); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 218 | } |
| 219 | |
Courtney Goeltzenleuchter | 426e187 | 2015-07-07 11:18:30 -0600 | [diff] [blame] | 220 | VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalLayerProperties( |
| 221 | uint32_t *pCount, |
| 222 | VkLayerProperties* pProperties) |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 223 | { |
Courtney Goeltzenleuchter | 426e187 | 2015-07-07 11:18:30 -0600 | [diff] [blame] | 224 | return util_GetLayerProperties(ARRAY_SIZE(pc_global_layers), |
| 225 | pc_global_layers, |
| 226 | pCount, pProperties); |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceExtensionProperties( |
Courtney Goeltzenleuchter | 426e187 | 2015-07-07 11:18:30 -0600 | [diff] [blame] | 230 | VkPhysicalDevice physicalDevice, |
| 231 | const char* pLayerName, |
| 232 | uint32_t* pCount, |
| 233 | VkExtensionProperties* pProperties) |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 234 | { |
Courtney Goeltzenleuchter | 426e187 | 2015-07-07 11:18:30 -0600 | [diff] [blame] | 235 | /* ParamChecker does not have any physical device extensions */ |
| 236 | return util_GetExtensionProperties(0, NULL, pCount, pProperties); |
| 237 | } |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 238 | |
Courtney Goeltzenleuchter | 426e187 | 2015-07-07 11:18:30 -0600 | [diff] [blame] | 239 | VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceLayerProperties( |
| 240 | VkPhysicalDevice physicalDevice, |
| 241 | uint32_t* pCount, |
| 242 | VkLayerProperties* pProperties) |
| 243 | { |
| 244 | /* ParamChecker's physical device layers are the same as global */ |
| 245 | return util_GetLayerProperties(ARRAY_SIZE(pc_global_layers), pc_global_layers, |
| 246 | pCount, pProperties); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 247 | } |
| 248 | |
Mark Lobodzinski | 2fd634c | 2015-07-29 09:21:22 -0600 | [diff] [blame^] | 249 | // Start of the Image layer proper |
| 250 | |
| 251 | // Returns TRUE if a format is a depth-compatible format |
| 252 | bool is_depth_format(VkFormat format) |
| 253 | { |
| 254 | bool result = VK_FALSE; |
| 255 | switch (format) { |
| 256 | case VK_FORMAT_D16_UNORM: |
| 257 | case VK_FORMAT_D24_UNORM: |
| 258 | case VK_FORMAT_D32_SFLOAT: |
| 259 | case VK_FORMAT_S8_UINT: |
| 260 | case VK_FORMAT_D16_UNORM_S8_UINT: |
| 261 | case VK_FORMAT_D24_UNORM_S8_UINT: |
| 262 | case VK_FORMAT_D32_SFLOAT_S8_UINT: |
| 263 | result = VK_TRUE; |
| 264 | break; |
| 265 | default: |
| 266 | break; |
| 267 | } |
| 268 | return result; |
| 269 | } |
| 270 | |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 271 | VK_LAYER_EXPORT VkResult VKAPI vkCreateImage(VkDevice device, const VkImageCreateInfo* pCreateInfo, VkImage* pImage) |
| 272 | { |
| 273 | if(pCreateInfo->format != VK_FORMAT_UNDEFINED) |
| 274 | { |
Courtney Goeltzenleuchter | a8fd5a5 | 2015-06-22 16:19:14 -0600 | [diff] [blame] | 275 | 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] | 276 | VkFormatProperties properties; |
Courtney Goeltzenleuchter | c729b3a | 2015-07-12 12:40:29 -0600 | [diff] [blame] | 277 | 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] | 278 | device_data->physicalDevice, pCreateInfo->format, &properties); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 279 | if(result != VK_SUCCESS) |
| 280 | { |
| 281 | char const str[] = "vkCreateImage parameter, VkFormat pCreateInfo->format, cannot be validated"; |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 282 | log_msg(mdd(device), VK_DBG_REPORT_WARN_BIT, (VkDbgObjectType)0, 0, 0, 1, "IMAGE", str); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | if((properties.linearTilingFeatures) == 0 && (properties.optimalTilingFeatures == 0)) |
| 286 | { |
| 287 | char const str[] = "vkCreateImage parameter, VkFormat pCreateInfo->format, contains unsupported format"; |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 288 | log_msg(mdd(device), VK_DBG_REPORT_WARN_BIT, (VkDbgObjectType)0, 0, 0, 1, "IMAGE", str); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 289 | } |
| 290 | } |
| 291 | |
| 292 | VkResult result = get_dispatch_table(image_device_table_map, device)->CreateImage(device, pCreateInfo, pImage); |
| 293 | |
| 294 | return result; |
| 295 | } |
| 296 | |
| 297 | VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, VkRenderPass* pRenderPass) |
| 298 | { |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 299 | for(uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 300 | { |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 301 | if(pCreateInfo->pAttachments[i].format != VK_FORMAT_UNDEFINED) |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 302 | { |
Courtney Goeltzenleuchter | a8fd5a5 | 2015-06-22 16:19:14 -0600 | [diff] [blame] | 303 | 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] | 304 | VkFormatProperties properties; |
Courtney Goeltzenleuchter | c729b3a | 2015-07-12 12:40:29 -0600 | [diff] [blame] | 305 | 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] | 306 | device_data->physicalDevice, pCreateInfo->pAttachments[i].format, &properties); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 307 | if(result != VK_SUCCESS) |
| 308 | { |
| 309 | std::stringstream ss; |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 310 | ss << "vkCreateRenderPass parameter, VkFormat in pCreateInfo->pAttachments[" << i << "], cannot be validated"; |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 311 | log_msg(mdd(device), VK_DBG_REPORT_WARN_BIT, (VkDbgObjectType)0, 0, 0, 1, "IMAGE", ss.str().c_str()); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 312 | continue; |
| 313 | } |
| 314 | |
| 315 | if((properties.linearTilingFeatures) == 0 && (properties.optimalTilingFeatures == 0)) |
| 316 | { |
| 317 | std::stringstream ss; |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 318 | ss << "vkCreateRenderPass parameter, VkFormat in pCreateInfo->pAttachments[" << i << "], contains unsupported format"; |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 319 | log_msg(mdd(device), VK_DBG_REPORT_WARN_BIT, (VkDbgObjectType)0, 0, 0, 1, "IMAGE", ss.str().c_str()); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 320 | } |
| 321 | } |
| 322 | } |
| 323 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 324 | for(uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 325 | { |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 326 | if(!validate_VkImageLayout(pCreateInfo->pAttachments[i].initialLayout) || |
| 327 | !validate_VkImageLayout(pCreateInfo->pAttachments[i].finalLayout)) |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 328 | { |
| 329 | std::stringstream ss; |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 330 | ss << "vkCreateRenderPass parameter, VkImageLayout in pCreateInfo->pAttachments[" << i << "], is unrecognized"; |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 331 | log_msg(mdd(device), VK_DBG_REPORT_WARN_BIT, (VkDbgObjectType)0, 0, 0, 1, "IMAGE", ss.str().c_str()); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 332 | } |
| 333 | } |
| 334 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 335 | for(uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 336 | { |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 337 | if(!validate_VkAttachmentLoadOp(pCreateInfo->pAttachments[i].loadOp)) |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 338 | { |
| 339 | std::stringstream ss; |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 340 | ss << "vkCreateRenderPass parameter, VkAttachmentLoadOp in pCreateInfo->pAttachments[" << i << "], is unrecognized"; |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 341 | log_msg(mdd(device), VK_DBG_REPORT_WARN_BIT, (VkDbgObjectType)0, 0, 0, 1, "IMAGE", ss.str().c_str()); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 342 | } |
| 343 | } |
| 344 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 345 | for(uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 346 | { |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 347 | if(!validate_VkAttachmentStoreOp(pCreateInfo->pAttachments[i].storeOp)) |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 348 | { |
| 349 | std::stringstream ss; |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 350 | ss << "vkCreateRenderPass parameter, VkAttachmentStoreOp in pCreateInfo->pAttachments[" << i << "], is unrecognized"; |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 351 | log_msg(mdd(device), VK_DBG_REPORT_WARN_BIT, (VkDbgObjectType)0, 0, 0, 1, "IMAGE", ss.str().c_str()); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 352 | } |
| 353 | } |
| 354 | |
Mark Lobodzinski | 2fd634c | 2015-07-29 09:21:22 -0600 | [diff] [blame^] | 355 | // Any depth buffers specified as attachments? |
| 356 | bool depthFormatPresent = VK_FALSE; |
| 357 | for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) |
| 358 | { |
| 359 | depthFormatPresent |= is_depth_format(pCreateInfo->pAttachments[i].format); |
| 360 | } |
| 361 | |
| 362 | if (depthFormatPresent == VK_FALSE) { |
| 363 | // No depth attachment is present, validate that subpasses set depthStencilAttachment to VK_ATTACHMENT_UNUSED; |
| 364 | for (uint32_t i = 0; i < pCreateInfo->subpassCount; i++) { |
| 365 | if (pCreateInfo->pSubpasses[i].depthStencilAttachment.attachment != VK_ATTACHMENT_UNUSED) { |
| 366 | std::stringstream ss; |
| 367 | ss << "vkCreateRenderPass has no depth/stencil attachment, yet subpass[" << i << "] has VkSubpassDescription::depthStencilAttachment value that is not VK_ATTACHMENT_UNUSED"; |
| 368 | log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, 1, "IMAGE", ss.str().c_str()); |
| 369 | } |
| 370 | } |
| 371 | } |
| 372 | |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 373 | VkResult result = get_dispatch_table(image_device_table_map, device)->CreateRenderPass(device, pCreateInfo, pRenderPass); |
| 374 | |
| 375 | return result; |
| 376 | } |
| 377 | |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 378 | VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice device, const char* funcName) |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 379 | { |
| 380 | if (device == NULL) { |
| 381 | return NULL; |
| 382 | } |
| 383 | |
| 384 | /* loader uses this to force layer initialization; device object is wrapped */ |
| 385 | if (!strcmp(funcName, "vkGetDeviceProcAddr")) { |
| 386 | initDeviceTable(image_device_table_map, (const VkBaseLayerObject *) device); |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 387 | return (PFN_vkVoidFunction) vkGetDeviceProcAddr; |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 388 | } |
| 389 | |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 390 | if (!strcmp(funcName, "vkCreateDevice")) |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 391 | return (PFN_vkVoidFunction) vkCreateDevice; |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 392 | if (!strcmp(funcName, "vkDestroyDevice")) |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 393 | return (PFN_vkVoidFunction) vkDestroyDevice; |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 394 | if (!strcmp(funcName, "vkCreateImage")) |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 395 | return (PFN_vkVoidFunction) vkCreateImage; |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 396 | if (!strcmp(funcName, "vkCreateRenderPass")) |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 397 | return (PFN_vkVoidFunction) vkCreateRenderPass; |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 398 | |
| 399 | { |
| 400 | if (get_dispatch_table(image_device_table_map, device)->GetDeviceProcAddr == NULL) |
| 401 | return NULL; |
| 402 | return get_dispatch_table(image_device_table_map, device)->GetDeviceProcAddr(device, funcName); |
| 403 | } |
| 404 | } |
| 405 | |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 406 | VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName) |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 407 | { |
| 408 | if (instance == NULL) { |
| 409 | return NULL; |
| 410 | } |
| 411 | |
| 412 | /* loader uses this to force layer initialization; instance object is wrapped */ |
| 413 | if (!strcmp(funcName, "vkGetInstanceProcAddr")) { |
| 414 | initInstanceTable(image_instance_table_map, (const VkBaseLayerObject *) instance); |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 415 | return (PFN_vkVoidFunction) vkGetInstanceProcAddr; |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | if (!strcmp(funcName, "vkCreateInstance")) |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 419 | return (PFN_vkVoidFunction) vkCreateInstance; |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 420 | if (!strcmp(funcName, "vkDestroyInstance")) |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 421 | return (PFN_vkVoidFunction) vkDestroyInstance; |
Courtney Goeltzenleuchter | 426e187 | 2015-07-07 11:18:30 -0600 | [diff] [blame] | 422 | if (!strcmp(funcName, "vkGetGlobalLayerProperties")) |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 423 | return (PFN_vkVoidFunction) vkGetGlobalLayerProperties; |
Courtney Goeltzenleuchter | 426e187 | 2015-07-07 11:18:30 -0600 | [diff] [blame] | 424 | if (!strcmp(funcName, "vkGetGlobalExtensionProperties")) |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 425 | return (PFN_vkVoidFunction) vkGetGlobalExtensionProperties; |
Courtney Goeltzenleuchter | 426e187 | 2015-07-07 11:18:30 -0600 | [diff] [blame] | 426 | if (!strcmp(funcName, "vkGetPhysicalDeviceLayerProperties")) |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 427 | return (PFN_vkVoidFunction) vkGetPhysicalDeviceLayerProperties; |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 428 | if (!strcmp(funcName, "vkGetPhysicalDeviceExtensionProperties")) |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 429 | return (PFN_vkVoidFunction) vkGetPhysicalDeviceExtensionProperties; |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 430 | |
| 431 | 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] | 432 | 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] | 433 | if(fptr) |
| 434 | return fptr; |
| 435 | |
| 436 | { |
| 437 | if (get_dispatch_table(image_instance_table_map, instance)->GetInstanceProcAddr == NULL) |
| 438 | return NULL; |
| 439 | return get_dispatch_table(image_instance_table_map, instance)->GetInstanceProcAddr(instance, funcName); |
| 440 | } |
| 441 | } |