diff --git a/wgpu-core/src/binding_model.rs b/wgpu-core/src/binding_model.rs index bc7628879..520f9a474 100644 --- a/wgpu-core/src/binding_model.rs +++ b/wgpu-core/src/binding_model.rs @@ -14,7 +14,7 @@ use crate::{ }, resource_log, snatch::{SnatchGuard, Snatchable}, - track::{BindGroupStates, UsageConflict}, + track::{BindGroupStates, ResourceUsageCompatibilityError}, Label, }; @@ -184,7 +184,7 @@ pub enum CreateBindGroupError { #[error("The adapter does not support read access for storages texture of format {0:?}")] StorageReadNotSupported(wgt::TextureFormat), #[error(transparent)] - ResourceUsageConflict(#[from] UsageConflict), + ResourceUsageCompatibility(#[from] ResourceUsageCompatibilityError), } impl PrettyError for CreateBindGroupError { diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index 4be9102d2..8f52738e6 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -17,7 +17,7 @@ use crate::{ init_tracker::MemoryInitKind, resource::{self, DestroyedResourceError, MissingBufferUsageError, ParentDevice, Resource}, snatch::SnatchGuard, - track::{Tracker, TrackerIndex, UsageConflict, UsageScope}, + track::{ResourceUsageCompatibilityError, Tracker, TrackerIndex, UsageScope}, Label, }; @@ -177,7 +177,7 @@ pub enum ComputePassErrorInner { #[error("BufferId {0:?} is invalid")] InvalidBufferId(id::BufferId), #[error(transparent)] - ResourceUsageConflict(#[from] UsageConflict), + ResourceUsageCompatibility(#[from] ResourceUsageCompatibilityError), #[error(transparent)] MissingBufferUsage(#[from] MissingBufferUsageError), #[error("Cannot pop debug group, because number of pushed debug groups is zero")] @@ -285,7 +285,7 @@ impl<'a, A: HalApi> State<'a, A> { base_trackers: &mut Tracker, indirect_buffer: Option, snatch_guard: &SnatchGuard, - ) -> Result<(), UsageConflict> { + ) -> Result<(), ResourceUsageCompatibilityError> { for bind_group in self.binder.list_active() { unsafe { self.scope.merge_bind_group(&bind_group.used)? }; // Note: stateless trackers are not merged: the lifetime reference diff --git a/wgpu-core/src/command/draw.rs b/wgpu-core/src/command/draw.rs index c6c11fc35..125fbdf8e 100644 --- a/wgpu-core/src/command/draw.rs +++ b/wgpu-core/src/command/draw.rs @@ -10,7 +10,7 @@ use crate::{ resource::{ Buffer, DestroyedResourceError, MissingBufferUsageError, MissingTextureUsageError, QuerySet, }, - track::UsageConflict, + track::ResourceUsageCompatibilityError, }; use wgt::{BufferAddress, BufferSize, Color, VertexStepMode}; @@ -93,7 +93,7 @@ pub enum RenderCommandError { #[error("Pipeline writes to depth/stencil, while the pass has read-only depth/stencil")] IncompatiblePipelineRods, #[error(transparent)] - UsageConflict(#[from] UsageConflict), + ResourceUsageCompatibility(#[from] ResourceUsageCompatibilityError), #[error(transparent)] DestroyedResource(#[from] DestroyedResourceError), #[error(transparent)] diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index 24bcced40..8b2bcc997 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -29,7 +29,7 @@ use crate::{ QuerySet, Texture, TextureView, TextureViewNotRenderableReason, }, storage::Storage, - track::{TextureSelector, Tracker, UsageConflict, UsageScope}, + track::{ResourceUsageCompatibilityError, TextureSelector, Tracker, UsageScope}, Label, }; @@ -628,7 +628,7 @@ pub enum RenderPassErrorInner { #[error("Cannot pop debug group, because number of pushed debug groups is zero")] InvalidPopDebugGroup, #[error(transparent)] - ResourceUsageConflict(#[from] UsageConflict), + ResourceUsageCompatibility(#[from] ResourceUsageCompatibilityError), #[error("Render bundle has incompatible targets, {0}")] IncompatibleBundleTargets(#[from] RenderPassCompatibilityError), #[error( @@ -1252,10 +1252,11 @@ impl<'a, 'd, A: HalApi> RenderPassInfo<'a, 'd, A> { // the tracker set of the pass is always in "extend" mode unsafe { - self.usage_scope - .textures - .merge_single(texture, Some(ra.selector.clone()), ra.usage) - .map_err(UsageConflict::from)? + self.usage_scope.textures.merge_single( + texture, + Some(ra.selector.clone()), + ra.usage, + )? }; } diff --git a/wgpu-core/src/error.rs b/wgpu-core/src/error.rs index 91b46261a..c55be1039 100644 --- a/wgpu-core/src/error.rs +++ b/wgpu-core/src/error.rs @@ -138,7 +138,8 @@ pub fn format_pretty_any( if let Some(pretty_err) = error.downcast_ref::() { return pretty_err.fmt_pretty(&mut fmt); } - if let Some(pretty_err) = error.downcast_ref::() { + if let Some(pretty_err) = error.downcast_ref::() + { return pretty_err.fmt_pretty(&mut fmt); } if let Some(pretty_err) = error.downcast_ref::() { diff --git a/wgpu-core/src/track/buffer.rs b/wgpu-core/src/track/buffer.rs index f098b1d59..4b75321f9 100644 --- a/wgpu-core/src/track/buffer.rs +++ b/wgpu-core/src/track/buffer.rs @@ -16,7 +16,7 @@ use crate::{ snatch::SnatchGuard, track::{ invalid_resource_state, skip_barrier, ResourceMetadata, ResourceMetadataProvider, - ResourceUses, UsageConflict, + ResourceUsageCompatibilityError, ResourceUses, }, }; use hal::{BufferBarrier, BufferUses}; @@ -158,7 +158,7 @@ impl BufferUsageScope { pub unsafe fn merge_bind_group( &mut self, bind_group: &BufferBindGroupState, - ) -> Result<(), UsageConflict> { + ) -> Result<(), ResourceUsageCompatibilityError> { let buffers = bind_group.buffers.lock(); for &(ref resource, state) in &*buffers { let index = resource.as_info().tracker_index().as_usize(); @@ -188,7 +188,10 @@ impl BufferUsageScope { /// /// If the given tracker uses IDs higher than the length of internal vectors, /// the vectors will be extended. A call to set_size is not needed. - pub fn merge_usage_scope(&mut self, scope: &Self) -> Result<(), UsageConflict> { + pub fn merge_usage_scope( + &mut self, + scope: &Self, + ) -> Result<(), ResourceUsageCompatibilityError> { let incoming_size = scope.state.len(); if incoming_size > self.state.len() { self.set_size(incoming_size); @@ -229,7 +232,7 @@ impl BufferUsageScope { &mut self, buffer: &Arc>, new_state: BufferUses, - ) -> Result<(), UsageConflict> { + ) -> Result<(), ResourceUsageCompatibilityError> { let index = buffer.info.tracker_index().as_usize(); self.allow_index(index); @@ -641,7 +644,7 @@ unsafe fn insert_or_merge( index: usize, state_provider: BufferStateProvider<'_>, metadata_provider: ResourceMetadataProvider<'_, Buffer>, -) -> Result<(), UsageConflict> { +) -> Result<(), ResourceUsageCompatibilityError> { let currently_owned = unsafe { resource_metadata.contains_unchecked(index) }; if !currently_owned { @@ -760,14 +763,14 @@ unsafe fn merge( index: usize, state_provider: BufferStateProvider<'_>, metadata_provider: ResourceMetadataProvider<'_, Buffer>, -) -> Result<(), UsageConflict> { +) -> Result<(), ResourceUsageCompatibilityError> { let current_state = unsafe { current_states.get_unchecked_mut(index) }; let new_state = unsafe { state_provider.get_state(index) }; let merged_state = *current_state | new_state; if invalid_resource_state(merged_state) { - return Err(UsageConflict::from_buffer( + return Err(ResourceUsageCompatibilityError::from_buffer( unsafe { metadata_provider.get(index) }, *current_state, new_state, diff --git a/wgpu-core/src/track/mod.rs b/wgpu-core/src/track/mod.rs index 794c3905b..0071b6e00 100644 --- a/wgpu-core/src/track/mod.rs +++ b/wgpu-core/src/track/mod.rs @@ -339,7 +339,7 @@ fn skip_barrier(old_state: T, new_state: T) -> bool { } #[derive(Clone, Debug, Error)] -pub enum UsageConflict { +pub enum ResourceUsageCompatibilityError { #[error("Attempted to use {res} with {invalid_use}.")] Buffer { res: ResourceErrorIdent, @@ -356,7 +356,7 @@ pub enum UsageConflict { }, } -impl UsageConflict { +impl ResourceUsageCompatibilityError { fn from_buffer( buffer: &resource::Buffer, current_state: hal::BufferUses, @@ -389,7 +389,7 @@ impl UsageConflict { } } -impl crate::error::PrettyError for UsageConflict { +impl crate::error::PrettyError for ResourceUsageCompatibilityError { fn fmt_pretty(&self, fmt: &mut crate::error::ErrorFormatter) { fmt.error(self); } @@ -509,7 +509,7 @@ impl RenderBundleScope { pub unsafe fn merge_bind_group( &mut self, bind_group: &BindGroupStates, - ) -> Result<(), UsageConflict> { + ) -> Result<(), ResourceUsageCompatibilityError> { unsafe { self.buffers.write().merge_bind_group(&bind_group.buffers)? }; unsafe { self.textures @@ -579,7 +579,7 @@ impl<'a, A: HalApi> UsageScope<'a, A> { pub unsafe fn merge_bind_group( &mut self, bind_group: &BindGroupStates, - ) -> Result<(), UsageConflict> { + ) -> Result<(), ResourceUsageCompatibilityError> { unsafe { self.buffers.merge_bind_group(&bind_group.buffers)?; self.textures.merge_bind_group(&bind_group.textures)?; @@ -600,7 +600,7 @@ impl<'a, A: HalApi> UsageScope<'a, A> { pub unsafe fn merge_render_bundle( &mut self, render_bundle: &RenderBundleScope, - ) -> Result<(), UsageConflict> { + ) -> Result<(), ResourceUsageCompatibilityError> { self.buffers .merge_usage_scope(&*render_bundle.buffers.read())?; self.textures @@ -691,7 +691,7 @@ impl Tracker { pub unsafe fn add_from_render_bundle( &mut self, render_bundle: &RenderBundleScope, - ) -> Result<(), UsageConflict> { + ) -> Result<(), ResourceUsageCompatibilityError> { self.bind_groups .add_from_tracker(&*render_bundle.bind_groups.read()); self.render_pipelines diff --git a/wgpu-core/src/track/texture.rs b/wgpu-core/src/track/texture.rs index ffd9fd52e..bd5b2a93b 100644 --- a/wgpu-core/src/track/texture.rs +++ b/wgpu-core/src/track/texture.rs @@ -30,7 +30,7 @@ use crate::{ snatch::SnatchGuard, track::{ invalid_resource_state, skip_barrier, ResourceMetadata, ResourceMetadataProvider, - ResourceUses, UsageConflict, + ResourceUsageCompatibilityError, ResourceUses, }, }; use hal::TextureUses; @@ -295,7 +295,10 @@ impl TextureUsageScope { /// /// If the given tracker uses IDs higher than the length of internal vectors, /// the vectors will be extended. A call to set_size is not needed. - pub fn merge_usage_scope(&mut self, scope: &Self) -> Result<(), UsageConflict> { + pub fn merge_usage_scope( + &mut self, + scope: &Self, + ) -> Result<(), ResourceUsageCompatibilityError> { let incoming_size = scope.set.simple.len(); if incoming_size > self.set.simple.len() { self.set_size(incoming_size); @@ -339,7 +342,7 @@ impl TextureUsageScope { pub unsafe fn merge_bind_group( &mut self, bind_group: &TextureBindGroupState, - ) -> Result<(), UsageConflict> { + ) -> Result<(), ResourceUsageCompatibilityError> { let textures = bind_group.textures.lock(); for t in &*textures { unsafe { self.merge_single(&t.texture, t.selector.clone(), t.usage)? }; @@ -366,7 +369,7 @@ impl TextureUsageScope { texture: &Arc>, selector: Option, new_state: TextureUses, - ) -> Result<(), UsageConflict> { + ) -> Result<(), ResourceUsageCompatibilityError> { let index = texture.as_info().tracker_index().as_usize(); self.tracker_assert_in_bounds(index); @@ -883,7 +886,7 @@ unsafe fn insert_or_merge( index: usize, state_provider: TextureStateProvider<'_>, metadata_provider: ResourceMetadataProvider<'_, Texture>, -) -> Result<(), UsageConflict> { +) -> Result<(), ResourceUsageCompatibilityError> { let currently_owned = unsafe { resource_metadata.contains_unchecked(index) }; if !currently_owned { @@ -1076,7 +1079,7 @@ unsafe fn merge( index: usize, state_provider: TextureStateProvider<'_>, metadata_provider: ResourceMetadataProvider<'_, Texture>, -) -> Result<(), UsageConflict> { +) -> Result<(), ResourceUsageCompatibilityError> { let current_simple = unsafe { current_state_set.simple.get_unchecked_mut(index) }; let current_state = if *current_simple == TextureUses::COMPLEX { SingleOrManyStates::Many(unsafe { @@ -1095,7 +1098,7 @@ unsafe fn merge( log::trace!("\ttex {index}: merge simple {current_simple:?} + {new_simple:?}"); if invalid_resource_state(merged_state) { - return Err(UsageConflict::from_texture( + return Err(ResourceUsageCompatibilityError::from_texture( unsafe { metadata_provider.get(index) }, texture_selector.clone(), *current_simple, @@ -1122,7 +1125,7 @@ unsafe fn merge( log::trace!("\ttex {index}: merge {selector:?} {current_simple:?} + {new_state:?}"); if invalid_resource_state(merged_state) { - return Err(UsageConflict::from_texture( + return Err(ResourceUsageCompatibilityError::from_texture( unsafe { metadata_provider.get(index) }, selector, *current_simple, @@ -1163,7 +1166,7 @@ unsafe fn merge( ); if invalid_resource_state(merged_state) { - return Err(UsageConflict::from_texture( + return Err(ResourceUsageCompatibilityError::from_texture( unsafe { metadata_provider.get(index) }, TextureSelector { mips: mip_id..mip_id + 1, @@ -1204,7 +1207,7 @@ unsafe fn merge( ); if invalid_resource_state(merged_state) { - return Err(UsageConflict::from_texture( + return Err(ResourceUsageCompatibilityError::from_texture( unsafe { metadata_provider.get(index) }, TextureSelector { mips: mip_id..mip_id + 1,