blob: 63e814f2f0846356f152ba407d9f211b6dba4956 [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 */
Tobin Ehlis2d1d9702015-07-03 09:42:57 -060024#include "vk_layer.h"
Tobin Ehlis63bb9482015-03-17 16:24:32 -060025#include <vector>
Tobin Ehlis92f12cd2015-07-08 17:08:02 -060026#include "layer_common.h"
Tobin Ehlis63bb9482015-03-17 16:24:32 -060027
28using namespace std;
29
Tobin Ehlise79df942014-11-18 16:38:08 -070030// Draw State ERROR codes
31typedef enum _DRAW_STATE_ERROR
32{
Tobin Ehlis84c521c2015-01-19 08:42:29 -070033 DRAWSTATE_NONE, // Used for INFO & other non-error messages
Tobin Ehlis41415bb2015-01-22 10:45:21 -070034 DRAWSTATE_INTERNAL_ERROR, // Error with DrawState internal data structures
Tobin Ehlis84c521c2015-01-19 08:42:29 -070035 DRAWSTATE_NO_PIPELINE_BOUND, // Unable to identify a bound pipeline
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -060036 DRAWSTATE_INVALID_POOL, // Invalid DS pool
Tobin Ehlis83ebbef2015-02-10 15:35:23 -070037 DRAWSTATE_INVALID_SET, // Invalid DS
Tobin Ehlis41415bb2015-01-22 10:45:21 -070038 DRAWSTATE_INVALID_LAYOUT, // Invalid DS layout
Tobin Ehlisde63c532015-06-18 15:59:33 -060039 DRAWSTATE_INVALID_PIPELINE, // Invalid Pipeline handle referenced
40 DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, // Attempt to create a pipeline with invalid state
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
Tobin Ehlis41415bb2015-01-22 10:45:21 -070045 DRAWSTATE_OUT_OF_MEMORY, // malloc failed
46 DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, // Type in layout vs. update are not the same
Tobin Ehlis83ebbef2015-02-10 15:35:23 -070047 DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, // Descriptors set for update out of bounds for corresponding layout section
Tobin Ehlis8733adc2015-02-23 16:09:58 -070048 DRAWSTATE_INVALID_UPDATE_INDEX, // Index of requested update is invalid for specified descriptors set
Tobin Ehlis2464b882015-04-01 08:40:34 -060049 DRAWSTATE_INVALID_UPDATE_STRUCT, // Struct in DS Update tree is of invalid type
Tobin Ehlis28be0be2015-05-22 12:38:16 -060050 DRAWSTATE_NUM_SAMPLES_MISMATCH, // Number of samples in bound PSO does not match number in FB of current RenderPass
51 DRAWSTATE_NO_END_CMD_BUFFER, // Must call vkEndCommandBuffer() before QueueSubmit on that cmdBuffer
Tobin Ehlise42007c2015-06-19 13:00:59 -060052 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 -060053 DRAWSTATE_VIEWPORT_NOT_BOUND, // Draw submitted with no viewport state object bound
54 DRAWSTATE_RASTER_NOT_BOUND, // Draw submitted with no raster state object bound
55 DRAWSTATE_COLOR_BLEND_NOT_BOUND, // Draw submitted with no color blend state object bound when color write enabled
56 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 -060057 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 -060058 DRAWSTATE_PIPELINE_LAYOUT_MISMATCH, // Draw submitted PSO Pipeline layout that doesn't match layout from BindDescriptorSets
Tobin Ehlis8b6c2352015-06-23 16:13:03 -060059 DRAWSTATE_INVALID_RENDERPASS, // Use of a NULL or otherwise invalid RenderPass object
Tobin Ehlis451efca2015-06-23 11:22:55 -060060 DRAWSTATE_INVALID_RENDERPASS_CMD, // Invalid cmd submitted while a RenderPass is active
61 DRAWSTATE_NO_ACTIVE_RENDERPASS, // Rendering cmd submitted without an active RenderPass
Tobin Ehlise4076782015-06-24 15:53:07 -060062 DRAWSTATE_DESCRIPTOR_SET_NOT_UPDATED, // DescriptorSet bound but it was never updated. This is a warning code.
Tobin Ehlis8cd650e2015-07-01 16:46:13 -060063 DRAWSTATE_CLEAR_CMD_BEFORE_DRAW, // Clear cmd issued before any Draw in CmdBuffer, should use RenderPass Ops instead
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -060064 DRAWSTATE_BEGIN_CB_INVALID_STATE, // Primary/Secondary CB created with mismatched FB/RP information
Tobin Ehlisde63c532015-06-18 15:59:33 -060065 DRAWSTATE_INVALID_EXTENSION,
Tobin Ehlise79df942014-11-18 16:38:08 -070066} DRAW_STATE_ERROR;
Tobin Ehlis26092022014-11-20 09:49:17 -070067
68typedef enum _DRAW_TYPE
69{
70 DRAW = 0,
71 DRAW_INDEXED = 1,
72 DRAW_INDIRECT = 2,
73 DRAW_INDEXED_INDIRECT = 3,
74 DRAW_BEGIN_RANGE = DRAW,
75 DRAW_END_RANGE = DRAW_INDEXED_INDIRECT,
76 NUM_DRAW_TYPES = (DRAW_END_RANGE - DRAW_BEGIN_RANGE + 1),
77} DRAW_TYPE;
Tobin Ehlisa701ef02014-11-27 15:43:39 -070078
Tobin Ehlis84c521c2015-01-19 08:42:29 -070079typedef struct _SHADER_DS_MAPPING {
80 uint32_t slotCount;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060081 VkDescriptorSetLayoutCreateInfo* pShaderMappingSlot;
Tobin Ehlis84c521c2015-01-19 08:42:29 -070082} SHADER_DS_MAPPING;
83
Tobin Ehlis41415bb2015-01-22 10:45:21 -070084typedef struct _GENERIC_HEADER {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060085 VkStructureType sType;
Tobin Ehlis84c521c2015-01-19 08:42:29 -070086 const void* pNext;
Tobin Ehlis41415bb2015-01-22 10:45:21 -070087} GENERIC_HEADER;
Tobin Ehlis84c521c2015-01-19 08:42:29 -070088
89typedef struct _PIPELINE_NODE {
Tony Barboure307f582015-07-10 15:29:03 -060090 VkPipeline pipeline;
91 VkGraphicsPipelineCreateInfo graphicsPipelineCI;
92 VkPipelineVertexInputStateCreateInfo vertexInputCI;
93 VkPipelineInputAssemblyStateCreateInfo iaStateCI;
94 VkPipelineTessellationStateCreateInfo tessStateCI;
95 VkPipelineViewportStateCreateInfo vpStateCI;
96 VkPipelineRasterStateCreateInfo rsStateCI;
97 VkPipelineMultisampleStateCreateInfo msStateCI;
98 VkPipelineColorBlendStateCreateInfo cbStateCI;
99 VkPipelineDepthStencilStateCreateInfo dsStateCI;
100 VkPipelineShaderStageCreateInfo vsCI;
101 VkPipelineShaderStageCreateInfo tcsCI;
102 VkPipelineShaderStageCreateInfo tesCI;
103 VkPipelineShaderStageCreateInfo gsCI;
104 VkPipelineShaderStageCreateInfo fsCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600105 // Compute shader is include in VkComputePipelineCreateInfo
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600106 VkComputePipelineCreateInfo computePipelineCI;
Tobin Ehlis806a97a2015-06-18 11:02:59 -0600107 // Flag of which shader stages are active for this pipeline
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600108 uint32_t active_shaders;
109 VkGraphicsPipelineCreateInfo* pCreateTree; // Ptr to shadow of data in create tree
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700110 // Vtx input info (if any)
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600111 uint32_t vtxBindingCount; // number of bindings
112 VkVertexInputBindingDescription* pVertexBindingDescriptions;
113 uint32_t vtxAttributeCount; // number of attributes
114 VkVertexInputAttributeDescription* pVertexAttributeDescriptions;
115 uint32_t attachmentCount; // number of CB attachments
Tony Barboure307f582015-07-10 15:29:03 -0600116 VkPipelineColorBlendAttachmentState* pAttachments;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700117} PIPELINE_NODE;
118
119typedef struct _SAMPLER_NODE {
Tobin Ehlisa366ca22015-06-19 15:07:05 -0600120 VkSampler sampler;
121 VkSamplerCreateInfo createInfo;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700122} SAMPLER_NODE;
123
Tobin Ehlis41415bb2015-01-22 10:45:21 -0700124typedef struct _BUFFER_NODE {
Tobin Ehlisa366ca22015-06-19 15:07:05 -0600125 VkBufferView buffer;
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600126 VkBufferViewCreateInfo createInfo;
Tobin Ehlisa366ca22015-06-19 15:07:05 -0600127 VkDescriptorInfo descriptorInfo;
Tobin Ehlis41415bb2015-01-22 10:45:21 -0700128} BUFFER_NODE;
129
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 {
Tobin Ehlisa366ca22015-06-19 15:07:05 -0600133 VkDescriptorSetLayout layout;
134 VkDescriptorType* pTypes; // Dynamic array that will be created to verify descriptor types
135 VkDescriptorSetLayoutCreateInfo createInfo;
136 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 {
Tobin Ehlisa366ca22015-06-19 15:07:05 -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 Ehlisa366ca22015-06-19 15:07:05 -0600144 GENERIC_HEADER* pUpdateStructs;
Tobin Ehlis41415bb2015-01-22 10:45:21 -0700145 // Total num of descriptors in this set (count of its layout plus all prior layouts)
Tobin Ehlisa366ca22015-06-19 15:07:05 -0600146 uint32_t descriptorCount;
147 GENERIC_HEADER** ppDescriptors; // Array where each index points to update node for its slot
148 LAYOUT_NODE* pLayout; // Layout for this set
149 struct _SET_NODE* pNext;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700150} SET_NODE;
151
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600152typedef struct _POOL_NODE {
Tobin Ehlisa366ca22015-06-19 15:07:05 -0600153 VkDescriptorPool pool;
154 VkDescriptorPoolUsage poolUsage;
155 uint32_t maxSets;
156 VkDescriptorPoolCreateInfo createInfo;
157 SET_NODE* pSets; // Head of LL of sets for this Pool
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600158} 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,
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600165 CMD_BINDDYNAMICVIEWPORTSTATE,
166 CMD_BINDDYNAMICRASTERSTATE,
167 CMD_BINDDYNAMICCOLORBLENDSTATE,
168 CMD_BINDDYNAMICDEPTHSTENCILSTATE,
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600169 CMD_BINDDESCRIPTORSETS,
Tobin Ehlis8cced212015-02-13 10:26:14 -0700170 CMD_BINDINDEXBUFFER,
171 CMD_BINDVERTEXBUFFER,
172 CMD_DRAW,
173 CMD_DRAWINDEXED,
174 CMD_DRAWINDIRECT,
175 CMD_DRAWINDEXEDINDIRECT,
176 CMD_DISPATCH,
177 CMD_DISPATCHINDIRECT,
178 CMD_COPYBUFFER,
179 CMD_COPYIMAGE,
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600180 CMD_BLITIMAGE,
Tobin Ehlis8cced212015-02-13 10:26:14 -0700181 CMD_COPYBUFFERTOIMAGE,
182 CMD_COPYIMAGETOBUFFER,
183 CMD_CLONEIMAGEDATA,
184 CMD_UPDATEBUFFER,
185 CMD_FILLBUFFER,
186 CMD_CLEARCOLORIMAGE,
Tobin Ehlis8cd650e2015-07-01 16:46:13 -0600187 CMD_CLEARCOLORATTACHMENT,
188 CMD_CLEARDEPTHSTENCILIMAGE,
189 CMD_CLEARDEPTHSTENCILATTACHMENT,
Tobin Ehlis8cced212015-02-13 10:26:14 -0700190 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,
Chia-I Wuc278df82015-07-07 11:50:03 +0800203 CMD_NEXTSUBPASS,
Tobin Ehlis1dae99a2015-03-02 10:16:40 -0700204 CMD_ENDRENDERPASS,
Chia-I Wu88eaa3b2015-06-26 15:34:39 +0800205 CMD_EXECUTECOMMANDS,
Tobin Ehlis1dae99a2015-03-02 10:16:40 -0700206 CMD_DBGMARKERBEGIN,
207 CMD_DBGMARKEREND,
Tobin Ehlis8cced212015-02-13 10:26:14 -0700208} CMD_TYPE;
209// Data structure for holding sequence of cmds in cmd buffer
210typedef struct _CMD_NODE {
Tobin Ehlis8cced212015-02-13 10:26:14 -0700211 CMD_TYPE type;
212 uint64_t cmdNumber;
213} CMD_NODE;
214
215typedef enum _CB_STATE
216{
217 CB_NEW, // Newly created CB w/o any cmds
218 CB_UPDATE_ACTIVE, // BeginCB has been called on this CB
219 CB_UPDATE_COMPLETE // EndCB has been called on this CB
220} CB_STATE;
Tobin Ehlis97866202015-06-10 12:57:07 -0600221// CB Status -- used to track status of various bindings on cmd buffer objects
222typedef VkFlags CBStatusFlags;
223typedef enum _CBStatusFlagBits
224{
225 CBSTATUS_NONE = 0x00000000, // No status is set
226 CBSTATUS_VIEWPORT_BOUND = 0x00000001, // Viewport state object has been bound
227 CBSTATUS_RASTER_BOUND = 0x00000002, // Raster state object has been bound
228 CBSTATUS_COLOR_BLEND_WRITE_ENABLE = 0x00000004, // PSO w/ CB Enable set has been bound
229 CBSTATUS_COLOR_BLEND_BOUND = 0x00000008, // CB state object has been bound
230 CBSTATUS_DEPTH_STENCIL_WRITE_ENABLE = 0x00000010, // PSO w/ DS Enable set has been bound
231 CBSTATUS_DEPTH_STENCIL_BOUND = 0x00000020, // DS state object has been bound
Tobin Ehlisa366ca22015-06-19 15:07:05 -0600232 CBSTATUS_INDEX_BUFFER_BOUND = 0x00000040, // Index buffer has been bound
Tobin Ehlis97866202015-06-10 12:57:07 -0600233} CBStatusFlagBits;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600234
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600235// Cmd Buffer Wrapper Struct
Tobin Ehlis8cced212015-02-13 10:26:14 -0700236typedef struct _GLOBAL_CB_NODE {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600237 VkCmdBuffer cmdBuffer;
Cody Northropf02f9f82015-07-09 18:08:05 -0600238 VkCmdPool pool;
Tobin Ehlis28be0be2015-05-22 12:38:16 -0600239 VkFlags flags;
240 VkFence fence; // fence tracking this cmd buffer
241 uint64_t numCmds; // number of cmds in this CB
242 uint64_t drawCount[NUM_DRAW_TYPES]; // Count of each type of draw in this CB
Tobin Ehlis97866202015-06-10 12:57:07 -0600243 CB_STATE state; // Track cmd buffer update state
244 CBStatusFlags status; // Track status of various bindings on cmd buffer
Tobin Ehlis28be0be2015-05-22 12:38:16 -0600245 vector<CMD_NODE*> pCmds;
Tobin Ehlis8cced212015-02-13 10:26:14 -0700246 // Currently storing "lastBound" objects on per-CB basis
247 // long-term may want to create caches of "lastBound" states and could have
248 // each individual CMD_NODE referencing its own "lastBound" state
Tobin Ehlis28be0be2015-05-22 12:38:16 -0600249 VkPipeline lastBoundPipeline;
250 uint32_t lastVtxBinding;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600251 uint64_t lastBoundDynamicState[VK_NUM_STATE_BIND_POINT];
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600252 VkDescriptorSet lastBoundDescriptorSet;
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600253 VkPipelineLayout lastBoundPipelineLayout;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600254 VkRenderPass activeRenderPass;
Chia-I Wuc278df82015-07-07 11:50:03 +0800255 uint32_t activeSubpass;
Tobin Ehlis28be0be2015-05-22 12:38:16 -0600256 VkFramebuffer framebuffer;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -0600257 VkCmdBufferLevel level;
Tobin Ehlis28be0be2015-05-22 12:38:16 -0600258 vector<VkDescriptorSet> boundDescriptorSets;
Tobin Ehlis8cced212015-02-13 10:26:14 -0700259} GLOBAL_CB_NODE;