Fix unecessary specialization checks for apps with many materials (#18410)

# Objective

For materials that aren't being used or a visible entity doesn't have an
instance of, we were unnecessarily constantly checking whether they
needed specialization, saying yes (because the material had never been
specialized for that entity), and failing to look up the material
instance.

## Solution

If an entity doesn't have an instance of the material, it can't possibly
need specialization, so exit early before spending time doing the check.

Fixes #18388.
This commit is contained in:
charlotte 2025-03-18 23:22:39 -07:00 committed by François Mockers
parent 42b74874e4
commit 48fc396f04
4 changed files with 15 additions and 18 deletions

View File

@ -863,6 +863,9 @@ pub fn specialize_material_meshes<M: Material>(
.or_default();
for (_, visible_entity) in visible_entities.iter::<Mesh3d>() {
let Some(material_asset_id) = render_material_instances.get(visible_entity) else {
continue;
};
let entity_tick = entity_specialization_ticks.get(visible_entity).unwrap();
let last_specialized_tick = view_specialized_material_pipeline_cache
.get(visible_entity)
@ -874,9 +877,6 @@ pub fn specialize_material_meshes<M: Material>(
if !needs_specialization {
continue;
}
let Some(material_asset_id) = render_material_instances.get(visible_entity) else {
continue;
};
let Some(mesh_instance) = render_mesh_instances.render_mesh_queue_data(*visible_entity)
else {
continue;

View File

@ -962,6 +962,9 @@ pub fn specialize_prepass_material_meshes<M>(
.or_default();
for (_, visible_entity) in visible_entities.iter::<Mesh3d>() {
let Some(material_asset_id) = render_material_instances.get(visible_entity) else {
continue;
};
let entity_tick = entity_specialization_ticks.get(visible_entity).unwrap();
let last_specialized_tick = view_specialized_material_pipeline_cache
.get(visible_entity)
@ -973,10 +976,6 @@ pub fn specialize_prepass_material_meshes<M>(
if !needs_specialization {
continue;
}
let Some(material_asset_id) = render_material_instances.get(visible_entity) else {
continue;
};
let Some(mesh_instance) = render_mesh_instances.render_mesh_queue_data(*visible_entity)
else {
continue;

View File

@ -1809,6 +1809,9 @@ pub fn specialize_shadows<M: Material>(
.or_default();
for (_, visible_entity) in visible_entities.iter().copied() {
let Some(material_asset_id) = render_material_instances.get(&visible_entity) else {
continue;
};
let entity_tick = entity_specialization_ticks.get(&visible_entity).unwrap();
let last_specialized_tick = view_specialized_material_pipeline_cache
.get(&visible_entity)
@ -1820,7 +1823,9 @@ pub fn specialize_shadows<M: Material>(
if !needs_specialization {
continue;
}
let Some(material) = render_materials.get(*material_asset_id) else {
continue;
};
let Some(mesh_instance) =
render_mesh_instances.render_mesh_queue_data(visible_entity)
else {
@ -1832,12 +1837,6 @@ pub fn specialize_shadows<M: Material>(
{
continue;
}
let Some(material_asset_id) = render_material_instances.get(&visible_entity) else {
continue;
};
let Some(material) = render_materials.get(*material_asset_id) else {
continue;
};
let Some(material_bind_group) =
material_bind_group_allocator.get(material.binding.group)
else {

View File

@ -698,6 +698,9 @@ pub fn specialize_material2d_meshes<M: Material2d>(
.or_default();
for (_, visible_entity) in visible_entities.iter::<Mesh2d>() {
let Some(material_asset_id) = render_material_instances.get(visible_entity) else {
continue;
};
let entity_tick = entity_specialization_ticks.get(visible_entity).unwrap();
let last_specialized_tick = view_specialized_material_pipeline_cache
.get(visible_entity)
@ -709,10 +712,6 @@ pub fn specialize_material2d_meshes<M: Material2d>(
if !needs_specialization {
continue;
}
let Some(material_asset_id) = render_material_instances.get(visible_entity) else {
continue;
};
let Some(mesh_instance) = render_mesh_instances.get_mut(visible_entity) else {
continue;
};