d3d11: Validate "ViewDimension" field in D3D11_SHADER_RESOURCE_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:33 +02:00 committed by Alexandre Julliard
parent 5f4fc0a937
commit 8f366a5673
1 changed files with 52 additions and 7 deletions

View File

@ -486,7 +486,7 @@ static HRESULT set_srdesc_from_resource(D3D11_SHADER_RESOURCE_VIEW_DESC *desc, I
} }
} }
static void normalize_srv_desc(D3D11_SHADER_RESOURCE_VIEW_DESC *desc, ID3D11Resource *resource) static HRESULT normalize_srv_desc(D3D11_SHADER_RESOURCE_VIEW_DESC *desc, ID3D11Resource *resource)
{ {
unsigned int miplevel_count, layer_count; unsigned int miplevel_count, layer_count;
D3D11_RESOURCE_DIMENSION dimension; D3D11_RESOURCE_DIMENSION dimension;
@ -495,14 +495,49 @@ static void normalize_srv_desc(D3D11_SHADER_RESOURCE_VIEW_DESC *desc, ID3D11Reso
ID3D11Resource_GetType(resource, &dimension); ID3D11Resource_GetType(resource, &dimension);
switch (dimension) switch (dimension)
{ {
case D3D11_RESOURCE_DIMENSION_BUFFER:
{
if (desc->ViewDimension != D3D11_SRV_DIMENSION_BUFFER
&& desc->ViewDimension != D3D11_SRV_DIMENSION_BUFFEREX)
{
WARN("Incompatible dimensions %#x, %#x.\n", dimension, desc->ViewDimension);
return E_INVALIDARG;
}
return S_OK;
}
case D3D11_RESOURCE_DIMENSION_TEXTURE1D:
{
if (desc->ViewDimension != D3D11_SRV_DIMENSION_TEXTURE1D
&& desc->ViewDimension != D3D11_SRV_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: case D3D11_RESOURCE_DIMENSION_TEXTURE2D:
{ {
const struct d3d_texture2d *texture; const struct d3d_texture2d *texture;
if (desc->ViewDimension != D3D11_SRV_DIMENSION_TEXTURE2D
&& desc->ViewDimension != D3D11_SRV_DIMENSION_TEXTURE2DARRAY
&& desc->ViewDimension != D3D11_SRV_DIMENSION_TEXTURE2DMS
&& desc->ViewDimension != D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY
&& desc->ViewDimension != D3D11_SRV_DIMENSION_TEXTURECUBE
&& desc->ViewDimension != D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
{
WARN("Incompatible dimensions %#x, %#x.\n", dimension, desc->ViewDimension);
return E_INVALIDARG;
}
if (!(texture = unsafe_impl_from_ID3D11Texture2D((ID3D11Texture2D *)resource))) if (!(texture = unsafe_impl_from_ID3D11Texture2D((ID3D11Texture2D *)resource)))
{ {
ERR("Cannot get implementation from ID3D11Texture2D.\n"); ERR("Cannot get implementation from ID3D11Texture2D.\n");
return; return E_FAIL;
} }
format = texture->desc.Format; format = texture->desc.Format;
@ -515,10 +550,16 @@ static void normalize_srv_desc(D3D11_SHADER_RESOURCE_VIEW_DESC *desc, ID3D11Reso
{ {
const struct d3d_texture3d *texture; const struct d3d_texture3d *texture;
if (desc->ViewDimension != D3D11_SRV_DIMENSION_TEXTURE3D)
{
WARN("Incompatible dimensions %#x, %#x.\n", dimension, desc->ViewDimension);
return E_INVALIDARG;
}
if (!(texture = unsafe_impl_from_ID3D11Texture3D((ID3D11Texture3D *)resource))) if (!(texture = unsafe_impl_from_ID3D11Texture3D((ID3D11Texture3D *)resource)))
{ {
ERR("Cannot get implementation from ID3D11Texture3D.\n"); ERR("Cannot get implementation from ID3D11Texture3D.\n");
return; return E_FAIL;
} }
format = texture->desc.Format; format = texture->desc.Format;
@ -528,7 +569,8 @@ static void normalize_srv_desc(D3D11_SHADER_RESOURCE_VIEW_DESC *desc, ID3D11Reso
} }
default: default:
return; ERR("Unhandled resource dimension %#x.\n", dimension);
return E_FAIL;
} }
if (desc->Format == DXGI_FORMAT_UNKNOWN) if (desc->Format == DXGI_FORMAT_UNKNOWN)
@ -585,6 +627,8 @@ static void normalize_srv_desc(D3D11_SHADER_RESOURCE_VIEW_DESC *desc, ID3D11Reso
default: default:
break; break;
} }
return S_OK;
} }
/* ID3D11DepthStencilView methods */ /* ID3D11DepthStencilView methods */
@ -1818,14 +1862,15 @@ static HRESULT d3d_shader_resource_view_init(struct d3d_shader_resource_view *vi
if (!desc) if (!desc)
{ {
if (FAILED(hr = set_srdesc_from_resource(&view->desc, resource))) hr = set_srdesc_from_resource(&view->desc, resource);
return hr;
} }
else else
{ {
view->desc = *desc; view->desc = *desc;
normalize_srv_desc(&view->desc, resource); hr = normalize_srv_desc(&view->desc, resource);
} }
if (FAILED(hr))
return hr;
if (FAILED(hr = wined3d_shader_resource_view_desc_from_d3d11(&wined3d_desc, &view->desc))) if (FAILED(hr = wined3d_shader_resource_view_desc_from_d3d11(&wined3d_desc, &view->desc)))
return hr; return hr;