d3d11: Introduce get_resource_properties() helper function.
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:
parent
dc1f45b3ae
commit
e3d485359d
|
@ -25,6 +25,74 @@
|
|||
|
||||
WINE_DEFAULT_DEBUG_CHANNEL(d3d11);
|
||||
|
||||
static HRESULT get_resource_properties(ID3D11Resource *resource, D3D11_RESOURCE_DIMENSION *dimension,
|
||||
DXGI_FORMAT *format, unsigned int *miplevel_count, unsigned int *layer_count)
|
||||
{
|
||||
ID3D11Resource_GetType(resource, dimension);
|
||||
switch (*dimension)
|
||||
{
|
||||
case D3D11_RESOURCE_DIMENSION_BUFFER:
|
||||
return S_OK;
|
||||
|
||||
case D3D11_RESOURCE_DIMENSION_TEXTURE1D:
|
||||
{
|
||||
const struct d3d_texture1d *texture;
|
||||
|
||||
if (!(texture = unsafe_impl_from_ID3D11Texture1D((ID3D11Texture1D *)resource)))
|
||||
{
|
||||
ERR("Cannot get implementation from ID3D11Texture1D.\n");
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
*format = texture->desc.Format;
|
||||
if (miplevel_count)
|
||||
*miplevel_count = texture->desc.MipLevels;
|
||||
*layer_count = texture->desc.ArraySize;
|
||||
break;
|
||||
}
|
||||
|
||||
case D3D11_RESOURCE_DIMENSION_TEXTURE2D:
|
||||
{
|
||||
const struct d3d_texture2d *texture;
|
||||
|
||||
if (!(texture = unsafe_impl_from_ID3D11Texture2D((ID3D11Texture2D *)resource)))
|
||||
{
|
||||
ERR("Cannot get implementation from ID3D11Texture2D.\n");
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
*format = texture->desc.Format;
|
||||
if (miplevel_count)
|
||||
*miplevel_count = texture->desc.MipLevels;
|
||||
*layer_count = texture->desc.ArraySize;
|
||||
break;
|
||||
}
|
||||
|
||||
case D3D11_RESOURCE_DIMENSION_TEXTURE3D:
|
||||
{
|
||||
const struct d3d_texture3d *texture;
|
||||
|
||||
if (!(texture = unsafe_impl_from_ID3D11Texture3D((ID3D11Texture3D *)resource)))
|
||||
{
|
||||
ERR("Cannot get implementation from ID3D11Texture3D.\n");
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
*format = texture->desc.Format;
|
||||
if (miplevel_count)
|
||||
*miplevel_count = texture->desc.MipLevels;
|
||||
*layer_count = texture->desc.Depth;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
WARN("Invalid resource dimension %#x.\n", *dimension);
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT set_dsv_desc_from_resource(D3D11_DEPTH_STENCIL_VIEW_DESC *desc, ID3D11Resource *resource)
|
||||
{
|
||||
D3D11_RESOURCE_DIMENSION dimension;
|
||||
|
@ -113,10 +181,10 @@ static HRESULT set_dsv_desc_from_resource(D3D11_DEPTH_STENCIL_VIEW_DESC *desc, I
|
|||
return S_OK;
|
||||
}
|
||||
|
||||
default:
|
||||
ERR("Unhandled resource dimension %#x.\n", dimension);
|
||||
case D3D11_RESOURCE_DIMENSION_BUFFER:
|
||||
case D3D11_RESOURCE_DIMENSION_TEXTURE3D:
|
||||
default:
|
||||
WARN("Invalid resource dimension %#x.\n", dimension);
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
}
|
||||
|
@ -126,36 +194,22 @@ static HRESULT normalize_dsv_desc(D3D11_DEPTH_STENCIL_VIEW_DESC *desc, ID3D11Res
|
|||
D3D11_RESOURCE_DIMENSION dimension;
|
||||
unsigned int layer_count;
|
||||
DXGI_FORMAT format;
|
||||
HRESULT hr;
|
||||
|
||||
ID3D11Resource_GetType(resource, &dimension);
|
||||
if (FAILED(hr = get_resource_properties(resource, &dimension, &format, NULL, &layer_count)))
|
||||
return hr;
|
||||
switch (dimension)
|
||||
{
|
||||
case D3D11_RESOURCE_DIMENSION_TEXTURE1D:
|
||||
{
|
||||
const struct d3d_texture1d *texture;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (!(texture = unsafe_impl_from_ID3D11Texture1D((ID3D11Texture1D *)resource)))
|
||||
{
|
||||
ERR("Cannot get implementation from ID3D11Texture1D.\n");
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
format = texture->desc.Format;
|
||||
layer_count = texture->desc.ArraySize;
|
||||
break;
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -164,26 +218,13 @@ static HRESULT normalize_dsv_desc(D3D11_DEPTH_STENCIL_VIEW_DESC *desc, ID3D11Res
|
|||
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 E_FAIL;
|
||||
}
|
||||
|
||||
format = texture->desc.Format;
|
||||
layer_count = texture->desc.ArraySize;
|
||||
break;
|
||||
}
|
||||
|
||||
case D3D11_RESOURCE_DIMENSION_BUFFER:
|
||||
case D3D11_RESOURCE_DIMENSION_TEXTURE3D:
|
||||
default:
|
||||
WARN("Invalid resource dimension %#x.\n", dimension);
|
||||
return E_INVALIDARG;
|
||||
|
||||
default:
|
||||
ERR("Unhandled resource dimension %#x.\n", dimension);
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (desc->Format == DXGI_FORMAT_UNKNOWN)
|
||||
|
@ -337,46 +378,30 @@ static HRESULT normalize_rtv_desc(D3D11_RENDER_TARGET_VIEW_DESC *desc, ID3D11Res
|
|||
D3D11_RESOURCE_DIMENSION dimension;
|
||||
unsigned int layer_count;
|
||||
DXGI_FORMAT format;
|
||||
HRESULT hr;
|
||||
|
||||
ID3D11Resource_GetType(resource, &dimension);
|
||||
if (FAILED(hr = get_resource_properties(resource, &dimension, &format, NULL, &layer_count)))
|
||||
return hr;
|
||||
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:
|
||||
{
|
||||
const struct d3d_texture1d *texture;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (!(texture = unsafe_impl_from_ID3D11Texture1D((ID3D11Texture1D *)resource)))
|
||||
{
|
||||
ERR("Cannot get implementation from ID3D11Texture1D.\n");
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
format = texture->desc.Format;
|
||||
layer_count = texture->desc.ArraySize;
|
||||
break;
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -385,42 +410,19 @@ static HRESULT normalize_rtv_desc(D3D11_RENDER_TARGET_VIEW_DESC *desc, ID3D11Res
|
|||
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 E_FAIL;
|
||||
}
|
||||
|
||||
format = texture->desc.Format;
|
||||
layer_count = texture->desc.ArraySize;
|
||||
break;
|
||||
}
|
||||
|
||||
case D3D11_RESOURCE_DIMENSION_TEXTURE3D:
|
||||
{
|
||||
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 E_FAIL;
|
||||
}
|
||||
|
||||
format = texture->desc.Format;
|
||||
layer_count = texture->desc.Depth;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
ERR("Unhandled resource dimension %#x.\n", dimension);
|
||||
return E_FAIL;
|
||||
WARN("Invalid resource dimension %#x.\n", dimension);
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
|
||||
if (desc->Format == DXGI_FORMAT_UNKNOWN)
|
||||
|
@ -612,7 +614,7 @@ static HRESULT set_srv_desc_from_resource(D3D11_SHADER_RESOURCE_VIEW_DESC *desc,
|
|||
}
|
||||
|
||||
default:
|
||||
ERR("Unhandled resource dimension %#x.\n", dimension);
|
||||
WARN("Invalid resource dimension %#x.\n", dimension);
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
}
|
||||
|
@ -622,12 +624,13 @@ static HRESULT normalize_srv_desc(D3D11_SHADER_RESOURCE_VIEW_DESC *desc, ID3D11R
|
|||
unsigned int miplevel_count, layer_count;
|
||||
D3D11_RESOURCE_DIMENSION dimension;
|
||||
DXGI_FORMAT format;
|
||||
HRESULT hr;
|
||||
|
||||
ID3D11Resource_GetType(resource, &dimension);
|
||||
if (FAILED(hr = get_resource_properties(resource, &dimension, &format, &miplevel_count, &layer_count)))
|
||||
return hr;
|
||||
switch (dimension)
|
||||
{
|
||||
case D3D11_RESOURCE_DIMENSION_BUFFER:
|
||||
{
|
||||
if (desc->ViewDimension != D3D11_SRV_DIMENSION_BUFFER
|
||||
&& desc->ViewDimension != D3D11_SRV_DIMENSION_BUFFEREX)
|
||||
{
|
||||
|
@ -640,35 +643,17 @@ static HRESULT normalize_srv_desc(D3D11_SHADER_RESOURCE_VIEW_DESC *desc, ID3D11R
|
|||
return E_INVALIDARG;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
case D3D11_RESOURCE_DIMENSION_TEXTURE1D:
|
||||
{
|
||||
const struct d3d_texture1d *texture;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (!(texture = unsafe_impl_from_ID3D11Texture1D((ID3D11Texture1D *)resource)))
|
||||
{
|
||||
ERR("Cannot get implementation from ID3D11Texture1D.\n");
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
format = texture->desc.Format;
|
||||
miplevel_count = texture->desc.MipLevels;
|
||||
layer_count = texture->desc.ArraySize;
|
||||
break;
|
||||
}
|
||||
|
||||
case D3D11_RESOURCE_DIMENSION_TEXTURE2D:
|
||||
{
|
||||
const struct d3d_texture2d *texture;
|
||||
|
||||
if (desc->ViewDimension != D3D11_SRV_DIMENSION_TEXTURE2D
|
||||
&& desc->ViewDimension != D3D11_SRV_DIMENSION_TEXTURE2DARRAY
|
||||
&& desc->ViewDimension != D3D11_SRV_DIMENSION_TEXTURE2DMS
|
||||
|
@ -679,44 +664,19 @@ static HRESULT normalize_srv_desc(D3D11_SHADER_RESOURCE_VIEW_DESC *desc, ID3D11R
|
|||
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 E_FAIL;
|
||||
}
|
||||
|
||||
format = texture->desc.Format;
|
||||
miplevel_count = texture->desc.MipLevels;
|
||||
layer_count = texture->desc.ArraySize;
|
||||
break;
|
||||
}
|
||||
|
||||
case D3D11_RESOURCE_DIMENSION_TEXTURE3D:
|
||||
{
|
||||
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)))
|
||||
{
|
||||
ERR("Cannot get implementation from ID3D11Texture3D.\n");
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
format = texture->desc.Format;
|
||||
miplevel_count = texture->desc.MipLevels;
|
||||
layer_count = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
ERR("Unhandled resource dimension %#x.\n", dimension);
|
||||
return E_FAIL;
|
||||
WARN("Invalid resource dimension %#x.\n", dimension);
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
|
||||
if (desc->Format == DXGI_FORMAT_UNKNOWN)
|
||||
|
@ -883,88 +843,49 @@ static HRESULT normalize_uav_desc(D3D11_UNORDERED_ACCESS_VIEW_DESC *desc, ID3D11
|
|||
D3D11_RESOURCE_DIMENSION dimension;
|
||||
unsigned int layer_count;
|
||||
DXGI_FORMAT format;
|
||||
HRESULT hr;
|
||||
|
||||
ID3D11Resource_GetType(resource, &dimension);
|
||||
if (FAILED(hr = get_resource_properties(resource, &dimension, &format, NULL, &layer_count)))
|
||||
return hr;
|
||||
switch (dimension)
|
||||
{
|
||||
case D3D11_RESOURCE_DIMENSION_BUFFER:
|
||||
{
|
||||
if (desc->ViewDimension != D3D11_UAV_DIMENSION_BUFFER)
|
||||
{
|
||||
WARN("Incompatible dimensions %#x, %#x.\n", dimension, desc->ViewDimension);
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
case D3D11_RESOURCE_DIMENSION_TEXTURE1D:
|
||||
{
|
||||
const struct d3d_texture1d *texture;
|
||||
|
||||
if (desc->ViewDimension != D3D11_UAV_DIMENSION_TEXTURE1D
|
||||
&& desc->ViewDimension != D3D11_UAV_DIMENSION_TEXTURE1DARRAY)
|
||||
{
|
||||
WARN("Incompatible dimensions %#x, %#x.\n", dimension, desc->ViewDimension);
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
|
||||
if (!(texture = unsafe_impl_from_ID3D11Texture1D((ID3D11Texture1D *)resource)))
|
||||
{
|
||||
ERR("Cannot get implementation from ID3D11Texture1D.\n");
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
format = texture->desc.Format;
|
||||
layer_count = texture->desc.ArraySize;
|
||||
break;
|
||||
}
|
||||
|
||||
case D3D11_RESOURCE_DIMENSION_TEXTURE2D:
|
||||
{
|
||||
const struct d3d_texture2d *texture;
|
||||
|
||||
if (desc->ViewDimension != D3D11_UAV_DIMENSION_TEXTURE2D
|
||||
&& desc->ViewDimension != D3D11_UAV_DIMENSION_TEXTURE2DARRAY)
|
||||
{
|
||||
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 E_FAIL;
|
||||
}
|
||||
|
||||
format = texture->desc.Format;
|
||||
layer_count = texture->desc.ArraySize;
|
||||
break;
|
||||
}
|
||||
|
||||
case D3D11_RESOURCE_DIMENSION_TEXTURE3D:
|
||||
{
|
||||
const struct d3d_texture3d *texture;
|
||||
|
||||
if (desc->ViewDimension != D3D11_UAV_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 E_FAIL;
|
||||
}
|
||||
|
||||
format = texture->desc.Format;
|
||||
layer_count = texture->desc.Depth;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
ERR("Unhandled resource dimension %#x.\n", dimension);
|
||||
return E_FAIL;
|
||||
WARN("Invalid resource dimension %#x.\n", dimension);
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
|
||||
if (desc->Format == DXGI_FORMAT_UNKNOWN)
|
||||
|
|
Loading…
Reference in New Issue