Camden | eaa86ea | 2019-07-26 11:00:09 -0600 | [diff] [blame] | 1 | /* Copyright (c) 2015-2019 The Khronos Group Inc. |
| 2 | * Copyright (c) 2015-2019 Valve Corporation |
| 3 | * Copyright (c) 2015-2019 LunarG, Inc. |
| 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 | |
Camden | 3231dcc | 2019-08-05 11:28:57 -0600 | [diff] [blame] | 20 | #include "best_practices.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" |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 23 | |
| 24 | #include <string> |
| 25 | #include <iomanip> |
| 26 | |
| 27 | // get the API name is proper format |
| 28 | std::string BestPractices::GetAPIVersionName(uint32_t version) { |
| 29 | std::stringstream version_name; |
| 30 | uint32_t major = VK_VERSION_MAJOR(version); |
| 31 | uint32_t minor = VK_VERSION_MINOR(version); |
| 32 | uint32_t patch = VK_VERSION_PATCH(version); |
| 33 | |
| 34 | version_name << major << "." << minor << "." << patch << " (0x" << std::setfill('0') << std::setw(8) << std::hex << version |
| 35 | << ")"; |
| 36 | |
| 37 | return version_name.str(); |
| 38 | } |
| 39 | |
| 40 | bool BestPractices::PreCallValidateCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, |
| 41 | VkInstance* pInstance) { |
| 42 | bool skip = false; |
| 43 | |
| 44 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
| 45 | if (white_list(pCreateInfo->ppEnabledExtensionNames[i], kDeviceExtensionNames)) { |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 46 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 47 | kVUID_BestPractices_CreateInstance_ExtensionMismatch, |
| 48 | "vkCreateInstance(): Attempting to enable Device Extension %s at CreateInstance time.", |
| 49 | pCreateInfo->ppEnabledExtensionNames[i]); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 50 | } |
| 51 | } |
| 52 | |
| 53 | return skip; |
| 54 | } |
| 55 | |
| 56 | void BestPractices::PreCallRecordCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, |
| 57 | VkInstance* pInstance) { |
| 58 | instance_api_version = pCreateInfo->pApplicationInfo->apiVersion; |
| 59 | } |
| 60 | |
| 61 | bool BestPractices::PreCallValidateCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* pCreateInfo, |
| 62 | const VkAllocationCallbacks* pAllocator, VkDevice* pDevice) { |
| 63 | bool skip = false; |
| 64 | |
| 65 | // get API version of physical device passed when creating device. |
| 66 | VkPhysicalDeviceProperties physical_device_properties{}; |
| 67 | DispatchGetPhysicalDeviceProperties(physicalDevice, &physical_device_properties); |
| 68 | device_api_version = physical_device_properties.apiVersion; |
| 69 | |
| 70 | // check api versions and warn if instance api Version is higher than version on device. |
| 71 | if (instance_api_version > device_api_version) { |
| 72 | std::string inst_api_name = GetAPIVersionName(instance_api_version); |
| 73 | std::string dev_api_name = GetAPIVersionName(device_api_version); |
| 74 | |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 75 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 76 | kVUID_BestPractices_CreateDevice_API_Mismatch, |
| 77 | "vkCreateDevice(): API Version of current instance, %s is higher than API Version on device, %s", |
| 78 | inst_api_name.c_str(), dev_api_name.c_str()); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
| 82 | if (white_list(pCreateInfo->ppEnabledExtensionNames[i], kInstanceExtensionNames)) { |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 83 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 84 | kVUID_BestPractices_CreateInstance_ExtensionMismatch, |
| 85 | "vkCreateDevice(): Attempting to enable Instance Extension %s at CreateDevice time.", |
| 86 | pCreateInfo->ppEnabledExtensionNames[i]); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 87 | } |
| 88 | } |
| 89 | |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 90 | auto pd_state = GetPhysicalDeviceState(physicalDevice); |
| 91 | if ((pd_state->vkGetPhysicalDeviceSurfaceCapabilitiesKHRState == UNCALLED) && (pCreateInfo->pEnabledFeatures != NULL)) { |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 92 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 93 | kVUID_BestPractices_CreateDevice_PDFeaturesNotCalled, |
| 94 | "vkCreateDevice() called before getting physical device features from vkGetPhysicalDeviceFeatures()."); |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 95 | } |
| 96 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 97 | return skip; |
| 98 | } |
| 99 | |
| 100 | bool BestPractices::PreCallValidateCreateBuffer(VkDevice device, const VkBufferCreateInfo* pCreateInfo, |
| 101 | const VkAllocationCallbacks* pAllocator, VkBuffer* pBuffer) { |
| 102 | bool skip = false; |
| 103 | |
| 104 | if ((pCreateInfo->queueFamilyIndexCount > 1) && (pCreateInfo->sharingMode == VK_SHARING_MODE_EXCLUSIVE)) { |
| 105 | std::stringstream bufferHex; |
| 106 | bufferHex << "0x" << std::hex << HandleToUint64(pBuffer); |
| 107 | |
| 108 | skip |= |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 109 | log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 110 | kVUID_BestPractices_SharingModeExclusive, |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 111 | "Warning: Buffer (%s) specifies a sharing mode of VK_SHARING_MODE_EXCLUSIVE while specifying multiple queues " |
| 112 | "(queueFamilyIndexCount of %" PRIu32 ").", |
| 113 | bufferHex.str().c_str(), pCreateInfo->queueFamilyIndexCount); |
| 114 | } |
| 115 | |
| 116 | return skip; |
| 117 | } |
| 118 | |
| 119 | bool BestPractices::PreCallValidateCreateImage(VkDevice device, const VkImageCreateInfo* pCreateInfo, |
| 120 | const VkAllocationCallbacks* pAllocator, VkImage* pImage) { |
| 121 | bool skip = false; |
| 122 | |
| 123 | if ((pCreateInfo->queueFamilyIndexCount > 1) && (pCreateInfo->sharingMode == VK_SHARING_MODE_EXCLUSIVE)) { |
| 124 | std::stringstream imageHex; |
| 125 | imageHex << "0x" << std::hex << HandleToUint64(pImage); |
| 126 | |
| 127 | skip |= |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 128 | log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 129 | kVUID_BestPractices_SharingModeExclusive, |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 130 | "Warning: Image (%s) specifies a sharing mode of VK_SHARING_MODE_EXCLUSIVE while specifying multiple queues " |
| 131 | "(queueFamilyIndexCount of %" PRIu32 ").", |
| 132 | imageHex.str().c_str(), pCreateInfo->queueFamilyIndexCount); |
| 133 | } |
| 134 | |
| 135 | return skip; |
| 136 | } |
| 137 | |
| 138 | bool BestPractices::PreCallValidateCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR* pCreateInfo, |
| 139 | const VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pSwapchain) { |
| 140 | bool skip = false; |
| 141 | |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 142 | auto physical_device_state = GetPhysicalDeviceState(); |
| 143 | |
| 144 | if (physical_device_state->vkGetPhysicalDeviceSurfaceCapabilitiesKHRState == UNCALLED) { |
| 145 | skip |= log_msg( |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 146 | report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 147 | kVUID_BestPractices_Swapchain_GetSurfaceNotCalled, |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 148 | "vkCreateSwapchainKHR() called before getting surface capabilities from vkGetPhysicalDeviceSurfaceCapabilitiesKHR()."); |
| 149 | } |
| 150 | |
| 151 | if (physical_device_state->vkGetPhysicalDeviceSurfacePresentModesKHRState != QUERY_DETAILS) { |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 152 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 153 | kVUID_BestPractices_Swapchain_GetSurfaceNotCalled, |
| 154 | "vkCreateSwapchainKHR() called before getting surface present mode(s) from " |
| 155 | "vkGetPhysicalDeviceSurfacePresentModesKHR()."); |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | if (physical_device_state->vkGetPhysicalDeviceSurfaceFormatsKHRState != QUERY_DETAILS) { |
| 159 | skip |= |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 160 | log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 161 | kVUID_BestPractices_Swapchain_GetSurfaceNotCalled, |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 162 | "vkCreateSwapchainKHR() called before getting surface format(s) from vkGetPhysicalDeviceSurfaceFormatsKHR()."); |
| 163 | } |
| 164 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 165 | if ((pCreateInfo->queueFamilyIndexCount > 1) && (pCreateInfo->imageSharingMode == VK_SHARING_MODE_EXCLUSIVE)) { |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 166 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 167 | kVUID_BestPractices_SharingModeExclusive, |
| 168 | "Warning: A Swapchain is being created which specifies a sharing mode of VK_SHARING_MODE_EXCULSIVE while " |
| 169 | "specifying multiple queues (queueFamilyIndexCount of %" PRIu32 ").", |
| 170 | pCreateInfo->queueFamilyIndexCount); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | return skip; |
| 174 | } |
| 175 | |
| 176 | bool BestPractices::PreCallValidateCreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount, |
| 177 | const VkSwapchainCreateInfoKHR* pCreateInfos, |
| 178 | const VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pSwapchains) { |
| 179 | bool skip = false; |
| 180 | |
| 181 | for (uint32_t i = 0; i < swapchainCount; i++) { |
| 182 | if ((pCreateInfos[i].queueFamilyIndexCount > 1) && (pCreateInfos[i].imageSharingMode == VK_SHARING_MODE_EXCLUSIVE)) { |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 183 | skip |= |
| 184 | log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 185 | kVUID_BestPractices_SharingModeExclusive, |
| 186 | "Warning: A shared swapchain (index %" PRIu32 |
| 187 | ") is being created which specifies a sharing mode of VK_SHARING_MODE_EXCLUSIVE while specifying multiple " |
| 188 | "queues (queueFamilyIndexCount of %" PRIu32 ").", |
| 189 | i, pCreateInfos[i].queueFamilyIndexCount); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 190 | } |
| 191 | } |
| 192 | |
| 193 | return skip; |
| 194 | } |
| 195 | |
| 196 | bool BestPractices::PreCallValidateCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, |
| 197 | const VkAllocationCallbacks* pAllocator, VkRenderPass* pRenderPass) { |
| 198 | bool skip = false; |
| 199 | |
| 200 | for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) { |
| 201 | VkFormat format = pCreateInfo->pAttachments[i].format; |
| 202 | if (pCreateInfo->pAttachments[i].initialLayout == VK_IMAGE_LAYOUT_UNDEFINED) { |
| 203 | if ((FormatIsColor(format) || FormatHasDepth(format)) && |
| 204 | pCreateInfo->pAttachments[i].loadOp == VK_ATTACHMENT_LOAD_OP_LOAD) { |
| 205 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 206 | kVUID_BestPractices_RenderPass_Attatchment, |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 207 | "Render pass has an attachment with loadOp == VK_ATTACHMENT_LOAD_OP_LOAD and " |
| 208 | "initialLayout == VK_IMAGE_LAYOUT_UNDEFINED. This is probably not what you " |
| 209 | "intended. Consider using VK_ATTACHMENT_LOAD_OP_DONT_CARE instead if the " |
| 210 | "image truely is undefined at the start of the render pass."); |
| 211 | } |
| 212 | if (FormatHasStencil(format) && pCreateInfo->pAttachments[i].stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD) { |
| 213 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 214 | kVUID_BestPractices_RenderPass_Attatchment, |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 215 | "Render pass has an attachment with stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD " |
| 216 | "and initialLayout == VK_IMAGE_LAYOUT_UNDEFINED. This is probably not what you " |
| 217 | "intended. Consider using VK_ATTACHMENT_LOAD_OP_DONT_CARE instead if the " |
| 218 | "image truely is undefined at the start of the render pass."); |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | for (uint32_t dependency = 0; dependency < pCreateInfo->dependencyCount; dependency++) { |
| 224 | skip |= CheckPipelineStageFlags("vkCreateRenderPass", pCreateInfo->pDependencies[dependency].srcStageMask); |
| 225 | skip |= CheckPipelineStageFlags("vkCreateRenderPass", pCreateInfo->pDependencies[dependency].dstStageMask); |
| 226 | } |
| 227 | |
| 228 | return skip; |
| 229 | } |
| 230 | |
| 231 | bool BestPractices::PreCallValidateAllocateMemory(VkDevice device, const VkMemoryAllocateInfo* pAllocateInfo, |
| 232 | const VkAllocationCallbacks* pAllocator, VkDeviceMemory* pMemory) { |
| 233 | bool skip = false; |
| 234 | |
| 235 | num_mem_objects++; |
| 236 | |
| 237 | if (num_mem_objects > kMemoryObjectWarningLimit) { |
| 238 | skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 239 | kVUID_BestPractices_AllocateMemory_TooManyObjects, |
| 240 | "Performance Warning: This app has > %" PRIu32 " memory objects.", kMemoryObjectWarningLimit); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 241 | } |
| 242 | |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 243 | // TODO: Insert get check for GetPhysicalDeviceMemoryProperties once the state is tracked in the StateTracker |
| 244 | |
| 245 | return skip; |
| 246 | } |
| 247 | |
| 248 | bool BestPractices::PreCallValidateFreeMemory(VkDevice device, VkDeviceMemory memory, const VkAllocationCallbacks* pAllocator) { |
| 249 | bool skip = false; |
| 250 | |
| 251 | DEVICE_MEMORY_STATE* mem_info = GetDevMemState(memory); |
| 252 | |
| 253 | for (auto& obj : mem_info->obj_bindings) { |
| 254 | skip |= log_msg(report_data, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, get_debug_report_enum[obj.type], 0, layer_name.c_str(), |
| 255 | "VK Object %s still has a reference to mem obj %s.", report_data->FormatHandle(obj).c_str(), |
| 256 | report_data->FormatHandle(mem_info->mem).c_str()); |
| 257 | } |
| 258 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 259 | return skip; |
| 260 | } |
| 261 | |
| 262 | void BestPractices::PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory memory, const VkAllocationCallbacks* pAllocator) { |
| 263 | if (memory != VK_NULL_HANDLE) { |
| 264 | num_mem_objects--; |
| 265 | } |
| 266 | } |
| 267 | |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 268 | bool BestPractices::ValidateBindBufferMemory(VkBuffer buffer, const char* api_name) { |
| 269 | bool skip = false; |
| 270 | BUFFER_STATE* buffer_state = GetBufferState(buffer); |
| 271 | |
| 272 | if (!buffer_state->memory_requirements_checked) { |
| 273 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 274 | kVUID_BestPractices_BufferMemReqNotCalled, |
| 275 | "%s: Binding memory to %s but vkGetBufferMemoryRequirements() has not been called on that buffer.", |
| 276 | api_name, report_data->FormatHandle(buffer).c_str()); |
| 277 | } |
| 278 | |
| 279 | return skip; |
| 280 | } |
| 281 | |
| 282 | bool BestPractices::PreCallValidateBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory memory, |
| 283 | VkDeviceSize memoryOffset) { |
| 284 | bool skip = false; |
| 285 | const char* api_name = "BindBufferMemory()"; |
| 286 | |
| 287 | skip |= ValidateBindBufferMemory(buffer, api_name); |
| 288 | |
| 289 | return skip; |
| 290 | } |
| 291 | |
| 292 | bool BestPractices::PreCallValidateBindBufferMemory2(VkDevice device, uint32_t bindInfoCount, |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 293 | const VkBindBufferMemoryInfo* pBindInfos) { |
| 294 | char api_name[64]; |
| 295 | bool skip = false; |
| 296 | |
| 297 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 298 | sprintf(api_name, "vkBindBufferMemory2() pBindInfos[%u]", i); |
| 299 | skip |= ValidateBindBufferMemory(pBindInfos[i].buffer, api_name); |
| 300 | } |
| 301 | |
| 302 | return skip; |
| 303 | } |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 304 | |
| 305 | bool BestPractices::PreCallValidateBindBufferMemory2KHR(VkDevice device, uint32_t bindInfoCount, |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 306 | const VkBindBufferMemoryInfo* pBindInfos) { |
| 307 | char api_name[64]; |
| 308 | bool skip = false; |
Camden Stocker | b603cc8 | 2019-09-03 10:09:02 -0600 | [diff] [blame] | 309 | |
Camden Stocker | 8b798ab | 2019-09-03 10:33:28 -0600 | [diff] [blame] | 310 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 311 | sprintf(api_name, "vkBindBufferMemory2KHR() pBindInfos[%u]", i); |
| 312 | skip |= ValidateBindBufferMemory(pBindInfos[i].buffer, api_name); |
| 313 | } |
| 314 | |
| 315 | return skip; |
| 316 | } |
| 317 | |
| 318 | bool BestPractices::ValidateBindImageMemory(VkImage image, const char* api_name) { |
| 319 | bool skip = false; |
| 320 | IMAGE_STATE* image_state = GetImageState(image); |
| 321 | |
| 322 | if (!image_state->memory_requirements_checked) { |
| 323 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 324 | kVUID_BestPractices_ImageMemReqNotCalled, |
| 325 | "%s: Binding memory to %s but vkGetImageMemoryRequirements() has not been called on that image.", api_name, |
| 326 | report_data->FormatHandle(image).c_str()); |
| 327 | } |
| 328 | |
| 329 | return skip; |
| 330 | } |
| 331 | |
| 332 | bool BestPractices::PreCallValidateBindImageMemory(VkDevice device, VkImage image, VkDeviceMemory memory, |
| 333 | VkDeviceSize memoryOffset) { |
| 334 | bool skip = false; |
| 335 | const char* api_name = "vkBindImageMemory()"; |
| 336 | |
| 337 | skip |= ValidateBindImageMemory(image, api_name); |
| 338 | |
| 339 | return skip; |
| 340 | } |
| 341 | |
| 342 | bool BestPractices::PreCallValidateBindImageMemory2(VkDevice device, uint32_t bindInfoCount, |
| 343 | const VkBindImageMemoryInfo* pBindInfos) { |
| 344 | char api_name[64]; |
| 345 | bool skip = false; |
| 346 | |
| 347 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 348 | sprintf(api_name, "vkBindImageMemory2() pBindInfos[%u]", i); |
| 349 | skip |= ValidateBindImageMemory(pBindInfos[i].image, api_name); |
| 350 | } |
| 351 | |
| 352 | return skip; |
| 353 | } |
| 354 | |
| 355 | bool BestPractices::PreCallValidateBindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount, |
| 356 | const VkBindImageMemoryInfo* pBindInfos) { |
| 357 | char api_name[64]; |
| 358 | bool skip = false; |
| 359 | |
| 360 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 361 | sprintf(api_name, "vkBindImageMemory2KHR() pBindInfos[%u]", i); |
| 362 | skip |= ValidateBindImageMemory(pBindInfos[i].image, api_name); |
| 363 | } |
| 364 | |
| 365 | return skip; |
| 366 | } |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 367 | |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 368 | bool BestPractices::PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount, |
| 369 | const VkGraphicsPipelineCreateInfo* pCreateInfos, |
| 370 | const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines) { |
| 371 | bool skip = false; |
| 372 | |
| 373 | if ((createInfoCount > 1) && (!pipelineCache)) { |
| 374 | skip |= |
| 375 | log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 376 | kVUID_BestPractices_CreatePipelines_MultiplePipelines, |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 377 | "Performance Warning: This vkCreateGraphicsPipelines call is creating multiple pipelines but is not using a " |
| 378 | "pipeline cache, which may help with performance"); |
| 379 | } |
| 380 | |
| 381 | return skip; |
| 382 | } |
| 383 | |
| 384 | bool BestPractices::PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount, |
| 385 | const VkComputePipelineCreateInfo* pCreateInfos, |
| 386 | const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines) { |
| 387 | bool skip = false; |
| 388 | |
| 389 | if ((createInfoCount > 1) && (!pipelineCache)) { |
| 390 | skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 391 | kVUID_BestPractices_CreatePipelines_MultiplePipelines, |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 392 | "Performance Warning: This vkCreateComputePipelines call is creating multiple pipelines but is not using a " |
| 393 | "pipeline cache, which may help with performance"); |
| 394 | } |
| 395 | |
| 396 | return skip; |
| 397 | } |
| 398 | |
| 399 | bool BestPractices::CheckPipelineStageFlags(std::string api_name, const VkPipelineStageFlags flags) { |
| 400 | bool skip = false; |
| 401 | |
| 402 | if (flags & VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT) { |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 403 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 404 | kVUID_BestPractices_PipelineStageFlags, |
| 405 | "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] | 406 | } else if (flags & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT) { |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 407 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 408 | kVUID_BestPractices_PipelineStageFlags, |
| 409 | "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] | 410 | } |
| 411 | |
| 412 | return skip; |
| 413 | } |
| 414 | |
| 415 | bool BestPractices::PreCallValidateQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence) { |
| 416 | bool skip = false; |
| 417 | |
| 418 | for (uint32_t submit = 0; submit < submitCount; submit++) { |
| 419 | for (uint32_t semaphore = 0; semaphore < pSubmits[submit].waitSemaphoreCount; semaphore++) { |
| 420 | skip |= CheckPipelineStageFlags("vkQueueSubmit", pSubmits[submit].pWaitDstStageMask[semaphore]); |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | return skip; |
| 425 | } |
| 426 | |
| 427 | bool BestPractices::PreCallValidateCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) { |
| 428 | bool skip = false; |
| 429 | |
| 430 | skip |= CheckPipelineStageFlags("vkCmdSetEvent", stageMask); |
| 431 | |
| 432 | return skip; |
| 433 | } |
| 434 | |
| 435 | bool BestPractices::PreCallValidateCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) { |
| 436 | bool skip = false; |
| 437 | |
| 438 | skip |= CheckPipelineStageFlags("vkCmdResetEvent", stageMask); |
| 439 | |
| 440 | return skip; |
| 441 | } |
| 442 | |
| 443 | bool BestPractices::PreCallValidateCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents, |
| 444 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 445 | uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers, |
| 446 | uint32_t bufferMemoryBarrierCount, |
| 447 | const VkBufferMemoryBarrier* pBufferMemoryBarriers, |
| 448 | uint32_t imageMemoryBarrierCount, |
| 449 | const VkImageMemoryBarrier* pImageMemoryBarriers) { |
| 450 | bool skip = false; |
| 451 | |
| 452 | skip |= CheckPipelineStageFlags("vkCmdWaitEvents", srcStageMask); |
| 453 | skip |= CheckPipelineStageFlags("vkCmdWaitEvents", dstStageMask); |
| 454 | |
| 455 | return skip; |
| 456 | } |
| 457 | |
| 458 | bool BestPractices::PreCallValidateCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, |
| 459 | VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, |
| 460 | uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers, |
| 461 | uint32_t bufferMemoryBarrierCount, |
| 462 | const VkBufferMemoryBarrier* pBufferMemoryBarriers, |
| 463 | uint32_t imageMemoryBarrierCount, |
| 464 | const VkImageMemoryBarrier* pImageMemoryBarriers) { |
| 465 | bool skip = false; |
| 466 | |
| 467 | skip |= CheckPipelineStageFlags("vkCmdPipelineBarrier", srcStageMask); |
| 468 | skip |= CheckPipelineStageFlags("vkCmdPipelineBarrier", dstStageMask); |
| 469 | |
| 470 | return skip; |
| 471 | } |
| 472 | |
| 473 | bool BestPractices::PreCallValidateCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, |
| 474 | VkQueryPool queryPool, uint32_t query) { |
| 475 | bool skip = false; |
| 476 | |
| 477 | skip |= CheckPipelineStageFlags("vkCmdWriteTimestamp", pipelineStage); |
| 478 | |
| 479 | return skip; |
| 480 | } |
| 481 | |
| 482 | bool BestPractices::PreCallValidateCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
| 483 | uint32_t firstVertex, uint32_t firstInstance) { |
| 484 | bool skip = false; |
| 485 | |
| 486 | if (instanceCount == 0) { |
| 487 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 488 | kVUID_BestPractices_CmdDraw_InstanceCountZero, |
| 489 | "Warning: You are calling vkCmdDraw() with an instanceCount of Zero."); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | return skip; |
| 493 | } |
| 494 | |
| 495 | bool BestPractices::PreCallValidateCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
| 496 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) { |
| 497 | bool skip = false; |
| 498 | |
| 499 | if (instanceCount == 0) { |
| 500 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 501 | kVUID_BestPractices_CmdDraw_InstanceCountZero, |
| 502 | "Warning: You are calling vkCmdDrawIndexed() with an instanceCount of Zero."); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | return skip; |
| 506 | } |
| 507 | |
| 508 | bool BestPractices::PreCallValidateCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 509 | uint32_t drawCount, uint32_t stride) { |
| 510 | bool skip = false; |
| 511 | |
| 512 | if (drawCount == 0) { |
| 513 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 514 | kVUID_BestPractices_CmdDraw_DrawCountZero, |
| 515 | "Warning: You are calling vkCmdDrawIndirect() with a drawCount of Zero."); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | return skip; |
| 519 | } |
| 520 | |
| 521 | bool BestPractices::PreCallValidateCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 522 | uint32_t drawCount, uint32_t stride) { |
| 523 | bool skip = false; |
| 524 | |
| 525 | if (drawCount == 0) { |
| 526 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 527 | kVUID_BestPractices_CmdDraw_DrawCountZero, |
| 528 | "Warning: You are calling vkCmdDrawIndexedIndirect() with a drawCount of Zero."); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | return skip; |
| 532 | } |
| 533 | |
| 534 | bool BestPractices::PreCallValidateCmdDispatch(VkCommandBuffer commandBuffer, uint32_t groupCountX, uint32_t groupCountY, |
| 535 | uint32_t groupCountZ) { |
| 536 | bool skip = false; |
| 537 | |
| 538 | if ((groupCountX == 0) || (groupCountY == 0) || (groupCountZ == 0)) { |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 539 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 540 | kVUID_BestPractices_CmdDispatch_GroupCountZero, |
| 541 | "Warning: You are calling vkCmdDispatch() while one or more groupCounts are zero (groupCountX = %" PRIu32 |
| 542 | ", groupCountY = %" PRIu32 ", groupCountZ = %" PRIu32 ").", |
| 543 | groupCountX, groupCountY, groupCountZ); |
Camden | 5b184be | 2019-08-13 07:50:19 -0600 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | return skip; |
| 547 | } |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 548 | |
| 549 | bool BestPractices::PreCallValidateGetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physicalDevice, uint32_t planeIndex, |
| 550 | uint32_t* pDisplayCount, VkDisplayKHR* pDisplays) { |
| 551 | bool skip = false; |
| 552 | |
| 553 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 554 | |
| 555 | if (physical_device_state->vkGetPhysicalDeviceDisplayPlanePropertiesKHRState != QUERY_DETAILS) { |
Camden Stocker | b6dee34 | 2019-08-22 15:56:15 -0600 | [diff] [blame] | 556 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 557 | kVUID_BestPractices_DisplayPlane_PropertiesNotCalled, |
| 558 | "vkGetDisplayPlaneSupportedDisplaysKHR() called before getting diplay plane properties from " |
| 559 | "vkGetPhysicalDeviceDisplayPlanePropertiesKHR()."); |
Camden | 83a9c37 | 2019-08-14 11:41:38 -0600 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | return skip; |
| 563 | } |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 564 | |
| 565 | bool BestPractices::PreCallValidateGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t* pSwapchainImageCount, |
| 566 | VkImage* pSwapchainImages) { |
| 567 | bool skip = false; |
| 568 | |
| 569 | auto swapchain_state = GetSwapchainState(swapchain); |
| 570 | |
| 571 | if (swapchain_state && pSwapchainImages) { |
| 572 | // Compare the preliminary value of *pSwapchainImageCount with the value this time: |
| 573 | if (swapchain_state->vkGetSwapchainImagesKHRState == UNCALLED) { |
| 574 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, |
| 575 | HandleToUint64(device), kVUID_Core_Swapchain_PriorCount, |
| 576 | "vkGetSwapchainImagesKHR() called with non-NULL pSwapchainImageCount; but no prior positive value has " |
| 577 | "been seen for pSwapchainImages."); |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | return skip; |
| 582 | } |
| 583 | |
| 584 | // Common function to handle validation for GetPhysicalDeviceQueueFamilyProperties & 2KHR version |
| 585 | static bool ValidateCommonGetPhysicalDeviceQueueFamilyProperties(debug_report_data* report_data, |
| 586 | const PHYSICAL_DEVICE_STATE* pd_state, |
| 587 | uint32_t requested_queue_family_property_count, bool qfp_null, |
| 588 | const char* caller_name) { |
| 589 | bool skip = false; |
| 590 | if (!qfp_null) { |
| 591 | // Verify that for each physical device, this command is called first with NULL pQueueFamilyProperties in order to get count |
| 592 | if (UNCALLED == pd_state->vkGetPhysicalDeviceQueueFamilyPropertiesState) { |
| 593 | skip |= log_msg( |
| 594 | report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
| 595 | HandleToUint64(pd_state->phys_device), kVUID_Core_DevLimit_MissingQueryCount, |
| 596 | "%s is called with non-NULL pQueueFamilyProperties before obtaining pQueueFamilyPropertyCount. It is recommended " |
| 597 | "to first call %s with NULL pQueueFamilyProperties in order to obtain the maximal pQueueFamilyPropertyCount.", |
| 598 | caller_name, caller_name); |
| 599 | // Then verify that pCount that is passed in on second call matches what was returned |
| 600 | } else if (pd_state->queue_family_known_count != requested_queue_family_property_count) { |
| 601 | skip |= log_msg( |
| 602 | report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
| 603 | HandleToUint64(pd_state->phys_device), kVUID_Core_DevLimit_CountMismatch, |
| 604 | "%s is called with non-NULL pQueueFamilyProperties and pQueueFamilyPropertyCount value %" PRIu32 |
| 605 | ", but the largest previously returned pQueueFamilyPropertyCount for this physicalDevice is %" PRIu32 |
| 606 | ". It is recommended to instead receive all the properties by calling %s with pQueueFamilyPropertyCount that was " |
| 607 | "previously obtained by calling %s with NULL pQueueFamilyProperties.", |
| 608 | caller_name, requested_queue_family_property_count, pd_state->queue_family_known_count, caller_name, caller_name); |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | return skip; |
| 613 | } |
| 614 | |
Camden Stocker | 8251058 | 2019-09-03 14:00:16 -0600 | [diff] [blame] | 615 | bool BestPractices::PreCallValidateBindAccelerationStructureMemoryNV(VkDevice device, uint32_t bindInfoCount, |
| 616 | const VkBindAccelerationStructureMemoryInfoNV* pBindInfos) { |
| 617 | bool skip = false; |
| 618 | |
| 619 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 620 | const ACCELERATION_STRUCTURE_STATE* as_state = GetAccelerationStructureState(pBindInfos[i].accelerationStructure); |
| 621 | if (!as_state->memory_requirements_checked) { |
| 622 | // There's not an explicit requirement in the spec to call vkGetImageMemoryRequirements() prior to calling |
| 623 | // BindAccelerationStructureMemoryNV but it's implied in that memory being bound must conform with |
| 624 | // VkAccelerationStructureMemoryRequirementsInfoNV from vkGetAccelerationStructureMemoryRequirementsNV |
| 625 | skip |= log_msg( |
| 626 | report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, |
| 627 | kVUID_BestPractices_BindAccelNV_NoMemReqQuery, |
| 628 | "vkBindAccelerationStructureMemoryNV(): " |
| 629 | "Binding memory to %s but vkGetAccelerationStructureMemoryRequirementsNV() has not been called on that structure.", |
| 630 | report_data->FormatHandle(pBindInfos[i].accelerationStructure).c_str()); |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | return skip; |
| 635 | } |
| 636 | |
Camden | 05de2d4 | 2019-08-19 10:23:56 -0600 | [diff] [blame] | 637 | bool BestPractices::PreCallValidateGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, |
| 638 | uint32_t* pQueueFamilyPropertyCount, |
| 639 | VkQueueFamilyProperties* pQueueFamilyProperties) { |
| 640 | const auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 641 | assert(physical_device_state); |
| 642 | return ValidateCommonGetPhysicalDeviceQueueFamilyProperties(report_data, physical_device_state, *pQueueFamilyPropertyCount, |
| 643 | (nullptr == pQueueFamilyProperties), |
| 644 | "vkGetPhysicalDeviceQueueFamilyProperties()"); |
| 645 | } |
| 646 | |
| 647 | bool BestPractices::PreCallValidateGetPhysicalDeviceQueueFamilyProperties2(VkPhysicalDevice physicalDevice, |
| 648 | uint32_t* pQueueFamilyPropertyCount, |
| 649 | VkQueueFamilyProperties2KHR* pQueueFamilyProperties) { |
| 650 | const auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 651 | assert(physical_device_state); |
| 652 | return ValidateCommonGetPhysicalDeviceQueueFamilyProperties(report_data, physical_device_state, *pQueueFamilyPropertyCount, |
| 653 | (nullptr == pQueueFamilyProperties), |
| 654 | "vkGetPhysicalDeviceQueueFamilyProperties2()"); |
| 655 | } |
| 656 | |
| 657 | bool BestPractices::PreCallValidateGetPhysicalDeviceQueueFamilyProperties2KHR(VkPhysicalDevice physicalDevice, |
| 658 | uint32_t* pQueueFamilyPropertyCount, |
| 659 | VkQueueFamilyProperties2KHR* pQueueFamilyProperties) { |
| 660 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 661 | assert(physical_device_state); |
| 662 | return ValidateCommonGetPhysicalDeviceQueueFamilyProperties(report_data, physical_device_state, *pQueueFamilyPropertyCount, |
| 663 | (nullptr == pQueueFamilyProperties), |
| 664 | "vkGetPhysicalDeviceQueueFamilyProperties2KHR()"); |
| 665 | } |
| 666 | |
| 667 | bool BestPractices::PreCallValidateGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, |
| 668 | uint32_t* pSurfaceFormatCount, |
| 669 | VkSurfaceFormatKHR* pSurfaceFormats) { |
| 670 | if (!pSurfaceFormats) return false; |
| 671 | const auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 672 | const auto& call_state = physical_device_state->vkGetPhysicalDeviceSurfaceFormatsKHRState; |
| 673 | bool skip = false; |
| 674 | if (call_state == UNCALLED) { |
| 675 | // Since we haven't recorded a preliminary value of *pSurfaceFormatCount, that likely means that the application didn't |
| 676 | // previously call this function with a NULL value of pSurfaceFormats: |
| 677 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
| 678 | HandleToUint64(physicalDevice), kVUID_Core_DevLimit_MustQueryCount, |
| 679 | "vkGetPhysicalDeviceSurfaceFormatsKHR() called with non-NULL pSurfaceFormatCount; but no prior " |
| 680 | "positive value has been seen for pSurfaceFormats."); |
| 681 | } else { |
| 682 | auto prev_format_count = (uint32_t)physical_device_state->surface_formats.size(); |
| 683 | if (prev_format_count != *pSurfaceFormatCount) { |
| 684 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, |
| 685 | HandleToUint64(physicalDevice), kVUID_Core_DevLimit_CountMismatch, |
| 686 | "vkGetPhysicalDeviceSurfaceFormatsKHR() called with non-NULL pSurfaceFormatCount, and with " |
| 687 | "pSurfaceFormats set to a value (%u) that is greater than the value (%u) that was returned " |
| 688 | "when pSurfaceFormatCount was NULL.", |
| 689 | *pSurfaceFormatCount, prev_format_count); |
| 690 | } |
| 691 | } |
| 692 | return skip; |
| 693 | } |
Camden Stocker | 23cc47d | 2019-09-03 14:53:57 -0600 | [diff] [blame^] | 694 | |
| 695 | bool BestPractices::PreCallValidateQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo* pBindInfo, |
| 696 | VkFence fence) { |
| 697 | bool skip = false; |
| 698 | |
| 699 | for (uint32_t bindIdx = 0; bindIdx < bindInfoCount; bindIdx++) { |
| 700 | const VkBindSparseInfo& bindInfo = pBindInfo[bindIdx]; |
| 701 | // Store sparse binding image_state and after binding is complete make sure that any requiring metadata have it bound |
| 702 | std::unordered_set<IMAGE_STATE*> sparse_images; |
| 703 | // If we're binding sparse image memory make sure reqs were queried and note if metadata is required and bound |
| 704 | for (uint32_t i = 0; i < bindInfo.imageBindCount; ++i) { |
| 705 | const auto& image_bind = bindInfo.pImageBinds[i]; |
| 706 | auto image_state = GetImageState(image_bind.image); |
| 707 | if (!image_state) |
| 708 | continue; // Param/Object validation should report image_bind.image handles being invalid, so just skip here. |
| 709 | sparse_images.insert(image_state); |
| 710 | if (image_state->createInfo.flags & VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT) { |
| 711 | if (!image_state->get_sparse_reqs_called || image_state->sparse_requirements.empty()) { |
| 712 | // For now just warning if sparse image binding occurs without calling to get reqs first |
| 713 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 714 | HandleToUint64(image_state->image), kVUID_Core_MemTrack_InvalidState, |
| 715 | "vkQueueBindSparse(): Binding sparse memory to %s without first calling " |
| 716 | "vkGetImageSparseMemoryRequirements[2KHR]() to retrieve requirements.", |
| 717 | report_data->FormatHandle(image_state->image).c_str()); |
| 718 | } |
| 719 | } |
| 720 | if (!image_state->memory_requirements_checked) { |
| 721 | // For now just warning if sparse image binding occurs without calling to get reqs first |
| 722 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 723 | HandleToUint64(image_state->image), kVUID_Core_MemTrack_InvalidState, |
| 724 | "vkQueueBindSparse(): Binding sparse memory to %s without first calling " |
| 725 | "vkGetImageMemoryRequirements() to retrieve requirements.", |
| 726 | report_data->FormatHandle(image_state->image).c_str()); |
| 727 | } |
| 728 | } |
| 729 | for (uint32_t i = 0; i < bindInfo.imageOpaqueBindCount; ++i) { |
| 730 | const auto& image_opaque_bind = bindInfo.pImageOpaqueBinds[i]; |
| 731 | auto image_state = GetImageState(bindInfo.pImageOpaqueBinds[i].image); |
| 732 | if (!image_state) |
| 733 | continue; // Param/Object validation should report image_bind.image handles being invalid, so just skip here. |
| 734 | sparse_images.insert(image_state); |
| 735 | if (image_state->createInfo.flags & VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT) { |
| 736 | if (!image_state->get_sparse_reqs_called || image_state->sparse_requirements.empty()) { |
| 737 | // For now just warning if sparse image binding occurs without calling to get reqs first |
| 738 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 739 | HandleToUint64(image_state->image), kVUID_Core_MemTrack_InvalidState, |
| 740 | "vkQueueBindSparse(): Binding opaque sparse memory to %s without first calling " |
| 741 | "vkGetImageSparseMemoryRequirements[2KHR]() to retrieve requirements.", |
| 742 | report_data->FormatHandle(image_state->image).c_str()); |
| 743 | } |
| 744 | } |
| 745 | if (!image_state->memory_requirements_checked) { |
| 746 | // For now just warning if sparse image binding occurs without calling to get reqs first |
| 747 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 748 | HandleToUint64(image_state->image), kVUID_Core_MemTrack_InvalidState, |
| 749 | "vkQueueBindSparse(): Binding opaque sparse memory to %s without first calling " |
| 750 | "vkGetImageMemoryRequirements() to retrieve requirements.", |
| 751 | report_data->FormatHandle(image_state->image).c_str()); |
| 752 | } |
| 753 | for (uint32_t j = 0; j < image_opaque_bind.bindCount; ++j) { |
| 754 | if (image_opaque_bind.pBinds[j].flags & VK_SPARSE_MEMORY_BIND_METADATA_BIT) { |
| 755 | image_state->sparse_metadata_bound = true; |
| 756 | } |
| 757 | } |
| 758 | } |
| 759 | for (const auto& sparse_image_state : sparse_images) { |
| 760 | if (sparse_image_state->sparse_metadata_required && !sparse_image_state->sparse_metadata_bound) { |
| 761 | // Warn if sparse image binding metadata required for image with sparse binding, but metadata not bound |
| 762 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 763 | HandleToUint64(sparse_image_state->image), kVUID_Core_MemTrack_InvalidState, |
| 764 | "vkQueueBindSparse(): Binding sparse memory to %s which requires a metadata aspect but no " |
| 765 | "binding with VK_SPARSE_MEMORY_BIND_METADATA_BIT set was made.", |
| 766 | report_data->FormatHandle(sparse_image_state->image).c_str()); |
| 767 | } |
| 768 | } |
| 769 | } |
| 770 | |
| 771 | return skip; |
| 772 | } |