From: Józef Kucia <jkucia(a)codeweavers.com>
Signed-off-by: Józef Kucia <jkucia(a)codeweavers.com>
---
dlls/d3d11/buffer.c | 8 +++--
dlls/d3d11/d3d11_private.h | 4 +++
dlls/d3d11/texture.c | 8 +++--
dlls/d3d11/utils.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 104 insertions(+), 4 deletions(-)
diff --git a/dlls/d3d11/buffer.c b/dlls/d3d11/buffer.c
index 3ccccc8cc861..ffa95a19396c 100644
--- a/dlls/d3d11/buffer.c
+++ b/dlls/d3d11/buffer.c
@@ -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;
diff --git a/dlls/d3d11/d3d11_private.h b/dlls/d3d11/d3d11_private.h
index c286e768d9cb..6702248e6958 100644
--- a/dlls/d3d11/d3d11_private.h
+++ b/dlls/d3d11/d3d11_private.h
@@ -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,
diff --git a/dlls/d3d11/texture.c b/dlls/d3d11/texture.c
index 2644b52dfa25..a35a9ac9a219 100644
--- a/dlls/d3d11/texture.c
+++ b/dlls/d3d11/texture.c
@@ -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;
diff --git a/dlls/d3d11/utils.c b/dlls/d3d11/utils.c
index ae761f448b74..b3894bbfa585 100644
--- a/dlls/d3d11/utils.c
+++ b/dlls/d3d11/utils.c
@@ -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;
--
2.13.6