[vlc-commits] direct3d11: use a function to allocate the shader resource views

Steve Lhomme git at videolan.org
Wed Feb 8 14:46:01 CET 2017


vlc | branch: master | Steve Lhomme <robUx4 at videolabs.io> | Wed Feb  8 14:26:55 2017 +0100| [0064f7996874b7d1343d29768993c812a84fda34] | committer: Jean-Baptiste Kempf

direct3d11: use a function to allocate the shader resource views

Based on the d3d_format_t matching the texture format.

Allow targetting a particular slice index in the texture slice array.

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 modules/video_output/win32/direct3d11.c | 63 +++++++++++++++++++++------------
 1 file changed, 40 insertions(+), 23 deletions(-)

diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index c50d815..dcfcf38 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -603,6 +603,45 @@ static const d3d_format_t *GetOutputFormat(vout_display_t *vd, vlc_fourcc_t i_sr
     return NULL;
 }
 
+/* map texture planes to resource views */
+static int AllocateShaderView(vout_display_t *vd, const d3d_format_t *format, ID3D11Texture2D *texture,
+                              int slice_index, ID3D11ShaderResourceView *resourceView[2])
+{
+    HRESULT hr;
+    vout_display_sys_t *sys = vd->sys;
+    D3D11_SHADER_RESOURCE_VIEW_DESC resviewDesc = {
+        .Format = format->resourceFormat[0],
+    };
+    resviewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
+    resviewDesc.Texture2D.MipLevels = 1;
+
+    hr = ID3D11Device_CreateShaderResourceView(sys->d3ddevice, (ID3D11Resource *)texture, &resviewDesc, &resourceView[0]);
+    if (FAILED(hr)) {
+        msg_Err(vd, "Could not Create the Y/RGB Texture ResourceView slice %d. (hr=0x%lX)", slice_index, hr);
+        goto error;
+    }
+
+    resourceView[1] = NULL;
+    if( format->resourceFormat[1] )
+    {
+        resviewDesc.Format = format->resourceFormat[1];
+        hr = ID3D11Device_CreateShaderResourceView(sys->d3ddevice, (ID3D11Resource *)texture, &resviewDesc, &resourceView[1]);
+        if (FAILED(hr)) {
+            msg_Err(vd, "Could not Create the UV Texture ResourceView slice %d. (hr=0x%lX)", slice_index, hr);
+            goto error;
+        }
+    }
+
+    return VLC_SUCCESS;
+error:
+    if (resourceView[0]) {
+        ID3D11ShaderResourceView_Release(resourceView[0]);
+        resourceView[0] = NULL;
+    }
+    resourceView[1] = NULL;
+    return VLC_EGENERIC;
+}
+
 static picture_pool_t *Pool(vout_display_t *vd, unsigned pool_size)
 {
     if ( vd->sys->sys.pool != NULL )
@@ -2032,30 +2071,8 @@ static int AllocQuad(vout_display_t *vd, const video_format_t *fmt, d3d_quad_t *
         goto error;
     }
 
-    /* map texture planes to resource views */
-    D3D11_SHADER_RESOURCE_VIEW_DESC resviewDesc;
-    memset(&resviewDesc, 0, sizeof(resviewDesc));
-    resviewDesc.Format = cfg->resourceFormat[0];
-    resviewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
-    resviewDesc.Texture2D.MipLevels = texDesc.MipLevels;
-
-    hr = ID3D11Device_CreateShaderResourceView(sys->d3ddevice, (ID3D11Resource *)quad->pTexture, &resviewDesc, &quad->picSys.resourceView[0]);
-    if (FAILED(hr)) {
-        msg_Err(vd, "Could not Create the Y/RGB D3d11 Texture ResourceView. (hr=0x%lX)", hr);
+    if (AllocateShaderView(vd, cfg, quad->pTexture, 0, quad->picSys.resourceView) != VLC_SUCCESS)
         goto error;
-    }
-
-    if( cfg->resourceFormat[1] )
-    {
-        resviewDesc.Format = cfg->resourceFormat[1];
-        hr = ID3D11Device_CreateShaderResourceView(sys->d3ddevice, (ID3D11Resource *)quad->pTexture, &resviewDesc, &quad->picSys.resourceView[1]);
-        if (FAILED(hr)) {
-            msg_Err(vd, "Could not Create the UV D3d11 Texture ResourceView. (hr=0x%lX)", hr);
-            goto error;
-        }
-    }
-    else
-        quad->picSys.resourceView[1] = NULL;
 
     if ( d3dpixelShader != NULL )
     {



More information about the vlc-commits mailing list