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