From 351447a3f5bc22c4589af727951a9624329c2b94 Mon Sep 17 00:00:00 2001 From: Niklas Haas Date: Fri, 28 Apr 2023 13:34:49 +0200 Subject: [PATCH] vulkan: add support for VK_KHR_synchronization2 Specifically, support loading this as extension instead of requiring the promoted symbols from Vulkan v1.3. --- src/vulkan/command.c | 2 +- src/vulkan/common.h | 4 ++-- src/vulkan/context.c | 12 +++++++++--- src/vulkan/gpu_buf.c | 4 ++-- src/vulkan/gpu_tex.c | 2 +- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/vulkan/command.c b/src/vulkan/command.c index dc8aae40..0503b813 100644 --- a/src/vulkan/command.c +++ b/src/vulkan/command.c @@ -353,7 +353,7 @@ bool vk_cmd_submit(struct vk_ctx *vk, struct vk_cmd **pcmd) } vk->lock_queue(vk->queue_ctx, pool->qf, cmd->qindex); - VkResult res = vk->QueueSubmit2(cmd->queue, 1, &sinfo, VK_NULL_HANDLE); + VkResult res = vk->QueueSubmit2KHR(cmd->queue, 1, &sinfo, VK_NULL_HANDLE); vk->unlock_queue(vk->queue_ctx, pool->qf, cmd->qindex); PL_VK_ASSERT(res, "vkQueueSubmit2"); diff --git a/src/vulkan/common.h b/src/vulkan/common.h index d200312e..32655104 100644 --- a/src/vulkan/common.h +++ b/src/vulkan/common.h @@ -139,7 +139,7 @@ struct vk_ctx { PL_VK_FUN(CmdDrawIndexed); PL_VK_FUN(CmdEndDebugUtilsLabelEXT); PL_VK_FUN(CmdEndRendering); - PL_VK_FUN(CmdPipelineBarrier2); + PL_VK_FUN(CmdPipelineBarrier2KHR); PL_VK_FUN(CmdPushConstants); PL_VK_FUN(CmdPushDescriptorSetKHR); PL_VK_FUN(CmdResetQueryPool); @@ -204,7 +204,7 @@ struct vk_ctx { PL_VK_FUN(InvalidateMappedMemoryRanges); PL_VK_FUN(MapMemory); PL_VK_FUN(QueuePresentKHR); - PL_VK_FUN(QueueSubmit2); + PL_VK_FUN(QueueSubmit2KHR); PL_VK_FUN(QueueWaitIdle); PL_VK_FUN(ResetFences); PL_VK_FUN(ResetQueryPool); diff --git a/src/vulkan/context.c b/src/vulkan/context.c index 6efdb758..02c76add 100644 --- a/src/vulkan/context.c +++ b/src/vulkan/context.c @@ -180,7 +180,14 @@ static const struct vk_ext vk_device_extensions[] = { {0} }, #endif - }, + }, { + .name = VK_KHR_SYNCHRONIZATION_2_EXTENSION_NAME, + .funs = (const struct vk_fun[]) { + PL_VK_DEV_FUN(CmdPipelineBarrier2KHR), + PL_VK_DEV_FUN(QueueSubmit2KHR), + {0} + }, + } }; // Make sure to keep this in sync with the above! @@ -206,6 +213,7 @@ const char * const pl_vulkan_recommended_extensions[] = { #ifdef VK_EXT_full_screen_exclusive VK_EXT_FULL_SCREEN_EXCLUSIVE_EXTENSION_NAME, #endif + VK_KHR_SYNCHRONIZATION_2_EXTENSION_NAME, }; const int pl_vulkan_num_recommended_extensions = @@ -313,7 +321,6 @@ static const struct vk_fun vk_dev_funs[] = { PL_VK_DEV_FUN(CmdDrawIndexed), PL_VK_DEV_FUN(CmdEndDebugUtilsLabelEXT), PL_VK_DEV_FUN(CmdEndRendering), - PL_VK_DEV_FUN(CmdPipelineBarrier2), PL_VK_DEV_FUN(CmdPushConstants), PL_VK_DEV_FUN(CmdResetQueryPool), PL_VK_DEV_FUN(CmdSetScissor), @@ -366,7 +373,6 @@ static const struct vk_fun vk_dev_funs[] = { PL_VK_DEV_FUN(GetQueryPoolResults), PL_VK_DEV_FUN(InvalidateMappedMemoryRanges), PL_VK_DEV_FUN(MapMemory), - PL_VK_DEV_FUN(QueueSubmit2), PL_VK_DEV_FUN(QueueWaitIdle), PL_VK_DEV_FUN(ResetFences), PL_VK_DEV_FUN(ResetQueryPool), diff --git a/src/vulkan/gpu_buf.c b/src/vulkan/gpu_buf.c index 8b8985a7..ac2e00a9 100644 --- a/src/vulkan/gpu_buf.c +++ b/src/vulkan/gpu_buf.c @@ -53,7 +53,7 @@ void vk_buf_barrier(pl_gpu gpu, struct vk_cmd *cmd, pl_buf buf, uint32_t dst_qf = export ? VK_QUEUE_FAMILY_EXTERNAL_KHR : qf; if (last.access || src_qf != dst_qf) { - vk->CmdPipelineBarrier2(cmd->buf, &(VkDependencyInfo) { + vk->CmdPipelineBarrier2KHR(cmd->buf, &(VkDependencyInfo) { .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO, .bufferMemoryBarrierCount = 1, .pBufferMemoryBarriers = &(VkBufferMemoryBarrier2) { @@ -288,7 +288,7 @@ void vk_buf_flush(pl_gpu gpu, struct vk_cmd *cmd, pl_buf buf, if (!can_read && !can_write) return; - vk->CmdPipelineBarrier2(cmd->buf, &(VkDependencyInfo) { + vk->CmdPipelineBarrier2KHR(cmd->buf, &(VkDependencyInfo) { .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO, .bufferMemoryBarrierCount = 1, .pBufferMemoryBarriers = &(VkBufferMemoryBarrier2) { diff --git a/src/vulkan/gpu_tex.c b/src/vulkan/gpu_tex.c index cd8e80f8..b52f4c8d 100644 --- a/src/vulkan/gpu_tex.c +++ b/src/vulkan/gpu_tex.c @@ -65,7 +65,7 @@ void vk_tex_barrier(pl_gpu gpu, struct vk_cmd *cmd, pl_tex tex, } if (last.access || is_trans || is_xfer) { - vk->CmdPipelineBarrier2(cmd->buf, &(VkDependencyInfo) { + vk->CmdPipelineBarrier2KHR(cmd->buf, &(VkDependencyInfo) { .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO, .imageMemoryBarrierCount = 1, .pImageMemoryBarriers = &barr,