Struct vulkano::buffer::BufferSlice
source · [−]pub struct BufferSlice<T: ?Sized, B> { /* private fields */ }
Expand description
A subpart of a buffer.
This object doesn’t correspond to any Vulkan object. It exists for API convenience.
Example
Creating a slice:
use vulkano::buffer::BufferSlice;
let _slice = BufferSlice::from(&buffer);
Selecting a slice of a buffer that contains [T]
:
use vulkano::buffer::BufferSlice;
let _slice = BufferSlice::from(&buffer).slice(12 .. 14).unwrap();
Implementations
sourceimpl<T: ?Sized, B> BufferSlice<T, B>
impl<T: ?Sized, B> BufferSlice<T, B>
pub fn from_typed_buffer_access(r: Arc<B>) -> Arc<BufferSlice<T, B>> where
B: TypedBufferAccess<Content = T>,
sourcepub fn offset(&self) -> DeviceSize
pub fn offset(&self) -> DeviceSize
Returns the offset of that slice within the buffer.
sourcepub fn size(&self) -> DeviceSize
pub fn size(&self) -> DeviceSize
Returns the size of that slice in bytes.
sourcepub unsafe fn slice_custom<F, R: ?Sized>(&self, f: F) -> Arc<BufferSlice<R, B>> where
F: for<'r> FnOnce(&'r T) -> &'r R,
pub unsafe fn slice_custom<F, R: ?Sized>(&self, f: F) -> Arc<BufferSlice<R, B>> where
F: for<'r> FnOnce(&'r T) -> &'r R,
Builds a slice that contains an element from inside the buffer.
This method builds an object that represents a slice of the buffer. No actual operation is performed.
Example
TODO
Safety
The object whose reference is passed to the closure is uninitialized. Therefore you must not access the content of the object.
You must return a reference to an element from the parameter. The closure must not panic.
sourcepub unsafe fn reinterpret<R: ?Sized>(&self) -> Arc<BufferSlice<R, B>>
pub unsafe fn reinterpret<R: ?Sized>(&self) -> Arc<BufferSlice<R, B>>
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
let blob_slice: Arc<BufferSlice<[u8], Arc<ImmutableBuffer<[u8]>>>> = return;
let vertex_slice: Arc<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.
sourceimpl<T, B> BufferSlice<[T], B>
impl<T, B> BufferSlice<[T], B>
sourcepub fn len(&self) -> DeviceSize
pub fn len(&self) -> DeviceSize
Returns the number of elements in this slice.
sourcepub fn index(&self, index: DeviceSize) -> Option<Arc<BufferSlice<T, B>>>
pub fn index(&self, index: DeviceSize) -> Option<Arc<BufferSlice<T, B>>>
Reduces the slice to just one element of the array.
Returns None
if out of range.
sourcepub fn slice(
&self,
range: Range<DeviceSize>
) -> Option<Arc<BufferSlice<[T], B>>>
pub fn slice(
&self,
range: Range<DeviceSize>
) -> Option<Arc<BufferSlice<[T], B>>>
Reduces the slice to just a range of the array.
Returns None
if out of range.
Trait Implementations
sourceimpl<T, B> BufferAccess for BufferSlice<T, B> where
B: BufferAccess,
T: Send + Sync + ?Sized,
impl<T, B> BufferAccess for BufferSlice<T, B> where
B: BufferAccess,
T: Send + Sync + ?Sized,
sourcefn inner(&self) -> BufferInner<'_>
fn inner(&self) -> BufferInner<'_>
Returns the inner information about this buffer.
sourcefn size(&self) -> DeviceSize
fn size(&self) -> DeviceSize
Returns the size of the buffer in bytes.
sourcefn conflict_key(&self) -> (u64, u64)
fn conflict_key(&self) -> (u64, u64)
Returns a key that uniquely identifies the buffer. Two buffers or images that potentially overlap in memory must return the same key. Read more
sourcefn try_gpu_lock(
&self,
exclusive_access: bool,
queue: &Queue
) -> Result<(), AccessError>
fn try_gpu_lock(
&self,
exclusive_access: bool,
queue: &Queue
) -> Result<(), AccessError>
Locks the resource for usage on the GPU. Returns an error if the lock can’t be acquired. Read more
sourceunsafe fn increase_gpu_lock(&self)
unsafe fn increase_gpu_lock(&self)
Locks the resource for usage on the GPU. Supposes that the resource is already locked, and simply increases the lock by one. Read more
sourceunsafe fn unlock(&self)
unsafe fn unlock(&self)
Unlocks the resource previously acquired with try_gpu_lock
or increase_gpu_lock
. Read more
sourcefn into_buffer_slice(self: &Arc<Self>) -> Arc<BufferSlice<Self::Content, Self>> where
Self: Sized + TypedBufferAccess,
fn into_buffer_slice(self: &Arc<Self>) -> Arc<BufferSlice<Self::Content, Self>> where
Self: Sized + TypedBufferAccess,
Returns a BufferSlice
covering the whole buffer.
sourcefn slice<T>(
self: &Arc<Self>,
range: Range<DeviceSize>
) -> Option<Arc<BufferSlice<[T], Self>>> where
Self: Sized + TypedBufferAccess<Content = [T]>,
fn slice<T>(
self: &Arc<Self>,
range: Range<DeviceSize>
) -> Option<Arc<BufferSlice<[T], Self>>> where
Self: Sized + TypedBufferAccess<Content = [T]>,
Returns a BufferSlice
for a subrange of elements in the buffer. Returns None
if
out of range. Read more
sourcefn index<T>(
self: &Arc<Self>,
index: DeviceSize
) -> Option<Arc<BufferSlice<T, Self>>> where
Self: Sized + TypedBufferAccess<Content = [T]>,
fn index<T>(
self: &Arc<Self>,
index: DeviceSize
) -> Option<Arc<BufferSlice<T, Self>>> where
Self: Sized + TypedBufferAccess<Content = [T]>,
Returns a BufferSlice
for a single element in the buffer. Returns None
if out of range. Read more
sourcefn raw_device_address(&self) -> Result<NonZeroU64, BufferDeviceAddressError>
fn raw_device_address(&self) -> Result<NonZeroU64, BufferDeviceAddressError>
Gets the device address for this buffer. Read more
sourceimpl<T: ?Sized, B> Clone for BufferSlice<T, B>
impl<T: ?Sized, B> Clone for BufferSlice<T, B>
sourceimpl<T: ?Sized, B> DeviceOwned for BufferSlice<T, B> where
B: DeviceOwned,
impl<T: ?Sized, B> DeviceOwned for BufferSlice<T, B> where
B: DeviceOwned,
sourceimpl<T, B> From<BufferSlice<T, B>> for BufferSlice<[T], B>
impl<T, B> From<BufferSlice<T, B>> for BufferSlice<[T], B>
sourcefn from(r: BufferSlice<T, B>) -> BufferSlice<[T], B>
fn from(r: BufferSlice<T, B>) -> BufferSlice<[T], B>
Performs the conversion.
sourceimpl<T: ?Sized, B> Hash for BufferSlice<T, B> where
T: Send + Sync,
B: BufferAccess,
impl<T: ?Sized, B> Hash for BufferSlice<T, B> where
T: Send + Sync,
B: BufferAccess,
sourceimpl<T: ?Sized, B> PartialEq<BufferSlice<T, B>> for BufferSlice<T, B> where
T: Send + Sync,
B: BufferAccess,
impl<T: ?Sized, B> PartialEq<BufferSlice<T, B>> for BufferSlice<T, B> where
T: Send + Sync,
B: BufferAccess,
sourceimpl<T, B> TypedBufferAccess for BufferSlice<T, B> where
T: BufferContents + ?Sized,
B: BufferAccess,
impl<T, B> TypedBufferAccess for BufferSlice<T, B> where
T: BufferContents + ?Sized,
B: BufferAccess,
type Content = T
type Content = T
The type of the content.
sourcefn len(&self) -> DeviceSize
fn len(&self) -> DeviceSize
Returns the length of the buffer in number of elements. Read more
impl<T: ?Sized, B> Eq for BufferSlice<T, B> where
B: BufferAccess,
T: Send + Sync,
Auto Trait Implementations
impl<T: ?Sized, B> RefUnwindSafe for BufferSlice<T, B> where
B: RefUnwindSafe,
T: RefUnwindSafe,
impl<T: ?Sized, B> Send for BufferSlice<T, B> where
B: Send + Sync,
T: Send,
impl<T: ?Sized, B> Sync for BufferSlice<T, B> where
B: Send + Sync,
T: Sync,
impl<T: ?Sized, B> Unpin for BufferSlice<T, B> where
T: Unpin,
impl<T: ?Sized, B> UnwindSafe for BufferSlice<T, B> where
B: RefUnwindSafe,
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more