Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- v2: Same changes as the d3d9 version.
dlls/d3d8/buffer.c | 18 ++++++++++++------ dlls/d3d8/d3d8_private.h | 5 +++-- dlls/d3d8/device.c | 6 +++--- dlls/d3d8/surface.c | 2 +- dlls/d3d8/volume.c | 2 +- 5 files changed, 20 insertions(+), 13 deletions(-)
diff --git a/dlls/d3d8/buffer.c b/dlls/d3d8/buffer.c index 0a6767be70e..5454d5712a1 100644 --- a/dlls/d3d8/buffer.c +++ b/dlls/d3d8/buffer.c @@ -188,6 +188,7 @@ static HRESULT WINAPI d3d8_vertexbuffer_Lock(IDirect3DVertexBuffer8 *iface, UINT BYTE **data, DWORD flags) { struct d3d8_vertexbuffer *buffer = impl_from_IDirect3DVertexBuffer8(iface); + struct wined3d_resource *wined3d_resource; struct wined3d_map_desc wined3d_map_desc; struct wined3d_box wined3d_box = {0}; HRESULT hr; @@ -198,8 +199,9 @@ static HRESULT WINAPI d3d8_vertexbuffer_Lock(IDirect3DVertexBuffer8 *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;
@@ -235,7 +237,7 @@ static HRESULT WINAPI d3d8_vertexbuffer_GetDesc(IDirect3DVertexBuffer8 *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; @@ -296,6 +298,7 @@ HRESULT vertexbuffer_init(struct d3d8_vertexbuffer *buffer, struct d3d8_device * buffer->IDirect3DVertexBuffer8_iface.lpVtbl = &Direct3DVertexBuffer8_Vtbl; d3d8_resource_init(&buffer->resource); buffer->fvf = fvf; + buffer->usage = usage;
desc.byte_width = size; desc.usage = usage & WINED3DUSAGE_MASK; @@ -509,6 +512,7 @@ static HRESULT WINAPI d3d8_indexbuffer_Lock(IDirect3DIndexBuffer8 *iface, UINT o BYTE **data, DWORD flags) { struct d3d8_indexbuffer *buffer = impl_from_IDirect3DIndexBuffer8(iface); + struct wined3d_resource *wined3d_resource; struct wined3d_map_desc wined3d_map_desc; struct wined3d_box wined3d_box = {0}; HRESULT hr; @@ -519,8 +523,9 @@ static HRESULT WINAPI d3d8_indexbuffer_Lock(IDirect3DIndexBuffer8 *iface, UINT o 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;
@@ -556,7 +561,7 @@ static HRESULT WINAPI d3d8_indexbuffer_GetDesc(IDirect3DIndexBuffer8 *iface,
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;
@@ -627,6 +632,7 @@ HRESULT indexbuffer_init(struct d3d8_indexbuffer *buffer, struct d3d8_device *de buffer->IDirect3DIndexBuffer8_iface.lpVtbl = &d3d8_indexbuffer_vtbl; d3d8_resource_init(&buffer->resource); buffer->format = wined3dformat_from_d3dformat(format); + buffer->usage = usage;
wined3d_mutex_lock(); hr = wined3d_buffer_create(device->wined3d_device, &desc, NULL, buffer, parent_ops, &buffer->wined3d_buffer); diff --git a/dlls/d3d8/d3d8_private.h b/dlls/d3d8/d3d8_private.h index 81f4e2009fd..955de86b80d 100644 --- a/dlls/d3d8/d3d8_private.h +++ b/dlls/d3d8/d3d8_private.h @@ -208,7 +208,7 @@ struct d3d8_vertexbuffer struct wined3d_buffer *wined3d_buffer; IDirect3DDevice8 *parent_device; struct wined3d_buffer *draw_buffer; - DWORD fvf; + DWORD fvf, usage; };
HRESULT vertexbuffer_init(struct d3d8_vertexbuffer *buffer, struct d3d8_device *device, @@ -223,6 +223,7 @@ struct d3d8_indexbuffer IDirect3DDevice8 *parent_device; struct wined3d_buffer *draw_buffer; enum wined3d_format_id format; + DWORD usage; };
HRESULT indexbuffer_init(struct d3d8_indexbuffer *buffer, struct d3d8_device *device, @@ -282,7 +283,7 @@ HRESULT d3d8_pixel_shader_init(struct d3d8_pixel_shader *shader, struct d3d8_dev
D3DFORMAT d3dformat_from_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 load_local_constants(const DWORD *d3d8_elements, struct wined3d_shader *wined3d_vertex_shader) DECLSPEC_HIDDEN; size_t parse_token(const DWORD *pToken) DECLSPEC_HIDDEN;
diff --git a/dlls/d3d8/device.c b/dlls/d3d8/device.c index a113e57f580..0a7f4775c96 100644 --- a/dlls/d3d8/device.c +++ b/dlls/d3d8/device.c @@ -142,7 +142,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 @@ -151,12 +151,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) diff --git a/dlls/d3d8/surface.c b/dlls/d3d8/surface.c index 0d8793788d7..2edc51da38b 100644 --- a/dlls/d3d8/surface.c +++ b/dlls/d3d8/surface.c @@ -245,7 +245,7 @@ static HRESULT WINAPI d3d8_surface_LockRect(IDirect3DSurface8 *iface, }
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)) diff --git a/dlls/d3d8/volume.c b/dlls/d3d8/volume.c index 00dd78a533e..26e0617b7cd 100644 --- a/dlls/d3d8/volume.c +++ b/dlls/d3d8/volume.c @@ -149,7 +149,7 @@ static HRESULT WINAPI d3d8_volume_LockBox(IDirect3DVolume8 *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();