[vlc-commits] direct3d11: move the hardcoded DXGI colorimetry list to the swapchain

Steve Lhomme git at videolan.org
Thu May 9 15:31:11 CEST 2019


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Thu May  9 11:41:18 2019 +0200| [c4262d2649122b95ebfc3daa2c5f17a06b71cda6] | committer: Steve Lhomme

direct3d11: move the hardcoded DXGI colorimetry list to the swapchain

The rendering can use any values, just a few select subsets

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c4262d2649122b95ebfc3daa2c5f17a06b71cda6
---

 modules/video_output/win32/d3d11_quad.c    |  4 +--
 modules/video_output/win32/d3d11_shaders.c | 10 +++---
 modules/video_output/win32/d3d11_shaders.h | 20 +++---------
 modules/video_output/win32/direct3d11.c    | 50 ++++++++++++++++++++++++------
 4 files changed, 51 insertions(+), 33 deletions(-)

diff --git a/modules/video_output/win32/d3d11_quad.c b/modules/video_output/win32/d3d11_quad.c
index 0e12e29060..d51781fc96 100644
--- a/modules/video_output/win32/d3d11_quad.c
+++ b/modules/video_output/win32/d3d11_quad.c
@@ -1040,10 +1040,10 @@ int D3D11_SetupQuad(vlc_object_t *o, d3d11_device_t *d3d_dev, const video_format
 
     memcpy(colorspace.Colorspace, ppColorspace, sizeof(colorspace.Colorspace));
 
-    if (fmt->primaries != displayFormat->colorspace->primaries)
+    if (fmt->primaries != displayFormat->primaries)
     {
         GetPrimariesTransform(colorspace.Primaries, fmt->primaries,
-                              displayFormat->colorspace->primaries);
+                              displayFormat->primaries);
     }
 
     ShaderUpdateConstants(o, d3d_dev, quad, PS_CONST_COLORSPACE, &colorspace);
