[vlc-devel] [PATCH 18/29] direct3d11: move the shader resource view in picture_sys_t

Steve Lhomme robux4 at videolabs.io
Thu Jan 19 11:10:53 CET 2017


So it can be set on textures coming from the decoder
---
 modules/codec/avcodec/d3d11va.c         |  1 +
 modules/video_chroma/d3d11_surface.c    |  3 ++-
 modules/video_output/win32/common.h     | 16 +++++++++++++--
 modules/video_output/win32/direct3d11.c | 35 +++++++++++----------------------
 4 files changed, 29 insertions(+), 26 deletions(-)

diff --git a/modules/codec/avcodec/d3d11va.c b/modules/codec/avcodec/d3d11va.c
index 7e858dd..4ce09ee 100644
--- a/modules/codec/avcodec/d3d11va.c
+++ b/modules/codec/avcodec/d3d11va.c
@@ -149,6 +149,7 @@ struct picture_sys_t
     ID3D11DeviceContext           *context;
     unsigned                      slice_index;
     ID3D11VideoProcessorInputView *inputView; /* when used as processor input */
+    ID3D11ShaderResourceView      *resourceView[2];
 };
 
 /* */
diff --git a/modules/video_chroma/d3d11_surface.c b/modules/video_chroma/d3d11_surface.c
index 92c1fe7..4f9171f 100644
--- a/modules/video_chroma/d3d11_surface.c
+++ b/modules/video_chroma/d3d11_surface.c
@@ -59,7 +59,8 @@ struct picture_sys_t
     ID3D11Texture2D               *texture;
     ID3D11DeviceContext           *context;
     unsigned                      slice_index;
-    HINSTANCE                     hd3d11_dll; /* TODO */
+    ID3D11VideoProcessorInputView *inputView; /* when used as processor input */
+    ID3D11ShaderResourceView      *resourceView[2];
 };
 
 struct filter_sys_t {
diff --git a/modules/video_output/win32/common.h b/modules/video_output/win32/common.h
index e88184d..a478762 100644
--- a/modules/video_output/win32/common.h
+++ b/modules/video_output/win32/common.h
@@ -52,6 +52,19 @@ typedef struct
     DXGI_FORMAT   resourceFormatUV;
 } d3d_quad_cfg_t;
 
+#ifdef HAVE_ID3D11VIDEODECODER
+/* VLC_CODEC_D3D11_OPAQUE */
+struct picture_sys_t
+{
+    ID3D11VideoDecoderOutputView  *decoder; /* may be NULL for pictures from the pool */
+    ID3D11Texture2D               *texture;
+    ID3D11DeviceContext           *context;
+    unsigned                      slice_index;
+    ID3D11VideoProcessorInputView *inputView; /* when used as processor input */
+    ID3D11ShaderResourceView      *resourceView[2];
+};
+#endif
+
 typedef struct
 {
     ID3D11Buffer              *pVertexBuffer;
@@ -60,11 +73,10 @@ typedef struct
     ID3D11Buffer              *pIndexBuffer;
     UINT                      indexCount;
     ID3D11Buffer              *pVertexShaderConstants;
+    picture_sys_t             picSys;
     ID3D11Texture2D           *pTexture;
     ID3D11Buffer              *pPixelShaderConstants[2];
     UINT                       PSConstantsCount;
-    ID3D11ShaderResourceView  *d3dresViewY;
-    ID3D11ShaderResourceView  *d3dresViewUV;
     ID3D11PixelShader         *d3dpixelShader;
     D3D11_VIEWPORT            cropViewport;
 } d3d_quad_t;
diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index 361f150..27bb51e 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -84,17 +84,6 @@ vlc_module_begin ()
     set_callbacks(Open, Close)
 vlc_module_end ()
 
