Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 34 additions & 29 deletions gpu/impl_vk.odin
Original file line number Diff line number Diff line change
Expand Up @@ -725,38 +725,43 @@ _init :: proc(validation := true, loc := #caller_location) -> bool
// VMA allocator
vma_vulkan_procs := vma.create_vulkan_functions()
// VMA validates KHR aliases; some loaders expose only core names on 1.1+.
if vma_vulkan_procs.get_buffer_memory_requirements2_khr == nil && vk.GetDeviceProcAddr != nil {
if vma_vulkan_procs.GetBufferMemoryRequirements2KHR == nil && vk.GetDeviceProcAddr != nil {
addr := vk.GetDeviceProcAddr(ctx.device, "vkGetBufferMemoryRequirements2")
if addr == nil do addr = vk.GetDeviceProcAddr(ctx.device, "vkGetBufferMemoryRequirements2KHR")
vma_vulkan_procs.get_buffer_memory_requirements2_khr = auto_cast addr
vma_vulkan_procs.GetBufferMemoryRequirements2KHR = auto_cast addr
}
if vma_vulkan_procs.get_image_memory_requirements2_khr == nil && vk.GetDeviceProcAddr != nil {
if vma_vulkan_procs.GetImageMemoryRequirements2KHR == nil && vk.GetDeviceProcAddr != nil {
addr := vk.GetDeviceProcAddr(ctx.device, "vkGetImageMemoryRequirements2")
if addr == nil do addr = vk.GetDeviceProcAddr(ctx.device, "vkGetImageMemoryRequirements2KHR")
vma_vulkan_procs.get_image_memory_requirements2_khr = auto_cast addr
vma_vulkan_procs.GetImageMemoryRequirements2KHR = auto_cast addr
}
if vma_vulkan_procs.bind_buffer_memory2_khr == nil && vk.GetDeviceProcAddr != nil {
if vma_vulkan_procs.BindBufferMemory2KHR == nil && vk.GetDeviceProcAddr != nil {
addr := vk.GetDeviceProcAddr(ctx.device, "vkBindBufferMemory2")
if addr == nil do addr = vk.GetDeviceProcAddr(ctx.device, "vkBindBufferMemory2KHR")
vma_vulkan_procs.bind_buffer_memory2_khr = auto_cast addr
vma_vulkan_procs.BindBufferMemory2KHR = auto_cast addr
}
if vma_vulkan_procs.bind_image_memory2_khr == nil && vk.GetDeviceProcAddr != nil {
if vma_vulkan_procs.BindImageMemory2KHR == nil && vk.GetDeviceProcAddr != nil {
addr := vk.GetDeviceProcAddr(ctx.device, "vkBindImageMemory2")
if addr == nil do addr = vk.GetDeviceProcAddr(ctx.device, "vkBindImageMemory2KHR")
vma_vulkan_procs.bind_image_memory2_khr = auto_cast addr
vma_vulkan_procs.BindImageMemory2KHR = auto_cast addr
}
if vma_vulkan_procs.get_physical_device_memory_properties2_khr == nil && vk.GetInstanceProcAddr != nil {
if vma_vulkan_procs.GetPhysicalDeviceMemoryProperties2KHR == nil && vk.GetInstanceProcAddr != nil {
addr := vk.GetInstanceProcAddr(ctx.instance, "vkGetPhysicalDeviceMemoryProperties2")
if addr == nil do addr = vk.GetInstanceProcAddr(ctx.instance, "vkGetPhysicalDeviceMemoryProperties2KHR")
vma_vulkan_procs.get_physical_device_memory_properties2_khr = auto_cast addr
vma_vulkan_procs.GetPhysicalDeviceMemoryProperties2KHR = auto_cast addr
}
ok_vma := vma.create_allocator({
flags = { .Buffer_Device_Address },
if vma_vulkan_procs.GetPhysicalDeviceProperties2KHR == nil && vk.GetInstanceProcAddr != nil {
addr := vk.GetInstanceProcAddr(ctx.instance, "vkGetPhysicalDeviceProperties2")
if addr == nil do addr = vk.GetInstanceProcAddr(ctx.instance, "vkGetPhysicalDeviceProperties2KHR")
vma_vulkan_procs.GetPhysicalDeviceProperties2KHR = auto_cast addr
}
ok_vma := vma.CreateAllocator({
flags = { .BUFFER_DEVICE_ADDRESS },
instance = ctx.instance,
vulkan_api_version = vk.API_VERSION_1_3,
physical_device = ctx.phys_device,
vulkanApiVersion = vk.API_VERSION_1_3,
physicalDevice = ctx.phys_device,
device = ctx.device,
vulkan_functions = &vma_vulkan_procs,
pVulkanFunctions = &vma_vulkan_procs,
}, &ctx.vma_allocator)
assert(ok_vma == .SUCCESS)

Expand Down Expand Up @@ -946,7 +951,7 @@ _cleanup :: proc(loc := #caller_location)
semaphore_destroy(semaphore)
}

vma.destroy_allocator(ctx.vma_allocator)
vma.DestroyAllocator(ctx.vma_allocator)

// Check for leaked resources
can_destroy_device := true
Expand Down Expand Up @@ -1206,24 +1211,24 @@ _mem_alloc_raw :: proc(#any_int el_size, #any_int el_count, #any_int align: i64,
bytes := el_size * el_count
if bytes == 0 do return {}

vma_usage: vma.Memory_Usage
vma_usage: vma.MemoryUsage
properties: vk.MemoryPropertyFlags
switch mem_type
{
case .Default:
{
properties = { .HOST_VISIBLE, .HOST_COHERENT }
vma_usage = .Cpu_To_Gpu
vma_usage = .CPU_TO_GPU
}
case .GPU:
{
properties = { .DEVICE_LOCAL }
vma_usage = .Gpu_Only
vma_usage = .GPU_ONLY
}
case .Readback:
{
properties = { .HOST_VISIBLE, .HOST_CACHED, .HOST_COHERENT }
vma_usage = .Gpu_To_Cpu
vma_usage = .GPU_TO_CPU
}
}

Expand All @@ -1248,19 +1253,19 @@ _mem_alloc_raw :: proc(#any_int el_size, #any_int el_count, #any_int align: i64,

mem_requirements.alignment = vk.DeviceSize(max(i64(mem_requirements.alignment), align))

alloc_ci := vma.Allocation_Create_Info {
flags = vma.Allocation_Create_Flags { .Mapped } if mem_type != .GPU else {},
alloc_ci := vma.AllocationCreateInfo {
flags = vma.AllocationCreateFlags { .MAPPED } if mem_type != .GPU else {},
usage = vma_usage,
required_flags = properties,
requiredFlags = properties,
}
alloc: vma.Allocation
vma_alloc_info: vma.Allocation_Info
vk_check(vma.allocate_memory(ctx.vma_allocator, mem_requirements, alloc_ci, &alloc, &vma_alloc_info))
vma_alloc_info: vma.AllocationInfo
vk_check(vma.AllocateMemory(ctx.vma_allocator, mem_requirements, alloc_ci, &alloc, &vma_alloc_info))

vk_check(vma.bind_buffer_memory(ctx.vma_allocator, alloc, buf))
vk_check(vma.BindBufferMemory(ctx.vma_allocator, alloc, buf))

p: ptr
if mem_type != .GPU do p.cpu = vma_alloc_info.mapped_data
if mem_type != .GPU do p.cpu = vma_alloc_info.pMappedData

info := vk.BufferDeviceAddressInfo {
sType = .BUFFER_DEVICE_ADDRESS_INFO,
Expand Down Expand Up @@ -1331,7 +1336,7 @@ _mem_free_raw :: proc(addr: gpuptr, loc := #caller_location)
if addr == {} do return

alloc_info := pool_get(&ctx.allocs, alloc)
vma.destroy_buffer(ctx.vma_allocator, alloc_info.buf_handle, alloc_info.allocation)
vma.DestroyBuffer(ctx.vma_allocator, alloc_info.buf_handle, alloc_info.allocation)
pool_remove(&ctx.allocs, alloc)
}

Expand Down Expand Up @@ -1375,7 +1380,7 @@ _texture_create :: proc(desc: Texture_Desc, storage: gpuptr, queue: Queue = .Mai
image: vk.Image
offset := uintptr(storage.ptr) - uintptr(alloc_info.gpu)
image_ci := to_vk_image_create_info(desc_clean)
vk_check(vma.create_aliasing_image2(ctx.vma_allocator, alloc_info.allocation, vk.DeviceSize(offset), image_ci, &image))
vk_check(vma.CreateAliasingImage2(ctx.vma_allocator, alloc_info.allocation, vk.DeviceSize(offset), image_ci, &image))

plane_aspect := to_vk_image_aspect_flags(desc_clean.format)

Expand Down
6 changes: 5 additions & 1 deletion gpu/vma/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ build
!.gitkeep

# Libraries
#*.lib
*.lib
*.a
*.la
*.lo
Expand All @@ -15,6 +15,10 @@ build
*.dylib
*.obj

# Precompiled Binaries
!libvma*.a
!vma_windows*.lib

# Executables
*.exe
*.out
Expand Down
2 changes: 1 addition & 1 deletion gpu/vma/LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023-2025 Rafael Henrique Capati
Copyright (c) 2023-2026 odin-vma

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
43 changes: 14 additions & 29 deletions gpu/vma/README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
# Odin VMA

Bindings for [Vulkan Memory Allocator][] **v3.3.0** in [Odin Programming Language][].
Bindings for [Vulkan Memory Allocator][] **v3.4.0** in [Odin Programming Language][].

## Basic Usage

Copy the `vma` folder to your project or `shared` directory.

```odin
// Initializes a subset of Vulkan functions required by VMA
vma_vulkan_functions := vma.create_vulkan_functions()

allocator_create_info: vma.Allocator_Create_Info = {
flags = {.Buffer_Device_Address},
instance = instance,
vulkan_api_version = 1003000, // 1.3
physical_device = physical_device,
device = device,
vulkan_functions = &vma_vulkan_functions,
vma_create_info: vma.AllocatorCreateInfo = {
flags = { .BUFFER_DEVICE_ADDRESS },
instance = vk_instance,
physicalDevice = vk_physical_device,
device = vk_device,
pVulkanFunctions = &vma_vulkan_functions,
vulkanApiVersion = api_version,
}

// Create the VMA (Vulkan Memory Allocator)
allocator: vma.Allocator = ---
if res := vma.create_allocator(allocator_create_info, &allocator); res != .SUCCESS {
log.errorf("Failed to Create Vulkan Memory Allocator: [%v]", res)
return
}
vma.CreateAllocator(vma_create_info, &allocator)

defer vma.destroy_allocator(allocator)
defer vma.DestroyAllocator(allocator)
```

## Building VMA
Expand Down Expand Up @@ -57,7 +56,7 @@ Precompiled binaries are not available, but you can easily compile the library u
(Vulkan 1.3).

```shell
premake5 --vk-version=3 vs2022 # 1003000 (1.3)
premake5 --vk-version=3 vs2026 # 1003000 (1.3)
```

4. From the project folder, open the directory `build\make\windows`, them open the generated
Expand Down Expand Up @@ -105,7 +104,7 @@ If you do not have Visual Studio installed, you can use the **Build Tools for Vi
(Vulkan 1.3).

```bash
premake5 --vk-version=3 gmake2 # 1003000 (1.3)
premake5 --vk-version=3 gmake # 1003000 (1.3)
# On macOS, you can also use Xcode:
premake5 --vk-version=3 xcode4
```
Expand Down Expand Up @@ -136,20 +135,6 @@ If you do not have Visual Studio installed, you can use the **Build Tools for Vi

The generated library file will be located in the root of the project directory.

## Naming Conventions

Types and values follow the [Odin Naming Convention][]. In general, `Ada_Case` for types and
`snake_case` for values

| | Case |
| ------------------ | ----------------------------------- |
| Import Name | snake_case (but prefer single word) |
| Types | Ada_Case |
| Enum Values | Ada_Case |
| Procedures | snake_case |
| Local Variables | snake_case |
| Constant Variables | SCREAMING_SNAKE_CASE |

## License

MIT License - See [LICENSE](./LICENSE) file for details.
Expand Down
Binary file modified gpu/vma/libvma_linux_x86_64.a
Binary file not shown.
6 changes: 3 additions & 3 deletions gpu/vma/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ if _PREMAKE_VERSION < "5.0" then
end

-- Constants and options
VMA_VERSION = "v3.3.0"
VULKAN_HEADERS_VERSION = "v1.4.337"
VMA_VERSION = "v3.4.0"
VULKAN_HEADERS_VERSION = "v1.4.355"

-- Utility functions
local redirectNul = (os.host() == "windows") and ">nul 2>&1" or ">/dev/null 2>&1"
Expand Down Expand Up @@ -224,4 +224,4 @@ project "vma"
defines { "NDEBUG" }
optimize "Speed"
symbols "Off"
flags { "NoMinimalRebuild" }
minimalrebuild "Off"
Loading