anv: Add an explicit_address parameter to anv_device_alloc_bo
authorJason Ekstrand <jason@jlekstrand.net>
Mon, 2 Dec 2019 21:22:38 +0000 (15:22 -0600)
committerJason Ekstrand <jason@jlekstrand.net>
Thu, 5 Dec 2019 16:59:10 +0000 (10:59 -0600)
We already have a mechanism for specifying that we want a fixed address
provided by the driver internals.  We're about to let the client start
specifying addresses in some very special scenarios as well so we want
to pass this through to the allocation function.

Reviewed-by: Ivan Briano <ivan.briano@intel.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
src/intel/vulkan/anv_allocator.c
src/intel/vulkan/anv_descriptor_set.c
src/intel/vulkan/anv_device.c
src/intel/vulkan/anv_private.h
src/intel/vulkan/anv_queue.c
src/intel/vulkan/genX_query.c

index f939a0c7c0e7a5759a76c5f970917a17aedfdb5e..eed6a194dd74f30d610a2c3cc1497f63d079c385 100644 (file)
@@ -498,18 +498,17 @@ anv_block_pool_expand_range(struct anv_block_pool *pool,
    if (pool->use_softpin) {
       uint32_t new_bo_size = size - pool->size;
       struct anv_bo *new_bo;
+      assert(center_bo_offset == 0);
       VkResult result = anv_device_alloc_bo(pool->device, new_bo_size,
                                             bo_alloc_flags |
                                             ANV_BO_ALLOC_FIXED_ADDRESS |
                                             ANV_BO_ALLOC_MAPPED |
                                             ANV_BO_ALLOC_SNOOPED,
+                                            pool->start_address + pool->size,
                                             &new_bo);
       if (result != VK_SUCCESS)
          return result;
 
-      assert(center_bo_offset == 0);
-
-      new_bo->offset = pool->start_address + pool->size;
       pool->bos[pool->nbos++] = new_bo;
 
       /* This pointer will always point to the first BO in the list */
@@ -1316,6 +1315,7 @@ anv_bo_pool_alloc(struct anv_bo_pool *pool, uint32_t size,
                                          pow2_size,
                                          ANV_BO_ALLOC_MAPPED |
                                          ANV_BO_ALLOC_SNOOPED,
+                                         0 /* explicit_address */,
                                          &bo);
    if (result != VK_SUCCESS)
       return result;
@@ -1454,7 +1454,9 @@ anv_scratch_pool_alloc(struct anv_device *device, struct anv_scratch_pool *pool,
     * so nothing will ever touch the top page.
     */
    VkResult result = anv_device_alloc_bo(device, size,
-                                         ANV_BO_ALLOC_32BIT_ADDRESS, &bo);
+                                         ANV_BO_ALLOC_32BIT_ADDRESS,
+                                         0 /* explicit_address */,
+                                         &bo);
    if (result != VK_SUCCESS)
       return NULL; /* TODO */
 
@@ -1528,6 +1530,7 @@ VkResult
 anv_device_alloc_bo(struct anv_device *device,
                     uint64_t size,
                     enum anv_bo_alloc_flags alloc_flags,
+                    uint64_t explicit_address,
                     struct anv_bo **bo_out)
 {
    const uint32_t bo_flags =
@@ -1580,7 +1583,9 @@ anv_device_alloc_bo(struct anv_device *device,
 
    if (alloc_flags & ANV_BO_ALLOC_FIXED_ADDRESS) {
       new_bo.has_fixed_address = true;
+      new_bo.offset = explicit_address;
    } else {
+      assert(explicit_address == 0);
       if (!anv_vma_alloc(device, &new_bo)) {
          if (new_bo.map)
             anv_gem_munmap(new_bo.map, size);
index af8fa40a0a966117dc493e811aaef5d757182ca0..020b6abd5edb12f8a396a3f926c11d6646f23420 100644 (file)
@@ -746,6 +746,7 @@ VkResult anv_CreateDescriptorPool(
                                             descriptor_bo_size,
                                             ANV_BO_ALLOC_MAPPED |
                                             ANV_BO_ALLOC_SNOOPED,
+                                            0 /* explicit_address */,
                                             &pool->bo);
       if (result != VK_SUCCESS) {
          vk_free2(&device->alloc, pAllocator, pool);
index 6a2c25478d18634b135df33af89b63b3b478b144..d300350b78940b456eb05f1a0313cf1909e0eb50 100644 (file)
@@ -2158,6 +2158,7 @@ anv_device_init_trivial_batch(struct anv_device *device)
 {
    VkResult result = anv_device_alloc_bo(device, 4096,
                                          ANV_BO_ALLOC_MAPPED,
+                                         0 /* explicit_address */,
                                          &device->trivial_batch_bo);
    if (result != VK_SUCCESS)
       return result;
@@ -2266,6 +2267,7 @@ anv_device_init_hiz_clear_value_bo(struct anv_device *device)
 {
    VkResult result = anv_device_alloc_bo(device, 4096,
                                          ANV_BO_ALLOC_MAPPED,
+                                         0 /* explicit_address */,
                                          &device->hiz_clear_bo);
    if (result != VK_SUCCESS)
       return result;
@@ -2597,7 +2599,9 @@ VkResult anv_CreateDevice(
          goto fail_binding_table_pool;
    }
 
-   result = anv_device_alloc_bo(device, 4096, 0, &device->workaround_bo);
+   result = anv_device_alloc_bo(device, 4096, 0 /* flags */,
+                                0 /* explicit_address */,
+                                &device->workaround_bo);
    if (result != VK_SUCCESS)
       goto fail_surface_aux_map_pool;
 
@@ -3184,7 +3188,8 @@ VkResult anv_AllocateMemory(
       alloc_flags |= ANV_BO_ALLOC_EXTERNAL;
 
    result = anv_device_alloc_bo(device, pAllocateInfo->allocationSize,
-                                alloc_flags, &mem->bo);
+                                alloc_flags, 0 /* explicit_address */,
+                                &mem->bo);
    if (result != VK_SUCCESS)
       goto fail;
 
index 127af8b01fd1ace6ea35de26002dab99a497489f..3e168f2b66d513e1af326c9fe42f43718b311300 100644 (file)
@@ -1331,7 +1331,10 @@ enum anv_bo_alloc_flags {
    /** Specifies that the BO should be captured in error states */
    ANV_BO_ALLOC_CAPTURE =        (1 << 4),
 
-   /** Specifies that the BO will have an address assigned by the caller */
+   /** Specifies that the BO will have an address assigned by the caller
+    *
+    * Such BOs do not exist in any VMA heap.
+    */
    ANV_BO_ALLOC_FIXED_ADDRESS = (1 << 5),
 
    /** Enables implicit synchronization on the BO
@@ -1349,6 +1352,7 @@ enum anv_bo_alloc_flags {
 
 VkResult anv_device_alloc_bo(struct anv_device *device, uint64_t size,
                              enum anv_bo_alloc_flags alloc_flags,
+                             uint64_t explicit_address,
                              struct anv_bo **bo);
 VkResult anv_device_import_bo_from_host_ptr(struct anv_device *device,
                                             void *host_ptr, uint32_t size,
index 3dedbcade468f5b38d48003c5d22a148465ea203..86010dbba0fe2b19f403d2c5c8869959a0ead2ac 100644 (file)
@@ -167,6 +167,7 @@ anv_timeline_add_point_locked(struct anv_device *device,
          result = anv_device_alloc_bo(device, 4096,
                                       ANV_BO_ALLOC_EXTERNAL |
                                       ANV_BO_ALLOC_IMPLICIT_SYNC,
+                                      0 /* explicit_address */,
                                       &(*point)->bo);
          if (result != VK_SUCCESS)
             vk_free(&device->alloc, *point);
@@ -573,6 +574,7 @@ anv_queue_submit_simple_batch(struct anv_queue *queue,
       result = anv_device_alloc_bo(device, 4096,
                                    ANV_BO_ALLOC_EXTERNAL |
                                    ANV_BO_ALLOC_IMPLICIT_SYNC,
+                                   0 /* explicit_address */,
                                    &sync_bo);
       if (result != VK_SUCCESS)
          goto err_free_submit;
@@ -1669,6 +1671,7 @@ binary_semaphore_create(struct anv_device *device,
          anv_device_alloc_bo(device, 4096,
                              ANV_BO_ALLOC_EXTERNAL |
                              ANV_BO_ALLOC_IMPLICIT_SYNC,
+                             0 /* explicit_address */,
                              &impl->bo);
       /* If we're going to use this as a fence, we need to *not* have the
        * EXEC_OBJECT_ASYNC bit set.
index 0a295cebb87f0a5a004679fe613c490b94116b31..6a512d3ea7b50ce0dc5d6f92cdf87b157ce47d40 100644 (file)
@@ -125,6 +125,7 @@ VkResult genX(CreateQueryPool)(
    result = anv_device_alloc_bo(device, size,
                                 ANV_BO_ALLOC_MAPPED |
                                 ANV_BO_ALLOC_SNOOPED,
+                                0 /* explicit_address */,
                                 &pool->bo);
    if (result != VK_SUCCESS)
       goto fail;