From 8465a64104e86e3b7b6432dc02580e36dd982619 Mon Sep 17 00:00:00 2001 From: teoxoy <28601907+teoxoy@users.noreply.github.com> Date: Wed, 19 Jun 2024 14:54:15 +0200 Subject: [PATCH] remove usage of Texture IDs in clear code --- wgpu-core/src/command/clear.rs | 20 +++++++++++--------- wgpu-core/src/command/memory_init.rs | 4 ++-- wgpu-core/src/command/mod.rs | 4 ++-- wgpu-core/src/device/queue.rs | 13 +++++++------ 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/wgpu-core/src/command/clear.rs b/wgpu-core/src/command/clear.rs index 66fb59ec7..a268a24a1 100644 --- a/wgpu-core/src/command/clear.rs +++ b/wgpu-core/src/command/clear.rs @@ -11,7 +11,7 @@ use crate::{ hal_api::HalApi, id::{BufferId, CommandEncoderId, TextureId}, init_tracker::{MemoryInitKind, TextureInitRange}, - resource::{ParentDevice, Resource, Texture, TextureClearMode}, + resource::{ParentDevice, Resource, ResourceErrorIdent, Texture, TextureClearMode}, snatch::SnatchGuard, track::{TextureSelector, TextureTracker}, }; @@ -28,10 +28,12 @@ pub enum ClearError { MissingClearTextureFeature, #[error("Buffer {0:?} is invalid or destroyed")] InvalidBuffer(BufferId), - #[error("Texture {0:?} is invalid or destroyed")] - InvalidTexture(TextureId), - #[error("Texture {0:?} can not be cleared")] - NoValidTextureClearMode(TextureId), + #[error("TextureId {0:?} is invalid")] + InvalidTextureId(TextureId), + #[error("{0} has been destroyed")] + Destroyed(ResourceErrorIdent), + #[error("{0} can not be cleared")] + NoValidTextureClearMode(ResourceErrorIdent), #[error("Buffer clear size {0:?} is not a multiple of `COPY_BUFFER_ALIGNMENT`")] UnalignedFillSize(BufferAddress), #[error("Buffer offset {0:?} is not a multiple of `COPY_BUFFER_ALIGNMENT`")] @@ -197,7 +199,7 @@ impl Global { let dst_texture = hub .textures .get(dst) - .map_err(|_| ClearError::InvalidTexture(dst))?; + .map_err(|_| ClearError::InvalidTextureId(dst))?; dst_texture.same_device_as(cmd_buf.as_ref())?; @@ -266,7 +268,7 @@ pub(crate) fn clear_texture( ) -> Result<(), ClearError> { let dst_raw = dst_texture .raw(snatch_guard) - .ok_or_else(|| ClearError::InvalidTexture(dst_texture.as_info().id()))?; + .ok_or_else(|| ClearError::Destroyed(dst_texture.error_ident()))?; // Issue the right barrier. let clear_usage = match *dst_texture.clear_mode.read() { @@ -279,7 +281,7 @@ pub(crate) fn clear_texture( } TextureClearMode::None => { return Err(ClearError::NoValidTextureClearMode( - dst_texture.as_info().id(), + dst_texture.error_ident(), )); } }; @@ -328,7 +330,7 @@ pub(crate) fn clear_texture( } TextureClearMode::None => { return Err(ClearError::NoValidTextureClearMode( - dst_texture.as_info().id(), + dst_texture.error_ident(), )); } } diff --git a/wgpu-core/src/command/memory_init.rs b/wgpu-core/src/command/memory_init.rs index 338cdf8f2..99f6c40cf 100644 --- a/wgpu-core/src/command/memory_init.rs +++ b/wgpu-core/src/command/memory_init.rs @@ -324,8 +324,8 @@ impl BakedCommands { // A Texture can be destroyed between the command recording // and now, this is out of our control so we have to handle // it gracefully. - if let Err(ClearError::InvalidTexture(id)) = clear_result { - return Err(DestroyedTextureError(id)); + if let Err(ClearError::Destroyed(ident)) = clear_result { + return Err(DestroyedTextureError(ident)); } // Other errors are unexpected. diff --git a/wgpu-core/src/command/mod.rs b/wgpu-core/src/command/mod.rs index 9c8bb7170..8d181a55b 100644 --- a/wgpu-core/src/command/mod.rs +++ b/wgpu-core/src/command/mod.rs @@ -29,7 +29,7 @@ use crate::lock::{rank, Mutex}; use crate::snatch::SnatchGuard; use crate::init_tracker::BufferInitTrackerAction; -use crate::resource::{ParentDevice, Resource, ResourceInfo, ResourceType}; +use crate::resource::{ParentDevice, Resource, ResourceErrorIdent, ResourceInfo, ResourceType}; use crate::track::{Tracker, UsageScope}; use crate::{api_log, global::Global, hal_api::HalApi, id, resource_log, Label}; @@ -244,7 +244,7 @@ pub(crate) struct BakedCommands { } pub(crate) struct DestroyedBufferError(pub id::BufferId); -pub(crate) struct DestroyedTextureError(pub id::TextureId); +pub(crate) struct DestroyedTextureError(pub ResourceErrorIdent); /// The mutable state of a [`CommandBuffer`]. pub struct CommandBufferMutable { diff --git a/wgpu-core/src/device/queue.rs b/wgpu-core/src/device/queue.rs index 0a3a4bef4..e76876394 100644 --- a/wgpu-core/src/device/queue.rs +++ b/wgpu-core/src/device/queue.rs @@ -17,7 +17,8 @@ use crate::{ lock::{rank, Mutex, RwLockWriteGuard}, resource::{ Buffer, BufferAccessError, BufferMapState, DestroyedBuffer, DestroyedTexture, ParentDevice, - Resource, ResourceInfo, ResourceType, StagingBuffer, Texture, TextureInner, + Resource, ResourceErrorIdent, ResourceInfo, ResourceType, StagingBuffer, Texture, + TextureInner, }, resource_log, track, FastHashMap, SubmissionIndex, }; @@ -373,8 +374,8 @@ pub enum QueueSubmitError { Queue(#[from] DeviceError), #[error("Buffer {0:?} is destroyed")] DestroyedBuffer(id::BufferId), - #[error("Texture {0:?} is destroyed")] - DestroyedTexture(id::TextureId), + #[error("{0} has been destroyed")] + DestroyedTexture(ResourceErrorIdent), #[error(transparent)] Unmap(#[from] BufferAccessError), #[error("Buffer {0:?} is still mapped")] @@ -1242,7 +1243,7 @@ impl Global { let should_extend = match texture.inner.get(&snatch_guard) { None => { return Err(QueueSubmitError::DestroyedTexture( - texture.info.id(), + texture.error_ident(), )); } Some(TextureInner::Native { .. }) => false, @@ -1421,10 +1422,10 @@ impl Global { { used_surface_textures.set_size(hub.textures.read().len()); - for (&id, texture) in pending_writes.dst_textures.iter() { + for texture in pending_writes.dst_textures.values() { match texture.inner.get(&snatch_guard) { None => { - return Err(QueueSubmitError::DestroyedTexture(id)); + return Err(QueueSubmitError::DestroyedTexture(texture.error_ident())); } Some(TextureInner::Native { .. }) => {} Some(TextureInner::Surface { ref raw, .. }) => {