diff --git a/framework/core/buffer.h b/framework/core/buffer.h index 56c7bfe7aa..5ccf37d4fc 100644 --- a/framework/core/buffer.h +++ b/framework/core/buffer.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2019-2023, Arm Limited and Contributors +/* Copyright (c) 2019-2024, Arm Limited and Contributors * * SPDX-License-Identifier: Apache-2.0 * @@ -43,7 +43,7 @@ class Buffer : public VulkanResource &queue_family_indices = {}); Buffer(const Buffer &) = delete; diff --git a/framework/core/device.cpp b/framework/core/device.cpp index a139fc8369..3faaba8d3a 100644 --- a/framework/core/device.cpp +++ b/framework/core/device.cpp @@ -1,5 +1,5 @@ -/* Copyright (c) 2019-2023, Arm Limited and Contributors - * Copyright (c) 2019-2023, Sascha Willems +/* Copyright (c) 2019-2024, Arm Limited and Contributors + * Copyright (c) 2019-2024, Sascha Willems * * SPDX-License-Identifier: Apache-2.0 * @@ -198,23 +198,8 @@ Device::Device(PhysicalDevice &gpu, } VmaVulkanFunctions vma_vulkan_func{}; - vma_vulkan_func.vkAllocateMemory = vkAllocateMemory; - vma_vulkan_func.vkBindBufferMemory = vkBindBufferMemory; - vma_vulkan_func.vkBindImageMemory = vkBindImageMemory; - vma_vulkan_func.vkCreateBuffer = vkCreateBuffer; - vma_vulkan_func.vkCreateImage = vkCreateImage; - vma_vulkan_func.vkDestroyBuffer = vkDestroyBuffer; - vma_vulkan_func.vkDestroyImage = vkDestroyImage; - vma_vulkan_func.vkFlushMappedMemoryRanges = vkFlushMappedMemoryRanges; - vma_vulkan_func.vkFreeMemory = vkFreeMemory; - vma_vulkan_func.vkGetBufferMemoryRequirements = vkGetBufferMemoryRequirements; - vma_vulkan_func.vkGetImageMemoryRequirements = vkGetImageMemoryRequirements; - vma_vulkan_func.vkGetPhysicalDeviceMemoryProperties = vkGetPhysicalDeviceMemoryProperties; - vma_vulkan_func.vkGetPhysicalDeviceProperties = vkGetPhysicalDeviceProperties; - vma_vulkan_func.vkInvalidateMappedMemoryRanges = vkInvalidateMappedMemoryRanges; - vma_vulkan_func.vkMapMemory = vkMapMemory; - vma_vulkan_func.vkUnmapMemory = vkUnmapMemory; - vma_vulkan_func.vkCmdCopyBuffer = vkCmdCopyBuffer; + vma_vulkan_func.vkGetInstanceProcAddr = vkGetInstanceProcAddr; + vma_vulkan_func.vkGetDeviceProcAddr = vkGetDeviceProcAddr; VmaAllocatorCreateInfo allocator_info{}; allocator_info.physicalDevice = gpu.get_handle(); @@ -224,8 +209,6 @@ Device::Device(PhysicalDevice &gpu, if (can_get_memory_requirements && has_dedicated_allocation) { allocator_info.flags |= VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT; - vma_vulkan_func.vkGetBufferMemoryRequirements2KHR = vkGetBufferMemoryRequirements2KHR; - vma_vulkan_func.vkGetImageMemoryRequirements2KHR = vkGetImageMemoryRequirements2KHR; } if (is_extension_supported(VK_KHR_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME) && is_enabled(VK_KHR_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME)) @@ -233,6 +216,26 @@ Device::Device(PhysicalDevice &gpu, allocator_info.flags |= VMA_ALLOCATOR_CREATE_BUFFER_DEVICE_ADDRESS_BIT; } + if (is_extension_supported(VK_EXT_MEMORY_BUDGET_EXTENSION_NAME) && is_enabled(VK_EXT_MEMORY_BUDGET_EXTENSION_NAME)) + { + allocator_info.flags |= VMA_ALLOCATOR_CREATE_EXT_MEMORY_BUDGET_BIT; + } + + if (is_extension_supported(VK_EXT_MEMORY_PRIORITY_EXTENSION_NAME) && is_enabled(VK_EXT_MEMORY_PRIORITY_EXTENSION_NAME)) + { + allocator_info.flags |= VMA_ALLOCATOR_CREATE_EXT_MEMORY_PRIORITY_BIT; + } + + if (is_extension_supported(VK_KHR_BIND_MEMORY_2_EXTENSION_NAME) && is_enabled(VK_KHR_BIND_MEMORY_2_EXTENSION_NAME)) + { + allocator_info.flags |= VMA_ALLOCATOR_CREATE_KHR_BIND_MEMORY2_BIT; + } + + if (is_extension_supported(VK_AMD_DEVICE_COHERENT_MEMORY_EXTENSION_NAME) && is_enabled(VK_AMD_DEVICE_COHERENT_MEMORY_EXTENSION_NAME)) + { + allocator_info.flags |= VMA_ALLOCATOR_CREATE_AMD_DEVICE_COHERENT_MEMORY_BIT; + } + allocator_info.pVulkanFunctions = &vma_vulkan_func; result = vmaCreateAllocator(&allocator_info, &memory_allocator); @@ -263,10 +266,10 @@ Device::~Device() if (memory_allocator != VK_NULL_HANDLE) { - VmaStats stats; - vmaCalculateStats(memory_allocator, &stats); + VmaTotalStatistics stats; + vmaCalculateStatistics(memory_allocator, &stats); - LOGI("Total device memory leaked: {} bytes.", stats.total.usedBytes); + LOGI("Total device memory leaked: {} bytes.", stats.total.statistics.allocationBytes); vmaDestroyAllocator(memory_allocator); } diff --git a/framework/core/hpp_buffer.h b/framework/core/hpp_buffer.h index 00d2161456..4aa899c966 100644 --- a/framework/core/hpp_buffer.h +++ b/framework/core/hpp_buffer.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2021-2023, NVIDIA CORPORATION. All rights reserved. +/* Copyright (c) 2021-2024, NVIDIA CORPORATION. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -42,7 +42,7 @@ class HPPBuffer : public vkb::core::HPPVulkanResource vk::DeviceSize size, vk::BufferUsageFlags buffer_usage, VmaMemoryUsage memory_usage, - VmaAllocationCreateFlags flags = VMA_ALLOCATION_CREATE_MAPPED_BIT, + VmaAllocationCreateFlags flags = VMA_ALLOCATION_CREATE_MAPPED_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT, const std::vector &queue_family_indices = {}); HPPBuffer(const HPPBuffer &) = delete; diff --git a/framework/core/hpp_device.cpp b/framework/core/hpp_device.cpp index eb522c6bee..0c17647343 100644 --- a/framework/core/hpp_device.cpp +++ b/framework/core/hpp_device.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2022-2023, NVIDIA CORPORATION. All rights reserved. +/* Copyright (c) 2022-2024, NVIDIA CORPORATION. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -25,7 +25,7 @@ namespace vkb { namespace core { -HPPDevice::HPPDevice(vkb::core::HPPPhysicalDevice &gpu, +HPPDevice::HPPDevice(vkb::core::HPPPhysicalDevice & gpu, vk::SurfaceKHR surface, std::unique_ptr &&debug_utils, std::unordered_map requested_extensions) : @@ -181,23 +181,8 @@ HPPDevice::HPPDevice(vkb::core::HPPPhysicalDevice &gpu, } VmaVulkanFunctions vma_vulkan_func{}; - vma_vulkan_func.vkAllocateMemory = reinterpret_cast(get_handle().getProcAddr("vkAllocateMemory")); - vma_vulkan_func.vkBindBufferMemory = reinterpret_cast(get_handle().getProcAddr("vkBindBufferMemory")); - vma_vulkan_func.vkBindImageMemory = reinterpret_cast(get_handle().getProcAddr("vkBindImageMemory")); - vma_vulkan_func.vkCreateBuffer = reinterpret_cast(get_handle().getProcAddr("vkCreateBuffer")); - vma_vulkan_func.vkCreateImage = reinterpret_cast(get_handle().getProcAddr("vkCreateImage")); - vma_vulkan_func.vkDestroyBuffer = reinterpret_cast(get_handle().getProcAddr("vkDestroyBuffer")); - vma_vulkan_func.vkDestroyImage = reinterpret_cast(get_handle().getProcAddr("vkDestroyImage")); - vma_vulkan_func.vkFlushMappedMemoryRanges = reinterpret_cast(get_handle().getProcAddr("vkFlushMappedMemoryRanges")); - vma_vulkan_func.vkFreeMemory = reinterpret_cast(get_handle().getProcAddr("vkFreeMemory")); - vma_vulkan_func.vkGetBufferMemoryRequirements = reinterpret_cast(get_handle().getProcAddr("vkGetBufferMemoryRequirements")); - vma_vulkan_func.vkGetImageMemoryRequirements = reinterpret_cast(get_handle().getProcAddr("vkGetImageMemoryRequirements")); - vma_vulkan_func.vkGetPhysicalDeviceMemoryProperties = reinterpret_cast(get_handle().getProcAddr("vkGetPhysicalDeviceMemoryProperties")); - vma_vulkan_func.vkGetPhysicalDeviceProperties = reinterpret_cast(get_handle().getProcAddr("vkGetPhysicalDeviceProperties")); - vma_vulkan_func.vkInvalidateMappedMemoryRanges = reinterpret_cast(get_handle().getProcAddr("vkInvalidateMappedMemoryRanges")); - vma_vulkan_func.vkMapMemory = reinterpret_cast(get_handle().getProcAddr("vkMapMemory")); - vma_vulkan_func.vkUnmapMemory = reinterpret_cast(get_handle().getProcAddr("vkUnmapMemory")); - vma_vulkan_func.vkCmdCopyBuffer = reinterpret_cast(get_handle().getProcAddr("vkCmdCopyBuffer")); + vma_vulkan_func.vkGetInstanceProcAddr = vkGetInstanceProcAddr; + vma_vulkan_func.vkGetDeviceProcAddr = reinterpret_cast(get_handle().getProcAddr("vkGetDeviceProcAddr")); VmaAllocatorCreateInfo allocator_info{}; allocator_info.physicalDevice = static_cast(gpu.get_handle()); @@ -207,8 +192,6 @@ HPPDevice::HPPDevice(vkb::core::HPPPhysicalDevice &gpu, if (can_get_memory_requirements && has_dedicated_allocation) { allocator_info.flags |= VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT; - vma_vulkan_func.vkGetBufferMemoryRequirements2KHR = vkGetBufferMemoryRequirements2KHR; - vma_vulkan_func.vkGetImageMemoryRequirements2KHR = vkGetImageMemoryRequirements2KHR; } if (is_extension_supported(VK_KHR_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME) && is_enabled(VK_KHR_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME)) @@ -216,6 +199,26 @@ HPPDevice::HPPDevice(vkb::core::HPPPhysicalDevice &gpu, allocator_info.flags |= VMA_ALLOCATOR_CREATE_BUFFER_DEVICE_ADDRESS_BIT; } + if (is_extension_supported(VK_EXT_MEMORY_BUDGET_EXTENSION_NAME) && is_enabled(VK_EXT_MEMORY_BUDGET_EXTENSION_NAME)) + { + allocator_info.flags |= VMA_ALLOCATOR_CREATE_EXT_MEMORY_BUDGET_BIT; + } + + if (is_extension_supported(VK_EXT_MEMORY_PRIORITY_EXTENSION_NAME) && is_enabled(VK_EXT_MEMORY_PRIORITY_EXTENSION_NAME)) + { + allocator_info.flags |= VMA_ALLOCATOR_CREATE_EXT_MEMORY_PRIORITY_BIT; + } + + if (is_extension_supported(VK_KHR_BIND_MEMORY_2_EXTENSION_NAME) && is_enabled(VK_KHR_BIND_MEMORY_2_EXTENSION_NAME)) + { + allocator_info.flags |= VMA_ALLOCATOR_CREATE_KHR_BIND_MEMORY2_BIT; + } + + if (is_extension_supported(VK_AMD_DEVICE_COHERENT_MEMORY_EXTENSION_NAME) && is_enabled(VK_AMD_DEVICE_COHERENT_MEMORY_EXTENSION_NAME)) + { + allocator_info.flags |= VMA_ALLOCATOR_CREATE_AMD_DEVICE_COHERENT_MEMORY_BIT; + } + allocator_info.pVulkanFunctions = &vma_vulkan_func; VkResult result = vmaCreateAllocator(&allocator_info, &memory_allocator); @@ -239,10 +242,10 @@ HPPDevice::~HPPDevice() if (memory_allocator != VK_NULL_HANDLE) { - VmaStats stats; - vmaCalculateStats(memory_allocator, &stats); + VmaTotalStatistics stats; + vmaCalculateStatistics(memory_allocator, &stats); - LOGI("Total device memory leaked: {} bytes.", stats.total.usedBytes); + LOGI("Total device memory leaked: {} bytes.", stats.total.statistics.allocationBytes); vmaDestroyAllocator(memory_allocator); } diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt index 5a902bd8bb..1f24cf9f8f 100644 --- a/third_party/CMakeLists.txt +++ b/third_party/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2023, Arm Limited and Contributors +# Copyright (c) 2019-2024, Arm Limited and Contributors # # SPDX-License-Identifier: Apache-2.0 # @@ -83,19 +83,19 @@ elseif(UNIX) else() message(FATAL_ERROR "Unknown WSI") endif() -endif() +endif() # vma add_library(vma INTERFACE) -set(VMA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/vma/src) +set(VMA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/vma/include) target_sources(vma INTERFACE ${VMA_DIR}/vk_mem_alloc.h) -target_include_directories(vma INTERFACE ${VMA_DIR}) +target_include_directories(vma SYSTEM INTERFACE ${VMA_DIR}) target_link_libraries(vma INTERFACE vulkan) # libktx set(KTX_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ktx) -set(KTX_SOURCES +set(KTX_SOURCES ${KTX_DIR}/lib/checkheader.c ${KTX_DIR}/lib/dfdutils/createdfd.c ${KTX_DIR}/lib/dfdutils/colourspaces.c @@ -136,7 +136,7 @@ set(KTX_SOURCES ${KTX_DIR}/lib/basisu/transcoder/basisu_transcoder.h ${KTX_DIR}/lib/basisu/transcoder/basisu.h ${KTX_DIR}/lib/basisu/zstd/zstd.c - + # KT1 ${KTX_DIR}/lib/texture1.c ${KTX_DIR}/lib/texture1.h @@ -152,7 +152,7 @@ set(KTX_SOURCES ${KTX_DIR}/lib/vkformat_str.c ${KTX_DIR}/lib/vk_funcs.c ${KTX_DIR}/lib/vk_funcs.h - ${KTX_DIR}/lib/vkloader.c + ${KTX_DIR}/lib/vkloader.c ) set(KTX_INCLUDE_DIRS diff --git a/third_party/vma b/third_party/vma index f9921aefdd..a6bfc23725 160000 --- a/third_party/vma +++ b/third_party/vma @@ -1 +1 @@ -Subproject commit f9921aefddee2437cc2e3303d3175bd8ef23e22c +Subproject commit a6bfc237255a6bac1513f7c1ebde6d8aed6b5191