• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
20 #pragma once
21 
22 #include "chassis.h"
23 #include <string>
24 
25 static const uint32_t kMemoryObjectWarningLimit = 250;
26 
27 class BestPractices : public ValidationObject {
28    public:
29     std::string GetAPIVersionName(uint32_t version);
30 
31     bool PreCallValidateCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator,
32                                        VkInstance* pInstance);
33     void PreCallRecordCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator,
34                                      VkInstance* pInstance);
35     bool PreCallValidateCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* pCreateInfo,
36                                      const VkAllocationCallbacks* pAllocator, VkDevice* pDevice);
37     bool PreCallValidateCreateBuffer(VkDevice device, const VkBufferCreateInfo* pCreateInfo,
38                                      const VkAllocationCallbacks* pAllocator, VkBuffer* pBuffer);
39     bool PreCallValidateCreateImage(VkDevice device, const VkImageCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator,
40                                     VkImage* pImage);
41     bool PreCallValidateCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR* pCreateInfo,
42                                            const VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pSwapchain);
43     bool PreCallValidateCreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount,
44                                                   const VkSwapchainCreateInfoKHR* pCreateInfos,
45                                                   const VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pSwapchains);
46     bool PreCallValidateCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo,
47                                          const VkAllocationCallbacks* pAllocator, VkRenderPass* pRenderPass);
48     bool PreCallValidateAllocateMemory(VkDevice device, const VkMemoryAllocateInfo* pAllocateInfo,
49                                        const VkAllocationCallbacks* pAllocator, VkDeviceMemory* pMemory);
50     void PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory memory, const VkAllocationCallbacks* pAllocator);
51     bool PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
52                                                 const VkGraphicsPipelineCreateInfo* pCreateInfos,
53                                                 const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines);
54     bool PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
55                                                const VkComputePipelineCreateInfo* pCreateInfos,
56                                                const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines);
57 
58     bool CheckPipelineStageFlags(std::string api_name, const VkPipelineStageFlags flags);
59     bool PreCallValidateQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence);
60     bool PreCallValidateCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask);
61     bool PreCallValidateCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask);
62     bool PreCallValidateCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents,
63                                       VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask,
64                                       uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers,
65                                       uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers,
66                                       uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers);
67     bool PreCallValidateCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask,
68                                            VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags,
69                                            uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers,
70                                            uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers,
71                                            uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers);
72     bool PreCallValidateCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage,
73                                           VkQueryPool queryPool, uint32_t query);
74     bool PreCallValidateCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex,
75                                 uint32_t firstInstance);
76     bool PreCallValidateCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount,
77                                        uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance);
78     bool PreCallValidateCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t drawCount,
79                                         uint32_t stride);
80     bool PreCallValidateCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
81                                                uint32_t drawCount, uint32_t stride);
82     bool PreCallValidateCmdDispatch(VkCommandBuffer commandBuffer, uint32_t groupCountX, uint32_t groupCountY,
83                                     uint32_t groupCountZ);
84 
85    private:
86     uint32_t instance_api_version;
87     uint32_t device_api_version;
88 
89     uint32_t num_mem_objects;
90 };
91