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