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

d3d11: Set resource access based on usage and CPU access flags.

parent 0509b9a4
......@@ -8199,28 +8199,28 @@ static void check_buffer_cpu_access_(unsigned int line, ID3D10Buffer *buffer,
expected_hr = cpu_read ? S_OK : E_INVALIDARG;
hr = ID3D10Buffer_Map(buffer, D3D10_MAP_READ, 0, &data);
todo_wine_if(expected_hr != S_OK)
todo_wine_if(expected_hr != S_OK && cpu_access)
ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for READ.\n", hr);
if (SUCCEEDED(hr))
ID3D10Buffer_Unmap(buffer);
expected_hr = !dynamic && cpu_write ? S_OK : E_INVALIDARG;
hr = ID3D10Buffer_Map(buffer, D3D10_MAP_WRITE, 0, &data);
todo_wine_if(expected_hr != S_OK)
todo_wine_if(expected_hr != S_OK && cpu_access)
ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for WRITE.\n", hr);
if (SUCCEEDED(hr))
ID3D10Buffer_Unmap(buffer);
expected_hr = cpu_read && cpu_write ? S_OK : E_INVALIDARG;
hr = ID3D10Buffer_Map(buffer, D3D10_MAP_READ_WRITE, 0, &data);
todo_wine_if(expected_hr != S_OK)
todo_wine_if(expected_hr != S_OK && cpu_access)
ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for READ_WRITE.\n", hr);
if (SUCCEEDED(hr))
ID3D10Buffer_Unmap(buffer);
expected_hr = dynamic ? S_OK : E_INVALIDARG;
hr = ID3D10Buffer_Map(buffer, D3D10_MAP_WRITE_DISCARD, 0, &data);
todo_wine_if(expected_hr != S_OK)
todo_wine_if(expected_hr != S_OK && cpu_access)
ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for WRITE_DISCARD.\n", hr);
if (SUCCEEDED(hr))
ID3D10Buffer_Unmap(buffer);
......@@ -8254,28 +8254,28 @@ static void check_texture_cpu_access_(unsigned int line, ID3D10Texture2D *textur
expected_hr = cpu_read ? S_OK : E_INVALIDARG;
hr = ID3D10Texture2D_Map(texture, 0, D3D10_MAP_READ, 0, &map_desc);
todo_wine_if(expected_hr != S_OK)
todo_wine_if(expected_hr != S_OK && cpu_access)
ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for READ.\n", hr);
if (SUCCEEDED(hr))
ID3D10Texture2D_Unmap(texture, 0);
expected_hr = !dynamic && cpu_write ? S_OK : E_INVALIDARG;
hr = ID3D10Texture2D_Map(texture, 0, D3D10_MAP_WRITE, 0, &map_desc);
todo_wine_if(expected_hr != S_OK)
todo_wine_if(expected_hr != S_OK && cpu_access)
ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for WRITE.\n", hr);
if (SUCCEEDED(hr))
ID3D10Texture2D_Unmap(texture, 0);
expected_hr = cpu_read && cpu_write ? S_OK : E_INVALIDARG;
hr = ID3D10Texture2D_Map(texture, 0, D3D10_MAP_READ_WRITE, 0, &map_desc);
todo_wine_if(expected_hr != S_OK)
todo_wine_if(expected_hr != S_OK && cpu_access)
ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for READ_WRITE.\n", hr);
if (SUCCEEDED(hr))
ID3D10Texture2D_Unmap(texture, 0);
expected_hr = dynamic ? S_OK : E_INVALIDARG;
hr = ID3D10Texture2D_Map(texture, 0, D3D10_MAP_WRITE_DISCARD, 0, &map_desc);
todo_wine_if(expected_hr != S_OK)
todo_wine_if(expected_hr != S_OK && cpu_access)
ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for WRITE_DISCARD.\n", hr);
if (SUCCEEDED(hr))
ID3D10Texture2D_Unmap(texture, 0);
......
......@@ -452,9 +452,7 @@ static HRESULT d3d_buffer_init(struct d3d_buffer *buffer, struct d3d_device *dev
wined3d_desc.byte_width = buffer->desc.ByteWidth;
wined3d_desc.usage = wined3d_usage_from_d3d11(0, buffer->desc.Usage);
wined3d_desc.bind_flags = buffer->desc.BindFlags;
if (~buffer->desc.CPUAccessFlags & (D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ))
FIXME("Ignoring CPU access flags %#x.\n", buffer->desc.CPUAccessFlags);
wined3d_desc.access = WINED3D_RESOURCE_ACCESS_GPU | WINED3D_RESOURCE_ACCESS_CPU | WINED3D_RESOURCE_ACCESS_MAP;
wined3d_desc.access = wined3d_access_from_d3d11(buffer->desc.Usage, buffer->desc.CPUAccessFlags);
wined3d_desc.misc_flags = buffer->desc.MiscFlags;
wined3d_desc.structure_byte_stride = buffer->desc.StructureByteStride;
......
......@@ -74,6 +74,7 @@ struct wined3d_resource *wined3d_resource_from_d3d11_resource(ID3D11Resource *re
struct wined3d_resource *wined3d_resource_from_d3d10_resource(ID3D10Resource *resource) DECLSPEC_HIDDEN;
DWORD wined3d_map_flags_from_d3d11_map_type(D3D11_MAP map_type) DECLSPEC_HIDDEN;
DWORD wined3d_clear_flags_from_d3d11_clear_flags(UINT clear_flags) DECLSPEC_HIDDEN;
unsigned int wined3d_access_from_d3d11(D3D11_USAGE usage, UINT cpu_access) DECLSPEC_HIDDEN;
enum D3D11_USAGE d3d11_usage_from_d3d10_usage(enum D3D10_USAGE usage) DECLSPEC_HIDDEN;
enum D3D10_USAGE d3d10_usage_from_d3d11_usage(enum D3D11_USAGE usage) DECLSPEC_HIDDEN;
......
......@@ -11029,7 +11029,7 @@ static void check_resource_cpu_access_(unsigned int line, ID3D11DeviceContext *c
expected_hr = cpu_read ? S_OK : E_INVALIDARG;
hr = ID3D11DeviceContext_Map(context, resource, 0, D3D11_MAP_READ, 0, &map_desc);
todo_wine_if(expected_hr != S_OK)
todo_wine_if(expected_hr != S_OK && cpu_access)
ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for READ.\n", hr);
if (SUCCEEDED(hr))
ID3D11DeviceContext_Unmap(context, resource, 0);
......@@ -11037,21 +11037,21 @@ static void check_resource_cpu_access_(unsigned int line, ID3D11DeviceContext *c
/* WRITE_DISCARD and WRITE_NO_OVERWRITE are the only allowed options for dynamic resources. */
expected_hr = !dynamic && cpu_write ? S_OK : E_INVALIDARG;
hr = ID3D11DeviceContext_Map(context, resource, 0, D3D11_MAP_WRITE, 0, &map_desc);
todo_wine_if(expected_hr != S_OK)
todo_wine_if(expected_hr != S_OK && cpu_access)
ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for WRITE.\n", hr);
if (SUCCEEDED(hr))
ID3D11DeviceContext_Unmap(context, resource, 0);
expected_hr = cpu_read && cpu_write ? S_OK : E_INVALIDARG;
hr = ID3D11DeviceContext_Map(context, resource, 0, D3D11_MAP_READ_WRITE, 0, &map_desc);
todo_wine_if(expected_hr != S_OK)
todo_wine_if(expected_hr != S_OK && cpu_access)
ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for READ_WRITE.\n", hr);
if (SUCCEEDED(hr))
ID3D11DeviceContext_Unmap(context, resource, 0);
expected_hr = dynamic ? S_OK : E_INVALIDARG;
hr = ID3D11DeviceContext_Map(context, resource, 0, D3D11_MAP_WRITE_DISCARD, 0, &map_desc);
todo_wine_if(expected_hr != S_OK)
todo_wine_if(expected_hr != S_OK && cpu_access)
ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for WRITE_DISCARD.\n", hr);
if (SUCCEEDED(hr))
ID3D11DeviceContext_Unmap(context, resource, 0);
......@@ -517,7 +517,8 @@ HRESULT d3d_texture2d_create(struct d3d_device *device, const D3D11_TEXTURE2D_DE
wined3d_desc.multisample_type = desc->SampleDesc.Count > 1 ? desc->SampleDesc.Count : WINED3D_MULTISAMPLE_NONE;
wined3d_desc.multisample_quality = desc->SampleDesc.Quality;
wined3d_desc.usage = wined3d_usage_from_d3d11(desc->BindFlags, desc->Usage);
wined3d_desc.access = WINED3D_RESOURCE_ACCESS_GPU | WINED3D_RESOURCE_ACCESS_MAP;
wined3d_desc.access = wined3d_access_from_d3d11(desc->Usage,
desc->Usage == D3D11_USAGE_DEFAULT ? 0 : desc->CPUAccessFlags);
wined3d_desc.width = desc->Width;
wined3d_desc.height = desc->Height;
wined3d_desc.depth = 1;
......@@ -974,9 +975,8 @@ static HRESULT d3d_texture3d_init(struct d3d_texture3d *texture, struct d3d_devi
wined3d_desc.multisample_type = WINED3D_MULTISAMPLE_NONE;
wined3d_desc.multisample_quality = 0;
wined3d_desc.usage = wined3d_usage_from_d3d11(desc->BindFlags, desc->Usage);
wined3d_desc.access = WINED3D_RESOURCE_ACCESS_GPU;
if (desc->Usage == D3D11_USAGE_STAGING)
wined3d_desc.access |= WINED3D_RESOURCE_ACCESS_CPU | WINED3D_RESOURCE_ACCESS_MAP;
wined3d_desc.access = wined3d_access_from_d3d11(desc->Usage,
desc->Usage == D3D11_USAGE_DEFAULT ? 0 : desc->CPUAccessFlags);
wined3d_desc.width = desc->Width;
wined3d_desc.height = desc->Height;
wined3d_desc.depth = desc->Depth;
......
......@@ -791,6 +791,21 @@ DWORD wined3d_clear_flags_from_d3d11_clear_flags(UINT clear_flags)
return wined3d_clear_flags;
}
unsigned int wined3d_access_from_d3d11(D3D11_USAGE usage, UINT cpu_access)
{
unsigned int access;
access = usage == D3D11_USAGE_STAGING ? WINED3D_RESOURCE_ACCESS_CPU : WINED3D_RESOURCE_ACCESS_GPU;
if (cpu_access)
{
if (~cpu_access & (D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ))
FIXME("Ignoring CPU access flags %#x.\n", cpu_access);
access |= WINED3D_RESOURCE_ACCESS_MAP;
}
return access;
}
HRESULT d3d_get_private_data(struct wined3d_private_store *store,
REFGUID guid, UINT *data_size, void *data)
{
......
......@@ -155,6 +155,8 @@ static HRESULT WINAPI d3d8_volume_LockBox(IDirect3DVolume8 *iface,
locked_box->SlicePitch = map_desc.slice_pitch;
locked_box->pBits = map_desc.data;
if (hr == E_INVALIDARG)
return D3DERR_INVALIDCALL;
return hr;
}
......
......@@ -155,6 +155,8 @@ static HRESULT WINAPI d3d9_volume_LockBox(IDirect3DVolume9 *iface,
locked_box->SlicePitch = map_desc.slice_pitch;
locked_box->pBits = map_desc.data;
if (hr == E_INVALIDARG)
return D3DERR_INVALIDCALL;
return hr;
}
......
......@@ -346,7 +346,7 @@ HRESULT CDECL wined3d_resource_map(struct wined3d_resource *resource, unsigned i
if (!(resource->access & WINED3D_RESOURCE_ACCESS_MAP))
{
WARN("Resource is not mappable.\n");
return WINED3DERR_INVALIDCALL;
return E_INVALIDARG;
}
flags = wined3d_resource_sanitise_map_flags(resource, flags);
......
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