Skip to content

Commit

Permalink
vulkan: add support for VK_KHR_synchronization2
Browse files Browse the repository at this point in the history
Specifically, support loading this as extension instead of requiring the
promoted symbols from Vulkan v1.3.
  • Loading branch information
haasn committed Apr 28, 2023
1 parent 369b1fb commit 351447a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/vulkan/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
4 changes: 2 additions & 2 deletions src/vulkan/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 9 additions & 3 deletions src/vulkan/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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 =
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions src/vulkan/gpu_buf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/vulkan/gpu_tex.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 351447a

Please sign in to comment.