Skip to content

Fix the ordering of the systems introduced in #18734. #18825

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

Merged
Merged
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion crates/bevy_pbr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,14 @@ impl Plugin for PbrPlugin {

// Extract the required data from the main world
render_app
.add_systems(ExtractSchedule, (extract_clusters, extract_lights))
.add_systems(
ExtractSchedule,
(
extract_clusters,
extract_lights,
late_sweep_material_instances,
),
)
.add_systems(
Render,
(
Expand Down
20 changes: 11 additions & 9 deletions crates/bevy_pbr/src/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,10 @@ where
.add_systems(
ExtractSchedule,
(
(
extract_mesh_materials::<M>,
early_sweep_material_instances::<M>,
)
.chain()
.before(late_sweep_material_instances)
.before(ExtractMeshesSet),
extract_mesh_materials::<M>.in_set(ExtractMaterialsSet),
early_sweep_material_instances::<M>
.after(ExtractMaterialsSet)
.before(late_sweep_material_instances),
extract_entities_needs_specialization::<M>.after(extract_cameras),
),
)
Expand Down Expand Up @@ -415,7 +412,8 @@ where
///
/// See the comments in [`RenderMaterialInstances::mesh_material`] for more
/// information.
static DUMMY_MESH_MATERIAL: AssetId<StandardMaterial> = AssetId::<StandardMaterial>::invalid();
pub(crate) static DUMMY_MESH_MATERIAL: AssetId<StandardMaterial> =
AssetId::<StandardMaterial>::invalid();

/// A key uniquely identifying a specialized [`MaterialPipeline`].
pub struct MaterialPipelineKey<M: Material> {
Expand Down Expand Up @@ -637,6 +635,10 @@ pub struct RenderMaterialInstance {
last_change_tick: Tick,
}

/// A [`SystemSet`] that contains all `extract_mesh_materials` systems.
#[derive(SystemSet, Clone, PartialEq, Eq, Debug, Hash)]
pub struct ExtractMaterialsSet;

pub const fn alpha_mode_pipeline_key(alpha_mode: AlphaMode, msaa: &Msaa) -> MeshPipelineKey {
match alpha_mode {
// Premultiplied and Add share the same pipeline key
Expand Down Expand Up @@ -782,7 +784,7 @@ fn early_sweep_material_instances<M>(
/// This runs after all invocations of [`early_sweep_material_instances`] and is
/// responsible for bumping [`RenderMaterialInstances::current_change_tick`] in
/// preparation for a new frame.
fn late_sweep_material_instances(
pub(crate) fn late_sweep_material_instances(
mut material_instances: ResMut<RenderMaterialInstances>,
mut removed_visibilities_query: Extract<RemovedComponents<ViewVisibility>>,
) {
Expand Down
27 changes: 13 additions & 14 deletions crates/bevy_pbr/src/meshlet/instance_manager.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use super::{meshlet_mesh_manager::MeshletMeshManager, MeshletMesh, MeshletMesh3d};
use crate::{
Material, MaterialBindingId, MeshFlags, MeshTransforms, MeshUniform, NotShadowCaster,
NotShadowReceiver, PreviousGlobalTransform, RenderMaterialBindings, RenderMaterialInstances,
StandardMaterial,
material::DUMMY_MESH_MATERIAL, Material, MaterialBindingId, MeshFlags, MeshTransforms,
MeshUniform, NotShadowCaster, NotShadowReceiver, PreviousGlobalTransform,
RenderMaterialBindings, RenderMaterialInstances,
};
use bevy_asset::{AssetEvent, AssetId, AssetServer, Assets, UntypedAssetId};
use bevy_asset::{AssetEvent, AssetServer, Assets, UntypedAssetId};
use bevy_ecs::{
entity::{Entities, Entity, EntityHashMap},
event::EventReader,
Expand Down Expand Up @@ -113,16 +113,15 @@ impl InstanceManager {
};

let mesh_material = mesh_material_ids.mesh_material(instance);
let mesh_material_binding_id =
if mesh_material != AssetId::<StandardMaterial>::invalid().untyped() {
render_material_bindings
.get(&mesh_material)
.cloned()
.unwrap_or_default()
} else {
// Use a dummy binding ID if the mesh has no material
MaterialBindingId::default()
};
let mesh_material_binding_id = if mesh_material != DUMMY_MESH_MATERIAL.untyped() {
render_material_bindings
.get(&mesh_material)
.cloned()
.unwrap_or_default()
} else {
// Use a dummy binding ID if the mesh has no material
MaterialBindingId::default()
};

let mesh_uniform = MeshUniform::new(
&transforms,
Expand Down
27 changes: 14 additions & 13 deletions crates/bevy_pbr/src/render/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ impl Plugin for MeshRenderPlugin {
.init_resource::<RenderMaterialInstances>()
.configure_sets(
ExtractSchedule,
ExtractMeshesSet.after(view::extract_visibility_ranges),
ExtractMeshesSet
.after(view::extract_visibility_ranges)
.after(late_sweep_material_instances),
)
.add_systems(
ExtractSchedule,
Expand Down Expand Up @@ -1131,19 +1133,18 @@ impl RenderMeshInstanceGpuBuilder {
// yet loaded. In that case, add the mesh to
// `meshes_to_reextract_next_frame` and bail.
let mesh_material = mesh_material_ids.mesh_material(entity);
let mesh_material_binding_id =
if mesh_material != AssetId::<StandardMaterial>::invalid().untyped() {
match render_material_bindings.get(&mesh_material) {
Some(binding_id) => *binding_id,
None => {
meshes_to_reextract_next_frame.insert(entity);
return None;
}
let mesh_material_binding_id = if mesh_material != DUMMY_MESH_MATERIAL.untyped() {
match render_material_bindings.get(&mesh_material) {
Some(binding_id) => *binding_id,
None => {
meshes_to_reextract_next_frame.insert(entity);
return None;
}
} else {
// Use a dummy material binding ID.
MaterialBindingId::default()
};
}
} else {
// Use a dummy material binding ID.
MaterialBindingId::default()
};
self.shared.material_bindings_index = mesh_material_binding_id;

let lightmap_slot = match render_lightmaps.render_lightmaps.get(&entity) {
Expand Down