Skip to content

Commit 07d0569

Browse files
committed
vulkan: minor hdr fix
1 parent 7184a1c commit 07d0569

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

gfx/common/vulkan_common.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ enum vk_flags
238238
VK_FLAG_READBACK_PENDING = (1 << 12),
239239
VK_FLAG_READBACK_STREAMED = (1 << 13),
240240
VK_FLAG_OVERLAY_ENABLE = (1 << 14),
241-
VK_FLAG_OVERLAY_FULLSCREEN = (1 << 15)
241+
VK_FLAG_OVERLAY_FULLSCREEN = (1 << 15),
242+
VK_FLAG_SDR_OFFSCREEN = (1 << 16) /* Rendering to SDR offscreen buffer */
242243
};
243244

244245

gfx/drivers/vulkan.c

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,10 +1484,18 @@ static void gfx_display_vk_draw(gfx_display_ctx_draw_t *draw,
14841484
default:
14851485
{
14861486
struct vk_draw_triangles call;
1487-
unsigned
1488-
disp_pipeline =
1489-
((draw->prim_type == GFX_DISPLAY_PRIM_TRIANGLESTRIP) << 1)
1490-
| (((vk->flags & VK_FLAG_DISPLAY_BLEND) > 0) << 0);
1487+
unsigned disp_pipeline;
1488+
#ifdef VULKAN_HDR_SWAPCHAIN
1489+
/* Use HDR pipeline when HDR is enabled, but not when rendering
1490+
* to the SDR offscreen buffer for menu/overlay compositing */
1491+
if ((vk->context->flags & VK_CTX_FLAG_HDR_ENABLE) &&
1492+
!(vk->flags & VK_FLAG_SDR_OFFSCREEN))
1493+
disp_pipeline = 4; /* HDR display pipeline */
1494+
else
1495+
#endif
1496+
disp_pipeline =
1497+
((draw->prim_type == GFX_DISPLAY_PRIM_TRIANGLESTRIP) << 1)
1498+
| (((vk->flags & VK_FLAG_DISPLAY_BLEND) > 0) << 0);
14911499
call.pipeline = vk->display.pipelines[disp_pipeline];
14921500
call.texture = texture;
14931501
call.sampler = (texture->flags & VK_TEX_FLAG_MIPMAP)
@@ -5160,12 +5168,14 @@ static bool vulkan_frame(void *data, const void *frame,
51605168
}
51615169

51625170
if ((vk->context->flags & VK_CTX_FLAG_HDR_ENABLE) &&
5163-
((vk->flags & VK_FLAG_MENU_ENABLE) || (vk->flags & VK_FLAG_OVERLAY_ENABLE)) &&
5171+
((vk->flags & VK_FLAG_MENU_ENABLE) || (vk->flags & VK_FLAG_OVERLAY_ENABLE)
5172+
|| !string_is_empty(msg) || widgets_active) &&
51645173
(vk->offscreen_buffer.image != VK_NULL_HANDLE))
51655174
{
51665175
if(end_pass) vkCmdEndRenderPass(vk->cmd);
51675176

51685177
backbuffer = &vk->offscreen_buffer;
5178+
vk->flags |= VK_FLAG_SDR_OFFSCREEN;
51695179

51705180
rp_info.renderPass = vk->sdr_render_pass;
51715181
rp_info.framebuffer = backbuffer->framebuffer;
@@ -5256,7 +5266,8 @@ static bool vulkan_frame(void *data, const void *frame,
52565266
#ifdef VULKAN_HDR_SWAPCHAIN
52575267
/* Copy over back buffer to swap chain render targets */
52585268
if ((vk->context->flags & VK_CTX_FLAG_HDR_ENABLE) &&
5259-
((vk->flags & VK_FLAG_MENU_ENABLE) || (vk->flags & VK_FLAG_OVERLAY_ENABLE)) &&
5269+
((vk->flags & VK_FLAG_MENU_ENABLE) || (vk->flags & VK_FLAG_OVERLAY_ENABLE)
5270+
|| !string_is_empty(msg) || widgets_active) &&
52605271
(vk->offscreen_buffer.image != VK_NULL_HANDLE))
52615272
{
52625273
backbuffer = &vk->backbuffers[swapchain_index];
@@ -5276,6 +5287,7 @@ static bool vulkan_frame(void *data, const void *frame,
52765287
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
52775288

52785289
vulkan_run_hdr_pipeline(vk->pipelines.hdr, vk->keep_render_pass, &vk->offscreen_buffer, backbuffer, vk, &vk->hdr.ubo);
5290+
vk->flags &= ~VK_FLAG_SDR_OFFSCREEN;
52795291
}
52805292
#endif /* VULKAN_HDR_SWAPCHAIN */
52815293
}
@@ -6273,7 +6285,16 @@ static void vulkan_render_overlay(vk_t *vk, unsigned width,
62736285
call.uniform = &vk->mvp;
62746286
call.vbo = &range;
62756287
call.texture = &vk->overlay.images[i];
6276-
call.pipeline = vk->display.pipelines[3]; /* Strip with blend */
6288+
#ifdef VULKAN_HDR_SWAPCHAIN
6289+
/* Use HDR pipeline when HDR is enabled, but not when rendering
6290+
* to the SDR offscreen buffer for menu/overlay compositing */
6291+
if ((vk->context->flags & VK_CTX_FLAG_HDR_ENABLE) &&
6292+
!(vk->flags & VK_FLAG_SDR_OFFSCREEN))
6293+
call.pipeline = vk->display.pipelines[4];
6294+
else
6295+
#else
6296+
call.pipeline = vk->display.pipelines[3]; /* Strip with blend */
6297+
#endif
62776298
call.sampler = (call.texture->flags & VK_TEX_FLAG_MIPMAP)
62786299
? vk->samplers.mipmap_linear : vk->samplers.linear;
62796300
vulkan_draw_triangles(vk, &call);

0 commit comments

Comments
 (0)