[PATCH 6/8] wined3d: Allow passing a NULL context to wined3d_device_vk_create_bo().

Zebediah Figura zfigura at codeweavers.com
Tue Nov 2 18:20:11 CDT 2021


Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
---
 dlls/wined3d/context_vk.c | 19 +++++++------------
 dlls/wined3d/utils.c      |  3 +++
 2 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/dlls/wined3d/context_vk.c b/dlls/wined3d/context_vk.c
index 21239bd74b9..25c41a49c34 100644
--- a/dlls/wined3d/context_vk.c
+++ b/dlls/wined3d/context_vk.c
@@ -314,14 +314,14 @@ static struct wined3d_allocator_block *wined3d_device_vk_allocate_memory(struct
 
     EnterCriticalSection(&device_vk->allocator_cs);
 
-    if (size > WINED3D_ALLOCATOR_CHUNK_SIZE / 2)
+    if (context_vk && size > WINED3D_ALLOCATOR_CHUNK_SIZE / 2)
     {
         *vk_memory = wined3d_context_vk_allocate_vram_chunk_memory(context_vk, memory_type, size);
         LeaveCriticalSection(&device_vk->allocator_cs);
         return NULL;
     }
 
-    if (!(block = wined3d_allocator_allocate(allocator, &context_vk->c, memory_type, size)))
+    if (!(block = wined3d_allocator_allocate(allocator, context_vk ? &context_vk->c : NULL, memory_type, size)))
     {
         LeaveCriticalSection(&device_vk->allocator_cs);
         *vk_memory = VK_NULL_HANDLE;
@@ -345,13 +345,14 @@ static void wined3d_device_vk_free_memory(struct wined3d_device_vk *device_vk, s
 static bool wined3d_device_vk_create_slab_bo(struct wined3d_device_vk *device_vk, struct wined3d_context_vk *context_vk,
         VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags memory_type, struct wined3d_bo_vk *bo)
 {
-    const struct wined3d_adapter_vk *adapter_vk = wined3d_adapter_vk(context_vk->c.device->adapter);
+    const struct wined3d_adapter_vk *adapter_vk = wined3d_adapter_vk(device_vk->d.adapter);
     const VkPhysicalDeviceLimits *limits = &adapter_vk->device_limits;
     struct wined3d_bo_slab_vk_key key;
     struct wined3d_bo_slab_vk *slab;
     struct wine_rb_entry *entry;
     size_t object_size, idx;
     size_t alignment;
+    int ret;
 
     if (size > WINED3D_ALLOCATOR_MIN_BLOCK_SIZE / 2)
         return false;
@@ -398,14 +399,8 @@ static bool wined3d_device_vk_create_slab_bo(struct wined3d_device_vk *device_vk
         }
         slab->map = ~0u;
 
-        if (wine_rb_put(&device_vk->bo_slab_available, &key, &slab->entry) < 0)
-        {
-            ERR("Failed to add slab to available tree.\n");
-            wined3d_context_vk_destroy_bo(context_vk, &slab->bo);
-            heap_free(slab);
-            return false;
-        }
-
+        ret = wine_rb_put(&device_vk->bo_slab_available, &key, &slab->entry);
+        assert(!ret);
         TRACE("Created new bo slab %p.\n", slab);
     }
 
@@ -445,7 +440,7 @@ static bool wined3d_device_vk_create_slab_bo(struct wined3d_device_vk *device_vk
 BOOL wined3d_device_vk_create_bo(struct wined3d_device_vk *device_vk, struct wined3d_context_vk *context_vk,
         VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags memory_type, struct wined3d_bo_vk *bo)
 {
-    const struct wined3d_vk_info *vk_info = context_vk->vk_info;
+    const struct wined3d_vk_info *vk_info = &device_vk->vk_info;
     VkMemoryRequirements memory_requirements;
     struct wined3d_adapter_vk *adapter_vk;
     VkBufferCreateInfo create_info;
diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c
index 29326668e07..3746eff270b 100644
--- a/dlls/wined3d/utils.c
+++ b/dlls/wined3d/utils.c
@@ -7408,6 +7408,9 @@ struct wined3d_allocator_block *wined3d_allocator_allocate(struct wined3d_alloca
             return block;
     }
 
+    if (!context)
+        return NULL;
+
     if (!(chunk = allocator->ops->allocator_create_chunk(allocator,
             context, memory_type, WINED3D_ALLOCATOR_CHUNK_SIZE)))
         return NULL;
-- 
2.33.0




More information about the wine-devel mailing list