blob: 171ff4f9c9a61cd2f1ae0c2e016bdce24a16e8e2 [file] [log] [blame]
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -07001/* Copyright (c) 2015-2016 The Khronos Group Inc.
2 * Copyright (c) 2015-2016 Valve Corporation
3 * Copyright (c) 2015-2016 LunarG, Inc.
4 * Copyright (C) 2015-2016 Google Inc.
Tobin Ehlis246ba4d2014-11-18 16:38:08 -07005 *
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -07006 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and/or associated documentation files (the "Materials"), to
8 * deal in the Materials without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Materials, and to permit persons to whom the Materials
11 * are furnished to do so, subject to the following conditions:
Tobin Ehlis246ba4d2014-11-18 16:38:08 -070012 *
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -070013 * The above copyright notice(s) and this permission notice shall be included
14 * in all copies or substantial portions of the Materials.
Tobin Ehlis246ba4d2014-11-18 16:38:08 -070015 *
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -070016 * The Materials are Confidential Information as defined by the Khronos
17 * Membership Agreement until designated non-confidential by Khronos, at which
18 * point this condition clause shall be removed.
Tobin Ehlis246ba4d2014-11-18 16:38:08 -070019 *
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -070020 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Tobin Ehlis246ba4d2014-11-18 16:38:08 -070021 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -070022 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 *
24 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
26 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
27 * USE OR OTHER DEALINGS IN THE MATERIALS
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060028 *
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070029 * Author: Courtney Goeltzenleuchter <courtneygo@google.com>
30 * Author: Tobin Ehlis <tobine@google.com>
31 * Author: Chris Forbes <chrisf@ijw.co.nz>
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -070032 * Author: Mark Lobodzinski <mark@lunarg.com>
Tobin Ehlis246ba4d2014-11-18 16:38:08 -070033 */
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -070034
David Pinedo9316d3b2015-11-06 12:54:48 -070035#include "vulkan/vk_layer.h"
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070036#include "vulkan/vk_ext_debug_report.h"
Michael Lentine700b0aa2015-10-30 17:57:32 -070037#include <atomic>
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060038#include <vector>
Tobin Ehlisb212dfc2015-10-07 15:40:22 -060039#include <memory>
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060040
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070041using std::vector;
42
Tobin Ehlis246ba4d2014-11-18 16:38:08 -070043// Draw State ERROR codes
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -070044typedef enum _DRAW_STATE_ERROR {
45 DRAWSTATE_NONE, // Used for INFO & other non-error messages
46 DRAWSTATE_INTERNAL_ERROR, // Error with DrawState internal data structures
47 DRAWSTATE_NO_PIPELINE_BOUND, // Unable to identify a bound pipeline
48 DRAWSTATE_INVALID_POOL, // Invalid DS pool
49 DRAWSTATE_INVALID_SET, // Invalid DS
50 DRAWSTATE_INVALID_LAYOUT, // Invalid DS layout
51 DRAWSTATE_INVALID_IMAGE_LAYOUT, // Invalid Image layout
52 DRAWSTATE_INVALID_PIPELINE, // Invalid Pipeline handle referenced
53 DRAWSTATE_INVALID_PIPELINE_LAYOUT, // Invalid PipelineLayout
54 DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, // Attempt to create a pipeline
55 // with invalid state
56 DRAWSTATE_INVALID_COMMAND_BUFFER, // Invalid CommandBuffer referenced
57 DRAWSTATE_INVALID_BARRIER, // Invalid Barrier
58 DRAWSTATE_INVALID_BUFFER, // Invalid Buffer
59 DRAWSTATE_INVALID_QUERY, // Invalid Query
60 DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, // binding in vkCmdBindVertexData() too
61 // large for PSO's
62 // pVertexBindingDescriptions array
63 DRAWSTATE_VTX_INDEX_ALIGNMENT_ERROR, // binding offset in
64 // vkCmdBindIndexBuffer() out of
65 // alignment based on indexType
66 // DRAWSTATE_MISSING_DOT_PROGRAM, // No "dot" program in order
67 // to generate png image
68 DRAWSTATE_OUT_OF_MEMORY, // malloc failed
69 DRAWSTATE_INVALID_DESCRIPTOR_SET, // Descriptor Set handle is unknown
70 DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, // Type in layout vs. update are not the
71 // same
72 DRAWSTATE_DESCRIPTOR_STAGEFLAGS_MISMATCH, // StageFlags in layout are not
73 // the same throughout a single
74 // VkWriteDescriptorSet update
75 DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, // Descriptors set for update out
76 // of bounds for corresponding
77 // layout section
78 DRAWSTATE_DESCRIPTOR_POOL_EMPTY, // Attempt to allocate descriptor from a
79 // pool with no more descriptors of that
80 // type available
81 DRAWSTATE_CANT_FREE_FROM_NON_FREE_POOL, // Invalid to call
82 // vkFreeDescriptorSets on Sets
83 // allocated from a NON_FREE Pool
84 DRAWSTATE_INVALID_UPDATE_INDEX, // Index of requested update is invalid for
85 // specified descriptors set
86 DRAWSTATE_INVALID_UPDATE_STRUCT, // Struct in DS Update tree is of invalid
87 // type
88 DRAWSTATE_NUM_SAMPLES_MISMATCH, // Number of samples in bound PSO does not
89 // match number in FB of current RenderPass
90 DRAWSTATE_NO_END_COMMAND_BUFFER, // Must call vkEndCommandBuffer() before
91 // QueueSubmit on that commandBuffer
92 DRAWSTATE_NO_BEGIN_COMMAND_BUFFER, // Binding cmds or calling End on CB that
93 // never had vkBeginCommandBuffer()
94 // called on it
95 DRAWSTATE_COMMAND_BUFFER_SINGLE_SUBMIT_VIOLATION, // Cmd Buffer created with
96 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT
97 // flag is submitted
98 // multiple times
99 DRAWSTATE_INVALID_SECONDARY_COMMAND_BUFFER, // vkCmdExecuteCommands() called
100 // with a primary commandBuffer
101 // in pCommandBuffers array
102 DRAWSTATE_VIEWPORT_NOT_BOUND, // Draw submitted with no viewport state bound
103 DRAWSTATE_SCISSOR_NOT_BOUND, // Draw submitted with no scissor state bound
104 DRAWSTATE_LINE_WIDTH_NOT_BOUND, // Draw submitted with no line width state
105 // bound
106 DRAWSTATE_DEPTH_BIAS_NOT_BOUND, // Draw submitted with no depth bias state
107 // bound
108 DRAWSTATE_BLEND_NOT_BOUND, // Draw submitted with no blend state bound when
109 // color write enabled
110 DRAWSTATE_DEPTH_BOUNDS_NOT_BOUND, // Draw submitted with no depth bounds
111 // state bound when depth enabled
112 DRAWSTATE_STENCIL_NOT_BOUND, // Draw submitted with no stencil state bound
113 // when stencil enabled
114 DRAWSTATE_INDEX_BUFFER_NOT_BOUND, // Draw submitted with no depth-stencil
115 // state bound when depth write enabled
116 DRAWSTATE_PIPELINE_LAYOUTS_INCOMPATIBLE, // Draw submitted PSO Pipeline
117 // layout that's not compatible
118 // with layout from
119 // BindDescriptorSets
120 DRAWSTATE_RENDERPASS_INCOMPATIBLE, // Incompatible renderpasses between
121 // secondary cmdBuffer and primary
122 // cmdBuffer or framebuffer
123 DRAWSTATE_FRAMEBUFFER_INCOMPATIBLE, // Incompatible framebuffer between
124 // secondary cmdBuffer and active
125 // renderPass
126 DRAWSTATE_INVALID_RENDERPASS, // Use of a NULL or otherwise invalid
127 // RenderPass object
128 DRAWSTATE_INVALID_RENDERPASS_CMD, // Invalid cmd submitted while a
129 // RenderPass is active
130 DRAWSTATE_NO_ACTIVE_RENDERPASS, // Rendering cmd submitted without an active
131 // RenderPass
132 DRAWSTATE_DESCRIPTOR_SET_NOT_UPDATED, // DescriptorSet bound but it was
133 // never updated. This is a warning
134 // code.
135 DRAWSTATE_DESCRIPTOR_SET_NOT_BOUND, // DescriptorSet used by pipeline at
136 // draw time is not bound, or has been
137 // disturbed (which would have flagged
138 // previous warning)
139 DRAWSTATE_INVALID_DYNAMIC_OFFSET_COUNT, // DescriptorSets bound with
140 // different number of dynamic
141 // descriptors that were included in
142 // dynamicOffsetCount
143 DRAWSTATE_CLEAR_CMD_BEFORE_DRAW, // Clear cmd issued before any Draw in
144 // CommandBuffer, should use RenderPass Ops
145 // instead
146 DRAWSTATE_BEGIN_CB_INVALID_STATE, // CB state at Begin call is bad. Can be
147 // Primary/Secondary CB created with
148 // mismatched FB/RP information or CB in
149 // RECORDING state
150 DRAWSTATE_INVALID_CB_SIMULTANEOUS_USE, // CmdBuffer is being used in
151 // violation of
152 // VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
153 // rules (i.e. simultaneous use w/o
154 // that bit set)
155 DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, // Attempting to call Reset (or
156 // Begin on recorded cmdBuffer) that
157 // was allocated from Pool w/o
158 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT
159 // bit set
160 DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, // Count for viewports and scissors
161 // mismatch and/or state doesn't match
162 // count
163 DRAWSTATE_INVALID_IMAGE_ASPECT, // Image aspect is invalid for the current
164 // operation
165 DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, // Attachment reference must be
166 // present in active subpass
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600167 DRAWSTATE_INVALID_EXTENSION,
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700168 DRAWSTATE_SAMPLER_DESCRIPTOR_ERROR, // A Descriptor of *_SAMPLER type is
169 // being updated with an invalid or bad
170 // Sampler
171 DRAWSTATE_INCONSISTENT_IMMUTABLE_SAMPLER_UPDATE, // Descriptors of
172 // *COMBINED_IMAGE_SAMPLER
173 // type are being updated
174 // where some, but not all,
175 // of the updates use
176 // immutable samplers
177 DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, // A Descriptor of *_IMAGE or
178 // *_ATTACHMENT type is being updated
179 // with an invalid or bad ImageView
180 DRAWSTATE_BUFFERVIEW_DESCRIPTOR_ERROR, // A Descriptor of *_TEXEL_BUFFER
181 // type is being updated with an
182 // invalid or bad BufferView
183 DRAWSTATE_BUFFERINFO_DESCRIPTOR_ERROR, // A Descriptor of
184 // *_[UNIFORM|STORAGE]_BUFFER_[DYNAMIC]
185 // type is being updated with an
186 // invalid or bad BufferView
187 DRAWSTATE_DYNAMIC_OFFSET_OVERFLOW, // At draw time the dynamic offset
188 // combined with buffer offset and range
189 // oversteps size of buffer
190 DRAWSTATE_DOUBLE_DESTROY, // Destroying an object twice
191 DRAWSTATE_OBJECT_INUSE, // Destroying or modifying an object in use by a
192 // command buffer
193 DRAWSTATE_QUEUE_FORWARD_PROGRESS, // Queue cannot guarantee forward progress
194 DRAWSTATE_INVALID_UNIFORM_BUFFER_OFFSET, // Dynamic Uniform Buffer Offsets
195 // violate device limit
196 DRAWSTATE_INVALID_STORAGE_BUFFER_OFFSET, // Dynamic Storage Buffer Offsets
197 // violate device limit
Tobin Ehlis246ba4d2014-11-18 16:38:08 -0700198} DRAW_STATE_ERROR;
Tobin Ehlis5742e772014-11-20 09:49:17 -0700199
Mark Lobodzinski9c75c162015-12-04 10:11:56 -0700200typedef enum _SHADER_CHECKER_ERROR {
201 SHADER_CHECKER_NONE,
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700202 SHADER_CHECKER_FS_MIXED_BROADCAST, /* FS writes broadcast output AND custom
203 outputs */
204 SHADER_CHECKER_INTERFACE_TYPE_MISMATCH, /* Type mismatch between shader
205 stages or shader and pipeline */
206 SHADER_CHECKER_OUTPUT_NOT_CONSUMED, /* Entry appears in output interface,
207 but missing in input */
208 SHADER_CHECKER_INPUT_NOT_PRODUCED, /* Entry appears in input interface, but
209 missing in output */
210 SHADER_CHECKER_NON_SPIRV_SHADER, /* Shader image is not SPIR-V */
211 SHADER_CHECKER_INCONSISTENT_SPIRV, /* General inconsistency within a SPIR-V
212 module */
213 SHADER_CHECKER_UNKNOWN_STAGE, /* Stage is not supported by analysis */
214 SHADER_CHECKER_INCONSISTENT_VI, /* VI state contains conflicting binding or
215 attrib descriptions */
216 SHADER_CHECKER_MISSING_DESCRIPTOR, /* Shader attempts to use a descriptor
217 binding not declared in the layout */
Mark Lobodzinski9c75c162015-12-04 10:11:56 -0700218} SHADER_CHECKER_ERROR;
219
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700220typedef enum _DRAW_TYPE {
221 DRAW = 0,
222 DRAW_INDEXED = 1,
223 DRAW_INDIRECT = 2,
Tobin Ehlis5742e772014-11-20 09:49:17 -0700224 DRAW_INDEXED_INDIRECT = 3,
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700225 DRAW_BEGIN_RANGE = DRAW,
226 DRAW_END_RANGE = DRAW_INDEXED_INDIRECT,
227 NUM_DRAW_TYPES = (DRAW_END_RANGE - DRAW_BEGIN_RANGE + 1),
Tobin Ehlis5742e772014-11-20 09:49:17 -0700228} DRAW_TYPE;
Tobin Ehlis83562882014-11-27 15:43:39 -0700229
Tobin Ehlis7265e832015-01-19 08:42:29 -0700230typedef struct _SHADER_DS_MAPPING {
231 uint32_t slotCount;
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700232 VkDescriptorSetLayoutCreateInfo *pShaderMappingSlot;
Tobin Ehlis7265e832015-01-19 08:42:29 -0700233} SHADER_DS_MAPPING;
234
Tobin Ehlis04178d72015-01-22 10:45:21 -0700235typedef struct _GENERIC_HEADER {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600236 VkStructureType sType;
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700237 const void *pNext;
Tobin Ehlis04178d72015-01-22 10:45:21 -0700238} GENERIC_HEADER;
Tobin Ehlis7265e832015-01-19 08:42:29 -0700239
240typedef struct _PIPELINE_NODE {
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700241 VkPipeline pipeline;
242 VkGraphicsPipelineCreateInfo graphicsPipelineCI;
243 VkPipelineVertexInputStateCreateInfo vertexInputCI;
244 VkPipelineInputAssemblyStateCreateInfo iaStateCI;
245 VkPipelineTessellationStateCreateInfo tessStateCI;
246 VkPipelineViewportStateCreateInfo vpStateCI;
247 VkPipelineRasterizationStateCreateInfo rsStateCI;
248 VkPipelineMultisampleStateCreateInfo msStateCI;
249 VkPipelineColorBlendStateCreateInfo cbStateCI;
250 VkPipelineDepthStencilStateCreateInfo dsStateCI;
251 VkPipelineDynamicStateCreateInfo dynStateCI;
252 VkPipelineShaderStageCreateInfo vsCI;
253 VkPipelineShaderStageCreateInfo tcsCI;
254 VkPipelineShaderStageCreateInfo tesCI;
255 VkPipelineShaderStageCreateInfo gsCI;
256 VkPipelineShaderStageCreateInfo fsCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600257 // Compute shader is include in VkComputePipelineCreateInfo
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700258 VkComputePipelineCreateInfo computePipelineCI;
Tobin Ehlisa85167d2015-06-18 11:02:59 -0600259 // Flag of which shader stages are active for this pipeline
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700260 uint32_t active_shaders;
Tobin Ehlis88452832015-12-03 09:40:56 -0700261 // Capture which sets are actually used by the shaders of this pipeline
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700262 std::set<unsigned> active_sets;
Tobin Ehlis7265e832015-01-19 08:42:29 -0700263 // Vtx input info (if any)
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700264 uint32_t vtxBindingCount; // number of bindings
265 VkVertexInputBindingDescription *pVertexBindingDescriptions;
266 uint32_t vtxAttributeCount; // number of attributes
267 VkVertexInputAttributeDescription *pVertexAttributeDescriptions;
268 uint32_t attachmentCount; // number of CB attachments
269 VkPipelineColorBlendAttachmentState *pAttachments;
Mark Lobodzinskic44baa52015-12-11 11:56:07 -0700270 // Default constructor
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700271 _PIPELINE_NODE()
272 : pipeline{}, graphicsPipelineCI{}, vertexInputCI{}, iaStateCI{},
273 tessStateCI{}, vpStateCI{}, rsStateCI{}, msStateCI{}, cbStateCI{},
274 dsStateCI{}, dynStateCI{}, vsCI{}, tcsCI{}, tesCI{}, gsCI{}, fsCI{},
275 computePipelineCI{}, active_shaders(0), vtxBindingCount(0),
276 pVertexBindingDescriptions(0), vtxAttributeCount(0),
277 pVertexAttributeDescriptions(0), attachmentCount(0),
278 pAttachments(0){};
Tobin Ehlis7265e832015-01-19 08:42:29 -0700279} PIPELINE_NODE;
280
Michael Lentine700b0aa2015-10-30 17:57:32 -0700281class BASE_NODE {
282 public:
283 std::atomic_int in_use;
284};
285
Tobin Ehlis7265e832015-01-19 08:42:29 -0700286typedef struct _SAMPLER_NODE {
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700287 VkSampler sampler;
Tobin Ehlisce132d82015-06-19 15:07:05 -0600288 VkSamplerCreateInfo createInfo;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -0600289
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700290 _SAMPLER_NODE(const VkSampler *ps, const VkSamplerCreateInfo *pci)
291 : sampler(*ps), createInfo(*pci){};
Tobin Ehlis7265e832015-01-19 08:42:29 -0700292} SAMPLER_NODE;
Michael Lentineabc5e922015-10-12 11:30:14 -0500293
294typedef struct _IMAGE_NODE {
295 VkImageLayout layout;
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700296 VkFormat format;
Michael Lentineabc5e922015-10-12 11:30:14 -0500297} IMAGE_NODE;
298
299typedef struct _IMAGE_CMD_BUF_NODE {
300 VkImageLayout layout;
301 VkImageLayout initialLayout;
302} IMAGE_CMD_BUF_NODE;
303
Michael Lentine700b0aa2015-10-30 17:57:32 -0700304class BUFFER_NODE : public BASE_NODE {
305 public:
306 using BASE_NODE::in_use;
307 unique_ptr<VkBufferCreateInfo> create_info;
308};
309
Tobin Ehlis651d9b02015-12-16 05:01:22 -0700310struct RENDER_PASS_NODE {
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700311 VkRenderPassCreateInfo const *pCreateInfo;
Michael Lentine48930b82015-10-15 17:07:00 -0500312 std::vector<bool> hasSelfDependency;
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -0700313 vector<std::vector<VkFormat>> subpassColorFormats;
314
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700315 RENDER_PASS_NODE(VkRenderPassCreateInfo const *pCreateInfo)
316 : pCreateInfo(pCreateInfo) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -0700317 uint32_t i;
318
319 subpassColorFormats.reserve(pCreateInfo->subpassCount);
320 for (i = 0; i < pCreateInfo->subpassCount; i++) {
321 const VkSubpassDescription *subpass = &pCreateInfo->pSubpasses[i];
322 vector<VkFormat> color_formats;
323 uint32_t j;
324
325 color_formats.reserve(subpass->colorAttachmentCount);
326 for (j = 0; j < subpass->colorAttachmentCount; j++) {
327 const uint32_t att = subpass->pColorAttachments[j].attachment;
328 const VkFormat format = pCreateInfo->pAttachments[att].format;
329
330 color_formats.push_back(pCreateInfo->pAttachments[att].format);
331 }
332
333 subpassColorFormats.push_back(color_formats);
334 }
335 }
Tobin Ehlis651d9b02015-12-16 05:01:22 -0700336};
Michael Lentine48930b82015-10-15 17:07:00 -0500337
Michael Lentine700b0aa2015-10-30 17:57:32 -0700338class FENCE_NODE : public BASE_NODE {
339 public:
340 using BASE_NODE::in_use;
Tobin Ehlisae82e7f2016-01-20 16:23:37 -0700341 VkQueue queue;
Michael Lentine700b0aa2015-10-30 17:57:32 -0700342 vector<VkCommandBuffer> cmdBuffers;
343 bool needsSignaled;
344 VkFence priorFence;
345};
346
Michael Lentineb887b0a2015-12-29 14:12:11 -0600347class EVENT_NODE : public BASE_NODE {
348 public:
349 using BASE_NODE::in_use;
350 bool needsSignaled;
351};
352
Michael Lentine700b0aa2015-10-30 17:57:32 -0700353class QUEUE_NODE {
354 public:
355 VkDevice device;
356 VkFence priorFence;
357 vector<VkCommandBuffer> untrackedCmdBuffers;
Michael Lentineb887b0a2015-12-29 14:12:11 -0600358 unordered_set<VkCommandBuffer> inFlightCmdBuffers;
Michael Lentine700b0aa2015-10-30 17:57:32 -0700359};
360
Tobin Ehlis7265e832015-01-19 08:42:29 -0700361// Descriptor Data structures
Tobin Ehlis04178d72015-01-22 10:45:21 -0700362// Layout Node has the core layout data
Tobin Ehlis7265e832015-01-19 08:42:29 -0700363typedef struct _LAYOUT_NODE {
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700364 VkDescriptorSetLayout layout;
Tobin Ehlisce132d82015-06-19 15:07:05 -0600365 VkDescriptorSetLayoutCreateInfo createInfo;
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700366 uint32_t startIndex; // 1st index of this layout
367 uint32_t endIndex; // last index of this layout
368 uint32_t dynamicDescriptorCount; // Total count of dynamic descriptors used
369 // by this layout
370 vector<VkDescriptorType> descriptorTypes; // Type per descriptor in this
371 // layout to verify correct
372 // updates
373 vector<VkShaderStageFlags> stageFlags; // stageFlags per descriptor in this
374 // layout to verify correct updates
375 unordered_set<uint32_t> bindings;
Mark Lobodzinski2bf36f02015-11-17 12:42:57 -0700376 // Default constructor
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700377 _LAYOUT_NODE()
378 : layout{}, createInfo{}, startIndex(0), endIndex(0),
379 dynamicDescriptorCount(0){};
Tobin Ehlis7265e832015-01-19 08:42:29 -0700380} LAYOUT_NODE;
Mark Lobodzinski2bf36f02015-11-17 12:42:57 -0700381
Tobin Ehlis644ff042015-10-20 10:11:55 -0600382// Store layouts and pushconstants for PipelineLayout
383struct PIPELINE_LAYOUT_NODE {
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700384 vector<VkDescriptorSetLayout> descriptorSetLayouts;
385 vector<VkPushConstantRange> pushConstantRanges;
Tobin Ehlis644ff042015-10-20 10:11:55 -0600386};
387
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -0700388class SET_NODE : public BASE_NODE {
389 public:
390 using BASE_NODE::in_use;
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700391 VkDescriptorSet set;
392 VkDescriptorPool pool;
Tobin Ehlis481ec712015-02-19 09:55:18 -0700393 // Head of LL of all Update structs for this set
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700394 GENERIC_HEADER *pUpdateStructs;
395 // Total num of descriptors in this set (count of its layout plus all prior
396 // layouts)
397 uint32_t descriptorCount;
398 GENERIC_HEADER **ppDescriptors; // Array where each index points to update
399 // node for its slot
400 LAYOUT_NODE *pLayout; // Layout for this set
401 SET_NODE *pNext;
402 unordered_set<VkCommandBuffer>
403 boundCmdBuffers; // Cmd buffers that this set has been bound to
404 SET_NODE()
405 : pUpdateStructs(NULL), ppDescriptors(NULL), pLayout(NULL),
406 pNext(NULL){};
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -0700407};
Tobin Ehlis7265e832015-01-19 08:42:29 -0700408
Mark Lobodzinski39298632015-11-18 08:38:27 -0700409typedef struct _DESCRIPTOR_POOL_NODE {
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700410 VkDescriptorPool pool;
411 uint32_t maxSets;
Tobin Ehlisce132d82015-06-19 15:07:05 -0600412 VkDescriptorPoolCreateInfo createInfo;
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700413 SET_NODE *pSets; // Head of LL of sets for this Pool
414 vector<uint32_t> maxDescriptorTypeCount; // max # of descriptors of each
415 // type in this pool
416 vector<uint32_t> availableDescriptorTypeCount; // available # of descriptors
417 // of each type in this pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -0600418
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700419 _DESCRIPTOR_POOL_NODE(const VkDescriptorPool pool,
420 const VkDescriptorPoolCreateInfo *pCreateInfo)
421 : pool(pool), createInfo(*pCreateInfo), maxSets(pCreateInfo->maxSets),
422 pSets(NULL), maxDescriptorTypeCount(VK_DESCRIPTOR_TYPE_RANGE_SIZE),
423 availableDescriptorTypeCount(VK_DESCRIPTOR_TYPE_RANGE_SIZE) {
424 if (createInfo.poolSizeCount) { // Shadow type struct from ptr into
425 // local struct
426 size_t poolSizeCountSize =
427 createInfo.poolSizeCount * sizeof(VkDescriptorPoolSize);
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800428 createInfo.pPoolSizes = new VkDescriptorPoolSize[poolSizeCountSize];
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700429 memcpy((void *)createInfo.pPoolSizes, pCreateInfo->pPoolSizes,
430 poolSizeCountSize);
431 // Now set max counts for each descriptor type based on count of
432 // that type times maxSets
433 uint32_t i = 0;
434 for (i = 0; i < createInfo.poolSizeCount; ++i) {
435 uint32_t typeIndex =
436 static_cast<uint32_t>(createInfo.pPoolSizes[i].type);
437 uint32_t poolSizeCount =
438 createInfo.pPoolSizes[i].descriptorCount;
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800439 maxDescriptorTypeCount[typeIndex] += poolSizeCount;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -0600440 }
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700441 for (i = 0; i < maxDescriptorTypeCount.size(); ++i) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -0600442 maxDescriptorTypeCount[i] *= createInfo.maxSets;
443 // Initially the available counts are equal to the max counts
444 availableDescriptorTypeCount[i] = maxDescriptorTypeCount[i];
445 }
446 } else {
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700447 createInfo.pPoolSizes =
448 NULL; // Make sure this is NULL so we don't try to clean it up
Tobin Ehlisf93f1e32015-10-20 16:16:04 -0600449 }
450 }
Mark Lobodzinski39298632015-11-18 08:38:27 -0700451 ~_DESCRIPTOR_POOL_NODE() {
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800452 if (createInfo.pPoolSizes) {
453 delete[] createInfo.pPoolSizes;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -0600454 }
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700455 // TODO : pSets are currently freed in deletePools function which uses
456 // freeShadowUpdateTree function
Tobin Ehlisf93f1e32015-10-20 16:16:04 -0600457 // need to migrate that struct to smart ptrs for auto-cleanup
458 }
Mark Lobodzinski39298632015-11-18 08:38:27 -0700459} DESCRIPTOR_POOL_NODE;
Tobin Ehlis7265e832015-01-19 08:42:29 -0700460
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700461// Cmd Buffer Tracking
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700462typedef enum _CMD_TYPE {
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700463 CMD_BINDPIPELINE,
464 CMD_BINDPIPELINEDELTA,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600465 CMD_SETVIEWPORTSTATE,
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -0600466 CMD_SETSCISSORSTATE,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600467 CMD_SETLINEWIDTHSTATE,
468 CMD_SETDEPTHBIASSTATE,
469 CMD_SETBLENDSTATE,
470 CMD_SETDEPTHBOUNDSSTATE,
471 CMD_SETSTENCILREADMASKSTATE,
472 CMD_SETSTENCILWRITEMASKSTATE,
473 CMD_SETSTENCILREFERENCESTATE,
Tobin Ehlis793ad302015-04-03 12:01:11 -0600474 CMD_BINDDESCRIPTORSETS,
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700475 CMD_BINDINDEXBUFFER,
476 CMD_BINDVERTEXBUFFER,
477 CMD_DRAW,
478 CMD_DRAWINDEXED,
479 CMD_DRAWINDIRECT,
480 CMD_DRAWINDEXEDINDIRECT,
481 CMD_DISPATCH,
482 CMD_DISPATCHINDIRECT,
483 CMD_COPYBUFFER,
484 CMD_COPYIMAGE,
Tobin Ehlis793ad302015-04-03 12:01:11 -0600485 CMD_BLITIMAGE,
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700486 CMD_COPYBUFFERTOIMAGE,
487 CMD_COPYIMAGETOBUFFER,
488 CMD_CLONEIMAGEDATA,
489 CMD_UPDATEBUFFER,
490 CMD_FILLBUFFER,
491 CMD_CLEARCOLORIMAGE,
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -0600492 CMD_CLEARATTACHMENTS,
Tobin Ehlis53eddda2015-07-01 16:46:13 -0600493 CMD_CLEARDEPTHSTENCILIMAGE,
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700494 CMD_RESOLVEIMAGE,
495 CMD_SETEVENT,
496 CMD_RESETEVENT,
497 CMD_WAITEVENTS,
498 CMD_PIPELINEBARRIER,
499 CMD_BEGINQUERY,
500 CMD_ENDQUERY,
501 CMD_RESETQUERYPOOL,
Mark Lobodzinski5495d132015-09-30 16:19:16 -0600502 CMD_COPYQUERYPOOLRESULTS,
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700503 CMD_WRITETIMESTAMP,
504 CMD_INITATOMICCOUNTERS,
505 CMD_LOADATOMICCOUNTERS,
506 CMD_SAVEATOMICCOUNTERS,
507 CMD_BEGINRENDERPASS,
Chia-I Wu08accc62015-07-07 11:50:03 +0800508 CMD_NEXTSUBPASS,
Tobin Ehlis67449422015-03-02 10:16:40 -0700509 CMD_ENDRENDERPASS,
Chia-I Wu0b50a1c2015-06-26 15:34:39 +0800510 CMD_EXECUTECOMMANDS,
Tobin Ehlis67449422015-03-02 10:16:40 -0700511 CMD_DBGMARKERBEGIN,
512 CMD_DBGMARKEREND,
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700513} CMD_TYPE;
514// Data structure for holding sequence of cmds in cmd buffer
515typedef struct _CMD_NODE {
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700516 CMD_TYPE type;
517 uint64_t cmdNumber;
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700518} CMD_NODE;
519
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700520typedef enum _CB_STATE {
Tobin Ehlisac0ef842015-12-14 13:46:38 -0700521 CB_NEW, // Newly created CB w/o any cmds
522 CB_RECORDING, // BeginCB has been called on this CB
Tobin Ehlise6e574b2016-01-24 23:25:31 -0700523 CB_RECORDED, // EndCB has been called on this CB
524 CB_INVALID // CB had a bound descriptor set destroyed or updated
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700525} CB_STATE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -0600526// CB Status -- used to track status of various bindings on cmd buffer objects
527typedef VkFlags CBStatusFlags;
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700528typedef enum _CBStatusFlagBits {
529 CBSTATUS_NONE = 0x00000000, // No status is set
530 CBSTATUS_VIEWPORT_SET = 0x00000001, // Viewport has been set
531 CBSTATUS_LINE_WIDTH_SET = 0x00000002, // Line width has been set
532 CBSTATUS_DEPTH_BIAS_SET = 0x00000004, // Depth bias has been set
533 CBSTATUS_COLOR_BLEND_WRITE_ENABLE =
534 0x00000008, // PSO w/ CB Enable set has been set
535 CBSTATUS_BLEND_SET = 0x00000010, // Blend state object has been set
536 CBSTATUS_DEPTH_WRITE_ENABLE =
537 0x00000020, // PSO w/ Depth Enable set has been set
538 CBSTATUS_STENCIL_TEST_ENABLE =
539 0x00000040, // PSO w/ Stencil Enable set has been set
540 CBSTATUS_DEPTH_BOUNDS_SET =
541 0x00000080, // Depth bounds state object has been set
542 CBSTATUS_STENCIL_READ_MASK_SET =
543 0x00000100, // Stencil read mask has been set
544 CBSTATUS_STENCIL_WRITE_MASK_SET =
545 0x00000200, // Stencil write mask has been set
546 CBSTATUS_STENCIL_REFERENCE_SET =
547 0x00000400, // Stencil reference has been set
548 CBSTATUS_INDEX_BUFFER_BOUND = 0x00000800, // Index buffer has been set
549 CBSTATUS_SCISSOR_SET = 0x00001000, // Scissor has been set
550 CBSTATUS_ALL = 0x00001FFF, // All dynamic state set
Tobin Ehlise382c5a2015-06-10 12:57:07 -0600551} CBStatusFlagBits;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600552
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600553typedef struct stencil_data {
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700554 uint32_t compareMask;
555 uint32_t writeMask;
556 uint32_t reference;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600557} CBStencilData;
558
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700559typedef struct _DRAW_DATA { vector<VkBuffer> buffers; } DRAW_DATA;
Michael Lentine700b0aa2015-10-30 17:57:32 -0700560
Michael Lentineb887b0a2015-12-29 14:12:11 -0600561struct QueryObject {
562 VkQueryPool pool;
563 uint32_t index;
564};
565
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700566bool operator==(const QueryObject &query1, const QueryObject &query2) {
Michael Lentineb887b0a2015-12-29 14:12:11 -0600567 return (query1.pool == query2.pool && query1.index == query2.index);
568}
569
570namespace std {
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700571template <> struct hash<QueryObject> {
Michael Lentineb887b0a2015-12-29 14:12:11 -0600572 size_t operator()(QueryObject query) const throw() {
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700573 return hash<uint64_t>()((uint64_t)(query.pool)) ^
574 hash<uint32_t>()(query.index);
Michael Lentineb887b0a2015-12-29 14:12:11 -0600575 }
576};
577}
578
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600579// Cmd Buffer Wrapper Struct
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700580typedef struct _GLOBAL_CB_NODE {
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700581 VkCommandBuffer commandBuffer;
582 VkCommandBufferAllocateInfo createInfo;
583 VkCommandBufferBeginInfo beginInfo;
Tobin Ehliscd5bfd82016-01-19 13:12:52 -0700584 VkCommandBufferInheritanceInfo inheritanceInfo;
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700585 VkFence fence; // fence tracking this cmd buffer
586 VkDevice device; // device this DB belongs to
587 uint64_t numCmds; // number of cmds in this CB
588 uint64_t drawCount[NUM_DRAW_TYPES]; // Count of each type of draw in this CB
589 CB_STATE state; // Track cmd buffer update state
590 uint64_t submitCount; // Number of times CB has been submitted
591 CBStatusFlags status; // Track status of various bindings on cmd buffer
592 vector<CMD_NODE> cmds; // vector of commands bound to this command buffer
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700593 // Currently storing "lastBound" objects on per-CB basis
594 // long-term may want to create caches of "lastBound" states and could have
595 // each individual CMD_NODE referencing its own "lastBound" state
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700596 VkPipeline lastBoundPipeline;
597 uint32_t lastVtxBinding;
598 vector<VkBuffer> boundVtxBuffers;
599 vector<VkViewport> viewports;
600 vector<VkRect2D> scissors;
601 float lineWidth;
602 float depthBiasConstantFactor;
603 float depthBiasClamp;
604 float depthBiasSlopeFactor;
605 float blendConstants[4];
606 float minDepthBounds;
607 float maxDepthBounds;
608 CBStencilData front;
609 CBStencilData back;
610 VkDescriptorSet lastBoundDescriptorSet;
611 VkPipelineLayout lastBoundPipelineLayout;
612 VkRenderPassBeginInfo activeRenderPassBeginInfo;
613 VkRenderPass activeRenderPass;
614 VkSubpassContents activeSubpassContents;
615 uint32_t activeSubpass;
616 VkFramebuffer framebuffer;
Tobin Ehlise6e574b2016-01-24 23:25:31 -0700617 // Capture unique std::set of descriptorSets that are bound to this CB.
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700618 std::set<VkDescriptorSet> uniqueBoundSets;
619 // Keep running track of which sets are bound to which set# at any given
620 // time
Tobin Ehlise6e574b2016-01-24 23:25:31 -0700621 // Track descriptor sets that are destroyed or updated while bound to CB
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700622 std::set<VkDescriptorSet> destroyedSets;
623 std::set<VkDescriptorSet> updatedSets;
624 vector<VkDescriptorSet>
625 boundDescriptorSets; // Index is set# that given set is bound to
626 vector<VkEvent> waitedEvents;
627 unordered_map<QueryObject, vector<VkEvent>> waitedEventsBeforeQueryReset;
628 unordered_map<QueryObject, bool>
629 queryToStateMap; // 0 is unavailable, 1 is available
Michael Lentineabc5e922015-10-12 11:30:14 -0500630 unordered_map<VkImage, IMAGE_CMD_BUF_NODE> imageLayoutMap;
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700631 vector<DRAW_DATA> drawData;
632 DRAW_DATA currentDrawData;
633 // If cmd buffer is primary, track secondary command buffers pending
634 // execution
Tobin Ehlisf4aafc02016-01-15 13:34:44 -0700635 std::unordered_set<VkCommandBuffer> secondaryCommandBuffers;
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700636 vector<uint32_t> dynamicOffsets; // one dynamic offset per dynamic
637 // descriptor bound to this CB
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700638} GLOBAL_CB_NODE;
Michael Lentineabc5e922015-10-12 11:30:14 -0500639
640typedef struct _SWAPCHAIN_NODE {
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700641 VkSwapchainCreateInfoKHR createInfo;
642 uint32_t *pQueueFamilyIndices;
643 std::vector<VkImage> images;
644 _SWAPCHAIN_NODE(const VkSwapchainCreateInfoKHR *pCreateInfo)
645 : createInfo(*pCreateInfo), pQueueFamilyIndices(NULL) {
Tobin Ehlis75cd1c52016-01-21 10:21:04 -0700646 if (pCreateInfo->queueFamilyIndexCount) {
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700647 pQueueFamilyIndices =
648 new uint32_t[pCreateInfo->queueFamilyIndexCount];
649 memcpy(pQueueFamilyIndices, pCreateInfo->pQueueFamilyIndices,
650 pCreateInfo->queueFamilyIndexCount * sizeof(uint32_t));
Tobin Ehlis75cd1c52016-01-21 10:21:04 -0700651 createInfo.pQueueFamilyIndices = pQueueFamilyIndices;
652 }
653 }
Mark Lobodzinskib39d9e62016-02-02 17:06:29 -0700654 ~_SWAPCHAIN_NODE() {
Tobin Ehlis75cd1c52016-01-21 10:21:04 -0700655 if (pQueueFamilyIndices)
656 delete pQueueFamilyIndices;
657 }
Michael Lentineabc5e922015-10-12 11:30:14 -0500658} SWAPCHAIN_NODE;