diff mbox series

[FFmpeg-devel,V2,4/5] libavutil/hwcontext_vulkan: Add hwupload and hwdownload support when using contiguous_planes flag.

Message ID 20211124052848.1122682-4-wenbin.chen@intel.com
State New
Headers show
Series [FFmpeg-devel,V2,1/5] hwcontext_vaapi: Use PRIME_2 memory type for modifiers.
Related show

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Chen, Wenbin Nov. 24, 2021, 5:28 a.m. UTC
Add hwupload and hwdownload support to vulkan when frames are allocated
in one memory

Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
---
 libavutil/hwcontext_vulkan.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

Comments

Lynne Nov. 24, 2021, 10:39 a.m. UTC | #1
24 Nov 2021, 06:28 by wenbin.chen@intel.com:

> Add hwupload and hwdownload support to vulkan when frames are allocated
> in one memory
>
> Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
> ---
>  libavutil/hwcontext_vulkan.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
> index 4100e8b0a2..6421115385 100644
> --- a/libavutil/hwcontext_vulkan.c
> +++ b/libavutil/hwcontext_vulkan.c
> @@ -2212,9 +2212,10 @@ static int vulkan_map_frame_to_mem(AVHWFramesContext *hwfc, AVFrame *dst,
>  const AVFrame *src, int flags)
>  {
>  VkResult ret;
> -    int err, mapped_mem_count = 0;
> +    int err, mapped_mem_count = 0, loop = 0;
>  AVVkFrame *f = (AVVkFrame *)src->data[0];
>  AVVulkanDeviceContext *hwctx = hwfc->device_ctx->hwctx;
> +    AVVulkanFramesContext *hwfctx = hwfc->hwctx;
>  const int planes = av_pix_fmt_count_planes(hwfc->sw_format);
>  VulkanDevicePriv *p = hwfc->device_ctx->internal->priv;
>  FFVulkanFunctions *vk = &p->vkfn;
> @@ -2241,7 +2242,9 @@ static int vulkan_map_frame_to_mem(AVHWFramesContext *hwfc, AVFrame *dst,
>  dst->width  = src->width;
>  dst->height = src->height;
>  
> -    for (int i = 0; i < planes; i++) {
> +    loop = hwfctx->contiguous_planes == AV_VK_FRAME_FLAG_CONTIGUOUS_MEMORY ?
> +           1 : planes;
> +    for (int i = 0; i < loop; i++) {
>  ret = vk->MapMemory(hwctx->act_dev, f->mem[i], 0,
>  VK_WHOLE_SIZE, 0, (void **)&dst->data[i]);
>  if (ret != VK_SUCCESS) {
> @@ -2252,6 +2255,11 @@ static int vulkan_map_frame_to_mem(AVHWFramesContext *hwfc, AVFrame *dst,
>  }
>  mapped_mem_count++;
>  }
> +    if (hwfctx->contiguous_planes == AV_VK_FRAME_FLAG_CONTIGUOUS_MEMORY) {
> +        for (int i = 0; i < planes; i++) {
> +            dst->data[i] = dst->data[0] + f->offset[i];
> +        }
> +    }
>  
>  /* Check if the memory contents matter */
>  if (((flags & AV_HWFRAME_MAP_READ) || !(flags & AV_HWFRAME_MAP_OVERWRITE)) &&
>

The patch description is wrong, this doesn't apply to hwupload/hwdownload,
it only applies to hwmap to a software frame.
Also, code style issues, we do not put brackets on one-line statements.
diff mbox series

Patch

diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index 4100e8b0a2..6421115385 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -2212,9 +2212,10 @@  static int vulkan_map_frame_to_mem(AVHWFramesContext *hwfc, AVFrame *dst,
                                    const AVFrame *src, int flags)
 {
     VkResult ret;
-    int err, mapped_mem_count = 0;
+    int err, mapped_mem_count = 0, loop = 0;
     AVVkFrame *f = (AVVkFrame *)src->data[0];
     AVVulkanDeviceContext *hwctx = hwfc->device_ctx->hwctx;
+    AVVulkanFramesContext *hwfctx = hwfc->hwctx;
     const int planes = av_pix_fmt_count_planes(hwfc->sw_format);
     VulkanDevicePriv *p = hwfc->device_ctx->internal->priv;
     FFVulkanFunctions *vk = &p->vkfn;
@@ -2241,7 +2242,9 @@  static int vulkan_map_frame_to_mem(AVHWFramesContext *hwfc, AVFrame *dst,
     dst->width  = src->width;
     dst->height = src->height;
 
-    for (int i = 0; i < planes; i++) {
+    loop = hwfctx->contiguous_planes == AV_VK_FRAME_FLAG_CONTIGUOUS_MEMORY ?
+           1 : planes;
+    for (int i = 0; i < loop; i++) {
         ret = vk->MapMemory(hwctx->act_dev, f->mem[i], 0,
                             VK_WHOLE_SIZE, 0, (void **)&dst->data[i]);
         if (ret != VK_SUCCESS) {
@@ -2252,6 +2255,11 @@  static int vulkan_map_frame_to_mem(AVHWFramesContext *hwfc, AVFrame *dst,
         }
         mapped_mem_count++;
     }
+    if (hwfctx->contiguous_planes == AV_VK_FRAME_FLAG_CONTIGUOUS_MEMORY) {
+        for (int i = 0; i < planes; i++) {
+            dst->data[i] = dst->data[0] + f->offset[i];
+        }
+    }
 
     /* Check if the memory contents matter */
     if (((flags & AV_HWFRAME_MAP_READ) || !(flags & AV_HWFRAME_MAP_OVERWRITE)) &&