-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathgpu_allocator.rs
58 lines (48 loc) · 1.79 KB
/
gpu_allocator.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use std::sync::{Arc, Mutex};
use anyhow::Result;
use gpu_allocator::vulkan::*;
use crate::allocator::{AllocationCreateInfoTrait, AllocationTrait, AllocatorTrait};
impl AllocationTrait for Allocation {
unsafe fn memory(&self) -> ash::vk::DeviceMemory {
Allocation::memory(&self)
}
fn offset(&self) -> u64 {
Allocation::offset(&self)
}
fn size(&self) -> u64 {
Allocation::size(&self)
}
fn mapped_ptr(&self) -> Option<std::ptr::NonNull<std::ffi::c_void>> {
Allocation::mapped_ptr(&self)
}
}
impl AllocationCreateInfoTrait for AllocationCreateDesc<'static> {
fn new(
requirements: ash::vk::MemoryRequirements,
location: crate::MemoryLocation,
linear: bool,
) -> Self {
Self {
name: "egui-winit-ash-integration",
requirements,
location: match location {
crate::MemoryLocation::Unknown => gpu_allocator::MemoryLocation::Unknown,
crate::MemoryLocation::GpuOnly => gpu_allocator::MemoryLocation::GpuOnly,
crate::MemoryLocation::CpuToGpu => gpu_allocator::MemoryLocation::CpuToGpu,
crate::MemoryLocation::GpuToCpu => gpu_allocator::MemoryLocation::GpuToCpu,
},
linear,
allocation_scheme: AllocationScheme::GpuAllocatorManaged,
}
}
}
impl AllocatorTrait for Arc<Mutex<Allocator>> {
type Allocation = Allocation;
type AllocationCreateInfo = AllocationCreateDesc<'static>;
fn allocate(&self, desc: Self::AllocationCreateInfo) -> Result<Self::Allocation> {
Ok(Allocator::allocate(&mut self.lock().unwrap(), &desc)?)
}
fn free(&self, allocation: Self::Allocation) -> Result<()> {
Ok(Allocator::free(&mut self.lock().unwrap(), allocation)?)
}
}