blob: 185e5a64f27d8acddc5f5c94225090c092ad90d6 [file] [log] [blame]
Tobin Ehlise79df942014-11-18 16:38:08 -07001/*
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002 * Vulkan
Tobin Ehlise79df942014-11-18 16:38:08 -07003 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060024#include "vkLayer.h"
Tobin Ehlis63bb9482015-03-17 16:24:32 -060025#include <vector>
26
27using namespace std;
28
Tobin Ehlise79df942014-11-18 16:38:08 -070029// Draw State ERROR codes
30typedef enum _DRAW_STATE_ERROR
31{
Tobin Ehlis84c521c2015-01-19 08:42:29 -070032 DRAWSTATE_NONE, // Used for INFO & other non-error messages
Tobin Ehlis41415bb2015-01-22 10:45:21 -070033 DRAWSTATE_INTERNAL_ERROR, // Error with DrawState internal data structures
Tobin Ehlis84c521c2015-01-19 08:42:29 -070034 DRAWSTATE_NO_PIPELINE_BOUND, // Unable to identify a bound pipeline
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -060035 DRAWSTATE_INVALID_POOL, // Invalid DS pool
Tobin Ehlis83ebbef2015-02-10 15:35:23 -070036 DRAWSTATE_INVALID_SET, // Invalid DS
Tobin Ehlis41415bb2015-01-22 10:45:21 -070037 DRAWSTATE_INVALID_LAYOUT, // Invalid DS layout
Tobin Ehlis84c521c2015-01-19 08:42:29 -070038 DRAWSTATE_DS_END_WITHOUT_BEGIN, // EndDSUpdate called w/o corresponding BeginDSUpdate
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -060039 DRAWSTATE_UPDATE_WITHOUT_BEGIN, // Attempt to update descriptors w/o calling BeginDescriptorPoolUpdate
Tobin Ehlis83ebbef2015-02-10 15:35:23 -070040 DRAWSTATE_INVALID_PIPELINE, // Invalid Pipeline referenced
Tobin Ehlis8cced212015-02-13 10:26:14 -070041 DRAWSTATE_INVALID_CMD_BUFFER, // Invalid CmdBuffer referenced
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060042 DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, // binding in vkCmdBindVertexData() too large for PSO's pVertexBindingDescriptions array
Tobin Ehlis84c521c2015-01-19 08:42:29 -070043 DRAWSTATE_INVALID_DYNAMIC_STATE_OBJECT, // Invalid dyn state object
44 DRAWSTATE_MISSING_DOT_PROGRAM, // No "dot" program in order to generate png image
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060045 DRAWSTATE_BINDING_DS_NO_END_UPDATE, // DS bound to CmdBuffer w/o call to vkEndDescriptorSetUpdate())
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -060046 DRAWSTATE_NO_DS_POOL, // No DS Pool is available
Tobin Ehlis41415bb2015-01-22 10:45:21 -070047 DRAWSTATE_OUT_OF_MEMORY, // malloc failed
48 DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, // Type in layout vs. update are not the same
Tobin Ehlis83ebbef2015-02-10 15:35:23 -070049 DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, // Descriptors set for update out of bounds for corresponding layout section
Tobin Ehlis8733adc2015-02-23 16:09:58 -070050 DRAWSTATE_INVALID_UPDATE_INDEX, // Index of requested update is invalid for specified descriptors set
Tobin Ehlis2464b882015-04-01 08:40:34 -060051 DRAWSTATE_INVALID_UPDATE_STRUCT, // Struct in DS Update tree is of invalid type
Tobin Ehlis28be0be2015-05-22 12:38:16 -060052 DRAWSTATE_NUM_SAMPLES_MISMATCH, // Number of samples in bound PSO does not match number in FB of current RenderPass
53 DRAWSTATE_NO_END_CMD_BUFFER, // Must call vkEndCommandBuffer() before QueueSubmit on that cmdBuffer
Tobin Ehlise79df942014-11-18 16:38:08 -070054} DRAW_STATE_ERROR;
Tobin Ehlis26092022014-11-20 09:49:17 -070055
56typedef enum _DRAW_TYPE
57{
58 DRAW = 0,
59 DRAW_INDEXED = 1,
60 DRAW_INDIRECT = 2,
61 DRAW_INDEXED_INDIRECT = 3,
62 DRAW_BEGIN_RANGE = DRAW,
63 DRAW_END_RANGE = DRAW_INDEXED_INDIRECT,
64 NUM_DRAW_TYPES = (DRAW_END_RANGE - DRAW_BEGIN_RANGE + 1),
65} DRAW_TYPE;
Tobin Ehlisa701ef02014-11-27 15:43:39 -070066
Tobin Ehlis84c521c2015-01-19 08:42:29 -070067typedef struct _SHADER_DS_MAPPING {
68 uint32_t slotCount;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060069 VkDescriptorSetLayoutCreateInfo* pShaderMappingSlot;
Tobin Ehlis84c521c2015-01-19 08:42:29 -070070} SHADER_DS_MAPPING;
71
Tobin Ehlis41415bb2015-01-22 10:45:21 -070072typedef struct _GENERIC_HEADER {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060073 VkStructureType sType;
Tobin Ehlis84c521c2015-01-19 08:42:29 -070074 const void* pNext;
Tobin Ehlis41415bb2015-01-22 10:45:21 -070075} GENERIC_HEADER;
Tobin Ehlis84c521c2015-01-19 08:42:29 -070076
77typedef struct _PIPELINE_NODE {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060078 VkPipeline pipeline;
Tobin Ehliscd3109e2015-04-01 11:59:08 -060079
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060080 VkGraphicsPipelineCreateInfo graphicsPipelineCI;
81 VkPipelineVertexInputCreateInfo vertexInputCI;
82 VkPipelineIaStateCreateInfo iaStateCI;
83 VkPipelineTessStateCreateInfo tessStateCI;
84 VkPipelineVpStateCreateInfo vpStateCI;
85 VkPipelineRsStateCreateInfo rsStateCI;
86 VkPipelineMsStateCreateInfo msStateCI;
87 VkPipelineCbStateCreateInfo cbStateCI;
88 VkPipelineDsStateCreateInfo dsStateCI;
89 VkPipelineShaderStageCreateInfo vsCI;
90 VkPipelineShaderStageCreateInfo tcsCI;
91 VkPipelineShaderStageCreateInfo tesCI;
92 VkPipelineShaderStageCreateInfo gsCI;
93 VkPipelineShaderStageCreateInfo fsCI;
94 // Compute shader is include in VkComputePipelineCreateInfo
95 VkComputePipelineCreateInfo computePipelineCI;
Tobin Ehliscd3109e2015-04-01 11:59:08 -060096
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060097 VkGraphicsPipelineCreateInfo* pCreateTree; // Ptr to shadow of data in create tree
Tobin Ehlis84c521c2015-01-19 08:42:29 -070098 // Vtx input info (if any)
99 uint32_t vtxBindingCount; // number of bindings
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600100 VkVertexInputBindingDescription* pVertexBindingDescriptions;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700101 uint32_t vtxAttributeCount; // number of attributes
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600102 VkVertexInputAttributeDescription* pVertexAttributeDescriptions;
Tobin Ehlis83ebbef2015-02-10 15:35:23 -0700103 uint32_t attachmentCount; // number of CB attachments
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600104 VkPipelineCbAttachmentState* pAttachments;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700105} PIPELINE_NODE;
106
107typedef struct _SAMPLER_NODE {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600108 VkSampler sampler;
109 VkSamplerCreateInfo createInfo;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700110} SAMPLER_NODE;
111
Tobin Ehlis41415bb2015-01-22 10:45:21 -0700112typedef struct _IMAGE_NODE {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600113 VkImageView image;
114 VkImageViewCreateInfo createInfo;
115 VkImageViewAttachInfo attachInfo;
Tobin Ehlis41415bb2015-01-22 10:45:21 -0700116} IMAGE_NODE;
117
118typedef struct _BUFFER_NODE {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600119 VkBufferView buffer;
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600120 VkBufferViewCreateInfo createInfo;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600121 VkBufferViewAttachInfo attachInfo;
Tobin Ehlis41415bb2015-01-22 10:45:21 -0700122} BUFFER_NODE;
123
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700124typedef struct _DYNAMIC_STATE_NODE {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600125 VkDynamicStateObject stateObj;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600126 GENERIC_HEADER* pCreateInfo;
127 union {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600128 VkDynamicVpStateCreateInfo vpci;
129 VkDynamicRsStateCreateInfo rsci;
130 VkDynamicCbStateCreateInfo cbci;
131 VkDynamicDsStateCreateInfo dsci;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600132 } create_info;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700133} DYNAMIC_STATE_NODE;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700134// Descriptor Data structures
Tobin Ehlis41415bb2015-01-22 10:45:21 -0700135// Layout Node has the core layout data
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700136typedef struct _LAYOUT_NODE {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600137 VkDescriptorSetLayout layout;
138 VkDescriptorType* pTypes; // Dynamic array that will be created to verify descriptor types
139 VkDescriptorSetLayoutCreateInfo createInfo;
Tobin Ehlis83ebbef2015-02-10 15:35:23 -0700140 uint32_t startIndex; // 1st index of this layout
141 uint32_t endIndex; // last index of this layout
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700142} LAYOUT_NODE;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700143typedef struct _SET_NODE {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600144 VkDescriptorSet set;
145 VkDescriptorPool pool;
146 VkDescriptorSetUsage setUsage;
Tobin Ehlis82871a82015-02-19 09:55:18 -0700147 // Head of LL of all Update structs for this set
Tobin Ehlis41415bb2015-01-22 10:45:21 -0700148 GENERIC_HEADER* pUpdateStructs;
149 // Total num of descriptors in this set (count of its layout plus all prior layouts)
150 uint32_t descriptorCount;
Tobin Ehlis82871a82015-02-19 09:55:18 -0700151 GENERIC_HEADER** ppDescriptors; // Array where each index points to update node for its slot
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600152 LAYOUT_NODE* pLayout; // Layout for this set
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700153 struct _SET_NODE* pNext;
154} SET_NODE;
155
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600156typedef struct _POOL_NODE {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600157 VkDescriptorPool pool;
158 VkDescriptorPoolUsage poolUsage;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700159 uint32_t maxSets;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600160 VkDescriptorPoolCreateInfo createInfo;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600161 bool32_t updateActive; // Track if Pool is in an update block
162 SET_NODE* pSets; // Head of LL of sets for this Pool
163} POOL_NODE;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700164
Tobin Ehlis8cced212015-02-13 10:26:14 -0700165// Cmd Buffer Tracking
166typedef enum _CMD_TYPE
167{
168 CMD_BINDPIPELINE,
169 CMD_BINDPIPELINEDELTA,
170 CMD_BINDDYNAMICSTATEOBJECT,
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600171 CMD_BINDDESCRIPTORSETS,
Tobin Ehlis8cced212015-02-13 10:26:14 -0700172 CMD_BINDINDEXBUFFER,
173 CMD_BINDVERTEXBUFFER,
174 CMD_DRAW,
175 CMD_DRAWINDEXED,
176 CMD_DRAWINDIRECT,
177 CMD_DRAWINDEXEDINDIRECT,
178 CMD_DISPATCH,
179 CMD_DISPATCHINDIRECT,
180 CMD_COPYBUFFER,
181 CMD_COPYIMAGE,
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600182 CMD_BLITIMAGE,
Tobin Ehlis8cced212015-02-13 10:26:14 -0700183 CMD_COPYBUFFERTOIMAGE,
184 CMD_COPYIMAGETOBUFFER,
185 CMD_CLONEIMAGEDATA,
186 CMD_UPDATEBUFFER,
187 CMD_FILLBUFFER,
188 CMD_CLEARCOLORIMAGE,
189 CMD_CLEARCOLORIMAGERAW,
190 CMD_CLEARDEPTHSTENCIL,
191 CMD_RESOLVEIMAGE,
192 CMD_SETEVENT,
193 CMD_RESETEVENT,
194 CMD_WAITEVENTS,
195 CMD_PIPELINEBARRIER,
196 CMD_BEGINQUERY,
197 CMD_ENDQUERY,
198 CMD_RESETQUERYPOOL,
199 CMD_WRITETIMESTAMP,
200 CMD_INITATOMICCOUNTERS,
201 CMD_LOADATOMICCOUNTERS,
202 CMD_SAVEATOMICCOUNTERS,
203 CMD_BEGINRENDERPASS,
Tobin Ehlis1dae99a2015-03-02 10:16:40 -0700204 CMD_ENDRENDERPASS,
205 CMD_DBGMARKERBEGIN,
206 CMD_DBGMARKEREND,
Tobin Ehlis8cced212015-02-13 10:26:14 -0700207} CMD_TYPE;
208// Data structure for holding sequence of cmds in cmd buffer
209typedef struct _CMD_NODE {
Tobin Ehlis8cced212015-02-13 10:26:14 -0700210 CMD_TYPE type;
211 uint64_t cmdNumber;
212} CMD_NODE;
213
214typedef enum _CB_STATE
215{
216 CB_NEW, // Newly created CB w/o any cmds
217 CB_UPDATE_ACTIVE, // BeginCB has been called on this CB
218 CB_UPDATE_COMPLETE // EndCB has been called on this CB
219} CB_STATE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600220// Cmd Buffer Wrapper Struct
Tobin Ehlis8cced212015-02-13 10:26:14 -0700221typedef struct _GLOBAL_CB_NODE {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600222 VkCmdBuffer cmdBuffer;
Tobin Ehlis28be0be2015-05-22 12:38:16 -0600223 uint32_t queueNodeIndex;
224 VkFlags flags;
225 VkFence fence; // fence tracking this cmd buffer
226 uint64_t numCmds; // number of cmds in this CB
227 uint64_t drawCount[NUM_DRAW_TYPES]; // Count of each type of draw in this CB
228 CB_STATE state; // Track if cmd buffer update status
229 vector<CMD_NODE*> pCmds;
Tobin Ehlis8cced212015-02-13 10:26:14 -0700230 // Currently storing "lastBound" objects on per-CB basis
231 // long-term may want to create caches of "lastBound" states and could have
232 // each individual CMD_NODE referencing its own "lastBound" state
Tobin Ehlis28be0be2015-05-22 12:38:16 -0600233 VkPipeline lastBoundPipeline;
234 uint32_t lastVtxBinding;
235 DYNAMIC_STATE_NODE* lastBoundDynamicState[VK_NUM_STATE_BIND_POINT];
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600236 VkDescriptorSet lastBoundDescriptorSet;
237 VkRenderPass activeRenderPass;
Tobin Ehlis28be0be2015-05-22 12:38:16 -0600238 VkFramebuffer framebuffer;
239 vector<VkDescriptorSet> boundDescriptorSets;
Tobin Ehlis8cced212015-02-13 10:26:14 -0700240} GLOBAL_CB_NODE;
241
Tobin Ehlisa701ef02014-11-27 15:43:39 -0700242//prototypes for extension functions
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600243void drawStateDumpDotFile(char* outFileName);
244void drawStateDumpPngFile(char* outFileName);
Jeremy Hayes7ec63022015-02-26 15:59:19 -0700245void drawStateDumpCommandBufferDotFile(char* outFileName);
Tobin Ehlis266473d2014-12-16 17:34:50 -0700246// Func ptr typedefs
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600247typedef void (*DRAW_STATE_DUMP_DOT_FILE)(char*);
248typedef void (*DRAW_STATE_DUMP_PNG_FILE)(char*);
Jeremy Hayes7ec63022015-02-26 15:59:19 -0700249typedef void (*DRAW_STATE_DUMP_COMMAND_BUFFER_DOT_FILE)(char*);