comp: Don't initialize unused fields in Vulkan structs.

In order to save redundancy with initializing empty fields with NULL / 0
values and improve readability of the Vulkan code.

This patch also uses struct initializers where possible.

This essentially reverts 1eae45212e.
This commit is contained in:
Lubosz Sarnecki 2020-03-31 18:37:08 +02:00
parent 65d6ade6f3
commit b6d8d4b458
5 changed files with 8 additions and 151 deletions

View file

@ -278,7 +278,6 @@ vk_create_image_from_fd(struct vk_bundle *vk,
VkExternalMemoryImageCreateInfoKHR external_memory_image_create_info = {
.sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO_KHR,
.pNext = NULL,
.handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR,
};
@ -304,7 +303,6 @@ vk_create_image_from_fd(struct vk_bundle *vk,
VkImageCreateInfo info = {
.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
.pNext = &external_memory_image_create_info,
.flags = 0,
.imageType = VK_IMAGE_TYPE_2D,
.format = (VkFormat)format,
.extent = {.width = width, .height = height, .depth = 1},
@ -314,8 +312,6 @@ vk_create_image_from_fd(struct vk_bundle *vk,
.tiling = VK_IMAGE_TILING_OPTIMAL,
.usage = image_usage,
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
.queueFamilyIndexCount = 0,
.pQueueFamilyIndices = NULL,
.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
};
@ -399,8 +395,6 @@ vk_create_view(struct vk_bundle *vk,
VkImageViewCreateInfo imageView = {
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
.pNext = NULL,
.flags = 0,
.image = image,
.viewType = VK_IMAGE_VIEW_TYPE_2D,
.format = format,
@ -441,7 +435,6 @@ vk_init_cmd_buffer(struct vk_bundle *vk, VkCommandBuffer *out_cmd_buffer)
// Allocate the command buffer.
VkCommandBufferAllocateInfo cmd_buffer_info = {
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
.pNext = NULL,
.commandPool = vk->cmd_pool,
.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY,
.commandBufferCount = 1,
@ -459,9 +452,6 @@ vk_init_cmd_buffer(struct vk_bundle *vk, VkCommandBuffer *out_cmd_buffer)
// Start the command buffer as well.
VkCommandBufferBeginInfo begin_info = {
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
.pNext = NULL,
.flags = 0,
.pInheritanceInfo = NULL,
};
ret = vk->vkBeginCommandBuffer(cmd_buffer, &begin_info);
if (ret != VK_SUCCESS) {
@ -492,7 +482,6 @@ vk_set_image_layout(struct vk_bundle *vk,
{
VkImageMemoryBarrier barrier = {
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
.pNext = 0,
.srcAccessMask = src_access_mask,
.dstAccessMask = dst_access_mask,
.oldLayout = old_layout,
@ -518,19 +507,11 @@ vk_submit_cmd_buffer(struct vk_bundle *vk, VkCommandBuffer cmd_buffer)
VkFence fence;
VkFenceCreateInfo fence_info = {
.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
.pNext = NULL,
.flags = 0,
};
VkSubmitInfo submitInfo = {
.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
.pNext = NULL,
.waitSemaphoreCount = 0,
.pWaitSemaphores = NULL,
.pWaitDstStageMask = NULL,
.commandBufferCount = 1,
.pCommandBuffers = &cmd_buffer,
.signalSemaphoreCount = 0,
.pSignalSemaphores = NULL,
};
// Finish the command buffer first.
@ -551,7 +532,6 @@ vk_submit_cmd_buffer(struct vk_bundle *vk, VkCommandBuffer cmd_buffer)
}
// Do the actual submitting.
ret = vk->vkQueueSubmit(queue, 1, &submitInfo, fence);
if (ret != VK_SUCCESS) {
VK_ERROR(vk, "Error: Could not submit queue.\n");
@ -580,7 +560,6 @@ vk_init_cmd_pool(struct vk_bundle *vk)
{
VkCommandPoolCreateInfo cmd_pool_info = {
.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
.pNext = NULL,
.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,
.queueFamilyIndex = vk->queue_family_index,
};
@ -651,10 +630,8 @@ vk_init_validation_callback(struct vk_bundle *vk)
VkDebugReportCallbackCreateInfoEXT info = {
.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT,
.pNext = NULL,
.flags = flags,
.pfnCallback = _validation_cb,
.pUserData = NULL,
};
vk->vkCreateDebugReportCallbackEXT(vk->instance, &info, NULL,
@ -959,14 +936,10 @@ vk_create_device(struct vk_bundle *vk, int forced_index)
float queue_priority = 0.0f;
VkDeviceQueueCreateInfo queue_create_info = {
.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
.pNext = NULL,
.flags = 0,
.queueFamilyIndex = 0, // assigned valid value later
.queueCount = 1,
.pQueuePriorities = &queue_priority,
};
//! @todo why not vk->queue_family_index ?
ret = vk_find_graphics_queue(vk, &queue_create_info.queueFamilyIndex);
if (ret != VK_SUCCESS) {
return ret;
@ -987,12 +960,8 @@ vk_create_device(struct vk_bundle *vk, int forced_index)
VkDeviceCreateInfo device_create_info = {
.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
.pNext = NULL,
.flags = 0,
.queueCreateInfoCount = 1,
.pQueueCreateInfos = &queue_create_info,
.enabledLayerCount = 0,
.ppEnabledLayerNames = NULL,
.enabledExtensionCount = ARRAY_SIZE(device_extensions),
.ppEnabledExtensionNames = device_extensions,
.pEnabledFeatures = enabled_features,

View file

@ -414,11 +414,8 @@ create_instance(struct comp_compositor *c)
VkApplicationInfo app_info = {
.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
.pNext = NULL,
.pApplicationName = "Collabora Compositor",
.applicationVersion = 0,
.pEngineName = "Monado",
.engineVersion = 0,
.apiVersion = VK_MAKE_VERSION(1, 0, 2),
};
@ -432,11 +429,7 @@ create_instance(struct comp_compositor *c)
VkInstanceCreateInfo instance_info = {
.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
.pNext = NULL,
.flags = 0,
.pApplicationInfo = &app_info,
.enabledLayerCount = 0,
.ppEnabledLayerNames = NULL,
.enabledExtensionCount = num_extensions,
.ppEnabledExtensionNames = instance_extensions,
};
@ -555,10 +548,6 @@ compositor_check_vulkan_caps(struct comp_compositor *c)
VkInstanceCreateInfo instance_create_info = {
.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
.pNext = NULL,
.flags = 0,
.pApplicationInfo = NULL,
.enabledLayerCount = 0,
.ppEnabledLayerNames = NULL,
.enabledExtensionCount = ARRAY_SIZE(extension_names),
.ppEnabledExtensionNames = extension_names,
};

View file

@ -147,8 +147,6 @@ _shader_load(struct vk_bundle *vk,
VkShaderModuleCreateInfo info = {
.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
.pNext = NULL,
.flags = 0,
.codeSize = size,
.pCode = code,
};
@ -161,12 +159,9 @@ _shader_load(struct vk_bundle *vk,
return (VkPipelineShaderStageCreateInfo){
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
.pNext = NULL,
.flags = 0,
.stage = flags,
.module = module,
.pName = "main",
.pSpecializationInfo = NULL,
};
}
@ -265,101 +260,55 @@ comp_distortion_init_pipeline(struct comp_distortion *d,
VkPipelineInputAssemblyStateCreateInfo input_assembly_state = {
.sType =
VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
.pNext = NULL,
.flags = 0,
.topology = topology,
.primitiveRestartEnable = VK_FALSE,
};
VkPipelineRasterizationStateCreateInfo rasterization_state = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
.pNext = NULL,
.flags = 0,
.depthClampEnable = VK_FALSE,
.rasterizerDiscardEnable = VK_FALSE,
.polygonMode = polygonMode,
.cullMode = VK_CULL_MODE_BACK_BIT,
.frontFace = VK_FRONT_FACE_CLOCKWISE,
.depthBiasEnable = VK_FALSE,
.depthBiasConstantFactor = 0.f,
.depthBiasClamp = 0.f,
.depthBiasSlopeFactor = 0.f,
.lineWidth = 1.0f,
};
VkPipelineColorBlendAttachmentState blend_attachment_state = {0};
blend_attachment_state.blendEnable = VK_FALSE;
blend_attachment_state.colorWriteMask = 0xf;
VkPipelineColorBlendAttachmentState blend_attachment_state = {
.blendEnable = VK_FALSE,
.colorWriteMask = 0xf,
};
VkPipelineColorBlendStateCreateInfo color_blend_state = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,
.pNext = NULL,
.flags = 0,
.logicOpEnable = VK_FALSE,
.logicOp = VK_LOGIC_OP_CLEAR,
.attachmentCount = 1,
.pAttachments = &blend_attachment_state,
//! @todo what's the right value for blendConstants?
.blendConstants = {1.f, 1.f, 1.f, 1.f},
};
VkPipelineDepthStencilStateCreateInfo depth_stencil_state = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,
.pNext = NULL,
.flags = 0,
.depthTestEnable = VK_TRUE,
.depthWriteEnable = VK_TRUE,
.depthCompareOp = VK_COMPARE_OP_LESS_OR_EQUAL,
.depthBoundsTestEnable = VK_FALSE,
.stencilTestEnable = VK_FALSE,
.front =
{
.failOp = VK_STENCIL_OP_KEEP,
.passOp = VK_STENCIL_OP_KEEP,
.depthFailOp = VK_STENCIL_OP_KEEP,
.compareOp = VK_COMPARE_OP_ALWAYS, // this is the only
// meaningful value here.
.compareMask = 0,
.writeMask = 0,
.reference = 0,
.compareOp = VK_COMPARE_OP_ALWAYS,
},
.back =
{
.failOp = VK_STENCIL_OP_KEEP,
.passOp = VK_STENCIL_OP_KEEP,
.depthFailOp = VK_STENCIL_OP_KEEP,
.compareOp = VK_COMPARE_OP_ALWAYS, // this is the only
// meaningful value here.
.compareMask = 0,
.writeMask = 0,
.reference = 0,
.compareOp = VK_COMPARE_OP_ALWAYS,
},
.minDepthBounds = 0.f,
.maxDepthBounds = 0.f,
};
VkPipelineViewportStateCreateInfo viewport_state = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,
.pNext = NULL,
.flags = 0,
.viewportCount = 1,
.pViewports = NULL, // assigned valid value later
.scissorCount = 1,
.pScissors = NULL, // assigned valid value later
};
VkPipelineMultisampleStateCreateInfo multisample_state = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
.pNext = NULL,
.flags = 0,
.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT,
.sampleShadingEnable = VK_FALSE,
.minSampleShading = 0,
.pSampleMask = NULL,
.alphaToCoverageEnable = VK_FALSE,
.alphaToOneEnable = VK_FALSE,
};
.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT};
VkDynamicState dynamic_states[] = {
VK_DYNAMIC_STATE_VIEWPORT,
@ -368,8 +317,6 @@ comp_distortion_init_pipeline(struct comp_distortion *d,
VkPipelineDynamicStateCreateInfo dynamic_state = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,
.pNext = NULL,
.flags = 0,
.dynamicStateCount = 2,
.pDynamicStates = dynamic_states,
};
@ -388,12 +335,6 @@ comp_distortion_init_pipeline(struct comp_distortion *d,
*/
VkPipelineVertexInputStateCreateInfo vertex_input_state = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
.pNext = NULL,
.flags = 0,
.vertexBindingDescriptionCount = 0,
.pVertexBindingDescriptions = NULL,
.vertexAttributeDescriptionCount = 0,
.pVertexAttributeDescriptions = NULL,
};
const uint32_t *vertex_shader_code = shaders_distortion_vert;
size_t vertex_shader_size = sizeof(shaders_distortion_vert);
@ -451,17 +392,13 @@ comp_distortion_init_pipeline(struct comp_distortion *d,
VK_SHADER_STAGE_FRAGMENT_BIT),
};
VkGraphicsPipelineCreateInfo pipeline_info = {
.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
.pNext = NULL,
.flags = 0,
.stageCount = ARRAY_SIZE(shader_stages),
.pStages = shader_stages,
.pVertexInputState = &vertex_input_state,
.pInputAssemblyState = &input_assembly_state,
.pTessellationState = NULL,
.pViewportState = &viewport_state,
.pRasterizationState = &rasterization_state,
.pMultisampleState = &multisample_state,
@ -470,7 +407,6 @@ comp_distortion_init_pipeline(struct comp_distortion *d,
.pDynamicState = &dynamic_state,
.layout = d->pipeline_layout,
.renderPass = render_pass,
.subpass = 0, //! @todo
.basePipelineHandle = VK_NULL_HANDLE,
.basePipelineIndex = -1,
};
@ -492,15 +428,11 @@ comp_distortion_get_uniform_write_descriptor_set(struct comp_distortion *d,
{
return (VkWriteDescriptorSet){
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.pNext = NULL,
.dstSet = d->descriptor_sets[eye],
.dstBinding = binding,
.dstArrayElement = 0, //! @todo
.descriptorCount = 1,
.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.pImageInfo = NULL,
.pBufferInfo = &d->ubo_handle.descriptor,
.pTexelBufferView = NULL,
};
}
@ -511,15 +443,11 @@ comp_distortion_get_uniform_write_descriptor_set_vp(struct comp_distortion *d,
{
return (VkWriteDescriptorSet){
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.pNext = NULL,
.dstSet = d->descriptor_sets[eye],
.dstBinding = binding,
.dstArrayElement = 0, //! @todo
.descriptorCount = 1,
.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.pImageInfo = NULL,
.pBufferInfo = &d->ubo_viewport_handles[eye].descriptor,
.pTexelBufferView = NULL,
};
}
@ -531,15 +459,11 @@ comp_distortion_get_image_write_descriptor_set(
{
return (VkWriteDescriptorSet){
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.pNext = NULL,
.dstSet = descriptor_set,
.dstBinding = binding,
.dstArrayElement = 0, //! @todo
.descriptorCount = 1,
.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
.pImageInfo = descriptor_position,
.pBufferInfo = NULL,
.pTexelBufferView = NULL,
};
}
@ -552,7 +476,6 @@ comp_distortion_init_descriptor_sets(struct comp_distortion *d,
VkDescriptorSetAllocateInfo alloc_info = {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
.pNext = NULL,
.descriptorPool = descriptor_pool,
.descriptorSetCount = 1,
.pSetLayouts = &d->descriptor_set_layout,
@ -621,7 +544,6 @@ comp_distortion_init_descriptor_set_layout(struct comp_distortion *d)
.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
.descriptorCount = 1,
.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT,
.pImmutableSamplers = NULL,
},
// Binding 1 : Fragment shader uniform buffer
{
@ -629,7 +551,6 @@ comp_distortion_init_descriptor_set_layout(struct comp_distortion *d)
.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.descriptorCount = 1,
.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT,
.pImmutableSamplers = NULL,
},
// binding 2: viewport index
{
@ -637,14 +558,11 @@ comp_distortion_init_descriptor_set_layout(struct comp_distortion *d)
.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.descriptorCount = 1,
.stageFlags = VK_SHADER_STAGE_VERTEX_BIT,
.pImmutableSamplers = NULL,
},
};
VkDescriptorSetLayoutCreateInfo set_layout_info = {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
.pNext = NULL,
.flags = 0,
.bindingCount = ARRAY_SIZE(set_layout_bindings),
.pBindings = set_layout_bindings,
};
@ -664,12 +582,9 @@ comp_distortion_init_pipeline_layout(struct comp_distortion *d)
VkPipelineLayoutCreateInfo pipeline_layout_info = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
.pNext = NULL,
.flags = 0,
.setLayoutCount = 1,
.pSetLayouts = &d->descriptor_set_layout,
.pushConstantRangeCount = 0,
.pPushConstantRanges = NULL};
};
ret = vk->vkCreatePipelineLayout(d->vk->device, &pipeline_layout_info,
NULL, &d->pipeline_layout);
@ -811,13 +726,8 @@ _create_buffer(struct vk_bundle *vk,
// Create the buffer handle.
VkBufferCreateInfo buffer_info = {
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
.pNext = NULL,
.flags = 0,
.size = size,
.usage = usage_flags,
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
.queueFamilyIndexCount = 0,
.pQueueFamilyIndices = NULL,
};
ret =
vk->vkCreateBuffer(vk->device, &buffer_info, NULL, &buffer->buffer);
@ -838,7 +748,6 @@ _create_buffer(struct vk_bundle *vk,
VkMemoryAllocateInfo mem_alloc = {
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
.pNext = NULL,
.allocationSize = mem_reqs.size,
.memoryTypeIndex = memory_type_index,
};

View file

@ -70,7 +70,6 @@ get_device_memory_fd(struct comp_compositor *c,
// vkGetMemoryFdKHR parameter
VkMemoryGetFdInfoKHR fd_info = {
.sType = VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR,
.pNext = NULL,
.memory = device_memory,
.handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR,
};
@ -114,7 +113,6 @@ create_image_fd(struct comp_compositor *c,
VkExternalMemoryImageCreateInfoKHR external_memory_image_create_info = {
.sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO_KHR,
.pNext = NULL,
.handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR,
};
@ -140,7 +138,6 @@ create_image_fd(struct comp_compositor *c,
VkImageCreateInfo info = {
.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
.pNext = &external_memory_image_create_info,
.flags = 0,
.imageType = VK_IMAGE_TYPE_2D,
.format = (VkFormat)format,
.extent = {.width = width, .height = height, .depth = 1},
@ -150,8 +147,6 @@ create_image_fd(struct comp_compositor *c,
.tiling = VK_IMAGE_TILING_OPTIMAL,
.usage = image_usage,
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
.queueFamilyIndexCount = 0,
.pQueueFamilyIndices = NULL,
.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
};

View file

@ -154,8 +154,6 @@ vk_swapchain_create(struct vk_swapchain *sc,
VkSwapchainCreateInfoKHR swap_chain_info = {
.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR,
.pNext = NULL,
.flags = 0,
.surface = sc->surface,
.minImageCount = surface_caps.minImageCount,
.imageFormat = sc->surface_format.format,
@ -169,7 +167,6 @@ vk_swapchain_create(struct vk_swapchain *sc,
.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE,
.queueFamilyIndexCount = 0,
.pQueueFamilyIndices = NULL,
.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR,
.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR,
.presentMode = sc->present_mode,
@ -249,13 +246,11 @@ vk_swapchain_present(struct vk_swapchain *sc,
{
VkPresentInfoKHR presentInfo = {
.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR,
.pNext = NULL,
.waitSemaphoreCount = 1,
.pWaitSemaphores = &semaphore,
.swapchainCount = 1,
.pSwapchains = &sc->swap_chain,
.pImageIndices = &index,
.pResults = NULL,
};
return sc->vk->vkQueuePresentKHR(queue, &presentInfo);