vulkan: Add gsk_vulkan_memory_can_map()

.. nd use it to assert memory is mappable when mapping it.
This commit is contained in:
Benjamin Otte 2023-06-14 02:55:32 +02:00
parent 49c2c2da1a
commit 17dd100f43
2 changed files with 26 additions and 0 deletions

View File

@ -9,6 +9,7 @@ struct _GskVulkanMemory
gsize size;
VkMemoryType vk_memory_type;
VkDeviceMemory vk_memory;
};
@ -41,6 +42,7 @@ gsk_vulkan_memory_new (GdkVulkanContext *context,
g_assert (i < properties.memoryTypeCount);
self->vk_memory_type = properties.memoryTypes[i];
GSK_VK_CHECK (vkAllocateMemory, gdk_vulkan_context_get_device (context),
&(VkMemoryAllocateInfo) {
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
@ -71,11 +73,33 @@ gsk_vulkan_memory_get_device_memory (GskVulkanMemory *self)
return self->vk_memory;
}
gboolean
gsk_vulkan_memory_can_map (GskVulkanMemory *self,
gboolean fast)
{
if (!(self->vk_memory_type.propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT))
return FALSE;
/* FIXME: no support implemented for this */
if (!(self->vk_memory_type.propertyFlags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))
return FALSE;
if (!fast)
return TRUE;
if (!(self->vk_memory_type.propertyFlags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT))
return FALSE;
return TRUE;
}
guchar *
gsk_vulkan_memory_map (GskVulkanMemory *self)
{
void *data;
g_assert (gsk_vulkan_memory_can_map (self, FALSE));
GSK_VK_CHECK (vkMapMemory, gdk_vulkan_context_get_device (self->vulkan),
self->vk_memory,
0,

View File

@ -14,6 +14,8 @@ void gsk_vulkan_memory_free (GskVulk
VkDeviceMemory gsk_vulkan_memory_get_device_memory (GskVulkanMemory *self);
gboolean gsk_vulkan_memory_can_map (GskVulkanMemory *self,
gboolean fast);
guchar * gsk_vulkan_memory_map (GskVulkanMemory *self);
void gsk_vulkan_memory_unmap (GskVulkanMemory *self);