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
59
60
61
62
63
64
use hal::memory as m;
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum MemoryUsage {
Private,
Dynamic {
sparse_updates: bool,
},
Staging {
read_back: bool,
},
}
impl MemoryUsage {
pub fn properties_required(&self) -> m::Properties {
match *self {
MemoryUsage::Private => m::Properties::DEVICE_LOCAL,
MemoryUsage::Dynamic { .. } | MemoryUsage::Staging { .. } => m::Properties::CPU_VISIBLE,
}
}
pub(crate) fn memory_fitness(&self, properties: m::Properties) -> u32 {
match *self {
MemoryUsage::Private => {
assert!(properties.contains(m::Properties::DEVICE_LOCAL));
0 | (!properties.contains(m::Properties::CPU_VISIBLE) as u32) << 3
| (!properties.contains(m::Properties::LAZILY_ALLOCATED) as u32) << 2
| (!properties.contains(m::Properties::CPU_CACHED) as u32) << 1
| (!properties.contains(m::Properties::COHERENT) as u32) << 0
}
MemoryUsage::Dynamic { sparse_updates } => {
assert!(properties.contains(m::Properties::CPU_VISIBLE));
assert!(!properties.contains(m::Properties::LAZILY_ALLOCATED));
0 | (properties.contains(m::Properties::DEVICE_LOCAL) as u32) << 2
| ((properties.contains(m::Properties::COHERENT) == sparse_updates) as u32) << 1
| (!properties.contains(m::Properties::CPU_CACHED) as u32) << 0
}
MemoryUsage::Staging { read_back } => {
assert!(properties.contains(m::Properties::CPU_VISIBLE));
assert!(!properties.contains(m::Properties::LAZILY_ALLOCATED));
0 | ((properties.contains(m::Properties::CPU_CACHED) == read_back) as u32) << 1
| (!properties.contains(m::Properties::DEVICE_LOCAL) as u32) << 0
}
}
}
}