Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid realloc memory across frame in GpuArrayBuffer #11290

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions crates/bevy_render/src/render_resource/gpu_array_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
use bevy_ecs::{prelude::Component, system::Resource};
use bevy_utils::nonmax::NonMaxU32;
use encase::{private::WriteInto, ShaderSize, ShaderType};
use std::{marker::PhantomData, mem};
use std::marker::PhantomData;
use wgpu::BindingResource;

/// Trait for types able to go in a [`GpuArrayBuffer`].
Expand Down Expand Up @@ -71,7 +71,9 @@ impl<T: GpuArrayBufferable> GpuArrayBuffer<T> {
match self {
GpuArrayBuffer::Uniform(buffer) => buffer.write_buffer(device, queue),
GpuArrayBuffer::Storage((buffer, vec)) => {
buffer.set(mem::take(vec));
std::mem::swap(vec, buffer.get_mut());
// TODO: shrink vector size to save memory when it's not needed
vec.clear();
buffer.write_buffer(device, queue);
}
}
Expand Down