diff options
Diffstat (limited to 'rendy-memory/src/block.rs')
-rw-r--r-- | rendy-memory/src/block.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/rendy-memory/src/block.rs b/rendy-memory/src/block.rs new file mode 100644 index 0000000..23ff4f4 --- /dev/null +++ b/rendy-memory/src/block.rs @@ -0,0 +1,36 @@ +use std::ops::Range; + +use crate::mapping::MappedRange; + +/// Block that owns a `Range` of the `Memory`. +/// Implementor must ensure that there can't be any other blocks +/// with overlapping range (either through type system or safety notes for unsafe functions). +/// Provides access to safe memory range mapping. +pub trait Block<B: gfx_hal::Backend> { + /// Get memory properties of the block. + fn properties(&self) -> gfx_hal::memory::Properties; + + /// Get raw memory object. + fn memory(&self) -> &B::Memory; + + /// Get memory range owned by this block. + fn range(&self) -> Range<u64>; + + /// Get size of the block. + fn size(&self) -> u64 { + let range = self.range(); + range.end - range.start + } + + /// Get mapping for the buffer range. + /// Memory writes to the region performed by device become available for the host. + fn map<'a>( + &'a mut self, + device: &B::Device, + range: Range<u64>, + ) -> Result<MappedRange<'a, B>, gfx_hal::device::MapError>; + + /// Release memory mapping. Must be called after successful `map` call. + /// No-op if block is not mapped. + fn unmap(&mut self, device: &B::Device); +} |