Nathaniel Cesario | 56a9665 | 2020-12-30 13:23:42 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2015-2021 The Khronos Group Inc. |
| 2 | * Copyright (c) 2015-2021 Valve Corporation |
| 3 | * Copyright (c) 2015-2021 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" |
Sam Walls | d7ab6db | 2020-06-19 20:41:54 +0100 | [diff] [blame] | 23 | #include "shader_validation.h" |
Jeremy Gebben | a3705f4 | 2021-01-19 16:47:43 -0700 | [diff] [blame] | 24 | #include "sync_utils.h" |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 25 | |
| 26 | #include <string> |
Sam Walls | 8e77e4f | 2020-03-16 20:47:40 +0000 | [diff] [blame] | 27 | #include <bitset> |
Sam Walls | d7ab6db | 2020-06-19 20:41:54 +0100 | [diff] [blame] | 28 | #include <memory> |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 29 | |
Attilio Provenzano | 19d6a98 | 2020-02-27 12:41:41 +0000 | [diff] [blame] | 30 | struct VendorSpecificInfo { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 31 | EnableFlags vendor_id; |
Attilio Provenzano | 19d6a98 | 2020-02-27 12:41:41 +0000 | [diff] [blame] | 32 | std::string name; |
| 33 | }; |
| 34 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 35 | const std::map<BPVendorFlagBits, VendorSpecificInfo> kVendorInfo = { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 36 | {kBPVendorArm, {vendor_specific_arm, "Arm"}}, |
Attilio Provenzano | 19d6a98 | 2020-02-27 12:41:41 +0000 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | bool BestPractices::VendorCheckEnabled(BPVendorFlags vendors) const { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 40 | for (const auto& vendor : kVendorInfo) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 41 | if (vendors & vendor.first && enabled[vendor.second.vendor_id]) { |
Attilio Provenzano | 19d6a98 | 2020-02-27 12:41:41 +0000 | [diff] [blame] | 42 | return true; |
| 43 | } |
| 44 | } |
| 45 | return false; |
| 46 | } |
| 47 | |
| 48 | const char* VendorSpecificTag(BPVendorFlags vendors) { |
| 49 | // Cache built vendor tags in a map |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame] | 50 | static layer_data::unordered_map<BPVendorFlags, std::string> tag_map; |
Attilio Provenzano | 19d6a98 | 2020-02-27 12:41:41 +0000 | [diff] [blame] | 51 | |
| 52 | auto res = tag_map.find(vendors); |
| 53 | if (res == tag_map.end()) { |
| 54 | // Build the vendor tag string |
| 55 | std::stringstream vendor_tag; |
| 56 | |
| 57 | vendor_tag << "["; |
| 58 | bool first_vendor = true; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 59 | for (const auto& vendor : kVendorInfo) { |
Attilio Provenzano | 19d6a98 | 2020-02-27 12:41:41 +0000 | [diff] [blame] | 60 | if (vendors & vendor.first) { |
| 61 | if (!first_vendor) { |
| 62 | vendor_tag << ", "; |
| 63 | } |
| 64 | vendor_tag << vendor.second.name; |
| 65 | first_vendor = false; |
| 66 | } |
| 67 | } |
| 68 | vendor_tag << "]"; |
| 69 | |
| 70 | tag_map[vendors] = vendor_tag.str(); |
| 71 | res = tag_map.find(vendors); |
| 72 | } |
| 73 | |
| 74 | return res->second.c_str(); |
| 75 | } |
| 76 | |
Mark Lobodzinski | 6167e10 | 2020-02-24 17:03:55 -0700 | [diff] [blame] | 77 | const char* DepReasonToString(ExtDeprecationReason reason) { |
| 78 | switch (reason) { |
| 79 | case kExtPromoted: |
| 80 | return "promoted to"; |
| 81 | break; |
| 82 | case kExtObsoleted: |
| 83 | return "obsoleted by"; |
| 84 | break; |
| 85 | case kExtDeprecated: |
| 86 | return "deprecated by"; |
| 87 | break; |
| 88 | default: |
| 89 | return ""; |
| 90 | break; |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | bool BestPractices::ValidateDeprecatedExtensions(const char* api_name, const char* extension_name, uint32_t version, |
| 95 | const char* vuid) const { |
| 96 | bool skip = false; |
| 97 | auto dep_info_it = deprecated_extensions.find(extension_name); |
| 98 | if (dep_info_it != deprecated_extensions.end()) { |
| 99 | auto dep_info = dep_info_it->second; |
Mark Lobodzinski | 6a14970 | 2020-05-14 12:21:34 -0600 | [diff] [blame] | 100 | if (((dep_info.target.compare("VK_VERSION_1_1") == 0) && (version >= VK_API_VERSION_1_1)) || |
| 101 | ((dep_info.target.compare("VK_VERSION_1_2") == 0) && (version >= VK_API_VERSION_1_2))) { |
Mark Lobodzinski | 6167e10 | 2020-02-24 17:03:55 -0700 | [diff] [blame] | 102 | skip |= |
| 103 | LogWarning(instance, vuid, "%s(): Attempting to enable deprecated extension %s, but this extension has been %s %s.", |
| 104 | api_name, extension_name, DepReasonToString(dep_info.reason), (dep_info.target).c_str()); |
Mark Lobodzinski | 6a14970 | 2020-05-14 12:21:34 -0600 | [diff] [blame] | 105 | } else if (dep_info.target.find("VK_VERSION") == std::string::npos) { |
Mark Lobodzinski | 6167e10 | 2020-02-24 17:03:55 -0700 | [diff] [blame] | 106 | if (dep_info.target.length() == 0) { |
| 107 | skip |= LogWarning(instance, vuid, |
| 108 | "%s(): Attempting to enable deprecated extension %s, but this extension has been deprecated " |
| 109 | "without replacement.", |
| 110 | api_name, extension_name); |
| 111 | } else { |
| 112 | skip |= LogWarning(instance, vuid, |
| 113 | "%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 | } |
| 116 | } |
| 117 | } |
| 118 | return skip; |
| 119 | } |
| 120 | |
Mark Lobodzinski | 057724a | 2020-11-09 17:13:18 -0700 | [diff] [blame] | 121 | bool BestPractices::ValidateSpecialUseExtensions(const char* api_name, const char* extension_name, const char* vuid) const { |
| 122 | bool skip = false; |
| 123 | auto dep_info_it = special_use_extensions.find(extension_name); |
| 124 | |
| 125 | if (dep_info_it != special_use_extensions.end()) { |
| 126 | auto special_uses = dep_info_it->second; |
| 127 | std::string message("is intended to support the following uses: "); |
| 128 | if (special_uses.find("cadsupport") != std::string::npos) { |
| 129 | message.append("specialized functionality used by CAD/CAM applications, "); |
| 130 | } |
| 131 | if (special_uses.find("d3demulation") != std::string::npos) { |
| 132 | message.append("D3D emulation layers, and applications ported from D3D, by adding functionality specific to D3D, "); |
| 133 | } |
| 134 | if (special_uses.find("devtools") != std::string::npos) { |
| 135 | message.append(" developer tools such as capture-replay libraries, "); |
| 136 | } |
| 137 | if (special_uses.find("debugging") != std::string::npos) { |
| 138 | message.append("use by applications when debugging, "); |
| 139 | } |
| 140 | if (special_uses.find("glemulation") != std::string::npos) { |
| 141 | message.append( |
| 142 | "OpenGL and/or OpenGL ES emulation layers, and applications ported from those APIs, by adding functionality " |
| 143 | "specific to those APIs, "); |
| 144 | } |
| 145 | message.append("and it is strongly recommended that they be otherwise avoided"); |
| 146 | |
| 147 | skip |= LogWarning(instance, vuid, "%s(): Attempting to enable extension %s, but this extension %s.", api_name, |
| 148 | extension_name, message.c_str()); |
| 149 | } |
| 150 | return skip; |
| 151 | } |
| 152 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 153 | bool BestPractices::PreCallValidateCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 154 | VkInstance* pInstance) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 155 | bool skip = false; |
| 156 | |
| 157 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
| 158 | if (white_list(pCreateInfo->ppEnabledExtensionNames[i], kDeviceExtensionNames)) { |
Camden Stocker | 11ecf51 | 2020-01-21 16:06:49 -0800 | [diff] [blame] | 159 | skip |= LogWarning(instance, kVUID_BestPractices_CreateInstance_ExtensionMismatch, |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 160 | "vkCreateInstance(): Attempting to enable Device Extension %s at CreateInstance time.", |
| 161 | pCreateInfo->ppEnabledExtensionNames[i]); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 162 | } |
Mark Lobodzinski | 17d8dc6 | 2020-06-03 08:48:58 -0600 | [diff] [blame] | 163 | uint32_t specified_version = |
| 164 | (pCreateInfo->pApplicationInfo ? pCreateInfo->pApplicationInfo->apiVersion : VK_API_VERSION_1_0); |
| 165 | skip |= ValidateDeprecatedExtensions("CreateInstance", pCreateInfo->ppEnabledExtensionNames[i], specified_version, |
Mark Lobodzinski | 6167e10 | 2020-02-24 17:03:55 -0700 | [diff] [blame] | 166 | kVUID_BestPractices_CreateInstance_DeprecatedExtension); |
Mark Lobodzinski | a431b77 | 2020-11-10 08:12:13 -0700 | [diff] [blame] | 167 | skip |= ValidateSpecialUseExtensions("CreateInstance", pCreateInfo->ppEnabledExtensionNames[i], |
| 168 | kVUID_BestPractices_CreateInstance_SpecialUseExtension); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | return skip; |
| 172 | } |
| 173 | |
| 174 | void BestPractices::PreCallRecordCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, |
| 175 | VkInstance* pInstance) { |
Mark Lobodzinski | 97484d6 | 2020-03-03 11:57:41 -0700 | [diff] [blame] | 176 | ValidationStateTracker::PreCallRecordCreateInstance(pCreateInfo, pAllocator, pInstance); |
Sam Walls | 53bf765 | 2020-04-21 17:35:15 +0100 | [diff] [blame] | 177 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 178 | if (pCreateInfo != nullptr && pCreateInfo->pApplicationInfo != nullptr) { |
Sam Walls | 53bf765 | 2020-04-21 17:35:15 +0100 | [diff] [blame] | 179 | instance_api_version = pCreateInfo->pApplicationInfo->apiVersion; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 180 | } else { |
Sam Walls | 53bf765 | 2020-04-21 17:35:15 +0100 | [diff] [blame] | 181 | instance_api_version = 0; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 182 | } |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | bool BestPractices::PreCallValidateCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* pCreateInfo, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 186 | const VkAllocationCallbacks* pAllocator, VkDevice* pDevice) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 187 | bool skip = false; |
| 188 | |
| 189 | // get API version of physical device passed when creating device. |
| 190 | VkPhysicalDeviceProperties physical_device_properties{}; |
| 191 | DispatchGetPhysicalDeviceProperties(physicalDevice, &physical_device_properties); |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 192 | auto device_api_version = physical_device_properties.apiVersion; |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 193 | |
| 194 | // check api versions and warn if instance api Version is higher than version on device. |
| 195 | if (instance_api_version > device_api_version) { |
Mark Lobodzinski | 6088078 | 2020-08-11 08:02:07 -0600 | [diff] [blame] | 196 | std::string inst_api_name = StringAPIVersion(instance_api_version); |
| 197 | std::string dev_api_name = StringAPIVersion(device_api_version); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 198 | |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 199 | skip |= LogWarning(device, kVUID_BestPractices_CreateDevice_API_Mismatch, |
| 200 | "vkCreateDevice(): API Version of current instance, %s is higher than API Version on device, %s", |
| 201 | inst_api_name.c_str(), dev_api_name.c_str()); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
| 205 | if (white_list(pCreateInfo->ppEnabledExtensionNames[i], kInstanceExtensionNames)) { |
Camden Stocker | 11ecf51 | 2020-01-21 16:06:49 -0800 | [diff] [blame] | 206 | skip |= LogWarning(instance, kVUID_BestPractices_CreateDevice_ExtensionMismatch, |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 207 | "vkCreateDevice(): Attempting to enable Instance Extension %s at CreateDevice time.", |
| 208 | pCreateInfo->ppEnabledExtensionNames[i]); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 209 | } |
Mark Lobodzinski | 6167e10 | 2020-02-24 17:03:55 -0700 | [diff] [blame] | 210 | skip |= ValidateDeprecatedExtensions("CreateDevice", pCreateInfo->ppEnabledExtensionNames[i], instance_api_version, |
| 211 | kVUID_BestPractices_CreateDevice_DeprecatedExtension); |
Mark Lobodzinski | a431b77 | 2020-11-10 08:12:13 -0700 | [diff] [blame] | 212 | skip |= ValidateSpecialUseExtensions("CreateInstance", pCreateInfo->ppEnabledExtensionNames[i], |
| 213 | kVUID_BestPractices_CreateDevice_SpecialUseExtension); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 214 | } |
| 215 | |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 216 | const auto bp_pd_state = GetPhysicalDeviceStateBP(physicalDevice); |
| 217 | if ((bp_pd_state->vkGetPhysicalDeviceFeaturesState == UNCALLED) && (pCreateInfo->pEnabledFeatures != NULL)) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 218 | skip |= LogWarning(device, kVUID_BestPractices_CreateDevice_PDFeaturesNotCalled, |
| 219 | "vkCreateDevice() called before getting physical device features from vkGetPhysicalDeviceFeatures()."); |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 220 | } |
| 221 | |
Szilard Papp | 7d2c795 | 2020-06-22 14:38:13 +0100 | [diff] [blame] | 222 | if ((VendorCheckEnabled(kBPVendorArm)) && (pCreateInfo->pEnabledFeatures != nullptr) && |
| 223 | (pCreateInfo->pEnabledFeatures->robustBufferAccess == VK_TRUE)) { |
| 224 | skip |= LogPerformanceWarning( |
| 225 | device, kVUID_BestPractices_CreateDevice_RobustBufferAccess, |
| 226 | "%s vkCreateDevice() called with enabled robustBufferAccess. Use robustBufferAccess as a debugging tool during " |
| 227 | "development. Enabling it causes loss in performance for accesses to uniform buffers and shader storage " |
| 228 | "buffers. Disable robustBufferAccess in release builds. Only leave it enabled if the application use-case " |
| 229 | "requires the additional level of reliability due to the use of unverified user-supplied draw parameters.", |
| 230 | VendorSpecificTag(kBPVendorArm)); |
| 231 | } |
| 232 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 233 | return skip; |
| 234 | } |
| 235 | |
| 236 | bool BestPractices::PreCallValidateCreateBuffer(VkDevice device, const VkBufferCreateInfo* pCreateInfo, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 237 | const VkAllocationCallbacks* pAllocator, VkBuffer* pBuffer) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 238 | bool skip = false; |
| 239 | |
| 240 | if ((pCreateInfo->queueFamilyIndexCount > 1) && (pCreateInfo->sharingMode == VK_SHARING_MODE_EXCLUSIVE)) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 241 | std::stringstream buffer_hex; |
| 242 | buffer_hex << "0x" << std::hex << HandleToUint64(pBuffer); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 243 | |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 244 | skip |= LogWarning( |
| 245 | device, kVUID_BestPractices_SharingModeExclusive, |
| 246 | "Warning: Buffer (%s) specifies a sharing mode of VK_SHARING_MODE_EXCLUSIVE while specifying multiple queues " |
| 247 | "(queueFamilyIndexCount of %" PRIu32 ").", |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 248 | buffer_hex.str().c_str(), pCreateInfo->queueFamilyIndexCount); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | return skip; |
| 252 | } |
| 253 | |
| 254 | bool BestPractices::PreCallValidateCreateImage(VkDevice device, const VkImageCreateInfo* pCreateInfo, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 255 | const VkAllocationCallbacks* pAllocator, VkImage* pImage) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 256 | bool skip = false; |
| 257 | |
| 258 | if ((pCreateInfo->queueFamilyIndexCount > 1) && (pCreateInfo->sharingMode == VK_SHARING_MODE_EXCLUSIVE)) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 259 | std::stringstream image_hex; |
| 260 | image_hex << "0x" << std::hex << HandleToUint64(pImage); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 261 | |
| 262 | skip |= |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 263 | LogWarning(device, kVUID_BestPractices_SharingModeExclusive, |
| 264 | "Warning: Image (%s) specifies a sharing mode of VK_SHARING_MODE_EXCLUSIVE while specifying multiple queues " |
| 265 | "(queueFamilyIndexCount of %" PRIu32 ").", |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 266 | image_hex.str().c_str(), pCreateInfo->queueFamilyIndexCount); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 267 | } |
| 268 | |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 269 | if (VendorCheckEnabled(kBPVendorArm)) { |
| 270 | if (pCreateInfo->samples > kMaxEfficientSamplesArm) { |
| 271 | skip |= LogPerformanceWarning( |
| 272 | device, kVUID_BestPractices_CreateImage_TooLargeSampleCount, |
| 273 | "%s vkCreateImage(): Trying to create an image with %u samples. " |
| 274 | "The hardware revision may not have full throughput for framebuffers with more than %u samples.", |
| 275 | VendorSpecificTag(kBPVendorArm), static_cast<uint32_t>(pCreateInfo->samples), kMaxEfficientSamplesArm); |
| 276 | } |
| 277 | |
| 278 | if (pCreateInfo->samples > VK_SAMPLE_COUNT_1_BIT && !(pCreateInfo->usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT)) { |
| 279 | skip |= LogPerformanceWarning( |
| 280 | device, kVUID_BestPractices_CreateImage_NonTransientMSImage, |
| 281 | "%s vkCreateImage(): Trying to create a multisampled image, but createInfo.usage did not have " |
| 282 | "VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT set. Multisampled images may be resolved on-chip, " |
| 283 | "and do not need to be backed by physical storage. " |
| 284 | "TRANSIENT_ATTACHMENT allows tiled GPUs to not back the multisampled image with physical memory.", |
| 285 | VendorSpecificTag(kBPVendorArm)); |
| 286 | } |
| 287 | } |
| 288 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 289 | return skip; |
| 290 | } |
| 291 | |
Hans-Kristian Arntzen | 5b466db | 2021-03-18 13:59:46 +0100 | [diff] [blame] | 292 | void BestPractices::PreCallRecordDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks *pAllocator) { |
| 293 | ValidationStateTracker::PreCallRecordDestroyImage(device, image, pAllocator); |
| 294 | ReleaseImageUsageState(image); |
| 295 | } |
| 296 | |
Hans-Kristian Arntzen | 92664eb | 2021-03-29 12:19:48 +0200 | [diff] [blame] | 297 | void BestPractices::PreCallRecordDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain, const VkAllocationCallbacks* pAllocator) { |
Tony-LunarG | 299187b | 2021-05-28 09:29:12 -0600 | [diff] [blame] | 298 | if (VK_NULL_HANDLE != swapchain) { |
| 299 | SWAPCHAIN_NODE* chain = GetSwapchainState(swapchain); |
| 300 | for (auto& image : chain->images) { |
| 301 | if (image.image_state) { |
| 302 | ReleaseImageUsageState(image.image_state->image()); |
| 303 | } |
| 304 | } |
Hans-Kristian Arntzen | 92664eb | 2021-03-29 12:19:48 +0200 | [diff] [blame] | 305 | } |
| 306 | ValidationStateTracker::PreCallRecordDestroySwapchainKHR(device, swapchain, pAllocator); |
| 307 | } |
| 308 | |
Hans-Kristian Arntzen | 5b466db | 2021-03-18 13:59:46 +0100 | [diff] [blame] | 309 | IMAGE_STATE_BP* BestPractices::GetImageUsageState(VkImage vk_image) { |
| 310 | auto itr = imageUsageMap.find(vk_image); |
| 311 | if (itr != imageUsageMap.end()) { |
| 312 | return &itr->second; |
| 313 | } else { |
| 314 | auto& state = imageUsageMap[vk_image]; |
| 315 | IMAGE_STATE* image = GetImageState(vk_image); |
| 316 | state.image = image; |
| 317 | state.usages.resize(image->createInfo.arrayLayers); |
| 318 | for (auto& mips : state.usages) { |
| 319 | mips.resize(image->createInfo.mipLevels, IMAGE_SUBRESOURCE_USAGE_BP::UNDEFINED); |
| 320 | } |
| 321 | return &state; |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | void BestPractices::ReleaseImageUsageState(VkImage image) { |
| 326 | auto itr = imageUsageMap.find(image); |
| 327 | if (itr != imageUsageMap.end()) { |
| 328 | imageUsageMap.erase(itr); |
| 329 | } |
| 330 | } |
| 331 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 332 | bool BestPractices::PreCallValidateCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR* pCreateInfo, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 333 | const VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pSwapchain) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 334 | bool skip = false; |
| 335 | |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 336 | const auto* bp_pd_state = GetPhysicalDeviceStateBP(); |
| 337 | if (bp_pd_state) { |
| 338 | if (bp_pd_state->vkGetPhysicalDeviceSurfaceCapabilitiesKHRState == UNCALLED) { |
| 339 | skip |= LogWarning(device, kVUID_BestPractices_Swapchain_GetSurfaceNotCalled, |
| 340 | "vkCreateSwapchainKHR() called before getting surface capabilities from " |
| 341 | "vkGetPhysicalDeviceSurfaceCapabilitiesKHR()."); |
| 342 | } |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 343 | |
Shannon McPherson | 73e58c8 | 2021-03-05 17:14:26 -0700 | [diff] [blame] | 344 | if ((pCreateInfo->presentMode != VK_PRESENT_MODE_FIFO_KHR) && |
| 345 | (bp_pd_state->vkGetPhysicalDeviceSurfacePresentModesKHRState != QUERY_DETAILS)) { |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 346 | skip |= LogWarning(device, kVUID_BestPractices_Swapchain_GetSurfaceNotCalled, |
| 347 | "vkCreateSwapchainKHR() called before getting surface present mode(s) from " |
| 348 | "vkGetPhysicalDeviceSurfacePresentModesKHR()."); |
| 349 | } |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 350 | |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 351 | if (bp_pd_state->vkGetPhysicalDeviceSurfaceFormatsKHRState != QUERY_DETAILS) { |
| 352 | skip |= LogWarning( |
| 353 | device, kVUID_BestPractices_Swapchain_GetSurfaceNotCalled, |
| 354 | "vkCreateSwapchainKHR() called before getting surface format(s) from vkGetPhysicalDeviceSurfaceFormatsKHR()."); |
| 355 | } |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 356 | } |
| 357 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 358 | if ((pCreateInfo->queueFamilyIndexCount > 1) && (pCreateInfo->imageSharingMode == VK_SHARING_MODE_EXCLUSIVE)) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 359 | skip |= |
| 360 | LogWarning(device, kVUID_BestPractices_SharingModeExclusive, |
Mark Lobodzinski | 019f4e3 | 2020-04-13 11:01:35 -0600 | [diff] [blame] | 361 | "Warning: A Swapchain is being created which specifies a sharing mode of VK_SHARING_MODE_EXCLUSIVE while " |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 362 | "specifying multiple queues (queueFamilyIndexCount of %" PRIu32 ").", |
| 363 | pCreateInfo->queueFamilyIndexCount); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 364 | } |
| 365 | |
Szilard Papp | 48a6da3 | 2020-06-10 14:41:59 +0100 | [diff] [blame] | 366 | if (pCreateInfo->minImageCount == 2) { |
| 367 | skip |= LogPerformanceWarning( |
| 368 | device, kVUID_BestPractices_SuboptimalSwapchainImageCount, |
| 369 | "Warning: A Swapchain is being created with minImageCount set to %" PRIu32 |
| 370 | ", which means double buffering is going " |
| 371 | "to be used. Using double buffering and vsync locks rendering to an integer fraction of the vsync rate. In turn, " |
| 372 | "reducing the performance of the application if rendering is slower than vsync. Consider setting minImageCount to " |
| 373 | "3 to use triple buffering to maximize performance in such cases.", |
| 374 | pCreateInfo->minImageCount); |
| 375 | } |
| 376 | |
Szilard Papp | d5f0f81 | 2020-06-22 09:01:29 +0100 | [diff] [blame] | 377 | if (VendorCheckEnabled(kBPVendorArm) && (pCreateInfo->presentMode != VK_PRESENT_MODE_FIFO_KHR)) { |
| 378 | skip |= LogWarning(device, kVUID_BestPractices_CreateSwapchain_PresentMode, |
| 379 | "%s Warning: Swapchain is not being created with presentation mode \"VK_PRESENT_MODE_FIFO_KHR\". " |
| 380 | "Prefer using \"VK_PRESENT_MODE_FIFO_KHR\" to avoid unnecessary CPU and GPU load and save power. " |
| 381 | "Presentation modes which are not FIFO will present the latest available frame and discard other " |
| 382 | "frame(s) if any.", |
| 383 | VendorSpecificTag(kBPVendorArm)); |
| 384 | } |
| 385 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 386 | return skip; |
| 387 | } |
| 388 | |
| 389 | bool BestPractices::PreCallValidateCreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount, |
| 390 | const VkSwapchainCreateInfoKHR* pCreateInfos, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 391 | const VkAllocationCallbacks* pAllocator, |
| 392 | VkSwapchainKHR* pSwapchains) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 393 | bool skip = false; |
| 394 | |
| 395 | for (uint32_t i = 0; i < swapchainCount; i++) { |
| 396 | if ((pCreateInfos[i].queueFamilyIndexCount > 1) && (pCreateInfos[i].imageSharingMode == VK_SHARING_MODE_EXCLUSIVE)) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 397 | skip |= LogWarning( |
| 398 | device, kVUID_BestPractices_SharingModeExclusive, |
| 399 | "Warning: A shared swapchain (index %" PRIu32 |
| 400 | ") is being created which specifies a sharing mode of VK_SHARING_MODE_EXCLUSIVE while specifying multiple " |
| 401 | "queues (queueFamilyIndexCount of %" PRIu32 ").", |
| 402 | i, pCreateInfos[i].queueFamilyIndexCount); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 403 | } |
| 404 | } |
| 405 | |
| 406 | return skip; |
| 407 | } |
| 408 | |
| 409 | bool BestPractices::PreCallValidateCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 410 | const VkAllocationCallbacks* pAllocator, VkRenderPass* pRenderPass) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 411 | bool skip = false; |
| 412 | |
| 413 | for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) { |
| 414 | VkFormat format = pCreateInfo->pAttachments[i].format; |
| 415 | if (pCreateInfo->pAttachments[i].initialLayout == VK_IMAGE_LAYOUT_UNDEFINED) { |
| 416 | if ((FormatIsColor(format) || FormatHasDepth(format)) && |
| 417 | pCreateInfo->pAttachments[i].loadOp == VK_ATTACHMENT_LOAD_OP_LOAD) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 418 | skip |= LogWarning(device, kVUID_BestPractices_RenderPass_Attatchment, |
| 419 | "Render pass has an attachment with loadOp == VK_ATTACHMENT_LOAD_OP_LOAD and " |
| 420 | "initialLayout == VK_IMAGE_LAYOUT_UNDEFINED. This is probably not what you " |
| 421 | "intended. Consider using VK_ATTACHMENT_LOAD_OP_DONT_CARE instead if the " |
| 422 | "image truely is undefined at the start of the render pass."); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 423 | } |
| 424 | if (FormatHasStencil(format) && pCreateInfo->pAttachments[i].stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 425 | skip |= LogWarning(device, kVUID_BestPractices_RenderPass_Attatchment, |
| 426 | "Render pass has an attachment with stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD " |
| 427 | "and initialLayout == VK_IMAGE_LAYOUT_UNDEFINED. This is probably not what you " |
| 428 | "intended. Consider using VK_ATTACHMENT_LOAD_OP_DONT_CARE instead if the " |
| 429 | "image truely is undefined at the start of the render pass."); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 430 | } |
| 431 | } |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 432 | |
| 433 | const auto& attachment = pCreateInfo->pAttachments[i]; |
| 434 | if (attachment.samples > VK_SAMPLE_COUNT_1_BIT) { |
| 435 | bool access_requires_memory = |
| 436 | attachment.loadOp == VK_ATTACHMENT_LOAD_OP_LOAD || attachment.storeOp == VK_ATTACHMENT_STORE_OP_STORE; |
| 437 | |
| 438 | if (FormatHasStencil(format)) { |
| 439 | access_requires_memory |= attachment.stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD || |
| 440 | attachment.stencilStoreOp == VK_ATTACHMENT_STORE_OP_STORE; |
| 441 | } |
| 442 | |
| 443 | if (access_requires_memory) { |
| 444 | skip |= LogPerformanceWarning( |
| 445 | device, kVUID_BestPractices_CreateRenderPass_ImageRequiresMemory, |
| 446 | "Attachment %u in the VkRenderPass is a multisampled image with %u samples, but it uses loadOp/storeOp " |
| 447 | "which requires accessing data from memory. Multisampled images should always be loadOp = CLEAR or DONT_CARE, " |
| 448 | "storeOp = DONT_CARE. This allows the implementation to use lazily allocated memory effectively.", |
| 449 | i, static_cast<uint32_t>(attachment.samples)); |
| 450 | } |
| 451 | } |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | for (uint32_t dependency = 0; dependency < pCreateInfo->dependencyCount; dependency++) { |
| 455 | skip |= CheckPipelineStageFlags("vkCreateRenderPass", pCreateInfo->pDependencies[dependency].srcStageMask); |
| 456 | skip |= CheckPipelineStageFlags("vkCreateRenderPass", pCreateInfo->pDependencies[dependency].dstStageMask); |
| 457 | } |
| 458 | |
| 459 | return skip; |
| 460 | } |
| 461 | |
Tony-LunarG | 767180f | 2020-04-23 14:03:59 -0600 | [diff] [blame] | 462 | bool BestPractices::ValidateAttachments(const VkRenderPassCreateInfo2* rpci, uint32_t attachmentCount, |
| 463 | const VkImageView* image_views) const { |
| 464 | bool skip = false; |
| 465 | |
| 466 | // Check for non-transient attachments that should be transient and vice versa |
| 467 | for (uint32_t i = 0; i < attachmentCount; ++i) { |
Hans-Kristian Arntzen | 69ace7d | 2021-04-28 14:17:19 +0200 | [diff] [blame] | 468 | const auto& attachment = rpci->pAttachments[i]; |
Tony-LunarG | 767180f | 2020-04-23 14:03:59 -0600 | [diff] [blame] | 469 | bool attachment_should_be_transient = |
| 470 | (attachment.loadOp != VK_ATTACHMENT_LOAD_OP_LOAD && attachment.storeOp != VK_ATTACHMENT_STORE_OP_STORE); |
| 471 | |
| 472 | if (FormatHasStencil(attachment.format)) { |
| 473 | attachment_should_be_transient &= (attachment.stencilLoadOp != VK_ATTACHMENT_LOAD_OP_LOAD && |
| 474 | attachment.stencilStoreOp != VK_ATTACHMENT_STORE_OP_STORE); |
| 475 | } |
| 476 | |
| 477 | auto view_state = GetImageViewState(image_views[i]); |
| 478 | if (view_state) { |
Hans-Kristian Arntzen | 69ace7d | 2021-04-28 14:17:19 +0200 | [diff] [blame] | 479 | const auto& ivci = view_state->create_info; |
| 480 | const auto& ici = GetImageState(ivci.image)->createInfo; |
Tony-LunarG | 767180f | 2020-04-23 14:03:59 -0600 | [diff] [blame] | 481 | |
| 482 | bool image_is_transient = (ici.usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) != 0; |
| 483 | |
| 484 | // The check for an image that should not be transient applies to all GPUs |
| 485 | if (!attachment_should_be_transient && image_is_transient) { |
| 486 | skip |= LogPerformanceWarning( |
| 487 | device, kVUID_BestPractices_CreateFramebuffer_AttachmentShouldNotBeTransient, |
| 488 | "Attachment %u in VkFramebuffer uses loadOp/storeOps which need to access physical memory, " |
| 489 | "but the image backing the image view has VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT set. " |
| 490 | "Physical memory will need to be backed lazily to this image, potentially causing stalls.", |
| 491 | i); |
| 492 | } |
| 493 | |
| 494 | bool supports_lazy = false; |
| 495 | for (uint32_t j = 0; j < phys_dev_mem_props.memoryTypeCount; j++) { |
| 496 | if (phys_dev_mem_props.memoryTypes[j].propertyFlags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) { |
| 497 | supports_lazy = true; |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | // The check for an image that should be transient only applies to GPUs supporting |
| 502 | // lazily allocated memory |
| 503 | if (supports_lazy && attachment_should_be_transient && !image_is_transient) { |
| 504 | skip |= LogPerformanceWarning( |
| 505 | device, kVUID_BestPractices_CreateFramebuffer_AttachmentShouldBeTransient, |
| 506 | "Attachment %u in VkFramebuffer uses loadOp/storeOps which never have to be backed by physical memory, " |
| 507 | "but the image backing the image view does not have VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT set. " |
| 508 | "You can save physical memory by using transient attachment backed by lazily allocated memory here.", |
| 509 | i); |
| 510 | } |
| 511 | } |
| 512 | } |
| 513 | return skip; |
| 514 | } |
| 515 | |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 516 | bool BestPractices::PreCallValidateCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, |
| 517 | const VkAllocationCallbacks* pAllocator, VkFramebuffer* pFramebuffer) const { |
| 518 | bool skip = false; |
| 519 | |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 520 | auto rp_state = GetRenderPassState(pCreateInfo->renderPass); |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 521 | if (rp_state && !(pCreateInfo->flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT)) { |
Tony-LunarG | 767180f | 2020-04-23 14:03:59 -0600 | [diff] [blame] | 522 | skip = ValidateAttachments(rp_state->createInfo.ptr(), pCreateInfo->attachmentCount, pCreateInfo->pAttachments); |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | return skip; |
| 526 | } |
| 527 | |
Sam Walls | e746d52 | 2020-03-16 21:20:23 +0000 | [diff] [blame] | 528 | bool BestPractices::PreCallValidateAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo* pAllocateInfo, |
| 529 | VkDescriptorSet* pDescriptorSets, void* ads_state_data) const { |
| 530 | bool skip = false; |
| 531 | skip |= ValidationStateTracker::PreCallValidateAllocateDescriptorSets(device, pAllocateInfo, pDescriptorSets, ads_state_data); |
| 532 | |
| 533 | if (!skip) { |
| 534 | const auto& pool_handle = pAllocateInfo->descriptorPool; |
| 535 | auto iter = descriptor_pool_freed_count.find(pool_handle); |
| 536 | // if the number of freed sets > 0, it implies they could be recycled instead if desirable |
| 537 | // this warning is specific to Arm |
| 538 | if (VendorCheckEnabled(kBPVendorArm) && iter != descriptor_pool_freed_count.end() && iter->second > 0) { |
| 539 | skip |= LogPerformanceWarning( |
| 540 | device, kVUID_BestPractices_AllocateDescriptorSets_SuboptimalReuse, |
| 541 | "%s Descriptor set memory was allocated via vkAllocateDescriptorSets() for sets which were previously freed in the " |
| 542 | "same logical device. On some drivers or architectures it may be most optimal to re-use existing descriptor sets.", |
| 543 | VendorSpecificTag(kBPVendorArm)); |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | return skip; |
| 548 | } |
| 549 | |
Mark Lobodzinski | 84101d7 | 2020-04-24 09:43:48 -0600 | [diff] [blame] | 550 | void BestPractices::ManualPostCallRecordAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo* pAllocateInfo, |
| 551 | VkDescriptorSet* pDescriptorSets, VkResult result, void* ads_state) { |
Sam Walls | e746d52 | 2020-03-16 21:20:23 +0000 | [diff] [blame] | 552 | if (result == VK_SUCCESS) { |
| 553 | // find the free count for the pool we allocated into |
| 554 | auto iter = descriptor_pool_freed_count.find(pAllocateInfo->descriptorPool); |
| 555 | if (iter != descriptor_pool_freed_count.end()) { |
| 556 | // we record successful allocations by subtracting the allocation count from the last recorded free count |
| 557 | const auto alloc_count = pAllocateInfo->descriptorSetCount; |
| 558 | // clamp the unsigned subtraction to the range [0, last_free_count] |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 559 | if (iter->second > alloc_count) { |
Sam Walls | e746d52 | 2020-03-16 21:20:23 +0000 | [diff] [blame] | 560 | iter->second -= alloc_count; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 561 | } else { |
Sam Walls | e746d52 | 2020-03-16 21:20:23 +0000 | [diff] [blame] | 562 | iter->second = 0; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 563 | } |
Sam Walls | e746d52 | 2020-03-16 21:20:23 +0000 | [diff] [blame] | 564 | } |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | void BestPractices::PostCallRecordFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t descriptorSetCount, |
| 569 | const VkDescriptorSet* pDescriptorSets, VkResult result) { |
| 570 | ValidationStateTracker::PostCallRecordFreeDescriptorSets(device, descriptorPool, descriptorSetCount, pDescriptorSets, result); |
| 571 | if (result == VK_SUCCESS) { |
| 572 | // we want to track frees because we're interested in suggesting re-use |
| 573 | auto iter = descriptor_pool_freed_count.find(descriptorPool); |
| 574 | if (iter == descriptor_pool_freed_count.end()) { |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame] | 575 | descriptor_pool_freed_count.emplace(descriptorPool, descriptorSetCount); |
Sam Walls | e746d52 | 2020-03-16 21:20:23 +0000 | [diff] [blame] | 576 | } else { |
| 577 | iter->second += descriptorSetCount; |
| 578 | } |
| 579 | } |
| 580 | } |
| 581 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 582 | bool BestPractices::PreCallValidateAllocateMemory(VkDevice device, const VkMemoryAllocateInfo* pAllocateInfo, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 583 | const VkAllocationCallbacks* pAllocator, VkDeviceMemory* pMemory) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 584 | bool skip = false; |
| 585 | |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 586 | if (num_mem_objects + 1 > kMemoryObjectWarningLimit) { |
Mark Lobodzinski | f95a266 | 2020-01-29 15:43:32 -0700 | [diff] [blame] | 587 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_AllocateMemory_TooManyObjects, |
| 588 | "Performance Warning: This app has > %" PRIu32 " memory objects.", kMemoryObjectWarningLimit); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 589 | } |
| 590 | |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 591 | if (pAllocateInfo->allocationSize < kMinDeviceAllocationSize) { |
| 592 | skip |= LogPerformanceWarning( |
| 593 | device, kVUID_BestPractices_AllocateMemory_SmallAllocation, |
Jeremy Gebben | da6b48f | 2021-05-13 10:46:18 -0600 | [diff] [blame] | 594 | "vkAllocateMemory(): Allocating a VkDeviceMemory of size %" PRIu64 ". This is a very small allocation (current " |
| 595 | "threshold is %" PRIu64 " bytes). " |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 596 | "You should make large allocations and sub-allocate from one large VkDeviceMemory.", |
| 597 | pAllocateInfo->allocationSize, kMinDeviceAllocationSize); |
| 598 | } |
| 599 | |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 600 | // TODO: Insert get check for GetPhysicalDeviceMemoryProperties once the state is tracked in the StateTracker |
| 601 | |
| 602 | return skip; |
| 603 | } |
| 604 | |
Mark Lobodzinski | 84101d7 | 2020-04-24 09:43:48 -0600 | [diff] [blame] | 605 | void BestPractices::ManualPostCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo* pAllocateInfo, |
| 606 | const VkAllocationCallbacks* pAllocator, VkDeviceMemory* pMemory, |
| 607 | VkResult result) { |
Mark Lobodzinski | 205b7a0 | 2020-02-21 13:23:17 -0700 | [diff] [blame] | 608 | if (result != VK_SUCCESS) { |
| 609 | static std::vector<VkResult> error_codes = {VK_ERROR_OUT_OF_HOST_MEMORY, VK_ERROR_OUT_OF_DEVICE_MEMORY, |
| 610 | VK_ERROR_TOO_MANY_OBJECTS, VK_ERROR_INVALID_EXTERNAL_HANDLE, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 611 | VK_ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS}; |
Mark Lobodzinski | 205b7a0 | 2020-02-21 13:23:17 -0700 | [diff] [blame] | 612 | static std::vector<VkResult> success_codes = {}; |
Nathaniel Cesario | db3f43f | 2021-05-12 09:08:23 -0600 | [diff] [blame] | 613 | ValidateReturnCodes("vkAllocateMemory", result, error_codes, success_codes); |
Mark Lobodzinski | 205b7a0 | 2020-02-21 13:23:17 -0700 | [diff] [blame] | 614 | return; |
| 615 | } |
| 616 | num_mem_objects++; |
| 617 | } |
Camden Stocker | 9738af9 | 2019-10-16 13:54:03 -0700 | [diff] [blame] | 618 | |
Mark Lobodzinski | de15e58 | 2020-04-29 08:06:00 -0600 | [diff] [blame] | 619 | void BestPractices::ValidateReturnCodes(const char* api_name, VkResult result, const std::vector<VkResult>& error_codes, |
| 620 | const std::vector<VkResult>& success_codes) const { |
Mark Lobodzinski | 205b7a0 | 2020-02-21 13:23:17 -0700 | [diff] [blame] | 621 | auto error = std::find(error_codes.begin(), error_codes.end(), result); |
| 622 | if (error != error_codes.end()) { |
Gareth Webb | 586c46b | 2021-01-13 11:17:22 +0000 | [diff] [blame] | 623 | static const std::vector<VkResult> common_failure_codes = {VK_ERROR_OUT_OF_DATE_KHR, |
| 624 | VK_ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXT}; |
| 625 | |
| 626 | auto common_failure = std::find(common_failure_codes.begin(), common_failure_codes.end(), result); |
| 627 | if (common_failure != common_failure_codes.end()) { |
| 628 | LogInfo(instance, kVUID_BestPractices_Failure_Result, "%s(): Returned error %s.", api_name, string_VkResult(result)); |
| 629 | } else { |
| 630 | LogWarning(instance, kVUID_BestPractices_Error_Result, "%s(): Returned error %s.", api_name, string_VkResult(result)); |
| 631 | } |
Mark Lobodzinski | 205b7a0 | 2020-02-21 13:23:17 -0700 | [diff] [blame] | 632 | return; |
| 633 | } |
| 634 | auto success = std::find(success_codes.begin(), success_codes.end(), result); |
| 635 | if (success != success_codes.end()) { |
Mark Lobodzinski | e721515 | 2020-05-11 08:21:23 -0600 | [diff] [blame] | 636 | LogInfo(instance, kVUID_BestPractices_NonSuccess_Result, "%s(): Returned non-success return code %s.", api_name, |
| 637 | string_VkResult(result)); |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 638 | } |
| 639 | } |
| 640 | |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 641 | bool BestPractices::PreCallValidateFreeMemory(VkDevice device, VkDeviceMemory memory, |
| 642 | const VkAllocationCallbacks* pAllocator) const { |
Mark Lobodzinski | 91e50bf | 2020-01-14 09:55:11 -0700 | [diff] [blame] | 643 | if (memory == VK_NULL_HANDLE) return false; |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 644 | bool skip = false; |
| 645 | |
Camden Stocker | 9738af9 | 2019-10-16 13:54:03 -0700 | [diff] [blame] | 646 | const DEVICE_MEMORY_STATE* mem_info = ValidationStateTracker::GetDevMemState(memory); |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 647 | |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 648 | for (const auto& node: mem_info->ObjectBindings()) { |
| 649 | const auto& obj = node->Handle(); |
Mark Lobodzinski | 818425a | 2020-03-16 18:19:03 -0600 | [diff] [blame] | 650 | LogObjectList objlist(device); |
| 651 | objlist.add(obj); |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 652 | objlist.add(mem_info->mem()); |
Mark Lobodzinski | 818425a | 2020-03-16 18:19:03 -0600 | [diff] [blame] | 653 | skip |= LogWarning(objlist, layer_name.c_str(), "VK Object %s still has a reference to mem obj %s.", |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 654 | 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] | 655 | } |
| 656 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 657 | return skip; |
| 658 | } |
| 659 | |
| 660 | void BestPractices::PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory memory, const VkAllocationCallbacks* pAllocator) { |
Mark Lobodzinski | 97484d6 | 2020-03-03 11:57:41 -0700 | [diff] [blame] | 661 | ValidationStateTracker::PreCallRecordFreeMemory(device, memory, pAllocator); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 662 | if (memory != VK_NULL_HANDLE) { |
| 663 | num_mem_objects--; |
| 664 | } |
| 665 | } |
| 666 | |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 667 | bool BestPractices::ValidateBindBufferMemory(VkBuffer buffer, VkDeviceMemory memory, const char* api_name) const { |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 668 | bool skip = false; |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 669 | const BUFFER_STATE* buffer_state = GetBufferState(buffer); |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 670 | |
sfricke-samsung | e244119 | 2019-11-06 14:07:57 -0800 | [diff] [blame] | 671 | if (!buffer_state->memory_requirements_checked && !buffer_state->external_memory_handle) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 672 | skip |= LogWarning(device, kVUID_BestPractices_BufferMemReqNotCalled, |
| 673 | "%s: Binding memory to %s but vkGetBufferMemoryRequirements() has not been called on that buffer.", |
| 674 | api_name, report_data->FormatHandle(buffer).c_str()); |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 675 | } |
| 676 | |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 677 | const DEVICE_MEMORY_STATE* mem_state = GetDevMemState(memory); |
| 678 | |
| 679 | if (mem_state->alloc_info.allocationSize == buffer_state->createInfo.size && |
| 680 | mem_state->alloc_info.allocationSize < kMinDedicatedAllocationSize) { |
| 681 | skip |= LogPerformanceWarning( |
| 682 | device, kVUID_BestPractices_SmallDedicatedAllocation, |
| 683 | "%s: Trying to bind %s to a memory block which is fully consumed by the buffer. " |
Jeremy Gebben | da6b48f | 2021-05-13 10:46:18 -0600 | [diff] [blame] | 684 | "The required size of the allocation is %" PRIu64 ", but smaller buffers like this should be sub-allocated from " |
| 685 | "larger memory blocks. (Current threshold is %" PRIu64 " bytes.)", |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 686 | api_name, report_data->FormatHandle(buffer).c_str(), mem_state->alloc_info.allocationSize, kMinDedicatedAllocationSize); |
| 687 | } |
| 688 | |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 689 | return skip; |
| 690 | } |
| 691 | |
| 692 | bool BestPractices::PreCallValidateBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory memory, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 693 | VkDeviceSize memoryOffset) const { |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 694 | bool skip = false; |
| 695 | const char* api_name = "BindBufferMemory()"; |
| 696 | |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 697 | skip |= ValidateBindBufferMemory(buffer, memory, api_name); |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 698 | |
| 699 | return skip; |
| 700 | } |
| 701 | |
| 702 | bool BestPractices::PreCallValidateBindBufferMemory2(VkDevice device, uint32_t bindInfoCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 703 | const VkBindBufferMemoryInfo* pBindInfos) const { |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 704 | char api_name[64]; |
| 705 | bool skip = false; |
| 706 | |
| 707 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 708 | sprintf(api_name, "vkBindBufferMemory2() pBindInfos[%u]", i); |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 709 | skip |= ValidateBindBufferMemory(pBindInfos[i].buffer, pBindInfos[i].memory, api_name); |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | return skip; |
| 713 | } |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 714 | |
| 715 | bool BestPractices::PreCallValidateBindBufferMemory2KHR(VkDevice device, uint32_t bindInfoCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 716 | const VkBindBufferMemoryInfo* pBindInfos) const { |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 717 | char api_name[64]; |
| 718 | bool skip = false; |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 719 | |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 720 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 721 | sprintf(api_name, "vkBindBufferMemory2KHR() pBindInfos[%u]", i); |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 722 | skip |= ValidateBindBufferMemory(pBindInfos[i].buffer, pBindInfos[i].memory, api_name); |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | return skip; |
| 726 | } |
| 727 | |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 728 | bool BestPractices::ValidateBindImageMemory(VkImage image, VkDeviceMemory memory, const char* api_name) const { |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 729 | bool skip = false; |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 730 | const IMAGE_STATE* image_state = GetImageState(image); |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 731 | |
sfricke-samsung | 71bc657 | 2020-04-29 15:49:43 -0700 | [diff] [blame] | 732 | if (image_state->disjoint == false) { |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 733 | if (!image_state->memory_requirements_checked && !image_state->external_memory_handle) { |
| 734 | skip |= LogWarning(device, kVUID_BestPractices_ImageMemReqNotCalled, |
| 735 | "%s: Binding memory to %s but vkGetImageMemoryRequirements() has not been called on that image.", |
| 736 | api_name, report_data->FormatHandle(image).c_str()); |
| 737 | } |
| 738 | } else { |
| 739 | // TODO If binding disjoint image then this needs to check that VkImagePlaneMemoryRequirementsInfo was called for each |
| 740 | // plane. |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 741 | } |
| 742 | |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 743 | const DEVICE_MEMORY_STATE* mem_state = GetDevMemState(memory); |
| 744 | |
| 745 | if (mem_state->alloc_info.allocationSize == image_state->requirements.size && |
| 746 | mem_state->alloc_info.allocationSize < kMinDedicatedAllocationSize) { |
| 747 | skip |= LogPerformanceWarning( |
| 748 | device, kVUID_BestPractices_SmallDedicatedAllocation, |
| 749 | "%s: Trying to bind %s to a memory block which is fully consumed by the image. " |
Jeremy Gebben | da6b48f | 2021-05-13 10:46:18 -0600 | [diff] [blame] | 750 | "The required size of the allocation is %" PRIu64 ", but smaller images like this should be sub-allocated from " |
| 751 | "larger memory blocks. (Current threshold is %" PRIu64 " bytes.)", |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 752 | api_name, report_data->FormatHandle(image).c_str(), mem_state->alloc_info.allocationSize, kMinDedicatedAllocationSize); |
| 753 | } |
| 754 | |
| 755 | // If we're binding memory to a image which was created as TRANSIENT and the image supports LAZY allocation, |
| 756 | // make sure this type is actually used. |
| 757 | // This warning will only trigger if this layer is run on a platform that supports LAZILY_ALLOCATED_BIT |
| 758 | // (i.e.most tile - based renderers) |
| 759 | if (image_state->createInfo.usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) { |
| 760 | bool supports_lazy = false; |
| 761 | uint32_t suggested_type = 0; |
| 762 | |
| 763 | for (uint32_t i = 0; i < phys_dev_mem_props.memoryTypeCount; i++) { |
| 764 | if ((1u << i) & image_state->requirements.memoryTypeBits) { |
| 765 | if (phys_dev_mem_props.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) { |
| 766 | supports_lazy = true; |
| 767 | suggested_type = i; |
| 768 | break; |
| 769 | } |
| 770 | } |
| 771 | } |
| 772 | |
| 773 | uint32_t allocated_properties = phys_dev_mem_props.memoryTypes[mem_state->alloc_info.memoryTypeIndex].propertyFlags; |
| 774 | |
| 775 | if (supports_lazy && (allocated_properties & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) == 0) { |
| 776 | skip |= LogPerformanceWarning( |
| 777 | device, kVUID_BestPractices_NonLazyTransientImage, |
Jeremy Gebben | da6b48f | 2021-05-13 10:46:18 -0600 | [diff] [blame] | 778 | "%s: Attempting to bind memory type %u to VkImage which was created with TRANSIENT_ATTACHMENT_BIT," |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 779 | "but this memory type is not LAZILY_ALLOCATED_BIT. You should use memory type %u here instead to save " |
Jeremy Gebben | da6b48f | 2021-05-13 10:46:18 -0600 | [diff] [blame] | 780 | "%" PRIu64 " bytes of physical memory.", |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 781 | api_name, mem_state->alloc_info.memoryTypeIndex, suggested_type, image_state->requirements.size); |
| 782 | } |
| 783 | } |
| 784 | |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 785 | return skip; |
| 786 | } |
| 787 | |
| 788 | bool BestPractices::PreCallValidateBindImageMemory(VkDevice device, VkImage image, VkDeviceMemory memory, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 789 | VkDeviceSize memoryOffset) const { |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 790 | bool skip = false; |
| 791 | const char* api_name = "vkBindImageMemory()"; |
| 792 | |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 793 | skip |= ValidateBindImageMemory(image, memory, api_name); |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 794 | |
| 795 | return skip; |
| 796 | } |
| 797 | |
| 798 | bool BestPractices::PreCallValidateBindImageMemory2(VkDevice device, uint32_t bindInfoCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 799 | const VkBindImageMemoryInfo* pBindInfos) const { |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 800 | char api_name[64]; |
| 801 | bool skip = false; |
| 802 | |
| 803 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 804 | sprintf(api_name, "vkBindImageMemory2() pBindInfos[%u]", i); |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 805 | if (!LvlFindInChain<VkBindImageMemorySwapchainInfoKHR>(pBindInfos[i].pNext)) { |
Tony-LunarG | 5e60b85 | 2020-04-27 11:27:54 -0600 | [diff] [blame] | 806 | skip |= ValidateBindImageMemory(pBindInfos[i].image, pBindInfos[i].memory, api_name); |
| 807 | } |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | return skip; |
| 811 | } |
| 812 | |
| 813 | bool BestPractices::PreCallValidateBindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 814 | const VkBindImageMemoryInfo* pBindInfos) const { |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 815 | char api_name[64]; |
| 816 | bool skip = false; |
| 817 | |
| 818 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 819 | sprintf(api_name, "vkBindImageMemory2KHR() pBindInfos[%u]", i); |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 820 | skip |= ValidateBindImageMemory(pBindInfos[i].image, pBindInfos[i].memory, api_name); |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | return skip; |
| 824 | } |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 825 | |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 826 | static inline bool FormatHasFullThroughputBlendingArm(VkFormat format) { |
| 827 | switch (format) { |
| 828 | case VK_FORMAT_B10G11R11_UFLOAT_PACK32: |
| 829 | case VK_FORMAT_R16_SFLOAT: |
| 830 | case VK_FORMAT_R16G16_SFLOAT: |
| 831 | case VK_FORMAT_R16G16B16_SFLOAT: |
| 832 | case VK_FORMAT_R16G16B16A16_SFLOAT: |
| 833 | case VK_FORMAT_R32_SFLOAT: |
| 834 | case VK_FORMAT_R32G32_SFLOAT: |
| 835 | case VK_FORMAT_R32G32B32_SFLOAT: |
| 836 | case VK_FORMAT_R32G32B32A32_SFLOAT: |
| 837 | return false; |
| 838 | |
| 839 | default: |
| 840 | return true; |
| 841 | } |
| 842 | } |
| 843 | |
| 844 | bool BestPractices::ValidateMultisampledBlendingArm(uint32_t createInfoCount, |
| 845 | const VkGraphicsPipelineCreateInfo* pCreateInfos) const { |
| 846 | bool skip = false; |
| 847 | |
| 848 | for (uint32_t i = 0; i < createInfoCount; i++) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 849 | auto create_info = &pCreateInfos[i]; |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 850 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 851 | if (!create_info->pColorBlendState || !create_info->pMultisampleState || |
| 852 | create_info->pMultisampleState->rasterizationSamples == VK_SAMPLE_COUNT_1_BIT || |
| 853 | create_info->pMultisampleState->sampleShadingEnable) { |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 854 | return skip; |
| 855 | } |
| 856 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 857 | auto rp_state = GetRenderPassState(create_info->renderPass); |
Hans-Kristian Arntzen | 69ace7d | 2021-04-28 14:17:19 +0200 | [diff] [blame] | 858 | const auto& subpass = rp_state->createInfo.pSubpasses[create_info->subpass]; |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 859 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 860 | for (uint32_t j = 0; j < create_info->pColorBlendState->attachmentCount; j++) { |
Hans-Kristian Arntzen | 69ace7d | 2021-04-28 14:17:19 +0200 | [diff] [blame] | 861 | const auto& blend_att = create_info->pColorBlendState->pAttachments[j]; |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 862 | uint32_t att = subpass.pColorAttachments[j].attachment; |
| 863 | |
| 864 | if (att != VK_ATTACHMENT_UNUSED && blend_att.blendEnable && blend_att.colorWriteMask) { |
| 865 | if (!FormatHasFullThroughputBlendingArm(rp_state->createInfo.pAttachments[att].format)) { |
| 866 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_CreatePipelines_MultisampledBlending, |
| 867 | "%s vkCreateGraphicsPipelines() - createInfo #%u: Pipeline is multisampled and " |
| 868 | "color attachment #%u makes use " |
| 869 | "of a format which cannot be blended at full throughput when using MSAA.", |
| 870 | VendorSpecificTag(kBPVendorArm), i, j); |
| 871 | } |
| 872 | } |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | return skip; |
| 877 | } |
| 878 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 879 | bool BestPractices::PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount, |
| 880 | const VkGraphicsPipelineCreateInfo* pCreateInfos, |
Mark Lobodzinski | 2a162a0 | 2019-09-06 11:02:12 -0600 | [diff] [blame] | 881 | const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 882 | void* cgpl_state_data) const { |
Mark Lobodzinski | 8317a3e | 2019-09-20 10:07:08 -0600 | [diff] [blame] | 883 | bool skip = StateTracker::PreCallValidateCreateGraphicsPipelines(device, pipelineCache, createInfoCount, pCreateInfos, |
| 884 | pAllocator, pPipelines, cgpl_state_data); |
Mark Lobodzinski | 8dd14d8 | 2020-04-10 14:16:33 -0600 | [diff] [blame] | 885 | create_graphics_pipeline_api_state* cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state*>(cgpl_state_data); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 886 | |
| 887 | if ((createInfoCount > 1) && (!pipelineCache)) { |
Mark Lobodzinski | f95a266 | 2020-01-29 15:43:32 -0700 | [diff] [blame] | 888 | skip |= LogPerformanceWarning( |
| 889 | device, kVUID_BestPractices_CreatePipelines_MultiplePipelines, |
| 890 | "Performance Warning: This vkCreateGraphicsPipelines call is creating multiple pipelines but is not using a " |
| 891 | "pipeline cache, which may help with performance"); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 892 | } |
| 893 | |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 894 | for (uint32_t i = 0; i < createInfoCount; i++) { |
Hans-Kristian Arntzen | 69ace7d | 2021-04-28 14:17:19 +0200 | [diff] [blame] | 895 | const auto& create_info = pCreateInfos[i]; |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 896 | |
Mark Lobodzinski | 8dd14d8 | 2020-04-10 14:16:33 -0600 | [diff] [blame] | 897 | if (!(cgpl_state->pipe_state[i]->active_shaders & VK_SHADER_STAGE_MESH_BIT_NV)) { |
Hans-Kristian Arntzen | 69ace7d | 2021-04-28 14:17:19 +0200 | [diff] [blame] | 898 | const auto& vertex_input = *create_info.pVertexInputState; |
Mark Lobodzinski | 8dd14d8 | 2020-04-10 14:16:33 -0600 | [diff] [blame] | 899 | uint32_t count = 0; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 900 | for (uint32_t j = 0; j < vertex_input.vertexBindingDescriptionCount; j++) { |
| 901 | if (vertex_input.pVertexBindingDescriptions[j].inputRate == VK_VERTEX_INPUT_RATE_INSTANCE) { |
Mark Lobodzinski | 8dd14d8 | 2020-04-10 14:16:33 -0600 | [diff] [blame] | 902 | count++; |
| 903 | } |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 904 | } |
Mark Lobodzinski | 8dd14d8 | 2020-04-10 14:16:33 -0600 | [diff] [blame] | 905 | if (count > kMaxInstancedVertexBuffers) { |
| 906 | skip |= LogPerformanceWarning( |
| 907 | device, kVUID_BestPractices_CreatePipelines_TooManyInstancedVertexBuffers, |
| 908 | "The pipeline is using %u instanced vertex buffers (current limit: %u), but this can be inefficient on the " |
| 909 | "GPU. If using instanced vertex attributes prefer interleaving them in a single buffer.", |
| 910 | count, kMaxInstancedVertexBuffers); |
| 911 | } |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 912 | } |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 913 | |
Szilard Papp | aaf2da3 | 2020-06-22 10:37:35 +0100 | [diff] [blame] | 914 | if ((pCreateInfos[i].pRasterizationState->depthBiasEnable) && |
| 915 | (pCreateInfos[i].pRasterizationState->depthBiasConstantFactor == 0.0f) && |
Hans-Kristian Arntzen | b214795 | 2021-04-28 14:32:00 +0200 | [diff] [blame] | 916 | (pCreateInfos[i].pRasterizationState->depthBiasSlopeFactor == 0.0f) && |
| 917 | VendorCheckEnabled(kBPVendorArm)) { |
| 918 | skip |= LogPerformanceWarning( |
| 919 | device, kVUID_BestPractices_CreatePipelines_DepthBias_Zero, |
| 920 | "%s Performance Warning: This vkCreateGraphicsPipelines call is created with depthBiasEnable set to true " |
| 921 | "and both depthBiasConstantFactor and depthBiasSlopeFactor are set to 0. This can cause reduced " |
| 922 | "efficiency during rasterization. Consider disabling depthBias or increasing either " |
| 923 | "depthBiasConstantFactor or depthBiasSlopeFactor.", |
| 924 | VendorSpecificTag(kBPVendorArm)); |
Szilard Papp | aaf2da3 | 2020-06-22 10:37:35 +0100 | [diff] [blame] | 925 | } |
| 926 | |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 927 | skip |= VendorCheckEnabled(kBPVendorArm) && ValidateMultisampledBlendingArm(createInfoCount, pCreateInfos); |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 928 | } |
| 929 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 930 | return skip; |
| 931 | } |
| 932 | |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 933 | void BestPractices::ManualPostCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, |
| 934 | const VkGraphicsPipelineCreateInfo* pCreateInfos, |
| 935 | const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines, |
| 936 | VkResult result, void* cgpl_state_data) { |
| 937 | for (size_t i = 0; i < count; i++) { |
| 938 | const auto* cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state*>(cgpl_state_data); |
| 939 | const VkPipeline pipeline_handle = pPipelines[i]; |
| 940 | |
| 941 | // record depth stencil state and color blend states for depth pre-pass tracking purposes |
| 942 | auto gp_cis = graphicsPipelineCIs.find(pipeline_handle); |
| 943 | |
| 944 | // add the tracking state if it doesn't exist |
| 945 | if (gp_cis == graphicsPipelineCIs.end()) { |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame] | 946 | auto result = graphicsPipelineCIs.emplace(pipeline_handle, GraphicsPipelineCIs{}); |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 947 | |
| 948 | if (!result.second) continue; |
| 949 | |
| 950 | gp_cis = result.first; |
| 951 | } |
| 952 | |
Tony-LunarG | 412b1b7 | 2020-07-15 10:30:13 -0600 | [diff] [blame] | 953 | gp_cis->second.colorBlendStateCI = |
| 954 | cgpl_state->pCreateInfos[i].pColorBlendState |
| 955 | ? new safe_VkPipelineColorBlendStateCreateInfo(cgpl_state->pCreateInfos[i].pColorBlendState) |
| 956 | : nullptr; |
| 957 | gp_cis->second.depthStencilStateCI = |
| 958 | cgpl_state->pCreateInfos[i].pDepthStencilState |
| 959 | ? new safe_VkPipelineDepthStencilStateCreateInfo(cgpl_state->pCreateInfos[i].pDepthStencilState) |
| 960 | : nullptr; |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 961 | } |
| 962 | } |
| 963 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 964 | bool BestPractices::PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount, |
| 965 | const VkComputePipelineCreateInfo* pCreateInfos, |
Mark Lobodzinski | 2a162a0 | 2019-09-06 11:02:12 -0600 | [diff] [blame] | 966 | const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 967 | void* ccpl_state_data) const { |
Mark Lobodzinski | 8317a3e | 2019-09-20 10:07:08 -0600 | [diff] [blame] | 968 | bool skip = StateTracker::PreCallValidateCreateComputePipelines(device, pipelineCache, createInfoCount, pCreateInfos, |
| 969 | pAllocator, pPipelines, ccpl_state_data); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 970 | |
| 971 | if ((createInfoCount > 1) && (!pipelineCache)) { |
Mark Lobodzinski | f95a266 | 2020-01-29 15:43:32 -0700 | [diff] [blame] | 972 | skip |= LogPerformanceWarning( |
| 973 | device, kVUID_BestPractices_CreatePipelines_MultiplePipelines, |
| 974 | "Performance Warning: This vkCreateComputePipelines call is creating multiple pipelines but is not using a " |
| 975 | "pipeline cache, which may help with performance"); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 976 | } |
| 977 | |
Sam Walls | d7ab6db | 2020-06-19 20:41:54 +0100 | [diff] [blame] | 978 | if (VendorCheckEnabled(kBPVendorArm)) { |
| 979 | for (size_t i = 0; i < createInfoCount; i++) { |
| 980 | skip |= ValidateCreateComputePipelineArm(pCreateInfos[i]); |
| 981 | } |
| 982 | } |
| 983 | |
| 984 | return skip; |
| 985 | } |
| 986 | |
| 987 | bool BestPractices::ValidateCreateComputePipelineArm(const VkComputePipelineCreateInfo& createInfo) const { |
| 988 | bool skip = false; |
| 989 | auto* module = GetShaderModuleState(createInfo.stage.module); |
sfricke-samsung | 8a7341a | 2021-02-28 07:30:21 -0800 | [diff] [blame] | 990 | // Generate warnings about work group sizes based on active resources. |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 991 | auto entrypoint = module->FindEntrypoint(createInfo.stage.pName, createInfo.stage.stage); |
sfricke-samsung | 8a7341a | 2021-02-28 07:30:21 -0800 | [diff] [blame] | 992 | if (entrypoint == module->end()) return false; |
Sam Walls | d7ab6db | 2020-06-19 20:41:54 +0100 | [diff] [blame] | 993 | |
| 994 | uint32_t x = 1, y = 1, z = 1; |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 995 | module->FindLocalSize(entrypoint, x, y, z); |
Sam Walls | d7ab6db | 2020-06-19 20:41:54 +0100 | [diff] [blame] | 996 | |
| 997 | uint32_t thread_count = x * y * z; |
| 998 | |
| 999 | // Generate a priori warnings about work group sizes. |
| 1000 | if (thread_count > kMaxEfficientWorkGroupThreadCountArm) { |
| 1001 | skip |= LogPerformanceWarning( |
| 1002 | device, kVUID_BestPractices_CreateComputePipelines_ComputeWorkGroupSize, |
| 1003 | "%s vkCreateComputePipelines(): compute shader with work group dimensions (%u, %u, " |
| 1004 | "%u) (%u threads total), has more threads than advised in a single work group. It is advised to use work " |
| 1005 | "groups with less than %u threads, especially when using barrier() or shared memory.", |
| 1006 | VendorSpecificTag(kBPVendorArm), x, y, z, thread_count, kMaxEfficientWorkGroupThreadCountArm); |
| 1007 | } |
| 1008 | |
| 1009 | if (thread_count == 1 || ((x > 1) && (x & (kThreadGroupDispatchCountAlignmentArm - 1))) || |
| 1010 | ((y > 1) && (y & (kThreadGroupDispatchCountAlignmentArm - 1))) || |
| 1011 | ((z > 1) && (z & (kThreadGroupDispatchCountAlignmentArm - 1)))) { |
| 1012 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_CreateComputePipelines_ComputeThreadGroupAlignment, |
| 1013 | "%s vkCreateComputePipelines(): compute shader with work group dimensions (%u, " |
| 1014 | "%u, %u) is not aligned to %u " |
| 1015 | "threads. On Arm Mali architectures, not aligning work group sizes to %u may " |
| 1016 | "leave threads idle on the shader " |
| 1017 | "core.", |
| 1018 | VendorSpecificTag(kBPVendorArm), x, y, z, kThreadGroupDispatchCountAlignmentArm, |
| 1019 | kThreadGroupDispatchCountAlignmentArm); |
| 1020 | } |
| 1021 | |
Sam Walls | d7ab6db | 2020-06-19 20:41:54 +0100 | [diff] [blame] | 1022 | bool has_writeable_descriptors = false; |
locke-lunarg | 63e4daf | 2020-08-17 17:53:25 -0600 | [diff] [blame] | 1023 | bool has_atomic_descriptors = false; |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 1024 | auto accessible_ids = module->MarkAccessibleIds(entrypoint); |
locke-lunarg | 63e4daf | 2020-08-17 17:53:25 -0600 | [diff] [blame] | 1025 | auto descriptor_uses = |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 1026 | module->CollectInterfaceByDescriptorSlot(accessible_ids, &has_writeable_descriptors, &has_atomic_descriptors); |
Sam Walls | d7ab6db | 2020-06-19 20:41:54 +0100 | [diff] [blame] | 1027 | |
| 1028 | unsigned dimensions = 0; |
| 1029 | if (x > 1) dimensions++; |
| 1030 | if (y > 1) dimensions++; |
| 1031 | if (z > 1) dimensions++; |
| 1032 | // Here the dimension will really depend on the dispatch grid, but assume it's 1D. |
| 1033 | dimensions = std::max(dimensions, 1u); |
| 1034 | |
| 1035 | // If we're accessing images, we almost certainly want to have a 2D workgroup for cache reasons. |
| 1036 | // There are some false positives here. We could simply have a shader that does this within a 1D grid, |
| 1037 | // or we may have a linearly tiled image, but these cases are quite unlikely in practice. |
| 1038 | bool accesses_2d = false; |
| 1039 | for (const auto& usage : descriptor_uses) { |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 1040 | auto dim = module->GetShaderResourceDimensionality(usage.second); |
Sam Walls | d7ab6db | 2020-06-19 20:41:54 +0100 | [diff] [blame] | 1041 | if (dim < 0) continue; |
| 1042 | auto spvdim = spv::Dim(dim); |
| 1043 | if (spvdim != spv::Dim1D && spvdim != spv::DimBuffer) accesses_2d = true; |
| 1044 | } |
| 1045 | |
| 1046 | if (accesses_2d && dimensions < 2) { |
| 1047 | LogPerformanceWarning(device, kVUID_BestPractices_CreateComputePipelines_ComputeSpatialLocality, |
| 1048 | "%s vkCreateComputePipelines(): compute shader has work group dimensions (%u, %u, %u), which " |
| 1049 | "suggests a 1D dispatch, but the shader is accessing 2D or 3D images. The shader may be " |
| 1050 | "exhibiting poor spatial locality with respect to one or more shader resources.", |
| 1051 | VendorSpecificTag(kBPVendorArm), x, y, z); |
| 1052 | } |
| 1053 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1054 | return skip; |
| 1055 | } |
| 1056 | |
Jeremy Gebben | a3705f4 | 2021-01-19 16:47:43 -0700 | [diff] [blame] | 1057 | bool BestPractices::CheckPipelineStageFlags(const std::string& api_name, VkPipelineStageFlags flags) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1058 | bool skip = false; |
| 1059 | |
| 1060 | if (flags & VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1061 | skip |= LogWarning(device, kVUID_BestPractices_PipelineStageFlags, |
| 1062 | "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] | 1063 | } else if (flags & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1064 | skip |= LogWarning(device, kVUID_BestPractices_PipelineStageFlags, |
| 1065 | "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] | 1066 | } |
| 1067 | |
| 1068 | return skip; |
| 1069 | } |
| 1070 | |
Jeremy Gebben | a3705f4 | 2021-01-19 16:47:43 -0700 | [diff] [blame] | 1071 | bool BestPractices::CheckPipelineStageFlags(const std::string& api_name, VkPipelineStageFlags2KHR flags) const { |
| 1072 | bool skip = false; |
| 1073 | |
| 1074 | if (flags & VK_PIPELINE_STAGE_2_ALL_GRAPHICS_BIT_KHR) { |
| 1075 | skip |= LogWarning(device, kVUID_BestPractices_PipelineStageFlags, |
| 1076 | "You are using VK_PIPELINE_STAGE_2_ALL_GRAPHICS_BIT_KHR when %s is called\n", api_name.c_str()); |
| 1077 | } else if (flags & VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT_KHR) { |
| 1078 | skip |= LogWarning(device, kVUID_BestPractices_PipelineStageFlags, |
| 1079 | "You are using VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT_KHR when %s is called\n", api_name.c_str()); |
| 1080 | } |
| 1081 | |
| 1082 | return skip; |
| 1083 | } |
| 1084 | |
| 1085 | bool BestPractices::CheckDependencyInfo(const std::string& api_name, const VkDependencyInfoKHR& dep_info) const { |
| 1086 | bool skip = false; |
| 1087 | auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info); |
| 1088 | |
| 1089 | skip |= CheckPipelineStageFlags(api_name, stage_masks.src); |
| 1090 | skip |= CheckPipelineStageFlags(api_name, stage_masks.dst); |
| 1091 | |
| 1092 | return skip; |
| 1093 | } |
| 1094 | |
Mark Lobodzinski | 84101d7 | 2020-04-24 09:43:48 -0600 | [diff] [blame] | 1095 | void BestPractices::ManualPostCallRecordQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo, VkResult result) { |
Mark Lobodzinski | 9b133c1 | 2020-03-10 10:42:56 -0600 | [diff] [blame] | 1096 | for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) { |
| 1097 | auto swapchains_result = pPresentInfo->pResults ? pPresentInfo->pResults[i] : result; |
| 1098 | if (swapchains_result == VK_SUBOPTIMAL_KHR) { |
| 1099 | LogPerformanceWarning( |
| 1100 | pPresentInfo->pSwapchains[i], kVUID_BestPractices_SuboptimalSwapchain, |
| 1101 | "vkQueuePresentKHR: %s :VK_SUBOPTIMAL_KHR was returned. VK_SUBOPTIMAL_KHR - Presentation will still succeed, " |
| 1102 | "subject to the window resize behavior, but the swapchain is no longer configured optimally for the surface it " |
| 1103 | "targets. Applications should query updated surface information and recreate their swapchain at the next " |
| 1104 | "convenient opportunity.", |
| 1105 | report_data->FormatHandle(pPresentInfo->pSwapchains[i]).c_str()); |
| 1106 | } |
| 1107 | } |
| 1108 | } |
| 1109 | |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1110 | bool BestPractices::PreCallValidateQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo* pSubmits, |
| 1111 | VkFence fence) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1112 | bool skip = false; |
| 1113 | |
| 1114 | for (uint32_t submit = 0; submit < submitCount; submit++) { |
| 1115 | for (uint32_t semaphore = 0; semaphore < pSubmits[submit].waitSemaphoreCount; semaphore++) { |
| 1116 | skip |= CheckPipelineStageFlags("vkQueueSubmit", pSubmits[submit].pWaitDstStageMask[semaphore]); |
| 1117 | } |
| 1118 | } |
| 1119 | |
| 1120 | return skip; |
| 1121 | } |
| 1122 | |
Jeremy Gebben | a3705f4 | 2021-01-19 16:47:43 -0700 | [diff] [blame] | 1123 | bool BestPractices::PreCallValidateQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR* pSubmits, |
| 1124 | VkFence fence) const { |
| 1125 | bool skip = false; |
| 1126 | |
| 1127 | for (uint32_t submit = 0; submit < submitCount; submit++) { |
| 1128 | for (uint32_t semaphore = 0; semaphore < pSubmits[submit].waitSemaphoreInfoCount; semaphore++) { |
| 1129 | skip |= CheckPipelineStageFlags("vkQueueSubmit2KHR", pSubmits[submit].pWaitSemaphoreInfos[semaphore].stageMask); |
| 1130 | } |
| 1131 | } |
| 1132 | |
| 1133 | return skip; |
| 1134 | } |
| 1135 | |
Attilio Provenzano | 746e43e | 2020-02-27 11:23:50 +0000 | [diff] [blame] | 1136 | bool BestPractices::PreCallValidateCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo, |
| 1137 | const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool) const { |
| 1138 | bool skip = false; |
| 1139 | |
| 1140 | if (pCreateInfo->flags & VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT) { |
| 1141 | skip |= LogPerformanceWarning( |
| 1142 | device, kVUID_BestPractices_CreateCommandPool_CommandBufferReset, |
| 1143 | "vkCreateCommandPool(): VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT is set. Consider resetting entire " |
| 1144 | "pool instead."); |
| 1145 | } |
| 1146 | |
| 1147 | return skip; |
| 1148 | } |
| 1149 | |
| 1150 | bool BestPractices::PreCallValidateBeginCommandBuffer(VkCommandBuffer commandBuffer, |
| 1151 | const VkCommandBufferBeginInfo* pBeginInfo) const { |
| 1152 | bool skip = false; |
| 1153 | |
| 1154 | if (pBeginInfo->flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT) { |
| 1155 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_BeginCommandBuffer_SimultaneousUse, |
| 1156 | "vkBeginCommandBuffer(): VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT is set."); |
| 1157 | } |
| 1158 | |
Hans-Kristian Arntzen | b214795 | 2021-04-28 14:32:00 +0200 | [diff] [blame] | 1159 | if (!(pBeginInfo->flags & VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT) && VendorCheckEnabled(kBPVendorArm)) { |
| 1160 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_BeginCommandBuffer_OneTimeSubmit, |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1161 | "%s vkBeginCommandBuffer(): VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT is not set. " |
| 1162 | "For best performance on Mali GPUs, consider setting ONE_TIME_SUBMIT by default.", |
| 1163 | VendorSpecificTag(kBPVendorArm)); |
| 1164 | } |
| 1165 | |
Attilio Provenzano | 746e43e | 2020-02-27 11:23:50 +0000 | [diff] [blame] | 1166 | return skip; |
| 1167 | } |
| 1168 | |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1169 | bool BestPractices::PreCallValidateCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1170 | bool skip = false; |
| 1171 | |
| 1172 | skip |= CheckPipelineStageFlags("vkCmdSetEvent", stageMask); |
| 1173 | |
| 1174 | return skip; |
| 1175 | } |
| 1176 | |
Jeremy Gebben | a3705f4 | 2021-01-19 16:47:43 -0700 | [diff] [blame] | 1177 | bool BestPractices::PreCallValidateCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 1178 | const VkDependencyInfoKHR* pDependencyInfo) const { |
| 1179 | return CheckDependencyInfo("vkCmdSetEvent2KHR", *pDependencyInfo); |
| 1180 | } |
| 1181 | |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1182 | bool BestPractices::PreCallValidateCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, |
| 1183 | VkPipelineStageFlags stageMask) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1184 | bool skip = false; |
| 1185 | |
| 1186 | skip |= CheckPipelineStageFlags("vkCmdResetEvent", stageMask); |
| 1187 | |
| 1188 | return skip; |
| 1189 | } |
| 1190 | |
Jeremy Gebben | a3705f4 | 2021-01-19 16:47:43 -0700 | [diff] [blame] | 1191 | bool BestPractices::PreCallValidateCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 1192 | VkPipelineStageFlags2KHR stageMask) const { |
| 1193 | bool skip = false; |
| 1194 | |
| 1195 | skip |= CheckPipelineStageFlags("vkCmdResetEvent2KHR", stageMask); |
| 1196 | |
| 1197 | return skip; |
| 1198 | } |
| 1199 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1200 | bool BestPractices::PreCallValidateCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents, |
| 1201 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 1202 | uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers, |
| 1203 | uint32_t bufferMemoryBarrierCount, |
| 1204 | const VkBufferMemoryBarrier* pBufferMemoryBarriers, |
| 1205 | uint32_t imageMemoryBarrierCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1206 | const VkImageMemoryBarrier* pImageMemoryBarriers) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1207 | bool skip = false; |
| 1208 | |
| 1209 | skip |= CheckPipelineStageFlags("vkCmdWaitEvents", srcStageMask); |
| 1210 | skip |= CheckPipelineStageFlags("vkCmdWaitEvents", dstStageMask); |
| 1211 | |
| 1212 | return skip; |
| 1213 | } |
| 1214 | |
Jeremy Gebben | a3705f4 | 2021-01-19 16:47:43 -0700 | [diff] [blame] | 1215 | bool BestPractices::PreCallValidateCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents, |
| 1216 | const VkDependencyInfoKHR* pDependencyInfos) const { |
| 1217 | bool skip = false; |
| 1218 | for (uint32_t i = 0; i < eventCount; i++) { |
| 1219 | skip = CheckDependencyInfo("vkCmdWaitEvents2KHR", pDependencyInfos[i]); |
| 1220 | } |
| 1221 | |
| 1222 | return skip; |
| 1223 | } |
| 1224 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1225 | bool BestPractices::PreCallValidateCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, |
| 1226 | VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, |
| 1227 | uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers, |
| 1228 | uint32_t bufferMemoryBarrierCount, |
| 1229 | const VkBufferMemoryBarrier* pBufferMemoryBarriers, |
| 1230 | uint32_t imageMemoryBarrierCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1231 | const VkImageMemoryBarrier* pImageMemoryBarriers) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1232 | bool skip = false; |
| 1233 | |
| 1234 | skip |= CheckPipelineStageFlags("vkCmdPipelineBarrier", srcStageMask); |
| 1235 | skip |= CheckPipelineStageFlags("vkCmdPipelineBarrier", dstStageMask); |
| 1236 | |
| 1237 | return skip; |
| 1238 | } |
| 1239 | |
Jeremy Gebben | a3705f4 | 2021-01-19 16:47:43 -0700 | [diff] [blame] | 1240 | bool BestPractices::PreCallValidateCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer, |
| 1241 | const VkDependencyInfoKHR* pDependencyInfo) const { |
| 1242 | return CheckDependencyInfo("vkCmdPipelineBarrier2KHR", *pDependencyInfo); |
| 1243 | } |
| 1244 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1245 | bool BestPractices::PreCallValidateCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1246 | VkQueryPool queryPool, uint32_t query) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1247 | bool skip = false; |
| 1248 | |
Jeremy Gebben | a3705f4 | 2021-01-19 16:47:43 -0700 | [diff] [blame] | 1249 | skip |= CheckPipelineStageFlags("vkCmdWriteTimestamp", static_cast<VkPipelineStageFlags>(pipelineStage)); |
| 1250 | |
| 1251 | return skip; |
| 1252 | } |
| 1253 | |
| 1254 | bool BestPractices::PreCallValidateCmdWriteTimestamp2KHR(VkCommandBuffer commandBuffer, VkPipelineStageFlags2KHR pipelineStage, |
| 1255 | VkQueryPool queryPool, uint32_t query) const { |
| 1256 | bool skip = false; |
| 1257 | |
| 1258 | skip |= CheckPipelineStageFlags("vkCmdWriteTimestamp2KHR", pipelineStage); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1259 | |
| 1260 | return skip; |
| 1261 | } |
| 1262 | |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1263 | void BestPractices::PostCallRecordCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, |
| 1264 | VkPipeline pipeline) { |
| 1265 | StateTracker::PostCallRecordCmdBindPipeline(commandBuffer, pipelineBindPoint, pipeline); |
| 1266 | |
| 1267 | if (pipelineBindPoint == VK_PIPELINE_BIND_POINT_GRAPHICS) { |
| 1268 | // check for depth/blend state tracking |
| 1269 | auto gp_cis = graphicsPipelineCIs.find(pipeline); |
| 1270 | if (gp_cis != graphicsPipelineCIs.end()) { |
| 1271 | auto prepass_state = cbDepthPrePassStates.find(commandBuffer); |
| 1272 | if (prepass_state == cbDepthPrePassStates.end()) { |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame] | 1273 | auto result = cbDepthPrePassStates.emplace(commandBuffer, DepthPrePassState{}); |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1274 | |
| 1275 | if (!result.second) return; |
| 1276 | |
| 1277 | prepass_state = result.first; |
| 1278 | } |
| 1279 | |
| 1280 | const auto* blend_state = gp_cis->second.colorBlendStateCI; |
| 1281 | const auto* stencil_state = gp_cis->second.depthStencilStateCI; |
| 1282 | |
| 1283 | if (blend_state) { |
| 1284 | // assume the pipeline is depth-only unless any of the attachments have color writes enabled |
| 1285 | prepass_state->second.depthOnly = true; |
| 1286 | for (size_t i = 0; i < blend_state->attachmentCount; i++) { |
| 1287 | if (blend_state->pAttachments[i].colorWriteMask != 0) { |
| 1288 | prepass_state->second.depthOnly = false; |
| 1289 | } |
| 1290 | } |
| 1291 | } |
| 1292 | |
| 1293 | // check for depth value usage |
| 1294 | prepass_state->second.depthEqualComparison = false; |
| 1295 | |
| 1296 | if (stencil_state && stencil_state->depthTestEnable) { |
| 1297 | switch (stencil_state->depthCompareOp) { |
| 1298 | case VK_COMPARE_OP_EQUAL: |
| 1299 | case VK_COMPARE_OP_GREATER_OR_EQUAL: |
| 1300 | case VK_COMPARE_OP_LESS_OR_EQUAL: |
| 1301 | prepass_state->second.depthEqualComparison = true; |
| 1302 | break; |
| 1303 | default: |
| 1304 | break; |
| 1305 | } |
| 1306 | } |
| 1307 | } else { |
| 1308 | // reset depth pre-pass tracking |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame] | 1309 | cbDepthPrePassStates.emplace(commandBuffer, DepthPrePassState{}); |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1310 | } |
| 1311 | } |
| 1312 | } |
| 1313 | |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1314 | static inline bool RenderPassUsesAttachmentOnTile(const safe_VkRenderPassCreateInfo2& createInfo, uint32_t attachment) { |
| 1315 | for (uint32_t subpass = 0; subpass < createInfo.subpassCount; subpass++) { |
Hans-Kristian Arntzen | 69ace7d | 2021-04-28 14:17:19 +0200 | [diff] [blame] | 1316 | const auto& subpass_info = createInfo.pSubpasses[subpass]; |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1317 | |
| 1318 | // If an attachment is ever used as a color attachment, |
| 1319 | // resolve attachment or depth stencil attachment, |
| 1320 | // it needs to exist on tile at some point. |
| 1321 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1322 | for (uint32_t i = 0; i < subpass_info.colorAttachmentCount; i++) { |
| 1323 | if (subpass_info.pColorAttachments[i].attachment == attachment) return true; |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1324 | } |
| 1325 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1326 | if (subpass_info.pResolveAttachments) { |
| 1327 | for (uint32_t i = 0; i < subpass_info.colorAttachmentCount; i++) { |
| 1328 | if (subpass_info.pResolveAttachments[i].attachment == attachment) return true; |
| 1329 | } |
| 1330 | } |
| 1331 | |
| 1332 | if (subpass_info.pDepthStencilAttachment && subpass_info.pDepthStencilAttachment->attachment == attachment) return true; |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1333 | } |
| 1334 | |
| 1335 | return false; |
| 1336 | } |
| 1337 | |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 1338 | static inline bool RenderPassUsesAttachmentAsImageOnly(const safe_VkRenderPassCreateInfo2& createInfo, uint32_t attachment) { |
| 1339 | if (RenderPassUsesAttachmentOnTile(createInfo, attachment)) { |
| 1340 | return false; |
| 1341 | } |
| 1342 | |
| 1343 | for (uint32_t subpass = 0; subpass < createInfo.subpassCount; subpass++) { |
Hans-Kristian Arntzen | 69ace7d | 2021-04-28 14:17:19 +0200 | [diff] [blame] | 1344 | const auto& subpassInfo = createInfo.pSubpasses[subpass]; |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 1345 | |
| 1346 | for (uint32_t i = 0; i < subpassInfo.inputAttachmentCount; i++) { |
| 1347 | if (subpassInfo.pInputAttachments[i].attachment == attachment) { |
| 1348 | return true; |
| 1349 | } |
| 1350 | } |
| 1351 | } |
| 1352 | |
| 1353 | return false; |
| 1354 | } |
| 1355 | |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1356 | bool BestPractices::ValidateCmdBeginRenderPass(VkCommandBuffer commandBuffer, RenderPassCreateVersion rp_version, |
| 1357 | const VkRenderPassBeginInfo* pRenderPassBegin) const { |
| 1358 | bool skip = false; |
| 1359 | |
| 1360 | if (!pRenderPassBegin) { |
| 1361 | return skip; |
| 1362 | } |
| 1363 | |
| 1364 | auto rp_state = GetRenderPassState(pRenderPassBegin->renderPass); |
| 1365 | if (rp_state) { |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1366 | if (rp_state->createInfo.flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) { |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1367 | const VkRenderPassAttachmentBeginInfo* rpabi = LvlFindInChain<VkRenderPassAttachmentBeginInfo>(pRenderPassBegin->pNext); |
Tony-LunarG | 767180f | 2020-04-23 14:03:59 -0600 | [diff] [blame] | 1368 | if (rpabi) { |
| 1369 | skip = ValidateAttachments(rp_state->createInfo.ptr(), rpabi->attachmentCount, rpabi->pAttachments); |
| 1370 | } |
| 1371 | } |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1372 | // Check if any attachments have LOAD operation on them |
| 1373 | for (uint32_t att = 0; att < rp_state->createInfo.attachmentCount; att++) { |
Hans-Kristian Arntzen | 69ace7d | 2021-04-28 14:17:19 +0200 | [diff] [blame] | 1374 | const auto& attachment = rp_state->createInfo.pAttachments[att]; |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1375 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1376 | bool attachment_has_readback = false; |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1377 | if (!FormatHasStencil(attachment.format) && attachment.loadOp == VK_ATTACHMENT_LOAD_OP_LOAD) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1378 | attachment_has_readback = true; |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1379 | } |
| 1380 | |
| 1381 | if (FormatHasStencil(attachment.format) && attachment.stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1382 | attachment_has_readback = true; |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1383 | } |
| 1384 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1385 | bool attachment_needs_readback = false; |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1386 | |
| 1387 | // Check if the attachment is actually used in any subpass on-tile |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1388 | if (attachment_has_readback && RenderPassUsesAttachmentOnTile(rp_state->createInfo, att)) { |
| 1389 | attachment_needs_readback = true; |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1390 | } |
| 1391 | |
| 1392 | // Using LOAD_OP_LOAD is expensive on tiled GPUs, so flag it as a potential improvement |
Hans-Kristian Arntzen | b214795 | 2021-04-28 14:32:00 +0200 | [diff] [blame] | 1393 | if (attachment_needs_readback && VendorCheckEnabled(kBPVendorArm)) { |
| 1394 | skip |= LogPerformanceWarning( |
| 1395 | device, kVUID_BestPractices_BeginRenderPass_AttachmentNeedsReadback, |
| 1396 | "%s Attachment #%u in render pass has begun with VK_ATTACHMENT_LOAD_OP_LOAD.\n" |
| 1397 | "Submitting this renderpass will cause the driver to inject a readback of the attachment " |
| 1398 | "which will copy in total %u pixels (renderArea = { %d, %d, %u, %u }) to the tile buffer.", |
| 1399 | VendorSpecificTag(kBPVendorArm), att, |
| 1400 | pRenderPassBegin->renderArea.extent.width * pRenderPassBegin->renderArea.extent.height, |
| 1401 | pRenderPassBegin->renderArea.offset.x, pRenderPassBegin->renderArea.offset.y, |
| 1402 | pRenderPassBegin->renderArea.extent.width, pRenderPassBegin->renderArea.extent.height); |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1403 | } |
| 1404 | } |
| 1405 | } |
| 1406 | |
| 1407 | return skip; |
| 1408 | } |
| 1409 | |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 1410 | void BestPractices::QueueValidateImageView(QueueCallbacks &funcs, const char* function_name, |
| 1411 | IMAGE_VIEW_STATE* view, IMAGE_SUBRESOURCE_USAGE_BP usage) { |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 1412 | if (view) { |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 1413 | QueueValidateImage(funcs, function_name, GetImageUsageState(view->create_info.image), usage, view->create_info.subresourceRange); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 1414 | } |
| 1415 | } |
| 1416 | |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 1417 | void BestPractices::QueueValidateImage(QueueCallbacks &funcs, const char* function_name, |
| 1418 | IMAGE_STATE_BP* state, IMAGE_SUBRESOURCE_USAGE_BP usage, |
Hans-Kristian Arntzen | 66f4b52 | 2021-03-22 11:35:58 +0100 | [diff] [blame] | 1419 | const VkImageSubresourceRange& subresource_range) { |
Hans-Kristian Arntzen | 5b466db | 2021-03-18 13:59:46 +0100 | [diff] [blame] | 1420 | IMAGE_STATE* image = state->image; |
Hans-Kristian Arntzen | 9326420 | 2021-05-21 17:07:46 +0200 | [diff] [blame] | 1421 | |
| 1422 | // If we're viewing a 3D slice, ignore base array layer. |
| 1423 | // The entire 3D subresource is accessed as one atomic unit. |
| 1424 | const uint32_t base_array_layer = image->createInfo.imageType == VK_IMAGE_TYPE_3D ? 0 : subresource_range.baseArrayLayer; |
| 1425 | |
| 1426 | const uint32_t max_layers = image->createInfo.arrayLayers - base_array_layer; |
Hans-Kristian Arntzen | 69ace7d | 2021-04-28 14:17:19 +0200 | [diff] [blame] | 1427 | const uint32_t array_layers = std::min(subresource_range.layerCount, max_layers); |
| 1428 | const uint32_t max_levels = image->createInfo.mipLevels - subresource_range.baseMipLevel; |
| 1429 | const uint32_t mip_levels = std::min(image->createInfo.mipLevels, max_levels); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 1430 | |
| 1431 | for (uint32_t layer = 0; layer < array_layers; layer++) { |
| 1432 | for (uint32_t level = 0; level < mip_levels; level++) { |
Hans-Kristian Arntzen | 9326420 | 2021-05-21 17:07:46 +0200 | [diff] [blame] | 1433 | QueueValidateImage(funcs, function_name, state, usage, layer + base_array_layer, |
| 1434 | level + subresource_range.baseMipLevel); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 1435 | } |
| 1436 | } |
| 1437 | } |
| 1438 | |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 1439 | void BestPractices::QueueValidateImage(QueueCallbacks &funcs, const char* function_name, |
| 1440 | IMAGE_STATE_BP* state, IMAGE_SUBRESOURCE_USAGE_BP usage, |
Hans-Kristian Arntzen | 66f4b52 | 2021-03-22 11:35:58 +0100 | [diff] [blame] | 1441 | const VkImageSubresourceLayers& subresource_layers) { |
Hans-Kristian Arntzen | 5b466db | 2021-03-18 13:59:46 +0100 | [diff] [blame] | 1442 | IMAGE_STATE* image = state->image; |
Hans-Kristian Arntzen | 69ace7d | 2021-04-28 14:17:19 +0200 | [diff] [blame] | 1443 | const uint32_t max_layers = image->createInfo.arrayLayers - subresource_layers.baseArrayLayer; |
| 1444 | const uint32_t array_layers = std::min(subresource_layers.layerCount, max_layers); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 1445 | |
| 1446 | for (uint32_t layer = 0; layer < array_layers; layer++) { |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 1447 | QueueValidateImage(funcs, function_name, state, usage, layer + subresource_layers.baseArrayLayer, subresource_layers.mipLevel); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 1448 | } |
| 1449 | } |
| 1450 | |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 1451 | void BestPractices::QueueValidateImage(QueueCallbacks &funcs, const char* function_name, |
| 1452 | IMAGE_STATE_BP* state, IMAGE_SUBRESOURCE_USAGE_BP usage, |
Hans-Kristian Arntzen | 66f4b52 | 2021-03-22 11:35:58 +0100 | [diff] [blame] | 1453 | uint32_t array_layer, uint32_t mip_level) { |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 1454 | funcs.push_back([this, function_name, state, usage, array_layer, mip_level](const ValidationStateTracker*, const QUEUE_STATE*) -> bool { |
| 1455 | ValidateImageInQueue(function_name, state, usage, array_layer, mip_level); |
Hans-Kristian Arntzen | 66f4b52 | 2021-03-22 11:35:58 +0100 | [diff] [blame] | 1456 | return false; |
| 1457 | }); |
| 1458 | } |
| 1459 | |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 1460 | void BestPractices::ValidateImageInQueueArm(const char* function_name, IMAGE_STATE* image, |
Hans-Kristian Arntzen | b214795 | 2021-04-28 14:32:00 +0200 | [diff] [blame] | 1461 | IMAGE_SUBRESOURCE_USAGE_BP last_usage, |
| 1462 | IMAGE_SUBRESOURCE_USAGE_BP usage, |
| 1463 | uint32_t array_layer, uint32_t mip_level) { |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 1464 | // Swapchain images are implicitly read so clear after store is expected. |
Hans-Kristian Arntzen | 5b466db | 2021-03-18 13:59:46 +0100 | [diff] [blame] | 1465 | if (usage == IMAGE_SUBRESOURCE_USAGE_BP::RENDER_PASS_CLEARED && last_usage == IMAGE_SUBRESOURCE_USAGE_BP::RENDER_PASS_STORED && |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 1466 | !image->is_swapchain_image) { |
Hans-Kristian Arntzen | b214795 | 2021-04-28 14:32:00 +0200 | [diff] [blame] | 1467 | LogPerformanceWarning( |
| 1468 | device, kVUID_BestPractices_RenderPass_RedundantStore, |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 1469 | "%s: %s Subresource (arrayLayer: %u, mipLevel: %u) of image was cleared as part of LOAD_OP_CLEAR, but last time " |
Hans-Kristian Arntzen | b214795 | 2021-04-28 14:32:00 +0200 | [diff] [blame] | 1470 | "image was used, it was written to with STORE_OP_STORE. " |
| 1471 | "Storing to the image is probably redundant in this case, and wastes bandwidth on tile-based " |
| 1472 | "architectures.", |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 1473 | function_name, VendorSpecificTag(kBPVendorArm), array_layer, mip_level); |
Hans-Kristian Arntzen | 5b466db | 2021-03-18 13:59:46 +0100 | [diff] [blame] | 1474 | } else if (usage == IMAGE_SUBRESOURCE_USAGE_BP::RENDER_PASS_CLEARED && last_usage == IMAGE_SUBRESOURCE_USAGE_BP::CLEARED) { |
Hans-Kristian Arntzen | b214795 | 2021-04-28 14:32:00 +0200 | [diff] [blame] | 1475 | LogPerformanceWarning( |
| 1476 | device, kVUID_BestPractices_RenderPass_RedundantClear, |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 1477 | "%s: %s Subresource (arrayLayer: %u, mipLevel: %u) of image was cleared as part of LOAD_OP_CLEAR, but last time " |
Hans-Kristian Arntzen | b214795 | 2021-04-28 14:32:00 +0200 | [diff] [blame] | 1478 | "image was used, it was written to with vkCmdClear*Image(). " |
| 1479 | "Clearing the image with vkCmdClear*Image() is probably redundant in this case, and wastes bandwidth on " |
| 1480 | "tile-based architectures." |
| 1481 | "architectures.", |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 1482 | function_name, VendorSpecificTag(kBPVendorArm), array_layer, mip_level); |
Hans-Kristian Arntzen | 44f9d86 | 2021-03-22 13:56:39 +0100 | [diff] [blame] | 1483 | } else if (usage == IMAGE_SUBRESOURCE_USAGE_BP::RENDER_PASS_READ_TO_TILE && |
| 1484 | (last_usage == IMAGE_SUBRESOURCE_USAGE_BP::BLIT_WRITE || |
| 1485 | last_usage == IMAGE_SUBRESOURCE_USAGE_BP::CLEARED || |
| 1486 | last_usage == IMAGE_SUBRESOURCE_USAGE_BP::COPY_WRITE || |
Hans-Kristian Arntzen | b214795 | 2021-04-28 14:32:00 +0200 | [diff] [blame] | 1487 | last_usage == IMAGE_SUBRESOURCE_USAGE_BP::RESOLVE_WRITE)) { |
Hans-Kristian Arntzen | 44f9d86 | 2021-03-22 13:56:39 +0100 | [diff] [blame] | 1488 | const char *last_cmd = nullptr; |
| 1489 | const char *vuid = nullptr; |
| 1490 | const char *suggestion = nullptr; |
| 1491 | |
| 1492 | switch (last_usage) { |
| 1493 | case IMAGE_SUBRESOURCE_USAGE_BP::BLIT_WRITE: |
| 1494 | vuid = kVUID_BestPractices_RenderPass_BlitImage_LoadOpLoad; |
| 1495 | last_cmd = "vkCmdBlitImage"; |
| 1496 | suggestion = |
| 1497 | "The blit is probably redundant in this case, and wastes bandwidth on tile-based architectures. " |
| 1498 | "Rather than blitting, just render the source image in a fragment shader in this render pass, " |
| 1499 | "which avoids the memory roundtrip."; |
| 1500 | break; |
| 1501 | case IMAGE_SUBRESOURCE_USAGE_BP::CLEARED: |
| 1502 | vuid = kVUID_BestPractices_RenderPass_InefficientClear; |
| 1503 | last_cmd = "vkCmdClear*Image"; |
| 1504 | suggestion = |
| 1505 | "Clearing the image with vkCmdClear*Image() is probably redundant in this case, and wastes bandwidth on " |
| 1506 | "tile-based architectures. " |
| 1507 | "Use LOAD_OP_CLEAR instead to clear the image for free."; |
| 1508 | break; |
| 1509 | case IMAGE_SUBRESOURCE_USAGE_BP::COPY_WRITE: |
| 1510 | vuid = kVUID_BestPractices_RenderPass_CopyImage_LoadOpLoad; |
| 1511 | last_cmd = "vkCmdCopy*Image"; |
| 1512 | suggestion = |
| 1513 | "The copy is probably redundant in this case, and wastes bandwidth on tile-based architectures. " |
| 1514 | "Rather than copying, just render the source image in a fragment shader in this render pass, " |
| 1515 | "which avoids the memory roundtrip."; |
| 1516 | break; |
| 1517 | case IMAGE_SUBRESOURCE_USAGE_BP::RESOLVE_WRITE: |
| 1518 | vuid = kVUID_BestPractices_RenderPass_ResolveImage_LoadOpLoad; |
| 1519 | last_cmd = "vkCmdResolveImage"; |
| 1520 | suggestion = |
| 1521 | "The resolve is probably redundant in this case, and wastes a lot of bandwidth on tile-based architectures. " |
| 1522 | "Rather than resolving, and then loading, try to keep rendering in the same render pass, " |
| 1523 | "which avoids the memory roundtrip."; |
| 1524 | break; |
| 1525 | default: |
| 1526 | break; |
| 1527 | } |
| 1528 | |
| 1529 | LogPerformanceWarning( |
| 1530 | device, vuid, |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 1531 | "%s: %s Subresource (arrayLayer: %u, mipLevel: %u) of image was loaded to tile as part of LOAD_OP_LOAD, but last " |
Hans-Kristian Arntzen | 44f9d86 | 2021-03-22 13:56:39 +0100 | [diff] [blame] | 1532 | "time image was used, it was written to with %s. %s", |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 1533 | function_name, VendorSpecificTag(kBPVendorArm), array_layer, mip_level, last_cmd, suggestion); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 1534 | } |
Hans-Kristian Arntzen | b214795 | 2021-04-28 14:32:00 +0200 | [diff] [blame] | 1535 | } |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 1536 | |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 1537 | void BestPractices::ValidateImageInQueue(const char* function_name, IMAGE_STATE_BP* state, |
Hans-Kristian Arntzen | b214795 | 2021-04-28 14:32:00 +0200 | [diff] [blame] | 1538 | IMAGE_SUBRESOURCE_USAGE_BP usage, uint32_t array_layer, |
| 1539 | uint32_t mip_level) { |
| 1540 | IMAGE_STATE* image = state->image; |
| 1541 | IMAGE_SUBRESOURCE_USAGE_BP last_usage = state->usages[array_layer][mip_level]; |
Hans-Kristian Arntzen | 5b466db | 2021-03-18 13:59:46 +0100 | [diff] [blame] | 1542 | state->usages[array_layer][mip_level] = usage; |
Hans-Kristian Arntzen | b214795 | 2021-04-28 14:32:00 +0200 | [diff] [blame] | 1543 | if (VendorCheckEnabled(kBPVendorArm)) { |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 1544 | ValidateImageInQueueArm(function_name, image, last_usage, usage, array_layer, mip_level); |
Hans-Kristian Arntzen | b214795 | 2021-04-28 14:32:00 +0200 | [diff] [blame] | 1545 | } |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 1546 | } |
| 1547 | |
Hans-Kristian Arntzen | b8336ad | 2021-04-28 14:54:09 +0200 | [diff] [blame] | 1548 | void BestPractices::AddDeferredQueueOperations(CMD_BUFFER_STATE* cb) { |
Hans-Kristian Arntzen | dd8acbb | 2021-03-22 13:41:47 +0100 | [diff] [blame] | 1549 | cb->queue_submit_functions.insert(cb->queue_submit_functions.end(), |
| 1550 | queue_submit_functions_after_render_pass.begin(), |
| 1551 | queue_submit_functions_after_render_pass.end()); |
| 1552 | queue_submit_functions_after_render_pass.clear(); |
| 1553 | } |
| 1554 | |
| 1555 | void BestPractices::PreCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) { |
| 1556 | ValidationStateTracker::PreCallRecordCmdEndRenderPass(commandBuffer); |
Hans-Kristian Arntzen | b8336ad | 2021-04-28 14:54:09 +0200 | [diff] [blame] | 1557 | AddDeferredQueueOperations(GetCBState(commandBuffer)); |
Hans-Kristian Arntzen | dd8acbb | 2021-03-22 13:41:47 +0100 | [diff] [blame] | 1558 | } |
| 1559 | |
| 1560 | void BestPractices::PreCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassInfo) { |
| 1561 | ValidationStateTracker::PreCallRecordCmdEndRenderPass2(commandBuffer, pSubpassInfo); |
Hans-Kristian Arntzen | b8336ad | 2021-04-28 14:54:09 +0200 | [diff] [blame] | 1562 | AddDeferredQueueOperations(GetCBState(commandBuffer)); |
Hans-Kristian Arntzen | dd8acbb | 2021-03-22 13:41:47 +0100 | [diff] [blame] | 1563 | } |
| 1564 | |
| 1565 | void BestPractices::PreCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer, const VkSubpassEndInfoKHR *pSubpassInfo) { |
| 1566 | ValidationStateTracker::PreCallRecordCmdEndRenderPass2KHR(commandBuffer, pSubpassInfo); |
Hans-Kristian Arntzen | b8336ad | 2021-04-28 14:54:09 +0200 | [diff] [blame] | 1567 | AddDeferredQueueOperations(GetCBState(commandBuffer)); |
Hans-Kristian Arntzen | dd8acbb | 2021-03-22 13:41:47 +0100 | [diff] [blame] | 1568 | } |
| 1569 | |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 1570 | void BestPractices::PreCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, |
| 1571 | VkSubpassContents contents) { |
Hans-Kristian Arntzen | dd8acbb | 2021-03-22 13:41:47 +0100 | [diff] [blame] | 1572 | ValidationStateTracker::PreCallRecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents); |
| 1573 | |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 1574 | if (!pRenderPassBegin) { |
| 1575 | return; |
| 1576 | } |
| 1577 | |
Hans-Kristian Arntzen | 66f4b52 | 2021-03-22 11:35:58 +0100 | [diff] [blame] | 1578 | CMD_BUFFER_STATE* cb = GetCBState(commandBuffer); |
| 1579 | |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 1580 | auto rp_state = GetRenderPassState(pRenderPassBegin->renderPass); |
| 1581 | if (rp_state) { |
| 1582 | // Check load ops |
| 1583 | for (uint32_t att = 0; att < rp_state->createInfo.attachmentCount; att++) { |
Hans-Kristian Arntzen | 69ace7d | 2021-04-28 14:17:19 +0200 | [diff] [blame] | 1584 | const auto& attachment = rp_state->createInfo.pAttachments[att]; |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 1585 | |
| 1586 | if (!RenderPassUsesAttachmentAsImageOnly(rp_state->createInfo, att) && |
| 1587 | !RenderPassUsesAttachmentOnTile(rp_state->createInfo, att)) { |
| 1588 | continue; |
| 1589 | } |
| 1590 | |
Hans-Kristian Arntzen | 5b466db | 2021-03-18 13:59:46 +0100 | [diff] [blame] | 1591 | IMAGE_SUBRESOURCE_USAGE_BP usage = IMAGE_SUBRESOURCE_USAGE_BP::UNDEFINED; |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 1592 | |
| 1593 | if ((!FormatIsStencilOnly(attachment.format) && attachment.loadOp == VK_ATTACHMENT_LOAD_OP_LOAD) || |
| 1594 | (FormatHasStencil(attachment.format) && attachment.stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD)) { |
Hans-Kristian Arntzen | 5b466db | 2021-03-18 13:59:46 +0100 | [diff] [blame] | 1595 | usage = IMAGE_SUBRESOURCE_USAGE_BP::RENDER_PASS_READ_TO_TILE; |
Hans-Kristian Arntzen | 5e56e55 | 2021-03-29 11:45:20 +0200 | [diff] [blame] | 1596 | } else if ((!FormatIsStencilOnly(attachment.format) && attachment.loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) || |
| 1597 | (FormatHasStencil(attachment.format) && attachment.stencilLoadOp == VK_ATTACHMENT_LOAD_OP_CLEAR)) { |
Hans-Kristian Arntzen | 5b466db | 2021-03-18 13:59:46 +0100 | [diff] [blame] | 1598 | usage = IMAGE_SUBRESOURCE_USAGE_BP::RENDER_PASS_CLEARED; |
Hans-Kristian Arntzen | 5e56e55 | 2021-03-29 11:45:20 +0200 | [diff] [blame] | 1599 | } else if (RenderPassUsesAttachmentAsImageOnly(rp_state->createInfo, att)) { |
Hans-Kristian Arntzen | dd8acbb | 2021-03-22 13:41:47 +0100 | [diff] [blame] | 1600 | usage = IMAGE_SUBRESOURCE_USAGE_BP::DESCRIPTOR_ACCESS; |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 1601 | } |
| 1602 | |
| 1603 | auto framebuffer = GetFramebufferState(pRenderPassBegin->framebuffer); |
Hans-Kristian Arntzen | 9710e14 | 2021-03-18 12:19:02 +0100 | [diff] [blame] | 1604 | IMAGE_VIEW_STATE* image_view = nullptr; |
| 1605 | |
| 1606 | if (rp_state->createInfo.flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) { |
| 1607 | const VkRenderPassAttachmentBeginInfo* rpabi = LvlFindInChain<VkRenderPassAttachmentBeginInfo>(pRenderPassBegin->pNext); |
| 1608 | if (rpabi) { |
| 1609 | image_view = GetImageViewState(rpabi->pAttachments[att]); |
| 1610 | } |
| 1611 | } else { |
| 1612 | image_view = GetImageViewState(framebuffer->createInfo.pAttachments[att]); |
| 1613 | } |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 1614 | |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 1615 | QueueValidateImageView(cb->queue_submit_functions, "vkCmdBeginRenderPass()", image_view, usage); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 1616 | } |
| 1617 | |
| 1618 | // Check store ops |
| 1619 | for (uint32_t att = 0; att < rp_state->createInfo.attachmentCount; att++) { |
Hans-Kristian Arntzen | 69ace7d | 2021-04-28 14:17:19 +0200 | [diff] [blame] | 1620 | const auto& attachment = rp_state->createInfo.pAttachments[att]; |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 1621 | |
| 1622 | if (!RenderPassUsesAttachmentOnTile(rp_state->createInfo, att)) { |
| 1623 | continue; |
| 1624 | } |
| 1625 | |
Hans-Kristian Arntzen | 5b466db | 2021-03-18 13:59:46 +0100 | [diff] [blame] | 1626 | IMAGE_SUBRESOURCE_USAGE_BP usage = IMAGE_SUBRESOURCE_USAGE_BP::RENDER_PASS_DISCARDED; |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 1627 | |
| 1628 | if ((!FormatIsStencilOnly(attachment.format) && attachment.storeOp == VK_ATTACHMENT_STORE_OP_STORE) || |
| 1629 | (FormatHasStencil(attachment.format) && attachment.stencilStoreOp == VK_ATTACHMENT_STORE_OP_STORE)) { |
Hans-Kristian Arntzen | 5b466db | 2021-03-18 13:59:46 +0100 | [diff] [blame] | 1630 | usage = IMAGE_SUBRESOURCE_USAGE_BP::RENDER_PASS_STORED; |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 1631 | } |
| 1632 | |
| 1633 | auto framebuffer = GetFramebufferState(pRenderPassBegin->framebuffer); |
Hans-Kristian Arntzen | 9710e14 | 2021-03-18 12:19:02 +0100 | [diff] [blame] | 1634 | |
| 1635 | IMAGE_VIEW_STATE* image_view = nullptr; |
| 1636 | if (rp_state->createInfo.flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) { |
| 1637 | const VkRenderPassAttachmentBeginInfo* rpabi = LvlFindInChain<VkRenderPassAttachmentBeginInfo>(pRenderPassBegin->pNext); |
| 1638 | if (rpabi) { |
| 1639 | image_view = GetImageViewState(rpabi->pAttachments[att]); |
| 1640 | } |
| 1641 | } else { |
| 1642 | image_view = GetImageViewState(framebuffer->createInfo.pAttachments[att]); |
| 1643 | } |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 1644 | |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 1645 | QueueValidateImageView(queue_submit_functions_after_render_pass, "vkCmdEndRenderPass()", image_view, usage); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 1646 | } |
| 1647 | } |
| 1648 | } |
| 1649 | |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1650 | bool BestPractices::PreCallValidateCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, |
| 1651 | VkSubpassContents contents) const { |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1652 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents); |
| 1653 | skip |= ValidateCmdBeginRenderPass(commandBuffer, RENDER_PASS_VERSION_1, pRenderPassBegin); |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1654 | return skip; |
| 1655 | } |
| 1656 | |
| 1657 | bool BestPractices::PreCallValidateCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 1658 | const VkRenderPassBeginInfo* pRenderPassBegin, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1659 | const VkSubpassBeginInfo* pSubpassBeginInfo) const { |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1660 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass2KHR(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
| 1661 | skip |= ValidateCmdBeginRenderPass(commandBuffer, RENDER_PASS_VERSION_2, pRenderPassBegin); |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1662 | return skip; |
| 1663 | } |
| 1664 | |
| 1665 | bool BestPractices::PreCallValidateCmdBeginRenderPass2(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1666 | const VkSubpassBeginInfo* pSubpassBeginInfo) const { |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1667 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass2(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
| 1668 | skip |= ValidateCmdBeginRenderPass(commandBuffer, RENDER_PASS_VERSION_2, pRenderPassBegin); |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1669 | return skip; |
| 1670 | } |
| 1671 | |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1672 | void BestPractices::RecordCmdBeginRenderPass(VkCommandBuffer commandBuffer, RenderPassCreateVersion rp_version, |
| 1673 | const VkRenderPassBeginInfo* pRenderPassBegin) { |
| 1674 | auto prepass_state = cbDepthPrePassStates.find(commandBuffer); |
| 1675 | |
| 1676 | // add the tracking state if it doesn't exist |
| 1677 | if (prepass_state == cbDepthPrePassStates.end()) { |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame] | 1678 | auto result = cbDepthPrePassStates.emplace(commandBuffer, DepthPrePassState{}); |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1679 | |
| 1680 | if (!result.second) return; |
| 1681 | |
| 1682 | prepass_state = result.first; |
| 1683 | } |
| 1684 | |
| 1685 | // reset the renderpass state |
| 1686 | prepass_state->second = {}; |
| 1687 | |
Hans-Kristian Arntzen | a1a92cc | 2021-03-17 13:09:33 +0100 | [diff] [blame] | 1688 | const auto* rp_state = GetRenderPassState(pRenderPassBegin->renderPass); |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1689 | |
| 1690 | // track depth / color attachment usage within the renderpass |
| 1691 | for (size_t i = 0; i < rp_state->createInfo.subpassCount; i++) { |
| 1692 | // record if depth/color attachments are in use for this renderpass |
| 1693 | if (rp_state->createInfo.pSubpasses[i].pDepthStencilAttachment != nullptr) prepass_state->second.depthAttachment = true; |
| 1694 | |
| 1695 | if (rp_state->createInfo.pSubpasses[i].colorAttachmentCount > 0) prepass_state->second.colorAttachment = true; |
| 1696 | } |
| 1697 | } |
| 1698 | |
| 1699 | void BestPractices::PostCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, |
| 1700 | VkSubpassContents contents) { |
| 1701 | StateTracker::PostCallRecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents); |
| 1702 | RecordCmdBeginRenderPass(commandBuffer, RENDER_PASS_VERSION_1, pRenderPassBegin); |
| 1703 | } |
| 1704 | |
| 1705 | void BestPractices::PostCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, |
| 1706 | const VkSubpassBeginInfo* pSubpassBeginInfo) { |
| 1707 | StateTracker::PostCallRecordCmdBeginRenderPass2(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
| 1708 | RecordCmdBeginRenderPass(commandBuffer, RENDER_PASS_VERSION_2, pRenderPassBegin); |
| 1709 | } |
| 1710 | |
| 1711 | void BestPractices::PostCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 1712 | const VkRenderPassBeginInfo* pRenderPassBegin, |
| 1713 | const VkSubpassBeginInfo* pSubpassBeginInfo) { |
| 1714 | StateTracker::PostCallRecordCmdBeginRenderPass2KHR(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
| 1715 | RecordCmdBeginRenderPass(commandBuffer, RENDER_PASS_VERSION_2, pRenderPassBegin); |
| 1716 | } |
| 1717 | |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 1718 | // Generic function to handle validation for all CmdDraw* type functions |
| 1719 | bool BestPractices::ValidateCmdDrawType(VkCommandBuffer cmd_buffer, const char* caller) const { |
| 1720 | bool skip = false; |
| 1721 | const CMD_BUFFER_STATE* cb_state = GetCBState(cmd_buffer); |
| 1722 | if (cb_state) { |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 1723 | const auto lv_bind_point = ConvertToLvlBindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 1724 | const auto* pipeline_state = cb_state->lastBound[lv_bind_point].pipeline_state; |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 1725 | const auto& current_vtx_bfr_binding_info = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings; |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 1726 | |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 1727 | // Verify vertex binding |
| 1728 | if (pipeline_state->vertex_binding_descriptions_.size() <= 0) { |
| 1729 | if ((!current_vtx_bfr_binding_info.empty()) && (!cb_state->vertex_buffer_used)) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1730 | skip |= LogPerformanceWarning(cb_state->commandBuffer(), kVUID_BestPractices_DrawState_VtxIndexOutOfBounds, |
Mark Lobodzinski | f95a266 | 2020-01-29 15:43:32 -0700 | [diff] [blame] | 1731 | "Vertex buffers are bound to %s but no vertex buffers are attached to %s.", |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1732 | report_data->FormatHandle(cb_state->commandBuffer()).c_str(), |
| 1733 | report_data->FormatHandle(pipeline_state->pipeline()).c_str()); |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 1734 | } |
| 1735 | } |
Nathaniel Cesario | f7b732a | 2021-06-03 14:08:27 -0600 | [diff] [blame^] | 1736 | |
| 1737 | const auto* pipe = GetCurrentPipelineFromCommandBuffer(*cb_state, VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 1738 | if (pipe) { |
| 1739 | const auto* rp_state = pipe->rp_state.get(); |
| 1740 | if (rp_state) { |
| 1741 | for (uint32_t i = 0; i < rp_state->createInfo.subpassCount; ++i) { |
| 1742 | const auto& subpass = rp_state->createInfo.pSubpasses[i]; |
| 1743 | const uint32_t depth_stencil_attachment = GetSubpassDepthStencilAttachmentIndex( |
| 1744 | pipe->graphicsPipelineCI.pDepthStencilState, subpass.pDepthStencilAttachment); |
| 1745 | if ((depth_stencil_attachment == VK_ATTACHMENT_UNUSED) && pipe->graphicsPipelineCI.pRasterizationState && |
| 1746 | pipe->graphicsPipelineCI.pRasterizationState->depthBiasEnable == VK_TRUE) { |
| 1747 | skip |= LogWarning(cb_state->commandBuffer(), kVUID_BestPractices_DepthBiasNoAttachment, |
| 1748 | "%s: depthBiasEnable == VK_TRUE without a depth-stencil attachment.", caller); |
| 1749 | } |
| 1750 | } |
| 1751 | } |
| 1752 | } |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 1753 | } |
| 1754 | return skip; |
| 1755 | } |
| 1756 | |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1757 | void BestPractices::RecordCmdDrawType(VkCommandBuffer cmd_buffer, uint32_t draw_count, const char* caller) { |
| 1758 | if (VendorCheckEnabled(kBPVendorArm)) { |
| 1759 | RecordCmdDrawTypeArm(cmd_buffer, draw_count, caller); |
| 1760 | } |
| 1761 | } |
| 1762 | |
| 1763 | void BestPractices::RecordCmdDrawTypeArm(VkCommandBuffer cmd_buffer, uint32_t draw_count, const char* caller) { |
| 1764 | auto prepass_state = cbDepthPrePassStates.find(cmd_buffer); |
| 1765 | if (prepass_state != cbDepthPrePassStates.end() && draw_count >= kDepthPrePassMinDrawCountArm) { |
| 1766 | if (prepass_state->second.depthOnly) prepass_state->second.numDrawCallsDepthOnly++; |
| 1767 | |
| 1768 | if (prepass_state->second.depthEqualComparison) prepass_state->second.numDrawCallsDepthEqualCompare++; |
| 1769 | } |
| 1770 | } |
| 1771 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1772 | bool BestPractices::PreCallValidateCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1773 | uint32_t firstVertex, uint32_t firstInstance) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1774 | bool skip = false; |
| 1775 | |
| 1776 | if (instanceCount == 0) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1777 | skip |= LogWarning(device, kVUID_BestPractices_CmdDraw_InstanceCountZero, |
| 1778 | "Warning: You are calling vkCmdDraw() with an instanceCount of Zero."); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1779 | } |
Nathaniel Cesario | f7b732a | 2021-06-03 14:08:27 -0600 | [diff] [blame^] | 1780 | skip |= ValidateCmdDrawType(commandBuffer, "vkCmdDraw()"); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1781 | |
| 1782 | return skip; |
| 1783 | } |
| 1784 | |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1785 | void BestPractices::PostCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
| 1786 | uint32_t firstVertex, uint32_t firstInstance) { |
| 1787 | StateTracker::PostCallRecordCmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance); |
| 1788 | RecordCmdDrawType(commandBuffer, vertexCount * instanceCount, "vkCmdDraw()"); |
| 1789 | } |
| 1790 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1791 | bool BestPractices::PreCallValidateCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1792 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1793 | bool skip = false; |
| 1794 | |
| 1795 | if (instanceCount == 0) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1796 | skip |= LogWarning(device, kVUID_BestPractices_CmdDraw_InstanceCountZero, |
| 1797 | "Warning: You are calling vkCmdDrawIndexed() with an instanceCount of Zero."); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1798 | } |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 1799 | skip |= ValidateCmdDrawType(commandBuffer, "vkCmdDrawIndexed()"); |
| 1800 | |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1801 | // Check if we reached the limit for small indexed draw calls. |
| 1802 | // Note that we cannot update the draw call count here, so we do it in PreCallRecordCmdDrawIndexed. |
| 1803 | const CMD_BUFFER_STATE* cmd_state = GetCBState(commandBuffer); |
| 1804 | if ((indexCount * instanceCount) <= kSmallIndexedDrawcallIndices && |
Hans-Kristian Arntzen | b214795 | 2021-04-28 14:32:00 +0200 | [diff] [blame] | 1805 | (cmd_state->small_indexed_draw_call_count == kMaxSmallIndexedDrawcalls - 1) && |
| 1806 | VendorCheckEnabled(kBPVendorArm)) { |
| 1807 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_CmdDrawIndexed_ManySmallIndexedDrawcalls, |
Jeremy Gebben | da6b48f | 2021-05-13 10:46:18 -0600 | [diff] [blame] | 1808 | "%s: The command buffer contains many small indexed drawcalls " |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1809 | "(at least %u drawcalls with less than %u indices each). This may cause pipeline bubbles. " |
| 1810 | "You can try batching drawcalls or instancing when applicable.", |
| 1811 | VendorSpecificTag(kBPVendorArm), kMaxSmallIndexedDrawcalls, kSmallIndexedDrawcallIndices); |
| 1812 | } |
| 1813 | |
Sam Walls | 8e77e4f | 2020-03-16 20:47:40 +0000 | [diff] [blame] | 1814 | if (VendorCheckEnabled(kBPVendorArm)) { |
| 1815 | ValidateIndexBufferArm(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); |
| 1816 | } |
| 1817 | |
| 1818 | return skip; |
| 1819 | } |
| 1820 | |
| 1821 | bool BestPractices::ValidateIndexBufferArm(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
| 1822 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) const { |
| 1823 | bool skip = false; |
| 1824 | |
| 1825 | // check for sparse/underutilised index buffer, and post-transform cache thrashing |
| 1826 | const auto* cmd_state = GetCBState(commandBuffer); |
| 1827 | if (cmd_state == nullptr) return skip; |
| 1828 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 1829 | const auto* ib_state = cmd_state->index_buffer_binding.buffer_state.get(); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 1830 | if (ib_state == nullptr || cmd_state->index_buffer_binding.buffer_state->Destroyed()) return skip; |
Sam Walls | 8e77e4f | 2020-03-16 20:47:40 +0000 | [diff] [blame] | 1831 | |
| 1832 | const VkIndexType ib_type = cmd_state->index_buffer_binding.index_type; |
| 1833 | const auto& ib_mem_state = *ib_state->binding.mem_state; |
| 1834 | const VkDeviceSize ib_mem_offset = ib_mem_state.mapped_range.offset; |
| 1835 | const void* ib_mem = ib_mem_state.p_driver_data; |
| 1836 | bool primitive_restart_enable = false; |
| 1837 | |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 1838 | const auto lv_bind_point = ConvertToLvlBindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 1839 | const auto& pipeline_binding_iter = cmd_state->lastBound[lv_bind_point]; |
| 1840 | const auto* pipeline_state = pipeline_binding_iter.pipeline_state; |
Sam Walls | 8e77e4f | 2020-03-16 20:47:40 +0000 | [diff] [blame] | 1841 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1842 | if (pipeline_state != nullptr && pipeline_state->graphicsPipelineCI.pInputAssemblyState != nullptr) { |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 1843 | primitive_restart_enable = pipeline_state->graphicsPipelineCI.pInputAssemblyState->primitiveRestartEnable == VK_TRUE; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1844 | } |
Sam Walls | 8e77e4f | 2020-03-16 20:47:40 +0000 | [diff] [blame] | 1845 | |
| 1846 | // no point checking index buffer if the memory is nonexistant/unmapped, or if there is no graphics pipeline bound to this CB |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 1847 | if (ib_mem && pipeline_binding_iter.IsUsing()) { |
Sam Walls | 8e77e4f | 2020-03-16 20:47:40 +0000 | [diff] [blame] | 1848 | uint32_t scan_stride; |
| 1849 | if (ib_type == VK_INDEX_TYPE_UINT8_EXT) { |
| 1850 | scan_stride = sizeof(uint8_t); |
| 1851 | } else if (ib_type == VK_INDEX_TYPE_UINT16) { |
| 1852 | scan_stride = sizeof(uint16_t); |
| 1853 | } else { |
| 1854 | scan_stride = sizeof(uint32_t); |
| 1855 | } |
| 1856 | |
| 1857 | const uint8_t* scan_begin = static_cast<const uint8_t*>(ib_mem) + ib_mem_offset + firstIndex * scan_stride; |
| 1858 | const uint8_t* scan_end = scan_begin + indexCount * scan_stride; |
| 1859 | |
| 1860 | // Min and max are important to track for some Mali architectures. In older Mali devices without IDVS, all |
| 1861 | // vertices corresponding to indices between the minimum and maximum may be loaded, and possibly shaded, |
| 1862 | // irrespective of whether or not they're part of the draw call. |
| 1863 | |
| 1864 | // start with minimum as 0xFFFFFFFF and adjust to indices in the buffer |
| 1865 | uint32_t min_index = ~0u; |
| 1866 | // start with maximum as 0 and adjust to indices in the buffer |
| 1867 | uint32_t max_index = 0u; |
| 1868 | |
| 1869 | // first scan-through, we're looking to simulate a model LRU post-transform cache, estimating the number of vertices shaded |
| 1870 | // for the given index buffer |
| 1871 | uint32_t vertex_shade_count = 0; |
| 1872 | |
| 1873 | PostTransformLRUCacheModel post_transform_cache; |
| 1874 | |
| 1875 | // The size of the cache being modelled positively correlates with how much behaviour it can capture about |
| 1876 | // arbitrary ground-truth hardware/architecture cache behaviour. I.e. it's a good solution when we don't know the |
| 1877 | // target architecture. |
| 1878 | // However, modelling a post-transform cache with more than 32 elements gives diminishing returns in practice. |
| 1879 | // http://eelpi.gotdns.org/papers/fast_vert_cache_opt.html |
| 1880 | post_transform_cache.resize(32); |
| 1881 | |
| 1882 | for (const uint8_t* scan_ptr = scan_begin; scan_ptr < scan_end; scan_ptr += scan_stride) { |
| 1883 | uint32_t scan_index; |
| 1884 | uint32_t primitive_restart_value; |
| 1885 | if (ib_type == VK_INDEX_TYPE_UINT8_EXT) { |
| 1886 | scan_index = *reinterpret_cast<const uint8_t*>(scan_ptr); |
| 1887 | primitive_restart_value = 0xFF; |
| 1888 | } else if (ib_type == VK_INDEX_TYPE_UINT16) { |
| 1889 | scan_index = *reinterpret_cast<const uint16_t*>(scan_ptr); |
| 1890 | primitive_restart_value = 0xFFFF; |
| 1891 | } else { |
| 1892 | scan_index = *reinterpret_cast<const uint32_t*>(scan_ptr); |
| 1893 | primitive_restart_value = 0xFFFFFFFF; |
| 1894 | } |
| 1895 | |
| 1896 | max_index = std::max(max_index, scan_index); |
| 1897 | min_index = std::min(min_index, scan_index); |
| 1898 | |
| 1899 | if (!primitive_restart_enable || scan_index != primitive_restart_value) { |
| 1900 | bool in_cache = post_transform_cache.query_cache(scan_index); |
| 1901 | // if the shaded vertex corresponding to the index is not in the PT-cache, we need to shade again |
| 1902 | if (!in_cache) vertex_shade_count++; |
| 1903 | } |
| 1904 | } |
| 1905 | |
| 1906 | // if the max and min values were not set, then we either have no indices, or all primitive restarts, exit... |
Sam Walls | 61b0689 | 2020-07-23 16:20:50 +0100 | [diff] [blame] | 1907 | // if the max and min are the same, then it implies all the indices are the same, then we don't need to do anything |
| 1908 | if (max_index < min_index || max_index == min_index) return skip; |
Sam Walls | 8e77e4f | 2020-03-16 20:47:40 +0000 | [diff] [blame] | 1909 | |
| 1910 | if (max_index - min_index >= indexCount) { |
Mark Young | 0ec6b06 | 2020-11-19 15:32:17 -0700 | [diff] [blame] | 1911 | skip |= |
| 1912 | LogPerformanceWarning(device, kVUID_BestPractices_CmdDrawIndexed_SparseIndexBuffer, |
| 1913 | "%s The indices which were specified for the draw call only utilise approximately %.02f%% of " |
| 1914 | "index buffer value range. Arm Mali architectures before G71 do not have IDVS (Index-Driven " |
| 1915 | "Vertex Shading), meaning all vertices corresponding to indices between the minimum and " |
| 1916 | "maximum would be loaded, and possibly shaded, whether or not they are used.", |
| 1917 | VendorSpecificTag(kBPVendorArm), |
| 1918 | (static_cast<float>(indexCount) / static_cast<float>(max_index - min_index)) * 100.0f); |
Sam Walls | 8e77e4f | 2020-03-16 20:47:40 +0000 | [diff] [blame] | 1919 | return skip; |
| 1920 | } |
| 1921 | |
| 1922 | // use a dynamic vector of bitsets as a memory-compact representation of which indices are included in the draw call |
| 1923 | // each bit of the n-th bucket contains the inclusion information for indices (n*n_buckets) to ((n+1)*n_buckets) |
Sam Walls | 61b0689 | 2020-07-23 16:20:50 +0100 | [diff] [blame] | 1924 | const size_t refs_per_bucket = 64; |
| 1925 | std::vector<std::bitset<refs_per_bucket>> vertex_reference_buckets; |
| 1926 | |
| 1927 | const uint32_t n_indices = max_index - min_index + 1; |
| 1928 | const uint32_t n_buckets = (n_indices / static_cast<uint32_t>(refs_per_bucket)) + |
| 1929 | ((n_indices % static_cast<uint32_t>(refs_per_bucket)) != 0 ? 1 : 0); |
| 1930 | |
| 1931 | // there needs to be at least one bitset to store a set of indices smaller than n_buckets |
| 1932 | vertex_reference_buckets.resize(std::max(1u, n_buckets)); |
Sam Walls | 8e77e4f | 2020-03-16 20:47:40 +0000 | [diff] [blame] | 1933 | |
| 1934 | // To avoid using too much memory, we run over the indices again. |
| 1935 | // Knowing the size from the last scan allows us to record index usage with bitsets |
| 1936 | for (const uint8_t* scan_ptr = scan_begin; scan_ptr < scan_end; scan_ptr += scan_stride) { |
| 1937 | uint32_t scan_index; |
| 1938 | if (ib_type == VK_INDEX_TYPE_UINT8_EXT) { |
| 1939 | scan_index = *reinterpret_cast<const uint8_t*>(scan_ptr); |
| 1940 | } else if (ib_type == VK_INDEX_TYPE_UINT16) { |
| 1941 | scan_index = *reinterpret_cast<const uint16_t*>(scan_ptr); |
| 1942 | } else { |
| 1943 | scan_index = *reinterpret_cast<const uint32_t*>(scan_ptr); |
| 1944 | } |
| 1945 | // keep track of the set of all indices used to reference vertices in the draw call |
| 1946 | size_t index_offset = scan_index - min_index; |
Sam Walls | 61b0689 | 2020-07-23 16:20:50 +0100 | [diff] [blame] | 1947 | size_t bitset_bucket_index = index_offset / refs_per_bucket; |
| 1948 | uint64_t used_indices = 1ull << ((index_offset % refs_per_bucket) & 0xFFFFFFFFu); |
Sam Walls | 8e77e4f | 2020-03-16 20:47:40 +0000 | [diff] [blame] | 1949 | vertex_reference_buckets[bitset_bucket_index] |= used_indices; |
| 1950 | } |
| 1951 | |
| 1952 | uint32_t vertex_reference_count = 0; |
| 1953 | for (const auto& bitset : vertex_reference_buckets) { |
| 1954 | vertex_reference_count += static_cast<uint32_t>(bitset.count()); |
| 1955 | } |
| 1956 | |
| 1957 | // low index buffer utilization implies that: of the vertices available to the draw call, not all are utilized |
Mark Young | 0ec6b06 | 2020-11-19 15:32:17 -0700 | [diff] [blame] | 1958 | float utilization = static_cast<float>(vertex_reference_count) / static_cast<float>(max_index - min_index + 1); |
Sam Walls | 8e77e4f | 2020-03-16 20:47:40 +0000 | [diff] [blame] | 1959 | // low hit rate (high miss rate) implies the order of indices in the draw call may be possible to improve |
Mark Young | 0ec6b06 | 2020-11-19 15:32:17 -0700 | [diff] [blame] | 1960 | float cache_hit_rate = static_cast<float>(vertex_reference_count) / static_cast<float>(vertex_shade_count); |
Sam Walls | 8e77e4f | 2020-03-16 20:47:40 +0000 | [diff] [blame] | 1961 | |
| 1962 | if (utilization < 0.5f) { |
| 1963 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_CmdDrawIndexed_SparseIndexBuffer, |
| 1964 | "%s The indices which were specified for the draw call only utilise approximately " |
| 1965 | "%.02f%% of the bound vertex buffer.", |
| 1966 | VendorSpecificTag(kBPVendorArm), utilization); |
| 1967 | } |
| 1968 | |
| 1969 | if (cache_hit_rate <= 0.5f) { |
| 1970 | skip |= |
| 1971 | LogPerformanceWarning(device, kVUID_BestPractices_CmdDrawIndexed_PostTransformCacheThrashing, |
| 1972 | "%s The indices which were specified for the draw call are estimated to cause thrashing of " |
| 1973 | "the post-transform vertex cache, with a hit-rate of %.02f%%. " |
| 1974 | "I.e. the ordering of the index buffer may not make optimal use of indices associated with " |
| 1975 | "recently shaded vertices.", |
| 1976 | VendorSpecificTag(kBPVendorArm), cache_hit_rate * 100.0f); |
| 1977 | } |
| 1978 | } |
| 1979 | |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 1980 | return skip; |
| 1981 | } |
| 1982 | |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1983 | void BestPractices::PreCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
| 1984 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) { |
| 1985 | ValidationStateTracker::PreCallRecordCmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, |
| 1986 | firstInstance); |
| 1987 | |
| 1988 | CMD_BUFFER_STATE* cmd_state = GetCBState(commandBuffer); |
| 1989 | if ((indexCount * instanceCount) <= kSmallIndexedDrawcallIndices) { |
| 1990 | cmd_state->small_indexed_draw_call_count++; |
| 1991 | } |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 1992 | |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 1993 | ValidateBoundDescriptorSets(commandBuffer, "vkCmdDrawIndexed()"); |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1994 | } |
| 1995 | |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1996 | void BestPractices::PostCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
| 1997 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) { |
| 1998 | StateTracker::PostCallRecordCmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); |
| 1999 | RecordCmdDrawType(commandBuffer, indexCount * instanceCount, "vkCmdDrawIndexed()"); |
| 2000 | } |
| 2001 | |
sfricke-samsung | 681ab7b | 2020-10-29 01:53:35 -0700 | [diff] [blame] | 2002 | bool BestPractices::PreCallValidateCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 2003 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 2004 | uint32_t maxDrawCount, uint32_t stride) const { |
| 2005 | bool skip = ValidateCmdDrawType(commandBuffer, "vkCmdDrawIndexedIndirectCount()"); |
| 2006 | |
| 2007 | return skip; |
| 2008 | } |
| 2009 | |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 2010 | bool BestPractices::PreCallValidateCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 2011 | VkDeviceSize offset, VkBuffer countBuffer, |
| 2012 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 2013 | uint32_t stride) const { |
| 2014 | bool skip = ValidateCmdDrawType(commandBuffer, "vkCmdDrawIndexedIndirectCountKHR()"); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 2015 | |
| 2016 | return skip; |
| 2017 | } |
| 2018 | |
| 2019 | bool BestPractices::PreCallValidateCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 2020 | uint32_t drawCount, uint32_t stride) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 2021 | bool skip = false; |
| 2022 | |
| 2023 | if (drawCount == 0) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 2024 | skip |= LogWarning(device, kVUID_BestPractices_CmdDraw_DrawCountZero, |
| 2025 | "Warning: You are calling vkCmdDrawIndirect() with a drawCount of Zero."); |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 2026 | skip |= ValidateCmdDrawType(commandBuffer, "vkCmdDrawIndirect()"); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 2027 | } |
| 2028 | |
| 2029 | return skip; |
| 2030 | } |
| 2031 | |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 2032 | void BestPractices::PostCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 2033 | uint32_t count, uint32_t stride) { |
| 2034 | StateTracker::PostCallRecordCmdDrawIndirect(commandBuffer, buffer, offset, count, stride); |
| 2035 | RecordCmdDrawType(commandBuffer, count, "vkCmdDrawIndirect()"); |
| 2036 | } |
| 2037 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 2038 | bool BestPractices::PreCallValidateCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 2039 | uint32_t drawCount, uint32_t stride) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 2040 | bool skip = false; |
| 2041 | |
| 2042 | if (drawCount == 0) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 2043 | skip |= LogWarning(device, kVUID_BestPractices_CmdDraw_DrawCountZero, |
| 2044 | "Warning: You are calling vkCmdDrawIndexedIndirect() with a drawCount of Zero."); |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 2045 | skip |= ValidateCmdDrawType(commandBuffer, "vkCmdDrawIndexedIndirect()"); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 2046 | } |
| 2047 | |
| 2048 | return skip; |
| 2049 | } |
| 2050 | |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 2051 | void BestPractices::PostCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 2052 | uint32_t count, uint32_t stride) { |
| 2053 | StateTracker::PostCallRecordCmdDrawIndexedIndirect(commandBuffer, buffer, offset, count, stride); |
| 2054 | RecordCmdDrawType(commandBuffer, count, "vkCmdDrawIndexedIndirect()"); |
| 2055 | } |
| 2056 | |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 2057 | void BestPractices::ValidateBoundDescriptorSets(VkCommandBuffer commandBuffer, const char* function_name) { |
Hans-Kristian Arntzen | 66f4b52 | 2021-03-22 11:35:58 +0100 | [diff] [blame] | 2058 | CMD_BUFFER_STATE* cb_state = GetCBState(commandBuffer); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2059 | |
| 2060 | if (cb_state) { |
| 2061 | for (auto descriptor_set : cb_state->validated_descriptor_sets) { |
Hans-Kristian Arntzen | 69ace7d | 2021-04-28 14:17:19 +0200 | [diff] [blame] | 2062 | const auto& layout = *descriptor_set->GetLayout(); |
Hans-Kristian Arntzen | a819901 | 2021-03-22 12:10:07 +0100 | [diff] [blame] | 2063 | |
| 2064 | for (uint32_t index = 0; index < descriptor_set->GetBindingCount(); ++index) { |
| 2065 | // For bindless scenarios, we should not attempt to track descriptor set state. |
| 2066 | // It is highly uncertain which resources are actually bound. |
| 2067 | // Resources which are written to such a descriptor should be marked as indeterminate w.r.t. state. |
| 2068 | VkDescriptorBindingFlags flags = layout.GetDescriptorBindingFlagsFromIndex(index); |
| 2069 | if (flags & (VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT | |
| 2070 | VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT | |
| 2071 | VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT)) { |
| 2072 | continue; |
| 2073 | } |
| 2074 | |
| 2075 | auto index_range = layout.GetGlobalIndexRangeFromIndex(index); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2076 | for (uint32_t i = index_range.start; i < index_range.end; ++i) { |
ZandroFargnoli | acf12f0 | 2020-06-18 16:50:00 +0100 | [diff] [blame] | 2077 | VkImageView image_view{VK_NULL_HANDLE}; |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2078 | |
| 2079 | auto descriptor = descriptor_set->GetDescriptorFromGlobalIndex(i); |
| 2080 | switch (descriptor->GetClass()) { |
| 2081 | case cvdescriptorset::DescriptorClass::Image: { |
| 2082 | if (const auto image_descriptor = static_cast<const cvdescriptorset::ImageDescriptor*>(descriptor)) { |
| 2083 | image_view = image_descriptor->GetImageView(); |
| 2084 | } |
Hans-Kristian Arntzen | bc3a615 | 2021-03-22 13:05:43 +0100 | [diff] [blame] | 2085 | break; |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2086 | } |
| 2087 | case cvdescriptorset::DescriptorClass::ImageSampler: { |
| 2088 | if (const auto image_sampler_descriptor = |
| 2089 | static_cast<const cvdescriptorset::ImageSamplerDescriptor*>(descriptor)) { |
| 2090 | image_view = image_sampler_descriptor->GetImageView(); |
| 2091 | } |
Hans-Kristian Arntzen | bc3a615 | 2021-03-22 13:05:43 +0100 | [diff] [blame] | 2092 | break; |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2093 | } |
ZandroFargnoli | acf12f0 | 2020-06-18 16:50:00 +0100 | [diff] [blame] | 2094 | default: |
Hans-Kristian Arntzen | bc3a615 | 2021-03-22 13:05:43 +0100 | [diff] [blame] | 2095 | break; |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2096 | } |
| 2097 | |
| 2098 | if (image_view) { |
| 2099 | IMAGE_VIEW_STATE* image_view_state = GetImageViewState(image_view); |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 2100 | QueueValidateImageView(cb_state->queue_submit_functions, function_name, |
| 2101 | image_view_state, IMAGE_SUBRESOURCE_USAGE_BP::DESCRIPTOR_ACCESS); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2102 | } |
| 2103 | } |
| 2104 | } |
| 2105 | } |
| 2106 | } |
| 2107 | } |
| 2108 | |
| 2109 | void BestPractices::PreCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
| 2110 | uint32_t firstVertex, uint32_t firstInstance) { |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 2111 | ValidateBoundDescriptorSets(commandBuffer, "vkCmdDraw()"); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2112 | } |
| 2113 | |
| 2114 | void BestPractices::PreCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 2115 | uint32_t drawCount, uint32_t stride) { |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 2116 | ValidateBoundDescriptorSets(commandBuffer, "vkCmdDrawIndirect()"); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2117 | } |
| 2118 | |
| 2119 | void BestPractices::PreCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 2120 | uint32_t drawCount, uint32_t stride) { |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 2121 | ValidateBoundDescriptorSets(commandBuffer, "vkCmdDrawIndexedIndirect()"); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2122 | } |
| 2123 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 2124 | bool BestPractices::PreCallValidateCmdDispatch(VkCommandBuffer commandBuffer, uint32_t groupCountX, uint32_t groupCountY, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 2125 | uint32_t groupCountZ) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 2126 | bool skip = false; |
| 2127 | |
| 2128 | if ((groupCountX == 0) || (groupCountY == 0) || (groupCountZ == 0)) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 2129 | skip |= LogWarning(device, kVUID_BestPractices_CmdDispatch_GroupCountZero, |
| 2130 | "Warning: You are calling vkCmdDispatch() while one or more groupCounts are zero (groupCountX = %" PRIu32 |
| 2131 | ", groupCountY = %" PRIu32 ", groupCountZ = %" PRIu32 ").", |
| 2132 | groupCountX, groupCountY, groupCountZ); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 2133 | } |
| 2134 | |
| 2135 | return skip; |
| 2136 | } |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 2137 | |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 2138 | bool BestPractices::PreCallValidateCmdEndRenderPass(VkCommandBuffer commandBuffer) const { |
| 2139 | bool skip = false; |
| 2140 | |
| 2141 | skip |= StateTracker::PreCallValidateCmdEndRenderPass(commandBuffer); |
| 2142 | |
| 2143 | auto prepass_state = cbDepthPrePassStates.find(commandBuffer); |
| 2144 | |
| 2145 | if (prepass_state == cbDepthPrePassStates.end()) return skip; |
| 2146 | |
| 2147 | bool uses_depth = (prepass_state->second.depthAttachment || prepass_state->second.colorAttachment) && |
| 2148 | prepass_state->second.numDrawCallsDepthEqualCompare >= kDepthPrePassNumDrawCallsArm && |
| 2149 | prepass_state->second.numDrawCallsDepthOnly >= kDepthPrePassNumDrawCallsArm; |
| 2150 | if (uses_depth) { |
| 2151 | skip |= LogPerformanceWarning( |
| 2152 | device, kVUID_BestPractices_EndRenderPass_DepthPrePassUsage, |
| 2153 | "%s Depth pre-passes may be in use. In general, this is not recommended, as in Arm Mali GPUs since " |
| 2154 | "Mali-T620, Forward Pixel Killing (FPK) can already perform automatic hidden surface removal; in which " |
| 2155 | "case, using depth pre-passes for hidden surface removal may worsen performance.", |
| 2156 | VendorSpecificTag(kBPVendorArm)); |
| 2157 | } |
| 2158 | |
| 2159 | return skip; |
| 2160 | } |
| 2161 | |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2162 | void BestPractices::PreCallRecordCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z) { |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 2163 | ValidateBoundDescriptorSets(commandBuffer, "vkCmdDispatch()"); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2164 | } |
| 2165 | |
| 2166 | void BestPractices::PreCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset) { |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 2167 | ValidateBoundDescriptorSets(commandBuffer, "vkCmdDispatchIndirect()"); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2168 | } |
| 2169 | |
Camden Stocker | 9c05144 | 2019-11-06 14:28:43 -0800 | [diff] [blame] | 2170 | bool BestPractices::ValidateGetPhysicalDeviceDisplayPlanePropertiesKHRQuery(VkPhysicalDevice physicalDevice, |
| 2171 | const char* api_name) const { |
| 2172 | bool skip = false; |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 2173 | const auto* bp_pd_state = GetPhysicalDeviceStateBP(physicalDevice); |
Camden Stocker | 9c05144 | 2019-11-06 14:28:43 -0800 | [diff] [blame] | 2174 | |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 2175 | if (bp_pd_state) { |
| 2176 | if (bp_pd_state->vkGetPhysicalDeviceDisplayPlanePropertiesKHRState == UNCALLED) { |
| 2177 | skip |= LogWarning(physicalDevice, kVUID_BestPractices_DisplayPlane_PropertiesNotCalled, |
| 2178 | "Potential problem with calling %s() without first retrieving properties from " |
| 2179 | "vkGetPhysicalDeviceDisplayPlanePropertiesKHR or vkGetPhysicalDeviceDisplayPlaneProperties2KHR.", |
| 2180 | api_name); |
| 2181 | } |
Camden Stocker | 9c05144 | 2019-11-06 14:28:43 -0800 | [diff] [blame] | 2182 | } |
| 2183 | |
| 2184 | return skip; |
| 2185 | } |
| 2186 | |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 2187 | bool BestPractices::PreCallValidateGetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physicalDevice, uint32_t planeIndex, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 2188 | uint32_t* pDisplayCount, VkDisplayKHR* pDisplays) const { |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 2189 | bool skip = false; |
| 2190 | |
Camden Stocker | 9c05144 | 2019-11-06 14:28:43 -0800 | [diff] [blame] | 2191 | skip |= ValidateGetPhysicalDeviceDisplayPlanePropertiesKHRQuery(physicalDevice, "vkGetDisplayPlaneSupportedDisplaysKHR"); |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 2192 | |
Camden Stocker | 9c05144 | 2019-11-06 14:28:43 -0800 | [diff] [blame] | 2193 | return skip; |
| 2194 | } |
| 2195 | |
| 2196 | bool BestPractices::PreCallValidateGetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice physicalDevice, VkDisplayModeKHR mode, |
| 2197 | uint32_t planeIndex, |
| 2198 | VkDisplayPlaneCapabilitiesKHR* pCapabilities) const { |
| 2199 | bool skip = false; |
| 2200 | |
| 2201 | skip |= ValidateGetPhysicalDeviceDisplayPlanePropertiesKHRQuery(physicalDevice, "vkGetDisplayPlaneCapabilitiesKHR"); |
| 2202 | |
| 2203 | return skip; |
| 2204 | } |
| 2205 | |
| 2206 | bool BestPractices::PreCallValidateGetDisplayPlaneCapabilities2KHR(VkPhysicalDevice physicalDevice, |
| 2207 | const VkDisplayPlaneInfo2KHR* pDisplayPlaneInfo, |
| 2208 | VkDisplayPlaneCapabilities2KHR* pCapabilities) const { |
| 2209 | bool skip = false; |
| 2210 | |
| 2211 | skip |= ValidateGetPhysicalDeviceDisplayPlanePropertiesKHRQuery(physicalDevice, "vkGetDisplayPlaneCapabilities2KHR"); |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 2212 | |
| 2213 | return skip; |
| 2214 | } |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 2215 | |
| 2216 | bool BestPractices::PreCallValidateGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t* pSwapchainImageCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 2217 | VkImage* pSwapchainImages) const { |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 2218 | bool skip = false; |
| 2219 | |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 2220 | auto swapchain_state_itr = swapchain_bp_state_map.find(swapchain); |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 2221 | |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 2222 | if ((swapchain_state_itr != swapchain_bp_state_map.cend()) && pSwapchainImages) { |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 2223 | // Compare the preliminary value of *pSwapchainImageCount with the value this time: |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 2224 | if (swapchain_state_itr->second.vkGetSwapchainImagesKHRState == UNCALLED) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 2225 | skip |= |
| 2226 | LogWarning(device, kVUID_Core_Swapchain_PriorCount, |
| 2227 | "vkGetSwapchainImagesKHR() called with non-NULL pSwapchainImageCount; but no prior positive value has " |
| 2228 | "been seen for pSwapchainImages."); |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 2229 | } |
| 2230 | } |
| 2231 | |
Nathaniel Cesario | 4ce9838 | 2021-05-28 11:33:20 -0600 | [diff] [blame] | 2232 | const auto swapchain_state = GetSwapchainState(swapchain); |
| 2233 | if (swapchain_state && pSwapchainImages) { |
| 2234 | if (*pSwapchainImageCount > swapchain_state->get_swapchain_image_count) { |
| 2235 | skip |= LogWarning( |
| 2236 | device, kVUID_BestPractices_Swapchain_InvalidCount, |
| 2237 | "vkGetSwapchainImagesKHR() called with non-NULL pSwapchainImages, and with pSwapchainImageCount set to a " |
| 2238 | "value (%d) that is greater than the value (%d) that was returned when pSwapchainImages was NULL.", |
| 2239 | *pSwapchainImageCount, swapchain_state->get_swapchain_image_count); |
| 2240 | } |
| 2241 | } |
| 2242 | |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 2243 | return skip; |
| 2244 | } |
| 2245 | |
| 2246 | // Common function to handle validation for GetPhysicalDeviceQueueFamilyProperties & 2KHR version |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 2247 | bool BestPractices::ValidateCommonGetPhysicalDeviceQueueFamilyProperties(const PHYSICAL_DEVICE_STATE* pd_state, |
| 2248 | uint32_t requested_queue_family_property_count, |
Nathaniel Cesario | 56a9665 | 2020-12-30 13:23:42 -0700 | [diff] [blame] | 2249 | const CALL_STATE call_state, |
| 2250 | const char* caller_name) const { |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 2251 | bool skip = false; |
Nathaniel Cesario | 56a9665 | 2020-12-30 13:23:42 -0700 | [diff] [blame] | 2252 | // Verify that for each physical device, this command is called first with NULL pQueueFamilyProperties in order to get count |
| 2253 | if (UNCALLED == call_state) { |
| 2254 | skip |= LogWarning( |
| 2255 | pd_state->phys_device, kVUID_Core_DevLimit_MissingQueryCount, |
| 2256 | "%s is called with non-NULL pQueueFamilyProperties before obtaining pQueueFamilyPropertyCount. It is " |
| 2257 | "recommended " |
| 2258 | "to first call %s with NULL pQueueFamilyProperties in order to obtain the maximal pQueueFamilyPropertyCount.", |
| 2259 | caller_name, caller_name); |
| 2260 | // Then verify that pCount that is passed in on second call matches what was returned |
| 2261 | } else if (pd_state->queue_family_known_count != requested_queue_family_property_count) { |
| 2262 | skip |= LogWarning(pd_state->phys_device, kVUID_Core_DevLimit_CountMismatch, |
| 2263 | "%s is called with non-NULL pQueueFamilyProperties and pQueueFamilyPropertyCount value %" PRIu32 |
| 2264 | ", but the largest previously returned pQueueFamilyPropertyCount for this physicalDevice is %" PRIu32 |
| 2265 | ". It is recommended to instead receive all the properties by calling %s with " |
| 2266 | "pQueueFamilyPropertyCount that was " |
| 2267 | "previously obtained by calling %s with NULL pQueueFamilyProperties.", |
| 2268 | caller_name, requested_queue_family_property_count, pd_state->queue_family_known_count, caller_name, |
| 2269 | caller_name); |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 2270 | } |
| 2271 | |
| 2272 | return skip; |
| 2273 | } |
| 2274 | |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 2275 | bool BestPractices::PreCallValidateBindAccelerationStructureMemoryNV( |
| 2276 | VkDevice device, uint32_t bindInfoCount, const VkBindAccelerationStructureMemoryInfoNV* pBindInfos) const { |
Camden Stocker | 8251058 | 2019-09-03 14:00:16 -0600 | [diff] [blame] | 2277 | bool skip = false; |
| 2278 | |
| 2279 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2280 | const ACCELERATION_STRUCTURE_STATE* as_state = GetAccelerationStructureStateNV(pBindInfos[i].accelerationStructure); |
Camden Stocker | 8251058 | 2019-09-03 14:00:16 -0600 | [diff] [blame] | 2281 | if (!as_state->memory_requirements_checked) { |
| 2282 | // There's not an explicit requirement in the spec to call vkGetImageMemoryRequirements() prior to calling |
| 2283 | // BindAccelerationStructureMemoryNV but it's implied in that memory being bound must conform with |
| 2284 | // VkAccelerationStructureMemoryRequirementsInfoNV from vkGetAccelerationStructureMemoryRequirementsNV |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 2285 | skip |= LogWarning( |
| 2286 | device, kVUID_BestPractices_BindAccelNV_NoMemReqQuery, |
Camden Stocker | 8251058 | 2019-09-03 14:00:16 -0600 | [diff] [blame] | 2287 | "vkBindAccelerationStructureMemoryNV(): " |
| 2288 | "Binding memory to %s but vkGetAccelerationStructureMemoryRequirementsNV() has not been called on that structure.", |
| 2289 | report_data->FormatHandle(pBindInfos[i].accelerationStructure).c_str()); |
| 2290 | } |
| 2291 | } |
| 2292 | |
| 2293 | return skip; |
| 2294 | } |
| 2295 | |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 2296 | bool BestPractices::PreCallValidateGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, |
| 2297 | uint32_t* pQueueFamilyPropertyCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 2298 | VkQueueFamilyProperties* pQueueFamilyProperties) const { |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 2299 | const auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 2300 | assert(physical_device_state); |
Nathaniel Cesario | 56a9665 | 2020-12-30 13:23:42 -0700 | [diff] [blame] | 2301 | const auto* bp_pd_state = GetPhysicalDeviceStateBP(physical_device_state->phys_device); |
| 2302 | if (pQueueFamilyProperties && bp_pd_state) { |
| 2303 | return ValidateCommonGetPhysicalDeviceQueueFamilyProperties(physical_device_state, *pQueueFamilyPropertyCount, |
| 2304 | bp_pd_state->vkGetPhysicalDeviceQueueFamilyPropertiesState, |
| 2305 | "vkGetPhysicalDeviceQueueFamilyProperties()"); |
| 2306 | } |
| 2307 | return false; |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 2308 | } |
| 2309 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 2310 | bool BestPractices::PreCallValidateGetPhysicalDeviceQueueFamilyProperties2(VkPhysicalDevice physicalDevice, |
| 2311 | uint32_t* pQueueFamilyPropertyCount, |
| 2312 | VkQueueFamilyProperties2* pQueueFamilyProperties) const { |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 2313 | const auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 2314 | assert(physical_device_state); |
Nathaniel Cesario | 56a9665 | 2020-12-30 13:23:42 -0700 | [diff] [blame] | 2315 | const auto* bp_pd_state = GetPhysicalDeviceStateBP(physical_device_state->phys_device); |
| 2316 | if (pQueueFamilyProperties && bp_pd_state) { |
| 2317 | return ValidateCommonGetPhysicalDeviceQueueFamilyProperties(physical_device_state, *pQueueFamilyPropertyCount, |
| 2318 | bp_pd_state->vkGetPhysicalDeviceQueueFamilyProperties2State, |
| 2319 | "vkGetPhysicalDeviceQueueFamilyProperties2()"); |
| 2320 | } |
| 2321 | return false; |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 2322 | } |
| 2323 | |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 2324 | bool BestPractices::PreCallValidateGetPhysicalDeviceQueueFamilyProperties2KHR( |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 2325 | VkPhysicalDevice physicalDevice, uint32_t* pQueueFamilyPropertyCount, VkQueueFamilyProperties2* pQueueFamilyProperties) const { |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 2326 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 2327 | assert(physical_device_state); |
Nathaniel Cesario | 56a9665 | 2020-12-30 13:23:42 -0700 | [diff] [blame] | 2328 | const auto* bp_pd_state = GetPhysicalDeviceStateBP(physical_device_state->phys_device); |
| 2329 | if (pQueueFamilyProperties && bp_pd_state) { |
| 2330 | return ValidateCommonGetPhysicalDeviceQueueFamilyProperties(physical_device_state, *pQueueFamilyPropertyCount, |
| 2331 | bp_pd_state->vkGetPhysicalDeviceQueueFamilyProperties2KHRState, |
| 2332 | "vkGetPhysicalDeviceQueueFamilyProperties2KHR()"); |
| 2333 | } |
| 2334 | return false; |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 2335 | } |
| 2336 | |
| 2337 | bool BestPractices::PreCallValidateGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, |
| 2338 | uint32_t* pSurfaceFormatCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 2339 | VkSurfaceFormatKHR* pSurfaceFormats) const { |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 2340 | if (!pSurfaceFormats) return false; |
| 2341 | const auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 2342 | const auto* bp_pd_state = GetPhysicalDeviceStateBP(physicalDevice); |
| 2343 | const auto& call_state = bp_pd_state->vkGetPhysicalDeviceSurfaceFormatsKHRState; |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 2344 | bool skip = false; |
| 2345 | if (call_state == UNCALLED) { |
| 2346 | // Since we haven't recorded a preliminary value of *pSurfaceFormatCount, that likely means that the application didn't |
| 2347 | // previously call this function with a NULL value of pSurfaceFormats: |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 2348 | skip |= LogWarning(physicalDevice, kVUID_Core_DevLimit_MustQueryCount, |
| 2349 | "vkGetPhysicalDeviceSurfaceFormatsKHR() called with non-NULL pSurfaceFormatCount; but no prior " |
| 2350 | "positive value has been seen for pSurfaceFormats."); |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 2351 | } else { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2352 | auto prev_format_count = static_cast<uint32_t>(physical_device_state->surface_formats.size()); |
Peter Chen | e191bd7 | 2019-09-16 13:04:37 -0400 | [diff] [blame] | 2353 | if (*pSurfaceFormatCount > prev_format_count) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 2354 | skip |= LogWarning(physicalDevice, kVUID_Core_DevLimit_CountMismatch, |
| 2355 | "vkGetPhysicalDeviceSurfaceFormatsKHR() called with non-NULL pSurfaceFormatCount, and with " |
| 2356 | "pSurfaceFormats set to a value (%u) that is greater than the value (%u) that was returned " |
| 2357 | "when pSurfaceFormatCount was NULL.", |
| 2358 | *pSurfaceFormatCount, prev_format_count); |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 2359 | } |
| 2360 | } |
| 2361 | return skip; |
| 2362 | } |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 2363 | |
| 2364 | bool BestPractices::PreCallValidateQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo* pBindInfo, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 2365 | VkFence fence) const { |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 2366 | bool skip = false; |
| 2367 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2368 | for (uint32_t bind_idx = 0; bind_idx < bindInfoCount; bind_idx++) { |
| 2369 | const VkBindSparseInfo& bind_info = pBindInfo[bind_idx]; |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 2370 | // Store sparse binding image_state and after binding is complete make sure that any requiring metadata have it bound |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame] | 2371 | layer_data::unordered_set<const IMAGE_STATE*> sparse_images; |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 2372 | // Track images getting metadata bound by this call in a set, it'll be recorded into the image_state |
| 2373 | // in RecordQueueBindSparse. |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame] | 2374 | layer_data::unordered_set<const IMAGE_STATE*> sparse_images_with_metadata; |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 2375 | // If we're binding sparse image memory make sure reqs were queried and note if metadata is required and bound |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2376 | for (uint32_t i = 0; i < bind_info.imageBindCount; ++i) { |
| 2377 | const auto& image_bind = bind_info.pImageBinds[i]; |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 2378 | auto image_state = GetImageState(image_bind.image); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2379 | if (!image_state) { |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 2380 | continue; // Param/Object validation should report image_bind.image handles being invalid, so just skip here. |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2381 | } |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 2382 | sparse_images.insert(image_state); |
| 2383 | if (image_state->createInfo.flags & VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT) { |
| 2384 | if (!image_state->get_sparse_reqs_called || image_state->sparse_requirements.empty()) { |
| 2385 | // For now just warning if sparse image binding occurs without calling to get reqs first |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2386 | skip |= LogWarning(image_state->image(), kVUID_Core_MemTrack_InvalidState, |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 2387 | "vkQueueBindSparse(): Binding sparse memory to %s without first calling " |
| 2388 | "vkGetImageSparseMemoryRequirements[2KHR]() to retrieve requirements.", |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2389 | report_data->FormatHandle(image_state->image()).c_str()); |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 2390 | } |
| 2391 | } |
| 2392 | if (!image_state->memory_requirements_checked) { |
| 2393 | // For now just warning if sparse image binding occurs without calling to get reqs first |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2394 | skip |= LogWarning(image_state->image(), kVUID_Core_MemTrack_InvalidState, |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 2395 | "vkQueueBindSparse(): Binding sparse memory to %s without first calling " |
| 2396 | "vkGetImageMemoryRequirements() to retrieve requirements.", |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2397 | report_data->FormatHandle(image_state->image()).c_str()); |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 2398 | } |
| 2399 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2400 | for (uint32_t i = 0; i < bind_info.imageOpaqueBindCount; ++i) { |
| 2401 | const auto& image_opaque_bind = bind_info.pImageOpaqueBinds[i]; |
| 2402 | auto image_state = GetImageState(bind_info.pImageOpaqueBinds[i].image); |
| 2403 | if (!image_state) { |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 2404 | continue; // Param/Object validation should report image_bind.image handles being invalid, so just skip here. |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2405 | } |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 2406 | sparse_images.insert(image_state); |
| 2407 | if (image_state->createInfo.flags & VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT) { |
| 2408 | if (!image_state->get_sparse_reqs_called || image_state->sparse_requirements.empty()) { |
| 2409 | // For now just warning if sparse image binding occurs without calling to get reqs first |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2410 | skip |= LogWarning(image_state->image(), kVUID_Core_MemTrack_InvalidState, |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 2411 | "vkQueueBindSparse(): Binding opaque sparse memory to %s without first calling " |
| 2412 | "vkGetImageSparseMemoryRequirements[2KHR]() to retrieve requirements.", |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2413 | report_data->FormatHandle(image_state->image()).c_str()); |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 2414 | } |
| 2415 | } |
| 2416 | if (!image_state->memory_requirements_checked) { |
| 2417 | // For now just warning if sparse image binding occurs without calling to get reqs first |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2418 | skip |= LogWarning(image_state->image(), kVUID_Core_MemTrack_InvalidState, |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 2419 | "vkQueueBindSparse(): Binding opaque sparse memory to %s without first calling " |
| 2420 | "vkGetImageMemoryRequirements() to retrieve requirements.", |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2421 | report_data->FormatHandle(image_state->image()).c_str()); |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 2422 | } |
| 2423 | for (uint32_t j = 0; j < image_opaque_bind.bindCount; ++j) { |
| 2424 | 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] | 2425 | sparse_images_with_metadata.insert(image_state); |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 2426 | } |
| 2427 | } |
| 2428 | } |
| 2429 | for (const auto& sparse_image_state : sparse_images) { |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 2430 | if (sparse_image_state->sparse_metadata_required && !sparse_image_state->sparse_metadata_bound && |
| 2431 | 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] | 2432 | // Warn if sparse image binding metadata required for image with sparse binding, but metadata not bound |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2433 | skip |= LogWarning(sparse_image_state->image(), kVUID_Core_MemTrack_InvalidState, |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 2434 | "vkQueueBindSparse(): Binding sparse memory to %s which requires a metadata aspect but no " |
| 2435 | "binding with VK_SPARSE_MEMORY_BIND_METADATA_BIT set was made.", |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2436 | report_data->FormatHandle(sparse_image_state->image()).c_str()); |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 2437 | } |
| 2438 | } |
| 2439 | } |
| 2440 | |
| 2441 | return skip; |
| 2442 | } |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 2443 | |
Mark Lobodzinski | 84101d7 | 2020-04-24 09:43:48 -0600 | [diff] [blame] | 2444 | void BestPractices::ManualPostCallRecordQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo* pBindInfo, |
| 2445 | VkFence fence, VkResult result) { |
Mark Lobodzinski | 205b7a0 | 2020-02-21 13:23:17 -0700 | [diff] [blame] | 2446 | if (result != VK_SUCCESS) { |
Mark Lobodzinski | 205b7a0 | 2020-02-21 13:23:17 -0700 | [diff] [blame] | 2447 | return; |
| 2448 | } |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 2449 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2450 | for (uint32_t bind_idx = 0; bind_idx < bindInfoCount; bind_idx++) { |
| 2451 | const VkBindSparseInfo& bind_info = pBindInfo[bind_idx]; |
| 2452 | for (uint32_t i = 0; i < bind_info.imageOpaqueBindCount; ++i) { |
| 2453 | const auto& image_opaque_bind = bind_info.pImageOpaqueBinds[i]; |
| 2454 | auto image_state = GetImageState(bind_info.pImageOpaqueBinds[i].image); |
| 2455 | if (!image_state) { |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 2456 | continue; // Param/Object validation should report image_bind.image handles being invalid, so just skip here. |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2457 | } |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 2458 | for (uint32_t j = 0; j < image_opaque_bind.bindCount; ++j) { |
| 2459 | if (image_opaque_bind.pBinds[j].flags & VK_SPARSE_MEMORY_BIND_METADATA_BIT) { |
| 2460 | image_state->sparse_metadata_bound = true; |
| 2461 | } |
| 2462 | } |
| 2463 | } |
| 2464 | } |
| 2465 | } |
Camden Stocker | 0e0f89b | 2019-10-16 12:24:31 -0700 | [diff] [blame] | 2466 | |
| 2467 | bool BestPractices::PreCallValidateCmdClearAttachments(VkCommandBuffer commandBuffer, uint32_t attachmentCount, |
Camden Stocker | f55721f | 2019-09-09 11:04:49 -0600 | [diff] [blame] | 2468 | const VkClearAttachment* pAttachments, uint32_t rectCount, |
| 2469 | const VkClearRect* pRects) const { |
Camden Stocker | 0e0f89b | 2019-10-16 12:24:31 -0700 | [diff] [blame] | 2470 | bool skip = false; |
| 2471 | const CMD_BUFFER_STATE* cb_node = GetCBState(commandBuffer); |
| 2472 | if (!cb_node) return skip; |
| 2473 | |
Camden Stocker | f55721f | 2019-09-09 11:04:49 -0600 | [diff] [blame] | 2474 | // 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] | 2475 | if (!cb_node->hasDrawCmd && (cb_node->activeRenderPassBeginInfo.renderArea.extent.width == pRects[0].rect.extent.width) && |
| 2476 | (cb_node->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) { |
| 2477 | // There are times where app needs to use ClearAttachments (generally when reusing a buffer inside of a render pass) |
| 2478 | // This warning should be made more specific. It'd be best to avoid triggering this test if it's a use that must call |
| 2479 | // CmdClearAttachments. |
Mark Lobodzinski | f95a266 | 2020-01-29 15:43:32 -0700 | [diff] [blame] | 2480 | skip |= LogPerformanceWarning(commandBuffer, kVUID_BestPractices_DrawState_ClearCmdBeforeDraw, |
| 2481 | "vkCmdClearAttachments() issued on %s prior to any Draw Cmds. It is recommended you " |
| 2482 | "use RenderPass LOAD_OP_CLEAR on Attachments prior to any Draw.", |
| 2483 | report_data->FormatHandle(commandBuffer).c_str()); |
Camden Stocker | 0e0f89b | 2019-10-16 12:24:31 -0700 | [diff] [blame] | 2484 | } |
| 2485 | |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 2486 | // Check for uses of ClearAttachments along with LOAD_OP_LOAD, |
| 2487 | // as it can be more efficient to just use LOAD_OP_CLEAR |
locke-lunarg | aecf215 | 2020-05-12 17:15:41 -0600 | [diff] [blame] | 2488 | const RENDER_PASS_STATE* rp = cb_node->activeRenderPass.get(); |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 2489 | if (rp) { |
| 2490 | const auto& subpass = rp->createInfo.pSubpasses[cb_node->activeSubpass]; |
| 2491 | |
| 2492 | for (uint32_t i = 0; i < attachmentCount; i++) { |
Hans-Kristian Arntzen | 69ace7d | 2021-04-28 14:17:19 +0200 | [diff] [blame] | 2493 | const auto& attachment = pAttachments[i]; |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 2494 | if (attachment.aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) { |
| 2495 | uint32_t color_attachment = attachment.colorAttachment; |
| 2496 | uint32_t fb_attachment = subpass.pColorAttachments[color_attachment].attachment; |
| 2497 | |
| 2498 | if (fb_attachment != VK_ATTACHMENT_UNUSED) { |
| 2499 | if (rp->createInfo.pAttachments[fb_attachment].loadOp == VK_ATTACHMENT_LOAD_OP_LOAD) { |
| 2500 | skip |= LogPerformanceWarning( |
| 2501 | device, kVUID_BestPractices_ClearAttachments_ClearAfterLoad, |
| 2502 | "vkCmdClearAttachments() issued on %s for color attachment #%u in this subpass, " |
| 2503 | "but LOAD_OP_LOAD was used. If you need to clear the framebuffer, always use LOAD_OP_CLEAR as " |
| 2504 | "it is more efficient.", |
| 2505 | report_data->FormatHandle(commandBuffer).c_str(), color_attachment); |
| 2506 | } |
| 2507 | } |
| 2508 | } |
| 2509 | |
| 2510 | if (subpass.pDepthStencilAttachment && attachment.aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) { |
| 2511 | uint32_t fb_attachment = subpass.pDepthStencilAttachment->attachment; |
| 2512 | |
| 2513 | if (fb_attachment != VK_ATTACHMENT_UNUSED) { |
| 2514 | if (rp->createInfo.pAttachments[fb_attachment].loadOp == VK_ATTACHMENT_LOAD_OP_LOAD) { |
| 2515 | skip |= LogPerformanceWarning( |
| 2516 | device, kVUID_BestPractices_ClearAttachments_ClearAfterLoad, |
| 2517 | "vkCmdClearAttachments() issued on %s for the depth attachment in this subpass, " |
| 2518 | "but LOAD_OP_LOAD was used. If you need to clear the framebuffer, always use LOAD_OP_CLEAR as " |
| 2519 | "it is more efficient.", |
| 2520 | report_data->FormatHandle(commandBuffer).c_str()); |
| 2521 | } |
| 2522 | } |
| 2523 | } |
| 2524 | |
| 2525 | if (subpass.pDepthStencilAttachment && attachment.aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) { |
| 2526 | uint32_t fb_attachment = subpass.pDepthStencilAttachment->attachment; |
| 2527 | |
| 2528 | if (fb_attachment != VK_ATTACHMENT_UNUSED) { |
| 2529 | if (rp->createInfo.pAttachments[fb_attachment].stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD) { |
| 2530 | skip |= LogPerformanceWarning( |
| 2531 | device, kVUID_BestPractices_ClearAttachments_ClearAfterLoad, |
| 2532 | "vkCmdClearAttachments() issued on %s for the stencil attachment in this subpass, " |
| 2533 | "but LOAD_OP_LOAD was used. If you need to clear the framebuffer, always use LOAD_OP_CLEAR as " |
| 2534 | "it is more efficient.", |
| 2535 | report_data->FormatHandle(commandBuffer).c_str()); |
| 2536 | } |
| 2537 | } |
| 2538 | } |
| 2539 | } |
| 2540 | } |
| 2541 | |
Camden Stocker | f55721f | 2019-09-09 11:04:49 -0600 | [diff] [blame] | 2542 | return skip; |
Camden Stocker | 0e0f89b | 2019-10-16 12:24:31 -0700 | [diff] [blame] | 2543 | } |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 2544 | |
| 2545 | bool BestPractices::PreCallValidateCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 2546 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 2547 | const VkImageResolve* pRegions) const { |
| 2548 | bool skip = false; |
| 2549 | |
| 2550 | skip |= VendorCheckEnabled(kBPVendorArm) && |
| 2551 | LogPerformanceWarning(device, kVUID_BestPractices_CmdResolveImage_ResolvingImage, |
| 2552 | "%s Attempting to use vkCmdResolveImage to resolve a multisampled image. " |
| 2553 | "This is a very slow and extremely bandwidth intensive path. " |
| 2554 | "You should always resolve multisampled images on-tile with pResolveAttachments in VkRenderPass.", |
| 2555 | VendorSpecificTag(kBPVendorArm)); |
| 2556 | |
| 2557 | return skip; |
| 2558 | } |
| 2559 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 2560 | bool BestPractices::PreCallValidateCmdResolveImage2KHR(VkCommandBuffer commandBuffer, |
| 2561 | const VkResolveImageInfo2KHR* pResolveImageInfo) const { |
| 2562 | bool skip = false; |
| 2563 | |
| 2564 | skip |= VendorCheckEnabled(kBPVendorArm) && |
| 2565 | LogPerformanceWarning(device, kVUID_BestPractices_CmdResolveImage2KHR_ResolvingImage, |
| 2566 | "%s Attempting to use vkCmdResolveImage2KHR to resolve a multisampled image. " |
| 2567 | "This is a very slow and extremely bandwidth intensive path. " |
| 2568 | "You should always resolve multisampled images on-tile with pResolveAttachments in VkRenderPass.", |
| 2569 | VendorSpecificTag(kBPVendorArm)); |
| 2570 | |
| 2571 | return skip; |
| 2572 | } |
| 2573 | |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2574 | void BestPractices::PreCallRecordCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 2575 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 2576 | const VkImageResolve* pRegions) { |
Hans-Kristian Arntzen | 66f4b52 | 2021-03-22 11:35:58 +0100 | [diff] [blame] | 2577 | CMD_BUFFER_STATE* cb = GetCBState(commandBuffer); |
Hans-Kristian Arntzen | dd8acbb | 2021-03-22 13:41:47 +0100 | [diff] [blame] | 2578 | auto &funcs = cb->queue_submit_functions; |
Hans-Kristian Arntzen | 5b466db | 2021-03-18 13:59:46 +0100 | [diff] [blame] | 2579 | auto* src = GetImageUsageState(srcImage); |
| 2580 | auto* dst = GetImageUsageState(dstImage); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2581 | |
| 2582 | for (uint32_t i = 0; i < regionCount; i++) { |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 2583 | QueueValidateImage(funcs, "vkCmdResolveImage()", src, IMAGE_SUBRESOURCE_USAGE_BP::RESOLVE_READ, pRegions[i].srcSubresource); |
| 2584 | QueueValidateImage(funcs, "vkCmdResolveImage()", dst, IMAGE_SUBRESOURCE_USAGE_BP::RESOLVE_WRITE, pRegions[i].dstSubresource); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2585 | } |
| 2586 | } |
| 2587 | |
Hans-Kristian Arntzen | 9e030f1 | 2021-03-17 13:09:30 +0100 | [diff] [blame] | 2588 | void BestPractices::PreCallRecordCmdResolveImage2KHR(VkCommandBuffer commandBuffer, |
| 2589 | const VkResolveImageInfo2KHR* pResolveImageInfo) { |
Hans-Kristian Arntzen | 66f4b52 | 2021-03-22 11:35:58 +0100 | [diff] [blame] | 2590 | CMD_BUFFER_STATE* cb = GetCBState(commandBuffer); |
Hans-Kristian Arntzen | dd8acbb | 2021-03-22 13:41:47 +0100 | [diff] [blame] | 2591 | auto &funcs = cb->queue_submit_functions; |
Hans-Kristian Arntzen | 5b466db | 2021-03-18 13:59:46 +0100 | [diff] [blame] | 2592 | auto* src = GetImageUsageState(pResolveImageInfo->srcImage); |
| 2593 | auto* dst = GetImageUsageState(pResolveImageInfo->dstImage); |
Hans-Kristian Arntzen | 9e030f1 | 2021-03-17 13:09:30 +0100 | [diff] [blame] | 2594 | uint32_t regionCount = pResolveImageInfo->regionCount; |
| 2595 | |
| 2596 | for (uint32_t i = 0; i < regionCount; i++) { |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 2597 | QueueValidateImage(funcs, "vkCmdResolveImage2KHR()", src, IMAGE_SUBRESOURCE_USAGE_BP::RESOLVE_READ, pResolveImageInfo->pRegions[i].srcSubresource); |
| 2598 | QueueValidateImage(funcs, "vkCmdResolveImage2KHR()", dst, IMAGE_SUBRESOURCE_USAGE_BP::RESOLVE_WRITE, pResolveImageInfo->pRegions[i].dstSubresource); |
Hans-Kristian Arntzen | 9e030f1 | 2021-03-17 13:09:30 +0100 | [diff] [blame] | 2599 | } |
| 2600 | } |
| 2601 | |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2602 | void BestPractices::PreCallRecordCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 2603 | const VkClearColorValue* pColor, uint32_t rangeCount, |
| 2604 | const VkImageSubresourceRange* pRanges) { |
Hans-Kristian Arntzen | 66f4b52 | 2021-03-22 11:35:58 +0100 | [diff] [blame] | 2605 | CMD_BUFFER_STATE* cb = GetCBState(commandBuffer); |
Hans-Kristian Arntzen | dd8acbb | 2021-03-22 13:41:47 +0100 | [diff] [blame] | 2606 | auto &funcs = cb->queue_submit_functions; |
Hans-Kristian Arntzen | 5b466db | 2021-03-18 13:59:46 +0100 | [diff] [blame] | 2607 | auto* dst = GetImageUsageState(image); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2608 | |
| 2609 | for (uint32_t i = 0; i < rangeCount; i++) { |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 2610 | QueueValidateImage(funcs, "vkCmdClearColorImage()", dst, IMAGE_SUBRESOURCE_USAGE_BP::CLEARED, pRanges[i]); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2611 | } |
| 2612 | } |
| 2613 | |
| 2614 | void BestPractices::PreCallRecordCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 2615 | const VkClearDepthStencilValue* pDepthStencil, uint32_t rangeCount, |
| 2616 | const VkImageSubresourceRange* pRanges) { |
Hans-Kristian Arntzen | 66f4b52 | 2021-03-22 11:35:58 +0100 | [diff] [blame] | 2617 | CMD_BUFFER_STATE* cb = GetCBState(commandBuffer); |
Hans-Kristian Arntzen | dd8acbb | 2021-03-22 13:41:47 +0100 | [diff] [blame] | 2618 | auto &funcs = cb->queue_submit_functions; |
Hans-Kristian Arntzen | 5b466db | 2021-03-18 13:59:46 +0100 | [diff] [blame] | 2619 | auto* dst = GetImageUsageState(image); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2620 | |
| 2621 | for (uint32_t i = 0; i < rangeCount; i++) { |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 2622 | QueueValidateImage(funcs, "vkCmdClearDepthStencilImage()", dst, IMAGE_SUBRESOURCE_USAGE_BP::CLEARED, pRanges[i]); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2623 | } |
| 2624 | } |
| 2625 | |
| 2626 | void BestPractices::PreCallRecordCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 2627 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 2628 | const VkImageCopy* pRegions) { |
Hans-Kristian Arntzen | 66f4b52 | 2021-03-22 11:35:58 +0100 | [diff] [blame] | 2629 | CMD_BUFFER_STATE* cb = GetCBState(commandBuffer); |
Hans-Kristian Arntzen | dd8acbb | 2021-03-22 13:41:47 +0100 | [diff] [blame] | 2630 | auto &funcs = cb->queue_submit_functions; |
Hans-Kristian Arntzen | 5b466db | 2021-03-18 13:59:46 +0100 | [diff] [blame] | 2631 | auto* src = GetImageUsageState(srcImage); |
| 2632 | auto* dst = GetImageUsageState(dstImage); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2633 | |
| 2634 | for (uint32_t i = 0; i < regionCount; i++) { |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 2635 | QueueValidateImage(funcs, "vkCmdCopyImage()", src, IMAGE_SUBRESOURCE_USAGE_BP::COPY_READ, pRegions[i].srcSubresource); |
| 2636 | QueueValidateImage(funcs, "vkCmdCopyImage()", dst, IMAGE_SUBRESOURCE_USAGE_BP::COPY_WRITE, pRegions[i].dstSubresource); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2637 | } |
| 2638 | } |
| 2639 | |
| 2640 | void BestPractices::PreCallRecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 2641 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 2642 | const VkBufferImageCopy* pRegions) { |
Hans-Kristian Arntzen | 66f4b52 | 2021-03-22 11:35:58 +0100 | [diff] [blame] | 2643 | CMD_BUFFER_STATE* cb = GetCBState(commandBuffer); |
Hans-Kristian Arntzen | dd8acbb | 2021-03-22 13:41:47 +0100 | [diff] [blame] | 2644 | auto &funcs = cb->queue_submit_functions; |
Hans-Kristian Arntzen | 5b466db | 2021-03-18 13:59:46 +0100 | [diff] [blame] | 2645 | auto* dst = GetImageUsageState(dstImage); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2646 | |
| 2647 | for (uint32_t i = 0; i < regionCount; i++) { |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 2648 | QueueValidateImage(funcs, "vkCmdCopyBufferToImage()", dst, IMAGE_SUBRESOURCE_USAGE_BP::COPY_WRITE, pRegions[i].imageSubresource); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2649 | } |
| 2650 | } |
| 2651 | |
| 2652 | void BestPractices::PreCallRecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 2653 | VkBuffer dstBuffer, uint32_t regionCount, const VkBufferImageCopy* pRegions) { |
Hans-Kristian Arntzen | 66f4b52 | 2021-03-22 11:35:58 +0100 | [diff] [blame] | 2654 | CMD_BUFFER_STATE* cb = GetCBState(commandBuffer); |
Hans-Kristian Arntzen | dd8acbb | 2021-03-22 13:41:47 +0100 | [diff] [blame] | 2655 | auto &funcs = cb->queue_submit_functions; |
Hans-Kristian Arntzen | 5b466db | 2021-03-18 13:59:46 +0100 | [diff] [blame] | 2656 | auto* src = GetImageUsageState(srcImage); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2657 | |
| 2658 | for (uint32_t i = 0; i < regionCount; i++) { |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 2659 | QueueValidateImage(funcs, "vkCmdCopyImageToBuffer()", src, IMAGE_SUBRESOURCE_USAGE_BP::COPY_READ, pRegions[i].imageSubresource); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2660 | } |
| 2661 | } |
| 2662 | |
| 2663 | void BestPractices::PreCallRecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 2664 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 2665 | const VkImageBlit* pRegions, VkFilter filter) { |
Hans-Kristian Arntzen | 66f4b52 | 2021-03-22 11:35:58 +0100 | [diff] [blame] | 2666 | CMD_BUFFER_STATE* cb = GetCBState(commandBuffer); |
Hans-Kristian Arntzen | dd8acbb | 2021-03-22 13:41:47 +0100 | [diff] [blame] | 2667 | auto &funcs = cb->queue_submit_functions; |
Hans-Kristian Arntzen | 5b466db | 2021-03-18 13:59:46 +0100 | [diff] [blame] | 2668 | auto* src = GetImageUsageState(srcImage); |
| 2669 | auto* dst = GetImageUsageState(dstImage); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2670 | |
| 2671 | for (uint32_t i = 0; i < regionCount; i++) { |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 2672 | QueueValidateImage(funcs, "vkCmdBlitImage()", src, IMAGE_SUBRESOURCE_USAGE_BP::BLIT_READ, pRegions[i].srcSubresource); |
| 2673 | QueueValidateImage(funcs, "vkCmdBlitImage()", dst, IMAGE_SUBRESOURCE_USAGE_BP::BLIT_WRITE, pRegions[i].dstSubresource); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2674 | } |
| 2675 | } |
| 2676 | |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 2677 | bool BestPractices::PreCallValidateCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, |
| 2678 | const VkAllocationCallbacks* pAllocator, VkSampler* pSampler) const { |
| 2679 | bool skip = false; |
| 2680 | |
| 2681 | if (VendorCheckEnabled(kBPVendorArm)) { |
| 2682 | if ((pCreateInfo->addressModeU != pCreateInfo->addressModeV) || (pCreateInfo->addressModeV != pCreateInfo->addressModeW)) { |
| 2683 | skip |= LogPerformanceWarning( |
| 2684 | device, kVUID_BestPractices_CreateSampler_DifferentWrappingModes, |
| 2685 | "%s Creating a sampler object with wrapping modes which do not match (U = %u, V = %u, W = %u). " |
| 2686 | "This may cause reduced performance even if only U (1D image) or U/V wrapping modes (2D " |
| 2687 | "image) are actually used. If you need different wrapping modes, disregard this warning.", |
Jeremy Gebben | da6b48f | 2021-05-13 10:46:18 -0600 | [diff] [blame] | 2688 | VendorSpecificTag(kBPVendorArm), pCreateInfo->addressModeU, pCreateInfo->addressModeV, pCreateInfo->addressModeW); |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 2689 | } |
| 2690 | |
| 2691 | if ((pCreateInfo->minLod != 0.0f) || (pCreateInfo->maxLod < VK_LOD_CLAMP_NONE)) { |
| 2692 | skip |= LogPerformanceWarning( |
| 2693 | device, kVUID_BestPractices_CreateSampler_LodClamping, |
| 2694 | "%s Creating a sampler object with LOD clamping (minLod = %f, maxLod = %f). This may cause reduced performance. " |
| 2695 | "Instead of clamping LOD in the sampler, consider using an VkImageView which restricts the mip-levels, set minLod " |
| 2696 | "to 0.0, and maxLod to VK_LOD_CLAMP_NONE.", |
| 2697 | VendorSpecificTag(kBPVendorArm), pCreateInfo->minLod, pCreateInfo->maxLod); |
| 2698 | } |
| 2699 | |
| 2700 | if (pCreateInfo->mipLodBias != 0.0f) { |
| 2701 | skip |= |
| 2702 | LogPerformanceWarning(device, kVUID_BestPractices_CreateSampler_LodBias, |
| 2703 | "%s Creating a sampler object with LOD bias != 0.0 (%f). This will lead to less efficient " |
| 2704 | "descriptors being created and may cause reduced performance.", |
| 2705 | VendorSpecificTag(kBPVendorArm), pCreateInfo->mipLodBias); |
| 2706 | } |
| 2707 | |
| 2708 | if ((pCreateInfo->addressModeU == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER || |
| 2709 | pCreateInfo->addressModeV == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER || |
| 2710 | pCreateInfo->addressModeW == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER) && |
| 2711 | (pCreateInfo->borderColor != VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK)) { |
| 2712 | skip |= LogPerformanceWarning( |
| 2713 | device, kVUID_BestPractices_CreateSampler_BorderClampColor, |
| 2714 | "%s Creating a sampler object with border clamping and borderColor != VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK. " |
| 2715 | "This will lead to less efficient descriptors being created and may cause reduced performance. " |
| 2716 | "If possible, use VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK as the border color.", |
| 2717 | VendorSpecificTag(kBPVendorArm)); |
| 2718 | } |
| 2719 | |
| 2720 | if (pCreateInfo->unnormalizedCoordinates) { |
| 2721 | skip |= LogPerformanceWarning( |
| 2722 | device, kVUID_BestPractices_CreateSampler_UnnormalizedCoordinates, |
| 2723 | "%s Creating a sampler object with unnormalized coordinates. This will lead to less efficient " |
| 2724 | "descriptors being created and may cause reduced performance.", |
| 2725 | VendorSpecificTag(kBPVendorArm)); |
| 2726 | } |
| 2727 | |
| 2728 | if (pCreateInfo->anisotropyEnable) { |
| 2729 | skip |= LogPerformanceWarning( |
| 2730 | device, kVUID_BestPractices_CreateSampler_Anisotropy, |
| 2731 | "%s Creating a sampler object with anisotropy. This will lead to less efficient descriptors being created " |
| 2732 | "and may cause reduced performance.", |
| 2733 | VendorSpecificTag(kBPVendorArm)); |
| 2734 | } |
| 2735 | } |
| 2736 | |
| 2737 | return skip; |
| 2738 | } |
Sam Walls | 8e77e4f | 2020-03-16 20:47:40 +0000 | [diff] [blame] | 2739 | |
| 2740 | void BestPractices::PostTransformLRUCacheModel::resize(size_t size) { _entries.resize(size); } |
| 2741 | |
| 2742 | bool BestPractices::PostTransformLRUCacheModel::query_cache(uint32_t value) { |
| 2743 | // look for a cache hit |
| 2744 | auto hit = std::find_if(_entries.begin(), _entries.end(), [value](const CacheEntry& entry) { return entry.value == value; }); |
| 2745 | if (hit != _entries.end()) { |
| 2746 | // mark the cache hit as being most recently used |
| 2747 | hit->age = iteration++; |
| 2748 | return true; |
| 2749 | } |
| 2750 | |
| 2751 | // if there's no cache hit, we need to model the entry being inserted into the cache |
| 2752 | CacheEntry new_entry = {value, iteration}; |
| 2753 | if (iteration < static_cast<uint32_t>(std::distance(_entries.begin(), _entries.end()))) { |
| 2754 | // if there is still space left in the cache, use the next available slot |
| 2755 | *(_entries.begin() + iteration) = new_entry; |
| 2756 | } else { |
| 2757 | // otherwise replace the least recently used cache entry |
| 2758 | auto lru = std::min_element(_entries.begin(), hit, [](const CacheEntry& a, const CacheEntry& b) { return a.age < b.age; }); |
| 2759 | *lru = new_entry; |
| 2760 | } |
| 2761 | iteration++; |
| 2762 | return false; |
| 2763 | } |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 2764 | |
| 2765 | bool BestPractices::PreCallValidateAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout, |
| 2766 | VkSemaphore semaphore, VkFence fence, uint32_t* pImageIndex) const { |
| 2767 | const auto swapchain_data = GetSwapchainState(swapchain); |
| 2768 | bool skip = false; |
| 2769 | if (swapchain_data && swapchain_data->images.size() == 0) { |
| 2770 | skip |= LogWarning(swapchain, kVUID_Core_DrawState_SwapchainImagesNotFound, |
| 2771 | "vkAcquireNextImageKHR: No images found to acquire from. Application probably did not call " |
| 2772 | "vkGetSwapchainImagesKHR after swapchain creation."); |
| 2773 | } |
| 2774 | return skip; |
| 2775 | } |
| 2776 | |
Nathaniel Cesario | 56a9665 | 2020-12-30 13:23:42 -0700 | [diff] [blame] | 2777 | void BestPractices::CommonPostCallRecordGetPhysicalDeviceQueueFamilyProperties(CALL_STATE& call_state, bool no_pointer) { |
| 2778 | if (no_pointer) { |
| 2779 | if (UNCALLED == call_state) { |
| 2780 | call_state = QUERY_COUNT; |
| 2781 | } |
| 2782 | } else { // Save queue family properties |
| 2783 | call_state = QUERY_DETAILS; |
| 2784 | } |
| 2785 | } |
| 2786 | |
Nathaniel Cesario | f121d12 | 2020-10-08 13:09:46 -0600 | [diff] [blame] | 2787 | void BestPractices::PostCallRecordGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, |
| 2788 | uint32_t* pQueueFamilyPropertyCount, |
| 2789 | VkQueueFamilyProperties* pQueueFamilyProperties) { |
| 2790 | ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties(physicalDevice, pQueueFamilyPropertyCount, |
| 2791 | pQueueFamilyProperties); |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 2792 | auto* bp_pd_state = GetPhysicalDeviceStateBP(physicalDevice); |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 2793 | if (bp_pd_state) { |
Nathaniel Cesario | 56a9665 | 2020-12-30 13:23:42 -0700 | [diff] [blame] | 2794 | CommonPostCallRecordGetPhysicalDeviceQueueFamilyProperties(bp_pd_state->vkGetPhysicalDeviceQueueFamilyPropertiesState, |
| 2795 | nullptr == pQueueFamilyProperties); |
| 2796 | } |
| 2797 | } |
| 2798 | |
| 2799 | void BestPractices::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2(VkPhysicalDevice physicalDevice, |
| 2800 | uint32_t* pQueueFamilyPropertyCount, |
| 2801 | VkQueueFamilyProperties2* pQueueFamilyProperties) { |
| 2802 | ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2(physicalDevice, pQueueFamilyPropertyCount, |
| 2803 | pQueueFamilyProperties); |
| 2804 | auto* bp_pd_state = GetPhysicalDeviceStateBP(physicalDevice); |
| 2805 | if (bp_pd_state) { |
| 2806 | CommonPostCallRecordGetPhysicalDeviceQueueFamilyProperties(bp_pd_state->vkGetPhysicalDeviceQueueFamilyProperties2State, |
| 2807 | nullptr == pQueueFamilyProperties); |
| 2808 | } |
| 2809 | } |
| 2810 | |
| 2811 | void BestPractices::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2KHR(VkPhysicalDevice physicalDevice, |
| 2812 | uint32_t* pQueueFamilyPropertyCount, |
| 2813 | VkQueueFamilyProperties2* pQueueFamilyProperties) { |
| 2814 | ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2KHR(physicalDevice, pQueueFamilyPropertyCount, |
| 2815 | pQueueFamilyProperties); |
| 2816 | auto* bp_pd_state = GetPhysicalDeviceStateBP(physicalDevice); |
| 2817 | if (bp_pd_state) { |
| 2818 | CommonPostCallRecordGetPhysicalDeviceQueueFamilyProperties(bp_pd_state->vkGetPhysicalDeviceQueueFamilyProperties2KHRState, |
| 2819 | nullptr == pQueueFamilyProperties); |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 2820 | } |
| 2821 | } |
| 2822 | |
Nathaniel Cesario | f121d12 | 2020-10-08 13:09:46 -0600 | [diff] [blame] | 2823 | void BestPractices::PostCallRecordGetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures* pFeatures) { |
| 2824 | ValidationStateTracker::PostCallRecordGetPhysicalDeviceFeatures(physicalDevice, pFeatures); |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 2825 | auto* bp_pd_state = GetPhysicalDeviceStateBP(physicalDevice); |
| 2826 | if (bp_pd_state) { |
| 2827 | bp_pd_state->vkGetPhysicalDeviceFeaturesState = QUERY_DETAILS; |
| 2828 | } |
| 2829 | } |
| 2830 | |
Nathaniel Cesario | f121d12 | 2020-10-08 13:09:46 -0600 | [diff] [blame] | 2831 | void BestPractices::PostCallRecordGetPhysicalDeviceFeatures2(VkPhysicalDevice physicalDevice, |
| 2832 | VkPhysicalDeviceFeatures2* pFeatures) { |
| 2833 | ValidationStateTracker::PostCallRecordGetPhysicalDeviceFeatures2(physicalDevice, pFeatures); |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 2834 | auto* bp_pd_state = GetPhysicalDeviceStateBP(physicalDevice); |
| 2835 | if (bp_pd_state) { |
| 2836 | bp_pd_state->vkGetPhysicalDeviceFeaturesState = QUERY_DETAILS; |
| 2837 | } |
| 2838 | } |
| 2839 | |
Nathaniel Cesario | f121d12 | 2020-10-08 13:09:46 -0600 | [diff] [blame] | 2840 | void BestPractices::PostCallRecordGetPhysicalDeviceFeatures2KHR(VkPhysicalDevice physicalDevice, |
| 2841 | VkPhysicalDeviceFeatures2* pFeatures) { |
| 2842 | ValidationStateTracker::PostCallRecordGetPhysicalDeviceFeatures2KHR(physicalDevice, pFeatures); |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 2843 | auto* bp_pd_state = GetPhysicalDeviceStateBP(physicalDevice); |
| 2844 | if (bp_pd_state) { |
| 2845 | bp_pd_state->vkGetPhysicalDeviceFeaturesState = QUERY_DETAILS; |
| 2846 | } |
| 2847 | } |
| 2848 | |
| 2849 | void BestPractices::ManualPostCallRecordGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice, |
| 2850 | VkSurfaceKHR surface, |
| 2851 | VkSurfaceCapabilitiesKHR* pSurfaceCapabilities, |
| 2852 | VkResult result) { |
| 2853 | auto* bp_pd_state = GetPhysicalDeviceStateBP(physicalDevice); |
| 2854 | if (bp_pd_state) { |
| 2855 | bp_pd_state->vkGetPhysicalDeviceSurfaceCapabilitiesKHRState = QUERY_DETAILS; |
| 2856 | } |
| 2857 | } |
| 2858 | |
| 2859 | void BestPractices::ManualPostCallRecordGetPhysicalDeviceSurfaceCapabilities2KHR( |
| 2860 | VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo, |
| 2861 | VkSurfaceCapabilities2KHR* pSurfaceCapabilities, VkResult result) { |
| 2862 | auto* bp_pd_state = GetPhysicalDeviceStateBP(physicalDevice); |
| 2863 | if (bp_pd_state) { |
| 2864 | bp_pd_state->vkGetPhysicalDeviceSurfaceCapabilitiesKHRState = QUERY_DETAILS; |
| 2865 | } |
| 2866 | } |
| 2867 | |
| 2868 | void BestPractices::ManualPostCallRecordGetPhysicalDeviceSurfaceCapabilities2EXT(VkPhysicalDevice physicalDevice, |
| 2869 | VkSurfaceKHR surface, |
| 2870 | VkSurfaceCapabilities2EXT* pSurfaceCapabilities, |
| 2871 | VkResult result) { |
| 2872 | auto* bp_pd_state = GetPhysicalDeviceStateBP(physicalDevice); |
| 2873 | if (bp_pd_state) { |
| 2874 | bp_pd_state->vkGetPhysicalDeviceSurfaceCapabilitiesKHRState = QUERY_DETAILS; |
| 2875 | } |
| 2876 | } |
| 2877 | |
| 2878 | void BestPractices::ManualPostCallRecordGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice, |
| 2879 | VkSurfaceKHR surface, uint32_t* pPresentModeCount, |
| 2880 | VkPresentModeKHR* pPresentModes, VkResult result) { |
| 2881 | auto* bp_pd_data = GetPhysicalDeviceStateBP(physicalDevice); |
| 2882 | if (bp_pd_data) { |
| 2883 | auto& call_state = bp_pd_data->vkGetPhysicalDeviceSurfacePresentModesKHRState; |
| 2884 | |
| 2885 | if (*pPresentModeCount) { |
| 2886 | if (call_state < QUERY_COUNT) { |
| 2887 | call_state = QUERY_COUNT; |
| 2888 | } |
| 2889 | } |
| 2890 | if (pPresentModes) { |
| 2891 | if (call_state < QUERY_DETAILS) { |
| 2892 | call_state = QUERY_DETAILS; |
| 2893 | } |
| 2894 | } |
| 2895 | } |
| 2896 | } |
| 2897 | |
| 2898 | void BestPractices::ManualPostCallRecordGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, |
| 2899 | uint32_t* pSurfaceFormatCount, |
| 2900 | VkSurfaceFormatKHR* pSurfaceFormats, VkResult result) { |
| 2901 | auto* bp_pd_data = GetPhysicalDeviceStateBP(physicalDevice); |
| 2902 | if (bp_pd_data) { |
| 2903 | auto& call_state = bp_pd_data->vkGetPhysicalDeviceSurfaceFormatsKHRState; |
| 2904 | |
| 2905 | if (*pSurfaceFormatCount) { |
| 2906 | if (call_state < QUERY_COUNT) { |
| 2907 | call_state = QUERY_COUNT; |
| 2908 | } |
| 2909 | } |
| 2910 | if (pSurfaceFormats) { |
| 2911 | if (call_state < QUERY_DETAILS) { |
| 2912 | call_state = QUERY_DETAILS; |
| 2913 | } |
| 2914 | } |
| 2915 | } |
| 2916 | } |
| 2917 | |
| 2918 | void BestPractices::ManualPostCallRecordGetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice, |
| 2919 | const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo, |
| 2920 | uint32_t* pSurfaceFormatCount, |
| 2921 | VkSurfaceFormat2KHR* pSurfaceFormats, VkResult result) { |
| 2922 | auto* bp_pd_data = GetPhysicalDeviceStateBP(physicalDevice); |
| 2923 | if (bp_pd_data) { |
| 2924 | if (*pSurfaceFormatCount) { |
| 2925 | if (bp_pd_data->vkGetPhysicalDeviceSurfaceFormatsKHRState < QUERY_COUNT) { |
| 2926 | bp_pd_data->vkGetPhysicalDeviceSurfaceFormatsKHRState = QUERY_COUNT; |
| 2927 | } |
| 2928 | } |
| 2929 | if (pSurfaceFormats) { |
| 2930 | if (bp_pd_data->vkGetPhysicalDeviceSurfaceFormatsKHRState < QUERY_DETAILS) { |
| 2931 | bp_pd_data->vkGetPhysicalDeviceSurfaceFormatsKHRState = QUERY_DETAILS; |
| 2932 | } |
| 2933 | } |
| 2934 | } |
| 2935 | } |
| 2936 | |
| 2937 | void BestPractices::ManualPostCallRecordGetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice, |
| 2938 | uint32_t* pPropertyCount, |
| 2939 | VkDisplayPlanePropertiesKHR* pProperties, |
| 2940 | VkResult result) { |
| 2941 | auto* bp_pd_data = GetPhysicalDeviceStateBP(physicalDevice); |
| 2942 | if (bp_pd_data) { |
| 2943 | if (*pPropertyCount) { |
| 2944 | if (bp_pd_data->vkGetPhysicalDeviceDisplayPlanePropertiesKHRState < QUERY_COUNT) { |
| 2945 | bp_pd_data->vkGetPhysicalDeviceDisplayPlanePropertiesKHRState = QUERY_COUNT; |
| 2946 | } |
| 2947 | } |
| 2948 | if (pProperties) { |
| 2949 | if (bp_pd_data->vkGetPhysicalDeviceDisplayPlanePropertiesKHRState < QUERY_DETAILS) { |
| 2950 | bp_pd_data->vkGetPhysicalDeviceDisplayPlanePropertiesKHRState = QUERY_DETAILS; |
| 2951 | } |
| 2952 | } |
| 2953 | } |
| 2954 | } |
| 2955 | |
| 2956 | void BestPractices::ManualPostCallRecordCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR* pCreateInfo, |
| 2957 | const VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pSwapchain, |
| 2958 | VkResult result) { |
| 2959 | if (VK_SUCCESS == result) { |
| 2960 | swapchain_bp_state_map.emplace(*pSwapchain, SWAPCHAIN_STATE_BP{}); |
| 2961 | } |
| 2962 | } |
| 2963 | |
Nathaniel Cesario | f121d12 | 2020-10-08 13:09:46 -0600 | [diff] [blame] | 2964 | void BestPractices::PostCallRecordDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain, |
| 2965 | const VkAllocationCallbacks* pAllocator) { |
| 2966 | ValidationStateTracker::PostCallRecordDestroySwapchainKHR(device, swapchain, pAllocator); |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 2967 | auto swapchain_state_itr = swapchain_bp_state_map.find(swapchain); |
| 2968 | if (swapchain_state_itr != swapchain_bp_state_map.cend()) { |
| 2969 | swapchain_bp_state_map.erase(swapchain_state_itr); |
| 2970 | } |
| 2971 | } |
| 2972 | |
| 2973 | void BestPractices::ManualPostCallRecordGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, |
| 2974 | uint32_t* pSwapchainImageCount, VkImage* pSwapchainImages, |
| 2975 | VkResult result) { |
| 2976 | auto swapchain_state_itr = swapchain_bp_state_map.find(swapchain); |
| 2977 | assert(swapchain_state_itr != swapchain_bp_state_map.cend()); |
| 2978 | auto& swapchain_state = swapchain_state_itr->second; |
| 2979 | if (pSwapchainImages || *pSwapchainImageCount) { |
| 2980 | if (swapchain_state.vkGetSwapchainImagesKHRState < QUERY_DETAILS) { |
| 2981 | swapchain_state.vkGetSwapchainImagesKHRState = QUERY_DETAILS; |
| 2982 | } |
| 2983 | } |
| 2984 | } |
| 2985 | |
| 2986 | void BestPractices::ManualPostCallRecordEnumeratePhysicalDevices(VkInstance instance, uint32_t* pPhysicalDeviceCount, |
| 2987 | VkPhysicalDevice* pPhysicalDevices, VkResult result) { |
| 2988 | if ((nullptr != pPhysicalDevices) && ((result == VK_SUCCESS || result == VK_INCOMPLETE))) { |
| 2989 | for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++) { |
| 2990 | phys_device_bp_state_map.emplace(pPhysicalDevices[i], PHYSICAL_DEVICE_STATE_BP{}); |
| 2991 | } |
| 2992 | } |
| 2993 | } |
| 2994 | |
| 2995 | void BestPractices::ManualPostCallRecordCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo*, const VkAllocationCallbacks*, |
| 2996 | VkDevice*, VkResult result) { |
| 2997 | if (VK_SUCCESS == result) { |
| 2998 | instance_device_bp_state = &phys_device_bp_state_map[gpu]; |
| 2999 | } |
| 3000 | } |
| 3001 | |
| 3002 | PHYSICAL_DEVICE_STATE_BP* BestPractices::GetPhysicalDeviceStateBP(const VkPhysicalDevice& phys_device) { |
| 3003 | if (phys_device_bp_state_map.count(phys_device) > 0) { |
| 3004 | return &phys_device_bp_state_map.at(phys_device); |
| 3005 | } else { |
| 3006 | return nullptr; |
| 3007 | } |
| 3008 | } |
| 3009 | |
| 3010 | const PHYSICAL_DEVICE_STATE_BP* BestPractices::GetPhysicalDeviceStateBP(const VkPhysicalDevice& phys_device) const { |
| 3011 | if (phys_device_bp_state_map.count(phys_device) > 0) { |
| 3012 | return &phys_device_bp_state_map.at(phys_device); |
| 3013 | } else { |
| 3014 | return nullptr; |
| 3015 | } |
| 3016 | } |
| 3017 | |
| 3018 | PHYSICAL_DEVICE_STATE_BP* BestPractices::GetPhysicalDeviceStateBP() { |
| 3019 | auto bp_state = (reinterpret_cast<BestPractices*>(instance_state))->instance_device_bp_state; |
| 3020 | if (bp_state) { |
| 3021 | return bp_state; |
| 3022 | } else if (!bp_state && phys_device_bp_state_map.count(physical_device_state->phys_device) > 0) { |
| 3023 | return &phys_device_bp_state_map.at(physical_device_state->phys_device); |
| 3024 | } else { |
| 3025 | return nullptr; |
| 3026 | } |
| 3027 | } |
| 3028 | |
| 3029 | const PHYSICAL_DEVICE_STATE_BP* BestPractices::GetPhysicalDeviceStateBP() const { |
| 3030 | auto bp_state = (reinterpret_cast<BestPractices*>(instance_state))->instance_device_bp_state; |
| 3031 | if (bp_state) { |
| 3032 | return bp_state; |
| 3033 | } else if (!bp_state && phys_device_bp_state_map.count(physical_device_state->phys_device) > 0) { |
| 3034 | return &phys_device_bp_state_map.at(physical_device_state->phys_device); |
| 3035 | } else { |
| 3036 | return nullptr; |
| 3037 | } |
| 3038 | } |
Hans-Kristian Arntzen | 66f4b52 | 2021-03-22 11:35:58 +0100 | [diff] [blame] | 3039 | |
| 3040 | void BestPractices::PreCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence) { |
| 3041 | ValidationStateTracker::PreCallRecordQueueSubmit(queue, submitCount, pSubmits, fence); |
| 3042 | |
| 3043 | QUEUE_STATE* queue_state = GetQueueState(queue); |
| 3044 | for (uint32_t submit = 0; submit < submitCount; submit++) { |
Hans-Kristian Arntzen | 69ace7d | 2021-04-28 14:17:19 +0200 | [diff] [blame] | 3045 | const auto& submit_info = pSubmits[submit]; |
Hans-Kristian Arntzen | 66f4b52 | 2021-03-22 11:35:58 +0100 | [diff] [blame] | 3046 | for (uint32_t cb_index = 0; cb_index < submit_info.commandBufferCount; cb_index++) { |
| 3047 | CMD_BUFFER_STATE* cb = GetCBState(submit_info.pCommandBuffers[cb_index]); |
| 3048 | for (auto &func : cb->queue_submit_functions) { |
| 3049 | func(this, queue_state); |
| 3050 | } |
| 3051 | } |
| 3052 | } |
| 3053 | } |
Hans-Kristian Arntzen | 7a5fdc5 | 2021-03-29 11:39:51 +0200 | [diff] [blame] | 3054 | |
| 3055 | void BestPractices::PreCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo* pBeginInfo) { |
| 3056 | ValidationStateTracker::PreCallRecordBeginCommandBuffer(commandBuffer, pBeginInfo); |
| 3057 | // This should not be required, but guards against buggy applications which do not call EndRenderPass correctly. |
| 3058 | queue_submit_functions_after_render_pass.clear(); |
Hans-Kristian Arntzen | b214795 | 2021-04-28 14:32:00 +0200 | [diff] [blame] | 3059 | } |