-#ifdef HAVE_ID3D11VIDEODECODER
-/* VLC_CODEC_D3D11_OPAQUE */
-struct picture_sys_t
-{
-    ID3D11VideoDecoderOutputView  *decoder; /* may be NULL for pictures from the pool */
-    ID3D11Texture2D               *texture;
-    ID3D11DeviceContext           *context;
-    unsigned                      slice_index;
-};
-#endif
-
 /* internal picture_t pool  */
 typedef struct
 {
@@ -522,7 +511,7 @@ static picture_pool_t *Pool(vout_display_t *vd, unsigned pool_size)
     texDesc.SampleDesc.Count = 1;
     texDesc.MiscFlags = 0; //D3D11_RESOURCE_MISC_SHARED;
     texDesc.Usage = D3D11_USAGE_DEFAULT;
-    texDesc.BindFlags = D3D11_BIND_DECODER;
+    texDesc.BindFlags = D3D11_BIND_DECODER | D3D11_BIND_SHADER_RESOURCE;
     texDesc.CPUAccessFlags = 0;
 
     texDesc.ArraySize = pool_size;
@@ -1023,9 +1012,7 @@ static void DisplayD3DPicture(vout_display_sys_t *sys, d3d_quad_t *quad)
     ID3D11DeviceContext_PSSetShader(sys->d3dcontext, quad->d3dpixelShader, NULL, 0);
 
     ID3D11DeviceContext_PSSetConstantBuffers(sys->d3dcontext, 0, quad->PSConstantsCount, quad->pPixelShaderConstants);
-    ID3D11DeviceContext_PSSetShaderResources(sys->d3dcontext, 0, 1, &quad->d3dresViewY);
-    if( quad->d3dresViewUV )
-        ID3D11DeviceContext_PSSetShaderResources(sys->d3dcontext, 1, 1, &quad->d3dresViewUV);
+    ID3D11DeviceContext_PSSetShaderResources(sys->d3dcontext, 0, 2, &quad->picSys.resourceView[0]);
 
     ID3D11DeviceContext_RSSetViewports(sys->d3dcontext, 1, &quad->cropViewport);
 
@@ -2076,7 +2063,7 @@ static int AllocQuad(vout_display_t *vd, const video_format_t *fmt, d3d_quad_t *
     resviewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
     resviewDesc.Texture2D.MipLevels = texDesc.MipLevels;
 
-    hr = ID3D11Device_CreateShaderResourceView(sys->d3ddevice, (ID3D11Resource *)quad->pTexture, &resviewDesc, &quad->d3dresViewY);
+    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);
         goto error;
@@ -2085,12 +2072,14 @@ static int AllocQuad(vout_display_t *vd, const video_format_t *fmt, d3d_quad_t *
     if( cfg->resourceFormatUV )
     {
         resviewDesc.Format = cfg->resourceFormatUV;
-        hr = ID3D11Device_CreateShaderResourceView(sys->d3ddevice, (ID3D11Resource *)quad->pTexture, &resviewDesc, &quad->d3dresViewUV);
+        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 )
     {
@@ -2146,15 +2135,15 @@ static void ReleaseQuad(d3d_quad_t *quad)
         ID3D11Texture2D_Release(quad->pTexture);
         quad->pTexture = NULL;
     }
-    if (quad->d3dresViewY)
+    if (quad->picSys.resourceView[0])
     {
-        ID3D11ShaderResourceView_Release(quad->d3dresViewY);
-        quad->d3dresViewY = NULL;
+        ID3D11ShaderResourceView_Release(quad->picSys.resourceView[0]);
+        quad->picSys.resourceView[0] = NULL;
     }
-    if (quad->d3dresViewUV)
+    if (quad->picSys.resourceView[1])
     {
-        ID3D11ShaderResourceView_Release(quad->d3dresViewUV);
-        quad->d3dresViewUV = NULL;
+        ID3D11ShaderResourceView_Release(quad->picSys.resourceView[1]);
+        quad->picSys.resourceView[1] = NULL;
     }
     if (quad->d3dpixelShader)
     {
-- 
2.10.2



More information about the vlc-devel mailing list