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