d3d11: Validate resource access flags for buffers and 2D textures.
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
5eb13b2413
commit
a2fe3ff066
|
@ -387,8 +387,12 @@ static const struct wined3d_parent_ops d3d_buffer_wined3d_parent_ops =
|
|||
d3d_buffer_wined3d_object_released,
|
||||
};
|
||||
|
||||
static BOOL validate_buffer_desc(D3D11_BUFFER_DESC *desc)
|
||||
static BOOL validate_buffer_desc(D3D11_BUFFER_DESC *desc, D3D_FEATURE_LEVEL feature_level)
|
||||
{
|
||||
if (!validate_d3d11_resource_access_flags(D3D11_RESOURCE_DIMENSION_BUFFER,
|
||||
desc->Usage, desc->BindFlags, desc->CPUAccessFlags, feature_level))
|
||||
return FALSE;
|
||||
|
||||
if (desc->MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS)
|
||||
{
|
||||
if (desc->MiscFlags & D3D11_RESOURCE_MISC_BUFFER_STRUCTURED)
|
||||
|
@ -442,7 +446,7 @@ static HRESULT d3d_buffer_init(struct d3d_buffer *buffer, struct d3d_device *dev
|
|||
buffer->refcount = 1;
|
||||
buffer->desc = *desc;
|
||||
|
||||
if (!validate_buffer_desc(&buffer->desc))
|
||||
if (!validate_buffer_desc(&buffer->desc, device->feature_level))
|
||||
return E_INVALIDARG;
|
||||
|
||||
wined3d_desc.byte_width = buffer->desc.ByteWidth;
|
||||
|
|
|
@ -83,6 +83,10 @@ UINT d3d10_cpu_access_flags_from_d3d11_cpu_access_flags(UINT cpu_access_flags) D
|
|||
UINT d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(UINT resource_misc_flags) DECLSPEC_HIDDEN;
|
||||
UINT d3d10_resource_misc_flags_from_d3d11_resource_misc_flags(UINT resource_misc_flags) DECLSPEC_HIDDEN;
|
||||
|
||||
BOOL validate_d3d11_resource_access_flags(D3D11_RESOURCE_DIMENSION resource_dimension,
|
||||
D3D11_USAGE usage, UINT bind_flags, UINT cpu_access_flags,
|
||||
D3D_FEATURE_LEVEL feature_level) DECLSPEC_HIDDEN;
|
||||
|
||||
HRESULT d3d_get_private_data(struct wined3d_private_store *store,
|
||||
REFGUID guid, UINT *data_size, void *data) DECLSPEC_HIDDEN;
|
||||
HRESULT d3d_set_private_data(struct wined3d_private_store *store,
|
||||
|
|
|
@ -456,8 +456,12 @@ static BOOL is_gdi_compatible_texture(const D3D11_TEXTURE2D_DESC *desc)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL validate_texture2d_desc(const D3D11_TEXTURE2D_DESC *desc)
|
||||
static BOOL validate_texture2d_desc(const D3D11_TEXTURE2D_DESC *desc, D3D_FEATURE_LEVEL feature_level)
|
||||
{
|
||||
if (!validate_d3d11_resource_access_flags(D3D11_RESOURCE_DIMENSION_TEXTURE2D,
|
||||
desc->Usage, desc->BindFlags, desc->CPUAccessFlags, feature_level))
|
||||
return FALSE;
|
||||
|
||||
if (desc->MiscFlags & D3D11_RESOURCE_MISC_TEXTURECUBE
|
||||
&& desc->ArraySize < 6)
|
||||
{
|
||||
|
@ -492,7 +496,7 @@ HRESULT d3d_texture2d_create(struct d3d_device *device, const D3D11_TEXTURE2D_DE
|
|||
DWORD flags = 0;
|
||||
HRESULT hr;
|
||||
|
||||
if (!validate_texture2d_desc(desc))
|
||||
if (!validate_texture2d_desc(desc, device->feature_level))
|
||||
{
|
||||
WARN("Failed to validate texture desc.\n");
|
||||
return E_INVALIDARG;
|
||||
|
|
|
@ -610,6 +610,94 @@ UINT d3d10_resource_misc_flags_from_d3d11_resource_misc_flags(UINT resource_misc
|
|||
return d3d10_resource_misc_flags;
|
||||
}
|
||||
|
||||
static BOOL d3d11_bind_flags_are_gpu_read_only(UINT bind_flags)
|
||||
{
|
||||
static const BOOL read_only_bind_flags = D3D11_BIND_VERTEX_BUFFER
|
||||
| D3D11_BIND_INDEX_BUFFER | D3D11_BIND_CONSTANT_BUFFER
|
||||
| D3D11_BIND_SHADER_RESOURCE;
|
||||
|
||||
return !(bind_flags & ~read_only_bind_flags);
|
||||
}
|
||||
|
||||
BOOL validate_d3d11_resource_access_flags(D3D11_RESOURCE_DIMENSION resource_dimension,
|
||||
D3D11_USAGE usage, UINT bind_flags, UINT cpu_access_flags, D3D_FEATURE_LEVEL feature_level)
|
||||
{
|
||||
const BOOL is_texture = resource_dimension != D3D11_RESOURCE_DIMENSION_BUFFER;
|
||||
|
||||
switch (usage)
|
||||
{
|
||||
case D3D11_USAGE_DEFAULT:
|
||||
if ((bind_flags == D3D11_BIND_SHADER_RESOURCE && feature_level >= D3D_FEATURE_LEVEL_11_0)
|
||||
|| (is_texture && bind_flags == D3D11_BIND_RENDER_TARGET)
|
||||
|| bind_flags == D3D11_BIND_UNORDERED_ACCESS)
|
||||
break;
|
||||
if (cpu_access_flags)
|
||||
{
|
||||
WARN("Default resources are not CPU accessible.\n");
|
||||
return FALSE;
|
||||
}
|
||||
break;
|
||||
|
||||
case D3D11_USAGE_IMMUTABLE:
|
||||
if (!bind_flags)
|
||||
{
|
||||
WARN("Bind flags must be non-zero for immutable resources.\n");
|
||||
return FALSE;
|
||||
}
|
||||
if (!d3d11_bind_flags_are_gpu_read_only(bind_flags))
|
||||
{
|
||||
WARN("Immutable resources cannot be writable by GPU.\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (cpu_access_flags)
|
||||
{
|
||||
WARN("Immutable resources are not CPU accessible.\n");
|
||||
return FALSE;
|
||||
}
|
||||
break;
|
||||
|
||||
case D3D11_USAGE_DYNAMIC:
|
||||
if (!bind_flags)
|
||||
{
|
||||
WARN("Bind flags must be non-zero for dynamic resources.\n");
|
||||
return FALSE;
|
||||
}
|
||||
if (!d3d11_bind_flags_are_gpu_read_only(bind_flags))
|
||||
{
|
||||
WARN("Dynamic resources cannot be writable by GPU.\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (cpu_access_flags != D3D11_CPU_ACCESS_WRITE)
|
||||
{
|
||||
WARN("CPU access must be D3D11_CPU_ACCESS_WRITE for dynamic resources.\n");
|
||||
return FALSE;
|
||||
}
|
||||
break;
|
||||
|
||||
case D3D11_USAGE_STAGING:
|
||||
if (bind_flags)
|
||||
{
|
||||
WARN("Invalid bind flags %#x for staging resources.\n", bind_flags);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!cpu_access_flags)
|
||||
{
|
||||
WARN("CPU access must be non-zero for staging resources.\n");
|
||||
return FALSE;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
WARN("Invalid usage %#x.\n", usage);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
struct wined3d_resource *wined3d_resource_from_d3d11_resource(ID3D11Resource *resource)
|
||||
{
|
||||
D3D11_RESOURCE_DIMENSION dimension;
|
||||
|
|
Loading…
Reference in New Issue