From ee3b63a9af6c7349d166117a3d54c755e46d17c5 Mon Sep 17 00:00:00 2001 From: teoxoy <28601907+teoxoy@users.noreply.github.com> Date: Fri, 6 Sep 2024 22:06:45 +0200 Subject: [PATCH] [wgpu-core] use `Fallible` for `PipelineCache` --- wgpu-core/src/device/global.rs | 29 +++++++++++------------------ wgpu-core/src/hub.rs | 2 +- wgpu-core/src/pipeline.rs | 4 ---- 3 files changed, 12 insertions(+), 23 deletions(-) diff --git a/wgpu-core/src/device/global.rs b/wgpu-core/src/device/global.rs index 455f581fc..9edcf0866 100644 --- a/wgpu-core/src/device/global.rs +++ b/wgpu-core/src/device/global.rs @@ -1228,15 +1228,11 @@ impl Global { let cache = desc .cache - .map(|cache| { - hub.pipeline_caches - .get(cache) - .map_err(|_| pipeline::CreateRenderPipelineError::InvalidCache) - }) + .map(|cache| hub.pipeline_caches.strict_get(cache).get()) .transpose(); let cache = match cache { Ok(cache) => cache, - Err(e) => break 'error e, + Err(e) => break 'error e.into(), }; let vertex = { @@ -1469,15 +1465,11 @@ impl Global { let cache = desc .cache - .map(|cache| { - hub.pipeline_caches - .get(cache) - .map_err(|_| pipeline::CreateComputePipelineError::InvalidCache) - }) + .map(|cache| hub.pipeline_caches.strict_get(cache).get()) .transpose(); let cache = match cache { Ok(cache) => cache, - Err(e) => break 'error e, + Err(e) => break 'error e.into(), }; let module = hub.shader_modules.strict_get(desc.stage.module).get(); @@ -1642,7 +1634,7 @@ impl Global { let cache = unsafe { device.create_pipeline_cache(desc) }; match cache { Ok(cache) => { - let id = fid.assign(cache); + let id = fid.assign(Fallible::Valid(cache)); api_log!("Device::create_pipeline_cache -> {id:?}"); return (id, None); } @@ -1650,7 +1642,7 @@ impl Global { } }; - let id = fid.assign_error(); + let id = fid.assign(Fallible::Invalid(Arc::new(desc.label.to_string()))); (id, Some(error)) } @@ -1661,12 +1653,13 @@ impl Global { let hub = &self.hub; - if let Some(cache) = hub.pipeline_caches.unregister(pipeline_cache_id) { - #[cfg(feature = "trace")] + let _cache = hub.pipeline_caches.strict_unregister(pipeline_cache_id); + + #[cfg(feature = "trace")] + if let Ok(cache) = _cache.get() { if let Some(t) = cache.device.trace.lock().as_mut() { t.add(trace::Action::DestroyPipelineCache(pipeline_cache_id)); } - drop(cache) } } @@ -2069,7 +2062,7 @@ impl Global { api_log!("PipelineCache::get_data"); let hub = &self.hub; - if let Ok(cache) = hub.pipeline_caches.get(id) { + if let Ok(cache) = hub.pipeline_caches.strict_get(id).get() { // TODO: Is this check needed? if !cache.device.is_valid() { return None; diff --git a/wgpu-core/src/hub.rs b/wgpu-core/src/hub.rs index d937597eb..d0f71f382 100644 --- a/wgpu-core/src/hub.rs +++ b/wgpu-core/src/hub.rs @@ -173,7 +173,7 @@ pub struct Hub { pub(crate) render_bundles: Registry>, pub(crate) render_pipelines: Registry>, pub(crate) compute_pipelines: Registry>, - pub(crate) pipeline_caches: Registry>, + pub(crate) pipeline_caches: Registry>, pub(crate) query_sets: Registry>, pub(crate) buffers: Registry>, pub(crate) staging_buffers: Registry, diff --git a/wgpu-core/src/pipeline.rs b/wgpu-core/src/pipeline.rs index 95cc415d4..08e7167db 100644 --- a/wgpu-core/src/pipeline.rs +++ b/wgpu-core/src/pipeline.rs @@ -222,8 +222,6 @@ pub struct ResolvedComputePipelineDescriptor<'a> { pub enum CreateComputePipelineError { #[error(transparent)] Device(#[from] DeviceError), - #[error("Cache is invalid")] - InvalidCache, #[error("Unable to derive an implicit layout")] Implicit(#[from] ImplicitLayoutError), #[error("Error matching shader requirements against the pipeline")] @@ -467,8 +465,6 @@ pub enum CreateRenderPipelineError { ColorAttachment(#[from] ColorAttachmentError), #[error(transparent)] Device(#[from] DeviceError), - #[error("Pipeline cache is invalid")] - InvalidCache, #[error("Unable to derive an implicit layout")] Implicit(#[from] ImplicitLayoutError), #[error("Color state [{0}] is invalid")]