diff --git a/CHANGELOG.md b/CHANGELOG.md index beae54b7a7..6810ee3173 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -166,6 +166,7 @@ By @ErichDonGubler in [#6456](https://github.com/gfx-rs/wgpu/pull/6456), [#6148] - Check that at least one index is specified. - Reject destroyed buffers in query set resolution. By @ErichDonGubler in [#6579](https://github.com/gfx-rs/wgpu/pull/6579). - Fix panic when dropping `Device` on some environments. By @Dinnerbone in [#6681](https://github.com/gfx-rs/wgpu/pull/6681). +- Reduced the overhead of command buffer validation. By @nical in [#6721](https://github.com/gfx-rs/wgpu/pull/6721). #### Naga diff --git a/wgpu-core/src/device/queue.rs b/wgpu-core/src/device/queue.rs index 6ba9728e9e..a44b3241a6 100644 --- a/wgpu-core/src/device/queue.rs +++ b/wgpu-core/src/device/queue.rs @@ -1568,8 +1568,7 @@ fn validate_command_buffer( TextureInner::Native { .. } => false, TextureInner::Surface { .. } => { // Compare the Arcs by pointer as Textures don't implement Eq. - submit_surface_textures_owned - .insert(Arc::as_ptr(&texture), texture.clone()); + submit_surface_textures_owned.insert(Arc::as_ptr(texture), texture.clone()); true } @@ -1577,7 +1576,7 @@ fn validate_command_buffer( if should_extend { unsafe { used_surface_textures - .merge_single(&texture, None, hal::TextureUses::PRESENT) + .merge_single(texture, None, hal::TextureUses::PRESENT) .unwrap(); }; } diff --git a/wgpu-core/src/device/resource.rs b/wgpu-core/src/device/resource.rs index d41156f0b9..e80708c695 100644 --- a/wgpu-core/src/device/resource.rs +++ b/wgpu-core/src/device/resource.rs @@ -3637,12 +3637,12 @@ impl Device { // During these iterations, we discard all errors. We don't care! let trackers = self.trackers.lock(); for buffer in trackers.buffers.used_resources() { - if let Some(buffer) = Weak::upgrade(&buffer) { + if let Some(buffer) = Weak::upgrade(buffer) { let _ = buffer.destroy(); } } for texture in trackers.textures.used_resources() { - if let Some(texture) = Weak::upgrade(&texture) { + if let Some(texture) = Weak::upgrade(texture) { let _ = texture.destroy(); } } diff --git a/wgpu-core/src/track/buffer.rs b/wgpu-core/src/track/buffer.rs index 0cdc9dc966..cfd166070d 100644 --- a/wgpu-core/src/track/buffer.rs +++ b/wgpu-core/src/track/buffer.rs @@ -311,7 +311,7 @@ impl BufferTracker { } /// Returns a list of all buffers tracked. - pub fn used_resources(&self) -> impl Iterator> + '_ { + pub fn used_resources(&self) -> impl Iterator> + '_ { self.metadata.owned_resources() } @@ -559,7 +559,7 @@ impl DeviceBufferTracker { } /// Returns a list of all buffers tracked. - pub fn used_resources(&self) -> impl Iterator> + '_ { + pub fn used_resources(&self) -> impl Iterator> + '_ { self.metadata.owned_resources() } diff --git a/wgpu-core/src/track/metadata.rs b/wgpu-core/src/track/metadata.rs index 7ecb2773e3..8f03caf7b0 100644 --- a/wgpu-core/src/track/metadata.rs +++ b/wgpu-core/src/track/metadata.rs @@ -111,13 +111,13 @@ impl ResourceMetadata { } /// Returns an iterator over the resources owned by `self`. - pub(super) fn owned_resources(&self) -> impl Iterator + '_ { + pub(super) fn owned_resources(&self) -> impl Iterator + '_ { if !self.owned.is_empty() { self.tracker_assert_in_bounds(self.owned.len() - 1) }; iterate_bitvec_indices(&self.owned).map(move |index| { let resource = unsafe { self.resources.get_unchecked(index) }; - resource.as_ref().unwrap().clone() + resource.as_ref().unwrap() }) } diff --git a/wgpu-core/src/track/texture.rs b/wgpu-core/src/track/texture.rs index 8ea1e04cd1..82c6442095 100644 --- a/wgpu-core/src/track/texture.rs +++ b/wgpu-core/src/track/texture.rs @@ -429,10 +429,9 @@ impl TextureTracker { } /// Returns a list of all textures tracked. - pub fn used_resources(&self) -> impl Iterator> + '_ { + pub fn used_resources(&self) -> impl Iterator> + '_ { self.metadata.owned_resources() } - /// Drain all currently pending transitions. pub fn drain_transitions<'a>( &'a mut self, @@ -672,7 +671,7 @@ impl DeviceTextureTracker { } /// Returns a list of all textures tracked. - pub fn used_resources(&self) -> impl Iterator> + '_ { + pub fn used_resources(&self) -> impl Iterator> + '_ { self.metadata.owned_resources() }