Skip to content

Commit d251a74

Browse files
MajorPainTheCactusLibretroAdmin
authored andcommitted
Vulkan: fix menu brightness overriding game brightness in HDR
The game and menu composite HDR pipeline calls shared a single persistently-mapped UBO buffer. Since both draws are recorded into one command buffer before GPU submission, the menu composite write overwrote the game content's BrightnessNits before the GPU executed either draw — causing menu brightness changes to affect game content. Add a separate ubo_menu buffer for the menu composite draw so each pipeline call writes to independent GPU memory. D3D11/D3D12 are unaffected: MAP_WRITE_DISCARD allocates new backing memory per Map call, so each draw naturally sees its own UBO data.
1 parent 4d9e2eb commit d251a74

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

gfx/drivers/vulkan.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ typedef struct vk
252252
{
253253
vulkan_hdr_uniform_t ubo_values;
254254
struct vk_buffer ubo;
255+
struct vk_buffer ubo_menu;
255256
float menu_nits;
256257
float max_output_nits;
257258
float min_output_nits;
@@ -3536,6 +3537,7 @@ static void vulkan_free(void *data)
35363537
if (vk->context->flags & VK_CTX_FLAG_HDR_SUPPORT)
35373538
{
35383539
vulkan_destroy_buffer(vk->context->device, &vk->hdr.ubo);
3540+
vulkan_destroy_buffer(vk->context->device, &vk->hdr.ubo_menu);
35393541
vulkan_destroy_hdr_buffer(vk->context->device, &vk->offscreen_buffer);
35403542
vulkan_destroy_hdr_buffer(vk->context->device, &vk->readback_image);
35413543
vulkan_deinit_hdr_readback_render_pass(vk);
@@ -3874,6 +3876,7 @@ static void *vulkan_init(const video_info_t *video,
38743876

38753877
#ifdef VULKAN_HDR_SWAPCHAIN
38763878
vk->hdr.ubo = vulkan_create_buffer(vk->context, sizeof(vulkan_hdr_uniform_t), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
3879+
vk->hdr.ubo_menu = vulkan_create_buffer(vk->context, sizeof(vulkan_hdr_uniform_t), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
38773880

38783881
vk->hdr.ubo_values.mvp = vk->mvp_no_rot;
38793882
vk->hdr.menu_nits = settings->floats.video_hdr_menu_nits;
@@ -5456,7 +5459,7 @@ static bool vulkan_frame(void *data, const void *frame,
54565459
{
54575460
/* Menu/overlay composite: source is always SDR (B8G8R8A8_UNORM) */
54585461
unsigned composite_hdr_mode = (vk->context->flags & VK_CTX_FLAG_HDR_SCRGB) ? 2 : 1;
5459-
vulkan_run_hdr_pipeline(vk->pipelines.hdr, vk->keep_render_pass, &vk->offscreen_buffer, backbuffer, vk, &vk->hdr.ubo, composite_hdr_mode, true);
5462+
vulkan_run_hdr_pipeline(vk->pipelines.hdr, vk->keep_render_pass, &vk->offscreen_buffer, backbuffer, vk, &vk->hdr.ubo_menu, composite_hdr_mode, true);
54605463
}
54615464
}
54625465
#endif /* VULKAN_HDR_SWAPCHAIN */

0 commit comments

Comments
 (0)