[vlc-commits] dxgi_fmt: add a function to fill black colors values for common render targets

Steve Lhomme git at videolan.org
Wed Feb 10 11:06:58 UTC 2021


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Fri Jan 29 08:03:59 2021 +0100| [aab42f50b6d72052e7736b8d618f83e5f60ad10b] | committer: Steve Lhomme

dxgi_fmt: add a function to fill black colors values for common render targets

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

 modules/video_chroma/dxgi_fmt.c            | 51 ++++++++++++++++++++++++++++++
 modules/video_chroma/dxgi_fmt.h            | 17 ++++++++++
 modules/video_output/win32/d3d11_shaders.c | 44 ++++++--------------------
 3 files changed, 77 insertions(+), 35 deletions(-)

diff --git a/modules/video_chroma/dxgi_fmt.c b/modules/video_chroma/dxgi_fmt.c
index 643dece81e..9597d93ccc 100644
--- a/modules/video_chroma/dxgi_fmt.c
+++ b/modules/video_chroma/dxgi_fmt.c
@@ -28,6 +28,8 @@
 
 #include "dxgi_fmt.h"
 
+#include <assert.h>
+
 typedef struct
 {
     const char   *name;
@@ -188,3 +190,52 @@ bool DxgiIsRGBFormat(const d3d_format_t *cfg)
            cfg->formatTexture != DXGI_FORMAT_Y410 &&
            cfg->formatTexture != DXGI_FORMAT_420_OPAQUE;
 }
+
+void DXGI_GetBlackColor( const d3d_format_t *pixelFormat,
+                         union DXGI_Color black[DXGI_MAX_RENDER_TARGET],
+                         size_t colors[DXGI_MAX_RENDER_TARGET] )
+{
+    static const union DXGI_Color blackY    = { .y = 0.0f };
+    static const union DXGI_Color blackUV   = { .u = 0.5f, .v = 0.5f };
+    static const union DXGI_Color blackRGBA = { .r = 0.0f, .g = 0.0f, .b = 0.0f, .a = 1.0f };
+    static const union DXGI_Color blackYUY2 = { .r = 0.0f, .g = 0.5f, .b = 0.0f, .a = 0.5f };
+    static const union DXGI_Color blackVUYA = { .r = 0.5f, .g = 0.5f, .b = 0.0f, .a = 1.0f };
+    static const union DXGI_Color blackY210 = { .r = 0.0f, .g = 0.5f, .b = 0.5f, .a = 0.0f };
+
+    static_assert(DXGI_MAX_RENDER_TARGET >= 2, "we need at least 2 RenderTargetView for NV12/P010");
+
+    switch (pixelFormat->formatTexture)
+    {
+    case DXGI_FORMAT_NV12:
+    case DXGI_FORMAT_P010:
+        colors[0] = 1; black[0] = blackY;
+        colors[1] = 2; black[1] = blackUV;
+        break;
+    case DXGI_FORMAT_R8G8B8A8_UNORM:
+    case DXGI_FORMAT_B8G8R8A8_UNORM:
+    case DXGI_FORMAT_B8G8R8X8_UNORM:
+    case DXGI_FORMAT_R10G10B10A2_UNORM:
+    case DXGI_FORMAT_B5G6R5_UNORM:
+        colors[0] = 4; black[0] = blackRGBA;
+        colors[1] = 0;
+        break;
+    case DXGI_FORMAT_YUY2:
+        colors[0] = 4; black[0] = blackYUY2;
+        colors[1] = 0;
+        break;
+    case DXGI_FORMAT_Y410:
+        colors[0] = 4; black[0] = blackVUYA;
+        colors[1] = 0;
+        break;
+    case DXGI_FORMAT_Y210:
+        colors[0] = 4; black[0] = blackY210;
+        colors[1] = 0;
+        break;
+    case DXGI_FORMAT_AYUV:
+        colors[0] = 4; black[0] = blackVUYA;
+        colors[1] = 0;
+        break;
+    default:
+        vlc_assert_unreachable();
+    }
+}
diff --git a/modules/video_chroma/dxgi_fmt.h b/modules/video_chroma/dxgi_fmt.h
index da9252d688..32b68ae445 100644
--- a/modules/video_chroma/dxgi_fmt.h
+++ b/modules/video_chroma/dxgi_fmt.h
@@ -66,4 +66,21 @@ bool DxgiIsRGBFormat(const d3d_format_t *);
 #define DXGI_CHROMA_CPU 1
 #define DXGI_CHROMA_GPU 2
 
