1use crate::{AtomSize, Size};
2
3#[derive(Debug)]
6pub struct Memory<B: hal::Backend> {
7 raw: B::Memory,
8 size: Size,
9 properties: hal::memory::Properties,
10 pub(crate) non_coherent_atom_size: Option<AtomSize>,
11}
12
13impl<B: hal::Backend> Memory<B> {
14 pub fn properties(&self) -> hal::memory::Properties {
16 self.properties
17 }
18
19 pub fn size(&self) -> Size {
21 self.size
22 }
23
24 pub fn raw(&self) -> &B::Memory {
26 &self.raw
27 }
28
29 pub fn into_raw(self) -> B::Memory {
31 self.raw
32 }
33
34 pub unsafe fn from_raw(
40 raw: B::Memory,
41 size: Size,
42 properties: hal::memory::Properties,
43 non_coherent_atom_size: Option<AtomSize>,
44 ) -> Self {
45 debug_assert_eq!(
46 non_coherent_atom_size.is_some(),
47 crate::is_non_coherent_visible(properties),
48 );
49 Memory {
50 properties,
51 raw,
52 size,
53 non_coherent_atom_size,
54 }
55 }
56
57 pub fn is_mappable(&self) -> bool {
60 self.properties
61 .contains(hal::memory::Properties::CPU_VISIBLE)
62 }
63}