From b03b5c4257caf354f90a99865525e5f3d06ff4bd Mon Sep 17 00:00:00 2001 From: Bradley Austin Davis Date: Fri, 9 Feb 2024 15:23:40 -0800 Subject: [PATCH 1/2] Fix MSVC flag setting in CMake (#897) --- .github/workflows/build.yml | 2 +- CMakeLists.txt | 46 ++++++++++++++++--------------------- 2 files changed, 21 insertions(+), 27 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 181f274e7..015cf8c2c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -47,7 +47,7 @@ jobs: name: Configure and build shell: pwsh run: | - cmake -B"build/${{ matrix.platform }}" -G"NMake Makefiles" -DVKB_BUILD_TESTS=ON -DVKB_BUILD_SAMPLES=ON -DCMAKE_C_COMPILER_LAUNCHER=C:\\Users\\runneradmin\\.cargo\\bin\\sccache -DCMAKE_CXX_COMPILER_LAUNCHER=C:\\Users\\runneradmin\\.cargo\\bin\\sccache + cmake -B"build/${{ matrix.platform }}" -G"Ninja" -DVKB_BUILD_TESTS=ON -DVKB_BUILD_SAMPLES=ON -DCMAKE_C_COMPILER_LAUNCHER=C:\\Users\\runneradmin\\.cargo\\bin\\sccache -DCMAKE_CXX_COMPILER_LAUNCHER=C:\\Users\\runneradmin\\.cargo\\bin\\sccache cmake --build "build/${{ matrix.platform }}" --target vulkan_samples --config ${{ matrix.build_type }} -j 1 - if: ${{ matrix.platform != 'windows' }} name: Configure and build diff --git a/CMakeLists.txt b/CMakeLists.txt index ca650bcce..b51c6ece6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2023, Arm Limited and Contributors +# Copyright (c) 2020-2024, Arm Limited and Contributors # # SPDX-License-Identifier: Apache-2.0 # @@ -14,34 +14,19 @@ # See the License for the specific language governing permissions and # limitations under the License. # - if(NOT DEFINED CMAKE_C_COMPILER_LAUNCHER AND NOT DEFINED CMAKE_CXX_COMPILER_LAUNCHER) -find_program(CCACHE_FOUND ccache) -find_program(SCCACHE_FOUND sccache) -if(CCACHE_FOUND AND NOT SCCACHE_FOUND) - message("setting CCACHE to ${CCACHE_FOUND}") - set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_FOUND}) - set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_FOUND}) -elseif(SCCACHE_FOUND AND NOT CCACHE_FOUND) - message("setting CCACHE to ${CCACHE_FOUND}") - set(CMAKE_C_COMPILER_LAUNCHER ${SCCACHE_FOUND}) - set(CMAKE_CXX_COMPILER_LAUNCHER ${SCCACHE_FOUND}) -endif(CCACHE_FOUND AND NOT SCCACHE_FOUND) -endif() -if(DEFINED CMAKE_C_COMPILER_LAUNCHER) -if(WIN32) - if(CMAKE_BUILD_TYPE STREQUAL "Debug") - string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") - string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") - elseif(CMAKE_BUILD_TYPE STREQUAL "Release") - string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") - string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") - elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") - string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") - string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}") + find_program(CCACHE_FOUND ccache) + find_program(SCCACHE_FOUND sccache) + if (SCCACHE_FOUND) + message("setting SCCACHE to ${SCCACHE_FOUND}") + set(CMAKE_C_COMPILER_LAUNCHER ${SCCACHE_FOUND}) + set(CMAKE_CXX_COMPILER_LAUNCHER ${SCCACHE_FOUND}) + elseif(CCACHE_FOUND) + message("setting CCACHE to ${CCACHE_FOUND}") + set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_FOUND}) + set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_FOUND}) endif() endif() -endif() cmake_minimum_required(VERSION 3.16) @@ -50,6 +35,15 @@ add_compile_definitions($<$:VKB_DEBUG>) project(vulkan_samples) +if(MSVC AND (DEFINED CMAKE_C_COMPILER_LAUNCHER)) + message(DEBUG "Setting MSVC flags to /Z7 for ccache compatibility. Current flags: ${CMAKE_CXX_FLAGS_DEBUG}") + string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") + string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") + string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") + string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}") + message(DEBUG "New flags: ${CMAKE_CXX_FLAGS_DEBUG}") +endif() + # create output folder file(MAKE_DIRECTORY output) From 9405db5041d64f3f08980f975daa85e200a5db91 Mon Sep 17 00:00:00 2001 From: Bradley Austin Davis Date: Wed, 7 Feb 2024 23:55:32 -0800 Subject: [PATCH 2/2] Update to most recent production release of VMA --- framework/core/buffer.h | 4 +-- framework/core/device.cpp | 51 ++++++++++++++++++----------------- framework/core/hpp_buffer.h | 4 +-- framework/core/hpp_device.cpp | 49 +++++++++++++++++---------------- third_party/CMakeLists.txt | 14 +++++----- third_party/vma | 2 +- 6 files changed, 65 insertions(+), 59 deletions(-) diff --git a/framework/core/buffer.h b/framework/core/buffer.h index 56c7bfe7a..5ccf37d4f 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 a139fc836..3faaba8d3 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 00d216145..4aa899c96 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 eb522c6be..2e4c49b14 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 * @@ -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 5a902bd8b..1f24cf9f8 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 f9921aefd..a6bfc2372 160000 --- a/third_party/vma +++ b/third_party/vma @@ -1 +1 @@ -Subproject commit f9921aefddee2437cc2e3303d3175bd8ef23e22c +Subproject commit a6bfc237255a6bac1513f7c1ebde6d8aed6b5191