1
mirror of https://code.videolan.org/videolan/vlc synced 2024-09-28 23:09:59 +02:00

direct3d11: use the picture_sys_t texture rather than a local quad one

picSys already has all the fields we need.

Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
This commit is contained in:
Steve Lhomme 2017-02-08 14:27:02 +01:00 committed by Jean-Baptiste Kempf
parent 866534e9c8
commit 8fa9ae9837

View File

@ -103,7 +103,6 @@ typedef struct
UINT indexCount;
ID3D11Buffer *pVertexShaderConstants;
picture_sys_t picSys;
ID3D11Texture2D *pTexture;
ID3D11Buffer *pPixelShaderConstants[2];
UINT PSConstantsCount;
ID3D11PixelShader *d3dpixelShader;
@ -625,8 +624,8 @@ static const d3d_format_t *GetOutputFormat(vout_display_t *vd, vlc_fourcc_t i_sr
}
/* map texture planes to resource views */
static int AllocateShaderView(vout_display_t *vd, const d3d_format_t *format, ID3D11Texture2D *texture,
int slice_index, ID3D11ShaderResourceView *resourceView[2])
static int AllocateShaderView(vout_display_t *vd, const d3d_format_t *format,
int slice_index, picture_sys_t *picsys)
{
HRESULT hr;
vout_display_sys_t *sys = vd->sys;
@ -636,17 +635,17 @@ static int AllocateShaderView(vout_display_t *vd, const d3d_format_t *format, ID
resviewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
resviewDesc.Texture2D.MipLevels = 1;
hr = ID3D11Device_CreateShaderResourceView(sys->d3ddevice, (ID3D11Resource *)texture, &resviewDesc, &resourceView[0]);
hr = ID3D11Device_CreateShaderResourceView(sys->d3ddevice, picsys->resource, &resviewDesc, &picsys->resourceView[0]);
if (FAILED(hr)) {
msg_Err(vd, "Could not Create the Y/RGB Texture ResourceView slice %d. (hr=0x%lX)", slice_index, hr);
goto error;
}
resourceView[1] = NULL;
picsys->resourceView[1] = NULL;
if( format->resourceFormat[1] )
{
resviewDesc.Format = format->resourceFormat[1];
hr = ID3D11Device_CreateShaderResourceView(sys->d3ddevice, (ID3D11Resource *)texture, &resviewDesc, &resourceView[1]);
hr = ID3D11Device_CreateShaderResourceView(sys->d3ddevice, picsys->resource, &resviewDesc, &picsys->resourceView[1]);
if (FAILED(hr)) {
msg_Err(vd, "Could not Create the UV Texture ResourceView slice %d. (hr=0x%lX)", slice_index, hr);
goto error;
@ -655,11 +654,11 @@ static int AllocateShaderView(vout_display_t *vd, const d3d_format_t *format, ID
return VLC_SUCCESS;
error:
if (resourceView[0]) {
ID3D11ShaderResourceView_Release(resourceView[0]);
resourceView[0] = NULL;
if (picsys->resourceView[0]) {
ID3D11ShaderResourceView_Release(picsys->resourceView[0]);
picsys->resourceView[0] = NULL;
}
resourceView[1] = NULL;
picsys->resourceView[1] = NULL;
return VLC_EGENERIC;
}
@ -759,7 +758,7 @@ static picture_pool_t *Pool(vout_display_t *vd, unsigned pool_size)
picsys->texture = textures[picture_count];
if (AllocateShaderView(vd, sys->picQuadConfig, picsys->texture, picture_count, picsys->resourceView) != VLC_SUCCESS)
if (AllocateShaderView(vd, sys->picQuadConfig, picture_count, picsys) != VLC_SUCCESS)
goto error;
picsys->slice_index = picture_count;
@ -1132,7 +1131,7 @@ static void Prepare(vout_display_t *vd, picture_t *picture, subpicture_t *subpic
WaitForSingleObjectEx( sys->context_lock, INFINITE, FALSE );
}
ID3D11DeviceContext_CopySubresourceRegion(sys->d3dcontext,
(ID3D11Resource*) sys->picQuad.pTexture,
sys->picQuad.picSys.resource,
0, 0, 0, 0,
p_sys->resource,
p_sys->slice_index, NULL);
@ -1747,7 +1746,7 @@ static int Direct3D11CreatePool(vout_display_t *vd, video_format_t *fmt)
if (unlikely(poolsys == NULL)) {
return VLC_ENOMEM;
}
poolsys->texture = sys->picQuad.pTexture;
poolsys->texture = sys->picQuad.picSys.texture;
poolsys->vd = vd;
picture_resource_t resource = {
@ -2118,25 +2117,25 @@ static int AllocQuad(vout_display_t *vd, const video_format_t *fmt, d3d_quad_t *
texDesc.Height &= ~1;
}
hr = ID3D11Device_CreateTexture2D(sys->d3ddevice, &texDesc, NULL, &quad->pTexture);
hr = ID3D11Device_CreateTexture2D(sys->d3ddevice, &texDesc, NULL, &quad->picSys.texture);
if (FAILED(hr)) {
msg_Err(vd, "Could not Create the D3d11 Texture. (hr=0x%lX)", hr);
goto error;
}
hr = ID3D11DeviceContext_Map(sys->d3dcontext, (ID3D11Resource *)quad->pTexture, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
hr = ID3D11DeviceContext_Map(sys->d3dcontext, quad->picSys.resource, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if( FAILED(hr) ) {
msg_Err(vd, "The texture cannot be mapped. (hr=0x%lX)", hr);
goto error;
}
ID3D11DeviceContext_Unmap(sys->d3dcontext, (ID3D11Resource *)quad->pTexture, 0);
ID3D11DeviceContext_Unmap(sys->d3dcontext, quad->picSys.resource, 0);
if (mappedResource.RowPitch < p_chroma_desc->pixel_size * texDesc.Width) {
msg_Err( vd, "The texture row pitch is too small (%d instead of %d)", mappedResource.RowPitch,
p_chroma_desc->pixel_size * texDesc.Width );
goto error;
}
if (AllocateShaderView(vd, cfg, quad->pTexture, 0, quad->picSys.resourceView) != VLC_SUCCESS)
if (AllocateShaderView(vd, cfg, 0, &quad->picSys) != VLC_SUCCESS)
goto error;
quad->picSys.formatTexture = cfg->formatTexture;
@ -2190,10 +2189,10 @@ static void ReleaseQuad(d3d_quad_t *quad)
ID3D11Buffer_Release(quad->pVertexShaderConstants);
quad->pVertexShaderConstants = NULL;
}
if (quad->pTexture)
if (quad->picSys.texture)
{
ID3D11Texture2D_Release(quad->pTexture);
quad->pTexture = NULL;
ID3D11Texture2D_Release(quad->picSys.texture);
quad->picSys.texture = NULL;
}
for (int i=0; i<D3D11_MAX_SHADER_VIEW; i++) {
if (quad->picSys.resourceView[i])
@ -2320,8 +2319,8 @@ static int Direct3D11MapSubpicture(vout_display_t *vd, int *subpicture_region_co
for (int j = 0; j < sys->d3dregion_count; j++) {
picture_t *cache = sys->d3dregions[j];
if (cache != NULL && ((d3d_quad_t *) cache->p_sys)->pTexture) {
ID3D11Texture2D_GetDesc( ((d3d_quad_t *) cache->p_sys)->pTexture, &texDesc );
if (cache != NULL && ((d3d_quad_t *) cache->p_sys)->picSys.texture) {
ID3D11Texture2D_GetDesc( ((d3d_quad_t *) cache->p_sys)->picSys.texture, &texDesc );
if (texDesc.Format == sys->d3dregion_format->formatTexture &&
texDesc.Width == r->fmt.i_visible_width &&
texDesc.Height == r->fmt.i_visible_height) {
@ -2360,7 +2359,7 @@ static int Direct3D11MapSubpicture(vout_display_t *vd, int *subpicture_region_co
quad_picture = (*region)[i];
}
hr = ID3D11DeviceContext_Map(sys->d3dcontext, (ID3D11Resource *)((d3d_quad_t *) quad_picture->p_sys)->pTexture, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
hr = ID3D11DeviceContext_Map(sys->d3dcontext, ((d3d_quad_t *) quad_picture->p_sys)->picSys.resource, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if( SUCCEEDED(hr) ) {
err = CommonUpdatePicture(quad_picture, NULL, mappedResource.pData, mappedResource.RowPitch);
if (err != VLC_SUCCESS) {
@ -2371,7 +2370,7 @@ static int Direct3D11MapSubpicture(vout_display_t *vd, int *subpicture_region_co
picture_CopyPixels(quad_picture, r->p_picture);
ID3D11DeviceContext_Unmap(sys->d3dcontext, (ID3D11Resource *)((d3d_quad_t *) quad_picture->p_sys)->pTexture, 0);
ID3D11DeviceContext_Unmap(sys->d3dcontext, ((d3d_quad_t *) quad_picture->p_sys)->picSys.resource, 0);
} else {
msg_Err(vd, "Failed to map the SPU texture (hr=0x%lX)", hr );
picture_Release(quad_picture);