[vlc-commits] direct3d11: move is_d3d11_opaque() and AllocateTextures() in d3d11_fmt

Steve Lhomme git at videolan.org
Thu Nov 16 12:42:19 CET 2017


vlc | branch: master | Steve Lhomme <robUx4 at videolabs.io> | Thu Nov 16 11:38:52 2017 +0100| [248b2c96f103caa8b7b67c0864e961043adf3cfd] | committer: Jean-Baptiste Kempf

direct3d11: move is_d3d11_opaque() and AllocateTextures() in d3d11_fmt

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

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

 modules/video_chroma/d3d11_fmt.c        | 115 +++++++++++++++++++++++++++++
 modules/video_chroma/d3d11_fmt.h        |  10 +++
 modules/video_output/win32/direct3d11.c | 127 --------------------------------
 3 files changed, 125 insertions(+), 127 deletions(-)

diff --git a/modules/video_chroma/d3d11_fmt.c b/modules/video_chroma/d3d11_fmt.c
index 7ae6fecee2..e3b5e4e0cd 100644
--- a/modules/video_chroma/d3d11_fmt.c
+++ b/modules/video_chroma/d3d11_fmt.c
@@ -283,3 +283,118 @@ const d3d_format_t *FindD3D11Format(ID3D11Device *d3ddevice,
     }
     return NULL;
 }
+
+int AllocateTextures( vlc_object_t *obj, d3d11_handle_t *hd3d11,
+                      const d3d_format_t *cfg, const video_format_t *fmt,
+                      unsigned pool_size, ID3D11Texture2D *textures[] )
+{
+    plane_t planes[PICTURE_PLANE_MAX];
+    int plane, plane_count;
+    HRESULT hr;
+    ID3D11Texture2D *slicedTexture = NULL;
+    D3D11_TEXTURE2D_DESC texDesc;
+    ZeroMemory(&texDesc, sizeof(texDesc));
+    texDesc.MipLevels = 1;
+    texDesc.SampleDesc.Count = 1;
+    texDesc.MiscFlags = 0; //D3D11_RESOURCE_MISC_SHARED;
+    texDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
+    if (is_d3d11_opaque(fmt->i_chroma)) {
+        texDesc.BindFlags |= D3D11_BIND_DECODER;
+        texDesc.Usage = D3D11_USAGE_DEFAULT;
+        texDesc.CPUAccessFlags = 0;
+    } else {
+        texDesc.Usage = D3D11_USAGE_DYNAMIC;
+        texDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
+    }
+    texDesc.ArraySize = pool_size;
+
+    const vlc_chroma_description_t *p_chroma_desc = vlc_fourcc_GetChromaDescription( fmt->i_chroma );
+    if( !p_chroma_desc )
+        return VLC_EGENERIC;
+
+    if (cfg->formatTexture == DXGI_FORMAT_UNKNOWN) {
+        if (p_chroma_desc->plane_count == 0)
+        {
+            msg_Dbg(obj, "failed to get the pixel format planes for %4.4s", (char *)&fmt->i_chroma);
+            return VLC_EGENERIC;
+        }
+        assert(p_chroma_desc->plane_count <= D3D11_MAX_SHADER_VIEW);
+        plane_count = p_chroma_desc->plane_count;
+
+        texDesc.Format = cfg->resourceFormat[0];
+        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;
+        texDesc.Height = fmt->i_height;
+        texDesc.Width = fmt->i_width;
+
+        hr = ID3D11Device_CreateTexture2D( hd3d11->d3ddevice, &texDesc, NULL, &slicedTexture );
+        if (FAILED(hr)) {
+            msg_Err(obj, "CreateTexture2D failed for the %d pool. (hr=0x%0lx)", pool_size, hr);
+            goto error;
+        }
+    }
+
+    for (unsigned picture_count = 0; picture_count < pool_size; picture_count++) {
+        for (plane = 0; plane < plane_count; plane++)
+        {
+            if (slicedTexture) {
+                textures[picture_count * D3D11_MAX_SHADER_VIEW + plane] = slicedTexture;
+                ID3D11Texture2D_AddRef(slicedTexture);
+            } else {
+                texDesc.Height = planes[plane].i_lines;
+                texDesc.Width = planes[plane].i_pitch;
+                hr = ID3D11Device_CreateTexture2D( hd3d11->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%0lx)", pool_size, hr);
+                    goto error;
+                }
+            }
+        }
+        for (; plane < D3D11_MAX_SHADER_VIEW; plane++) {
+            if (!cfg->resourceFormat[plane])
+                textures[picture_count * D3D11_MAX_SHADER_VIEW + plane] = NULL;
+            else
+            {
+                textures[picture_count * D3D11_MAX_SHADER_VIEW + plane] = textures[picture_count * D3D11_MAX_SHADER_VIEW];
+                ID3D11Texture2D_AddRef(textures[picture_count * D3D11_MAX_SHADER_VIEW + plane]);
+            }
+        }
+    }
+
+    if (!is_d3d11_opaque(fmt->i_chroma) && cfg->formatTexture != DXGI_FORMAT_UNKNOWN) {
+        D3D11_MAPPED_SUBRESOURCE mappedResource;
+        hr = ID3D11DeviceContext_Map(hd3d11->d3dcontext, (ID3D11Resource*)textures[0], 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
+        if( FAILED(hr) ) {
+            msg_Err(obj, "The texture cannot be mapped. (hr=0x%lX)", hr);
+            goto error;
+        }
+        ID3D11DeviceContext_Unmap(hd3d11->d3dcontext, (ID3D11Resource*)textures[0], 0);
+        if (mappedResource.RowPitch < p_chroma_desc->pixel_size * texDesc.Width) {
+            msg_Err( obj, "The texture row pitch is too small (%d instead of %d)", mappedResource.RowPitch,
+                     p_chroma_desc->pixel_size * texDesc.Width );
+            goto error;
+        }
+    }
+
+    if (slicedTexture)
+        ID3D11Texture2D_Release(slicedTexture);
+    return VLC_SUCCESS;
+error:
+    if (slicedTexture)
+        ID3D11Texture2D_Release(slicedTexture);
+    return VLC_EGENERIC;
+}
diff --git a/modules/video_chroma/d3d11_fmt.h b/modules/video_chroma/d3d11_fmt.h
index 1f17d490b8..bdc886c9b6 100644
--- a/modules/video_chroma/d3d11_fmt.h
+++ b/modules/video_chroma/d3d11_fmt.h
@@ -59,6 +59,12 @@ picture_sys_t *ActivePictureSys(picture_t *p_pic);
  * (ie not DXGI_FORMAT_UNKNWON) */
 #define KNOWN_DXGI_INDEX   0
 
