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