brutal/Brutal.Vulkan.Abstractions/Allocator/Allocation.cs
Rian Drake b578433e37 first
2026-10-15 17:10:50 +13:00

55 lines
2.4 KiB
C#

namespace Brutal.VulkanApi.Abstractions;
/// <summary>
/// Struct containing information about a memory allocation. Intentionally made similar to VMA's AllocationInfo
/// </summary>
/// <param name="Allocator">Allocator that sourced this allocation</param>
/// <param name="Memory">Device memory handle</param>
/// <param name="AllocSize">Size available in the memory allocation (might be more than requested)</param>
/// <param name="AllocOffset">Offset into the memory allocation</param>
/// <param name="MemoryTypeIndex">Memory type this allocation was made from</param>
/// <param name="AllocHandle">Custom handle, optionally used by allocator</param>
public readonly record struct AllocationInfo(
IAllocator Allocator,
VkDeviceMemory Memory,
ByteSize AllocSize,
ByteSize AllocOffset,
int MemoryTypeIndex,
nint AllocHandle
)
{
/// <summary>
/// Struct containing information about a memory allocation. Intentionally made similar to VMA's AllocationCreateInfo
/// </summary>
/// <param name="Preference">Memory location preference can just leave as 'None'</param>
/// <param name="RequiredProperties">Flags that must be set in a Memory Type chosen for an allocation</param>
/// <param name="PreferredProperties">Flags that preferably should be set in a memory type chosen for an allocation</param>
/// <param name="Priority">A floating-point value between 0 and 1, indicating the priority of the allocation relative to other memory allocations</param>
/// <param name="Next">For advanced use only. A pointer to an application-defined structure that can be used to pass custom data to the allocator</param>
public record struct CreateInfo(
MemoryPreference Preference,
VkMemoryPropertyFlags RequiredProperties,
VkMemoryPropertyFlags PreferredProperties,
float Priority,
Ptr Next
)
{
/// <summary>
/// Optional memory allocation flags. When set, the allocator chains a
/// <see cref="VkMemoryAllocateFlagsInfo"/> in front of <see cref="Next"/>
/// (e.g. <see cref="VkMemoryAllocateFlags.DeviceAddressBit"/> for buffers whose
/// device address will be queried).
/// </summary>
public VkMemoryAllocateFlags AllocateFlags { get; set; }
}
}
/// <summary>
/// Enum listing memory allocation preferences: whether to prefer GPU or CPU memory
/// </summary>
public enum MemoryPreference : byte
{
None,
PreferGpu,
PreferCpu,
}