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