pub struct MappedRange<'a, B: Backend, C = MaybeCoherent> { /* private fields */ }Expand description
Represents range of the memory mapped to the host. Provides methods for safer host access to the memory.
Implementations§
Source§impl<'a, B> MappedRange<'a, B>where
B: Backend,
impl<'a, B> MappedRange<'a, B>where
B: Backend,
Sourcepub unsafe fn from_raw(
memory: &'a Memory<B>,
ptr: NonNull<u8>,
range: Range<u64>,
) -> Self
pub unsafe fn from_raw( memory: &'a Memory<B>, ptr: NonNull<u8>, range: Range<u64>, ) -> Self
Construct mapped range from raw mapping
§Safety
memory range must be mapped to host memory region pointer by ptr.
range is in memory object space.
ptr points to the range.start offset from memory origin.
Sourcepub fn ptr(&self) -> NonNull<u8>
pub fn ptr(&self) -> NonNull<u8>
Get pointer to beginning of memory region.
i.e. to range().start offset from memory origin.
Sourcepub unsafe fn read<'b, T>(
&'b mut self,
device: &B::Device,
range: Range<u64>,
) -> Result<&'b [T], MapError>where
T: Copy,
'a: 'b,
pub unsafe fn read<'b, T>(
&'b mut self,
device: &B::Device,
range: Range<u64>,
) -> Result<&'b [T], MapError>where
T: Copy,
'a: 'b,
Fetch readable slice of sub-range to be read.
Invalidating range if memory is not coherent.
range.end - range.start must be multiple of size_of::().
mapping offset + range.start must be multiple of align_of::().
§Safety
- Caller must ensure that device won’t write to the memory region until the borrowing ends.
TMust be plain-old-data type compatible with data in mapped region.
Sourcepub unsafe fn write<'b, T>(
&'b mut self,
device: &'b B::Device,
range: Range<u64>,
) -> Result<impl Write<T> + 'b, MapError>where
T: Copy + 'b,
'a: 'b,
pub unsafe fn write<'b, T>(
&'b mut self,
device: &'b B::Device,
range: Range<u64>,
) -> Result<impl Write<T> + 'b, MapError>where
T: Copy + 'b,
'a: 'b,
Fetch writer to the sub-region. This writer will flush data on drop if written at least once.
§Safety
- Caller must ensure that device won’t write to or read from the memory region.
Sourcepub fn coherent(
self,
) -> Result<MappedRange<'a, B, Coherent>, MappedRange<'a, B, NonCoherent>>
pub fn coherent( self, ) -> Result<MappedRange<'a, B, Coherent>, MappedRange<'a, B, NonCoherent>>
Convert into mapped range with statically known coherency.