anv: Allocate descriptor buffers from the BO cache
authorJason Ekstrand <jason@jlekstrand.net>
Fri, 25 Oct 2019 22:15:31 +0000 (17:15 -0500)
committerJason Ekstrand <jason@jlekstrand.net>
Thu, 31 Oct 2019 13:46:09 +0000 (13:46 +0000)
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
src/intel/vulkan/anv_descriptor_set.c
src/intel/vulkan/anv_private.h
src/intel/vulkan/genX_cmd_buffer.c

index 3951a665e188821b54335e54967d57f4d9b0d38f..2f7b32b1b82f99556ff4469edd9c593cdc429b5f 100644 (file)
@@ -663,7 +663,6 @@ VkResult anv_CreateDescriptorPool(
     VkDescriptorPool*                           pDescriptorPool)
 {
    ANV_FROM_HANDLE(anv_device, device, _device);
-   const struct anv_physical_device *pdevice = &device->instance->physicalDevice;
    struct anv_descriptor_pool *pool;
 
    const VkDescriptorPoolInlineUniformBlockCreateInfoEXT *inline_info =
@@ -734,36 +733,19 @@ VkResult anv_CreateDescriptorPool(
    pool->free_list = EMPTY;
 
    if (descriptor_bo_size > 0) {
-      VkResult result = anv_bo_init_new(&pool->bo, device, descriptor_bo_size);
+      VkResult result = anv_device_alloc_bo(device,
+                                            descriptor_bo_size,
+                                            ANV_BO_ALLOC_MAPPED |
+                                            ANV_BO_ALLOC_SNOOPED,
+                                            &pool->bo);
       if (result != VK_SUCCESS) {
          vk_free2(&device->alloc, pAllocator, pool);
          return result;
       }
 
-      anv_gem_set_caching(device, pool->bo.gem_handle, I915_CACHING_CACHED);
-
-      pool->bo.map = anv_gem_mmap(device, pool->bo.gem_handle, 0,
-                                  descriptor_bo_size, 0);
-      if (pool->bo.map == NULL) {
-         anv_gem_close(device, pool->bo.gem_handle);
-         vk_free2(&device->alloc, pAllocator, pool);
-         return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
-      }
-
-      if (pdevice->supports_48bit_addresses)
-         pool->bo.flags |= EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
-
-      if (pdevice->use_softpin) {
-         pool->bo.flags |= EXEC_OBJECT_PINNED;
-         anv_vma_alloc(device, &pool->bo);
-      }
-
-      if (pdevice->has_exec_async)
-         pool->bo.flags |= EXEC_OBJECT_ASYNC;
-
       util_vma_heap_init(&pool->bo_heap, POOL_HEAP_OFFSET, descriptor_bo_size);
    } else {
-      pool->bo.size = 0;
+      pool->bo = NULL;
    }
 
    anv_state_stream_init(&pool->surface_state_stream,
@@ -793,12 +775,8 @@ void anv_DestroyDescriptorPool(
       anv_descriptor_set_layout_unref(device, set->layout);
    }
 
-   if (pool->bo.size) {
-      anv_gem_munmap(pool->bo.map, pool->bo.size);
-      anv_vma_free(device, &pool->bo);
-      anv_gem_close(device, pool->bo.gem_handle);
-      util_vma_heap_finish(&pool->bo_heap);
-   }
+   if (pool->bo)
+      anv_device_release_bo(device, pool->bo);
    anv_state_stream_finish(&pool->surface_state_stream);
 
    vk_free2(&device->alloc, pAllocator, pool);
@@ -821,9 +799,9 @@ VkResult anv_ResetDescriptorPool(
    pool->next = 0;
    pool->free_list = EMPTY;
 
-   if (pool->bo.size) {
+   if (pool->bo) {
       util_vma_heap_finish(&pool->bo_heap);
-      util_vma_heap_init(&pool->bo_heap, POOL_HEAP_OFFSET, pool->bo.size);
+      util_vma_heap_init(&pool->bo_heap, POOL_HEAP_OFFSET, pool->bo->size);
    }
 
    anv_state_stream_finish(&pool->surface_state_stream);
@@ -954,13 +932,13 @@ anv_descriptor_set_create(struct anv_device *device,
              pool_vma_offset - POOL_HEAP_OFFSET <= INT32_MAX);
       set->desc_mem.offset = pool_vma_offset - POOL_HEAP_OFFSET;
       set->desc_mem.alloc_size = set_buffer_size;
-      set->desc_mem.map = pool->bo.map + set->desc_mem.offset;
+      set->desc_mem.map = pool->bo->map + set->desc_mem.offset;
 
       set->desc_surface_state = anv_descriptor_pool_alloc_state(pool);
       anv_fill_buffer_surface_state(device, set->desc_surface_state,
                                     ISL_FORMAT_R32G32B32A32_FLOAT,
                                     (struct anv_address) {
-                                       .bo = &pool->bo,
+                                       .bo = pool->bo,
                                        .offset = set->desc_mem.offset,
                                     },
                                     layout->descriptor_buffer_size, 1);
index 0ef2ec73b017d4bf858a607c85906f06f2c6035b..07ef198cb4de8c29a79379c1761a745f3063b65e 100644 (file)
@@ -1889,7 +1889,7 @@ struct anv_descriptor_pool {
    uint32_t next;
    uint32_t free_list;
 
-   struct anv_bo bo;
+   struct anv_bo *bo;
    struct util_vma_heap bo_heap;
 
    struct anv_state_stream surface_state_stream;
index f7a4914739407cfe616a64fdc5101f6309655c05..5301486f192d520c24c6ce2c0501106a386d8f7e 100644 (file)
@@ -2103,7 +2103,7 @@ anv_descriptor_set_address(struct anv_cmd_buffer *cmd_buffer,
    if (set->pool) {
       /* This is a normal descriptor set */
       return (struct anv_address) {
-         .bo = &set->pool->bo,
+         .bo = set->pool->bo,
          .offset = set->desc_mem.offset,
       };
    } else {