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