sotrh / learn-wgpu

Guide for using gfx-rs's wgpu library.
https://sotrh.github.io/learn-wgpu/
MIT License
1.5k stars 264 forks source link

Example application hangs after resize #230

Open jfrimmel opened 3 years ago

jfrimmel commented 3 years ago

Hello, first of all: thank you for this great learning resource!

I have a problem when running the example code of these tutorials. I've recorded a GIF demonstrating the issue: learn-wgpu_tutorial2-bug As you can see, the example works, but after some resizing (amount varies between runs), the code reproducible hangs and won't update the window anymore. I've tested the tutorial2-code with the latest commit (as seen in the GIF) and the tutoral8-code as well (both show that behavior).

I've attached a gdb to the hanging process and it seems, like it is always hanging in DisplatchQueuePresentKHR:

gdb backtrace ``` (gdb) bt #0 0x00007fb57d54c59b in ioctl () from /usr/lib/libc.so.6 #1 0x00007fb57c5755f4 in ?? () from /usr/lib/libvulkan_intel.so #2 0x00007fb57b16bea4 in DispatchQueuePresentKHR (queue=0x557ad4b15600, pPresentInfo=0x7ffcd3c5d210) at /build/vulkan-validation-layers/src/Vulkan-ValidationLayers-1.2.190/layers/generated/layer_chassis_dispatch.cpp:468 #3 0x00007fb57b0debcc in vulkan_layer_chassis::QueuePresentKHR (queue=0x557ad4b15600, pPresentInfo=0x7ffcd3c5d210) at /build/vulkan-validation-layers/src/Vulkan-ValidationLayers-1.2.190/layers/generated/chassis.cpp:4880 #4 0x0000557ad2aca6d0 in ash::vk::extensions::KhrSwapchainFn::queue_present_khr (self=0x557ad4b1a260, queue=..., p_present_info=0x7ffcd3c5d210) at /home/jfrimmel/.cargo/registry/src/github.com-1ecc6299db9ec823/ash-0.33.3+1.2.191/src/vk/extensions.rs:566 #5 0x0000557ad2abe56d in ash::extensions::khr::swapchain::Swapchain::queue_present (self=0x557ad4b1a258, queue=..., create_info=0x7ffcd3c5d210) at /home/jfrimmel/.cargo/registry/src/github.com-1ecc6299db9ec823/ash-0.33.3+1.2.191/src/extensions/khr/swapchain.rs:91 #6 0x0000557ad2a2be55 in wgpu_hal::vulkan::{impl#8}::present (self=0x557ad4b1a250, surface=0x557ad4ac2920, texture=...) at /home/jfrimmel/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-hal-0.10.4/src/vulkan/mod.rs:531 #7 0x0000557ad27a5dda in wgpu_core::hub::Global::surface_present (self=0x557ad4ac1650, surface_id=...) at /home/jfrimmel/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-core-0.10.2/src/present.rs:243 #8 0x0000557ad289d35b in wgpu::backend::direct::{impl#3}::surface_present (self=0x557ad4ac1650, texture=0x7ffcd3c5df38, detail=0x7ffcd3c5df50) at /home/jfrimmel/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-0.10.1/src/backend/direct.rs:929 #9 0x0000557ad28dfa9e in wgpu::{impl#60}::drop (self=0x7ffcd3c5df30) at /home/jfrimmel/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-0.10.1/src/lib.rs:3069 #10 0x0000557ad288a347 in core::ptr::drop_in_place () at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/core/src/ptr/mod.rs:192 #11 0x0000557ad25a08f4 in tutorial2_surface::State::render (self=0x7ffcd3c5f068) at code/beginner/tutorial2-surface/src/main.rs:115 #12 0x0000557ad25abf57 in tutorial2_surface::main::{closure#0} (event=..., control_flow=0x7ffcd3c5e800) at code/beginner/tutorial2-surface/src/main.rs:158 #13 0x0000557ad25a24e7 in winit::platform_impl::platform::sticky_exit_callback<(), tutorial2_surface::main::{closure#0}> (evt=..., target=0x557ad42ab540, control_flow=0x7ffcd3c5e800, callback=0x7ffcd3c5eff8) at /home/jfrimmel/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.25.0/src/platform_impl/linux/mod.rs:746 #14 0x0000557ad258a3b4 in winit::platform_impl::platform::x11::EventLoop<()>::run_return<(), tutorial2_surface::main::{closure#0}> (self=0x7ffcd3c5f370, callback=...) at /home/jfrimmel/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.25.0/src/platform_impl/linux/x11/mod.rs:307 #15 0x0000557ad258b243 in winit::platform_impl::platform::x11::EventLoop<()>::run<(), tutorial2_surface::main::{closure#0}> (self=..., callback=...) at /home/jfrimmel/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.25.0/src/platform_impl/linux/x11/mod.rs:385 #16 0x0000557ad25a2320 in winit::platform_impl::platform::EventLoop<()>::run<(), tutorial2_surface::main::{closure#0}> (self=..., callback=...) at /home/jfrimmel/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.25.0/src/platform_impl/linux/mod.rs:662 #17 0x0000557ad25bc35c in winit::event_loop::EventLoop<()>::run<(), tutorial2_surface::main::{closure#0}> ( self=..., event_handler=...) at /home/jfrimmel/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.25.0/src/event_loop.rs:154 #18 0x0000557ad25a0b9b in tutorial2_surface::main () at code/beginner/tutorial2-surface/src/main.rs:126 ```

