Henri Verbeet : wined3d: Unmap the chunk if needed in wined3d_context_vk_destroy_bo().

Alexandre Julliard julliard at winehq.org
Mon Dec 14 15:51:17 CST 2020


Module: wine
Branch: master
Commit: 9992d710e4d6e7aa9a0dd3ea0824849c7043bae7
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=9992d710e4d6e7aa9a0dd3ea0824849c7043bae7

Author: Henri Verbeet <hverbeet at codeweavers.com>
Date:   Mon Dec 14 18:15:21 2020 +0330

wined3d: Unmap the chunk if needed in wined3d_context_vk_destroy_bo().

Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/wined3d/adapter_vk.c      | 16 +++++++---------
 dlls/wined3d/context_vk.c      |  2 ++
 dlls/wined3d/wined3d_private.h |  5 +++++
 3 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/dlls/wined3d/adapter_vk.c b/dlls/wined3d/adapter_vk.c
index 3da1615b1b5..4e804b60502 100644
--- a/dlls/wined3d/adapter_vk.c
+++ b/dlls/wined3d/adapter_vk.c
@@ -762,7 +762,6 @@ static void *wined3d_bo_vk_map(struct wined3d_bo_vk *bo, struct wined3d_context_
     const struct wined3d_vk_info *vk_info;
     struct wined3d_device_vk *device_vk;
     struct wined3d_bo_slab_vk *slab;
-    void *map_ptr;
     VkResult vr;
 
     if (bo->map_ptr)
@@ -773,7 +772,7 @@ static void *wined3d_bo_vk_map(struct wined3d_bo_vk *bo, struct wined3d_context_
 
     if ((slab = bo->slab))
     {
-        if (!(map_ptr = slab->map_ptr) && !(map_ptr = wined3d_bo_vk_map(&slab->bo, context_vk)))
+        if (!(bo->map_ptr = slab->map_ptr) && !(bo->map_ptr = wined3d_bo_vk_map(&slab->bo, context_vk)))
         {
             ERR("Failed to map slab.\n");
             return NULL;
@@ -784,22 +783,19 @@ static void *wined3d_bo_vk_map(struct wined3d_bo_vk *bo, struct wined3d_context_
     {
         struct wined3d_allocator_chunk_vk *chunk_vk = wined3d_allocator_chunk_vk(bo->memory->chunk);
 
-        if (!(map_ptr = wined3d_allocator_chunk_vk_map(chunk_vk, context_vk)))
+        if (!(bo->map_ptr = wined3d_allocator_chunk_vk_map(chunk_vk, context_vk)))
         {
             ERR("Failed to map chunk.\n");
             return NULL;
         }
     }
-    else if ((vr = VK_CALL(vkMapMemory(device_vk->vk_device, bo->vk_memory, 0, VK_WHOLE_SIZE, 0, &map_ptr))) < 0)
+    else if ((vr = VK_CALL(vkMapMemory(device_vk->vk_device, bo->vk_memory, 0, VK_WHOLE_SIZE, 0, &bo->map_ptr))) < 0)
     {
         ERR("Failed to map memory, vr %s.\n", wined3d_debug_vkresult(vr));
         return NULL;
     }
 
-    if (sizeof(map_ptr) >= sizeof(uint64_t))
-        bo->map_ptr = map_ptr;
-
-    return map_ptr;
+    return bo->map_ptr;
 }
 
 static void wined3d_bo_vk_unmap(struct wined3d_bo_vk *bo, struct wined3d_context_vk *context_vk)
@@ -808,9 +804,11 @@ static void wined3d_bo_vk_unmap(struct wined3d_bo_vk *bo, struct wined3d_context
     struct wined3d_device_vk *device_vk;
     struct wined3d_bo_slab_vk *slab;
 
-    if (bo->map_ptr)
+    if (wined3d_map_persistent())
         return;
 
+    bo->map_ptr = NULL;
+
     if ((slab = bo->slab))
     {
         if (--slab->map_count)
diff --git a/dlls/wined3d/context_vk.c b/dlls/wined3d/context_vk.c
index 1b937dd3b21..bd3dc50ab01 100644
--- a/dlls/wined3d/context_vk.c
+++ b/dlls/wined3d/context_vk.c
@@ -812,6 +812,8 @@ void wined3d_context_vk_destroy_bo(struct wined3d_context_vk *context_vk, const
     wined3d_context_vk_destroy_buffer(context_vk, bo->vk_buffer, bo->command_buffer_id);
     if (bo->memory)
     {
+        if (bo->map_ptr)
+            wined3d_allocator_chunk_vk_unmap(wined3d_allocator_chunk_vk(bo->memory->chunk), context_vk);
         wined3d_context_vk_destroy_allocator_block(context_vk, bo->memory, bo->command_buffer_id);
         return;
     }
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 30b21a8225f..f48778ee345 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -6367,6 +6367,11 @@ static inline void wined3d_context_gl_reference_bo(struct wined3d_context_gl *co
     bo_gl->command_fence_id = device_gl->current_fence_id;
 }
 
+static inline bool wined3d_map_persistent(void)
+{
+    return sizeof(void *) >= sizeof(uint64_t);
+}
+
 /* The WNDCLASS-Name for the fake window which we use to retrieve the GL capabilities */
 #define WINED3D_OPENGL_WINDOW_CLASS_NAME "WineD3D_OpenGL"
 




More information about the wine-cvs mailing list