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