Tobin Ehlis | 246ba4d | 2014-11-18 16:38:08 -0700 | [diff] [blame] | 1 | /* |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2 | * Vulkan |
Tobin Ehlis | 246ba4d | 2014-11-18 16:38:08 -0700 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2014 LunarG, Inc. |
| 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. |
| 23 | */ |
Tobin Ehlis | 0c6f9ee | 2015-07-03 09:42:57 -0600 | [diff] [blame] | 24 | #include "vk_layer.h" |
Tobin Ehlis | 10ae8c1 | 2015-03-17 16:24:32 -0600 | [diff] [blame] | 25 | #include <vector> |
Tobin Ehlis | b212dfc | 2015-10-07 15:40:22 -0600 | [diff] [blame] | 26 | #include <memory> |
Courtney Goeltzenleuchter | 319db13 | 2015-09-23 12:30:48 -0600 | [diff] [blame] | 27 | #include "vk_debug_report_lunarg.h" |
Tobin Ehlis | 10ae8c1 | 2015-03-17 16:24:32 -0600 | [diff] [blame] | 28 | |
| 29 | using namespace std; |
| 30 | |
Tobin Ehlis | 246ba4d | 2014-11-18 16:38:08 -0700 | [diff] [blame] | 31 | // Draw State ERROR codes |
| 32 | typedef enum _DRAW_STATE_ERROR |
| 33 | { |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 34 | DRAWSTATE_NONE, // Used for INFO & other non-error messages |
Tobin Ehlis | 04178d7 | 2015-01-22 10:45:21 -0700 | [diff] [blame] | 35 | DRAWSTATE_INTERNAL_ERROR, // Error with DrawState internal data structures |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 36 | DRAWSTATE_NO_PIPELINE_BOUND, // Unable to identify a bound pipeline |
Tobin Ehlis | 793ad30 | 2015-04-03 12:01:11 -0600 | [diff] [blame] | 37 | DRAWSTATE_INVALID_POOL, // Invalid DS pool |
Tobin Ehlis | a3a693e | 2015-02-10 15:35:23 -0700 | [diff] [blame] | 38 | DRAWSTATE_INVALID_SET, // Invalid DS |
Tobin Ehlis | 04178d7 | 2015-01-22 10:45:21 -0700 | [diff] [blame] | 39 | DRAWSTATE_INVALID_LAYOUT, // Invalid DS layout |
Tobin Ehlis | 75283bf | 2015-06-18 15:59:33 -0600 | [diff] [blame] | 40 | DRAWSTATE_INVALID_PIPELINE, // Invalid Pipeline handle referenced |
| 41 | DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, // Attempt to create a pipeline with invalid state |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 42 | DRAWSTATE_INVALID_COMMAND_BUFFER, // Invalid CommandBuffer referenced |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 43 | 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] | 44 | 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] | 45 | //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] | 46 | DRAWSTATE_OUT_OF_MEMORY, // malloc failed |
| 47 | 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] | 48 | 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] | 49 | 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] | 50 | 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] | 51 | 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] | 52 | 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] | 53 | 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] | 54 | 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] | 55 | DRAWSTATE_NO_END_COMMAND_BUFFER, // Must call vkEndCommandBuffer() before QueueSubmit on that commandBuffer |
| 56 | DRAWSTATE_NO_BEGIN_COMMAND_BUFFER, // Binding cmds or calling End on CB that never had vkBeginCommandBuffer() called on it |
| 57 | DRAWSTATE_COMMAND_BUFFER_SINGLE_SUBMIT_VIOLATION, // Cmd Buffer created with VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT flag is submitted multiple times |
| 58 | 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] | 59 | DRAWSTATE_VIEWPORT_NOT_BOUND, // Draw submitted with no viewport state bound |
| 60 | DRAWSTATE_SCISSOR_NOT_BOUND, // Draw submitted with no scissor state bound |
| 61 | DRAWSTATE_LINE_WIDTH_NOT_BOUND, // Draw submitted with no line width state bound |
| 62 | DRAWSTATE_DEPTH_BIAS_NOT_BOUND, // Draw submitted with no depth bias state bound |
| 63 | DRAWSTATE_BLEND_NOT_BOUND, // Draw submitted with no blend state bound when color write enabled |
| 64 | DRAWSTATE_DEPTH_BOUNDS_NOT_BOUND, // Draw submitted with no depth bounds state bound when depth enabled |
| 65 | DRAWSTATE_STENCIL_NOT_BOUND, // Draw submitted with no stencil state bound when stencil enabled |
| 66 | DRAWSTATE_INDEX_BUFFER_NOT_BOUND, // Draw submitted with no depth-stencil state bound when depth write enabled |
Tobin Ehlis | 429b91d | 2015-06-22 17:20:50 -0600 | [diff] [blame] | 67 | DRAWSTATE_PIPELINE_LAYOUT_MISMATCH, // Draw submitted PSO Pipeline layout that doesn't match layout from BindDescriptorSets |
Tobin Ehlis | 259730a | 2015-06-23 16:13:03 -0600 | [diff] [blame] | 68 | DRAWSTATE_INVALID_RENDERPASS, // Use of a NULL or otherwise invalid RenderPass object |
Tobin Ehlis | d1fe4ec | 2015-06-23 11:22:55 -0600 | [diff] [blame] | 69 | DRAWSTATE_INVALID_RENDERPASS_CMD, // Invalid cmd submitted while a RenderPass is active |
| 70 | DRAWSTATE_NO_ACTIVE_RENDERPASS, // Rendering cmd submitted without an active RenderPass |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 71 | DRAWSTATE_DESCRIPTOR_SET_NOT_UPDATED, // DescriptorSet bound but it was never updated. This is a warning code. |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 72 | DRAWSTATE_CLEAR_CMD_BEFORE_DRAW, // Clear cmd issued before any Draw in CommandBuffer, should use RenderPass Ops instead |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 73 | DRAWSTATE_BEGIN_CB_INVALID_STATE, // Primary/Secondary CB created with mismatched FB/RP information |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 74 | 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] | 75 | DRAWSTATE_INVALID_IMAGE_ASPECT, // Image aspect is invalid for the current operation |
Mark Lobodzinski | 13ec6b0 | 2015-10-16 09:17:27 -0600 | [diff] [blame] | 76 | DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, // Attachment reference must be present in active subpass |
Tobin Ehlis | 75283bf | 2015-06-18 15:59:33 -0600 | [diff] [blame] | 77 | DRAWSTATE_INVALID_EXTENSION, |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 78 | 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] | 79 | 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] | 80 | DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, // A Descriptor of *_IMAGE or *_ATTACHMENT type is being updated with an invalid or bad ImageView |
| 81 | DRAWSTATE_BUFFERVIEW_DESCRIPTOR_ERROR, // A Descriptor of *_TEXEL_BUFFER type is being updated with an invalid or bad BufferView |
| 82 | DRAWSTATE_BUFFERINFO_DESCRIPTOR_ERROR, // A Descriptor of *_[UNIFORM|STORAGE]_BUFFER_[DYNAMIC] type is being updated with an invalid or bad BufferView |
Tobin Ehlis | 246ba4d | 2014-11-18 16:38:08 -0700 | [diff] [blame] | 83 | } DRAW_STATE_ERROR; |
Tobin Ehlis | 5742e77 | 2014-11-20 09:49:17 -0700 | [diff] [blame] | 84 | |
| 85 | typedef enum _DRAW_TYPE |
| 86 | { |
| 87 | DRAW = 0, |
| 88 | DRAW_INDEXED = 1, |
| 89 | DRAW_INDIRECT = 2, |
| 90 | DRAW_INDEXED_INDIRECT = 3, |
| 91 | DRAW_BEGIN_RANGE = DRAW, |
| 92 | DRAW_END_RANGE = DRAW_INDEXED_INDIRECT, |
| 93 | NUM_DRAW_TYPES = (DRAW_END_RANGE - DRAW_BEGIN_RANGE + 1), |
| 94 | } DRAW_TYPE; |
Tobin Ehlis | 8356288 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 95 | |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 96 | typedef struct _SHADER_DS_MAPPING { |
| 97 | uint32_t slotCount; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 98 | VkDescriptorSetLayoutCreateInfo* pShaderMappingSlot; |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 99 | } SHADER_DS_MAPPING; |
| 100 | |
Tobin Ehlis | 04178d7 | 2015-01-22 10:45:21 -0700 | [diff] [blame] | 101 | typedef struct _GENERIC_HEADER { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 102 | VkStructureType sType; |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 103 | const void* pNext; |
Tobin Ehlis | 04178d7 | 2015-01-22 10:45:21 -0700 | [diff] [blame] | 104 | } GENERIC_HEADER; |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 105 | |
| 106 | typedef struct _PIPELINE_NODE { |
Tony Barbour | dd6e32e | 2015-07-10 15:29:03 -0600 | [diff] [blame] | 107 | VkPipeline pipeline; |
| 108 | VkGraphicsPipelineCreateInfo graphicsPipelineCI; |
| 109 | VkPipelineVertexInputStateCreateInfo vertexInputCI; |
| 110 | VkPipelineInputAssemblyStateCreateInfo iaStateCI; |
| 111 | VkPipelineTessellationStateCreateInfo tessStateCI; |
| 112 | VkPipelineViewportStateCreateInfo vpStateCI; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 113 | VkPipelineRasterizationStateCreateInfo rsStateCI; |
Tony Barbour | dd6e32e | 2015-07-10 15:29:03 -0600 | [diff] [blame] | 114 | VkPipelineMultisampleStateCreateInfo msStateCI; |
| 115 | VkPipelineColorBlendStateCreateInfo cbStateCI; |
| 116 | VkPipelineDepthStencilStateCreateInfo dsStateCI; |
Tobin Ehlis | 963a404 | 2015-09-29 08:18:34 -0600 | [diff] [blame] | 117 | VkPipelineDynamicStateCreateInfo dynStateCI; |
Tony Barbour | dd6e32e | 2015-07-10 15:29:03 -0600 | [diff] [blame] | 118 | VkPipelineShaderStageCreateInfo vsCI; |
| 119 | VkPipelineShaderStageCreateInfo tcsCI; |
| 120 | VkPipelineShaderStageCreateInfo tesCI; |
| 121 | VkPipelineShaderStageCreateInfo gsCI; |
| 122 | VkPipelineShaderStageCreateInfo fsCI; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 123 | // Compute shader is include in VkComputePipelineCreateInfo |
Mark Lobodzinski | d5732f3 | 2015-06-23 15:11:57 -0600 | [diff] [blame] | 124 | VkComputePipelineCreateInfo computePipelineCI; |
Tobin Ehlis | a85167d | 2015-06-18 11:02:59 -0600 | [diff] [blame] | 125 | // Flag of which shader stages are active for this pipeline |
Mark Lobodzinski | d5732f3 | 2015-06-23 15:11:57 -0600 | [diff] [blame] | 126 | uint32_t active_shaders; |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 127 | // Vtx input info (if any) |
Mark Lobodzinski | d5732f3 | 2015-06-23 15:11:57 -0600 | [diff] [blame] | 128 | uint32_t vtxBindingCount; // number of bindings |
| 129 | VkVertexInputBindingDescription* pVertexBindingDescriptions; |
| 130 | uint32_t vtxAttributeCount; // number of attributes |
| 131 | VkVertexInputAttributeDescription* pVertexAttributeDescriptions; |
| 132 | uint32_t attachmentCount; // number of CB attachments |
Tony Barbour | dd6e32e | 2015-07-10 15:29:03 -0600 | [diff] [blame] | 133 | VkPipelineColorBlendAttachmentState* pAttachments; |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 134 | } PIPELINE_NODE; |
| 135 | |
| 136 | typedef struct _SAMPLER_NODE { |
Tobin Ehlis | ce132d8 | 2015-06-19 15:07:05 -0600 | [diff] [blame] | 137 | VkSampler sampler; |
| 138 | VkSamplerCreateInfo createInfo; |
Tobin Ehlis | b212dfc | 2015-10-07 15:40:22 -0600 | [diff] [blame] | 139 | |
| 140 | _SAMPLER_NODE(const VkSampler* ps, const VkSamplerCreateInfo* pci) : sampler(*ps), createInfo(*pci) {}; |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 141 | } SAMPLER_NODE; |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 142 | // Descriptor Data structures |
Tobin Ehlis | 04178d7 | 2015-01-22 10:45:21 -0700 | [diff] [blame] | 143 | // Layout Node has the core layout data |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 144 | typedef struct _LAYOUT_NODE { |
Tobin Ehlis | ce132d8 | 2015-06-19 15:07:05 -0600 | [diff] [blame] | 145 | VkDescriptorSetLayout layout; |
Tobin Ehlis | ce132d8 | 2015-06-19 15:07:05 -0600 | [diff] [blame] | 146 | VkDescriptorSetLayoutCreateInfo createInfo; |
| 147 | uint32_t startIndex; // 1st index of this layout |
| 148 | uint32_t endIndex; // last index of this layout |
Tobin Ehlis | 644ff04 | 2015-10-20 10:11:55 -0600 | [diff] [blame] | 149 | 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] | 150 | vector<VkShaderStageFlags> stageFlags; // stageFlags per descriptor in this layout to verify correct updates |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 151 | } LAYOUT_NODE; |
Tobin Ehlis | 644ff04 | 2015-10-20 10:11:55 -0600 | [diff] [blame] | 152 | // Store layouts and pushconstants for PipelineLayout |
| 153 | struct PIPELINE_LAYOUT_NODE { |
| 154 | vector<VkDescriptorSetLayout> descriptorSetLayouts; |
| 155 | vector<VkPushConstantRange> pushConstantRanges; |
| 156 | }; |
| 157 | |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 158 | typedef struct _SET_NODE { |
Tobin Ehlis | ce132d8 | 2015-06-19 15:07:05 -0600 | [diff] [blame] | 159 | VkDescriptorSet set; |
| 160 | VkDescriptorPool pool; |
Tobin Ehlis | 481ec71 | 2015-02-19 09:55:18 -0700 | [diff] [blame] | 161 | // Head of LL of all Update structs for this set |
Tobin Ehlis | ce132d8 | 2015-06-19 15:07:05 -0600 | [diff] [blame] | 162 | GENERIC_HEADER* pUpdateStructs; |
Tobin Ehlis | 04178d7 | 2015-01-22 10:45:21 -0700 | [diff] [blame] | 163 | // 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] | 164 | uint32_t descriptorCount; |
| 165 | GENERIC_HEADER** ppDescriptors; // Array where each index points to update node for its slot |
| 166 | LAYOUT_NODE* pLayout; // Layout for this set |
| 167 | struct _SET_NODE* pNext; |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 168 | } SET_NODE; |
| 169 | |
Tobin Ehlis | 793ad30 | 2015-04-03 12:01:11 -0600 | [diff] [blame] | 170 | typedef struct _POOL_NODE { |
Tobin Ehlis | ce132d8 | 2015-06-19 15:07:05 -0600 | [diff] [blame] | 171 | VkDescriptorPool pool; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 172 | uint32_t maxSets; |
Tobin Ehlis | ce132d8 | 2015-06-19 15:07:05 -0600 | [diff] [blame] | 173 | VkDescriptorPoolCreateInfo createInfo; |
| 174 | SET_NODE* pSets; // Head of LL of sets for this Pool |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 175 | vector<uint32_t> maxDescriptorTypeCount; // max # of descriptors of each type in this pool |
| 176 | vector<uint32_t> availableDescriptorTypeCount; // available # of descriptors of each type in this pool |
| 177 | |
| 178 | _POOL_NODE(const VkDescriptorPool pool, const VkDescriptorPoolCreateInfo* pCreateInfo) : |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 179 | pool(pool), createInfo(*pCreateInfo), maxSets(pCreateInfo->maxSets), pSets(NULL), |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 180 | maxDescriptorTypeCount(VK_DESCRIPTOR_TYPE_END_RANGE), availableDescriptorTypeCount(VK_DESCRIPTOR_TYPE_END_RANGE) |
| 181 | { |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 182 | if (createInfo.typeCount) { // Shadow type struct from ptr into local struct |
| 183 | size_t typeCountSize = createInfo.typeCount * sizeof(VkDescriptorTypeCount); |
| 184 | createInfo.pTypeCounts = new VkDescriptorTypeCount[typeCountSize]; |
| 185 | memcpy((void*)createInfo.pTypeCounts, pCreateInfo->pTypeCounts, typeCountSize); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 186 | // Now set max counts for each descriptor type based on count of that type times maxSets |
| 187 | int32_t i=0; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 188 | for (i=0; i<createInfo.typeCount; ++i) { |
| 189 | uint32_t typeIndex = static_cast<uint32_t>(createInfo.pTypeCounts[i].type); |
| 190 | uint32_t typeCount = createInfo.pTypeCounts[i].descriptorCount; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 191 | maxDescriptorTypeCount[typeIndex] += typeCount; |
| 192 | } |
| 193 | for (i=0; i<maxDescriptorTypeCount.size(); ++i) { |
| 194 | maxDescriptorTypeCount[i] *= createInfo.maxSets; |
| 195 | // Initially the available counts are equal to the max counts |
| 196 | availableDescriptorTypeCount[i] = maxDescriptorTypeCount[i]; |
| 197 | } |
| 198 | } else { |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 199 | createInfo.pTypeCounts = 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] | 200 | } |
| 201 | } |
| 202 | ~_POOL_NODE() { |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 203 | if (createInfo.pTypeCounts) { |
| 204 | delete[] createInfo.pTypeCounts; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 205 | } |
| 206 | // TODO : pSets are currently freed in deletePools function which uses freeShadowUpdateTree function |
| 207 | // need to migrate that struct to smart ptrs for auto-cleanup |
| 208 | } |
Tobin Ehlis | 793ad30 | 2015-04-03 12:01:11 -0600 | [diff] [blame] | 209 | } POOL_NODE; |
Tobin Ehlis | 7265e83 | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 210 | |
Tobin Ehlis | d01f7d6 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 211 | // Cmd Buffer Tracking |
| 212 | typedef enum _CMD_TYPE |
| 213 | { |
| 214 | CMD_BINDPIPELINE, |
| 215 | CMD_BINDPIPELINEDELTA, |
Courtney Goeltzenleuchter | 49c7308 | 2015-09-17 15:06:17 -0600 | [diff] [blame] | 216 | CMD_SETVIEWPORTSTATE, |
Courtney Goeltzenleuchter | 078f817 | 2015-09-21 11:44:06 -0600 | [diff] [blame] | 217 | CMD_SETSCISSORSTATE, |
Courtney Goeltzenleuchter | 49c7308 | 2015-09-17 15:06:17 -0600 | [diff] [blame] | 218 | CMD_SETLINEWIDTHSTATE, |
| 219 | CMD_SETDEPTHBIASSTATE, |
| 220 | CMD_SETBLENDSTATE, |
| 221 | CMD_SETDEPTHBOUNDSSTATE, |
| 222 | CMD_SETSTENCILREADMASKSTATE, |
| 223 | CMD_SETSTENCILWRITEMASKSTATE, |
| 224 | CMD_SETSTENCILREFERENCESTATE, |
Tobin Ehlis | 793ad30 | 2015-04-03 12:01:11 -0600 | [diff] [blame] | 225 | CMD_BINDDESCRIPTORSETS, |
Tobin Ehlis | d01f7d6 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 226 | CMD_BINDINDEXBUFFER, |
| 227 | CMD_BINDVERTEXBUFFER, |
| 228 | CMD_DRAW, |
| 229 | CMD_DRAWINDEXED, |
| 230 | CMD_DRAWINDIRECT, |
| 231 | CMD_DRAWINDEXEDINDIRECT, |
| 232 | CMD_DISPATCH, |
| 233 | CMD_DISPATCHINDIRECT, |
| 234 | CMD_COPYBUFFER, |
| 235 | CMD_COPYIMAGE, |
Tobin Ehlis | 793ad30 | 2015-04-03 12:01:11 -0600 | [diff] [blame] | 236 | CMD_BLITIMAGE, |
Tobin Ehlis | d01f7d6 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 237 | CMD_COPYBUFFERTOIMAGE, |
| 238 | CMD_COPYIMAGETOBUFFER, |
| 239 | CMD_CLONEIMAGEDATA, |
| 240 | CMD_UPDATEBUFFER, |
| 241 | CMD_FILLBUFFER, |
| 242 | CMD_CLEARCOLORIMAGE, |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 243 | CMD_CLEARATTACHMENTS, |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 244 | CMD_CLEARDEPTHSTENCILIMAGE, |
Tobin Ehlis | d01f7d6 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 245 | CMD_RESOLVEIMAGE, |
| 246 | CMD_SETEVENT, |
| 247 | CMD_RESETEVENT, |
| 248 | CMD_WAITEVENTS, |
| 249 | CMD_PIPELINEBARRIER, |
| 250 | CMD_BEGINQUERY, |
| 251 | CMD_ENDQUERY, |
| 252 | CMD_RESETQUERYPOOL, |
Mark Lobodzinski | 5495d13 | 2015-09-30 16:19:16 -0600 | [diff] [blame] | 253 | CMD_COPYQUERYPOOLRESULTS, |
Tobin Ehlis | d01f7d6 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 254 | CMD_WRITETIMESTAMP, |
| 255 | CMD_INITATOMICCOUNTERS, |
| 256 | CMD_LOADATOMICCOUNTERS, |
| 257 | CMD_SAVEATOMICCOUNTERS, |
| 258 | CMD_BEGINRENDERPASS, |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 259 | CMD_NEXTSUBPASS, |
Tobin Ehlis | 6744942 | 2015-03-02 10:16:40 -0700 | [diff] [blame] | 260 | CMD_ENDRENDERPASS, |
Chia-I Wu | 0b50a1c | 2015-06-26 15:34:39 +0800 | [diff] [blame] | 261 | CMD_EXECUTECOMMANDS, |
Tobin Ehlis | 6744942 | 2015-03-02 10:16:40 -0700 | [diff] [blame] | 262 | CMD_DBGMARKERBEGIN, |
| 263 | CMD_DBGMARKEREND, |
Tobin Ehlis | d01f7d6 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 264 | } CMD_TYPE; |
| 265 | // Data structure for holding sequence of cmds in cmd buffer |
| 266 | typedef struct _CMD_NODE { |
Tobin Ehlis | d01f7d6 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 267 | CMD_TYPE type; |
| 268 | uint64_t cmdNumber; |
| 269 | } CMD_NODE; |
| 270 | |
| 271 | typedef enum _CB_STATE |
| 272 | { |
| 273 | CB_NEW, // Newly created CB w/o any cmds |
| 274 | CB_UPDATE_ACTIVE, // BeginCB has been called on this CB |
| 275 | CB_UPDATE_COMPLETE // EndCB has been called on this CB |
| 276 | } CB_STATE; |
Tobin Ehlis | e382c5a | 2015-06-10 12:57:07 -0600 | [diff] [blame] | 277 | // CB Status -- used to track status of various bindings on cmd buffer objects |
| 278 | typedef VkFlags CBStatusFlags; |
| 279 | typedef enum _CBStatusFlagBits |
| 280 | { |
| 281 | CBSTATUS_NONE = 0x00000000, // No status is set |
Courtney Goeltzenleuchter | 49c7308 | 2015-09-17 15:06:17 -0600 | [diff] [blame] | 282 | CBSTATUS_VIEWPORT_SET = 0x00000001, // Viewport has been set |
| 283 | CBSTATUS_LINE_WIDTH_SET = 0x00000002, // Line width has been set |
| 284 | CBSTATUS_DEPTH_BIAS_SET = 0x00000004, // Depth bias has been set |
| 285 | CBSTATUS_COLOR_BLEND_WRITE_ENABLE = 0x00000008, // PSO w/ CB Enable set has been set |
| 286 | CBSTATUS_BLEND_SET = 0x00000010, // Blend state object has been set |
| 287 | CBSTATUS_DEPTH_WRITE_ENABLE = 0x00000020, // PSO w/ Depth Enable set has been set |
| 288 | CBSTATUS_STENCIL_TEST_ENABLE = 0x00000040, // PSO w/ Stencil Enable set has been set |
| 289 | CBSTATUS_DEPTH_BOUNDS_SET = 0x00000080, // Depth bounds state object has been set |
| 290 | CBSTATUS_STENCIL_READ_MASK_SET = 0x00000100, // Stencil read mask has been set |
| 291 | CBSTATUS_STENCIL_WRITE_MASK_SET = 0x00000200, // Stencil write mask has been set |
| 292 | CBSTATUS_STENCIL_REFERENCE_SET = 0x00000400, // Stencil reference has been set |
| 293 | CBSTATUS_INDEX_BUFFER_BOUND = 0x00000800, // Index buffer has been set |
Courtney Goeltzenleuchter | 078f817 | 2015-09-21 11:44:06 -0600 | [diff] [blame] | 294 | CBSTATUS_SCISSOR_SET = 0x00001000, // Scissor has been set |
Tobin Ehlis | 5e5a1e9 | 2015-10-01 09:24:40 -0600 | [diff] [blame] | 295 | CBSTATUS_ALL = 0x00001FFF, // All dynamic state set |
Tobin Ehlis | e382c5a | 2015-06-10 12:57:07 -0600 | [diff] [blame] | 296 | } CBStatusFlagBits; |
Tobin Ehlis | 60a9b4f | 2015-07-07 10:42:20 -0600 | [diff] [blame] | 297 | |
Courtney Goeltzenleuchter | 49c7308 | 2015-09-17 15:06:17 -0600 | [diff] [blame] | 298 | typedef struct stencil_data { |
| 299 | uint32_t stencilCompareMask; |
| 300 | uint32_t stencilWriteMask; |
| 301 | uint32_t stencilReference; |
| 302 | } CBStencilData; |
| 303 | |
Tobin Ehlis | 10ae8c1 | 2015-03-17 16:24:32 -0600 | [diff] [blame] | 304 | // Cmd Buffer Wrapper Struct |
Tobin Ehlis | d01f7d6 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 305 | typedef struct _GLOBAL_CB_NODE { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 306 | VkCommandBuffer commandBuffer; |
| 307 | VkCommandBufferAllocateInfo createInfo; |
| 308 | VkCommandBufferBeginInfo beginInfo; |
Tobin Ehlis | a9f3d76 | 2015-05-22 12:38:16 -0600 | [diff] [blame] | 309 | VkFence fence; // fence tracking this cmd buffer |
| 310 | uint64_t numCmds; // number of cmds in this CB |
| 311 | 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] | 312 | CB_STATE state; // Track cmd buffer update state |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 313 | uint64_t submitCount; // Number of times CB has been submitted |
Tobin Ehlis | e382c5a | 2015-06-10 12:57:07 -0600 | [diff] [blame] | 314 | CBStatusFlags status; // Track status of various bindings on cmd buffer |
Tobin Ehlis | a9f3d76 | 2015-05-22 12:38:16 -0600 | [diff] [blame] | 315 | vector<CMD_NODE*> pCmds; |
Tobin Ehlis | d01f7d6 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 316 | // Currently storing "lastBound" objects on per-CB basis |
| 317 | // long-term may want to create caches of "lastBound" states and could have |
| 318 | // each individual CMD_NODE referencing its own "lastBound" state |
Tobin Ehlis | a9f3d76 | 2015-05-22 12:38:16 -0600 | [diff] [blame] | 319 | VkPipeline lastBoundPipeline; |
| 320 | uint32_t lastVtxBinding; |
Courtney Goeltzenleuchter | 49c7308 | 2015-09-17 15:06:17 -0600 | [diff] [blame] | 321 | vector<VkViewport> viewports; |
| 322 | vector<VkRect2D> scissors; |
| 323 | float lineWidth; |
Chia-I Wu | d8c946a | 2015-10-26 19:08:09 +0800 | [diff] [blame] | 324 | float depthBiasConstantFactor; |
Courtney Goeltzenleuchter | 49c7308 | 2015-09-17 15:06:17 -0600 | [diff] [blame] | 325 | float depthBiasClamp; |
Chia-I Wu | d8c946a | 2015-10-26 19:08:09 +0800 | [diff] [blame] | 326 | float depthBiasSlopeFactor; |
Chia-I Wu | 2bfb33c | 2015-10-26 17:24:52 +0800 | [diff] [blame] | 327 | float blendConstants[4]; |
Courtney Goeltzenleuchter | 49c7308 | 2015-09-17 15:06:17 -0600 | [diff] [blame] | 328 | float minDepthBounds; |
| 329 | float maxDepthBounds; |
| 330 | CBStencilData front; |
| 331 | CBStencilData back; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 332 | VkDescriptorSet lastBoundDescriptorSet; |
Tobin Ehlis | 429b91d | 2015-06-22 17:20:50 -0600 | [diff] [blame] | 333 | VkPipelineLayout lastBoundPipelineLayout; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 334 | VkRenderPass activeRenderPass; |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 335 | uint32_t activeSubpass; |
Tobin Ehlis | a9f3d76 | 2015-05-22 12:38:16 -0600 | [diff] [blame] | 336 | VkFramebuffer framebuffer; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 337 | VkCommandBufferLevel level; |
Tobin Ehlis | a9f3d76 | 2015-05-22 12:38:16 -0600 | [diff] [blame] | 338 | vector<VkDescriptorSet> boundDescriptorSets; |
Tobin Ehlis | d01f7d6 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 339 | } GLOBAL_CB_NODE; |