[vlc-commits] direct3d11: handle the projection update via ShaderUpdateConstants()

Steve Lhomme git at videolan.org
Tue Sep 1 12:06:18 CEST 2020


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Mon Aug 31 14:21:15 2020 +0200| [1aff8a63571f82db418dd3d6947e8cf35a09bb4c] | committer: Steve Lhomme

direct3d11: handle the projection update via ShaderUpdateConstants()

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

 modules/video_output/win32/d3d11_quad.c    | 53 ++++++++++++++++++++----------
 modules/video_output/win32/d3d11_quad.h    |  2 +-
 modules/video_output/win32/d3d11_shaders.h |  1 +
 3 files changed, 37 insertions(+), 19 deletions(-)

diff --git a/modules/video_output/win32/d3d11_quad.c b/modules/video_output/win32/d3d11_quad.c
index 36abdfec86..6fff189ed7 100644
--- a/modules/video_output/win32/d3d11_quad.c
+++ b/modules/video_output/win32/d3d11_quad.c
@@ -598,21 +598,43 @@ bool D3D11_UpdateQuadPosition( vlc_object_t *o, d3d11_device_t *d3d_dev, d3d_qua
     return result;
 }
 
-static bool ShaderUpdateConstants(vlc_object_t *o, d3d11_device_t *d3d_dev, d3d_quad_t *quad, size_t index, void *new_buf)
+static bool ShaderUpdateConstants(vlc_object_t *o, d3d11_device_t *d3d_dev, d3d_quad_t *quad, int type, void *new_buf)
 {
+    ID3D11Resource *res;
+    switch (type)
+    {
+        case PS_CONST_LUMI_BOUNDS:
+            res = (ID3D11Resource *)quad->pPixelShaderConstants[PS_CONST_LUMI_BOUNDS];
+            break;
+        case PS_CONST_COLORSPACE:
+            res = (ID3D11Resource *)quad->pPixelShaderConstants[PS_CONST_COLORSPACE];
+            break;
+        case VS_CONST_VIEWPOINT:
+            res = (ID3D11Resource *)quad->pVertexShaderConstants;
+            break;
+    }
+
     D3D11_MAPPED_SUBRESOURCE mappedResource;
-    HRESULT hr = ID3D11DeviceContext_Map(d3d_dev->d3dcontext, (ID3D11Resource *)quad->pPixelShaderConstants[index], 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
-    if (FAILED(hr))
+    HRESULT hr = ID3D11DeviceContext_Map(d3d_dev->d3dcontext, res, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
+    if (unlikely(FAILED(hr)))
     {
         msg_Err(o, "Failed to lock the picture shader constants (hr=0x%lX)", hr);
         return false;
     }
 
-    if (index == PS_CONST_LUMI_BOUNDS)
-        memcpy(mappedResource.pData, new_buf,sizeof(PS_CONSTANT_BUFFER));
-    else
-        memcpy(mappedResource.pData, new_buf,sizeof(PS_COLOR_TRANSFORM));
-    ID3D11DeviceContext_Unmap(d3d_dev->d3dcontext, (ID3D11Resource *)quad->pPixelShaderConstants[index], 0);
+    switch (type)
+    {
+        case PS_CONST_LUMI_BOUNDS:
+            memcpy(mappedResource.pData, new_buf, sizeof(PS_CONSTANT_BUFFER));
+            break;
+        case PS_CONST_COLORSPACE:
+            memcpy(mappedResource.pData, new_buf, sizeof(PS_COLOR_TRANSFORM));
+            break;
+        case VS_CONST_VIEWPOINT:
+            memcpy(mappedResource.pData, new_buf, sizeof(VS_PROJECTION_CONST));
+            break;
+    }
+    ID3D11DeviceContext_Unmap(d3d_dev->d3dcontext, res, 0);
     return true;
 }
 
@@ -719,16 +741,11 @@ void (D3D11_UpdateViewpoint)(vlc_object_t *o, d3d11_device_t *d3d_dev, d3d_quad_
     vlc_viewpoint_t vp;
     vlc_viewpoint_reverse(&vp, viewpoint);
 
-    HRESULT hr;
-    D3D11_MAPPED_SUBRESOURCE mapped;
-    hr = ID3D11DeviceContext_Map(d3d_dev->d3dcontext, (ID3D11Resource *)quad->pVertexShaderConstants, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
-    if (SUCCEEDED(hr)) {
-        VS_PROJECTION_CONST *dst_data = mapped.pData;
-        getZoomMatrix(SPHERE_RADIUS * f_z, dst_data->Zoom);
-        getProjectionMatrix(f_sar, f_fovy, dst_data->Projection);
-        vlc_viewpoint_to_4x4(&vp, dst_data->View);
-    }
-    ID3D11DeviceContext_Unmap(d3d_dev->d3dcontext, (ID3D11Resource *)quad->pVertexShaderConstants, 0);
+    getZoomMatrix(SPHERE_RADIUS * f_z, quad->vertexConstants.Zoom);
+    getProjectionMatrix(f_sar, f_fovy, quad->vertexConstants.Projection);
+    vlc_viewpoint_to_4x4(&vp, quad->vertexConstants.View);
+
+    ShaderUpdateConstants(o, d3d_dev, quad, VS_CONST_VIEWPOINT, &quad->vertexConstants);
 }
 
 #undef D3D11_AllocateQuad
diff --git a/modules/video_output/win32/d3d11_quad.h b/modules/video_output/win32/d3d11_quad.h
index 57ab0ac7fe..f1a573aea3 100644
--- a/modules/video_output/win32/d3d11_quad.h
+++ b/modules/video_output/win32/d3d11_quad.h
@@ -30,7 +30,7 @@
 
 #define PS_CONST_LUMI_BOUNDS 0
 #define PS_CONST_COLORSPACE  1
-#define PS_CONST_COUNT       2
+#define VS_CONST_VIEWPOINT   2
 
 /* matches the D3D11_INPUT_ELEMENT_DESC we setup */
 typedef struct d3d_vertex_t {
diff --git a/modules/video_output/win32/d3d11_shaders.h b/modules/video_output/win32/d3d11_shaders.h
index 7712c3eff3..969b337a0b 100644
--- a/modules/video_output/win32/d3d11_shaders.h
+++ b/modules/video_output/win32/d3d11_shaders.h
@@ -99,6 +99,7 @@ typedef struct
     video_projection_mode_t   projection;
 
     PS_CONSTANT_BUFFER        shaderConstants;
+    VS_PROJECTION_CONST       vertexConstants;
 } d3d_quad_t;
 
 #define D3D11_MAX_RENDER_TARGET    2



More information about the vlc-commits mailing list