diff --git a/modules/video_output/win32/d3d11_shaders.c b/modules/video_output/win32/d3d11_shaders.c
index b24f0eb450..5150189602 100644
--- a/modules/video_output/win32/d3d11_shaders.c
+++ b/modules/video_output/win32/d3d11_shaders.c
@@ -423,7 +423,7 @@ HRESULT D3D11_CompilePixelShader(vlc_object_t *o, d3d11_handle_t *hd3d, bool leg
 
     video_transfer_func_t src_transfer;
 
-    if (transfer != display->colorspace->transfer)
+    if (transfer != display->transfer)
     {
         /* we need to go in linear mode */
         switch (transfer)
@@ -466,7 +466,7 @@ HRESULT D3D11_CompilePixelShader(vlc_object_t *o, d3d11_handle_t *hd3d, bool leg
                 break;
         }
 
-        switch (display->colorspace->transfer)
+        switch (display->transfer)
         {
             case TRANSFER_FUNC_SRGB:
                 if (src_transfer == TRANSFER_FUNC_LINEAR)
@@ -502,12 +502,12 @@ HRESULT D3D11_CompilePixelShader(vlc_object_t *o, d3d11_handle_t *hd3d, bool leg
                     msg_Warn(o, "don't know how to transfer from %d to SMPTE ST 2084", src_transfer);
                 break;
             default:
-                msg_Warn(o, "don't know how to transfer from %d to %d", src_transfer, display->colorspace->transfer);
+                msg_Warn(o, "don't know how to transfer from %d to %d", src_transfer, display->transfer);
                 break;
         }
     }
 
-    if (display->colorspace->primaries != primaries)
+    if (display->primaries != primaries)
     {
         switch (primaries)
         {
@@ -526,7 +526,7 @@ HRESULT D3D11_CompilePixelShader(vlc_object_t *o, d3d11_handle_t *hd3d, bool leg
     }
 
     int range_adjust = 0;
-    if (display->colorspace->b_full_range) {
+    if (display->b_full_range) {
         if (!src_full_range)
             range_adjust = 1; /* raise the source to full range */
     } else {
diff --git a/modules/video_output/win32/d3d11_shaders.h b/modules/video_output/win32/d3d11_shaders.h
index 501410a2d5..5af23b3943 100644
--- a/modules/video_output/win32/d3d11_shaders.h
+++ b/modules/video_output/win32/d3d11_shaders.h
@@ -30,23 +30,11 @@
 #define DEFAULT_SRGB_BRIGHTNESS    100
 #define MAX_PQ_BRIGHTNESS        10000
 
-typedef enum video_color_axis {
-    COLOR_AXIS_RGB,
-    COLOR_AXIS_YCBCR,
-} video_color_axis;
-
-typedef struct {
-    DXGI_COLOR_SPACE_TYPE   dxgi;
-    const char              *name;
-    video_color_axis        axis;
-    video_color_primaries_t primaries;
-    video_transfer_func_t   transfer;
-    video_color_space_t     color;
-    bool                    b_full_range;
-} dxgi_color_space;
-
 typedef struct {
-    const dxgi_color_space   *colorspace;
+    video_color_primaries_t  primaries;
+    video_transfer_func_t    transfer;
+    video_color_space_t      color;
+    bool                     b_full_range;
     unsigned                 luminance_peak;
     const d3d_format_t       *pixelFormat;
 } display_info_t;
diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index cedbceffc6..b0c60a32a7 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -88,11 +88,28 @@ vlc_module_begin ()
     set_callbacks(Open, Close)
 vlc_module_end ()
 
+typedef enum video_color_axis {
+    COLOR_AXIS_RGB,
+    COLOR_AXIS_YCBCR,
+} video_color_axis;
+
+typedef struct {
+    DXGI_COLOR_SPACE_TYPE   dxgi;
+    const char              *name;
+    video_color_axis        axis;
+    video_color_primaries_t primaries;
+    video_transfer_func_t   transfer;
+    video_color_space_t     color;
+    bool                    b_full_range;
+} dxgi_color_space;
+
 struct d3d11_local_swapchain
 {
     vlc_object_t           *obj;
     d3d11_device_t         d3d_dev;
 
+    const dxgi_color_space *colorspace;
+
     HWND                   swapchainHwnd;
     IDXGISwapChain1        *dxgiswapChain;   /* DXGI 1.2 swap chain */
     IDXGISwapChain4        *dxgiswapChain4;  /* DXGI 1.5 for HDR metadata */
@@ -171,6 +188,18 @@ static int Control(vout_display_t *, int, va_list);
 
 static void SelectSwapchainColorspace(vout_display_t *vd, const struct direct3d_cfg_t *cfg);
 
+static int UpdateDisplayFormat(vout_display_t *vd, struct output_cfg_t *out)
+{
+    vout_display_sys_t *sys = vd->sys;
+
+    sys->display.color = out->colorspace;
+    sys->display.transfer = out->transfer;
+    sys->display.primaries = out->primaries;
+    sys->display.b_full_range = out->full_range;
+
+    return VLC_SUCCESS;
+}
+
 static int QueryDisplayFormat(vout_display_t *vd, const video_format_t *fmt)
 {
     vout_display_sys_t *sys = vd->sys;
@@ -221,7 +250,7 @@ static int QueryDisplayFormat(vout_display_t *vd, const video_format_t *fmt)
         return VLC_EGENERIC;
     }
 
-    return VLC_SUCCESS;
+    return UpdateDisplayFormat(vd, &out);
 }
 
 static void UpdateSize(vout_display_t *vd)
@@ -499,13 +528,14 @@ static int SetupWindowLessOutput(vout_display_t *vd)
 static bool LocalSwapchainUpdateOutput( void *opaque, const struct direct3d_cfg_t *cfg, struct output_cfg_t *out )
 {
     vout_display_t *vd = opaque;
+    struct d3d11_local_swapchain *display = &vd->sys->internal_swapchain;
     if ( !UpdateSwapchain( vd, cfg ) )
         return false;
     out->surface_format = vd->sys->display.pixelFormat->formatTexture;
-    out->full_range     = vd->sys->display.colorspace->b_full_range;
-    out->colorspace     = vd->sys->display.colorspace->color;
-    out->primaries      = vd->sys->display.colorspace->primaries;
-    out->transfer       = vd->sys->display.colorspace->transfer;
+    out->full_range     = display->colorspace->b_full_range;
+    out->colorspace     = display->colorspace->color;
+    out->primaries      = display->colorspace->primaries;
+    out->transfer       = display->colorspace->transfer;
     return true;
 }
 
@@ -1113,7 +1143,7 @@ static void SelectSwapchainColorspace(vout_display_t *vd, const struct direct3d_
     int score, best_score = 0;
     UINT support;
     IDXGISwapChain3 *dxgiswapChain3 = NULL;
-    sys->display.colorspace = &color_spaces[0];
+    display->colorspace = &color_spaces[0];
 
     hr = IDXGISwapChain_QueryInterface( display->dxgiswapChain, &IID_IDXGISwapChain3, (void **)&dxgiswapChain3);
     if (FAILED(hr)) {
@@ -1193,14 +1223,14 @@ static void SelectSwapchainColorspace(vout_display_t *vd, const struct direct3d_
     hr = IDXGISwapChain3_SetColorSpace1(dxgiswapChain3, color_spaces[best].dxgi);
     if (SUCCEEDED(hr))
     {
-        sys->display.colorspace = &color_spaces[best];
-        msg_Dbg(display->obj, "using colorspace %s", sys->display.colorspace->name);
+        display->colorspace = &color_spaces[best];
+        msg_Dbg(display->obj, "using colorspace %s", display->colorspace->name);
     }
     else
-        msg_Err(display->obj, "Failed to set colorspace %s. (hr=0x%lX)", sys->display.colorspace->name, hr);
+        msg_Err(display->obj, "Failed to set colorspace %s. (hr=0x%lX)", display->colorspace->name, hr);
 done:
     /* guestimate the display peak luminance */
-    switch (sys->display.colorspace->transfer)
+    switch (display->colorspace->transfer)
     {
     case TRANSFER_FUNC_LINEAR:
     case TRANSFER_FUNC_SRGB:



More information about the vlc-commits mailing list