Skip to content

Commit 425570a

Browse files
authored
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
1 parent 759b398 commit 425570a

File tree

12 files changed

+17
-17
lines changed

12 files changed

+17
-17
lines changed

crates/bevy_gltf/src/loader.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ async fn load_gltf<'a, 'b, 'c>(
390390
let primitive_label = primitive_label(&gltf_mesh, &primitive);
391391
let primitive_topology = get_primitive_topology(primitive.mode())?;
392392

393-
let mut mesh = Mesh::new(primitive_topology, RenderAssetPersistencePolicy::Unload);
393+
let mut mesh = Mesh::new(primitive_topology, RenderAssetPersistencePolicy::Keep);
394394

395395
// Read vertex attributes
396396
for (semantic, accessor) in primitive.attributes() {
@@ -434,7 +434,7 @@ async fn load_gltf<'a, 'b, 'c>(
434434
let morph_target_image = MorphTargetImage::new(
435435
morph_target_reader.map(PrimitiveMorphAttributesIter),
436436
mesh.count_vertices(),
437-
RenderAssetPersistencePolicy::Unload,
437+
RenderAssetPersistencePolicy::Keep,
438438
)?;
439439
let handle =
440440
load_context.add_labeled_asset(morph_targets_label, morph_target_image.0);
@@ -726,7 +726,7 @@ async fn load_image<'a, 'b>(
726726
supported_compressed_formats,
727727
is_srgb,
728728
ImageSampler::Descriptor(sampler_descriptor),
729-
RenderAssetPersistencePolicy::Unload,
729+
RenderAssetPersistencePolicy::Keep,
730730
)?;
731731
Ok(ImageOrPath::Image {
732732
image,
@@ -748,7 +748,7 @@ async fn load_image<'a, 'b>(
748748
supported_compressed_formats,
749749
is_srgb,
750750
ImageSampler::Descriptor(sampler_descriptor),
751-
RenderAssetPersistencePolicy::Unload,
751+
RenderAssetPersistencePolicy::Keep,
752752
)?,
753753
label: texture_label(&gltf_texture),
754754
})

crates/bevy_render/src/mesh/shape/capsule.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ impl From<Capsule> for Mesh {
369369

370370
Mesh::new(
371371
PrimitiveTopology::TriangleList,
372-
RenderAssetPersistencePolicy::Unload,
372+
RenderAssetPersistencePolicy::Keep,
373373
)
374374
.with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, vs)
375375
.with_inserted_attribute(Mesh::ATTRIBUTE_NORMAL, vns)

crates/bevy_render/src/mesh/shape/cylinder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl From<Cylinder> for Mesh {
123123

124124
Mesh::new(
125125
PrimitiveTopology::TriangleList,
126-
RenderAssetPersistencePolicy::Unload,
126+
RenderAssetPersistencePolicy::Keep,
127127
)
128128
.with_indices(Some(Indices::U32(indices)))
129129
.with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, positions)

crates/bevy_render/src/mesh/shape/icosphere.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl TryFrom<Icosphere> for Mesh {
108108

109109
Ok(Mesh::new(
110110
PrimitiveTopology::TriangleList,
111-
RenderAssetPersistencePolicy::Unload,
111+
RenderAssetPersistencePolicy::Keep,
112112
)
113113
.with_indices(Some(indices))
114114
.with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, points)

crates/bevy_render/src/mesh/shape/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl From<Box> for Mesh {
124124

125125
Mesh::new(
126126
PrimitiveTopology::TriangleList,
127-
RenderAssetPersistencePolicy::Unload,
127+
RenderAssetPersistencePolicy::Keep,
128128
)
129129
.with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, positions)
130130
.with_inserted_attribute(Mesh::ATTRIBUTE_NORMAL, normals)
@@ -179,7 +179,7 @@ impl From<Quad> for Mesh {
179179

180180
Mesh::new(
181181
PrimitiveTopology::TriangleList,
182-
RenderAssetPersistencePolicy::Unload,
182+
RenderAssetPersistencePolicy::Keep,
183183
)
184184
.with_indices(Some(indices))
185185
.with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, positions)
@@ -263,7 +263,7 @@ impl From<Plane> for Mesh {
263263

264264
Mesh::new(
265265
PrimitiveTopology::TriangleList,
266-
RenderAssetPersistencePolicy::Unload,
266+
RenderAssetPersistencePolicy::Keep,
267267
)
268268
.with_indices(Some(Indices::U32(indices)))
269269
.with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, positions)

crates/bevy_render/src/mesh/shape/regular_polygon.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl From<RegularPolygon> for Mesh {
6060

6161
Mesh::new(
6262
PrimitiveTopology::TriangleList,
63-
RenderAssetPersistencePolicy::Unload,
63+
RenderAssetPersistencePolicy::Keep,
6464
)
6565
.with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, positions)
6666
.with_inserted_attribute(Mesh::ATTRIBUTE_NORMAL, normals)

crates/bevy_render/src/mesh/shape/torus.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl From<Torus> for Mesh {
8989

9090
Mesh::new(
9191
PrimitiveTopology::TriangleList,
92-
RenderAssetPersistencePolicy::Unload,
92+
RenderAssetPersistencePolicy::Keep,
9393
)
9494
.with_indices(Some(Indices::U32(indices)))
9595
.with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, positions)

crates/bevy_render/src/mesh/shape/uvsphere.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl From<UVSphere> for Mesh {
8585

8686
Mesh::new(
8787
PrimitiveTopology::TriangleList,
88-
RenderAssetPersistencePolicy::Unload,
88+
RenderAssetPersistencePolicy::Keep,
8989
)
9090
.with_indices(Some(Indices::U32(indices)))
9191
.with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, vertices)

crates/bevy_render/src/render_asset.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ pub trait RenderAsset: Asset + Clone {
5555
/// or only need very infrequent access, then set this to Unload. Otherwise, set this to Keep.
5656
#[derive(Reflect, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default, Debug)]
5757
pub enum RenderAssetPersistencePolicy {
58-
#[default]
5958
Unload,
59+
#[default]
6060
Keep,
6161
}
6262

crates/bevy_render/src/texture/image.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ impl Default for Image {
467467
},
468468
sampler: ImageSampler::Default,
469469
texture_view_descriptor: None,
470-
cpu_persistent_access: RenderAssetPersistencePolicy::Unload,
470+
cpu_persistent_access: RenderAssetPersistencePolicy::Keep,
471471
}
472472
}
473473
}

0 commit comments

Comments
 (0)