diff --git a/wgpu-core/src/binding_model.rs b/wgpu-core/src/binding_model.rs index 9c19d72485..0d94b4b9a6 100644 --- a/wgpu-core/src/binding_model.rs +++ b/wgpu-core/src/binding_model.rs @@ -2,7 +2,7 @@ use crate::{ device::{ bgl, Device, DeviceError, MissingDownlevelFlags, MissingFeatures, SHADER_STAGE_COUNT, }, - error::{ErrorFormatter, PrettyError}, + error::PrettyError, hal_api::HalApi, id::{BindGroupLayoutId, BufferId, SamplerId, TextureViewId}, init_tracker::{BufferInitTrackerAction, TextureInitTrackerAction}, @@ -94,20 +94,20 @@ pub enum CreateBindGroupError { BindingArrayLengthMismatch { actual: usize, expected: usize }, #[error("Array binding provided zero elements")] BindingArrayZeroLength, - #[error("Bound buffer range {range:?} does not fit in buffer of size {size}")] + #[error("The bound range {range:?} of {buffer} overflows its size ({size})")] BindingRangeTooLarge { - buffer: BufferId, + buffer: ResourceErrorIdent, range: Range, size: u64, }, - #[error("Buffer binding size {actual} is less than minimum {min}")] + #[error("Binding size {actual} of {buffer} is less than minimum {min}")] BindingSizeTooSmall { - buffer: BufferId, + buffer: ResourceErrorIdent, actual: u64, min: u64, }, - #[error("Buffer binding size is zero")] - BindingZeroSize(BufferId), + #[error("{0} binding size is zero")] + BindingZeroSize(ResourceErrorIdent), #[error("Number of bindings in bind group descriptor ({actual}) does not match the number of bindings defined in the bind group layout ({expected})")] BindingsNumMismatch { actual: usize, expected: usize }, #[error("Binding {0} is used at least twice in the descriptor")] @@ -185,23 +185,7 @@ pub enum CreateBindGroupError { ResourceUsageCompatibility(#[from] ResourceUsageCompatibilityError), } -impl PrettyError for CreateBindGroupError { - fn fmt_pretty(&self, fmt: &mut ErrorFormatter) { - fmt.error(self); - match *self { - Self::BindingZeroSize(id) => { - fmt.buffer_label(&id); - } - Self::BindingRangeTooLarge { buffer, .. } => { - fmt.buffer_label(&buffer); - } - Self::BindingSizeTooSmall { buffer, .. } => { - fmt.buffer_label(&buffer); - } - _ => {} - }; - } -} +impl PrettyError for CreateBindGroupError {} #[derive(Clone, Debug, Error)] pub enum BindingZone { diff --git a/wgpu-core/src/device/resource.rs b/wgpu-core/src/device/resource.rs index 5e2c560dfb..bb5ad8ba93 100644 --- a/wgpu-core/src/device/resource.rs +++ b/wgpu-core/src/device/resource.rs @@ -1919,7 +1919,7 @@ impl Device { let end = bb.offset + size.get(); if end > buffer.size { return Err(Error::BindingRangeTooLarge { - buffer: bb.buffer_id, + buffer: buffer.error_ident(), range: bb.offset..end, size: buffer.size, }); @@ -1929,7 +1929,7 @@ impl Device { None => { if buffer.size < bb.offset { return Err(Error::BindingRangeTooLarge { - buffer: bb.buffer_id, + buffer: buffer.error_ident(), range: bb.offset..bb.offset, size: buffer.size, }); @@ -1961,14 +1961,14 @@ impl Device { let min_size = non_zero.get(); if min_size > bind_size { return Err(Error::BindingSizeTooSmall { - buffer: bb.buffer_id, + buffer: buffer.error_ident(), actual: bind_size, min: min_size, }); } } else { - let late_size = - wgt::BufferSize::new(bind_size).ok_or(Error::BindingZeroSize(bb.buffer_id))?; + let late_size = wgt::BufferSize::new(bind_size) + .ok_or_else(|| Error::BindingZeroSize(buffer.error_ident()))?; late_buffer_binding_sizes.insert(binding, late_size); }