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