anv: flag BO for write combine when CPU visible and potentially in lmem
authorLionel Landwerlin <lionel.g.landwerlin@intel.com>
Fri, 23 Sep 2022 19:21:10 +0000 (22:21 +0300)
committerMarge Bot <emma+marge@anholt.net>
Wed, 28 Sep 2022 09:51:31 +0000 (09:51 +0000)
This should fix a performance regression with the internal kernel
branch which does not support the upstream I915_MMAP_OFFSET_FIXED.

With I915_MMAP_OFFSET_FIXED we defer the mapping flags to the kernel
since it knows better where buffers are going to end up (lmem or smem).

The internal kernel doesn´t have that and there we should use write
combined for anything that can be in lmem.

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18841>

src/intel/vulkan/anv_device.c

index aa7a5a7..a6fe4c3 100644 (file)
@@ -3923,6 +3923,13 @@ VkResult anv_AllocateMemory(
    if (!(mem_type->propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT))
       alloc_flags |= ANV_BO_ALLOC_NO_LOCAL_MEM;
 
+   /* If the allocated buffer might end up in local memory and it's host
+    * visible, make CPU writes are combined, it should be faster.
+    */
+   if (!(alloc_flags & ANV_BO_ALLOC_NO_LOCAL_MEM) &&
+       (mem_type->propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT))
+      alloc_flags |= ANV_BO_ALLOC_WRITE_COMBINE;
+
    if (vk_flags & VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT)
       alloc_flags |= ANV_BO_ALLOC_CLIENT_VISIBLE_ADDRESS;