[Mesa-dev] [PATCH 02/12] anv: Refactor anv_bo flag initialisation

Chris Wilson chris at chris-wilson.co.uk
Sun May 14 23:38:46 UTC 2017


Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
---
 src/intel/vulkan/anv_allocator.c | 10 ++--------
 src/intel/vulkan/anv_device.c    |  7 +------
 src/intel/vulkan/anv_intel.c     |  3 +--
 src/intel/vulkan/anv_private.h   | 20 ++++++++++++++++++++
 4 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/src/intel/vulkan/anv_allocator.c b/src/intel/vulkan/anv_allocator.c
index b767542aa5..1e4bb34ee2 100644
--- a/src/intel/vulkan/anv_allocator.c
+++ b/src/intel/vulkan/anv_allocator.c
@@ -535,8 +535,7 @@ anv_block_pool_grow(struct anv_block_pool *pool, struct anv_block_state *state)
 
    result = anv_block_pool_expand_range(pool, center_bo_offset, size);
 
-   if (pool->device->instance->physicalDevice.has_exec_async)
-      pool->bo.flags |= EXEC_OBJECT_ASYNC;
+   anv_bo_set_flags(pool->device, &pool->bo, EXEC_OBJECT_ASYNC);
 
 done:
    pthread_mutex_unlock(&pool->device->mutex);
@@ -1308,12 +1307,7 @@ anv_bo_cache_import(struct anv_device *device,
       bo->refcount = 1;
 
       anv_bo_init(&bo->bo, gem_handle, size);
-
-      if (device->instance->physicalDevice.supports_48bit_addresses)
-         bo->bo.flags |= EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
-
-      if (device->instance->physicalDevice.has_exec_async)
-         bo->bo.flags |= EXEC_OBJECT_ASYNC;
+      anv_bo_set_flags(device, &bo->bo, ANV_BO_DEFAULT_FLAGS);
 
       _mesa_hash_table_insert(cache->bo_map, (void *)(uintptr_t)gem_handle, bo);
    }
diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index 35e40301a3..e4c0a1551a 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -1413,12 +1413,7 @@ anv_bo_init_new(struct anv_bo *bo, struct anv_device *device, uint64_t size)
       return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY);
 
    anv_bo_init(bo, gem_handle, size);
-
-   if (device->instance->physicalDevice.supports_48bit_addresses)
-      bo->flags |= EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
-
-   if (device->instance->physicalDevice.has_exec_async)
-      bo->flags |= EXEC_OBJECT_ASYNC;
+   anv_bo_set_flags(device, bo, ANV_BO_DEFAULT_FLAGS);
 
    return VK_SUCCESS;
 }
diff --git a/src/intel/vulkan/anv_intel.c b/src/intel/vulkan/anv_intel.c
index 991a93542d..f232411231 100644
--- a/src/intel/vulkan/anv_intel.c
+++ b/src/intel/vulkan/anv_intel.c
@@ -56,8 +56,7 @@ VkResult anv_CreateDmaBufImageINTEL(
    if (result != VK_SUCCESS)
       goto fail;
 
-   if (device->instance->physicalDevice.supports_48bit_addresses)
-      mem->bo->flags |= EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
+   anv_bo_set_flags(device, mem->bo, EXEC_OBJECT_SUPPORTS_48B_ADDRESS);
 
    anv_image_create(_device,
       &(struct anv_image_create_info) {
diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
index 9b0dd678fd..ebf9533390 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -808,6 +808,26 @@ int anv_gem_set_caching(struct anv_device *device, uint32_t gem_handle, uint32_t
 int anv_gem_set_domain(struct anv_device *device, uint32_t gem_handle,
                        uint32_t read_domains, uint32_t write_domain);
 
+static inline void
+anv_bo_set_flags(const struct anv_device *device,
+                 struct anv_bo *bo,
+                 unsigned int flags)
+{
+   struct anv_physical_device *phys = &device->instance->physicalDevice;
+
+   if (flags & EXEC_OBJECT_SUPPORTS_48B_ADDRESS &&
+       phys->supports_48bit_addresses)
+      bo->flags |= EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
+
+   if (flags & EXEC_OBJECT_ASYNC &&
+       phys->has_exec_async)
+      bo->flags |= EXEC_OBJECT_ASYNC;
+}
+
+#define ANV_BO_DEFAULT_FLAGS \
+   (EXEC_OBJECT_SUPPORTS_48B_ADDRESS | \
+    EXEC_OBJECT_ASYNC)
+
 VkResult anv_bo_init_new(struct anv_bo *bo, struct anv_device *device, uint64_t size);
 
 struct anv_reloc_list {
-- 
2.11.0



More information about the mesa-dev mailing list