Skip to content

Commit 9efc73f

Browse files
committed
VULKAN: Fix shader module lifetime bugs in SDR pipeline creation
Fixes startup crash on Windows Vulkan introduced by 8fa8418. Two bugs in the SDR pipeline creation path when HDR is supported: 1. SDR display pipelines 0-3 were created after the alpha_blend fragment shader module had already been destroyed. The alpha_blend_sdr pipeline was created, then the fragment shader module was immediately destroyed (line 3692 in the original patch). The subsequent display pipeline loop (pipelines_sdr[0..3]) still referenced that destroyed module through the pipe struct, producing an invalid VkShaderModule handle passed to vkCreateGraphicsPipelines. Fix: keep both the vertex and fragment shader modules alive through the display 0-3 loop, then destroy both afterward. 2. After the SDR menu shader loop (pipelines_sdr[6+]), an extra vkDestroyShaderModule call destroyed shader_stages[0].module which had already been destroyed in the loop's last iteration at line 3782. Double-free on a VkShaderModule handle. Fix: remove the spurious destroy after the loop. Both bugs only manifest when VK_CTX_FLAG_HDR_SUPPORT is set (Windows with HDR-capable displays, or any platform where the Vulkan driver reports HDR swapchain support). Non-HDR paths are unaffected because the entire SDR pipeline block is guarded by the HDR support check.
1 parent 8fa8418 commit 9efc73f

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

gfx/drivers/vulkan.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3689,9 +3689,11 @@ static void vulkan_init_pipelines(vk_t *vk)
36893689

36903690
vkCreateGraphicsPipelines(vk->context->device, vk->pipelines.cache,
36913691
1, &pipe, NULL, &vk->pipelines.alpha_blend_sdr);
3692-
vkDestroyShaderModule(vk->context->device, shader_stages[1].module, NULL);
36933692

3694-
/* SDR display pipelines 0-3 */
3693+
/* SDR display pipelines 0-3.
3694+
* Reuse the alpha_blend vertex shader (stages[0]) and
3695+
* alpha_blend fragment shader (stages[1]) still alive
3696+
* from just above. */
36953697
for (i = 0; i < 4; i++)
36963698
{
36973699
input_assembly.topology = i & 2 ?
@@ -3702,6 +3704,10 @@ static void vulkan_init_pipelines(vk_t *vk)
37023704
1, &pipe, NULL, &vk->display.pipelines_sdr[i]);
37033705
}
37043706

3707+
/* Done with the alpha_blend shader modules. */
3708+
vkDestroyShaderModule(vk->context->device, shader_stages[0].module, NULL);
3709+
vkDestroyShaderModule(vk->context->device, shader_stages[1].module, NULL);
3710+
37053711
/* SDR menu shader pipelines 6+ */
37063712
for (i = 0; i < (int)ARRAY_SIZE(vk->display.pipelines) - 6; i++)
37073713
{
@@ -3782,8 +3788,6 @@ static void vulkan_init_pipelines(vk_t *vk)
37823788
vkDestroyShaderModule(vk->context->device, shader_stages[0].module, NULL);
37833789
vkDestroyShaderModule(vk->context->device, shader_stages[1].module, NULL);
37843790
}
3785-
3786-
vkDestroyShaderModule(vk->context->device, shader_stages[0].module, NULL);
37873791
}
37883792
#endif /* VULKAN_HDR_SWAPCHAIN */
37893793

0 commit comments

Comments
 (0)