From 97a038a7681f6ccfc3ec9e3f510a0977cec48a14 Mon Sep 17 00:00:00 2001 From: teoxoy <28601907+teoxoy@users.noreply.github.com> Date: Thu, 20 Jun 2024 00:56:09 +0200 Subject: [PATCH] make return type of `TextureTracker.set_single` non-optional --- wgpu-core/src/command/clear.rs | 1 - wgpu-core/src/command/transfer.rs | 36 +++++++++++++++---------------- wgpu-core/src/device/queue.rs | 16 +++++++------- wgpu-core/src/track/texture.rs | 4 ++-- 4 files changed, 28 insertions(+), 29 deletions(-) diff --git a/wgpu-core/src/command/clear.rs b/wgpu-core/src/command/clear.rs index 694b437c4..578346d98 100644 --- a/wgpu-core/src/command/clear.rs +++ b/wgpu-core/src/command/clear.rs @@ -304,7 +304,6 @@ pub(crate) fn clear_texture( // change_replace_tracked whenever possible. let dst_barrier = texture_tracker .set_single(dst_texture, selector, clear_usage) - .unwrap() .map(|pending| pending.into_hal(dst_raw)); unsafe { encoder.transition_textures(dst_barrier.into_iter()); diff --git a/wgpu-core/src/command/transfer.rs b/wgpu-core/src/command/transfer.rs index b20a8cbfd..bde24f5e8 100644 --- a/wgpu-core/src/command/transfer.rs +++ b/wgpu-core/src/command/transfer.rs @@ -814,10 +814,10 @@ impl Global { } let src_barrier = src_pending.map(|pending| pending.into_hal(&src_buffer, &snatch_guard)); - let dst_pending = tracker - .textures - .set_single(&dst_texture, dst_range, hal::TextureUses::COPY_DST) - .ok_or(TransferError::InvalidTexture(destination.texture))?; + let dst_pending = + tracker + .textures + .set_single(&dst_texture, dst_range, hal::TextureUses::COPY_DST); let dst_raw = dst_texture .raw(&snatch_guard) .ok_or(TransferError::InvalidTexture(destination.texture))?; @@ -952,10 +952,10 @@ impl Global { &snatch_guard, )?; - let src_pending = tracker - .textures - .set_single(&src_texture, src_range, hal::TextureUses::COPY_SRC) - .ok_or(TransferError::InvalidTexture(source.texture))?; + let src_pending = + tracker + .textures + .set_single(&src_texture, src_range, hal::TextureUses::COPY_SRC); let src_raw = src_texture .raw(&snatch_guard) .ok_or(TransferError::InvalidTexture(source.texture))?; @@ -1169,11 +1169,11 @@ impl Global { &snatch_guard, )?; - let src_pending = cmd_buf_data - .trackers - .textures - .set_single(&src_texture, src_range, hal::TextureUses::COPY_SRC) - .ok_or(TransferError::InvalidTexture(source.texture))?; + let src_pending = cmd_buf_data.trackers.textures.set_single( + &src_texture, + src_range, + hal::TextureUses::COPY_SRC, + ); let src_raw = src_texture .raw(&snatch_guard) .ok_or(TransferError::InvalidTexture(source.texture))?; @@ -1187,11 +1187,11 @@ impl Global { .map(|pending| pending.into_hal(src_raw)) .collect(); - let dst_pending = cmd_buf_data - .trackers - .textures - .set_single(&dst_texture, dst_range, hal::TextureUses::COPY_DST) - .ok_or(TransferError::InvalidTexture(destination.texture))?; + let dst_pending = cmd_buf_data.trackers.textures.set_single( + &dst_texture, + dst_range, + hal::TextureUses::COPY_DST, + ); let dst_raw = dst_texture .raw(&snatch_guard) .ok_or(TransferError::InvalidTexture(destination.texture))?; diff --git a/wgpu-core/src/device/queue.rs b/wgpu-core/src/device/queue.rs index 4e8f2320a..9ca2bd1f0 100644 --- a/wgpu-core/src/device/queue.rs +++ b/wgpu-core/src/device/queue.rs @@ -909,10 +909,10 @@ impl Global { }; let mut trackers = device.trackers.lock(); - let transition = trackers - .textures - .set_single(&dst, selector, hal::TextureUses::COPY_DST) - .ok_or(TransferError::InvalidTexture(destination.texture))?; + let transition = + trackers + .textures + .set_single(&dst, selector, hal::TextureUses::COPY_DST); unsafe { encoder.transition_textures(transition.map(|pending| pending.into_hal(dst_raw))); encoder.transition_buffers(iter::once(barrier)); @@ -1110,10 +1110,10 @@ impl Global { unsafe { let mut trackers = device.trackers.lock(); - let transitions = trackers - .textures - .set_single(&dst, selector, hal::TextureUses::COPY_DST) - .ok_or(TransferError::InvalidTexture(destination.texture))?; + let transitions = + trackers + .textures + .set_single(&dst, selector, hal::TextureUses::COPY_DST); encoder.transition_textures(transitions.map(|pending| pending.into_hal(dst_raw))); encoder.copy_external_image_to_texture( source, diff --git a/wgpu-core/src/track/texture.rs b/wgpu-core/src/track/texture.rs index b3ec79681..137cc55a5 100644 --- a/wgpu-core/src/track/texture.rs +++ b/wgpu-core/src/track/texture.rs @@ -575,7 +575,7 @@ impl TextureTracker { texture: &Arc>, selector: TextureSelector, new_state: TextureUses, - ) -> Option>> { + ) -> Drain<'_, PendingTransition> { let index = texture.as_info().tracker_index().as_usize(); self.allow_index(index); @@ -601,7 +601,7 @@ impl TextureTracker { ) } - Some(self.temp.drain(..)) + self.temp.drain(..) } /// Sets the given state for all texture in the given tracker.