Skip to content

Commit

Permalink
Fix MeshletMesh material system ordering (#14016)
Browse files Browse the repository at this point in the history
# Objective
- Fixes #13811 (probably, I lost my test code...)

## Solution
- Turns out that Queue and PrepareAssets are _not_ ordered. We should
probably either rethink our system sets (again), or improve the
documentation here. For reference, I've included the current ordering
below.
- The `prepare_meshlet_meshes_X` systems need to run after
`prepare_assets::<PreparedMaterial<M>>`, and have also been moved to
QueueMeshes.

```rust
schedule.configure_sets(
    (
        ExtractCommands,
        ManageViews,
        Queue,
        PhaseSort,
        Prepare,
        Render,
        Cleanup,
    )
        .chain(),
);

schedule.configure_sets((ExtractCommands, PrepareAssets, Prepare).chain());
schedule.configure_sets(QueueMeshes.in_set(Queue).after(prepare_assets::<GpuMesh>));
schedule.configure_sets(
    (PrepareResources, PrepareResourcesFlush, PrepareBindGroups)
        .chain()
        .in_set(Prepare),
);
```

## Testing
- Ambiguity checker to make sure I don't have ambiguous system ordering
  • Loading branch information
JMS55 authored and mockersf committed Jun 25, 2024
1 parent 9eb547e commit 65daab8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
18 changes: 12 additions & 6 deletions crates/bevy_pbr/src/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,18 @@ where
#[cfg(feature = "meshlet")]
render_app.add_systems(
Render,
(
prepare_material_meshlet_meshes_main_opaque_pass::<M>,
queue_material_meshlet_meshes::<M>,
)
.chain()
.in_set(RenderSet::Queue)
queue_material_meshlet_meshes::<M>
.in_set(RenderSet::QueueMeshes)
.run_if(resource_exists::<MeshletGpuScene>),
);

#[cfg(feature = "meshlet")]
render_app.add_systems(
Render,
prepare_material_meshlet_meshes_main_opaque_pass::<M>
.in_set(RenderSet::QueueMeshes)
.after(prepare_assets::<PreparedMaterial<M>>)
.before(queue_material_meshlet_meshes::<M>)
.run_if(resource_exists::<MeshletGpuScene>),
);
}
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_pbr/src/prepass/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ where
render_app.add_systems(
Render,
prepare_material_meshlet_meshes_prepass::<M>
.in_set(RenderSet::Queue)
.in_set(RenderSet::QueueMeshes)
.after(prepare_assets::<PreparedMaterial<M>>)
.before(queue_material_meshlet_meshes::<M>)
.run_if(resource_exists::<MeshletGpuScene>),
);
Expand Down

0 comments on commit 65daab8

Please sign in to comment.