diff --git a/Makefile b/Makefile index 8af4f4753..6b8d37e38 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ build_shaders: $(SCMP) -V shaders/glsl/computeheadless.comp -o shaders/glsl/computeheadless.comp.spv format: - $(CF) -i -style="{BasedOnStyle: mozilla, IndentWidth: 4}" src/*.cpp src/*.h src/*.hpp + $(CF) -i -style="{BasedOnStyle: mozilla, IndentWidth: 4, ContinuationIndentWidth: 8}" src/*.cpp src/*.h src/*.hpp clean: rm ./bin/main.exe; diff --git a/src/VulkanInitializers.hpp b/src/VulkanInitializers.hpp index aca24ed2f..a663eba57 100644 --- a/src/VulkanInitializers.hpp +++ b/src/VulkanInitializers.hpp @@ -11,63 +11,78 @@ #pragma once -#include #include "vulkan/vulkan.h" +#include namespace vks { namespace initializers { -inline VkMemoryAllocateInfo memoryAllocateInfo() { +inline VkMemoryAllocateInfo +memoryAllocateInfo() +{ VkMemoryAllocateInfo memAllocInfo{}; memAllocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; return memAllocInfo; } -inline VkMappedMemoryRange mappedMemoryRange() { +inline VkMappedMemoryRange +mappedMemoryRange() +{ VkMappedMemoryRange mappedMemoryRange{}; mappedMemoryRange.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE; return mappedMemoryRange; } -inline VkCommandBufferAllocateInfo commandBufferAllocateInfo( - VkCommandPool commandPool, - VkCommandBufferLevel level, - uint32_t bufferCount) { +inline VkCommandBufferAllocateInfo +commandBufferAllocateInfo(VkCommandPool commandPool, + VkCommandBufferLevel level, + uint32_t bufferCount) +{ VkCommandBufferAllocateInfo commandBufferAllocateInfo{}; commandBufferAllocateInfo.sType = - VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; + VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; commandBufferAllocateInfo.commandPool = commandPool; commandBufferAllocateInfo.level = level; commandBufferAllocateInfo.commandBufferCount = bufferCount; return commandBufferAllocateInfo; } -inline VkCommandPoolCreateInfo commandPoolCreateInfo() { +inline VkCommandPoolCreateInfo +commandPoolCreateInfo() +{ VkCommandPoolCreateInfo cmdPoolCreateInfo{}; cmdPoolCreateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; return cmdPoolCreateInfo; } -inline VkCommandBufferBeginInfo commandBufferBeginInfo() { +inline VkCommandBufferBeginInfo +commandBufferBeginInfo() +{ VkCommandBufferBeginInfo cmdBufferBeginInfo{}; cmdBufferBeginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; return cmdBufferBeginInfo; } -inline VkCommandBufferInheritanceInfo commandBufferInheritanceInfo() { +inline VkCommandBufferInheritanceInfo +commandBufferInheritanceInfo() +{ VkCommandBufferInheritanceInfo cmdBufferInheritanceInfo{}; cmdBufferInheritanceInfo.sType = - VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO; + VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO; return cmdBufferInheritanceInfo; } -inline VkRenderPassBeginInfo renderPassBeginInfo() { +inline VkRenderPassBeginInfo +renderPassBeginInfo() +{ VkRenderPassBeginInfo renderPassBeginInfo{}; renderPassBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; return renderPassBeginInfo; } -inline VkRenderPassCreateInfo renderPassCreateInfo() { +inline VkRenderPassCreateInfo +renderPassCreateInfo() +{ VkRenderPassCreateInfo renderPassCreateInfo{}; renderPassCreateInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; return renderPassCreateInfo; @@ -75,7 +90,9 @@ inline VkRenderPassCreateInfo renderPassCreateInfo() { /** @brief Initialize an image memory barrier with no image transfer ownership */ -inline VkImageMemoryBarrier imageMemoryBarrier() { +inline VkImageMemoryBarrier +imageMemoryBarrier() +{ VkImageMemoryBarrier imageMemoryBarrier{}; imageMemoryBarrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; imageMemoryBarrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; @@ -85,7 +102,9 @@ inline VkImageMemoryBarrier imageMemoryBarrier() { /** @brief Initialize a buffer memory barrier with no image transfer ownership */ -inline VkBufferMemoryBarrier bufferMemoryBarrier() { +inline VkBufferMemoryBarrier +bufferMemoryBarrier() +{ VkBufferMemoryBarrier bufferMemoryBarrier{}; bufferMemoryBarrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; bufferMemoryBarrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; @@ -93,66 +112,83 @@ inline VkBufferMemoryBarrier bufferMemoryBarrier() { return bufferMemoryBarrier; } -inline VkMemoryBarrier memoryBarrier() { +inline VkMemoryBarrier +memoryBarrier() +{ VkMemoryBarrier memoryBarrier{}; memoryBarrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER; return memoryBarrier; } -inline VkImageCreateInfo imageCreateInfo() { +inline VkImageCreateInfo +imageCreateInfo() +{ VkImageCreateInfo imageCreateInfo{}; imageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; return imageCreateInfo; } -inline VkSamplerCreateInfo samplerCreateInfo() { +inline VkSamplerCreateInfo +samplerCreateInfo() +{ VkSamplerCreateInfo samplerCreateInfo{}; samplerCreateInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; samplerCreateInfo.maxAnisotropy = 1.0f; return samplerCreateInfo; } -inline VkImageViewCreateInfo imageViewCreateInfo() { +inline VkImageViewCreateInfo +imageViewCreateInfo() +{ VkImageViewCreateInfo imageViewCreateInfo{}; imageViewCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; return imageViewCreateInfo; } -inline VkFramebufferCreateInfo framebufferCreateInfo() { +inline VkFramebufferCreateInfo +framebufferCreateInfo() +{ VkFramebufferCreateInfo framebufferCreateInfo{}; framebufferCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; return framebufferCreateInfo; } -inline VkSemaphoreCreateInfo semaphoreCreateInfo() { +inline VkSemaphoreCreateInfo +semaphoreCreateInfo() +{ VkSemaphoreCreateInfo semaphoreCreateInfo{}; semaphoreCreateInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; return semaphoreCreateInfo; } -inline VkFenceCreateInfo fenceCreateInfo(VkFenceCreateFlags flags = 0) { +inline VkFenceCreateInfo +fenceCreateInfo(VkFenceCreateFlags flags = 0) +{ VkFenceCreateInfo fenceCreateInfo{}; fenceCreateInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; fenceCreateInfo.flags = flags; return fenceCreateInfo; } -inline VkEventCreateInfo eventCreateInfo() { +inline VkEventCreateInfo +eventCreateInfo() +{ VkEventCreateInfo eventCreateInfo{}; eventCreateInfo.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; return eventCreateInfo; } -inline VkSubmitInfo submitInfo() { +inline VkSubmitInfo +submitInfo() +{ VkSubmitInfo submitInfo{}; submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; return submitInfo; } -inline VkViewport viewport(float width, - float height, - float minDepth, - float maxDepth) { +inline VkViewport +viewport(float width, float height, float minDepth, float maxDepth) +{ VkViewport viewport{}; viewport.width = width; viewport.height = height; @@ -161,10 +197,9 @@ inline VkViewport viewport(float width, return viewport; } -inline VkRect2D rect2D(int32_t width, - int32_t height, - int32_t offsetX, - int32_t offsetY) { +inline VkRect2D +rect2D(int32_t width, int32_t height, int32_t offsetX, int32_t offsetY) +{ VkRect2D rect2D{}; rect2D.extent.width = width; rect2D.extent.height = height; @@ -173,14 +208,17 @@ inline VkRect2D rect2D(int32_t width, return rect2D; } -inline VkBufferCreateInfo bufferCreateInfo() { +inline VkBufferCreateInfo +bufferCreateInfo() +{ VkBufferCreateInfo bufCreateInfo{}; bufCreateInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; return bufCreateInfo; } -inline VkBufferCreateInfo bufferCreateInfo(VkBufferUsageFlags usage, - VkDeviceSize size) { +inline VkBufferCreateInfo +bufferCreateInfo(VkBufferUsageFlags usage, VkDeviceSize size) +{ VkBufferCreateInfo bufCreateInfo{}; bufCreateInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; bufCreateInfo.usage = usage; @@ -188,10 +226,11 @@ inline VkBufferCreateInfo bufferCreateInfo(VkBufferUsageFlags usage, return bufCreateInfo; } -inline VkDescriptorPoolCreateInfo descriptorPoolCreateInfo( - uint32_t poolSizeCount, - VkDescriptorPoolSize* pPoolSizes, - uint32_t maxSets) { +inline VkDescriptorPoolCreateInfo +descriptorPoolCreateInfo(uint32_t poolSizeCount, + VkDescriptorPoolSize* pPoolSizes, + uint32_t maxSets) +{ VkDescriptorPoolCreateInfo descriptorPoolInfo{}; descriptorPoolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; descriptorPoolInfo.poolSizeCount = poolSizeCount; @@ -200,9 +239,10 @@ inline VkDescriptorPoolCreateInfo descriptorPoolCreateInfo( return descriptorPoolInfo; } -inline VkDescriptorPoolCreateInfo descriptorPoolCreateInfo( - const std::vector& poolSizes, - uint32_t maxSets) { +inline VkDescriptorPoolCreateInfo +descriptorPoolCreateInfo(const std::vector& poolSizes, + uint32_t maxSets) +{ VkDescriptorPoolCreateInfo descriptorPoolInfo{}; descriptorPoolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; descriptorPoolInfo.poolSizeCount = static_cast(poolSizes.size()); @@ -211,19 +251,21 @@ inline VkDescriptorPoolCreateInfo descriptorPoolCreateInfo( return descriptorPoolInfo; } -inline VkDescriptorPoolSize descriptorPoolSize(VkDescriptorType type, - uint32_t descriptorCount) { +inline VkDescriptorPoolSize +descriptorPoolSize(VkDescriptorType type, uint32_t descriptorCount) +{ VkDescriptorPoolSize descriptorPoolSize{}; descriptorPoolSize.type = type; descriptorPoolSize.descriptorCount = descriptorCount; return descriptorPoolSize; } -inline VkDescriptorSetLayoutBinding descriptorSetLayoutBinding( - VkDescriptorType type, - VkShaderStageFlags stageFlags, - uint32_t binding, - uint32_t descriptorCount = 1) { +inline VkDescriptorSetLayoutBinding +descriptorSetLayoutBinding(VkDescriptorType type, + VkShaderStageFlags stageFlags, + uint32_t binding, + uint32_t descriptorCount = 1) +{ VkDescriptorSetLayoutBinding setLayoutBinding{}; setLayoutBinding.descriptorType = type; setLayoutBinding.stageFlags = stageFlags; @@ -232,64 +274,72 @@ inline VkDescriptorSetLayoutBinding descriptorSetLayoutBinding( return setLayoutBinding; } -inline VkDescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo( - const VkDescriptorSetLayoutBinding* pBindings, - uint32_t bindingCount) { +inline VkDescriptorSetLayoutCreateInfo +descriptorSetLayoutCreateInfo(const VkDescriptorSetLayoutBinding* pBindings, + uint32_t bindingCount) +{ VkDescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo{}; descriptorSetLayoutCreateInfo.sType = - VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; + VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; descriptorSetLayoutCreateInfo.pBindings = pBindings; descriptorSetLayoutCreateInfo.bindingCount = bindingCount; return descriptorSetLayoutCreateInfo; } -inline VkDescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo( - const std::vector& bindings) { +inline VkDescriptorSetLayoutCreateInfo +descriptorSetLayoutCreateInfo( + const std::vector& bindings) +{ VkDescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo{}; descriptorSetLayoutCreateInfo.sType = - VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; + VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; descriptorSetLayoutCreateInfo.pBindings = bindings.data(); descriptorSetLayoutCreateInfo.bindingCount = - static_cast(bindings.size()); + static_cast(bindings.size()); return descriptorSetLayoutCreateInfo; } -inline VkPipelineLayoutCreateInfo pipelineLayoutCreateInfo( - const VkDescriptorSetLayout* pSetLayouts, - uint32_t setLayoutCount = 1) { +inline VkPipelineLayoutCreateInfo +pipelineLayoutCreateInfo(const VkDescriptorSetLayout* pSetLayouts, + uint32_t setLayoutCount = 1) +{ VkPipelineLayoutCreateInfo pipelineLayoutCreateInfo{}; pipelineLayoutCreateInfo.sType = - VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; + VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; pipelineLayoutCreateInfo.setLayoutCount = setLayoutCount; pipelineLayoutCreateInfo.pSetLayouts = pSetLayouts; return pipelineLayoutCreateInfo; } -inline VkPipelineLayoutCreateInfo pipelineLayoutCreateInfo( - uint32_t setLayoutCount = 1) { +inline VkPipelineLayoutCreateInfo +pipelineLayoutCreateInfo(uint32_t setLayoutCount = 1) +{ VkPipelineLayoutCreateInfo pipelineLayoutCreateInfo{}; pipelineLayoutCreateInfo.sType = - VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; + VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; pipelineLayoutCreateInfo.setLayoutCount = setLayoutCount; return pipelineLayoutCreateInfo; } -inline VkDescriptorSetAllocateInfo descriptorSetAllocateInfo( - VkDescriptorPool descriptorPool, - const VkDescriptorSetLayout* pSetLayouts, - uint32_t descriptorSetCount) { +inline VkDescriptorSetAllocateInfo +descriptorSetAllocateInfo(VkDescriptorPool descriptorPool, + const VkDescriptorSetLayout* pSetLayouts, + uint32_t descriptorSetCount) +{ VkDescriptorSetAllocateInfo descriptorSetAllocateInfo{}; descriptorSetAllocateInfo.sType = - VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; + VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; descriptorSetAllocateInfo.descriptorPool = descriptorPool; descriptorSetAllocateInfo.pSetLayouts = pSetLayouts; descriptorSetAllocateInfo.descriptorSetCount = descriptorSetCount; return descriptorSetAllocateInfo; } -inline VkDescriptorImageInfo descriptorImageInfo(VkSampler sampler, - VkImageView imageView, - VkImageLayout imageLayout) { +inline VkDescriptorImageInfo +descriptorImageInfo(VkSampler sampler, + VkImageView imageView, + VkImageLayout imageLayout) +{ VkDescriptorImageInfo descriptorImageInfo{}; descriptorImageInfo.sampler = sampler; descriptorImageInfo.imageView = imageView; @@ -297,12 +347,13 @@ inline VkDescriptorImageInfo descriptorImageInfo(VkSampler sampler, return descriptorImageInfo; } -inline VkWriteDescriptorSet writeDescriptorSet( - VkDescriptorSet dstSet, - VkDescriptorType type, - uint32_t binding, - VkDescriptorBufferInfo* bufferInfo, - uint32_t descriptorCount = 1) { +inline VkWriteDescriptorSet +writeDescriptorSet(VkDescriptorSet dstSet, + VkDescriptorType type, + uint32_t binding, + VkDescriptorBufferInfo* bufferInfo, + uint32_t descriptorCount = 1) +{ VkWriteDescriptorSet writeDescriptorSet{}; writeDescriptorSet.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; writeDescriptorSet.dstSet = dstSet; @@ -313,11 +364,13 @@ inline VkWriteDescriptorSet writeDescriptorSet( return writeDescriptorSet; } -inline VkWriteDescriptorSet writeDescriptorSet(VkDescriptorSet dstSet, - VkDescriptorType type, - uint32_t binding, - VkDescriptorImageInfo* imageInfo, - uint32_t descriptorCount = 1) { +inline VkWriteDescriptorSet +writeDescriptorSet(VkDescriptorSet dstSet, + VkDescriptorType type, + uint32_t binding, + VkDescriptorImageInfo* imageInfo, + uint32_t descriptorCount = 1) +{ VkWriteDescriptorSet writeDescriptorSet{}; writeDescriptorSet.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; writeDescriptorSet.dstSet = dstSet; @@ -328,10 +381,11 @@ inline VkWriteDescriptorSet writeDescriptorSet(VkDescriptorSet dstSet, return writeDescriptorSet; } -inline VkVertexInputBindingDescription vertexInputBindingDescription( - uint32_t binding, - uint32_t stride, - VkVertexInputRate inputRate) { +inline VkVertexInputBindingDescription +vertexInputBindingDescription(uint32_t binding, + uint32_t stride, + VkVertexInputRate inputRate) +{ VkVertexInputBindingDescription vInputBindDescription{}; vInputBindDescription.binding = binding; vInputBindDescription.stride = stride; @@ -339,11 +393,12 @@ inline VkVertexInputBindingDescription vertexInputBindingDescription( return vInputBindDescription; } -inline VkVertexInputAttributeDescription vertexInputAttributeDescription( - uint32_t binding, - uint32_t location, - VkFormat format, - uint32_t offset) { +inline VkVertexInputAttributeDescription +vertexInputAttributeDescription(uint32_t binding, + uint32_t location, + VkFormat format, + uint32_t offset) +{ VkVertexInputAttributeDescription vInputAttribDescription{}; vInputAttribDescription.location = location; vInputAttribDescription.binding = binding; @@ -353,58 +408,63 @@ inline VkVertexInputAttributeDescription vertexInputAttributeDescription( } inline VkPipelineVertexInputStateCreateInfo -pipelineVertexInputStateCreateInfo() { +pipelineVertexInputStateCreateInfo() +{ VkPipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo{}; pipelineVertexInputStateCreateInfo.sType = - VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; + VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; return pipelineVertexInputStateCreateInfo; } -inline VkPipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo( - const std::vector& - vertexBindingDescriptions, - const std::vector& - vertexAttributeDescriptions) { +inline VkPipelineVertexInputStateCreateInfo +pipelineVertexInputStateCreateInfo( + const std::vector& + vertexBindingDescriptions, + const std::vector& + vertexAttributeDescriptions) +{ VkPipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo{}; pipelineVertexInputStateCreateInfo.sType = - VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; + VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; pipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = - static_cast(vertexBindingDescriptions.size()); + static_cast(vertexBindingDescriptions.size()); pipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = - vertexBindingDescriptions.data(); + vertexBindingDescriptions.data(); pipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = - static_cast(vertexAttributeDescriptions.size()); + static_cast(vertexAttributeDescriptions.size()); pipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = - vertexAttributeDescriptions.data(); + vertexAttributeDescriptions.data(); return pipelineVertexInputStateCreateInfo; } inline VkPipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo( - VkPrimitiveTopology topology, - VkPipelineInputAssemblyStateCreateFlags flags, - VkBool32 primitiveRestartEnable) { + VkPrimitiveTopology topology, + VkPipelineInputAssemblyStateCreateFlags flags, + VkBool32 primitiveRestartEnable) +{ VkPipelineInputAssemblyStateCreateInfo - pipelineInputAssemblyStateCreateInfo{}; + pipelineInputAssemblyStateCreateInfo{}; pipelineInputAssemblyStateCreateInfo.sType = - VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; + VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; pipelineInputAssemblyStateCreateInfo.topology = topology; pipelineInputAssemblyStateCreateInfo.flags = flags; pipelineInputAssemblyStateCreateInfo.primitiveRestartEnable = - primitiveRestartEnable; + primitiveRestartEnable; return pipelineInputAssemblyStateCreateInfo; } inline VkPipelineRasterizationStateCreateInfo pipelineRasterizationStateCreateInfo( - VkPolygonMode polygonMode, - VkCullModeFlags cullMode, - VkFrontFace frontFace, - VkPipelineRasterizationStateCreateFlags flags = 0) { + VkPolygonMode polygonMode, + VkCullModeFlags cullMode, + VkFrontFace frontFace, + VkPipelineRasterizationStateCreateFlags flags = 0) +{ VkPipelineRasterizationStateCreateInfo - pipelineRasterizationStateCreateInfo{}; + pipelineRasterizationStateCreateInfo{}; pipelineRasterizationStateCreateInfo.sType = - VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; + VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; pipelineRasterizationStateCreateInfo.polygonMode = polygonMode; pipelineRasterizationStateCreateInfo.cullMode = cullMode; pipelineRasterizationStateCreateInfo.frontFace = frontFace; @@ -414,21 +474,24 @@ pipelineRasterizationStateCreateInfo( return pipelineRasterizationStateCreateInfo; } -inline VkPipelineColorBlendAttachmentState pipelineColorBlendAttachmentState( - VkColorComponentFlags colorWriteMask, - VkBool32 blendEnable) { +inline VkPipelineColorBlendAttachmentState +pipelineColorBlendAttachmentState(VkColorComponentFlags colorWriteMask, + VkBool32 blendEnable) +{ VkPipelineColorBlendAttachmentState pipelineColorBlendAttachmentState{}; pipelineColorBlendAttachmentState.colorWriteMask = colorWriteMask; pipelineColorBlendAttachmentState.blendEnable = blendEnable; return pipelineColorBlendAttachmentState; } -inline VkPipelineColorBlendStateCreateInfo pipelineColorBlendStateCreateInfo( - uint32_t attachmentCount, - const VkPipelineColorBlendAttachmentState* pAttachments) { +inline VkPipelineColorBlendStateCreateInfo +pipelineColorBlendStateCreateInfo( + uint32_t attachmentCount, + const VkPipelineColorBlendAttachmentState* pAttachments) +{ VkPipelineColorBlendStateCreateInfo pipelineColorBlendStateCreateInfo{}; pipelineColorBlendStateCreateInfo.sType = - VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; + VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; pipelineColorBlendStateCreateInfo.attachmentCount = attachmentCount; pipelineColorBlendStateCreateInfo.pAttachments = pAttachments; return pipelineColorBlendStateCreateInfo; @@ -437,10 +500,11 @@ inline VkPipelineColorBlendStateCreateInfo pipelineColorBlendStateCreateInfo( inline VkPipelineDepthStencilStateCreateInfo pipelineDepthStencilStateCreateInfo(VkBool32 depthTestEnable, VkBool32 depthWriteEnable, - VkCompareOp depthCompareOp) { + VkCompareOp depthCompareOp) +{ VkPipelineDepthStencilStateCreateInfo pipelineDepthStencilStateCreateInfo{}; pipelineDepthStencilStateCreateInfo.sType = - VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; + VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; pipelineDepthStencilStateCreateInfo.depthTestEnable = depthTestEnable; pipelineDepthStencilStateCreateInfo.depthWriteEnable = depthWriteEnable; pipelineDepthStencilStateCreateInfo.depthCompareOp = depthCompareOp; @@ -448,70 +512,78 @@ pipelineDepthStencilStateCreateInfo(VkBool32 depthTestEnable, return pipelineDepthStencilStateCreateInfo; } -inline VkPipelineViewportStateCreateInfo pipelineViewportStateCreateInfo( - uint32_t viewportCount, - uint32_t scissorCount, - VkPipelineViewportStateCreateFlags flags = 0) { +inline VkPipelineViewportStateCreateInfo +pipelineViewportStateCreateInfo(uint32_t viewportCount, + uint32_t scissorCount, + VkPipelineViewportStateCreateFlags flags = 0) +{ VkPipelineViewportStateCreateInfo pipelineViewportStateCreateInfo{}; pipelineViewportStateCreateInfo.sType = - VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; + VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; pipelineViewportStateCreateInfo.viewportCount = viewportCount; pipelineViewportStateCreateInfo.scissorCount = scissorCount; pipelineViewportStateCreateInfo.flags = flags; return pipelineViewportStateCreateInfo; } -inline VkPipelineMultisampleStateCreateInfo pipelineMultisampleStateCreateInfo( - VkSampleCountFlagBits rasterizationSamples, - VkPipelineMultisampleStateCreateFlags flags = 0) { +inline VkPipelineMultisampleStateCreateInfo +pipelineMultisampleStateCreateInfo( + VkSampleCountFlagBits rasterizationSamples, + VkPipelineMultisampleStateCreateFlags flags = 0) +{ VkPipelineMultisampleStateCreateInfo pipelineMultisampleStateCreateInfo{}; pipelineMultisampleStateCreateInfo.sType = - VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; + VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; pipelineMultisampleStateCreateInfo.rasterizationSamples = - rasterizationSamples; + rasterizationSamples; pipelineMultisampleStateCreateInfo.flags = flags; return pipelineMultisampleStateCreateInfo; } -inline VkPipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo( - const VkDynamicState* pDynamicStates, - uint32_t dynamicStateCount, - VkPipelineDynamicStateCreateFlags flags = 0) { +inline VkPipelineDynamicStateCreateInfo +pipelineDynamicStateCreateInfo(const VkDynamicState* pDynamicStates, + uint32_t dynamicStateCount, + VkPipelineDynamicStateCreateFlags flags = 0) +{ VkPipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo{}; pipelineDynamicStateCreateInfo.sType = - VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; + VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; pipelineDynamicStateCreateInfo.pDynamicStates = pDynamicStates; pipelineDynamicStateCreateInfo.dynamicStateCount = dynamicStateCount; pipelineDynamicStateCreateInfo.flags = flags; return pipelineDynamicStateCreateInfo; } -inline VkPipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo( - const std::vector& pDynamicStates, - VkPipelineDynamicStateCreateFlags flags = 0) { +inline VkPipelineDynamicStateCreateInfo +pipelineDynamicStateCreateInfo( + const std::vector& pDynamicStates, + VkPipelineDynamicStateCreateFlags flags = 0) +{ VkPipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo{}; pipelineDynamicStateCreateInfo.sType = - VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; + VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; pipelineDynamicStateCreateInfo.pDynamicStates = pDynamicStates.data(); pipelineDynamicStateCreateInfo.dynamicStateCount = - static_cast(pDynamicStates.size()); + static_cast(pDynamicStates.size()); pipelineDynamicStateCreateInfo.flags = flags; return pipelineDynamicStateCreateInfo; } inline VkPipelineTessellationStateCreateInfo -pipelineTessellationStateCreateInfo(uint32_t patchControlPoints) { +pipelineTessellationStateCreateInfo(uint32_t patchControlPoints) +{ VkPipelineTessellationStateCreateInfo pipelineTessellationStateCreateInfo{}; pipelineTessellationStateCreateInfo.sType = - VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO; + VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO; pipelineTessellationStateCreateInfo.patchControlPoints = patchControlPoints; return pipelineTessellationStateCreateInfo; } -inline VkGraphicsPipelineCreateInfo pipelineCreateInfo( - VkPipelineLayout layout, - VkRenderPass renderPass, - VkPipelineCreateFlags flags = 0) { +inline VkGraphicsPipelineCreateInfo +pipelineCreateInfo(VkPipelineLayout layout, + VkRenderPass renderPass, + VkPipelineCreateFlags flags = 0) +{ VkGraphicsPipelineCreateInfo pipelineCreateInfo{}; pipelineCreateInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; pipelineCreateInfo.layout = layout; @@ -522,7 +594,9 @@ inline VkGraphicsPipelineCreateInfo pipelineCreateInfo( return pipelineCreateInfo; } -inline VkGraphicsPipelineCreateInfo pipelineCreateInfo() { +inline VkGraphicsPipelineCreateInfo +pipelineCreateInfo() +{ VkGraphicsPipelineCreateInfo pipelineCreateInfo{}; pipelineCreateInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; pipelineCreateInfo.basePipelineIndex = -1; @@ -530,20 +604,21 @@ inline VkGraphicsPipelineCreateInfo pipelineCreateInfo() { return pipelineCreateInfo; } -inline VkComputePipelineCreateInfo computePipelineCreateInfo( - VkPipelineLayout layout, - VkPipelineCreateFlags flags = 0) { +inline VkComputePipelineCreateInfo +computePipelineCreateInfo(VkPipelineLayout layout, + VkPipelineCreateFlags flags = 0) +{ VkComputePipelineCreateInfo computePipelineCreateInfo{}; computePipelineCreateInfo.sType = - VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO; + VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO; computePipelineCreateInfo.layout = layout; computePipelineCreateInfo.flags = flags; return computePipelineCreateInfo; } -inline VkPushConstantRange pushConstantRange(VkShaderStageFlags stageFlags, - uint32_t size, - uint32_t offset) { +inline VkPushConstantRange +pushConstantRange(VkShaderStageFlags stageFlags, uint32_t size, uint32_t offset) +{ VkPushConstantRange pushConstantRange{}; pushConstantRange.stageFlags = stageFlags; pushConstantRange.offset = offset; @@ -551,16 +626,18 @@ inline VkPushConstantRange pushConstantRange(VkShaderStageFlags stageFlags, return pushConstantRange; } -inline VkBindSparseInfo bindSparseInfo() { +inline VkBindSparseInfo +bindSparseInfo() +{ VkBindSparseInfo bindSparseInfo{}; bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO; return bindSparseInfo; } /** @brief Initialize a map entry for a shader specialization constant */ -inline VkSpecializationMapEntry specializationMapEntry(uint32_t constantID, - uint32_t offset, - size_t size) { +inline VkSpecializationMapEntry +specializationMapEntry(uint32_t constantID, uint32_t offset, size_t size) +{ VkSpecializationMapEntry specializationMapEntry{}; specializationMapEntry.constantID = constantID; specializationMapEntry.offset = offset; @@ -570,11 +647,12 @@ inline VkSpecializationMapEntry specializationMapEntry(uint32_t constantID, /** @brief Initialize a specialization constant info structure to pass to a * shader stage */ -inline VkSpecializationInfo specializationInfo( - uint32_t mapEntryCount, - const VkSpecializationMapEntry* mapEntries, - size_t dataSize, - const void* data) { +inline VkSpecializationInfo +specializationInfo(uint32_t mapEntryCount, + const VkSpecializationMapEntry* mapEntries, + size_t dataSize, + const void* data) +{ VkSpecializationInfo specializationInfo{}; specializationInfo.mapEntryCount = mapEntryCount; specializationInfo.pMapEntries = mapEntries; @@ -585,10 +663,11 @@ inline VkSpecializationInfo specializationInfo( /** @brief Initialize a specialization constant info structure to pass to a * shader stage */ -inline VkSpecializationInfo specializationInfo( - const std::vector& mapEntries, - size_t dataSize, - const void* data) { +inline VkSpecializationInfo +specializationInfo(const std::vector& mapEntries, + size_t dataSize, + const void* data) +{ VkSpecializationInfo specializationInfo{}; specializationInfo.mapEntryCount = static_cast(mapEntries.size()); specializationInfo.pMapEntries = mapEntries.data(); @@ -597,5 +676,5 @@ inline VkSpecializationInfo specializationInfo( return specializationInfo; } -} // namespace initializers -} // namespace vks +} // namespace initializers +} // namespace vks diff --git a/src/VulkanTools.cpp b/src/VulkanTools.cpp index dbda6696f..0afb17dae 100644 --- a/src/VulkanTools.cpp +++ b/src/VulkanTools.cpp @@ -9,7 +9,9 @@ #include "VulkanTools.h" -const std::string getAssetPath() { +const std::string +getAssetPath() +{ #if defined(VK_EXAMPLE_DATA_DIR) return VK_EXAMPLE_DATA_DIR; #else @@ -21,10 +23,12 @@ namespace vks { namespace tools { bool errorModeSilent = false; -std::string errorString(VkResult errorCode) { +std::string +errorString(VkResult errorCode) +{ switch (errorCode) { -#define STR(r) \ - case VK_##r: \ +#define STR(r) \ + case VK_##r: \ return #r STR(NOT_READY); STR(TIMEOUT); @@ -55,10 +59,12 @@ std::string errorString(VkResult errorCode) { } } -std::string physicalDeviceTypeString(VkPhysicalDeviceType type) { +std::string +physicalDeviceTypeString(VkPhysicalDeviceType type) +{ switch (type) { -#define STR(r) \ - case VK_PHYSICAL_DEVICE_TYPE_##r: \ +#define STR(r) \ + case VK_PHYSICAL_DEVICE_TYPE_##r: \ return #r STR(OTHER); STR(INTEGRATED_GPU); @@ -70,19 +76,21 @@ std::string physicalDeviceTypeString(VkPhysicalDeviceType type) { } } -VkBool32 getSupportedDepthFormat(VkPhysicalDevice physicalDevice, - VkFormat* depthFormat) { +VkBool32 +getSupportedDepthFormat(VkPhysicalDevice physicalDevice, VkFormat* depthFormat) +{ // Since all depth formats may be optional, we need to find a suitable depth // format to use Start with the highest precision packed format - std::vector depthFormats = { - VK_FORMAT_D32_SFLOAT_S8_UINT, VK_FORMAT_D32_SFLOAT, - VK_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_D16_UNORM_S8_UINT, - VK_FORMAT_D16_UNORM}; + std::vector depthFormats = { VK_FORMAT_D32_SFLOAT_S8_UINT, + VK_FORMAT_D32_SFLOAT, + VK_FORMAT_D24_UNORM_S8_UINT, + VK_FORMAT_D16_UNORM_S8_UINT, + VK_FORMAT_D16_UNORM }; for (auto& format : depthFormats) { VkFormatProperties formatProps; - vkGetPhysicalDeviceFormatProperties(physicalDevice, format, - &formatProps); + vkGetPhysicalDeviceFormatProperties( + physicalDevice, format, &formatProps); // Format must support depth stencil attachment for optimal tiling if (formatProps.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) { @@ -95,9 +103,11 @@ VkBool32 getSupportedDepthFormat(VkPhysicalDevice physicalDevice, } // Returns if a given format support LINEAR filtering -VkBool32 formatIsFilterable(VkPhysicalDevice physicalDevice, - VkFormat format, - VkImageTiling tiling) { +VkBool32 +formatIsFilterable(VkPhysicalDevice physicalDevice, + VkFormat format, + VkImageTiling tiling) +{ VkFormatProperties formatProps; vkGetPhysicalDeviceFormatProperties(physicalDevice, format, &formatProps); @@ -116,16 +126,18 @@ VkBool32 formatIsFilterable(VkPhysicalDevice physicalDevice, // an image and put it into an active command buffer // See chapter 11.4 "Image Layout" for details -void setImageLayout(VkCommandBuffer cmdbuffer, - VkImage image, - VkImageLayout oldImageLayout, - VkImageLayout newImageLayout, - VkImageSubresourceRange subresourceRange, - VkPipelineStageFlags srcStageMask, - VkPipelineStageFlags dstStageMask) { +void +setImageLayout(VkCommandBuffer cmdbuffer, + VkImage image, + VkImageLayout oldImageLayout, + VkImageLayout newImageLayout, + VkImageSubresourceRange subresourceRange, + VkPipelineStageFlags srcStageMask, + VkPipelineStageFlags dstStageMask) +{ // Create an image barrier object VkImageMemoryBarrier imageMemoryBarrier = - vks::initializers::imageMemoryBarrier(); + vks::initializers::imageMemoryBarrier(); imageMemoryBarrier.oldLayout = oldImageLayout; imageMemoryBarrier.newLayout = newImageLayout; imageMemoryBarrier.image = image; @@ -153,7 +165,7 @@ void setImageLayout(VkCommandBuffer cmdbuffer, // Image is a color attachment // Make sure any writes to the color buffer have been finished imageMemoryBarrier.srcAccessMask = - VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; + VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; break; case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: @@ -161,7 +173,7 @@ void setImageLayout(VkCommandBuffer cmdbuffer, // Make sure any writes to the depth/stencil buffer have been // finished imageMemoryBarrier.srcAccessMask = - VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; + VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; break; case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: @@ -205,15 +217,15 @@ void setImageLayout(VkCommandBuffer cmdbuffer, // Image will be used as a color attachment // Make sure any writes to the color buffer have been finished imageMemoryBarrier.dstAccessMask = - VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; + VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; break; case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: // Image layout will be used as a depth/stencil attachment // Make sure any writes to depth/stencil buffer have been finished imageMemoryBarrier.dstAccessMask = - imageMemoryBarrier.dstAccessMask | - VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; + imageMemoryBarrier.dstAccessMask | + VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; break; case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: @@ -221,7 +233,7 @@ void setImageLayout(VkCommandBuffer cmdbuffer, // Make sure any writes to the image have been finished if (imageMemoryBarrier.srcAccessMask == 0) { imageMemoryBarrier.srcAccessMask = - VK_ACCESS_HOST_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT; + VK_ACCESS_HOST_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT; } imageMemoryBarrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; break; @@ -231,38 +243,55 @@ void setImageLayout(VkCommandBuffer cmdbuffer, } // Put barrier inside setup command buffer - vkCmdPipelineBarrier(cmdbuffer, srcStageMask, dstStageMask, 0, 0, nullptr, - 0, nullptr, 1, &imageMemoryBarrier); + vkCmdPipelineBarrier(cmdbuffer, + srcStageMask, + dstStageMask, + 0, + 0, + nullptr, + 0, + nullptr, + 1, + &imageMemoryBarrier); } // Fixed sub resource on first mip level and layer -void setImageLayout(VkCommandBuffer cmdbuffer, - VkImage image, - VkImageAspectFlags aspectMask, - VkImageLayout oldImageLayout, - VkImageLayout newImageLayout, - VkPipelineStageFlags srcStageMask, - VkPipelineStageFlags dstStageMask) { +void +setImageLayout(VkCommandBuffer cmdbuffer, + VkImage image, + VkImageAspectFlags aspectMask, + VkImageLayout oldImageLayout, + VkImageLayout newImageLayout, + VkPipelineStageFlags srcStageMask, + VkPipelineStageFlags dstStageMask) +{ VkImageSubresourceRange subresourceRange = {}; subresourceRange.aspectMask = aspectMask; subresourceRange.baseMipLevel = 0; subresourceRange.levelCount = 1; subresourceRange.layerCount = 1; - setImageLayout(cmdbuffer, image, oldImageLayout, newImageLayout, - subresourceRange, srcStageMask, dstStageMask); + setImageLayout(cmdbuffer, + image, + oldImageLayout, + newImageLayout, + subresourceRange, + srcStageMask, + dstStageMask); } -void insertImageMemoryBarrier(VkCommandBuffer cmdbuffer, - VkImage image, - VkAccessFlags srcAccessMask, - VkAccessFlags dstAccessMask, - VkImageLayout oldImageLayout, - VkImageLayout newImageLayout, - VkPipelineStageFlags srcStageMask, - VkPipelineStageFlags dstStageMask, - VkImageSubresourceRange subresourceRange) { +void +insertImageMemoryBarrier(VkCommandBuffer cmdbuffer, + VkImage image, + VkAccessFlags srcAccessMask, + VkAccessFlags dstAccessMask, + VkImageLayout oldImageLayout, + VkImageLayout newImageLayout, + VkPipelineStageFlags srcStageMask, + VkPipelineStageFlags dstStageMask, + VkImageSubresourceRange subresourceRange) +{ VkImageMemoryBarrier imageMemoryBarrier = - vks::initializers::imageMemoryBarrier(); + vks::initializers::imageMemoryBarrier(); imageMemoryBarrier.srcAccessMask = srcAccessMask; imageMemoryBarrier.dstAccessMask = dstAccessMask; imageMemoryBarrier.oldLayout = oldImageLayout; @@ -270,11 +299,21 @@ void insertImageMemoryBarrier(VkCommandBuffer cmdbuffer, imageMemoryBarrier.image = image; imageMemoryBarrier.subresourceRange = subresourceRange; - vkCmdPipelineBarrier(cmdbuffer, srcStageMask, dstStageMask, 0, 0, nullptr, - 0, nullptr, 1, &imageMemoryBarrier); + vkCmdPipelineBarrier(cmdbuffer, + srcStageMask, + dstStageMask, + 0, + 0, + nullptr, + 0, + nullptr, + 1, + &imageMemoryBarrier); } -void exitFatal(std::string message, int32_t exitCode) { +void +exitFatal(std::string message, int32_t exitCode) +{ #if defined(_WIN32) if (!errorModeSilent) { MessageBox(NULL, message.c_str(), NULL, MB_OK | MB_ICONERROR); @@ -283,11 +322,15 @@ void exitFatal(std::string message, int32_t exitCode) { std::cerr << message << "\n"; } -void exitFatal(std::string message, VkResult resultCode) { +void +exitFatal(std::string message, VkResult resultCode) +{ exitFatal(message, (int32_t)resultCode); } -VkShaderModule loadShader(const char* fileName, VkDevice device) { +VkShaderModule +loadShader(const char* fileName, VkDevice device) +{ std::ifstream is(fileName, std::ios::binary | std::ios::in | std::ios::ate); if (is.is_open()) { @@ -305,8 +348,8 @@ VkShaderModule loadShader(const char* fileName, VkDevice device) { moduleCreateInfo.codeSize = size; moduleCreateInfo.pCode = (uint32_t*)shaderCode; - VK_CHECK_RESULT(vkCreateShaderModule(device, &moduleCreateInfo, NULL, - &shaderModule)); + VK_CHECK_RESULT(vkCreateShaderModule( + device, &moduleCreateInfo, NULL, &shaderModule)); delete[] shaderCode; @@ -318,9 +361,11 @@ VkShaderModule loadShader(const char* fileName, VkDevice device) { } } -bool fileExists(const std::string& filename) { +bool +fileExists(const std::string& filename) +{ std::ifstream f(filename.c_str()); return !f.fail(); } -} // namespace tools -} // namespace vks +} // namespace tools +} // namespace vks diff --git a/src/VulkanTools.h b/src/VulkanTools.h index f159654dd..3fd51ecb8 100644 --- a/src/VulkanTools.h +++ b/src/VulkanTools.h @@ -13,13 +13,13 @@ #include "vulkan/vulkan.h" #include -#include -#include -#include #include #include #include +#include #include +#include +#include #include #include #if defined(_WIN32) @@ -34,18 +34,19 @@ #define DEFAULT_FENCE_TIMEOUT 100000000000 // Macro to check and display Vulkan return results -#define VK_CHECK_RESULT(f) \ - { \ - VkResult res = (f); \ - if (res != VK_SUCCESS) { \ - std::cout << "Fatal : VkResult is \"" \ - << vks::tools::errorString(res) << "\" in " << __FILE__ \ - << " at line " << __LINE__ << std::endl; \ - assert(res == VK_SUCCESS); \ - } \ +#define VK_CHECK_RESULT(f) \ + { \ + VkResult res = (f); \ + if (res != VK_SUCCESS) { \ + std::cout << "Fatal : VkResult is \"" \ + << vks::tools::errorString(res) << "\" in " << __FILE__ \ + << " at line " << __LINE__ << std::endl; \ + assert(res == VK_SUCCESS); \ + } \ } -const std::string getAssetPath(); +const std::string +getAssetPath(); namespace vks { namespace tools { @@ -53,61 +54,71 @@ namespace tools { extern bool errorModeSilent; /** @brief Returns an error code as a string */ -std::string errorString(VkResult errorCode); +std::string +errorString(VkResult errorCode); /** @brief Returns the device type as a string */ -std::string physicalDeviceTypeString(VkPhysicalDeviceType type); +std::string +physicalDeviceTypeString(VkPhysicalDeviceType type); // Selected a suitable supported depth format starting with 32 bit down to 16 // bit Returns false if none of the depth formats in the list is supported by // the device -VkBool32 getSupportedDepthFormat(VkPhysicalDevice physicalDevice, - VkFormat* depthFormat); +VkBool32 +getSupportedDepthFormat(VkPhysicalDevice physicalDevice, VkFormat* depthFormat); // Returns if a given format support LINEAR filtering -VkBool32 formatIsFilterable(VkPhysicalDevice physicalDevice, - VkFormat format, - VkImageTiling tiling); +VkBool32 +formatIsFilterable(VkPhysicalDevice physicalDevice, + VkFormat format, + VkImageTiling tiling); // Put an image memory barrier for setting an image layout on the sub resource // into the given command buffer -void setImageLayout( - VkCommandBuffer cmdbuffer, - VkImage image, - VkImageLayout oldImageLayout, - VkImageLayout newImageLayout, - VkImageSubresourceRange subresourceRange, - VkPipelineStageFlags srcStageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); +void +setImageLayout( + VkCommandBuffer cmdbuffer, + VkImage image, + VkImageLayout oldImageLayout, + VkImageLayout newImageLayout, + VkImageSubresourceRange subresourceRange, + VkPipelineStageFlags srcStageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, + VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); // Uses a fixed sub resource layout with first mip level and layer -void setImageLayout( - VkCommandBuffer cmdbuffer, - VkImage image, - VkImageAspectFlags aspectMask, - VkImageLayout oldImageLayout, - VkImageLayout newImageLayout, - VkPipelineStageFlags srcStageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); +void +setImageLayout( + VkCommandBuffer cmdbuffer, + VkImage image, + VkImageAspectFlags aspectMask, + VkImageLayout oldImageLayout, + VkImageLayout newImageLayout, + VkPipelineStageFlags srcStageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, + VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); /** @brief Inser an image memory barrier into the command buffer */ -void insertImageMemoryBarrier(VkCommandBuffer cmdbuffer, - VkImage image, - VkAccessFlags srcAccessMask, - VkAccessFlags dstAccessMask, - VkImageLayout oldImageLayout, - VkImageLayout newImageLayout, - VkPipelineStageFlags srcStageMask, - VkPipelineStageFlags dstStageMask, - VkImageSubresourceRange subresourceRange); +void +insertImageMemoryBarrier(VkCommandBuffer cmdbuffer, + VkImage image, + VkAccessFlags srcAccessMask, + VkAccessFlags dstAccessMask, + VkImageLayout oldImageLayout, + VkImageLayout newImageLayout, + VkPipelineStageFlags srcStageMask, + VkPipelineStageFlags dstStageMask, + VkImageSubresourceRange subresourceRange); // Display error message and exit on fatal error -void exitFatal(std::string message, int32_t exitCode); -void exitFatal(std::string message, VkResult resultCode); +void +exitFatal(std::string message, int32_t exitCode); +void +exitFatal(std::string message, VkResult resultCode); // Load a SPIR-V shader (binary) -VkShaderModule loadShader(const char* fileName, VkDevice device); +VkShaderModule +loadShader(const char* fileName, VkDevice device); /** @brief Checks if a file exists */ -bool fileExists(const std::string& filename); -} // namespace tools -} // namespace vks +bool +fileExists(const std::string& filename); +} // namespace tools +} // namespace vks diff --git a/src/main.cpp b/src/main.cpp index e38f7467d..89922f49b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -63,11 +63,11 @@ class VulkanExample { // Create the buffer handle VkBufferCreateInfo bufferCreateInfo = - vks::initializers::bufferCreateInfo(usageFlags, size); + vks::initializers::bufferCreateInfo(usageFlags, size); bufferCreateInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; - VK_CHECK_RESULT( - vkCreateBuffer(this->device, &bufferCreateInfo, nullptr, buffer)); + VK_CHECK_RESULT(vkCreateBuffer( + this->device, &bufferCreateInfo, nullptr, buffer)); // Create the memory backing up the buffer handle VkPhysicalDeviceMemoryProperties deviceMemoryProperties; @@ -159,26 +159,30 @@ class VulkanExample } #endif VK_CHECK_RESULT( - vkCreateInstance(&instanceCreateInfo, nullptr, &instance)); + vkCreateInstance(&instanceCreateInfo, nullptr, &instance)); #if DEBUG if (layersAvailable) { VkDebugReportCallbackCreateInfoEXT debugReportCreateInfo = {}; debugReportCreateInfo.sType = - VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT; - debugReportCreateInfo.flags = - VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT; + VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT; + debugReportCreateInfo.flags = VK_DEBUG_REPORT_ERROR_BIT_EXT | + VK_DEBUG_REPORT_WARNING_BIT_EXT; debugReportCreateInfo.pfnCallback = - (PFN_vkDebugReportCallbackEXT)debugMessageCallback; + (PFN_vkDebugReportCallbackEXT)debugMessageCallback; // We have to explicitly load this function. PFN_vkCreateDebugReportCallbackEXT vkCreateDebugReportCallbackEXT = - reinterpret_cast( - vkGetInstanceProcAddr(instance, - "vkCreateDebugReportCallbackEXT")); + reinterpret_cast( + vkGetInstanceProcAddr( + instance, + "vkCreateDebugReportCallbackEXT")); assert(vkCreateDebugReportCallbackEXT); - VK_CHECK_RESULT(vkCreateDebugReportCallbackEXT( - instance, &debugReportCreateInfo, nullptr, &debugReportCallback)); + VK_CHECK_RESULT( + vkCreateDebugReportCallbackEXT(instance, + &debugReportCreateInfo, + nullptr, + &debugReportCallback)); } #endif @@ -188,11 +192,11 @@ class VulkanExample // Physical device (always use first) uint32_t deviceCount = 0; VK_CHECK_RESULT( - vkEnumeratePhysicalDevices(instance, &deviceCount, nullptr)); + vkEnumeratePhysicalDevices(instance, &deviceCount, nullptr)); std::vector physicalDevices(deviceCount); VK_CHECK_RESULT(vkEnumeratePhysicalDevices( - instance, &deviceCount, physicalDevices.data())); + instance, &deviceCount, physicalDevices.data())); physicalDevice = physicalDevices[0]; @@ -205,21 +209,21 @@ class VulkanExample VkDeviceQueueCreateInfo queueCreateInfo = {}; uint32_t queueFamilyCount; vkGetPhysicalDeviceQueueFamilyProperties( - physicalDevice, &queueFamilyCount, nullptr); + physicalDevice, &queueFamilyCount, nullptr); std::vector queueFamilyProperties( - queueFamilyCount); - vkGetPhysicalDeviceQueueFamilyProperties( - physicalDevice, &queueFamilyCount, queueFamilyProperties.data()); + queueFamilyCount); + vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, + &queueFamilyCount, + queueFamilyProperties.data()); for (uint32_t i = 0; i < static_cast(queueFamilyProperties.size()); i++) { - if (queueFamilyProperties[i].queueFlags & VK_QUEUE_COMPUTE_BIT) { queueFamilyIndex = i; queueCreateInfo.sType = - VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; + VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; queueCreateInfo.queueFamilyIndex = i; queueCreateInfo.queueCount = 1; queueCreateInfo.pQueuePriorities = &defaultQueuePriority; @@ -231,8 +235,8 @@ class VulkanExample deviceCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; deviceCreateInfo.queueCreateInfoCount = 1; deviceCreateInfo.pQueueCreateInfos = &queueCreateInfo; - VK_CHECK_RESULT( - vkCreateDevice(this->physicalDevice, &deviceCreateInfo, nullptr, &device)); + VK_CHECK_RESULT(vkCreateDevice( + this->physicalDevice, &deviceCreateInfo, nullptr, &device)); // Get a compute queue vkGetDeviceQueue(this->device, this->queueFamilyIndex, 0, &queue); @@ -242,8 +246,8 @@ class VulkanExample cmdPoolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; cmdPoolInfo.queueFamilyIndex = this->queueFamilyIndex; cmdPoolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; - VK_CHECK_RESULT( - vkCreateCommandPool(this->device, &cmdPoolInfo, nullptr, &this->commandPool)); + VK_CHECK_RESULT(vkCreateCommandPool( + this->device, &cmdPoolInfo, nullptr, &this->commandPool)); /* Prepare storage buffers @@ -254,7 +258,7 @@ class VulkanExample // Fill input data uint32_t n = 0; std::generate( - computeInput.begin(), computeInput.end(), [&n] { return n++; }); + computeInput.begin(), computeInput.end(), [&n] { return n++; }); const VkDeviceSize bufferSize = BUFFER_ELEMENTS * sizeof(uint32_t); @@ -264,7 +268,7 @@ class VulkanExample // Copy input data to VRAM using a staging buffer { createBuffer(VK_BUFFER_USAGE_TRANSFER_SRC_BIT | - VK_BUFFER_USAGE_TRANSFER_DST_BIT, + VK_BUFFER_USAGE_TRANSFER_DST_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, &hostBuffer, &hostMemory, @@ -275,7 +279,7 @@ class VulkanExample void* mapped; vkMapMemory(device, hostMemory, 0, VK_WHOLE_SIZE, 0, &mapped); VkMappedMemoryRange mappedRange = - vks::initializers::mappedMemoryRange(); + vks::initializers::mappedMemoryRange(); mappedRange.memory = hostMemory; mappedRange.offset = 0; mappedRange.size = VK_WHOLE_SIZE; @@ -283,8 +287,8 @@ class VulkanExample vkUnmapMemory(device, hostMemory); createBuffer(VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | - VK_BUFFER_USAGE_TRANSFER_SRC_BIT | - VK_BUFFER_USAGE_TRANSFER_DST_BIT, + VK_BUFFER_USAGE_TRANSFER_SRC_BIT | + VK_BUFFER_USAGE_TRANSFER_DST_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &deviceBuffer, &deviceMemory, @@ -292,13 +296,13 @@ class VulkanExample // Copy to staging buffer VkCommandBufferAllocateInfo cmdBufAllocateInfo = - vks::initializers::commandBufferAllocateInfo( - commandPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1); + vks::initializers::commandBufferAllocateInfo( + commandPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1); VkCommandBuffer copyCmd; - VK_CHECK_RESULT( - vkAllocateCommandBuffers(device, &cmdBufAllocateInfo, ©Cmd)); + VK_CHECK_RESULT(vkAllocateCommandBuffers( + device, &cmdBufAllocateInfo, ©Cmd)); VkCommandBufferBeginInfo cmdBufInfo = - vks::initializers::commandBufferBeginInfo(); + vks::initializers::commandBufferBeginInfo(); VK_CHECK_RESULT(vkBeginCommandBuffer(copyCmd, &cmdBufInfo)); VkBufferCopy copyRegion = {}; @@ -310,14 +314,14 @@ class VulkanExample submitInfo.commandBufferCount = 1; submitInfo.pCommandBuffers = ©Cmd; VkFenceCreateInfo fenceInfo = - vks::initializers::fenceCreateInfo(VK_FLAGS_NONE); + vks::initializers::fenceCreateInfo(VK_FLAGS_NONE); VkFence fence; VK_CHECK_RESULT(vkCreateFence(device, &fenceInfo, nullptr, &fence)); // Submit to the queue VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, fence)); VK_CHECK_RESULT( - vkWaitForFences(device, 1, &fence, VK_TRUE, UINT64_MAX)); + vkWaitForFences(device, 1, &fence, VK_TRUE, UINT64_MAX)); vkDestroyFence(device, fence, nullptr); vkFreeCommandBuffers(device, commandPool, 1, ©Cmd); @@ -329,65 +333,72 @@ class VulkanExample { std::vector poolSizes = { vks::initializers::descriptorPoolSize( - VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1), + VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1), }; VkDescriptorPoolCreateInfo descriptorPoolInfo = - vks::initializers::descriptorPoolCreateInfo( - static_cast(poolSizes.size()), poolSizes.data(), 1); + vks::initializers::descriptorPoolCreateInfo( + static_cast(poolSizes.size()), + poolSizes.data(), + 1); VK_CHECK_RESULT(vkCreateDescriptorPool( - device, &descriptorPoolInfo, nullptr, &descriptorPool)); + device, &descriptorPoolInfo, nullptr, &descriptorPool)); std::vector setLayoutBindings = { vks::initializers::descriptorSetLayoutBinding( - VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, - VK_SHADER_STAGE_COMPUTE_BIT, - 0), + VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, + VK_SHADER_STAGE_COMPUTE_BIT, + 0), }; VkDescriptorSetLayoutCreateInfo descriptorLayout = - vks::initializers::descriptorSetLayoutCreateInfo( - setLayoutBindings); + vks::initializers::descriptorSetLayoutCreateInfo( + setLayoutBindings); VK_CHECK_RESULT(vkCreateDescriptorSetLayout( - device, &descriptorLayout, nullptr, &descriptorSetLayout)); + device, &descriptorLayout, nullptr, &descriptorSetLayout)); VkPipelineLayoutCreateInfo pipelineLayoutCreateInfo = - vks::initializers::pipelineLayoutCreateInfo(&descriptorSetLayout, - 1); - VK_CHECK_RESULT(vkCreatePipelineLayout( - device, &pipelineLayoutCreateInfo, nullptr, &pipelineLayout)); + vks::initializers::pipelineLayoutCreateInfo( + &descriptorSetLayout, 1); + VK_CHECK_RESULT(vkCreatePipelineLayout(device, + &pipelineLayoutCreateInfo, + nullptr, + &pipelineLayout)); VkDescriptorSetAllocateInfo allocInfo = - vks::initializers::descriptorSetAllocateInfo( - descriptorPool, &descriptorSetLayout, 1); - VK_CHECK_RESULT( - vkAllocateDescriptorSets(device, &allocInfo, &descriptorSet)); + vks::initializers::descriptorSetAllocateInfo( + descriptorPool, &descriptorSetLayout, 1); + VK_CHECK_RESULT(vkAllocateDescriptorSets( + device, &allocInfo, &descriptorSet)); VkDescriptorBufferInfo bufferDescriptor = { deviceBuffer, 0, VK_WHOLE_SIZE }; std::vector computeWriteDescriptorSets = { vks::initializers::writeDescriptorSet( - descriptorSet, - VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, - 0, - &bufferDescriptor), + descriptorSet, + VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, + 0, + &bufferDescriptor), }; vkUpdateDescriptorSets( - device, - static_cast(computeWriteDescriptorSets.size()), - computeWriteDescriptorSets.data(), - 0, - NULL); + device, + static_cast(computeWriteDescriptorSets.size()), + computeWriteDescriptorSets.data(), + 0, + NULL); VkPipelineCacheCreateInfo pipelineCacheCreateInfo = {}; pipelineCacheCreateInfo.sType = - VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; - VK_CHECK_RESULT(vkCreatePipelineCache( - this->device, &pipelineCacheCreateInfo, nullptr, &this->pipelineCache)); + VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; + VK_CHECK_RESULT(vkCreatePipelineCache(this->device, + &pipelineCacheCreateInfo, + nullptr, + &this->pipelineCache)); // Create pipeline VkComputePipelineCreateInfo computePipelineCreateInfo = - vks::initializers::computePipelineCreateInfo(pipelineLayout, 0); + vks::initializers::computePipelineCreateInfo(pipelineLayout, + 0); // Pass SSBO size via specialization constant struct SpecializationData @@ -396,12 +407,14 @@ class VulkanExample } specializationData; VkSpecializationMapEntry specializationMapEntry = - vks::initializers::specializationMapEntry(0, 0, sizeof(uint32_t)); + vks::initializers::specializationMapEntry( + 0, 0, sizeof(uint32_t)); VkSpecializationInfo specializationInfo = - vks::initializers::specializationInfo(1, - &specializationMapEntry, - sizeof(SpecializationData), - &specializationData); + vks::initializers::specializationInfo( + 1, + &specializationMapEntry, + sizeof(SpecializationData), + &specializationData); // TODO: There is no command line arguments parsing (nor Android // settings) for this example, so we have no way of picking between @@ -411,11 +424,11 @@ class VulkanExample VkPipelineShaderStageCreateInfo shaderStage = {}; shaderStage.sType = - VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; shaderStage.stage = VK_SHADER_STAGE_COMPUTE_BIT; shaderStage.module = vks::tools::loadShader( - (shadersPath + "computeheadless.comp.spv").c_str(), device); + (shadersPath + "computeheadless.comp.spv").c_str(), device); shaderStage.pName = "main"; shaderStage.pSpecializationInfo = &specializationInfo; @@ -432,16 +445,17 @@ class VulkanExample // Create a command buffer for compute operations VkCommandBufferAllocateInfo cmdBufAllocateInfo = - vks::initializers::commandBufferAllocateInfo( - commandPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1); + vks::initializers::commandBufferAllocateInfo( + commandPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1); VK_CHECK_RESULT(vkAllocateCommandBuffers( - device, &cmdBufAllocateInfo, &commandBuffer)); + device, &cmdBufAllocateInfo, &commandBuffer)); // Fence for compute CB sync VkFenceCreateInfo fenceCreateInfo = - vks::initializers::fenceCreateInfo(VK_FENCE_CREATE_SIGNALED_BIT); + vks::initializers::fenceCreateInfo( + VK_FENCE_CREATE_SIGNALED_BIT); VK_CHECK_RESULT( - vkCreateFence(device, &fenceCreateInfo, nullptr, &fence)); + vkCreateFence(device, &fenceCreateInfo, nullptr, &fence)); } /* @@ -449,14 +463,14 @@ class VulkanExample */ { VkCommandBufferBeginInfo cmdBufInfo = - vks::initializers::commandBufferBeginInfo(); + vks::initializers::commandBufferBeginInfo(); VK_CHECK_RESULT(vkBeginCommandBuffer(commandBuffer, &cmdBufInfo)); // Barrier to ensure that input buffer transfer is finished before // compute shader reads from it VkBufferMemoryBarrier bufferBarrier = - vks::initializers::bufferMemoryBarrier(); + vks::initializers::bufferMemoryBarrier(); bufferBarrier.buffer = deviceBuffer; bufferBarrier.size = VK_WHOLE_SIZE; bufferBarrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; @@ -476,7 +490,7 @@ class VulkanExample nullptr); vkCmdBindPipeline( - commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline); + commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline); vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipelineLayout, @@ -512,7 +526,7 @@ class VulkanExample VkBufferCopy copyRegion = {}; copyRegion.size = bufferSize; vkCmdCopyBuffer( - commandBuffer, deviceBuffer, hostBuffer, 1, ©Region); + commandBuffer, deviceBuffer, hostBuffer, 1, ©Region); // Barrier to ensure that buffer copy is finished before host // reading from it @@ -539,20 +553,20 @@ class VulkanExample // Submit compute work vkResetFences(device, 1, &fence); const VkPipelineStageFlags waitStageMask = - VK_PIPELINE_STAGE_TRANSFER_BIT; + VK_PIPELINE_STAGE_TRANSFER_BIT; VkSubmitInfo computeSubmitInfo = vks::initializers::submitInfo(); computeSubmitInfo.pWaitDstStageMask = &waitStageMask; computeSubmitInfo.commandBufferCount = 1; computeSubmitInfo.pCommandBuffers = &commandBuffer; VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &computeSubmitInfo, fence)); VK_CHECK_RESULT( - vkWaitForFences(device, 1, &fence, VK_TRUE, UINT64_MAX)); + vkWaitForFences(device, 1, &fence, VK_TRUE, UINT64_MAX)); // Make device writes visible to the host void* mapped; vkMapMemory(device, hostMemory, 0, VK_WHOLE_SIZE, 0, &mapped); VkMappedMemoryRange mappedRange = - vks::initializers::mappedMemoryRange(); + vks::initializers::mappedMemoryRange(); mappedRange.memory = hostMemory; mappedRange.offset = 0; mappedRange.size = VK_WHOLE_SIZE; @@ -599,12 +613,13 @@ class VulkanExample #if DEBUG if (debugReportCallback) { PFN_vkDestroyDebugReportCallbackEXT vkDestroyDebugReportCallback = - reinterpret_cast( - vkGetInstanceProcAddr(instance, - "vkDestroyDebugReportCallbackEXT")); + reinterpret_cast( + vkGetInstanceProcAddr( + instance, + "vkDestroyDebugReportCallbackEXT")); assert(vkDestroyDebugReportCallback); vkDestroyDebugReportCallback( - instance, debugReportCallback, nullptr); + instance, debugReportCallback, nullptr); } #endif vkDestroyInstance(instance, nullptr);