pub struct InstanceBuffer<T: Pod> { /* private fields */ }Expand description
GPU instance buffer with partial update support.
Maintains a CPU-side buffer and GPU buffer, tracking which ranges have been modified and need uploading. Supports efficient partial writes for retained-mode rendering where only dirty instances change.
Implementations§
Source§impl<T: Pod> InstanceBuffer<T>
impl<T: Pod> InstanceBuffer<T>
Sourcepub fn new(device: &Device, label: Option<&str>, capacity: usize) -> Self
pub fn new(device: &Device, label: Option<&str>, capacity: usize) -> Self
Create a new instance buffer with the specified capacity.
Sourcepub fn set_instances(&mut self, device: &Device, instances: Vec<T>)
pub fn set_instances(&mut self, device: &Device, instances: Vec<T>)
Set instances, replacing all existing data.
Marks the entire buffer as dirty for GPU upload. Reallocates GPU buffer if capacity is exceeded.
Sourcepub fn update_range(&mut self, start: usize, new_data: &[T])
pub fn update_range(&mut self, start: usize, new_data: &[T])
Update a specific range of instances.
Replaces instances[start..end] with the provided data. Marks the range as dirty for GPU upload.
Sourcepub fn update_instance(&mut self, index: usize, instance: T)
pub fn update_instance(&mut self, index: usize, instance: T)
Update a single instance.
Sourcepub fn append(&mut self, device: &Device, new_instances: &[T])
pub fn append(&mut self, device: &Device, new_instances: &[T])
Append instances to the buffer.
Reallocates if capacity is exceeded.
Sourcepub fn upload_dirty(&mut self, queue: &Queue)
pub fn upload_dirty(&mut self, queue: &Queue)
Upload all dirty ranges to the GPU.
This performs partial buffer writes for each dirty range, minimizing GPU bandwidth usage for retained rendering.
Sourcepub fn upload_all(&mut self, queue: &Queue)
pub fn upload_all(&mut self, queue: &Queue)
Force upload of the entire buffer, ignoring dirty tracking.
Sourcepub fn dirty_ranges(&self) -> &DirtyRanges
pub fn dirty_ranges(&self) -> &DirtyRanges
Get dirty ranges for inspection.
Sourcepub fn write_count(&self) -> u64
pub fn write_count(&self) -> u64
Get write statistics.
Sourcepub fn stats(&self) -> InstanceBufferStats
pub fn stats(&self) -> InstanceBufferStats
Get buffer statistics.
Auto Trait Implementations§
impl<T> Freeze for InstanceBuffer<T>
impl<T> !RefUnwindSafe for InstanceBuffer<T>
impl<T> Send for InstanceBuffer<T>where
T: Send,
impl<T> Sync for InstanceBuffer<T>where
T: Sync,
impl<T> Unpin for InstanceBuffer<T>where
T: Unpin,
impl<T> UnsafeUnpin for InstanceBuffer<T>
impl<T> !UnwindSafe for InstanceBuffer<T>
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 more