| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include <vk_initializers.h> | ||
| 2 | |||
| 3 | VkCommandPoolCreateInfo vkinit::command_pool_create_info(uint32_t queueFamilyIndex, VkCommandPoolCreateFlags flags /*= 0*/) | ||
| 4 | { | ||
| 5 | ✗ | VkCommandPoolCreateInfo info = {}; | |
| 6 | ✗ | info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; | |
| 7 | ✗ | info.pNext = nullptr; | |
| 8 | |||
| 9 | ✗ | info.flags = flags; | |
| 10 | ✗ | return info; | |
| 11 | } | ||
| 12 | |||
| 13 | VkCommandBufferAllocateInfo vkinit::command_buffer_allocate_info(VkCommandPool pool, uint32_t count /*= 1*/, VkCommandBufferLevel level /*= VK_COMMAND_BUFFER_LEVEL_PRIMARY*/) | ||
| 14 | { | ||
| 15 | ✗ | VkCommandBufferAllocateInfo info = {}; | |
| 16 | ✗ | info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; | |
| 17 | ✗ | info.pNext = nullptr; | |
| 18 | |||
| 19 | ✗ | info.commandPool = pool; | |
| 20 | ✗ | info.commandBufferCount = count; | |
| 21 | ✗ | info.level = level; | |
| 22 | ✗ | return info; | |
| 23 | } | ||
| 24 | |||
| 25 | VkCommandBufferBeginInfo vkinit::command_buffer_begin_info(VkCommandBufferUsageFlags flags /*= 0*/) | ||
| 26 | { | ||
| 27 | ✗ | VkCommandBufferBeginInfo info = {}; | |
| 28 | ✗ | info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; | |
| 29 | ✗ | info.pNext = nullptr; | |
| 30 | |||
| 31 | ✗ | info.pInheritanceInfo = nullptr; | |
| 32 | ✗ | info.flags = flags; | |
| 33 | ✗ | return info; | |
| 34 | } | ||
| 35 | |||
| 36 | VkFramebufferCreateInfo vkinit::framebuffer_create_info(VkRenderPass renderPass, VkExtent2D extent) | ||
| 37 | { | ||
| 38 | ✗ | VkFramebufferCreateInfo info = {}; | |
| 39 | ✗ | info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; | |
| 40 | ✗ | info.pNext = nullptr; | |
| 41 | |||
| 42 | ✗ | info.renderPass = renderPass; | |
| 43 | ✗ | info.attachmentCount = 1; | |
| 44 | ✗ | info.width = extent.width; | |
| 45 | ✗ | info.height = extent.height; | |
| 46 | ✗ | info.layers = 1; | |
| 47 | |||
| 48 | ✗ | return info; | |
| 49 | } | ||
| 50 | |||
| 51 | VkFenceCreateInfo vkinit::fence_create_info(VkFenceCreateFlags flags /*= 0*/) | ||
| 52 | { | ||
| 53 | ✗ | VkFenceCreateInfo info = {}; | |
| 54 | ✗ | info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; | |
| 55 | ✗ | info.pNext = nullptr; | |
| 56 | |||
| 57 | ✗ | info.flags = flags; | |
| 58 | |||
| 59 | ✗ | return info; | |
| 60 | } | ||
| 61 | |||
| 62 | VkSemaphoreCreateInfo vkinit::semaphore_create_info(VkSemaphoreCreateFlags flags /*= 0*/) | ||
| 63 | { | ||
| 64 | ✗ | VkSemaphoreCreateInfo info = {}; | |
| 65 | ✗ | info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; | |
| 66 | ✗ | info.pNext = nullptr; | |
| 67 | ✗ | info.flags = flags; | |
| 68 | ✗ | return info; | |
| 69 | } | ||
| 70 | |||
| 71 | VkSubmitInfo vkinit::submit_info(VkCommandBuffer* cmd) | ||
| 72 | { | ||
| 73 | ✗ | VkSubmitInfo info = {}; | |
| 74 | ✗ | info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; | |
| 75 | ✗ | info.pNext = nullptr; | |
| 76 | |||
| 77 | ✗ | info.waitSemaphoreCount = 0; | |
| 78 | ✗ | info.pWaitSemaphores = nullptr; | |
| 79 | ✗ | info.pWaitDstStageMask = nullptr; | |
| 80 | ✗ | info.commandBufferCount = 1; | |
| 81 | ✗ | info.pCommandBuffers = cmd; | |
| 82 | ✗ | info.signalSemaphoreCount = 0; | |
| 83 | ✗ | info.pSignalSemaphores = nullptr; | |
| 84 | |||
| 85 | ✗ | return info; | |
| 86 | } | ||
| 87 | |||
| 88 | VkPresentInfoKHR vkinit::present_info() | ||
| 89 | { | ||
| 90 | ✗ | VkPresentInfoKHR info = {}; | |
| 91 | ✗ | info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; | |
| 92 | ✗ | info.pNext = nullptr; | |
| 93 | |||
| 94 | ✗ | info.swapchainCount = 0; | |
| 95 | ✗ | info.pSwapchains = nullptr; | |
| 96 | ✗ | info.pWaitSemaphores = nullptr; | |
| 97 | ✗ | info.waitSemaphoreCount = 0; | |
| 98 | ✗ | info.pImageIndices = nullptr; | |
| 99 | |||
| 100 | ✗ | return info; | |
| 101 | } | ||
| 102 | |||
| 103 | VkRenderPassBeginInfo vkinit::renderpass_begin_info(VkRenderPass renderPass, VkExtent2D windowExtent, VkFramebuffer framebuffer) | ||
| 104 | { | ||
| 105 | ✗ | VkRenderPassBeginInfo info = {}; | |
| 106 | ✗ | info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; | |
| 107 | ✗ | info.pNext = nullptr; | |
| 108 | |||
| 109 | ✗ | info.renderPass = renderPass; | |
| 110 | ✗ | info.renderArea.offset.x = 0; | |
| 111 | ✗ | info.renderArea.offset.y = 0; | |
| 112 | ✗ | info.renderArea.extent = windowExtent; | |
| 113 | ✗ | info.clearValueCount = 1; | |
| 114 | ✗ | info.pClearValues = nullptr; | |
| 115 | ✗ | info.framebuffer = framebuffer; | |
| 116 | |||
| 117 | ✗ | return info; | |
| 118 | } | ||
| 119 | |||
| 120 | VkPipelineShaderStageCreateInfo vkinit::pipeline_shader_stage_create_info(VkShaderStageFlagBits stage, VkShaderModule shaderModule) | ||
| 121 | { | ||
| 122 | ✗ | VkPipelineShaderStageCreateInfo info{}; | |
| 123 | ✗ | info.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; | |
| 124 | ✗ | info.pNext = nullptr; | |
| 125 | |||
| 126 | //shader stage | ||
| 127 | ✗ | info.stage = stage; | |
| 128 | //module containing the code for this shader stage | ||
| 129 | ✗ | info.module = shaderModule; | |
| 130 | //the entry point of the shader | ||
| 131 | ✗ | info.pName = "main"; | |
| 132 | ✗ | return info; | |
| 133 | } | ||
| 134 | VkPipelineVertexInputStateCreateInfo vkinit::vertex_input_state_create_info() { | ||
| 135 | ✗ | VkPipelineVertexInputStateCreateInfo info = {}; | |
| 136 | ✗ | info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; | |
| 137 | ✗ | info.pNext = nullptr; | |
| 138 | |||
| 139 | //no vertex bindings or attributes | ||
| 140 | ✗ | info.vertexBindingDescriptionCount = 0; | |
| 141 | ✗ | info.vertexAttributeDescriptionCount = 0; | |
| 142 | ✗ | return info; | |
| 143 | } | ||
| 144 | |||
| 145 | VkPipelineInputAssemblyStateCreateInfo vkinit::input_assembly_create_info(VkPrimitiveTopology topology) { | ||
| 146 | ✗ | VkPipelineInputAssemblyStateCreateInfo info = {}; | |
| 147 | ✗ | info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; | |
| 148 | ✗ | info.pNext = nullptr; | |
| 149 | |||
| 150 | ✗ | info.topology = topology; | |
| 151 | //we are not going to use primitive restart on the entire tutorial so leave it on false | ||
| 152 | ✗ | info.primitiveRestartEnable = VK_FALSE; | |
| 153 | ✗ | return info; | |
| 154 | } | ||
| 155 | VkPipelineRasterizationStateCreateInfo vkinit::rasterization_state_create_info(VkPolygonMode polygonMode) | ||
| 156 | { | ||
| 157 | ✗ | VkPipelineRasterizationStateCreateInfo info = {}; | |
| 158 | ✗ | info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; | |
| 159 | ✗ | info.pNext = nullptr; | |
| 160 | |||
| 161 | ✗ | info.depthClampEnable = VK_FALSE; | |
| 162 | //rasterizer discard allows objects with holes, default to no | ||
| 163 | ✗ | info.rasterizerDiscardEnable = VK_FALSE; | |
| 164 | |||
| 165 | ✗ | info.polygonMode = polygonMode; | |
| 166 | ✗ | info.lineWidth = 1.0f; | |
| 167 | //no backface cull | ||
| 168 | ✗ | info.cullMode = VK_CULL_MODE_NONE; | |
| 169 | ✗ | info.frontFace = VK_FRONT_FACE_CLOCKWISE; | |
| 170 | //no depth bias | ||
| 171 | ✗ | info.depthBiasEnable = VK_FALSE; | |
| 172 | ✗ | info.depthBiasConstantFactor = 0.0f; | |
| 173 | ✗ | info.depthBiasClamp = 0.0f; | |
| 174 | ✗ | info.depthBiasSlopeFactor = 0.0f; | |
| 175 | |||
| 176 | ✗ | return info; | |
| 177 | } | ||
| 178 | VkPipelineMultisampleStateCreateInfo vkinit::multisampling_state_create_info() | ||
| 179 | { | ||
| 180 | ✗ | VkPipelineMultisampleStateCreateInfo info = {}; | |
| 181 | ✗ | info.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; | |
| 182 | ✗ | info.pNext = nullptr; | |
| 183 | |||
| 184 | ✗ | info.sampleShadingEnable = VK_FALSE; | |
| 185 | //multisampling defaulted to no multisampling (1 sample per pixel) | ||
| 186 | ✗ | info.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; | |
| 187 | ✗ | info.minSampleShading = 1.0f; | |
| 188 | ✗ | info.pSampleMask = nullptr; | |
| 189 | ✗ | info.alphaToCoverageEnable = VK_FALSE; | |
| 190 | ✗ | info.alphaToOneEnable = VK_FALSE; | |
| 191 | ✗ | return info; | |
| 192 | } | ||
| 193 | VkPipelineColorBlendAttachmentState vkinit::color_blend_attachment_state() { | ||
| 194 | ✗ | VkPipelineColorBlendAttachmentState colorBlendAttachment = {}; | |
| 195 | ✗ | colorBlendAttachment.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | | |
| 196 | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; | ||
| 197 | ✗ | colorBlendAttachment.blendEnable = VK_FALSE; | |
| 198 | ✗ | return colorBlendAttachment; | |
| 199 | } | ||
| 200 | VkPipelineLayoutCreateInfo vkinit::pipeline_layout_create_info() { | ||
| 201 | ✗ | VkPipelineLayoutCreateInfo info{}; | |
| 202 | ✗ | info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; | |
| 203 | ✗ | info.pNext = nullptr; | |
| 204 | |||
| 205 | //empty defaults | ||
| 206 | ✗ | info.flags = 0; | |
| 207 | ✗ | info.setLayoutCount = 0; | |
| 208 | ✗ | info.pSetLayouts = nullptr; | |
| 209 | ✗ | info.pushConstantRangeCount = 0; | |
| 210 | ✗ | info.pPushConstantRanges = nullptr; | |
| 211 | ✗ | return info; | |
| 212 | } | ||
| 213 | |||
| 214 | VkImageCreateInfo vkinit::image_create_info(VkFormat format, VkImageUsageFlags usageFlags, VkExtent3D extent) | ||
| 215 | { | ||
| 216 | ✗ | VkImageCreateInfo info = { }; | |
| 217 | ✗ | info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; | |
| 218 | ✗ | info.pNext = nullptr; | |
| 219 | |||
| 220 | ✗ | info.imageType = VK_IMAGE_TYPE_2D; | |
| 221 | |||
| 222 | ✗ | info.format = format; | |
| 223 | ✗ | info.extent = extent; | |
| 224 | |||
| 225 | ✗ | info.mipLevels = 1; | |
| 226 | ✗ | info.arrayLayers = 1; | |
| 227 | ✗ | info.samples = VK_SAMPLE_COUNT_1_BIT; | |
| 228 | ✗ | info.tiling = VK_IMAGE_TILING_OPTIMAL; | |
| 229 | ✗ | info.usage = usageFlags; | |
| 230 | |||
| 231 | ✗ | return info; | |
| 232 | } | ||
| 233 | |||
| 234 | VkImageViewCreateInfo vkinit::imageview_create_info(VkFormat format, VkImage image, VkImageAspectFlags aspectFlags) | ||
| 235 | { | ||
| 236 | //build a image-view for the depth image to use for rendering | ||
| 237 | ✗ | VkImageViewCreateInfo info = {}; | |
| 238 | ✗ | info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; | |
| 239 | ✗ | info.pNext = nullptr; | |
| 240 | |||
| 241 | ✗ | info.viewType = VK_IMAGE_VIEW_TYPE_2D; | |
| 242 | ✗ | info.image = image; | |
| 243 | ✗ | info.format = format; | |
| 244 | ✗ | info.subresourceRange.baseMipLevel = 0; | |
| 245 | ✗ | info.subresourceRange.levelCount = 1; | |
| 246 | ✗ | info.subresourceRange.baseArrayLayer = 0; | |
| 247 | ✗ | info.subresourceRange.layerCount = 1; | |
| 248 | ✗ | info.subresourceRange.aspectMask = aspectFlags; | |
| 249 | |||
| 250 | ✗ | return info; | |
| 251 | } | ||
| 252 | |||
| 253 | VkPipelineDepthStencilStateCreateInfo vkinit::depth_stencil_create_info(bool bDepthTest, bool bDepthWrite, VkCompareOp compareOp) | ||
| 254 | { | ||
| 255 | ✗ | VkPipelineDepthStencilStateCreateInfo info = {}; | |
| 256 | ✗ | info.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; | |
| 257 | ✗ | info.pNext = nullptr; | |
| 258 | |||
| 259 | ✗ | info.depthTestEnable = bDepthTest ? VK_TRUE : VK_FALSE; | |
| 260 | ✗ | info.depthWriteEnable = bDepthWrite ? VK_TRUE : VK_FALSE; | |
| 261 | ✗ | info.depthCompareOp = bDepthTest ? compareOp : VK_COMPARE_OP_ALWAYS; | |
| 262 | ✗ | info.depthBoundsTestEnable = VK_FALSE; | |
| 263 | ✗ | info.minDepthBounds = 0.0f; // Optional | |
| 264 | ✗ | info.maxDepthBounds = 1.0f; // Optional | |
| 265 | ✗ | info.stencilTestEnable = VK_FALSE; | |
| 266 | |||
| 267 | ✗ | return info; | |
| 268 | } | ||
| 269 | |||
| 270 | VkDescriptorSetLayoutBinding vkinit::descriptorset_layout_binding(VkDescriptorType type, VkShaderStageFlags stageFlags, uint32_t binding) | ||
| 271 | { | ||
| 272 | ✗ | VkDescriptorSetLayoutBinding setbind = {}; | |
| 273 | ✗ | setbind.binding = binding; | |
| 274 | ✗ | setbind.descriptorCount = 1; | |
| 275 | ✗ | setbind.descriptorType = type; | |
| 276 | ✗ | setbind.pImmutableSamplers = nullptr; | |
| 277 | ✗ | setbind.stageFlags = stageFlags; | |
| 278 | |||
| 279 | ✗ | return setbind; | |
| 280 | } | ||
| 281 | VkWriteDescriptorSet vkinit::write_descriptor_buffer(VkDescriptorType type, VkDescriptorSet dstSet, VkDescriptorBufferInfo* bufferInfo , uint32_t binding) | ||
| 282 | { | ||
| 283 | ✗ | VkWriteDescriptorSet write = {}; | |
| 284 | ✗ | write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; | |
| 285 | ✗ | write.pNext = nullptr; | |
| 286 | |||
| 287 | ✗ | write.dstBinding = binding; | |
| 288 | ✗ | write.dstSet = dstSet; | |
| 289 | ✗ | write.descriptorCount = 1; | |
| 290 | ✗ | write.descriptorType = type; | |
| 291 | ✗ | write.pBufferInfo = bufferInfo; | |
| 292 | |||
| 293 | ✗ | return write; | |
| 294 | } | ||
| 295 | |||
| 296 | VkWriteDescriptorSet vkinit::write_descriptor_image(VkDescriptorType type, VkDescriptorSet dstSet, VkDescriptorImageInfo* imageInfo, uint32_t binding) | ||
| 297 | { | ||
| 298 | ✗ | VkWriteDescriptorSet write = {}; | |
| 299 | ✗ | write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; | |
| 300 | ✗ | write.pNext = nullptr; | |
| 301 | |||
| 302 | ✗ | write.dstBinding = binding; | |
| 303 | ✗ | write.dstSet = dstSet; | |
| 304 | ✗ | write.descriptorCount = 1; | |
| 305 | ✗ | write.descriptorType = type; | |
| 306 | ✗ | write.pImageInfo = imageInfo; | |
| 307 | |||
| 308 | ✗ | return write; | |
| 309 | } | ||
| 310 | |||
| 311 | VkSamplerCreateInfo vkinit::sampler_create_info(VkFilter filters, VkSamplerAddressMode samplerAdressMode /*= VK_SAMPLER_ADDRESS_MODE_REPEAT*/) | ||
| 312 | { | ||
| 313 | ✗ | VkSamplerCreateInfo info = {}; | |
| 314 | ✗ | info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; | |
| 315 | ✗ | info.pNext = nullptr; | |
| 316 | |||
| 317 | ✗ | info.magFilter = filters; | |
| 318 | ✗ | info.minFilter = filters; | |
| 319 | ✗ | info.addressModeU = samplerAdressMode; | |
| 320 | ✗ | info.addressModeV = samplerAdressMode; | |
| 321 | ✗ | info.addressModeW = samplerAdressMode; | |
| 322 | |||
| 323 | ✗ | return info; | |
| 324 | } | ||
| 325 |