venus: emit device memory report for device memory events

Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23411>
This commit is contained in:
Yiwei Zhang
2023-06-03 00:01:48 -07:00
committed by Marge Bot
parent f70a08bc60
commit 0960ceb071
3 changed files with 56 additions and 0 deletions

View File

@@ -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 */

View File

@@ -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 {

View File

@@ -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;