(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));
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);
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)
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);
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);
* 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;
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);
* 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)
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;
}
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;
/* 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;
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)
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;
/** 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
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
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,
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;
} 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);
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;