gfx-rs / wgpu

A cross-platform, safe, pure-Rust graphics API.
https://wgpu.rs
Apache License 2.0
12.53k stars 916 forks source link

[FreeBSD] Out of memory error on `Queue::write_texture` on high resolution pictures #6468

Open Canvis-Me opened 4 days ago

Canvis-Me commented 4 days ago

Description Program simp panic when open high resolution pictures, such as 8736x11658px.

Repro steps

Expected vs observed behavior simp open high resolution pictures normally.

Extra materials

panic.txt ``` 0: simp::main::{{closure}} at /usr/home/canvis/Downloads/simp/src/main.rs:448:25 1: std::panicking::rust_panic_with_hook 2: std::panicking::begin_panic_handler::{{closure}} 3: std::sys::backtrace::__rust_end_short_backtrace 4: rust_begin_unwind 5: core::panicking::panic_fmt 6: wgpu::backend::wgpu_core::default_error_handler at /home/canvis/.cargo/registry/src/mirrors.ustc.edu.cn-4affec411d11e50f/wgpu-22.1.0/src/backend/wgpu_core.rs:3411:5 7: core::ops::function::Fn::call at /rustc/f54dd915b0a4345ee06fd561416ad1af08b54dbb/library/core/src/ops/function.rs:79:5 8: as core::ops::function::Fn>::call at /rustc/f54dd915b0a4345ee06fd561416ad1af08b54dbb/library/alloc/src/boxed.rs:2084:9 9: wgpu::backend::wgpu_core::ErrorSinkRaw::handle_error at /home/canvis/.cargo/registry/src/mirrors.ustc.edu.cn-4affec411d11e50f/wgpu-22.1.0/src/backend/wgpu_core.rs:3397:17 10: wgpu::backend::wgpu_core::ContextWgpuCore::handle_error 11: wgpu::backend::wgpu_core::ContextWgpuCore::handle_error_nolabel at /home/canvis/.cargo/registry/src/mirrors.ustc.edu.cn-4affec411d11e50f/wgpu-22.1.0/src/backend/wgpu_core.rs:308:9 12: ::queue_write_texture at /home/canvis/.cargo/registry/src/mirrors.ustc.edu.cn-4affec411d11e50f/wgpu-22.1.0/src/backend/wgpu_core.rs:2272:22 13: ::queue_write_texture at /home/canvis/.cargo/registry/src/mirrors.ustc.edu.cn-4affec411d11e50f/wgpu-22.1.0/src/context.rs:3032:9 14: wgpu::Queue::write_texture at /home/canvis/.cargo/registry/src/mirrors.ustc.edu.cn-4affec411d11e50f/wgpu-22.1.0/src/lib.rs:5499:9 15: simp::app::image_view::texture::Texture::from_image at /usr/home/canvis/Downloads/simp/src/app/image_view/texture.rs:73:9 16: simp::app::image_view::mosaic::Mosaic::from_images at /usr/home/canvis/Downloads/simp/src/app/image_view/mosaic.rs:69:25 17: simp::app::image_view::ImageView::new at /usr/home/canvis/Downloads/simp/src/app/image_view.rs:58:22 18: simp::app::App::handle_output at /usr/home/canvis/Downloads/simp/src/app.rs:118:37 19: simp::app::App::handle_user_event at /usr/home/canvis/Downloads/simp/src/app.rs:353:21 20: simp::WindowHandler::main_loop::{{closure}} at /usr/home/canvis/Downloads/simp/src/main.rs:432:44 21: core::ops::function::impls:: for &mut F>::call_mut at /rustc/f54dd915b0a4345ee06fd561416ad1af08b54dbb/library/core/src/ops/function.rs:294:13 22: core::ops::function::impls:: for &mut F>::call_mut at /rustc/f54dd915b0a4345ee06fd561416ad1af08b54dbb/library/core/src/ops/function.rs:294:13 23: winit::platform_impl::linux::wayland::event_loop::EventLoop::single_iteration at /home/canvis/.cargo/registry/src/mirrors.ustc.edu.cn-4affec411d11e50f/winit-0.30.5/src/platform_impl/linux/wayland/event_loop/mod.rs:323:13 24: winit::platform_impl::linux::wayland::event_loop::EventLoop::poll_events_with_timeout at /home/canvis/.cargo/registry/src/mirrors.ustc.edu.cn-4affec411d11e50f/winit-0.30.5/src/platform_impl/linux/wayland/event_loop/mod.rs:295:9 25: winit::platform_impl::linux::wayland::event_loop::EventLoop::pump_events at /home/canvis/.cargo/registry/src/mirrors.ustc.edu.cn-4affec411d11e50f/winit-0.30.5/src/platform_impl/linux/wayland/event_loop/mod.rs:217:13 26: winit::platform_impl::linux::wayland::event_loop::EventLoop::run_on_demand at /home/canvis/.cargo/registry/src/mirrors.ustc.edu.cn-4affec411d11e50f/winit-0.30.5/src/platform_impl/linux/wayland/event_loop/mod.rs:181:19 27: winit::platform_impl::linux::EventLoop::run_on_demand at /home/canvis/.cargo/registry/src/mirrors.ustc.edu.cn-4affec411d11e50f/winit-0.30.5/src/platform_impl/linux/mod.rs:813:56 panicked at /home/canvis/.cargo/registry/src/mirrors.ustc.edu.cn-4affec411d11e50f/wgpu-22.1.0/src/backend/wgpu_core.rs:3411:5: wgpu error: Validation Error Caused by: In Queue::write_texture Not enough memory left. ```

Tested on both Ubuntu and Windows 11, simp works fine.

Platform FreeBSD 14.1-RELEASE-p5 with latest ports wgpu-22.1.0 The wm is sway with vulkan enabled and pure wayland.

Wumpf commented 3 days ago

I don't think there's much to do here - apparently you ran out of memory:

Caused by:
  In Queue::write_texture
    Not enough memory left.

If you don't want this to panic and instead to fail recoverably, you have to install an error scope.

If you think there is no way this should run out of vram we'll of course reopen the issue! (Such a texture would be about 389MiB, but you probably need at least double that to account for for upload buffer that write_texture has to manage which are subject to padding restrictions.)

Canvis-Me commented 3 days ago

It's not probably running out of vram. When all other programs except sway and terminal emulator closed, simp still panic to open high resolution pictures based on a 92MiB/8192MiB usage of Nvidia 3060ti. So I guess it would be a wgpu/freebsd problem, since there is no such crash on Linux/Windows.

Wumpf commented 3 days ago

Technically FreeBSD isn't one of the supported platforms but let's leave it open anyways for reference