[vlc-commits] [Git][videolan/vlc][master] 9 commits: direct3d11: use the CPU chroma description from D3D11 opaque

Steve Lhomme (@robUx4) gitlab at videolan.org
Sat Oct 21 16:24:20 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
1289d688 by Steve Lhomme at 2023-10-21T16:06:00+00:00
direct3d11: use the CPU chroma description from D3D11 opaque

- - - - -
1cc51544 by Steve Lhomme at 2023-10-21T16:06:00+00:00
nvdec: split public and private headers

- - - - -
8b622088 by Steve Lhomme at 2023-10-21T16:06:00+00:00
nvdec: add a function to map NVDEC opaque chromas to VLC chromas

- - - - -
8d41f942 by Steve Lhomme at 2023-10-21T16:06:00+00:00
nvdec_gl: use NVDECToVlcChroma()

- - - - -
5b287d4e by Steve Lhomme at 2023-10-21T16:06:00+00:00
nvdec/chroma: use NVDECToVlcChroma() to check the output CPU chroma matches

VLC_CODEC_YUVA is a special case that is allowed with

- - - - -
be4da675 by Steve Lhomme at 2023-10-21T16:06:00+00:00
direct3d11: use NVDECToVlcChroma() to the the CPU equivalent of NVDEC chromas

- - - - -
522ffc41 by Steve Lhomme at 2023-10-21T16:06:00+00:00
direct3d11: simplify test for unknown/opaque chroma descriptions

- - - - -
466c59f3 by Steve Lhomme at 2023-10-21T16:06:00+00:00
direct3d11: simplify indentation

- - - - -
13898c11 by Steve Lhomme at 2023-10-21T16:06:00+00:00
nvdec_fmt: simplify is_nvdec_opaque()

So have a single source of information for the CPU/GPU chroma difference.

- - - - -


8 changed files:

- modules/hw/nvdec/Makefile.am
- modules/hw/nvdec/chroma.c
- modules/hw/nvdec/nvdec.c
- modules/hw/nvdec/nvdec_fmt.h
- modules/hw/nvdec/nvdec_gl.c
- + modules/hw/nvdec/nvdec_priv.h
- modules/video_output/Makefile.am
- modules/video_output/win32/direct3d11.cpp


Changes:

=====================================
modules/hw/nvdec/Makefile.am
=====================================
@@ -2,20 +2,21 @@ nvdecdir = $(pluginsdir)/nvdec
 nvdec_LTLIBRARIES =
 
 libnvdec_plugin_la_SOURCES = \
-	hw/nvdec/nvdec.c hw/nvdec/nvdec_fmt.h \
+	hw/nvdec/nvdec.c hw/nvdec/nvdec_fmt.h hw/nvdec/nvdec_priv.h \
 	hw/nvdec/hw_pool.c hw/nvdec/hw_pool.h
 libnvdec_plugin_la_LIBADD = $(LIBDL) libvlc_hxxxhelper.la
 if HAVE_NVDEC
 nvdec_LTLIBRARIES += libnvdec_plugin.la
 endif
 
-libnvdec_chroma_plugin_la_SOURCES = hw/nvdec/chroma.c hw/nvdec/nvdec_fmt.h
+libnvdec_chroma_plugin_la_SOURCES = hw/nvdec/chroma.c \
+	hw/nvdec/nvdec_fmt.h hw/nvdec/nvdec_priv.h
 if HAVE_NVDEC
 nvdec_LTLIBRARIES += libnvdec_chroma_plugin.la
 endif
 
 libglinterop_nvdec_plugin_la_SOURCES = hw/nvdec/nvdec_gl.c \
-	video_output/opengl/interop.h hw/nvdec/nvdec_fmt.h
+	video_output/opengl/interop.h hw/nvdec/nvdec_fmt.h hw/nvdec/nvdec_priv.h
 libglinterop_nvdec_plugin_la_LIBADD = $(LIBDL)
 if HAVE_GL
 if HAVE_NVDEC


