diff mbox series

[FFmpeg-devel] Allow exporting of RGB and BGR images to CUDA.

Message ID d46faf00c6214a6592d6c8b3c4951247@MRU.MEDICAL.CANON
State New
Headers show
Series [FFmpeg-devel] Allow exporting of RGB and BGR images to CUDA. | expand

Checks

Context Check Description
andriy/commit_msg_x86 warning The first line of the commit message must start with a context terminated by a colon and a space, for example "lavu/opt: " or "doc: ".
yinshiyou/commit_msg_loongarch64 warning The first line of the commit message must start with a context terminated by a colon and a space, for example "lavu/opt: " or "doc: ".
andriy/commit_msg_armv7_RPi4 warning The first line of the commit message must start with a context terminated by a colon and a space, for example "lavu/opt: " or "doc: ".
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_armv7_RPi4 success Make finished
andriy/make_fate_armv7_RPi4 success Make fate finished

Commit Message

dpeeters@MRU.MEDICAL.CANON July 8, 2022, 9:51 p.m. UTC
Use the step size when calculating the number of channels to allow for more than two channels per plane.  This allows the use of AV_PIX_FMT_0BGR32 when using av_hwframe_transfer_data to transfer data from a Vulkan frame to a CUDA frame.

Signed-off-by: David Peeters <dpeeters@MRU.MEDICAL.CANON>
---
 libavutil/hwcontext_vulkan.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

