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