Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 1/2] libavutil/hwcontext_vulkan: Fix VK_FORMAT_R8G8_UNORM and VK_FORMAT_R16G16_UNORM map problem on Vulkan
@ 2022-03-30  3:41 Wenbin Chen
  2022-03-30  3:41 ` [FFmpeg-devel] [PATCH 2/2] libavutil/hwcontext_vaapi: fix nv12 map error Wenbin Chen
  2022-04-13  6:05 ` [FFmpeg-devel] [PATCH 1/2] libavutil/hwcontext_vulkan: Fix VK_FORMAT_R8G8_UNORM and VK_FORMAT_R16G16_UNORM map problem on Vulkan Xiang, Haihao
  0 siblings, 2 replies; 4+ messages in thread
From: Wenbin Chen @ 2022-03-30  3:41 UTC (permalink / raw)
  To: ffmpeg-devel

Vulkan map both DRM_FORMAT_RG88 and DRM_FORMAT_GR88 to
VK_FORMAT_R8G8_UNORM. This cannot distinguish nv12/nv24 and nv21/nv42.
Vulkan also map both DRM_FORMAT_RG1616 and DRM_FORMAT_GR1616 to
VK_FORMAT_R16G16_UNORM. This causes issue when map back.
VK_FORMAT_R16G16 will be mapped to DRM_FORMAT_GR1616, while p010 need
DRM_FORMAT_RG1616.
Add sw_format check to vulkan_fmt_to_drm() to fix this problem.

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

diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index 237caa4bc0..791649001f 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -3290,8 +3290,17 @@ static void vulkan_unmap_to_drm(AVHWFramesContext *hwfc, HWMapDescriptor *hwmap)
     av_free(drm_desc);
 }
 
