blob: 1ab4228682f8447ebf8e05cb0ed518c90cda1594 [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"
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070029#include "vulkan/vk_ext_debug_report.h"
Michael Lentine700b0aa2015-10-30 17:57:32 -070030#include <atomic>
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060031#include <vector>
Tobin Ehlisb212dfc2015-10-07 15:40:22 -060032#include <memory>
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060033
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070034using std::vector;
35
Tobin Ehlis246ba4d2014-11-18 16:38:08 -070036// Draw State ERROR codes
37typedef enum _DRAW_STATE_ERROR
38{
Tobin Ehlis7265e832015-01-19 08:42:29 -070039 DRAWSTATE_NONE, // Used for INFO & other non-error messages
Tobin Ehlis04178d72015-01-22 10:45:21 -070040 DRAWSTATE_INTERNAL_ERROR, // Error with DrawState internal data structures
Tobin Ehlis7265e832015-01-19 08:42:29 -070041 DRAWSTATE_NO_PIPELINE_BOUND, // Unable to identify a bound pipeline
Tobin Ehlis793ad302015-04-03 12:01:11 -060042 DRAWSTATE_INVALID_POOL, // Invalid DS pool
Tobin Ehlisa3a693e2015-02-10 15:35:23 -070043 DRAWSTATE_INVALID_SET, // Invalid DS
Tobin Ehlis04178d72015-01-22 10:45:21 -070044 DRAWSTATE_INVALID_LAYOUT, // Invalid DS layout
Michael Lentineabc5e922015-10-12 11:30:14 -050045 DRAWSTATE_INVALID_IMAGE_LAYOUT, // Invalid Image layout
Tobin Ehlis75283bf2015-06-18 15:59:33 -060046 DRAWSTATE_INVALID_PIPELINE, // Invalid Pipeline handle referenced
Tobin Ehlis559c6382015-11-05 09:52:49 -070047 DRAWSTATE_INVALID_PIPELINE_LAYOUT, // Invalid PipelineLayout
Tobin Ehlis75283bf2015-06-18 15:59:33 -060048 DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, // Attempt to create a pipeline with invalid state
Michael Lentine48930b82015-10-15 17:07:00 -050049 DRAWSTATE_INVALID_COMMAND_BUFFER, // Invalid CommandBuffer referenced
50 DRAWSTATE_INVALID_BARRIER, // Invalid Barrier
Michael Lentine700b0aa2015-10-30 17:57:32 -070051 DRAWSTATE_INVALID_BUFFER, // Invalid Buffer
Michael Lentineb887b0a2015-12-29 14:12:11 -060052 DRAWSTATE_INVALID_QUERY, // Invalid Query
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060053 DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, // binding in vkCmdBindVertexData() too large for PSO's pVertexBindingDescriptions array
Tobin Ehlisc4c23182015-09-17 12:24:13 -060054 DRAWSTATE_VTX_INDEX_ALIGNMENT_ERROR, // binding offset in vkCmdBindIndexBuffer() out of alignment based on indexType
Tobin Ehlis12d4c6a2015-08-31 12:42:38 -060055 //DRAWSTATE_MISSING_DOT_PROGRAM, // No "dot" program in order to generate png image
Tobin Ehlis04178d72015-01-22 10:45:21 -070056 DRAWSTATE_OUT_OF_MEMORY, // malloc failed
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -070057 DRAWSTATE_INVALID_DESCRIPTOR_SET, // Descriptor Set handle is unknown
Tobin Ehlis04178d72015-01-22 10:45:21 -070058 DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, // Type in layout vs. update are not the same
Tobin Ehlisa1f9b642015-10-27 12:25:35 -060059 DRAWSTATE_DESCRIPTOR_STAGEFLAGS_MISMATCH, // StageFlags in layout are not the same throughout a single VkWriteDescriptorSet update
Tobin Ehlisa3a693e2015-02-10 15:35:23 -070060 DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, // Descriptors set for update out of bounds for corresponding layout section
Tobin Ehlisf93f1e32015-10-20 16:16:04 -060061 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 -060062 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 -070063 DRAWSTATE_INVALID_UPDATE_INDEX, // Index of requested update is invalid for specified descriptors set
Tobin Ehliseba312c2015-04-01 08:40:34 -060064 DRAWSTATE_INVALID_UPDATE_STRUCT, // Struct in DS Update tree is of invalid type
Tobin Ehlisa9f3d762015-05-22 12:38:16 -060065 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 +080066 DRAWSTATE_NO_END_COMMAND_BUFFER, // Must call vkEndCommandBuffer() before QueueSubmit on that commandBuffer
67 DRAWSTATE_NO_BEGIN_COMMAND_BUFFER, // Binding cmds or calling End on CB that never had vkBeginCommandBuffer() called on it
68 DRAWSTATE_COMMAND_BUFFER_SINGLE_SUBMIT_VIOLATION, // Cmd Buffer created with VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT flag is submitted multiple times
69 DRAWSTATE_INVALID_SECONDARY_COMMAND_BUFFER, // vkCmdExecuteCommands() called with a primary commandBuffer in pCommandBuffers array
Tobin Ehlis963a4042015-09-29 08:18:34 -060070 DRAWSTATE_VIEWPORT_NOT_BOUND, // Draw submitted with no viewport state bound
71 DRAWSTATE_SCISSOR_NOT_BOUND, // Draw submitted with no scissor state bound
72 DRAWSTATE_LINE_WIDTH_NOT_BOUND, // Draw submitted with no line width state bound
73 DRAWSTATE_DEPTH_BIAS_NOT_BOUND, // Draw submitted with no depth bias state bound
74 DRAWSTATE_BLEND_NOT_BOUND, // Draw submitted with no blend state bound when color write enabled
75 DRAWSTATE_DEPTH_BOUNDS_NOT_BOUND, // Draw submitted with no depth bounds state bound when depth enabled
76 DRAWSTATE_STENCIL_NOT_BOUND, // Draw submitted with no stencil state bound when stencil enabled
77 DRAWSTATE_INDEX_BUFFER_NOT_BOUND, // Draw submitted with no depth-stencil state bound when depth write enabled
Tobin Ehlis559c6382015-11-05 09:52:49 -070078 DRAWSTATE_PIPELINE_LAYOUTS_INCOMPATIBLE, // Draw submitted PSO Pipeline layout that's not compatible with layout from BindDescriptorSets
Tobin Ehlis651d9b02015-12-16 05:01:22 -070079 DRAWSTATE_RENDERPASS_INCOMPATIBLE, // Incompatible renderpasses between secondary cmdBuffer and primary cmdBuffer or framebuffer
80 DRAWSTATE_FRAMEBUFFER_INCOMPATIBLE, // Incompatible framebuffer between secondary cmdBuffer and active renderPass
Tobin Ehlis259730a2015-06-23 16:13:03 -060081 DRAWSTATE_INVALID_RENDERPASS, // Use of a NULL or otherwise invalid RenderPass object
Tobin Ehlisd1fe4ec2015-06-23 11:22:55 -060082 DRAWSTATE_INVALID_RENDERPASS_CMD, // Invalid cmd submitted while a RenderPass is active
83 DRAWSTATE_NO_ACTIVE_RENDERPASS, // Rendering cmd submitted without an active RenderPass
Tobin Ehlis502480b2015-06-24 15:53:07 -060084 DRAWSTATE_DESCRIPTOR_SET_NOT_UPDATED, // DescriptorSet bound but it was never updated. This is a warning code.
Tobin Ehlis88452832015-12-03 09:40:56 -070085 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 -070086 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 +080087 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 -070088 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
89 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 -060090 DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, // Count for viewports and scissors mismatch and/or state doesn't match count
Mark Lobodzinskif53c6e52015-10-16 13:32:24 -060091 DRAWSTATE_INVALID_IMAGE_ASPECT, // Image aspect is invalid for the current operation
Mark Lobodzinski13ec6b02015-10-16 09:17:27 -060092 DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, // Attachment reference must be present in active subpass
Tobin Ehlis75283bf2015-06-18 15:59:33 -060093 DRAWSTATE_INVALID_EXTENSION,
Tobin Ehlisa1c28562015-10-23 16:00:08 -060094 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 -060095 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 -060096 DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, // A Descriptor of *_IMAGE or *_ATTACHMENT type is being updated with an invalid or bad ImageView
97 DRAWSTATE_BUFFERVIEW_DESCRIPTOR_ERROR, // A Descriptor of *_TEXEL_BUFFER type is being updated with an invalid or bad BufferView
98 DRAWSTATE_BUFFERINFO_DESCRIPTOR_ERROR, // A Descriptor of *_[UNIFORM|STORAGE]_BUFFER_[DYNAMIC] type is being updated with an invalid or bad BufferView
Tobin Ehlisf6585052015-12-17 11:48:42 -070099 DRAWSTATE_DYNAMIC_OFFSET_OVERFLOW, // At draw time the dynamic offset combined with buffer offset and range oversteps size of buffer
Michael Lentine700b0aa2015-10-30 17:57:32 -0700100 DRAWSTATE_DOUBLE_DESTROY, // Destroying an object twice
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -0700101 DRAWSTATE_OBJECT_INUSE, // Destroying or modifying an object in use by a command buffer
Michael Lentine15a47882016-01-06 10:05:48 -0600102 DRAWSTATE_QUEUE_FORWARD_PROGRESS, // Queue cannot guarantee forward progress
Mark Lobodzinski941aea92016-01-13 10:23:15 -0700103 DRAWSTATE_INVALID_UNIFORM_BUFFER_OFFSET, // Dynamic Uniform Buffer Offsets violate device limit
104 DRAWSTATE_INVALID_STORAGE_BUFFER_OFFSET, // Dynamic Storage Buffer Offsets violate device limit
Tobin Ehlis246ba4d2014-11-18 16:38:08 -0700105} DRAW_STATE_ERROR;
Tobin Ehlis5742e772014-11-20 09:49:17 -0700106
Mark Lobodzinski9c75c162015-12-04 10:11:56 -0700107typedef enum _SHADER_CHECKER_ERROR {
108 SHADER_CHECKER_NONE,
109 SHADER_CHECKER_FS_MIXED_BROADCAST, /* FS writes broadcast output AND custom outputs */
110 SHADER_CHECKER_INTERFACE_TYPE_MISMATCH, /* Type mismatch between shader stages or shader and pipeline */
111 SHADER_CHECKER_OUTPUT_NOT_CONSUMED, /* Entry appears in output interface, but missing in input */
112 SHADER_CHECKER_INPUT_NOT_PRODUCED, /* Entry appears in input interface, but missing in output */
113 SHADER_CHECKER_NON_SPIRV_SHADER, /* Shader image is not SPIR-V */
114 SHADER_CHECKER_INCONSISTENT_SPIRV, /* General inconsistency within a SPIR-V module */
115 SHADER_CHECKER_UNKNOWN_STAGE, /* Stage is not supported by analysis */
116 SHADER_CHECKER_INCONSISTENT_VI, /* VI state contains conflicting binding or attrib descriptions */
117 SHADER_CHECKER_MISSING_DESCRIPTOR, /* Shader attempts to use a descriptor binding not declared in the layout */
118} SHADER_CHECKER_ERROR;
119
Tobin Ehlis5742e772014-11-20 09:49:17 -0700120typedef enum _DRAW_TYPE
121{
122 DRAW = 0,
123 DRAW_INDEXED = 1,
124 DRAW_INDIRECT = 2,
125 DRAW_INDEXED_INDIRECT = 3,
126 DRAW_BEGIN_RANGE = DRAW,
127 DRAW_END_RANGE = DRAW_INDEXED_INDIRECT,
128 NUM_DRAW_TYPES = (DRAW_END_RANGE - DRAW_BEGIN_RANGE + 1),
129} DRAW_TYPE;
Tobin Ehlis83562882014-11-27 15:43:39 -0700130
Tobin Ehlis7265e832015-01-19 08:42:29 -0700131typedef struct _SHADER_DS_MAPPING {
132 uint32_t slotCount;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600133 VkDescriptorSetLayoutCreateInfo* pShaderMappingSlot;
Tobin Ehlis7265e832015-01-19 08:42:29 -0700134} SHADER_DS_MAPPING;
135
Tobin Ehlis04178d72015-01-22 10:45:21 -0700136typedef struct _GENERIC_HEADER {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600137 VkStructureType sType;
Tobin Ehlis7265e832015-01-19 08:42:29 -0700138 const void* pNext;
Tobin Ehlis04178d72015-01-22 10:45:21 -0700139} GENERIC_HEADER;
Tobin Ehlis7265e832015-01-19 08:42:29 -0700140
141typedef struct _PIPELINE_NODE {
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600142 VkPipeline pipeline;
143 VkGraphicsPipelineCreateInfo graphicsPipelineCI;
144 VkPipelineVertexInputStateCreateInfo vertexInputCI;
145 VkPipelineInputAssemblyStateCreateInfo iaStateCI;
146 VkPipelineTessellationStateCreateInfo tessStateCI;
147 VkPipelineViewportStateCreateInfo vpStateCI;
Tobin Ehlis559c6382015-11-05 09:52:49 -0700148 VkPipelineRasterizationStateCreateInfo rsStateCI;
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600149 VkPipelineMultisampleStateCreateInfo msStateCI;
150 VkPipelineColorBlendStateCreateInfo cbStateCI;
151 VkPipelineDepthStencilStateCreateInfo dsStateCI;
Tobin Ehlis963a4042015-09-29 08:18:34 -0600152 VkPipelineDynamicStateCreateInfo dynStateCI;
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600153 VkPipelineShaderStageCreateInfo vsCI;
154 VkPipelineShaderStageCreateInfo tcsCI;
155 VkPipelineShaderStageCreateInfo tesCI;
156 VkPipelineShaderStageCreateInfo gsCI;
157 VkPipelineShaderStageCreateInfo fsCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600158 // Compute shader is include in VkComputePipelineCreateInfo
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600159 VkComputePipelineCreateInfo computePipelineCI;
Tobin Ehlisa85167d2015-06-18 11:02:59 -0600160 // Flag of which shader stages are active for this pipeline
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600161 uint32_t active_shaders;
Tobin Ehlis88452832015-12-03 09:40:56 -0700162 // Capture which sets are actually used by the shaders of this pipeline
163 std::set<unsigned> active_sets;
Tobin Ehlis7265e832015-01-19 08:42:29 -0700164 // Vtx input info (if any)
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600165 uint32_t vtxBindingCount; // number of bindings
166 VkVertexInputBindingDescription* pVertexBindingDescriptions;
167 uint32_t vtxAttributeCount; // number of attributes
168 VkVertexInputAttributeDescription* pVertexAttributeDescriptions;
169 uint32_t attachmentCount; // number of CB attachments
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600170 VkPipelineColorBlendAttachmentState* pAttachments;
Mark Lobodzinskic44baa52015-12-11 11:56:07 -0700171 // Default constructor
172 _PIPELINE_NODE():pipeline{},
173 graphicsPipelineCI{},
174 vertexInputCI{},
175 iaStateCI{},
176 tessStateCI{},
177 vpStateCI{},
178 rsStateCI{},
179 msStateCI{},
180 cbStateCI{},
181 dsStateCI{},
182 dynStateCI{},
183 vsCI{},
184 tcsCI{},
185 tesCI{},
186 gsCI{},
187 fsCI{},
188 computePipelineCI{},
189 active_shaders(0),
190 vtxBindingCount(0),
191 pVertexBindingDescriptions(0),
192 vtxAttributeCount(0),
193 pVertexAttributeDescriptions(0),
194 attachmentCount(0),
195 pAttachments(0)
196 {};
Tobin Ehlis7265e832015-01-19 08:42:29 -0700197} PIPELINE_NODE;
198
Michael Lentine700b0aa2015-10-30 17:57:32 -0700199class BASE_NODE {
200 public:
201 std::atomic_int in_use;
202};
203
Tobin Ehlis7265e832015-01-19 08:42:29 -0700204typedef struct _SAMPLER_NODE {
Tobin Ehlisce132d82015-06-19 15:07:05 -0600205 VkSampler sampler;
206 VkSamplerCreateInfo createInfo;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -0600207
208 _SAMPLER_NODE(const VkSampler* ps, const VkSamplerCreateInfo* pci) : sampler(*ps), createInfo(*pci) {};
Tobin Ehlis7265e832015-01-19 08:42:29 -0700209} SAMPLER_NODE;
Michael Lentineabc5e922015-10-12 11:30:14 -0500210
211typedef struct _IMAGE_NODE {
212 VkImageLayout layout;
213} IMAGE_NODE;
214
215typedef struct _IMAGE_CMD_BUF_NODE {
216 VkImageLayout layout;
217 VkImageLayout initialLayout;
218} IMAGE_CMD_BUF_NODE;
219
Michael Lentine700b0aa2015-10-30 17:57:32 -0700220class BUFFER_NODE : public BASE_NODE {
221 public:
222 using BASE_NODE::in_use;
223 unique_ptr<VkBufferCreateInfo> create_info;
224};
225
Tobin Ehlis651d9b02015-12-16 05:01:22 -0700226struct RENDER_PASS_NODE {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -0700227 VkRenderPassCreateInfo const* pCreateInfo;
Michael Lentine48930b82015-10-15 17:07:00 -0500228 std::vector<bool> hasSelfDependency;
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -0700229 vector<std::vector<VkFormat>> subpassColorFormats;
230
Tobin Ehlis651d9b02015-12-16 05:01:22 -0700231 RENDER_PASS_NODE(VkRenderPassCreateInfo const *pCreateInfo) : pCreateInfo(pCreateInfo)
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -0700232 {
233 uint32_t i;
234
235 subpassColorFormats.reserve(pCreateInfo->subpassCount);
236 for (i = 0; i < pCreateInfo->subpassCount; i++) {
237 const VkSubpassDescription *subpass = &pCreateInfo->pSubpasses[i];
238 vector<VkFormat> color_formats;
239 uint32_t j;
240
241 color_formats.reserve(subpass->colorAttachmentCount);
242 for (j = 0; j < subpass->colorAttachmentCount; j++) {
243 const uint32_t att = subpass->pColorAttachments[j].attachment;
244 const VkFormat format = pCreateInfo->pAttachments[att].format;
245
246 color_formats.push_back(pCreateInfo->pAttachments[att].format);
247 }
248
249 subpassColorFormats.push_back(color_formats);
250 }
251 }
Tobin Ehlis651d9b02015-12-16 05:01:22 -0700252};
Michael Lentine48930b82015-10-15 17:07:00 -0500253
Michael Lentine700b0aa2015-10-30 17:57:32 -0700254class FENCE_NODE : public BASE_NODE {
255 public:
256 using BASE_NODE::in_use;
257 vector<VkCommandBuffer> cmdBuffers;
258 bool needsSignaled;
259 VkFence priorFence;
260};
261
Michael Lentineb887b0a2015-12-29 14:12:11 -0600262class EVENT_NODE : public BASE_NODE {
263 public:
264 using BASE_NODE::in_use;
265 bool needsSignaled;
266};
267
Michael Lentine700b0aa2015-10-30 17:57:32 -0700268class QUEUE_NODE {
269 public:
270 VkDevice device;
271 VkFence priorFence;
272 vector<VkCommandBuffer> untrackedCmdBuffers;
Michael Lentineb887b0a2015-12-29 14:12:11 -0600273 unordered_set<VkCommandBuffer> inFlightCmdBuffers;
Michael Lentine700b0aa2015-10-30 17:57:32 -0700274};
275
276class DEVICE_NODE {
277 public:
278 vector<VkQueue> queues;
279};
280
Tobin Ehlis7265e832015-01-19 08:42:29 -0700281// Descriptor Data structures
Tobin Ehlis04178d72015-01-22 10:45:21 -0700282// Layout Node has the core layout data
Tobin Ehlis7265e832015-01-19 08:42:29 -0700283typedef struct _LAYOUT_NODE {
Tobin Ehlisce132d82015-06-19 15:07:05 -0600284 VkDescriptorSetLayout layout;
Tobin Ehlisce132d82015-06-19 15:07:05 -0600285 VkDescriptorSetLayoutCreateInfo createInfo;
286 uint32_t startIndex; // 1st index of this layout
287 uint32_t endIndex; // last index of this layout
Tobin Ehlisda2f0d02015-11-04 12:28:28 -0700288 uint32_t dynamicDescriptorCount; // Total count of dynamic descriptors used by this layout
Tobin Ehlis644ff042015-10-20 10:11:55 -0600289 vector<VkDescriptorType> descriptorTypes; // Type per descriptor in this layout to verify correct updates
Tobin Ehlisa1f9b642015-10-27 12:25:35 -0600290 vector<VkShaderStageFlags> stageFlags; // stageFlags per descriptor in this layout to verify correct updates
Chia-I Wud46e6ae2015-10-31 00:31:16 +0800291 unordered_set<uint32_t> bindings;
Mark Lobodzinski2bf36f02015-11-17 12:42:57 -0700292 // Default constructor
Mark Lobodzinskic44baa52015-12-11 11:56:07 -0700293 _LAYOUT_NODE():layout{},
294 createInfo{},
295 startIndex(0),
296 endIndex(0),
297 dynamicDescriptorCount(0)
298 {};
Tobin Ehlis7265e832015-01-19 08:42:29 -0700299} LAYOUT_NODE;
Mark Lobodzinski2bf36f02015-11-17 12:42:57 -0700300
Tobin Ehlis644ff042015-10-20 10:11:55 -0600301// Store layouts and pushconstants for PipelineLayout
302struct PIPELINE_LAYOUT_NODE {
303 vector<VkDescriptorSetLayout> descriptorSetLayouts;
304 vector<VkPushConstantRange> pushConstantRanges;
305};
306
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -0700307class SET_NODE : public BASE_NODE {
308 public:
309 using BASE_NODE::in_use;
Tobin Ehlisce132d82015-06-19 15:07:05 -0600310 VkDescriptorSet set;
311 VkDescriptorPool pool;
Tobin Ehlis481ec712015-02-19 09:55:18 -0700312 // Head of LL of all Update structs for this set
Tobin Ehlisce132d82015-06-19 15:07:05 -0600313 GENERIC_HEADER* pUpdateStructs;
Tobin Ehlis04178d72015-01-22 10:45:21 -0700314 // Total num of descriptors in this set (count of its layout plus all prior layouts)
Tobin Ehlisce132d82015-06-19 15:07:05 -0600315 uint32_t descriptorCount;
316 GENERIC_HEADER** ppDescriptors; // Array where each index points to update node for its slot
317 LAYOUT_NODE* pLayout; // Layout for this set
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -0700318 struct SET_NODE* pNext;
Tobin Ehlisf6585052015-12-17 11:48:42 -0700319 vector<uint32_t> dynamicOffsets; // one dynamic offset per dynamic descriptor
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -0700320 SET_NODE() : pUpdateStructs(NULL), ppDescriptors(NULL), pLayout(NULL), pNext(NULL) {};
321};
Tobin Ehlis7265e832015-01-19 08:42:29 -0700322
Mark Lobodzinski39298632015-11-18 08:38:27 -0700323typedef struct _DESCRIPTOR_POOL_NODE {
Tobin Ehlisce132d82015-06-19 15:07:05 -0600324 VkDescriptorPool pool;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -0600325 uint32_t maxSets;
Tobin Ehlisce132d82015-06-19 15:07:05 -0600326 VkDescriptorPoolCreateInfo createInfo;
327 SET_NODE* pSets; // Head of LL of sets for this Pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -0600328 vector<uint32_t> maxDescriptorTypeCount; // max # of descriptors of each type in this pool
329 vector<uint32_t> availableDescriptorTypeCount; // available # of descriptors of each type in this pool
330
Mark Lobodzinski39298632015-11-18 08:38:27 -0700331 _DESCRIPTOR_POOL_NODE(const VkDescriptorPool pool, const VkDescriptorPoolCreateInfo* pCreateInfo) :
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -0600332 pool(pool), createInfo(*pCreateInfo), maxSets(pCreateInfo->maxSets), pSets(NULL),
Tobin Ehlisf93f1e32015-10-20 16:16:04 -0600333 maxDescriptorTypeCount(VK_DESCRIPTOR_TYPE_END_RANGE), availableDescriptorTypeCount(VK_DESCRIPTOR_TYPE_END_RANGE)
334 {
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800335 if (createInfo.poolSizeCount) { // Shadow type struct from ptr into local struct
336 size_t poolSizeCountSize = createInfo.poolSizeCount * sizeof(VkDescriptorPoolSize);
337 createInfo.pPoolSizes = new VkDescriptorPoolSize[poolSizeCountSize];
338 memcpy((void*)createInfo.pPoolSizes, pCreateInfo->pPoolSizes, poolSizeCountSize);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -0600339 // Now set max counts for each descriptor type based on count of that type times maxSets
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -0700340 uint32_t i=0;
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800341 for (i=0; i<createInfo.poolSizeCount; ++i) {
342 uint32_t typeIndex = static_cast<uint32_t>(createInfo.pPoolSizes[i].type);
343 uint32_t poolSizeCount = createInfo.pPoolSizes[i].descriptorCount;
344 maxDescriptorTypeCount[typeIndex] += poolSizeCount;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -0600345 }
346 for (i=0; i<maxDescriptorTypeCount.size(); ++i) {
347 maxDescriptorTypeCount[i] *= createInfo.maxSets;
348 // Initially the available counts are equal to the max counts
349 availableDescriptorTypeCount[i] = maxDescriptorTypeCount[i];
350 }
351 } else {
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800352 createInfo.pPoolSizes = NULL; // Make sure this is NULL so we don't try to clean it up
Tobin Ehlisf93f1e32015-10-20 16:16:04 -0600353 }
354 }
Mark Lobodzinski39298632015-11-18 08:38:27 -0700355 ~_DESCRIPTOR_POOL_NODE() {
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800356 if (createInfo.pPoolSizes) {
357 delete[] createInfo.pPoolSizes;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -0600358 }
359 // TODO : pSets are currently freed in deletePools function which uses freeShadowUpdateTree function
360 // need to migrate that struct to smart ptrs for auto-cleanup
361 }
Mark Lobodzinski39298632015-11-18 08:38:27 -0700362} DESCRIPTOR_POOL_NODE;
Tobin Ehlis7265e832015-01-19 08:42:29 -0700363
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700364// Cmd Buffer Tracking
365typedef enum _CMD_TYPE
366{
367 CMD_BINDPIPELINE,
368 CMD_BINDPIPELINEDELTA,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600369 CMD_SETVIEWPORTSTATE,
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -0600370 CMD_SETSCISSORSTATE,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600371 CMD_SETLINEWIDTHSTATE,
372 CMD_SETDEPTHBIASSTATE,
373 CMD_SETBLENDSTATE,
374 CMD_SETDEPTHBOUNDSSTATE,
375 CMD_SETSTENCILREADMASKSTATE,
376 CMD_SETSTENCILWRITEMASKSTATE,
377 CMD_SETSTENCILREFERENCESTATE,
Tobin Ehlis793ad302015-04-03 12:01:11 -0600378 CMD_BINDDESCRIPTORSETS,
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700379 CMD_BINDINDEXBUFFER,
380 CMD_BINDVERTEXBUFFER,
381 CMD_DRAW,
382 CMD_DRAWINDEXED,
383 CMD_DRAWINDIRECT,
384 CMD_DRAWINDEXEDINDIRECT,
385 CMD_DISPATCH,
386 CMD_DISPATCHINDIRECT,
387 CMD_COPYBUFFER,
388 CMD_COPYIMAGE,
Tobin Ehlis793ad302015-04-03 12:01:11 -0600389 CMD_BLITIMAGE,
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700390 CMD_COPYBUFFERTOIMAGE,
391 CMD_COPYIMAGETOBUFFER,
392 CMD_CLONEIMAGEDATA,
393 CMD_UPDATEBUFFER,
394 CMD_FILLBUFFER,
395 CMD_CLEARCOLORIMAGE,
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -0600396 CMD_CLEARATTACHMENTS,
Tobin Ehlis53eddda2015-07-01 16:46:13 -0600397 CMD_CLEARDEPTHSTENCILIMAGE,
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700398 CMD_RESOLVEIMAGE,
399 CMD_SETEVENT,
400 CMD_RESETEVENT,
401 CMD_WAITEVENTS,
402 CMD_PIPELINEBARRIER,
403 CMD_BEGINQUERY,
404 CMD_ENDQUERY,
405 CMD_RESETQUERYPOOL,
Mark Lobodzinski5495d132015-09-30 16:19:16 -0600406 CMD_COPYQUERYPOOLRESULTS,
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700407 CMD_WRITETIMESTAMP,
408 CMD_INITATOMICCOUNTERS,
409 CMD_LOADATOMICCOUNTERS,
410 CMD_SAVEATOMICCOUNTERS,
411 CMD_BEGINRENDERPASS,
Chia-I Wu08accc62015-07-07 11:50:03 +0800412 CMD_NEXTSUBPASS,
Tobin Ehlis67449422015-03-02 10:16:40 -0700413 CMD_ENDRENDERPASS,
Chia-I Wu0b50a1c2015-06-26 15:34:39 +0800414 CMD_EXECUTECOMMANDS,
Tobin Ehlis67449422015-03-02 10:16:40 -0700415 CMD_DBGMARKERBEGIN,
416 CMD_DBGMARKEREND,
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700417} CMD_TYPE;
418// Data structure for holding sequence of cmds in cmd buffer
419typedef struct _CMD_NODE {
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700420 CMD_TYPE type;
421 uint64_t cmdNumber;
422} CMD_NODE;
423
424typedef enum _CB_STATE
425{
Tobin Ehlisac0ef842015-12-14 13:46:38 -0700426 CB_NEW, // Newly created CB w/o any cmds
427 CB_RECORDING, // BeginCB has been called on this CB
428 CB_RECORDED // EndCB has been called on this CB
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700429} CB_STATE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -0600430// CB Status -- used to track status of various bindings on cmd buffer objects
431typedef VkFlags CBStatusFlags;
432typedef enum _CBStatusFlagBits
433{
434 CBSTATUS_NONE = 0x00000000, // No status is set
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600435 CBSTATUS_VIEWPORT_SET = 0x00000001, // Viewport has been set
436 CBSTATUS_LINE_WIDTH_SET = 0x00000002, // Line width has been set
437 CBSTATUS_DEPTH_BIAS_SET = 0x00000004, // Depth bias has been set
438 CBSTATUS_COLOR_BLEND_WRITE_ENABLE = 0x00000008, // PSO w/ CB Enable set has been set
439 CBSTATUS_BLEND_SET = 0x00000010, // Blend state object has been set
440 CBSTATUS_DEPTH_WRITE_ENABLE = 0x00000020, // PSO w/ Depth Enable set has been set
441 CBSTATUS_STENCIL_TEST_ENABLE = 0x00000040, // PSO w/ Stencil Enable set has been set
442 CBSTATUS_DEPTH_BOUNDS_SET = 0x00000080, // Depth bounds state object has been set
443 CBSTATUS_STENCIL_READ_MASK_SET = 0x00000100, // Stencil read mask has been set
444 CBSTATUS_STENCIL_WRITE_MASK_SET = 0x00000200, // Stencil write mask has been set
445 CBSTATUS_STENCIL_REFERENCE_SET = 0x00000400, // Stencil reference has been set
446 CBSTATUS_INDEX_BUFFER_BOUND = 0x00000800, // Index buffer has been set
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -0600447 CBSTATUS_SCISSOR_SET = 0x00001000, // Scissor has been set
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -0600448 CBSTATUS_ALL = 0x00001FFF, // All dynamic state set
Tobin Ehlise382c5a2015-06-10 12:57:07 -0600449} CBStatusFlagBits;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600450
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600451typedef struct stencil_data {
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800452 uint32_t compareMask;
453 uint32_t writeMask;
454 uint32_t reference;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600455} CBStencilData;
456
Michael Lentine700b0aa2015-10-30 17:57:32 -0700457typedef struct _DRAW_DATA {
458 vector<VkBuffer> buffers;
459} DRAW_DATA;
460
Michael Lentineb887b0a2015-12-29 14:12:11 -0600461struct QueryObject {
462 VkQueryPool pool;
463 uint32_t index;
464};
465
466bool operator==(const QueryObject& query1, const QueryObject& query2) {
467 return (query1.pool == query2.pool && query1.index == query2.index);
468}
469
470namespace std {
471template <>
472struct hash<QueryObject> {
473 size_t operator()(QueryObject query) const throw() {
474 return hash<uint64_t>()(reinterpret_cast<uint64_t>(query.pool)) ^ hash<uint32_t>()(query.index);
475 }
476};
477}
478
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600479// Cmd Buffer Wrapper Struct
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700480typedef struct _GLOBAL_CB_NODE {
Michael Lentineabc5e922015-10-12 11:30:14 -0500481 VkCommandBuffer commandBuffer;
482 VkCommandBufferAllocateInfo createInfo;
483 VkCommandBufferBeginInfo beginInfo;
Tobin Ehliscd5bfd82016-01-19 13:12:52 -0700484 VkCommandBufferInheritanceInfo inheritanceInfo;
Tobin Ehlisa9f3d762015-05-22 12:38:16 -0600485 VkFence fence; // fence tracking this cmd buffer
Mark Lobodzinski941aea92016-01-13 10:23:15 -0700486 VkDevice device; // device this DB belongs to
Tobin Ehlisa9f3d762015-05-22 12:38:16 -0600487 uint64_t numCmds; // number of cmds in this CB
488 uint64_t drawCount[NUM_DRAW_TYPES]; // Count of each type of draw in this CB
Tobin Ehlise382c5a2015-06-10 12:57:07 -0600489 CB_STATE state; // Track cmd buffer update state
Tobin Ehlis59278bf2015-08-18 07:10:58 -0600490 uint64_t submitCount; // Number of times CB has been submitted
Tobin Ehlise382c5a2015-06-10 12:57:07 -0600491 CBStatusFlags status; // Track status of various bindings on cmd buffer
Tobin Ehlis9a874302016-01-20 10:25:29 -0700492 vector<CMD_NODE> cmds; // vector of commands bound to this command buffer
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700493 // Currently storing "lastBound" objects on per-CB basis
494 // long-term may want to create caches of "lastBound" states and could have
495 // each individual CMD_NODE referencing its own "lastBound" state
Tobin Ehlisa9f3d762015-05-22 12:38:16 -0600496 VkPipeline lastBoundPipeline;
497 uint32_t lastVtxBinding;
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -0700498 vector<VkBuffer> boundVtxBuffers;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600499 vector<VkViewport> viewports;
500 vector<VkRect2D> scissors;
501 float lineWidth;
Chia-I Wud8c946a2015-10-26 19:08:09 +0800502 float depthBiasConstantFactor;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600503 float depthBiasClamp;
Chia-I Wud8c946a2015-10-26 19:08:09 +0800504 float depthBiasSlopeFactor;
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800505 float blendConstants[4];
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600506 float minDepthBounds;
507 float maxDepthBounds;
508 CBStencilData front;
509 CBStencilData back;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600510 VkDescriptorSet lastBoundDescriptorSet;
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600511 VkPipelineLayout lastBoundPipelineLayout;
Michael Lentineabc5e922015-10-12 11:30:14 -0500512 VkRenderPassBeginInfo activeRenderPassBeginInfo;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600513 VkRenderPass activeRenderPass;
Michael Lentine2e068b22015-12-29 16:05:27 -0600514 VkSubpassContents activeSubpassContents;
Chia-I Wu08accc62015-07-07 11:50:03 +0800515 uint32_t activeSubpass;
Tobin Ehlisa9f3d762015-05-22 12:38:16 -0600516 VkFramebuffer framebuffer;
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -0700517 // Capture which sets are actually used by the shaders of this CB. This is union of all sets used by each Draw in CB
518 std::set<VkDescriptorSet> activeSets;
519 // Keep running track of which sets are bound to which set# at any given time
Tobin Ehlis559c6382015-11-05 09:52:49 -0700520 vector<VkDescriptorSet> boundDescriptorSets; // Index is set# that given set is bound to
Michael Lentineb887b0a2015-12-29 14:12:11 -0600521 vector<VkEvent> waitedEvents;
522 unordered_map<QueryObject, vector<VkEvent> > waitedEventsBeforeQueryReset;
523 unordered_map<QueryObject, bool> queryToStateMap; // 0 is unavailable, 1 is available
Michael Lentineabc5e922015-10-12 11:30:14 -0500524 unordered_map<VkImage, IMAGE_CMD_BUF_NODE> imageLayoutMap;
Michael Lentine700b0aa2015-10-30 17:57:32 -0700525 vector<DRAW_DATA> drawData;
526 DRAW_DATA currentDrawData;
Tobin Ehlisd01f7d62015-02-13 10:26:14 -0700527} GLOBAL_CB_NODE;
Michael Lentineabc5e922015-10-12 11:30:14 -0500528
529typedef struct _SWAPCHAIN_NODE {
530 std::vector<VkImage> images;
531} SWAPCHAIN_NODE;