Skip to content

Commit

Permalink
log pipeline cache errors earlier (#6115)
Browse files Browse the repository at this point in the history
# Objective

- Currently, errors aren't logged as soon as they are found, they are logged only on the next frame. This means your shader could have an unreported error that could have been reported on the first frame.

## Solution

- Log the error as soon as they are found, don't wait until next frame

## Notes

I discovered this issue because I was simply unwrapping the `Result` from `PipelinCache::get_render_pipeline()` which caused it to fail without any explanations. Admittedly, this was a bit of a user error, I shouldn't have unwrapped that, but it seems a bit strange to wait until the next time the pipeline is processed to log the error instead of just logging it as soon as possible since we already have all the info necessary.
  • Loading branch information
IceSentry committed Sep 28, 2022
1 parent d22d310 commit 018509c
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions crates/bevy_render/src/render_resource/pipeline_cache.rs
Expand Up @@ -609,28 +609,8 @@ impl PipelineCache {

for id in waiting_pipelines {
let pipeline = &mut pipelines[id];
match &pipeline.state {
CachedPipelineState::Ok(_) => continue,
CachedPipelineState::Queued => {}
CachedPipelineState::Err(err) => {
match err {
PipelineCacheError::ShaderNotLoaded(_)
| PipelineCacheError::ShaderImportNotYetAvailable => { /* retry */ }
// shader could not be processed ... retrying won't help
PipelineCacheError::ProcessShaderError(err) => {
error!("failed to process shader: {}", err);
continue;
}
PipelineCacheError::AsModuleDescriptorError(err, source) => {
log_shader_error(source, err);
continue;
}
PipelineCacheError::CreateShaderModule(description) => {
error!("failed to create shader module: {}", description);
continue;
}
}
}
if matches!(pipeline.state, CachedPipelineState::Ok(_)) {
continue;
}

pipeline.state = match &pipeline.descriptor {
Expand All @@ -642,8 +622,27 @@ impl PipelineCache {
}
};

if let CachedPipelineState::Err(_) = pipeline.state {
self.waiting_pipelines.insert(id);
if let CachedPipelineState::Err(err) = &pipeline.state {
match err {
PipelineCacheError::ShaderNotLoaded(_)
| PipelineCacheError::ShaderImportNotYetAvailable => {
// retry
self.waiting_pipelines.insert(id);
}
// shader could not be processed ... retrying won't help
PipelineCacheError::ProcessShaderError(err) => {
error!("failed to process shader: {}", err);
continue;
}
PipelineCacheError::AsModuleDescriptorError(err, source) => {
log_shader_error(source, err);
continue;
}
PipelineCacheError::CreateShaderModule(description) => {
error!("failed to create shader module: {}", description);
continue;
}
}
}
}

Expand Down

0 comments on commit 018509c

Please sign in to comment.