Commit a4630d47 authored by Haihao Xiang's avatar Haihao Xiang Committed by Lynne

lavu/hwcontext_vulkan: Support write on drm frame

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: 's avatarHaihao Xiang <haihao.xiang@intel.com>
parent 9c9f095e
......@@ -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;
......@@ -2580,8 +2580,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 = 0x0, /* filled in below */
.samples = VK_SAMPLE_COUNT_1_BIT,
.pQueueFamilyIndices = p->img_qfs,
.queueFamilyIndexCount = p->nb_img_qfs,
......@@ -2619,6 +2618,13 @@ static int vulkan_map_from_drm_frame_desc(AVHWFramesContext *hwfc, AVVkFrame **f
.flags = create_info.flags,
};
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;
/* Check if importing is possible for this combination of parameters */
ret = vk->GetPhysicalDeviceImageFormatProperties2(hwctx->phys_dev,
&fmt_props, &props_ret);
......@@ -2788,7 +2794,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 */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment