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