Skip to content

Commit e3bfe42

Browse files
Limethrukai
authored andcommitted
Add a reinterpret function to BufferSlice (#1038)
Add a `reinterpret` function to `BufferSlice`
1 parent d8bcc6b commit e3bfe42

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

Diff for: CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Unreleased (Breaking)
22

3-
- Split 'PersistentDescriptorSetError::MissingUsage' into 'MissingImageUsage' and 'MissingBufferUsage'
3+
- Split `PersistentDescriptorSetError::MissingUsage` into `MissingImageUsage` and `MissingBufferUsage`
44
each with a matching enum indicating the usage that was missing.
55
- Fix instance_count when using draw_index with instance buffers
6+
- Added a `reinterpret` function to `BufferSlice`
67

78
# Version 0.10.0 (2018-08-10)
89

Diff for: vulkano/src/buffer/slice.rs

+32
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,38 @@ impl<T: ?Sized, B> BufferSlice<T, B> {
132132
size: size,
133133
}
134134
}
135+
136+
/// Changes the `T` generic parameter of the `BufferSlice` to the desired type. This can be
137+
/// useful when you have a buffer with various types of data and want to create a typed slice
138+
/// of a region that contains a single type of data.
139+
///
140+
/// # Example
141+
///
142+
/// ```
143+
/// # use std::sync::Arc;
144+
/// # use vulkano::buffer::BufferSlice;
145+
/// # use vulkano::buffer::immutable::ImmutableBuffer;
146+
/// # struct VertexImpl;
147+
/// let blob_slice: BufferSlice<[u8], Arc<ImmutableBuffer<[u8]>>> = return;
148+
/// let vertex_slice: BufferSlice<[VertexImpl], Arc<ImmutableBuffer<[u8]>>> = unsafe {
149+
/// blob_slice.reinterpret::<[VertexImpl]>()
150+
/// };
151+
/// ```
152+
///
153+
/// # Safety
154+
///
155+
/// Correct `offset` and `size` must be ensured before using this `BufferSlice` on the device.
156+
/// See `BufferSlice::slice` for adjusting these properties.
157+
#[inline]
158+
pub unsafe fn reinterpret<R: ?Sized>(self) -> BufferSlice<R, B>
159+
{
160+
BufferSlice {
161+
marker: PhantomData,
162+
resource: self.resource,
163+
offset: self.offset,
164+
size: self.size,
165+
}
166+
}
135167
}
136168

137169
impl<T, B> BufferSlice<[T], B> {

0 commit comments

Comments
 (0)