=====================================
modules/hw/nvdec/chroma.c
=====================================
@@ -30,6 +30,7 @@
 #include <vlc_codec.h>
 
 #include "nvdec_fmt.h"
+#include "nvdec_priv.h"
 
 static int OpenCUDAToCPU( filter_t * );
 
@@ -124,17 +125,11 @@ static int OpenCUDAToCPU( filter_t *p_filter )
     if ( p_filter->vctx_in == NULL ||
          vlc_video_context_GetType(p_filter->vctx_in) != VLC_VIDEO_CONTEXT_NVDEC )
         return VLC_EGENERIC;
-    if ( !( ( p_filter->fmt_in.video.i_chroma  == VLC_CODEC_NVDEC_OPAQUE &&
-              p_filter->fmt_out.video.i_chroma == VLC_CODEC_NV12 ) ||
-            ( p_filter->fmt_in.video.i_chroma  == VLC_CODEC_NVDEC_OPAQUE_10B &&
-              p_filter->fmt_out.video.i_chroma == VLC_CODEC_P010 ) ||
-            ( p_filter->fmt_in.video.i_chroma  == VLC_CODEC_NVDEC_OPAQUE_16B &&
-              p_filter->fmt_out.video.i_chroma == VLC_CODEC_P016 ) ||
-            ( p_filter->fmt_in.video.i_chroma  == VLC_CODEC_NVDEC_OPAQUE_444 &&
-              (p_filter->fmt_out.video.i_chroma == VLC_CODEC_I444 || p_filter->fmt_out.video.i_chroma == VLC_CODEC_YUVA) ) ||
-            ( p_filter->fmt_in.video.i_chroma  == VLC_CODEC_NVDEC_OPAQUE_444_16B &&
-              p_filter->fmt_out.video.i_chroma == VLC_CODEC_I444_16L )
-           ) )
+    assert(is_nvdec_opaque(p_filter->fmt_in.video.i_chroma));
+    vlc_fourcc_t outfcc = NVDECToVlcChroma(p_filter->fmt_in.video.i_chroma);
+    if (p_filter->fmt_out.video.i_chroma != outfcc &&
+        !(p_filter->fmt_in.video.i_chroma == VLC_CODEC_NVDEC_OPAQUE_444 &&
+          p_filter->fmt_out.video.i_chroma == VLC_CODEC_YUVA))
         return VLC_EGENERIC;
 
     p_filter->ops = &filter_ops;


=====================================
modules/hw/nvdec/nvdec.c
=====================================
@@ -32,6 +32,7 @@
 
 #include "../../codec/hxxx_helper.h"
 #include "nvdec_fmt.h"
+#include "nvdec_priv.h"
 #include "hw_pool.h"
 
 #ifndef CU_DEVICE_ATTRIBUTE_TEXTURE_ALIGNMENT


