From e3bfe4270c63e7fa09a6440e9238b79d18a793f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Hlusi=C4=8Dka?= Date: Sun, 16 Sep 2018 23:44:36 +0200 Subject: [PATCH] Add a `reinterpret` function to `BufferSlice` (#1038) Add a `reinterpret` function to `BufferSlice` --- CHANGELOG.md | 3 ++- vulkano/src/buffer/slice.rs | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b4d9745..69663c6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,9 @@ # 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. - Fix instance_count when using draw_index with instance buffers +- Added a `reinterpret` function to `BufferSlice` # Version 0.10.0 (2018-08-10) diff --git a/vulkano/src/buffer/slice.rs b/vulkano/src/buffer/slice.rs index fa4cb4d4..4d8983a4 100644 --- a/vulkano/src/buffer/slice.rs +++ b/vulkano/src/buffer/slice.rs @@ -132,6 +132,38 @@ impl BufferSlice { 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>> = return; + /// let vertex_slice: BufferSlice<[VertexImpl], Arc>> = 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(self) -> BufferSlice + { + BufferSlice { + marker: PhantomData, + resource: self.resource, + offset: self.offset, + size: self.size, + } + } } impl BufferSlice<[T], B> {