From 12066a2b675437fc2f535e7439bfc09a1f416841 Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Wed, 14 Jul 2021 16:08:20 +0200 Subject: [PATCH] vkd3d: Add debug config to log resizable BAR allocations. Signed-off-by: Hans-Kristian Arntzen --- include/vkd3d.h | 1 + libs/vkd3d/device.c | 1 + libs/vkd3d/memory.c | 19 +++++++++++++++++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/include/vkd3d.h b/include/vkd3d.h index f6419e7a..c9fc0a1f 100644 --- a/include/vkd3d.h +++ b/include/vkd3d.h @@ -71,6 +71,7 @@ enum vkd3d_config_flags VKD3D_CONFIG_FLAG_FORCE_DSV_EXCLUSIVE_QUEUE = 0x00000100, VKD3D_CONFIG_FLAG_FORCE_MINIMUM_SUBGROUP_SIZE = 0x00000200, VKD3D_CONFIG_FLAG_UPLOAD_HVV = 0x00000400, + VKD3D_CONFIG_FLAG_LOG_MEMORY_BUDGET = 0x00000800, }; typedef HRESULT (*PFN_vkd3d_signal_event)(HANDLE event); diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c index 0b3c4a66..20d41fc2 100644 --- a/libs/vkd3d/device.c +++ b/libs/vkd3d/device.c @@ -501,6 +501,7 @@ static const struct vkd3d_debug_option vkd3d_config_options[] = {"force_dsv_exclusive_queue", VKD3D_CONFIG_FLAG_FORCE_DSV_EXCLUSIVE_QUEUE}, {"force_exclusive_queue", VKD3D_CONFIG_FLAG_FORCE_RTV_EXCLUSIVE_QUEUE | VKD3D_CONFIG_FLAG_FORCE_DSV_EXCLUSIVE_QUEUE}, {"upload_hvv", VKD3D_CONFIG_FLAG_UPLOAD_HVV}, + {"log_memory_budget", VKD3D_CONFIG_FLAG_LOG_MEMORY_BUDGET}, }; static void vkd3d_config_flags_init_once(void) diff --git a/libs/vkd3d/memory.c b/libs/vkd3d/memory.c index 65098215..361b97e1 100644 --- a/libs/vkd3d/memory.c +++ b/libs/vkd3d/memory.c @@ -154,6 +154,11 @@ void vkd3d_free_device_memory(struct d3d12_device *device, const struct vkd3d_de pthread_mutex_lock(&device->memory_info.budget_lock); assert(*type_current >= allocation->size); *type_current -= allocation->size; + if (vkd3d_config_flags & VKD3D_CONFIG_FLAG_LOG_MEMORY_BUDGET) + { + INFO("Freeing memory of type %u, new total allocated size %"PRIu64" MiB.\n", + allocation->vk_memory_type, *type_current / (1024 * 1024)); + } pthread_mutex_unlock(&device->memory_info.budget_lock); } } @@ -198,8 +203,11 @@ static HRESULT vkd3d_try_allocate_device_memory(struct d3d12_device *device, pthread_mutex_lock(&memory_info->budget_lock); if (*type_current + size > *type_budget) { - WARN("Attempting to allocate from memory type %u, but exceeding fixed budget: %"PRIu64" + %"PRIu64" > %"PRIu64".\n", - type_index, *type_current, size, *type_budget); + if (vkd3d_config_flags & VKD3D_CONFIG_FLAG_LOG_MEMORY_BUDGET) + { + INFO("Attempting to allocate from memory type %u, but exceeding fixed budget: %"PRIu64" + %"PRIu64" > %"PRIu64".\n", + type_index, *type_current, size, *type_budget); + } pthread_mutex_unlock(&memory_info->budget_lock); /* If we're out of DEVICE budget, don't try other types. */ @@ -215,7 +223,14 @@ static HRESULT vkd3d_try_allocate_device_memory(struct d3d12_device *device, if (budget_sensitive) { if (vr == VK_SUCCESS) + { *type_current += size; + if (vkd3d_config_flags & VKD3D_CONFIG_FLAG_LOG_MEMORY_BUDGET) + { + INFO("Allocated memory of type %u, new total allocated size %"PRIu64" MiB.\n", + type_index, *type_current / (1024 * 1024)); + } + } pthread_mutex_unlock(&memory_info->budget_lock); }