=====================================
modules/hw/nvdec/nvdec_fmt.h
=====================================
@@ -1,7 +1,7 @@
 /*****************************************************************************
- * nvdec_fmt.h : NVDEC common code
+ * nvdec_fmt.h : NVDEC common shared code
  *****************************************************************************
- * Copyright © 2019 VLC authors, VideoLAN and VideoLabs
+ * Copyright © 2019-2023 VLC authors, VideoLAN and VideoLabs
  *
  * Authors: Steve Lhomme <robux4 at videolabs.io>
  *
@@ -23,56 +23,38 @@
 #ifndef VLC_VIDEOCHROMA_NVDEC_FMT_H_
 #define VLC_VIDEOCHROMA_NVDEC_FMT_H_
 
-#define FFNV_LOG_FUNC(logctx, msg, ...)        msg_Err((vlc_object_t*)logctx, msg, __VA_ARGS__)
-#define FFNV_DEBUG_LOG_FUNC(logctx, msg, ...)  msg_Dbg((vlc_object_t*)logctx, msg, __VA_ARGS__)
+#include <vlc_fourcc.h>
 
-#include <ffnvcodec/dynlink_loader.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
 
-typedef struct {
-
-    CudaFunctions  *cudaFunctions;
-    CUcontext      cuCtx;
-
-} decoder_device_nvdec_t;
-
-static inline decoder_device_nvdec_t *GetNVDECOpaqueDevice(vlc_decoder_device *device)
+static inline vlc_fourcc_t NVDECToVlcChroma(vlc_fourcc_t chroma)
 {
-    if (device == NULL || device->type != VLC_DECODER_DEVICE_NVDEC)
-        return NULL;
-    return device->opaque;
-}
-
-static inline int CudaCheckErr(vlc_object_t *obj, CudaFunctions *cudaFunctions, CUresult result, const char *psz_func)
-{
-    if (unlikely(result != CUDA_SUCCESS)) {
-        const char *psz_err, *psz_err_str;
-        cudaFunctions->cuGetErrorName(result, &psz_err);
-        cudaFunctions->cuGetErrorString(result, &psz_err_str);
-        msg_Err(obj, "%s failed: %s (%s)", psz_func, psz_err_str, psz_err);
-        return VLC_EGENERIC;
+    switch (chroma)
+    {
+    case VLC_CODEC_NVDEC_OPAQUE:
+        return VLC_CODEC_NV12;
+    case VLC_CODEC_NVDEC_OPAQUE_10B:
+        return VLC_CODEC_P010;
+    case VLC_CODEC_NVDEC_OPAQUE_16B:
+        return VLC_CODEC_P016;
+    case VLC_CODEC_NVDEC_OPAQUE_444:
+        return VLC_CODEC_I444;
+    case VLC_CODEC_NVDEC_OPAQUE_444_16B:
+        return VLC_CODEC_I444_16L;
+    default:
+        return 0;
     }
-    return VLC_SUCCESS;
 }
 
 static inline bool is_nvdec_opaque(vlc_fourcc_t fourcc)
 {
-    return fourcc == VLC_CODEC_NVDEC_OPAQUE ||
-           fourcc == VLC_CODEC_NVDEC_OPAQUE_10B ||
-           fourcc == VLC_CODEC_NVDEC_OPAQUE_16B ||
-           fourcc == VLC_CODEC_NVDEC_OPAQUE_444 ||
-           fourcc == VLC_CODEC_NVDEC_OPAQUE_444_16B;
+    return NVDECToVlcChroma(fourcc) != 0;
 }
 
-/* for VLC_CODEC_NVDEC_OPAQUE / VLC_CODEC_NVDEC_OPAQUE_16B */
-typedef struct
-{
-    picture_context_t ctx;
-    CUdeviceptr  devicePtr;
-    unsigned int bufferPitch;
-    unsigned int bufferHeight;
-} pic_context_nvdec_t;
-
-#define NVDEC_PICCONTEXT_FROM_PICCTX(pic_ctx)  \
-    container_of(pic_ctx, pic_context_nvdec_t, ctx)
+#ifdef __cplusplus
+}
+#endif
 
 #endif /* include-guard */


=====================================
modules/hw/nvdec/nvdec_gl.c
=====================================
@@ -32,6 +32,7 @@
 #include <vlc_plugin.h>
 
 #include "nvdec_fmt.h"
+#include "nvdec_priv.h"
 
 #include "../../video_output/opengl/interop.h"
 
@@ -213,17 +214,7 @@ static int Open(vlc_object_t *obj)
         }
     }
 
