[wgpu-core] use Fallible for PipelineLayout

This commit is contained in:
teoxoy 2024-09-06 22:00:02 +02:00 committed by Teodor Tanasoaia
parent e444e78d94
commit 1c5793afb3
3 changed files with 22 additions and 27 deletions

View File

@ -683,12 +683,12 @@ impl Global {
Err(e) => break 'error e,
};
let id = fid.assign(layout);
let id = fid.assign(Fallible::Valid(layout));
api_log!("Device::create_pipeline_layout -> {id:?}");
return (id, None);
};
let id = fid.assign_error();
let id = fid.assign(Fallible::Invalid(Arc::new(desc.label.to_string())));
(id, Some(error))
}
@ -697,9 +697,12 @@ impl Global {
api_log!("PipelineLayout::drop {pipeline_layout_id:?}");
let hub = &self.hub;
if let Some(_layout) = hub.pipeline_layouts.unregister(pipeline_layout_id) {
#[cfg(feature = "trace")]
if let Some(t) = _layout.device.trace.lock().as_mut() {
let _layout = hub.pipeline_layouts.strict_unregister(pipeline_layout_id);
#[cfg(feature = "trace")]
if let Ok(layout) = _layout.get() {
if let Some(t) = layout.device.trace.lock().as_mut() {
t.add(trace::Action::DestroyPipelineLayout(pipeline_layout_id));
}
}
@ -1215,15 +1218,11 @@ impl Global {
let layout = desc
.layout
.map(|layout| {
hub.pipeline_layouts
.get(layout)
.map_err(|_| pipeline::CreateRenderPipelineError::InvalidLayout)
})
.map(|layout| hub.pipeline_layouts.strict_get(layout).get())
.transpose();
let layout = match layout {
Ok(layout) => layout,
Err(e) => break 'error e,
Err(e) => break 'error e.into(),
};
let cache = desc
@ -1326,7 +1325,7 @@ impl Global {
let mut pipeline_layout_guard = hub.pipeline_layouts.write();
let mut bgl_guard = hub.bind_group_layouts.write();
pipeline_layout_guard.insert(ids.root_id, pipeline.layout.clone());
pipeline_layout_guard.insert(ids.root_id, Fallible::Valid(pipeline.layout.clone()));
let mut group_ids = ids.group_ids.iter();
// NOTE: If the first iterator is longer than the second, the `.zip()` impl will still advance the
// the first iterator before realizing that the second iterator has finished.
@ -1358,7 +1357,7 @@ impl Global {
if let Some(ids) = implicit_context {
let mut pipeline_layout_guard = hub.pipeline_layouts.write();
let mut bgl_guard = hub.bind_group_layouts.write();
pipeline_layout_guard.insert_error(ids.root_id);
pipeline_layout_guard.insert(ids.root_id, Fallible::Invalid(Arc::new(String::new())));
for bgl_id in ids.group_ids {
bgl_guard.insert(bgl_id, Fallible::Invalid(Arc::new(String::new())));
}
@ -1457,15 +1456,11 @@ impl Global {
let layout = desc
.layout
.map(|layout| {
hub.pipeline_layouts
.get(layout)
.map_err(|_| pipeline::CreateComputePipelineError::InvalidLayout)
})
.map(|layout| hub.pipeline_layouts.strict_get(layout).get())
.transpose();
let layout = match layout {
Ok(layout) => layout,
Err(e) => break 'error e,
Err(e) => break 'error e.into(),
};
let cache = desc
@ -1523,7 +1518,7 @@ impl Global {
let mut pipeline_layout_guard = hub.pipeline_layouts.write();
let mut bgl_guard = hub.bind_group_layouts.write();
pipeline_layout_guard.insert(ids.root_id, pipeline.layout.clone());
pipeline_layout_guard.insert(ids.root_id, Fallible::Valid(pipeline.layout.clone()));
let mut group_ids = ids.group_ids.iter();
// NOTE: If the first iterator is longer than the second, the `.zip()` impl will still advance the
// the first iterator before realizing that the second iterator has finished.
@ -1555,7 +1550,7 @@ impl Global {
if let Some(ids) = implicit_context {
let mut pipeline_layout_guard = hub.pipeline_layouts.write();
let mut bgl_guard = hub.bind_group_layouts.write();
pipeline_layout_guard.insert_error(ids.root_id);
pipeline_layout_guard.insert(ids.root_id, Fallible::Invalid(Arc::new(String::new())));
for bgl_id in ids.group_ids {
bgl_guard.insert(bgl_id, Fallible::Invalid(Arc::new(String::new())));
}

View File

@ -165,7 +165,7 @@ pub struct Hub {
pub(crate) adapters: Registry<Arc<Adapter>>,
pub(crate) devices: Registry<Arc<Device>>,
pub(crate) queues: Registry<Arc<Queue>>,
pub(crate) pipeline_layouts: Registry<Arc<PipelineLayout>>,
pub(crate) pipeline_layouts: Registry<Fallible<PipelineLayout>>,
pub(crate) shader_modules: Registry<Arc<ShaderModule>>,
pub(crate) bind_group_layouts: Registry<Fallible<BindGroupLayout>>,
pub(crate) bind_groups: Registry<Fallible<BindGroup>>,

View File

@ -4,7 +4,7 @@ use crate::{
command::ColorAttachmentError,
device::{Device, DeviceError, MissingDownlevelFlags, MissingFeatures, RenderPassContext},
id::{PipelineCacheId, PipelineLayoutId, ShaderModuleId},
resource::{Labeled, TrackingData},
resource::{InvalidResourceError, Labeled, TrackingData},
resource_log, validation, Label,
};
use arrayvec::ArrayVec;
@ -222,8 +222,6 @@ pub struct ResolvedComputePipelineDescriptor<'a> {
pub enum CreateComputePipelineError {
#[error(transparent)]
Device(#[from] DeviceError),
#[error("Pipeline layout is invalid")]
InvalidLayout,
#[error("Cache is invalid")]
InvalidCache,
#[error("Unable to derive an implicit layout")]
@ -236,6 +234,8 @@ pub enum CreateComputePipelineError {
PipelineConstants(String),
#[error(transparent)]
MissingDownlevelFlags(#[from] MissingDownlevelFlags),
#[error(transparent)]
InvalidResource(#[from] InvalidResourceError),
}
#[derive(Debug)]
@ -467,8 +467,6 @@ pub enum CreateRenderPipelineError {
ColorAttachment(#[from] ColorAttachmentError),
#[error(transparent)]
Device(#[from] DeviceError),
#[error("Pipeline layout is invalid")]
InvalidLayout,
#[error("Pipeline cache is invalid")]
InvalidCache,
#[error("Unable to derive an implicit layout")]
@ -540,6 +538,8 @@ pub enum CreateRenderPipelineError {
"but no render target for the pipeline was specified."
))]
NoTargetSpecified,
#[error(transparent)]
InvalidResource(#[from] InvalidResourceError),
}
bitflags::bitflags! {