From: Lynne via ffmpeg-devel <ffmpeg-devel@ffmpeg.org> To: ffmpeg-devel@ffmpeg.org Cc: Lynne <dev@lynne.ee> Subject: Re: [FFmpeg-devel] [PATCH] lavu/hwcontext_vulkan: Support write on drm frame Date: Wed, 12 Jun 2024 02:02:07 +0200 Message-ID: <b55e6ca3-ab76-400c-9824-d7758df1ab71@lynne.ee> (raw) In-Reply-To: <20240611045547.334627-1-haihao.xiang@intel.com> [-- Attachment #1.1.1.1: Type: text/plain, Size: 4252 bytes --] On 11/06/2024 06:55, Xiang, Haihao wrote: > From: Haihao Xiang <haihao.xiang@intel.com> > > Otherwise nothing is written into the destination when a write mapping > is requested. > > For example, a vulkan frame mapped from a drm frame (which is wrapped as > a vaapi frame in the example) is used as the output of scale_vulkan > filter, it always gets a green screen without this patch. > > ffmpeg -init_hw_device vaapi=va -init_hw_device vulkan=vulkan@va > -filter_hw_device vulkan -f lavfi -i testsrc=size=352x288,format=nv12 > -vf > "hwupload,scale_vulkan,hwmap=derive_device=vaapi:reverse=1,format=vaapi,hwdownload,format=nv12" > -f nut - | ffplay - > > Signed-off-by: Haihao Xiang <haihao.xiang@intel.com> > --- > libavutil/hwcontext_vulkan.c | 15 +++++++++++---- > 1 file changed, 11 insertions(+), 4 deletions(-) > > diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c > index e2f92af227..675ead0ba6 100644 > --- a/libavutil/hwcontext_vulkan.c > +++ b/libavutil/hwcontext_vulkan.c > @@ -2511,7 +2511,7 @@ static inline VkFormat drm_to_vulkan_fmt(uint32_t drm_fourcc) > } > > static int vulkan_map_from_drm_frame_desc(AVHWFramesContext *hwfc, AVVkFrame **frame, > - const AVFrame *src) > + const AVFrame *src, int flags) > { > int err = 0; > VkResult ret; > @@ -2569,6 +2569,14 @@ static int vulkan_map_from_drm_frame_desc(AVHWFramesContext *hwfc, AVVkFrame **f > .pNext = &ext_img_mod_spec, > .handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT, > }; > + int usage = (((flags & (AV_HWFRAME_MAP_READ | AV_HWFRAME_MAP_WRITE)) == (AV_HWFRAME_MAP_READ | AV_HWFRAME_MAP_WRITE)) ? > + (VK_IMAGE_USAGE_SAMPLED_BIT | > + VK_IMAGE_USAGE_TRANSFER_SRC_BIT | > + VK_IMAGE_USAGE_TRANSFER_DST_BIT | > + VK_IMAGE_USAGE_STORAGE_BIT) : > + ((flags & AV_HWFRAME_MAP_WRITE) ? > + (VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_STORAGE_BIT) : > + (VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT))); Changed to a more readable: > + if (flags & AV_HWFRAME_MAP_READ) > + create_info.usage |= VK_IMAGE_USAGE_SAMPLED_BIT | > + VK_IMAGE_USAGE_TRANSFER_SRC_BIT; > + if (flags & AV_HWFRAME_MAP_WRITE) > + create_info.usage |= VK_IMAGE_USAGE_STORAGE_BIT | > + VK_IMAGE_USAGE_TRANSFER_DST_BIT; By filling it down below. > VkImageCreateInfo create_info = { > .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, > .pNext = &ext_img_spec, > @@ -2580,8 +2588,7 @@ static int vulkan_map_from_drm_frame_desc(AVHWFramesContext *hwfc, AVVkFrame **f > .flags = 0x0, > .tiling = VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT, > .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED, /* specs say so */ > - .usage = VK_IMAGE_USAGE_SAMPLED_BIT | > - VK_IMAGE_USAGE_TRANSFER_SRC_BIT, > + .usage = usage, > .samples = VK_SAMPLE_COUNT_1_BIT, > .pQueueFamilyIndices = p->img_qfs, > .queueFamilyIndexCount = p->nb_img_qfs, > @@ -2788,7 +2795,7 @@ static int vulkan_map_from_drm(AVHWFramesContext *hwfc, AVFrame *dst, > int err = 0; > AVVkFrame *f; > > - if ((err = vulkan_map_from_drm_frame_desc(hwfc, &f, src))) > + if ((err = vulkan_map_from_drm_frame_desc(hwfc, &f, src, flags))) > return err; > > /* The unmapping function will free this */ Pushed, thanks. Glad to know writing to DRM frames works, this was not tested, and it was for a long time unsupported, due to missing modifier support. Once Vulkan encode is added, this should be updated with ENCODE_SRC, but hopefully I'll remember to take care of that. [-- Attachment #1.1.1.2: OpenPGP public key --] [-- Type: application/pgp-keys, Size: 637 bytes --] [-- Attachment #1.2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 236 bytes --] [-- Attachment #2: 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:[~2024-06-12 0:02 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-06-11 4:55 Xiang, Haihao 2024-06-12 0:02 ` Lynne via ffmpeg-devel [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=b55e6ca3-ab76-400c-9824-d7758df1ab71@lynne.ee \ --to=ffmpeg-devel@ffmpeg.org \ --cc=dev@lynne.ee \ /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