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