diff --git a/Makefile b/Makefile index 6b8d37e38..8af4f4753 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, ContinuationIndentWidth: 8}" src/*.cpp src/*.h src/*.hpp + $(CF) -i -style="{BasedOnStyle: mozilla, IndentWidth: 4}" src/*.cpp src/*.h src/*.hpp clean: rm ./bin/main.exe; diff --git a/src/VulkanInitializers.hpp b/src/VulkanInitializers.hpp index a663eba57..81a2621b5 100644 --- a/src/VulkanInitializers.hpp +++ b/src/VulkanInitializers.hpp @@ -40,7 +40,7 @@ commandBufferAllocateInfo(VkCommandPool commandPool, { 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; @@ -68,7 +68,7 @@ commandBufferInheritanceInfo() { VkCommandBufferInheritanceInfo cmdBufferInheritanceInfo{}; cmdBufferInheritanceInfo.sType = - VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO; + VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO; return cmdBufferInheritanceInfo; } @@ -280,7 +280,7 @@ descriptorSetLayoutCreateInfo(const VkDescriptorSetLayoutBinding* pBindings, { 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; @@ -288,14 +288,14 @@ descriptorSetLayoutCreateInfo(const VkDescriptorSetLayoutBinding* pBindings, inline VkDescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo( - const std::vector& bindings) + 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; } @@ -305,7 +305,7 @@ pipelineLayoutCreateInfo(const VkDescriptorSetLayout* pSetLayouts, { 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; @@ -316,7 +316,7 @@ 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; } @@ -328,7 +328,7 @@ descriptorSetAllocateInfo(VkDescriptorPool descriptorPool, { 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; @@ -412,59 +412,58 @@ 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) + 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; @@ -486,12 +485,12 @@ pipelineColorBlendAttachmentState(VkColorComponentFlags colorWriteMask, inline VkPipelineColorBlendStateCreateInfo pipelineColorBlendStateCreateInfo( - uint32_t attachmentCount, - const VkPipelineColorBlendAttachmentState* pAttachments) + 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; @@ -504,7 +503,7 @@ pipelineDepthStencilStateCreateInfo(VkBool32 depthTestEnable, { 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; @@ -519,7 +518,7 @@ pipelineViewportStateCreateInfo(uint32_t viewportCount, { 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; @@ -528,14 +527,14 @@ pipelineViewportStateCreateInfo(uint32_t viewportCount, inline VkPipelineMultisampleStateCreateInfo pipelineMultisampleStateCreateInfo( - VkSampleCountFlagBits rasterizationSamples, - VkPipelineMultisampleStateCreateFlags flags = 0) + 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; } @@ -547,7 +546,7 @@ pipelineDynamicStateCreateInfo(const VkDynamicState* pDynamicStates, { 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; @@ -556,15 +555,15 @@ pipelineDynamicStateCreateInfo(const VkDynamicState* pDynamicStates, inline VkPipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo( - const std::vector& pDynamicStates, - VkPipelineDynamicStateCreateFlags flags = 0) + 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; } @@ -574,7 +573,7 @@ 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; } @@ -610,7 +609,7 @@ computePipelineCreateInfo(VkPipelineLayout layout, { 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; diff --git a/src/VulkanTools.cpp b/src/VulkanTools.cpp index 0afb17dae..963084153 100644 --- a/src/VulkanTools.cpp +++ b/src/VulkanTools.cpp @@ -90,7 +90,7 @@ getSupportedDepthFormat(VkPhysicalDevice physicalDevice, VkFormat* depthFormat) for (auto& format : depthFormats) { VkFormatProperties formatProps; vkGetPhysicalDeviceFormatProperties( - physicalDevice, format, &formatProps); + physicalDevice, format, &formatProps); // Format must support depth stencil attachment for optimal tiling if (formatProps.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) { @@ -137,7 +137,7 @@ setImageLayout(VkCommandBuffer cmdbuffer, { // Create an image barrier object VkImageMemoryBarrier imageMemoryBarrier = - vks::initializers::imageMemoryBarrier(); + vks::initializers::imageMemoryBarrier(); imageMemoryBarrier.oldLayout = oldImageLayout; imageMemoryBarrier.newLayout = newImageLayout; imageMemoryBarrier.image = image; @@ -165,7 +165,7 @@ 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: @@ -173,7 +173,7 @@ 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: @@ -217,15 +217,15 @@ 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: @@ -233,7 +233,7 @@ 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; @@ -291,7 +291,7 @@ insertImageMemoryBarrier(VkCommandBuffer cmdbuffer, VkImageSubresourceRange subresourceRange) { VkImageMemoryBarrier imageMemoryBarrier = - vks::initializers::imageMemoryBarrier(); + vks::initializers::imageMemoryBarrier(); imageMemoryBarrier.srcAccessMask = srcAccessMask; imageMemoryBarrier.dstAccessMask = dstAccessMask; imageMemoryBarrier.oldLayout = oldImageLayout; @@ -348,8 +348,8 @@ 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; diff --git a/src/VulkanTools.h b/src/VulkanTools.h index 3fd51ecb8..bec00baa7 100644 --- a/src/VulkanTools.h +++ b/src/VulkanTools.h @@ -77,23 +77,23 @@ formatIsFilterable(VkPhysicalDevice physicalDevice, // 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); + 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); + 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 diff --git a/src/main.cpp b/src/main.cpp index 89922f49b..7f51b6f6a 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,30 +159,26 @@ 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 @@ -192,11 +188,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]; @@ -209,13 +205,12 @@ 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()); @@ -223,7 +218,7 @@ class VulkanExample 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; @@ -236,7 +231,7 @@ class VulkanExample deviceCreateInfo.queueCreateInfoCount = 1; deviceCreateInfo.pQueueCreateInfos = &queueCreateInfo; VK_CHECK_RESULT(vkCreateDevice( - this->physicalDevice, &deviceCreateInfo, nullptr, &device)); + this->physicalDevice, &deviceCreateInfo, nullptr, &device)); // Get a compute queue vkGetDeviceQueue(this->device, this->queueFamilyIndex, 0, &queue); @@ -247,7 +242,7 @@ class VulkanExample cmdPoolInfo.queueFamilyIndex = this->queueFamilyIndex; cmdPoolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; VK_CHECK_RESULT(vkCreateCommandPool( - this->device, &cmdPoolInfo, nullptr, &this->commandPool)); + this->device, &cmdPoolInfo, nullptr, &this->commandPool)); /* Prepare storage buffers @@ -258,7 +253,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); @@ -268,7 +263,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, @@ -279,7 +274,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; @@ -287,8 +282,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, @@ -296,13 +291,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 = {}; @@ -314,14 +309,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); @@ -333,63 +328,59 @@ 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_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; VK_CHECK_RESULT(vkCreatePipelineCache(this->device, &pipelineCacheCreateInfo, nullptr, @@ -397,8 +388,8 @@ class VulkanExample // Create pipeline VkComputePipelineCreateInfo computePipelineCreateInfo = - vks::initializers::computePipelineCreateInfo(pipelineLayout, - 0); + vks::initializers::computePipelineCreateInfo(this->pipelineLayout, + 0); // Pass SSBO size via specialization constant struct SpecializationData @@ -407,14 +398,12 @@ 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 @@ -424,11 +413,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; @@ -445,17 +434,16 @@ 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)); } /* @@ -463,14 +451,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; @@ -490,7 +478,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, @@ -526,7 +514,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 @@ -553,20 +541,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; @@ -613,13 +601,12 @@ 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);