venus: track memory type property flags in vn_device_memory
Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org> Reviewed-by: Chia-I Wu <olvaffe@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13874>
This commit is contained in:
parent
86b3a4e6aa
commit
19d6b497fb
|
@ -44,6 +44,7 @@ vn_device_memory_pool_grow_alloc(struct vn_device *dev,
|
|||
|
||||
vn_object_base_init(&mem->base, VK_OBJECT_TYPE_DEVICE_MEMORY, &dev->base);
|
||||
mem->size = size;
|
||||
mem->flags = mem_flags;
|
||||
|
||||
mem_handle = vn_device_memory_to_handle(mem);
|
||||
result = vn_call_vkAllocateMemory(
|
||||
|
@ -60,7 +61,7 @@ vn_device_memory_pool_grow_alloc(struct vn_device *dev,
|
|||
}
|
||||
|
||||
result = vn_renderer_bo_create_from_device_memory(
|
||||
dev->renderer, mem->size, mem->base.id, mem_flags, 0, &mem->base_bo);
|
||||
dev->renderer, mem->size, mem->base.id, mem->flags, 0, &mem->base_bo);
|
||||
if (result != VK_SUCCESS) {
|
||||
assert(!mem->base_bo);
|
||||
goto fail;
|
||||
|
@ -187,7 +188,7 @@ vn_device_memory_pool_suballocate(struct vn_device *dev,
|
|||
|
||||
static bool
|
||||
vn_device_memory_should_suballocate(const VkMemoryAllocateInfo *alloc_info,
|
||||
const VkMemoryType *mem_type)
|
||||
const VkMemoryPropertyFlags flags)
|
||||
{
|
||||
/* We should not support suballocations because apps can do better. But
|
||||
* each BO takes up a KVM memslot currently and some CTS tests exhausts
|
||||
|
@ -196,7 +197,7 @@ vn_device_memory_should_suballocate(const VkMemoryAllocateInfo *alloc_info,
|
|||
*/
|
||||
|
||||
/* consider host-visible memory only */
|
||||
if (!(mem_type->propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT))
|
||||
if (!(flags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT))
|
||||
return false;
|
||||
|
||||
/* reject larger allocations */
|
||||
|
@ -286,7 +287,6 @@ vn_device_memory_alloc(struct vn_device *dev,
|
|||
struct vn_device_memory *mem,
|
||||
const VkMemoryAllocateInfo *alloc_info,
|
||||
bool need_bo,
|
||||
VkMemoryPropertyFlags flags,
|
||||
VkExternalMemoryHandleTypeFlags external_handles)
|
||||
{
|
||||
VkDevice dev_handle = vn_device_to_handle(dev);
|
||||
|
@ -297,7 +297,7 @@ vn_device_memory_alloc(struct vn_device *dev,
|
|||
return result;
|
||||
|
||||
result = vn_renderer_bo_create_from_device_memory(
|
||||
dev->renderer, mem->size, mem->base.id, flags, external_handles,
|
||||
dev->renderer, mem->size, mem->base.id, mem->flags, external_handles,
|
||||
&mem->base_bo);
|
||||
if (result != VK_SUCCESS) {
|
||||
vn_async_vkFreeMemory(dev->instance, dev_handle, mem_handle, NULL);
|
||||
|
@ -329,8 +329,8 @@ vn_AllocateMemory(VkDevice device,
|
|||
|
||||
const VkPhysicalDeviceMemoryProperties *mem_props =
|
||||
&dev->physical_device->memory_properties.memoryProperties;
|
||||
const VkMemoryType *mem_type =
|
||||
&mem_props->memoryTypes[pAllocateInfo->memoryTypeIndex];
|
||||
const VkMemoryPropertyFlags mem_flags =
|
||||
mem_props->memoryTypes[pAllocateInfo->memoryTypeIndex].propertyFlags;
|
||||
|
||||
const VkExportMemoryAllocateInfo *export_info = NULL;
|
||||
const VkImportAndroidHardwareBufferInfoANDROID *import_ahb_info = NULL;
|
||||
|
@ -366,6 +366,7 @@ vn_AllocateMemory(VkDevice device,
|
|||
|
||||
vn_object_base_init(&mem->base, VK_OBJECT_TYPE_DEVICE_MEMORY, &dev->base);
|
||||
mem->size = pAllocateInfo->allocationSize;
|
||||
mem->flags = mem_flags;
|
||||
|
||||
VkDeviceMemory mem_handle = vn_device_memory_to_handle(mem);
|
||||
VkResult result;
|
||||
|
@ -379,16 +380,13 @@ vn_AllocateMemory(VkDevice device,
|
|||
import_fd_info->fd);
|
||||
} else if (export_info) {
|
||||
result = vn_device_memory_alloc(dev, mem, pAllocateInfo, true,
|
||||
mem_type->propertyFlags,
|
||||
export_info->handleTypes);
|
||||
} else if (vn_device_memory_should_suballocate(pAllocateInfo, mem_type)) {
|
||||
} else if (vn_device_memory_should_suballocate(pAllocateInfo, mem_flags)) {
|
||||
result = vn_device_memory_pool_suballocate(
|
||||
dev, mem, pAllocateInfo->memoryTypeIndex);
|
||||
} else {
|
||||
const bool need_bo =
|
||||
mem_type->propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
|
||||
result = vn_device_memory_alloc(dev, mem, pAllocateInfo, need_bo,
|
||||
mem_type->propertyFlags, 0);
|
||||
const bool need_bo = mem_flags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
|
||||
result = vn_device_memory_alloc(dev, mem, pAllocateInfo, need_bo, 0);
|
||||
}
|
||||
if (result != VK_SUCCESS) {
|
||||
vn_object_base_fini(&mem->base);
|
||||
|
|
|
@ -23,6 +23,7 @@ struct vn_device_memory {
|
|||
struct vn_object_base base;
|
||||
|
||||
VkDeviceSize size;
|
||||
VkMemoryPropertyFlags flags;
|
||||
|
||||
/* non-NULL when suballocated */
|
||||
struct vn_device_memory *base_memory;
|
||||
|
|
Loading…
Reference in New Issue