rename UsageConflict to ResourceUsageCompatibilityError

This commit is contained in:
teoxoy 2024-06-20 13:57:40 +02:00 committed by Teodor Tanasoaia
parent 5f6848eddf
commit ef2da1a6d7
8 changed files with 46 additions and 38 deletions

View File

@ -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 {

View File

@ -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<A>,
indirect_buffer: Option<TrackerIndex>,
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

View File

@ -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)]

View File

@ -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,
)?
};
}

View File

@ -138,7 +138,8 @@ pub fn format_pretty_any(
if let Some(pretty_err) = error.downcast_ref::<crate::command::PassErrorScope>() {
return pretty_err.fmt_pretty(&mut fmt);
}
if let Some(pretty_err) = error.downcast_ref::<crate::track::UsageConflict>() {
if let Some(pretty_err) = error.downcast_ref::<crate::track::ResourceUsageCompatibilityError>()
{
return pretty_err.fmt_pretty(&mut fmt);
}
if let Some(pretty_err) = error.downcast_ref::<crate::command::QueryError>() {

View File

@ -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<A: HalApi> BufferUsageScope<A> {
pub unsafe fn merge_bind_group(
&mut self,
bind_group: &BufferBindGroupState<A>,
) -> 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<A: HalApi> BufferUsageScope<A> {
///
/// 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<A: HalApi> BufferUsageScope<A> {
&mut self,
buffer: &Arc<Buffer<A>>,
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<A: HalApi>(
index: usize,
state_provider: BufferStateProvider<'_>,
metadata_provider: ResourceMetadataProvider<'_, Buffer<A>>,
) -> Result<(), UsageConflict> {
) -> Result<(), ResourceUsageCompatibilityError> {
let currently_owned = unsafe { resource_metadata.contains_unchecked(index) };
if !currently_owned {
@ -760,14 +763,14 @@ unsafe fn merge<A: HalApi>(
index: usize,
state_provider: BufferStateProvider<'_>,
metadata_provider: ResourceMetadataProvider<'_, Buffer<A>>,
) -> 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,

View File

@ -339,7 +339,7 @@ fn skip_barrier<T: ResourceUses>(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<A: HalApi>(
buffer: &resource::Buffer<A>,
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<A: HalApi> RenderBundleScope<A> {
pub unsafe fn merge_bind_group(
&mut self,
bind_group: &BindGroupStates<A>,
) -> 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<A>,
) -> 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<A>,
) -> Result<(), UsageConflict> {
) -> Result<(), ResourceUsageCompatibilityError> {
self.buffers
.merge_usage_scope(&*render_bundle.buffers.read())?;
self.textures
@ -691,7 +691,7 @@ impl<A: HalApi> Tracker<A> {
pub unsafe fn add_from_render_bundle(
&mut self,
render_bundle: &RenderBundleScope<A>,
) -> Result<(), UsageConflict> {
) -> Result<(), ResourceUsageCompatibilityError> {
self.bind_groups
.add_from_tracker(&*render_bundle.bind_groups.read());
self.render_pipelines

View File

@ -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<A: HalApi> TextureUsageScope<A> {
///
/// 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<A: HalApi> TextureUsageScope<A> {
pub unsafe fn merge_bind_group(
&mut self,
bind_group: &TextureBindGroupState<A>,
) -> 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<A: HalApi> TextureUsageScope<A> {
texture: &Arc<Texture<A>>,
selector: Option<TextureSelector>,
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<A: HalApi>(
index: usize,
state_provider: TextureStateProvider<'_>,
metadata_provider: ResourceMetadataProvider<'_, Texture<A>>,
) -> Result<(), UsageConflict> {
) -> Result<(), ResourceUsageCompatibilityError> {
let currently_owned = unsafe { resource_metadata.contains_unchecked(index) };
if !currently_owned {
@ -1076,7 +1079,7 @@ unsafe fn merge<A: HalApi>(
index: usize,
state_provider: TextureStateProvider<'_>,
metadata_provider: ResourceMetadataProvider<'_, Texture<A>>,
) -> 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<A: HalApi>(
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<A: HalApi>(
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<A: HalApi>(
);
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<A: HalApi>(
);
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,