+static inline bool is_d3d11_opaque(vlc_fourcc_t chroma)
+{
+    return chroma == VLC_CODEC_D3D11_OPAQUE ||
+           chroma == VLC_CODEC_D3D11_OPAQUE_10B;
+}
+
 void AcquirePictureSys(picture_sys_t *p_sys);
 
 void ReleasePictureSys(picture_sys_t *p_sys);
@@ -92,4 +98,8 @@ const d3d_format_t *FindD3D11Format(ID3D11Device *d3ddevice,
                                                   bool allow_opaque,
                                                   UINT supportFlags);
 
+int AllocateTextures(vlc_object_t *obj, d3d11_handle_t *hd3d11,
+                     const d3d_format_t *cfg, const video_format_t *fmt,
+                     unsigned pool_size, ID3D11Texture2D *textures[]);
+
 #endif /* include-guard */
diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index 338eb67d8e..73e627ef35 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -476,18 +476,6 @@ static int OpenCoreW(vout_display_t *vd)
 }
 #endif
 
-static bool is_d3d11_opaque(vlc_fourcc_t chroma)
-{
-    switch (chroma)
-    {
-    case VLC_CODEC_D3D11_OPAQUE:
-    case VLC_CODEC_D3D11_OPAQUE_10B:
-        return true;
-    default:
-        return false;
-    }
-}
-
 #if VLC_WINSTORE_APP
 static bool GetRect(const vout_display_sys_win32_t *p_sys, RECT *out)
 {
@@ -580,121 +568,6 @@ static void Close(vlc_object_t *object)
     free(vd->sys);
 }
 
