render/vulkan: remove hardcoded counts

Use the array size instead.
This commit is contained in:
Simon Ser 2025-08-16 11:53:12 +02:00 committed by Simon Zeni
parent 1a18e47efa
commit e95117b700
2 changed files with 29 additions and 29 deletions

View file

@ -771,13 +771,13 @@ bool vulkan_setup_plain_framebuffer(struct wlr_vk_render_buffer *buffer,
}; };
vkUpdateDescriptorSets(dev, 1, &ds_write, 0, NULL); vkUpdateDescriptorSets(dev, 1, &ds_write, 0, NULL);
VkImageView attachments[2] = { VkImageView attachments[] = {
buffer->plain.blend_image_view, buffer->plain.blend_image_view,
buffer->plain.image_view buffer->plain.image_view
}; };
VkFramebufferCreateInfo fb_info = { VkFramebufferCreateInfo fb_info = {
.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
.attachmentCount = 2, .attachmentCount = sizeof(attachments) / sizeof(attachments[0]),
.pAttachments = attachments, .pAttachments = attachments,
.flags = 0u, .flags = 0u,
.width = dmabuf->width, .width = dmabuf->width,
@ -1466,7 +1466,7 @@ static bool init_tex_layouts(struct wlr_vk_renderer *renderer,
return false; return false;
} }
VkPushConstantRange pc_ranges[2] = { VkPushConstantRange pc_ranges[] = {
{ {
.size = sizeof(struct wlr_vk_vert_pcr_data), .size = sizeof(struct wlr_vk_vert_pcr_data),
.stageFlags = VK_SHADER_STAGE_VERTEX_BIT, .stageFlags = VK_SHADER_STAGE_VERTEX_BIT,
@ -1482,7 +1482,7 @@ static bool init_tex_layouts(struct wlr_vk_renderer *renderer,
.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
.setLayoutCount = 1, .setLayoutCount = 1,
.pSetLayouts = out_ds_layout, .pSetLayouts = out_ds_layout,
.pushConstantRangeCount = 2, .pushConstantRangeCount = sizeof(pc_ranges) / sizeof(pc_ranges[0]),
.pPushConstantRanges = pc_ranges, .pPushConstantRanges = pc_ranges,
}; };
@ -1560,7 +1560,7 @@ static bool init_blend_to_output_layouts(struct wlr_vk_renderer *renderer) {
} }
// pipeline layout -- standard vertex uniforms, no shader uniforms // pipeline layout -- standard vertex uniforms, no shader uniforms
VkPushConstantRange pc_ranges[2] = { VkPushConstantRange pc_ranges[] = {
{ {
.offset = 0, .offset = 0,
.size = sizeof(struct wlr_vk_vert_pcr_data), .size = sizeof(struct wlr_vk_vert_pcr_data),
@ -1573,16 +1573,16 @@ static bool init_blend_to_output_layouts(struct wlr_vk_renderer *renderer) {
}, },
}; };
VkDescriptorSetLayout out_ds_layouts[2] = { VkDescriptorSetLayout out_ds_layouts[] = {
renderer->output_ds_srgb_layout, renderer->output_ds_srgb_layout,
renderer->output_ds_lut3d_layout, renderer->output_ds_lut3d_layout,
}; };
VkPipelineLayoutCreateInfo pl_info = { VkPipelineLayoutCreateInfo pl_info = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
.setLayoutCount = 2, .setLayoutCount = sizeof(out_ds_layouts) / sizeof(out_ds_layouts[0]),
.pSetLayouts = out_ds_layouts, .pSetLayouts = out_ds_layouts,
.pushConstantRangeCount = 2, .pushConstantRangeCount = sizeof(pc_ranges) / sizeof(pc_ranges[0]),
.pPushConstantRanges = pc_ranges, .pPushConstantRanges = pc_ranges,
}; };
@ -1755,14 +1755,14 @@ struct wlr_vk_pipeline *setup_get_or_create_pipeline(
.scissorCount = 1, .scissorCount = 1,
}; };
VkDynamicState dynStates[2] = { VkDynamicState dyn_states[] = {
VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_VIEWPORT,
VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_SCISSOR,
}; };
VkPipelineDynamicStateCreateInfo dynamic = { VkPipelineDynamicStateCreateInfo dynamic = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,
.pDynamicStates = dynStates, .pDynamicStates = dyn_states,
.dynamicStateCount = 2, .dynamicStateCount = sizeof(dyn_states) / sizeof(dyn_states[0]),
}; };
VkPipelineVertexInputStateCreateInfo vertex = { VkPipelineVertexInputStateCreateInfo vertex = {
@ -1774,7 +1774,7 @@ struct wlr_vk_pipeline *setup_get_or_create_pipeline(
.layout = pipeline_layout->vk, .layout = pipeline_layout->vk,
.renderPass = setup->render_pass, .renderPass = setup->render_pass,
.subpass = 0, .subpass = 0,
.stageCount = 2, .stageCount = sizeof(stages) / sizeof(stages[0]),
.pStages = stages, .pStages = stages,
.pInputAssemblyState = &assembly, .pInputAssemblyState = &assembly,
@ -1817,7 +1817,7 @@ static bool init_blend_to_output_pipeline(struct wlr_vk_renderer *renderer,
.pData = &output_transform_type, .pData = &output_transform_type,
}; };
VkPipelineShaderStageCreateInfo tex_stages[2] = { VkPipelineShaderStageCreateInfo tex_stages[] = {
{ {
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
.stage = VK_SHADER_STAGE_VERTEX_BIT, .stage = VK_SHADER_STAGE_VERTEX_BIT,
@ -1872,14 +1872,14 @@ static bool init_blend_to_output_pipeline(struct wlr_vk_renderer *renderer,
.scissorCount = 1, .scissorCount = 1,
}; };
VkDynamicState dynStates[2] = { VkDynamicState dyn_states[] = {
VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_VIEWPORT,
VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_SCISSOR,
}; };
VkPipelineDynamicStateCreateInfo dynamic = { VkPipelineDynamicStateCreateInfo dynamic = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,
.pDynamicStates = dynStates, .pDynamicStates = dyn_states,
.dynamicStateCount = 2, .dynamicStateCount = sizeof(dyn_states) / sizeof(dyn_states[0]),
}; };
VkPipelineVertexInputStateCreateInfo vertex = { VkPipelineVertexInputStateCreateInfo vertex = {
@ -1892,7 +1892,7 @@ static bool init_blend_to_output_pipeline(struct wlr_vk_renderer *renderer,
.layout = pipe_layout, .layout = pipe_layout,
.renderPass = rp, .renderPass = rp,
.subpass = 1, // second subpass! .subpass = 1, // second subpass!
.stageCount = 2, .stageCount = sizeof(tex_stages) / sizeof(tex_stages[0]),
.pStages = tex_stages, .pStages = tex_stages,
.pInputAssemblyState = &assembly, .pInputAssemblyState = &assembly,
.pRasterizationState = &rasterization, .pRasterizationState = &rasterization,
@ -2185,7 +2185,7 @@ static struct wlr_vk_render_format_setup *find_or_create_render_setup(
VkResult res; VkResult res;
if (use_blending_buffer) { if (use_blending_buffer) {
VkAttachmentDescription attachments[2] = { VkAttachmentDescription attachments[] = {
{ {
.format = VK_FORMAT_R16G16B16A16_SFLOAT, .format = VK_FORMAT_R16G16B16A16_SFLOAT,
.samples = VK_SAMPLE_COUNT_1_BIT, .samples = VK_SAMPLE_COUNT_1_BIT,
@ -2223,7 +2223,7 @@ static struct wlr_vk_render_format_setup *find_or_create_render_setup(
.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, .layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
}; };
VkSubpassDescription subpasses[2] = { VkSubpassDescription subpasses[] = {
{ {
.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS, .pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS,
.colorAttachmentCount = 1, .colorAttachmentCount = 1,
@ -2238,7 +2238,7 @@ static struct wlr_vk_render_format_setup *find_or_create_render_setup(
} }
}; };
VkSubpassDependency deps[3] = { VkSubpassDependency deps[] = {
{ {
.srcSubpass = VK_SUBPASS_EXTERNAL, .srcSubpass = VK_SUBPASS_EXTERNAL,
.srcStageMask = VK_PIPELINE_STAGE_HOST_BIT | .srcStageMask = VK_PIPELINE_STAGE_HOST_BIT |
@ -2280,11 +2280,11 @@ static struct wlr_vk_render_format_setup *find_or_create_render_setup(
.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
.pNext = NULL, .pNext = NULL,
.flags = 0, .flags = 0,
.attachmentCount = 2u, .attachmentCount = sizeof(attachments) / sizeof(attachments[0]),
.pAttachments = attachments, .pAttachments = attachments,
.subpassCount = 2u, .subpassCount = sizeof(subpasses) / sizeof(subpasses[0]),
.pSubpasses = subpasses, .pSubpasses = subpasses,
.dependencyCount = 3u, .dependencyCount = sizeof(deps) / sizeof(deps[0]),
.pDependencies = deps, .pDependencies = deps,
}; };
@ -2339,7 +2339,7 @@ static struct wlr_vk_render_format_setup *find_or_create_render_setup(
.pColorAttachments = &color_ref, .pColorAttachments = &color_ref,
}; };
VkSubpassDependency deps[2] = { VkSubpassDependency deps[] = {
{ {
.srcSubpass = VK_SUBPASS_EXTERNAL, .srcSubpass = VK_SUBPASS_EXTERNAL,
.srcStageMask = VK_PIPELINE_STAGE_HOST_BIT | .srcStageMask = VK_PIPELINE_STAGE_HOST_BIT |
@ -2374,7 +2374,7 @@ static struct wlr_vk_render_format_setup *find_or_create_render_setup(
.pAttachments = &attachment, .pAttachments = &attachment,
.subpassCount = 1, .subpassCount = 1,
.pSubpasses = &subpass, .pSubpasses = &subpass,
.dependencyCount = 2u, .dependencyCount = sizeof(deps) / sizeof(deps[0]),
.pDependencies = deps, .pDependencies = deps,
}; };

View file

@ -399,14 +399,14 @@ static struct wlr_texture *vulkan_texture_from_pixels(
texture_set_format(texture, &fmt->format, fmt->shm.has_mutable_srgb); texture_set_format(texture, &fmt->format, fmt->shm.has_mutable_srgb);
VkFormat view_formats[2] = { VkFormat view_formats[] = {
fmt->format.vk, fmt->format.vk,
fmt->format.vk_srgb, fmt->format.vk_srgb,
}; };
VkImageFormatListCreateInfoKHR list_info = { VkImageFormatListCreateInfoKHR list_info = {
.sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO_KHR, .sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO_KHR,
.pViewFormats = view_formats, .pViewFormats = view_formats,
.viewFormatCount = 2, .viewFormatCount = sizeof(view_formats) / sizeof(view_formats[0]),
}; };
VkImageCreateInfo img_info = { VkImageCreateInfo img_info = {
.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
@ -600,14 +600,14 @@ VkImage vulkan_import_dmabuf(struct wlr_vk_renderer *renderer,
}; };
eimg.pNext = &mod_info; eimg.pNext = &mod_info;
VkFormat view_formats[2] = { VkFormat view_formats[] = {
fmt->format.vk, fmt->format.vk,
fmt->format.vk_srgb, fmt->format.vk_srgb,
}; };
VkImageFormatListCreateInfoKHR list_info = { VkImageFormatListCreateInfoKHR list_info = {
.sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO_KHR, .sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO_KHR,
.pViewFormats = view_formats, .pViewFormats = view_formats,
.viewFormatCount = 2, .viewFormatCount = sizeof(view_formats) / sizeof(view_formats[0]),
}; };
if (mod->has_mutable_srgb) { if (mod->has_mutable_srgb) {
mod_info.pNext = &list_info; mod_info.pNext = &list_info;