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/examples/src/framework.rs b/examples/src/framework.rs index 77eaf07712..9b7c4368e1 100644 --- a/examples/src/framework.rs +++ b/examples/src/framework.rs @@ -268,16 +268,7 @@ impl ExampleContext { async fn init_async(surface: &mut SurfaceWrapper, window: Arc) -> Self { log::info!("Initializing wgpu..."); - let backends = wgpu::util::backend_bits_from_env().unwrap_or_default(); - let dx12_shader_compiler = wgpu::util::dx12_shader_compiler_from_env().unwrap_or_default(); - let gles_minor_version = wgpu::util::gles_minor_version_from_env().unwrap_or_default(); - - let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { - backends, - flags: wgpu::InstanceFlags::from_build_config().with_env(), - dx12_shader_compiler, - gles_minor_version, - }); + let instance = wgpu::Instance::new(wgpu::util::instance_descriptor_from_env()); surface.pre_adapter(&instance, window); let adapter = get_adapter_with_capabilities_or_from_env( diff --git a/examples/src/hello_triangle/mod.rs b/examples/src/hello_triangle/mod.rs index 7c82d49cf0..27903795aa 100644 --- a/examples/src/hello_triangle/mod.rs +++ b/examples/src/hello_triangle/mod.rs @@ -10,7 +10,7 @@ async fn run(event_loop: EventLoop<()>, window: Window) { size.width = size.width.max(1); size.height = size.height.max(1); - let instance = wgpu::Instance::default(); + let instance = wgpu::Instance::new(wgpu::util::instance_descriptor_from_env()); let surface = instance.create_surface(&window).unwrap(); let adapter = instance 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() } diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index a366681ddf..4bf2f7e89a 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -559,7 +559,6 @@ bitflags::bitflags! { /// - `buffer myBuffer { ... } buffer_array[10]` (GLSL) /// /// Supported platforms: - /// - DX12 /// - Vulkan /// /// This is a native only feature. diff --git a/wgpu/src/util/init.rs b/wgpu/src/util/init.rs index 87f787bcb8..b4ff99ef87 100644 --- a/wgpu/src/util/init.rs +++ b/wgpu/src/util/init.rs @@ -138,6 +138,22 @@ pub fn gles_minor_version_from_env() -> Option { ) } +/// Get an instance descriptor from the following environment variables +/// - WGPU_BACKEND +/// - WGPU_DEBUG +/// - WGPU_VALIDATION +/// - WGPU_DX12_COMPILER +/// - WGPU_GLES_MINOR_VERSION +/// If variables are missing, falls back to default or build config values +pub fn instance_descriptor_from_env() -> wgt::InstanceDescriptor { + wgt::InstanceDescriptor { + backends: backend_bits_from_env().unwrap_or_default(), + flags: wgt::InstanceFlags::from_build_config().with_env(), + dx12_shader_compiler: dx12_shader_compiler_from_env().unwrap_or_default(), + gles_minor_version: gles_minor_version_from_env().unwrap_or_default(), + } +} + /// Determines whether the [`Backends::BROWSER_WEBGPU`] backend is supported. /// /// The result can only be true if this is called from the main thread or a dedicated worker.