From e54d334526af4f717198af148c3d8093379f9f81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Manuel=20J=C3=A1quez=20Leal?= Date: Wed, 4 Jan 2023 17:30:47 +0100 Subject: [PATCH] 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: --- .../gst-libs/gst/vulkan/gstvkmemory.c | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkmemory.c b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkmemory.c index 40ed31e8ff..5bec9213e6 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkmemory.c +++ b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkmemory.c @@ -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); }