+union DXGI_Color
+{
+    struct {
+        FLOAT r, g, b, a;
+    };
+    struct {
+        FLOAT y;
+    };
+    struct {
+        FLOAT u, v;
+    };
+    FLOAT array[4];
+};
+void DXGI_GetBlackColor( const d3d_format_t *,
+                         union DXGI_Color black[DXGI_MAX_RENDER_TARGET],
+                         size_t colors[DXGI_MAX_RENDER_TARGET] );
+
 #endif /* include-guard */
diff --git a/modules/video_output/win32/d3d11_shaders.c b/modules/video_output/win32/d3d11_shaders.c
index 4ce1b45687..39eef96ef4 100644
--- a/modules/video_output/win32/d3d11_shaders.c
+++ b/modules/video_output/win32/d3d11_shaders.c
@@ -134,43 +134,17 @@ HRESULT D3D11_CreateRenderTargets( d3d11_device_t *d3d_dev, ID3D11Resource *text
 void D3D11_ClearRenderTargets(d3d11_device_t *d3d_dev, const d3d_format_t *cfg,
                               ID3D11RenderTargetView *targets[DXGI_MAX_RENDER_TARGET])
 {
-    static const FLOAT blackY[1] = {0.0f};
-    static const FLOAT blackUV[2] = {0.5f, 0.5f};
-    static const FLOAT blackRGBA[4] = {0.0f, 0.0f, 0.0f, 1.0f};
-    static const FLOAT blackYUY2[4] = {0.0f, 0.5f, 0.0f, 0.5f};
-    static const FLOAT blackVUYA[4] = {0.5f, 0.5f, 0.0f, 1.0f};
-    static const FLOAT blackY210[4] = {0.0f, 0.5f, 0.5f, 0.0f};
+    union DXGI_Color black[DXGI_MAX_RENDER_TARGET];
+    size_t colorCount[DXGI_MAX_RENDER_TARGET];
+    DXGI_GetBlackColor(cfg, black, colorCount);
 
-    static_assert(DXGI_MAX_RENDER_TARGET >= 2, "we need at least 2 RenderTargetView for NV12/P010");
-
-    switch (cfg->formatTexture)
+    if (colorCount[0])
+    {
+        ID3D11DeviceContext_ClearRenderTargetView( d3d_dev->d3dcontext, targets[0], black[0].array);
+    }
+    if (colorCount[1])
     {
-    case DXGI_FORMAT_NV12:
-    case DXGI_FORMAT_P010:
-        ID3D11DeviceContext_ClearRenderTargetView( d3d_dev->d3dcontext, targets[0], blackY);
-        ID3D11DeviceContext_ClearRenderTargetView( d3d_dev->d3dcontext, targets[1], blackUV);
-        break;
-    case DXGI_FORMAT_R8G8B8A8_UNORM:
-    case DXGI_FORMAT_B8G8R8A8_UNORM:
-    case DXGI_FORMAT_B8G8R8X8_UNORM:
-    case DXGI_FORMAT_R10G10B10A2_UNORM:
-    case DXGI_FORMAT_B5G6R5_UNORM:
-        ID3D11DeviceContext_ClearRenderTargetView( d3d_dev->d3dcontext, targets[0], blackRGBA);
-        break;
-    case DXGI_FORMAT_YUY2:
-        ID3D11DeviceContext_ClearRenderTargetView( d3d_dev->d3dcontext, targets[0], blackYUY2);
-        break;
-    case DXGI_FORMAT_Y410:
-        ID3D11DeviceContext_ClearRenderTargetView( d3d_dev->d3dcontext, targets[0], blackVUYA);
-        break;
-    case DXGI_FORMAT_Y210:
-        ID3D11DeviceContext_ClearRenderTargetView( d3d_dev->d3dcontext, targets[0], blackY210);
-        break;
-    case DXGI_FORMAT_AYUV:
-        ID3D11DeviceContext_ClearRenderTargetView( d3d_dev->d3dcontext, targets[0], blackVUYA);
-        break;
-    default:
-        vlc_assert_unreachable();
+        ID3D11DeviceContext_ClearRenderTargetView( d3d_dev->d3dcontext, targets[1], black[1].array);
     }
 }
 



More information about the vlc-commits mailing list