From c257bf514277ab51d30096cbf3c29c884561ae52 Mon Sep 17 00:00:00 2001 From: Boris Brezillon Date: Fri, 28 Jun 2024 12:05:01 +0200 Subject: [PATCH] panvk: Conditionally register an host address when tracking user memory When PANVK_DEBUG=dump, all internal buffers get dumped, but not the user ones, because they don't have a host address attached to them. Let's register one when mappings dump is enabled. Signed-off-by: Boris Brezillon Reviewed-by: Mary Guillemard Part-of: --- src/panfrost/vulkan/panvk_device_memory.c | 16 ++++++++++++++-- src/panfrost/vulkan/panvk_device_memory.h | 6 ++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/panfrost/vulkan/panvk_device_memory.c b/src/panfrost/vulkan/panvk_device_memory.c index 00fb1cd54e9..52248eb4246 100644 --- a/src/panfrost/vulkan/panvk_device_memory.c +++ b/src/panfrost/vulkan/panvk_device_memory.c @@ -20,6 +20,8 @@ panvk_AllocateMemory(VkDevice _device, VkDeviceMemory *pMem) { VK_FROM_HANDLE(panvk_device, device, _device); + struct panvk_instance *instance = + to_panvk_instance(device->vk.physical->instance); struct panvk_device_memory *mem; bool can_be_exported = false; VkResult result; @@ -110,8 +112,15 @@ panvk_AllocateMemory(VkDevice _device, } if (device->debug.decode_ctx) { - pandecode_inject_mmap(device->debug.decode_ctx, mem->addr.dev, NULL, - pan_kmod_bo_size(mem->bo), NULL); + if (instance->debug_flags & PANVK_DEBUG_DUMP) { + mem->debug.host_mapping = + pan_kmod_bo_mmap(mem->bo, 0, pan_kmod_bo_size(mem->bo), + PROT_READ | PROT_WRITE, MAP_SHARED, NULL); + } + + pandecode_inject_mmap(device->debug.decode_ctx, mem->addr.dev, + mem->debug.host_mapping, pan_kmod_bo_size(mem->bo), + NULL); } *pMem = panvk_device_memory_to_handle(mem); @@ -139,6 +148,9 @@ panvk_FreeMemory(VkDevice _device, VkDeviceMemory _mem, if (device->debug.decode_ctx) { pandecode_inject_free(device->debug.decode_ctx, mem->addr.dev, pan_kmod_bo_size(mem->bo)); + + if (mem->debug.host_mapping) + os_munmap(mem->debug.host_mapping, pan_kmod_bo_size(mem->bo)); } struct pan_kmod_vm_op op = { diff --git a/src/panfrost/vulkan/panvk_device_memory.h b/src/panfrost/vulkan/panvk_device_memory.h index e211cab7766..6fc545b6a0f 100644 --- a/src/panfrost/vulkan/panvk_device_memory.h +++ b/src/panfrost/vulkan/panvk_device_memory.h @@ -19,6 +19,12 @@ struct panvk_device_memory { uint64_t dev; void *host; } addr; + + struct { + /* Don't use this pointer, it's only to have user memory dumped when + * PANVK_DEBUG=dump. */ + void *host_mapping; + } debug; }; VK_DEFINE_NONDISP_HANDLE_CASTS(panvk_device_memory, vk.base, VkDeviceMemory,