d3d11: Do not keep mutex locked when D3D11_BUFFER_DESC validation fails.
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
111a4b5b64
commit
6640bc323a
|
@ -387,6 +387,44 @@ 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)
|
||||
{
|
||||
if (desc->MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS)
|
||||
{
|
||||
if (desc->MiscFlags & D3D11_RESOURCE_MISC_BUFFER_STRUCTURED)
|
||||
{
|
||||
WARN("Raw and structure buffers are mutually exclusive.\n");
|
||||
return FALSE;
|
||||
}
|
||||
if (!(desc->BindFlags & (D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS)))
|
||||
{
|
||||
WARN("Invalid bind flags %#x for raw buffer.\n", desc->BindFlags);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (desc->MiscFlags & D3D11_RESOURCE_MISC_BUFFER_STRUCTURED)
|
||||
{
|
||||
if (!desc->StructureByteStride || desc->StructureByteStride % 4)
|
||||
{
|
||||
WARN("Invalid structure byte stride %u.\n", desc->StructureByteStride);
|
||||
return FALSE;
|
||||
}
|
||||
if (desc->ByteWidth % desc->StructureByteStride)
|
||||
{
|
||||
WARN("Byte width %u is not divisible by structure byte stride %u.\n",
|
||||
desc->ByteWidth, desc->StructureByteStride);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
desc->StructureByteStride = 0;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static HRESULT d3d_buffer_init(struct d3d_buffer *buffer, struct d3d_device *device,
|
||||
const D3D11_BUFFER_DESC *desc, const D3D11_SUBRESOURCE_DATA *data)
|
||||
{
|
||||
|
@ -396,42 +434,10 @@ static HRESULT d3d_buffer_init(struct d3d_buffer *buffer, struct d3d_device *dev
|
|||
buffer->ID3D11Buffer_iface.lpVtbl = &d3d11_buffer_vtbl;
|
||||
buffer->ID3D10Buffer_iface.lpVtbl = &d3d10_buffer_vtbl;
|
||||
buffer->refcount = 1;
|
||||
wined3d_mutex_lock();
|
||||
wined3d_private_store_init(&buffer->private_store);
|
||||
buffer->desc = *desc;
|
||||
|
||||
if (buffer->desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS)
|
||||
{
|
||||
if (buffer->desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_STRUCTURED)
|
||||
{
|
||||
WARN("Raw and structure buffers are mutually exclusive.\n");
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
if (!(buffer->desc.BindFlags & (D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS)))
|
||||
{
|
||||
WARN("Invalid bind flags %#x for raw buffer.\n", buffer->desc.BindFlags);
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
}
|
||||
|
||||
if (buffer->desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_STRUCTURED)
|
||||
{
|
||||
if (!buffer->desc.StructureByteStride || buffer->desc.StructureByteStride % 4)
|
||||
{
|
||||
WARN("Invalid structure byte stride %u.\n", buffer->desc.StructureByteStride);
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
if (buffer->desc.ByteWidth % buffer->desc.StructureByteStride)
|
||||
{
|
||||
WARN("Byte width %u is not divisible by structure byte stride %u.\n",
|
||||
buffer->desc.ByteWidth, buffer->desc.StructureByteStride);
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer->desc.StructureByteStride = 0;
|
||||
}
|
||||
if (!validate_buffer_desc(&buffer->desc))
|
||||
return E_INVALIDARG;
|
||||
|
||||
wined3d_desc.byte_width = buffer->desc.ByteWidth;
|
||||
wined3d_desc.usage = wined3d_usage_from_d3d11(0, buffer->desc.Usage);
|
||||
|
@ -442,6 +448,9 @@ static HRESULT d3d_buffer_init(struct d3d_buffer *buffer, struct d3d_device *dev
|
|||
if (buffer->desc.StructureByteStride)
|
||||
FIXME("Ignoring structure byte stride %u.\n", buffer->desc.StructureByteStride);
|
||||
|
||||
wined3d_mutex_lock();
|
||||
wined3d_private_store_init(&buffer->private_store);
|
||||
|
||||
if (FAILED(hr = wined3d_buffer_create(device->wined3d_device, &wined3d_desc,
|
||||
(const struct wined3d_sub_resource_data *)data, buffer,
|
||||
&d3d_buffer_wined3d_parent_ops, &buffer->wined3d_buffer)))
|
||||
|
|
Loading…
Reference in New Issue