Merge pull request #171 from IAmNotHanni/master

Add CMake support
This commit is contained in:
Adam Sawicki 2021-06-09 16:48:06 +02:00 committed by GitHub
commit 2f4bc1bb20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 217 additions and 6 deletions

33
CMakeLists.txt Normal file
View File

@ -0,0 +1,33 @@
cmake_minimum_required(VERSION 3.9)
project(VulkanMemoryAllocator)
find_package(Vulkan REQUIRED)
# VulkanMemoryAllocator contains an sample application and VmaReplay which are not build by default
option(VMA_BUILD_SAMPLE "Build VulkanMemoryAllocator sample application" OFF)
option(VMA_BUILD_SAMPLE_SHADERS "Build VulkanMemoryAllocator sample application's shaders" OFF)
option(VMA_BUILD_REPLAY "Build VulkanMemoryAllocator replay application" OFF)
message(STATUS "VMA_BUILD_SAMPLE = ${VMA_BUILD_SAMPLE}")
message(STATUS "VMA_BUILD_SAMPLE_SHADERS = ${VMA_BUILD_SAMPLE_SHADERS}")
message(STATUS "VMA_BUILD_REPLAY = ${VMA_BUILD_REPLAY}")
option(VMA_RECORDING_ENABLED "Enable VMA memory recording for debugging" OFF)
option(VMA_USE_STL_CONTAINERS "Use C++ STL containers instead of VMA's containers" OFF)
option(VMA_STATIC_VULKAN_FUNCTIONS "Link statically with Vulkan API" OFF)
option(VMA_DYNAMIC_VULKAN_FUNCTIONS "Fetch pointers to Vulkan functions internally (no static linking)" ON)
option(VMA_DEBUG_ALWAYS_DEDICATED_MEMORY "Every allocation will have its own memory block" OFF)
option(VMA_DEBUG_INITIALIZE_ALLOCATIONS "Automatically fill new allocations and destroyed allocations with some bit pattern" OFF)
option(VMA_DEBUG_GLOBAL_MUTEX "Enable single mutex protecting all entry calls to the library" OFF)
option(VMA_DEBUG_DONT_EXCEED_MAX_MEMORY_ALLOCATION_COUNT "Never exceed VkPhysicalDeviceLimits::maxMemoryAllocationCount and return error" OFF)
message(STATUS "VMA_RECORDING_ENABLED = ${VMA_RECORDING_ENABLED}")
message(STATUS "VMA_USE_STL_CONTAINERS = ${VMA_USE_STL_CONTAINERS}")
message(STATUS "VMA_DYNAMIC_VULKAN_FUNCTIONS = ${VMA_DYNAMIC_VULKAN_FUNCTIONS}")
message(STATUS "VMA_DEBUG_ALWAYS_DEDICATED_MEMORY = ${VMA_DEBUG_ALWAYS_DEDICATED_MEMORY}")
message(STATUS "VMA_DEBUG_INITIALIZE_ALLOCATIONS = ${VMA_DEBUG_INITIALIZE_ALLOCATIONS}")
message(STATUS "VMA_DEBUG_GLOBAL_MUTEX = ${VMA_DEBUG_GLOBAL_MUTEX}")
message(STATUS "VMA_DEBUG_DONT_EXCEED_MAX_MEMORY_ALLOCATION_COUNT = ${VMA_DEBUG_DONT_EXCEED_MAX_MEMORY_ALLOCATION_COUNT}")
add_subdirectory(src)

View File

