assets should be kept on CPU by default (#11212)

# Objective

- Since #10520, assets are unloaded from RAM by default. This breaks a
number of scenario:
  - using `load_folder`
- loading a gltf, then going through its mesh to transform them /
compute a collider / ...
- any assets/subassets scenario should be `Keep` as you can't know what
the user will do with the assets
  - android suspension, where GPU memory is unloaded

- Alternative to #11202 

## Solution

- Keep assets on CPU memory by default
This commit is contained in:
François 2024-01-05 06:53:47 +01:00 committed by GitHub
parent 759b3985d8
commit 425570aa75
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 17 additions and 17 deletions

View file

@ -390,7 +390,7 @@ async fn load_gltf<'a, 'b, 'c>(
let primitive_label = primitive_label(&gltf_mesh, &primitive);
let primitive_topology = get_primitive_topology(primitive.mode())?;
let mut mesh = Mesh::new(primitive_topology, RenderAssetPersistencePolicy::Unload);
let mut mesh = Mesh::new(primitive_topology, RenderAssetPersistencePolicy::Keep);
// Read vertex attributes
for (semantic, accessor) in primitive.attributes() {
@ -434,7 +434,7 @@ async fn load_gltf<'a, 'b, 'c>(
let morph_target_image = MorphTargetImage::new(
morph_target_reader.map(PrimitiveMorphAttributesIter),
mesh.count_vertices(),
RenderAssetPersistencePolicy::Unload,
RenderAssetPersistencePolicy::Keep,
)?;
let handle =
load_context.add_labeled_asset(morph_targets_label, morph_target_image.0);
@ -726,7 +726,7 @@ async fn load_image<'a, 'b>(
supported_compressed_formats,
is_srgb,
ImageSampler::Descriptor(sampler_descriptor),
RenderAssetPersistencePolicy::Unload,
RenderAssetPersistencePolicy::Keep,
)?;
Ok(ImageOrPath::Image {
image,
@ -748,7 +748,7 @@ async fn load_image<'a, 'b>(
supported_compressed_formats,
is_srgb,
ImageSampler::Descriptor(sampler_descriptor),
RenderAssetPersistencePolicy::Unload,
RenderAssetPersistencePolicy::Keep,
)?,
label: texture_label(&gltf_texture),
})

View file

@ -369,7 +369,7 @@ impl From<Capsule> for Mesh {
Mesh::new(
PrimitiveTopology::TriangleList,
RenderAssetPersistencePolicy::Unload,
RenderAssetPersistencePolicy::Keep,
)
.with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, vs)
.with_inserted_attribute(Mesh::ATTRIBUTE_NORMAL, vns)

View file

@ -123,7 +123,7 @@ impl From<Cylinder> for Mesh {
Mesh::new(
PrimitiveTopology::TriangleList,
RenderAssetPersistencePolicy::Unload,
RenderAssetPersistencePolicy::Keep,
)
.with_indices(Some(Indices::U32(indices)))
.with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, positions)

View file

@ -108,7 +108,7 @@ impl TryFrom<Icosphere> for Mesh {
Ok(Mesh::new(
PrimitiveTopology::TriangleList,
RenderAssetPersistencePolicy::Unload,
RenderAssetPersistencePolicy::Keep,
)
.with_indices(Some(indices))
.with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, points)

View file

@ -124,7 +124,7 @@ impl From<Box> for Mesh {
Mesh::new(
PrimitiveTopology::TriangleList,
RenderAssetPersistencePolicy::Unload,
RenderAssetPersistencePolicy::Keep,
)
.with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, positions)
.with_inserted_attribute(Mesh::ATTRIBUTE_NORMAL, normals)
@ -179,7 +179,7 @@ impl From<Quad> for Mesh {
Mesh::new(
PrimitiveTopology::TriangleList,
RenderAssetPersistencePolicy::Unload,
RenderAssetPersistencePolicy::Keep,
)
.with_indices(Some(indices))
.with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, positions)
@ -263,7 +263,7 @@ impl From<Plane> for Mesh {
Mesh::new(
PrimitiveTopology::TriangleList,
RenderAssetPersistencePolicy::Unload,
RenderAssetPersistencePolicy::Keep,
)
.with_indices(Some(Indices::U32(indices)))
.with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, positions)

View file

@ -60,7 +60,7 @@ impl From<RegularPolygon> for Mesh {
Mesh::new(
PrimitiveTopology::TriangleList,
RenderAssetPersistencePolicy::Unload,
RenderAssetPersistencePolicy::Keep,
)
.with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, positions)
.with_inserted_attribute(Mesh::ATTRIBUTE_NORMAL, normals)

View file

@ -89,7 +89,7 @@ impl From<Torus> for Mesh {
Mesh::new(
PrimitiveTopology::TriangleList,
RenderAssetPersistencePolicy::Unload,
RenderAssetPersistencePolicy::Keep,
)
.with_indices(Some(Indices::U32(indices)))
.with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, positions)

View file

@ -85,7 +85,7 @@ impl From<UVSphere> for Mesh {
Mesh::new(
PrimitiveTopology::TriangleList,
RenderAssetPersistencePolicy::Unload,
RenderAssetPersistencePolicy::Keep,
)
.with_indices(Some(Indices::U32(indices)))
.with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, vertices)

View file

@ -55,8 +55,8 @@ pub trait RenderAsset: Asset + Clone {
/// or only need very infrequent access, then set this to Unload. Otherwise, set this to Keep.
#[derive(Reflect, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default, Debug)]
pub enum RenderAssetPersistencePolicy {
#[default]
Unload,
#[default]
Keep,
}

View file

@ -467,7 +467,7 @@ impl Default for Image {
},
sampler: ImageSampler::Default,
texture_view_descriptor: None,
cpu_persistent_access: RenderAssetPersistencePolicy::Unload,
cpu_persistent_access: RenderAssetPersistencePolicy::Keep,
}
}
}

View file

@ -67,7 +67,7 @@ impl Default for ImageLoaderSettings {
format: ImageFormatSetting::default(),
is_srgb: true,
sampler: ImageSampler::Default,
cpu_persistent_access: RenderAssetPersistencePolicy::Unload,
cpu_persistent_access: RenderAssetPersistencePolicy::Keep,
}
}
}

View file

@ -209,7 +209,7 @@ impl TextureAtlasBuilder {
self.format.pixel_size() * (current_width * current_height) as usize
],
self.format,
RenderAssetPersistencePolicy::Unload,
RenderAssetPersistencePolicy::Keep,
);
Some(rect_placements)
}