So as to allow chunks to be mapped from the client thread.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/wined3d/adapter_vk.c | 2 +- dlls/wined3d/context_vk.c | 27 +++++++++++++++++++++++++-- dlls/wined3d/wined3d_private.h | 5 +++++ 3 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/dlls/wined3d/adapter_vk.c b/dlls/wined3d/adapter_vk.c index 5c83db9bfc9..8413429bd42 100644 --- a/dlls/wined3d/adapter_vk.c +++ b/dlls/wined3d/adapter_vk.c @@ -380,7 +380,7 @@ static void wined3d_allocator_vk_destroy_chunk(struct wined3d_allocator_chunk *c
TRACE("chunk %p.\n", chunk);
- device_vk = CONTAINING_RECORD(chunk_vk->c.allocator, struct wined3d_device_vk, allocator); + device_vk = wined3d_device_vk_from_allocator(chunk_vk->c.allocator); vk_info = &device_vk->vk_info;
if (chunk_vk->c.map_ptr) diff --git a/dlls/wined3d/context_vk.c b/dlls/wined3d/context_vk.c index 854a800c0e4..619f722f809 100644 --- a/dlls/wined3d/context_vk.c +++ b/dlls/wined3d/context_vk.c @@ -247,26 +247,42 @@ static VkStencilOp vk_stencil_op_from_wined3d(enum wined3d_stencil_op op) } }
+static void wined3d_allocator_chunk_vk_lock(struct wined3d_allocator_chunk_vk *chunk_vk) +{ + wined3d_device_vk_allocator_lock(wined3d_device_vk_from_allocator(chunk_vk->c.allocator)); +} + +static void wined3d_allocator_chunk_vk_unlock(struct wined3d_allocator_chunk_vk *chunk_vk) +{ + wined3d_device_vk_allocator_unlock(wined3d_device_vk_from_allocator(chunk_vk->c.allocator)); +} + void *wined3d_allocator_chunk_vk_map(struct wined3d_allocator_chunk_vk *chunk_vk, struct wined3d_context_vk *context_vk) { struct wined3d_device_vk *device_vk = wined3d_device_vk(context_vk->c.device); const struct wined3d_vk_info *vk_info = context_vk->vk_info; + void *map_ptr; VkResult vr;
TRACE("chunk %p, memory 0x%s, map_ptr %p.\n", chunk_vk, wine_dbgstr_longlong(chunk_vk->vk_memory), chunk_vk->c.map_ptr);
+ wined3d_allocator_chunk_vk_lock(chunk_vk); + if (!chunk_vk->c.map_ptr && (vr = VK_CALL(vkMapMemory(device_vk->vk_device, - chunk_vk->vk_memory, 0, VK_WHOLE_SIZE, 0, &chunk_vk->c.map_ptr))) < 0) + chunk_vk->vk_memory, 0, VK_WHOLE_SIZE, 0, &map_ptr))) < 0) { ERR("Failed to map chunk memory, vr %s.\n", wined3d_debug_vkresult(vr)); return NULL; } + chunk_vk->c.map_ptr = map_ptr;
++chunk_vk->c.map_count;
- return chunk_vk->c.map_ptr; + wined3d_allocator_chunk_vk_unlock(chunk_vk); + + return map_ptr; }
void wined3d_allocator_chunk_vk_unmap(struct wined3d_allocator_chunk_vk *chunk_vk, @@ -277,11 +293,18 @@ void wined3d_allocator_chunk_vk_unmap(struct wined3d_allocator_chunk_vk *chunk_v
TRACE("chunk_vk %p, context_vk %p.\n", chunk_vk, context_vk);
+ wined3d_allocator_chunk_vk_lock(chunk_vk); + if (--chunk_vk->c.map_count) + { + wined3d_allocator_chunk_vk_unlock(chunk_vk); return; + }
VK_CALL(vkUnmapMemory(device_vk->vk_device, chunk_vk->vk_memory)); chunk_vk->c.map_ptr = NULL; + + wined3d_allocator_chunk_vk_unlock(chunk_vk); }
VkDeviceMemory wined3d_context_vk_allocate_vram_chunk_memory(struct wined3d_context_vk *context_vk, diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index f1f03abc2b5..d8f680f50f4 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -4095,6 +4095,11 @@ static inline struct wined3d_device_vk *wined3d_device_vk(struct wined3d_device return CONTAINING_RECORD(device, struct wined3d_device_vk, d); }
+static inline struct wined3d_device_vk *wined3d_device_vk_from_allocator(struct wined3d_allocator *allocator) +{ + return CONTAINING_RECORD(allocator, struct wined3d_device_vk, allocator); +} + static inline void wined3d_device_vk_allocator_lock(struct wined3d_device_vk *device_vk) { EnterCriticalSection(&device_vk->allocator_cs);