d3d9: Take usage flags into account when assigning map flags.

Signed-off-by: Matteo Bruni <mbruni@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Matteo Bruni 2019-01-30 16:25:58 +01:00 committed by Alexandre Julliard
parent 2b4859333f
commit 4e58c72e3a
5 changed files with 20 additions and 13 deletions

View File

@ -189,6 +189,7 @@ static HRESULT WINAPI d3d9_vertexbuffer_Lock(IDirect3DVertexBuffer9 *iface, UINT
void **data, DWORD flags)
{
struct d3d9_vertexbuffer *buffer = impl_from_IDirect3DVertexBuffer9(iface);
struct wined3d_resource *wined3d_resource;
struct wined3d_map_desc wined3d_map_desc;
struct wined3d_box wined3d_box = {0};
HRESULT hr;
@ -199,8 +200,9 @@ static HRESULT WINAPI d3d9_vertexbuffer_Lock(IDirect3DVertexBuffer9 *iface, UINT
wined3d_box.left = offset;
wined3d_box.right = offset + size;
wined3d_mutex_lock();
hr = wined3d_resource_map(wined3d_buffer_get_resource(buffer->wined3d_buffer),
0, &wined3d_map_desc, &wined3d_box, wined3dmapflags_from_d3dmapflags(flags));
wined3d_resource = wined3d_buffer_get_resource(buffer->wined3d_buffer);
hr = wined3d_resource_map(wined3d_resource, 0, &wined3d_map_desc, &wined3d_box,
wined3dmapflags_from_d3dmapflags(flags, buffer->usage));
wined3d_mutex_unlock();
*data = wined3d_map_desc.data;
@ -236,7 +238,7 @@ static HRESULT WINAPI d3d9_vertexbuffer_GetDesc(IDirect3DVertexBuffer9 *iface,
desc->Format = D3DFMT_VERTEXDATA;
desc->Type = D3DRTYPE_VERTEXBUFFER;
desc->Usage = d3dusage_from_wined3dusage(wined3d_desc.usage, wined3d_desc.bind_flags);
desc->Usage = buffer->usage;
desc->Pool = d3dpool_from_wined3daccess(wined3d_desc.access, wined3d_desc.usage);
desc->Size = wined3d_desc.size;
desc->FVF = buffer->fvf;
@ -302,6 +304,7 @@ HRESULT vertexbuffer_init(struct d3d9_vertexbuffer *buffer, struct d3d9_device *
buffer->IDirect3DVertexBuffer9_iface.lpVtbl = &d3d9_vertexbuffer_vtbl;
buffer->fvf = fvf;
buffer->usage = usage;
d3d9_resource_init(&buffer->resource);
desc.byte_width = size;
@ -515,6 +518,7 @@ static HRESULT WINAPI d3d9_indexbuffer_Lock(IDirect3DIndexBuffer9 *iface,
UINT offset, UINT size, void **data, DWORD flags)
{
struct d3d9_indexbuffer *buffer = impl_from_IDirect3DIndexBuffer9(iface);
struct wined3d_resource *wined3d_resource;
struct wined3d_map_desc wined3d_map_desc;
struct wined3d_box wined3d_box = {0};
HRESULT hr;
@ -525,8 +529,9 @@ static HRESULT WINAPI d3d9_indexbuffer_Lock(IDirect3DIndexBuffer9 *iface,
wined3d_box.left = offset;
wined3d_box.right = offset + size;
wined3d_mutex_lock();
hr = wined3d_resource_map(wined3d_buffer_get_resource(buffer->wined3d_buffer),
0, &wined3d_map_desc, &wined3d_box, wined3dmapflags_from_d3dmapflags(flags));
wined3d_resource = wined3d_buffer_get_resource(buffer->wined3d_buffer);
hr = wined3d_resource_map(wined3d_resource, 0, &wined3d_map_desc, &wined3d_box,
wined3dmapflags_from_d3dmapflags(flags, buffer->usage));
wined3d_mutex_unlock();
*data = wined3d_map_desc.data;
@ -561,7 +566,7 @@ static HRESULT WINAPI d3d9_indexbuffer_GetDesc(IDirect3DIndexBuffer9 *iface, D3D
desc->Format = d3dformat_from_wined3dformat(buffer->format);
desc->Type = D3DRTYPE_INDEXBUFFER;
desc->Usage = d3dusage_from_wined3dusage(wined3d_desc.usage, wined3d_desc.bind_flags);
desc->Usage = buffer->usage;
desc->Pool = d3dpool_from_wined3daccess(wined3d_desc.access, wined3d_desc.usage);
desc->Size = wined3d_desc.size;
@ -637,6 +642,7 @@ HRESULT indexbuffer_init(struct d3d9_indexbuffer *buffer, struct d3d9_device *de
buffer->IDirect3DIndexBuffer9_iface.lpVtbl = &d3d9_indexbuffer_vtbl;
buffer->format = wined3dformat_from_d3dformat(format);
buffer->usage = usage;
d3d9_resource_init(&buffer->resource);
wined3d_mutex_lock();

View File

@ -54,7 +54,7 @@ HRESULT vdecl_convert_fvf(DWORD FVF, D3DVERTEXELEMENT9 **ppVertexElements) DECLS
D3DFORMAT d3dformat_from_wined3dformat(enum wined3d_format_id format) DECLSPEC_HIDDEN;
BOOL is_gdi_compat_wined3dformat(enum wined3d_format_id format) DECLSPEC_HIDDEN;
enum wined3d_format_id wined3dformat_from_d3dformat(D3DFORMAT format) DECLSPEC_HIDDEN;
unsigned int wined3dmapflags_from_d3dmapflags(unsigned int flags) DECLSPEC_HIDDEN;
unsigned int wined3dmapflags_from_d3dmapflags(unsigned int flags, unsigned int usage) DECLSPEC_HIDDEN;
void present_parameters_from_wined3d_swapchain_desc(D3DPRESENT_PARAMETERS *present_parameters,
const struct wined3d_swapchain_desc *swapchain_desc, DWORD presentation_interval) DECLSPEC_HIDDEN;
void d3dcaps_from_wined3dcaps(D3DCAPS9 *caps, const struct wined3d_caps *wined3d_caps) DECLSPEC_HIDDEN;
@ -187,7 +187,7 @@ struct d3d9_vertexbuffer
struct wined3d_buffer *wined3d_buffer;
IDirect3DDevice9Ex *parent_device;
struct wined3d_buffer *draw_buffer;
DWORD fvf;
DWORD fvf, usage;
};
HRESULT vertexbuffer_init(struct d3d9_vertexbuffer *buffer, struct d3d9_device *device,
@ -202,6 +202,7 @@ struct d3d9_indexbuffer
IDirect3DDevice9Ex *parent_device;
struct wined3d_buffer *draw_buffer;
enum wined3d_format_id format;
DWORD usage;
};
HRESULT indexbuffer_init(struct d3d9_indexbuffer *buffer, struct d3d9_device *device,

View File

@ -169,7 +169,7 @@ enum wined3d_format_id wined3dformat_from_d3dformat(D3DFORMAT format)
}
}
unsigned int wined3dmapflags_from_d3dmapflags(unsigned int flags)
unsigned int wined3dmapflags_from_d3dmapflags(unsigned int flags, unsigned int usage)
{
static const unsigned int handled = D3DLOCK_NOSYSLOCK
| D3DLOCK_NOOVERWRITE
@ -179,12 +179,12 @@ unsigned int wined3dmapflags_from_d3dmapflags(unsigned int flags)
unsigned int wined3d_flags;
wined3d_flags = flags & handled;
if (!(flags & (D3DLOCK_NOOVERWRITE | D3DLOCK_DISCARD)))
if (~usage & D3DUSAGE_WRITEONLY && !(flags & (D3DLOCK_NOOVERWRITE | D3DLOCK_DISCARD)))
wined3d_flags |= WINED3D_MAP_READ;
if (!(flags & D3DLOCK_READONLY))
wined3d_flags |= WINED3D_MAP_WRITE;
if (!(wined3d_flags & (WINED3D_MAP_READ | WINED3D_MAP_WRITE)))
wined3d_flags |= WINED3D_MAP_READ | WINED3D_MAP_WRITE;
wined3d_flags |= WINED3D_MAP_WRITE;
flags &= ~(handled | D3DLOCK_READONLY);
if (flags)

View File

@ -250,7 +250,7 @@ static HRESULT WINAPI d3d9_surface_LockRect(IDirect3DSurface9 *iface,
wined3d_mutex_lock();
hr = wined3d_resource_map(wined3d_texture_get_resource(surface->wined3d_texture), surface->sub_resource_idx,
&map_desc, rect ? &box : NULL, wined3dmapflags_from_d3dmapflags(flags));
&map_desc, rect ? &box : NULL, wined3dmapflags_from_d3dmapflags(flags, 0));
wined3d_mutex_unlock();
if (SUCCEEDED(hr))

View File

@ -149,7 +149,7 @@ static HRESULT WINAPI d3d9_volume_LockBox(IDirect3DVolume9 *iface,
wined3d_mutex_lock();
if (FAILED(hr = wined3d_resource_map(wined3d_texture_get_resource(volume->wined3d_texture),
volume->sub_resource_idx, &map_desc, (const struct wined3d_box *)box,
wined3dmapflags_from_d3dmapflags(flags))))
wined3dmapflags_from_d3dmapflags(flags, 0))))
map_desc.data = NULL;
wined3d_mutex_unlock();