mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-21 06:50:59 +01:00
[wgpu-core] use Fallible for BindGroup
This commit is contained in:
1 parent
2ea314e978
commit
b42500ee40
8 files changed
+114
-119
No files matched your search
@@ -581,7 +581,7 @@ impl RenderBundleEncoder {
|
||||
|
||||
fn set_bind_group(
|
||||
state: &mut State,
|
||||
bind_group_guard: &crate::storage::Storage<Arc<BindGroup>>,
|
||||
bind_group_guard: &crate::storage::Storage<Fallible<BindGroup>>,
|
||||
dynamic_offsets: &[u32],
|
||||
index: u32,
|
||||
num_dynamic_offsets: usize,
|
||||
@@ -594,9 +594,7 @@ fn set_bind_group(
|
||||
|
||||
let bind_group_id = bind_group_id.unwrap();
|
||||
|
||||
let bind_group = bind_group_guard
|
||||
.get_owned(bind_group_id)
|
||||
.map_err(|_| RenderCommandError::InvalidBindGroupId(bind_group_id))?;
|
||||
let bind_group = bind_group_guard.strict_get(bind_group_id).get()?;
|
||||
|
||||
bind_group.same_device(&state.device)?;
|
||||
|
||||
|
||||
@@ -132,8 +132,6 @@ pub enum ComputePassErrorInner {
|
||||
Encoder(#[from] CommandEncoderError),
|
||||
#[error("Parent encoder is invalid")]
|
||||
InvalidParentEncoder,
|
||||
#[error("BindGroupId {0:?} is invalid")]
|
||||
InvalidBindGroupId(id::BindGroupId),
|
||||
#[error("Bind group index {index} is greater than the device's requested `max_bind_group` limit {max}")]
|
||||
BindGroupIndexOutOfRange { index: u32, max: u32 },
|
||||
#[error("ComputePipelineId {0:?} is invalid")]
|
||||
@@ -985,8 +983,8 @@ impl Global {
|
||||
let hub = &self.hub;
|
||||
let bg = hub
|
||||
.bind_groups
|
||||
.get(bind_group_id)
|
||||
.map_err(|_| ComputePassErrorInner::InvalidBindGroupId(bind_group_id))
|
||||
.strict_get(bind_group_id)
|
||||
.get()
|
||||
.map_pass_err(scope)?;
|
||||
bind_group = Some(bg);
|
||||
}
|
||||
|
||||
@@ -81,113 +81,115 @@ impl ComputeCommand {
|
||||
let query_set_guard = hub.query_sets.read();
|
||||
let pipelines_guard = hub.compute_pipelines.read();
|
||||
|
||||
let resolved_commands: Vec<ArcComputeCommand> =
|
||||
commands
|
||||
.iter()
|
||||
.map(|c| -> Result<ArcComputeCommand, ComputePassError> {
|
||||
Ok(match *c {
|
||||
ComputeCommand::SetBindGroup {
|
||||
index,
|
||||
num_dynamic_offsets,
|
||||
bind_group_id,
|
||||
} => {
|
||||
if bind_group_id.is_none() {
|
||||
return Ok(ArcComputeCommand::SetBindGroup {
|
||||
index,
|
||||
num_dynamic_offsets,
|
||||
bind_group: None,
|
||||
});
|
||||
}
|
||||
|
||||
let bind_group_id = bind_group_id.unwrap();
|
||||
let bg = bind_group_guard.get_owned(bind_group_id).map_err(|_| {
|
||||
ComputePassError {
|
||||
scope: PassErrorScope::SetBindGroup,
|
||||
inner: ComputePassErrorInner::InvalidBindGroupId(bind_group_id),
|
||||
}
|
||||
})?;
|
||||
|
||||
ArcComputeCommand::SetBindGroup {
|
||||
let resolved_commands: Vec<ArcComputeCommand> = commands
|
||||
.iter()
|
||||
.map(|c| -> Result<ArcComputeCommand, ComputePassError> {
|
||||
Ok(match *c {
|
||||
ComputeCommand::SetBindGroup {
|
||||
index,
|
||||
num_dynamic_offsets,
|
||||
bind_group_id,
|
||||
} => {
|
||||
if bind_group_id.is_none() {
|
||||
return Ok(ArcComputeCommand::SetBindGroup {
|
||||
index,
|
||||
num_dynamic_offsets,
|
||||
bind_group: Some(bg),
|
||||
}
|
||||
bind_group: None,
|
||||
});
|
||||
}
|
||||
ComputeCommand::SetPipeline(pipeline_id) => ArcComputeCommand::SetPipeline(
|
||||
pipelines_guard.get_owned(pipeline_id).map_err(|_| {
|
||||
|
||||
let bind_group_id = bind_group_id.unwrap();
|
||||
let bg = bind_group_guard
|
||||
.strict_get(bind_group_id)
|
||||
.get()
|
||||
.map_err(|e| ComputePassError {
|
||||
scope: PassErrorScope::SetBindGroup,
|
||||
inner: e.into(),
|
||||
})?;
|
||||
|
||||
ArcComputeCommand::SetBindGroup {
|
||||
index,
|
||||
num_dynamic_offsets,
|
||||
bind_group: Some(bg),
|
||||
}
|
||||
}
|
||||
ComputeCommand::SetPipeline(pipeline_id) => ArcComputeCommand::SetPipeline(
|
||||
pipelines_guard
|
||||
.get_owned(pipeline_id)
|
||||
.map_err(|_| ComputePassError {
|
||||
scope: PassErrorScope::SetPipelineCompute,
|
||||
inner: ComputePassErrorInner::InvalidPipelineId(pipeline_id),
|
||||
})?,
|
||||
),
|
||||
|
||||
ComputeCommand::SetPushConstant {
|
||||
offset,
|
||||
size_bytes,
|
||||
values_offset,
|
||||
} => ArcComputeCommand::SetPushConstant {
|
||||
offset,
|
||||
size_bytes,
|
||||
values_offset,
|
||||
},
|
||||
|
||||
ComputeCommand::Dispatch(dim) => ArcComputeCommand::Dispatch(dim),
|
||||
|
||||
ComputeCommand::DispatchIndirect { buffer_id, offset } => {
|
||||
ArcComputeCommand::DispatchIndirect {
|
||||
buffer: buffers_guard.strict_get(buffer_id).get().map_err(|e| {
|
||||
ComputePassError {
|
||||
scope: PassErrorScope::SetPipelineCompute,
|
||||
inner: ComputePassErrorInner::InvalidPipelineId(pipeline_id),
|
||||
scope: PassErrorScope::Dispatch { indirect: true },
|
||||
inner: e.into(),
|
||||
}
|
||||
})?,
|
||||
),
|
||||
|
||||
ComputeCommand::SetPushConstant {
|
||||
offset,
|
||||
size_bytes,
|
||||
values_offset,
|
||||
} => ArcComputeCommand::SetPushConstant {
|
||||
offset,
|
||||
size_bytes,
|
||||
values_offset,
|
||||
},
|
||||
|
||||
ComputeCommand::Dispatch(dim) => ArcComputeCommand::Dispatch(dim),
|
||||
|
||||
ComputeCommand::DispatchIndirect { buffer_id, offset } => {
|
||||
ArcComputeCommand::DispatchIndirect {
|
||||
buffer: buffers_guard.strict_get(buffer_id).get().map_err(|e| {
|
||||
ComputePassError {
|
||||
scope: PassErrorScope::Dispatch { indirect: true },
|
||||
inner: e.into(),
|
||||
}
|
||||
})?,
|
||||
offset,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ComputeCommand::PushDebugGroup { color, len } => {
|
||||
ArcComputeCommand::PushDebugGroup { color, len }
|
||||
}
|
||||
ComputeCommand::PushDebugGroup { color, len } => {
|
||||
ArcComputeCommand::PushDebugGroup { color, len }
|
||||
}
|
||||
|
||||
ComputeCommand::PopDebugGroup => ArcComputeCommand::PopDebugGroup,
|
||||
ComputeCommand::PopDebugGroup => ArcComputeCommand::PopDebugGroup,
|
||||
|
||||
ComputeCommand::InsertDebugMarker { color, len } => {
|
||||
ArcComputeCommand::InsertDebugMarker { color, len }
|
||||
}
|
||||
ComputeCommand::InsertDebugMarker { color, len } => {
|
||||
ArcComputeCommand::InsertDebugMarker { color, len }
|
||||
}
|
||||
|
||||
ComputeCommand::WriteTimestamp {
|
||||
query_set_id,
|
||||
query_index,
|
||||
} => ArcComputeCommand::WriteTimestamp {
|
||||
query_set: query_set_guard.strict_get(query_set_id).get().map_err(
|
||||
|e| ComputePassError {
|
||||
scope: PassErrorScope::WriteTimestamp,
|
||||
inner: e.into(),
|
||||
},
|
||||
)?,
|
||||
query_index,
|
||||
},
|
||||
ComputeCommand::WriteTimestamp {
|
||||
query_set_id,
|
||||
query_index,
|
||||
} => ArcComputeCommand::WriteTimestamp {
|
||||
query_set: query_set_guard
|
||||
.strict_get(query_set_id)
|
||||
.get()
|
||||
.map_err(|e| ComputePassError {
|
||||
scope: PassErrorScope::WriteTimestamp,
|
||||
inner: e.into(),
|
||||
})?,
|
||||
query_index,
|
||||
},
|
||||
|
||||
ComputeCommand::BeginPipelineStatisticsQuery {
|
||||
query_set_id,
|
||||
query_index,
|
||||
} => ArcComputeCommand::BeginPipelineStatisticsQuery {
|
||||
query_set: query_set_guard.strict_get(query_set_id).get().map_err(
|
||||
|e| ComputePassError {
|
||||
scope: PassErrorScope::BeginPipelineStatisticsQuery,
|
||||
inner: e.into(),
|
||||
},
|
||||
)?,
|
||||
query_index,
|
||||
},
|
||||
ComputeCommand::BeginPipelineStatisticsQuery {
|
||||
query_set_id,
|
||||
query_index,
|
||||
} => ArcComputeCommand::BeginPipelineStatisticsQuery {
|
||||
query_set: query_set_guard
|
||||
.strict_get(query_set_id)
|
||||
.get()
|
||||
.map_err(|e| ComputePassError {
|
||||
scope: PassErrorScope::BeginPipelineStatisticsQuery,
|
||||
inner: e.into(),
|
||||
})?,
|
||||
query_index,
|
||||
},
|
||||
|
||||
ComputeCommand::EndPipelineStatisticsQuery => {
|
||||
ArcComputeCommand::EndPipelineStatisticsQuery
|
||||
}
|
||||
})
|
||||
ComputeCommand::EndPipelineStatisticsQuery => {
|
||||
ArcComputeCommand::EndPipelineStatisticsQuery
|
||||
}
|
||||
})
|
||||
.collect::<Result<Vec<_>, ComputePassError>>()?;
|
||||
})
|
||||
.collect::<Result<Vec<_>, ComputePassError>>()?;
|
||||
Ok(resolved_commands)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,8 +68,6 @@ pub enum DrawError {
|
||||
#[derive(Clone, Debug, Error)]
|
||||
#[non_exhaustive]
|
||||
pub enum RenderCommandError {
|
||||
#[error("BindGroupId {0:?} is invalid")]
|
||||
InvalidBindGroupId(id::BindGroupId),
|
||||
#[error("Render bundle {0:?} is invalid")]
|
||||
InvalidRenderBundle(id::RenderBundleId),
|
||||
#[error("Bind group index {index} is greater than the device's requested `max_bind_group` limit {max}")]
|
||||
|
||||
@@ -632,8 +632,6 @@ pub enum RenderPassErrorInner {
|
||||
SurfaceTextureDropped,
|
||||
#[error("Not enough memory left for render pass")]
|
||||
OutOfMemory,
|
||||
#[error("BindGroupId {0:?} is invalid")]
|
||||
InvalidBindGroupId(id::BindGroupId),
|
||||
#[error("Unable to clear non-present/read-only depth")]
|
||||
InvalidDepthOps,
|
||||
#[error("Unable to clear non-present/read-only stencil")]
|
||||
@@ -2816,8 +2814,8 @@ impl Global {
|
||||
let hub = &self.hub;
|
||||
let bg = hub
|
||||
.bind_groups
|
||||
.get(bind_group_id)
|
||||
.map_err(|_| RenderPassErrorInner::InvalidBindGroupId(bind_group_id))
|
||||
.strict_get(bind_group_id)
|
||||
.get()
|
||||
.map_pass_err(scope)?;
|
||||
bind_group = Some(bg);
|
||||
}
|
||||
|
||||
@@ -129,9 +129,7 @@ impl RenderCommand {
|
||||
hub: &crate::hub::Hub,
|
||||
commands: &[RenderCommand],
|
||||
) -> Result<Vec<ArcRenderCommand>, super::RenderPassError> {
|
||||
use super::{
|
||||
DrawKind, PassErrorScope, RenderCommandError, RenderPassError, RenderPassErrorInner,
|
||||
};
|
||||
use super::{DrawKind, PassErrorScope, RenderCommandError, RenderPassError};
|
||||
|
||||
let buffers_guard = hub.buffers.read();
|
||||
let bind_group_guard = hub.bind_groups.read();
|
||||
@@ -157,12 +155,13 @@ impl RenderCommand {
|
||||
}
|
||||
|
||||
let bind_group_id = bind_group_id.unwrap();
|
||||
let bg = bind_group_guard.get_owned(bind_group_id).map_err(|_| {
|
||||
RenderPassError {
|
||||
let bg = bind_group_guard
|
||||
.strict_get(bind_group_id)
|
||||
.get()
|
||||
.map_err(|e| RenderPassError {
|
||||
scope: PassErrorScope::SetBindGroup,
|
||||
inner: RenderPassErrorInner::InvalidBindGroupId(bind_group_id),
|
||||
}
|
||||
})?;
|
||||
inner: e.into(),
|
||||
})?;
|
||||
|
||||
ArcRenderCommand::SetBindGroup {
|
||||
index,
|
||||
|
||||
@@ -825,14 +825,14 @@ impl Global {
|
||||
Err(e) => break 'error e,
|
||||
};
|
||||
|
||||
let id = fid.assign(bind_group);
|
||||
let id = fid.assign(Fallible::Valid(bind_group));
|
||||
|
||||
api_log!("Device::create_bind_group -> {id:?}");
|
||||
|
||||
return (id, None);
|
||||
};
|
||||
|
||||
let id = fid.assign_error();
|
||||
let id = fid.assign(Fallible::Invalid(Arc::new(desc.label.to_string())));
|
||||
(id, Some(error))
|
||||
}
|
||||
|
||||
@@ -842,8 +842,10 @@ impl Global {
|
||||
|
||||
let hub = &self.hub;
|
||||
|
||||
if let Some(_bind_group) = hub.bind_groups.unregister(bind_group_id) {
|
||||
#[cfg(feature = "trace")]
|
||||
let _bind_group = hub.bind_groups.strict_unregister(bind_group_id);
|
||||
|
||||
#[cfg(feature = "trace")]
|
||||
if let Ok(_bind_group) = _bind_group.get() {
|
||||
if let Some(t) = _bind_group.device.trace.lock().as_mut() {
|
||||
t.add(trace::Action::DestroyBindGroup(bind_group_id));
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ pub struct Hub {
|
||||
pub(crate) pipeline_layouts: Registry<Arc<PipelineLayout>>,
|
||||
pub(crate) shader_modules: Registry<Arc<ShaderModule>>,
|
||||
pub(crate) bind_group_layouts: Registry<Arc<BindGroupLayout>>,
|
||||
pub(crate) bind_groups: Registry<Arc<BindGroup>>,
|
||||
pub(crate) bind_groups: Registry<Fallible<BindGroup>>,
|
||||
pub(crate) command_buffers: Registry<Arc<CommandBuffer>>,
|
||||
pub(crate) render_bundles: Registry<Arc<RenderBundle>>,
|
||||
pub(crate) render_pipelines: Registry<Arc<RenderPipeline>>,
|
||||
|
||||
Reference in new issue
Block a user