@@ -154,9 +154,11 @@ impl<T: NoUninit> RawBufferVec<T> {
154154 /// the `RawBufferVec` was created, the buffer on the [`RenderDevice`]
155155 /// is marked as [`BufferUsages::COPY_DST`](BufferUsages).
156156 pub fn reserve ( & mut self , capacity : usize , device : & RenderDevice ) {
157- let size = self . item_size * capacity;
158- if capacity > self . capacity || ( self . changed && size > 0 ) {
159- self . capacity = capacity;
157+ if capacity > self . capacity || ( self . changed && capacity > 0 ) {
158+ if capacity > self . capacity {
159+ self . capacity = capacity. max ( self . capacity * 2 ) ;
160+ }
161+ let size = self . item_size * self . capacity ;
160162 self . buffer = Some ( device. create_buffer ( & wgpu:: BufferDescriptor {
161163 label : make_buffer_label :: < Self > ( & self . label ) ,
162164 size : size as BufferAddress ,
@@ -383,9 +385,11 @@ where
383385 /// the `AtomicRawBufferVec` was created, the buffer on the [`RenderDevice`]
384386 /// is marked as [`BufferUsages::COPY_DST`](BufferUsages).
385387 pub fn reserve ( & mut self , capacity : usize , device : & RenderDevice ) {
386- let size = size_of :: < T :: Blob > ( ) * capacity;
387- if capacity > self . capacity || ( self . changed && size > 0 ) {
388- self . capacity = capacity;
388+ if capacity > self . capacity || ( self . changed && capacity > 0 ) {
389+ if capacity > self . capacity {
390+ self . capacity = capacity. max ( self . capacity * 2 ) ;
391+ }
392+ let size = size_of :: < T :: Blob > ( ) * self . capacity ;
389393 self . buffer = Some ( device. create_buffer ( & wgpu:: BufferDescriptor {
390394 label : make_buffer_label :: < Self > ( & self . label ) ,
391395 size : size as BufferAddress ,
@@ -609,8 +613,9 @@ where
609613 if capacity <= self . capacity && !self . label_changed {
610614 return ;
611615 }
612-
613- self . capacity = capacity;
616+ if capacity > self . capacity {
617+ self . capacity = capacity. max ( self . capacity * 2 ) ;
618+ }
614619 let size = u64:: from ( T :: min_size ( ) ) as usize * capacity;
615620 self . buffer = Some ( device. create_buffer ( & wgpu:: BufferDescriptor {
616621 label : make_buffer_label :: < Self > ( & self . label ) ,
@@ -793,8 +798,9 @@ where
793798 if capacity <= self . capacity && !self . label_changed {
794799 return ;
795800 }
796-
797- self . capacity = capacity;
801+ if capacity > self . capacity {
802+ self . capacity = capacity. max ( self . capacity * 2 ) ;
803+ }
798804 let size = self . item_size * capacity;
799805 self . buffer = Some ( device. create_buffer ( & wgpu:: BufferDescriptor {
800806 label : make_buffer_label :: < Self > ( & self . label ) ,
@@ -883,9 +889,8 @@ where
883889 if capacity <= self . capacity {
884890 return ;
885891 }
886-
887- let size = size_of :: < T > ( ) * capacity;
888- self . capacity = capacity;
892+ self . capacity = capacity. max ( self . capacity * 2 ) ;
893+ let size = size_of :: < T > ( ) * self . capacity ;
889894 self . buffer = Some ( render_device. create_buffer ( & wgpu:: BufferDescriptor {
890895 label : Some ( & self . label ) ,
891896 size : size as u64 ,
0 commit comments