@ -94,6 +94,42 @@ With this one function call:
`VmaAllocation` is an object that represents memory assigned to this buffer. It can be queried for parameters like Vulkan memory handle and offset.
# How to build
On Windows it is recommended to use [CMake UI](https://cmake.org/runningcmake/). Alternatively you can generate a Visual Studio project map using CMake in command line: `cmake -B./build/ -DCMAKE_BUILD_TYPE=Debug -G "Visual Studio 16 2019" -A x64 ./`
On Linux:
```
mkdir build
cd build
cmake ..
make
```
The following targets are available
| Target | Description | CMake option | Default setting |
| ------------- | ------------- | ------------- | ------------- |
| VmaSample | VMA sample application | `VMA_BUILD_SAMPLE` | `OFF` |
| VmaBuildSampleShaders | Shaders for VmaSample | `VMA_BUILD_SAMPLE_SHADERS` | `OFF` |
| VmaReplay | Replay tool for VMA .csv trace files | `VMA_BUILD_REPLAY` | `OFF` |
Please note that while VulkanMemoryAllocator library is supported on other platforms besides Windows, VmaSample and VmaReplay are not.
These CMake options are available
| CMake option | Description | Default setting |
| ------------- | ------------- | ------------- |
| `VMA_RECORDING_ENABLED` | Enable VMA memory recording for debugging | `OFF` |
| `VMA_USE_STL_CONTAINERS` | Use C++ STL containers instead of VMA's containers | `OFF` |
| `VMA_STATIC_VULKAN_FUNCTIONS` | Link statically with Vulkan API | `OFF` |
| `VMA_DYNAMIC_VULKAN_FUNCTIONS` | Fetch pointers to Vulkan functions internally (no static linking) | `ON` |
| `VMA_DEBUG_ALWAYS_DEDICATED_MEMORY` | Every allocation will have its own memory block | `OFF` |
| `VMA_DEBUG_INITIALIZE_ALLOCATIONS` | Automatically fill new allocations and destroyed allocations with some bit pattern | `OFF` |
| `VMA_DEBUG_GLOBAL_MUTEX` | Enable single mutex protecting all entry calls to the library | `OFF` |
| `VMA_DEBUG_DONT_EXCEED_MAX_MEMORY_ALLOCATION_COUNT` | Never exceed [VkPhysicalDeviceLimits::maxMemoryAllocationCount](https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#limits-maxMemoryAllocationCount) and return error | `OFF` |
# Binaries
The release comes with precompiled binary executables for "VulkanSample" application which contains test suite and "VmaReplay" tool. They are compiled using Visual Studio 2019, so they require appropriate libraries to work, including "MSVCP140.dll", "VCRUNTIME140.dll", "VCRUNTIME140_1.dll". If their launch fails with error message telling about those files missing, please download and install [Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019](https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads), "x64" version.

92
src/CMakeLists.txt Normal file
View File

@ -0,0 +1,92 @@
set(VMA_LIBRARY_SOURCE_FILES
VmaUsage.cpp
)
add_library(VulkanMemoryAllocator ${VMA_LIBRARY_SOURCE_FILES})
set_target_properties(
VulkanMemoryAllocator PROPERTIES
CXX_EXTENSIONS OFF
# Use C++14
CXX_STANDARD 14
CXX_STANDARD_REQUIRED ON
)
target_include_directories(VulkanMemoryAllocator PUBLIC ${PROJECT_SOURCE_DIR}/include)
# Only link to Vulkan if static linking is used
if (NOT ${VMA_DYNAMIC_VULKAN_FUNCTIONS})
target_link_libraries(VulkanMemoryAllocator PUBLIC Vulkan::Vulkan)
endif()
target_compile_definitions(
VulkanMemoryAllocator
PUBLIC
VMA_USE_STL_CONTAINERS=$<BOOL:${VMA_USE_STL_CONTAINERS}>
VMA_DYNAMIC_VULKAN_FUNCTIONS=$<BOOL:${VMA_DYNAMIC_VULKAN_FUNCTIONS}>
VMA_DEBUG_ALWAYS_DEDICATED_MEMORY=$<BOOL:${VMA_DEBUG_ALWAYS_DEDICATED_MEMORY}>
VMA_DEBUG_INITIALIZE_ALLOCATIONS=$<BOOL:${VMA_DEBUG_INITIALIZE_ALLOCATIONS}>
VMA_DEBUG_GLOBAL_MUTEX=$<BOOL:${VMA_DEBUG_GLOBAL_MUTEX}>
VMA_DEBUG_DONT_EXCEED_MAX_MEMORY_ALLOCATION_COUNT=$<BOOL:${VMA_DEBUG_DONT_EXCEED_MAX_MEMORY_ALLOCATION_COUNT}>
VMA_RECORDING_ENABLED=$<BOOL:${VMA_RECORDING_ENABLED}>
)
if (VMA_BUILD_SAMPLE)
if(WIN32)
set(VMA_SAMPLE_SOURCE_FILES
Common.cpp
SparseBindingTest.cpp
Tests.cpp
VulkanSample.cpp
)
add_executable(VmaSample ${VMA_SAMPLE_SOURCE_FILES})
# Visual Studio specific settings
if(${CMAKE_GENERATOR} MATCHES "Visual Studio.*")
# Use Unicode instead of multibyte set
add_compile_definitions(UNICODE _UNICODE)
# Set VmaSample as startup project
set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT "VmaSample")
# Enable multithreaded compiling
target_compile_options(VmaSample PRIVATE "/MP")
# Set working directory for Visual Studio debugger
set_target_properties(
VmaSample
PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/bin"
)
endif()
set_target_properties(
VmaSample PROPERTIES
CXX_EXTENSIONS OFF
# Use C++14
CXX_STANDARD 14
CXX_STANDARD_REQUIRED ON
)
target_link_libraries(
VmaSample
PRIVATE
VulkanMemoryAllocator
Vulkan::Vulkan
)
else()
message(STATUS "VmaSample application is not supported to Linux")
endif()
endif()
if(VMA_BUILD_SAMPLE_SHADERS)
add_subdirectory(Shaders)
endif()
if(VMA_BUILD_REPLAY)
add_subdirectory(VmaReplay)
endif()

View File

@ -0,0 +1,32 @@
# This file will only be executed if VMA_BUILD_SAMPLE_SHADERS is set to ON
find_program(GLSL_VALIDATOR glslangValidator REQUIRED)
if(NOT GLSL_VALIDATOR)
message(FATAL_ERROR "glslangValidator not found!")
endif()
set(SHADERS
Shader.vert
Shader.frag
SparseBindingTest.comp
)
# Compile each shader using glslangValidator
foreach(SHADER ${SHADERS})
get_filename_component(FILE_NAME ${SHADER} NAME)
# Put the .spv files into the bin folder
set(SPIRV ${PROJECT_SOURCE_DIR}/bin/${FILE_NAME}.spv)
add_custom_command(
OUTPUT ${SPIRV}
# Use the same file name and append .spv to the compiled shader
COMMAND ${GLSL_VALIDATOR} -V ${CMAKE_CURRENT_SOURCE_DIR}/${SHADER} -o ${SPIRV}
DEPENDS ${SHADER}
)
list(APPEND SPIRV_FILES ${SPIRV})
endforeach()
add_custom_target(VmaSampleShaders ALL DEPENDS ${SPIRV_FILES})

View File

@ -0,0 +1,24 @@
# This file will only be executed if VMA_BUILD_REPLAY is set to ON
if (WIN32)
set(VMA_REPLAY_SOURCE_FILES
Common.cpp
Constants.cpp
VmaReplay.cpp
VmaUsage.cpp
)
add_executable(VmaReplay ${VMA_REPLAY_SOURCE_FILES})
# Enable multithreaded compiling
target_compile_options(VmaReplay PRIVATE "/MP")
target_link_libraries(
VmaReplay
PRIVATE
Vulkan::Vulkan
)
else()
message(STATUS "VmaReplay is not supported on Linux")
endif()

View File

@ -48,18 +48,12 @@ include all public interface declarations. Example:
*/
//#define VMA_HEAVY_ASSERT(expr) assert(expr)
//#define VMA_USE_STL_CONTAINERS 1
//#define VMA_DEDICATED_ALLOCATION 0
//#define VMA_DEBUG_MARGIN 16
//#define VMA_DEBUG_DETECT_CORRUPTION 1
//#define VMA_DEBUG_INITIALIZE_ALLOCATIONS 1
//#define VMA_RECORDING_ENABLED 1
//#define VMA_DEBUG_MIN_BUFFER_IMAGE_GRANULARITY 256
//#define VMA_USE_STL_SHARED_MUTEX 0
//#define VMA_DEBUG_GLOBAL_MUTEX 1
//#define VMA_MEMORY_BUDGET 0
#define VMA_STATIC_VULKAN_FUNCTIONS 0
#define VMA_DYNAMIC_VULKAN_FUNCTIONS 1
#define VMA_VULKAN_VERSION 1002000 // Vulkan 1.2
//#define VMA_VULKAN_VERSION 1001000 // Vulkan 1.1