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