-static inline uint32_t vulkan_fmt_to_drm(VkFormat vkfmt)
+static inline uint32_t vulkan_fmt_to_drm(VkFormat vkfmt,
+                                         enum AVPixelFormat sw_format)
 {
+    if (vkfmt == VK_FORMAT_R8G8_UNORM &&
+       (sw_format == AV_PIX_FMT_NV12 || sw_format == AV_PIX_FMT_NV24))
+            return DRM_FORMAT_RG88;
+
+    if (vkfmt == VK_FORMAT_R16G16_UNORM &&
+       (sw_format == AV_PIX_FMT_P010 || sw_format == AV_PIX_FMT_P016))
+            return DRM_FORMAT_RG1616;
+
     for (int i = 0; i < FF_ARRAY_ELEMS(vulkan_drm_format_map); i++)
         if (vulkan_drm_format_map[i].vk_format == vkfmt)
             return vulkan_drm_format_map[i].drm_fourcc;
@@ -3373,7 +3382,7 @@ static int vulkan_map_to_drm(AVHWFramesContext *hwfc, AVFrame *dst,
         };
         VkFormat plane_vkfmt = av_vkfmt_from_pixfmt(hwfc->sw_format)[i];
 
-        drm_desc->layers[i].format    = vulkan_fmt_to_drm(plane_vkfmt);
+        drm_desc->layers[i].format    = vulkan_fmt_to_drm(plane_vkfmt, hwfc->sw_format);
         drm_desc->layers[i].nb_planes = 1;
 
         if (drm_desc->layers[i].format == DRM_FORMAT_INVALID) {
-- 
2.32.0

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [FFmpeg-devel] [PATCH 2/2] libavutil/hwcontext_vaapi: fix nv12 map error
  2022-03-30  3:41 [FFmpeg-devel] [PATCH 1/2] libavutil/hwcontext_vulkan: Fix VK_FORMAT_R8G8_UNORM and VK_FORMAT_R16G16_UNORM map problem on Vulkan Wenbin Chen
@ 2022-03-30  3:41 ` Wenbin Chen
  2022-04-13  6:05 ` [FFmpeg-devel] [PATCH 1/2] libavutil/hwcontext_vulkan: Fix VK_FORMAT_R8G8_UNORM and VK_FORMAT_R16G16_UNORM map problem on Vulkan Xiang, Haihao
  1 sibling, 0 replies; 4+ messages in thread
From: Wenbin Chen @ 2022-03-30  3:41 UTC (permalink / raw)
  To: ffmpeg-devel

The UV plane of NV12 should not be mapped to DRM_FORMAT_GR88. Remove
this map after the problem is fixed on ffmpeg-vulkan side.

Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
---
 libavutil/hwcontext_vaapi.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 994b744e4d..75acc851d6 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -992,7 +992,6 @@ static const struct {
 } vaapi_drm_format_map[] = {
 #ifdef DRM_FORMAT_R8
     DRM_MAP(NV12, 2, DRM_FORMAT_R8,  DRM_FORMAT_RG88),
-    DRM_MAP(NV12, 2, DRM_FORMAT_R8,  DRM_FORMAT_GR88),
 #endif
     DRM_MAP(NV12, 1, DRM_FORMAT_NV12),
 #if defined(VA_FOURCC_P010) && defined(DRM_FORMAT_R16)
-- 
2.32.0

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [FFmpeg-devel] [PATCH 1/2] libavutil/hwcontext_vulkan: Fix VK_FORMAT_R8G8_UNORM and VK_FORMAT_R16G16_UNORM map problem on Vulkan
  2022-03-30  3:41 [FFmpeg-devel] [PATCH 1/2] libavutil/hwcontext_vulkan: Fix VK_FORMAT_R8G8_UNORM and VK_FORMAT_R16G16_UNORM map problem on Vulkan Wenbin Chen
  2022-03-30  3:41 ` [FFmpeg-devel] [PATCH 2/2] libavutil/hwcontext_vaapi: fix nv12 map error Wenbin Chen
@ 2022-04-13  6:05 ` Xiang, Haihao
  2022-04-14 10:39   ` Lynne
  1 sibling, 1 reply; 4+ messages in thread
From: Xiang, Haihao @ 2022-04-13  6:05 UTC (permalink / raw)
  To: ffmpeg-devel

On Wed, 2022-03-30 at 11:41 +0800, Wenbin Chen wrote:
> Vulkan map both DRM_FORMAT_RG88 and DRM_FORMAT_GR88 to
> VK_FORMAT_R8G8_UNORM. This cannot distinguish nv12/nv24 and nv21/nv42.
> Vulkan also map both DRM_FORMAT_RG1616 and DRM_FORMAT_GR1616 to
> VK_FORMAT_R16G16_UNORM. This causes issue when map back.
> VK_FORMAT_R16G16 will be mapped to DRM_FORMAT_GR1616, while p010 need
> DRM_FORMAT_RG1616.
> Add sw_format check to vulkan_fmt_to_drm() to fix this problem.
> 
> Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
> ---
>  libavutil/hwcontext_vulkan.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
> index 237caa4bc0..791649001f 100644
> --- a/libavutil/hwcontext_vulkan.c
> +++ b/libavutil/hwcontext_vulkan.c
> @@ -3290,8 +3290,17 @@ static void vulkan_unmap_to_drm(AVHWFramesContext
> *hwfc, HWMapDescriptor *hwmap)
>      av_free(drm_desc);
>  }
>  
> -static inline uint32_t vulkan_fmt_to_drm(VkFormat vkfmt)
> +static inline uint32_t vulkan_fmt_to_drm(VkFormat vkfmt,
> +                                         enum AVPixelFormat sw_format)
>  {
> +    if (vkfmt == VK_FORMAT_R8G8_UNORM &&
> +       (sw_format == AV_PIX_FMT_NV12 || sw_format == AV_PIX_FMT_NV24))
> +            return DRM_FORMAT_RG88;
> +
> +    if (vkfmt == VK_FORMAT_R16G16_UNORM &&
> +       (sw_format == AV_PIX_FMT_P010 || sw_format == AV_PIX_FMT_P016))
> +            return DRM_FORMAT_RG1616;
> +
>      for (int i = 0; i < FF_ARRAY_ELEMS(vulkan_drm_format_map); i++)
>          if (vulkan_drm_format_map[i].vk_format == vkfmt)
>              return vulkan_drm_format_map[i].drm_fourcc;
> @@ -3373,7 +3382,7 @@ static int vulkan_map_to_drm(AVHWFramesContext *hwfc,
> AVFrame *dst,
>          };
>          VkFormat plane_vkfmt = av_vkfmt_from_pixfmt(hwfc->sw_format)[i];
>  
> -        drm_desc->layers[i].format    = vulkan_fmt_to_drm(plane_vkfmt);
> +        drm_desc->layers[i].format    = vulkan_fmt_to_drm(plane_vkfmt, hwfc-
> >sw_format);
>          drm_desc->layers[i].nb_planes = 1;
>  
>          if (drm_desc->layers[i].format == DRM_FORMAT_INVALID) {

Patchset LGTM

-Haihao

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [FFmpeg-devel] [PATCH 1/2] libavutil/hwcontext_vulkan: Fix VK_FORMAT_R8G8_UNORM and VK_FORMAT_R16G16_UNORM map problem on Vulkan
  2022-04-13  6:05 ` [FFmpeg-devel] [PATCH 1/2] libavutil/hwcontext_vulkan: Fix VK_FORMAT_R8G8_UNORM and VK_FORMAT_R16G16_UNORM map problem on Vulkan Xiang, Haihao
@ 2022-04-14 10:39   ` Lynne
  0 siblings, 0 replies; 4+ messages in thread
From: Lynne @ 2022-04-14 10:39 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

13 Apr 2022, 08:05 by haihao.xiang-at-intel.com@ffmpeg.org:

> On Wed, 2022-03-30 at 11:41 +0800, Wenbin Chen wrote:
>
>> Vulkan map both DRM_FORMAT_RG88 and DRM_FORMAT_GR88 to
>> VK_FORMAT_R8G8_UNORM. This cannot distinguish nv12/nv24 and nv21/nv42.
>> Vulkan also map both DRM_FORMAT_RG1616 and DRM_FORMAT_GR1616 to
>> VK_FORMAT_R16G16_UNORM. This causes issue when map back.
>> VK_FORMAT_R16G16 will be mapped to DRM_FORMAT_GR1616, while p010 need
>> DRM_FORMAT_RG1616.
>> Add sw_format check to vulkan_fmt_to_drm() to fix this problem.
>>
>> Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
>> ---
>>  libavutil/hwcontext_vulkan.c | 13 +++++++++++--
>>  1 file changed, 11 insertions(+), 2 deletions(-)
>>
>> diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
>> index 237caa4bc0..791649001f 100644
>> --- a/libavutil/hwcontext_vulkan.c
>> +++ b/libavutil/hwcontext_vulkan.c
>> @@ -3290,8 +3290,17 @@ static void vulkan_unmap_to_drm(AVHWFramesContext
>> *hwfc, HWMapDescriptor *hwmap)
>>  av_free(drm_desc);
>>  }
>>  
>> -static inline uint32_t vulkan_fmt_to_drm(VkFormat vkfmt)
>> +static inline uint32_t vulkan_fmt_to_drm(VkFormat vkfmt,
>> +                                         enum AVPixelFormat sw_format)
>>  {
>> +    if (vkfmt == VK_FORMAT_R8G8_UNORM &&
>> +       (sw_format == AV_PIX_FMT_NV12 || sw_format == AV_PIX_FMT_NV24))
>> +            return DRM_FORMAT_RG88;
>> +
>> +    if (vkfmt == VK_FORMAT_R16G16_UNORM &&
>> +       (sw_format == AV_PIX_FMT_P010 || sw_format == AV_PIX_FMT_P016))
>> +            return DRM_FORMAT_RG1616;
>> +
>>  for (int i = 0; i < FF_ARRAY_ELEMS(vulkan_drm_format_map); i++)
>>  if (vulkan_drm_format_map[i].vk_format == vkfmt)
>>  return vulkan_drm_format_map[i].drm_fourcc;
>> @@ -3373,7 +3382,7 @@ static int vulkan_map_to_drm(AVHWFramesContext *hwfc,
>> AVFrame *dst,
>>  };
>>  VkFormat plane_vkfmt = av_vkfmt_from_pixfmt(hwfc->sw_format)[i];
>>  
>> -        drm_desc->layers[i].format    = vulkan_fmt_to_drm(plane_vkfmt);
>> +        drm_desc->layers[i].format    = vulkan_fmt_to_drm(plane_vkfmt, hwfc-
>> >sw_format);
>>  drm_desc->layers[i].nb_planes = 1;
>>  
>>  if (drm_desc->layers[i].format == DRM_FORMAT_INVALID) {
>>
>
> Patchset LGTM
>

I'll hold off on pushing all of your and Wenbin's Vulkan patches for now.

Your hacks for cheap hardware have seriously broken image
and memory allocation for anyone who doesn't care about
your niche use cases, and of course it's up to me to salvage it.
What's worse, I don't know if it's your drivers that are at fault,
or if it's your patches that are at fault, or both.
I already had to rip all of your patches off just to get Vulkan
Video decoding working.

Pushing any more code will just create even more mess for me
to deal with, and I'm already knee-deep in it trying to work around
the Khronos user synchronized object madness.

You'll just have to wait for me to fix them, unless you think you
can fix them yourselves, which I doubt. I may have to partially
revert your patches too, because right now, everything's
pretty broken.
_______________________________________________
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".

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-04-14 10:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-30  3:41 [FFmpeg-devel] [PATCH 1/2] libavutil/hwcontext_vulkan: Fix VK_FORMAT_R8G8_UNORM and VK_FORMAT_R16G16_UNORM map problem on Vulkan Wenbin Chen
2022-03-30  3:41 ` [FFmpeg-devel] [PATCH 2/2] libavutil/hwcontext_vaapi: fix nv12 map error Wenbin Chen
2022-04-13  6:05 ` [FFmpeg-devel] [PATCH 1/2] libavutil/hwcontext_vulkan: Fix VK_FORMAT_R8G8_UNORM and VK_FORMAT_R16G16_UNORM map problem on Vulkan Xiang, Haihao
2022-04-14 10:39   ` Lynne

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