Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
VMA.h
Go to the documentation of this file.
1/* Copyright (C) 2026 Wildfire Games.
2 * This file is part of 0 A.D.
3 *
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef INCLUDED_RENDERER_BACKEND_VULKAN_VMA
19#define INCLUDED_RENDERER_BACKEND_VULKAN_VMA
20
21#include "lib/debug.h"
22#include "lib/sysdep/compiler.h"
23
24#include <glad/vulkan.h>
25
26#define VMA_VULKAN_VERSION 1001000
27#define VMA_ASSERT(EXPR) ASSERT(EXPR)
28#define VMA_HEAVY_ASSERT(EXPR) ENSURE(EXPR)
29#define VMA_DYNAMIC_VULKAN_FUNCTIONS 0
30#define VMA_STATIC_VULKAN_FUNCTIONS 0
31#define VMA_BUFFER_DEVICE_ADDRESS 0
32
33#ifndef NDEBUG
34#define VMA_DEBUG_LOG(...) do { debug_printf(__VA_ARGS__); debug_printf("\n"); } while (0)
35#define VMA_STATS_STRING_ENABLED 1
36#else
37#define VMA_DEBUG_LOG(...)
38#define VMA_STATS_STRING_ENABLED 0
39#endif
40
41#if GCC_VERSION
42#pragma GCC diagnostic push
43#pragma GCC diagnostic ignored "-Wformat"
44#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
45#pragma GCC diagnostic ignored "-Wparentheses"
46#pragma GCC diagnostic ignored "-Wundef"
47#pragma GCC diagnostic ignored "-Wunused-parameter"
48#pragma GCC diagnostic ignored "-Wunused-variable"
49#endif
50#if CLANG_VERSION
51#pragma clang diagnostic push
52#pragma clang diagnostic ignored "-Wformat"
53#pragma clang diagnostic ignored "-Wnullability-completeness"
54#pragma clang diagnostic ignored "-Wparentheses"
55#pragma clang diagnostic ignored "-Wundef"
56#pragma clang diagnostic ignored "-Wunused-parameter"
57#pragma clang diagnostic ignored "-Wunused-variable"
58#endif
59#if MSC_VERSION
60#pragma warning(push, 1)
61#pragma warning(disable: 4100) // Unreferenced formal parameter.
62#pragma warning(disable: 4701) // Potentially uninitialized local variable used.
63#pragma warning(disable: 4703) // Potentially uninitialized local pointer variable used.
64#endif
65
66// GCC before 13 doesn't account some diagnostics:
67// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53431
68// VMA tests the MSVC-specific _MSVC_LANG in an #if, so define it for GCC to
69// avoid -Wundef. Needs to be undefined again below, as >=fmt-11 would take the
70// pre-C++14 code path and fail to build with <gcc-15.
71#if GCC_VERSION && !defined(_MSVC_LANG)
72#define _MSVC_LANG 0
73#define RENDERER_BACKEND_VULKAN_VMA_MSVC_LANG
74#endif
75
76// VMA always uses extension variants and glad doesn't provide extension
77// defines and types that were promoted to the core version. So we need to
78// define them manually.
79#define PFN_vkBindBufferMemory2KHR PFN_vkBindBufferMemory2
80#define PFN_vkBindImageMemory2KHR PFN_vkBindImageMemory2
81#define PFN_vkGetBufferMemoryRequirements2KHR PFN_vkGetBufferMemoryRequirements2
82#define PFN_vkGetImageMemoryRequirements2KHR PFN_vkGetImageMemoryRequirements2
83#define PFN_vkGetPhysicalDeviceMemoryProperties2KHR PFN_vkGetPhysicalDeviceMemoryProperties2
84
85#define vkBindBufferMemory2KHR vkBindBufferMemory2
86#define vkBindImageMemory2KHR vkBindImageMemory2
87#define vkGetBufferMemoryRequirements2KHR vkGetBufferMemoryRequirements2
88#define vkGetImageMemoryRequirements2KHR vkGetImageMemoryRequirements2
89#define vkGetPhysicalDeviceMemoryProperties2KHR vkGetPhysicalDeviceMemoryProperties2
90
91#define VkBindBufferMemoryInfoKHR VkBindBufferMemoryInfo
92#define VkBindImageMemoryInfoKHR VkBindImageMemoryInfo
93#define VkBufferMemoryRequirementsInfo2KHR VkBufferMemoryRequirementsInfo2
94#define VkImageMemoryRequirementsInfo2KHR VkImageMemoryRequirementsInfo2
95#define VkMemoryDedicatedAllocateInfoKHR VkMemoryDedicatedAllocateInfo
96#define VkMemoryDedicatedRequirementsKHR VkMemoryDedicatedRequirements
97#define VkMemoryRequirements2KHR VkMemoryRequirements2
98#define VkPhysicalDeviceMemoryProperties2KHR VkPhysicalDeviceMemoryProperties2
99
100#define VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
101#define VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_INFO_KHR VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_INFO
102#define VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2_KHR VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2
103#define VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2_KHR VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2
104#define VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO_KHR VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO
105#define VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
106#define VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2_KHR VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2
107#define VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2_KHR VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2
108
109// Those extensions should be enabled automatically by picking Vulkan 1.1.
110#define VK_AMD_device_coherent_memory 0
111#define VK_KHR_bind_memory2 0
112#define VK_KHR_get_memory_requirements2 0
113#define VK_KHR_external_memory 0
114#define VK_EXT_memory_budget 0
115#define VK_EXT_memory_priority 0
116
117#include "third_party/vma/vk_mem_alloc.h"
118
119#ifdef RENDERER_BACKEND_VULKAN_VMA_MSVC_LANG
120#undef _MSVC_LANG
121#undef RENDERER_BACKEND_VULKAN_VMA_MSVC_LANG
122#endif
123
124#if GCC_VERSION
125#pragma GCC diagnostic pop
126#endif
127#if CLANG_VERSION
128#pragma clang diagnostic pop
129#endif
130#if MSC_VERSION
131#pragma warning(pop)
132#endif
133
134#endif // INCLUDED_RENDERER_BACKEND_VULKAN_VMA