From: Lynne <dev@lynne.ee> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Subject: [FFmpeg-devel] [PATCH] hwcontext_vulkan: properly enable sync2 and make prepare_frame compatible Date: Sun, 3 Apr 2022 17:49:50 +0200 (CEST) Message-ID: <Mzk6ZCB--3-2@lynne.ee> (raw) In-Reply-To: <MzjuZff--3-2@lynne.ee-Mzjubs4--J-2> [-- Attachment #1: Type: text/plain, Size: 133 bytes --] This was meant to be present before the first patch. I'll move the fixes to the first patch when I apply/resubmit. Patch attached. [-- Attachment #2: 0001-hwcontext_vulkan-properly-enable-sync2-and-make-prep.patch --] [-- Type: text/x-patch, Size: 6386 bytes --] From e09d026eedbd4c30f4bf3cfa9ffe547906781d3b Mon Sep 17 00:00:00 2001 From: Lynne <dev@lynne.ee> Date: Sun, 3 Apr 2022 17:47:58 +0200 Subject: [PATCH] hwcontext_vulkan: properly enable sync2 and make prepare_frame compatible --- libavutil/hwcontext_vulkan.c | 52 +++++++++++++++++++++++++++--------- libavutil/vulkan_functions.h | 4 +++ 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c index 5bd0cab7ef..c8de358fa3 100644 --- a/libavutil/hwcontext_vulkan.c +++ b/libavutil/hwcontext_vulkan.c @@ -347,7 +347,7 @@ static const VulkanOptExtension optional_device_exts[] = { /* Misc or required by other extensions */ { VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME, FF_VK_EXT_NO_FLAG }, { VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME, FF_VK_EXT_NO_FLAG }, - { VK_KHR_SYNCHRONIZATION_2_EXTENSION_NAME, FF_VK_EXT_NO_FLAG }, + { VK_KHR_SYNCHRONIZATION_2_EXTENSION_NAME, FF_VK_EXT_SYNC2 }, /* Imports/exports */ { VK_KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME, FF_VK_EXT_EXTERNAL_FD_MEMORY }, @@ -1340,9 +1340,13 @@ static int vulkan_device_create_internal(AVHWDeviceContext *ctx, VkPhysicalDeviceTimelineSemaphoreFeatures timeline_features = { .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TIMELINE_SEMAPHORE_FEATURES, }; + VkPhysicalDeviceSynchronization2Features sync2_features = { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SYNCHRONIZATION_2_FEATURES, + .pNext = &timeline_features, + }; VkPhysicalDeviceVulkan12Features dev_features_1_2 = { .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES, - .pNext = &timeline_features, + .pNext = &sync2_features, }; VkPhysicalDeviceVulkan11Features dev_features_1_1 = { .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES, @@ -1352,10 +1356,8 @@ static int vulkan_device_create_internal(AVHWDeviceContext *ctx, .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, .pNext = &dev_features_1_1, }; - VkDeviceCreateInfo dev_info = { - .sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, - .pNext = &hwctx->device_features, + .sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, }; hwctx->device_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2; @@ -1393,6 +1395,9 @@ static int vulkan_device_create_internal(AVHWDeviceContext *ctx, } p->device_features_1_2.timelineSemaphore = 1; + dev_info.pNext = &sync2_features; + sync2_features.pNext = &hwctx->device_features; + /* Setup queue family */ if ((err = setup_queue_families(ctx, &dev_info))) goto end; @@ -2054,14 +2059,37 @@ static int prepare_frame(AVHWFramesContext *hwfc, VulkanExecCtx *ectx, frame->access[i] = img_bar[i].dstAccessMask; } - dep_info = (VkDependencyInfo) { - .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO, - .dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT, - .pImageMemoryBarriers = img_bar, - .imageMemoryBarrierCount = planes, - }; + if (p->extensions & FF_VK_EXT_SYNC2) { + dep_info = (VkDependencyInfo) { + .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO, + .dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT, + .pImageMemoryBarriers = img_bar, + .imageMemoryBarrierCount = planes, + }; - vk->CmdPipelineBarrier2KHR(get_buf_exec_ctx(hwfc, ectx), &dep_info); + vk->CmdPipelineBarrier2KHR(get_buf_exec_ctx(hwfc, ectx), &dep_info); + } else { + VkImageMemoryBarrier img_bar_old[AV_NUM_DATA_POINTERS] = { 0 }; + + for (int i = 0; i < planes; i++) { + img_bar_old[i] = (VkImageMemoryBarrier) { + .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, + .srcAccessMask = img_bar[i].srcAccessMask, + .dstAccessMask = img_bar[i].dstAccessMask, + .oldLayout = img_bar[i].oldLayout, + .newLayout = img_bar[i].newLayout, + .srcQueueFamilyIndex = img_bar[i].srcQueueFamilyIndex, + .dstQueueFamilyIndex = img_bar[i].dstQueueFamilyIndex, + .image = img_bar[i].image, + .subresourceRange = img_bar[i].subresourceRange, + }; + } + + vk->CmdPipelineBarrier(get_buf_exec_ctx(hwfc, ectx), + VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, + VK_PIPELINE_STAGE_TRANSFER_BIT, + 0, 0, NULL, 0, NULL, planes, img_bar_old); + } err = submit_exec_ctx(hwfc, ectx, &s_info, frame, 0); vkfc->unlock_frame(hwfc, &tmp); diff --git a/libavutil/vulkan_functions.h b/libavutil/vulkan_functions.h index d15a5d9a42..72d242b9a6 100644 --- a/libavutil/vulkan_functions.h +++ b/libavutil/vulkan_functions.h @@ -37,6 +37,7 @@ typedef enum FFVulkanExtensions { FF_VK_EXT_EXTERNAL_WIN32_MEMORY = 1ULL << 6, /* VK_KHR_external_memory_win32 */ FF_VK_EXT_EXTERNAL_WIN32_SEM = 1ULL << 7, /* VK_KHR_external_semaphore_win32 */ #endif + FF_VK_EXT_SYNC2 = 1ULL << 8, /* VK_KHR_synchronization2 */ FF_VK_EXT_NO_FLAG = 1ULL << 31, } FFVulkanExtensions; @@ -145,6 +146,9 @@ typedef enum FFVulkanExtensions { MACRO(1, 1, FF_VK_EXT_NO_FLAG, UpdateDescriptorSetWithTemplate) \ MACRO(1, 1, FF_VK_EXT_NO_FLAG, CreateDescriptorUpdateTemplate) \ MACRO(1, 1, FF_VK_EXT_NO_FLAG, DestroyDescriptorUpdateTemplate) \ + \ + /* sync2 */ \ + MACRO(1, 1, FF_VK_EXT_SYNC2, CmdPipelineBarrier2KHR) \ \ /* Pipeline */ \ MACRO(1, 1, FF_VK_EXT_NO_FLAG, CreatePipelineLayout) \ -- 2.35.1 [-- Attachment #3: Type: text/plain, Size: 251 bytes --] _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
prev parent reply other threads:[~2022-04-03 15:50 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-04-03 14:51 [FFmpeg-devel] [PATCH 1/3] hwcontext_vulkan: expose image queue families Lynne [not found] ` <MzjuD2p--3-2@lynne.ee-MzjuHsU----2> 2022-04-03 14:52 ` [FFmpeg-devel] [PATCH 2/3] hwcontext_vulkan: add queue and frame locking functions Lynne 2022-04-05 9:38 ` Anton Khirnov 2022-04-05 14:16 ` Lynne [not found] ` <MzjuQ-Z--3-2@lynne.ee-MzjuTDW----2> 2022-04-03 14:53 ` [FFmpeg-devel] [PATCH 3/3] lavu: bump version and add APIchanges for Vulkan API changes Lynne [not found] ` <MzjuZff--3-2@lynne.ee-Mzjubs4--J-2> 2022-04-03 15:49 ` Lynne [this message]
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=Mzk6ZCB--3-2@lynne.ee \ --to=dev@lynne.ee \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git