Signed-off-by: Matteo Bruni <mbruni(a)codeweavers.com>
---
dlls/d3d9/buffer.c | 16 ++++++++++++----
dlls/d3d9/d3d9_private.h | 2 +-
dlls/d3d9/device.c | 14 +++++++++++++-
dlls/d3d9/surface.c | 2 +-
dlls/d3d9/volume.c | 2 +-
5 files changed, 28 insertions(+), 8 deletions(-)
diff --git a/dlls/d3d9/buffer.c b/dlls/d3d9/buffer.c
index b6cd646dee2..6becf7d3af0 100644
--- a/dlls/d3d9/buffer.c
+++ b/dlls/d3d9/buffer.c
@@ -189,6 +189,8 @@ 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_resource_desc wined3d_desc;
struct wined3d_map_desc wined3d_map_desc;
struct wined3d_box wined3d_box = {0};
HRESULT hr;
@@ -199,8 +201,10 @@ 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);
+ wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
+ hr = wined3d_resource_map(wined3d_resource, 0, &wined3d_map_desc, &wined3d_box,
+ wined3dmapflags_from_d3dmapflags(flags, wined3d_desc.access));
wined3d_mutex_unlock();
*data = wined3d_map_desc.data;
@@ -515,6 +519,8 @@ 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_resource_desc wined3d_desc;
struct wined3d_map_desc wined3d_map_desc;
struct wined3d_box wined3d_box = {0};
HRESULT hr;
@@ -525,8 +531,10 @@ 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);
+ wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
+ hr = wined3d_resource_map(wined3d_resource, 0, &wined3d_map_desc, &wined3d_box,
+ wined3dmapflags_from_d3dmapflags(flags, wined3d_desc.access));
wined3d_mutex_unlock();
*data = wined3d_map_desc.data;
diff --git a/dlls/d3d9/d3d9_private.h b/dlls/d3d9/d3d9_private.h
index a4dc3abb7a6..c6d73d92957 100644
--- a/dlls/d3d9/d3d9_private.h
+++ b/dlls/d3d9/d3d9_private.h
@@ -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 access) 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;
diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c
index 83db304d6a4..d8e5f0fbfc3 100644
--- a/dlls/d3d9/device.c
+++ b/dlls/d3d9/device.c
@@ -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 access)
{
static const unsigned int handled = D3DLOCK_NOSYSLOCK
| D3DLOCK_NOOVERWRITE
@@ -190,6 +190,18 @@ unsigned int wined3dmapflags_from_d3dmapflags(unsigned int flags)
if (flags)
FIXME("Unhandled flags %#x.\n", flags);
+ if ((wined3d_flags & WINED3D_MAP_READ && ~access & WINED3D_RESOURCE_ACCESS_MAP_R)
+ || (wined3d_flags & WINED3D_MAP_WRITE && ~access & WINED3D_RESOURCE_ACCESS_MAP_W))
+ {
+ WARN("Sanitizing map flags %#x, access %#x.\n", flags, access);
+ if (wined3d_flags & WINED3D_MAP_READ && ~access & WINED3D_RESOURCE_ACCESS_MAP_R)
+ wined3d_flags &= ~WINED3D_MAP_READ;
+ if (wined3d_flags & WINED3D_MAP_WRITE && ~access & WINED3D_RESOURCE_ACCESS_MAP_W)
+ wined3d_flags &= ~WINED3D_MAP_WRITE;
+ if (!wined3d_flags)
+ wined3d_flags = WINED3D_MAP_WRITE;
+ }
+
return wined3d_flags;
}
diff --git a/dlls/d3d9/surface.c b/dlls/d3d9/surface.c
index ded7dc4f490..5905d87b5d6 100644
--- a/dlls/d3d9/surface.c
+++ b/dlls/d3d9/surface.c
@@ -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, ~0u));
wined3d_mutex_unlock();
if (SUCCEEDED(hr))
diff --git a/dlls/d3d9/volume.c b/dlls/d3d9/volume.c
index 7bf12570a89..4a4eab08f6d 100644
--- a/dlls/d3d9/volume.c
+++ b/dlls/d3d9/volume.c
@@ -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, ~0u))))
map_desc.data = NULL;
wined3d_mutex_unlock();
--
2.19.2