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