[vlc-commits] direct3d11: only clear the swapchain back buffer once

Steve Lhomme git at videolan.org
Mon May 28 13:25:39 CEST 2018


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Tue Jan  9 15:20:09 2018 +0100| [87e765d989e91b335d1da5d41e09c02fd92a3f1b] | committer: Steve Lhomme

direct3d11: only clear the swapchain back buffer once

If picture dimensions change, we'll update it

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

 modules/video_output/win32/direct3d11.c | 33 ++++++++++++++++++++-------------
 1 file changed, 20 insertions(+), 13 deletions(-)

diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index 5576e6fcfc..1f5f8bc9a8 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -102,7 +102,7 @@ struct vout_display_sys_t
 
     picture_sys_t            stagingSys;
 
-    ID3D11RenderTargetView   *d3drenderTargetView;
+    ID3D11RenderTargetView   *d3drenderTargetView[D3D11_MAX_SHADER_VIEW];
     ID3D11DepthStencilView   *d3ddepthStencilView;
 
     ID3D11InputLayout         *pVertexLayout;
@@ -486,9 +486,9 @@ static HRESULT UpdateBackBuffer(vout_display_t *vd)
     uint32_t i_height = RECTHeight(rect);
     D3D11_TEXTURE2D_DESC dsc = { 0 };
 
-    if (sys->d3drenderTargetView) {
+    if (sys->d3drenderTargetView[0]) {
         ID3D11Resource *res = NULL;
-        ID3D11RenderTargetView_GetResource(sys->d3drenderTargetView, &res);
+        ID3D11RenderTargetView_GetResource(sys->d3drenderTargetView[0], &res);
         if (res)
         {
             ID3D11Texture2D_GetDesc((ID3D11Texture2D*) res, &dsc);
@@ -499,9 +499,12 @@ static HRESULT UpdateBackBuffer(vout_display_t *vd)
     if (dsc.Width == i_width && dsc.Height == i_height)
         return S_OK; /* nothing changed */
 
-    if (sys->d3drenderTargetView) {
-        ID3D11RenderTargetView_Release(sys->d3drenderTargetView);
-        sys->d3drenderTargetView = NULL;
+    for (size_t i=0; i < D3D11_MAX_SHADER_VIEW; i++)
+    {
+        if (sys->d3drenderTargetView[i]) {
+            ID3D11RenderTargetView_Release(sys->d3drenderTargetView[i]);
+            sys->d3drenderTargetView[i] = NULL;
+        }
     }
     if (sys->d3ddepthStencilView) {
         ID3D11DepthStencilView_Release(sys->d3ddepthStencilView);
@@ -522,13 +525,16 @@ static HRESULT UpdateBackBuffer(vout_display_t *vd)
        return hr;
     }
 
-    hr = ID3D11Device_CreateRenderTargetView(sys->d3d_dev.d3ddevice, (ID3D11Resource *)pBackBuffer, NULL, &sys->d3drenderTargetView);
+    hr = D3D11_CreateRenderTargets( &sys->d3d_dev, (ID3D11Resource *)pBackBuffer,
+                                    sys->display.pixelFormat, sys->d3drenderTargetView );
     ID3D11Texture2D_Release(pBackBuffer);
     if (FAILED(hr)) {
         msg_Err(vd, "Failed to create the target view. (hr=0x%lX)", hr);
         return hr;
     }
 
+    D3D11_ClearRenderTargets( &sys->d3d_dev, sys->display.pixelFormat, sys->d3drenderTargetView );
+
     D3D11_TEXTURE2D_DESC deptTexDesc;
     memset(&deptTexDesc, 0,sizeof(deptTexDesc));
     deptTexDesc.ArraySize = 1;
@@ -904,6 +910,8 @@ static void Prepare(vout_display_t *vd, picture_t *picture,
         sys->d3dregions      = subpicture_regions;
     }
 
+    D3D11_ClearRenderTargets( &sys->d3d_dev, sys->display.pixelFormat, sys->d3drenderTargetView );
+
     if (picture->format.mastering.max_luminance)
     {
         D3D11_UpdateQuadLuminanceScale(vd, &sys->d3d_dev, &sys->picQuad, GetFormatLuminance(VLC_OBJECT(vd), &picture->format) / (float)sys->display.luminance_peak);
@@ -927,9 +935,6 @@ static void Prepare(vout_display_t *vd, picture_t *picture,
         }
     }
 
-    FLOAT blackRGBA[4] = {0.0f, 0.0f, 0.0f, 1.0f};
-    ID3D11DeviceContext_ClearRenderTargetView(sys->d3d_dev.d3dcontext, sys->d3drenderTargetView, blackRGBA);
-
     /* no ID3D11Device operations should come here */
 
     ID3D11DeviceContext_ClearDepthStencilView(sys->d3d_dev.d3dcontext, sys->d3ddepthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
@@ -1679,10 +1684,12 @@ static void Direct3D11DestroyResources(vout_display_t *vd)
         ID3D11VertexShader_Release(sys->projectionVSShader);
         sys->projectionVSShader = NULL;
     }
-    if (sys->d3drenderTargetView)
+    for (size_t i=0; i < D3D11_MAX_SHADER_VIEW; i++)
     {
-        ID3D11RenderTargetView_Release(sys->d3drenderTargetView);
-        sys->d3drenderTargetView = NULL;
+        if (sys->d3drenderTargetView[i]) {
+            ID3D11RenderTargetView_Release(sys->d3drenderTargetView[i]);
+            sys->d3drenderTargetView[i] = NULL;
+        }
     }
     if (sys->d3ddepthStencilView)
     {



More information about the vlc-commits mailing list