Mark Lobodzinski | 91e50bf | 2020-01-14 09:55:11 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2015-2020 The Khronos Group Inc. |
| 2 | * Copyright (c) 2015-2020 Valve Corporation |
| 3 | * Copyright (c) 2015-2020 LunarG, Inc. |
Camden | eaa86ea | 2019-07-26 11:00:09 -0600 | [diff] [blame] | 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | * |
| 17 | * Author: Camden Stocker <camden@lunarg.com> |
| 18 | */ |
| 19 | |
Mark Lobodzinski | 57b8ae8 | 2020-02-20 16:37:14 -0700 | [diff] [blame] | 20 | #include "best_practices_validation.h" |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 21 | #include "layer_chassis_dispatch.h" |
Camden Stocker | 0a660ce | 2019-08-27 15:30:40 -0600 | [diff] [blame] | 22 | #include "best_practices_error_enums.h" |
Sam Walls | d7ab6db | 2020-06-19 20:41:54 +0100 | [diff] [blame] | 23 | #include "shader_validation.h" |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 24 | |
| 25 | #include <string> |
Sam Walls | 8e77e4f | 2020-03-16 20:47:40 +0000 | [diff] [blame] | 26 | #include <bitset> |
Sam Walls | d7ab6db | 2020-06-19 20:41:54 +0100 | [diff] [blame] | 27 | #include <memory> |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 28 | |
Attilio Provenzano | 19d6a98 | 2020-02-27 12:41:41 +0000 | [diff] [blame] | 29 | struct VendorSpecificInfo { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 30 | EnableFlags vendor_id; |
Attilio Provenzano | 19d6a98 | 2020-02-27 12:41:41 +0000 | [diff] [blame] | 31 | std::string name; |
| 32 | }; |
| 33 | |
| 34 | const std::map<BPVendorFlagBits, VendorSpecificInfo> vendor_info = { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 35 | {kBPVendorArm, {vendor_specific_arm, "Arm"}}, |
Attilio Provenzano | 19d6a98 | 2020-02-27 12:41:41 +0000 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | bool BestPractices::VendorCheckEnabled(BPVendorFlags vendors) const { |
| 39 | for (const auto& vendor : vendor_info) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 40 | if (vendors & vendor.first && enabled[vendor.second.vendor_id]) { |
Attilio Provenzano | 19d6a98 | 2020-02-27 12:41:41 +0000 | [diff] [blame] | 41 | return true; |
| 42 | } |
| 43 | } |
| 44 | return false; |
| 45 | } |
| 46 | |
| 47 | const char* VendorSpecificTag(BPVendorFlags vendors) { |
| 48 | // Cache built vendor tags in a map |
| 49 | static std::unordered_map<BPVendorFlags, std::string> tag_map; |
| 50 | |
| 51 | auto res = tag_map.find(vendors); |
| 52 | if (res == tag_map.end()) { |
| 53 | // Build the vendor tag string |
| 54 | std::stringstream vendor_tag; |
| 55 | |
| 56 | vendor_tag << "["; |
| 57 | bool first_vendor = true; |
| 58 | for (const auto& vendor : vendor_info) { |
| 59 | if (vendors & vendor.first) { |
| 60 | if (!first_vendor) { |
| 61 | vendor_tag << ", "; |
| 62 | } |
| 63 | vendor_tag << vendor.second.name; |
| 64 | first_vendor = false; |
| 65 | } |
| 66 | } |
| 67 | vendor_tag << "]"; |
| 68 | |
| 69 | tag_map[vendors] = vendor_tag.str(); |
| 70 | res = tag_map.find(vendors); |
| 71 | } |
| 72 | |
| 73 | return res->second.c_str(); |
| 74 | } |
| 75 | |
Mark Lobodzinski | 6167e10 | 2020-02-24 17:03:55 -0700 | [diff] [blame] | 76 | const char* DepReasonToString(ExtDeprecationReason reason) { |
| 77 | switch (reason) { |
| 78 | case kExtPromoted: |
| 79 | return "promoted to"; |
| 80 | break; |
| 81 | case kExtObsoleted: |
| 82 | return "obsoleted by"; |
| 83 | break; |
| 84 | case kExtDeprecated: |
| 85 | return "deprecated by"; |
| 86 | break; |
| 87 | default: |
| 88 | return ""; |
| 89 | break; |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | bool BestPractices::ValidateDeprecatedExtensions(const char* api_name, const char* extension_name, uint32_t version, |
| 94 | const char* vuid) const { |
| 95 | bool skip = false; |
| 96 | auto dep_info_it = deprecated_extensions.find(extension_name); |
| 97 | if (dep_info_it != deprecated_extensions.end()) { |
| 98 | auto dep_info = dep_info_it->second; |
Mark Lobodzinski | 6a14970 | 2020-05-14 12:21:34 -0600 | [diff] [blame] | 99 | if (((dep_info.target.compare("VK_VERSION_1_1") == 0) && (version >= VK_API_VERSION_1_1)) || |
| 100 | ((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] | 101 | skip |= |
| 102 | LogWarning(instance, vuid, "%s(): Attempting to enable deprecated extension %s, but this extension has been %s %s.", |
| 103 | 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] | 104 | } else if (dep_info.target.find("VK_VERSION") == std::string::npos) { |
Mark Lobodzinski | 6167e10 | 2020-02-24 17:03:55 -0700 | [diff] [blame] | 105 | if (dep_info.target.length() == 0) { |
| 106 | skip |= LogWarning(instance, vuid, |
| 107 | "%s(): Attempting to enable deprecated extension %s, but this extension has been deprecated " |
| 108 | "without replacement.", |
| 109 | api_name, extension_name); |
| 110 | } else { |
| 111 | skip |= LogWarning(instance, vuid, |
| 112 | "%s(): Attempting to enable deprecated extension %s, but this extension has been %s %s.", |
| 113 | api_name, extension_name, DepReasonToString(dep_info.reason), (dep_info.target).c_str()); |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | return skip; |
| 118 | } |
| 119 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 120 | bool BestPractices::PreCallValidateCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 121 | VkInstance* pInstance) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 122 | bool skip = false; |
| 123 | |
| 124 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
| 125 | if (white_list(pCreateInfo->ppEnabledExtensionNames[i], kDeviceExtensionNames)) { |
Camden Stocker | 11ecf51 | 2020-01-21 16:06:49 -0800 | [diff] [blame] | 126 | skip |= LogWarning(instance, kVUID_BestPractices_CreateInstance_ExtensionMismatch, |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 127 | "vkCreateInstance(): Attempting to enable Device Extension %s at CreateInstance time.", |
| 128 | pCreateInfo->ppEnabledExtensionNames[i]); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 129 | } |
Mark Lobodzinski | 17d8dc6 | 2020-06-03 08:48:58 -0600 | [diff] [blame] | 130 | uint32_t specified_version = |
| 131 | (pCreateInfo->pApplicationInfo ? pCreateInfo->pApplicationInfo->apiVersion : VK_API_VERSION_1_0); |
| 132 | skip |= ValidateDeprecatedExtensions("CreateInstance", pCreateInfo->ppEnabledExtensionNames[i], specified_version, |
Mark Lobodzinski | 6167e10 | 2020-02-24 17:03:55 -0700 | [diff] [blame] | 133 | kVUID_BestPractices_CreateInstance_DeprecatedExtension); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | return skip; |
| 137 | } |
| 138 | |
| 139 | void BestPractices::PreCallRecordCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, |
| 140 | VkInstance* pInstance) { |
Mark Lobodzinski | 97484d6 | 2020-03-03 11:57:41 -0700 | [diff] [blame] | 141 | ValidationStateTracker::PreCallRecordCreateInstance(pCreateInfo, pAllocator, pInstance); |
Sam Walls | 53bf765 | 2020-04-21 17:35:15 +0100 | [diff] [blame] | 142 | |
| 143 | if (pCreateInfo != nullptr && pCreateInfo->pApplicationInfo != nullptr) |
| 144 | instance_api_version = pCreateInfo->pApplicationInfo->apiVersion; |
| 145 | else |
| 146 | instance_api_version = 0; |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | bool BestPractices::PreCallValidateCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* pCreateInfo, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 150 | const VkAllocationCallbacks* pAllocator, VkDevice* pDevice) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 151 | bool skip = false; |
| 152 | |
| 153 | // get API version of physical device passed when creating device. |
| 154 | VkPhysicalDeviceProperties physical_device_properties{}; |
| 155 | DispatchGetPhysicalDeviceProperties(physicalDevice, &physical_device_properties); |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 156 | auto device_api_version = physical_device_properties.apiVersion; |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 157 | |
| 158 | // check api versions and warn if instance api Version is higher than version on device. |
| 159 | if (instance_api_version > device_api_version) { |
Mark Lobodzinski | 6088078 | 2020-08-11 08:02:07 -0600 | [diff] [blame] | 160 | std::string inst_api_name = StringAPIVersion(instance_api_version); |
| 161 | std::string dev_api_name = StringAPIVersion(device_api_version); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 162 | |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 163 | skip |= LogWarning(device, kVUID_BestPractices_CreateDevice_API_Mismatch, |
| 164 | "vkCreateDevice(): API Version of current instance, %s is higher than API Version on device, %s", |
| 165 | inst_api_name.c_str(), dev_api_name.c_str()); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
| 169 | if (white_list(pCreateInfo->ppEnabledExtensionNames[i], kInstanceExtensionNames)) { |
Camden Stocker | 11ecf51 | 2020-01-21 16:06:49 -0800 | [diff] [blame] | 170 | skip |= LogWarning(instance, kVUID_BestPractices_CreateDevice_ExtensionMismatch, |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 171 | "vkCreateDevice(): Attempting to enable Instance Extension %s at CreateDevice time.", |
| 172 | pCreateInfo->ppEnabledExtensionNames[i]); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 173 | } |
Mark Lobodzinski | 6167e10 | 2020-02-24 17:03:55 -0700 | [diff] [blame] | 174 | skip |= ValidateDeprecatedExtensions("CreateDevice", pCreateInfo->ppEnabledExtensionNames[i], instance_api_version, |
| 175 | kVUID_BestPractices_CreateDevice_DeprecatedExtension); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 176 | } |
| 177 | |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 178 | auto pd_state = GetPhysicalDeviceState(physicalDevice); |
Cort | a48da1d | 2019-09-20 18:59:07 +0200 | [diff] [blame] | 179 | if ((pd_state->vkGetPhysicalDeviceFeaturesState == UNCALLED) && (pCreateInfo->pEnabledFeatures != NULL)) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 180 | skip |= LogWarning(device, kVUID_BestPractices_CreateDevice_PDFeaturesNotCalled, |
| 181 | "vkCreateDevice() called before getting physical device features from vkGetPhysicalDeviceFeatures()."); |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 182 | } |
| 183 | |
Szilard Papp | 7d2c795 | 2020-06-22 14:38:13 +0100 | [diff] [blame] | 184 | if ((VendorCheckEnabled(kBPVendorArm)) && (pCreateInfo->pEnabledFeatures != nullptr) && |
| 185 | (pCreateInfo->pEnabledFeatures->robustBufferAccess == VK_TRUE)) { |
| 186 | skip |= LogPerformanceWarning( |
| 187 | device, kVUID_BestPractices_CreateDevice_RobustBufferAccess, |
| 188 | "%s vkCreateDevice() called with enabled robustBufferAccess. Use robustBufferAccess as a debugging tool during " |
| 189 | "development. Enabling it causes loss in performance for accesses to uniform buffers and shader storage " |
| 190 | "buffers. Disable robustBufferAccess in release builds. Only leave it enabled if the application use-case " |
| 191 | "requires the additional level of reliability due to the use of unverified user-supplied draw parameters.", |
| 192 | VendorSpecificTag(kBPVendorArm)); |
| 193 | } |
| 194 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 195 | return skip; |
| 196 | } |
| 197 | |
| 198 | bool BestPractices::PreCallValidateCreateBuffer(VkDevice device, const VkBufferCreateInfo* pCreateInfo, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 199 | const VkAllocationCallbacks* pAllocator, VkBuffer* pBuffer) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 200 | bool skip = false; |
| 201 | |
| 202 | if ((pCreateInfo->queueFamilyIndexCount > 1) && (pCreateInfo->sharingMode == VK_SHARING_MODE_EXCLUSIVE)) { |
| 203 | std::stringstream bufferHex; |
| 204 | bufferHex << "0x" << std::hex << HandleToUint64(pBuffer); |
| 205 | |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 206 | skip |= LogWarning( |
| 207 | device, kVUID_BestPractices_SharingModeExclusive, |
| 208 | "Warning: Buffer (%s) specifies a sharing mode of VK_SHARING_MODE_EXCLUSIVE while specifying multiple queues " |
| 209 | "(queueFamilyIndexCount of %" PRIu32 ").", |
| 210 | bufferHex.str().c_str(), pCreateInfo->queueFamilyIndexCount); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | return skip; |
| 214 | } |
| 215 | |
| 216 | bool BestPractices::PreCallValidateCreateImage(VkDevice device, const VkImageCreateInfo* pCreateInfo, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 217 | const VkAllocationCallbacks* pAllocator, VkImage* pImage) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 218 | bool skip = false; |
| 219 | |
| 220 | if ((pCreateInfo->queueFamilyIndexCount > 1) && (pCreateInfo->sharingMode == VK_SHARING_MODE_EXCLUSIVE)) { |
| 221 | std::stringstream imageHex; |
| 222 | imageHex << "0x" << std::hex << HandleToUint64(pImage); |
| 223 | |
| 224 | skip |= |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 225 | LogWarning(device, kVUID_BestPractices_SharingModeExclusive, |
| 226 | "Warning: Image (%s) specifies a sharing mode of VK_SHARING_MODE_EXCLUSIVE while specifying multiple queues " |
| 227 | "(queueFamilyIndexCount of %" PRIu32 ").", |
| 228 | imageHex.str().c_str(), pCreateInfo->queueFamilyIndexCount); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 229 | } |
| 230 | |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 231 | if (VendorCheckEnabled(kBPVendorArm)) { |
| 232 | if (pCreateInfo->samples > kMaxEfficientSamplesArm) { |
| 233 | skip |= LogPerformanceWarning( |
| 234 | device, kVUID_BestPractices_CreateImage_TooLargeSampleCount, |
| 235 | "%s vkCreateImage(): Trying to create an image with %u samples. " |
| 236 | "The hardware revision may not have full throughput for framebuffers with more than %u samples.", |
| 237 | VendorSpecificTag(kBPVendorArm), static_cast<uint32_t>(pCreateInfo->samples), kMaxEfficientSamplesArm); |
| 238 | } |
| 239 | |
| 240 | if (pCreateInfo->samples > VK_SAMPLE_COUNT_1_BIT && !(pCreateInfo->usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT)) { |
| 241 | skip |= LogPerformanceWarning( |
| 242 | device, kVUID_BestPractices_CreateImage_NonTransientMSImage, |
| 243 | "%s vkCreateImage(): Trying to create a multisampled image, but createInfo.usage did not have " |
| 244 | "VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT set. Multisampled images may be resolved on-chip, " |
| 245 | "and do not need to be backed by physical storage. " |
| 246 | "TRANSIENT_ATTACHMENT allows tiled GPUs to not back the multisampled image with physical memory.", |
| 247 | VendorSpecificTag(kBPVendorArm)); |
| 248 | } |
| 249 | } |
| 250 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 251 | return skip; |
| 252 | } |
| 253 | |
| 254 | bool BestPractices::PreCallValidateCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR* pCreateInfo, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 255 | const VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pSwapchain) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 256 | bool skip = false; |
| 257 | |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 258 | auto physical_device_state = GetPhysicalDeviceState(); |
| 259 | |
| 260 | if (physical_device_state->vkGetPhysicalDeviceSurfaceCapabilitiesKHRState == UNCALLED) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 261 | skip |= LogWarning( |
| 262 | device, kVUID_BestPractices_Swapchain_GetSurfaceNotCalled, |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 263 | "vkCreateSwapchainKHR() called before getting surface capabilities from vkGetPhysicalDeviceSurfaceCapabilitiesKHR()."); |
| 264 | } |
| 265 | |
| 266 | if (physical_device_state->vkGetPhysicalDeviceSurfacePresentModesKHRState != QUERY_DETAILS) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 267 | skip |= LogWarning(device, kVUID_BestPractices_Swapchain_GetSurfaceNotCalled, |
| 268 | "vkCreateSwapchainKHR() called before getting surface present mode(s) from " |
| 269 | "vkGetPhysicalDeviceSurfacePresentModesKHR()."); |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | if (physical_device_state->vkGetPhysicalDeviceSurfaceFormatsKHRState != QUERY_DETAILS) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 273 | skip |= LogWarning( |
| 274 | device, kVUID_BestPractices_Swapchain_GetSurfaceNotCalled, |
| 275 | "vkCreateSwapchainKHR() called before getting surface format(s) from vkGetPhysicalDeviceSurfaceFormatsKHR()."); |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 276 | } |
| 277 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 278 | if ((pCreateInfo->queueFamilyIndexCount > 1) && (pCreateInfo->imageSharingMode == VK_SHARING_MODE_EXCLUSIVE)) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 279 | skip |= |
| 280 | LogWarning(device, kVUID_BestPractices_SharingModeExclusive, |
Mark Lobodzinski | 019f4e3 | 2020-04-13 11:01:35 -0600 | [diff] [blame] | 281 | "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] | 282 | "specifying multiple queues (queueFamilyIndexCount of %" PRIu32 ").", |
| 283 | pCreateInfo->queueFamilyIndexCount); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 284 | } |
| 285 | |
Szilard Papp | 48a6da3 | 2020-06-10 14:41:59 +0100 | [diff] [blame] | 286 | if (pCreateInfo->minImageCount == 2) { |
| 287 | skip |= LogPerformanceWarning( |
| 288 | device, kVUID_BestPractices_SuboptimalSwapchainImageCount, |
| 289 | "Warning: A Swapchain is being created with minImageCount set to %" PRIu32 |
| 290 | ", which means double buffering is going " |
| 291 | "to be used. Using double buffering and vsync locks rendering to an integer fraction of the vsync rate. In turn, " |
| 292 | "reducing the performance of the application if rendering is slower than vsync. Consider setting minImageCount to " |
| 293 | "3 to use triple buffering to maximize performance in such cases.", |
| 294 | pCreateInfo->minImageCount); |
| 295 | } |
| 296 | |
Szilard Papp | d5f0f81 | 2020-06-22 09:01:29 +0100 | [diff] [blame] | 297 | if (VendorCheckEnabled(kBPVendorArm) && (pCreateInfo->presentMode != VK_PRESENT_MODE_FIFO_KHR)) { |
| 298 | skip |= LogWarning(device, kVUID_BestPractices_CreateSwapchain_PresentMode, |
| 299 | "%s Warning: Swapchain is not being created with presentation mode \"VK_PRESENT_MODE_FIFO_KHR\". " |
| 300 | "Prefer using \"VK_PRESENT_MODE_FIFO_KHR\" to avoid unnecessary CPU and GPU load and save power. " |
| 301 | "Presentation modes which are not FIFO will present the latest available frame and discard other " |
| 302 | "frame(s) if any.", |
| 303 | VendorSpecificTag(kBPVendorArm)); |
| 304 | } |
| 305 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 306 | return skip; |
| 307 | } |
| 308 | |
| 309 | bool BestPractices::PreCallValidateCreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount, |
| 310 | const VkSwapchainCreateInfoKHR* pCreateInfos, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 311 | const VkAllocationCallbacks* pAllocator, |
| 312 | VkSwapchainKHR* pSwapchains) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 313 | bool skip = false; |
| 314 | |
| 315 | for (uint32_t i = 0; i < swapchainCount; i++) { |
| 316 | if ((pCreateInfos[i].queueFamilyIndexCount > 1) && (pCreateInfos[i].imageSharingMode == VK_SHARING_MODE_EXCLUSIVE)) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 317 | skip |= LogWarning( |
| 318 | device, kVUID_BestPractices_SharingModeExclusive, |
| 319 | "Warning: A shared swapchain (index %" PRIu32 |
| 320 | ") is being created which specifies a sharing mode of VK_SHARING_MODE_EXCLUSIVE while specifying multiple " |
| 321 | "queues (queueFamilyIndexCount of %" PRIu32 ").", |
| 322 | i, pCreateInfos[i].queueFamilyIndexCount); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 323 | } |
| 324 | } |
| 325 | |
| 326 | return skip; |
| 327 | } |
| 328 | |
| 329 | bool BestPractices::PreCallValidateCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 330 | const VkAllocationCallbacks* pAllocator, VkRenderPass* pRenderPass) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 331 | bool skip = false; |
| 332 | |
| 333 | for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) { |
| 334 | VkFormat format = pCreateInfo->pAttachments[i].format; |
| 335 | if (pCreateInfo->pAttachments[i].initialLayout == VK_IMAGE_LAYOUT_UNDEFINED) { |
| 336 | if ((FormatIsColor(format) || FormatHasDepth(format)) && |
| 337 | pCreateInfo->pAttachments[i].loadOp == VK_ATTACHMENT_LOAD_OP_LOAD) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 338 | skip |= LogWarning(device, kVUID_BestPractices_RenderPass_Attatchment, |
| 339 | "Render pass has an attachment with loadOp == VK_ATTACHMENT_LOAD_OP_LOAD and " |
| 340 | "initialLayout == VK_IMAGE_LAYOUT_UNDEFINED. This is probably not what you " |
| 341 | "intended. Consider using VK_ATTACHMENT_LOAD_OP_DONT_CARE instead if the " |
| 342 | "image truely is undefined at the start of the render pass."); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 343 | } |
| 344 | if (FormatHasStencil(format) && pCreateInfo->pAttachments[i].stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 345 | skip |= LogWarning(device, kVUID_BestPractices_RenderPass_Attatchment, |
| 346 | "Render pass has an attachment with stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD " |
| 347 | "and initialLayout == VK_IMAGE_LAYOUT_UNDEFINED. This is probably not what you " |
| 348 | "intended. Consider using VK_ATTACHMENT_LOAD_OP_DONT_CARE instead if the " |
| 349 | "image truely is undefined at the start of the render pass."); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 350 | } |
| 351 | } |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 352 | |
| 353 | const auto& attachment = pCreateInfo->pAttachments[i]; |
| 354 | if (attachment.samples > VK_SAMPLE_COUNT_1_BIT) { |
| 355 | bool access_requires_memory = |
| 356 | attachment.loadOp == VK_ATTACHMENT_LOAD_OP_LOAD || attachment.storeOp == VK_ATTACHMENT_STORE_OP_STORE; |
| 357 | |
| 358 | if (FormatHasStencil(format)) { |
| 359 | access_requires_memory |= attachment.stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD || |
| 360 | attachment.stencilStoreOp == VK_ATTACHMENT_STORE_OP_STORE; |
| 361 | } |
| 362 | |
| 363 | if (access_requires_memory) { |
| 364 | skip |= LogPerformanceWarning( |
| 365 | device, kVUID_BestPractices_CreateRenderPass_ImageRequiresMemory, |
| 366 | "Attachment %u in the VkRenderPass is a multisampled image with %u samples, but it uses loadOp/storeOp " |
| 367 | "which requires accessing data from memory. Multisampled images should always be loadOp = CLEAR or DONT_CARE, " |
| 368 | "storeOp = DONT_CARE. This allows the implementation to use lazily allocated memory effectively.", |
| 369 | i, static_cast<uint32_t>(attachment.samples)); |
| 370 | } |
| 371 | } |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | for (uint32_t dependency = 0; dependency < pCreateInfo->dependencyCount; dependency++) { |
| 375 | skip |= CheckPipelineStageFlags("vkCreateRenderPass", pCreateInfo->pDependencies[dependency].srcStageMask); |
| 376 | skip |= CheckPipelineStageFlags("vkCreateRenderPass", pCreateInfo->pDependencies[dependency].dstStageMask); |
| 377 | } |
| 378 | |
| 379 | return skip; |
| 380 | } |
| 381 | |
Tony-LunarG | 767180f | 2020-04-23 14:03:59 -0600 | [diff] [blame] | 382 | bool BestPractices::ValidateAttachments(const VkRenderPassCreateInfo2* rpci, uint32_t attachmentCount, |
| 383 | const VkImageView* image_views) const { |
| 384 | bool skip = false; |
| 385 | |
| 386 | // Check for non-transient attachments that should be transient and vice versa |
| 387 | for (uint32_t i = 0; i < attachmentCount; ++i) { |
| 388 | auto& attachment = rpci->pAttachments[i]; |
| 389 | bool attachment_should_be_transient = |
| 390 | (attachment.loadOp != VK_ATTACHMENT_LOAD_OP_LOAD && attachment.storeOp != VK_ATTACHMENT_STORE_OP_STORE); |
| 391 | |
| 392 | if (FormatHasStencil(attachment.format)) { |
| 393 | attachment_should_be_transient &= (attachment.stencilLoadOp != VK_ATTACHMENT_LOAD_OP_LOAD && |
| 394 | attachment.stencilStoreOp != VK_ATTACHMENT_STORE_OP_STORE); |
| 395 | } |
| 396 | |
| 397 | auto view_state = GetImageViewState(image_views[i]); |
| 398 | if (view_state) { |
| 399 | auto& ivci = view_state->create_info; |
| 400 | auto& ici = GetImageState(ivci.image)->createInfo; |
| 401 | |
| 402 | bool image_is_transient = (ici.usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) != 0; |
| 403 | |
| 404 | // The check for an image that should not be transient applies to all GPUs |
| 405 | if (!attachment_should_be_transient && image_is_transient) { |
| 406 | skip |= LogPerformanceWarning( |
| 407 | device, kVUID_BestPractices_CreateFramebuffer_AttachmentShouldNotBeTransient, |
| 408 | "Attachment %u in VkFramebuffer uses loadOp/storeOps which need to access physical memory, " |
| 409 | "but the image backing the image view has VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT set. " |
| 410 | "Physical memory will need to be backed lazily to this image, potentially causing stalls.", |
| 411 | i); |
| 412 | } |
| 413 | |
| 414 | bool supports_lazy = false; |
| 415 | for (uint32_t j = 0; j < phys_dev_mem_props.memoryTypeCount; j++) { |
| 416 | if (phys_dev_mem_props.memoryTypes[j].propertyFlags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) { |
| 417 | supports_lazy = true; |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | // The check for an image that should be transient only applies to GPUs supporting |
| 422 | // lazily allocated memory |
| 423 | if (supports_lazy && attachment_should_be_transient && !image_is_transient) { |
| 424 | skip |= LogPerformanceWarning( |
| 425 | device, kVUID_BestPractices_CreateFramebuffer_AttachmentShouldBeTransient, |
| 426 | "Attachment %u in VkFramebuffer uses loadOp/storeOps which never have to be backed by physical memory, " |
| 427 | "but the image backing the image view does not have VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT set. " |
| 428 | "You can save physical memory by using transient attachment backed by lazily allocated memory here.", |
| 429 | i); |
| 430 | } |
| 431 | } |
| 432 | } |
| 433 | return skip; |
| 434 | } |
| 435 | |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 436 | bool BestPractices::PreCallValidateCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, |
| 437 | const VkAllocationCallbacks* pAllocator, VkFramebuffer* pFramebuffer) const { |
| 438 | bool skip = false; |
| 439 | |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 440 | auto rp_state = GetRenderPassState(pCreateInfo->renderPass); |
Tony-LunarG | 767180f | 2020-04-23 14:03:59 -0600 | [diff] [blame] | 441 | if (rp_state && !(pCreateInfo->flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR)) { |
| 442 | skip = ValidateAttachments(rp_state->createInfo.ptr(), pCreateInfo->attachmentCount, pCreateInfo->pAttachments); |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | return skip; |
| 446 | } |
| 447 | |
Sam Walls | e746d52 | 2020-03-16 21:20:23 +0000 | [diff] [blame] | 448 | bool BestPractices::PreCallValidateAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo* pAllocateInfo, |
| 449 | VkDescriptorSet* pDescriptorSets, void* ads_state_data) const { |
| 450 | bool skip = false; |
| 451 | skip |= ValidationStateTracker::PreCallValidateAllocateDescriptorSets(device, pAllocateInfo, pDescriptorSets, ads_state_data); |
| 452 | |
| 453 | if (!skip) { |
| 454 | const auto& pool_handle = pAllocateInfo->descriptorPool; |
| 455 | auto iter = descriptor_pool_freed_count.find(pool_handle); |
| 456 | // if the number of freed sets > 0, it implies they could be recycled instead if desirable |
| 457 | // this warning is specific to Arm |
| 458 | if (VendorCheckEnabled(kBPVendorArm) && iter != descriptor_pool_freed_count.end() && iter->second > 0) { |
| 459 | skip |= LogPerformanceWarning( |
| 460 | device, kVUID_BestPractices_AllocateDescriptorSets_SuboptimalReuse, |
| 461 | "%s Descriptor set memory was allocated via vkAllocateDescriptorSets() for sets which were previously freed in the " |
| 462 | "same logical device. On some drivers or architectures it may be most optimal to re-use existing descriptor sets.", |
| 463 | VendorSpecificTag(kBPVendorArm)); |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | return skip; |
| 468 | } |
| 469 | |
Mark Lobodzinski | 84101d7 | 2020-04-24 09:43:48 -0600 | [diff] [blame] | 470 | void BestPractices::ManualPostCallRecordAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo* pAllocateInfo, |
| 471 | VkDescriptorSet* pDescriptorSets, VkResult result, void* ads_state) { |
Sam Walls | e746d52 | 2020-03-16 21:20:23 +0000 | [diff] [blame] | 472 | if (result == VK_SUCCESS) { |
| 473 | // find the free count for the pool we allocated into |
| 474 | auto iter = descriptor_pool_freed_count.find(pAllocateInfo->descriptorPool); |
| 475 | if (iter != descriptor_pool_freed_count.end()) { |
| 476 | // we record successful allocations by subtracting the allocation count from the last recorded free count |
| 477 | const auto alloc_count = pAllocateInfo->descriptorSetCount; |
| 478 | // clamp the unsigned subtraction to the range [0, last_free_count] |
| 479 | if (iter->second > alloc_count) |
| 480 | iter->second -= alloc_count; |
| 481 | else |
| 482 | iter->second = 0; |
| 483 | } |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | void BestPractices::PostCallRecordFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t descriptorSetCount, |
| 488 | const VkDescriptorSet* pDescriptorSets, VkResult result) { |
| 489 | ValidationStateTracker::PostCallRecordFreeDescriptorSets(device, descriptorPool, descriptorSetCount, pDescriptorSets, result); |
| 490 | if (result == VK_SUCCESS) { |
| 491 | // we want to track frees because we're interested in suggesting re-use |
| 492 | auto iter = descriptor_pool_freed_count.find(descriptorPool); |
| 493 | if (iter == descriptor_pool_freed_count.end()) { |
| 494 | descriptor_pool_freed_count.insert(std::make_pair(descriptorPool, descriptorSetCount)); |
| 495 | } else { |
| 496 | iter->second += descriptorSetCount; |
| 497 | } |
| 498 | } |
| 499 | } |
| 500 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 501 | bool BestPractices::PreCallValidateAllocateMemory(VkDevice device, const VkMemoryAllocateInfo* pAllocateInfo, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 502 | const VkAllocationCallbacks* pAllocator, VkDeviceMemory* pMemory) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 503 | bool skip = false; |
| 504 | |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 505 | if (num_mem_objects + 1 > kMemoryObjectWarningLimit) { |
Mark Lobodzinski | f95a266 | 2020-01-29 15:43:32 -0700 | [diff] [blame] | 506 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_AllocateMemory_TooManyObjects, |
| 507 | "Performance Warning: This app has > %" PRIu32 " memory objects.", kMemoryObjectWarningLimit); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 508 | } |
| 509 | |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 510 | if (pAllocateInfo->allocationSize < kMinDeviceAllocationSize) { |
| 511 | skip |= LogPerformanceWarning( |
| 512 | device, kVUID_BestPractices_AllocateMemory_SmallAllocation, |
| 513 | "vkAllocateMemory(): Allocating a VkDeviceMemory of size %llu. This is a very small allocation (current " |
| 514 | "threshold is %llu bytes). " |
| 515 | "You should make large allocations and sub-allocate from one large VkDeviceMemory.", |
| 516 | pAllocateInfo->allocationSize, kMinDeviceAllocationSize); |
| 517 | } |
| 518 | |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 519 | // TODO: Insert get check for GetPhysicalDeviceMemoryProperties once the state is tracked in the StateTracker |
| 520 | |
| 521 | return skip; |
| 522 | } |
| 523 | |
Mark Lobodzinski | 84101d7 | 2020-04-24 09:43:48 -0600 | [diff] [blame] | 524 | void BestPractices::ManualPostCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo* pAllocateInfo, |
| 525 | const VkAllocationCallbacks* pAllocator, VkDeviceMemory* pMemory, |
| 526 | VkResult result) { |
Mark Lobodzinski | 205b7a0 | 2020-02-21 13:23:17 -0700 | [diff] [blame] | 527 | if (result != VK_SUCCESS) { |
| 528 | static std::vector<VkResult> error_codes = {VK_ERROR_OUT_OF_HOST_MEMORY, VK_ERROR_OUT_OF_DEVICE_MEMORY, |
| 529 | VK_ERROR_TOO_MANY_OBJECTS, VK_ERROR_INVALID_EXTERNAL_HANDLE, |
| 530 | VK_ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS_KHR}; |
| 531 | static std::vector<VkResult> success_codes = {}; |
| 532 | ValidateReturnCodes("vkReleaseFullScreenExclusiveModeEXT", result, error_codes, success_codes); |
| 533 | return; |
| 534 | } |
| 535 | num_mem_objects++; |
| 536 | } |
Camden Stocker | 9738af9 | 2019-10-16 13:54:03 -0700 | [diff] [blame] | 537 | |
Mark Lobodzinski | de15e58 | 2020-04-29 08:06:00 -0600 | [diff] [blame] | 538 | void BestPractices::ValidateReturnCodes(const char* api_name, VkResult result, const std::vector<VkResult>& error_codes, |
| 539 | const std::vector<VkResult>& success_codes) const { |
Mark Lobodzinski | 205b7a0 | 2020-02-21 13:23:17 -0700 | [diff] [blame] | 540 | auto error = std::find(error_codes.begin(), error_codes.end(), result); |
| 541 | if (error != error_codes.end()) { |
Mark Lobodzinski | 629defa | 2020-04-29 12:00:23 -0600 | [diff] [blame] | 542 | LogWarning(instance, kVUID_BestPractices_Error_Result, "%s(): Returned error %s.", api_name, string_VkResult(result)); |
Mark Lobodzinski | 205b7a0 | 2020-02-21 13:23:17 -0700 | [diff] [blame] | 543 | return; |
| 544 | } |
| 545 | auto success = std::find(success_codes.begin(), success_codes.end(), result); |
| 546 | if (success != success_codes.end()) { |
Mark Lobodzinski | e721515 | 2020-05-11 08:21:23 -0600 | [diff] [blame] | 547 | LogInfo(instance, kVUID_BestPractices_NonSuccess_Result, "%s(): Returned non-success return code %s.", api_name, |
| 548 | string_VkResult(result)); |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 549 | } |
| 550 | } |
| 551 | |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 552 | bool BestPractices::PreCallValidateFreeMemory(VkDevice device, VkDeviceMemory memory, |
| 553 | const VkAllocationCallbacks* pAllocator) const { |
Mark Lobodzinski | 91e50bf | 2020-01-14 09:55:11 -0700 | [diff] [blame] | 554 | if (memory == VK_NULL_HANDLE) return false; |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 555 | bool skip = false; |
| 556 | |
Camden Stocker | 9738af9 | 2019-10-16 13:54:03 -0700 | [diff] [blame] | 557 | const DEVICE_MEMORY_STATE* mem_info = ValidationStateTracker::GetDevMemState(memory); |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 558 | |
| 559 | for (auto& obj : mem_info->obj_bindings) { |
Mark Lobodzinski | 818425a | 2020-03-16 18:19:03 -0600 | [diff] [blame] | 560 | LogObjectList objlist(device); |
| 561 | objlist.add(obj); |
| 562 | objlist.add(mem_info->mem); |
| 563 | skip |= LogWarning(objlist, layer_name.c_str(), "VK Object %s still has a reference to mem obj %s.", |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 564 | 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] | 565 | } |
| 566 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 567 | return skip; |
| 568 | } |
| 569 | |
| 570 | void BestPractices::PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory memory, const VkAllocationCallbacks* pAllocator) { |
Mark Lobodzinski | 97484d6 | 2020-03-03 11:57:41 -0700 | [diff] [blame] | 571 | ValidationStateTracker::PreCallRecordFreeMemory(device, memory, pAllocator); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 572 | if (memory != VK_NULL_HANDLE) { |
| 573 | num_mem_objects--; |
| 574 | } |
| 575 | } |
| 576 | |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 577 | bool BestPractices::ValidateBindBufferMemory(VkBuffer buffer, VkDeviceMemory memory, const char* api_name) const { |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 578 | bool skip = false; |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 579 | const BUFFER_STATE* buffer_state = GetBufferState(buffer); |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 580 | |
sfricke-samsung | e244119 | 2019-11-06 14:07:57 -0800 | [diff] [blame] | 581 | if (!buffer_state->memory_requirements_checked && !buffer_state->external_memory_handle) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 582 | skip |= LogWarning(device, kVUID_BestPractices_BufferMemReqNotCalled, |
| 583 | "%s: Binding memory to %s but vkGetBufferMemoryRequirements() has not been called on that buffer.", |
| 584 | api_name, report_data->FormatHandle(buffer).c_str()); |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 585 | } |
| 586 | |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 587 | const DEVICE_MEMORY_STATE* mem_state = GetDevMemState(memory); |
| 588 | |
| 589 | if (mem_state->alloc_info.allocationSize == buffer_state->createInfo.size && |
| 590 | mem_state->alloc_info.allocationSize < kMinDedicatedAllocationSize) { |
| 591 | skip |= LogPerformanceWarning( |
| 592 | device, kVUID_BestPractices_SmallDedicatedAllocation, |
| 593 | "%s: Trying to bind %s to a memory block which is fully consumed by the buffer. " |
| 594 | "The required size of the allocation is %llu, but smaller buffers like this should be sub-allocated from " |
| 595 | "larger memory blocks. (Current threshold is %llu bytes.)", |
| 596 | api_name, report_data->FormatHandle(buffer).c_str(), mem_state->alloc_info.allocationSize, kMinDedicatedAllocationSize); |
| 597 | } |
| 598 | |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 599 | return skip; |
| 600 | } |
| 601 | |
| 602 | bool BestPractices::PreCallValidateBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory memory, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 603 | VkDeviceSize memoryOffset) const { |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 604 | bool skip = false; |
| 605 | const char* api_name = "BindBufferMemory()"; |
| 606 | |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 607 | skip |= ValidateBindBufferMemory(buffer, memory, api_name); |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 608 | |
| 609 | return skip; |
| 610 | } |
| 611 | |
| 612 | bool BestPractices::PreCallValidateBindBufferMemory2(VkDevice device, uint32_t bindInfoCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 613 | const VkBindBufferMemoryInfo* pBindInfos) const { |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 614 | char api_name[64]; |
| 615 | bool skip = false; |
| 616 | |
| 617 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 618 | sprintf(api_name, "vkBindBufferMemory2() pBindInfos[%u]", i); |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 619 | skip |= ValidateBindBufferMemory(pBindInfos[i].buffer, pBindInfos[i].memory, api_name); |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | return skip; |
| 623 | } |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 624 | |
| 625 | bool BestPractices::PreCallValidateBindBufferMemory2KHR(VkDevice device, uint32_t bindInfoCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 626 | const VkBindBufferMemoryInfo* pBindInfos) const { |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 627 | char api_name[64]; |
| 628 | bool skip = false; |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 629 | |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 630 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 631 | sprintf(api_name, "vkBindBufferMemory2KHR() pBindInfos[%u]", i); |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 632 | skip |= ValidateBindBufferMemory(pBindInfos[i].buffer, pBindInfos[i].memory, api_name); |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | return skip; |
| 636 | } |
| 637 | |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 638 | bool BestPractices::ValidateBindImageMemory(VkImage image, VkDeviceMemory memory, const char* api_name) const { |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 639 | bool skip = false; |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 640 | const IMAGE_STATE* image_state = GetImageState(image); |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 641 | |
sfricke-samsung | 71bc657 | 2020-04-29 15:49:43 -0700 | [diff] [blame] | 642 | if (image_state->disjoint == false) { |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 643 | if (!image_state->memory_requirements_checked && !image_state->external_memory_handle) { |
| 644 | skip |= LogWarning(device, kVUID_BestPractices_ImageMemReqNotCalled, |
| 645 | "%s: Binding memory to %s but vkGetImageMemoryRequirements() has not been called on that image.", |
| 646 | api_name, report_data->FormatHandle(image).c_str()); |
| 647 | } |
| 648 | } else { |
| 649 | // TODO If binding disjoint image then this needs to check that VkImagePlaneMemoryRequirementsInfo was called for each |
| 650 | // plane. |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 651 | } |
| 652 | |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 653 | const DEVICE_MEMORY_STATE* mem_state = GetDevMemState(memory); |
| 654 | |
| 655 | if (mem_state->alloc_info.allocationSize == image_state->requirements.size && |
| 656 | mem_state->alloc_info.allocationSize < kMinDedicatedAllocationSize) { |
| 657 | skip |= LogPerformanceWarning( |
| 658 | device, kVUID_BestPractices_SmallDedicatedAllocation, |
| 659 | "%s: Trying to bind %s to a memory block which is fully consumed by the image. " |
| 660 | "The required size of the allocation is %llu, but smaller images like this should be sub-allocated from " |
| 661 | "larger memory blocks. (Current threshold is %llu bytes.)", |
| 662 | api_name, report_data->FormatHandle(image).c_str(), mem_state->alloc_info.allocationSize, kMinDedicatedAllocationSize); |
| 663 | } |
| 664 | |
| 665 | // If we're binding memory to a image which was created as TRANSIENT and the image supports LAZY allocation, |
| 666 | // make sure this type is actually used. |
| 667 | // This warning will only trigger if this layer is run on a platform that supports LAZILY_ALLOCATED_BIT |
| 668 | // (i.e.most tile - based renderers) |
| 669 | if (image_state->createInfo.usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) { |
| 670 | bool supports_lazy = false; |
| 671 | uint32_t suggested_type = 0; |
| 672 | |
| 673 | for (uint32_t i = 0; i < phys_dev_mem_props.memoryTypeCount; i++) { |
| 674 | if ((1u << i) & image_state->requirements.memoryTypeBits) { |
| 675 | if (phys_dev_mem_props.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) { |
| 676 | supports_lazy = true; |
| 677 | suggested_type = i; |
| 678 | break; |
| 679 | } |
| 680 | } |
| 681 | } |
| 682 | |
| 683 | uint32_t allocated_properties = phys_dev_mem_props.memoryTypes[mem_state->alloc_info.memoryTypeIndex].propertyFlags; |
| 684 | |
| 685 | if (supports_lazy && (allocated_properties & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) == 0) { |
| 686 | skip |= LogPerformanceWarning( |
| 687 | device, kVUID_BestPractices_NonLazyTransientImage, |
| 688 | "%s: Attempting to bind memory type % u to VkImage which was created with TRANSIENT_ATTACHMENT_BIT," |
| 689 | "but this memory type is not LAZILY_ALLOCATED_BIT. You should use memory type %u here instead to save " |
| 690 | "%llu bytes of physical memory.", |
| 691 | api_name, mem_state->alloc_info.memoryTypeIndex, suggested_type, image_state->requirements.size); |
| 692 | } |
| 693 | } |
| 694 | |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 695 | return skip; |
| 696 | } |
| 697 | |
| 698 | bool BestPractices::PreCallValidateBindImageMemory(VkDevice device, VkImage image, VkDeviceMemory memory, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 699 | VkDeviceSize memoryOffset) const { |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 700 | bool skip = false; |
| 701 | const char* api_name = "vkBindImageMemory()"; |
| 702 | |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 703 | skip |= ValidateBindImageMemory(image, memory, api_name); |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 704 | |
| 705 | return skip; |
| 706 | } |
| 707 | |
| 708 | bool BestPractices::PreCallValidateBindImageMemory2(VkDevice device, uint32_t bindInfoCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 709 | const VkBindImageMemoryInfo* pBindInfos) const { |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 710 | char api_name[64]; |
| 711 | bool skip = false; |
| 712 | |
| 713 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 714 | sprintf(api_name, "vkBindImageMemory2() pBindInfos[%u]", i); |
Tony-LunarG | 5e60b85 | 2020-04-27 11:27:54 -0600 | [diff] [blame] | 715 | if (!lvl_find_in_chain<VkBindImageMemorySwapchainInfoKHR>(pBindInfos[i].pNext)) { |
| 716 | skip |= ValidateBindImageMemory(pBindInfos[i].image, pBindInfos[i].memory, api_name); |
| 717 | } |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | return skip; |
| 721 | } |
| 722 | |
| 723 | bool BestPractices::PreCallValidateBindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 724 | const VkBindImageMemoryInfo* pBindInfos) const { |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 725 | char api_name[64]; |
| 726 | bool skip = false; |
| 727 | |
| 728 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 729 | sprintf(api_name, "vkBindImageMemory2KHR() pBindInfos[%u]", i); |
Attilio Provenzano | f31788e | 2020-02-27 12:00:36 +0000 | [diff] [blame] | 730 | skip |= ValidateBindImageMemory(pBindInfos[i].image, pBindInfos[i].memory, api_name); |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | return skip; |
| 734 | } |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 735 | |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 736 | static inline bool FormatHasFullThroughputBlendingArm(VkFormat format) { |
| 737 | switch (format) { |
| 738 | case VK_FORMAT_B10G11R11_UFLOAT_PACK32: |
| 739 | case VK_FORMAT_R16_SFLOAT: |
| 740 | case VK_FORMAT_R16G16_SFLOAT: |
| 741 | case VK_FORMAT_R16G16B16_SFLOAT: |
| 742 | case VK_FORMAT_R16G16B16A16_SFLOAT: |
| 743 | case VK_FORMAT_R32_SFLOAT: |
| 744 | case VK_FORMAT_R32G32_SFLOAT: |
| 745 | case VK_FORMAT_R32G32B32_SFLOAT: |
| 746 | case VK_FORMAT_R32G32B32A32_SFLOAT: |
| 747 | return false; |
| 748 | |
| 749 | default: |
| 750 | return true; |
| 751 | } |
| 752 | } |
| 753 | |
| 754 | bool BestPractices::ValidateMultisampledBlendingArm(uint32_t createInfoCount, |
| 755 | const VkGraphicsPipelineCreateInfo* pCreateInfos) const { |
| 756 | bool skip = false; |
| 757 | |
| 758 | for (uint32_t i = 0; i < createInfoCount; i++) { |
| 759 | auto pCreateInfo = &pCreateInfos[i]; |
| 760 | |
| 761 | if (!pCreateInfo->pColorBlendState || !pCreateInfo->pMultisampleState || |
| 762 | pCreateInfo->pMultisampleState->rasterizationSamples == VK_SAMPLE_COUNT_1_BIT || |
| 763 | pCreateInfo->pMultisampleState->sampleShadingEnable) { |
| 764 | return skip; |
| 765 | } |
| 766 | |
| 767 | auto rp_state = GetRenderPassState(pCreateInfo->renderPass); |
| 768 | auto& subpass = rp_state->createInfo.pSubpasses[pCreateInfo->subpass]; |
| 769 | |
| 770 | for (uint32_t j = 0; j < pCreateInfo->pColorBlendState->attachmentCount; j++) { |
| 771 | auto& blend_att = pCreateInfo->pColorBlendState->pAttachments[j]; |
| 772 | uint32_t att = subpass.pColorAttachments[j].attachment; |
| 773 | |
| 774 | if (att != VK_ATTACHMENT_UNUSED && blend_att.blendEnable && blend_att.colorWriteMask) { |
| 775 | if (!FormatHasFullThroughputBlendingArm(rp_state->createInfo.pAttachments[att].format)) { |
| 776 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_CreatePipelines_MultisampledBlending, |
| 777 | "%s vkCreateGraphicsPipelines() - createInfo #%u: Pipeline is multisampled and " |
| 778 | "color attachment #%u makes use " |
| 779 | "of a format which cannot be blended at full throughput when using MSAA.", |
| 780 | VendorSpecificTag(kBPVendorArm), i, j); |
| 781 | } |
| 782 | } |
| 783 | } |
| 784 | } |
| 785 | |
| 786 | return skip; |
| 787 | } |
| 788 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 789 | bool BestPractices::PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount, |
| 790 | const VkGraphicsPipelineCreateInfo* pCreateInfos, |
Mark Lobodzinski | 2a162a0 | 2019-09-06 11:02:12 -0600 | [diff] [blame] | 791 | const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 792 | void* cgpl_state_data) const { |
Mark Lobodzinski | 8317a3e | 2019-09-20 10:07:08 -0600 | [diff] [blame] | 793 | bool skip = StateTracker::PreCallValidateCreateGraphicsPipelines(device, pipelineCache, createInfoCount, pCreateInfos, |
| 794 | pAllocator, pPipelines, cgpl_state_data); |
Mark Lobodzinski | 8dd14d8 | 2020-04-10 14:16:33 -0600 | [diff] [blame] | 795 | 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] | 796 | |
| 797 | if ((createInfoCount > 1) && (!pipelineCache)) { |
Mark Lobodzinski | f95a266 | 2020-01-29 15:43:32 -0700 | [diff] [blame] | 798 | skip |= LogPerformanceWarning( |
| 799 | device, kVUID_BestPractices_CreatePipelines_MultiplePipelines, |
| 800 | "Performance Warning: This vkCreateGraphicsPipelines call is creating multiple pipelines but is not using a " |
| 801 | "pipeline cache, which may help with performance"); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 802 | } |
| 803 | |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 804 | for (uint32_t i = 0; i < createInfoCount; i++) { |
| 805 | auto& createInfo = pCreateInfos[i]; |
| 806 | |
Mark Lobodzinski | 8dd14d8 | 2020-04-10 14:16:33 -0600 | [diff] [blame] | 807 | if (!(cgpl_state->pipe_state[i]->active_shaders & VK_SHADER_STAGE_MESH_BIT_NV)) { |
| 808 | auto& vertexInput = *createInfo.pVertexInputState; |
| 809 | uint32_t count = 0; |
| 810 | for (uint32_t j = 0; j < vertexInput.vertexBindingDescriptionCount; j++) { |
| 811 | if (vertexInput.pVertexBindingDescriptions[j].inputRate == VK_VERTEX_INPUT_RATE_INSTANCE) { |
| 812 | count++; |
| 813 | } |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 814 | } |
Mark Lobodzinski | 8dd14d8 | 2020-04-10 14:16:33 -0600 | [diff] [blame] | 815 | if (count > kMaxInstancedVertexBuffers) { |
| 816 | skip |= LogPerformanceWarning( |
| 817 | device, kVUID_BestPractices_CreatePipelines_TooManyInstancedVertexBuffers, |
| 818 | "The pipeline is using %u instanced vertex buffers (current limit: %u), but this can be inefficient on the " |
| 819 | "GPU. If using instanced vertex attributes prefer interleaving them in a single buffer.", |
| 820 | count, kMaxInstancedVertexBuffers); |
| 821 | } |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 822 | } |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 823 | |
Szilard Papp | aaf2da3 | 2020-06-22 10:37:35 +0100 | [diff] [blame] | 824 | if ((pCreateInfos[i].pRasterizationState->depthBiasEnable) && |
| 825 | (pCreateInfos[i].pRasterizationState->depthBiasConstantFactor == 0.0f) && |
| 826 | (pCreateInfos[i].pRasterizationState->depthBiasSlopeFactor == 0.0f)) { |
| 827 | skip |= VendorCheckEnabled(kBPVendorArm) && |
| 828 | LogPerformanceWarning( |
| 829 | device, kVUID_BestPractices_CreatePipelines_DepthBias_Zero, |
| 830 | "%s Performance Warning: This vkCreateGraphicsPipelines call is created with depthBiasEnable set to true " |
| 831 | "and both depthBiasConstantFactor and depthBiasSlopeFactor are set to 0. This can cause reduced " |
| 832 | "efficiency during rasterization. Consider disabling depthBias or increasing either " |
| 833 | "depthBiasConstantFactor or depthBiasSlopeFactor.", |
| 834 | VendorSpecificTag(kBPVendorArm)); |
| 835 | } |
| 836 | |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 837 | skip |= VendorCheckEnabled(kBPVendorArm) && ValidateMultisampledBlendingArm(createInfoCount, pCreateInfos); |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 838 | } |
| 839 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 840 | return skip; |
| 841 | } |
| 842 | |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 843 | void BestPractices::ManualPostCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, |
| 844 | const VkGraphicsPipelineCreateInfo* pCreateInfos, |
| 845 | const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines, |
| 846 | VkResult result, void* cgpl_state_data) { |
| 847 | for (size_t i = 0; i < count; i++) { |
| 848 | const auto* cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state*>(cgpl_state_data); |
| 849 | const VkPipeline pipeline_handle = pPipelines[i]; |
| 850 | |
| 851 | // record depth stencil state and color blend states for depth pre-pass tracking purposes |
| 852 | auto gp_cis = graphicsPipelineCIs.find(pipeline_handle); |
| 853 | |
| 854 | // add the tracking state if it doesn't exist |
| 855 | if (gp_cis == graphicsPipelineCIs.end()) { |
| 856 | auto result = graphicsPipelineCIs.emplace(std::make_pair(pipeline_handle, GraphicsPipelineCIs{})); |
| 857 | |
| 858 | if (!result.second) continue; |
| 859 | |
| 860 | gp_cis = result.first; |
| 861 | } |
| 862 | |
Tony-LunarG | 412b1b7 | 2020-07-15 10:30:13 -0600 | [diff] [blame] | 863 | gp_cis->second.colorBlendStateCI = |
| 864 | cgpl_state->pCreateInfos[i].pColorBlendState |
| 865 | ? new safe_VkPipelineColorBlendStateCreateInfo(cgpl_state->pCreateInfos[i].pColorBlendState) |
| 866 | : nullptr; |
| 867 | gp_cis->second.depthStencilStateCI = |
| 868 | cgpl_state->pCreateInfos[i].pDepthStencilState |
| 869 | ? new safe_VkPipelineDepthStencilStateCreateInfo(cgpl_state->pCreateInfos[i].pDepthStencilState) |
| 870 | : nullptr; |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 871 | } |
| 872 | } |
| 873 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 874 | bool BestPractices::PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount, |
| 875 | const VkComputePipelineCreateInfo* pCreateInfos, |
Mark Lobodzinski | 2a162a0 | 2019-09-06 11:02:12 -0600 | [diff] [blame] | 876 | const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 877 | void* ccpl_state_data) const { |
Mark Lobodzinski | 8317a3e | 2019-09-20 10:07:08 -0600 | [diff] [blame] | 878 | bool skip = StateTracker::PreCallValidateCreateComputePipelines(device, pipelineCache, createInfoCount, pCreateInfos, |
| 879 | pAllocator, pPipelines, ccpl_state_data); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 880 | |
| 881 | if ((createInfoCount > 1) && (!pipelineCache)) { |
Mark Lobodzinski | f95a266 | 2020-01-29 15:43:32 -0700 | [diff] [blame] | 882 | skip |= LogPerformanceWarning( |
| 883 | device, kVUID_BestPractices_CreatePipelines_MultiplePipelines, |
| 884 | "Performance Warning: This vkCreateComputePipelines call is creating multiple pipelines but is not using a " |
| 885 | "pipeline cache, which may help with performance"); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 886 | } |
| 887 | |
Sam Walls | d7ab6db | 2020-06-19 20:41:54 +0100 | [diff] [blame] | 888 | if (VendorCheckEnabled(kBPVendorArm)) { |
| 889 | for (size_t i = 0; i < createInfoCount; i++) { |
| 890 | skip |= ValidateCreateComputePipelineArm(pCreateInfos[i]); |
| 891 | } |
| 892 | } |
| 893 | |
| 894 | return skip; |
| 895 | } |
| 896 | |
| 897 | bool BestPractices::ValidateCreateComputePipelineArm(const VkComputePipelineCreateInfo& createInfo) const { |
| 898 | bool skip = false; |
| 899 | auto* module = GetShaderModuleState(createInfo.stage.module); |
| 900 | |
| 901 | uint32_t x = 1, y = 1, z = 1; |
| 902 | FindLocalSize(module, x, y, z); |
| 903 | |
| 904 | uint32_t thread_count = x * y * z; |
| 905 | |
| 906 | // Generate a priori warnings about work group sizes. |
| 907 | if (thread_count > kMaxEfficientWorkGroupThreadCountArm) { |
| 908 | skip |= LogPerformanceWarning( |
| 909 | device, kVUID_BestPractices_CreateComputePipelines_ComputeWorkGroupSize, |
| 910 | "%s vkCreateComputePipelines(): compute shader with work group dimensions (%u, %u, " |
| 911 | "%u) (%u threads total), has more threads than advised in a single work group. It is advised to use work " |
| 912 | "groups with less than %u threads, especially when using barrier() or shared memory.", |
| 913 | VendorSpecificTag(kBPVendorArm), x, y, z, thread_count, kMaxEfficientWorkGroupThreadCountArm); |
| 914 | } |
| 915 | |
| 916 | if (thread_count == 1 || ((x > 1) && (x & (kThreadGroupDispatchCountAlignmentArm - 1))) || |
| 917 | ((y > 1) && (y & (kThreadGroupDispatchCountAlignmentArm - 1))) || |
| 918 | ((z > 1) && (z & (kThreadGroupDispatchCountAlignmentArm - 1)))) { |
| 919 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_CreateComputePipelines_ComputeThreadGroupAlignment, |
| 920 | "%s vkCreateComputePipelines(): compute shader with work group dimensions (%u, " |
| 921 | "%u, %u) is not aligned to %u " |
| 922 | "threads. On Arm Mali architectures, not aligning work group sizes to %u may " |
| 923 | "leave threads idle on the shader " |
| 924 | "core.", |
| 925 | VendorSpecificTag(kBPVendorArm), x, y, z, kThreadGroupDispatchCountAlignmentArm, |
| 926 | kThreadGroupDispatchCountAlignmentArm); |
| 927 | } |
| 928 | |
| 929 | // Generate warnings about work group sizes based on active resources. |
| 930 | auto entrypoint = FindEntrypoint(module, createInfo.stage.pName, createInfo.stage.stage); |
| 931 | if (entrypoint == module->end()) return false; |
| 932 | |
| 933 | bool has_writeable_descriptors = false; |
| 934 | auto accessible_ids = MarkAccessibleIds(module, entrypoint); |
| 935 | auto descriptor_uses = CollectInterfaceByDescriptorSlot(module, accessible_ids, &has_writeable_descriptors); |
| 936 | |
| 937 | unsigned dimensions = 0; |
| 938 | if (x > 1) dimensions++; |
| 939 | if (y > 1) dimensions++; |
| 940 | if (z > 1) dimensions++; |
| 941 | // Here the dimension will really depend on the dispatch grid, but assume it's 1D. |
| 942 | dimensions = std::max(dimensions, 1u); |
| 943 | |
| 944 | // If we're accessing images, we almost certainly want to have a 2D workgroup for cache reasons. |
| 945 | // There are some false positives here. We could simply have a shader that does this within a 1D grid, |
| 946 | // or we may have a linearly tiled image, but these cases are quite unlikely in practice. |
| 947 | bool accesses_2d = false; |
| 948 | for (const auto& usage : descriptor_uses) { |
| 949 | auto dim = GetShaderResourceDimensionality(module, usage.second); |
| 950 | if (dim < 0) continue; |
| 951 | auto spvdim = spv::Dim(dim); |
| 952 | if (spvdim != spv::Dim1D && spvdim != spv::DimBuffer) accesses_2d = true; |
| 953 | } |
| 954 | |
| 955 | if (accesses_2d && dimensions < 2) { |
| 956 | LogPerformanceWarning(device, kVUID_BestPractices_CreateComputePipelines_ComputeSpatialLocality, |
| 957 | "%s vkCreateComputePipelines(): compute shader has work group dimensions (%u, %u, %u), which " |
| 958 | "suggests a 1D dispatch, but the shader is accessing 2D or 3D images. The shader may be " |
| 959 | "exhibiting poor spatial locality with respect to one or more shader resources.", |
| 960 | VendorSpecificTag(kBPVendorArm), x, y, z); |
| 961 | } |
| 962 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 963 | return skip; |
| 964 | } |
| 965 | |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 966 | bool BestPractices::CheckPipelineStageFlags(std::string api_name, const VkPipelineStageFlags flags) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 967 | bool skip = false; |
| 968 | |
| 969 | if (flags & VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 970 | skip |= LogWarning(device, kVUID_BestPractices_PipelineStageFlags, |
| 971 | "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] | 972 | } else if (flags & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 973 | skip |= LogWarning(device, kVUID_BestPractices_PipelineStageFlags, |
| 974 | "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] | 975 | } |
| 976 | |
| 977 | return skip; |
| 978 | } |
| 979 | |
Mark Lobodzinski | 84101d7 | 2020-04-24 09:43:48 -0600 | [diff] [blame] | 980 | void BestPractices::ManualPostCallRecordQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo, VkResult result) { |
Mark Lobodzinski | 9b133c1 | 2020-03-10 10:42:56 -0600 | [diff] [blame] | 981 | for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) { |
| 982 | auto swapchains_result = pPresentInfo->pResults ? pPresentInfo->pResults[i] : result; |
| 983 | if (swapchains_result == VK_SUBOPTIMAL_KHR) { |
| 984 | LogPerformanceWarning( |
| 985 | pPresentInfo->pSwapchains[i], kVUID_BestPractices_SuboptimalSwapchain, |
| 986 | "vkQueuePresentKHR: %s :VK_SUBOPTIMAL_KHR was returned. VK_SUBOPTIMAL_KHR - Presentation will still succeed, " |
| 987 | "subject to the window resize behavior, but the swapchain is no longer configured optimally for the surface it " |
| 988 | "targets. Applications should query updated surface information and recreate their swapchain at the next " |
| 989 | "convenient opportunity.", |
| 990 | report_data->FormatHandle(pPresentInfo->pSwapchains[i]).c_str()); |
| 991 | } |
| 992 | } |
| 993 | } |
| 994 | |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 995 | bool BestPractices::PreCallValidateQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo* pSubmits, |
| 996 | VkFence fence) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 997 | bool skip = false; |
| 998 | |
| 999 | for (uint32_t submit = 0; submit < submitCount; submit++) { |
| 1000 | for (uint32_t semaphore = 0; semaphore < pSubmits[submit].waitSemaphoreCount; semaphore++) { |
| 1001 | skip |= CheckPipelineStageFlags("vkQueueSubmit", pSubmits[submit].pWaitDstStageMask[semaphore]); |
| 1002 | } |
| 1003 | } |
| 1004 | |
| 1005 | return skip; |
| 1006 | } |
| 1007 | |
Attilio Provenzano | 746e43e | 2020-02-27 11:23:50 +0000 | [diff] [blame] | 1008 | bool BestPractices::PreCallValidateCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo, |
| 1009 | const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool) const { |
| 1010 | bool skip = false; |
| 1011 | |
| 1012 | if (pCreateInfo->flags & VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT) { |
| 1013 | skip |= LogPerformanceWarning( |
| 1014 | device, kVUID_BestPractices_CreateCommandPool_CommandBufferReset, |
| 1015 | "vkCreateCommandPool(): VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT is set. Consider resetting entire " |
| 1016 | "pool instead."); |
| 1017 | } |
| 1018 | |
| 1019 | return skip; |
| 1020 | } |
| 1021 | |
| 1022 | bool BestPractices::PreCallValidateBeginCommandBuffer(VkCommandBuffer commandBuffer, |
| 1023 | const VkCommandBufferBeginInfo* pBeginInfo) const { |
| 1024 | bool skip = false; |
| 1025 | |
| 1026 | if (pBeginInfo->flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT) { |
| 1027 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_BeginCommandBuffer_SimultaneousUse, |
| 1028 | "vkBeginCommandBuffer(): VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT is set."); |
| 1029 | } |
| 1030 | |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1031 | if (!(pBeginInfo->flags & VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT)) { |
| 1032 | skip |= VendorCheckEnabled(kBPVendorArm) && |
| 1033 | LogPerformanceWarning(device, kVUID_BestPractices_BeginCommandBuffer_OneTimeSubmit, |
| 1034 | "%s vkBeginCommandBuffer(): VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT is not set. " |
| 1035 | "For best performance on Mali GPUs, consider setting ONE_TIME_SUBMIT by default.", |
| 1036 | VendorSpecificTag(kBPVendorArm)); |
| 1037 | } |
| 1038 | |
Attilio Provenzano | 746e43e | 2020-02-27 11:23:50 +0000 | [diff] [blame] | 1039 | return skip; |
| 1040 | } |
| 1041 | |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1042 | bool BestPractices::PreCallValidateCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1043 | bool skip = false; |
| 1044 | |
| 1045 | skip |= CheckPipelineStageFlags("vkCmdSetEvent", stageMask); |
| 1046 | |
| 1047 | return skip; |
| 1048 | } |
| 1049 | |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1050 | bool BestPractices::PreCallValidateCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, |
| 1051 | VkPipelineStageFlags stageMask) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1052 | bool skip = false; |
| 1053 | |
| 1054 | skip |= CheckPipelineStageFlags("vkCmdResetEvent", stageMask); |
| 1055 | |
| 1056 | return skip; |
| 1057 | } |
| 1058 | |
| 1059 | bool BestPractices::PreCallValidateCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents, |
| 1060 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 1061 | uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers, |
| 1062 | uint32_t bufferMemoryBarrierCount, |
| 1063 | const VkBufferMemoryBarrier* pBufferMemoryBarriers, |
| 1064 | uint32_t imageMemoryBarrierCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1065 | const VkImageMemoryBarrier* pImageMemoryBarriers) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1066 | bool skip = false; |
| 1067 | |
| 1068 | skip |= CheckPipelineStageFlags("vkCmdWaitEvents", srcStageMask); |
| 1069 | skip |= CheckPipelineStageFlags("vkCmdWaitEvents", dstStageMask); |
| 1070 | |
| 1071 | return skip; |
| 1072 | } |
| 1073 | |
| 1074 | bool BestPractices::PreCallValidateCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, |
| 1075 | VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, |
| 1076 | uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers, |
| 1077 | uint32_t bufferMemoryBarrierCount, |
| 1078 | const VkBufferMemoryBarrier* pBufferMemoryBarriers, |
| 1079 | uint32_t imageMemoryBarrierCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1080 | const VkImageMemoryBarrier* pImageMemoryBarriers) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1081 | bool skip = false; |
| 1082 | |
| 1083 | skip |= CheckPipelineStageFlags("vkCmdPipelineBarrier", srcStageMask); |
| 1084 | skip |= CheckPipelineStageFlags("vkCmdPipelineBarrier", dstStageMask); |
| 1085 | |
| 1086 | return skip; |
| 1087 | } |
| 1088 | |
| 1089 | bool BestPractices::PreCallValidateCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1090 | VkQueryPool queryPool, uint32_t query) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1091 | bool skip = false; |
| 1092 | |
| 1093 | skip |= CheckPipelineStageFlags("vkCmdWriteTimestamp", pipelineStage); |
| 1094 | |
| 1095 | return skip; |
| 1096 | } |
| 1097 | |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1098 | void BestPractices::PostCallRecordCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, |
| 1099 | VkPipeline pipeline) { |
| 1100 | StateTracker::PostCallRecordCmdBindPipeline(commandBuffer, pipelineBindPoint, pipeline); |
| 1101 | |
| 1102 | if (pipelineBindPoint == VK_PIPELINE_BIND_POINT_GRAPHICS) { |
| 1103 | // check for depth/blend state tracking |
| 1104 | auto gp_cis = graphicsPipelineCIs.find(pipeline); |
| 1105 | if (gp_cis != graphicsPipelineCIs.end()) { |
| 1106 | auto prepass_state = cbDepthPrePassStates.find(commandBuffer); |
| 1107 | if (prepass_state == cbDepthPrePassStates.end()) { |
| 1108 | auto result = cbDepthPrePassStates.emplace(std::make_pair(commandBuffer, DepthPrePassState{})); |
| 1109 | |
| 1110 | if (!result.second) return; |
| 1111 | |
| 1112 | prepass_state = result.first; |
| 1113 | } |
| 1114 | |
| 1115 | const auto* blend_state = gp_cis->second.colorBlendStateCI; |
| 1116 | const auto* stencil_state = gp_cis->second.depthStencilStateCI; |
| 1117 | |
| 1118 | if (blend_state) { |
| 1119 | // assume the pipeline is depth-only unless any of the attachments have color writes enabled |
| 1120 | prepass_state->second.depthOnly = true; |
| 1121 | for (size_t i = 0; i < blend_state->attachmentCount; i++) { |
| 1122 | if (blend_state->pAttachments[i].colorWriteMask != 0) { |
| 1123 | prepass_state->second.depthOnly = false; |
| 1124 | } |
| 1125 | } |
| 1126 | } |
| 1127 | |
| 1128 | // check for depth value usage |
| 1129 | prepass_state->second.depthEqualComparison = false; |
| 1130 | |
| 1131 | if (stencil_state && stencil_state->depthTestEnable) { |
| 1132 | switch (stencil_state->depthCompareOp) { |
| 1133 | case VK_COMPARE_OP_EQUAL: |
| 1134 | case VK_COMPARE_OP_GREATER_OR_EQUAL: |
| 1135 | case VK_COMPARE_OP_LESS_OR_EQUAL: |
| 1136 | prepass_state->second.depthEqualComparison = true; |
| 1137 | break; |
| 1138 | default: |
| 1139 | break; |
| 1140 | } |
| 1141 | } |
| 1142 | } else { |
| 1143 | // reset depth pre-pass tracking |
| 1144 | cbDepthPrePassStates.emplace(std::make_pair(commandBuffer, DepthPrePassState{})); |
| 1145 | } |
| 1146 | } |
| 1147 | } |
| 1148 | |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1149 | static inline bool RenderPassUsesAttachmentOnTile(const safe_VkRenderPassCreateInfo2& createInfo, uint32_t attachment) { |
| 1150 | for (uint32_t subpass = 0; subpass < createInfo.subpassCount; subpass++) { |
| 1151 | auto& subpassInfo = createInfo.pSubpasses[subpass]; |
| 1152 | |
| 1153 | // If an attachment is ever used as a color attachment, |
| 1154 | // resolve attachment or depth stencil attachment, |
| 1155 | // it needs to exist on tile at some point. |
| 1156 | |
| 1157 | for (uint32_t i = 0; i < subpassInfo.colorAttachmentCount; i++) |
| 1158 | if (subpassInfo.pColorAttachments[i].attachment == attachment) return true; |
| 1159 | |
| 1160 | if (subpassInfo.pResolveAttachments) { |
| 1161 | for (uint32_t i = 0; i < subpassInfo.colorAttachmentCount; i++) |
| 1162 | if (subpassInfo.pResolveAttachments[i].attachment == attachment) return true; |
| 1163 | } |
| 1164 | |
| 1165 | if (subpassInfo.pDepthStencilAttachment && subpassInfo.pDepthStencilAttachment->attachment == attachment) return true; |
| 1166 | } |
| 1167 | |
| 1168 | return false; |
| 1169 | } |
| 1170 | |
| 1171 | bool BestPractices::ValidateCmdBeginRenderPass(VkCommandBuffer commandBuffer, RenderPassCreateVersion rp_version, |
| 1172 | const VkRenderPassBeginInfo* pRenderPassBegin) const { |
| 1173 | bool skip = false; |
| 1174 | |
| 1175 | if (!pRenderPassBegin) { |
| 1176 | return skip; |
| 1177 | } |
| 1178 | |
| 1179 | auto rp_state = GetRenderPassState(pRenderPassBegin->renderPass); |
| 1180 | if (rp_state) { |
Tony-LunarG | 767180f | 2020-04-23 14:03:59 -0600 | [diff] [blame] | 1181 | if (rp_state->createInfo.flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR) { |
| 1182 | const VkRenderPassAttachmentBeginInfo* rpabi = |
| 1183 | lvl_find_in_chain<VkRenderPassAttachmentBeginInfo>(pRenderPassBegin->pNext); |
| 1184 | if (rpabi) { |
| 1185 | skip = ValidateAttachments(rp_state->createInfo.ptr(), rpabi->attachmentCount, rpabi->pAttachments); |
| 1186 | } |
| 1187 | } |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1188 | // Check if any attachments have LOAD operation on them |
| 1189 | for (uint32_t att = 0; att < rp_state->createInfo.attachmentCount; att++) { |
| 1190 | auto& attachment = rp_state->createInfo.pAttachments[att]; |
| 1191 | |
| 1192 | bool attachmentHasReadback = false; |
| 1193 | if (!FormatHasStencil(attachment.format) && attachment.loadOp == VK_ATTACHMENT_LOAD_OP_LOAD) { |
| 1194 | attachmentHasReadback = true; |
| 1195 | } |
| 1196 | |
| 1197 | if (FormatHasStencil(attachment.format) && attachment.stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD) { |
| 1198 | attachmentHasReadback = true; |
| 1199 | } |
| 1200 | |
| 1201 | bool attachmentNeedsReadback = false; |
| 1202 | |
| 1203 | // Check if the attachment is actually used in any subpass on-tile |
| 1204 | if (attachmentHasReadback && RenderPassUsesAttachmentOnTile(rp_state->createInfo, att)) { |
| 1205 | attachmentNeedsReadback = true; |
| 1206 | } |
| 1207 | |
| 1208 | // Using LOAD_OP_LOAD is expensive on tiled GPUs, so flag it as a potential improvement |
| 1209 | if (attachmentNeedsReadback) { |
| 1210 | skip |= VendorCheckEnabled(kBPVendorArm) && |
| 1211 | LogPerformanceWarning( |
| 1212 | device, kVUID_BestPractices_BeginRenderPass_AttachmentNeedsReadback, |
| 1213 | "%s Attachment #%u in render pass has begun with VK_ATTACHMENT_LOAD_OP_LOAD.\n" |
| 1214 | "Submitting this renderpass will cause the driver to inject a readback of the attachment " |
| 1215 | "which will copy in total %u pixels (renderArea = { %d, %d, %u, %u }) to the tile buffer.", |
| 1216 | VendorSpecificTag(kBPVendorArm), att, |
| 1217 | pRenderPassBegin->renderArea.extent.width * pRenderPassBegin->renderArea.extent.height, |
| 1218 | pRenderPassBegin->renderArea.offset.x, pRenderPassBegin->renderArea.offset.y, |
| 1219 | pRenderPassBegin->renderArea.extent.width, pRenderPassBegin->renderArea.extent.height); |
| 1220 | } |
| 1221 | } |
| 1222 | } |
| 1223 | |
| 1224 | return skip; |
| 1225 | } |
| 1226 | |
| 1227 | bool BestPractices::PreCallValidateCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, |
| 1228 | VkSubpassContents contents) const { |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1229 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents); |
| 1230 | skip |= ValidateCmdBeginRenderPass(commandBuffer, RENDER_PASS_VERSION_1, pRenderPassBegin); |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1231 | return skip; |
| 1232 | } |
| 1233 | |
| 1234 | bool BestPractices::PreCallValidateCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 1235 | const VkRenderPassBeginInfo* pRenderPassBegin, |
| 1236 | const VkSubpassBeginInfoKHR* pSubpassBeginInfo) const { |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1237 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass2KHR(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
| 1238 | skip |= ValidateCmdBeginRenderPass(commandBuffer, RENDER_PASS_VERSION_2, pRenderPassBegin); |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1239 | return skip; |
| 1240 | } |
| 1241 | |
| 1242 | bool BestPractices::PreCallValidateCmdBeginRenderPass2(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, |
| 1243 | const VkSubpassBeginInfoKHR* pSubpassBeginInfo) const { |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1244 | bool skip = StateTracker::PreCallValidateCmdBeginRenderPass2(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
| 1245 | skip |= ValidateCmdBeginRenderPass(commandBuffer, RENDER_PASS_VERSION_2, pRenderPassBegin); |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1246 | return skip; |
| 1247 | } |
| 1248 | |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1249 | void BestPractices::RecordCmdBeginRenderPass(VkCommandBuffer commandBuffer, RenderPassCreateVersion rp_version, |
| 1250 | const VkRenderPassBeginInfo* pRenderPassBegin) { |
| 1251 | auto prepass_state = cbDepthPrePassStates.find(commandBuffer); |
| 1252 | |
| 1253 | // add the tracking state if it doesn't exist |
| 1254 | if (prepass_state == cbDepthPrePassStates.end()) { |
| 1255 | auto result = cbDepthPrePassStates.emplace(std::make_pair(commandBuffer, DepthPrePassState{})); |
| 1256 | |
| 1257 | if (!result.second) return; |
| 1258 | |
| 1259 | prepass_state = result.first; |
| 1260 | } |
| 1261 | |
| 1262 | // reset the renderpass state |
| 1263 | prepass_state->second = {}; |
| 1264 | |
| 1265 | const auto* cb_state = GetCBState(commandBuffer); |
locke-lunarg | aecf215 | 2020-05-12 17:15:41 -0600 | [diff] [blame] | 1266 | const auto* rp_state = cb_state->activeRenderPass.get(); |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1267 | |
| 1268 | // track depth / color attachment usage within the renderpass |
| 1269 | for (size_t i = 0; i < rp_state->createInfo.subpassCount; i++) { |
| 1270 | // record if depth/color attachments are in use for this renderpass |
| 1271 | if (rp_state->createInfo.pSubpasses[i].pDepthStencilAttachment != nullptr) prepass_state->second.depthAttachment = true; |
| 1272 | |
| 1273 | if (rp_state->createInfo.pSubpasses[i].colorAttachmentCount > 0) prepass_state->second.colorAttachment = true; |
| 1274 | } |
| 1275 | } |
| 1276 | |
| 1277 | void BestPractices::PostCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, |
| 1278 | VkSubpassContents contents) { |
| 1279 | StateTracker::PostCallRecordCmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents); |
| 1280 | RecordCmdBeginRenderPass(commandBuffer, RENDER_PASS_VERSION_1, pRenderPassBegin); |
| 1281 | } |
| 1282 | |
| 1283 | void BestPractices::PostCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, |
| 1284 | const VkSubpassBeginInfo* pSubpassBeginInfo) { |
| 1285 | StateTracker::PostCallRecordCmdBeginRenderPass2(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
| 1286 | RecordCmdBeginRenderPass(commandBuffer, RENDER_PASS_VERSION_2, pRenderPassBegin); |
| 1287 | } |
| 1288 | |
| 1289 | void BestPractices::PostCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 1290 | const VkRenderPassBeginInfo* pRenderPassBegin, |
| 1291 | const VkSubpassBeginInfo* pSubpassBeginInfo) { |
| 1292 | StateTracker::PostCallRecordCmdBeginRenderPass2KHR(commandBuffer, pRenderPassBegin, pSubpassBeginInfo); |
| 1293 | RecordCmdBeginRenderPass(commandBuffer, RENDER_PASS_VERSION_2, pRenderPassBegin); |
| 1294 | } |
| 1295 | |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 1296 | // Generic function to handle validation for all CmdDraw* type functions |
| 1297 | bool BestPractices::ValidateCmdDrawType(VkCommandBuffer cmd_buffer, const char* caller) const { |
| 1298 | bool skip = false; |
| 1299 | const CMD_BUFFER_STATE* cb_state = GetCBState(cmd_buffer); |
| 1300 | if (cb_state) { |
| 1301 | const auto last_bound_it = cb_state->lastBound.find(VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 1302 | const PIPELINE_STATE* pipeline_state = nullptr; |
| 1303 | if (last_bound_it != cb_state->lastBound.cend()) { |
| 1304 | pipeline_state = last_bound_it->second.pipeline_state; |
| 1305 | } |
| 1306 | const auto& current_vtx_bfr_binding_info = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings; |
| 1307 | // Verify vertex binding |
| 1308 | if (pipeline_state->vertex_binding_descriptions_.size() <= 0) { |
| 1309 | if ((!current_vtx_bfr_binding_info.empty()) && (!cb_state->vertex_buffer_used)) { |
Mark Lobodzinski | f95a266 | 2020-01-29 15:43:32 -0700 | [diff] [blame] | 1310 | skip |= LogPerformanceWarning(cb_state->commandBuffer, kVUID_BestPractices_DrawState_VtxIndexOutOfBounds, |
| 1311 | "Vertex buffers are bound to %s but no vertex buffers are attached to %s.", |
| 1312 | report_data->FormatHandle(cb_state->commandBuffer).c_str(), |
| 1313 | report_data->FormatHandle(pipeline_state->pipeline).c_str()); |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 1314 | } |
| 1315 | } |
| 1316 | } |
| 1317 | return skip; |
| 1318 | } |
| 1319 | |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1320 | void BestPractices::RecordCmdDrawType(VkCommandBuffer cmd_buffer, uint32_t draw_count, const char* caller) { |
| 1321 | if (VendorCheckEnabled(kBPVendorArm)) { |
| 1322 | RecordCmdDrawTypeArm(cmd_buffer, draw_count, caller); |
| 1323 | } |
| 1324 | } |
| 1325 | |
| 1326 | void BestPractices::RecordCmdDrawTypeArm(VkCommandBuffer cmd_buffer, uint32_t draw_count, const char* caller) { |
| 1327 | auto prepass_state = cbDepthPrePassStates.find(cmd_buffer); |
| 1328 | if (prepass_state != cbDepthPrePassStates.end() && draw_count >= kDepthPrePassMinDrawCountArm) { |
| 1329 | if (prepass_state->second.depthOnly) prepass_state->second.numDrawCallsDepthOnly++; |
| 1330 | |
| 1331 | if (prepass_state->second.depthEqualComparison) prepass_state->second.numDrawCallsDepthEqualCompare++; |
| 1332 | } |
| 1333 | } |
| 1334 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1335 | bool BestPractices::PreCallValidateCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1336 | uint32_t firstVertex, uint32_t firstInstance) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1337 | bool skip = false; |
| 1338 | |
| 1339 | if (instanceCount == 0) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1340 | skip |= LogWarning(device, kVUID_BestPractices_CmdDraw_InstanceCountZero, |
| 1341 | "Warning: You are calling vkCmdDraw() with an instanceCount of Zero."); |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 1342 | skip |= ValidateCmdDrawType(commandBuffer, "vkCmdDraw()"); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1343 | } |
| 1344 | |
| 1345 | return skip; |
| 1346 | } |
| 1347 | |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1348 | void BestPractices::PostCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
| 1349 | uint32_t firstVertex, uint32_t firstInstance) { |
| 1350 | StateTracker::PostCallRecordCmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance); |
| 1351 | RecordCmdDrawType(commandBuffer, vertexCount * instanceCount, "vkCmdDraw()"); |
| 1352 | } |
| 1353 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1354 | bool BestPractices::PreCallValidateCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1355 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1356 | bool skip = false; |
| 1357 | |
| 1358 | if (instanceCount == 0) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1359 | skip |= LogWarning(device, kVUID_BestPractices_CmdDraw_InstanceCountZero, |
| 1360 | "Warning: You are calling vkCmdDrawIndexed() with an instanceCount of Zero."); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1361 | } |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 1362 | skip |= ValidateCmdDrawType(commandBuffer, "vkCmdDrawIndexed()"); |
| 1363 | |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1364 | // Check if we reached the limit for small indexed draw calls. |
| 1365 | // Note that we cannot update the draw call count here, so we do it in PreCallRecordCmdDrawIndexed. |
| 1366 | const CMD_BUFFER_STATE* cmd_state = GetCBState(commandBuffer); |
| 1367 | if ((indexCount * instanceCount) <= kSmallIndexedDrawcallIndices && |
| 1368 | (cmd_state->small_indexed_draw_call_count == kMaxSmallIndexedDrawcalls - 1)) { |
| 1369 | skip |= VendorCheckEnabled(kBPVendorArm) && |
| 1370 | LogPerformanceWarning(device, kVUID_BestPractices_CmdDrawIndexed_ManySmallIndexedDrawcalls, |
| 1371 | "The command buffer contains many small indexed drawcalls " |
| 1372 | "(at least %u drawcalls with less than %u indices each). This may cause pipeline bubbles. " |
| 1373 | "You can try batching drawcalls or instancing when applicable.", |
| 1374 | VendorSpecificTag(kBPVendorArm), kMaxSmallIndexedDrawcalls, kSmallIndexedDrawcallIndices); |
| 1375 | } |
| 1376 | |
Sam Walls | 8e77e4f | 2020-03-16 20:47:40 +0000 | [diff] [blame] | 1377 | if (VendorCheckEnabled(kBPVendorArm)) { |
| 1378 | ValidateIndexBufferArm(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); |
| 1379 | } |
| 1380 | |
| 1381 | return skip; |
| 1382 | } |
| 1383 | |
| 1384 | bool BestPractices::ValidateIndexBufferArm(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
| 1385 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) const { |
| 1386 | bool skip = false; |
| 1387 | |
| 1388 | // check for sparse/underutilised index buffer, and post-transform cache thrashing |
| 1389 | const auto* cmd_state = GetCBState(commandBuffer); |
| 1390 | if (cmd_state == nullptr) return skip; |
| 1391 | |
| 1392 | const auto* ib_state = GetBufferState(cmd_state->index_buffer_binding.buffer); |
| 1393 | if (ib_state == nullptr) return skip; |
| 1394 | |
| 1395 | const VkIndexType ib_type = cmd_state->index_buffer_binding.index_type; |
| 1396 | const auto& ib_mem_state = *ib_state->binding.mem_state; |
| 1397 | const VkDeviceSize ib_mem_offset = ib_mem_state.mapped_range.offset; |
| 1398 | const void* ib_mem = ib_mem_state.p_driver_data; |
| 1399 | bool primitive_restart_enable = false; |
| 1400 | |
| 1401 | const auto& pipeline_binding_iter = cmd_state->lastBound.find(VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 1402 | |
| 1403 | if (pipeline_binding_iter != cmd_state->lastBound.end()) { |
| 1404 | const auto* pipeline_state = pipeline_binding_iter->second.pipeline_state; |
| 1405 | if (pipeline_state != nullptr && pipeline_state->graphicsPipelineCI.pInputAssemblyState != nullptr) |
| 1406 | primitive_restart_enable = pipeline_state->graphicsPipelineCI.pInputAssemblyState->primitiveRestartEnable == VK_TRUE; |
| 1407 | } |
| 1408 | |
| 1409 | // no point checking index buffer if the memory is nonexistant/unmapped, or if there is no graphics pipeline bound to this CB |
| 1410 | if (ib_mem && pipeline_binding_iter != cmd_state->lastBound.end()) { |
| 1411 | uint32_t scan_stride; |
| 1412 | if (ib_type == VK_INDEX_TYPE_UINT8_EXT) { |
| 1413 | scan_stride = sizeof(uint8_t); |
| 1414 | } else if (ib_type == VK_INDEX_TYPE_UINT16) { |
| 1415 | scan_stride = sizeof(uint16_t); |
| 1416 | } else { |
| 1417 | scan_stride = sizeof(uint32_t); |
| 1418 | } |
| 1419 | |
| 1420 | const uint8_t* scan_begin = static_cast<const uint8_t*>(ib_mem) + ib_mem_offset + firstIndex * scan_stride; |
| 1421 | const uint8_t* scan_end = scan_begin + indexCount * scan_stride; |
| 1422 | |
| 1423 | // Min and max are important to track for some Mali architectures. In older Mali devices without IDVS, all |
| 1424 | // vertices corresponding to indices between the minimum and maximum may be loaded, and possibly shaded, |
| 1425 | // irrespective of whether or not they're part of the draw call. |
| 1426 | |
| 1427 | // start with minimum as 0xFFFFFFFF and adjust to indices in the buffer |
| 1428 | uint32_t min_index = ~0u; |
| 1429 | // start with maximum as 0 and adjust to indices in the buffer |
| 1430 | uint32_t max_index = 0u; |
| 1431 | |
| 1432 | // first scan-through, we're looking to simulate a model LRU post-transform cache, estimating the number of vertices shaded |
| 1433 | // for the given index buffer |
| 1434 | uint32_t vertex_shade_count = 0; |
| 1435 | |
| 1436 | PostTransformLRUCacheModel post_transform_cache; |
| 1437 | |
| 1438 | // The size of the cache being modelled positively correlates with how much behaviour it can capture about |
| 1439 | // arbitrary ground-truth hardware/architecture cache behaviour. I.e. it's a good solution when we don't know the |
| 1440 | // target architecture. |
| 1441 | // However, modelling a post-transform cache with more than 32 elements gives diminishing returns in practice. |
| 1442 | // http://eelpi.gotdns.org/papers/fast_vert_cache_opt.html |
| 1443 | post_transform_cache.resize(32); |
| 1444 | |
| 1445 | for (const uint8_t* scan_ptr = scan_begin; scan_ptr < scan_end; scan_ptr += scan_stride) { |
| 1446 | uint32_t scan_index; |
| 1447 | uint32_t primitive_restart_value; |
| 1448 | if (ib_type == VK_INDEX_TYPE_UINT8_EXT) { |
| 1449 | scan_index = *reinterpret_cast<const uint8_t*>(scan_ptr); |
| 1450 | primitive_restart_value = 0xFF; |
| 1451 | } else if (ib_type == VK_INDEX_TYPE_UINT16) { |
| 1452 | scan_index = *reinterpret_cast<const uint16_t*>(scan_ptr); |
| 1453 | primitive_restart_value = 0xFFFF; |
| 1454 | } else { |
| 1455 | scan_index = *reinterpret_cast<const uint32_t*>(scan_ptr); |
| 1456 | primitive_restart_value = 0xFFFFFFFF; |
| 1457 | } |
| 1458 | |
| 1459 | max_index = std::max(max_index, scan_index); |
| 1460 | min_index = std::min(min_index, scan_index); |
| 1461 | |
| 1462 | if (!primitive_restart_enable || scan_index != primitive_restart_value) { |
| 1463 | bool in_cache = post_transform_cache.query_cache(scan_index); |
| 1464 | // if the shaded vertex corresponding to the index is not in the PT-cache, we need to shade again |
| 1465 | if (!in_cache) vertex_shade_count++; |
| 1466 | } |
| 1467 | } |
| 1468 | |
| 1469 | // 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^] | 1470 | // 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 |
| 1471 | if (max_index < min_index || max_index == min_index) return skip; |
Sam Walls | 8e77e4f | 2020-03-16 20:47:40 +0000 | [diff] [blame] | 1472 | |
| 1473 | if (max_index - min_index >= indexCount) { |
| 1474 | skip |= LogPerformanceWarning( |
| 1475 | device, kVUID_BestPractices_CmdDrawIndexed_SparseIndexBuffer, |
| 1476 | "%s The indices which were specified for the draw call only utilise approximately %.02f%% of " |
| 1477 | "index buffer value range. Arm Mali architectures before G71 do not have IDVS (Index-Driven " |
| 1478 | "Vertex Shading), meaning all vertices corresponding to indices between the minimum and " |
| 1479 | "maximum would be loaded, and possibly shaded, whether or not they are used.", |
| 1480 | VendorSpecificTag(kBPVendorArm), (static_cast<float>(indexCount) / (max_index - min_index)) * 100.0f); |
| 1481 | return skip; |
| 1482 | } |
| 1483 | |
| 1484 | // use a dynamic vector of bitsets as a memory-compact representation of which indices are included in the draw call |
| 1485 | // 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^] | 1486 | const size_t refs_per_bucket = 64; |
| 1487 | std::vector<std::bitset<refs_per_bucket>> vertex_reference_buckets; |
| 1488 | |
| 1489 | const uint32_t n_indices = max_index - min_index + 1; |
| 1490 | const uint32_t n_buckets = (n_indices / static_cast<uint32_t>(refs_per_bucket)) + |
| 1491 | ((n_indices % static_cast<uint32_t>(refs_per_bucket)) != 0 ? 1 : 0); |
| 1492 | |
| 1493 | // there needs to be at least one bitset to store a set of indices smaller than n_buckets |
| 1494 | vertex_reference_buckets.resize(std::max(1u, n_buckets)); |
Sam Walls | 8e77e4f | 2020-03-16 20:47:40 +0000 | [diff] [blame] | 1495 | |
| 1496 | // To avoid using too much memory, we run over the indices again. |
| 1497 | // Knowing the size from the last scan allows us to record index usage with bitsets |
| 1498 | for (const uint8_t* scan_ptr = scan_begin; scan_ptr < scan_end; scan_ptr += scan_stride) { |
| 1499 | uint32_t scan_index; |
| 1500 | if (ib_type == VK_INDEX_TYPE_UINT8_EXT) { |
| 1501 | scan_index = *reinterpret_cast<const uint8_t*>(scan_ptr); |
| 1502 | } else if (ib_type == VK_INDEX_TYPE_UINT16) { |
| 1503 | scan_index = *reinterpret_cast<const uint16_t*>(scan_ptr); |
| 1504 | } else { |
| 1505 | scan_index = *reinterpret_cast<const uint32_t*>(scan_ptr); |
| 1506 | } |
| 1507 | // keep track of the set of all indices used to reference vertices in the draw call |
| 1508 | size_t index_offset = scan_index - min_index; |
Sam Walls | 61b0689 | 2020-07-23 16:20:50 +0100 | [diff] [blame^] | 1509 | size_t bitset_bucket_index = index_offset / refs_per_bucket; |
| 1510 | uint64_t used_indices = 1ull << ((index_offset % refs_per_bucket) & 0xFFFFFFFFu); |
Sam Walls | 8e77e4f | 2020-03-16 20:47:40 +0000 | [diff] [blame] | 1511 | vertex_reference_buckets[bitset_bucket_index] |= used_indices; |
| 1512 | } |
| 1513 | |
| 1514 | uint32_t vertex_reference_count = 0; |
| 1515 | for (const auto& bitset : vertex_reference_buckets) { |
| 1516 | vertex_reference_count += static_cast<uint32_t>(bitset.count()); |
| 1517 | } |
| 1518 | |
| 1519 | // low index buffer utilization implies that: of the vertices available to the draw call, not all are utilized |
| 1520 | float utilization = static_cast<float>(vertex_reference_count) / (max_index - min_index + 1); |
| 1521 | // low hit rate (high miss rate) implies the order of indices in the draw call may be possible to improve |
| 1522 | float cache_hit_rate = static_cast<float>(vertex_reference_count) / vertex_shade_count; |
| 1523 | |
| 1524 | if (utilization < 0.5f) { |
| 1525 | skip |= LogPerformanceWarning(device, kVUID_BestPractices_CmdDrawIndexed_SparseIndexBuffer, |
| 1526 | "%s The indices which were specified for the draw call only utilise approximately " |
| 1527 | "%.02f%% of the bound vertex buffer.", |
| 1528 | VendorSpecificTag(kBPVendorArm), utilization); |
| 1529 | } |
| 1530 | |
| 1531 | if (cache_hit_rate <= 0.5f) { |
| 1532 | skip |= |
| 1533 | LogPerformanceWarning(device, kVUID_BestPractices_CmdDrawIndexed_PostTransformCacheThrashing, |
| 1534 | "%s The indices which were specified for the draw call are estimated to cause thrashing of " |
| 1535 | "the post-transform vertex cache, with a hit-rate of %.02f%%. " |
| 1536 | "I.e. the ordering of the index buffer may not make optimal use of indices associated with " |
| 1537 | "recently shaded vertices.", |
| 1538 | VendorSpecificTag(kBPVendorArm), cache_hit_rate * 100.0f); |
| 1539 | } |
| 1540 | } |
| 1541 | |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 1542 | return skip; |
| 1543 | } |
| 1544 | |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1545 | void BestPractices::PreCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
| 1546 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) { |
| 1547 | ValidationStateTracker::PreCallRecordCmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, |
| 1548 | firstInstance); |
| 1549 | |
| 1550 | CMD_BUFFER_STATE* cmd_state = GetCBState(commandBuffer); |
| 1551 | if ((indexCount * instanceCount) <= kSmallIndexedDrawcallIndices) { |
| 1552 | cmd_state->small_indexed_draw_call_count++; |
| 1553 | } |
| 1554 | } |
| 1555 | |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1556 | void BestPractices::PostCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
| 1557 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) { |
| 1558 | StateTracker::PostCallRecordCmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); |
| 1559 | RecordCmdDrawType(commandBuffer, indexCount * instanceCount, "vkCmdDrawIndexed()"); |
| 1560 | } |
| 1561 | |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 1562 | bool BestPractices::PreCallValidateCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 1563 | VkDeviceSize offset, VkBuffer countBuffer, |
| 1564 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 1565 | uint32_t stride) const { |
| 1566 | bool skip = ValidateCmdDrawType(commandBuffer, "vkCmdDrawIndexedIndirectCountKHR()"); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1567 | |
| 1568 | return skip; |
| 1569 | } |
| 1570 | |
| 1571 | bool BestPractices::PreCallValidateCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1572 | uint32_t drawCount, uint32_t stride) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1573 | bool skip = false; |
| 1574 | |
| 1575 | if (drawCount == 0) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1576 | skip |= LogWarning(device, kVUID_BestPractices_CmdDraw_DrawCountZero, |
| 1577 | "Warning: You are calling vkCmdDrawIndirect() with a drawCount of Zero."); |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 1578 | skip |= ValidateCmdDrawType(commandBuffer, "vkCmdDrawIndirect()"); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1579 | } |
| 1580 | |
| 1581 | return skip; |
| 1582 | } |
| 1583 | |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1584 | void BestPractices::PostCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 1585 | uint32_t count, uint32_t stride) { |
| 1586 | StateTracker::PostCallRecordCmdDrawIndirect(commandBuffer, buffer, offset, count, stride); |
| 1587 | RecordCmdDrawType(commandBuffer, count, "vkCmdDrawIndirect()"); |
| 1588 | } |
| 1589 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1590 | bool BestPractices::PreCallValidateCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1591 | uint32_t drawCount, uint32_t stride) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1592 | bool skip = false; |
| 1593 | |
| 1594 | if (drawCount == 0) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1595 | skip |= LogWarning(device, kVUID_BestPractices_CmdDraw_DrawCountZero, |
| 1596 | "Warning: You are calling vkCmdDrawIndexedIndirect() with a drawCount of Zero."); |
Mark Lobodzinski | 4c4cf94 | 2019-12-20 11:09:51 -0700 | [diff] [blame] | 1597 | skip |= ValidateCmdDrawType(commandBuffer, "vkCmdDrawIndexedIndirect()"); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1598 | } |
| 1599 | |
| 1600 | return skip; |
| 1601 | } |
| 1602 | |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1603 | void BestPractices::PostCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 1604 | uint32_t count, uint32_t stride) { |
| 1605 | StateTracker::PostCallRecordCmdDrawIndexedIndirect(commandBuffer, buffer, offset, count, stride); |
| 1606 | RecordCmdDrawType(commandBuffer, count, "vkCmdDrawIndexedIndirect()"); |
| 1607 | } |
| 1608 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1609 | bool BestPractices::PreCallValidateCmdDispatch(VkCommandBuffer commandBuffer, uint32_t groupCountX, uint32_t groupCountY, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1610 | uint32_t groupCountZ) const { |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1611 | bool skip = false; |
| 1612 | |
| 1613 | if ((groupCountX == 0) || (groupCountY == 0) || (groupCountZ == 0)) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1614 | skip |= LogWarning(device, kVUID_BestPractices_CmdDispatch_GroupCountZero, |
| 1615 | "Warning: You are calling vkCmdDispatch() while one or more groupCounts are zero (groupCountX = %" PRIu32 |
| 1616 | ", groupCountY = %" PRIu32 ", groupCountZ = %" PRIu32 ").", |
| 1617 | groupCountX, groupCountY, groupCountZ); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 1618 | } |
| 1619 | |
| 1620 | return skip; |
| 1621 | } |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 1622 | |
Sam Walls | 0961ec0 | 2020-03-31 16:39:15 +0100 | [diff] [blame] | 1623 | bool BestPractices::PreCallValidateCmdEndRenderPass(VkCommandBuffer commandBuffer) const { |
| 1624 | bool skip = false; |
| 1625 | |
| 1626 | skip |= StateTracker::PreCallValidateCmdEndRenderPass(commandBuffer); |
| 1627 | |
| 1628 | auto prepass_state = cbDepthPrePassStates.find(commandBuffer); |
| 1629 | |
| 1630 | if (prepass_state == cbDepthPrePassStates.end()) return skip; |
| 1631 | |
| 1632 | bool uses_depth = (prepass_state->second.depthAttachment || prepass_state->second.colorAttachment) && |
| 1633 | prepass_state->second.numDrawCallsDepthEqualCompare >= kDepthPrePassNumDrawCallsArm && |
| 1634 | prepass_state->second.numDrawCallsDepthOnly >= kDepthPrePassNumDrawCallsArm; |
| 1635 | if (uses_depth) { |
| 1636 | skip |= LogPerformanceWarning( |
| 1637 | device, kVUID_BestPractices_EndRenderPass_DepthPrePassUsage, |
| 1638 | "%s Depth pre-passes may be in use. In general, this is not recommended, as in Arm Mali GPUs since " |
| 1639 | "Mali-T620, Forward Pixel Killing (FPK) can already perform automatic hidden surface removal; in which " |
| 1640 | "case, using depth pre-passes for hidden surface removal may worsen performance.", |
| 1641 | VendorSpecificTag(kBPVendorArm)); |
| 1642 | } |
| 1643 | |
| 1644 | return skip; |
| 1645 | } |
| 1646 | |
Camden Stocker | 9c05144 | 2019-11-06 14:28:43 -0800 | [diff] [blame] | 1647 | bool BestPractices::ValidateGetPhysicalDeviceDisplayPlanePropertiesKHRQuery(VkPhysicalDevice physicalDevice, |
| 1648 | const char* api_name) const { |
| 1649 | bool skip = false; |
| 1650 | const auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 1651 | |
| 1652 | if (physical_device_state->vkGetPhysicalDeviceDisplayPlanePropertiesKHRState == UNCALLED) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1653 | skip |= LogWarning(physicalDevice, kVUID_BestPractices_DisplayPlane_PropertiesNotCalled, |
| 1654 | "Potential problem with calling %s() without first retrieving properties from " |
| 1655 | "vkGetPhysicalDeviceDisplayPlanePropertiesKHR or vkGetPhysicalDeviceDisplayPlaneProperties2KHR.", |
| 1656 | api_name); |
Camden Stocker | 9c05144 | 2019-11-06 14:28:43 -0800 | [diff] [blame] | 1657 | } |
| 1658 | |
| 1659 | return skip; |
| 1660 | } |
| 1661 | |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 1662 | bool BestPractices::PreCallValidateGetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physicalDevice, uint32_t planeIndex, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1663 | uint32_t* pDisplayCount, VkDisplayKHR* pDisplays) const { |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 1664 | bool skip = false; |
| 1665 | |
Camden Stocker | 9c05144 | 2019-11-06 14:28:43 -0800 | [diff] [blame] | 1666 | skip |= ValidateGetPhysicalDeviceDisplayPlanePropertiesKHRQuery(physicalDevice, "vkGetDisplayPlaneSupportedDisplaysKHR"); |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 1667 | |
Camden Stocker | 9c05144 | 2019-11-06 14:28:43 -0800 | [diff] [blame] | 1668 | return skip; |
| 1669 | } |
| 1670 | |
| 1671 | bool BestPractices::PreCallValidateGetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice physicalDevice, VkDisplayModeKHR mode, |
| 1672 | uint32_t planeIndex, |
| 1673 | VkDisplayPlaneCapabilitiesKHR* pCapabilities) const { |
| 1674 | bool skip = false; |
| 1675 | |
| 1676 | skip |= ValidateGetPhysicalDeviceDisplayPlanePropertiesKHRQuery(physicalDevice, "vkGetDisplayPlaneCapabilitiesKHR"); |
| 1677 | |
| 1678 | return skip; |
| 1679 | } |
| 1680 | |
| 1681 | bool BestPractices::PreCallValidateGetDisplayPlaneCapabilities2KHR(VkPhysicalDevice physicalDevice, |
| 1682 | const VkDisplayPlaneInfo2KHR* pDisplayPlaneInfo, |
| 1683 | VkDisplayPlaneCapabilities2KHR* pCapabilities) const { |
| 1684 | bool skip = false; |
| 1685 | |
| 1686 | skip |= ValidateGetPhysicalDeviceDisplayPlanePropertiesKHRQuery(physicalDevice, "vkGetDisplayPlaneCapabilities2KHR"); |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 1687 | |
| 1688 | return skip; |
| 1689 | } |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 1690 | |
| 1691 | bool BestPractices::PreCallValidateGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t* pSwapchainImageCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1692 | VkImage* pSwapchainImages) const { |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 1693 | bool skip = false; |
| 1694 | |
| 1695 | auto swapchain_state = GetSwapchainState(swapchain); |
| 1696 | |
| 1697 | if (swapchain_state && pSwapchainImages) { |
| 1698 | // Compare the preliminary value of *pSwapchainImageCount with the value this time: |
| 1699 | if (swapchain_state->vkGetSwapchainImagesKHRState == UNCALLED) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1700 | skip |= |
| 1701 | LogWarning(device, kVUID_Core_Swapchain_PriorCount, |
| 1702 | "vkGetSwapchainImagesKHR() called with non-NULL pSwapchainImageCount; but no prior positive value has " |
| 1703 | "been seen for pSwapchainImages."); |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 1704 | } |
| 1705 | } |
| 1706 | |
| 1707 | return skip; |
| 1708 | } |
| 1709 | |
| 1710 | // Common function to handle validation for GetPhysicalDeviceQueueFamilyProperties & 2KHR version |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1711 | bool BestPractices::ValidateCommonGetPhysicalDeviceQueueFamilyProperties(const PHYSICAL_DEVICE_STATE* pd_state, |
| 1712 | uint32_t requested_queue_family_property_count, |
| 1713 | bool qfp_null, const char* caller_name) const { |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 1714 | bool skip = false; |
| 1715 | if (!qfp_null) { |
| 1716 | // Verify that for each physical device, this command is called first with NULL pQueueFamilyProperties in order to get count |
| 1717 | if (UNCALLED == pd_state->vkGetPhysicalDeviceQueueFamilyPropertiesState) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1718 | skip |= LogWarning( |
| 1719 | pd_state->phys_device, kVUID_Core_DevLimit_MissingQueryCount, |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 1720 | "%s is called with non-NULL pQueueFamilyProperties before obtaining pQueueFamilyPropertyCount. It is recommended " |
| 1721 | "to first call %s with NULL pQueueFamilyProperties in order to obtain the maximal pQueueFamilyPropertyCount.", |
| 1722 | caller_name, caller_name); |
| 1723 | // Then verify that pCount that is passed in on second call matches what was returned |
| 1724 | } else if (pd_state->queue_family_known_count != requested_queue_family_property_count) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1725 | skip |= LogWarning( |
| 1726 | pd_state->phys_device, kVUID_Core_DevLimit_CountMismatch, |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 1727 | "%s is called with non-NULL pQueueFamilyProperties and pQueueFamilyPropertyCount value %" PRIu32 |
| 1728 | ", but the largest previously returned pQueueFamilyPropertyCount for this physicalDevice is %" PRIu32 |
| 1729 | ". It is recommended to instead receive all the properties by calling %s with pQueueFamilyPropertyCount that was " |
| 1730 | "previously obtained by calling %s with NULL pQueueFamilyProperties.", |
| 1731 | caller_name, requested_queue_family_property_count, pd_state->queue_family_known_count, caller_name, caller_name); |
| 1732 | } |
| 1733 | } |
| 1734 | |
| 1735 | return skip; |
| 1736 | } |
| 1737 | |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1738 | bool BestPractices::PreCallValidateBindAccelerationStructureMemoryNV( |
| 1739 | VkDevice device, uint32_t bindInfoCount, const VkBindAccelerationStructureMemoryInfoNV* pBindInfos) const { |
Camden Stocker | 8251058 | 2019-09-03 14:00:16 -0600 | [diff] [blame] | 1740 | bool skip = false; |
| 1741 | |
| 1742 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 1743 | const ACCELERATION_STRUCTURE_STATE* as_state = GetAccelerationStructureState(pBindInfos[i].accelerationStructure); |
| 1744 | if (!as_state->memory_requirements_checked) { |
| 1745 | // There's not an explicit requirement in the spec to call vkGetImageMemoryRequirements() prior to calling |
| 1746 | // BindAccelerationStructureMemoryNV but it's implied in that memory being bound must conform with |
| 1747 | // VkAccelerationStructureMemoryRequirementsInfoNV from vkGetAccelerationStructureMemoryRequirementsNV |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1748 | skip |= LogWarning( |
| 1749 | device, kVUID_BestPractices_BindAccelNV_NoMemReqQuery, |
Camden Stocker | 8251058 | 2019-09-03 14:00:16 -0600 | [diff] [blame] | 1750 | "vkBindAccelerationStructureMemoryNV(): " |
| 1751 | "Binding memory to %s but vkGetAccelerationStructureMemoryRequirementsNV() has not been called on that structure.", |
| 1752 | report_data->FormatHandle(pBindInfos[i].accelerationStructure).c_str()); |
| 1753 | } |
| 1754 | } |
| 1755 | |
| 1756 | return skip; |
| 1757 | } |
| 1758 | |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 1759 | bool BestPractices::PreCallValidateGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, |
| 1760 | uint32_t* pQueueFamilyPropertyCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1761 | VkQueueFamilyProperties* pQueueFamilyProperties) const { |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 1762 | const auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 1763 | assert(physical_device_state); |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1764 | return ValidateCommonGetPhysicalDeviceQueueFamilyProperties(physical_device_state, *pQueueFamilyPropertyCount, |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 1765 | (nullptr == pQueueFamilyProperties), |
| 1766 | "vkGetPhysicalDeviceQueueFamilyProperties()"); |
| 1767 | } |
| 1768 | |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1769 | bool BestPractices::PreCallValidateGetPhysicalDeviceQueueFamilyProperties2( |
| 1770 | VkPhysicalDevice physicalDevice, uint32_t* pQueueFamilyPropertyCount, |
| 1771 | VkQueueFamilyProperties2KHR* pQueueFamilyProperties) const { |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 1772 | const auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 1773 | assert(physical_device_state); |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1774 | return ValidateCommonGetPhysicalDeviceQueueFamilyProperties(physical_device_state, *pQueueFamilyPropertyCount, |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 1775 | (nullptr == pQueueFamilyProperties), |
| 1776 | "vkGetPhysicalDeviceQueueFamilyProperties2()"); |
| 1777 | } |
| 1778 | |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1779 | bool BestPractices::PreCallValidateGetPhysicalDeviceQueueFamilyProperties2KHR( |
| 1780 | VkPhysicalDevice physicalDevice, uint32_t* pQueueFamilyPropertyCount, |
| 1781 | VkQueueFamilyProperties2KHR* pQueueFamilyProperties) const { |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 1782 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 1783 | assert(physical_device_state); |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1784 | return ValidateCommonGetPhysicalDeviceQueueFamilyProperties(physical_device_state, *pQueueFamilyPropertyCount, |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 1785 | (nullptr == pQueueFamilyProperties), |
| 1786 | "vkGetPhysicalDeviceQueueFamilyProperties2KHR()"); |
| 1787 | } |
| 1788 | |
| 1789 | bool BestPractices::PreCallValidateGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, |
| 1790 | uint32_t* pSurfaceFormatCount, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1791 | VkSurfaceFormatKHR* pSurfaceFormats) const { |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 1792 | if (!pSurfaceFormats) return false; |
| 1793 | const auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 1794 | const auto& call_state = physical_device_state->vkGetPhysicalDeviceSurfaceFormatsKHRState; |
| 1795 | bool skip = false; |
| 1796 | if (call_state == UNCALLED) { |
| 1797 | // Since we haven't recorded a preliminary value of *pSurfaceFormatCount, that likely means that the application didn't |
| 1798 | // previously call this function with a NULL value of pSurfaceFormats: |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1799 | skip |= LogWarning(physicalDevice, kVUID_Core_DevLimit_MustQueryCount, |
| 1800 | "vkGetPhysicalDeviceSurfaceFormatsKHR() called with non-NULL pSurfaceFormatCount; but no prior " |
| 1801 | "positive value has been seen for pSurfaceFormats."); |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 1802 | } else { |
| 1803 | auto prev_format_count = (uint32_t)physical_device_state->surface_formats.size(); |
Peter Chen | e191bd7 | 2019-09-16 13:04:37 -0400 | [diff] [blame] | 1804 | if (*pSurfaceFormatCount > prev_format_count) { |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1805 | skip |= LogWarning(physicalDevice, kVUID_Core_DevLimit_CountMismatch, |
| 1806 | "vkGetPhysicalDeviceSurfaceFormatsKHR() called with non-NULL pSurfaceFormatCount, and with " |
| 1807 | "pSurfaceFormats set to a value (%u) that is greater than the value (%u) that was returned " |
| 1808 | "when pSurfaceFormatCount was NULL.", |
| 1809 | *pSurfaceFormatCount, prev_format_count); |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 1810 | } |
| 1811 | } |
| 1812 | return skip; |
| 1813 | } |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 1814 | |
| 1815 | bool BestPractices::PreCallValidateQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo* pBindInfo, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 1816 | VkFence fence) const { |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 1817 | bool skip = false; |
| 1818 | |
| 1819 | for (uint32_t bindIdx = 0; bindIdx < bindInfoCount; bindIdx++) { |
| 1820 | const VkBindSparseInfo& bindInfo = pBindInfo[bindIdx]; |
| 1821 | // Store sparse binding image_state and after binding is complete make sure that any requiring metadata have it bound |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 1822 | std::unordered_set<const IMAGE_STATE*> sparse_images; |
| 1823 | // Track images getting metadata bound by this call in a set, it'll be recorded into the image_state |
| 1824 | // in RecordQueueBindSparse. |
| 1825 | std::unordered_set<const IMAGE_STATE*> sparse_images_with_metadata; |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 1826 | // If we're binding sparse image memory make sure reqs were queried and note if metadata is required and bound |
| 1827 | for (uint32_t i = 0; i < bindInfo.imageBindCount; ++i) { |
| 1828 | const auto& image_bind = bindInfo.pImageBinds[i]; |
| 1829 | auto image_state = GetImageState(image_bind.image); |
| 1830 | if (!image_state) |
| 1831 | continue; // Param/Object validation should report image_bind.image handles being invalid, so just skip here. |
| 1832 | sparse_images.insert(image_state); |
| 1833 | if (image_state->createInfo.flags & VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT) { |
| 1834 | if (!image_state->get_sparse_reqs_called || image_state->sparse_requirements.empty()) { |
| 1835 | // For now just warning if sparse image binding occurs without calling to get reqs first |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1836 | skip |= LogWarning(image_state->image, kVUID_Core_MemTrack_InvalidState, |
| 1837 | "vkQueueBindSparse(): Binding sparse memory to %s without first calling " |
| 1838 | "vkGetImageSparseMemoryRequirements[2KHR]() to retrieve requirements.", |
| 1839 | report_data->FormatHandle(image_state->image).c_str()); |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 1840 | } |
| 1841 | } |
| 1842 | if (!image_state->memory_requirements_checked) { |
| 1843 | // For now just warning if sparse image binding occurs without calling to get reqs first |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1844 | skip |= LogWarning(image_state->image, kVUID_Core_MemTrack_InvalidState, |
| 1845 | "vkQueueBindSparse(): Binding sparse memory to %s without first calling " |
| 1846 | "vkGetImageMemoryRequirements() to retrieve requirements.", |
| 1847 | report_data->FormatHandle(image_state->image).c_str()); |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 1848 | } |
| 1849 | } |
| 1850 | for (uint32_t i = 0; i < bindInfo.imageOpaqueBindCount; ++i) { |
| 1851 | const auto& image_opaque_bind = bindInfo.pImageOpaqueBinds[i]; |
| 1852 | auto image_state = GetImageState(bindInfo.pImageOpaqueBinds[i].image); |
| 1853 | if (!image_state) |
| 1854 | continue; // Param/Object validation should report image_bind.image handles being invalid, so just skip here. |
| 1855 | sparse_images.insert(image_state); |
| 1856 | if (image_state->createInfo.flags & VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT) { |
| 1857 | if (!image_state->get_sparse_reqs_called || image_state->sparse_requirements.empty()) { |
| 1858 | // For now just warning if sparse image binding occurs without calling to get reqs first |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1859 | skip |= LogWarning(image_state->image, kVUID_Core_MemTrack_InvalidState, |
| 1860 | "vkQueueBindSparse(): Binding opaque sparse memory to %s without first calling " |
| 1861 | "vkGetImageSparseMemoryRequirements[2KHR]() to retrieve requirements.", |
| 1862 | report_data->FormatHandle(image_state->image).c_str()); |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 1863 | } |
| 1864 | } |
| 1865 | if (!image_state->memory_requirements_checked) { |
| 1866 | // For now just warning if sparse image binding occurs without calling to get reqs first |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1867 | skip |= LogWarning(image_state->image, kVUID_Core_MemTrack_InvalidState, |
| 1868 | "vkQueueBindSparse(): Binding opaque sparse memory to %s without first calling " |
| 1869 | "vkGetImageMemoryRequirements() to retrieve requirements.", |
| 1870 | report_data->FormatHandle(image_state->image).c_str()); |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 1871 | } |
| 1872 | for (uint32_t j = 0; j < image_opaque_bind.bindCount; ++j) { |
| 1873 | 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] | 1874 | sparse_images_with_metadata.insert(image_state); |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 1875 | } |
| 1876 | } |
| 1877 | } |
| 1878 | for (const auto& sparse_image_state : sparse_images) { |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 1879 | if (sparse_image_state->sparse_metadata_required && !sparse_image_state->sparse_metadata_bound && |
| 1880 | 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] | 1881 | // Warn if sparse image binding metadata required for image with sparse binding, but metadata not bound |
Mark Lobodzinski | b6e2a28 | 2020-01-29 16:03:26 -0700 | [diff] [blame] | 1882 | skip |= LogWarning(sparse_image_state->image, kVUID_Core_MemTrack_InvalidState, |
| 1883 | "vkQueueBindSparse(): Binding sparse memory to %s which requires a metadata aspect but no " |
| 1884 | "binding with VK_SPARSE_MEMORY_BIND_METADATA_BIT set was made.", |
| 1885 | report_data->FormatHandle(sparse_image_state->image).c_str()); |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame] | 1886 | } |
| 1887 | } |
| 1888 | } |
| 1889 | |
| 1890 | return skip; |
| 1891 | } |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 1892 | |
Mark Lobodzinski | 84101d7 | 2020-04-24 09:43:48 -0600 | [diff] [blame] | 1893 | void BestPractices::ManualPostCallRecordQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo* pBindInfo, |
| 1894 | VkFence fence, VkResult result) { |
Mark Lobodzinski | 205b7a0 | 2020-02-21 13:23:17 -0700 | [diff] [blame] | 1895 | if (result != VK_SUCCESS) { |
Mark Lobodzinski | 205b7a0 | 2020-02-21 13:23:17 -0700 | [diff] [blame] | 1896 | return; |
| 1897 | } |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 1898 | |
| 1899 | for (uint32_t bindIdx = 0; bindIdx < bindInfoCount; bindIdx++) { |
| 1900 | const VkBindSparseInfo& bindInfo = pBindInfo[bindIdx]; |
| 1901 | for (uint32_t i = 0; i < bindInfo.imageOpaqueBindCount; ++i) { |
| 1902 | const auto& image_opaque_bind = bindInfo.pImageOpaqueBinds[i]; |
| 1903 | auto image_state = GetImageState(bindInfo.pImageOpaqueBinds[i].image); |
| 1904 | if (!image_state) |
| 1905 | continue; // Param/Object validation should report image_bind.image handles being invalid, so just skip here. |
| 1906 | for (uint32_t j = 0; j < image_opaque_bind.bindCount; ++j) { |
| 1907 | if (image_opaque_bind.pBinds[j].flags & VK_SPARSE_MEMORY_BIND_METADATA_BIT) { |
| 1908 | image_state->sparse_metadata_bound = true; |
| 1909 | } |
| 1910 | } |
| 1911 | } |
| 1912 | } |
| 1913 | } |
Camden Stocker | 0e0f89b | 2019-10-16 12:24:31 -0700 | [diff] [blame] | 1914 | |
| 1915 | bool BestPractices::PreCallValidateCmdClearAttachments(VkCommandBuffer commandBuffer, uint32_t attachmentCount, |
Camden Stocker | f55721f | 2019-09-09 11:04:49 -0600 | [diff] [blame] | 1916 | const VkClearAttachment* pAttachments, uint32_t rectCount, |
| 1917 | const VkClearRect* pRects) const { |
Camden Stocker | 0e0f89b | 2019-10-16 12:24:31 -0700 | [diff] [blame] | 1918 | bool skip = false; |
| 1919 | const CMD_BUFFER_STATE* cb_node = GetCBState(commandBuffer); |
| 1920 | if (!cb_node) return skip; |
| 1921 | |
Camden Stocker | f55721f | 2019-09-09 11:04:49 -0600 | [diff] [blame] | 1922 | // Warn if this is issued prior to Draw Cmd and clearing the entire attachment |
Camden Stocker | 0e0f89b | 2019-10-16 12:24:31 -0700 | [diff] [blame] | 1923 | if (!cb_node->hasDrawCmd && (cb_node->activeRenderPassBeginInfo.renderArea.extent.width == pRects[0].rect.extent.width) && |
| 1924 | (cb_node->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) { |
| 1925 | // There are times where app needs to use ClearAttachments (generally when reusing a buffer inside of a render pass) |
| 1926 | // This warning should be made more specific. It'd be best to avoid triggering this test if it's a use that must call |
| 1927 | // CmdClearAttachments. |
Mark Lobodzinski | f95a266 | 2020-01-29 15:43:32 -0700 | [diff] [blame] | 1928 | skip |= LogPerformanceWarning(commandBuffer, kVUID_BestPractices_DrawState_ClearCmdBeforeDraw, |
| 1929 | "vkCmdClearAttachments() issued on %s prior to any Draw Cmds. It is recommended you " |
| 1930 | "use RenderPass LOAD_OP_CLEAR on Attachments prior to any Draw.", |
| 1931 | report_data->FormatHandle(commandBuffer).c_str()); |
Camden Stocker | 0e0f89b | 2019-10-16 12:24:31 -0700 | [diff] [blame] | 1932 | } |
| 1933 | |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 1934 | // Check for uses of ClearAttachments along with LOAD_OP_LOAD, |
| 1935 | // as it can be more efficient to just use LOAD_OP_CLEAR |
locke-lunarg | aecf215 | 2020-05-12 17:15:41 -0600 | [diff] [blame] | 1936 | const RENDER_PASS_STATE* rp = cb_node->activeRenderPass.get(); |
Attilio Provenzano | 1d9a836 | 2020-02-27 12:23:51 +0000 | [diff] [blame] | 1937 | if (rp) { |
| 1938 | const auto& subpass = rp->createInfo.pSubpasses[cb_node->activeSubpass]; |
| 1939 | |
| 1940 | for (uint32_t i = 0; i < attachmentCount; i++) { |
| 1941 | auto& attachment = pAttachments[i]; |
| 1942 | if (attachment.aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) { |
| 1943 | uint32_t color_attachment = attachment.colorAttachment; |
| 1944 | uint32_t fb_attachment = subpass.pColorAttachments[color_attachment].attachment; |
| 1945 | |
| 1946 | if (fb_attachment != VK_ATTACHMENT_UNUSED) { |
| 1947 | if (rp->createInfo.pAttachments[fb_attachment].loadOp == VK_ATTACHMENT_LOAD_OP_LOAD) { |
| 1948 | skip |= LogPerformanceWarning( |
| 1949 | device, kVUID_BestPractices_ClearAttachments_ClearAfterLoad, |
| 1950 | "vkCmdClearAttachments() issued on %s for color attachment #%u in this subpass, " |
| 1951 | "but LOAD_OP_LOAD was used. If you need to clear the framebuffer, always use LOAD_OP_CLEAR as " |
| 1952 | "it is more efficient.", |
| 1953 | report_data->FormatHandle(commandBuffer).c_str(), color_attachment); |
| 1954 | } |
| 1955 | } |
| 1956 | } |
| 1957 | |
| 1958 | if (subpass.pDepthStencilAttachment && attachment.aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) { |
| 1959 | uint32_t fb_attachment = subpass.pDepthStencilAttachment->attachment; |
| 1960 | |
| 1961 | if (fb_attachment != VK_ATTACHMENT_UNUSED) { |
| 1962 | if (rp->createInfo.pAttachments[fb_attachment].loadOp == VK_ATTACHMENT_LOAD_OP_LOAD) { |
| 1963 | skip |= LogPerformanceWarning( |
| 1964 | device, kVUID_BestPractices_ClearAttachments_ClearAfterLoad, |
| 1965 | "vkCmdClearAttachments() issued on %s for the depth attachment in this subpass, " |
| 1966 | "but LOAD_OP_LOAD was used. If you need to clear the framebuffer, always use LOAD_OP_CLEAR as " |
| 1967 | "it is more efficient.", |
| 1968 | report_data->FormatHandle(commandBuffer).c_str()); |
| 1969 | } |
| 1970 | } |
| 1971 | } |
| 1972 | |
| 1973 | if (subpass.pDepthStencilAttachment && attachment.aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) { |
| 1974 | uint32_t fb_attachment = subpass.pDepthStencilAttachment->attachment; |
| 1975 | |
| 1976 | if (fb_attachment != VK_ATTACHMENT_UNUSED) { |
| 1977 | if (rp->createInfo.pAttachments[fb_attachment].stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD) { |
| 1978 | skip |= LogPerformanceWarning( |
| 1979 | device, kVUID_BestPractices_ClearAttachments_ClearAfterLoad, |
| 1980 | "vkCmdClearAttachments() issued on %s for the stencil attachment in this subpass, " |
| 1981 | "but LOAD_OP_LOAD was used. If you need to clear the framebuffer, always use LOAD_OP_CLEAR as " |
| 1982 | "it is more efficient.", |
| 1983 | report_data->FormatHandle(commandBuffer).c_str()); |
| 1984 | } |
| 1985 | } |
| 1986 | } |
| 1987 | } |
| 1988 | } |
| 1989 | |
Camden Stocker | f55721f | 2019-09-09 11:04:49 -0600 | [diff] [blame] | 1990 | return skip; |
Camden Stocker | 0e0f89b | 2019-10-16 12:24:31 -0700 | [diff] [blame] | 1991 | } |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1992 | |
| 1993 | bool BestPractices::PreCallValidateCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 1994 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 1995 | const VkImageResolve* pRegions) const { |
| 1996 | bool skip = false; |
| 1997 | |
| 1998 | skip |= VendorCheckEnabled(kBPVendorArm) && |
| 1999 | LogPerformanceWarning(device, kVUID_BestPractices_CmdResolveImage_ResolvingImage, |
| 2000 | "%s Attempting to use vkCmdResolveImage to resolve a multisampled image. " |
| 2001 | "This is a very slow and extremely bandwidth intensive path. " |
| 2002 | "You should always resolve multisampled images on-tile with pResolveAttachments in VkRenderPass.", |
| 2003 | VendorSpecificTag(kBPVendorArm)); |
| 2004 | |
| 2005 | return skip; |
| 2006 | } |
| 2007 | |
| 2008 | bool BestPractices::PreCallValidateCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, |
| 2009 | const VkAllocationCallbacks* pAllocator, VkSampler* pSampler) const { |
| 2010 | bool skip = false; |
| 2011 | |
| 2012 | if (VendorCheckEnabled(kBPVendorArm)) { |
| 2013 | if ((pCreateInfo->addressModeU != pCreateInfo->addressModeV) || (pCreateInfo->addressModeV != pCreateInfo->addressModeW)) { |
| 2014 | skip |= LogPerformanceWarning( |
| 2015 | device, kVUID_BestPractices_CreateSampler_DifferentWrappingModes, |
| 2016 | "%s Creating a sampler object with wrapping modes which do not match (U = %u, V = %u, W = %u). " |
| 2017 | "This may cause reduced performance even if only U (1D image) or U/V wrapping modes (2D " |
| 2018 | "image) are actually used. If you need different wrapping modes, disregard this warning.", |
| 2019 | VendorSpecificTag(kBPVendorArm)); |
| 2020 | } |
| 2021 | |
| 2022 | if ((pCreateInfo->minLod != 0.0f) || (pCreateInfo->maxLod < VK_LOD_CLAMP_NONE)) { |
| 2023 | skip |= LogPerformanceWarning( |
| 2024 | device, kVUID_BestPractices_CreateSampler_LodClamping, |
| 2025 | "%s Creating a sampler object with LOD clamping (minLod = %f, maxLod = %f). This may cause reduced performance. " |
| 2026 | "Instead of clamping LOD in the sampler, consider using an VkImageView which restricts the mip-levels, set minLod " |
| 2027 | "to 0.0, and maxLod to VK_LOD_CLAMP_NONE.", |
| 2028 | VendorSpecificTag(kBPVendorArm), pCreateInfo->minLod, pCreateInfo->maxLod); |
| 2029 | } |
| 2030 | |
| 2031 | if (pCreateInfo->mipLodBias != 0.0f) { |
| 2032 | skip |= |
| 2033 | LogPerformanceWarning(device, kVUID_BestPractices_CreateSampler_LodBias, |
| 2034 | "%s Creating a sampler object with LOD bias != 0.0 (%f). This will lead to less efficient " |
| 2035 | "descriptors being created and may cause reduced performance.", |
| 2036 | VendorSpecificTag(kBPVendorArm), pCreateInfo->mipLodBias); |
| 2037 | } |
| 2038 | |
| 2039 | if ((pCreateInfo->addressModeU == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER || |
| 2040 | pCreateInfo->addressModeV == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER || |
| 2041 | pCreateInfo->addressModeW == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER) && |
| 2042 | (pCreateInfo->borderColor != VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK)) { |
| 2043 | skip |= LogPerformanceWarning( |
| 2044 | device, kVUID_BestPractices_CreateSampler_BorderClampColor, |
| 2045 | "%s Creating a sampler object with border clamping and borderColor != VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK. " |
| 2046 | "This will lead to less efficient descriptors being created and may cause reduced performance. " |
| 2047 | "If possible, use VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK as the border color.", |
| 2048 | VendorSpecificTag(kBPVendorArm)); |
| 2049 | } |
| 2050 | |
| 2051 | if (pCreateInfo->unnormalizedCoordinates) { |
| 2052 | skip |= LogPerformanceWarning( |
| 2053 | device, kVUID_BestPractices_CreateSampler_UnnormalizedCoordinates, |
| 2054 | "%s Creating a sampler object with unnormalized coordinates. This will lead to less efficient " |
| 2055 | "descriptors being created and may cause reduced performance.", |
| 2056 | VendorSpecificTag(kBPVendorArm)); |
| 2057 | } |
| 2058 | |
| 2059 | if (pCreateInfo->anisotropyEnable) { |
| 2060 | skip |= LogPerformanceWarning( |
| 2061 | device, kVUID_BestPractices_CreateSampler_Anisotropy, |
| 2062 | "%s Creating a sampler object with anisotropy. This will lead to less efficient descriptors being created " |
| 2063 | "and may cause reduced performance.", |
| 2064 | VendorSpecificTag(kBPVendorArm)); |
| 2065 | } |
| 2066 | } |
| 2067 | |
| 2068 | return skip; |
| 2069 | } |
Sam Walls | 8e77e4f | 2020-03-16 20:47:40 +0000 | [diff] [blame] | 2070 | |
| 2071 | void BestPractices::PostTransformLRUCacheModel::resize(size_t size) { _entries.resize(size); } |
| 2072 | |
| 2073 | bool BestPractices::PostTransformLRUCacheModel::query_cache(uint32_t value) { |
| 2074 | // look for a cache hit |
| 2075 | auto hit = std::find_if(_entries.begin(), _entries.end(), [value](const CacheEntry& entry) { return entry.value == value; }); |
| 2076 | if (hit != _entries.end()) { |
| 2077 | // mark the cache hit as being most recently used |
| 2078 | hit->age = iteration++; |
| 2079 | return true; |
| 2080 | } |
| 2081 | |
| 2082 | // if there's no cache hit, we need to model the entry being inserted into the cache |
| 2083 | CacheEntry new_entry = {value, iteration}; |
| 2084 | if (iteration < static_cast<uint32_t>(std::distance(_entries.begin(), _entries.end()))) { |
| 2085 | // if there is still space left in the cache, use the next available slot |
| 2086 | *(_entries.begin() + iteration) = new_entry; |
| 2087 | } else { |
| 2088 | // otherwise replace the least recently used cache entry |
| 2089 | auto lru = std::min_element(_entries.begin(), hit, [](const CacheEntry& a, const CacheEntry& b) { return a.age < b.age; }); |
| 2090 | *lru = new_entry; |
| 2091 | } |
| 2092 | iteration++; |
| 2093 | return false; |
| 2094 | } |