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 |
| 44 | typedef enum _DRAW_STATE_ERROR |
| 45 | { |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 46 | DRAWSTATE_NONE, // Used for INFO & other non-error messages |
Tobin Ehlis | 04178d7 | 2015-01-22 10:45:21 -0700 | [diff] [blame] | 47 | DRAWSTATE_INTERNAL_ERROR, // Error with DrawState internal data structures |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 48 | DRAWSTATE_NO_PIPELINE_BOUND, // Unable to identify a bound pipeline |
Tobin Ehlis | 793ad30 | 2015-04-03 12:01:11 -0600 | [diff] [blame] | 49 | DRAWSTATE_INVALID_POOL, // Invalid DS pool |
Tobin Ehlis | a3a693e | 2015-02-10 15:35:23 -0700 | [diff] [blame] | 50 | DRAWSTATE_INVALID_SET, // Invalid DS |
Tobin Ehlis | 04178d7 | 2015-01-22 10:45:21 -0700 | [diff] [blame] | 51 | DRAWSTATE_INVALID_LAYOUT, // Invalid DS layout |
Michael Lentine | abc5e92 | 2015-10-12 11:30:14 -0500 | [diff] [blame] | 52 | DRAWSTATE_INVALID_IMAGE_LAYOUT, // Invalid Image layout |
Tobin Ehlis | 75283bf | 2015-06-18 15:59:33 -0600 | [diff] [blame] | 53 | DRAWSTATE_INVALID_PIPELINE, // Invalid Pipeline handle referenced |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 54 | DRAWSTATE_INVALID_PIPELINE_LAYOUT, // Invalid PipelineLayout |
Tobin Ehlis | 75283bf | 2015-06-18 15:59:33 -0600 | [diff] [blame] | 55 | DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, // Attempt to create a pipeline with invalid state |
Michael Lentine | 48930b8 | 2015-10-15 17:07:00 -0500 | [diff] [blame] | 56 | DRAWSTATE_INVALID_COMMAND_BUFFER, // Invalid CommandBuffer referenced |
| 57 | DRAWSTATE_INVALID_BARRIER, // Invalid Barrier |
Michael Lentine | 700b0aa | 2015-10-30 17:57:32 -0700 | [diff] [blame] | 58 | DRAWSTATE_INVALID_BUFFER, // Invalid Buffer |
Michael Lentine | b887b0a | 2015-12-29 14:12:11 -0600 | [diff] [blame] | 59 | DRAWSTATE_INVALID_QUERY, // Invalid Query |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 60 | DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, // binding in vkCmdBindVertexData() too large for PSO's pVertexBindingDescriptions array |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 61 | DRAWSTATE_VTX_INDEX_ALIGNMENT_ERROR, // binding offset in vkCmdBindIndexBuffer() out of alignment based on indexType |
Tobin Ehlis | 12d4c6a | 2015-08-31 12:42:38 -0600 | [diff] [blame] | 62 | //DRAWSTATE_MISSING_DOT_PROGRAM, // No "dot" program in order to generate png image |
Tobin Ehlis | 04178d7 | 2015-01-22 10:45:21 -0700 | [diff] [blame] | 63 | DRAWSTATE_OUT_OF_MEMORY, // malloc failed |
Tobin Ehlis | 9c4f38d | 2016-01-14 12:47:19 -0700 | [diff] [blame] | 64 | DRAWSTATE_INVALID_DESCRIPTOR_SET, // Descriptor Set handle is unknown |
Tobin Ehlis | 04178d7 | 2015-01-22 10:45:21 -0700 | [diff] [blame] | 65 | DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, // Type in layout vs. update are not the same |
Tobin Ehlis | a1f9b64 | 2015-10-27 12:25:35 -0600 | [diff] [blame] | 66 | DRAWSTATE_DESCRIPTOR_STAGEFLAGS_MISMATCH, // StageFlags in layout are not the same throughout a single VkWriteDescriptorSet update |
Tobin Ehlis | a3a693e | 2015-02-10 15:35:23 -0700 | [diff] [blame] | 67 | DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, // Descriptors set for update out of bounds for corresponding layout section |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 68 | DRAWSTATE_DESCRIPTOR_POOL_EMPTY, // Attempt to allocate descriptor from a pool with no more descriptors of that type available |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 69 | DRAWSTATE_CANT_FREE_FROM_NON_FREE_POOL, // Invalid to call vkFreeDescriptorSets on Sets allocated from a NON_FREE Pool |
Tobin Ehlis | 297b985 | 2015-02-23 16:09:58 -0700 | [diff] [blame] | 70 | DRAWSTATE_INVALID_UPDATE_INDEX, // Index of requested update is invalid for specified descriptors set |
Tobin Ehlis | eba312c | 2015-04-01 08:40:34 -0600 | [diff] [blame] | 71 | DRAWSTATE_INVALID_UPDATE_STRUCT, // Struct in DS Update tree is of invalid type |
Tobin Ehlis | a9f3d76 | 2015-05-22 12:38:16 -0600 | [diff] [blame] | 72 | DRAWSTATE_NUM_SAMPLES_MISMATCH, // Number of samples in bound PSO does not match number in FB of current RenderPass |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 73 | DRAWSTATE_NO_END_COMMAND_BUFFER, // Must call vkEndCommandBuffer() before QueueSubmit on that commandBuffer |
| 74 | DRAWSTATE_NO_BEGIN_COMMAND_BUFFER, // Binding cmds or calling End on CB that never had vkBeginCommandBuffer() called on it |
| 75 | DRAWSTATE_COMMAND_BUFFER_SINGLE_SUBMIT_VIOLATION, // Cmd Buffer created with VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT flag is submitted multiple times |
| 76 | DRAWSTATE_INVALID_SECONDARY_COMMAND_BUFFER, // vkCmdExecuteCommands() called with a primary commandBuffer in pCommandBuffers array |
Tobin Ehlis | 963a404 | 2015-09-29 08:18:34 -0600 | [diff] [blame] | 77 | DRAWSTATE_VIEWPORT_NOT_BOUND, // Draw submitted with no viewport state bound |
| 78 | DRAWSTATE_SCISSOR_NOT_BOUND, // Draw submitted with no scissor state bound |
| 79 | DRAWSTATE_LINE_WIDTH_NOT_BOUND, // Draw submitted with no line width state bound |
| 80 | DRAWSTATE_DEPTH_BIAS_NOT_BOUND, // Draw submitted with no depth bias state bound |
| 81 | DRAWSTATE_BLEND_NOT_BOUND, // Draw submitted with no blend state bound when color write enabled |
| 82 | DRAWSTATE_DEPTH_BOUNDS_NOT_BOUND, // Draw submitted with no depth bounds state bound when depth enabled |
| 83 | DRAWSTATE_STENCIL_NOT_BOUND, // Draw submitted with no stencil state bound when stencil enabled |
| 84 | DRAWSTATE_INDEX_BUFFER_NOT_BOUND, // Draw submitted with no depth-stencil state bound when depth write enabled |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 85 | DRAWSTATE_PIPELINE_LAYOUTS_INCOMPATIBLE, // Draw submitted PSO Pipeline layout that's not compatible with layout from BindDescriptorSets |
Tobin Ehlis | 651d9b0 | 2015-12-16 05:01:22 -0700 | [diff] [blame] | 86 | DRAWSTATE_RENDERPASS_INCOMPATIBLE, // Incompatible renderpasses between secondary cmdBuffer and primary cmdBuffer or framebuffer |
| 87 | DRAWSTATE_FRAMEBUFFER_INCOMPATIBLE, // Incompatible framebuffer between secondary cmdBuffer and active renderPass |
Tobin Ehlis | 259730a | 2015-06-23 16:13:03 -0600 | [diff] [blame] | 88 | DRAWSTATE_INVALID_RENDERPASS, // Use of a NULL or otherwise invalid RenderPass object |
Tobin Ehlis | d1fe4ec | 2015-06-23 11:22:55 -0600 | [diff] [blame] | 89 | DRAWSTATE_INVALID_RENDERPASS_CMD, // Invalid cmd submitted while a RenderPass is active |
| 90 | DRAWSTATE_NO_ACTIVE_RENDERPASS, // Rendering cmd submitted without an active RenderPass |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 91 | DRAWSTATE_DESCRIPTOR_SET_NOT_UPDATED, // DescriptorSet bound but it was never updated. This is a warning code. |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 92 | 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 Ehlis | da2f0d0 | 2015-11-04 12:28:28 -0700 | [diff] [blame] | 93 | DRAWSTATE_INVALID_DYNAMIC_OFFSET_COUNT, // DescriptorSets bound with different number of dynamic descriptors that were included in dynamicOffsetCount |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 94 | DRAWSTATE_CLEAR_CMD_BEFORE_DRAW, // Clear cmd issued before any Draw in CommandBuffer, should use RenderPass Ops instead |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 95 | 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 |
Tobin Ehlis | f4aafc0 | 2016-01-15 13:34:44 -0700 | [diff] [blame] | 96 | DRAWSTATE_INVALID_CB_SIMULTANEOUS_USE, // CmdBuffer is being used in violation of VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT rules (i.e. simultaneous use w/o that bit set) |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 97 | 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 Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 98 | DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, // Count for viewports and scissors mismatch and/or state doesn't match count |
Mark Lobodzinski | f53c6e5 | 2015-10-16 13:32:24 -0600 | [diff] [blame] | 99 | DRAWSTATE_INVALID_IMAGE_ASPECT, // Image aspect is invalid for the current operation |
Mark Lobodzinski | 13ec6b0 | 2015-10-16 09:17:27 -0600 | [diff] [blame] | 100 | DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, // Attachment reference must be present in active subpass |
Tobin Ehlis | 75283bf | 2015-06-18 15:59:33 -0600 | [diff] [blame] | 101 | DRAWSTATE_INVALID_EXTENSION, |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 102 | DRAWSTATE_SAMPLER_DESCRIPTOR_ERROR, // A Descriptor of *_SAMPLER type is being updated with an invalid or bad Sampler |
Tobin Ehlis | a1f9b64 | 2015-10-27 12:25:35 -0600 | [diff] [blame] | 103 | 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 Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 104 | DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, // A Descriptor of *_IMAGE or *_ATTACHMENT type is being updated with an invalid or bad ImageView |
| 105 | DRAWSTATE_BUFFERVIEW_DESCRIPTOR_ERROR, // A Descriptor of *_TEXEL_BUFFER type is being updated with an invalid or bad BufferView |
| 106 | DRAWSTATE_BUFFERINFO_DESCRIPTOR_ERROR, // A Descriptor of *_[UNIFORM|STORAGE]_BUFFER_[DYNAMIC] type is being updated with an invalid or bad BufferView |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 107 | DRAWSTATE_DYNAMIC_OFFSET_OVERFLOW, // At draw time the dynamic offset combined with buffer offset and range oversteps size of buffer |
Michael Lentine | 700b0aa | 2015-10-30 17:57:32 -0700 | [diff] [blame] | 108 | DRAWSTATE_DOUBLE_DESTROY, // Destroying an object twice |
Tobin Ehlis | 9c4f38d | 2016-01-14 12:47:19 -0700 | [diff] [blame] | 109 | DRAWSTATE_OBJECT_INUSE, // Destroying or modifying an object in use by a command buffer |
Michael Lentine | 15a4788 | 2016-01-06 10:05:48 -0600 | [diff] [blame] | 110 | DRAWSTATE_QUEUE_FORWARD_PROGRESS, // Queue cannot guarantee forward progress |
Mark Lobodzinski | 941aea9 | 2016-01-13 10:23:15 -0700 | [diff] [blame] | 111 | DRAWSTATE_INVALID_UNIFORM_BUFFER_OFFSET, // Dynamic Uniform Buffer Offsets violate device limit |
| 112 | DRAWSTATE_INVALID_STORAGE_BUFFER_OFFSET, // Dynamic Storage Buffer Offsets violate device limit |
Tobin Ehlis | 246ba4d | 2014-11-18 16:38:08 -0700 | [diff] [blame] | 113 | } DRAW_STATE_ERROR; |
Tobin Ehlis | 5742e77 | 2014-11-20 09:49:17 -0700 | [diff] [blame] | 114 | |
Mark Lobodzinski | 9c75c16 | 2015-12-04 10:11:56 -0700 | [diff] [blame] | 115 | typedef enum _SHADER_CHECKER_ERROR { |
| 116 | SHADER_CHECKER_NONE, |
| 117 | SHADER_CHECKER_FS_MIXED_BROADCAST, /* FS writes broadcast output AND custom outputs */ |
| 118 | SHADER_CHECKER_INTERFACE_TYPE_MISMATCH, /* Type mismatch between shader stages or shader and pipeline */ |
| 119 | SHADER_CHECKER_OUTPUT_NOT_CONSUMED, /* Entry appears in output interface, but missing in input */ |
| 120 | SHADER_CHECKER_INPUT_NOT_PRODUCED, /* Entry appears in input interface, but missing in output */ |
| 121 | SHADER_CHECKER_NON_SPIRV_SHADER, /* Shader image is not SPIR-V */ |
| 122 | SHADER_CHECKER_INCONSISTENT_SPIRV, /* General inconsistency within a SPIR-V module */ |
| 123 | SHADER_CHECKER_UNKNOWN_STAGE, /* Stage is not supported by analysis */ |
| 124 | SHADER_CHECKER_INCONSISTENT_VI, /* VI state contains conflicting binding or attrib descriptions */ |
| 125 | SHADER_CHECKER_MISSING_DESCRIPTOR, /* Shader attempts to use a descriptor binding not declared in the layout */ |
| 126 | } SHADER_CHECKER_ERROR; |
| 127 | |
Tobin Ehlis | 5742e77 | 2014-11-20 09:49:17 -0700 | [diff] [blame] | 128 | typedef enum _DRAW_TYPE |
| 129 | { |
| 130 | DRAW = 0, |
| 131 | DRAW_INDEXED = 1, |
| 132 | DRAW_INDIRECT = 2, |
| 133 | DRAW_INDEXED_INDIRECT = 3, |
| 134 | DRAW_BEGIN_RANGE = DRAW, |
| 135 | DRAW_END_RANGE = DRAW_INDEXED_INDIRECT, |
| 136 | NUM_DRAW_TYPES = (DRAW_END_RANGE - DRAW_BEGIN_RANGE + 1), |
| 137 | } DRAW_TYPE; |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 138 | |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 139 | typedef struct _SHADER_DS_MAPPING { |
| 140 | uint32_t slotCount; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 141 | VkDescriptorSetLayoutCreateInfo* pShaderMappingSlot; |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 142 | } SHADER_DS_MAPPING; |
| 143 | |
Tobin Ehlis | 04178d7 | 2015-01-22 10:45:21 -0700 | [diff] [blame] | 144 | typedef struct _GENERIC_HEADER { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 145 | VkStructureType sType; |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 146 | const void* pNext; |
Tobin Ehlis | 04178d7 | 2015-01-22 10:45:21 -0700 | [diff] [blame] | 147 | } GENERIC_HEADER; |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 148 | |
| 149 | typedef struct _PIPELINE_NODE { |
Tony Barbour | dd6e32e | 2015-07-10 15:29:03 -0600 | [diff] [blame] | 150 | VkPipeline pipeline; |
| 151 | VkGraphicsPipelineCreateInfo graphicsPipelineCI; |
| 152 | VkPipelineVertexInputStateCreateInfo vertexInputCI; |
| 153 | VkPipelineInputAssemblyStateCreateInfo iaStateCI; |
| 154 | VkPipelineTessellationStateCreateInfo tessStateCI; |
| 155 | VkPipelineViewportStateCreateInfo vpStateCI; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 156 | VkPipelineRasterizationStateCreateInfo rsStateCI; |
Tony Barbour | dd6e32e | 2015-07-10 15:29:03 -0600 | [diff] [blame] | 157 | VkPipelineMultisampleStateCreateInfo msStateCI; |
| 158 | VkPipelineColorBlendStateCreateInfo cbStateCI; |
| 159 | VkPipelineDepthStencilStateCreateInfo dsStateCI; |
Tobin Ehlis | 963a404 | 2015-09-29 08:18:34 -0600 | [diff] [blame] | 160 | VkPipelineDynamicStateCreateInfo dynStateCI; |
Tony Barbour | dd6e32e | 2015-07-10 15:29:03 -0600 | [diff] [blame] | 161 | VkPipelineShaderStageCreateInfo vsCI; |
| 162 | VkPipelineShaderStageCreateInfo tcsCI; |
| 163 | VkPipelineShaderStageCreateInfo tesCI; |
| 164 | VkPipelineShaderStageCreateInfo gsCI; |
| 165 | VkPipelineShaderStageCreateInfo fsCI; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 166 | // Compute shader is include in VkComputePipelineCreateInfo |
Mark Lobodzinski | d5732f3 | 2015-06-23 15:11:57 -0600 | [diff] [blame] | 167 | VkComputePipelineCreateInfo computePipelineCI; |
Tobin Ehlis | a85167d | 2015-06-18 11:02:59 -0600 | [diff] [blame] | 168 | // Flag of which shader stages are active for this pipeline |
Mark Lobodzinski | d5732f3 | 2015-06-23 15:11:57 -0600 | [diff] [blame] | 169 | uint32_t active_shaders; |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 170 | // Capture which sets are actually used by the shaders of this pipeline |
| 171 | std::set<unsigned> active_sets; |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 172 | // Vtx input info (if any) |
Mark Lobodzinski | d5732f3 | 2015-06-23 15:11:57 -0600 | [diff] [blame] | 173 | uint32_t vtxBindingCount; // number of bindings |
| 174 | VkVertexInputBindingDescription* pVertexBindingDescriptions; |
| 175 | uint32_t vtxAttributeCount; // number of attributes |
| 176 | VkVertexInputAttributeDescription* pVertexAttributeDescriptions; |
| 177 | uint32_t attachmentCount; // number of CB attachments |
Tony Barbour | dd6e32e | 2015-07-10 15:29:03 -0600 | [diff] [blame] | 178 | VkPipelineColorBlendAttachmentState* pAttachments; |
Mark Lobodzinski | c44baa5 | 2015-12-11 11:56:07 -0700 | [diff] [blame] | 179 | // Default constructor |
| 180 | _PIPELINE_NODE():pipeline{}, |
| 181 | graphicsPipelineCI{}, |
| 182 | vertexInputCI{}, |
| 183 | iaStateCI{}, |
| 184 | tessStateCI{}, |
| 185 | vpStateCI{}, |
| 186 | rsStateCI{}, |
| 187 | msStateCI{}, |
| 188 | cbStateCI{}, |
| 189 | dsStateCI{}, |
| 190 | dynStateCI{}, |
| 191 | vsCI{}, |
| 192 | tcsCI{}, |
| 193 | tesCI{}, |
| 194 | gsCI{}, |
| 195 | fsCI{}, |
| 196 | computePipelineCI{}, |
| 197 | active_shaders(0), |
| 198 | vtxBindingCount(0), |
| 199 | pVertexBindingDescriptions(0), |
| 200 | vtxAttributeCount(0), |
| 201 | pVertexAttributeDescriptions(0), |
| 202 | attachmentCount(0), |
| 203 | pAttachments(0) |
| 204 | {}; |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 205 | } PIPELINE_NODE; |
| 206 | |
Michael Lentine | 700b0aa | 2015-10-30 17:57:32 -0700 | [diff] [blame] | 207 | class BASE_NODE { |
| 208 | public: |
| 209 | std::atomic_int in_use; |
| 210 | }; |
| 211 | |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 212 | typedef struct _SAMPLER_NODE { |
Tobin Ehlis | ce132d8 | 2015-06-19 15:07:05 -0600 | [diff] [blame] | 213 | VkSampler sampler; |
| 214 | VkSamplerCreateInfo createInfo; |
Tobin Ehlis | b212dfc | 2015-10-07 15:40:22 -0600 | [diff] [blame] | 215 | |
| 216 | _SAMPLER_NODE(const VkSampler* ps, const VkSamplerCreateInfo* pci) : sampler(*ps), createInfo(*pci) {}; |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 217 | } SAMPLER_NODE; |
Michael Lentine | abc5e92 | 2015-10-12 11:30:14 -0500 | [diff] [blame] | 218 | |
| 219 | typedef struct _IMAGE_NODE { |
| 220 | VkImageLayout layout; |
Tobin Ehlis | 75cd1c5 | 2016-01-21 10:21:04 -0700 | [diff] [blame] | 221 | VkFormat format; |
Michael Lentine | abc5e92 | 2015-10-12 11:30:14 -0500 | [diff] [blame] | 222 | } IMAGE_NODE; |
| 223 | |
| 224 | typedef struct _IMAGE_CMD_BUF_NODE { |
| 225 | VkImageLayout layout; |
| 226 | VkImageLayout initialLayout; |
| 227 | } IMAGE_CMD_BUF_NODE; |
| 228 | |
Michael Lentine | 700b0aa | 2015-10-30 17:57:32 -0700 | [diff] [blame] | 229 | class BUFFER_NODE : public BASE_NODE { |
| 230 | public: |
| 231 | using BASE_NODE::in_use; |
| 232 | unique_ptr<VkBufferCreateInfo> create_info; |
| 233 | }; |
| 234 | |
Tobin Ehlis | 651d9b0 | 2015-12-16 05:01:22 -0700 | [diff] [blame] | 235 | struct RENDER_PASS_NODE { |
Tobin Ehlis | 3f5ddbb | 2015-12-02 13:53:34 -0700 | [diff] [blame] | 236 | VkRenderPassCreateInfo const* pCreateInfo; |
Michael Lentine | 48930b8 | 2015-10-15 17:07:00 -0500 | [diff] [blame] | 237 | std::vector<bool> hasSelfDependency; |
Tobin Ehlis | 3f5ddbb | 2015-12-02 13:53:34 -0700 | [diff] [blame] | 238 | vector<std::vector<VkFormat>> subpassColorFormats; |
| 239 | |
Tobin Ehlis | 651d9b0 | 2015-12-16 05:01:22 -0700 | [diff] [blame] | 240 | RENDER_PASS_NODE(VkRenderPassCreateInfo const *pCreateInfo) : pCreateInfo(pCreateInfo) |
Tobin Ehlis | 3f5ddbb | 2015-12-02 13:53:34 -0700 | [diff] [blame] | 241 | { |
| 242 | uint32_t i; |
| 243 | |
| 244 | subpassColorFormats.reserve(pCreateInfo->subpassCount); |
| 245 | for (i = 0; i < pCreateInfo->subpassCount; i++) { |
| 246 | const VkSubpassDescription *subpass = &pCreateInfo->pSubpasses[i]; |
| 247 | vector<VkFormat> color_formats; |
| 248 | uint32_t j; |
| 249 | |
| 250 | color_formats.reserve(subpass->colorAttachmentCount); |
| 251 | for (j = 0; j < subpass->colorAttachmentCount; j++) { |
| 252 | const uint32_t att = subpass->pColorAttachments[j].attachment; |
| 253 | const VkFormat format = pCreateInfo->pAttachments[att].format; |
| 254 | |
| 255 | color_formats.push_back(pCreateInfo->pAttachments[att].format); |
| 256 | } |
| 257 | |
| 258 | subpassColorFormats.push_back(color_formats); |
| 259 | } |
| 260 | } |
Tobin Ehlis | 651d9b0 | 2015-12-16 05:01:22 -0700 | [diff] [blame] | 261 | }; |
Michael Lentine | 48930b8 | 2015-10-15 17:07:00 -0500 | [diff] [blame] | 262 | |
Michael Lentine | 700b0aa | 2015-10-30 17:57:32 -0700 | [diff] [blame] | 263 | class FENCE_NODE : public BASE_NODE { |
| 264 | public: |
| 265 | using BASE_NODE::in_use; |
Tobin Ehlis | ae82e7f | 2016-01-20 16:23:37 -0700 | [diff] [blame] | 266 | VkQueue queue; |
Michael Lentine | 700b0aa | 2015-10-30 17:57:32 -0700 | [diff] [blame] | 267 | vector<VkCommandBuffer> cmdBuffers; |
| 268 | bool needsSignaled; |
| 269 | VkFence priorFence; |
| 270 | }; |
| 271 | |
Michael Lentine | b887b0a | 2015-12-29 14:12:11 -0600 | [diff] [blame] | 272 | class EVENT_NODE : public BASE_NODE { |
| 273 | public: |
| 274 | using BASE_NODE::in_use; |
| 275 | bool needsSignaled; |
| 276 | }; |
| 277 | |
Michael Lentine | 700b0aa | 2015-10-30 17:57:32 -0700 | [diff] [blame] | 278 | class QUEUE_NODE { |
| 279 | public: |
| 280 | VkDevice device; |
| 281 | VkFence priorFence; |
| 282 | vector<VkCommandBuffer> untrackedCmdBuffers; |
Michael Lentine | b887b0a | 2015-12-29 14:12:11 -0600 | [diff] [blame] | 283 | unordered_set<VkCommandBuffer> inFlightCmdBuffers; |
Michael Lentine | 700b0aa | 2015-10-30 17:57:32 -0700 | [diff] [blame] | 284 | }; |
| 285 | |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 286 | // Descriptor Data structures |
Tobin Ehlis | 04178d7 | 2015-01-22 10:45:21 -0700 | [diff] [blame] | 287 | // Layout Node has the core layout data |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 288 | typedef struct _LAYOUT_NODE { |
Tobin Ehlis | ce132d8 | 2015-06-19 15:07:05 -0600 | [diff] [blame] | 289 | VkDescriptorSetLayout layout; |
Tobin Ehlis | ce132d8 | 2015-06-19 15:07:05 -0600 | [diff] [blame] | 290 | VkDescriptorSetLayoutCreateInfo createInfo; |
| 291 | uint32_t startIndex; // 1st index of this layout |
| 292 | uint32_t endIndex; // last index of this layout |
Tobin Ehlis | da2f0d0 | 2015-11-04 12:28:28 -0700 | [diff] [blame] | 293 | uint32_t dynamicDescriptorCount; // Total count of dynamic descriptors used by this layout |
Tobin Ehlis | 644ff04 | 2015-10-20 10:11:55 -0600 | [diff] [blame] | 294 | vector<VkDescriptorType> descriptorTypes; // Type per descriptor in this layout to verify correct updates |
Tobin Ehlis | a1f9b64 | 2015-10-27 12:25:35 -0600 | [diff] [blame] | 295 | vector<VkShaderStageFlags> stageFlags; // stageFlags per descriptor in this layout to verify correct updates |
Chia-I Wu | d46e6ae | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 296 | unordered_set<uint32_t> bindings; |
Mark Lobodzinski | 2bf36f0 | 2015-11-17 12:42:57 -0700 | [diff] [blame] | 297 | // Default constructor |
Mark Lobodzinski | c44baa5 | 2015-12-11 11:56:07 -0700 | [diff] [blame] | 298 | _LAYOUT_NODE():layout{}, |
| 299 | createInfo{}, |
| 300 | startIndex(0), |
| 301 | endIndex(0), |
| 302 | dynamicDescriptorCount(0) |
| 303 | {}; |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 304 | } LAYOUT_NODE; |
Mark Lobodzinski | 2bf36f0 | 2015-11-17 12:42:57 -0700 | [diff] [blame] | 305 | |
Tobin Ehlis | 644ff04 | 2015-10-20 10:11:55 -0600 | [diff] [blame] | 306 | // Store layouts and pushconstants for PipelineLayout |
| 307 | struct PIPELINE_LAYOUT_NODE { |
| 308 | vector<VkDescriptorSetLayout> descriptorSetLayouts; |
| 309 | vector<VkPushConstantRange> pushConstantRanges; |
| 310 | }; |
| 311 | |
Tobin Ehlis | 9c4f38d | 2016-01-14 12:47:19 -0700 | [diff] [blame] | 312 | class SET_NODE : public BASE_NODE { |
| 313 | public: |
| 314 | using BASE_NODE::in_use; |
Tobin Ehlis | ce132d8 | 2015-06-19 15:07:05 -0600 | [diff] [blame] | 315 | VkDescriptorSet set; |
| 316 | VkDescriptorPool pool; |
Tobin Ehlis | 481ec71 | 2015-02-19 09:55:18 -0700 | [diff] [blame] | 317 | // Head of LL of all Update structs for this set |
Tobin Ehlis | ce132d8 | 2015-06-19 15:07:05 -0600 | [diff] [blame] | 318 | GENERIC_HEADER* pUpdateStructs; |
Tobin Ehlis | 04178d7 | 2015-01-22 10:45:21 -0700 | [diff] [blame] | 319 | // Total num of descriptors in this set (count of its layout plus all prior layouts) |
Tobin Ehlis | ce132d8 | 2015-06-19 15:07:05 -0600 | [diff] [blame] | 320 | uint32_t descriptorCount; |
| 321 | GENERIC_HEADER** ppDescriptors; // Array where each index points to update node for its slot |
| 322 | LAYOUT_NODE* pLayout; // Layout for this set |
Mark Young | d652d13 | 2016-01-25 13:37:06 -0700 | [diff] [blame] | 323 | SET_NODE* pNext; |
Tobin Ehlis | e6e574b | 2016-01-24 23:25:31 -0700 | [diff] [blame] | 324 | unordered_set<VkCommandBuffer> boundCmdBuffers; // Cmd buffers that this set has been bound to |
Tobin Ehlis | 9c4f38d | 2016-01-14 12:47:19 -0700 | [diff] [blame] | 325 | SET_NODE() : pUpdateStructs(NULL), ppDescriptors(NULL), pLayout(NULL), pNext(NULL) {}; |
| 326 | }; |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 327 | |
Mark Lobodzinski | 3929863 | 2015-11-18 08:38:27 -0700 | [diff] [blame] | 328 | typedef struct _DESCRIPTOR_POOL_NODE { |
Tobin Ehlis | ce132d8 | 2015-06-19 15:07:05 -0600 | [diff] [blame] | 329 | VkDescriptorPool pool; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 330 | uint32_t maxSets; |
Tobin Ehlis | ce132d8 | 2015-06-19 15:07:05 -0600 | [diff] [blame] | 331 | VkDescriptorPoolCreateInfo createInfo; |
| 332 | SET_NODE* pSets; // Head of LL of sets for this Pool |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 333 | vector<uint32_t> maxDescriptorTypeCount; // max # of descriptors of each type in this pool |
| 334 | vector<uint32_t> availableDescriptorTypeCount; // available # of descriptors of each type in this pool |
| 335 | |
Mark Lobodzinski | 3929863 | 2015-11-18 08:38:27 -0700 | [diff] [blame] | 336 | _DESCRIPTOR_POOL_NODE(const VkDescriptorPool pool, const VkDescriptorPoolCreateInfo* pCreateInfo) : |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 337 | pool(pool), createInfo(*pCreateInfo), maxSets(pCreateInfo->maxSets), pSets(NULL), |
Mark Lobodzinski | 9db41a0 | 2016-01-23 16:55:31 -0700 | [diff] [blame] | 338 | maxDescriptorTypeCount(VK_DESCRIPTOR_TYPE_RANGE_SIZE), availableDescriptorTypeCount(VK_DESCRIPTOR_TYPE_RANGE_SIZE) |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 339 | { |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 340 | if (createInfo.poolSizeCount) { // Shadow type struct from ptr into local struct |
| 341 | size_t poolSizeCountSize = createInfo.poolSizeCount * sizeof(VkDescriptorPoolSize); |
| 342 | createInfo.pPoolSizes = new VkDescriptorPoolSize[poolSizeCountSize]; |
| 343 | memcpy((void*)createInfo.pPoolSizes, pCreateInfo->pPoolSizes, poolSizeCountSize); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 344 | // Now set max counts for each descriptor type based on count of that type times maxSets |
Courtney Goeltzenleuchter | 6ed5dc2 | 2015-11-03 15:41:43 -0700 | [diff] [blame] | 345 | uint32_t i=0; |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 346 | for (i=0; i<createInfo.poolSizeCount; ++i) { |
| 347 | uint32_t typeIndex = static_cast<uint32_t>(createInfo.pPoolSizes[i].type); |
| 348 | uint32_t poolSizeCount = createInfo.pPoolSizes[i].descriptorCount; |
| 349 | maxDescriptorTypeCount[typeIndex] += poolSizeCount; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 350 | } |
| 351 | for (i=0; i<maxDescriptorTypeCount.size(); ++i) { |
| 352 | maxDescriptorTypeCount[i] *= createInfo.maxSets; |
| 353 | // Initially the available counts are equal to the max counts |
| 354 | availableDescriptorTypeCount[i] = maxDescriptorTypeCount[i]; |
| 355 | } |
| 356 | } else { |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 357 | createInfo.pPoolSizes = 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] | 358 | } |
| 359 | } |
Mark Lobodzinski | 3929863 | 2015-11-18 08:38:27 -0700 | [diff] [blame] | 360 | ~_DESCRIPTOR_POOL_NODE() { |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 361 | if (createInfo.pPoolSizes) { |
| 362 | delete[] createInfo.pPoolSizes; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 363 | } |
| 364 | // TODO : pSets are currently freed in deletePools function which uses freeShadowUpdateTree function |
| 365 | // need to migrate that struct to smart ptrs for auto-cleanup |
| 366 | } |
Mark Lobodzinski | 3929863 | 2015-11-18 08:38:27 -0700 | [diff] [blame] | 367 | } DESCRIPTOR_POOL_NODE; |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 368 | |
Tobin Ehlis | d01f7d6 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 369 | // Cmd Buffer Tracking |
| 370 | typedef enum _CMD_TYPE |
| 371 | { |
| 372 | CMD_BINDPIPELINE, |
| 373 | CMD_BINDPIPELINEDELTA, |
Courtney Goeltzenleuchter | 49c7308 | 2015-09-17 15:06:17 -0600 | [diff] [blame] | 374 | CMD_SETVIEWPORTSTATE, |
Courtney Goeltzenleuchter | 078f817 | 2015-09-21 11:44:06 -0600 | [diff] [blame] | 375 | CMD_SETSCISSORSTATE, |
Courtney Goeltzenleuchter | 49c7308 | 2015-09-17 15:06:17 -0600 | [diff] [blame] | 376 | CMD_SETLINEWIDTHSTATE, |
| 377 | CMD_SETDEPTHBIASSTATE, |
| 378 | CMD_SETBLENDSTATE, |
| 379 | CMD_SETDEPTHBOUNDSSTATE, |
| 380 | CMD_SETSTENCILREADMASKSTATE, |
| 381 | CMD_SETSTENCILWRITEMASKSTATE, |
| 382 | CMD_SETSTENCILREFERENCESTATE, |
Tobin Ehlis | 793ad30 | 2015-04-03 12:01:11 -0600 | [diff] [blame] | 383 | CMD_BINDDESCRIPTORSETS, |
Tobin Ehlis | d01f7d6 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 384 | CMD_BINDINDEXBUFFER, |
| 385 | CMD_BINDVERTEXBUFFER, |
| 386 | CMD_DRAW, |
| 387 | CMD_DRAWINDEXED, |
| 388 | CMD_DRAWINDIRECT, |
| 389 | CMD_DRAWINDEXEDINDIRECT, |
| 390 | CMD_DISPATCH, |
| 391 | CMD_DISPATCHINDIRECT, |
| 392 | CMD_COPYBUFFER, |
| 393 | CMD_COPYIMAGE, |
Tobin Ehlis | 793ad30 | 2015-04-03 12:01:11 -0600 | [diff] [blame] | 394 | CMD_BLITIMAGE, |
Tobin Ehlis | d01f7d6 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 395 | CMD_COPYBUFFERTOIMAGE, |
| 396 | CMD_COPYIMAGETOBUFFER, |
| 397 | CMD_CLONEIMAGEDATA, |
| 398 | CMD_UPDATEBUFFER, |
| 399 | CMD_FILLBUFFER, |
| 400 | CMD_CLEARCOLORIMAGE, |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 401 | CMD_CLEARATTACHMENTS, |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 402 | CMD_CLEARDEPTHSTENCILIMAGE, |
Tobin Ehlis | d01f7d6 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 403 | CMD_RESOLVEIMAGE, |
| 404 | CMD_SETEVENT, |
| 405 | CMD_RESETEVENT, |
| 406 | CMD_WAITEVENTS, |
| 407 | CMD_PIPELINEBARRIER, |
| 408 | CMD_BEGINQUERY, |
| 409 | CMD_ENDQUERY, |
| 410 | CMD_RESETQUERYPOOL, |
Mark Lobodzinski | 5495d13 | 2015-09-30 16:19:16 -0600 | [diff] [blame] | 411 | CMD_COPYQUERYPOOLRESULTS, |
Tobin Ehlis | d01f7d6 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 412 | CMD_WRITETIMESTAMP, |
| 413 | CMD_INITATOMICCOUNTERS, |
| 414 | CMD_LOADATOMICCOUNTERS, |
| 415 | CMD_SAVEATOMICCOUNTERS, |
| 416 | CMD_BEGINRENDERPASS, |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 417 | CMD_NEXTSUBPASS, |
Tobin Ehlis | 6744942 | 2015-03-02 10:16:40 -0700 | [diff] [blame] | 418 | CMD_ENDRENDERPASS, |
Chia-I Wu | 0b50a1c | 2015-06-26 15:34:39 +0800 | [diff] [blame] | 419 | CMD_EXECUTECOMMANDS, |
Tobin Ehlis | 6744942 | 2015-03-02 10:16:40 -0700 | [diff] [blame] | 420 | CMD_DBGMARKERBEGIN, |
| 421 | CMD_DBGMARKEREND, |
Tobin Ehlis | d01f7d6 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 422 | } CMD_TYPE; |
| 423 | // Data structure for holding sequence of cmds in cmd buffer |
| 424 | typedef struct _CMD_NODE { |
Tobin Ehlis | d01f7d6 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 425 | CMD_TYPE type; |
| 426 | uint64_t cmdNumber; |
| 427 | } CMD_NODE; |
| 428 | |
| 429 | typedef enum _CB_STATE |
| 430 | { |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 431 | CB_NEW, // Newly created CB w/o any cmds |
| 432 | CB_RECORDING, // BeginCB has been called on this CB |
Tobin Ehlis | e6e574b | 2016-01-24 23:25:31 -0700 | [diff] [blame] | 433 | CB_RECORDED, // EndCB has been called on this CB |
| 434 | CB_INVALID // CB had a bound descriptor set destroyed or updated |
Tobin Ehlis | d01f7d6 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 435 | } CB_STATE; |
Tobin Ehlis | e382c5a | 2015-06-10 12:57:07 -0600 | [diff] [blame] | 436 | // CB Status -- used to track status of various bindings on cmd buffer objects |
| 437 | typedef VkFlags CBStatusFlags; |
| 438 | typedef enum _CBStatusFlagBits |
| 439 | { |
| 440 | CBSTATUS_NONE = 0x00000000, // No status is set |
Courtney Goeltzenleuchter | 49c7308 | 2015-09-17 15:06:17 -0600 | [diff] [blame] | 441 | CBSTATUS_VIEWPORT_SET = 0x00000001, // Viewport has been set |
| 442 | CBSTATUS_LINE_WIDTH_SET = 0x00000002, // Line width has been set |
| 443 | CBSTATUS_DEPTH_BIAS_SET = 0x00000004, // Depth bias has been set |
| 444 | CBSTATUS_COLOR_BLEND_WRITE_ENABLE = 0x00000008, // PSO w/ CB Enable set has been set |
| 445 | CBSTATUS_BLEND_SET = 0x00000010, // Blend state object has been set |
| 446 | CBSTATUS_DEPTH_WRITE_ENABLE = 0x00000020, // PSO w/ Depth Enable set has been set |
| 447 | CBSTATUS_STENCIL_TEST_ENABLE = 0x00000040, // PSO w/ Stencil Enable set has been set |
| 448 | CBSTATUS_DEPTH_BOUNDS_SET = 0x00000080, // Depth bounds state object has been set |
| 449 | CBSTATUS_STENCIL_READ_MASK_SET = 0x00000100, // Stencil read mask has been set |
| 450 | CBSTATUS_STENCIL_WRITE_MASK_SET = 0x00000200, // Stencil write mask has been set |
| 451 | CBSTATUS_STENCIL_REFERENCE_SET = 0x00000400, // Stencil reference has been set |
| 452 | CBSTATUS_INDEX_BUFFER_BOUND = 0x00000800, // Index buffer has been set |
Courtney Goeltzenleuchter | 078f817 | 2015-09-21 11:44:06 -0600 | [diff] [blame] | 453 | CBSTATUS_SCISSOR_SET = 0x00001000, // Scissor has been set |
Tobin Ehlis | 5e5a1e9 | 2015-10-01 09:24:40 -0600 | [diff] [blame] | 454 | CBSTATUS_ALL = 0x00001FFF, // All dynamic state set |
Tobin Ehlis | e382c5a | 2015-06-10 12:57:07 -0600 | [diff] [blame] | 455 | } CBStatusFlagBits; |
Tobin Ehlis | 60a9b4f | 2015-07-07 10:42:20 -0600 | [diff] [blame] | 456 | |
Courtney Goeltzenleuchter | 49c7308 | 2015-09-17 15:06:17 -0600 | [diff] [blame] | 457 | typedef struct stencil_data { |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 458 | uint32_t compareMask; |
| 459 | uint32_t writeMask; |
| 460 | uint32_t reference; |
Courtney Goeltzenleuchter | 49c7308 | 2015-09-17 15:06:17 -0600 | [diff] [blame] | 461 | } CBStencilData; |
| 462 | |
Michael Lentine | 700b0aa | 2015-10-30 17:57:32 -0700 | [diff] [blame] | 463 | typedef struct _DRAW_DATA { |
| 464 | vector<VkBuffer> buffers; |
| 465 | } DRAW_DATA; |
| 466 | |
Michael Lentine | b887b0a | 2015-12-29 14:12:11 -0600 | [diff] [blame] | 467 | struct QueryObject { |
| 468 | VkQueryPool pool; |
| 469 | uint32_t index; |
| 470 | }; |
| 471 | |
| 472 | bool operator==(const QueryObject& query1, const QueryObject& query2) { |
| 473 | return (query1.pool == query2.pool && query1.index == query2.index); |
| 474 | } |
| 475 | |
| 476 | namespace std { |
| 477 | template <> |
| 478 | struct hash<QueryObject> { |
| 479 | size_t operator()(QueryObject query) const throw() { |
Mark Young | 93ecb1d | 2016-01-13 13:47:16 -0700 | [diff] [blame] | 480 | return hash<uint64_t>()((uint64_t)(query.pool)) ^ hash<uint32_t>()(query.index); |
Michael Lentine | b887b0a | 2015-12-29 14:12:11 -0600 | [diff] [blame] | 481 | } |
| 482 | }; |
| 483 | } |
| 484 | |
Tobin Ehlis | 10ae8c1 | 2015-03-17 16:24:32 -0600 | [diff] [blame] | 485 | // Cmd Buffer Wrapper Struct |
Tobin Ehlis | d01f7d6 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 486 | typedef struct _GLOBAL_CB_NODE { |
Michael Lentine | abc5e92 | 2015-10-12 11:30:14 -0500 | [diff] [blame] | 487 | VkCommandBuffer commandBuffer; |
| 488 | VkCommandBufferAllocateInfo createInfo; |
| 489 | VkCommandBufferBeginInfo beginInfo; |
Tobin Ehlis | cd5bfd8 | 2016-01-19 13:12:52 -0700 | [diff] [blame] | 490 | VkCommandBufferInheritanceInfo inheritanceInfo; |
Tobin Ehlis | a9f3d76 | 2015-05-22 12:38:16 -0600 | [diff] [blame] | 491 | VkFence fence; // fence tracking this cmd buffer |
Mark Lobodzinski | 941aea9 | 2016-01-13 10:23:15 -0700 | [diff] [blame] | 492 | VkDevice device; // device this DB belongs to |
Tobin Ehlis | a9f3d76 | 2015-05-22 12:38:16 -0600 | [diff] [blame] | 493 | uint64_t numCmds; // number of cmds in this CB |
| 494 | uint64_t drawCount[NUM_DRAW_TYPES]; // Count of each type of draw in this CB |
Tobin Ehlis | e382c5a | 2015-06-10 12:57:07 -0600 | [diff] [blame] | 495 | CB_STATE state; // Track cmd buffer update state |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 496 | uint64_t submitCount; // Number of times CB has been submitted |
Tobin Ehlis | e382c5a | 2015-06-10 12:57:07 -0600 | [diff] [blame] | 497 | CBStatusFlags status; // Track status of various bindings on cmd buffer |
Tobin Ehlis | 9a87430 | 2016-01-20 10:25:29 -0700 | [diff] [blame] | 498 | vector<CMD_NODE> cmds; // vector of commands bound to this command buffer |
Tobin Ehlis | d01f7d6 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 499 | // Currently storing "lastBound" objects on per-CB basis |
| 500 | // long-term may want to create caches of "lastBound" states and could have |
| 501 | // each individual CMD_NODE referencing its own "lastBound" state |
Tobin Ehlis | a9f3d76 | 2015-05-22 12:38:16 -0600 | [diff] [blame] | 502 | VkPipeline lastBoundPipeline; |
| 503 | uint32_t lastVtxBinding; |
Mark Lobodzinski | dfcd9b6 | 2015-12-14 15:14:10 -0700 | [diff] [blame] | 504 | vector<VkBuffer> boundVtxBuffers; |
Courtney Goeltzenleuchter | 49c7308 | 2015-09-17 15:06:17 -0600 | [diff] [blame] | 505 | vector<VkViewport> viewports; |
| 506 | vector<VkRect2D> scissors; |
| 507 | float lineWidth; |
Chia-I Wu | d8c946a | 2015-10-26 19:08:09 +0800 | [diff] [blame] | 508 | float depthBiasConstantFactor; |
Courtney Goeltzenleuchter | 49c7308 | 2015-09-17 15:06:17 -0600 | [diff] [blame] | 509 | float depthBiasClamp; |
Chia-I Wu | d8c946a | 2015-10-26 19:08:09 +0800 | [diff] [blame] | 510 | float depthBiasSlopeFactor; |
Chia-I Wu | 2bfb33c | 2015-10-26 17:24:52 +0800 | [diff] [blame] | 511 | float blendConstants[4]; |
Courtney Goeltzenleuchter | 49c7308 | 2015-09-17 15:06:17 -0600 | [diff] [blame] | 512 | float minDepthBounds; |
| 513 | float maxDepthBounds; |
| 514 | CBStencilData front; |
| 515 | CBStencilData back; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 516 | VkDescriptorSet lastBoundDescriptorSet; |
Tobin Ehlis | 429b91d | 2015-06-22 17:20:50 -0600 | [diff] [blame] | 517 | VkPipelineLayout lastBoundPipelineLayout; |
Michael Lentine | abc5e92 | 2015-10-12 11:30:14 -0500 | [diff] [blame] | 518 | VkRenderPassBeginInfo activeRenderPassBeginInfo; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 519 | VkRenderPass activeRenderPass; |
Michael Lentine | 2e068b2 | 2015-12-29 16:05:27 -0600 | [diff] [blame] | 520 | VkSubpassContents activeSubpassContents; |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 521 | uint32_t activeSubpass; |
Tobin Ehlis | a9f3d76 | 2015-05-22 12:38:16 -0600 | [diff] [blame] | 522 | VkFramebuffer framebuffer; |
Tobin Ehlis | e6e574b | 2016-01-24 23:25:31 -0700 | [diff] [blame] | 523 | // Capture unique std::set of descriptorSets that are bound to this CB. |
| 524 | std::set<VkDescriptorSet> uniqueBoundSets; |
Tobin Ehlis | 9c4f38d | 2016-01-14 12:47:19 -0700 | [diff] [blame] | 525 | // Keep running track of which sets are bound to which set# at any given time |
Tobin Ehlis | e6e574b | 2016-01-24 23:25:31 -0700 | [diff] [blame] | 526 | // Track descriptor sets that are destroyed or updated while bound to CB |
| 527 | std::set<VkDescriptorSet> destroyedSets; |
| 528 | std::set<VkDescriptorSet> updatedSets; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 529 | vector<VkDescriptorSet> boundDescriptorSets; // Index is set# that given set is bound to |
Michael Lentine | b887b0a | 2015-12-29 14:12:11 -0600 | [diff] [blame] | 530 | vector<VkEvent> waitedEvents; |
| 531 | unordered_map<QueryObject, vector<VkEvent> > waitedEventsBeforeQueryReset; |
| 532 | unordered_map<QueryObject, bool> queryToStateMap; // 0 is unavailable, 1 is available |
Michael Lentine | abc5e92 | 2015-10-12 11:30:14 -0500 | [diff] [blame] | 533 | unordered_map<VkImage, IMAGE_CMD_BUF_NODE> imageLayoutMap; |
Michael Lentine | 700b0aa | 2015-10-30 17:57:32 -0700 | [diff] [blame] | 534 | vector<DRAW_DATA> drawData; |
| 535 | DRAW_DATA currentDrawData; |
Tobin Ehlis | f4aafc0 | 2016-01-15 13:34:44 -0700 | [diff] [blame] | 536 | // If cmd buffer is primary, track secondary command buffers pending execution |
| 537 | std::unordered_set<VkCommandBuffer> secondaryCommandBuffers; |
Tobin Ehlis | d239377 | 2016-01-29 11:50:47 -0700 | [diff] [blame] | 538 | vector<uint32_t> dynamicOffsets; // one dynamic offset per dynamic descriptor bound to this CB |
Tobin Ehlis | d01f7d6 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 539 | } GLOBAL_CB_NODE; |
Michael Lentine | abc5e92 | 2015-10-12 11:30:14 -0500 | [diff] [blame] | 540 | |
| 541 | typedef struct _SWAPCHAIN_NODE { |
Tobin Ehlis | 75cd1c5 | 2016-01-21 10:21:04 -0700 | [diff] [blame] | 542 | VkSwapchainCreateInfoKHR createInfo; |
| 543 | uint32_t* pQueueFamilyIndices; |
Michael Lentine | abc5e92 | 2015-10-12 11:30:14 -0500 | [diff] [blame] | 544 | std::vector<VkImage> images; |
Tobin Ehlis | 75cd1c5 | 2016-01-21 10:21:04 -0700 | [diff] [blame] | 545 | _SWAPCHAIN_NODE(const VkSwapchainCreateInfoKHR *pCreateInfo) : |
| 546 | createInfo(*pCreateInfo), |
| 547 | pQueueFamilyIndices(NULL) |
| 548 | { |
| 549 | if (pCreateInfo->queueFamilyIndexCount) { |
| 550 | pQueueFamilyIndices = new uint32_t[pCreateInfo->queueFamilyIndexCount]; |
| 551 | memcpy(pQueueFamilyIndices, pCreateInfo->pQueueFamilyIndices, pCreateInfo->queueFamilyIndexCount*sizeof(uint32_t)); |
| 552 | createInfo.pQueueFamilyIndices = pQueueFamilyIndices; |
| 553 | } |
| 554 | } |
| 555 | ~_SWAPCHAIN_NODE() |
| 556 | { |
| 557 | if (pQueueFamilyIndices) |
| 558 | delete pQueueFamilyIndices; |
| 559 | } |
Michael Lentine | abc5e92 | 2015-10-12 11:30:14 -0500 | [diff] [blame] | 560 | } SWAPCHAIN_NODE; |