Mark Lobodzinski | 91e50bf | 2020-01-14 09:55:11 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2015-2020 The Khronos Group Inc. |
| 2 | * Copyright (c) 2015-2020 Valve Corporation |
| 3 | * Copyright (c) 2015-2020 LunarG, Inc. |
Camden | eaa86ea | 2019-07-26 11:00:09 -0600 | [diff] [blame] | 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | * |
| 17 | * Author: Camden Stocker <camden@lunarg.com> |
| 18 | */ |
| 19 | |
Camden | 3231dcc | 2019-08-05 11:28:57 -0600 | [diff] [blame] | 20 | #include "best_practices.h" |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 21 | #include "layer_chassis_dispatch.h" |
Camden Stocker | 0a660ce | 2019-08-27 15:30:40 -0600 | [diff] [blame] | 22 | #include "best_practices_error_enums.h" |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 23 | |
| 24 | #include <string> |
| 25 | #include <iomanip> |
| 26 | |
| 27 | // get the API name is proper format |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 28 | std::string BestPractices::GetAPIVersionName(uint32_t version) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 29 | std::stringstream version_name; |
| 30 | uint32_t major = VK_VERSION_MAJOR(version); |
| 31 | uint32_t minor = VK_VERSION_MINOR(version); |
| 32 | uint32_t patch = VK_VERSION_PATCH(version); |
| 33 | |
| 34 | version_name << major << "." << minor << "." << patch << " (0x" << std::setfill('0') << std::setw(8) << std::hex << version |
| 35 | << ")"; |
| 36 | |
| 37 | return version_name.str(); |
| 38 | } |
| 39 | |
| 40 | bool BestPractices::PreCallValidateCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 41 | VkInstance* pInstance) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 42 | bool skip = false; |
| 43 | |
| 44 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
| 45 | if (white_list(pCreateInfo->ppEnabledExtensionNames[i], kDeviceExtensionNames)) { |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 46 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 47 | kVUID_BestPractices_CreateInstance_ExtensionMismatch, |
| 48 | "vkCreateInstance(): Attempting to enable Device Extension %s at CreateInstance time.", |
| 49 | pCreateInfo->ppEnabledExtensionNames[i]); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 50 | } |
| 51 | } |
| 52 | |
| 53 | return skip; |
| 54 | } |
| 55 | |
| 56 | void BestPractices::PreCallRecordCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, |
| 57 | VkInstance* pInstance) { |
| 58 | instance_api_version = pCreateInfo->pApplicationInfo->apiVersion; |
| 59 | } |
| 60 | |
| 61 | bool BestPractices::PreCallValidateCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* pCreateInfo, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 62 | const VkAllocationCallbacks* pAllocator, VkDevice* pDevice) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 63 | bool skip = false; |
| 64 | |
| 65 | // get API version of physical device passed when creating device. |
| 66 | VkPhysicalDeviceProperties physical_device_properties{}; |
| 67 | DispatchGetPhysicalDeviceProperties(physicalDevice, &physical_device_properties); |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 68 | auto device_api_version = physical_device_properties.apiVersion; |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 69 | |
| 70 | // check api versions and warn if instance api Version is higher than version on device. |
| 71 | if (instance_api_version > device_api_version) { |
| 72 | std::string inst_api_name = GetAPIVersionName(instance_api_version); |
| 73 | std::string dev_api_name = GetAPIVersionName(device_api_version); |
| 74 | |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 75 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 76 | kVUID_BestPractices_CreateDevice_API_Mismatch, |
| 77 | "vkCreateDevice(): API Version of current instance, %s is higher than API Version on device, %s", |
| 78 | inst_api_name.c_str(), dev_api_name.c_str()); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
| 82 | if (white_list(pCreateInfo->ppEnabledExtensionNames[i], kInstanceExtensionNames)) { |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 83 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 84 | kVUID_BestPractices_CreateInstance_ExtensionMismatch, |
| 85 | "vkCreateDevice(): Attempting to enable Instance Extension %s at CreateDevice time.", |
| 86 | pCreateInfo->ppEnabledExtensionNames[i]); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 87 | } |
| 88 | } |
| 89 | |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 90 | auto pd_state = GetPhysicalDeviceState(physicalDevice); |
Cort | a48da1d | 2019-09-20 18:59:07 +0200 | [diff] [blame] | 91 | if ((pd_state->vkGetPhysicalDeviceFeaturesState == UNCALLED) && (pCreateInfo->pEnabledFeatures != NULL)) { |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 92 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 93 | kVUID_BestPractices_CreateDevice_PDFeaturesNotCalled, |
| 94 | "vkCreateDevice() called before getting physical device features from vkGetPhysicalDeviceFeatures()."); |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 95 | } |
| 96 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 97 | return skip; |
| 98 | } |
| 99 | |
| 100 | bool BestPractices::PreCallValidateCreateBuffer(VkDevice device, const VkBufferCreateInfo* pCreateInfo, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 101 | const VkAllocationCallbacks* pAllocator, VkBuffer* pBuffer) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 102 | bool skip = false; |
| 103 | |
| 104 | if ((pCreateInfo->queueFamilyIndexCount > 1) && (pCreateInfo->sharingMode == VK_SHARING_MODE_EXCLUSIVE)) { |
| 105 | std::stringstream bufferHex; |
| 106 | bufferHex << "0x" << std::hex << HandleToUint64(pBuffer); |
| 107 | |
| 108 | skip |= |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 109 | log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 110 | kVUID_BestPractices_SharingModeExclusive, |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 111 | "Warning: Buffer (%s) specifies a sharing mode of VK_SHARING_MODE_EXCLUSIVE while specifying multiple queues " |
| 112 | "(queueFamilyIndexCount of %" PRIu32 ").", |
| 113 | bufferHex.str().c_str(), pCreateInfo->queueFamilyIndexCount); |
| 114 | } |
| 115 | |
| 116 | return skip; |
| 117 | } |
| 118 | |
| 119 | bool BestPractices::PreCallValidateCreateImage(VkDevice device, const VkImageCreateInfo* pCreateInfo, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 120 | const VkAllocationCallbacks* pAllocator, VkImage* pImage) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 121 | bool skip = false; |
| 122 | |
| 123 | if ((pCreateInfo->queueFamilyIndexCount > 1) && (pCreateInfo->sharingMode == VK_SHARING_MODE_EXCLUSIVE)) { |
| 124 | std::stringstream imageHex; |
| 125 | imageHex << "0x" << std::hex << HandleToUint64(pImage); |
| 126 | |
| 127 | skip |= |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 128 | log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 129 | kVUID_BestPractices_SharingModeExclusive, |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 130 | "Warning: Image (%s) specifies a sharing mode of VK_SHARING_MODE_EXCLUSIVE while specifying multiple queues " |
| 131 | "(queueFamilyIndexCount of %" PRIu32 ").", |
| 132 | imageHex.str().c_str(), pCreateInfo->queueFamilyIndexCount); |
| 133 | } |
| 134 | |
| 135 | return skip; |
| 136 | } |
| 137 | |
| 138 | bool BestPractices::PreCallValidateCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR* pCreateInfo, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 139 | const VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pSwapchain) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 140 | bool skip = false; |
| 141 | |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 142 | auto physical_device_state = GetPhysicalDeviceState(); |
| 143 | |
| 144 | if (physical_device_state->vkGetPhysicalDeviceSurfaceCapabilitiesKHRState == UNCALLED) { |
| 145 | skip |= log_msg( |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 146 | report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 147 | kVUID_BestPractices_Swapchain_GetSurfaceNotCalled, |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 148 | "vkCreateSwapchainKHR() called before getting surface capabilities from vkGetPhysicalDeviceSurfaceCapabilitiesKHR()."); |
| 149 | } |
| 150 | |
| 151 | if (physical_device_state->vkGetPhysicalDeviceSurfacePresentModesKHRState != QUERY_DETAILS) { |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 152 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 153 | kVUID_BestPractices_Swapchain_GetSurfaceNotCalled, |
| 154 | "vkCreateSwapchainKHR() called before getting surface present mode(s) from " |
| 155 | "vkGetPhysicalDeviceSurfacePresentModesKHR()."); |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | if (physical_device_state->vkGetPhysicalDeviceSurfaceFormatsKHRState != QUERY_DETAILS) { |
| 159 | skip |= |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 160 | log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 161 | kVUID_BestPractices_Swapchain_GetSurfaceNotCalled, |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 162 | "vkCreateSwapchainKHR() called before getting surface format(s) from vkGetPhysicalDeviceSurfaceFormatsKHR()."); |
| 163 | } |
| 164 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 165 | if ((pCreateInfo->queueFamilyIndexCount > 1) && (pCreateInfo->imageSharingMode == VK_SHARING_MODE_EXCLUSIVE)) { |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 166 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 167 | kVUID_BestPractices_SharingModeExclusive, |
| 168 | "Warning: A Swapchain is being created which specifies a sharing mode of VK_SHARING_MODE_EXCULSIVE while " |
| 169 | "specifying multiple queues (queueFamilyIndexCount of %" PRIu32 ").", |
| 170 | pCreateInfo->queueFamilyIndexCount); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | return skip; |
| 174 | } |
| 175 | |
| 176 | bool BestPractices::PreCallValidateCreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount, |
| 177 | const VkSwapchainCreateInfoKHR* pCreateInfos, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 178 | const VkAllocationCallbacks* pAllocator, |
| 179 | VkSwapchainKHR* pSwapchains) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 180 | bool skip = false; |
| 181 | |
| 182 | for (uint32_t i = 0; i < swapchainCount; i++) { |
| 183 | if ((pCreateInfos[i].queueFamilyIndexCount > 1) && (pCreateInfos[i].imageSharingMode == VK_SHARING_MODE_EXCLUSIVE)) { |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 184 | skip |= |
| 185 | log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 186 | kVUID_BestPractices_SharingModeExclusive, |
| 187 | "Warning: A shared swapchain (index %" PRIu32 |
| 188 | ") is being created which specifies a sharing mode of VK_SHARING_MODE_EXCLUSIVE while specifying multiple " |
| 189 | "queues (queueFamilyIndexCount of %" PRIu32 ").", |
| 190 | i, pCreateInfos[i].queueFamilyIndexCount); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 191 | } |
| 192 | } |
| 193 | |
| 194 | return skip; |
| 195 | } |
| 196 | |
| 197 | bool BestPractices::PreCallValidateCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 198 | const VkAllocationCallbacks* pAllocator, VkRenderPass* pRenderPass) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 199 | bool skip = false; |
| 200 | |
| 201 | for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) { |
| 202 | VkFormat format = pCreateInfo->pAttachments[i].format; |
| 203 | if (pCreateInfo->pAttachments[i].initialLayout == VK_IMAGE_LAYOUT_UNDEFINED) { |
| 204 | if ((FormatIsColor(format) || FormatHasDepth(format)) && |
| 205 | pCreateInfo->pAttachments[i].loadOp == VK_ATTACHMENT_LOAD_OP_LOAD) { |
| 206 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 207 | kVUID_BestPractices_RenderPass_Attatchment, |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 208 | "Render pass has an attachment with loadOp == VK_ATTACHMENT_LOAD_OP_LOAD and " |
| 209 | "initialLayout == VK_IMAGE_LAYOUT_UNDEFINED. This is probably not what you " |
| 210 | "intended. Consider using VK_ATTACHMENT_LOAD_OP_DONT_CARE instead if the " |
| 211 | "image truely is undefined at the start of the render pass."); |
| 212 | } |
| 213 | if (FormatHasStencil(format) && pCreateInfo->pAttachments[i].stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD) { |
| 214 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 215 | kVUID_BestPractices_RenderPass_Attatchment, |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 216 | "Render pass has an attachment with stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD " |
| 217 | "and initialLayout == VK_IMAGE_LAYOUT_UNDEFINED. This is probably not what you " |
| 218 | "intended. Consider using VK_ATTACHMENT_LOAD_OP_DONT_CARE instead if the " |
| 219 | "image truely is undefined at the start of the render pass."); |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | for (uint32_t dependency = 0; dependency < pCreateInfo->dependencyCount; dependency++) { |
| 225 | skip |= CheckPipelineStageFlags("vkCreateRenderPass", pCreateInfo->pDependencies[dependency].srcStageMask); |
| 226 | skip |= CheckPipelineStageFlags("vkCreateRenderPass", pCreateInfo->pDependencies[dependency].dstStageMask); |
| 227 | } |
| 228 | |
| 229 | return skip; |
| 230 | } |
| 231 | |
| 232 | bool BestPractices::PreCallValidateAllocateMemory(VkDevice device, const VkMemoryAllocateInfo* pAllocateInfo, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 233 | const VkAllocationCallbacks* pAllocator, VkDeviceMemory* pMemory) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 234 | bool skip = false; |
| 235 | |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 236 | if (num_mem_objects + 1 > kMemoryObjectWarningLimit) { |
Mark Lobodzinski | f95a266 | 2020-01-29 15:43:32 -0700 | [diff] [blame^] | 237 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_AllocateMemory_TooManyObjects, |
| 238 | "Performance Warning: This app has > %" PRIu32 " memory objects.", kMemoryObjectWarningLimit); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 239 | } |
| 240 | |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 241 | // TODO: Insert get check for GetPhysicalDeviceMemoryProperties once the state is tracked in the StateTracker |
| 242 | |
| 243 | return skip; |
| 244 | } |
| 245 | |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 246 | void BestPractices::PostCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo* pAllocateInfo, |
| 247 | const VkAllocationCallbacks* pAllocator, VkDeviceMemory* pMemory, |
| 248 | VkResult result) { |
Camden Stocker | 9738af9 | 2019-10-16 13:54:03 -0700 | [diff] [blame] | 249 | ValidationStateTracker::PostCallRecordAllocateMemory(device, pAllocateInfo, pAllocator, pMemory, result); |
| 250 | |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 251 | if (VK_SUCCESS == result) { |
| 252 | num_mem_objects++; |
| 253 | } |
| 254 | } |
| 255 | |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 256 | bool BestPractices::PreCallValidateFreeMemory(VkDevice device, VkDeviceMemory memory, |
| 257 | const VkAllocationCallbacks* pAllocator) const { |
Mark Lobodzinski | 91e50bf | 2020-01-14 09:55:11 -0700 | [diff] [blame] | 258 | if (memory == VK_NULL_HANDLE) return false; |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 259 | bool skip = false; |
| 260 | |
Camden Stocker | 9738af9 | 2019-10-16 13:54:03 -0700 | [diff] [blame] | 261 | const DEVICE_MEMORY_STATE* mem_info = ValidationStateTracker::GetDevMemState(memory); |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 262 | |
| 263 | for (auto& obj : mem_info->obj_bindings) { |
Mark Lobodzinski | c8a6d05 | 2020-01-29 15:39:16 -0700 | [diff] [blame] | 264 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, get_debug_report_enum[obj.type], 0, layer_name.c_str(), |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 265 | "VK Object %s still has a reference to mem obj %s.", report_data->FormatHandle(obj).c_str(), |
| 266 | report_data->FormatHandle(mem_info->mem).c_str()); |
| 267 | } |
| 268 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 269 | return skip; |
| 270 | } |
| 271 | |
| 272 | void BestPractices::PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory memory, const VkAllocationCallbacks* pAllocator) { |
| 273 | if (memory != VK_NULL_HANDLE) { |
| 274 | num_mem_objects--; |
| 275 | } |
| 276 | } |
| 277 | |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 278 | bool BestPractices::ValidateBindBufferMemory(VkBuffer buffer, const char* api_name) const { |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 279 | bool skip = false; |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 280 | const BUFFER_STATE* buffer_state = GetBufferState(buffer); |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 281 | |
sfricke-samsung | e244119 | 2019-11-06 14:07:57 -0800 | [diff] [blame] | 282 | if (!buffer_state->memory_requirements_checked && !buffer_state->external_memory_handle) { |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 283 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 284 | kVUID_BestPractices_BufferMemReqNotCalled, |
| 285 | "%s: Binding memory to %s but vkGetBufferMemoryRequirements() has not been called on that buffer.", |
| 286 | api_name, report_data->FormatHandle(buffer).c_str()); |
| 287 | } |
| 288 | |
| 289 | return skip; |
| 290 | } |
| 291 | |
| 292 | bool BestPractices::PreCallValidateBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory memory, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 293 | VkDeviceSize memoryOffset) const { |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 294 | bool skip = false; |
| 295 | const char* api_name = "BindBufferMemory()"; |
| 296 | |
| 297 | skip |= ValidateBindBufferMemory(buffer, api_name); |
| 298 | |
| 299 | return skip; |
| 300 | } |
| 301 | |
| 302 | bool BestPractices::PreCallValidateBindBufferMemory2(VkDevice device, uint32_t bindInfoCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 303 | const VkBindBufferMemoryInfo* pBindInfos) const { |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 304 | char api_name[64]; |
| 305 | bool skip = false; |
| 306 | |
| 307 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 308 | sprintf(api_name, "vkBindBufferMemory2() pBindInfos[%u]", i); |
| 309 | skip |= ValidateBindBufferMemory(pBindInfos[i].buffer, api_name); |
| 310 | } |
| 311 | |
| 312 | return skip; |
| 313 | } |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 314 | |
| 315 | bool BestPractices::PreCallValidateBindBufferMemory2KHR(VkDevice device, uint32_t bindInfoCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 316 | const VkBindBufferMemoryInfo* pBindInfos) const { |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 317 | char api_name[64]; |
| 318 | bool skip = false; |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 319 | |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 320 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 321 | sprintf(api_name, "vkBindBufferMemory2KHR() pBindInfos[%u]", i); |
| 322 | skip |= ValidateBindBufferMemory(pBindInfos[i].buffer, api_name); |
| 323 | } |
| 324 | |
| 325 | return skip; |
| 326 | } |
| 327 | |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 328 | bool BestPractices::ValidateBindImageMemory(VkImage image, const char* api_name) const { |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 329 | bool skip = false; |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 330 | const IMAGE_STATE* image_state = GetImageState(image); |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 331 | |
sfricke-samsung | e244119 | 2019-11-06 14:07:57 -0800 | [diff] [blame] | 332 | if (!image_state->memory_requirements_checked && !image_state->external_memory_handle) { |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 333 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 334 | kVUID_BestPractices_ImageMemReqNotCalled, |
| 335 | "%s: Binding memory to %s but vkGetImageMemoryRequirements() has not been called on that image.", api_name, |
| 336 | report_data->FormatHandle(image).c_str()); |
| 337 | } |
| 338 | |
| 339 | return skip; |
| 340 | } |
| 341 | |
| 342 | bool BestPractices::PreCallValidateBindImageMemory(VkDevice device, VkImage image, VkDeviceMemory memory, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 343 | VkDeviceSize memoryOffset) const { |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 344 | bool skip = false; |
| 345 | const char* api_name = "vkBindImageMemory()"; |
| 346 | |
| 347 | skip |= ValidateBindImageMemory(image, api_name); |
| 348 | |
| 349 | return skip; |
| 350 | } |
| 351 | |
| 352 | bool BestPractices::PreCallValidateBindImageMemory2(VkDevice device, uint32_t bindInfoCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 353 | const VkBindImageMemoryInfo* pBindInfos) const { |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 354 | char api_name[64]; |
| 355 | bool skip = false; |
| 356 | |
| 357 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 358 | sprintf(api_name, "vkBindImageMemory2() pBindInfos[%u]", i); |
| 359 | skip |= ValidateBindImageMemory(pBindInfos[i].image, api_name); |
| 360 | } |
| 361 | |
| 362 | return skip; |
| 363 | } |
| 364 | |
| 365 | bool BestPractices::PreCallValidateBindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 366 | const VkBindImageMemoryInfo* pBindInfos) const { |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 367 | char api_name[64]; |
| 368 | bool skip = false; |
| 369 | |
| 370 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 371 | sprintf(api_name, "vkBindImageMemory2KHR() pBindInfos[%u]", i); |
| 372 | skip |= ValidateBindImageMemory(pBindInfos[i].image, api_name); |
| 373 | } |
| 374 | |
| 375 | return skip; |
| 376 | } |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 377 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 378 | bool BestPractices::PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount, |
| 379 | const VkGraphicsPipelineCreateInfo* pCreateInfos, |
Mark Lobodzinski | 2a162a0 | 2019-09-06 11:02:12 -0600 | [diff] [blame] | 380 | const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 381 | void* cgpl_state_data) const { |
Mark Lobodzinski | 8317a3e | 2019-09-20 10:07:08 -0600 | [diff] [blame] | 382 | bool skip = StateTracker::PreCallValidateCreateGraphicsPipelines(device, pipelineCache, createInfoCount, pCreateInfos, |
| 383 | pAllocator, pPipelines, cgpl_state_data); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 384 | |
| 385 | if ((createInfoCount > 1) && (!pipelineCache)) { |
Mark Lobodzinski | f95a266 | 2020-01-29 15:43:32 -0700 | [diff] [blame^] | 386 | skip |= LogPerformanceWarning( |
| 387 | device, kVUID_BestPractices_CreatePipelines_MultiplePipelines, |
| 388 | "Performance Warning: This vkCreateGraphicsPipelines call is creating multiple pipelines but is not using a " |
| 389 | "pipeline cache, which may help with performance"); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | return skip; |
| 393 | } |
| 394 | |
| 395 | bool BestPractices::PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount, |
| 396 | const VkComputePipelineCreateInfo* pCreateInfos, |
Mark Lobodzinski | 2a162a0 | 2019-09-06 11:02:12 -0600 | [diff] [blame] | 397 | const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 398 | void* ccpl_state_data) const { |
Mark Lobodzinski | 8317a3e | 2019-09-20 10:07:08 -0600 | [diff] [blame] | 399 | bool skip = StateTracker::PreCallValidateCreateComputePipelines(device, pipelineCache, createInfoCount, pCreateInfos, |
| 400 | pAllocator, pPipelines, ccpl_state_data); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 401 | |
| 402 | if ((createInfoCount > 1) && (!pipelineCache)) { |
Mark Lobodzinski | f95a266 | 2020-01-29 15:43:32 -0700 | [diff] [blame^] | 403 | skip |= LogPerformanceWarning( |
| 404 | device, kVUID_BestPractices_CreatePipelines_MultiplePipelines, |
| 405 | "Performance Warning: This vkCreateComputePipelines call is creating multiple pipelines but is not using a " |
| 406 | "pipeline cache, which may help with performance"); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | return skip; |
| 410 | } |
| 411 | |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 412 | bool BestPractices::CheckPipelineStageFlags(std::string api_name, const VkPipelineStageFlags flags) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 413 | bool skip = false; |
| 414 | |
| 415 | if (flags & VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT) { |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 416 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 417 | kVUID_BestPractices_PipelineStageFlags, |
| 418 | "You are using VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT when %s is called\n", api_name.c_str()); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 419 | } else if (flags & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT) { |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 420 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 421 | kVUID_BestPractices_PipelineStageFlags, |
| 422 | "You are using VK_PIPELINE_STAGE_ALL_COMMANDS_BIT when %s is called\n", api_name.c_str()); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | return skip; |
| 426 | } |
| 427 | |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 428 | bool BestPractices::PreCallValidateQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo* pSubmits, |
| 429 | VkFence fence) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 430 | bool skip = false; |
| 431 | |
| 432 | for (uint32_t submit = 0; submit < submitCount; submit++) { |
| 433 | for (uint32_t semaphore = 0; semaphore < pSubmits[submit].waitSemaphoreCount; semaphore++) { |
| 434 | skip |= CheckPipelineStageFlags("vkQueueSubmit", pSubmits[submit].pWaitDstStageMask[semaphore]); |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | return skip; |
| 439 | } |
| 440 | |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 441 | bool BestPractices::PreCallValidateCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 442 | bool skip = false; |
| 443 | |
| 444 | skip |= CheckPipelineStageFlags("vkCmdSetEvent", stageMask); |
| 445 | |
| 446 | return skip; |
| 447 | } |
| 448 | |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 449 | bool BestPractices::PreCallValidateCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, |
| 450 | VkPipelineStageFlags stageMask) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 451 | bool skip = false; |
| 452 | |
| 453 | skip |= CheckPipelineStageFlags("vkCmdResetEvent", stageMask); |
| 454 | |
| 455 | return skip; |
| 456 | } |
| 457 | |
| 458 | bool BestPractices::PreCallValidateCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents, |
| 459 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 460 | uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers, |
| 461 | uint32_t bufferMemoryBarrierCount, |
| 462 | const VkBufferMemoryBarrier* pBufferMemoryBarriers, |
| 463 | uint32_t imageMemoryBarrierCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 464 | const VkImageMemoryBarrier* pImageMemoryBarriers) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 465 | bool skip = false; |
| 466 | |
| 467 | skip |= CheckPipelineStageFlags("vkCmdWaitEvents", srcStageMask); |
| 468 | skip |= CheckPipelineStageFlags("vkCmdWaitEvents", dstStageMask); |
| 469 | |
| 470 | return skip; |
| 471 | } |
| 472 | |
| 473 | bool BestPractices::PreCallValidateCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, |
| 474 | VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, |
| 475 | uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers, |
| 476 | uint32_t bufferMemoryBarrierCount, |
| 477 | const VkBufferMemoryBarrier* pBufferMemoryBarriers, |
| 478 | uint32_t imageMemoryBarrierCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 479 | const VkImageMemoryBarrier* pImageMemoryBarriers) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 480 | bool skip = false; |
| 481 | |
| 482 | skip |= CheckPipelineStageFlags("vkCmdPipelineBarrier", srcStageMask); |
| 483 | skip |= CheckPipelineStageFlags("vkCmdPipelineBarrier", dstStageMask); |
| 484 | |
| 485 | return skip; |
| 486 | } |
| 487 | |
| 488 | bool BestPractices::PreCallValidateCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 489 | VkQueryPool queryPool, uint32_t query) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 490 | bool skip = false; |
| 491 | |
| 492 | skip |= CheckPipelineStageFlags("vkCmdWriteTimestamp", pipelineStage); |
| 493 | |
| 494 | return skip; |
| 495 | } |
| 496 | |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 497 | // Generic function to handle validation for all CmdDraw* type functions |
| 498 | bool BestPractices::ValidateCmdDrawType(VkCommandBuffer cmd_buffer, const char* caller) const { |
| 499 | bool skip = false; |
| 500 | const CMD_BUFFER_STATE* cb_state = GetCBState(cmd_buffer); |
| 501 | if (cb_state) { |
| 502 | const auto last_bound_it = cb_state->lastBound.find(VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 503 | const PIPELINE_STATE* pipeline_state = nullptr; |
| 504 | if (last_bound_it != cb_state->lastBound.cend()) { |
| 505 | pipeline_state = last_bound_it->second.pipeline_state; |
| 506 | } |
| 507 | const auto& current_vtx_bfr_binding_info = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings; |
| 508 | // Verify vertex binding |
| 509 | if (pipeline_state->vertex_binding_descriptions_.size() <= 0) { |
| 510 | if ((!current_vtx_bfr_binding_info.empty()) && (!cb_state->vertex_buffer_used)) { |
Mark Lobodzinski | f95a266 | 2020-01-29 15:43:32 -0700 | [diff] [blame^] | 511 | skip |= LogPerformanceWarning(cb_state->commandBuffer, kVUID_BestPractices_DrawState_VtxIndexOutOfBounds, |
| 512 | "Vertex buffers are bound to %s but no vertex buffers are attached to %s.", |
| 513 | report_data->FormatHandle(cb_state->commandBuffer).c_str(), |
| 514 | report_data->FormatHandle(pipeline_state->pipeline).c_str()); |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 515 | } |
| 516 | } |
| 517 | } |
| 518 | return skip; |
| 519 | } |
| 520 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 521 | bool BestPractices::PreCallValidateCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 522 | uint32_t firstVertex, uint32_t firstInstance) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 523 | bool skip = false; |
| 524 | |
| 525 | if (instanceCount == 0) { |
| 526 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 527 | kVUID_BestPractices_CmdDraw_InstanceCountZero, |
| 528 | "Warning: You are calling vkCmdDraw() with an instanceCount of Zero."); |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 529 | skip |= ValidateCmdDrawType(commandBuffer, "vkCmdDraw()"); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | return skip; |
| 533 | } |
| 534 | |
| 535 | bool BestPractices::PreCallValidateCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 536 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 537 | bool skip = false; |
| 538 | |
| 539 | if (instanceCount == 0) { |
| 540 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 541 | kVUID_BestPractices_CmdDraw_InstanceCountZero, |
| 542 | "Warning: You are calling vkCmdDrawIndexed() with an instanceCount of Zero."); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 543 | } |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 544 | skip |= ValidateCmdDrawType(commandBuffer, "vkCmdDrawIndexed()"); |
| 545 | |
| 546 | return skip; |
| 547 | } |
| 548 | |
| 549 | bool BestPractices::PreCallValidateCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 550 | VkDeviceSize offset, VkBuffer countBuffer, |
| 551 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 552 | uint32_t stride) const { |
| 553 | bool skip = ValidateCmdDrawType(commandBuffer, "vkCmdDrawIndexedIndirectCountKHR()"); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 554 | |
| 555 | return skip; |
| 556 | } |
| 557 | |
| 558 | bool BestPractices::PreCallValidateCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 559 | uint32_t drawCount, uint32_t stride) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 560 | bool skip = false; |
| 561 | |
| 562 | if (drawCount == 0) { |
| 563 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 564 | kVUID_BestPractices_CmdDraw_DrawCountZero, |
| 565 | "Warning: You are calling vkCmdDrawIndirect() with a drawCount of Zero."); |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 566 | skip |= ValidateCmdDrawType(commandBuffer, "vkCmdDrawIndirect()"); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | return skip; |
| 570 | } |
| 571 | |
| 572 | bool BestPractices::PreCallValidateCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 573 | uint32_t drawCount, uint32_t stride) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 574 | bool skip = false; |
| 575 | |
| 576 | if (drawCount == 0) { |
| 577 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 578 | kVUID_BestPractices_CmdDraw_DrawCountZero, |
| 579 | "Warning: You are calling vkCmdDrawIndexedIndirect() with a drawCount of Zero."); |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 580 | skip |= ValidateCmdDrawType(commandBuffer, "vkCmdDrawIndexedIndirect()"); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | return skip; |
| 584 | } |
| 585 | |
| 586 | bool BestPractices::PreCallValidateCmdDispatch(VkCommandBuffer commandBuffer, uint32_t groupCountX, uint32_t groupCountY, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 587 | uint32_t groupCountZ) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 588 | bool skip = false; |
| 589 | |
| 590 | if ((groupCountX == 0) || (groupCountY == 0) || (groupCountZ == 0)) { |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 591 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 592 | kVUID_BestPractices_CmdDispatch_GroupCountZero, |
| 593 | "Warning: You are calling vkCmdDispatch() while one or more groupCounts are zero (groupCountX = %" PRIu32 |
| 594 | ", groupCountY = %" PRIu32 ", groupCountZ = %" PRIu32 ").", |
| 595 | groupCountX, groupCountY, groupCountZ); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | return skip; |
| 599 | } |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 600 | |
Camden Stocker | 9c05144 | 2019-11-06 14:28:43 -0800 | [diff] [blame] | 601 | bool BestPractices::ValidateGetPhysicalDeviceDisplayPlanePropertiesKHRQuery(VkPhysicalDevice physicalDevice, |
| 602 | const char* api_name) const { |
| 603 | bool skip = false; |
| 604 | const auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 605 | |
| 606 | if (physical_device_state->vkGetPhysicalDeviceDisplayPlanePropertiesKHRState == UNCALLED) { |
| 607 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
| 608 | HandleToUint64(physicalDevice), kVUID_BestPractices_DisplayPlane_PropertiesNotCalled, |
| 609 | "Potential problem with calling %s() without first retrieving properties from " |
| 610 | "vkGetPhysicalDeviceDisplayPlanePropertiesKHR or vkGetPhysicalDeviceDisplayPlaneProperties2KHR.", |
| 611 | api_name); |
| 612 | } |
| 613 | |
| 614 | return skip; |
| 615 | } |
| 616 | |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 617 | bool BestPractices::PreCallValidateGetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physicalDevice, uint32_t planeIndex, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 618 | uint32_t* pDisplayCount, VkDisplayKHR* pDisplays) const { |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 619 | bool skip = false; |
| 620 | |
Camden Stocker | 9c05144 | 2019-11-06 14:28:43 -0800 | [diff] [blame] | 621 | skip |= ValidateGetPhysicalDeviceDisplayPlanePropertiesKHRQuery(physicalDevice, "vkGetDisplayPlaneSupportedDisplaysKHR"); |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 622 | |
Camden Stocker | 9c05144 | 2019-11-06 14:28:43 -0800 | [diff] [blame] | 623 | return skip; |
| 624 | } |
| 625 | |
| 626 | bool BestPractices::PreCallValidateGetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice physicalDevice, VkDisplayModeKHR mode, |
| 627 | uint32_t planeIndex, |
| 628 | VkDisplayPlaneCapabilitiesKHR* pCapabilities) const { |
| 629 | bool skip = false; |
| 630 | |
| 631 | skip |= ValidateGetPhysicalDeviceDisplayPlanePropertiesKHRQuery(physicalDevice, "vkGetDisplayPlaneCapabilitiesKHR"); |
| 632 | |
| 633 | return skip; |
| 634 | } |
| 635 | |
| 636 | bool BestPractices::PreCallValidateGetDisplayPlaneCapabilities2KHR(VkPhysicalDevice physicalDevice, |
| 637 | const VkDisplayPlaneInfo2KHR* pDisplayPlaneInfo, |
| 638 | VkDisplayPlaneCapabilities2KHR* pCapabilities) const { |
| 639 | bool skip = false; |
| 640 | |
| 641 | skip |= ValidateGetPhysicalDeviceDisplayPlanePropertiesKHRQuery(physicalDevice, "vkGetDisplayPlaneCapabilities2KHR"); |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 642 | |
| 643 | return skip; |
| 644 | } |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 645 | |
| 646 | bool BestPractices::PreCallValidateGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t* pSwapchainImageCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 647 | VkImage* pSwapchainImages) const { |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 648 | bool skip = false; |
| 649 | |
| 650 | auto swapchain_state = GetSwapchainState(swapchain); |
| 651 | |
| 652 | if (swapchain_state && pSwapchainImages) { |
| 653 | // Compare the preliminary value of *pSwapchainImageCount with the value this time: |
| 654 | if (swapchain_state->vkGetSwapchainImagesKHRState == UNCALLED) { |
| 655 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 656 | HandleToUint64(device), kVUID_Core_Swapchain_PriorCount, |
| 657 | "vkGetSwapchainImagesKHR() called with non-NULL pSwapchainImageCount; but no prior positive value has " |
| 658 | "been seen for pSwapchainImages."); |
| 659 | } |
| 660 | } |
| 661 | |
| 662 | return skip; |
| 663 | } |
| 664 | |
| 665 | // Common function to handle validation for GetPhysicalDeviceQueueFamilyProperties & 2KHR version |
| 666 | static bool ValidateCommonGetPhysicalDeviceQueueFamilyProperties(debug_report_data* report_data, |
| 667 | const PHYSICAL_DEVICE_STATE* pd_state, |
| 668 | uint32_t requested_queue_family_property_count, bool qfp_null, |
| 669 | const char* caller_name) { |
| 670 | bool skip = false; |
| 671 | if (!qfp_null) { |
| 672 | // Verify that for each physical device, this command is called first with NULL pQueueFamilyProperties in order to get count |
| 673 | if (UNCALLED == pd_state->vkGetPhysicalDeviceQueueFamilyPropertiesState) { |
| 674 | skip |= log_msg( |
| 675 | report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
| 676 | HandleToUint64(pd_state->phys_device), kVUID_Core_DevLimit_MissingQueryCount, |
| 677 | "%s is called with non-NULL pQueueFamilyProperties before obtaining pQueueFamilyPropertyCount. It is recommended " |
| 678 | "to first call %s with NULL pQueueFamilyProperties in order to obtain the maximal pQueueFamilyPropertyCount.", |
| 679 | caller_name, caller_name); |
| 680 | // Then verify that pCount that is passed in on second call matches what was returned |
| 681 | } else if (pd_state->queue_family_known_count != requested_queue_family_property_count) { |
| 682 | skip |= log_msg( |
| 683 | report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
| 684 | HandleToUint64(pd_state->phys_device), kVUID_Core_DevLimit_CountMismatch, |
| 685 | "%s is called with non-NULL pQueueFamilyProperties and pQueueFamilyPropertyCount value %" PRIu32 |
| 686 | ", but the largest previously returned pQueueFamilyPropertyCount for this physicalDevice is %" PRIu32 |
| 687 | ". It is recommended to instead receive all the properties by calling %s with pQueueFamilyPropertyCount that was " |
| 688 | "previously obtained by calling %s with NULL pQueueFamilyProperties.", |
| 689 | caller_name, requested_queue_family_property_count, pd_state->queue_family_known_count, caller_name, caller_name); |
| 690 | } |
| 691 | } |
| 692 | |
| 693 | return skip; |
| 694 | } |
| 695 | |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 696 | bool BestPractices::PreCallValidateBindAccelerationStructureMemoryNV( |
| 697 | VkDevice device, uint32_t bindInfoCount, const VkBindAccelerationStructureMemoryInfoNV* pBindInfos) const { |
Camden Stocker | 8251058 | 2019-09-03 14:00:16 -0600 | [diff] [blame] | 698 | bool skip = false; |
| 699 | |
| 700 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 701 | const ACCELERATION_STRUCTURE_STATE* as_state = GetAccelerationStructureState(pBindInfos[i].accelerationStructure); |
| 702 | if (!as_state->memory_requirements_checked) { |
| 703 | // There's not an explicit requirement in the spec to call vkGetImageMemoryRequirements() prior to calling |
| 704 | // BindAccelerationStructureMemoryNV but it's implied in that memory being bound must conform with |
| 705 | // VkAccelerationStructureMemoryRequirementsInfoNV from vkGetAccelerationStructureMemoryRequirementsNV |
| 706 | skip |= log_msg( |
| 707 | report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, |
| 708 | kVUID_BestPractices_BindAccelNV_NoMemReqQuery, |
| 709 | "vkBindAccelerationStructureMemoryNV(): " |
| 710 | "Binding memory to %s but vkGetAccelerationStructureMemoryRequirementsNV() has not been called on that structure.", |
| 711 | report_data->FormatHandle(pBindInfos[i].accelerationStructure).c_str()); |
| 712 | } |
| 713 | } |
| 714 | |
| 715 | return skip; |
| 716 | } |
| 717 | |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 718 | bool BestPractices::PreCallValidateGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, |
| 719 | uint32_t* pQueueFamilyPropertyCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 720 | VkQueueFamilyProperties* pQueueFamilyProperties) const { |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 721 | const auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 722 | assert(physical_device_state); |
| 723 | return ValidateCommonGetPhysicalDeviceQueueFamilyProperties(report_data, physical_device_state, *pQueueFamilyPropertyCount, |
| 724 | (nullptr == pQueueFamilyProperties), |
| 725 | "vkGetPhysicalDeviceQueueFamilyProperties()"); |
| 726 | } |
| 727 | |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 728 | bool BestPractices::PreCallValidateGetPhysicalDeviceQueueFamilyProperties2( |
| 729 | VkPhysicalDevice physicalDevice, uint32_t* pQueueFamilyPropertyCount, |
| 730 | VkQueueFamilyProperties2KHR* pQueueFamilyProperties) const { |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 731 | const auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 732 | assert(physical_device_state); |
| 733 | return ValidateCommonGetPhysicalDeviceQueueFamilyProperties(report_data, physical_device_state, *pQueueFamilyPropertyCount, |
| 734 | (nullptr == pQueueFamilyProperties), |
| 735 | "vkGetPhysicalDeviceQueueFamilyProperties2()"); |
| 736 | } |
| 737 | |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 738 | bool BestPractices::PreCallValidateGetPhysicalDeviceQueueFamilyProperties2KHR( |
| 739 | VkPhysicalDevice physicalDevice, uint32_t* pQueueFamilyPropertyCount, |
| 740 | VkQueueFamilyProperties2KHR* pQueueFamilyProperties) const { |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 741 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 742 | assert(physical_device_state); |
| 743 | return ValidateCommonGetPhysicalDeviceQueueFamilyProperties(report_data, physical_device_state, *pQueueFamilyPropertyCount, |
| 744 | (nullptr == pQueueFamilyProperties), |
| 745 | "vkGetPhysicalDeviceQueueFamilyProperties2KHR()"); |
| 746 | } |
| 747 | |
| 748 | bool BestPractices::PreCallValidateGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, |
| 749 | uint32_t* pSurfaceFormatCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 750 | VkSurfaceFormatKHR* pSurfaceFormats) const { |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 751 | if (!pSurfaceFormats) return false; |
| 752 | const auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 753 | const auto& call_state = physical_device_state->vkGetPhysicalDeviceSurfaceFormatsKHRState; |
| 754 | bool skip = false; |
| 755 | if (call_state == UNCALLED) { |
| 756 | // Since we haven't recorded a preliminary value of *pSurfaceFormatCount, that likely means that the application didn't |
| 757 | // previously call this function with a NULL value of pSurfaceFormats: |
| 758 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
| 759 | HandleToUint64(physicalDevice), kVUID_Core_DevLimit_MustQueryCount, |
| 760 | "vkGetPhysicalDeviceSurfaceFormatsKHR() called with non-NULL pSurfaceFormatCount; but no prior " |
| 761 | "positive value has been seen for pSurfaceFormats."); |
| 762 | } else { |
| 763 | auto prev_format_count = (uint32_t)physical_device_state->surface_formats.size(); |
Peter Chen | e191bd7 | 2019-09-16 13:04:37 -0400 | [diff] [blame] | 764 | if (*pSurfaceFormatCount > prev_format_count) { |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 765 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
| 766 | HandleToUint64(physicalDevice), kVUID_Core_DevLimit_CountMismatch, |
| 767 | "vkGetPhysicalDeviceSurfaceFormatsKHR() called with non-NULL pSurfaceFormatCount, and with " |
| 768 | "pSurfaceFormats set to a value (%u) that is greater than the value (%u) that was returned " |
| 769 | "when pSurfaceFormatCount was NULL.", |
| 770 | *pSurfaceFormatCount, prev_format_count); |
| 771 | } |
| 772 | } |
| 773 | return skip; |
| 774 | } |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 775 | |
| 776 | bool BestPractices::PreCallValidateQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo* pBindInfo, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 777 | VkFence fence) const { |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 778 | bool skip = false; |
| 779 | |
| 780 | for (uint32_t bindIdx = 0; bindIdx < bindInfoCount; bindIdx++) { |
| 781 | const VkBindSparseInfo& bindInfo = pBindInfo[bindIdx]; |
| 782 | // Store sparse binding image_state and after binding is complete make sure that any requiring metadata have it bound |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 783 | std::unordered_set<const IMAGE_STATE*> sparse_images; |
| 784 | // Track images getting metadata bound by this call in a set, it'll be recorded into the image_state |
| 785 | // in RecordQueueBindSparse. |
| 786 | std::unordered_set<const IMAGE_STATE*> sparse_images_with_metadata; |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 787 | // If we're binding sparse image memory make sure reqs were queried and note if metadata is required and bound |
| 788 | for (uint32_t i = 0; i < bindInfo.imageBindCount; ++i) { |
| 789 | const auto& image_bind = bindInfo.pImageBinds[i]; |
| 790 | auto image_state = GetImageState(image_bind.image); |
| 791 | if (!image_state) |
| 792 | continue; // Param/Object validation should report image_bind.image handles being invalid, so just skip here. |
| 793 | sparse_images.insert(image_state); |
| 794 | if (image_state->createInfo.flags & VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT) { |
| 795 | if (!image_state->get_sparse_reqs_called || image_state->sparse_requirements.empty()) { |
| 796 | // For now just warning if sparse image binding occurs without calling to get reqs first |
| 797 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 798 | HandleToUint64(image_state->image), kVUID_Core_MemTrack_InvalidState, |
| 799 | "vkQueueBindSparse(): Binding sparse memory to %s without first calling " |
| 800 | "vkGetImageSparseMemoryRequirements[2KHR]() to retrieve requirements.", |
| 801 | report_data->FormatHandle(image_state->image).c_str()); |
| 802 | } |
| 803 | } |
| 804 | if (!image_state->memory_requirements_checked) { |
| 805 | // For now just warning if sparse image binding occurs without calling to get reqs first |
| 806 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 807 | HandleToUint64(image_state->image), kVUID_Core_MemTrack_InvalidState, |
| 808 | "vkQueueBindSparse(): Binding sparse memory to %s without first calling " |
| 809 | "vkGetImageMemoryRequirements() to retrieve requirements.", |
| 810 | report_data->FormatHandle(image_state->image).c_str()); |
| 811 | } |
| 812 | } |
| 813 | for (uint32_t i = 0; i < bindInfo.imageOpaqueBindCount; ++i) { |
| 814 | const auto& image_opaque_bind = bindInfo.pImageOpaqueBinds[i]; |
| 815 | auto image_state = GetImageState(bindInfo.pImageOpaqueBinds[i].image); |
| 816 | if (!image_state) |
| 817 | continue; // Param/Object validation should report image_bind.image handles being invalid, so just skip here. |
| 818 | sparse_images.insert(image_state); |
| 819 | if (image_state->createInfo.flags & VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT) { |
| 820 | if (!image_state->get_sparse_reqs_called || image_state->sparse_requirements.empty()) { |
| 821 | // For now just warning if sparse image binding occurs without calling to get reqs first |
| 822 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 823 | HandleToUint64(image_state->image), kVUID_Core_MemTrack_InvalidState, |
| 824 | "vkQueueBindSparse(): Binding opaque sparse memory to %s without first calling " |
| 825 | "vkGetImageSparseMemoryRequirements[2KHR]() to retrieve requirements.", |
| 826 | report_data->FormatHandle(image_state->image).c_str()); |
| 827 | } |
| 828 | } |
| 829 | if (!image_state->memory_requirements_checked) { |
| 830 | // For now just warning if sparse image binding occurs without calling to get reqs first |
| 831 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 832 | HandleToUint64(image_state->image), kVUID_Core_MemTrack_InvalidState, |
| 833 | "vkQueueBindSparse(): Binding opaque sparse memory to %s without first calling " |
| 834 | "vkGetImageMemoryRequirements() to retrieve requirements.", |
| 835 | report_data->FormatHandle(image_state->image).c_str()); |
| 836 | } |
| 837 | for (uint32_t j = 0; j < image_opaque_bind.bindCount; ++j) { |
| 838 | if (image_opaque_bind.pBinds[j].flags & VK_SPARSE_MEMORY_BIND_METADATA_BIT) { |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 839 | sparse_images_with_metadata.insert(image_state); |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 840 | } |
| 841 | } |
| 842 | } |
| 843 | for (const auto& sparse_image_state : sparse_images) { |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 844 | if (sparse_image_state->sparse_metadata_required && !sparse_image_state->sparse_metadata_bound && |
| 845 | sparse_images_with_metadata.find(sparse_image_state) == sparse_images_with_metadata.end()) { |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 846 | // Warn if sparse image binding metadata required for image with sparse binding, but metadata not bound |
| 847 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 848 | HandleToUint64(sparse_image_state->image), kVUID_Core_MemTrack_InvalidState, |
| 849 | "vkQueueBindSparse(): Binding sparse memory to %s which requires a metadata aspect but no " |
| 850 | "binding with VK_SPARSE_MEMORY_BIND_METADATA_BIT set was made.", |
| 851 | report_data->FormatHandle(sparse_image_state->image).c_str()); |
| 852 | } |
| 853 | } |
| 854 | } |
| 855 | |
| 856 | return skip; |
| 857 | } |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 858 | |
| 859 | void BestPractices::PostCallRecordQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo* pBindInfo, |
| 860 | VkFence fence, VkResult result) { |
| 861 | if (result != VK_SUCCESS) return; |
| 862 | |
| 863 | for (uint32_t bindIdx = 0; bindIdx < bindInfoCount; bindIdx++) { |
| 864 | const VkBindSparseInfo& bindInfo = pBindInfo[bindIdx]; |
| 865 | for (uint32_t i = 0; i < bindInfo.imageOpaqueBindCount; ++i) { |
| 866 | const auto& image_opaque_bind = bindInfo.pImageOpaqueBinds[i]; |
| 867 | auto image_state = GetImageState(bindInfo.pImageOpaqueBinds[i].image); |
| 868 | if (!image_state) |
| 869 | continue; // Param/Object validation should report image_bind.image handles being invalid, so just skip here. |
| 870 | for (uint32_t j = 0; j < image_opaque_bind.bindCount; ++j) { |
| 871 | if (image_opaque_bind.pBinds[j].flags & VK_SPARSE_MEMORY_BIND_METADATA_BIT) { |
| 872 | image_state->sparse_metadata_bound = true; |
| 873 | } |
| 874 | } |
| 875 | } |
| 876 | } |
| 877 | } |
Camden Stocker | 0e0f89b | 2019-10-16 12:24:31 -0700 | [diff] [blame] | 878 | |
| 879 | bool BestPractices::PreCallValidateCmdClearAttachments(VkCommandBuffer commandBuffer, uint32_t attachmentCount, |
Camden Stocker | f55721f | 2019-09-09 11:04:49 -0600 | [diff] [blame] | 880 | const VkClearAttachment* pAttachments, uint32_t rectCount, |
| 881 | const VkClearRect* pRects) const { |
Camden Stocker | 0e0f89b | 2019-10-16 12:24:31 -0700 | [diff] [blame] | 882 | bool skip = false; |
| 883 | const CMD_BUFFER_STATE* cb_node = GetCBState(commandBuffer); |
| 884 | if (!cb_node) return skip; |
| 885 | |
Camden Stocker | f55721f | 2019-09-09 11:04:49 -0600 | [diff] [blame] | 886 | // Warn if this is issued prior to Draw Cmd and clearing the entire attachment |
Camden Stocker | 0e0f89b | 2019-10-16 12:24:31 -0700 | [diff] [blame] | 887 | if (!cb_node->hasDrawCmd && (cb_node->activeRenderPassBeginInfo.renderArea.extent.width == pRects[0].rect.extent.width) && |
| 888 | (cb_node->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) { |
| 889 | // There are times where app needs to use ClearAttachments (generally when reusing a buffer inside of a render pass) |
| 890 | // This warning should be made more specific. It'd be best to avoid triggering this test if it's a use that must call |
| 891 | // CmdClearAttachments. |
Mark Lobodzinski | f95a266 | 2020-01-29 15:43:32 -0700 | [diff] [blame^] | 892 | skip |= LogPerformanceWarning(commandBuffer, kVUID_BestPractices_DrawState_ClearCmdBeforeDraw, |
| 893 | "vkCmdClearAttachments() issued on %s prior to any Draw Cmds. It is recommended you " |
| 894 | "use RenderPass LOAD_OP_CLEAR on Attachments prior to any Draw.", |
| 895 | report_data->FormatHandle(commandBuffer).c_str()); |
Camden Stocker | 0e0f89b | 2019-10-16 12:24:31 -0700 | [diff] [blame] | 896 | } |
| 897 | |
Camden Stocker | f55721f | 2019-09-09 11:04:49 -0600 | [diff] [blame] | 898 | return skip; |
Camden Stocker | 0e0f89b | 2019-10-16 12:24:31 -0700 | [diff] [blame] | 899 | } |