├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── build.zig ├── test ├── test.zig ├── vulkan-1.lib ├── vulkan-1.pdb └── vulkan_core.zig ├── vk_mem_alloc.cpp ├── vk_mem_alloc.natvis ├── vma.zig ├── vma_build.zig ├── vma_config.zig └── vulkan ├── vk_icd.h ├── vk_layer.h ├── vk_platform.h ├── vk_sdk_platform.h ├── vulkan.h ├── vulkan.hpp ├── vulkan_android.h ├── vulkan_core.h ├── vulkan_fuchsia.h ├── vulkan_ggp.h ├── vulkan_ios.h ├── vulkan_macos.h ├── vulkan_metal.h ├── vulkan_vi.h ├── vulkan_wayland.h ├── vulkan_win32.h ├── vulkan_xcb.h ├── vulkan_xlib.h └── vulkan_xlib_xrandr.h /.gitattributes: -------------------------------------------------------------------------------- 1 | # See https://git-scm.com/docs/gitattributes 2 | # See https://help.github.com/articles/dealing-with-line-endings/ 3 | 4 | # Default behavior, if core.autocrlf is unset. 5 | * text=auto 6 | 7 | # Files to be converted to native line endings on checkout. 8 | *.cpp text 9 | *.h text 10 | 11 | # Text files to always have CRLF (dos) line endings on checkout. 12 | *.bat text eol=crlf 13 | 14 | # Text files to always have LF (unix) line endings on checkout. 15 | *.sh text eol=lf 16 | *.zig text eol=lf 17 | 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | zig-cache/ 2 | zig-out/ 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | ===================== VulkanMemoryAllocator ======================= 2 | 3 | Copyright (c) 2017-2019 Advanced Micro Devices, Inc. All rights reserved. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | ======================= Zig-VMA =============================== 24 | 25 | Copyright (c) 2020 Martin Wickham. 26 | 27 | Permission is hereby granted, free of charge, to any person obtaining a copy 28 | of this software and associated documentation files (the "Software"), to deal 29 | in the Software without restriction, including without limitation the rights 30 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 31 | copies of the Software, and to permit persons to whom the Software is 32 | furnished to do so, subject to the following conditions: 33 | 34 | The above copyright notice and this permission notice shall be included in 35 | all copies or substantial portions of the Software. 36 | 37 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 38 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 39 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 40 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 41 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 42 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 43 | THE SOFTWARE. 44 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Zig-VMA 2 | 3 | This project provides Zig bindings for the Vulkan Memory Allocator library. 4 | 5 | ## Using this project 6 | 7 | To use this library, first vendor this repository into your project (or use a git submodule). 8 | 9 | In your build.zig, use this to link vma to your executable: 10 | ```zig 11 | const vma_build = @import("path/to/vma/vma_build.zig"); 12 | vma_build.link(exe, "path/to/vk.zig", mode, target); 13 | ``` 14 | 15 | If you are linking vma to a package, use `pkg` to obtain a package for use in dependencies: 16 | ```zig 17 | vma_build.pkg(exe.builder, "path/to/vk.zig") 18 | ``` 19 | If you aren't using `link` to enable the vma package on your root, you will still need to link the C sources with the executable, using this: 20 | ```zig 21 | vma_build.linkWithoutPkg(exe, mode, target); 22 | ``` 23 | 24 | `vma_config.zig` contains build flags which will be used to configure the project. It has separate configurations for debug and release builds. These flags can be modified to tune the library. 25 | 26 | Check out [this repository](https://github.com/SpexGuy/sdltest) for an example of the library in use. 27 | -------------------------------------------------------------------------------- /build.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const vma_build = @import("vma_build.zig"); 3 | 4 | pub fn build(b: *std.build.Builder) void { 5 | // Standard target options allows the person running `zig build` to choose 6 | // what target to build for. Here we do not override the defaults, which 7 | // means any target is allowed, and the default is native. Other options 8 | // for restricting supported target set are available. 9 | const target = b.standardTargetOptions(.{}); 10 | 11 | // Standard release options allow the person running `zig build` to select 12 | // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. 13 | const mode = b.standardReleaseOptions(); 14 | 15 | // make step for tests 16 | const tests = b.addTest("test/test.zig"); 17 | tests.setBuildMode(mode); 18 | tests.setTarget(target); 19 | 20 | // link vk 21 | tests.addPackagePath("vk", "test/vulkan_core.zig"); 22 | if (target.getOs().tag == .windows) { 23 | tests.addObjectFile("test/vulkan-1.lib"); 24 | } else { 25 | tests.linkSystemLibrary("vulkan"); 26 | } 27 | 28 | // link vma 29 | vma_build.link(tests, "test/vulkan_core.zig", mode, target); 30 | 31 | const test_step = b.step("test", "run tests"); 32 | test_step.dependOn(&tests.step); 33 | } 34 | -------------------------------------------------------------------------------- /test/test.zig: -------------------------------------------------------------------------------- 1 | const vk = @import("vk"); 2 | const vma = @import("vma"); 3 | const std = @import("std"); 4 | 5 | test "vma" { 6 | const instance = try vk.CreateInstance(.{}, null); 7 | defer vk.DestroyInstance(instance, null); 8 | 9 | var physDevice: vk.PhysicalDevice = .Null; 10 | _ = try vk.EnumeratePhysicalDevices(instance, @as(*[1]vk.PhysicalDevice, &physDevice)); 11 | if (physDevice == .Null) return error.NoDevicesAvailable; 12 | 13 | const device = try vk.CreateDevice(physDevice, .{ 14 | .queueCreateInfoCount = 1, 15 | .pQueueCreateInfos = &[_]vk.DeviceQueueCreateInfo{ .{ 16 | .queueFamilyIndex = 0, 17 | .queueCount = 1, 18 | .pQueuePriorities = &[_]f32{ 1.0 }, 19 | } }, 20 | }, null); 21 | defer vk.DestroyDevice(device, null); 22 | 23 | const functions = vma.VulkanFunctions.init(instance, device, vk.vkGetInstanceProcAddr); 24 | 25 | const allocator = try vma.Allocator.create(.{ 26 | .instance = instance, 27 | .physicalDevice = physDevice, 28 | .device = device, 29 | .frameInUseCount = 3, 30 | .pVulkanFunctions = &functions, 31 | }); 32 | defer allocator.destroy(); 33 | } 34 | 35 | test "Compile everything" { 36 | @setEvalBranchQuota(10000); 37 | compileEverything(vma); 38 | } 39 | 40 | fn compileEverything(comptime Outer: type) void { 41 | inline for (comptime std.meta.declarations(Outer)) |decl| { 42 | if (decl.is_pub) { 43 | const T = @TypeOf(@field(Outer, decl.name)); 44 | if (T == type) { 45 | switch (@typeInfo(@field(Outer, decl.name))) { 46 | .Struct, 47 | .Enum, 48 | .Union, 49 | .Opaque, 50 | => compileEverything(@field(Outer, decl.name)), 51 | else => {}, 52 | } 53 | } 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /test/vulkan-1.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SpexGuy/Zig-VMA/1f74653e44ecfe98da66059f2bb13033dfabc0df/test/vulkan-1.lib -------------------------------------------------------------------------------- /test/vulkan-1.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SpexGuy/Zig-VMA/1f74653e44ecfe98da66059f2bb13033dfabc0df/test/vulkan-1.pdb -------------------------------------------------------------------------------- /vk_mem_alloc.natvis: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | {{ Count={m_Count} }} 5 | 6 | m_Count 7 | 8 | m_Count 9 | m_pFront 10 | pNext 11 | Value 12 | 13 | 14 | 15 | 16 | 17 | {{ Count={m_RawList.m_Count} }} 18 | 19 | m_RawList.m_Count 20 | 21 | m_RawList.m_Count 22 | m_RawList.m_pFront 23 | pNext 24 | Value 25 | 26 | 27 | 28 | 29 | 30 | {{ Count={m_Count} }} 31 | 32 | m_Count 33 | m_Capacity 34 | 35 | m_Count 36 | m_pArray 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /vma.zig: -------------------------------------------------------------------------------- 1 | // This API and many of the comments in this file come 2 | // directly from the VulkanMemoryAllocator source, which is 3 | // released under the following license: 4 | // 5 | // Copyright (c) 2017-2019 Advanced Micro Devices, Inc. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | const std = @import("std"); 26 | const builtin = @import("builtin"); 27 | const assert = std.debug.assert; 28 | const vk = @import("vk"); 29 | const vma_config = @import("vma_config.zig"); 30 | pub const config = if (builtin.mode == .Debug) vma_config.debugConfig else vma_config.releaseConfig; 31 | 32 | // callbacks use vk.CallConv, but the vma functions may not. 33 | pub const CallConv = .C; 34 | 35 | /// \struct Allocator 36 | /// \brief Represents main object of this library initialized. 37 | /// 38 | /// Fill structure #AllocatorCreateInfo and call function create() to create it. 39 | /// Call function destroy() to destroy it. 40 | /// 41 | /// It is recommended to create just one object of this type per `Device` object, 42 | /// right after Vulkan is initialized and keep it alive until before Vulkan device is destroyed. 43 | pub const Allocator = enum(usize) { 44 | Null = 0, 45 | _, 46 | 47 | /// Creates Allocator object. 48 | pub fn create(createInfo: AllocatorCreateInfo) !Allocator { 49 | var result: Allocator = undefined; 50 | const rc = vmaCreateAllocator(&createInfo, &result); 51 | if (@enumToInt(rc) >= 0) return result; 52 | 53 | return error.VMACreateFailed; 54 | } 55 | 56 | /// Destroys allocator object. 57 | /// fn (Allocator) void 58 | pub const destroy = vmaDestroyAllocator; 59 | 60 | /// PhysicalDeviceProperties are fetched from physicalDevice by the allocator. 61 | /// You can access it here, without fetching it again on your own. 62 | pub fn getPhysicalDeviceProperties(allocator: Allocator) *const vk.PhysicalDeviceProperties { 63 | var properties: *const vk.PhysicalDeviceProperties = undefined; 64 | vmaGetPhysicalDeviceProperties(allocator, &properties); 65 | return properties; 66 | } 67 | 68 | /// PhysicalDeviceMemoryProperties are fetched from physicalDevice by the allocator. 69 | /// You can access it here, without fetching it again on your own. 70 | pub fn getMemoryProperties(allocator: Allocator) *const vk.PhysicalDeviceMemoryProperties { 71 | var properties: *const vk.PhysicalDeviceMemoryProperties = undefined; 72 | vmaGetMemoryProperties(allocator, &properties); 73 | return properties; 74 | } 75 | 76 | /// \brief Given Memory Type Index, returns Property Flags of this memory type. 77 | /// 78 | /// This is just a convenience function. Same information can be obtained using 79 | /// GetMemoryProperties(). 80 | pub fn getMemoryTypeProperties(allocator: Allocator, memoryTypeIndex: u32) vk.MemoryPropertyFlags { 81 | var flags: vk.MemoryPropertyFlags align(4) = undefined; 82 | vmaGetMemoryTypeProperties(allocator, memoryTypeIndex, &flags); 83 | return flags; 84 | } 85 | 86 | /// \brief Sets index of the current frame. 87 | /// 88 | /// This function must be used if you make allocations with 89 | /// #VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT and 90 | /// #VMA_ALLOCATION_CREATE_CAN_MAKE_OTHER_LOST_BIT flags to inform the allocator 91 | /// when a new frame begins. Allocations queried using GetAllocationInfo() cannot 92 | /// become lost in the current frame. 93 | /// fn setCurrentFrameIndex(self: Allocator, frameIndex: u32) void 94 | pub const setCurrentFrameIndex = vmaSetCurrentFrameIndex; 95 | 96 | /// \brief Retrieves statistics from current state of the Allocator. 97 | /// 98 | /// This function is called "calculate" not "get" because it has to traverse all 99 | /// internal data structures, so it may be quite slow. For faster but more brief statistics 100 | /// suitable to be called every frame or every allocation, use GetBudget(). 101 | /// 102 | /// Note that when using allocator from multiple threads, returned information may immediately 103 | /// become outdated. 104 | pub fn calculateStats(allocator: Allocator) Stats { 105 | var stats: Stats = undefined; 106 | vmaCalculateStats(allocator, &stats); 107 | return stats; 108 | } 109 | 110 | /// \brief Retrieves information about current memory budget for all memory heaps. 111 | /// 112 | /// \param[out] pBudget Must point to array with number of elements at least equal to number of memory heaps in physical device used. 113 | /// 114 | /// This function is called "get" not "calculate" because it is very fast, suitable to be called 115 | /// every frame or every allocation. For more detailed statistics use CalculateStats(). 116 | /// 117 | /// Note that when using allocator from multiple threads, returned information may immediately 118 | /// become outdated. 119 | pub fn getBudget(allocator: Allocator) Budget { 120 | var budget: Budget = undefined; 121 | vmaGetBudget(allocator, &budget); 122 | return budget; 123 | } 124 | 125 | // pub usingnamespace if (config.statsStringEnabled) 126 | // struct { 127 | // /// Builds and returns statistics as string in JSON format. 128 | // /// @param[out] ppStatsString Must be freed using FreeStatsString() function. 129 | // pub fn buildStatsString(allocator: Allocator, detailedMap: bool) [*:0]u8 { 130 | // var string: [*:0]u8 = undefined; 131 | // vmaBuildStatsString(allocator, &string, @boolToInt(detailedMap)); 132 | // return string; 133 | // } 134 | 135 | // pub const freeStatsString = vmaFreeStatsString; 136 | // } 137 | // else 138 | // struct {}; 139 | 140 | /// \brief Helps to find memoryTypeIndex, given memoryTypeBits and AllocationCreateInfo. 141 | /// 142 | /// This algorithm tries to find a memory type that: 143 | /// 144 | /// - Is allowed by memoryTypeBits. 145 | /// - Contains all the flags from pAllocationCreateInfo->requiredFlags. 146 | /// - Matches intended usage. 147 | /// - Has as many flags from pAllocationCreateInfo->preferredFlags as possible. 148 | /// 149 | /// \return Returns error.VK_FEATURE_NOT_PRESENT if not found. Receiving such result 150 | /// from this function or any other allocating function probably means that your 151 | /// device doesn't support any memory type with requested features for the specific 152 | /// type of resource you want to use it for. Please check parameters of your 153 | /// resource, like image layout (OPTIMAL versus LINEAR) or mip level count. 154 | pub fn findMemoryTypeIndex(allocator: Allocator, memoryTypeBits: u32, allocationCreateInfo: AllocationCreateInfo) !u32 { 155 | var index: u32 = undefined; 156 | const rc = vmaFindMemoryTypeIndex(allocator, memoryTypeBits, &allocationCreateInfo, &index); 157 | if (@enumToInt(rc) >= 0) return index; 158 | 159 | if (rc == .ERROR_FEATURE_NOT_PRESENT) return error.VK_FEATURE_NOT_PRESENT; 160 | return error.VK_UNDOCUMENTED_ERROR; 161 | } 162 | 163 | /// \brief Helps to find memoryTypeIndex, given vk.BufferCreateInfo and AllocationCreateInfo. 164 | /// 165 | /// It can be useful e.g. to determine value to be used as PoolCreateInfo::memoryTypeIndex. 166 | /// It internally creates a temporary, dummy buffer that never has memory bound. 167 | /// It is just a convenience function, equivalent to calling: 168 | /// 169 | /// - `vkCreateBuffer` 170 | /// - `vkGetBufferMemoryRequirements` 171 | /// - `FindMemoryTypeIndex` 172 | /// - `vkDestroyBuffer` 173 | pub fn findMemoryTypeIndexForBufferInfo( 174 | allocator: Allocator, 175 | bufferCreateInfo: vk.BufferCreateInfo, 176 | allocationCreateInfo: AllocationCreateInfo, 177 | ) !u32 { 178 | var index: u32 = undefined; 179 | const rc = vmaFindMemoryTypeIndexForBufferInfo(allocator, &bufferCreateInfo, &allocationCreateInfo, &index); 180 | if (@enumToInt(rc) >= 0) return index; 181 | 182 | return switch (rc) { 183 | .ERROR_OUT_OF_HOST_MEMORY => error.VK_OUT_OF_HOST_MEMORY, 184 | .ERROR_OUT_OF_DEVICE_MEMORY => error.VK_OUT_OF_DEVICE_MEMORY, 185 | .ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS => error.VK_INVALID_OPAQUE_CAPTURE_ADDRESS, 186 | .ERROR_FEATURE_NOT_PRESENT => error.VK_FEATURE_NOT_PRESENT, 187 | else => error.VK_UNDOCUMENTED_ERROR, 188 | }; 189 | } 190 | 191 | /// \brief Helps to find memoryTypeIndex, given vk.ImageCreateInfo and AllocationCreateInfo. 192 | /// 193 | /// It can be useful e.g. to determine value to be used as PoolCreateInfo::memoryTypeIndex. 194 | /// It internally creates a temporary, dummy image that never has memory bound. 195 | /// It is just a convenience function, equivalent to calling: 196 | /// 197 | /// - `vkCreateImage` 198 | /// - `vkGetImageMemoryRequirements` 199 | /// - `FindMemoryTypeIndex` 200 | /// - `vkDestroyImage` 201 | pub fn findMemoryTypeIndexForImageInfo( 202 | allocator: Allocator, 203 | imageCreateInfo: vk.ImageCreateInfo, 204 | allocationCreateInfo: AllocationCreateInfo, 205 | ) !u32 { 206 | var index: u32 = undefined; 207 | const rc = vmaFindMemoryTypeIndexForImageInfo(allocator, &imageCreateInfo, &allocationCreateInfo, &index); 208 | if (@enumToInt(rc) >= 0) return index; 209 | 210 | return switch (rc) { 211 | .ERROR_OUT_OF_HOST_MEMORY => error.VK_OUT_OF_HOST_MEMORY, 212 | .ERROR_OUT_OF_DEVICE_MEMORY => error.VK_OUT_OF_DEVICE_MEMORY, 213 | .ERROR_FEATURE_NOT_PRESENT => error.VK_FEATURE_NOT_PRESENT, 214 | else => error.VK_UNDOCUMENTED_ERROR, 215 | }; 216 | } 217 | 218 | /// \brief Allocates Vulkan device memory and creates #Pool object. 219 | /// 220 | /// @param allocator Allocator object. 221 | /// @param pCreateInfo Parameters of pool to create. 222 | /// @param[out] pPool Handle to created pool. 223 | pub fn createPool(allocator: Allocator, createInfo: PoolCreateInfo) !Pool { 224 | var pool: Pool = undefined; 225 | const rc = vmaCreatePool(allocator, &createInfo, &pool); 226 | if (@enumToInt(rc) >= 0) return pool; 227 | 228 | return switch (rc) { 229 | .ERROR_OUT_OF_HOST_MEMORY => error.VK_OUT_OF_HOST_MEMORY, 230 | .ERROR_OUT_OF_DEVICE_MEMORY => error.VK_OUT_OF_DEVICE_MEMORY, 231 | .ERROR_TOO_MANY_OBJECTS => error.VK_TOO_MANY_OBJECTS, 232 | .ERROR_INVALID_EXTERNAL_HANDLE => error.VK_INVALID_EXTERNAL_HANDLE, 233 | .ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS => error.VK_INVALID_OPAQUE_CAPTURE_ADDRESS, 234 | .ERROR_MEMORY_MAP_FAILED => error.VK_MEMORY_MAP_FAILED, 235 | else => error.VK_UNDOCUMENTED_ERROR, 236 | }; 237 | } 238 | 239 | /// \brief Destroys #Pool object and frees Vulkan device memory. 240 | /// fn destroyPool(self: Allocator, pool: Pool) void 241 | pub const destroyPool = vmaDestroyPool; 242 | 243 | /// \brief Retrieves statistics of existing #Pool object. 244 | /// 245 | /// @param allocator Allocator object. 246 | /// @param pool Pool object. 247 | /// @param[out] pPoolStats Statistics of specified pool. 248 | pub fn getPoolStats(allocator: Allocator, pool: Pool) PoolStats { 249 | var stats: PoolStats = undefined; 250 | vmaGetPoolStats(allocator, pool, &stats); 251 | return stats; 252 | } 253 | 254 | /// \brief Marks all allocations in given pool as lost if they are not used in current frame or PoolCreateInfo::frameInUseCount back from now. 255 | /// 256 | /// @param allocator Allocator object. 257 | /// @param pool Pool. 258 | pub fn makePoolAllocationsLost(allocator: Allocator, pool: Pool) void { 259 | vmaMakePoolAllocationsLost(allocator, pool, null); 260 | } 261 | /// \brief Marks all allocations in given pool as lost if they are not used in current frame or PoolCreateInfo::frameInUseCount back from now. 262 | /// 263 | /// @param allocator Allocator object. 264 | /// @param pool Pool. 265 | /// @return the number of allocations that were marked as lost. 266 | pub fn makePoolAllocationsLostAndCount(allocator: Allocator, pool: Pool) usize { 267 | var count: usize = undefined; 268 | vmaMakePoolAllocationsLost(allocator, pool, &count); 269 | return count; 270 | } 271 | 272 | /// \brief Checks magic number in margins around all allocations in given memory pool in search for corruptions. 273 | /// 274 | /// Corruption detection is enabled only when `VMA_DEBUG_DETECT_CORRUPTION` macro is defined to nonzero, 275 | /// `VMA_DEBUG_MARGIN` is defined to nonzero and the pool is created in memory type that is 276 | /// `HOST_VISIBLE` and `HOST_COHERENT`. For more information, see [Corruption detection](@ref debugging_memory_usage_corruption_detection). 277 | /// 278 | /// Possible return values: 279 | /// 280 | /// - `error.VK_FEATURE_NOT_PRESENT` - corruption detection is not enabled for specified pool. 281 | /// - `vk.SUCCESS` - corruption detection has been performed and succeeded. 282 | /// - `error.VK_VALIDATION_FAILED_EXT` - corruption detection has been performed and found memory corruptions around one of the allocations. 283 | /// `VMA_ASSERT` is also fired in that case. 284 | /// - Other value: Error returned by Vulkan, e.g. memory mapping failure. 285 | pub fn checkPoolCorruption(allocator: Allocator, pool: Pool) !void { 286 | const rc = vmaCheckPoolCorruption(allocator, pool); 287 | if (@enumToInt(rc) >= 0) return; 288 | 289 | return switch (rc) { 290 | .ERROR_FEATURE_NOT_PRESENT => error.VMA_CORRUPTION_DETECTION_DISABLED, 291 | .ERROR_VALIDATION_FAILED_EXT => error.VMA_CORRUPTION_DETECTED, 292 | .ERROR_OUT_OF_HOST_MEMORY => error.VK_OUT_OF_HOST_MEMORY, 293 | .ERROR_OUT_OF_DEVICE_MEMORY => error.VK_OUT_OF_DEVICE_MEMORY, 294 | .ERROR_MEMORY_MAP_FAILED => error.VK_MEMORY_MAP_FAILED, 295 | else => error.VK_UNDOCUMENTED_ERROR, 296 | }; 297 | } 298 | 299 | /// \brief Retrieves name of a custom pool. 300 | /// 301 | /// After the call `ppName` is either null or points to an internally-owned null-terminated string 302 | /// containing name of the pool that was previously set. The pointer becomes invalid when the pool is 303 | /// destroyed or its name is changed using SetPoolName(). 304 | pub fn getPoolName(allocator: Allocator, pool: Pool) ?[*:0]const u8 { 305 | var name: ?[*:0]const u8 = undefined; 306 | vmaGetPoolName(allocator, pool, &name); 307 | return name; 308 | } 309 | 310 | /// \brief Sets name of a custom pool. 311 | /// 312 | /// `pName` can be either null or pointer to a null-terminated string with new name for the pool. 313 | /// Function makes internal copy of the string, so it can be changed or freed immediately after this call. 314 | /// fn setPoolName(self: Allocator, pool: Pool, name: ?[*:0]const u8) 315 | pub const setPoolName = vmaSetPoolName; 316 | 317 | /// \brief General purpose memory allocation. 318 | /// 319 | /// @param[out] pAllocation Handle to allocated memory. 320 | /// @param[out] pAllocationInfo Optional. Information about allocated memory. It can be later fetched using function GetAllocationInfo(). 321 | /// 322 | /// You should free the memory using FreeMemory() or FreeMemoryPages(). 323 | /// 324 | /// It is recommended to use AllocateMemoryForBuffer(), AllocateMemoryForImage(), 325 | /// CreateBuffer(), CreateImage() instead whenever possible. 326 | pub fn allocateMemory(allocator: Allocator, vkMemoryRequirements: vk.MemoryRequirements, createInfo: AllocationCreateInfo) !Allocation { 327 | return allocateMemoryAndGetInfo(allocator, vkMemoryRequirements, createInfo, null); 328 | } 329 | pub fn allocateMemoryAndGetInfo(allocator: Allocator, vkMemoryRequirements: vk.MemoryRequirements, createInfo: AllocationCreateInfo, outInfo: ?*AllocationInfo) !Allocation { 330 | var result: Allocation = undefined; 331 | const rc = vmaAllocateMemory(allocator, &vkMemoryRequirements, &createInfo, &result, outInfo); 332 | if (@enumToInt(rc) >= 0) return result; 333 | return switch (rc) { 334 | .ERROR_OUT_OF_HOST_MEMORY => error.VK_OUT_OF_HOST_MEMORY, 335 | .ERROR_OUT_OF_DEVICE_MEMORY => error.VK_OUT_OF_DEVICE_MEMORY, 336 | .ERROR_TOO_MANY_OBJECTS => error.VK_TOO_MANY_OBJECTS, 337 | .ERROR_INVALID_EXTERNAL_HANDLE => error.VK_INVALID_EXTERNAL_HANDLE, 338 | .ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS => error.VK_INVALID_OPAQUE_CAPTURE_ADDRESS, 339 | .ERROR_MEMORY_MAP_FAILED => error.VK_MEMORY_MAP_FAILED, 340 | .ERROR_FRAGMENTED_POOL => error.VK_FRAGMENTED_POOL, 341 | .ERROR_OUT_OF_POOL_MEMORY => error.VK_OUT_OF_POOL_MEMORY, 342 | else => error.VK_UNDOCUMENTED_ERROR, 343 | }; 344 | } 345 | 346 | /// \brief General purpose memory allocation for multiple allocation objects at once. 347 | /// 348 | /// @param allocator Allocator object. 349 | /// @param pVkMemoryRequirements Memory requirements for each allocation. 350 | /// @param pCreateInfo Creation parameters for each alloction. 351 | /// @param allocationCount Number of allocations to make. 352 | /// @param[out] pAllocations Pointer to array that will be filled with handles to created allocations. 353 | /// @param[out] pAllocationInfo Optional. Pointer to array that will be filled with parameters of created allocations. 354 | /// 355 | /// You should free the memory using FreeMemory() or FreeMemoryPages(). 356 | /// 357 | /// Word "pages" is just a suggestion to use this function to allocate pieces of memory needed for sparse binding. 358 | /// It is just a general purpose allocation function able to make multiple allocations at once. 359 | /// It may be internally optimized to be more efficient than calling AllocateMemory() `allocationCount` times. 360 | /// 361 | /// All allocations are made using same parameters. All of them are created out of the same memory pool and type. 362 | /// If any allocation fails, all allocations already made within this function call are also freed, so that when 363 | /// returned result is not `vk.SUCCESS`, `pAllocation` array is always entirely filled with `.Null`. 364 | pub fn allocateMemoryPages(allocator: Allocator, vkMemoryRequirements: vk.MemoryRequirements, createInfo: AllocationCreateInfo, outAllocations: []Allocation) !void { 365 | const rc = vmaAllocateMemoryPages(allocator, &vkMemoryRequirements, &createInfo, outAllocations.len, outAllocations.ptr, null); 366 | if (@enumToInt(rc) >= 0) return; 367 | return switch (rc) { 368 | .ERROR_OUT_OF_HOST_MEMORY => error.VK_OUT_OF_HOST_MEMORY, 369 | .ERROR_OUT_OF_DEVICE_MEMORY => error.VK_OUT_OF_DEVICE_MEMORY, 370 | .ERROR_TOO_MANY_OBJECTS => error.VK_TOO_MANY_OBJECTS, 371 | .ERROR_INVALID_EXTERNAL_HANDLE => error.VK_INVALID_EXTERNAL_HANDLE, 372 | .ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS => error.VK_INVALID_OPAQUE_CAPTURE_ADDRESS, 373 | .ERROR_MEMORY_MAP_FAILED => error.VK_MEMORY_MAP_FAILED, 374 | .ERROR_FRAGMENTED_POOL => error.VK_FRAGMENTED_POOL, 375 | .ERROR_OUT_OF_POOL_MEMORY => error.VK_OUT_OF_POOL_MEMORY, 376 | else => error.VK_UNDOCUMENTED_ERROR, 377 | }; 378 | } 379 | pub fn allocateMemoryPagesAndGetInfo(allocator: Allocator, vkMemoryRequirements: vk.MemoryRequirements, createInfo: AllocationCreateInfo, outAllocations: []Allocation, outInfo: []AllocationInfo) !void { 380 | assert(outAllocations.len == outInfo.len); 381 | const rc = vmaAllocateMemoryPages(allocator, &vkMemoryRequirements, &createInfo, outAllocations.len, outAllocations.ptr, outInfo.ptr); 382 | if (@enumToInt(rc) >= 0) return; 383 | return switch (rc) { 384 | .ERROR_OUT_OF_HOST_MEMORY => error.VK_OUT_OF_HOST_MEMORY, 385 | .ERROR_OUT_OF_DEVICE_MEMORY => error.VK_OUT_OF_DEVICE_MEMORY, 386 | .ERROR_TOO_MANY_OBJECTS => error.VK_TOO_MANY_OBJECTS, 387 | .ERROR_INVALID_EXTERNAL_HANDLE => error.VK_INVALID_EXTERNAL_HANDLE, 388 | .ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS => error.VK_INVALID_OPAQUE_CAPTURE_ADDRESS, 389 | .ERROR_MEMORY_MAP_FAILED => error.VK_MEMORY_MAP_FAILED, 390 | .ERROR_FRAGMENTED_POOL => error.VK_FRAGMENTED_POOL, 391 | .ERROR_OUT_OF_POOL_MEMORY => error.VK_OUT_OF_POOL_MEMORY, 392 | else => error.VK_UNDOCUMENTED_ERROR, 393 | }; 394 | } 395 | 396 | /// @param[out] pAllocation Handle to allocated memory. 397 | /// @param[out] pAllocationInfo Optional. Information about allocated memory. It can be later fetched using function GetAllocationInfo(). 398 | /// 399 | /// You should free the memory using FreeMemory(). 400 | pub fn allocateMemoryForBuffer(allocator: Allocator, buffer: vk.Buffer, createInfo: AllocationCreateInfo) !Allocation { 401 | return allocateMemoryForBufferAndGetInfo(allocator, buffer, createInfo, null); 402 | } 403 | pub fn allocateMemoryForBufferAndGetInfo(allocator: Allocator, buffer: vk.Buffer, createInfo: AllocationCreateInfo, outInfo: ?*AllocationInfo) !Allocation { 404 | var result: Allocation = undefined; 405 | const rc = vmaAllocateMemoryForBuffer(allocator, buffer, &createInfo, &result, outInfo); 406 | if (@enumToInt(rc) >= 0) return result; 407 | 408 | return switch (rc) { 409 | .ERROR_OUT_OF_HOST_MEMORY => error.VK_OUT_OF_HOST_MEMORY, 410 | .ERROR_OUT_OF_DEVICE_MEMORY => error.VK_OUT_OF_DEVICE_MEMORY, 411 | .ERROR_TOO_MANY_OBJECTS => error.VK_TOO_MANY_OBJECTS, 412 | .ERROR_INVALID_EXTERNAL_HANDLE => error.VK_INVALID_EXTERNAL_HANDLE, 413 | .ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS => error.VK_INVALID_OPAQUE_CAPTURE_ADDRESS, 414 | .ERROR_MEMORY_MAP_FAILED => error.VK_MEMORY_MAP_FAILED, 415 | .ERROR_FRAGMENTED_POOL => error.VK_FRAGMENTED_POOL, 416 | .ERROR_OUT_OF_POOL_MEMORY => error.VK_OUT_OF_POOL_MEMORY, 417 | else => error.VK_UNDOCUMENTED_ERROR, 418 | }; 419 | } 420 | 421 | /// Function similar to AllocateMemoryForBuffer(). 422 | pub fn allocateMemoryForImage(allocator: Allocator, image: vk.Image, createInfo: AllocationCreateInfo) !Allocation { 423 | return allocateMemoryForImageAndGetInfo(allocator, image, createInfo, null); 424 | } 425 | pub fn allocateMemoryForImageAndGetInfo(allocator: Allocator, image: vk.Image, createInfo: AllocationCreateInfo, outInfo: ?*AllocationInfo) !Allocation { 426 | var result: Allocation = undefined; 427 | const rc = vmaAllocateMemoryForImage(allocator, image, &createInfo, &result, outInfo); 428 | if (@enumToInt(rc) >= 0) return result; 429 | 430 | return switch (rc) { 431 | .ERROR_OUT_OF_HOST_MEMORY => error.VK_OUT_OF_HOST_MEMORY, 432 | .ERROR_OUT_OF_DEVICE_MEMORY => error.VK_OUT_OF_DEVICE_MEMORY, 433 | .ERROR_TOO_MANY_OBJECTS => error.VK_TOO_MANY_OBJECTS, 434 | .ERROR_INVALID_EXTERNAL_HANDLE => error.VK_INVALID_EXTERNAL_HANDLE, 435 | .ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS => error.VK_INVALID_OPAQUE_CAPTURE_ADDRESS, 436 | .ERROR_MEMORY_MAP_FAILED => error.VK_MEMORY_MAP_FAILED, 437 | .ERROR_FRAGMENTED_POOL => error.VK_FRAGMENTED_POOL, 438 | .ERROR_OUT_OF_POOL_MEMORY => error.VK_OUT_OF_POOL_MEMORY, 439 | else => error.VK_UNDOCUMENTED_ERROR, 440 | }; 441 | } 442 | 443 | /// \brief Frees memory previously allocated using AllocateMemory(), AllocateMemoryForBuffer(), or AllocateMemoryForImage(). 444 | /// 445 | /// Passing `.Null` as `allocation` is valid. Such function call is just skipped. 446 | /// fn freeMemory(allocator: Allocator, allocation: Allocation) void 447 | pub const freeMemory = vmaFreeMemory; 448 | 449 | /// \brief Frees memory and destroys multiple allocations. 450 | /// 451 | /// Word "pages" is just a suggestion to use this function to free pieces of memory used for sparse binding. 452 | /// It is just a general purpose function to free memory and destroy allocations made using e.g. AllocateMemory(), 453 | /// AllocateMemoryPages() and other functions. 454 | /// It may be internally optimized to be more efficient than calling FreeMemory() `allocationCount` times. 455 | /// 456 | /// Allocations in `pAllocations` array can come from any memory pools and types. 457 | /// Passing `.Null` as elements of `pAllocations` array is valid. Such entries are just skipped. 458 | pub fn freeMemoryPages(allocator: Allocator, allocations: []Allocation) void { 459 | vmaFreeMemoryPages(allocator, allocations.len, allocations.ptr); 460 | } 461 | 462 | /// \brief Returns current information about specified allocation and atomically marks it as used in current frame. 463 | /// 464 | /// Current paramters of given allocation are returned in `pAllocationInfo`. 465 | /// 466 | /// This function also atomically "touches" allocation - marks it as used in current frame, 467 | /// just like TouchAllocation(). 468 | /// If the allocation is in lost state, `pAllocationInfo->deviceMemory == .Null`. 469 | /// 470 | /// Although this function uses atomics and doesn't lock any mutex, so it should be quite efficient, 471 | /// you can avoid calling it too often. 472 | /// 473 | /// - You can retrieve same AllocationInfo structure while creating your resource, from function 474 | /// CreateBuffer(), CreateImage(). You can remember it if you are sure parameters don't change 475 | /// (e.g. due to defragmentation or allocation becoming lost). 476 | /// - If you just want to check if allocation is not lost, TouchAllocation() will work faster. 477 | pub fn getAllocationInfo(allocator: Allocator, allocation: Allocation) AllocationInfo { 478 | var info: AllocationInfo = undefined; 479 | vmaGetAllocationInfo(allocator, allocation, &info); 480 | return info; 481 | } 482 | 483 | /// \brief Returns `true` if allocation is not lost and atomically marks it as used in current frame. 484 | /// 485 | /// If the allocation has been created with #.canBecomeLost flag, 486 | /// this function returns `true` if it's not in lost state, so it can still be used. 487 | /// It then also atomically "touches" the allocation - marks it as used in current frame, 488 | /// so that you can be sure it won't become lost in current frame or next `frameInUseCount` frames. 489 | /// 490 | /// If the allocation is in lost state, the function returns `false`. 491 | /// Memory of such allocation, as well as buffer or image bound to it, should not be used. 492 | /// Lost allocation and the buffer/image still need to be destroyed. 493 | /// 494 | /// If the allocation has been created without #.canBecomeLost flag, 495 | /// this function always returns `true`. 496 | pub fn touchAllocation(allocator: Allocator, allocation: Allocation) bool { 497 | return vmaTouchAllocation(allocator, allocation) != 0; 498 | } 499 | 500 | /// \brief Sets pUserData in given allocation to new value. 501 | /// 502 | /// If the allocation was created with VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT, 503 | /// pUserData must be either null, or pointer to a null-terminated string. The function 504 | /// makes local copy of the string and sets it as allocation's `pUserData`. String 505 | /// passed as pUserData doesn't need to be valid for whole lifetime of the allocation - 506 | /// you can free it after this call. String previously pointed by allocation's 507 | /// pUserData is freed from memory. 508 | /// 509 | /// If the flag was not used, the value of pointer `pUserData` is just copied to 510 | /// allocation's `pUserData`. It is opaque, so you can use it however you want - e.g. 511 | /// as a pointer, ordinal number or some handle to you own data. 512 | /// fn setAllocationUserData(allocator: Allocator, allocation: Allocation, pUserData: ?*anyopaque) void 513 | pub const setAllocationUserData = vmaSetAllocationUserData; 514 | 515 | /// \brief Creates new allocation that is in lost state from the beginning. 516 | /// 517 | /// It can be useful if you need a dummy, non-null allocation. 518 | /// 519 | /// You still need to destroy created object using FreeMemory(). 520 | /// 521 | /// Returned allocation is not tied to any specific memory pool or memory type and 522 | /// not bound to any image or buffer. It has size = 0. It cannot be turned into 523 | /// a real, non-empty allocation. 524 | pub fn createLostAllocation(allocator: Allocator) Allocation { 525 | var allocation: Allocation = undefined; 526 | vmaCreateLostAllocation(allocator, &allocation); 527 | return allocation; 528 | } 529 | 530 | /// \brief Maps memory represented by given allocation and returns pointer to it. 531 | /// 532 | /// Maps memory represented by given allocation to make it accessible to CPU code. 533 | /// When succeeded, `*ppData` contains pointer to first byte of this memory. 534 | /// If the allocation is part of bigger `vk.DeviceMemory` block, the pointer is 535 | /// correctly offseted to the beginning of region assigned to this particular 536 | /// allocation. 537 | /// 538 | /// Mapping is internally reference-counted and synchronized, so despite raw Vulkan 539 | /// function `vkMapMemory()` cannot be used to map same block of `vk.DeviceMemory` 540 | /// multiple times simultaneously, it is safe to call this function on allocations 541 | /// assigned to the same memory block. Actual Vulkan memory will be mapped on first 542 | /// mapping and unmapped on last unmapping. 543 | /// 544 | /// If the function succeeded, you must call UnmapMemory() to unmap the 545 | /// allocation when mapping is no longer needed or before freeing the allocation, at 546 | /// the latest. 547 | /// 548 | /// It also safe to call this function multiple times on the same allocation. You 549 | /// must call UnmapMemory() same number of times as you called MapMemory(). 550 | /// 551 | /// It is also safe to call this function on allocation created with 552 | /// #VMA_ALLOCATION_CREATE_MAPPED_BIT flag. Its memory stays mapped all the time. 553 | /// You must still call UnmapMemory() same number of times as you called 554 | /// MapMemory(). You must not call UnmapMemory() additional time to free the 555 | /// "0-th" mapping made automatically due to #VMA_ALLOCATION_CREATE_MAPPED_BIT flag. 556 | /// 557 | /// This function fails when used on allocation made in memory type that is not 558 | /// `HOST_VISIBLE`. 559 | /// 560 | /// This function always fails when called for allocation that was created with 561 | /// #VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT flag. Such allocations cannot be 562 | /// mapped. 563 | /// 564 | /// This function doesn't automatically flush or invalidate caches. 565 | /// If the allocation is made from a memory types that is not `HOST_COHERENT`, 566 | /// you also need to use InvalidateAllocation() / FlushAllocation(), as required by Vulkan specification. 567 | pub fn mapMemory(allocator: Allocator, allocation: Allocation, comptime T: type) ![*]T { 568 | var data: *anyopaque = undefined; 569 | const rc = vmaMapMemory(allocator, allocation, &data); 570 | if (@enumToInt(rc) >= 0) return @intToPtr([*]T, @ptrToInt(data)); 571 | return switch (rc) { 572 | .ERROR_OUT_OF_HOST_MEMORY => error.VK_OUT_OF_HOST_MEMORY, 573 | .ERROR_OUT_OF_DEVICE_MEMORY => error.VK_OUT_OF_DEVICE_MEMORY, 574 | .ERROR_MEMORY_MAP_FAILED => error.VK_MEMORY_MAP_FAILED, 575 | else => error.VK_UNDOCUMENTED_ERROR, 576 | }; 577 | } 578 | 579 | /// \brief Unmaps memory represented by given allocation, mapped previously using MapMemory(). 580 | /// 581 | /// For details, see description of MapMemory(). 582 | /// 583 | /// This function doesn't automatically flush or invalidate caches. 584 | /// If the allocation is made from a memory types that is not `HOST_COHERENT`, 585 | /// you also need to use InvalidateAllocation() / FlushAllocation(), as required by Vulkan specification. 586 | /// fn unmapMemory(self: Allocator, allocation: Allocation) void 587 | pub const unmapMemory = vmaUnmapMemory; 588 | 589 | /// \brief Flushes memory of given allocation. 590 | /// 591 | /// Calls `vkFlushMappedMemoryRanges()` for memory associated with given range of given allocation. 592 | /// It needs to be called after writing to a mapped memory for memory types that are not `HOST_COHERENT`. 593 | /// Unmap operation doesn't do that automatically. 594 | /// 595 | /// - `offset` must be relative to the beginning of allocation. 596 | /// - `size` can be `vk.WHOLE_SIZE`. It means all memory from `offset` the the end of given allocation. 597 | /// - `offset` and `size` don't have to be aligned. 598 | /// They are internally rounded down/up to multiply of `nonCoherentAtomSize`. 599 | /// - If `size` is 0, this call is ignored. 600 | /// - If memory type that the `allocation` belongs to is not `HOST_VISIBLE` or it is `HOST_COHERENT`, 601 | /// this call is ignored. 602 | /// 603 | /// Warning! `offset` and `size` are relative to the contents of given `allocation`. 604 | /// If you mean whole allocation, you can pass 0 and `vk.WHOLE_SIZE`, respectively. 605 | /// Do not pass allocation's offset as `offset`!!! 606 | /// fn flushAllocation(allocator: Allocator, allocation: Allocation, offset: vk.DeviceSize, size: vk.DeviceSize) void 607 | pub const flushAllocation = vmaFlushAllocation; 608 | 609 | /// \brief Invalidates memory of given allocation. 610 | /// 611 | /// Calls `vkInvalidateMappedMemoryRanges()` for memory associated with given range of given allocation. 612 | /// It needs to be called before reading from a mapped memory for memory types that are not `HOST_COHERENT`. 613 | /// Map operation doesn't do that automatically. 614 | /// 615 | /// - `offset` must be relative to the beginning of allocation. 616 | /// - `size` can be `vk.WHOLE_SIZE`. It means all memory from `offset` the the end of given allocation. 617 | /// - `offset` and `size` don't have to be aligned. 618 | /// They are internally rounded down/up to multiply of `nonCoherentAtomSize`. 619 | /// - If `size` is 0, this call is ignored. 620 | /// - If memory type that the `allocation` belongs to is not `HOST_VISIBLE` or it is `HOST_COHERENT`, 621 | /// this call is ignored. 622 | /// 623 | /// Warning! `offset` and `size` are relative to the contents of given `allocation`. 624 | /// If you mean whole allocation, you can pass 0 and `vk.WHOLE_SIZE`, respectively. 625 | /// Do not pass allocation's offset as `offset`!!! 626 | /// fn invalidateAllocation(allocator: Allocator, allocation: Allocation, offset: vk.DeviceSize, size: vk.DeviceSize) void 627 | pub const invalidateAllocation = vmaInvalidateAllocation; 628 | 629 | /// \brief Checks magic number in margins around all allocations in given memory types (in both default and custom pools) in search for corruptions. 630 | /// 631 | /// @param memoryTypeBits Bit mask, where each bit set means that a memory type with that index should be checked. 632 | /// 633 | /// Corruption detection is enabled only when `VMA_DEBUG_DETECT_CORRUPTION` macro is defined to nonzero, 634 | /// `VMA_DEBUG_MARGIN` is defined to nonzero and only for memory types that are 635 | /// `HOST_VISIBLE` and `HOST_COHERENT`. For more information, see [Corruption detection](@ref debugging_memory_usage_corruption_detection). 636 | /// 637 | /// Possible return values: 638 | /// 639 | /// - `error.VK_FEATURE_NOT_PRESENT` - corruption detection is not enabled for any of specified memory types. 640 | /// - `vk.SUCCESS` - corruption detection has been performed and succeeded. 641 | /// - `error.VK_VALIDATION_FAILED_EXT` - corruption detection has been performed and found memory corruptions around one of the allocations. 642 | /// `VMA_ASSERT` is also fired in that case. 643 | /// - Other value: Error returned by Vulkan, e.g. memory mapping failure. 644 | pub fn checkCorruption(allocator: Allocator, memoryTypeBits: u32) !void { 645 | const rc = vmaCheckCorruption(allocator, memoryTypeBits); 646 | if (@enumToInt(rc) >= 0) return; 647 | 648 | return switch (rc) { 649 | .ERROR_FEATURE_NOT_PRESENT => error.VMA_CORRUPTION_DETECTION_DISABLED, 650 | .ERROR_VALIDATION_FAILED_EXT => error.VMA_CORRUPTION_DETECTED, 651 | .ERROR_OUT_OF_HOST_MEMORY => error.VK_OUT_OF_HOST_MEMORY, 652 | .ERROR_OUT_OF_DEVICE_MEMORY => error.VK_OUT_OF_DEVICE_MEMORY, 653 | .ERROR_MEMORY_MAP_FAILED => error.VK_MEMORY_MAP_FAILED, 654 | else => error.VK_UNDOCUMENTED_ERROR, 655 | }; 656 | } 657 | 658 | /// \brief Begins defragmentation process. 659 | /// 660 | /// @param allocator Allocator object. 661 | /// @param pInfo Structure filled with parameters of defragmentation. 662 | /// @param[out] pStats Optional. Statistics of defragmentation. You can pass null if you are not interested in this information. 663 | /// @param[out] pContext Context object that must be passed to DefragmentationEnd() to finish defragmentation. 664 | /// @return `vk.SUCCESS` and `*pContext == null` if defragmentation finished within this function call. `vk.NOT_READY` and `*pContext != null` if defragmentation has been started and you need to call DefragmentationEnd() to finish it. Negative value in case of error. 665 | /// 666 | /// Use this function instead of old, deprecated Defragment(). 667 | /// 668 | /// Warning! Between the call to DefragmentationBegin() and DefragmentationEnd(): 669 | /// 670 | /// - You should not use any of allocations passed as `pInfo->pAllocations` or 671 | /// any allocations that belong to pools passed as `pInfo->pPools`, 672 | /// including calling GetAllocationInfo(), TouchAllocation(), or access 673 | /// their data. 674 | /// - Some mutexes protecting internal data structures may be locked, so trying to 675 | /// make or free any allocations, bind buffers or images, map memory, or launch 676 | /// another simultaneous defragmentation in between may cause stall (when done on 677 | /// another thread) or deadlock (when done on the same thread), unless you are 678 | /// 100% sure that defragmented allocations are in different pools. 679 | /// - Information returned via `pStats` and `pInfo->pAllocationsChanged` are undefined. 680 | /// They become valid after call to DefragmentationEnd(). 681 | /// - If `pInfo->commandBuffer` is not null, you must submit that command buffer 682 | /// and make sure it finished execution before calling DefragmentationEnd(). 683 | /// 684 | /// For more information and important limitations regarding defragmentation, see documentation chapter: 685 | /// [Defragmentation](@ref defragmentation). 686 | pub fn defragmentationBegin(allocator: Allocator, info: DefragmentationInfo2) !DefragmentationContext { 687 | return defragmentationBeginWithStats(allocator, info, null); 688 | } 689 | pub fn defragmentationBeginWithStats(allocator: Allocator, info: DefragmentationInfo2, stats: ?*DefragmentationStats) !DefragmentationContext { 690 | var context: DefragmentationContext = undefined; 691 | const rc = vmaDefragmentationBegin(allocator, &info, stats, &context); 692 | if (@enumToInt(rc) >= 0) return context; // includes NOT_READY 693 | return switch (rc) { 694 | .ERROR_OUT_OF_HOST_MEMORY => error.VK_OUT_OF_HOST_MEMORY, 695 | .ERROR_OUT_OF_DEVICE_MEMORY => error.VK_OUT_OF_DEVICE_MEMORY, 696 | .ERROR_TOO_MANY_OBJECTS => error.VK_TOO_MANY_OBJECTS, 697 | .ERROR_INVALID_EXTERNAL_HANDLE => error.VK_INVALID_EXTERNAL_HANDLE, 698 | .ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS => error.VK_INVALID_OPAQUE_CAPTURE_ADDRESS, 699 | .ERROR_MEMORY_MAP_FAILED => error.VK_MEMORY_MAP_FAILED, 700 | .ERROR_FRAGMENTED_POOL => error.VK_FRAGMENTED_POOL, 701 | .ERROR_OUT_OF_POOL_MEMORY => error.VK_OUT_OF_POOL_MEMORY, 702 | else => error.VK_UNDOCUMENTED_ERROR, 703 | }; 704 | } 705 | 706 | /// \brief Ends defragmentation process. 707 | /// 708 | /// Use this function to finish defragmentation started by DefragmentationBegin(). 709 | /// It is safe to pass `context == null`. The function then does nothing. 710 | pub fn defragmentationEnd(allocator: Allocator, context: DefragmentationContext) !void { 711 | const rc = vmaDefragmentationEnd(allocator, context); 712 | if (@enumToInt(rc) >= 0) return; 713 | return switch (rc) { 714 | .ERROR_OUT_OF_HOST_MEMORY => error.VK_OUT_OF_HOST_MEMORY, 715 | .ERROR_OUT_OF_DEVICE_MEMORY => error.VK_OUT_OF_DEVICE_MEMORY, 716 | .ERROR_TOO_MANY_OBJECTS => error.VK_TOO_MANY_OBJECTS, 717 | .ERROR_INVALID_EXTERNAL_HANDLE => error.VK_INVALID_EXTERNAL_HANDLE, 718 | .ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS => error.VK_INVALID_OPAQUE_CAPTURE_ADDRESS, 719 | .ERROR_MEMORY_MAP_FAILED => error.VK_MEMORY_MAP_FAILED, 720 | .ERROR_FRAGMENTED_POOL => error.VK_FRAGMENTED_POOL, 721 | .ERROR_OUT_OF_POOL_MEMORY => error.VK_OUT_OF_POOL_MEMORY, 722 | else => error.VK_UNDOCUMENTED_ERROR, 723 | }; 724 | } 725 | 726 | /// \brief Binds buffer to allocation. 727 | /// 728 | /// Binds specified buffer to region of memory represented by specified allocation. 729 | /// Gets `vk.DeviceMemory` handle and offset from the allocation. 730 | /// If you want to create a buffer, allocate memory for it and bind them together separately, 731 | /// you should use this function for binding instead of standard `vkBindBufferMemory()`, 732 | /// because it ensures proper synchronization so that when a `vk.DeviceMemory` object is used by multiple 733 | /// allocations, calls to `vkBind*Memory()` or `vkMapMemory()` won't happen from multiple threads simultaneously 734 | /// (which is illegal in Vulkan). 735 | /// 736 | /// It is recommended to use function createBuffer() instead of this one. 737 | pub fn bindBufferMemory(allocator: Allocator, allocation: Allocation, buffer: vk.Buffer) !void { 738 | const rc = vmaBindBufferMemory(allocator, allocation, buffer); 739 | if (@enumToInt(rc) >= 0) return; 740 | return switch (rc) { 741 | .ERROR_OUT_OF_HOST_MEMORY => error.VK_OUT_OF_HOST_MEMORY, 742 | .ERROR_OUT_OF_DEVICE_MEMORY => error.VK_OUT_OF_DEVICE_MEMORY, 743 | .ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS => error.VK_INVALID_OPAQUE_CAPTURE_ADDRESS, 744 | else => error.VK_UNDOCUMENTED_ERROR, 745 | }; 746 | } 747 | 748 | /// \brief Binds buffer to allocation with additional parameters. 749 | /// 750 | /// @param allocationLocalOffset Additional offset to be added while binding, relative to the beginnig of the `allocation`. Normally it should be 0. 751 | /// @param pNext A chain of structures to be attached to `vk.BindBufferMemoryInfoKHR` structure used internally. Normally it should be null. 752 | /// 753 | /// This function is similar to BindBufferMemory(), but it provides additional parameters. 754 | /// 755 | /// If `pNext` is not null, #Allocator object must have been created with #VMA_ALLOCATOR_CREATE_KHR_BIND_MEMORY2_BIT flag 756 | /// or with AllocatorCreateInfo::vulkanApiVersion `== vk.API_VERSION_1_1`. Otherwise the call fails. 757 | pub fn bindBufferMemory2(allocator: Allocator, allocation: Allocation, allocationLocalOffset: vk.DeviceSize, buffer: vk.Buffer, pNext: ?*const anyopaque) !void { 758 | const rc = vmaBindBufferMemory2(allocator, allocation, allocationLocalOffset, buffer, pNext); 759 | if (@enumToInt(rc) >= 0) return; 760 | return switch (rc) { 761 | .ERROR_OUT_OF_HOST_MEMORY => error.VK_OUT_OF_HOST_MEMORY, 762 | .ERROR_OUT_OF_DEVICE_MEMORY => error.VK_OUT_OF_DEVICE_MEMORY, 763 | .ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS => error.VK_INVALID_OPAQUE_CAPTURE_ADDRESS, 764 | else => error.VK_UNDOCUMENTED_ERROR, 765 | }; 766 | } 767 | 768 | /// \brief Binds image to allocation. 769 | /// 770 | /// Binds specified image to region of memory represented by specified allocation. 771 | /// Gets `vk.DeviceMemory` handle and offset from the allocation. 772 | /// If you want to create an image, allocate memory for it and bind them together separately, 773 | /// you should use this function for binding instead of standard `vkBindImageMemory()`, 774 | /// because it ensures proper synchronization so that when a `vk.DeviceMemory` object is used by multiple 775 | /// allocations, calls to `vkBind*Memory()` or `vkMapMemory()` won't happen from multiple threads simultaneously 776 | /// (which is illegal in Vulkan). 777 | /// 778 | /// It is recommended to use function CreateImage() instead of this one. 779 | pub fn bindImageMemory(allocator: Allocator, allocation: Allocation, image: vk.Image) !void { 780 | const rc = vmaBindImageMemory(allocator, allocation, image); 781 | if (@enumToInt(rc) >= 0) return; 782 | return switch (rc) { 783 | .ERROR_OUT_OF_HOST_MEMORY => error.VK_OUT_OF_HOST_MEMORY, 784 | .ERROR_OUT_OF_DEVICE_MEMORY => error.VK_OUT_OF_DEVICE_MEMORY, 785 | else => error.VK_UNDOCUMENTED_ERROR, 786 | }; 787 | } 788 | 789 | /// \brief Binds image to allocation with additional parameters. 790 | /// 791 | /// @param allocationLocalOffset Additional offset to be added while binding, relative to the beginnig of the `allocation`. Normally it should be 0. 792 | /// @param pNext A chain of structures to be attached to `vk.BindImageMemoryInfoKHR` structure used internally. Normally it should be null. 793 | /// 794 | /// This function is similar to BindImageMemory(), but it provides additional parameters. 795 | /// 796 | /// If `pNext` is not null, #Allocator object must have been created with #VMA_ALLOCATOR_CREATE_KHR_BIND_MEMORY2_BIT flag 797 | /// or with AllocatorCreateInfo::vulkanApiVersion `== vk.API_VERSION_1_1`. Otherwise the call fails. 798 | pub fn bindImageMemory2(allocator: Allocator, allocation: Allocation, allocationLocalOffset: vk.DeviceSize, image: vk.Image, pNext: ?*const anyopaque) !void { 799 | const rc = vmaBindImageMemory2(allocator, allocation, allocationLocalOffset, image, pNext); 800 | if (@enumToInt(rc) >= 0) return; 801 | return switch (rc) { 802 | .ERROR_OUT_OF_HOST_MEMORY => error.VK_OUT_OF_HOST_MEMORY, 803 | .ERROR_OUT_OF_DEVICE_MEMORY => error.VK_OUT_OF_DEVICE_MEMORY, 804 | .ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS => error.VK_INVALID_OPAQUE_CAPTURE_ADDRESS, 805 | else => error.VK_UNDOCUMENTED_ERROR, 806 | }; 807 | } 808 | 809 | /// @param[out] pBuffer Buffer that was created. 810 | /// @param[out] pAllocation Allocation that was created. 811 | /// @param[out] pAllocationInfo Optional. Information about allocated memory. It can be later fetched using function GetAllocationInfo(). 812 | /// 813 | /// This function automatically: 814 | /// 815 | /// -# Creates buffer. 816 | /// -# Allocates appropriate memory for it. 817 | /// -# Binds the buffer with the memory. 818 | /// 819 | /// If any of these operations fail, buffer and allocation are not created, 820 | /// returned value is negative error code, *pBuffer and *pAllocation are null. 821 | /// 822 | /// If the function succeeded, you must destroy both buffer and allocation when you 823 | /// no longer need them using either convenience function DestroyBuffer() or 824 | /// separately, using `vkDestroyBuffer()` and FreeMemory(). 825 | /// 826 | /// If VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT flag was used, 827 | /// vk.KHR_dedicated_allocation extension is used internally to query driver whether 828 | /// it requires or prefers the new buffer to have dedicated allocation. If yes, 829 | /// and if dedicated allocation is possible (AllocationCreateInfo::pool is null 830 | /// and VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT is not used), it creates dedicated 831 | /// allocation for this buffer, just like when using 832 | /// VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT. 833 | pub fn createBuffer( 834 | allocator: Allocator, 835 | bufferCreateInfo: vk.BufferCreateInfo, 836 | allocationCreateInfo: AllocationCreateInfo, 837 | ) !CreateBufferResult { 838 | return createBufferAndGetInfo(allocator, bufferCreateInfo, allocationCreateInfo, null); 839 | } 840 | pub fn createBufferAndGetInfo( 841 | allocator: Allocator, 842 | bufferCreateInfo: vk.BufferCreateInfo, 843 | allocationCreateInfo: AllocationCreateInfo, 844 | outInfo: ?*AllocationInfo, 845 | ) !CreateBufferResult { 846 | var result: CreateBufferResult = undefined; 847 | const rc = vmaCreateBuffer( 848 | allocator, 849 | &bufferCreateInfo, 850 | &allocationCreateInfo, 851 | &result.buffer, 852 | &result.allocation, 853 | outInfo, 854 | ); 855 | if (@enumToInt(rc) >= 0) return result; 856 | return switch (rc) { 857 | .ERROR_OUT_OF_HOST_MEMORY => error.VK_OUT_OF_HOST_MEMORY, 858 | .ERROR_OUT_OF_DEVICE_MEMORY => error.VK_OUT_OF_DEVICE_MEMORY, 859 | .ERROR_TOO_MANY_OBJECTS => error.VK_TOO_MANY_OBJECTS, 860 | .ERROR_INVALID_EXTERNAL_HANDLE => error.VK_INVALID_EXTERNAL_HANDLE, 861 | .ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS => error.VK_INVALID_OPAQUE_CAPTURE_ADDRESS, 862 | .ERROR_MEMORY_MAP_FAILED => error.VK_MEMORY_MAP_FAILED, 863 | .ERROR_FRAGMENTED_POOL => error.VK_FRAGMENTED_POOL, 864 | .ERROR_OUT_OF_POOL_MEMORY => error.VK_OUT_OF_POOL_MEMORY, 865 | else => error.VK_UNDOCUMENTED_ERROR, 866 | }; 867 | } 868 | pub const CreateBufferResult = struct { 869 | buffer: vk.Buffer, 870 | allocation: Allocation, 871 | }; 872 | 873 | /// \brief Destroys Vulkan buffer and frees allocated memory. 874 | /// 875 | /// This is just a convenience function equivalent to: 876 | /// 877 | /// \code 878 | /// vkDestroyBuffer(device, buffer, allocationCallbacks); 879 | /// FreeMemory(allocator, allocation); 880 | /// \endcode 881 | /// 882 | /// It it safe to pass null as buffer and/or allocation. 883 | /// fn destroyBuffer(allocator: Allocator, buffer: vk.Buffer, allocation: Allocation) void 884 | pub const destroyBuffer = vmaDestroyBuffer; 885 | 886 | /// Function similar to CreateBuffer(). 887 | pub fn createImage( 888 | allocator: Allocator, 889 | imageCreateInfo: vk.ImageCreateInfo, 890 | allocationCreateInfo: AllocationCreateInfo, 891 | ) !CreateImageResult { 892 | return createImageAndGetInfo(allocator, imageCreateInfo, allocationCreateInfo, null); 893 | } 894 | pub fn createImageAndGetInfo( 895 | allocator: Allocator, 896 | imageCreateInfo: vk.ImageCreateInfo, 897 | allocationCreateInfo: AllocationCreateInfo, 898 | outInfo: ?*AllocationInfo, 899 | ) !CreateImageResult { 900 | var result: CreateImageResult = undefined; 901 | const rc = vmaCreateImage( 902 | allocator, 903 | &imageCreateInfo, 904 | &allocationCreateInfo, 905 | &result.image, 906 | &result.allocation, 907 | outInfo, 908 | ); 909 | if (@enumToInt(rc) >= 0) return result; 910 | return switch (rc) { 911 | .ERROR_OUT_OF_HOST_MEMORY => error.VK_OUT_OF_HOST_MEMORY, 912 | .ERROR_OUT_OF_DEVICE_MEMORY => error.VK_OUT_OF_DEVICE_MEMORY, 913 | .ERROR_TOO_MANY_OBJECTS => error.VK_TOO_MANY_OBJECTS, 914 | .ERROR_INVALID_EXTERNAL_HANDLE => error.VK_INVALID_EXTERNAL_HANDLE, 915 | .ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS => error.VK_INVALID_OPAQUE_CAPTURE_ADDRESS, 916 | .ERROR_MEMORY_MAP_FAILED => error.VK_MEMORY_MAP_FAILED, 917 | .ERROR_FRAGMENTED_POOL => error.VK_FRAGMENTED_POOL, 918 | .ERROR_OUT_OF_POOL_MEMORY => error.VK_OUT_OF_POOL_MEMORY, 919 | else => error.VK_UNDOCUMENTED_ERROR, 920 | }; 921 | } 922 | pub const CreateImageResult = struct { 923 | image: vk.Image, 924 | allocation: Allocation, 925 | }; 926 | 927 | /// \brief Destroys Vulkan image and frees allocated memory. 928 | /// 929 | /// This is just a convenience function equivalent to: 930 | /// 931 | /// \code 932 | /// vkDestroyImage(device, image, allocationCallbacks); 933 | /// FreeMemory(allocator, allocation); 934 | /// \endcode 935 | /// 936 | /// It is safe to pass null as image and/or allocation. 937 | /// fn destroyImage(self: Allocator, image: vk.Image, allocation: Allocation) void 938 | pub const destroyImage = vmaDestroyImage; 939 | }; 940 | 941 | /// Callback function called after successful vkAllocateMemory. 942 | pub const PFN_AllocateDeviceMemoryFunction = fn ( 943 | allocator: Allocator, 944 | memoryType: u32, 945 | memory: vk.DeviceMemory, 946 | size: vk.DeviceSize, 947 | ) callconv(vk.CallConv) void; 948 | 949 | /// Callback function called before vkFreeMemory. 950 | pub const PFN_FreeDeviceMemoryFunction = fn ( 951 | allocator: Allocator, 952 | memoryType: u32, 953 | memory: vk.DeviceMemory, 954 | size: vk.DeviceSize, 955 | ) callconv(vk.CallConv) void; 956 | 957 | /// \brief Set of callbacks that the library will call for `vkAllocateMemory` and `vkFreeMemory`. 958 | /// 959 | /// Provided for informative purpose, e.g. to gather statistics about number of 960 | /// allocations or total amount of memory allocated in Vulkan. 961 | /// 962 | /// Used in AllocatorCreateInfo::pDeviceMemoryCallbacks. 963 | pub const DeviceMemoryCallbacks = extern struct { 964 | pfnAllocate: ?PFN_AllocateDeviceMemoryFunction, 965 | pfnFree: ?PFN_FreeDeviceMemoryFunction, 966 | }; 967 | 968 | /// Flags for created #Allocator. 969 | pub const AllocatorCreateFlags = packed struct { 970 | /// \brief Allocator and all objects created from it will not be synchronized internally, so you must guarantee they are used from only one thread at a time or synchronized externally by you. 971 | /// 972 | /// Using this flag may increase performance because internal mutexes are not used. 973 | externallySynchronized: bool = false, 974 | 975 | /// \brief Enables usage of vk.KHR_dedicated_allocation extension. 976 | /// 977 | /// The flag works only if AllocatorCreateInfo::vulkanApiVersion `== vk.API_VERSION_1_0`. 978 | /// When it's `vk.API_VERSION_1_1`, the flag is ignored because the extension has been promoted to Vulkan 1.1. 979 | /// 980 | /// Using this extenion will automatically allocate dedicated blocks of memory for 981 | /// some buffers and images instead of suballocating place for them out of bigger 982 | /// memory blocks (as if you explicitly used #VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT 983 | /// flag) when it is recommended by the driver. It may improve performance on some 984 | /// GPUs. 985 | /// 986 | /// You may set this flag only if you found out that following device extensions are 987 | /// supported, you enabled them while creating Vulkan device passed as 988 | /// AllocatorCreateInfo::device, and you want them to be used internally by this 989 | /// library: 990 | /// 991 | /// - vk.KHR_get_memory_requirements2 (device extension) 992 | /// - vk.KHR_dedicated_allocation (device extension) 993 | /// 994 | /// When this flag is set, you can experience following warnings reported by Vulkan 995 | /// validation layer. You can ignore them. 996 | /// 997 | /// > vkBindBufferMemory(): Binding memory to buffer 0x2d but vkGetBufferMemoryRequirements() has not been called on that buffer. 998 | dedicatedAllocationKHR: bool = false, 999 | 1000 | /// Enables usage of vk.KHR_bind_memory2 extension. 1001 | /// 1002 | /// The flag works only if AllocatorCreateInfo::vulkanApiVersion `== vk.API_VERSION_1_0`. 1003 | /// When it's `vk.API_VERSION_1_1`, the flag is ignored because the extension has been promoted to Vulkan 1.1. 1004 | /// 1005 | /// You may set this flag only if you found out that this device extension is supported, 1006 | /// you enabled it while creating Vulkan device passed as AllocatorCreateInfo::device, 1007 | /// and you want it to be used internally by this library. 1008 | /// 1009 | /// The extension provides functions `vkBindBufferMemory2KHR` and `vkBindImageMemory2KHR`, 1010 | /// which allow to pass a chain of `pNext` structures while binding. 1011 | /// This flag is required if you use `pNext` parameter in BindBufferMemory2() or BindImageMemory2(). 1012 | bindMemory2KHR: bool = false, 1013 | 1014 | /// Enables usage of vk.EXT_memory_budget extension. 1015 | /// 1016 | /// You may set this flag only if you found out that this device extension is supported, 1017 | /// you enabled it while creating Vulkan device passed as AllocatorCreateInfo::device, 1018 | /// and you want it to be used internally by this library, along with another instance extension 1019 | /// vk.KHR_get_physical_device_properties2, which is required by it (or Vulkan 1.1, where this extension is promoted). 1020 | /// 1021 | /// The extension provides query for current memory usage and budget, which will probably 1022 | /// be more accurate than an estimation used by the library otherwise. 1023 | memoryBudgetEXT: bool = false, 1024 | 1025 | __reserved_bits_04_31: u28 = 0, 1026 | 1027 | pub usingnamespace vk.FlagsMixin(@This()); 1028 | }; 1029 | 1030 | /// \brief Pointers to some Vulkan functions - a subset used by the library. 1031 | /// 1032 | /// Used in AllocatorCreateInfo::pVulkanFunctions. 1033 | pub const VulkanFunctions = extern struct { 1034 | vkGetPhysicalDeviceProperties: @TypeOf(vk.vkGetPhysicalDeviceProperties), 1035 | vkGetPhysicalDeviceMemoryProperties: @TypeOf(vk.vkGetPhysicalDeviceMemoryProperties), 1036 | vkAllocateMemory: @TypeOf(vk.vkAllocateMemory), 1037 | vkFreeMemory: @TypeOf(vk.vkFreeMemory), 1038 | vkMapMemory: @TypeOf(vk.vkMapMemory), 1039 | vkUnmapMemory: @TypeOf(vk.vkUnmapMemory), 1040 | vkFlushMappedMemoryRanges: @TypeOf(vk.vkFlushMappedMemoryRanges), 1041 | vkInvalidateMappedMemoryRanges: @TypeOf(vk.vkInvalidateMappedMemoryRanges), 1042 | vkBindBufferMemory: @TypeOf(vk.vkBindBufferMemory), 1043 | vkBindImageMemory: @TypeOf(vk.vkBindImageMemory), 1044 | vkGetBufferMemoryRequirements: @TypeOf(vk.vkGetBufferMemoryRequirements), 1045 | vkGetImageMemoryRequirements: @TypeOf(vk.vkGetImageMemoryRequirements), 1046 | vkCreateBuffer: @TypeOf(vk.vkCreateBuffer), 1047 | vkDestroyBuffer: @TypeOf(vk.vkDestroyBuffer), 1048 | vkCreateImage: @TypeOf(vk.vkCreateImage), 1049 | vkDestroyImage: @TypeOf(vk.vkDestroyImage), 1050 | vkCmdCopyBuffer: @TypeOf(vk.vkCmdCopyBuffer), 1051 | 1052 | dedicatedAllocation: if (config.dedicatedAllocation or config.vulkanVersion >= 1001000) DedicatedAllocationFunctions else void, 1053 | bindMemory2: if (config.bindMemory2 or config.vulkanVersion >= 1001000) BindMemory2Functions else void, 1054 | memoryBudget: if (config.memoryBudget or config.vulkanVersion >= 1001000) MemoryBudgetFunctions else void, 1055 | 1056 | const DedicatedAllocationFunctions = extern struct { 1057 | vkGetBufferMemoryRequirements2: @TypeOf(vk.vkGetBufferMemoryRequirements2KHR), 1058 | vkGetImageMemoryRequirements2: @TypeOf(vk.vkGetImageMemoryRequirements2KHR), 1059 | }; 1060 | const BindMemory2Functions = extern struct { 1061 | vkBindBufferMemory2: @TypeOf(vk.vkBindBufferMemory2KHR), 1062 | vkBindImageMemory2: @TypeOf(vk.vkBindImageMemory2KHR), 1063 | }; 1064 | const MemoryBudgetFunctions = extern struct { 1065 | vkGetPhysicalDeviceMemoryProperties2: @TypeOf(vk.vkGetPhysicalDeviceMemoryProperties2KHR), 1066 | }; 1067 | 1068 | fn isDeviceFunc(comptime FuncType: type) bool { 1069 | comptime { 1070 | const info = @typeInfo(FuncType).Fn; 1071 | if (info.args.len == 0) return false; 1072 | const arg0 = info.args[0].arg_type; 1073 | return arg0 == vk.Device or arg0 == vk.Queue or arg0 == vk.CommandBuffer; 1074 | } 1075 | } 1076 | 1077 | fn loadRecursive( 1078 | comptime T: type, 1079 | inst: vk.Instance, 1080 | device: vk.Device, 1081 | vkGetInstanceProcAddr: fn(vk.Instance, [*:0]const u8) callconv(vk.CallConv) ?vk.PFN_VoidFunction, 1082 | vkGetDeviceProcAddr: fn(vk.Device, [*:0]const u8) callconv(vk.CallConv) ?vk.PFN_VoidFunction, 1083 | ) T { 1084 | if (@typeInfo(T) != .Struct) return undefined; 1085 | var value: T = undefined; 1086 | inline for (@typeInfo(T).Struct.fields) |field| { 1087 | if (comptime std.mem.startsWith(u8, field.name, "vk")) { 1088 | if (comptime isDeviceFunc(field.field_type)) { 1089 | const func = vkGetDeviceProcAddr(device, @ptrCast([*:0]const u8, field.name.ptr)); 1090 | const resolved = func orelse @panic("Couldn't fetch vk device function "++field.name); 1091 | @field(value, field.name) = @ptrCast(field.field_type, resolved); 1092 | } else { 1093 | const func = vkGetInstanceProcAddr(inst, @ptrCast([*:0]const u8, field.name.ptr)); 1094 | const resolved = func orelse @panic("Couldn't fetch vk instance function "++field.name); 1095 | @field(value, field.name) = @ptrCast(field.field_type, resolved); 1096 | } 1097 | } else { 1098 | @field(value, field.name) = loadRecursive(field.field_type, inst, device, vkGetInstanceProcAddr, vkGetDeviceProcAddr); 1099 | } 1100 | } 1101 | return value; 1102 | } 1103 | 1104 | pub fn init( 1105 | inst: vk.Instance, 1106 | device: vk.Device, 1107 | vkGetInstanceProcAddr: fn(vk.Instance, [*:0]const u8) callconv(vk.CallConv) ?vk.PFN_VoidFunction, 1108 | ) VulkanFunctions { 1109 | const vkGetDeviceProcAddrPtr = vkGetInstanceProcAddr(inst, "vkGetDeviceProcAddr") 1110 | orelse @panic("Couldn't fetch vkGetDeviceProcAddr: vkGetInstanceProcAddr returned null."); 1111 | const vkGetDeviceProcAddr = @ptrCast(fn(vk.Device, [*:0]const u8) callconv(vk.CallConv) ?vk.PFN_VoidFunction, vkGetDeviceProcAddrPtr); 1112 | return loadRecursive(VulkanFunctions, inst, device, vkGetInstanceProcAddr, vkGetDeviceProcAddr); 1113 | } 1114 | }; 1115 | 1116 | /// Flags to be used in RecordSettings::flags. 1117 | pub const RecordFlags = packed struct { 1118 | /// \brief Enables flush after recording every function call. 1119 | /// 1120 | /// Enable it if you expect your application to crash, which may leave recording file truncated. 1121 | /// It may degrade performance though. 1122 | flushAfterCall: bool = false, 1123 | 1124 | __reserved_bits_01_31: u31 = 0, 1125 | 1126 | pub usingnamespace vk.FlagsMixin(@This()); 1127 | }; 1128 | 1129 | /// Parameters for recording calls to VMA functions. To be used in AllocatorCreateInfo::pRecordSettings. 1130 | pub const RecordSettings = extern struct { 1131 | /// Flags for recording. Use #RecordFlagBits enum. 1132 | flags: RecordFlags = .{}, 1133 | /// \brief Path to the file that should be written by the recording. 1134 | /// 1135 | /// Suggested extension: "csv". 1136 | /// If the file already exists, it will be overwritten. 1137 | /// It will be opened for the whole time #Allocator object is alive. 1138 | /// If opening this file fails, creation of the whole allocator object fails. 1139 | pFilePath: [*:0]const u8, 1140 | }; 1141 | 1142 | /// Description of a Allocator to be created. 1143 | pub const AllocatorCreateInfo = extern struct { 1144 | /// Flags for created allocator. Use #AllocatorCreateFlagBits enum. 1145 | flags: AllocatorCreateFlags align(4) = .{}, 1146 | /// Vulkan physical device. 1147 | /// It must be valid throughout whole lifetime of created allocator. 1148 | physicalDevice: vk.PhysicalDevice, 1149 | /// Vulkan device. 1150 | /// It must be valid throughout whole lifetime of created allocator. 1151 | device: vk.Device, 1152 | /// Preferred size of a single `vk.DeviceMemory` block to be allocated from large heaps > 1 GiB. Optional. 1153 | /// Set to 0 to use default, which is currently 256 MiB. 1154 | preferredLargeHeapBlockSize: vk.DeviceSize = 0, 1155 | /// Custom CPU memory allocation callbacks. Optional. 1156 | /// Optional, can be null. When specified, will also be used for all CPU-side memory allocations. 1157 | pAllocationCallbacks: ?*const vk.AllocationCallbacks = null, 1158 | /// Informative callbacks for `vkAllocateMemory`, `vkFreeMemory`. Optional. 1159 | /// Optional, can be null. 1160 | pDeviceMemoryCallbacks: ?*const DeviceMemoryCallbacks = null, 1161 | /// \brief Maximum number of additional frames that are in use at the same time as current frame. 1162 | /// 1163 | /// This value is used only when you make allocations with 1164 | /// .canBeLost = true. Such allocation cannot become 1165 | /// lost if allocation.lastUseFrameIndex >= allocator.currentFrameIndex - frameInUseCount. 1166 | /// 1167 | /// For example, if you double-buffer your command buffers, so resources used for 1168 | /// rendering in previous frame may still be in use by the GPU at the moment you 1169 | /// allocate resources needed for the current frame, set this value to 1. 1170 | /// 1171 | /// If you want to allow any allocations other than used in the current frame to 1172 | /// become lost, set this value to 0. 1173 | frameInUseCount: u32, 1174 | /// \brief Either null or a pointer to an array of limits on maximum number of bytes that can be allocated out of particular Vulkan memory heap. 1175 | /// 1176 | /// If not NULL, it must be a pointer to an array of 1177 | /// `vk.PhysicalDeviceMemoryProperties::memoryHeapCount` elements, defining limit on 1178 | /// maximum number of bytes that can be allocated out of particular Vulkan memory 1179 | /// heap. 1180 | /// 1181 | /// Any of the elements may be equal to `vk.WHOLE_SIZE`, which means no limit on that 1182 | /// heap. This is also the default in case of `pHeapSizeLimit` = NULL. 1183 | /// 1184 | /// If there is a limit defined for a heap: 1185 | /// 1186 | /// - If user tries to allocate more memory from that heap using this allocator, 1187 | /// the allocation fails with `error.VK_OUT_OF_DEVICE_MEMORY`. 1188 | /// - If the limit is smaller than heap size reported in `vk.MemoryHeap::size`, the 1189 | /// value of this limit will be reported instead when using GetMemoryProperties(). 1190 | /// 1191 | /// Warning! Using this feature may not be equivalent to installing a GPU with 1192 | /// smaller amount of memory, because graphics driver doesn't necessary fail new 1193 | /// allocations with `error.VK_OUT_OF_DEVICE_MEMORY` result when memory capacity is 1194 | /// exceeded. It may return success and just silently migrate some device memory 1195 | /// blocks to system RAM. This driver behavior can also be controlled using 1196 | /// vk.AMD_memory_overallocation_behavior extension. 1197 | pHeapSizeLimit: ?[*]const vk.DeviceSize = null, 1198 | /// \brief Pointers to Vulkan functions. Can be null if you leave define `VMA_STATIC_VULKAN_FUNCTIONS 1`. 1199 | /// 1200 | /// If you leave define `VMA_STATIC_VULKAN_FUNCTIONS 1` in configuration section, 1201 | /// you can pass null as this member, because the library will fetch pointers to 1202 | /// Vulkan functions internally in a static way, like: 1203 | /// 1204 | /// vulkanFunctions.vkAllocateMemory = &vkAllocateMemory; 1205 | /// 1206 | /// Fill this member if you want to provide your own pointers to Vulkan functions, 1207 | /// e.g. fetched using `vkGetInstanceProcAddr()` and `vkGetDeviceProcAddr()`. 1208 | pVulkanFunctions: ?*const VulkanFunctions = null, 1209 | /// \brief Parameters for recording of VMA calls. Can be null. 1210 | /// 1211 | /// If not null, it enables recording of calls to VMA functions to a file. 1212 | /// If support for recording is not enabled using `VMA_RECORDING_ENABLED` macro, 1213 | /// creation of the allocator object fails with `error.VK_FEATURE_NOT_PRESENT`. 1214 | pRecordSettings: ?*const RecordSettings = null, 1215 | /// \brief Optional handle to Vulkan instance object. 1216 | /// 1217 | /// Optional, can be null. Must be set if #VMA_ALLOCATOR_CREATE_EXT_MEMORY_BUDGET_BIT flas is used 1218 | /// or if `vulkanApiVersion >= vk.MAKE_VERSION(1, 1, 0)`. 1219 | instance: vk.Instance, 1220 | /// \brief Optional. The highest version of Vulkan that the application is designed to use. 1221 | /// 1222 | /// 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`. 1223 | /// The patch version number specified is ignored. Only the major and minor versions are considered. 1224 | /// It must be less or euqal (preferably equal) to value as passed to `vkCreateInstance` as `vk.ApplicationInfo::apiVersion`. 1225 | /// Only versions 1.0 and 1.1 are supported by the current implementation. 1226 | /// Leaving it initialized to zero is equivalent to `vk.API_VERSION_1_0`. 1227 | vulkanApiVersion: u32 = 0, 1228 | }; 1229 | 1230 | /// \brief Calculated statistics of memory usage in entire allocator. 1231 | pub const StatInfo = extern struct { 1232 | /// Number of `vk.DeviceMemory` Vulkan memory blocks allocated. 1233 | blockCount: u32, 1234 | /// Number of #Allocation allocation objects allocated. 1235 | allocationCount: u32, 1236 | /// Number of free ranges of memory between allocations. 1237 | unusedRangeCount: u32, 1238 | /// Total number of bytes occupied by all allocations. 1239 | usedBytes: vk.DeviceSize, 1240 | /// Total number of bytes occupied by unused ranges. 1241 | unusedBytes: vk.DeviceSize, 1242 | 1243 | allocationSizeMin: vk.DeviceSize, 1244 | allocationSizeAvg: vk.DeviceSize, 1245 | allocationSizeMax: vk.DeviceSize, 1246 | unusedRangeSizeMin: vk.DeviceSize, 1247 | unusedRangeSizeAvg: vk.DeviceSize, 1248 | unusedRangeSizeMax: vk.DeviceSize, 1249 | }; 1250 | 1251 | /// General statistics from current state of Allocator. 1252 | pub const Stats = extern struct { 1253 | memoryType: [vk.MAX_MEMORY_TYPES]StatInfo, 1254 | memoryHeap: [vk.MAX_MEMORY_HEAPS]StatInfo, 1255 | total: StatInfo, 1256 | }; 1257 | 1258 | /// \brief Statistics of current memory usage and available budget, in bytes, for specific memory heap. 1259 | pub const Budget = extern struct { 1260 | /// \brief Sum size of all `vk.DeviceMemory` blocks allocated from particular heap, in bytes. 1261 | blockBytes: vk.DeviceSize, 1262 | 1263 | /// \brief Sum size of all allocations created in particular heap, in bytes. 1264 | /// 1265 | /// Usually less or equal than `blockBytes`. 1266 | /// Difference `blockBytes - allocationBytes` is the amount of memory allocated but unused - 1267 | /// available for new allocations or wasted due to fragmentation. 1268 | /// 1269 | /// It might be greater than `blockBytes` if there are some allocations in lost state, as they account 1270 | /// to this value as well. 1271 | allocationBytes: vk.DeviceSize, 1272 | 1273 | /// \brief Estimated current memory usage of the program, in bytes. 1274 | /// 1275 | /// Fetched from system using `vk.EXT_memory_budget` extension if enabled. 1276 | /// 1277 | /// It might be different than `blockBytes` (usually higher) due to additional implicit objects 1278 | /// also occupying the memory, like swapchain, pipelines, descriptor heaps, command buffers, or 1279 | /// `vk.DeviceMemory` blocks allocated outside of this library, if any. 1280 | usage: vk.DeviceSize, 1281 | 1282 | /// \brief Estimated amount of memory available to the program, in bytes. 1283 | /// 1284 | /// Fetched from system using `vk.EXT_memory_budget` extension if enabled. 1285 | /// 1286 | /// It might be different (most probably smaller) than `vk.MemoryHeap::size[heapIndex]` due to factors 1287 | /// external to the program, like other programs also consuming system resources. 1288 | /// Difference `budget - usage` is the amount of additional memory that can probably 1289 | /// be allocated without problems. Exceeding the budget may result in various problems. 1290 | budget: vk.DeviceSize, 1291 | }; 1292 | 1293 | /// \struct Pool 1294 | /// \brief Represents custom memory pool 1295 | /// 1296 | /// Fill structure PoolCreateInfo and call function CreatePool() to create it. 1297 | /// Call function DestroyPool() to destroy it. 1298 | /// 1299 | /// For more information see [Custom memory pools](@ref choosing_memory_type_custom_memory_pools). 1300 | pub const Pool = enum(usize) { Null = 0, _ }; 1301 | 1302 | pub const MemoryUsage = enum(u32) { 1303 | /// No intended memory usage specified. 1304 | /// Use other members of AllocationCreateInfo to specify your requirements. 1305 | unknown = 0, 1306 | /// Memory will be used on device only, so fast access from the device is preferred. 1307 | /// It usually means device-local GPU (video) memory. 1308 | /// No need to be mappable on host. 1309 | /// It is roughly equivalent of `D3D12_HEAP_TYPE_DEFAULT`. 1310 | /// 1311 | /// Usage: 1312 | /// 1313 | /// - Resources written and read by device, e.g. images used as attachments. 1314 | /// - Resources transferred from host once (immutable) or infrequently and read by 1315 | /// device multiple times, e.g. textures to be sampled, vertex buffers, uniform 1316 | /// (constant) buffers, and majority of other types of resources used on GPU. 1317 | /// 1318 | /// Allocation may still end up in `HOST_VISIBLE` memory on some implementations. 1319 | /// In such case, you are free to map it. 1320 | /// You can use #VMA_ALLOCATION_CREATE_MAPPED_BIT with this usage type. 1321 | gpuOnly = 1, 1322 | /// Memory will be mappable on host. 1323 | /// It usually means CPU (system) memory. 1324 | /// Guarantees to be `HOST_VISIBLE` and `HOST_COHERENT`. 1325 | /// CPU access is typically uncached. Writes may be write-combined. 1326 | /// Resources created in this pool may still be accessible to the device, but access to them can be slow. 1327 | /// It is roughly equivalent of `D3D12_HEAP_TYPE_UPLOAD`. 1328 | /// 1329 | /// Usage: Staging copy of resources used as transfer source. 1330 | cpuOnly = 2, 1331 | /// Memory that is both mappable on host (guarantees to be `HOST_VISIBLE`) and preferably fast to access by GPU. 1332 | /// CPU access is typically uncached. Writes may be write-combined. 1333 | /// 1334 | /// Usage: Resources written frequently by host (dynamic), read by device. E.g. textures, vertex buffers, uniform buffers updated every frame or every draw call. 1335 | cpuToGpu = 3, 1336 | /// Memory mappable on host (guarantees to be `HOST_VISIBLE`) and cached. 1337 | /// It is roughly equivalent of `D3D12_HEAP_TYPE_READBACK`. 1338 | /// 1339 | /// Usage: 1340 | /// 1341 | /// - Resources written by device, read by host - results of some computations, e.g. screen capture, average scene luminance for HDR tone mapping. 1342 | /// - Any resources read or accessed randomly on host, e.g. CPU-side copy of vertex buffer used as source of transfer, but also used for collision detection. 1343 | gpuToCpu = 4, 1344 | /// CPU memory - memory that is preferably not `DEVICE_LOCAL`, but also not guaranteed to be `HOST_VISIBLE`. 1345 | /// 1346 | /// Usage: Staging copy of resources moved from GPU memory to CPU memory as part 1347 | /// of custom paging/residency mechanism, to be moved back to GPU memory when needed. 1348 | cpuCopy = 5, 1349 | /// Lazily allocated GPU memory having `vk.MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT`. 1350 | /// Exists mostly on mobile platforms. Using it on desktop PC or other GPUs with no such memory type present will fail the allocation. 1351 | /// 1352 | /// Usage: Memory for transient attachment images (color attachments, depth attachments etc.), created with `vk.IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT`. 1353 | /// 1354 | /// Allocations with this usage are always created as dedicated - it implies #VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT. 1355 | gpuLazilyAllocated = 6, 1356 | }; 1357 | 1358 | /// Flags to be passed as AllocationCreateInfo::flags. 1359 | pub const AllocationCreateFlags = packed struct { 1360 | /// \brief Set this flag if the allocation should have its own memory block. 1361 | /// 1362 | /// Use it for special, big resources, like fullscreen images used as attachments. 1363 | /// 1364 | /// You should not use this flag if AllocationCreateInfo::pool is not null. 1365 | dedicatedMemory: bool = false, 1366 | 1367 | /// \brief Set this flag to only try to allocate from existing `vk.DeviceMemory` blocks and never create new such block. 1368 | /// 1369 | /// If new allocation cannot be placed in any of the existing blocks, allocation 1370 | /// fails with `error.VK_OUT_OF_DEVICE_MEMORY` error. 1371 | /// 1372 | /// You should not use #VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT and 1373 | /// #VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT at the same time. It makes no sense. 1374 | /// 1375 | /// If AllocationCreateInfo::pool is not null, this flag is implied and ignored. */ 1376 | neverAllocate: bool = false, 1377 | /// \brief Set this flag to use a memory that will be persistently mapped and retrieve pointer to it. 1378 | /// 1379 | /// Pointer to mapped memory will be returned through AllocationInfo::pMappedData. 1380 | /// 1381 | /// Is it valid to use this flag for allocation made from memory type that is not 1382 | /// `HOST_VISIBLE`. This flag is then ignored and memory is not mapped. This is 1383 | /// useful if you need an allocation that is efficient to use on GPU 1384 | /// (`DEVICE_LOCAL`) and still want to map it directly if possible on platforms that 1385 | /// support it (e.g. Intel GPU). 1386 | /// 1387 | /// You should not use this flag together with #VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT. 1388 | createMapped: bool = false, 1389 | /// Allocation created with this flag can become lost as a result of another 1390 | /// allocation with #VMA_ALLOCATION_CREATE_CAN_MAKE_OTHER_LOST_BIT flag, so you 1391 | /// must check it before use. 1392 | /// 1393 | /// To check if allocation is not lost, call GetAllocationInfo() and check if 1394 | /// AllocationInfo::deviceMemory is not `.Null`. 1395 | /// 1396 | /// For details about supporting lost allocations, see Lost Allocations 1397 | /// chapter of User Guide on Main Page. 1398 | /// 1399 | /// You should not use this flag together with #VMA_ALLOCATION_CREATE_MAPPED_BIT. 1400 | canBecomeLost: bool = false, 1401 | /// While creating allocation using this flag, other allocations that were 1402 | /// created with flag #VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT can become lost. 1403 | /// 1404 | /// For details about supporting lost allocations, see Lost Allocations 1405 | /// chapter of User Guide on Main Page. 1406 | canMakeOtherLost: bool = false, 1407 | /// Set this flag to treat AllocationCreateInfo::pUserData as pointer to a 1408 | /// null-terminated string. Instead of copying pointer value, a local copy of the 1409 | /// string is made and stored in allocation's `pUserData`. The string is automatically 1410 | /// freed together with the allocation. It is also used in BuildStatsString(). 1411 | userDataCopyString: bool = false, 1412 | /// Allocation will be created from upper stack in a double stack pool. 1413 | /// 1414 | /// This flag is only allowed for custom pools created with #VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT flag. 1415 | upperAddress: bool = false, 1416 | /// Create both buffer/image and allocation, but don't bind them together. 1417 | /// It is useful when you want to bind yourself to do some more advanced binding, e.g. using some extensions. 1418 | /// The flag is meaningful only with functions that bind by default: CreateBuffer(), CreateImage(). 1419 | /// Otherwise it is ignored. 1420 | dontBind: bool = false, 1421 | /// Create allocation only if additional device memory required for it, if any, won't exceed 1422 | /// memory budget. Otherwise return `error.VK_OUT_OF_DEVICE_MEMORY`. 1423 | withinBudget: bool = false, 1424 | 1425 | __reserved_bits_09_15: u7 = 0, 1426 | 1427 | /// Allocation strategy that chooses smallest possible free range for the 1428 | /// allocation. 1429 | strategyBestFit: bool = false, 1430 | /// Allocation strategy that chooses biggest possible free range for the 1431 | /// allocation. 1432 | strategyWorstFit: bool = false, 1433 | /// Allocation strategy that chooses first suitable free range for the 1434 | /// allocation. 1435 | /// 1436 | /// "First" doesn't necessarily means the one with smallest offset in memory, 1437 | /// but rather the one that is easiest and fastest to find. 1438 | strategyFirstFit: bool = false, 1439 | 1440 | __reserved_bits_19_31: u13 = 0, 1441 | 1442 | /// Allocation strategy that tries to minimize memory usage. 1443 | pub const STRATEGY_MIN_MEMORY = AllocationCreateFlags{ .strategyBestFit = true }; 1444 | /// Allocation strategy that tries to minimize allocation time. 1445 | pub const STRATEGY_MIN_TIME = AllocationCreateFlags{ .strategyFirstFit = true }; 1446 | /// Allocation strategy that tries to minimize memory fragmentation. 1447 | pub const STRATEGY_MIN_FRAGMENTATION = AllocationCreateFlags{ .strategyWorstFit = true }; 1448 | 1449 | /// A bit mask to extract only `STRATEGY` bits from entire set of flags. 1450 | pub const STRATEGY_MASK = AllocationCreateFlags{ 1451 | .strategyBestFit = true, 1452 | .strategyWorstFit = true, 1453 | .strategyFirstFit = true, 1454 | }; 1455 | 1456 | pub usingnamespace vk.FlagsMixin(@This()); 1457 | }; 1458 | 1459 | pub const AllocationCreateInfo = extern struct { 1460 | /// Use #AllocationCreateFlagBits enum. 1461 | flags: AllocationCreateFlags = .{}, 1462 | /// \brief Intended usage of memory. 1463 | /// 1464 | /// You can leave #MemoryUsage.unknown if you specify memory requirements in other way. \n 1465 | /// If `pool` is not null, this member is ignored. 1466 | usage: MemoryUsage = .unknown, 1467 | /// \brief Flags that must be set in a Memory Type chosen for an allocation. 1468 | /// 1469 | /// Leave 0 if you specify memory requirements in other way. \n 1470 | /// If `pool` is not null, this member is ignored.*/ 1471 | requiredFlags: vk.MemoryPropertyFlags = .{}, 1472 | /// \brief Flags that preferably should be set in a memory type chosen for an allocation. 1473 | /// 1474 | /// Set to 0 if no additional flags are prefered. \n 1475 | /// If `pool` is not null, this member is ignored. */ 1476 | preferredFlags: vk.MemoryPropertyFlags = .{}, 1477 | /// \brief Bitmask containing one bit set for every memory type acceptable for this allocation. 1478 | /// 1479 | /// Value 0 is equivalent to `UINT32_MAX` - it means any memory type is accepted if 1480 | /// it meets other requirements specified by this structure, with no further 1481 | /// restrictions on memory type index. \n 1482 | /// If `pool` is not null, this member is ignored. 1483 | memoryTypeBits: u32 = 0, 1484 | /// \brief Pool that this allocation should be created in. 1485 | /// 1486 | /// Leave `.Null` to allocate from default pool. If not null, members: 1487 | /// `usage`, `requiredFlags`, `preferredFlags`, `memoryTypeBits` are ignored. 1488 | pool: Pool = .Null, 1489 | /// \brief Custom general-purpose pointer that will be stored in #Allocation, can be read as AllocationInfo::pUserData and changed using SetAllocationUserData(). 1490 | /// 1491 | /// If #AllocationCreateFlags.userDataCopyString is true, it must be either 1492 | /// null or pointer to a null-terminated string. The string will be then copied to 1493 | /// internal buffer, so it doesn't need to be valid after allocation call. 1494 | pUserData: ?*anyopaque = null, 1495 | }; 1496 | 1497 | /// Flags to be passed as PoolCreateInfo::flags. 1498 | pub const PoolCreateFlags = packed struct { 1499 | __reserved_bit_00: u1 = 0, 1500 | /// \brief Use this flag if you always allocate only buffers and linear images or only optimal images out of this pool and so Buffer-Image Granularity can be ignored. 1501 | /// 1502 | /// This is an optional optimization flag. 1503 | /// 1504 | /// If you always allocate using CreateBuffer(), CreateImage(), 1505 | /// AllocateMemoryForBuffer(), then you don't need to use it because allocator 1506 | /// knows exact type of your allocations so it can handle Buffer-Image Granularity 1507 | /// in the optimal way. 1508 | /// 1509 | /// If you also allocate using AllocateMemoryForImage() or AllocateMemory(), 1510 | /// exact type of such allocations is not known, so allocator must be conservative 1511 | /// in handling Buffer-Image Granularity, which can lead to suboptimal allocation 1512 | /// (wasted memory). In that case, if you can make sure you always allocate only 1513 | /// buffers and linear images or only optimal images out of this pool, use this flag 1514 | /// to make allocator disregard Buffer-Image Granularity and so make allocations 1515 | /// faster and more optimal. 1516 | ignoreBufferImageGranularity: bool = false, 1517 | 1518 | /// \brief Enables alternative, linear allocation algorithm in this pool. 1519 | /// 1520 | /// Specify this flag to enable linear allocation algorithm, which always creates 1521 | /// new allocations after last one and doesn't reuse space from allocations freed in 1522 | /// between. It trades memory consumption for simplified algorithm and data 1523 | /// structure, which has better performance and uses less memory for metadata. 1524 | /// 1525 | /// By using this flag, you can achieve behavior of free-at-once, stack, 1526 | /// ring buffer, and double stack. For details, see documentation chapter 1527 | /// \ref linear_algorithm. 1528 | /// 1529 | /// When using this flag, you must specify PoolCreateInfo::maxBlockCount == 1 (or 0 for default). 1530 | /// 1531 | /// For more details, see [Linear allocation algorithm](@ref linear_algorithm). 1532 | linearAlgorithm: bool = false, 1533 | 1534 | /// \brief Enables alternative, buddy allocation algorithm in this pool. 1535 | /// 1536 | /// It operates on a tree of blocks, each having size that is a power of two and 1537 | /// a half of its parent's size. Comparing to default algorithm, this one provides 1538 | /// faster allocation and deallocation and decreased external fragmentation, 1539 | /// at the expense of more memory wasted (internal fragmentation). 1540 | /// 1541 | /// For more details, see [Buddy allocation algorithm](@ref buddy_algorithm). 1542 | buddyAlgorithm: bool = false, 1543 | 1544 | __reserved_bits_04_31: u28 = 0, 1545 | 1546 | /// Bit mask to extract only `ALGORITHM` bits from entire set of flags. 1547 | pub const ALGORITHM_MASK = PoolCreateFlags{ 1548 | .linearAlgorithm = true, 1549 | .buddyAlgorithm = true, 1550 | }; 1551 | 1552 | pub usingnamespace vk.FlagsMixin(@This()); 1553 | }; 1554 | 1555 | /// \brief Describes parameter of created #Pool. 1556 | pub const PoolCreateInfo = extern struct { 1557 | /// \brief Vulkan memory type index to allocate this pool from. 1558 | memoryTypeIndex: u32, 1559 | /// \brief Use combination of #PoolCreateFlagBits. 1560 | flags: PoolCreateFlags = .{}, 1561 | /// \brief Size of a single `vk.DeviceMemory` block to be allocated as part of this pool, in bytes. Optional. 1562 | /// 1563 | /// Specify nonzero to set explicit, constant size of memory blocks used by this 1564 | /// pool. 1565 | /// 1566 | /// Leave 0 to use default and let the library manage block sizes automatically. 1567 | /// Sizes of particular blocks may vary. 1568 | blockSize: vk.DeviceSize = 0, 1569 | /// \brief Minimum number of blocks to be always allocated in this pool, even if they stay empty. 1570 | /// 1571 | /// Set to 0 to have no preallocated blocks and allow the pool be completely empty. 1572 | minBlockCount: usize = 0, 1573 | /// \brief Maximum number of blocks that can be allocated in this pool. Optional. 1574 | /// 1575 | /// Set to 0 to use default, which is `SIZE_MAX`, which means no limit. 1576 | /// 1577 | /// Set to same value as PoolCreateInfo::minBlockCount to have fixed amount of memory allocated 1578 | /// throughout whole lifetime of this pool. 1579 | maxBlockCount: usize = 0, 1580 | /// \brief Maximum number of additional frames that are in use at the same time as current frame. 1581 | /// 1582 | /// This value is used only when you make allocations with 1583 | /// #VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT flag. Such allocation cannot become 1584 | /// lost if allocation.lastUseFrameIndex >= allocator.currentFrameIndex - frameInUseCount. 1585 | /// 1586 | /// For example, if you double-buffer your command buffers, so resources used for 1587 | /// rendering in previous frame may still be in use by the GPU at the moment you 1588 | /// allocate resources needed for the current frame, set this value to 1. 1589 | /// 1590 | /// If you want to allow any allocations other than used in the current frame to 1591 | /// become lost, set this value to 0. 1592 | frameInUseCount: u32, 1593 | }; 1594 | 1595 | /// \brief Describes parameter of existing #Pool. 1596 | pub const PoolStats = extern struct { 1597 | /// \brief Total amount of `vk.DeviceMemory` allocated from Vulkan for this pool, in bytes. 1598 | size: vk.DeviceSize, 1599 | /// \brief Total number of bytes in the pool not used by any #Allocation. 1600 | unusedSize: vk.DeviceSize, 1601 | /// \brief Number of #Allocation objects created from this pool that were not destroyed or lost. 1602 | allocationCount: usize, 1603 | /// \brief Number of continuous memory ranges in the pool not used by any #Allocation. 1604 | unusedRangeCount: usize, 1605 | /// \brief Size of the largest continuous free memory region available for new allocation. 1606 | /// 1607 | /// Making a new allocation of that size is not guaranteed to succeed because of 1608 | /// possible additional margin required to respect alignment and buffer/image 1609 | /// granularity. 1610 | unusedRangeSizeMax: vk.DeviceSize, 1611 | /// \brief Number of `vk.DeviceMemory` blocks allocated for this pool. 1612 | blockCount: usize, 1613 | }; 1614 | 1615 | /// \struct Allocation 1616 | /// \brief Represents single memory allocation. 1617 | /// 1618 | /// It may be either dedicated block of `vk.DeviceMemory` or a specific region of a bigger block of this type 1619 | /// plus unique offset. 1620 | /// 1621 | /// There are multiple ways to create such object. 1622 | /// You need to fill structure AllocationCreateInfo. 1623 | /// For more information see [Choosing memory type](@ref choosing_memory_type). 1624 | /// 1625 | /// Although the library provides convenience functions that create Vulkan buffer or image, 1626 | /// allocate memory for it and bind them together, 1627 | /// binding of the allocation to a buffer or an image is out of scope of the allocation itself. 1628 | /// Allocation object can exist without buffer/image bound, 1629 | /// binding can be done manually by the user, and destruction of it can be done 1630 | /// independently of destruction of the allocation. 1631 | /// 1632 | /// The object also remembers its size and some other information. 1633 | /// To retrieve this information, use function GetAllocationInfo() and inspect 1634 | /// returned structure AllocationInfo. 1635 | /// 1636 | /// Some kinds allocations can be in lost state. 1637 | /// For more information, see [Lost allocations](@ref lost_allocations). 1638 | pub const Allocation = enum(usize) { Null = 0, _ }; 1639 | 1640 | /// \brief Parameters of #Allocation objects, that can be retrieved using function GetAllocationInfo(). 1641 | pub const AllocationInfo = extern struct { 1642 | /// \brief Memory type index that this allocation was allocated from. 1643 | /// 1644 | /// It never changes. 1645 | memoryType: u32, 1646 | /// \brief Handle to Vulkan memory object. 1647 | /// 1648 | /// Same memory object can be shared by multiple allocations. 1649 | /// 1650 | /// It can change after call to Defragment() if this allocation is passed to the function, or if allocation is lost. 1651 | /// 1652 | /// If the allocation is lost, it is equal to `.Null`. 1653 | deviceMemory: vk.DeviceMemory, 1654 | /// \brief Offset into deviceMemory object to the beginning of this allocation, in bytes. (deviceMemory, offset) pair is unique to this allocation. 1655 | /// 1656 | /// It can change after call to Defragment() if this allocation is passed to the function, or if allocation is lost. 1657 | offset: vk.DeviceSize, 1658 | /// \brief Size of this allocation, in bytes. 1659 | /// 1660 | /// It never changes, unless allocation is lost. 1661 | size: vk.DeviceSize, 1662 | /// \brief Pointer to the beginning of this allocation as mapped data. 1663 | /// 1664 | /// If the allocation hasn't been mapped using MapMemory() and hasn't been 1665 | /// created with #VMA_ALLOCATION_CREATE_MAPPED_BIT flag, this value null. 1666 | /// 1667 | /// It can change after call to MapMemory(), UnmapMemory(). 1668 | /// It can also change after call to Defragment() if this allocation is passed to the function. 1669 | pMappedData: ?*anyopaque, 1670 | /// \brief Custom general-purpose pointer that was passed as AllocationCreateInfo::pUserData or set using SetAllocationUserData(). 1671 | /// 1672 | /// It can change after call to SetAllocationUserData() for this allocation. 1673 | pUserData: ?*anyopaque, 1674 | }; 1675 | 1676 | /// \struct DefragmentationContext 1677 | /// \brief Represents Opaque object that represents started defragmentation process. 1678 | /// 1679 | /// Fill structure #DefragmentationInfo2 and call function DefragmentationBegin() to create it. 1680 | /// Call function DefragmentationEnd() to destroy it. 1681 | pub const DefragmentationContext = enum(usize) { Null = 0, _ }; 1682 | 1683 | /// Flags to be used in DefragmentationBegin(). None at the moment. Reserved for future use. 1684 | pub const DefragmentationFlags = packed struct { 1685 | __reserved_bits_0_31: u32 = 0, 1686 | 1687 | pub usingnamespace vk.FlagsMixin(@This()); 1688 | }; 1689 | 1690 | /// \brief Parameters for defragmentation. 1691 | /// 1692 | /// To be used with function DefragmentationBegin(). 1693 | pub const DefragmentationInfo2 = extern struct { 1694 | /// \brief Reserved for future use. Should be 0. 1695 | flags: DefragmentationFlags = .{}, 1696 | /// \brief Number of allocations in `pAllocations` array. 1697 | allocationCount: u32, 1698 | /// \brief Pointer to array of allocations that can be defragmented. 1699 | /// 1700 | /// The array should have `allocationCount` elements. 1701 | /// The array should not contain nulls. 1702 | /// Elements in the array should be unique - same allocation cannot occur twice. 1703 | /// It is safe to pass allocations that are in the lost state - they are ignored. 1704 | /// All allocations not present in this array are considered non-moveable during this defragmentation. 1705 | pAllocations: [*]Allocation, 1706 | /// \brief Optional, output. Pointer to array that will be filled with information whether the allocation at certain index has been changed during defragmentation. 1707 | /// 1708 | /// The array should have `allocationCount` elements. 1709 | /// You can pass null if you are not interested in this information. 1710 | pAllocationsChanged: ?[*]vk.Bool32, 1711 | /// \brief Numer of pools in `pPools` array. 1712 | poolCount: u32, 1713 | /// \brief Either null or pointer to array of pools to be defragmented. 1714 | /// 1715 | /// All the allocations in the specified pools can be moved during defragmentation 1716 | /// and there is no way to check if they were really moved as in `pAllocationsChanged`, 1717 | /// so you must query all the allocations in all these pools for new `vk.DeviceMemory` 1718 | /// and offset using GetAllocationInfo() if you might need to recreate buffers 1719 | /// and images bound to them. 1720 | /// 1721 | /// The array should have `poolCount` elements. 1722 | /// The array should not contain nulls. 1723 | /// Elements in the array should be unique - same pool cannot occur twice. 1724 | /// 1725 | /// Using this array is equivalent to specifying all allocations from the pools in `pAllocations`. 1726 | /// It might be more efficient. 1727 | pPools: ?[*]Pool, 1728 | /// \brief Maximum total numbers of bytes that can be copied while moving allocations to different places using transfers on CPU side, like `memcpy()`, `memmove()`. 1729 | /// 1730 | /// `vk.WHOLE_SIZE` means no limit. 1731 | maxCpuBytesToMove: vk.DeviceSize, 1732 | /// \brief Maximum number of allocations that can be moved to a different place using transfers on CPU side, like `memcpy()`, `memmove()`. 1733 | /// 1734 | /// `UINT32_MAX` means no limit. 1735 | maxCpuAllocationsToMove: u32, 1736 | /// \brief Maximum total numbers of bytes that can be copied while moving allocations to different places using transfers on GPU side, posted to `commandBuffer`. 1737 | /// 1738 | /// `vk.WHOLE_SIZE` means no limit. 1739 | maxGpuBytesToMove: vk.DeviceSize, 1740 | /// \brief Maximum number of allocations that can be moved to a different place using transfers on GPU side, posted to `commandBuffer`. 1741 | /// 1742 | /// `UINT32_MAX` means no limit. 1743 | maxGpuAllocationsToMove: u32, 1744 | /// \brief Optional. Command buffer where GPU copy commands will be posted. 1745 | /// 1746 | /// If not null, it must be a valid command buffer handle that supports Transfer queue type. 1747 | /// It must be in the recording state and outside of a render pass instance. 1748 | /// You need to submit it and make sure it finished execution before calling DefragmentationEnd(). 1749 | /// 1750 | /// Passing null means that only CPU defragmentation will be performed. 1751 | commandBuffer: vk.CommandBuffer, 1752 | }; 1753 | 1754 | /// \brief Deprecated. Optional configuration parameters to be passed to function Defragment(). 1755 | /// 1756 | /// \deprecated This is a part of the old interface. It is recommended to use structure #DefragmentationInfo2 and function DefragmentationBegin() instead. 1757 | pub const DefragmentationInfo = extern struct { 1758 | /// \brief Maximum total numbers of bytes that can be copied while moving allocations to different places. 1759 | /// 1760 | /// Default is `vk.WHOLE_SIZE`, which means no limit. 1761 | maxBytesToMove: vk.DeviceSize, 1762 | /// \brief Maximum number of allocations that can be moved to different place. 1763 | /// 1764 | /// Default is `UINT32_MAX`, which means no limit. 1765 | maxAllocationsToMove: u32, 1766 | }; 1767 | 1768 | /// \brief Statistics returned by function Defragment(). 1769 | pub const DefragmentationStats = extern struct { 1770 | /// Total number of bytes that have been copied while moving allocations to different places. 1771 | bytesMoved: vk.DeviceSize, 1772 | /// Total number of bytes that have been released to the system by freeing empty `vk.DeviceMemory` objects. 1773 | bytesFreed: vk.DeviceSize, 1774 | /// Number of allocations that have been moved to different places. 1775 | allocationsMoved: u32, 1776 | /// Number of empty `vk.DeviceMemory` objects that have been released to the system. 1777 | deviceMemoryBlocksFreed: u32, 1778 | }; 1779 | 1780 | pub extern fn vmaCreateAllocator(pCreateInfo: *const AllocatorCreateInfo, pAllocator: *Allocator) callconv(CallConv) vk.Result; 1781 | pub extern fn vmaDestroyAllocator(allocator: Allocator) callconv(CallConv) void; 1782 | 1783 | pub extern fn vmaGetPhysicalDeviceProperties( 1784 | allocator: Allocator, 1785 | ppPhysicalDeviceProperties: **const vk.PhysicalDeviceProperties, 1786 | ) callconv(CallConv) void; 1787 | pub extern fn vmaGetMemoryProperties( 1788 | allocator: Allocator, 1789 | ppPhysicalDeviceMemoryProperties: **const vk.PhysicalDeviceMemoryProperties, 1790 | ) callconv(CallConv) void; 1791 | pub extern fn vmaGetMemoryTypeProperties( 1792 | allocator: Allocator, 1793 | memoryTypeIndex: u32, 1794 | pFlags: *align(4) vk.MemoryPropertyFlags, 1795 | ) callconv(CallConv) void; 1796 | 1797 | pub extern fn vmaSetCurrentFrameIndex(allocator: Allocator, frameIndex: u32) callconv(CallConv) void; 1798 | pub extern fn vmaCalculateStats(allocator: Allocator, pStats: *Stats) callconv(CallConv) void; 1799 | 1800 | pub extern fn vmaGetBudget( 1801 | allocator: Allocator, 1802 | pBudget: *Budget, 1803 | ) callconv(CallConv) void; 1804 | 1805 | // pub usingnamespace if (config.statsStringEnabled) 1806 | // struct { 1807 | // pub extern fn vmaBuildStatsString( 1808 | // allocator: Allocator, 1809 | // ppStatsString: *[*:0]u8, 1810 | // detailedMap: vk.Bool32, 1811 | // ) callconv(CallConv) void; 1812 | // pub extern fn vmaFreeStatsString( 1813 | // allocator: Allocator, 1814 | // pStatsString: [*:0]u8, 1815 | // ) callconv(CallConv) void; 1816 | // } 1817 | // else 1818 | // struct {}; 1819 | 1820 | pub extern fn vmaFindMemoryTypeIndex( 1821 | allocator: Allocator, 1822 | memoryTypeBits: u32, 1823 | pAllocationCreateInfo: *const AllocationCreateInfo, 1824 | pMemoryTypeIndex: *u32, 1825 | ) callconv(CallConv) vk.Result; 1826 | 1827 | pub extern fn vmaFindMemoryTypeIndexForBufferInfo( 1828 | allocator: Allocator, 1829 | pBufferCreateInfo: *const vk.BufferCreateInfo, 1830 | pAllocationCreateInfo: *const AllocationCreateInfo, 1831 | pMemoryTypeIndex: *u32, 1832 | ) callconv(CallConv) vk.Result; 1833 | 1834 | pub extern fn vmaFindMemoryTypeIndexForImageInfo( 1835 | allocator: Allocator, 1836 | pImageCreateInfo: *const vk.ImageCreateInfo, 1837 | pAllocationCreateInfo: *const AllocationCreateInfo, 1838 | pMemoryTypeIndex: *u32, 1839 | ) callconv(CallConv) vk.Result; 1840 | 1841 | pub extern fn vmaCreatePool( 1842 | allocator: Allocator, 1843 | pCreateInfo: *const PoolCreateInfo, 1844 | pPool: *Pool, 1845 | ) callconv(CallConv) vk.Result; 1846 | 1847 | pub extern fn vmaDestroyPool( 1848 | allocator: Allocator, 1849 | pool: Pool, 1850 | ) callconv(CallConv) void; 1851 | 1852 | pub extern fn vmaGetPoolStats( 1853 | allocator: Allocator, 1854 | pool: Pool, 1855 | pPoolStats: *PoolStats, 1856 | ) callconv(CallConv) void; 1857 | 1858 | pub extern fn vmaMakePoolAllocationsLost( 1859 | allocator: Allocator, 1860 | pool: Pool, 1861 | pLostAllocationCount: ?*usize, 1862 | ) callconv(CallConv) void; 1863 | 1864 | pub extern fn vmaCheckPoolCorruption(allocator: Allocator, pool: Pool) callconv(CallConv) vk.Result; 1865 | 1866 | pub extern fn vmaGetPoolName( 1867 | allocator: Allocator, 1868 | pool: Pool, 1869 | ppName: *?[*:0]const u8, 1870 | ) callconv(CallConv) void; 1871 | 1872 | pub extern fn vmaSetPoolName( 1873 | allocator: Allocator, 1874 | pool: Pool, 1875 | pName: ?[*:0]const u8, 1876 | ) callconv(CallConv) void; 1877 | 1878 | pub extern fn vmaAllocateMemory( 1879 | allocator: Allocator, 1880 | pVkMemoryRequirements: *const vk.MemoryRequirements, 1881 | pCreateInfo: *const AllocationCreateInfo, 1882 | pAllocation: *Allocation, 1883 | pAllocationInfo: ?*AllocationInfo, 1884 | ) callconv(CallConv) vk.Result; 1885 | 1886 | pub extern fn vmaAllocateMemoryPages( 1887 | allocator: Allocator, 1888 | pVkMemoryRequirements: *const vk.MemoryRequirements, 1889 | pCreateInfo: *const AllocationCreateInfo, 1890 | allocationCount: usize, 1891 | pAllocations: [*]Allocation, 1892 | pAllocationInfo: ?[*]AllocationInfo, 1893 | ) callconv(CallConv) vk.Result; 1894 | 1895 | pub extern fn vmaAllocateMemoryForBuffer( 1896 | allocator: Allocator, 1897 | buffer: vk.Buffer, 1898 | pCreateInfo: *const AllocationCreateInfo, 1899 | pAllocation: *Allocation, 1900 | pAllocationInfo: ?*AllocationInfo, 1901 | ) callconv(CallConv) vk.Result; 1902 | 1903 | pub extern fn vmaAllocateMemoryForImage( 1904 | allocator: Allocator, 1905 | image: vk.Image, 1906 | pCreateInfo: *const AllocationCreateInfo, 1907 | pAllocation: *Allocation, 1908 | pAllocationInfo: ?*AllocationInfo, 1909 | ) callconv(CallConv) vk.Result; 1910 | 1911 | pub extern fn vmaFreeMemory( 1912 | allocator: Allocator, 1913 | allocation: Allocation, 1914 | ) callconv(CallConv) void; 1915 | 1916 | pub extern fn vmaFreeMemoryPages( 1917 | allocator: Allocator, 1918 | allocationCount: usize, 1919 | pAllocations: [*]Allocation, 1920 | ) callconv(CallConv) void; 1921 | 1922 | /// \brief Deprecated. 1923 | /// 1924 | /// In version 2.2.0 it used to try to change allocation's size without moving or reallocating it. 1925 | /// In current version it returns `vk.SUCCESS` only if `newSize` equals current allocation's size. 1926 | /// Otherwise returns `error.VK_OUT_OF_POOL_MEMORY`, indicating that allocation's size could not be changed. 1927 | pub extern fn vmaResizeAllocation( 1928 | allocator: Allocator, 1929 | allocation: Allocation, 1930 | newSize: vk.DeviceSize, 1931 | ) callconv(CallConv) vk.Result; 1932 | 1933 | pub extern fn vmaGetAllocationInfo( 1934 | allocator: Allocator, 1935 | allocation: Allocation, 1936 | pAllocationInfo: *AllocationInfo, 1937 | ) callconv(CallConv) void; 1938 | 1939 | pub extern fn vmaTouchAllocation( 1940 | allocator: Allocator, 1941 | allocation: Allocation, 1942 | ) callconv(CallConv) vk.Bool32; 1943 | 1944 | pub extern fn vmaSetAllocationUserData( 1945 | allocator: Allocator, 1946 | allocation: Allocation, 1947 | pUserData: ?*anyopaque, 1948 | ) callconv(CallConv) void; 1949 | 1950 | pub extern fn vmaCreateLostAllocation( 1951 | allocator: Allocator, 1952 | pAllocation: *Allocation, 1953 | ) callconv(CallConv) void; 1954 | 1955 | pub extern fn vmaMapMemory( 1956 | allocator: Allocator, 1957 | allocation: Allocation, 1958 | ppData: **anyopaque, 1959 | ) callconv(CallConv) vk.Result; 1960 | 1961 | pub extern fn vmaUnmapMemory( 1962 | allocator: Allocator, 1963 | allocation: Allocation, 1964 | ) callconv(CallConv) void; 1965 | 1966 | pub extern fn vmaFlushAllocation(allocator: Allocator, allocation: Allocation, offset: vk.DeviceSize, size: vk.DeviceSize) callconv(CallConv) void; 1967 | 1968 | pub extern fn vmaInvalidateAllocation(allocator: Allocator, allocation: Allocation, offset: vk.DeviceSize, size: vk.DeviceSize) callconv(CallConv) void; 1969 | 1970 | pub extern fn vmaCheckCorruption(allocator: Allocator, memoryTypeBits: u32) callconv(CallConv) vk.Result; 1971 | 1972 | pub extern fn vmaDefragmentationBegin( 1973 | allocator: Allocator, 1974 | pInfo: *const DefragmentationInfo2, 1975 | pStats: ?*DefragmentationStats, 1976 | pContext: *DefragmentationContext, 1977 | ) callconv(CallConv) vk.Result; 1978 | 1979 | pub extern fn vmaDefragmentationEnd( 1980 | allocator: Allocator, 1981 | context: DefragmentationContext, 1982 | ) callconv(CallConv) vk.Result; 1983 | 1984 | /// \brief Deprecated. Compacts memory by moving allocations. 1985 | /// 1986 | /// @param pAllocations Array of allocations that can be moved during this compation. 1987 | /// @param allocationCount Number of elements in pAllocations and pAllocationsChanged arrays. 1988 | /// @param[out] pAllocationsChanged Array of boolean values that will indicate whether matching allocation in pAllocations array has been moved. This parameter is optional. Pass null if you don't need this information. 1989 | /// @param pDefragmentationInfo Configuration parameters. Optional - pass null to use default values. 1990 | /// @param[out] pDefragmentationStats Statistics returned by the function. Optional - pass null if you don't need this information. 1991 | /// @return `vk.SUCCESS` if completed, negative error code in case of error. 1992 | /// 1993 | /// \deprecated This is a part of the old interface. It is recommended to use structure #DefragmentationInfo2 and function DefragmentationBegin() instead. 1994 | /// 1995 | /// This function works by moving allocations to different places (different 1996 | /// `vk.DeviceMemory` objects and/or different offsets) in order to optimize memory 1997 | /// usage. Only allocations that are in `pAllocations` array can be moved. All other 1998 | /// allocations are considered nonmovable in this call. Basic rules: 1999 | /// 2000 | /// - Only allocations made in memory types that have 2001 | /// `vk.MEMORY_PROPERTY_HOST_VISIBLE_BIT` and `vk.MEMORY_PROPERTY_HOST_COHERENT_BIT` 2002 | /// flags can be compacted. You may pass other allocations but it makes no sense - 2003 | /// these will never be moved. 2004 | /// - Custom pools created with #VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT or 2005 | /// #VMA_POOL_CREATE_BUDDY_ALGORITHM_BIT flag are not defragmented. Allocations 2006 | /// passed to this function that come from such pools are ignored. 2007 | /// - Allocations created with #VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT or 2008 | /// created as dedicated allocations for any other reason are also ignored. 2009 | /// - Both allocations made with or without #VMA_ALLOCATION_CREATE_MAPPED_BIT 2010 | /// flag can be compacted. If not persistently mapped, memory will be mapped 2011 | /// temporarily inside this function if needed. 2012 | /// - You must not pass same #Allocation object multiple times in `pAllocations` array. 2013 | /// 2014 | /// The function also frees empty `vk.DeviceMemory` blocks. 2015 | /// 2016 | /// Warning: This function may be time-consuming, so you shouldn't call it too often 2017 | /// (like after every resource creation/destruction). 2018 | /// You can call it on special occasions (like when reloading a game level or 2019 | /// when you just destroyed a lot of objects). Calling it every frame may be OK, but 2020 | /// you should measure that on your platform. 2021 | /// 2022 | /// For more information, see [Defragmentation](@ref defragmentation) chapter. 2023 | pub extern fn vmaDefragment( 2024 | allocator: Allocator, 2025 | pAllocations: *Allocation, 2026 | allocationCount: usize, 2027 | pAllocationsChanged: *vk.Bool32, 2028 | pDefragmentationInfo: *const DefragmentationInfo, 2029 | pDefragmentationStats: *DefragmentationStats, 2030 | ) callconv(CallConv) vk.Result; 2031 | 2032 | pub extern fn vmaBindBufferMemory( 2033 | allocator: Allocator, 2034 | allocation: Allocation, 2035 | buffer: vk.Buffer, 2036 | ) callconv(CallConv) vk.Result; 2037 | 2038 | pub extern fn vmaBindBufferMemory2( 2039 | allocator: Allocator, 2040 | allocation: Allocation, 2041 | allocationLocalOffset: vk.DeviceSize, 2042 | buffer: vk.Buffer, 2043 | pNext: ?*const anyopaque, 2044 | ) callconv(CallConv) vk.Result; 2045 | 2046 | pub extern fn vmaBindImageMemory( 2047 | allocator: Allocator, 2048 | allocation: Allocation, 2049 | image: vk.Image, 2050 | ) callconv(CallConv) vk.Result; 2051 | 2052 | pub extern fn vmaBindImageMemory2( 2053 | allocator: Allocator, 2054 | allocation: Allocation, 2055 | allocationLocalOffset: vk.DeviceSize, 2056 | image: vk.Image, 2057 | pNext: ?*const anyopaque, 2058 | ) callconv(CallConv) vk.Result; 2059 | 2060 | pub extern fn vmaCreateBuffer( 2061 | allocator: Allocator, 2062 | pBufferCreateInfo: *const vk.BufferCreateInfo, 2063 | pAllocationCreateInfo: *const AllocationCreateInfo, 2064 | pBuffer: *vk.Buffer, 2065 | pAllocation: *Allocation, 2066 | pAllocationInfo: ?*AllocationInfo, 2067 | ) callconv(CallConv) vk.Result; 2068 | 2069 | pub extern fn vmaDestroyBuffer( 2070 | allocator: Allocator, 2071 | buffer: vk.Buffer, 2072 | allocation: Allocation, 2073 | ) callconv(CallConv) void; 2074 | 2075 | pub extern fn vmaCreateImage( 2076 | allocator: Allocator, 2077 | pImageCreateInfo: *const vk.ImageCreateInfo, 2078 | pAllocationCreateInfo: *const AllocationCreateInfo, 2079 | pImage: *vk.Image, 2080 | pAllocation: *Allocation, 2081 | pAllocationInfo: ?*AllocationInfo, 2082 | ) callconv(CallConv) vk.Result; 2083 | 2084 | pub extern fn vmaDestroyImage( 2085 | allocator: Allocator, 2086 | image: vk.Image, 2087 | allocation: Allocation, 2088 | ) callconv(CallConv) void; 2089 | -------------------------------------------------------------------------------- /vma_build.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const Builder = std.build.Builder; 3 | const LibExeObjStep = std.build.LibExeObjStep; 4 | const Pkg = std.build.Pkg; 5 | const vma_config = @import("vma_config.zig"); 6 | const version: std.SemanticVersion = @import("builtin").zig_version; 7 | const old_pkg_structure = version.order(std.SemanticVersion.parse("0.9.1") catch unreachable) != .gt; 8 | 9 | // @src() is only allowed inside of a function, so we need this wrapper 10 | fn srcFile() []const u8 { return @src().file; } 11 | const sep = std.fs.path.sep_str; 12 | 13 | const zig_vma_path = std.fs.path.dirname(srcFile()).?; 14 | const zig_vma_file = zig_vma_path ++ sep ++ "vma.zig"; 15 | 16 | pub fn pkg(b: *Builder, vk_root_file: []const u8) Pkg { 17 | const allocator = b.allocator; 18 | return if (old_pkg_structure) Pkg{ 19 | .name = "vma", 20 | .path = .{ .path = zig_vma_file }, 21 | .dependencies = allocator.dupe(Pkg, &[_]Pkg{ .{ 22 | .name = "vk", 23 | .path = .{ .path = vk_root_file }, 24 | } }) catch unreachable, 25 | } else Pkg{ 26 | .name = "vma", 27 | .source = .{ .path = zig_vma_file }, 28 | .dependencies = allocator.dupe(Pkg, &[_]Pkg{ .{ 29 | .name = "vk", 30 | .source = .{ .path = vk_root_file }, 31 | } }) catch unreachable, 32 | }; 33 | } 34 | 35 | 36 | fn getConfigArgs(comptime config: vma_config.Config) []const []const u8 { 37 | comptime { 38 | @setEvalBranchQuota(100000); 39 | var args: []const []const u8 = &[_][]const u8 { 40 | std.fmt.comptimePrint("-DVMA_VULKAN_VERSION={}", .{ config.vulkanVersion }), 41 | std.fmt.comptimePrint("-DVMA_DEDICATED_ALLOCATION={}", .{ @boolToInt(config.dedicatedAllocation)}), 42 | std.fmt.comptimePrint("-DVMA_BIND_MEMORY2={}", .{ @boolToInt(config.bindMemory2)}), 43 | std.fmt.comptimePrint("-DVMA_MEMORY_BUDGET={}", .{ @boolToInt(config.memoryBudget)}), 44 | std.fmt.comptimePrint("-DVMA_STATIC_VULKAN_FUNCTIONS={}", .{ @boolToInt(config.staticVulkanFunctions)}), 45 | std.fmt.comptimePrint("-DVMA_STATS_STRING_ENABLED={}", .{ @boolToInt(config.statsStringEnabled)}), 46 | }; 47 | if (config.debugInitializeAllocations) |value| { 48 | args = args ++ &[_][]const u8 { std.fmt.comptimePrint( 49 | "-DVMA_DEBUG_INITIALIZE_ALLOCATIONS={}", 50 | .{ @boolToInt(value) }, 51 | ) }; 52 | } 53 | if (config.debugMargin) |value| { 54 | args = args ++ &[_][]const u8 { std.fmt.comptimePrint( 55 | "-DVMA_DEBUG_MARGIN={}", 56 | .{ value }, 57 | ) }; 58 | } 59 | if (config.debugDetectCorruption) |value| { 60 | args = args ++ &[_][]const u8 { std.fmt.comptimePrint( 61 | "-DVMA_DEBUG_DETECT_CORRUPTION={}", 62 | .{ @boolToInt(value) }, 63 | ) }; 64 | } 65 | if (config.recordingEnabled) |value| { 66 | args = args ++ &[_][]const u8 { std.fmt.comptimePrint( 67 | "-DVMA_RECORDING_ENABLED={}", 68 | .{ @boolToInt(value) }, 69 | ) }; 70 | } 71 | if (config.debugMinBufferImageGranularity) |value| { 72 | args = args ++ &[_][]const u8 { std.fmt.comptimePrint( 73 | "-DVMA_DEBUG_MIN_BUFFER_IMAGE_GRANULARITY={}", 74 | .{ value }, 75 | ) }; 76 | } 77 | if (config.debugGlobalMutex) |value| { 78 | args = args ++ &[_][]const u8 { std.fmt.comptimePrint( 79 | "-DVMA_DEBUG_GLOBAL_MUTEX={}", 80 | .{ @boolToInt(value) }, 81 | ) }; 82 | } 83 | if (config.useStlContainers) |value| { 84 | args = args ++ &[_][]const u8 { std.fmt.comptimePrint( 85 | "-DVMA_USE_STL_CONTAINERS={}", 86 | .{ @boolToInt(value) }, 87 | ) }; 88 | } 89 | if (config.useStlSharedMutex) |value| { 90 | args = args ++ &[_][]const u8 { std.fmt.comptimePrint( 91 | "-DVMA_USE_STL_SHARED_MUTEX={}", 92 | .{ @boolToInt(value) }, 93 | ) }; 94 | } 95 | 96 | return args; 97 | } 98 | } 99 | 100 | pub fn link(object: *LibExeObjStep, vk_root_file: []const u8, mode: std.builtin.Mode, target: std.zig.CrossTarget) void { 101 | linkWithoutPkg(object, mode, target); 102 | object.addPackage(pkg(object.builder, vk_root_file)); 103 | } 104 | 105 | pub fn linkWithoutPkg(object: *LibExeObjStep, mode: std.builtin.Mode, target: std.zig.CrossTarget) void { 106 | const commonArgs = &[_][]const u8 { "-std=c++14", "-DVMA_IMPLEMENTATION" }; 107 | const releaseArgs = &[_][]const u8 { } ++ commonArgs ++ comptime getConfigArgs(vma_config.releaseConfig); 108 | const debugArgs = &[_][]const u8 { } ++ commonArgs ++ comptime getConfigArgs(vma_config.debugConfig); 109 | const args = if (mode == .Debug) debugArgs else releaseArgs; 110 | 111 | object.addCSourceFile(zig_vma_path ++ sep ++ "vk_mem_alloc.cpp", args); 112 | object.linkLibC(); 113 | if (target.getAbi() != .msvc) { 114 | // MSVC can't link libc++, it causes duplicate symbol errors. 115 | // But it's needed for other targets. 116 | object.linkLibCpp(); 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /vma_config.zig: -------------------------------------------------------------------------------- 1 | // This file stores comptime-known configuration variables. 2 | // These would be defines specified before including vk_mem_alloc.h. 3 | // This file is read by both the `zig build` in this repo and the 4 | // zig header. 5 | 6 | pub const debugConfig = Config{ 7 | // Override values here for your build 8 | .vulkanVersion = 1001000, // Vulkan 1.1 9 | //.recordingEnabled = true, 10 | //.statsStringEnabled = false, 11 | //.debugMargin = 64, 12 | //.debugDetectCorruption = true, 13 | //.debugInitializeAllocations = true, 14 | //.debugGlobalMutex = true, 15 | //.debugMinBufferImageGranularity = 256, 16 | }; 17 | 18 | pub const releaseConfig = Config{ 19 | // Override values here for your build 20 | .vulkanVersion = 1001000, // Vulkan 1.1 21 | //.statsStringEnabled = false, 22 | }; 23 | 24 | // Default values here, please do not change 25 | // Null in any of these values means that no 26 | // define will be passed to the build and the 27 | // default value will be used. 28 | pub const Config = struct { 29 | /// The current version of vulkan 30 | vulkanVersion: u32 = 1000000, // Vulkan 1.0 31 | 32 | /// Whether to use the KHR Dedicated Allocation extension 33 | dedicatedAllocation: bool = false, // NOTE: Please modify values in the instance at the top of this file, not here. 34 | 35 | /// Whether to use the KHR Bind Memory 2 extension 36 | bindMemory2: bool = false, // NOTE: Please modify values in the instance at the top of this file, not here. 37 | 38 | /// Whether to use the KHR Memory Budget extension 39 | memoryBudget: bool = false, // NOTE: Please modify values in the instance at the top of this file, not here. 40 | 41 | /// If you experience a bug with incorrect and nondeterministic data in your program and you suspect uninitialized memory to be used, 42 | /// you can enable automatic memory initialization to verify this. 43 | /// To do it, set debugInitializeAllocations to true. 44 | /// 45 | /// It makes memory of all new allocations initialized to bit pattern `0xDCDCDCDC`. 46 | /// Before an allocation is destroyed, its memory is filled with bit pattern `0xEFEFEFEF`. 47 | /// Memory is automatically mapped and unmapped if necessary. 48 | /// 49 | /// If you find these values while debugging your program, good chances are that you incorrectly 50 | /// read Vulkan memory that is allocated but not initialized, or already freed, respectively. 51 | /// 52 | /// Memory initialization works only with memory types that are `HOST_VISIBLE`. 53 | /// It works also with dedicated allocations. 54 | /// It doesn't work with allocations created with #VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT flag, 55 | /// as they cannot be mapped. 56 | debugInitializeAllocations: ?bool = null, // NOTE: Please modify values in the instance at the top of this file, not here. 57 | 58 | /// By default, allocations are laid out in memory blocks next to each other if possible 59 | /// (considering required alignment, `bufferImageGranularity`, and `nonCoherentAtomSize`). 60 | /// 61 | /// ![Allocations without margin](../gfx/Margins_1.png) 62 | /// 63 | /// Define debugMargin to some non-zero value (e.g. 16) to enforce specified 64 | /// number of bytes as a margin before and after every allocation. 65 | /// If your bug goes away after enabling margins, it means it may be caused by memory 66 | /// being overwritten outside of allocation boundaries. It is not 100% certain though. 67 | /// Change in application behavior may also be caused by different order and distribution 68 | /// of allocations across memory blocks after margins are applied. 69 | /// 70 | /// The margin is applied also before first and after last allocation in a block. 71 | /// It may occur only once between two adjacent allocations. 72 | /// 73 | /// Margins work with all types of memory. 74 | /// 75 | /// Margin is applied only to allocations made out of memory blocks and not to dedicated 76 | /// allocations, which have their own memory block of specific size. 77 | /// It is thus not applied to allocations made using #VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT flag 78 | /// or those automatically decided to put into dedicated allocations, e.g. due to its 79 | /// large size or recommended by VK_KHR_dedicated_allocation extension. 80 | /// Margins are also not active in custom pools created with #VMA_POOL_CREATE_BUDDY_ALGORITHM_BIT flag. 81 | /// 82 | /// Margins appear in [JSON dump](@ref statistics_json_dump) as part of free space. 83 | /// 84 | /// Note that enabling margins increases memory usage and fragmentation. 85 | debugMargin: ?usize = null, // NOTE: Please modify values in the instance at the top of this file, not here. 86 | 87 | /// You can additionally set debugDetectCorruption to enable validation 88 | /// of contents of the margins. 89 | /// 90 | /// When this feature is enabled, number of bytes specified as `VMA_DEBUG_MARGIN` 91 | /// (it must be multiply of 4) before and after every allocation is filled with a magic number. 92 | /// This idea is also know as "canary". 93 | /// Memory is automatically mapped and unmapped if necessary. 94 | /// 95 | /// This number is validated automatically when the allocation is destroyed. 96 | /// If it's not equal to the expected value, `VMA_ASSERT()` is executed. 97 | /// It clearly means that either CPU or GPU overwritten the memory outside of boundaries of the allocation, 98 | /// which indicates a serious bug. 99 | /// 100 | /// You can also explicitly request checking margins of all allocations in all memory blocks 101 | /// that belong to specified memory types by using function vmaCheckCorruption(), 102 | /// or in memory blocks that belong to specified custom pool, by using function 103 | /// vmaCheckPoolCorruption(). 104 | /// 105 | /// Margin validation (corruption detection) works only for memory types that are 106 | /// `HOST_VISIBLE` and `HOST_COHERENT`. 107 | debugDetectCorruption: ?bool = null, // NOTE: Please modify values in the instance at the top of this file, not here. 108 | 109 | /// Recording functionality is disabled by default. 110 | /// To enable it, set recordingEnabled to true. 111 | /// 112 | /// To record sequence of calls to a file: Fill in 113 | /// VmaAllocatorCreateInfo::pRecordSettings member while creating #VmaAllocator 114 | /// object. File is opened and written during whole lifetime of the allocator. 115 | /// 116 | /// To replay file: Use VmaReplay - standalone command-line program. 117 | /// Precompiled binary can be found in "bin" directory. 118 | /// Its source can be found in "src/VmaReplay" directory. 119 | /// Its project is generated by Premake. 120 | /// Command line syntax is printed when the program is launched without parameters. 121 | /// Basic usage: 122 | /// 123 | /// VmaReplay.exe MyRecording.csv 124 | /// 125 | /// Documentation of file format can be found in file: "docs/Recording file format.md". 126 | /// It's a human-readable, text file in CSV format (Comma Separated Values). 127 | /// 128 | /// \section record_and_replay_additional_considerations Additional considerations 129 | /// 130 | /// - Replaying file that was recorded on a different GPU (with different parameters 131 | /// like `bufferImageGranularity`, `nonCoherentAtomSize`, and especially different 132 | /// set of memory heaps and types) may give different performance and memory usage 133 | /// results, as well as issue some warnings and errors. 134 | /// - Current implementation of recording in VMA, as well as VmaReplay application, is 135 | /// coded and tested only on Windows. Inclusion of recording code is driven by 136 | /// `VMA_RECORDING_ENABLED` macro. Support for other platforms should be easy to 137 | /// add. Contributions are welcomed. 138 | recordingEnabled: ?bool = null, // NOTE: Please modify values in the instance at the top of this file, not here. 139 | 140 | /// Minimum value for VkPhysicalDeviceLimits::bufferImageGranularity. 141 | /// Set to more than 1 for debugging purposes only. Must be power of two. 142 | debugMinBufferImageGranularity: ?usize = null, // NOTE: Please modify values in the instance at the top of this file, not here. 143 | 144 | /// Set this to 1 for debugging purposes only, to enable single mutex protecting all 145 | /// entry calls to the library. Can be useful for debugging multithreading issues. 146 | debugGlobalMutex: ?bool = null, // NOTE: Please modify values in the instance at the top of this file, not here. 147 | 148 | /// Whether to use C++ STL containers for VMA internal data 149 | useStlContainers: ?bool = null, // NOTE: Please modify values in the instance at the top of this file, not here. 150 | 151 | /// Set to true to always use STL mutex, false otherwise. 152 | /// If null, the library will choose based on whether 153 | /// the compiler supports C++17. 154 | useStlSharedMutex: ?bool = null, // NOTE: Please modify values in the instance at the top of this file, not here. 155 | 156 | // Set this to true to enable functions: vmaBuildStatsString, vmaFreeStatsString. 157 | statsStringEnabled: bool = true, // NOTE: Please modify values in the instance at the top of this file, not here. 158 | 159 | /// Set this value to true to make the library fetch pointers to Vulkan functions 160 | /// internally, like: 161 | /// 162 | /// vulkanFunctions.vkAllocateMemory = &vkAllocateMemory; 163 | /// 164 | /// Set to false if you are going to provide you own pointers to Vulkan functions via 165 | /// AllocatorCreateInfo::pVulkanFunctions. 166 | staticVulkanFunctions: bool = true, // NOTE: Please modify values in the instance at the top of this file, not here. 167 | }; 168 | -------------------------------------------------------------------------------- /vulkan/vk_icd.h: -------------------------------------------------------------------------------- 1 | // 2 | // File: vk_icd.h 3 | // 4 | /* 5 | * Copyright (c) 2015-2016 The Khronos Group Inc. 6 | * Copyright (c) 2015-2016 Valve Corporation 7 | * Copyright (c) 2015-2016 LunarG, Inc. 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | */ 22 | 23 | #ifndef VKICD_H 24 | #define VKICD_H 25 | 26 | #include "vulkan.h" 27 | #include 28 | 29 | // Loader-ICD version negotiation API. Versions add the following features: 30 | // Version 0 - Initial. Doesn't support vk_icdGetInstanceProcAddr 31 | // or vk_icdNegotiateLoaderICDInterfaceVersion. 32 | // Version 1 - Add support for vk_icdGetInstanceProcAddr. 33 | // Version 2 - Add Loader/ICD Interface version negotiation 34 | // via vk_icdNegotiateLoaderICDInterfaceVersion. 35 | // Version 3 - Add ICD creation/destruction of KHR_surface objects. 36 | // Version 4 - Add unknown physical device extension qyering via 37 | // vk_icdGetPhysicalDeviceProcAddr. 38 | // Version 5 - Tells ICDs that the loader is now paying attention to the 39 | // application version of Vulkan passed into the ApplicationInfo 40 | // structure during vkCreateInstance. This will tell the ICD 41 | // that if the loader is older, it should automatically fail a 42 | // call for any API version > 1.0. Otherwise, the loader will 43 | // manually determine if it can support the expected version. 44 | #define CURRENT_LOADER_ICD_INTERFACE_VERSION 5 45 | #define MIN_SUPPORTED_LOADER_ICD_INTERFACE_VERSION 0 46 | #define MIN_PHYS_DEV_EXTENSION_ICD_INTERFACE_VERSION 4 47 | typedef VkResult(VKAPI_PTR *PFN_vkNegotiateLoaderICDInterfaceVersion)(uint32_t *pVersion); 48 | 49 | // This is defined in vk_layer.h which will be found by the loader, but if an ICD is building against this 50 | // file directly, it won't be found. 51 | #ifndef PFN_GetPhysicalDeviceProcAddr 52 | typedef PFN_vkVoidFunction(VKAPI_PTR *PFN_GetPhysicalDeviceProcAddr)(VkInstance instance, const char *pName); 53 | #endif 54 | 55 | /* 56 | * The ICD must reserve space for a pointer for the loader's dispatch 57 | * table, at the start of . 58 | * The ICD must initialize this variable using the SET_LOADER_MAGIC_VALUE macro. 59 | */ 60 | 61 | #define ICD_LOADER_MAGIC 0x01CDC0DE 62 | 63 | typedef union { 64 | uintptr_t loaderMagic; 65 | void *loaderData; 66 | } VK_LOADER_DATA; 67 | 68 | static inline void set_loader_magic_value(void *pNewObject) { 69 | VK_LOADER_DATA *loader_info = (VK_LOADER_DATA *)pNewObject; 70 | loader_info->loaderMagic = ICD_LOADER_MAGIC; 71 | } 72 | 73 | static inline bool valid_loader_magic_value(void *pNewObject) { 74 | const VK_LOADER_DATA *loader_info = (VK_LOADER_DATA *)pNewObject; 75 | return (loader_info->loaderMagic & 0xffffffff) == ICD_LOADER_MAGIC; 76 | } 77 | 78 | /* 79 | * Windows and Linux ICDs will treat VkSurfaceKHR as a pointer to a struct that 80 | * contains the platform-specific connection and surface information. 81 | */ 82 | typedef enum { 83 | VK_ICD_WSI_PLATFORM_MIR, 84 | VK_ICD_WSI_PLATFORM_WAYLAND, 85 | VK_ICD_WSI_PLATFORM_WIN32, 86 | VK_ICD_WSI_PLATFORM_XCB, 87 | VK_ICD_WSI_PLATFORM_XLIB, 88 | VK_ICD_WSI_PLATFORM_ANDROID, 89 | VK_ICD_WSI_PLATFORM_MACOS, 90 | VK_ICD_WSI_PLATFORM_IOS, 91 | VK_ICD_WSI_PLATFORM_DISPLAY, 92 | VK_ICD_WSI_PLATFORM_HEADLESS, 93 | VK_ICD_WSI_PLATFORM_METAL, 94 | } VkIcdWsiPlatform; 95 | 96 | typedef struct { 97 | VkIcdWsiPlatform platform; 98 | } VkIcdSurfaceBase; 99 | 100 | #ifdef VK_USE_PLATFORM_MIR_KHR 101 | typedef struct { 102 | VkIcdSurfaceBase base; 103 | MirConnection *connection; 104 | MirSurface *mirSurface; 105 | } VkIcdSurfaceMir; 106 | #endif // VK_USE_PLATFORM_MIR_KHR 107 | 108 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR 109 | typedef struct { 110 | VkIcdSurfaceBase base; 111 | struct wl_display *display; 112 | struct wl_surface *surface; 113 | } VkIcdSurfaceWayland; 114 | #endif // VK_USE_PLATFORM_WAYLAND_KHR 115 | 116 | #ifdef VK_USE_PLATFORM_WIN32_KHR 117 | typedef struct { 118 | VkIcdSurfaceBase base; 119 | HINSTANCE hinstance; 120 | HWND hwnd; 121 | } VkIcdSurfaceWin32; 122 | #endif // VK_USE_PLATFORM_WIN32_KHR 123 | 124 | #ifdef VK_USE_PLATFORM_XCB_KHR 125 | typedef struct { 126 | VkIcdSurfaceBase base; 127 | xcb_connection_t *connection; 128 | xcb_window_t window; 129 | } VkIcdSurfaceXcb; 130 | #endif // VK_USE_PLATFORM_XCB_KHR 131 | 132 | #ifdef VK_USE_PLATFORM_XLIB_KHR 133 | typedef struct { 134 | VkIcdSurfaceBase base; 135 | Display *dpy; 136 | Window window; 137 | } VkIcdSurfaceXlib; 138 | #endif // VK_USE_PLATFORM_XLIB_KHR 139 | 140 | #ifdef VK_USE_PLATFORM_ANDROID_KHR 141 | typedef struct { 142 | VkIcdSurfaceBase base; 143 | struct ANativeWindow *window; 144 | } VkIcdSurfaceAndroid; 145 | #endif // VK_USE_PLATFORM_ANDROID_KHR 146 | 147 | #ifdef VK_USE_PLATFORM_MACOS_MVK 148 | typedef struct { 149 | VkIcdSurfaceBase base; 150 | const void *pView; 151 | } VkIcdSurfaceMacOS; 152 | #endif // VK_USE_PLATFORM_MACOS_MVK 153 | 154 | #ifdef VK_USE_PLATFORM_IOS_MVK 155 | typedef struct { 156 | VkIcdSurfaceBase base; 157 | const void *pView; 158 | } VkIcdSurfaceIOS; 159 | #endif // VK_USE_PLATFORM_IOS_MVK 160 | 161 | typedef struct { 162 | VkIcdSurfaceBase base; 163 | VkDisplayModeKHR displayMode; 164 | uint32_t planeIndex; 165 | uint32_t planeStackIndex; 166 | VkSurfaceTransformFlagBitsKHR transform; 167 | float globalAlpha; 168 | VkDisplayPlaneAlphaFlagBitsKHR alphaMode; 169 | VkExtent2D imageExtent; 170 | } VkIcdSurfaceDisplay; 171 | 172 | typedef struct { 173 | VkIcdSurfaceBase base; 174 | } VkIcdSurfaceHeadless; 175 | 176 | #ifdef VK_USE_PLATFORM_METAL_EXT 177 | typedef struct { 178 | VkIcdSurfaceBase base; 179 | const CAMetalLayer *pLayer; 180 | } VkIcdSurfaceMetal; 181 | #endif // VK_USE_PLATFORM_METAL_EXT 182 | 183 | #endif // VKICD_H 184 | -------------------------------------------------------------------------------- /vulkan/vk_layer.h: -------------------------------------------------------------------------------- 1 | // 2 | // File: vk_layer.h 3 | // 4 | /* 5 | * Copyright (c) 2015-2017 The Khronos Group Inc. 6 | * Copyright (c) 2015-2017 Valve Corporation 7 | * Copyright (c) 2015-2017 LunarG, Inc. 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | */ 22 | 23 | /* Need to define dispatch table 24 | * Core struct can then have ptr to dispatch table at the top 25 | * Along with object ptrs for current and next OBJ 26 | */ 27 | #pragma once 28 | 29 | #include "vulkan.h" 30 | #if defined(__GNUC__) && __GNUC__ >= 4 31 | #define VK_LAYER_EXPORT __attribute__((visibility("default"))) 32 | #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590) 33 | #define VK_LAYER_EXPORT __attribute__((visibility("default"))) 34 | #else 35 | #define VK_LAYER_EXPORT 36 | #endif 37 | 38 | #define MAX_NUM_UNKNOWN_EXTS 250 39 | 40 | // Loader-Layer version negotiation API. Versions add the following features: 41 | // Versions 0/1 - Initial. Doesn't support vk_layerGetPhysicalDeviceProcAddr 42 | // or vk_icdNegotiateLoaderLayerInterfaceVersion. 43 | // Version 2 - Add support for vk_layerGetPhysicalDeviceProcAddr and 44 | // vk_icdNegotiateLoaderLayerInterfaceVersion. 45 | #define CURRENT_LOADER_LAYER_INTERFACE_VERSION 2 46 | #define MIN_SUPPORTED_LOADER_LAYER_INTERFACE_VERSION 1 47 | 48 | #define VK_CURRENT_CHAIN_VERSION 1 49 | 50 | // Typedef for use in the interfaces below 51 | typedef PFN_vkVoidFunction (VKAPI_PTR *PFN_GetPhysicalDeviceProcAddr)(VkInstance instance, const char* pName); 52 | 53 | // Version negotiation values 54 | typedef enum VkNegotiateLayerStructType { 55 | LAYER_NEGOTIATE_UNINTIALIZED = 0, 56 | LAYER_NEGOTIATE_INTERFACE_STRUCT = 1, 57 | } VkNegotiateLayerStructType; 58 | 59 | // Version negotiation structures 60 | typedef struct VkNegotiateLayerInterface { 61 | VkNegotiateLayerStructType sType; 62 | void *pNext; 63 | uint32_t loaderLayerInterfaceVersion; 64 | PFN_vkGetInstanceProcAddr pfnGetInstanceProcAddr; 65 | PFN_vkGetDeviceProcAddr pfnGetDeviceProcAddr; 66 | PFN_GetPhysicalDeviceProcAddr pfnGetPhysicalDeviceProcAddr; 67 | } VkNegotiateLayerInterface; 68 | 69 | // Version negotiation functions 70 | typedef VkResult (VKAPI_PTR *PFN_vkNegotiateLoaderLayerInterfaceVersion)(VkNegotiateLayerInterface *pVersionStruct); 71 | 72 | // Function prototype for unknown physical device extension command 73 | typedef VkResult(VKAPI_PTR *PFN_PhysDevExt)(VkPhysicalDevice phys_device); 74 | 75 | // ------------------------------------------------------------------------------------------------ 76 | // CreateInstance and CreateDevice support structures 77 | 78 | /* Sub type of structure for instance and device loader ext of CreateInfo. 79 | * When sType == VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO 80 | * or sType == VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO 81 | * then VkLayerFunction indicates struct type pointed to by pNext 82 | */ 83 | typedef enum VkLayerFunction_ { 84 | VK_LAYER_LINK_INFO = 0, 85 | VK_LOADER_DATA_CALLBACK = 1, 86 | VK_LOADER_LAYER_CREATE_DEVICE_CALLBACK = 2 87 | } VkLayerFunction; 88 | 89 | typedef struct VkLayerInstanceLink_ { 90 | struct VkLayerInstanceLink_ *pNext; 91 | PFN_vkGetInstanceProcAddr pfnNextGetInstanceProcAddr; 92 | PFN_GetPhysicalDeviceProcAddr pfnNextGetPhysicalDeviceProcAddr; 93 | } VkLayerInstanceLink; 94 | 95 | /* 96 | * When creating the device chain the loader needs to pass 97 | * down information about it's device structure needed at 98 | * the end of the chain. Passing the data via the 99 | * VkLayerDeviceInfo avoids issues with finding the 100 | * exact instance being used. 101 | */ 102 | typedef struct VkLayerDeviceInfo_ { 103 | void *device_info; 104 | PFN_vkGetInstanceProcAddr pfnNextGetInstanceProcAddr; 105 | } VkLayerDeviceInfo; 106 | 107 | typedef VkResult (VKAPI_PTR *PFN_vkSetInstanceLoaderData)(VkInstance instance, 108 | void *object); 109 | typedef VkResult (VKAPI_PTR *PFN_vkSetDeviceLoaderData)(VkDevice device, 110 | void *object); 111 | typedef VkResult (VKAPI_PTR *PFN_vkLayerCreateDevice)(VkInstance instance, VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo, 112 | const VkAllocationCallbacks *pAllocator, VkDevice *pDevice, PFN_vkGetInstanceProcAddr layerGIPA, PFN_vkGetDeviceProcAddr *nextGDPA); 113 | typedef void (VKAPI_PTR *PFN_vkLayerDestroyDevice)(VkDevice physicalDevice, const VkAllocationCallbacks *pAllocator, PFN_vkDestroyDevice destroyFunction); 114 | typedef struct { 115 | VkStructureType sType; // VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO 116 | const void *pNext; 117 | VkLayerFunction function; 118 | union { 119 | VkLayerInstanceLink *pLayerInfo; 120 | PFN_vkSetInstanceLoaderData pfnSetInstanceLoaderData; 121 | struct { 122 | PFN_vkLayerCreateDevice pfnLayerCreateDevice; 123 | PFN_vkLayerDestroyDevice pfnLayerDestroyDevice; 124 | } layerDevice; 125 | } u; 126 | } VkLayerInstanceCreateInfo; 127 | 128 | typedef struct VkLayerDeviceLink_ { 129 | struct VkLayerDeviceLink_ *pNext; 130 | PFN_vkGetInstanceProcAddr pfnNextGetInstanceProcAddr; 131 | PFN_vkGetDeviceProcAddr pfnNextGetDeviceProcAddr; 132 | } VkLayerDeviceLink; 133 | 134 | typedef struct { 135 | VkStructureType sType; // VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO 136 | const void *pNext; 137 | VkLayerFunction function; 138 | union { 139 | VkLayerDeviceLink *pLayerInfo; 140 | PFN_vkSetDeviceLoaderData pfnSetDeviceLoaderData; 141 | } u; 142 | } VkLayerDeviceCreateInfo; 143 | 144 | #ifdef __cplusplus 145 | extern "C" { 146 | #endif 147 | 148 | VKAPI_ATTR VkResult VKAPI_CALL vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *pVersionStruct); 149 | 150 | typedef enum VkChainType { 151 | VK_CHAIN_TYPE_UNKNOWN = 0, 152 | VK_CHAIN_TYPE_ENUMERATE_INSTANCE_EXTENSION_PROPERTIES = 1, 153 | VK_CHAIN_TYPE_ENUMERATE_INSTANCE_LAYER_PROPERTIES = 2, 154 | VK_CHAIN_TYPE_ENUMERATE_INSTANCE_VERSION = 3, 155 | } VkChainType; 156 | 157 | typedef struct VkChainHeader { 158 | VkChainType type; 159 | uint32_t version; 160 | uint32_t size; 161 | } VkChainHeader; 162 | 163 | typedef struct VkEnumerateInstanceExtensionPropertiesChain { 164 | VkChainHeader header; 165 | VkResult(VKAPI_PTR *pfnNextLayer)(const struct VkEnumerateInstanceExtensionPropertiesChain *, const char *, uint32_t *, 166 | VkExtensionProperties *); 167 | const struct VkEnumerateInstanceExtensionPropertiesChain *pNextLink; 168 | 169 | #if defined(__cplusplus) 170 | inline VkResult CallDown(const char *pLayerName, uint32_t *pPropertyCount, VkExtensionProperties *pProperties) const { 171 | return pfnNextLayer(pNextLink, pLayerName, pPropertyCount, pProperties); 172 | } 173 | #endif 174 | } VkEnumerateInstanceExtensionPropertiesChain; 175 | 176 | typedef struct VkEnumerateInstanceLayerPropertiesChain { 177 | VkChainHeader header; 178 | VkResult(VKAPI_PTR *pfnNextLayer)(const struct VkEnumerateInstanceLayerPropertiesChain *, uint32_t *, VkLayerProperties *); 179 | const struct VkEnumerateInstanceLayerPropertiesChain *pNextLink; 180 | 181 | #if defined(__cplusplus) 182 | inline VkResult CallDown(uint32_t *pPropertyCount, VkLayerProperties *pProperties) const { 183 | return pfnNextLayer(pNextLink, pPropertyCount, pProperties); 184 | } 185 | #endif 186 | } VkEnumerateInstanceLayerPropertiesChain; 187 | 188 | typedef struct VkEnumerateInstanceVersionChain { 189 | VkChainHeader header; 190 | VkResult(VKAPI_PTR *pfnNextLayer)(const struct VkEnumerateInstanceVersionChain *, uint32_t *); 191 | const struct VkEnumerateInstanceVersionChain *pNextLink; 192 | 193 | #if defined(__cplusplus) 194 | inline VkResult CallDown(uint32_t *pApiVersion) const { 195 | return pfnNextLayer(pNextLink, pApiVersion); 196 | } 197 | #endif 198 | } VkEnumerateInstanceVersionChain; 199 | 200 | #ifdef __cplusplus 201 | } 202 | #endif 203 | -------------------------------------------------------------------------------- /vulkan/vk_platform.h: -------------------------------------------------------------------------------- 1 | // 2 | // File: vk_platform.h 3 | // 4 | /* 5 | ** Copyright (c) 2014-2020 The Khronos Group Inc. 6 | ** 7 | ** Licensed under the Apache License, Version 2.0 (the "License"); 8 | ** you may not use this file except in compliance with the License. 9 | ** You may obtain a copy of the License at 10 | ** 11 | ** http://www.apache.org/licenses/LICENSE-2.0 12 | ** 13 | ** Unless required by applicable law or agreed to in writing, software 14 | ** distributed under the License is distributed on an "AS IS" BASIS, 15 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | ** See the License for the specific language governing permissions and 17 | ** limitations under the License. 18 | */ 19 | 20 | 21 | #ifndef VK_PLATFORM_H_ 22 | #define VK_PLATFORM_H_ 23 | 24 | #ifdef __cplusplus 25 | extern "C" 26 | { 27 | #endif // __cplusplus 28 | 29 | /* 30 | *************************************************************************************************** 31 | * Platform-specific directives and type declarations 32 | *************************************************************************************************** 33 | */ 34 | 35 | /* Platform-specific calling convention macros. 36 | * 37 | * Platforms should define these so that Vulkan clients call Vulkan commands 38 | * with the same calling conventions that the Vulkan implementation expects. 39 | * 40 | * VKAPI_ATTR - Placed before the return type in function declarations. 41 | * Useful for C++11 and GCC/Clang-style function attribute syntax. 42 | * VKAPI_CALL - Placed after the return type in function declarations. 43 | * Useful for MSVC-style calling convention syntax. 44 | * VKAPI_PTR - Placed between the '(' and '*' in function pointer types. 45 | * 46 | * Function declaration: VKAPI_ATTR void VKAPI_CALL vkCommand(void); 47 | * Function pointer type: typedef void (VKAPI_PTR *PFN_vkCommand)(void); 48 | */ 49 | #if defined(_WIN32) 50 | // On Windows, Vulkan commands use the stdcall convention 51 | #define VKAPI_ATTR 52 | #define VKAPI_CALL __stdcall 53 | #define VKAPI_PTR VKAPI_CALL 54 | #elif defined(__ANDROID__) && defined(__ARM_ARCH) && __ARM_ARCH < 7 55 | #error "Vulkan isn't supported for the 'armeabi' NDK ABI" 56 | #elif defined(__ANDROID__) && defined(__ARM_ARCH) && __ARM_ARCH >= 7 && defined(__ARM_32BIT_STATE) 57 | // On Android 32-bit ARM targets, Vulkan functions use the "hardfloat" 58 | // calling convention, i.e. float parameters are passed in registers. This 59 | // is true even if the rest of the application passes floats on the stack, 60 | // as it does by default when compiling for the armeabi-v7a NDK ABI. 61 | #define VKAPI_ATTR __attribute__((pcs("aapcs-vfp"))) 62 | #define VKAPI_CALL 63 | #define VKAPI_PTR VKAPI_ATTR 64 | #else 65 | // On other platforms, use the default calling convention 66 | #define VKAPI_ATTR 67 | #define VKAPI_CALL 68 | #define VKAPI_PTR 69 | #endif 70 | 71 | #include 72 | 73 | #if !defined(VK_NO_STDINT_H) 74 | #if defined(_MSC_VER) && (_MSC_VER < 1600) 75 | typedef signed __int8 int8_t; 76 | typedef unsigned __int8 uint8_t; 77 | typedef signed __int16 int16_t; 78 | typedef unsigned __int16 uint16_t; 79 | typedef signed __int32 int32_t; 80 | typedef unsigned __int32 uint32_t; 81 | typedef signed __int64 int64_t; 82 | typedef unsigned __int64 uint64_t; 83 | #else 84 | #include 85 | #endif 86 | #endif // !defined(VK_NO_STDINT_H) 87 | 88 | #ifdef __cplusplus 89 | } // extern "C" 90 | #endif // __cplusplus 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /vulkan/vk_sdk_platform.h: -------------------------------------------------------------------------------- 1 | // 2 | // File: vk_sdk_platform.h 3 | // 4 | /* 5 | * Copyright (c) 2015-2016 The Khronos Group Inc. 6 | * Copyright (c) 2015-2016 Valve Corporation 7 | * Copyright (c) 2015-2016 LunarG, Inc. 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | #ifndef VK_SDK_PLATFORM_H 23 | #define VK_SDK_PLATFORM_H 24 | 25 | #if defined(_WIN32) 26 | #define NOMINMAX 27 | #ifndef __cplusplus 28 | #undef inline 29 | #define inline __inline 30 | #endif // __cplusplus 31 | 32 | #if (defined(_MSC_VER) && _MSC_VER < 1900 /*vs2015*/) 33 | // C99: 34 | // Microsoft didn't implement C99 in Visual Studio; but started adding it with 35 | // VS2013. However, VS2013 still didn't have snprintf(). The following is a 36 | // work-around (Note: The _CRT_SECURE_NO_WARNINGS macro must be set in the 37 | // "CMakeLists.txt" file). 38 | // NOTE: This is fixed in Visual Studio 2015. 39 | #define snprintf _snprintf 40 | #endif 41 | 42 | #define strdup _strdup 43 | 44 | #endif // _WIN32 45 | 46 | // Check for noexcept support using clang, with fallback to Windows or GCC version numbers 47 | #ifndef NOEXCEPT 48 | #if defined(__clang__) 49 | #if __has_feature(cxx_noexcept) 50 | #define HAS_NOEXCEPT 51 | #endif 52 | #else 53 | #if defined(__GXX_EXPERIMENTAL_CXX0X__) && __GNUC__ * 10 + __GNUC_MINOR__ >= 46 54 | #define HAS_NOEXCEPT 55 | #else 56 | #if defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 190023026 && defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS 57 | #define HAS_NOEXCEPT 58 | #endif 59 | #endif 60 | #endif 61 | 62 | #ifdef HAS_NOEXCEPT 63 | #define NOEXCEPT noexcept 64 | #else 65 | #define NOEXCEPT 66 | #endif 67 | #endif 68 | 69 | #endif // VK_SDK_PLATFORM_H 70 | -------------------------------------------------------------------------------- /vulkan/vulkan.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_H_ 2 | #define VULKAN_H_ 1 3 | 4 | /* 5 | ** Copyright (c) 2015-2020 The Khronos Group Inc. 6 | ** 7 | ** Licensed under the Apache License, Version 2.0 (the "License"); 8 | ** you may not use this file except in compliance with the License. 9 | ** You may obtain a copy of the License at 10 | ** 11 | ** http://www.apache.org/licenses/LICENSE-2.0 12 | ** 13 | ** Unless required by applicable law or agreed to in writing, software 14 | ** distributed under the License is distributed on an "AS IS" BASIS, 15 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | ** See the License for the specific language governing permissions and 17 | ** limitations under the License. 18 | */ 19 | 20 | #include "vk_platform.h" 21 | #include "vulkan_core.h" 22 | 23 | #ifdef VK_USE_PLATFORM_ANDROID_KHR 24 | #include "vulkan_android.h" 25 | #endif 26 | 27 | #ifdef VK_USE_PLATFORM_FUCHSIA 28 | #include 29 | #include "vulkan_fuchsia.h" 30 | #endif 31 | 32 | #ifdef VK_USE_PLATFORM_IOS_MVK 33 | #include "vulkan_ios.h" 34 | #endif 35 | 36 | 37 | #ifdef VK_USE_PLATFORM_MACOS_MVK 38 | #include "vulkan_macos.h" 39 | #endif 40 | 41 | #ifdef VK_USE_PLATFORM_METAL_EXT 42 | #include "vulkan_metal.h" 43 | #endif 44 | 45 | #ifdef VK_USE_PLATFORM_VI_NN 46 | #include "vulkan_vi.h" 47 | #endif 48 | 49 | 50 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR 51 | #include 52 | #include "vulkan_wayland.h" 53 | #endif 54 | 55 | 56 | #ifdef VK_USE_PLATFORM_WIN32_KHR 57 | #include 58 | #include "vulkan_win32.h" 59 | #endif 60 | 61 | 62 | #ifdef VK_USE_PLATFORM_XCB_KHR 63 | #include 64 | #include "vulkan_xcb.h" 65 | #endif 66 | 67 | 68 | #ifdef VK_USE_PLATFORM_XLIB_KHR 69 | #include 70 | #include "vulkan_xlib.h" 71 | #endif 72 | 73 | 74 | #ifdef VK_USE_PLATFORM_XLIB_XRANDR_EXT 75 | #include 76 | #include 77 | #include "vulkan_xlib_xrandr.h" 78 | #endif 79 | 80 | 81 | #ifdef VK_USE_PLATFORM_GGP 82 | #include 83 | #include "vulkan_ggp.h" 84 | #endif 85 | 86 | #endif // VULKAN_H_ 87 | -------------------------------------------------------------------------------- /vulkan/vulkan_android.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_ANDROID_H_ 2 | #define VULKAN_ANDROID_H_ 1 3 | 4 | /* 5 | ** Copyright (c) 2015-2020 The Khronos Group Inc. 6 | ** 7 | ** Licensed under the Apache License, Version 2.0 (the "License"); 8 | ** you may not use this file except in compliance with the License. 9 | ** You may obtain a copy of the License at 10 | ** 11 | ** http://www.apache.org/licenses/LICENSE-2.0 12 | ** 13 | ** Unless required by applicable law or agreed to in writing, software 14 | ** distributed under the License is distributed on an "AS IS" BASIS, 15 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | ** See the License for the specific language governing permissions and 17 | ** limitations under the License. 18 | */ 19 | 20 | /* 21 | ** This header is generated from the Khronos Vulkan XML API Registry. 22 | ** 23 | */ 24 | 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | 31 | 32 | #define VK_KHR_android_surface 1 33 | struct ANativeWindow; 34 | #define VK_KHR_ANDROID_SURFACE_SPEC_VERSION 6 35 | #define VK_KHR_ANDROID_SURFACE_EXTENSION_NAME "VK_KHR_android_surface" 36 | typedef VkFlags VkAndroidSurfaceCreateFlagsKHR; 37 | typedef struct VkAndroidSurfaceCreateInfoKHR { 38 | VkStructureType sType; 39 | const void* pNext; 40 | VkAndroidSurfaceCreateFlagsKHR flags; 41 | struct ANativeWindow* window; 42 | } VkAndroidSurfaceCreateInfoKHR; 43 | 44 | typedef VkResult (VKAPI_PTR *PFN_vkCreateAndroidSurfaceKHR)(VkInstance instance, const VkAndroidSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 45 | 46 | #ifndef VK_NO_PROTOTYPES 47 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateAndroidSurfaceKHR( 48 | VkInstance instance, 49 | const VkAndroidSurfaceCreateInfoKHR* pCreateInfo, 50 | const VkAllocationCallbacks* pAllocator, 51 | VkSurfaceKHR* pSurface); 52 | #endif 53 | 54 | 55 | #define VK_ANDROID_external_memory_android_hardware_buffer 1 56 | struct AHardwareBuffer; 57 | #define VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_SPEC_VERSION 3 58 | #define VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_EXTENSION_NAME "VK_ANDROID_external_memory_android_hardware_buffer" 59 | typedef struct VkAndroidHardwareBufferUsageANDROID { 60 | VkStructureType sType; 61 | void* pNext; 62 | uint64_t androidHardwareBufferUsage; 63 | } VkAndroidHardwareBufferUsageANDROID; 64 | 65 | typedef struct VkAndroidHardwareBufferPropertiesANDROID { 66 | VkStructureType sType; 67 | void* pNext; 68 | VkDeviceSize allocationSize; 69 | uint32_t memoryTypeBits; 70 | } VkAndroidHardwareBufferPropertiesANDROID; 71 | 72 | typedef struct VkAndroidHardwareBufferFormatPropertiesANDROID { 73 | VkStructureType sType; 74 | void* pNext; 75 | VkFormat format; 76 | uint64_t externalFormat; 77 | VkFormatFeatureFlags formatFeatures; 78 | VkComponentMapping samplerYcbcrConversionComponents; 79 | VkSamplerYcbcrModelConversion suggestedYcbcrModel; 80 | VkSamplerYcbcrRange suggestedYcbcrRange; 81 | VkChromaLocation suggestedXChromaOffset; 82 | VkChromaLocation suggestedYChromaOffset; 83 | } VkAndroidHardwareBufferFormatPropertiesANDROID; 84 | 85 | typedef struct VkImportAndroidHardwareBufferInfoANDROID { 86 | VkStructureType sType; 87 | const void* pNext; 88 | struct AHardwareBuffer* buffer; 89 | } VkImportAndroidHardwareBufferInfoANDROID; 90 | 91 | typedef struct VkMemoryGetAndroidHardwareBufferInfoANDROID { 92 | VkStructureType sType; 93 | const void* pNext; 94 | VkDeviceMemory memory; 95 | } VkMemoryGetAndroidHardwareBufferInfoANDROID; 96 | 97 | typedef struct VkExternalFormatANDROID { 98 | VkStructureType sType; 99 | void* pNext; 100 | uint64_t externalFormat; 101 | } VkExternalFormatANDROID; 102 | 103 | typedef VkResult (VKAPI_PTR *PFN_vkGetAndroidHardwareBufferPropertiesANDROID)(VkDevice device, const struct AHardwareBuffer* buffer, VkAndroidHardwareBufferPropertiesANDROID* pProperties); 104 | typedef VkResult (VKAPI_PTR *PFN_vkGetMemoryAndroidHardwareBufferANDROID)(VkDevice device, const VkMemoryGetAndroidHardwareBufferInfoANDROID* pInfo, struct AHardwareBuffer** pBuffer); 105 | 106 | #ifndef VK_NO_PROTOTYPES 107 | VKAPI_ATTR VkResult VKAPI_CALL vkGetAndroidHardwareBufferPropertiesANDROID( 108 | VkDevice device, 109 | const struct AHardwareBuffer* buffer, 110 | VkAndroidHardwareBufferPropertiesANDROID* pProperties); 111 | 112 | VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryAndroidHardwareBufferANDROID( 113 | VkDevice device, 114 | const VkMemoryGetAndroidHardwareBufferInfoANDROID* pInfo, 115 | struct AHardwareBuffer** pBuffer); 116 | #endif 117 | 118 | #ifdef __cplusplus 119 | } 120 | #endif 121 | 122 | #endif 123 | -------------------------------------------------------------------------------- /vulkan/vulkan_fuchsia.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_FUCHSIA_H_ 2 | #define VULKAN_FUCHSIA_H_ 1 3 | 4 | /* 5 | ** Copyright (c) 2015-2020 The Khronos Group Inc. 6 | ** 7 | ** Licensed under the Apache License, Version 2.0 (the "License"); 8 | ** you may not use this file except in compliance with the License. 9 | ** You may obtain a copy of the License at 10 | ** 11 | ** http://www.apache.org/licenses/LICENSE-2.0 12 | ** 13 | ** Unless required by applicable law or agreed to in writing, software 14 | ** distributed under the License is distributed on an "AS IS" BASIS, 15 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | ** See the License for the specific language governing permissions and 17 | ** limitations under the License. 18 | */ 19 | 20 | /* 21 | ** This header is generated from the Khronos Vulkan XML API Registry. 22 | ** 23 | */ 24 | 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | 31 | 32 | #define VK_FUCHSIA_imagepipe_surface 1 33 | #define VK_FUCHSIA_IMAGEPIPE_SURFACE_SPEC_VERSION 1 34 | #define VK_FUCHSIA_IMAGEPIPE_SURFACE_EXTENSION_NAME "VK_FUCHSIA_imagepipe_surface" 35 | typedef VkFlags VkImagePipeSurfaceCreateFlagsFUCHSIA; 36 | typedef struct VkImagePipeSurfaceCreateInfoFUCHSIA { 37 | VkStructureType sType; 38 | const void* pNext; 39 | VkImagePipeSurfaceCreateFlagsFUCHSIA flags; 40 | zx_handle_t imagePipeHandle; 41 | } VkImagePipeSurfaceCreateInfoFUCHSIA; 42 | 43 | typedef VkResult (VKAPI_PTR *PFN_vkCreateImagePipeSurfaceFUCHSIA)(VkInstance instance, const VkImagePipeSurfaceCreateInfoFUCHSIA* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 44 | 45 | #ifndef VK_NO_PROTOTYPES 46 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateImagePipeSurfaceFUCHSIA( 47 | VkInstance instance, 48 | const VkImagePipeSurfaceCreateInfoFUCHSIA* pCreateInfo, 49 | const VkAllocationCallbacks* pAllocator, 50 | VkSurfaceKHR* pSurface); 51 | #endif 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /vulkan/vulkan_ggp.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_GGP_H_ 2 | #define VULKAN_GGP_H_ 1 3 | 4 | /* 5 | ** Copyright (c) 2015-2020 The Khronos Group Inc. 6 | ** 7 | ** Licensed under the Apache License, Version 2.0 (the "License"); 8 | ** you may not use this file except in compliance with the License. 9 | ** You may obtain a copy of the License at 10 | ** 11 | ** http://www.apache.org/licenses/LICENSE-2.0 12 | ** 13 | ** Unless required by applicable law or agreed to in writing, software 14 | ** distributed under the License is distributed on an "AS IS" BASIS, 15 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | ** See the License for the specific language governing permissions and 17 | ** limitations under the License. 18 | */ 19 | 20 | /* 21 | ** This header is generated from the Khronos Vulkan XML API Registry. 22 | ** 23 | */ 24 | 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | 31 | 32 | #define VK_GGP_stream_descriptor_surface 1 33 | #define VK_GGP_STREAM_DESCRIPTOR_SURFACE_SPEC_VERSION 1 34 | #define VK_GGP_STREAM_DESCRIPTOR_SURFACE_EXTENSION_NAME "VK_GGP_stream_descriptor_surface" 35 | typedef VkFlags VkStreamDescriptorSurfaceCreateFlagsGGP; 36 | typedef struct VkStreamDescriptorSurfaceCreateInfoGGP { 37 | VkStructureType sType; 38 | const void* pNext; 39 | VkStreamDescriptorSurfaceCreateFlagsGGP flags; 40 | GgpStreamDescriptor streamDescriptor; 41 | } VkStreamDescriptorSurfaceCreateInfoGGP; 42 | 43 | typedef VkResult (VKAPI_PTR *PFN_vkCreateStreamDescriptorSurfaceGGP)(VkInstance instance, const VkStreamDescriptorSurfaceCreateInfoGGP* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 44 | 45 | #ifndef VK_NO_PROTOTYPES 46 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateStreamDescriptorSurfaceGGP( 47 | VkInstance instance, 48 | const VkStreamDescriptorSurfaceCreateInfoGGP* pCreateInfo, 49 | const VkAllocationCallbacks* pAllocator, 50 | VkSurfaceKHR* pSurface); 51 | #endif 52 | 53 | 54 | #define VK_GGP_frame_token 1 55 | #define VK_GGP_FRAME_TOKEN_SPEC_VERSION 1 56 | #define VK_GGP_FRAME_TOKEN_EXTENSION_NAME "VK_GGP_frame_token" 57 | typedef struct VkPresentFrameTokenGGP { 58 | VkStructureType sType; 59 | const void* pNext; 60 | GgpFrameToken frameToken; 61 | } VkPresentFrameTokenGGP; 62 | 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /vulkan/vulkan_ios.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_IOS_H_ 2 | #define VULKAN_IOS_H_ 1 3 | 4 | /* 5 | ** Copyright (c) 2015-2020 The Khronos Group Inc. 6 | ** 7 | ** Licensed under the Apache License, Version 2.0 (the "License"); 8 | ** you may not use this file except in compliance with the License. 9 | ** You may obtain a copy of the License at 10 | ** 11 | ** http://www.apache.org/licenses/LICENSE-2.0 12 | ** 13 | ** Unless required by applicable law or agreed to in writing, software 14 | ** distributed under the License is distributed on an "AS IS" BASIS, 15 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | ** See the License for the specific language governing permissions and 17 | ** limitations under the License. 18 | */ 19 | 20 | /* 21 | ** This header is generated from the Khronos Vulkan XML API Registry. 22 | ** 23 | */ 24 | 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | 31 | 32 | #define VK_MVK_ios_surface 1 33 | #define VK_MVK_IOS_SURFACE_SPEC_VERSION 2 34 | #define VK_MVK_IOS_SURFACE_EXTENSION_NAME "VK_MVK_ios_surface" 35 | typedef VkFlags VkIOSSurfaceCreateFlagsMVK; 36 | typedef struct VkIOSSurfaceCreateInfoMVK { 37 | VkStructureType sType; 38 | const void* pNext; 39 | VkIOSSurfaceCreateFlagsMVK flags; 40 | const void* pView; 41 | } VkIOSSurfaceCreateInfoMVK; 42 | 43 | typedef VkResult (VKAPI_PTR *PFN_vkCreateIOSSurfaceMVK)(VkInstance instance, const VkIOSSurfaceCreateInfoMVK* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 44 | 45 | #ifndef VK_NO_PROTOTYPES 46 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateIOSSurfaceMVK( 47 | VkInstance instance, 48 | const VkIOSSurfaceCreateInfoMVK* pCreateInfo, 49 | const VkAllocationCallbacks* pAllocator, 50 | VkSurfaceKHR* pSurface); 51 | #endif 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /vulkan/vulkan_macos.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_MACOS_H_ 2 | #define VULKAN_MACOS_H_ 1 3 | 4 | /* 5 | ** Copyright (c) 2015-2020 The Khronos Group Inc. 6 | ** 7 | ** Licensed under the Apache License, Version 2.0 (the "License"); 8 | ** you may not use this file except in compliance with the License. 9 | ** You may obtain a copy of the License at 10 | ** 11 | ** http://www.apache.org/licenses/LICENSE-2.0 12 | ** 13 | ** Unless required by applicable law or agreed to in writing, software 14 | ** distributed under the License is distributed on an "AS IS" BASIS, 15 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | ** See the License for the specific language governing permissions and 17 | ** limitations under the License. 18 | */ 19 | 20 | /* 21 | ** This header is generated from the Khronos Vulkan XML API Registry. 22 | ** 23 | */ 24 | 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | 31 | 32 | #define VK_MVK_macos_surface 1 33 | #define VK_MVK_MACOS_SURFACE_SPEC_VERSION 2 34 | #define VK_MVK_MACOS_SURFACE_EXTENSION_NAME "VK_MVK_macos_surface" 35 | typedef VkFlags VkMacOSSurfaceCreateFlagsMVK; 36 | typedef struct VkMacOSSurfaceCreateInfoMVK { 37 | VkStructureType sType; 38 | const void* pNext; 39 | VkMacOSSurfaceCreateFlagsMVK flags; 40 | const void* pView; 41 | } VkMacOSSurfaceCreateInfoMVK; 42 | 43 | typedef VkResult (VKAPI_PTR *PFN_vkCreateMacOSSurfaceMVK)(VkInstance instance, const VkMacOSSurfaceCreateInfoMVK* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 44 | 45 | #ifndef VK_NO_PROTOTYPES 46 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateMacOSSurfaceMVK( 47 | VkInstance instance, 48 | const VkMacOSSurfaceCreateInfoMVK* pCreateInfo, 49 | const VkAllocationCallbacks* pAllocator, 50 | VkSurfaceKHR* pSurface); 51 | #endif 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /vulkan/vulkan_metal.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_METAL_H_ 2 | #define VULKAN_METAL_H_ 1 3 | 4 | /* 5 | ** Copyright (c) 2015-2020 The Khronos Group Inc. 6 | ** 7 | ** Licensed under the Apache License, Version 2.0 (the "License"); 8 | ** you may not use this file except in compliance with the License. 9 | ** You may obtain a copy of the License at 10 | ** 11 | ** http://www.apache.org/licenses/LICENSE-2.0 12 | ** 13 | ** Unless required by applicable law or agreed to in writing, software 14 | ** distributed under the License is distributed on an "AS IS" BASIS, 15 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | ** See the License for the specific language governing permissions and 17 | ** limitations under the License. 18 | */ 19 | 20 | /* 21 | ** This header is generated from the Khronos Vulkan XML API Registry. 22 | ** 23 | */ 24 | 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | 31 | 32 | #define VK_EXT_metal_surface 1 33 | 34 | #ifdef __OBJC__ 35 | @class CAMetalLayer; 36 | #else 37 | typedef void CAMetalLayer; 38 | #endif 39 | 40 | #define VK_EXT_METAL_SURFACE_SPEC_VERSION 1 41 | #define VK_EXT_METAL_SURFACE_EXTENSION_NAME "VK_EXT_metal_surface" 42 | typedef VkFlags VkMetalSurfaceCreateFlagsEXT; 43 | typedef struct VkMetalSurfaceCreateInfoEXT { 44 | VkStructureType sType; 45 | const void* pNext; 46 | VkMetalSurfaceCreateFlagsEXT flags; 47 | const CAMetalLayer* pLayer; 48 | } VkMetalSurfaceCreateInfoEXT; 49 | 50 | typedef VkResult (VKAPI_PTR *PFN_vkCreateMetalSurfaceEXT)(VkInstance instance, const VkMetalSurfaceCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 51 | 52 | #ifndef VK_NO_PROTOTYPES 53 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateMetalSurfaceEXT( 54 | VkInstance instance, 55 | const VkMetalSurfaceCreateInfoEXT* pCreateInfo, 56 | const VkAllocationCallbacks* pAllocator, 57 | VkSurfaceKHR* pSurface); 58 | #endif 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /vulkan/vulkan_vi.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_VI_H_ 2 | #define VULKAN_VI_H_ 1 3 | 4 | /* 5 | ** Copyright (c) 2015-2020 The Khronos Group Inc. 6 | ** 7 | ** Licensed under the Apache License, Version 2.0 (the "License"); 8 | ** you may not use this file except in compliance with the License. 9 | ** You may obtain a copy of the License at 10 | ** 11 | ** http://www.apache.org/licenses/LICENSE-2.0 12 | ** 13 | ** Unless required by applicable law or agreed to in writing, software 14 | ** distributed under the License is distributed on an "AS IS" BASIS, 15 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | ** See the License for the specific language governing permissions and 17 | ** limitations under the License. 18 | */ 19 | 20 | /* 21 | ** This header is generated from the Khronos Vulkan XML API Registry. 22 | ** 23 | */ 24 | 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | 31 | 32 | #define VK_NN_vi_surface 1 33 | #define VK_NN_VI_SURFACE_SPEC_VERSION 1 34 | #define VK_NN_VI_SURFACE_EXTENSION_NAME "VK_NN_vi_surface" 35 | typedef VkFlags VkViSurfaceCreateFlagsNN; 36 | typedef struct VkViSurfaceCreateInfoNN { 37 | VkStructureType sType; 38 | const void* pNext; 39 | VkViSurfaceCreateFlagsNN flags; 40 | void* window; 41 | } VkViSurfaceCreateInfoNN; 42 | 43 | typedef VkResult (VKAPI_PTR *PFN_vkCreateViSurfaceNN)(VkInstance instance, const VkViSurfaceCreateInfoNN* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 44 | 45 | #ifndef VK_NO_PROTOTYPES 46 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateViSurfaceNN( 47 | VkInstance instance, 48 | const VkViSurfaceCreateInfoNN* pCreateInfo, 49 | const VkAllocationCallbacks* pAllocator, 50 | VkSurfaceKHR* pSurface); 51 | #endif 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /vulkan/vulkan_wayland.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_WAYLAND_H_ 2 | #define VULKAN_WAYLAND_H_ 1 3 | 4 | /* 5 | ** Copyright (c) 2015-2020 The Khronos Group Inc. 6 | ** 7 | ** Licensed under the Apache License, Version 2.0 (the "License"); 8 | ** you may not use this file except in compliance with the License. 9 | ** You may obtain a copy of the License at 10 | ** 11 | ** http://www.apache.org/licenses/LICENSE-2.0 12 | ** 13 | ** Unless required by applicable law or agreed to in writing, software 14 | ** distributed under the License is distributed on an "AS IS" BASIS, 15 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | ** See the License for the specific language governing permissions and 17 | ** limitations under the License. 18 | */ 19 | 20 | /* 21 | ** This header is generated from the Khronos Vulkan XML API Registry. 22 | ** 23 | */ 24 | 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | 31 | 32 | #define VK_KHR_wayland_surface 1 33 | #define VK_KHR_WAYLAND_SURFACE_SPEC_VERSION 6 34 | #define VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME "VK_KHR_wayland_surface" 35 | typedef VkFlags VkWaylandSurfaceCreateFlagsKHR; 36 | typedef struct VkWaylandSurfaceCreateInfoKHR { 37 | VkStructureType sType; 38 | const void* pNext; 39 | VkWaylandSurfaceCreateFlagsKHR flags; 40 | struct wl_display* display; 41 | struct wl_surface* surface; 42 | } VkWaylandSurfaceCreateInfoKHR; 43 | 44 | typedef VkResult (VKAPI_PTR *PFN_vkCreateWaylandSurfaceKHR)(VkInstance instance, const VkWaylandSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 45 | typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, struct wl_display* display); 46 | 47 | #ifndef VK_NO_PROTOTYPES 48 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateWaylandSurfaceKHR( 49 | VkInstance instance, 50 | const VkWaylandSurfaceCreateInfoKHR* pCreateInfo, 51 | const VkAllocationCallbacks* pAllocator, 52 | VkSurfaceKHR* pSurface); 53 | 54 | VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceWaylandPresentationSupportKHR( 55 | VkPhysicalDevice physicalDevice, 56 | uint32_t queueFamilyIndex, 57 | struct wl_display* display); 58 | #endif 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /vulkan/vulkan_win32.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_WIN32_H_ 2 | #define VULKAN_WIN32_H_ 1 3 | 4 | /* 5 | ** Copyright (c) 2015-2020 The Khronos Group Inc. 6 | ** 7 | ** Licensed under the Apache License, Version 2.0 (the "License"); 8 | ** you may not use this file except in compliance with the License. 9 | ** You may obtain a copy of the License at 10 | ** 11 | ** http://www.apache.org/licenses/LICENSE-2.0 12 | ** 13 | ** Unless required by applicable law or agreed to in writing, software 14 | ** distributed under the License is distributed on an "AS IS" BASIS, 15 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | ** See the License for the specific language governing permissions and 17 | ** limitations under the License. 18 | */ 19 | 20 | /* 21 | ** This header is generated from the Khronos Vulkan XML API Registry. 22 | ** 23 | */ 24 | 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | 31 | 32 | #define VK_KHR_win32_surface 1 33 | #define VK_KHR_WIN32_SURFACE_SPEC_VERSION 6 34 | #define VK_KHR_WIN32_SURFACE_EXTENSION_NAME "VK_KHR_win32_surface" 35 | typedef VkFlags VkWin32SurfaceCreateFlagsKHR; 36 | typedef struct VkWin32SurfaceCreateInfoKHR { 37 | VkStructureType sType; 38 | const void* pNext; 39 | VkWin32SurfaceCreateFlagsKHR flags; 40 | HINSTANCE hinstance; 41 | HWND hwnd; 42 | } VkWin32SurfaceCreateInfoKHR; 43 | 44 | typedef VkResult (VKAPI_PTR *PFN_vkCreateWin32SurfaceKHR)(VkInstance instance, const VkWin32SurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 45 | typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex); 46 | 47 | #ifndef VK_NO_PROTOTYPES 48 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateWin32SurfaceKHR( 49 | VkInstance instance, 50 | const VkWin32SurfaceCreateInfoKHR* pCreateInfo, 51 | const VkAllocationCallbacks* pAllocator, 52 | VkSurfaceKHR* pSurface); 53 | 54 | VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceWin32PresentationSupportKHR( 55 | VkPhysicalDevice physicalDevice, 56 | uint32_t queueFamilyIndex); 57 | #endif 58 | 59 | 60 | #define VK_KHR_external_memory_win32 1 61 | #define VK_KHR_EXTERNAL_MEMORY_WIN32_SPEC_VERSION 1 62 | #define VK_KHR_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME "VK_KHR_external_memory_win32" 63 | typedef struct VkImportMemoryWin32HandleInfoKHR { 64 | VkStructureType sType; 65 | const void* pNext; 66 | VkExternalMemoryHandleTypeFlagBits handleType; 67 | HANDLE handle; 68 | LPCWSTR name; 69 | } VkImportMemoryWin32HandleInfoKHR; 70 | 71 | typedef struct VkExportMemoryWin32HandleInfoKHR { 72 | VkStructureType sType; 73 | const void* pNext; 74 | const SECURITY_ATTRIBUTES* pAttributes; 75 | DWORD dwAccess; 76 | LPCWSTR name; 77 | } VkExportMemoryWin32HandleInfoKHR; 78 | 79 | typedef struct VkMemoryWin32HandlePropertiesKHR { 80 | VkStructureType sType; 81 | void* pNext; 82 | uint32_t memoryTypeBits; 83 | } VkMemoryWin32HandlePropertiesKHR; 84 | 85 | typedef struct VkMemoryGetWin32HandleInfoKHR { 86 | VkStructureType sType; 87 | const void* pNext; 88 | VkDeviceMemory memory; 89 | VkExternalMemoryHandleTypeFlagBits handleType; 90 | } VkMemoryGetWin32HandleInfoKHR; 91 | 92 | typedef VkResult (VKAPI_PTR *PFN_vkGetMemoryWin32HandleKHR)(VkDevice device, const VkMemoryGetWin32HandleInfoKHR* pGetWin32HandleInfo, HANDLE* pHandle); 93 | typedef VkResult (VKAPI_PTR *PFN_vkGetMemoryWin32HandlePropertiesKHR)(VkDevice device, VkExternalMemoryHandleTypeFlagBits handleType, HANDLE handle, VkMemoryWin32HandlePropertiesKHR* pMemoryWin32HandleProperties); 94 | 95 | #ifndef VK_NO_PROTOTYPES 96 | VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryWin32HandleKHR( 97 | VkDevice device, 98 | const VkMemoryGetWin32HandleInfoKHR* pGetWin32HandleInfo, 99 | HANDLE* pHandle); 100 | 101 | VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryWin32HandlePropertiesKHR( 102 | VkDevice device, 103 | VkExternalMemoryHandleTypeFlagBits handleType, 104 | HANDLE handle, 105 | VkMemoryWin32HandlePropertiesKHR* pMemoryWin32HandleProperties); 106 | #endif 107 | 108 | 109 | #define VK_KHR_win32_keyed_mutex 1 110 | #define VK_KHR_WIN32_KEYED_MUTEX_SPEC_VERSION 1 111 | #define VK_KHR_WIN32_KEYED_MUTEX_EXTENSION_NAME "VK_KHR_win32_keyed_mutex" 112 | typedef struct VkWin32KeyedMutexAcquireReleaseInfoKHR { 113 | VkStructureType sType; 114 | const void* pNext; 115 | uint32_t acquireCount; 116 | const VkDeviceMemory* pAcquireSyncs; 117 | const uint64_t* pAcquireKeys; 118 | const uint32_t* pAcquireTimeouts; 119 | uint32_t releaseCount; 120 | const VkDeviceMemory* pReleaseSyncs; 121 | const uint64_t* pReleaseKeys; 122 | } VkWin32KeyedMutexAcquireReleaseInfoKHR; 123 | 124 | 125 | 126 | #define VK_KHR_external_semaphore_win32 1 127 | #define VK_KHR_EXTERNAL_SEMAPHORE_WIN32_SPEC_VERSION 1 128 | #define VK_KHR_EXTERNAL_SEMAPHORE_WIN32_EXTENSION_NAME "VK_KHR_external_semaphore_win32" 129 | typedef struct VkImportSemaphoreWin32HandleInfoKHR { 130 | VkStructureType sType; 131 | const void* pNext; 132 | VkSemaphore semaphore; 133 | VkSemaphoreImportFlags flags; 134 | VkExternalSemaphoreHandleTypeFlagBits handleType; 135 | HANDLE handle; 136 | LPCWSTR name; 137 | } VkImportSemaphoreWin32HandleInfoKHR; 138 | 139 | typedef struct VkExportSemaphoreWin32HandleInfoKHR { 140 | VkStructureType sType; 141 | const void* pNext; 142 | const SECURITY_ATTRIBUTES* pAttributes; 143 | DWORD dwAccess; 144 | LPCWSTR name; 145 | } VkExportSemaphoreWin32HandleInfoKHR; 146 | 147 | typedef struct VkD3D12FenceSubmitInfoKHR { 148 | VkStructureType sType; 149 | const void* pNext; 150 | uint32_t waitSemaphoreValuesCount; 151 | const uint64_t* pWaitSemaphoreValues; 152 | uint32_t signalSemaphoreValuesCount; 153 | const uint64_t* pSignalSemaphoreValues; 154 | } VkD3D12FenceSubmitInfoKHR; 155 | 156 | typedef struct VkSemaphoreGetWin32HandleInfoKHR { 157 | VkStructureType sType; 158 | const void* pNext; 159 | VkSemaphore semaphore; 160 | VkExternalSemaphoreHandleTypeFlagBits handleType; 161 | } VkSemaphoreGetWin32HandleInfoKHR; 162 | 163 | typedef VkResult (VKAPI_PTR *PFN_vkImportSemaphoreWin32HandleKHR)(VkDevice device, const VkImportSemaphoreWin32HandleInfoKHR* pImportSemaphoreWin32HandleInfo); 164 | typedef VkResult (VKAPI_PTR *PFN_vkGetSemaphoreWin32HandleKHR)(VkDevice device, const VkSemaphoreGetWin32HandleInfoKHR* pGetWin32HandleInfo, HANDLE* pHandle); 165 | 166 | #ifndef VK_NO_PROTOTYPES 167 | VKAPI_ATTR VkResult VKAPI_CALL vkImportSemaphoreWin32HandleKHR( 168 | VkDevice device, 169 | const VkImportSemaphoreWin32HandleInfoKHR* pImportSemaphoreWin32HandleInfo); 170 | 171 | VKAPI_ATTR VkResult VKAPI_CALL vkGetSemaphoreWin32HandleKHR( 172 | VkDevice device, 173 | const VkSemaphoreGetWin32HandleInfoKHR* pGetWin32HandleInfo, 174 | HANDLE* pHandle); 175 | #endif 176 | 177 | 178 | #define VK_KHR_external_fence_win32 1 179 | #define VK_KHR_EXTERNAL_FENCE_WIN32_SPEC_VERSION 1 180 | #define VK_KHR_EXTERNAL_FENCE_WIN32_EXTENSION_NAME "VK_KHR_external_fence_win32" 181 | typedef struct VkImportFenceWin32HandleInfoKHR { 182 | VkStructureType sType; 183 | const void* pNext; 184 | VkFence fence; 185 | VkFenceImportFlags flags; 186 | VkExternalFenceHandleTypeFlagBits handleType; 187 | HANDLE handle; 188 | LPCWSTR name; 189 | } VkImportFenceWin32HandleInfoKHR; 190 | 191 | typedef struct VkExportFenceWin32HandleInfoKHR { 192 | VkStructureType sType; 193 | const void* pNext; 194 | const SECURITY_ATTRIBUTES* pAttributes; 195 | DWORD dwAccess; 196 | LPCWSTR name; 197 | } VkExportFenceWin32HandleInfoKHR; 198 | 199 | typedef struct VkFenceGetWin32HandleInfoKHR { 200 | VkStructureType sType; 201 | const void* pNext; 202 | VkFence fence; 203 | VkExternalFenceHandleTypeFlagBits handleType; 204 | } VkFenceGetWin32HandleInfoKHR; 205 | 206 | typedef VkResult (VKAPI_PTR *PFN_vkImportFenceWin32HandleKHR)(VkDevice device, const VkImportFenceWin32HandleInfoKHR* pImportFenceWin32HandleInfo); 207 | typedef VkResult (VKAPI_PTR *PFN_vkGetFenceWin32HandleKHR)(VkDevice device, const VkFenceGetWin32HandleInfoKHR* pGetWin32HandleInfo, HANDLE* pHandle); 208 | 209 | #ifndef VK_NO_PROTOTYPES 210 | VKAPI_ATTR VkResult VKAPI_CALL vkImportFenceWin32HandleKHR( 211 | VkDevice device, 212 | const VkImportFenceWin32HandleInfoKHR* pImportFenceWin32HandleInfo); 213 | 214 | VKAPI_ATTR VkResult VKAPI_CALL vkGetFenceWin32HandleKHR( 215 | VkDevice device, 216 | const VkFenceGetWin32HandleInfoKHR* pGetWin32HandleInfo, 217 | HANDLE* pHandle); 218 | #endif 219 | 220 | 221 | #define VK_NV_external_memory_win32 1 222 | #define VK_NV_EXTERNAL_MEMORY_WIN32_SPEC_VERSION 1 223 | #define VK_NV_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME "VK_NV_external_memory_win32" 224 | typedef struct VkImportMemoryWin32HandleInfoNV { 225 | VkStructureType sType; 226 | const void* pNext; 227 | VkExternalMemoryHandleTypeFlagsNV handleType; 228 | HANDLE handle; 229 | } VkImportMemoryWin32HandleInfoNV; 230 | 231 | typedef struct VkExportMemoryWin32HandleInfoNV { 232 | VkStructureType sType; 233 | const void* pNext; 234 | const SECURITY_ATTRIBUTES* pAttributes; 235 | DWORD dwAccess; 236 | } VkExportMemoryWin32HandleInfoNV; 237 | 238 | typedef VkResult (VKAPI_PTR *PFN_vkGetMemoryWin32HandleNV)(VkDevice device, VkDeviceMemory memory, VkExternalMemoryHandleTypeFlagsNV handleType, HANDLE* pHandle); 239 | 240 | #ifndef VK_NO_PROTOTYPES 241 | VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryWin32HandleNV( 242 | VkDevice device, 243 | VkDeviceMemory memory, 244 | VkExternalMemoryHandleTypeFlagsNV handleType, 245 | HANDLE* pHandle); 246 | #endif 247 | 248 | 249 | #define VK_NV_win32_keyed_mutex 1 250 | #define VK_NV_WIN32_KEYED_MUTEX_SPEC_VERSION 2 251 | #define VK_NV_WIN32_KEYED_MUTEX_EXTENSION_NAME "VK_NV_win32_keyed_mutex" 252 | typedef struct VkWin32KeyedMutexAcquireReleaseInfoNV { 253 | VkStructureType sType; 254 | const void* pNext; 255 | uint32_t acquireCount; 256 | const VkDeviceMemory* pAcquireSyncs; 257 | const uint64_t* pAcquireKeys; 258 | const uint32_t* pAcquireTimeoutMilliseconds; 259 | uint32_t releaseCount; 260 | const VkDeviceMemory* pReleaseSyncs; 261 | const uint64_t* pReleaseKeys; 262 | } VkWin32KeyedMutexAcquireReleaseInfoNV; 263 | 264 | 265 | 266 | #define VK_EXT_full_screen_exclusive 1 267 | #define VK_EXT_FULL_SCREEN_EXCLUSIVE_SPEC_VERSION 4 268 | #define VK_EXT_FULL_SCREEN_EXCLUSIVE_EXTENSION_NAME "VK_EXT_full_screen_exclusive" 269 | 270 | typedef enum VkFullScreenExclusiveEXT { 271 | VK_FULL_SCREEN_EXCLUSIVE_DEFAULT_EXT = 0, 272 | VK_FULL_SCREEN_EXCLUSIVE_ALLOWED_EXT = 1, 273 | VK_FULL_SCREEN_EXCLUSIVE_DISALLOWED_EXT = 2, 274 | VK_FULL_SCREEN_EXCLUSIVE_APPLICATION_CONTROLLED_EXT = 3, 275 | VK_FULL_SCREEN_EXCLUSIVE_BEGIN_RANGE_EXT = VK_FULL_SCREEN_EXCLUSIVE_DEFAULT_EXT, 276 | VK_FULL_SCREEN_EXCLUSIVE_END_RANGE_EXT = VK_FULL_SCREEN_EXCLUSIVE_APPLICATION_CONTROLLED_EXT, 277 | VK_FULL_SCREEN_EXCLUSIVE_RANGE_SIZE_EXT = (VK_FULL_SCREEN_EXCLUSIVE_APPLICATION_CONTROLLED_EXT - VK_FULL_SCREEN_EXCLUSIVE_DEFAULT_EXT + 1), 278 | VK_FULL_SCREEN_EXCLUSIVE_MAX_ENUM_EXT = 0x7FFFFFFF 279 | } VkFullScreenExclusiveEXT; 280 | typedef struct VkSurfaceFullScreenExclusiveInfoEXT { 281 | VkStructureType sType; 282 | void* pNext; 283 | VkFullScreenExclusiveEXT fullScreenExclusive; 284 | } VkSurfaceFullScreenExclusiveInfoEXT; 285 | 286 | typedef struct VkSurfaceCapabilitiesFullScreenExclusiveEXT { 287 | VkStructureType sType; 288 | void* pNext; 289 | VkBool32 fullScreenExclusiveSupported; 290 | } VkSurfaceCapabilitiesFullScreenExclusiveEXT; 291 | 292 | typedef struct VkSurfaceFullScreenExclusiveWin32InfoEXT { 293 | VkStructureType sType; 294 | const void* pNext; 295 | HMONITOR hmonitor; 296 | } VkSurfaceFullScreenExclusiveWin32InfoEXT; 297 | 298 | typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceSurfacePresentModes2EXT)(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo, uint32_t* pPresentModeCount, VkPresentModeKHR* pPresentModes); 299 | typedef VkResult (VKAPI_PTR *PFN_vkAcquireFullScreenExclusiveModeEXT)(VkDevice device, VkSwapchainKHR swapchain); 300 | typedef VkResult (VKAPI_PTR *PFN_vkReleaseFullScreenExclusiveModeEXT)(VkDevice device, VkSwapchainKHR swapchain); 301 | typedef VkResult (VKAPI_PTR *PFN_vkGetDeviceGroupSurfacePresentModes2EXT)(VkDevice device, const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo, VkDeviceGroupPresentModeFlagsKHR* pModes); 302 | 303 | #ifndef VK_NO_PROTOTYPES 304 | VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfacePresentModes2EXT( 305 | VkPhysicalDevice physicalDevice, 306 | const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo, 307 | uint32_t* pPresentModeCount, 308 | VkPresentModeKHR* pPresentModes); 309 | 310 | VKAPI_ATTR VkResult VKAPI_CALL vkAcquireFullScreenExclusiveModeEXT( 311 | VkDevice device, 312 | VkSwapchainKHR swapchain); 313 | 314 | VKAPI_ATTR VkResult VKAPI_CALL vkReleaseFullScreenExclusiveModeEXT( 315 | VkDevice device, 316 | VkSwapchainKHR swapchain); 317 | 318 | VKAPI_ATTR VkResult VKAPI_CALL vkGetDeviceGroupSurfacePresentModes2EXT( 319 | VkDevice device, 320 | const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo, 321 | VkDeviceGroupPresentModeFlagsKHR* pModes); 322 | #endif 323 | 324 | #ifdef __cplusplus 325 | } 326 | #endif 327 | 328 | #endif 329 | -------------------------------------------------------------------------------- /vulkan/vulkan_xcb.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_XCB_H_ 2 | #define VULKAN_XCB_H_ 1 3 | 4 | /* 5 | ** Copyright (c) 2015-2020 The Khronos Group Inc. 6 | ** 7 | ** Licensed under the Apache License, Version 2.0 (the "License"); 8 | ** you may not use this file except in compliance with the License. 9 | ** You may obtain a copy of the License at 10 | ** 11 | ** http://www.apache.org/licenses/LICENSE-2.0 12 | ** 13 | ** Unless required by applicable law or agreed to in writing, software 14 | ** distributed under the License is distributed on an "AS IS" BASIS, 15 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | ** See the License for the specific language governing permissions and 17 | ** limitations under the License. 18 | */ 19 | 20 | /* 21 | ** This header is generated from the Khronos Vulkan XML API Registry. 22 | ** 23 | */ 24 | 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | 31 | 32 | #define VK_KHR_xcb_surface 1 33 | #define VK_KHR_XCB_SURFACE_SPEC_VERSION 6 34 | #define VK_KHR_XCB_SURFACE_EXTENSION_NAME "VK_KHR_xcb_surface" 35 | typedef VkFlags VkXcbSurfaceCreateFlagsKHR; 36 | typedef struct VkXcbSurfaceCreateInfoKHR { 37 | VkStructureType sType; 38 | const void* pNext; 39 | VkXcbSurfaceCreateFlagsKHR flags; 40 | xcb_connection_t* connection; 41 | xcb_window_t window; 42 | } VkXcbSurfaceCreateInfoKHR; 43 | 44 | typedef VkResult (VKAPI_PTR *PFN_vkCreateXcbSurfaceKHR)(VkInstance instance, const VkXcbSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 45 | typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, xcb_connection_t* connection, xcb_visualid_t visual_id); 46 | 47 | #ifndef VK_NO_PROTOTYPES 48 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateXcbSurfaceKHR( 49 | VkInstance instance, 50 | const VkXcbSurfaceCreateInfoKHR* pCreateInfo, 51 | const VkAllocationCallbacks* pAllocator, 52 | VkSurfaceKHR* pSurface); 53 | 54 | VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXcbPresentationSupportKHR( 55 | VkPhysicalDevice physicalDevice, 56 | uint32_t queueFamilyIndex, 57 | xcb_connection_t* connection, 58 | xcb_visualid_t visual_id); 59 | #endif 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /vulkan/vulkan_xlib.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_XLIB_H_ 2 | #define VULKAN_XLIB_H_ 1 3 | 4 | /* 5 | ** Copyright (c) 2015-2020 The Khronos Group Inc. 6 | ** 7 | ** Licensed under the Apache License, Version 2.0 (the "License"); 8 | ** you may not use this file except in compliance with the License. 9 | ** You may obtain a copy of the License at 10 | ** 11 | ** http://www.apache.org/licenses/LICENSE-2.0 12 | ** 13 | ** Unless required by applicable law or agreed to in writing, software 14 | ** distributed under the License is distributed on an "AS IS" BASIS, 15 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | ** See the License for the specific language governing permissions and 17 | ** limitations under the License. 18 | */ 19 | 20 | /* 21 | ** This header is generated from the Khronos Vulkan XML API Registry. 22 | ** 23 | */ 24 | 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | 31 | 32 | #define VK_KHR_xlib_surface 1 33 | #define VK_KHR_XLIB_SURFACE_SPEC_VERSION 6 34 | #define VK_KHR_XLIB_SURFACE_EXTENSION_NAME "VK_KHR_xlib_surface" 35 | typedef VkFlags VkXlibSurfaceCreateFlagsKHR; 36 | typedef struct VkXlibSurfaceCreateInfoKHR { 37 | VkStructureType sType; 38 | const void* pNext; 39 | VkXlibSurfaceCreateFlagsKHR flags; 40 | Display* dpy; 41 | Window window; 42 | } VkXlibSurfaceCreateInfoKHR; 43 | 44 | typedef VkResult (VKAPI_PTR *PFN_vkCreateXlibSurfaceKHR)(VkInstance instance, const VkXlibSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 45 | typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, Display* dpy, VisualID visualID); 46 | 47 | #ifndef VK_NO_PROTOTYPES 48 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateXlibSurfaceKHR( 49 | VkInstance instance, 50 | const VkXlibSurfaceCreateInfoKHR* pCreateInfo, 51 | const VkAllocationCallbacks* pAllocator, 52 | VkSurfaceKHR* pSurface); 53 | 54 | VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXlibPresentationSupportKHR( 55 | VkPhysicalDevice physicalDevice, 56 | uint32_t queueFamilyIndex, 57 | Display* dpy, 58 | VisualID visualID); 59 | #endif 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /vulkan/vulkan_xlib_xrandr.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_XLIB_XRANDR_H_ 2 | #define VULKAN_XLIB_XRANDR_H_ 1 3 | 4 | /* 5 | ** Copyright (c) 2015-2020 The Khronos Group Inc. 6 | ** 7 | ** Licensed under the Apache License, Version 2.0 (the "License"); 8 | ** you may not use this file except in compliance with the License. 9 | ** You may obtain a copy of the License at 10 | ** 11 | ** http://www.apache.org/licenses/LICENSE-2.0 12 | ** 13 | ** Unless required by applicable law or agreed to in writing, software 14 | ** distributed under the License is distributed on an "AS IS" BASIS, 15 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | ** See the License for the specific language governing permissions and 17 | ** limitations under the License. 18 | */ 19 | 20 | /* 21 | ** This header is generated from the Khronos Vulkan XML API Registry. 22 | ** 23 | */ 24 | 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | 31 | 32 | #define VK_EXT_acquire_xlib_display 1 33 | #define VK_EXT_ACQUIRE_XLIB_DISPLAY_SPEC_VERSION 1 34 | #define VK_EXT_ACQUIRE_XLIB_DISPLAY_EXTENSION_NAME "VK_EXT_acquire_xlib_display" 35 | typedef VkResult (VKAPI_PTR *PFN_vkAcquireXlibDisplayEXT)(VkPhysicalDevice physicalDevice, Display* dpy, VkDisplayKHR display); 36 | typedef VkResult (VKAPI_PTR *PFN_vkGetRandROutputDisplayEXT)(VkPhysicalDevice physicalDevice, Display* dpy, RROutput rrOutput, VkDisplayKHR* pDisplay); 37 | 38 | #ifndef VK_NO_PROTOTYPES 39 | VKAPI_ATTR VkResult VKAPI_CALL vkAcquireXlibDisplayEXT( 40 | VkPhysicalDevice physicalDevice, 41 | Display* dpy, 42 | VkDisplayKHR display); 43 | 44 | VKAPI_ATTR VkResult VKAPI_CALL vkGetRandROutputDisplayEXT( 45 | VkPhysicalDevice physicalDevice, 46 | Display* dpy, 47 | RROutput rrOutput, 48 | VkDisplayKHR* pDisplay); 49 | #endif 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif 56 | --------------------------------------------------------------------------------