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