blob: ef0f9c321f168c6c0569a6ca167daf39603cbd2d [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 Ehlis7e2ad752015-12-01 09:48:58 -07004 * Copyright (C) 2015 Google, Inc.
Tobin Ehlis246ba4d2014-11-18 16:38:08 -07005 *
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.
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060023 *
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070024 * Author: Courtney Goeltzenleuchter <courtneygo@google.com>
25 * Author: Tobin Ehlis <tobine@google.com>
26 * Author: Chris Forbes <chrisf@ijw.co.nz>
Tobin Ehlis246ba4d2014-11-18 16:38:08 -070027 */
David Pinedo9316d3b2015-11-06 12:54:48 -070028#include "vulkan/vk_layer.h"
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070029#include "vulkan/vk_lunarg_debug_report.h"
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060030#include <vector>
Tobin Ehlisb212dfc2015-10-07 15:40:22 -060031#include <memory>
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060032
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070033using std::vector;
34
Tobin Ehlis246ba4d2014-11-18 16:38:08 -070035// Draw State ERROR codes
36typedef enum _DRAW_STATE_ERROR
37{
Tobin Ehlis7265e832015-01-19 08:42:29 -070038 DRAWSTATE_NONE, // Used for INFO & other non-error messages
Tobin Ehlis04178d72015-01-22 10:45:21 -070039 DRAWSTATE_INTERNAL_ERROR, // Error with DrawState internal data structures
Tobin Ehlis7265e832015-01-19 08:42:29 -070040 DRAWSTATE_NO_PIPELINE_BOUND, // Unable to identify a bound pipeline
Tobin Ehlis793ad302015-04-03 12:01:11 -060041 DRAWSTATE_INVALID_POOL, // Invalid DS pool
Tobin Ehlisa3a693e2015-02-10 15:35:23 -070042 DRAWSTATE_INVALID_SET, // Invalid DS
Tobin Ehlis04178d72015-01-22 10:45:21 -070043 DRAWSTATE_INVALID_LAYOUT, // Invalid DS layout
Michael Lentineabc5e922015-10-12 11:30:14 -050044 DRAWSTATE_INVALID_IMAGE_LAYOUT, // Invalid Image layout
Tobin Ehlis75283bf2015-06-18 15:59:33 -060045 DRAWSTATE_INVALID_PIPELINE, // Invalid Pipeline handle referenced
Tobin Ehlis559c6382015-11-05 09:52:49 -070046 DRAWSTATE_INVALID_PIPELINE_LAYOUT, // Invalid PipelineLayout
Tobin Ehlis75283bf2015-06-18 15:59:33 -060047 DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, // Attempt to create a pipeline with invalid state
Michael Lentine48930b82015-10-15 17:07:00 -050048 DRAWSTATE_INVALID_COMMAND_BUFFER, // Invalid CommandBuffer referenced
49 DRAWSTATE_INVALID_BARRIER, // Invalid Barrier
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060050 DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, // binding in vkCmdBindVertexData() too large for PSO's pVertexBindingDescriptions array
Tobin Ehlisc4c23182015-09-17 12:24:13 -060051 DRAWSTATE_VTX_INDEX_ALIGNMENT_ERROR, // binding offset in vkCmdBindIndexBuffer() out of alignment based on indexType
Tobin Ehlis12d4c6a2015-08-31 12:42:38 -060052 //DRAWSTATE_MISSING_DOT_PROGRAM, // No "dot" program in order to generate png image
Tobin Ehlis04178d72015-01-22 10:45:21 -070053 DRAWSTATE_OUT_OF_MEMORY, // malloc failed
54 DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, // Type in layout vs. update are not the same
Tobin Ehlisa1f9b642015-10-27 12:25:35 -060055 DRAWSTATE_DESCRIPTOR_STAGEFLAGS_MISMATCH, // StageFlags in layout are not the same throughout a single VkWriteDescriptorSet update
Tobin Ehlisa3a693e2015-02-10 15:35:23 -070056 DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, // Descriptors set for update out of bounds for corresponding layout section
Tobin Ehlisf93f1e32015-10-20 16:16:04 -060057 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 -060058 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 -070059 DRAWSTATE_INVALID_UPDATE_INDEX, // Index of requested update is invalid for specified descriptors set
Tobin Ehliseba312c2015-04-01 08:40:34 -060060 DRAWSTATE_INVALID_UPDATE_STRUCT, // Struct in DS Update tree is of invalid type
Tobin Ehlisa9f3d762015-05-22 12:38:16 -060061 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 +080062 DRAWSTATE_NO_END_COMMAND_BUFFER, // Must call vkEndCommandBuffer() before QueueSubmit on that commandBuffer
63 DRAWSTATE_NO_BEGIN_COMMAND_BUFFER, // Binding cmds or calling End on CB that never had vkBeginCommandBuffer() called on it
64 DRAWSTATE_COMMAND_BUFFER_SINGLE_SUBMIT_VIOLATION, // Cmd Buffer created with VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT flag is submitted multiple times
65 DRAWSTATE_INVALID_SECONDARY_COMMAND_BUFFER, // vkCmdExecuteCommands() called with a primary commandBuffer in pCommandBuffers array
Tobin Ehlis963a4042015-09-29 08:18:34 -060066 DRAWSTATE_VIEWPORT_NOT_BOUND, // Draw submitted with no viewport state bound
67 DRAWSTATE_SCISSOR_NOT_BOUND, // Draw submitted with no scissor state bound
68 DRAWSTATE_LINE_WIDTH_NOT_BOUND, // Draw submitted with no line width state bound
69 DRAWSTATE_DEPTH_BIAS_NOT_BOUND, // Draw submitted with no depth bias state bound
70 DRAWSTATE_BLEND_NOT_BOUND, // Draw submitted with no blend state bound when color write enabled
71 DRAWSTATE_DEPTH_BOUNDS_NOT_BOUND, // Draw submitted with no depth bounds state bound when depth enabled
72 DRAWSTATE_STENCIL_NOT_BOUND, // Draw submitted with no stencil state bound when stencil enabled
73 DRAWSTATE_INDEX_BUFFER_NOT_BOUND, // Draw submitted with no depth-stencil state bound when depth write enabled
Tobin Ehlis559c6382015-11-05 09:52:49 -070074 DRAWSTATE_PIPELINE_LAYOUTS_INCOMPATIBLE, // Draw submitted PSO Pipeline layout that's not compatible with layout from BindDescriptorSets
Tobin Ehlis259730a2015-06-23 16:13:03 -060075 DRAWSTATE_INVALID_RENDERPASS, // Use of a NULL or otherwise invalid RenderPass object
Tobin Ehlisd1fe4ec2015-06-23 11:22:55 -060076 DRAWSTATE_INVALID_RENDERPASS_CMD, // Invalid cmd submitted while a RenderPass is active
77 DRAWSTATE_NO_ACTIVE_RENDERPASS, // Rendering cmd submitted without an active RenderPass
Tobin Ehlis502480b2015-06-24 15:53:07 -060078 DRAWSTATE_DESCRIPTOR_SET_NOT_UPDATED, // DescriptorSet bound but it was never updated. This is a warning code.
Tobin Ehlis88452832015-12-03 09:40:56 -070079 DRAWSTATE_DESCRIPTOR_SET_NOT_BOUND, // DescriptorSet used by pipeline at draw time is not bound, or has been disturbed (which would have flagged previous warning)
Tobin Ehlisda2f0d02015-11-04 12:28:28 -070080 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 +080081 DRAWSTATE_CLEAR_CMD_BEFORE_DRAW, // Clear cmd issued before any Draw in CommandBuffer, should use RenderPass Ops instead
Tobin Ehlisac0ef842015-12-14 13:46:38 -070082 DRAWSTATE_BEGIN_CB_INVALID_STATE, // CB state at Begin call is bad. Can be Primary/Secondary CB created with mismatched FB/RP information or CB in RECORDING state
83 DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, // Attempting to call Reset (or Begin on recorded cmdBuffer) that was allocated from Pool w/o VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT bit set
Tobin Ehlise68360f2015-10-01 11:15:13 -060084 DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, // Count for viewports and scissors mismatch and/or state doesn't match count
Mark Lobodzinskif53c6e52015-10-16 13:32:24 -060085 DRAWSTATE_INVALID_IMAGE_ASPECT, // Image aspect is invalid for the current operation
Mark Lobodzinski13ec6b02015-10-16 09:17:27 -060086 DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, // Attachment reference must be present in active subpass
Tobin Ehlis75283bf2015-06-18 15:59:33 -060087 DRAWSTATE_INVALID_EXTENSION,
Tobin Ehlisa1c28562015-10-23 16:00:08 -060088 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 -060089 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 -060090 DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, // A Descriptor of *_IMAGE or *_ATTACHMENT type is being updated with an invalid or bad ImageView
91 DRAWSTATE_BUFFERVIEW_DESCRIPTOR_ERROR, // A Descriptor of *_TEXEL_BUFFER type is being updated with an invalid or bad BufferView
92 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 -070093} DRAW_STATE_ERROR;
Tobin Ehlis5742e772014-11-20 09:49:17 -070094
Mark Lobodzinski9c75c162015-12-04 10:11:56 -070095typedef enum _SHADER_CHECKER_ERROR {
96 SHADER_CHECKER_NONE,
97 SHADER_CHECKER_FS_MIXED_BROADCAST, /* FS writes broadcast output AND custom outputs */
98 SHADER_CHECKER_INTERFACE_TYPE_MISMATCH, /* Type mismatch between shader stages or shader and pipeline */
99 SHADER_CHECKER_OUTPUT_NOT_CONSUMED, /* Entry appears in output interface, but missing in input */
100 SHADER_CHECKER_INPUT_NOT_PRODUCED, /* Entry appears in input interface, but missing in output */
101 SHADER_CHECKER_NON_SPIRV_SHADER, /* Shader image is not SPIR-V */
102 SHADER_CHECKER_INCONSISTENT_SPIRV, /* General inconsistency within a SPIR-V module */
103 SHADER_CHECKER_UNKNOWN_STAGE, /* Stage is not supported by analysis */
104 SHADER_CHECKER_INCONSISTENT_VI, /* VI state contains conflicting binding or attrib descriptions */
105 SHADER_CHECKER_MISSING_DESCRIPTOR, /* Shader attempts to use a descriptor binding not declared in the layout */
106} SHADER_CHECKER_ERROR;
107
Tobin Ehlis5742e772014-11-20 09:49:17 -0700108typedef enum _DRAW_TYPE
109{
110 DRAW = 0,
111 DRAW_INDEXED = 1,
112 DRAW_INDIRECT = 2,
113 DRAW_INDEXED_INDIRECT = 3,
114 DRAW_BEGIN_RANGE = DRAW,
115 DRAW_END_RANGE = DRAW_INDEXED_INDIRECT,
116 NUM_DRAW_TYPES = (DRAW_END_RANGE - DRAW_BEGIN_RANGE + 1),
117} DRAW_TYPE;
Tobin Ehlis83562882014-11-27 15:43:39 -0700118
Tobin Ehlis7265e832015-01-19 08:42:29 -0700119typedef struct _SHADER_DS_MAPPING {
120 uint32_t slotCount;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600121 VkDescriptorSetLayoutCreateInfo* pShaderMappingSlot;
Tobin Ehlis7265e832015-01-19 08:42:29 -0700122} SHADER_DS_MAPPING;
123
Tobin Ehlis04178d72015-01-22 10:45:21 -0700124typedef struct _GENERIC_HEADER {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600125 VkStructureType sType;
Tobin Ehlis7265e832015-01-19 08:42:29 -0700126 const void* pNext;
Tobin Ehlis04178d72015-01-22 10:45:21 -0700127} GENERIC_HEADER;
Tobin Ehlis7265e832015-01-19 08:42:29 -0700128
129typedef struct _PIPELINE_NODE {
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600130 VkPipeline pipeline;
131 VkGraphicsPipelineCreateInfo graphicsPipelineCI;
132 VkPipelineVertexInputStateCreateInfo vertexInputCI;
133 VkPipelineInputAssemblyStateCreateInfo iaStateCI;
134 VkPipelineTessellationStateCreateInfo tessStateCI;
135 VkPipelineViewportStateCreateInfo vpStateCI;
Tobin Ehlis559c6382015-11-05 09:52:49 -0700136 VkPipelineRasterizationStateCreateInfo rsStateCI;
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600137 VkPipelineMultisampleStateCreateInfo msStateCI;
138 VkPipelineColorBlendStateCreateInfo cbStateCI;
139 VkPipelineDepthStencilStateCreateInfo dsStateCI;
Tobin Ehlis963a4042015-09-29 08:18:34 -0600140 VkPipelineDynamicStateCreateInfo dynStateCI;
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600141 VkPipelineShaderStageCreateInfo vsCI;
142 VkPipelineShaderStageCreateInfo tcsCI;
143 VkPipelineShaderStageCreateInfo tesCI;
144 VkPipelineShaderStageCreateInfo gsCI;
145 VkPipelineShaderStageCreateInfo fsCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600146 // Compute shader is include in VkComputePipelineCreateInfo
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600147 VkComputePipelineCreateInfo computePipelineCI;
Tobin Ehlisa85167d2015-06-18 11:02:59 -0600148 // Flag of which shader stages are active for this pipeline
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600149 uint32_t active_shaders;
Tobin Ehlis88452832015-12-03 09:40:56 -0700150 // Capture which sets are actually used by the shaders of this pipeline
151 std::set<unsigned> active_sets;
Tobin Ehlis7265e832015-01-19 08:42:29 -0700152 // Vtx input info (if any)
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600153 uint32_t vtxBindingCount; // number of bindings
154 VkVertexInputBindingDescription* pVertexBindingDescriptions;
155 uint32_t vtxAttributeCount; // number of attributes
156 VkVertexInputAttributeDescription* pVertexAttributeDescriptions;
157 uint32_t attachmentCount; // number of CB attachments
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600158 VkPipelineColorBlendAttachmentState* pAttachments;
Mark Lobodzinskic44baa52015-12-11 11:56:07 -0700159 // Default constructor
160 _PIPELINE_NODE():pipeline{},
161 graphicsPipelineCI{},
162 vertexInputCI{},
163 iaStateCI{},
164 tessStateCI{},
165 vpStateCI{},
166 rsStateCI{},
167 msStateCI{},
168 cbStateCI{},
169 dsStateCI{},
170 dynStateCI{},
171 vsCI{},
172 tcsCI{},
173 tesCI{},
174 gsCI{},
175 fsCI{},
176 computePipelineCI{},
177 active_shaders(0),
178 vtxBindingCount(0),
179 pVertexBindingDescriptions(0),
180 vtxAttributeCount(0),
181 pVertexAttributeDescriptions(0),
182 attachmentCount(0),
183 pAttachments(0)
184 {};
Tobin Ehlis7265e832015-01-19 08:42:29 -0700185} PIPELINE_NODE;
186
187typedef struct _SAMPLER_NODE {
Tobin Ehlisce132d82015-06-19 15:07:05 -0600188 VkSampler sampler;
189 VkSamplerCreateInfo createInfo;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -0600190
191 _SAMPLER_NODE(const VkSampler* ps, const VkSamplerCreateInfo* pci) : sampler(*ps), createInfo(*pci) {};
Tobin Ehlis7265e832015-01-19 08:42:29 -0700192} SAMPLER_NODE;
Michael Lentineabc5e922015-10-12 11:30:14 -0500193
194typedef struct _IMAGE_NODE {
195 VkImageLayout layout;
196} IMAGE_NODE;
197
198typedef struct _IMAGE_CMD_BUF_NODE {
199 VkImageLayout layout;
200 VkImageLayout initialLayout;
201} IMAGE_CMD_BUF_NODE;
202
Michael Lentine48930b82015-10-15 17:07:00 -0500203typedef struct _RENDER_PASS_NODE {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -0700204 VkRenderPassCreateInfo const* pCreateInfo;
Michael Lentine48930b82015-10-15 17:07:00 -0500205 std::vector<bool> hasSelfDependency;
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -0700206 vector<std::vector<VkFormat>> subpassColorFormats;
207
208 _RENDER_PASS_NODE(VkRenderPassCreateInfo const *pCreateInfo) : pCreateInfo(pCreateInfo)
209 {
210 uint32_t i;
211
212 subpassColorFormats.reserve(pCreateInfo->subpassCount);
213 for (i = 0; i < pCreateInfo->subpassCount; i++) {
214 const VkSubpassDescription *subpass = &pCreateInfo->pSubpasses[i];
215 vector<VkFormat> color_formats;
216 uint32_t j;
217
218 color_formats.reserve(subpass->colorAttachmentCount);
219 for (j = 0; j < subpass->colorAttachmentCount; j++) {
220 const uint32_t att = subpass->pColorAttachments[j].attachment;
221 const VkFormat format = pCreateInfo->pAttachments[att].format;
222
223 color_formats.push_back(pCreateInfo->pAttachments[att].format);
224 }
225
226 subpassColorFormats.push_back(color_formats);
227 }
228 }
Michael Lentine48930b82015-10-15 17:07:00 -0500229} RENDER_PASS_NODE;
230
Tobin Ehlis7265e832015-01-19 08:42:29 -0700231// Descriptor Data structures
Tobin Ehlis04178d72015-01-22 10:45:21 -0700232// Layout Node has the core layout data
Tobin Ehlis7265e832015-01-19 08:42:29 -0700233typedef struct _LAYOUT_NODE {
Tobin Ehlisce132d82015-06-19 15:07:05 -0600234 VkDescriptorSetLayout layout;
Tobin Ehlisce132d82015-06-19 15:07:05 -0600235 VkDescriptorSetLayoutCreateInfo createInfo;
236 uint32_t startIndex; // 1st index of this layout
237 uint32_t endIndex; // last index of this layout
Tobin Ehlisda2f0d02015-11-04 12:28:28 -0700238 uint32_t dynamicDescriptorCount; // Total count of dynamic descriptors used by this layout
Tobin Ehlis644ff042015-10-20 10:11:55 -0600239 vector<VkDescriptorType> descriptorTypes; // Type per descriptor in this layout to verify correct updates
Tobin Ehlisa1f9b642015-10-27 12:25:35 -0600240 vector<VkShaderStageFlags> stageFlags; // stageFlags per descriptor in this layout to verify correct updates
Chia-I Wud46e6ae2015-10-31 00:31:16 +0800241 unordered_set<uint32_t> bindings;
Mark Lobodzinski2bf36f02015-11-17 12:42:57 -0700242 // Default constructor
Mark Lobodzinskic44baa52015-12-11 11:56:07 -0700243 _LAYOUT_NODE():layout{},
244 createInfo{},
245 startIndex(0),
246 endIndex(0),
247 dynamicDescriptorCount(0)
248 {};
Tobin Ehlis7265e832015-01-19 08:42:29 -0700249} LAYOUT_NODE;
Mark Lobodzinski2bf36f02015-11-17 12:42:57 -0700250
Tobin Ehlis644ff042015-10-20 10:11:55 -0600251// Store layouts and pushconstants for PipelineLayout
252struct PIPELINE_LAYOUT_NODE {
253 vector<VkDescriptorSetLayout> descriptorSetLayouts;
254 vector<VkPushConstantRange> pushConstantRanges;
255};
256
Tobin Ehlis7265e832015-01-19 08:42:29 -0700257typedef struct _SET_NODE {
Tobin Ehlisce132d82015-06-19 15:07:05 -0600258 VkDescriptorSet set;
259 VkDescriptorPool pool;
Tobin Ehlis481ec712015-02-19 09:55:18 -0700260 // Head of LL of all Update structs for this set
Tobin Ehlisce132d82015-06-19 15:07:05 -0600261 GENERIC_HEADER* pUpdateStructs;
Tobin Ehlis04178d72015-01-22 10:45:21 -0700262 // Total num of descriptors in this set (count of its layout plus all prior layouts)
Tobin Ehlisce132d82015-06-19 15:07:05 -0600263 uint32_t descriptorCount;
264 GENERIC_HEADER** ppDescriptors; // Array where each index points to update node for its slot
265 LAYOUT_NODE* pLayout; // Layout for this set
266 struct _SET_NODE* pNext;
Tobin Ehlis7265e832015-01-19 08:42:29 -0700267} SET_NODE;
268
Mark Lobodzinski39298632015-11-18 08:38:27 -0700269typedef struct _DESCRIPTOR_POOL_NODE {
Tobin Ehlisce132d82015-06-19 15:07:05 -0600270 VkDescriptorPool pool;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -0600271 uint32_t maxSets;
Tobin Ehlisce132d82015-06-19 15:07:05 -0600272 VkDescriptorPoolCreateInfo createInfo;
273 SET_NODE* pSets; // Head of LL of sets for this Pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -0600274 vector<uint32_t> maxDescriptorTypeCount; // max # of descriptors of each type in this pool
275 vector<uint32_t> availableDescriptorTypeCount; // available # of descriptors of each type in this pool
276
Mark Lobodzinski39298632015-11-18 08:38:27 -0700277 _DESCRIPTOR_POOL_NODE(const VkDescriptorPool pool, const VkDescriptorPoolCreateInfo* pCreateInfo) :
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -0600278 pool(pool), createInfo(*pCreateInfo), maxSets(pCreateInfo->maxSets), pSets(NULL),
Tobin Ehlisf93f1e32015-10-20 16:16:04 -0600279 maxDescriptorTypeCount(VK_DESCRIPTOR_TYPE_END_RANGE), availableDescriptorTypeCount(VK_DESCRIPTOR_TYPE_END_RANGE)
280 {
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800281 if (createInfo.poolSizeCount) { // Shadow type struct from ptr into local struct
282 size_t poolSizeCountSize = createInfo.poolSizeCount * sizeof(VkDescriptorPoolSize);
283 createInfo.pPoolSizes = new VkDescriptorPoolSize[poolSizeCountSize];
284 memcpy((void*)createInfo.pPoolSizes, pCreateInfo->pPoolSizes, poolSizeCountSize);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -0600285 // Now set max counts for each descriptor type based on count of that type times maxSets
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -0700286 uint32_t i=0;
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800287 for (i=0; i<createInfo.poolSizeCount; ++i) {
288 uint32_t typeIndex = static_cast<uint32_t>(createInfo.pPoolSizes[i].type);
289 uint32_t poolSizeCount = createInfo.pPoolSizes[i].descriptorCount;
290 maxDescriptorTypeCount[typeIndex] += poolSizeCount;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -0600291 }
292 for (i=0; i<maxDescriptorTypeCount.size(); ++i) {
293 maxDescriptorTypeCount[i] *= createInfo.maxSets;
294 // Initially the available counts are equal to the max counts
295 availableDescriptorTypeCount[i] = maxDescriptorTypeCount[i];
296 }
297 } else {
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800298 createInfo.pPoolSizes = NULL; // Make sure this is NULL so we don't try to clean it up
Tobin Ehlisf93f1e32015-10-20 16:16:04 -0600299 }
300 }
Mark Lobodzinski39298632015-11-18 08:38:27 -0700301 ~_DESCRIPTOR_POOL_NODE() {
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800302 if (createInfo.pPoolSizes) {
303 delete[] createInfo.pPoolSizes;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -0600304 }
305 // TODO : pSets are currently freed in deletePools function which uses freeShadowUpdateTree function
306 // need to migrate that struct to smart ptrs for auto-cleanup
307 }
Mark Lobodzinski39298632015-11-18 08:38:27 -0700308} DESCRIPTOR_POOL_NODE;
Tobin Ehlis7265e832015-01-19 08:42:29 -0700309
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700310// Cmd Buffer Tracking
311typedef enum _CMD_TYPE
312{
313 CMD_BINDPIPELINE,
314 CMD_BINDPIPELINEDELTA,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600315 CMD_SETVIEWPORTSTATE,
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -0600316 CMD_SETSCISSORSTATE,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600317 CMD_SETLINEWIDTHSTATE,
318 CMD_SETDEPTHBIASSTATE,
319 CMD_SETBLENDSTATE,
320 CMD_SETDEPTHBOUNDSSTATE,
321 CMD_SETSTENCILREADMASKSTATE,
322 CMD_SETSTENCILWRITEMASKSTATE,
323 CMD_SETSTENCILREFERENCESTATE,
Tobin Ehlis793ad302015-04-03 12:01:11 -0600324 CMD_BINDDESCRIPTORSETS,
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700325 CMD_BINDINDEXBUFFER,
326 CMD_BINDVERTEXBUFFER,
327 CMD_DRAW,
328 CMD_DRAWINDEXED,
329 CMD_DRAWINDIRECT,
330 CMD_DRAWINDEXEDINDIRECT,
331 CMD_DISPATCH,
332 CMD_DISPATCHINDIRECT,
333 CMD_COPYBUFFER,
334 CMD_COPYIMAGE,
Tobin Ehlis793ad302015-04-03 12:01:11 -0600335 CMD_BLITIMAGE,
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700336 CMD_COPYBUFFERTOIMAGE,
337 CMD_COPYIMAGETOBUFFER,
338 CMD_CLONEIMAGEDATA,
339 CMD_UPDATEBUFFER,
340 CMD_FILLBUFFER,
341 CMD_CLEARCOLORIMAGE,
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -0600342 CMD_CLEARATTACHMENTS,
Tobin Ehlis53eddda2015-07-01 16:46:13 -0600343 CMD_CLEARDEPTHSTENCILIMAGE,
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700344 CMD_RESOLVEIMAGE,
345 CMD_SETEVENT,
346 CMD_RESETEVENT,
347 CMD_WAITEVENTS,
348 CMD_PIPELINEBARRIER,
349 CMD_BEGINQUERY,
350 CMD_ENDQUERY,
351 CMD_RESETQUERYPOOL,
Mark Lobodzinski5495d132015-09-30 16:19:16 -0600352 CMD_COPYQUERYPOOLRESULTS,
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700353 CMD_WRITETIMESTAMP,
354 CMD_INITATOMICCOUNTERS,
355 CMD_LOADATOMICCOUNTERS,
356 CMD_SAVEATOMICCOUNTERS,
357 CMD_BEGINRENDERPASS,
Chia-I Wu08accc62015-07-07 11:50:03 +0800358 CMD_NEXTSUBPASS,
Tobin Ehlis67449422015-03-02 10:16:40 -0700359 CMD_ENDRENDERPASS,
Chia-I Wu0b50a1c2015-06-26 15:34:39 +0800360 CMD_EXECUTECOMMANDS,
Tobin Ehlis67449422015-03-02 10:16:40 -0700361 CMD_DBGMARKERBEGIN,
362 CMD_DBGMARKEREND,
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700363} CMD_TYPE;
364// Data structure for holding sequence of cmds in cmd buffer
365typedef struct _CMD_NODE {
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700366 CMD_TYPE type;
367 uint64_t cmdNumber;
368} CMD_NODE;
369
370typedef enum _CB_STATE
371{
Tobin Ehlisac0ef842015-12-14 13:46:38 -0700372 CB_NEW, // Newly created CB w/o any cmds
373 CB_RECORDING, // BeginCB has been called on this CB
374 CB_RECORDED // EndCB has been called on this CB
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700375} CB_STATE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -0600376// CB Status -- used to track status of various bindings on cmd buffer objects
377typedef VkFlags CBStatusFlags;
378typedef enum _CBStatusFlagBits
379{
380 CBSTATUS_NONE = 0x00000000, // No status is set
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600381 CBSTATUS_VIEWPORT_SET = 0x00000001, // Viewport has been set
382 CBSTATUS_LINE_WIDTH_SET = 0x00000002, // Line width has been set
383 CBSTATUS_DEPTH_BIAS_SET = 0x00000004, // Depth bias has been set
384 CBSTATUS_COLOR_BLEND_WRITE_ENABLE = 0x00000008, // PSO w/ CB Enable set has been set
385 CBSTATUS_BLEND_SET = 0x00000010, // Blend state object has been set
386 CBSTATUS_DEPTH_WRITE_ENABLE = 0x00000020, // PSO w/ Depth Enable set has been set
387 CBSTATUS_STENCIL_TEST_ENABLE = 0x00000040, // PSO w/ Stencil Enable set has been set
388 CBSTATUS_DEPTH_BOUNDS_SET = 0x00000080, // Depth bounds state object has been set
389 CBSTATUS_STENCIL_READ_MASK_SET = 0x00000100, // Stencil read mask has been set
390 CBSTATUS_STENCIL_WRITE_MASK_SET = 0x00000200, // Stencil write mask has been set
391 CBSTATUS_STENCIL_REFERENCE_SET = 0x00000400, // Stencil reference has been set
392 CBSTATUS_INDEX_BUFFER_BOUND = 0x00000800, // Index buffer has been set
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -0600393 CBSTATUS_SCISSOR_SET = 0x00001000, // Scissor has been set
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -0600394 CBSTATUS_ALL = 0x00001FFF, // All dynamic state set
Tobin Ehlise382c5a2015-06-10 12:57:07 -0600395} CBStatusFlagBits;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600396
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600397typedef struct stencil_data {
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800398 uint32_t compareMask;
399 uint32_t writeMask;
400 uint32_t reference;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600401} CBStencilData;
402
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600403// Cmd Buffer Wrapper Struct
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700404typedef struct _GLOBAL_CB_NODE {
Michael Lentineabc5e922015-10-12 11:30:14 -0500405 VkCommandBuffer commandBuffer;
406 VkCommandBufferAllocateInfo createInfo;
407 VkCommandBufferBeginInfo beginInfo;
Tobin Ehlisa9f3d762015-05-22 12:38:16 -0600408 VkFence fence; // fence tracking this cmd buffer
409 uint64_t numCmds; // number of cmds in this CB
410 uint64_t drawCount[NUM_DRAW_TYPES]; // Count of each type of draw in this CB
Tobin Ehlise382c5a2015-06-10 12:57:07 -0600411 CB_STATE state; // Track cmd buffer update state
Tobin Ehlis59278bf2015-08-18 07:10:58 -0600412 uint64_t submitCount; // Number of times CB has been submitted
Tobin Ehlise382c5a2015-06-10 12:57:07 -0600413 CBStatusFlags status; // Track status of various bindings on cmd buffer
Tobin Ehlisa9f3d762015-05-22 12:38:16 -0600414 vector<CMD_NODE*> pCmds;
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700415 // Currently storing "lastBound" objects on per-CB basis
416 // long-term may want to create caches of "lastBound" states and could have
417 // each individual CMD_NODE referencing its own "lastBound" state
Tobin Ehlisa9f3d762015-05-22 12:38:16 -0600418 VkPipeline lastBoundPipeline;
419 uint32_t lastVtxBinding;
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -0700420 vector<VkBuffer> boundVtxBuffers;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600421 vector<VkViewport> viewports;
422 vector<VkRect2D> scissors;
423 float lineWidth;
Chia-I Wud8c946a2015-10-26 19:08:09 +0800424 float depthBiasConstantFactor;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600425 float depthBiasClamp;
Chia-I Wud8c946a2015-10-26 19:08:09 +0800426 float depthBiasSlopeFactor;
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800427 float blendConstants[4];
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600428 float minDepthBounds;
429 float maxDepthBounds;
430 CBStencilData front;
431 CBStencilData back;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600432 VkDescriptorSet lastBoundDescriptorSet;
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600433 VkPipelineLayout lastBoundPipelineLayout;
Michael Lentineabc5e922015-10-12 11:30:14 -0500434 VkRenderPassBeginInfo activeRenderPassBeginInfo;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600435 VkRenderPass activeRenderPass;
Chia-I Wu08accc62015-07-07 11:50:03 +0800436 uint32_t activeSubpass;
Tobin Ehlisa9f3d762015-05-22 12:38:16 -0600437 VkFramebuffer framebuffer;
Tobin Ehlis559c6382015-11-05 09:52:49 -0700438 vector<VkDescriptorSet> boundDescriptorSets; // Index is set# that given set is bound to
Michael Lentineabc5e922015-10-12 11:30:14 -0500439 unordered_map<VkImage, IMAGE_CMD_BUF_NODE> imageLayoutMap;
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700440} GLOBAL_CB_NODE;
Michael Lentineabc5e922015-10-12 11:30:14 -0500441
442typedef struct _SWAPCHAIN_NODE {
443 std::vector<VkImage> images;
444} SWAPCHAIN_NODE;