[vlc-devel] [PATCH 29/29] direct3d11: rework the texture placement
Steve Lhomme
robux4 at videolabs.io
Thu Jan 19 11:11:04 CET 2017
Now we always copy the whole texture area and move the boundaries in the
viewport to match the offset/visible dimensions.
---
modules/video_output/win32/direct3d11.c | 66 ++++++++-------------------------
1 file changed, 16 insertions(+), 50 deletions(-)
diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index 6c53628..cfcbb1d 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -155,8 +155,7 @@ static void Direct3D11DeleteRegions(int, picture_t **);
static int Direct3D11MapSubpicture(vout_display_t *, int *, picture_t ***, subpicture_t *);
static int AllocQuad(vout_display_t *, const video_format_t *, d3d_quad_t *,
- const d3d_format_t *, ID3D11PixelShader *, bool b_visible,
- video_projection_mode_t);
+ const d3d_format_t *, ID3D11PixelShader *, video_projection_mode_t);
static void ReleaseQuad(d3d_quad_t *);
static void UpdatePicQuadPosition(vout_display_t *);
static void UpdateQuadOpacity(vout_display_t *, const d3d_quad_t *, float);
@@ -1023,49 +1022,16 @@ static void Prepare(vout_display_t *vd, picture_t *picture, subpicture_t *subpic
{
Direct3D11UnmapTexture(picture);
- D3D11_BOX box;
- box.left = picture->format.i_x_offset;
- /* box.right = picture->format.i_x_offset + picture->format.i_visible_width; */
- box.top = picture->format.i_y_offset;
- /* box.bottom = picture->format.i_y_offset + picture->format.i_visible_height; */
- box.back = 1;
- box.front = 0;
-
- D3D11_TEXTURE2D_DESC dstDesc;
- ID3D11Texture2D_GetDesc(sys->picQuad.pTexture, &dstDesc);
- box.bottom = box.top + dstDesc.Height;
- box.right = box.left + dstDesc.Width;
-
ID3D11DeviceContext_CopySubresourceRegion(sys->d3dcontext,
(ID3D11Resource*) sys->picQuad.pTexture,
0, 0, 0, 0,
(ID3D11Resource*) sys->stagingQuad.pTexture,
- 0, &box);
+ 0, NULL);
}
#ifdef HAVE_ID3D11VIDEODECODER
if (is_d3d11_opaque(picture->format.i_chroma) && sys->legacy_shader) {
- D3D11_BOX box;
picture_sys_t *p_sys = picture->p_sys;
- D3D11_TEXTURE2D_DESC texDesc;
- ID3D11Texture2D_GetDesc( p_sys->texture, &texDesc );
- if (texDesc.Format == DXGI_FORMAT_NV12 || texDesc.Format == DXGI_FORMAT_P010)
- {
- box.left = (picture->format.i_x_offset + 1) & ~1;
- box.right = (picture->format.i_x_offset + picture->format.i_visible_width) & ~1;
- box.top = (picture->format.i_y_offset + 1) & ~1;
- box.bottom = (picture->format.i_y_offset + picture->format.i_visible_height) & ~1;
- }
- else
- {
- box.left = picture->format.i_x_offset;
- box.right = picture->format.i_x_offset + picture->format.i_visible_width;
- box.top = picture->format.i_y_offset;
- box.bottom = picture->format.i_y_offset + picture->format.i_visible_height;
- }
- box.back = 1;
- box.front = 0;
-
if( sys->context_lock != INVALID_HANDLE_VALUE )
{
WaitForSingleObjectEx( sys->context_lock, INFINITE, FALSE );
@@ -1074,7 +1040,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,
- p_sys->slice_index, &box);
+ p_sys->slice_index, NULL);
if ( sys->context_lock != INVALID_HANDLE_VALUE)
ReleaseMutex( sys->context_lock );
}
@@ -1693,7 +1659,7 @@ static int Direct3D11CreateResources(vout_display_t *vd, video_format_t *fmt)
ID3D10Blob_Release(pVSBlob);
if (AllocQuad( vd, fmt, &sys->picQuad, sys->picQuadConfig, pPicQuadShader,
- true, vd->fmt.projection_mode) != VLC_SUCCESS) {
+ vd->fmt.projection_mode) != VLC_SUCCESS) {
ID3D11PixelShader_Release(pPicQuadShader);
msg_Err(vd, "Could not Create the main quad picture. (hr=0x%lX)", hr);
return VLC_EGENERIC;
@@ -1793,12 +1759,12 @@ static void Direct3D11DestroyPool(vout_display_t *vd)
sys->pool = NULL;
}
-static void SetupQuadFlat(d3d_vertex_t *dst_data, WORD *triangle_pos)
+static void SetupQuadFlat(d3d_vertex_t *dst_data, const video_format_t *fmt, WORD *triangle_pos)
{
- float right = 1.0f;
- float left = -1.0f;
- float top = 1.0f;
- float bottom = -1.0f;
+ float right = (float) (2*fmt->i_width-fmt->i_visible_width-2*fmt->i_x_offset) / (float) fmt->i_visible_width;
+ float left = -(float) (2*fmt->i_x_offset + fmt->i_visible_width) / (float) fmt->i_visible_width;
+ float top = (float) (2*fmt->i_y_offset + fmt->i_visible_height) / (float) fmt->i_visible_height;
+ float bottom = -(float) (2*fmt->i_height-fmt->i_visible_height-2*fmt->i_y_offset) / (float) fmt->i_visible_height;
// bottom left
dst_data[0].position.x = left;
@@ -1887,7 +1853,7 @@ static void SetupQuadSphere(d3d_vertex_t *dst_data, WORD *triangle_pos)
}
}
-static bool AllocQuadVertices(vout_display_t *vd, d3d_quad_t *quad, video_projection_mode_t projection)
+static bool AllocQuadVertices(vout_display_t *vd, d3d_quad_t *quad, const video_format_t *fmt, video_projection_mode_t projection)
{
HRESULT hr;
D3D11_MAPPED_SUBRESOURCE mappedResource;
@@ -1951,7 +1917,7 @@ static bool AllocQuadVertices(vout_display_t *vd, d3d_quad_t *quad, video_projec
WORD *triangle_pos = mappedResource.pData;
if ( projection == PROJECTION_MODE_RECTANGULAR )
- SetupQuadFlat(dst_data, triangle_pos);
+ SetupQuadFlat(dst_data, fmt, triangle_pos);
else
SetupQuadSphere(dst_data, triangle_pos);
@@ -1962,7 +1928,7 @@ static bool AllocQuadVertices(vout_display_t *vd, d3d_quad_t *quad, video_projec
}
static int AllocQuad(vout_display_t *vd, const video_format_t *fmt, d3d_quad_t *quad,
- const d3d_format_t *cfg, ID3D11PixelShader *d3dpixelShader, bool b_visible,
+ const d3d_format_t *cfg, ID3D11PixelShader *d3dpixelShader,
video_projection_mode_t projection)
{
vout_display_sys_t *sys = vd->sys;
@@ -2093,8 +2059,8 @@ static int AllocQuad(vout_display_t *vd, const video_format_t *fmt, d3d_quad_t *
D3D11_TEXTURE2D_DESC texDesc;
memset(&texDesc, 0, sizeof(texDesc));
- texDesc.Width = b_visible ? fmt->i_visible_width : fmt->i_width;
- texDesc.Height = b_visible ? fmt->i_visible_height : fmt->i_height;
+ texDesc.Width = fmt->i_width;
+ texDesc.Height = fmt->i_height;
texDesc.MipLevels = texDesc.ArraySize = 1;
texDesc.Format = cfg->formatTexture;
texDesc.SampleDesc.Count = 1;
@@ -2144,7 +2110,7 @@ static int AllocQuad(vout_display_t *vd, const video_format_t *fmt, d3d_quad_t *
if ( d3dpixelShader != NULL )
{
- if (!AllocQuadVertices(vd, quad, projection))
+ if (!AllocQuadVertices(vd, quad, fmt, projection))
goto error;
if (projection == PROJECTION_MODE_RECTANGULAR)
@@ -2363,7 +2329,7 @@ static int Direct3D11MapSubpicture(vout_display_t *vd, int *subpicture_region_co
continue;
}
err = AllocQuad( vd, &r->fmt, d3dquad, sys->d3dregion_format, sys->pSPUPixelShader,
- false, PROJECTION_MODE_RECTANGULAR );
+ PROJECTION_MODE_RECTANGULAR );
if (err != VLC_SUCCESS) {
msg_Err(vd, "Failed to create %dx%d texture for OSD",
r->fmt.i_visible_width, r->fmt.i_visible_height);
--
2.10.2
More information about the vlc-devel
mailing list