Skip to content

Surface::get_current_texture does not block when the window is fully invisible (macOS) #4779

@ComfyFluffy

Description

@ComfyFluffy

Description
I am currently following a WGPU Tutorial and have implemented Hello Triangle with vertex buffers.
image

When I click the green button to expand the window into fullscreen, the process will suddenly take up to 22GB of memory:
image

After a few seconds, the memory usage goes down:
image

image

Repro steps
I have uploaded the code onto GitHub.

git clone https://github.com/ComfyFluffy/wgpu-tutorial.git
cd wgpu-tutorial
RUST_LOG=info MTL_HUD_ENABLED=1 cargo run

Then expand the app to fullscreen.

If expanding to fullscreen does not cause memory peak, switching to other desktop then switch back to the app can also cause it.

Resizing on windowed mode does not trigger the behavior.

Resizing on Windows 11 does not trigger the behavior.

Expected vs observed behavior

Expected: The memory usage should remain largely the same during resizing.
Observed: The memory usage goes up to 22 GB.

Extra materials
Info log logged by env_logger. Memory peak happened during resizing.

[2023-11-26T06:43:52Z INFO  wgpu_core::instance] Adapter Metal AdapterInfo { name: "Apple M1 Pro", vendor: 0, device: 0, device_type: IntegratedGpu, driver: "", driver_info: "", backend: Metal }
[2023-11-26T06:43:52Z INFO  wgpu_core::device::global] configuring surface with SurfaceConfiguration { usage: TextureUsages(RENDER_ATTACHMENT), format: Bgra8UnormSrgb, width: 1600, height: 1200, present_mode: Fifo, alpha_mode: Opaque, view_formats: [] }
[2023-11-26T06:43:52Z INFO  wgpu_hal::metal::surface] build swapchain SurfaceConfiguration { swap_chain_size: 3, present_mode: Fifo, composite_alpha_mode: Opaque, format: Bgra8UnormSrgb, extent: Extent3d { width: 1600, height: 1200, depth_or_array_layers: 1 }, usage: TextureUses(COLOR_TARGET), view_formats: [] }
[2023-11-26T06:43:52Z INFO  wgpu_core::device::global] configuring surface with SurfaceConfiguration { usage: TextureUsages(RENDER_ATTACHMENT), format: Bgra8UnormSrgb, width: 1600, height: 1200, present_mode: AutoVsync, alpha_mode: Opaque, view_formats: [] }
[2023-11-26T06:43:52Z INFO  wgpu_core::device::global] Automatically choosing presentation mode by rule AutoVsync. Chose Fifo
[2023-11-26T06:43:52Z INFO  wgpu_hal::metal::surface] build swapchain SurfaceConfiguration { swap_chain_size: 3, present_mode: Fifo, composite_alpha_mode: Opaque, format: Bgra8UnormSrgb, extent: Extent3d { width: 1600, height: 1200, depth_or_array_layers: 1 }, usage: TextureUses(COLOR_TARGET), view_formats: [] }
[2023-11-26T06:43:53Z INFO  wgpu_core::device::global] configuring surface with SurfaceConfiguration { usage: TextureUsages(RENDER_ATTACHMENT), format: Bgra8UnormSrgb, width: 1600, height: 1200, present_mode: AutoVsync, alpha_mode: Opaque, view_formats: [] }
[2023-11-26T06:43:53Z INFO  wgpu_core::device::global] Automatically choosing presentation mode by rule AutoVsync. Chose Fifo
[2023-11-26T06:43:53Z INFO  wgpu_hal::metal::surface] build swapchain SurfaceConfiguration { swap_chain_size: 3, present_mode: Fifo, composite_alpha_mode: Opaque, format: Bgra8UnormSrgb, extent: Extent3d { width: 1600, height: 1200, depth_or_array_layers: 1 }, usage: TextureUses(COLOR_TARGET), view_formats: [] }
[2023-11-26T06:43:56Z INFO  wgpu_core::device::global] configuring surface with SurfaceConfiguration { usage: TextureUsages(RENDER_ATTACHMENT), format: Bgra8UnormSrgb, width: 1600, height: 1256, present_mode: AutoVsync, alpha_mode: Opaque, view_formats: [] }
[2023-11-26T06:43:56Z INFO  wgpu_core::device::global] Automatically choosing presentation mode by rule AutoVsync. Chose Fifo
[2023-11-26T06:43:56Z INFO  wgpu_hal::metal::surface] build swapchain SurfaceConfiguration { swap_chain_size: 3, present_mode: Fifo, composite_alpha_mode: Opaque, format: Bgra8UnormSrgb, extent: Extent3d { width: 1600, height: 1256, depth_or_array_layers: 1 }, usage: TextureUses(COLOR_TARGET), view_formats: [] }
[2023-11-26T06:43:56Z INFO  wgpu_core::device::global] configuring surface with SurfaceConfiguration { usage: TextureUsages(RENDER_ATTACHMENT), format: Bgra8UnormSrgb, width: 5120, height: 2880, present_mode: AutoVsync, alpha_mode: Opaque, view_formats: [] }
[2023-11-26T06:43:56Z INFO  wgpu_core::device::global] Automatically choosing presentation mode by rule AutoVsync. Chose Fifo
[2023-11-26T06:43:56Z INFO  wgpu_hal::metal::surface] build swapchain SurfaceConfiguration { swap_chain_size: 3, present_mode: Fifo, composite_alpha_mode: Opaque, format: Bgra8UnormSrgb, extent: Extent3d { width: 5120, height: 2880, depth_or_array_layers: 1 }, usage: TextureUses(COLOR_TARGET), view_formats: [] }

Platform
Macbook Pro 14 (2021), M1 Pro with macOS Sonoma, 16 GB Memory
wgpu: 0.18.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    backend: metalIssues with Metalexternal: upstreamIssues happening in lower level APIs or platformshelp requiredWe need community help to make this happen.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions