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

Author: José Roberto de Souza <[email protected]>
Date:   Fri Dec 15 08:07:32 2023 -0800

anv: Add ANV_BO_ALLOC_IMPORTED

The next patch will replace anv_bo.is_vram by a anv_bo.alloc_flags
check but to that actually work we can't use ANV_BO_ALLOC_NO_LOCAL_MEM
for imported bos, so here adding it.

Cc: mesa-stable
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/10291
Signed-off-by: José Roberto de Souza <[email protected]>
Reviewed-by: Lionel Landwerlin <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26711>

---

 src/intel/vulkan/anv_allocator.c | 9 ++++-----
 src/intel/vulkan/anv_device.c    | 3 ++-
 src/intel/vulkan/anv_private.h   | 6 ++++++
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/src/intel/vulkan/anv_allocator.c b/src/intel/vulkan/anv_allocator.c
index 8134455837d..0c09b0c4c48 100644
--- a/src/intel/vulkan/anv_allocator.c
+++ b/src/intel/vulkan/anv_allocator.c
@@ -1431,7 +1431,8 @@ anv_bo_get_mmap_mode(struct anv_device *device, struct 
anv_bo *bo)
       return anv_device_get_pat_entry(device, alloc_flags)->mmap;
 
    if (anv_physical_device_has_vram(device->physical)) {
-      if (alloc_flags & ANV_BO_ALLOC_NO_LOCAL_MEM)
+      if ((alloc_flags & ANV_BO_ALLOC_NO_LOCAL_MEM) ||
+          (alloc_flags & ANV_BO_ALLOC_IMPORTED))
          return INTEL_DEVICE_INFO_MMAP_MODE_WB;
 
       return INTEL_DEVICE_INFO_MMAP_MODE_WC;
@@ -1665,8 +1666,7 @@ anv_device_import_bo_from_host_ptr(struct anv_device 
*device,
 
       __sync_fetch_and_add(&bo->refcount, 1);
    } else {
-      /* Makes sure that userptr gets WB+1way host caching */
-      alloc_flags |= (ANV_BO_ALLOC_HOST_CACHED_COHERENT | 
ANV_BO_ALLOC_NO_LOCAL_MEM);
+      alloc_flags |= ANV_BO_ALLOC_IMPORTED;
       struct anv_bo new_bo = {
          .name = "host-ptr",
          .gem_handle = gem_handle,
@@ -1756,8 +1756,7 @@ anv_device_import_bo(struct anv_device *device,
 
       __sync_fetch_and_add(&bo->refcount, 1);
    } else {
-      /* so imported bos get WB+1way host caching */
-      alloc_flags |= (ANV_BO_ALLOC_HOST_CACHED_COHERENT | 
ANV_BO_ALLOC_NO_LOCAL_MEM);
+      alloc_flags |= ANV_BO_ALLOC_IMPORTED;
       struct anv_bo new_bo = {
          .name = "imported",
          .gem_handle = gem_handle,
diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index 80bb62977a4..4805cb5f26e 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -5112,7 +5112,8 @@ anv_device_get_pat_entry(struct anv_device *device,
     * This might change in future discrete platforms.
     */
    if (anv_physical_device_has_vram(device->physical)) {
-      if (alloc_flags & ANV_BO_ALLOC_NO_LOCAL_MEM)
+      if ((alloc_flags & ANV_BO_ALLOC_NO_LOCAL_MEM) ||
+          (alloc_flags & ANV_BO_ALLOC_IMPORTED))
          return &device->info->pat.cached_coherent;
       return &device->info->pat.writecombining;
    }
diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
index 40d35066f97..76f103df525 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -436,6 +436,12 @@ enum anv_bo_alloc_flags {
    /** For sampler pools */
    ANV_BO_ALLOC_SAMPLER_POOL =            (1 << 17),
 
+   /** Specifies that the BO is imported.
+    *
+    * Imported BOs must also be marked as ANV_BO_ALLOC_EXTERNAL
+    */
+   ANV_BO_ALLOC_IMPORTED =                (1 << 18),
+
    /** Specifies that the BO should be cached and coherent. */
    ANV_BO_ALLOC_HOST_CACHED_COHERENT =    (ANV_BO_ALLOC_HOST_COHERENT | 
ANV_BO_ALLOC_HOST_CACHED),
 };

Reply via email to