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