From: Yiwei Zhang Date: Sat, 3 Jun 2023 07:01:48 +0000 (-0700) Subject: venus: emit device memory report for device memory events X-Git-Tag: upstream/23.3.3~7464 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0960ceb0719e500ca1dba8eb43b3955dc9ecbb6e;p=platform%2Fupstream%2Fmesa.git venus: emit device memory report for device memory events Signed-off-by: Yiwei Zhang Part-of: --- diff --git a/src/virtio/vulkan/vn_device.h b/src/virtio/vulkan/vn_device.h index 6cb705e..e766087 100644 --- a/src/virtio/vulkan/vn_device.h +++ b/src/virtio/vulkan/vn_device.h @@ -56,4 +56,26 @@ VK_DEFINE_HANDLE_CASTS(vn_device, VkDevice, VK_OBJECT_TYPE_DEVICE) +static inline void +vn_device_emit_device_memory_report(struct vn_device *dev, + VkDeviceMemoryReportEventTypeEXT type, + uint64_t mem_obj_id, + VkDeviceSize size, + struct vn_object_base *obj, + uint32_t heap_index) +{ + assert(dev->memory_reports); + const VkDeviceMemoryReportCallbackDataEXT report = { + .sType = VK_STRUCTURE_TYPE_DEVICE_MEMORY_REPORT_CALLBACK_DATA_EXT, + .type = type, + .memoryObjectId = mem_obj_id, + .size = size, + .objectType = obj->base.type, + .objectHandle = obj->id, + .heapIndex = heap_index, + }; + for (uint32_t i = 0; i < dev->memory_report_count; i++) + dev->memory_reports[i].callback(&report, dev->memory_reports[i].data); +} + #endif /* VN_DEVICE_H */ diff --git a/src/virtio/vulkan/vn_device_memory.c b/src/virtio/vulkan/vn_device_memory.c index 255829f..ad789fd 100644 --- a/src/virtio/vulkan/vn_device_memory.c +++ b/src/virtio/vulkan/vn_device_memory.c @@ -468,6 +468,31 @@ vn_device_memory_alloc(struct vn_device *dev, external_handles); } +static void +vn_device_memory_emit_report(struct vn_device *dev, + struct vn_device_memory *mem, + bool is_alloc, + VkResult result) +{ + if (likely(!dev->memory_reports)) + return; + + VkDeviceMemoryReportEventTypeEXT type; + if (result != VK_SUCCESS) { + type = VK_DEVICE_MEMORY_REPORT_EVENT_TYPE_ALLOCATION_FAILED_EXT; + } else if (is_alloc) { + type = mem->is_import ? VK_DEVICE_MEMORY_REPORT_EVENT_TYPE_IMPORT_EXT + : VK_DEVICE_MEMORY_REPORT_EVENT_TYPE_ALLOCATE_EXT; + } else { + type = mem->is_import ? VK_DEVICE_MEMORY_REPORT_EVENT_TYPE_UNIMPORT_EXT + : VK_DEVICE_MEMORY_REPORT_EVENT_TYPE_FREE_EXT; + } + const uint64_t mem_obj_id = + mem->is_external ? mem->base_bo->res_id : mem->base.id; + vn_device_emit_device_memory_report(dev, type, mem_obj_id, mem->size, + &mem->base, mem->type.heapIndex); +} + VkResult vn_AllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo, @@ -514,6 +539,8 @@ vn_AllocateMemory(VkDevice device, mem->size = pAllocateInfo->allocationSize; mem->type = dev->physical_device->memory_properties.memoryProperties .memoryTypes[pAllocateInfo->memoryTypeIndex]; + mem->is_import = import_ahb_info || import_fd_info; + mem->is_external = mem->is_import || export_info; VkDeviceMemory mem_handle = vn_device_memory_to_handle(mem); VkResult result; @@ -535,6 +562,9 @@ vn_AllocateMemory(VkDevice device, } else { result = vn_device_memory_alloc(dev, mem, pAllocateInfo, 0); } + + vn_device_memory_emit_report(dev, mem, /* is_alloc */ true, result); + if (result != VK_SUCCESS) { vn_object_base_fini(&mem->base); vk_free(alloc, mem); @@ -560,6 +590,8 @@ vn_FreeMemory(VkDevice device, if (!mem) return; + vn_device_memory_emit_report(dev, mem, /* is_alloc */ false, VK_SUCCESS); + if (mem->base_memory) { vn_device_memory_pool_unref(dev, mem->base_memory); } else { diff --git a/src/virtio/vulkan/vn_device_memory.h b/src/virtio/vulkan/vn_device_memory.h index 3dfa6bc..4bf5911 100644 --- a/src/virtio/vulkan/vn_device_memory.h +++ b/src/virtio/vulkan/vn_device_memory.h @@ -24,6 +24,8 @@ struct vn_device_memory { VkDeviceSize size; VkMemoryType type; + bool is_external; + bool is_import; /* non-NULL when suballocated */ struct vn_device_memory *base_memory;