Module: Mesa
Branch: main
Commit: 66dce74d741dd1ede7d05de14d1c1d85fa601c7c
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=66dce74d741dd1ede7d05de14d1c1d85fa601c7c

Author: José Roberto de Souza <jose.so...@intel.com>
Date:   Thu Sep  7 12:29:36 2023 -0700

anv: Honor memory coherency of the memory type selected

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 <jose.so...@intel.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwer...@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26099>

---

 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.
        */

Reply via email to