Add a reinterpret function to BufferSlice (#1038)

Add a `reinterpret` function to `BufferSlice`
This commit is contained in:
Jakub Hlusička 2018-09-16 23:44:36 +02:00 committed by Lucas Kent
parent d8bcc6b126
commit e3bfe4270c
2 changed files with 34 additions and 1 deletions

View File

@ -1,8 +1,9 @@
# Unreleased (Breaking) # Unreleased (Breaking)
- Split 'PersistentDescriptorSetError::MissingUsage' into 'MissingImageUsage' and 'MissingBufferUsage' - Split `PersistentDescriptorSetError::MissingUsage` into `MissingImageUsage` and `MissingBufferUsage`
each with a matching enum indicating the usage that was missing. each with a matching enum indicating the usage that was missing.
- Fix instance_count when using draw_index with instance buffers - Fix instance_count when using draw_index with instance buffers
- Added a `reinterpret` function to `BufferSlice`
# Version 0.10.0 (2018-08-10) # Version 0.10.0 (2018-08-10)

View File

@ -132,6 +132,38 @@ impl<T: ?Sized, B> BufferSlice<T, B> {
size: size, size: size,
} }
} }
/// Changes the `T` generic parameter of the `BufferSlice` to the desired type. This can be
/// useful when you have a buffer with various types of data and want to create a typed slice
/// of a region that contains a single type of data.
///
/// # Example
///
/// ```
/// # use std::sync::Arc;
/// # use vulkano::buffer::BufferSlice;
/// # use vulkano::buffer::immutable::ImmutableBuffer;
/// # struct VertexImpl;
/// let blob_slice: BufferSlice<[u8], Arc<ImmutableBuffer<[u8]>>> = return;
/// let vertex_slice: BufferSlice<[VertexImpl], Arc<ImmutableBuffer<[u8]>>> = unsafe {
/// blob_slice.reinterpret::<[VertexImpl]>()
/// };
/// ```
///
/// # Safety
///
/// Correct `offset` and `size` must be ensured before using this `BufferSlice` on the device.
/// See `BufferSlice::slice` for adjusting these properties.
#[inline]
pub unsafe fn reinterpret<R: ?Sized>(self) -> BufferSlice<R, B>
{
BufferSlice {
marker: PhantomData,
resource: self.resource,
offset: self.offset,
size: self.size,
}
}
} }
impl<T, B> BufferSlice<[T], B> { impl<T, B> BufferSlice<[T], B> {