Skip batching for phase items from other pipelines (#14296)

# Objective

- Fix #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`.
This commit is contained in:
James O'Brien 2024-08-01 17:15:42 -07:00 committed by François
parent d8886408bf
commit 833ee3f577
No known key found for this signature in database

View File

@ -425,13 +425,18 @@ pub fn batch_and_prepare_sorted_render_phase<I, GFBD>(
// Unpack that index and metadata. Note that it's possible for index // Unpack that index and metadata. Note that it's possible for index
// and/or metadata to not be present, which signifies that this // and/or metadata to not be present, which signifies that this
// entity is unbatchable. In that case, we break the batch here. // entity is unbatchable. In that case, we break the batch here.
let (mut current_input_index, mut current_meta) = (None, None); // If the index isn't present the item is not part of this pipeline and so will be skipped.
if let Some((input_index, maybe_meta)) = current_batch_input_index { let Some((current_input_index, current_meta)) = current_batch_input_index else {
current_input_index = Some(input_index); // Break a batch if we need to.
current_meta = if let Some(batch) = batch.take() {
maybe_meta.map(|meta| BatchMeta::new(&phase.items[current_index], meta)); 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 // Determine if this entity can be included in the batch we're
// building up. // building up.
let can_batch = batch.as_ref().is_some_and(|batch| { let can_batch = batch.as_ref().is_some_and(|batch| {
@ -474,10 +479,9 @@ pub fn batch_and_prepare_sorted_render_phase<I, GFBD>(
// Add a new preprocessing work item so that the preprocessing // Add a new preprocessing work item so that the preprocessing
// shader will copy the per-instance data over. // 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 { work_item_buffer.buffer.push(PreprocessWorkItem {
input_index: (*input_index).into(), input_index: current_input_index.into(),
output_index: match batch.indirect_parameters_index { output_index: match batch.indirect_parameters_index {
Some(indirect_parameters_index) => indirect_parameters_index.into(), Some(indirect_parameters_index) => indirect_parameters_index.into(),
None => output_index, None => output_index,