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:
@@ -1624,13 +1624,13 @@ anv_bo_cache_lookup(struct anv_bo_cache *cache, uint32_t gem_handle)
|
|||||||
(EXEC_OBJECT_WRITE | \
|
(EXEC_OBJECT_WRITE | \
|
||||||
EXEC_OBJECT_ASYNC | \
|
EXEC_OBJECT_ASYNC | \
|
||||||
EXEC_OBJECT_SUPPORTS_48B_ADDRESS | \
|
EXEC_OBJECT_SUPPORTS_48B_ADDRESS | \
|
||||||
EXEC_OBJECT_PINNED | \
|
EXEC_OBJECT_PINNED)
|
||||||
ANV_BO_EXTERNAL)
|
|
||||||
|
|
||||||
VkResult
|
VkResult
|
||||||
anv_bo_cache_alloc(struct anv_device *device,
|
anv_bo_cache_alloc(struct anv_device *device,
|
||||||
struct anv_bo_cache *cache,
|
struct anv_bo_cache *cache,
|
||||||
uint64_t size, uint64_t bo_flags,
|
uint64_t size, uint64_t bo_flags,
|
||||||
|
bool is_external,
|
||||||
struct anv_bo **bo_out)
|
struct anv_bo **bo_out)
|
||||||
{
|
{
|
||||||
assert(bo_flags == (bo_flags & ANV_BO_CACHE_SUPPORTED_FLAGS));
|
assert(bo_flags == (bo_flags & ANV_BO_CACHE_SUPPORTED_FLAGS));
|
||||||
@@ -1644,6 +1644,7 @@ anv_bo_cache_alloc(struct anv_device *device,
|
|||||||
return result;
|
return result;
|
||||||
|
|
||||||
new_bo.flags = bo_flags;
|
new_bo.flags = bo_flags;
|
||||||
|
new_bo.is_external = is_external;
|
||||||
|
|
||||||
if (!anv_vma_alloc(device, &new_bo)) {
|
if (!anv_vma_alloc(device, &new_bo)) {
|
||||||
anv_gem_close(device, new_bo.gem_handle);
|
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)
|
uint64_t bo_flags, struct anv_bo **bo_out)
|
||||||
{
|
{
|
||||||
assert(bo_flags == (bo_flags & ANV_BO_CACHE_SUPPORTED_FLAGS));
|
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);
|
uint32_t gem_handle = anv_gem_userptr(device, host_ptr, size);
|
||||||
if (!gem_handle)
|
if (!gem_handle)
|
||||||
@@ -1698,6 +1698,7 @@ anv_bo_cache_import_host_ptr(struct anv_device *device,
|
|||||||
struct anv_bo new_bo;
|
struct anv_bo new_bo;
|
||||||
anv_bo_init(&new_bo, gem_handle, size);
|
anv_bo_init(&new_bo, gem_handle, size);
|
||||||
new_bo.flags = bo_flags;
|
new_bo.flags = bo_flags;
|
||||||
|
new_bo.is_external = true;
|
||||||
|
|
||||||
if (!anv_vma_alloc(device, &new_bo)) {
|
if (!anv_vma_alloc(device, &new_bo)) {
|
||||||
anv_gem_close(device, new_bo.gem_handle);
|
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)
|
struct anv_bo **bo_out)
|
||||||
{
|
{
|
||||||
assert(bo_flags == (bo_flags & ANV_BO_CACHE_SUPPORTED_FLAGS));
|
assert(bo_flags == (bo_flags & ANV_BO_CACHE_SUPPORTED_FLAGS));
|
||||||
assert(bo_flags & ANV_BO_EXTERNAL);
|
|
||||||
|
|
||||||
pthread_mutex_lock(&cache->mutex);
|
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
|
* client has imported a BO twice in different ways and they get what
|
||||||
* they have coming.
|
* 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_WRITE;
|
||||||
new_flags |= (bo->flags & bo_flags) & EXEC_OBJECT_ASYNC;
|
new_flags |= (bo->flags & bo_flags) & EXEC_OBJECT_ASYNC;
|
||||||
new_flags |= (bo->flags & bo_flags) & EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
|
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;
|
struct anv_bo new_bo;
|
||||||
anv_bo_init(&new_bo, gem_handle, size);
|
anv_bo_init(&new_bo, gem_handle, size);
|
||||||
new_bo.flags = bo_flags;
|
new_bo.flags = bo_flags;
|
||||||
|
new_bo.is_external = true;
|
||||||
|
|
||||||
if (!anv_vma_alloc(device, &new_bo)) {
|
if (!anv_vma_alloc(device, &new_bo)) {
|
||||||
anv_gem_close(device, new_bo.gem_handle);
|
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
|
* to export it. This is done based on external options passed into
|
||||||
* anv_AllocateMemory.
|
* anv_AllocateMemory.
|
||||||
*/
|
*/
|
||||||
assert(bo->flags & ANV_BO_EXTERNAL);
|
assert(bo->is_external);
|
||||||
|
|
||||||
int fd = anv_gem_handle_to_fd(device, bo->gem_handle);
|
int fd = anv_gem_handle_to_fd(device, bo->gem_handle);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
|
@@ -1113,7 +1113,7 @@ anv_execbuf_add_bo(struct anv_execbuf *exec,
|
|||||||
obj->relocs_ptr = 0;
|
obj->relocs_ptr = 0;
|
||||||
obj->alignment = 0;
|
obj->alignment = 0;
|
||||||
obj->offset = bo->offset;
|
obj->offset = bo->offset;
|
||||||
obj->flags = (bo->flags & ~ANV_BO_FLAG_MASK) | extra_flags;
|
obj->flags = bo->flags | extra_flags;
|
||||||
obj->rsvd1 = 0;
|
obj->rsvd1 = 0;
|
||||||
obj->rsvd2 = 0;
|
obj->rsvd2 = 0;
|
||||||
}
|
}
|
||||||
|
@@ -3177,7 +3177,7 @@ VkResult anv_AllocateMemory(
|
|||||||
VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT);
|
VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT);
|
||||||
|
|
||||||
result = anv_bo_cache_import(device, &device->bo_cache, fd_info->fd,
|
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)
|
if (result != VK_SUCCESS)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
@@ -3242,11 +3242,10 @@ VkResult anv_AllocateMemory(
|
|||||||
|
|
||||||
/* Regular allocate (not importing memory). */
|
/* Regular allocate (not importing memory). */
|
||||||
|
|
||||||
if (export_info && export_info->handleTypes)
|
bool is_external = export_info && export_info->handleTypes;
|
||||||
bo_flags |= ANV_BO_EXTERNAL;
|
|
||||||
|
|
||||||
result = anv_bo_cache_alloc(device, &device->bo_cache,
|
result = anv_bo_cache_alloc(device, &device->bo_cache,
|
||||||
pAllocateInfo->allocationSize, bo_flags,
|
pAllocateInfo->allocationSize,
|
||||||
|
bo_flags, is_external,
|
||||||
&mem->bo);
|
&mem->bo);
|
||||||
if (result != VK_SUCCESS)
|
if (result != VK_SUCCESS)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
@@ -72,7 +72,7 @@ VkResult anv_CreateDmaBufImageINTEL(
|
|||||||
|
|
||||||
image = anv_image_from_handle(image_h);
|
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)
|
if (device->instance->physicalDevice.supports_48bit_addresses)
|
||||||
bo_flags |= EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
|
bo_flags |= EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
|
||||||
if (device->instance->physicalDevice.use_softpin)
|
if (device->instance->physicalDevice.use_softpin)
|
||||||
|
@@ -597,10 +597,6 @@ anv_multialloc_alloc2(struct anv_multialloc *ma,
|
|||||||
return anv_multialloc_alloc(ma, alloc ? alloc : parent_alloc, scope);
|
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 {
|
struct anv_bo {
|
||||||
uint32_t gem_handle;
|
uint32_t gem_handle;
|
||||||
|
|
||||||
@@ -623,6 +619,9 @@ struct anv_bo {
|
|||||||
|
|
||||||
/** Flags to pass to the kernel through drm_i915_exec_object2::flags */
|
/** Flags to pass to the kernel through drm_i915_exec_object2::flags */
|
||||||
uint32_t flags;
|
uint32_t flags;
|
||||||
|
|
||||||
|
/** True if this BO may be shared with other processes */
|
||||||
|
bool is_external:1;
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline void
|
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->size = size;
|
||||||
bo->map = NULL;
|
bo->map = NULL;
|
||||||
bo->flags = 0;
|
bo->flags = 0;
|
||||||
|
bo->is_external = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Represents a lock-free linked list of "free" things. This is used by
|
/* 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,
|
VkResult anv_bo_cache_alloc(struct anv_device *device,
|
||||||
struct anv_bo_cache *cache,
|
struct anv_bo_cache *cache,
|
||||||
uint64_t size, uint64_t bo_flags,
|
uint64_t size, uint64_t bo_flags,
|
||||||
|
bool is_external,
|
||||||
struct anv_bo **bo);
|
struct anv_bo **bo);
|
||||||
VkResult anv_bo_cache_import_host_ptr(struct anv_device *device,
|
VkResult anv_bo_cache_import_host_ptr(struct anv_device *device,
|
||||||
struct anv_bo_cache *cache,
|
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
|
static inline uint32_t
|
||||||
anv_mocs_for_bo(const struct anv_device *device, const struct anv_bo *bo)
|
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;
|
return device->external_mocs;
|
||||||
else
|
else
|
||||||
return device->default_mocs;
|
return device->default_mocs;
|
||||||
|
@@ -952,7 +952,8 @@ VkResult anv_CreateSemaphore(
|
|||||||
} else {
|
} else {
|
||||||
semaphore->permanent.type = ANV_SEMAPHORE_TYPE_BO;
|
semaphore->permanent.type = ANV_SEMAPHORE_TYPE_BO;
|
||||||
VkResult result = anv_bo_cache_alloc(device, &device->bo_cache,
|
VkResult result = anv_bo_cache_alloc(device, &device->bo_cache,
|
||||||
4096, ANV_BO_EXTERNAL,
|
4096, 0 /* flags */,
|
||||||
|
true /* is_external */,
|
||||||
&semaphore->permanent.bo);
|
&semaphore->permanent.bo);
|
||||||
if (result != VK_SUCCESS) {
|
if (result != VK_SUCCESS) {
|
||||||
vk_free2(&device->alloc, pAllocator, semaphore);
|
vk_free2(&device->alloc, pAllocator, semaphore);
|
||||||
@@ -1106,7 +1107,7 @@ VkResult anv_ImportSemaphoreFdKHR(
|
|||||||
new_impl.type = ANV_SEMAPHORE_TYPE_BO;
|
new_impl.type = ANV_SEMAPHORE_TYPE_BO;
|
||||||
|
|
||||||
VkResult result = anv_bo_cache_import(device, &device->bo_cache,
|
VkResult result = anv_bo_cache_import(device, &device->bo_cache,
|
||||||
fd, ANV_BO_EXTERNAL,
|
fd, 0 /* flags */,
|
||||||
&new_impl.bo);
|
&new_impl.bo);
|
||||||
if (result != VK_SUCCESS)
|
if (result != VK_SUCCESS)
|
||||||
return result;
|
return result;
|
||||||
|
Reference in New Issue
Block a user