From 018509c3a1b238fe4e2569357267de428ca2ad06 Mon Sep 17 00:00:00 2001 From: Charles Date: Wed, 28 Sep 2022 04:04:55 +0000 Subject: [PATCH] log pipeline cache errors earlier (#6115) # 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. --- .../src/render_resource/pipeline_cache.rs | 47 +++++++++---------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/crates/bevy_render/src/render_resource/pipeline_cache.rs b/crates/bevy_render/src/render_resource/pipeline_cache.rs index dbcc5ef93efd9..48603edefe7a2 100644 --- a/crates/bevy_render/src/render_resource/pipeline_cache.rs +++ b/crates/bevy_render/src/render_resource/pipeline_cache.rs @@ -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 { @@ -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; + } + } } }