Skip to content

Commit

Permalink
Fix staging buffer required size calculation (fixes bevyengine#1056)
Browse files Browse the repository at this point in the history
The required staging buffer size is already properly calculated in
prepare_staging_buffers(). Whenever a resize was needed, this value
got overwritten by set_required_staging_buffer_size_to_max(), which
computed the wrong (smaller) size. This in turn prevented the staging
buffers from being resized in resize_staging_buffer().

By removing set_required_staging_buffer_size_to_max() entiery, the value
from prepare_staging_buffers() is used.
  • Loading branch information
rmsc committed Feb 23, 2021
1 parent bc4fe9b commit 4623bd3
Showing 1 changed file with 0 additions and 17 deletions.
17 changes: 0 additions & 17 deletions crates/bevy_render/src/render_graph/nodes/render_resources_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,17 +208,6 @@ where
resized
}

fn set_required_staging_buffer_size_to_max(&mut self) {
let mut new_size = 0;
for buffer_array in self.buffer_arrays.iter() {
if let Some(buffer_array) = buffer_array {
new_size += buffer_array.item_size * buffer_array.len;
}
}

self.required_staging_buffer_size = new_size;
}

/// Update the staging buffer to provide enough space to copy data to target buffers.
fn resize_staging_buffer(&mut self, render_resource_context: &dyn RenderResourceContext) {
// TODO: allow staging buffer to scale down
Expand Down Expand Up @@ -484,9 +473,6 @@ fn render_resources_node_system<T: RenderResources>(
}

let resized = uniform_buffer_arrays.resize_buffer_arrays(render_resource_context);
if resized {
uniform_buffer_arrays.set_required_staging_buffer_size_to_max()
}
uniform_buffer_arrays.resize_staging_buffer(render_resource_context);

if let Some(staging_buffer) = state.uniform_buffer_arrays.staging_buffer {
Expand Down Expand Up @@ -697,9 +683,6 @@ fn asset_render_resources_node_system<T: RenderResources + Asset>(
}

let resized = uniform_buffer_arrays.resize_buffer_arrays(render_resource_context);
if resized {
uniform_buffer_arrays.set_required_staging_buffer_size_to_max()
}
uniform_buffer_arrays.resize_staging_buffer(render_resource_context);

if let Some(staging_buffer) = state.uniform_buffer_arrays.staging_buffer {
Expand Down

0 comments on commit 4623bd3

Please sign in to comment.