[vlc-commits] d3d11: allow getting the plane layout of allocated textures

Steve Lhomme git at videolan.org
Thu Aug 22 13:15:50 CEST 2019


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Thu Aug 22 12:46:23 2019 +0200| [113bae6e5612f79246255f50950c376ee34558a2] | committer: Steve Lhomme

d3d11: allow getting the plane layout of allocated textures

For those texture format that can be mapped to CPU (or UNKNOWN which we map
ourselves).

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

 modules/hw/d3d11/d3d11_deinterlace.c    |  2 +-
 modules/video_chroma/d3d11_fmt.c        | 32 +++++++++++++++++++-------------
 modules/video_chroma/d3d11_fmt.h        |  7 +++++--
 modules/video_output/win32/direct3d11.c | 20 +++++++-------------
 4 files changed, 32 insertions(+), 29 deletions(-)

diff --git a/modules/hw/d3d11/d3d11_deinterlace.c b/modules/hw/d3d11/d3d11_deinterlace.c
index 939402aa3d..a2a83a9104 100644
--- a/modules/hw/d3d11/d3d11_deinterlace.c
+++ b/modules/hw/d3d11/d3d11_deinterlace.c
@@ -272,7 +272,7 @@ picture_t *AllocPicture( filter_t *p_filter )
             fmt.i_width  = dstDesc.Width;
             fmt.i_height = dstDesc.Height;
             if (AllocateTextures(p_filter, &p_sys->d3d_dev, cfg,
-                                 &fmt, 1, pic_sys->texture) != VLC_SUCCESS)
+                                 &fmt, 1, pic_sys->texture, NULL) != VLC_SUCCESS)
             {
                 free(pic_sys);
                 return NULL;
diff --git a/modules/video_chroma/d3d11_fmt.c b/modules/video_chroma/d3d11_fmt.c
index d4a0f38c89..c8dd3235fa 100644
--- a/modules/video_chroma/d3d11_fmt.c
+++ b/modules/video_chroma/d3d11_fmt.c
@@ -600,7 +600,8 @@ const d3d_format_t *FindD3D11Format(vlc_object_t *o,
 #undef AllocateTextures
 int AllocateTextures( vlc_object_t *obj, d3d11_device_t *d3d_dev,
                       const d3d_format_t *cfg, const video_format_t *fmt,
-                      unsigned pool_size, ID3D11Texture2D *textures[] )
+                      unsigned pool_size, ID3D11Texture2D *textures[],
+                      plane_t out_planes[] )
 {
     plane_t planes[PICTURE_PLANE_MAX];
     int plane, plane_count;
@@ -639,16 +640,6 @@ int AllocateTextures( vlc_object_t *obj, d3d11_device_t *d3d_dev,
         assert(cfg->resourceFormat[1] == cfg->resourceFormat[0]);
         assert(cfg->resourceFormat[2] == cfg->resourceFormat[0]);
 
-        for( int i = 0; i < plane_count; i++ )
-        {
-            plane_t *p = &planes[i];
-
-            p->i_lines         = fmt->i_height * p_chroma_desc->p[i].h.num / p_chroma_desc->p[i].h.den;
-            p->i_visible_lines = fmt->i_visible_height * p_chroma_desc->p[i].h.num / p_chroma_desc->p[i].h.den;
-            p->i_pitch         = fmt->i_width * p_chroma_desc->p[i].w.num / p_chroma_desc->p[i].w.den * p_chroma_desc->pixel_size;
-            p->i_visible_pitch = fmt->i_visible_width * p_chroma_desc->p[i].w.num / p_chroma_desc->p[i].w.den * p_chroma_desc->pixel_size;
-            p->i_pixel_pitch   = p_chroma_desc->pixel_size;
-        }
     } else {
         plane_count = 1;
         texDesc.Format = cfg->formatTexture;
@@ -661,6 +652,16 @@ int AllocateTextures( vlc_object_t *obj, d3d11_device_t *d3d_dev,
             goto error;
         }
     }
+    for( int i = 0; i < p_chroma_desc->plane_count; i++ )
+    {
+        plane_t *p = &planes[i];
+
+        p->i_lines         = fmt->i_height * p_chroma_desc->p[i].h.num / p_chroma_desc->p[i].h.den;
+        p->i_visible_lines = fmt->i_visible_height * p_chroma_desc->p[i].h.num / p_chroma_desc->p[i].h.den;
+        p->i_pitch         = fmt->i_width * p_chroma_desc->p[i].w.num / p_chroma_desc->p[i].w.den * p_chroma_desc->pixel_size;
+        p->i_visible_pitch = fmt->i_visible_width * p_chroma_desc->p[i].w.num / p_chroma_desc->p[i].w.den * p_chroma_desc->pixel_size;
+        p->i_pixel_pitch   = p_chroma_desc->pixel_size;
+    }
 
     for (unsigned picture_count = 0; picture_count < pool_size; picture_count++) {
         for (plane = 0; plane < plane_count; plane++)
@@ -669,8 +670,8 @@ int AllocateTextures( vlc_object_t *obj, d3d11_device_t *d3d_dev,
                 textures[picture_count * D3D11_MAX_SHADER_VIEW + plane] = slicedTexture;
                 ID3D11Texture2D_AddRef(slicedTexture);
             } else {
-                texDesc.Height = fmt->i_height * p_chroma_desc->p[plane].h.num / p_chroma_desc->p[plane].h.den;
-                texDesc.Width = fmt->i_width * p_chroma_desc->p[plane].w.num / p_chroma_desc->p[plane].w.den;
+                texDesc.Height = planes[plane].i_lines;
+                texDesc.Width  = planes[plane].i_pitch;
                 hr = ID3D11Device_CreateTexture2D( d3d_dev->d3ddevice, &texDesc, NULL, &textures[picture_count * D3D11_MAX_SHADER_VIEW + plane] );
                 if (FAILED(hr)) {
                     msg_Err(obj, "CreateTexture2D failed for the %d pool. (hr=0x%lX)", pool_size, hr);
@@ -678,6 +679,11 @@ int AllocateTextures( vlc_object_t *obj, d3d11_device_t *d3d_dev,
                 }
             }
         }
+        if (out_planes)
+            for (plane = 0; plane < p_chroma_desc->plane_count; plane++)
+            {
+                out_planes[plane] = planes[plane];
+            }
         for (; plane < D3D11_MAX_SHADER_VIEW; plane++) {
             if (!cfg->resourceFormat[plane])
                 textures[picture_count * D3D11_MAX_SHADER_VIEW + plane] = NULL;
diff --git a/modules/video_chroma/d3d11_fmt.h b/modules/video_chroma/d3d11_fmt.h
index ab3573edac..717609c425 100644
--- a/modules/video_chroma/d3d11_fmt.h
+++ b/modules/video_chroma/d3d11_fmt.h
@@ -28,6 +28,8 @@
 
 #include "dxgi_fmt.h"
 
+#include <vlc_picture.h>
+
 DEFINE_GUID(GUID_CONTEXT_MUTEX, 0x472e8835, 0x3f8e, 0x4f93, 0xa0, 0xcb, 0x25, 0x79, 0x77, 0x6c, 0xed, 0x86);
 
 /* see https://msdn.microsoft.com/windows/hardware/commercialize/design/compatibility/device-graphics
@@ -145,8 +147,9 @@ const d3d_format_t *FindD3D11Format(vlc_object_t *,
     FindD3D11Format(VLC_OBJECT(a),b,c,d,e,f,g,h,i)
 
 int AllocateTextures(vlc_object_t *, d3d11_device_t *, const d3d_format_t *,
-                     const video_format_t *, unsigned pool_size, ID3D11Texture2D *textures[]);
-#define AllocateTextures(a,b,c,d,e,f)  AllocateTextures(VLC_OBJECT(a),b,c,d,e,f)
+                     const video_format_t *, unsigned pool_size, ID3D11Texture2D *textures[],
+                     plane_t planes[]);
+#define AllocateTextures(a,b,c,d,e,f,g)  AllocateTextures(VLC_OBJECT(a),b,c,d,e,f,g)
 
 static inline void d3d11_device_lock(d3d11_device_t *d3d_dev)
 {
diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index fd791828f2..733a249bd8 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -105,6 +105,7 @@ struct vout_display_sys_t
     ID3D11Query              *prepareWait;
 
     picture_sys_d3d11_t      stagingSys;
+    plane_t                  stagingPlanes[PICTURE_PLANE_MAX];
     picture_pool_t           *pool; /* hardware decoding pool */
 
     d3d_vshader_t            projectionVShader;
@@ -425,7 +426,7 @@ static picture_pool_t *Pool(vout_display_t *vd, unsigned pool_size)
         /* only provide enough for the filters, we can still do direct rendering */
         slices = __MIN(slices, 6);
 
-    if (AllocateTextures(vd, &sys->d3d_dev, sys->picQuad.textureFormat, &sys->area.texture_source, slices, textures))
+    if (AllocateTextures(vd, &sys->d3d_dev, sys->picQuad.textureFormat, &sys->area.texture_source, slices, textures, NULL))
         goto error;
 
     pictures = calloc(pool_size, sizeof(*pictures));
@@ -631,10 +632,8 @@ static void PreparePicture(vout_display_t *vd, picture_t *picture, subpicture_t
     if (sys->picQuad.textureFormat->formatTexture == DXGI_FORMAT_UNKNOWN || !is_d3d11_opaque(picture->format.i_chroma))
     {
         D3D11_MAPPED_SUBRESOURCE mappedResource;
-        D3D11_TEXTURE2D_DESC texDesc;
         int i;
         HRESULT hr;
-        plane_t planes[PICTURE_PLANE_MAX];
 
         bool b_mapped = true;
         for (i = 0; i < picture->i_planes; i++) {
@@ -647,19 +646,14 @@ static void PreparePicture(vout_display_t *vd, picture_t *picture, subpicture_t
                 b_mapped = false;
                 break;
             }
-            ID3D11Texture2D_GetDesc(sys->stagingSys.texture[i], &texDesc);
-            planes[i].i_lines = texDesc.Height;
-            planes[i].i_pitch = mappedResource.RowPitch;
-            planes[i].p_pixels = mappedResource.pData;
-
-            planes[i].i_visible_lines = picture->p[i].i_visible_lines;
-            planes[i].i_visible_pitch = picture->p[i].i_visible_pitch;
+            sys->stagingPlanes[i].i_pitch = mappedResource.RowPitch;
+            sys->stagingPlanes[i].p_pixels = mappedResource.pData;
         }
 
         if (b_mapped)
         {
             for (i = 0; i < picture->i_planes; i++)
-                plane_CopyPixels(&planes[i], &picture->p[i]);
+                plane_CopyPixels(&sys->stagingPlanes[i], &picture->p[i]);
 
             for (i = 0; i < picture->i_planes; i++)
                 ID3D11DeviceContext_Unmap(sys->d3d_dev.d3dcontext, sys->stagingSys.resource[i], 0);
@@ -1195,7 +1189,7 @@ static int Direct3D11CreateFormatResources(vout_display_t *vd, const video_forma
         /* we need a staging texture */
         ID3D11Texture2D *textures[D3D11_MAX_SHADER_VIEW] = {0};
 
-        if (AllocateTextures(vd, &sys->d3d_dev, sys->picQuad.textureFormat, &sys->area.texture_source, 1, textures))
+        if (AllocateTextures(vd, &sys->d3d_dev, sys->picQuad.textureFormat, &sys->area.texture_source, 1, textures, sys->stagingPlanes))
         {
             msg_Err(vd, "Failed to allocate the staging texture");
             return VLC_EGENERIC;
@@ -1394,7 +1388,7 @@ static int Direct3D11MapSubpicture(vout_display_t *vd, int *subpicture_region_co
             if (unlikely(d3dquad==NULL)) {
                 continue;
             }
-            if (AllocateTextures(vd, &sys->d3d_dev, sys->regionQuad.textureFormat, &r->p_picture->format, 1, d3dquad->picSys.texture)) {
+            if (AllocateTextures(vd, &sys->d3d_dev, sys->regionQuad.textureFormat, &r->p_picture->format, 1, d3dquad->picSys.texture, NULL)) {
                 msg_Err(vd, "Failed to allocate %dx%d texture for OSD",
                         r->fmt.i_visible_width, r->fmt.i_visible_height);
                 for (int j=0; j<D3D11_MAX_SHADER_VIEW; j++)



More information about the vlc-commits mailing list