Skip to content

Commit

Permalink
Update to most recent production release of VMA
Browse files Browse the repository at this point in the history
  • Loading branch information
jherico committed Feb 8, 2024
1 parent 2c197da commit 4f4b45c
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 60 deletions.
4 changes: 2 additions & 2 deletions framework/core/buffer.h
Original file line number Diff line number Diff line change
@@ -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
*
Expand Down Expand Up @@ -43,7 +43,7 @@ class Buffer : public VulkanResource<VkBuffer, VK_OBJECT_TYPE_BUFFER, const Devi
VkDeviceSize size,
VkBufferUsageFlags 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<uint32_t> &queue_family_indices = {});

Buffer(const Buffer &) = delete;
Expand Down
51 changes: 27 additions & 24 deletions framework/core/device.cpp
Original file line number Diff line number Diff line change
@@ -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
*
Expand Down Expand Up @@ -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();
Expand All @@ -224,15 +209,33 @@ 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))
{
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);
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions framework/core/hpp_buffer.h
Original file line number Diff line number Diff line change
@@ -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
*
Expand Down Expand Up @@ -42,7 +42,7 @@ class HPPBuffer : public vkb::core::HPPVulkanResource<vk::Buffer>
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<uint32_t> &queue_family_indices = {});

HPPBuffer(const HPPBuffer &) = delete;
Expand Down
51 changes: 27 additions & 24 deletions framework/core/hpp_device.cpp
Original file line number Diff line number Diff line change
@@ -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
*
Expand All @@ -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<vkb::core::HPPDebugUtils> &&debug_utils,
std::unordered_map<const char *, bool> requested_extensions) :
Expand Down Expand Up @@ -181,23 +181,8 @@ HPPDevice::HPPDevice(vkb::core::HPPPhysicalDevice &gpu,
}

VmaVulkanFunctions vma_vulkan_func{};
vma_vulkan_func.vkAllocateMemory = reinterpret_cast<PFN_vkAllocateMemory>(get_handle().getProcAddr("vkAllocateMemory"));
vma_vulkan_func.vkBindBufferMemory = reinterpret_cast<PFN_vkBindBufferMemory>(get_handle().getProcAddr("vkBindBufferMemory"));
vma_vulkan_func.vkBindImageMemory = reinterpret_cast<PFN_vkBindImageMemory>(get_handle().getProcAddr("vkBindImageMemory"));
vma_vulkan_func.vkCreateBuffer = reinterpret_cast<PFN_vkCreateBuffer>(get_handle().getProcAddr("vkCreateBuffer"));
vma_vulkan_func.vkCreateImage = reinterpret_cast<PFN_vkCreateImage>(get_handle().getProcAddr("vkCreateImage"));
vma_vulkan_func.vkDestroyBuffer = reinterpret_cast<PFN_vkDestroyBuffer>(get_handle().getProcAddr("vkDestroyBuffer"));
vma_vulkan_func.vkDestroyImage = reinterpret_cast<PFN_vkDestroyImage>(get_handle().getProcAddr("vkDestroyImage"));
vma_vulkan_func.vkFlushMappedMemoryRanges = reinterpret_cast<PFN_vkFlushMappedMemoryRanges>(get_handle().getProcAddr("vkFlushMappedMemoryRanges"));
vma_vulkan_func.vkFreeMemory = reinterpret_cast<PFN_vkFreeMemory>(get_handle().getProcAddr("vkFreeMemory"));
vma_vulkan_func.vkGetBufferMemoryRequirements = reinterpret_cast<PFN_vkGetBufferMemoryRequirements>(get_handle().getProcAddr("vkGetBufferMemoryRequirements"));
vma_vulkan_func.vkGetImageMemoryRequirements = reinterpret_cast<PFN_vkGetImageMemoryRequirements>(get_handle().getProcAddr("vkGetImageMemoryRequirements"));
vma_vulkan_func.vkGetPhysicalDeviceMemoryProperties = reinterpret_cast<PFN_vkGetPhysicalDeviceMemoryProperties>(get_handle().getProcAddr("vkGetPhysicalDeviceMemoryProperties"));
vma_vulkan_func.vkGetPhysicalDeviceProperties = reinterpret_cast<PFN_vkGetPhysicalDeviceProperties>(get_handle().getProcAddr("vkGetPhysicalDeviceProperties"));
vma_vulkan_func.vkInvalidateMappedMemoryRanges = reinterpret_cast<PFN_vkInvalidateMappedMemoryRanges>(get_handle().getProcAddr("vkInvalidateMappedMemoryRanges"));
vma_vulkan_func.vkMapMemory = reinterpret_cast<PFN_vkMapMemory>(get_handle().getProcAddr("vkMapMemory"));
vma_vulkan_func.vkUnmapMemory = reinterpret_cast<PFN_vkUnmapMemory>(get_handle().getProcAddr("vkUnmapMemory"));
vma_vulkan_func.vkCmdCopyBuffer = reinterpret_cast<PFN_vkCmdCopyBuffer>(get_handle().getProcAddr("vkCmdCopyBuffer"));
vma_vulkan_func.vkGetInstanceProcAddr = vkGetInstanceProcAddr;
vma_vulkan_func.vkGetDeviceProcAddr = reinterpret_cast<PFN_vkGetDeviceProcAddr>(get_handle().getProcAddr("vkGetDeviceProcAddr"));

VmaAllocatorCreateInfo allocator_info{};
allocator_info.physicalDevice = static_cast<VkPhysicalDevice>(gpu.get_handle());
Expand All @@ -207,15 +192,33 @@ 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))
{
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);
Expand All @@ -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);
}
Expand Down
14 changes: 7 additions & 7 deletions third_party/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
#
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion third_party/vma
Submodule vma updated 288 files

0 comments on commit 4f4b45c

Please sign in to comment.