Is this related to the interaction between winit <-> wgpu or might this be a bug in wgpu itself? If so, should I post an issue there instead?

I'm happy to provide more information if needed.

System specs and versions - x86_64-based Laptop with internal Intel graphics card - Linux (Arch Linux 5.13.13-arch1-1) - X11 as display server, no wayland installed - Vulkan as backend - Rust 1.55 (rustc 1.55.0 (c8dfcfe04 2021-09-06))
sotrh commented 3 years ago

That might be a bug in wgpu itself. I wasn't able to get it to hang on my end. I did get it to display some validation errors. I'll posted those below, but you should probably file and issue on the wgpu repo itself. Be sure to mention this issue too!

2021-09-15T15:40:46Z ERROR wgpu_hal::vulkan::instance] VALIDATION [VUID-VkSwapchainCreateInfoKHR-imageExtent-01274 (0x7cd0911d)]
        Validation Error: [ VUID-VkSwapchainCreateInfoKHR-imageExtent-01274 ] Object 0: handle = 0x55760e7f7a60, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0x7cd0911d | vkCreateSwapchainKHR() called with imageExtent = (490,699), which is outside the bounds returned by vkGetPhysicalDeviceSurfaceCapabilitiesKHR(): currentExtent = (1060,524), minImageExtent = (1060,524), maxImageExtent = (1060,524). The Vulkan spec states: imageExtent must be between minImageExtent and maxImageExtent, inclusive, where minImageExtent and maxImageExtent are members of the VkSurfaceCapabilitiesKHR structure returned by vkGetPhysicalDeviceSurfaceCapabilitiesKHR for the surface (https://vulkan.lunarg.com/doc/view/1.2.189.0/linux/1.2-extensions/vkspec.html#VUID-VkSwapchainCreateInfoKHR-imageExtent-01274)
[2021-09-15T15:40:46Z ERROR wgpu_hal::vulkan::instance]     objects: (type: DEVICE, hndl: 0x55760e7f7a60, name: ?)
[2021-09-15T15:40:46Z ERROR wgpu_hal::vulkan::instance] VALIDATION [VUID-VkSwapchainCreateInfoKHR-imageExtent-01274 (0x7cd0911d)]
        Validation Error: [ VUID-VkSwapchainCreateInfoKHR-imageExtent-01274 ] Object 0: handle = 0x55760e7f7a60, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0x7cd0911d | vkCreateSwapchainKHR() called with imageExtent = (534,687), which is outside the bounds returned by vkGetPhysicalDeviceSurfaceCapabilitiesKHR(): currentExtent = (1060,524), minImageExtent = (1060,524), maxImageExtent = (1060,524). The Vulkan spec states: imageExtent must be between minImageExtent and maxImageExtent, inclusive, where minImageExtent and maxImageExtent are members of the VkSurfaceCapabilitiesKHR structure returned by vkGetPhysicalDeviceSurfaceCapabilitiesKHR for the surface (https://vulkan.lunarg.com/doc/view/1.2.189.0/linux/1.2-extensions/vkspec.html#VUID-VkSwapchainCreateInfoKHR-imageExtent-01274)
[2021-09-15T15:40:46Z ERROR wgpu_hal::vulkan::instance]     objects: (type: DEVICE, hndl: 0x55760e7f7a60, name: ?)
[2021-09-15T15:40:46Z ERROR wgpu_hal::vulkan::instance] VALIDATION [VUID-VkSwapchainCreateInfoKHR-imageExtent-01274 (0x7cd0911d)]
        Validation Error: [ VUID-VkSwapchainCreateInfoKHR-imageExtent-01274 ] Object 0: handle = 0x55760e7f7a60, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0x7cd0911d | vkCreateSwapchainKHR() called with imageExtent = (974,539), which is outside the bounds returned by vkGetPhysicalDeviceSurfaceCapabilitiesKHR(): currentExtent = (1060,524), minImageExtent = (1060,524), maxImageExtent = (1060,524). The Vulkan spec states: imageExtent must be between minImageExtent and maxImageExtent, inclusive, where minImageExtent and maxImageExtent are members of the VkSurfaceCapabilitiesKHR structure returned by vkGetPhysicalDeviceSurfaceCapabilitiesKHR for the surface (https://vulkan.lunarg.com/doc/view/1.2.189.0/linux/1.2-extensions/vkspec.html#VUID-VkSwapchainCreateInfoKHR-imageExtent-01274)
[2021-09-15T15:40:46Z ERROR wgpu_hal::vulkan::instance]     objects: (type: DEVICE, hndl: 0x55760e7f7a60, name: ?)
jfrimmel commented 3 years ago

Thanks for your reply. I've opened the upstream issue: https://github.com/gfx-rs/wgpu/issues/1971.

I've got the same validation layer errors as well and opened https://github.com/gfx-rs/wgpu/issues/1958 for it.

sotrh commented 2 years ago

Any updates on this?

jfrimmel commented 2 years ago

No, unfortunately not. I doubt anything in this area will happen soon. I can reproduce the error fairly often, but cannot find the source.