Tobin Ehlis | e79df94 | 2014-11-18 16:38:08 -0700 | [diff] [blame] | 1 | /* |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2 | * Vulkan |
Tobin Ehlis | e79df94 | 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 | 2d1d970 | 2015-07-03 09:42:57 -0600 | [diff] [blame] | 24 | #include "vk_layer.h" |
Tobin Ehlis | 63bb948 | 2015-03-17 16:24:32 -0600 | [diff] [blame] | 25 | #include <vector> |
Tobin Ehlis | d04ccab | 2015-10-07 15:40:22 -0600 | [diff] [blame] | 26 | #include <memory> |
Courtney Goeltzenleuchter | d4d26dd | 2015-09-23 12:30:48 -0600 | [diff] [blame] | 27 | #include "vk_debug_report_lunarg.h" |
Tobin Ehlis | 63bb948 | 2015-03-17 16:24:32 -0600 | [diff] [blame] | 28 | |
| 29 | using namespace std; |
| 30 | |
Tobin Ehlis | e79df94 | 2014-11-18 16:38:08 -0700 | [diff] [blame] | 31 | // Draw State ERROR codes |
| 32 | typedef enum _DRAW_STATE_ERROR |
| 33 | { |
Tobin Ehlis | 84c521c | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 34 | DRAWSTATE_NONE, // Used for INFO & other non-error messages |
Tobin Ehlis | 41415bb | 2015-01-22 10:45:21 -0700 | [diff] [blame] | 35 | DRAWSTATE_INTERNAL_ERROR, // Error with DrawState internal data structures |
Tobin Ehlis | 84c521c | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 36 | DRAWSTATE_NO_PIPELINE_BOUND, // Unable to identify a bound pipeline |
Tobin Ehlis | dd82f6b | 2015-04-03 12:01:11 -0600 | [diff] [blame] | 37 | DRAWSTATE_INVALID_POOL, // Invalid DS pool |
Tobin Ehlis | 83ebbef | 2015-02-10 15:35:23 -0700 | [diff] [blame] | 38 | DRAWSTATE_INVALID_SET, // Invalid DS |
Tobin Ehlis | 41415bb | 2015-01-22 10:45:21 -0700 | [diff] [blame] | 39 | DRAWSTATE_INVALID_LAYOUT, // Invalid DS layout |
Tobin Ehlis | de63c53 | 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 |
Tobin Ehlis | 8cced21 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 42 | DRAWSTATE_INVALID_CMD_BUFFER, // Invalid CmdBuffer referenced |
Courtney Goeltzenleuchter | 9cc421e | 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 | 8d199e5 | 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 | 236717c | 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 | 41415bb | 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 | 83ebbef | 2015-02-10 15:35:23 -0700 | [diff] [blame] | 48 | DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, // Descriptors set for update out of bounds for corresponding layout section |
Tobin Ehlis | c6457d2 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 49 | DRAWSTATE_DESCRIPTOR_POOL_EMPTY, // Attempt to allocate descriptor from a pool with no more descriptors of that type available |
Tobin Ehlis | 3c54311 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 50 | DRAWSTATE_CANT_FREE_FROM_ONE_SHOT_POOL, // Invalid to call vkFreeDescriptorSets on Sets allocated from a ONE_SHOT Pool |
Tobin Ehlis | 8733adc | 2015-02-23 16:09:58 -0700 | [diff] [blame] | 51 | DRAWSTATE_INVALID_UPDATE_INDEX, // Index of requested update is invalid for specified descriptors set |
Tobin Ehlis | 2464b88 | 2015-04-01 08:40:34 -0600 | [diff] [blame] | 52 | DRAWSTATE_INVALID_UPDATE_STRUCT, // Struct in DS Update tree is of invalid type |
Tobin Ehlis | 28be0be | 2015-05-22 12:38:16 -0600 | [diff] [blame] | 53 | DRAWSTATE_NUM_SAMPLES_MISMATCH, // Number of samples in bound PSO does not match number in FB of current RenderPass |
| 54 | DRAWSTATE_NO_END_CMD_BUFFER, // Must call vkEndCommandBuffer() before QueueSubmit on that cmdBuffer |
Tobin Ehlis | e42007c | 2015-06-19 13:00:59 -0600 | [diff] [blame] | 55 | DRAWSTATE_NO_BEGIN_CMD_BUFFER, // Binding cmds or calling End on CB that never had vkBeginCommandBuffer() called on it |
Courtney Goeltzenleuchter | a32436b | 2015-10-21 18:11:04 -0600 | [diff] [blame^] | 56 | DRAWSTATE_CMD_BUFFER_SINGLE_SUBMIT_VIOLATION, // Cmd Buffer created with VK_CMD_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT flag is submitted multiple times |
Tobin Ehlis | 5f728d3 | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 57 | DRAWSTATE_INVALID_SECONDARY_CMD_BUFFER, // vkCmdExecuteCommands() called with a primary cmdBuffer in pCmdBuffers array |
Tobin Ehlis | f6cb467 | 2015-09-29 08:18:34 -0600 | [diff] [blame] | 58 | DRAWSTATE_VIEWPORT_NOT_BOUND, // Draw submitted with no viewport state bound |
| 59 | DRAWSTATE_SCISSOR_NOT_BOUND, // Draw submitted with no scissor state bound |
| 60 | DRAWSTATE_LINE_WIDTH_NOT_BOUND, // Draw submitted with no line width state bound |
| 61 | DRAWSTATE_DEPTH_BIAS_NOT_BOUND, // Draw submitted with no depth bias state bound |
| 62 | DRAWSTATE_BLEND_NOT_BOUND, // Draw submitted with no blend state bound when color write enabled |
| 63 | DRAWSTATE_DEPTH_BOUNDS_NOT_BOUND, // Draw submitted with no depth bounds state bound when depth enabled |
| 64 | DRAWSTATE_STENCIL_NOT_BOUND, // Draw submitted with no stencil state bound when stencil enabled |
| 65 | DRAWSTATE_INDEX_BUFFER_NOT_BOUND, // Draw submitted with no depth-stencil state bound when depth write enabled |
Tobin Ehlis | c6c3d6d | 2015-06-22 17:20:50 -0600 | [diff] [blame] | 66 | DRAWSTATE_PIPELINE_LAYOUT_MISMATCH, // Draw submitted PSO Pipeline layout that doesn't match layout from BindDescriptorSets |
Tobin Ehlis | 8b6c235 | 2015-06-23 16:13:03 -0600 | [diff] [blame] | 67 | DRAWSTATE_INVALID_RENDERPASS, // Use of a NULL or otherwise invalid RenderPass object |
Tobin Ehlis | 451efca | 2015-06-23 11:22:55 -0600 | [diff] [blame] | 68 | DRAWSTATE_INVALID_RENDERPASS_CMD, // Invalid cmd submitted while a RenderPass is active |
| 69 | DRAWSTATE_NO_ACTIVE_RENDERPASS, // Rendering cmd submitted without an active RenderPass |
Tobin Ehlis | e407678 | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 70 | DRAWSTATE_DESCRIPTOR_SET_NOT_UPDATED, // DescriptorSet bound but it was never updated. This is a warning code. |
Tobin Ehlis | 8cd650e | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 71 | DRAWSTATE_CLEAR_CMD_BEFORE_DRAW, // Clear cmd issued before any Draw in CmdBuffer, should use RenderPass Ops instead |
Mark Lobodzinski | 90bf5b0 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 72 | DRAWSTATE_BEGIN_CB_INVALID_STATE, // Primary/Secondary CB created with mismatched FB/RP information |
Tobin Ehlis | 9e839e5 | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 73 | DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, // Count for viewports and scissors mismatch and/or state doesn't match count |
Mark Lobodzinski | f14c845 | 2015-10-16 13:32:24 -0600 | [diff] [blame] | 74 | DRAWSTATE_INVALID_IMAGE_ASPECT, // Image aspect is invalid for the current operation |
Mark Lobodzinski | 50bc2cc | 2015-10-16 09:17:27 -0600 | [diff] [blame] | 75 | DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, // Attachment reference must be present in active subpass |
Tobin Ehlis | de63c53 | 2015-06-18 15:59:33 -0600 | [diff] [blame] | 76 | DRAWSTATE_INVALID_EXTENSION, |
Tobin Ehlis | e79df94 | 2014-11-18 16:38:08 -0700 | [diff] [blame] | 77 | } DRAW_STATE_ERROR; |
Tobin Ehlis | 2609202 | 2014-11-20 09:49:17 -0700 | [diff] [blame] | 78 | |
| 79 | typedef enum _DRAW_TYPE |
| 80 | { |
| 81 | DRAW = 0, |
| 82 | DRAW_INDEXED = 1, |
| 83 | DRAW_INDIRECT = 2, |
| 84 | DRAW_INDEXED_INDIRECT = 3, |
| 85 | DRAW_BEGIN_RANGE = DRAW, |
| 86 | DRAW_END_RANGE = DRAW_INDEXED_INDIRECT, |
| 87 | NUM_DRAW_TYPES = (DRAW_END_RANGE - DRAW_BEGIN_RANGE + 1), |
| 88 | } DRAW_TYPE; |
Tobin Ehlis | a701ef0 | 2014-11-27 15:43:39 -0700 | [diff] [blame] | 89 | |
Tobin Ehlis | 84c521c | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 90 | typedef struct _SHADER_DS_MAPPING { |
| 91 | uint32_t slotCount; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 92 | VkDescriptorSetLayoutCreateInfo* pShaderMappingSlot; |
Tobin Ehlis | 84c521c | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 93 | } SHADER_DS_MAPPING; |
| 94 | |
Tobin Ehlis | 41415bb | 2015-01-22 10:45:21 -0700 | [diff] [blame] | 95 | typedef struct _GENERIC_HEADER { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 96 | VkStructureType sType; |
Tobin Ehlis | 84c521c | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 97 | const void* pNext; |
Tobin Ehlis | 41415bb | 2015-01-22 10:45:21 -0700 | [diff] [blame] | 98 | } GENERIC_HEADER; |
Tobin Ehlis | 84c521c | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 99 | |
| 100 | typedef struct _PIPELINE_NODE { |
Tony Barbour | e307f58 | 2015-07-10 15:29:03 -0600 | [diff] [blame] | 101 | VkPipeline pipeline; |
| 102 | VkGraphicsPipelineCreateInfo graphicsPipelineCI; |
| 103 | VkPipelineVertexInputStateCreateInfo vertexInputCI; |
| 104 | VkPipelineInputAssemblyStateCreateInfo iaStateCI; |
| 105 | VkPipelineTessellationStateCreateInfo tessStateCI; |
| 106 | VkPipelineViewportStateCreateInfo vpStateCI; |
| 107 | VkPipelineRasterStateCreateInfo rsStateCI; |
| 108 | VkPipelineMultisampleStateCreateInfo msStateCI; |
| 109 | VkPipelineColorBlendStateCreateInfo cbStateCI; |
| 110 | VkPipelineDepthStencilStateCreateInfo dsStateCI; |
Tobin Ehlis | f6cb467 | 2015-09-29 08:18:34 -0600 | [diff] [blame] | 111 | VkPipelineDynamicStateCreateInfo dynStateCI; |
Tony Barbour | e307f58 | 2015-07-10 15:29:03 -0600 | [diff] [blame] | 112 | VkPipelineShaderStageCreateInfo vsCI; |
| 113 | VkPipelineShaderStageCreateInfo tcsCI; |
| 114 | VkPipelineShaderStageCreateInfo tesCI; |
| 115 | VkPipelineShaderStageCreateInfo gsCI; |
| 116 | VkPipelineShaderStageCreateInfo fsCI; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 117 | // Compute shader is include in VkComputePipelineCreateInfo |
Mark Lobodzinski | 0e0fb5c | 2015-06-23 15:11:57 -0600 | [diff] [blame] | 118 | VkComputePipelineCreateInfo computePipelineCI; |
Tobin Ehlis | 806a97a | 2015-06-18 11:02:59 -0600 | [diff] [blame] | 119 | // Flag of which shader stages are active for this pipeline |
Mark Lobodzinski | 0e0fb5c | 2015-06-23 15:11:57 -0600 | [diff] [blame] | 120 | uint32_t active_shaders; |
Tobin Ehlis | 84c521c | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 121 | // Vtx input info (if any) |
Mark Lobodzinski | 0e0fb5c | 2015-06-23 15:11:57 -0600 | [diff] [blame] | 122 | uint32_t vtxBindingCount; // number of bindings |
| 123 | VkVertexInputBindingDescription* pVertexBindingDescriptions; |
| 124 | uint32_t vtxAttributeCount; // number of attributes |
| 125 | VkVertexInputAttributeDescription* pVertexAttributeDescriptions; |
| 126 | uint32_t attachmentCount; // number of CB attachments |
Tony Barbour | e307f58 | 2015-07-10 15:29:03 -0600 | [diff] [blame] | 127 | VkPipelineColorBlendAttachmentState* pAttachments; |
Tobin Ehlis | 84c521c | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 128 | } PIPELINE_NODE; |
| 129 | |
| 130 | typedef struct _SAMPLER_NODE { |
Tobin Ehlis | a366ca2 | 2015-06-19 15:07:05 -0600 | [diff] [blame] | 131 | VkSampler sampler; |
| 132 | VkSamplerCreateInfo createInfo; |
Tobin Ehlis | d04ccab | 2015-10-07 15:40:22 -0600 | [diff] [blame] | 133 | |
| 134 | _SAMPLER_NODE(const VkSampler* ps, const VkSamplerCreateInfo* pci) : sampler(*ps), createInfo(*pci) {}; |
Tobin Ehlis | 84c521c | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 135 | } SAMPLER_NODE; |
| 136 | |
Tobin Ehlis | 41415bb | 2015-01-22 10:45:21 -0700 | [diff] [blame] | 137 | typedef struct _BUFFER_NODE { |
Tobin Ehlis | a366ca2 | 2015-06-19 15:07:05 -0600 | [diff] [blame] | 138 | VkBufferView buffer; |
Courtney Goeltzenleuchter | ddcb619 | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 139 | VkBufferViewCreateInfo createInfo; |
Tobin Ehlis | d04ccab | 2015-10-07 15:40:22 -0600 | [diff] [blame] | 140 | |
| 141 | _BUFFER_NODE(const VkBufferView* pbv, const VkBufferViewCreateInfo* pci) : buffer(*pbv), createInfo(*pci) {}; |
Tobin Ehlis | 41415bb | 2015-01-22 10:45:21 -0700 | [diff] [blame] | 142 | } BUFFER_NODE; |
| 143 | |
Tobin Ehlis | 84c521c | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 144 | // Descriptor Data structures |
Tobin Ehlis | 41415bb | 2015-01-22 10:45:21 -0700 | [diff] [blame] | 145 | // Layout Node has the core layout data |
Tobin Ehlis | 84c521c | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 146 | typedef struct _LAYOUT_NODE { |
Tobin Ehlis | a366ca2 | 2015-06-19 15:07:05 -0600 | [diff] [blame] | 147 | VkDescriptorSetLayout layout; |
Tobin Ehlis | a366ca2 | 2015-06-19 15:07:05 -0600 | [diff] [blame] | 148 | VkDescriptorSetLayoutCreateInfo createInfo; |
| 149 | uint32_t startIndex; // 1st index of this layout |
| 150 | uint32_t endIndex; // last index of this layout |
Tobin Ehlis | 91423d2 | 2015-10-20 10:11:55 -0600 | [diff] [blame] | 151 | vector<VkDescriptorType> descriptorTypes; // Type per descriptor in this layout to verify correct updates |
Tobin Ehlis | 84c521c | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 152 | } LAYOUT_NODE; |
Tobin Ehlis | 91423d2 | 2015-10-20 10:11:55 -0600 | [diff] [blame] | 153 | // Store layouts and pushconstants for PipelineLayout |
| 154 | struct PIPELINE_LAYOUT_NODE { |
| 155 | vector<VkDescriptorSetLayout> descriptorSetLayouts; |
| 156 | vector<VkPushConstantRange> pushConstantRanges; |
| 157 | }; |
| 158 | |
Tobin Ehlis | 84c521c | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 159 | typedef struct _SET_NODE { |
Tobin Ehlis | a366ca2 | 2015-06-19 15:07:05 -0600 | [diff] [blame] | 160 | VkDescriptorSet set; |
| 161 | VkDescriptorPool pool; |
| 162 | VkDescriptorSetUsage setUsage; |
Tobin Ehlis | 82871a8 | 2015-02-19 09:55:18 -0700 | [diff] [blame] | 163 | // Head of LL of all Update structs for this set |
Tobin Ehlis | a366ca2 | 2015-06-19 15:07:05 -0600 | [diff] [blame] | 164 | GENERIC_HEADER* pUpdateStructs; |
Tobin Ehlis | 41415bb | 2015-01-22 10:45:21 -0700 | [diff] [blame] | 165 | // Total num of descriptors in this set (count of its layout plus all prior layouts) |
Tobin Ehlis | a366ca2 | 2015-06-19 15:07:05 -0600 | [diff] [blame] | 166 | uint32_t descriptorCount; |
| 167 | GENERIC_HEADER** ppDescriptors; // Array where each index points to update node for its slot |
| 168 | LAYOUT_NODE* pLayout; // Layout for this set |
| 169 | struct _SET_NODE* pNext; |
Tobin Ehlis | 84c521c | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 170 | } SET_NODE; |
| 171 | |
Tobin Ehlis | dd82f6b | 2015-04-03 12:01:11 -0600 | [diff] [blame] | 172 | typedef struct _POOL_NODE { |
Tobin Ehlis | a366ca2 | 2015-06-19 15:07:05 -0600 | [diff] [blame] | 173 | VkDescriptorPool pool; |
Tobin Ehlis | a366ca2 | 2015-06-19 15:07:05 -0600 | [diff] [blame] | 174 | VkDescriptorPoolCreateInfo createInfo; |
| 175 | SET_NODE* pSets; // Head of LL of sets for this Pool |
Tobin Ehlis | c6457d2 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 176 | vector<uint32_t> maxDescriptorTypeCount; // max # of descriptors of each type in this pool |
| 177 | vector<uint32_t> availableDescriptorTypeCount; // available # of descriptors of each type in this pool |
| 178 | |
| 179 | _POOL_NODE(const VkDescriptorPool pool, const VkDescriptorPoolCreateInfo* pCreateInfo) : |
| 180 | pool(pool), createInfo(*pCreateInfo), pSets(NULL), |
| 181 | maxDescriptorTypeCount(VK_DESCRIPTOR_TYPE_END_RANGE), availableDescriptorTypeCount(VK_DESCRIPTOR_TYPE_END_RANGE) |
| 182 | { |
| 183 | if (createInfo.count) { // Shadow type struct from ptr into local struct |
| 184 | size_t typeCountSize = createInfo.count * sizeof(VkDescriptorTypeCount); |
| 185 | createInfo.pTypeCount = new VkDescriptorTypeCount[typeCountSize]; |
| 186 | memcpy((void*)createInfo.pTypeCount, pCreateInfo->pTypeCount, typeCountSize); |
| 187 | // Now set max counts for each descriptor type based on count of that type times maxSets |
| 188 | int32_t i=0; |
| 189 | for (i=0; i<createInfo.count; ++i) { |
| 190 | uint32_t typeIndex = static_cast<uint32_t>(createInfo.pTypeCount[i].type); |
| 191 | uint32_t typeCount = createInfo.pTypeCount[i].count; |
| 192 | maxDescriptorTypeCount[typeIndex] += typeCount; |
| 193 | } |
| 194 | for (i=0; i<maxDescriptorTypeCount.size(); ++i) { |
| 195 | maxDescriptorTypeCount[i] *= createInfo.maxSets; |
| 196 | // Initially the available counts are equal to the max counts |
| 197 | availableDescriptorTypeCount[i] = maxDescriptorTypeCount[i]; |
| 198 | } |
| 199 | } else { |
| 200 | createInfo.pTypeCount = NULL; // Make sure this is NULL so we don't try to clean it up |
| 201 | } |
| 202 | } |
| 203 | ~_POOL_NODE() { |
| 204 | if (createInfo.pTypeCount) { |
| 205 | delete[] createInfo.pTypeCount; |
| 206 | } |
| 207 | // TODO : pSets are currently freed in deletePools function which uses freeShadowUpdateTree function |
| 208 | // need to migrate that struct to smart ptrs for auto-cleanup |
| 209 | } |
Tobin Ehlis | dd82f6b | 2015-04-03 12:01:11 -0600 | [diff] [blame] | 210 | } POOL_NODE; |
Tobin Ehlis | 84c521c | 2015-01-19 08:42:29 -0700 | [diff] [blame] | 211 | |
Tobin Ehlis | 8cced21 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 212 | // Cmd Buffer Tracking |
| 213 | typedef enum _CMD_TYPE |
| 214 | { |
| 215 | CMD_BINDPIPELINE, |
| 216 | CMD_BINDPIPELINEDELTA, |
Courtney Goeltzenleuchter | 09772bb | 2015-09-17 15:06:17 -0600 | [diff] [blame] | 217 | CMD_SETVIEWPORTSTATE, |
Courtney Goeltzenleuchter | 932cdb5 | 2015-09-21 11:44:06 -0600 | [diff] [blame] | 218 | CMD_SETSCISSORSTATE, |
Courtney Goeltzenleuchter | 09772bb | 2015-09-17 15:06:17 -0600 | [diff] [blame] | 219 | CMD_SETLINEWIDTHSTATE, |
| 220 | CMD_SETDEPTHBIASSTATE, |
| 221 | CMD_SETBLENDSTATE, |
| 222 | CMD_SETDEPTHBOUNDSSTATE, |
| 223 | CMD_SETSTENCILREADMASKSTATE, |
| 224 | CMD_SETSTENCILWRITEMASKSTATE, |
| 225 | CMD_SETSTENCILREFERENCESTATE, |
Tobin Ehlis | dd82f6b | 2015-04-03 12:01:11 -0600 | [diff] [blame] | 226 | CMD_BINDDESCRIPTORSETS, |
Tobin Ehlis | 8cced21 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 227 | CMD_BINDINDEXBUFFER, |
| 228 | CMD_BINDVERTEXBUFFER, |
| 229 | CMD_DRAW, |
| 230 | CMD_DRAWINDEXED, |
| 231 | CMD_DRAWINDIRECT, |
| 232 | CMD_DRAWINDEXEDINDIRECT, |
| 233 | CMD_DISPATCH, |
| 234 | CMD_DISPATCHINDIRECT, |
| 235 | CMD_COPYBUFFER, |
| 236 | CMD_COPYIMAGE, |
Tobin Ehlis | dd82f6b | 2015-04-03 12:01:11 -0600 | [diff] [blame] | 237 | CMD_BLITIMAGE, |
Tobin Ehlis | 8cced21 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 238 | CMD_COPYBUFFERTOIMAGE, |
| 239 | CMD_COPYIMAGETOBUFFER, |
| 240 | CMD_CLONEIMAGEDATA, |
| 241 | CMD_UPDATEBUFFER, |
| 242 | CMD_FILLBUFFER, |
| 243 | CMD_CLEARCOLORIMAGE, |
Courtney Goeltzenleuchter | 9feb073 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 244 | CMD_CLEARATTACHMENTS, |
Tobin Ehlis | 8cd650e | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 245 | CMD_CLEARDEPTHSTENCILIMAGE, |
Tobin Ehlis | 8cced21 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 246 | CMD_RESOLVEIMAGE, |
| 247 | CMD_SETEVENT, |
| 248 | CMD_RESETEVENT, |
| 249 | CMD_WAITEVENTS, |
| 250 | CMD_PIPELINEBARRIER, |
| 251 | CMD_BEGINQUERY, |
| 252 | CMD_ENDQUERY, |
| 253 | CMD_RESETQUERYPOOL, |
Mark Lobodzinski | a0f061c | 2015-09-30 16:19:16 -0600 | [diff] [blame] | 254 | CMD_COPYQUERYPOOLRESULTS, |
Tobin Ehlis | 8cced21 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 255 | CMD_WRITETIMESTAMP, |
| 256 | CMD_INITATOMICCOUNTERS, |
| 257 | CMD_LOADATOMICCOUNTERS, |
| 258 | CMD_SAVEATOMICCOUNTERS, |
| 259 | CMD_BEGINRENDERPASS, |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 260 | CMD_NEXTSUBPASS, |
Tobin Ehlis | 1dae99a | 2015-03-02 10:16:40 -0700 | [diff] [blame] | 261 | CMD_ENDRENDERPASS, |
Chia-I Wu | 88eaa3b | 2015-06-26 15:34:39 +0800 | [diff] [blame] | 262 | CMD_EXECUTECOMMANDS, |
Tobin Ehlis | 1dae99a | 2015-03-02 10:16:40 -0700 | [diff] [blame] | 263 | CMD_DBGMARKERBEGIN, |
| 264 | CMD_DBGMARKEREND, |
Tobin Ehlis | 8cced21 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 265 | } CMD_TYPE; |
| 266 | // Data structure for holding sequence of cmds in cmd buffer |
| 267 | typedef struct _CMD_NODE { |
Tobin Ehlis | 8cced21 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 268 | CMD_TYPE type; |
| 269 | uint64_t cmdNumber; |
| 270 | } CMD_NODE; |
| 271 | |
| 272 | typedef enum _CB_STATE |
| 273 | { |
| 274 | CB_NEW, // Newly created CB w/o any cmds |
| 275 | CB_UPDATE_ACTIVE, // BeginCB has been called on this CB |
| 276 | CB_UPDATE_COMPLETE // EndCB has been called on this CB |
| 277 | } CB_STATE; |
Tobin Ehlis | 9786620 | 2015-06-10 12:57:07 -0600 | [diff] [blame] | 278 | // CB Status -- used to track status of various bindings on cmd buffer objects |
| 279 | typedef VkFlags CBStatusFlags; |
| 280 | typedef enum _CBStatusFlagBits |
| 281 | { |
| 282 | CBSTATUS_NONE = 0x00000000, // No status is set |
Courtney Goeltzenleuchter | 09772bb | 2015-09-17 15:06:17 -0600 | [diff] [blame] | 283 | CBSTATUS_VIEWPORT_SET = 0x00000001, // Viewport has been set |
| 284 | CBSTATUS_LINE_WIDTH_SET = 0x00000002, // Line width has been set |
| 285 | CBSTATUS_DEPTH_BIAS_SET = 0x00000004, // Depth bias has been set |
| 286 | CBSTATUS_COLOR_BLEND_WRITE_ENABLE = 0x00000008, // PSO w/ CB Enable set has been set |
| 287 | CBSTATUS_BLEND_SET = 0x00000010, // Blend state object has been set |
| 288 | CBSTATUS_DEPTH_WRITE_ENABLE = 0x00000020, // PSO w/ Depth Enable set has been set |
| 289 | CBSTATUS_STENCIL_TEST_ENABLE = 0x00000040, // PSO w/ Stencil Enable set has been set |
| 290 | CBSTATUS_DEPTH_BOUNDS_SET = 0x00000080, // Depth bounds state object has been set |
| 291 | CBSTATUS_STENCIL_READ_MASK_SET = 0x00000100, // Stencil read mask has been set |
| 292 | CBSTATUS_STENCIL_WRITE_MASK_SET = 0x00000200, // Stencil write mask has been set |
| 293 | CBSTATUS_STENCIL_REFERENCE_SET = 0x00000400, // Stencil reference has been set |
| 294 | CBSTATUS_INDEX_BUFFER_BOUND = 0x00000800, // Index buffer has been set |
Courtney Goeltzenleuchter | 932cdb5 | 2015-09-21 11:44:06 -0600 | [diff] [blame] | 295 | CBSTATUS_SCISSOR_SET = 0x00001000, // Scissor has been set |
Tobin Ehlis | 3dec46c | 2015-10-01 09:24:40 -0600 | [diff] [blame] | 296 | CBSTATUS_ALL = 0x00001FFF, // All dynamic state set |
Tobin Ehlis | 9786620 | 2015-06-10 12:57:07 -0600 | [diff] [blame] | 297 | } CBStatusFlagBits; |
Tobin Ehlis | 1dce5f1 | 2015-07-07 10:42:20 -0600 | [diff] [blame] | 298 | |
Courtney Goeltzenleuchter | 09772bb | 2015-09-17 15:06:17 -0600 | [diff] [blame] | 299 | typedef struct stencil_data { |
| 300 | uint32_t stencilCompareMask; |
| 301 | uint32_t stencilWriteMask; |
| 302 | uint32_t stencilReference; |
| 303 | } CBStencilData; |
| 304 | |
Tobin Ehlis | 63bb948 | 2015-03-17 16:24:32 -0600 | [diff] [blame] | 305 | // Cmd Buffer Wrapper Struct |
Tobin Ehlis | 8cced21 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 306 | typedef struct _GLOBAL_CB_NODE { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 307 | VkCmdBuffer cmdBuffer; |
Tobin Ehlis | 0cea408 | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 308 | VkCmdBufferCreateInfo createInfo; |
| 309 | VkCmdBufferBeginInfo beginInfo; |
Tobin Ehlis | 28be0be | 2015-05-22 12:38:16 -0600 | [diff] [blame] | 310 | VkFence fence; // fence tracking this cmd buffer |
| 311 | uint64_t numCmds; // number of cmds in this CB |
| 312 | uint64_t drawCount[NUM_DRAW_TYPES]; // Count of each type of draw in this CB |
Tobin Ehlis | 9786620 | 2015-06-10 12:57:07 -0600 | [diff] [blame] | 313 | CB_STATE state; // Track cmd buffer update state |
Tobin Ehlis | 0cea408 | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 314 | uint64_t submitCount; // Number of times CB has been submitted |
Tobin Ehlis | 9786620 | 2015-06-10 12:57:07 -0600 | [diff] [blame] | 315 | CBStatusFlags status; // Track status of various bindings on cmd buffer |
Tobin Ehlis | 28be0be | 2015-05-22 12:38:16 -0600 | [diff] [blame] | 316 | vector<CMD_NODE*> pCmds; |
Tobin Ehlis | 8cced21 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 317 | // Currently storing "lastBound" objects on per-CB basis |
| 318 | // long-term may want to create caches of "lastBound" states and could have |
| 319 | // each individual CMD_NODE referencing its own "lastBound" state |
Tobin Ehlis | 28be0be | 2015-05-22 12:38:16 -0600 | [diff] [blame] | 320 | VkPipeline lastBoundPipeline; |
| 321 | uint32_t lastVtxBinding; |
Courtney Goeltzenleuchter | 09772bb | 2015-09-17 15:06:17 -0600 | [diff] [blame] | 322 | vector<VkViewport> viewports; |
| 323 | vector<VkRect2D> scissors; |
| 324 | float lineWidth; |
| 325 | float depthBias; |
| 326 | float depthBiasClamp; |
| 327 | float slopeScaledDepthBias; |
| 328 | float blendConst[4]; |
| 329 | float minDepthBounds; |
| 330 | float maxDepthBounds; |
| 331 | CBStencilData front; |
| 332 | CBStencilData back; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 333 | VkDescriptorSet lastBoundDescriptorSet; |
Tobin Ehlis | c6c3d6d | 2015-06-22 17:20:50 -0600 | [diff] [blame] | 334 | VkPipelineLayout lastBoundPipelineLayout; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 335 | VkRenderPass activeRenderPass; |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 336 | uint32_t activeSubpass; |
Tobin Ehlis | 28be0be | 2015-05-22 12:38:16 -0600 | [diff] [blame] | 337 | VkFramebuffer framebuffer; |
Mark Lobodzinski | 90bf5b0 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 338 | VkCmdBufferLevel level; |
Tobin Ehlis | 28be0be | 2015-05-22 12:38:16 -0600 | [diff] [blame] | 339 | vector<VkDescriptorSet> boundDescriptorSets; |
Tobin Ehlis | 8cced21 | 2015-02-13 10:26:14 -0700 | [diff] [blame] | 340 | } GLOBAL_CB_NODE; |