dpeeters@MRU.MEDICAL.CANON July 28, 2022, 4:23 p.m. UTC | #1
> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> dpeeters@MRU.MEDICAL.CANON
> Sent: Friday, July 8, 2022 4:51 PM
> To: ffmpeg-devel@ffmpeg.org
> Subject: [EXTERNAL] [FFmpeg-devel] [PATCH] Allow exporting of RGB and
> BGR images to CUDA.
> 
> Use the step size when calculating the number of channels to allow for more
> than two channels per plane.  This allows the use of AV_PIX_FMT_0BGR32
> when using av_hwframe_transfer_data to transfer data from a Vulkan frame
> to a CUDA frame.
> 
> Signed-off-by: David Peeters <dpeeters@MRU.MEDICAL.CANON>
> ---
>  libavutil/hwcontext_vulkan.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
> index 237caa4bc0..05e8fc5268 100644
> --- a/libavutil/hwcontext_vulkan.c
> +++ b/libavutil/hwcontext_vulkan.c
> @@ -2992,6 +2992,8 @@ static int
> vulkan_export_to_cuda(AVHWFramesContext *hwfc,
>      const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(hwfc-
> >sw_format);
>      VulkanDevicePriv *p = ctx->internal->priv;
>      FFVulkanFunctions *vk = &p->vkfn;
> +    int max_pixsteps[4];
> +    int max_pixstep_comps[4];
> 
>      AVHWFramesContext *cuda_fc = (AVHWFramesContext*)cuda_hwfc-
> >data;
>      AVHWDeviceContext *cuda_cu = cuda_fc->device_ctx; @@ -3001,6
> +3003,8 @@ static int vulkan_export_to_cuda(AVHWFramesContext *hwfc,
>      CUarray_format cufmt = desc->comp[0].depth > 8 ?
> CU_AD_FORMAT_UNSIGNED_INT16 :
>                                                       CU_AD_FORMAT_UNSIGNED_INT8;
> 
> +    av_image_fill_max_pixsteps(max_pixsteps, max_pixstep_comps, desc);
> +
>      dst_f = (AVVkFrame *)frame->data[0];
> 
>      dst_int = dst_f->internal;
> @@ -3023,7 +3027,9 @@ static int
> vulkan_export_to_cuda(AVHWFramesContext *hwfc,
>                  .arrayDesc = {
>                      .Depth = 0,
>                      .Format = cufmt,
> -                    .NumChannels = 1 + ((planes == 2) && i),
> +                    .NumChannels = desc->comp[max_pixstep_comps[i]].depth > 8
> +                        ? max_pixsteps[i] / 2
> +                        : max_pixsteps[i],
>                      .Flags = 0,
>                  },
>                  .numLevels = 1,
> --
> 2.36.1
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://urldefense.com/v3/__https://ffmpeg.org/mailman/listinfo/ffmpeg-
> devel__;!!Ai2CFrZnFhI!6NGwn-
> Nv1AZn7qfPlMbwKHeDqU79spui_ApfLibprH2k3cVnA6ayxejFpL_xrg-
> 8adz1jY9btFkZrg33AWLLDsXfE_uWCpvx$
> 
> To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org
> with subject "unsubscribe".

Ping.
Are there any changes needed for this?
dpeeters@MRU.MEDICAL.CANON Aug. 23, 2022, 8:40 p.m. UTC | #2
> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> dpeeters@MRU.MEDICAL.CANON
> Sent: Thursday, July 28, 2022 11:24 AM
> To: ffmpeg-devel@ffmpeg.org
> Subject: [EXTERNAL] Re: [FFmpeg-devel] [PATCH] Allow exporting of RGB
> and BGR images to CUDA.
> 
> > -----Original Message-----
> > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> > dpeeters@MRU.MEDICAL.CANON
> > Sent: Friday, July 8, 2022 4:51 PM
> > To: ffmpeg-devel@ffmpeg.org
> > Subject: [EXTERNAL] [FFmpeg-devel] [PATCH] Allow exporting of RGB and
> > BGR images to CUDA.
> >
> > Use the step size when calculating the number of channels to allow for
> > more than two channels per plane.  This allows the use of
> > AV_PIX_FMT_0BGR32 when using av_hwframe_transfer_data to transfer
> data
> > from a Vulkan frame to a CUDA frame.
> >
> > Signed-off-by: David Peeters <dpeeters@MRU.MEDICAL.CANON>
> > ---
> >  libavutil/hwcontext_vulkan.c | 8 +++++++-
> >  1 file changed, 7 insertions(+), 1 deletion(-)
> >
> > diff --git a/libavutil/hwcontext_vulkan.c
> > b/libavutil/hwcontext_vulkan.c index 237caa4bc0..05e8fc5268 100644
> > --- a/libavutil/hwcontext_vulkan.c
> > +++ b/libavutil/hwcontext_vulkan.c
> > @@ -2992,6 +2992,8 @@ static int
> > vulkan_export_to_cuda(AVHWFramesContext *hwfc,
> >      const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(hwfc-
> > >sw_format);
> >      VulkanDevicePriv *p = ctx->internal->priv;
> >      FFVulkanFunctions *vk = &p->vkfn;
> > +    int max_pixsteps[4];
> > +    int max_pixstep_comps[4];
> >
> >      AVHWFramesContext *cuda_fc = (AVHWFramesContext*)cuda_hwfc-
> > >data;
> >      AVHWDeviceContext *cuda_cu = cuda_fc->device_ctx; @@ -3001,6
> > +3003,8 @@ static int vulkan_export_to_cuda(AVHWFramesContext
> *hwfc,
> >      CUarray_format cufmt = desc->comp[0].depth > 8 ?
> > CU_AD_FORMAT_UNSIGNED_INT16 :
> >
> > CU_AD_FORMAT_UNSIGNED_INT8;
> >
> > +    av_image_fill_max_pixsteps(max_pixsteps, max_pixstep_comps,
> > + desc);
> > +
> >      dst_f = (AVVkFrame *)frame->data[0];
> >
> >      dst_int = dst_f->internal;
> > @@ -3023,7 +3027,9 @@ static int
> > vulkan_export_to_cuda(AVHWFramesContext *hwfc,
> >                  .arrayDesc = {
> >                      .Depth = 0,
> >                      .Format = cufmt,
> > -                    .NumChannels = 1 + ((planes == 2) && i),
> > +                    .NumChannels = desc->comp[max_pixstep_comps[i]].depth > 8
> > +                        ? max_pixsteps[i] / 2
> > +                        : max_pixsteps[i],
> >                      .Flags = 0,
> >                  },
> >                  .numLevels = 1,
> > --
> > 2.36.1
> >
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> >
> https://urldefense.com/v3/__https://ffmpeg.org/mailman/listinfo/ffmpeg
> > -
> > devel__;!!Ai2CFrZnFhI!6NGwn-
> > Nv1AZn7qfPlMbwKHeDqU79spui_ApfLibprH2k3cVnA6ayxejFpL_xrg-
> > 8adz1jY9btFkZrg33AWLLDsXfE_uWCpvx$
> >
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> 
> Ping.
> Are there any changes needed for this?
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://urldefense.com/v3/__https://ffmpeg.org/mailman/listinfo/ffmpeg-
> devel__;!!Ai2CFrZnFhI!_8PN4GC6c0n28X6z7gL1O_2a6oaf-
> cxdrbLpTmzsR4HvKg7EtCBTrFBiOUrsQrY_ptbzSzlpiVrLjzrCotNFYmkiQZn2BHW
> _$
> 
> To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org
> with subject "unsubscribe".

Ping.
diff mbox series

Patch

diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index 237caa4bc0..05e8fc5268 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -2992,6 +2992,8 @@  static int vulkan_export_to_cuda(AVHWFramesContext *hwfc,
     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(hwfc->sw_format);
     VulkanDevicePriv *p = ctx->internal->priv;
     FFVulkanFunctions *vk = &p->vkfn;
+    int max_pixsteps[4];
+    int max_pixstep_comps[4];
 
     AVHWFramesContext *cuda_fc = (AVHWFramesContext*)cuda_hwfc->data;
     AVHWDeviceContext *cuda_cu = cuda_fc->device_ctx;
@@ -3001,6 +3003,8 @@  static int vulkan_export_to_cuda(AVHWFramesContext *hwfc,
     CUarray_format cufmt = desc->comp[0].depth > 8 ? CU_AD_FORMAT_UNSIGNED_INT16 :
                                                      CU_AD_FORMAT_UNSIGNED_INT8;
 
+    av_image_fill_max_pixsteps(max_pixsteps, max_pixstep_comps, desc);
+
     dst_f = (AVVkFrame *)frame->data[0];
 
     dst_int = dst_f->internal;
@@ -3023,7 +3027,9 @@  static int vulkan_export_to_cuda(AVHWFramesContext *hwfc,
                 .arrayDesc = {
                     .Depth = 0,
                     .Format = cufmt,
-                    .NumChannels = 1 + ((planes == 2) && i),
+                    .NumChannels = desc->comp[max_pixstep_comps[i]].depth > 8
+                        ? max_pixsteps[i] / 2
+                        : max_pixsteps[i],
                     .Flags = 0,
                 },
                 .numLevels = 1,