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 | |
| 292 | bool BestPractices::PreCallValidateCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR* pCreateInfo, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 293 | const VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pSwapchain) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 294 | bool skip = false; |
| 295 | |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 296 | const auto* bp_pd_state = GetPhysicalDeviceStateBP(); |
| 297 | if (bp_pd_state) { |
| 298 | if (bp_pd_state->vkGetPhysicalDeviceSurfaceCapabilitiesKHRState == UNCALLED) { |
| 299 | skip |= LogWarning(device, kVUID_BestPractices_Swapchain_GetSurfaceNotCalled, |
| 300 | "vkCreateSwapchainKHR() called before getting surface capabilities from " |
| 301 | "vkGetPhysicalDeviceSurfaceCapabilitiesKHR()."); |
| 302 | } |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 303 | |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 304 | if (bp_pd_state->vkGetPhysicalDeviceSurfacePresentModesKHRState != QUERY_DETAILS) { |
| 305 | skip |= LogWarning(device, kVUID_BestPractices_Swapchain_GetSurfaceNotCalled, |
| 306 | "vkCreateSwapchainKHR() called before getting surface present mode(s) from " |
| 307 | "vkGetPhysicalDeviceSurfacePresentModesKHR()."); |
| 308 | } |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 309 | |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 310 | if (bp_pd_state->vkGetPhysicalDeviceSurfaceFormatsKHRState != QUERY_DETAILS) { |
| 311 | skip |= LogWarning( |
| 312 | device, kVUID_BestPractices_Swapchain_GetSurfaceNotCalled, |
| 313 | "vkCreateSwapchainKHR() called before getting surface format(s) from vkGetPhysicalDeviceSurfaceFormatsKHR()."); |
| 314 | } |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 315 | } |
| 316 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 317 | if ((pCreateInfo->queueFamilyIndexCount > 1) && (pCreateInfo->imageSharingMode == VK_SHARING_MODE_EXCLUSIVE)) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 318 | skip |= |
| 319 | LogWarning(device, kVUID_BestPractices_SharingModeExclusive, |
Mark Lobodzinski | 019f4e3 | 2020-04-13 11:01:35 -0600 | [diff] [blame] | 320 | "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] | 321 | "specifying multiple queues (queueFamilyIndexCount of %" PRIu32 ").", |
| 322 | pCreateInfo->queueFamilyIndexCount); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 323 | } |
| 324 | |
Szilard Papp | 48a6da3 | 2020-06-10 14:41:59 +0100 | [diff] [blame] | 325 | if (pCreateInfo->minImageCount == 2) { |
| 326 | skip |= LogPerformanceWarning( |
| 327 | device, kVUID_BestPractices_SuboptimalSwapchainImageCount, |
| 328 | "Warning: A Swapchain is being created with minImageCount set to %" PRIu32 |
| 329 | ", which means double buffering is going " |
| 330 | "to be used. Using double buffering and vsync locks rendering to an integer fraction of the vsync rate. In turn, " |
| 331 | "reducing the performance of the application if rendering is slower than vsync. Consider setting minImageCount to " |
| 332 | "3 to use triple buffering to maximize performance in such cases.", |
| 333 | pCreateInfo->minImageCount); |
| 334 | } |
| 335 | |
Szilard Papp | d5f0f81 | 2020-06-22 09:01:29 +0100 | [diff] [blame] | 336 | if (VendorCheckEnabled(kBPVendorArm) && (pCreateInfo->presentMode != VK_PRESENT_MODE_FIFO_KHR)) { |
| 337 | skip |= LogWarning(device, kVUID_BestPractices_CreateSwapchain_PresentMode, |
| 338 | "%s Warning: Swapchain is not being created with presentation mode \"VK_PRESENT_MODE_FIFO_KHR\". " |
| 339 | "Prefer using \"VK_PRESENT_MODE_FIFO_KHR\" to avoid unnecessary CPU and GPU load and save power. " |
| 340 | "Presentation modes which are not FIFO will present the latest available frame and discard other " |
| 341 | "frame(s) if any.", |
| 342 | VendorSpecificTag(kBPVendorArm)); |
| 343 | } |
| 344 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 345 | return skip; |
| 346 | } |
| 347 | |
| 348 | bool BestPractices::PreCallValidateCreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount, |
| 349 | const VkSwapchainCreateInfoKHR* pCreateInfos, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 350 | const VkAllocationCallbacks* pAllocator, |
| 351 | VkSwapchainKHR* pSwapchains) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 352 | bool skip = false; |
| 353 | |
| 354 | for (uint32_t i = 0; i < swapchainCount; i++) { |
| 355 | if ((pCreateInfos[i].queueFamilyIndexCount > 1) && (pCreateInfos[i].imageSharingMode == VK_SHARING_MODE_EXCLUSIVE)) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 356 | skip |= LogWarning( |
| 357 | device, kVUID_BestPractices_SharingModeExclusive, |
| 358 | "Warning: A shared swapchain (index %" PRIu32 |
| 359 | ") is being created which specifies a sharing mode of VK_SHARING_MODE_EXCLUSIVE while specifying multiple " |
| 360 | "queues (queueFamilyIndexCount of %" PRIu32 ").", |
| 361 | i, pCreateInfos[i].queueFamilyIndexCount); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 362 | } |
| 363 | } |
| 364 | |
| 365 | return skip; |
| 366 | } |
| 367 | |
| 368 | bool BestPractices::PreCallValidateCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 369 | const VkAllocationCallbacks* pAllocator, VkRenderPass* pRenderPass) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 370 | bool skip = false; |
| 371 | |
| 372 | for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) { |
| 373 | VkFormat format = pCreateInfo->pAttachments[i].format; |
| 374 | if (pCreateInfo->pAttachments[i].initialLayout == VK_IMAGE_LAYOUT_UNDEFINED) { |
| 375 | if ((FormatIsColor(format) || FormatHasDepth(format)) && |
| 376 | pCreateInfo->pAttachments[i].loadOp == VK_ATTACHMENT_LOAD_OP_LOAD) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 377 | skip |= LogWarning(device, kVUID_BestPractices_RenderPass_Attatchment, |
| 378 | "Render pass has an attachment with loadOp == VK_ATTACHMENT_LOAD_OP_LOAD and " |
| 379 | "initialLayout == VK_IMAGE_LAYOUT_UNDEFINED. This is probably not what you " |
| 380 | "intended. Consider using VK_ATTACHMENT_LOAD_OP_DONT_CARE instead if the " |
| 381 | "image truely is undefined at the start of the render pass."); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 382 | } |
| 383 | if (FormatHasStencil(format) && pCreateInfo->pAttachments[i].stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 384 | skip |= LogWarning(device, kVUID_BestPractices_RenderPass_Attatchment, |
| 385 | "Render pass has an attachment with stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD " |
| 386 | "and initialLayout == VK_IMAGE_LAYOUT_UNDEFINED. This is probably not what you " |
| 387 | "intended. Consider using VK_ATTACHMENT_LOAD_OP_DONT_CARE instead if the " |
| 388 | "image truely is undefined at the start of the render pass."); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 389 | } |
| 390 | } |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 391 | |
| 392 | const auto& attachment = pCreateInfo->pAttachments[i]; |
| 393 | if (attachment.samples > VK_SAMPLE_COUNT_1_BIT) { |
| 394 | bool access_requires_memory = |
| 395 | attachment.loadOp == VK_ATTACHMENT_LOAD_OP_LOAD || attachment.storeOp == VK_ATTACHMENT_STORE_OP_STORE; |
| 396 | |
| 397 | if (FormatHasStencil(format)) { |
| 398 | access_requires_memory |= attachment.stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD || |
| 399 | attachment.stencilStoreOp == VK_ATTACHMENT_STORE_OP_STORE; |
| 400 | } |
| 401 | |
| 402 | if (access_requires_memory) { |
| 403 | skip |= LogPerformanceWarning( |
| 404 | device, kVUID_BestPractices_CreateRenderPass_ImageRequiresMemory, |
| 405 | "Attachment %u in the VkRenderPass is a multisampled image with %u samples, but it uses loadOp/storeOp " |
| 406 | "which requires accessing data from memory. Multisampled images should always be loadOp = CLEAR or DONT_CARE, " |
| 407 | "storeOp = DONT_CARE. This allows the implementation to use lazily allocated memory effectively.", |
| 408 | i, static_cast<uint32_t>(attachment.samples)); |
| 409 | } |
| 410 | } |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | for (uint32_t dependency = 0; dependency < pCreateInfo->dependencyCount; dependency++) { |
| 414 | skip |= CheckPipelineStageFlags("vkCreateRenderPass", pCreateInfo->pDependencies[dependency].srcStageMask); |
| 415 | skip |= CheckPipelineStageFlags("vkCreateRenderPass", pCreateInfo->pDependencies[dependency].dstStageMask); |
| 416 | } |
| 417 | |
| 418 | return skip; |
| 419 | } |
| 420 | |
Tony-LunarG | 767180f | 2020-04-23 14:03:59 -0600 | [diff] [blame] | 421 | bool BestPractices::ValidateAttachments(const VkRenderPassCreateInfo2* rpci, uint32_t attachmentCount, |
| 422 | const VkImageView* image_views) const { |
| 423 | bool skip = false; |
| 424 | |
| 425 | // Check for non-transient attachments that should be transient and vice versa |
| 426 | for (uint32_t i = 0; i < attachmentCount; ++i) { |
| 427 | auto& attachment = rpci->pAttachments[i]; |
| 428 | bool attachment_should_be_transient = |
| 429 | (attachment.loadOp != VK_ATTACHMENT_LOAD_OP_LOAD && attachment.storeOp != VK_ATTACHMENT_STORE_OP_STORE); |
| 430 | |
| 431 | if (FormatHasStencil(attachment.format)) { |
| 432 | attachment_should_be_transient &= (attachment.stencilLoadOp != VK_ATTACHMENT_LOAD_OP_LOAD && |
| 433 | attachment.stencilStoreOp != VK_ATTACHMENT_STORE_OP_STORE); |
| 434 | } |
| 435 | |
| 436 | auto view_state = GetImageViewState(image_views[i]); |
| 437 | if (view_state) { |
| 438 | auto& ivci = view_state->create_info; |
| 439 | auto& ici = GetImageState(ivci.image)->createInfo; |
| 440 | |
| 441 | bool image_is_transient = (ici.usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) != 0; |
| 442 | |
| 443 | // The check for an image that should not be transient applies to all GPUs |
| 444 | if (!attachment_should_be_transient && image_is_transient) { |
| 445 | skip |= LogPerformanceWarning( |
| 446 | device, kVUID_BestPractices_CreateFramebuffer_AttachmentShouldNotBeTransient, |
| 447 | "Attachment %u in VkFramebuffer uses loadOp/storeOps which need to access physical memory, " |
| 448 | "but the image backing the image view has VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT set. " |
| 449 | "Physical memory will need to be backed lazily to this image, potentially causing stalls.", |
| 450 | i); |
| 451 | } |
| 452 | |
| 453 | bool supports_lazy = false; |
| 454 | for (uint32_t j = 0; j < phys_dev_mem_props.memoryTypeCount; j++) { |
| 455 | if (phys_dev_mem_props.memoryTypes[j].propertyFlags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) { |
| 456 | supports_lazy = true; |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | // The check for an image that should be transient only applies to GPUs supporting |
| 461 | // lazily allocated memory |
| 462 | if (supports_lazy && attachment_should_be_transient && !image_is_transient) { |
| 463 | skip |= LogPerformanceWarning( |
| 464 | device, kVUID_BestPractices_CreateFramebuffer_AttachmentShouldBeTransient, |
| 465 | "Attachment %u in VkFramebuffer uses loadOp/storeOps which never have to be backed by physical memory, " |
| 466 | "but the image backing the image view does not have VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT set. " |
| 467 | "You can save physical memory by using transient attachment backed by lazily allocated memory here.", |
| 468 | i); |
| 469 | } |
| 470 | } |
| 471 | } |
| 472 | return skip; |
| 473 | } |
| 474 | |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 475 | bool BestPractices::PreCallValidateCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, |
| 476 | const VkAllocationCallbacks* pAllocator, VkFramebuffer* pFramebuffer) const { |
| 477 | bool skip = false; |
| 478 | |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 479 | auto rp_state = GetRenderPassState(pCreateInfo->renderPass); |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 480 | if (rp_state && !(pCreateInfo->flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT)) { |
Tony-LunarG | 767180f | 2020-04-23 14:03:59 -0600 | [diff] [blame] | 481 | skip = ValidateAttachments(rp_state->createInfo.ptr(), pCreateInfo->attachmentCount, pCreateInfo->pAttachments); |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | return skip; |
| 485 | } |
| 486 | |
Sam Walls | e746d52 | 2020-03-16 21:20:23 +0000 | [diff] [blame] | 487 | bool BestPractices::PreCallValidateAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo* pAllocateInfo, |
| 488 | VkDescriptorSet* pDescriptorSets, void* ads_state_data) const { |
| 489 | bool skip = false; |
| 490 | skip |= ValidationStateTracker::PreCallValidateAllocateDescriptorSets(device, pAllocateInfo, pDescriptorSets, ads_state_data); |
| 491 | |
| 492 | if (!skip) { |
| 493 | const auto& pool_handle = pAllocateInfo->descriptorPool; |
| 494 | auto iter = descriptor_pool_freed_count.find(pool_handle); |
| 495 | // if the number of freed sets > 0, it implies they could be recycled instead if desirable |
| 496 | // this warning is specific to Arm |
| 497 | if (VendorCheckEnabled(kBPVendorArm) && iter != descriptor_pool_freed_count.end() && iter->second > 0) { |
| 498 | skip |= LogPerformanceWarning( |
| 499 | device, kVUID_BestPractices_AllocateDescriptorSets_SuboptimalReuse, |
| 500 | "%s Descriptor set memory was allocated via vkAllocateDescriptorSets() for sets which were previously freed in the " |
| 501 | "same logical device. On some drivers or architectures it may be most optimal to re-use existing descriptor sets.", |
| 502 | VendorSpecificTag(kBPVendorArm)); |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | return skip; |
| 507 | } |
| 508 | |
Mark Lobodzinski | 84101d7 | 2020-04-24 09:43:48 -0600 | [diff] [blame] | 509 | void BestPractices::ManualPostCallRecordAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo* pAllocateInfo, |
| 510 | VkDescriptorSet* pDescriptorSets, VkResult result, void* ads_state) { |
Sam Walls | e746d52 | 2020-03-16 21:20:23 +0000 | [diff] [blame] | 511 | if (result == VK_SUCCESS) { |
| 512 | // find the free count for the pool we allocated into |
| 513 | auto iter = descriptor_pool_freed_count.find(pAllocateInfo->descriptorPool); |
| 514 | if (iter != descriptor_pool_freed_count.end()) { |
| 515 | // we record successful allocations by subtracting the allocation count from the last recorded free count |
| 516 | const auto alloc_count = pAllocateInfo->descriptorSetCount; |
| 517 | // clamp the unsigned subtraction to the range [0, last_free_count] |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 518 | if (iter->second > alloc_count) { |
Sam Walls | e746d52 | 2020-03-16 21:20:23 +0000 | [diff] [blame] | 519 | iter->second -= alloc_count; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 520 | } else { |
Sam Walls | e746d52 | 2020-03-16 21:20:23 +0000 | [diff] [blame] | 521 | iter->second = 0; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 522 | } |
Sam Walls | e746d52 | 2020-03-16 21:20:23 +0000 | [diff] [blame] | 523 | } |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | void BestPractices::PostCallRecordFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t descriptorSetCount, |
| 528 | const VkDescriptorSet* pDescriptorSets, VkResult result) { |
| 529 | ValidationStateTracker::PostCallRecordFreeDescriptorSets(device, descriptorPool, descriptorSetCount, pDescriptorSets, result); |
| 530 | if (result == VK_SUCCESS) { |
| 531 | // we want to track frees because we're interested in suggesting re-use |
| 532 | auto iter = descriptor_pool_freed_count.find(descriptorPool); |
| 533 | if (iter == descriptor_pool_freed_count.end()) { |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame^] | 534 | descriptor_pool_freed_count.emplace(descriptorPool, descriptorSetCount); |
Sam Walls | e746d52 | 2020-03-16 21:20:23 +0000 | [diff] [blame] | 535 | } else { |
| 536 | iter->second += descriptorSetCount; |
| 537 | } |
| 538 | } |
| 539 | } |
| 540 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 541 | bool BestPractices::PreCallValidateAllocateMemory(VkDevice device, const VkMemoryAllocateInfo* pAllocateInfo, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 542 | const VkAllocationCallbacks* pAllocator, VkDeviceMemory* pMemory) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 543 | bool skip = false; |
| 544 | |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 545 | if (num_mem_objects + 1 > kMemoryObjectWarningLimit) { |
Mark Lobodzinski | f95a266 | 2020-01-29 15:43:32 -0700 | [diff] [blame] | 546 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_AllocateMemory_TooManyObjects, |
| 547 | "Performance Warning: This app has > %" PRIu32 " memory objects.", kMemoryObjectWarningLimit); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 548 | } |
| 549 | |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 550 | if (pAllocateInfo->allocationSize < kMinDeviceAllocationSize) { |
| 551 | skip |= LogPerformanceWarning( |
| 552 | device, kVUID_BestPractices_AllocateMemory_SmallAllocation, |
| 553 | "vkAllocateMemory(): Allocating a VkDeviceMemory of size %llu. This is a very small allocation (current " |
| 554 | "threshold is %llu bytes). " |
| 555 | "You should make large allocations and sub-allocate from one large VkDeviceMemory.", |
| 556 | pAllocateInfo->allocationSize, kMinDeviceAllocationSize); |
| 557 | } |
| 558 | |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 559 | // TODO: Insert get check for GetPhysicalDeviceMemoryProperties once the state is tracked in the StateTracker |
| 560 | |
| 561 | return skip; |
| 562 | } |
| 563 | |
Mark Lobodzinski | 84101d7 | 2020-04-24 09:43:48 -0600 | [diff] [blame] | 564 | void BestPractices::ManualPostCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo* pAllocateInfo, |
| 565 | const VkAllocationCallbacks* pAllocator, VkDeviceMemory* pMemory, |
| 566 | VkResult result) { |
Mark Lobodzinski | 205b7a0 | 2020-02-21 13:23:17 -0700 | [diff] [blame] | 567 | if (result != VK_SUCCESS) { |
| 568 | static std::vector<VkResult> error_codes = {VK_ERROR_OUT_OF_HOST_MEMORY, VK_ERROR_OUT_OF_DEVICE_MEMORY, |
| 569 | VK_ERROR_TOO_MANY_OBJECTS, VK_ERROR_INVALID_EXTERNAL_HANDLE, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 570 | VK_ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS}; |
Mark Lobodzinski | 205b7a0 | 2020-02-21 13:23:17 -0700 | [diff] [blame] | 571 | static std::vector<VkResult> success_codes = {}; |
| 572 | ValidateReturnCodes("vkReleaseFullScreenExclusiveModeEXT", result, error_codes, success_codes); |
| 573 | return; |
| 574 | } |
| 575 | num_mem_objects++; |
| 576 | } |
Camden Stocker | 9738af9 | 2019-10-16 13:54:03 -0700 | [diff] [blame] | 577 | |
Mark Lobodzinski | de15e58 | 2020-04-29 08:06:00 -0600 | [diff] [blame] | 578 | void BestPractices::ValidateReturnCodes(const char* api_name, VkResult result, const std::vector<VkResult>& error_codes, |
| 579 | const std::vector<VkResult>& success_codes) const { |
Mark Lobodzinski | 205b7a0 | 2020-02-21 13:23:17 -0700 | [diff] [blame] | 580 | auto error = std::find(error_codes.begin(), error_codes.end(), result); |
| 581 | if (error != error_codes.end()) { |
Gareth Webb | 586c46b | 2021-01-13 11:17:22 +0000 | [diff] [blame] | 582 | static const std::vector<VkResult> common_failure_codes = {VK_ERROR_OUT_OF_DATE_KHR, |
| 583 | VK_ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXT}; |
| 584 | |
| 585 | auto common_failure = std::find(common_failure_codes.begin(), common_failure_codes.end(), result); |
| 586 | if (common_failure != common_failure_codes.end()) { |
| 587 | LogInfo(instance, kVUID_BestPractices_Failure_Result, "%s(): Returned error %s.", api_name, string_VkResult(result)); |
| 588 | } else { |
| 589 | LogWarning(instance, kVUID_BestPractices_Error_Result, "%s(): Returned error %s.", api_name, string_VkResult(result)); |
| 590 | } |
Mark Lobodzinski | 205b7a0 | 2020-02-21 13:23:17 -0700 | [diff] [blame] | 591 | return; |
| 592 | } |
| 593 | auto success = std::find(success_codes.begin(), success_codes.end(), result); |
| 594 | if (success != success_codes.end()) { |
Mark Lobodzinski | e721515 | 2020-05-11 08:21:23 -0600 | [diff] [blame] | 595 | LogInfo(instance, kVUID_BestPractices_NonSuccess_Result, "%s(): Returned non-success return code %s.", api_name, |
| 596 | string_VkResult(result)); |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 597 | } |
| 598 | } |
| 599 | |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 600 | bool BestPractices::PreCallValidateFreeMemory(VkDevice device, VkDeviceMemory memory, |
| 601 | const VkAllocationCallbacks* pAllocator) const { |
Mark Lobodzinski | 91e50bf | 2020-01-14 09:55:11 -0700 | [diff] [blame] | 602 | if (memory == VK_NULL_HANDLE) return false; |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 603 | bool skip = false; |
| 604 | |
Camden Stocker | 9738af9 | 2019-10-16 13:54:03 -0700 | [diff] [blame] | 605 | const DEVICE_MEMORY_STATE* mem_info = ValidationStateTracker::GetDevMemState(memory); |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 606 | |
| 607 | for (auto& obj : mem_info->obj_bindings) { |
Mark Lobodzinski | 818425a | 2020-03-16 18:19:03 -0600 | [diff] [blame] | 608 | LogObjectList objlist(device); |
| 609 | objlist.add(obj); |
| 610 | objlist.add(mem_info->mem); |
| 611 | skip |= LogWarning(objlist, layer_name.c_str(), "VK Object %s still has a reference to mem obj %s.", |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 612 | 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] | 613 | } |
| 614 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 615 | return skip; |
| 616 | } |
| 617 | |
| 618 | void BestPractices::PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory memory, const VkAllocationCallbacks* pAllocator) { |
Mark Lobodzinski | 97484d6 | 2020-03-03 11:57:41 -0700 | [diff] [blame] | 619 | ValidationStateTracker::PreCallRecordFreeMemory(device, memory, pAllocator); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 620 | if (memory != VK_NULL_HANDLE) { |
| 621 | num_mem_objects--; |
| 622 | } |
| 623 | } |
| 624 | |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 625 | bool BestPractices::ValidateBindBufferMemory(VkBuffer buffer, VkDeviceMemory memory, const char* api_name) const { |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 626 | bool skip = false; |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 627 | const BUFFER_STATE* buffer_state = GetBufferState(buffer); |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 628 | |
sfricke-samsung | e244119 | 2019-11-06 14:07:57 -0800 | [diff] [blame] | 629 | if (!buffer_state->memory_requirements_checked && !buffer_state->external_memory_handle) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 630 | skip |= LogWarning(device, kVUID_BestPractices_BufferMemReqNotCalled, |
| 631 | "%s: Binding memory to %s but vkGetBufferMemoryRequirements() has not been called on that buffer.", |
| 632 | api_name, report_data->FormatHandle(buffer).c_str()); |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 633 | } |
| 634 | |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 635 | const DEVICE_MEMORY_STATE* mem_state = GetDevMemState(memory); |
| 636 | |
| 637 | if (mem_state->alloc_info.allocationSize == buffer_state->createInfo.size && |
| 638 | mem_state->alloc_info.allocationSize < kMinDedicatedAllocationSize) { |
| 639 | skip |= LogPerformanceWarning( |
| 640 | device, kVUID_BestPractices_SmallDedicatedAllocation, |
| 641 | "%s: Trying to bind %s to a memory block which is fully consumed by the buffer. " |
| 642 | "The required size of the allocation is %llu, but smaller buffers like this should be sub-allocated from " |
| 643 | "larger memory blocks. (Current threshold is %llu bytes.)", |
| 644 | api_name, report_data->FormatHandle(buffer).c_str(), mem_state->alloc_info.allocationSize, kMinDedicatedAllocationSize); |
| 645 | } |
| 646 | |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 647 | return skip; |
| 648 | } |
| 649 | |
| 650 | bool BestPractices::PreCallValidateBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory memory, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 651 | VkDeviceSize memoryOffset) const { |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 652 | bool skip = false; |
| 653 | const char* api_name = "BindBufferMemory()"; |
| 654 | |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 655 | skip |= ValidateBindBufferMemory(buffer, memory, api_name); |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 656 | |
| 657 | return skip; |
| 658 | } |
| 659 | |
| 660 | bool BestPractices::PreCallValidateBindBufferMemory2(VkDevice device, uint32_t bindInfoCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 661 | const VkBindBufferMemoryInfo* pBindInfos) const { |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 662 | char api_name[64]; |
| 663 | bool skip = false; |
| 664 | |
| 665 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 666 | sprintf(api_name, "vkBindBufferMemory2() pBindInfos[%u]", i); |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 667 | skip |= ValidateBindBufferMemory(pBindInfos[i].buffer, pBindInfos[i].memory, api_name); |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | return skip; |
| 671 | } |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 672 | |
| 673 | bool BestPractices::PreCallValidateBindBufferMemory2KHR(VkDevice device, uint32_t bindInfoCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 674 | const VkBindBufferMemoryInfo* pBindInfos) const { |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 675 | char api_name[64]; |
| 676 | bool skip = false; |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 677 | |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 678 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 679 | sprintf(api_name, "vkBindBufferMemory2KHR() pBindInfos[%u]", i); |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 680 | skip |= ValidateBindBufferMemory(pBindInfos[i].buffer, pBindInfos[i].memory, api_name); |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | return skip; |
| 684 | } |
| 685 | |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 686 | bool BestPractices::ValidateBindImageMemory(VkImage image, VkDeviceMemory memory, const char* api_name) const { |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 687 | bool skip = false; |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 688 | const IMAGE_STATE* image_state = GetImageState(image); |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 689 | |
sfricke-samsung | 71bc657 | 2020-04-29 15:49:43 -0700 | [diff] [blame] | 690 | if (image_state->disjoint == false) { |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 691 | if (!image_state->memory_requirements_checked && !image_state->external_memory_handle) { |
| 692 | skip |= LogWarning(device, kVUID_BestPractices_ImageMemReqNotCalled, |
| 693 | "%s: Binding memory to %s but vkGetImageMemoryRequirements() has not been called on that image.", |
| 694 | api_name, report_data->FormatHandle(image).c_str()); |
| 695 | } |
| 696 | } else { |
| 697 | // TODO If binding disjoint image then this needs to check that VkImagePlaneMemoryRequirementsInfo was called for each |
| 698 | // plane. |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 699 | } |
| 700 | |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 701 | const DEVICE_MEMORY_STATE* mem_state = GetDevMemState(memory); |
| 702 | |
| 703 | if (mem_state->alloc_info.allocationSize == image_state->requirements.size && |
| 704 | mem_state->alloc_info.allocationSize < kMinDedicatedAllocationSize) { |
| 705 | skip |= LogPerformanceWarning( |
| 706 | device, kVUID_BestPractices_SmallDedicatedAllocation, |
| 707 | "%s: Trying to bind %s to a memory block which is fully consumed by the image. " |
| 708 | "The required size of the allocation is %llu, but smaller images like this should be sub-allocated from " |
| 709 | "larger memory blocks. (Current threshold is %llu bytes.)", |
| 710 | api_name, report_data->FormatHandle(image).c_str(), mem_state->alloc_info.allocationSize, kMinDedicatedAllocationSize); |
| 711 | } |
| 712 | |
| 713 | // If we're binding memory to a image which was created as TRANSIENT and the image supports LAZY allocation, |
| 714 | // make sure this type is actually used. |
| 715 | // This warning will only trigger if this layer is run on a platform that supports LAZILY_ALLOCATED_BIT |
| 716 | // (i.e.most tile - based renderers) |
| 717 | if (image_state->createInfo.usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) { |
| 718 | bool supports_lazy = false; |
| 719 | uint32_t suggested_type = 0; |
| 720 | |
| 721 | for (uint32_t i = 0; i < phys_dev_mem_props.memoryTypeCount; i++) { |
| 722 | if ((1u << i) & image_state->requirements.memoryTypeBits) { |
| 723 | if (phys_dev_mem_props.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) { |
| 724 | supports_lazy = true; |
| 725 | suggested_type = i; |
| 726 | break; |
| 727 | } |
| 728 | } |
| 729 | } |
| 730 | |
| 731 | uint32_t allocated_properties = phys_dev_mem_props.memoryTypes[mem_state->alloc_info.memoryTypeIndex].propertyFlags; |
| 732 | |
| 733 | if (supports_lazy && (allocated_properties & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) == 0) { |
| 734 | skip |= LogPerformanceWarning( |
| 735 | device, kVUID_BestPractices_NonLazyTransientImage, |
| 736 | "%s: Attempting to bind memory type % u to VkImage which was created with TRANSIENT_ATTACHMENT_BIT," |
| 737 | "but this memory type is not LAZILY_ALLOCATED_BIT. You should use memory type %u here instead to save " |
| 738 | "%llu bytes of physical memory.", |
| 739 | api_name, mem_state->alloc_info.memoryTypeIndex, suggested_type, image_state->requirements.size); |
| 740 | } |
| 741 | } |
| 742 | |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 743 | return skip; |
| 744 | } |
| 745 | |
| 746 | bool BestPractices::PreCallValidateBindImageMemory(VkDevice device, VkImage image, VkDeviceMemory memory, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 747 | VkDeviceSize memoryOffset) const { |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 748 | bool skip = false; |
| 749 | const char* api_name = "vkBindImageMemory()"; |
| 750 | |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 751 | skip |= ValidateBindImageMemory(image, memory, api_name); |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 752 | |
| 753 | return skip; |
| 754 | } |
| 755 | |
| 756 | bool BestPractices::PreCallValidateBindImageMemory2(VkDevice device, uint32_t bindInfoCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 757 | const VkBindImageMemoryInfo* pBindInfos) const { |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 758 | char api_name[64]; |
| 759 | bool skip = false; |
| 760 | |
| 761 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 762 | sprintf(api_name, "vkBindImageMemory2() pBindInfos[%u]", i); |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 763 | if (!LvlFindInChain<VkBindImageMemorySwapchainInfoKHR>(pBindInfos[i].pNext)) { |
Tony-LunarG | 5e60b85 | 2020-04-27 11:27:54 -0600 | [diff] [blame] | 764 | skip |= ValidateBindImageMemory(pBindInfos[i].image, pBindInfos[i].memory, api_name); |
| 765 | } |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | return skip; |
| 769 | } |
| 770 | |
| 771 | bool BestPractices::PreCallValidateBindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 772 | const VkBindImageMemoryInfo* pBindInfos) const { |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 773 | char api_name[64]; |
| 774 | bool skip = false; |
| 775 | |
| 776 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 777 | sprintf(api_name, "vkBindImageMemory2KHR() pBindInfos[%u]", i); |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 778 | skip |= ValidateBindImageMemory(pBindInfos[i].image, pBindInfos[i].memory, api_name); |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | return skip; |
| 782 | } |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 783 | |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 784 | static inline bool FormatHasFullThroughputBlendingArm(VkFormat format) { |
| 785 | switch (format) { |
| 786 | case VK_FORMAT_B10G11R11_UFLOAT_PACK32: |
| 787 | case VK_FORMAT_R16_SFLOAT: |
| 788 | case VK_FORMAT_R16G16_SFLOAT: |
| 789 | case VK_FORMAT_R16G16B16_SFLOAT: |
| 790 | case VK_FORMAT_R16G16B16A16_SFLOAT: |
| 791 | case VK_FORMAT_R32_SFLOAT: |
| 792 | case VK_FORMAT_R32G32_SFLOAT: |
| 793 | case VK_FORMAT_R32G32B32_SFLOAT: |
| 794 | case VK_FORMAT_R32G32B32A32_SFLOAT: |
| 795 | return false; |
| 796 | |
| 797 | default: |
| 798 | return true; |
| 799 | } |
| 800 | } |
| 801 | |
| 802 | bool BestPractices::ValidateMultisampledBlendingArm(uint32_t createInfoCount, |
| 803 | const VkGraphicsPipelineCreateInfo* pCreateInfos) const { |
| 804 | bool skip = false; |
| 805 | |
| 806 | for (uint32_t i = 0; i < createInfoCount; i++) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 807 | auto create_info = &pCreateInfos[i]; |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 808 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 809 | if (!create_info->pColorBlendState || !create_info->pMultisampleState || |
| 810 | create_info->pMultisampleState->rasterizationSamples == VK_SAMPLE_COUNT_1_BIT || |
| 811 | create_info->pMultisampleState->sampleShadingEnable) { |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 812 | return skip; |
| 813 | } |
| 814 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 815 | auto rp_state = GetRenderPassState(create_info->renderPass); |
| 816 | auto& subpass = rp_state->createInfo.pSubpasses[create_info->subpass]; |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 817 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 818 | for (uint32_t j = 0; j < create_info->pColorBlendState->attachmentCount; j++) { |
| 819 | auto& blend_att = create_info->pColorBlendState->pAttachments[j]; |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 820 | uint32_t att = subpass.pColorAttachments[j].attachment; |
| 821 | |
| 822 | if (att != VK_ATTACHMENT_UNUSED && blend_att.blendEnable && blend_att.colorWriteMask) { |
| 823 | if (!FormatHasFullThroughputBlendingArm(rp_state->createInfo.pAttachments[att].format)) { |
| 824 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_CreatePipelines_MultisampledBlending, |
| 825 | "%s vkCreateGraphicsPipelines() - createInfo #%u: Pipeline is multisampled and " |
| 826 | "color attachment #%u makes use " |
| 827 | "of a format which cannot be blended at full throughput when using MSAA.", |
| 828 | VendorSpecificTag(kBPVendorArm), i, j); |
| 829 | } |
| 830 | } |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | return skip; |
| 835 | } |
| 836 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 837 | bool BestPractices::PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount, |
| 838 | const VkGraphicsPipelineCreateInfo* pCreateInfos, |
Mark Lobodzinski | 2a162a0 | 2019-09-06 11:02:12 -0600 | [diff] [blame] | 839 | const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 840 | void* cgpl_state_data) const { |
Mark Lobodzinski | 8317a3e | 2019-09-20 10:07:08 -0600 | [diff] [blame] | 841 | bool skip = StateTracker::PreCallValidateCreateGraphicsPipelines(device, pipelineCache, createInfoCount, pCreateInfos, |
| 842 | pAllocator, pPipelines, cgpl_state_data); |
Mark Lobodzinski | 8dd14d8 | 2020-04-10 14:16:33 -0600 | [diff] [blame] | 843 | 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] | 844 | |
| 845 | if ((createInfoCount > 1) && (!pipelineCache)) { |
Mark Lobodzinski | f95a266 | 2020-01-29 15:43:32 -0700 | [diff] [blame] | 846 | skip |= LogPerformanceWarning( |
| 847 | device, kVUID_BestPractices_CreatePipelines_MultiplePipelines, |
| 848 | "Performance Warning: This vkCreateGraphicsPipelines call is creating multiple pipelines but is not using a " |
| 849 | "pipeline cache, which may help with performance"); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 850 | } |
| 851 | |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 852 | for (uint32_t i = 0; i < createInfoCount; i++) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 853 | auto& create_info = pCreateInfos[i]; |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 854 | |
Mark Lobodzinski | 8dd14d8 | 2020-04-10 14:16:33 -0600 | [diff] [blame] | 855 | if (!(cgpl_state->pipe_state[i]->active_shaders & VK_SHADER_STAGE_MESH_BIT_NV)) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 856 | auto& vertex_input = *create_info.pVertexInputState; |
Mark Lobodzinski | 8dd14d8 | 2020-04-10 14:16:33 -0600 | [diff] [blame] | 857 | uint32_t count = 0; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 858 | for (uint32_t j = 0; j < vertex_input.vertexBindingDescriptionCount; j++) { |
| 859 | if (vertex_input.pVertexBindingDescriptions[j].inputRate == VK_VERTEX_INPUT_RATE_INSTANCE) { |
Mark Lobodzinski | 8dd14d8 | 2020-04-10 14:16:33 -0600 | [diff] [blame] | 860 | count++; |
| 861 | } |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 862 | } |
Mark Lobodzinski | 8dd14d8 | 2020-04-10 14:16:33 -0600 | [diff] [blame] | 863 | if (count > kMaxInstancedVertexBuffers) { |
| 864 | skip |= LogPerformanceWarning( |
| 865 | device, kVUID_BestPractices_CreatePipelines_TooManyInstancedVertexBuffers, |
| 866 | "The pipeline is using %u instanced vertex buffers (current limit: %u), but this can be inefficient on the " |
| 867 | "GPU. If using instanced vertex attributes prefer interleaving them in a single buffer.", |
| 868 | count, kMaxInstancedVertexBuffers); |
| 869 | } |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 870 | } |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 871 | |
Szilard Papp | aaf2da3 | 2020-06-22 10:37:35 +0100 | [diff] [blame] | 872 | if ((pCreateInfos[i].pRasterizationState->depthBiasEnable) && |
| 873 | (pCreateInfos[i].pRasterizationState->depthBiasConstantFactor == 0.0f) && |
| 874 | (pCreateInfos[i].pRasterizationState->depthBiasSlopeFactor == 0.0f)) { |
| 875 | skip |= VendorCheckEnabled(kBPVendorArm) && |
| 876 | LogPerformanceWarning( |
| 877 | device, kVUID_BestPractices_CreatePipelines_DepthBias_Zero, |
| 878 | "%s Performance Warning: This vkCreateGraphicsPipelines call is created with depthBiasEnable set to true " |
| 879 | "and both depthBiasConstantFactor and depthBiasSlopeFactor are set to 0. This can cause reduced " |
| 880 | "efficiency during rasterization. Consider disabling depthBias or increasing either " |
| 881 | "depthBiasConstantFactor or depthBiasSlopeFactor.", |
| 882 | VendorSpecificTag(kBPVendorArm)); |
| 883 | } |
| 884 | |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 885 | skip |= VendorCheckEnabled(kBPVendorArm) && ValidateMultisampledBlendingArm(createInfoCount, pCreateInfos); |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 886 | } |
| 887 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 888 | return skip; |
| 889 | } |
| 890 | |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 891 | void BestPractices::ManualPostCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, |
| 892 | const VkGraphicsPipelineCreateInfo* pCreateInfos, |
| 893 | const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines, |
| 894 | VkResult result, void* cgpl_state_data) { |
| 895 | for (size_t i = 0; i < count; i++) { |
| 896 | const auto* cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state*>(cgpl_state_data); |
| 897 | const VkPipeline pipeline_handle = pPipelines[i]; |
| 898 | |
| 899 | // record depth stencil state and color blend states for depth pre-pass tracking purposes |
| 900 | auto gp_cis = graphicsPipelineCIs.find(pipeline_handle); |
| 901 | |
| 902 | // add the tracking state if it doesn't exist |
| 903 | if (gp_cis == graphicsPipelineCIs.end()) { |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame^] | 904 | auto result = graphicsPipelineCIs.emplace(pipeline_handle, GraphicsPipelineCIs{}); |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 905 | |
| 906 | if (!result.second) continue; |
| 907 | |
| 908 | gp_cis = result.first; |
| 909 | } |
| 910 | |
Tony-LunarG | 412b1b7 | 2020-07-15 10:30:13 -0600 | [diff] [blame] | 911 | gp_cis->second.colorBlendStateCI = |
| 912 | cgpl_state->pCreateInfos[i].pColorBlendState |
| 913 | ? new safe_VkPipelineColorBlendStateCreateInfo(cgpl_state->pCreateInfos[i].pColorBlendState) |
| 914 | : nullptr; |
| 915 | gp_cis->second.depthStencilStateCI = |
| 916 | cgpl_state->pCreateInfos[i].pDepthStencilState |
| 917 | ? new safe_VkPipelineDepthStencilStateCreateInfo(cgpl_state->pCreateInfos[i].pDepthStencilState) |
| 918 | : nullptr; |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 919 | } |
| 920 | } |
| 921 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 922 | bool BestPractices::PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount, |
| 923 | const VkComputePipelineCreateInfo* pCreateInfos, |
Mark Lobodzinski | 2a162a0 | 2019-09-06 11:02:12 -0600 | [diff] [blame] | 924 | const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 925 | void* ccpl_state_data) const { |
Mark Lobodzinski | 8317a3e | 2019-09-20 10:07:08 -0600 | [diff] [blame] | 926 | bool skip = StateTracker::PreCallValidateCreateComputePipelines(device, pipelineCache, createInfoCount, pCreateInfos, |
| 927 | pAllocator, pPipelines, ccpl_state_data); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 928 | |
| 929 | if ((createInfoCount > 1) && (!pipelineCache)) { |
Mark Lobodzinski | f95a266 | 2020-01-29 15:43:32 -0700 | [diff] [blame] | 930 | skip |= LogPerformanceWarning( |
| 931 | device, kVUID_BestPractices_CreatePipelines_MultiplePipelines, |
| 932 | "Performance Warning: This vkCreateComputePipelines call is creating multiple pipelines but is not using a " |
| 933 | "pipeline cache, which may help with performance"); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 934 | } |
| 935 | |
Sam Walls | d7ab6db | 2020-06-19 20:41:54 +0100 | [diff] [blame] | 936 | if (VendorCheckEnabled(kBPVendorArm)) { |
| 937 | for (size_t i = 0; i < createInfoCount; i++) { |
| 938 | skip |= ValidateCreateComputePipelineArm(pCreateInfos[i]); |
| 939 | } |
| 940 | } |
| 941 | |
| 942 | return skip; |
| 943 | } |
| 944 | |
| 945 | bool BestPractices::ValidateCreateComputePipelineArm(const VkComputePipelineCreateInfo& createInfo) const { |
| 946 | bool skip = false; |
| 947 | auto* module = GetShaderModuleState(createInfo.stage.module); |
sfricke-samsung | 8a7341a | 2021-02-28 07:30:21 -0800 | [diff] [blame] | 948 | // Generate warnings about work group sizes based on active resources. |
| 949 | auto entrypoint = FindEntrypoint(module, createInfo.stage.pName, createInfo.stage.stage); |
| 950 | if (entrypoint == module->end()) return false; |
Sam Walls | d7ab6db | 2020-06-19 20:41:54 +0100 | [diff] [blame] | 951 | |
| 952 | uint32_t x = 1, y = 1, z = 1; |
sfricke-samsung | 8a7341a | 2021-02-28 07:30:21 -0800 | [diff] [blame] | 953 | FindLocalSize(module, entrypoint, x, y, z); |
Sam Walls | d7ab6db | 2020-06-19 20:41:54 +0100 | [diff] [blame] | 954 | |
| 955 | uint32_t thread_count = x * y * z; |
| 956 | |
| 957 | // Generate a priori warnings about work group sizes. |
| 958 | if (thread_count > kMaxEfficientWorkGroupThreadCountArm) { |
| 959 | skip |= LogPerformanceWarning( |
| 960 | device, kVUID_BestPractices_CreateComputePipelines_ComputeWorkGroupSize, |
| 961 | "%s vkCreateComputePipelines(): compute shader with work group dimensions (%u, %u, " |
| 962 | "%u) (%u threads total), has more threads than advised in a single work group. It is advised to use work " |
| 963 | "groups with less than %u threads, especially when using barrier() or shared memory.", |
| 964 | VendorSpecificTag(kBPVendorArm), x, y, z, thread_count, kMaxEfficientWorkGroupThreadCountArm); |
| 965 | } |
| 966 | |
| 967 | if (thread_count == 1 || ((x > 1) && (x & (kThreadGroupDispatchCountAlignmentArm - 1))) || |
| 968 | ((y > 1) && (y & (kThreadGroupDispatchCountAlignmentArm - 1))) || |
| 969 | ((z > 1) && (z & (kThreadGroupDispatchCountAlignmentArm - 1)))) { |
| 970 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_CreateComputePipelines_ComputeThreadGroupAlignment, |
| 971 | "%s vkCreateComputePipelines(): compute shader with work group dimensions (%u, " |
| 972 | "%u, %u) is not aligned to %u " |
| 973 | "threads. On Arm Mali architectures, not aligning work group sizes to %u may " |
| 974 | "leave threads idle on the shader " |
| 975 | "core.", |
| 976 | VendorSpecificTag(kBPVendorArm), x, y, z, kThreadGroupDispatchCountAlignmentArm, |
| 977 | kThreadGroupDispatchCountAlignmentArm); |
| 978 | } |
| 979 | |
Sam Walls | d7ab6db | 2020-06-19 20:41:54 +0100 | [diff] [blame] | 980 | bool has_writeable_descriptors = false; |
locke-lunarg | 63e4daf | 2020-08-17 17:53:25 -0600 | [diff] [blame] | 981 | bool has_atomic_descriptors = false; |
Sam Walls | d7ab6db | 2020-06-19 20:41:54 +0100 | [diff] [blame] | 982 | auto accessible_ids = MarkAccessibleIds(module, entrypoint); |
locke-lunarg | 63e4daf | 2020-08-17 17:53:25 -0600 | [diff] [blame] | 983 | auto descriptor_uses = |
| 984 | CollectInterfaceByDescriptorSlot(module, accessible_ids, &has_writeable_descriptors, &has_atomic_descriptors); |
Sam Walls | d7ab6db | 2020-06-19 20:41:54 +0100 | [diff] [blame] | 985 | |
| 986 | unsigned dimensions = 0; |
| 987 | if (x > 1) dimensions++; |
| 988 | if (y > 1) dimensions++; |
| 989 | if (z > 1) dimensions++; |
| 990 | // Here the dimension will really depend on the dispatch grid, but assume it's 1D. |
| 991 | dimensions = std::max(dimensions, 1u); |
| 992 | |
| 993 | // If we're accessing images, we almost certainly want to have a 2D workgroup for cache reasons. |
| 994 | // There are some false positives here. We could simply have a shader that does this within a 1D grid, |
| 995 | // or we may have a linearly tiled image, but these cases are quite unlikely in practice. |
| 996 | bool accesses_2d = false; |
| 997 | for (const auto& usage : descriptor_uses) { |
| 998 | auto dim = GetShaderResourceDimensionality(module, usage.second); |
| 999 | if (dim < 0) continue; |
| 1000 | auto spvdim = spv::Dim(dim); |
| 1001 | if (spvdim != spv::Dim1D && spvdim != spv::DimBuffer) accesses_2d = true; |
| 1002 | } |
| 1003 | |
| 1004 | if (accesses_2d && dimensions < 2) { |
| 1005 | LogPerformanceWarning(device, kVUID_BestPractices_CreateComputePipelines_ComputeSpatialLocality, |
| 1006 | "%s vkCreateComputePipelines(): compute shader has work group dimensions (%u, %u, %u), which " |
| 1007 | "suggests a 1D dispatch, but the shader is accessing 2D or 3D images. The shader may be " |
| 1008 | "exhibiting poor spatial locality with respect to one or more shader resources.", |
| 1009 | VendorSpecificTag(kBPVendorArm), x, y, z); |
| 1010 | } |
| 1011 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1012 | return skip; |
| 1013 | } |
| 1014 | |
Jeremy Gebben | a3705f4 | 2021-01-19 16:47:43 -0700 | [diff] [blame] | 1015 | bool BestPractices::CheckPipelineStageFlags(const std::string& api_name, VkPipelineStageFlags flags) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1016 | bool skip = false; |
| 1017 | |
| 1018 | if (flags & VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1019 | skip |= LogWarning(device, kVUID_BestPractices_PipelineStageFlags, |
| 1020 | "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] | 1021 | } else if (flags & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1022 | skip |= LogWarning(device, kVUID_BestPractices_PipelineStageFlags, |
| 1023 | "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] | 1024 | } |
| 1025 | |
| 1026 | return skip; |
| 1027 | } |
| 1028 | |
Jeremy Gebben | a3705f4 | 2021-01-19 16:47:43 -0700 | [diff] [blame] | 1029 | bool BestPractices::CheckPipelineStageFlags(const std::string& api_name, VkPipelineStageFlags2KHR flags) const { |
| 1030 | bool skip = false; |
| 1031 | |
| 1032 | if (flags & VK_PIPELINE_STAGE_2_ALL_GRAPHICS_BIT_KHR) { |
| 1033 | skip |= LogWarning(device, kVUID_BestPractices_PipelineStageFlags, |
| 1034 | "You are using VK_PIPELINE_STAGE_2_ALL_GRAPHICS_BIT_KHR when %s is called\n", api_name.c_str()); |
| 1035 | } else if (flags & VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT_KHR) { |
| 1036 | skip |= LogWarning(device, kVUID_BestPractices_PipelineStageFlags, |
| 1037 | "You are using VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT_KHR when %s is called\n", api_name.c_str()); |
| 1038 | } |
| 1039 | |
| 1040 | return skip; |
| 1041 | } |
| 1042 | |
| 1043 | bool BestPractices::CheckDependencyInfo(const std::string& api_name, const VkDependencyInfoKHR& dep_info) const { |
| 1044 | bool skip = false; |
| 1045 | auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info); |
| 1046 | |
| 1047 | skip |= CheckPipelineStageFlags(api_name, stage_masks.src); |
| 1048 | skip |= CheckPipelineStageFlags(api_name, stage_masks.dst); |
| 1049 | |
| 1050 | return skip; |
| 1051 | } |
| 1052 | |
Mark Lobodzinski | 84101d7 | 2020-04-24 09:43:48 -0600 | [diff] [blame] | 1053 | void BestPractices::ManualPostCallRecordQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo, VkResult result) { |
Mark Lobodzinski | 9b133c1 | 2020-03-10 10:42:56 -0600 | [diff] [blame] | 1054 | for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) { |
| 1055 | auto swapchains_result = pPresentInfo->pResults ? pPresentInfo->pResults[i] : result; |
| 1056 | if (swapchains_result == VK_SUBOPTIMAL_KHR) { |
| 1057 | LogPerformanceWarning( |
| 1058 | pPresentInfo->pSwapchains[i], kVUID_BestPractices_SuboptimalSwapchain, |
| 1059 | "vkQueuePresentKHR: %s :VK_SUBOPTIMAL_KHR was returned. VK_SUBOPTIMAL_KHR - Presentation will still succeed, " |
| 1060 | "subject to the window resize behavior, but the swapchain is no longer configured optimally for the surface it " |
| 1061 | "targets. Applications should query updated surface information and recreate their swapchain at the next " |
| 1062 | "convenient opportunity.", |
| 1063 | report_data->FormatHandle(pPresentInfo->pSwapchains[i]).c_str()); |
| 1064 | } |
| 1065 | } |
| 1066 | } |
| 1067 | |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1068 | bool BestPractices::PreCallValidateQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo* pSubmits, |
| 1069 | VkFence fence) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1070 | bool skip = false; |
| 1071 | |
| 1072 | for (uint32_t submit = 0; submit < submitCount; submit++) { |
| 1073 | for (uint32_t semaphore = 0; semaphore < pSubmits[submit].waitSemaphoreCount; semaphore++) { |
| 1074 | skip |= CheckPipelineStageFlags("vkQueueSubmit", pSubmits[submit].pWaitDstStageMask[semaphore]); |
| 1075 | } |
| 1076 | } |
| 1077 | |
| 1078 | return skip; |
| 1079 | } |
| 1080 | |
Jeremy Gebben | a3705f4 | 2021-01-19 16:47:43 -0700 | [diff] [blame] | 1081 | bool BestPractices::PreCallValidateQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR* pSubmits, |
| 1082 | VkFence fence) const { |
| 1083 | bool skip = false; |
| 1084 | |
| 1085 | for (uint32_t submit = 0; submit < submitCount; submit++) { |
| 1086 | for (uint32_t semaphore = 0; semaphore < pSubmits[submit].waitSemaphoreInfoCount; semaphore++) { |
| 1087 | skip |= CheckPipelineStageFlags("vkQueueSubmit2KHR", pSubmits[submit].pWaitSemaphoreInfos[semaphore].stageMask); |
| 1088 | } |
| 1089 | } |
| 1090 | |
| 1091 | return skip; |
| 1092 | } |
| 1093 | |
Attilio Provenzano | 746e43e | 2020-02-27 11:23:50 +0000 | [diff] [blame] | 1094 | bool BestPractices::PreCallValidateCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo, |
| 1095 | const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool) const { |
| 1096 | bool skip = false; |
| 1097 | |
| 1098 | if (pCreateInfo->flags & VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT) { |
| 1099 | skip |= LogPerformanceWarning( |
| 1100 | device, kVUID_BestPractices_CreateCommandPool_CommandBufferReset, |
| 1101 | "vkCreateCommandPool(): VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT is set. Consider resetting entire " |
| 1102 | "pool instead."); |
| 1103 | } |
| 1104 | |
| 1105 | return skip; |
| 1106 | } |
| 1107 | |
| 1108 | bool BestPractices::PreCallValidateBeginCommandBuffer(VkCommandBuffer commandBuffer, |
| 1109 | const VkCommandBufferBeginInfo* pBeginInfo) const { |
| 1110 | bool skip = false; |
| 1111 | |
| 1112 | if (pBeginInfo->flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT) { |
| 1113 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_BeginCommandBuffer_SimultaneousUse, |
| 1114 | "vkBeginCommandBuffer(): VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT is set."); |
| 1115 | } |
| 1116 | |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1117 | if (!(pBeginInfo->flags & VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT)) { |
| 1118 | skip |= VendorCheckEnabled(kBPVendorArm) && |
| 1119 | LogPerformanceWarning(device, kVUID_BestPractices_BeginCommandBuffer_OneTimeSubmit, |
| 1120 | "%s vkBeginCommandBuffer(): VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT is not set. " |
| 1121 | "For best performance on Mali GPUs, consider setting ONE_TIME_SUBMIT by default.", |
| 1122 | VendorSpecificTag(kBPVendorArm)); |
| 1123 | } |
| 1124 | |
Attilio Provenzano | 746e43e | 2020-02-27 11:23:50 +0000 | [diff] [blame] | 1125 | return skip; |
| 1126 | } |
| 1127 | |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1128 | bool BestPractices::PreCallValidateCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1129 | bool skip = false; |
| 1130 | |
| 1131 | skip |= CheckPipelineStageFlags("vkCmdSetEvent", stageMask); |
| 1132 | |
| 1133 | return skip; |
| 1134 | } |
| 1135 | |
Jeremy Gebben | a3705f4 | 2021-01-19 16:47:43 -0700 | [diff] [blame] | 1136 | bool BestPractices::PreCallValidateCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 1137 | const VkDependencyInfoKHR* pDependencyInfo) const { |
| 1138 | return CheckDependencyInfo("vkCmdSetEvent2KHR", *pDependencyInfo); |
| 1139 | } |
| 1140 | |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1141 | bool BestPractices::PreCallValidateCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, |
| 1142 | VkPipelineStageFlags stageMask) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1143 | bool skip = false; |
| 1144 | |
| 1145 | skip |= CheckPipelineStageFlags("vkCmdResetEvent", stageMask); |
| 1146 | |
| 1147 | return skip; |
| 1148 | } |
| 1149 | |
Jeremy Gebben | a3705f4 | 2021-01-19 16:47:43 -0700 | [diff] [blame] | 1150 | bool BestPractices::PreCallValidateCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 1151 | VkPipelineStageFlags2KHR stageMask) const { |
| 1152 | bool skip = false; |
| 1153 | |
| 1154 | skip |= CheckPipelineStageFlags("vkCmdResetEvent2KHR", stageMask); |
| 1155 | |
| 1156 | return skip; |
| 1157 | } |
| 1158 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1159 | bool BestPractices::PreCallValidateCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents, |
| 1160 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 1161 | uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers, |
| 1162 | uint32_t bufferMemoryBarrierCount, |
| 1163 | const VkBufferMemoryBarrier* pBufferMemoryBarriers, |
| 1164 | uint32_t imageMemoryBarrierCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1165 | const VkImageMemoryBarrier* pImageMemoryBarriers) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1166 | bool skip = false; |
| 1167 | |
| 1168 | skip |= CheckPipelineStageFlags("vkCmdWaitEvents", srcStageMask); |
| 1169 | skip |= CheckPipelineStageFlags("vkCmdWaitEvents", dstStageMask); |
| 1170 | |
| 1171 | return skip; |
| 1172 | } |
| 1173 | |
Jeremy Gebben | a3705f4 | 2021-01-19 16:47:43 -0700 | [diff] [blame] | 1174 | bool BestPractices::PreCallValidateCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents, |
| 1175 | const VkDependencyInfoKHR* pDependencyInfos) const { |
| 1176 | bool skip = false; |
| 1177 | for (uint32_t i = 0; i < eventCount; i++) { |
| 1178 | skip = CheckDependencyInfo("vkCmdWaitEvents2KHR", pDependencyInfos[i]); |
| 1179 | } |
| 1180 | |
| 1181 | return skip; |
| 1182 | } |
| 1183 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1184 | bool BestPractices::PreCallValidateCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, |
| 1185 | VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, |
| 1186 | uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers, |
| 1187 | uint32_t bufferMemoryBarrierCount, |
| 1188 | const VkBufferMemoryBarrier* pBufferMemoryBarriers, |
| 1189 | uint32_t imageMemoryBarrierCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1190 | const VkImageMemoryBarrier* pImageMemoryBarriers) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1191 | bool skip = false; |
| 1192 | |
| 1193 | skip |= CheckPipelineStageFlags("vkCmdPipelineBarrier", srcStageMask); |
| 1194 | skip |= CheckPipelineStageFlags("vkCmdPipelineBarrier", dstStageMask); |
| 1195 | |
| 1196 | return skip; |
| 1197 | } |
| 1198 | |
Jeremy Gebben | a3705f4 | 2021-01-19 16:47:43 -0700 | [diff] [blame] | 1199 | bool BestPractices::PreCallValidateCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer, |
| 1200 | const VkDependencyInfoKHR* pDependencyInfo) const { |
| 1201 | return CheckDependencyInfo("vkCmdPipelineBarrier2KHR", *pDependencyInfo); |
| 1202 | } |
| 1203 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1204 | bool BestPractices::PreCallValidateCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1205 | VkQueryPool queryPool, uint32_t query) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1206 | bool skip = false; |
| 1207 | |
Jeremy Gebben | a3705f4 | 2021-01-19 16:47:43 -0700 | [diff] [blame] | 1208 | skip |= CheckPipelineStageFlags("vkCmdWriteTimestamp", static_cast<VkPipelineStageFlags>(pipelineStage)); |
| 1209 | |
| 1210 | return skip; |
| 1211 | } |
| 1212 | |
| 1213 | bool BestPractices::PreCallValidateCmdWriteTimestamp2KHR(VkCommandBuffer commandBuffer, VkPipelineStageFlags2KHR pipelineStage, |
| 1214 | VkQueryPool queryPool, uint32_t query) const { |
| 1215 | bool skip = false; |
| 1216 | |
| 1217 | skip |= CheckPipelineStageFlags("vkCmdWriteTimestamp2KHR", pipelineStage); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1218 | |
| 1219 | return skip; |
| 1220 | } |
| 1221 | |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1222 | void BestPractices::PostCallRecordCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, |
| 1223 | VkPipeline pipeline) { |
| 1224 | StateTracker::PostCallRecordCmdBindPipeline(commandBuffer, pipelineBindPoint, pipeline); |
| 1225 | |
| 1226 | if (pipelineBindPoint == VK_PIPELINE_BIND_POINT_GRAPHICS) { |
| 1227 | // check for depth/blend state tracking |
| 1228 | auto gp_cis = graphicsPipelineCIs.find(pipeline); |
| 1229 | if (gp_cis != graphicsPipelineCIs.end()) { |
| 1230 | auto prepass_state = cbDepthPrePassStates.find(commandBuffer); |
| 1231 | if (prepass_state == cbDepthPrePassStates.end()) { |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame^] | 1232 | auto result = cbDepthPrePassStates.emplace(commandBuffer, DepthPrePassState{}); |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1233 | |
| 1234 | if (!result.second) return; |
| 1235 | |
| 1236 | prepass_state = result.first; |
| 1237 | } |
| 1238 | |
| 1239 | const auto* blend_state = gp_cis->second.colorBlendStateCI; |
| 1240 | const auto* stencil_state = gp_cis->second.depthStencilStateCI; |
| 1241 | |
| 1242 | if (blend_state) { |
| 1243 | // assume the pipeline is depth-only unless any of the attachments have color writes enabled |
| 1244 | prepass_state->second.depthOnly = true; |
| 1245 | for (size_t i = 0; i < blend_state->attachmentCount; i++) { |
| 1246 | if (blend_state->pAttachments[i].colorWriteMask != 0) { |
| 1247 | prepass_state->second.depthOnly = false; |
| 1248 | } |
| 1249 | } |
| 1250 | } |
| 1251 | |
| 1252 | // check for depth value usage |
| 1253 | prepass_state->second.depthEqualComparison = false; |
| 1254 | |
| 1255 | if (stencil_state && stencil_state->depthTestEnable) { |
| 1256 | switch (stencil_state->depthCompareOp) { |
| 1257 | case VK_COMPARE_OP_EQUAL: |
| 1258 | case VK_COMPARE_OP_GREATER_OR_EQUAL: |
| 1259 | case VK_COMPARE_OP_LESS_OR_EQUAL: |
| 1260 | prepass_state->second.depthEqualComparison = true; |
| 1261 | break; |
| 1262 | default: |
| 1263 | break; |
| 1264 | } |
| 1265 | } |
| 1266 | } else { |
| 1267 | // reset depth pre-pass tracking |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame^] | 1268 | cbDepthPrePassStates.emplace(commandBuffer, DepthPrePassState{}); |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1269 | } |
| 1270 | } |
| 1271 | } |
| 1272 | |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1273 | static inline bool RenderPassUsesAttachmentOnTile(const safe_VkRenderPassCreateInfo2& createInfo, uint32_t attachment) { |
| 1274 | for (uint32_t subpass = 0; subpass < createInfo.subpassCount; subpass++) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1275 | auto& subpass_info = createInfo.pSubpasses[subpass]; |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1276 | |
| 1277 | // If an attachment is ever used as a color attachment, |
| 1278 | // resolve attachment or depth stencil attachment, |
| 1279 | // it needs to exist on tile at some point. |
| 1280 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1281 | for (uint32_t i = 0; i < subpass_info.colorAttachmentCount; i++) { |
| 1282 | if (subpass_info.pColorAttachments[i].attachment == attachment) return true; |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1283 | } |
| 1284 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1285 | if (subpass_info.pResolveAttachments) { |
| 1286 | for (uint32_t i = 0; i < subpass_info.colorAttachmentCount; i++) { |
| 1287 | if (subpass_info.pResolveAttachments[i].attachment == attachment) return true; |
| 1288 | } |
| 1289 | } |
| 1290 | |
| 1291 | if (subpass_info.pDepthStencilAttachment && subpass_info.pDepthStencilAttachment->attachment == attachment) return true; |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1292 | } |
| 1293 | |
| 1294 | return false; |
| 1295 | } |
| 1296 | |
| 1297 | bool BestPractices::ValidateCmdBeginRenderPass(VkCommandBuffer commandBuffer, RenderPassCreateVersion rp_version, |
| 1298 | const VkRenderPassBeginInfo* pRenderPassBegin) const { |
| 1299 | bool skip = false; |
| 1300 | |
| 1301 | if (!pRenderPassBegin) { |
| 1302 | return skip; |
| 1303 | } |
| 1304 | |
| 1305 | auto rp_state = GetRenderPassState(pRenderPassBegin->renderPass); |
| 1306 | if (rp_state) { |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1307 | if (rp_state->createInfo.flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) { |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1308 | const VkRenderPassAttachmentBeginInfo* rpabi = LvlFindInChain<VkRenderPassAttachmentBeginInfo>(pRenderPassBegin->pNext); |
Tony-LunarG | 767180f | 2020-04-23 14:03:59 -0600 | [diff] [blame] | 1309 | if (rpabi) { |
| 1310 | skip = ValidateAttachments(rp_state->createInfo.ptr(), rpabi->attachmentCount, rpabi->pAttachments); |
| 1311 | } |
| 1312 | } |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1313 | // Check if any attachments have LOAD operation on them |
| 1314 | for (uint32_t att = 0; att < rp_state->createInfo.attachmentCount; att++) { |
| 1315 | auto& attachment = rp_state->createInfo.pAttachments[att]; |
| 1316 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1317 | bool attachment_has_readback = false; |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1318 | if (!FormatHasStencil(attachment.format) && attachment.loadOp == VK_ATTACHMENT_LOAD_OP_LOAD) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1319 | attachment_has_readback = true; |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1320 | } |
| 1321 | |
| 1322 | if (FormatHasStencil(attachment.format) && attachment.stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1323 | attachment_has_readback = 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 | bool attachment_needs_readback = false; |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1327 | |
| 1328 | // Check if the attachment is actually used in any subpass on-tile |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1329 | if (attachment_has_readback && RenderPassUsesAttachmentOnTile(rp_state->createInfo, att)) { |
| 1330 | attachment_needs_readback = true; |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1331 | } |
| 1332 | |
| 1333 | // Using LOAD_OP_LOAD is expensive on tiled GPUs, so flag it as a potential improvement |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1334 | if (attachment_needs_readback) { |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1335 | skip |= VendorCheckEnabled(kBPVendorArm) && |
| 1336 | LogPerformanceWarning( |
| 1337 | device, kVUID_BestPractices_BeginRenderPass_AttachmentNeedsReadback, |
| 1338 | "%s Attachment #%u in render pass has begun with VK_ATTACHMENT_LOAD_OP_LOAD.\n" |
| 1339 | "Submitting this renderpass will cause the driver to inject a readback of the attachment " |
| 1340 | "which will copy in total %u pixels (renderArea = { %d, %d, %u, %u }) to the tile buffer.", |
| 1341 | VendorSpecificTag(kBPVendorArm), att, |
| 1342 | pRenderPassBegin->renderArea.extent.width * pRenderPassBegin->renderArea.extent.height, |
| 1343 | pRenderPassBegin->renderArea.offset.x, pRenderPassBegin->renderArea.offset.y, |
| 1344 | pRenderPassBegin->renderArea.extent.width, pRenderPassBegin->renderArea.extent.height); |
| 1345 | } |
| 1346 | } |
| 1347 | } |
| 1348 | |
| 1349 | return skip; |
| 1350 | } |
| 1351 | |
| 1352 | bool BestPractices::PreCallValidateCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, |
| 1353 | VkSubpassContents contents) const { |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1354 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents); |
| 1355 | skip |= ValidateCmdBeginRenderPass(commandBuffer, RENDER_PASS_VERSION_1, pRenderPassBegin); |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1356 | return skip; |
| 1357 | } |
| 1358 | |
| 1359 | bool BestPractices::PreCallValidateCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 1360 | const VkRenderPassBeginInfo* pRenderPassBegin, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1361 | const VkSubpassBeginInfo* pSubpassBeginInfo) const { |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1362 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass2KHR(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
| 1363 | skip |= ValidateCmdBeginRenderPass(commandBuffer, RENDER_PASS_VERSION_2, pRenderPassBegin); |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1364 | return skip; |
| 1365 | } |
| 1366 | |
| 1367 | bool BestPractices::PreCallValidateCmdBeginRenderPass2(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1368 | const VkSubpassBeginInfo* pSubpassBeginInfo) const { |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1369 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass2(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
| 1370 | skip |= ValidateCmdBeginRenderPass(commandBuffer, RENDER_PASS_VERSION_2, pRenderPassBegin); |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1371 | return skip; |
| 1372 | } |
| 1373 | |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1374 | void BestPractices::RecordCmdBeginRenderPass(VkCommandBuffer commandBuffer, RenderPassCreateVersion rp_version, |
| 1375 | const VkRenderPassBeginInfo* pRenderPassBegin) { |
| 1376 | auto prepass_state = cbDepthPrePassStates.find(commandBuffer); |
| 1377 | |
| 1378 | // add the tracking state if it doesn't exist |
| 1379 | if (prepass_state == cbDepthPrePassStates.end()) { |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame^] | 1380 | auto result = cbDepthPrePassStates.emplace(commandBuffer, DepthPrePassState{}); |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1381 | |
| 1382 | if (!result.second) return; |
| 1383 | |
| 1384 | prepass_state = result.first; |
| 1385 | } |
| 1386 | |
| 1387 | // reset the renderpass state |
| 1388 | prepass_state->second = {}; |
| 1389 | |
| 1390 | const auto* cb_state = GetCBState(commandBuffer); |
locke-lunarg | aecf215 | 2020-05-12 17:15:41 -0600 | [diff] [blame] | 1391 | const auto* rp_state = cb_state->activeRenderPass.get(); |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1392 | |
| 1393 | // track depth / color attachment usage within the renderpass |
| 1394 | for (size_t i = 0; i < rp_state->createInfo.subpassCount; i++) { |
| 1395 | // record if depth/color attachments are in use for this renderpass |
| 1396 | if (rp_state->createInfo.pSubpasses[i].pDepthStencilAttachment != nullptr) prepass_state->second.depthAttachment = true; |
| 1397 | |
| 1398 | if (rp_state->createInfo.pSubpasses[i].colorAttachmentCount > 0) prepass_state->second.colorAttachment = true; |
| 1399 | } |
| 1400 | } |
| 1401 | |
| 1402 | void BestPractices::PostCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, |
| 1403 | VkSubpassContents contents) { |
| 1404 | StateTracker::PostCallRecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents); |
| 1405 | RecordCmdBeginRenderPass(commandBuffer, RENDER_PASS_VERSION_1, pRenderPassBegin); |
| 1406 | } |
| 1407 | |
| 1408 | void BestPractices::PostCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, |
| 1409 | const VkSubpassBeginInfo* pSubpassBeginInfo) { |
| 1410 | StateTracker::PostCallRecordCmdBeginRenderPass2(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
| 1411 | RecordCmdBeginRenderPass(commandBuffer, RENDER_PASS_VERSION_2, pRenderPassBegin); |
| 1412 | } |
| 1413 | |
| 1414 | void BestPractices::PostCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 1415 | const VkRenderPassBeginInfo* pRenderPassBegin, |
| 1416 | const VkSubpassBeginInfo* pSubpassBeginInfo) { |
| 1417 | StateTracker::PostCallRecordCmdBeginRenderPass2KHR(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
| 1418 | RecordCmdBeginRenderPass(commandBuffer, RENDER_PASS_VERSION_2, pRenderPassBegin); |
| 1419 | } |
| 1420 | |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 1421 | // Generic function to handle validation for all CmdDraw* type functions |
| 1422 | bool BestPractices::ValidateCmdDrawType(VkCommandBuffer cmd_buffer, const char* caller) const { |
| 1423 | bool skip = false; |
| 1424 | const CMD_BUFFER_STATE* cb_state = GetCBState(cmd_buffer); |
| 1425 | if (cb_state) { |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 1426 | const auto lv_bind_point = ConvertToLvlBindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 1427 | const auto* pipeline_state = cb_state->lastBound[lv_bind_point].pipeline_state; |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 1428 | 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] | 1429 | |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 1430 | // Verify vertex binding |
| 1431 | if (pipeline_state->vertex_binding_descriptions_.size() <= 0) { |
| 1432 | if ((!current_vtx_bfr_binding_info.empty()) && (!cb_state->vertex_buffer_used)) { |
Mark Lobodzinski | f95a266 | 2020-01-29 15:43:32 -0700 | [diff] [blame] | 1433 | skip |= LogPerformanceWarning(cb_state->commandBuffer, kVUID_BestPractices_DrawState_VtxIndexOutOfBounds, |
| 1434 | "Vertex buffers are bound to %s but no vertex buffers are attached to %s.", |
| 1435 | report_data->FormatHandle(cb_state->commandBuffer).c_str(), |
| 1436 | report_data->FormatHandle(pipeline_state->pipeline).c_str()); |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 1437 | } |
| 1438 | } |
| 1439 | } |
| 1440 | return skip; |
| 1441 | } |
| 1442 | |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1443 | void BestPractices::RecordCmdDrawType(VkCommandBuffer cmd_buffer, uint32_t draw_count, const char* caller) { |
| 1444 | if (VendorCheckEnabled(kBPVendorArm)) { |
| 1445 | RecordCmdDrawTypeArm(cmd_buffer, draw_count, caller); |
| 1446 | } |
| 1447 | } |
| 1448 | |
| 1449 | void BestPractices::RecordCmdDrawTypeArm(VkCommandBuffer cmd_buffer, uint32_t draw_count, const char* caller) { |
| 1450 | auto prepass_state = cbDepthPrePassStates.find(cmd_buffer); |
| 1451 | if (prepass_state != cbDepthPrePassStates.end() && draw_count >= kDepthPrePassMinDrawCountArm) { |
| 1452 | if (prepass_state->second.depthOnly) prepass_state->second.numDrawCallsDepthOnly++; |
| 1453 | |
| 1454 | if (prepass_state->second.depthEqualComparison) prepass_state->second.numDrawCallsDepthEqualCompare++; |
| 1455 | } |
| 1456 | } |
| 1457 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1458 | bool BestPractices::PreCallValidateCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1459 | uint32_t firstVertex, uint32_t firstInstance) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1460 | bool skip = false; |
| 1461 | |
| 1462 | if (instanceCount == 0) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1463 | skip |= LogWarning(device, kVUID_BestPractices_CmdDraw_InstanceCountZero, |
| 1464 | "Warning: You are calling vkCmdDraw() with an instanceCount of Zero."); |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 1465 | skip |= ValidateCmdDrawType(commandBuffer, "vkCmdDraw()"); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1466 | } |
| 1467 | |
| 1468 | return skip; |
| 1469 | } |
| 1470 | |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1471 | void BestPractices::PostCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
| 1472 | uint32_t firstVertex, uint32_t firstInstance) { |
| 1473 | StateTracker::PostCallRecordCmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance); |
| 1474 | RecordCmdDrawType(commandBuffer, vertexCount * instanceCount, "vkCmdDraw()"); |
| 1475 | } |
| 1476 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1477 | bool BestPractices::PreCallValidateCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1478 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1479 | bool skip = false; |
| 1480 | |
| 1481 | if (instanceCount == 0) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1482 | skip |= LogWarning(device, kVUID_BestPractices_CmdDraw_InstanceCountZero, |
| 1483 | "Warning: You are calling vkCmdDrawIndexed() with an instanceCount of Zero."); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1484 | } |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 1485 | skip |= ValidateCmdDrawType(commandBuffer, "vkCmdDrawIndexed()"); |
| 1486 | |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1487 | // Check if we reached the limit for small indexed draw calls. |
| 1488 | // Note that we cannot update the draw call count here, so we do it in PreCallRecordCmdDrawIndexed. |
| 1489 | const CMD_BUFFER_STATE* cmd_state = GetCBState(commandBuffer); |
| 1490 | if ((indexCount * instanceCount) <= kSmallIndexedDrawcallIndices && |
| 1491 | (cmd_state->small_indexed_draw_call_count == kMaxSmallIndexedDrawcalls - 1)) { |
| 1492 | skip |= VendorCheckEnabled(kBPVendorArm) && |
| 1493 | LogPerformanceWarning(device, kVUID_BestPractices_CmdDrawIndexed_ManySmallIndexedDrawcalls, |
| 1494 | "The command buffer contains many small indexed drawcalls " |
| 1495 | "(at least %u drawcalls with less than %u indices each). This may cause pipeline bubbles. " |
| 1496 | "You can try batching drawcalls or instancing when applicable.", |
| 1497 | VendorSpecificTag(kBPVendorArm), kMaxSmallIndexedDrawcalls, kSmallIndexedDrawcallIndices); |
| 1498 | } |
| 1499 | |
Sam Walls | 8e77e4f | 2020-03-16 20:47:40 +0000 | [diff] [blame] | 1500 | if (VendorCheckEnabled(kBPVendorArm)) { |
| 1501 | ValidateIndexBufferArm(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); |
| 1502 | } |
| 1503 | |
| 1504 | return skip; |
| 1505 | } |
| 1506 | |
| 1507 | bool BestPractices::ValidateIndexBufferArm(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
| 1508 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) const { |
| 1509 | bool skip = false; |
| 1510 | |
| 1511 | // check for sparse/underutilised index buffer, and post-transform cache thrashing |
| 1512 | const auto* cmd_state = GetCBState(commandBuffer); |
| 1513 | if (cmd_state == nullptr) return skip; |
| 1514 | |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 1515 | const auto* ib_state = cmd_state->index_buffer_binding.buffer_state.get(); |
| 1516 | 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] | 1517 | |
| 1518 | const VkIndexType ib_type = cmd_state->index_buffer_binding.index_type; |
| 1519 | const auto& ib_mem_state = *ib_state->binding.mem_state; |
| 1520 | const VkDeviceSize ib_mem_offset = ib_mem_state.mapped_range.offset; |
| 1521 | const void* ib_mem = ib_mem_state.p_driver_data; |
| 1522 | bool primitive_restart_enable = false; |
| 1523 | |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 1524 | const auto lv_bind_point = ConvertToLvlBindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 1525 | const auto& pipeline_binding_iter = cmd_state->lastBound[lv_bind_point]; |
| 1526 | const auto* pipeline_state = pipeline_binding_iter.pipeline_state; |
Sam Walls | 8e77e4f | 2020-03-16 20:47:40 +0000 | [diff] [blame] | 1527 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1528 | if (pipeline_state != nullptr && pipeline_state->graphicsPipelineCI.pInputAssemblyState != nullptr) { |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 1529 | primitive_restart_enable = pipeline_state->graphicsPipelineCI.pInputAssemblyState->primitiveRestartEnable == VK_TRUE; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1530 | } |
Sam Walls | 8e77e4f | 2020-03-16 20:47:40 +0000 | [diff] [blame] | 1531 | |
| 1532 | // 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] | 1533 | if (ib_mem && pipeline_binding_iter.IsUsing()) { |
Sam Walls | 8e77e4f | 2020-03-16 20:47:40 +0000 | [diff] [blame] | 1534 | uint32_t scan_stride; |
| 1535 | if (ib_type == VK_INDEX_TYPE_UINT8_EXT) { |
| 1536 | scan_stride = sizeof(uint8_t); |
| 1537 | } else if (ib_type == VK_INDEX_TYPE_UINT16) { |
| 1538 | scan_stride = sizeof(uint16_t); |
| 1539 | } else { |
| 1540 | scan_stride = sizeof(uint32_t); |
| 1541 | } |
| 1542 | |
| 1543 | const uint8_t* scan_begin = static_cast<const uint8_t*>(ib_mem) + ib_mem_offset + firstIndex * scan_stride; |
| 1544 | const uint8_t* scan_end = scan_begin + indexCount * scan_stride; |
| 1545 | |
| 1546 | // Min and max are important to track for some Mali architectures. In older Mali devices without IDVS, all |
| 1547 | // vertices corresponding to indices between the minimum and maximum may be loaded, and possibly shaded, |
| 1548 | // irrespective of whether or not they're part of the draw call. |
| 1549 | |
| 1550 | // start with minimum as 0xFFFFFFFF and adjust to indices in the buffer |
| 1551 | uint32_t min_index = ~0u; |
| 1552 | // start with maximum as 0 and adjust to indices in the buffer |
| 1553 | uint32_t max_index = 0u; |
| 1554 | |
| 1555 | // first scan-through, we're looking to simulate a model LRU post-transform cache, estimating the number of vertices shaded |
| 1556 | // for the given index buffer |
| 1557 | uint32_t vertex_shade_count = 0; |
| 1558 | |
| 1559 | PostTransformLRUCacheModel post_transform_cache; |
| 1560 | |
| 1561 | // The size of the cache being modelled positively correlates with how much behaviour it can capture about |
| 1562 | // arbitrary ground-truth hardware/architecture cache behaviour. I.e. it's a good solution when we don't know the |
| 1563 | // target architecture. |
| 1564 | // However, modelling a post-transform cache with more than 32 elements gives diminishing returns in practice. |
| 1565 | // http://eelpi.gotdns.org/papers/fast_vert_cache_opt.html |
| 1566 | post_transform_cache.resize(32); |
| 1567 | |
| 1568 | for (const uint8_t* scan_ptr = scan_begin; scan_ptr < scan_end; scan_ptr += scan_stride) { |
| 1569 | uint32_t scan_index; |
| 1570 | uint32_t primitive_restart_value; |
| 1571 | if (ib_type == VK_INDEX_TYPE_UINT8_EXT) { |
| 1572 | scan_index = *reinterpret_cast<const uint8_t*>(scan_ptr); |
| 1573 | primitive_restart_value = 0xFF; |
| 1574 | } else if (ib_type == VK_INDEX_TYPE_UINT16) { |
| 1575 | scan_index = *reinterpret_cast<const uint16_t*>(scan_ptr); |
| 1576 | primitive_restart_value = 0xFFFF; |
| 1577 | } else { |
| 1578 | scan_index = *reinterpret_cast<const uint32_t*>(scan_ptr); |
| 1579 | primitive_restart_value = 0xFFFFFFFF; |
| 1580 | } |
| 1581 | |
| 1582 | max_index = std::max(max_index, scan_index); |
| 1583 | min_index = std::min(min_index, scan_index); |
| 1584 | |
| 1585 | if (!primitive_restart_enable || scan_index != primitive_restart_value) { |
| 1586 | bool in_cache = post_transform_cache.query_cache(scan_index); |
| 1587 | // if the shaded vertex corresponding to the index is not in the PT-cache, we need to shade again |
| 1588 | if (!in_cache) vertex_shade_count++; |
| 1589 | } |
| 1590 | } |
| 1591 | |
| 1592 | // 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] | 1593 | // 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 |
| 1594 | if (max_index < min_index || max_index == min_index) return skip; |
Sam Walls | 8e77e4f | 2020-03-16 20:47:40 +0000 | [diff] [blame] | 1595 | |
| 1596 | if (max_index - min_index >= indexCount) { |
Mark Young | 0ec6b06 | 2020-11-19 15:32:17 -0700 | [diff] [blame] | 1597 | skip |= |
| 1598 | LogPerformanceWarning(device, kVUID_BestPractices_CmdDrawIndexed_SparseIndexBuffer, |
| 1599 | "%s The indices which were specified for the draw call only utilise approximately %.02f%% of " |
| 1600 | "index buffer value range. Arm Mali architectures before G71 do not have IDVS (Index-Driven " |
| 1601 | "Vertex Shading), meaning all vertices corresponding to indices between the minimum and " |
| 1602 | "maximum would be loaded, and possibly shaded, whether or not they are used.", |
| 1603 | VendorSpecificTag(kBPVendorArm), |
| 1604 | (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] | 1605 | return skip; |
| 1606 | } |
| 1607 | |
| 1608 | // use a dynamic vector of bitsets as a memory-compact representation of which indices are included in the draw call |
| 1609 | // 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] | 1610 | const size_t refs_per_bucket = 64; |
| 1611 | std::vector<std::bitset<refs_per_bucket>> vertex_reference_buckets; |
| 1612 | |
| 1613 | const uint32_t n_indices = max_index - min_index + 1; |
| 1614 | const uint32_t n_buckets = (n_indices / static_cast<uint32_t>(refs_per_bucket)) + |
| 1615 | ((n_indices % static_cast<uint32_t>(refs_per_bucket)) != 0 ? 1 : 0); |
| 1616 | |
| 1617 | // there needs to be at least one bitset to store a set of indices smaller than n_buckets |
| 1618 | vertex_reference_buckets.resize(std::max(1u, n_buckets)); |
Sam Walls | 8e77e4f | 2020-03-16 20:47:40 +0000 | [diff] [blame] | 1619 | |
| 1620 | // To avoid using too much memory, we run over the indices again. |
| 1621 | // Knowing the size from the last scan allows us to record index usage with bitsets |
| 1622 | for (const uint8_t* scan_ptr = scan_begin; scan_ptr < scan_end; scan_ptr += scan_stride) { |
| 1623 | uint32_t scan_index; |
| 1624 | if (ib_type == VK_INDEX_TYPE_UINT8_EXT) { |
| 1625 | scan_index = *reinterpret_cast<const uint8_t*>(scan_ptr); |
| 1626 | } else if (ib_type == VK_INDEX_TYPE_UINT16) { |
| 1627 | scan_index = *reinterpret_cast<const uint16_t*>(scan_ptr); |
| 1628 | } else { |
| 1629 | scan_index = *reinterpret_cast<const uint32_t*>(scan_ptr); |
| 1630 | } |
| 1631 | // keep track of the set of all indices used to reference vertices in the draw call |
| 1632 | size_t index_offset = scan_index - min_index; |
Sam Walls | 61b0689 | 2020-07-23 16:20:50 +0100 | [diff] [blame] | 1633 | size_t bitset_bucket_index = index_offset / refs_per_bucket; |
| 1634 | uint64_t used_indices = 1ull << ((index_offset % refs_per_bucket) & 0xFFFFFFFFu); |
Sam Walls | 8e77e4f | 2020-03-16 20:47:40 +0000 | [diff] [blame] | 1635 | vertex_reference_buckets[bitset_bucket_index] |= used_indices; |
| 1636 | } |
| 1637 | |
| 1638 | uint32_t vertex_reference_count = 0; |
| 1639 | for (const auto& bitset : vertex_reference_buckets) { |
| 1640 | vertex_reference_count += static_cast<uint32_t>(bitset.count()); |
| 1641 | } |
| 1642 | |
| 1643 | // 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] | 1644 | 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] | 1645 | // 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] | 1646 | 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] | 1647 | |
| 1648 | if (utilization < 0.5f) { |
| 1649 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_CmdDrawIndexed_SparseIndexBuffer, |
| 1650 | "%s The indices which were specified for the draw call only utilise approximately " |
| 1651 | "%.02f%% of the bound vertex buffer.", |
| 1652 | VendorSpecificTag(kBPVendorArm), utilization); |
| 1653 | } |
| 1654 | |
| 1655 | if (cache_hit_rate <= 0.5f) { |
| 1656 | skip |= |
| 1657 | LogPerformanceWarning(device, kVUID_BestPractices_CmdDrawIndexed_PostTransformCacheThrashing, |
| 1658 | "%s The indices which were specified for the draw call are estimated to cause thrashing of " |
| 1659 | "the post-transform vertex cache, with a hit-rate of %.02f%%. " |
| 1660 | "I.e. the ordering of the index buffer may not make optimal use of indices associated with " |
| 1661 | "recently shaded vertices.", |
| 1662 | VendorSpecificTag(kBPVendorArm), cache_hit_rate * 100.0f); |
| 1663 | } |
| 1664 | } |
| 1665 | |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 1666 | return skip; |
| 1667 | } |
| 1668 | |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1669 | void BestPractices::PreCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
| 1670 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) { |
| 1671 | ValidationStateTracker::PreCallRecordCmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, |
| 1672 | firstInstance); |
| 1673 | |
| 1674 | CMD_BUFFER_STATE* cmd_state = GetCBState(commandBuffer); |
| 1675 | if ((indexCount * instanceCount) <= kSmallIndexedDrawcallIndices) { |
| 1676 | cmd_state->small_indexed_draw_call_count++; |
| 1677 | } |
| 1678 | } |
| 1679 | |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1680 | void BestPractices::PostCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
| 1681 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) { |
| 1682 | StateTracker::PostCallRecordCmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); |
| 1683 | RecordCmdDrawType(commandBuffer, indexCount * instanceCount, "vkCmdDrawIndexed()"); |
| 1684 | } |
| 1685 | |
sfricke-samsung | 681ab7b | 2020-10-29 01:53:35 -0700 | [diff] [blame] | 1686 | bool BestPractices::PreCallValidateCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 1687 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 1688 | uint32_t maxDrawCount, uint32_t stride) const { |
| 1689 | bool skip = ValidateCmdDrawType(commandBuffer, "vkCmdDrawIndexedIndirectCount()"); |
| 1690 | |
| 1691 | return skip; |
| 1692 | } |
| 1693 | |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 1694 | bool BestPractices::PreCallValidateCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 1695 | VkDeviceSize offset, VkBuffer countBuffer, |
| 1696 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 1697 | uint32_t stride) const { |
| 1698 | bool skip = ValidateCmdDrawType(commandBuffer, "vkCmdDrawIndexedIndirectCountKHR()"); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1699 | |
| 1700 | return skip; |
| 1701 | } |
| 1702 | |
| 1703 | bool BestPractices::PreCallValidateCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1704 | uint32_t drawCount, uint32_t stride) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1705 | bool skip = false; |
| 1706 | |
| 1707 | if (drawCount == 0) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1708 | skip |= LogWarning(device, kVUID_BestPractices_CmdDraw_DrawCountZero, |
| 1709 | "Warning: You are calling vkCmdDrawIndirect() with a drawCount of Zero."); |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 1710 | skip |= ValidateCmdDrawType(commandBuffer, "vkCmdDrawIndirect()"); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1711 | } |
| 1712 | |
| 1713 | return skip; |
| 1714 | } |
| 1715 | |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1716 | void BestPractices::PostCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 1717 | uint32_t count, uint32_t stride) { |
| 1718 | StateTracker::PostCallRecordCmdDrawIndirect(commandBuffer, buffer, offset, count, stride); |
| 1719 | RecordCmdDrawType(commandBuffer, count, "vkCmdDrawIndirect()"); |
| 1720 | } |
| 1721 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1722 | bool BestPractices::PreCallValidateCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1723 | uint32_t drawCount, uint32_t stride) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1724 | bool skip = false; |
| 1725 | |
| 1726 | if (drawCount == 0) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1727 | skip |= LogWarning(device, kVUID_BestPractices_CmdDraw_DrawCountZero, |
| 1728 | "Warning: You are calling vkCmdDrawIndexedIndirect() with a drawCount of Zero."); |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 1729 | skip |= ValidateCmdDrawType(commandBuffer, "vkCmdDrawIndexedIndirect()"); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1730 | } |
| 1731 | |
| 1732 | return skip; |
| 1733 | } |
| 1734 | |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1735 | void BestPractices::PostCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 1736 | uint32_t count, uint32_t stride) { |
| 1737 | StateTracker::PostCallRecordCmdDrawIndexedIndirect(commandBuffer, buffer, offset, count, stride); |
| 1738 | RecordCmdDrawType(commandBuffer, count, "vkCmdDrawIndexedIndirect()"); |
| 1739 | } |
| 1740 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1741 | bool BestPractices::PreCallValidateCmdDispatch(VkCommandBuffer commandBuffer, uint32_t groupCountX, uint32_t groupCountY, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1742 | uint32_t groupCountZ) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1743 | bool skip = false; |
| 1744 | |
| 1745 | if ((groupCountX == 0) || (groupCountY == 0) || (groupCountZ == 0)) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1746 | skip |= LogWarning(device, kVUID_BestPractices_CmdDispatch_GroupCountZero, |
| 1747 | "Warning: You are calling vkCmdDispatch() while one or more groupCounts are zero (groupCountX = %" PRIu32 |
| 1748 | ", groupCountY = %" PRIu32 ", groupCountZ = %" PRIu32 ").", |
| 1749 | groupCountX, groupCountY, groupCountZ); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | return skip; |
| 1753 | } |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 1754 | |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1755 | bool BestPractices::PreCallValidateCmdEndRenderPass(VkCommandBuffer commandBuffer) const { |
| 1756 | bool skip = false; |
| 1757 | |
| 1758 | skip |= StateTracker::PreCallValidateCmdEndRenderPass(commandBuffer); |
| 1759 | |
| 1760 | auto prepass_state = cbDepthPrePassStates.find(commandBuffer); |
| 1761 | |
| 1762 | if (prepass_state == cbDepthPrePassStates.end()) return skip; |
| 1763 | |
| 1764 | bool uses_depth = (prepass_state->second.depthAttachment || prepass_state->second.colorAttachment) && |
| 1765 | prepass_state->second.numDrawCallsDepthEqualCompare >= kDepthPrePassNumDrawCallsArm && |
| 1766 | prepass_state->second.numDrawCallsDepthOnly >= kDepthPrePassNumDrawCallsArm; |
| 1767 | if (uses_depth) { |
| 1768 | skip |= LogPerformanceWarning( |
| 1769 | device, kVUID_BestPractices_EndRenderPass_DepthPrePassUsage, |
| 1770 | "%s Depth pre-passes may be in use. In general, this is not recommended, as in Arm Mali GPUs since " |
| 1771 | "Mali-T620, Forward Pixel Killing (FPK) can already perform automatic hidden surface removal; in which " |
| 1772 | "case, using depth pre-passes for hidden surface removal may worsen performance.", |
| 1773 | VendorSpecificTag(kBPVendorArm)); |
| 1774 | } |
| 1775 | |
| 1776 | return skip; |
| 1777 | } |
| 1778 | |
Camden Stocker | 9c05144 | 2019-11-06 14:28:43 -0800 | [diff] [blame] | 1779 | bool BestPractices::ValidateGetPhysicalDeviceDisplayPlanePropertiesKHRQuery(VkPhysicalDevice physicalDevice, |
| 1780 | const char* api_name) const { |
| 1781 | bool skip = false; |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 1782 | const auto* bp_pd_state = GetPhysicalDeviceStateBP(physicalDevice); |
Camden Stocker | 9c05144 | 2019-11-06 14:28:43 -0800 | [diff] [blame] | 1783 | |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 1784 | if (bp_pd_state) { |
| 1785 | if (bp_pd_state->vkGetPhysicalDeviceDisplayPlanePropertiesKHRState == UNCALLED) { |
| 1786 | skip |= LogWarning(physicalDevice, kVUID_BestPractices_DisplayPlane_PropertiesNotCalled, |
| 1787 | "Potential problem with calling %s() without first retrieving properties from " |
| 1788 | "vkGetPhysicalDeviceDisplayPlanePropertiesKHR or vkGetPhysicalDeviceDisplayPlaneProperties2KHR.", |
| 1789 | api_name); |
| 1790 | } |
Camden Stocker | 9c05144 | 2019-11-06 14:28:43 -0800 | [diff] [blame] | 1791 | } |
| 1792 | |
| 1793 | return skip; |
| 1794 | } |
| 1795 | |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 1796 | bool BestPractices::PreCallValidateGetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physicalDevice, uint32_t planeIndex, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1797 | uint32_t* pDisplayCount, VkDisplayKHR* pDisplays) const { |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 1798 | bool skip = false; |
| 1799 | |
Camden Stocker | 9c05144 | 2019-11-06 14:28:43 -0800 | [diff] [blame] | 1800 | skip |= ValidateGetPhysicalDeviceDisplayPlanePropertiesKHRQuery(physicalDevice, "vkGetDisplayPlaneSupportedDisplaysKHR"); |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 1801 | |
Camden Stocker | 9c05144 | 2019-11-06 14:28:43 -0800 | [diff] [blame] | 1802 | return skip; |
| 1803 | } |
| 1804 | |
| 1805 | bool BestPractices::PreCallValidateGetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice physicalDevice, VkDisplayModeKHR mode, |
| 1806 | uint32_t planeIndex, |
| 1807 | VkDisplayPlaneCapabilitiesKHR* pCapabilities) const { |
| 1808 | bool skip = false; |
| 1809 | |
| 1810 | skip |= ValidateGetPhysicalDeviceDisplayPlanePropertiesKHRQuery(physicalDevice, "vkGetDisplayPlaneCapabilitiesKHR"); |
| 1811 | |
| 1812 | return skip; |
| 1813 | } |
| 1814 | |
| 1815 | bool BestPractices::PreCallValidateGetDisplayPlaneCapabilities2KHR(VkPhysicalDevice physicalDevice, |
| 1816 | const VkDisplayPlaneInfo2KHR* pDisplayPlaneInfo, |
| 1817 | VkDisplayPlaneCapabilities2KHR* pCapabilities) const { |
| 1818 | bool skip = false; |
| 1819 | |
| 1820 | skip |= ValidateGetPhysicalDeviceDisplayPlanePropertiesKHRQuery(physicalDevice, "vkGetDisplayPlaneCapabilities2KHR"); |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 1821 | |
| 1822 | return skip; |
| 1823 | } |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 1824 | |
| 1825 | bool BestPractices::PreCallValidateGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t* pSwapchainImageCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1826 | VkImage* pSwapchainImages) const { |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 1827 | bool skip = false; |
| 1828 | |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 1829 | auto swapchain_state_itr = swapchain_bp_state_map.find(swapchain); |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 1830 | |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 1831 | if ((swapchain_state_itr != swapchain_bp_state_map.cend()) && pSwapchainImages) { |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 1832 | // Compare the preliminary value of *pSwapchainImageCount with the value this time: |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 1833 | if (swapchain_state_itr->second.vkGetSwapchainImagesKHRState == UNCALLED) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1834 | skip |= |
| 1835 | LogWarning(device, kVUID_Core_Swapchain_PriorCount, |
| 1836 | "vkGetSwapchainImagesKHR() called with non-NULL pSwapchainImageCount; but no prior positive value has " |
| 1837 | "been seen for pSwapchainImages."); |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 1838 | } |
| 1839 | } |
| 1840 | |
| 1841 | return skip; |
| 1842 | } |
| 1843 | |
| 1844 | // Common function to handle validation for GetPhysicalDeviceQueueFamilyProperties & 2KHR version |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1845 | bool BestPractices::ValidateCommonGetPhysicalDeviceQueueFamilyProperties(const PHYSICAL_DEVICE_STATE* pd_state, |
| 1846 | uint32_t requested_queue_family_property_count, |
Nathaniel Cesario | 56a9665 | 2020-12-30 13:23:42 -0700 | [diff] [blame] | 1847 | const CALL_STATE call_state, |
| 1848 | const char* caller_name) const { |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 1849 | bool skip = false; |
Nathaniel Cesario | 56a9665 | 2020-12-30 13:23:42 -0700 | [diff] [blame] | 1850 | // Verify that for each physical device, this command is called first with NULL pQueueFamilyProperties in order to get count |
| 1851 | if (UNCALLED == call_state) { |
| 1852 | skip |= LogWarning( |
| 1853 | pd_state->phys_device, kVUID_Core_DevLimit_MissingQueryCount, |
| 1854 | "%s is called with non-NULL pQueueFamilyProperties before obtaining pQueueFamilyPropertyCount. It is " |
| 1855 | "recommended " |
| 1856 | "to first call %s with NULL pQueueFamilyProperties in order to obtain the maximal pQueueFamilyPropertyCount.", |
| 1857 | caller_name, caller_name); |
| 1858 | // Then verify that pCount that is passed in on second call matches what was returned |
| 1859 | } else if (pd_state->queue_family_known_count != requested_queue_family_property_count) { |
| 1860 | skip |= LogWarning(pd_state->phys_device, kVUID_Core_DevLimit_CountMismatch, |
| 1861 | "%s is called with non-NULL pQueueFamilyProperties and pQueueFamilyPropertyCount value %" PRIu32 |
| 1862 | ", but the largest previously returned pQueueFamilyPropertyCount for this physicalDevice is %" PRIu32 |
| 1863 | ". It is recommended to instead receive all the properties by calling %s with " |
| 1864 | "pQueueFamilyPropertyCount that was " |
| 1865 | "previously obtained by calling %s with NULL pQueueFamilyProperties.", |
| 1866 | caller_name, requested_queue_family_property_count, pd_state->queue_family_known_count, caller_name, |
| 1867 | caller_name); |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 1868 | } |
| 1869 | |
| 1870 | return skip; |
| 1871 | } |
| 1872 | |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1873 | bool BestPractices::PreCallValidateBindAccelerationStructureMemoryNV( |
| 1874 | VkDevice device, uint32_t bindInfoCount, const VkBindAccelerationStructureMemoryInfoNV* pBindInfos) const { |
Camden Stocker | 8251058 | 2019-09-03 14:00:16 -0600 | [diff] [blame] | 1875 | bool skip = false; |
| 1876 | |
| 1877 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 1878 | const ACCELERATION_STRUCTURE_STATE* as_state = GetAccelerationStructureStateNV(pBindInfos[i].accelerationStructure); |
Camden Stocker | 8251058 | 2019-09-03 14:00:16 -0600 | [diff] [blame] | 1879 | if (!as_state->memory_requirements_checked) { |
| 1880 | // There's not an explicit requirement in the spec to call vkGetImageMemoryRequirements() prior to calling |
| 1881 | // BindAccelerationStructureMemoryNV but it's implied in that memory being bound must conform with |
| 1882 | // VkAccelerationStructureMemoryRequirementsInfoNV from vkGetAccelerationStructureMemoryRequirementsNV |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1883 | skip |= LogWarning( |
| 1884 | device, kVUID_BestPractices_BindAccelNV_NoMemReqQuery, |
Camden Stocker | 8251058 | 2019-09-03 14:00:16 -0600 | [diff] [blame] | 1885 | "vkBindAccelerationStructureMemoryNV(): " |
| 1886 | "Binding memory to %s but vkGetAccelerationStructureMemoryRequirementsNV() has not been called on that structure.", |
| 1887 | report_data->FormatHandle(pBindInfos[i].accelerationStructure).c_str()); |
| 1888 | } |
| 1889 | } |
| 1890 | |
| 1891 | return skip; |
| 1892 | } |
| 1893 | |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 1894 | bool BestPractices::PreCallValidateGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, |
| 1895 | uint32_t* pQueueFamilyPropertyCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1896 | VkQueueFamilyProperties* pQueueFamilyProperties) const { |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 1897 | const auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 1898 | assert(physical_device_state); |
Nathaniel Cesario | 56a9665 | 2020-12-30 13:23:42 -0700 | [diff] [blame] | 1899 | const auto* bp_pd_state = GetPhysicalDeviceStateBP(physical_device_state->phys_device); |
| 1900 | if (pQueueFamilyProperties && bp_pd_state) { |
| 1901 | return ValidateCommonGetPhysicalDeviceQueueFamilyProperties(physical_device_state, *pQueueFamilyPropertyCount, |
| 1902 | bp_pd_state->vkGetPhysicalDeviceQueueFamilyPropertiesState, |
| 1903 | "vkGetPhysicalDeviceQueueFamilyProperties()"); |
| 1904 | } |
| 1905 | return false; |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 1906 | } |
| 1907 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1908 | bool BestPractices::PreCallValidateGetPhysicalDeviceQueueFamilyProperties2(VkPhysicalDevice physicalDevice, |
| 1909 | uint32_t* pQueueFamilyPropertyCount, |
| 1910 | VkQueueFamilyProperties2* pQueueFamilyProperties) const { |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 1911 | const auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 1912 | assert(physical_device_state); |
Nathaniel Cesario | 56a9665 | 2020-12-30 13:23:42 -0700 | [diff] [blame] | 1913 | const auto* bp_pd_state = GetPhysicalDeviceStateBP(physical_device_state->phys_device); |
| 1914 | if (pQueueFamilyProperties && bp_pd_state) { |
| 1915 | return ValidateCommonGetPhysicalDeviceQueueFamilyProperties(physical_device_state, *pQueueFamilyPropertyCount, |
| 1916 | bp_pd_state->vkGetPhysicalDeviceQueueFamilyProperties2State, |
| 1917 | "vkGetPhysicalDeviceQueueFamilyProperties2()"); |
| 1918 | } |
| 1919 | return false; |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 1920 | } |
| 1921 | |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1922 | bool BestPractices::PreCallValidateGetPhysicalDeviceQueueFamilyProperties2KHR( |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1923 | VkPhysicalDevice physicalDevice, uint32_t* pQueueFamilyPropertyCount, VkQueueFamilyProperties2* pQueueFamilyProperties) const { |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 1924 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 1925 | assert(physical_device_state); |
Nathaniel Cesario | 56a9665 | 2020-12-30 13:23:42 -0700 | [diff] [blame] | 1926 | const auto* bp_pd_state = GetPhysicalDeviceStateBP(physical_device_state->phys_device); |
| 1927 | if (pQueueFamilyProperties && bp_pd_state) { |
| 1928 | return ValidateCommonGetPhysicalDeviceQueueFamilyProperties(physical_device_state, *pQueueFamilyPropertyCount, |
| 1929 | bp_pd_state->vkGetPhysicalDeviceQueueFamilyProperties2KHRState, |
| 1930 | "vkGetPhysicalDeviceQueueFamilyProperties2KHR()"); |
| 1931 | } |
| 1932 | return false; |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 1933 | } |
| 1934 | |
| 1935 | bool BestPractices::PreCallValidateGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, |
| 1936 | uint32_t* pSurfaceFormatCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1937 | VkSurfaceFormatKHR* pSurfaceFormats) const { |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 1938 | if (!pSurfaceFormats) return false; |
| 1939 | const auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 1940 | const auto* bp_pd_state = GetPhysicalDeviceStateBP(physicalDevice); |
| 1941 | const auto& call_state = bp_pd_state->vkGetPhysicalDeviceSurfaceFormatsKHRState; |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 1942 | bool skip = false; |
| 1943 | if (call_state == UNCALLED) { |
| 1944 | // Since we haven't recorded a preliminary value of *pSurfaceFormatCount, that likely means that the application didn't |
| 1945 | // previously call this function with a NULL value of pSurfaceFormats: |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1946 | skip |= LogWarning(physicalDevice, kVUID_Core_DevLimit_MustQueryCount, |
| 1947 | "vkGetPhysicalDeviceSurfaceFormatsKHR() called with non-NULL pSurfaceFormatCount; but no prior " |
| 1948 | "positive value has been seen for pSurfaceFormats."); |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 1949 | } else { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1950 | 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] | 1951 | if (*pSurfaceFormatCount > prev_format_count) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1952 | skip |= LogWarning(physicalDevice, kVUID_Core_DevLimit_CountMismatch, |
| 1953 | "vkGetPhysicalDeviceSurfaceFormatsKHR() called with non-NULL pSurfaceFormatCount, and with " |
| 1954 | "pSurfaceFormats set to a value (%u) that is greater than the value (%u) that was returned " |
| 1955 | "when pSurfaceFormatCount was NULL.", |
| 1956 | *pSurfaceFormatCount, prev_format_count); |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 1957 | } |
| 1958 | } |
| 1959 | return skip; |
| 1960 | } |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 1961 | |
| 1962 | bool BestPractices::PreCallValidateQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo* pBindInfo, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1963 | VkFence fence) const { |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 1964 | bool skip = false; |
| 1965 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1966 | for (uint32_t bind_idx = 0; bind_idx < bindInfoCount; bind_idx++) { |
| 1967 | const VkBindSparseInfo& bind_info = pBindInfo[bind_idx]; |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 1968 | // 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^] | 1969 | layer_data::unordered_set<const IMAGE_STATE*> sparse_images; |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 1970 | // Track images getting metadata bound by this call in a set, it'll be recorded into the image_state |
| 1971 | // in RecordQueueBindSparse. |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame^] | 1972 | layer_data::unordered_set<const IMAGE_STATE*> sparse_images_with_metadata; |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 1973 | // 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] | 1974 | for (uint32_t i = 0; i < bind_info.imageBindCount; ++i) { |
| 1975 | const auto& image_bind = bind_info.pImageBinds[i]; |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 1976 | auto image_state = GetImageState(image_bind.image); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1977 | if (!image_state) { |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 1978 | 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] | 1979 | } |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 1980 | sparse_images.insert(image_state); |
| 1981 | if (image_state->createInfo.flags & VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT) { |
| 1982 | if (!image_state->get_sparse_reqs_called || image_state->sparse_requirements.empty()) { |
| 1983 | // For now just warning if sparse image binding occurs without calling to get reqs first |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1984 | skip |= LogWarning(image_state->image, kVUID_Core_MemTrack_InvalidState, |
| 1985 | "vkQueueBindSparse(): Binding sparse memory to %s without first calling " |
| 1986 | "vkGetImageSparseMemoryRequirements[2KHR]() to retrieve requirements.", |
| 1987 | report_data->FormatHandle(image_state->image).c_str()); |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 1988 | } |
| 1989 | } |
| 1990 | if (!image_state->memory_requirements_checked) { |
| 1991 | // For now just warning if sparse image binding occurs without calling to get reqs first |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1992 | skip |= LogWarning(image_state->image, kVUID_Core_MemTrack_InvalidState, |
| 1993 | "vkQueueBindSparse(): Binding sparse memory to %s without first calling " |
| 1994 | "vkGetImageMemoryRequirements() to retrieve requirements.", |
| 1995 | report_data->FormatHandle(image_state->image).c_str()); |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 1996 | } |
| 1997 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1998 | for (uint32_t i = 0; i < bind_info.imageOpaqueBindCount; ++i) { |
| 1999 | const auto& image_opaque_bind = bind_info.pImageOpaqueBinds[i]; |
| 2000 | auto image_state = GetImageState(bind_info.pImageOpaqueBinds[i].image); |
| 2001 | if (!image_state) { |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 2002 | 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] | 2003 | } |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 2004 | sparse_images.insert(image_state); |
| 2005 | if (image_state->createInfo.flags & VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT) { |
| 2006 | if (!image_state->get_sparse_reqs_called || image_state->sparse_requirements.empty()) { |
| 2007 | // For now just warning if sparse image binding occurs without calling to get reqs first |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 2008 | skip |= LogWarning(image_state->image, kVUID_Core_MemTrack_InvalidState, |
| 2009 | "vkQueueBindSparse(): Binding opaque sparse memory to %s without first calling " |
| 2010 | "vkGetImageSparseMemoryRequirements[2KHR]() to retrieve requirements.", |
| 2011 | report_data->FormatHandle(image_state->image).c_str()); |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 2012 | } |
| 2013 | } |
| 2014 | if (!image_state->memory_requirements_checked) { |
| 2015 | // For now just warning if sparse image binding occurs without calling to get reqs first |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 2016 | skip |= LogWarning(image_state->image, kVUID_Core_MemTrack_InvalidState, |
| 2017 | "vkQueueBindSparse(): Binding opaque sparse memory to %s without first calling " |
| 2018 | "vkGetImageMemoryRequirements() to retrieve requirements.", |
| 2019 | report_data->FormatHandle(image_state->image).c_str()); |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 2020 | } |
| 2021 | for (uint32_t j = 0; j < image_opaque_bind.bindCount; ++j) { |
| 2022 | 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] | 2023 | sparse_images_with_metadata.insert(image_state); |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 2024 | } |
| 2025 | } |
| 2026 | } |
| 2027 | for (const auto& sparse_image_state : sparse_images) { |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 2028 | if (sparse_image_state->sparse_metadata_required && !sparse_image_state->sparse_metadata_bound && |
| 2029 | 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] | 2030 | // Warn if sparse image binding metadata required for image with sparse binding, but metadata not bound |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 2031 | skip |= LogWarning(sparse_image_state->image, kVUID_Core_MemTrack_InvalidState, |
| 2032 | "vkQueueBindSparse(): Binding sparse memory to %s which requires a metadata aspect but no " |
| 2033 | "binding with VK_SPARSE_MEMORY_BIND_METADATA_BIT set was made.", |
| 2034 | report_data->FormatHandle(sparse_image_state->image).c_str()); |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 2035 | } |
| 2036 | } |
| 2037 | } |
| 2038 | |
| 2039 | return skip; |
| 2040 | } |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 2041 | |
Mark Lobodzinski | 84101d7 | 2020-04-24 09:43:48 -0600 | [diff] [blame] | 2042 | void BestPractices::ManualPostCallRecordQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo* pBindInfo, |
| 2043 | VkFence fence, VkResult result) { |
Mark Lobodzinski | 205b7a0 | 2020-02-21 13:23:17 -0700 | [diff] [blame] | 2044 | if (result != VK_SUCCESS) { |
Mark Lobodzinski | 205b7a0 | 2020-02-21 13:23:17 -0700 | [diff] [blame] | 2045 | return; |
| 2046 | } |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 2047 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2048 | for (uint32_t bind_idx = 0; bind_idx < bindInfoCount; bind_idx++) { |
| 2049 | const VkBindSparseInfo& bind_info = pBindInfo[bind_idx]; |
| 2050 | for (uint32_t i = 0; i < bind_info.imageOpaqueBindCount; ++i) { |
| 2051 | const auto& image_opaque_bind = bind_info.pImageOpaqueBinds[i]; |
| 2052 | auto image_state = GetImageState(bind_info.pImageOpaqueBinds[i].image); |
| 2053 | if (!image_state) { |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 2054 | 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] | 2055 | } |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 2056 | for (uint32_t j = 0; j < image_opaque_bind.bindCount; ++j) { |
| 2057 | if (image_opaque_bind.pBinds[j].flags & VK_SPARSE_MEMORY_BIND_METADATA_BIT) { |
| 2058 | image_state->sparse_metadata_bound = true; |
| 2059 | } |
| 2060 | } |
| 2061 | } |
| 2062 | } |
| 2063 | } |
Camden Stocker | 0e0f89b | 2019-10-16 12:24:31 -0700 | [diff] [blame] | 2064 | |
| 2065 | bool BestPractices::PreCallValidateCmdClearAttachments(VkCommandBuffer commandBuffer, uint32_t attachmentCount, |
Camden Stocker | f55721f | 2019-09-09 11:04:49 -0600 | [diff] [blame] | 2066 | const VkClearAttachment* pAttachments, uint32_t rectCount, |
| 2067 | const VkClearRect* pRects) const { |
Camden Stocker | 0e0f89b | 2019-10-16 12:24:31 -0700 | [diff] [blame] | 2068 | bool skip = false; |
| 2069 | const CMD_BUFFER_STATE* cb_node = GetCBState(commandBuffer); |
| 2070 | if (!cb_node) return skip; |
| 2071 | |
Camden Stocker | f55721f | 2019-09-09 11:04:49 -0600 | [diff] [blame] | 2072 | // 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] | 2073 | if (!cb_node->hasDrawCmd && (cb_node->activeRenderPassBeginInfo.renderArea.extent.width == pRects[0].rect.extent.width) && |
| 2074 | (cb_node->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) { |
| 2075 | // There are times where app needs to use ClearAttachments (generally when reusing a buffer inside of a render pass) |
| 2076 | // This warning should be made more specific. It'd be best to avoid triggering this test if it's a use that must call |
| 2077 | // CmdClearAttachments. |
Mark Lobodzinski | f95a266 | 2020-01-29 15:43:32 -0700 | [diff] [blame] | 2078 | skip |= LogPerformanceWarning(commandBuffer, kVUID_BestPractices_DrawState_ClearCmdBeforeDraw, |
| 2079 | "vkCmdClearAttachments() issued on %s prior to any Draw Cmds. It is recommended you " |
| 2080 | "use RenderPass LOAD_OP_CLEAR on Attachments prior to any Draw.", |
| 2081 | report_data->FormatHandle(commandBuffer).c_str()); |
Camden Stocker | 0e0f89b | 2019-10-16 12:24:31 -0700 | [diff] [blame] | 2082 | } |
| 2083 | |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 2084 | // Check for uses of ClearAttachments along with LOAD_OP_LOAD, |
| 2085 | // as it can be more efficient to just use LOAD_OP_CLEAR |
locke-lunarg | aecf215 | 2020-05-12 17:15:41 -0600 | [diff] [blame] | 2086 | const RENDER_PASS_STATE* rp = cb_node->activeRenderPass.get(); |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 2087 | if (rp) { |
| 2088 | const auto& subpass = rp->createInfo.pSubpasses[cb_node->activeSubpass]; |
| 2089 | |
| 2090 | for (uint32_t i = 0; i < attachmentCount; i++) { |
| 2091 | auto& attachment = pAttachments[i]; |
| 2092 | if (attachment.aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) { |
| 2093 | uint32_t color_attachment = attachment.colorAttachment; |
| 2094 | uint32_t fb_attachment = subpass.pColorAttachments[color_attachment].attachment; |
| 2095 | |
| 2096 | if (fb_attachment != VK_ATTACHMENT_UNUSED) { |
| 2097 | if (rp->createInfo.pAttachments[fb_attachment].loadOp == VK_ATTACHMENT_LOAD_OP_LOAD) { |
| 2098 | skip |= LogPerformanceWarning( |
| 2099 | device, kVUID_BestPractices_ClearAttachments_ClearAfterLoad, |
| 2100 | "vkCmdClearAttachments() issued on %s for color attachment #%u in this subpass, " |
| 2101 | "but LOAD_OP_LOAD was used. If you need to clear the framebuffer, always use LOAD_OP_CLEAR as " |
| 2102 | "it is more efficient.", |
| 2103 | report_data->FormatHandle(commandBuffer).c_str(), color_attachment); |
| 2104 | } |
| 2105 | } |
| 2106 | } |
| 2107 | |
| 2108 | if (subpass.pDepthStencilAttachment && attachment.aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) { |
| 2109 | uint32_t fb_attachment = subpass.pDepthStencilAttachment->attachment; |
| 2110 | |
| 2111 | if (fb_attachment != VK_ATTACHMENT_UNUSED) { |
| 2112 | if (rp->createInfo.pAttachments[fb_attachment].loadOp == VK_ATTACHMENT_LOAD_OP_LOAD) { |
| 2113 | skip |= LogPerformanceWarning( |
| 2114 | device, kVUID_BestPractices_ClearAttachments_ClearAfterLoad, |
| 2115 | "vkCmdClearAttachments() issued on %s for the depth attachment in this subpass, " |
| 2116 | "but LOAD_OP_LOAD was used. If you need to clear the framebuffer, always use LOAD_OP_CLEAR as " |
| 2117 | "it is more efficient.", |
| 2118 | report_data->FormatHandle(commandBuffer).c_str()); |
| 2119 | } |
| 2120 | } |
| 2121 | } |
| 2122 | |
| 2123 | if (subpass.pDepthStencilAttachment && attachment.aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) { |
| 2124 | uint32_t fb_attachment = subpass.pDepthStencilAttachment->attachment; |
| 2125 | |
| 2126 | if (fb_attachment != VK_ATTACHMENT_UNUSED) { |
| 2127 | if (rp->createInfo.pAttachments[fb_attachment].stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD) { |
| 2128 | skip |= LogPerformanceWarning( |
| 2129 | device, kVUID_BestPractices_ClearAttachments_ClearAfterLoad, |
| 2130 | "vkCmdClearAttachments() issued on %s for the stencil attachment in this subpass, " |
| 2131 | "but LOAD_OP_LOAD was used. If you need to clear the framebuffer, always use LOAD_OP_CLEAR as " |
| 2132 | "it is more efficient.", |
| 2133 | report_data->FormatHandle(commandBuffer).c_str()); |
| 2134 | } |
| 2135 | } |
| 2136 | } |
| 2137 | } |
| 2138 | } |
| 2139 | |
Camden Stocker | f55721f | 2019-09-09 11:04:49 -0600 | [diff] [blame] | 2140 | return skip; |
Camden Stocker | 0e0f89b | 2019-10-16 12:24:31 -0700 | [diff] [blame] | 2141 | } |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 2142 | |
| 2143 | bool BestPractices::PreCallValidateCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 2144 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 2145 | const VkImageResolve* pRegions) const { |
| 2146 | bool skip = false; |
| 2147 | |
| 2148 | skip |= VendorCheckEnabled(kBPVendorArm) && |
| 2149 | LogPerformanceWarning(device, kVUID_BestPractices_CmdResolveImage_ResolvingImage, |
| 2150 | "%s Attempting to use vkCmdResolveImage to resolve a multisampled image. " |
| 2151 | "This is a very slow and extremely bandwidth intensive path. " |
| 2152 | "You should always resolve multisampled images on-tile with pResolveAttachments in VkRenderPass.", |
| 2153 | VendorSpecificTag(kBPVendorArm)); |
| 2154 | |
| 2155 | return skip; |
| 2156 | } |
| 2157 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 2158 | bool BestPractices::PreCallValidateCmdResolveImage2KHR(VkCommandBuffer commandBuffer, |
| 2159 | const VkResolveImageInfo2KHR* pResolveImageInfo) const { |
| 2160 | bool skip = false; |
| 2161 | |
| 2162 | skip |= VendorCheckEnabled(kBPVendorArm) && |
| 2163 | LogPerformanceWarning(device, kVUID_BestPractices_CmdResolveImage2KHR_ResolvingImage, |
| 2164 | "%s Attempting to use vkCmdResolveImage2KHR to resolve a multisampled image. " |
| 2165 | "This is a very slow and extremely bandwidth intensive path. " |
| 2166 | "You should always resolve multisampled images on-tile with pResolveAttachments in VkRenderPass.", |
| 2167 | VendorSpecificTag(kBPVendorArm)); |
| 2168 | |
| 2169 | return skip; |
| 2170 | } |
| 2171 | |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 2172 | bool BestPractices::PreCallValidateCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, |
| 2173 | const VkAllocationCallbacks* pAllocator, VkSampler* pSampler) const { |
| 2174 | bool skip = false; |
| 2175 | |
| 2176 | if (VendorCheckEnabled(kBPVendorArm)) { |
| 2177 | if ((pCreateInfo->addressModeU != pCreateInfo->addressModeV) || (pCreateInfo->addressModeV != pCreateInfo->addressModeW)) { |
| 2178 | skip |= LogPerformanceWarning( |
| 2179 | device, kVUID_BestPractices_CreateSampler_DifferentWrappingModes, |
| 2180 | "%s Creating a sampler object with wrapping modes which do not match (U = %u, V = %u, W = %u). " |
| 2181 | "This may cause reduced performance even if only U (1D image) or U/V wrapping modes (2D " |
| 2182 | "image) are actually used. If you need different wrapping modes, disregard this warning.", |
| 2183 | VendorSpecificTag(kBPVendorArm)); |
| 2184 | } |
| 2185 | |
| 2186 | if ((pCreateInfo->minLod != 0.0f) || (pCreateInfo->maxLod < VK_LOD_CLAMP_NONE)) { |
| 2187 | skip |= LogPerformanceWarning( |
| 2188 | device, kVUID_BestPractices_CreateSampler_LodClamping, |
| 2189 | "%s Creating a sampler object with LOD clamping (minLod = %f, maxLod = %f). This may cause reduced performance. " |
| 2190 | "Instead of clamping LOD in the sampler, consider using an VkImageView which restricts the mip-levels, set minLod " |
| 2191 | "to 0.0, and maxLod to VK_LOD_CLAMP_NONE.", |
| 2192 | VendorSpecificTag(kBPVendorArm), pCreateInfo->minLod, pCreateInfo->maxLod); |
| 2193 | } |
| 2194 | |
| 2195 | if (pCreateInfo->mipLodBias != 0.0f) { |
| 2196 | skip |= |
| 2197 | LogPerformanceWarning(device, kVUID_BestPractices_CreateSampler_LodBias, |
| 2198 | "%s Creating a sampler object with LOD bias != 0.0 (%f). This will lead to less efficient " |
| 2199 | "descriptors being created and may cause reduced performance.", |
| 2200 | VendorSpecificTag(kBPVendorArm), pCreateInfo->mipLodBias); |
| 2201 | } |
| 2202 | |
| 2203 | if ((pCreateInfo->addressModeU == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER || |
| 2204 | pCreateInfo->addressModeV == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER || |
| 2205 | pCreateInfo->addressModeW == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER) && |
| 2206 | (pCreateInfo->borderColor != VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK)) { |
| 2207 | skip |= LogPerformanceWarning( |
| 2208 | device, kVUID_BestPractices_CreateSampler_BorderClampColor, |
| 2209 | "%s Creating a sampler object with border clamping and borderColor != VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK. " |
| 2210 | "This will lead to less efficient descriptors being created and may cause reduced performance. " |
| 2211 | "If possible, use VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK as the border color.", |
| 2212 | VendorSpecificTag(kBPVendorArm)); |
| 2213 | } |
| 2214 | |
| 2215 | if (pCreateInfo->unnormalizedCoordinates) { |
| 2216 | skip |= LogPerformanceWarning( |
| 2217 | device, kVUID_BestPractices_CreateSampler_UnnormalizedCoordinates, |
| 2218 | "%s Creating a sampler object with unnormalized coordinates. This will lead to less efficient " |
| 2219 | "descriptors being created and may cause reduced performance.", |
| 2220 | VendorSpecificTag(kBPVendorArm)); |
| 2221 | } |
| 2222 | |
| 2223 | if (pCreateInfo->anisotropyEnable) { |
| 2224 | skip |= LogPerformanceWarning( |
| 2225 | device, kVUID_BestPractices_CreateSampler_Anisotropy, |
| 2226 | "%s Creating a sampler object with anisotropy. This will lead to less efficient descriptors being created " |
| 2227 | "and may cause reduced performance.", |
| 2228 | VendorSpecificTag(kBPVendorArm)); |
| 2229 | } |
| 2230 | } |
| 2231 | |
| 2232 | return skip; |
| 2233 | } |
Sam Walls | 8e77e4f | 2020-03-16 20:47:40 +0000 | [diff] [blame] | 2234 | |
| 2235 | void BestPractices::PostTransformLRUCacheModel::resize(size_t size) { _entries.resize(size); } |
| 2236 | |
| 2237 | bool BestPractices::PostTransformLRUCacheModel::query_cache(uint32_t value) { |
| 2238 | // look for a cache hit |
| 2239 | auto hit = std::find_if(_entries.begin(), _entries.end(), [value](const CacheEntry& entry) { return entry.value == value; }); |
| 2240 | if (hit != _entries.end()) { |
| 2241 | // mark the cache hit as being most recently used |
| 2242 | hit->age = iteration++; |
| 2243 | return true; |
| 2244 | } |
| 2245 | |
| 2246 | // if there's no cache hit, we need to model the entry being inserted into the cache |
| 2247 | CacheEntry new_entry = {value, iteration}; |
| 2248 | if (iteration < static_cast<uint32_t>(std::distance(_entries.begin(), _entries.end()))) { |
| 2249 | // if there is still space left in the cache, use the next available slot |
| 2250 | *(_entries.begin() + iteration) = new_entry; |
| 2251 | } else { |
| 2252 | // otherwise replace the least recently used cache entry |
| 2253 | auto lru = std::min_element(_entries.begin(), hit, [](const CacheEntry& a, const CacheEntry& b) { return a.age < b.age; }); |
| 2254 | *lru = new_entry; |
| 2255 | } |
| 2256 | iteration++; |
| 2257 | return false; |
| 2258 | } |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 2259 | |
| 2260 | bool BestPractices::PreCallValidateAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout, |
| 2261 | VkSemaphore semaphore, VkFence fence, uint32_t* pImageIndex) const { |
| 2262 | const auto swapchain_data = GetSwapchainState(swapchain); |
| 2263 | bool skip = false; |
| 2264 | if (swapchain_data && swapchain_data->images.size() == 0) { |
| 2265 | skip |= LogWarning(swapchain, kVUID_Core_DrawState_SwapchainImagesNotFound, |
| 2266 | "vkAcquireNextImageKHR: No images found to acquire from. Application probably did not call " |
| 2267 | "vkGetSwapchainImagesKHR after swapchain creation."); |
| 2268 | } |
| 2269 | return skip; |
| 2270 | } |
| 2271 | |
Nathaniel Cesario | 56a9665 | 2020-12-30 13:23:42 -0700 | [diff] [blame] | 2272 | void BestPractices::CommonPostCallRecordGetPhysicalDeviceQueueFamilyProperties(CALL_STATE& call_state, bool no_pointer) { |
| 2273 | if (no_pointer) { |
| 2274 | if (UNCALLED == call_state) { |
| 2275 | call_state = QUERY_COUNT; |
| 2276 | } |
| 2277 | } else { // Save queue family properties |
| 2278 | call_state = QUERY_DETAILS; |
| 2279 | } |
| 2280 | } |
| 2281 | |
Nathaniel Cesario | f121d12 | 2020-10-08 13:09:46 -0600 | [diff] [blame] | 2282 | void BestPractices::PostCallRecordGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, |
| 2283 | uint32_t* pQueueFamilyPropertyCount, |
| 2284 | VkQueueFamilyProperties* pQueueFamilyProperties) { |
| 2285 | ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties(physicalDevice, pQueueFamilyPropertyCount, |
| 2286 | pQueueFamilyProperties); |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 2287 | auto* bp_pd_state = GetPhysicalDeviceStateBP(physicalDevice); |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 2288 | if (bp_pd_state) { |
Nathaniel Cesario | 56a9665 | 2020-12-30 13:23:42 -0700 | [diff] [blame] | 2289 | CommonPostCallRecordGetPhysicalDeviceQueueFamilyProperties(bp_pd_state->vkGetPhysicalDeviceQueueFamilyPropertiesState, |
| 2290 | nullptr == pQueueFamilyProperties); |
| 2291 | } |
| 2292 | } |
| 2293 | |
| 2294 | void BestPractices::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2(VkPhysicalDevice physicalDevice, |
| 2295 | uint32_t* pQueueFamilyPropertyCount, |
| 2296 | VkQueueFamilyProperties2* pQueueFamilyProperties) { |
| 2297 | ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2(physicalDevice, pQueueFamilyPropertyCount, |
| 2298 | pQueueFamilyProperties); |
| 2299 | auto* bp_pd_state = GetPhysicalDeviceStateBP(physicalDevice); |
| 2300 | if (bp_pd_state) { |
| 2301 | CommonPostCallRecordGetPhysicalDeviceQueueFamilyProperties(bp_pd_state->vkGetPhysicalDeviceQueueFamilyProperties2State, |
| 2302 | nullptr == pQueueFamilyProperties); |
| 2303 | } |
| 2304 | } |
| 2305 | |
| 2306 | void BestPractices::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2KHR(VkPhysicalDevice physicalDevice, |
| 2307 | uint32_t* pQueueFamilyPropertyCount, |
| 2308 | VkQueueFamilyProperties2* pQueueFamilyProperties) { |
| 2309 | ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2KHR(physicalDevice, pQueueFamilyPropertyCount, |
| 2310 | pQueueFamilyProperties); |
| 2311 | auto* bp_pd_state = GetPhysicalDeviceStateBP(physicalDevice); |
| 2312 | if (bp_pd_state) { |
| 2313 | CommonPostCallRecordGetPhysicalDeviceQueueFamilyProperties(bp_pd_state->vkGetPhysicalDeviceQueueFamilyProperties2KHRState, |
| 2314 | nullptr == pQueueFamilyProperties); |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 2315 | } |
| 2316 | } |
| 2317 | |
Nathaniel Cesario | f121d12 | 2020-10-08 13:09:46 -0600 | [diff] [blame] | 2318 | void BestPractices::PostCallRecordGetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures* pFeatures) { |
| 2319 | ValidationStateTracker::PostCallRecordGetPhysicalDeviceFeatures(physicalDevice, pFeatures); |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 2320 | auto* bp_pd_state = GetPhysicalDeviceStateBP(physicalDevice); |
| 2321 | if (bp_pd_state) { |
| 2322 | bp_pd_state->vkGetPhysicalDeviceFeaturesState = QUERY_DETAILS; |
| 2323 | } |
| 2324 | } |
| 2325 | |
Nathaniel Cesario | f121d12 | 2020-10-08 13:09:46 -0600 | [diff] [blame] | 2326 | void BestPractices::PostCallRecordGetPhysicalDeviceFeatures2(VkPhysicalDevice physicalDevice, |
| 2327 | VkPhysicalDeviceFeatures2* pFeatures) { |
| 2328 | ValidationStateTracker::PostCallRecordGetPhysicalDeviceFeatures2(physicalDevice, pFeatures); |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 2329 | auto* bp_pd_state = GetPhysicalDeviceStateBP(physicalDevice); |
| 2330 | if (bp_pd_state) { |
| 2331 | bp_pd_state->vkGetPhysicalDeviceFeaturesState = QUERY_DETAILS; |
| 2332 | } |
| 2333 | } |
| 2334 | |
Nathaniel Cesario | f121d12 | 2020-10-08 13:09:46 -0600 | [diff] [blame] | 2335 | void BestPractices::PostCallRecordGetPhysicalDeviceFeatures2KHR(VkPhysicalDevice physicalDevice, |
| 2336 | VkPhysicalDeviceFeatures2* pFeatures) { |
| 2337 | ValidationStateTracker::PostCallRecordGetPhysicalDeviceFeatures2KHR(physicalDevice, pFeatures); |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 2338 | auto* bp_pd_state = GetPhysicalDeviceStateBP(physicalDevice); |
| 2339 | if (bp_pd_state) { |
| 2340 | bp_pd_state->vkGetPhysicalDeviceFeaturesState = QUERY_DETAILS; |
| 2341 | } |
| 2342 | } |
| 2343 | |
| 2344 | void BestPractices::ManualPostCallRecordGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice, |
| 2345 | VkSurfaceKHR surface, |
| 2346 | VkSurfaceCapabilitiesKHR* pSurfaceCapabilities, |
| 2347 | VkResult result) { |
| 2348 | auto* bp_pd_state = GetPhysicalDeviceStateBP(physicalDevice); |
| 2349 | if (bp_pd_state) { |
| 2350 | bp_pd_state->vkGetPhysicalDeviceSurfaceCapabilitiesKHRState = QUERY_DETAILS; |
| 2351 | } |
| 2352 | } |
| 2353 | |
| 2354 | void BestPractices::ManualPostCallRecordGetPhysicalDeviceSurfaceCapabilities2KHR( |
| 2355 | VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo, |
| 2356 | VkSurfaceCapabilities2KHR* pSurfaceCapabilities, VkResult result) { |
| 2357 | auto* bp_pd_state = GetPhysicalDeviceStateBP(physicalDevice); |
| 2358 | if (bp_pd_state) { |
| 2359 | bp_pd_state->vkGetPhysicalDeviceSurfaceCapabilitiesKHRState = QUERY_DETAILS; |
| 2360 | } |
| 2361 | } |
| 2362 | |
| 2363 | void BestPractices::ManualPostCallRecordGetPhysicalDeviceSurfaceCapabilities2EXT(VkPhysicalDevice physicalDevice, |
| 2364 | VkSurfaceKHR surface, |
| 2365 | VkSurfaceCapabilities2EXT* pSurfaceCapabilities, |
| 2366 | VkResult result) { |
| 2367 | auto* bp_pd_state = GetPhysicalDeviceStateBP(physicalDevice); |
| 2368 | if (bp_pd_state) { |
| 2369 | bp_pd_state->vkGetPhysicalDeviceSurfaceCapabilitiesKHRState = QUERY_DETAILS; |
| 2370 | } |
| 2371 | } |
| 2372 | |
| 2373 | void BestPractices::ManualPostCallRecordGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice, |
| 2374 | VkSurfaceKHR surface, uint32_t* pPresentModeCount, |
| 2375 | VkPresentModeKHR* pPresentModes, VkResult result) { |
| 2376 | auto* bp_pd_data = GetPhysicalDeviceStateBP(physicalDevice); |
| 2377 | if (bp_pd_data) { |
| 2378 | auto& call_state = bp_pd_data->vkGetPhysicalDeviceSurfacePresentModesKHRState; |
| 2379 | |
| 2380 | if (*pPresentModeCount) { |
| 2381 | if (call_state < QUERY_COUNT) { |
| 2382 | call_state = QUERY_COUNT; |
| 2383 | } |
| 2384 | } |
| 2385 | if (pPresentModes) { |
| 2386 | if (call_state < QUERY_DETAILS) { |
| 2387 | call_state = QUERY_DETAILS; |
| 2388 | } |
| 2389 | } |
| 2390 | } |
| 2391 | } |
| 2392 | |
| 2393 | void BestPractices::ManualPostCallRecordGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, |
| 2394 | uint32_t* pSurfaceFormatCount, |
| 2395 | VkSurfaceFormatKHR* pSurfaceFormats, VkResult result) { |
| 2396 | auto* bp_pd_data = GetPhysicalDeviceStateBP(physicalDevice); |
| 2397 | if (bp_pd_data) { |
| 2398 | auto& call_state = bp_pd_data->vkGetPhysicalDeviceSurfaceFormatsKHRState; |
| 2399 | |
| 2400 | if (*pSurfaceFormatCount) { |
| 2401 | if (call_state < QUERY_COUNT) { |
| 2402 | call_state = QUERY_COUNT; |
| 2403 | } |
| 2404 | } |
| 2405 | if (pSurfaceFormats) { |
| 2406 | if (call_state < QUERY_DETAILS) { |
| 2407 | call_state = QUERY_DETAILS; |
| 2408 | } |
| 2409 | } |
| 2410 | } |
| 2411 | } |
| 2412 | |
| 2413 | void BestPractices::ManualPostCallRecordGetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice, |
| 2414 | const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo, |
| 2415 | uint32_t* pSurfaceFormatCount, |
| 2416 | VkSurfaceFormat2KHR* pSurfaceFormats, VkResult result) { |
| 2417 | auto* bp_pd_data = GetPhysicalDeviceStateBP(physicalDevice); |
| 2418 | if (bp_pd_data) { |
| 2419 | if (*pSurfaceFormatCount) { |
| 2420 | if (bp_pd_data->vkGetPhysicalDeviceSurfaceFormatsKHRState < QUERY_COUNT) { |
| 2421 | bp_pd_data->vkGetPhysicalDeviceSurfaceFormatsKHRState = QUERY_COUNT; |
| 2422 | } |
| 2423 | } |
| 2424 | if (pSurfaceFormats) { |
| 2425 | if (bp_pd_data->vkGetPhysicalDeviceSurfaceFormatsKHRState < QUERY_DETAILS) { |
| 2426 | bp_pd_data->vkGetPhysicalDeviceSurfaceFormatsKHRState = QUERY_DETAILS; |
| 2427 | } |
| 2428 | } |
| 2429 | } |
| 2430 | } |
| 2431 | |
| 2432 | void BestPractices::ManualPostCallRecordGetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice, |
| 2433 | uint32_t* pPropertyCount, |
| 2434 | VkDisplayPlanePropertiesKHR* pProperties, |
| 2435 | VkResult result) { |
| 2436 | auto* bp_pd_data = GetPhysicalDeviceStateBP(physicalDevice); |
| 2437 | if (bp_pd_data) { |
| 2438 | if (*pPropertyCount) { |
| 2439 | if (bp_pd_data->vkGetPhysicalDeviceDisplayPlanePropertiesKHRState < QUERY_COUNT) { |
| 2440 | bp_pd_data->vkGetPhysicalDeviceDisplayPlanePropertiesKHRState = QUERY_COUNT; |
| 2441 | } |
| 2442 | } |
| 2443 | if (pProperties) { |
| 2444 | if (bp_pd_data->vkGetPhysicalDeviceDisplayPlanePropertiesKHRState < QUERY_DETAILS) { |
| 2445 | bp_pd_data->vkGetPhysicalDeviceDisplayPlanePropertiesKHRState = QUERY_DETAILS; |
| 2446 | } |
| 2447 | } |
| 2448 | } |
| 2449 | } |
| 2450 | |
| 2451 | void BestPractices::ManualPostCallRecordCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR* pCreateInfo, |
| 2452 | const VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pSwapchain, |
| 2453 | VkResult result) { |
| 2454 | if (VK_SUCCESS == result) { |
| 2455 | swapchain_bp_state_map.emplace(*pSwapchain, SWAPCHAIN_STATE_BP{}); |
| 2456 | } |
| 2457 | } |
| 2458 | |
Nathaniel Cesario | f121d12 | 2020-10-08 13:09:46 -0600 | [diff] [blame] | 2459 | void BestPractices::PostCallRecordDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain, |
| 2460 | const VkAllocationCallbacks* pAllocator) { |
| 2461 | ValidationStateTracker::PostCallRecordDestroySwapchainKHR(device, swapchain, pAllocator); |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 2462 | auto swapchain_state_itr = swapchain_bp_state_map.find(swapchain); |
| 2463 | if (swapchain_state_itr != swapchain_bp_state_map.cend()) { |
| 2464 | swapchain_bp_state_map.erase(swapchain_state_itr); |
| 2465 | } |
| 2466 | } |
| 2467 | |
| 2468 | void BestPractices::ManualPostCallRecordGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, |
| 2469 | uint32_t* pSwapchainImageCount, VkImage* pSwapchainImages, |
| 2470 | VkResult result) { |
| 2471 | auto swapchain_state_itr = swapchain_bp_state_map.find(swapchain); |
| 2472 | assert(swapchain_state_itr != swapchain_bp_state_map.cend()); |
| 2473 | auto& swapchain_state = swapchain_state_itr->second; |
| 2474 | if (pSwapchainImages || *pSwapchainImageCount) { |
| 2475 | if (swapchain_state.vkGetSwapchainImagesKHRState < QUERY_DETAILS) { |
| 2476 | swapchain_state.vkGetSwapchainImagesKHRState = QUERY_DETAILS; |
| 2477 | } |
| 2478 | } |
| 2479 | } |
| 2480 | |
| 2481 | void BestPractices::ManualPostCallRecordEnumeratePhysicalDevices(VkInstance instance, uint32_t* pPhysicalDeviceCount, |
| 2482 | VkPhysicalDevice* pPhysicalDevices, VkResult result) { |
| 2483 | if ((nullptr != pPhysicalDevices) && ((result == VK_SUCCESS || result == VK_INCOMPLETE))) { |
| 2484 | for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++) { |
| 2485 | phys_device_bp_state_map.emplace(pPhysicalDevices[i], PHYSICAL_DEVICE_STATE_BP{}); |
| 2486 | } |
| 2487 | } |
| 2488 | } |
| 2489 | |
| 2490 | void BestPractices::ManualPostCallRecordCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo*, const VkAllocationCallbacks*, |
| 2491 | VkDevice*, VkResult result) { |
| 2492 | if (VK_SUCCESS == result) { |
| 2493 | instance_device_bp_state = &phys_device_bp_state_map[gpu]; |
| 2494 | } |
| 2495 | } |
| 2496 | |
| 2497 | PHYSICAL_DEVICE_STATE_BP* BestPractices::GetPhysicalDeviceStateBP(const VkPhysicalDevice& phys_device) { |
| 2498 | if (phys_device_bp_state_map.count(phys_device) > 0) { |
| 2499 | return &phys_device_bp_state_map.at(phys_device); |
| 2500 | } else { |
| 2501 | return nullptr; |
| 2502 | } |
| 2503 | } |
| 2504 | |
| 2505 | const PHYSICAL_DEVICE_STATE_BP* BestPractices::GetPhysicalDeviceStateBP(const VkPhysicalDevice& phys_device) const { |
| 2506 | if (phys_device_bp_state_map.count(phys_device) > 0) { |
| 2507 | return &phys_device_bp_state_map.at(phys_device); |
| 2508 | } else { |
| 2509 | return nullptr; |
| 2510 | } |
| 2511 | } |
| 2512 | |
| 2513 | PHYSICAL_DEVICE_STATE_BP* BestPractices::GetPhysicalDeviceStateBP() { |
| 2514 | auto bp_state = (reinterpret_cast<BestPractices*>(instance_state))->instance_device_bp_state; |
| 2515 | if (bp_state) { |
| 2516 | return bp_state; |
| 2517 | } else if (!bp_state && phys_device_bp_state_map.count(physical_device_state->phys_device) > 0) { |
| 2518 | return &phys_device_bp_state_map.at(physical_device_state->phys_device); |
| 2519 | } else { |
| 2520 | return nullptr; |
| 2521 | } |
| 2522 | } |
| 2523 | |
| 2524 | const PHYSICAL_DEVICE_STATE_BP* BestPractices::GetPhysicalDeviceStateBP() const { |
| 2525 | auto bp_state = (reinterpret_cast<BestPractices*>(instance_state))->instance_device_bp_state; |
| 2526 | if (bp_state) { |
| 2527 | return bp_state; |
| 2528 | } else if (!bp_state && phys_device_bp_state_map.count(physical_device_state->phys_device) > 0) { |
| 2529 | return &phys_device_bp_state_map.at(physical_device_state->phys_device); |
| 2530 | } else { |
| 2531 | return nullptr; |
| 2532 | } |
| 2533 | } |