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) { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 237 | skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 238 | kVUID_BestPractices_AllocateMemory_TooManyObjects, |
| 239 | "Performance Warning: This app has > %" PRIu32 " memory objects.", kMemoryObjectWarningLimit); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 240 | } |
| 241 | |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 242 | // TODO: Insert get check for GetPhysicalDeviceMemoryProperties once the state is tracked in the StateTracker |
| 243 | |
| 244 | return skip; |
| 245 | } |
| 246 | |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 247 | void BestPractices::PostCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo* pAllocateInfo, |
| 248 | const VkAllocationCallbacks* pAllocator, VkDeviceMemory* pMemory, |
| 249 | VkResult result) { |
Camden Stocker | 9738af9 | 2019-10-16 13:54:03 -0700 | [diff] [blame] | 250 | ValidationStateTracker::PostCallRecordAllocateMemory(device, pAllocateInfo, pAllocator, pMemory, result); |
| 251 | |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 252 | if (VK_SUCCESS == result) { |
| 253 | num_mem_objects++; |
| 254 | } |
| 255 | } |
| 256 | |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 257 | bool BestPractices::PreCallValidateFreeMemory(VkDevice device, VkDeviceMemory memory, |
| 258 | const VkAllocationCallbacks* pAllocator) const { |
Mark Lobodzinski | 91e50bf | 2020-01-14 09:55:11 -0700 | [diff] [blame^] | 259 | if (memory == VK_NULL_HANDLE) return false; |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 260 | bool skip = false; |
| 261 | |
Camden Stocker | 9738af9 | 2019-10-16 13:54:03 -0700 | [diff] [blame] | 262 | const DEVICE_MEMORY_STATE* mem_info = ValidationStateTracker::GetDevMemState(memory); |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 263 | |
| 264 | for (auto& obj : mem_info->obj_bindings) { |
| 265 | skip |= log_msg(report_data, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, get_debug_report_enum[obj.type], 0, layer_name.c_str(), |
| 266 | "VK Object %s still has a reference to mem obj %s.", report_data->FormatHandle(obj).c_str(), |
| 267 | report_data->FormatHandle(mem_info->mem).c_str()); |
| 268 | } |
| 269 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 270 | return skip; |
| 271 | } |
| 272 | |
| 273 | void BestPractices::PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory memory, const VkAllocationCallbacks* pAllocator) { |
| 274 | if (memory != VK_NULL_HANDLE) { |
| 275 | num_mem_objects--; |
| 276 | } |
| 277 | } |
| 278 | |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 279 | bool BestPractices::ValidateBindBufferMemory(VkBuffer buffer, const char* api_name) const { |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 280 | bool skip = false; |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 281 | const BUFFER_STATE* buffer_state = GetBufferState(buffer); |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 282 | |
sfricke-samsung | e244119 | 2019-11-06 14:07:57 -0800 | [diff] [blame] | 283 | if (!buffer_state->memory_requirements_checked && !buffer_state->external_memory_handle) { |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 284 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 285 | kVUID_BestPractices_BufferMemReqNotCalled, |
| 286 | "%s: Binding memory to %s but vkGetBufferMemoryRequirements() has not been called on that buffer.", |
| 287 | api_name, report_data->FormatHandle(buffer).c_str()); |
| 288 | } |
| 289 | |
| 290 | return skip; |
| 291 | } |
| 292 | |
| 293 | bool BestPractices::PreCallValidateBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory memory, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 294 | VkDeviceSize memoryOffset) const { |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 295 | bool skip = false; |
| 296 | const char* api_name = "BindBufferMemory()"; |
| 297 | |
| 298 | skip |= ValidateBindBufferMemory(buffer, api_name); |
| 299 | |
| 300 | return skip; |
| 301 | } |
| 302 | |
| 303 | bool BestPractices::PreCallValidateBindBufferMemory2(VkDevice device, uint32_t bindInfoCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 304 | const VkBindBufferMemoryInfo* pBindInfos) const { |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 305 | char api_name[64]; |
| 306 | bool skip = false; |
| 307 | |
| 308 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 309 | sprintf(api_name, "vkBindBufferMemory2() pBindInfos[%u]", i); |
| 310 | skip |= ValidateBindBufferMemory(pBindInfos[i].buffer, api_name); |
| 311 | } |
| 312 | |
| 313 | return skip; |
| 314 | } |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 315 | |
| 316 | bool BestPractices::PreCallValidateBindBufferMemory2KHR(VkDevice device, uint32_t bindInfoCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 317 | const VkBindBufferMemoryInfo* pBindInfos) const { |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 318 | char api_name[64]; |
| 319 | bool skip = false; |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 320 | |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 321 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 322 | sprintf(api_name, "vkBindBufferMemory2KHR() pBindInfos[%u]", i); |
| 323 | skip |= ValidateBindBufferMemory(pBindInfos[i].buffer, api_name); |
| 324 | } |
| 325 | |
| 326 | return skip; |
| 327 | } |
| 328 | |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 329 | bool BestPractices::ValidateBindImageMemory(VkImage image, const char* api_name) const { |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 330 | bool skip = false; |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 331 | const IMAGE_STATE* image_state = GetImageState(image); |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 332 | |
sfricke-samsung | e244119 | 2019-11-06 14:07:57 -0800 | [diff] [blame] | 333 | if (!image_state->memory_requirements_checked && !image_state->external_memory_handle) { |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 334 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 335 | kVUID_BestPractices_ImageMemReqNotCalled, |
| 336 | "%s: Binding memory to %s but vkGetImageMemoryRequirements() has not been called on that image.", api_name, |
| 337 | report_data->FormatHandle(image).c_str()); |
| 338 | } |
| 339 | |
| 340 | return skip; |
| 341 | } |
| 342 | |
| 343 | bool BestPractices::PreCallValidateBindImageMemory(VkDevice device, VkImage image, VkDeviceMemory memory, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 344 | VkDeviceSize memoryOffset) const { |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 345 | bool skip = false; |
| 346 | const char* api_name = "vkBindImageMemory()"; |
| 347 | |
| 348 | skip |= ValidateBindImageMemory(image, api_name); |
| 349 | |
| 350 | return skip; |
| 351 | } |
| 352 | |
| 353 | bool BestPractices::PreCallValidateBindImageMemory2(VkDevice device, uint32_t bindInfoCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 354 | const VkBindImageMemoryInfo* pBindInfos) const { |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 355 | char api_name[64]; |
| 356 | bool skip = false; |
| 357 | |
| 358 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 359 | sprintf(api_name, "vkBindImageMemory2() pBindInfos[%u]", i); |
| 360 | skip |= ValidateBindImageMemory(pBindInfos[i].image, api_name); |
| 361 | } |
| 362 | |
| 363 | return skip; |
| 364 | } |
| 365 | |
| 366 | bool BestPractices::PreCallValidateBindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 367 | const VkBindImageMemoryInfo* pBindInfos) const { |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 368 | char api_name[64]; |
| 369 | bool skip = false; |
| 370 | |
| 371 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 372 | sprintf(api_name, "vkBindImageMemory2KHR() pBindInfos[%u]", i); |
| 373 | skip |= ValidateBindImageMemory(pBindInfos[i].image, api_name); |
| 374 | } |
| 375 | |
| 376 | return skip; |
| 377 | } |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 378 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 379 | bool BestPractices::PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount, |
| 380 | const VkGraphicsPipelineCreateInfo* pCreateInfos, |
Mark Lobodzinski | 2a162a0 | 2019-09-06 11:02:12 -0600 | [diff] [blame] | 381 | const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 382 | void* cgpl_state_data) const { |
Mark Lobodzinski | 8317a3e | 2019-09-20 10:07:08 -0600 | [diff] [blame] | 383 | bool skip = StateTracker::PreCallValidateCreateGraphicsPipelines(device, pipelineCache, createInfoCount, pCreateInfos, |
| 384 | pAllocator, pPipelines, cgpl_state_data); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 385 | |
| 386 | if ((createInfoCount > 1) && (!pipelineCache)) { |
| 387 | skip |= |
| 388 | log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 389 | kVUID_BestPractices_CreatePipelines_MultiplePipelines, |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 390 | "Performance Warning: This vkCreateGraphicsPipelines call is creating multiple pipelines but is not using a " |
| 391 | "pipeline cache, which may help with performance"); |
| 392 | } |
| 393 | |
| 394 | return skip; |
| 395 | } |
| 396 | |
| 397 | bool BestPractices::PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount, |
| 398 | const VkComputePipelineCreateInfo* pCreateInfos, |
Mark Lobodzinski | 2a162a0 | 2019-09-06 11:02:12 -0600 | [diff] [blame] | 399 | const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 400 | void* ccpl_state_data) const { |
Mark Lobodzinski | 8317a3e | 2019-09-20 10:07:08 -0600 | [diff] [blame] | 401 | bool skip = StateTracker::PreCallValidateCreateComputePipelines(device, pipelineCache, createInfoCount, pCreateInfos, |
| 402 | pAllocator, pPipelines, ccpl_state_data); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 403 | |
| 404 | if ((createInfoCount > 1) && (!pipelineCache)) { |
| 405 | skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 406 | kVUID_BestPractices_CreatePipelines_MultiplePipelines, |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 407 | "Performance Warning: This vkCreateComputePipelines call is creating multiple pipelines but is not using a " |
| 408 | "pipeline cache, which may help with performance"); |
| 409 | } |
| 410 | |
| 411 | return skip; |
| 412 | } |
| 413 | |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 414 | bool BestPractices::CheckPipelineStageFlags(std::string api_name, const VkPipelineStageFlags flags) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 415 | bool skip = false; |
| 416 | |
| 417 | if (flags & VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT) { |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 418 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 419 | kVUID_BestPractices_PipelineStageFlags, |
| 420 | "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] | 421 | } else if (flags & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT) { |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 422 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 423 | kVUID_BestPractices_PipelineStageFlags, |
| 424 | "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] | 425 | } |
| 426 | |
| 427 | return skip; |
| 428 | } |
| 429 | |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 430 | bool BestPractices::PreCallValidateQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo* pSubmits, |
| 431 | VkFence fence) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 432 | bool skip = false; |
| 433 | |
| 434 | for (uint32_t submit = 0; submit < submitCount; submit++) { |
| 435 | for (uint32_t semaphore = 0; semaphore < pSubmits[submit].waitSemaphoreCount; semaphore++) { |
| 436 | skip |= CheckPipelineStageFlags("vkQueueSubmit", pSubmits[submit].pWaitDstStageMask[semaphore]); |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | return skip; |
| 441 | } |
| 442 | |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 443 | bool BestPractices::PreCallValidateCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 444 | bool skip = false; |
| 445 | |
| 446 | skip |= CheckPipelineStageFlags("vkCmdSetEvent", stageMask); |
| 447 | |
| 448 | return skip; |
| 449 | } |
| 450 | |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 451 | bool BestPractices::PreCallValidateCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, |
| 452 | VkPipelineStageFlags stageMask) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 453 | bool skip = false; |
| 454 | |
| 455 | skip |= CheckPipelineStageFlags("vkCmdResetEvent", stageMask); |
| 456 | |
| 457 | return skip; |
| 458 | } |
| 459 | |
| 460 | bool BestPractices::PreCallValidateCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents, |
| 461 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 462 | uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers, |
| 463 | uint32_t bufferMemoryBarrierCount, |
| 464 | const VkBufferMemoryBarrier* pBufferMemoryBarriers, |
| 465 | uint32_t imageMemoryBarrierCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 466 | const VkImageMemoryBarrier* pImageMemoryBarriers) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 467 | bool skip = false; |
| 468 | |
| 469 | skip |= CheckPipelineStageFlags("vkCmdWaitEvents", srcStageMask); |
| 470 | skip |= CheckPipelineStageFlags("vkCmdWaitEvents", dstStageMask); |
| 471 | |
| 472 | return skip; |
| 473 | } |
| 474 | |
| 475 | bool BestPractices::PreCallValidateCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, |
| 476 | VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, |
| 477 | uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers, |
| 478 | uint32_t bufferMemoryBarrierCount, |
| 479 | const VkBufferMemoryBarrier* pBufferMemoryBarriers, |
| 480 | uint32_t imageMemoryBarrierCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 481 | const VkImageMemoryBarrier* pImageMemoryBarriers) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 482 | bool skip = false; |
| 483 | |
| 484 | skip |= CheckPipelineStageFlags("vkCmdPipelineBarrier", srcStageMask); |
| 485 | skip |= CheckPipelineStageFlags("vkCmdPipelineBarrier", dstStageMask); |
| 486 | |
| 487 | return skip; |
| 488 | } |
| 489 | |
| 490 | bool BestPractices::PreCallValidateCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 491 | VkQueryPool queryPool, uint32_t query) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 492 | bool skip = false; |
| 493 | |
| 494 | skip |= CheckPipelineStageFlags("vkCmdWriteTimestamp", pipelineStage); |
| 495 | |
| 496 | return skip; |
| 497 | } |
| 498 | |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 499 | // Generic function to handle validation for all CmdDraw* type functions |
| 500 | bool BestPractices::ValidateCmdDrawType(VkCommandBuffer cmd_buffer, const char* caller) const { |
| 501 | bool skip = false; |
| 502 | const CMD_BUFFER_STATE* cb_state = GetCBState(cmd_buffer); |
| 503 | if (cb_state) { |
| 504 | const auto last_bound_it = cb_state->lastBound.find(VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 505 | const PIPELINE_STATE* pipeline_state = nullptr; |
| 506 | if (last_bound_it != cb_state->lastBound.cend()) { |
| 507 | pipeline_state = last_bound_it->second.pipeline_state; |
| 508 | } |
| 509 | const auto& current_vtx_bfr_binding_info = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings; |
| 510 | // Verify vertex binding |
| 511 | if (pipeline_state->vertex_binding_descriptions_.size() <= 0) { |
| 512 | if ((!current_vtx_bfr_binding_info.empty()) && (!cb_state->vertex_buffer_used)) { |
| 513 | skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 514 | VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, HandleToUint64(cb_state->commandBuffer), |
| 515 | kVUID_BestPractices_DrawState_VtxIndexOutOfBounds, |
| 516 | "Vertex buffers are bound to %s but no vertex buffers are attached to %s.", |
| 517 | report_data->FormatHandle(cb_state->commandBuffer).c_str(), |
| 518 | report_data->FormatHandle(pipeline_state->pipeline).c_str()); |
| 519 | } |
| 520 | } |
| 521 | } |
| 522 | return skip; |
| 523 | } |
| 524 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 525 | bool BestPractices::PreCallValidateCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 526 | uint32_t firstVertex, uint32_t firstInstance) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 527 | bool skip = false; |
| 528 | |
| 529 | if (instanceCount == 0) { |
| 530 | 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] | 531 | kVUID_BestPractices_CmdDraw_InstanceCountZero, |
| 532 | "Warning: You are calling vkCmdDraw() with an instanceCount of Zero."); |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 533 | skip |= ValidateCmdDrawType(commandBuffer, "vkCmdDraw()"); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | return skip; |
| 537 | } |
| 538 | |
| 539 | bool BestPractices::PreCallValidateCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 540 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 541 | bool skip = false; |
| 542 | |
| 543 | if (instanceCount == 0) { |
| 544 | 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] | 545 | kVUID_BestPractices_CmdDraw_InstanceCountZero, |
| 546 | "Warning: You are calling vkCmdDrawIndexed() with an instanceCount of Zero."); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 547 | } |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 548 | skip |= ValidateCmdDrawType(commandBuffer, "vkCmdDrawIndexed()"); |
| 549 | |
| 550 | return skip; |
| 551 | } |
| 552 | |
| 553 | bool BestPractices::PreCallValidateCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 554 | VkDeviceSize offset, VkBuffer countBuffer, |
| 555 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 556 | uint32_t stride) const { |
| 557 | bool skip = ValidateCmdDrawType(commandBuffer, "vkCmdDrawIndexedIndirectCountKHR()"); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 558 | |
| 559 | return skip; |
| 560 | } |
| 561 | |
| 562 | bool BestPractices::PreCallValidateCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 563 | uint32_t drawCount, uint32_t stride) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 564 | bool skip = false; |
| 565 | |
| 566 | if (drawCount == 0) { |
| 567 | 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] | 568 | kVUID_BestPractices_CmdDraw_DrawCountZero, |
| 569 | "Warning: You are calling vkCmdDrawIndirect() with a drawCount of Zero."); |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 570 | skip |= ValidateCmdDrawType(commandBuffer, "vkCmdDrawIndirect()"); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | return skip; |
| 574 | } |
| 575 | |
| 576 | bool BestPractices::PreCallValidateCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 577 | uint32_t drawCount, uint32_t stride) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 578 | bool skip = false; |
| 579 | |
| 580 | if (drawCount == 0) { |
| 581 | 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] | 582 | kVUID_BestPractices_CmdDraw_DrawCountZero, |
| 583 | "Warning: You are calling vkCmdDrawIndexedIndirect() with a drawCount of Zero."); |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 584 | skip |= ValidateCmdDrawType(commandBuffer, "vkCmdDrawIndexedIndirect()"); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | return skip; |
| 588 | } |
| 589 | |
| 590 | bool BestPractices::PreCallValidateCmdDispatch(VkCommandBuffer commandBuffer, uint32_t groupCountX, uint32_t groupCountY, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 591 | uint32_t groupCountZ) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 592 | bool skip = false; |
| 593 | |
| 594 | if ((groupCountX == 0) || (groupCountY == 0) || (groupCountZ == 0)) { |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 595 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 596 | kVUID_BestPractices_CmdDispatch_GroupCountZero, |
| 597 | "Warning: You are calling vkCmdDispatch() while one or more groupCounts are zero (groupCountX = %" PRIu32 |
| 598 | ", groupCountY = %" PRIu32 ", groupCountZ = %" PRIu32 ").", |
| 599 | groupCountX, groupCountY, groupCountZ); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | return skip; |
| 603 | } |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 604 | |
Camden Stocker | 9c05144 | 2019-11-06 14:28:43 -0800 | [diff] [blame] | 605 | bool BestPractices::ValidateGetPhysicalDeviceDisplayPlanePropertiesKHRQuery(VkPhysicalDevice physicalDevice, |
| 606 | const char* api_name) const { |
| 607 | bool skip = false; |
| 608 | const auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 609 | |
| 610 | if (physical_device_state->vkGetPhysicalDeviceDisplayPlanePropertiesKHRState == UNCALLED) { |
| 611 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
| 612 | HandleToUint64(physicalDevice), kVUID_BestPractices_DisplayPlane_PropertiesNotCalled, |
| 613 | "Potential problem with calling %s() without first retrieving properties from " |
| 614 | "vkGetPhysicalDeviceDisplayPlanePropertiesKHR or vkGetPhysicalDeviceDisplayPlaneProperties2KHR.", |
| 615 | api_name); |
| 616 | } |
| 617 | |
| 618 | return skip; |
| 619 | } |
| 620 | |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 621 | bool BestPractices::PreCallValidateGetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physicalDevice, uint32_t planeIndex, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 622 | uint32_t* pDisplayCount, VkDisplayKHR* pDisplays) const { |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 623 | bool skip = false; |
| 624 | |
Camden Stocker | 9c05144 | 2019-11-06 14:28:43 -0800 | [diff] [blame] | 625 | skip |= ValidateGetPhysicalDeviceDisplayPlanePropertiesKHRQuery(physicalDevice, "vkGetDisplayPlaneSupportedDisplaysKHR"); |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 626 | |
Camden Stocker | 9c05144 | 2019-11-06 14:28:43 -0800 | [diff] [blame] | 627 | return skip; |
| 628 | } |
| 629 | |
| 630 | bool BestPractices::PreCallValidateGetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice physicalDevice, VkDisplayModeKHR mode, |
| 631 | uint32_t planeIndex, |
| 632 | VkDisplayPlaneCapabilitiesKHR* pCapabilities) const { |
| 633 | bool skip = false; |
| 634 | |
| 635 | skip |= ValidateGetPhysicalDeviceDisplayPlanePropertiesKHRQuery(physicalDevice, "vkGetDisplayPlaneCapabilitiesKHR"); |
| 636 | |
| 637 | return skip; |
| 638 | } |
| 639 | |
| 640 | bool BestPractices::PreCallValidateGetDisplayPlaneCapabilities2KHR(VkPhysicalDevice physicalDevice, |
| 641 | const VkDisplayPlaneInfo2KHR* pDisplayPlaneInfo, |
| 642 | VkDisplayPlaneCapabilities2KHR* pCapabilities) const { |
| 643 | bool skip = false; |
| 644 | |
| 645 | skip |= ValidateGetPhysicalDeviceDisplayPlanePropertiesKHRQuery(physicalDevice, "vkGetDisplayPlaneCapabilities2KHR"); |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 646 | |
| 647 | return skip; |
| 648 | } |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 649 | |
| 650 | bool BestPractices::PreCallValidateGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t* pSwapchainImageCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 651 | VkImage* pSwapchainImages) const { |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 652 | bool skip = false; |
| 653 | |
| 654 | auto swapchain_state = GetSwapchainState(swapchain); |
| 655 | |
| 656 | if (swapchain_state && pSwapchainImages) { |
| 657 | // Compare the preliminary value of *pSwapchainImageCount with the value this time: |
| 658 | if (swapchain_state->vkGetSwapchainImagesKHRState == UNCALLED) { |
| 659 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 660 | HandleToUint64(device), kVUID_Core_Swapchain_PriorCount, |
| 661 | "vkGetSwapchainImagesKHR() called with non-NULL pSwapchainImageCount; but no prior positive value has " |
| 662 | "been seen for pSwapchainImages."); |
| 663 | } |
| 664 | } |
| 665 | |
| 666 | return skip; |
| 667 | } |
| 668 | |
| 669 | // Common function to handle validation for GetPhysicalDeviceQueueFamilyProperties & 2KHR version |
| 670 | static bool ValidateCommonGetPhysicalDeviceQueueFamilyProperties(debug_report_data* report_data, |
| 671 | const PHYSICAL_DEVICE_STATE* pd_state, |
| 672 | uint32_t requested_queue_family_property_count, bool qfp_null, |
| 673 | const char* caller_name) { |
| 674 | bool skip = false; |
| 675 | if (!qfp_null) { |
| 676 | // Verify that for each physical device, this command is called first with NULL pQueueFamilyProperties in order to get count |
| 677 | if (UNCALLED == pd_state->vkGetPhysicalDeviceQueueFamilyPropertiesState) { |
| 678 | skip |= log_msg( |
| 679 | report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
| 680 | HandleToUint64(pd_state->phys_device), kVUID_Core_DevLimit_MissingQueryCount, |
| 681 | "%s is called with non-NULL pQueueFamilyProperties before obtaining pQueueFamilyPropertyCount. It is recommended " |
| 682 | "to first call %s with NULL pQueueFamilyProperties in order to obtain the maximal pQueueFamilyPropertyCount.", |
| 683 | caller_name, caller_name); |
| 684 | // Then verify that pCount that is passed in on second call matches what was returned |
| 685 | } else if (pd_state->queue_family_known_count != requested_queue_family_property_count) { |
| 686 | skip |= log_msg( |
| 687 | report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
| 688 | HandleToUint64(pd_state->phys_device), kVUID_Core_DevLimit_CountMismatch, |
| 689 | "%s is called with non-NULL pQueueFamilyProperties and pQueueFamilyPropertyCount value %" PRIu32 |
| 690 | ", but the largest previously returned pQueueFamilyPropertyCount for this physicalDevice is %" PRIu32 |
| 691 | ". It is recommended to instead receive all the properties by calling %s with pQueueFamilyPropertyCount that was " |
| 692 | "previously obtained by calling %s with NULL pQueueFamilyProperties.", |
| 693 | caller_name, requested_queue_family_property_count, pd_state->queue_family_known_count, caller_name, caller_name); |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | return skip; |
| 698 | } |
| 699 | |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 700 | bool BestPractices::PreCallValidateBindAccelerationStructureMemoryNV( |
| 701 | VkDevice device, uint32_t bindInfoCount, const VkBindAccelerationStructureMemoryInfoNV* pBindInfos) const { |
Camden Stocker | 8251058 | 2019-09-03 14:00:16 -0600 | [diff] [blame] | 702 | bool skip = false; |
| 703 | |
| 704 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 705 | const ACCELERATION_STRUCTURE_STATE* as_state = GetAccelerationStructureState(pBindInfos[i].accelerationStructure); |
| 706 | if (!as_state->memory_requirements_checked) { |
| 707 | // There's not an explicit requirement in the spec to call vkGetImageMemoryRequirements() prior to calling |
| 708 | // BindAccelerationStructureMemoryNV but it's implied in that memory being bound must conform with |
| 709 | // VkAccelerationStructureMemoryRequirementsInfoNV from vkGetAccelerationStructureMemoryRequirementsNV |
| 710 | skip |= log_msg( |
| 711 | report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, |
| 712 | kVUID_BestPractices_BindAccelNV_NoMemReqQuery, |
| 713 | "vkBindAccelerationStructureMemoryNV(): " |
| 714 | "Binding memory to %s but vkGetAccelerationStructureMemoryRequirementsNV() has not been called on that structure.", |
| 715 | report_data->FormatHandle(pBindInfos[i].accelerationStructure).c_str()); |
| 716 | } |
| 717 | } |
| 718 | |
| 719 | return skip; |
| 720 | } |
| 721 | |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 722 | bool BestPractices::PreCallValidateGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, |
| 723 | uint32_t* pQueueFamilyPropertyCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 724 | VkQueueFamilyProperties* pQueueFamilyProperties) const { |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 725 | const auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 726 | assert(physical_device_state); |
| 727 | return ValidateCommonGetPhysicalDeviceQueueFamilyProperties(report_data, physical_device_state, *pQueueFamilyPropertyCount, |
| 728 | (nullptr == pQueueFamilyProperties), |
| 729 | "vkGetPhysicalDeviceQueueFamilyProperties()"); |
| 730 | } |
| 731 | |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 732 | bool BestPractices::PreCallValidateGetPhysicalDeviceQueueFamilyProperties2( |
| 733 | VkPhysicalDevice physicalDevice, uint32_t* pQueueFamilyPropertyCount, |
| 734 | VkQueueFamilyProperties2KHR* pQueueFamilyProperties) const { |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 735 | const auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 736 | assert(physical_device_state); |
| 737 | return ValidateCommonGetPhysicalDeviceQueueFamilyProperties(report_data, physical_device_state, *pQueueFamilyPropertyCount, |
| 738 | (nullptr == pQueueFamilyProperties), |
| 739 | "vkGetPhysicalDeviceQueueFamilyProperties2()"); |
| 740 | } |
| 741 | |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 742 | bool BestPractices::PreCallValidateGetPhysicalDeviceQueueFamilyProperties2KHR( |
| 743 | VkPhysicalDevice physicalDevice, uint32_t* pQueueFamilyPropertyCount, |
| 744 | VkQueueFamilyProperties2KHR* pQueueFamilyProperties) const { |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 745 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 746 | assert(physical_device_state); |
| 747 | return ValidateCommonGetPhysicalDeviceQueueFamilyProperties(report_data, physical_device_state, *pQueueFamilyPropertyCount, |
| 748 | (nullptr == pQueueFamilyProperties), |
| 749 | "vkGetPhysicalDeviceQueueFamilyProperties2KHR()"); |
| 750 | } |
| 751 | |
| 752 | bool BestPractices::PreCallValidateGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, |
| 753 | uint32_t* pSurfaceFormatCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 754 | VkSurfaceFormatKHR* pSurfaceFormats) const { |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 755 | if (!pSurfaceFormats) return false; |
| 756 | const auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 757 | const auto& call_state = physical_device_state->vkGetPhysicalDeviceSurfaceFormatsKHRState; |
| 758 | bool skip = false; |
| 759 | if (call_state == UNCALLED) { |
| 760 | // Since we haven't recorded a preliminary value of *pSurfaceFormatCount, that likely means that the application didn't |
| 761 | // previously call this function with a NULL value of pSurfaceFormats: |
| 762 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
| 763 | HandleToUint64(physicalDevice), kVUID_Core_DevLimit_MustQueryCount, |
| 764 | "vkGetPhysicalDeviceSurfaceFormatsKHR() called with non-NULL pSurfaceFormatCount; but no prior " |
| 765 | "positive value has been seen for pSurfaceFormats."); |
| 766 | } else { |
| 767 | auto prev_format_count = (uint32_t)physical_device_state->surface_formats.size(); |
Peter Chen | e191bd7 | 2019-09-16 13:04:37 -0400 | [diff] [blame] | 768 | if (*pSurfaceFormatCount > prev_format_count) { |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 769 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
| 770 | HandleToUint64(physicalDevice), kVUID_Core_DevLimit_CountMismatch, |
| 771 | "vkGetPhysicalDeviceSurfaceFormatsKHR() called with non-NULL pSurfaceFormatCount, and with " |
| 772 | "pSurfaceFormats set to a value (%u) that is greater than the value (%u) that was returned " |
| 773 | "when pSurfaceFormatCount was NULL.", |
| 774 | *pSurfaceFormatCount, prev_format_count); |
| 775 | } |
| 776 | } |
| 777 | return skip; |
| 778 | } |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 779 | |
| 780 | bool BestPractices::PreCallValidateQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo* pBindInfo, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 781 | VkFence fence) const { |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 782 | bool skip = false; |
| 783 | |
| 784 | for (uint32_t bindIdx = 0; bindIdx < bindInfoCount; bindIdx++) { |
| 785 | const VkBindSparseInfo& bindInfo = pBindInfo[bindIdx]; |
| 786 | // 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] | 787 | std::unordered_set<const IMAGE_STATE*> sparse_images; |
| 788 | // Track images getting metadata bound by this call in a set, it'll be recorded into the image_state |
| 789 | // in RecordQueueBindSparse. |
| 790 | std::unordered_set<const IMAGE_STATE*> sparse_images_with_metadata; |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 791 | // If we're binding sparse image memory make sure reqs were queried and note if metadata is required and bound |
| 792 | for (uint32_t i = 0; i < bindInfo.imageBindCount; ++i) { |
| 793 | const auto& image_bind = bindInfo.pImageBinds[i]; |
| 794 | auto image_state = GetImageState(image_bind.image); |
| 795 | if (!image_state) |
| 796 | continue; // Param/Object validation should report image_bind.image handles being invalid, so just skip here. |
| 797 | sparse_images.insert(image_state); |
| 798 | if (image_state->createInfo.flags & VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT) { |
| 799 | if (!image_state->get_sparse_reqs_called || image_state->sparse_requirements.empty()) { |
| 800 | // For now just warning if sparse image binding occurs without calling to get reqs first |
| 801 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 802 | HandleToUint64(image_state->image), kVUID_Core_MemTrack_InvalidState, |
| 803 | "vkQueueBindSparse(): Binding sparse memory to %s without first calling " |
| 804 | "vkGetImageSparseMemoryRequirements[2KHR]() to retrieve requirements.", |
| 805 | report_data->FormatHandle(image_state->image).c_str()); |
| 806 | } |
| 807 | } |
| 808 | if (!image_state->memory_requirements_checked) { |
| 809 | // For now just warning if sparse image binding occurs without calling to get reqs first |
| 810 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 811 | HandleToUint64(image_state->image), kVUID_Core_MemTrack_InvalidState, |
| 812 | "vkQueueBindSparse(): Binding sparse memory to %s without first calling " |
| 813 | "vkGetImageMemoryRequirements() to retrieve requirements.", |
| 814 | report_data->FormatHandle(image_state->image).c_str()); |
| 815 | } |
| 816 | } |
| 817 | for (uint32_t i = 0; i < bindInfo.imageOpaqueBindCount; ++i) { |
| 818 | const auto& image_opaque_bind = bindInfo.pImageOpaqueBinds[i]; |
| 819 | auto image_state = GetImageState(bindInfo.pImageOpaqueBinds[i].image); |
| 820 | if (!image_state) |
| 821 | continue; // Param/Object validation should report image_bind.image handles being invalid, so just skip here. |
| 822 | sparse_images.insert(image_state); |
| 823 | if (image_state->createInfo.flags & VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT) { |
| 824 | if (!image_state->get_sparse_reqs_called || image_state->sparse_requirements.empty()) { |
| 825 | // For now just warning if sparse image binding occurs without calling to get reqs first |
| 826 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 827 | HandleToUint64(image_state->image), kVUID_Core_MemTrack_InvalidState, |
| 828 | "vkQueueBindSparse(): Binding opaque sparse memory to %s without first calling " |
| 829 | "vkGetImageSparseMemoryRequirements[2KHR]() to retrieve requirements.", |
| 830 | report_data->FormatHandle(image_state->image).c_str()); |
| 831 | } |
| 832 | } |
| 833 | if (!image_state->memory_requirements_checked) { |
| 834 | // For now just warning if sparse image binding occurs without calling to get reqs first |
| 835 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 836 | HandleToUint64(image_state->image), kVUID_Core_MemTrack_InvalidState, |
| 837 | "vkQueueBindSparse(): Binding opaque sparse memory to %s without first calling " |
| 838 | "vkGetImageMemoryRequirements() to retrieve requirements.", |
| 839 | report_data->FormatHandle(image_state->image).c_str()); |
| 840 | } |
| 841 | for (uint32_t j = 0; j < image_opaque_bind.bindCount; ++j) { |
| 842 | 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] | 843 | sparse_images_with_metadata.insert(image_state); |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 844 | } |
| 845 | } |
| 846 | } |
| 847 | for (const auto& sparse_image_state : sparse_images) { |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 848 | if (sparse_image_state->sparse_metadata_required && !sparse_image_state->sparse_metadata_bound && |
| 849 | 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] | 850 | // Warn if sparse image binding metadata required for image with sparse binding, but metadata not bound |
| 851 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 852 | HandleToUint64(sparse_image_state->image), kVUID_Core_MemTrack_InvalidState, |
| 853 | "vkQueueBindSparse(): Binding sparse memory to %s which requires a metadata aspect but no " |
| 854 | "binding with VK_SPARSE_MEMORY_BIND_METADATA_BIT set was made.", |
| 855 | report_data->FormatHandle(sparse_image_state->image).c_str()); |
| 856 | } |
| 857 | } |
| 858 | } |
| 859 | |
| 860 | return skip; |
| 861 | } |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 862 | |
| 863 | void BestPractices::PostCallRecordQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo* pBindInfo, |
| 864 | VkFence fence, VkResult result) { |
| 865 | if (result != VK_SUCCESS) return; |
| 866 | |
| 867 | for (uint32_t bindIdx = 0; bindIdx < bindInfoCount; bindIdx++) { |
| 868 | const VkBindSparseInfo& bindInfo = pBindInfo[bindIdx]; |
| 869 | for (uint32_t i = 0; i < bindInfo.imageOpaqueBindCount; ++i) { |
| 870 | const auto& image_opaque_bind = bindInfo.pImageOpaqueBinds[i]; |
| 871 | auto image_state = GetImageState(bindInfo.pImageOpaqueBinds[i].image); |
| 872 | if (!image_state) |
| 873 | continue; // Param/Object validation should report image_bind.image handles being invalid, so just skip here. |
| 874 | for (uint32_t j = 0; j < image_opaque_bind.bindCount; ++j) { |
| 875 | if (image_opaque_bind.pBinds[j].flags & VK_SPARSE_MEMORY_BIND_METADATA_BIT) { |
| 876 | image_state->sparse_metadata_bound = true; |
| 877 | } |
| 878 | } |
| 879 | } |
| 880 | } |
| 881 | } |
Camden Stocker | 0e0f89b | 2019-10-16 12:24:31 -0700 | [diff] [blame] | 882 | |
| 883 | bool BestPractices::PreCallValidateCmdClearAttachments(VkCommandBuffer commandBuffer, uint32_t attachmentCount, |
Camden Stocker | f55721f | 2019-09-09 11:04:49 -0600 | [diff] [blame] | 884 | const VkClearAttachment* pAttachments, uint32_t rectCount, |
| 885 | const VkClearRect* pRects) const { |
Camden Stocker | 0e0f89b | 2019-10-16 12:24:31 -0700 | [diff] [blame] | 886 | bool skip = false; |
| 887 | const CMD_BUFFER_STATE* cb_node = GetCBState(commandBuffer); |
| 888 | if (!cb_node) return skip; |
| 889 | |
Camden Stocker | f55721f | 2019-09-09 11:04:49 -0600 | [diff] [blame] | 890 | // 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] | 891 | if (!cb_node->hasDrawCmd && (cb_node->activeRenderPassBeginInfo.renderArea.extent.width == pRects[0].rect.extent.width) && |
| 892 | (cb_node->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) { |
| 893 | // There are times where app needs to use ClearAttachments (generally when reusing a buffer inside of a render pass) |
| 894 | // This warning should be made more specific. It'd be best to avoid triggering this test if it's a use that must call |
| 895 | // CmdClearAttachments. |
| 896 | skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 427beff | 2019-12-20 11:26:20 -0700 | [diff] [blame] | 897 | HandleToUint64(commandBuffer), kVUID_BestPractices_DrawState_ClearCmdBeforeDraw, |
Camden Stocker | 0e0f89b | 2019-10-16 12:24:31 -0700 | [diff] [blame] | 898 | "vkCmdClearAttachments() issued on %s prior to any Draw Cmds. It is recommended you " |
| 899 | "use RenderPass LOAD_OP_CLEAR on Attachments prior to any Draw.", |
| 900 | report_data->FormatHandle(commandBuffer).c_str()); |
| 901 | } |
| 902 | |
Camden Stocker | f55721f | 2019-09-09 11:04:49 -0600 | [diff] [blame] | 903 | return skip; |
Camden Stocker | 0e0f89b | 2019-10-16 12:24:31 -0700 | [diff] [blame] | 904 | } |