Skip to content

Commit

Permalink
Add AssetChanged query filter (#16810)
Browse files Browse the repository at this point in the history
# Objective

Implement a new `AssetChanged` query filter that allows users to query
for entities whose related assets may have changed.

- Closes #5069
- Unblocks #16420. Currently, `cold-specialization`, a key rendering
optimization for unlocking ancillary benefits of the retained render
world, is blocked on being unable detect all scenarios in which an
entity's mesh/material changes using events and observers. An
`AssetChanged` filter will drastically simplify our implementation and
be more robust to future changes.

Originally implemented by @nicopap in #5080.

## Solution

- Adds a new `AssetChanged` query filter that initializes a
`AssetChanges<A>` resource that tracks changed assets and ticks in
`asset_events`.
- ~Reverts #13343 and changes the api of `get_state` to accept `impl
Into<UnsafeWorldCell<'w>>` to allow accessing the `AssetChanges<A>`
resource.~
- Adds a `AsAssetId` trait used for newtype handle wrappers (e.g.
`Mesh3d`) that allows associating a component with the underlying
`Asset` it represents.

## Testing

- Tests are added for `AssetChanged`.
- TBD on performance. We are going to add this `Mesh3d` and
`MeshMaterial3d` (etc) in the renderer. Long term wins in render
performance this unblocks should swamp tracking overhead for any
realistic workload.

## Migration Guide

- The `asset_events` system is no longer public. Users should order
their systems relative to the `AssetEvents` system set.

---------

Co-authored-by: Nicola Papale <[email protected]>
Co-authored-by: Patrick Walton <[email protected]>
Co-authored-by: Alice Cecile <[email protected]>
Co-authored-by: Chris Russell <[email protected]>
  • Loading branch information
5 people authored Dec 17, 2024
1 parent cc0f6a8 commit df14443
Show file tree
Hide file tree
Showing 3 changed files with 515 additions and 3 deletions.
Loading

0 comments on commit df14443

Please sign in to comment.