Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MacOS Ventura and Sonoma memory leak #5394

Open
Aultus-defora opened this issue Mar 15, 2024 · 2 comments
Open

MacOS Ventura and Sonoma memory leak #5394

Aultus-defora opened this issue Mar 15, 2024 · 2 comments

Comments

@Aultus-defora
Copy link

Aultus-defora commented Mar 15, 2024

Description
Starting from MacOS Ventura, some Mac machines (there are Intel and M1 examples) using wgpu and apps using it accumulate memory over time.

Repro steps
With wgpu run cargo run --example boids --release; starting from v0.14; or cargo run --bin wgpu-examples boids --release on later versions. I tested trunk version too, so up to and including 0.19

Expected vs observed behavior
I expected old bevy apps to not accumulate memory after I updated MacOS. They do, as does even the wgpu boids example

Extra materials
Right when starting it has few memory usage:
Start

After some time:
WGPU memory

Platform
MacOS Sonoma 14.4 (23E214), Radeon Pro 560X 4 GB, memory 8 GB 2667 MHz DDR4.

@jimblandy jimblandy changed the title MacOS Ventura and Somona memory leak MacOS Ventura and Sonoma memory leak Apr 2, 2024
@jonmmease
Copy link

Hi, I believe I'm seeing the same memory leak behavior on Sonoma 14.4.1 (23E224) with Apple M1 Pro. But in my case, the difference in memory usage happened when updating wgpu from 0.18.0 to 0.19.0 (and is still present in 0.19.3).

I have a test suite that performs headless rendering to PNG following https://sotrh.github.io/learn-wgpu/showcase/windowless/. And while tests are running the memory usage remained steady with wgpu 0.18.0, but rises steadily in 0.19.3, finally crashing with this backtrace:

Backtrace
assertion failed: !ptr.is_null()
thread 'test_image_baselines::test_image_baseline::case_118' panicked at /Users/jonmmease/.cargo/registry/src/index.crates.io-6f17d22bba15001f/foreign-types-shared-0.3.1/src/lib.rs:72:9:
assertion failed: !ptr.is_null()
stack backtrace:
   0: rust_begin_unwind
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:645:5
   1: core::panicking::panic_fmt
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/panicking.rs:72:14
   2: core::panicking::panic
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/panicking.rs:144:5
   3: foreign_types_shared::ForeignTypeRef::from_ptr
             at /Users/jonmmease/.cargo/registry/src/index.crates.io-6f17d22bba15001f/foreign-types-shared-0.3.1/src/lib.rs:72:9
   4: <metal::commandqueue::CommandQueue as core::ops::deref::Deref>::deref
             at /Users/jonmmease/.cargo/registry/src/index.crates.io-6f17d22bba15001f/metal-0.27.0/src/commandqueue.rs:13:1
   5: wgpu_hal::metal::command::<impl wgpu_hal::CommandEncoder<wgpu_hal::metal::Api> for wgpu_hal::metal::CommandEncoder>::begin_encoding::{{closure}}
             at /Users/jonmmease/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-hal-0.19.3/src/metal/command.rs:179:17
   6: objc::rc::autorelease::autoreleasepool
             at /Users/jonmmease/.cargo/registry/src/index.crates.io-6f17d22bba15001f/objc-0.2.7/src/rc/autorelease.rs:29:5
   7: wgpu_hal::metal::command::<impl wgpu_hal::CommandEncoder<wgpu_hal::metal::Api> for wgpu_hal::metal::CommandEncoder>::begin_encoding
             at /Users/jonmmease/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-hal-0.19.3/src/metal/command.rs:175:19
   8: wgpu_core::device::queue::PendingWrites<A>::activate
             at /Users/jonmmease/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-core-0.19.3/src/device/queue.rs:265:17
   9: wgpu_core::device::resource::Device<A>::new
             at /Users/jonmmease/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-core-0.19.3/src/device/resource.rs:230:9
  10: wgpu_core::instance::Adapter<A>::create_device_and_queue_from_hal
             at /Users/jonmmease/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-core-0.19.3/src/instance.rs:306:29
  11: wgpu_core::instance::Adapter<A>::create_device_and_queue
             at /Users/jonmmease/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-core-0.19.3/src/instance.rs:381:9
  12: wgpu_core::instance::<impl wgpu_core::global::Global<G>>::adapter_request_device
             at /Users/jonmmease/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-core-0.19.3/src/instance.rs:1084:23
  13: <wgpu::backend::wgpu_core::ContextWgpuCore as wgpu::context::Context>::adapter_request_device
             at /Users/jonmmease/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-0.19.0/src/backend/wgpu_core.rs:587:44
  14: <T as wgpu::context::DynContext>::adapter_request_device
             at /Users/jonmmease/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-0.19.0/src/context.rs:2019:22
  15: wgpu::Adapter::request_device
             at /Users/jonmmease/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-0.19.0/src/lib.rs:2118:22
  16: avenger_wgpu::canvas::request_wgpu_device::{{closure}}
             at ./src/canvas.rs:360:8
  17: avenger_wgpu::canvas::PngCanvas::new::{{closure}}::{{closure}}
             at ./src/canvas.rs:635:61
  18: avenger_wgpu::canvas::PngCanvas::new::{{closure}}
             at ./src/canvas.rs:631:5
  19: pollster::block_on
             at /Users/jonmmease/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pollster-0.3.0/src/lib.rs:128:15
  20: test_image_baselines::test_image_baselines::test_image_baseline
             at ./tests/test_image_baselines.rs:217:30
  21: test_image_baselines::test_image_baselines::test_image_baseline::case_118
             at ./tests/test_image_baselines.rs:29:5
  22: test_image_baselines::test_image_baselines::test_image_baseline::case_118::{{closure}}
             at ./tests/test_image_baselines.rs:184:7
  23: core::ops::function::FnOnce::call_once
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/ops/function.rs:250:5
  24: core::ops::function::FnOnce::call_once
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/ops/function.rs:250:5

I'm happy to open a new issue if this doesn't sound like the same issue.

Is the boids example that @Aultus-defora demonstrated above a sufficient repro to debug this? Is there anything else that would be helpful from our side? Thanks!

@jonmmease
Copy link

Since it may be a different problem, I created a dedicate repro for the issue I'm seeing in #5529

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants