From 66dce74d741dd1ede7d05de14d1c1d85fa601c7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Roberto=20de=20Souza?= Date: Thu, 7 Sep 2023 12:29:36 -0700 Subject: [PATCH] anv: Honor memory coherency of the memory type selected MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Integrated GPUs almost always works with write-back caching(only scanout and external bos works in write-combine) but in platforms without LLC the coherency is broken if not explict asked to KMD. vkFlushMappedMemoryRanges and vkInvalidateMappedMemoryRanges() don't do any flushing or invalidate for memory allocated with VK_MEMORY_PROPERTY_HOST_COHERENT_BIT. So if an application asked for a memory coherent, the ANV_BO_ALLOC_SNOOPED flag needs to be set in alloc_flags and that will be passed to KMD backends to properly ask to KMD for coherent buffer. The other chunk here removes the assert(alloc_flags & ANV_BO_ALLOC_MAPPED), that is needed otherwise application can't ask for a coherent and mapped memory. Tried to find a reason for that assert in git history but did not found what was the reasoning of this assert. Signed-off-by: José Roberto de Souza Reviewed-by: Lionel Landwerlin Part-of: --- src/intel/vulkan/anv_device.c | 5 +++++ src/intel/vulkan/i915/anv_kmd_backend.c | 1 - 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index 3fea16a96d4..90197b4dcf3 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -4036,6 +4036,11 @@ VkResult anv_AllocateMemory( if (mem->vk.export_handle_types || mem->vk.import_handle_type) alloc_flags |= (ANV_BO_ALLOC_EXTERNAL | ANV_BO_ALLOC_IMPLICIT_SYNC); + if ((mem_type->propertyFlags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) && + (mem_type->propertyFlags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT) && + (alloc_flags & (ANV_BO_ALLOC_EXTERNAL | ANV_BO_ALLOC_SCANOUT)) == 0) + alloc_flags |= ANV_BO_ALLOC_SNOOPED; + if (mem->vk.ahardware_buffer) { result = anv_import_ahw_memory(_device, mem); if (result != VK_SUCCESS) diff --git a/src/intel/vulkan/i915/anv_kmd_backend.c b/src/intel/vulkan/i915/anv_kmd_backend.c index 78d7ef9fcb4..e01c0264596 100644 --- a/src/intel/vulkan/i915/anv_kmd_backend.c +++ b/src/intel/vulkan/i915/anv_kmd_backend.c @@ -108,7 +108,6 @@ i915_gem_create(struct anv_device *device, *actual_size = gem_create.size; if (alloc_flags & ANV_BO_ALLOC_SNOOPED) { - assert(alloc_flags & ANV_BO_ALLOC_MAPPED); /* We don't want to change these defaults if it's going to be shared * with another process. */