bevy/crates/bevy_pbr/src
charlotte 2ea5e9b846
Cold Specialization (#17567)
# Cold Specialization

## Objective

An ongoing part of our quest to retain everything in the render world,
cold-specialization aims to cache pipeline specialization so that
pipeline IDs can be recomputed only when necessary, rather than every
frame. This approach reduces redundant work in stable scenes, while
still accommodating scenarios in which materials, views, or visibility
might change, as well as unlocking future optimization work like
retaining render bins.

## Solution

Queue systems are split into a specialization system and queue system,
the former of which only runs when necessary to compute a new pipeline
id. Pipelines are invalidated using a combination of change detection
and ECS ticks.

### The difficulty with change detection

Detecting “what changed” can be tricky because pipeline specialization
depends not only on the entity’s components (e.g., mesh, material, etc.)
but also on which view (camera) it is rendering in. In other words, the
cache key for a given pipeline id is a view entity/render entity pair.
As such, it's not sufficient simply to react to change detection in
order to specialize -- an entity could currently be out of view or could
be rendered in the future in camera that is currently disabled or hasn't
spawned yet.

### Why ticks?

Ticks allow us to ensure correctness by allowing us to compare the last
time a view or entity was updated compared to the cached pipeline id.
This ensures that even if an entity was out of view or has never been
seen in a given camera before we can still correctly determine whether
it needs to be re-specialized or not.

## Testing

TODO: Tested a bunch of different examples, need to test more.

## Migration Guide

TODO

- `AssetEvents` has been moved into the `PostUpdate` schedule.

---------

Co-authored-by: Patrick Walton <pcwalton@mimiga.net>
2025-02-05 18:31:20 +00:00
..
atmosphere Atmosphere LUT parameterization improvements (#17555) 2025-02-03 21:52:11 +00:00
cluster Disable clustered decals on Metal. (#17554) 2025-01-27 05:39:07 +00:00
decal Disable clustered decals on Metal. (#17554) 2025-01-27 05:39:07 +00:00
deferred Add support for specular tints and maps per the KHR_materials_specular glTF extension. (#14069) 2025-01-26 20:38:46 +00:00
light Make the default directional light shadow cascade settings similar to those of other engines. (#17552) 2025-01-27 01:48:57 +00:00
light_probe Implement basic clustered decal projectors. (#17315) 2025-01-26 20:13:39 +00:00
lightmap Move hashbrown and foldhash out of bevy_utils (#17460) 2025-01-23 16:46:08 +00:00
meshlet Implement experimental GPU two-phase occlusion culling for the standard 3D mesh pipeline. (#17413) 2025-01-27 05:02:46 +00:00
prepass Cold Specialization (#17567) 2025-02-05 18:31:20 +00:00
render Cold Specialization (#17567) 2025-02-05 18:31:20 +00:00
ssao Procedural atmospheric scattering (#16314) 2025-01-23 22:52:46 +00:00
ssr Move Resource trait to its own file (#17469) 2025-01-21 19:47:08 +00:00
volumetric_fog Move Resource trait to its own file (#17469) 2025-01-21 19:47:08 +00:00
components.rs Support non-Vec data structures in relations (#17447) 2025-01-20 21:26:08 +00:00
extended_material.rs Forward decals (port of bevy_contact_projective_decals) (#16600) 2025-01-15 02:31:30 +00:00
fog.rs Remove all deprecated code (#16338) 2025-01-05 20:33:39 +00:00
lib.rs Implement experimental GPU two-phase occlusion culling for the standard 3D mesh pipeline. (#17413) 2025-01-27 05:02:46 +00:00
material_bind_groups.rs Move hashbrown and foldhash out of bevy_utils (#17460) 2025-01-23 16:46:08 +00:00
material.rs Cold Specialization (#17567) 2025-02-05 18:31:20 +00:00
mesh_material.rs Cold Specialization (#17567) 2025-02-05 18:31:20 +00:00
parallax.rs bevy_reflect: FromReflect Ergonomics Implementation (#6056) 2023-06-29 01:31:34 +00:00
pbr_material.rs Add support for specular tints and maps per the KHR_materials_specular glTF extension. (#14069) 2025-01-26 20:38:46 +00:00
wireframe.rs Reflect and register the wireframe materials (#17334) 2025-01-28 05:19:34 +00:00