From a5c73399202e8ce6af43010a7e7cea2910ca5b2a Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Mon, 6 Nov 2023 04:31:24 +0100 Subject: [PATCH] gpu: Improve memory handling on Vulkan We now handle the case where memory is not HOST_CACHED. We also track the memory type now so we can avoid mapping image memory that is not HOST_CACHED and use buffer transfers instead. --- gsk/gpu/gskvulkanimage.c | 3 +++ gsk/gpu/gskvulkanmemory.c | 2 ++ gsk/gpu/gskvulkanmemoryprivate.h | 4 ++-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/gsk/gpu/gskvulkanimage.c b/gsk/gpu/gskvulkanimage.c index 15bb2c6385..104cc6a60e 100644 --- a/gsk/gpu/gskvulkanimage.c +++ b/gsk/gpu/gskvulkanimage.c @@ -746,6 +746,9 @@ gsk_vulkan_image_can_map (GskVulkanImage *self) self->vk_image_layout != VK_IMAGE_LAYOUT_GENERAL) return FALSE; + if ((self->allocation.memory_flags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT) == 0) + return FALSE; + return self->allocation.map != NULL; } diff --git a/gsk/gpu/gskvulkanmemory.c b/gsk/gpu/gskvulkanmemory.c index 8bd05dcd52..4e6672caa9 100644 --- a/gsk/gpu/gskvulkanmemory.c +++ b/gsk/gpu/gskvulkanmemory.c @@ -57,6 +57,7 @@ gsk_vulkan_direct_allocator_alloc (GskVulkanAllocator *allocator, alloc->offset = 0; alloc->size = size; + alloc->memory_flags = self->vk_memory_type.propertyFlags; } static void @@ -398,6 +399,7 @@ gsk_vulkan_external_allocator_alloc (GskVulkanAllocator *allocator, alloc->map = NULL; alloc->offset = 0; alloc->size = size; + alloc->memory_flags = 0; } static void diff --git a/gsk/gpu/gskvulkanmemoryprivate.h b/gsk/gpu/gskvulkanmemoryprivate.h index 1f8fb4b08f..6dcb30c05a 100644 --- a/gsk/gpu/gskvulkanmemoryprivate.h +++ b/gsk/gpu/gskvulkanmemoryprivate.h @@ -5,8 +5,7 @@ G_BEGIN_DECLS #define GSK_VULKAN_MEMORY_MAPPABLE (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | \ - VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | \ - VK_MEMORY_PROPERTY_HOST_CACHED_BIT) + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) typedef struct _GskVulkanAllocator GskVulkanAllocator; typedef struct _GskVulkanAllocation GskVulkanAllocation; @@ -18,6 +17,7 @@ struct _GskVulkanAllocation guchar *map; VkDeviceSize offset; VkDeviceSize size; + VkMemoryPropertyFlags memory_flags; }; struct _GskVulkanAllocator