rendy_memory/
block.rs

1use std::ops::Range;
2
3use crate::mapping::MappedRange;
4
5/// Block that owns a `Range` of the `Memory`.
6/// Implementor must ensure that there can't be any other blocks
7/// with overlapping range (either through type system or safety notes for unsafe functions).
8/// Provides access to safe memory range mapping.
9pub trait Block<B: gfx_hal::Backend> {
10    /// Get memory properties of the block.
11    fn properties(&self) -> gfx_hal::memory::Properties;
12
13    /// Get raw memory object.
14    fn memory(&self) -> &B::Memory;
15
16    /// Get memory range owned by this block.
17    fn range(&self) -> Range<u64>;
18
19    /// Get size of the block.
20    fn size(&self) -> u64 {
21        let range = self.range();
22        range.end - range.start
23    }
24
25    /// Get mapping for the buffer range.
26    /// Memory writes to the region performed by device become available for the host.
27    fn map<'a>(
28        &'a mut self,
29        device: &B::Device,
30        range: Range<u64>,
31    ) -> Result<MappedRange<'a, B>, gfx_hal::device::MapError>;
32
33    /// Release memory mapping. Must be called after successful `map` call.
34    /// No-op if block is not mapped.
35    fn unmap(&mut self, device: &B::Device);
36}