[Mesa-dev] [PATCH 1/2] anv: Add support for 48-bit addresses

Jason Ekstrand jason at jlekstrand.net
Sat Mar 18 04:24:08 UTC 2017


This commit adds support for using the full 48-bit address space on
Broadwell and newer hardware.  Thanks to certain limitations, not all
objects can be placed above the 32-bit boundary.  In particular, general
and state base address need to live within 32 bits.  (See also
Wa32bitGeneralStateOffset and Wa32bitInstructionBaseOffset.)  In order
to handle this, we add a supports_48bit_address field to anv_bo and only
set EXEC_OBJECT_SUPPORTS_48B_ADDRESS if that bit is set.  We set the bit
for all client-allocated memory objects but leave it false for
driver-allocated objects.  While this is more conservative than needed,
all driver allocations should easily fit in the first 32 bits of address
space and keeps things simple because we don't have to think about
whether or not any given one of our allocation data structures will be
used in a 48-bit-unsafe way.
---
 src/intel/vulkan/anv_batch_chain.c | 14 ++++++++++----
 src/intel/vulkan/anv_device.c      |  5 +++++
 src/intel/vulkan/anv_gem.c         | 18 ++++++++++++++++++
 src/intel/vulkan/anv_private.h     |  9 ++++++++-
 4 files changed, 41 insertions(+), 5 deletions(-)

diff --git a/src/intel/vulkan/anv_batch_chain.c b/src/intel/vulkan/anv_batch_chain.c
index 5d7abc6..b098e4b 100644
--- a/src/intel/vulkan/anv_batch_chain.c
+++ b/src/intel/vulkan/anv_batch_chain.c
@@ -979,7 +979,8 @@ anv_execbuf_finish(struct anv_execbuf *exec,
 }
 
 static VkResult
