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