diff --git a/third_party/vkmemalloc/.gitignore b/third_party/vkmemalloc/.gitignore
index 88ea8d1152..98d315649a 100644
--- a/third_party/vkmemalloc/.gitignore
+++ b/third_party/vkmemalloc/.gitignore
@@ -1,2 +1,13 @@
-build/
+/bin/*
+/build/*
+!/build/src/
+/build/src/*
+!/build/src/Release/
+/build/src/Release/*
+!/build/src/Release/VmaSample.exe
+!/build/src/VmaReplay/
+/build/src/VmaReplay/*
+!/build/src/VmaReplay/Release/
+/build/src/VmaReplay/Release/*
+!/build/src/VmaReplay/Release/VmaReplay.exe
diff --git a/third_party/vkmemalloc/.travis.yml b/third_party/vkmemalloc/.travis.yml
index 2a68740864..342a73c463 100644
--- a/third_party/vkmemalloc/.travis.yml
+++ b/third_party/vkmemalloc/.travis.yml
@@ -1,7 +1,7 @@
language: cpp
sudo: required
os: linux
-dist: trusty
+dist: bionic
branches:
only:
@@ -12,24 +12,22 @@ compiler:
- gcc
before_script:
- - sudo apt-get install
+ - sudo apt-get install
+ - eval "${MATRIX_EVAL}"
install:
- - wget https://github.com/premake/premake-core/releases/download/v5.0.0-alpha11/premake-5.0.0-alpha11-linux.tar.gz?Human=true -O premake-5.0.0-alpha11-linux.tar.gz
- - tar -xzvf premake-5.0.0-alpha11-linux.tar.gz
- sudo apt-get -qq update
- sudo apt-get install -y libassimp-dev libglm-dev graphviz libxcb-dri3-0 libxcb-present0 libpciaccess0 cmake libpng-dev libxcb-dri3-dev libx11-dev libx11-xcb-dev libmirclient-dev libwayland-dev libxrandr-dev
- export VK_VERSION=1.2.131.1
- - wget -O vulkansdk-linux-x86_64-$VK_VERSION.tar.gz https://sdk.lunarg.com/sdk/download/$VK_VERSION/linux/vulkansdk-linux-x86_64-$VK_VERSION.tar.gz
+ - wget -O vulkansdk-linux-x86_64-$VK_VERSION.tar.gz https://sdk.lunarg.com/sdk/download/$VK_VERSION/linux/vulkansdk-linux-x86_64-$VK_VERSION.tar.gz?Human=true
- tar zxf vulkansdk-linux-x86_64-$VK_VERSION.tar.gz
- export VULKAN_SDK=$TRAVIS_BUILD_DIR/$VK_VERSION/x86_64
script:
- - cd premake
- - ../premake5 gmake
- - cd ../build
- - make config=debug_linux-x64
- - cd ..
+ - mkdir build
+ - cd build
+ - cmake ..
+ - make
notifications:
email:
diff --git a/third_party/vkmemalloc/CMakeLists.txt b/third_party/vkmemalloc/CMakeLists.txt
new file mode 100644
index 0000000000..3c323ceb51
--- /dev/null
+++ b/third_party/vkmemalloc/CMakeLists.txt
@@ -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)
diff --git a/third_party/vkmemalloc/src/Doxyfile b/third_party/vkmemalloc/Doxyfile
similarity index 90%
rename from third_party/vkmemalloc/src/Doxyfile
rename to third_party/vkmemalloc/Doxyfile
index b880bb2c59..0d50ff3335 100644
--- a/third_party/vkmemalloc/src/Doxyfile
+++ b/third_party/vkmemalloc/Doxyfile
@@ -1,4 +1,4 @@
-# Doxyfile 1.8.16
+# Doxyfile 1.9.1
# This file describes the settings to be used by the documentation system
# doxygen (www.doxygen.org) for a project.
@@ -58,7 +58,7 @@ PROJECT_LOGO =
# entered, it will be relative to the location where doxygen was started. If
# left blank the current directory will be used.
-OUTPUT_DIRECTORY = ../docs
+OUTPUT_DIRECTORY = docs
# If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub-
# directories (in 2 levels) under the output directory of each output format and
@@ -227,6 +227,14 @@ QT_AUTOBRIEF = NO
MULTILINE_CPP_IS_BRIEF = NO
+# By default Python docstrings are displayed as preformatted text and doxygen's
+# special commands cannot be used. By setting PYTHON_DOCSTRING to NO the
+# doxygen's special commands can be used and the contents of the docstring
+# documentation blocks is shown as doxygen documentation.
+# The default value is: YES.
+
+PYTHON_DOCSTRING = YES
+
# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the
# documentation from any documented member that it re-implements.
# The default value is: YES.
@@ -263,12 +271,6 @@ TAB_SIZE = 4
ALIASES =
-# This tag can be used to specify a number of word-keyword mappings (TCL only).
-# A mapping has the form "name=value". For example adding "class=itcl::class"
-# will allow you to use the command class in the itcl::class meaning.
-
-TCL_SUBST =
-
# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources
# only. Doxygen will then generate output that is more tailored for C. For
# instance, some of the names that are used will be different. The list of all
@@ -309,19 +311,22 @@ OPTIMIZE_OUTPUT_SLICE = NO
# parses. With this tag you can assign which parser to use for a given
# extension. Doxygen has a built-in mapping, but you can override or extend it
# using this tag. The format is ext=language, where ext is a file extension, and
-# language is one of the parsers supported by doxygen: IDL, Java, Javascript,
-# Csharp (C#), C, C++, D, PHP, md (Markdown), Objective-C, Python, Slice,
+# language is one of the parsers supported by doxygen: IDL, Java, JavaScript,
+# Csharp (C#), C, C++, D, PHP, md (Markdown), Objective-C, Python, Slice, VHDL,
# Fortran (fixed format Fortran: FortranFixed, free formatted Fortran:
# FortranFree, unknown formatted Fortran: Fortran. In the later case the parser
# tries to guess whether the code is fixed or free formatted code, this is the
-# default for Fortran type files), VHDL, tcl. For instance to make doxygen treat
-# .inc files as Fortran files (default is PHP), and .f files as C (default is
-# Fortran), use: inc=Fortran f=C.
+# default for Fortran type files). For instance to make doxygen treat .inc files
+# as Fortran files (default is PHP), and .f files as C (default is Fortran),
+# use: inc=Fortran f=C.
#
# Note: For files without extension you can use no_extension as a placeholder.
#
# Note that for custom extensions you also need to set FILE_PATTERNS otherwise
-# the files are not read by doxygen.
+# the files are not read by doxygen. When specifying no_extension you should add
+# * to the FILE_PATTERNS.
+#
+# Note see also the list of default file extension mappings.
EXTENSION_MAPPING =
@@ -455,6 +460,19 @@ TYPEDEF_HIDES_STRUCT = NO
LOOKUP_CACHE_SIZE = 0
+# The NUM_PROC_THREADS specifies the number threads doxygen is allowed to use
+# during processing. When set to 0 doxygen will based this on the number of
+# cores available in the system. You can set it explicitly to a value larger
+# than 0 to get more control over the balance between CPU load and processing
+# speed. At this moment only the input processing can be done using multiple
+# threads. Since this is still an experimental feature the default is set to 1,
+# which efficively disables parallel processing. Please report any issues you
+# encounter. Generating dot graphs in parallel is controlled by the
+# DOT_NUM_THREADS setting.
+# Minimum value: 0, maximum value: 32, default value: 1.
+
+NUM_PROC_THREADS = 1
+
#---------------------------------------------------------------------------
# Build related configuration options
#---------------------------------------------------------------------------
@@ -518,6 +536,13 @@ EXTRACT_LOCAL_METHODS = NO
EXTRACT_ANON_NSPACES = NO
+# If this flag is set to YES, the name of an unnamed parameter in a declaration
+# will be determined by the corresponding definition. By default unnamed
+# parameters remain unnamed in the output.
+# The default value is: YES.
+
+RESOLVE_UNNAMED_PARAMS = YES
+
# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all
# undocumented members inside documented classes or files. If set to NO these
# members will be included in the various overviews, but no documentation
@@ -535,8 +560,8 @@ HIDE_UNDOC_MEMBERS = NO
HIDE_UNDOC_CLASSES = NO
# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend
-# (class|struct|union) declarations. If set to NO, these declarations will be
-# included in the documentation.
+# declarations. If set to NO, these declarations will be included in the
+# documentation.
# The default value is: NO.
HIDE_FRIEND_COMPOUNDS = NO
@@ -555,11 +580,18 @@ HIDE_IN_BODY_DOCS = NO
INTERNAL_DOCS = NO
-# If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file
-# names in lower-case letters. If set to YES, upper-case letters are also
-# allowed. This is useful if you have classes or files whose names only differ
-# in case and if your file system supports case sensitive file names. Windows
-# (including Cygwin) ands Mac users are advised to set this option to NO.
+# With the correct setting of option CASE_SENSE_NAMES doxygen will better be
+# able to match the capabilities of the underlying filesystem. In case the
+# filesystem is case sensitive (i.e. it supports files in the same directory
+# whose names only differ in casing), the option must be set to YES to properly
+# deal with such files in case they appear in the input. For filesystems that
+# are not case sensitive the option should be be set to NO to properly deal with
+# output files written for symbols that only differ in casing, such as for two
+# classes, one named CLASS and the other named Class, and to also support
+# references to files without having to specify the exact matching casing. On
+# Windows (including Cygwin) and MacOS, users should typically set this option
+# to NO, whereas on Linux or other Unix flavors it should typically be set to
+# YES.
# The default value is: system dependent.
CASE_SENSE_NAMES = NO
@@ -798,7 +830,10 @@ WARN_IF_DOC_ERROR = YES
WARN_NO_PARAMDOC = NO
# If the WARN_AS_ERROR tag is set to YES then doxygen will immediately stop when
-# a warning is encountered.
+# a warning is encountered. If the WARN_AS_ERROR tag is set to FAIL_ON_WARNINGS
+# then doxygen will continue running as if WARN_AS_ERROR tag is set to NO, but
+# at the end of the doxygen process doxygen will return with a non-zero status.
+# Possible values are: NO, YES and FAIL_ON_WARNINGS.
# The default value is: NO.
WARN_AS_ERROR = NO
@@ -829,13 +864,13 @@ WARN_LOGFILE =
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
# Note: If this tag is empty the current directory is searched.
-INPUT = vk_mem_alloc.h
+INPUT = include/vk_mem_alloc.h
# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
# libiconv (or the iconv built into libc) for the transcoding. See the libiconv
-# documentation (see: https://www.gnu.org/software/libiconv/) for the list of
-# possible encodings.
+# documentation (see:
+# https://www.gnu.org/software/libiconv/) for the list of possible encodings.
# The default value is: UTF-8.
INPUT_ENCODING = UTF-8
@@ -848,11 +883,15 @@ INPUT_ENCODING = UTF-8
# need to set EXTENSION_MAPPING for the extension otherwise the files are not
# read by doxygen.
#
+# Note the list of default checked file patterns might differ from the list of
+# default file extension mappings.
+#
# If left blank the following patterns are tested:*.c, *.cc, *.cxx, *.cpp,
# *.c++, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h,
# *.hh, *.hxx, *.hpp, *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc,
-# *.m, *.markdown, *.md, *.mm, *.dox, *.py, *.pyw, *.f90, *.f95, *.f03, *.f08,
-# *.f, *.for, *.tcl, *.vhd, *.vhdl, *.ucf, *.qsf and *.ice.
+# *.m, *.markdown, *.md, *.mm, *.dox (to be provided as doxygen C comment),
+# *.py, *.pyw, *.f90, *.f95, *.f03, *.f08, *.f18, *.f, *.for, *.vhd, *.vhdl,
+# *.ucf, *.qsf and *.ice.
FILE_PATTERNS = *.c \
*.cc \
@@ -1110,16 +1149,22 @@ USE_HTAGS = NO
VERBATIM_HEADERS = YES
# If the CLANG_ASSISTED_PARSING tag is set to YES then doxygen will use the
-# clang parser (see: http://clang.llvm.org/) for more accurate parsing at the
-# cost of reduced performance. This can be particularly helpful with template
-# rich C++ code for which doxygen's built-in parser lacks the necessary type
-# information.
+# clang parser (see:
+# http://clang.llvm.org/) for more accurate parsing at the cost of reduced
+# performance. This can be particularly helpful with template rich C++ code for
+# which doxygen's built-in parser lacks the necessary type information.
# Note: The availability of this option depends on whether or not doxygen was
# generated with the -Duse_libclang=ON option for CMake.
# The default value is: NO.
CLANG_ASSISTED_PARSING = NO
+# If clang assisted parsing is enabled and the CLANG_ADD_INC_PATHS tag is set to
+# YES then doxygen will add the directory of each input to the include path.
+# The default value is: YES.
+
+CLANG_ADD_INC_PATHS = YES
+
# If clang assisted parsing is enabled you can provide the compiler with command
# line options that you would normally use when invoking the compiler. Note that
# the include paths will already be set by doxygen for the files and directories
@@ -1129,10 +1174,13 @@ CLANG_ASSISTED_PARSING = NO
CLANG_OPTIONS =
# If clang assisted parsing is enabled you can provide the clang parser with the
-# path to the compilation database (see:
-# http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html) used when the files
-# were built. This is equivalent to specifying the "-p" option to a clang tool,
-# such as clang-check. These options will then be passed to the parser.
+# path to the directory containing a file called compile_commands.json. This
+# file is the compilation database (see:
+# http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html) containing the
+# options used when the source files were built. This is equivalent to
+# specifying the -p option to a clang tool, such as clang-check. These options
+# will then be passed to the parser. Any options specified with CLANG_OPTIONS
+# will be added as well.
# Note: The availability of this option depends on whether or not doxygen was
# generated with the -Duse_libclang=ON option for CMake.
@@ -1149,13 +1197,6 @@ CLANG_DATABASE_PATH =
ALPHABETICAL_INDEX = YES
-# The COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns in
-# which the alphabetical index list will be split.
-# Minimum value: 1, maximum value: 20, default value: 5.
-# This tag requires that the tag ALPHABETICAL_INDEX is set to YES.
-
-COLS_IN_ALPHA_INDEX = 5
-
# In case all classes in a project start with a common prefix, all classes will
# be put under the same header in the alphabetical index. The IGNORE_PREFIX tag
# can be used to specify a prefix (or a list of prefixes) that should be ignored
@@ -1294,9 +1335,9 @@ HTML_TIMESTAMP = NO
# If the HTML_DYNAMIC_MENUS tag is set to YES then the generated HTML
# documentation will contain a main index with vertical navigation menus that
-# are dynamically created via Javascript. If disabled, the navigation index will
+# are dynamically created via JavaScript. If disabled, the navigation index will
# consists of multiple levels of tabs that are statically embedded in every HTML
-# page. Disable this option to support browsers that do not have Javascript,
+# page. Disable this option to support browsers that do not have JavaScript,
# like the Qt help browser.
# The default value is: YES.
# This tag requires that the tag GENERATE_HTML is set to YES.
@@ -1326,10 +1367,11 @@ HTML_INDEX_NUM_ENTRIES = 100
# If the GENERATE_DOCSET tag is set to YES, additional index files will be
# generated that can be used as input for Apple's Xcode 3 integrated development
-# environment (see: https://developer.apple.com/xcode/), introduced with OSX
-# 10.5 (Leopard). To create a documentation set, doxygen will generate a
-# Makefile in the HTML output directory. Running make will produce the docset in
-# that directory and running make install will install the docset in
+# environment (see:
+# https://developer.apple.com/xcode/), introduced with OSX 10.5 (Leopard). To
+# create a documentation set, doxygen will generate a Makefile in the HTML
+# output directory. Running make will produce the docset in that directory and
+# running make install will install the docset in
# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at
# startup. See https://developer.apple.com/library/archive/featuredarticles/Doxy
# genXcode/_index.html for more information.
@@ -1371,8 +1413,8 @@ DOCSET_PUBLISHER_NAME = Publisher
# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three
# additional HTML index files: index.hhp, index.hhc, and index.hhk. The
# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop
-# (see: https://www.microsoft.com/en-us/download/details.aspx?id=21138) on
-# Windows.
+# (see:
+# https://www.microsoft.com/en-us/download/details.aspx?id=21138) on Windows.
#
# The HTML Help Workshop contains a compiler that can convert all HTML output
# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML
@@ -1402,7 +1444,7 @@ CHM_FILE =
HHC_LOCATION =
# The GENERATE_CHI flag controls if a separate .chi index file is generated
-# (YES) or that it should be included in the master .chm file (NO).
+# (YES) or that it should be included in the main .chm file (NO).
# The default value is: NO.
# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
@@ -1447,7 +1489,8 @@ QCH_FILE =
# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help
# Project output. For more information please see Qt Help Project / Namespace
-# (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#namespace).
+# (see:
+# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#namespace).
# The default value is: org.doxygen.Project.
# This tag requires that the tag GENERATE_QHP is set to YES.
@@ -1455,8 +1498,8 @@ QHP_NAMESPACE = org.doxygen.Project
# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt
# Help Project output. For more information please see Qt Help Project / Virtual
-# Folders (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#virtual-
-# folders).
+# Folders (see:
+# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#virtual-folders).
# The default value is: doc.
# This tag requires that the tag GENERATE_QHP is set to YES.
@@ -1464,16 +1507,16 @@ QHP_VIRTUAL_FOLDER = doc
# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom
# filter to add. For more information please see Qt Help Project / Custom
-# Filters (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-
-# filters).
+# Filters (see:
+# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-filters).
# This tag requires that the tag GENERATE_QHP is set to YES.
QHP_CUST_FILTER_NAME =
# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the
# custom filter to add. For more information please see Qt Help Project / Custom
-# Filters (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-
-# filters).
+# Filters (see:
+# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-filters).
# This tag requires that the tag GENERATE_QHP is set to YES.
QHP_CUST_FILTER_ATTRS =
@@ -1485,9 +1528,9 @@ QHP_CUST_FILTER_ATTRS =
QHP_SECT_FILTER_ATTRS =
-# The QHG_LOCATION tag can be used to specify the location of Qt's
-# qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the
-# generated .qhp file.
+# The QHG_LOCATION tag can be used to specify the location (absolute path
+# including file name) of Qt's qhelpgenerator. If non-empty doxygen will try to
+# run qhelpgenerator on the generated .qhp file.
# This tag requires that the tag GENERATE_QHP is set to YES.
QHG_LOCATION =
@@ -1564,6 +1607,17 @@ TREEVIEW_WIDTH = 250
EXT_LINKS_IN_WINDOW = NO
+# If the HTML_FORMULA_FORMAT option is set to svg, doxygen will use the pdf2svg
+# tool (see https://github.com/dawbarton/pdf2svg) or inkscape (see
+# https://inkscape.org) to generate formulas as SVG images instead of PNGs for
+# the HTML output. These images will generally look nicer at scaled resolutions.
+# Possible values are: png (the default) and svg (looks nicer but requires the
+# pdf2svg or inkscape tool).
+# The default value is: png.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_FORMULA_FORMAT = png
+
# Use this tag to change the font size of LaTeX formulas included as images in
# the HTML documentation. When you change the font size after a successful
# doxygen run you need to manually remove any form_*.png images from the HTML
@@ -1584,8 +1638,14 @@ FORMULA_FONTSIZE = 10
FORMULA_TRANSPARENT = YES
+# The FORMULA_MACROFILE can contain LaTeX \newcommand and \renewcommand commands
+# to create new LaTeX commands to be used in formulas as building blocks. See
+# the section "Including formulas" for details.
+
+FORMULA_MACROFILE =
+
# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see
-# https://www.mathjax.org) which uses client side Javascript for the rendering
+# https://www.mathjax.org) which uses client side JavaScript for the rendering
# instead of using pre-rendered bitmaps. Use this if you do not have LaTeX
# installed or if you want to formulas look prettier in the HTML output. When
# enabled you may also need to install MathJax separately and configure the path
@@ -1597,7 +1657,7 @@ USE_MATHJAX = NO
# When MathJax is enabled you can set the default output format to be used for
# the MathJax output. See the MathJax site (see:
-# http://docs.mathjax.org/en/latest/output.html) for more details.
+# http://docs.mathjax.org/en/v2.7-latest/output.html) for more details.
# Possible values are: HTML-CSS (which is slower, but has the best
# compatibility), NativeMML (i.e. MathML) and SVG.
# The default value is: HTML-CSS.
@@ -1613,7 +1673,7 @@ MATHJAX_FORMAT = HTML-CSS
# Content Delivery Network so you can quickly see the result without installing
# MathJax. However, it is strongly recommended to install a local copy of
# MathJax from https://www.mathjax.org before deployment.
-# The default value is: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/.
+# The default value is: https://cdn.jsdelivr.net/npm/mathjax@2.
# This tag requires that the tag USE_MATHJAX is set to YES.
MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest
@@ -1627,7 +1687,8 @@ MATHJAX_EXTENSIONS =
# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces
# of code that will be used on startup of the MathJax code. See the MathJax site
-# (see: http://docs.mathjax.org/en/latest/output.html) for more details. For an
+# (see:
+# http://docs.mathjax.org/en/v2.7-latest/output.html) for more details. For an
# example see the documentation.
# This tag requires that the tag USE_MATHJAX is set to YES.
@@ -1655,7 +1716,7 @@ MATHJAX_CODEFILE =
SEARCHENGINE = YES
# When the SERVER_BASED_SEARCH tag is enabled the search engine will be
-# implemented using a web server instead of a web client using Javascript. There
+# implemented using a web server instead of a web client using JavaScript. There
# are two flavors of web server based searching depending on the EXTERNAL_SEARCH
# setting. When disabled, doxygen will generate a PHP script for searching and
# an index file used by the script. When EXTERNAL_SEARCH is enabled the indexing
@@ -1674,7 +1735,8 @@ SERVER_BASED_SEARCH = NO
#
# Doxygen ships with an example indexer (doxyindexer) and search engine
# (doxysearch.cgi) which are based on the open source search engine library
-# Xapian (see: https://xapian.org/).
+# Xapian (see:
+# https://xapian.org/).
#
# See the section "External Indexing and Searching" for details.
# The default value is: NO.
@@ -1687,8 +1749,9 @@ EXTERNAL_SEARCH = NO
#
# Doxygen ships with an example indexer (doxyindexer) and search engine
# (doxysearch.cgi) which are based on the open source search engine library
-# Xapian (see: https://xapian.org/). See the section "External Indexing and
-# Searching" for details.
+# Xapian (see:
+# https://xapian.org/). See the section "External Indexing and Searching" for
+# details.
# This tag requires that the tag SEARCHENGINE is set to YES.
SEARCHENGINE_URL =
@@ -1852,9 +1915,11 @@ LATEX_EXTRA_FILES =
PDF_HYPERLINKS = YES
-# If the USE_PDFLATEX tag is set to YES, doxygen will use pdflatex to generate
-# the PDF file directly from the LaTeX files. Set this option to YES, to get a
-# higher quality PDF documentation.
+# If the USE_PDFLATEX tag is set to YES, doxygen will use the engine as
+# specified with LATEX_CMD_NAME to generate the PDF file directly from the LaTeX
+# files. Set this option to YES, to get a higher quality PDF documentation.
+#
+# See also section LATEX_CMD_NAME for selecting the engine.
# The default value is: YES.
# This tag requires that the tag GENERATE_LATEX is set to YES.
@@ -2188,7 +2253,13 @@ INCLUDE_FILE_PATTERNS =
# recursively expanded use the := operator instead of the = operator.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
-PREDEFINED = VMA_CALL_PRE= VMA_CALL_POST= VMA_NOT_NULL= VMA_NULLABLE= VMA_LEN_IF_NOT_NULL(len)= VMA_NOT_NULL_NON_DISPATCHABLE= VMA_NULLABLE_NON_DISPATCHABLE=
+PREDEFINED = VMA_CALL_PRE= \
+ VMA_CALL_POST= \
+ VMA_NOT_NULL= \
+ VMA_NULLABLE= \
+ VMA_LEN_IF_NOT_NULL(len)= \
+ VMA_NOT_NULL_NON_DISPATCHABLE= \
+ VMA_NULLABLE_NON_DISPATCHABLE=
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
# tag can be used to specify a list of macro names that should be expanded. The
@@ -2365,10 +2436,32 @@ UML_LOOK = NO
# but if the number exceeds 15, the total amount of fields shown is limited to
# 10.
# Minimum value: 0, maximum value: 100, default value: 10.
-# This tag requires that the tag HAVE_DOT is set to YES.
+# This tag requires that the tag UML_LOOK is set to YES.
UML_LIMIT_NUM_FIELDS = 10
+# If the DOT_UML_DETAILS tag is set to NO, doxygen will show attributes and
+# methods without types and arguments in the UML graphs. If the DOT_UML_DETAILS
+# tag is set to YES, doxygen will add type and arguments for attributes and
+# methods in the UML graphs. If the DOT_UML_DETAILS tag is set to NONE, doxygen
+# will not generate fields with class member information in the UML graphs. The
+# class diagrams will look similar to the default class diagrams but using UML
+# notation for the relationships.
+# Possible values are: NO, YES and NONE.
+# The default value is: NO.
+# This tag requires that the tag UML_LOOK is set to YES.
+
+DOT_UML_DETAILS = NO
+
+# The DOT_WRAP_THRESHOLD tag can be used to set the maximum number of characters
+# to display on a single line. If the actual line length exceeds this threshold
+# significantly it will wrapped across multiple lines. Some heuristics are apply
+# to avoid ugly line breaks.
+# Minimum value: 0, maximum value: 1000, default value: 17.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_WRAP_THRESHOLD = 17
+
# If the TEMPLATE_RELATIONS tag is set to YES then the inheritance and
# collaboration graphs will show the relations between templates and their
# instances.
@@ -2558,9 +2651,11 @@ DOT_MULTI_TARGETS = NO
GENERATE_LEGEND = YES
-# If the DOT_CLEANUP tag is set to YES, doxygen will remove the intermediate dot
+# If the DOT_CLEANUP tag is set to YES, doxygen will remove the intermediate
# files that are used to generate the various graphs.
+#
+# Note: This setting is not only used for dot files but also for msc and
+# plantuml temporary files.
# The default value is: YES.
-# This tag requires that the tag HAVE_DOT is set to YES.
DOT_CLEANUP = YES
diff --git a/third_party/vkmemalloc/LICENSE.txt b/third_party/vkmemalloc/LICENSE.txt
index bee6af703f..71e824f805 100644
--- a/third_party/vkmemalloc/LICENSE.txt
+++ b/third_party/vkmemalloc/LICENSE.txt
@@ -1,4 +1,4 @@
-Copyright (c) 2017-2020 Advanced Micro Devices, Inc. All rights reserved.
+Copyright (c) 2017-2021 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/third_party/vkmemalloc/README.md b/third_party/vkmemalloc/README.md
index 3c778a2057..b1e2dba2c4 100644
--- a/third_party/vkmemalloc/README.md
+++ b/third_party/vkmemalloc/README.md
@@ -2,7 +2,7 @@
Easy to integrate Vulkan memory allocation library.
-**Documentation:** See [Vulkan Memory Allocator](https://gpuopen-librariesandsdks.github.io/VulkanMemoryAllocator/html/) (generated from Doxygen-style comments in [src/vk_mem_alloc.h](src/vk_mem_alloc.h))
+**Documentation:** See [Vulkan Memory Allocator](https://gpuopen-librariesandsdks.github.io/VulkanMemoryAllocator/html/) (generated from Doxygen-style comments in [include/vk_mem_alloc.h](include/vk_mem_alloc.h))
**License:** MIT. See [LICENSE.txt](LICENSE.txt)
@@ -13,7 +13,7 @@ Easy to integrate Vulkan memory allocation library.
**Build status:**
- Windows: [](https://ci.appveyor.com/project/adam-sawicki-amd/vulkanmemoryallocator/branch/master)
-- Linux: [](https://travis-ci.org/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator)
+- Linux: [](https://travis-ci.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator)
# Problem
@@ -37,7 +37,7 @@ This library can help game developers to manage memory allocations and resource
Additional features:
- Well-documented - description of all functions and structures provided, along with chapters that contain general description and example code.
-- Thread-safety: Library is designed to be used by multithreaded code.
+- Thread-safety: Library is designed to be used in multithreaded code. Access to a single device memory block referred by different buffers and textures (binding, mapping) is synchronized internally.
- Configuration: Fill optional members of CreateInfo structure to provide custom CPU memory allocator, pointers to Vulkan functions and other parameters.
- Customization: Predefine appropriate macros to provide your own implementation of all external facilities used by the library, from assert, mutex, and atomic, to vector and linked list.
- Support for memory mapping, reference-counted internally. Support for persistently mapped memory: Just allocate with appropriate flag and you get access to mapped pointer.
@@ -94,9 +94,45 @@ 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 2017, so they require appropriate libraries to work, including "vcruntime140.dll" and "msvcp140.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.
+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.
# Read more
@@ -104,6 +140,7 @@ See **[Documentation](https://gpuopen-librariesandsdks.github.io/VulkanMemoryAll
# Software using this library
+- **[Detroit: Become Human](https://gpuopen.com/learn/porting-detroit-3/)**
- **[Vulkan Samples](https://github.com/LunarG/VulkanSamples)** - official Khronos Vulkan samples. License: Apache-style.
- **[Anvil](https://github.com/GPUOpen-LibrariesAndSDKs/Anvil)** - cross-platform framework for Vulkan. License: MIT.
- **[Filament](https://github.com/google/filament)** - physically based rendering engine for Android, Windows, Linux and macOS, from Google. Apache License 2.0.
@@ -117,6 +154,7 @@ See **[Documentation](https://gpuopen-librariesandsdks.github.io/VulkanMemoryAll
- **[vkDOOM3](https://github.com/DustinHLand/vkDOOM3)** - Vulkan port of GPL DOOM 3 BFG Edition. License: GNU GPL.
- **[vkQuake2](https://github.com/kondrak/vkQuake2)** - vanilla Quake 2 with Vulkan support. License: GNU GPL.
- **[Vulkan Best Practice for Mobile Developers](https://github.com/ARM-software/vulkan_best_practice_for_mobile_developers)** from ARM. License: MIT.
+- **[RPCS3](https://github.com/RPCS3/rpcs3)** - PlayStation 3 emulator/debugger. License: GNU GPLv2.
[Many other projects on GitHub](https://github.com/search?q=AMD_VULKAN_MEMORY_ALLOCATOR_H&type=Code) and some game development studios that use Vulkan in their games.
diff --git a/third_party/vkmemalloc/src/vk_mem_alloc.h b/third_party/vkmemalloc/include/vk_mem_alloc.h
similarity index 93%
rename from third_party/vkmemalloc/src/vk_mem_alloc.h
rename to third_party/vkmemalloc/include/vk_mem_alloc.h
index 2d1134daaa..852f86ab82 100644
--- a/third_party/vkmemalloc/src/vk_mem_alloc.h
+++ b/third_party/vkmemalloc/include/vk_mem_alloc.h
@@ -1,5 +1,5 @@
//
-// Copyright (c) 2017-2020 Advanced Micro Devices, Inc. All rights reserved.
+// Copyright (c) 2017-2021 Advanced Micro Devices, Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -25,9 +25,9 @@
/** \mainpage Vulkan Memory Allocator
-Version 3.0.0-development (2020-06-24)
+Version 3.0.0-development (2021-02-16)
-Copyright (c) 2017-2020 Advanced Micro Devices, Inc. All rights reserved. \n
+Copyright (c) 2017-2021 Advanced Micro Devices, Inc. All rights reserved. \n
License: MIT
Documentation of all members: vk_mem_alloc.h
@@ -122,7 +122,7 @@ To do it properly:
-# Include "vk_mem_alloc.h" file in each CPP file where you want to use the library.
This includes declarations of all members of the library.
--# In exacly one CPP file define following macro before this include.
+-# In exactly one CPP file define following macro before this include.
It enables also internal definitions.
\code
@@ -142,6 +142,15 @@ before including these headers (like `WIN32_LEAN_AND_MEAN` or
`WINVER` for Windows, `VK_USE_PLATFORM_WIN32_KHR` for Vulkan), you must define
them before every `#include` of this library.
+You may need to configure the way you import Vulkan functions.
+
+- By default, VMA assumes you you link statically with Vulkan API. If this is not the case,
+ `#define VMA_STATIC_VULKAN_FUNCTIONS 0` before `#include` of the VMA implementation and use another way.
+- You can `#define VMA_DYNAMIC_VULKAN_FUNCTIONS 1` and make sure `vkGetInstanceProcAddr` and `vkGetDeviceProcAddr` globals are defined.
+ All the remaining Vulkan functions will be fetched automatically.
+- Finally, you can provide your own pointers to all Vulkan functions needed by VMA using structure member
+ VmaAllocatorCreateInfo::pVulkanFunctions, if you fetched them in some custom way e.g. using some loader like [Volk](https://github.com/zeux/volk).
+
\section quick_start_initialization Initialization
@@ -153,6 +162,7 @@ At program startup:
\code
VmaAllocatorCreateInfo allocatorInfo = {};
+allocatorInfo.vulkanApiVersion = VK_API_VERSION_1_2;
allocatorInfo.physicalDevice = physicalDevice;
allocatorInfo.device = device;
allocatorInfo.instance = instance;
@@ -161,6 +171,13 @@ VmaAllocator allocator;
vmaCreateAllocator(&allocatorInfo, &allocator);
\endcode
+Only members `physicalDevice`, `device`, `instance` are required.
+However, you should inform the library which Vulkan version do you use by setting
+VmaAllocatorCreateInfo::vulkanApiVersion and which extensions did you enable
+by setting VmaAllocatorCreateInfo::flags (like #VMA_ALLOCATOR_CREATE_BUFFER_DEVICE_ADDRESS_BIT for VK_KHR_buffer_device_address).
+Otherwise, VMA would use only features of Vulkan 1.0 core with no extensions.
+
+
\section quick_start_resource_allocation Resource allocation
When you want to create a buffer or image:
@@ -423,12 +440,10 @@ There are some exceptions though, when you should consider mapping memory only f
block is migrated by WDDM to system RAM, which degrades performance. It doesn't
matter if that particular memory block is actually used by the command buffer
being submitted.
-- On Mac/MoltenVK there is a known bug - [Issue #175](https://github.com/KhronosGroup/MoltenVK/issues/175)
- which requires unmapping before GPU can see updated texture.
- Keeping many large memory blocks mapped may impact performance or stability of some debugging tools.
\section memory_mapping_cache_control Cache flush and invalidate
-
+
Memory in Vulkan doesn't need to be unmapped before using it on GPU,
but unless a memory types has `VK_MEMORY_PROPERTY_HOST_COHERENT_BIT` flag set,
you need to manually **invalidate** cache before reading of mapped pointer
@@ -686,7 +701,7 @@ vkDestroyImage(allocator, img2, nullptr);
vkDestroyImage(allocator, img1, nullptr);
\endcode
-Remember that using resouces that alias in memory requires proper synchronization.
+Remember that using resources that alias in memory requires proper synchronization.
You need to issue a memory barrier to make sure commands that use `img1` and `img2`
don't overlap on GPU timeline.
You also need to treat a resource after aliasing as uninitialized - containing garbage data.
@@ -932,7 +947,7 @@ allocations.
To mitigate this problem, you can use defragmentation feature:
structure #VmaDefragmentationInfo2, function vmaDefragmentationBegin(), vmaDefragmentationEnd().
-Given set of allocations,
+Given set of allocations,
this function can move them to compact used memory, ensure more continuous free
space and possibly also free some `VkDeviceMemory` blocks.
@@ -998,9 +1013,9 @@ for(uint32_t i = 0; i < allocCount; ++i)
// Create new buffer with same parameters.
VkBufferCreateInfo bufferInfo = ...;
vkCreateBuffer(device, &bufferInfo, nullptr, &buffers[i]);
-
+
// You can make dummy call to vkGetBufferMemoryRequirements here to silence validation layer warning.
-
+
// Bind new buffer to new memory region. Data contained in it is already moved.
VmaAllocationInfo allocInfo;
vmaGetAllocationInfo(allocator, allocations[i], &allocInfo);
@@ -1076,9 +1091,9 @@ for(uint32_t i = 0; i < allocCount; ++i)
// Create new buffer with same parameters.
VkBufferCreateInfo bufferInfo = ...;
vkCreateBuffer(device, &bufferInfo, nullptr, &buffers[i]);
-
+
// You can make dummy call to vkGetBufferMemoryRequirements here to silence validation layer warning.
-
+
// Bind new buffer to new memory region. Data contained in it is already moved.
VmaAllocationInfo allocInfo;
vmaGetAllocationInfo(allocator, allocations[i], &allocInfo);
@@ -1115,7 +1130,7 @@ See [Validation layer warnings](@ref general_considerations_validation_layer_war
Please don't expect memory to be fully compacted after defragmentation.
Algorithms inside are based on some heuristics that try to maximize number of Vulkan
-memory blocks to make totally empty to release them, as well as to maximimze continuous
+memory blocks to make totally empty to release them, as well as to maximize continuous
empty space inside remaining blocks, while minimizing the number and size of allocations that
need to be moved. Some fragmentation may still remain - this is normal.
@@ -1472,7 +1487,7 @@ which indicates a serious bug.
You can also explicitly request checking margins of all allocations in all memory blocks
that belong to specified memory types by using function vmaCheckCorruption(),
-or in memory blocks that belong to specified custom pool, by using function
+or in memory blocks that belong to specified custom pool, by using function
vmaCheckPoolCorruption().
Margin validation (corruption detection) works only for memory types that are
@@ -1656,7 +1671,7 @@ Which solution is the most efficient depends on your resource and especially on
It is best to measure it and then make the decision.
Some general recommendations:
-- On integrated graphics use (2) or (3) to avoid unnecesary time and memory overhead
+- On integrated graphics use (2) or (3) to avoid unnecessary time and memory overhead
related to using a second copy and making transfer.
- For small resources (e.g. constant buffers) use (2).
Discrete AMD cards have special 256 MiB pool of video memory that is directly mappable.
@@ -1749,7 +1764,7 @@ VmaAllocatorCreateInfo::pDeviceMemoryCallbacks.
When device memory of certain heap runs out of free space, new allocations may
fail (returning error code) or they may succeed, silently pushing some existing
memory blocks from GPU VRAM to system RAM (which degrades performance). This
-behavior is implementation-dependant - it depends on GPU vendor and graphics
+behavior is implementation-dependent - it depends on GPU vendor and graphics
driver.
On AMD cards it can be controlled while creating Vulkan device object by using
@@ -1807,7 +1822,7 @@ unaware of it.
To learn more about this extension, see:
-- [VK_KHR_dedicated_allocation in Vulkan specification](https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/chap44.html#VK_KHR_dedicated_allocation)
+- [VK_KHR_dedicated_allocation in Vulkan specification](https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/chap50.html#VK_KHR_dedicated_allocation)
- [VK_KHR_dedicated_allocation unofficial manual](http://asawicki.info/articles/VK_KHR_dedicated_allocation.php5)
@@ -1949,7 +1964,7 @@ to just ignore them.
up together, especially on GPUs with unified memory like Intel.
- *Non-linear image 0xebc91 is aliased with linear buffer 0xeb8e4 which may indicate a bug.*
- It happens when you use lost allocations, and a new image or buffer is
- created in place of an existing object that bacame lost.
+ created in place of an existing object that became lost.
- It may happen also when you use [defragmentation](@ref defragmentation).
\section general_considerations_allocation_algorithm Allocation algorithm
@@ -1972,7 +1987,7 @@ The library uses following algorithm for allocation, in order:
Features deliberately excluded from the scope of this library:
-- Data transfer. Uploading (straming) and downloading data of buffers and images
+- Data transfer. Uploading (streaming) and downloading data of buffers and images
between CPU and GPU memory and related synchronization is responsibility of the user.
Defining some "texture" object that would automatically stream its data from a
staging copy in CPU memory to GPU memory would rather be a feature of another,
@@ -1981,6 +1996,8 @@ Features deliberately excluded from the scope of this library:
explicit memory type index and dedicated allocation anyway, so they don't
interact with main features of this library. Such special purpose allocations
should be made manually, using `vkCreateBuffer()` and `vkAllocateMemory()`.
+- Sub-allocation of parts of one large buffer. Although recommended as a good practice,
+ it is the user's responsibility to implement such logic on top of VMA.
- Recreation of buffers and images. Although the library has functions for
buffer and image creation (vmaCreateBuffer(), vmaCreateImage()), you need to
recreate these objects yourself after defragmentation. That's because the big
@@ -1992,7 +2009,7 @@ Features deliberately excluded from the scope of this library:
is usually not needed in desktop PC applications anyway.
Success of an allocation is just checked with an assert.
- Code free of any compiler warnings. Maintaining the library to compile and
- work correctly on so many different platforms is hard enough. Being free of
+ work correctly on so many different platforms is hard enough. Being free of
any warnings, on any version of any compiler, is simply not feasible.
- This is a C++ library with C interface.
Bindings or ports to any other programming languages are welcomed as external projects and
@@ -2000,16 +2017,6 @@ Features deliberately excluded from the scope of this library:
*/
-#if VMA_RECORDING_ENABLED
- #include
- #if defined(_WIN32)
- #include
- #else
- #include
- #include
- #endif
-#endif
-
#ifdef __cplusplus
extern "C" {
#endif
@@ -2022,7 +2029,7 @@ available through VmaAllocatorCreateInfo::pRecordSettings.
#define VMA_RECORDING_ENABLED 0
#endif
-#ifndef NOMINMAX
+#if !defined(NOMINMAX) && defined(VMA_IMPLEMENTATION)
#define NOMINMAX // For windows.h
#endif
@@ -2105,6 +2112,15 @@ available through VmaAllocatorCreateInfo::pRecordSettings.
#endif
#endif
+// Defined to 1 when VK_EXT_memory_priority device extension is defined in Vulkan headers.
+#if !defined(VMA_MEMORY_PRIORITY)
+ #if VK_EXT_memory_priority
+ #define VMA_MEMORY_PRIORITY 1
+ #else
+ #define VMA_MEMORY_PRIORITY 0
+ #endif
+#endif
+
// Define these macros to decorate all public functions with additional code,
// before and after returned type, appropriately. This may be useful for
// exporting the functions when compiling VMA as a separate library. Example:
@@ -2224,7 +2240,7 @@ typedef enum VmaAllocatorCreateFlagBits {
The flag works only if VmaAllocatorCreateInfo::vulkanApiVersion `== VK_API_VERSION_1_0`.
When it's `VK_API_VERSION_1_1`, the flag is ignored because the extension has been promoted to Vulkan 1.1.
- Using this extenion will automatically allocate dedicated blocks of memory for
+ Using this extension will automatically allocate dedicated blocks of memory for
some buffers and images instead of suballocating place for them out of bigger
memory blocks (as if you explicitly used #VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT
flag) when it is recommended by the driver. It may improve performance on some
@@ -2273,7 +2289,7 @@ typedef enum VmaAllocatorCreateFlagBits {
VMA_ALLOCATOR_CREATE_EXT_MEMORY_BUDGET_BIT = 0x00000008,
/**
Enables usage of VK_AMD_device_coherent_memory extension.
-
+
You may set this flag only if you:
- found out that this device extension is supported and enabled it while creating Vulkan device passed as VmaAllocatorCreateInfo::device,
@@ -2283,7 +2299,7 @@ typedef enum VmaAllocatorCreateFlagBits {
The extension and accompanying device feature provide access to memory types with
`VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD` and `VK_MEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMD` flags.
They are useful mostly for writing breadcrumb markers - a common method for debugging GPU crash/hang/TDR.
-
+
When the extension is not enabled, such memory types are still enumerated, but their usage is illegal.
To protect from this error, if you don't create the allocator with this flag, it will refuse to allocate any memory or create a custom pool in such memory type,
returning `VK_ERROR_FEATURE_NOT_PRESENT`.
@@ -2298,15 +2314,32 @@ typedef enum VmaAllocatorCreateFlagBits {
1. (For Vulkan version < 1.2) Found as available and enabled device extension
VK_KHR_buffer_device_address.
This extension is promoted to core Vulkan 1.2.
- 2. Found as available and enabled device feature `VkPhysicalDeviceBufferDeviceAddressFeatures*::bufferDeviceAddress`.
+ 2. Found as available and enabled device feature `VkPhysicalDeviceBufferDeviceAddressFeatures::bufferDeviceAddress`.
- When this flag is set, you can create buffers with `VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT*` using VMA.
- The library automatically adds `VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT*` to
+ When this flag is set, you can create buffers with `VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT` using VMA.
+ The library automatically adds `VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT` to
allocated memory blocks wherever it might be needed.
For more information, see documentation chapter \ref enabling_buffer_device_address.
*/
VMA_ALLOCATOR_CREATE_BUFFER_DEVICE_ADDRESS_BIT = 0x00000020,
+ /**
+ Enables usage of VK_EXT_memory_priority extension in the library.
+
+ You may set this flag only if you found available and enabled this device extension,
+ along with `VkPhysicalDeviceMemoryPriorityFeaturesEXT::memoryPriority == VK_TRUE`,
+ while creating Vulkan device passed as VmaAllocatorCreateInfo::device.
+
+ When this flag is used, VmaAllocationCreateInfo::priority and VmaPoolCreateInfo::priority
+ are used to set priorities of allocated Vulkan memory. Without it, these variables are ignored.
+
+ A priority must be a floating-point value between 0 and 1, indicating the priority of the allocation relative to other memory allocations.
+ Larger values are higher priority. The granularity of the priorities is implementation-dependent.
+ It is automatically passed to every call to `vkAllocateMemory` done by the library using structure `VkMemoryPriorityAllocateInfoEXT`.
+ The value to be used for default priority is 0.5.
+ For more details, see the documentation of the VK_EXT_memory_priority extension.
+ */
+ VMA_ALLOCATOR_CREATE_EXT_MEMORY_PRIORITY_BIT = 0x00000040,
VMA_ALLOCATOR_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
} VmaAllocatorCreateFlagBits;
@@ -2355,7 +2388,7 @@ typedef enum VmaRecordFlagBits {
It may degrade performance though.
*/
VMA_RECORD_FLUSH_AFTER_CALL_BIT = 0x00000001,
-
+
VMA_RECORD_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
} VmaRecordFlagBits;
typedef VkFlags VmaRecordFlags;
@@ -2453,11 +2486,11 @@ typedef struct VmaAllocatorCreateInfo
*/
VkInstance VMA_NOT_NULL instance;
/** \brief Optional. The highest version of Vulkan that the application is designed to use.
-
+
It must be a value in the format as created by macro `VK_MAKE_VERSION` or a constant like: `VK_API_VERSION_1_1`, `VK_API_VERSION_1_0`.
The patch version number specified is ignored. Only the major and minor versions are considered.
It must be less or equal (preferably equal) to value as passed to `vkCreateInstance` as `VkApplicationInfo::apiVersion`.
- Only versions 1.0 and 1.1 are supported by the current implementation.
+ Only versions 1.0, 1.1, 1.2 are supported by the current implementation.
Leaving it initialized to zero is equivalent to `VK_API_VERSION_1_0`.
*/
uint32_t vulkanApiVersion;
@@ -2585,32 +2618,32 @@ typedef struct VmaBudget
/** \brief Sum size of all `VkDeviceMemory` blocks allocated from particular heap, in bytes.
*/
VkDeviceSize blockBytes;
-
+
/** \brief Sum size of all allocations created in particular heap, in bytes.
-
+
Usually less or equal than `blockBytes`.
Difference `blockBytes - allocationBytes` is the amount of memory allocated but unused -
available for new allocations or wasted due to fragmentation.
-
+
It might be greater than `blockBytes` if there are some allocations in lost state, as they account
to this value as well.
*/
VkDeviceSize allocationBytes;
-
+
/** \brief Estimated current memory usage of the program, in bytes.
-
+
Fetched from system using `VK_EXT_memory_budget` extension if enabled.
-
+
It might be different than `blockBytes` (usually higher) due to additional implicit objects
also occupying the memory, like swapchain, pipelines, descriptor heaps, command buffers, or
`VkDeviceMemory` blocks allocated outside of this library, if any.
*/
VkDeviceSize usage;
-
+
/** \brief Estimated amount of memory available to the program, in bytes.
-
+
Fetched from system using `VK_EXT_memory_budget` extension if enabled.
-
+
It might be different (most probably smaller) than `VkMemoryHeap::size[heapIndex]` due to factors
external to the program, like other programs also consuming system resources.
Difference `budget - usage` is the amount of additional memory that can probably
@@ -2675,7 +2708,7 @@ typedef enum VmaMemoryUsage
It is roughly equivalent of `D3D12_HEAP_TYPE_DEFAULT`.
Usage:
-
+
- Resources written and read by device, e.g. images used as attachments.
- Resources transferred from host once (immutable) or infrequently and read by
device multiple times, e.g. textures to be sampled, vertex buffers, uniform
@@ -2720,7 +2753,7 @@ typedef enum VmaMemoryUsage
VMA_MEMORY_USAGE_CPU_COPY = 5,
/** Lazily allocated GPU memory having `VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT`.
Exists mostly on mobile platforms. Using it on desktop PC or other GPUs with no such memory type present will fail the allocation.
-
+
Usage: Memory for transient attachment images (color attachments, depth attachments etc.), created with `VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT`.
Allocations with this usage are always created as dedicated - it implies #VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT.
@@ -2733,25 +2766,25 @@ typedef enum VmaMemoryUsage
/// Flags to be passed as VmaAllocationCreateInfo::flags.
typedef enum VmaAllocationCreateFlagBits {
/** \brief Set this flag if the allocation should have its own memory block.
-
+
Use it for special, big resources, like fullscreen images used as attachments.
-
+
You should not use this flag if VmaAllocationCreateInfo::pool is not null.
*/
VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT = 0x00000001,
/** \brief Set this flag to only try to allocate from existing `VkDeviceMemory` blocks and never create new such block.
-
+
If new allocation cannot be placed in any of the existing blocks, allocation
fails with `VK_ERROR_OUT_OF_DEVICE_MEMORY` error.
-
+
You should not use #VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT and
#VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT at the same time. It makes no sense.
-
+
If VmaAllocationCreateInfo::pool is not null, this flag is implied and ignored. */
VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT = 0x00000002,
/** \brief Set this flag to use a memory that will be persistently mapped and retrieve pointer to it.
-
+
Pointer to mapped memory will be returned through VmaAllocationInfo::pMappedData.
It is valid to use this flag for allocation made from memory type that is not
@@ -2847,19 +2880,19 @@ typedef struct VmaAllocationCreateInfo
/// Use #VmaAllocationCreateFlagBits enum.
VmaAllocationCreateFlags flags;
/** \brief Intended usage of memory.
-
+
You can leave #VMA_MEMORY_USAGE_UNKNOWN if you specify memory requirements in other way. \n
If `pool` is not null, this member is ignored.
*/
VmaMemoryUsage usage;
/** \brief Flags that must be set in a Memory Type chosen for an allocation.
-
+
Leave 0 if you specify memory requirements in other way. \n
If `pool` is not null, this member is ignored.*/
VkMemoryPropertyFlags requiredFlags;
/** \brief Flags that preferably should be set in a memory type chosen for an allocation.
-
- Set to 0 if no additional flags are prefered. \n
+
+ Set to 0 if no additional flags are preferred. \n
If `pool` is not null, this member is ignored. */
VkMemoryPropertyFlags preferredFlags;
/** \brief Bitmask containing one bit set for every memory type acceptable for this allocation.
@@ -2877,12 +2910,19 @@ typedef struct VmaAllocationCreateInfo
*/
VmaPool VMA_NULLABLE pool;
/** \brief Custom general-purpose pointer that will be stored in #VmaAllocation, can be read as VmaAllocationInfo::pUserData and changed using vmaSetAllocationUserData().
-
+
If #VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT is used, it must be either
null or pointer to a null-terminated string. The string will be then copied to
internal buffer, so it doesn't need to be valid after allocation call.
*/
void* VMA_NULLABLE pUserData;
+ /** \brief A floating-point value between 0 and 1, indicating the priority of the allocation relative to other memory allocations.
+
+ It is used only when #VMA_ALLOCATOR_CREATE_EXT_MEMORY_PRIORITY_BIT flag was used during creation of the #VmaAllocator object
+ and this allocation ends up as dedicated or is explicitly forced as dedicated using #VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT.
+ Otherwise, it has the priority of a memory block where it is placed and this variable is ignored.
+ */
+ float priority;
} VmaAllocationCreateInfo;
/**
@@ -3028,7 +3068,7 @@ typedef struct VmaPoolCreateInfo {
/** \brief Maximum number of blocks that can be allocated in this pool. Optional.
Set to 0 to use default, which is `SIZE_MAX`, which means no limit.
-
+
Set to same value as VmaPoolCreateInfo::minBlockCount to have fixed amount of memory allocated
throughout whole lifetime of this pool.
*/
@@ -3047,6 +3087,12 @@ typedef struct VmaPoolCreateInfo {
become lost, set this value to 0.
*/
uint32_t frameInUseCount;
+ /** \brief A floating-point value between 0 and 1, indicating the priority of the allocations in this pool relative to other memory allocations.
+
+ It is used only when #VMA_ALLOCATOR_CREATE_EXT_MEMORY_PRIORITY_BIT flag was used during creation of the #VmaAllocator object.
+ Otherwise, this variable is ignored.
+ */
+ float priority;
} VmaPoolCreateInfo;
/** \brief Describes parameter of existing #VmaPool.
@@ -3182,20 +3228,25 @@ VK_DEFINE_HANDLE(VmaAllocation)
*/
typedef struct VmaAllocationInfo {
/** \brief Memory type index that this allocation was allocated from.
-
+
It never changes.
*/
uint32_t memoryType;
/** \brief Handle to Vulkan memory object.
Same memory object can be shared by multiple allocations.
-
+
It can change after call to vmaDefragment() if this allocation is passed to the function, or if allocation is lost.
If the allocation is lost, it is equal to `VK_NULL_HANDLE`.
*/
VkDeviceMemory VMA_NULLABLE_NON_DISPATCHABLE deviceMemory;
- /** \brief Offset into deviceMemory object to the beginning of this allocation, in bytes. (deviceMemory, offset) pair is unique to this allocation.
+ /** \brief Offset in `VkDeviceMemory` object to the beginning of this allocation, in bytes. `(deviceMemory, offset)` pair is unique to this allocation.
+
+ You usually don't need to use this offset. If you create a buffer or an image together with the allocation using e.g. function
+ vmaCreateBuffer(), vmaCreateImage(), functions that operate on these resources refer to the beginning of the buffer or image,
+ not entire device memory block. Functions like vmaMapMemory(), vmaBindBufferMemory() also refer to the beginning of the allocation
+ and apply this offset automatically.
It can change after call to vmaDefragment() if this allocation is passed to the function, or if allocation is lost.
*/
@@ -3315,21 +3366,9 @@ VMA_CALL_PRE void VMA_CALL_POST vmaFreeMemoryPages(
size_t allocationCount,
const VmaAllocation VMA_NULLABLE * VMA_NOT_NULL VMA_LEN_IF_NOT_NULL(allocationCount) pAllocations);
-/** \brief Deprecated.
-
-\deprecated
-In version 2.2.0 it used to try to change allocation's size without moving or reallocating it.
-In current version it returns `VK_SUCCESS` only if `newSize` equals current allocation's size.
-Otherwise returns `VK_ERROR_OUT_OF_POOL_MEMORY`, indicating that allocation's size could not be changed.
-*/
-VMA_CALL_PRE VkResult VMA_CALL_POST vmaResizeAllocation(
- VmaAllocator VMA_NOT_NULL allocator,
- VmaAllocation VMA_NOT_NULL allocation,
- VkDeviceSize newSize);
-
/** \brief Returns current information about specified allocation and atomically marks it as used in current frame.
-Current paramters of given allocation are returned in `pAllocationInfo`.
+Current paramteres of given allocation are returned in `pAllocationInfo`.
This function also atomically "touches" allocation - marks it as used in current frame,
just like vmaTouchAllocation().
@@ -3403,7 +3442,7 @@ VMA_CALL_PRE void VMA_CALL_POST vmaCreateLostAllocation(
Maps memory represented by given allocation to make it accessible to CPU code.
When succeeded, `*ppData` contains pointer to first byte of this memory.
If the allocation is part of bigger `VkDeviceMemory` block, the pointer is
-correctly offseted to the beginning of region assigned to this particular
+correctly offsetted to the beginning of region assigned to this particular
allocation.
Mapping is internally reference-counted and synchronized, so despite raw Vulkan
@@ -3628,7 +3667,7 @@ typedef struct VmaDefragmentationInfo2 {
*/
const VmaPool VMA_NOT_NULL * VMA_NULLABLE VMA_LEN_IF_NOT_NULL(poolCount) pPools;
/** \brief Maximum total numbers of bytes that can be copied while moving allocations to different places using transfers on CPU side, like `memcpy()`, `memmove()`.
-
+
`VK_WHOLE_SIZE` means no limit.
*/
VkDeviceSize maxCpuBytesToMove;
@@ -3638,7 +3677,7 @@ typedef struct VmaDefragmentationInfo2 {
*/
uint32_t maxCpuAllocationsToMove;
/** \brief Maximum total numbers of bytes that can be copied while moving allocations to different places using transfers on GPU side, posted to `commandBuffer`.
-
+
`VK_WHOLE_SIZE` means no limit.
*/
VkDeviceSize maxGpuBytesToMove;
@@ -3679,7 +3718,7 @@ typedef struct VmaDefragmentationPassInfo {
*/
typedef struct VmaDefragmentationInfo {
/** \brief Maximum total numbers of bytes that can be copied while moving allocations to different places.
-
+
Default is `VK_WHOLE_SIZE`, which means no limit.
*/
VkDeviceSize maxBytesToMove;
@@ -3823,7 +3862,7 @@ VMA_CALL_PRE VkResult VMA_CALL_POST vmaBindBufferMemory(
/** \brief Binds buffer to allocation with additional parameters.
-@param allocationLocalOffset Additional offset to be added while binding, relative to the beginnig of the `allocation`. Normally it should be 0.
+@param allocationLocalOffset Additional offset to be added while binding, relative to the beginning of the `allocation`. Normally it should be 0.
@param pNext A chain of structures to be attached to `VkBindBufferMemoryInfoKHR` structure used internally. Normally it should be null.
This function is similar to vmaBindBufferMemory(), but it provides additional parameters.
@@ -3857,7 +3896,7 @@ VMA_CALL_PRE VkResult VMA_CALL_POST vmaBindImageMemory(
/** \brief Binds image to allocation with additional parameters.
-@param allocationLocalOffset Additional offset to be added while binding, relative to the beginnig of the `allocation`. Normally it should be 0.
+@param allocationLocalOffset Additional offset to be added while binding, relative to the beginning of the `allocation`. Normally it should be 0.
@param pNext A chain of structures to be attached to `VkBindImageMemoryInfoKHR` structure used internally. Normally it should be null.
This function is similar to vmaBindImageMemory(), but it provides additional parameters.
@@ -3890,13 +3929,17 @@ If the function succeeded, you must destroy both buffer and allocation when you
no longer need them using either convenience function vmaDestroyBuffer() or
separately, using `vkDestroyBuffer()` and vmaFreeMemory().
-If VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT flag was used,
+If #VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT flag was used,
VK_KHR_dedicated_allocation extension is used internally to query driver whether
it requires or prefers the new buffer to have dedicated allocation. If yes,
and if dedicated allocation is possible (VmaAllocationCreateInfo::pool is null
-and VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT is not used), it creates dedicated
+and #VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT is not used), it creates dedicated
allocation for this buffer, just like when using
-VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT.
+#VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT.
+
+\note This function creates a new `VkBuffer`. Sub-allocation of parts of one large buffer,
+although recommended as a good practice, is out of scope of this library and could be implemented
+by the user as a higher-level logic on top of VMA.
*/
VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreateBuffer(
VmaAllocator VMA_NOT_NULL allocator,
@@ -3966,6 +4009,16 @@ VMA_CALL_PRE void VMA_CALL_POST vmaDestroyImage(
#include
#include
+#if VMA_RECORDING_ENABLED
+ #include
+ #if defined(_WIN32)
+ #include
+ #else
+ #include
+ #include
+ #endif
+#endif
+
/*******************************************************************************
CONFIGURATION SECTION
@@ -4057,7 +4110,7 @@ remove them if not needed.
#if defined(__ANDROID_API__) && (__ANDROID_API__ < 16)
#include
-void *vma_aligned_alloc(size_t alignment, size_t size)
+static void* vma_aligned_alloc(size_t alignment, size_t size)
{
// alignment must be >= sizeof(void*)
if(alignment < sizeof(void*))
@@ -4074,12 +4127,12 @@ void *vma_aligned_alloc(size_t alignment, size_t size)
#include
#endif
-void *vma_aligned_alloc(size_t alignment, size_t size)
+static void* vma_aligned_alloc(size_t alignment, size_t size)
{
#if defined(__APPLE__) && (defined(MAC_OS_X_VERSION_10_16) || defined(__IPHONE_14_0))
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_16 || __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_14_0
// For C++14, usr/include/malloc/_malloc.h declares aligned_alloc()) only
- // with the MacOSX11.0 SDK in Xcode 12 (which is what adds
+ // with the MacOSX11.0 SDK in Xcode 12 (which is what adds
// MAC_OS_X_VERSION_10_16), even though the function is marked
// availabe for 10.15. That's why the preprocessor checks for 10.16 but
// the __builtin_available checks for 10.15.
@@ -4100,17 +4153,29 @@ void *vma_aligned_alloc(size_t alignment, size_t size)
return VMA_NULL;
}
#elif defined(_WIN32)
-void *vma_aligned_alloc(size_t alignment, size_t size)
+static void* vma_aligned_alloc(size_t alignment, size_t size)
{
return _aligned_malloc(size, alignment);
}
#else
-void *vma_aligned_alloc(size_t alignment, size_t size)
+static void* vma_aligned_alloc(size_t alignment, size_t size)
{
return aligned_alloc(alignment, size);
}
#endif
+#if defined(_WIN32)
+static void vma_aligned_free(void* ptr)
+{
+ _aligned_free(ptr);
+}
+#else
+static void vma_aligned_free(void* VMA_NULLABLE ptr)
+{
+ free(ptr);
+}
+#endif
+
// If your compiler is not compatible with C++11 and definition of
// aligned_alloc() function is missing, uncommeting following line may help:
@@ -4143,12 +4208,13 @@ void *vma_aligned_alloc(size_t alignment, size_t size)
#define VMA_SYSTEM_ALIGNED_MALLOC(size, alignment) vma_aligned_alloc((alignment), (size))
#endif
-#ifndef VMA_SYSTEM_FREE
- #if defined(_WIN32)
- #define VMA_SYSTEM_FREE(ptr) _aligned_free(ptr)
+#ifndef VMA_SYSTEM_ALIGNED_FREE
+ // VMA_SYSTEM_FREE is the old name, but might have been defined by the user
+ #if defined(VMA_SYSTEM_FREE)
+ #define VMA_SYSTEM_ALIGNED_FREE(ptr) VMA_SYSTEM_FREE(ptr)
#else
- #define VMA_SYSTEM_FREE(ptr) free(ptr)
- #endif
+ #define VMA_SYSTEM_ALIGNED_FREE(ptr) vma_aligned_free(ptr)
+ #endif
#endif
#ifndef VMA_MIN
@@ -4179,15 +4245,15 @@ void *vma_aligned_alloc(size_t alignment, size_t size)
// Define this macro to 1 to enable functions: vmaBuildStatsString, vmaFreeStatsString.
#if VMA_STATS_STRING_ENABLED
- static inline void VmaUint32ToStr(char* outStr, size_t strLen, uint32_t num)
+ static inline void VmaUint32ToStr(char* VMA_NOT_NULL outStr, size_t strLen, uint32_t num)
{
snprintf(outStr, strLen, "%u", static_cast(num));
}
- static inline void VmaUint64ToStr(char* outStr, size_t strLen, uint64_t num)
+ static inline void VmaUint64ToStr(char* VMA_NOT_NULL outStr, size_t strLen, uint64_t num)
{
snprintf(outStr, strLen, "%llu", static_cast(num));
}
- static inline void VmaPtrToStr(char* outStr, size_t strLen, const void* ptr)
+ static inline void VmaPtrToStr(char* VMA_NOT_NULL outStr, size_t strLen, const void* ptr)
{
snprintf(outStr, strLen, "%p", ptr);
}
@@ -4280,12 +4346,16 @@ If providing your own implementation, you need to implement a subset of std::ato
#define VMA_DEBUG_ALWAYS_DEDICATED_MEMORY (0)
#endif
-#ifndef VMA_DEBUG_ALIGNMENT
+#ifndef VMA_MIN_ALIGNMENT
/**
Minimum alignment of all allocations, in bytes.
- Set to more than 1 for debugging purposes only. Must be power of two.
+ Set to more than 1 for debugging purposes. Must be power of two.
*/
- #define VMA_DEBUG_ALIGNMENT (1)
+ #ifdef VMA_DEBUG_ALIGNMENT // Old name
+ #define VMA_MIN_ALIGNMENT VMA_DEBUG_ALIGNMENT
+ #else
+ #define VMA_MIN_ALIGNMENT (1)
+ #endif
#endif
#ifndef VMA_DEBUG_MARGIN
@@ -4329,6 +4399,14 @@ If providing your own implementation, you need to implement a subset of std::ato
#define VMA_DEBUG_MIN_BUFFER_IMAGE_GRANULARITY (1)
#endif
+#ifndef VMA_DEBUG_DONT_EXCEED_MAX_MEMORY_ALLOCATION_COUNT
+ /*
+ Set this to 1 to make VMA never exceed VkPhysicalDeviceLimits::maxMemoryAllocationCount
+ and return error instead of leaving up to Vulkan implementation what to do in such cases.
+ */
+ #define VMA_DEBUG_DONT_EXCEED_MAX_MEMORY_ALLOCATION_COUNT (0)
+#endif
+
#ifndef VMA_SMALL_HEAP_MAX_SIZE
/// Maximum size of a memory heap in Vulkan to consider it "small".
#define VMA_SMALL_HEAP_MAX_SIZE (1024ull * 1024 * 1024)
@@ -4574,7 +4652,7 @@ static inline bool VmaIsBufferImageGranularityConflict(
{
VMA_SWAP(suballocType1, suballocType2);
}
-
+
switch(suballocType1)
{
case VMA_SUBALLOCATION_TYPE_FREE:
@@ -4708,7 +4786,7 @@ static IterT VmaBinaryFindFirstNotLess(IterT beg, IterT end, const KeyT &key, co
size_t down = 0, up = (end - beg);
while(down < up)
{
- const size_t mid = (down + up) / 2;
+ const size_t mid = down + (up - down) / 2; // Overflow-safe midpoint calculation
if(cmp(*(beg+mid), key))
{
down = mid + 1;
@@ -4799,7 +4877,7 @@ static void VmaFree(const VkAllocationCallbacks* pAllocationCallbacks, void* ptr
}
else
{
- VMA_SYSTEM_FREE(ptr);
+ VMA_SYSTEM_ALIGNED_FREE(ptr);
}
}
@@ -4870,7 +4948,7 @@ class VmaStlAllocator
public:
const VkAllocationCallbacks* const m_pCallbacks;
typedef T value_type;
-
+
VmaStlAllocator(const VkAllocationCallbacks* pCallbacks) : m_pCallbacks(pCallbacks) { }
template VmaStlAllocator(const VmaStlAllocator& src) : m_pCallbacks(src.m_pCallbacks) { }
@@ -4889,6 +4967,7 @@ public:
}
VmaStlAllocator& operator=(const VmaStlAllocator& x) = delete;
+ VmaStlAllocator(const VmaStlAllocator&) = default;
};
#if VMA_USE_STL_VECTOR
@@ -4933,12 +5012,12 @@ public:
m_Capacity(count)
{
}
-
+
// This version of the constructor is here for compatibility with pre-C++14 std::vector.
// value is unused.
VmaVector(size_t count, const T& value, const AllocatorT& allocator)
: VmaVector(count, allocator) {}
-
+
VmaVector(const VmaVector& src) :
m_Allocator(src.m_Allocator),
m_pArray(src.m_Count ? (T*)VmaAllocateArray(src.m_Allocator.m_pCallbacks, src.m_Count) : VMA_NULL),
@@ -4950,7 +5029,7 @@ public:
memcpy(m_pArray, src.m_pArray, m_Count * sizeof(T));
}
}
-
+
~VmaVector()
{
VmaFree(m_Allocator.m_pCallbacks, m_pArray);
@@ -4968,12 +5047,12 @@ public:
}
return *this;
}
-
+
bool empty() const { return m_Count == 0; }
size_t size() const { return m_Count; }
T* data() { return m_pArray; }
const T* data() const { return m_pArray; }
-
+
T& operator[](size_t index)
{
VMA_HEAVY_ASSERT(index < m_Count);
@@ -5009,12 +5088,12 @@ public:
void reserve(size_t newCapacity, bool freeMemory = false)
{
newCapacity = VMA_MAX(newCapacity, m_Count);
-
+
if((newCapacity < m_Capacity) && !freeMemory)
{
newCapacity = m_Capacity;
}
-
+
if(newCapacity != m_Capacity)
{
T* const newArray = newCapacity ? VmaAllocateArray(m_Allocator, newCapacity) : VMA_NULL;
@@ -5028,17 +5107,13 @@ public:
}
}
- void resize(size_t newCount, bool freeMemory = false)
+ void resize(size_t newCount)
{
size_t newCapacity = m_Capacity;
if(newCount > m_Capacity)
{
newCapacity = VMA_MAX(newCount, VMA_MAX(m_Capacity * 3 / 2, (size_t)8));
}
- else if(freeMemory)
- {
- newCapacity = newCount;
- }
if(newCapacity != m_Capacity)
{
@@ -5056,9 +5131,25 @@ public:
m_Count = newCount;
}
- void clear(bool freeMemory = false)
+ void clear()
{
- resize(0, freeMemory);
+ resize(0);
+ }
+
+ void shrink_to_fit()
+ {
+ if(m_Capacity > m_Count)
+ {
+ T* newArray = VMA_NULL;
+ if(m_Count > 0)
+ {
+ newArray = VmaAllocateArray(m_Allocator.m_pCallbacks, m_Count);
+ memcpy(newArray, m_pArray, m_Count * sizeof(T));
+ }
+ VmaFree(m_Allocator.m_pCallbacks, m_pArray);
+ m_Capacity = m_Count;
+ m_pArray = newArray;
+ }
}
void insert(size_t index, const T& src)
@@ -5238,12 +5329,16 @@ public:
if(newCount > N && m_Count > N)
{
// Any direction, staying in m_DynamicArray
- m_DynamicArray.resize(newCount, freeMemory);
+ m_DynamicArray.resize(newCount);
+ if(freeMemory)
+ {
+ m_DynamicArray.shrink_to_fit();
+ }
}
else if(newCount > N && m_Count <= N)
{
// Growing, moving from m_StaticArray to m_DynamicArray
- m_DynamicArray.resize(newCount, freeMemory);
+ m_DynamicArray.resize(newCount);
if(m_Count > 0)
{
memcpy(m_DynamicArray.data(), m_StaticArray, m_Count * sizeof(T));
@@ -5256,7 +5351,11 @@ public:
{
memcpy(m_StaticArray, m_DynamicArray.data(), newCount * sizeof(T));
}
- m_DynamicArray.resize(0, freeMemory);
+ m_DynamicArray.resize(0);
+ if(freeMemory)
+ {
+ m_DynamicArray.shrink_to_fit();
+ }
}
else
{
@@ -5267,7 +5366,11 @@ public:
void clear(bool freeMemory = false)
{
- m_DynamicArray.clear(freeMemory);
+ m_DynamicArray.clear();
+ if(freeMemory)
+ {
+ m_DynamicArray.shrink_to_fit();
+ }
m_Count = 0;
}
@@ -5364,7 +5467,7 @@ private:
uint32_t Capacity;
uint32_t FirstFreeIndex;
};
-
+
const VkAllocationCallbacks* m_pAllocationCallbacks;
const uint32_t m_FirstBlockCapacity;
VmaVector< ItemBlock, VmaStlAllocator > m_ItemBlocks;
@@ -5422,11 +5525,11 @@ void VmaPoolAllocator::Free(T* ptr)
for(size_t i = m_ItemBlocks.size(); i--; )
{
ItemBlock& block = m_ItemBlocks[i];
-
+
// Casting to union.
Item* pItemPtr;
memcpy(&pItemPtr, &ptr, sizeof(pItemPtr));
-
+
// Check if pItemPtr is in address range of this block.
if((pItemPtr >= block.pItems) && (pItemPtr < block.pItems + block.Capacity))
{
@@ -5503,7 +5606,7 @@ public:
ItemType* PushFront(const T& value);
void PopBack();
void PopFront();
-
+
// Item can be null - it means PushBack.
ItemType* InsertBefore(ItemType* pItem);
// Item can be null - it means PushFront.
@@ -5813,7 +5916,7 @@ public:
VMA_HEAVY_ASSERT(m_pList == rhs.m_pList);
return m_pItem != rhs.m_pItem;
}
-
+
private:
VmaRawList* m_pList;
VmaListItem* m_pItem;
@@ -5841,7 +5944,7 @@ public:
m_pItem(src.m_pItem)
{
}
-
+
const T& operator*() const
{
VMA_HEAVY_ASSERT(m_pItem != VMA_NULL);
@@ -5896,7 +5999,7 @@ public:
VMA_HEAVY_ASSERT(m_pList == rhs.m_pList);
return m_pItem != rhs.m_pItem;
}
-
+
private:
const_iterator(const VmaRawList* pList, const VmaListItem* pItem) :
m_pList(pList),
@@ -5932,6 +6035,222 @@ private:
#endif // #if VMA_USE_STL_LIST
+////////////////////////////////////////////////////////////////////////////////
+// class VmaIntrusiveLinkedList
+
+/*
+Expected interface of ItemTypeTraits:
+struct MyItemTypeTraits
+{
+ typedef MyItem ItemType;
+ static ItemType* GetPrev(const ItemType* item) { return item->myPrevPtr; }
+ static ItemType* GetNext(const ItemType* item) { return item->myNextPtr; }
+ static ItemType*& AccessPrev(ItemType* item) { return item->myPrevPtr; }
+ static ItemType*& AccessNext(ItemType* item) { return item->myNextPtr; }
+};
+*/
+template
+class VmaIntrusiveLinkedList
+{
+public:
+ typedef typename ItemTypeTraits::ItemType ItemType;
+ static ItemType* GetPrev(const ItemType* item) { return ItemTypeTraits::GetPrev(item); }
+ static ItemType* GetNext(const ItemType* item) { return ItemTypeTraits::GetNext(item); }
+ // Movable, not copyable.
+ VmaIntrusiveLinkedList() { }
+ VmaIntrusiveLinkedList(const VmaIntrusiveLinkedList& src) = delete;
+ VmaIntrusiveLinkedList(VmaIntrusiveLinkedList&& src) :
+ m_Front(src.m_Front), m_Back(src.m_Back), m_Count(src.m_Count)
+ {
+ src.m_Front = src.m_Back = VMA_NULL;
+ src.m_Count = 0;
+ }
+ ~VmaIntrusiveLinkedList()
+ {
+ VMA_HEAVY_ASSERT(IsEmpty());
+ }
+ VmaIntrusiveLinkedList& operator=(const VmaIntrusiveLinkedList& src) = delete;
+ VmaIntrusiveLinkedList& operator=(VmaIntrusiveLinkedList&& src)
+ {
+ if(&src != this)
+ {
+ VMA_HEAVY_ASSERT(IsEmpty());
+ m_Front = src.m_Front;
+ m_Back = src.m_Back;
+ m_Count = src.m_Count;
+ src.m_Front = src.m_Back = VMA_NULL;
+ src.m_Count = 0;
+ }
+ return *this;
+ }
+ void RemoveAll()
+ {
+ if(!IsEmpty())
+ {
+ ItemType* item = m_Back;
+ while(item != VMA_NULL)
+ {
+ ItemType* const prevItem = ItemTypeTraits::AccessPrev(item);
+ ItemTypeTraits::AccessPrev(item) = VMA_NULL;
+ ItemTypeTraits::AccessNext(item) = VMA_NULL;
+ item = prevItem;
+ }
+ m_Front = VMA_NULL;
+ m_Back = VMA_NULL;
+ m_Count = 0;
+ }
+ }
+ size_t GetCount() const { return m_Count; }
+ bool IsEmpty() const { return m_Count == 0; }
+ ItemType* Front() { return m_Front; }
+ const ItemType* Front() const { return m_Front; }
+ ItemType* Back() { return m_Back; }
+ const ItemType* Back() const { return m_Back; }
+ void PushBack(ItemType* item)
+ {
+ VMA_HEAVY_ASSERT(ItemTypeTraits::GetPrev(item) == VMA_NULL && ItemTypeTraits::GetNext(item) == VMA_NULL);
+ if(IsEmpty())
+ {
+ m_Front = item;
+ m_Back = item;
+ m_Count = 1;
+ }
+ else
+ {
+ ItemTypeTraits::AccessPrev(item) = m_Back;
+ ItemTypeTraits::AccessNext(m_Back) = item;
+ m_Back = item;
+ ++m_Count;
+ }
+ }
+ void PushFront(ItemType* item)
+ {
+ VMA_HEAVY_ASSERT(ItemTypeTraits::GetPrev(item) == VMA_NULL && ItemTypeTraits::GetNext(item) == VMA_NULL);
+ if(IsEmpty())
+ {
+ m_Front = item;
+ m_Back = item;
+ m_Count = 1;
+ }
+ else
+ {
+ ItemTypeTraits::AccessNext(item) = m_Front;
+ ItemTypeTraits::AccessPrev(m_Front) = item;
+ m_Front = item;
+ ++m_Count;
+ }
+ }
+ ItemType* PopBack()
+ {
+ VMA_HEAVY_ASSERT(m_Count > 0);
+ ItemType* const backItem = m_Back;
+ ItemType* const prevItem = ItemTypeTraits::GetPrev(backItem);
+ if(prevItem != VMA_NULL)
+ {
+ ItemTypeTraits::AccessNext(prevItem) = VMA_NULL;
+ }
+ m_Back = prevItem;
+ --m_Count;
+ ItemTypeTraits::AccessPrev(backItem) = VMA_NULL;
+ ItemTypeTraits::AccessNext(backItem) = VMA_NULL;
+ return backItem;
+ }
+ ItemType* PopFront()
+ {
+ VMA_HEAVY_ASSERT(m_Count > 0);
+ ItemType* const frontItem = m_Front;
+ ItemType* const nextItem = ItemTypeTraits::GetNext(frontItem);
+ if(nextItem != VMA_NULL)
+ {
+ ItemTypeTraits::AccessPrev(nextItem) = VMA_NULL;
+ }
+ m_Front = nextItem;
+ --m_Count;
+ ItemTypeTraits::AccessPrev(frontItem) = VMA_NULL;
+ ItemTypeTraits::AccessNext(frontItem) = VMA_NULL;
+ return frontItem;
+ }
+
+ // MyItem can be null - it means PushBack.
+ void InsertBefore(ItemType* existingItem, ItemType* newItem)
+ {
+ VMA_HEAVY_ASSERT(newItem != VMA_NULL && ItemTypeTraits::GetPrev(newItem) == VMA_NULL && ItemTypeTraits::GetNext(newItem) == VMA_NULL);
+ if(existingItem != VMA_NULL)
+ {
+ ItemType* const prevItem = ItemTypeTraits::GetPrev(existingItem);
+ ItemTypeTraits::AccessPrev(newItem) = prevItem;
+ ItemTypeTraits::AccessNext(newItem) = existingItem;
+ ItemTypeTraits::AccessPrev(existingItem) = newItem;
+ if(prevItem != VMA_NULL)
+ {
+ ItemTypeTraits::AccessNext(prevItem) = newItem;
+ }
+ else
+ {
+ VMA_HEAVY_ASSERT(m_Front == existingItem);
+ m_Front = newItem;
+ }
+ ++m_Count;
+ }
+ else
+ PushBack(newItem);
+ }
+ // MyItem can be null - it means PushFront.
+ void InsertAfter(ItemType* existingItem, ItemType* newItem)
+ {
+ VMA_HEAVY_ASSERT(newItem != VMA_NULL && ItemTypeTraits::GetPrev(newItem) == VMA_NULL && ItemTypeTraits::GetNext(newItem) == VMA_NULL);
+ if(existingItem != VMA_NULL)
+ {
+ ItemType* const nextItem = ItemTypeTraits::GetNext(existingItem);
+ ItemTypeTraits::AccessNext(newItem) = nextItem;
+ ItemTypeTraits::AccessPrev(newItem) = existingItem;
+ ItemTypeTraits::AccessNext(existingItem) = newItem;
+ if(nextItem != VMA_NULL)
+ {
+ ItemTypeTraits::AccessPrev(nextItem) = newItem;
+ }
+ else
+ {
+ VMA_HEAVY_ASSERT(m_Back == existingItem);
+ m_Back = newItem;
+ }
+ ++m_Count;
+ }
+ else
+ return PushFront(newItem);
+ }
+ void Remove(ItemType* item)
+ {
+ VMA_HEAVY_ASSERT(item != VMA_NULL && m_Count > 0);
+ if(ItemTypeTraits::GetPrev(item) != VMA_NULL)
+ {
+ ItemTypeTraits::AccessNext(ItemTypeTraits::AccessPrev(item)) = ItemTypeTraits::GetNext(item);
+ }
+ else
+ {
+ VMA_HEAVY_ASSERT(m_Front == item);
+ m_Front = ItemTypeTraits::GetNext(item);
+ }
+
+ if(ItemTypeTraits::GetNext(item) != VMA_NULL)
+ {
+ ItemTypeTraits::AccessPrev(ItemTypeTraits::AccessNext(item)) = ItemTypeTraits::GetPrev(item);
+ }
+ else
+ {
+ VMA_HEAVY_ASSERT(m_Back == item);
+ m_Back = ItemTypeTraits::GetPrev(item);
+ }
+ ItemTypeTraits::AccessPrev(item) = VMA_NULL;
+ ItemTypeTraits::AccessNext(item) = VMA_NULL;
+ --m_Count;
+ }
+private:
+ ItemType* m_Front = VMA_NULL;
+ ItemType* m_Back = VMA_NULL;
+ size_t m_Count = 0;
+};
+
////////////////////////////////////////////////////////////////////////////////
// class VmaMap
@@ -5975,7 +6294,7 @@ public:
void insert(const PairType& pair);
iterator find(const KeyT& key);
void erase(iterator it);
-
+
private:
VmaVector< PairType, VmaStlAllocator > m_Vector;
};
@@ -6124,7 +6443,7 @@ public:
void ChangeBlockAllocation(
VmaAllocator hAllocator,
VmaDeviceMemoryBlock* block,
- VkDeviceSize offset);
+ VkDeviceSize offset);
void ChangeOffset(VkDeviceSize newOffset);
@@ -6146,6 +6465,8 @@ public:
m_MapCount = (pMappedData != VMA_NULL) ? MAP_COUNT_FLAG_PERSISTENT_MAP : 0;
m_DedicatedAllocation.m_hMemory = hMemory;
m_DedicatedAllocation.m_pMappedData = pMappedData;
+ m_DedicatedAllocation.m_Prev = VMA_NULL;
+ m_DedicatedAllocation.m_Next = VMA_NULL;
}
ALLOCATION_TYPE GetType() const { return (ALLOCATION_TYPE)m_Type; }
@@ -6167,7 +6488,7 @@ public:
bool IsPersistentMap() const { return (m_MapCount & MAP_COUNT_FLAG_PERSISTENT_MAP) != 0; }
void* GetMappedData() const;
bool CanBecomeLost() const;
-
+
uint32_t GetLastUseFrameIndex() const
{
return m_LastUseFrameIndex.load();
@@ -6180,7 +6501,7 @@ public:
- If hAllocation.LastUseFrameIndex + frameInUseCount < allocator.CurrentFrameIndex,
makes it lost by setting LastUseFrameIndex = VMA_FRAME_INDEX_LOST and returns true.
- Else, returns false.
-
+
If hAllocation is already lost, assert - you should not call it then.
If hAllocation was not created with CAN_BECOME_LOST_BIT, assert.
*/
@@ -6243,6 +6564,8 @@ private:
{
VkDeviceMemory m_hMemory;
void* m_pMappedData; // Not null means memory is mapped.
+ VmaAllocation_T* m_Prev;
+ VmaAllocation_T* m_Next;
};
union
@@ -6259,6 +6582,32 @@ private:
#endif
void FreeUserDataString(VmaAllocator hAllocator);
+
+ friend struct VmaDedicatedAllocationListItemTraits;
+};
+
+struct VmaDedicatedAllocationListItemTraits
+{
+ typedef VmaAllocation_T ItemType;
+ static ItemType* GetPrev(const ItemType* item)
+ {
+ VMA_HEAVY_ASSERT(item->GetType() == VmaAllocation_T::ALLOCATION_TYPE_DEDICATED);
+ return item->m_DedicatedAllocation.m_Prev;
+ }
+ static ItemType* GetNext(const ItemType* item)
+ {
+ VMA_HEAVY_ASSERT(item->GetType() == VmaAllocation_T::ALLOCATION_TYPE_DEDICATED);
+ return item->m_DedicatedAllocation.m_Next;
+ }
+ static ItemType*& AccessPrev(ItemType* item)
+ {
+ VMA_HEAVY_ASSERT(item->GetType() == VmaAllocation_T::ALLOCATION_TYPE_DEDICATED);
+ return item->m_DedicatedAllocation.m_Prev;
+ }
+ static ItemType*& AccessNext(ItemType* item){
+ VMA_HEAVY_ASSERT(item->GetType() == VmaAllocation_T::ALLOCATION_TYPE_DEDICATED);
+ return item->m_DedicatedAllocation.m_Next;
+ }
};
/*
@@ -6476,7 +6825,7 @@ public:
////////////////////////////////////////////////////////////////////////////////
// For defragmentation
-
+
bool IsBufferImageGranularityConflictPossible(
VkDeviceSize bufferImageGranularity,
VmaSuballocationType& inOutPrevSuballocType) const;
@@ -6687,7 +7036,7 @@ private:
SuballocationVectorType& AccessSuballocations2nd() { return m_1stVectorIndex ? m_Suballocations0 : m_Suballocations1; }
const SuballocationVectorType& AccessSuballocations1st() const { return m_1stVectorIndex ? m_Suballocations1 : m_Suballocations0; }
const SuballocationVectorType& AccessSuballocations2nd() const { return m_1stVectorIndex ? m_Suballocations0 : m_Suballocations1; }
-
+
// Number of items in 1st vector with hAllocation = null at the beginning.
size_t m_1stNullItemsBeginCount;
// Number of other items in 1st vector with hAllocation = null somewhere in the middle.
@@ -6725,7 +7074,7 @@ private:
- m_UsableSize is this size aligned down to a power of two.
All allocations and calculations happen relative to m_UsableSize.
- GetUnusableSize() is the difference between them.
- It is repoted as separate, unused range, not available for allocations.
+ It is reported as separate, unused range, not available for allocations.
Node at level 0 has size = m_UsableSize.
Each next level contains nodes with size 2 times smaller than current level.
@@ -6898,7 +7247,7 @@ public:
uint32_t algorithm);
// Always call before destruction.
void Destroy(VmaAllocator allocator);
-
+
VmaPool GetParentPool() const { return m_hParentPool; }
VkDeviceMemory GetDeviceMemory() const { return m_hMemory; }
uint32_t GetMemoryTypeIndex() const { return m_MemoryTypeIndex; }
@@ -6946,14 +7295,6 @@ private:
void* m_pMappedData;
};
-struct VmaPointerLess
-{
- bool operator()(const void* lhs, const void* rhs) const
- {
- return lhs < rhs;
- }
-};
-
struct VmaDefragmentationMove
{
size_t srcBlockIndex;
@@ -6988,7 +7329,8 @@ public:
VkDeviceSize bufferImageGranularity,
uint32_t frameInUseCount,
bool explicitBlockSize,
- uint32_t algorithm);
+ uint32_t algorithm,
+ float priority);
~VmaBlockVector();
VkResult CreateMinBlocks();
@@ -7071,6 +7413,7 @@ private:
const uint32_t m_FrameInUseCount;
const bool m_ExplicitBlockSize;
const uint32_t m_Algorithm;
+ const float m_Priority;
VMA_RW_MUTEX m_Mutex;
/* There can be at most one allocation that is completely empty (except when minBlockCount > 0) -
@@ -7155,6 +7498,18 @@ public:
private:
uint32_t m_Id;
char* m_Name;
+ VmaPool_T* m_PrevPool = VMA_NULL;
+ VmaPool_T* m_NextPool = VMA_NULL;
+ friend struct VmaPoolListItemTraits;
+};
+
+struct VmaPoolListItemTraits
+{
+ typedef VmaPool_T ItemType;
+ static ItemType* GetPrev(const ItemType* item) { return item->m_PrevPool; }
+ static ItemType* GetNext(const ItemType* item) { return item->m_NextPool; }
+ static ItemType*& AccessPrev(ItemType* item) { return item->m_PrevPool; }
+ static ItemType*& AccessNext(ItemType* item) { return item->m_NextPool; }
};
/*
@@ -7443,7 +7798,7 @@ private:
}
}
}
-
+
if(bestIndex != SIZE_MAX)
{
outBlockInfoIndex = m_FreeSpaces[bestIndex].blockInfoIndex;
@@ -7574,7 +7929,7 @@ public:
Returns:
- `VK_SUCCESS` if succeeded and object can be destroyed immediately.
- `VK_NOT_READY` if succeeded but the object must remain alive until vmaDefragmentationEnd().
- - Negative value if error occured and object can be destroyed immediately.
+ - Negative value if error occurred and object can be destroyed immediately.
*/
VkResult Defragment(
VkDeviceSize maxCpuBytesToMove, uint32_t maxCpuAllocationsToMove,
@@ -7814,13 +8169,14 @@ public:
bool m_UseExtMemoryBudget;
bool m_UseAmdDeviceCoherentMemory;
bool m_UseKhrBufferDeviceAddress;
+ bool m_UseExtMemoryPriority;
VkDevice m_hDevice;
VkInstance m_hInstance;
bool m_AllocationCallbacksSpecified;
VkAllocationCallbacks m_AllocationCallbacks;
VmaDeviceMemoryCallbacks m_DeviceMemoryCallbacks;
VmaAllocationObjectAllocator m_AllocationObjectAllocator;
-
+
// Each bit (1 << i) is set if HeapSizeLimit is enabled for that heap, so cannot allocate more than the heap size.
uint32_t m_HeapSizeLimitMask;
@@ -7830,12 +8186,12 @@ public:
// Default pools.
VmaBlockVector* m_pBlockVectors[VK_MAX_MEMORY_TYPES];
- // Each vector is sorted by memory (handle value).
- typedef VmaVector< VmaAllocation, VmaStlAllocator > AllocationVectorType;
- AllocationVectorType* m_pDedicatedAllocations[VK_MAX_MEMORY_TYPES];
+ typedef VmaIntrusiveLinkedList DedicatedAllocationLinkedList;
+ DedicatedAllocationLinkedList m_DedicatedAllocations[VK_MAX_MEMORY_TYPES];
VMA_RW_MUTEX m_DedicatedAllocationsMutex[VK_MAX_MEMORY_TYPES];
VmaCurrentBudgetData m_Budget;
+ VMA_ATOMIC_UINT32 m_DeviceMemoryCount; // Total number of VkDeviceMemory objects.
VmaAllocator_T(const VmaAllocatorCreateInfo* pCreateInfo);
VkResult Init(const VmaAllocatorCreateInfo* pCreateInfo);
@@ -7877,8 +8233,8 @@ public:
VkDeviceSize GetMemoryTypeMinAlignment(uint32_t memTypeIndex) const
{
return IsMemoryTypeNonCoherent(memTypeIndex) ?
- VMA_MAX((VkDeviceSize)VMA_DEBUG_ALIGNMENT, m_PhysicalDeviceProperties.limits.nonCoherentAtomSize) :
- (VkDeviceSize)VMA_DEBUG_ALIGNMENT;
+ VMA_MAX((VkDeviceSize)VMA_MIN_ALIGNMENT, m_PhysicalDeviceProperties.limits.nonCoherentAtomSize) :
+ (VkDeviceSize)VMA_MIN_ALIGNMENT;
}
bool IsIntegratedGpu() const
@@ -7921,10 +8277,6 @@ public:
size_t allocationCount,
const VmaAllocation* pAllocations);
- VkResult ResizeAllocation(
- const VmaAllocation alloc,
- VkDeviceSize newSize);
-
void CalculateStats(VmaStats* pStats);
void GetBudget(
@@ -8020,10 +8372,11 @@ private:
VkPhysicalDevice m_PhysicalDevice;
VMA_ATOMIC_UINT32 m_CurrentFrameIndex;
VMA_ATOMIC_UINT32 m_GpuDefragmentationMemoryTypeBits; // UINT32_MAX means uninitialized.
-
+
VMA_RW_MUTEX m_PoolsMutex;
- // Protected by m_PoolsMutex. Sorted by pointer value.
- VmaVector > m_Pools;
+ typedef VmaIntrusiveLinkedList PoolList;
+ // Protected by m_PoolsMutex.
+ PoolList m_Pools;
uint32_t m_NextPoolId;
VmaVulkanFunctions m_VulkanFunctions;
@@ -8084,6 +8437,7 @@ private:
bool map,
bool isUserDataString,
void* pUserData,
+ float priority,
VkBuffer dedicatedBuffer,
VkBufferUsageFlags dedicatedBufferUsage,
VkImage dedicatedImage,
@@ -8241,10 +8595,10 @@ public:
void BeginObject(bool singleLine = false);
void EndObject();
-
+
void BeginArray(bool singleLine = false);
void EndArray();
-
+
void WriteString(const char* pStr);
void BeginString(const char* pStr = VMA_NULL);
void ContinueString(const char* pStr);
@@ -8252,7 +8606,7 @@ public:
void ContinueString(uint64_t n);
void ContinueString_Pointer(const void* ptr);
void EndString(const char* pStr = VMA_NULL);
-
+
void WriteNumber(uint32_t n);
void WriteNumber(uint64_t n);
void WriteBool(bool b);
@@ -8500,7 +8854,7 @@ void VmaJsonWriter::WriteIndent(bool oneLess)
if(!m_Stack.empty() && !m_Stack.back().singleLineMode)
{
m_SB.AddNewLine();
-
+
size_t count = m_Stack.size();
if(count > 0 && oneLess)
{
@@ -8914,7 +9268,7 @@ void VmaBlockMetadata::PrintDetailedMap_Allocation(class VmaJsonWriter& json,
VmaAllocation hAllocation) const
{
json.BeginObject(true);
-
+
json.WriteString("Offset");
json.WriteNumber(offset);
@@ -8928,7 +9282,7 @@ void VmaBlockMetadata::PrintDetailedMap_UnusedRange(class VmaJsonWriter& json,
VkDeviceSize size) const
{
json.BeginObject(true);
-
+
json.WriteString("Offset");
json.WriteNumber(offset);
@@ -8988,7 +9342,7 @@ void VmaBlockMetadata_Generic::Init(VkDeviceSize size)
bool VmaBlockMetadata_Generic::Validate() const
{
VMA_VALIDATE(!m_Suballocations.empty());
-
+
// Expected offset of new suballocation as calculated from previous ones.
VkDeviceSize calculatedOffset = 0;
// Expected number of free suballocations as calculated from traversing their list.
@@ -9006,7 +9360,7 @@ bool VmaBlockMetadata_Generic::Validate() const
++suballocItem)
{
const VmaSuballocation& subAlloc = *suballocItem;
-
+
// Actual offset of this suballocation doesn't match expected one.
VMA_VALIDATE(subAlloc.offset == calculatedOffset);
@@ -9049,7 +9403,7 @@ bool VmaBlockMetadata_Generic::Validate() const
for(size_t i = 0; i < m_FreeSuballocationsBySize.size(); ++i)
{
VmaSuballocationList::iterator suballocItem = m_FreeSuballocationsBySize[i];
-
+
// Only free suballocations can be registered in m_FreeSuballocationsBySize.
VMA_VALIDATE(suballocItem->type == VMA_SUBALLOCATION_TYPE_FREE);
// They must be sorted by size ascending.
@@ -9058,7 +9412,7 @@ bool VmaBlockMetadata_Generic::Validate() const
lastSize = suballocItem->size;
}
- // Check if totals match calculacted values.
+ // Check if totals match calculated values.
VMA_VALIDATE(ValidateFreeSuballocationList());
VMA_VALIDATE(calculatedOffset == GetSize());
VMA_VALIDATE(calculatedSumFreeSize == m_SumFreeSize);
@@ -9091,7 +9445,7 @@ void VmaBlockMetadata_Generic::CalcAllocationStatInfo(VmaStatInfo& outInfo) cons
const uint32_t rangeCount = (uint32_t)m_Suballocations.size();
outInfo.allocationCount = rangeCount - m_FreeCount;
outInfo.unusedRangeCount = m_FreeCount;
-
+
outInfo.unusedBytes = m_SumFreeSize;
outInfo.usedBytes = GetSize() - outInfo.unusedBytes;
@@ -9350,7 +9704,7 @@ bool VmaBlockMetadata_Generic::MakeRequestedAllocationsLost(
VMA_HEAVY_ASSERT(Validate());
VMA_ASSERT(pAllocationRequest->item != m_Suballocations.end());
VMA_ASSERT(pAllocationRequest->item->type == VMA_SUBALLOCATION_TYPE_FREE);
-
+
return true;
}
@@ -9527,7 +9881,7 @@ bool VmaBlockMetadata_Generic::CheckAllocation(
VMA_ASSERT(allocType != VMA_SUBALLOCATION_TYPE_FREE);
VMA_ASSERT(suballocItem != m_Suballocations.cend());
VMA_ASSERT(pOffset != VMA_NULL);
-
+
*itemsToMakeLostCount = 0;
*pSumFreeSize = 0;
*pSumItemSize = 0;
@@ -9560,19 +9914,19 @@ bool VmaBlockMetadata_Generic::CheckAllocation(
// Start from offset equal to beginning of this suballocation.
*pOffset = suballocItem->offset;
-
+
// Apply VMA_DEBUG_MARGIN at the beginning.
if(VMA_DEBUG_MARGIN > 0)
{
*pOffset += VMA_DEBUG_MARGIN;
}
-
+
// Apply alignment.
*pOffset = VmaAlignUp(*pOffset, allocAlignment);
// Check previous suballocations for BufferImageGranularity conflicts.
// Make bigger alignment if necessary.
- if(bufferImageGranularity > 1)
+ if(bufferImageGranularity > 1 && bufferImageGranularity != allocAlignment)
{
bool bufferImageGranularityConflict = false;
VmaSuballocationList::const_iterator prevSuballocItem = suballocItem;
@@ -9597,14 +9951,14 @@ bool VmaBlockMetadata_Generic::CheckAllocation(
*pOffset = VmaAlignUp(*pOffset, bufferImageGranularity);
}
}
-
+
// Now that we have final *pOffset, check if we are past suballocItem.
// If yes, return false - this function should be called for another suballocItem as starting point.
if(*pOffset >= suballocItem->offset + suballocItem->size)
{
return false;
}
-
+
// Calculate padding at the beginning based on current offset.
const VkDeviceSize paddingBegin = *pOffset - suballocItem->offset;
@@ -9656,7 +10010,7 @@ bool VmaBlockMetadata_Generic::CheckAllocation(
// Check next suballocations for BufferImageGranularity conflicts.
// If conflict exists, we must mark more allocations lost or fail.
- if(bufferImageGranularity > 1)
+ if(allocSize % bufferImageGranularity || *pOffset % bufferImageGranularity)
{
VmaSuballocationList::const_iterator nextSuballocItem = lastSuballocItem;
++nextSuballocItem;
@@ -9703,19 +10057,19 @@ bool VmaBlockMetadata_Generic::CheckAllocation(
// Start from offset equal to beginning of this suballocation.
*pOffset = suballoc.offset;
-
+
// Apply VMA_DEBUG_MARGIN at the beginning.
if(VMA_DEBUG_MARGIN > 0)
{
*pOffset += VMA_DEBUG_MARGIN;
}
-
+
// Apply alignment.
*pOffset = VmaAlignUp(*pOffset, allocAlignment);
-
+
// Check previous suballocations for BufferImageGranularity conflicts.
// Make bigger alignment if necessary.
- if(bufferImageGranularity > 1)
+ if(bufferImageGranularity > 1 && bufferImageGranularity != allocAlignment)
{
bool bufferImageGranularityConflict = false;
VmaSuballocationList::const_iterator prevSuballocItem = suballocItem;
@@ -9740,7 +10094,7 @@ bool VmaBlockMetadata_Generic::CheckAllocation(
*pOffset = VmaAlignUp(*pOffset, bufferImageGranularity);
}
}
-
+
// Calculate padding at the beginning based on current offset.
const VkDeviceSize paddingBegin = *pOffset - suballoc.offset;
@@ -9755,7 +10109,7 @@ bool VmaBlockMetadata_Generic::CheckAllocation(
// Check next suballocations for BufferImageGranularity conflicts.
// If conflict exists, allocation cannot be made here.
- if(bufferImageGranularity > 1)
+ if(allocSize % bufferImageGranularity || *pOffset % bufferImageGranularity)
{
VmaSuballocationList::const_iterator nextSuballocItem = suballocItem;
++nextSuballocItem;
@@ -9787,7 +10141,7 @@ void VmaBlockMetadata_Generic::MergeFreeWithNext(VmaSuballocationList::iterator
{
VMA_ASSERT(item != m_Suballocations.end());
VMA_ASSERT(item->type == VMA_SUBALLOCATION_TYPE_FREE);
-
+
VmaSuballocationList::iterator nextItem = item;
++nextItem;
VMA_ASSERT(nextItem != m_Suballocations.end());
@@ -9804,7 +10158,7 @@ VmaSuballocationList::iterator VmaBlockMetadata_Generic::FreeSuballocation(VmaSu
VmaSuballocation& suballoc = *suballocItem;
suballoc.type = VMA_SUBALLOCATION_TYPE_FREE;
suballoc.hAllocation = VK_NULL_HANDLE;
-
+
// Update totals.
++m_FreeCount;
m_SumFreeSize += suballoc.size;
@@ -9812,7 +10166,7 @@ VmaSuballocationList::iterator VmaBlockMetadata_Generic::FreeSuballocation(VmaSu
// Merge with previous and/or next suballocation if it's also free.
bool mergeWithNext = false;
bool mergeWithPrev = false;
-
+
VmaSuballocationList::iterator nextItem = suballocItem;
++nextItem;
if((nextItem != m_Suballocations.end()) && (nextItem->type == VMA_SUBALLOCATION_TYPE_FREE))
@@ -10110,7 +10464,7 @@ VkDeviceSize VmaBlockMetadata_Linear::GetUnusedRangeSizeMax() const
{
return size;
}
-
+
const SuballocationVectorType& suballocations1st = AccessSuballocations1st();
switch(m_2ndVectorMode)
@@ -10118,7 +10472,7 @@ VkDeviceSize VmaBlockMetadata_Linear::GetUnusedRangeSizeMax() const
case SECOND_VECTOR_EMPTY:
/*
Available space is after end of 1st, as well as before beginning of 1st (which
- whould make it a ring buffer).
+ would make it a ring buffer).
*/
{
const size_t suballocations1stCount = suballocations1st.size();
@@ -10197,7 +10551,7 @@ void VmaBlockMetadata_Linear::CalcAllocationStatInfo(VmaStatInfo& outInfo) const
if(nextAlloc2ndIndex < suballoc2ndCount)
{
const VmaSuballocation& suballoc = suballocations2nd[nextAlloc2ndIndex];
-
+
// 1. Process free space before this allocation.
if(lastOffset < suballoc.offset)
{
@@ -10208,13 +10562,13 @@ void VmaBlockMetadata_Linear::CalcAllocationStatInfo(VmaStatInfo& outInfo) const
outInfo.unusedRangeSizeMin = VMA_MIN(outInfo.unusedRangeSizeMin, unusedRangeSize);
outInfo.unusedRangeSizeMax = VMA_MIN(outInfo.unusedRangeSizeMax, unusedRangeSize);
}
-
+
// 2. Process this allocation.
// There is allocation with suballoc.offset, suballoc.size.
outInfo.usedBytes += suballoc.size;
outInfo.allocationSizeMin = VMA_MIN(outInfo.allocationSizeMin, suballoc.size);
outInfo.allocationSizeMax = VMA_MIN(outInfo.allocationSizeMax, suballoc.size);
-
+
// 3. Prepare for next iteration.
lastOffset = suballoc.offset + suballoc.size;
++nextAlloc2ndIndex;
@@ -10254,7 +10608,7 @@ void VmaBlockMetadata_Linear::CalcAllocationStatInfo(VmaStatInfo& outInfo) const
if(nextAlloc1stIndex < suballoc1stCount)
{
const VmaSuballocation& suballoc = suballocations1st[nextAlloc1stIndex];
-
+
// 1. Process free space before this allocation.
if(lastOffset < suballoc.offset)
{
@@ -10265,13 +10619,13 @@ void VmaBlockMetadata_Linear::CalcAllocationStatInfo(VmaStatInfo& outInfo) const
outInfo.unusedRangeSizeMin = VMA_MIN(outInfo.unusedRangeSizeMin, unusedRangeSize);
outInfo.unusedRangeSizeMax = VMA_MIN(outInfo.unusedRangeSizeMax, unusedRangeSize);
}
-
+
// 2. Process this allocation.
// There is allocation with suballoc.offset, suballoc.size.
outInfo.usedBytes += suballoc.size;
outInfo.allocationSizeMin = VMA_MIN(outInfo.allocationSizeMin, suballoc.size);
outInfo.allocationSizeMax = VMA_MIN(outInfo.allocationSizeMax, suballoc.size);
-
+
// 3. Prepare for next iteration.
lastOffset = suballoc.offset + suballoc.size;
++nextAlloc1stIndex;
@@ -10310,7 +10664,7 @@ void VmaBlockMetadata_Linear::CalcAllocationStatInfo(VmaStatInfo& outInfo) const
if(nextAlloc2ndIndex != SIZE_MAX)
{
const VmaSuballocation& suballoc = suballocations2nd[nextAlloc2ndIndex];
-
+
// 1. Process free space before this allocation.
if(lastOffset < suballoc.offset)
{
@@ -10321,13 +10675,13 @@ void VmaBlockMetadata_Linear::CalcAllocationStatInfo(VmaStatInfo& outInfo) const
outInfo.unusedRangeSizeMin = VMA_MIN(outInfo.unusedRangeSizeMin, unusedRangeSize);
outInfo.unusedRangeSizeMax = VMA_MIN(outInfo.unusedRangeSizeMax, unusedRangeSize);
}
-
+
// 2. Process this allocation.
// There is allocation with suballoc.offset, suballoc.size.
outInfo.usedBytes += suballoc.size;
outInfo.allocationSizeMin = VMA_MIN(outInfo.allocationSizeMin, suballoc.size);
outInfo.allocationSizeMax = VMA_MIN(outInfo.allocationSizeMax, suballoc.size);
-
+
// 3. Prepare for next iteration.
lastOffset = suballoc.offset + suballoc.size;
--nextAlloc2ndIndex;
@@ -10383,7 +10737,7 @@ void VmaBlockMetadata_Linear::AddPoolStats(VmaPoolStats& inoutStats) const
if(nextAlloc2ndIndex < suballoc2ndCount)
{
const VmaSuballocation& suballoc = suballocations2nd[nextAlloc2ndIndex];
-
+
// 1. Process free space before this allocation.
if(lastOffset < suballoc.offset)
{
@@ -10393,11 +10747,11 @@ void VmaBlockMetadata_Linear::AddPoolStats(VmaPoolStats& inoutStats) const
++inoutStats.unusedRangeCount;
inoutStats.unusedRangeSizeMax = VMA_MAX(inoutStats.unusedRangeSizeMax, unusedRangeSize);
}
-
+
// 2. Process this allocation.
// There is allocation with suballoc.offset, suballoc.size.
++inoutStats.allocationCount;
-
+
// 3. Prepare for next iteration.
lastOffset = suballoc.offset + suballoc.size;
++nextAlloc2ndIndex;
@@ -10436,7 +10790,7 @@ void VmaBlockMetadata_Linear::AddPoolStats(VmaPoolStats& inoutStats) const
if(nextAlloc1stIndex < suballoc1stCount)
{
const VmaSuballocation& suballoc = suballocations1st[nextAlloc1stIndex];
-
+
// 1. Process free space before this allocation.
if(lastOffset < suballoc.offset)
{
@@ -10446,11 +10800,11 @@ void VmaBlockMetadata_Linear::AddPoolStats(VmaPoolStats& inoutStats) const
++inoutStats.unusedRangeCount;
inoutStats.unusedRangeSizeMax = VMA_MAX(inoutStats.unusedRangeSizeMax, unusedRangeSize);
}
-
+
// 2. Process this allocation.
// There is allocation with suballoc.offset, suballoc.size.
++inoutStats.allocationCount;
-
+
// 3. Prepare for next iteration.
lastOffset = suballoc.offset + suballoc.size;
++nextAlloc1stIndex;
@@ -10488,7 +10842,7 @@ void VmaBlockMetadata_Linear::AddPoolStats(VmaPoolStats& inoutStats) const
if(nextAlloc2ndIndex != SIZE_MAX)
{
const VmaSuballocation& suballoc = suballocations2nd[nextAlloc2ndIndex];
-
+
// 1. Process free space before this allocation.
if(lastOffset < suballoc.offset)
{
@@ -10498,11 +10852,11 @@ void VmaBlockMetadata_Linear::AddPoolStats(VmaPoolStats& inoutStats) const
++inoutStats.unusedRangeCount;
inoutStats.unusedRangeSizeMax = VMA_MAX(inoutStats.unusedRangeSizeMax, unusedRangeSize);
}
-
+
// 2. Process this allocation.
// There is allocation with suballoc.offset, suballoc.size.
++inoutStats.allocationCount;
-
+
// 3. Prepare for next iteration.
lastOffset = suballoc.offset + suballoc.size;
--nextAlloc2ndIndex;
@@ -10560,19 +10914,19 @@ void VmaBlockMetadata_Linear::PrintDetailedMap(class VmaJsonWriter& json) const
if(nextAlloc2ndIndex < suballoc2ndCount)
{
const VmaSuballocation& suballoc = suballocations2nd[nextAlloc2ndIndex];
-
+
// 1. Process free space before this allocation.
if(lastOffset < suballoc.offset)
{
// There is free space from lastOffset to suballoc.offset.
++unusedRangeCount;
}
-
+
// 2. Process this allocation.
// There is allocation with suballoc.offset, suballoc.size.
++alloc2ndCount;
usedBytes += suballoc.size;
-
+
// 3. Prepare for next iteration.
lastOffset = suballoc.offset + suballoc.size;
++nextAlloc2ndIndex;
@@ -10609,19 +10963,19 @@ void VmaBlockMetadata_Linear::PrintDetailedMap(class VmaJsonWriter& json) const
if(nextAlloc1stIndex < suballoc1stCount)
{
const VmaSuballocation& suballoc = suballocations1st[nextAlloc1stIndex];
-
+
// 1. Process free space before this allocation.
if(lastOffset < suballoc.offset)
{
// There is free space from lastOffset to suballoc.offset.
++unusedRangeCount;
}
-
+
// 2. Process this allocation.
// There is allocation with suballoc.offset, suballoc.size.
++alloc1stCount;
usedBytes += suballoc.size;
-
+
// 3. Prepare for next iteration.
lastOffset = suballoc.offset + suballoc.size;
++nextAlloc1stIndex;
@@ -10656,19 +11010,19 @@ void VmaBlockMetadata_Linear::PrintDetailedMap(class VmaJsonWriter& json) const
if(nextAlloc2ndIndex != SIZE_MAX)
{
const VmaSuballocation& suballoc = suballocations2nd[nextAlloc2ndIndex];
-
+
// 1. Process free space before this allocation.
if(lastOffset < suballoc.offset)
{
// There is free space from lastOffset to suballoc.offset.
++unusedRangeCount;
}
-
+
// 2. Process this allocation.
// There is allocation with suballoc.offset, suballoc.size.
++alloc2ndCount;
usedBytes += suballoc.size;
-
+
// 3. Prepare for next iteration.
lastOffset = suballoc.offset + suballoc.size;
--nextAlloc2ndIndex;
@@ -10711,7 +11065,7 @@ void VmaBlockMetadata_Linear::PrintDetailedMap(class VmaJsonWriter& json) const
if(nextAlloc2ndIndex < suballoc2ndCount)
{
const VmaSuballocation& suballoc = suballocations2nd[nextAlloc2ndIndex];
-
+
// 1. Process free space before this allocation.
if(lastOffset < suballoc.offset)
{
@@ -10719,11 +11073,11 @@ void VmaBlockMetadata_Linear::PrintDetailedMap(class VmaJsonWriter& json) const
const VkDeviceSize unusedRangeSize = suballoc.offset - lastOffset;
PrintDetailedMap_UnusedRange(json, lastOffset, unusedRangeSize);
}
-
+
// 2. Process this allocation.
// There is allocation with suballoc.offset, suballoc.size.
PrintDetailedMap_Allocation(json, suballoc.offset, suballoc.hAllocation);
-
+
// 3. Prepare for next iteration.
lastOffset = suballoc.offset + suballoc.size;
++nextAlloc2ndIndex;
@@ -10758,7 +11112,7 @@ void VmaBlockMetadata_Linear::PrintDetailedMap(class VmaJsonWriter& json) const
if(nextAlloc1stIndex < suballoc1stCount)
{
const VmaSuballocation& suballoc = suballocations1st[nextAlloc1stIndex];
-
+
// 1. Process free space before this allocation.
if(lastOffset < suballoc.offset)
{
@@ -10766,11 +11120,11 @@ void VmaBlockMetadata_Linear::PrintDetailedMap(class VmaJsonWriter& json) const
const VkDeviceSize unusedRangeSize = suballoc.offset - lastOffset;
PrintDetailedMap_UnusedRange(json, lastOffset, unusedRangeSize);
}
-
+
// 2. Process this allocation.
// There is allocation with suballoc.offset, suballoc.size.
PrintDetailedMap_Allocation(json, suballoc.offset, suballoc.hAllocation);
-
+
// 3. Prepare for next iteration.
lastOffset = suballoc.offset + suballoc.size;
++nextAlloc1stIndex;
@@ -10806,7 +11160,7 @@ void VmaBlockMetadata_Linear::PrintDetailedMap(class VmaJsonWriter& json) const
if(nextAlloc2ndIndex != SIZE_MAX)
{
const VmaSuballocation& suballoc = suballocations2nd[nextAlloc2ndIndex];
-
+
// 1. Process free space before this allocation.
if(lastOffset < suballoc.offset)
{
@@ -10814,11 +11168,11 @@ void VmaBlockMetadata_Linear::PrintDetailedMap(class VmaJsonWriter& json) const
const VkDeviceSize unusedRangeSize = suballoc.offset - lastOffset;
PrintDetailedMap_UnusedRange(json, lastOffset, unusedRangeSize);
}
-
+
// 2. Process this allocation.
// There is allocation with suballoc.offset, suballoc.size.
PrintDetailedMap_Allocation(json, suballoc.offset, suballoc.hAllocation);
-
+
// 3. Prepare for next iteration.
lastOffset = suballoc.offset + suballoc.size;
--nextAlloc2ndIndex;
@@ -10923,7 +11277,7 @@ bool VmaBlockMetadata_Linear::CreateAllocationRequest_UpperAddress(
// Check next suballocations from 2nd for BufferImageGranularity conflicts.
// Make bigger alignment if necessary.
- if(bufferImageGranularity > 1 && !suballocations2nd.empty())
+ if(bufferImageGranularity > 1 && bufferImageGranularity != allocAlignment && !suballocations2nd.empty())
{
bool bufferImageGranularityConflict = false;
for(size_t nextSuballocIndex = suballocations2nd.size(); nextSuballocIndex--; )
@@ -11028,7 +11382,7 @@ bool VmaBlockMetadata_Linear::CreateAllocationRequest_LowerAddress(
// Check previous suballocations for BufferImageGranularity conflicts.
// Make bigger alignment if necessary.
- if(bufferImageGranularity > 1 && !suballocations1st.empty())
+ if(bufferImageGranularity > 1 && bufferImageGranularity != allocAlignment && !suballocations1st.empty())
{
bool bufferImageGranularityConflict = false;
for(size_t prevSuballocIndex = suballocations1st.size(); prevSuballocIndex--; )
@@ -11060,7 +11414,7 @@ bool VmaBlockMetadata_Linear::CreateAllocationRequest_LowerAddress(
{
// Check next suballocations for BufferImageGranularity conflicts.
// If conflict exists, allocation cannot be made here.
- if(bufferImageGranularity > 1 && m_2ndVectorMode == SECOND_VECTOR_DOUBLE_STACK)
+ if((allocSize % bufferImageGranularity || resultOffset % bufferImageGranularity) && m_2ndVectorMode == SECOND_VECTOR_DOUBLE_STACK)
{
for(size_t nextSuballocIndex = suballocations2nd.size(); nextSuballocIndex--; )
{
@@ -11118,7 +11472,7 @@ bool VmaBlockMetadata_Linear::CreateAllocationRequest_LowerAddress(
// Check previous suballocations for BufferImageGranularity conflicts.
// Make bigger alignment if necessary.
- if(bufferImageGranularity > 1 && !suballocations2nd.empty())
+ if(bufferImageGranularity > 1 && bufferImageGranularity != allocAlignment && !suballocations2nd.empty())
{
bool bufferImageGranularityConflict = false;
for(size_t prevSuballocIndex = suballocations2nd.size(); prevSuballocIndex--; )
@@ -11176,7 +11530,7 @@ bool VmaBlockMetadata_Linear::CreateAllocationRequest_LowerAddress(
// Check next suballocations for BufferImageGranularity conflicts.
// If conflict exists, we must mark more allocations lost or fail.
- if(bufferImageGranularity > 1)
+ if(allocSize % bufferImageGranularity || resultOffset % bufferImageGranularity)
{
while(index1st < suballocations1st.size())
{
@@ -11222,7 +11576,7 @@ bool VmaBlockMetadata_Linear::CreateAllocationRequest_LowerAddress(
{
// Check next suballocations for BufferImageGranularity conflicts.
// If conflict exists, allocation cannot be made here.
- if(bufferImageGranularity > 1)
+ if(allocSize % bufferImageGranularity || resultOffset % bufferImageGranularity)
{
for(size_t nextSuballocIndex = index1st;
nextSuballocIndex < suballocations1st.size();
@@ -11270,7 +11624,7 @@ bool VmaBlockMetadata_Linear::MakeRequestedAllocationsLost(
}
VMA_ASSERT(m_2ndVectorMode == SECOND_VECTOR_EMPTY || m_2ndVectorMode == SECOND_VECTOR_RING_BUFFER);
-
+
// We always start from 1st.
SuballocationVectorType* suballocations = &AccessSuballocations1st();
size_t index = m_1stNullItemsBeginCount;
@@ -11318,15 +11672,15 @@ bool VmaBlockMetadata_Linear::MakeRequestedAllocationsLost(
}
CleanupAfterFree();
- //VMA_HEAVY_ASSERT(Validate()); // Already called by ClanupAfterFree().
-
+ //VMA_HEAVY_ASSERT(Validate()); // Already called by CleanupAfterFree().
+
return true;
}
uint32_t VmaBlockMetadata_Linear::MakeAllocationsLost(uint32_t currentFrameIndex, uint32_t frameInUseCount)
{
uint32_t lostAllocationCount = 0;
-
+
SuballocationVectorType& suballocations1st = AccessSuballocations1st();
for(size_t i = m_1stNullItemsBeginCount, count = suballocations1st.size(); i < count; ++i)
{
@@ -11750,7 +12104,7 @@ bool VmaBlockMetadata_Buddy::Validate() const
node = node->free.next)
{
VMA_VALIDATE(node->type == Node::TYPE_FREE);
-
+
if(node->free.next == VMA_NULL)
{
VMA_VALIDATE(m_FreeList[level].back == node);
@@ -11936,7 +12290,7 @@ void VmaBlockMetadata_Buddy::Alloc(
const uint32_t targetLevel = AllocSizeToLevel(allocSize);
uint32_t currLevel = (uint32_t)(uintptr_t)request.customData;
-
+
Node* currNode = m_FreeList[currLevel].front;
VMA_ASSERT(currNode != VMA_NULL && currNode->type == Node::TYPE_FREE);
while(currNode->offset != request.offset)
@@ -11944,14 +12298,14 @@ void VmaBlockMetadata_Buddy::Alloc(
currNode = currNode->free.next;
VMA_ASSERT(currNode != VMA_NULL && currNode->type == Node::TYPE_FREE);
}
-
+
// Go down, splitting free nodes.
while(currLevel < targetLevel)
{
// currNode is already first free node at currLevel.
// Remove it from list of free nodes at this currLevel.
RemoveFromFreeList(currLevel, currNode);
-
+
const uint32_t childrenLevel = currLevel + 1;
// Create two free sub-nodes.
@@ -12113,7 +12467,7 @@ void VmaBlockMetadata_Buddy::FreeAtOffset(VmaAllocation alloc, VkDeviceSize offs
vma_delete(GetAllocationCallbacks(), node->buddy);
vma_delete(GetAllocationCallbacks(), node);
parent->type = Node::TYPE_FREE;
-
+
node = parent;
--level;
//m_SumFreeSize += LevelToNodeSize(level) % 2; // Useful only when level node sizes can be non power of 2.
@@ -12227,7 +12581,7 @@ void VmaBlockMetadata_Buddy::PrintDetailedMapNode(class VmaJsonWriter& json, con
PrintDetailedMap_UnusedRange(json, node->offset, levelNodeSize);
break;
case Node::TYPE_ALLOCATION:
- {
+ {
PrintDetailedMap_Allocation(json, node->offset, node->allocation.alloc);
const VkDeviceSize allocSize = node->allocation.alloc->GetSize();
if(allocSize < levelNodeSize)
@@ -12316,7 +12670,7 @@ bool VmaDeviceMemoryBlock::Validate() const
{
VMA_VALIDATE((m_hMemory != VK_NULL_HANDLE) &&
(m_pMetadata->GetSize() != 0));
-
+
return m_pMetadata->Validate();
}
@@ -12521,7 +12875,8 @@ VmaPool_T::VmaPool_T(
(createInfo.flags & VMA_POOL_CREATE_IGNORE_BUFFER_IMAGE_GRANULARITY_BIT) != 0 ? 1 : hAllocator->GetBufferImageGranularity(),
createInfo.frameInUseCount,
createInfo.blockSize != 0, // explicitBlockSize
- createInfo.flags & VMA_POOL_CREATE_ALGORITHM_MASK), // algorithm
+ createInfo.flags & VMA_POOL_CREATE_ALGORITHM_MASK,
+ createInfo.priority), // algorithm
m_Id(0),
m_Name(VMA_NULL)
{
@@ -12529,13 +12884,14 @@ VmaPool_T::VmaPool_T(
VmaPool_T::~VmaPool_T()
{
+ VMA_ASSERT(m_PrevPool == VMA_NULL && m_NextPool == VMA_NULL);
}
void VmaPool_T::SetName(const char* pName)
{
const VkAllocationCallbacks* allocs = m_BlockVector.GetAllocator()->GetAllocationCallbacks();
VmaFreeString(allocs, m_Name);
-
+
if(pName != VMA_NULL)
{
m_Name = VmaCreateStringCopy(allocs, pName);
@@ -12560,7 +12916,8 @@ VmaBlockVector::VmaBlockVector(
VkDeviceSize bufferImageGranularity,
uint32_t frameInUseCount,
bool explicitBlockSize,
- uint32_t algorithm) :
+ uint32_t algorithm,
+ float priority) :
m_hAllocator(hAllocator),
m_hParentPool(hParentPool),
m_MemoryTypeIndex(memoryTypeIndex),
@@ -12571,6 +12928,7 @@ VmaBlockVector::VmaBlockVector(
m_FrameInUseCount(frameInUseCount),
m_ExplicitBlockSize(explicitBlockSize),
m_Algorithm(algorithm),
+ m_Priority(priority),
m_HasEmptyBlock(false),
m_Blocks(VmaStlAllocator(hAllocator->GetAllocationCallbacks())),
m_NextBlockId(0)
@@ -12677,9 +13035,13 @@ VkResult VmaBlockVector::Allocate(
if(res != VK_SUCCESS)
{
// Free all already created allocations.
+ const uint32_t heapIndex = m_hAllocator->MemoryTypeIndexToHeapIndex(m_MemoryTypeIndex);
while(allocIndex--)
{
- Free(pAllocations[allocIndex]);
+ VmaAllocation_T* const alloc = pAllocations[allocIndex];
+ const VkDeviceSize allocSize = alloc->GetSize();
+ Free(alloc);
+ m_hAllocator->m_Budget.RemoveAllocation(heapIndex, allocSize);
}
memset(pAllocations, 0, sizeof(VmaAllocation) * allocationCount);
}
@@ -12699,7 +13061,7 @@ VkResult VmaBlockVector::AllocatePage(
bool canMakeOtherLost = (createInfo.flags & VMA_ALLOCATION_CREATE_CAN_MAKE_OTHER_LOST_BIT) != 0;
const bool mapped = (createInfo.flags & VMA_ALLOCATION_CREATE_MAPPED_BIT) != 0;
const bool isUserDataString = (createInfo.flags & VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT) != 0;
-
+
VkDeviceSize freeMemory;
{
const uint32_t heapIndex = m_hAllocator->MemoryTypeIndexToHeapIndex(m_MemoryTypeIndex);
@@ -12707,7 +13069,7 @@ VkResult VmaBlockVector::AllocatePage(
m_hAllocator->GetBudget(&heapBudget, heapIndex, 1);
freeMemory = (heapBudget.usage < heapBudget.budget) ? (heapBudget.budget - heapBudget.usage) : 0;
}
-
+
const bool canFallbackToDedicated = !IsCustomPool();
const bool canCreateNewBlock =
((createInfo.flags & VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT) == 0) &&
@@ -13221,7 +13583,7 @@ VkResult VmaBlockVector::AllocateFromBlock(
return res;
}
}
-
+
*pAllocation = m_hAllocator->m_AllocationObjectAllocator.Allocate(currentFrameIndex, isUserDataString);
pBlock->m_pMetadata->Alloc(currRequest, suballocType, size, *pAllocation);
UpdateHasEmptyBlock();
@@ -13267,6 +13629,15 @@ VkResult VmaBlockVector::CreateBlock(VkDeviceSize blockSize, size_t* pNewBlockIn
}
#endif // #if VMA_BUFFER_DEVICE_ADDRESS
+#if VMA_MEMORY_PRIORITY
+ VkMemoryPriorityAllocateInfoEXT priorityInfo = { VK_STRUCTURE_TYPE_MEMORY_PRIORITY_ALLOCATE_INFO_EXT };
+ if(m_hAllocator->m_UseExtMemoryPriority)
+ {
+ priorityInfo.priority = m_Priority;
+ VmaPnextChainPushFront(&allocInfo, &priorityInfo);
+ }
+#endif // #if VMA_MEMORY_PRIORITY
+
VkDeviceMemory mem = VK_NULL_HANDLE;
VkResult res = m_hAllocator->AllocateVulkanMemory(&allocInfo, &mem);
if(res < 0)
@@ -13616,7 +13987,7 @@ void VmaBlockVector::Defragment(
VkCommandBuffer commandBuffer)
{
pCtx->res = VK_SUCCESS;
-
+
const VkMemoryPropertyFlags memPropFlags =
m_hAllocator->m_MemProps.memoryTypes[m_MemoryTypeIndex].propertyFlags;
const bool isHostVisible = (memPropFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0;
@@ -13695,13 +14066,13 @@ void VmaBlockVector::Defragment(
{
if(m_hAllocator->m_UseMutex)
m_Mutex.UnlockWrite();
-
+
if(pCtx->res >= VK_SUCCESS && !pCtx->defragmentationMoves.empty())
pCtx->res = VK_NOT_READY;
return;
}
-
+
if(pCtx->res >= VK_SUCCESS)
{
if(defragmentOnGpu)
@@ -13762,8 +14133,8 @@ uint32_t VmaBlockVector::ProcessDefragmentations(
VmaDefragmentationPassMoveInfo* pMove, uint32_t maxMoves)
{
VmaMutexLockWrite lock(m_Mutex, m_hAllocator->m_UseMutex);
-
- const uint32_t moveCount = std::min(uint32_t(pCtx->defragmentationMoves.size()) - pCtx->defragmentationMovesProcessed, maxMoves);
+
+ const uint32_t moveCount = VMA_MIN(uint32_t(pCtx->defragmentationMoves.size()) - pCtx->defragmentationMovesProcessed, maxMoves);
for(uint32_t i = 0; i < moveCount; ++ i)
{
@@ -13786,7 +14157,7 @@ void VmaBlockVector::CommitDefragmentations(
VmaDefragmentationStats* pStats)
{
VmaMutexLockWrite lock(m_Mutex, m_hAllocator->m_UseMutex);
-
+
for(uint32_t i = pCtx->defragmentationMovesCommitted; i < pCtx->defragmentationMovesProcessed; ++ i)
{
const VmaDefragmentationMove &move = pCtx->defragmentationMoves[i];
@@ -14005,7 +14376,7 @@ VkResult VmaDefragmentationAlgorithm_Generic::DefragmentRound(
srcAllocIndex = m_Blocks[srcBlockIndex]->m_Allocations.size() - 1;
}
}
-
+
BlockInfo* pSrcBlockInfo = m_Blocks[srcBlockIndex];
AllocationInfo& allocInfo = pSrcBlockInfo->m_Allocations[srcAllocIndex];
@@ -14065,7 +14436,7 @@ VkResult VmaDefragmentationAlgorithm_Generic::DefragmentRound(
pSrcBlockInfo->m_pBlock->m_pMetadata->FreeAtOffset(srcOffset);
allocInfo.m_hAllocation->ChangeBlockAllocation(m_hAllocator, pDstBlockInfo->m_pBlock, dstAllocRequest.offset);
}
-
+
if(allocInfo.m_pChanged != VMA_NULL)
{
*allocInfo.m_pChanged = VK_TRUE;
@@ -14146,7 +14517,7 @@ VkResult VmaDefragmentationAlgorithm_Generic::Defragment(
}
pBlockInfo->CalcHasNonMovableAllocations();
-
+
// This is a choice based on research.
// Option 1:
pBlockInfo->SortAllocationsByOffsetDescending();
@@ -14296,7 +14667,7 @@ VkResult VmaDefragmentationAlgorithm_Fast::Defragment(
suballoc.hAllocation->ChangeOffset(dstAllocOffset);
m_BytesMoved += srcAllocSize;
++m_AllocationsMoved;
-
+
VmaSuballocationList::iterator nextSuballocIt = srcSuballocIt;
++nextSuballocIt;
pSrcMetadata->m_Suballocations.erase(srcSuballocIt);
@@ -14309,7 +14680,7 @@ VkResult VmaDefragmentationAlgorithm_Fast::Defragment(
move.srcOffset = srcAllocOffset;
move.dstOffset = dstAllocOffset;
move.size = srcAllocSize;
-
+
moves.push_back(move);
}
// Different block
@@ -14337,7 +14708,7 @@ VkResult VmaDefragmentationAlgorithm_Fast::Defragment(
move.srcOffset = srcAllocOffset;
move.dstOffset = dstAllocOffset;
move.size = srcAllocSize;
-
+
moves.push_back(move);
}
}
@@ -14392,13 +14763,13 @@ VkResult VmaDefragmentationAlgorithm_Fast::Defragment(
m_BytesMoved += srcAllocSize;
++m_AllocationsMoved;
++srcSuballocIt;
-
+
move.srcBlockIndex = srcOrigBlockIndex;
move.dstBlockIndex = dstOrigBlockIndex;
move.srcOffset = srcAllocOffset;
move.dstOffset = dstAllocOffset;
move.size = srcAllocSize;
-
+
moves.push_back(move);
}
}
@@ -14429,7 +14800,7 @@ VkResult VmaDefragmentationAlgorithm_Fast::Defragment(
move.srcOffset = srcAllocOffset;
move.dstOffset = dstAllocOffset;
move.size = srcAllocSize;
-
+
moves.push_back(move);
}
}
@@ -14437,7 +14808,7 @@ VkResult VmaDefragmentationAlgorithm_Fast::Defragment(
}
m_BlockInfos.clear();
-
+
PostprocessMetadata();
return VK_SUCCESS;
@@ -14479,7 +14850,7 @@ void VmaDefragmentationAlgorithm_Fast::PostprocessMetadata()
VmaBlockMetadata_Generic* const pMetadata =
(VmaBlockMetadata_Generic*)m_pBlockVector->GetBlock(blockIndex)->m_pMetadata;
const VkDeviceSize blockSize = pMetadata->GetSize();
-
+
// No allocations in this block - entire area is free.
if(pMetadata->m_Suballocations.empty())
{
@@ -14693,7 +15064,7 @@ void VmaDefragmentationContext_T::AddPools(uint32_t poolCount, const VmaPool* pP
if(pool->m_BlockVector.GetAlgorithm() == 0)
{
VmaBlockVectorDefragmentationContext* pBlockVectorDefragCtx = VMA_NULL;
-
+
for(size_t i = m_CustomPoolContexts.size(); i--; )
{
if(m_CustomPoolContexts[i]->GetCustomPool() == pool)
@@ -14702,7 +15073,7 @@ void VmaDefragmentationContext_T::AddPools(uint32_t poolCount, const VmaPool* pP
break;
}
}
-
+
if(!pBlockVectorDefragCtx)
{
pBlockVectorDefragCtx = vma_new(m_hAllocator, VmaBlockVectorDefragmentationContext)(
@@ -15540,7 +15911,7 @@ void VmaRecorder::WriteConfiguration(
fprintf(m_File, "Extension,VK_AMD_device_coherent_memory,%u\n", deviceCoherentMemoryExtensionEnabled ? 1 : 0);
fprintf(m_File, "Macro,VMA_DEBUG_ALWAYS_DEDICATED_MEMORY,%u\n", VMA_DEBUG_ALWAYS_DEDICATED_MEMORY ? 1 : 0);
- fprintf(m_File, "Macro,VMA_DEBUG_ALIGNMENT,%llu\n", (VkDeviceSize)VMA_DEBUG_ALIGNMENT);
+ fprintf(m_File, "Macro,VMA_MIN_ALIGNMENT,%llu\n", (VkDeviceSize)VMA_MIN_ALIGNMENT);
fprintf(m_File, "Macro,VMA_DEBUG_MARGIN,%llu\n", (VkDeviceSize)VMA_DEBUG_MARGIN);
fprintf(m_File, "Macro,VMA_DEBUG_INITIALIZE_ALLOCATIONS,%u\n", VMA_DEBUG_INITIALIZE_ALLOCATIONS ? 1 : 0);
fprintf(m_File, "Macro,VMA_DEBUG_DETECT_CORRUPTION,%u\n", VMA_DEBUG_DETECT_CORRUPTION ? 1 : 0);
@@ -15561,12 +15932,12 @@ void VmaRecorder::GetBasicParams(CallParams& outParams)
// There is room for optimization since sstream is quite slow.
// Is there a better way to convert std::this_thread::get_id() to uint32_t?
std::thread::id thread_id = std::this_thread::get_id();
- stringstream thread_id_to_string_converter;
+ std::stringstream thread_id_to_string_converter;
thread_id_to_string_converter << thread_id;
- string thread_id_as_string = thread_id_to_string_converter.str();
+ std::string thread_id_as_string = thread_id_to_string_converter.str();
outParams.threadId = static_cast(std::stoi(thread_id_as_string.c_str()));
#endif
-
+
auto current_time = std::chrono::high_resolution_clock::now();
outParams.time = std::chrono::duration(current_time - m_RecordingStartTime).count();
@@ -15625,6 +15996,7 @@ VmaAllocator_T::VmaAllocator_T(const VmaAllocatorCreateInfo* pCreateInfo) :
m_UseExtMemoryBudget((pCreateInfo->flags & VMA_ALLOCATOR_CREATE_EXT_MEMORY_BUDGET_BIT) != 0),
m_UseAmdDeviceCoherentMemory((pCreateInfo->flags & VMA_ALLOCATOR_CREATE_AMD_DEVICE_COHERENT_MEMORY_BIT) != 0),
m_UseKhrBufferDeviceAddress((pCreateInfo->flags & VMA_ALLOCATOR_CREATE_BUFFER_DEVICE_ADDRESS_BIT) != 0),
+ m_UseExtMemoryPriority((pCreateInfo->flags & VMA_ALLOCATOR_CREATE_EXT_MEMORY_PRIORITY_BIT) != 0),
m_hDevice(pCreateInfo->device),
m_hInstance(pCreateInfo->instance),
m_AllocationCallbacksSpecified(pCreateInfo->pAllocationCallbacks != VMA_NULL),
@@ -15632,11 +16004,11 @@ VmaAllocator_T::VmaAllocator_T(const VmaAllocatorCreateInfo* pCreateInfo) :
*pCreateInfo->pAllocationCallbacks : VmaEmptyAllocationCallbacks),
m_AllocationObjectAllocator(&m_AllocationCallbacks),
m_HeapSizeLimitMask(0),
+ m_DeviceMemoryCount(0),
m_PreferredLargeHeapBlockSize(0),
m_PhysicalDevice(pCreateInfo->physicalDevice),
m_CurrentFrameIndex(0),
m_GpuDefragmentationMemoryTypeBits(UINT32_MAX),
- m_Pools(VmaStlAllocator(GetAllocationCallbacks())),
m_NextPoolId(0),
m_GlobalMemoryTypeBits(UINT32_MAX)
#if VMA_RECORDING_ENABLED
@@ -15696,13 +16068,18 @@ VmaAllocator_T::VmaAllocator_T(const VmaAllocatorCreateInfo* pCreateInfo) :
VMA_ASSERT(0 && "vulkanApiVersion >= VK_API_VERSION_1_1 but required Vulkan version is disabled by preprocessor macros.");
}
#endif
+#if !(VMA_MEMORY_PRIORITY)
+ if(m_UseExtMemoryPriority)
+ {
+ VMA_ASSERT(0 && "VMA_ALLOCATOR_CREATE_EXT_MEMORY_PRIORITY_BIT is set but required extension is not available in your Vulkan header or its support in VMA has been disabled by a preprocessor macro.");
+ }
+#endif
memset(&m_DeviceMemoryCallbacks, 0 ,sizeof(m_DeviceMemoryCallbacks));
memset(&m_PhysicalDeviceProperties, 0, sizeof(m_PhysicalDeviceProperties));
memset(&m_MemProps, 0, sizeof(m_MemProps));
-
+
memset(&m_pBlockVectors, 0, sizeof(m_pBlockVectors));
- memset(&m_pDedicatedAllocations, 0, sizeof(m_pDedicatedAllocations));
memset(&m_VulkanFunctions, 0, sizeof(m_VulkanFunctions));
if(pCreateInfo->pDeviceMemoryCallbacks != VMA_NULL)
@@ -15717,7 +16094,7 @@ VmaAllocator_T::VmaAllocator_T(const VmaAllocatorCreateInfo* pCreateInfo) :
(*m_VulkanFunctions.vkGetPhysicalDeviceProperties)(m_PhysicalDevice, &m_PhysicalDeviceProperties);
(*m_VulkanFunctions.vkGetPhysicalDeviceMemoryProperties)(m_PhysicalDevice, &m_MemProps);
- VMA_ASSERT(VmaIsPow2(VMA_DEBUG_ALIGNMENT));
+ VMA_ASSERT(VmaIsPow2(VMA_MIN_ALIGNMENT));
VMA_ASSERT(VmaIsPow2(VMA_DEBUG_MIN_BUFFER_IMAGE_GRANULARITY));
VMA_ASSERT(VmaIsPow2(m_PhysicalDeviceProperties.limits.bufferImageGranularity));
VMA_ASSERT(VmaIsPow2(m_PhysicalDeviceProperties.limits.nonCoherentAtomSize));
@@ -15757,11 +16134,10 @@ VmaAllocator_T::VmaAllocator_T(const VmaAllocatorCreateInfo* pCreateInfo) :
GetBufferImageGranularity(),
pCreateInfo->frameInUseCount,
false, // explicitBlockSize
- false); // linearAlgorithm
+ false, // linearAlgorithm
+ 0.5f); // priority (0.5 is the default per Vulkan spec)
// No need to call m_pBlockVectors[memTypeIndex][blockVectorTypeIndex]->CreateMinBlocks here,
// becase minBlockCount is 0.
- m_pDedicatedAllocations[memTypeIndex] = vma_new(this, AllocationVectorType)(VmaStlAllocator(GetAllocationCallbacks()));
-
}
}
@@ -15813,18 +16189,17 @@ VmaAllocator_T::~VmaAllocator_T()
vma_delete(this, m_pRecorder);
}
#endif
-
- VMA_ASSERT(m_Pools.empty());
- for(size_t i = GetMemoryTypeCount(); i--; )
+ VMA_ASSERT(m_Pools.IsEmpty());
+
+ for(size_t memTypeIndex = GetMemoryTypeCount(); memTypeIndex--; )
{
- if(m_pDedicatedAllocations[i] != VMA_NULL && !m_pDedicatedAllocations[i]->empty())
+ if(!m_DedicatedAllocations[memTypeIndex].IsEmpty())
{
VMA_ASSERT(0 && "Unfreed dedicated allocations found.");
}
- vma_delete(this, m_pDedicatedAllocations[i]);
- vma_delete(this, m_pBlockVectors[i]);
+ vma_delete(this, m_pBlockVectors[memTypeIndex]);
}
}
@@ -16112,6 +16487,7 @@ VkResult VmaAllocator_T::AllocateMemoryOfType(
(finalCreateInfo.flags & VMA_ALLOCATION_CREATE_MAPPED_BIT) != 0,
(finalCreateInfo.flags & VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT) != 0,
finalCreateInfo.pUserData,
+ finalCreateInfo.priority,
dedicatedBuffer,
dedicatedBufferUsage,
dedicatedImage,
@@ -16139,33 +16515,40 @@ VkResult VmaAllocator_T::AllocateMemoryOfType(
{
return VK_ERROR_OUT_OF_DEVICE_MEMORY;
}
+
+ // Protection against creating each allocation as dedicated when we reach or exceed heap size/budget,
+ // which can quickly deplete maxMemoryAllocationCount: Don't try dedicated allocations when above
+ // 3/4 of the maximum allocation count.
+ if(m_DeviceMemoryCount.load() > m_PhysicalDeviceProperties.limits.maxMemoryAllocationCount * 3 / 4)
+ {
+ return VK_ERROR_OUT_OF_DEVICE_MEMORY;
+ }
+
+ res = AllocateDedicatedMemory(
+ size,
+ suballocType,
+ memTypeIndex,
+ (finalCreateInfo.flags & VMA_ALLOCATION_CREATE_WITHIN_BUDGET_BIT) != 0,
+ (finalCreateInfo.flags & VMA_ALLOCATION_CREATE_MAPPED_BIT) != 0,
+ (finalCreateInfo.flags & VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT) != 0,
+ finalCreateInfo.pUserData,
+ finalCreateInfo.priority,
+ dedicatedBuffer,
+ dedicatedBufferUsage,
+ dedicatedImage,
+ allocationCount,
+ pAllocations);
+ if(res == VK_SUCCESS)
+ {
+ // Succeeded: AllocateDedicatedMemory function already filld pMemory, nothing more to do here.
+ VMA_DEBUG_LOG(" Allocated as DedicatedMemory");
+ return VK_SUCCESS;
+ }
else
{
- res = AllocateDedicatedMemory(
- size,
- suballocType,
- memTypeIndex,
- (finalCreateInfo.flags & VMA_ALLOCATION_CREATE_WITHIN_BUDGET_BIT) != 0,
- (finalCreateInfo.flags & VMA_ALLOCATION_CREATE_MAPPED_BIT) != 0,
- (finalCreateInfo.flags & VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT) != 0,
- finalCreateInfo.pUserData,
- dedicatedBuffer,
- dedicatedBufferUsage,
- dedicatedImage,
- allocationCount,
- pAllocations);
- if(res == VK_SUCCESS)
- {
- // Succeeded: AllocateDedicatedMemory function already filld pMemory, nothing more to do here.
- VMA_DEBUG_LOG(" Allocated as DedicatedMemory");
- return VK_SUCCESS;
- }
- else
- {
- // Everything failed: Return error code.
- VMA_DEBUG_LOG(" vkAllocateMemory FAILED");
- return res;
- }
+ // Everything failed: Return error code.
+ VMA_DEBUG_LOG(" vkAllocateMemory FAILED");
+ return res;
}
}
}
@@ -16178,6 +16561,7 @@ VkResult VmaAllocator_T::AllocateDedicatedMemory(
bool map,
bool isUserDataString,
void* pUserData,
+ float priority,
VkBuffer dedicatedBuffer,
VkBufferUsageFlags dedicatedBufferUsage,
VkImage dedicatedImage,
@@ -16241,6 +16625,15 @@ VkResult VmaAllocator_T::AllocateDedicatedMemory(
}
#endif // #if VMA_BUFFER_DEVICE_ADDRESS
+#if VMA_MEMORY_PRIORITY
+ VkMemoryPriorityAllocateInfoEXT priorityInfo = { VK_STRUCTURE_TYPE_MEMORY_PRIORITY_ALLOCATE_INFO_EXT };
+ if(m_UseExtMemoryPriority)
+ {
+ priorityInfo.priority = priority;
+ VmaPnextChainPushFront(&allocInfo, &priorityInfo);
+ }
+#endif // #if VMA_MEMORY_PRIORITY
+
size_t allocIndex;
VkResult res = VK_SUCCESS;
for(allocIndex = 0; allocIndex < allocationCount; ++allocIndex)
@@ -16262,14 +16655,13 @@ VkResult VmaAllocator_T::AllocateDedicatedMemory(
if(res == VK_SUCCESS)
{
- // Register them in m_pDedicatedAllocations.
+ // Register them in m_DedicatedAllocations.
{
VmaMutexLockWrite lock(m_DedicatedAllocationsMutex[memTypeIndex], m_UseMutex);
- AllocationVectorType* pDedicatedAllocations = m_pDedicatedAllocations[memTypeIndex];
- VMA_ASSERT(pDedicatedAllocations);
+ DedicatedAllocationLinkedList& dedicatedAllocations = m_DedicatedAllocations[memTypeIndex];
for(allocIndex = 0; allocIndex < allocationCount; ++allocIndex)
{
- VmaVectorInsertSorted(*pDedicatedAllocations, pAllocations[allocIndex]);
+ dedicatedAllocations.PushBack(pAllocations[allocIndex]);
}
}
@@ -16282,7 +16674,7 @@ VkResult VmaAllocator_T::AllocateDedicatedMemory(
{
VmaAllocation currAlloc = pAllocations[allocIndex];
VkDeviceMemory hMemory = currAlloc->GetMemory();
-
+
/*
There is no need to call this, because Vulkan spec allows to skip vkUnmapMemory
before vkFreeMemory.
@@ -16292,7 +16684,7 @@ VkResult VmaAllocator_T::AllocateDedicatedMemory(
(*m_VulkanFunctions.vkUnmapMemory)(m_hDevice, hMemory);
}
*/
-
+
FreeVulkanMemory(memTypeIndex, currAlloc->GetSize(), hMemory);
m_Budget.RemoveAllocation(MemoryTypeIndexToHeapIndex(memTypeIndex), currAlloc->GetSize());
currAlloc->SetUserData(this, VMA_NULL);
@@ -16535,7 +16927,7 @@ VkResult VmaAllocator_T::AllocateMemory(
alignmentForMemType = VMA_MAX(
vkMemReq.alignment,
GetMemoryTypeMinAlignment(memTypeIndex));
-
+
res = AllocateMemoryOfType(
vkMemReq.size,
alignmentForMemType,
@@ -16623,22 +17015,6 @@ void VmaAllocator_T::FreeMemory(
}
}
-VkResult VmaAllocator_T::ResizeAllocation(
- const VmaAllocation alloc,
- VkDeviceSize newSize)
-{
- // This function is deprecated and so it does nothing. It's left for backward compatibility.
- if(newSize == 0 || alloc->GetLastUseFrameIndex() == VMA_FRAME_INDEX_LOST)
- {
- return VK_ERROR_VALIDATION_FAILED_EXT;
- }
- if(newSize == alloc->GetSize())
- {
- return VK_SUCCESS;
- }
- return VK_ERROR_OUT_OF_POOL_MEMORY;
-}
-
void VmaAllocator_T::CalculateStats(VmaStats* pStats)
{
// Initialize.
@@ -16647,7 +17023,7 @@ void VmaAllocator_T::CalculateStats(VmaStats* pStats)
InitStatInfo(pStats->memoryType[i]);
for(size_t i = 0; i < VK_MAX_MEMORY_HEAPS; ++i)
InitStatInfo(pStats->memoryHeap[i]);
-
+
// Process default pools.
for(uint32_t memTypeIndex = 0; memTypeIndex < GetMemoryTypeCount(); ++memTypeIndex)
{
@@ -16659,9 +17035,9 @@ void VmaAllocator_T::CalculateStats(VmaStats* pStats)
// Process custom pools.
{
VmaMutexLockRead lock(m_PoolsMutex, m_UseMutex);
- for(size_t poolIndex = 0, poolCount = m_Pools.size(); poolIndex < poolCount; ++poolIndex)
+ for(VmaPool pool = m_Pools.Front(); pool != VMA_NULL; pool = m_Pools.GetNext(pool))
{
- m_Pools[poolIndex]->m_BlockVector.AddStats(pStats);
+ pool->m_BlockVector.AddStats(pStats);
}
}
@@ -16670,12 +17046,12 @@ void VmaAllocator_T::CalculateStats(VmaStats* pStats)
{
const uint32_t memHeapIndex = MemoryTypeIndexToHeapIndex(memTypeIndex);
VmaMutexLockRead dedicatedAllocationsLock(m_DedicatedAllocationsMutex[memTypeIndex], m_UseMutex);
- AllocationVectorType* const pDedicatedAllocVector = m_pDedicatedAllocations[memTypeIndex];
- VMA_ASSERT(pDedicatedAllocVector);
- for(size_t allocIndex = 0, allocCount = pDedicatedAllocVector->size(); allocIndex < allocCount; ++allocIndex)
+ DedicatedAllocationLinkedList& dedicatedAllocList = m_DedicatedAllocations[memTypeIndex];
+ for(VmaAllocation alloc = dedicatedAllocList.Front();
+ alloc != VMA_NULL; alloc = dedicatedAllocList.GetNext(alloc))
{
VmaStatInfo allocationStatInfo;
- (*pDedicatedAllocVector)[allocIndex]->DedicatedAllocCalcStatsInfo(allocationStatInfo);
+ alloc->DedicatedAllocCalcStatsInfo(allocationStatInfo);
VmaAddStatInfo(pStats->total, allocationStatInfo);
VmaAddStatInfo(pStats->memoryType[memTypeIndex], allocationStatInfo);
VmaAddStatInfo(pStats->memoryHeap[memHeapIndex], allocationStatInfo);
@@ -16792,7 +17168,7 @@ VkResult VmaAllocator_T::DefragmentationPassEnd(
VmaDefragmentationContext context)
{
return context->DefragmentPassEnd();
-
+
}
void VmaAllocator_T::GetAllocationInfo(VmaAllocation hAllocation, VmaAllocationInfo* pAllocationInfo)
@@ -16956,7 +17332,7 @@ VkResult VmaAllocator_T::CreatePool(const VmaPoolCreateInfo* pCreateInfo, VmaPoo
{
VmaMutexLockWrite lock(m_PoolsMutex, m_UseMutex);
(*pPool)->SetId(m_NextPoolId++);
- VmaVectorInsertSorted(m_Pools, *pPool);
+ m_Pools.PushBack(*pPool);
}
return VK_SUCCESS;
@@ -16967,8 +17343,7 @@ void VmaAllocator_T::DestroyPool(VmaPool pool)
// Remove from m_Pools.
{
VmaMutexLockWrite lock(m_PoolsMutex, m_UseMutex);
- bool success = VmaVectorRemoveSorted(m_Pools, pool);
- VMA_ASSERT(success && "Pool not found in Allocator.");
+ m_Pools.Remove(pool);
}
vma_delete(this, pool);
@@ -17033,11 +17408,11 @@ VkResult VmaAllocator_T::CheckCorruption(uint32_t memoryTypeBits)
// Process custom pools.
{
VmaMutexLockRead lock(m_PoolsMutex, m_UseMutex);
- for(size_t poolIndex = 0, poolCount = m_Pools.size(); poolIndex < poolCount; ++poolIndex)
+ for(VmaPool pool = m_Pools.Front(); pool != VMA_NULL; pool = m_Pools.GetNext(pool))
{
- if(((1u << m_Pools[poolIndex]->m_BlockVector.GetMemoryTypeIndex()) & memoryTypeBits) != 0)
+ if(((1u << pool->m_BlockVector.GetMemoryTypeIndex()) & memoryTypeBits) != 0)
{
- VkResult localRes = m_Pools[poolIndex]->m_BlockVector.CheckCorruption();
+ VkResult localRes = pool->m_BlockVector.CheckCorruption();
switch(localRes)
{
case VK_ERROR_FEATURE_NOT_PRESENT:
@@ -17061,8 +17436,42 @@ void VmaAllocator_T::CreateLostAllocation(VmaAllocation* pAllocation)
(*pAllocation)->InitLost();
}
+// An object that increments given atomic but decrements it back in the destructor unless Commit() is called.
+template
+struct AtomicTransactionalIncrement
+{
+public:
+ typedef std::atomic AtomicT;
+ ~AtomicTransactionalIncrement()
+ {
+ if(m_Atomic)
+ --(*m_Atomic);
+ }
+ T Increment(AtomicT* atomic)
+ {
+ m_Atomic = atomic;
+ return m_Atomic->fetch_add(1);
+ }
+ void Commit()
+ {
+ m_Atomic = nullptr;
+ }
+
+private:
+ AtomicT* m_Atomic = nullptr;
+};
+
VkResult VmaAllocator_T::AllocateVulkanMemory(const VkMemoryAllocateInfo* pAllocateInfo, VkDeviceMemory* pMemory)
{
+ AtomicTransactionalIncrement deviceMemoryCountIncrement;
+ const uint64_t prevDeviceMemoryCount = deviceMemoryCountIncrement.Increment(&m_DeviceMemoryCount);
+#if VMA_DEBUG_DONT_EXCEED_MAX_MEMORY_ALLOCATION_COUNT
+ if(prevDeviceMemoryCount >= m_PhysicalDeviceProperties.limits.maxMemoryAllocationCount)
+ {
+ return VK_ERROR_TOO_MANY_OBJECTS;
+ }
+#endif
+
const uint32_t heapIndex = MemoryTypeIndexToHeapIndex(pAllocateInfo->memoryTypeIndex);
// HeapSizeLimit is in effect for this heap.
@@ -17102,6 +17511,8 @@ VkResult VmaAllocator_T::AllocateVulkanMemory(const VkMemoryAllocateInfo* pAlloc
{
(*m_DeviceMemoryCallbacks.pfnAllocate)(this, pAllocateInfo->memoryTypeIndex, *pMemory, pAllocateInfo->allocationSize, m_DeviceMemoryCallbacks.pUserData);
}
+
+ deviceMemoryCountIncrement.Commit();
}
else
{
@@ -17123,6 +17534,8 @@ void VmaAllocator_T::FreeVulkanMemory(uint32_t memoryType, VkDeviceSize size, Vk
(*m_VulkanFunctions.vkFreeMemory)(m_hDevice, hMemory, GetAllocationCallbacks());
m_Budget.m_BlockBytes[MemoryTypeIndexToHeapIndex(memoryType)] -= size;
+
+ --m_DeviceMemoryCount;
}
VkResult VmaAllocator_T::BindVulkanBuffer(
@@ -17320,7 +17733,7 @@ VkResult VmaAllocator_T::FlushOrInvalidateAllocations(
typedef VmaStlAllocator RangeAllocator;
typedef VmaSmallVector RangeVector;
RangeVector ranges = RangeVector(RangeAllocator(GetAllocationCallbacks()));
-
+
for(uint32_t allocIndex = 0; allocIndex < allocationCount; ++allocIndex)
{
const VmaAllocation alloc = allocations[allocIndex];
@@ -17359,14 +17772,12 @@ void VmaAllocator_T::FreeDedicatedMemory(const VmaAllocation allocation)
const uint32_t memTypeIndex = allocation->GetMemoryTypeIndex();
{
VmaMutexLockWrite lock(m_DedicatedAllocationsMutex[memTypeIndex], m_UseMutex);
- AllocationVectorType* const pDedicatedAllocations = m_pDedicatedAllocations[memTypeIndex];
- VMA_ASSERT(pDedicatedAllocations);
- bool success = VmaVectorRemoveSorted(*pDedicatedAllocations, allocation);
- VMA_ASSERT(success);
+ DedicatedAllocationLinkedList& dedicatedAllocations = m_DedicatedAllocations[memTypeIndex];
+ dedicatedAllocations.Remove(allocation);
}
VkDeviceMemory hMemory = allocation->GetMemory();
-
+
/*
There is no need to call this, because Vulkan spec allows to skip vkUnmapMemory
before vkFreeMemory.
@@ -17376,7 +17787,7 @@ void VmaAllocator_T::FreeDedicatedMemory(const VmaAllocation allocation)
(*m_VulkanFunctions.vkUnmapMemory)(m_hDevice, hMemory);
}
*/
-
+
FreeVulkanMemory(memTypeIndex, allocation->GetSize(), hMemory);
VMA_DEBUG_LOG(" Freed DedicatedMemory MemoryTypeIndex=%u", memTypeIndex);
@@ -17574,9 +17985,8 @@ void VmaAllocator_T::PrintDetailedMap(VmaJsonWriter& json)
for(uint32_t memTypeIndex = 0; memTypeIndex < GetMemoryTypeCount(); ++memTypeIndex)
{
VmaMutexLockRead dedicatedAllocationsLock(m_DedicatedAllocationsMutex[memTypeIndex], m_UseMutex);
- AllocationVectorType* const pDedicatedAllocVector = m_pDedicatedAllocations[memTypeIndex];
- VMA_ASSERT(pDedicatedAllocVector);
- if(pDedicatedAllocVector->empty() == false)
+ DedicatedAllocationLinkedList& dedicatedAllocList = m_DedicatedAllocations[memTypeIndex];
+ if(!dedicatedAllocList.IsEmpty())
{
if(dedicatedAllocationsStarted == false)
{
@@ -17588,14 +17998,14 @@ void VmaAllocator_T::PrintDetailedMap(VmaJsonWriter& json)
json.BeginString("Type ");
json.ContinueString(memTypeIndex);
json.EndString();
-
+
json.BeginArray();
- for(size_t i = 0; i < pDedicatedAllocVector->size(); ++i)
+ for(VmaAllocation alloc = dedicatedAllocList.Front();
+ alloc != VMA_NULL; alloc = dedicatedAllocList.GetNext(alloc))
{
json.BeginObject(true);
- const VmaAllocation hAlloc = (*pDedicatedAllocVector)[i];
- hAlloc->PrintParameters(json);
+ alloc->PrintParameters(json);
json.EndObject();
}
@@ -17636,18 +18046,17 @@ void VmaAllocator_T::PrintDetailedMap(VmaJsonWriter& json)
// Custom pools
{
VmaMutexLockRead lock(m_PoolsMutex, m_UseMutex);
- const size_t poolCount = m_Pools.size();
- if(poolCount > 0)
+ if(!m_Pools.IsEmpty())
{
json.WriteString("Pools");
json.BeginObject();
- for(size_t poolIndex = 0; poolIndex < poolCount; ++poolIndex)
+ for(VmaPool pool = m_Pools.Front(); pool != VMA_NULL; pool = m_Pools.GetNext(pool))
{
json.BeginString();
- json.ContinueString(m_Pools[poolIndex]->GetId());
+ json.ContinueString(pool->GetId());
json.EndString();
- m_Pools[poolIndex]->m_BlockVector.PrintDetailedMap(json);
+ pool->m_BlockVector.PrintDetailedMap(json);
}
json.EndObject();
}
@@ -17769,7 +18178,7 @@ VMA_CALL_PRE void VMA_CALL_POST vmaBuildStatsString(
json.WriteString("Total");
VmaPrintStatInfo(json, stats.total);
-
+
for(uint32_t heapIndex = 0; heapIndex < allocator->GetMemoryHeapCount(); ++heapIndex)
{
json.BeginString("Heap ");
@@ -17841,18 +18250,22 @@ VMA_CALL_PRE void VMA_CALL_POST vmaBuildStatsString(
{
json.WriteString("LAZILY_ALLOCATED");
}
+#if VMA_VULKAN_VERSION >= 1001000
if((flags & VK_MEMORY_PROPERTY_PROTECTED_BIT) != 0)
{
- json.WriteString(" PROTECTED");
+ json.WriteString("PROTECTED");
}
+#endif // #if VMA_VULKAN_VERSION >= 1001000
+#if VK_AMD_device_coherent_memory
if((flags & VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD_COPY) != 0)
{
- json.WriteString(" DEVICE_COHERENT");
+ json.WriteString("DEVICE_COHERENT");
}
if((flags & VK_MEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMD_COPY) != 0)
{
- json.WriteString(" DEVICE_UNCACHED");
+ json.WriteString("DEVICE_UNCACHED");
}
+#endif // #if VK_AMD_device_coherent_memory
json.EndArray();
if(stats.memoryType[typeIndex].blockCount > 0)
@@ -17918,7 +18331,7 @@ VMA_CALL_PRE VkResult VMA_CALL_POST vmaFindMemoryTypeIndex(
{
memoryTypeBits &= pAllocationCreateInfo->memoryTypeBits;
}
-
+
uint32_t requiredFlags = pAllocationCreateInfo->requiredFlags;
uint32_t preferredFlags = pAllocationCreateInfo->preferredFlags;
uint32_t notPreferredFlags = 0;
@@ -18071,20 +18484,20 @@ VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreatePool(
VmaPool* pPool)
{
VMA_ASSERT(allocator && pCreateInfo && pPool);
-
+
VMA_DEBUG_LOG("vmaCreatePool");
-
+
VMA_DEBUG_GLOBAL_MUTEX_LOCK
-
+
VkResult res = allocator->CreatePool(pCreateInfo, pPool);
-
+
#if VMA_RECORDING_ENABLED
if(allocator->GetRecorder() != VMA_NULL)
{
allocator->GetRecorder()->RecordCreatePool(allocator->GetCurrentFrameIndex(), *pCreateInfo, *pPool);
}
#endif
-
+
return res;
}
@@ -18093,16 +18506,16 @@ VMA_CALL_PRE void VMA_CALL_POST vmaDestroyPool(
VmaPool pool)
{
VMA_ASSERT(allocator);
-
+
if(pool == VK_NULL_HANDLE)
{
return;
}
-
+
VMA_DEBUG_LOG("vmaDestroyPool");
-
+
VMA_DEBUG_GLOBAL_MUTEX_LOCK
-
+
#if VMA_RECORDING_ENABLED
if(allocator->GetRecorder() != VMA_NULL)
{
@@ -18161,7 +18574,7 @@ VMA_CALL_PRE void VMA_CALL_POST vmaGetPoolName(
const char** ppName)
{
VMA_ASSERT(allocator && pool && ppName);
-
+
VMA_DEBUG_LOG("vmaGetPoolName");
VMA_DEBUG_GLOBAL_MUTEX_LOCK
@@ -18225,7 +18638,7 @@ VMA_CALL_PRE VkResult VMA_CALL_POST vmaAllocateMemory(
*pAllocation);
}
#endif
-
+
if(pAllocationInfo != VMA_NULL && result == VK_SUCCESS)
{
allocator->GetAllocationInfo(*pAllocation, pAllocationInfo);
@@ -18276,7 +18689,7 @@ VMA_CALL_PRE VkResult VMA_CALL_POST vmaAllocateMemoryPages(
pAllocations);
}
#endif
-
+
if(pAllocationInfo != VMA_NULL && result == VK_SUCCESS)
{
for(size_t i = 0; i < allocationCount; ++i)
@@ -18398,14 +18811,14 @@ VMA_CALL_PRE void VMA_CALL_POST vmaFreeMemory(
VmaAllocation allocation)
{
VMA_ASSERT(allocator);
-
+
if(allocation == VK_NULL_HANDLE)
{
return;
}
-
+
VMA_DEBUG_LOG("vmaFreeMemory");
-
+
VMA_DEBUG_GLOBAL_MUTEX_LOCK
#if VMA_RECORDING_ENABLED
@@ -18416,7 +18829,7 @@ VMA_CALL_PRE void VMA_CALL_POST vmaFreeMemory(
allocation);
}
#endif
-
+
allocator->FreeMemory(
1, // allocationCount
&allocation);
@@ -18433,9 +18846,9 @@ VMA_CALL_PRE void VMA_CALL_POST vmaFreeMemoryPages(
}
VMA_ASSERT(allocator);
-
+
VMA_DEBUG_LOG("vmaFreeMemoryPages");
-
+
VMA_DEBUG_GLOBAL_MUTEX_LOCK
#if VMA_RECORDING_ENABLED
@@ -18447,24 +18860,10 @@ VMA_CALL_PRE void VMA_CALL_POST vmaFreeMemoryPages(
pAllocations);
}
#endif
-
+
allocator->FreeMemory(allocationCount, pAllocations);
}
-VMA_CALL_PRE VkResult VMA_CALL_POST vmaResizeAllocation(
- VmaAllocator allocator,
- VmaAllocation allocation,
- VkDeviceSize newSize)
-{
- VMA_ASSERT(allocator && allocation);
-
- VMA_DEBUG_LOG("vmaResizeAllocation");
-
- VMA_DEBUG_GLOBAL_MUTEX_LOCK
-
- return allocator->ResizeAllocation(allocation, newSize);
-}
-
VMA_CALL_PRE void VMA_CALL_POST vmaGetAllocationInfo(
VmaAllocator allocator,
VmaAllocation allocation,
@@ -18925,9 +19324,9 @@ VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreateBuffer(
VMA_ASSERT(0 && "Creating a buffer with VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT is not valid if VMA_ALLOCATOR_CREATE_BUFFER_DEVICE_ADDRESS_BIT was not used.");
return VK_ERROR_VALIDATION_FAILED_EXT;
}
-
+
VMA_DEBUG_LOG("vmaCreateBuffer");
-
+
VMA_DEBUG_GLOBAL_MUTEX_LOCK
*pBuffer = VK_NULL_HANDLE;
@@ -19082,7 +19481,7 @@ VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreateImage(
VmaSuballocationType suballocType = pImageCreateInfo->tiling == VK_IMAGE_TILING_OPTIMAL ?
VMA_SUBALLOCATION_TYPE_IMAGE_OPTIMAL :
VMA_SUBALLOCATION_TYPE_IMAGE_LINEAR;
-
+
// 2. Allocate memory using allocator.
VkMemoryRequirements vkMemReq = {};
bool requiresDedicatedAllocation = false;
diff --git a/third_party/vkmemalloc/src/CMakeLists.txt b/third_party/vkmemalloc/src/CMakeLists.txt
new file mode 100644
index 0000000000..eccf82e80b
--- /dev/null
+++ b/third_party/vkmemalloc/src/CMakeLists.txt
@@ -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=$
+ VMA_DYNAMIC_VULKAN_FUNCTIONS=$
+ VMA_DEBUG_ALWAYS_DEDICATED_MEMORY=$
+ VMA_DEBUG_INITIALIZE_ALLOCATIONS=$
+ VMA_DEBUG_GLOBAL_MUTEX=$
+ VMA_DEBUG_DONT_EXCEED_MAX_MEMORY_ALLOCATION_COUNT=$
+ 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()
diff --git a/third_party/vkmemalloc/src/Common.cpp b/third_party/vkmemalloc/src/Common.cpp
index 246acaa6b3..2dcbb680cf 100644
--- a/third_party/vkmemalloc/src/Common.cpp
+++ b/third_party/vkmemalloc/src/Common.cpp
@@ -1,5 +1,5 @@
//
-// Copyright (c) 2017-2020 Advanced Micro Devices, Inc. All rights reserved.
+// Copyright (c) 2017-2021 Advanced Micro Devices, Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -177,4 +177,152 @@ void SaveFile(const wchar_t* filePath, const void* data, size_t dataSize)
assert(0);
}
+std::wstring SizeToStr(size_t size)
+{
+ if(size == 0)
+ return L"0";
+ wchar_t result[32];
+ double size2 = (double)size;
+ if (size2 >= 1024.0*1024.0*1024.0*1024.0)
+ {
+ swprintf_s(result, L"%.2f TB", size2 / (1024.0*1024.0*1024.0*1024.0));
+ }
+ else if (size2 >= 1024.0*1024.0*1024.0)
+ {
+ swprintf_s(result, L"%.2f GB", size2 / (1024.0*1024.0*1024.0));
+ }
+ else if (size2 >= 1024.0*1024.0)
+ {
+ swprintf_s(result, L"%.2f MB", size2 / (1024.0*1024.0));
+ }
+ else if (size2 >= 1024.0)
+ {
+ swprintf_s(result, L"%.2f KB", size2 / 1024.0);
+ }
+ else
+ swprintf_s(result, L"%llu B", size);
+ return result;
+}
+
+bool ConvertCharsToUnicode(std::wstring *outStr, const std::string &s, unsigned codePage)
+{
+ if (s.empty())
+ {
+ outStr->clear();
+ return true;
+ }
+
+ // Phase 1 - Get buffer size.
+ const int size = MultiByteToWideChar(codePage, 0, s.data(), (int)s.length(), NULL, 0);
+ if (size == 0)
+ {
+ outStr->clear();
+ return false;
+ }
+
+ // Phase 2 - Do conversion.
+ std::unique_ptr buf(new wchar_t[(size_t)size]);
+ int result = MultiByteToWideChar(codePage, 0, s.data(), (int)s.length(), buf.get(), size);
+ if (result == 0)
+ {
+ outStr->clear();
+ return false;
+ }
+
+ outStr->assign(buf.get(), (size_t)size);
+ return true;
+}
+
+bool ConvertCharsToUnicode(std::wstring *outStr, const char *s, size_t sCharCount, unsigned codePage)
+{
+ if (sCharCount == 0)
+ {
+ outStr->clear();
+ return true;
+ }
+
+ assert(sCharCount <= (size_t)INT_MAX);
+
+ // Phase 1 - Get buffer size.
+ int size = MultiByteToWideChar(codePage, 0, s, (int)sCharCount, NULL, 0);
+ if (size == 0)
+ {
+ outStr->clear();
+ return false;
+ }
+
+ // Phase 2 - Do conversion.
+ std::unique_ptr buf(new wchar_t[(size_t)size]);
+ int result = MultiByteToWideChar(codePage, 0, s, (int)sCharCount, buf.get(), size);
+ if (result == 0)
+ {
+ outStr->clear();
+ return false;
+ }
+
+ outStr->assign(buf.get(), (size_t)size);
+ return true;
+}
+
+const wchar_t* PhysicalDeviceTypeToStr(VkPhysicalDeviceType type)
+{
+ // Skipping common prefix VK_PHYSICAL_DEVICE_TYPE_
+ static const wchar_t* const VALUES[] = {
+ L"OTHER",
+ L"INTEGRATED_GPU",
+ L"DISCRETE_GPU",
+ L"VIRTUAL_GPU",
+ L"CPU",
+ };
+ return (uint32_t)type < _countof(VALUES) ? VALUES[(uint32_t)type] : L"";
+}
+
+const wchar_t* VendorIDToStr(uint32_t vendorID)
+{
+ switch(vendorID)
+ {
+ // Skipping common prefix VK_VENDOR_ID_ for these:
+ case 0x10001: return L"VIV";
+ case 0x10002: return L"VSI";
+ case 0x10003: return L"KAZAN";
+ case 0x10004: return L"CODEPLAY";
+ case 0x10005: return L"MESA";
+ case 0x10006: return L"POCL";
+ // Others...
+ case VENDOR_ID_AMD: return L"AMD";
+ case VENDOR_ID_NVIDIA: return L"NVIDIA";
+ case VENDOR_ID_INTEL: return L"Intel";
+ case 0x1010: return L"ImgTec";
+ case 0x13B5: return L"ARM";
+ case 0x5143: return L"Qualcomm";
+ }
+ return L"";
+}
+
+#if VMA_VULKAN_VERSION >= 1002000
+const wchar_t* DriverIDToStr(VkDriverId driverID)
+{
+ // Skipping common prefix VK_DRIVER_ID_
+ static const wchar_t* const VALUES[] = {
+ L"",
+ L"AMD_PROPRIETARY",
+ L"AMD_OPEN_SOURCE",
+ L"MESA_RADV",
+ L"NVIDIA_PROPRIETARY",
+ L"INTEL_PROPRIETARY_WINDOWS",
+ L"INTEL_OPEN_SOURCE_MESA",
+ L"IMAGINATION_PROPRIETARY",
+ L"QUALCOMM_PROPRIETARY",
+ L"ARM_PROPRIETARY",
+ L"GOOGLE_SWIFTSHADER",
+ L"GGP_PROPRIETARY",
+ L"BROADCOM_PROPRIETARY",
+ L"MESA_LLVMPIPE",
+ L"MOLTENVK",
+ };
+ return (uint32_t)driverID < _countof(VALUES) ? VALUES[(uint32_t)driverID] : L"";
+}
+#endif // #if VMA_VULKAN_VERSION >= 1002000
+
+
#endif // #ifdef _WIN32
diff --git a/third_party/vkmemalloc/src/Common.h b/third_party/vkmemalloc/src/Common.h
index 19c0297a4e..a718234682 100644
--- a/third_party/vkmemalloc/src/Common.h
+++ b/third_party/vkmemalloc/src/Common.h
@@ -1,5 +1,5 @@
//
-// Copyright (c) 2017-2020 Advanced Micro Devices, Inc. All rights reserved.
+// Copyright (c) 2017-2021 Advanced Micro Devices, Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -48,21 +48,21 @@
typedef std::chrono::high_resolution_clock::time_point time_point;
typedef std::chrono::high_resolution_clock::duration duration;
-#ifdef _DEBUG
- #define TEST(expr) do { \
- if(!(expr)) { \
- assert(0 && #expr); \
- } \
- } while(0)
-#else
- #define TEST(expr) do { \
- if(!(expr)) { \
- throw std::runtime_error("TEST FAILED: " #expr); \
- } \
- } while(0)
-#endif
+#define STRINGIZE(x) STRINGIZE2(x)
+#define STRINGIZE2(x) #x
+#define LINE_STRING STRINGIZE(__LINE__)
+#define TEST(expr) do { if(!(expr)) { \
+ assert(0 && #expr); \
+ throw std::runtime_error(__FILE__ "(" LINE_STRING "): ( " #expr " ) == false"); \
+ } } while(false)
+#define ERR_GUARD_VULKAN(expr) do { if((expr) < 0) { \
+ assert(0 && #expr); \
+ throw std::runtime_error(__FILE__ "(" LINE_STRING "): VkResult( " #expr " ) < 0"); \
+ } } while(false)
-#define ERR_GUARD_VULKAN(expr) TEST((expr) >= 0)
+static const uint32_t VENDOR_ID_AMD = 0x1002;
+static const uint32_t VENDOR_ID_NVIDIA = 0x10DE;
+static const uint32_t VENDOR_ID_INTEL = 0x8086;
extern VkInstance g_hVulkanInstance;
extern VkPhysicalDevice g_hPhysicalDevice;
@@ -322,6 +322,18 @@ void PrintErrorF(const wchar_t* format, ...);
void SaveFile(const wchar_t* filePath, const void* data, size_t dataSize);
+std::wstring SizeToStr(size_t size);
+// As codePage use e.g. CP_ACP for native Windows 1-byte codepage or CP_UTF8.
+bool ConvertCharsToUnicode(std::wstring *outStr, const std::string &s, unsigned codePage);
+bool ConvertCharsToUnicode(std::wstring *outStr, const char *s, size_t sCharCount, unsigned codePage);
+
+const wchar_t* PhysicalDeviceTypeToStr(VkPhysicalDeviceType type);
+const wchar_t* VendorIDToStr(uint32_t vendorID);
+
+#if VMA_VULKAN_VERSION >= 1002000
+const wchar_t* DriverIDToStr(VkDriverId driverID);
+#endif
+
#endif // #ifdef _WIN32
#endif
diff --git a/third_party/vkmemalloc/src/Shaders/CMakeLists.txt b/third_party/vkmemalloc/src/Shaders/CMakeLists.txt
new file mode 100644
index 0000000000..f85ab78cfd
--- /dev/null
+++ b/third_party/vkmemalloc/src/Shaders/CMakeLists.txt
@@ -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})
diff --git a/third_party/vkmemalloc/src/Shaders/Shader.frag b/third_party/vkmemalloc/src/Shaders/Shader.frag
index bbe754b000..207ec8bcd8 100644
--- a/third_party/vkmemalloc/src/Shaders/Shader.frag
+++ b/third_party/vkmemalloc/src/Shaders/Shader.frag
@@ -1,5 +1,5 @@
//
-// Copyright (c) 2017-2020 Advanced Micro Devices, Inc. All rights reserved.
+// Copyright (c) 2017-2021 Advanced Micro Devices, Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
diff --git a/third_party/vkmemalloc/src/Shaders/Shader.vert b/third_party/vkmemalloc/src/Shaders/Shader.vert
index e62544f428..7ef5ddbdcc 100644
--- a/third_party/vkmemalloc/src/Shaders/Shader.vert
+++ b/third_party/vkmemalloc/src/Shaders/Shader.vert
@@ -1,5 +1,5 @@
//
-// Copyright (c) 2017-2020 Advanced Micro Devices, Inc. All rights reserved.
+// Copyright (c) 2017-2021 Advanced Micro Devices, Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
diff --git a/third_party/vkmemalloc/src/Shaders/SparseBindingTest.comp b/third_party/vkmemalloc/src/Shaders/SparseBindingTest.comp
index f615278513..b94027d5ee 100644
--- a/third_party/vkmemalloc/src/Shaders/SparseBindingTest.comp
+++ b/third_party/vkmemalloc/src/Shaders/SparseBindingTest.comp
@@ -1,5 +1,5 @@
//
-// Copyright (c) 2018-2020 Advanced Micro Devices, Inc. All rights reserved.
+// Copyright (c) 2018-2021 Advanced Micro Devices, Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
diff --git a/third_party/vkmemalloc/src/SparseBindingTest.cpp b/third_party/vkmemalloc/src/SparseBindingTest.cpp
index 3c636418ed..b56a048013 100644
--- a/third_party/vkmemalloc/src/SparseBindingTest.cpp
+++ b/third_party/vkmemalloc/src/SparseBindingTest.cpp
@@ -1,5 +1,5 @@
//
-// Copyright (c) 2017-2020 Advanced Micro Devices, Inc. All rights reserved.
+// Copyright (c) 2017-2021 Advanced Micro Devices, Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -532,6 +532,8 @@ SparseBindingImage::~SparseBindingImage()
void TestSparseBinding()
{
+ wprintf(L"TESTING SPARSE BINDING:\n");
+
struct ImageInfo
{
std::unique_ptr image;
@@ -545,7 +547,7 @@ void TestSparseBinding()
RandomNumberGenerator rand(4652467);
- for(uint32_t i = 0; i < frameCount; ++i)
+ for(uint32_t frameIndex = 0; frameIndex < frameCount; ++frameIndex)
{
// Bump frame index.
++g_FrameIndex;
@@ -560,11 +562,11 @@ void TestSparseBinding()
images.push_back(std::move(imageInfo));
// Delete all images that expired.
- for(size_t i = images.size(); i--; )
+ for(size_t imageIndex = images.size(); imageIndex--; )
{
- if(g_FrameIndex >= images[i].endFrame)
+ if(g_FrameIndex >= images[imageIndex].endFrame)
{
- images.erase(images.begin() + i);
+ images.erase(images.begin() + imageIndex);
}
}
}
@@ -588,6 +590,8 @@ void TestSparseBinding()
// Free remaining images.
images.clear();
+
+ wprintf(L"Done.\n");
}
#endif // #ifdef _WIN32
diff --git a/third_party/vkmemalloc/src/SparseBindingTest.h b/third_party/vkmemalloc/src/SparseBindingTest.h
index 3b7a6e183c..98087fa7f2 100644
--- a/third_party/vkmemalloc/src/SparseBindingTest.h
+++ b/third_party/vkmemalloc/src/SparseBindingTest.h
@@ -1,5 +1,5 @@
//
-// Copyright (c) 2017-2020 Advanced Micro Devices, Inc. All rights reserved.
+// Copyright (c) 2017-2021 Advanced Micro Devices, Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
diff --git a/third_party/vkmemalloc/src/Tests.cpp b/third_party/vkmemalloc/src/Tests.cpp
index 55bd67cc1d..7cccb4dedd 100644
--- a/third_party/vkmemalloc/src/Tests.cpp
+++ b/third_party/vkmemalloc/src/Tests.cpp
@@ -1,5 +1,5 @@
//
-// Copyright (c) 2017-2020 Advanced Micro Devices, Inc. All rights reserved.
+// Copyright (c) 2017-2021 Advanced Micro Devices, Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -34,10 +34,12 @@ static const char* CODE_DESCRIPTION = "Foo";
extern VkCommandBuffer g_hTemporaryCommandBuffer;
extern const VkAllocationCallbacks* g_Allocs;
-extern bool g_BufferDeviceAddressEnabled;
-extern PFN_vkGetBufferDeviceAddressEXT g_vkGetBufferDeviceAddressEXT;
+extern bool VK_KHR_buffer_device_address_enabled;
+extern bool VK_EXT_memory_priority_enabled;
+extern PFN_vkGetBufferDeviceAddressKHR g_vkGetBufferDeviceAddressKHR;
void BeginSingleTimeCommands();
void EndSingleTimeCommands();
+void SetDebugUtilsObjectName(VkObjectType type, uint64_t handle, const char* name);
#ifndef VMA_DEBUG_MARGIN
#define VMA_DEBUG_MARGIN 0
@@ -3800,7 +3802,7 @@ static void TestBufferDeviceAddress()
{
wprintf(L"Test buffer device address\n");
- assert(g_BufferDeviceAddressEnabled);
+ assert(VK_KHR_buffer_device_address_enabled);
VkBufferCreateInfo bufCreateInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
bufCreateInfo.size = 0x10000;
@@ -3823,12 +3825,40 @@ static void TestBufferDeviceAddress()
VkBufferDeviceAddressInfoEXT bufferDeviceAddressInfo = { VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO_EXT };
bufferDeviceAddressInfo.buffer = bufInfo.Buffer;
- //assert(g_vkGetBufferDeviceAddressEXT != nullptr);
- if(g_vkGetBufferDeviceAddressEXT != nullptr)
- {
- VkDeviceAddress addr = g_vkGetBufferDeviceAddressEXT(g_hDevice, &bufferDeviceAddressInfo);
- TEST(addr != 0);
- }
+ TEST(g_vkGetBufferDeviceAddressKHR != nullptr);
+ VkDeviceAddress addr = g_vkGetBufferDeviceAddressKHR(g_hDevice, &bufferDeviceAddressInfo);
+ TEST(addr != 0);
+
+ vmaDestroyBuffer(g_hAllocator, bufInfo.Buffer, bufInfo.Allocation);
+ }
+}
+
+static void TestMemoryPriority()
+{
+ wprintf(L"Test memory priority\n");
+
+ assert(VK_EXT_memory_priority_enabled);
+
+ VkBufferCreateInfo bufCreateInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
+ bufCreateInfo.size = 0x10000;
+ bufCreateInfo.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
+
+ VmaAllocationCreateInfo allocCreateInfo = {};
+ allocCreateInfo.usage = VMA_MEMORY_USAGE_GPU_ONLY;
+ allocCreateInfo.priority = 1.f;
+
+ for(uint32_t testIndex = 0; testIndex < 2; ++testIndex)
+ {
+ // 1st is placed, 2nd is dedicated.
+ if(testIndex == 1)
+ allocCreateInfo.flags |= VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT;
+
+ BufferInfo bufInfo = {};
+ VkResult res = vmaCreateBuffer(g_hAllocator, &bufCreateInfo, &allocCreateInfo,
+ &bufInfo.Buffer, &bufInfo.Allocation, nullptr);
+ TEST(res == VK_SUCCESS);
+
+ // There is nothing we can do to validate the priority.
vmaDestroyBuffer(g_hAllocator, bufInfo.Buffer, bufInfo.Allocation);
}
@@ -4315,27 +4345,27 @@ static void TestPool_Benchmark(
return sum + allocSize.Probability;
});
- VkBufferCreateInfo bufferInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
- bufferInfo.size = 256; // Whatever.
- bufferInfo.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
+ VkBufferCreateInfo bufferTemplateInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
+ bufferTemplateInfo.size = 256; // Whatever.
+ bufferTemplateInfo.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
- VkImageCreateInfo imageInfo = { VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO };
- imageInfo.imageType = VK_IMAGE_TYPE_2D;
- imageInfo.extent.width = 256; // Whatever.
- imageInfo.extent.height = 256; // Whatever.
- imageInfo.extent.depth = 1;
- imageInfo.mipLevels = 1;
- imageInfo.arrayLayers = 1;
- imageInfo.format = VK_FORMAT_R8G8B8A8_UNORM;
- imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL; // LINEAR if CPU memory.
- imageInfo.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
- imageInfo.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT; // TRANSFER_SRC if CPU memory.
- imageInfo.samples = VK_SAMPLE_COUNT_1_BIT;
+ VkImageCreateInfo imageTemplateInfo = { VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO };
+ imageTemplateInfo.imageType = VK_IMAGE_TYPE_2D;
+ imageTemplateInfo.extent.width = 256; // Whatever.
+ imageTemplateInfo.extent.height = 256; // Whatever.
+ imageTemplateInfo.extent.depth = 1;
+ imageTemplateInfo.mipLevels = 1;
+ imageTemplateInfo.arrayLayers = 1;
+ imageTemplateInfo.format = VK_FORMAT_R8G8B8A8_UNORM;
+ imageTemplateInfo.tiling = VK_IMAGE_TILING_OPTIMAL; // LINEAR if CPU memory.
+ imageTemplateInfo.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
+ imageTemplateInfo.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT; // TRANSFER_SRC if CPU memory.
+ imageTemplateInfo.samples = VK_SAMPLE_COUNT_1_BIT;
uint32_t bufferMemoryTypeBits = UINT32_MAX;
{
VkBuffer dummyBuffer;
- VkResult res = vkCreateBuffer(g_hDevice, &bufferInfo, g_Allocs, &dummyBuffer);
+ VkResult res = vkCreateBuffer(g_hDevice, &bufferTemplateInfo, g_Allocs, &dummyBuffer);
TEST(res == VK_SUCCESS);
VkMemoryRequirements memReq;
@@ -4348,7 +4378,7 @@ static void TestPool_Benchmark(
uint32_t imageMemoryTypeBits = UINT32_MAX;
{
VkImage dummyImage;
- VkResult res = vkCreateImage(g_hDevice, &imageInfo, g_Allocs, &dummyImage);
+ VkResult res = vkCreateImage(g_hDevice, &imageTemplateInfo, g_Allocs, &dummyImage);
TEST(res == VK_SUCCESS);
VkMemoryRequirements memReq;
@@ -4376,32 +4406,67 @@ static void TestPool_Benchmark(
TEST(0);
VmaPoolCreateInfo poolCreateInfo = {};
- poolCreateInfo.memoryTypeIndex = 0;
poolCreateInfo.minBlockCount = 1;
poolCreateInfo.maxBlockCount = 1;
poolCreateInfo.blockSize = config.PoolSize;
poolCreateInfo.frameInUseCount = 1;
- VmaAllocationCreateInfo dummyAllocCreateInfo = {};
- dummyAllocCreateInfo.usage = VMA_MEMORY_USAGE_GPU_ONLY;
- vmaFindMemoryTypeIndex(g_hAllocator, memoryTypeBits, &dummyAllocCreateInfo, &poolCreateInfo.memoryTypeIndex);
+ const VkPhysicalDeviceMemoryProperties* memProps = nullptr;
+ vmaGetMemoryProperties(g_hAllocator, &memProps);
- VmaPool pool;
- VkResult res = vmaCreatePool(g_hAllocator, &poolCreateInfo, &pool);
- TEST(res == VK_SUCCESS);
+ VmaPool pool = VK_NULL_HANDLE;
+ VkResult res;
+ // Loop over memory types because we sometimes allocate a big block here,
+ // while the most eligible DEVICE_LOCAL heap may be only 256 MB on some GPUs.
+ while(memoryTypeBits)
+ {
+ VmaAllocationCreateInfo dummyAllocCreateInfo = {};
+ dummyAllocCreateInfo.usage = VMA_MEMORY_USAGE_GPU_ONLY;
+ vmaFindMemoryTypeIndex(g_hAllocator, memoryTypeBits, &dummyAllocCreateInfo, &poolCreateInfo.memoryTypeIndex);
+
+ const uint32_t heapIndex = memProps->memoryTypes[poolCreateInfo.memoryTypeIndex].heapIndex;
+ // Protection against validation layer error when trying to allocate a block larger than entire heap size,
+ // which may be only 256 MB on some platforms.
+ if(poolCreateInfo.blockSize * poolCreateInfo.minBlockCount < memProps->memoryHeaps[heapIndex].size)
+ {
+ res = vmaCreatePool(g_hAllocator, &poolCreateInfo, &pool);
+ if(res == VK_SUCCESS)
+ break;
+ }
+ memoryTypeBits &= ~(1u << poolCreateInfo.memoryTypeIndex);
+ }
+ TEST(pool);
// Start time measurement - after creating pool and initializing data structures.
time_point timeBeg = std::chrono::high_resolution_clock::now();
////////////////////////////////////////////////////////////////////////////////
// ThreadProc
- auto ThreadProc = [&](
+ auto ThreadProc = [&config, allocationSizeProbabilitySum, pool](
PoolTestThreadResult* outThreadResult,
uint32_t randSeed,
HANDLE frameStartEvent,
HANDLE frameEndEvent) -> void
{
RandomNumberGenerator threadRand{randSeed};
+ VkResult res = VK_SUCCESS;
+
+ VkBufferCreateInfo bufferInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
+ bufferInfo.size = 256; // Whatever.
+ bufferInfo.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
+
+ VkImageCreateInfo imageInfo = { VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO };
+ imageInfo.imageType = VK_IMAGE_TYPE_2D;
+ imageInfo.extent.width = 256; // Whatever.
+ imageInfo.extent.height = 256; // Whatever.
+ imageInfo.extent.depth = 1;
+ imageInfo.mipLevels = 1;
+ imageInfo.arrayLayers = 1;
+ imageInfo.format = VK_FORMAT_R8G8B8A8_UNORM;
+ imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL; // LINEAR if CPU memory.
+ imageInfo.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
+ imageInfo.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT; // TRANSFER_SRC if CPU memory.
+ imageInfo.samples = VK_SAMPLE_COUNT_1_BIT;
outThreadResult->AllocationTimeMin = duration::max();
outThreadResult->AllocationTimeSum = duration::zero();
@@ -4418,16 +4483,62 @@ static void TestPool_Benchmark(
struct Item
{
- VkDeviceSize BufferSize;
- VkExtent2D ImageSize;
- VkBuffer Buf;
- VkImage Image;
- VmaAllocation Alloc;
+ VkDeviceSize BufferSize = 0;
+ VkExtent2D ImageSize = { 0, 0 };
+ VkBuffer Buf = VK_NULL_HANDLE;
+ VkImage Image = VK_NULL_HANDLE;
+ VmaAllocation Alloc = VK_NULL_HANDLE;
+ Item() { }
+ Item(Item&& src) :
+ BufferSize(src.BufferSize), ImageSize(src.ImageSize), Buf(src.Buf), Image(src.Image), Alloc(src.Alloc)
+ {
+ src.BufferSize = 0;
+ src.ImageSize = {0, 0};
+ src.Buf = VK_NULL_HANDLE;
+ src.Image = VK_NULL_HANDLE;
+ src.Alloc = VK_NULL_HANDLE;
+ }
+ Item(const Item& src) = delete;
+ ~Item()
+ {
+ DestroyResources();
+ }
+ Item& operator=(Item&& src)
+ {
+ if(&src != this)
+ {
+ DestroyResources();
+ BufferSize = src.BufferSize; ImageSize = src.ImageSize;
+ Buf = src.Buf; Image = src.Image; Alloc = src.Alloc;
+ src.BufferSize = 0;
+ src.ImageSize = {0, 0};
+ src.Buf = VK_NULL_HANDLE;
+ src.Image = VK_NULL_HANDLE;
+ src.Alloc = VK_NULL_HANDLE;
+ }
+ return *this;
+ }
+ Item& operator=(const Item& src) = delete;
+ void DestroyResources()
+ {
+ if(Buf)
+ {
+ assert(Image == VK_NULL_HANDLE);
+ vmaDestroyBuffer(g_hAllocator, Buf, Alloc);
+ Buf = VK_NULL_HANDLE;
+ }
+ else
+ {
+ vmaDestroyImage(g_hAllocator, Image, Alloc);
+ Image = VK_NULL_HANDLE;
+ }
+ Alloc = VK_NULL_HANDLE;
+ }
VkDeviceSize CalcSizeBytes() const
{
return BufferSize +
- ImageSize.width * ImageSize.height * 4;
+ 4ull * ImageSize.width * ImageSize.height;
}
};
std::vector- unusedItems, usedItems;
@@ -4469,11 +4580,13 @@ static void TestPool_Benchmark(
}
}
- unusedItems.push_back(item);
+ unusedItems.push_back(std::move(item));
}
auto Allocate = [&](Item& item) -> VkResult
{
+ assert(item.Buf == VK_NULL_HANDLE && item.Image == VK_NULL_HANDLE && item.Alloc == VK_NULL_HANDLE);
+
VmaAllocationCreateInfo allocCreateInfo = {};
allocCreateInfo.pool = pool;
allocCreateInfo.flags = VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT |
@@ -4482,8 +4595,14 @@ static void TestPool_Benchmark(
if(item.BufferSize)
{
bufferInfo.size = item.BufferSize;
- PoolAllocationTimeRegisterObj timeRegisterObj(*outThreadResult);
- return vmaCreateBuffer(g_hAllocator, &bufferInfo, &allocCreateInfo, &item.Buf, &item.Alloc, nullptr);
+ VkResult res = VK_SUCCESS;
+ {
+ PoolAllocationTimeRegisterObj timeRegisterObj(*outThreadResult);
+ res = vmaCreateBuffer(g_hAllocator, &bufferInfo, &allocCreateInfo, &item.Buf, &item.Alloc, nullptr);
+ }
+ if(res == VK_SUCCESS)
+ SetDebugUtilsObjectName(VK_OBJECT_TYPE_BUFFER, (uint64_t)item.Buf, "TestPool_Benchmark_Buffer");
+ return res;
}
else
{
@@ -4491,8 +4610,14 @@ static void TestPool_Benchmark(
imageInfo.extent.width = item.ImageSize.width;
imageInfo.extent.height = item.ImageSize.height;
- PoolAllocationTimeRegisterObj timeRegisterObj(*outThreadResult);
- return vmaCreateImage(g_hAllocator, &imageInfo, &allocCreateInfo, &item.Image, &item.Alloc, nullptr);
+ VkResult res = VK_SUCCESS;
+ {
+ PoolAllocationTimeRegisterObj timeRegisterObj(*outThreadResult);
+ res = vmaCreateImage(g_hAllocator, &imageInfo, &allocCreateInfo, &item.Image, &item.Alloc, nullptr);
+ }
+ if(res == VK_SUCCESS)
+ SetDebugUtilsObjectName(VK_OBJECT_TYPE_IMAGE, (uint64_t)item.Image, "TestPool_Benchmark_Image");
+ return res;
}
};
@@ -4507,8 +4632,10 @@ static void TestPool_Benchmark(
for(size_t i = 0; i < bufsToMakeUnused; ++i)
{
size_t index = threadRand.Generate() % usedItems.size();
- unusedItems.push_back(usedItems[index]);
- usedItems.erase(usedItems.begin() + index);
+ auto it = usedItems.begin() + index;
+ Item item = std::move(*it);
+ usedItems.erase(it);
+ unusedItems.push_back(std::move(item));
}
// Determine which bufs we want to use in this frame.
@@ -4519,15 +4646,19 @@ static void TestPool_Benchmark(
while(usedBufCount < usedItems.size())
{
size_t index = threadRand.Generate() % usedItems.size();
- unusedItems.push_back(usedItems[index]);
- usedItems.erase(usedItems.begin() + index);
+ auto it = usedItems.begin() + index;
+ Item item = std::move(*it);
+ usedItems.erase(it);
+ unusedItems.push_back(std::move(item));
}
// Move some unused to used.
while(usedBufCount > usedItems.size())
{
size_t index = threadRand.Generate() % unusedItems.size();
- usedItems.push_back(unusedItems[index]);
- unusedItems.erase(unusedItems.begin() + index);
+ auto it = unusedItems.begin() + index;
+ Item item = std::move(*it);
+ unusedItems.erase(it);
+ usedItems.push_back(std::move(item));
}
uint32_t touchExistingCount = 0;
@@ -4546,8 +4677,7 @@ static void TestPool_Benchmark(
++outThreadResult->AllocationCount;
if(res != VK_SUCCESS)
{
- item.Alloc = VK_NULL_HANDLE;
- item.Buf = VK_NULL_HANDLE;
+ assert(item.Alloc == VK_NULL_HANDLE && item.Buf == VK_NULL_HANDLE && item.Image == VK_NULL_HANDLE);
++outThreadResult->FailedAllocationCount;
outThreadResult->FailedAllocationTotalSize += item.CalcSizeBytes();
++createFailedCount;
@@ -4568,14 +4698,9 @@ static void TestPool_Benchmark(
// Destroy.
{
PoolDeallocationTimeRegisterObj timeRegisterObj(*outThreadResult);
- if(item.Buf)
- vmaDestroyBuffer(g_hAllocator, item.Buf, item.Alloc);
- else
- vmaDestroyImage(g_hAllocator, item.Image, item.Alloc);
+ item.DestroyResources();
++outThreadResult->DeallocationCount;
}
- item.Alloc = VK_NULL_HANDLE;
- item.Buf = VK_NULL_HANDLE;
++outThreadResult->LostAllocationCount;
outThreadResult->LostAllocationTotalSize += item.CalcSizeBytes();
@@ -4586,6 +4711,7 @@ static void TestPool_Benchmark(
// Creation failed.
if(res != VK_SUCCESS)
{
+ TEST(item.Alloc == VK_NULL_HANDLE && item.Buf == VK_NULL_HANDLE && item.Image == VK_NULL_HANDLE);
++outThreadResult->FailedAllocationCount;
outThreadResult->FailedAllocationTotalSize += item.CalcSizeBytes();
++createFailedCount;
@@ -4612,19 +4738,13 @@ static void TestPool_Benchmark(
for(size_t i = usedItems.size(); i--; )
{
PoolDeallocationTimeRegisterObj timeRegisterObj(*outThreadResult);
- if(usedItems[i].Buf)
- vmaDestroyBuffer(g_hAllocator, usedItems[i].Buf, usedItems[i].Alloc);
- else
- vmaDestroyImage(g_hAllocator, usedItems[i].Image, usedItems[i].Alloc);
+ usedItems[i].DestroyResources();
++outThreadResult->DeallocationCount;
}
for(size_t i = unusedItems.size(); i--; )
{
PoolDeallocationTimeRegisterObj timeRegisterOb(*outThreadResult);
- if(unusedItems[i].Buf)
- vmaDestroyBuffer(g_hAllocator, unusedItems[i].Buf, unusedItems[i].Alloc);
- else
- vmaDestroyImage(g_hAllocator, unusedItems[i].Image, unusedItems[i].Alloc);
+ unusedItems[i].DestroyResources();
++outThreadResult->DeallocationCount;
}
};
@@ -5663,6 +5783,8 @@ static void PerformCustomPoolTest(FILE* file)
static void PerformMainTests(FILE* file)
{
+ wprintf(L"MAIN TESTS:\n");
+
uint32_t repeatCount = 1;
if(ConfigType >= CONFIG_TYPE_MAXIMUM) repeatCount = 3;
@@ -5928,6 +6050,8 @@ static void PerformMainTests(FILE* file)
static void PerformPoolTests(FILE* file)
{
+ wprintf(L"POOL TESTS:\n");
+
const size_t AVG_RESOURCES_PER_POOL = 300;
uint32_t repeatCount = 1;
@@ -6427,8 +6551,10 @@ void Test()
BasicTestBuddyAllocator();
BasicTestAllocatePages();
- if(g_BufferDeviceAddressEnabled)
+ if(VK_KHR_buffer_device_address_enabled)
TestBufferDeviceAddress();
+ if(VK_EXT_memory_priority_enabled)
+ TestMemoryPriority();
{
FILE* file;
@@ -6460,7 +6586,7 @@ void Test()
fclose(file);
- wprintf(L"Done.\n");
+ wprintf(L"Done, all PASSED.\n");
}
#endif // #ifdef _WIN32
diff --git a/third_party/vkmemalloc/src/Tests.h b/third_party/vkmemalloc/src/Tests.h
index d259fa94a0..01cf1a8750 100644
--- a/third_party/vkmemalloc/src/Tests.h
+++ b/third_party/vkmemalloc/src/Tests.h
@@ -1,5 +1,5 @@
//
-// Copyright (c) 2017-2020 Advanced Micro Devices, Inc. All rights reserved.
+// Copyright (c) 2017-2021 Advanced Micro Devices, Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
diff --git a/third_party/vkmemalloc/src/VmaReplay/CMakeLists.txt b/third_party/vkmemalloc/src/VmaReplay/CMakeLists.txt
new file mode 100644
index 0000000000..a53f9c9c79
--- /dev/null
+++ b/third_party/vkmemalloc/src/VmaReplay/CMakeLists.txt
@@ -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()
diff --git a/third_party/vkmemalloc/src/VmaReplay/Common.cpp b/third_party/vkmemalloc/src/VmaReplay/Common.cpp
index b2bedf1865..e7880a9321 100644
--- a/third_party/vkmemalloc/src/VmaReplay/Common.cpp
+++ b/third_party/vkmemalloc/src/VmaReplay/Common.cpp
@@ -1,5 +1,5 @@
//
-// Copyright (c) 2017-2020 Advanced Micro Devices, Inc. All rights reserved.
+// Copyright (c) 2017-2021 Advanced Micro Devices, Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
diff --git a/third_party/vkmemalloc/src/VmaReplay/Common.h b/third_party/vkmemalloc/src/VmaReplay/Common.h
index 3f966c9ea5..e42b47b048 100644
--- a/third_party/vkmemalloc/src/VmaReplay/Common.h
+++ b/third_party/vkmemalloc/src/VmaReplay/Common.h
@@ -1,5 +1,5 @@
//
-// Copyright (c) 2017-2020 Advanced Micro Devices, Inc. All rights reserved.
+// Copyright (c) 2017-2021 Advanced Micro Devices, Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
diff --git a/third_party/vkmemalloc/src/VmaReplay/Constants.cpp b/third_party/vkmemalloc/src/VmaReplay/Constants.cpp
index 28d9c3b783..6d2b15a0ca 100644
--- a/third_party/vkmemalloc/src/VmaReplay/Constants.cpp
+++ b/third_party/vkmemalloc/src/VmaReplay/Constants.cpp
@@ -1,5 +1,5 @@
//
-// Copyright (c) 2017-2020 Advanced Micro Devices, Inc. All rights reserved.
+// Copyright (c) 2017-2021 Advanced Micro Devices, Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
diff --git a/third_party/vkmemalloc/src/VmaReplay/Constants.h b/third_party/vkmemalloc/src/VmaReplay/Constants.h
index 5db0858396..03b76ff90d 100644
--- a/third_party/vkmemalloc/src/VmaReplay/Constants.h
+++ b/third_party/vkmemalloc/src/VmaReplay/Constants.h
@@ -1,5 +1,5 @@
//
-// Copyright (c) 2017-2020 Advanced Micro Devices, Inc. All rights reserved.
+// Copyright (c) 2017-2021 Advanced Micro Devices, Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
diff --git a/third_party/vkmemalloc/src/VmaReplay/VmaReplay.cpp b/third_party/vkmemalloc/src/VmaReplay/VmaReplay.cpp
index 774f070259..d6b23c09f1 100644
--- a/third_party/vkmemalloc/src/VmaReplay/VmaReplay.cpp
+++ b/third_party/vkmemalloc/src/VmaReplay/VmaReplay.cpp
@@ -1,5 +1,5 @@
//
-// Copyright (c) 2018-2020 Advanced Micro Devices, Inc. All rights reserved.
+// Copyright (c) 2018-2021 Advanced Micro Devices, Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -1089,7 +1089,7 @@ private:
Extension_VK_EXT_memory_budget,
Extension_VK_AMD_device_coherent_memory,
Macro_VMA_DEBUG_ALWAYS_DEDICATED_MEMORY,
- Macro_VMA_DEBUG_ALIGNMENT,
+ Macro_VMA_MIN_ALIGNMENT,
Macro_VMA_DEBUG_MARGIN,
Macro_VMA_DEBUG_INITIALIZE_ALLOCATIONS,
Macro_VMA_DEBUG_DETECT_CORRUPTION,
@@ -1237,8 +1237,8 @@ bool ConfigurationParser::Parse(LineSplit& lineSplit)
const StrRange subOptionName = csvSplit.GetRange(1);
if(StrRangeEq(subOptionName, "VMA_DEBUG_ALWAYS_DEDICATED_MEMORY"))
SetOption(currLineNumber, OPTION::Macro_VMA_DEBUG_ALWAYS_DEDICATED_MEMORY, csvSplit.GetRange(2));
- else if(StrRangeEq(subOptionName, "VMA_DEBUG_ALIGNMENT"))
- SetOption(currLineNumber, OPTION::Macro_VMA_DEBUG_ALIGNMENT, csvSplit.GetRange(2));
+ else if(StrRangeEq(subOptionName, "VMA_MIN_ALIGNMENT") || StrRangeEq(subOptionName, "VMA_DEBUG_ALIGNMENT"))
+ SetOption(currLineNumber, OPTION::Macro_VMA_MIN_ALIGNMENT, csvSplit.GetRange(2));
else if(StrRangeEq(subOptionName, "VMA_DEBUG_MARGIN"))
SetOption(currLineNumber, OPTION::Macro_VMA_DEBUG_MARGIN, csvSplit.GetRange(2));
else if(StrRangeEq(subOptionName, "VMA_DEBUG_INITIALIZE_ALLOCATIONS"))
@@ -3683,7 +3683,8 @@ void Player::ExecuteResizeAllocation(size_t lineNumber, const CsvSplit& csvSplit
const auto it = m_Allocations.find(origPtr);
if(it != m_Allocations.end())
{
- vmaResizeAllocation(m_Allocator, it->second.allocation, newSize);
+ // Do nothing - the function was deprecated and has been removed.
+ //vmaResizeAllocation(m_Allocator, it->second.allocation, newSize);
UpdateMemStats();
}
else
diff --git a/third_party/vkmemalloc/src/VmaReplay/VmaUsage.cpp b/third_party/vkmemalloc/src/VmaReplay/VmaUsage.cpp
index 20555a4d69..6353bcf7ca 100644
--- a/third_party/vkmemalloc/src/VmaReplay/VmaUsage.cpp
+++ b/third_party/vkmemalloc/src/VmaReplay/VmaUsage.cpp
@@ -1,5 +1,5 @@
//
-// Copyright (c) 2017-2020 Advanced Micro Devices, Inc. All rights reserved.
+// Copyright (c) 2017-2021 Advanced Micro Devices, Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
diff --git a/third_party/vkmemalloc/src/VmaReplay/VmaUsage.h b/third_party/vkmemalloc/src/VmaReplay/VmaUsage.h
index 5c1b4815db..22ba27e420 100644
--- a/third_party/vkmemalloc/src/VmaReplay/VmaUsage.h
+++ b/third_party/vkmemalloc/src/VmaReplay/VmaUsage.h
@@ -1,5 +1,5 @@
//
-// Copyright (c) 2017-2020 Advanced Micro Devices, Inc. All rights reserved.
+// Copyright (c) 2017-2021 Advanced Micro Devices, Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -45,6 +45,6 @@
#pragma warning(disable: 4189) // local variable is initialized but not referenced
#pragma warning(disable: 4324) // structure was padded due to alignment specifier
-#include "../vk_mem_alloc.h"
+#include "../../include/vk_mem_alloc.h"
#pragma warning(pop)
diff --git a/third_party/vkmemalloc/src/VmaUsage.cpp b/third_party/vkmemalloc/src/VmaUsage.cpp
index 5dc0ded2ee..cd2d783b42 100644
--- a/third_party/vkmemalloc/src/VmaUsage.cpp
+++ b/third_party/vkmemalloc/src/VmaUsage.cpp
@@ -1,5 +1,5 @@
//
-// Copyright (c) 2017-2020 Advanced Micro Devices, Inc. All rights reserved.
+// Copyright (c) 2017-2021 Advanced Micro Devices, Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
diff --git a/third_party/vkmemalloc/src/VmaUsage.h b/third_party/vkmemalloc/src/VmaUsage.h
index 59df6c3f06..52c0513e8b 100644
--- a/third_party/vkmemalloc/src/VmaUsage.h
+++ b/third_party/vkmemalloc/src/VmaUsage.h
@@ -1,5 +1,5 @@
//
-// Copyright (c) 2017-2020 Advanced Micro Devices, Inc. All rights reserved.
+// Copyright (c) 2017-2021 Advanced Micro Devices, Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -48,21 +48,15 @@ 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
+#define VMA_VULKAN_VERSION 1002000 // Vulkan 1.2
+//#define VMA_VULKAN_VERSION 1001000 // Vulkan 1.1
//#define VMA_VULKAN_VERSION 1000000 // Vulkan 1.0
/*
@@ -89,7 +83,7 @@ include all public interface declarations. Example:
#pragma clang diagnostic ignored "-Wnullability-completeness"
#endif
-#include "vk_mem_alloc.h"
+#include "../include/vk_mem_alloc.h"
#ifdef __clang__
#pragma clang diagnostic pop
diff --git a/third_party/vkmemalloc/src/VulkanSample.cpp b/third_party/vkmemalloc/src/VulkanSample.cpp
index 1c31f0795d..0d07cfbb1a 100644
--- a/third_party/vkmemalloc/src/VulkanSample.cpp
+++ b/third_party/vkmemalloc/src/VulkanSample.cpp
@@ -1,5 +1,5 @@
//
-// Copyright (c) 2017-2020 Advanced Micro Devices, Inc. All rights reserved.
+// Copyright (c) 2017-2021 Advanced Micro Devices, Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -27,6 +27,9 @@
#include "VmaUsage.h"
#include "Common.h"
#include
+#include
+
+#pragma comment(lib, "shlwapi.lib")
static const char* const SHADER_PATH1 = "./";
static const char* const SHADER_PATH2 = "../bin/";
@@ -40,6 +43,15 @@ static const uint32_t COMMAND_BUFFER_COUNT = 2;
static void* const CUSTOM_CPU_ALLOCATION_CALLBACK_USER_DATA = (void*)(intptr_t)43564544;
static const bool USE_CUSTOM_CPU_ALLOCATION_CALLBACKS = true;
+enum class ExitCode : int
+{
+ GPUList = 2,
+ Help = 1,
+ Success = 0,
+ RuntimeError = -1,
+ CommandLineError = -2,
+};
+
VkPhysicalDevice g_hPhysicalDevice;
VkDevice g_hDevice;
VmaAllocator g_hAllocator;
@@ -52,14 +64,13 @@ bool VK_KHR_dedicated_allocation_enabled = false;
bool VK_KHR_bind_memory2_enabled = false;
bool VK_EXT_memory_budget_enabled = false;
bool VK_AMD_device_coherent_memory_enabled = false;
-bool VK_EXT_buffer_device_address_enabled = false;
bool VK_KHR_buffer_device_address_enabled = false;
+bool VK_EXT_memory_priority_enabled = false;
bool VK_EXT_debug_utils_enabled = false;
bool g_SparseBindingEnabled = false;
-bool g_BufferDeviceAddressEnabled = false;
// # Pointers to functions from extensions
-PFN_vkGetBufferDeviceAddressEXT g_vkGetBufferDeviceAddressEXT;
+PFN_vkGetBufferDeviceAddressKHR g_vkGetBufferDeviceAddressKHR;
static HINSTANCE g_hAppInstance;
static HWND g_hWnd;
@@ -106,7 +117,7 @@ static const VkDebugUtilsMessageTypeFlagsEXT DEBUG_UTILS_MESSENGER_MESSAGE_TYPE
VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT;
static PFN_vkCreateDebugUtilsMessengerEXT vkCreateDebugUtilsMessengerEXT_Func;
static PFN_vkDestroyDebugUtilsMessengerEXT vkDestroyDebugUtilsMessengerEXT_Func;
-static VkDebugUtilsMessengerEXT g_DebugUtilsMessenger;
+static PFN_vkSetDebugUtilsObjectNameEXT vkSetDebugUtilsObjectNameEXT_Func;
static VkQueue g_hGraphicsQueue;
VkQueue g_hSparseBindingQueue;
@@ -179,6 +190,75 @@ static const VkAllocationCallbacks g_CpuAllocationCallbacks = {
const VkAllocationCallbacks* g_Allocs;
+struct GPUSelection
+{
+ uint32_t Index = UINT32_MAX;
+ std::wstring Substring;
+};
+
+class VulkanUsage
+{
+public:
+ void Init();
+ ~VulkanUsage();
+ void PrintPhysicalDeviceList() const;
+ // If failed, returns VK_NULL_HANDLE.
+ VkPhysicalDevice SelectPhysicalDevice(const GPUSelection& GPUSelection) const;
+
+private:
+ VkDebugUtilsMessengerEXT m_DebugUtilsMessenger = VK_NULL_HANDLE;
+
+ void RegisterDebugCallbacks();
+ static bool IsLayerSupported(const VkLayerProperties* pProps, size_t propCount, const char* pLayerName);
+};
+
+struct CommandLineParameters
+{
+ bool m_Help = false;
+ bool m_List = false;
+ GPUSelection m_GPUSelection;
+
+ bool Parse(int argc, wchar_t** argv)
+ {
+ for(int i = 1; i < argc; ++i)
+ {
+ if(_wcsicmp(argv[i], L"-h") == 0 || _wcsicmp(argv[i], L"--Help") == 0)
+ {
+ m_Help = true;
+ }
+ else if(_wcsicmp(argv[i], L"-l") == 0 || _wcsicmp(argv[i], L"--List") == 0)
+ {
+ m_List = true;
+ }
+ else if((_wcsicmp(argv[i], L"-g") == 0 || _wcsicmp(argv[i], L"--GPU") == 0) && i + 1 < argc)
+ {
+ m_GPUSelection.Substring = argv[i + 1];
+ ++i;
+ }
+ else if((_wcsicmp(argv[i], L"-i") == 0 || _wcsicmp(argv[i], L"--GPUIndex") == 0) && i + 1 < argc)
+ {
+ m_GPUSelection.Index = _wtoi(argv[i + 1]);
+ ++i;
+ }
+ else
+ return false;
+ }
+ return true;
+ }
+} g_CommandLineParameters;
+
+void SetDebugUtilsObjectName(VkObjectType type, uint64_t handle, const char* name)
+{
+ if(vkSetDebugUtilsObjectNameEXT_Func == nullptr)
+ return;
+
+ VkDebugUtilsObjectNameInfoEXT info = { VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT };
+ info.objectType = type;
+ info.objectHandle = handle;
+ info.pObjectName = name;
+ vkSetDebugUtilsObjectNameEXT_Func(g_hDevice, &info);
+}
+
void BeginSingleTimeCommands()
{
VkCommandBufferBeginInfo cmdBufBeginInfo = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO };
@@ -301,6 +381,223 @@ static VkExtent2D ChooseSwapExtent()
return result;
}
+static constexpr uint32_t GetVulkanApiVersion()
+{
+#if VMA_VULKAN_VERSION == 1002000
+ return VK_API_VERSION_1_2;
+#elif VMA_VULKAN_VERSION == 1001000
+ return VK_API_VERSION_1_1;
+#elif VMA_VULKAN_VERSION == 1000000
+ return VK_API_VERSION_1_0;
+#else
+#error Invalid VMA_VULKAN_VERSION.
+ return UINT32_MAX;
+#endif
+}
+
+void VulkanUsage::Init()
+{
+ g_hAppInstance = (HINSTANCE)GetModuleHandle(NULL);
+
+ if(USE_CUSTOM_CPU_ALLOCATION_CALLBACKS)
+ {
+ g_Allocs = &g_CpuAllocationCallbacks;
+ }
+
+ uint32_t instanceLayerPropCount = 0;
+ ERR_GUARD_VULKAN( vkEnumerateInstanceLayerProperties(&instanceLayerPropCount, nullptr) );
+ std::vector instanceLayerProps(instanceLayerPropCount);
+ if(instanceLayerPropCount > 0)
+ {
+ ERR_GUARD_VULKAN( vkEnumerateInstanceLayerProperties(&instanceLayerPropCount, instanceLayerProps.data()) );
+ }
+
+ if(g_EnableValidationLayer)
+ {
+ if(IsLayerSupported(instanceLayerProps.data(), instanceLayerProps.size(), VALIDATION_LAYER_NAME) == false)
+ {
+ wprintf(L"Layer \"%hs\" not supported.", VALIDATION_LAYER_NAME);
+ g_EnableValidationLayer = false;
+ }
+ }
+
+ uint32_t availableInstanceExtensionCount = 0;
+ ERR_GUARD_VULKAN( vkEnumerateInstanceExtensionProperties(nullptr, &availableInstanceExtensionCount, nullptr) );
+ std::vector availableInstanceExtensions(availableInstanceExtensionCount);
+ if(availableInstanceExtensionCount > 0)
+ {
+ ERR_GUARD_VULKAN( vkEnumerateInstanceExtensionProperties(nullptr, &availableInstanceExtensionCount, availableInstanceExtensions.data()) );
+ }
+
+ std::vector enabledInstanceExtensions;
+ enabledInstanceExtensions.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
+ enabledInstanceExtensions.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
+
+ std::vector instanceLayers;
+ if(g_EnableValidationLayer)
+ {
+ instanceLayers.push_back(VALIDATION_LAYER_NAME);
+ }
+
+ for(const auto& extensionProperties : availableInstanceExtensions)
+ {
+ if(strcmp(extensionProperties.extensionName, VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME) == 0)
+ {
+ if(GetVulkanApiVersion() == VK_API_VERSION_1_0)
+ {
+ enabledInstanceExtensions.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
+ VK_KHR_get_physical_device_properties2_enabled = true;
+ }
+ }
+ else if(strcmp(extensionProperties.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME) == 0)
+ {
+ enabledInstanceExtensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
+ VK_EXT_debug_utils_enabled = true;
+ }
+ }
+
+ VkApplicationInfo appInfo = { VK_STRUCTURE_TYPE_APPLICATION_INFO };
+ appInfo.pApplicationName = APP_TITLE_A;
+ appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
+ appInfo.pEngineName = "Adam Sawicki Engine";
+ appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0);
+ appInfo.apiVersion = GetVulkanApiVersion();
+
+ VkInstanceCreateInfo instInfo = { VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO };
+ instInfo.pApplicationInfo = &appInfo;
+ instInfo.enabledExtensionCount = static_cast(enabledInstanceExtensions.size());
+ instInfo.ppEnabledExtensionNames = enabledInstanceExtensions.data();
+ instInfo.enabledLayerCount = static_cast(instanceLayers.size());
+ instInfo.ppEnabledLayerNames = instanceLayers.data();
+
+ wprintf(L"Vulkan API version used: ");
+ switch(appInfo.apiVersion)
+ {
+ case VK_API_VERSION_1_0: wprintf(L"1.0\n"); break;
+ case VK_API_VERSION_1_1: wprintf(L"1.1\n"); break;
+ case VK_API_VERSION_1_2: wprintf(L"1.2\n"); break;
+ default: assert(0);
+ }
+
+ ERR_GUARD_VULKAN( vkCreateInstance(&instInfo, g_Allocs, &g_hVulkanInstance) );
+
+ if(VK_EXT_debug_utils_enabled)
+ {
+ RegisterDebugCallbacks();
+ }
+}
+
+VulkanUsage::~VulkanUsage()
+{
+ if(m_DebugUtilsMessenger)
+ {
+ vkDestroyDebugUtilsMessengerEXT_Func(g_hVulkanInstance, m_DebugUtilsMessenger, g_Allocs);
+ }
+
+ if(g_hVulkanInstance)
+ {
+ vkDestroyInstance(g_hVulkanInstance, g_Allocs);
+ g_hVulkanInstance = VK_NULL_HANDLE;
+ }
+}
+
+void VulkanUsage::PrintPhysicalDeviceList() const
+{
+ uint32_t deviceCount = 0;
+ ERR_GUARD_VULKAN(vkEnumeratePhysicalDevices(g_hVulkanInstance, &deviceCount, nullptr));
+ std::vector physicalDevices(deviceCount);
+ if(deviceCount > 0)
+ {
+ ERR_GUARD_VULKAN(vkEnumeratePhysicalDevices(g_hVulkanInstance, &deviceCount, physicalDevices.data()));
+ }
+
+ for(size_t i = 0; i < deviceCount; ++i)
+ {
+ VkPhysicalDeviceProperties props = {};
+ vkGetPhysicalDeviceProperties(physicalDevices[i], &props);
+ wprintf(L"Physical device %zu: %hs\n", i, props.deviceName);
+ }
+}
+
+VkPhysicalDevice VulkanUsage::SelectPhysicalDevice(const GPUSelection& GPUSelection) const
+{
+ uint32_t deviceCount = 0;
+ ERR_GUARD_VULKAN(vkEnumeratePhysicalDevices(g_hVulkanInstance, &deviceCount, nullptr));
+ std::vector physicalDevices(deviceCount);
+ if(deviceCount > 0)
+ {
+ ERR_GUARD_VULKAN(vkEnumeratePhysicalDevices(g_hVulkanInstance, &deviceCount, physicalDevices.data()));
+ }
+
+ if(GPUSelection.Index != UINT32_MAX)
+ {
+ // Cannot specify both index and name.
+ if(!GPUSelection.Substring.empty())
+ {
+ return VK_NULL_HANDLE;
+ }
+
+ return GPUSelection.Index < deviceCount ? physicalDevices[GPUSelection.Index] : VK_NULL_HANDLE;
+ }
+
+ if(!GPUSelection.Substring.empty())
+ {
+ VkPhysicalDevice result = VK_NULL_HANDLE;
+ std::wstring name;
+ for(uint32_t i = 0; i < deviceCount; ++i)
+ {
+ VkPhysicalDeviceProperties props = {};
+ vkGetPhysicalDeviceProperties(physicalDevices[i], &props);
+ if(ConvertCharsToUnicode(&name, props.deviceName, strlen(props.deviceName), CP_UTF8) &&
+ StrStrI(name.c_str(), GPUSelection.Substring.c_str()))
+ {
+ // Second matching device found - error.
+ if(result != VK_NULL_HANDLE)
+ {
+ return VK_NULL_HANDLE;
+ }
+ // First matching device found.
+ result = physicalDevices[i];
+ }
+ }
+ // Found or not, return it.
+ return result;
+ }
+
+ // Select first one.
+ return deviceCount > 0 ? physicalDevices[0] : VK_NULL_HANDLE;
+}
+
+void VulkanUsage::RegisterDebugCallbacks()
+{
+ vkCreateDebugUtilsMessengerEXT_Func = (PFN_vkCreateDebugUtilsMessengerEXT)vkGetInstanceProcAddr(
+ g_hVulkanInstance, "vkCreateDebugUtilsMessengerEXT");
+ vkDestroyDebugUtilsMessengerEXT_Func = (PFN_vkDestroyDebugUtilsMessengerEXT)vkGetInstanceProcAddr(
+ g_hVulkanInstance, "vkDestroyDebugUtilsMessengerEXT");
+ vkSetDebugUtilsObjectNameEXT_Func = (PFN_vkSetDebugUtilsObjectNameEXT)vkGetInstanceProcAddr(
+ g_hVulkanInstance, "vkSetDebugUtilsObjectNameEXT");
+ assert(vkCreateDebugUtilsMessengerEXT_Func);
+ assert(vkDestroyDebugUtilsMessengerEXT_Func);
+ assert(vkSetDebugUtilsObjectNameEXT_Func);
+
+ VkDebugUtilsMessengerCreateInfoEXT messengerCreateInfo = { VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT };
+ messengerCreateInfo.messageSeverity = DEBUG_UTILS_MESSENGER_MESSAGE_SEVERITY;
+ messengerCreateInfo.messageType = DEBUG_UTILS_MESSENGER_MESSAGE_TYPE;
+ messengerCreateInfo.pfnUserCallback = MyDebugReportCallback;
+ ERR_GUARD_VULKAN( vkCreateDebugUtilsMessengerEXT_Func(g_hVulkanInstance, &messengerCreateInfo, g_Allocs, &m_DebugUtilsMessenger) );
+}
+
+bool VulkanUsage::IsLayerSupported(const VkLayerProperties* pProps, size_t propCount, const char* pLayerName)
+{
+ const VkLayerProperties* propsEnd = pProps + propCount;
+ return std::find_if(
+ pProps,
+ propsEnd,
+ [pLayerName](const VkLayerProperties& prop) -> bool {
+ return strcmp(pLayerName, prop.layerName) == 0;
+ }) != propsEnd;
+}
+
struct Vertex
{
float pos[3];
@@ -563,41 +860,6 @@ struct UniformBufferObject
mat4 ModelViewProj;
};
-static void RegisterDebugCallbacks()
-{
- vkCreateDebugUtilsMessengerEXT_Func = (PFN_vkCreateDebugUtilsMessengerEXT)vkGetInstanceProcAddr(
- g_hVulkanInstance, "vkCreateDebugUtilsMessengerEXT");
- vkDestroyDebugUtilsMessengerEXT_Func = (PFN_vkDestroyDebugUtilsMessengerEXT)vkGetInstanceProcAddr(
- g_hVulkanInstance, "vkDestroyDebugUtilsMessengerEXT");
- assert(vkCreateDebugUtilsMessengerEXT_Func);
- assert(vkDestroyDebugUtilsMessengerEXT_Func);
-
- VkDebugUtilsMessengerCreateInfoEXT messengerCreateInfo = { VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT };
- messengerCreateInfo.messageSeverity = DEBUG_UTILS_MESSENGER_MESSAGE_SEVERITY;
- messengerCreateInfo.messageType = DEBUG_UTILS_MESSENGER_MESSAGE_TYPE;
- messengerCreateInfo.pfnUserCallback = MyDebugReportCallback;
- ERR_GUARD_VULKAN( vkCreateDebugUtilsMessengerEXT_Func(g_hVulkanInstance, &messengerCreateInfo, g_Allocs, &g_DebugUtilsMessenger) );
-}
-
-static void UnregisterDebugCallbacks()
-{
- if(g_DebugUtilsMessenger)
- {
- vkDestroyDebugUtilsMessengerEXT_Func(g_hVulkanInstance, g_DebugUtilsMessenger, g_Allocs);
- }
-}
-
-static bool IsLayerSupported(const VkLayerProperties* pProps, size_t propCount, const char* pLayerName)
-{
- const VkLayerProperties* propsEnd = pProps + propCount;
- return std::find_if(
- pProps,
- propsEnd,
- [pLayerName](const VkLayerProperties& prop) -> bool {
- return strcmp(pLayerName, prop.layerName) == 0;
- }) != propsEnd;
-}
-
static VkFormat FindSupportedFormat(
const std::vector& candidates,
VkImageTiling tiling,
@@ -1095,25 +1357,11 @@ static void DestroySwapchain(bool destroyActualSwapchain)
}
}
-static constexpr uint32_t GetVulkanApiVersion()
-{
-#if VMA_VULKAN_VERSION == 1002000
- return VK_API_VERSION_1_2;
-#elif VMA_VULKAN_VERSION == 1001000
- return VK_API_VERSION_1_1;
-#elif VMA_VULKAN_VERSION == 1000000
- return VK_API_VERSION_1_0;
-#else
- #error Invalid VMA_VULKAN_VERSION.
- return UINT32_MAX;
-#endif
-}
-
static void PrintEnabledFeatures()
{
+ wprintf(L"Enabled extensions and features:\n");
wprintf(L"Validation layer: %d\n", g_EnableValidationLayer ? 1 : 0);
wprintf(L"Sparse binding: %d\n", g_SparseBindingEnabled ? 1 : 0);
- wprintf(L"Buffer device address: %d\n", g_BufferDeviceAddressEnabled ? 1 : 0);
if(GetVulkanApiVersion() == VK_API_VERSION_1_0)
{
wprintf(L"VK_KHR_get_memory_requirements2: %d\n", VK_KHR_get_memory_requirements2_enabled ? 1 : 0);
@@ -1123,8 +1371,15 @@ static void PrintEnabledFeatures()
}
wprintf(L"VK_EXT_memory_budget: %d\n", VK_EXT_memory_budget_enabled ? 1 : 0);
wprintf(L"VK_AMD_device_coherent_memory: %d\n", VK_AMD_device_coherent_memory_enabled ? 1 : 0);
- wprintf(L"VK_KHR_buffer_device_address: %d\n", VK_KHR_buffer_device_address_enabled ? 1 : 0);
- wprintf(L"VK_EXT_buffer_device_address: %d\n", VK_EXT_buffer_device_address_enabled ? 1 : 0);
+ if(GetVulkanApiVersion() < VK_API_VERSION_1_2)
+ {
+ wprintf(L"VK_KHR_buffer_device_address: %d\n", VK_KHR_buffer_device_address_enabled ? 1 : 0);
+ }
+ else
+ {
+ wprintf(L"bufferDeviceAddress: %d\n", VK_KHR_buffer_device_address_enabled ? 1 : 0);
+ }
+ wprintf(L"VK_EXT_memory_priority: %d\n", VK_EXT_memory_priority ? 1 : 0);
}
void SetAllocatorCreateInfo(VmaAllocatorCreateInfo& outInfo)
@@ -1155,10 +1410,16 @@ void SetAllocatorCreateInfo(VmaAllocatorCreateInfo& outInfo)
{
outInfo.flags |= VMA_ALLOCATOR_CREATE_AMD_DEVICE_COHERENT_MEMORY_BIT;
}
- if(g_BufferDeviceAddressEnabled)
+ if(VK_KHR_buffer_device_address_enabled)
{
outInfo.flags |= VMA_ALLOCATOR_CREATE_BUFFER_DEVICE_ADDRESS_BIT;
}
+#if !defined(VMA_MEMORY_PRIORITY) || VMA_MEMORY_PRIORITY == 1
+ if(VK_EXT_memory_priority_enabled)
+ {
+ outInfo.flags |= VMA_ALLOCATOR_CREATE_EXT_MEMORY_PRIORITY_BIT;
+ }
+#endif
if(USE_CUSTOM_CPU_ALLOCATION_CALLBACKS)
{
@@ -1183,103 +1444,317 @@ void SetAllocatorCreateInfo(VmaAllocatorCreateInfo& outInfo)
static void PrintPhysicalDeviceProperties(const VkPhysicalDeviceProperties& properties)
{
- wprintf(L"Physical device:\n");
- wprintf(L" Driver version: 0x%X\n", properties.driverVersion);
- wprintf(L" Vendor ID: 0x%X\n", properties.vendorID);
- wprintf(L" Device ID: 0x%X\n", properties.deviceID);
- wprintf(L" Device type: %u\n", properties.deviceType);
- wprintf(L" Device name: %hs\n", properties.deviceName);
+ wprintf(L"physicalDeviceProperties:\n");
+ wprintf(L" driverVersion: 0x%X\n", properties.driverVersion);
+ wprintf(L" vendorID: 0x%X (%s)\n", properties.vendorID, VendorIDToStr(properties.vendorID));
+ wprintf(L" deviceID: 0x%X\n", properties.deviceID);
+ wprintf(L" deviceType: %u (%s)\n", properties.deviceType, PhysicalDeviceTypeToStr(properties.deviceType));
+ wprintf(L" deviceName: %hs\n", properties.deviceName);
+ wprintf(L" limits:\n");
+ wprintf(L" maxMemoryAllocationCount: %u\n", properties.limits.maxMemoryAllocationCount);
+ wprintf(L" bufferImageGranularity: %llu B\n", properties.limits.bufferImageGranularity);
+ wprintf(L" nonCoherentAtomSize: %llu B\n", properties.limits.nonCoherentAtomSize);
+}
+
+#if VMA_VULKAN_VERSION >= 1002000
+static void PrintPhysicalDeviceVulkan11Properties(const VkPhysicalDeviceVulkan11Properties& properties)
+{
+ wprintf(L"physicalDeviceVulkan11Properties:\n");
+ std::wstring sizeStr = SizeToStr(properties.maxMemoryAllocationSize);
+ wprintf(L" maxMemoryAllocationSize: %llu B (%s)\n", properties.maxMemoryAllocationSize, sizeStr.c_str());
+}
+static void PrintPhysicalDeviceVulkan12Properties(const VkPhysicalDeviceVulkan12Properties& properties)
+{
+ wprintf(L"physicalDeviceVulkan12Properties:\n");
+ std::wstring str = DriverIDToStr(properties.driverID);
+ wprintf(L" driverID: %u (%s)\n", properties.driverID, str.c_str());
+ wprintf(L" driverName: %hs\n", properties.driverName);
+ wprintf(L" driverInfo: %hs\n", properties.driverInfo);
+}
+#endif // #if VMA_VULKAN_VERSION > 1002000
+
+static void AddFlagToStr(std::wstring& inout, const wchar_t* flagStr)
+{
+ if(!inout.empty())
+ inout += L", ";
+ inout += flagStr;
+}
+
+static std::wstring HeapFlagsToStr(VkMemoryHeapFlags flags)
+{
+ std::wstring result;
+ if(flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT)
+ AddFlagToStr(result, L"DEVICE_LOCAL");
+ if(flags & VK_MEMORY_HEAP_MULTI_INSTANCE_BIT)
+ AddFlagToStr(result, L"MULTI_INSTANCE");
+ return result;
+}
+
+static std::wstring PropertyFlagsToStr(VkMemoryPropertyFlags flags)
+{
+ std::wstring result;
+ if(flags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)
+ AddFlagToStr(result, L"DEVICE_LOCAL");
+ if(flags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)
+ AddFlagToStr(result, L"HOST_VISIBLE");
+ if(flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)
+ AddFlagToStr(result, L"HOST_COHERENT");
+ if(flags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT)
+ AddFlagToStr(result, L"HOST_CACHED");
+ if(flags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT)
+ AddFlagToStr(result, L"LAZILY_ALLOCATED");
+
+#if VMA_VULKAN_VERSION >= 1001000
+ if(flags & VK_MEMORY_PROPERTY_PROTECTED_BIT)
+ AddFlagToStr(result, L"PROTECTED");
+#endif
+
+#if VK_AMD_device_coherent_memory
+ if(flags & VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD)
+ AddFlagToStr(result, L"DEVICE_COHERENT (AMD)");
+ if(flags & VK_MEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMD)
+ AddFlagToStr(result, L"DEVICE_UNCACHED (AMD)");
+#endif
+
+ return result;
+}
+
+static void PrintMemoryTypes()
+{
+ wprintf(L"MEMORY HEAPS:\n");
+ const VkPhysicalDeviceMemoryProperties* memProps = nullptr;
+ vmaGetMemoryProperties(g_hAllocator, &memProps);
+
+ wprintf(L"heapCount=%u, typeCount=%u\n", memProps->memoryHeapCount, memProps->memoryTypeCount);
+
+ std::wstring sizeStr, flagsStr;
+ for(uint32_t heapIndex = 0; heapIndex < memProps->memoryHeapCount; ++heapIndex)
+ {
+ const VkMemoryHeap& heap = memProps->memoryHeaps[heapIndex];
+ sizeStr = SizeToStr(heap.size);
+ flagsStr = HeapFlagsToStr(heap.flags);
+ wprintf(L"Heap %u: %llu B (%s) %s\n", heapIndex, heap.size, sizeStr.c_str(), flagsStr.c_str());
+
+ for(uint32_t typeIndex = 0; typeIndex < memProps->memoryTypeCount; ++typeIndex)
+ {
+ const VkMemoryType& type = memProps->memoryTypes[typeIndex];
+ if(type.heapIndex == heapIndex)
+ {
+ flagsStr = PropertyFlagsToStr(type.propertyFlags);
+ wprintf(L" Type %u: %s\n", typeIndex, flagsStr.c_str());
+ }
+ }
+ }
+}
+
+#if 0
+template
+inline VkDeviceSize MapSum(It beg, It end, MapFunc mapFunc)
+{
+ VkDeviceSize result = 0;
+ for(It it = beg; it != end; ++it)
+ result += mapFunc(*it);
+ return result;
+}
+#endif
+
+static bool CanCreateVertexBuffer(uint32_t allowedMemoryTypeBits)
+{
+ VkBufferCreateInfo bufCreateInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
+ bufCreateInfo.size = 0x10000;
+ bufCreateInfo.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
+
+ VkBuffer buf = VK_NULL_HANDLE;
+ VkResult res = vkCreateBuffer(g_hDevice, &bufCreateInfo, g_Allocs, &buf);
+ assert(res == VK_SUCCESS);
+
+ VkMemoryRequirements memReq = {};
+ vkGetBufferMemoryRequirements(g_hDevice, buf, &memReq);
+
+ vkDestroyBuffer(g_hDevice, buf, g_Allocs);
+
+ return (memReq.memoryTypeBits & allowedMemoryTypeBits) != 0;
+}
+
+static bool CanCreateOptimalSampledImage(uint32_t allowedMemoryTypeBits)
+{
+ VkImageCreateInfo imgCreateInfo = { VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO };
+ imgCreateInfo.imageType = VK_IMAGE_TYPE_2D;
+ imgCreateInfo.extent.width = 256;
+ imgCreateInfo.extent.height = 256;
+ imgCreateInfo.extent.depth = 1;
+ imgCreateInfo.mipLevels = 1;
+ imgCreateInfo.arrayLayers = 1;
+ imgCreateInfo.format = VK_FORMAT_R8G8B8A8_UNORM;
+ imgCreateInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
+ imgCreateInfo.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
+ imgCreateInfo.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
+ imgCreateInfo.samples = VK_SAMPLE_COUNT_1_BIT;
+
+ VkImage img = VK_NULL_HANDLE;
+ VkResult res = vkCreateImage(g_hDevice, &imgCreateInfo, g_Allocs, &img);
+ assert(res == VK_SUCCESS);
+
+ VkMemoryRequirements memReq = {};
+ vkGetImageMemoryRequirements(g_hDevice, img, &memReq);
+
+ vkDestroyImage(g_hDevice, img, g_Allocs);
+
+ return (memReq.memoryTypeBits & allowedMemoryTypeBits) != 0;
+}
+
+static void PrintMemoryConclusions()
+{
+ wprintf(L"Conclusions:\n");
+
+ const VkPhysicalDeviceProperties* props = nullptr;
+ const VkPhysicalDeviceMemoryProperties* memProps = nullptr;
+ vmaGetPhysicalDeviceProperties(g_hAllocator, &props);
+ vmaGetMemoryProperties(g_hAllocator, &memProps);
+
+ const uint32_t heapCount = memProps->memoryHeapCount;
+
+ uint32_t deviceLocalHeapCount = 0;
+ uint32_t hostVisibleHeapCount = 0;
+ uint32_t deviceLocalAndHostVisibleHeapCount = 0;
+ VkDeviceSize deviceLocalHeapSumSize = 0;
+ VkDeviceSize hostVisibleHeapSumSize = 0;
+ VkDeviceSize deviceLocalAndHostVisibleHeapSumSize = 0;
+
+ for(uint32_t heapIndex = 0; heapIndex < heapCount; ++heapIndex)
+ {
+ const VkMemoryHeap& heap = memProps->memoryHeaps[heapIndex];
+ const bool isDeviceLocal = (heap.flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) != 0;
+ bool isHostVisible = false;
+ for(uint32_t typeIndex = 0; typeIndex < memProps->memoryTypeCount; ++typeIndex)
+ {
+ const VkMemoryType& type = memProps->memoryTypes[typeIndex];
+ if(type.heapIndex == heapIndex && (type.propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT))
+ {
+ isHostVisible = true;
+ break;
+ }
+ }
+ if(isDeviceLocal)
+ {
+ ++deviceLocalHeapCount;
+ deviceLocalHeapSumSize += heap.size;
+ }
+ if(isHostVisible)
+ {
+ ++hostVisibleHeapCount;
+ hostVisibleHeapSumSize += heap.size;
+ if(isDeviceLocal)
+ {
+ ++deviceLocalAndHostVisibleHeapCount;
+ deviceLocalAndHostVisibleHeapSumSize += heap.size;
+ }
+ }
+ }
+
+ uint32_t hostVisibleNotHostCoherentTypeCount = 0;
+ uint32_t notDeviceLocalNotHostVisibleTypeCount = 0;
+ uint32_t amdSpecificTypeCount = 0;
+ uint32_t lazilyAllocatedTypeCount = 0;
+ uint32_t allTypeBits = 0;
+ uint32_t deviceLocalTypeBits = 0;
+ for(uint32_t typeIndex = 0; typeIndex < memProps->memoryTypeCount; ++typeIndex)
+ {
+ const VkMemoryType& type = memProps->memoryTypes[typeIndex];
+ allTypeBits |= 1u << typeIndex;
+ if(type.propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)
+ {
+ deviceLocalTypeBits |= 1u << typeIndex;
+ }
+ if((type.propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) &&
+ (type.propertyFlags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) == 0)
+ {
+ ++hostVisibleNotHostCoherentTypeCount;
+ }
+ if((type.propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) == 0 &&
+ (type.propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == 0)
+ {
+ ++notDeviceLocalNotHostVisibleTypeCount;
+ }
+ if(type.propertyFlags & (VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD | VK_MEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMD))
+ {
+ ++amdSpecificTypeCount;
+ }
+ if(type.propertyFlags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT)
+ {
+ ++lazilyAllocatedTypeCount;
+ }
+ }
+
+ assert(deviceLocalHeapCount > 0);
+ if(deviceLocalHeapCount == heapCount)
+ wprintf(L"- All heaps are DEVICE_LOCAL.\n");
+ else
+ wprintf(L"- %u heaps are DEVICE_LOCAL, total %s.\n", deviceLocalHeapCount, SizeToStr(deviceLocalHeapSumSize).c_str());
+
+ assert(hostVisibleHeapCount > 0);
+ if(hostVisibleHeapCount == heapCount)
+ wprintf(L"- All heaps are HOST_VISIBLE.\n");
+ else
+ wprintf(L"- %u heaps are HOST_VISIBLE, total %s.\n", deviceLocalHeapCount, SizeToStr(hostVisibleHeapSumSize).c_str());
+
+ if(deviceLocalHeapCount < heapCount && hostVisibleHeapCount < heapCount)
+ {
+ if(deviceLocalAndHostVisibleHeapCount == 0)
+ wprintf(L"- No heaps are DEVICE_LOCAL and HOST_VISIBLE.\n");
+ if(deviceLocalAndHostVisibleHeapCount == heapCount)
+ wprintf(L"- All heaps are DEVICE_LOCAL and HOST_VISIBLE.\n");
+ else
+ wprintf(L"- %u heaps are DEVICE_LOCAL and HOST_VISIBLE, total %s.\n", deviceLocalAndHostVisibleHeapCount, SizeToStr(deviceLocalAndHostVisibleHeapSumSize).c_str());
+ }
+
+ if(hostVisibleNotHostCoherentTypeCount == 0)
+ wprintf(L"- No types are HOST_VISIBLE but not HOST_COHERENT.\n");
+ else
+ wprintf(L"- %u types are HOST_VISIBLE but not HOST_COHERENT.\n", hostVisibleNotHostCoherentTypeCount);
+
+ if(notDeviceLocalNotHostVisibleTypeCount == 0)
+ wprintf(L"- No types are not DEVICE_LOCAL and not HOST_VISIBLE.\n");
+ else
+ wprintf(L"- %u types are not DEVICE_LOCAL and not HOST_VISIBLE.\n", notDeviceLocalNotHostVisibleTypeCount);
+
+ if(amdSpecificTypeCount == 0)
+ wprintf(L"- No types are AMD-specific DEVICE_COHERENT or DEVICE_UNCACHED.\n");
+ else
+ wprintf(L"- %u types are AMD-specific DEVICE_COHERENT or DEVICE_UNCACHED.\n", amdSpecificTypeCount);
+
+ if(lazilyAllocatedTypeCount == 0)
+ wprintf(L"- No types are LAZILY_ALLOCATED.\n");
+ else
+ wprintf(L"- %u types are LAZILY_ALLOCATED.\n", lazilyAllocatedTypeCount);
+
+ if(props->vendorID == VENDOR_ID_AMD &&
+ props->deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU &&
+ deviceLocalAndHostVisibleHeapSumSize > 256llu * 1024 * 1024)
+ {
+ wprintf(L"- AMD Smart Access Memory (SAM) is enabled!\n");
+ }
+
+ if(deviceLocalHeapCount < heapCount)
+ {
+ const uint32_t nonDeviceLocalTypeBits = ~deviceLocalTypeBits & allTypeBits;
+
+ if(CanCreateVertexBuffer(nonDeviceLocalTypeBits))
+ wprintf(L"- A buffer with VERTEX_BUFFER usage can be created in some non-DEVICE_LOCAL type.\n");
+ else
+ wprintf(L"- A buffer with VERTEX_BUFFER usage cannot be created in some non-DEVICE_LOCAL type.\n");
+
+ if(CanCreateOptimalSampledImage(nonDeviceLocalTypeBits))
+ wprintf(L"- An image with OPTIMAL tiling and SAMPLED usage can be created in some non-DEVICE_LOCAL type.\n");
+ else
+ wprintf(L"- An image with OPTIMAL tiling and SAMPLED usage cannot be created in some non-DEVICE_LOCAL type.\n");
+ }
+
+ //wprintf(L"\n");
}
static void InitializeApplication()
{
- if(USE_CUSTOM_CPU_ALLOCATION_CALLBACKS)
- {
- g_Allocs = &g_CpuAllocationCallbacks;
- }
-
- uint32_t instanceLayerPropCount = 0;
- ERR_GUARD_VULKAN( vkEnumerateInstanceLayerProperties(&instanceLayerPropCount, nullptr) );
- std::vector instanceLayerProps(instanceLayerPropCount);
- if(instanceLayerPropCount > 0)
- {
- ERR_GUARD_VULKAN( vkEnumerateInstanceLayerProperties(&instanceLayerPropCount, instanceLayerProps.data()) );
- }
-
- if(g_EnableValidationLayer)
- {
- if(IsLayerSupported(instanceLayerProps.data(), instanceLayerProps.size(), VALIDATION_LAYER_NAME) == false)
- {
- wprintf(L"Layer \"%hs\" not supported.", VALIDATION_LAYER_NAME);
- g_EnableValidationLayer = false;
- }
- }
-
- uint32_t availableInstanceExtensionCount = 0;
- ERR_GUARD_VULKAN( vkEnumerateInstanceExtensionProperties(nullptr, &availableInstanceExtensionCount, nullptr) );
- std::vector availableInstanceExtensions(availableInstanceExtensionCount);
- if(availableInstanceExtensionCount > 0)
- {
- ERR_GUARD_VULKAN( vkEnumerateInstanceExtensionProperties(nullptr, &availableInstanceExtensionCount, availableInstanceExtensions.data()) );
- }
-
- std::vector enabledInstanceExtensions;
- enabledInstanceExtensions.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
- enabledInstanceExtensions.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
-
- std::vector instanceLayers;
- if(g_EnableValidationLayer)
- {
- instanceLayers.push_back(VALIDATION_LAYER_NAME);
- }
-
- for(const auto& extensionProperties : availableInstanceExtensions)
- {
- if(strcmp(extensionProperties.extensionName, VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME) == 0)
- {
- if(GetVulkanApiVersion() == VK_API_VERSION_1_0)
- {
- enabledInstanceExtensions.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
- VK_KHR_get_physical_device_properties2_enabled = true;
- }
- }
- else if(strcmp(extensionProperties.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME) == 0)
- {
- enabledInstanceExtensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
- VK_EXT_debug_utils_enabled = true;
- }
- }
-
- VkApplicationInfo appInfo = { VK_STRUCTURE_TYPE_APPLICATION_INFO };
- appInfo.pApplicationName = APP_TITLE_A;
- appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
- appInfo.pEngineName = "Adam Sawicki Engine";
- appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0);
- appInfo.apiVersion = GetVulkanApiVersion();
-
- VkInstanceCreateInfo instInfo = { VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO };
- instInfo.pApplicationInfo = &appInfo;
- instInfo.enabledExtensionCount = static_cast(enabledInstanceExtensions.size());
- instInfo.ppEnabledExtensionNames = enabledInstanceExtensions.data();
- instInfo.enabledLayerCount = static_cast(instanceLayers.size());
- instInfo.ppEnabledLayerNames = instanceLayers.data();
-
- wprintf(L"Vulkan API version: ");
- switch(appInfo.apiVersion)
- {
- case VK_API_VERSION_1_0: wprintf(L"1.0\n"); break;
- case VK_API_VERSION_1_1: wprintf(L"1.1\n"); break;
- case VK_API_VERSION_1_2: wprintf(L"1.2\n"); break;
- default: assert(0);
- }
-
- ERR_GUARD_VULKAN( vkCreateInstance(&instInfo, g_Allocs, &g_hVulkanInstance) );
-
- if(VK_EXT_debug_utils_enabled)
- {
- RegisterDebugCallbacks();
- }
-
// Create VkSurfaceKHR.
VkWin32SurfaceCreateInfoKHR surfaceInfo = { VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR };
surfaceInfo.hinstance = g_hAppInstance;
@@ -1287,17 +1762,6 @@ static void InitializeApplication()
VkResult result = vkCreateWin32SurfaceKHR(g_hVulkanInstance, &surfaceInfo, g_Allocs, &g_hSurface);
assert(result == VK_SUCCESS);
- // Find physical device
-
- uint32_t deviceCount = 0;
- ERR_GUARD_VULKAN( vkEnumeratePhysicalDevices(g_hVulkanInstance, &deviceCount, nullptr) );
- assert(deviceCount > 0);
-
- std::vector physicalDevices(deviceCount);
- ERR_GUARD_VULKAN( vkEnumeratePhysicalDevices(g_hVulkanInstance, &deviceCount, physicalDevices.data()) );
-
- g_hPhysicalDevice = physicalDevices[0];
-
// Query for device extensions
uint32_t physicalDeviceExtensionPropertyCount = 0;
@@ -1346,25 +1810,43 @@ static void InitializeApplication()
VK_KHR_buffer_device_address_enabled = true;
}
}
- else if(strcmp(physicalDeviceExtensionProperties[i].extensionName, VK_EXT_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME) == 0)
- {
- if(GetVulkanApiVersion() < VK_API_VERSION_1_2)
- {
- VK_EXT_buffer_device_address_enabled = true;
- }
- }
+ else if(strcmp(physicalDeviceExtensionProperties[i].extensionName, VK_EXT_MEMORY_PRIORITY_EXTENSION_NAME) == 0)
+ VK_EXT_memory_priority_enabled = true;
}
- if(VK_EXT_buffer_device_address_enabled && VK_KHR_buffer_device_address_enabled)
- VK_EXT_buffer_device_address_enabled = false;
+ if(GetVulkanApiVersion() >= VK_API_VERSION_1_2)
+ VK_KHR_buffer_device_address_enabled = true; // Promoted to core Vulkan 1.2.
// Query for features
+#if VMA_VULKAN_VERSION >= 1001000
+ VkPhysicalDeviceProperties2 physicalDeviceProperties2 = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2 };
+
+#if VMA_VULKAN_VERSION >= 1002000
+ // Vulkan spec says structure VkPhysicalDeviceVulkan11Properties is "Provided by VK_VERSION_1_2" - is this a mistake? Assuming not...
+ VkPhysicalDeviceVulkan11Properties physicalDeviceVulkan11Properties = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_PROPERTIES };
+ VkPhysicalDeviceVulkan12Properties physicalDeviceVulkan12Properties = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_PROPERTIES };
+ PnextChainPushFront(&physicalDeviceProperties2, &physicalDeviceVulkan11Properties);
+ PnextChainPushFront(&physicalDeviceProperties2, &physicalDeviceVulkan12Properties);
+#endif
+
+ vkGetPhysicalDeviceProperties2(g_hPhysicalDevice, &physicalDeviceProperties2);
+
+ PrintPhysicalDeviceProperties(physicalDeviceProperties2.properties);
+#if VMA_VULKAN_VERSION >= 1002000
+ PrintPhysicalDeviceVulkan11Properties(physicalDeviceVulkan11Properties);
+ PrintPhysicalDeviceVulkan12Properties(physicalDeviceVulkan12Properties);
+#endif
+
+#else // #if VMA_VULKAN_VERSION >= 1001000
VkPhysicalDeviceProperties physicalDeviceProperties = {};
vkGetPhysicalDeviceProperties(g_hPhysicalDevice, &physicalDeviceProperties);
-
PrintPhysicalDeviceProperties(physicalDeviceProperties);
+#endif // #if VMA_VULKAN_VERSION >= 1001000
+
+ wprintf(L"\n");
+
VkPhysicalDeviceFeatures2 physicalDeviceFeatures = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2 };
VkPhysicalDeviceCoherentMemoryFeaturesAMD physicalDeviceCoherentMemoryFeatures = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COHERENT_MEMORY_FEATURES_AMD };
@@ -1373,12 +1855,18 @@ static void InitializeApplication()
PnextChainPushFront(&physicalDeviceFeatures, &physicalDeviceCoherentMemoryFeatures);
}
- VkPhysicalDeviceBufferDeviceAddressFeaturesEXT physicalDeviceBufferDeviceAddressFeatures = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES_EXT };
- if(VK_KHR_buffer_device_address_enabled || VK_EXT_buffer_device_address_enabled || GetVulkanApiVersion() >= VK_API_VERSION_1_2)
+ VkPhysicalDeviceBufferDeviceAddressFeaturesKHR physicalDeviceBufferDeviceAddressFeatures = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES_KHR };
+ if(VK_KHR_buffer_device_address_enabled)
{
PnextChainPushFront(&physicalDeviceFeatures, &physicalDeviceBufferDeviceAddressFeatures);
}
+ VkPhysicalDeviceMemoryPriorityFeaturesEXT physicalDeviceMemoryPriorityFeatures = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PRIORITY_FEATURES_EXT };
+ if(VK_EXT_memory_priority_enabled)
+ {
+ PnextChainPushFront(&physicalDeviceFeatures, &physicalDeviceMemoryPriorityFeatures);
+ }
+
vkGetPhysicalDeviceFeatures2(g_hPhysicalDevice, &physicalDeviceFeatures);
g_SparseBindingEnabled = physicalDeviceFeatures.features.sparseBinding != 0;
@@ -1386,8 +1874,10 @@ static void InitializeApplication()
// The extension is supported as fake with no real support for this feature? Don't use it.
if(VK_AMD_device_coherent_memory_enabled && !physicalDeviceCoherentMemoryFeatures.deviceCoherentMemory)
VK_AMD_device_coherent_memory_enabled = false;
- if(VK_KHR_buffer_device_address_enabled || VK_EXT_buffer_device_address_enabled || GetVulkanApiVersion() >= VK_API_VERSION_1_2)
- g_BufferDeviceAddressEnabled = physicalDeviceBufferDeviceAddressFeatures.bufferDeviceAddress != VK_FALSE;
+ if(VK_KHR_buffer_device_address_enabled && !physicalDeviceBufferDeviceAddressFeatures.bufferDeviceAddress)
+ VK_KHR_buffer_device_address_enabled = false;
+ if(VK_EXT_memory_priority_enabled && !physicalDeviceMemoryPriorityFeatures.memoryPriority)
+ VK_EXT_memory_priority_enabled = false;
// Find queue family index
@@ -1476,10 +1966,10 @@ static void InitializeApplication()
enabledDeviceExtensions.push_back(VK_EXT_MEMORY_BUDGET_EXTENSION_NAME);
if(VK_AMD_device_coherent_memory_enabled)
enabledDeviceExtensions.push_back(VK_AMD_DEVICE_COHERENT_MEMORY_EXTENSION_NAME);
- if(VK_KHR_buffer_device_address_enabled)
+ if(VK_KHR_buffer_device_address_enabled && GetVulkanApiVersion() < VK_API_VERSION_1_2)
enabledDeviceExtensions.push_back(VK_KHR_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME);
- if(VK_EXT_buffer_device_address_enabled)
- enabledDeviceExtensions.push_back(VK_EXT_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME);
+ if(VK_EXT_memory_priority_enabled)
+ enabledDeviceExtensions.push_back(VK_EXT_MEMORY_PRIORITY_EXTENSION_NAME);
VkPhysicalDeviceFeatures2 deviceFeatures = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2 };
deviceFeatures.features.samplerAnisotropy = VK_TRUE;
@@ -1490,12 +1980,16 @@ static void InitializeApplication()
physicalDeviceCoherentMemoryFeatures.deviceCoherentMemory = VK_TRUE;
PnextChainPushBack(&deviceFeatures, &physicalDeviceCoherentMemoryFeatures);
}
- if(g_BufferDeviceAddressEnabled)
+ if(VK_KHR_buffer_device_address_enabled)
{
- physicalDeviceBufferDeviceAddressFeatures = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES_EXT };
+ physicalDeviceBufferDeviceAddressFeatures = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES_KHR };
physicalDeviceBufferDeviceAddressFeatures.bufferDeviceAddress = VK_TRUE;
PnextChainPushBack(&deviceFeatures, &physicalDeviceBufferDeviceAddressFeatures);
}
+ if(VK_EXT_memory_priority_enabled)
+ {
+ PnextChainPushBack(&deviceFeatures, &physicalDeviceMemoryPriorityFeatures);
+ }
VkDeviceCreateInfo deviceCreateInfo = { VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO };
deviceCreateInfo.pNext = &deviceFeatures;
@@ -1509,48 +2003,17 @@ static void InitializeApplication()
ERR_GUARD_VULKAN( vkCreateDevice(g_hPhysicalDevice, &deviceCreateInfo, g_Allocs, &g_hDevice) );
// Fetch pointers to extension functions
- if(g_BufferDeviceAddressEnabled)
+ if(VK_KHR_buffer_device_address_enabled)
{
if(GetVulkanApiVersion() >= VK_API_VERSION_1_2)
{
- g_vkGetBufferDeviceAddressEXT = (PFN_vkGetBufferDeviceAddressEXT)vkGetDeviceProcAddr(g_hDevice, "vkGetBufferDeviceAddress");
- //assert(g_vkGetBufferDeviceAddressEXT != nullptr);
- /*
- For some reason this doesn't work, the pointer is NULL :( None of the below methods help.
-
- Validation layers also report following error:
- [ VUID-VkMemoryAllocateInfo-flags-03331 ] Object: VK_NULL_HANDLE (Type = 0) | If VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT_KHR is set, bufferDeviceAddress must be enabled. The Vulkan spec states: If VkMemoryAllocateFlagsInfo::flags includes VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT, the bufferDeviceAddress feature must be enabled (https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#VUID-VkMemoryAllocateInfo-flags-03331)
- Despite I'm posting VkPhysicalDeviceBufferDeviceAddressFeaturesEXT::bufferDeviceAddress = VK_TRUE in VkDeviceCreateInfo::pNext chain.
-
- if(g_vkGetBufferDeviceAddressEXT == nullptr)
- {
- g_vkGetBufferDeviceAddressEXT = &vkGetBufferDeviceAddress; // Doesn't run, cannot find entry point...
- }
-
- if(g_vkGetBufferDeviceAddressEXT == nullptr)
- {
- g_vkGetBufferDeviceAddressEXT = (PFN_vkGetBufferDeviceAddressEXT)vkGetInstanceProcAddr(g_hVulkanInstance, "vkGetBufferDeviceAddress");
- }
- if(g_vkGetBufferDeviceAddressEXT == nullptr)
- {
- g_vkGetBufferDeviceAddressEXT = (PFN_vkGetBufferDeviceAddressEXT)vkGetDeviceProcAddr(g_hDevice, "vkGetBufferDeviceAddressKHR");
- }
- if(g_vkGetBufferDeviceAddressEXT == nullptr)
- {
- g_vkGetBufferDeviceAddressEXT = (PFN_vkGetBufferDeviceAddressEXT)vkGetDeviceProcAddr(g_hDevice, "vkGetBufferDeviceAddressEXT");
- }
- */
+ g_vkGetBufferDeviceAddressKHR = (PFN_vkGetBufferDeviceAddressEXT)vkGetDeviceProcAddr(g_hDevice, "vkGetBufferDeviceAddress");
}
else if(VK_KHR_buffer_device_address_enabled)
{
- g_vkGetBufferDeviceAddressEXT = (PFN_vkGetBufferDeviceAddressEXT)vkGetDeviceProcAddr(g_hDevice, "vkGetBufferDeviceAddressKHR");
- assert(g_vkGetBufferDeviceAddressEXT != nullptr);
- }
- else if(VK_EXT_buffer_device_address_enabled)
- {
- g_vkGetBufferDeviceAddressEXT = (PFN_vkGetBufferDeviceAddressEXT)vkGetDeviceProcAddr(g_hDevice, "vkGetBufferDeviceAddressEXT");
- assert(g_vkGetBufferDeviceAddressEXT != nullptr);
+ g_vkGetBufferDeviceAddressKHR = (PFN_vkGetBufferDeviceAddressEXT)vkGetDeviceProcAddr(g_hDevice, "vkGetBufferDeviceAddressKHR");
}
+ assert(g_vkGetBufferDeviceAddressKHR != nullptr);
}
// Create memory allocator
@@ -1559,7 +2022,12 @@ static void InitializeApplication()
SetAllocatorCreateInfo(allocatorInfo);
ERR_GUARD_VULKAN( vmaCreateAllocator(&allocatorInfo, &g_hAllocator) );
+ PrintMemoryTypes();
+ wprintf(L"\n");
+ PrintMemoryConclusions();
+ wprintf(L"\n");
PrintEnabledFeatures();
+ wprintf(L"\n");
// Retrieve queues (don't need to be destroyed).
@@ -1769,14 +2237,6 @@ static void FinalizeApplication()
vkDestroySurfaceKHR(g_hVulkanInstance, g_hSurface, g_Allocs);
g_hSurface = VK_NULL_HANDLE;
}
-
- UnregisterDebugCallbacks();
-
- if(g_hVulkanInstance != VK_NULL_HANDLE)
- {
- vkDestroyInstance(g_hVulkanInstance, g_Allocs);
- g_hVulkanInstance = VK_NULL_HANDLE;
- }
}
static void PrintAllocatorStats()
@@ -1939,6 +2399,18 @@ static void HandlePossibleSizeChange()
}
}
+#define CATCH_PRINT_ERROR(extraCatchCode) \
+ catch(const std::exception& ex) \
+ { \
+ fwprintf(stderr, L"ERROR: %hs\n", ex.what()); \
+ extraCatchCode \
+ } \
+ catch(...) \
+ { \
+ fwprintf(stderr, L"UNKNOWN ERROR.\n"); \
+ extraCatchCode \
+ }
+
static LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
@@ -1946,12 +2418,20 @@ static LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
case WM_CREATE:
// This is intentionally assigned here because we are now inside CreateWindow, before it returns.
g_hWnd = hWnd;
- InitializeApplication();
- PrintAllocatorStats();
+ try
+ {
+ InitializeApplication();
+ }
+ CATCH_PRINT_ERROR(return -1;)
+ //PrintAllocatorStats();
return 0;
case WM_DESTROY:
- FinalizeApplication();
+ try
+ {
+ FinalizeApplication();
+ }
+ CATCH_PRINT_ERROR(;)
PostQuitMessage(0);
return 0;
@@ -1963,11 +2443,21 @@ static LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
case WM_SIZE:
if((wParam == SIZE_MAXIMIZED) || (wParam == SIZE_RESTORED))
- HandlePossibleSizeChange();
+ {
+ try
+ {
+ HandlePossibleSizeChange();
+ }
+ CATCH_PRINT_ERROR(DestroyWindow(hWnd);)
+ }
return 0;
case WM_EXITSIZEMOVE:
- HandlePossibleSizeChange();
+ try
+ {
+ HandlePossibleSizeChange();
+ }
+ CATCH_PRINT_ERROR(DestroyWindow(hWnd);)
return 0;
case WM_KEYDOWN:
@@ -1981,17 +2471,18 @@ static LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
Test();
}
- catch(const std::exception& ex)
- {
- printf("ERROR: %s\n", ex.what());
- }
+ CATCH_PRINT_ERROR(;)
break;
case 'S':
try
{
if(g_SparseBindingEnabled)
{
- TestSparseBinding();
+ try
+ {
+ TestSparseBinding();
+ }
+ CATCH_PRINT_ERROR(;)
}
else
{
@@ -2013,10 +2504,24 @@ static LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
return DefWindowProc(hWnd, msg, wParam, lParam);
}
-int main()
+static void PrintLogo()
{
- g_hAppInstance = (HINSTANCE)GetModuleHandle(NULL);
+ wprintf(L"%s\n", APP_TITLE_W);
+}
+static void PrintHelp()
+{
+ wprintf(
+ L"Command line syntax:\n"
+ L"-h, --Help Print this information\n"
+ L"-l, --List Print list of GPUs\n"
+ L"-g S, --GPU S Select GPU with name containing S\n"
+ L"-i N, --GPUIndex N Select GPU index N\n"
+ );
+}
+
+int MainWindow()
+{
WNDCLASSEX wndClassDesc = { sizeof(WNDCLASSEX) };
wndClassDesc.style = CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS;
wndClassDesc.hbrBackground = NULL;
@@ -2054,11 +2559,51 @@ int main()
DrawFrame();
}
- TEST(g_CpuAllocCount.load() == 0);
-
- return 0;
+ return (int)msg.wParam;;
}
+int Main2(int argc, wchar_t** argv)
+{
+ PrintLogo();
+
+ if(!g_CommandLineParameters.Parse(argc, argv))
+ {
+ wprintf(L"ERROR: Invalid command line syntax.\n");
+ PrintHelp();
+ return (int)ExitCode::CommandLineError;
+ }
+
+ if(g_CommandLineParameters.m_Help)
+ {
+ PrintHelp();
+ return (int)ExitCode::Help;
+ }
+
+ VulkanUsage vulkanUsage;
+ vulkanUsage.Init();
+
+ if(g_CommandLineParameters.m_List)
+ {
+ vulkanUsage.PrintPhysicalDeviceList();
+ return (int)ExitCode::GPUList;
+ }
+
+ g_hPhysicalDevice = vulkanUsage.SelectPhysicalDevice(g_CommandLineParameters.m_GPUSelection);
+ TEST(g_hPhysicalDevice);
+
+ return MainWindow();
+}
+
+int wmain(int argc, wchar_t** argv)
+{
+ try
+ {
+ return Main2(argc, argv);
+ TEST(g_CpuAllocCount.load() == 0);
+ }
+ CATCH_PRINT_ERROR(return (int)ExitCode::RuntimeError;)
+}
+
#else // #ifdef _WIN32
#include "VmaUsage.h"
diff --git a/third_party/vkmemalloc/tnt/CMakeLists.txt b/third_party/vkmemalloc/tnt/CMakeLists.txt
index 12f959c002..1e551077bd 100644
--- a/third_party/vkmemalloc/tnt/CMakeLists.txt
+++ b/third_party/vkmemalloc/tnt/CMakeLists.txt
@@ -3,7 +3,7 @@ project(vkmemalloc)
set(TARGET vkmemalloc)
-set(PUBLIC_HDR_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../src)
+set(PUBLIC_HDR_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../include)
set(PUBLIC_HDRS ${PUBLIC_HDR_DIR}/vk_mem_alloc.h)
diff --git a/third_party/vkmemalloc/tnt/README b/third_party/vkmemalloc/tnt/README
index 9e098bdd43..8b12a3c16c 100644
--- a/third_party/vkmemalloc/tnt/README
+++ b/third_party/vkmemalloc/tnt/README
@@ -1,8 +1,8 @@
This folder was created as follows:
-curl -L -O https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator/archive/2193611.zip
-unzip 2193611.zip
+curl -L -O https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator/archive/8d4a9e9.zip
+unzip 8d4a9e9.zip
mv VulkanMemoryAllocator-* vkmemalloc
cd vkmemalloc
-rm -rf bin docs media premake third_party tools
+rm -rf build docs media tools
rsync -r ./ ~/github/filament/third_party/vkmemalloc/ --delete --exclude tnt