Jeremy Hayes | b707aa5 | 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 | 7a51d90 | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 34 | #include "vk_loader_platform.h" |
Tobin Ehlis | 2d1d970 | 2015-07-03 09:42:57 -0600 | [diff] [blame] | 35 | #include "vk_layer.h" |
Tobin Ehlis | 56d204a | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 36 | #include "vk_layer_config.h" |
Jeremy Hayes | b707aa5 | 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 | 7a51d90 | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 40 | #include "vk_loader_platform.h" |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 41 | |
Tobin Ehlis | 56d204a | 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 | eb1ddb0 | 2015-07-07 11:18:30 -0600 | [diff] [blame] | 45 | #include "vk_layer_extension_utils.h" |
Jeremy Hayes | b707aa5 | 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 | d757630 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 50 | VkPhysicalDevice physicalDevice; |
Jeremy Hayes | b707aa5 | 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 | 2a199c1 | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 58 | debug_report_data *mdd(const void* object) |
Jeremy Hayes | b707aa5 | 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 | b707aa5 | 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 | 0719921 | 2015-06-22 16:19:14 -0600 | [diff] [blame] | 72 | layer_data *data = get_my_data_ptr(key, layer_data_map); |
Jeremy Hayes | b707aa5 | 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 | b707aa5 | 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 | eb1ddb0 | 2015-07-07 11:18:30 -0600 | [diff] [blame] | 140 | pCreateInfo->ppEnabledExtensionNames); |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 141 | |
| 142 | InitImage(data); |
| 143 | } |
| 144 | |
| 145 | return result; |
| 146 | } |
| 147 | |
Mark Lobodzinski | 67b42b7 | 2015-09-07 13:59:43 -0600 | [diff] [blame] | 148 | VK_LAYER_EXPORT void VKAPI vkDestroyInstance(VkInstance instance) |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 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); |
Mark Lobodzinski | 67b42b7 | 2015-09-07 13:59:43 -0600 | [diff] [blame] | 153 | pTable->DestroyInstance(instance); |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 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"); |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice) |
| 170 | { |
Courtney Goeltzenleuchter | be63799 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 171 | VkLayerDispatchTable *pTable = get_dispatch_table(image_device_table_map, *pDevice); |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 172 | VkResult result = pTable->CreateDevice(physicalDevice, pCreateInfo, pDevice); |
| 173 | if(result == VK_SUCCESS) |
| 174 | { |
| 175 | layer_data *instance_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
| 176 | layer_data *device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map); |
| 177 | device_data->report_data = layer_debug_report_create_device(instance_data->report_data, *pDevice); |
Chris Forbes | d757630 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 178 | device_data->physicalDevice = physicalDevice; |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | return result; |
| 182 | } |
| 183 | |
Mark Lobodzinski | 67b42b7 | 2015-09-07 13:59:43 -0600 | [diff] [blame] | 184 | VK_LAYER_EXPORT void VKAPI vkDestroyDevice(VkDevice device) |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 185 | { |
| 186 | layer_debug_report_destroy_device(device); |
| 187 | |
| 188 | dispatch_key key = get_dispatch_key(device); |
| 189 | #if DISPATCH_MAP_DEBUG |
| 190 | fprintf(stderr, "Device: %p, key: %p\n", device, key); |
| 191 | #endif |
| 192 | |
Mark Lobodzinski | 67b42b7 | 2015-09-07 13:59:43 -0600 | [diff] [blame] | 193 | get_dispatch_table(image_device_table_map, device)->DestroyDevice(device); |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 194 | image_device_table_map.erase(key); |
| 195 | assert(image_device_table_map.size() == 0 && "Should not have any instance mappings hanging around"); |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 196 | } |
| 197 | |
Courtney Goeltzenleuchter | eb1ddb0 | 2015-07-07 11:18:30 -0600 | [diff] [blame] | 198 | static const VkLayerProperties pc_global_layers[] = { |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 199 | { |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 200 | "Image", |
Courtney Goeltzenleuchter | eb1ddb0 | 2015-07-07 11:18:30 -0600 | [diff] [blame] | 201 | VK_API_VERSION, |
| 202 | VK_MAKE_VERSION(0, 1, 0), |
| 203 | "Validation layer: Image ParamChecker", |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 204 | } |
| 205 | }; |
| 206 | |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 207 | VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionProperties( |
Courtney Goeltzenleuchter | eb1ddb0 | 2015-07-07 11:18:30 -0600 | [diff] [blame] | 208 | const char *pLayerName, |
| 209 | uint32_t *pCount, |
| 210 | VkExtensionProperties* pProperties) |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 211 | { |
Courtney Goeltzenleuchter | eb1ddb0 | 2015-07-07 11:18:30 -0600 | [diff] [blame] | 212 | /* ParamChecker does not have any global extensions */ |
| 213 | return util_GetExtensionProperties(0, NULL, pCount, pProperties); |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 214 | } |
| 215 | |
Courtney Goeltzenleuchter | eb1ddb0 | 2015-07-07 11:18:30 -0600 | [diff] [blame] | 216 | VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalLayerProperties( |
| 217 | uint32_t *pCount, |
| 218 | VkLayerProperties* pProperties) |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 219 | { |
Courtney Goeltzenleuchter | eb1ddb0 | 2015-07-07 11:18:30 -0600 | [diff] [blame] | 220 | return util_GetLayerProperties(ARRAY_SIZE(pc_global_layers), |
| 221 | pc_global_layers, |
| 222 | pCount, pProperties); |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceExtensionProperties( |
Courtney Goeltzenleuchter | eb1ddb0 | 2015-07-07 11:18:30 -0600 | [diff] [blame] | 226 | VkPhysicalDevice physicalDevice, |
| 227 | const char* pLayerName, |
| 228 | uint32_t* pCount, |
| 229 | VkExtensionProperties* pProperties) |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 230 | { |
Courtney Goeltzenleuchter | eb1ddb0 | 2015-07-07 11:18:30 -0600 | [diff] [blame] | 231 | /* ParamChecker does not have any physical device extensions */ |
| 232 | return util_GetExtensionProperties(0, NULL, pCount, pProperties); |
| 233 | } |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 234 | |
Courtney Goeltzenleuchter | eb1ddb0 | 2015-07-07 11:18:30 -0600 | [diff] [blame] | 235 | VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceLayerProperties( |
| 236 | VkPhysicalDevice physicalDevice, |
| 237 | uint32_t* pCount, |
| 238 | VkLayerProperties* pProperties) |
| 239 | { |
| 240 | /* ParamChecker's physical device layers are the same as global */ |
| 241 | return util_GetLayerProperties(ARRAY_SIZE(pc_global_layers), pc_global_layers, |
| 242 | pCount, pProperties); |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 243 | } |
| 244 | |
Mark Lobodzinski | 9cce783 | 2015-07-29 09:21:22 -0600 | [diff] [blame] | 245 | // Start of the Image layer proper |
| 246 | |
| 247 | // Returns TRUE if a format is a depth-compatible format |
| 248 | bool is_depth_format(VkFormat format) |
| 249 | { |
| 250 | bool result = VK_FALSE; |
| 251 | switch (format) { |
| 252 | case VK_FORMAT_D16_UNORM: |
Courtney Goeltzenleuchter | 7ed1059 | 2015-09-10 17:17:43 -0600 | [diff] [blame^] | 253 | case VK_FORMAT_D24_UNORM_X8: |
Mark Lobodzinski | 9cce783 | 2015-07-29 09:21:22 -0600 | [diff] [blame] | 254 | case VK_FORMAT_D32_SFLOAT: |
| 255 | case VK_FORMAT_S8_UINT: |
| 256 | case VK_FORMAT_D16_UNORM_S8_UINT: |
| 257 | case VK_FORMAT_D24_UNORM_S8_UINT: |
| 258 | case VK_FORMAT_D32_SFLOAT_S8_UINT: |
| 259 | result = VK_TRUE; |
| 260 | break; |
| 261 | default: |
| 262 | break; |
| 263 | } |
| 264 | return result; |
| 265 | } |
| 266 | |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 267 | VK_LAYER_EXPORT VkResult VKAPI vkCreateImage(VkDevice device, const VkImageCreateInfo* pCreateInfo, VkImage* pImage) |
| 268 | { |
| 269 | if(pCreateInfo->format != VK_FORMAT_UNDEFINED) |
| 270 | { |
Courtney Goeltzenleuchter | 0719921 | 2015-06-22 16:19:14 -0600 | [diff] [blame] | 271 | layer_data *device_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 272 | VkFormatProperties properties; |
Courtney Goeltzenleuchter | ab36aa6 | 2015-07-12 12:40:29 -0600 | [diff] [blame] | 273 | VkResult result = get_dispatch_table(image_instance_table_map, device_data->physicalDevice)->GetPhysicalDeviceFormatProperties( |
Chris Forbes | d757630 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 274 | device_data->physicalDevice, pCreateInfo->format, &properties); |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 275 | if(result != VK_SUCCESS) |
| 276 | { |
| 277 | char const str[] = "vkCreateImage parameter, VkFormat pCreateInfo->format, cannot be validated"; |
Tony Barbour | 2a199c1 | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 278 | log_msg(mdd(device), VK_DBG_REPORT_WARN_BIT, (VkDbgObjectType)0, 0, 0, 1, "IMAGE", str); |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | if((properties.linearTilingFeatures) == 0 && (properties.optimalTilingFeatures == 0)) |
| 282 | { |
| 283 | char const str[] = "vkCreateImage parameter, VkFormat pCreateInfo->format, contains unsupported format"; |
Tony Barbour | 2a199c1 | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 284 | log_msg(mdd(device), VK_DBG_REPORT_WARN_BIT, (VkDbgObjectType)0, 0, 0, 1, "IMAGE", str); |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 285 | } |
| 286 | } |
| 287 | |
| 288 | VkResult result = get_dispatch_table(image_device_table_map, device)->CreateImage(device, pCreateInfo, pImage); |
| 289 | |
| 290 | return result; |
| 291 | } |
| 292 | |
| 293 | VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, VkRenderPass* pRenderPass) |
| 294 | { |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 295 | for(uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 296 | { |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 297 | if(pCreateInfo->pAttachments[i].format != VK_FORMAT_UNDEFINED) |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 298 | { |
Courtney Goeltzenleuchter | 0719921 | 2015-06-22 16:19:14 -0600 | [diff] [blame] | 299 | layer_data *device_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 300 | VkFormatProperties properties; |
Courtney Goeltzenleuchter | ab36aa6 | 2015-07-12 12:40:29 -0600 | [diff] [blame] | 301 | VkResult result = get_dispatch_table(image_instance_table_map, device_data->physicalDevice)->GetPhysicalDeviceFormatProperties( |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 302 | device_data->physicalDevice, pCreateInfo->pAttachments[i].format, &properties); |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 303 | if(result != VK_SUCCESS) |
| 304 | { |
| 305 | std::stringstream ss; |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 306 | ss << "vkCreateRenderPass parameter, VkFormat in pCreateInfo->pAttachments[" << i << "], cannot be validated"; |
Tony Barbour | 2a199c1 | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 307 | log_msg(mdd(device), VK_DBG_REPORT_WARN_BIT, (VkDbgObjectType)0, 0, 0, 1, "IMAGE", ss.str().c_str()); |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 308 | continue; |
| 309 | } |
| 310 | |
| 311 | if((properties.linearTilingFeatures) == 0 && (properties.optimalTilingFeatures == 0)) |
| 312 | { |
| 313 | std::stringstream ss; |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 314 | ss << "vkCreateRenderPass parameter, VkFormat in pCreateInfo->pAttachments[" << i << "], contains unsupported format"; |
Tony Barbour | 2a199c1 | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 315 | log_msg(mdd(device), VK_DBG_REPORT_WARN_BIT, (VkDbgObjectType)0, 0, 0, 1, "IMAGE", ss.str().c_str()); |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 316 | } |
| 317 | } |
| 318 | } |
| 319 | |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 320 | for(uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 321 | { |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 322 | if(!validate_VkImageLayout(pCreateInfo->pAttachments[i].initialLayout) || |
| 323 | !validate_VkImageLayout(pCreateInfo->pAttachments[i].finalLayout)) |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 324 | { |
| 325 | std::stringstream ss; |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 326 | ss << "vkCreateRenderPass parameter, VkImageLayout in pCreateInfo->pAttachments[" << i << "], is unrecognized"; |
Tony Barbour | 2a199c1 | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 327 | log_msg(mdd(device), VK_DBG_REPORT_WARN_BIT, (VkDbgObjectType)0, 0, 0, 1, "IMAGE", ss.str().c_str()); |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 328 | } |
| 329 | } |
| 330 | |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 331 | for(uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 332 | { |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 333 | if(!validate_VkAttachmentLoadOp(pCreateInfo->pAttachments[i].loadOp)) |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 334 | { |
| 335 | std::stringstream ss; |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 336 | ss << "vkCreateRenderPass parameter, VkAttachmentLoadOp in pCreateInfo->pAttachments[" << i << "], is unrecognized"; |
Tony Barbour | 2a199c1 | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 337 | log_msg(mdd(device), VK_DBG_REPORT_WARN_BIT, (VkDbgObjectType)0, 0, 0, 1, "IMAGE", ss.str().c_str()); |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 338 | } |
| 339 | } |
| 340 | |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 341 | for(uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 342 | { |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 343 | if(!validate_VkAttachmentStoreOp(pCreateInfo->pAttachments[i].storeOp)) |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 344 | { |
| 345 | std::stringstream ss; |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 346 | ss << "vkCreateRenderPass parameter, VkAttachmentStoreOp in pCreateInfo->pAttachments[" << i << "], is unrecognized"; |
Tony Barbour | 2a199c1 | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 347 | log_msg(mdd(device), VK_DBG_REPORT_WARN_BIT, (VkDbgObjectType)0, 0, 0, 1, "IMAGE", ss.str().c_str()); |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 348 | } |
| 349 | } |
| 350 | |
Mark Lobodzinski | 9cce783 | 2015-07-29 09:21:22 -0600 | [diff] [blame] | 351 | // Any depth buffers specified as attachments? |
| 352 | bool depthFormatPresent = VK_FALSE; |
| 353 | for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) |
| 354 | { |
| 355 | depthFormatPresent |= is_depth_format(pCreateInfo->pAttachments[i].format); |
| 356 | } |
| 357 | |
| 358 | if (depthFormatPresent == VK_FALSE) { |
| 359 | // No depth attachment is present, validate that subpasses set depthStencilAttachment to VK_ATTACHMENT_UNUSED; |
| 360 | for (uint32_t i = 0; i < pCreateInfo->subpassCount; i++) { |
| 361 | if (pCreateInfo->pSubpasses[i].depthStencilAttachment.attachment != VK_ATTACHMENT_UNUSED) { |
| 362 | std::stringstream ss; |
| 363 | ss << "vkCreateRenderPass has no depth/stencil attachment, yet subpass[" << i << "] has VkSubpassDescription::depthStencilAttachment value that is not VK_ATTACHMENT_UNUSED"; |
| 364 | log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, 1, "IMAGE", ss.str().c_str()); |
| 365 | } |
| 366 | } |
| 367 | } |
| 368 | |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 369 | VkResult result = get_dispatch_table(image_device_table_map, device)->CreateRenderPass(device, pCreateInfo, pRenderPass); |
| 370 | |
| 371 | return result; |
| 372 | } |
| 373 | |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 374 | VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice device, const char* funcName) |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 375 | { |
| 376 | if (device == NULL) { |
| 377 | return NULL; |
| 378 | } |
| 379 | |
| 380 | /* loader uses this to force layer initialization; device object is wrapped */ |
| 381 | if (!strcmp(funcName, "vkGetDeviceProcAddr")) { |
| 382 | initDeviceTable(image_device_table_map, (const VkBaseLayerObject *) device); |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 383 | return (PFN_vkVoidFunction) vkGetDeviceProcAddr; |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 384 | } |
| 385 | |
Courtney Goeltzenleuchter | be63799 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 386 | if (!strcmp(funcName, "vkCreateDevice")) |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 387 | return (PFN_vkVoidFunction) vkCreateDevice; |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 388 | if (!strcmp(funcName, "vkDestroyDevice")) |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 389 | return (PFN_vkVoidFunction) vkDestroyDevice; |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 390 | if (!strcmp(funcName, "vkCreateImage")) |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 391 | return (PFN_vkVoidFunction) vkCreateImage; |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 392 | if (!strcmp(funcName, "vkCreateRenderPass")) |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 393 | return (PFN_vkVoidFunction) vkCreateRenderPass; |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 394 | |
| 395 | { |
| 396 | if (get_dispatch_table(image_device_table_map, device)->GetDeviceProcAddr == NULL) |
| 397 | return NULL; |
| 398 | return get_dispatch_table(image_device_table_map, device)->GetDeviceProcAddr(device, funcName); |
| 399 | } |
| 400 | } |
| 401 | |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 402 | VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName) |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 403 | { |
| 404 | if (instance == NULL) { |
| 405 | return NULL; |
| 406 | } |
| 407 | |
| 408 | /* loader uses this to force layer initialization; instance object is wrapped */ |
| 409 | if (!strcmp(funcName, "vkGetInstanceProcAddr")) { |
| 410 | initInstanceTable(image_instance_table_map, (const VkBaseLayerObject *) instance); |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 411 | return (PFN_vkVoidFunction) vkGetInstanceProcAddr; |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | if (!strcmp(funcName, "vkCreateInstance")) |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 415 | return (PFN_vkVoidFunction) vkCreateInstance; |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 416 | if (!strcmp(funcName, "vkDestroyInstance")) |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 417 | return (PFN_vkVoidFunction) vkDestroyInstance; |
Courtney Goeltzenleuchter | eb1ddb0 | 2015-07-07 11:18:30 -0600 | [diff] [blame] | 418 | if (!strcmp(funcName, "vkGetGlobalLayerProperties")) |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 419 | return (PFN_vkVoidFunction) vkGetGlobalLayerProperties; |
Courtney Goeltzenleuchter | eb1ddb0 | 2015-07-07 11:18:30 -0600 | [diff] [blame] | 420 | if (!strcmp(funcName, "vkGetGlobalExtensionProperties")) |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 421 | return (PFN_vkVoidFunction) vkGetGlobalExtensionProperties; |
Courtney Goeltzenleuchter | eb1ddb0 | 2015-07-07 11:18:30 -0600 | [diff] [blame] | 422 | if (!strcmp(funcName, "vkGetPhysicalDeviceLayerProperties")) |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 423 | return (PFN_vkVoidFunction) vkGetPhysicalDeviceLayerProperties; |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 424 | if (!strcmp(funcName, "vkGetPhysicalDeviceExtensionProperties")) |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 425 | return (PFN_vkVoidFunction) vkGetPhysicalDeviceExtensionProperties; |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 426 | |
| 427 | layer_data *data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 428 | PFN_vkVoidFunction fptr = debug_report_get_instance_proc_addr(data->report_data, funcName); |
Jeremy Hayes | b707aa5 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 429 | if(fptr) |
| 430 | return fptr; |
| 431 | |
| 432 | { |
| 433 | if (get_dispatch_table(image_instance_table_map, instance)->GetInstanceProcAddr == NULL) |
| 434 | return NULL; |
| 435 | return get_dispatch_table(image_instance_table_map, instance)->GetInstanceProcAddr(instance, funcName); |
| 436 | } |
| 437 | } |