Mesa (main): anv: Agressively no-op Flush/InvalidateMappedMemoryRanges

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Jun 15 21:24:37 UTC 2021


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

Author: Jason Ekstrand <jason at jlekstrand.net>
Date:   Mon Jun 14 15:10:17 2021 -0500

anv: Agressively no-op Flush/InvalidateMappedMemoryRanges

This has two steps.  First, for each range we look at the memory object
and see if it actually needs flushing before we start throwing CLFLUSH
instructions.  Second, we look at the whole list of types on device
initialization and decide whether or not we need CLFLUSH at all.  The
first part should speed up atom chips a bit since we're currently
CLFLUSHing everything even when we don't need to.  The second isn't
needed on most of today's parts because we base it on !has_llc but it is
needed for discrete parts.  It's also over-all cleaner.

Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
Tested-by: Felix DeGrood <felix.j.degrood at intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11364>

---

 src/intel/vulkan/anv_device.c  | 15 +++++++++++++--
 src/intel/vulkan/anv_private.h |  1 +
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index 547ed88522a..7a66f629ee6 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -444,6 +444,14 @@ anv_physical_device_init_heaps(struct anv_physical_device *device, int fd)
       };
    }
 
+   device->memory.need_clflush = false;
+   for (unsigned i = 0; i < device->memory.type_count; i++) {
+      VkMemoryPropertyFlags props = device->memory.types[i].propertyFlags;
+      if ((props & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) &&
+          !(props & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))
+         device->memory.need_clflush = true;
+   }
+
    return VK_SUCCESS;
 }
 
@@ -4138,6 +4146,9 @@ clflush_mapped_ranges(struct anv_device         *device,
       if (ranges[i].offset >= mem->map_size)
          continue;
 
+      if (mem->type->propertyFlags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)
+         continue;
+
       intel_clflush_range(mem->map + ranges[i].offset,
                         MIN2(ranges[i].size, mem->map_size - ranges[i].offset));
    }
@@ -4150,7 +4161,7 @@ VkResult anv_FlushMappedMemoryRanges(
 {
    ANV_FROM_HANDLE(anv_device, device, _device);
 
-   if (device->info.has_llc)
+   if (!device->physical->memory.need_clflush)
       return VK_SUCCESS;
 
    /* Make sure the writes we're flushing have landed. */
@@ -4168,7 +4179,7 @@ VkResult anv_InvalidateMappedMemoryRanges(
 {
    ANV_FROM_HANDLE(anv_device, device, _device);
 
-   if (device->info.has_llc)
+   if (!device->physical->memory.need_clflush)
       return VK_SUCCESS;
 
    clflush_mapped_ranges(device, memoryRangeCount, pMemoryRanges);
diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
index bf96b7b5851..0e31f98085b 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -965,6 +965,7 @@ struct anv_physical_device {
       struct anv_memory_type                    types[VK_MAX_MEMORY_TYPES];
       uint32_t                                  heap_count;
       struct anv_memory_heap                    heaps[VK_MAX_MEMORY_HEAPS];
+      bool                                      need_clflush;
     } memory;
 
     struct anv_memregion                        vram;



More information about the mesa-commit mailing list