blob: 87ff4073d44afcb17b40aa98fe0d7de841dea2da [file] [log] [blame]
Tobin Ehlis246ba4d2014-11-18 16:38:08 -07001/*
Tobin Ehlis246ba4d2014-11-18 16:38:08 -07002 *
Courtney Goeltzenleuchterfcbe16f2015-10-29 13:50:34 -06003 * Copyright (C) 2015 Valve Corporation
Tobin Ehlis246ba4d2014-11-18 16:38:08 -07004 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060022 *
23 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
24 * Author: Tobin Ehlis <tobin@lunarg.com>
Tobin Ehlis246ba4d2014-11-18 16:38:08 -070025 */
David Pinedo9316d3b2015-11-06 12:54:48 -070026#include "vulkan/vk_layer.h"
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060027#include <vector>
Tobin Ehlisb212dfc2015-10-07 15:40:22 -060028#include <memory>
David Pinedo9316d3b2015-11-06 12:54:48 -070029#include "vulkan/vk_debug_report_lunarg.h"
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060030
31using namespace std;
32
Tobin Ehlis246ba4d2014-11-18 16:38:08 -070033// Draw State ERROR codes
34typedef enum _DRAW_STATE_ERROR
35{
Tobin Ehlis7265e832015-01-19 08:42:29 -070036 DRAWSTATE_NONE, // Used for INFO & other non-error messages
Tobin Ehlis04178d72015-01-22 10:45:21 -070037 DRAWSTATE_INTERNAL_ERROR, // Error with DrawState internal data structures
Tobin Ehlis7265e832015-01-19 08:42:29 -070038 DRAWSTATE_NO_PIPELINE_BOUND, // Unable to identify a bound pipeline
Tobin Ehlis793ad302015-04-03 12:01:11 -060039 DRAWSTATE_INVALID_POOL, // Invalid DS pool
Tobin Ehlisa3a693e2015-02-10 15:35:23 -070040 DRAWSTATE_INVALID_SET, // Invalid DS
Tobin Ehlis04178d72015-01-22 10:45:21 -070041 DRAWSTATE_INVALID_LAYOUT, // Invalid DS layout
Michael Lentineabc5e922015-10-12 11:30:14 -050042 DRAWSTATE_INVALID_IMAGE_LAYOUT, // Invalid Image layout
Tobin Ehlis75283bf2015-06-18 15:59:33 -060043 DRAWSTATE_INVALID_PIPELINE, // Invalid Pipeline handle referenced
44 DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, // Attempt to create a pipeline with invalid state
Michael Lentine48930b82015-10-15 17:07:00 -050045 DRAWSTATE_INVALID_COMMAND_BUFFER, // Invalid CommandBuffer referenced
46 DRAWSTATE_INVALID_BARRIER, // Invalid Barrier
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060047 DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, // binding in vkCmdBindVertexData() too large for PSO's pVertexBindingDescriptions array
Tobin Ehlisc4c23182015-09-17 12:24:13 -060048 DRAWSTATE_VTX_INDEX_ALIGNMENT_ERROR, // binding offset in vkCmdBindIndexBuffer() out of alignment based on indexType
Tobin Ehlis12d4c6a2015-08-31 12:42:38 -060049 //DRAWSTATE_MISSING_DOT_PROGRAM, // No "dot" program in order to generate png image
Tobin Ehlis04178d72015-01-22 10:45:21 -070050 DRAWSTATE_OUT_OF_MEMORY, // malloc failed
51 DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, // Type in layout vs. update are not the same
Tobin Ehlisa1f9b642015-10-27 12:25:35 -060052 DRAWSTATE_DESCRIPTOR_STAGEFLAGS_MISMATCH, // StageFlags in layout are not the same throughout a single VkWriteDescriptorSet update
Tobin Ehlisa3a693e2015-02-10 15:35:23 -070053 DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, // Descriptors set for update out of bounds for corresponding layout section
Tobin Ehlisf93f1e32015-10-20 16:16:04 -060054 DRAWSTATE_DESCRIPTOR_POOL_EMPTY, // Attempt to allocate descriptor from a pool with no more descriptors of that type available
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060055 DRAWSTATE_CANT_FREE_FROM_NON_FREE_POOL, // Invalid to call vkFreeDescriptorSets on Sets allocated from a NON_FREE Pool
Tobin Ehlis297b9852015-02-23 16:09:58 -070056 DRAWSTATE_INVALID_UPDATE_INDEX, // Index of requested update is invalid for specified descriptors set
Tobin Ehliseba312c2015-04-01 08:40:34 -060057 DRAWSTATE_INVALID_UPDATE_STRUCT, // Struct in DS Update tree is of invalid type
Tobin Ehlisa9f3d762015-05-22 12:38:16 -060058 DRAWSTATE_NUM_SAMPLES_MISMATCH, // Number of samples in bound PSO does not match number in FB of current RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080059 DRAWSTATE_NO_END_COMMAND_BUFFER, // Must call vkEndCommandBuffer() before QueueSubmit on that commandBuffer
60 DRAWSTATE_NO_BEGIN_COMMAND_BUFFER, // Binding cmds or calling End on CB that never had vkBeginCommandBuffer() called on it
61 DRAWSTATE_COMMAND_BUFFER_SINGLE_SUBMIT_VIOLATION, // Cmd Buffer created with VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT flag is submitted multiple times
62 DRAWSTATE_INVALID_SECONDARY_COMMAND_BUFFER, // vkCmdExecuteCommands() called with a primary commandBuffer in pCommandBuffers array
Tobin Ehlis963a4042015-09-29 08:18:34 -060063 DRAWSTATE_VIEWPORT_NOT_BOUND, // Draw submitted with no viewport state bound
64 DRAWSTATE_SCISSOR_NOT_BOUND, // Draw submitted with no scissor state bound
65 DRAWSTATE_LINE_WIDTH_NOT_BOUND, // Draw submitted with no line width state bound
66 DRAWSTATE_DEPTH_BIAS_NOT_BOUND, // Draw submitted with no depth bias state bound
67 DRAWSTATE_BLEND_NOT_BOUND, // Draw submitted with no blend state bound when color write enabled
68 DRAWSTATE_DEPTH_BOUNDS_NOT_BOUND, // Draw submitted with no depth bounds state bound when depth enabled
69 DRAWSTATE_STENCIL_NOT_BOUND, // Draw submitted with no stencil state bound when stencil enabled
70 DRAWSTATE_INDEX_BUFFER_NOT_BOUND, // Draw submitted with no depth-stencil state bound when depth write enabled
Tobin Ehlis429b91d2015-06-22 17:20:50 -060071 DRAWSTATE_PIPELINE_LAYOUT_MISMATCH, // Draw submitted PSO Pipeline layout that doesn't match layout from BindDescriptorSets
Tobin Ehlis259730a2015-06-23 16:13:03 -060072 DRAWSTATE_INVALID_RENDERPASS, // Use of a NULL or otherwise invalid RenderPass object
Tobin Ehlisd1fe4ec2015-06-23 11:22:55 -060073 DRAWSTATE_INVALID_RENDERPASS_CMD, // Invalid cmd submitted while a RenderPass is active
74 DRAWSTATE_NO_ACTIVE_RENDERPASS, // Rendering cmd submitted without an active RenderPass
Tobin Ehlis502480b2015-06-24 15:53:07 -060075 DRAWSTATE_DESCRIPTOR_SET_NOT_UPDATED, // DescriptorSet bound but it was never updated. This is a warning code.
Tobin Ehlisda2f0d02015-11-04 12:28:28 -070076 DRAWSTATE_INVALID_DYNAMIC_OFFSET_COUNT, // DescriptorSets bound with different number of dynamic descriptors that were included in dynamicOffsetCount
Chia-I Wu3432a0c2015-10-27 18:04:07 +080077 DRAWSTATE_CLEAR_CMD_BEFORE_DRAW, // Clear cmd issued before any Draw in CommandBuffer, should use RenderPass Ops instead
Mark Lobodzinskid9139a62015-08-04 16:24:20 -060078 DRAWSTATE_BEGIN_CB_INVALID_STATE, // Primary/Secondary CB created with mismatched FB/RP information
Tobin Ehlise68360f2015-10-01 11:15:13 -060079 DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, // Count for viewports and scissors mismatch and/or state doesn't match count
Mark Lobodzinskif53c6e52015-10-16 13:32:24 -060080 DRAWSTATE_INVALID_IMAGE_ASPECT, // Image aspect is invalid for the current operation
Mark Lobodzinski13ec6b02015-10-16 09:17:27 -060081 DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, // Attachment reference must be present in active subpass
Tobin Ehlis75283bf2015-06-18 15:59:33 -060082 DRAWSTATE_INVALID_EXTENSION,
Tobin Ehlisa1c28562015-10-23 16:00:08 -060083 DRAWSTATE_SAMPLER_DESCRIPTOR_ERROR, // A Descriptor of *_SAMPLER type is being updated with an invalid or bad Sampler
Tobin Ehlisa1f9b642015-10-27 12:25:35 -060084 DRAWSTATE_INCONSISTENT_IMMUTABLE_SAMPLER_UPDATE, // Descriptors of *COMBINED_IMAGE_SAMPLER type are being updated where some, but not all, of the updates use immutable samplers
Tobin Ehlisa1c28562015-10-23 16:00:08 -060085 DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, // A Descriptor of *_IMAGE or *_ATTACHMENT type is being updated with an invalid or bad ImageView
86 DRAWSTATE_BUFFERVIEW_DESCRIPTOR_ERROR, // A Descriptor of *_TEXEL_BUFFER type is being updated with an invalid or bad BufferView
87 DRAWSTATE_BUFFERINFO_DESCRIPTOR_ERROR, // A Descriptor of *_[UNIFORM|STORAGE]_BUFFER_[DYNAMIC] type is being updated with an invalid or bad BufferView
Tobin Ehlis246ba4d2014-11-18 16:38:08 -070088} DRAW_STATE_ERROR;
Tobin Ehlis5742e772014-11-20 09:49:17 -070089
90typedef enum _DRAW_TYPE
91{
92 DRAW = 0,
93 DRAW_INDEXED = 1,
94 DRAW_INDIRECT = 2,
95 DRAW_INDEXED_INDIRECT = 3,
96 DRAW_BEGIN_RANGE = DRAW,
97 DRAW_END_RANGE = DRAW_INDEXED_INDIRECT,
98 NUM_DRAW_TYPES = (DRAW_END_RANGE - DRAW_BEGIN_RANGE + 1),
99} DRAW_TYPE;
Tobin Ehlis83562882014-11-27 15:43:39 -0700100
Tobin Ehlis7265e832015-01-19 08:42:29 -0700101typedef struct _SHADER_DS_MAPPING {
102 uint32_t slotCount;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600103 VkDescriptorSetLayoutCreateInfo* pShaderMappingSlot;
Tobin Ehlis7265e832015-01-19 08:42:29 -0700104} SHADER_DS_MAPPING;
105
Tobin Ehlis04178d72015-01-22 10:45:21 -0700106typedef struct _GENERIC_HEADER {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600107 VkStructureType sType;
Tobin Ehlis7265e832015-01-19 08:42:29 -0700108 const void* pNext;
Tobin Ehlis04178d72015-01-22 10:45:21 -0700109} GENERIC_HEADER;
Tobin Ehlis7265e832015-01-19 08:42:29 -0700110
111typedef struct _PIPELINE_NODE {
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600112 VkPipeline pipeline;
113 VkGraphicsPipelineCreateInfo graphicsPipelineCI;
114 VkPipelineVertexInputStateCreateInfo vertexInputCI;
115 VkPipelineInputAssemblyStateCreateInfo iaStateCI;
116 VkPipelineTessellationStateCreateInfo tessStateCI;
117 VkPipelineViewportStateCreateInfo vpStateCI;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800118 VkPipelineRasterizationStateCreateInfo rsStateCI;
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600119 VkPipelineMultisampleStateCreateInfo msStateCI;
120 VkPipelineColorBlendStateCreateInfo cbStateCI;
121 VkPipelineDepthStencilStateCreateInfo dsStateCI;
Tobin Ehlis963a4042015-09-29 08:18:34 -0600122 VkPipelineDynamicStateCreateInfo dynStateCI;
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600123 VkPipelineShaderStageCreateInfo vsCI;
124 VkPipelineShaderStageCreateInfo tcsCI;
125 VkPipelineShaderStageCreateInfo tesCI;
126 VkPipelineShaderStageCreateInfo gsCI;
127 VkPipelineShaderStageCreateInfo fsCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600128 // Compute shader is include in VkComputePipelineCreateInfo
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600129 VkComputePipelineCreateInfo computePipelineCI;
Tobin Ehlisa85167d2015-06-18 11:02:59 -0600130 // Flag of which shader stages are active for this pipeline
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600131 uint32_t active_shaders;
Tobin Ehlis7265e832015-01-19 08:42:29 -0700132 // Vtx input info (if any)
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600133 uint32_t vtxBindingCount; // number of bindings
134 VkVertexInputBindingDescription* pVertexBindingDescriptions;
135 uint32_t vtxAttributeCount; // number of attributes
136 VkVertexInputAttributeDescription* pVertexAttributeDescriptions;
137 uint32_t attachmentCount; // number of CB attachments
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600138 VkPipelineColorBlendAttachmentState* pAttachments;
Tobin Ehlis7265e832015-01-19 08:42:29 -0700139} PIPELINE_NODE;
140
141typedef struct _SAMPLER_NODE {
Tobin Ehlisce132d82015-06-19 15:07:05 -0600142 VkSampler sampler;
143 VkSamplerCreateInfo createInfo;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -0600144
145 _SAMPLER_NODE(const VkSampler* ps, const VkSamplerCreateInfo* pci) : sampler(*ps), createInfo(*pci) {};
Tobin Ehlis7265e832015-01-19 08:42:29 -0700146} SAMPLER_NODE;
Michael Lentineabc5e922015-10-12 11:30:14 -0500147
148typedef struct _IMAGE_NODE {
149 VkImageLayout layout;
150} IMAGE_NODE;
151
152typedef struct _IMAGE_CMD_BUF_NODE {
153 VkImageLayout layout;
154 VkImageLayout initialLayout;
155} IMAGE_CMD_BUF_NODE;
156
Michael Lentine48930b82015-10-15 17:07:00 -0500157typedef struct _RENDER_PASS_NODE {
158 VkRenderPassCreateInfo* createInfo;
159 std::vector<bool> hasSelfDependency;
160} RENDER_PASS_NODE;
161
Tobin Ehlis7265e832015-01-19 08:42:29 -0700162// Descriptor Data structures
Tobin Ehlis04178d72015-01-22 10:45:21 -0700163// Layout Node has the core layout data
Tobin Ehlis7265e832015-01-19 08:42:29 -0700164typedef struct _LAYOUT_NODE {
Tobin Ehlisce132d82015-06-19 15:07:05 -0600165 VkDescriptorSetLayout layout;
Tobin Ehlisce132d82015-06-19 15:07:05 -0600166 VkDescriptorSetLayoutCreateInfo createInfo;
167 uint32_t startIndex; // 1st index of this layout
168 uint32_t endIndex; // last index of this layout
Tobin Ehlisda2f0d02015-11-04 12:28:28 -0700169 uint32_t dynamicDescriptorCount; // Total count of dynamic descriptors used by this layout
Tobin Ehlis644ff042015-10-20 10:11:55 -0600170 vector<VkDescriptorType> descriptorTypes; // Type per descriptor in this layout to verify correct updates
Tobin Ehlisa1f9b642015-10-27 12:25:35 -0600171 vector<VkShaderStageFlags> stageFlags; // stageFlags per descriptor in this layout to verify correct updates
Chia-I Wud46e6ae2015-10-31 00:31:16 +0800172 unordered_set<uint32_t> bindings;
Mark Lobodzinski2bf36f02015-11-17 12:42:57 -0700173 // Default constructor
174 _LAYOUT_NODE():layout{},createInfo{},startIndex(0),endIndex(0),dynamicDescriptorCount(0) {};
Tobin Ehlis7265e832015-01-19 08:42:29 -0700175} LAYOUT_NODE;
Mark Lobodzinski2bf36f02015-11-17 12:42:57 -0700176
Tobin Ehlis644ff042015-10-20 10:11:55 -0600177// Store layouts and pushconstants for PipelineLayout
178struct PIPELINE_LAYOUT_NODE {
179 vector<VkDescriptorSetLayout> descriptorSetLayouts;
180 vector<VkPushConstantRange> pushConstantRanges;
181};
182
Tobin Ehlis7265e832015-01-19 08:42:29 -0700183typedef struct _SET_NODE {
Tobin Ehlisce132d82015-06-19 15:07:05 -0600184 VkDescriptorSet set;
185 VkDescriptorPool pool;
Tobin Ehlis481ec712015-02-19 09:55:18 -0700186 // Head of LL of all Update structs for this set
Tobin Ehlisce132d82015-06-19 15:07:05 -0600187 GENERIC_HEADER* pUpdateStructs;
Tobin Ehlis04178d72015-01-22 10:45:21 -0700188 // Total num of descriptors in this set (count of its layout plus all prior layouts)
Tobin Ehlisce132d82015-06-19 15:07:05 -0600189 uint32_t descriptorCount;
190 GENERIC_HEADER** ppDescriptors; // Array where each index points to update node for its slot
191 LAYOUT_NODE* pLayout; // Layout for this set
192 struct _SET_NODE* pNext;
Tobin Ehlis7265e832015-01-19 08:42:29 -0700193} SET_NODE;
194
Mark Lobodzinski39298632015-11-18 08:38:27 -0700195typedef struct _DESCRIPTOR_POOL_NODE {
Tobin Ehlisce132d82015-06-19 15:07:05 -0600196 VkDescriptorPool pool;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -0600197 uint32_t maxSets;
Tobin Ehlisce132d82015-06-19 15:07:05 -0600198 VkDescriptorPoolCreateInfo createInfo;
199 SET_NODE* pSets; // Head of LL of sets for this Pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -0600200 vector<uint32_t> maxDescriptorTypeCount; // max # of descriptors of each type in this pool
201 vector<uint32_t> availableDescriptorTypeCount; // available # of descriptors of each type in this pool
202
Mark Lobodzinski39298632015-11-18 08:38:27 -0700203 _DESCRIPTOR_POOL_NODE(const VkDescriptorPool pool, const VkDescriptorPoolCreateInfo* pCreateInfo) :
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -0600204 pool(pool), createInfo(*pCreateInfo), maxSets(pCreateInfo->maxSets), pSets(NULL),
Tobin Ehlisf93f1e32015-10-20 16:16:04 -0600205 maxDescriptorTypeCount(VK_DESCRIPTOR_TYPE_END_RANGE), availableDescriptorTypeCount(VK_DESCRIPTOR_TYPE_END_RANGE)
206 {
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800207 if (createInfo.poolSizeCount) { // Shadow type struct from ptr into local struct
208 size_t poolSizeCountSize = createInfo.poolSizeCount * sizeof(VkDescriptorPoolSize);
209 createInfo.pPoolSizes = new VkDescriptorPoolSize[poolSizeCountSize];
210 memcpy((void*)createInfo.pPoolSizes, pCreateInfo->pPoolSizes, poolSizeCountSize);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -0600211 // Now set max counts for each descriptor type based on count of that type times maxSets
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -0700212 uint32_t i=0;
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800213 for (i=0; i<createInfo.poolSizeCount; ++i) {
214 uint32_t typeIndex = static_cast<uint32_t>(createInfo.pPoolSizes[i].type);
215 uint32_t poolSizeCount = createInfo.pPoolSizes[i].descriptorCount;
216 maxDescriptorTypeCount[typeIndex] += poolSizeCount;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -0600217 }
218 for (i=0; i<maxDescriptorTypeCount.size(); ++i) {
219 maxDescriptorTypeCount[i] *= createInfo.maxSets;
220 // Initially the available counts are equal to the max counts
221 availableDescriptorTypeCount[i] = maxDescriptorTypeCount[i];
222 }
223 } else {
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800224 createInfo.pPoolSizes = NULL; // Make sure this is NULL so we don't try to clean it up
Tobin Ehlisf93f1e32015-10-20 16:16:04 -0600225 }
226 }
Mark Lobodzinski39298632015-11-18 08:38:27 -0700227 ~_DESCRIPTOR_POOL_NODE() {
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800228 if (createInfo.pPoolSizes) {
229 delete[] createInfo.pPoolSizes;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -0600230 }
231 // TODO : pSets are currently freed in deletePools function which uses freeShadowUpdateTree function
232 // need to migrate that struct to smart ptrs for auto-cleanup
233 }
Mark Lobodzinski39298632015-11-18 08:38:27 -0700234} DESCRIPTOR_POOL_NODE;
Tobin Ehlis7265e832015-01-19 08:42:29 -0700235
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700236// Cmd Buffer Tracking
237typedef enum _CMD_TYPE
238{
239 CMD_BINDPIPELINE,
240 CMD_BINDPIPELINEDELTA,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600241 CMD_SETVIEWPORTSTATE,
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -0600242 CMD_SETSCISSORSTATE,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600243 CMD_SETLINEWIDTHSTATE,
244 CMD_SETDEPTHBIASSTATE,
245 CMD_SETBLENDSTATE,
246 CMD_SETDEPTHBOUNDSSTATE,
247 CMD_SETSTENCILREADMASKSTATE,
248 CMD_SETSTENCILWRITEMASKSTATE,
249 CMD_SETSTENCILREFERENCESTATE,
Tobin Ehlis793ad302015-04-03 12:01:11 -0600250 CMD_BINDDESCRIPTORSETS,
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700251 CMD_BINDINDEXBUFFER,
252 CMD_BINDVERTEXBUFFER,
253 CMD_DRAW,
254 CMD_DRAWINDEXED,
255 CMD_DRAWINDIRECT,
256 CMD_DRAWINDEXEDINDIRECT,
257 CMD_DISPATCH,
258 CMD_DISPATCHINDIRECT,
259 CMD_COPYBUFFER,
260 CMD_COPYIMAGE,
Tobin Ehlis793ad302015-04-03 12:01:11 -0600261 CMD_BLITIMAGE,
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700262 CMD_COPYBUFFERTOIMAGE,
263 CMD_COPYIMAGETOBUFFER,
264 CMD_CLONEIMAGEDATA,
265 CMD_UPDATEBUFFER,
266 CMD_FILLBUFFER,
267 CMD_CLEARCOLORIMAGE,
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -0600268 CMD_CLEARATTACHMENTS,
Tobin Ehlis53eddda2015-07-01 16:46:13 -0600269 CMD_CLEARDEPTHSTENCILIMAGE,
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700270 CMD_RESOLVEIMAGE,
271 CMD_SETEVENT,
272 CMD_RESETEVENT,
273 CMD_WAITEVENTS,
274 CMD_PIPELINEBARRIER,
275 CMD_BEGINQUERY,
276 CMD_ENDQUERY,
277 CMD_RESETQUERYPOOL,
Mark Lobodzinski5495d132015-09-30 16:19:16 -0600278 CMD_COPYQUERYPOOLRESULTS,
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700279 CMD_WRITETIMESTAMP,
280 CMD_INITATOMICCOUNTERS,
281 CMD_LOADATOMICCOUNTERS,
282 CMD_SAVEATOMICCOUNTERS,
283 CMD_BEGINRENDERPASS,
Chia-I Wu08accc62015-07-07 11:50:03 +0800284 CMD_NEXTSUBPASS,
Tobin Ehlis67449422015-03-02 10:16:40 -0700285 CMD_ENDRENDERPASS,
Chia-I Wu0b50a1c2015-06-26 15:34:39 +0800286 CMD_EXECUTECOMMANDS,
Tobin Ehlis67449422015-03-02 10:16:40 -0700287 CMD_DBGMARKERBEGIN,
288 CMD_DBGMARKEREND,
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700289} CMD_TYPE;
290// Data structure for holding sequence of cmds in cmd buffer
291typedef struct _CMD_NODE {
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700292 CMD_TYPE type;
293 uint64_t cmdNumber;
294} CMD_NODE;
295
296typedef enum _CB_STATE
297{
298 CB_NEW, // Newly created CB w/o any cmds
299 CB_UPDATE_ACTIVE, // BeginCB has been called on this CB
300 CB_UPDATE_COMPLETE // EndCB has been called on this CB
301} CB_STATE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -0600302// CB Status -- used to track status of various bindings on cmd buffer objects
303typedef VkFlags CBStatusFlags;
304typedef enum _CBStatusFlagBits
305{
306 CBSTATUS_NONE = 0x00000000, // No status is set
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600307 CBSTATUS_VIEWPORT_SET = 0x00000001, // Viewport has been set
308 CBSTATUS_LINE_WIDTH_SET = 0x00000002, // Line width has been set
309 CBSTATUS_DEPTH_BIAS_SET = 0x00000004, // Depth bias has been set
310 CBSTATUS_COLOR_BLEND_WRITE_ENABLE = 0x00000008, // PSO w/ CB Enable set has been set
311 CBSTATUS_BLEND_SET = 0x00000010, // Blend state object has been set
312 CBSTATUS_DEPTH_WRITE_ENABLE = 0x00000020, // PSO w/ Depth Enable set has been set
313 CBSTATUS_STENCIL_TEST_ENABLE = 0x00000040, // PSO w/ Stencil Enable set has been set
314 CBSTATUS_DEPTH_BOUNDS_SET = 0x00000080, // Depth bounds state object has been set
315 CBSTATUS_STENCIL_READ_MASK_SET = 0x00000100, // Stencil read mask has been set
316 CBSTATUS_STENCIL_WRITE_MASK_SET = 0x00000200, // Stencil write mask has been set
317 CBSTATUS_STENCIL_REFERENCE_SET = 0x00000400, // Stencil reference has been set
318 CBSTATUS_INDEX_BUFFER_BOUND = 0x00000800, // Index buffer has been set
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -0600319 CBSTATUS_SCISSOR_SET = 0x00001000, // Scissor has been set
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -0600320 CBSTATUS_ALL = 0x00001FFF, // All dynamic state set
Tobin Ehlise382c5a2015-06-10 12:57:07 -0600321} CBStatusFlagBits;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600322
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600323typedef struct stencil_data {
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800324 uint32_t compareMask;
325 uint32_t writeMask;
326 uint32_t reference;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600327} CBStencilData;
328
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600329// Cmd Buffer Wrapper Struct
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700330typedef struct _GLOBAL_CB_NODE {
Michael Lentineabc5e922015-10-12 11:30:14 -0500331 VkCommandBuffer commandBuffer;
332 VkCommandBufferAllocateInfo createInfo;
333 VkCommandBufferBeginInfo beginInfo;
Tobin Ehlisa9f3d762015-05-22 12:38:16 -0600334 VkFence fence; // fence tracking this cmd buffer
335 uint64_t numCmds; // number of cmds in this CB
336 uint64_t drawCount[NUM_DRAW_TYPES]; // Count of each type of draw in this CB
Tobin Ehlise382c5a2015-06-10 12:57:07 -0600337 CB_STATE state; // Track cmd buffer update state
Tobin Ehlis59278bf2015-08-18 07:10:58 -0600338 uint64_t submitCount; // Number of times CB has been submitted
Tobin Ehlise382c5a2015-06-10 12:57:07 -0600339 CBStatusFlags status; // Track status of various bindings on cmd buffer
Tobin Ehlisa9f3d762015-05-22 12:38:16 -0600340 vector<CMD_NODE*> pCmds;
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700341 // Currently storing "lastBound" objects on per-CB basis
342 // long-term may want to create caches of "lastBound" states and could have
343 // each individual CMD_NODE referencing its own "lastBound" state
Tobin Ehlisa9f3d762015-05-22 12:38:16 -0600344 VkPipeline lastBoundPipeline;
345 uint32_t lastVtxBinding;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600346 vector<VkViewport> viewports;
347 vector<VkRect2D> scissors;
348 float lineWidth;
Chia-I Wud8c946a2015-10-26 19:08:09 +0800349 float depthBiasConstantFactor;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600350 float depthBiasClamp;
Chia-I Wud8c946a2015-10-26 19:08:09 +0800351 float depthBiasSlopeFactor;
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800352 float blendConstants[4];
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600353 float minDepthBounds;
354 float maxDepthBounds;
355 CBStencilData front;
356 CBStencilData back;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600357 VkDescriptorSet lastBoundDescriptorSet;
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600358 VkPipelineLayout lastBoundPipelineLayout;
Michael Lentineabc5e922015-10-12 11:30:14 -0500359 VkRenderPassBeginInfo activeRenderPassBeginInfo;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600360 VkRenderPass activeRenderPass;
Chia-I Wu08accc62015-07-07 11:50:03 +0800361 uint32_t activeSubpass;
Tobin Ehlisa9f3d762015-05-22 12:38:16 -0600362 VkFramebuffer framebuffer;
Michael Lentineabc5e922015-10-12 11:30:14 -0500363 VkCommandBufferLevel level;
Tobin Ehlisa9f3d762015-05-22 12:38:16 -0600364 vector<VkDescriptorSet> boundDescriptorSets;
Michael Lentineabc5e922015-10-12 11:30:14 -0500365 unordered_map<VkImage, IMAGE_CMD_BUF_NODE> imageLayoutMap;
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700366} GLOBAL_CB_NODE;
Michael Lentineabc5e922015-10-12 11:30:14 -0500367
368typedef struct _SWAPCHAIN_NODE {
369 std::vector<VkImage> images;
370} SWAPCHAIN_NODE;