-anv_execbuf_add_bo(struct anv_execbuf *exec,
+anv_execbuf_add_bo(struct anv_device *device,
+                   struct anv_execbuf *exec,
                    struct anv_bo *bo,
                    struct anv_reloc_list *relocs,
                    const VkAllocationCallbacks *alloc)
@@ -1039,6 +1040,10 @@ anv_execbuf_add_bo(struct anv_execbuf *exec,
       obj->flags = bo->is_winsys_bo ? EXEC_OBJECT_WRITE : 0;
       obj->rsvd1 = 0;
       obj->rsvd2 = 0;
+
+      if (device->instance->physicalDevice.supports_48bit_addresses &&
+          bo->supports_48bit_address)
+         obj->flags |= EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
    }
 
    if (relocs != NULL && obj->relocation_count == 0) {
@@ -1052,7 +1057,7 @@ anv_execbuf_add_bo(struct anv_execbuf *exec,
       for (size_t i = 0; i < relocs->num_relocs; i++) {
          /* A quick sanity check on relocations */
          assert(relocs->relocs[i].offset < bo->size);
-         anv_execbuf_add_bo(exec, relocs->reloc_bos[i], NULL, alloc);
+         anv_execbuf_add_bo(device, exec, relocs->reloc_bos[i], NULL, alloc);
       }
    }
 
@@ -1264,7 +1269,8 @@ anv_cmd_buffer_execbuf(struct anv_device *device,
    adjust_relocations_from_state_pool(ss_pool, &cmd_buffer->surface_relocs,
                                       cmd_buffer->last_ss_pool_center);
    VkResult result =
-      anv_execbuf_add_bo(&execbuf, &ss_pool->bo, &cmd_buffer->surface_relocs,
+      anv_execbuf_add_bo(device, &execbuf, &ss_pool->bo,
+                         &cmd_buffer->surface_relocs,
                          &cmd_buffer->pool->alloc);
    if (result != VK_SUCCESS)
       return result;
@@ -1277,7 +1283,7 @@ anv_cmd_buffer_execbuf(struct anv_device *device,
       adjust_relocations_to_state_pool(ss_pool, &(*bbo)->bo, &(*bbo)->relocs,
                                        cmd_buffer->last_ss_pool_center);
 
-      anv_execbuf_add_bo(&execbuf, &(*bbo)->bo, &(*bbo)->relocs,
+      anv_execbuf_add_bo(device, &execbuf, &(*bbo)->bo, &(*bbo)->relocs,
                          &cmd_buffer->pool->alloc);
    }
 
diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index 92ff8ad..8994e70 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -149,6 +149,8 @@ anv_physical_device_init(struct anv_physical_device *device,
       goto fail;
    }
 
+   device->supports_48bit_addresses = anv_gem_supports_48b_addresses(fd);
+
    if (!anv_device_get_cache_uuid(device->uuid)) {
       result = vk_errorf(VK_ERROR_INITIALIZATION_FAILED,
                          "cannot generate UUID");
@@ -1411,6 +1413,9 @@ VkResult anv_AllocateMemory(
    if (result != VK_SUCCESS)
       goto fail;
 
+   /* Client memory objects should all be 48-bit safe. */
+   mem->bo.supports_48bit_address = true;
+
    mem->type_index = pAllocateInfo->memoryTypeIndex;
 
    mem->map = NULL;
diff --git a/src/intel/vulkan/anv_gem.c b/src/intel/vulkan/anv_gem.c
index 0dde6d9..3d45243 100644
--- a/src/intel/vulkan/anv_gem.c
+++ b/src/intel/vulkan/anv_gem.c
@@ -301,6 +301,24 @@ anv_gem_get_aperture(int fd, uint64_t *size)
    return 0;
 }
 
+bool
+anv_gem_supports_48b_addresses(int fd)
+{
+   struct drm_i915_gem_exec_object2 obj = {
+      .flags = EXEC_OBJECT_SUPPORTS_48B_ADDRESS,
+   };
+
+   struct drm_i915_gem_execbuffer2 execbuf = {
+      .buffers_ptr = (uintptr_t)&obj,
+      .buffer_count = 1,
+      .rsvd1 = 0xffffffu,
+   };
+
+   int ret = anv_ioctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, &execbuf);
+
+   return ret == -1 && errno == ENOENT;
+}
+
 int
 anv_gem_handle_to_fd(struct anv_device *device, uint32_t gem_handle)
 {
diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
index 82a3be2..99277f0 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -299,7 +299,12 @@ struct anv_bo {
     * writing to them and synchronize uses on other rings (eg if the display
     * server uses the blitter ring).
     */
-   bool is_winsys_bo;
+   bool is_winsys_bo:1;
+
+   /* Whether or not this BO supports having a 48-bit address.  If the kernel
+    * or hardware does not support 48-bit addresses, this field is ignored.
+    */
+   bool supports_48bit_address:1;
 };
 
 static inline void
@@ -311,6 +316,7 @@ anv_bo_init(struct anv_bo *bo, uint32_t gem_handle, uint64_t size)
    bo->size = size;
    bo->map = NULL;
    bo->is_winsys_bo = false;
+   bo->supports_48bit_address = false;
 }
 
 /* Represents a lock-free linked list of "free" things.  This is used by
@@ -653,6 +659,7 @@ int anv_gem_destroy_context(struct anv_device *device, int context);
 int anv_gem_get_param(int fd, uint32_t param);
 bool anv_gem_get_bit6_swizzle(int fd, uint32_t tiling);
 int anv_gem_get_aperture(int fd, uint64_t *size);
+bool anv_gem_supports_48b_addresses(int fd);
 int anv_gem_handle_to_fd(struct anv_device *device, uint32_t gem_handle);
 uint32_t anv_gem_fd_to_handle(struct anv_device *device, int fd);
 int anv_gem_set_caching(struct anv_device *device, uint32_t gem_handle, uint32_t caching);
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list