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