d3d11: Validate "ViewDimension" field in D3D11_DEPTH_STENCIL_VIEW_DESC.

Signed-off-by: Józef Kucia <jkucia@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Józef Kucia 2016-06-16 11:59:38 +02:00 committed by Alexandre Julliard
parent b511775b1b
commit 0626559c53
1 changed files with 37 additions and 6 deletions

View File

@ -121,7 +121,7 @@ static HRESULT set_dsdesc_from_resource(D3D11_DEPTH_STENCIL_VIEW_DESC *desc, ID3
}
}
static void normalize_dsv_desc(D3D11_DEPTH_STENCIL_VIEW_DESC *desc, ID3D11Resource *resource)
static HRESULT normalize_dsv_desc(D3D11_DEPTH_STENCIL_VIEW_DESC *desc, ID3D11Resource *resource)
{
D3D11_RESOURCE_DIMENSION dimension;
unsigned int layer_count;
@ -130,14 +130,36 @@ static void normalize_dsv_desc(D3D11_DEPTH_STENCIL_VIEW_DESC *desc, ID3D11Resour
ID3D11Resource_GetType(resource, &dimension);
switch (dimension)
{
case D3D11_RESOURCE_DIMENSION_TEXTURE1D:
{
if (desc->ViewDimension != D3D11_DSV_DIMENSION_TEXTURE1D
&& desc->ViewDimension != D3D11_DSV_DIMENSION_TEXTURE1DARRAY)
{
WARN("Incompatible dimensions %#x, %#x.\n", dimension, desc->ViewDimension);
return E_INVALIDARG;
}
FIXME("Unhandled 1D texture resource.\n");
return S_OK;
}
case D3D11_RESOURCE_DIMENSION_TEXTURE2D:
{
const struct d3d_texture2d *texture;
if (desc->ViewDimension != D3D11_DSV_DIMENSION_TEXTURE2D
&& desc->ViewDimension != D3D11_DSV_DIMENSION_TEXTURE2DARRAY
&& desc->ViewDimension != D3D11_DSV_DIMENSION_TEXTURE2DMS
&& desc->ViewDimension != D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY)
{
WARN("Incompatible dimensions %#x, %#x.\n", dimension, desc->ViewDimension);
return E_INVALIDARG;
}
if (!(texture = unsafe_impl_from_ID3D11Texture2D((ID3D11Texture2D *)resource)))
{
ERR("Cannot get implementation from ID3D11Texture2D.\n");
return;
return E_FAIL;
}
format = texture->desc.Format;
@ -145,8 +167,14 @@ static void normalize_dsv_desc(D3D11_DEPTH_STENCIL_VIEW_DESC *desc, ID3D11Resour
break;
}
case D3D11_RESOURCE_DIMENSION_BUFFER:
case D3D11_RESOURCE_DIMENSION_TEXTURE3D:
WARN("Invalid resource dimension %#x.\n", dimension);
return E_INVALIDARG;
default:
return;
ERR("Unhandled resource dimension %#x.\n", dimension);
return E_FAIL;
}
if (desc->Format == DXGI_FORMAT_UNKNOWN)
@ -172,6 +200,8 @@ static void normalize_dsv_desc(D3D11_DEPTH_STENCIL_VIEW_DESC *desc, ID3D11Resour
default:
break;
}
return S_OK;
}
static HRESULT set_rtdesc_from_resource(D3D11_RENDER_TARGET_VIEW_DESC *desc, ID3D11Resource *resource)
@ -972,14 +1002,15 @@ static HRESULT d3d_depthstencil_view_init(struct d3d_depthstencil_view *view, st
if (!desc)
{
if (FAILED(hr = set_dsdesc_from_resource(&view->desc, resource)))
return hr;
hr = set_dsdesc_from_resource(&view->desc, resource);
}
else
{
view->desc = *desc;
normalize_dsv_desc(&view->desc, resource);
hr = normalize_dsv_desc(&view->desc, resource);
}
if (FAILED(hr))
return hr;
wined3d_mutex_lock();
if (!(wined3d_resource = wined3d_resource_from_d3d11_resource(resource)))