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