[vlc-devel] [PATCH] direct3d11: use multiple texture slices instead of multiples textures

Steve Lhomme robux4 at videolabs.io
Mon Oct 3 17:45:37 CEST 2016


---
 modules/codec/avcodec/d3d11va.c         |  3 ++-
 modules/video_chroma/d3d11_surface.c    |  1 +
 modules/video_output/win32/direct3d11.c | 21 +++++++++++++--------
 3 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/modules/codec/avcodec/d3d11va.c b/modules/codec/avcodec/d3d11va.c
index 4f779ef..5e7d106 100644
--- a/modules/codec/avcodec/d3d11va.c
+++ b/modules/codec/avcodec/d3d11va.c
@@ -139,6 +139,7 @@ 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 */
 };
 
@@ -326,7 +327,7 @@ static int Extract(vlc_va_t *va, picture_t *output, uint8_t *data)
                 .right = dstDesc.Width, .bottom = dstDesc.Height, .back = 1,
             };
             ID3D11DeviceContext_CopySubresourceRegion(sys->d3dctx, (ID3D11Resource*) p_sys_out->texture,
-                                                      0, 0, 0, 0,
+                                                      p_sys_out->slice_index, 0, 0, 0,
                                                       (ID3D11Resource*) p_sys_in->texture,
                                                       viewDesc.Texture2D.ArraySlice,
                                                       &copyBox);
diff --git a/modules/video_chroma/d3d11_surface.c b/modules/video_chroma/d3d11_surface.c
index cc773a1..270e9e4 100644
--- a/modules/video_chroma/d3d11_surface.c
+++ b/modules/video_chroma/d3d11_surface.c
@@ -57,6 +57,7 @@ struct picture_sys_t
     ID3D11VideoDecoderOutputView  *decoder; /* may be NULL for pictures from the pool */
     ID3D11Texture2D               *texture;
     ID3D11DeviceContext           *context;
+    unsigned                      slice_index;
     HINSTANCE                     hd3d11_dll; /* TODO */
 };
 
diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index a229337..830f95d 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -97,6 +97,7 @@ struct picture_sys_t
     ID3D11VideoDecoderOutputView  *decoder; /* may be NULL for pictures from the pool */
     ID3D11Texture2D               *texture;
     ID3D11DeviceContext           *context;
+    unsigned                      slice_index;
 };
 #endif
 
@@ -581,22 +582,26 @@ static picture_pool_t *Pool(vout_display_t *vd, unsigned pool_size)
     texDesc.Format = vd->sys->picQuadConfig.textureFormat;
     texDesc.SampleDesc.Count = 1;
     texDesc.MiscFlags = 0; //D3D11_RESOURCE_MISC_SHARED;
-    texDesc.ArraySize = 1;
     texDesc.Usage = D3D11_USAGE_DYNAMIC;
     texDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
     texDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
 
+    texDesc.ArraySize = pool_size;
+
+    ID3D11Texture2D *texture;
+    hr = ID3D11Device_CreateTexture2D( vd->sys->d3ddevice, &texDesc, NULL, &texture );
+    if (FAILED(hr)) {
+        msg_Err(vd, "CreateTexture2D %d failed on picture %d of the pool. (hr=0x%0lx)", pool_size, picture_count, hr);
+        goto error;
+    }
+
     for (picture_count = 0; picture_count < pool_size; picture_count++) {
         picture_sys_t *picsys = calloc(1, sizeof(*picsys));
         if (unlikely(picsys == NULL))
             goto error;
 
-        hr = ID3D11Device_CreateTexture2D( vd->sys->d3ddevice, &texDesc, NULL, &picsys->texture );
-        if (FAILED(hr)) {
-            msg_Err(vd, "CreateTexture2D %d failed on picture %d of the pool. (hr=0x%0lx)", pool_size, picture_count, hr);
-            goto error;
-        }
-
+        picsys->texture = texture;
+        picsys->slice_index = picture_count;
         picsys->context = vd->sys->d3dcontext;
 
         picture_resource_t resource = {
@@ -888,7 +893,7 @@ static void Prepare(vout_display_t *vd, picture_t *picture, subpicture_t *subpic
                                                   (ID3D11Resource*) sys->picQuad.pTexture,
                                                   0, 0, 0, 0,
                                                   (ID3D11Resource*) p_sys->texture,
-                                                  0, &box);
+                                                  p_sys->slice_index, &box);
     }
 #endif
 
-- 
2.8.2



More information about the vlc-devel mailing list