Skip to content

Commit 208e6e9

Browse files
authored
Silently skip effects if pipeline creation pending (#433)
Silently skip (with a debug log) any effect if one of the compute pipelines is queued for creation but was not created yet. This prevents a panic in `wgpu` and ensure we can retry later once all pipelines are ready. Fixes #428
1 parent 37f5875 commit 208e6e9

File tree

1 file changed

+57
-11
lines changed

1 file changed

+57
-11
lines changed

src/render/mod.rs

+57-11
Original file line numberDiff line numberDiff line change
@@ -6158,6 +6158,23 @@ enum HanabiPipelineId {
61586158
Cached(CachedComputePipelineId),
61596159
}
61606160

6161+
pub(crate) enum ComputePipelineError {
6162+
Queued,
6163+
Creating,
6164+
Error,
6165+
}
6166+
6167+
impl From<&CachedPipelineState> for ComputePipelineError {
6168+
fn from(value: &CachedPipelineState) -> Self {
6169+
match value {
6170+
CachedPipelineState::Queued => Self::Queued,
6171+
CachedPipelineState::Creating(_) => Self::Creating,
6172+
CachedPipelineState::Err(_) => Self::Error,
6173+
_ => panic!("Trying to convert Ok state to error."),
6174+
}
6175+
}
6176+
}
6177+
61616178
pub(crate) struct HanabiComputePass<'a> {
61626179
/// Pipeline cache to fetch cached compute pipelines by ID.
61636180
pipeline_cache: &'a PipelineCache,
@@ -6193,22 +6210,24 @@ impl<'a> HanabiComputePass<'a> {
61936210
pub fn set_cached_compute_pipeline(
61946211
&mut self,
61956212
pipeline_id: CachedComputePipelineId,
6196-
) -> Result<(), NodeRunError> {
6213+
) -> Result<(), ComputePipelineError> {
6214+
trace!("set_cached_compute_pipeline() id={pipeline_id:?}");
61976215
if HanabiPipelineId::Cached(pipeline_id) == self.pipeline_id {
6216+
trace!("-> already set; skipped");
61986217
return Ok(());
61996218
}
62006219
let Some(pipeline) = self.pipeline_cache.get_compute_pipeline(pipeline_id) else {
6201-
if let CachedPipelineState::Err(err) =
6202-
self.pipeline_cache.get_compute_pipeline_state(pipeline_id)
6203-
{
6220+
let state = self.pipeline_cache.get_compute_pipeline_state(pipeline_id);
6221+
if let CachedPipelineState::Err(err) = state {
62046222
error!(
62056223
"Failed to find compute pipeline #{}: {:?}",
62066224
pipeline_id.id(),
62076225
err
62086226
);
6227+
} else {
6228+
debug!("Compute pipeline not ready #{}", pipeline_id.id());
62096229
}
6210-
// FIXME - Bevy doesn't allow returning custom errors here...
6211-
return Ok(());
6230+
return Err(state.into());
62126231
};
62136232
self.compute_pass.set_pipeline(pipeline);
62146233
self.pipeline_id = HanabiPipelineId::Cached(pipeline_id);
@@ -6493,7 +6512,13 @@ impl Node for VfxSimulateNode {
64936512
}
64946513
}
64956514

6496-
compute_pass.set_cached_compute_pipeline(effects_meta.active_indirect_pipeline_id)?;
6515+
if compute_pass
6516+
.set_cached_compute_pipeline(effects_meta.active_indirect_pipeline_id)
6517+
.is_err()
6518+
{
6519+
// FIXME - Bevy doesn't allow returning custom errors here...
6520+
return Ok(());
6521+
}
64976522

64986523
//error!("FIXME - effect_metadata_buffer has gaps!!!! this won't work. len() is
64996524
// the size exluding gaps!");
@@ -6677,7 +6702,14 @@ impl Node for VfxSimulateNode {
66776702
warn!("Missing sort-fill pipeline.");
66786703
continue;
66796704
};
6680-
compute_pass.set_cached_compute_pipeline(pipeline_id)?;
6705+
if compute_pass
6706+
.set_cached_compute_pipeline(pipeline_id)
6707+
.is_err()
6708+
{
6709+
compute_pass.pop_debug_group();
6710+
// FIXME - Bevy doesn't allow returning custom errors here...
6711+
return Ok(());
6712+
}
66816713

66826714
// Bind group sort_fill@0
66836715
let particle_buffer = effect_buffer.particle_buffer();
@@ -6726,8 +6758,15 @@ impl Node for VfxSimulateNode {
67266758
{
67276759
compute_pass.push_debug_group("hanabi:sort");
67286760

6729-
compute_pass
6730-
.set_cached_compute_pipeline(sort_bind_groups.sort_pipeline_id())?;
6761+
if compute_pass
6762+
.set_cached_compute_pipeline(sort_bind_groups.sort_pipeline_id())
6763+
.is_err()
6764+
{
6765+
compute_pass.pop_debug_group();
6766+
// FIXME - Bevy doesn't allow returning custom errors here...
6767+
return Ok(());
6768+
}
6769+
67316770
compute_pass.set_bind_group(0, sort_bind_groups.sort_bind_group(), &[]);
67326771
let indirect_offset =
67336772
sort_bind_groups.get_sort_indirect_dispatch_byte_offset() as u64;
@@ -6744,7 +6783,14 @@ impl Node for VfxSimulateNode {
67446783

67456784
// Fetch compute pipeline
67466785
let pipeline_id = sort_bind_groups.get_sort_copy_pipeline_id();
6747-
compute_pass.set_cached_compute_pipeline(pipeline_id)?;
6786+
if compute_pass
6787+
.set_cached_compute_pipeline(pipeline_id)
6788+
.is_err()
6789+
{
6790+
compute_pass.pop_debug_group();
6791+
// FIXME - Bevy doesn't allow returning custom errors here...
6792+
return Ok(());
6793+
}
67486794

67496795
// Bind group sort_copy@0
67506796
let indirect_index_buffer = effect_buffer.indirect_index_buffer();

0 commit comments

Comments
 (0)