Commit 215d9299 authored by Józef Kucia's avatar Józef Kucia Committed by Alexandre Julliard

d3d11: Validate "ViewDimension" field in D3D11_RENDER_TARGET_VIEW_DESC.

parent 0626559c
......@@ -211,7 +211,7 @@ static HRESULT set_rtdesc_from_resource(D3D11_RENDER_TARGET_VIEW_DESC *desc, ID3
ID3D11Resource_GetType(resource, &dimension);
switch(dimension)
switch (dimension)
{
case D3D11_RESOURCE_DIMENSION_TEXTURE1D:
{
......@@ -323,7 +323,7 @@ static HRESULT set_rtdesc_from_resource(D3D11_RENDER_TARGET_VIEW_DESC *desc, ID3
}
}
static void normalize_rtv_desc(D3D11_RENDER_TARGET_VIEW_DESC *desc, ID3D11Resource *resource)
static HRESULT normalize_rtv_desc(D3D11_RENDER_TARGET_VIEW_DESC *desc, ID3D11Resource *resource)
{
D3D11_RESOURCE_DIMENSION dimension;
unsigned int layer_count;
......@@ -332,14 +332,46 @@ static void normalize_rtv_desc(D3D11_RENDER_TARGET_VIEW_DESC *desc, ID3D11Resour
ID3D11Resource_GetType(resource, &dimension);
switch (dimension)
{
case D3D11_RESOURCE_DIMENSION_BUFFER:
{
if (desc->ViewDimension != D3D11_RTV_DIMENSION_BUFFER)
{
WARN("Incompatible dimensions %#x, %#x.\n", dimension, desc->ViewDimension);
return E_INVALIDARG;
}
return S_OK;
}
case D3D11_RESOURCE_DIMENSION_TEXTURE1D:
{
if (desc->ViewDimension != D3D11_RTV_DIMENSION_TEXTURE1D
&& desc->ViewDimension != D3D11_RTV_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_RTV_DIMENSION_TEXTURE2D
&& desc->ViewDimension != D3D11_RTV_DIMENSION_TEXTURE2DARRAY
&& desc->ViewDimension != D3D11_RTV_DIMENSION_TEXTURE2DMS
&& desc->ViewDimension != D3D11_RTV_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;
......@@ -351,10 +383,16 @@ static void normalize_rtv_desc(D3D11_RENDER_TARGET_VIEW_DESC *desc, ID3D11Resour
{
const struct d3d_texture3d *texture;
if (desc->ViewDimension != D3D11_RTV_DIMENSION_TEXTURE3D)
{
WARN("Incompatible dimensions %#x, %#x.\n", dimension, desc->ViewDimension);
return E_INVALIDARG;
}
if (!(texture = unsafe_impl_from_ID3D11Texture3D((ID3D11Texture3D *)resource)))
{
ERR("Cannot get implementation from ID3D11Texture3D.\n");
return;
return E_FAIL;
}
format = texture->desc.Format;
......@@ -363,7 +401,8 @@ static void normalize_rtv_desc(D3D11_RENDER_TARGET_VIEW_DESC *desc, ID3D11Resour
}
default:
return;
ERR("Unhandled resource dimension %#x.\n", dimension);
return E_FAIL;
}
if (desc->Format == DXGI_FORMAT_UNKNOWN)
......@@ -395,6 +434,8 @@ static void normalize_rtv_desc(D3D11_RENDER_TARGET_VIEW_DESC *desc, ID3D11Resour
default:
break;
}
return S_OK;
}
static HRESULT set_srdesc_from_resource(D3D11_SHADER_RESOURCE_VIEW_DESC *desc, ID3D11Resource *resource)
......@@ -1425,14 +1466,15 @@ static HRESULT d3d_rendertarget_view_init(struct d3d_rendertarget_view *view, st
if (!desc)
{
if (FAILED(hr = set_rtdesc_from_resource(&view->desc, resource)))
return hr;
hr = set_rtdesc_from_resource(&view->desc, resource);
}
else
{
view->desc = *desc;
normalize_rtv_desc(&view->desc, resource);
hr = normalize_rtv_desc(&view->desc, resource);
}
if (FAILED(hr))
return hr;
wined3d_mutex_lock();
if (!(wined3d_resource = wined3d_resource_from_d3d11_resource(resource)))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment