blob: 6ae96d9d205233e4f189b3fe7f740bc25c149726 [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 Ehlisde63c532015-06-18 15:59:33 -060038 DRAWSTATE_INVALID_PIPELINE, // Invalid Pipeline handle referenced
39 DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, // Attempt to create a pipeline with invalid state
Tobin Ehlis8cced212015-02-13 10:26:14 -070040 DRAWSTATE_INVALID_CMD_BUFFER, // Invalid CmdBuffer referenced
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060041 DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, // binding in vkCmdBindVertexData() too large for PSO's pVertexBindingDescriptions array
Tobin Ehlis84c521c2015-01-19 08:42:29 -070042 DRAWSTATE_INVALID_DYNAMIC_STATE_OBJECT, // Invalid dyn state object
43 DRAWSTATE_MISSING_DOT_PROGRAM, // No "dot" program in order to generate png image
Tobin Ehlis41415bb2015-01-22 10:45:21 -070044 DRAWSTATE_OUT_OF_MEMORY, // malloc failed
45 DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, // Type in layout vs. update are not the same
Tobin Ehlis83ebbef2015-02-10 15:35:23 -070046 DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, // Descriptors set for update out of bounds for corresponding layout section
Tobin Ehlis8733adc2015-02-23 16:09:58 -070047 DRAWSTATE_INVALID_UPDATE_INDEX, // Index of requested update is invalid for specified descriptors set
Tobin Ehlis2464b882015-04-01 08:40:34 -060048 DRAWSTATE_INVALID_UPDATE_STRUCT, // Struct in DS Update tree is of invalid type
Tobin Ehlis28be0be2015-05-22 12:38:16 -060049 DRAWSTATE_NUM_SAMPLES_MISMATCH, // Number of samples in bound PSO does not match number in FB of current RenderPass
50 DRAWSTATE_NO_END_CMD_BUFFER, // Must call vkEndCommandBuffer() before QueueSubmit on that cmdBuffer
Tobin Ehlise42007c2015-06-19 13:00:59 -060051 DRAWSTATE_NO_BEGIN_CMD_BUFFER, // Binding cmds or calling End on CB that never had vkBeginCommandBuffer() called on it
Tobin Ehlis97866202015-06-10 12:57:07 -060052 DRAWSTATE_VIEWPORT_NOT_BOUND, // Draw submitted with no viewport state object bound
53 DRAWSTATE_RASTER_NOT_BOUND, // Draw submitted with no raster state object bound
54 DRAWSTATE_COLOR_BLEND_NOT_BOUND, // Draw submitted with no color blend state object bound when color write enabled
55 DRAWSTATE_DEPTH_STENCIL_NOT_BOUND, // Draw submitted with no depth-stencil state object bound when depth write enabled
Tobin Ehlisa366ca22015-06-19 15:07:05 -060056 DRAWSTATE_INDEX_BUFFER_NOT_BOUND, // Draw submitted with no depth-stencil state object bound when depth write enabled
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -060057 DRAWSTATE_PIPELINE_LAYOUT_MISMATCH, // Draw submitted PSO Pipeline layout that doesn't match layout from BindDescriptorSets
Tobin Ehlis642d5a52015-06-23 08:46:18 -060058 DRAWSTATE_INVALID_RENDERPASS_CMD, // Invalid cmd submitted while a RenderPass is active
Tobin Ehlis8b6c2352015-06-23 16:13:03 -060059 DRAWSTATE_RENDER_CMD_WITHOUT_RENDERPASS, // Rendering cmd submitted without an active RenderPass
60 DRAWSTATE_INVALID_RENDERPASS, // Use of a NULL or otherwise invalid RenderPass object
Tobin Ehlisde63c532015-06-18 15:59:33 -060061 DRAWSTATE_INVALID_EXTENSION,
Tobin Ehlise79df942014-11-18 16:38:08 -070062} DRAW_STATE_ERROR;
Tobin Ehlis26092022014-11-20 09:49:17 -070063
64typedef enum _DRAW_TYPE
65{
66 DRAW = 0,
67 DRAW_INDEXED = 1,
68 DRAW_INDIRECT = 2,
69 DRAW_INDEXED_INDIRECT = 3,
70 DRAW_BEGIN_RANGE = DRAW,
71 DRAW_END_RANGE = DRAW_INDEXED_INDIRECT,
72 NUM_DRAW_TYPES = (DRAW_END_RANGE - DRAW_BEGIN_RANGE + 1),
73} DRAW_TYPE;
Tobin Ehlisa701ef02014-11-27 15:43:39 -070074
Tobin Ehlis84c521c2015-01-19 08:42:29 -070075typedef struct _SHADER_DS_MAPPING {
76 uint32_t slotCount;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060077 VkDescriptorSetLayoutCreateInfo* pShaderMappingSlot;
Tobin Ehlis84c521c2015-01-19 08:42:29 -070078} SHADER_DS_MAPPING;
79
Tobin Ehlis41415bb2015-01-22 10:45:21 -070080typedef struct _GENERIC_HEADER {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060081 VkStructureType sType;
Tobin Ehlis84c521c2015-01-19 08:42:29 -070082 const void* pNext;
Tobin Ehlis41415bb2015-01-22 10:45:21 -070083} GENERIC_HEADER;
Tobin Ehlis84c521c2015-01-19 08:42:29 -070084
85typedef struct _PIPELINE_NODE {
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -060086 VkPipeline pipeline;
87 VkGraphicsPipelineCreateInfo graphicsPipelineCI;
88 VkPipelineVertexInputStateCreateInfo vertexInputCI;
89 VkPipelineIaStateCreateInfo iaStateCI;
90 VkPipelineTessStateCreateInfo tessStateCI;
91 VkPipelineVpStateCreateInfo vpStateCI;
92 VkPipelineRsStateCreateInfo rsStateCI;
93 VkPipelineMsStateCreateInfo msStateCI;
94 VkPipelineCbStateCreateInfo cbStateCI;
95 VkPipelineDsStateCreateInfo dsStateCI;
96 VkPipelineShaderStageCreateInfo vsCI;
97 VkPipelineShaderStageCreateInfo tcsCI;
98 VkPipelineShaderStageCreateInfo tesCI;
99 VkPipelineShaderStageCreateInfo gsCI;
100 VkPipelineShaderStageCreateInfo fsCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600101 // Compute shader is include in VkComputePipelineCreateInfo
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600102 VkComputePipelineCreateInfo computePipelineCI;
Tobin Ehlis806a97a2015-06-18 11:02:59 -0600103 // Flag of which shader stages are active for this pipeline
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600104 uint32_t active_shaders;
105 VkGraphicsPipelineCreateInfo* pCreateTree; // Ptr to shadow of data in create tree
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700106 // Vtx input info (if any)
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600107 uint32_t vtxBindingCount; // number of bindings
108 VkVertexInputBindingDescription* pVertexBindingDescriptions;
109 uint32_t vtxAttributeCount; // number of attributes
110 VkVertexInputAttributeDescription* pVertexAttributeDescriptions;
111 uint32_t attachmentCount; // number of CB attachments
112 VkPipelineCbAttachmentState* pAttachments;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700113} PIPELINE_NODE;
114
115typedef struct _SAMPLER_NODE {
Tobin Ehlisa366ca22015-06-19 15:07:05 -0600116 VkSampler sampler;
117 VkSamplerCreateInfo createInfo;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700118} SAMPLER_NODE;
119
Tobin Ehlis41415bb2015-01-22 10:45:21 -0700120typedef struct _IMAGE_NODE {
Tobin Ehlisa366ca22015-06-19 15:07:05 -0600121 VkImageView image;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600122 VkImageViewCreateInfo createInfo;
Tobin Ehlisa366ca22015-06-19 15:07:05 -0600123 VkDescriptorInfo descriptorInfo;
Tobin Ehlis41415bb2015-01-22 10:45:21 -0700124} IMAGE_NODE;
125
126typedef struct _BUFFER_NODE {
Tobin Ehlisa366ca22015-06-19 15:07:05 -0600127 VkBufferView buffer;
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600128 VkBufferViewCreateInfo createInfo;
Tobin Ehlisa366ca22015-06-19 15:07:05 -0600129 VkDescriptorInfo descriptorInfo;
Tobin Ehlis41415bb2015-01-22 10:45:21 -0700130} BUFFER_NODE;
131
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700132typedef struct _DYNAMIC_STATE_NODE {
Tobin Ehlisa366ca22015-06-19 15:07:05 -0600133 VkObjectType objType;
134 VkDynamicStateObject stateObj;
135 GENERIC_HEADER* pCreateInfo;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600136 union {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600137 VkDynamicVpStateCreateInfo vpci;
138 VkDynamicRsStateCreateInfo rsci;
139 VkDynamicCbStateCreateInfo cbci;
140 VkDynamicDsStateCreateInfo dsci;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600141 } create_info;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700142} DYNAMIC_STATE_NODE;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700143// Descriptor Data structures
Tobin Ehlis41415bb2015-01-22 10:45:21 -0700144// Layout Node has the core layout data
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700145typedef struct _LAYOUT_NODE {
Tobin Ehlisa366ca22015-06-19 15:07:05 -0600146 VkDescriptorSetLayout layout;
147 VkDescriptorType* pTypes; // Dynamic array that will be created to verify descriptor types
148 VkDescriptorSetLayoutCreateInfo createInfo;
149 uint32_t startIndex; // 1st index of this layout
150 uint32_t endIndex; // last index of this layout
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700151} LAYOUT_NODE;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700152typedef struct _SET_NODE {
Tobin Ehlisa366ca22015-06-19 15:07:05 -0600153 VkDescriptorSet set;
154 VkDescriptorPool pool;
155 VkDescriptorSetUsage setUsage;
Tobin Ehlis82871a82015-02-19 09:55:18 -0700156 // Head of LL of all Update structs for this set
Tobin Ehlisa366ca22015-06-19 15:07:05 -0600157 GENERIC_HEADER* pUpdateStructs;
Tobin Ehlis41415bb2015-01-22 10:45:21 -0700158 // Total num of descriptors in this set (count of its layout plus all prior layouts)
Tobin Ehlisa366ca22015-06-19 15:07:05 -0600159 uint32_t descriptorCount;
160 GENERIC_HEADER** ppDescriptors; // Array where each index points to update node for its slot
161 LAYOUT_NODE* pLayout; // Layout for this set
162 struct _SET_NODE* pNext;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700163} SET_NODE;
164
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600165typedef struct _POOL_NODE {
Tobin Ehlisa366ca22015-06-19 15:07:05 -0600166 VkDescriptorPool pool;
167 VkDescriptorPoolUsage poolUsage;
168 uint32_t maxSets;
169 VkDescriptorPoolCreateInfo createInfo;
170 SET_NODE* pSets; // Head of LL of sets for this Pool
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600171} POOL_NODE;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700172
Tobin Ehlis8cced212015-02-13 10:26:14 -0700173// Cmd Buffer Tracking
174typedef enum _CMD_TYPE
175{
176 CMD_BINDPIPELINE,
177 CMD_BINDPIPELINEDELTA,
178 CMD_BINDDYNAMICSTATEOBJECT,
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600179 CMD_BINDDESCRIPTORSETS,
Tobin Ehlis8cced212015-02-13 10:26:14 -0700180 CMD_BINDINDEXBUFFER,
181 CMD_BINDVERTEXBUFFER,
182 CMD_DRAW,
183 CMD_DRAWINDEXED,
184 CMD_DRAWINDIRECT,
185 CMD_DRAWINDEXEDINDIRECT,
186 CMD_DISPATCH,
187 CMD_DISPATCHINDIRECT,
188 CMD_COPYBUFFER,
189 CMD_COPYIMAGE,
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600190 CMD_BLITIMAGE,
Tobin Ehlis8cced212015-02-13 10:26:14 -0700191 CMD_COPYBUFFERTOIMAGE,
192 CMD_COPYIMAGETOBUFFER,
193 CMD_CLONEIMAGEDATA,
194 CMD_UPDATEBUFFER,
195 CMD_FILLBUFFER,
196 CMD_CLEARCOLORIMAGE,
197 CMD_CLEARCOLORIMAGERAW,
198 CMD_CLEARDEPTHSTENCIL,
199 CMD_RESOLVEIMAGE,
200 CMD_SETEVENT,
201 CMD_RESETEVENT,
202 CMD_WAITEVENTS,
203 CMD_PIPELINEBARRIER,
204 CMD_BEGINQUERY,
205 CMD_ENDQUERY,
206 CMD_RESETQUERYPOOL,
207 CMD_WRITETIMESTAMP,
208 CMD_INITATOMICCOUNTERS,
209 CMD_LOADATOMICCOUNTERS,
210 CMD_SAVEATOMICCOUNTERS,
211 CMD_BEGINRENDERPASS,
Tobin Ehlis1dae99a2015-03-02 10:16:40 -0700212 CMD_ENDRENDERPASS,
213 CMD_DBGMARKERBEGIN,
214 CMD_DBGMARKEREND,
Tobin Ehlis8cced212015-02-13 10:26:14 -0700215} CMD_TYPE;
216// Data structure for holding sequence of cmds in cmd buffer
217typedef struct _CMD_NODE {
Tobin Ehlis8cced212015-02-13 10:26:14 -0700218 CMD_TYPE type;
219 uint64_t cmdNumber;
220} CMD_NODE;
221
222typedef enum _CB_STATE
223{
224 CB_NEW, // Newly created CB w/o any cmds
225 CB_UPDATE_ACTIVE, // BeginCB has been called on this CB
226 CB_UPDATE_COMPLETE // EndCB has been called on this CB
227} CB_STATE;
Tobin Ehlis97866202015-06-10 12:57:07 -0600228// CB Status -- used to track status of various bindings on cmd buffer objects
229typedef VkFlags CBStatusFlags;
230typedef enum _CBStatusFlagBits
231{
232 CBSTATUS_NONE = 0x00000000, // No status is set
233 CBSTATUS_VIEWPORT_BOUND = 0x00000001, // Viewport state object has been bound
234 CBSTATUS_RASTER_BOUND = 0x00000002, // Raster state object has been bound
235 CBSTATUS_COLOR_BLEND_WRITE_ENABLE = 0x00000004, // PSO w/ CB Enable set has been bound
236 CBSTATUS_COLOR_BLEND_BOUND = 0x00000008, // CB state object has been bound
237 CBSTATUS_DEPTH_STENCIL_WRITE_ENABLE = 0x00000010, // PSO w/ DS Enable set has been bound
238 CBSTATUS_DEPTH_STENCIL_BOUND = 0x00000020, // DS state object has been bound
Tobin Ehlisa366ca22015-06-19 15:07:05 -0600239 CBSTATUS_INDEX_BUFFER_BOUND = 0x00000040, // Index buffer has been bound
Tobin Ehlis97866202015-06-10 12:57:07 -0600240} CBStatusFlagBits;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600241// Cmd Buffer Wrapper Struct
Tobin Ehlis8cced212015-02-13 10:26:14 -0700242typedef struct _GLOBAL_CB_NODE {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600243 VkCmdBuffer cmdBuffer;
Tobin Ehlis28be0be2015-05-22 12:38:16 -0600244 uint32_t queueNodeIndex;
245 VkFlags flags;
246 VkFence fence; // fence tracking this cmd buffer
247 uint64_t numCmds; // number of cmds in this CB
248 uint64_t drawCount[NUM_DRAW_TYPES]; // Count of each type of draw in this CB
Tobin Ehlis97866202015-06-10 12:57:07 -0600249 CB_STATE state; // Track cmd buffer update state
250 CBStatusFlags status; // Track status of various bindings on cmd buffer
Tobin Ehlis28be0be2015-05-22 12:38:16 -0600251 vector<CMD_NODE*> pCmds;
Tobin Ehlis8cced212015-02-13 10:26:14 -0700252 // Currently storing "lastBound" objects on per-CB basis
253 // long-term may want to create caches of "lastBound" states and could have
254 // each individual CMD_NODE referencing its own "lastBound" state
Tobin Ehlis28be0be2015-05-22 12:38:16 -0600255 VkPipeline lastBoundPipeline;
256 uint32_t lastVtxBinding;
257 DYNAMIC_STATE_NODE* lastBoundDynamicState[VK_NUM_STATE_BIND_POINT];
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600258 VkDescriptorSet lastBoundDescriptorSet;
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600259 VkPipelineLayout lastBoundPipelineLayout;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600260 VkRenderPass activeRenderPass;
Tobin Ehlis28be0be2015-05-22 12:38:16 -0600261 VkFramebuffer framebuffer;
262 vector<VkDescriptorSet> boundDescriptorSets;
Tobin Ehlis8cced212015-02-13 10:26:14 -0700263} GLOBAL_CB_NODE;
264
Tobin Ehlisa701ef02014-11-27 15:43:39 -0700265//prototypes for extension functions
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600266void drawStateDumpDotFile(char* outFileName);
Tobin Ehlisde63c532015-06-18 15:59:33 -0600267void drawStateDumpPngFile(const VkDevice device, char* outFileName);
Jeremy Hayes7ec63022015-02-26 15:59:19 -0700268void drawStateDumpCommandBufferDotFile(char* outFileName);
Tobin Ehlis266473d2014-12-16 17:34:50 -0700269// Func ptr typedefs
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600270typedef void (*DRAW_STATE_DUMP_DOT_FILE)(char*);
271typedef void (*DRAW_STATE_DUMP_PNG_FILE)(char*);
Jeremy Hayes7ec63022015-02-26 15:59:19 -0700272typedef void (*DRAW_STATE_DUMP_COMMAND_BUFFER_DOT_FILE)(char*);