vulkan: memory: Flush non coherent memory after write.

Spec 7.1.3:

If a memory object does not have the VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
property, then vkFlushMappedMemoryRanges must be called in order to guarantee
that writes to the memory object from the host are made available to the host
domain, where they can be further made available to the device domain via a
domain operation. Similarly, vkInvalidateMappedMemoryRanges must be called to
guarantee that writes which are available to the host domain are made visible to
host operations.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3723>
This commit is contained in:
Víctor Manuel Jáquez Leal 2023-01-04 17:30:47 +01:00 committed by GStreamer Marge Bot
parent 621feb32e9
commit e54d334526

View file

@ -142,6 +142,27 @@ _vk_mem_map_full (GstVulkanMemory * mem, GstMapInfo * info, gsize size)
static void
_vk_mem_unmap_full (GstVulkanMemory * mem, GstMapInfo * info)
{
if ((info->flags & GST_MAP_WRITE)
&& !(mem->properties & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) {
GError *error = NULL;
VkResult err;
VkMappedMemoryRange range = {
.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,
/* .pNext = */
.memory = mem->mem_ptr,
.offset = mem->vk_offset,
.size = mem->mem.size,
};
err = vkFlushMappedMemoryRanges (mem->device->device, 1u, &range);
if (gst_vulkan_error_to_g_error (err, &error,
"vkFlushMappedMemoryRanges") < 0) {
GST_CAT_WARNING (GST_CAT_VULKAN_MEMORY, "Failed to flush memory: %s",
error->message);
g_clear_error (&error);
}
}
vkUnmapMemory (mem->device->device, mem->mem_ptr);
}