[vlc-devel] [PATCH 2/6] direct3d11: pass the whitepoint and colorspace matrices to the RGB pixel shader

Steve Lhomme robux4 at videolabs.io
Mon Feb 6 15:06:20 CET 2017


Now all pixel shaders are given the same constant buffers

--
replaces https://patches.videolan.org/patch/15375/
* base the RGB detection on the quad config, not the main config
---
 modules/video_output/win32/direct3d11.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index 7edbeb0..90c35e8 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -305,6 +305,7 @@ static const char* globPixelShaderDefault = "\
     float WhitePointY;\
     float WhitePointZ;\
     float whitePadding;\
+    float4x4 Colorspace;\
   };\
   Texture2D shaderTexture[" STRINGIZE(D3D11_MAX_SHADER_VIEW) "];\
   SamplerState SampleType;\
@@ -320,8 +321,11 @@ static const char* globPixelShaderDefault = "\
     float4 rgba; \
     \
     rgba = shaderTexture[0].Sample(SampleType, In.Texture);\
+    rgba.x += WhitePointX;\
+    rgba.y += WhitePointY;\
+    rgba.z += WhitePointZ;\
     rgba.a = rgba.a * Opacity;\
-    return rgba; \
+    return saturate(mul(rgba, Colorspace));\
   }\
 ";
 
@@ -1958,6 +1962,9 @@ static int AllocQuad(vout_display_t *vd, const video_format_t *fmt, d3d_quad_t *
     vout_display_sys_t *sys = vd->sys;
     D3D11_MAPPED_SUBRESOURCE mappedResource;
     HRESULT hr;
+    const bool RGB_shader = cfg->resourceFormat[0] != DXGI_FORMAT_R8_UNORM &&
+        cfg->resourceFormat[0] != DXGI_FORMAT_R16_UNORM &&
+        fmt->i_chroma != VLC_CODEC_YUYV;
 
     /* pixel shader constant buffer */
     PS_CONSTANT_BUFFER defaultConstants = {
@@ -1979,7 +1986,15 @@ static int AllocQuad(vout_display_t *vd, const video_format_t *fmt, d3d_quad_t *
 
 #define FULL_TO_STUDIO_SHIFT (16.f / 256.f)
     FLOAT WHITE_POINT_D65_TO_FULL[4] = { -FULL_TO_STUDIO_SHIFT, -0.5f, -0.5f, 1.f };
+    if (RGB_shader)
+        WHITE_POINT_D65_TO_FULL[0] = WHITE_POINT_D65_TO_FULL[1] = WHITE_POINT_D65_TO_FULL[2] = 0.f;
 
+    FLOAT COLORSPACE_RGB_FULL[4 * 4] = {
+        1.f, 0.f, 0.f, 0.f,
+        0.f, 1.f, 0.f, 0.f,
+        0.f, 0.f, 1.f, 0.f,
+        0.f, 0.f, 0.f, 1.f,
+    };
     FLOAT COLORSPACE_BT601_TO_FULL[4*4] = {
         1.164383561643836f,                 0.f,  1.596026785714286f, 0.f,
         1.164383561643836f, -0.391762290094914f, -0.812967647237771f, 0.f,
@@ -2002,6 +2017,9 @@ static int AllocQuad(vout_display_t *vd, const video_format_t *fmt, d3d_quad_t *
 
     PS_COLOR_TRANSFORM colorspace;
     FLOAT *ppColorspace;
+    if (RGB_shader)
+        ppColorspace = COLORSPACE_RGB_FULL;
+    else
     switch (fmt->space){
         case COLOR_SPACE_BT709:
             ppColorspace = COLORSPACE_BT709_TO_FULL;
-- 
2.10.2



More information about the vlc-devel mailing list