1use std::ffi::c_void;
2use std::ptr::NonNull;
3
4use anyhow::Result;
5use ash::vk::*;
6
7pub trait Allocation: Send + Sync {
9 unsafe fn memory(&self) -> DeviceMemory;
11
12 fn offset(&self) -> u64;
14
15 fn size(&self) -> u64;
17
18 fn mapped_ptr(&self) -> Option<NonNull<c_void>>;
20}
21
22pub trait MemoryLocation: Clone + Send + Sync {
24 fn gpu_only() -> Self;
25 fn cpu_to_gpu() -> Self;
26 fn gpu_to_cpu() -> Self;
27}
28
29pub trait AllocationCreateInfo {
31 type MemoryLocation: MemoryLocation;
32 fn new(
33 name: Option<&'static str>,
34 requirements: MemoryRequirements,
35 location: Self::MemoryLocation,
36 linear: bool,
37 ) -> Self;
38}
39
40pub trait Allocator: Clone + Send + Sync {
42 type Allocation: Allocation;
43 type AllocationCreateInfo: AllocationCreateInfo;
44
45 fn allocate(&self, desc: Self::AllocationCreateInfo) -> Result<Self::Allocation>;
47
48 fn free(&self, allocation: Self::Allocation) -> Result<()>;
50}