[vlc-devel] [PATCH] d3d11: display only the left eye of stereo video

Adrien Maglo magsoft at videolan.org
Tue Nov 14 14:50:41 CET 2017


This allows to display an usable view of 360 stereo video.
---
 modules/video_output/win32/direct3d11.c | 63 +++++++++++++++++++++++++--------
 1 file changed, 48 insertions(+), 15 deletions(-)

diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index 5a105cc4a0..9e1cca7043 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -192,7 +192,10 @@ typedef struct d3d_vertex_t {
 
 typedef struct {
     FLOAT Opacity;
-    FLOAT opacityPadding[3];
+    FLOAT StereoOffsets[2];
+    FLOAT padding1;
+    FLOAT StereoCoefs[2];
+    FLOAT padding2[2];
 } PS_CONSTANT_BUFFER;
 
 typedef struct {
@@ -309,7 +312,10 @@ static const char* globPixelShaderDefault = "\
   cbuffer PS_CONSTANT_BUFFER : register(b0)\
   {\
     float Opacity;\
-    float opacityPadding[3];\
+    float2 StereoOffsets;\
+    float padding1;\
+    float2 StereoCoefs;\
+    float padding2[2];\
   };\
   cbuffer PS_COLOR_TRANSFORM : register(b1)\
   {\
@@ -375,6 +381,10 @@ static const char* globPixelShaderDefault = "\
   {\
     float4 sample;\
     \
+    float3 texCoord;\
+    texCoord.x = In.Texture.x * StereoCoefs.x + StereoOffsets.x;\
+    texCoord.y = In.Texture.y * StereoCoefs.y + StereoOffsets.y;\
+    texCoord.z = 0;\
     %s /* sampling routine in sample */\
     float4 rgba = mul(mul(sample, WhitePoint), Colorspace);\
     float opacity = rgba.a * Opacity;\
@@ -1826,15 +1836,15 @@ static HRESULT CompilePixelShader(vout_display_t *vd, const d3d_format_t *format
     case DXGI_FORMAT_NV12:
     case DXGI_FORMAT_P010:
         psz_sampler =
-                "sample.x  = shaderTexture[0].Sample(SampleType, In.Texture).x;\
-                sample.yz = shaderTexture[1].Sample(SampleType, In.Texture).xy;\
+                "sample.x  = shaderTexture[0].Sample(SampleType, texCoord).x;\
+                sample.yz = shaderTexture[1].Sample(SampleType, texCoord).xy;\
                 sample.a  = 1;";
         break;
     case DXGI_FORMAT_YUY2:
         psz_sampler =
-                "sample.x  = shaderTexture[0].Sample(SampleType, In.Texture).x;\
-                sample.y  = shaderTexture[0].Sample(SampleType, In.Texture).y;\
-                sample.z  = shaderTexture[0].Sample(SampleType, In.Texture).a;\
+                "sample.x  = shaderTexture[0].Sample(SampleType, texCoord).x;\
+                sample.y  = shaderTexture[0].Sample(SampleType, texCoord).y;\
+                sample.z  = shaderTexture[0].Sample(SampleType, texCoord).a;\
                 sample.a  = 1;";
         break;
     case DXGI_FORMAT_R8G8B8A8_UNORM:
@@ -1842,13 +1852,13 @@ static HRESULT CompilePixelShader(vout_display_t *vd, const d3d_format_t *format
     case DXGI_FORMAT_B8G8R8X8_UNORM:
     case DXGI_FORMAT_B5G6R5_UNORM:
         psz_sampler =
-                "sample = shaderTexture[0].Sample(SampleType, In.Texture);";
+                "sample = shaderTexture[0].Sample(SampleType, texCoord);";
         break;
     case DXGI_FORMAT_UNKNOWN:
         psz_sampler =
-               "sample.x  = shaderTexture[0].Sample(SampleType, In.Texture).x;\
-                sample.y  = shaderTexture[1].Sample(SampleType, In.Texture).x;\
-                sample.z  = shaderTexture[2].Sample(SampleType, In.Texture).x;\
+               "sample.x  = shaderTexture[0].Sample(SampleType, texCoord).x;\
+                sample.y  = shaderTexture[1].Sample(SampleType, texCoord).x;\
+                sample.z  = shaderTexture[2].Sample(SampleType, texCoord).x;\
                 sample.a  = 1;";
         break;
     default:
@@ -2628,6 +2638,26 @@ static int SetupQuad(vout_display_t *vd, const video_format_t *fmt, d3d_quad_t *
     PS_CONSTANT_BUFFER defaultConstants = {
       .Opacity = 1,
     };
+
+    switch (fmt->multiview_mode)
+    {
+    case MULTIVIEW_STEREO_TB:
+        // Left eye.
+        defaultConstants.StereoCoefs[0] = 1; defaultConstants.StereoCoefs[1] = 0.5;
+        defaultConstants.StereoOffsets[0] = 0; defaultConstants.StereoOffsets[1] = 0;
+        break;
+    case MULTIVIEW_STEREO_SBS:
+        // Left eye.
+        defaultConstants.StereoCoefs[0] = 0.5; defaultConstants.StereoCoefs[1] = 1;
+        defaultConstants.StereoOffsets[0] = 0; defaultConstants.StereoOffsets[1] = 0;
+        break;
+    default:
+        // Everything
+        defaultConstants.StereoCoefs[0] = 1; defaultConstants.StereoCoefs[1] = 1;
+        defaultConstants.StereoOffsets[0] = 0; defaultConstants.StereoOffsets[1] = 0;
+        break;
+    }
+
     static_assert((sizeof(PS_CONSTANT_BUFFER)%16)==0,"Constant buffers require 16-byte alignment");
     D3D11_BUFFER_DESC constantDesc = {
         .Usage = D3D11_USAGE_DYNAMIC,
@@ -2882,15 +2912,14 @@ static void DestroyPictureQuad(picture_t *p_picture)
     free( p_picture );
 }
 
-static void UpdateQuadOpacity(vout_display_t *vd, const d3d_quad_t *quad, float opacity)
+static void UpdatePSConstantBuffer(vout_display_t *vd, const d3d_quad_t *quad, PS_CONSTANT_BUFFER *psCstBuf)
 {
     vout_display_sys_t *sys = vd->sys;
     D3D11_MAPPED_SUBRESOURCE mappedResource;
 
     HRESULT hr = ID3D11DeviceContext_Map(sys->d3dcontext, (ID3D11Resource *)quad->pPixelShaderConstants[0], 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
     if (SUCCEEDED(hr)) {
-        FLOAT *dst_data = mappedResource.pData;
-        *dst_data = opacity;
+        memcpy(mappedResource.pData, psCstBuf, sizeof(PS_CONSTANT_BUFFER));
         ID3D11DeviceContext_Unmap(sys->d3dcontext, (ID3D11Resource *)quad->pPixelShaderConstants[0], 0);
     }
     else {
@@ -3024,7 +3053,11 @@ static int Direct3D11MapSubpicture(vout_display_t *vd, int *subpicture_region_co
         quad->cropViewport.TopLeftX = sys->sys.rect_dest.left + (FLOAT) r->i_x * RECTWidth(sys->sys.rect_dest) / subpicture->i_original_picture_width;
         quad->cropViewport.TopLeftY = sys->sys.rect_dest.top  + (FLOAT) r->i_y * RECTHeight(sys->sys.rect_dest) / subpicture->i_original_picture_height;
 
-        UpdateQuadOpacity(vd, quad, r->i_alpha / 255.0f );
+        PS_CONSTANT_BUFFER psCstBuf;
+        psCstBuf.Opacity = r->i_alpha / 255.f;
+        psCstBuf.StereoCoefs[0] = 1.f; psCstBuf.StereoCoefs[1] = 1.f;
+        psCstBuf.StereoOffsets[0] = 0.f; psCstBuf.StereoOffsets[1] = 0.f;
+        UpdatePSConstantBuffer(vd, quad, &psCstBuf);
     }
     return VLC_SUCCESS;
 }
-- 
2.14.1



More information about the vlc-devel mailing list