blob: a7b0a20276be869502310597d2379dbd275e5884 [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 Ehlis83ebbef2015-02-10 15:35:23 -070038 DRAWSTATE_INVALID_PIPELINE, // Invalid Pipeline referenced
Tobin Ehlis8cced212015-02-13 10:26:14 -070039 DRAWSTATE_INVALID_CMD_BUFFER, // Invalid CmdBuffer referenced
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060040 DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, // binding in vkCmdBindVertexData() too large for PSO's pVertexBindingDescriptions array
Tobin Ehlis84c521c2015-01-19 08:42:29 -070041 DRAWSTATE_INVALID_DYNAMIC_STATE_OBJECT, // Invalid dyn state object
42 DRAWSTATE_MISSING_DOT_PROGRAM, // No "dot" program in order to generate png image
Tobin Ehlis41415bb2015-01-22 10:45:21 -070043 DRAWSTATE_OUT_OF_MEMORY, // malloc failed
44 DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, // Type in layout vs. update are not the same
Tobin Ehlis83ebbef2015-02-10 15:35:23 -070045 DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, // Descriptors set for update out of bounds for corresponding layout section
Tobin Ehlis8733adc2015-02-23 16:09:58 -070046 DRAWSTATE_INVALID_UPDATE_INDEX, // Index of requested update is invalid for specified descriptors set
Tobin Ehlis2464b882015-04-01 08:40:34 -060047 DRAWSTATE_INVALID_UPDATE_STRUCT, // Struct in DS Update tree is of invalid type
Tobin Ehlis28be0be2015-05-22 12:38:16 -060048 DRAWSTATE_NUM_SAMPLES_MISMATCH, // Number of samples in bound PSO does not match number in FB of current RenderPass
49 DRAWSTATE_NO_END_CMD_BUFFER, // Must call vkEndCommandBuffer() before QueueSubmit on that cmdBuffer
Tobin Ehlise79df942014-11-18 16:38:08 -070050} DRAW_STATE_ERROR;
Tobin Ehlis26092022014-11-20 09:49:17 -070051
52typedef enum _DRAW_TYPE
53{
54 DRAW = 0,
55 DRAW_INDEXED = 1,
56 DRAW_INDIRECT = 2,
57 DRAW_INDEXED_INDIRECT = 3,
58 DRAW_BEGIN_RANGE = DRAW,
59 DRAW_END_RANGE = DRAW_INDEXED_INDIRECT,
60 NUM_DRAW_TYPES = (DRAW_END_RANGE - DRAW_BEGIN_RANGE + 1),
61} DRAW_TYPE;
Tobin Ehlisa701ef02014-11-27 15:43:39 -070062
Tobin Ehlis84c521c2015-01-19 08:42:29 -070063typedef struct _SHADER_DS_MAPPING {
64 uint32_t slotCount;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060065 VkDescriptorSetLayoutCreateInfo* pShaderMappingSlot;
Tobin Ehlis84c521c2015-01-19 08:42:29 -070066} SHADER_DS_MAPPING;
67
Tobin Ehlis41415bb2015-01-22 10:45:21 -070068typedef struct _GENERIC_HEADER {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060069 VkStructureType sType;
Tobin Ehlis84c521c2015-01-19 08:42:29 -070070 const void* pNext;
Tobin Ehlis41415bb2015-01-22 10:45:21 -070071} GENERIC_HEADER;
Tobin Ehlis84c521c2015-01-19 08:42:29 -070072
73typedef struct _PIPELINE_NODE {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060074 VkPipeline pipeline;
Tobin Ehliscd3109e2015-04-01 11:59:08 -060075
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060076 VkGraphicsPipelineCreateInfo graphicsPipelineCI;
77 VkPipelineVertexInputCreateInfo vertexInputCI;
78 VkPipelineIaStateCreateInfo iaStateCI;
79 VkPipelineTessStateCreateInfo tessStateCI;
80 VkPipelineVpStateCreateInfo vpStateCI;
81 VkPipelineRsStateCreateInfo rsStateCI;
82 VkPipelineMsStateCreateInfo msStateCI;
83 VkPipelineCbStateCreateInfo cbStateCI;
84 VkPipelineDsStateCreateInfo dsStateCI;
85 VkPipelineShaderStageCreateInfo vsCI;
86 VkPipelineShaderStageCreateInfo tcsCI;
87 VkPipelineShaderStageCreateInfo tesCI;
88 VkPipelineShaderStageCreateInfo gsCI;
89 VkPipelineShaderStageCreateInfo fsCI;
90 // Compute shader is include in VkComputePipelineCreateInfo
91 VkComputePipelineCreateInfo computePipelineCI;
Tobin Ehliscd3109e2015-04-01 11:59:08 -060092
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060093 VkGraphicsPipelineCreateInfo* pCreateTree; // Ptr to shadow of data in create tree
Tobin Ehlis84c521c2015-01-19 08:42:29 -070094 // Vtx input info (if any)
95 uint32_t vtxBindingCount; // number of bindings
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060096 VkVertexInputBindingDescription* pVertexBindingDescriptions;
Tobin Ehlis84c521c2015-01-19 08:42:29 -070097 uint32_t vtxAttributeCount; // number of attributes
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060098 VkVertexInputAttributeDescription* pVertexAttributeDescriptions;
Tobin Ehlis83ebbef2015-02-10 15:35:23 -070099 uint32_t attachmentCount; // number of CB attachments
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600100 VkPipelineCbAttachmentState* pAttachments;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700101} PIPELINE_NODE;
102
103typedef struct _SAMPLER_NODE {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600104 VkSampler sampler;
105 VkSamplerCreateInfo createInfo;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700106} SAMPLER_NODE;
107
Tobin Ehlis41415bb2015-01-22 10:45:21 -0700108typedef struct _IMAGE_NODE {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600109 VkImageView image;
110 VkImageViewCreateInfo createInfo;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800111 VkDescriptorInfo descriptorInfo;
Tobin Ehlis41415bb2015-01-22 10:45:21 -0700112} IMAGE_NODE;
113
114typedef struct _BUFFER_NODE {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600115 VkBufferView buffer;
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600116 VkBufferViewCreateInfo createInfo;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800117 VkDescriptorInfo descriptorInfo;
Tobin Ehlis41415bb2015-01-22 10:45:21 -0700118} BUFFER_NODE;
119
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700120typedef struct _DYNAMIC_STATE_NODE {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600121 VkDynamicStateObject stateObj;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600122 GENERIC_HEADER* pCreateInfo;
123 union {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600124 VkDynamicVpStateCreateInfo vpci;
125 VkDynamicRsStateCreateInfo rsci;
126 VkDynamicCbStateCreateInfo cbci;
127 VkDynamicDsStateCreateInfo dsci;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600128 } create_info;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700129} DYNAMIC_STATE_NODE;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700130// Descriptor Data structures
Tobin Ehlis41415bb2015-01-22 10:45:21 -0700131// Layout Node has the core layout data
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700132typedef struct _LAYOUT_NODE {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600133 VkDescriptorSetLayout layout;
134 VkDescriptorType* pTypes; // Dynamic array that will be created to verify descriptor types
135 VkDescriptorSetLayoutCreateInfo createInfo;
Tobin Ehlis83ebbef2015-02-10 15:35:23 -0700136 uint32_t startIndex; // 1st index of this layout
137 uint32_t endIndex; // last index of this layout
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700138} LAYOUT_NODE;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700139typedef struct _SET_NODE {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600140 VkDescriptorSet set;
141 VkDescriptorPool pool;
142 VkDescriptorSetUsage setUsage;
Tobin Ehlis82871a82015-02-19 09:55:18 -0700143 // Head of LL of all Update structs for this set
Tobin Ehlis41415bb2015-01-22 10:45:21 -0700144 GENERIC_HEADER* pUpdateStructs;
145 // Total num of descriptors in this set (count of its layout plus all prior layouts)
146 uint32_t descriptorCount;
Tobin Ehlis82871a82015-02-19 09:55:18 -0700147 GENERIC_HEADER** ppDescriptors; // Array where each index points to update node for its slot
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600148 LAYOUT_NODE* pLayout; // Layout for this set
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700149 struct _SET_NODE* pNext;
150} SET_NODE;
151
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600152typedef struct _POOL_NODE {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600153 VkDescriptorPool pool;
154 VkDescriptorPoolUsage poolUsage;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700155 uint32_t maxSets;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600156 VkDescriptorPoolCreateInfo createInfo;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600157 SET_NODE* pSets; // Head of LL of sets for this Pool
158} POOL_NODE;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700159
Tobin Ehlis8cced212015-02-13 10:26:14 -0700160// Cmd Buffer Tracking
161typedef enum _CMD_TYPE
162{
163 CMD_BINDPIPELINE,
164 CMD_BINDPIPELINEDELTA,
165 CMD_BINDDYNAMICSTATEOBJECT,
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600166 CMD_BINDDESCRIPTORSETS,
Tobin Ehlis8cced212015-02-13 10:26:14 -0700167 CMD_BINDINDEXBUFFER,
168 CMD_BINDVERTEXBUFFER,
169 CMD_DRAW,
170 CMD_DRAWINDEXED,
171 CMD_DRAWINDIRECT,
172 CMD_DRAWINDEXEDINDIRECT,
173 CMD_DISPATCH,
174 CMD_DISPATCHINDIRECT,
175 CMD_COPYBUFFER,
176 CMD_COPYIMAGE,
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600177 CMD_BLITIMAGE,
Tobin Ehlis8cced212015-02-13 10:26:14 -0700178 CMD_COPYBUFFERTOIMAGE,
179 CMD_COPYIMAGETOBUFFER,
180 CMD_CLONEIMAGEDATA,
181 CMD_UPDATEBUFFER,
182 CMD_FILLBUFFER,
183 CMD_CLEARCOLORIMAGE,
184 CMD_CLEARCOLORIMAGERAW,
185 CMD_CLEARDEPTHSTENCIL,
186 CMD_RESOLVEIMAGE,
187 CMD_SETEVENT,
188 CMD_RESETEVENT,
189 CMD_WAITEVENTS,
190 CMD_PIPELINEBARRIER,
191 CMD_BEGINQUERY,
192 CMD_ENDQUERY,
193 CMD_RESETQUERYPOOL,
194 CMD_WRITETIMESTAMP,
195 CMD_INITATOMICCOUNTERS,
196 CMD_LOADATOMICCOUNTERS,
197 CMD_SAVEATOMICCOUNTERS,
198 CMD_BEGINRENDERPASS,
Tobin Ehlis1dae99a2015-03-02 10:16:40 -0700199 CMD_ENDRENDERPASS,
200 CMD_DBGMARKERBEGIN,
201 CMD_DBGMARKEREND,
Tobin Ehlis8cced212015-02-13 10:26:14 -0700202} CMD_TYPE;
203// Data structure for holding sequence of cmds in cmd buffer
204typedef struct _CMD_NODE {
Tobin Ehlis8cced212015-02-13 10:26:14 -0700205 CMD_TYPE type;
206 uint64_t cmdNumber;
207} CMD_NODE;
208
209typedef enum _CB_STATE
210{
211 CB_NEW, // Newly created CB w/o any cmds
212 CB_UPDATE_ACTIVE, // BeginCB has been called on this CB
213 CB_UPDATE_COMPLETE // EndCB has been called on this CB
214} CB_STATE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600215// Cmd Buffer Wrapper Struct
Tobin Ehlis8cced212015-02-13 10:26:14 -0700216typedef struct _GLOBAL_CB_NODE {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600217 VkCmdBuffer cmdBuffer;
Tobin Ehlis28be0be2015-05-22 12:38:16 -0600218 uint32_t queueNodeIndex;
219 VkFlags flags;
220 VkFence fence; // fence tracking this cmd buffer
221 uint64_t numCmds; // number of cmds in this CB
222 uint64_t drawCount[NUM_DRAW_TYPES]; // Count of each type of draw in this CB
223 CB_STATE state; // Track if cmd buffer update status
224 vector<CMD_NODE*> pCmds;
Tobin Ehlis8cced212015-02-13 10:26:14 -0700225 // Currently storing "lastBound" objects on per-CB basis
226 // long-term may want to create caches of "lastBound" states and could have
227 // each individual CMD_NODE referencing its own "lastBound" state
Tobin Ehlis28be0be2015-05-22 12:38:16 -0600228 VkPipeline lastBoundPipeline;
229 uint32_t lastVtxBinding;
230 DYNAMIC_STATE_NODE* lastBoundDynamicState[VK_NUM_STATE_BIND_POINT];
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600231 VkDescriptorSet lastBoundDescriptorSet;
232 VkRenderPass activeRenderPass;
Tobin Ehlis28be0be2015-05-22 12:38:16 -0600233 VkFramebuffer framebuffer;
234 vector<VkDescriptorSet> boundDescriptorSets;
Tobin Ehlis8cced212015-02-13 10:26:14 -0700235} GLOBAL_CB_NODE;
236
Tobin Ehlisa701ef02014-11-27 15:43:39 -0700237//prototypes for extension functions
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600238void drawStateDumpDotFile(char* outFileName);
239void drawStateDumpPngFile(char* outFileName);
Jeremy Hayes7ec63022015-02-26 15:59:19 -0700240void drawStateDumpCommandBufferDotFile(char* outFileName);
Tobin Ehlis266473d2014-12-16 17:34:50 -0700241// Func ptr typedefs
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600242typedef void (*DRAW_STATE_DUMP_DOT_FILE)(char*);
243typedef void (*DRAW_STATE_DUMP_PNG_FILE)(char*);
Jeremy Hayes7ec63022015-02-26 15:59:19 -0700244typedef void (*DRAW_STATE_DUMP_COMMAND_BUFFER_DOT_FILE)(char*);