1 use crate::{AtomSize, Size}; 2 3 /// Memory object wrapper. 4 /// Contains size and properties of the memory. 5 #[derive(Debug)] 6 pub 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 13 impl<B: hal::Backend> Memory<B> { 14 /// Get memory properties. properties(&self) -> hal::memory::Properties15 pub fn properties(&self) -> hal::memory::Properties { 16 self.properties 17 } 18 19 /// Get memory size. size(&self) -> Size20 pub fn size(&self) -> Size { 21 self.size 22 } 23 24 /// Get raw memory. raw(&self) -> &B::Memory25 pub fn raw(&self) -> &B::Memory { 26 &self.raw 27 } 28 29 /// Unwrap raw memory. into_raw(self) -> B::Memory30 pub fn into_raw(self) -> B::Memory { 31 self.raw 32 } 33 34 /// Create memory from raw object. 35 /// 36 /// # Safety 37 /// 38 /// TODO: from_raw( raw: B::Memory, size: Size, properties: hal::memory::Properties, non_coherent_atom_size: Option<AtomSize>, ) -> Self39 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 /// Check if this memory is host-visible and can be mapped. 58 /// `Equivalent to `memory.properties().contains(Properties::CPU_VISIBLE)`. is_mappable(&self) -> bool59 pub fn is_mappable(&self) -> bool { 60 self.properties 61 .contains(hal::memory::Properties::CPU_VISIBLE) 62 } 63 } 64