Mark Lobodzinski | 6eda00a | 2016-02-02 15:55:36 -0700 | [diff] [blame] | 1 | /* 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 Ehlis | 246ba4d | 2014-11-18 16:38:08 -0700 | [diff] [blame] | 5 | * |
Mark Lobodzinski | 6eda00a | 2016-02-02 15:55:36 -0700 | [diff] [blame] | 6 | * 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 Ehlis | 246ba4d | 2014-11-18 16:38:08 -0700 | [diff] [blame] | 12 | * |
Mark Lobodzinski | 6eda00a | 2016-02-02 15:55:36 -0700 | [diff] [blame] | 13 | * The above copyright notice(s) and this permission notice shall be included |
| 14 | * in all copies or substantial portions of the Materials. |
Tobin Ehlis | 246ba4d | 2014-11-18 16:38:08 -0700 | [diff] [blame] | 15 | * |
Mark Lobodzinski | 6eda00a | 2016-02-02 15:55:36 -0700 | [diff] [blame] | 16 | * 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 Ehlis | 246ba4d | 2014-11-18 16:38:08 -0700 | [diff] [blame] | 19 | * |
Mark Lobodzinski | 6eda00a | 2016-02-02 15:55:36 -0700 | [diff] [blame] | 20 | * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
Tobin Ehlis | 246ba4d | 2014-11-18 16:38:08 -0700 | [diff] [blame] | 21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
Mark Lobodzinski | 6eda00a | 2016-02-02 15:55:36 -0700 | [diff] [blame] | 22 | * 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 Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 28 | * |
Tobin Ehlis | 7e2ad75 | 2015-12-01 09:48:58 -0700 | [diff] [blame] | 29 | * Author: Courtney Goeltzenleuchter <courtneygo@google.com> |
| 30 | * Author: Tobin Ehlis <tobine@google.com> |
| 31 | * Author: Chris Forbes <chrisf@ijw.co.nz> |
Mark Lobodzinski | 6eda00a | 2016-02-02 15:55:36 -0700 | [diff] [blame] | 32 | * Author: Mark Lobodzinski <mark@lunarg.com> |
Tobin Ehlis | 246ba4d | 2014-11-18 16:38:08 -0700 | [diff] [blame] | 33 | */ |
Mark Lobodzinski | 6eda00a | 2016-02-02 15:55:36 -0700 | [diff] [blame] | 34 | |
David Pinedo | 9316d3b | 2015-11-06 12:54:48 -0700 | [diff] [blame] | 35 | #include "vulkan/vk_layer.h" |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 36 | #include "vulkan/vk_ext_debug_report.h" |
Michael Lentine | 700b0aa | 2015-10-30 17:57:32 -0700 | [diff] [blame] | 37 | #include <atomic> |
Tobin Ehlis | 10ae8c1 | 2015-03-17 16:24:32 -0600 | [diff] [blame] | 38 | #include <vector> |
Tobin Ehlis | b212dfc | 2015-10-07 15:40:22 -0600 | [diff] [blame] | 39 | #include <memory> |
Tobin Ehlis | 10ae8c1 | 2015-03-17 16:24:32 -0600 | [diff] [blame] | 40 | |
Tobin Ehlis | 7e2ad75 | 2015-12-01 09:48:58 -0700 | [diff] [blame] | 41 | using std::vector; |
| 42 | |
Tobin Ehlis | 246ba4d | 2014-11-18 16:38:08 -0700 | [diff] [blame] | 43 | // Draw State ERROR codes |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 44 | typedef 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 Ehlis | 75283bf | 2015-06-18 15:59:33 -0600 | [diff] [blame] | 167 | DRAWSTATE_INVALID_EXTENSION, |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 168 | 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 Ehlis | 246ba4d | 2014-11-18 16:38:08 -0700 | [diff] [blame] | 198 | } DRAW_STATE_ERROR; |
Tobin Ehlis | 5742e77 | 2014-11-20 09:49:17 -0700 | [diff] [blame] | 199 | |
Mark Lobodzinski | 9c75c16 | 2015-12-04 10:11:56 -0700 | [diff] [blame] | 200 | typedef enum _SHADER_CHECKER_ERROR { |
| 201 | SHADER_CHECKER_NONE, |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 202 | 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 Lobodzinski | 9c75c16 | 2015-12-04 10:11:56 -0700 | [diff] [blame] | 218 | } SHADER_CHECKER_ERROR; |
| 219 | |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 220 | typedef enum _DRAW_TYPE { |
| 221 | DRAW = 0, |
| 222 | DRAW_INDEXED = 1, |
| 223 | DRAW_INDIRECT = 2, |
Tobin Ehlis | 5742e77 | 2014-11-20 09:49:17 -0700 | [diff] [blame] | 224 | DRAW_INDEXED_INDIRECT = 3, |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 225 | DRAW_BEGIN_RANGE = DRAW, |
| 226 | DRAW_END_RANGE = DRAW_INDEXED_INDIRECT, |
| 227 | NUM_DRAW_TYPES = (DRAW_END_RANGE - DRAW_BEGIN_RANGE + 1), |
Tobin Ehlis | 5742e77 | 2014-11-20 09:49:17 -0700 | [diff] [blame] | 228 | } DRAW_TYPE; |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 229 | |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 230 | typedef struct _SHADER_DS_MAPPING { |
| 231 | uint32_t slotCount; |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 232 | VkDescriptorSetLayoutCreateInfo *pShaderMappingSlot; |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 233 | } SHADER_DS_MAPPING; |
| 234 | |
Tobin Ehlis | 04178d7 | 2015-01-22 10:45:21 -0700 | [diff] [blame] | 235 | typedef struct _GENERIC_HEADER { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 236 | VkStructureType sType; |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 237 | const void *pNext; |
Tobin Ehlis | 04178d7 | 2015-01-22 10:45:21 -0700 | [diff] [blame] | 238 | } GENERIC_HEADER; |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 239 | |
| 240 | typedef struct _PIPELINE_NODE { |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 241 | 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 Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 257 | // Compute shader is include in VkComputePipelineCreateInfo |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 258 | VkComputePipelineCreateInfo computePipelineCI; |
Tobin Ehlis | a85167d | 2015-06-18 11:02:59 -0600 | [diff] [blame] | 259 | // Flag of which shader stages are active for this pipeline |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 260 | uint32_t active_shaders; |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 261 | // Capture which sets are actually used by the shaders of this pipeline |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 262 | std::set<unsigned> active_sets; |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 263 | // Vtx input info (if any) |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 264 | 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 Lobodzinski | c44baa5 | 2015-12-11 11:56:07 -0700 | [diff] [blame] | 270 | // Default constructor |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 271 | _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 Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 279 | } PIPELINE_NODE; |
| 280 | |
Michael Lentine | 700b0aa | 2015-10-30 17:57:32 -0700 | [diff] [blame] | 281 | class BASE_NODE { |
| 282 | public: |
| 283 | std::atomic_int in_use; |
| 284 | }; |
| 285 | |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 286 | typedef struct _SAMPLER_NODE { |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 287 | VkSampler sampler; |
Tobin Ehlis | ce132d8 | 2015-06-19 15:07:05 -0600 | [diff] [blame] | 288 | VkSamplerCreateInfo createInfo; |
Tobin Ehlis | b212dfc | 2015-10-07 15:40:22 -0600 | [diff] [blame] | 289 | |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 290 | _SAMPLER_NODE(const VkSampler *ps, const VkSamplerCreateInfo *pci) |
| 291 | : sampler(*ps), createInfo(*pci){}; |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 292 | } SAMPLER_NODE; |
Michael Lentine | abc5e92 | 2015-10-12 11:30:14 -0500 | [diff] [blame] | 293 | |
| 294 | typedef struct _IMAGE_NODE { |
| 295 | VkImageLayout layout; |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 296 | VkFormat format; |
Michael Lentine | abc5e92 | 2015-10-12 11:30:14 -0500 | [diff] [blame] | 297 | } IMAGE_NODE; |
| 298 | |
| 299 | typedef struct _IMAGE_CMD_BUF_NODE { |
| 300 | VkImageLayout layout; |
| 301 | VkImageLayout initialLayout; |
| 302 | } IMAGE_CMD_BUF_NODE; |
| 303 | |
Michael Lentine | 700b0aa | 2015-10-30 17:57:32 -0700 | [diff] [blame] | 304 | class BUFFER_NODE : public BASE_NODE { |
| 305 | public: |
| 306 | using BASE_NODE::in_use; |
| 307 | unique_ptr<VkBufferCreateInfo> create_info; |
| 308 | }; |
| 309 | |
Tobin Ehlis | 651d9b0 | 2015-12-16 05:01:22 -0700 | [diff] [blame] | 310 | struct RENDER_PASS_NODE { |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 311 | VkRenderPassCreateInfo const *pCreateInfo; |
Michael Lentine | 48930b8 | 2015-10-15 17:07:00 -0500 | [diff] [blame] | 312 | std::vector<bool> hasSelfDependency; |
Tobin Ehlis | 3f5ddbb | 2015-12-02 13:53:34 -0700 | [diff] [blame] | 313 | vector<std::vector<VkFormat>> subpassColorFormats; |
| 314 | |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 315 | RENDER_PASS_NODE(VkRenderPassCreateInfo const *pCreateInfo) |
| 316 | : pCreateInfo(pCreateInfo) { |
Tobin Ehlis | 3f5ddbb | 2015-12-02 13:53:34 -0700 | [diff] [blame] | 317 | 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 Ehlis | 651d9b0 | 2015-12-16 05:01:22 -0700 | [diff] [blame] | 336 | }; |
Michael Lentine | 48930b8 | 2015-10-15 17:07:00 -0500 | [diff] [blame] | 337 | |
Michael Lentine | 700b0aa | 2015-10-30 17:57:32 -0700 | [diff] [blame] | 338 | class FENCE_NODE : public BASE_NODE { |
| 339 | public: |
| 340 | using BASE_NODE::in_use; |
Tobin Ehlis | ae82e7f | 2016-01-20 16:23:37 -0700 | [diff] [blame] | 341 | VkQueue queue; |
Michael Lentine | 700b0aa | 2015-10-30 17:57:32 -0700 | [diff] [blame] | 342 | vector<VkCommandBuffer> cmdBuffers; |
| 343 | bool needsSignaled; |
| 344 | VkFence priorFence; |
| 345 | }; |
| 346 | |
Michael Lentine | b887b0a | 2015-12-29 14:12:11 -0600 | [diff] [blame] | 347 | class EVENT_NODE : public BASE_NODE { |
| 348 | public: |
| 349 | using BASE_NODE::in_use; |
| 350 | bool needsSignaled; |
| 351 | }; |
| 352 | |
Michael Lentine | 700b0aa | 2015-10-30 17:57:32 -0700 | [diff] [blame] | 353 | class QUEUE_NODE { |
| 354 | public: |
| 355 | VkDevice device; |
| 356 | VkFence priorFence; |
| 357 | vector<VkCommandBuffer> untrackedCmdBuffers; |
Michael Lentine | b887b0a | 2015-12-29 14:12:11 -0600 | [diff] [blame] | 358 | unordered_set<VkCommandBuffer> inFlightCmdBuffers; |
Michael Lentine | 700b0aa | 2015-10-30 17:57:32 -0700 | [diff] [blame] | 359 | }; |
| 360 | |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 361 | // Descriptor Data structures |
Tobin Ehlis | 04178d7 | 2015-01-22 10:45:21 -0700 | [diff] [blame] | 362 | // Layout Node has the core layout data |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 363 | typedef struct _LAYOUT_NODE { |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 364 | VkDescriptorSetLayout layout; |
Tobin Ehlis | ce132d8 | 2015-06-19 15:07:05 -0600 | [diff] [blame] | 365 | VkDescriptorSetLayoutCreateInfo createInfo; |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 366 | 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 Lobodzinski | 2bf36f0 | 2015-11-17 12:42:57 -0700 | [diff] [blame] | 376 | // Default constructor |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 377 | _LAYOUT_NODE() |
| 378 | : layout{}, createInfo{}, startIndex(0), endIndex(0), |
| 379 | dynamicDescriptorCount(0){}; |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 380 | } LAYOUT_NODE; |
Mark Lobodzinski | 2bf36f0 | 2015-11-17 12:42:57 -0700 | [diff] [blame] | 381 | |
Tobin Ehlis | 644ff04 | 2015-10-20 10:11:55 -0600 | [diff] [blame] | 382 | // Store layouts and pushconstants for PipelineLayout |
| 383 | struct PIPELINE_LAYOUT_NODE { |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 384 | vector<VkDescriptorSetLayout> descriptorSetLayouts; |
| 385 | vector<VkPushConstantRange> pushConstantRanges; |
Tobin Ehlis | 644ff04 | 2015-10-20 10:11:55 -0600 | [diff] [blame] | 386 | }; |
| 387 | |
Tobin Ehlis | 9c4f38d | 2016-01-14 12:47:19 -0700 | [diff] [blame] | 388 | class SET_NODE : public BASE_NODE { |
| 389 | public: |
| 390 | using BASE_NODE::in_use; |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 391 | VkDescriptorSet set; |
| 392 | VkDescriptorPool pool; |
Tobin Ehlis | 481ec71 | 2015-02-19 09:55:18 -0700 | [diff] [blame] | 393 | // Head of LL of all Update structs for this set |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 394 | 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 Ehlis | 9c4f38d | 2016-01-14 12:47:19 -0700 | [diff] [blame] | 407 | }; |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 408 | |
Mark Lobodzinski | 3929863 | 2015-11-18 08:38:27 -0700 | [diff] [blame] | 409 | typedef struct _DESCRIPTOR_POOL_NODE { |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 410 | VkDescriptorPool pool; |
| 411 | uint32_t maxSets; |
Tobin Ehlis | ce132d8 | 2015-06-19 15:07:05 -0600 | [diff] [blame] | 412 | VkDescriptorPoolCreateInfo createInfo; |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 413 | 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 Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 418 | |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 419 | _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 Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 428 | createInfo.pPoolSizes = new VkDescriptorPoolSize[poolSizeCountSize]; |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 429 | 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 Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 439 | maxDescriptorTypeCount[typeIndex] += poolSizeCount; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 440 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 441 | for (i = 0; i < maxDescriptorTypeCount.size(); ++i) { |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 442 | maxDescriptorTypeCount[i] *= createInfo.maxSets; |
| 443 | // Initially the available counts are equal to the max counts |
| 444 | availableDescriptorTypeCount[i] = maxDescriptorTypeCount[i]; |
| 445 | } |
| 446 | } else { |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 447 | createInfo.pPoolSizes = |
| 448 | NULL; // Make sure this is NULL so we don't try to clean it up |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 449 | } |
| 450 | } |
Mark Lobodzinski | 3929863 | 2015-11-18 08:38:27 -0700 | [diff] [blame] | 451 | ~_DESCRIPTOR_POOL_NODE() { |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 452 | if (createInfo.pPoolSizes) { |
| 453 | delete[] createInfo.pPoolSizes; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 454 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 455 | // TODO : pSets are currently freed in deletePools function which uses |
| 456 | // freeShadowUpdateTree function |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 457 | // need to migrate that struct to smart ptrs for auto-cleanup |
| 458 | } |
Mark Lobodzinski | 3929863 | 2015-11-18 08:38:27 -0700 | [diff] [blame] | 459 | } DESCRIPTOR_POOL_NODE; |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 460 | |
Tobin Ehlis | d01f7d6 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 461 | // Cmd Buffer Tracking |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 462 | typedef enum _CMD_TYPE { |
Tobin Ehlis | d01f7d6 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 463 | CMD_BINDPIPELINE, |
| 464 | CMD_BINDPIPELINEDELTA, |
Courtney Goeltzenleuchter | 49c7308 | 2015-09-17 15:06:17 -0600 | [diff] [blame] | 465 | CMD_SETVIEWPORTSTATE, |
Courtney Goeltzenleuchter | 078f817 | 2015-09-21 11:44:06 -0600 | [diff] [blame] | 466 | CMD_SETSCISSORSTATE, |
Courtney Goeltzenleuchter | 49c7308 | 2015-09-17 15:06:17 -0600 | [diff] [blame] | 467 | CMD_SETLINEWIDTHSTATE, |
| 468 | CMD_SETDEPTHBIASSTATE, |
| 469 | CMD_SETBLENDSTATE, |
| 470 | CMD_SETDEPTHBOUNDSSTATE, |
| 471 | CMD_SETSTENCILREADMASKSTATE, |
| 472 | CMD_SETSTENCILWRITEMASKSTATE, |
| 473 | CMD_SETSTENCILREFERENCESTATE, |
Tobin Ehlis | 793ad30 | 2015-04-03 12:01:11 -0600 | [diff] [blame] | 474 | CMD_BINDDESCRIPTORSETS, |
Tobin Ehlis | d01f7d6 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 475 | 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 Ehlis | 793ad30 | 2015-04-03 12:01:11 -0600 | [diff] [blame] | 485 | CMD_BLITIMAGE, |
Tobin Ehlis | d01f7d6 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 486 | CMD_COPYBUFFERTOIMAGE, |
| 487 | CMD_COPYIMAGETOBUFFER, |
| 488 | CMD_CLONEIMAGEDATA, |
| 489 | CMD_UPDATEBUFFER, |
| 490 | CMD_FILLBUFFER, |
| 491 | CMD_CLEARCOLORIMAGE, |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 492 | CMD_CLEARATTACHMENTS, |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 493 | CMD_CLEARDEPTHSTENCILIMAGE, |
Tobin Ehlis | d01f7d6 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 494 | CMD_RESOLVEIMAGE, |
| 495 | CMD_SETEVENT, |
| 496 | CMD_RESETEVENT, |
| 497 | CMD_WAITEVENTS, |
| 498 | CMD_PIPELINEBARRIER, |
| 499 | CMD_BEGINQUERY, |
| 500 | CMD_ENDQUERY, |
| 501 | CMD_RESETQUERYPOOL, |
Mark Lobodzinski | 5495d13 | 2015-09-30 16:19:16 -0600 | [diff] [blame] | 502 | CMD_COPYQUERYPOOLRESULTS, |
Tobin Ehlis | d01f7d6 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 503 | CMD_WRITETIMESTAMP, |
| 504 | CMD_INITATOMICCOUNTERS, |
| 505 | CMD_LOADATOMICCOUNTERS, |
| 506 | CMD_SAVEATOMICCOUNTERS, |
| 507 | CMD_BEGINRENDERPASS, |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 508 | CMD_NEXTSUBPASS, |
Tobin Ehlis | 6744942 | 2015-03-02 10:16:40 -0700 | [diff] [blame] | 509 | CMD_ENDRENDERPASS, |
Chia-I Wu | 0b50a1c | 2015-06-26 15:34:39 +0800 | [diff] [blame] | 510 | CMD_EXECUTECOMMANDS, |
Tobin Ehlis | 6744942 | 2015-03-02 10:16:40 -0700 | [diff] [blame] | 511 | CMD_DBGMARKERBEGIN, |
| 512 | CMD_DBGMARKEREND, |
Tobin Ehlis | d01f7d6 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 513 | } CMD_TYPE; |
| 514 | // Data structure for holding sequence of cmds in cmd buffer |
| 515 | typedef struct _CMD_NODE { |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 516 | CMD_TYPE type; |
| 517 | uint64_t cmdNumber; |
Tobin Ehlis | d01f7d6 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 518 | } CMD_NODE; |
| 519 | |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 520 | typedef enum _CB_STATE { |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 521 | CB_NEW, // Newly created CB w/o any cmds |
| 522 | CB_RECORDING, // BeginCB has been called on this CB |
Tobin Ehlis | e6e574b | 2016-01-24 23:25:31 -0700 | [diff] [blame] | 523 | CB_RECORDED, // EndCB has been called on this CB |
| 524 | CB_INVALID // CB had a bound descriptor set destroyed or updated |
Tobin Ehlis | d01f7d6 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 525 | } CB_STATE; |
Tobin Ehlis | e382c5a | 2015-06-10 12:57:07 -0600 | [diff] [blame] | 526 | // CB Status -- used to track status of various bindings on cmd buffer objects |
| 527 | typedef VkFlags CBStatusFlags; |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 528 | typedef 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 Ehlis | e382c5a | 2015-06-10 12:57:07 -0600 | [diff] [blame] | 551 | } CBStatusFlagBits; |
Tobin Ehlis | 60a9b4f | 2015-07-07 10:42:20 -0600 | [diff] [blame] | 552 | |
Courtney Goeltzenleuchter | 49c7308 | 2015-09-17 15:06:17 -0600 | [diff] [blame] | 553 | typedef struct stencil_data { |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 554 | uint32_t compareMask; |
| 555 | uint32_t writeMask; |
| 556 | uint32_t reference; |
Courtney Goeltzenleuchter | 49c7308 | 2015-09-17 15:06:17 -0600 | [diff] [blame] | 557 | } CBStencilData; |
| 558 | |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 559 | typedef struct _DRAW_DATA { vector<VkBuffer> buffers; } DRAW_DATA; |
Michael Lentine | 700b0aa | 2015-10-30 17:57:32 -0700 | [diff] [blame] | 560 | |
Michael Lentine | b887b0a | 2015-12-29 14:12:11 -0600 | [diff] [blame] | 561 | struct QueryObject { |
| 562 | VkQueryPool pool; |
| 563 | uint32_t index; |
| 564 | }; |
| 565 | |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 566 | bool operator==(const QueryObject &query1, const QueryObject &query2) { |
Michael Lentine | b887b0a | 2015-12-29 14:12:11 -0600 | [diff] [blame] | 567 | return (query1.pool == query2.pool && query1.index == query2.index); |
| 568 | } |
| 569 | |
| 570 | namespace std { |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 571 | template <> struct hash<QueryObject> { |
Michael Lentine | b887b0a | 2015-12-29 14:12:11 -0600 | [diff] [blame] | 572 | size_t operator()(QueryObject query) const throw() { |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 573 | return hash<uint64_t>()((uint64_t)(query.pool)) ^ |
| 574 | hash<uint32_t>()(query.index); |
Michael Lentine | b887b0a | 2015-12-29 14:12:11 -0600 | [diff] [blame] | 575 | } |
| 576 | }; |
| 577 | } |
| 578 | |
Tobin Ehlis | 10ae8c1 | 2015-03-17 16:24:32 -0600 | [diff] [blame] | 579 | // Cmd Buffer Wrapper Struct |
Tobin Ehlis | d01f7d6 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 580 | typedef struct _GLOBAL_CB_NODE { |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 581 | VkCommandBuffer commandBuffer; |
| 582 | VkCommandBufferAllocateInfo createInfo; |
| 583 | VkCommandBufferBeginInfo beginInfo; |
Tobin Ehlis | cd5bfd8 | 2016-01-19 13:12:52 -0700 | [diff] [blame] | 584 | VkCommandBufferInheritanceInfo inheritanceInfo; |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 585 | 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 Ehlis | d01f7d6 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 593 | // 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 Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 596 | 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 Ehlis | e6e574b | 2016-01-24 23:25:31 -0700 | [diff] [blame] | 617 | // Capture unique std::set of descriptorSets that are bound to this CB. |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 618 | std::set<VkDescriptorSet> uniqueBoundSets; |
| 619 | // Keep running track of which sets are bound to which set# at any given |
| 620 | // time |
Tobin Ehlis | e6e574b | 2016-01-24 23:25:31 -0700 | [diff] [blame] | 621 | // Track descriptor sets that are destroyed or updated while bound to CB |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 622 | 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 Lentine | abc5e92 | 2015-10-12 11:30:14 -0500 | [diff] [blame] | 630 | unordered_map<VkImage, IMAGE_CMD_BUF_NODE> imageLayoutMap; |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 631 | vector<DRAW_DATA> drawData; |
| 632 | DRAW_DATA currentDrawData; |
| 633 | // If cmd buffer is primary, track secondary command buffers pending |
| 634 | // execution |
Tobin Ehlis | f4aafc0 | 2016-01-15 13:34:44 -0700 | [diff] [blame] | 635 | std::unordered_set<VkCommandBuffer> secondaryCommandBuffers; |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 636 | vector<uint32_t> dynamicOffsets; // one dynamic offset per dynamic |
| 637 | // descriptor bound to this CB |
Tobin Ehlis | d01f7d6 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 638 | } GLOBAL_CB_NODE; |
Michael Lentine | abc5e92 | 2015-10-12 11:30:14 -0500 | [diff] [blame] | 639 | |
| 640 | typedef struct _SWAPCHAIN_NODE { |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 641 | VkSwapchainCreateInfoKHR createInfo; |
| 642 | uint32_t *pQueueFamilyIndices; |
| 643 | std::vector<VkImage> images; |
| 644 | _SWAPCHAIN_NODE(const VkSwapchainCreateInfoKHR *pCreateInfo) |
| 645 | : createInfo(*pCreateInfo), pQueueFamilyIndices(NULL) { |
Tobin Ehlis | 75cd1c5 | 2016-01-21 10:21:04 -0700 | [diff] [blame] | 646 | if (pCreateInfo->queueFamilyIndexCount) { |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 647 | pQueueFamilyIndices = |
| 648 | new uint32_t[pCreateInfo->queueFamilyIndexCount]; |
| 649 | memcpy(pQueueFamilyIndices, pCreateInfo->pQueueFamilyIndices, |
| 650 | pCreateInfo->queueFamilyIndexCount * sizeof(uint32_t)); |
Tobin Ehlis | 75cd1c5 | 2016-01-21 10:21:04 -0700 | [diff] [blame] | 651 | createInfo.pQueueFamilyIndices = pQueueFamilyIndices; |
| 652 | } |
| 653 | } |
Mark Lobodzinski | b39d9e6 | 2016-02-02 17:06:29 -0700 | [diff] [blame] | 654 | ~_SWAPCHAIN_NODE() { |
Tobin Ehlis | 75cd1c5 | 2016-01-21 10:21:04 -0700 | [diff] [blame] | 655 | if (pQueueFamilyIndices) |
| 656 | delete pQueueFamilyIndices; |
| 657 | } |
Michael Lentine | abc5e92 | 2015-10-12 11:30:14 -0500 | [diff] [blame] | 658 | } SWAPCHAIN_NODE; |