-static int AllocateTextures(vlc_object_t *obj, d3d11_handle_t *hd3d11,
-                            const d3d_format_t *cfg, const video_format_t *fmt,
-                            unsigned pool_size, ID3D11Texture2D *textures[])
-{
-    plane_t planes[PICTURE_PLANE_MAX];
-    int plane, plane_count;
-    HRESULT hr;
-    ID3D11Texture2D *slicedTexture = NULL;
-    D3D11_TEXTURE2D_DESC texDesc;
-    ZeroMemory(&texDesc, sizeof(texDesc));
-    texDesc.MipLevels = 1;
-    texDesc.SampleDesc.Count = 1;
-    texDesc.MiscFlags = 0; //D3D11_RESOURCE_MISC_SHARED;
-    texDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
-    if (is_d3d11_opaque(fmt->i_chroma)) {
-        texDesc.BindFlags |= D3D11_BIND_DECODER;
-        texDesc.Usage = D3D11_USAGE_DEFAULT;
-        texDesc.CPUAccessFlags = 0;
-    } else {
-        texDesc.Usage = D3D11_USAGE_DYNAMIC;
-        texDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
-    }
-    texDesc.ArraySize = pool_size;
-
-    const vlc_chroma_description_t *p_chroma_desc = vlc_fourcc_GetChromaDescription( fmt->i_chroma );
-    if( !p_chroma_desc )
-        return VLC_EGENERIC;
-
-    if (cfg->formatTexture == DXGI_FORMAT_UNKNOWN) {
-        if (p_chroma_desc->plane_count == 0)
-        {
-            msg_Dbg(obj, "failed to get the pixel format planes for %4.4s", (char *)&fmt->i_chroma);
-            return VLC_EGENERIC;
-        }
-        assert(p_chroma_desc->plane_count <= D3D11_MAX_SHADER_VIEW);
-        plane_count = p_chroma_desc->plane_count;
-
-        texDesc.Format = cfg->resourceFormat[0];
-        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;
-        texDesc.Height = fmt->i_height;
-        texDesc.Width = fmt->i_width;
-
-        hr = ID3D11Device_CreateTexture2D( hd3d11->d3ddevice, &texDesc, NULL, &slicedTexture );
-        if (FAILED(hr)) {
-            msg_Err(obj, "CreateTexture2D failed for the %d pool. (hr=0x%0lx)", pool_size, hr);
-            goto error;
-        }
-    }
-
-    for (unsigned picture_count = 0; picture_count < pool_size; picture_count++) {
-        for (plane = 0; plane < plane_count; plane++)
-        {
-            if (slicedTexture) {
-                textures[picture_count * D3D11_MAX_SHADER_VIEW + plane] = slicedTexture;
-                ID3D11Texture2D_AddRef(slicedTexture);
-            } else {
-                texDesc.Height = planes[plane].i_lines;
-                texDesc.Width = planes[plane].i_pitch;
-                hr = ID3D11Device_CreateTexture2D( hd3d11->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%0lx)", pool_size, hr);
-                    goto error;
-                }
-            }
-        }
-        for (; plane < D3D11_MAX_SHADER_VIEW; plane++) {
-            if (!cfg->resourceFormat[plane])
-                textures[picture_count * D3D11_MAX_SHADER_VIEW + plane] = NULL;
-            else
-            {
-                textures[picture_count * D3D11_MAX_SHADER_VIEW + plane] = textures[picture_count * D3D11_MAX_SHADER_VIEW];
-                ID3D11Texture2D_AddRef(textures[picture_count * D3D11_MAX_SHADER_VIEW + plane]);
-            }
-        }
-    }
-
-    if (!is_d3d11_opaque(fmt->i_chroma) && cfg->formatTexture != DXGI_FORMAT_UNKNOWN) {
-        D3D11_MAPPED_SUBRESOURCE mappedResource;
-        hr = ID3D11DeviceContext_Map(hd3d11->d3dcontext, (ID3D11Resource*)textures[0], 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
-        if( FAILED(hr) ) {
-            msg_Err(obj, "The texture cannot be mapped. (hr=0x%lX)", hr);
-            goto error;
-        }
-        ID3D11DeviceContext_Unmap(hd3d11->d3dcontext, (ID3D11Resource*)textures[0], 0);
-        if (mappedResource.RowPitch < p_chroma_desc->pixel_size * texDesc.Width) {
-            msg_Err( obj, "The texture row pitch is too small (%d instead of %d)", mappedResource.RowPitch,
-                     p_chroma_desc->pixel_size * texDesc.Width );
-            goto error;
-        }
-    }
-
-    if (slicedTexture)
-        ID3D11Texture2D_Release(slicedTexture);
-    return VLC_SUCCESS;
-error:
-    if (slicedTexture)
-        ID3D11Texture2D_Release(slicedTexture);
-    return VLC_EGENERIC;
-}
-
 static picture_pool_t *Pool(vout_display_t *vd, unsigned pool_size)
 {
     /* compensate for extra hardware decoding pulling extra pictures from our pool */



More information about the vlc-commits mailing list