-    vlc_fourcc_t render_chroma;
-    switch (interop->fmt_in.i_chroma)
-    {
-        case VLC_CODEC_NVDEC_OPAQUE_10B: render_chroma = VLC_CODEC_P010; break;
-        case VLC_CODEC_NVDEC_OPAQUE_16B: render_chroma = VLC_CODEC_P016; break;
-        case VLC_CODEC_NVDEC_OPAQUE_444:     render_chroma = VLC_CODEC_I444; break;
-        case VLC_CODEC_NVDEC_OPAQUE_444_16B: render_chroma = VLC_CODEC_I444_16L; break;
-        case VLC_CODEC_NVDEC_OPAQUE:
-        default:                         render_chroma = VLC_CODEC_NV12; break;
-    }
-
+    vlc_fourcc_t render_chroma = NVDECToVlcChroma(interop->fmt_in.i_chroma);
     switch (render_chroma)
     {
         case VLC_CODEC_P010:


=====================================
modules/hw/nvdec/nvdec_priv.h
=====================================
@@ -0,0 +1,69 @@
+/*****************************************************************************
+ * nvdec_priv.h : NVDEC private common code
+ *****************************************************************************
+ * Copyright © 2019-2023 VLC authors, VideoLAN and VideoLabs
+ *
+ * Authors: Steve Lhomme <robux4 at videolabs.io>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifndef VLC_VIDEOCHROMA_NVDEC_PRIV_H_
+#define VLC_VIDEOCHROMA_NVDEC_PRIV_H_
+
+#define FFNV_LOG_FUNC(logctx, msg, ...)        msg_Err((vlc_object_t*)logctx, msg, __VA_ARGS__)
+#define FFNV_DEBUG_LOG_FUNC(logctx, msg, ...)  msg_Dbg((vlc_object_t*)logctx, msg, __VA_ARGS__)
+
+#include <ffnvcodec/dynlink_loader.h>
+
+typedef struct {
+
+    CudaFunctions  *cudaFunctions;
+    CUcontext      cuCtx;
+
+} decoder_device_nvdec_t;
+
+static inline decoder_device_nvdec_t *GetNVDECOpaqueDevice(vlc_decoder_device *device)
+{
+    if (device == NULL || device->type != VLC_DECODER_DEVICE_NVDEC)
+        return NULL;
+    return device->opaque;
+}
+
+static inline int CudaCheckErr(vlc_object_t *obj, CudaFunctions *cudaFunctions, CUresult result, const char *psz_func)
+{
+    if (unlikely(result != CUDA_SUCCESS)) {
+        const char *psz_err, *psz_err_str;
+        cudaFunctions->cuGetErrorName(result, &psz_err);
+        cudaFunctions->cuGetErrorString(result, &psz_err_str);
+        msg_Err(obj, "%s failed: %s (%s)", psz_func, psz_err_str, psz_err);
+        return VLC_EGENERIC;
+    }
+    return VLC_SUCCESS;
+}
+
+/* for VLC_CODEC_NVDEC_OPAQUE / VLC_CODEC_NVDEC_OPAQUE_16B */
+typedef struct
+{
+    picture_context_t ctx;
+    CUdeviceptr  devicePtr;
+    unsigned int bufferPitch;
+    unsigned int bufferHeight;
+} pic_context_nvdec_t;
+
+#define NVDEC_PICCONTEXT_FROM_PICCTX(pic_ctx)  \
+    container_of(pic_ctx, pic_context_nvdec_t, ctx)
+
+#endif /* include-guard */


=====================================
modules/video_output/Makefile.am
=====================================
@@ -220,6 +220,9 @@ else
 libdirect3d11_plugin_la_LIBADD += -ld3d11
 libdirect3d11_plugin_la_LIBADD += -ld3dcompiler_47
 endif
+if HAVE_NVDEC
+libdirect3d11_plugin_la_SOURCES += hw/nvdec/nvdec_fmt.h
+endif
 libdirect3d11_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(voutdir)'
 vout_LTLIBRARIES += $(LTLIBdirect3d11)
 EXTRA_LTLIBRARIES += libdirect3d11_plugin.la


=====================================
modules/video_output/win32/direct3d11.cpp
=====================================
@@ -40,6 +40,7 @@
 #include <new>
 
 #include "../../video_chroma/d3d11_fmt.h"
+#include "../../hw/nvdec/nvdec_fmt.h"
 
 #include "d3d11_quad.h"
 #include "d3d11_shaders.h"
@@ -907,58 +908,32 @@ static int SetupOutputFormat(vout_display_t *vd, video_format_t *fmt, vlc_video_
     {
         uint8_t bits_per_channel;
         uint8_t widthDenominator, heightDenominator;
-        switch (fmt->i_chroma)
+        vlc_fourcc_t cpu_chroma;
+        if (is_d3d11_opaque(fmt->i_chroma))
+            cpu_chroma = DxgiFormatFourcc(vtcx_sys->format);
+        else if (is_nvdec_opaque(fmt->i_chroma))
+            cpu_chroma = NVDECToVlcChroma(fmt->i_chroma);
+        else
+            cpu_chroma = fmt->i_chroma;
+
+        const auto *p_format = vlc_fourcc_GetChromaDescription(cpu_chroma);
+        if (unlikely(p_format == NULL || p_format->plane_count == 0))
         {
-        case VLC_CODEC_D3D11_OPAQUE:
-        case VLC_CODEC_NVDEC_OPAQUE:
-            bits_per_channel = 8;
-            widthDenominator = heightDenominator = 2;
-            break;
-        case VLC_CODEC_D3D11_OPAQUE_RGBA:
-        case VLC_CODEC_D3D11_OPAQUE_BGRA:
             bits_per_channel = 8;
-            widthDenominator = heightDenominator = 1;
-            break;
-        case VLC_CODEC_D3D11_OPAQUE_10B:
-        case VLC_CODEC_NVDEC_OPAQUE_10B:
-            bits_per_channel = 10;
-            widthDenominator = heightDenominator = 2;
-            break;
-        case VLC_CODEC_NVDEC_OPAQUE_16B:
-            bits_per_channel = 16;
             widthDenominator = heightDenominator = 2;
-            break;
-        case VLC_CODEC_NVDEC_OPAQUE_444:
-            bits_per_channel = 8;
-            widthDenominator = heightDenominator = 1;
-            break;
-        case VLC_CODEC_NVDEC_OPAQUE_444_16B:
-            bits_per_channel = 16;
+        }
+        else
+        {
+            bits_per_channel = p_format->pixel_bits /
+                               (p_format->plane_count==1 ? p_format->pixel_size : 1);
             widthDenominator = heightDenominator = 1;
-            break;
-        default:
+            for (size_t i=0; i<p_format->plane_count; i++)
             {
-                const auto *p_format = vlc_fourcc_GetChromaDescription(fmt->i_chroma);
-                if (p_format == NULL)
-                {
-                    bits_per_channel = 8;
-                    widthDenominator = heightDenominator = 2;
-                }
-                else
-                {
-                    bits_per_channel = p_format->pixel_bits == 0 ? 8 : p_format->pixel_bits /
-                                                                   (p_format->plane_count==1 ? p_format->pixel_size : 1);
-                    widthDenominator = heightDenominator = 1;
-                    for (size_t i=0; i<p_format->plane_count; i++)
-                    {
-                        if (widthDenominator < p_format->p[i].w.den)
-                            widthDenominator = p_format->p[i].w.den;
-                        if (heightDenominator < p_format->p[i].h.den)
-                            heightDenominator = p_format->p[1].h.den;
-                    }
-                }
+                if (widthDenominator < p_format->p[i].w.den)
+                    widthDenominator = p_format->p[i].w.den;
+                if (heightDenominator < p_format->p[i].h.den)
+                    heightDenominator = p_format->p[1].h.den;
             }
-            break;
         }
 
         /* look for a decoder format that can be decoded but not used in shaders */



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/5fb07a80df49c12a565c3d410518718f96e12543...13898c11fe9fda58417a449f367c098b1e4b9978

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/5fb07a80df49c12a565c3d410518718f96e12543...13898c11fe9fda58417a449f367c098b1e4b9978
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list