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

a lot of new buffers created all the time after #599 #764

Closed
mrk-its opened this issue Nov 1, 2020 · 2 comments · Fixed by #768
Closed

a lot of new buffers created all the time after #599 #764

mrk-its opened this issue Nov 1, 2020 · 2 comments · Fixed by #768
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior C-Performance A change motivated by improving speed, memory usage or compile times

Comments

@mrk-its
Copy link
Member

mrk-its commented Nov 1, 2020

Bevy version
current master (4645da3 or later)

Operating system & version
Ubuntu 20.04

What you did

Apply this patch to print a line on stdout when new buffer is created:

diff --git a/crates/bevy_wgpu/src/renderer/wgpu_render_resource_context.rs b/crates/bevy_wgpu/src/renderer/wgpu_render_resource_context.rs
index ab5048da..2e3df8e6 100644
--- a/crates/bevy_wgpu/src/renderer/wgpu_render_resource_context.rs
+++ b/crates/bevy_wgpu/src/renderer/wgpu_render_resource_context.rs
@@ -185,6 +185,7 @@ impl RenderResourceContext for WgpuRenderResourceContext {
     }
 
     fn create_buffer(&self, buffer_info: BufferInfo) -> BufferId {
+        println!("create_buffer");
         // TODO: consider moving this below "create" for efficiency
         let mut buffer_infos = self.resources.buffer_infos.write();
         let mut buffers = self.resources.buffers.write();
@@ -203,6 +204,7 @@ impl RenderResourceContext for WgpuRenderResourceContext {
     }
 
     fn create_buffer_with_data(&self, mut buffer_info: BufferInfo, data: &[u8]) -> BufferId {
+        println!("create_buffer_with_data");
         // TODO: consider moving this below "create" for efficiency
         let mut buffer_infos = self.resources.buffer_infos.write();
         let mut buffers = self.resources.buffers.write();

and run

cargo run --example sprite

What you expected to happen

there should be constant number of buffers allocated

What actually happened

New buffers are created all the time (for sprite example it is like ~3 new buffers per frame)

Additional information

This behavior was introduced in #599 (4645da3)

@mrk-its mrk-its added the C-Bug An unexpected or incorrect behavior label Nov 1, 2020
@mrk-its
Copy link
Member Author

mrk-its commented Nov 1, 2020

@julhe could you take a look?

@karroffel karroffel added C-Performance A change motivated by improving speed, memory usage or compile times A-Rendering Drawing game state to the screen labels Nov 1, 2020
@julhe
Copy link
Contributor

julhe commented Nov 2, 2020

Okay, this seems because I made this a ResMut<>

mut meshes: ResMut<Assets<Mesh>>,

This causes

AssetEvent::Modified { ref handle } => {
changed_meshes.insert(handle.clone_weak());
remove_current_mesh_resources(render_resource_context, handle);
}

to be triggered every frame, finally leading to the constant buffer recreation.

Problem is that I need to have the Mesh mutable, to set

mesh.attribute_buffer_descriptor_reference = Some(interleaved_buffer.1);

So the only option I see is to store attribute_buffer_descriptor_reference outside of Mesh, so we can go back to Res<>.

But where? 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior C-Performance A change motivated by improving speed, memory usage or compile times
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants