mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 12:43:34 +00:00
gltf loader: do not use the taskpool for only one task (#3577)
# Objective - Fix the case mentioned in https://github.com/bevyengine/bevy/pull/2725#issuecomment-1007014024. - On a machine with 4 cores, so 1 thread for assets, loading a gltf with only one textures hangs all asset loading ## Solution - Do not use the task pool when there is only one texture to load Co-authored-by: François <8672791+mockersf@users.noreply.github.com>
This commit is contained in:
parent
fda0b2c911
commit
015da72250
1 changed files with 33 additions and 29 deletions
|
@ -247,36 +247,40 @@ async fn load_gltf<'a, 'b>(
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// TODO: use the threaded impl on wasm once wasm thread pool doesn't deadlock on it
|
// TODO: use the threaded impl on wasm once wasm thread pool doesn't deadlock on it
|
||||||
#[cfg(target_arch = "wasm32")]
|
// See https://github.com/bevyengine/bevy/issues/1924 for more details
|
||||||
for gltf_texture in gltf.textures() {
|
// The taskpool use is also avoided when there is only one texture for performance reasons and
|
||||||
let (texture, label) =
|
// to avoid https://github.com/bevyengine/bevy/pull/2725
|
||||||
load_texture(gltf_texture, &buffer_data, &linear_textures, &load_context).await?;
|
if gltf.textures().len() == 1 || cfg!(target_arch = "wasm32") {
|
||||||
load_context.set_labeled_asset(&label, LoadedAsset::new(texture));
|
for gltf_texture in gltf.textures() {
|
||||||
}
|
let (texture, label) =
|
||||||
|
load_texture(gltf_texture, &buffer_data, &linear_textures, load_context).await?;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
load_context
|
|
||||||
.task_pool()
|
|
||||||
.scope(|scope| {
|
|
||||||
gltf.textures().for_each(|gltf_texture| {
|
|
||||||
let linear_textures = &linear_textures;
|
|
||||||
let load_context: &LoadContext = load_context;
|
|
||||||
let buffer_data = &buffer_data;
|
|
||||||
scope.spawn(async move {
|
|
||||||
load_texture(gltf_texture, buffer_data, linear_textures, load_context).await
|
|
||||||
});
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.into_iter()
|
|
||||||
.filter_map(|res| {
|
|
||||||
if let Err(err) = res.as_ref() {
|
|
||||||
warn!("Error loading glTF texture: {}", err);
|
|
||||||
}
|
|
||||||
res.ok()
|
|
||||||
})
|
|
||||||
.for_each(|(texture, label)| {
|
|
||||||
load_context.set_labeled_asset(&label, LoadedAsset::new(texture));
|
load_context.set_labeled_asset(&label, LoadedAsset::new(texture));
|
||||||
});
|
}
|
||||||
|
} else {
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
load_context
|
||||||
|
.task_pool()
|
||||||
|
.scope(|scope| {
|
||||||
|
gltf.textures().for_each(|gltf_texture| {
|
||||||
|
let linear_textures = &linear_textures;
|
||||||
|
let load_context: &LoadContext = load_context;
|
||||||
|
let buffer_data = &buffer_data;
|
||||||
|
scope.spawn(async move {
|
||||||
|
load_texture(gltf_texture, buffer_data, linear_textures, load_context).await
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|res| {
|
||||||
|
if let Err(err) = res.as_ref() {
|
||||||
|
warn!("Error loading glTF texture: {}", err);
|
||||||
|
}
|
||||||
|
res.ok()
|
||||||
|
})
|
||||||
|
.for_each(|(texture, label)| {
|
||||||
|
load_context.set_labeled_asset(&label, LoadedAsset::new(texture));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let mut scenes = vec![];
|
let mut scenes = vec![];
|
||||||
let mut named_scenes = HashMap::default();
|
let mut named_scenes = HashMap::default();
|
||||||
|
|
Loading…
Reference in a new issue