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 | |
Rodrigo Locatti | 5466f9d | 2022-03-09 18:20:38 -0300 | [diff] [blame] | 417 | if (VendorCheckEnabled(kBPVendorNVIDIA)) { |
| 418 | std::stringstream image_hex; |
| 419 | image_hex << "0x" << std::hex << HandleToUint64(pImage); |
| 420 | |
| 421 | if (pCreateInfo->tiling == VK_IMAGE_TILING_LINEAR) { |
| 422 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_CreateImage_TilingLinear, |
| 423 | "%s Performance warning: image (%s) is created with tiling VK_IMAGE_TILING_LINEAR. " |
| 424 | "Use VK_IMAGE_TILING_OPTIMAL instead.", |
| 425 | VendorSpecificTag(kBPVendorNVIDIA), image_hex.str().c_str()); |
| 426 | } |
Rodrigo Locatti | 3290c2b | 2022-03-09 18:25:56 -0300 | [diff] [blame] | 427 | |
| 428 | if (pCreateInfo->format == VK_FORMAT_D32_SFLOAT || pCreateInfo->format == VK_FORMAT_D32_SFLOAT_S8_UINT) { |
| 429 | skip |= LogPerformanceWarning( |
| 430 | device, kVUID_BestPractices_CreateImage_Depth32Format, |
| 431 | "%s Performance warning: image (%s) is created with a 32-bit depth format. Use VK_FORMAT_D24_UNORM_S8_UINT or " |
| 432 | "VK_FORMAT_D16_UNORM instead, unless the extra precision is needed.", |
| 433 | VendorSpecificTag(kBPVendorNVIDIA), image_hex.str().c_str()); |
| 434 | } |
Rodrigo Locatti | 5466f9d | 2022-03-09 18:20:38 -0300 | [diff] [blame] | 435 | } |
| 436 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 437 | return skip; |
| 438 | } |
| 439 | |
| 440 | bool BestPractices::PreCallValidateCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR* pCreateInfo, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 441 | const VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pSwapchain) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 442 | bool skip = false; |
| 443 | |
Jeremy Gebben | 383b9a3 | 2021-09-08 16:31:33 -0600 | [diff] [blame] | 444 | const auto* bp_pd_state = GetPhysicalDeviceState(); |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 445 | if (bp_pd_state) { |
| 446 | if (bp_pd_state->vkGetPhysicalDeviceSurfaceCapabilitiesKHRState == UNCALLED) { |
| 447 | skip |= LogWarning(device, kVUID_BestPractices_Swapchain_GetSurfaceNotCalled, |
| 448 | "vkCreateSwapchainKHR() called before getting surface capabilities from " |
| 449 | "vkGetPhysicalDeviceSurfaceCapabilitiesKHR()."); |
| 450 | } |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 451 | |
Shannon McPherson | 73e58c8 | 2021-03-05 17:14:26 -0700 | [diff] [blame] | 452 | if ((pCreateInfo->presentMode != VK_PRESENT_MODE_FIFO_KHR) && |
| 453 | (bp_pd_state->vkGetPhysicalDeviceSurfacePresentModesKHRState != QUERY_DETAILS)) { |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 454 | skip |= LogWarning(device, kVUID_BestPractices_Swapchain_GetSurfaceNotCalled, |
| 455 | "vkCreateSwapchainKHR() called before getting surface present mode(s) from " |
| 456 | "vkGetPhysicalDeviceSurfacePresentModesKHR()."); |
| 457 | } |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 458 | |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 459 | if (bp_pd_state->vkGetPhysicalDeviceSurfaceFormatsKHRState != QUERY_DETAILS) { |
| 460 | skip |= LogWarning( |
| 461 | device, kVUID_BestPractices_Swapchain_GetSurfaceNotCalled, |
| 462 | "vkCreateSwapchainKHR() called before getting surface format(s) from vkGetPhysicalDeviceSurfaceFormatsKHR()."); |
| 463 | } |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 464 | } |
| 465 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 466 | if ((pCreateInfo->queueFamilyIndexCount > 1) && (pCreateInfo->imageSharingMode == VK_SHARING_MODE_EXCLUSIVE)) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 467 | skip |= |
| 468 | LogWarning(device, kVUID_BestPractices_SharingModeExclusive, |
Mark Lobodzinski | 019f4e3 | 2020-04-13 11:01:35 -0600 | [diff] [blame] | 469 | "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] | 470 | "specifying multiple queues (queueFamilyIndexCount of %" PRIu32 ").", |
| 471 | pCreateInfo->queueFamilyIndexCount); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 472 | } |
| 473 | |
ziga-lunarg | 79beba6 | 2022-03-30 01:17:30 +0200 | [diff] [blame] | 474 | const auto present_mode = pCreateInfo->presentMode; |
| 475 | if (((present_mode == VK_PRESENT_MODE_MAILBOX_KHR) || (present_mode == VK_PRESENT_MODE_FIFO_KHR)) && |
| 476 | (pCreateInfo->minImageCount == 2)) { |
Szilard Papp | 48a6da3 | 2020-06-10 14:41:59 +0100 | [diff] [blame] | 477 | skip |= LogPerformanceWarning( |
| 478 | device, kVUID_BestPractices_SuboptimalSwapchainImageCount, |
| 479 | "Warning: A Swapchain is being created with minImageCount set to %" PRIu32 |
| 480 | ", which means double buffering is going " |
| 481 | "to be used. Using double buffering and vsync locks rendering to an integer fraction of the vsync rate. In turn, " |
| 482 | "reducing the performance of the application if rendering is slower than vsync. Consider setting minImageCount to " |
| 483 | "3 to use triple buffering to maximize performance in such cases.", |
| 484 | pCreateInfo->minImageCount); |
| 485 | } |
| 486 | |
Szilard Papp | d5f0f81 | 2020-06-22 09:01:29 +0100 | [diff] [blame] | 487 | if (VendorCheckEnabled(kBPVendorArm) && (pCreateInfo->presentMode != VK_PRESENT_MODE_FIFO_KHR)) { |
| 488 | skip |= LogWarning(device, kVUID_BestPractices_CreateSwapchain_PresentMode, |
| 489 | "%s Warning: Swapchain is not being created with presentation mode \"VK_PRESENT_MODE_FIFO_KHR\". " |
| 490 | "Prefer using \"VK_PRESENT_MODE_FIFO_KHR\" to avoid unnecessary CPU and GPU load and save power. " |
| 491 | "Presentation modes which are not FIFO will present the latest available frame and discard other " |
| 492 | "frame(s) if any.", |
| 493 | VendorSpecificTag(kBPVendorArm)); |
| 494 | } |
| 495 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 496 | return skip; |
| 497 | } |
| 498 | |
| 499 | bool BestPractices::PreCallValidateCreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount, |
| 500 | const VkSwapchainCreateInfoKHR* pCreateInfos, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 501 | const VkAllocationCallbacks* pAllocator, |
| 502 | VkSwapchainKHR* pSwapchains) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 503 | bool skip = false; |
| 504 | |
| 505 | for (uint32_t i = 0; i < swapchainCount; i++) { |
| 506 | if ((pCreateInfos[i].queueFamilyIndexCount > 1) && (pCreateInfos[i].imageSharingMode == VK_SHARING_MODE_EXCLUSIVE)) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 507 | skip |= LogWarning( |
| 508 | device, kVUID_BestPractices_SharingModeExclusive, |
| 509 | "Warning: A shared swapchain (index %" PRIu32 |
| 510 | ") is being created which specifies a sharing mode of VK_SHARING_MODE_EXCLUSIVE while specifying multiple " |
| 511 | "queues (queueFamilyIndexCount of %" PRIu32 ").", |
| 512 | i, pCreateInfos[i].queueFamilyIndexCount); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 513 | } |
| 514 | } |
| 515 | |
| 516 | return skip; |
| 517 | } |
| 518 | |
| 519 | bool BestPractices::PreCallValidateCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 520 | const VkAllocationCallbacks* pAllocator, VkRenderPass* pRenderPass) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 521 | bool skip = false; |
| 522 | |
| 523 | for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) { |
| 524 | VkFormat format = pCreateInfo->pAttachments[i].format; |
| 525 | if (pCreateInfo->pAttachments[i].initialLayout == VK_IMAGE_LAYOUT_UNDEFINED) { |
| 526 | if ((FormatIsColor(format) || FormatHasDepth(format)) && |
| 527 | pCreateInfo->pAttachments[i].loadOp == VK_ATTACHMENT_LOAD_OP_LOAD) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 528 | skip |= LogWarning(device, kVUID_BestPractices_RenderPass_Attatchment, |
| 529 | "Render pass has an attachment with loadOp == VK_ATTACHMENT_LOAD_OP_LOAD and " |
| 530 | "initialLayout == VK_IMAGE_LAYOUT_UNDEFINED. This is probably not what you " |
| 531 | "intended. Consider using VK_ATTACHMENT_LOAD_OP_DONT_CARE instead if the " |
| 532 | "image truely is undefined at the start of the render pass."); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 533 | } |
| 534 | if (FormatHasStencil(format) && pCreateInfo->pAttachments[i].stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 535 | skip |= LogWarning(device, kVUID_BestPractices_RenderPass_Attatchment, |
| 536 | "Render pass has an attachment with stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD " |
| 537 | "and initialLayout == VK_IMAGE_LAYOUT_UNDEFINED. This is probably not what you " |
| 538 | "intended. Consider using VK_ATTACHMENT_LOAD_OP_DONT_CARE instead if the " |
| 539 | "image truely is undefined at the start of the render pass."); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 540 | } |
| 541 | } |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 542 | |
| 543 | const auto& attachment = pCreateInfo->pAttachments[i]; |
| 544 | if (attachment.samples > VK_SAMPLE_COUNT_1_BIT) { |
| 545 | bool access_requires_memory = |
| 546 | attachment.loadOp == VK_ATTACHMENT_LOAD_OP_LOAD || attachment.storeOp == VK_ATTACHMENT_STORE_OP_STORE; |
| 547 | |
| 548 | if (FormatHasStencil(format)) { |
| 549 | access_requires_memory |= attachment.stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD || |
| 550 | attachment.stencilStoreOp == VK_ATTACHMENT_STORE_OP_STORE; |
| 551 | } |
| 552 | |
| 553 | if (access_requires_memory) { |
| 554 | skip |= LogPerformanceWarning( |
| 555 | device, kVUID_BestPractices_CreateRenderPass_ImageRequiresMemory, |
| 556 | "Attachment %u in the VkRenderPass is a multisampled image with %u samples, but it uses loadOp/storeOp " |
| 557 | "which requires accessing data from memory. Multisampled images should always be loadOp = CLEAR or DONT_CARE, " |
| 558 | "storeOp = DONT_CARE. This allows the implementation to use lazily allocated memory effectively.", |
| 559 | i, static_cast<uint32_t>(attachment.samples)); |
| 560 | } |
| 561 | } |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | for (uint32_t dependency = 0; dependency < pCreateInfo->dependencyCount; dependency++) { |
| 565 | skip |= CheckPipelineStageFlags("vkCreateRenderPass", pCreateInfo->pDependencies[dependency].srcStageMask); |
| 566 | skip |= CheckPipelineStageFlags("vkCreateRenderPass", pCreateInfo->pDependencies[dependency].dstStageMask); |
| 567 | } |
| 568 | |
| 569 | return skip; |
| 570 | } |
| 571 | |
Tony-LunarG | 767180f | 2020-04-23 14:03:59 -0600 | [diff] [blame] | 572 | bool BestPractices::ValidateAttachments(const VkRenderPassCreateInfo2* rpci, uint32_t attachmentCount, |
| 573 | const VkImageView* image_views) const { |
| 574 | bool skip = false; |
| 575 | |
| 576 | // Check for non-transient attachments that should be transient and vice versa |
| 577 | for (uint32_t i = 0; i < attachmentCount; ++i) { |
Hans-Kristian Arntzen | 69ace7d | 2021-04-28 14:17:19 +0200 | [diff] [blame] | 578 | const auto& attachment = rpci->pAttachments[i]; |
Tony-LunarG | 767180f | 2020-04-23 14:03:59 -0600 | [diff] [blame] | 579 | bool attachment_should_be_transient = |
| 580 | (attachment.loadOp != VK_ATTACHMENT_LOAD_OP_LOAD && attachment.storeOp != VK_ATTACHMENT_STORE_OP_STORE); |
| 581 | |
| 582 | if (FormatHasStencil(attachment.format)) { |
| 583 | attachment_should_be_transient &= (attachment.stencilLoadOp != VK_ATTACHMENT_LOAD_OP_LOAD && |
| 584 | attachment.stencilStoreOp != VK_ATTACHMENT_STORE_OP_STORE); |
| 585 | } |
| 586 | |
Jeremy Gebben | b20a824 | 2021-11-05 15:14:43 -0600 | [diff] [blame] | 587 | auto view_state = Get<IMAGE_VIEW_STATE>(image_views[i]); |
Tony-LunarG | 767180f | 2020-04-23 14:03:59 -0600 | [diff] [blame] | 588 | if (view_state) { |
Jeremy Gebben | 057f9d5 | 2021-11-05 14:12:31 -0600 | [diff] [blame] | 589 | const auto& ici = view_state->image_state->createInfo; |
Tony-LunarG | 767180f | 2020-04-23 14:03:59 -0600 | [diff] [blame] | 590 | |
| 591 | bool image_is_transient = (ici.usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) != 0; |
| 592 | |
| 593 | // The check for an image that should not be transient applies to all GPUs |
| 594 | if (!attachment_should_be_transient && image_is_transient) { |
| 595 | skip |= LogPerformanceWarning( |
| 596 | device, kVUID_BestPractices_CreateFramebuffer_AttachmentShouldNotBeTransient, |
| 597 | "Attachment %u in VkFramebuffer uses loadOp/storeOps which need to access physical memory, " |
| 598 | "but the image backing the image view has VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT set. " |
| 599 | "Physical memory will need to be backed lazily to this image, potentially causing stalls.", |
| 600 | i); |
| 601 | } |
| 602 | |
| 603 | bool supports_lazy = false; |
| 604 | for (uint32_t j = 0; j < phys_dev_mem_props.memoryTypeCount; j++) { |
| 605 | if (phys_dev_mem_props.memoryTypes[j].propertyFlags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) { |
| 606 | supports_lazy = true; |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | // The check for an image that should be transient only applies to GPUs supporting |
| 611 | // lazily allocated memory |
| 612 | if (supports_lazy && attachment_should_be_transient && !image_is_transient) { |
| 613 | skip |= LogPerformanceWarning( |
| 614 | device, kVUID_BestPractices_CreateFramebuffer_AttachmentShouldBeTransient, |
| 615 | "Attachment %u in VkFramebuffer uses loadOp/storeOps which never have to be backed by physical memory, " |
| 616 | "but the image backing the image view does not have VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT set. " |
| 617 | "You can save physical memory by using transient attachment backed by lazily allocated memory here.", |
| 618 | i); |
| 619 | } |
| 620 | } |
| 621 | } |
| 622 | return skip; |
| 623 | } |
| 624 | |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 625 | bool BestPractices::PreCallValidateCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, |
| 626 | const VkAllocationCallbacks* pAllocator, VkFramebuffer* pFramebuffer) const { |
| 627 | bool skip = false; |
| 628 | |
Jeremy Gebben | b20a824 | 2021-11-05 15:14:43 -0600 | [diff] [blame] | 629 | auto rp_state = Get<RENDER_PASS_STATE>(pCreateInfo->renderPass); |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 630 | if (rp_state && !(pCreateInfo->flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT)) { |
Tony-LunarG | 767180f | 2020-04-23 14:03:59 -0600 | [diff] [blame] | 631 | skip = ValidateAttachments(rp_state->createInfo.ptr(), pCreateInfo->attachmentCount, pCreateInfo->pAttachments); |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | return skip; |
| 635 | } |
| 636 | |
Sam Walls | e746d52 | 2020-03-16 21:20:23 +0000 | [diff] [blame] | 637 | bool BestPractices::PreCallValidateAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo* pAllocateInfo, |
| 638 | VkDescriptorSet* pDescriptorSets, void* ads_state_data) const { |
| 639 | bool skip = false; |
| 640 | skip |= ValidationStateTracker::PreCallValidateAllocateDescriptorSets(device, pAllocateInfo, pDescriptorSets, ads_state_data); |
| 641 | |
| 642 | if (!skip) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 643 | const auto pool_state = Get<bp_state::DescriptorPool>(pAllocateInfo->descriptorPool); |
Sam Walls | e746d52 | 2020-03-16 21:20:23 +0000 | [diff] [blame] | 644 | // if the number of freed sets > 0, it implies they could be recycled instead if desirable |
| 645 | // this warning is specific to Arm |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 646 | if (VendorCheckEnabled(kBPVendorArm) && pool_state && (pool_state->freed_count > 0)) { |
Sam Walls | e746d52 | 2020-03-16 21:20:23 +0000 | [diff] [blame] | 647 | skip |= LogPerformanceWarning( |
| 648 | device, kVUID_BestPractices_AllocateDescriptorSets_SuboptimalReuse, |
| 649 | "%s Descriptor set memory was allocated via vkAllocateDescriptorSets() for sets which were previously freed in the " |
| 650 | "same logical device. On some drivers or architectures it may be most optimal to re-use existing descriptor sets.", |
| 651 | VendorSpecificTag(kBPVendorArm)); |
| 652 | } |
ziga-lunarg | 5a76c44 | 2022-04-17 18:04:08 +0200 | [diff] [blame] | 653 | |
| 654 | if (IsExtEnabled(device_extensions.vk_khr_maintenance1)) { |
| 655 | // Track number of descriptorSets allowable in this pool |
| 656 | if (pool_state->GetAvailableSets() < pAllocateInfo->descriptorSetCount) { |
| 657 | skip |= LogWarning(pool_state->Handle(), kVUID_BestPractices_EmptyDescriptorPool, |
| 658 | "vkAllocateDescriptorSets(): Unable to allocate %" PRIu32 " descriptorSets from %s" |
| 659 | ". This pool only has %" PRIu32 " descriptorSets remaining.", |
| 660 | pAllocateInfo->descriptorSetCount, report_data->FormatHandle(pool_state->Handle()).c_str(), |
| 661 | pool_state->GetAvailableSets()); |
| 662 | } |
| 663 | } |
Sam Walls | e746d52 | 2020-03-16 21:20:23 +0000 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | return skip; |
| 667 | } |
| 668 | |
Mark Lobodzinski | 84101d7 | 2020-04-24 09:43:48 -0600 | [diff] [blame] | 669 | void BestPractices::ManualPostCallRecordAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo* pAllocateInfo, |
| 670 | VkDescriptorSet* pDescriptorSets, VkResult result, void* ads_state) { |
Sam Walls | e746d52 | 2020-03-16 21:20:23 +0000 | [diff] [blame] | 671 | if (result == VK_SUCCESS) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 672 | auto pool_state = Get<bp_state::DescriptorPool>(pAllocateInfo->descriptorPool); |
| 673 | if (pool_state) { |
Sam Walls | e746d52 | 2020-03-16 21:20:23 +0000 | [diff] [blame] | 674 | // we record successful allocations by subtracting the allocation count from the last recorded free count |
| 675 | const auto alloc_count = pAllocateInfo->descriptorSetCount; |
| 676 | // clamp the unsigned subtraction to the range [0, last_free_count] |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 677 | if (pool_state->freed_count > alloc_count) { |
| 678 | pool_state->freed_count -= alloc_count; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 679 | } else { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 680 | pool_state->freed_count = 0; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 681 | } |
Sam Walls | e746d52 | 2020-03-16 21:20:23 +0000 | [diff] [blame] | 682 | } |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | void BestPractices::PostCallRecordFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t descriptorSetCount, |
| 687 | const VkDescriptorSet* pDescriptorSets, VkResult result) { |
| 688 | ValidationStateTracker::PostCallRecordFreeDescriptorSets(device, descriptorPool, descriptorSetCount, pDescriptorSets, result); |
| 689 | if (result == VK_SUCCESS) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 690 | auto pool_state = Get<bp_state::DescriptorPool>(descriptorPool); |
Sam Walls | e746d52 | 2020-03-16 21:20:23 +0000 | [diff] [blame] | 691 | // 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] | 692 | if (pool_state) { |
| 693 | pool_state->freed_count += descriptorSetCount; |
Sam Walls | e746d52 | 2020-03-16 21:20:23 +0000 | [diff] [blame] | 694 | } |
| 695 | } |
| 696 | } |
| 697 | |
Rodrigo Locatti | d5b54f5 | 2022-03-16 19:12:45 -0300 | [diff] [blame] | 698 | void BestPractices::PreCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo* pAllocateInfo, |
| 699 | const VkAllocationCallbacks* pAllocator, VkDeviceMemory* pMemory) { |
| 700 | if (VendorCheckEnabled(kBPVendorNVIDIA)) { |
| 701 | WriteLockGuard guard{memory_free_events_lock_}; |
| 702 | |
| 703 | // Release old allocations to avoid overpopulating the container |
| 704 | const auto now = std::chrono::high_resolution_clock::now(); |
| 705 | const auto last_old = std::find_if(memory_free_events_.rbegin(), memory_free_events_.rend(), [now](const MemoryFreeEvent& event) { |
| 706 | return now - event.time > kAllocateMemoryReuseTimeThresholdNVIDIA; |
| 707 | }); |
| 708 | memory_free_events_.erase(memory_free_events_.begin(), last_old.base()); |
| 709 | } |
| 710 | } |
| 711 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 712 | bool BestPractices::PreCallValidateAllocateMemory(VkDevice device, const VkMemoryAllocateInfo* pAllocateInfo, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 713 | const VkAllocationCallbacks* pAllocator, VkDeviceMemory* pMemory) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 714 | bool skip = false; |
| 715 | |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 716 | if ((Count<DEVICE_MEMORY_STATE>() + 1) > kMemoryObjectWarningLimit) { |
Mark Lobodzinski | f95a266 | 2020-01-29 15:43:32 -0700 | [diff] [blame] | 717 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_AllocateMemory_TooManyObjects, |
| 718 | "Performance Warning: This app has > %" PRIu32 " memory objects.", kMemoryObjectWarningLimit); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 719 | } |
| 720 | |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 721 | if (pAllocateInfo->allocationSize < kMinDeviceAllocationSize) { |
| 722 | skip |= LogPerformanceWarning( |
| 723 | device, kVUID_BestPractices_AllocateMemory_SmallAllocation, |
Jeremy Gebben | da6b48f | 2021-05-13 10:46:18 -0600 | [diff] [blame] | 724 | "vkAllocateMemory(): Allocating a VkDeviceMemory of size %" PRIu64 ". This is a very small allocation (current " |
| 725 | "threshold is %" PRIu64 " bytes). " |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 726 | "You should make large allocations and sub-allocate from one large VkDeviceMemory.", |
| 727 | pAllocateInfo->allocationSize, kMinDeviceAllocationSize); |
| 728 | } |
| 729 | |
Rodrigo Locatti | d5b54f5 | 2022-03-16 19:12:45 -0300 | [diff] [blame] | 730 | if (VendorCheckEnabled(kBPVendorNVIDIA)) { |
| 731 | if (!device_extensions.vk_ext_pageable_device_local_memory && |
| 732 | !LvlFindInChain<VkMemoryPriorityAllocateInfoEXT>(pAllocateInfo->pNext)) { |
| 733 | skip |= LogPerformanceWarning( |
| 734 | device, kVUID_BestPractices_AllocateMemory_SetPriority, |
| 735 | "%s Use VkMemoryPriorityAllocateInfoEXT to provide the operating system information on the allocations that " |
| 736 | "should stay in video memory and which should be demoted first when video memory is limited. " |
| 737 | "The highest priority should be given to GPU-written resources like color attachments, depth attachments, " |
| 738 | "storage images, and buffers written from the GPU.", |
| 739 | VendorSpecificTag(kBPVendorNVIDIA)); |
| 740 | } |
| 741 | |
| 742 | { |
| 743 | // Size in bytes for an allocation to be considered "compatible" |
| 744 | static constexpr VkDeviceSize size_threshold = VkDeviceSize{1} << 20; |
| 745 | |
| 746 | ReadLockGuard guard{memory_free_events_lock_}; |
| 747 | |
| 748 | const auto now = std::chrono::high_resolution_clock::now(); |
| 749 | const VkDeviceSize alloc_size = pAllocateInfo->allocationSize; |
| 750 | const uint32_t memory_type_index = pAllocateInfo->memoryTypeIndex; |
| 751 | const auto latest_event = std::find_if(memory_free_events_.rbegin(), memory_free_events_.rend(), [&](const MemoryFreeEvent& event) { |
| 752 | return (memory_type_index == event.memory_type_index) && (alloc_size <= event.allocation_size) && |
| 753 | (alloc_size - event.allocation_size <= size_threshold) && (now - event.time < kAllocateMemoryReuseTimeThresholdNVIDIA); |
| 754 | }); |
| 755 | |
| 756 | if (latest_event != memory_free_events_.rend()) { |
| 757 | const auto time_delta = std::chrono::duration_cast<std::chrono::milliseconds>(now - latest_event->time); |
| 758 | if (time_delta < std::chrono::milliseconds{5}) { |
| 759 | skip |= |
| 760 | LogPerformanceWarning(device, kVUID_BestPractices_AllocateMemory_ReuseAllocations, |
| 761 | "%s Reuse memory allocations instead of releasing and reallocating. A memory allocation " |
| 762 | "has just been released, and it could have been reused in place of this allocation.", |
| 763 | VendorSpecificTag(kBPVendorNVIDIA)); |
| 764 | } else { |
| 765 | const uint32_t seconds = static_cast<uint32_t>(time_delta.count() / 1000); |
| 766 | const uint32_t milliseconds = static_cast<uint32_t>(time_delta.count() % 1000); |
| 767 | |
| 768 | skip |= LogPerformanceWarning( |
| 769 | device, kVUID_BestPractices_AllocateMemory_ReuseAllocations, |
| 770 | "%s Reuse memory allocations instead of releasing and reallocating. A memory allocation has been released " |
| 771 | "%" PRIu32 ".%03" PRIu32 " seconds ago, and it could have been reused in place of this allocation.", |
| 772 | VendorSpecificTag(kBPVendorNVIDIA), seconds, milliseconds); |
| 773 | } |
| 774 | } |
| 775 | } |
Rodrigo Locatti | e4f8d52 | 2022-03-15 16:30:49 -0300 | [diff] [blame] | 776 | } |
| 777 | |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 778 | // TODO: Insert get check for GetPhysicalDeviceMemoryProperties once the state is tracked in the StateTracker |
| 779 | |
| 780 | return skip; |
| 781 | } |
| 782 | |
Mark Lobodzinski | 84101d7 | 2020-04-24 09:43:48 -0600 | [diff] [blame] | 783 | void BestPractices::ManualPostCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo* pAllocateInfo, |
| 784 | const VkAllocationCallbacks* pAllocator, VkDeviceMemory* pMemory, |
| 785 | VkResult result) { |
Mark Lobodzinski | 205b7a0 | 2020-02-21 13:23:17 -0700 | [diff] [blame] | 786 | if (result != VK_SUCCESS) { |
| 787 | static std::vector<VkResult> error_codes = {VK_ERROR_OUT_OF_HOST_MEMORY, VK_ERROR_OUT_OF_DEVICE_MEMORY, |
| 788 | VK_ERROR_TOO_MANY_OBJECTS, VK_ERROR_INVALID_EXTERNAL_HANDLE, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 789 | VK_ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS}; |
Mark Lobodzinski | 205b7a0 | 2020-02-21 13:23:17 -0700 | [diff] [blame] | 790 | static std::vector<VkResult> success_codes = {}; |
Nathaniel Cesario | db3f43f | 2021-05-12 09:08:23 -0600 | [diff] [blame] | 791 | ValidateReturnCodes("vkAllocateMemory", result, error_codes, success_codes); |
Mark Lobodzinski | 205b7a0 | 2020-02-21 13:23:17 -0700 | [diff] [blame] | 792 | return; |
| 793 | } |
Mark Lobodzinski | 205b7a0 | 2020-02-21 13:23:17 -0700 | [diff] [blame] | 794 | } |
Camden Stocker | 9738af9 | 2019-10-16 13:54:03 -0700 | [diff] [blame] | 795 | |
Mark Lobodzinski | de15e58 | 2020-04-29 08:06:00 -0600 | [diff] [blame] | 796 | void BestPractices::ValidateReturnCodes(const char* api_name, VkResult result, const std::vector<VkResult>& error_codes, |
| 797 | const std::vector<VkResult>& success_codes) const { |
Mark Lobodzinski | 205b7a0 | 2020-02-21 13:23:17 -0700 | [diff] [blame] | 798 | auto error = std::find(error_codes.begin(), error_codes.end(), result); |
| 799 | if (error != error_codes.end()) { |
Gareth Webb | 586c46b | 2021-01-13 11:17:22 +0000 | [diff] [blame] | 800 | static const std::vector<VkResult> common_failure_codes = {VK_ERROR_OUT_OF_DATE_KHR, |
| 801 | VK_ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXT}; |
| 802 | |
| 803 | auto common_failure = std::find(common_failure_codes.begin(), common_failure_codes.end(), result); |
| 804 | if (common_failure != common_failure_codes.end()) { |
| 805 | LogInfo(instance, kVUID_BestPractices_Failure_Result, "%s(): Returned error %s.", api_name, string_VkResult(result)); |
| 806 | } else { |
| 807 | LogWarning(instance, kVUID_BestPractices_Error_Result, "%s(): Returned error %s.", api_name, string_VkResult(result)); |
| 808 | } |
Mark Lobodzinski | 205b7a0 | 2020-02-21 13:23:17 -0700 | [diff] [blame] | 809 | return; |
| 810 | } |
| 811 | auto success = std::find(success_codes.begin(), success_codes.end(), result); |
| 812 | if (success != success_codes.end()) { |
Mark Lobodzinski | e721515 | 2020-05-11 08:21:23 -0600 | [diff] [blame] | 813 | LogInfo(instance, kVUID_BestPractices_NonSuccess_Result, "%s(): Returned non-success return code %s.", api_name, |
| 814 | string_VkResult(result)); |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 815 | } |
| 816 | } |
| 817 | |
Rodrigo Locatti | d5b54f5 | 2022-03-16 19:12:45 -0300 | [diff] [blame] | 818 | void BestPractices::PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory memory, const VkAllocationCallbacks* pAllocator) { |
| 819 | if (memory != VK_NULL_HANDLE && VendorCheckEnabled(kBPVendorNVIDIA)) { |
| 820 | auto mem_info = Get<DEVICE_MEMORY_STATE>(memory); |
| 821 | |
| 822 | // Exclude memory free events on dedicated allocations, or imported/exported allocations. |
| 823 | if (!mem_info->IsDedicatedBuffer() && !mem_info->IsDedicatedImage() && !mem_info->IsExport() && !mem_info->IsImport()) { |
| 824 | MemoryFreeEvent event; |
| 825 | event.time = std::chrono::high_resolution_clock::now(); |
| 826 | event.memory_type_index = mem_info->alloc_info.memoryTypeIndex; |
| 827 | event.allocation_size = mem_info->alloc_info.allocationSize; |
| 828 | |
| 829 | WriteLockGuard guard{memory_free_events_lock_}; |
| 830 | memory_free_events_.push_back(event); |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | ValidationStateTracker::PreCallRecordFreeMemory(device, memory, pAllocator); |
| 835 | } |
| 836 | |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 837 | bool BestPractices::PreCallValidateFreeMemory(VkDevice device, VkDeviceMemory memory, |
| 838 | const VkAllocationCallbacks* pAllocator) const { |
Mark Lobodzinski | 91e50bf | 2020-01-14 09:55:11 -0700 | [diff] [blame] | 839 | if (memory == VK_NULL_HANDLE) return false; |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 840 | bool skip = false; |
| 841 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 842 | auto mem_info = Get<DEVICE_MEMORY_STATE>(memory); |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 843 | |
Jeremy Gebben | 610d3a6 | 2022-01-01 12:53:17 -0700 | [diff] [blame] | 844 | for (const auto& item : mem_info->ObjectBindings()) { |
| 845 | const auto& obj = item.first; |
Mark Lobodzinski | 818425a | 2020-03-16 18:19:03 -0600 | [diff] [blame] | 846 | LogObjectList objlist(device); |
| 847 | objlist.add(obj); |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 848 | objlist.add(mem_info->mem()); |
Mark Lobodzinski | 818425a | 2020-03-16 18:19:03 -0600 | [diff] [blame] | 849 | 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] | 850 | 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] | 851 | } |
| 852 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 853 | return skip; |
| 854 | } |
| 855 | |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 856 | bool BestPractices::ValidateBindBufferMemory(VkBuffer buffer, VkDeviceMemory memory, const char* api_name) const { |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 857 | bool skip = false; |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 858 | auto buffer_state = Get<BUFFER_STATE>(buffer); |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 859 | |
sfricke-samsung | e244119 | 2019-11-06 14:07:57 -0800 | [diff] [blame] | 860 | if (!buffer_state->memory_requirements_checked && !buffer_state->external_memory_handle) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 861 | skip |= LogWarning(device, kVUID_BestPractices_BufferMemReqNotCalled, |
| 862 | "%s: Binding memory to %s but vkGetBufferMemoryRequirements() has not been called on that buffer.", |
| 863 | api_name, report_data->FormatHandle(buffer).c_str()); |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 864 | } |
| 865 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 866 | auto mem_state = Get<DEVICE_MEMORY_STATE>(memory); |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 867 | |
AndreyVK_D3D | 0416a33 | 2021-11-02 23:22:28 +0300 | [diff] [blame] | 868 | if (mem_state && mem_state->alloc_info.allocationSize == buffer_state->createInfo.size && |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 869 | mem_state->alloc_info.allocationSize < kMinDedicatedAllocationSize) { |
| 870 | skip |= LogPerformanceWarning( |
| 871 | device, kVUID_BestPractices_SmallDedicatedAllocation, |
| 872 | "%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] | 873 | "The required size of the allocation is %" PRIu64 ", but smaller buffers like this should be sub-allocated from " |
| 874 | "larger memory blocks. (Current threshold is %" PRIu64 " bytes.)", |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 875 | api_name, report_data->FormatHandle(buffer).c_str(), mem_state->alloc_info.allocationSize, kMinDedicatedAllocationSize); |
| 876 | } |
| 877 | |
Rodrigo Locatti | 66b2335 | 2022-03-15 17:28:32 -0300 | [diff] [blame] | 878 | skip |= ValidateBindMemory(device, memory); |
| 879 | |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 880 | return skip; |
| 881 | } |
| 882 | |
| 883 | bool BestPractices::PreCallValidateBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory memory, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 884 | VkDeviceSize memoryOffset) const { |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 885 | bool skip = false; |
| 886 | const char* api_name = "BindBufferMemory()"; |
| 887 | |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 888 | skip |= ValidateBindBufferMemory(buffer, memory, api_name); |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 889 | |
| 890 | return skip; |
| 891 | } |
| 892 | |
| 893 | bool BestPractices::PreCallValidateBindBufferMemory2(VkDevice device, uint32_t bindInfoCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 894 | const VkBindBufferMemoryInfo* pBindInfos) const { |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 895 | char api_name[64]; |
| 896 | bool skip = false; |
| 897 | |
| 898 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
Frédéric Wang | afb8986 | 2022-06-21 16:15:29 +0200 | [diff] [blame] | 899 | snprintf(api_name, sizeof(api_name), "vkBindBufferMemory2() pBindInfos[%u]", i); |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 900 | skip |= ValidateBindBufferMemory(pBindInfos[i].buffer, pBindInfos[i].memory, api_name); |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 901 | } |
| 902 | |
| 903 | return skip; |
| 904 | } |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 905 | |
| 906 | bool BestPractices::PreCallValidateBindBufferMemory2KHR(VkDevice device, uint32_t bindInfoCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 907 | const VkBindBufferMemoryInfo* pBindInfos) const { |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 908 | char api_name[64]; |
| 909 | bool skip = false; |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 910 | |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 911 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
Frédéric Wang | afb8986 | 2022-06-21 16:15:29 +0200 | [diff] [blame] | 912 | snprintf(api_name, sizeof(api_name), "vkBindBufferMemory2KHR() pBindInfos[%u]", i); |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 913 | skip |= ValidateBindBufferMemory(pBindInfos[i].buffer, pBindInfos[i].memory, api_name); |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 914 | } |
| 915 | |
| 916 | return skip; |
| 917 | } |
| 918 | |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 919 | bool BestPractices::ValidateBindImageMemory(VkImage image, VkDeviceMemory memory, const char* api_name) const { |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 920 | bool skip = false; |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 921 | auto image_state = Get<IMAGE_STATE>(image); |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 922 | |
sfricke-samsung | 71bc657 | 2020-04-29 15:49:43 -0700 | [diff] [blame] | 923 | if (image_state->disjoint == false) { |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 924 | if (!image_state->memory_requirements_checked[0] && !image_state->external_memory_handle) { |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 925 | skip |= LogWarning(device, kVUID_BestPractices_ImageMemReqNotCalled, |
| 926 | "%s: Binding memory to %s but vkGetImageMemoryRequirements() has not been called on that image.", |
| 927 | api_name, report_data->FormatHandle(image).c_str()); |
| 928 | } |
| 929 | } else { |
| 930 | // TODO If binding disjoint image then this needs to check that VkImagePlaneMemoryRequirementsInfo was called for each |
| 931 | // plane. |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 932 | } |
| 933 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 934 | auto mem_state = Get<DEVICE_MEMORY_STATE>(memory); |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 935 | |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 936 | if (mem_state->alloc_info.allocationSize == image_state->requirements[0].size && |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 937 | mem_state->alloc_info.allocationSize < kMinDedicatedAllocationSize) { |
| 938 | skip |= LogPerformanceWarning( |
| 939 | device, kVUID_BestPractices_SmallDedicatedAllocation, |
| 940 | "%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] | 941 | "The required size of the allocation is %" PRIu64 ", but smaller images like this should be sub-allocated from " |
| 942 | "larger memory blocks. (Current threshold is %" PRIu64 " bytes.)", |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 943 | api_name, report_data->FormatHandle(image).c_str(), mem_state->alloc_info.allocationSize, kMinDedicatedAllocationSize); |
| 944 | } |
| 945 | |
| 946 | // If we're binding memory to a image which was created as TRANSIENT and the image supports LAZY allocation, |
| 947 | // make sure this type is actually used. |
| 948 | // This warning will only trigger if this layer is run on a platform that supports LAZILY_ALLOCATED_BIT |
| 949 | // (i.e.most tile - based renderers) |
| 950 | if (image_state->createInfo.usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) { |
| 951 | bool supports_lazy = false; |
| 952 | uint32_t suggested_type = 0; |
| 953 | |
| 954 | for (uint32_t i = 0; i < phys_dev_mem_props.memoryTypeCount; i++) { |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 955 | if ((1u << i) & image_state->requirements[0].memoryTypeBits) { |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 956 | if (phys_dev_mem_props.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) { |
| 957 | supports_lazy = true; |
| 958 | suggested_type = i; |
| 959 | break; |
| 960 | } |
| 961 | } |
| 962 | } |
| 963 | |
| 964 | uint32_t allocated_properties = phys_dev_mem_props.memoryTypes[mem_state->alloc_info.memoryTypeIndex].propertyFlags; |
| 965 | |
| 966 | if (supports_lazy && (allocated_properties & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) == 0) { |
| 967 | skip |= LogPerformanceWarning( |
| 968 | device, kVUID_BestPractices_NonLazyTransientImage, |
Jeremy Gebben | da6b48f | 2021-05-13 10:46:18 -0600 | [diff] [blame] | 969 | "%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] | 970 | "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] | 971 | "%" PRIu64 " bytes of physical memory.", |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 972 | 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] | 973 | } |
| 974 | } |
| 975 | |
Rodrigo Locatti | 66b2335 | 2022-03-15 17:28:32 -0300 | [diff] [blame] | 976 | skip |= ValidateBindMemory(device, memory); |
| 977 | |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 978 | return skip; |
| 979 | } |
| 980 | |
| 981 | bool BestPractices::PreCallValidateBindImageMemory(VkDevice device, VkImage image, VkDeviceMemory memory, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 982 | VkDeviceSize memoryOffset) const { |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 983 | bool skip = false; |
| 984 | const char* api_name = "vkBindImageMemory()"; |
| 985 | |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 986 | skip |= ValidateBindImageMemory(image, memory, api_name); |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 987 | |
| 988 | return skip; |
| 989 | } |
| 990 | |
| 991 | bool BestPractices::PreCallValidateBindImageMemory2(VkDevice device, uint32_t bindInfoCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 992 | const VkBindImageMemoryInfo* pBindInfos) const { |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 993 | char api_name[64]; |
| 994 | bool skip = false; |
| 995 | |
| 996 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
Frédéric Wang | afb8986 | 2022-06-21 16:15:29 +0200 | [diff] [blame] | 997 | snprintf(api_name, sizeof(api_name), "vkBindImageMemory2() pBindInfos[%u]", i); |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 998 | if (!LvlFindInChain<VkBindImageMemorySwapchainInfoKHR>(pBindInfos[i].pNext)) { |
Tony-LunarG | 5e60b85 | 2020-04-27 11:27:54 -0600 | [diff] [blame] | 999 | skip |= ValidateBindImageMemory(pBindInfos[i].image, pBindInfos[i].memory, api_name); |
| 1000 | } |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | return skip; |
| 1004 | } |
| 1005 | |
| 1006 | bool BestPractices::PreCallValidateBindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1007 | const VkBindImageMemoryInfo* pBindInfos) const { |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 1008 | char api_name[64]; |
| 1009 | bool skip = false; |
| 1010 | |
| 1011 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
Frédéric Wang | afb8986 | 2022-06-21 16:15:29 +0200 | [diff] [blame] | 1012 | snprintf(api_name, sizeof(api_name), "vkBindImageMemory2KHR() pBindInfos[%u]", i); |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 1013 | skip |= ValidateBindImageMemory(pBindInfos[i].image, pBindInfos[i].memory, api_name); |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 1014 | } |
| 1015 | |
| 1016 | return skip; |
| 1017 | } |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 1018 | |
Rodrigo Locatti | 66b2335 | 2022-03-15 17:28:32 -0300 | [diff] [blame] | 1019 | void BestPractices::PreCallRecordSetDeviceMemoryPriorityEXT(VkDevice device, VkDeviceMemory memory, float priority) { |
| 1020 | auto mem_info = std::static_pointer_cast<bp_state::DeviceMemory>(Get<DEVICE_MEMORY_STATE>(memory)); |
| 1021 | mem_info->dynamic_priority.emplace(priority); |
| 1022 | } |
| 1023 | |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1024 | static inline bool FormatHasFullThroughputBlendingArm(VkFormat format) { |
| 1025 | switch (format) { |
| 1026 | case VK_FORMAT_B10G11R11_UFLOAT_PACK32: |
| 1027 | case VK_FORMAT_R16_SFLOAT: |
| 1028 | case VK_FORMAT_R16G16_SFLOAT: |
| 1029 | case VK_FORMAT_R16G16B16_SFLOAT: |
| 1030 | case VK_FORMAT_R16G16B16A16_SFLOAT: |
| 1031 | case VK_FORMAT_R32_SFLOAT: |
| 1032 | case VK_FORMAT_R32G32_SFLOAT: |
| 1033 | case VK_FORMAT_R32G32B32_SFLOAT: |
| 1034 | case VK_FORMAT_R32G32B32A32_SFLOAT: |
| 1035 | return false; |
| 1036 | |
| 1037 | default: |
| 1038 | return true; |
| 1039 | } |
| 1040 | } |
| 1041 | |
| 1042 | bool BestPractices::ValidateMultisampledBlendingArm(uint32_t createInfoCount, |
| 1043 | const VkGraphicsPipelineCreateInfo* pCreateInfos) const { |
| 1044 | bool skip = false; |
| 1045 | |
| 1046 | for (uint32_t i = 0; i < createInfoCount; i++) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1047 | auto create_info = &pCreateInfos[i]; |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1048 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1049 | if (!create_info->pColorBlendState || !create_info->pMultisampleState || |
| 1050 | create_info->pMultisampleState->rasterizationSamples == VK_SAMPLE_COUNT_1_BIT || |
| 1051 | create_info->pMultisampleState->sampleShadingEnable) { |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1052 | return skip; |
| 1053 | } |
| 1054 | |
Jeremy Gebben | b20a824 | 2021-11-05 15:14:43 -0600 | [diff] [blame] | 1055 | auto rp_state = Get<RENDER_PASS_STATE>(create_info->renderPass); |
Hans-Kristian Arntzen | 69ace7d | 2021-04-28 14:17:19 +0200 | [diff] [blame] | 1056 | const auto& subpass = rp_state->createInfo.pSubpasses[create_info->subpass]; |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1057 | |
Hans-Kristian Arntzen | c2742e7 | 2021-07-01 14:31:06 +0200 | [diff] [blame] | 1058 | // According to spec, pColorBlendState must be ignored if subpass does not have color attachments. |
| 1059 | uint32_t num_color_attachments = std::min(subpass.colorAttachmentCount, create_info->pColorBlendState->attachmentCount); |
| 1060 | |
| 1061 | for (uint32_t j = 0; j < num_color_attachments; j++) { |
Hans-Kristian Arntzen | 69ace7d | 2021-04-28 14:17:19 +0200 | [diff] [blame] | 1062 | const auto& blend_att = create_info->pColorBlendState->pAttachments[j]; |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1063 | uint32_t att = subpass.pColorAttachments[j].attachment; |
| 1064 | |
| 1065 | if (att != VK_ATTACHMENT_UNUSED && blend_att.blendEnable && blend_att.colorWriteMask) { |
| 1066 | if (!FormatHasFullThroughputBlendingArm(rp_state->createInfo.pAttachments[att].format)) { |
| 1067 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_CreatePipelines_MultisampledBlending, |
| 1068 | "%s vkCreateGraphicsPipelines() - createInfo #%u: Pipeline is multisampled and " |
| 1069 | "color attachment #%u makes use " |
| 1070 | "of a format which cannot be blended at full throughput when using MSAA.", |
| 1071 | VendorSpecificTag(kBPVendorArm), i, j); |
| 1072 | } |
| 1073 | } |
| 1074 | } |
| 1075 | } |
| 1076 | |
| 1077 | return skip; |
| 1078 | } |
| 1079 | |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 1080 | void BestPractices::ManualPostCallRecordCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount, |
| 1081 | const VkComputePipelineCreateInfo* pCreateInfos, |
| 1082 | const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines, |
| 1083 | VkResult result, void* pipe_state) { |
| 1084 | // AMD best practice |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 1085 | pipeline_cache_ = pipelineCache; |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 1086 | } |
| 1087 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1088 | bool BestPractices::PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount, |
| 1089 | const VkGraphicsPipelineCreateInfo* pCreateInfos, |
Mark Lobodzinski | 2a162a0 | 2019-09-06 11:02:12 -0600 | [diff] [blame] | 1090 | const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1091 | void* cgpl_state_data) const { |
Mark Lobodzinski | 8317a3e | 2019-09-20 10:07:08 -0600 | [diff] [blame] | 1092 | bool skip = StateTracker::PreCallValidateCreateGraphicsPipelines(device, pipelineCache, createInfoCount, pCreateInfos, |
| 1093 | pAllocator, pPipelines, cgpl_state_data); |
ziga-lunarg | 08c8158 | 2022-03-08 17:33:45 +0100 | [diff] [blame] | 1094 | if (skip) { |
| 1095 | return skip; |
| 1096 | } |
Mark Lobodzinski | 8dd14d8 | 2020-04-10 14:16:33 -0600 | [diff] [blame] | 1097 | 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] | 1098 | |
| 1099 | if ((createInfoCount > 1) && (!pipelineCache)) { |
Mark Lobodzinski | f95a266 | 2020-01-29 15:43:32 -0700 | [diff] [blame] | 1100 | skip |= LogPerformanceWarning( |
| 1101 | device, kVUID_BestPractices_CreatePipelines_MultiplePipelines, |
| 1102 | "Performance Warning: This vkCreateGraphicsPipelines call is creating multiple pipelines but is not using a " |
| 1103 | "pipeline cache, which may help with performance"); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1104 | } |
| 1105 | |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 1106 | for (uint32_t i = 0; i < createInfoCount; i++) { |
Hans-Kristian Arntzen | 69ace7d | 2021-04-28 14:17:19 +0200 | [diff] [blame] | 1107 | const auto& create_info = pCreateInfos[i]; |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 1108 | |
Tony-LunarG | b6a2daf | 2022-07-29 11:30:55 -0600 | [diff] [blame] | 1109 | 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] | 1110 | const auto& vertex_input = *create_info.pVertexInputState; |
Mark Lobodzinski | 8dd14d8 | 2020-04-10 14:16:33 -0600 | [diff] [blame] | 1111 | uint32_t count = 0; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1112 | for (uint32_t j = 0; j < vertex_input.vertexBindingDescriptionCount; j++) { |
| 1113 | if (vertex_input.pVertexBindingDescriptions[j].inputRate == VK_VERTEX_INPUT_RATE_INSTANCE) { |
Mark Lobodzinski | 8dd14d8 | 2020-04-10 14:16:33 -0600 | [diff] [blame] | 1114 | count++; |
| 1115 | } |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 1116 | } |
Mark Lobodzinski | 8dd14d8 | 2020-04-10 14:16:33 -0600 | [diff] [blame] | 1117 | if (count > kMaxInstancedVertexBuffers) { |
| 1118 | skip |= LogPerformanceWarning( |
| 1119 | device, kVUID_BestPractices_CreatePipelines_TooManyInstancedVertexBuffers, |
| 1120 | "The pipeline is using %u instanced vertex buffers (current limit: %u), but this can be inefficient on the " |
| 1121 | "GPU. If using instanced vertex attributes prefer interleaving them in a single buffer.", |
| 1122 | count, kMaxInstancedVertexBuffers); |
| 1123 | } |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 1124 | } |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1125 | |
Szilard Papp | aaf2da3 | 2020-06-22 10:37:35 +0100 | [diff] [blame] | 1126 | if ((pCreateInfos[i].pRasterizationState->depthBiasEnable) && |
| 1127 | (pCreateInfos[i].pRasterizationState->depthBiasConstantFactor == 0.0f) && |
Hans-Kristian Arntzen | b214795 | 2021-04-28 14:32:00 +0200 | [diff] [blame] | 1128 | (pCreateInfos[i].pRasterizationState->depthBiasSlopeFactor == 0.0f) && |
| 1129 | VendorCheckEnabled(kBPVendorArm)) { |
| 1130 | skip |= LogPerformanceWarning( |
| 1131 | device, kVUID_BestPractices_CreatePipelines_DepthBias_Zero, |
| 1132 | "%s Performance Warning: This vkCreateGraphicsPipelines call is created with depthBiasEnable set to true " |
| 1133 | "and both depthBiasConstantFactor and depthBiasSlopeFactor are set to 0. This can cause reduced " |
| 1134 | "efficiency during rasterization. Consider disabling depthBias or increasing either " |
| 1135 | "depthBiasConstantFactor or depthBiasSlopeFactor.", |
| 1136 | VendorSpecificTag(kBPVendorArm)); |
Szilard Papp | aaf2da3 | 2020-06-22 10:37:35 +0100 | [diff] [blame] | 1137 | } |
| 1138 | |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1139 | skip |= VendorCheckEnabled(kBPVendorArm) && ValidateMultisampledBlendingArm(createInfoCount, pCreateInfos); |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 1140 | } |
Rodrigo Locatti | 494e448 | 2022-03-30 16:37:40 -0300 | [diff] [blame] | 1141 | if (VendorCheckEnabled(kBPVendorAMD) || VendorCheckEnabled(kBPVendorNVIDIA)) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 1142 | auto prev_pipeline = pipeline_cache_.load(); |
| 1143 | if (pipelineCache && prev_pipeline && pipelineCache != prev_pipeline) { |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 1144 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_CreatePipelines_MultiplePipelineCaches, |
Rodrigo Locatti | 494e448 | 2022-03-30 16:37:40 -0300 | [diff] [blame] | 1145 | "%s %s Performance Warning: A second pipeline cache is in use. " |
| 1146 | "Consider using only one pipeline cache to improve cache hit rate.", |
| 1147 | VendorSpecificTag(kBPVendorAMD), VendorSpecificTag(kBPVendorNVIDIA)); |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 1148 | } |
Rodrigo Locatti | 494e448 | 2022-03-30 16:37:40 -0300 | [diff] [blame] | 1149 | } |
| 1150 | if (VendorCheckEnabled(kBPVendorAMD)) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 1151 | if (num_pso_ > kMaxRecommendedNumberOfPSOAMD) { |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 1152 | skip |= |
| 1153 | LogPerformanceWarning(device, kVUID_BestPractices_CreatePipelines_TooManyPipelines, |
| 1154 | "%s Performance warning: Too many pipelines created, consider consolidation", |
| 1155 | VendorSpecificTag(kBPVendorAMD)); |
| 1156 | } |
| 1157 | |
Nathaniel Cesario | 1a7e1a9 | 2021-08-30 14:34:20 -0600 | [diff] [blame] | 1158 | if (pCreateInfos->pInputAssemblyState && pCreateInfos->pInputAssemblyState->primitiveRestartEnable) { |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 1159 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_CreatePipelines_AvoidPrimitiveRestart, |
| 1160 | "%s Performance warning: Use of primitive restart is not recommended", |
| 1161 | VendorSpecificTag(kBPVendorAMD)); |
| 1162 | } |
| 1163 | |
| 1164 | // TODO: this might be too aggressive of a check |
| 1165 | if (pCreateInfos->pDynamicState && pCreateInfos->pDynamicState->dynamicStateCount > kDynamicStatesWarningLimitAMD) { |
| 1166 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_CreatePipelines_MinimizeNumDynamicStates, |
| 1167 | "%s Performance warning: Dynamic States usage incurs a performance cost. Ensure that they are truly needed", |
| 1168 | VendorSpecificTag(kBPVendorAMD)); |
| 1169 | } |
| 1170 | } |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 1171 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1172 | return skip; |
| 1173 | } |
| 1174 | |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 1175 | static std::vector<bp_state::AttachmentInfo> GetAttachmentAccess(const safe_VkGraphicsPipelineCreateInfo& create_info, |
| 1176 | std::shared_ptr<const RENDER_PASS_STATE>& rp) { |
| 1177 | std::vector<bp_state::AttachmentInfo> result; |
Jeremy Gebben | b5dda54 | 2022-08-02 14:26:20 -0600 | [diff] [blame] | 1178 | if (!rp || rp->UsesDynamicRendering()) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 1179 | return result; |
Hans-Kristian Arntzen | b033ab1 | 2021-06-16 11:16:59 +0200 | [diff] [blame] | 1180 | } |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 1181 | |
| 1182 | const auto& subpass = rp->createInfo.pSubpasses[create_info.subpass]; |
| 1183 | |
| 1184 | // NOTE: see PIPELINE_LAYOUT and safe_VkGraphicsPipelineCreateInfo constructors. pColorBlendState and pDepthStencilState |
| 1185 | // are only non-null if they are enabled. |
| 1186 | if (create_info.pColorBlendState) { |
| 1187 | // According to spec, pColorBlendState must be ignored if subpass does not have color attachments. |
| 1188 | uint32_t num_color_attachments = std::min(subpass.colorAttachmentCount, create_info.pColorBlendState->attachmentCount); |
| 1189 | for (uint32_t j = 0; j < num_color_attachments; j++) { |
| 1190 | if (create_info.pColorBlendState->pAttachments[j].colorWriteMask != 0) { |
| 1191 | uint32_t attachment = subpass.pColorAttachments[j].attachment; |
| 1192 | if (attachment != VK_ATTACHMENT_UNUSED) { |
| 1193 | result.push_back({attachment, VK_IMAGE_ASPECT_COLOR_BIT}); |
| 1194 | } |
| 1195 | } |
| 1196 | } |
| 1197 | } |
| 1198 | |
| 1199 | if (create_info.pDepthStencilState && |
| 1200 | (create_info.pDepthStencilState->depthTestEnable || create_info.pDepthStencilState->depthBoundsTestEnable || |
| 1201 | create_info.pDepthStencilState->stencilTestEnable)) { |
| 1202 | uint32_t attachment = subpass.pDepthStencilAttachment ? subpass.pDepthStencilAttachment->attachment : VK_ATTACHMENT_UNUSED; |
| 1203 | if (attachment != VK_ATTACHMENT_UNUSED) { |
| 1204 | VkImageAspectFlags aspects = 0; |
| 1205 | if (create_info.pDepthStencilState->depthTestEnable || create_info.pDepthStencilState->depthBoundsTestEnable) { |
| 1206 | aspects |= VK_IMAGE_ASPECT_DEPTH_BIT; |
| 1207 | } |
| 1208 | if (create_info.pDepthStencilState->stencilTestEnable) { |
| 1209 | aspects |= VK_IMAGE_ASPECT_STENCIL_BIT; |
| 1210 | } |
| 1211 | result.push_back({attachment, aspects}); |
| 1212 | } |
| 1213 | } |
| 1214 | return result; |
| 1215 | } |
| 1216 | |
| 1217 | bp_state::Pipeline::Pipeline(const ValidationStateTracker* state_data, const VkGraphicsPipelineCreateInfo* pCreateInfo, |
| 1218 | std::shared_ptr<const RENDER_PASS_STATE>&& rpstate, |
| 1219 | std::shared_ptr<const PIPELINE_LAYOUT_STATE>&& layout) |
| 1220 | : PIPELINE_STATE(state_data, pCreateInfo, std::move(rpstate), std::move(layout)), |
| 1221 | access_framebuffer_attachments(GetAttachmentAccess(create_info.graphics, rp_state)) {} |
| 1222 | |
| 1223 | std::shared_ptr<PIPELINE_STATE> BestPractices::CreateGraphicsPipelineState( |
| 1224 | const VkGraphicsPipelineCreateInfo* pCreateInfo, std::shared_ptr<const RENDER_PASS_STATE>&& render_pass, |
| 1225 | std::shared_ptr<const PIPELINE_LAYOUT_STATE>&& layout) const { |
| 1226 | return std::static_pointer_cast<PIPELINE_STATE>( |
| 1227 | 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] | 1228 | } |
| 1229 | |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1230 | void BestPractices::ManualPostCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, |
| 1231 | const VkGraphicsPipelineCreateInfo* pCreateInfos, |
| 1232 | const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines, |
| 1233 | VkResult result, void* cgpl_state_data) { |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 1234 | // AMD best practice |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 1235 | pipeline_cache_ = pipelineCache; |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1236 | } |
| 1237 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1238 | bool BestPractices::PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount, |
| 1239 | const VkComputePipelineCreateInfo* pCreateInfos, |
Mark Lobodzinski | 2a162a0 | 2019-09-06 11:02:12 -0600 | [diff] [blame] | 1240 | const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1241 | void* ccpl_state_data) const { |
Mark Lobodzinski | 8317a3e | 2019-09-20 10:07:08 -0600 | [diff] [blame] | 1242 | bool skip = StateTracker::PreCallValidateCreateComputePipelines(device, pipelineCache, createInfoCount, pCreateInfos, |
| 1243 | pAllocator, pPipelines, ccpl_state_data); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1244 | |
| 1245 | if ((createInfoCount > 1) && (!pipelineCache)) { |
Mark Lobodzinski | f95a266 | 2020-01-29 15:43:32 -0700 | [diff] [blame] | 1246 | skip |= LogPerformanceWarning( |
| 1247 | device, kVUID_BestPractices_CreatePipelines_MultiplePipelines, |
| 1248 | "Performance Warning: This vkCreateComputePipelines call is creating multiple pipelines but is not using a " |
| 1249 | "pipeline cache, which may help with performance"); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1250 | } |
| 1251 | |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 1252 | if (VendorCheckEnabled(kBPVendorAMD)) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 1253 | auto prev_pipeline = pipeline_cache_.load(); |
| 1254 | if (pipelineCache && prev_pipeline && pipelineCache != prev_pipeline) { |
| 1255 | skip |= LogPerformanceWarning( |
| 1256 | device, kVUID_BestPractices_CreatePipelines_MultiplePipelines, |
| 1257 | "%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] | 1258 | "improve cache hit rate", |
| 1259 | VendorSpecificTag(kBPVendorAMD)); |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 1260 | } |
| 1261 | } |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 1262 | |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 1263 | for (uint32_t i = 0; i < createInfoCount; i++) { |
| 1264 | const VkComputePipelineCreateInfo& createInfo = pCreateInfos[i]; |
| 1265 | if (VendorCheckEnabled(kBPVendorArm)) { |
| 1266 | skip |= ValidateCreateComputePipelineArm(createInfo); |
| 1267 | } |
sfricke-samsung | 86d055a | 2022-02-11 14:43:50 -0800 | [diff] [blame] | 1268 | |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 1269 | if (IsExtEnabled(device_extensions.vk_khr_maintenance4)) { |
| 1270 | auto module_state = Get<SHADER_MODULE_STATE>(createInfo.stage.module); |
| 1271 | for (const auto& builtin : module_state->static_data_.builtin_decoration_list) { |
| 1272 | if (builtin.builtin == spv::BuiltInWorkgroupSize) { |
| 1273 | skip |= LogWarning(device, kVUID_BestPractices_SpirvDeprecated_WorkgroupSize, |
| 1274 | "vkCreateComputePipelines(): pCreateInfos[ %" PRIu32 |
| 1275 | "] is using the Workgroup built-in which SPIR-V 1.6 deprecated. The VK_KHR_maintenance4 " |
| 1276 | "extension exposes a new LocalSizeId execution mode that should be used instead.", |
| 1277 | i); |
sfricke-samsung | 86d055a | 2022-02-11 14:43:50 -0800 | [diff] [blame] | 1278 | } |
| 1279 | } |
Sam Walls | d7ab6db | 2020-06-19 20:41:54 +0100 | [diff] [blame] | 1280 | } |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 1281 | } |
Sam Walls | d7ab6db | 2020-06-19 20:41:54 +0100 | [diff] [blame] | 1282 | |
| 1283 | return skip; |
| 1284 | } |
| 1285 | |
| 1286 | bool BestPractices::ValidateCreateComputePipelineArm(const VkComputePipelineCreateInfo& createInfo) const { |
| 1287 | bool skip = false; |
sfricke-samsung | ef15e48 | 2022-01-26 11:32:49 -0800 | [diff] [blame] | 1288 | auto module_state = Get<SHADER_MODULE_STATE>(createInfo.stage.module); |
sfricke-samsung | 8a7341a | 2021-02-28 07:30:21 -0800 | [diff] [blame] | 1289 | // Generate warnings about work group sizes based on active resources. |
sfricke-samsung | ef15e48 | 2022-01-26 11:32:49 -0800 | [diff] [blame] | 1290 | auto entrypoint = module_state->FindEntrypoint(createInfo.stage.pName, createInfo.stage.stage); |
| 1291 | if (entrypoint == module_state->end()) return false; |
Sam Walls | d7ab6db | 2020-06-19 20:41:54 +0100 | [diff] [blame] | 1292 | |
| 1293 | uint32_t x = 1, y = 1, z = 1; |
sfricke-samsung | ef15e48 | 2022-01-26 11:32:49 -0800 | [diff] [blame] | 1294 | module_state->FindLocalSize(entrypoint, x, y, z); |
Sam Walls | d7ab6db | 2020-06-19 20:41:54 +0100 | [diff] [blame] | 1295 | |
| 1296 | uint32_t thread_count = x * y * z; |
| 1297 | |
| 1298 | // Generate a priori warnings about work group sizes. |
| 1299 | if (thread_count > kMaxEfficientWorkGroupThreadCountArm) { |
| 1300 | skip |= LogPerformanceWarning( |
| 1301 | device, kVUID_BestPractices_CreateComputePipelines_ComputeWorkGroupSize, |
| 1302 | "%s vkCreateComputePipelines(): compute shader with work group dimensions (%u, %u, " |
| 1303 | "%u) (%u threads total), has more threads than advised in a single work group. It is advised to use work " |
| 1304 | "groups with less than %u threads, especially when using barrier() or shared memory.", |
| 1305 | VendorSpecificTag(kBPVendorArm), x, y, z, thread_count, kMaxEfficientWorkGroupThreadCountArm); |
| 1306 | } |
| 1307 | |
| 1308 | if (thread_count == 1 || ((x > 1) && (x & (kThreadGroupDispatchCountAlignmentArm - 1))) || |
| 1309 | ((y > 1) && (y & (kThreadGroupDispatchCountAlignmentArm - 1))) || |
| 1310 | ((z > 1) && (z & (kThreadGroupDispatchCountAlignmentArm - 1)))) { |
| 1311 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_CreateComputePipelines_ComputeThreadGroupAlignment, |
| 1312 | "%s vkCreateComputePipelines(): compute shader with work group dimensions (%u, " |
| 1313 | "%u, %u) is not aligned to %u " |
| 1314 | "threads. On Arm Mali architectures, not aligning work group sizes to %u may " |
| 1315 | "leave threads idle on the shader " |
| 1316 | "core.", |
| 1317 | VendorSpecificTag(kBPVendorArm), x, y, z, kThreadGroupDispatchCountAlignmentArm, |
| 1318 | kThreadGroupDispatchCountAlignmentArm); |
| 1319 | } |
| 1320 | |
sfricke-samsung | ef15e48 | 2022-01-26 11:32:49 -0800 | [diff] [blame] | 1321 | auto accessible_ids = module_state->MarkAccessibleIds(entrypoint); |
| 1322 | auto descriptor_uses = module_state->CollectInterfaceByDescriptorSlot(accessible_ids); |
Sam Walls | d7ab6db | 2020-06-19 20:41:54 +0100 | [diff] [blame] | 1323 | |
| 1324 | unsigned dimensions = 0; |
| 1325 | if (x > 1) dimensions++; |
| 1326 | if (y > 1) dimensions++; |
| 1327 | if (z > 1) dimensions++; |
| 1328 | // Here the dimension will really depend on the dispatch grid, but assume it's 1D. |
| 1329 | dimensions = std::max(dimensions, 1u); |
| 1330 | |
| 1331 | // If we're accessing images, we almost certainly want to have a 2D workgroup for cache reasons. |
| 1332 | // There are some false positives here. We could simply have a shader that does this within a 1D grid, |
| 1333 | // or we may have a linearly tiled image, but these cases are quite unlikely in practice. |
| 1334 | bool accesses_2d = false; |
| 1335 | for (const auto& usage : descriptor_uses) { |
sfricke-samsung | ef15e48 | 2022-01-26 11:32:49 -0800 | [diff] [blame] | 1336 | auto dim = module_state->GetShaderResourceDimensionality(usage.second); |
Sam Walls | d7ab6db | 2020-06-19 20:41:54 +0100 | [diff] [blame] | 1337 | if (dim < 0) continue; |
| 1338 | auto spvdim = spv::Dim(dim); |
| 1339 | if (spvdim != spv::Dim1D && spvdim != spv::DimBuffer) accesses_2d = true; |
| 1340 | } |
| 1341 | |
| 1342 | if (accesses_2d && dimensions < 2) { |
| 1343 | LogPerformanceWarning(device, kVUID_BestPractices_CreateComputePipelines_ComputeSpatialLocality, |
| 1344 | "%s vkCreateComputePipelines(): compute shader has work group dimensions (%u, %u, %u), which " |
| 1345 | "suggests a 1D dispatch, but the shader is accessing 2D or 3D images. The shader may be " |
| 1346 | "exhibiting poor spatial locality with respect to one or more shader resources.", |
| 1347 | VendorSpecificTag(kBPVendorArm), x, y, z); |
| 1348 | } |
| 1349 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1350 | return skip; |
| 1351 | } |
| 1352 | |
Jeremy Gebben | a3705f4 | 2021-01-19 16:47:43 -0700 | [diff] [blame] | 1353 | bool BestPractices::CheckPipelineStageFlags(const std::string& api_name, VkPipelineStageFlags flags) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1354 | bool skip = false; |
| 1355 | |
| 1356 | if (flags & VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1357 | skip |= LogWarning(device, kVUID_BestPractices_PipelineStageFlags, |
| 1358 | "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] | 1359 | } else if (flags & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1360 | skip |= LogWarning(device, kVUID_BestPractices_PipelineStageFlags, |
| 1361 | "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] | 1362 | } |
| 1363 | |
| 1364 | return skip; |
| 1365 | } |
| 1366 | |
Jeremy Gebben | a3705f4 | 2021-01-19 16:47:43 -0700 | [diff] [blame] | 1367 | bool BestPractices::CheckPipelineStageFlags(const std::string& api_name, VkPipelineStageFlags2KHR flags) const { |
| 1368 | bool skip = false; |
| 1369 | |
| 1370 | if (flags & VK_PIPELINE_STAGE_2_ALL_GRAPHICS_BIT_KHR) { |
| 1371 | skip |= LogWarning(device, kVUID_BestPractices_PipelineStageFlags, |
| 1372 | "You are using VK_PIPELINE_STAGE_2_ALL_GRAPHICS_BIT_KHR when %s is called\n", api_name.c_str()); |
| 1373 | } else if (flags & VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT_KHR) { |
| 1374 | skip |= LogWarning(device, kVUID_BestPractices_PipelineStageFlags, |
| 1375 | "You are using VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT_KHR when %s is called\n", api_name.c_str()); |
| 1376 | } |
| 1377 | |
| 1378 | return skip; |
| 1379 | } |
| 1380 | |
| 1381 | bool BestPractices::CheckDependencyInfo(const std::string& api_name, const VkDependencyInfoKHR& dep_info) const { |
| 1382 | bool skip = false; |
| 1383 | auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info); |
| 1384 | |
| 1385 | skip |= CheckPipelineStageFlags(api_name, stage_masks.src); |
| 1386 | skip |= CheckPipelineStageFlags(api_name, stage_masks.dst); |
| 1387 | |
| 1388 | return skip; |
| 1389 | } |
| 1390 | |
Mark Lobodzinski | 84101d7 | 2020-04-24 09:43:48 -0600 | [diff] [blame] | 1391 | void BestPractices::ManualPostCallRecordQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo, VkResult result) { |
Mark Lobodzinski | 9b133c1 | 2020-03-10 10:42:56 -0600 | [diff] [blame] | 1392 | for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) { |
| 1393 | auto swapchains_result = pPresentInfo->pResults ? pPresentInfo->pResults[i] : result; |
| 1394 | if (swapchains_result == VK_SUBOPTIMAL_KHR) { |
| 1395 | LogPerformanceWarning( |
| 1396 | pPresentInfo->pSwapchains[i], kVUID_BestPractices_SuboptimalSwapchain, |
| 1397 | "vkQueuePresentKHR: %s :VK_SUBOPTIMAL_KHR was returned. VK_SUBOPTIMAL_KHR - Presentation will still succeed, " |
| 1398 | "subject to the window resize behavior, but the swapchain is no longer configured optimally for the surface it " |
| 1399 | "targets. Applications should query updated surface information and recreate their swapchain at the next " |
| 1400 | "convenient opportunity.", |
| 1401 | report_data->FormatHandle(pPresentInfo->pSwapchains[i]).c_str()); |
| 1402 | } |
| 1403 | } |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 1404 | |
| 1405 | // AMD best practice |
| 1406 | // end-of-frame cleanup |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 1407 | num_queue_submissions_ = 0; |
| 1408 | num_barriers_objects_ = 0; |
| 1409 | ClearPipelinesUsedInFrame(); |
Mark Lobodzinski | 9b133c1 | 2020-03-10 10:42:56 -0600 | [diff] [blame] | 1410 | } |
| 1411 | |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1412 | bool BestPractices::PreCallValidateQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo* pSubmits, |
| 1413 | VkFence fence) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1414 | bool skip = false; |
| 1415 | |
| 1416 | for (uint32_t submit = 0; submit < submitCount; submit++) { |
| 1417 | for (uint32_t semaphore = 0; semaphore < pSubmits[submit].waitSemaphoreCount; semaphore++) { |
| 1418 | skip |= CheckPipelineStageFlags("vkQueueSubmit", pSubmits[submit].pWaitDstStageMask[semaphore]); |
| 1419 | } |
ziga-lunarg | c77f0c0 | 2022-04-18 00:15:16 +0200 | [diff] [blame] | 1420 | if (pSubmits[submit].signalSemaphoreCount == 0 && pSubmits[submit].pSignalSemaphores != nullptr) { |
| 1421 | skip |= |
| 1422 | LogWarning(device, kVUID_BestPractices_SemaphoreCount, |
| 1423 | "pSubmits[%" PRIu32 "].pSignalSemaphores is set, but pSubmits[%" PRIu32 "].signalSemaphoreCount is 0.", |
| 1424 | submit, submit); |
| 1425 | } |
| 1426 | if (pSubmits[submit].waitSemaphoreCount == 0 && pSubmits[submit].pWaitSemaphores != nullptr) { |
| 1427 | skip |= LogWarning(device, kVUID_BestPractices_SemaphoreCount, |
| 1428 | "pSubmits[%" PRIu32 "].pWaitSemaphores is set, but pSubmits[%" PRIu32 "].waitSemaphoreCount is 0.", |
| 1429 | submit, submit); |
| 1430 | } |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1431 | } |
| 1432 | |
| 1433 | return skip; |
| 1434 | } |
| 1435 | |
Jeremy Gebben | a3705f4 | 2021-01-19 16:47:43 -0700 | [diff] [blame] | 1436 | bool BestPractices::PreCallValidateQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR* pSubmits, |
| 1437 | VkFence fence) const { |
| 1438 | bool skip = false; |
| 1439 | |
| 1440 | for (uint32_t submit = 0; submit < submitCount; submit++) { |
| 1441 | for (uint32_t semaphore = 0; semaphore < pSubmits[submit].waitSemaphoreInfoCount; semaphore++) { |
| 1442 | skip |= CheckPipelineStageFlags("vkQueueSubmit2KHR", pSubmits[submit].pWaitSemaphoreInfos[semaphore].stageMask); |
| 1443 | } |
| 1444 | } |
| 1445 | |
| 1446 | return skip; |
| 1447 | } |
| 1448 | |
Tony-LunarG | d36f5f3 | 2022-01-20 11:49:59 -0700 | [diff] [blame] | 1449 | bool BestPractices::PreCallValidateQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2* pSubmits, |
| 1450 | VkFence fence) const { |
| 1451 | bool skip = false; |
| 1452 | |
| 1453 | for (uint32_t submit = 0; submit < submitCount; submit++) { |
| 1454 | for (uint32_t semaphore = 0; semaphore < pSubmits[submit].waitSemaphoreInfoCount; semaphore++) { |
| 1455 | skip |= CheckPipelineStageFlags("vkQueueSubmit2", pSubmits[submit].pWaitSemaphoreInfos[semaphore].stageMask); |
| 1456 | } |
| 1457 | } |
| 1458 | |
| 1459 | return skip; |
| 1460 | } |
| 1461 | |
Attilio Provenzano | 746e43e | 2020-02-27 11:23:50 +0000 | [diff] [blame] | 1462 | bool BestPractices::PreCallValidateCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo, |
| 1463 | const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool) const { |
| 1464 | bool skip = false; |
| 1465 | |
| 1466 | if (pCreateInfo->flags & VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT) { |
| 1467 | skip |= LogPerformanceWarning( |
| 1468 | device, kVUID_BestPractices_CreateCommandPool_CommandBufferReset, |
| 1469 | "vkCreateCommandPool(): VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT is set. Consider resetting entire " |
| 1470 | "pool instead."); |
| 1471 | } |
| 1472 | |
| 1473 | return skip; |
| 1474 | } |
| 1475 | |
| 1476 | bool BestPractices::PreCallValidateBeginCommandBuffer(VkCommandBuffer commandBuffer, |
| 1477 | const VkCommandBufferBeginInfo* pBeginInfo) const { |
| 1478 | bool skip = false; |
| 1479 | |
| 1480 | if (pBeginInfo->flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT) { |
| 1481 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_BeginCommandBuffer_SimultaneousUse, |
| 1482 | "vkBeginCommandBuffer(): VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT is set."); |
| 1483 | } |
| 1484 | |
Rodrigo Locatti | fe5172b | 2022-03-22 18:49:29 -0300 | [diff] [blame] | 1485 | if (VendorCheckEnabled(kBPVendorArm) || VendorCheckEnabled(kBPVendorNVIDIA)) { |
| 1486 | if (!(pBeginInfo->flags & VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT)) { |
| 1487 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_BeginCommandBuffer_OneTimeSubmit, |
| 1488 | "%s %s vkBeginCommandBuffer(): VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT is not set. " |
| 1489 | "For best performance on Mali and NVIDIA GPUs, consider setting ONE_TIME_SUBMIT by default.", |
| 1490 | VendorSpecificTag(kBPVendorArm), VendorSpecificTag(kBPVendorNVIDIA)); |
| 1491 | } |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1492 | } |
| 1493 | |
Attilio Provenzano | 746e43e | 2020-02-27 11:23:50 +0000 | [diff] [blame] | 1494 | return skip; |
| 1495 | } |
| 1496 | |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1497 | bool BestPractices::PreCallValidateCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1498 | bool skip = false; |
| 1499 | |
| 1500 | skip |= CheckPipelineStageFlags("vkCmdSetEvent", stageMask); |
| 1501 | |
| 1502 | return skip; |
| 1503 | } |
| 1504 | |
Jeremy Gebben | a3705f4 | 2021-01-19 16:47:43 -0700 | [diff] [blame] | 1505 | bool BestPractices::PreCallValidateCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 1506 | const VkDependencyInfoKHR* pDependencyInfo) const { |
| 1507 | return CheckDependencyInfo("vkCmdSetEvent2KHR", *pDependencyInfo); |
| 1508 | } |
| 1509 | |
Tony-LunarG | d36f5f3 | 2022-01-20 11:49:59 -0700 | [diff] [blame] | 1510 | bool BestPractices::PreCallValidateCmdSetEvent2(VkCommandBuffer commandBuffer, VkEvent event, |
| 1511 | const VkDependencyInfo* pDependencyInfo) const { |
| 1512 | return CheckDependencyInfo("vkCmdSetEvent2", *pDependencyInfo); |
| 1513 | } |
| 1514 | |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1515 | bool BestPractices::PreCallValidateCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, |
| 1516 | VkPipelineStageFlags stageMask) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1517 | bool skip = false; |
| 1518 | |
| 1519 | skip |= CheckPipelineStageFlags("vkCmdResetEvent", stageMask); |
| 1520 | |
| 1521 | return skip; |
| 1522 | } |
| 1523 | |
Jeremy Gebben | a3705f4 | 2021-01-19 16:47:43 -0700 | [diff] [blame] | 1524 | bool BestPractices::PreCallValidateCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 1525 | VkPipelineStageFlags2KHR stageMask) const { |
| 1526 | bool skip = false; |
| 1527 | |
| 1528 | skip |= CheckPipelineStageFlags("vkCmdResetEvent2KHR", stageMask); |
| 1529 | |
| 1530 | return skip; |
| 1531 | } |
| 1532 | |
Tony-LunarG | d36f5f3 | 2022-01-20 11:49:59 -0700 | [diff] [blame] | 1533 | bool BestPractices::PreCallValidateCmdResetEvent2(VkCommandBuffer commandBuffer, VkEvent event, |
| 1534 | VkPipelineStageFlags2 stageMask) const { |
| 1535 | bool skip = false; |
| 1536 | |
| 1537 | skip |= CheckPipelineStageFlags("vkCmdResetEvent2", stageMask); |
| 1538 | |
| 1539 | return skip; |
| 1540 | } |
| 1541 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1542 | bool BestPractices::PreCallValidateCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents, |
| 1543 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 1544 | uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers, |
| 1545 | uint32_t bufferMemoryBarrierCount, |
| 1546 | const VkBufferMemoryBarrier* pBufferMemoryBarriers, |
| 1547 | uint32_t imageMemoryBarrierCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1548 | const VkImageMemoryBarrier* pImageMemoryBarriers) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1549 | bool skip = false; |
| 1550 | |
| 1551 | skip |= CheckPipelineStageFlags("vkCmdWaitEvents", srcStageMask); |
| 1552 | skip |= CheckPipelineStageFlags("vkCmdWaitEvents", dstStageMask); |
| 1553 | |
| 1554 | return skip; |
| 1555 | } |
| 1556 | |
Jeremy Gebben | a3705f4 | 2021-01-19 16:47:43 -0700 | [diff] [blame] | 1557 | bool BestPractices::PreCallValidateCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents, |
| 1558 | const VkDependencyInfoKHR* pDependencyInfos) const { |
| 1559 | bool skip = false; |
| 1560 | for (uint32_t i = 0; i < eventCount; i++) { |
| 1561 | skip = CheckDependencyInfo("vkCmdWaitEvents2KHR", pDependencyInfos[i]); |
| 1562 | } |
| 1563 | |
| 1564 | return skip; |
| 1565 | } |
| 1566 | |
Tony-LunarG | d36f5f3 | 2022-01-20 11:49:59 -0700 | [diff] [blame] | 1567 | bool BestPractices::PreCallValidateCmdWaitEvents2(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents, |
| 1568 | const VkDependencyInfo* pDependencyInfos) const { |
| 1569 | bool skip = false; |
| 1570 | for (uint32_t i = 0; i < eventCount; i++) { |
| 1571 | skip = CheckDependencyInfo("vkCmdWaitEvents2", pDependencyInfos[i]); |
| 1572 | } |
| 1573 | |
| 1574 | return skip; |
| 1575 | } |
| 1576 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1577 | bool BestPractices::PreCallValidateCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, |
| 1578 | VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, |
| 1579 | uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers, |
| 1580 | uint32_t bufferMemoryBarrierCount, |
| 1581 | const VkBufferMemoryBarrier* pBufferMemoryBarriers, |
| 1582 | uint32_t imageMemoryBarrierCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1583 | const VkImageMemoryBarrier* pImageMemoryBarriers) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1584 | bool skip = false; |
| 1585 | |
| 1586 | skip |= CheckPipelineStageFlags("vkCmdPipelineBarrier", srcStageMask); |
| 1587 | skip |= CheckPipelineStageFlags("vkCmdPipelineBarrier", dstStageMask); |
| 1588 | |
ziga-lunarg | b65dbfb | 2022-03-19 18:45:09 +0100 | [diff] [blame] | 1589 | for (uint32_t i = 0; i < imageMemoryBarrierCount; ++i) { |
| 1590 | if (pImageMemoryBarriers[i].oldLayout == VK_IMAGE_LAYOUT_UNDEFINED && |
| 1591 | IsImageLayoutReadOnly(pImageMemoryBarriers[i].newLayout)) { |
| 1592 | skip |= LogWarning(device, kVUID_BestPractices_TransitionUndefinedToReadOnly, |
| 1593 | "VkImageMemoryBarrier is being submitted with oldLayout VK_IMAGE_LAYOUT_UNDEFINED and the contents " |
| 1594 | "may be discarded, but the newLayout is %s, which is read only.", |
| 1595 | string_VkImageLayout(pImageMemoryBarriers[i].newLayout)); |
| 1596 | } |
| 1597 | } |
| 1598 | |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 1599 | if (VendorCheckEnabled(kBPVendorAMD)) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 1600 | auto num = num_barriers_objects_.load(); |
| 1601 | if (num + imageMemoryBarrierCount + bufferMemoryBarrierCount > kMaxRecommendedBarriersSizeAMD) { |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 1602 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_CmdBuffer_highBarrierCount, |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 1603 | "%s Performance warning: In this frame, %" PRIu32 |
| 1604 | " barriers were already submitted. Barriers have a high cost and can " |
| 1605 | "stall the GPU. " |
| 1606 | "Consider consolidating and re-organizing the frame to use fewer barriers.", |
| 1607 | VendorSpecificTag(kBPVendorAMD), num); |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 1608 | } |
Rodrigo Locatti | 494e448 | 2022-03-30 16:37:40 -0300 | [diff] [blame] | 1609 | } |
| 1610 | if (VendorCheckEnabled(kBPVendorAMD) || VendorCheckEnabled(kBPVendorNVIDIA)) { |
| 1611 | static constexpr std::array<VkImageLayout, 3> read_layouts = { |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 1612 | VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, |
| 1613 | VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, |
| 1614 | VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, |
| 1615 | }; |
| 1616 | |
| 1617 | for (uint32_t i = 0; i < imageMemoryBarrierCount; i++) { |
| 1618 | // read to read barriers |
Rodrigo Locatti | 494e448 | 2022-03-30 16:37:40 -0300 | [diff] [blame] | 1619 | const auto &image_barrier = pImageMemoryBarriers[i]; |
| 1620 | bool old_is_read_layout = std::find(read_layouts.begin(), read_layouts.end(), image_barrier.oldLayout) != read_layouts.end(); |
| 1621 | bool new_is_read_layout = std::find(read_layouts.begin(), read_layouts.end(), image_barrier.newLayout) != read_layouts.end(); |
| 1622 | |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 1623 | if (old_is_read_layout && new_is_read_layout) { |
| 1624 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_PipelineBarrier_readToReadBarrier, |
Rodrigo Locatti | 494e448 | 2022-03-30 16:37:40 -0300 | [diff] [blame] | 1625 | "%s %s Performance warning: Don't issue read-to-read barriers. " |
| 1626 | "Get the resource in the right state the first time you use it.", |
| 1627 | VendorSpecificTag(kBPVendorAMD), VendorSpecificTag(kBPVendorNVIDIA)); |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 1628 | } |
| 1629 | |
| 1630 | // general with no storage |
Rodrigo Locatti | 494e448 | 2022-03-30 16:37:40 -0300 | [diff] [blame] | 1631 | if (VendorCheckEnabled(kBPVendorAMD) && image_barrier.newLayout == VK_IMAGE_LAYOUT_GENERAL) { |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 1632 | auto image_state = Get<IMAGE_STATE>(pImageMemoryBarriers[i].image); |
| 1633 | if (!(image_state->createInfo.usage & VK_IMAGE_USAGE_STORAGE_BIT)) { |
| 1634 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_vkImage_AvoidGeneral, |
| 1635 | "%s Performance warning: VK_IMAGE_LAYOUT_GENERAL should only be used with " |
| 1636 | "VK_IMAGE_USAGE_STORAGE_BIT images.", |
| 1637 | VendorSpecificTag(kBPVendorAMD)); |
| 1638 | } |
| 1639 | } |
| 1640 | } |
| 1641 | } |
| 1642 | |
Rodrigo Locatti | 0b16cda | 2022-04-01 17:59:53 -0300 | [diff] [blame^] | 1643 | for (uint32_t i = 0; i < imageMemoryBarrierCount; ++i) { |
| 1644 | skip |= ValidateCmdPipelineBarrierImageBarrier(commandBuffer, pImageMemoryBarriers[i]); |
| 1645 | } |
| 1646 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1647 | return skip; |
| 1648 | } |
| 1649 | |
Jeremy Gebben | a3705f4 | 2021-01-19 16:47:43 -0700 | [diff] [blame] | 1650 | bool BestPractices::PreCallValidateCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer, |
| 1651 | const VkDependencyInfoKHR* pDependencyInfo) const { |
Rodrigo Locatti | 0b16cda | 2022-04-01 17:59:53 -0300 | [diff] [blame^] | 1652 | bool skip = false; |
| 1653 | |
| 1654 | skip |= CheckDependencyInfo("vkCmdPipelineBarrier2KHR", *pDependencyInfo); |
| 1655 | |
| 1656 | for (uint32_t i = 0; i < pDependencyInfo->imageMemoryBarrierCount; ++i) { |
| 1657 | skip |= ValidateCmdPipelineBarrierImageBarrier(commandBuffer, pDependencyInfo->pImageMemoryBarriers[i]); |
| 1658 | } |
| 1659 | |
| 1660 | return skip; |
Jeremy Gebben | a3705f4 | 2021-01-19 16:47:43 -0700 | [diff] [blame] | 1661 | } |
| 1662 | |
Tony-LunarG | d36f5f3 | 2022-01-20 11:49:59 -0700 | [diff] [blame] | 1663 | bool BestPractices::PreCallValidateCmdPipelineBarrier2(VkCommandBuffer commandBuffer, |
| 1664 | const VkDependencyInfo* pDependencyInfo) const { |
Rodrigo Locatti | 0b16cda | 2022-04-01 17:59:53 -0300 | [diff] [blame^] | 1665 | bool skip = false; |
| 1666 | |
| 1667 | skip |= CheckDependencyInfo("vkCmdPipelineBarrier2", *pDependencyInfo); |
| 1668 | |
| 1669 | for (uint32_t i = 0; i < pDependencyInfo->imageMemoryBarrierCount; ++i) { |
| 1670 | skip |= ValidateCmdPipelineBarrierImageBarrier(commandBuffer, pDependencyInfo->pImageMemoryBarriers[i]); |
| 1671 | } |
| 1672 | |
| 1673 | return skip; |
| 1674 | } |
| 1675 | |
| 1676 | template <typename ImageMemoryBarrier> |
| 1677 | bool BestPractices::ValidateCmdPipelineBarrierImageBarrier(VkCommandBuffer commandBuffer, |
| 1678 | const ImageMemoryBarrier& barrier) const { |
| 1679 | |
| 1680 | bool skip = false; |
| 1681 | |
| 1682 | if (VendorCheckEnabled(kBPVendorNVIDIA)) { |
| 1683 | if (barrier.oldLayout == VK_IMAGE_LAYOUT_UNDEFINED && barrier.newLayout != VK_IMAGE_LAYOUT_UNDEFINED) { |
| 1684 | skip |= ValidateZcull(commandBuffer, barrier.image, barrier.subresourceRange); |
| 1685 | } |
| 1686 | } |
| 1687 | |
| 1688 | return skip; |
Tony-LunarG | d36f5f3 | 2022-01-20 11:49:59 -0700 | [diff] [blame] | 1689 | } |
| 1690 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1691 | bool BestPractices::PreCallValidateCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1692 | VkQueryPool queryPool, uint32_t query) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1693 | bool skip = false; |
| 1694 | |
Jeremy Gebben | a3705f4 | 2021-01-19 16:47:43 -0700 | [diff] [blame] | 1695 | skip |= CheckPipelineStageFlags("vkCmdWriteTimestamp", static_cast<VkPipelineStageFlags>(pipelineStage)); |
| 1696 | |
| 1697 | return skip; |
| 1698 | } |
| 1699 | |
| 1700 | bool BestPractices::PreCallValidateCmdWriteTimestamp2KHR(VkCommandBuffer commandBuffer, VkPipelineStageFlags2KHR pipelineStage, |
| 1701 | VkQueryPool queryPool, uint32_t query) const { |
| 1702 | bool skip = false; |
| 1703 | |
| 1704 | skip |= CheckPipelineStageFlags("vkCmdWriteTimestamp2KHR", pipelineStage); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1705 | |
| 1706 | return skip; |
| 1707 | } |
| 1708 | |
Tony-LunarG | d36f5f3 | 2022-01-20 11:49:59 -0700 | [diff] [blame] | 1709 | bool BestPractices::PreCallValidateCmdWriteTimestamp2(VkCommandBuffer commandBuffer, VkPipelineStageFlags2 pipelineStage, |
| 1710 | VkQueryPool queryPool, uint32_t query) const { |
| 1711 | bool skip = false; |
| 1712 | |
| 1713 | skip |= CheckPipelineStageFlags("vkCmdWriteTimestamp2", pipelineStage); |
| 1714 | |
| 1715 | return skip; |
| 1716 | } |
| 1717 | |
Rodrigo Locatti | a5eaf6e | 2022-04-01 18:05:23 -0300 | [diff] [blame] | 1718 | void BestPractices::PreCallRecordCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, |
| 1719 | VkPipeline pipeline) { |
| 1720 | StateTracker::PreCallRecordCmdBindPipeline(commandBuffer, pipelineBindPoint, pipeline); |
| 1721 | |
| 1722 | auto pipeline_info = Get<PIPELINE_STATE>(pipeline); |
Rodrigo Locatti | 0b16cda | 2022-04-01 17:59:53 -0300 | [diff] [blame^] | 1723 | auto cb = GetWrite<bp_state::CommandBuffer>(commandBuffer); |
Rodrigo Locatti | a5eaf6e | 2022-04-01 18:05:23 -0300 | [diff] [blame] | 1724 | |
| 1725 | assert(pipeline_info); |
| 1726 | assert(cb); |
| 1727 | |
| 1728 | if (pipelineBindPoint == VK_PIPELINE_BIND_POINT_GRAPHICS && VendorCheckEnabled(kBPVendorNVIDIA)) { |
| 1729 | using TessGeometryMeshState = bp_state::CommandBufferStateNV::TessGeometryMesh::State; |
| 1730 | auto& tgm = cb->nv.tess_geometry_mesh; |
| 1731 | |
| 1732 | // Make sure the message is only signaled once per command buffer |
| 1733 | tgm.threshold_signaled = tgm.num_switches >= kNumBindPipelineTessGeometryMeshSwitchesThresholdNVIDIA; |
| 1734 | |
| 1735 | // Track pipeline switches with tessellation, geometry, and/or mesh shaders enabled, and disabled |
| 1736 | auto tgm_stages = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT | |
| 1737 | VK_SHADER_STAGE_GEOMETRY_BIT | VK_SHADER_STAGE_TASK_BIT_NV | VK_SHADER_STAGE_MESH_BIT_NV; |
| 1738 | auto new_tgm_state = (pipeline_info->active_shaders & tgm_stages) != 0 |
| 1739 | ? TessGeometryMeshState::Enabled |
| 1740 | : TessGeometryMeshState::Disabled; |
| 1741 | if (tgm.state != new_tgm_state && tgm.state != TessGeometryMeshState::Unknown) { |
| 1742 | tgm.num_switches++; |
| 1743 | } |
| 1744 | tgm.state = new_tgm_state; |
Rodrigo Locatti | 0b16cda | 2022-04-01 17:59:53 -0300 | [diff] [blame^] | 1745 | |
| 1746 | // Track depthTestEnable and depthCompareOp |
| 1747 | auto &pipeline_create_info = pipeline_info->GetCreateInfo<VkGraphicsPipelineCreateInfo>(); |
| 1748 | auto depth_stencil_state = pipeline_create_info.pDepthStencilState; |
| 1749 | auto dynamic_state = pipeline_create_info.pDynamicState; |
| 1750 | if (depth_stencil_state && dynamic_state) { |
| 1751 | auto dynamic_state_begin = dynamic_state->pDynamicStates; |
| 1752 | auto dynamic_state_end = dynamic_state->pDynamicStates + dynamic_state->dynamicStateCount; |
| 1753 | |
| 1754 | bool dynamic_depth_test_enable = std::find(dynamic_state_begin, dynamic_state_end, VK_DYNAMIC_STATE_DEPTH_TEST_ENABLE) != dynamic_state_end; |
| 1755 | bool dynamic_depth_func = std::find(dynamic_state_begin, dynamic_state_end, VK_DYNAMIC_STATE_DEPTH_COMPARE_OP) != dynamic_state_end; |
| 1756 | |
| 1757 | if (!dynamic_depth_test_enable) { |
| 1758 | RecordSetDepthTestState(*cb, cb->nv.depth_compare_op, depth_stencil_state->depthTestEnable != VK_FALSE); |
| 1759 | } |
| 1760 | if (!dynamic_depth_func) { |
| 1761 | RecordSetDepthTestState(*cb, depth_stencil_state->depthCompareOp, cb->nv.depth_test_enable); |
| 1762 | } |
| 1763 | } |
Rodrigo Locatti | a5eaf6e | 2022-04-01 18:05:23 -0300 | [diff] [blame] | 1764 | } |
| 1765 | } |
| 1766 | |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1767 | void BestPractices::PostCallRecordCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, |
| 1768 | VkPipeline pipeline) { |
| 1769 | StateTracker::PostCallRecordCmdBindPipeline(commandBuffer, pipelineBindPoint, pipeline); |
| 1770 | |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 1771 | // AMD best practice |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 1772 | PipelineUsedInFrame(pipeline); |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 1773 | |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1774 | if (pipelineBindPoint == VK_PIPELINE_BIND_POINT_GRAPHICS) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 1775 | auto pipeline_state = Get<bp_state::Pipeline>(pipeline); |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1776 | // check for depth/blend state tracking |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 1777 | if (pipeline_state) { |
| 1778 | auto cb_node = GetWrite<bp_state::CommandBuffer>(commandBuffer); |
Jeremy Gebben | 7c2cd8b | 2021-08-11 15:40:38 -0600 | [diff] [blame] | 1779 | assert(cb_node); |
| 1780 | auto& render_pass_state = cb_node->render_pass_state; |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1781 | |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 1782 | render_pass_state.nextDrawTouchesAttachments = pipeline_state->access_framebuffer_attachments; |
Hans-Kristian Arntzen | 56232b9 | 2021-06-16 14:37:48 +0200 | [diff] [blame] | 1783 | render_pass_state.drawTouchAttachments = true; |
Hans-Kristian Arntzen | 8abca1e | 2021-06-16 13:57:45 +0200 | [diff] [blame] | 1784 | |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 1785 | const auto* blend_state = pipeline_state->ColorBlendState(); |
| 1786 | const auto* stencil_state = pipeline_state->DepthStencilState(); |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1787 | |
| 1788 | if (blend_state) { |
| 1789 | // 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] | 1790 | render_pass_state.depthOnly = true; |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1791 | for (size_t i = 0; i < blend_state->attachmentCount; i++) { |
| 1792 | if (blend_state->pAttachments[i].colorWriteMask != 0) { |
Hans-Kristian Arntzen | 56232b9 | 2021-06-16 14:37:48 +0200 | [diff] [blame] | 1793 | render_pass_state.depthOnly = false; |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1794 | } |
| 1795 | } |
| 1796 | } |
| 1797 | |
| 1798 | // check for depth value usage |
Hans-Kristian Arntzen | 56232b9 | 2021-06-16 14:37:48 +0200 | [diff] [blame] | 1799 | render_pass_state.depthEqualComparison = false; |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1800 | |
| 1801 | if (stencil_state && stencil_state->depthTestEnable) { |
| 1802 | switch (stencil_state->depthCompareOp) { |
| 1803 | case VK_COMPARE_OP_EQUAL: |
| 1804 | case VK_COMPARE_OP_GREATER_OR_EQUAL: |
| 1805 | case VK_COMPARE_OP_LESS_OR_EQUAL: |
Hans-Kristian Arntzen | 56232b9 | 2021-06-16 14:37:48 +0200 | [diff] [blame] | 1806 | render_pass_state.depthEqualComparison = true; |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1807 | break; |
| 1808 | default: |
| 1809 | break; |
| 1810 | } |
| 1811 | } |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1812 | } |
| 1813 | } |
| 1814 | } |
| 1815 | |
Rodrigo Locatti | 0b16cda | 2022-04-01 17:59:53 -0300 | [diff] [blame^] | 1816 | void BestPractices::PreCallRecordCmdSetDepthCompareOp(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) { |
| 1817 | StateTracker::PreCallRecordCmdSetDepthCompareOp(commandBuffer, depthCompareOp); |
| 1818 | |
| 1819 | auto cb = GetWrite<bp_state::CommandBuffer>(commandBuffer); |
| 1820 | assert(cb); |
| 1821 | |
| 1822 | if (VendorCheckEnabled(kBPVendorNVIDIA)) { |
| 1823 | RecordSetDepthTestState(*cb, depthCompareOp, cb->nv.depth_test_enable); |
| 1824 | } |
| 1825 | } |
| 1826 | |
| 1827 | void BestPractices::PreCallRecordCmdSetDepthCompareOpEXT(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) { |
| 1828 | StateTracker::PreCallRecordCmdSetDepthCompareOpEXT(commandBuffer, depthCompareOp); |
| 1829 | |
| 1830 | auto cb = GetWrite<bp_state::CommandBuffer>(commandBuffer); |
| 1831 | assert(cb); |
| 1832 | |
| 1833 | if (VendorCheckEnabled(kBPVendorNVIDIA)) { |
| 1834 | RecordSetDepthTestState(*cb, depthCompareOp, cb->nv.depth_test_enable); |
| 1835 | } |
| 1836 | } |
| 1837 | |
| 1838 | void BestPractices::PreCallRecordCmdSetDepthTestEnable(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) { |
| 1839 | StateTracker::PreCallRecordCmdSetDepthTestEnable(commandBuffer, depthTestEnable); |
| 1840 | |
| 1841 | auto cb = GetWrite<bp_state::CommandBuffer>(commandBuffer); |
| 1842 | assert(cb); |
| 1843 | |
| 1844 | if (VendorCheckEnabled(kBPVendorNVIDIA)) { |
| 1845 | RecordSetDepthTestState(*cb, cb->nv.depth_compare_op, depthTestEnable != VK_FALSE); |
| 1846 | } |
| 1847 | } |
| 1848 | |
| 1849 | void BestPractices::PreCallRecordCmdSetDepthTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) { |
| 1850 | StateTracker::PreCallRecordCmdSetDepthTestEnableEXT(commandBuffer, depthTestEnable); |
| 1851 | |
| 1852 | auto cb = GetWrite<bp_state::CommandBuffer>(commandBuffer); |
| 1853 | assert(cb); |
| 1854 | |
| 1855 | if (VendorCheckEnabled(kBPVendorNVIDIA)) { |
| 1856 | RecordSetDepthTestState(*cb, cb->nv.depth_compare_op, depthTestEnable != VK_FALSE); |
| 1857 | } |
| 1858 | } |
| 1859 | |
| 1860 | void BestPractices::RecordSetDepthTestState(bp_state::CommandBuffer& cmd_state, VkCompareOp new_depth_compare_op, bool new_depth_test_enable) { |
| 1861 | assert(VendorCheckEnabled(kBPVendorNVIDIA)); |
| 1862 | |
| 1863 | if (cmd_state.nv.depth_compare_op != new_depth_compare_op) { |
| 1864 | switch (new_depth_compare_op) { |
| 1865 | case VK_COMPARE_OP_LESS: |
| 1866 | case VK_COMPARE_OP_LESS_OR_EQUAL: |
| 1867 | cmd_state.nv.zcull_direction = bp_state::CommandBufferStateNV::ZcullDirection::Less; |
| 1868 | break; |
| 1869 | case VK_COMPARE_OP_GREATER: |
| 1870 | case VK_COMPARE_OP_GREATER_OR_EQUAL: |
| 1871 | cmd_state.nv.zcull_direction = bp_state::CommandBufferStateNV::ZcullDirection::Greater; |
| 1872 | break; |
| 1873 | default: |
| 1874 | // The other ops carry over the previous state. |
| 1875 | break; |
| 1876 | } |
| 1877 | } |
| 1878 | cmd_state.nv.depth_compare_op = new_depth_compare_op; |
| 1879 | cmd_state.nv.depth_test_enable = new_depth_test_enable; |
| 1880 | } |
| 1881 | |
| 1882 | void BestPractices::RecordCmdBeginRenderingCommon(VkCommandBuffer commandBuffer) { |
| 1883 | auto cmd_state = GetWrite<bp_state::CommandBuffer>(commandBuffer); |
| 1884 | assert(cmd_state); |
| 1885 | |
| 1886 | auto rp = cmd_state->activeRenderPass.get(); |
| 1887 | assert(rp); |
| 1888 | |
| 1889 | if (VendorCheckEnabled(kBPVendorNVIDIA)) { |
| 1890 | std::shared_ptr<IMAGE_VIEW_STATE> depth_image_view_shared_ptr; |
| 1891 | IMAGE_VIEW_STATE* depth_image_view = nullptr; |
| 1892 | layer_data::optional<VkAttachmentLoadOp> load_op; |
| 1893 | |
| 1894 | if (rp->use_dynamic_rendering || rp->use_dynamic_rendering_inherited) { |
| 1895 | const auto depth_attachment = rp->dynamic_rendering_begin_rendering_info.pDepthAttachment; |
| 1896 | if (depth_attachment) { |
| 1897 | load_op.emplace(depth_attachment->loadOp); |
| 1898 | depth_image_view_shared_ptr = Get<IMAGE_VIEW_STATE>(depth_attachment->imageView); |
| 1899 | depth_image_view = depth_image_view_shared_ptr.get(); |
| 1900 | } |
| 1901 | } else { |
| 1902 | if (rp->createInfo.subpassCount > 0) { |
| 1903 | const auto depth_attachment = rp->createInfo.pSubpasses[0].pDepthStencilAttachment; |
| 1904 | if (depth_attachment) { |
| 1905 | const uint32_t attachment_index = depth_attachment->attachment; |
| 1906 | if (attachment_index != VK_ATTACHMENT_UNUSED) { |
| 1907 | load_op.emplace(rp->createInfo.pAttachments[attachment_index].loadOp); |
| 1908 | depth_image_view = (*cmd_state->active_attachments)[attachment_index]; |
| 1909 | } |
| 1910 | } |
| 1911 | } |
| 1912 | } |
| 1913 | if (depth_image_view && (depth_image_view->create_info.subresourceRange.aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) != 0U) { |
| 1914 | const VkImage depth_image = depth_image_view->image_state->image(); |
| 1915 | const VkImageSubresourceRange& subresource_range = depth_image_view->create_info.subresourceRange; |
| 1916 | RecordBindZcullScope(*cmd_state, depth_image, subresource_range); |
| 1917 | } else { |
| 1918 | RecordUnbindZcullScope(*cmd_state); |
| 1919 | } |
| 1920 | if (load_op) { |
| 1921 | if (*load_op == VK_ATTACHMENT_LOAD_OP_CLEAR || *load_op == VK_ATTACHMENT_LOAD_OP_DONT_CARE) { |
| 1922 | RecordResetScopeZcullDirection(*cmd_state); |
| 1923 | } |
| 1924 | } |
| 1925 | } |
| 1926 | } |
| 1927 | |
| 1928 | void BestPractices::RecordCmdEndRenderingCommon(VkCommandBuffer commandBuffer) { |
| 1929 | auto cmd_state = GetWrite<bp_state::CommandBuffer>(commandBuffer); |
| 1930 | assert(cmd_state); |
| 1931 | |
| 1932 | auto rp = cmd_state->activeRenderPass.get(); |
| 1933 | assert(rp); |
| 1934 | |
| 1935 | if (VendorCheckEnabled(kBPVendorNVIDIA)) { |
| 1936 | layer_data::optional<VkAttachmentStoreOp> store_op; |
| 1937 | |
| 1938 | if (rp->use_dynamic_rendering || rp->use_dynamic_rendering_inherited) { |
| 1939 | const auto depth_attachment = rp->dynamic_rendering_begin_rendering_info.pDepthAttachment; |
| 1940 | if (depth_attachment) { |
| 1941 | store_op.emplace(depth_attachment->storeOp); |
| 1942 | } |
| 1943 | } else { |
| 1944 | if (rp->createInfo.subpassCount > 0) { |
| 1945 | const uint32_t last_subpass = rp->createInfo.subpassCount - 1; |
| 1946 | const auto depth_attachment = rp->createInfo.pSubpasses[last_subpass].pDepthStencilAttachment; |
| 1947 | if (depth_attachment) { |
| 1948 | const uint32_t attachment = depth_attachment->attachment; |
| 1949 | if (attachment != VK_ATTACHMENT_UNUSED) { |
| 1950 | store_op.emplace(rp->createInfo.pAttachments[attachment].storeOp); |
| 1951 | } |
| 1952 | } |
| 1953 | } |
| 1954 | } |
| 1955 | |
| 1956 | if (store_op) { |
| 1957 | if (*store_op == VK_ATTACHMENT_STORE_OP_DONT_CARE || *store_op == VK_ATTACHMENT_STORE_OP_NONE) { |
| 1958 | RecordResetScopeZcullDirection(*cmd_state); |
| 1959 | } |
| 1960 | } |
| 1961 | |
| 1962 | RecordUnbindZcullScope(*cmd_state); |
| 1963 | } |
| 1964 | } |
| 1965 | |
| 1966 | void BestPractices::RecordBindZcullScope(bp_state::CommandBuffer& cmd_state, VkImage depth_attachment, const VkImageSubresourceRange& subresource_range) { |
| 1967 | assert(VendorCheckEnabled(kBPVendorNVIDIA)); |
| 1968 | |
| 1969 | if (depth_attachment == VK_NULL_HANDLE) { |
| 1970 | cmd_state.nv.zcull_scope = {}; |
| 1971 | return; |
| 1972 | } |
| 1973 | |
| 1974 | assert((subresource_range.aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) != 0U); |
| 1975 | |
| 1976 | auto image_state = Get<IMAGE_STATE>(depth_attachment); |
| 1977 | assert(image_state); |
| 1978 | |
| 1979 | const uint32_t mip_levels = image_state->createInfo.mipLevels; |
| 1980 | const uint32_t array_layers = image_state->createInfo.arrayLayers; |
| 1981 | |
| 1982 | auto& tree = cmd_state.nv.zcull_per_image[depth_attachment]; |
| 1983 | if (tree.states.empty()) { |
| 1984 | tree.mip_levels = mip_levels; |
| 1985 | tree.array_layers = array_layers; |
| 1986 | tree.states.resize(array_layers * mip_levels); |
| 1987 | } |
| 1988 | |
| 1989 | cmd_state.nv.zcull_scope.image = depth_attachment; |
| 1990 | cmd_state.nv.zcull_scope.range = subresource_range; |
| 1991 | cmd_state.nv.zcull_scope.tree = &tree; |
| 1992 | } |
| 1993 | |
| 1994 | void BestPractices::RecordUnbindZcullScope(bp_state::CommandBuffer& cmd_state) { |
| 1995 | assert(VendorCheckEnabled(kBPVendorNVIDIA)); |
| 1996 | |
| 1997 | RecordBindZcullScope(cmd_state, VK_NULL_HANDLE, VkImageSubresourceRange{}); |
| 1998 | } |
| 1999 | |
| 2000 | void BestPractices::RecordResetScopeZcullDirection(bp_state::CommandBuffer& cmd_state) { |
| 2001 | assert(VendorCheckEnabled(kBPVendorNVIDIA)); |
| 2002 | |
| 2003 | auto& scope = cmd_state.nv.zcull_scope; |
| 2004 | RecordResetZcullDirection(cmd_state, scope.image, scope.range); |
| 2005 | } |
| 2006 | |
| 2007 | void BestPractices::RecordResetZcullDirection(bp_state::CommandBuffer& cmd_state, VkImage depth_image, |
| 2008 | const VkImageSubresourceRange& subresource_range) { |
| 2009 | assert(VendorCheckEnabled(kBPVendorNVIDIA)); |
| 2010 | |
| 2011 | RecordSetZcullDirection(cmd_state, depth_image, subresource_range, bp_state::CommandBufferStateNV::ZcullDirection::Unknown); |
| 2012 | |
| 2013 | const auto image_it = cmd_state.nv.zcull_per_image.find(depth_image); |
| 2014 | if (image_it == cmd_state.nv.zcull_per_image.end()) { |
| 2015 | return; |
| 2016 | } |
| 2017 | auto& tree = image_it->second; |
| 2018 | |
| 2019 | for (uint32_t i = 0; i < subresource_range.layerCount; ++i) { |
| 2020 | const uint32_t layer = subresource_range.baseArrayLayer + i; |
| 2021 | |
| 2022 | for (uint32_t j = 0; j < subresource_range.levelCount; ++j) { |
| 2023 | const uint32_t level = subresource_range.baseMipLevel + j; |
| 2024 | |
| 2025 | auto& subresource = tree.GetState(layer, level); |
| 2026 | subresource.num_less_draws = 0; |
| 2027 | subresource.num_greater_draws = 0; |
| 2028 | } |
| 2029 | } |
| 2030 | } |
| 2031 | |
| 2032 | void BestPractices::RecordSetScopeZcullDirection(bp_state::CommandBuffer& cmd_state, bp_state::CommandBufferStateNV::ZcullDirection mode) { |
| 2033 | assert(VendorCheckEnabled(kBPVendorNVIDIA)); |
| 2034 | |
| 2035 | auto& scope = cmd_state.nv.zcull_scope; |
| 2036 | RecordSetZcullDirection(cmd_state, scope.image, scope.range, mode); |
| 2037 | } |
| 2038 | |
| 2039 | void BestPractices::RecordSetZcullDirection(bp_state::CommandBuffer& cmd_state, VkImage depth_image, |
| 2040 | const VkImageSubresourceRange& subresource_range, |
| 2041 | bp_state::CommandBufferStateNV::ZcullDirection mode) { |
| 2042 | assert(VendorCheckEnabled(kBPVendorNVIDIA)); |
| 2043 | |
| 2044 | const auto image_it = cmd_state.nv.zcull_per_image.find(depth_image); |
| 2045 | if (image_it == cmd_state.nv.zcull_per_image.end()) { |
| 2046 | return; |
| 2047 | } |
| 2048 | auto& tree = image_it->second; |
| 2049 | |
| 2050 | for (uint32_t i = 0; i < subresource_range.layerCount; ++i) { |
| 2051 | const uint32_t layer = subresource_range.baseArrayLayer + i; |
| 2052 | |
| 2053 | for (uint32_t j = 0; j < subresource_range.levelCount; ++j) { |
| 2054 | const uint32_t level = subresource_range.baseMipLevel + j; |
| 2055 | tree.GetState(layer, level).direction = cmd_state.nv.zcull_direction; |
| 2056 | } |
| 2057 | } |
| 2058 | } |
| 2059 | |
| 2060 | void BestPractices::RecordZcullDraw(bp_state::CommandBuffer& cmd_state) { |
| 2061 | assert(VendorCheckEnabled(kBPVendorNVIDIA)); |
| 2062 | |
| 2063 | // Add one draw to each subresource depending on the current Z-cull direction |
| 2064 | auto& scope = cmd_state.nv.zcull_scope; |
| 2065 | |
| 2066 | for (uint32_t i = 0; i < scope.range.layerCount; ++i) { |
| 2067 | const uint32_t layer = scope.range.baseArrayLayer + i; |
| 2068 | auto& subresource = scope.tree->GetState(layer, scope.range.baseMipLevel); |
| 2069 | |
| 2070 | switch (subresource.direction) { |
| 2071 | case bp_state::CommandBufferStateNV::ZcullDirection::Unknown: |
| 2072 | // Unreachable |
| 2073 | assert(0); |
| 2074 | break; |
| 2075 | case bp_state::CommandBufferStateNV::ZcullDirection::Less: |
| 2076 | ++subresource.num_less_draws; |
| 2077 | break; |
| 2078 | case bp_state::CommandBufferStateNV::ZcullDirection::Greater: |
| 2079 | ++subresource.num_greater_draws; |
| 2080 | break; |
| 2081 | } |
| 2082 | } |
| 2083 | } |
| 2084 | |
| 2085 | bool BestPractices::ValidateZcullScope(VkCommandBuffer commandBuffer) const { |
| 2086 | assert(VendorCheckEnabled(kBPVendorNVIDIA)); |
| 2087 | |
| 2088 | bool skip = false; |
| 2089 | |
| 2090 | const auto cmd_state = GetRead<bp_state::CommandBuffer>(commandBuffer); |
| 2091 | assert(cmd_state); |
| 2092 | |
| 2093 | if (cmd_state->nv.depth_test_enable) { |
| 2094 | auto& scope = cmd_state->nv.zcull_scope; |
| 2095 | skip |= ValidateZcull(commandBuffer, scope.image, scope.range); |
| 2096 | } |
| 2097 | |
| 2098 | return skip; |
| 2099 | } |
| 2100 | |
| 2101 | bool BestPractices::ValidateZcull(VkCommandBuffer commandBuffer, VkImage image, |
| 2102 | const VkImageSubresourceRange& subresource_range) const { |
| 2103 | bool skip = false; |
| 2104 | |
| 2105 | const char* good_mode = nullptr; |
| 2106 | const char* bad_mode = nullptr; |
| 2107 | |
| 2108 | const auto cmd_state = GetRead<bp_state::CommandBuffer>(commandBuffer); |
| 2109 | assert(cmd_state); |
| 2110 | |
| 2111 | const auto image_it = cmd_state->nv.zcull_per_image.find(image); |
| 2112 | if (image_it == cmd_state->nv.zcull_per_image.end()) { |
| 2113 | return skip; |
| 2114 | } |
| 2115 | const auto& tree = image_it->second; |
| 2116 | |
| 2117 | bool is_balanced = false; |
| 2118 | |
| 2119 | for (uint32_t i = 0; i < subresource_range.layerCount; ++i) { |
| 2120 | const uint32_t layer = subresource_range.baseArrayLayer + i; |
| 2121 | |
| 2122 | for (uint32_t j = 0; j < subresource_range.levelCount; ++j) { |
| 2123 | const uint32_t level = subresource_range.baseMipLevel + j; |
| 2124 | |
| 2125 | const auto& resource = tree.GetState(layer, level); |
| 2126 | const uint64_t num_draws = resource.num_less_draws + resource.num_greater_draws; |
| 2127 | |
| 2128 | if (num_draws > 0) { |
| 2129 | const uint64_t less_ratio = (resource.num_less_draws * 100) / num_draws; |
| 2130 | const uint64_t greater_ratio = (resource.num_greater_draws * 100) / num_draws; |
| 2131 | |
| 2132 | if ((less_ratio > kZcullDirectionBalanceRatioNVIDIA) && (greater_ratio > kZcullDirectionBalanceRatioNVIDIA)) { |
| 2133 | is_balanced = true; |
| 2134 | |
| 2135 | if (greater_ratio > less_ratio) { |
| 2136 | good_mode = "GREATER"; |
| 2137 | bad_mode = "LESS"; |
| 2138 | } else { |
| 2139 | good_mode = "LESS"; |
| 2140 | bad_mode = "GREATER"; |
| 2141 | } |
| 2142 | break; |
| 2143 | } |
| 2144 | } |
| 2145 | } |
| 2146 | if (is_balanced) { |
| 2147 | break; |
| 2148 | } |
| 2149 | } |
| 2150 | |
| 2151 | if (is_balanced) { |
| 2152 | skip |= LogPerformanceWarning( |
| 2153 | commandBuffer, kVUID_BestPractices_Zcull_LessGreaterRatio, |
| 2154 | "%s Depth attachment %s is primarily rendered with depth compare op %s, but some draws use %s. " |
| 2155 | "Z-cull is disabled for the least used direction, which harms depth testing performance. " |
| 2156 | "The Z-cull direction can be reset by clearing the depth attachment, transitioning from VK_IMAGE_LAYOUT_UNDEFINED, " |
| 2157 | "using VK_ATTACHMENT_LOAD_OP_DONT_CARE, or using VK_ATTACHMENT_STORE_OP_DONT_CARE.", |
| 2158 | VendorSpecificTag(kBPVendorNVIDIA), report_data->FormatHandle(cmd_state->nv.zcull_scope.image).c_str(), good_mode, |
| 2159 | bad_mode); |
| 2160 | } |
| 2161 | |
| 2162 | return skip; |
| 2163 | } |
| 2164 | |
Hans-Kristian Arntzen | 237663c | 2021-07-01 14:36:40 +0200 | [diff] [blame] | 2165 | static inline bool RenderPassUsesAttachmentAsResolve(const safe_VkRenderPassCreateInfo2& createInfo, uint32_t attachment) { |
| 2166 | for (uint32_t subpass = 0; subpass < createInfo.subpassCount; subpass++) { |
| 2167 | const auto& subpass_info = createInfo.pSubpasses[subpass]; |
| 2168 | if (subpass_info.pResolveAttachments) { |
| 2169 | for (uint32_t i = 0; i < subpass_info.colorAttachmentCount; i++) { |
| 2170 | if (subpass_info.pResolveAttachments[i].attachment == attachment) return true; |
| 2171 | } |
| 2172 | } |
| 2173 | } |
| 2174 | |
| 2175 | return false; |
| 2176 | } |
| 2177 | |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 2178 | static inline bool RenderPassUsesAttachmentOnTile(const safe_VkRenderPassCreateInfo2& createInfo, uint32_t attachment) { |
| 2179 | for (uint32_t subpass = 0; subpass < createInfo.subpassCount; subpass++) { |
Hans-Kristian Arntzen | 69ace7d | 2021-04-28 14:17:19 +0200 | [diff] [blame] | 2180 | const auto& subpass_info = createInfo.pSubpasses[subpass]; |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 2181 | |
| 2182 | // If an attachment is ever used as a color attachment, |
| 2183 | // resolve attachment or depth stencil attachment, |
| 2184 | // it needs to exist on tile at some point. |
| 2185 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2186 | for (uint32_t i = 0; i < subpass_info.colorAttachmentCount; i++) { |
| 2187 | if (subpass_info.pColorAttachments[i].attachment == attachment) return true; |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 2188 | } |
| 2189 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2190 | if (subpass_info.pResolveAttachments) { |
| 2191 | for (uint32_t i = 0; i < subpass_info.colorAttachmentCount; i++) { |
| 2192 | if (subpass_info.pResolveAttachments[i].attachment == attachment) return true; |
| 2193 | } |
| 2194 | } |
| 2195 | |
| 2196 | if (subpass_info.pDepthStencilAttachment && subpass_info.pDepthStencilAttachment->attachment == attachment) return true; |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 2197 | } |
| 2198 | |
| 2199 | return false; |
| 2200 | } |
| 2201 | |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2202 | static inline bool RenderPassUsesAttachmentAsImageOnly(const safe_VkRenderPassCreateInfo2& createInfo, uint32_t attachment) { |
| 2203 | if (RenderPassUsesAttachmentOnTile(createInfo, attachment)) { |
| 2204 | return false; |
| 2205 | } |
| 2206 | |
| 2207 | for (uint32_t subpass = 0; subpass < createInfo.subpassCount; subpass++) { |
Hans-Kristian Arntzen | 69ace7d | 2021-04-28 14:17:19 +0200 | [diff] [blame] | 2208 | const auto& subpassInfo = createInfo.pSubpasses[subpass]; |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2209 | |
| 2210 | for (uint32_t i = 0; i < subpassInfo.inputAttachmentCount; i++) { |
| 2211 | if (subpassInfo.pInputAttachments[i].attachment == attachment) { |
| 2212 | return true; |
| 2213 | } |
| 2214 | } |
| 2215 | } |
| 2216 | |
| 2217 | return false; |
| 2218 | } |
| 2219 | |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 2220 | bool BestPractices::ValidateCmdBeginRenderPass(VkCommandBuffer commandBuffer, RenderPassCreateVersion rp_version, |
| 2221 | const VkRenderPassBeginInfo* pRenderPassBegin) const { |
| 2222 | bool skip = false; |
| 2223 | |
| 2224 | if (!pRenderPassBegin) { |
| 2225 | return skip; |
| 2226 | } |
| 2227 | |
Gareth Webb | dc6549a | 2021-06-16 03:52:24 +0100 | [diff] [blame] | 2228 | if (pRenderPassBegin->renderArea.extent.width == 0 || pRenderPassBegin->renderArea.extent.height == 0) { |
| 2229 | skip |= LogWarning(device, kVUID_BestPractices_BeginRenderPass_ZeroSizeRenderArea, |
| 2230 | "This render pass has a zero-size render area. It cannot write to any attachments, " |
| 2231 | "and can only be used for side effects such as layout transitions."); |
| 2232 | } |
| 2233 | |
Jeremy Gebben | b20a824 | 2021-11-05 15:14:43 -0600 | [diff] [blame] | 2234 | auto rp_state = Get<RENDER_PASS_STATE>(pRenderPassBegin->renderPass); |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 2235 | if (rp_state) { |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 2236 | if (rp_state->createInfo.flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) { |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 2237 | const VkRenderPassAttachmentBeginInfo* rpabi = LvlFindInChain<VkRenderPassAttachmentBeginInfo>(pRenderPassBegin->pNext); |
Tony-LunarG | 767180f | 2020-04-23 14:03:59 -0600 | [diff] [blame] | 2238 | if (rpabi) { |
| 2239 | skip = ValidateAttachments(rp_state->createInfo.ptr(), rpabi->attachmentCount, rpabi->pAttachments); |
| 2240 | } |
| 2241 | } |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 2242 | // Check if any attachments have LOAD operation on them |
| 2243 | for (uint32_t att = 0; att < rp_state->createInfo.attachmentCount; att++) { |
Hans-Kristian Arntzen | 69ace7d | 2021-04-28 14:17:19 +0200 | [diff] [blame] | 2244 | const auto& attachment = rp_state->createInfo.pAttachments[att]; |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 2245 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2246 | bool attachment_has_readback = false; |
Hans-Kristian Arntzen | 4afb59b | 2021-06-18 12:41:36 +0200 | [diff] [blame] | 2247 | if (!FormatIsStencilOnly(attachment.format) && attachment.loadOp == VK_ATTACHMENT_LOAD_OP_LOAD) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2248 | attachment_has_readback = true; |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 2249 | } |
| 2250 | |
| 2251 | if (FormatHasStencil(attachment.format) && attachment.stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2252 | attachment_has_readback = true; |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 2253 | } |
| 2254 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2255 | bool attachment_needs_readback = false; |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 2256 | |
| 2257 | // Check if the attachment is actually used in any subpass on-tile |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2258 | if (attachment_has_readback && RenderPassUsesAttachmentOnTile(rp_state->createInfo, att)) { |
| 2259 | attachment_needs_readback = true; |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 2260 | } |
| 2261 | |
| 2262 | // 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] | 2263 | if (attachment_needs_readback && (VendorCheckEnabled(kBPVendorArm) || VendorCheckEnabled(kBPVendorIMG))) { |
| 2264 | skip |= |
| 2265 | LogPerformanceWarning(device, kVUID_BestPractices_BeginRenderPass_AttachmentNeedsReadback, |
LawG4 | 015be1c | 2022-03-01 10:37:52 +0000 | [diff] [blame] | 2266 | "%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] | 2267 | "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] | 2268 | "which will copy in total %u pixels (renderArea = " |
LawG4 | 7747b32 | 2022-02-23 16:12:10 +0000 | [diff] [blame] | 2269 | "{ %" PRId32 ", %" PRId32 ", %" PRIu32 ", %" PRIu32 " }) to the tile buffer.", |
| 2270 | VendorSpecificTag(kBPVendorArm), VendorSpecificTag(kBPVendorIMG), att, |
| 2271 | pRenderPassBegin->renderArea.extent.width * pRenderPassBegin->renderArea.extent.height, |
| 2272 | pRenderPassBegin->renderArea.offset.x, pRenderPassBegin->renderArea.offset.y, |
| 2273 | pRenderPassBegin->renderArea.extent.width, pRenderPassBegin->renderArea.extent.height); |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 2274 | } |
| 2275 | } |
paul-lunarg | 7089e27 | 2022-06-20 22:19:37 +0200 | [diff] [blame] | 2276 | |
| 2277 | // Check if renderpass has at least one VK_ATTACHMENT_LOAD_OP_CLEAR |
| 2278 | |
| 2279 | bool clearing = false; |
| 2280 | |
| 2281 | for (uint32_t att = 0; att < rp_state->createInfo.attachmentCount; att++) { |
| 2282 | const auto& attachment = rp_state->createInfo.pAttachments[att]; |
| 2283 | |
| 2284 | if (attachment.loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) { |
| 2285 | clearing = true; |
| 2286 | break; |
| 2287 | } |
| 2288 | } |
| 2289 | |
| 2290 | // Check if there are ClearValues passed to BeginRenderPass even though no attachments will be cleared |
| 2291 | if (!clearing && pRenderPassBegin->clearValueCount > 0) { |
| 2292 | // Flag as warning because nothing will happen per spec, and pClearValues will be ignored |
| 2293 | skip |= LogWarning( |
| 2294 | device, kVUID_BestPractices_ClearValueWithoutLoadOpClear, |
| 2295 | "This render pass does not have VkRenderPassCreateInfo.pAttachments->loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR " |
| 2296 | "but VkRenderPassBeginInfo.clearValueCount > 0. VkRenderPassBeginInfo.pClearValues will be ignored and no " |
paul-lunarg | a0a149c | 2022-06-23 16:18:51 +0200 | [diff] [blame] | 2297 | "attachments will be cleared."); |
paul-lunarg | 7089e27 | 2022-06-20 22:19:37 +0200 | [diff] [blame] | 2298 | } |
paul-lunarg | a0a149c | 2022-06-23 16:18:51 +0200 | [diff] [blame] | 2299 | |
| 2300 | // Check if there are more clearValues than attachments |
| 2301 | if(pRenderPassBegin->clearValueCount > rp_state->createInfo.attachmentCount) { |
| 2302 | // Flag as warning because the overflowing clearValues will be ignored and could even be undefined on certain platforms. |
| 2303 | // This could signal a bug and there seems to be no reason for this to happen on purpose. |
| 2304 | skip |= LogWarning( |
| 2305 | device, kVUID_BestPractices_ClearValueCountHigherThanAttachmentCount, |
| 2306 | "This render pass has VkRenderPassBeginInfo.clearValueCount > VkRenderPassCreateInfo.attachmentCount " |
| 2307 | "(%" PRIu32 " > %" PRIu32 ") and as such the clearValues that do not have a corresponding attachment will be ignored.", |
| 2308 | pRenderPassBegin->clearValueCount, rp_state->createInfo.attachmentCount); |
| 2309 | } |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 2310 | } |
| 2311 | |
| 2312 | return skip; |
| 2313 | } |
| 2314 | |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 2315 | void BestPractices::QueueValidateImageView(QueueCallbacks &funcs, const char* function_name, |
| 2316 | IMAGE_VIEW_STATE* view, IMAGE_SUBRESOURCE_USAGE_BP usage) { |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2317 | if (view) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 2318 | auto image_state = std::static_pointer_cast<bp_state::Image>(view->image_state); |
| 2319 | QueueValidateImage(funcs, function_name, image_state, usage, view->normalized_subresource_range); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2320 | } |
| 2321 | } |
| 2322 | |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 2323 | void BestPractices::QueueValidateImage(QueueCallbacks& funcs, const char* function_name, std::shared_ptr<bp_state::Image>& state, |
| 2324 | IMAGE_SUBRESOURCE_USAGE_BP usage, const VkImageSubresourceRange& subresource_range) { |
Hans-Kristian Arntzen | 9326420 | 2021-05-21 17:07:46 +0200 | [diff] [blame] | 2325 | // If we're viewing a 3D slice, ignore base array layer. |
| 2326 | // The entire 3D subresource is accessed as one atomic unit. |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 2327 | 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] | 2328 | |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 2329 | const uint32_t max_layers = state->createInfo.arrayLayers - base_array_layer; |
Hans-Kristian Arntzen | 69ace7d | 2021-04-28 14:17:19 +0200 | [diff] [blame] | 2330 | const uint32_t array_layers = std::min(subresource_range.layerCount, max_layers); |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 2331 | const uint32_t max_levels = state->createInfo.mipLevels - subresource_range.baseMipLevel; |
| 2332 | const uint32_t mip_levels = std::min(state->createInfo.mipLevels, max_levels); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2333 | |
| 2334 | for (uint32_t layer = 0; layer < array_layers; layer++) { |
| 2335 | for (uint32_t level = 0; level < mip_levels; level++) { |
Hans-Kristian Arntzen | 9326420 | 2021-05-21 17:07:46 +0200 | [diff] [blame] | 2336 | QueueValidateImage(funcs, function_name, state, usage, layer + base_array_layer, |
| 2337 | level + subresource_range.baseMipLevel); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2338 | } |
| 2339 | } |
| 2340 | } |
| 2341 | |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 2342 | void BestPractices::QueueValidateImage(QueueCallbacks& funcs, const char* function_name, std::shared_ptr<bp_state::Image>& state, |
| 2343 | IMAGE_SUBRESOURCE_USAGE_BP usage, const VkImageSubresourceLayers& subresource_layers) { |
| 2344 | const uint32_t max_layers = state->createInfo.arrayLayers - subresource_layers.baseArrayLayer; |
Hans-Kristian Arntzen | 69ace7d | 2021-04-28 14:17:19 +0200 | [diff] [blame] | 2345 | const uint32_t array_layers = std::min(subresource_layers.layerCount, max_layers); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2346 | |
| 2347 | for (uint32_t layer = 0; layer < array_layers; layer++) { |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 2348 | QueueValidateImage(funcs, function_name, state, usage, layer + subresource_layers.baseArrayLayer, subresource_layers.mipLevel); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2349 | } |
| 2350 | } |
| 2351 | |
paul-lunarg | 5eb5206 | 2022-06-27 18:57:15 +0200 | [diff] [blame] | 2352 | void BestPractices::QueueValidateImage(QueueCallbacks& funcs, const char* function_name, std::shared_ptr<bp_state::Image>& state, |
| 2353 | IMAGE_SUBRESOURCE_USAGE_BP usage, uint32_t array_layer, uint32_t mip_level) { |
| 2354 | funcs.push_back([this, function_name, state, usage, array_layer, mip_level](const ValidationStateTracker&, const QUEUE_STATE&, |
| 2355 | const CMD_BUFFER_STATE&) -> bool { |
| 2356 | ValidateImageInQueue(function_name, *state, usage, array_layer, mip_level); |
| 2357 | return false; |
| 2358 | }); |
Hans-Kristian Arntzen | 66f4b52 | 2021-03-22 11:35:58 +0100 | [diff] [blame] | 2359 | } |
| 2360 | |
LawG4 | 4d414ba | 2022-02-23 15:35:41 +0000 | [diff] [blame] | 2361 | void BestPractices::ValidateImageInQueueArmImg(const char* function_name, const bp_state::Image& image, |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 2362 | IMAGE_SUBRESOURCE_USAGE_BP last_usage, IMAGE_SUBRESOURCE_USAGE_BP usage, |
Hans-Kristian Arntzen | b214795 | 2021-04-28 14:32:00 +0200 | [diff] [blame] | 2363 | uint32_t array_layer, uint32_t mip_level) { |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2364 | // Swapchain images are implicitly read so clear after store is expected. |
Hans-Kristian Arntzen | 5b466db | 2021-03-18 13:59:46 +0100 | [diff] [blame] | 2365 | 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] | 2366 | !image.IsSwapchainImage()) { |
Hans-Kristian Arntzen | b214795 | 2021-04-28 14:32:00 +0200 | [diff] [blame] | 2367 | LogPerformanceWarning( |
| 2368 | device, kVUID_BestPractices_RenderPass_RedundantStore, |
LawG4 | 015be1c | 2022-03-01 10:37:52 +0000 | [diff] [blame] | 2369 | "%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] | 2370 | "image was used, it was written to with STORE_OP_STORE. " |
| 2371 | "Storing to the image is probably redundant in this case, and wastes bandwidth on tile-based " |
| 2372 | "architectures.", |
LawG4 | 4d414ba | 2022-02-23 15:35:41 +0000 | [diff] [blame] | 2373 | function_name, VendorSpecificTag(kBPVendorArm), VendorSpecificTag(kBPVendorIMG), array_layer, mip_level); |
Hans-Kristian Arntzen | 5b466db | 2021-03-18 13:59:46 +0100 | [diff] [blame] | 2374 | } 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] | 2375 | LogPerformanceWarning( |
| 2376 | device, kVUID_BestPractices_RenderPass_RedundantClear, |
LawG4 | 015be1c | 2022-03-01 10:37:52 +0000 | [diff] [blame] | 2377 | "%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] | 2378 | "image was used, it was written to with vkCmdClear*Image(). " |
| 2379 | "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] | 2380 | "tile-based architectures.", |
| 2381 | function_name, VendorSpecificTag(kBPVendorArm), VendorSpecificTag(kBPVendorIMG), array_layer, mip_level); |
Hans-Kristian Arntzen | 44f9d86 | 2021-03-22 13:56:39 +0100 | [diff] [blame] | 2382 | } else if (usage == IMAGE_SUBRESOURCE_USAGE_BP::RENDER_PASS_READ_TO_TILE && |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 2383 | (last_usage == IMAGE_SUBRESOURCE_USAGE_BP::BLIT_WRITE || last_usage == IMAGE_SUBRESOURCE_USAGE_BP::CLEARED || |
| 2384 | 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] | 2385 | const char *last_cmd = nullptr; |
| 2386 | const char *vuid = nullptr; |
| 2387 | const char *suggestion = nullptr; |
| 2388 | |
| 2389 | switch (last_usage) { |
| 2390 | case IMAGE_SUBRESOURCE_USAGE_BP::BLIT_WRITE: |
| 2391 | vuid = kVUID_BestPractices_RenderPass_BlitImage_LoadOpLoad; |
| 2392 | last_cmd = "vkCmdBlitImage"; |
| 2393 | suggestion = |
| 2394 | "The blit is probably redundant in this case, and wastes bandwidth on tile-based architectures. " |
| 2395 | "Rather than blitting, just render the source image in a fragment shader in this render pass, " |
| 2396 | "which avoids the memory roundtrip."; |
| 2397 | break; |
| 2398 | case IMAGE_SUBRESOURCE_USAGE_BP::CLEARED: |
| 2399 | vuid = kVUID_BestPractices_RenderPass_InefficientClear; |
| 2400 | last_cmd = "vkCmdClear*Image"; |
| 2401 | suggestion = |
| 2402 | "Clearing the image with vkCmdClear*Image() is probably redundant in this case, and wastes bandwidth on " |
| 2403 | "tile-based architectures. " |
| 2404 | "Use LOAD_OP_CLEAR instead to clear the image for free."; |
| 2405 | break; |
| 2406 | case IMAGE_SUBRESOURCE_USAGE_BP::COPY_WRITE: |
| 2407 | vuid = kVUID_BestPractices_RenderPass_CopyImage_LoadOpLoad; |
| 2408 | last_cmd = "vkCmdCopy*Image"; |
| 2409 | suggestion = |
| 2410 | "The copy is probably redundant in this case, and wastes bandwidth on tile-based architectures. " |
| 2411 | "Rather than copying, just render the source image in a fragment shader in this render pass, " |
| 2412 | "which avoids the memory roundtrip."; |
| 2413 | break; |
| 2414 | case IMAGE_SUBRESOURCE_USAGE_BP::RESOLVE_WRITE: |
| 2415 | vuid = kVUID_BestPractices_RenderPass_ResolveImage_LoadOpLoad; |
| 2416 | last_cmd = "vkCmdResolveImage"; |
| 2417 | suggestion = |
| 2418 | "The resolve is probably redundant in this case, and wastes a lot of bandwidth on tile-based architectures. " |
| 2419 | "Rather than resolving, and then loading, try to keep rendering in the same render pass, " |
| 2420 | "which avoids the memory roundtrip."; |
| 2421 | break; |
| 2422 | default: |
| 2423 | break; |
| 2424 | } |
| 2425 | |
| 2426 | LogPerformanceWarning( |
| 2427 | device, vuid, |
LawG4 | 015be1c | 2022-03-01 10:37:52 +0000 | [diff] [blame] | 2428 | "%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] | 2429 | "time image was used, it was written to with %s. %s", |
LawG4 | 4d414ba | 2022-02-23 15:35:41 +0000 | [diff] [blame] | 2430 | function_name, VendorSpecificTag(kBPVendorArm), VendorSpecificTag(kBPVendorIMG), array_layer, mip_level, last_cmd, |
| 2431 | suggestion); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2432 | } |
Hans-Kristian Arntzen | b214795 | 2021-04-28 14:32:00 +0200 | [diff] [blame] | 2433 | } |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2434 | |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 2435 | void BestPractices::ValidateImageInQueue(const char* function_name, bp_state::Image& state, IMAGE_SUBRESOURCE_USAGE_BP usage, |
| 2436 | uint32_t array_layer, uint32_t mip_level) { |
| 2437 | auto last_usage = state.UpdateUsage(array_layer, mip_level, usage); |
paul-lunarg | 5eb5206 | 2022-06-27 18:57:15 +0200 | [diff] [blame] | 2438 | |
| 2439 | // When image was discarded with StoreOpDontCare but is now being read with LoadOpLoad |
| 2440 | if (last_usage == IMAGE_SUBRESOURCE_USAGE_BP::RENDER_PASS_DISCARDED && |
| 2441 | usage == IMAGE_SUBRESOURCE_USAGE_BP::RENDER_PASS_READ_TO_TILE) { |
| 2442 | LogWarning(device, kVUID_BestPractices_StoreOpDontCareThenLoadOpLoad, |
| 2443 | "Trying to load an attachment with LOAD_OP_LOAD that was previously stored with STORE_OP_DONT_CARE. This may " |
| 2444 | "result in undefined behaviour."); |
| 2445 | } |
| 2446 | |
LawG4 | 4d414ba | 2022-02-23 15:35:41 +0000 | [diff] [blame] | 2447 | if (VendorCheckEnabled(kBPVendorArm) || VendorCheckEnabled(kBPVendorIMG)) { |
| 2448 | ValidateImageInQueueArmImg(function_name, state, last_usage, usage, array_layer, mip_level); |
Hans-Kristian Arntzen | b214795 | 2021-04-28 14:32:00 +0200 | [diff] [blame] | 2449 | } |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2450 | } |
| 2451 | |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 2452 | void BestPractices::AddDeferredQueueOperations(bp_state::CommandBuffer& cb) { |
| 2453 | cb.queue_submit_functions.insert(cb.queue_submit_functions.end(), cb.queue_submit_functions_after_render_pass.begin(), |
| 2454 | cb.queue_submit_functions_after_render_pass.end()); |
| 2455 | cb.queue_submit_functions_after_render_pass.clear(); |
Hans-Kristian Arntzen | dd8acbb | 2021-03-22 13:41:47 +0100 | [diff] [blame] | 2456 | } |
| 2457 | |
| 2458 | void BestPractices::PreCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) { |
Rodrigo Locatti | 0b16cda | 2022-04-01 17:59:53 -0300 | [diff] [blame^] | 2459 | RecordCmdEndRenderingCommon(commandBuffer); |
| 2460 | |
Hans-Kristian Arntzen | dd8acbb | 2021-03-22 13:41:47 +0100 | [diff] [blame] | 2461 | ValidationStateTracker::PreCallRecordCmdEndRenderPass(commandBuffer); |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 2462 | auto cb_node = GetWrite<bp_state::CommandBuffer>(commandBuffer); |
| 2463 | if (cb_node) { |
| 2464 | AddDeferredQueueOperations(*cb_node); |
| 2465 | } |
Hans-Kristian Arntzen | dd8acbb | 2021-03-22 13:41:47 +0100 | [diff] [blame] | 2466 | } |
| 2467 | |
| 2468 | void BestPractices::PreCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassInfo) { |
Rodrigo Locatti | 0b16cda | 2022-04-01 17:59:53 -0300 | [diff] [blame^] | 2469 | RecordCmdEndRenderingCommon(commandBuffer); |
| 2470 | |
Hans-Kristian Arntzen | dd8acbb | 2021-03-22 13:41:47 +0100 | [diff] [blame] | 2471 | ValidationStateTracker::PreCallRecordCmdEndRenderPass2(commandBuffer, pSubpassInfo); |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 2472 | auto cb_node = GetWrite<bp_state::CommandBuffer>(commandBuffer); |
| 2473 | if (cb_node) { |
| 2474 | AddDeferredQueueOperations(*cb_node); |
| 2475 | } |
Hans-Kristian Arntzen | dd8acbb | 2021-03-22 13:41:47 +0100 | [diff] [blame] | 2476 | } |
| 2477 | |
| 2478 | void BestPractices::PreCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer, const VkSubpassEndInfoKHR *pSubpassInfo) { |
Rodrigo Locatti | 0b16cda | 2022-04-01 17:59:53 -0300 | [diff] [blame^] | 2479 | RecordCmdEndRenderingCommon(commandBuffer); |
| 2480 | |
Hans-Kristian Arntzen | dd8acbb | 2021-03-22 13:41:47 +0100 | [diff] [blame] | 2481 | ValidationStateTracker::PreCallRecordCmdEndRenderPass2KHR(commandBuffer, pSubpassInfo); |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 2482 | auto cb_node = GetWrite<bp_state::CommandBuffer>(commandBuffer); |
| 2483 | if (cb_node) { |
| 2484 | AddDeferredQueueOperations(*cb_node); |
| 2485 | } |
Hans-Kristian Arntzen | dd8acbb | 2021-03-22 13:41:47 +0100 | [diff] [blame] | 2486 | } |
| 2487 | |
Rodrigo Locatti | 0b16cda | 2022-04-01 17:59:53 -0300 | [diff] [blame^] | 2488 | void BestPractices::PreCallRecordCmdEndRendering(VkCommandBuffer commandBuffer) { |
| 2489 | RecordCmdEndRenderingCommon(commandBuffer); |
| 2490 | |
| 2491 | ValidationStateTracker::PreCallRecordCmdEndRendering(commandBuffer); |
| 2492 | } |
| 2493 | |
| 2494 | void BestPractices::PreCallRecordCmdEndRenderingKHR(VkCommandBuffer commandBuffer) { |
| 2495 | RecordCmdEndRenderingCommon(commandBuffer); |
| 2496 | |
| 2497 | ValidationStateTracker::PreCallRecordCmdEndRenderingKHR(commandBuffer); |
| 2498 | } |
| 2499 | |
Hans-Kristian Arntzen | d9941a9 | 2021-06-18 12:31:30 +0200 | [diff] [blame] | 2500 | void BestPractices::PreCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer, |
| 2501 | const VkRenderPassBeginInfo* pRenderPassBegin, |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2502 | VkSubpassContents contents) { |
Hans-Kristian Arntzen | dd8acbb | 2021-03-22 13:41:47 +0100 | [diff] [blame] | 2503 | ValidationStateTracker::PreCallRecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents); |
Rodrigo Locatti | 0b16cda | 2022-04-01 17:59:53 -0300 | [diff] [blame^] | 2504 | RecordCmdBeginRenderingCommon(commandBuffer); |
Hans-Kristian Arntzen | d9941a9 | 2021-06-18 12:31:30 +0200 | [diff] [blame] | 2505 | RecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin); |
| 2506 | } |
| 2507 | |
| 2508 | void BestPractices::PreCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer, |
| 2509 | const VkRenderPassBeginInfo* pRenderPassBegin, |
| 2510 | const VkSubpassBeginInfo* pSubpassBeginInfo) { |
| 2511 | ValidationStateTracker::PreCallRecordCmdBeginRenderPass2(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
Rodrigo Locatti | 0b16cda | 2022-04-01 17:59:53 -0300 | [diff] [blame^] | 2512 | RecordCmdBeginRenderingCommon(commandBuffer); |
Hans-Kristian Arntzen | d9941a9 | 2021-06-18 12:31:30 +0200 | [diff] [blame] | 2513 | RecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin); |
| 2514 | } |
| 2515 | |
| 2516 | void BestPractices::PreCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 2517 | const VkRenderPassBeginInfo* pRenderPassBegin, |
| 2518 | const VkSubpassBeginInfo* pSubpassBeginInfo) { |
| 2519 | ValidationStateTracker::PreCallRecordCmdBeginRenderPass2KHR(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
Rodrigo Locatti | 0b16cda | 2022-04-01 17:59:53 -0300 | [diff] [blame^] | 2520 | RecordCmdBeginRenderingCommon(commandBuffer); |
Hans-Kristian Arntzen | d9941a9 | 2021-06-18 12:31:30 +0200 | [diff] [blame] | 2521 | RecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin); |
| 2522 | } |
| 2523 | |
Rodrigo Locatti | 0b16cda | 2022-04-01 17:59:53 -0300 | [diff] [blame^] | 2524 | void BestPractices::PreCallRecordCmdBeginRendering(VkCommandBuffer commandBuffer, const VkRenderingInfo* pRenderingInfo) { |
| 2525 | ValidationStateTracker::PreCallRecordCmdBeginRendering(commandBuffer, pRenderingInfo); |
| 2526 | RecordCmdBeginRenderingCommon(commandBuffer); |
| 2527 | } |
| 2528 | |
| 2529 | void BestPractices::PreCallRecordCmdBeginRenderingKHR(VkCommandBuffer commandBuffer, const VkRenderingInfo* pRenderingInfo) { |
| 2530 | ValidationStateTracker::PreCallRecordCmdBeginRenderingKHR(commandBuffer, pRenderingInfo); |
| 2531 | RecordCmdBeginRenderingCommon(commandBuffer); |
| 2532 | } |
| 2533 | |
| 2534 | void BestPractices::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) { |
| 2535 | ValidationStateTracker::PostCallRecordCmdNextSubpass(commandBuffer, contents); |
| 2536 | |
| 2537 | auto cmd_state = GetWrite<bp_state::CommandBuffer>(commandBuffer); |
| 2538 | auto rp = cmd_state->activeRenderPass.get(); |
| 2539 | assert(rp); |
| 2540 | |
| 2541 | if (VendorCheckEnabled(kBPVendorNVIDIA)) { |
| 2542 | IMAGE_VIEW_STATE* depth_image_view = nullptr; |
| 2543 | |
| 2544 | const auto depth_attachment = rp->createInfo.pSubpasses[cmd_state->activeSubpass].pDepthStencilAttachment; |
| 2545 | if (depth_attachment) { |
| 2546 | const uint32_t attachment_index = depth_attachment->attachment; |
| 2547 | if (attachment_index != VK_ATTACHMENT_UNUSED) { |
| 2548 | depth_image_view = (*cmd_state->active_attachments)[attachment_index]; |
| 2549 | } |
| 2550 | } |
| 2551 | if (depth_image_view && (depth_image_view->create_info.subresourceRange.aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) != 0U) { |
| 2552 | const VkImage depth_image = depth_image_view->image_state->image(); |
| 2553 | const VkImageSubresourceRange& subresource_range = depth_image_view->create_info.subresourceRange; |
| 2554 | RecordBindZcullScope(*cmd_state, depth_image, subresource_range); |
| 2555 | } else { |
| 2556 | RecordUnbindZcullScope(*cmd_state); |
| 2557 | } |
| 2558 | } |
| 2559 | } |
| 2560 | |
Hans-Kristian Arntzen | d9941a9 | 2021-06-18 12:31:30 +0200 | [diff] [blame] | 2561 | void BestPractices::RecordCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) { |
Hans-Kristian Arntzen | dd8acbb | 2021-03-22 13:41:47 +0100 | [diff] [blame] | 2562 | |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2563 | if (!pRenderPassBegin) { |
| 2564 | return; |
| 2565 | } |
| 2566 | |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 2567 | auto cb = GetWrite<bp_state::CommandBuffer>(commandBuffer); |
Hans-Kristian Arntzen | 66f4b52 | 2021-03-22 11:35:58 +0100 | [diff] [blame] | 2568 | |
Jeremy Gebben | b20a824 | 2021-11-05 15:14:43 -0600 | [diff] [blame] | 2569 | auto rp_state = Get<RENDER_PASS_STATE>(pRenderPassBegin->renderPass); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2570 | if (rp_state) { |
| 2571 | // Check load ops |
| 2572 | for (uint32_t att = 0; att < rp_state->createInfo.attachmentCount; att++) { |
Hans-Kristian Arntzen | 69ace7d | 2021-04-28 14:17:19 +0200 | [diff] [blame] | 2573 | const auto& attachment = rp_state->createInfo.pAttachments[att]; |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2574 | |
| 2575 | if (!RenderPassUsesAttachmentAsImageOnly(rp_state->createInfo, att) && |
| 2576 | !RenderPassUsesAttachmentOnTile(rp_state->createInfo, att)) { |
| 2577 | continue; |
| 2578 | } |
| 2579 | |
Hans-Kristian Arntzen | 5b466db | 2021-03-18 13:59:46 +0100 | [diff] [blame] | 2580 | IMAGE_SUBRESOURCE_USAGE_BP usage = IMAGE_SUBRESOURCE_USAGE_BP::UNDEFINED; |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2581 | |
| 2582 | if ((!FormatIsStencilOnly(attachment.format) && attachment.loadOp == VK_ATTACHMENT_LOAD_OP_LOAD) || |
| 2583 | (FormatHasStencil(attachment.format) && attachment.stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD)) { |
Hans-Kristian Arntzen | 5b466db | 2021-03-18 13:59:46 +0100 | [diff] [blame] | 2584 | usage = IMAGE_SUBRESOURCE_USAGE_BP::RENDER_PASS_READ_TO_TILE; |
Hans-Kristian Arntzen | 5e56e55 | 2021-03-29 11:45:20 +0200 | [diff] [blame] | 2585 | } else if ((!FormatIsStencilOnly(attachment.format) && attachment.loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) || |
| 2586 | (FormatHasStencil(attachment.format) && attachment.stencilLoadOp == VK_ATTACHMENT_LOAD_OP_CLEAR)) { |
Hans-Kristian Arntzen | 5b466db | 2021-03-18 13:59:46 +0100 | [diff] [blame] | 2587 | usage = IMAGE_SUBRESOURCE_USAGE_BP::RENDER_PASS_CLEARED; |
Hans-Kristian Arntzen | 5e56e55 | 2021-03-29 11:45:20 +0200 | [diff] [blame] | 2588 | } else if (RenderPassUsesAttachmentAsImageOnly(rp_state->createInfo, att)) { |
Hans-Kristian Arntzen | dd8acbb | 2021-03-22 13:41:47 +0100 | [diff] [blame] | 2589 | usage = IMAGE_SUBRESOURCE_USAGE_BP::DESCRIPTOR_ACCESS; |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2590 | } |
| 2591 | |
Jeremy Gebben | b20a824 | 2021-11-05 15:14:43 -0600 | [diff] [blame] | 2592 | auto framebuffer = Get<FRAMEBUFFER_STATE>(pRenderPassBegin->framebuffer); |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 2593 | std::shared_ptr<IMAGE_VIEW_STATE> image_view = nullptr; |
Hans-Kristian Arntzen | 9710e14 | 2021-03-18 12:19:02 +0100 | [diff] [blame] | 2594 | |
Tony-LunarG | b3ab357 | 2021-07-02 09:45:17 -0600 | [diff] [blame] | 2595 | if (framebuffer->createInfo.flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) { |
Hans-Kristian Arntzen | 9710e14 | 2021-03-18 12:19:02 +0100 | [diff] [blame] | 2596 | const VkRenderPassAttachmentBeginInfo* rpabi = LvlFindInChain<VkRenderPassAttachmentBeginInfo>(pRenderPassBegin->pNext); |
| 2597 | if (rpabi) { |
Jeremy Gebben | b20a824 | 2021-11-05 15:14:43 -0600 | [diff] [blame] | 2598 | image_view = Get<IMAGE_VIEW_STATE>(rpabi->pAttachments[att]); |
Hans-Kristian Arntzen | 9710e14 | 2021-03-18 12:19:02 +0100 | [diff] [blame] | 2599 | } |
| 2600 | } else { |
Jeremy Gebben | b20a824 | 2021-11-05 15:14:43 -0600 | [diff] [blame] | 2601 | image_view = Get<IMAGE_VIEW_STATE>(framebuffer->createInfo.pAttachments[att]); |
Hans-Kristian Arntzen | 9710e14 | 2021-03-18 12:19:02 +0100 | [diff] [blame] | 2602 | } |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2603 | |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 2604 | QueueValidateImageView(cb->queue_submit_functions, "vkCmdBeginRenderPass()", image_view.get(), usage); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2605 | } |
| 2606 | |
| 2607 | // Check store ops |
| 2608 | for (uint32_t att = 0; att < rp_state->createInfo.attachmentCount; att++) { |
Hans-Kristian Arntzen | 69ace7d | 2021-04-28 14:17:19 +0200 | [diff] [blame] | 2609 | const auto& attachment = rp_state->createInfo.pAttachments[att]; |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2610 | |
| 2611 | if (!RenderPassUsesAttachmentOnTile(rp_state->createInfo, att)) { |
| 2612 | continue; |
| 2613 | } |
| 2614 | |
Hans-Kristian Arntzen | 5b466db | 2021-03-18 13:59:46 +0100 | [diff] [blame] | 2615 | IMAGE_SUBRESOURCE_USAGE_BP usage = IMAGE_SUBRESOURCE_USAGE_BP::RENDER_PASS_DISCARDED; |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2616 | |
| 2617 | if ((!FormatIsStencilOnly(attachment.format) && attachment.storeOp == VK_ATTACHMENT_STORE_OP_STORE) || |
| 2618 | (FormatHasStencil(attachment.format) && attachment.stencilStoreOp == VK_ATTACHMENT_STORE_OP_STORE)) { |
Hans-Kristian Arntzen | 5b466db | 2021-03-18 13:59:46 +0100 | [diff] [blame] | 2619 | usage = IMAGE_SUBRESOURCE_USAGE_BP::RENDER_PASS_STORED; |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2620 | } |
| 2621 | |
Jeremy Gebben | b20a824 | 2021-11-05 15:14:43 -0600 | [diff] [blame] | 2622 | auto framebuffer = Get<FRAMEBUFFER_STATE>(pRenderPassBegin->framebuffer); |
Hans-Kristian Arntzen | 9710e14 | 2021-03-18 12:19:02 +0100 | [diff] [blame] | 2623 | |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 2624 | std::shared_ptr<IMAGE_VIEW_STATE> image_view; |
Tony-LunarG | b3ab357 | 2021-07-02 09:45:17 -0600 | [diff] [blame] | 2625 | if (framebuffer->createInfo.flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) { |
Hans-Kristian Arntzen | 9710e14 | 2021-03-18 12:19:02 +0100 | [diff] [blame] | 2626 | const VkRenderPassAttachmentBeginInfo* rpabi = LvlFindInChain<VkRenderPassAttachmentBeginInfo>(pRenderPassBegin->pNext); |
| 2627 | if (rpabi) { |
Jeremy Gebben | b20a824 | 2021-11-05 15:14:43 -0600 | [diff] [blame] | 2628 | image_view = Get<IMAGE_VIEW_STATE>(rpabi->pAttachments[att]); |
Hans-Kristian Arntzen | 9710e14 | 2021-03-18 12:19:02 +0100 | [diff] [blame] | 2629 | } |
| 2630 | } else { |
Jeremy Gebben | b20a824 | 2021-11-05 15:14:43 -0600 | [diff] [blame] | 2631 | image_view = Get<IMAGE_VIEW_STATE>(framebuffer->createInfo.pAttachments[att]); |
Hans-Kristian Arntzen | 9710e14 | 2021-03-18 12:19:02 +0100 | [diff] [blame] | 2632 | } |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2633 | |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 2634 | QueueValidateImageView(cb->queue_submit_functions_after_render_pass, "vkCmdEndRenderPass()", image_view.get(), usage); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 2635 | } |
| 2636 | } |
| 2637 | } |
| 2638 | |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 2639 | bool BestPractices::PreCallValidateCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, |
| 2640 | VkSubpassContents contents) const { |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 2641 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents); |
| 2642 | skip |= ValidateCmdBeginRenderPass(commandBuffer, RENDER_PASS_VERSION_1, pRenderPassBegin); |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 2643 | return skip; |
| 2644 | } |
| 2645 | |
| 2646 | bool BestPractices::PreCallValidateCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 2647 | const VkRenderPassBeginInfo* pRenderPassBegin, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 2648 | const VkSubpassBeginInfo* pSubpassBeginInfo) const { |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 2649 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass2KHR(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
| 2650 | skip |= ValidateCmdBeginRenderPass(commandBuffer, RENDER_PASS_VERSION_2, pRenderPassBegin); |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 2651 | return skip; |
| 2652 | } |
| 2653 | |
| 2654 | bool BestPractices::PreCallValidateCmdBeginRenderPass2(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 2655 | const VkSubpassBeginInfo* pSubpassBeginInfo) const { |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 2656 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass2(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
| 2657 | skip |= ValidateCmdBeginRenderPass(commandBuffer, RENDER_PASS_VERSION_2, pRenderPassBegin); |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 2658 | return skip; |
| 2659 | } |
| 2660 | |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 2661 | void BestPractices::RecordCmdBeginRenderPass(VkCommandBuffer commandBuffer, RenderPassCreateVersion rp_version, |
| 2662 | const VkRenderPassBeginInfo* pRenderPassBegin) { |
Hans-Kristian Arntzen | a900f5d | 2021-06-14 15:09:31 +0200 | [diff] [blame] | 2663 | // Reset the renderpass state |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 2664 | auto cb = GetWrite<bp_state::CommandBuffer>(commandBuffer); |
sjfricke | 52defd4 | 2022-08-08 16:37:46 +0900 | [diff] [blame] | 2665 | // TODO - move this logic to the Render Pass state as cb->has_draw_cmd should stay true for lifetime of command buffer |
| 2666 | cb->has_draw_cmd = false; |
Jeremy Gebben | 7c2cd8b | 2021-08-11 15:40:38 -0600 | [diff] [blame] | 2667 | assert(cb); |
| 2668 | auto& render_pass_state = cb->render_pass_state; |
Hans-Kristian Arntzen | b658631 | 2021-07-05 11:43:39 +0200 | [diff] [blame] | 2669 | render_pass_state.touchesAttachments.clear(); |
| 2670 | render_pass_state.earlyClearAttachments.clear(); |
Hans-Kristian Arntzen | a900f5d | 2021-06-14 15:09:31 +0200 | [diff] [blame] | 2671 | render_pass_state.numDrawCallsDepthOnly = 0; |
| 2672 | render_pass_state.numDrawCallsDepthEqualCompare = 0; |
| 2673 | render_pass_state.colorAttachment = false; |
| 2674 | render_pass_state.depthAttachment = false; |
Hans-Kristian Arntzen | 8abca1e | 2021-06-16 13:57:45 +0200 | [diff] [blame] | 2675 | render_pass_state.drawTouchAttachments = true; |
Hans-Kristian Arntzen | a900f5d | 2021-06-14 15:09:31 +0200 | [diff] [blame] | 2676 | // Don't reset state related to pipeline state. |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 2677 | |
Rodrigo Locatti | a5eaf6e | 2022-04-01 18:05:23 -0300 | [diff] [blame] | 2678 | // Reset NV state |
| 2679 | cb->nv = {}; |
| 2680 | |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 2681 | auto rp_state = Get<RENDER_PASS_STATE>(pRenderPassBegin->renderPass); |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 2682 | |
| 2683 | // track depth / color attachment usage within the renderpass |
| 2684 | for (size_t i = 0; i < rp_state->createInfo.subpassCount; i++) { |
| 2685 | // record if depth/color attachments are in use for this renderpass |
Hans-Kristian Arntzen | a900f5d | 2021-06-14 15:09:31 +0200 | [diff] [blame] | 2686 | 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] | 2687 | |
Hans-Kristian Arntzen | a900f5d | 2021-06-14 15:09:31 +0200 | [diff] [blame] | 2688 | 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] | 2689 | } |
| 2690 | } |
| 2691 | |
| 2692 | void BestPractices::PostCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, |
| 2693 | VkSubpassContents contents) { |
| 2694 | StateTracker::PostCallRecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents); |
| 2695 | RecordCmdBeginRenderPass(commandBuffer, RENDER_PASS_VERSION_1, pRenderPassBegin); |
| 2696 | } |
| 2697 | |
| 2698 | void BestPractices::PostCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, |
| 2699 | const VkSubpassBeginInfo* pSubpassBeginInfo) { |
| 2700 | StateTracker::PostCallRecordCmdBeginRenderPass2(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
| 2701 | RecordCmdBeginRenderPass(commandBuffer, RENDER_PASS_VERSION_2, pRenderPassBegin); |
| 2702 | } |
| 2703 | |
| 2704 | void BestPractices::PostCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 2705 | const VkRenderPassBeginInfo* pRenderPassBegin, |
| 2706 | const VkSubpassBeginInfo* pSubpassBeginInfo) { |
| 2707 | StateTracker::PostCallRecordCmdBeginRenderPass2KHR(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
| 2708 | RecordCmdBeginRenderPass(commandBuffer, RENDER_PASS_VERSION_2, pRenderPassBegin); |
| 2709 | } |
| 2710 | |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 2711 | // Generic function to handle validation for all CmdDraw* type functions |
| 2712 | bool BestPractices::ValidateCmdDrawType(VkCommandBuffer cmd_buffer, const char* caller) const { |
| 2713 | bool skip = false; |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 2714 | const auto cb_state = GetRead<bp_state::CommandBuffer>(cmd_buffer); |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 2715 | if (cb_state) { |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 2716 | const auto lv_bind_point = ConvertToLvlBindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 2717 | const auto* pipeline_state = cb_state->lastBound[lv_bind_point].pipeline_state; |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 2718 | 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] | 2719 | |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 2720 | // Verify vertex binding |
Tony-LunarG | 2ffe1f5 | 2022-04-11 15:13:30 -0600 | [diff] [blame] | 2721 | if (pipeline_state && pipeline_state->vertex_input_state && |
| 2722 | pipeline_state->vertex_input_state->binding_descriptions.size() <= 0) { |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 2723 | if ((!current_vtx_bfr_binding_info.empty()) && (!cb_state->vertex_buffer_used)) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2724 | skip |= LogPerformanceWarning(cb_state->commandBuffer(), kVUID_BestPractices_DrawState_VtxIndexOutOfBounds, |
Mark Lobodzinski | f95a266 | 2020-01-29 15:43:32 -0700 | [diff] [blame] | 2725 | "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] | 2726 | report_data->FormatHandle(cb_state->commandBuffer()).c_str(), |
| 2727 | report_data->FormatHandle(pipeline_state->pipeline()).c_str()); |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 2728 | } |
| 2729 | } |
Nathaniel Cesario | f7b732a | 2021-06-03 14:08:27 -0600 | [diff] [blame] | 2730 | |
Jeremy Gebben | 159b3cc | 2021-06-03 09:09:03 -0600 | [diff] [blame] | 2731 | const auto* pipe = cb_state->GetCurrentPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS); |
Nathaniel Cesario | f7b732a | 2021-06-03 14:08:27 -0600 | [diff] [blame] | 2732 | if (pipe) { |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2733 | const auto& rp_state = pipe->RenderPassState(); |
Nathaniel Cesario | f7b732a | 2021-06-03 14:08:27 -0600 | [diff] [blame] | 2734 | if (rp_state) { |
| 2735 | for (uint32_t i = 0; i < rp_state->createInfo.subpassCount; ++i) { |
| 2736 | const auto& subpass = rp_state->createInfo.pSubpasses[i]; |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2737 | const auto* ds_state = pipe->DepthStencilState(); |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 2738 | const uint32_t depth_stencil_attachment = |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2739 | GetSubpassDepthStencilAttachmentIndex(ds_state, subpass.pDepthStencilAttachment); |
| 2740 | const auto* raster_state = pipe->RasterizationState(); |
| 2741 | if ((depth_stencil_attachment == VK_ATTACHMENT_UNUSED) && raster_state && |
| 2742 | raster_state->depthBiasEnable == VK_TRUE) { |
Nathaniel Cesario | f7b732a | 2021-06-03 14:08:27 -0600 | [diff] [blame] | 2743 | skip |= LogWarning(cb_state->commandBuffer(), kVUID_BestPractices_DepthBiasNoAttachment, |
| 2744 | "%s: depthBiasEnable == VK_TRUE without a depth-stencil attachment.", caller); |
| 2745 | } |
| 2746 | } |
| 2747 | } |
| 2748 | } |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 2749 | } |
| 2750 | return skip; |
| 2751 | } |
| 2752 | |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 2753 | 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] | 2754 | auto cb_node = GetWrite<bp_state::CommandBuffer>(cmd_buffer); |
Jeremy Gebben | 7c2cd8b | 2021-08-11 15:40:38 -0600 | [diff] [blame] | 2755 | assert(cb_node); |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 2756 | if (VendorCheckEnabled(kBPVendorArm)) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 2757 | RecordCmdDrawTypeArm(*cb_node, draw_count, caller); |
Hans-Kristian Arntzen | 8abca1e | 2021-06-16 13:57:45 +0200 | [diff] [blame] | 2758 | } |
Rodrigo Locatti | 0b16cda | 2022-04-01 17:59:53 -0300 | [diff] [blame^] | 2759 | if (VendorCheckEnabled(kBPVendorNVIDIA)) { |
| 2760 | RecordCmdDrawTypeNVIDIA(*cb_node); |
| 2761 | } |
Hans-Kristian Arntzen | 8abca1e | 2021-06-16 13:57:45 +0200 | [diff] [blame] | 2762 | |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 2763 | if (cb_node->render_pass_state.drawTouchAttachments) { |
| 2764 | for (auto& touch : cb_node->render_pass_state.nextDrawTouchesAttachments) { |
| 2765 | RecordAttachmentAccess(*cb_node, touch.framebufferAttachment, touch.aspects); |
Hans-Kristian Arntzen | 8abca1e | 2021-06-16 13:57:45 +0200 | [diff] [blame] | 2766 | } |
| 2767 | // No need to touch the same attachments over and over. |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 2768 | cb_node->render_pass_state.drawTouchAttachments = false; |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 2769 | } |
| 2770 | } |
| 2771 | |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 2772 | void BestPractices::RecordCmdDrawTypeArm(bp_state::CommandBuffer& cb_node, uint32_t draw_count, const char* caller) { |
| 2773 | auto& render_pass_state = cb_node.render_pass_state; |
LawG4 | b21485c | 2022-02-28 13:46:48 +0000 | [diff] [blame] | 2774 | // Each TBDR vendor requires a depth pre-pass draw call to have a minimum number of vertices/indices before it counts towards |
| 2775 | // depth prepass warnings First find the lowest enabled draw count |
| 2776 | uint32_t lowestEnabledMinDrawCount = 0; |
| 2777 | lowestEnabledMinDrawCount = VendorCheckEnabled(kBPVendorArm) * kDepthPrePassMinDrawCountArm; |
| 2778 | if (VendorCheckEnabled(kBPVendorIMG) && kDepthPrePassMinDrawCountIMG < lowestEnabledMinDrawCount) |
| 2779 | lowestEnabledMinDrawCount = kDepthPrePassMinDrawCountIMG; |
| 2780 | |
| 2781 | if (draw_count >= lowestEnabledMinDrawCount) { |
Hans-Kristian Arntzen | 8abca1e | 2021-06-16 13:57:45 +0200 | [diff] [blame] | 2782 | if (render_pass_state.depthOnly) render_pass_state.numDrawCallsDepthOnly++; |
| 2783 | if (render_pass_state.depthEqualComparison) render_pass_state.numDrawCallsDepthEqualCompare++; |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 2784 | } |
| 2785 | } |
| 2786 | |
Rodrigo Locatti | 0b16cda | 2022-04-01 17:59:53 -0300 | [diff] [blame^] | 2787 | void BestPractices::RecordCmdDrawTypeNVIDIA(bp_state::CommandBuffer& cmd_state) { |
| 2788 | assert(VendorCheckEnabled(kBPVendorNVIDIA)); |
| 2789 | |
| 2790 | if (cmd_state.nv.depth_test_enable && cmd_state.nv.zcull_direction != bp_state::CommandBufferStateNV::ZcullDirection::Unknown) { |
| 2791 | RecordSetScopeZcullDirection(cmd_state, cmd_state.nv.zcull_direction); |
| 2792 | RecordZcullDraw(cmd_state); |
| 2793 | } |
| 2794 | } |
| 2795 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 2796 | bool BestPractices::PreCallValidateCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 2797 | uint32_t firstVertex, uint32_t firstInstance) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 2798 | bool skip = false; |
| 2799 | |
| 2800 | if (instanceCount == 0) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 2801 | skip |= LogWarning(device, kVUID_BestPractices_CmdDraw_InstanceCountZero, |
| 2802 | "Warning: You are calling vkCmdDraw() with an instanceCount of Zero."); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 2803 | } |
Nathaniel Cesario | f7b732a | 2021-06-03 14:08:27 -0600 | [diff] [blame] | 2804 | skip |= ValidateCmdDrawType(commandBuffer, "vkCmdDraw()"); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 2805 | |
| 2806 | return skip; |
| 2807 | } |
| 2808 | |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 2809 | void BestPractices::PostCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
| 2810 | uint32_t firstVertex, uint32_t firstInstance) { |
| 2811 | StateTracker::PostCallRecordCmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance); |
| 2812 | RecordCmdDrawType(commandBuffer, vertexCount * instanceCount, "vkCmdDraw()"); |
| 2813 | } |
| 2814 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 2815 | bool BestPractices::PreCallValidateCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 2816 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 2817 | bool skip = false; |
| 2818 | |
| 2819 | if (instanceCount == 0) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 2820 | skip |= LogWarning(device, kVUID_BestPractices_CmdDraw_InstanceCountZero, |
| 2821 | "Warning: You are calling vkCmdDrawIndexed() with an instanceCount of Zero."); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 2822 | } |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 2823 | skip |= ValidateCmdDrawType(commandBuffer, "vkCmdDrawIndexed()"); |
| 2824 | |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 2825 | // Check if we reached the limit for small indexed draw calls. |
| 2826 | // 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] | 2827 | const auto cmd_state = GetRead<bp_state::CommandBuffer>(commandBuffer); |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 2828 | if ((indexCount * instanceCount) <= kSmallIndexedDrawcallIndices && |
Hans-Kristian Arntzen | b214795 | 2021-04-28 14:32:00 +0200 | [diff] [blame] | 2829 | (cmd_state->small_indexed_draw_call_count == kMaxSmallIndexedDrawcalls - 1) && |
LawG4 | ff42d72 | 2022-03-01 10:28:25 +0000 | [diff] [blame] | 2830 | (VendorCheckEnabled(kBPVendorArm) || VendorCheckEnabled(kBPVendorIMG))) { |
Hans-Kristian Arntzen | b214795 | 2021-04-28 14:32:00 +0200 | [diff] [blame] | 2831 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_CmdDrawIndexed_ManySmallIndexedDrawcalls, |
LawG4 | ff42d72 | 2022-03-01 10:28:25 +0000 | [diff] [blame] | 2832 | "%s %s: The command buffer contains many small indexed drawcalls " |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 2833 | "(at least %u drawcalls with less than %u indices each). This may cause pipeline bubbles. " |
| 2834 | "You can try batching drawcalls or instancing when applicable.", |
LawG4 | ff42d72 | 2022-03-01 10:28:25 +0000 | [diff] [blame] | 2835 | VendorSpecificTag(kBPVendorArm), VendorSpecificTag(kBPVendorIMG), kMaxSmallIndexedDrawcalls, |
| 2836 | kSmallIndexedDrawcallIndices); |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 2837 | } |
| 2838 | |
Sam Walls | 8e77e4f | 2020-03-16 20:47:40 +0000 | [diff] [blame] | 2839 | if (VendorCheckEnabled(kBPVendorArm)) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 2840 | ValidateIndexBufferArm(*cmd_state, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); |
Sam Walls | 8e77e4f | 2020-03-16 20:47:40 +0000 | [diff] [blame] | 2841 | } |
| 2842 | |
| 2843 | return skip; |
| 2844 | } |
| 2845 | |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 2846 | 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] | 2847 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) const { |
| 2848 | bool skip = false; |
| 2849 | |
| 2850 | // check for sparse/underutilised index buffer, and post-transform cache thrashing |
Sam Walls | 8e77e4f | 2020-03-16 20:47:40 +0000 | [diff] [blame] | 2851 | |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 2852 | const auto* ib_state = cmd_state.index_buffer_binding.buffer_state.get(); |
| 2853 | 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] | 2854 | |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 2855 | const VkIndexType ib_type = cmd_state.index_buffer_binding.index_type; |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 2856 | const auto& ib_mem_state = *ib_state->MemState(); |
Sam Walls | 8e77e4f | 2020-03-16 20:47:40 +0000 | [diff] [blame] | 2857 | const VkDeviceSize ib_mem_offset = ib_mem_state.mapped_range.offset; |
| 2858 | const void* ib_mem = ib_mem_state.p_driver_data; |
| 2859 | bool primitive_restart_enable = false; |
| 2860 | |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 2861 | const auto lv_bind_point = ConvertToLvlBindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS); |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 2862 | const auto& pipeline_binding_iter = cmd_state.lastBound[lv_bind_point]; |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 2863 | const auto* pipeline_state = pipeline_binding_iter.pipeline_state; |
Sam Walls | 8e77e4f | 2020-03-16 20:47:40 +0000 | [diff] [blame] | 2864 | |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 2865 | const auto* ia_state = pipeline_state ? pipeline_state->InputAssemblyState() : nullptr; |
| 2866 | if (ia_state) { |
| 2867 | primitive_restart_enable = ia_state->primitiveRestartEnable == VK_TRUE; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2868 | } |
Sam Walls | 8e77e4f | 2020-03-16 20:47:40 +0000 | [diff] [blame] | 2869 | |
| 2870 | // 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] | 2871 | if (ib_mem && pipeline_binding_iter.IsUsing()) { |
Sam Walls | 8e77e4f | 2020-03-16 20:47:40 +0000 | [diff] [blame] | 2872 | uint32_t scan_stride; |
| 2873 | if (ib_type == VK_INDEX_TYPE_UINT8_EXT) { |
| 2874 | scan_stride = sizeof(uint8_t); |
| 2875 | } else if (ib_type == VK_INDEX_TYPE_UINT16) { |
| 2876 | scan_stride = sizeof(uint16_t); |
| 2877 | } else { |
| 2878 | scan_stride = sizeof(uint32_t); |
| 2879 | } |
| 2880 | |
| 2881 | const uint8_t* scan_begin = static_cast<const uint8_t*>(ib_mem) + ib_mem_offset + firstIndex * scan_stride; |
| 2882 | const uint8_t* scan_end = scan_begin + indexCount * scan_stride; |
| 2883 | |
| 2884 | // Min and max are important to track for some Mali architectures. In older Mali devices without IDVS, all |
| 2885 | // vertices corresponding to indices between the minimum and maximum may be loaded, and possibly shaded, |
| 2886 | // irrespective of whether or not they're part of the draw call. |
| 2887 | |
| 2888 | // start with minimum as 0xFFFFFFFF and adjust to indices in the buffer |
| 2889 | uint32_t min_index = ~0u; |
| 2890 | // start with maximum as 0 and adjust to indices in the buffer |
| 2891 | uint32_t max_index = 0u; |
| 2892 | |
| 2893 | // first scan-through, we're looking to simulate a model LRU post-transform cache, estimating the number of vertices shaded |
| 2894 | // for the given index buffer |
| 2895 | uint32_t vertex_shade_count = 0; |
| 2896 | |
| 2897 | PostTransformLRUCacheModel post_transform_cache; |
| 2898 | |
| 2899 | // The size of the cache being modelled positively correlates with how much behaviour it can capture about |
| 2900 | // arbitrary ground-truth hardware/architecture cache behaviour. I.e. it's a good solution when we don't know the |
| 2901 | // target architecture. |
| 2902 | // However, modelling a post-transform cache with more than 32 elements gives diminishing returns in practice. |
| 2903 | // http://eelpi.gotdns.org/papers/fast_vert_cache_opt.html |
| 2904 | post_transform_cache.resize(32); |
| 2905 | |
| 2906 | for (const uint8_t* scan_ptr = scan_begin; scan_ptr < scan_end; scan_ptr += scan_stride) { |
| 2907 | uint32_t scan_index; |
| 2908 | uint32_t primitive_restart_value; |
| 2909 | if (ib_type == VK_INDEX_TYPE_UINT8_EXT) { |
| 2910 | scan_index = *reinterpret_cast<const uint8_t*>(scan_ptr); |
| 2911 | primitive_restart_value = 0xFF; |
| 2912 | } else if (ib_type == VK_INDEX_TYPE_UINT16) { |
| 2913 | scan_index = *reinterpret_cast<const uint16_t*>(scan_ptr); |
| 2914 | primitive_restart_value = 0xFFFF; |
| 2915 | } else { |
| 2916 | scan_index = *reinterpret_cast<const uint32_t*>(scan_ptr); |
| 2917 | primitive_restart_value = 0xFFFFFFFF; |
| 2918 | } |
| 2919 | |
| 2920 | max_index = std::max(max_index, scan_index); |
| 2921 | min_index = std::min(min_index, scan_index); |
| 2922 | |
| 2923 | if (!primitive_restart_enable || scan_index != primitive_restart_value) { |
| 2924 | bool in_cache = post_transform_cache.query_cache(scan_index); |
| 2925 | // if the shaded vertex corresponding to the index is not in the PT-cache, we need to shade again |
| 2926 | if (!in_cache) vertex_shade_count++; |
| 2927 | } |
| 2928 | } |
| 2929 | |
| 2930 | // 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] | 2931 | // 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 |
| 2932 | if (max_index < min_index || max_index == min_index) return skip; |
Sam Walls | 8e77e4f | 2020-03-16 20:47:40 +0000 | [diff] [blame] | 2933 | |
| 2934 | if (max_index - min_index >= indexCount) { |
Mark Young | 0ec6b06 | 2020-11-19 15:32:17 -0700 | [diff] [blame] | 2935 | skip |= |
| 2936 | LogPerformanceWarning(device, kVUID_BestPractices_CmdDrawIndexed_SparseIndexBuffer, |
| 2937 | "%s The indices which were specified for the draw call only utilise approximately %.02f%% of " |
| 2938 | "index buffer value range. Arm Mali architectures before G71 do not have IDVS (Index-Driven " |
| 2939 | "Vertex Shading), meaning all vertices corresponding to indices between the minimum and " |
| 2940 | "maximum would be loaded, and possibly shaded, whether or not they are used.", |
| 2941 | VendorSpecificTag(kBPVendorArm), |
| 2942 | (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] | 2943 | return skip; |
| 2944 | } |
| 2945 | |
| 2946 | // use a dynamic vector of bitsets as a memory-compact representation of which indices are included in the draw call |
| 2947 | // 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] | 2948 | const size_t refs_per_bucket = 64; |
| 2949 | std::vector<std::bitset<refs_per_bucket>> vertex_reference_buckets; |
| 2950 | |
| 2951 | const uint32_t n_indices = max_index - min_index + 1; |
| 2952 | const uint32_t n_buckets = (n_indices / static_cast<uint32_t>(refs_per_bucket)) + |
| 2953 | ((n_indices % static_cast<uint32_t>(refs_per_bucket)) != 0 ? 1 : 0); |
| 2954 | |
| 2955 | // there needs to be at least one bitset to store a set of indices smaller than n_buckets |
| 2956 | vertex_reference_buckets.resize(std::max(1u, n_buckets)); |
Sam Walls | 8e77e4f | 2020-03-16 20:47:40 +0000 | [diff] [blame] | 2957 | |
| 2958 | // To avoid using too much memory, we run over the indices again. |
| 2959 | // Knowing the size from the last scan allows us to record index usage with bitsets |
| 2960 | for (const uint8_t* scan_ptr = scan_begin; scan_ptr < scan_end; scan_ptr += scan_stride) { |
| 2961 | uint32_t scan_index; |
| 2962 | if (ib_type == VK_INDEX_TYPE_UINT8_EXT) { |
| 2963 | scan_index = *reinterpret_cast<const uint8_t*>(scan_ptr); |
| 2964 | } else if (ib_type == VK_INDEX_TYPE_UINT16) { |
| 2965 | scan_index = *reinterpret_cast<const uint16_t*>(scan_ptr); |
| 2966 | } else { |
| 2967 | scan_index = *reinterpret_cast<const uint32_t*>(scan_ptr); |
| 2968 | } |
| 2969 | // keep track of the set of all indices used to reference vertices in the draw call |
| 2970 | size_t index_offset = scan_index - min_index; |
Sam Walls | 61b0689 | 2020-07-23 16:20:50 +0100 | [diff] [blame] | 2971 | size_t bitset_bucket_index = index_offset / refs_per_bucket; |
| 2972 | uint64_t used_indices = 1ull << ((index_offset % refs_per_bucket) & 0xFFFFFFFFu); |
Sam Walls | 8e77e4f | 2020-03-16 20:47:40 +0000 | [diff] [blame] | 2973 | vertex_reference_buckets[bitset_bucket_index] |= used_indices; |
| 2974 | } |
| 2975 | |
| 2976 | uint32_t vertex_reference_count = 0; |
| 2977 | for (const auto& bitset : vertex_reference_buckets) { |
| 2978 | vertex_reference_count += static_cast<uint32_t>(bitset.count()); |
| 2979 | } |
| 2980 | |
| 2981 | // 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] | 2982 | 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] | 2983 | // 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] | 2984 | 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] | 2985 | |
| 2986 | if (utilization < 0.5f) { |
| 2987 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_CmdDrawIndexed_SparseIndexBuffer, |
| 2988 | "%s The indices which were specified for the draw call only utilise approximately " |
| 2989 | "%.02f%% of the bound vertex buffer.", |
| 2990 | VendorSpecificTag(kBPVendorArm), utilization); |
| 2991 | } |
| 2992 | |
| 2993 | if (cache_hit_rate <= 0.5f) { |
| 2994 | skip |= |
| 2995 | LogPerformanceWarning(device, kVUID_BestPractices_CmdDrawIndexed_PostTransformCacheThrashing, |
| 2996 | "%s The indices which were specified for the draw call are estimated to cause thrashing of " |
| 2997 | "the post-transform vertex cache, with a hit-rate of %.02f%%. " |
| 2998 | "I.e. the ordering of the index buffer may not make optimal use of indices associated with " |
| 2999 | "recently shaded vertices.", |
| 3000 | VendorSpecificTag(kBPVendorArm), cache_hit_rate * 100.0f); |
| 3001 | } |
| 3002 | } |
| 3003 | |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 3004 | return skip; |
| 3005 | } |
| 3006 | |
Hans-Kristian Arntzen | b658631 | 2021-07-05 11:43:39 +0200 | [diff] [blame] | 3007 | bool BestPractices::PreCallValidateCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBufferCount, |
| 3008 | const VkCommandBuffer* pCommandBuffers) const { |
| 3009 | bool skip = false; |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 3010 | const auto primary = GetRead<bp_state::CommandBuffer>(commandBuffer); |
Hans-Kristian Arntzen | b658631 | 2021-07-05 11:43:39 +0200 | [diff] [blame] | 3011 | for (uint32_t i = 0; i < commandBufferCount; i++) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 3012 | const auto secondary_cb = GetRead<bp_state::CommandBuffer>(pCommandBuffers[i]); |
Jeremy Gebben | 7c2cd8b | 2021-08-11 15:40:38 -0600 | [diff] [blame] | 3013 | if (secondary_cb == nullptr) { |
Hans-Kristian Arntzen | b658631 | 2021-07-05 11:43:39 +0200 | [diff] [blame] | 3014 | continue; |
| 3015 | } |
Jeremy Gebben | 7c2cd8b | 2021-08-11 15:40:38 -0600 | [diff] [blame] | 3016 | const auto& secondary = secondary_cb->render_pass_state; |
Hans-Kristian Arntzen | b658631 | 2021-07-05 11:43:39 +0200 | [diff] [blame] | 3017 | for (auto& clear : secondary.earlyClearAttachments) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 3018 | if (ClearAttachmentsIsFullClear(*primary, uint32_t(clear.rects.size()), clear.rects.data())) { |
| 3019 | skip |= ValidateClearAttachment(*primary, clear.framebufferAttachment, clear.colorAttachment, clear.aspects, true); |
Hans-Kristian Arntzen | b658631 | 2021-07-05 11:43:39 +0200 | [diff] [blame] | 3020 | } |
| 3021 | } |
| 3022 | } |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 3023 | |
| 3024 | if (VendorCheckEnabled(kBPVendorAMD)) { |
| 3025 | if (commandBufferCount > 0) { |
| 3026 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_CmdBuffer_AvoidSecondaryCmdBuffers, |
| 3027 | "%s Performance warning: Use of secondary command buffers is not recommended. ", |
| 3028 | VendorSpecificTag(kBPVendorAMD)); |
| 3029 | } |
| 3030 | } |
Hans-Kristian Arntzen | b658631 | 2021-07-05 11:43:39 +0200 | [diff] [blame] | 3031 | return skip; |
| 3032 | } |
| 3033 | |
| 3034 | void BestPractices::PreCallRecordCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBufferCount, |
| 3035 | const VkCommandBuffer* pCommandBuffers) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 3036 | ValidationStateTracker::PreCallRecordCmdExecuteCommands(commandBuffer, commandBufferCount, pCommandBuffers); |
| 3037 | |
| 3038 | auto primary = GetWrite<bp_state::CommandBuffer>(commandBuffer); |
| 3039 | if (!primary) { |
| 3040 | return; |
| 3041 | } |
Hans-Kristian Arntzen | b658631 | 2021-07-05 11:43:39 +0200 | [diff] [blame] | 3042 | |
| 3043 | for (uint32_t i = 0; i < commandBufferCount; i++) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 3044 | auto secondary = GetWrite<bp_state::CommandBuffer>(pCommandBuffers[i]); |
| 3045 | if (!secondary) { |
Jeremy Gebben | 7c2cd8b | 2021-08-11 15:40:38 -0600 | [diff] [blame] | 3046 | continue; |
| 3047 | } |
Hans-Kristian Arntzen | b658631 | 2021-07-05 11:43:39 +0200 | [diff] [blame] | 3048 | |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 3049 | for (auto& early_clear : secondary->render_pass_state.earlyClearAttachments) { |
| 3050 | if (ClearAttachmentsIsFullClear(*primary, uint32_t(early_clear.rects.size()), early_clear.rects.data())) { |
| 3051 | RecordAttachmentClearAttachments(*primary, early_clear.framebufferAttachment, early_clear.colorAttachment, |
| 3052 | 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] | 3053 | } else { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 3054 | RecordAttachmentAccess(*primary, early_clear.framebufferAttachment, early_clear.aspects); |
Hans-Kristian Arntzen | b658631 | 2021-07-05 11:43:39 +0200 | [diff] [blame] | 3055 | } |
| 3056 | } |
| 3057 | |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 3058 | for (auto& touch : secondary->render_pass_state.touchesAttachments) { |
| 3059 | RecordAttachmentAccess(*primary, touch.framebufferAttachment, touch.aspects); |
Hans-Kristian Arntzen | b658631 | 2021-07-05 11:43:39 +0200 | [diff] [blame] | 3060 | } |
Hans-Kristian Arntzen | c7eb82a | 2021-06-16 13:57:18 +0200 | [diff] [blame] | 3061 | |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 3062 | primary->render_pass_state.numDrawCallsDepthEqualCompare += secondary->render_pass_state.numDrawCallsDepthEqualCompare; |
| 3063 | primary->render_pass_state.numDrawCallsDepthOnly += secondary->render_pass_state.numDrawCallsDepthOnly; |
Hans-Kristian Arntzen | b658631 | 2021-07-05 11:43:39 +0200 | [diff] [blame] | 3064 | } |
| 3065 | |
Hans-Kristian Arntzen | b658631 | 2021-07-05 11:43:39 +0200 | [diff] [blame] | 3066 | } |
| 3067 | |
Rodrigo Locatti | 7d716e1 | 2022-03-09 19:15:17 -0300 | [diff] [blame] | 3068 | bool BestPractices::PreCallValidateCmdBuildAccelerationStructureNV(VkCommandBuffer commandBuffer, |
| 3069 | const VkAccelerationStructureInfoNV* pInfo, |
| 3070 | VkBuffer instanceData, VkDeviceSize instanceOffset, |
| 3071 | VkBool32 update, VkAccelerationStructureNV dst, |
| 3072 | VkAccelerationStructureNV src, VkBuffer scratch, |
| 3073 | VkDeviceSize scratchOffset) const { |
| 3074 | return ValidateBuildAccelerationStructure(commandBuffer); |
| 3075 | } |
| 3076 | |
| 3077 | bool BestPractices::PreCallValidateCmdBuildAccelerationStructuresIndirectKHR( |
| 3078 | VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR* pInfos, |
| 3079 | const VkDeviceAddress* pIndirectDeviceAddresses, const uint32_t* pIndirectStrides, |
| 3080 | const uint32_t* const* ppMaxPrimitiveCounts) const { |
| 3081 | return ValidateBuildAccelerationStructure(commandBuffer); |
| 3082 | } |
| 3083 | |
| 3084 | bool BestPractices::PreCallValidateCmdBuildAccelerationStructuresKHR( |
| 3085 | VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR* pInfos, |
| 3086 | const VkAccelerationStructureBuildRangeInfoKHR* const* ppBuildRangeInfos) const { |
| 3087 | return ValidateBuildAccelerationStructure(commandBuffer); |
| 3088 | } |
| 3089 | |
| 3090 | bool BestPractices::ValidateBuildAccelerationStructure(VkCommandBuffer commandBuffer) const { |
| 3091 | bool skip = false; |
| 3092 | auto cb_node = GetRead<bp_state::CommandBuffer>(commandBuffer); |
| 3093 | assert(cb_node); |
| 3094 | |
| 3095 | if (VendorCheckEnabled(kBPVendorNVIDIA)) { |
| 3096 | if ((cb_node->GetQueueFlags() & VK_QUEUE_GRAPHICS_BIT) != 0) { |
| 3097 | skip |= LogPerformanceWarning(commandBuffer, kVUID_BestPractices_AccelerationStructure_NotAsync, |
| 3098 | "%s Performance warning: Prefer building acceleration structures on an asynchronous " |
| 3099 | "compute queue, instead of using the universal graphics queue.", |
| 3100 | VendorSpecificTag(kBPVendorNVIDIA)); |
| 3101 | } |
| 3102 | } |
| 3103 | |
| 3104 | return skip; |
| 3105 | } |
| 3106 | |
Rodrigo Locatti | 66b2335 | 2022-03-15 17:28:32 -0300 | [diff] [blame] | 3107 | bool BestPractices::ValidateBindMemory(VkDevice device, VkDeviceMemory memory) const { |
| 3108 | bool skip = false; |
| 3109 | |
| 3110 | if (VendorCheckEnabled(kBPVendorNVIDIA) && device_extensions.vk_ext_pageable_device_local_memory) { |
| 3111 | auto mem_info = std::static_pointer_cast<const bp_state::DeviceMemory>(Get<DEVICE_MEMORY_STATE>(memory)); |
| 3112 | if (!mem_info->dynamic_priority) { |
| 3113 | skip |= |
| 3114 | LogPerformanceWarning(device, kVUID_BestPractices_BindMemory_NoPriority, |
| 3115 | "%s Use vkSetDeviceMemoryPriorityEXT to provide the OS with information on which allocations " |
| 3116 | "should stay in memory and which should be demoted first when video memory is limited. The " |
| 3117 | "highest priority should be given to GPU-written resources like color attachments, depth " |
| 3118 | "attachments, storage images, and buffers written from the GPU.", |
| 3119 | VendorSpecificTag(kBPVendorNVIDIA)); |
| 3120 | } |
| 3121 | } |
| 3122 | |
| 3123 | return skip; |
| 3124 | } |
| 3125 | |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 3126 | void BestPractices::RecordAttachmentAccess(bp_state::CommandBuffer& cb_state, uint32_t fb_attachment, VkImageAspectFlags aspects) { |
| 3127 | auto& state = cb_state.render_pass_state; |
Hans-Kristian Arntzen | b658631 | 2021-07-05 11:43:39 +0200 | [diff] [blame] | 3128 | // 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] | 3129 | auto itr = |
| 3130 | std::find_if(state.touchesAttachments.begin(), state.touchesAttachments.end(), |
| 3131 | [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] | 3132 | |
| 3133 | if (itr != state.touchesAttachments.end()) { |
| 3134 | itr->aspects |= aspects; |
| 3135 | } else { |
| 3136 | state.touchesAttachments.push_back({ fb_attachment, aspects }); |
| 3137 | } |
| 3138 | } |
| 3139 | |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 3140 | void BestPractices::RecordAttachmentClearAttachments(bp_state::CommandBuffer& cmd_state, uint32_t fb_attachment, |
Jeremy Gebben | 7c2cd8b | 2021-08-11 15:40:38 -0600 | [diff] [blame] | 3141 | uint32_t color_attachment, VkImageAspectFlags aspects, uint32_t rectCount, |
| 3142 | const VkClearRect* pRects) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 3143 | auto& state = cmd_state.render_pass_state; |
Hans-Kristian Arntzen | b658631 | 2021-07-05 11:43:39 +0200 | [diff] [blame] | 3144 | // If we observe a full clear before any other access to a frame buffer attachment, |
| 3145 | // we have candidate for redundant clear attachments. |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 3146 | auto itr = |
| 3147 | std::find_if(state.touchesAttachments.begin(), state.touchesAttachments.end(), |
| 3148 | [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] | 3149 | |
| 3150 | uint32_t new_aspects = aspects; |
| 3151 | if (itr != state.touchesAttachments.end()) { |
| 3152 | new_aspects = aspects & ~itr->aspects; |
| 3153 | itr->aspects |= aspects; |
| 3154 | } else { |
| 3155 | state.touchesAttachments.push_back({ fb_attachment, aspects }); |
| 3156 | } |
| 3157 | |
| 3158 | if (new_aspects == 0) { |
| 3159 | return; |
| 3160 | } |
| 3161 | |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 3162 | if (cmd_state.createInfo.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) { |
Hans-Kristian Arntzen | b658631 | 2021-07-05 11:43:39 +0200 | [diff] [blame] | 3163 | // The first command might be a clear, but might not be the first in the render pass, defer any checks until |
| 3164 | // CmdExecuteCommands. |
| 3165 | state.earlyClearAttachments.push_back({ fb_attachment, color_attachment, new_aspects, |
| 3166 | std::vector<VkClearRect>{pRects, pRects + rectCount} }); |
| 3167 | } |
| 3168 | } |
| 3169 | |
| 3170 | void BestPractices::PreCallRecordCmdClearAttachments(VkCommandBuffer commandBuffer, |
| 3171 | uint32_t attachmentCount, const VkClearAttachment* pClearAttachments, |
| 3172 | uint32_t rectCount, const VkClearRect* pRects) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 3173 | ValidationStateTracker::PreCallRecordCmdClearAttachments(commandBuffer, attachmentCount, pClearAttachments, rectCount, pRects); |
| 3174 | |
| 3175 | auto cmd_state = GetWrite<bp_state::CommandBuffer>(commandBuffer); |
| 3176 | auto* rp_state = cmd_state->activeRenderPass.get(); |
| 3177 | auto* fb_state = cmd_state->activeFramebuffer.get(); |
Hans-Kristian Arntzen | b658631 | 2021-07-05 11:43:39 +0200 | [diff] [blame] | 3178 | bool is_secondary = cmd_state->createInfo.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY; |
| 3179 | |
| 3180 | if (rectCount == 0 || !rp_state) { |
| 3181 | return; |
| 3182 | } |
| 3183 | |
Rodrigo Locatti | 0b16cda | 2022-04-01 17:59:53 -0300 | [diff] [blame^] | 3184 | if (!is_secondary && !fb_state && !rp_state->use_dynamic_rendering && !rp_state->use_dynamic_rendering_inherited) { |
Hans-Kristian Arntzen | b658631 | 2021-07-05 11:43:39 +0200 | [diff] [blame] | 3185 | return; |
| 3186 | } |
| 3187 | |
| 3188 | // If we have a rect which covers the entire frame buffer, we have a LOAD_OP_CLEAR-like command. |
Rodrigo Locatti | 0b16cda | 2022-04-01 17:59:53 -0300 | [diff] [blame^] | 3189 | const bool full_clear = ClearAttachmentsIsFullClear(*cmd_state, rectCount, pRects); |
Hans-Kristian Arntzen | b658631 | 2021-07-05 11:43:39 +0200 | [diff] [blame] | 3190 | |
Rodrigo Locatti | 0b16cda | 2022-04-01 17:59:53 -0300 | [diff] [blame^] | 3191 | if (rp_state->UsesDynamicRendering()) { |
| 3192 | if (VendorCheckEnabled(kBPVendorNVIDIA)) { |
| 3193 | for (uint32_t i = 0; i < attachmentCount; i++) { |
| 3194 | if (pClearAttachments[i].aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) { |
| 3195 | RecordResetScopeZcullDirection(*cmd_state); |
| 3196 | } |
| 3197 | } |
| 3198 | } |
| 3199 | |
| 3200 | // TODO: Implement other best practices for dynamic rendering |
| 3201 | |
| 3202 | } else { |
ziga-lunarg | 885c654 | 2022-03-07 01:08:25 +0100 | [diff] [blame] | 3203 | auto& subpass = rp_state->createInfo.pSubpasses[cmd_state->activeSubpass]; |
| 3204 | for (uint32_t i = 0; i < attachmentCount; i++) { |
| 3205 | auto& attachment = pClearAttachments[i]; |
| 3206 | uint32_t fb_attachment = VK_ATTACHMENT_UNUSED; |
| 3207 | VkImageAspectFlags aspects = attachment.aspectMask; |
Hans-Kristian Arntzen | b658631 | 2021-07-05 11:43:39 +0200 | [diff] [blame] | 3208 | |
Rodrigo Locatti | 0b16cda | 2022-04-01 17:59:53 -0300 | [diff] [blame^] | 3209 | if (aspects & VK_IMAGE_ASPECT_DEPTH_BIT) { |
| 3210 | if (VendorCheckEnabled(kBPVendorNVIDIA)) { |
| 3211 | RecordResetScopeZcullDirection(*cmd_state); |
| 3212 | } |
| 3213 | } |
ziga-lunarg | 885c654 | 2022-03-07 01:08:25 +0100 | [diff] [blame] | 3214 | if (aspects & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) { |
| 3215 | if (subpass.pDepthStencilAttachment) { |
| 3216 | fb_attachment = subpass.pDepthStencilAttachment->attachment; |
| 3217 | } |
| 3218 | } else if (aspects & VK_IMAGE_ASPECT_COLOR_BIT) { |
| 3219 | fb_attachment = subpass.pColorAttachments[attachment.colorAttachment].attachment; |
Hans-Kristian Arntzen | b658631 | 2021-07-05 11:43:39 +0200 | [diff] [blame] | 3220 | } |
ziga-lunarg | 885c654 | 2022-03-07 01:08:25 +0100 | [diff] [blame] | 3221 | if (fb_attachment != VK_ATTACHMENT_UNUSED) { |
| 3222 | if (full_clear) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 3223 | RecordAttachmentClearAttachments(*cmd_state, fb_attachment, attachment.colorAttachment, |
ziga-lunarg | 885c654 | 2022-03-07 01:08:25 +0100 | [diff] [blame] | 3224 | aspects, rectCount, pRects); |
| 3225 | } else { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 3226 | RecordAttachmentAccess(*cmd_state, fb_attachment, aspects); |
ziga-lunarg | 885c654 | 2022-03-07 01:08:25 +0100 | [diff] [blame] | 3227 | } |
Hans-Kristian Arntzen | b658631 | 2021-07-05 11:43:39 +0200 | [diff] [blame] | 3228 | } |
| 3229 | } |
| 3230 | } |
Hans-Kristian Arntzen | b658631 | 2021-07-05 11:43:39 +0200 | [diff] [blame] | 3231 | } |
| 3232 | |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 3233 | void BestPractices::PreCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
| 3234 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) { |
| 3235 | ValidationStateTracker::PreCallRecordCmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, |
| 3236 | firstInstance); |
| 3237 | |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 3238 | auto cmd_state = GetWrite<bp_state::CommandBuffer>(commandBuffer); |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 3239 | if ((indexCount * instanceCount) <= kSmallIndexedDrawcallIndices) { |
| 3240 | cmd_state->small_indexed_draw_call_count++; |
| 3241 | } |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 3242 | |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 3243 | ValidateBoundDescriptorSets(*cmd_state, "vkCmdDrawIndexed()"); |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 3244 | } |
| 3245 | |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 3246 | void BestPractices::PostCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
| 3247 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) { |
| 3248 | StateTracker::PostCallRecordCmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); |
| 3249 | RecordCmdDrawType(commandBuffer, indexCount * instanceCount, "vkCmdDrawIndexed()"); |
| 3250 | } |
| 3251 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 3252 | bool BestPractices::PreCallValidateCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 3253 | uint32_t drawCount, uint32_t stride) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 3254 | bool skip = false; |
| 3255 | |
| 3256 | if (drawCount == 0) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 3257 | skip |= LogWarning(device, kVUID_BestPractices_CmdDraw_DrawCountZero, |
| 3258 | "Warning: You are calling vkCmdDrawIndirect() with a drawCount of Zero."); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 3259 | } |
| 3260 | |
Rodrigo Locatti | 8419cde | 2022-03-30 18:45:13 -0300 | [diff] [blame] | 3261 | skip |= ValidateCmdDrawType(commandBuffer, "vkCmdDrawIndirect()"); |
| 3262 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 3263 | return skip; |
| 3264 | } |
| 3265 | |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 3266 | void BestPractices::PostCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3267 | uint32_t count, uint32_t stride) { |
| 3268 | StateTracker::PostCallRecordCmdDrawIndirect(commandBuffer, buffer, offset, count, stride); |
| 3269 | RecordCmdDrawType(commandBuffer, count, "vkCmdDrawIndirect()"); |
| 3270 | } |
| 3271 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 3272 | bool BestPractices::PreCallValidateCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 3273 | uint32_t drawCount, uint32_t stride) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 3274 | bool skip = false; |
| 3275 | |
| 3276 | if (drawCount == 0) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 3277 | skip |= LogWarning(device, kVUID_BestPractices_CmdDraw_DrawCountZero, |
| 3278 | "Warning: You are calling vkCmdDrawIndexedIndirect() with a drawCount of Zero."); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 3279 | } |
| 3280 | |
Rodrigo Locatti | 8419cde | 2022-03-30 18:45:13 -0300 | [diff] [blame] | 3281 | skip |= ValidateCmdDrawType(commandBuffer, "vkCmdDrawIndexedIndirect()"); |
| 3282 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 3283 | return skip; |
| 3284 | } |
| 3285 | |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 3286 | void BestPractices::PostCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3287 | uint32_t count, uint32_t stride) { |
| 3288 | StateTracker::PostCallRecordCmdDrawIndexedIndirect(commandBuffer, buffer, offset, count, stride); |
| 3289 | RecordCmdDrawType(commandBuffer, count, "vkCmdDrawIndexedIndirect()"); |
| 3290 | } |
| 3291 | |
Rodrigo Locatti | 467344a | 2022-03-30 18:48:13 -0300 | [diff] [blame] | 3292 | bool BestPractices::PreCallValidateCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3293 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 3294 | uint32_t maxDrawCount, uint32_t stride) const { |
| 3295 | bool skip = ValidateCmdDrawType(commandBuffer, "vkCmdDrawIndexedIndirectCount()"); |
| 3296 | |
| 3297 | return skip; |
| 3298 | } |
| 3299 | |
| 3300 | void BestPractices::PostCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3301 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 3302 | uint32_t maxDrawCount, uint32_t stride) { |
| 3303 | StateTracker::PostCallRecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 3304 | maxDrawCount, stride); |
| 3305 | RecordCmdDrawType(commandBuffer, 0, "vkCmdDrawIndexedIndirectCount()"); |
| 3306 | } |
| 3307 | |
| 3308 | bool BestPractices::PreCallValidateCmdDrawIndexedIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 3309 | VkDeviceSize offset, VkBuffer countBuffer, |
| 3310 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 3311 | uint32_t stride) const { |
| 3312 | bool skip = ValidateCmdDrawType(commandBuffer, "vkCmdDrawIndexedIndirectCountAMD"); |
| 3313 | |
| 3314 | return skip; |
| 3315 | } |
| 3316 | |
| 3317 | void BestPractices::PostCallRecordCmdDrawIndexedIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 3318 | VkDeviceSize offset, VkBuffer countBuffer, |
| 3319 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 3320 | uint32_t stride) { |
| 3321 | StateTracker::PostCallRecordCmdDrawIndexedIndirectCountAMD(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 3322 | maxDrawCount, stride); |
| 3323 | RecordCmdDrawType(commandBuffer, 0, "vkCmdDrawIndexedIndirectCountAMD()"); |
| 3324 | } |
| 3325 | |
| 3326 | bool BestPractices::PreCallValidateCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 3327 | VkDeviceSize offset, VkBuffer countBuffer, |
| 3328 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 3329 | uint32_t stride) const { |
| 3330 | bool skip = ValidateCmdDrawType(commandBuffer, "vkCmdDrawIndexedIndirectCountKHR"); |
| 3331 | |
| 3332 | return skip; |
| 3333 | } |
| 3334 | |
| 3335 | void BestPractices::PostCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 3336 | VkDeviceSize offset, VkBuffer countBuffer, |
| 3337 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 3338 | uint32_t stride) { |
| 3339 | StateTracker::PostCallRecordCmdDrawIndexedIndirectCountKHR(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 3340 | maxDrawCount, stride); |
| 3341 | RecordCmdDrawType(commandBuffer, 0, "vkCmdDrawIndexedIndirectCountKHR()"); |
| 3342 | } |
| 3343 | |
| 3344 | bool BestPractices::PreCallValidateCmdDrawIndirectByteCountEXT(VkCommandBuffer commandBuffer, uint32_t instanceCount, |
| 3345 | uint32_t firstInstance, VkBuffer counterBuffer, |
| 3346 | VkDeviceSize counterBufferOffset, uint32_t counterOffset, |
| 3347 | uint32_t vertexStride) const { |
| 3348 | bool skip = ValidateCmdDrawType(commandBuffer, "vkCmdDrawIndirectByteCountEXT"); |
| 3349 | |
| 3350 | return skip; |
| 3351 | } |
| 3352 | |
| 3353 | void BestPractices::PostCallRecordCmdDrawIndirectByteCountEXT(VkCommandBuffer commandBuffer, uint32_t instanceCount, |
| 3354 | uint32_t firstInstance, VkBuffer counterBuffer, |
| 3355 | VkDeviceSize counterBufferOffset, uint32_t counterOffset, |
| 3356 | uint32_t vertexStride) { |
| 3357 | StateTracker::PostCallRecordCmdDrawIndirectByteCountEXT(commandBuffer, instanceCount, firstInstance, counterBuffer, |
| 3358 | counterBufferOffset, counterOffset, vertexStride); |
| 3359 | RecordCmdDrawType(commandBuffer, 0, "vkCmdDrawIndirectByteCountEXT()"); |
| 3360 | } |
| 3361 | |
| 3362 | bool BestPractices::PreCallValidateCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3363 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 3364 | uint32_t stride) const { |
| 3365 | bool skip = ValidateCmdDrawType(commandBuffer, "vkCmdDrawIndirectCount"); |
| 3366 | |
| 3367 | return skip; |
| 3368 | } |
| 3369 | |
| 3370 | void BestPractices::PostCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3371 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 3372 | uint32_t stride) { |
| 3373 | StateTracker::PostCallRecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, |
| 3374 | stride); |
| 3375 | RecordCmdDrawType(commandBuffer, 0, "vkCmdDrawIndirectCount()"); |
| 3376 | } |
| 3377 | |
| 3378 | bool BestPractices::PreCallValidateCmdDrawIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3379 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 3380 | uint32_t maxDrawCount, uint32_t stride) const { |
| 3381 | bool skip = ValidateCmdDrawType(commandBuffer, "vkCmdDrawIndirectCountAMD"); |
| 3382 | |
| 3383 | return skip; |
| 3384 | } |
| 3385 | |
| 3386 | void BestPractices::PostCallRecordCmdDrawIndirectCountAMD(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3387 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 3388 | uint32_t maxDrawCount, uint32_t stride) { |
| 3389 | StateTracker::PostCallRecordCmdDrawIndirectCountAMD(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, |
| 3390 | stride); |
| 3391 | RecordCmdDrawType(commandBuffer, 0, "vkCmdDrawIndirectCountAMD()"); |
| 3392 | } |
| 3393 | |
| 3394 | bool BestPractices::PreCallValidateCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3395 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 3396 | uint32_t maxDrawCount, uint32_t stride) const { |
| 3397 | bool skip = ValidateCmdDrawType(commandBuffer, "vkCmdDrawIndirectCountKHR"); |
| 3398 | |
| 3399 | return skip; |
| 3400 | } |
| 3401 | |
| 3402 | void BestPractices::PostCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3403 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 3404 | uint32_t maxDrawCount, uint32_t stride) { |
| 3405 | StateTracker::PostCallRecordCmdDrawIndirectCountKHR(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, |
| 3406 | stride); |
| 3407 | RecordCmdDrawType(commandBuffer, 0, "vkCmdDrawIndirectCountKHR()"); |
| 3408 | } |
| 3409 | |
| 3410 | bool BestPractices::PreCallValidateCmdDrawMeshTasksIndirectCountNV(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 3411 | VkDeviceSize offset, VkBuffer countBuffer, |
| 3412 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 3413 | uint32_t stride) const { |
| 3414 | bool skip = ValidateCmdDrawType(commandBuffer, "vkCmdDrawMeshTasksIndirectCountNV"); |
| 3415 | |
| 3416 | return skip; |
| 3417 | } |
| 3418 | |
| 3419 | void BestPractices::PostCallRecordCmdDrawMeshTasksIndirectCountNV(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 3420 | VkDeviceSize offset, VkBuffer countBuffer, |
| 3421 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 3422 | uint32_t stride) { |
| 3423 | StateTracker::PostCallRecordCmdDrawMeshTasksIndirectCountNV(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 3424 | maxDrawCount, stride); |
| 3425 | RecordCmdDrawType(commandBuffer, 0, "vkCmdDrawMeshTasksIndirectCountNV()"); |
| 3426 | } |
| 3427 | |
| 3428 | bool BestPractices::PreCallValidateCmdDrawMeshTasksIndirectNV(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3429 | uint32_t drawCount, uint32_t stride) const { |
| 3430 | bool skip = ValidateCmdDrawType(commandBuffer, "vkCmdDrawMeshTasksIndirectNV"); |
| 3431 | |
| 3432 | return skip; |
| 3433 | } |
| 3434 | |
| 3435 | void BestPractices::PostCallRecordCmdDrawMeshTasksIndirectNV(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3436 | uint32_t drawCount, uint32_t stride) { |
| 3437 | StateTracker::PostCallRecordCmdDrawMeshTasksIndirectNV(commandBuffer, buffer, offset, drawCount, stride); |
| 3438 | RecordCmdDrawType(commandBuffer, 0, "vkCmdDrawMeshTasksIndirectNV()"); |
| 3439 | } |
| 3440 | |
| 3441 | bool BestPractices::PreCallValidateCmdDrawMeshTasksNV(VkCommandBuffer commandBuffer, uint32_t taskCount, uint32_t firstTask) const { |
| 3442 | bool skip = ValidateCmdDrawType(commandBuffer, "vkCmdDrawMeshTasksNV"); |
| 3443 | |
| 3444 | return skip; |
| 3445 | } |
| 3446 | |
| 3447 | void BestPractices::PostCallRecordCmdDrawMeshTasksNV(VkCommandBuffer commandBuffer, uint32_t taskCount, uint32_t firstTask) { |
| 3448 | StateTracker::PostCallRecordCmdDrawMeshTasksNV(commandBuffer, taskCount, firstTask); |
| 3449 | RecordCmdDrawType(commandBuffer, 0, "vkCmdDrawMeshTasksNV()"); |
| 3450 | } |
| 3451 | |
| 3452 | bool BestPractices::PreCallValidateCmdDrawMultiIndexedEXT(VkCommandBuffer commandBuffer, uint32_t drawCount, |
| 3453 | const VkMultiDrawIndexedInfoEXT* pIndexInfo, uint32_t instanceCount, |
| 3454 | uint32_t firstInstance, uint32_t stride, |
| 3455 | const int32_t* pVertexOffset) const { |
| 3456 | bool skip = ValidateCmdDrawType(commandBuffer, "vkCmdDrawMultiIndexedEXT"); |
| 3457 | |
| 3458 | return skip; |
| 3459 | } |
| 3460 | |
| 3461 | void BestPractices::PostCallRecordCmdDrawMultiIndexedEXT(VkCommandBuffer commandBuffer, uint32_t drawCount, |
| 3462 | const VkMultiDrawIndexedInfoEXT* pIndexInfo, uint32_t instanceCount, |
| 3463 | uint32_t firstInstance, uint32_t stride, const int32_t* pVertexOffset) { |
| 3464 | StateTracker::PostCallRecordCmdDrawMultiIndexedEXT(commandBuffer, drawCount, pIndexInfo, instanceCount, firstInstance, stride, |
| 3465 | pVertexOffset); |
| 3466 | uint32_t count = 0; |
| 3467 | for (uint32_t i = 0; i < drawCount; ++i) { |
| 3468 | count += pIndexInfo[i].indexCount; |
| 3469 | } |
| 3470 | RecordCmdDrawType(commandBuffer, count, "vkCmdDrawMultiIndexedEXT()"); |
| 3471 | } |
| 3472 | |
| 3473 | bool BestPractices::PreCallValidateCmdDrawMultiEXT(VkCommandBuffer commandBuffer, uint32_t drawCount, const VkMultiDrawInfoEXT* pVertexInfo, |
| 3474 | uint32_t instanceCount, uint32_t firstInstance, uint32_t stride) const { |
| 3475 | bool skip = ValidateCmdDrawType(commandBuffer, "vkCmdDrawMultiEXT"); |
| 3476 | |
| 3477 | return skip; |
| 3478 | } |
| 3479 | |
| 3480 | void BestPractices::PostCallRecordCmdDrawMultiEXT(VkCommandBuffer commandBuffer, uint32_t drawCount, |
| 3481 | const VkMultiDrawInfoEXT* pVertexInfo, uint32_t instanceCount, |
| 3482 | uint32_t firstInstance, uint32_t stride) { |
| 3483 | StateTracker::PostCallRecordCmdDrawMultiEXT(commandBuffer, drawCount, pVertexInfo, instanceCount, firstInstance, stride); |
| 3484 | uint32_t count = 0; |
| 3485 | for (uint32_t i = 0; i < drawCount; ++i) { |
| 3486 | count += pVertexInfo[i].vertexCount; |
| 3487 | } |
| 3488 | RecordCmdDrawType(commandBuffer, count, "vkCmdDrawMultiEXT()"); |
| 3489 | } |
| 3490 | |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 3491 | void BestPractices::ValidateBoundDescriptorSets(bp_state::CommandBuffer& cb_state, const char* function_name) { |
| 3492 | for (auto descriptor_set : cb_state.validated_descriptor_sets) { |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 3493 | for (const auto& binding : *descriptor_set) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 3494 | // For bindless scenarios, we should not attempt to track descriptor set state. |
| 3495 | // It is highly uncertain which resources are actually bound. |
| 3496 | // 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] | 3497 | if (binding->binding_flags & (VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT | VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT | |
| 3498 | VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT)) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 3499 | continue; |
| 3500 | } |
Hans-Kristian Arntzen | a819901 | 2021-03-22 12:10:07 +0100 | [diff] [blame] | 3501 | |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 3502 | for (uint32_t i = 0; i < binding->count; ++i) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 3503 | VkImageView image_view{VK_NULL_HANDLE}; |
| 3504 | |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 3505 | auto descriptor = binding->GetDescriptor(i); |
ziga-lunarg | 33d806c | 2022-05-05 17:00:52 +0200 | [diff] [blame] | 3506 | if (!descriptor) { |
| 3507 | continue; |
| 3508 | } |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 3509 | switch (descriptor->GetClass()) { |
| 3510 | case cvdescriptorset::DescriptorClass::Image: { |
| 3511 | if (const auto image_descriptor = static_cast<const cvdescriptorset::ImageDescriptor*>(descriptor)) { |
| 3512 | image_view = image_descriptor->GetImageView(); |
| 3513 | } |
| 3514 | break; |
| 3515 | } |
| 3516 | case cvdescriptorset::DescriptorClass::ImageSampler: { |
| 3517 | if (const auto image_sampler_descriptor = |
| 3518 | static_cast<const cvdescriptorset::ImageSamplerDescriptor*>(descriptor)) { |
| 3519 | image_view = image_sampler_descriptor->GetImageView(); |
| 3520 | } |
| 3521 | break; |
| 3522 | } |
| 3523 | default: |
| 3524 | break; |
Hans-Kristian Arntzen | a819901 | 2021-03-22 12:10:07 +0100 | [diff] [blame] | 3525 | } |
| 3526 | |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 3527 | if (image_view) { |
| 3528 | auto image_view_state = Get<IMAGE_VIEW_STATE>(image_view); |
| 3529 | QueueValidateImageView(cb_state.queue_submit_functions, function_name, image_view_state.get(), |
| 3530 | IMAGE_SUBRESOURCE_USAGE_BP::DESCRIPTOR_ACCESS); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 3531 | } |
| 3532 | } |
| 3533 | } |
| 3534 | } |
| 3535 | } |
| 3536 | |
| 3537 | void BestPractices::PreCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
| 3538 | uint32_t firstVertex, uint32_t firstInstance) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 3539 | const auto cb_node = GetWrite<bp_state::CommandBuffer>(commandBuffer); |
| 3540 | ValidateBoundDescriptorSets(*cb_node, "vkCmdDraw()"); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 3541 | } |
| 3542 | |
| 3543 | void BestPractices::PreCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3544 | uint32_t drawCount, uint32_t stride) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 3545 | const auto cb_node = GetWrite<bp_state::CommandBuffer>(commandBuffer); |
| 3546 | ValidateBoundDescriptorSets(*cb_node, "vkCmdDrawIndirect()"); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 3547 | } |
| 3548 | |
| 3549 | void BestPractices::PreCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3550 | uint32_t drawCount, uint32_t stride) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 3551 | const auto cb_node = GetWrite<bp_state::CommandBuffer>(commandBuffer); |
| 3552 | ValidateBoundDescriptorSets(*cb_node, "vkCmdDrawIndexedIndirect()"); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 3553 | } |
| 3554 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 3555 | bool BestPractices::PreCallValidateCmdDispatch(VkCommandBuffer commandBuffer, uint32_t groupCountX, uint32_t groupCountY, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 3556 | uint32_t groupCountZ) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 3557 | bool skip = false; |
| 3558 | |
| 3559 | if ((groupCountX == 0) || (groupCountY == 0) || (groupCountZ == 0)) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 3560 | skip |= LogWarning(device, kVUID_BestPractices_CmdDispatch_GroupCountZero, |
| 3561 | "Warning: You are calling vkCmdDispatch() while one or more groupCounts are zero (groupCountX = %" PRIu32 |
| 3562 | ", groupCountY = %" PRIu32 ", groupCountZ = %" PRIu32 ").", |
| 3563 | groupCountX, groupCountY, groupCountZ); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 3564 | } |
| 3565 | |
| 3566 | return skip; |
| 3567 | } |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 3568 | |
Hans-Kristian Arntzen | d9941a9 | 2021-06-18 12:31:30 +0200 | [diff] [blame] | 3569 | bool BestPractices::PreCallValidateCmdEndRenderPass2(VkCommandBuffer commandBuffer, const VkSubpassEndInfo* pSubpassEndInfo) const { |
| 3570 | bool skip = false; |
| 3571 | skip |= StateTracker::PreCallValidateCmdEndRenderPass2(commandBuffer, pSubpassEndInfo); |
| 3572 | skip |= ValidateCmdEndRenderPass(commandBuffer); |
Rodrigo Locatti | 0b16cda | 2022-04-01 17:59:53 -0300 | [diff] [blame^] | 3573 | if (VendorCheckEnabled(kBPVendorNVIDIA)) { |
| 3574 | skip |= ValidateZcullScope(commandBuffer); |
| 3575 | } |
Hans-Kristian Arntzen | d9941a9 | 2021-06-18 12:31:30 +0200 | [diff] [blame] | 3576 | return skip; |
| 3577 | } |
| 3578 | |
| 3579 | bool BestPractices::PreCallValidateCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer, const VkSubpassEndInfo* pSubpassEndInfo) const { |
| 3580 | bool skip = false; |
| 3581 | skip |= StateTracker::PreCallValidateCmdEndRenderPass2KHR(commandBuffer, pSubpassEndInfo); |
| 3582 | skip |= ValidateCmdEndRenderPass(commandBuffer); |
Rodrigo Locatti | 0b16cda | 2022-04-01 17:59:53 -0300 | [diff] [blame^] | 3583 | if (VendorCheckEnabled(kBPVendorNVIDIA)) { |
| 3584 | skip |= ValidateZcullScope(commandBuffer); |
| 3585 | } |
Hans-Kristian Arntzen | d9941a9 | 2021-06-18 12:31:30 +0200 | [diff] [blame] | 3586 | return skip; |
| 3587 | } |
| 3588 | |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 3589 | bool BestPractices::PreCallValidateCmdEndRenderPass(VkCommandBuffer commandBuffer) const { |
| 3590 | bool skip = false; |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 3591 | skip |= StateTracker::PreCallValidateCmdEndRenderPass(commandBuffer); |
Hans-Kristian Arntzen | d9941a9 | 2021-06-18 12:31:30 +0200 | [diff] [blame] | 3592 | skip |= ValidateCmdEndRenderPass(commandBuffer); |
Rodrigo Locatti | 0b16cda | 2022-04-01 17:59:53 -0300 | [diff] [blame^] | 3593 | if (VendorCheckEnabled(kBPVendorNVIDIA)) { |
| 3594 | skip |= ValidateZcullScope(commandBuffer); |
| 3595 | } |
| 3596 | return skip; |
| 3597 | } |
| 3598 | |
| 3599 | bool BestPractices::PreCallValidateCmdEndRendering(VkCommandBuffer commandBuffer) const { |
| 3600 | bool skip = false; |
| 3601 | skip |= StateTracker::PreCallValidateCmdEndRendering(commandBuffer); |
| 3602 | if (VendorCheckEnabled(kBPVendorNVIDIA)) { |
| 3603 | skip |= ValidateZcullScope(commandBuffer); |
| 3604 | } |
| 3605 | return skip; |
| 3606 | } |
| 3607 | |
| 3608 | bool BestPractices::PreCallValidateCmdEndRenderingKHR(VkCommandBuffer commandBuffer) const { |
| 3609 | bool skip = false; |
| 3610 | skip |= StateTracker::PreCallValidateCmdEndRenderingKHR(commandBuffer); |
| 3611 | if (VendorCheckEnabled(kBPVendorNVIDIA)) { |
| 3612 | skip |= ValidateZcullScope(commandBuffer); |
| 3613 | } |
Hans-Kristian Arntzen | d9941a9 | 2021-06-18 12:31:30 +0200 | [diff] [blame] | 3614 | return skip; |
| 3615 | } |
| 3616 | |
| 3617 | bool BestPractices::ValidateCmdEndRenderPass(VkCommandBuffer commandBuffer) const { |
| 3618 | bool skip = false; |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 3619 | const auto cmd = GetRead<bp_state::CommandBuffer>(commandBuffer); |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 3620 | |
Jeremy Gebben | 7c2cd8b | 2021-08-11 15:40:38 -0600 | [diff] [blame] | 3621 | if (cmd == nullptr) return skip; |
| 3622 | auto &render_pass_state = cmd->render_pass_state; |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 3623 | |
LawG4 | b21485c | 2022-02-28 13:46:48 +0000 | [diff] [blame] | 3624 | // Does the number of draw calls classified as depth only surpass the vendor limit for a specified vendor |
| 3625 | bool depth_only_arm = render_pass_state.numDrawCallsDepthEqualCompare >= kDepthPrePassNumDrawCallsArm && |
| 3626 | render_pass_state.numDrawCallsDepthOnly >= kDepthPrePassNumDrawCallsArm; |
| 3627 | bool depth_only_img = render_pass_state.numDrawCallsDepthEqualCompare >= kDepthPrePassNumDrawCallsIMG && |
| 3628 | render_pass_state.numDrawCallsDepthOnly >= kDepthPrePassNumDrawCallsIMG; |
| 3629 | |
| 3630 | // 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] | 3631 | bool uses_depth = |
| 3632 | (render_pass_state.depthAttachment || render_pass_state.colorAttachment) && |
LawG4 | 5507e14 | 2022-04-08 09:36:54 +0100 | [diff] [blame] | 3633 | ((depth_only_arm && VendorCheckEnabled(kBPVendorArm)) || (depth_only_img && VendorCheckEnabled(kBPVendorIMG))); |
LawG4 | b21485c | 2022-02-28 13:46:48 +0000 | [diff] [blame] | 3634 | |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 3635 | if (uses_depth) { |
| 3636 | skip |= LogPerformanceWarning( |
| 3637 | device, kVUID_BestPractices_EndRenderPass_DepthPrePassUsage, |
LawG4 | 015be1c | 2022-03-01 10:37:52 +0000 | [diff] [blame] | 3638 | "%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] | 3639 | "renderering architectures; such as those in Arm Mali or PowerVR GPUs. Since they can remove geometry " |
| 3640 | "hidden by other opaque geometry. Mali has Forward Pixel Killing (FPK), PowerVR has Hiden Surface " |
| 3641 | "Remover (HSR) in which case, using depth pre-passes for hidden surface removal may worsen performance.", |
| 3642 | VendorSpecificTag(kBPVendorArm), VendorSpecificTag(kBPVendorIMG)); |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 3643 | } |
| 3644 | |
Hans-Kristian Arntzen | 808bfa1 | 2021-06-18 13:52:45 +0200 | [diff] [blame] | 3645 | RENDER_PASS_STATE* rp = cmd->activeRenderPass.get(); |
| 3646 | |
LawG4 | 0da9c3d | 2022-03-01 09:51:01 +0000 | [diff] [blame] | 3647 | if ((VendorCheckEnabled(kBPVendorArm) || VendorCheckEnabled(kBPVendorIMG)) && rp) { |
Hans-Kristian Arntzen | 808bfa1 | 2021-06-18 13:52:45 +0200 | [diff] [blame] | 3648 | // If we use an attachment on-tile, we should access it in some way. Otherwise, |
| 3649 | // it is redundant to have it be part of the render pass. |
| 3650 | // Only consider it redundant if it will actually consume bandwidth, i.e. |
| 3651 | // LOAD_OP_LOAD is used or STORE_OP_STORE. CLEAR -> DONT_CARE is benign, |
| 3652 | // as is using pure input attachments. |
| 3653 | // CLEAR -> STORE might be considered a "useful" thing to do, but |
| 3654 | // the optimal thing to do is to defer the clear until you're actually |
| 3655 | // going to render to the image. |
| 3656 | |
| 3657 | uint32_t num_attachments = rp->createInfo.attachmentCount; |
| 3658 | for (uint32_t i = 0; i < num_attachments; i++) { |
Hans-Kristian Arntzen | 237663c | 2021-07-01 14:36:40 +0200 | [diff] [blame] | 3659 | if (!RenderPassUsesAttachmentOnTile(rp->createInfo, i) || |
| 3660 | RenderPassUsesAttachmentAsResolve(rp->createInfo, i)) { |
Hans-Kristian Arntzen | 808bfa1 | 2021-06-18 13:52:45 +0200 | [diff] [blame] | 3661 | continue; |
| 3662 | } |
| 3663 | |
| 3664 | auto& attachment = rp->createInfo.pAttachments[i]; |
| 3665 | |
| 3666 | VkImageAspectFlags bandwidth_aspects = 0; |
| 3667 | |
| 3668 | if (!FormatIsStencilOnly(attachment.format) && |
| 3669 | (attachment.loadOp == VK_ATTACHMENT_LOAD_OP_LOAD || |
| 3670 | attachment.storeOp == VK_ATTACHMENT_STORE_OP_STORE)) { |
| 3671 | if (FormatHasDepth(attachment.format)) { |
| 3672 | bandwidth_aspects |= VK_IMAGE_ASPECT_DEPTH_BIT; |
| 3673 | } else { |
| 3674 | bandwidth_aspects |= VK_IMAGE_ASPECT_COLOR_BIT; |
| 3675 | } |
| 3676 | } |
| 3677 | |
| 3678 | if (FormatHasStencil(attachment.format) && |
| 3679 | (attachment.stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD || |
| 3680 | attachment.stencilStoreOp == VK_ATTACHMENT_STORE_OP_STORE)) { |
| 3681 | bandwidth_aspects |= VK_IMAGE_ASPECT_STENCIL_BIT; |
| 3682 | } |
| 3683 | |
| 3684 | if (!bandwidth_aspects) { |
| 3685 | continue; |
| 3686 | } |
| 3687 | |
Jeremy Gebben | 7c2cd8b | 2021-08-11 15:40:38 -0600 | [diff] [blame] | 3688 | 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] | 3689 | [i](const bp_state::AttachmentInfo& info) { return info.framebufferAttachment == i; }); |
Hans-Kristian Arntzen | 808bfa1 | 2021-06-18 13:52:45 +0200 | [diff] [blame] | 3690 | uint32_t untouched_aspects = bandwidth_aspects; |
Jeremy Gebben | 7c2cd8b | 2021-08-11 15:40:38 -0600 | [diff] [blame] | 3691 | if (itr != render_pass_state.touchesAttachments.end()) { |
Hans-Kristian Arntzen | 808bfa1 | 2021-06-18 13:52:45 +0200 | [diff] [blame] | 3692 | untouched_aspects &= ~itr->aspects; |
| 3693 | } |
| 3694 | |
| 3695 | if (untouched_aspects) { |
| 3696 | skip |= LogPerformanceWarning( |
| 3697 | device, kVUID_BestPractices_EndRenderPass_RedundantAttachmentOnTile, |
LawG4 | 015be1c | 2022-03-01 10:37:52 +0000 | [diff] [blame] | 3698 | "%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] | 3699 | "was never accessed by a pipeline or clear command. " |
LawG4 | 0da9c3d | 2022-03-01 09:51:01 +0000 | [diff] [blame] | 3700 | "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] | 3701 | "render pass if the attachments are not intended to be accessed.", |
LawG4 | 0da9c3d | 2022-03-01 09:51:01 +0000 | [diff] [blame] | 3702 | VendorSpecificTag(kBPVendorArm), VendorSpecificTag(kBPVendorIMG), i, attachment.format, untouched_aspects); |
Hans-Kristian Arntzen | 808bfa1 | 2021-06-18 13:52:45 +0200 | [diff] [blame] | 3703 | } |
| 3704 | } |
| 3705 | } |
| 3706 | |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 3707 | return skip; |
| 3708 | } |
| 3709 | |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 3710 | 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] | 3711 | const auto cb_node = GetWrite<bp_state::CommandBuffer>(commandBuffer); |
| 3712 | ValidateBoundDescriptorSets(*cb_node, "vkCmdDispatch()"); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 3713 | } |
| 3714 | |
| 3715 | void BestPractices::PreCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 3716 | const auto cb_node = GetWrite<bp_state::CommandBuffer>(commandBuffer); |
| 3717 | ValidateBoundDescriptorSets(*cb_node, "vkCmdDispatchIndirect()"); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 3718 | } |
| 3719 | |
Camden Stocker | 9c05144 | 2019-11-06 14:28:43 -0800 | [diff] [blame] | 3720 | bool BestPractices::ValidateGetPhysicalDeviceDisplayPlanePropertiesKHRQuery(VkPhysicalDevice physicalDevice, |
| 3721 | const char* api_name) const { |
| 3722 | bool skip = false; |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 3723 | const auto bp_pd_state = Get<bp_state::PhysicalDevice>(physicalDevice); |
Camden Stocker | 9c05144 | 2019-11-06 14:28:43 -0800 | [diff] [blame] | 3724 | |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 3725 | if (bp_pd_state) { |
| 3726 | if (bp_pd_state->vkGetPhysicalDeviceDisplayPlanePropertiesKHRState == UNCALLED) { |
| 3727 | skip |= LogWarning(physicalDevice, kVUID_BestPractices_DisplayPlane_PropertiesNotCalled, |
| 3728 | "Potential problem with calling %s() without first retrieving properties from " |
| 3729 | "vkGetPhysicalDeviceDisplayPlanePropertiesKHR or vkGetPhysicalDeviceDisplayPlaneProperties2KHR.", |
| 3730 | api_name); |
| 3731 | } |
Camden Stocker | 9c05144 | 2019-11-06 14:28:43 -0800 | [diff] [blame] | 3732 | } |
| 3733 | |
| 3734 | return skip; |
| 3735 | } |
| 3736 | |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 3737 | bool BestPractices::PreCallValidateGetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physicalDevice, uint32_t planeIndex, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 3738 | uint32_t* pDisplayCount, VkDisplayKHR* pDisplays) const { |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 3739 | bool skip = false; |
| 3740 | |
Camden Stocker | 9c05144 | 2019-11-06 14:28:43 -0800 | [diff] [blame] | 3741 | skip |= ValidateGetPhysicalDeviceDisplayPlanePropertiesKHRQuery(physicalDevice, "vkGetDisplayPlaneSupportedDisplaysKHR"); |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 3742 | |
Camden Stocker | 9c05144 | 2019-11-06 14:28:43 -0800 | [diff] [blame] | 3743 | return skip; |
| 3744 | } |
| 3745 | |
| 3746 | bool BestPractices::PreCallValidateGetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice physicalDevice, VkDisplayModeKHR mode, |
| 3747 | uint32_t planeIndex, |
| 3748 | VkDisplayPlaneCapabilitiesKHR* pCapabilities) const { |
| 3749 | bool skip = false; |
| 3750 | |
| 3751 | skip |= ValidateGetPhysicalDeviceDisplayPlanePropertiesKHRQuery(physicalDevice, "vkGetDisplayPlaneCapabilitiesKHR"); |
| 3752 | |
| 3753 | return skip; |
| 3754 | } |
| 3755 | |
| 3756 | bool BestPractices::PreCallValidateGetDisplayPlaneCapabilities2KHR(VkPhysicalDevice physicalDevice, |
| 3757 | const VkDisplayPlaneInfo2KHR* pDisplayPlaneInfo, |
| 3758 | VkDisplayPlaneCapabilities2KHR* pCapabilities) const { |
| 3759 | bool skip = false; |
| 3760 | |
| 3761 | skip |= ValidateGetPhysicalDeviceDisplayPlanePropertiesKHRQuery(physicalDevice, "vkGetDisplayPlaneCapabilities2KHR"); |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 3762 | |
| 3763 | return skip; |
| 3764 | } |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 3765 | |
| 3766 | bool BestPractices::PreCallValidateGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t* pSwapchainImageCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 3767 | VkImage* pSwapchainImages) const { |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 3768 | bool skip = false; |
| 3769 | |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 3770 | auto swapchain_state = Get<bp_state::Swapchain>(swapchain); |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 3771 | |
Nathaniel Cesario | 39152e6 | 2021-07-02 13:04:16 -0600 | [diff] [blame] | 3772 | if (swapchain_state && pSwapchainImages) { |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 3773 | // Compare the preliminary value of *pSwapchainImageCount with the value this time: |
Nathaniel Cesario | 39152e6 | 2021-07-02 13:04:16 -0600 | [diff] [blame] | 3774 | if (swapchain_state->vkGetSwapchainImagesKHRState == UNCALLED) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 3775 | skip |= |
| 3776 | LogWarning(device, kVUID_Core_Swapchain_PriorCount, |
| 3777 | "vkGetSwapchainImagesKHR() called with non-NULL pSwapchainImageCount; but no prior positive value has " |
| 3778 | "been seen for pSwapchainImages."); |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 3779 | } |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 3780 | |
Nathaniel Cesario | 4ce9838 | 2021-05-28 11:33:20 -0600 | [diff] [blame] | 3781 | if (*pSwapchainImageCount > swapchain_state->get_swapchain_image_count) { |
| 3782 | skip |= LogWarning( |
| 3783 | device, kVUID_BestPractices_Swapchain_InvalidCount, |
| 3784 | "vkGetSwapchainImagesKHR() called with non-NULL pSwapchainImages, and with pSwapchainImageCount set to a " |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 3785 | "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] | 3786 | *pSwapchainImageCount, swapchain_state->get_swapchain_image_count); |
| 3787 | } |
| 3788 | } |
| 3789 | |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 3790 | return skip; |
| 3791 | } |
| 3792 | |
| 3793 | // Common function to handle validation for GetPhysicalDeviceQueueFamilyProperties & 2KHR version |
Jeremy Gebben | 383b9a3 | 2021-09-08 16:31:33 -0600 | [diff] [blame] | 3794 | bool BestPractices::ValidateCommonGetPhysicalDeviceQueueFamilyProperties(const PHYSICAL_DEVICE_STATE* bp_pd_state, |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 3795 | uint32_t requested_queue_family_property_count, |
Nathaniel Cesario | 56a9665 | 2020-12-30 13:23:42 -0700 | [diff] [blame] | 3796 | const CALL_STATE call_state, |
| 3797 | const char* caller_name) const { |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 3798 | bool skip = false; |
Nathaniel Cesario | 56a9665 | 2020-12-30 13:23:42 -0700 | [diff] [blame] | 3799 | // Verify that for each physical device, this command is called first with NULL pQueueFamilyProperties in order to get count |
| 3800 | if (UNCALLED == call_state) { |
| 3801 | skip |= LogWarning( |
Jeremy Gebben | 383b9a3 | 2021-09-08 16:31:33 -0600 | [diff] [blame] | 3802 | bp_pd_state->Handle(), kVUID_Core_DevLimit_MissingQueryCount, |
Nathaniel Cesario | 56a9665 | 2020-12-30 13:23:42 -0700 | [diff] [blame] | 3803 | "%s is called with non-NULL pQueueFamilyProperties before obtaining pQueueFamilyPropertyCount. It is " |
| 3804 | "recommended " |
| 3805 | "to first call %s with NULL pQueueFamilyProperties in order to obtain the maximal pQueueFamilyPropertyCount.", |
| 3806 | caller_name, caller_name); |
| 3807 | // 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] | 3808 | } else if (bp_pd_state->queue_family_known_count != requested_queue_family_property_count) { |
| 3809 | skip |= LogWarning(bp_pd_state->Handle(), kVUID_Core_DevLimit_CountMismatch, |
Nathaniel Cesario | 56a9665 | 2020-12-30 13:23:42 -0700 | [diff] [blame] | 3810 | "%s is called with non-NULL pQueueFamilyProperties and pQueueFamilyPropertyCount value %" PRIu32 |
| 3811 | ", but the largest previously returned pQueueFamilyPropertyCount for this physicalDevice is %" PRIu32 |
| 3812 | ". It is recommended to instead receive all the properties by calling %s with " |
| 3813 | "pQueueFamilyPropertyCount that was " |
| 3814 | "previously obtained by calling %s with NULL pQueueFamilyProperties.", |
Jeremy Gebben | 383b9a3 | 2021-09-08 16:31:33 -0600 | [diff] [blame] | 3815 | 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] | 3816 | caller_name); |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 3817 | } |
| 3818 | |
| 3819 | return skip; |
| 3820 | } |
| 3821 | |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 3822 | bool BestPractices::PreCallValidateBindAccelerationStructureMemoryNV( |
| 3823 | VkDevice device, uint32_t bindInfoCount, const VkBindAccelerationStructureMemoryInfoNV* pBindInfos) const { |
Camden Stocker | 8251058 | 2019-09-03 14:00:16 -0600 | [diff] [blame] | 3824 | bool skip = false; |
| 3825 | |
| 3826 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 3827 | auto as_state = Get<ACCELERATION_STRUCTURE_STATE>(pBindInfos[i].accelerationStructure); |
Camden Stocker | 8251058 | 2019-09-03 14:00:16 -0600 | [diff] [blame] | 3828 | if (!as_state->memory_requirements_checked) { |
| 3829 | // There's not an explicit requirement in the spec to call vkGetImageMemoryRequirements() prior to calling |
| 3830 | // BindAccelerationStructureMemoryNV but it's implied in that memory being bound must conform with |
| 3831 | // VkAccelerationStructureMemoryRequirementsInfoNV from vkGetAccelerationStructureMemoryRequirementsNV |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 3832 | skip |= LogWarning( |
| 3833 | device, kVUID_BestPractices_BindAccelNV_NoMemReqQuery, |
Camden Stocker | 8251058 | 2019-09-03 14:00:16 -0600 | [diff] [blame] | 3834 | "vkBindAccelerationStructureMemoryNV(): " |
| 3835 | "Binding memory to %s but vkGetAccelerationStructureMemoryRequirementsNV() has not been called on that structure.", |
| 3836 | report_data->FormatHandle(pBindInfos[i].accelerationStructure).c_str()); |
| 3837 | } |
| 3838 | } |
| 3839 | |
| 3840 | return skip; |
| 3841 | } |
| 3842 | |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 3843 | bool BestPractices::PreCallValidateGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, |
| 3844 | uint32_t* pQueueFamilyPropertyCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 3845 | VkQueueFamilyProperties* pQueueFamilyProperties) const { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 3846 | const auto bp_pd_state = Get<bp_state::PhysicalDevice>(physicalDevice); |
Nathaniel Cesario | 56a9665 | 2020-12-30 13:23:42 -0700 | [diff] [blame] | 3847 | if (pQueueFamilyProperties && bp_pd_state) { |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 3848 | return ValidateCommonGetPhysicalDeviceQueueFamilyProperties(bp_pd_state.get(), *pQueueFamilyPropertyCount, |
Nathaniel Cesario | 56a9665 | 2020-12-30 13:23:42 -0700 | [diff] [blame] | 3849 | bp_pd_state->vkGetPhysicalDeviceQueueFamilyPropertiesState, |
| 3850 | "vkGetPhysicalDeviceQueueFamilyProperties()"); |
| 3851 | } |
| 3852 | return false; |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 3853 | } |
| 3854 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3855 | bool BestPractices::PreCallValidateGetPhysicalDeviceQueueFamilyProperties2(VkPhysicalDevice physicalDevice, |
| 3856 | uint32_t* pQueueFamilyPropertyCount, |
| 3857 | VkQueueFamilyProperties2* pQueueFamilyProperties) const { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 3858 | const auto bp_pd_state = Get<bp_state::PhysicalDevice>(physicalDevice); |
Nathaniel Cesario | 56a9665 | 2020-12-30 13:23:42 -0700 | [diff] [blame] | 3859 | if (pQueueFamilyProperties && bp_pd_state) { |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 3860 | return ValidateCommonGetPhysicalDeviceQueueFamilyProperties(bp_pd_state.get(), *pQueueFamilyPropertyCount, |
Nathaniel Cesario | 56a9665 | 2020-12-30 13:23:42 -0700 | [diff] [blame] | 3861 | bp_pd_state->vkGetPhysicalDeviceQueueFamilyProperties2State, |
| 3862 | "vkGetPhysicalDeviceQueueFamilyProperties2()"); |
| 3863 | } |
| 3864 | return false; |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 3865 | } |
| 3866 | |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 3867 | bool BestPractices::PreCallValidateGetPhysicalDeviceQueueFamilyProperties2KHR( |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3868 | VkPhysicalDevice physicalDevice, uint32_t* pQueueFamilyPropertyCount, VkQueueFamilyProperties2* pQueueFamilyProperties) const { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 3869 | const auto bp_pd_state = Get<bp_state::PhysicalDevice>(physicalDevice); |
Nathaniel Cesario | 56a9665 | 2020-12-30 13:23:42 -0700 | [diff] [blame] | 3870 | if (pQueueFamilyProperties && bp_pd_state) { |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 3871 | return ValidateCommonGetPhysicalDeviceQueueFamilyProperties(bp_pd_state.get(), *pQueueFamilyPropertyCount, |
Nathaniel Cesario | 56a9665 | 2020-12-30 13:23:42 -0700 | [diff] [blame] | 3872 | bp_pd_state->vkGetPhysicalDeviceQueueFamilyProperties2KHRState, |
| 3873 | "vkGetPhysicalDeviceQueueFamilyProperties2KHR()"); |
| 3874 | } |
| 3875 | return false; |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 3876 | } |
| 3877 | |
| 3878 | bool BestPractices::PreCallValidateGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, |
| 3879 | uint32_t* pSurfaceFormatCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 3880 | VkSurfaceFormatKHR* pSurfaceFormats) const { |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 3881 | if (!pSurfaceFormats) return false; |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 3882 | const auto bp_pd_state = Get<bp_state::PhysicalDevice>(physicalDevice); |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 3883 | const auto& call_state = bp_pd_state->vkGetPhysicalDeviceSurfaceFormatsKHRState; |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 3884 | bool skip = false; |
| 3885 | if (call_state == UNCALLED) { |
| 3886 | // Since we haven't recorded a preliminary value of *pSurfaceFormatCount, that likely means that the application didn't |
| 3887 | // previously call this function with a NULL value of pSurfaceFormats: |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 3888 | skip |= LogWarning(physicalDevice, kVUID_Core_DevLimit_MustQueryCount, |
| 3889 | "vkGetPhysicalDeviceSurfaceFormatsKHR() called with non-NULL pSurfaceFormatCount; but no prior " |
| 3890 | "positive value has been seen for pSurfaceFormats."); |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 3891 | } else { |
Jeremy Gebben | c7a834a | 2021-09-08 18:39:30 -0600 | [diff] [blame] | 3892 | if (*pSurfaceFormatCount > bp_pd_state->surface_formats_count) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 3893 | skip |= LogWarning(physicalDevice, kVUID_Core_DevLimit_CountMismatch, |
| 3894 | "vkGetPhysicalDeviceSurfaceFormatsKHR() called with non-NULL pSurfaceFormatCount, and with " |
| 3895 | "pSurfaceFormats set to a value (%u) that is greater than the value (%u) that was returned " |
| 3896 | "when pSurfaceFormatCount was NULL.", |
Jeremy Gebben | c7a834a | 2021-09-08 18:39:30 -0600 | [diff] [blame] | 3897 | *pSurfaceFormatCount, bp_pd_state->surface_formats_count); |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 3898 | } |
| 3899 | } |
| 3900 | return skip; |
| 3901 | } |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 3902 | |
| 3903 | bool BestPractices::PreCallValidateQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo* pBindInfo, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 3904 | VkFence fence) const { |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 3905 | bool skip = false; |
| 3906 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 3907 | for (uint32_t bind_idx = 0; bind_idx < bindInfoCount; bind_idx++) { |
| 3908 | const VkBindSparseInfo& bind_info = pBindInfo[bind_idx]; |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 3909 | // 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] | 3910 | layer_data::unordered_set<const IMAGE_STATE*> sparse_images; |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 3911 | // Track images getting metadata bound by this call in a set, it'll be recorded into the image_state |
| 3912 | // in RecordQueueBindSparse. |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame] | 3913 | layer_data::unordered_set<const IMAGE_STATE*> sparse_images_with_metadata; |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 3914 | // 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] | 3915 | for (uint32_t i = 0; i < bind_info.imageBindCount; ++i) { |
| 3916 | const auto& image_bind = bind_info.pImageBinds[i]; |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 3917 | auto image_state = Get<IMAGE_STATE>(image_bind.image); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 3918 | if (!image_state) { |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 3919 | 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] | 3920 | } |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 3921 | sparse_images.insert(image_state.get()); |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 3922 | if (image_state->createInfo.flags & VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT) { |
| 3923 | if (!image_state->get_sparse_reqs_called || image_state->sparse_requirements.empty()) { |
| 3924 | // 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] | 3925 | skip |= LogWarning(image_state->image(), kVUID_Core_MemTrack_InvalidState, |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 3926 | "vkQueueBindSparse(): Binding sparse memory to %s without first calling " |
| 3927 | "vkGetImageSparseMemoryRequirements[2KHR]() to retrieve requirements.", |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 3928 | report_data->FormatHandle(image_state->image()).c_str()); |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 3929 | } |
| 3930 | } |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 3931 | if (!image_state->memory_requirements_checked[0]) { |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 3932 | // 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] | 3933 | skip |= LogWarning(image_state->image(), kVUID_Core_MemTrack_InvalidState, |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 3934 | "vkQueueBindSparse(): Binding sparse memory to %s without first calling " |
| 3935 | "vkGetImageMemoryRequirements() to retrieve requirements.", |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 3936 | report_data->FormatHandle(image_state->image()).c_str()); |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 3937 | } |
| 3938 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 3939 | for (uint32_t i = 0; i < bind_info.imageOpaqueBindCount; ++i) { |
| 3940 | const auto& image_opaque_bind = bind_info.pImageOpaqueBinds[i]; |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 3941 | auto image_state = Get<IMAGE_STATE>(bind_info.pImageOpaqueBinds[i].image); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 3942 | if (!image_state) { |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 3943 | 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] | 3944 | } |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 3945 | sparse_images.insert(image_state.get()); |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 3946 | if (image_state->createInfo.flags & VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT) { |
| 3947 | if (!image_state->get_sparse_reqs_called || image_state->sparse_requirements.empty()) { |
| 3948 | // 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] | 3949 | skip |= LogWarning(image_state->image(), kVUID_Core_MemTrack_InvalidState, |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 3950 | "vkQueueBindSparse(): Binding opaque sparse memory to %s without first calling " |
| 3951 | "vkGetImageSparseMemoryRequirements[2KHR]() to retrieve requirements.", |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 3952 | report_data->FormatHandle(image_state->image()).c_str()); |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 3953 | } |
| 3954 | } |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 3955 | if (!image_state->memory_requirements_checked[0]) { |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 3956 | // 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] | 3957 | skip |= LogWarning(image_state->image(), kVUID_Core_MemTrack_InvalidState, |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 3958 | "vkQueueBindSparse(): Binding opaque sparse memory to %s without first calling " |
| 3959 | "vkGetImageMemoryRequirements() to retrieve requirements.", |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 3960 | report_data->FormatHandle(image_state->image()).c_str()); |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 3961 | } |
| 3962 | for (uint32_t j = 0; j < image_opaque_bind.bindCount; ++j) { |
| 3963 | 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] | 3964 | sparse_images_with_metadata.insert(image_state.get()); |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 3965 | } |
| 3966 | } |
| 3967 | } |
| 3968 | for (const auto& sparse_image_state : sparse_images) { |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 3969 | if (sparse_image_state->sparse_metadata_required && !sparse_image_state->sparse_metadata_bound && |
| 3970 | 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] | 3971 | // 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] | 3972 | skip |= LogWarning(sparse_image_state->image(), kVUID_Core_MemTrack_InvalidState, |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 3973 | "vkQueueBindSparse(): Binding sparse memory to %s which requires a metadata aspect but no " |
| 3974 | "binding with VK_SPARSE_MEMORY_BIND_METADATA_BIT set was made.", |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 3975 | report_data->FormatHandle(sparse_image_state->image()).c_str()); |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 3976 | } |
| 3977 | } |
| 3978 | } |
| 3979 | |
Rodrigo Locatti | 7ab778d | 2022-03-09 18:57:15 -0300 | [diff] [blame] | 3980 | if (VendorCheckEnabled(kBPVendorNVIDIA)) { |
| 3981 | auto queue_state = Get<QUEUE_STATE>(queue); |
| 3982 | if (queue_state && queue_state->queueFamilyProperties.queueFlags != (VK_QUEUE_TRANSFER_BIT | VK_QUEUE_SPARSE_BINDING_BIT)) { |
| 3983 | skip |= LogPerformanceWarning(queue, kVUID_BestPractices_QueueBindSparse_NotAsync, |
| 3984 | "vkQueueBindSparse() issued on queue %s. All binds should happen on an asynchronous copy " |
| 3985 | "queue to hide the OS scheduling and submit costs.", |
| 3986 | report_data->FormatHandle(queue).c_str()); |
| 3987 | } |
| 3988 | } |
| 3989 | |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 3990 | return skip; |
| 3991 | } |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 3992 | |
Mark Lobodzinski | 84101d7 | 2020-04-24 09:43:48 -0600 | [diff] [blame] | 3993 | void BestPractices::ManualPostCallRecordQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo* pBindInfo, |
| 3994 | VkFence fence, VkResult result) { |
Mark Lobodzinski | 205b7a0 | 2020-02-21 13:23:17 -0700 | [diff] [blame] | 3995 | if (result != VK_SUCCESS) { |
Mark Lobodzinski | 205b7a0 | 2020-02-21 13:23:17 -0700 | [diff] [blame] | 3996 | return; |
| 3997 | } |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 3998 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 3999 | for (uint32_t bind_idx = 0; bind_idx < bindInfoCount; bind_idx++) { |
| 4000 | const VkBindSparseInfo& bind_info = pBindInfo[bind_idx]; |
| 4001 | for (uint32_t i = 0; i < bind_info.imageOpaqueBindCount; ++i) { |
| 4002 | const auto& image_opaque_bind = bind_info.pImageOpaqueBinds[i]; |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 4003 | auto image_state = Get<IMAGE_STATE>(bind_info.pImageOpaqueBinds[i].image); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 4004 | if (!image_state) { |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 4005 | 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] | 4006 | } |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 4007 | for (uint32_t j = 0; j < image_opaque_bind.bindCount; ++j) { |
| 4008 | if (image_opaque_bind.pBinds[j].flags & VK_SPARSE_MEMORY_BIND_METADATA_BIT) { |
| 4009 | image_state->sparse_metadata_bound = true; |
| 4010 | } |
| 4011 | } |
| 4012 | } |
| 4013 | } |
| 4014 | } |
Camden Stocker | 0e0f89b | 2019-10-16 12:24:31 -0700 | [diff] [blame] | 4015 | |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4016 | bool BestPractices::ClearAttachmentsIsFullClear(const bp_state::CommandBuffer& cmd, uint32_t rectCount, |
Jeremy Gebben | 7c2cd8b | 2021-08-11 15:40:38 -0600 | [diff] [blame] | 4017 | const VkClearRect* pRects) const { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4018 | if (cmd.createInfo.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) { |
Hans-Kristian Arntzen | b658631 | 2021-07-05 11:43:39 +0200 | [diff] [blame] | 4019 | // We don't know the accurate render area in a secondary, |
| 4020 | // so assume we clear the entire frame buffer. |
| 4021 | // This is resolved in CmdExecuteCommands where we can check if the clear is a full clear. |
| 4022 | return true; |
| 4023 | } |
| 4024 | |
| 4025 | // If we have a rect which covers the entire frame buffer, we have a LOAD_OP_CLEAR-like command. |
| 4026 | for (uint32_t i = 0; i < rectCount; i++) { |
| 4027 | auto& rect = pRects[i]; |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4028 | auto& render_area = cmd.activeRenderPassBeginInfo.renderArea; |
Hans-Kristian Arntzen | b658631 | 2021-07-05 11:43:39 +0200 | [diff] [blame] | 4029 | if (rect.rect.extent.width == render_area.extent.width && rect.rect.extent.height == render_area.extent.height) { |
| 4030 | return true; |
| 4031 | } |
| 4032 | } |
| 4033 | |
| 4034 | return false; |
| 4035 | } |
| 4036 | |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4037 | bool BestPractices::ValidateClearAttachment(const bp_state::CommandBuffer& cmd, uint32_t fb_attachment, uint32_t color_attachment, |
| 4038 | VkImageAspectFlags aspects, bool secondary) const { |
| 4039 | const RENDER_PASS_STATE* rp = cmd.activeRenderPass.get(); |
Hans-Kristian Arntzen | b658631 | 2021-07-05 11:43:39 +0200 | [diff] [blame] | 4040 | bool skip = false; |
| 4041 | |
| 4042 | if (!rp || fb_attachment == VK_ATTACHMENT_UNUSED) { |
| 4043 | return skip; |
| 4044 | } |
| 4045 | |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4046 | const auto& rp_state = cmd.render_pass_state; |
Hans-Kristian Arntzen | b658631 | 2021-07-05 11:43:39 +0200 | [diff] [blame] | 4047 | |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4048 | auto attachment_itr = |
| 4049 | std::find_if(rp_state.touchesAttachments.begin(), rp_state.touchesAttachments.end(), |
| 4050 | [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] | 4051 | |
| 4052 | // Only report aspects which haven't been touched yet. |
| 4053 | VkImageAspectFlags new_aspects = aspects; |
Jeremy Gebben | 7c2cd8b | 2021-08-11 15:40:38 -0600 | [diff] [blame] | 4054 | if (attachment_itr != rp_state.touchesAttachments.end()) { |
Hans-Kristian Arntzen | b658631 | 2021-07-05 11:43:39 +0200 | [diff] [blame] | 4055 | new_aspects &= ~attachment_itr->aspects; |
| 4056 | } |
| 4057 | |
| 4058 | // 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] | 4059 | if (!cmd.has_draw_cmd) { |
Hans-Kristian Arntzen | b658631 | 2021-07-05 11:43:39 +0200 | [diff] [blame] | 4060 | skip |= LogPerformanceWarning( |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4061 | cmd.Handle(), kVUID_BestPractices_DrawState_ClearCmdBeforeDraw, |
Hans-Kristian Arntzen | 4ddd618 | 2021-06-18 12:16:33 +0200 | [diff] [blame] | 4062 | "vkCmdClearAttachments() issued on %s prior to any Draw Cmds in current render pass. It is recommended you " |
| 4063 | "use RenderPass LOAD_OP_CLEAR on attachments instead.", |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4064 | report_data->FormatHandle(cmd.Handle()).c_str()); |
Hans-Kristian Arntzen | b658631 | 2021-07-05 11:43:39 +0200 | [diff] [blame] | 4065 | } |
| 4066 | |
| 4067 | if ((new_aspects & VK_IMAGE_ASPECT_COLOR_BIT) && |
| 4068 | rp->createInfo.pAttachments[fb_attachment].loadOp == VK_ATTACHMENT_LOAD_OP_LOAD) { |
| 4069 | skip |= LogPerformanceWarning( |
| 4070 | device, kVUID_BestPractices_ClearAttachments_ClearAfterLoad, |
| 4071 | "%svkCmdClearAttachments() issued on %s for color attachment #%u in this subpass, " |
| 4072 | "but LOAD_OP_LOAD was used. If you need to clear the framebuffer, always use LOAD_OP_CLEAR as " |
| 4073 | "it is more efficient.", |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4074 | secondary ? "vkCmdExecuteCommands(): " : "", report_data->FormatHandle(cmd.Handle()).c_str(), color_attachment); |
Hans-Kristian Arntzen | b658631 | 2021-07-05 11:43:39 +0200 | [diff] [blame] | 4075 | } |
| 4076 | |
| 4077 | if ((new_aspects & VK_IMAGE_ASPECT_DEPTH_BIT) && |
| 4078 | rp->createInfo.pAttachments[fb_attachment].loadOp == VK_ATTACHMENT_LOAD_OP_LOAD) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4079 | skip |= |
| 4080 | LogPerformanceWarning(device, kVUID_BestPractices_ClearAttachments_ClearAfterLoad, |
| 4081 | "%svkCmdClearAttachments() issued on %s for the depth attachment in this subpass, " |
| 4082 | "but LOAD_OP_LOAD was used. If you need to clear the framebuffer, always use LOAD_OP_CLEAR as " |
| 4083 | "it is more efficient.", |
| 4084 | secondary ? "vkCmdExecuteCommands(): " : "", report_data->FormatHandle(cmd.Handle()).c_str()); |
Rodrigo Locatti | 0b16cda | 2022-04-01 17:59:53 -0300 | [diff] [blame^] | 4085 | |
| 4086 | if (VendorCheckEnabled(kBPVendorNVIDIA)) { |
| 4087 | skip |= ValidateZcullScope(cmd.commandBuffer()); |
| 4088 | } |
Hans-Kristian Arntzen | b658631 | 2021-07-05 11:43:39 +0200 | [diff] [blame] | 4089 | } |
| 4090 | |
| 4091 | if ((new_aspects & VK_IMAGE_ASPECT_STENCIL_BIT) && |
| 4092 | rp->createInfo.pAttachments[fb_attachment].stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4093 | skip |= |
| 4094 | LogPerformanceWarning(device, kVUID_BestPractices_ClearAttachments_ClearAfterLoad, |
| 4095 | "%svkCmdClearAttachments() issued on %s for the stencil attachment in this subpass, " |
| 4096 | "but LOAD_OP_LOAD was used. If you need to clear the framebuffer, always use LOAD_OP_CLEAR as " |
| 4097 | "it is more efficient.", |
| 4098 | secondary ? "vkCmdExecuteCommands(): " : "", report_data->FormatHandle(cmd.Handle()).c_str()); |
Hans-Kristian Arntzen | b658631 | 2021-07-05 11:43:39 +0200 | [diff] [blame] | 4099 | } |
| 4100 | |
| 4101 | return skip; |
| 4102 | } |
| 4103 | |
Camden Stocker | 0e0f89b | 2019-10-16 12:24:31 -0700 | [diff] [blame] | 4104 | bool BestPractices::PreCallValidateCmdClearAttachments(VkCommandBuffer commandBuffer, uint32_t attachmentCount, |
Camden Stocker | f55721f | 2019-09-09 11:04:49 -0600 | [diff] [blame] | 4105 | const VkClearAttachment* pAttachments, uint32_t rectCount, |
| 4106 | const VkClearRect* pRects) const { |
Camden Stocker | 0e0f89b | 2019-10-16 12:24:31 -0700 | [diff] [blame] | 4107 | bool skip = false; |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4108 | const auto cb_node = GetRead<bp_state::CommandBuffer>(commandBuffer); |
Camden Stocker | 0e0f89b | 2019-10-16 12:24:31 -0700 | [diff] [blame] | 4109 | if (!cb_node) return skip; |
| 4110 | |
Hans-Kristian Arntzen | b658631 | 2021-07-05 11:43:39 +0200 | [diff] [blame] | 4111 | if (cb_node->createInfo.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) { |
| 4112 | // Defer checks to ExecuteCommands. |
| 4113 | return skip; |
| 4114 | } |
| 4115 | |
| 4116 | // Only care about full clears, partial clears might have legitimate uses. |
Rodrigo Locatti | 0b16cda | 2022-04-01 17:59:53 -0300 | [diff] [blame^] | 4117 | const bool is_full_clear = ClearAttachmentsIsFullClear(*cb_node, rectCount, pRects); |
Camden Stocker | 0e0f89b | 2019-10-16 12:24:31 -0700 | [diff] [blame] | 4118 | |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 4119 | // Check for uses of ClearAttachments along with LOAD_OP_LOAD, |
| 4120 | // as it can be more efficient to just use LOAD_OP_CLEAR |
locke-lunarg | aecf215 | 2020-05-12 17:15:41 -0600 | [diff] [blame] | 4121 | const RENDER_PASS_STATE* rp = cb_node->activeRenderPass.get(); |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 4122 | if (rp) { |
Rodrigo Locatti | 0b16cda | 2022-04-01 17:59:53 -0300 | [diff] [blame^] | 4123 | if (rp->use_dynamic_rendering || rp->use_dynamic_rendering_inherited) { |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 4124 | |
Rodrigo Locatti | 0b16cda | 2022-04-01 17:59:53 -0300 | [diff] [blame^] | 4125 | if (VendorCheckEnabled(kBPVendorNVIDIA)) { |
| 4126 | for (uint32_t i = 0; i < attachmentCount; i++) { |
| 4127 | if (pAttachments[i].aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) { |
| 4128 | skip |= ValidateZcullScope(commandBuffer); |
| 4129 | } |
| 4130 | } |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 4131 | } |
| 4132 | |
Rodrigo Locatti | 0b16cda | 2022-04-01 17:59:53 -0300 | [diff] [blame^] | 4133 | if (is_full_clear) { |
| 4134 | // TODO: Implement ValidateClearAttachment for dynamic rendering |
| 4135 | } |
| 4136 | |
| 4137 | } else { |
| 4138 | const auto& subpass = rp->createInfo.pSubpasses[cb_node->activeSubpass]; |
| 4139 | |
| 4140 | if (is_full_clear) { |
| 4141 | for (uint32_t i = 0; i < attachmentCount; i++) { |
| 4142 | const auto& attachment = pAttachments[i]; |
| 4143 | |
| 4144 | if (attachment.aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) { |
| 4145 | uint32_t color_attachment = attachment.colorAttachment; |
| 4146 | uint32_t fb_attachment = subpass.pColorAttachments[color_attachment].attachment; |
| 4147 | skip |= ValidateClearAttachment(*cb_node, fb_attachment, color_attachment, attachment.aspectMask, false); |
| 4148 | } |
| 4149 | |
| 4150 | if (subpass.pDepthStencilAttachment && |
| 4151 | (attachment.aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT))) { |
| 4152 | uint32_t fb_attachment = subpass.pDepthStencilAttachment->attachment; |
| 4153 | skip |= ValidateClearAttachment(*cb_node, fb_attachment, VK_ATTACHMENT_UNUSED, attachment.aspectMask, false); |
| 4154 | } |
| 4155 | } |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 4156 | } |
| 4157 | } |
| 4158 | } |
| 4159 | |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 4160 | if (VendorCheckEnabled(kBPVendorAMD)) { |
| 4161 | for (uint32_t attachment_idx = 0; attachment_idx < attachmentCount; attachment_idx++) { |
| 4162 | if (pAttachments[attachment_idx].aspectMask == VK_IMAGE_ASPECT_COLOR_BIT) { |
| 4163 | bool black_check = false; |
| 4164 | black_check |= pAttachments[attachment_idx].clearValue.color.float32[0] != 0.0f; |
| 4165 | black_check |= pAttachments[attachment_idx].clearValue.color.float32[1] != 0.0f; |
| 4166 | black_check |= pAttachments[attachment_idx].clearValue.color.float32[2] != 0.0f; |
| 4167 | black_check |= pAttachments[attachment_idx].clearValue.color.float32[3] != 0.0f && |
| 4168 | pAttachments[attachment_idx].clearValue.color.float32[3] != 1.0f; |
| 4169 | |
| 4170 | bool white_check = false; |
| 4171 | white_check |= pAttachments[attachment_idx].clearValue.color.float32[0] != 1.0f; |
| 4172 | white_check |= pAttachments[attachment_idx].clearValue.color.float32[1] != 1.0f; |
| 4173 | white_check |= pAttachments[attachment_idx].clearValue.color.float32[2] != 1.0f; |
| 4174 | white_check |= pAttachments[attachment_idx].clearValue.color.float32[3] != 0.0f && |
| 4175 | pAttachments[attachment_idx].clearValue.color.float32[3] != 1.0f; |
| 4176 | |
| 4177 | if (black_check && white_check) { |
| 4178 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_ClearAttachment_FastClearValues, |
| 4179 | "%s Performance warning: vkCmdClearAttachments() clear value for color attachment %" PRId32 " is not a fast clear value." |
| 4180 | "Consider changing to one of the following:" |
| 4181 | "RGBA(0, 0, 0, 0) " |
| 4182 | "RGBA(0, 0, 0, 1) " |
| 4183 | "RGBA(1, 1, 1, 0) " |
| 4184 | "RGBA(1, 1, 1, 1)", |
| 4185 | VendorSpecificTag(kBPVendorAMD), attachment_idx); |
| 4186 | } |
| 4187 | } else { |
| 4188 | if ((pAttachments[attachment_idx].clearValue.depthStencil.depth != 0 && |
| 4189 | pAttachments[attachment_idx].clearValue.depthStencil.depth != 1) && |
| 4190 | pAttachments[attachment_idx].clearValue.depthStencil.stencil != 0) { |
| 4191 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_ClearAttachment_FastClearValues, |
| 4192 | "%s Performance warning: vkCmdClearAttachments() clear value for depth/stencil " |
| 4193 | "attachment %" PRId32 " is not a fast clear value." |
| 4194 | "Consider changing to one of the following:" |
| 4195 | "D=0.0f, S=0" |
| 4196 | "D=1.0f, S=0", |
| 4197 | VendorSpecificTag(kBPVendorAMD), attachment_idx); |
| 4198 | } |
| 4199 | } |
| 4200 | } |
| 4201 | } |
| 4202 | |
Camden Stocker | f55721f | 2019-09-09 11:04:49 -0600 | [diff] [blame] | 4203 | return skip; |
Camden Stocker | 0e0f89b | 2019-10-16 12:24:31 -0700 | [diff] [blame] | 4204 | } |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 4205 | |
| 4206 | bool BestPractices::PreCallValidateCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4207 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4208 | const VkImageResolve* pRegions) const { |
| 4209 | bool skip = false; |
| 4210 | |
| 4211 | skip |= VendorCheckEnabled(kBPVendorArm) && |
| 4212 | LogPerformanceWarning(device, kVUID_BestPractices_CmdResolveImage_ResolvingImage, |
| 4213 | "%s Attempting to use vkCmdResolveImage to resolve a multisampled image. " |
| 4214 | "This is a very slow and extremely bandwidth intensive path. " |
| 4215 | "You should always resolve multisampled images on-tile with pResolveAttachments in VkRenderPass.", |
| 4216 | VendorSpecificTag(kBPVendorArm)); |
| 4217 | |
| 4218 | return skip; |
| 4219 | } |
| 4220 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 4221 | bool BestPractices::PreCallValidateCmdResolveImage2KHR(VkCommandBuffer commandBuffer, |
| 4222 | const VkResolveImageInfo2KHR* pResolveImageInfo) const { |
| 4223 | bool skip = false; |
| 4224 | |
| 4225 | skip |= VendorCheckEnabled(kBPVendorArm) && |
| 4226 | LogPerformanceWarning(device, kVUID_BestPractices_CmdResolveImage2KHR_ResolvingImage, |
| 4227 | "%s Attempting to use vkCmdResolveImage2KHR to resolve a multisampled image. " |
| 4228 | "This is a very slow and extremely bandwidth intensive path. " |
| 4229 | "You should always resolve multisampled images on-tile with pResolveAttachments in VkRenderPass.", |
| 4230 | VendorSpecificTag(kBPVendorArm)); |
| 4231 | |
| 4232 | return skip; |
| 4233 | } |
| 4234 | |
Tony-LunarG | d36f5f3 | 2022-01-20 11:49:59 -0700 | [diff] [blame] | 4235 | bool BestPractices::PreCallValidateCmdResolveImage2(VkCommandBuffer commandBuffer, |
| 4236 | const VkResolveImageInfo2* pResolveImageInfo) const { |
| 4237 | bool skip = false; |
| 4238 | |
| 4239 | skip |= VendorCheckEnabled(kBPVendorArm) && |
| 4240 | LogPerformanceWarning(device, kVUID_BestPractices_CmdResolveImage2_ResolvingImage, |
| 4241 | "%s Attempting to use vkCmdResolveImage2 to resolve a multisampled image. " |
| 4242 | "This is a very slow and extremely bandwidth intensive path. " |
| 4243 | "You should always resolve multisampled images on-tile with pResolveAttachments in VkRenderPass.", |
| 4244 | VendorSpecificTag(kBPVendorArm)); |
| 4245 | |
| 4246 | return skip; |
| 4247 | } |
| 4248 | |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 4249 | void BestPractices::PreCallRecordCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4250 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4251 | const VkImageResolve* pRegions) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4252 | auto cb = GetWrite<bp_state::CommandBuffer>(commandBuffer); |
Hans-Kristian Arntzen | dd8acbb | 2021-03-22 13:41:47 +0100 | [diff] [blame] | 4253 | auto &funcs = cb->queue_submit_functions; |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4254 | auto src = Get<bp_state::Image>(srcImage); |
| 4255 | auto dst = Get<bp_state::Image>(dstImage); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 4256 | |
| 4257 | for (uint32_t i = 0; i < regionCount; i++) { |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 4258 | QueueValidateImage(funcs, "vkCmdResolveImage()", src, IMAGE_SUBRESOURCE_USAGE_BP::RESOLVE_READ, pRegions[i].srcSubresource); |
| 4259 | QueueValidateImage(funcs, "vkCmdResolveImage()", dst, IMAGE_SUBRESOURCE_USAGE_BP::RESOLVE_WRITE, pRegions[i].dstSubresource); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 4260 | } |
| 4261 | } |
| 4262 | |
Hans-Kristian Arntzen | 9e030f1 | 2021-03-17 13:09:30 +0100 | [diff] [blame] | 4263 | void BestPractices::PreCallRecordCmdResolveImage2KHR(VkCommandBuffer commandBuffer, |
| 4264 | const VkResolveImageInfo2KHR* pResolveImageInfo) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4265 | auto cb = GetWrite<bp_state::CommandBuffer>(commandBuffer); |
Hans-Kristian Arntzen | dd8acbb | 2021-03-22 13:41:47 +0100 | [diff] [blame] | 4266 | auto &funcs = cb->queue_submit_functions; |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4267 | auto src = Get<bp_state::Image>(pResolveImageInfo->srcImage); |
| 4268 | auto dst = Get<bp_state::Image>(pResolveImageInfo->dstImage); |
Hans-Kristian Arntzen | 9e030f1 | 2021-03-17 13:09:30 +0100 | [diff] [blame] | 4269 | uint32_t regionCount = pResolveImageInfo->regionCount; |
| 4270 | |
| 4271 | for (uint32_t i = 0; i < regionCount; i++) { |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 4272 | QueueValidateImage(funcs, "vkCmdResolveImage2KHR()", src, IMAGE_SUBRESOURCE_USAGE_BP::RESOLVE_READ, pResolveImageInfo->pRegions[i].srcSubresource); |
| 4273 | 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] | 4274 | } |
| 4275 | } |
| 4276 | |
Tony-LunarG | d36f5f3 | 2022-01-20 11:49:59 -0700 | [diff] [blame] | 4277 | void BestPractices::PreCallRecordCmdResolveImage2(VkCommandBuffer commandBuffer, |
| 4278 | const VkResolveImageInfo2* pResolveImageInfo) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4279 | auto cb = GetWrite<bp_state::CommandBuffer>(commandBuffer); |
Tony-LunarG | d36f5f3 | 2022-01-20 11:49:59 -0700 | [diff] [blame] | 4280 | auto& funcs = cb->queue_submit_functions; |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4281 | auto src = Get<bp_state::Image>(pResolveImageInfo->srcImage); |
| 4282 | auto dst = Get<bp_state::Image>(pResolveImageInfo->dstImage); |
Tony-LunarG | d36f5f3 | 2022-01-20 11:49:59 -0700 | [diff] [blame] | 4283 | uint32_t regionCount = pResolveImageInfo->regionCount; |
| 4284 | |
| 4285 | for (uint32_t i = 0; i < regionCount; i++) { |
| 4286 | QueueValidateImage(funcs, "vkCmdResolveImage2()", src, IMAGE_SUBRESOURCE_USAGE_BP::RESOLVE_READ, |
| 4287 | pResolveImageInfo->pRegions[i].srcSubresource); |
| 4288 | QueueValidateImage(funcs, "vkCmdResolveImage2()", dst, IMAGE_SUBRESOURCE_USAGE_BP::RESOLVE_WRITE, |
| 4289 | pResolveImageInfo->pRegions[i].dstSubresource); |
| 4290 | } |
| 4291 | } |
| 4292 | |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 4293 | void BestPractices::PreCallRecordCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 4294 | const VkClearColorValue* pColor, uint32_t rangeCount, |
| 4295 | const VkImageSubresourceRange* pRanges) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4296 | auto cb = GetWrite<bp_state::CommandBuffer>(commandBuffer); |
Hans-Kristian Arntzen | dd8acbb | 2021-03-22 13:41:47 +0100 | [diff] [blame] | 4297 | auto &funcs = cb->queue_submit_functions; |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4298 | auto dst = Get<bp_state::Image>(image); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 4299 | |
| 4300 | for (uint32_t i = 0; i < rangeCount; i++) { |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 4301 | QueueValidateImage(funcs, "vkCmdClearColorImage()", dst, IMAGE_SUBRESOURCE_USAGE_BP::CLEARED, pRanges[i]); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 4302 | } |
| 4303 | } |
| 4304 | |
| 4305 | void BestPractices::PreCallRecordCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 4306 | const VkClearDepthStencilValue* pDepthStencil, uint32_t rangeCount, |
| 4307 | const VkImageSubresourceRange* pRanges) { |
Rodrigo Locatti | 0b16cda | 2022-04-01 17:59:53 -0300 | [diff] [blame^] | 4308 | ValidationStateTracker::PreCallRecordCmdClearDepthStencilImage(commandBuffer, image, imageLayout, pDepthStencil, rangeCount, |
| 4309 | pRanges); |
| 4310 | |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4311 | auto cb = GetWrite<bp_state::CommandBuffer>(commandBuffer); |
Hans-Kristian Arntzen | dd8acbb | 2021-03-22 13:41:47 +0100 | [diff] [blame] | 4312 | auto &funcs = cb->queue_submit_functions; |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4313 | auto dst = Get<bp_state::Image>(image); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 4314 | |
| 4315 | for (uint32_t i = 0; i < rangeCount; i++) { |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 4316 | QueueValidateImage(funcs, "vkCmdClearDepthStencilImage()", dst, IMAGE_SUBRESOURCE_USAGE_BP::CLEARED, pRanges[i]); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 4317 | } |
Rodrigo Locatti | 0b16cda | 2022-04-01 17:59:53 -0300 | [diff] [blame^] | 4318 | for (uint32_t i = 0; i < rangeCount; i++) { |
| 4319 | RecordResetZcullDirection(*cb, image, pRanges[i]); |
| 4320 | } |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 4321 | } |
| 4322 | |
| 4323 | void BestPractices::PreCallRecordCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4324 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4325 | const VkImageCopy* pRegions) { |
Rodrigo Locatti | 0b16cda | 2022-04-01 17:59:53 -0300 | [diff] [blame^] | 4326 | ValidationStateTracker::PreCallRecordCmdCopyImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, |
| 4327 | regionCount, pRegions); |
| 4328 | |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4329 | auto cb = GetWrite<bp_state::CommandBuffer>(commandBuffer); |
Hans-Kristian Arntzen | dd8acbb | 2021-03-22 13:41:47 +0100 | [diff] [blame] | 4330 | auto &funcs = cb->queue_submit_functions; |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4331 | auto src = Get<bp_state::Image>(srcImage); |
| 4332 | auto dst = Get<bp_state::Image>(dstImage); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 4333 | |
| 4334 | for (uint32_t i = 0; i < regionCount; i++) { |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 4335 | QueueValidateImage(funcs, "vkCmdCopyImage()", src, IMAGE_SUBRESOURCE_USAGE_BP::COPY_READ, pRegions[i].srcSubresource); |
| 4336 | QueueValidateImage(funcs, "vkCmdCopyImage()", dst, IMAGE_SUBRESOURCE_USAGE_BP::COPY_WRITE, pRegions[i].dstSubresource); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 4337 | } |
| 4338 | } |
| 4339 | |
| 4340 | void BestPractices::PreCallRecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 4341 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4342 | const VkBufferImageCopy* pRegions) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4343 | auto cb = GetWrite<bp_state::CommandBuffer>(commandBuffer); |
Hans-Kristian Arntzen | dd8acbb | 2021-03-22 13:41:47 +0100 | [diff] [blame] | 4344 | auto &funcs = cb->queue_submit_functions; |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4345 | auto dst = Get<bp_state::Image>(dstImage); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 4346 | |
| 4347 | for (uint32_t i = 0; i < regionCount; i++) { |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 4348 | QueueValidateImage(funcs, "vkCmdCopyBufferToImage()", dst, IMAGE_SUBRESOURCE_USAGE_BP::COPY_WRITE, pRegions[i].imageSubresource); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 4349 | } |
| 4350 | } |
| 4351 | |
| 4352 | void BestPractices::PreCallRecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4353 | VkBuffer dstBuffer, uint32_t regionCount, const VkBufferImageCopy* pRegions) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4354 | auto cb = GetWrite<bp_state::CommandBuffer>(commandBuffer); |
Hans-Kristian Arntzen | dd8acbb | 2021-03-22 13:41:47 +0100 | [diff] [blame] | 4355 | auto &funcs = cb->queue_submit_functions; |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4356 | auto src = Get<bp_state::Image>(srcImage); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 4357 | |
| 4358 | for (uint32_t i = 0; i < regionCount; i++) { |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 4359 | QueueValidateImage(funcs, "vkCmdCopyImageToBuffer()", src, IMAGE_SUBRESOURCE_USAGE_BP::COPY_READ, pRegions[i].imageSubresource); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 4360 | } |
| 4361 | } |
| 4362 | |
| 4363 | void BestPractices::PreCallRecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4364 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4365 | const VkImageBlit* pRegions, VkFilter filter) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4366 | auto cb = GetWrite<bp_state::CommandBuffer>(commandBuffer); |
Hans-Kristian Arntzen | dd8acbb | 2021-03-22 13:41:47 +0100 | [diff] [blame] | 4367 | auto &funcs = cb->queue_submit_functions; |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4368 | auto src = Get<bp_state::Image>(srcImage); |
| 4369 | auto dst = Get<bp_state::Image>(dstImage); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 4370 | |
| 4371 | for (uint32_t i = 0; i < regionCount; i++) { |
Hans-Kristian Arntzen | c8b831c | 2021-04-28 15:29:49 +0200 | [diff] [blame] | 4372 | QueueValidateImage(funcs, "vkCmdBlitImage()", src, IMAGE_SUBRESOURCE_USAGE_BP::BLIT_READ, pRegions[i].srcSubresource); |
| 4373 | QueueValidateImage(funcs, "vkCmdBlitImage()", dst, IMAGE_SUBRESOURCE_USAGE_BP::BLIT_WRITE, pRegions[i].dstSubresource); |
ZandroFargnoli | 1ced2b6 | 2020-06-18 16:49:34 +0100 | [diff] [blame] | 4374 | } |
| 4375 | } |
| 4376 | |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 4377 | bool BestPractices::PreCallValidateCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, |
| 4378 | const VkAllocationCallbacks* pAllocator, VkSampler* pSampler) const { |
| 4379 | bool skip = false; |
| 4380 | |
| 4381 | if (VendorCheckEnabled(kBPVendorArm)) { |
| 4382 | if ((pCreateInfo->addressModeU != pCreateInfo->addressModeV) || (pCreateInfo->addressModeV != pCreateInfo->addressModeW)) { |
| 4383 | skip |= LogPerformanceWarning( |
| 4384 | device, kVUID_BestPractices_CreateSampler_DifferentWrappingModes, |
| 4385 | "%s Creating a sampler object with wrapping modes which do not match (U = %u, V = %u, W = %u). " |
| 4386 | "This may cause reduced performance even if only U (1D image) or U/V wrapping modes (2D " |
| 4387 | "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] | 4388 | VendorSpecificTag(kBPVendorArm), pCreateInfo->addressModeU, pCreateInfo->addressModeV, pCreateInfo->addressModeW); |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 4389 | } |
| 4390 | |
| 4391 | if ((pCreateInfo->minLod != 0.0f) || (pCreateInfo->maxLod < VK_LOD_CLAMP_NONE)) { |
| 4392 | skip |= LogPerformanceWarning( |
| 4393 | device, kVUID_BestPractices_CreateSampler_LodClamping, |
| 4394 | "%s Creating a sampler object with LOD clamping (minLod = %f, maxLod = %f). This may cause reduced performance. " |
| 4395 | "Instead of clamping LOD in the sampler, consider using an VkImageView which restricts the mip-levels, set minLod " |
| 4396 | "to 0.0, and maxLod to VK_LOD_CLAMP_NONE.", |
| 4397 | VendorSpecificTag(kBPVendorArm), pCreateInfo->minLod, pCreateInfo->maxLod); |
| 4398 | } |
| 4399 | |
| 4400 | if (pCreateInfo->mipLodBias != 0.0f) { |
| 4401 | skip |= |
| 4402 | LogPerformanceWarning(device, kVUID_BestPractices_CreateSampler_LodBias, |
| 4403 | "%s Creating a sampler object with LOD bias != 0.0 (%f). This will lead to less efficient " |
| 4404 | "descriptors being created and may cause reduced performance.", |
| 4405 | VendorSpecificTag(kBPVendorArm), pCreateInfo->mipLodBias); |
| 4406 | } |
| 4407 | |
| 4408 | if ((pCreateInfo->addressModeU == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER || |
| 4409 | pCreateInfo->addressModeV == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER || |
| 4410 | pCreateInfo->addressModeW == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER) && |
| 4411 | (pCreateInfo->borderColor != VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK)) { |
| 4412 | skip |= LogPerformanceWarning( |
| 4413 | device, kVUID_BestPractices_CreateSampler_BorderClampColor, |
| 4414 | "%s Creating a sampler object with border clamping and borderColor != VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK. " |
| 4415 | "This will lead to less efficient descriptors being created and may cause reduced performance. " |
| 4416 | "If possible, use VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK as the border color.", |
| 4417 | VendorSpecificTag(kBPVendorArm)); |
| 4418 | } |
| 4419 | |
| 4420 | if (pCreateInfo->unnormalizedCoordinates) { |
| 4421 | skip |= LogPerformanceWarning( |
| 4422 | device, kVUID_BestPractices_CreateSampler_UnnormalizedCoordinates, |
| 4423 | "%s Creating a sampler object with unnormalized coordinates. This will lead to less efficient " |
| 4424 | "descriptors being created and may cause reduced performance.", |
| 4425 | VendorSpecificTag(kBPVendorArm)); |
| 4426 | } |
| 4427 | |
| 4428 | if (pCreateInfo->anisotropyEnable) { |
| 4429 | skip |= LogPerformanceWarning( |
| 4430 | device, kVUID_BestPractices_CreateSampler_Anisotropy, |
| 4431 | "%s Creating a sampler object with anisotropy. This will lead to less efficient descriptors being created " |
| 4432 | "and may cause reduced performance.", |
| 4433 | VendorSpecificTag(kBPVendorArm)); |
| 4434 | } |
| 4435 | } |
| 4436 | |
| 4437 | return skip; |
| 4438 | } |
Sam Walls | 8e77e4f | 2020-03-16 20:47:40 +0000 | [diff] [blame] | 4439 | |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 4440 | void BestPractices::PreCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount, |
| 4441 | const VkGraphicsPipelineCreateInfo* pCreateInfos, |
| 4442 | const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines, |
| 4443 | void* cgpl_state) { |
| 4444 | ValidationStateTracker::PreCallRecordCreateGraphicsPipelines(device, pipelineCache, createInfoCount, pCreateInfos, pAllocator, |
| 4445 | pPipelines); |
| 4446 | // AMD best practice |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4447 | num_pso_ += createInfoCount; |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 4448 | } |
| 4449 | |
| 4450 | bool BestPractices::PreCallValidateUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount, |
| 4451 | const VkWriteDescriptorSet* pDescriptorWrites, uint32_t descriptorCopyCount, |
| 4452 | const VkCopyDescriptorSet* pDescriptorCopies) const { |
| 4453 | bool skip = false; |
| 4454 | if (VendorCheckEnabled(kBPVendorAMD)) { |
| 4455 | if (descriptorCopyCount > 0) { |
| 4456 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_UpdateDescriptors_AvoidCopyingDescriptors, |
| 4457 | "%s Performance warning: copying descriptor sets is not recommended", |
| 4458 | VendorSpecificTag(kBPVendorAMD)); |
| 4459 | } |
| 4460 | } |
| 4461 | |
| 4462 | return skip; |
| 4463 | } |
| 4464 | |
| 4465 | bool BestPractices::PreCallValidateCreateDescriptorUpdateTemplate(VkDevice device, |
| 4466 | const VkDescriptorUpdateTemplateCreateInfo* pCreateInfo, |
| 4467 | const VkAllocationCallbacks* pAllocator, |
| 4468 | VkDescriptorUpdateTemplate* pDescriptorUpdateTemplate) const { |
| 4469 | bool skip = false; |
| 4470 | if (VendorCheckEnabled(kBPVendorAMD)) { |
| 4471 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_UpdateDescriptors_PreferNonTemplate, |
| 4472 | "%s Performance warning: using DescriptorSetWithTemplate is not recommended. Prefer using " |
| 4473 | "vkUpdateDescriptorSet instead", |
| 4474 | VendorSpecificTag(kBPVendorAMD)); |
| 4475 | } |
| 4476 | |
| 4477 | return skip; |
| 4478 | } |
| 4479 | |
| 4480 | bool BestPractices::PreCallValidateCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 4481 | const VkClearColorValue* pColor, uint32_t rangeCount, |
| 4482 | const VkImageSubresourceRange* pRanges) const { |
| 4483 | bool skip = false; |
| 4484 | if (VendorCheckEnabled(kBPVendorAMD)) { |
sfricke-samsung | ef15e48 | 2022-01-26 11:32:49 -0800 | [diff] [blame] | 4485 | skip |= LogPerformanceWarning( |
| 4486 | device, kVUID_BestPractices_ClearAttachment_ClearImage, |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 4487 | "%s Performance warning: using vkCmdClearColorImage is not recommended. Prefer using LOAD_OP_CLEAR or " |
| 4488 | "vkCmdClearAttachments instead", |
| 4489 | VendorSpecificTag(kBPVendorAMD)); |
| 4490 | } |
| 4491 | |
| 4492 | return skip; |
| 4493 | } |
| 4494 | |
| 4495 | bool BestPractices::PreCallValidateCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image, |
| 4496 | VkImageLayout imageLayout, |
| 4497 | const VkClearDepthStencilValue* pDepthStencil, uint32_t rangeCount, |
| 4498 | const VkImageSubresourceRange* pRanges) const { |
| 4499 | bool skip = false; |
| 4500 | if (VendorCheckEnabled(kBPVendorAMD)) { |
| 4501 | skip |= LogPerformanceWarning( |
| 4502 | device, kVUID_BestPractices_ClearAttachment_ClearImage, |
| 4503 | "%s Performance warning: using vkCmdClearDepthStencilImage is not recommended. Prefer using LOAD_OP_CLEAR or " |
| 4504 | "vkCmdClearAttachments instead", |
| 4505 | VendorSpecificTag(kBPVendorAMD)); |
| 4506 | } |
Rodrigo Locatti | 0b16cda | 2022-04-01 17:59:53 -0300 | [diff] [blame^] | 4507 | if (VendorCheckEnabled(kBPVendorNVIDIA)) { |
| 4508 | for (uint32_t i = 0; i < rangeCount; i++) { |
| 4509 | skip |= ValidateZcull(commandBuffer, image, pRanges[i]); |
| 4510 | } |
| 4511 | } |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 4512 | |
| 4513 | return skip; |
| 4514 | } |
| 4515 | |
| 4516 | bool BestPractices::PreCallValidateCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, |
| 4517 | const VkAllocationCallbacks* pAllocator, |
| 4518 | VkPipelineLayout* pPipelineLayout) const { |
| 4519 | bool skip = false; |
| 4520 | if (VendorCheckEnabled(kBPVendorAMD)) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4521 | uint32_t descriptor_size = enabled_features.core.robustBufferAccess ? 4 : 2; |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 4522 | // Descriptor sets cost 1 DWORD each. |
| 4523 | // Dynamic buffers cost 2 DWORDs each when robust buffer access is OFF. |
| 4524 | // Dynamic buffers cost 4 DWORDs each when robust buffer access is ON. |
| 4525 | // Push constants cost 1 DWORD per 4 bytes in the Push constant range. |
| 4526 | uint32_t pipeline_size = pCreateInfo->setLayoutCount; // in DWORDS |
| 4527 | for (uint32_t i = 0; i < pCreateInfo->setLayoutCount; i++) { |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 4528 | auto descriptor_set_layout_state = Get<cvdescriptorset::DescriptorSetLayout>(pCreateInfo->pSetLayouts[i]); |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4529 | pipeline_size += descriptor_set_layout_state->GetDynamicDescriptorCount() * descriptor_size; |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 4530 | } |
| 4531 | |
| 4532 | for (uint32_t i = 0; i < pCreateInfo->pushConstantRangeCount; i++) { |
| 4533 | pipeline_size += pCreateInfo->pPushConstantRanges[i].size / 4; |
| 4534 | } |
| 4535 | |
| 4536 | if (pipeline_size > kPipelineLayoutSizeWarningLimitAMD) { |
| 4537 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_CreatePipelinesLayout_KeepLayoutSmall, |
| 4538 | "%s Performance warning: pipeline layout size is too large. Prefer smaller pipeline layouts." |
| 4539 | "Descriptor sets cost 1 DWORD each. " |
| 4540 | "Dynamic buffers cost 2 DWORDs each when robust buffer access is OFF. " |
| 4541 | "Dynamic buffers cost 4 DWORDs each when robust buffer access is ON. " |
| 4542 | "Push constants cost 1 DWORD per 4 bytes in the Push constant range. ", |
| 4543 | VendorSpecificTag(kBPVendorAMD)); |
| 4544 | } |
| 4545 | } |
| 4546 | |
Rodrigo Locatti | 65b3383 | 2022-03-15 17:57:30 -0300 | [diff] [blame] | 4547 | if (VendorCheckEnabled(kBPVendorNVIDIA)) { |
| 4548 | bool has_separate_sampler = false; |
Rodrigo Locatti | 12f6ffc | 2022-03-15 18:29:11 -0300 | [diff] [blame] | 4549 | size_t fast_space_usage = 0; |
Rodrigo Locatti | 65b3383 | 2022-03-15 17:57:30 -0300 | [diff] [blame] | 4550 | |
| 4551 | for (uint32_t i = 0; i < pCreateInfo->setLayoutCount; ++i) { |
| 4552 | auto descriptor_set_layout_state = Get<cvdescriptorset::DescriptorSetLayout>(pCreateInfo->pSetLayouts[i]); |
| 4553 | for (const auto& binding : descriptor_set_layout_state->GetBindings()) { |
| 4554 | if (binding.descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER) { |
| 4555 | has_separate_sampler = true; |
| 4556 | } |
Rodrigo Locatti | 12f6ffc | 2022-03-15 18:29:11 -0300 | [diff] [blame] | 4557 | |
| 4558 | if ((descriptor_set_layout_state->GetCreateFlags() & VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT) == 0U) { |
| 4559 | size_t descriptor_type_size = 0; |
| 4560 | |
| 4561 | switch (binding.descriptorType) { |
| 4562 | case VK_DESCRIPTOR_TYPE_SAMPLER: |
| 4563 | case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: |
| 4564 | case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: |
| 4565 | case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: |
| 4566 | case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: |
| 4567 | case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: |
| 4568 | case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: |
| 4569 | descriptor_type_size = 4; |
| 4570 | break; |
| 4571 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: |
| 4572 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: |
| 4573 | case VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR: |
| 4574 | case VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_NV: |
| 4575 | descriptor_type_size = 8; |
| 4576 | break; |
| 4577 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: |
| 4578 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: |
| 4579 | case VK_DESCRIPTOR_TYPE_MUTABLE_VALVE: |
| 4580 | descriptor_type_size = 16; |
| 4581 | break; |
| 4582 | case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK: |
| 4583 | descriptor_type_size = 1; |
| 4584 | default: |
| 4585 | // Unknown type. |
| 4586 | break; |
| 4587 | } |
| 4588 | |
| 4589 | size_t descriptor_size = descriptor_type_size * binding.descriptorCount; |
| 4590 | fast_space_usage += descriptor_size; |
| 4591 | } |
Rodrigo Locatti | 65b3383 | 2022-03-15 17:57:30 -0300 | [diff] [blame] | 4592 | } |
| 4593 | } |
| 4594 | |
| 4595 | if (has_separate_sampler) { |
| 4596 | skip |= LogPerformanceWarning( |
| 4597 | device, kVUID_BestPractices_CreatePipelineLayout_SeparateSampler, |
| 4598 | "%s Consider using combined image samplers instead of separate samplers for marginally better performance.", |
| 4599 | VendorSpecificTag(kBPVendorNVIDIA)); |
| 4600 | } |
Rodrigo Locatti | 12f6ffc | 2022-03-15 18:29:11 -0300 | [diff] [blame] | 4601 | |
| 4602 | if (fast_space_usage > kPipelineLayoutFastDescriptorSpaceNVIDIA) { |
| 4603 | skip |= LogPerformanceWarning( |
| 4604 | device, kVUID_BestPractices_CreatePipelinesLayout_LargePipelineLayout, |
| 4605 | "%s Pipeline layout size is too large, prefer using pipeline-specific descriptor set layouts. " |
| 4606 | "Aim for consuming less than %" PRIu32 " bytes to allow fast reads for all non-bindless descriptors. " |
| 4607 | "Samplers, textures, texel buffers, and combined image samplers consume 4 bytes each. " |
| 4608 | "Uniform buffers and acceleration structures consume 8 bytes. " |
| 4609 | "Storage buffers consume 16 bytes. " |
| 4610 | "Push constants do not consume space.", |
| 4611 | VendorSpecificTag(kBPVendorNVIDIA), kPipelineLayoutFastDescriptorSpaceNVIDIA); |
| 4612 | } |
Rodrigo Locatti | 65b3383 | 2022-03-15 17:57:30 -0300 | [diff] [blame] | 4613 | } |
| 4614 | |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 4615 | return skip; |
| 4616 | } |
| 4617 | |
| 4618 | bool BestPractices::PreCallValidateCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4619 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4620 | const VkImageCopy* pRegions) const { |
| 4621 | bool skip = false; |
| 4622 | std::stringstream src_image_hex; |
| 4623 | std::stringstream dst_image_hex; |
| 4624 | src_image_hex << "0x" << std::hex << HandleToUint64(srcImage); |
| 4625 | dst_image_hex << "0x" << std::hex << HandleToUint64(dstImage); |
| 4626 | |
| 4627 | if (VendorCheckEnabled(kBPVendorAMD)) { |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4628 | auto src_state = Get<IMAGE_STATE>(srcImage); |
| 4629 | auto dst_state = Get<IMAGE_STATE>(dstImage); |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 4630 | |
| 4631 | if (src_state && dst_state) { |
| 4632 | VkImageTiling src_Tiling = src_state->createInfo.tiling; |
| 4633 | VkImageTiling dst_Tiling = dst_state->createInfo.tiling; |
| 4634 | if (src_Tiling != dst_Tiling && (src_Tiling == VK_IMAGE_TILING_LINEAR || dst_Tiling == VK_IMAGE_TILING_LINEAR)) { |
| 4635 | skip |= |
| 4636 | LogPerformanceWarning(device, kVUID_BestPractices_vkImage_AvoidImageToImageCopy, |
| 4637 | "%s Performance warning: image %s and image %s have differing tilings. Use buffer to " |
| 4638 | "image (vkCmdCopyImageToBuffer) " |
| 4639 | "and image to buffer (vkCmdCopyBufferToImage) copies instead of image to image " |
| 4640 | "copies when converting between linear and optimal images", |
| 4641 | VendorSpecificTag(kBPVendorAMD), src_image_hex.str().c_str(), dst_image_hex.str().c_str()); |
| 4642 | } |
| 4643 | } |
| 4644 | } |
| 4645 | |
| 4646 | return skip; |
| 4647 | } |
| 4648 | |
| 4649 | bool BestPractices::PreCallValidateCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, |
| 4650 | VkPipeline pipeline) const { |
| 4651 | bool skip = false; |
| 4652 | |
Rodrigo Locatti | a5eaf6e | 2022-04-01 18:05:23 -0300 | [diff] [blame] | 4653 | auto cb = Get<bp_state::CommandBuffer>(commandBuffer); |
| 4654 | |
Rodrigo Locatti | 494e448 | 2022-03-30 16:37:40 -0300 | [diff] [blame] | 4655 | if (VendorCheckEnabled(kBPVendorAMD) || VendorCheckEnabled(kBPVendorNVIDIA)) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4656 | if (IsPipelineUsedInFrame(pipeline)) { |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 4657 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_Pipeline_SortAndBind, |
Rodrigo Locatti | 494e448 | 2022-03-30 16:37:40 -0300 | [diff] [blame] | 4658 | "%s %s Performance warning: Pipeline %s was bound twice in the frame. " |
| 4659 | "Keep pipeline state changes to a minimum, for example, by sorting draw calls by pipeline.", |
| 4660 | VendorSpecificTag(kBPVendorAMD), VendorSpecificTag(kBPVendorNVIDIA), |
| 4661 | report_data->FormatHandle(pipeline).c_str()); |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 4662 | } |
| 4663 | } |
Rodrigo Locatti | a5eaf6e | 2022-04-01 18:05:23 -0300 | [diff] [blame] | 4664 | if (VendorCheckEnabled(kBPVendorNVIDIA)) { |
| 4665 | const auto& tgm = cb->nv.tess_geometry_mesh; |
| 4666 | if (tgm.num_switches >= kNumBindPipelineTessGeometryMeshSwitchesThresholdNVIDIA && !tgm.threshold_signaled) { |
| 4667 | LogPerformanceWarning(commandBuffer, kVUID_BestPractices_BindPipeline_SwitchTessGeometryMesh, |
| 4668 | "%s Avoid switching between pipelines with and without tessellation, geometry, task, " |
| 4669 | "and/or mesh shaders. Group draw calls using these shader stages together.", |
| 4670 | VendorSpecificTag(kBPVendorNVIDIA)); |
| 4671 | // Do not set 'skip' so the number of switches gets properly counted after the message. |
| 4672 | } |
| 4673 | } |
| 4674 | |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 4675 | return skip; |
| 4676 | } |
| 4677 | |
| 4678 | void BestPractices::ManualPostCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo* pSubmits, |
| 4679 | VkFence fence, VkResult result) { |
| 4680 | // AMD best practice |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4681 | num_queue_submissions_ += submitCount; |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 4682 | } |
| 4683 | |
| 4684 | bool BestPractices::PreCallValidateQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo) const { |
| 4685 | bool skip = false; |
| 4686 | |
Rodrigo Locatti | 494e448 | 2022-03-30 16:37:40 -0300 | [diff] [blame] | 4687 | if (VendorCheckEnabled(kBPVendorAMD) || VendorCheckEnabled(kBPVendorNVIDIA)) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4688 | auto num = num_queue_submissions_.load(); |
| 4689 | if (num > kNumberOfSubmissionWarningLimitAMD) { |
| 4690 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_Submission_ReduceNumberOfSubmissions, |
Rodrigo Locatti | 494e448 | 2022-03-30 16:37:40 -0300 | [diff] [blame] | 4691 | "%s %s Performance warning: command buffers submitted %" PRId32 |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4692 | " times this frame. Submitting command buffers has a CPU " |
| 4693 | "and GPU overhead. Submit fewer times to incur less overhead.", |
Rodrigo Locatti | 494e448 | 2022-03-30 16:37:40 -0300 | [diff] [blame] | 4694 | VendorSpecificTag(kBPVendorAMD), VendorSpecificTag(kBPVendorNVIDIA), num); |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 4695 | } |
| 4696 | } |
| 4697 | |
| 4698 | return skip; |
| 4699 | } |
| 4700 | |
| 4701 | void BestPractices::PostCallRecordCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, |
| 4702 | VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, |
| 4703 | uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers, |
| 4704 | uint32_t bufferMemoryBarrierCount, |
| 4705 | const VkBufferMemoryBarrier* pBufferMemoryBarriers, |
| 4706 | uint32_t imageMemoryBarrierCount, |
| 4707 | const VkImageMemoryBarrier* pImageMemoryBarriers) { |
Rodrigo Locatti | 0b16cda | 2022-04-01 17:59:53 -0300 | [diff] [blame^] | 4708 | ValidationStateTracker::PostCallRecordCmdPipelineBarrier(commandBuffer, srcStageMask, dstStageMask, dependencyFlags, |
| 4709 | memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, |
| 4710 | pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers); |
| 4711 | |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4712 | num_barriers_objects_ += (memoryBarrierCount + imageMemoryBarrierCount + bufferMemoryBarrierCount); |
Rodrigo Locatti | 0b16cda | 2022-04-01 17:59:53 -0300 | [diff] [blame^] | 4713 | |
| 4714 | for (uint32_t i = 0; i < imageMemoryBarrierCount; ++i) { |
| 4715 | RecordCmdPipelineBarrierImageBarrier(commandBuffer, pImageMemoryBarriers[i]); |
| 4716 | } |
| 4717 | } |
| 4718 | |
| 4719 | void BestPractices::PostCallRecordCmdPipelineBarrier2(VkCommandBuffer commandBuffer, const VkDependencyInfo *pDependencyInfo) { |
| 4720 | ValidationStateTracker::PostCallRecordCmdPipelineBarrier2(commandBuffer, pDependencyInfo); |
| 4721 | |
| 4722 | for (uint32_t i = 0; i < pDependencyInfo->imageMemoryBarrierCount; ++i) { |
| 4723 | RecordCmdPipelineBarrierImageBarrier(commandBuffer, pDependencyInfo->pImageMemoryBarriers[i]); |
| 4724 | } |
| 4725 | } |
| 4726 | |
| 4727 | void BestPractices::PostCallRecordCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer, const VkDependencyInfo *pDependencyInfo) { |
| 4728 | ValidationStateTracker::PostCallRecordCmdPipelineBarrier2KHR(commandBuffer, pDependencyInfo); |
| 4729 | |
| 4730 | for (uint32_t i = 0; i < pDependencyInfo->imageMemoryBarrierCount; ++i) { |
| 4731 | RecordCmdPipelineBarrierImageBarrier(commandBuffer, pDependencyInfo->pImageMemoryBarriers[i]); |
| 4732 | } |
| 4733 | } |
| 4734 | |
| 4735 | template <typename ImageMemoryBarrier> |
| 4736 | void BestPractices::RecordCmdPipelineBarrierImageBarrier(VkCommandBuffer commandBuffer, const ImageMemoryBarrier& barrier) { |
| 4737 | auto cb = Get<bp_state::CommandBuffer>(commandBuffer); |
| 4738 | assert(cb); |
| 4739 | |
| 4740 | if (VendorCheckEnabled(kBPVendorNVIDIA)) { |
| 4741 | RecordResetZcullDirection(*cb, barrier.image, barrier.subresourceRange); |
| 4742 | } |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 4743 | } |
| 4744 | |
| 4745 | bool BestPractices::PreCallValidateCreateSemaphore(VkDevice device, const VkSemaphoreCreateInfo* pCreateInfo, |
| 4746 | const VkAllocationCallbacks* pAllocator, VkSemaphore* pSemaphore) const { |
| 4747 | bool skip = false; |
Rodrigo Locatti | 494e448 | 2022-03-30 16:37:40 -0300 | [diff] [blame] | 4748 | if (VendorCheckEnabled(kBPVendorAMD) || VendorCheckEnabled(kBPVendorNVIDIA)) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4749 | if (Count<SEMAPHORE_STATE>() > kMaxRecommendedSemaphoreObjectsSizeAMD) { |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 4750 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_SyncObjects_HighNumberOfSemaphores, |
Rodrigo Locatti | 494e448 | 2022-03-30 16:37:40 -0300 | [diff] [blame] | 4751 | "%s %s Performance warning: High number of vkSemaphore objects created. " |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 4752 | "Minimize the amount of queue synchronization that is used. " |
| 4753 | "Semaphores and fences have overhead. Each fence has a CPU and GPU cost with it.", |
Rodrigo Locatti | 494e448 | 2022-03-30 16:37:40 -0300 | [diff] [blame] | 4754 | VendorSpecificTag(kBPVendorAMD), VendorSpecificTag(kBPVendorNVIDIA)); |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 4755 | } |
| 4756 | } |
| 4757 | |
| 4758 | return skip; |
| 4759 | } |
| 4760 | |
| 4761 | bool BestPractices::PreCallValidateCreateFence(VkDevice device, const VkFenceCreateInfo* pCreateInfo, |
| 4762 | const VkAllocationCallbacks* pAllocator, VkFence* pFence) const { |
| 4763 | bool skip = false; |
Rodrigo Locatti | 494e448 | 2022-03-30 16:37:40 -0300 | [diff] [blame] | 4764 | if (VendorCheckEnabled(kBPVendorAMD) || VendorCheckEnabled(kBPVendorNVIDIA)) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4765 | if (Count<FENCE_STATE>() > kMaxRecommendedFenceObjectsSizeAMD) { |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 4766 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_SyncObjects_HighNumberOfFences, |
Rodrigo Locatti | 494e448 | 2022-03-30 16:37:40 -0300 | [diff] [blame] | 4767 | "%s %s Performance warning: High number of VkFence objects created." |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 4768 | "Minimize the amount of CPU-GPU synchronization that is used. " |
Rodrigo Locatti | 494e448 | 2022-03-30 16:37:40 -0300 | [diff] [blame] | 4769 | "Semaphores and fences have overhead. Each fence has a CPU and GPU cost with it.", |
| 4770 | VendorSpecificTag(kBPVendorAMD), VendorSpecificTag(kBPVendorNVIDIA)); |
Nadav Geva | f080844 | 2021-05-21 13:51:25 -0400 | [diff] [blame] | 4771 | } |
| 4772 | } |
| 4773 | |
| 4774 | return skip; |
| 4775 | } |
| 4776 | |
Sam Walls | 8e77e4f | 2020-03-16 20:47:40 +0000 | [diff] [blame] | 4777 | void BestPractices::PostTransformLRUCacheModel::resize(size_t size) { _entries.resize(size); } |
| 4778 | |
| 4779 | bool BestPractices::PostTransformLRUCacheModel::query_cache(uint32_t value) { |
| 4780 | // look for a cache hit |
| 4781 | auto hit = std::find_if(_entries.begin(), _entries.end(), [value](const CacheEntry& entry) { return entry.value == value; }); |
| 4782 | if (hit != _entries.end()) { |
| 4783 | // mark the cache hit as being most recently used |
| 4784 | hit->age = iteration++; |
| 4785 | return true; |
| 4786 | } |
| 4787 | |
| 4788 | // if there's no cache hit, we need to model the entry being inserted into the cache |
| 4789 | CacheEntry new_entry = {value, iteration}; |
| 4790 | if (iteration < static_cast<uint32_t>(std::distance(_entries.begin(), _entries.end()))) { |
| 4791 | // if there is still space left in the cache, use the next available slot |
| 4792 | *(_entries.begin() + iteration) = new_entry; |
| 4793 | } else { |
| 4794 | // otherwise replace the least recently used cache entry |
| 4795 | auto lru = std::min_element(_entries.begin(), hit, [](const CacheEntry& a, const CacheEntry& b) { return a.age < b.age; }); |
| 4796 | *lru = new_entry; |
| 4797 | } |
| 4798 | iteration++; |
| 4799 | return false; |
| 4800 | } |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 4801 | |
| 4802 | bool BestPractices::PreCallValidateAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout, |
| 4803 | VkSemaphore semaphore, VkFence fence, uint32_t* pImageIndex) const { |
Jeremy Gebben | f444939 | 2022-01-28 10:09:10 -0700 | [diff] [blame] | 4804 | auto swapchain_data = Get<SWAPCHAIN_NODE>(swapchain); |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 4805 | bool skip = false; |
| 4806 | if (swapchain_data && swapchain_data->images.size() == 0) { |
| 4807 | skip |= LogWarning(swapchain, kVUID_Core_DrawState_SwapchainImagesNotFound, |
| 4808 | "vkAcquireNextImageKHR: No images found to acquire from. Application probably did not call " |
| 4809 | "vkGetSwapchainImagesKHR after swapchain creation."); |
| 4810 | } |
| 4811 | return skip; |
| 4812 | } |
| 4813 | |
Nathaniel Cesario | 56a9665 | 2020-12-30 13:23:42 -0700 | [diff] [blame] | 4814 | void BestPractices::CommonPostCallRecordGetPhysicalDeviceQueueFamilyProperties(CALL_STATE& call_state, bool no_pointer) { |
| 4815 | if (no_pointer) { |
| 4816 | if (UNCALLED == call_state) { |
| 4817 | call_state = QUERY_COUNT; |
| 4818 | } |
| 4819 | } else { // Save queue family properties |
| 4820 | call_state = QUERY_DETAILS; |
| 4821 | } |
| 4822 | } |
| 4823 | |
Nathaniel Cesario | f121d12 | 2020-10-08 13:09:46 -0600 | [diff] [blame] | 4824 | void BestPractices::PostCallRecordGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, |
| 4825 | uint32_t* pQueueFamilyPropertyCount, |
| 4826 | VkQueueFamilyProperties* pQueueFamilyProperties) { |
| 4827 | ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties(physicalDevice, pQueueFamilyPropertyCount, |
| 4828 | pQueueFamilyProperties); |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4829 | auto bp_pd_state = Get<bp_state::PhysicalDevice>(physicalDevice); |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 4830 | if (bp_pd_state) { |
Nathaniel Cesario | 56a9665 | 2020-12-30 13:23:42 -0700 | [diff] [blame] | 4831 | CommonPostCallRecordGetPhysicalDeviceQueueFamilyProperties(bp_pd_state->vkGetPhysicalDeviceQueueFamilyPropertiesState, |
| 4832 | nullptr == pQueueFamilyProperties); |
| 4833 | } |
| 4834 | } |
| 4835 | |
| 4836 | void BestPractices::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2(VkPhysicalDevice physicalDevice, |
| 4837 | uint32_t* pQueueFamilyPropertyCount, |
| 4838 | VkQueueFamilyProperties2* pQueueFamilyProperties) { |
| 4839 | ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2(physicalDevice, pQueueFamilyPropertyCount, |
| 4840 | pQueueFamilyProperties); |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4841 | auto bp_pd_state = Get<bp_state::PhysicalDevice>(physicalDevice); |
Nathaniel Cesario | 56a9665 | 2020-12-30 13:23:42 -0700 | [diff] [blame] | 4842 | if (bp_pd_state) { |
| 4843 | CommonPostCallRecordGetPhysicalDeviceQueueFamilyProperties(bp_pd_state->vkGetPhysicalDeviceQueueFamilyProperties2State, |
| 4844 | nullptr == pQueueFamilyProperties); |
| 4845 | } |
| 4846 | } |
| 4847 | |
| 4848 | void BestPractices::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2KHR(VkPhysicalDevice physicalDevice, |
| 4849 | uint32_t* pQueueFamilyPropertyCount, |
| 4850 | VkQueueFamilyProperties2* pQueueFamilyProperties) { |
| 4851 | ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2KHR(physicalDevice, pQueueFamilyPropertyCount, |
| 4852 | pQueueFamilyProperties); |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4853 | auto bp_pd_state = Get<bp_state::PhysicalDevice>(physicalDevice); |
Nathaniel Cesario | 56a9665 | 2020-12-30 13:23:42 -0700 | [diff] [blame] | 4854 | if (bp_pd_state) { |
| 4855 | CommonPostCallRecordGetPhysicalDeviceQueueFamilyProperties(bp_pd_state->vkGetPhysicalDeviceQueueFamilyProperties2KHRState, |
| 4856 | nullptr == pQueueFamilyProperties); |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 4857 | } |
| 4858 | } |
| 4859 | |
Nathaniel Cesario | f121d12 | 2020-10-08 13:09:46 -0600 | [diff] [blame] | 4860 | void BestPractices::PostCallRecordGetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures* pFeatures) { |
| 4861 | ValidationStateTracker::PostCallRecordGetPhysicalDeviceFeatures(physicalDevice, pFeatures); |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4862 | auto bp_pd_state = Get<bp_state::PhysicalDevice>(physicalDevice); |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 4863 | if (bp_pd_state) { |
| 4864 | bp_pd_state->vkGetPhysicalDeviceFeaturesState = QUERY_DETAILS; |
| 4865 | } |
| 4866 | } |
| 4867 | |
Nathaniel Cesario | f121d12 | 2020-10-08 13:09:46 -0600 | [diff] [blame] | 4868 | void BestPractices::PostCallRecordGetPhysicalDeviceFeatures2(VkPhysicalDevice physicalDevice, |
| 4869 | VkPhysicalDeviceFeatures2* pFeatures) { |
| 4870 | ValidationStateTracker::PostCallRecordGetPhysicalDeviceFeatures2(physicalDevice, pFeatures); |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4871 | auto bp_pd_state = Get<bp_state::PhysicalDevice>(physicalDevice); |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 4872 | if (bp_pd_state) { |
| 4873 | bp_pd_state->vkGetPhysicalDeviceFeaturesState = QUERY_DETAILS; |
| 4874 | } |
| 4875 | } |
| 4876 | |
Nathaniel Cesario | f121d12 | 2020-10-08 13:09:46 -0600 | [diff] [blame] | 4877 | void BestPractices::PostCallRecordGetPhysicalDeviceFeatures2KHR(VkPhysicalDevice physicalDevice, |
| 4878 | VkPhysicalDeviceFeatures2* pFeatures) { |
| 4879 | ValidationStateTracker::PostCallRecordGetPhysicalDeviceFeatures2KHR(physicalDevice, pFeatures); |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4880 | auto bp_pd_state = Get<bp_state::PhysicalDevice>(physicalDevice); |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 4881 | if (bp_pd_state) { |
| 4882 | bp_pd_state->vkGetPhysicalDeviceFeaturesState = QUERY_DETAILS; |
| 4883 | } |
| 4884 | } |
| 4885 | |
| 4886 | void BestPractices::ManualPostCallRecordGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice, |
| 4887 | VkSurfaceKHR surface, |
| 4888 | VkSurfaceCapabilitiesKHR* pSurfaceCapabilities, |
| 4889 | VkResult result) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4890 | auto bp_pd_state = Get<bp_state::PhysicalDevice>(physicalDevice); |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 4891 | if (bp_pd_state) { |
| 4892 | bp_pd_state->vkGetPhysicalDeviceSurfaceCapabilitiesKHRState = QUERY_DETAILS; |
| 4893 | } |
| 4894 | } |
| 4895 | |
| 4896 | void BestPractices::ManualPostCallRecordGetPhysicalDeviceSurfaceCapabilities2KHR( |
| 4897 | VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo, |
| 4898 | VkSurfaceCapabilities2KHR* pSurfaceCapabilities, VkResult result) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4899 | auto bp_pd_state = Get<bp_state::PhysicalDevice>(physicalDevice); |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 4900 | if (bp_pd_state) { |
| 4901 | bp_pd_state->vkGetPhysicalDeviceSurfaceCapabilitiesKHRState = QUERY_DETAILS; |
| 4902 | } |
| 4903 | } |
| 4904 | |
| 4905 | void BestPractices::ManualPostCallRecordGetPhysicalDeviceSurfaceCapabilities2EXT(VkPhysicalDevice physicalDevice, |
| 4906 | VkSurfaceKHR surface, |
| 4907 | VkSurfaceCapabilities2EXT* pSurfaceCapabilities, |
| 4908 | VkResult result) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4909 | auto bp_pd_state = Get<bp_state::PhysicalDevice>(physicalDevice); |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 4910 | if (bp_pd_state) { |
| 4911 | bp_pd_state->vkGetPhysicalDeviceSurfaceCapabilitiesKHRState = QUERY_DETAILS; |
| 4912 | } |
| 4913 | } |
| 4914 | |
| 4915 | void BestPractices::ManualPostCallRecordGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice, |
| 4916 | VkSurfaceKHR surface, uint32_t* pPresentModeCount, |
| 4917 | VkPresentModeKHR* pPresentModes, VkResult result) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4918 | auto bp_pd_data = Get<bp_state::PhysicalDevice>(physicalDevice); |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 4919 | if (bp_pd_data) { |
| 4920 | auto& call_state = bp_pd_data->vkGetPhysicalDeviceSurfacePresentModesKHRState; |
| 4921 | |
| 4922 | if (*pPresentModeCount) { |
| 4923 | if (call_state < QUERY_COUNT) { |
| 4924 | call_state = QUERY_COUNT; |
| 4925 | } |
| 4926 | } |
| 4927 | if (pPresentModes) { |
| 4928 | if (call_state < QUERY_DETAILS) { |
| 4929 | call_state = QUERY_DETAILS; |
| 4930 | } |
| 4931 | } |
| 4932 | } |
| 4933 | } |
| 4934 | |
| 4935 | void BestPractices::ManualPostCallRecordGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, |
| 4936 | uint32_t* pSurfaceFormatCount, |
| 4937 | VkSurfaceFormatKHR* pSurfaceFormats, VkResult result) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4938 | auto bp_pd_data = Get<bp_state::PhysicalDevice>(physicalDevice); |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 4939 | if (bp_pd_data) { |
| 4940 | auto& call_state = bp_pd_data->vkGetPhysicalDeviceSurfaceFormatsKHRState; |
| 4941 | |
| 4942 | if (*pSurfaceFormatCount) { |
| 4943 | if (call_state < QUERY_COUNT) { |
| 4944 | call_state = QUERY_COUNT; |
| 4945 | } |
Jeremy Gebben | c7a834a | 2021-09-08 18:39:30 -0600 | [diff] [blame] | 4946 | bp_pd_data->surface_formats_count = *pSurfaceFormatCount; |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 4947 | } |
| 4948 | if (pSurfaceFormats) { |
| 4949 | if (call_state < QUERY_DETAILS) { |
| 4950 | call_state = QUERY_DETAILS; |
| 4951 | } |
| 4952 | } |
| 4953 | } |
| 4954 | } |
| 4955 | |
| 4956 | void BestPractices::ManualPostCallRecordGetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice, |
| 4957 | const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo, |
| 4958 | uint32_t* pSurfaceFormatCount, |
| 4959 | VkSurfaceFormat2KHR* pSurfaceFormats, VkResult result) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4960 | auto bp_pd_data = Get<bp_state::PhysicalDevice>(physicalDevice); |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 4961 | if (bp_pd_data) { |
| 4962 | if (*pSurfaceFormatCount) { |
| 4963 | if (bp_pd_data->vkGetPhysicalDeviceSurfaceFormatsKHRState < QUERY_COUNT) { |
| 4964 | bp_pd_data->vkGetPhysicalDeviceSurfaceFormatsKHRState = QUERY_COUNT; |
| 4965 | } |
Jeremy Gebben | c7a834a | 2021-09-08 18:39:30 -0600 | [diff] [blame] | 4966 | bp_pd_data->surface_formats_count = *pSurfaceFormatCount; |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 4967 | } |
| 4968 | if (pSurfaceFormats) { |
| 4969 | if (bp_pd_data->vkGetPhysicalDeviceSurfaceFormatsKHRState < QUERY_DETAILS) { |
| 4970 | bp_pd_data->vkGetPhysicalDeviceSurfaceFormatsKHRState = QUERY_DETAILS; |
| 4971 | } |
| 4972 | } |
| 4973 | } |
| 4974 | } |
| 4975 | |
| 4976 | void BestPractices::ManualPostCallRecordGetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice, |
| 4977 | uint32_t* pPropertyCount, |
| 4978 | VkDisplayPlanePropertiesKHR* pProperties, |
| 4979 | VkResult result) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4980 | auto bp_pd_data = Get<bp_state::PhysicalDevice>(physicalDevice); |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 4981 | if (bp_pd_data) { |
| 4982 | if (*pPropertyCount) { |
| 4983 | if (bp_pd_data->vkGetPhysicalDeviceDisplayPlanePropertiesKHRState < QUERY_COUNT) { |
| 4984 | bp_pd_data->vkGetPhysicalDeviceDisplayPlanePropertiesKHRState = QUERY_COUNT; |
| 4985 | } |
| 4986 | } |
| 4987 | if (pProperties) { |
| 4988 | if (bp_pd_data->vkGetPhysicalDeviceDisplayPlanePropertiesKHRState < QUERY_DETAILS) { |
| 4989 | bp_pd_data->vkGetPhysicalDeviceDisplayPlanePropertiesKHRState = QUERY_DETAILS; |
| 4990 | } |
| 4991 | } |
| 4992 | } |
| 4993 | } |
| 4994 | |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 4995 | void BestPractices::ManualPostCallRecordGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, |
| 4996 | uint32_t* pSwapchainImageCount, VkImage* pSwapchainImages, |
| 4997 | VkResult result) { |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 4998 | auto swapchain_state = Get<bp_state::Swapchain>(swapchain); |
Nathaniel Cesario | 39152e6 | 2021-07-02 13:04:16 -0600 | [diff] [blame] | 4999 | if (swapchain_state && (pSwapchainImages || *pSwapchainImageCount)) { |
| 5000 | if (swapchain_state->vkGetSwapchainImagesKHRState < QUERY_DETAILS) { |
| 5001 | swapchain_state->vkGetSwapchainImagesKHRState = QUERY_DETAILS; |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 5002 | } |
| 5003 | } |
| 5004 | } |
| 5005 | |
Hans-Kristian Arntzen | 66f4b52 | 2021-03-22 11:35:58 +0100 | [diff] [blame] | 5006 | void BestPractices::PreCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence) { |
| 5007 | ValidationStateTracker::PreCallRecordQueueSubmit(queue, submitCount, pSubmits, fence); |
| 5008 | |
Jeremy Gebben | b20a824 | 2021-11-05 15:14:43 -0600 | [diff] [blame] | 5009 | auto queue_state = Get<QUEUE_STATE>(queue); |
Hans-Kristian Arntzen | 66f4b52 | 2021-03-22 11:35:58 +0100 | [diff] [blame] | 5010 | for (uint32_t submit = 0; submit < submitCount; submit++) { |
Hans-Kristian Arntzen | 69ace7d | 2021-04-28 14:17:19 +0200 | [diff] [blame] | 5011 | const auto& submit_info = pSubmits[submit]; |
Hans-Kristian Arntzen | 66f4b52 | 2021-03-22 11:35:58 +0100 | [diff] [blame] | 5012 | 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] | 5013 | auto cb = GetWrite<bp_state::CommandBuffer>(submit_info.pCommandBuffers[cb_index]); |
Hans-Kristian Arntzen | 66f4b52 | 2021-03-22 11:35:58 +0100 | [diff] [blame] | 5014 | for (auto &func : cb->queue_submit_functions) { |
Jeremy Gebben | e5361dd | 2021-11-18 14:23:56 -0700 | [diff] [blame] | 5015 | func(*this, *queue_state, *cb); |
Hans-Kristian Arntzen | 66f4b52 | 2021-03-22 11:35:58 +0100 | [diff] [blame] | 5016 | } |
| 5017 | } |
| 5018 | } |
| 5019 | } |