anv: Replace ANV_BO_EXTERNAL with anv_bo::is_external

We're not THAT strapped for space that we can't burn one extra bit for
a boolean.  If we're really worried about it, we can always shrink the
flags field to 16 bits because the kernel only uses 7 currently.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
This commit is contained in:
Jason Ekstrand
2019-10-28 20:12:24 -05:00
parent 5534358ef6
commit b781c85c79
6 changed files with 22 additions and 20 deletions

View File

@@ -1624,13 +1624,13 @@ anv_bo_cache_lookup(struct anv_bo_cache *cache, uint32_t gem_handle)
(EXEC_OBJECT_WRITE | \
EXEC_OBJECT_ASYNC | \
EXEC_OBJECT_SUPPORTS_48B_ADDRESS | \
EXEC_OBJECT_PINNED | \
ANV_BO_EXTERNAL)
EXEC_OBJECT_PINNED)
VkResult
anv_bo_cache_alloc(struct anv_device *device,
struct anv_bo_cache *cache,
uint64_t size, uint64_t bo_flags,
bool is_external,
struct anv_bo **bo_out)
{
assert(bo_flags == (bo_flags & ANV_BO_CACHE_SUPPORTED_FLAGS));
@@ -1644,6 +1644,7 @@ anv_bo_cache_alloc(struct anv_device *device,
return result;
new_bo.flags = bo_flags;
new_bo.is_external = is_external;
if (!anv_vma_alloc(device, &new_bo)) {
anv_gem_close(device, new_bo.gem_handle);
@@ -1672,7 +1673,6 @@ anv_bo_cache_import_host_ptr(struct anv_device *device,
uint64_t bo_flags, struct anv_bo **bo_out)
{
assert(bo_flags == (bo_flags & ANV_BO_CACHE_SUPPORTED_FLAGS));
assert((bo_flags & ANV_BO_EXTERNAL) == 0);
uint32_t gem_handle = anv_gem_userptr(device, host_ptr, size);
if (!gem_handle)
@@ -1698,6 +1698,7 @@ anv_bo_cache_import_host_ptr(struct anv_device *device,
struct anv_bo new_bo;
anv_bo_init(&new_bo, gem_handle, size);
new_bo.flags = bo_flags;
new_bo.is_external = true;
if (!anv_vma_alloc(device, &new_bo)) {
anv_gem_close(device, new_bo.gem_handle);
@@ -1723,7 +1724,6 @@ anv_bo_cache_import(struct anv_device *device,
struct anv_bo **bo_out)
{
assert(bo_flags == (bo_flags & ANV_BO_CACHE_SUPPORTED_FLAGS));
assert(bo_flags & ANV_BO_EXTERNAL);
pthread_mutex_lock(&cache->mutex);
@@ -1740,7 +1740,7 @@ anv_bo_cache_import(struct anv_device *device,
* client has imported a BO twice in different ways and they get what
* they have coming.
*/
uint64_t new_flags = ANV_BO_EXTERNAL;
uint64_t new_flags = 0;
new_flags |= (bo->flags | bo_flags) & EXEC_OBJECT_WRITE;
new_flags |= (bo->flags & bo_flags) & EXEC_OBJECT_ASYNC;
new_flags |= (bo->flags & bo_flags) & EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
@@ -1789,6 +1789,7 @@ anv_bo_cache_import(struct anv_device *device,
struct anv_bo new_bo;
anv_bo_init(&new_bo, gem_handle, size);
new_bo.flags = bo_flags;
new_bo.is_external = true;
if (!anv_vma_alloc(device, &new_bo)) {
anv_gem_close(device, new_bo.gem_handle);
@@ -1818,7 +1819,7 @@ anv_bo_cache_export(struct anv_device *device,
* to export it. This is done based on external options passed into
* anv_AllocateMemory.
*/
assert(bo->flags & ANV_BO_EXTERNAL);
assert(bo->is_external);
int fd = anv_gem_handle_to_fd(device, bo->gem_handle);
if (fd < 0)

View File

@@ -1113,7 +1113,7 @@ anv_execbuf_add_bo(struct anv_execbuf *exec,
obj->relocs_ptr = 0;
obj->alignment = 0;
obj->offset = bo->offset;
obj->flags = (bo->flags & ~ANV_BO_FLAG_MASK) | extra_flags;
obj->flags = bo->flags | extra_flags;
obj->rsvd1 = 0;
obj->rsvd2 = 0;
}

View File

@@ -3177,7 +3177,7 @@ VkResult anv_AllocateMemory(
VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT);
result = anv_bo_cache_import(device, &device->bo_cache, fd_info->fd,
bo_flags | ANV_BO_EXTERNAL, &mem->bo);
bo_flags, &mem->bo);
if (result != VK_SUCCESS)
goto fail;
@@ -3242,11 +3242,10 @@ VkResult anv_AllocateMemory(
/* Regular allocate (not importing memory). */
if (export_info && export_info->handleTypes)
bo_flags |= ANV_BO_EXTERNAL;
bool is_external = export_info && export_info->handleTypes;
result = anv_bo_cache_alloc(device, &device->bo_cache,
pAllocateInfo->allocationSize, bo_flags,
pAllocateInfo->allocationSize,
bo_flags, is_external,
&mem->bo);
if (result != VK_SUCCESS)
goto fail;

View File

@@ -72,7 +72,7 @@ VkResult anv_CreateDmaBufImageINTEL(
image = anv_image_from_handle(image_h);
uint64_t bo_flags = ANV_BO_EXTERNAL;
uint64_t bo_flags = 0;
if (device->instance->physicalDevice.supports_48bit_addresses)
bo_flags |= EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
if (device->instance->physicalDevice.use_softpin)

View File

@@ -597,10 +597,6 @@ anv_multialloc_alloc2(struct anv_multialloc *ma,
return anv_multialloc_alloc(ma, alloc ? alloc : parent_alloc, scope);
}
/* Extra ANV-defined BO flags which won't be passed to the kernel */
#define ANV_BO_EXTERNAL (1ull << 31)
#define ANV_BO_FLAG_MASK (1ull << 31)
struct anv_bo {
uint32_t gem_handle;
@@ -623,6 +619,9 @@ struct anv_bo {
/** Flags to pass to the kernel through drm_i915_exec_object2::flags */
uint32_t flags;
/** True if this BO may be shared with other processes */
bool is_external:1;
};
static inline void
@@ -635,6 +634,7 @@ anv_bo_init(struct anv_bo *bo, uint32_t gem_handle, uint64_t size)
bo->size = size;
bo->map = NULL;
bo->flags = 0;
bo->is_external = false;
}
/* Represents a lock-free linked list of "free" things. This is used by
@@ -901,6 +901,7 @@ void anv_bo_cache_finish(struct anv_bo_cache *cache);
VkResult anv_bo_cache_alloc(struct anv_device *device,
struct anv_bo_cache *cache,
uint64_t size, uint64_t bo_flags,
bool is_external,
struct anv_bo **bo);
VkResult anv_bo_cache_import_host_ptr(struct anv_device *device,
struct anv_bo_cache *cache,
@@ -1219,7 +1220,7 @@ anv_binding_table_pool_free(struct anv_device *device, struct anv_state state) {
static inline uint32_t
anv_mocs_for_bo(const struct anv_device *device, const struct anv_bo *bo)
{
if (bo->flags & ANV_BO_EXTERNAL)
if (bo->is_external)
return device->external_mocs;
else
return device->default_mocs;

View File

@@ -952,7 +952,8 @@ VkResult anv_CreateSemaphore(
} else {
semaphore->permanent.type = ANV_SEMAPHORE_TYPE_BO;
VkResult result = anv_bo_cache_alloc(device, &device->bo_cache,
4096, ANV_BO_EXTERNAL,
4096, 0 /* flags */,
true /* is_external */,
&semaphore->permanent.bo);
if (result != VK_SUCCESS) {
vk_free2(&device->alloc, pAllocator, semaphore);
@@ -1106,7 +1107,7 @@ VkResult anv_ImportSemaphoreFdKHR(
new_impl.type = ANV_SEMAPHORE_TYPE_BO;
VkResult result = anv_bo_cache_import(device, &device->bo_cache,
fd, ANV_BO_EXTERNAL,
fd, 0 /* flags */,
&new_impl.bo);
if (result != VK_SUCCESS)
return result;