Skip to content

Commit 98344cf

Browse files
Vulkan: Fix HDR pipeline blend factors and quad vertex buffer handling
Set explicit blend factors (src=ONE, dst=ONE_MINUS_SRC_ALPHA) on the HDR pipeline blend attachment for correct alpha compositing. Refactor vulkan_run_hdr_pipeline to check the return value of vulkan_buffer_chain_alloc before writing vertices, replace the VULKAN_WRITE_QUAD_VBO macro with explicit vertex definitions for clarity, and move vkCmdBindVertexBuffers/vkCmdDraw inside the allocation success block to avoid drawing with invalid buffers.
1 parent bed2dc3 commit 98344cf

1 file changed

Lines changed: 29 additions & 15 deletions

File tree

gfx/drivers/vulkan.c

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2668,6 +2668,8 @@ if (vk->context->flags & VK_CTX_FLAG_HDR_SUPPORT)
26682668
/* HDR pipeline. */
26692669
blend_attachment.blendEnable = VK_TRUE;
26702670

2671+
blend_attachment.srcColorBlendFactor = VK_BLEND_FACTOR_ONE;
2672+
blend_attachment.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
26712673

26722674
/* HDR pipeline. */
26732675
module_info.codeSize = sizeof(hdr_frag);
@@ -4695,26 +4697,38 @@ static void vulkan_run_hdr_pipeline(VkPipeline pipeline, VkRenderPass render_pas
46954697
{
46964698
struct vk_buffer_range range;
46974699

4698-
vulkan_buffer_chain_alloc(vk->context, &vk->chain->vbo, 6 * sizeof(struct vk_vertex), &range);
4699-
4700+
if (vulkan_buffer_chain_alloc(vk->context, &vk->chain->vbo, 6 * sizeof(struct vk_vertex), &range))
47004701
{
4701-
struct vk_vertex *pv = (struct vk_vertex*)range.data;
4702-
struct vk_color color;
4703-
4704-
color.r = 1.0f;
4705-
color.g = 1.0f;
4706-
color.b = 1.0f;
4707-
color.a = 1.0f;
4702+
struct vk_vertex *pv = (struct vk_vertex*)range.data;
4703+
int i;
4704+
4705+
/* Explicitly define the quad vertices to avoid macro issues.
4706+
Triangle 1: TL, BL, TR
4707+
Triangle 2: TR, BL, BR */
4708+
4709+
pv[0].x = 0.0f; pv[0].y = 0.0f; pv[0].tex_x = 0.0f; pv[0].tex_y = 0.0f;
4710+
pv[1].x = 0.0f; pv[1].y = 1.0f; pv[1].tex_x = 0.0f; pv[1].tex_y = 1.0f;
4711+
pv[2].x = 1.0f; pv[2].y = 0.0f; pv[2].tex_x = 1.0f; pv[2].tex_y = 0.0f;
4712+
4713+
pv[3].x = 1.0f; pv[3].y = 0.0f; pv[3].tex_x = 1.0f; pv[3].tex_y = 0.0f;
4714+
pv[4].x = 0.0f; pv[4].y = 1.0f; pv[4].tex_x = 0.0f; pv[4].tex_y = 1.0f;
4715+
pv[5].x = 1.0f; pv[5].y = 1.0f; pv[5].tex_x = 1.0f; pv[5].tex_y = 1.0f;
4716+
4717+
for (i = 0; i < 6; i++)
4718+
{
4719+
pv[i].color.r = 1.0f;
4720+
pv[i].color.g = 1.0f;
4721+
pv[i].color.b = 1.0f;
4722+
pv[i].color.a = 1.0f;
4723+
}
47084724

4709-
VULKAN_WRITE_QUAD_VBO(pv, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, &color);
4725+
vkCmdBindVertexBuffers(vk->cmd, 0, 1,
4726+
&range.buffer, &range.offset);
4727+
4728+
vkCmdDraw(vk->cmd, 6, 1, 0, 0);
47104729
}
4711-
4712-
vkCmdBindVertexBuffers(vk->cmd, 0, 1,
4713-
&range.buffer, &range.offset);
47144730
}
47154731

4716-
vkCmdDraw(vk->cmd, 6, 1, 0, 0);
4717-
47184732
vkCmdEndRenderPass(vk->cmd);
47194733

47204734
vk->hdr.ubo_values.inverse_tonemap = prev_inverse_tonemap;

0 commit comments

Comments
 (0)