Mark Lobodzinski | 6eda00a | 2016-02-02 15:55:36 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2015-2016 The Khronos Group Inc. |
| 2 | * Copyright (c) 2015-2016 Valve Corporation |
| 3 | * Copyright (c) 2015-2016 LunarG, Inc. |
| 4 | * Copyright (C) 2015-2016 Google Inc. |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 5 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 9 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 11 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
Courtney Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 17 | * |
| 18 | * Author: Jeremy Hayes <jeremy@lunarg.com> |
| 19 | * Author: Mark Lobodzinski <mark@lunarg.com> |
| 20 | * Author: Mike Stroyan <mike@LunarG.com> |
| 21 | * Author: Tobin Ehlis <tobin@lunarg.com> |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 22 | */ |
| 23 | |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 24 | // Allow use of STL min and max functions in Windows |
| 25 | #define NOMINMAX |
| 26 | |
Jeremy Hayes | e0ed6a2 | 2016-04-08 09:53:54 -0600 | [diff] [blame] | 27 | #include <algorithm> |
| 28 | #include <assert.h> |
Karl Schultz | d7f3754 | 2016-05-10 11:36:08 -0600 | [diff] [blame] | 29 | #include <cinttypes> |
Jeremy Hayes | e0ed6a2 | 2016-04-08 09:53:54 -0600 | [diff] [blame] | 30 | #include <memory> |
| 31 | #include <mutex> |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 32 | #include <stdio.h> |
| 33 | #include <stdlib.h> |
| 34 | #include <string.h> |
Mark Lobodzinski | 040142c | 2016-11-22 11:18:46 -0700 | [diff] [blame] | 35 | #include <limits.h> |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 36 | #include <unordered_map> |
Jeremy Hayes | e0ed6a2 | 2016-04-08 09:53:54 -0600 | [diff] [blame] | 37 | #include <vector> |
Mark Lobodzinski | 040142c | 2016-11-22 11:18:46 -0700 | [diff] [blame] | 38 | #include <bitset> |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 39 | |
Tobin Ehlis | b835d1b | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 40 | #include "vk_loader_platform.h" |
Courtney Goeltzenleuchter | 8f8367e | 2015-10-07 08:38:30 -0600 | [diff] [blame] | 41 | #include "vk_dispatch_table_helper.h" |
| 42 | #include "vk_struct_string_helper_cpp.h" |
Courtney Goeltzenleuchter | 8f8367e | 2015-10-07 08:38:30 -0600 | [diff] [blame] | 43 | #include "image.h" |
| 44 | #include "vk_layer_config.h" |
| 45 | #include "vk_layer_extension_utils.h" |
Tobin Ehlis | a0cb02e | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 46 | #include "vk_layer_table.h" |
| 47 | #include "vk_layer_data.h" |
Courtney Goeltzenleuchter | 426e187 | 2015-07-07 11:18:30 -0600 | [diff] [blame] | 48 | #include "vk_layer_extension_utils.h" |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 49 | #include "vk_layer_utils.h" |
Courtney Goeltzenleuchter | 8f8367e | 2015-10-07 08:38:30 -0600 | [diff] [blame] | 50 | #include "vk_layer_logging.h" |
Mark Lobodzinski | 69b52fe | 2016-10-14 11:43:06 -0600 | [diff] [blame] | 51 | #include "vk_validation_error_messages.h" |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 52 | |
Mark Mueller | aab3650 | 2016-05-03 13:17:29 -0600 | [diff] [blame] | 53 | using namespace std; |
| 54 | |
Chia-I Wu | aacb0fc | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 55 | namespace image { |
| 56 | |
Cody Northrop | 55443ef | 2015-09-28 15:09:32 -0600 | [diff] [blame] | 57 | struct layer_data { |
Chia-I Wu | 2cfc77c | 2016-04-28 16:04:15 +0800 | [diff] [blame] | 58 | VkInstance instance; |
| 59 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 60 | debug_report_data *report_data; |
| 61 | vector<VkDebugReportCallbackEXT> logging_callback; |
| 62 | VkLayerDispatchTable *device_dispatch_table; |
Mark Lobodzinski | d5a2382 | 2015-11-12 15:14:35 -0700 | [diff] [blame] | 63 | VkLayerInstanceDispatchTable *instance_dispatch_table; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 64 | VkPhysicalDevice physicalDevice; |
| 65 | VkPhysicalDeviceProperties physicalDeviceProperties; |
Mark Lobodzinski | d5a2382 | 2015-11-12 15:14:35 -0700 | [diff] [blame] | 66 | |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 67 | unordered_map<VkImage, IMAGE_STATE> imageMap; |
Cody Northrop | 55443ef | 2015-09-28 15:09:32 -0600 | [diff] [blame] | 68 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 69 | layer_data() |
| 70 | : report_data(nullptr), device_dispatch_table(nullptr), instance_dispatch_table(nullptr), physicalDevice(0), |
| 71 | physicalDeviceProperties(){}; |
Cody Northrop | 55443ef | 2015-09-28 15:09:32 -0600 | [diff] [blame] | 72 | }; |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 73 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 74 | static unordered_map<void *, layer_data *> layer_data_map; |
Jeremy Hayes | e0ed6a2 | 2016-04-08 09:53:54 -0600 | [diff] [blame] | 75 | static std::mutex global_lock; |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 76 | |
Mark Lobodzinski | 1079e1b | 2016-03-15 14:21:59 -0600 | [diff] [blame] | 77 | static void init_image(layer_data *my_data, const VkAllocationCallbacks *pAllocator) { |
Mark Lobodzinski | 1079e1b | 2016-03-15 14:21:59 -0600 | [diff] [blame] | 78 | layer_debug_actions(my_data->report_data, my_data->logging_callback, pAllocator, "lunarg_image"); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 79 | } |
| 80 | |
Tobin Ehlis | f4d352b | 2016-05-19 09:59:30 -0600 | [diff] [blame] | 81 | static IMAGE_STATE const *getImageState(layer_data const *dev_data, VkImage image) { |
| 82 | auto it = dev_data->imageMap.find(image); |
| 83 | if (it == dev_data->imageMap.end()) { |
| 84 | return nullptr; |
| 85 | } |
| 86 | return &it->second; |
| 87 | } |
| 88 | |
Chia-I Wu | 4935c76 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 89 | VKAPI_ATTR VkResult VKAPI_CALL |
| 90 | CreateDebugReportCallbackEXT(VkInstance instance, const VkDebugReportCallbackCreateInfoEXT *pCreateInfo, |
| 91 | const VkAllocationCallbacks *pAllocator, VkDebugReportCallbackEXT *pMsgCallback) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 92 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
| 93 | VkResult res = my_data->instance_dispatch_table->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 94 | if (res == VK_SUCCESS) { |
Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 95 | res = layer_create_msg_callback(my_data->report_data, false, pCreateInfo, pAllocator, pMsgCallback); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 96 | } |
| 97 | return res; |
| 98 | } |
| 99 | |
Chia-I Wu | 4935c76 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 100 | VKAPI_ATTR void VKAPI_CALL DestroyDebugReportCallbackEXT(VkInstance instance, |
| 101 | VkDebugReportCallbackEXT msgCallback, |
| 102 | const VkAllocationCallbacks *pAllocator) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 103 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
| 104 | my_data->instance_dispatch_table->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator); |
Courtney Goeltzenleuchter | 05854bf | 2015-11-30 12:13:14 -0700 | [diff] [blame] | 105 | layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 106 | } |
| 107 | |
Chia-I Wu | 4935c76 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 108 | VKAPI_ATTR void VKAPI_CALL |
| 109 | DebugReportMessageEXT(VkInstance instance, VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t object, |
| 110 | size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 111 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 112 | my_data->instance_dispatch_table->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, |
| 113 | pMsg); |
Courtney Goeltzenleuchter | f0de724 | 2015-12-01 14:10:55 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Chia-I Wu | 4935c76 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 116 | VKAPI_ATTR VkResult VKAPI_CALL |
| 117 | CreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkInstance *pInstance) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 118 | VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 119 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 120 | assert(chain_info->u.pLayerInfo); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 121 | PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 122 | PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 123 | if (fpCreateInstance == NULL) { |
| 124 | return VK_ERROR_INITIALIZATION_FAILED; |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 125 | } |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 126 | |
| 127 | // Advance the link info for the next element on the chain |
| 128 | chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; |
| 129 | |
| 130 | VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance); |
| 131 | if (result != VK_SUCCESS) |
| 132 | return result; |
| 133 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 134 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map); |
Chia-I Wu | 2cfc77c | 2016-04-28 16:04:15 +0800 | [diff] [blame] | 135 | my_data->instance = *pInstance; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 136 | my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 137 | layer_init_instance_dispatch_table(*pInstance, my_data->instance_dispatch_table, fpGetInstanceProcAddr); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 138 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 139 | my_data->report_data = debug_report_create_instance(my_data->instance_dispatch_table, *pInstance, |
| 140 | pCreateInfo->enabledExtensionCount, pCreateInfo->ppEnabledExtensionNames); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 141 | |
Mark Lobodzinski | 1079e1b | 2016-03-15 14:21:59 -0600 | [diff] [blame] | 142 | init_image(my_data, pAllocator); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 143 | |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 144 | return result; |
| 145 | } |
| 146 | |
Chia-I Wu | 4935c76 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 147 | VKAPI_ATTR void VKAPI_CALL DestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) { |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 148 | // Grab the key before the instance is destroyed. |
| 149 | dispatch_key key = get_dispatch_key(instance); |
Tobin Ehlis | b74f6ab | 2015-10-29 14:19:18 -0600 | [diff] [blame] | 150 | layer_data *my_data = get_my_data_ptr(key, layer_data_map); |
| 151 | VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 152 | pTable->DestroyInstance(instance, pAllocator); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 153 | |
| 154 | // Clean up logging callback, if any |
Courtney Goeltzenleuchter | ffcdd8b | 2015-10-05 15:59:11 -0600 | [diff] [blame] | 155 | while (my_data->logging_callback.size() > 0) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 156 | VkDebugReportCallbackEXT callback = my_data->logging_callback.back(); |
Courtney Goeltzenleuchter | 05854bf | 2015-11-30 12:13:14 -0700 | [diff] [blame] | 157 | layer_destroy_msg_callback(my_data->report_data, callback, pAllocator); |
Courtney Goeltzenleuchter | ffcdd8b | 2015-10-05 15:59:11 -0600 | [diff] [blame] | 158 | my_data->logging_callback.pop_back(); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 159 | } |
| 160 | |
Tobin Ehlis | b74f6ab | 2015-10-29 14:19:18 -0600 | [diff] [blame] | 161 | layer_debug_report_destroy_instance(my_data->report_data); |
| 162 | delete my_data->instance_dispatch_table; |
| 163 | layer_data_map.erase(key); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 164 | } |
| 165 | |
Chia-I Wu | 4935c76 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 166 | VKAPI_ATTR VkResult VKAPI_CALL CreateDevice(VkPhysicalDevice physicalDevice, |
| 167 | const VkDeviceCreateInfo *pCreateInfo, |
| 168 | const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) { |
Chia-I Wu | 2cfc77c | 2016-04-28 16:04:15 +0800 | [diff] [blame] | 169 | layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 170 | VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 171 | |
| 172 | assert(chain_info->u.pLayerInfo); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 173 | PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr; |
| 174 | PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr; |
Chia-I Wu | 2cfc77c | 2016-04-28 16:04:15 +0800 | [diff] [blame] | 175 | PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice)fpGetInstanceProcAddr(my_instance_data->instance, "vkCreateDevice"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 176 | if (fpCreateDevice == NULL) { |
| 177 | return VK_ERROR_INITIALIZATION_FAILED; |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 178 | } |
| 179 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 180 | // Advance the link info for the next element on the chain |
| 181 | chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; |
| 182 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 183 | VkResult result = fpCreateDevice(physicalDevice, pCreateInfo, pAllocator, pDevice); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 184 | if (result != VK_SUCCESS) { |
| 185 | return result; |
| 186 | } |
| 187 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 188 | layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 189 | |
| 190 | // Setup device dispatch table |
| 191 | my_device_data->device_dispatch_table = new VkLayerDispatchTable; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 192 | layer_init_device_dispatch_table(*pDevice, my_device_data->device_dispatch_table, fpGetDeviceProcAddr); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 193 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 194 | my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 195 | my_device_data->physicalDevice = physicalDevice; |
| 196 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 197 | my_instance_data->instance_dispatch_table->GetPhysicalDeviceProperties(physicalDevice, |
| 198 | &(my_device_data->physicalDeviceProperties)); |
Mark Lobodzinski | d5a2382 | 2015-11-12 15:14:35 -0700 | [diff] [blame] | 199 | |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 200 | return result; |
| 201 | } |
| 202 | |
Chia-I Wu | 4935c76 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 203 | VKAPI_ATTR void VKAPI_CALL DestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) { |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 204 | dispatch_key key = get_dispatch_key(device); |
Tobin Ehlis | b74f6ab | 2015-10-29 14:19:18 -0600 | [diff] [blame] | 205 | layer_data *my_data = get_my_data_ptr(key, layer_data_map); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 206 | my_data->device_dispatch_table->DestroyDevice(device, pAllocator); |
Tobin Ehlis | b74f6ab | 2015-10-29 14:19:18 -0600 | [diff] [blame] | 207 | delete my_data->device_dispatch_table; |
| 208 | layer_data_map.erase(key); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 209 | } |
| 210 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 211 | static const VkExtensionProperties instance_extensions[] = {{VK_EXT_DEBUG_REPORT_EXTENSION_NAME, VK_EXT_DEBUG_REPORT_SPEC_VERSION}}; |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 212 | |
Chia-I Wu | 740891e | 2016-04-28 14:12:27 +0800 | [diff] [blame] | 213 | static const VkLayerProperties global_layer = { |
Jon Ashburn | dc9111c | 2016-03-22 12:57:13 -0600 | [diff] [blame] | 214 | "VK_LAYER_LUNARG_image", VK_LAYER_API_VERSION, 1, "LunarG Validation Layer", |
Chia-I Wu | 740891e | 2016-04-28 14:12:27 +0800 | [diff] [blame] | 215 | }; |
Courtney Goeltzenleuchter | 5285766 | 2015-12-01 14:08:28 -0700 | [diff] [blame] | 216 | |
Mark Lobodzinski | 2fd634c | 2015-07-29 09:21:22 -0600 | [diff] [blame] | 217 | // Start of the Image layer proper |
| 218 | |
Mark Lobodzinski | 9d1d6b1 | 2016-05-17 08:42:03 -0600 | [diff] [blame] | 219 | VKAPI_ATTR VkResult VKAPI_CALL CreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo, |
| 220 | const VkAllocationCallbacks *pAllocator, VkImage *pImage) { |
| 221 | bool skip_call = false; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 222 | VkResult result = VK_ERROR_VALIDATION_FAILED_EXT; |
Michael Lentine | 0a369f6 | 2016-02-03 16:51:46 -0600 | [diff] [blame] | 223 | VkImageFormatProperties ImageFormatProperties; |
Mark Lobodzinski | d5a2382 | 2015-11-12 15:14:35 -0700 | [diff] [blame] | 224 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 225 | layer_data *device_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
| 226 | VkPhysicalDevice physicalDevice = device_data->physicalDevice; |
| 227 | layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
Mark Lobodzinski | d5a2382 | 2015-11-12 15:14:35 -0700 | [diff] [blame] | 228 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 229 | if (pCreateInfo->format != VK_FORMAT_UNDEFINED) { |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 230 | VkFormatProperties properties; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 231 | phy_dev_data->instance_dispatch_table->GetPhysicalDeviceFormatProperties(device_data->physicalDevice, pCreateInfo->format, |
| 232 | &properties); |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 233 | if ((pCreateInfo->tiling == VK_IMAGE_TILING_LINEAR) && (properties.linearTilingFeatures == 0)) { |
Mark Lobodzinski | 9d1d6b1 | 2016-05-17 08:42:03 -0600 | [diff] [blame] | 234 | std::stringstream ss; |
| 235 | ss << "vkCreateImage format parameter (" << string_VkFormat(pCreateInfo->format) << ") is an unsupported format"; |
Mark Lobodzinski | 9d1d6b1 | 2016-05-17 08:42:03 -0600 | [diff] [blame] | 236 | skip_call |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 237 | 0, __LINE__, VALIDATION_ERROR_02150, "IMAGE", "%s. %s", ss.str().c_str(), |
| 238 | validation_error_map[VALIDATION_ERROR_02150]); |
| 239 | } |
| 240 | |
| 241 | if ((pCreateInfo->tiling == VK_IMAGE_TILING_OPTIMAL) && (properties.optimalTilingFeatures == 0)) { |
| 242 | std::stringstream ss; |
| 243 | ss << "vkCreateImage format parameter (" << string_VkFormat(pCreateInfo->format) << ") is an unsupported format"; |
| 244 | skip_call |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, |
| 245 | 0, __LINE__, VALIDATION_ERROR_02155, "IMAGE", "%s. %s", ss.str().c_str(), |
| 246 | validation_error_map[VALIDATION_ERROR_02155]); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 247 | } |
Mark Lobodzinski | 9d1d6b1 | 2016-05-17 08:42:03 -0600 | [diff] [blame] | 248 | |
| 249 | // Validate that format supports usage as color attachment |
| 250 | if (pCreateInfo->usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) { |
| 251 | if ((pCreateInfo->tiling == VK_IMAGE_TILING_OPTIMAL) && |
| 252 | ((properties.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) == 0)) { |
| 253 | std::stringstream ss; |
| 254 | ss << "vkCreateImage: VkFormat for TILING_OPTIMAL image (" << string_VkFormat(pCreateInfo->format) |
| 255 | << ") does not support requested Image usage type VK_IMAGE_USAGE_COLOR_ATTACHMENT"; |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 256 | skip_call |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 257 | VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, VALIDATION_ERROR_02158, "IMAGE", |
| 258 | "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02158]); |
Mark Lobodzinski | 9d1d6b1 | 2016-05-17 08:42:03 -0600 | [diff] [blame] | 259 | } |
| 260 | if ((pCreateInfo->tiling == VK_IMAGE_TILING_LINEAR) && |
| 261 | ((properties.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) == 0)) { |
| 262 | std::stringstream ss; |
| 263 | ss << "vkCreateImage: VkFormat for TILING_LINEAR image (" << string_VkFormat(pCreateInfo->format) |
| 264 | << ") does not support requested Image usage type VK_IMAGE_USAGE_COLOR_ATTACHMENT"; |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 265 | skip_call |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 266 | VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, VALIDATION_ERROR_02153, "IMAGE", |
| 267 | "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02153]); |
Mark Lobodzinski | 9d1d6b1 | 2016-05-17 08:42:03 -0600 | [diff] [blame] | 268 | } |
| 269 | } |
| 270 | // Validate that format supports usage as depth/stencil attachment |
| 271 | if (pCreateInfo->usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) { |
| 272 | if ((pCreateInfo->tiling == VK_IMAGE_TILING_OPTIMAL) && |
| 273 | ((properties.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0)) { |
| 274 | std::stringstream ss; |
| 275 | ss << "vkCreateImage: VkFormat for TILING_OPTIMAL image (" << string_VkFormat(pCreateInfo->format) |
| 276 | << ") does not support requested Image usage type VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT"; |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 277 | skip_call |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 278 | VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, VALIDATION_ERROR_02159, "IMAGE", |
| 279 | "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02159]); |
Mark Lobodzinski | 9d1d6b1 | 2016-05-17 08:42:03 -0600 | [diff] [blame] | 280 | } |
| 281 | if ((pCreateInfo->tiling == VK_IMAGE_TILING_LINEAR) && |
| 282 | ((properties.linearTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0)) { |
| 283 | std::stringstream ss; |
| 284 | ss << "vkCreateImage: VkFormat for TILING_LINEAR image (" << string_VkFormat(pCreateInfo->format) |
| 285 | << ") does not support requested Image usage type VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT"; |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 286 | skip_call |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 287 | VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, VALIDATION_ERROR_02154, "IMAGE", |
| 288 | "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02154]); |
Mark Lobodzinski | 9d1d6b1 | 2016-05-17 08:42:03 -0600 | [diff] [blame] | 289 | } |
| 290 | } |
| 291 | } else { |
| 292 | skip_call |= |
| 293 | log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 294 | VALIDATION_ERROR_00715, "IMAGE", "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED. %s", |
| 295 | validation_error_map[VALIDATION_ERROR_00715]); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 296 | } |
| 297 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 298 | // Internal call to get format info. Still goes through layers, could potentially go directly to ICD. |
| 299 | phy_dev_data->instance_dispatch_table->GetPhysicalDeviceImageFormatProperties( |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 300 | physicalDevice, pCreateInfo->format, pCreateInfo->imageType, pCreateInfo->tiling, pCreateInfo->usage, pCreateInfo->flags, |
| 301 | &ImageFormatProperties); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 302 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 303 | VkDeviceSize imageGranularity = device_data->physicalDeviceProperties.limits.bufferImageGranularity; |
Mark Lobodzinski | d5a2382 | 2015-11-12 15:14:35 -0700 | [diff] [blame] | 304 | imageGranularity = imageGranularity == 1 ? 0 : imageGranularity; |
| 305 | |
Mark Young | c48c4c1 | 2016-04-11 14:26:49 -0600 | [diff] [blame] | 306 | // Make sure all required dimension are non-zero at least. |
| 307 | bool failedMinSize = false; |
| 308 | switch (pCreateInfo->imageType) { |
| 309 | case VK_IMAGE_TYPE_3D: |
| 310 | if (pCreateInfo->extent.depth == 0) { |
| 311 | failedMinSize = true; |
| 312 | } |
| 313 | // Intentional fall-through |
| 314 | case VK_IMAGE_TYPE_2D: |
| 315 | if (pCreateInfo->extent.height == 0) { |
| 316 | failedMinSize = true; |
| 317 | } |
| 318 | // Intentional fall-through |
| 319 | case VK_IMAGE_TYPE_1D: |
| 320 | if (pCreateInfo->extent.width == 0) { |
| 321 | failedMinSize = true; |
| 322 | } |
| 323 | break; |
| 324 | default: |
| 325 | break; |
| 326 | } |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 327 | // TODO: VALIDATION_ERROR_00716 |
| 328 | // this is *almost* VU 00716, except should not be condidtional on image type - all extents must be non-zero for all types |
Mark Young | c48c4c1 | 2016-04-11 14:26:49 -0600 | [diff] [blame] | 329 | if (failedMinSize) { |
Mark Lobodzinski | 9d1d6b1 | 2016-05-17 08:42:03 -0600 | [diff] [blame] | 330 | skip_call |= |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 331 | log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__, |
| 332 | IMAGE_INVALID_FORMAT_LIMITS_VIOLATION, "Image", |
Mark Young | c48c4c1 | 2016-04-11 14:26:49 -0600 | [diff] [blame] | 333 | "CreateImage extents is 0 for at least one required dimension for image of type %d: " |
| 334 | "Width = %d Height = %d Depth = %d.", |
| 335 | pCreateInfo->imageType, pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth); |
| 336 | } |
| 337 | |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 338 | // TODO: VALIDATION_ERROR_02125 VALIDATION_ERROR_02126 VALIDATION_ERROR_02128 VALIDATION_ERROR_00720 |
| 339 | // All these extent-related VUs should be checked here |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 340 | if ((pCreateInfo->extent.depth > ImageFormatProperties.maxExtent.depth) || |
| 341 | (pCreateInfo->extent.width > ImageFormatProperties.maxExtent.width) || |
Mark Lobodzinski | d5a2382 | 2015-11-12 15:14:35 -0700 | [diff] [blame] | 342 | (pCreateInfo->extent.height > ImageFormatProperties.maxExtent.height)) { |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 343 | skip_call |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, |
| 344 | __LINE__, IMAGE_INVALID_FORMAT_LIMITS_VIOLATION, "Image", |
| 345 | "CreateImage extents exceed allowable limits for format: " |
| 346 | "Width = %d Height = %d Depth = %d: Limits for Width = %d Height = %d Depth = %d for format %s.", |
| 347 | pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth, |
| 348 | ImageFormatProperties.maxExtent.width, ImageFormatProperties.maxExtent.height, |
| 349 | ImageFormatProperties.maxExtent.depth, string_VkFormat(pCreateInfo->format)); |
Mark Lobodzinski | d5a2382 | 2015-11-12 15:14:35 -0700 | [diff] [blame] | 350 | } |
| 351 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 352 | uint64_t totalSize = ((uint64_t)pCreateInfo->extent.width * (uint64_t)pCreateInfo->extent.height * |
| 353 | (uint64_t)pCreateInfo->extent.depth * (uint64_t)pCreateInfo->arrayLayers * |
| 354 | (uint64_t)pCreateInfo->samples * (uint64_t)vk_format_get_size(pCreateInfo->format) + |
| 355 | (uint64_t)imageGranularity) & |
| 356 | ~(uint64_t)imageGranularity; |
Mark Lobodzinski | d5a2382 | 2015-11-12 15:14:35 -0700 | [diff] [blame] | 357 | |
| 358 | if (totalSize > ImageFormatProperties.maxResourceSize) { |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 359 | skip_call |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, |
| 360 | __LINE__, IMAGE_INVALID_FORMAT_LIMITS_VIOLATION, "Image", |
| 361 | "CreateImage resource size exceeds allowable maximum " |
| 362 | "Image resource size = 0x%" PRIxLEAST64 ", maximum resource size = 0x%" PRIxLEAST64 " ", |
| 363 | totalSize, ImageFormatProperties.maxResourceSize); |
Mark Lobodzinski | d5a2382 | 2015-11-12 15:14:35 -0700 | [diff] [blame] | 364 | } |
| 365 | |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 366 | // TODO: VALIDATION_ERROR_02132 |
Mark Lobodzinski | d5a2382 | 2015-11-12 15:14:35 -0700 | [diff] [blame] | 367 | if (pCreateInfo->mipLevels > ImageFormatProperties.maxMipLevels) { |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 368 | skip_call |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, |
| 369 | __LINE__, IMAGE_INVALID_FORMAT_LIMITS_VIOLATION, "Image", |
| 370 | "CreateImage mipLevels=%d exceeds allowable maximum supported by format of %d", pCreateInfo->mipLevels, |
| 371 | ImageFormatProperties.maxMipLevels); |
Mark Lobodzinski | d5a2382 | 2015-11-12 15:14:35 -0700 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | if (pCreateInfo->arrayLayers > ImageFormatProperties.maxArrayLayers) { |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 375 | skip_call |= log_msg( |
| 376 | phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__, |
| 377 | VALIDATION_ERROR_02133, "Image", "CreateImage arrayLayers=%d exceeds allowable maximum supported by format of %d. %s", |
| 378 | pCreateInfo->arrayLayers, ImageFormatProperties.maxArrayLayers, validation_error_map[VALIDATION_ERROR_02133]); |
Mark Lobodzinski | d5a2382 | 2015-11-12 15:14:35 -0700 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | if ((pCreateInfo->samples & ImageFormatProperties.sampleCounts) == 0) { |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 382 | skip_call |= |
| 383 | log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__, |
| 384 | VALIDATION_ERROR_02138, "Image", "CreateImage samples %s is not supported by format 0x%.8X. %s", |
| 385 | string_VkSampleCountFlagBits(pCreateInfo->samples), ImageFormatProperties.sampleCounts, |
| 386 | validation_error_map[VALIDATION_ERROR_02138]); |
Mark Lobodzinski | d5a2382 | 2015-11-12 15:14:35 -0700 | [diff] [blame] | 387 | } |
| 388 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 389 | if (pCreateInfo->initialLayout != VK_IMAGE_LAYOUT_UNDEFINED && pCreateInfo->initialLayout != VK_IMAGE_LAYOUT_PREINITIALIZED) { |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 390 | skip_call |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, |
| 391 | __LINE__, VALIDATION_ERROR_00731, "Image", |
| 392 | "vkCreateImage parameter, pCreateInfo->initialLayout, must be VK_IMAGE_LAYOUT_UNDEFINED or " |
| 393 | "VK_IMAGE_LAYOUT_PREINITIALIZED. %s", |
| 394 | validation_error_map[VALIDATION_ERROR_00731]); |
Jeremy Hayes | ffc8a70 | 2016-03-01 14:01:45 -0700 | [diff] [blame] | 395 | } |
| 396 | |
Mark Lobodzinski | 9d1d6b1 | 2016-05-17 08:42:03 -0600 | [diff] [blame] | 397 | if (!skip_call) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 398 | result = device_data->device_dispatch_table->CreateImage(device, pCreateInfo, pAllocator, pImage); |
Mark Lobodzinski | d5a2382 | 2015-11-12 15:14:35 -0700 | [diff] [blame] | 399 | } |
| 400 | if (result == VK_SUCCESS) { |
Jeremy Hayes | e0ed6a2 | 2016-04-08 09:53:54 -0600 | [diff] [blame] | 401 | std::lock_guard<std::mutex> lock(global_lock); |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 402 | device_data->imageMap[*pImage] = IMAGE_STATE(pCreateInfo); |
Tobin Ehlis | ad8c446 | 2015-09-21 15:20:28 -0600 | [diff] [blame] | 403 | } |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 404 | return result; |
| 405 | } |
| 406 | |
Chia-I Wu | 4935c76 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 407 | VKAPI_ATTR void VKAPI_CALL DestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks *pAllocator) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 408 | layer_data *device_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
Jeremy Hayes | e0ed6a2 | 2016-04-08 09:53:54 -0600 | [diff] [blame] | 409 | std::unique_lock<std::mutex> lock(global_lock); |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 410 | device_data->imageMap.erase(image); |
Jeremy Hayes | e0ed6a2 | 2016-04-08 09:53:54 -0600 | [diff] [blame] | 411 | lock.unlock(); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 412 | device_data->device_dispatch_table->DestroyImage(device, image, pAllocator); |
Tobin Ehlis | ad8c446 | 2015-09-21 15:20:28 -0600 | [diff] [blame] | 413 | } |
| 414 | |
Chia-I Wu | 4935c76 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 415 | VKAPI_ATTR VkResult VKAPI_CALL CreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo, |
Mark Lobodzinski | f2eabc8 | 2016-08-05 11:20:21 -0600 | [diff] [blame] | 416 | const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 417 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
Mark Lobodzinski | f2eabc8 | 2016-08-05 11:20:21 -0600 | [diff] [blame] | 418 | bool skip_call = false; |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 419 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 420 | for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) { |
Mark Lobodzinski | 27ced8b | 2016-08-05 11:30:15 -0600 | [diff] [blame] | 421 | if (pCreateInfo->pAttachments[i].format == VK_FORMAT_UNDEFINED) { |
| 422 | std::stringstream ss; |
| 423 | ss << "vkCreateRenderPass: pCreateInfo->pAttachments[" << i << "].format is VK_FORMAT_UNDEFINED"; |
| 424 | skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 425 | IMAGE_RENDERPASS_INVALID_ATTACHMENT, "IMAGE", "%s", ss.str().c_str()); |
| 426 | } |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 427 | } |
| 428 | |
Mark Lobodzinski | f2eabc8 | 2016-08-05 11:20:21 -0600 | [diff] [blame] | 429 | if (skip_call) { |
Courtney Goeltzenleuchter | 52fee65 | 2015-12-10 16:41:22 -0700 | [diff] [blame] | 430 | return VK_ERROR_VALIDATION_FAILED_EXT; |
Mark Lobodzinski | f2eabc8 | 2016-08-05 11:20:21 -0600 | [diff] [blame] | 431 | } |
Mark Lobodzinski | 2fd634c | 2015-07-29 09:21:22 -0600 | [diff] [blame] | 432 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 433 | VkResult result = my_data->device_dispatch_table->CreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 434 | |
| 435 | return result; |
| 436 | } |
| 437 | |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 438 | VKAPI_ATTR void VKAPI_CALL CmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 439 | const VkClearColorValue *pColor, uint32_t rangeCount, |
| 440 | const VkImageSubresourceRange *pRanges) { |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 441 | bool skipCall = false; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 442 | layer_data *device_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map); |
Jeremy Hayes | a4dc0ac | 2016-03-01 16:51:02 -0700 | [diff] [blame] | 443 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 444 | if (imageLayout != VK_IMAGE_LAYOUT_GENERAL && imageLayout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) { |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 445 | char const str[] = |
| 446 | "vkCmdClearColorImage parameter, imageLayout, must be VK_IMAGE_LAYOUT_GENERAL or VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL"; |
Jeremy Hayes | a4dc0ac | 2016-03-01 16:51:02 -0700 | [diff] [blame] | 447 | skipCall |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 448 | (uint64_t)commandBuffer, __LINE__, VALIDATION_ERROR_01086, "IMAGE", "%s. %s", str, |
| 449 | validation_error_map[VALIDATION_ERROR_01086]); |
Jeremy Hayes | a4dc0ac | 2016-03-01 16:51:02 -0700 | [diff] [blame] | 450 | } |
| 451 | |
Mark Lobodzinski | a5eabe7 | 2015-10-05 17:16:05 -0600 | [diff] [blame] | 452 | // For each range, image aspect must be color only |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 453 | // TODO: this is a 'must' in the spec, so there should be a VU enum for it |
Mark Lobodzinski | a5eabe7 | 2015-10-05 17:16:05 -0600 | [diff] [blame] | 454 | for (uint32_t i = 0; i < rangeCount; i++) { |
| 455 | if (pRanges[i].aspectMask != VK_IMAGE_ASPECT_COLOR_BIT) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 456 | char const str[] = |
| 457 | "vkCmdClearColorImage aspectMasks for all subresource ranges must be set to VK_IMAGE_ASPECT_COLOR_BIT"; |
| 458 | skipCall |= |
| 459 | log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 460 | (uint64_t)commandBuffer, __LINE__, IMAGE_INVALID_IMAGE_ASPECT, "IMAGE", str); |
Mark Lobodzinski | a5eabe7 | 2015-10-05 17:16:05 -0600 | [diff] [blame] | 461 | } |
| 462 | } |
| 463 | |
Tobin Ehlis | f4d352b | 2016-05-19 09:59:30 -0600 | [diff] [blame] | 464 | auto image_state = getImageState(device_data, image); |
| 465 | if (image_state) { |
| 466 | if (vk_format_is_depth_or_stencil(image_state->format)) { |
| 467 | char const str[] = "vkCmdClearColorImage called with depth/stencil image."; |
| 468 | skipCall |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 469 | reinterpret_cast<uint64_t &>(image), __LINE__, VALIDATION_ERROR_01088, "IMAGE", "%s. %s", str, |
| 470 | validation_error_map[VALIDATION_ERROR_01088]); |
Tobin Ehlis | f4d352b | 2016-05-19 09:59:30 -0600 | [diff] [blame] | 471 | } else if (vk_format_is_compressed(image_state->format)) { |
| 472 | char const str[] = "vkCmdClearColorImage called with compressed image."; |
| 473 | skipCall |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 474 | reinterpret_cast<uint64_t &>(image), __LINE__, VALIDATION_ERROR_01088, "IMAGE", "%s. %s", str, |
| 475 | validation_error_map[VALIDATION_ERROR_01088]); |
Tobin Ehlis | f4d352b | 2016-05-19 09:59:30 -0600 | [diff] [blame] | 476 | } |
Tony Barbour | 26434b9 | 2016-06-02 09:43:50 -0600 | [diff] [blame] | 477 | |
| 478 | if (!(image_state->usage & VK_IMAGE_USAGE_TRANSFER_DST_BIT)) { |
| 479 | char const str[] = "vkCmdClearColorImage called with image created without VK_IMAGE_USAGE_TRANSFER_DST_BIT."; |
| 480 | skipCall |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 481 | reinterpret_cast<uint64_t &>(image), __LINE__, VALIDATION_ERROR_01084, "IMAGE", "%s. %s", str, |
| 482 | validation_error_map[VALIDATION_ERROR_01084]); |
Tony Barbour | 26434b9 | 2016-06-02 09:43:50 -0600 | [diff] [blame] | 483 | } |
Tobin Ehlis | f4d352b | 2016-05-19 09:59:30 -0600 | [diff] [blame] | 484 | } |
| 485 | |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 486 | if (!skipCall) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 487 | device_data->device_dispatch_table->CmdClearColorImage(commandBuffer, image, imageLayout, pColor, rangeCount, pRanges); |
Mark Lobodzinski | a5eabe7 | 2015-10-05 17:16:05 -0600 | [diff] [blame] | 488 | } |
| 489 | } |
| 490 | |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 491 | VKAPI_ATTR void VKAPI_CALL CmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 492 | const VkClearDepthStencilValue *pDepthStencil, uint32_t rangeCount, |
| 493 | const VkImageSubresourceRange *pRanges) { |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 494 | bool skipCall = false; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 495 | layer_data *device_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map); |
Mark Lobodzinski | a5eabe7 | 2015-10-05 17:16:05 -0600 | [diff] [blame] | 496 | // For each range, Image aspect must be depth or stencil or both |
| 497 | for (uint32_t i = 0; i < rangeCount; i++) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 498 | if (((pRanges[i].aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) != VK_IMAGE_ASPECT_DEPTH_BIT) && |
| 499 | ((pRanges[i].aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) != VK_IMAGE_ASPECT_STENCIL_BIT)) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 500 | char const str[] = "vkCmdClearDepthStencilImage aspectMasks for all subresource ranges must be " |
| 501 | "set to VK_IMAGE_ASPECT_DEPTH_BIT and/or VK_IMAGE_ASPECT_STENCIL_BIT"; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 502 | skipCall |= |
| 503 | log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 504 | (uint64_t)commandBuffer, __LINE__, IMAGE_INVALID_IMAGE_ASPECT, "IMAGE", str); |
Mark Lobodzinski | a5eabe7 | 2015-10-05 17:16:05 -0600 | [diff] [blame] | 505 | } |
| 506 | } |
| 507 | |
Tobin Ehlis | f4d352b | 2016-05-19 09:59:30 -0600 | [diff] [blame] | 508 | auto image_state = getImageState(device_data, image); |
| 509 | if (image_state && !vk_format_is_depth_or_stencil(image_state->format)) { |
| 510 | char const str[] = "vkCmdClearDepthStencilImage called without a depth/stencil image."; |
| 511 | skipCall |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 512 | reinterpret_cast<uint64_t &>(image), __LINE__, VALIDATION_ERROR_01103, "IMAGE", "%s. %s", str, |
| 513 | validation_error_map[VALIDATION_ERROR_01103]); |
Tobin Ehlis | f4d352b | 2016-05-19 09:59:30 -0600 | [diff] [blame] | 514 | } |
| 515 | |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 516 | if (!skipCall) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 517 | device_data->device_dispatch_table->CmdClearDepthStencilImage(commandBuffer, image, imageLayout, pDepthStencil, rangeCount, |
| 518 | pRanges); |
Mark Lobodzinski | a5eabe7 | 2015-10-05 17:16:05 -0600 | [diff] [blame] | 519 | } |
| 520 | } |
| 521 | |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 522 | // Returns true if [x, xoffset] and [y, yoffset] overlap |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 523 | static bool RangesIntersect(int32_t start, uint32_t start_offset, int32_t end, uint32_t end_offset) { |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 524 | bool result = false; |
| 525 | uint32_t intersection_min = std::max(static_cast<uint32_t>(start), static_cast<uint32_t>(end)); |
| 526 | uint32_t intersection_max = std::min(static_cast<uint32_t>(start) + start_offset, static_cast<uint32_t>(end) + end_offset); |
| 527 | |
| 528 | if (intersection_max > intersection_min) { |
| 529 | result = true; |
| 530 | } |
| 531 | return result; |
| 532 | } |
| 533 | |
| 534 | // Returns true if two VkImageCopy structures overlap |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 535 | static bool RegionIntersects(const VkImageCopy *src, const VkImageCopy *dst, VkImageType type) { |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 536 | bool result = true; |
| 537 | if ((src->srcSubresource.mipLevel == dst->dstSubresource.mipLevel) && |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 538 | (RangesIntersect(src->srcSubresource.baseArrayLayer, src->srcSubresource.layerCount, dst->dstSubresource.baseArrayLayer, |
| 539 | dst->dstSubresource.layerCount))) { |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 540 | |
| 541 | switch (type) { |
| 542 | case VK_IMAGE_TYPE_3D: |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 543 | result &= RangesIntersect(src->srcOffset.z, src->extent.depth, dst->dstOffset.z, dst->extent.depth); |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 544 | // Intentionally fall through to 2D case |
| 545 | case VK_IMAGE_TYPE_2D: |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 546 | result &= RangesIntersect(src->srcOffset.y, src->extent.height, dst->dstOffset.y, dst->extent.height); |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 547 | // Intentionally fall through to 1D case |
| 548 | case VK_IMAGE_TYPE_1D: |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 549 | result &= RangesIntersect(src->srcOffset.x, src->extent.width, dst->dstOffset.x, dst->extent.width); |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 550 | break; |
| 551 | default: |
| 552 | // Unrecognized or new IMAGE_TYPE enums will be caught in parameter_validation |
| 553 | assert(false); |
| 554 | } |
| 555 | } |
| 556 | return result; |
| 557 | } |
| 558 | |
| 559 | // Returns true if offset and extent exceed image extents |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 560 | static bool ExceedsBounds(const VkOffset3D *offset, const VkExtent3D *extent, const IMAGE_STATE *image) { |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 561 | bool result = false; |
| 562 | // Extents/depths cannot be negative but checks left in for clarity |
Mark Lobodzinski | 39573d2 | 2016-10-14 10:59:27 -0600 | [diff] [blame] | 563 | switch (image->imageType) { |
| 564 | case VK_IMAGE_TYPE_3D: // Validate z and depth |
| 565 | if ((offset->z + extent->depth > image->extent.depth) || (offset->z < 0) || |
| 566 | ((offset->z + static_cast<int32_t>(extent->depth)) < 0)) { |
| 567 | result = true; |
| 568 | } |
| 569 | // Intentionally fall through to 2D case to check height |
| 570 | case VK_IMAGE_TYPE_2D: // Validate y and height |
| 571 | if ((offset->y + extent->height > image->extent.height) || (offset->y < 0) || |
| 572 | ((offset->y + static_cast<int32_t>(extent->height)) < 0)) { |
| 573 | result = true; |
| 574 | } |
| 575 | // Intentionally fall through to 1D case to check width |
| 576 | case VK_IMAGE_TYPE_1D: // Validate x and width |
| 577 | if ((offset->x + extent->width > image->extent.width) || (offset->x < 0) || |
| 578 | ((offset->x + static_cast<int32_t>(extent->width)) < 0)) { |
| 579 | result = true; |
| 580 | } |
| 581 | break; |
| 582 | default: |
| 583 | assert(false); |
| 584 | } |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 585 | return result; |
| 586 | } |
| 587 | |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 588 | bool PreCallValidateCmdCopyImage(VkCommandBuffer command_buffer, VkImage src_image, VkImage dst_image, uint32_t region_count, |
| 589 | const VkImageCopy *regions) { |
| 590 | bool skip = false; |
| 591 | layer_data *device_data = get_my_data_ptr(get_dispatch_key(command_buffer), layer_data_map); |
| 592 | auto src_image_entry = getImageState(device_data, src_image); |
| 593 | auto dst_image_entry = getImageState(device_data, dst_image); |
Mark Lobodzinski | a5eabe7 | 2015-10-05 17:16:05 -0600 | [diff] [blame] | 594 | |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 595 | // TODO: This does not cover swapchain-created images. This should fall out when this layer is moved |
| 596 | // into the core_validation layer |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 597 | if (src_image_entry && dst_image_entry) { |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 598 | |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 599 | for (uint32_t i = 0; i < region_count; i++) { |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 600 | |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 601 | if (regions[i].srcSubresource.layerCount == 0) { |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 602 | std::stringstream ss; |
| 603 | ss << "vkCmdCopyImage: number of layers in pRegions[" << i << "] srcSubresource is zero"; |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 604 | skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, |
| 605 | VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, reinterpret_cast<uint64_t &>(command_buffer), |
| 606 | __LINE__, IMAGE_MISMATCHED_IMAGE_ASPECT, "IMAGE", "%s", ss.str().c_str()); |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 607 | } |
| 608 | |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 609 | if (regions[i].dstSubresource.layerCount == 0) { |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 610 | std::stringstream ss; |
| 611 | ss << "vkCmdCopyImage: number of layers in pRegions[" << i << "] dstSubresource is zero"; |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 612 | skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, |
| 613 | VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, reinterpret_cast<uint64_t &>(command_buffer), |
| 614 | __LINE__, IMAGE_MISMATCHED_IMAGE_ASPECT, "IMAGE", "%s", ss.str().c_str()); |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | // For each region the layerCount member of srcSubresource and dstSubresource must match |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 618 | if (regions[i].srcSubresource.layerCount != regions[i].dstSubresource.layerCount) { |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 619 | std::stringstream ss; |
| 620 | ss << "vkCmdCopyImage: number of layers in source and destination subresources for pRegions[" << i |
| 621 | << "] do not match"; |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 622 | skip |= |
Mark Lobodzinski | a9a69ad | 2016-10-14 12:13:33 -0600 | [diff] [blame] | 623 | log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 624 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01198, "IMAGE", "%s. %s", |
Mark Lobodzinski | a9a69ad | 2016-10-14 12:13:33 -0600 | [diff] [blame] | 625 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01198]); |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | // For each region, the aspectMask member of srcSubresource and dstSubresource must match |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 629 | if (regions[i].srcSubresource.aspectMask != regions[i].dstSubresource.aspectMask) { |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 630 | char const str[] = "vkCmdCopyImage: Src and dest aspectMasks for each region must match"; |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 631 | skip |= |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 632 | log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 633 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01197, "IMAGE", "%s. %s", str, |
| 634 | validation_error_map[VALIDATION_ERROR_01197]); |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | // AspectMask must not contain VK_IMAGE_ASPECT_METADATA_BIT |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 638 | if ((regions[i].srcSubresource.aspectMask & VK_IMAGE_ASPECT_METADATA_BIT) || |
| 639 | (regions[i].dstSubresource.aspectMask & VK_IMAGE_ASPECT_METADATA_BIT)) { |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 640 | std::stringstream ss; |
| 641 | ss << "vkCmdCopyImage: pRegions[" << i << "] may not specify aspectMask containing VK_IMAGE_ASPECT_METADATA_BIT"; |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 642 | skip |= |
| 643 | log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 644 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01222, "IMAGE", "%s. %s", |
| 645 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01222]); |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | // For each region, if aspectMask contains VK_IMAGE_ASPECT_COLOR_BIT, it must not contain either of |
| 649 | // VK_IMAGE_ASPECT_DEPTH_BIT or VK_IMAGE_ASPECT_STENCIL_BIT |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 650 | if ((regions[i].srcSubresource.aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) && |
| 651 | (regions[i].srcSubresource.aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT))) { |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 652 | char const str[] = "vkCmdCopyImage aspectMask cannot specify both COLOR and DEPTH/STENCIL aspects"; |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 653 | skip |= |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 654 | log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 655 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01221, "IMAGE", "%s. %s", str, |
| 656 | validation_error_map[VALIDATION_ERROR_01221]); |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 657 | } |
| 658 | |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 659 | // If either of the calling command's src_image or dst_image parameters are of VkImageType VK_IMAGE_TYPE_3D, |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 660 | // the baseArrayLayer and layerCount members of both srcSubresource and dstSubresource must be 0 and 1, respectively |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 661 | if (((src_image_entry->imageType == VK_IMAGE_TYPE_3D) || (dst_image_entry->imageType == VK_IMAGE_TYPE_3D)) && |
| 662 | ((regions[i].srcSubresource.baseArrayLayer != 0) || (regions[i].srcSubresource.layerCount != 1) || |
| 663 | (regions[i].dstSubresource.baseArrayLayer != 0) || (regions[i].dstSubresource.layerCount != 1))) { |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 664 | std::stringstream ss; |
| 665 | ss << "vkCmdCopyImage: src or dstImage type was IMAGE_TYPE_3D, but in subRegion[" << i |
| 666 | << "] baseArrayLayer was not zero or layerCount was not 1."; |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 667 | skip |= |
| 668 | log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 669 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01199, "IMAGE", "%s. %s", |
| 670 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01199]); |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | // MipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 674 | if (regions[i].srcSubresource.mipLevel >= src_image_entry->mipLevels) { |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 675 | std::stringstream ss; |
| 676 | ss << "vkCmdCopyImage: pRegions[" << i |
| 677 | << "] specifies a src mipLevel greater than the number specified when the srcImage was created."; |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 678 | skip |= |
| 679 | log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 680 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01223, "IMAGE", "%s. %s", |
| 681 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01223]); |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 682 | } |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 683 | if (regions[i].dstSubresource.mipLevel >= dst_image_entry->mipLevels) { |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 684 | std::stringstream ss; |
| 685 | ss << "vkCmdCopyImage: pRegions[" << i |
| 686 | << "] specifies a dst mipLevel greater than the number specified when the dstImage was created."; |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 687 | skip |= |
| 688 | log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 689 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01223, "IMAGE", "%s. %s", |
| 690 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01223]); |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | // (baseArrayLayer + layerCount) must be less than or equal to the arrayLayers specified in VkImageCreateInfo when the |
| 694 | // image was created |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 695 | if ((regions[i].srcSubresource.baseArrayLayer + regions[i].srcSubresource.layerCount) > src_image_entry->arraySize) { |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 696 | std::stringstream ss; |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 697 | ss << "vkCmdCopyImage: srcImage arrayLayers was " << src_image_entry->arraySize << " but subRegion[" << i |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 698 | << "] baseArrayLayer + layerCount is " |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 699 | << (regions[i].srcSubresource.baseArrayLayer + regions[i].srcSubresource.layerCount); |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 700 | skip |= |
| 701 | log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 702 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01224, "IMAGE", "%s. %s", |
| 703 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01224]); |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 704 | } |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 705 | if ((regions[i].dstSubresource.baseArrayLayer + regions[i].dstSubresource.layerCount) > dst_image_entry->arraySize) { |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 706 | std::stringstream ss; |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 707 | ss << "vkCmdCopyImage: dstImage arrayLayers was " << dst_image_entry->arraySize << " but subRegion[" << i |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 708 | << "] baseArrayLayer + layerCount is " |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 709 | << (regions[i].dstSubresource.baseArrayLayer + regions[i].dstSubresource.layerCount); |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 710 | skip |= |
| 711 | log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 712 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01224, "IMAGE", "%s. %s", |
| 713 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01224]); |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 714 | } |
| 715 | |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 716 | // The source region specified by a given element of regions must be a region that is contained within srcImage |
| 717 | if (ExceedsBounds(®ions[i].srcOffset, ®ions[i].extent, src_image_entry)) { |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 718 | std::stringstream ss; |
| 719 | ss << "vkCmdCopyImage: srcSubResource in pRegions[" << i << "] exceeds extents srcImage was created with"; |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 720 | skip |= |
Mark Lobodzinski | 8ea6eb0 | 2016-10-14 11:40:31 -0600 | [diff] [blame] | 721 | log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 722 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01175, "IMAGE", "%s. %s", |
Tobin Ehlis | 15edfa8 | 2016-10-18 07:31:22 -0600 | [diff] [blame] | 723 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01175]); |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 724 | } |
| 725 | |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 726 | // The destination region specified by a given element of regions must be a region that is contained within dst_image |
| 727 | if (ExceedsBounds(®ions[i].dstOffset, ®ions[i].extent, dst_image_entry)) { |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 728 | std::stringstream ss; |
| 729 | ss << "vkCmdCopyImage: dstSubResource in pRegions[" << i << "] exceeds extents dstImage was created with"; |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 730 | skip |= |
Mark Lobodzinski | 8ea6eb0 | 2016-10-14 11:40:31 -0600 | [diff] [blame] | 731 | log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 732 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01176, "IMAGE", "%s. %s", |
Mark Lobodzinski | 8ea6eb0 | 2016-10-14 11:40:31 -0600 | [diff] [blame] | 733 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01176]); |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 734 | } |
| 735 | |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 736 | // The union of all source regions, and the union of all destination regions, specified by the elements of regions, |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 737 | // must not overlap in memory |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 738 | if (src_image == dst_image) { |
| 739 | for (uint32_t j = 0; j < region_count; j++) { |
| 740 | if (RegionIntersects(®ions[i], ®ions[j], src_image_entry->imageType)) { |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 741 | std::stringstream ss; |
| 742 | ss << "vkCmdCopyImage: pRegions[" << i << "] src overlaps with pRegions[" << j << "]."; |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 743 | skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 744 | VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 745 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01177, "IMAGE", |
| 746 | "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01177]); |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 747 | } |
| 748 | } |
| 749 | } |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 750 | } |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 751 | |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 752 | // The formats of src_image and dst_image must be compatible. Formats are considered compatible if their texel size in bytes |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 753 | // is the same between both formats. For example, VK_FORMAT_R8G8B8A8_UNORM is compatible with VK_FORMAT_R32_UINT because |
| 754 | // because both texels are 4 bytes in size. Depth/stencil formats must match exactly. |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 755 | if (vk_format_is_depth_or_stencil(src_image_entry->format) || vk_format_is_depth_or_stencil(dst_image_entry->format)) { |
| 756 | if (src_image_entry->format != dst_image_entry->format) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 757 | char const str[] = "vkCmdCopyImage called with unmatched source and dest image depth/stencil formats."; |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 758 | skip |= |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 759 | log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 760 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, IMAGE_MISMATCHED_IMAGE_FORMAT, "IMAGE", str); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 761 | } |
| 762 | } else { |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 763 | size_t srcSize = vk_format_get_size(src_image_entry->format); |
| 764 | size_t destSize = vk_format_get_size(dst_image_entry->format); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 765 | if (srcSize != destSize) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 766 | char const str[] = "vkCmdCopyImage called with unmatched source and dest image format sizes."; |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 767 | skip |= |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 768 | log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 769 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01184, "IMAGE", "%s. %s", str, |
Tobin Ehlis | 15edfa8 | 2016-10-18 07:31:22 -0600 | [diff] [blame] | 770 | validation_error_map[VALIDATION_ERROR_01184]); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 771 | } |
| 772 | } |
| 773 | } |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 774 | return skip; |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 775 | } |
| 776 | |
Chia-I Wu | 4935c76 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 777 | VKAPI_ATTR void VKAPI_CALL CmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, |
| 778 | VkImageLayout srcImageLayout, VkImage dstImage, |
| 779 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 780 | const VkImageCopy *pRegions) { |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 781 | |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 782 | bool skip = false; |
Mark Lobodzinski | b2ad702 | 2016-03-29 17:10:14 -0600 | [diff] [blame] | 783 | layer_data *device_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map); |
| 784 | |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 785 | skip = PreCallValidateCmdCopyImage(commandBuffer, srcImage, dstImage, regionCount, pRegions); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 786 | |
Mark Lobodzinski | a9920fb | 2016-10-14 13:09:48 -0600 | [diff] [blame] | 787 | if (!skip) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 788 | device_data->device_dispatch_table->CmdCopyImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, |
| 789 | regionCount, pRegions); |
Mark Lobodzinski | a5eabe7 | 2015-10-05 17:16:05 -0600 | [diff] [blame] | 790 | } |
| 791 | } |
| 792 | |
Chia-I Wu | 4935c76 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 793 | VKAPI_ATTR void VKAPI_CALL CmdClearAttachments(VkCommandBuffer commandBuffer, uint32_t attachmentCount, |
| 794 | const VkClearAttachment *pAttachments, uint32_t rectCount, |
| 795 | const VkClearRect *pRects) { |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 796 | bool skipCall = false; |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 797 | VkImageAspectFlags aspectMask; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 798 | layer_data *device_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map); |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 799 | for (uint32_t i = 0; i < attachmentCount; i++) { |
| 800 | aspectMask = pAttachments[i].aspectMask; |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 801 | if (0 == aspectMask) { |
| 802 | skipCall |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 803 | VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, __LINE__, |
| 804 | VALIDATION_ERROR_01128, "IMAGE", "%s", validation_error_map[VALIDATION_ERROR_01128]); |
| 805 | } else if (aspectMask & VK_IMAGE_ASPECT_METADATA_BIT) { |
| 806 | skipCall |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 807 | VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, __LINE__, |
| 808 | VALIDATION_ERROR_01126, "IMAGE", "%s", validation_error_map[VALIDATION_ERROR_01126]); |
| 809 | } else if (aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) { |
| 810 | if ((aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) || (aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 811 | char const str[] = |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 812 | "vkCmdClearAttachments aspectMask [%d] must set only VK_IMAGE_ASPECT_COLOR_BIT of a color attachment. %s"; |
| 813 | skipCall |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 814 | VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, __LINE__, |
| 815 | VALIDATION_ERROR_01125, "IMAGE", str, i, validation_error_map[VALIDATION_ERROR_01125]); |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 816 | } |
| 817 | } else { |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 818 | // Having eliminated all other possibilities, image aspect must be depth or stencil or both |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 819 | if (((aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) != VK_IMAGE_ASPECT_DEPTH_BIT) && |
| 820 | ((aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) != VK_IMAGE_ASPECT_STENCIL_BIT)) { |
| 821 | char const str[] = "vkCmdClearAttachments aspectMask [%d] must be set to VK_IMAGE_ASPECT_DEPTH_BIT and/or " |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 822 | "VK_IMAGE_ASPECT_STENCIL_BIT. %s"; |
| 823 | skipCall |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 824 | VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, __LINE__, |
| 825 | VALIDATION_ERROR_01127, "IMAGE", str, i, validation_error_map[VALIDATION_ERROR_01127]); |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 826 | } |
| 827 | } |
| 828 | } |
| 829 | |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 830 | if (!skipCall) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 831 | device_data->device_dispatch_table->CmdClearAttachments(commandBuffer, attachmentCount, pAttachments, rectCount, pRects); |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 832 | } |
| 833 | } |
| 834 | |
Mark Lobodzinski | 576d839 | 2016-11-22 10:44:37 -0700 | [diff] [blame] | 835 | static bool ValidateBufferImageCopyData(layer_data *dev_data, uint32_t regionCount, const VkBufferImageCopy *pRegions, |
| 836 | VkImage image, const char *function) { |
Mark Lobodzinski | a0efcdd | 2016-08-19 08:50:15 -0600 | [diff] [blame] | 837 | bool skip = false; |
| 838 | |
| 839 | for (uint32_t i = 0; i < regionCount; i++) { |
| 840 | |
| 841 | auto image_info = getImageState(dev_data, image); |
| 842 | if (image_info) { |
Mark Lobodzinski | 1bda889 | 2016-11-22 14:46:39 -0700 | [diff] [blame] | 843 | |
| 844 | if ((image_info->imageType == VK_IMAGE_TYPE_1D) || (image_info->imageType == VK_IMAGE_TYPE_2D)) { |
| 845 | if ((pRegions[i].imageOffset.z != 0) || (pRegions[i].imageExtent.depth != 1)) { |
| 846 | skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 847 | reinterpret_cast<uint64_t &>(image), __LINE__, VALIDATION_ERROR_01269, "IMAGE", |
| 848 | "%s(): pRegion[%d] imageOffset.z is %d and imageExtent.depth is %d. These must be 0 and 1, " |
| 849 | "respectively. %s", |
| 850 | function, i, pRegions[i].imageOffset.z, pRegions[i].imageExtent.depth, |
| 851 | validation_error_map[VALIDATION_ERROR_01269]); |
| 852 | } |
| 853 | } |
| 854 | |
Mark Lobodzinski | a0efcdd | 2016-08-19 08:50:15 -0600 | [diff] [blame] | 855 | // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size |
| 856 | auto texel_size = vk_format_get_size(image_info->format); |
| 857 | if (vk_safe_modulo(pRegions[i].bufferOffset, texel_size) != 0) { |
| 858 | skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 576d839 | 2016-11-22 10:44:37 -0700 | [diff] [blame] | 859 | reinterpret_cast<uint64_t &>(image), __LINE__, VALIDATION_ERROR_01263, "IMAGE", |
Mark Lobodzinski | a0efcdd | 2016-08-19 08:50:15 -0600 | [diff] [blame] | 860 | "%s(): pRegion[%d] bufferOffset 0x%" PRIxLEAST64 |
Mark Lobodzinski | 576d839 | 2016-11-22 10:44:37 -0700 | [diff] [blame] | 861 | " must be a multiple of this format's texel size (" PRINTF_SIZE_T_SPECIFIER "). %s", |
| 862 | function, i, pRegions[i].bufferOffset, texel_size, validation_error_map[VALIDATION_ERROR_01263]); |
Mark Lobodzinski | a0efcdd | 2016-08-19 08:50:15 -0600 | [diff] [blame] | 863 | } |
Mark Lobodzinski | 1bda889 | 2016-11-22 14:46:39 -0700 | [diff] [blame] | 864 | |
Mark Lobodzinski | a0efcdd | 2016-08-19 08:50:15 -0600 | [diff] [blame] | 865 | // BufferOffset must be a multiple of 4 |
| 866 | if (vk_safe_modulo(pRegions[i].bufferOffset, 4) != 0) { |
| 867 | skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 576d839 | 2016-11-22 10:44:37 -0700 | [diff] [blame] | 868 | reinterpret_cast<uint64_t &>(image), __LINE__, VALIDATION_ERROR_01264, "IMAGE", |
| 869 | "%s(): pRegion[%d] bufferOffset 0x%" PRIxLEAST64 " must be a multiple of 4. %s", function, i, |
| 870 | pRegions[i].bufferOffset, validation_error_map[VALIDATION_ERROR_01264]); |
Mark Lobodzinski | a0efcdd | 2016-08-19 08:50:15 -0600 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent |
| 874 | if ((pRegions[i].bufferRowLength != 0) && (pRegions[i].bufferRowLength < pRegions[i].imageExtent.width)) { |
| 875 | skip |= log_msg( |
| 876 | dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 576d839 | 2016-11-22 10:44:37 -0700 | [diff] [blame] | 877 | reinterpret_cast<uint64_t &>(image), __LINE__, VALIDATION_ERROR_01265, "IMAGE", |
| 878 | "%s(): pRegion[%d] bufferRowLength (%d) must be zero or greater-than-or-equal-to imageExtent.width (%d). %s", |
| 879 | function, i, pRegions[i].bufferRowLength, pRegions[i].imageExtent.width, |
| 880 | validation_error_map[VALIDATION_ERROR_01265]); |
Mark Lobodzinski | a0efcdd | 2016-08-19 08:50:15 -0600 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent |
| 884 | if ((pRegions[i].bufferImageHeight != 0) && (pRegions[i].bufferImageHeight < pRegions[i].imageExtent.height)) { |
| 885 | skip |= log_msg( |
| 886 | dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 576d839 | 2016-11-22 10:44:37 -0700 | [diff] [blame] | 887 | reinterpret_cast<uint64_t &>(image), __LINE__, VALIDATION_ERROR_01266, "IMAGE", |
| 888 | "%s(): pRegion[%d] bufferImageHeight (%d) must be zero or greater-than-or-equal-to imageExtent.height (%d). %s", |
| 889 | function, i, pRegions[i].bufferImageHeight, pRegions[i].imageExtent.height, |
| 890 | validation_error_map[VALIDATION_ERROR_01266]); |
Mark Lobodzinski | a0efcdd | 2016-08-19 08:50:15 -0600 | [diff] [blame] | 891 | } |
Mark Lobodzinski | 040142c | 2016-11-22 11:18:46 -0700 | [diff] [blame] | 892 | |
| 893 | const int num_bits = sizeof(VkFlags) * CHAR_BIT; |
Mark Lobodzinski | 3702e93 | 2016-11-22 11:40:48 -0700 | [diff] [blame] | 894 | std::bitset<num_bits> aspect_mask_bits(pRegions[i].imageSubresource.aspectMask); |
Mark Lobodzinski | 040142c | 2016-11-22 11:18:46 -0700 | [diff] [blame] | 895 | if (aspect_mask_bits.count() != 1) { |
| 896 | skip |= |
| 897 | log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 898 | reinterpret_cast<uint64_t &>(image), __LINE__, VALIDATION_ERROR_01280, "IMAGE", |
| 899 | "%s: aspectMasks for imageSubresource in each region must have only a single bit set. %s", function, |
| 900 | validation_error_map[VALIDATION_ERROR_01280]); |
| 901 | } |
Mark Lobodzinski | a0efcdd | 2016-08-19 08:50:15 -0600 | [diff] [blame] | 902 | } |
| 903 | } |
| 904 | |
| 905 | return skip; |
| 906 | } |
| 907 | |
Mark Lobodzinski | 3702e93 | 2016-11-22 11:40:48 -0700 | [diff] [blame] | 908 | static bool PreCallValidateCmdCopyImageToBuffer(layer_data *dev_data, VkImage srcImage, uint32_t regionCount, |
Mark Lobodzinski | 39b8328 | 2016-11-22 09:33:23 -0700 | [diff] [blame] | 909 | const VkBufferImageCopy *pRegions, const char *func_name) { |
Mark Lobodzinski | 3702e93 | 2016-11-22 11:40:48 -0700 | [diff] [blame] | 910 | return ValidateBufferImageCopyData(dev_data, regionCount, pRegions, srcImage, "vkCmdCopyImageToBuffer"); |
Mark Lobodzinski | 39b8328 | 2016-11-22 09:33:23 -0700 | [diff] [blame] | 911 | } |
Mark Lobodzinski | a5eabe7 | 2015-10-05 17:16:05 -0600 | [diff] [blame] | 912 | |
Mark Lobodzinski | 39b8328 | 2016-11-22 09:33:23 -0700 | [diff] [blame] | 913 | VKAPI_ATTR void VKAPI_CALL CmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 914 | VkBuffer dstBuffer, uint32_t regionCount, const VkBufferImageCopy *pRegions) { |
| 915 | layer_data *device_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map); |
| 916 | |
Mark Lobodzinski | 3702e93 | 2016-11-22 11:40:48 -0700 | [diff] [blame] | 917 | if (!PreCallValidateCmdCopyImageToBuffer(device_data, srcImage, regionCount, pRegions, "vkCmdCopyImageToBuffer()")) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 918 | device_data->device_dispatch_table->CmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, |
| 919 | pRegions); |
Mark Lobodzinski | a5eabe7 | 2015-10-05 17:16:05 -0600 | [diff] [blame] | 920 | } |
| 921 | } |
| 922 | |
Mark Lobodzinski | 3702e93 | 2016-11-22 11:40:48 -0700 | [diff] [blame] | 923 | static bool PreCallValidateCmdCopyBufferToImage(layer_data *dev_data, VkImage dstImage, uint32_t regionCount, |
Mark Lobodzinski | 39b8328 | 2016-11-22 09:33:23 -0700 | [diff] [blame] | 924 | const VkBufferImageCopy *pRegions, const char *func_name) { |
Mark Lobodzinski | 3702e93 | 2016-11-22 11:40:48 -0700 | [diff] [blame] | 925 | return ValidateBufferImageCopyData(dev_data, regionCount, pRegions, dstImage, "vkCmdCopyBufferToImage"); |
Mark Lobodzinski | 39b8328 | 2016-11-22 09:33:23 -0700 | [diff] [blame] | 926 | } |
Mark Lobodzinski | a5eabe7 | 2015-10-05 17:16:05 -0600 | [diff] [blame] | 927 | |
Mark Lobodzinski | 39b8328 | 2016-11-22 09:33:23 -0700 | [diff] [blame] | 928 | VKAPI_ATTR void VKAPI_CALL CmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 929 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 930 | const VkBufferImageCopy *pRegions) { |
| 931 | layer_data *device_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map); |
| 932 | |
Mark Lobodzinski | 3702e93 | 2016-11-22 11:40:48 -0700 | [diff] [blame] | 933 | if (!PreCallValidateCmdCopyBufferToImage(device_data, dstImage, regionCount, pRegions, "vkCmdCopyBufferToImage()")) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 934 | device_data->device_dispatch_table->CmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, |
| 935 | pRegions); |
Mark Lobodzinski | a5eabe7 | 2015-10-05 17:16:05 -0600 | [diff] [blame] | 936 | } |
| 937 | } |
| 938 | |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 939 | VKAPI_ATTR void VKAPI_CALL CmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 940 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 941 | const VkImageBlit *pRegions, VkFilter filter) { |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 942 | bool skipCall = false; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 943 | layer_data *device_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 944 | |
Mark Lobodzinski | 1af172a | 2016-08-16 11:51:12 -0600 | [diff] [blame] | 945 | // Warn for zero-sized regions |
| 946 | for (uint32_t i = 0; i < regionCount; i++) { |
| 947 | if ((pRegions[i].srcOffsets[0].x == pRegions[i].srcOffsets[1].x) || |
| 948 | (pRegions[i].srcOffsets[0].y == pRegions[i].srcOffsets[1].y) || |
| 949 | (pRegions[i].srcOffsets[0].z == pRegions[i].srcOffsets[1].z)) { |
| 950 | std::stringstream ss; |
| 951 | ss << "vkCmdBlitImage: pRegions[" << i << "].srcOffsets specify a zero-volume area."; |
| 952 | skipCall |= log_msg(device_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 953 | VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, reinterpret_cast<uint64_t>(commandBuffer), __LINE__, |
| 954 | IMAGE_INVALID_EXTENTS, "IMAGE", "%s", ss.str().c_str()); |
Mark Lobodzinski | 1af172a | 2016-08-16 11:51:12 -0600 | [diff] [blame] | 955 | } |
| 956 | if ((pRegions[i].dstOffsets[0].x == pRegions[i].dstOffsets[1].x) || |
| 957 | (pRegions[i].dstOffsets[0].y == pRegions[i].dstOffsets[1].y) || |
| 958 | (pRegions[i].dstOffsets[0].z == pRegions[i].dstOffsets[1].z)) { |
| 959 | std::stringstream ss; |
| 960 | ss << "vkCmdBlitImage: pRegions[" << i << "].dstOffsets specify a zero-volume area."; |
| 961 | skipCall |= log_msg(device_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 962 | VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, reinterpret_cast<uint64_t>(commandBuffer), __LINE__, |
| 963 | IMAGE_INVALID_EXTENTS, "IMAGE", "%s", ss.str().c_str()); |
Mark Lobodzinski | 1af172a | 2016-08-16 11:51:12 -0600 | [diff] [blame] | 964 | } |
| 965 | } |
| 966 | |
Tobin Ehlis | f4d352b | 2016-05-19 09:59:30 -0600 | [diff] [blame] | 967 | auto srcImageEntry = getImageState(device_data, srcImage); |
| 968 | auto dstImageEntry = getImageState(device_data, dstImage); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 969 | |
Tobin Ehlis | f4d352b | 2016-05-19 09:59:30 -0600 | [diff] [blame] | 970 | if (srcImageEntry && dstImageEntry) { |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 971 | |
Tobin Ehlis | f4d352b | 2016-05-19 09:59:30 -0600 | [diff] [blame] | 972 | VkFormat srcFormat = srcImageEntry->format; |
| 973 | VkFormat dstFormat = dstImageEntry->format; |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 974 | |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 975 | // Validate consistency for unsigned formats |
| 976 | if (vk_format_is_uint(srcFormat) != vk_format_is_uint(dstFormat)) { |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 977 | std::stringstream ss; |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 978 | ss << "vkCmdBlitImage: If one of srcImage and dstImage images has unsigned integer format, " |
| 979 | << "the other one must also have unsigned integer format. " |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 980 | << "Source format is " << string_VkFormat(srcFormat) << " Destination format is " << string_VkFormat(dstFormat); |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 981 | skipCall |= |
| 982 | log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 983 | (uint64_t)commandBuffer, __LINE__, VALIDATION_ERROR_02191, "IMAGE", "%s. %s", ss.str().c_str(), |
| 984 | validation_error_map[VALIDATION_ERROR_02191]); |
| 985 | } |
| 986 | |
| 987 | // Validate consistency for signed formats |
| 988 | if (vk_format_is_sint(srcFormat) != vk_format_is_sint(dstFormat)) { |
| 989 | std::stringstream ss; |
| 990 | ss << "vkCmdBlitImage: If one of srcImage and dstImage images has signed integer format, " |
| 991 | << "the other one must also have signed integer format. " |
| 992 | << "Source format is " << string_VkFormat(srcFormat) << " Destination format is " << string_VkFormat(dstFormat); |
| 993 | skipCall |= |
| 994 | log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 995 | (uint64_t)commandBuffer, __LINE__, VALIDATION_ERROR_02190, "IMAGE", "%s. %s", ss.str().c_str(), |
| 996 | validation_error_map[VALIDATION_ERROR_02190]); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 997 | } |
| 998 | |
| 999 | // Validate aspect bits and formats for depth/stencil images |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1000 | if (vk_format_is_depth_or_stencil(srcFormat) || vk_format_is_depth_or_stencil(dstFormat)) { |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 1001 | if (srcFormat != dstFormat) { |
| 1002 | std::stringstream ss; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1003 | ss << "vkCmdBlitImage: If one of srcImage and dstImage images has a format of depth, stencil or depth " |
| 1004 | << "stencil, the other one must have exactly the same format. " |
| 1005 | << "Source format is " << string_VkFormat(srcFormat) << " Destination format is " << string_VkFormat(dstFormat); |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1006 | skipCall |= |
| 1007 | log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 1008 | (uint64_t)commandBuffer, __LINE__, VALIDATION_ERROR_02192, "IMAGE", "%s. %s", ss.str().c_str(), |
| 1009 | validation_error_map[VALIDATION_ERROR_02192]); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 1010 | } |
| 1011 | |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 1012 | // TODO: Confirm that all these checks are intended to be nested under depth/stencil only |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 1013 | for (uint32_t i = 0; i < regionCount; i++) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1014 | if (pRegions[i].srcSubresource.layerCount == 0) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1015 | char const str[] = "vkCmdBlitImage: number of layers in source subresource is zero"; |
| 1016 | // TODO: Verify against Valid Use section of spec, if this case yields undefined results, then it's an error |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1017 | skipCall |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1018 | VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, __LINE__, |
| 1019 | IMAGE_MISMATCHED_IMAGE_ASPECT, "IMAGE", str); |
Jeremy Hayes | 148bab2 | 2015-10-28 13:01:39 -0600 | [diff] [blame] | 1020 | } |
| 1021 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1022 | if (pRegions[i].dstSubresource.layerCount == 0) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1023 | char const str[] = "vkCmdBlitImage: number of layers in destination subresource is zero"; |
| 1024 | // TODO: Verify against Valid Use section of spec, if this case yields undefined results, then it's an error |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1025 | skipCall |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1026 | VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, __LINE__, |
| 1027 | IMAGE_MISMATCHED_IMAGE_ASPECT, "IMAGE", str); |
Jeremy Hayes | 148bab2 | 2015-10-28 13:01:39 -0600 | [diff] [blame] | 1028 | } |
| 1029 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1030 | if (pRegions[i].srcSubresource.layerCount != pRegions[i].dstSubresource.layerCount) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1031 | char const str[] = "vkCmdBlitImage: number of layers in source and destination subresources must match"; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1032 | skipCall |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1033 | VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, __LINE__, |
| 1034 | IMAGE_MISMATCHED_IMAGE_ASPECT, "IMAGE", str); |
Jeremy Hayes | 148bab2 | 2015-10-28 13:01:39 -0600 | [diff] [blame] | 1035 | } |
| 1036 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1037 | VkImageAspectFlags srcAspect = pRegions[i].srcSubresource.aspectMask; |
| 1038 | VkImageAspectFlags dstAspect = pRegions[i].dstSubresource.aspectMask; |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 1039 | |
| 1040 | if (srcAspect != dstAspect) { |
| 1041 | std::stringstream ss; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1042 | ss << "vkCmdBlitImage: Image aspects of depth/stencil images should match"; |
| 1043 | // TODO: Verify against Valid Use section of spec, if this case yields undefined results, then it's an error |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1044 | skipCall |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1045 | VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, __LINE__, |
| 1046 | IMAGE_INVALID_IMAGE_ASPECT, "IMAGE", "%s", ss.str().c_str()); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 1047 | } |
| 1048 | if (vk_format_is_depth_and_stencil(srcFormat)) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1049 | if ((srcAspect != VK_IMAGE_ASPECT_DEPTH_BIT) && (srcAspect != VK_IMAGE_ASPECT_STENCIL_BIT)) { |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 1050 | std::stringstream ss; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1051 | ss << "vkCmdBlitImage: Combination depth/stencil image formats must have only one of " |
| 1052 | "VK_IMAGE_ASPECT_DEPTH_BIT " |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1053 | << "and VK_IMAGE_ASPECT_STENCIL_BIT set in srcImage and dstImage"; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1054 | skipCall |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1055 | VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, __LINE__, |
| 1056 | IMAGE_INVALID_IMAGE_ASPECT, "IMAGE", "%s", ss.str().c_str()); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 1057 | } |
| 1058 | } else if (vk_format_is_stencil_only(srcFormat)) { |
| 1059 | if (srcAspect != VK_IMAGE_ASPECT_STENCIL_BIT) { |
| 1060 | std::stringstream ss; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1061 | ss << "vkCmdBlitImage: Stencil-only image formats must have only the VK_IMAGE_ASPECT_STENCIL_BIT " |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1062 | << "set in both the srcImage and dstImage"; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1063 | skipCall |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1064 | VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, __LINE__, |
| 1065 | IMAGE_INVALID_IMAGE_ASPECT, "IMAGE", "%s", ss.str().c_str()); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 1066 | } |
| 1067 | } else if (vk_format_is_depth_only(srcFormat)) { |
| 1068 | if (srcAspect != VK_IMAGE_ASPECT_DEPTH_BIT) { |
| 1069 | std::stringstream ss; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1070 | ss << "vkCmdBlitImage: Depth-only image formats must have only the VK_IMAGE_ASPECT_DEPTH " |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1071 | << "set in both the srcImage and dstImage"; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1072 | skipCall |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1073 | VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, __LINE__, |
| 1074 | IMAGE_INVALID_IMAGE_ASPECT, "IMAGE", "%s", ss.str().c_str()); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 1075 | } |
| 1076 | } |
| 1077 | } |
| 1078 | } |
| 1079 | |
| 1080 | // Validate filter |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 1081 | if (vk_format_is_depth_or_stencil(srcFormat) && (filter != VK_FILTER_NEAREST)) { |
| 1082 | std::stringstream ss; |
| 1083 | ss << "vkCmdBlitImage: If the format of srcImage is a depth, stencil, or depth stencil " |
| 1084 | << "then filter must be VK_FILTER_NEAREST."; |
| 1085 | skipCall |= |
| 1086 | log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1087 | (uint64_t)commandBuffer, __LINE__, VALIDATION_ERROR_02193, "IMAGE", "%s. %s", ss.str().c_str(), |
| 1088 | validation_error_map[VALIDATION_ERROR_02193]); |
| 1089 | } |
| 1090 | if (vk_format_is_int(srcFormat) && (filter != VK_FILTER_NEAREST)) { |
| 1091 | std::stringstream ss; |
| 1092 | ss << "vkCmdBlitImage: If the format of srcImage is an integer-based format " |
| 1093 | << "then filter must be VK_FILTER_NEAREST."; |
| 1094 | skipCall |= |
| 1095 | log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1096 | (uint64_t)commandBuffer, __LINE__, IMAGE_INVALID_FILTER, "IMAGE", "%s", ss.str().c_str()); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 1097 | } |
| 1098 | } |
Mark Lobodzinski | a5eabe7 | 2015-10-05 17:16:05 -0600 | [diff] [blame] | 1099 | |
Tony Barbour | f830910 | 2016-05-05 10:50:21 -0600 | [diff] [blame] | 1100 | if (!skipCall) { |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 1101 | device_data->device_dispatch_table->CmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, |
| 1102 | regionCount, pRegions, filter); |
Tony Barbour | f830910 | 2016-05-05 10:50:21 -0600 | [diff] [blame] | 1103 | } |
Mark Lobodzinski | a5eabe7 | 2015-10-05 17:16:05 -0600 | [diff] [blame] | 1104 | } |
| 1105 | |
Chia-I Wu | 4935c76 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 1106 | VKAPI_ATTR void VKAPI_CALL |
| 1107 | CmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 1108 | VkDependencyFlags dependencyFlags, uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 1109 | uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 1110 | uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier *pImageMemoryBarriers) { |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 1111 | bool skipCall = false; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1112 | layer_data *device_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map); |
Jeremy Hayes | 01b3889 | 2015-11-17 18:19:55 -0700 | [diff] [blame] | 1113 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1114 | for (uint32_t i = 0; i < imageMemoryBarrierCount; ++i) { |
| 1115 | VkImageMemoryBarrier const *const barrier = (VkImageMemoryBarrier const *const) & pImageMemoryBarriers[i]; |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 1116 | // TODO: add VALIDATION_ERROR_00309 (sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) here |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1117 | if (barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) { |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 1118 | // TODO: this check should include VALIDATION_ERROR_00301 and VALIDATION_ERROR_00316 |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1119 | if (barrier->subresourceRange.layerCount == 0) { |
Jeremy Hayes | 01b3889 | 2015-11-17 18:19:55 -0700 | [diff] [blame] | 1120 | std::stringstream ss; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1121 | ss << "vkCmdPipelineBarrier called with 0 in ppMemoryBarriers[" << i << "]->subresourceRange.layerCount."; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1122 | skipCall |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, |
| 1123 | __LINE__, IMAGE_INVALID_IMAGE_RESOURCE, "IMAGE", "%s", ss.str().c_str()); |
Jeremy Hayes | 01b3889 | 2015-11-17 18:19:55 -0700 | [diff] [blame] | 1124 | } |
| 1125 | } |
| 1126 | } |
| 1127 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1128 | if (skipCall) { |
Jeremy Hayes | 01b3889 | 2015-11-17 18:19:55 -0700 | [diff] [blame] | 1129 | return; |
| 1130 | } |
| 1131 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1132 | device_data->device_dispatch_table->CmdPipelineBarrier(commandBuffer, srcStageMask, dstStageMask, dependencyFlags, |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1133 | memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, |
| 1134 | pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers); |
Jeremy Hayes | 01b3889 | 2015-11-17 18:19:55 -0700 | [diff] [blame] | 1135 | } |
| 1136 | |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 1137 | VKAPI_ATTR void VKAPI_CALL CmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 1138 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 1139 | const VkImageResolve *pRegions) { |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 1140 | bool skipCall = false; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1141 | layer_data *device_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map); |
Tobin Ehlis | f4d352b | 2016-05-19 09:59:30 -0600 | [diff] [blame] | 1142 | auto srcImageEntry = getImageState(device_data, srcImage); |
| 1143 | auto dstImageEntry = getImageState(device_data, dstImage); |
Mark Lobodzinski | a5eabe7 | 2015-10-05 17:16:05 -0600 | [diff] [blame] | 1144 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1145 | // For each region, the number of layers in the image subresource should not be zero |
Mark Lobodzinski | a5eabe7 | 2015-10-05 17:16:05 -0600 | [diff] [blame] | 1146 | // For each region, src and dest image aspect must be color only |
| 1147 | for (uint32_t i = 0; i < regionCount; i++) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1148 | if (pRegions[i].srcSubresource.layerCount == 0) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1149 | char const str[] = "vkCmdResolveImage: number of layers in source subresource is zero"; |
| 1150 | // TODO: Verify against Valid Use section of spec. Generally if something yield an undefined result, it's invalid/error |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1151 | skipCall |= |
| 1152 | log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1153 | (uint64_t)commandBuffer, __LINE__, IMAGE_MISMATCHED_IMAGE_ASPECT, "IMAGE", str); |
Jeremy Hayes | 148bab2 | 2015-10-28 13:01:39 -0600 | [diff] [blame] | 1154 | } |
| 1155 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1156 | if (pRegions[i].dstSubresource.layerCount == 0) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1157 | char const str[] = "vkCmdResolveImage: number of layers in destination subresource is zero"; |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1158 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1159 | // TODO: Verify against Valid Use section of spec. Generally if something yield an undefined result, it's invalid/error |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1160 | skipCall |= |
| 1161 | log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1162 | (uint64_t)commandBuffer, __LINE__, IMAGE_MISMATCHED_IMAGE_ASPECT, "IMAGE", str); |
Jeremy Hayes | 148bab2 | 2015-10-28 13:01:39 -0600 | [diff] [blame] | 1163 | } |
| 1164 | |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 1165 | // TODO: VALIDATION_ERROR_01339 |
| 1166 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1167 | if ((pRegions[i].srcSubresource.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT) || |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1168 | (pRegions[i].dstSubresource.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT)) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1169 | char const str[] = |
| 1170 | "vkCmdResolveImage: src and dest aspectMasks for each region must specify only VK_IMAGE_ASPECT_COLOR_BIT"; |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 1171 | skipCall |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1172 | VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, __LINE__, |
| 1173 | VALIDATION_ERROR_01338, "IMAGE", "%s. %s", str, validation_error_map[VALIDATION_ERROR_01338]); |
Mark Lobodzinski | a5eabe7 | 2015-10-05 17:16:05 -0600 | [diff] [blame] | 1174 | } |
| 1175 | } |
| 1176 | |
Tobin Ehlis | f4d352b | 2016-05-19 09:59:30 -0600 | [diff] [blame] | 1177 | if (srcImageEntry && dstImageEntry) { |
| 1178 | if (srcImageEntry->format != dstImageEntry->format) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1179 | char const str[] = "vkCmdResolveImage called with unmatched source and dest formats."; |
| 1180 | skipCall |= |
| 1181 | log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1182 | (uint64_t)commandBuffer, __LINE__, IMAGE_MISMATCHED_IMAGE_FORMAT, "IMAGE", str); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 1183 | } |
Tobin Ehlis | f4d352b | 2016-05-19 09:59:30 -0600 | [diff] [blame] | 1184 | if (srcImageEntry->imageType != dstImageEntry->imageType) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1185 | char const str[] = "vkCmdResolveImage called with unmatched source and dest image types."; |
| 1186 | skipCall |= |
| 1187 | log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1188 | (uint64_t)commandBuffer, __LINE__, IMAGE_MISMATCHED_IMAGE_TYPE, "IMAGE", str); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 1189 | } |
Tobin Ehlis | f4d352b | 2016-05-19 09:59:30 -0600 | [diff] [blame] | 1190 | if (srcImageEntry->samples == VK_SAMPLE_COUNT_1_BIT) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1191 | char const str[] = "vkCmdResolveImage called with source sample count less than 2."; |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 1192 | skipCall |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1193 | VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, __LINE__, |
| 1194 | VALIDATION_ERROR_01320, "IMAGE", "%s. %s", str, validation_error_map[VALIDATION_ERROR_01320]); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 1195 | } |
Tobin Ehlis | f4d352b | 2016-05-19 09:59:30 -0600 | [diff] [blame] | 1196 | if (dstImageEntry->samples != VK_SAMPLE_COUNT_1_BIT) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1197 | char const str[] = "vkCmdResolveImage called with dest sample count greater than 1."; |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 1198 | skipCall |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1199 | VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, __LINE__, |
| 1200 | VALIDATION_ERROR_01321, "IMAGE", "%s. %s", str, validation_error_map[VALIDATION_ERROR_01321]); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 1201 | } |
| 1202 | } |
| 1203 | |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 1204 | if (!skipCall) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1205 | device_data->device_dispatch_table->CmdResolveImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, |
| 1206 | regionCount, pRegions); |
Mark Lobodzinski | a5eabe7 | 2015-10-05 17:16:05 -0600 | [diff] [blame] | 1207 | } |
| 1208 | } |
| 1209 | |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 1210 | VKAPI_ATTR void VKAPI_CALL GetImageSubresourceLayout(VkDevice device, VkImage image, const VkImageSubresource *pSubresource, |
| 1211 | VkSubresourceLayout *pLayout) { |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 1212 | bool skipCall = false; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1213 | layer_data *device_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1214 | VkFormat format; |
Mark Lobodzinski | a5eabe7 | 2015-10-05 17:16:05 -0600 | [diff] [blame] | 1215 | |
Tobin Ehlis | f4d352b | 2016-05-19 09:59:30 -0600 | [diff] [blame] | 1216 | auto imageEntry = getImageState(device_data, image); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 1217 | |
| 1218 | // Validate that image aspects match formats |
Tobin Ehlis | f4d352b | 2016-05-19 09:59:30 -0600 | [diff] [blame] | 1219 | if (imageEntry) { |
| 1220 | format = imageEntry->format; |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 1221 | if (vk_format_is_color(format)) { |
Chia-I Wu | 52b07e7 | 2015-10-27 19:55:05 +0800 | [diff] [blame] | 1222 | if (pSubresource->aspectMask != VK_IMAGE_ASPECT_COLOR_BIT) { |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 1223 | std::stringstream ss; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1224 | ss << "vkGetImageSubresourceLayout: For color formats, the aspectMask field of VkImageSubresource must be " |
| 1225 | "VK_IMAGE_ASPECT_COLOR."; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1226 | skipCall |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 1227 | (uint64_t)image, __LINE__, VALIDATION_ERROR_00741, "IMAGE", "%s. %s", ss.str().c_str(), |
| 1228 | validation_error_map[VALIDATION_ERROR_00741]); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 1229 | } |
| 1230 | } else if (vk_format_is_depth_or_stencil(format)) { |
Chia-I Wu | 52b07e7 | 2015-10-27 19:55:05 +0800 | [diff] [blame] | 1231 | if ((pSubresource->aspectMask != VK_IMAGE_ASPECT_DEPTH_BIT) && |
| 1232 | (pSubresource->aspectMask != VK_IMAGE_ASPECT_STENCIL_BIT)) { |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 1233 | std::stringstream ss; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1234 | ss << "vkGetImageSubresourceLayout: For depth/stencil formats, the aspectMask selects either the depth or stencil " |
| 1235 | "image aspectMask."; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1236 | skipCall |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | 34df4cb | 2016-12-01 16:43:06 -0700 | [diff] [blame] | 1237 | (uint64_t)image, __LINE__, VALIDATION_ERROR_00741, "IMAGE", "%s. %s", ss.str().c_str(), |
| 1238 | validation_error_map[VALIDATION_ERROR_00741]); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 1239 | } |
| 1240 | } |
| 1241 | } |
| 1242 | |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 1243 | if (!skipCall) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1244 | device_data->device_dispatch_table->GetImageSubresourceLayout(device, image, pSubresource, pLayout); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 1245 | } |
Mark Lobodzinski | a5eabe7 | 2015-10-05 17:16:05 -0600 | [diff] [blame] | 1246 | } |
| 1247 | |
Chia-I Wu | 4935c76 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 1248 | VKAPI_ATTR void VKAPI_CALL |
| 1249 | GetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties *pProperties) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1250 | layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
| 1251 | phy_dev_data->instance_dispatch_table->GetPhysicalDeviceProperties(physicalDevice, pProperties); |
Mark Lobodzinski | d5a2382 | 2015-11-12 15:14:35 -0700 | [diff] [blame] | 1252 | } |
| 1253 | |
Chia-I Wu | b02600c | 2016-05-20 07:11:22 +0800 | [diff] [blame] | 1254 | VKAPI_ATTR VkResult VKAPI_CALL |
| 1255 | EnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties *pProperties) { |
| 1256 | return util_GetLayerProperties(1, &global_layer, pCount, pProperties); |
| 1257 | } |
| 1258 | |
| 1259 | VKAPI_ATTR VkResult VKAPI_CALL |
| 1260 | EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount, VkLayerProperties *pProperties) { |
| 1261 | return util_GetLayerProperties(1, &global_layer, pCount, pProperties); |
| 1262 | } |
| 1263 | |
| 1264 | VKAPI_ATTR VkResult VKAPI_CALL |
| 1265 | EnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount, VkExtensionProperties *pProperties) { |
| 1266 | if (pLayerName && !strcmp(pLayerName, global_layer.layerName)) |
| 1267 | return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties); |
| 1268 | |
| 1269 | return VK_ERROR_LAYER_NOT_PRESENT; |
| 1270 | } |
| 1271 | |
Chia-I Wu | 4935c76 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 1272 | VKAPI_ATTR VkResult VKAPI_CALL EnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, |
| 1273 | const char *pLayerName, uint32_t *pCount, |
| 1274 | VkExtensionProperties *pProperties) { |
Chia-I Wu | eec9a31 | 2016-04-28 11:21:49 +0800 | [diff] [blame] | 1275 | // Image does not have any physical device extensions |
Chia-I Wu | 3f32622 | 2016-04-28 14:21:13 +0800 | [diff] [blame] | 1276 | if (pLayerName && !strcmp(pLayerName, global_layer.layerName)) |
Chia-I Wu | eec9a31 | 2016-04-28 11:21:49 +0800 | [diff] [blame] | 1277 | return util_GetExtensionProperties(0, NULL, pCount, pProperties); |
Chia-I Wu | 3f32622 | 2016-04-28 14:21:13 +0800 | [diff] [blame] | 1278 | |
| 1279 | assert(physicalDevice); |
| 1280 | |
| 1281 | dispatch_key key = get_dispatch_key(physicalDevice); |
| 1282 | layer_data *my_data = get_my_data_ptr(key, layer_data_map); |
| 1283 | VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table; |
| 1284 | return pTable->EnumerateDeviceExtensionProperties(physicalDevice, NULL, pCount, pProperties); |
Chia-I Wu | eec9a31 | 2016-04-28 11:21:49 +0800 | [diff] [blame] | 1285 | } |
| 1286 | |
Chia-I Wu | 64df8ed | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 1287 | static PFN_vkVoidFunction |
Chia-I Wu | 428eba0 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 1288 | intercept_core_instance_command(const char *name); |
| 1289 | static PFN_vkVoidFunction |
Chia-I Wu | 64df8ed | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 1290 | intercept_core_device_command(const char *name); |
Tobin Ehlis | b74f6ab | 2015-10-29 14:19:18 -0600 | [diff] [blame] | 1291 | |
Chia-I Wu | 64df8ed | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 1292 | VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetDeviceProcAddr(VkDevice device, const char *funcName) { |
| 1293 | PFN_vkVoidFunction proc = intercept_core_device_command(funcName); |
| 1294 | if (proc) |
| 1295 | return proc; |
| 1296 | |
| 1297 | assert(device); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 1298 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1299 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 1300 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1301 | VkLayerDispatchTable *pTable = my_data->device_dispatch_table; |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 1302 | { |
Tobin Ehlis | b74f6ab | 2015-10-29 14:19:18 -0600 | [diff] [blame] | 1303 | if (pTable->GetDeviceProcAddr == NULL) |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 1304 | return NULL; |
Tobin Ehlis | b74f6ab | 2015-10-29 14:19:18 -0600 | [diff] [blame] | 1305 | return pTable->GetDeviceProcAddr(device, funcName); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 1306 | } |
| 1307 | } |
| 1308 | |
Chia-I Wu | 4935c76 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 1309 | VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetInstanceProcAddr(VkInstance instance, const char *funcName) { |
Chia-I Wu | 428eba0 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 1310 | PFN_vkVoidFunction proc = intercept_core_instance_command(funcName); |
Chia-I Wu | f89922c | 2016-04-28 15:16:59 +0800 | [diff] [blame] | 1311 | if (!proc) |
| 1312 | proc = intercept_core_device_command(funcName); |
Chia-I Wu | 428eba0 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 1313 | if (proc) |
| 1314 | return proc; |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 1315 | |
Chia-I Wu | f89922c | 2016-04-28 15:16:59 +0800 | [diff] [blame] | 1316 | assert(instance); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 1317 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 1318 | |
Chia-I Wu | f89922c | 2016-04-28 15:16:59 +0800 | [diff] [blame] | 1319 | proc = debug_report_get_instance_proc_addr(my_data->report_data, funcName); |
| 1320 | if (proc) |
| 1321 | return proc; |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 1322 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 1323 | VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 1324 | if (pTable->GetInstanceProcAddr == NULL) |
| 1325 | return NULL; |
| 1326 | return pTable->GetInstanceProcAddr(instance, funcName); |
Jeremy Hayes | 9cc3158 | 2015-06-18 10:12:39 -0600 | [diff] [blame] | 1327 | } |
Chia-I Wu | eec9a31 | 2016-04-28 11:21:49 +0800 | [diff] [blame] | 1328 | |
Chia-I Wu | 64df8ed | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 1329 | static PFN_vkVoidFunction |
Chia-I Wu | 428eba0 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 1330 | intercept_core_instance_command(const char *name) { |
| 1331 | static const struct { |
| 1332 | const char *name; |
| 1333 | PFN_vkVoidFunction proc; |
| 1334 | } core_instance_commands[] = { |
| 1335 | { "vkGetInstanceProcAddr", reinterpret_cast<PFN_vkVoidFunction>(GetInstanceProcAddr) }, |
| 1336 | { "vkCreateInstance", reinterpret_cast<PFN_vkVoidFunction>(CreateInstance) }, |
| 1337 | { "vkDestroyInstance", reinterpret_cast<PFN_vkVoidFunction>(DestroyInstance) }, |
| 1338 | { "vkCreateDevice", reinterpret_cast<PFN_vkVoidFunction>(CreateDevice) }, |
Chia-I Wu | b02600c | 2016-05-20 07:11:22 +0800 | [diff] [blame] | 1339 | { "vkEnumerateInstanceLayerProperties", reinterpret_cast<PFN_vkVoidFunction>(EnumerateInstanceLayerProperties) }, |
| 1340 | { "vkEnumerateDeviceLayerProperties", reinterpret_cast<PFN_vkVoidFunction>(EnumerateDeviceLayerProperties) }, |
| 1341 | { "vkEnumerateInstanceExtensionProperties", reinterpret_cast<PFN_vkVoidFunction>(EnumerateInstanceExtensionProperties) }, |
Chia-I Wu | 428eba0 | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 1342 | { "vkEnumerateDeviceExtensionProperties", reinterpret_cast<PFN_vkVoidFunction>(EnumerateDeviceExtensionProperties) }, |
| 1343 | { "vkGetPhysicalDeviceProperties", reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceProperties) }, |
| 1344 | }; |
| 1345 | |
| 1346 | for (size_t i = 0; i < ARRAY_SIZE(core_instance_commands); i++) { |
| 1347 | if (!strcmp(core_instance_commands[i].name, name)) |
| 1348 | return core_instance_commands[i].proc; |
| 1349 | } |
| 1350 | |
| 1351 | return nullptr; |
| 1352 | } |
| 1353 | |
| 1354 | static PFN_vkVoidFunction |
Chia-I Wu | 64df8ed | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 1355 | intercept_core_device_command(const char *name) { |
| 1356 | static const struct { |
| 1357 | const char *name; |
| 1358 | PFN_vkVoidFunction proc; |
| 1359 | } core_device_commands[] = { |
Tobin Ehlis | 1623987 | 2016-10-26 10:42:49 -0600 | [diff] [blame] | 1360 | {"vkGetDeviceProcAddr", reinterpret_cast<PFN_vkVoidFunction>(GetDeviceProcAddr)}, |
| 1361 | {"vkDestroyDevice", reinterpret_cast<PFN_vkVoidFunction>(DestroyDevice)}, |
| 1362 | {"vkCreateImage", reinterpret_cast<PFN_vkVoidFunction>(CreateImage)}, |
| 1363 | {"vkDestroyImage", reinterpret_cast<PFN_vkVoidFunction>(DestroyImage)}, |
| 1364 | {"vkCreateRenderPass", reinterpret_cast<PFN_vkVoidFunction>(CreateRenderPass)}, |
| 1365 | {"vkCmdClearColorImage", reinterpret_cast<PFN_vkVoidFunction>(CmdClearColorImage)}, |
| 1366 | {"vkCmdClearDepthStencilImage", reinterpret_cast<PFN_vkVoidFunction>(CmdClearDepthStencilImage)}, |
| 1367 | {"vkCmdClearAttachments", reinterpret_cast<PFN_vkVoidFunction>(CmdClearAttachments)}, |
| 1368 | {"vkCmdCopyImage", reinterpret_cast<PFN_vkVoidFunction>(CmdCopyImage)}, |
| 1369 | {"vkCmdCopyImageToBuffer", reinterpret_cast<PFN_vkVoidFunction>(CmdCopyImageToBuffer)}, |
| 1370 | {"vkCmdCopyBufferToImage", reinterpret_cast<PFN_vkVoidFunction>(CmdCopyBufferToImage)}, |
| 1371 | {"vkCmdBlitImage", reinterpret_cast<PFN_vkVoidFunction>(CmdBlitImage)}, |
| 1372 | {"vkCmdPipelineBarrier", reinterpret_cast<PFN_vkVoidFunction>(CmdPipelineBarrier)}, |
| 1373 | {"vkCmdResolveImage", reinterpret_cast<PFN_vkVoidFunction>(CmdResolveImage)}, |
| 1374 | {"vkGetImageSubresourceLayout", reinterpret_cast<PFN_vkVoidFunction>(GetImageSubresourceLayout)}, |
Chia-I Wu | 64df8ed | 2016-04-28 14:38:57 +0800 | [diff] [blame] | 1375 | }; |
| 1376 | |
| 1377 | for (size_t i = 0; i < ARRAY_SIZE(core_device_commands); i++) { |
| 1378 | if (!strcmp(core_device_commands[i].name, name)) |
| 1379 | return core_device_commands[i].proc; |
| 1380 | } |
| 1381 | |
| 1382 | return nullptr; |
| 1383 | } |
| 1384 | |
Chia-I Wu | aacb0fc | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 1385 | } // namespace image |
| 1386 | |
| 1387 | // vk_layer_logging.h expects these to be defined |
| 1388 | |
| 1389 | VKAPI_ATTR VkResult VKAPI_CALL |
| 1390 | vkCreateDebugReportCallbackEXT(VkInstance instance, const VkDebugReportCallbackCreateInfoEXT *pCreateInfo, |
| 1391 | const VkAllocationCallbacks *pAllocator, VkDebugReportCallbackEXT *pMsgCallback) { |
Chia-I Wu | 4935c76 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 1392 | return image::CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback); |
Chia-I Wu | aacb0fc | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 1393 | } |
| 1394 | |
| 1395 | VKAPI_ATTR void VKAPI_CALL |
| 1396 | vkDestroyDebugReportCallbackEXT(VkInstance instance, |
| 1397 | VkDebugReportCallbackEXT msgCallback, |
| 1398 | const VkAllocationCallbacks *pAllocator) { |
Chia-I Wu | 4935c76 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 1399 | image::DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator); |
Chia-I Wu | aacb0fc | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 1400 | } |
| 1401 | |
| 1402 | VKAPI_ATTR void VKAPI_CALL |
| 1403 | vkDebugReportMessageEXT(VkInstance instance, VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t object, |
| 1404 | size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg) { |
Chia-I Wu | 4935c76 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 1405 | image::DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg); |
Chia-I Wu | aacb0fc | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 1406 | } |
| 1407 | |
Chia-I Wu | b02600c | 2016-05-20 07:11:22 +0800 | [diff] [blame] | 1408 | // loader-layer interface v0, just wrappers since there is only a layer |
Chia-I Wu | aacb0fc | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 1409 | |
Chia-I Wu | eec9a31 | 2016-04-28 11:21:49 +0800 | [diff] [blame] | 1410 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL |
| 1411 | vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount, VkExtensionProperties *pProperties) { |
Chia-I Wu | b02600c | 2016-05-20 07:11:22 +0800 | [diff] [blame] | 1412 | return image::EnumerateInstanceExtensionProperties(pLayerName, pCount, pProperties); |
Chia-I Wu | eec9a31 | 2016-04-28 11:21:49 +0800 | [diff] [blame] | 1413 | } |
| 1414 | |
| 1415 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL |
| 1416 | vkEnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties *pProperties) { |
Chia-I Wu | b02600c | 2016-05-20 07:11:22 +0800 | [diff] [blame] | 1417 | return image::EnumerateInstanceLayerProperties(pCount, pProperties); |
Chia-I Wu | eec9a31 | 2016-04-28 11:21:49 +0800 | [diff] [blame] | 1418 | } |
| 1419 | |
| 1420 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL |
| 1421 | vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount, VkLayerProperties *pProperties) { |
Chia-I Wu | b02600c | 2016-05-20 07:11:22 +0800 | [diff] [blame] | 1422 | // the layer command handles VK_NULL_HANDLE just fine internally |
| 1423 | assert(physicalDevice == VK_NULL_HANDLE); |
| 1424 | return image::EnumerateDeviceLayerProperties(VK_NULL_HANDLE, pCount, pProperties); |
Chia-I Wu | aacb0fc | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 1425 | } |
| 1426 | |
| 1427 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, |
| 1428 | const char *pLayerName, uint32_t *pCount, |
| 1429 | VkExtensionProperties *pProperties) { |
Chia-I Wu | b02600c | 2016-05-20 07:11:22 +0800 | [diff] [blame] | 1430 | // the layer command handles VK_NULL_HANDLE just fine internally |
| 1431 | assert(physicalDevice == VK_NULL_HANDLE); |
Chia-I Wu | 3f32622 | 2016-04-28 14:21:13 +0800 | [diff] [blame] | 1432 | return image::EnumerateDeviceExtensionProperties(VK_NULL_HANDLE, pLayerName, pCount, pProperties); |
Chia-I Wu | aacb0fc | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 1433 | } |
| 1434 | |
| 1435 | VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char *funcName) { |
Chia-I Wu | 4935c76 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 1436 | return image::GetDeviceProcAddr(dev, funcName); |
Chia-I Wu | aacb0fc | 2016-04-28 11:27:46 +0800 | [diff] [blame] | 1437 | } |
| 1438 | |
| 1439 | VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) { |
Chia-I Wu | 4935c76 | 2016-04-28 14:01:30 +0800 | [diff] [blame] | 1440 | return image::GetInstanceProcAddr(instance, funcName); |
Chia-I Wu | eec9a31 | 2016-04-28 11:21:49 +0800 | [diff] [blame] | 1441 | } |