blob: 426bf38aed7e9da563634f2d4fffe47dfb02adc9 [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
52 DRAWSTATE_NUM_SAMPLES_MISMATCH // Number of samples in bound PSO does not match number in FB of current RenderPass
Tobin Ehlise79df942014-11-18 16:38:08 -070053} DRAW_STATE_ERROR;
Tobin Ehlis26092022014-11-20 09:49:17 -070054
55typedef enum _DRAW_TYPE
56{
57 DRAW = 0,
58 DRAW_INDEXED = 1,
59 DRAW_INDIRECT = 2,
60 DRAW_INDEXED_INDIRECT = 3,
61 DRAW_BEGIN_RANGE = DRAW,
62 DRAW_END_RANGE = DRAW_INDEXED_INDIRECT,
63 NUM_DRAW_TYPES = (DRAW_END_RANGE - DRAW_BEGIN_RANGE + 1),
64} DRAW_TYPE;
Tobin Ehlisa701ef02014-11-27 15:43:39 -070065
Tobin Ehlis84c521c2015-01-19 08:42:29 -070066typedef struct _SHADER_DS_MAPPING {
67 uint32_t slotCount;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060068 VK_DESCRIPTOR_SET_LAYOUT_CREATE_INFO* pShaderMappingSlot;
Tobin Ehlis84c521c2015-01-19 08:42:29 -070069} SHADER_DS_MAPPING;
70
Tobin Ehlis41415bb2015-01-22 10:45:21 -070071typedef struct _GENERIC_HEADER {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060072 VK_STRUCTURE_TYPE sType;
Tobin Ehlis84c521c2015-01-19 08:42:29 -070073 const void* pNext;
Tobin Ehlis41415bb2015-01-22 10:45:21 -070074} GENERIC_HEADER;
Tobin Ehlis84c521c2015-01-19 08:42:29 -070075
76typedef struct _PIPELINE_NODE {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060077 VK_PIPELINE pipeline;
Tobin Ehliscd3109e2015-04-01 11:59:08 -060078
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060079 VK_GRAPHICS_PIPELINE_CREATE_INFO graphicsPipelineCI;
80 VK_PIPELINE_VERTEX_INPUT_CREATE_INFO vertexInputCI;
81 VK_PIPELINE_IA_STATE_CREATE_INFO iaStateCI;
82 VK_PIPELINE_TESS_STATE_CREATE_INFO tessStateCI;
83 VK_PIPELINE_VP_STATE_CREATE_INFO vpStateCI;
84 VK_PIPELINE_RS_STATE_CREATE_INFO rsStateCI;
85 VK_PIPELINE_MS_STATE_CREATE_INFO msStateCI;
86 VK_PIPELINE_CB_STATE_CREATE_INFO cbStateCI;
87 VK_PIPELINE_DS_STATE_CREATE_INFO dsStateCI;
88 VK_PIPELINE_SHADER_STAGE_CREATE_INFO vsCI;
89 VK_PIPELINE_SHADER_STAGE_CREATE_INFO tcsCI;
90 VK_PIPELINE_SHADER_STAGE_CREATE_INFO tesCI;
91 VK_PIPELINE_SHADER_STAGE_CREATE_INFO gsCI;
92 VK_PIPELINE_SHADER_STAGE_CREATE_INFO fsCI;
93 // Compute shader is include in VK_COMPUTE_PIPELINE_CREATE_INFO
94 VK_COMPUTE_PIPELINE_CREATE_INFO computePipelineCI;
Tobin Ehliscd3109e2015-04-01 11:59:08 -060095
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060096 VK_GRAPHICS_PIPELINE_CREATE_INFO* pCreateTree; // Ptr to shadow of data in create tree
Tobin Ehlis84c521c2015-01-19 08:42:29 -070097 // Vtx input info (if any)
98 uint32_t vtxBindingCount; // number of bindings
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060099 VK_VERTEX_INPUT_BINDING_DESCRIPTION* pVertexBindingDescriptions;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700100 uint32_t vtxAttributeCount; // number of attributes
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600101 VK_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION* pVertexAttributeDescriptions;
Tobin Ehlis83ebbef2015-02-10 15:35:23 -0700102 uint32_t attachmentCount; // number of CB attachments
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600103 VK_PIPELINE_CB_ATTACHMENT_STATE* pAttachments;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700104} PIPELINE_NODE;
105
106typedef struct _SAMPLER_NODE {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600107 VK_SAMPLER sampler;
108 VK_SAMPLER_CREATE_INFO createInfo;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700109} SAMPLER_NODE;
110
Tobin Ehlis41415bb2015-01-22 10:45:21 -0700111typedef struct _IMAGE_NODE {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600112 VK_IMAGE_VIEW image;
113 VK_IMAGE_VIEW_CREATE_INFO createInfo;
114 VK_IMAGE_VIEW_ATTACH_INFO attachInfo;
Tobin Ehlis41415bb2015-01-22 10:45:21 -0700115} IMAGE_NODE;
116
117typedef struct _BUFFER_NODE {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600118 VK_BUFFER_VIEW buffer;
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600119 VkBufferViewCreateInfo createInfo;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600120 VK_BUFFER_VIEW_ATTACH_INFO attachInfo;
Tobin Ehlis41415bb2015-01-22 10:45:21 -0700121} BUFFER_NODE;
122
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700123typedef struct _DYNAMIC_STATE_NODE {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600124 VK_DYNAMIC_STATE_OBJECT stateObj;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600125 GENERIC_HEADER* pCreateInfo;
126 union {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600127 VK_DYNAMIC_VP_STATE_CREATE_INFO vpci;
128 VK_DYNAMIC_RS_STATE_CREATE_INFO rsci;
129 VK_DYNAMIC_CB_STATE_CREATE_INFO cbci;
130 VK_DYNAMIC_DS_STATE_CREATE_INFO dsci;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600131 } create_info;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700132} DYNAMIC_STATE_NODE;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700133// Descriptor Data structures
Tobin Ehlis41415bb2015-01-22 10:45:21 -0700134// Layout Node has the core layout data
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700135typedef struct _LAYOUT_NODE {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600136 VK_DESCRIPTOR_SET_LAYOUT layout;
137 VK_DESCRIPTOR_TYPE* pTypes; // Dynamic array that will be created to verify descriptor types
138 VK_DESCRIPTOR_SET_LAYOUT_CREATE_INFO createInfo;
Tobin Ehlis83ebbef2015-02-10 15:35:23 -0700139 uint32_t startIndex; // 1st index of this layout
140 uint32_t endIndex; // last index of this layout
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700141} LAYOUT_NODE;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700142typedef struct _SET_NODE {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600143 VK_DESCRIPTOR_SET set;
144 VK_DESCRIPTOR_POOL pool;
145 VK_DESCRIPTOR_SET_USAGE setUsage;
Tobin Ehlis82871a82015-02-19 09:55:18 -0700146 // Head of LL of all Update structs for this set
Tobin Ehlis41415bb2015-01-22 10:45:21 -0700147 GENERIC_HEADER* pUpdateStructs;
148 // Total num of descriptors in this set (count of its layout plus all prior layouts)
149 uint32_t descriptorCount;
Tobin Ehlis82871a82015-02-19 09:55:18 -0700150 GENERIC_HEADER** ppDescriptors; // Array where each index points to update node for its slot
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600151 LAYOUT_NODE* pLayout; // Layout for this set
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700152 struct _SET_NODE* pNext;
153} SET_NODE;
154
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600155typedef struct _POOL_NODE {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600156 VK_DESCRIPTOR_POOL pool;
157 VK_DESCRIPTOR_POOL_USAGE poolUsage;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700158 uint32_t maxSets;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600159 VK_DESCRIPTOR_POOL_CREATE_INFO createInfo;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600160 bool32_t updateActive; // Track if Pool is in an update block
161 SET_NODE* pSets; // Head of LL of sets for this Pool
162} POOL_NODE;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700163
Tobin Ehlis8cced212015-02-13 10:26:14 -0700164// Cmd Buffer Tracking
165typedef enum _CMD_TYPE
166{
167 CMD_BINDPIPELINE,
168 CMD_BINDPIPELINEDELTA,
169 CMD_BINDDYNAMICSTATEOBJECT,
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600170 CMD_BINDDESCRIPTORSETS,
Tobin Ehlis8cced212015-02-13 10:26:14 -0700171 CMD_BINDINDEXBUFFER,
172 CMD_BINDVERTEXBUFFER,
173 CMD_DRAW,
174 CMD_DRAWINDEXED,
175 CMD_DRAWINDIRECT,
176 CMD_DRAWINDEXEDINDIRECT,
177 CMD_DISPATCH,
178 CMD_DISPATCHINDIRECT,
179 CMD_COPYBUFFER,
180 CMD_COPYIMAGE,
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600181 CMD_BLITIMAGE,
Tobin Ehlis8cced212015-02-13 10:26:14 -0700182 CMD_COPYBUFFERTOIMAGE,
183 CMD_COPYIMAGETOBUFFER,
184 CMD_CLONEIMAGEDATA,
185 CMD_UPDATEBUFFER,
186 CMD_FILLBUFFER,
187 CMD_CLEARCOLORIMAGE,
188 CMD_CLEARCOLORIMAGERAW,
189 CMD_CLEARDEPTHSTENCIL,
190 CMD_RESOLVEIMAGE,
191 CMD_SETEVENT,
192 CMD_RESETEVENT,
193 CMD_WAITEVENTS,
194 CMD_PIPELINEBARRIER,
195 CMD_BEGINQUERY,
196 CMD_ENDQUERY,
197 CMD_RESETQUERYPOOL,
198 CMD_WRITETIMESTAMP,
199 CMD_INITATOMICCOUNTERS,
200 CMD_LOADATOMICCOUNTERS,
201 CMD_SAVEATOMICCOUNTERS,
202 CMD_BEGINRENDERPASS,
Tobin Ehlis1dae99a2015-03-02 10:16:40 -0700203 CMD_ENDRENDERPASS,
204 CMD_DBGMARKERBEGIN,
205 CMD_DBGMARKEREND,
Tobin Ehlis8cced212015-02-13 10:26:14 -0700206} CMD_TYPE;
207// Data structure for holding sequence of cmds in cmd buffer
208typedef struct _CMD_NODE {
Tobin Ehlis8cced212015-02-13 10:26:14 -0700209 CMD_TYPE type;
210 uint64_t cmdNumber;
211} CMD_NODE;
212
213typedef enum _CB_STATE
214{
215 CB_NEW, // Newly created CB w/o any cmds
216 CB_UPDATE_ACTIVE, // BeginCB has been called on this CB
217 CB_UPDATE_COMPLETE // EndCB has been called on this CB
218} CB_STATE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600219// Cmd Buffer Wrapper Struct
Tobin Ehlis8cced212015-02-13 10:26:14 -0700220typedef struct _GLOBAL_CB_NODE {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600221 VK_CMD_BUFFER cmdBuffer;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600222 uint32_t queueNodeIndex;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600223 VK_FLAGS flags;
224 VK_FENCE fence; // fence tracking this cmd buffer
Tobin Ehlis8cced212015-02-13 10:26:14 -0700225 uint64_t numCmds; // number of cmds in this CB
226 uint64_t drawCount[NUM_DRAW_TYPES]; // Count of each type of draw in this CB
227 CB_STATE state; // Track if cmd buffer update status
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600228 vector<CMD_NODE*> pCmds;
Tobin Ehlis8cced212015-02-13 10:26:14 -0700229 // Currently storing "lastBound" objects on per-CB basis
230 // long-term may want to create caches of "lastBound" states and could have
231 // each individual CMD_NODE referencing its own "lastBound" state
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600232 VK_PIPELINE lastBoundPipeline;
Tobin Ehlis8cced212015-02-13 10:26:14 -0700233 uint32_t lastVtxBinding;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600234 DYNAMIC_STATE_NODE* lastBoundDynamicState[VK_NUM_STATE_BIND_POINT];
235 VK_DESCRIPTOR_SET lastBoundDescriptorSet;
236 VK_RENDER_PASS activeRenderPass;
237 VK_FRAMEBUFFER framebuffer;
Tobin Ehlis8cced212015-02-13 10:26:14 -0700238} GLOBAL_CB_NODE;
239
Tobin Ehlisa701ef02014-11-27 15:43:39 -0700240//prototypes for extension functions
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600241void drawStateDumpDotFile(char* outFileName);
242void drawStateDumpPngFile(char* outFileName);
Jeremy Hayes7ec63022015-02-26 15:59:19 -0700243void drawStateDumpCommandBufferDotFile(char* outFileName);
Tobin Ehlis266473d2014-12-16 17:34:50 -0700244// Func ptr typedefs
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600245typedef void (*DRAW_STATE_DUMP_DOT_FILE)(char*);
246typedef void (*DRAW_STATE_DUMP_PNG_FILE)(char*);
Jeremy Hayes7ec63022015-02-26 15:59:19 -0700247typedef void (*DRAW_STATE_DUMP_COMMAND_BUFFER_DOT_FILE)(char*);