Skip to content

Commit

Permalink
Skip batching for phase items from other pipelines (bevyengine#14296)
Browse files Browse the repository at this point in the history
# Objective

- Fix bevyengine#14295

## Solution

- Early out when `GFBD::get_index_and_compare_data` returns None.

## Testing

- Tested on a selection of examples including `many_foxes` and
`3d_shapes`.
- Resolved the original issue in `bevy_vector_shapes`.
  • Loading branch information
james-j-obrien authored Aug 2, 2024
1 parent 56c9d44 commit b98d15f
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions crates/bevy_render/src/batching/gpu_preprocessing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,12 +426,17 @@ pub fn batch_and_prepare_sorted_render_phase<I, GFBD>(
// Unpack that index and metadata. Note that it's possible for index
// and/or metadata to not be present, which signifies that this
// entity is unbatchable. In that case, we break the batch here.
let (mut current_input_index, mut current_meta) = (None, None);
if let Some((input_index, maybe_meta)) = current_batch_input_index {
current_input_index = Some(input_index);
current_meta =
maybe_meta.map(|meta| BatchMeta::new(&phase.items[current_index], meta));
}
// If the index isn't present the item is not part of this pipeline and so will be skipped.
let Some((current_input_index, current_meta)) = current_batch_input_index else {
// Break a batch if we need to.
if let Some(batch) = batch.take() {
batch.flush(data_buffer.len() as u32, phase);
}

continue;
};
let current_meta =
current_meta.map(|meta| BatchMeta::new(&phase.items[current_index], meta));

// Determine if this entity can be included in the batch we're
// building up.
Expand Down Expand Up @@ -475,10 +480,9 @@ pub fn batch_and_prepare_sorted_render_phase<I, GFBD>(

// Add a new preprocessing work item so that the preprocessing
// shader will copy the per-instance data over.
if let (Some(batch), Some(input_index)) = (batch.as_ref(), current_input_index.as_ref())
{
if let Some(batch) = batch.as_ref() {
work_item_buffer.buffer.push(PreprocessWorkItem {
input_index: (*input_index).into(),
input_index: current_input_index.into(),
output_index: match batch.indirect_parameters_index {
Some(indirect_parameters_index) => indirect_parameters_index.into(),
None => output_index,
Expand Down

0 comments on commit b98d15f

Please sign in to comment.