Commit f519aca8 authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Reject sub-resource types in wined3d_check_device_format().

parent c21b51ad
......@@ -244,27 +244,20 @@ static HRESULT WINAPI d3d8_CheckDeviceFormat(IDirect3D8 *iface, UINT adapter, D3
usage = usage & (WINED3DUSAGE_MASK | WINED3DUSAGE_QUERY_MASK);
switch (resource_type)
{
case D3DRTYPE_SURFACE:
wined3d_rtype = WINED3D_RTYPE_SURFACE;
break;
case D3DRTYPE_VOLUME:
wined3d_rtype = WINED3D_RTYPE_VOLUME;
break;
case D3DRTYPE_CUBETEXTURE:
usage |= WINED3DUSAGE_LEGACY_CUBEMAP;
case D3DRTYPE_TEXTURE:
usage |= WINED3DUSAGE_TEXTURE;
case D3DRTYPE_SURFACE:
wined3d_rtype = WINED3D_RTYPE_TEXTURE_2D;
break;
case D3DRTYPE_VOLUMETEXTURE:
case D3DRTYPE_VOLUME:
usage |= WINED3DUSAGE_TEXTURE;
wined3d_rtype = WINED3D_RTYPE_TEXTURE_3D;
break;
case D3DRTYPE_CUBETEXTURE:
wined3d_rtype = WINED3D_RTYPE_TEXTURE_2D;
usage |= WINED3DUSAGE_LEGACY_CUBEMAP;
break;
case D3DRTYPE_VERTEXBUFFER:
case D3DRTYPE_INDEXBUFFER:
wined3d_rtype = WINED3D_RTYPE_BUFFER;
......
......@@ -257,27 +257,20 @@ static HRESULT WINAPI d3d9_CheckDeviceFormat(IDirect3D9Ex *iface, UINT adapter,
usage = usage & (WINED3DUSAGE_MASK | WINED3DUSAGE_QUERY_MASK);
switch (resource_type)
{
case D3DRTYPE_SURFACE:
wined3d_rtype = WINED3D_RTYPE_SURFACE;
break;
case D3DRTYPE_VOLUME:
wined3d_rtype = WINED3D_RTYPE_VOLUME;
break;
case D3DRTYPE_CUBETEXTURE:
usage |= WINED3DUSAGE_LEGACY_CUBEMAP;
case D3DRTYPE_TEXTURE:
usage |= WINED3DUSAGE_TEXTURE;
case D3DRTYPE_SURFACE:
wined3d_rtype = WINED3D_RTYPE_TEXTURE_2D;
break;
case D3DRTYPE_VOLUMETEXTURE:
case D3DRTYPE_VOLUME:
usage |= WINED3DUSAGE_TEXTURE;
wined3d_rtype = WINED3D_RTYPE_TEXTURE_3D;
break;
case D3DRTYPE_CUBETEXTURE:
wined3d_rtype = WINED3D_RTYPE_TEXTURE_2D;
usage |= WINED3DUSAGE_LEGACY_CUBEMAP;
break;
case D3DRTYPE_VERTEXBUFFER:
case D3DRTYPE_INDEXBUFFER:
wined3d_rtype = WINED3D_RTYPE_BUFFER;
......
......@@ -1733,7 +1733,7 @@ static HRESULT WINAPI ddraw7_GetFourCCCodes(IDirectDraw7 *iface, DWORD *NumCodes
for (i = 0; i < (sizeof(formats) / sizeof(formats[0])); ++i)
{
if (SUCCEEDED(wined3d_check_device_format(ddraw->wined3d, WINED3DADAPTER_DEFAULT, WINED3D_DEVICE_TYPE_HAL,
mode.format_id, 0, WINED3D_RTYPE_SURFACE, formats[i])))
mode.format_id, 0, WINED3D_RTYPE_TEXTURE_2D, formats[i])))
{
if (count < outsize)
Codes[count] = formats[i];
......@@ -4310,7 +4310,7 @@ static HRESULT WINAPI d3d7_EnumZBufferFormats(IDirect3D7 *iface, REFCLSID device
for (i = 0; i < (sizeof(formats) / sizeof(*formats)); ++i)
{
if (SUCCEEDED(wined3d_check_device_format(ddraw->wined3d, WINED3DADAPTER_DEFAULT, type, mode.format_id,
WINED3DUSAGE_DEPTHSTENCIL, WINED3D_RTYPE_SURFACE, formats[i])))
WINED3DUSAGE_DEPTHSTENCIL, WINED3D_RTYPE_TEXTURE_2D, formats[i])))
{
DDPIXELFORMAT pformat;
......@@ -4334,7 +4334,7 @@ static HRESULT WINAPI d3d7_EnumZBufferFormats(IDirect3D7 *iface, REFCLSID device
* pixel format, so we use dwZBufferBitDepth=32. Some games expect 24. Windows Vista and
* newer enumerate both versions, so we do the same(bug 22434) */
if (SUCCEEDED(wined3d_check_device_format(ddraw->wined3d, WINED3DADAPTER_DEFAULT, type, mode.format_id,
WINED3DUSAGE_DEPTHSTENCIL, WINED3D_RTYPE_SURFACE, WINED3DFMT_X8D24_UNORM)))
WINED3DUSAGE_DEPTHSTENCIL, WINED3D_RTYPE_TEXTURE_2D, WINED3DFMT_X8D24_UNORM)))
{
DDPIXELFORMAT x8d24 =
{
......
......@@ -1091,7 +1091,7 @@ static HRESULT d3d_device7_EnumTextureFormats(IDirect3DDevice7 *iface,
for (i = 0; i < sizeof(FormatList) / sizeof(*FormatList); ++i)
{
if (wined3d_check_device_format(device->ddraw->wined3d, WINED3DADAPTER_DEFAULT, WINED3D_DEVICE_TYPE_HAL,
mode.format_id, 0, WINED3D_RTYPE_TEXTURE_2D, FormatList[i]) == D3D_OK)
mode.format_id, WINED3DUSAGE_TEXTURE, WINED3D_RTYPE_TEXTURE_2D, FormatList[i]) == D3D_OK)
{
DDPIXELFORMAT pformat;
......@@ -1113,7 +1113,7 @@ static HRESULT d3d_device7_EnumTextureFormats(IDirect3DDevice7 *iface,
for (i = 0; i < sizeof(BumpFormatList) / sizeof(*BumpFormatList); ++i)
{
if (wined3d_check_device_format(device->ddraw->wined3d, WINED3DADAPTER_DEFAULT,
WINED3D_DEVICE_TYPE_HAL, mode.format_id, WINED3DUSAGE_QUERY_LEGACYBUMPMAP,
WINED3D_DEVICE_TYPE_HAL, mode.format_id, WINED3DUSAGE_TEXTURE | WINED3DUSAGE_QUERY_LEGACYBUMPMAP,
WINED3D_RTYPE_TEXTURE_2D, BumpFormatList[i]) == D3D_OK)
{
DDPIXELFORMAT pformat;
......@@ -1219,7 +1219,7 @@ static HRESULT WINAPI d3d_device2_EnumTextureFormats(IDirect3DDevice2 *iface,
for (i = 0; i < sizeof(FormatList) / sizeof(*FormatList); ++i)
{
if (wined3d_check_device_format(device->ddraw->wined3d, 0, WINED3D_DEVICE_TYPE_HAL,
mode.format_id, 0, WINED3D_RTYPE_TEXTURE_2D, FormatList[i]) == D3D_OK)
mode.format_id, WINED3DUSAGE_TEXTURE, WINED3D_RTYPE_TEXTURE_2D, FormatList[i]) == D3D_OK)
{
DDSURFACEDESC sdesc;
......
......@@ -5935,18 +5935,12 @@ HRESULT ddraw_surface_create(struct ddraw *ddraw, const DDSURFACEDESC2 *surface_
{
if (!(desc->ddsCaps.dwCaps2 & (DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_D3DTEXTUREMANAGE)))
{
enum wined3d_resource_type rtype;
DWORD usage = 0;
if (desc->ddsCaps.dwCaps2 & DDSCAPS2_CUBEMAP)
{
usage |= WINED3DUSAGE_LEGACY_CUBEMAP;
rtype = WINED3D_RTYPE_TEXTURE_2D;
}
usage |= WINED3DUSAGE_LEGACY_CUBEMAP | WINED3DUSAGE_TEXTURE;
else if (desc->ddsCaps.dwCaps & DDSCAPS_TEXTURE)
rtype = WINED3D_RTYPE_TEXTURE_2D;
else
rtype = WINED3D_RTYPE_SURFACE;
usage |= WINED3DUSAGE_TEXTURE;
if (desc->ddsCaps.dwCaps & DDSCAPS_ZBUFFER)
usage = WINED3DUSAGE_DEPTHSTENCIL;
......@@ -5954,7 +5948,7 @@ HRESULT ddraw_surface_create(struct ddraw *ddraw, const DDSURFACEDESC2 *surface_
usage = WINED3DUSAGE_RENDERTARGET;
if (SUCCEEDED(hr = wined3d_check_device_format(ddraw->wined3d, WINED3DADAPTER_DEFAULT,
WINED3D_DEVICE_TYPE_HAL, mode.format_id, usage, rtype, wined3d_desc.format)))
WINED3D_DEVICE_TYPE_HAL, mode.format_id, usage, WINED3D_RTYPE_TEXTURE_2D, wined3d_desc.format)))
desc->ddsCaps.dwCaps |= DDSCAPS_VIDEOMEMORY;
else
desc->ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY;
......
......@@ -4713,34 +4713,38 @@ HRESULT CDECL wined3d_check_device_format(const struct wined3d *wined3d, UINT ad
if (adapter_idx >= wined3d->adapter_count)
return WINED3DERR_INVALIDCALL;
switch (resource_type)
if (resource_type == WINED3D_RTYPE_SURFACE || resource_type == WINED3D_RTYPE_VOLUME)
{
case WINED3D_RTYPE_SURFACE:
if (!CheckSurfaceCapability(adapter, adapter_format, format, wined3d->flags & WINED3D_NO3D))
{
TRACE("[FAILED] - Not supported for plain surfaces.\n");
return WINED3DERR_NOTAVAILABLE;
}
WARN("Invalid resource_type %s.\n", debug_d3dresourcetype(resource_type));
return WINED3DERR_INVALIDCALL;
}
switch (resource_type)
{
case WINED3D_RTYPE_TEXTURE_2D:
allowed_usage = WINED3DUSAGE_DEPTHSTENCIL
| WINED3DUSAGE_RENDERTARGET
| WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
if (usage & WINED3DUSAGE_RENDERTARGET)
allowed_usage |= WINED3DUSAGE_QUERY_SRGBWRITE;
gl_type = WINED3D_GL_RES_TYPE_RB;
break;
if (!(usage & WINED3DUSAGE_TEXTURE))
{
if (!CheckSurfaceCapability(adapter, adapter_format, format, wined3d->flags & WINED3D_NO3D))
{
TRACE("[FAILED] - Not supported for plain surfaces.\n");
return WINED3DERR_NOTAVAILABLE;
}
case WINED3D_RTYPE_TEXTURE_2D:
format_flags |= WINED3DFMT_FLAG_TEXTURE;
allowed_usage = WINED3DUSAGE_AUTOGENMIPMAP
| WINED3DUSAGE_DEPTHSTENCIL
gl_type = WINED3D_GL_RES_TYPE_RB;
break;
}
allowed_usage |= WINED3DUSAGE_AUTOGENMIPMAP
| WINED3DUSAGE_DYNAMIC
| WINED3DUSAGE_LEGACY_CUBEMAP
| WINED3DUSAGE_RENDERTARGET
| WINED3DUSAGE_SOFTWAREPROCESSING
| WINED3DUSAGE_TEXTURE
| WINED3DUSAGE_QUERY_FILTER
| WINED3DUSAGE_QUERY_LEGACYBUMPMAP
| WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING
| WINED3DUSAGE_QUERY_SRGBREAD
| WINED3DUSAGE_QUERY_SRGBWRITE
| WINED3DUSAGE_QUERY_VERTEXTEXTURE
......@@ -4761,10 +4765,9 @@ HRESULT CDECL wined3d_check_device_format(const struct wined3d *wined3d, UINT ad
break;
case WINED3D_RTYPE_TEXTURE_3D:
case WINED3D_RTYPE_VOLUME:
format_flags |= WINED3DFMT_FLAG_TEXTURE;
allowed_usage = WINED3DUSAGE_DYNAMIC
| WINED3DUSAGE_SOFTWAREPROCESSING
| WINED3DUSAGE_TEXTURE
| WINED3DUSAGE_QUERY_FILTER
| WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING
| WINED3DUSAGE_QUERY_SRGBREAD
......@@ -4786,6 +4789,8 @@ HRESULT CDECL wined3d_check_device_format(const struct wined3d *wined3d, UINT ad
return WINED3DERR_NOTAVAILABLE;
}
if (usage & WINED3DUSAGE_TEXTURE)
format_flags |= WINED3DFMT_FLAG_TEXTURE;
if (usage & WINED3DUSAGE_QUERY_FILTER)
format_flags |= WINED3DFMT_FLAG_FILTERING;
if (usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING)
......@@ -4970,7 +4975,7 @@ HRESULT CDECL wined3d_check_device_type(const struct wined3d *wined3d, UINT adap
/* Validate that the back buffer format is usable for render targets. */
if (FAILED(wined3d_check_device_format(wined3d, adapter_idx, device_type, display_format,
WINED3DUSAGE_RENDERTARGET, WINED3D_RTYPE_SURFACE, backbuffer_format)))
WINED3DUSAGE_RENDERTARGET, WINED3D_RTYPE_TEXTURE_2D, backbuffer_format)))
{
TRACE("Format %s not allowed for render targets.\n", debug_d3dformat(backbuffer_format));
return WINED3DERR_NOTAVAILABLE;
......
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