blob: 87f9d619e7942b0824d2e412bbe271fc4b473f71 [file] [log] [blame]
Camdeneaa86ea2019-07-26 11:00:09 -06001/* 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
Camden3231dcc2019-08-05 11:28:57 -060020#include "best_practices.h"
Camden5b184be2019-08-13 07:50:19 -060021#include "layer_chassis_dispatch.h"
Camden Stocker0a660ce2019-08-27 15:30:40 -060022#include "best_practices_error_enums.h"
Camden5b184be2019-08-13 07:50:19 -060023
24#include <string>
25#include <iomanip>
26
27// get the API name is proper format
28std::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
40bool 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 Stockerb6dee342019-08-22 15:56:15 -060046 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]);
Camden5b184be2019-08-13 07:50:19 -060050 }
51 }
52
53 return skip;
54}
55
56void BestPractices::PreCallRecordCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator,
57 VkInstance* pInstance) {
58 instance_api_version = pCreateInfo->pApplicationInfo->apiVersion;
59}
60
61bool 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 Stockerb6dee342019-08-22 15:56:15 -060075 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());
Camden5b184be2019-08-13 07:50:19 -060079 }
80
81 for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
82 if (white_list(pCreateInfo->ppEnabledExtensionNames[i], kInstanceExtensionNames)) {
Camden Stockerb6dee342019-08-22 15:56:15 -060083 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]);
Camden5b184be2019-08-13 07:50:19 -060087 }
88 }
89
Camden83a9c372019-08-14 11:41:38 -060090 auto pd_state = GetPhysicalDeviceState(physicalDevice);
91 if ((pd_state->vkGetPhysicalDeviceSurfaceCapabilitiesKHRState == UNCALLED) && (pCreateInfo->pEnabledFeatures != NULL)) {
Camden Stockerb6dee342019-08-22 15:56:15 -060092 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().");
Camden83a9c372019-08-14 11:41:38 -060095 }
96
Camden5b184be2019-08-13 07:50:19 -060097 return skip;
98}
99
100bool 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 Stockerb6dee342019-08-22 15:56:15 -0600109 log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
110 kVUID_BestPractices_SharingModeExclusive,
Camden5b184be2019-08-13 07:50:19 -0600111 "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
119bool 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 Stockerb6dee342019-08-22 15:56:15 -0600128 log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
129 kVUID_BestPractices_SharingModeExclusive,
Camden5b184be2019-08-13 07:50:19 -0600130 "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
138bool BestPractices::PreCallValidateCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR* pCreateInfo,
139 const VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pSwapchain) {
140 bool skip = false;
141
Camden83a9c372019-08-14 11:41:38 -0600142 auto physical_device_state = GetPhysicalDeviceState();
143
144 if (physical_device_state->vkGetPhysicalDeviceSurfaceCapabilitiesKHRState == UNCALLED) {
145 skip |= log_msg(
Camden Stockerb6dee342019-08-22 15:56:15 -0600146 report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
147 kVUID_BestPractices_Swapchain_GetSurfaceNotCalled,
Camden83a9c372019-08-14 11:41:38 -0600148 "vkCreateSwapchainKHR() called before getting surface capabilities from vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
149 }
150
151 if (physical_device_state->vkGetPhysicalDeviceSurfacePresentModesKHRState != QUERY_DETAILS) {
Camden Stockerb6dee342019-08-22 15:56:15 -0600152 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().");
Camden83a9c372019-08-14 11:41:38 -0600156 }
157
158 if (physical_device_state->vkGetPhysicalDeviceSurfaceFormatsKHRState != QUERY_DETAILS) {
159 skip |=
Camden Stockerb6dee342019-08-22 15:56:15 -0600160 log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
161 kVUID_BestPractices_Swapchain_GetSurfaceNotCalled,
Camden83a9c372019-08-14 11:41:38 -0600162 "vkCreateSwapchainKHR() called before getting surface format(s) from vkGetPhysicalDeviceSurfaceFormatsKHR().");
163 }
164
Camden5b184be2019-08-13 07:50:19 -0600165 if ((pCreateInfo->queueFamilyIndexCount > 1) && (pCreateInfo->imageSharingMode == VK_SHARING_MODE_EXCLUSIVE)) {
Camden Stockerb6dee342019-08-22 15:56:15 -0600166 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);
Camden5b184be2019-08-13 07:50:19 -0600171 }
172
173 return skip;
174}
175
176bool 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 Stockerb6dee342019-08-22 15:56:15 -0600183 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);
Camden5b184be2019-08-13 07:50:19 -0600190 }
191 }
192
193 return skip;
194}
195
196bool 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 Stockerb6dee342019-08-22 15:56:15 -0600206 kVUID_BestPractices_RenderPass_Attatchment,
Camden5b184be2019-08-13 07:50:19 -0600207 "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 Stockerb6dee342019-08-22 15:56:15 -0600214 kVUID_BestPractices_RenderPass_Attatchment,
Camden5b184be2019-08-13 07:50:19 -0600215 "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
231bool 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 Stockerb6dee342019-08-22 15:56:15 -0600239 kVUID_BestPractices_AllocateMemory_TooManyObjects,
240 "Performance Warning: This app has > %" PRIu32 " memory objects.", kMemoryObjectWarningLimit);
Camden5b184be2019-08-13 07:50:19 -0600241 }
242
Camden83a9c372019-08-14 11:41:38 -0600243 // TODO: Insert get check for GetPhysicalDeviceMemoryProperties once the state is tracked in the StateTracker
244
245 return skip;
246}
247
248bool 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
Camden5b184be2019-08-13 07:50:19 -0600259 return skip;
260}
261
262void BestPractices::PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory memory, const VkAllocationCallbacks* pAllocator) {
263 if (memory != VK_NULL_HANDLE) {
264 num_mem_objects--;
265 }
266}
267
Camden83a9c372019-08-14 11:41:38 -0600268// TODO: Insert get check for Get[Buffer/Image]MemoryRequirements() inside Bind[Buffer/Image]Memory() once tracked inside of
269// StateTracker State will be tracked in [BUFFER/IMAGE]_STATE->memory_requirements_checked
270
Camden5b184be2019-08-13 07:50:19 -0600271bool BestPractices::PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
272 const VkGraphicsPipelineCreateInfo* pCreateInfos,
273 const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines) {
274 bool skip = false;
275
276 if ((createInfoCount > 1) && (!pipelineCache)) {
277 skip |=
278 log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Camden Stockerb6dee342019-08-22 15:56:15 -0600279 kVUID_BestPractices_CreatePipelines_MultiplePipelines,
Camden5b184be2019-08-13 07:50:19 -0600280 "Performance Warning: This vkCreateGraphicsPipelines call is creating multiple pipelines but is not using a "
281 "pipeline cache, which may help with performance");
282 }
283
284 return skip;
285}
286
287bool BestPractices::PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
288 const VkComputePipelineCreateInfo* pCreateInfos,
289 const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines) {
290 bool skip = false;
291
292 if ((createInfoCount > 1) && (!pipelineCache)) {
293 skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Camden Stockerb6dee342019-08-22 15:56:15 -0600294 kVUID_BestPractices_CreatePipelines_MultiplePipelines,
Camden5b184be2019-08-13 07:50:19 -0600295 "Performance Warning: This vkCreateComputePipelines call is creating multiple pipelines but is not using a "
296 "pipeline cache, which may help with performance");
297 }
298
299 return skip;
300}
301
302bool BestPractices::CheckPipelineStageFlags(std::string api_name, const VkPipelineStageFlags flags) {
303 bool skip = false;
304
305 if (flags & VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT) {
Camden Stockerb6dee342019-08-22 15:56:15 -0600306 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
307 kVUID_BestPractices_PipelineStageFlags,
308 "You are using VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT when %s is called\n", api_name.c_str());
Camden5b184be2019-08-13 07:50:19 -0600309 } else if (flags & VK_PIPELINE_STAGE_ALL_COMMANDS_BIT) {
Camden Stockerb6dee342019-08-22 15:56:15 -0600310 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
311 kVUID_BestPractices_PipelineStageFlags,
312 "You are using VK_PIPELINE_STAGE_ALL_COMMANDS_BIT when %s is called\n", api_name.c_str());
Camden5b184be2019-08-13 07:50:19 -0600313 }
314
315 return skip;
316}
317
318bool BestPractices::PreCallValidateQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence) {
319 bool skip = false;
320
321 for (uint32_t submit = 0; submit < submitCount; submit++) {
322 for (uint32_t semaphore = 0; semaphore < pSubmits[submit].waitSemaphoreCount; semaphore++) {
323 skip |= CheckPipelineStageFlags("vkQueueSubmit", pSubmits[submit].pWaitDstStageMask[semaphore]);
324 }
325 }
326
327 return skip;
328}
329
330bool BestPractices::PreCallValidateCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) {
331 bool skip = false;
332
333 skip |= CheckPipelineStageFlags("vkCmdSetEvent", stageMask);
334
335 return skip;
336}
337
338bool BestPractices::PreCallValidateCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask) {
339 bool skip = false;
340
341 skip |= CheckPipelineStageFlags("vkCmdResetEvent", stageMask);
342
343 return skip;
344}
345
346bool BestPractices::PreCallValidateCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents,
347 VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask,
348 uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers,
349 uint32_t bufferMemoryBarrierCount,
350 const VkBufferMemoryBarrier* pBufferMemoryBarriers,
351 uint32_t imageMemoryBarrierCount,
352 const VkImageMemoryBarrier* pImageMemoryBarriers) {
353 bool skip = false;
354
355 skip |= CheckPipelineStageFlags("vkCmdWaitEvents", srcStageMask);
356 skip |= CheckPipelineStageFlags("vkCmdWaitEvents", dstStageMask);
357
358 return skip;
359}
360
361bool BestPractices::PreCallValidateCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask,
362 VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags,
363 uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers,
364 uint32_t bufferMemoryBarrierCount,
365 const VkBufferMemoryBarrier* pBufferMemoryBarriers,
366 uint32_t imageMemoryBarrierCount,
367 const VkImageMemoryBarrier* pImageMemoryBarriers) {
368 bool skip = false;
369
370 skip |= CheckPipelineStageFlags("vkCmdPipelineBarrier", srcStageMask);
371 skip |= CheckPipelineStageFlags("vkCmdPipelineBarrier", dstStageMask);
372
373 return skip;
374}
375
376bool BestPractices::PreCallValidateCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage,
377 VkQueryPool queryPool, uint32_t query) {
378 bool skip = false;
379
380 skip |= CheckPipelineStageFlags("vkCmdWriteTimestamp", pipelineStage);
381
382 return skip;
383}
384
385bool BestPractices::PreCallValidateCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount,
386 uint32_t firstVertex, uint32_t firstInstance) {
387 bool skip = false;
388
389 if (instanceCount == 0) {
390 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Camden Stockerb6dee342019-08-22 15:56:15 -0600391 kVUID_BestPractices_CmdDraw_InstanceCountZero,
392 "Warning: You are calling vkCmdDraw() with an instanceCount of Zero.");
Camden5b184be2019-08-13 07:50:19 -0600393 }
394
395 return skip;
396}
397
398bool BestPractices::PreCallValidateCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount,
399 uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) {
400 bool skip = false;
401
402 if (instanceCount == 0) {
403 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Camden Stockerb6dee342019-08-22 15:56:15 -0600404 kVUID_BestPractices_CmdDraw_InstanceCountZero,
405 "Warning: You are calling vkCmdDrawIndexed() with an instanceCount of Zero.");
Camden5b184be2019-08-13 07:50:19 -0600406 }
407
408 return skip;
409}
410
411bool BestPractices::PreCallValidateCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
412 uint32_t drawCount, uint32_t stride) {
413 bool skip = false;
414
415 if (drawCount == 0) {
416 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Camden Stockerb6dee342019-08-22 15:56:15 -0600417 kVUID_BestPractices_CmdDraw_DrawCountZero,
418 "Warning: You are calling vkCmdDrawIndirect() with a drawCount of Zero.");
Camden5b184be2019-08-13 07:50:19 -0600419 }
420
421 return skip;
422}
423
424bool BestPractices::PreCallValidateCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
425 uint32_t drawCount, uint32_t stride) {
426 bool skip = false;
427
428 if (drawCount == 0) {
429 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Camden Stockerb6dee342019-08-22 15:56:15 -0600430 kVUID_BestPractices_CmdDraw_DrawCountZero,
431 "Warning: You are calling vkCmdDrawIndexedIndirect() with a drawCount of Zero.");
Camden5b184be2019-08-13 07:50:19 -0600432 }
433
434 return skip;
435}
436
437bool BestPractices::PreCallValidateCmdDispatch(VkCommandBuffer commandBuffer, uint32_t groupCountX, uint32_t groupCountY,
438 uint32_t groupCountZ) {
439 bool skip = false;
440
441 if ((groupCountX == 0) || (groupCountY == 0) || (groupCountZ == 0)) {
Camden Stockerb6dee342019-08-22 15:56:15 -0600442 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
443 kVUID_BestPractices_CmdDispatch_GroupCountZero,
444 "Warning: You are calling vkCmdDispatch() while one or more groupCounts are zero (groupCountX = %" PRIu32
445 ", groupCountY = %" PRIu32 ", groupCountZ = %" PRIu32 ").",
446 groupCountX, groupCountY, groupCountZ);
Camden5b184be2019-08-13 07:50:19 -0600447 }
448
449 return skip;
450}
Camden83a9c372019-08-14 11:41:38 -0600451
452bool BestPractices::PreCallValidateGetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physicalDevice, uint32_t planeIndex,
453 uint32_t* pDisplayCount, VkDisplayKHR* pDisplays) {
454 bool skip = false;
455
456 auto physical_device_state = GetPhysicalDeviceState(physicalDevice);
457
458 if (physical_device_state->vkGetPhysicalDeviceDisplayPlanePropertiesKHRState != QUERY_DETAILS) {
Camden Stockerb6dee342019-08-22 15:56:15 -0600459 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
460 kVUID_BestPractices_DisplayPlane_PropertiesNotCalled,
461 "vkGetDisplayPlaneSupportedDisplaysKHR() called before getting diplay plane properties from "
462 "vkGetPhysicalDeviceDisplayPlanePropertiesKHR().");
Camden83a9c372019-08-14 11:41:38 -0600463 }
464
465 return skip;
466}