From 173839f298ccff994fa163a6ae4fbbb042951b8e Mon Sep 17 00:00:00 2001 From: Xiaopeng Li Date: Mon, 6 May 2024 18:53:03 +0800 Subject: [PATCH 1/7] Clean up weak references to texture views and bind groups (#5595) * Clean up weak references to texture views * add change to CHANGELOG.md * drop texture view before clean up * cleanup weak ref to bind groups * update changelog * Trim weak backlinks in their holders' triage functions. --------- Co-authored-by: Jim Blandy --- CHANGELOG.md | 9 +++++++++ wgpu-core/src/device/life.rs | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e15d2f287..86e67c46d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,15 @@ Bottom level categories: ## Unreleased +## v0.20.1 (2024-04-??) + +### Bug Fixes + +#### General + +- Clean up weak references to texture views and bind groups. By @xiaopengli89 [#5595](https://github.com/gfx-rs/wgpu/pull/5595). + + ## v0.20.0 (2024-04-28) ### Major Changes diff --git a/wgpu-core/src/device/life.rs b/wgpu-core/src/device/life.rs index 23f09682e4..1f1881ce9f 100644 --- a/wgpu-core/src/device/life.rs +++ b/wgpu-core/src/device/life.rs @@ -596,6 +596,18 @@ impl LifetimeTracker { &mut trackers.textures, |maps| &mut maps.textures, ); + + // We may have been suspected because a texture view or bind group + // referring to us was dropped. Remove stale weak references, so that + // the backlink table doesn't grow without bound. + for texture in self.suspected_resources.textures.values() { + texture.views.lock().retain(|view| view.strong_count() > 0); + texture + .bind_groups + .lock() + .retain(|bg| bg.strong_count() > 0); + } + self } @@ -621,6 +633,13 @@ impl LifetimeTracker { |maps| &mut maps.buffers, ); + // We may have been suspected because a bind group referring to us was + // dropped. Remove stale weak references, so that the backlink table + // doesn't grow without bound. + for buffer in self.suspected_resources.buffers.values() { + buffer.bind_groups.lock().retain(|bg| bg.strong_count() > 0); + } + self } From bc67f4cdf1d477242a6433bd5d0092009377cacb Mon Sep 17 00:00:00 2001 From: Connor Fitzgerald Date: Tue, 14 May 2024 10:21:53 -0400 Subject: [PATCH 2/7] Fix Subgroup Ops on VK 1.2 Device (#5624) --- CHANGELOG.md | 8 +++++--- wgpu-hal/src/vulkan/adapter.rs | 4 +--- wgpu-hal/src/vulkan/device.rs | 2 +- wgpu-hal/src/vulkan/mod.rs | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 86e67c46d4..500ad8fc6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,9 +37,7 @@ Bottom level categories: - Hal --> -## Unreleased - -## v0.20.1 (2024-04-??) +## Unreleased -- v0.20.1 (2024-04-??) ### Bug Fixes @@ -47,6 +45,10 @@ Bottom level categories: - Clean up weak references to texture views and bind groups. By @xiaopengli89 [#5595](https://github.com/gfx-rs/wgpu/pull/5595). +#### Vulkan + +- Fix enablement of subgroup ops extension on Vulkan devices that don't support Vulkan 1.3. By @cwfitzgerald in [#5624](https://github.com/gfx-rs/wgpu/pull/5624). + ## v0.20.0 (2024-04-28) diff --git a/wgpu-hal/src/vulkan/adapter.rs b/wgpu-hal/src/vulkan/adapter.rs index 21219361f4..bbf44feace 100644 --- a/wgpu-hal/src/vulkan/adapter.rs +++ b/wgpu-hal/src/vulkan/adapter.rs @@ -1485,9 +1485,6 @@ impl super::Instance { }), image_format_list: phd_capabilities.device_api_version >= vk::API_VERSION_1_2 || phd_capabilities.supports_extension(vk::KhrImageFormatListFn::name()), - subgroup_size_control: phd_features - .subgroup_size_control - .map_or(false, |ext| ext.subgroup_size_control == vk::TRUE), }; let capabilities = crate::Capabilities { limits: phd_capabilities.to_wgpu_limits(), @@ -1792,6 +1789,7 @@ impl super::Adapter { vendor_id: self.phd_capabilities.properties.vendor_id, timestamp_period: self.phd_capabilities.properties.limits.timestamp_period, private_caps: self.private_caps.clone(), + features, workarounds: self.workarounds, render_passes: Mutex::new(Default::default()), framebuffers: Mutex::new(Default::default()), diff --git a/wgpu-hal/src/vulkan/device.rs b/wgpu-hal/src/vulkan/device.rs index ec392533a0..aba36311de 100644 --- a/wgpu-hal/src/vulkan/device.rs +++ b/wgpu-hal/src/vulkan/device.rs @@ -789,7 +789,7 @@ impl super::Device { }; let mut flags = vk::PipelineShaderStageCreateFlags::empty(); - if self.shared.private_caps.subgroup_size_control { + if self.shared.features.contains(wgt::Features::SUBGROUP) { flags |= vk::PipelineShaderStageCreateFlags::ALLOW_VARYING_SUBGROUP_SIZE } diff --git a/wgpu-hal/src/vulkan/mod.rs b/wgpu-hal/src/vulkan/mod.rs index d1ea82772e..0dd361e0b6 100644 --- a/wgpu-hal/src/vulkan/mod.rs +++ b/wgpu-hal/src/vulkan/mod.rs @@ -238,7 +238,6 @@ struct PrivateCapabilities { robust_image_access2: bool, zero_initialize_workgroup_memory: bool, image_format_list: bool, - subgroup_size_control: bool, } bitflags::bitflags!( @@ -344,6 +343,7 @@ struct DeviceShared { timestamp_period: f32, private_caps: PrivateCapabilities, workarounds: Workarounds, + features: wgt::Features, render_passes: Mutex>, framebuffers: Mutex>, } From 2b154c5bc45a878a6d4c7835a1e0eb611783f94f Mon Sep 17 00:00:00 2001 From: Samson <16504129+sagudev@users.noreply.github.com> Date: Tue, 30 Apr 2024 17:39:56 +0200 Subject: [PATCH 3/7] Cast ptr to Device not Surface (#5640) --- CHANGELOG.md | 3 ++- wgpu-core/src/device/any_device.rs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 500ad8fc6c..38636fd59e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,7 +43,8 @@ Bottom level categories: #### General -- Clean up weak references to texture views and bind groups. By @xiaopengli89 [#5595](https://github.com/gfx-rs/wgpu/pull/5595). +- Clean up weak references to texture views and bind groups. By @xiaopengli89 in [#5595](https://github.com/gfx-rs/wgpu/pull/5595). +- Fix segfault on exit is queue & device are dropped before surface. By @sagudev in [#5640](https://github.com/gfx-rs/wgpu/pull/5640). #### Vulkan diff --git a/wgpu-core/src/device/any_device.rs b/wgpu-core/src/device/any_device.rs index 693155a753..9e459c1a94 100644 --- a/wgpu-core/src/device/any_device.rs +++ b/wgpu-core/src/device/any_device.rs @@ -34,7 +34,7 @@ impl AnyDevice { unsafe fn drop_glue(ptr: *mut ()) { // Drop the arc this instance is holding. unsafe { - _ = Arc::from_raw(ptr.cast::()); + _ = Arc::from_raw(ptr.cast::()); } } From 28fd4cc6f6de2a4b77009a42c97dff754abfbcdd Mon Sep 17 00:00:00 2001 From: Valaphee The Meerkat <32491319+valaphee@users.noreply.github.com> Date: Fri, 3 May 2024 22:29:27 +0200 Subject: [PATCH 4/7] Fix OpenGL non-srgb on Linux (#5642) --- CHANGELOG.md | 4 ++++ wgpu-hal/src/gles/egl.rs | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 38636fd59e..9c2625fb9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,10 @@ Bottom level categories: - Fix enablement of subgroup ops extension on Vulkan devices that don't support Vulkan 1.3. By @cwfitzgerald in [#5624](https://github.com/gfx-rs/wgpu/pull/5624). +#### GLES / OpenGL + +- Fix regression on OpenGL (EGL) where non-sRGB still used sRGB [#5642](https://github.com/gfx-rs/wgpu/pull/5642) + ## v0.20.0 (2024-04-28) ### Major Changes diff --git a/wgpu-hal/src/gles/egl.rs b/wgpu-hal/src/gles/egl.rs index 7494dcad76..a91358676c 100644 --- a/wgpu-hal/src/gles/egl.rs +++ b/wgpu-hal/src/gles/egl.rs @@ -1130,6 +1130,13 @@ impl Surface { unsafe { gl.bind_framebuffer(glow::DRAW_FRAMEBUFFER, None) }; unsafe { gl.bind_framebuffer(glow::READ_FRAMEBUFFER, Some(sc.framebuffer)) }; + + if !matches!(self.srgb_kind, SrgbFrameBufferKind::None) { + // Disable sRGB conversions for `glBlitFramebuffer` as behavior does diverge between + // drivers and formats otherwise and we want to ensure no sRGB conversions happen. + unsafe { gl.disable(glow::FRAMEBUFFER_SRGB) }; + } + // Note the Y-flipping here. GL's presentation is not flipped, // but main rendering is. Therefore, we Y-flip the output positions // in the shader, and also this blit. @@ -1147,6 +1154,11 @@ impl Surface { glow::NEAREST, ) }; + + if !matches!(self.srgb_kind, SrgbFrameBufferKind::None) { + unsafe { gl.enable(glow::FRAMEBUFFER_SRGB) }; + } + unsafe { gl.bind_framebuffer(glow::READ_FRAMEBUFFER, None) }; self.egl From 6d57c437c481498a8dc082952d1b97f80a5bb83e Mon Sep 17 00:00:00 2001 From: Connor Fitzgerald Date: Wed, 8 May 2024 20:45:11 -0400 Subject: [PATCH 5/7] Remove `#[doc(inline)]` to Prevent Doc Spam --- wgpu/src/lib.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index 2807c55cb9..bde91f4193 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -69,32 +69,27 @@ pub use wgt::{ /// Re-export of our `wgpu-core` dependency. /// #[cfg(wgpu_core)] -#[doc(inline)] pub use ::wgc as core; /// Re-export of our `wgpu-hal` dependency. /// /// #[cfg(wgpu_core)] -#[doc(inline)] pub use ::hal; /// Re-export of our `naga` dependency. /// #[cfg(wgpu_core)] #[cfg_attr(docsrs, doc(cfg(any(wgpu_core, naga))))] -#[doc(inline)] // We re-export wgpu-core's re-export of naga, as we may not have direct access to it. pub use ::wgc::naga; /// Re-export of our `naga` dependency. /// #[cfg(all(not(wgpu_core), naga))] #[cfg_attr(docsrs, doc(cfg(any(wgpu_core, naga))))] -#[doc(inline)] // If that's not available, we re-export our own. pub use naga; -#[doc(inline)] /// Re-export of our `raw-window-handle` dependency. /// pub use raw_window_handle as rwh; @@ -102,7 +97,6 @@ pub use raw_window_handle as rwh; /// Re-export of our `web-sys` dependency. /// #[cfg(any(webgl, webgpu))] -#[doc(inline)] pub use web_sys; // wasm-only types, we try to keep as many types non-platform From dfb345d15775750e699a3867721ce530aa34d3ef Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Sat, 18 May 2024 16:41:52 +0200 Subject: [PATCH 6/7] minor changelog improvement --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c2625fb9b..8036a3d933 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,7 +43,7 @@ Bottom level categories: #### General -- Clean up weak references to texture views and bind groups. By @xiaopengli89 in [#5595](https://github.com/gfx-rs/wgpu/pull/5595). +- Clean up weak references to texture views and bind groups to prevent memory leaks. By @xiaopengli89 in [#5595](https://github.com/gfx-rs/wgpu/pull/5595). - Fix segfault on exit is queue & device are dropped before surface. By @sagudev in [#5640](https://github.com/gfx-rs/wgpu/pull/5640). #### Vulkan From 1a1275a6990b07537e11a3d63661458493e8c94f Mon Sep 17 00:00:00 2001 From: Connor Fitzgerald Date: Sun, 28 Apr 2024 23:46:28 -0400 Subject: [PATCH 7/7] Fix Failure Case for MacOS 14.3 --- tests/tests/subgroup_operations/mod.rs | 16 ++++++++++++++-- tests/tests/subgroup_operations/shader.wgsl | 3 +++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/tests/tests/subgroup_operations/mod.rs b/tests/tests/subgroup_operations/mod.rs index c78cf131ac..2c518a9d93 100644 --- a/tests/tests/subgroup_operations/mod.rs +++ b/tests/tests/subgroup_operations/mod.rs @@ -11,10 +11,22 @@ static SUBGROUP_OPERATIONS: GpuTestConfiguration = GpuTestConfiguration::new() TestParameters::default() .features(wgpu::Features::SUBGROUP) .limits(wgpu::Limits::downlevel_defaults()) - .expect_fail(wgpu_test::FailureCase::molten_vk()) + // Expect metal to fail on tests involving operations in divergent control flow + // + // Newlines are included in the panic message to ensure that _additional_ failures + // are not matched against. + .expect_fail( + wgpu_test::FailureCase::molten_vk() + // 14.3 doesn't fail test 29 + .panic("thread 0 failed tests: 27,\nthread 1 failed tests: 27, 28,\n") + // Prior versions do. + .panic("thread 0 failed tests: 27, 29,\nthread 1 failed tests: 27, 28, 29,\n"), + ) .expect_fail( - // Expect metal to fail on tests involving operations in divergent control flow wgpu_test::FailureCase::backend(wgpu::Backends::METAL) + // 14.3 doesn't fail test 29 + .panic("thread 0 failed tests: 27,\nthread 1 failed tests: 27, 28,\n") + // Prior versions do. .panic("thread 0 failed tests: 27, 29,\nthread 1 failed tests: 27, 28, 29,\n"), ), ) diff --git a/tests/tests/subgroup_operations/shader.wgsl b/tests/tests/subgroup_operations/shader.wgsl index 7834514cb4..77cb81ce75 100644 --- a/tests/tests/subgroup_operations/shader.wgsl +++ b/tests/tests/subgroup_operations/shader.wgsl @@ -111,6 +111,7 @@ fn main( add_result_to_mask(&passed, 25u, subgroup_invocation_id == 0u || subgroupShuffleUp(subgroup_invocation_id, 1u) == subgroup_invocation_id - 1u); add_result_to_mask(&passed, 26u, subgroupShuffleXor(subgroup_invocation_id, subgroup_size - 1u) == (subgroup_invocation_id ^ (subgroup_size - 1u))); + // Mac/Apple will fail this test. var passed_27 = false; if subgroup_invocation_id % 2u == 0u { passed_27 |= subgroupAdd(1u) == (subgroup_size / 2u); @@ -119,6 +120,7 @@ fn main( } add_result_to_mask(&passed, 27u, passed_27); + // Mac/Apple will fail this test. var passed_28 = false; switch subgroup_invocation_id % 3u { case 0u: { @@ -134,6 +136,7 @@ fn main( } add_result_to_mask(&passed, 28u, passed_28); + // Mac/Apple will sometimes fail this test. MacOS 14.3 passes it, so the bug in the metal compiler seems to be fixed. expected = 0u; for (var i = subgroup_size; i >= 0u; i -= 1u) { expected = subgroupAdd(1u);