pub struct BufferVec<T: BufferVecItem> { /* private fields */ }Expand description
The advanced buffer object that could be used as a vector
Implementations§
Source§impl<T> BufferVec<T>where
T: BufferVecItem,
impl<T> BufferVec<T>where
T: BufferVecItem,
Sourcepub fn new(
device: Arc<VulkanDevice>,
usage: VkBufferUsageFlags,
) -> Result<Self, VulkanError>
pub fn new( device: Arc<VulkanDevice>, usage: VkBufferUsageFlags, ) -> Result<Self, VulkanError>
Create the BufferVec<T>
Sourcepub fn get_device(&self) -> Arc<VulkanDevice>
pub fn get_device(&self) -> Arc<VulkanDevice>
Get the device
Sourcepub fn from(
device: Arc<VulkanDevice>,
data: &[T],
cmdbuf: VkCommandBuffer,
usage: VkBufferUsageFlags,
) -> Result<Self, VulkanError>
pub fn from( device: Arc<VulkanDevice>, data: &[T], cmdbuf: VkCommandBuffer, usage: VkBufferUsageFlags, ) -> Result<Self, VulkanError>
Create from a slice of data
Sourcepub fn with_capacity(
device: Arc<VulkanDevice>,
capacity: usize,
usage: VkBufferUsageFlags,
) -> Result<Self, VulkanError>
pub fn with_capacity( device: Arc<VulkanDevice>, capacity: usize, usage: VkBufferUsageFlags, ) -> Result<Self, VulkanError>
Create the BufferVec<T> with an initial capacity
Sourcepub fn change_capacity(
&mut self,
new_capacity: usize,
) -> Result<(), VulkanError>
pub fn change_capacity( &mut self, new_capacity: usize, ) -> Result<(), VulkanError>
Change the capacity
- If the capacity is less than the current items, the number of items will be reduced to the new capacity.
Sourcepub unsafe fn set_data_modified(
&mut self,
first_index: usize,
length: usize,
flag: bool,
)
pub unsafe fn set_data_modified( &mut self, first_index: usize, length: usize, flag: bool, )
Set data is modified or not
§Safety
This would change the behavior of how flush does to the data.
The data marked as modified will be uploaded to the device, while the data marked as unmodified maybe uploaded to the device, or not (skipped because the gap is long enough)
You are going to control which part of the data will be synchronized to the device, while you are not actually knowing if the data is really changed.
first_index: Which part of the data you are going to mark.length: From the index, how many items you are going to mark.flag: The boolean value of the mark,truemeans the data is marked as changed and will be synchronized to the device after nextflushwas called,falsemeans the data is unchanged and will not be synchronized to the device.
§Panic
Panic if the index and range is out of bounds
Sourcepub unsafe fn set_len(&mut self, new_len: usize)
pub unsafe fn set_len(&mut self, new_len: usize)
Change the length Forces the length of the vector to new_len.
This is a low-level operation that maintains none of the normal invariants of the type.
§Safety
new_len must be less than or equal to capacity().
The elements at old_len..new_len must be initialized.
Sourcepub fn into_inner(self) -> Buffer
pub fn into_inner(self) -> Buffer
Get the inner buffer
Sourcepub unsafe fn from_raw_parts(
buffer: Buffer,
length: usize,
) -> Result<Self, VulkanError>
pub unsafe fn from_raw_parts( buffer: Buffer, length: usize, ) -> Result<Self, VulkanError>
Creates a BufferVec<T> directly from a buffer, a length, and a capacity.
§Safety
This is highly unsafe, just like the Rust official Vec<T>::from_raw_parts()
- Unlike the Rust official
Vec<T>::from_raw_parts(), capacity is not needed to be provided since it was calculated bybuffer.get_size() / size_of::<T>() lengthmust be less than the calculated capacity.
Sourcepub fn push(&mut self, data: T) -> Result<(), VulkanError>
pub fn push(&mut self, data: T) -> Result<(), VulkanError>
Push data to the buffer
Sourcepub fn remove(&mut self, index: usize) -> T
pub fn remove(&mut self, index: usize) -> T
Removes and returns the element at position index within the vector, shifting all elements after it to the left.
Note: Because this shifts over the remaining elements, it has a worst-case performance of O(n). If you don’t need the order of elements to be preserved, use swap_remove instead.
§Panics
Panics if index is out of bounds.
Sourcepub fn swap_remove(&mut self, index: usize) -> T
pub fn swap_remove(&mut self, index: usize) -> T
Removes an element from the vector and returns it.
The removed element is replaced by the last element of the vector.
This does not preserve ordering of the remaining elements, but is O(1). If you need to preserve the element order, use remove instead.
§Panics
Panics if index is out of bounds.
Sourcepub fn resize(&mut self, new_len: usize, new_data: T) -> Result<(), VulkanError>
pub fn resize(&mut self, new_len: usize, new_data: T) -> Result<(), VulkanError>
Resize the buffer
Sourcepub fn get_capacity(&self) -> usize
pub fn get_capacity(&self) -> usize
Get the capacity
Sourcepub fn shrink_to_fit(&mut self) -> Result<(), VulkanError>
pub fn shrink_to_fit(&mut self) -> Result<(), VulkanError>
Shrink to fit
Sourcepub fn flush(&mut self, cmdbuf: VkCommandBuffer) -> Result<(), VulkanError>
pub fn flush(&mut self, cmdbuf: VkCommandBuffer) -> Result<(), VulkanError>
Flush the staging buffer to the device memory
Trait Implementations§
Source§impl<T> BufferForDraw<T> for BufferVec<T>where
T: BufferVecItem,
impl<T> BufferForDraw<T> for BufferVec<T>where
T: BufferVecItem,
Source§fn create(
device: Arc<VulkanDevice>,
data: &[T],
cmdbuf: VkCommandBuffer,
usage: VkBufferUsageFlags,
) -> Result<Self, VulkanError>
fn create( device: Arc<VulkanDevice>, data: &[T], cmdbuf: VkCommandBuffer, usage: VkBufferUsageFlags, ) -> Result<Self, VulkanError>
Source§fn get_vk_buffer(&self) -> VkBuffer
fn get_vk_buffer(&self) -> VkBuffer
VkBuffer handleSource§fn get_device(&self) -> Arc<VulkanDevice>
fn get_device(&self) -> Arc<VulkanDevice>
Source§fn flush(&mut self, cmdbuf: VkCommandBuffer) -> Result<(), VulkanError>
fn flush(&mut self, cmdbuf: VkCommandBuffer) -> Result<(), VulkanError>
Source§fn convert_to_buffer_vec(self) -> BufferVec<T>
fn convert_to_buffer_vec(self) -> BufferVec<T>
BufferVec<T>Source§fn convert_to_buffer_with_type(self) -> BufferWithType<T>
fn convert_to_buffer_with_type(self) -> BufferWithType<T>
BufferWithType<T>Source§fn discard_staging_buffer(&self)
fn discard_staging_buffer(&self)
Source§impl<T> Clone for BufferVec<T>where
T: BufferVecItem,
impl<T> Clone for BufferVec<T>where
T: BufferVecItem,
Source§impl<T> Debug for BufferVec<T>where
T: BufferVecItem,
impl<T> Debug for BufferVec<T>where
T: BufferVecItem,
Source§impl<T> Index<RangeInclusive<usize>> for BufferVec<T>where
T: BufferVecItem,
impl<T> Index<RangeInclusive<usize>> for BufferVec<T>where
T: BufferVecItem,
Source§impl<T> Index<RangeToInclusive<usize>> for BufferVec<T>where
T: BufferVecItem,
impl<T> Index<RangeToInclusive<usize>> for BufferVec<T>where
T: BufferVecItem,
Source§impl<T> IndexMut<RangeInclusive<usize>> for BufferVec<T>where
T: BufferVecItem,
impl<T> IndexMut<RangeInclusive<usize>> for BufferVec<T>where
T: BufferVecItem,
Source§impl<T> IndexMut<RangeToInclusive<usize>> for BufferVec<T>where
T: BufferVecItem,
impl<T> IndexMut<RangeToInclusive<usize>> for BufferVec<T>where
T: BufferVecItem,
impl<T> Send for BufferVec<T>where
T: BufferVecItem,
impl<T> Sync for BufferVec<T>where
T: BufferVecItem,
Auto Trait Implementations§
impl<T> !Freeze for BufferVec<T>
impl<T> RefUnwindSafe for BufferVec<T>where
T: RefUnwindSafe,
impl<T> Unpin for BufferVec<T>where
T: Unpin,
impl<T> UnwindSafe for BufferVec<T>where
T: RefUnwindSafe + UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.