Native VK Swapchain: Use a compact way to initialize Vulkan structs
Use designated initializers[1] to initialize Vulkan structs in a more
compact way.
[1]: https://en.cppreference.com/w/cpp/language/aggregate_initialization
Test: run the emulator
Change-Id: If743b78fc2c7451ca0483b22067c53c3fd0231be
diff --git a/stream-servers/CompositorVk.cpp b/stream-servers/CompositorVk.cpp
index 3c1b6e1..7be3925 100644
--- a/stream-servers/CompositorVk.cpp
+++ b/stream-servers/CompositorVk.cpp
@@ -15,11 +15,10 @@
static VkShaderModule createShaderModule(const goldfish_vk::VulkanDispatch &vk,
VkDevice device,
const std::vector<uint32_t> &code) {
- VkShaderModuleCreateInfo shaderModuleCi = {};
- shaderModuleCi.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
- shaderModuleCi.codeSize =
- static_cast<uint32_t>(code.size() * sizeof(uint32_t));
- shaderModuleCi.pCode = code.data();
+ VkShaderModuleCreateInfo shaderModuleCi = {
+ .sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
+ .codeSize = static_cast<uint32_t>(code.size() * sizeof(uint32_t)),
+ .pCode = code.data()};
VkShaderModule res;
VK_CHECK(vk.vkCreateShaderModule(device, &shaderModuleCi, nullptr, &res));
return res;
@@ -94,41 +93,35 @@
((sizeof(UniformBufferObject) - 1) / alignment + 1) * alignment;
}
- CompositorVk::~CompositorVk() {
- m_vk.vkDestroySampler(m_vkDevice, m_emptyCompositionVkSampler,
- nullptr);
- m_vk.vkDestroyImageView(m_vkDevice, m_emptyCompositionVkImageView,
- nullptr);
- m_vk.vkFreeMemory(m_vkDevice, m_emptyCompositionVkDeviceMemory,
- nullptr);
- m_vk.vkDestroyImage(m_vkDevice, m_emptyCompositionVkImage, nullptr);
- m_vk.vkDestroyDescriptorPool(m_vkDevice, m_vkDescriptorPool, nullptr);
- m_vk.vkFreeCommandBuffers(
- m_vkDevice, m_vkCommandPool,
- static_cast<uint32_t>(m_vkCommandBuffers.size()),
- m_vkCommandBuffers.data());
- if (m_uniformStorage.m_vkDeviceMemory != VK_NULL_HANDLE) {
- m_vk.vkUnmapMemory(m_vkDevice, m_uniformStorage.m_vkDeviceMemory);
- }
- m_vk.vkDestroyBuffer(m_vkDevice, m_uniformStorage.m_vkBuffer,
- nullptr);
- m_vk.vkFreeMemory(m_vkDevice, m_uniformStorage.m_vkDeviceMemory,
- nullptr);
- while (!m_renderTargetVkFrameBuffers.empty()) {
- m_vk.vkDestroyFramebuffer(
- m_vkDevice, m_renderTargetVkFrameBuffers.back(), nullptr);
- m_renderTargetVkFrameBuffers.pop_back();
- }
- m_vk.vkFreeMemory(m_vkDevice, m_vertexVkDeviceMemory, nullptr);
- m_vk.vkDestroyBuffer(m_vkDevice, m_vertexVkBuffer, nullptr);
- m_vk.vkFreeMemory(m_vkDevice, m_indexVkDeviceMemory, nullptr);
- m_vk.vkDestroyBuffer(m_vkDevice, m_indexVkBuffer, nullptr);
- m_vk.vkDestroyPipeline(m_vkDevice, m_graphicsVkPipeline, nullptr);
- m_vk.vkDestroyRenderPass(m_vkDevice, m_vkRenderPass, nullptr);
- m_vk.vkDestroyPipelineLayout(m_vkDevice, m_vkPipelineLayout, nullptr);
- m_vk.vkDestroyDescriptorSetLayout(m_vkDevice, m_vkDescriptorSetLayout,
- nullptr);
- }
+CompositorVk::~CompositorVk() {
+ m_vk.vkDestroySampler(m_vkDevice, m_emptyCompositionVkSampler, nullptr);
+ m_vk.vkDestroyImageView(m_vkDevice, m_emptyCompositionVkImageView, nullptr);
+ m_vk.vkFreeMemory(m_vkDevice, m_emptyCompositionVkDeviceMemory, nullptr);
+ m_vk.vkDestroyImage(m_vkDevice, m_emptyCompositionVkImage, nullptr);
+ m_vk.vkDestroyDescriptorPool(m_vkDevice, m_vkDescriptorPool, nullptr);
+ m_vk.vkFreeCommandBuffers(m_vkDevice, m_vkCommandPool,
+ static_cast<uint32_t>(m_vkCommandBuffers.size()),
+ m_vkCommandBuffers.data());
+ if (m_uniformStorage.m_vkDeviceMemory != VK_NULL_HANDLE) {
+ m_vk.vkUnmapMemory(m_vkDevice, m_uniformStorage.m_vkDeviceMemory);
+ }
+ m_vk.vkDestroyBuffer(m_vkDevice, m_uniformStorage.m_vkBuffer, nullptr);
+ m_vk.vkFreeMemory(m_vkDevice, m_uniformStorage.m_vkDeviceMemory, nullptr);
+ while (!m_renderTargetVkFrameBuffers.empty()) {
+ m_vk.vkDestroyFramebuffer(m_vkDevice,
+ m_renderTargetVkFrameBuffers.back(), nullptr);
+ m_renderTargetVkFrameBuffers.pop_back();
+ }
+ m_vk.vkFreeMemory(m_vkDevice, m_vertexVkDeviceMemory, nullptr);
+ m_vk.vkDestroyBuffer(m_vkDevice, m_vertexVkBuffer, nullptr);
+ m_vk.vkFreeMemory(m_vkDevice, m_indexVkDeviceMemory, nullptr);
+ m_vk.vkDestroyBuffer(m_vkDevice, m_indexVkBuffer, nullptr);
+ m_vk.vkDestroyPipeline(m_vkDevice, m_graphicsVkPipeline, nullptr);
+ m_vk.vkDestroyRenderPass(m_vkDevice, m_vkRenderPass, nullptr);
+ m_vk.vkDestroyPipelineLayout(m_vkDevice, m_vkPipelineLayout, nullptr);
+ m_vk.vkDestroyDescriptorSetLayout(m_vkDevice, m_vkDescriptorSetLayout,
+ nullptr);
+}
void CompositorVk::setUpGraphicsPipeline(uint32_t width, uint32_t height,
VkFormat renderTargetFormat,
@@ -145,207 +138,183 @@
const auto fragShaderMod =
createShaderModule(m_vk, m_vkDevice, fragSpvBuff);
- VkPipelineShaderStageCreateInfo shaderStageCis[2] = {};
- shaderStageCis[0].sType =
- VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
- shaderStageCis[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
- shaderStageCis[0].module = vertShaderMod;
- shaderStageCis[0].pName = "main";
- shaderStageCis[1].sType =
- VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
- shaderStageCis[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
- shaderStageCis[1].module = fragShaderMod;
- shaderStageCis[1].pName = "main";
+ VkPipelineShaderStageCreateInfo shaderStageCis[2] = {
+ {.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
+ .stage = VK_SHADER_STAGE_VERTEX_BIT,
+ .module = vertShaderMod,
+ .pName = "main"},
+ {.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
+ .stage = VK_SHADER_STAGE_FRAGMENT_BIT,
+ .module = fragShaderMod,
+ .pName = "main"}};
auto bindingDescription = Vertex::getBindingDescription();
auto attributeDescription = Vertex::getAttributeDescription();
- VkPipelineVertexInputStateCreateInfo vertexInputStateCi = {};
- vertexInputStateCi.sType =
- VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
- vertexInputStateCi.vertexBindingDescriptionCount = 1;
- vertexInputStateCi.pVertexBindingDescriptions = &bindingDescription;
- vertexInputStateCi.vertexAttributeDescriptionCount =
- static_cast<uint32_t>(attributeDescription.size());
- vertexInputStateCi.pVertexAttributeDescriptions =
- attributeDescription.data();
+ VkPipelineVertexInputStateCreateInfo vertexInputStateCi = {
+ .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
+ .vertexBindingDescriptionCount = 1,
+ .pVertexBindingDescriptions = &bindingDescription,
+ .vertexAttributeDescriptionCount =
+ static_cast<uint32_t>(attributeDescription.size()),
+ .pVertexAttributeDescriptions = attributeDescription.data()};
+ VkPipelineInputAssemblyStateCreateInfo inputAssemblyStateCi = {
+ .sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
+ .topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,
+ .primitiveRestartEnable = VK_FALSE,
+ };
- VkPipelineInputAssemblyStateCreateInfo inputAssemblyStateCi = {};
- inputAssemblyStateCi.sType =
- VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
- inputAssemblyStateCi.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
- inputAssemblyStateCi.primitiveRestartEnable = VK_FALSE;
+ VkViewport viewport = {.x = 0.0f,
+ .y = 0.0f,
+ .width = static_cast<float>(width),
+ .height = static_cast<float>(height),
+ .minDepth = 0.0f,
+ .maxDepth = 1.0f};
- VkViewport viewport = {};
- viewport.x = 0.0f;
- viewport.y = 0.0f;
- viewport.width = static_cast<float>(width);
- viewport.height = static_cast<float>(height);
- viewport.minDepth = 0.0f;
- viewport.maxDepth = 1.0f;
+ VkRect2D scissor = {.offset = {0, 0}, .extent = {width, height}};
- VkRect2D scissor = {};
- scissor.offset = {0, 0};
- scissor.extent.width = width;
- scissor.extent.height = height;
+ VkPipelineViewportStateCreateInfo viewportStateCi = {
+ .sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,
+ .viewportCount = 1,
+ .pViewports = &viewport,
+ .scissorCount = 1,
+ .pScissors = &scissor};
- VkPipelineViewportStateCreateInfo viewportStateCi = {};
- viewportStateCi.sType =
- VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
- viewportStateCi.viewportCount = 1;
- viewportStateCi.pViewports = &viewport;
- viewportStateCi.scissorCount = 1;
- viewportStateCi.pScissors = &scissor;
+ VkPipelineRasterizationStateCreateInfo rasterizerStateCi = {
+ .sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
+ .depthClampEnable = VK_FALSE,
+ .rasterizerDiscardEnable = VK_FALSE,
+ .polygonMode = VK_POLYGON_MODE_FILL,
+ .cullMode = VK_CULL_MODE_BACK_BIT,
+ .frontFace = VK_FRONT_FACE_CLOCKWISE,
+ .depthBiasEnable = VK_FALSE,
+ .depthBiasConstantFactor = 0.0f,
+ .depthBiasClamp = 0.0f,
+ .depthBiasSlopeFactor = 0.0f,
+ .lineWidth = 1.0f};
- VkPipelineRasterizationStateCreateInfo rasterizerStateCi = {};
- rasterizerStateCi.sType =
- VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
- rasterizerStateCi.depthClampEnable = VK_FALSE;
- rasterizerStateCi.rasterizerDiscardEnable = VK_FALSE;
- rasterizerStateCi.polygonMode = VK_POLYGON_MODE_FILL;
- rasterizerStateCi.lineWidth = 1.0f;
- rasterizerStateCi.cullMode = VK_CULL_MODE_BACK_BIT;
- rasterizerStateCi.frontFace = VK_FRONT_FACE_CLOCKWISE;
- rasterizerStateCi.depthBiasEnable = VK_FALSE;
- rasterizerStateCi.depthBiasConstantFactor = 0.0f;
- rasterizerStateCi.depthBiasClamp = 0.0f;
- rasterizerStateCi.depthBiasSlopeFactor = 0.0f;
+ VkPipelineMultisampleStateCreateInfo multisampleStateCi = {
+ .sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
+ .rasterizationSamples = VK_SAMPLE_COUNT_1_BIT,
+ .sampleShadingEnable = VK_FALSE,
+ .minSampleShading = 1.0f,
+ .pSampleMask = nullptr,
+ .alphaToCoverageEnable = VK_FALSE,
+ .alphaToOneEnable = VK_FALSE};
- VkPipelineMultisampleStateCreateInfo multisampleStateCi = {};
- multisampleStateCi.sType =
- VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
- multisampleStateCi.sampleShadingEnable = VK_FALSE;
- multisampleStateCi.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
- multisampleStateCi.minSampleShading = 1.0f;
- multisampleStateCi.pSampleMask = nullptr;
- multisampleStateCi.alphaToCoverageEnable = VK_FALSE;
- multisampleStateCi.alphaToOneEnable = VK_FALSE;
+ VkPipelineColorBlendAttachmentState colorBlendAttachment = {
+ .blendEnable = VK_TRUE,
+ .srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA,
+ .dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
+ .colorBlendOp = VK_BLEND_OP_ADD,
+ .srcAlphaBlendFactor = VK_BLEND_FACTOR_ZERO,
+ .dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE,
+ .alphaBlendOp = VK_BLEND_OP_MAX,
+ .colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT |
+ VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT};
- VkPipelineColorBlendAttachmentState colorBlendAttachment = {};
- colorBlendAttachment.colorWriteMask =
- VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT |
- VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
- colorBlendAttachment.blendEnable = VK_TRUE;
- colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
- colorBlendAttachment.dstColorBlendFactor =
- VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
- colorBlendAttachment.colorBlendOp = VK_BLEND_OP_ADD;
- colorBlendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
- colorBlendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
- colorBlendAttachment.alphaBlendOp = VK_BLEND_OP_MAX;
+ VkPipelineColorBlendStateCreateInfo colorBlendStateCi = {
+ .sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,
+ .logicOpEnable = VK_FALSE,
+ .attachmentCount = 1,
+ .pAttachments = &colorBlendAttachment};
- VkPipelineColorBlendStateCreateInfo colorBlendStateCi = {};
- colorBlendStateCi.sType =
- VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
- colorBlendStateCi.logicOpEnable = VK_FALSE;
- colorBlendStateCi.attachmentCount = 1;
- colorBlendStateCi.pAttachments = &colorBlendAttachment;
-
- VkDescriptorSetLayoutBinding layoutBindings[2] = {};
- layoutBindings[0].binding = 0;
- layoutBindings[0].descriptorCount = 1;
- layoutBindings[0].descriptorType =
- VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
- layoutBindings[0].pImmutableSamplers = nullptr;
- layoutBindings[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
-
- layoutBindings[1].binding = 1;
- layoutBindings[1].descriptorCount = 1;
- layoutBindings[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
- layoutBindings[1].pImmutableSamplers = nullptr;
- layoutBindings[1].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
+ VkDescriptorSetLayoutBinding layoutBindings[2] = {
+ {.binding = 0,
+ .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
+ .descriptorCount = 1,
+ .stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT,
+ .pImmutableSamplers = nullptr},
+ {.binding = 1,
+ .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
+ .descriptorCount = 1,
+ .stageFlags = VK_SHADER_STAGE_VERTEX_BIT,
+ .pImmutableSamplers = nullptr}};
VkDescriptorBindingFlagsEXT bindingFlags[] = {
VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT_EXT, 0};
- VkDescriptorSetLayoutBindingFlagsCreateInfoEXT bindingFlagsCi = {};
- bindingFlagsCi.sType =
- VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO_EXT;
- bindingFlagsCi.bindingCount =
- static_cast<uint32_t>(std::size(bindingFlags));
- bindingFlagsCi.pBindingFlags = bindingFlags;
- VkDescriptorSetLayoutCreateInfo descriptorSetLayoutCi = {};
- descriptorSetLayoutCi.sType =
- VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
- descriptorSetLayoutCi.bindingCount =
- static_cast<uint32_t>(std::size(layoutBindings));
- descriptorSetLayoutCi.pBindings = layoutBindings;
- descriptorSetLayoutCi.pNext = &bindingFlagsCi;
- descriptorSetLayoutCi.flags =
- VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT;
+ VkDescriptorSetLayoutBindingFlagsCreateInfoEXT bindingFlagsCi = {
+ .sType =
+ VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO_EXT,
+ .bindingCount = static_cast<uint32_t>(std::size(bindingFlags)),
+ .pBindingFlags = bindingFlags,
+ };
+ VkDescriptorSetLayoutCreateInfo descriptorSetLayoutCi = {
+ .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
+ .pNext = &bindingFlagsCi,
+ .flags = VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT,
+ .bindingCount = static_cast<uint32_t>(std::size(layoutBindings)),
+ .pBindings = layoutBindings};
VK_CHECK(m_vk.vkCreateDescriptorSetLayout(
m_vkDevice, &descriptorSetLayoutCi, nullptr, &m_vkDescriptorSetLayout));
- VkPipelineLayoutCreateInfo pipelineLayoutCi = {};
- pipelineLayoutCi.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
- pipelineLayoutCi.setLayoutCount = 1;
- pipelineLayoutCi.pSetLayouts = &m_vkDescriptorSetLayout;
- pipelineLayoutCi.pushConstantRangeCount = 0;
+ VkPipelineLayoutCreateInfo pipelineLayoutCi = {
+ .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
+ .setLayoutCount = 1,
+ .pSetLayouts = &m_vkDescriptorSetLayout,
+ .pushConstantRangeCount = 0};
VK_CHECK(m_vk.vkCreatePipelineLayout(m_vkDevice, &pipelineLayoutCi, nullptr,
&m_vkPipelineLayout));
- VkAttachmentDescription colorAttachment = {};
- colorAttachment.format = renderTargetFormat;
- colorAttachment.samples = VK_SAMPLE_COUNT_1_BIT;
- colorAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
- colorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
- colorAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
- colorAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
- colorAttachment.initialLayout = initialLayout;
- colorAttachment.finalLayout = finalLayout;
+ VkAttachmentDescription colorAttachment = {
+ .format = renderTargetFormat,
+ .samples = VK_SAMPLE_COUNT_1_BIT,
+ .loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR,
+ .storeOp = VK_ATTACHMENT_STORE_OP_STORE,
+ .stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE,
+ .stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE,
+ .initialLayout = initialLayout,
+ .finalLayout = finalLayout};
- VkAttachmentReference colorAttachmentRef = {};
- colorAttachmentRef.attachment = 0;
- colorAttachmentRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
+ VkAttachmentReference colorAttachmentRef = {
+ .attachment = 0, .layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
- VkSubpassDescription subpass = {};
- subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
- subpass.colorAttachmentCount = 1;
- subpass.pColorAttachments = &colorAttachmentRef;
+ VkSubpassDescription subpass = {
+ .pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS,
+ .colorAttachmentCount = 1,
+ .pColorAttachments = &colorAttachmentRef};
// TODO: to support multiple layer composition, we could run the same render
// pass for multiple time. In that case, we should use explicit
// VkImageMemoryBarriers to transform the image layout instead of relying on
// renderpass to do it.
- VkSubpassDependency subpassDependency = {};
- subpassDependency.srcSubpass = VK_SUBPASS_EXTERNAL;
- subpassDependency.dstSubpass = 0;
- subpassDependency.srcStageMask =
- VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
- subpassDependency.srcAccessMask = 0;
- subpassDependency.dstStageMask =
- VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
- subpassDependency.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
+ VkSubpassDependency subpassDependency = {
+ .srcSubpass = VK_SUBPASS_EXTERNAL,
+ .dstSubpass = 0,
+ .srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
+ .dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
+ .srcAccessMask = 0,
+ .dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT};
- VkRenderPassCreateInfo renderPassCi = {};
- renderPassCi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
- renderPassCi.attachmentCount = 1;
- renderPassCi.pAttachments = &colorAttachment;
- renderPassCi.subpassCount = 1;
- renderPassCi.pSubpasses = &subpass;
- renderPassCi.dependencyCount = 1;
- renderPassCi.pDependencies = &subpassDependency;
+ VkRenderPassCreateInfo renderPassCi = {
+ .sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
+ .attachmentCount = 1,
+ .pAttachments = &colorAttachment,
+ .subpassCount = 1,
+ .pSubpasses = &subpass,
+ .dependencyCount = 1,
+ .pDependencies = &subpassDependency};
VK_CHECK(m_vk.vkCreateRenderPass(m_vkDevice, &renderPassCi, nullptr,
&m_vkRenderPass));
- VkGraphicsPipelineCreateInfo graphicsPipelineCi = {};
- graphicsPipelineCi.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
- graphicsPipelineCi.stageCount =
- static_cast<uint32_t>(std::size(shaderStageCis));
- graphicsPipelineCi.pStages = shaderStageCis;
- graphicsPipelineCi.pVertexInputState = &vertexInputStateCi;
- graphicsPipelineCi.pInputAssemblyState = &inputAssemblyStateCi;
- graphicsPipelineCi.pViewportState = &viewportStateCi;
- graphicsPipelineCi.pRasterizationState = &rasterizerStateCi;
- graphicsPipelineCi.pMultisampleState = &multisampleStateCi;
- graphicsPipelineCi.pDepthStencilState = nullptr;
- graphicsPipelineCi.pColorBlendState = &colorBlendStateCi;
- graphicsPipelineCi.pDynamicState = nullptr;
- graphicsPipelineCi.layout = m_vkPipelineLayout;
- graphicsPipelineCi.renderPass = m_vkRenderPass;
- graphicsPipelineCi.subpass = 0;
- graphicsPipelineCi.basePipelineHandle = VK_NULL_HANDLE;
- graphicsPipelineCi.basePipelineIndex = -1;
+ VkGraphicsPipelineCreateInfo graphicsPipelineCi = {
+ .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
+ .stageCount = static_cast<uint32_t>(std::size(shaderStageCis)),
+ .pStages = shaderStageCis,
+ .pVertexInputState = &vertexInputStateCi,
+ .pInputAssemblyState = &inputAssemblyStateCi,
+ .pViewportState = &viewportStateCi,
+ .pRasterizationState = &rasterizerStateCi,
+ .pMultisampleState = &multisampleStateCi,
+ .pDepthStencilState = nullptr,
+ .pColorBlendState = &colorBlendStateCi,
+ .pDynamicState = nullptr,
+ .layout = m_vkPipelineLayout,
+ .renderPass = m_vkRenderPass,
+ .subpass = 0,
+ .basePipelineHandle = VK_NULL_HANDLE,
+ .basePipelineIndex = -1};
VK_CHECK(m_vk.vkCreateGraphicsPipelines(m_vkDevice, VK_NULL_HANDLE, 1,
&graphicsPipelineCi, nullptr,
@@ -361,11 +330,11 @@
std::optional<std::tuple<VkBuffer, VkDeviceMemory>> CompositorVk::createBuffer(
VkDeviceSize size, VkBufferUsageFlags usage,
VkMemoryPropertyFlags memProperty) const {
- VkBufferCreateInfo bufferCi = {};
- bufferCi.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
- bufferCi.size = size;
- bufferCi.usage = usage;
- bufferCi.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
+ VkBufferCreateInfo bufferCi = {
+ .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
+ .size = size,
+ .usage = usage,
+ .sharingMode = VK_SHARING_MODE_EXCLUSIVE};
VkBuffer resBuffer;
VK_CHECK(m_vk.vkCreateBuffer(m_vkDevice, &bufferCi, nullptr, &resBuffer));
VkMemoryRequirements memRequirements;
@@ -379,10 +348,10 @@
m_vk.vkDestroyBuffer(m_vkDevice, resBuffer, nullptr);
return std::nullopt;
}
- VkMemoryAllocateInfo memAllocInfo = {};
- memAllocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
- memAllocInfo.allocationSize = memRequirements.size;
- memAllocInfo.memoryTypeIndex = maybeMemoryTypeIndex.value();
+ VkMemoryAllocateInfo memAllocInfo = {
+ .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
+ .allocationSize = memRequirements.size,
+ .memoryTypeIndex = maybeMemoryTypeIndex.value()};
VkDeviceMemory resMemory;
VK_CHECK(
m_vk.vkAllocateMemory(m_vkDevice, &memAllocInfo, nullptr, &resMemory));
@@ -449,14 +418,14 @@
const std::vector<VkImageView> &renderTargets, uint32_t width,
uint32_t height) {
for (size_t i = 0; i < renderTargets.size(); i++) {
- VkFramebufferCreateInfo fbCi = {};
- fbCi.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
- fbCi.renderPass = m_vkRenderPass;
- fbCi.attachmentCount = 1;
- fbCi.pAttachments = &renderTargets[i];
- fbCi.width = width;
- fbCi.height = height;
- fbCi.layers = 1;
+ VkFramebufferCreateInfo fbCi = {
+ .sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
+ .renderPass = m_vkRenderPass,
+ .attachmentCount = 1,
+ .pAttachments = &renderTargets[i],
+ .width = width,
+ .height = height,
+ .layers = 1};
VkFramebuffer framebuffer;
VK_CHECK(
m_vk.vkCreateFramebuffer(m_vkDevice, &fbCi, nullptr, &framebuffer));
@@ -468,85 +437,74 @@
uint32_t numOfFrames =
static_cast<uint32_t>(m_renderTargetVkFrameBuffers.size());
- VkDescriptorPoolSize descriptorPoolSizes[2] = {};
- descriptorPoolSizes[0].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
- descriptorPoolSizes[0].descriptorCount = numOfFrames;
- descriptorPoolSizes[1].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
- descriptorPoolSizes[1].descriptorCount = numOfFrames;
+ VkDescriptorPoolSize descriptorPoolSizes[2] = {
+ {.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
+ .descriptorCount = numOfFrames},
+ {.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
+ .descriptorCount = numOfFrames}};
- VkDescriptorPoolCreateInfo descriptorPoolCi = {};
- descriptorPoolCi.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
- descriptorPoolCi.poolSizeCount =
- static_cast<uint32_t>(std::size(descriptorPoolSizes));
- descriptorPoolCi.pPoolSizes = descriptorPoolSizes;
- descriptorPoolCi.maxSets = static_cast<uint32_t>(numOfFrames);
- descriptorPoolCi.flags =
- VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT_EXT;
+ VkDescriptorPoolCreateInfo descriptorPoolCi = {
+ .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
+ .flags = VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT_EXT,
+ .maxSets = static_cast<uint32_t>(numOfFrames),
+ .poolSizeCount = static_cast<uint32_t>(std::size(descriptorPoolSizes)),
+ .pPoolSizes = descriptorPoolSizes};
VK_CHECK(m_vk.vkCreateDescriptorPool(m_vkDevice, &descriptorPoolCi, nullptr,
&m_vkDescriptorPool));
std::vector<VkDescriptorSetLayout> layouts(numOfFrames,
m_vkDescriptorSetLayout);
- VkDescriptorSetAllocateInfo descriptorSetAllocInfo = {};
- descriptorSetAllocInfo.sType =
- VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
- descriptorSetAllocInfo.descriptorPool = m_vkDescriptorPool;
- descriptorSetAllocInfo.descriptorSetCount = numOfFrames;
- descriptorSetAllocInfo.pSetLayouts = layouts.data();
+ VkDescriptorSetAllocateInfo descriptorSetAllocInfo = {
+ .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
+ .descriptorPool = m_vkDescriptorPool,
+ .descriptorSetCount = numOfFrames,
+ .pSetLayouts = layouts.data()};
m_vkDescriptorSets.resize(numOfFrames);
VK_CHECK(m_vk.vkAllocateDescriptorSets(m_vkDevice, &descriptorSetAllocInfo,
m_vkDescriptorSets.data()));
for (size_t i = 0; i < numOfFrames; i++) {
- VkDescriptorBufferInfo bufferInfo = {};
- bufferInfo.buffer = m_uniformStorage.m_vkBuffer;
- bufferInfo.offset = i * m_uniformStorage.m_stride;
- bufferInfo.range = sizeof(UniformBufferObject);
-
- VkWriteDescriptorSet descriptorSetWrite = {};
- descriptorSetWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
- descriptorSetWrite.dstSet = m_vkDescriptorSets[i];
- descriptorSetWrite.dstBinding = 1;
- descriptorSetWrite.dstArrayElement = 0;
- descriptorSetWrite.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
- descriptorSetWrite.descriptorCount = 1;
- descriptorSetWrite.pBufferInfo = &bufferInfo;
-
+ VkDescriptorBufferInfo bufferInfo = {
+ .buffer = m_uniformStorage.m_vkBuffer,
+ .offset = i * m_uniformStorage.m_stride,
+ .range = sizeof(UniformBufferObject)};
+ VkWriteDescriptorSet descriptorSetWrite = {
+ .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
+ .dstSet = m_vkDescriptorSets[i],
+ .dstBinding = 1,
+ .dstArrayElement = 0,
+ .descriptorCount = 1,
+ .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
+ .pBufferInfo = &bufferInfo};
m_vk.vkUpdateDescriptorSets(m_vkDevice, 1, &descriptorSetWrite, 0,
nullptr);
}
}
void CompositorVk::setUpCommandBuffers(uint32_t width, uint32_t height) {
- VkCommandBufferAllocateInfo cmdBuffAllocInfo = {};
- cmdBuffAllocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
- cmdBuffAllocInfo.commandPool = m_vkCommandPool;
- cmdBuffAllocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
- cmdBuffAllocInfo.commandBufferCount =
- static_cast<uint32_t>(m_renderTargetVkFrameBuffers.size());
+ VkCommandBufferAllocateInfo cmdBuffAllocInfo = {
+ .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
+ .commandPool = m_vkCommandPool,
+ .level = VK_COMMAND_BUFFER_LEVEL_PRIMARY,
+ .commandBufferCount =
+ static_cast<uint32_t>(m_renderTargetVkFrameBuffers.size())};
m_vkCommandBuffers.resize(m_renderTargetVkFrameBuffers.size());
VK_CHECK(m_vk.vkAllocateCommandBuffers(m_vkDevice, &cmdBuffAllocInfo,
m_vkCommandBuffers.data()));
for (size_t i = 0; i < m_vkCommandBuffers.size(); i++) {
- VkCommandBufferBeginInfo beginInfo = {};
- beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
+ VkCommandBufferBeginInfo beginInfo = {
+ beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO};
const auto &cmdBuffer = m_vkCommandBuffers[i];
VK_CHECK(m_vk.vkBeginCommandBuffer(cmdBuffer, &beginInfo));
- VkClearValue clearColor = {};
- clearColor.color.float32[0] = 0.0f;
- clearColor.color.float32[1] = 0.0f;
- clearColor.color.float32[2] = 0.0f;
- clearColor.color.float32[3] = 1.0f;
-
- VkRenderPassBeginInfo renderPassBeginInfo = {};
- renderPassBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
- renderPassBeginInfo.renderPass = m_vkRenderPass;
- renderPassBeginInfo.framebuffer = m_renderTargetVkFrameBuffers[i];
- renderPassBeginInfo.clearValueCount = 1;
- renderPassBeginInfo.pClearValues = &clearColor;
- renderPassBeginInfo.renderArea.offset = {0, 0};
- renderPassBeginInfo.renderArea.extent = {width, height};
-
+ VkClearValue clearColor = {
+ .color = {.float32 = {0.0f, 0.0f, 0.0f, 1.0f}}};
+ VkRenderPassBeginInfo renderPassBeginInfo = {
+ .sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
+ .renderPass = m_vkRenderPass,
+ .framebuffer = m_renderTargetVkFrameBuffers[i],
+ .renderArea = {.offset = {0, 0}, .extent = {width, height}},
+ .clearValueCount = 1,
+ .pClearValues = &clearColor};
m_vk.vkCmdBeginRenderPass(cmdBuffer, &renderPassBeginInfo,
VK_SUBPASS_CONTENTS_INLINE);
m_vk.vkCmdBindPipeline(cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS,
@@ -568,35 +526,33 @@
}
void CompositorVk::setUpEmptyComposition(VkFormat format) {
- VkImageCreateInfo imageCi = {};
- imageCi.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
- imageCi.imageType = VK_IMAGE_TYPE_2D;
- imageCi.extent.width = k_emptyCompositionExtent.width;
- imageCi.extent.height = k_emptyCompositionExtent.height;
- imageCi.extent.depth = 1;
- imageCi.mipLevels = 1;
- imageCi.arrayLayers = 1;
- imageCi.format = format;
- imageCi.tiling = VK_IMAGE_TILING_OPTIMAL;
- imageCi.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
- imageCi.usage =
- VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
- imageCi.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
- imageCi.samples = VK_SAMPLE_COUNT_1_BIT;
- imageCi.flags = 0;
+ VkImageCreateInfo imageCi = {
+ .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
+ .flags = 0,
+ .imageType = VK_IMAGE_TYPE_2D,
+ .format = format,
+ .extent = {.width = k_emptyCompositionExtent.width,
+ .height = k_emptyCompositionExtent.height,
+ .depth = 1},
+ .mipLevels = 1,
+ .arrayLayers = 1,
+ .samples = VK_SAMPLE_COUNT_1_BIT,
+ .tiling = VK_IMAGE_TILING_OPTIMAL,
+ .usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT,
+ .sharingMode = VK_SHARING_MODE_EXCLUSIVE,
+ .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED};
VK_CHECK(m_vk.vkCreateImage(m_vkDevice, &imageCi, nullptr,
&m_emptyCompositionVkImage));
VkMemoryRequirements memRequirements;
m_vk.vkGetImageMemoryRequirements(m_vkDevice, m_emptyCompositionVkImage,
&memRequirements);
- VkMemoryAllocateInfo allocInfo = {};
- allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
- allocInfo.allocationSize = memRequirements.size;
- allocInfo.memoryTypeIndex =
- findMemoryType(memRequirements.memoryTypeBits,
- VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)
- .value();
+ VkMemoryAllocateInfo allocInfo = {
+ .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
+ .allocationSize = memRequirements.size,
+ .memoryTypeIndex = findMemoryType(memRequirements.memoryTypeBits,
+ VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)
+ .value()};
VK_CHECK(m_vk.vkAllocateMemory(m_vkDevice, &allocInfo, nullptr,
&m_emptyCompositionVkDeviceMemory));
VK_CHECK(m_vk.vkBindImageMemory(m_vkDevice, m_emptyCompositionVkImage,
@@ -606,12 +562,12 @@
cmdBuff, m_emptyCompositionVkImage, VK_IMAGE_LAYOUT_UNDEFINED,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
VkClearColorValue clearColor = {.float32 = {0.0, 0.0, 0.0, 1.0}};
- VkImageSubresourceRange range = {};
- range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
- range.baseMipLevel = 0;
- range.levelCount = 1;
- range.baseArrayLayer = 0;
- range.layerCount = 1;
+ VkImageSubresourceRange range = {
+ .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
+ .baseMipLevel = 0,
+ .levelCount = 1,
+ .baseArrayLayer = 0,
+ .layerCount = 1};
m_vk.vkCmdClearColorImage(cmdBuff, m_emptyCompositionVkImage,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
&clearColor, 1, &range);
@@ -621,40 +577,40 @@
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
});
- VkImageViewCreateInfo imageViewCi = {};
- imageViewCi.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
- imageViewCi.image = m_emptyCompositionVkImage;
- imageViewCi.viewType = VK_IMAGE_VIEW_TYPE_2D;
- imageViewCi.format = format;
- imageViewCi.components.r = VK_COMPONENT_SWIZZLE_IDENTITY;
- imageViewCi.components.g = VK_COMPONENT_SWIZZLE_IDENTITY;
- imageViewCi.components.b = VK_COMPONENT_SWIZZLE_IDENTITY;
- imageViewCi.components.a = VK_COMPONENT_SWIZZLE_IDENTITY;
- imageViewCi.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
- imageViewCi.subresourceRange.baseMipLevel = 0;
- imageViewCi.subresourceRange.levelCount = 1;
- imageViewCi.subresourceRange.baseArrayLayer = 0;
- imageViewCi.subresourceRange.layerCount = 1;
+ VkImageViewCreateInfo imageViewCi = {
+ .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
+ .image = m_emptyCompositionVkImage,
+ .viewType = VK_IMAGE_VIEW_TYPE_2D,
+ .format = format,
+ .components = {.r = VK_COMPONENT_SWIZZLE_IDENTITY,
+ .g = VK_COMPONENT_SWIZZLE_IDENTITY,
+ .b = VK_COMPONENT_SWIZZLE_IDENTITY,
+ .a = VK_COMPONENT_SWIZZLE_IDENTITY},
+ .subresourceRange{.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
+ .baseMipLevel = 0,
+ .levelCount = 1,
+ .baseArrayLayer = 0,
+ .layerCount = 1}};
VK_CHECK(m_vk.vkCreateImageView(m_vkDevice, &imageViewCi, nullptr,
&m_emptyCompositionVkImageView));
- VkSamplerCreateInfo samplerCi = {};
- samplerCi.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
- samplerCi.magFilter = VK_FILTER_LINEAR;
- samplerCi.minFilter = VK_FILTER_LINEAR;
- samplerCi.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
- samplerCi.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
- samplerCi.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
- samplerCi.anisotropyEnable = VK_FALSE;
- samplerCi.maxAnisotropy = 1.0f;
- samplerCi.borderColor = VK_BORDER_COLOR_INT_TRANSPARENT_BLACK;
- samplerCi.unnormalizedCoordinates = VK_FALSE;
- samplerCi.compareEnable = VK_FALSE;
- samplerCi.compareOp = VK_COMPARE_OP_ALWAYS;
- samplerCi.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
- samplerCi.mipLodBias = 0.0f;
- samplerCi.minLod = 0.0f;
- samplerCi.maxLod = 0.0f;
+ VkSamplerCreateInfo samplerCi = {
+ .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
+ .magFilter = VK_FILTER_LINEAR,
+ .minFilter = VK_FILTER_LINEAR,
+ .mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR,
+ .addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER,
+ .addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER,
+ .addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER,
+ .mipLodBias = 0.0f,
+ .anisotropyEnable = VK_FALSE,
+ .maxAnisotropy = 1.0f,
+ .compareEnable = VK_FALSE,
+ .compareOp = VK_COMPARE_OP_ALWAYS,
+ .minLod = 0.0f,
+ .maxLod = 0.0f,
+ .borderColor = VK_BORDER_COLOR_INT_TRANSPARENT_BLACK,
+ .unnormalizedCoordinates = VK_FALSE};
VK_CHECK(m_vk.vkCreateSampler(m_vkDevice, &samplerCi, nullptr,
&m_emptyCompositionVkSampler));
}
@@ -725,19 +681,18 @@
std::unique_ptr<Composition> &&composition) {
m_currentCompositions[i] = std::move(composition);
const auto ¤tComposition = *m_currentCompositions[i];
- VkDescriptorImageInfo imageInfo = {};
- imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
- imageInfo.imageView = currentComposition.m_vkImageView;
- imageInfo.sampler = currentComposition.m_vkSampler;
- VkWriteDescriptorSet descriptorSetWrite = {};
- descriptorSetWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
- descriptorSetWrite.dstSet = m_vkDescriptorSets[i];
- descriptorSetWrite.dstBinding = 0;
- descriptorSetWrite.dstArrayElement = 0;
- descriptorSetWrite.descriptorType =
- VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
- descriptorSetWrite.descriptorCount = 1;
- descriptorSetWrite.pImageInfo = &imageInfo;
+ VkDescriptorImageInfo imageInfo = {
+ .sampler = currentComposition.m_vkSampler,
+ .imageView = currentComposition.m_vkImageView,
+ .imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL};
+ VkWriteDescriptorSet descriptorSetWrite = {
+ .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
+ .dstSet = m_vkDescriptorSets[i],
+ .dstBinding = 0,
+ .dstArrayElement = 0,
+ .descriptorCount = 1,
+ .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
+ .pImageInfo = &imageInfo};
m_vk.vkUpdateDescriptorSets(m_vkDevice, 1, &descriptorSetWrite, 0, nullptr);
auto local2screen = glm::translate(glm::mat3(1.0f), glm::vec2(1.0f, 1.0f));
@@ -765,23 +720,21 @@
}
VkVertexInputBindingDescription CompositorVk::Vertex::getBindingDescription() {
- VkVertexInputBindingDescription res = {};
- res.binding = 0;
- res.stride = sizeof(struct Vertex);
- res.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
- return res;
+ return {.binding = 0,
+ .stride = sizeof(struct Vertex),
+ .inputRate = VK_VERTEX_INPUT_RATE_VERTEX};
}
std::array<VkVertexInputAttributeDescription, 2>
CompositorVk::Vertex::getAttributeDescription() {
- std::array<VkVertexInputAttributeDescription, 2> res = {};
- res[0].binding = 0;
- res[0].location = 0;
- res[0].format = VK_FORMAT_R32G32_SFLOAT;
- res[0].offset = offsetof(struct Vertex, pos);
- res[1].binding = 0;
- res[1].location = 1;
- res[1].format = VK_FORMAT_R32G32_SFLOAT;
- res[1].offset = offsetof(struct Vertex, texPos);
- return res;
+ return {VkVertexInputAttributeDescription{
+ .location = 0,
+ .binding = 0,
+ .format = VK_FORMAT_R32G32_SFLOAT,
+ .offset = offsetof(struct Vertex, pos)},
+ VkVertexInputAttributeDescription{
+ .location = 1,
+ .binding = 0,
+ .format = VK_FORMAT_R32G32_SFLOAT,
+ .offset = offsetof(struct Vertex, texPos)}};
}
\ No newline at end of file
diff --git a/stream-servers/DisplayVk.cpp b/stream-servers/DisplayVk.cpp
index 78e5046..62fc66c 100644
--- a/stream-servers/DisplayVk.cpp
+++ b/stream-servers/DisplayVk.cpp
@@ -4,7 +4,6 @@
#include <glm/gtx/matrix_transform_2d.hpp>
#include "ErrorLog.h"
-#include "NativeSubWindow.h"
DisplayVk::DisplayVk(const goldfish_vk::VulkanDispatch &vk,
VkPhysicalDevice vkPhysicalDevice,
@@ -25,40 +24,40 @@
m_canComposite() {
// TODO(kaiyili): validate the capabilites of the passed in Vulkan
// components.
- VkCommandPoolCreateInfo commandPoolCi = {};
- commandPoolCi.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
- commandPoolCi.queueFamilyIndex = m_compositorQueueFamilyIndex;
+ VkCommandPoolCreateInfo commandPoolCi = {
+ .sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
+ .queueFamilyIndex = m_compositorQueueFamilyIndex,
+ };
VK_CHECK(m_vk.vkCreateCommandPool(m_vkDevice, &commandPoolCi, nullptr,
&m_vkCommandPool));
- VkFenceCreateInfo fenceCi = {};
- fenceCi.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
- fenceCi.flags = VK_FENCE_CREATE_SIGNALED_BIT;
+ VkFenceCreateInfo fenceCi = {.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
+ .flags = VK_FENCE_CREATE_SIGNALED_BIT};
VK_CHECK(m_vk.vkCreateFence(m_vkDevice, &fenceCi, nullptr,
&m_frameDrawCompleteFence));
- VkSemaphoreCreateInfo semaphoreCi = {};
- semaphoreCi.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
+ VkSemaphoreCreateInfo semaphoreCi = {
+ .sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO};
VK_CHECK(m_vk.vkCreateSemaphore(m_vkDevice, &semaphoreCi, nullptr,
&m_imageReadySem));
VK_CHECK(m_vk.vkCreateSemaphore(m_vkDevice, &semaphoreCi, nullptr,
&m_frameDrawCompleteSem));
- VkSamplerCreateInfo samplerCi = {};
- samplerCi.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
- samplerCi.magFilter = VK_FILTER_NEAREST;
- samplerCi.minFilter = VK_FILTER_NEAREST;
- samplerCi.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
- samplerCi.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
- samplerCi.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
- samplerCi.anisotropyEnable = VK_FALSE;
- samplerCi.maxAnisotropy = 1.0f;
- samplerCi.borderColor = VK_BORDER_COLOR_INT_TRANSPARENT_BLACK;
- samplerCi.unnormalizedCoordinates = VK_FALSE;
- samplerCi.compareEnable = VK_FALSE;
- samplerCi.compareOp = VK_COMPARE_OP_ALWAYS;
- samplerCi.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
- samplerCi.mipLodBias = 0.0f;
- samplerCi.minLod = 0.0f;
- samplerCi.maxLod = 0.0f;
+ VkSamplerCreateInfo samplerCi = {
+ .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
+ .magFilter = VK_FILTER_NEAREST,
+ .minFilter = VK_FILTER_NEAREST,
+ .mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR,
+ .addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER,
+ .addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER,
+ .addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER,
+ .mipLodBias = 0.0f,
+ .anisotropyEnable = VK_FALSE,
+ .maxAnisotropy = 1.0f,
+ .compareEnable = VK_FALSE,
+ .compareOp = VK_COMPARE_OP_ALWAYS,
+ .minLod = 0.0f,
+ .maxLod = 0.0f,
+ .borderColor = VK_BORDER_COLOR_INT_TRANSPARENT_BLACK,
+ .unnormalizedCoordinates = VK_FALSE};
VK_CHECK(m_vk.vkCreateSampler(m_vkDevice, &samplerCi, nullptr,
&m_compositionVkSampler));
}
@@ -158,26 +157,24 @@
VK_CHECK(m_vk.vkResetFences(m_vkDevice, 1, &m_frameDrawCompleteFence));
VkPipelineStageFlags waitStages[] = {
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT};
- VkSubmitInfo submitInfo = {};
- submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
- submitInfo.waitSemaphoreCount = 1;
- submitInfo.pWaitSemaphores = &m_imageReadySem;
- submitInfo.pWaitDstStageMask = waitStages;
- submitInfo.commandBufferCount = 1;
- submitInfo.pCommandBuffers = &cmdBuff;
- submitInfo.signalSemaphoreCount = 1;
- submitInfo.pSignalSemaphores = &m_frameDrawCompleteSem;
+ VkSubmitInfo submitInfo = {.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
+ .waitSemaphoreCount = 1,
+ .pWaitSemaphores = &m_imageReadySem,
+ .pWaitDstStageMask = waitStages,
+ .commandBufferCount = 1,
+ .pCommandBuffers = &cmdBuff,
+ .signalSemaphoreCount = 1,
+ .pSignalSemaphores = &m_frameDrawCompleteSem};
VK_CHECK(m_vk.vkQueueSubmit(m_compositorVkQueue, 1, &submitInfo,
m_frameDrawCompleteFence));
auto swapChain = m_swapChainStateVk->getSwapChain();
- VkPresentInfoKHR presentInfo = {};
- presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
- presentInfo.waitSemaphoreCount = 1;
- presentInfo.pWaitSemaphores = &m_frameDrawCompleteSem;
- presentInfo.swapchainCount = 1;
- presentInfo.pSwapchains = &swapChain;
- presentInfo.pImageIndices = &imageIndex;
+ VkPresentInfoKHR presentInfo = {.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR,
+ .waitSemaphoreCount = 1,
+ .pWaitSemaphores = &m_frameDrawCompleteSem,
+ .swapchainCount = 1,
+ .pSwapchains = &swapChain,
+ .pImageIndices = &imageIndex};
VK_CHECK(m_vk.vkQueuePresentKHR(m_swapChainVkQueue, &presentInfo));
VK_CHECK(m_vk.vkWaitForFences(m_vkDevice, 1, &m_frameDrawCompleteFence,
VK_TRUE, UINT64_MAX));
@@ -206,20 +203,20 @@
m_height(height),
m_vkFormat(format),
m_vkImageView(VK_NULL_HANDLE) {
- VkImageViewCreateInfo imageViewCi = {};
- imageViewCi.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
- imageViewCi.image = image;
- imageViewCi.viewType = VK_IMAGE_VIEW_TYPE_2D;
- imageViewCi.format = format;
- imageViewCi.components.r = VK_COMPONENT_SWIZZLE_IDENTITY;
- imageViewCi.components.g = VK_COMPONENT_SWIZZLE_IDENTITY;
- imageViewCi.components.b = VK_COMPONENT_SWIZZLE_IDENTITY;
- imageViewCi.components.a = VK_COMPONENT_SWIZZLE_IDENTITY;
- imageViewCi.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
- imageViewCi.subresourceRange.baseMipLevel = 0;
- imageViewCi.subresourceRange.levelCount = 1;
- imageViewCi.subresourceRange.baseArrayLayer = 0;
- imageViewCi.subresourceRange.layerCount = 1;
+ VkImageViewCreateInfo imageViewCi = {
+ .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
+ .image = image,
+ .viewType = VK_IMAGE_VIEW_TYPE_2D,
+ .format = format,
+ .components = {.r = VK_COMPONENT_SWIZZLE_IDENTITY,
+ .g = VK_COMPONENT_SWIZZLE_IDENTITY,
+ .b = VK_COMPONENT_SWIZZLE_IDENTITY,
+ .a = VK_COMPONENT_SWIZZLE_IDENTITY},
+ .subresourceRange = {.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
+ .baseMipLevel = 0,
+ .levelCount = 1,
+ .baseArrayLayer = 0,
+ .layerCount = 1}};
VK_CHECK(m_vk.vkCreateImageView(m_vkDevice, &imageViewCi, nullptr,
&m_vkImageView));
}
diff --git a/stream-servers/SwapChainStateVk.cpp b/stream-servers/SwapChainStateVk.cpp
index 7cd98c6..9ba435f 100644
--- a/stream-servers/SwapChainStateVk.cpp
+++ b/stream-servers/SwapChainStateVk.cpp
@@ -19,20 +19,20 @@
VK_CHECK(m_vk.vkGetSwapchainImagesKHR(m_vkDevice, m_vkSwapChain,
&imageCount, m_vkImages.data()));
for (auto i = 0; i < m_vkImages.size(); i++) {
- VkImageViewCreateInfo imageViewCi = {};
- imageViewCi.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
- imageViewCi.image = m_vkImages[i];
- imageViewCi.viewType = VK_IMAGE_VIEW_TYPE_2D;
- imageViewCi.format = k_vkFormat;
- imageViewCi.components.r = VK_COMPONENT_SWIZZLE_IDENTITY;
- imageViewCi.components.g = VK_COMPONENT_SWIZZLE_IDENTITY;
- imageViewCi.components.b = VK_COMPONENT_SWIZZLE_IDENTITY;
- imageViewCi.components.a = VK_COMPONENT_SWIZZLE_IDENTITY;
- imageViewCi.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
- imageViewCi.subresourceRange.baseMipLevel = 0;
- imageViewCi.subresourceRange.levelCount = 1;
- imageViewCi.subresourceRange.baseArrayLayer = 0;
- imageViewCi.subresourceRange.layerCount = 1;
+ VkImageViewCreateInfo imageViewCi = {
+ .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
+ .image = m_vkImages[i],
+ .viewType = VK_IMAGE_VIEW_TYPE_2D,
+ .format = k_vkFormat,
+ .components = {.r = VK_COMPONENT_SWIZZLE_IDENTITY,
+ .g = VK_COMPONENT_SWIZZLE_IDENTITY,
+ .b = VK_COMPONENT_SWIZZLE_IDENTITY,
+ .a = VK_COMPONENT_SWIZZLE_IDENTITY},
+ .subresourceRange = {.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
+ .baseMipLevel = 0,
+ .levelCount = 1,
+ .baseArrayLayer = 0,
+ .layerCount = 1}};
VkImageView vkImageView;
VK_CHECK(m_vk.vkCreateImageView(m_vkDevice, &imageViewCi, nullptr,
&vkImageView));
@@ -133,24 +133,25 @@
imageCount = surfaceCaps.maxImageCount;
}
VkSwapchainCreateInfoKHRPtr swapChainCi(
- new VkSwapchainCreateInfoKHR({}), [](VkSwapchainCreateInfoKHR *p) {
+ new VkSwapchainCreateInfoKHR{
+ .sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR,
+ .surface = surface,
+ .minImageCount = imageCount,
+ .imageFormat = iSurfaceFormat->format,
+ .imageColorSpace = iSurfaceFormat->colorSpace,
+ .imageExtent = extent,
+ .imageArrayLayers = 1,
+ .imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
+ .preTransform = surfaceCaps.currentTransform,
+ .compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR,
+ .presentMode = *iPresentMode,
+ .clipped = VK_TRUE,
+ .oldSwapchain = VK_NULL_HANDLE},
+ [](VkSwapchainCreateInfoKHR *p) {
if (p->pQueueFamilyIndices != nullptr) {
delete[] p->pQueueFamilyIndices;
}
});
- swapChainCi->sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
- swapChainCi->surface = surface;
- swapChainCi->minImageCount = imageCount;
- swapChainCi->imageFormat = iSurfaceFormat->format;
- swapChainCi->imageColorSpace = iSurfaceFormat->colorSpace;
- swapChainCi->imageExtent = extent;
- swapChainCi->imageArrayLayers = 1;
- swapChainCi->imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
- swapChainCi->preTransform = surfaceCaps.currentTransform;
- swapChainCi->compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
- swapChainCi->presentMode = *iPresentMode;
- swapChainCi->clipped = VK_TRUE;
- swapChainCi->oldSwapchain = VK_NULL_HANDLE;
if (queueFamilyIndices.empty()) {
return nullptr;
}
diff --git a/stream-servers/tests/CompositorVk_unittest.cpp b/stream-servers/tests/CompositorVk_unittest.cpp
index 428207e..7d585bd 100644
--- a/stream-servers/tests/CompositorVk_unittest.cpp
+++ b/stream-servers/tests/CompositorVk_unittest.cpp
@@ -1,7 +1,7 @@
-#include "CompositorVk.h"
-
#include <gtest/gtest.h>
+#include "CompositorVk.h"
+
#include <algorithm>
#include <array>
#include <glm/gtx/matrix_transform_2d.hpp>
@@ -46,9 +46,9 @@
GTEST_SKIP();
}
- VkCommandPoolCreateInfo commandPoolCi = {};
- commandPoolCi.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
- commandPoolCi.queueFamilyIndex = m_compositorQueueFamilyIndex;
+ VkCommandPoolCreateInfo commandPoolCi = {
+ .sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
+ .queueFamilyIndex = m_compositorQueueFamilyIndex};
ASSERT_EQ(k_vk->vkCreateCommandPool(m_vkDevice, &commandPoolCi, nullptr,
&m_vkCommandPool),
VK_SUCCESS);
@@ -93,23 +93,23 @@
}
VkSampler createSampler() {
- VkSamplerCreateInfo samplerCi = {};
- samplerCi.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
- samplerCi.magFilter = VK_FILTER_NEAREST;
- samplerCi.minFilter = VK_FILTER_NEAREST;
- samplerCi.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
- samplerCi.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
- samplerCi.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
- samplerCi.anisotropyEnable = VK_FALSE;
- samplerCi.maxAnisotropy = 1.0f;
- samplerCi.borderColor = VK_BORDER_COLOR_INT_TRANSPARENT_BLACK;
- samplerCi.unnormalizedCoordinates = VK_FALSE;
- samplerCi.compareEnable = VK_FALSE;
- samplerCi.compareOp = VK_COMPARE_OP_ALWAYS;
- samplerCi.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
- samplerCi.mipLodBias = 0.0f;
- samplerCi.minLod = 0.0f;
- samplerCi.maxLod = 0.0f;
+ VkSamplerCreateInfo samplerCi = {
+ .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
+ .magFilter = VK_FILTER_NEAREST,
+ .minFilter = VK_FILTER_NEAREST,
+ .mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR,
+ .addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER,
+ .addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER,
+ .addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER,
+ .mipLodBias = 0.0f,
+ .anisotropyEnable = VK_FALSE,
+ .maxAnisotropy = 1.0f,
+ .compareEnable = VK_FALSE,
+ .compareOp = VK_COMPARE_OP_ALWAYS,
+ .minLod = 0.0f,
+ .maxLod = 0.0f,
+ .borderColor = VK_BORDER_COLOR_INT_TRANSPARENT_BLACK,
+ .unnormalizedCoordinates = VK_FALSE};
VkSampler res;
VK_CHECK(k_vk->vkCreateSampler(m_vkDevice, &samplerCi, nullptr, &res));
return res;
@@ -127,19 +127,19 @@
private:
void createInstance() {
- VkApplicationInfo appInfo = {};
- appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
- appInfo.pNext = nullptr;
- appInfo.pApplicationName = "emulator CompositorVk unittest";
- appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
- appInfo.pEngineName = "No Engine";
- appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0);
- appInfo.apiVersion = VK_API_VERSION_1_1;
- VkInstanceCreateInfo instanceCi = {};
- instanceCi.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
- instanceCi.ppEnabledExtensionNames = nullptr;
- instanceCi.enabledExtensionCount = 0;
- instanceCi.pApplicationInfo = &appInfo;
+ VkApplicationInfo appInfo = {
+ .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
+ .pNext = nullptr,
+ .pApplicationName = "emulator CompositorVk unittest",
+ .applicationVersion = VK_MAKE_VERSION(1, 0, 0),
+ .pEngineName = "No Engine",
+ .engineVersion = VK_MAKE_VERSION(1, 0, 0),
+ .apiVersion = VK_API_VERSION_1_1};
+ VkInstanceCreateInfo instanceCi = {
+ .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
+ .pApplicationInfo = &appInfo,
+ .enabledExtensionCount = 0,
+ .ppEnabledExtensionNames = nullptr};
ASSERT_EQ(k_vk->vkCreateInstance(&instanceCi, nullptr, &m_vkInstance),
VK_SUCCESS);
ASSERT_TRUE(m_vkInstance != VK_NULL_HANDLE);
@@ -157,13 +157,12 @@
physicalDevices.data()),
VK_SUCCESS);
for (const auto &device : physicalDevices) {
- VkPhysicalDeviceDescriptorIndexingFeaturesEXT descIndexingFeatures =
- {};
- descIndexingFeatures.sType =
- VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT;
- VkPhysicalDeviceFeatures2 features = {};
- features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
- features.pNext = &descIndexingFeatures;
+ VkPhysicalDeviceDescriptorIndexingFeaturesEXT descIndexingFeatures = {
+ .sType =
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT};
+ VkPhysicalDeviceFeatures2 features = {
+ .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2,
+ .pNext = &descIndexingFeatures};
k_vk->vkGetPhysicalDeviceFeatures2(device, &features);
if (!CompositorVk::validatePhysicalDeviceFeatures(features)) {
continue;
@@ -196,30 +195,29 @@
void createLogicalDevice() {
const float queuePriority = 1.0f;
- VkDeviceQueueCreateInfo queueCi = {};
- queueCi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
- queueCi.queueFamilyIndex = m_compositorQueueFamilyIndex;
- queueCi.queueCount = 1;
- queueCi.pQueuePriorities = &queuePriority;
- VkPhysicalDeviceDescriptorIndexingFeaturesEXT descIndexingFeatures = {};
- descIndexingFeatures.sType =
- VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT;
- VkPhysicalDeviceFeatures2 features = {};
- features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
- features.pNext = &descIndexingFeatures;
+ VkDeviceQueueCreateInfo queueCi = {
+ .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
+ .queueFamilyIndex = m_compositorQueueFamilyIndex,
+ .queueCount = 1,
+ .pQueuePriorities = &queuePriority};
+ VkPhysicalDeviceDescriptorIndexingFeaturesEXT descIndexingFeatures = {
+ .sType =
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT};
+ VkPhysicalDeviceFeatures2 features = {
+ .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2,
+ .pNext = &descIndexingFeatures};
ASSERT_TRUE(CompositorVk::enablePhysicalDeviceFeatures(features));
const std::vector<const char *> enabledDeviceExtensions =
CompositorVk::getRequiredDeviceExtensions();
- VkDeviceCreateInfo deviceCi = {};
- deviceCi.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
- deviceCi.pQueueCreateInfos = &queueCi;
- deviceCi.queueCreateInfoCount = 1;
- deviceCi.pEnabledFeatures = nullptr;
- deviceCi.enabledLayerCount = 0;
- deviceCi.enabledExtensionCount =
- static_cast<uint32_t>(enabledDeviceExtensions.size());
- deviceCi.ppEnabledExtensionNames = enabledDeviceExtensions.data();
- deviceCi.pNext = &features;
+ VkDeviceCreateInfo deviceCi = {
+ .sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
+ .pNext = &features,
+ .queueCreateInfoCount = 1,
+ .pQueueCreateInfos = &queueCi,
+ .enabledLayerCount = 0,
+ .enabledExtensionCount =
+ static_cast<uint32_t>(enabledDeviceExtensions.size()),
+ .ppEnabledExtensionNames = enabledDeviceExtensions.data()};
ASSERT_EQ(k_vk->vkCreateDevice(m_vkPhysicalDevice, &deviceCi, nullptr,
&m_vkDevice),
VK_SUCCESS);
@@ -229,18 +227,16 @@
const goldfish_vk::VulkanDispatch *CompositorVkTest::k_vk = nullptr;
-TEST_F(CompositorVkTest, Init) {
- ASSERT_NE(createCompositor(), nullptr);
-}
+TEST_F(CompositorVkTest, Init) { ASSERT_NE(createCompositor(), nullptr); }
TEST_F(CompositorVkTest, ValidatePhysicalDeviceFeatures) {
- VkPhysicalDeviceFeatures2 features = {};
- features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
+ VkPhysicalDeviceFeatures2 features = {
+ .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2};
ASSERT_FALSE(CompositorVk::validatePhysicalDeviceFeatures(features));
- VkPhysicalDeviceDescriptorIndexingFeaturesEXT descIndexingFeatures = {};
- descIndexingFeatures.sType =
- VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT;
- features.pNext = &descIndexingFeatures;
+ VkPhysicalDeviceDescriptorIndexingFeaturesEXT descIndexingFeatures = {
+ .sType =
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT,
+ .pNext = &descIndexingFeatures};
ASSERT_FALSE(CompositorVk::validatePhysicalDeviceFeatures(features));
descIndexingFeatures.descriptorBindingSampledImageUpdateAfterBind = VK_TRUE;
ASSERT_TRUE(CompositorVk::validatePhysicalDeviceFeatures(features));
@@ -255,13 +251,13 @@
}
TEST_F(CompositorVkTest, EnablePhysicalDeviceFeatures) {
- VkPhysicalDeviceFeatures2 features = {};
- features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
+ VkPhysicalDeviceFeatures2 features = {
+ .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2};
ASSERT_FALSE(CompositorVk::enablePhysicalDeviceFeatures(features));
- VkPhysicalDeviceDescriptorIndexingFeaturesEXT descIndexingFeatures = {};
- descIndexingFeatures.sType =
- VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT;
- features.pNext = &descIndexingFeatures;
+ VkPhysicalDeviceDescriptorIndexingFeaturesEXT descIndexingFeatures = {
+ .sType =
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT,
+ .pNext = &descIndexingFeatures};
ASSERT_TRUE(CompositorVk::enablePhysicalDeviceFeatures(features));
ASSERT_EQ(descIndexingFeatures.descriptorBindingSampledImageUpdateAfterBind,
VK_TRUE);
@@ -296,10 +292,10 @@
cmdBuffs.emplace_back(compositor->getCommandBuffer(i));
}
}
- VkSubmitInfo submitInfo = {};
- submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
- submitInfo.commandBufferCount = static_cast<uint32_t>(cmdBuffs.size());
- submitInfo.pCommandBuffers = cmdBuffs.data();
+ VkSubmitInfo submitInfo = {
+ .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
+ .commandBufferCount = static_cast<uint32_t>(cmdBuffs.size()),
+ .pCommandBuffers = cmdBuffs.data()};
ASSERT_EQ(k_vk->vkQueueSubmit(m_compositorVkQueue, 1, &submitInfo,
VK_NULL_HANDLE),
VK_SUCCESS);
@@ -354,10 +350,9 @@
composition->m_transform = transform;
compositor->setComposition(0, std::move(composition));
VkCommandBuffer cmdBuff = compositor->getCommandBuffer(0);
- VkSubmitInfo submitInfo = {};
- submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
- submitInfo.commandBufferCount = 1;
- submitInfo.pCommandBuffers = &cmdBuff;
+ VkSubmitInfo submitInfo = {.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
+ .commandBufferCount = 1,
+ .pCommandBuffers = &cmdBuff};
ASSERT_EQ(k_vk->vkQueueSubmit(m_compositorVkQueue, 1, &submitInfo,
VK_NULL_HANDLE),
VK_SUCCESS);
@@ -428,10 +423,9 @@
composition->m_transform = transform;
compositor->setComposition(i, std::move(composition));
VkCommandBuffer cmdBuff = compositor->getCommandBuffer(i);
- VkSubmitInfo submitInfo = {};
- submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
- submitInfo.commandBufferCount = 1;
- submitInfo.pCommandBuffers = &cmdBuff;
+ VkSubmitInfo submitInfo = {.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
+ .commandBufferCount = 1,
+ .pCommandBuffers = &cmdBuff};
ASSERT_EQ(k_vk->vkQueueSubmit(m_compositorVkQueue, 1, &submitInfo,
VK_NULL_HANDLE),
VK_SUCCESS);
diff --git a/stream-servers/tests/DisplayVk_unittest.cpp b/stream-servers/tests/DisplayVk_unittest.cpp
index fee1747..71b1960 100644
--- a/stream-servers/tests/DisplayVk_unittest.cpp
+++ b/stream-servers/tests/DisplayVk_unittest.cpp
@@ -26,9 +26,9 @@
&m_compositorVkQueue);
k_vk->vkGetDeviceQueue(m_vkDevice, m_swapChainQueueFamilyIndex, 0,
&m_swapChainVkQueue);
- VkCommandPoolCreateInfo commandPoolCi = {};
- commandPoolCi.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
- commandPoolCi.queueFamilyIndex = m_compositorQueueFamilyIndex;
+ VkCommandPoolCreateInfo commandPoolCi = {
+ .sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
+ .queueFamilyIndex = m_compositorQueueFamilyIndex};
ASSERT_EQ(k_vk->vkCreateCommandPool(m_vkDevice, &commandPoolCi, nullptr,
&m_vkCommandPool),
VK_SUCCESS);
@@ -72,21 +72,20 @@
private:
void createInstance() {
- VkApplicationInfo appInfo = {};
- appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
- appInfo.pNext = nullptr;
- appInfo.pApplicationName = "emulator SwapChainStateVk unittest";
- appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
- appInfo.pEngineName = "No Engine";
- appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0);
- appInfo.apiVersion = VK_API_VERSION_1_1;
+ VkApplicationInfo appInfo = {
+ .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
+ .pNext = nullptr,
+ .pApplicationName = "emulator SwapChainStateVk unittest",
+ .applicationVersion = VK_MAKE_VERSION(1, 0, 0),
+ .pEngineName = "No Engine",
+ .engineVersion = VK_MAKE_VERSION(1, 0, 0),
+ .apiVersion = VK_API_VERSION_1_1};
auto extensions = SwapChainStateVk::getRequiredInstanceExtensions();
- VkInstanceCreateInfo instanceCi = {};
- instanceCi.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
- instanceCi.ppEnabledExtensionNames = extensions.data();
- instanceCi.enabledExtensionCount =
- static_cast<uint32_t>(extensions.size());
- instanceCi.pApplicationInfo = &appInfo;
+ VkInstanceCreateInfo instanceCi = {
+ .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
+ .pApplicationInfo = &appInfo,
+ .enabledExtensionCount = static_cast<uint32_t>(extensions.size()),
+ .ppEnabledExtensionNames = extensions.data()};
ASSERT_EQ(k_vk->vkCreateInstance(&instanceCi, nullptr, &m_vkInstance),
VK_SUCCESS);
ASSERT_TRUE(m_vkInstance != VK_NULL_HANDLE);
@@ -97,10 +96,10 @@
ASSERT_NE(m_window, nullptr);
// TODO(kaiyili, b/179477624): add support for other platforms
#ifdef _WIN32
- VkWin32SurfaceCreateInfoKHR surfaceCi = {};
- surfaceCi.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
- surfaceCi.hinstance = GetModuleHandle(nullptr);
- surfaceCi.hwnd = m_window->getNativeWindow();
+ VkWin32SurfaceCreateInfoKHR surfaceCi = {
+ .sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR,
+ .hinstance = GetModuleHandle(nullptr),
+ .hwnd = m_window->getNativeWindow()};
ASSERT_EQ(k_vk->vkCreateWin32SurfaceKHR(m_vkInstance, &surfaceCi,
nullptr, &m_vkSurface),
VK_SUCCESS);
@@ -119,13 +118,12 @@
physicalDevices.data()),
VK_SUCCESS);
for (const auto &device : physicalDevices) {
- VkPhysicalDeviceDescriptorIndexingFeaturesEXT descIndexingFeatures =
- {};
- descIndexingFeatures.sType =
- VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT;
- VkPhysicalDeviceFeatures2 features = {};
- features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
- features.pNext = &descIndexingFeatures;
+ VkPhysicalDeviceDescriptorIndexingFeaturesEXT descIndexingFeatures = {
+ .sType =
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT};
+ VkPhysicalDeviceFeatures2 features = {
+ .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2,
+ .pNext = &descIndexingFeatures};
k_vk->vkGetPhysicalDeviceFeatures2(device, &features);
if (!CompositorVk::validatePhysicalDeviceFeatures(features)) {
continue;
@@ -176,35 +174,34 @@
std::vector<VkDeviceQueueCreateInfo> queueCis(0);
for (auto queueFamilyIndex : std::unordered_set(
{m_swapChainQueueFamilyIndex, m_compositorQueueFamilyIndex})) {
- VkDeviceQueueCreateInfo queueCi = {};
- queueCi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
- queueCi.queueFamilyIndex = queueFamilyIndex;
- queueCi.queueCount = 1;
- queueCi.pQueuePriorities = &queuePriority;
+ VkDeviceQueueCreateInfo queueCi = {
+ .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
+ .queueFamilyIndex = queueFamilyIndex,
+ .queueCount = 1,
+ .pQueuePriorities = &queuePriority};
queueCis.push_back(queueCi);
}
- VkPhysicalDeviceDescriptorIndexingFeaturesEXT descIndexingFeatures = {};
- descIndexingFeatures.sType =
- VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT;
- VkPhysicalDeviceFeatures2 features = {};
- features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
- features.pNext = &descIndexingFeatures;
+ VkPhysicalDeviceDescriptorIndexingFeaturesEXT descIndexingFeatures = {
+ .sType =
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT};
+ VkPhysicalDeviceFeatures2 features = {
+ .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2,
+ .pNext = &descIndexingFeatures};
ASSERT_TRUE(CompositorVk::enablePhysicalDeviceFeatures(features));
auto extensions = SwapChainStateVk::getRequiredDeviceExtensions();
const auto compositorExtensions =
CompositorVk::getRequiredDeviceExtensions();
extensions.insert(extensions.end(), compositorExtensions.begin(),
compositorExtensions.end());
- VkDeviceCreateInfo deviceCi = {};
- deviceCi.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
- deviceCi.pQueueCreateInfos = queueCis.data();
- deviceCi.queueCreateInfoCount = static_cast<uint32_t>(queueCis.size());
- deviceCi.pEnabledFeatures = nullptr;
- deviceCi.enabledLayerCount = 0;
- deviceCi.enabledExtensionCount =
- static_cast<uint32_t>(extensions.size());
- deviceCi.ppEnabledExtensionNames = extensions.data();
- deviceCi.pNext = &features;
+ VkDeviceCreateInfo deviceCi = {
+ .sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
+ .pNext = &features,
+ .queueCreateInfoCount = static_cast<uint32_t>(queueCis.size()),
+ .pQueueCreateInfos = queueCis.data(),
+ .enabledLayerCount = 0,
+ .enabledExtensionCount = static_cast<uint32_t>(extensions.size()),
+ .ppEnabledExtensionNames = extensions.data(),
+ .pEnabledFeatures = nullptr};
ASSERT_EQ(k_vk->vkCreateDevice(m_vkPhysicalDevice, &deviceCi, nullptr,
&m_vkDevice),
VK_SUCCESS);
diff --git a/stream-servers/tests/SwapChainStateVk_unittest.cpp b/stream-servers/tests/SwapChainStateVk_unittest.cpp
index b119e0f..f3ed3e6 100644
--- a/stream-servers/tests/SwapChainStateVk_unittest.cpp
+++ b/stream-servers/tests/SwapChainStateVk_unittest.cpp
@@ -1,7 +1,7 @@
-#include "SwapChainStateVk.h"
-
#include <gtest/gtest.h>
+#include "SwapChainStateVk.h"
+
#include "Standalone.h"
#include "vulkan/VulkanDispatch.h"
@@ -43,21 +43,20 @@
private:
void createInstance() {
- VkApplicationInfo appInfo = {};
- appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
- appInfo.pNext = nullptr;
- appInfo.pApplicationName = "emulator SwapChainStateVk unittest";
- appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
- appInfo.pEngineName = "No Engine";
- appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0);
- appInfo.apiVersion = VK_API_VERSION_1_1;
+ VkApplicationInfo appInfo = {
+ .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
+ .pNext = nullptr,
+ .pApplicationName = "emulator SwapChainStateVk unittest",
+ .applicationVersion = VK_MAKE_VERSION(1, 0, 0),
+ .pEngineName = "No Engine",
+ .engineVersion = VK_MAKE_VERSION(1, 0, 0),
+ .apiVersion = VK_API_VERSION_1_1};
auto extensions = SwapChainStateVk::getRequiredInstanceExtensions();
- VkInstanceCreateInfo instanceCi = {};
- instanceCi.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
- instanceCi.ppEnabledExtensionNames = extensions.data();
- instanceCi.enabledExtensionCount =
- static_cast<uint32_t>(extensions.size());
- instanceCi.pApplicationInfo = &appInfo;
+ VkInstanceCreateInfo instanceCi = {
+ .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
+ .pApplicationInfo = &appInfo,
+ .enabledExtensionCount = static_cast<uint32_t>(extensions.size()),
+ .ppEnabledExtensionNames = extensions.data()};
ASSERT_EQ(k_vk->vkCreateInstance(&instanceCi, nullptr, &m_vkInstance),
VK_SUCCESS);
ASSERT_TRUE(m_vkInstance != VK_NULL_HANDLE);
@@ -68,10 +67,10 @@
ASSERT_NE(m_window, nullptr);
// TODO(kaiyili, b/179477624): add support for other platforms
#ifdef _WIN32
- VkWin32SurfaceCreateInfoKHR surfaceCi = {};
- surfaceCi.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
- surfaceCi.hinstance = GetModuleHandle(nullptr);
- surfaceCi.hwnd = m_window->getNativeWindow();
+ VkWin32SurfaceCreateInfoKHR surfaceCi = {
+ .sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR,
+ .hinstance = GetModuleHandle(nullptr),
+ .hwnd = m_window->getNativeWindow()};
ASSERT_EQ(k_vk->vkCreateWin32SurfaceKHR(m_vkInstance, &surfaceCi,
nullptr, &m_vkSurface),
VK_SUCCESS);
@@ -120,23 +119,23 @@
void createLogicalDevice() {
const float queuePriority = 1.0f;
- VkDeviceQueueCreateInfo queueCi = {};
- queueCi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
- queueCi.queueFamilyIndex = m_swapChainQueueFamilyIndex;
- queueCi.queueCount = 1;
- queueCi.pQueuePriorities = &queuePriority;
+ VkDeviceQueueCreateInfo queueCi = {
+ .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
+ .queueFamilyIndex = m_swapChainQueueFamilyIndex,
+ .queueCount = 1,
+ .pQueuePriorities = &queuePriority};
VkPhysicalDeviceFeatures features = {};
const std::vector<const char *> enabledDeviceExtensions =
SwapChainStateVk::getRequiredDeviceExtensions();
- VkDeviceCreateInfo deviceCi = {};
- deviceCi.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
- deviceCi.pQueueCreateInfos = &queueCi;
- deviceCi.queueCreateInfoCount = 1;
- deviceCi.pEnabledFeatures = &features;
- deviceCi.enabledLayerCount = 0;
- deviceCi.enabledExtensionCount =
- static_cast<uint32_t>(enabledDeviceExtensions.size());
- deviceCi.ppEnabledExtensionNames = enabledDeviceExtensions.data();
+ VkDeviceCreateInfo deviceCi = {
+ .sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
+ .queueCreateInfoCount = 1,
+ .pQueueCreateInfos = &queueCi,
+ .enabledLayerCount = 0,
+ .enabledExtensionCount =
+ static_cast<uint32_t>(enabledDeviceExtensions.size()),
+ .ppEnabledExtensionNames = enabledDeviceExtensions.data(),
+ .pEnabledFeatures = &features};
ASSERT_EQ(k_vk->vkCreateDevice(m_vkPhysicalDevice, &deviceCi, nullptr,
&m_vkDevice),
VK_SUCCESS);
diff --git a/stream-servers/tests/VkTestUtils.h b/stream-servers/tests/VkTestUtils.h
index a8dcb4a..6164bae 100644
--- a/stream-servers/tests/VkTestUtils.h
+++ b/stream-servers/tests/VkTestUtils.h
@@ -110,21 +110,11 @@
if (m_memory) {
m_vk.vkUnmapMemory(m_vkDevice, m_bufferVkDeviceMemory);
}
- if (m_bufferVkDeviceMemory != VK_NULL_HANDLE) {
- m_vk.vkFreeMemory(m_vkDevice, m_bufferVkDeviceMemory, nullptr);
- }
- if (m_vkBuffer != VK_NULL_HANDLE) {
- m_vk.vkDestroyBuffer(m_vkDevice, m_vkBuffer, nullptr);
- }
- if (m_vkImageView != VK_NULL_HANDLE) {
- m_vk.vkDestroyImageView(m_vkDevice, m_vkImageView, nullptr);
- }
- if (m_imageVkDeviceMemory != VK_NULL_HANDLE) {
- m_vk.vkFreeMemory(m_vkDevice, m_imageVkDeviceMemory, nullptr);
- }
- if (m_vkImage != VK_NULL_HANDLE) {
- m_vk.vkDestroyImage(m_vkDevice, m_vkImage, nullptr);
- }
+ m_vk.vkFreeMemory(m_vkDevice, m_bufferVkDeviceMemory, nullptr);
+ m_vk.vkDestroyBuffer(m_vkDevice, m_vkBuffer, nullptr);
+ m_vk.vkDestroyImageView(m_vkDevice, m_vkImageView, nullptr);
+ m_vk.vkFreeMemory(m_vkDevice, m_imageVkDeviceMemory, nullptr);
+ m_vk.vkDestroyImage(m_vkDevice, m_vkImage, nullptr);
}
private:
@@ -132,22 +122,19 @@
: RenderResourceVkBase(vk) {}
bool setUpImage() {
- VkImageCreateInfo imageCi{};
- imageCi.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
- imageCi.imageType = VK_IMAGE_TYPE_2D;
- imageCi.extent.width = m_width;
- imageCi.extent.height = m_height;
- imageCi.extent.depth = 1;
- imageCi.mipLevels = 1;
- imageCi.arrayLayers = 1;
- imageCi.format = k_vkFormat;
- imageCi.tiling = VK_IMAGE_TILING_OPTIMAL;
- imageCi.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
- imageCi.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT |
- VK_IMAGE_USAGE_TRANSFER_SRC_BIT | imageUsage;
- imageCi.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
- imageCi.samples = VK_SAMPLE_COUNT_1_BIT;
- imageCi.flags = 0;
+ VkImageCreateInfo imageCi{
+ .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
+ .imageType = VK_IMAGE_TYPE_2D,
+ .format = k_vkFormat,
+ .extent = {.width = m_width, .height = m_height, .depth = 1},
+ .mipLevels = 1,
+ .arrayLayers = 1,
+ .samples = VK_SAMPLE_COUNT_1_BIT,
+ .tiling = VK_IMAGE_TILING_OPTIMAL,
+ .usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT |
+ VK_IMAGE_USAGE_TRANSFER_SRC_BIT | imageUsage,
+ .sharingMode = VK_SHARING_MODE_EXCLUSIVE,
+ .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED};
if (m_vk.vkCreateImage(m_vkDevice, &imageCi, nullptr, &m_vkImage) !=
VK_SUCCESS) {
m_vkImage = VK_NULL_HANDLE;
@@ -163,10 +150,10 @@
if (!maybeMemoryTypeIndex.has_value()) {
return false;
}
- VkMemoryAllocateInfo allocInfo = {};
- allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
- allocInfo.allocationSize = memRequirements.size;
- allocInfo.memoryTypeIndex = maybeMemoryTypeIndex.value();
+ VkMemoryAllocateInfo allocInfo = {
+ .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
+ .allocationSize = memRequirements.size,
+ .memoryTypeIndex = maybeMemoryTypeIndex.value()};
if (m_vk.vkAllocateMemory(m_vkDevice, &allocInfo, nullptr,
&m_imageVkDeviceMemory) != VK_SUCCESS) {
m_imageVkDeviceMemory = VK_NULL_HANDLE;
@@ -182,20 +169,20 @@
cmdBuff, m_vkImage, VK_IMAGE_LAYOUT_UNDEFINED, k_vkImageLayout);
});
- VkImageViewCreateInfo imageViewCi = {};
- imageViewCi.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
- imageViewCi.image = m_vkImage;
- imageViewCi.viewType = VK_IMAGE_VIEW_TYPE_2D;
- imageViewCi.format = k_vkFormat;
- imageViewCi.components.r = VK_COMPONENT_SWIZZLE_IDENTITY;
- imageViewCi.components.g = VK_COMPONENT_SWIZZLE_IDENTITY;
- imageViewCi.components.b = VK_COMPONENT_SWIZZLE_IDENTITY;
- imageViewCi.components.a = VK_COMPONENT_SWIZZLE_IDENTITY;
- imageViewCi.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
- imageViewCi.subresourceRange.baseMipLevel = 0;
- imageViewCi.subresourceRange.levelCount = 1;
- imageViewCi.subresourceRange.baseArrayLayer = 0;
- imageViewCi.subresourceRange.layerCount = 1;
+ VkImageViewCreateInfo imageViewCi = {
+ .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
+ .image = m_vkImage,
+ .viewType = VK_IMAGE_VIEW_TYPE_2D,
+ .format = k_vkFormat,
+ .components = {.r = VK_COMPONENT_SWIZZLE_IDENTITY,
+ .g = VK_COMPONENT_SWIZZLE_IDENTITY,
+ .b = VK_COMPONENT_SWIZZLE_IDENTITY,
+ .a = VK_COMPONENT_SWIZZLE_IDENTITY},
+ .subresourceRange = {.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
+ .baseMipLevel = 0,
+ .levelCount = 1,
+ .baseArrayLayer = 0,
+ .layerCount = 1}};
if (m_vk.vkCreateImageView(m_vkDevice, &imageViewCi, nullptr,
&m_vkImageView) != VK_SUCCESS) {
return false;
@@ -204,10 +191,9 @@
}
bool submitCommandBufferAndWait(VkCommandBuffer cmdBuff) const {
- VkSubmitInfo submitInfo = {};
- submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
- submitInfo.commandBufferCount = 1;
- submitInfo.pCommandBuffers = &cmdBuff;
+ VkSubmitInfo submitInfo = {.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
+ .commandBufferCount = 1,
+ .pCommandBuffers = &cmdBuff};
if (m_vk.vkQueueSubmit(m_vkQueue, 1, &submitInfo, VK_NULL_HANDLE) !=
VK_SUCCESS) {
return false;
@@ -219,12 +205,12 @@
}
bool setUpBuffer() {
- VkBufferCreateInfo bufferCi = {};
- bufferCi.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
- bufferCi.size = m_width * m_height * k_bpp;
- bufferCi.usage =
- VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
- bufferCi.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
+ VkBufferCreateInfo bufferCi = {
+ .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
+ .size = m_width * m_height * k_bpp,
+ .usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT |
+ VK_BUFFER_USAGE_TRANSFER_DST_BIT,
+ .sharingMode = VK_SHARING_MODE_EXCLUSIVE};
if (m_vk.vkCreateBuffer(m_vkDevice, &bufferCi, nullptr, &m_vkBuffer) !=
VK_SUCCESS) {
@@ -242,10 +228,10 @@
if (!maybeMemoryTypeIndex.has_value()) {
return false;
}
- VkMemoryAllocateInfo allocInfo = {};
- allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
- allocInfo.allocationSize = memRequirements.size;
- allocInfo.memoryTypeIndex = maybeMemoryTypeIndex.value();
+ VkMemoryAllocateInfo allocInfo = {
+ .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
+ .allocationSize = memRequirements.size,
+ .memoryTypeIndex = maybeMemoryTypeIndex.value()};
if (m_vk.vkAllocateMemory(m_vkDevice, &allocInfo, nullptr,
&m_bufferVkDeviceMemory) != VK_SUCCESS) {
m_bufferVkDeviceMemory = VK_NULL_HANDLE;
@@ -266,12 +252,11 @@
bool setUpCommandBuffer() {
std::array<VkCommandBuffer, 2> cmdBuffs;
- VkCommandBufferAllocateInfo cmdBuffAllocInfo = {};
- cmdBuffAllocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
- cmdBuffAllocInfo.commandPool = m_vkCommandPool;
- cmdBuffAllocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
- cmdBuffAllocInfo.commandBufferCount =
- static_cast<uint32_t>(cmdBuffs.size());
+ VkCommandBufferAllocateInfo cmdBuffAllocInfo = {
+ .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
+ .commandPool = m_vkCommandPool,
+ .level = VK_COMMAND_BUFFER_LEVEL_PRIMARY,
+ .commandBufferCount = static_cast<uint32_t>(cmdBuffs.size())};
if (m_vk.vkAllocateCommandBuffers(m_vkDevice, &cmdBuffAllocInfo,
cmdBuffs.data()) != VK_SUCCESS) {
return false;
@@ -279,8 +264,8 @@
m_readCommandBuffer = cmdBuffs[0];
m_writeCommandBuffer = cmdBuffs[1];
- VkCommandBufferBeginInfo beginInfo = {};
- beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
+ VkCommandBufferBeginInfo beginInfo = {
+ .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO};
if (m_vk.vkBeginCommandBuffer(m_readCommandBuffer, &beginInfo) !=
VK_SUCCESS) {
return false;
@@ -288,16 +273,16 @@
recordImageLayoutTransformCommands(
m_readCommandBuffer, m_vkImage, k_vkImageLayout,
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
- VkBufferImageCopy region = {};
- region.bufferOffset = 0;
- region.bufferRowLength = 0;
- region.bufferImageHeight = 0;
- region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
- region.imageSubresource.mipLevel = 0;
- region.imageSubresource.baseArrayLayer = 0;
- region.imageSubresource.layerCount = 1;
- region.imageOffset = {0, 0, 0};
- region.imageExtent = {m_width, m_height, 1};
+ VkBufferImageCopy region = {
+ .bufferOffset = 0,
+ .bufferRowLength = 0,
+ .bufferImageHeight = 0,
+ .imageSubresource = {.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
+ .mipLevel = 0,
+ .baseArrayLayer = 0,
+ .layerCount = 1},
+ .imageOffset = {0, 0, 0},
+ .imageExtent = {m_width, m_height, 1}};
m_vk.vkCmdCopyImageToBuffer(m_readCommandBuffer, m_vkImage,
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
m_vkBuffer, 1, ®ion);
@@ -326,7 +311,7 @@
}
return true;
}
-};
+}; // namespace emugl
using RenderTextureVk =
emugl::RenderResourceVk<VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
diff --git a/stream-servers/vulkan/vk_util.h b/stream-servers/vulkan/vk_util.h
index 7c4064d..91aa2d5 100644
--- a/stream-servers/vulkan/vk_util.h
+++ b/stream-servers/vulkan/vk_util.h
@@ -290,23 +290,22 @@
std::function<void(const VkCommandBuffer &commandBuffer)> f) const {
const T &self = static_cast<const T &>(*this);
VkCommandBuffer cmdBuff;
- VkCommandBufferAllocateInfo cmdBuffAllocInfo = {};
- cmdBuffAllocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
- cmdBuffAllocInfo.commandPool = self.m_vkCommandPool;
- cmdBuffAllocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
- cmdBuffAllocInfo.commandBufferCount = 1;
+ VkCommandBufferAllocateInfo cmdBuffAllocInfo = {
+ .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
+ .commandPool = self.m_vkCommandPool,
+ .level = VK_COMMAND_BUFFER_LEVEL_PRIMARY,
+ .commandBufferCount = 1};
VK_CHECK(self.m_vk.vkAllocateCommandBuffers(
self.m_vkDevice, &cmdBuffAllocInfo, &cmdBuff));
- VkCommandBufferBeginInfo beginInfo = {};
- beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
- beginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
+ VkCommandBufferBeginInfo beginInfo = {
+ .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
+ .flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT};
VK_CHECK(self.m_vk.vkBeginCommandBuffer(cmdBuff, &beginInfo));
f(cmdBuff);
VK_CHECK(self.m_vk.vkEndCommandBuffer(cmdBuff));
- VkSubmitInfo submitInfo = {};
- submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
- submitInfo.commandBufferCount = 1;
- submitInfo.pCommandBuffers = &cmdBuff;
+ VkSubmitInfo submitInfo = {.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
+ .commandBufferCount = 1,
+ .pCommandBuffers = &cmdBuff};
VK_CHECK(
self.m_vk.vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE));
VK_CHECK(self.m_vk.vkQueueWaitIdle(queue));
@@ -322,20 +321,20 @@
VkImageLayout oldLayout,
VkImageLayout newLayout) const {
const T &self = static_cast<const T &>(*this);
- VkImageMemoryBarrier imageBarrier = {};
- imageBarrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
- imageBarrier.srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT;
- imageBarrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
- imageBarrier.oldLayout = oldLayout;
- imageBarrier.newLayout = newLayout;
- imageBarrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
- imageBarrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
- imageBarrier.image = image;
- imageBarrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
- imageBarrier.subresourceRange.baseMipLevel = 0;
- imageBarrier.subresourceRange.levelCount = 1;
- imageBarrier.subresourceRange.baseArrayLayer = 0;
- imageBarrier.subresourceRange.layerCount = 1;
+ VkImageMemoryBarrier imageBarrier = {
+ .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
+ .srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT,
+ .dstAccessMask = VK_ACCESS_SHADER_READ_BIT,
+ .oldLayout = oldLayout,
+ .newLayout = newLayout,
+ .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
+ .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
+ .image = image,
+ .subresourceRange{.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
+ .baseMipLevel = 0,
+ .levelCount = 1,
+ .baseArrayLayer = 0,
+ .layerCount = 1}};
self.m_vk.vkCmdPipelineBarrier(cmdBuff,
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,