bevy/crates
JMS55 44424391fe
Unload render assets from RAM (#10520)
# Objective
- No point in keeping Meshes/Images in RAM once they're going to be sent
to the GPU, and kept in VRAM. This saves a _significant_ amount of
memory (several GBs) on scenes like bistro.
- References
  - https://github.com/bevyengine/bevy/pull/1782
  - https://github.com/bevyengine/bevy/pull/8624 

## Solution
- Augment RenderAsset with the capability to unload the underlying asset
after extracting to the render world.
- Mesh/Image now have a cpu_persistent_access field. If this field is
RenderAssetPersistencePolicy::Unload, the asset will be unloaded from
Assets<T>.
- A new AssetEvent is sent upon dropping the last strong handle for the
asset, which signals to the RenderAsset to remove the GPU version of the
asset.

---

## Changelog
- Added `AssetEvent::NoLongerUsed` and
`AssetEvent::is_no_longer_used()`. This event is sent when the last
strong handle of an asset is dropped.
- Rewrote the API for `RenderAsset` to allow for unloading the asset
data from the CPU.
- Added `RenderAssetPersistencePolicy`.
- Added `Mesh::cpu_persistent_access` for memory savings when the asset
is not needed except for on the GPU.
- Added `Image::cpu_persistent_access` for memory savings when the asset
is not needed except for on the GPU.
- Added `ImageLoaderSettings::cpu_persistent_access`.
- Added `ExrTextureLoaderSettings`.
- Added `HdrTextureLoaderSettings`.

## Migration Guide
- Asset loaders (GLTF, etc) now load meshes and textures without
`cpu_persistent_access`. These assets will be removed from
`Assets<Mesh>` and `Assets<Image>` once `RenderAssets<Mesh>` and
`RenderAssets<Image>` contain the GPU versions of these assets, in order
to reduce memory usage. If you require access to the asset data from the
CPU in future frames after the GLTF asset has been loaded, modify all
dependent `Mesh` and `Image` assets and set `cpu_persistent_access` to
`RenderAssetPersistencePolicy::Keep`.
- `Mesh` now requires a new `cpu_persistent_access` field. Set it to
`RenderAssetPersistencePolicy::Keep` to mimic the previous behavior.
- `Image` now requires a new `cpu_persistent_access` field. Set it to
`RenderAssetPersistencePolicy::Keep` to mimic the previous behavior.
- `MorphTargetImage::new()` now requires a new `cpu_persistent_access`
parameter. Set it to `RenderAssetPersistencePolicy::Keep` to mimic the
previous behavior.
- `DynamicTextureAtlasBuilder::add_texture()` now requires that the
`TextureAtlas` you pass has an `Image` with `cpu_persistent_access:
RenderAssetPersistencePolicy::Keep`. Ensure you construct the image
properly for the texture atlas.
- The `RenderAsset` trait has significantly changed, and requires
adapting your existing implementations.
  - The trait now requires `Clone`.
- The `ExtractedAsset` associated type has been removed (the type itself
is now extracted).
  - The signature of `prepare_asset()` is slightly different
- A new `persistence_policy()` method is now required (return
RenderAssetPersistencePolicy::Unload to match the previous behavior).
- Match on the new `NoLongerUsed` variant for exhaustive matches of
`AssetEvent`.
2024-01-03 03:31:04 +00:00
..
bevy_a11y Add [lints] table, fix adding #![allow(clippy::type_complexity)] everywhere (#10011) 2023-11-18 20:58:48 +00:00
bevy_animation support all types of animation interpolation from gltf (#10755) 2023-12-31 18:01:50 +00:00
bevy_app Replace or document ignored doctests (#11040) 2024-01-01 16:50:56 +00:00
bevy_asset Unload render assets from RAM (#10520) 2024-01-03 03:31:04 +00:00
bevy_audio Reorder impl to be the same as the trait (#11076) 2023-12-24 17:43:55 +00:00
bevy_core Replace or document ignored doctests (#11040) 2024-01-01 16:50:56 +00:00
bevy_core_pipeline Unload render assets from RAM (#10520) 2024-01-03 03:31:04 +00:00
bevy_derive Reexport winit::platform::android::activity::* in bevy_winit (#11011) 2023-12-19 20:15:03 +00:00
bevy_diagnostic Replace or document ignored doctests (#11040) 2024-01-01 16:50:56 +00:00
bevy_dylib Add [lints] table, fix adding #![allow(clippy::type_complexity)] everywhere (#10011) 2023-11-18 20:58:48 +00:00
bevy_dynamic_plugin Add [lints] table, fix adding #![allow(clippy::type_complexity)] everywhere (#10011) 2023-11-18 20:58:48 +00:00
bevy_ecs impl ExclusiveSystemParam for SystemName (#11163) 2024-01-01 17:08:29 +00:00
bevy_ecs_compile_fail_tests Rename WorldQueryData & WorldQueryFilter to QueryData & QueryFilter (#10779) 2023-12-12 19:45:50 +00:00
bevy_encase_derive Add [lints] table, fix adding #![allow(clippy::type_complexity)] everywhere (#10011) 2023-11-18 20:58:48 +00:00
bevy_gilrs Remove unnecessary path prefixes (#10749) 2023-11-28 23:43:40 +00:00
bevy_gizmos Unload render assets from RAM (#10520) 2024-01-03 03:31:04 +00:00
bevy_gltf Unload render assets from RAM (#10520) 2024-01-03 03:31:04 +00:00
bevy_hierarchy Add bevy_hierarchy Crate and plugin documentation (#10951) 2024-01-02 19:40:14 +00:00
bevy_input Add window entity to TouchInput events (#11128) 2024-01-02 03:03:05 +00:00
bevy_internal Remove unnecessary path prefixes (#10749) 2023-11-28 23:43:40 +00:00
bevy_log Print to stderr from panic handler in LogPlugin (#11170) 2024-01-01 17:10:20 +00:00
bevy_macro_utils Replace or document ignored doctests (#11040) 2024-01-01 16:50:56 +00:00
bevy_macros_compile_fail_tests Standardize toml format with taplo (#10594) 2023-11-21 01:04:14 +00:00
bevy_math Add approx feature to bevy_math (#11176) 2024-01-02 18:10:44 +00:00
bevy_mikktspace Replace calculation with function call (#11077) 2023-12-23 17:32:26 +00:00
bevy_pbr Unload render assets from RAM (#10520) 2024-01-03 03:31:04 +00:00
bevy_ptr Simplify equality assertions (#10988) 2023-12-16 23:58:41 +00:00
bevy_reflect Replace or document ignored doctests (#11040) 2024-01-01 16:50:56 +00:00
bevy_reflect_compile_fail_tests Fix nested generics in Reflect derive (#10791) 2023-11-29 01:46:09 +00:00
bevy_render Unload render assets from RAM (#10520) 2024-01-03 03:31:04 +00:00
bevy_scene Rename ArchetypeEntity::entity into ArchetypeEntity::id (#11118) 2024-01-01 16:12:24 +00:00
bevy_sprite Unload render assets from RAM (#10520) 2024-01-03 03:31:04 +00:00
bevy_tasks Replace or document ignored doctests (#11040) 2024-01-01 16:50:56 +00:00
bevy_text Unload render assets from RAM (#10520) 2024-01-03 03:31:04 +00:00
bevy_time Replace or document ignored doctests (#11040) 2024-01-01 16:50:56 +00:00
bevy_transform Add approx feature to bevy_math (#11176) 2024-01-02 18:10:44 +00:00
bevy_ui Unload render assets from RAM (#10520) 2024-01-03 03:31:04 +00:00
bevy_utils Add static assertions to bevy_utils for compile-time checks (#11182) 2024-01-02 22:08:30 +00:00
bevy_window Remove CanvasParentResizePlugin (#11057) 2023-12-21 20:01:22 +00:00
bevy_winit Add window entity to TouchInput events (#11128) 2024-01-02 03:03:05 +00:00