venus: Tighten the conditions for guest_vram device memory alloc

In addition to the platform requirement (use_guest_vram), device memory
allocations from dedicated heap (guest_vram) are necessary only when:

1. VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT is set and it indicates that
memory is host visible and assumed to be accessed by CPU (vkMapMemory).
2. One of external memory handle types is set, that indicates memory
can be exported with external handle.

In other cases it's not necessary to create virtgpu_bo object in the
guest and enough just perform vkAllocateMemory on host side without
memory import from dedicated heap.

Reported-by: Yiwei Zhang <zzyiwei@chromium.org>
Signed-off-by: Andrew D. Gazizov <andrew.gazizov@opensynergy.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26130>
This commit is contained in:
Andrew Gazizov
2023-11-16 19:01:44 +01:00
committed by Marge Bot
parent 816f66cdfd
commit 8929889563
+9 -4
View File
@@ -468,9 +468,14 @@ vn_device_memory_alloc(struct vn_device *dev,
const VkMemoryAllocateInfo *alloc_info)
{
struct vk_device_memory *mem_vk = &mem->base.base;
const VkMemoryType *mem_type = &dev->physical_device->memory_properties
.memoryTypes[mem_vk->memory_type_index];
const bool has_guest_vram = dev->renderer->info.has_guest_vram;
const bool host_visible =
mem_type->propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
const bool export_alloc = mem_vk->export_handle_types;
const bool has_guest_vram =
dev->physical_device->instance->renderer->info.has_guest_vram;
const VkExternalMemoryHandleTypeFlagBits renderer_handle_type =
dev->physical_device->external_memory.renderer_handle_type;
struct vn_device_memory_alloc_info local_info;
@@ -483,9 +488,9 @@ vn_device_memory_alloc(struct vn_device *dev,
mem_vk->export_handle_types = renderer_handle_type;
}
if (has_guest_vram) {
if (has_guest_vram && (host_visible || export_alloc)) {
return vn_device_memory_alloc_guest_vram(dev, mem, alloc_info);
} else if (mem_vk->export_handle_types) {
} else if (export_alloc) {
return vn_device_memory_alloc_export(dev, mem, alloc_info);
} else {
return vn_device_memory_alloc_simple(dev, mem, alloc_info);