From a9a5ee8a965fd81373b654d0796335d02b9c4c53 Mon Sep 17 00:00:00 2001 From: dpjudas Date: Mon, 19 Feb 2024 09:27:51 +0100 Subject: [PATCH] Enable more extensions desired by vk_mem_alloc and add vk_membudget cvar --- libraries/ZVulkan/src/vulkanbuilders.cpp | 10 ++++++ libraries/ZVulkan/src/vulkandevice.cpp | 14 ++++++++ .../rendering/vulkan/vk_renderdevice.cpp | 36 +++++++++++++++++++ 3 files changed, 60 insertions(+) diff --git a/libraries/ZVulkan/src/vulkanbuilders.cpp b/libraries/ZVulkan/src/vulkanbuilders.cpp index be18a8632..e056c6f15 100644 --- a/libraries/ZVulkan/src/vulkanbuilders.cpp +++ b/libraries/ZVulkan/src/vulkanbuilders.cpp @@ -1762,10 +1762,20 @@ std::shared_ptr VulkanSurfaceBuilder::Create(std::shared_ptrEnabledExtensions.find(ext) != Instance->EnabledExtensions.end(); } +#ifndef VK_KHR_MAINTENANCE4_EXTENSION_NAME +#define VK_KHR_MAINTENANCE4_EXTENSION_NAME "VK_KHR_maintenance4" +#endif + void VulkanDevice::CreateAllocator() { VmaAllocatorCreateInfo allocinfo = {}; @@ -48,6 +52,16 @@ void VulkanDevice::CreateAllocator() allocinfo.flags |= VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT; if (SupportsExtension(VK_KHR_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME)) allocinfo.flags |= VMA_ALLOCATOR_CREATE_BUFFER_DEVICE_ADDRESS_BIT; + if (SupportsExtension(VK_KHR_BIND_MEMORY_2_EXTENSION_NAME)) + allocinfo.flags |= VMA_ALLOCATOR_CREATE_KHR_BIND_MEMORY2_BIT; + //if (SupportsExtension(VK_KHR_MAINTENANCE4_EXTENSION_NAME)) + // allocinfo.flags |= MA_ALLOCATOR_CREATE_KHR_MAINTENANCE4_BIT; + if (SupportsExtension(VK_EXT_MEMORY_BUDGET_EXTENSION_NAME)) + allocinfo.flags |= VMA_ALLOCATOR_CREATE_EXT_MEMORY_BUDGET_BIT; + if (SupportsExtension(VK_EXT_MEMORY_PRIORITY_EXTENSION_NAME)) + allocinfo.flags |= VMA_ALLOCATOR_CREATE_EXT_MEMORY_PRIORITY_BIT; + if (SupportsExtension(VK_AMD_DEVICE_COHERENT_MEMORY_EXTENSION_NAME)) + allocinfo.flags |= VMA_ALLOCATOR_CREATE_AMD_DEVICE_COHERENT_MEMORY_BIT; allocinfo.physicalDevice = PhysicalDevice.Device; allocinfo.device = device; allocinfo.instance = Instance->Instance; diff --git a/src/common/rendering/vulkan/vk_renderdevice.cpp b/src/common/rendering/vulkan/vk_renderdevice.cpp index ba1f55a8d..cd5527243 100644 --- a/src/common/rendering/vulkan/vk_renderdevice.cpp +++ b/src/common/rendering/vulkan/vk_renderdevice.cpp @@ -76,6 +76,8 @@ EXTERN_CVAR(Bool, r_skipmats) // Physical device info static std::vector SupportedDevices; int vkversion; +static TArray memheapnames; +static TArray membudgets; CUSTOM_CVAR(Bool, vk_debug, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL) { @@ -102,6 +104,27 @@ CCMD(vk_listdevices) } } +CCMD(vk_membudget) +{ + for (size_t i = 0; i < membudgets.size(); i++) + { + if (membudgets[i].budget != 0) + { + Printf("#%d %s - %d MB used out of %d MB estimated budget (%d%%)\n", + i, memheapnames[i].GetChars(), + (int)(membudgets[i].usage / (1024 * 1024)), + (int)(membudgets[i].budget / (1024 * 1024)), + (int)(membudgets[i].usage * 100 / membudgets[i].budget)); + } + else + { + Printf("#%d %s - %d MB used\n", + i, memheapnames[i].GetChars(), + (int)(membudgets[i].usage / (1024 * 1024))); + } + } +} + void I_BuildVKDeviceList(FOptionValues* opt) { for (size_t i = 0; i < SupportedDevices.size(); i++) @@ -478,6 +501,19 @@ TArray VulkanRenderDevice::GetScreenshotBuffer(int &pitch, ESSType &col void VulkanRenderDevice::BeginFrame() { + vmaSetCurrentFrameIndex(mDevice->allocator, 0); + membudgets.Resize(mDevice->PhysicalDevice.Properties.Memory.memoryHeapCount); + vmaGetHeapBudgets(mDevice->allocator, membudgets.data()); + if (memheapnames.size() == 0) + { + memheapnames.Resize(mDevice->PhysicalDevice.Properties.Memory.memoryHeapCount); + for (unsigned int i = 0; i < memheapnames.Size(); i++) + { + bool deviceLocal = !!(mDevice->PhysicalDevice.Properties.Memory.memoryHeaps[i].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT); + memheapnames[i] = deviceLocal ? "device local" : "system"; + } + } + if (levelMeshChanged) { levelMeshChanged = false;