[wgpu-core] use Fallible for RenderBundle

This commit is contained in:
teoxoy 2024-09-06 22:11:03 +02:00 committed by Teodor Tanasoaia
parent ee3b63a9af
commit c0c594eff2
5 changed files with 18 additions and 25 deletions

View File

@ -1,6 +1,5 @@
use crate::{
binding_model::{LateMinBufferBindingSizeMismatch, PushConstantUploadError},
id,
resource::{
DestroyedResourceError, MissingBufferUsageError, MissingTextureUsageError,
ResourceErrorIdent,
@ -68,8 +67,6 @@ pub enum DrawError {
#[derive(Clone, Debug, Error)]
#[non_exhaustive]
pub enum RenderCommandError {
#[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}")]
BindGroupIndexOutOfRange { index: u32, max: u32 },
#[error("Vertex buffer index {index} is greater than the device's requested `max_vertex_buffers` limit {max}")]

View File

@ -583,8 +583,6 @@ pub enum RenderPassErrorInner {
InvalidParentEncoder,
#[error("The format of the depth-stencil attachment ({0:?}) is not a depth-stencil format")]
InvalidDepthStencilAttachmentFormat(wgt::TextureFormat),
#[error("Render bundle {0:?} is invalid")]
InvalidRenderBundle(id::RenderBundleId),
#[error("The format of the {location} ({format:?}) is not resolvable")]
UnsupportedResolveTargetFormat {
location: AttachmentErrorLocation,
@ -3333,10 +3331,7 @@ impl Global {
let bundles = hub.render_bundles.read();
for &bundle_id in render_bundle_ids {
let bundle = bundles
.get_owned(bundle_id)
.map_err(|_| RenderPassErrorInner::InvalidRenderBundle(bundle_id))
.map_pass_err(scope)?;
let bundle = bundles.strict_get(bundle_id).get().map_pass_err(scope)?;
base.commands.push(ArcRenderCommand::ExecuteBundle(bundle));
}

View File

@ -129,7 +129,7 @@ impl RenderCommand {
hub: &crate::hub::Hub,
commands: &[RenderCommand],
) -> Result<Vec<ArcRenderCommand>, super::RenderPassError> {
use super::{DrawKind, PassErrorScope, RenderCommandError, RenderPassError};
use super::{DrawKind, PassErrorScope, RenderPassError};
let buffers_guard = hub.buffers.read();
let bind_group_guard = hub.bind_groups.read();
@ -376,12 +376,12 @@ impl RenderCommand {
RenderCommand::EndOcclusionQuery => ArcRenderCommand::EndOcclusionQuery,
RenderCommand::ExecuteBundle(bundle) => ArcRenderCommand::ExecuteBundle(
render_bundles_guard
.get_owned(bundle)
.map_err(|_| RenderPassError {
render_bundles_guard.strict_get(bundle).get().map_err(|e| {
RenderPassError {
scope: PassErrorScope::ExecuteBundle,
inner: RenderCommandError::InvalidRenderBundle(bundle).into(),
})?,
inner: e.into(),
}
})?,
),
})
})

View File

@ -186,11 +186,10 @@ impl Global {
&self,
backend: wgt::Backend,
id_in: Option<id::RenderBundleId>,
desc: &command::RenderBundleDescriptor,
) {
let hub = &self.hub;
let fid = hub.render_bundles.prepare(backend, id_in);
fid.assign_error();
let fid = self.hub.render_bundles.prepare(backend, id_in);
fid.assign(Fallible::Invalid(Arc::new(desc.label.to_string())));
}
/// Assign `id_in` an error with the given `label`.
@ -1103,13 +1102,13 @@ impl Global {
Err(e) => break 'error e,
};
let id = fid.assign(render_bundle);
let id = fid.assign(Fallible::Valid(render_bundle));
api_log!("RenderBundleEncoder::finish -> {id:?}");
return (id, None);
};
let id = fid.assign_error();
let id = fid.assign(Fallible::Invalid(Arc::new(desc.label.to_string())));
(id, Some(error))
}
@ -1119,9 +1118,11 @@ impl Global {
let hub = &self.hub;
if let Some(_bundle) = hub.render_bundles.unregister(render_bundle_id) {
#[cfg(feature = "trace")]
if let Some(t) = _bundle.device.trace.lock().as_mut() {
let _bundle = hub.render_bundles.strict_unregister(render_bundle_id);
#[cfg(feature = "trace")]
if let Ok(bundle) = _bundle.get() {
if let Some(t) = bundle.device.trace.lock().as_mut() {
t.add(trace::Action::DestroyRenderBundle(render_bundle_id));
}
}

View File

@ -170,7 +170,7 @@ pub struct Hub {
pub(crate) bind_group_layouts: Registry<Fallible<BindGroupLayout>>,
pub(crate) bind_groups: Registry<Fallible<BindGroup>>,
pub(crate) command_buffers: Registry<Arc<CommandBuffer>>,
pub(crate) render_bundles: Registry<Arc<RenderBundle>>,
pub(crate) render_bundles: Registry<Fallible<RenderBundle>>,
pub(crate) render_pipelines: Registry<Fallible<RenderPipeline>>,
pub(crate) compute_pipelines: Registry<Fallible<ComputePipeline>>,
pub(crate) pipeline_caches: Registry<Fallible<PipelineCache>>,