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

Prevent scissor_rect region to be larger than the target texture in wgpu::Backend::flush #818

Merged
merged 3 commits into from
Jun 10, 2021

Conversation

thenlevy
Copy link
Contributor

@thenlevy thenlevy commented Apr 8, 2021

This seems to solve #775 for me. I speculate that it might also solve #816

Fixes #738.
Fixes #748.
Fixes #775.
Fixes #816.

wgpu/src/backend.rs Outdated Show resolved Hide resolved
@kaimast
Copy link

kaimast commented May 7, 2021

I just tested your branch and still get a crash when resizing the integration example. :/

@thenlevy
Copy link
Contributor Author

thenlevy commented May 7, 2021

I just tested your branch and still get a crash when resizing the integration example. :/

Oh sad... I cannot reproduce it on my branch :(
Could you provide a backtrace ? Also, what os are you using ?
Edit: Since this does not fix the targeted issue, I'm converting the PR to draft

@thenlevy thenlevy marked this pull request as draft May 7, 2021 06:19
@kaimast
Copy link

kaimast commented May 8, 2021

I'm on Ubuntu 21.04 with GNOME & X11

  ~/dev/tmp/iced check_bounds ❯ env RUST_BACKTRACE=full cargo run --package integration                                                                                                             52s
warning: unused variable: `target_bounds`
   --> wgpu/src/backend.rs:113:13
    |
113 |         let target_bounds = iced_graphics::Rectangle::with_size(
    |             ^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_target_bounds`
    |
    = note: `#[warn(unused_variables)]` on by default

warning: 1 warning emitted

    Finished dev [unoptimized + debuginfo] target(s) in 0.16s
     Running `target/debug/integration`
[2021-05-08T00:24:53Z ERROR gfx_backend_vulkan]
    VALIDATION [VUID-VkSwapchainCreateInfoKHR-imageExtent-01274 (2094043421)] : Validation Error: [ VUID-VkSwapchainCreateInfoKHR-imageExtent-01274 ] Object 0: handle = 0x5631d1e46630, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0x7cd0911d | vkCreateSwapchainKHR() called with imageExtent = (2313,1849), which is outside the bounds returned by vkGetPhysicalDeviceSurfaceCapabilitiesKHR(): currentExtent = (1543,1849), minImageExtent = (1543,1849), maxImageExtent = (1543,1849). 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://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#VUID-VkSwapchainCreateInfoKHR-imageExtent-01274)
    object info: (type: DEVICE, hndl: 94771974792752)

wgpu error: Validation Error

Caused by:
    In a RenderPass
      note: encoder = `<CommandBuffer-(0, 1032, Vulkan)>`
    In a set_scissor_rect command
    Invalid ScissorRect parameters


thread 'main' panicked at 'Handling wgpu errors as fatal by default', /home/kai/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/wgpu-0.7.1/src/backend/direct.rs:1896:5
stack backtrace:
   0:     0x5631cfdedca0 - std::backtrace_rs::backtrace::libunwind::trace::hdcf4f90f85129e83
                               at /rustc/676ee14729462585b969bbc52f32c307403f4126/library/std/src/../../backtrace/src/backtrace/libunwind.rs:90:5
   1:     0x5631cfdedca0 - std::backtrace_rs::backtrace::trace_unsynchronized::h2669e30cb82f6732
                               at /rustc/676ee14729462585b969bbc52f32c307403f4126/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x5631cfdedca0 - std::sys_common::backtrace::_print_fmt::hfbda19e17f6db318
                               at /rustc/676ee14729462585b969bbc52f32c307403f4126/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x5631cfdedca0 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h1a8751bf59281272
                               at /rustc/676ee14729462585b969bbc52f32c307403f4126/library/std/src/sys_common/backtrace.rs:46:22
   4:     0x5631cfe117ff - core::fmt::write::h7aa6cd0067dca82a
                               at /rustc/676ee14729462585b969bbc52f32c307403f4126/library/core/src/fmt/mod.rs:1094:17
   5:     0x5631cfde95b5 - std::io::Write::write_fmt::hd7dd3a1df9b6befb
                               at /rustc/676ee14729462585b969bbc52f32c307403f4126/library/std/src/io/mod.rs:1584:15
   6:     0x5631cfdefdab - std::sys_common::backtrace::_print::h551e9ec8a9fa8106
                               at /rustc/676ee14729462585b969bbc52f32c307403f4126/library/std/src/sys_common/backtrace.rs:49:5
   7:     0x5631cfdefdab - std::sys_common::backtrace::print::ha4b1c5e95fa040b3
                               at /rustc/676ee14729462585b969bbc52f32c307403f4126/library/std/src/sys_common/backtrace.rs:36:9
   8:     0x5631cfdefdab - std::panicking::default_hook::{{closure}}::h0b34c9ab7fb9f857
                               at /rustc/676ee14729462585b969bbc52f32c307403f4126/library/std/src/panicking.rs:208:50
   9:     0x5631cfdef88d - std::panicking::default_hook::h3067e8318decd17a
                               at /rustc/676ee14729462585b969bbc52f32c307403f4126/library/std/src/panicking.rs:225:9
  10:     0x5631cfdf035d - std::panicking::rust_panic_with_hook::h81b8facc50f34daa
                               at /rustc/676ee14729462585b969bbc52f32c307403f4126/library/std/src/panicking.rs:591:17
  11:     0x5631cf954073 - std::panicking::begin_panic::{{closure}}::h7b926e8e0b3cddc3
                               at /home/kai/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:520:9
  12:     0x5631cf9554f9 - std::sys_common::backtrace::__rust_end_short_backtrace::he88a64c4b4ba215c
                               at /home/kai/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys_common/backtrace.rs:141:18
  13:     0x5631cf953fa9 - std::panicking::begin_panic::h2013209409f0f701
                               at /home/kai/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:519:12
  14:     0x5631cf32298c - wgpu::backend::direct::default_error_handler::ha0a3524495d4d8fb
                               at /home/kai/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/wgpu-0.7.1/src/backend/direct.rs:1896:5
  15:     0x5631cf5d1e7c - core::ops::function::Fn::call::hb9841aab3f65f0d4
                               at /home/kai/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:70:5
  16:     0x5631cf285d92 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h6b35aa8a26ff1d06
                               at /home/kai/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/boxed.rs:1589:9
  17:     0x5631cf322881 - wgpu::backend::direct::ErrorSinkRaw::handle_error::h8c40fbcb1179e7f7
                               at /home/kai/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/wgpu-0.7.1/src/backend/direct.rs:1883:9
  18:     0x5631cf3181a0 - wgpu::backend::direct::Context::handle_error::ha13b36d227e2ecea
                               at /home/kai/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/wgpu-0.7.1/src/backend/direct.rs:109:9
  19:     0x5631cf322425 - <wgpu::backend::direct::Context as wgpu::Context>::command_encoder_end_render_pass::hcdd598b566c6616d
                               at /home/kai/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/wgpu-0.7.1/src/backend/direct.rs:1739:13
  20:     0x5631cf4d0707 - <wgpu::RenderPass as core::ops::drop::Drop>::drop::h66013b3d0fdb2f82
                               at /home/kai/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/wgpu-0.7.1/src/lib.rs:2486:13
  21:     0x5631cf146da7 - core::ptr::drop_in_place<wgpu::RenderPass>::h45ba154f946709f0
                               at /home/kai/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:192:1
  22:     0x5631cf0bb0ec - iced_wgpu::quad::Pipeline::draw::hb0bd5d1681fd6cce
                               at /home/kai/dev/tmp/iced/wgpu/src/quad.rs:275:13
  23:     0x5631cf0a3321 - iced_wgpu::backend::Backend::flush::hce96231d3f41b1b8
                               at /home/kai/dev/tmp/iced/wgpu/src/backend.rs:125:13
  24:     0x5631ce90321f - iced_wgpu::backend::Backend::draw::h37065d5ef0ededaf
                               at /home/kai/dev/tmp/iced/wgpu/src/backend.rs:82:13
  25:     0x5631ce8dd55b - integration::main::{{closure}}::hc53d3e13f8f34051
                               at /home/kai/dev/tmp/iced/examples/integration/src/main.rs:193:41
  26:     0x5631ce92efbe - winit::platform_impl::platform::sticky_exit_callback::h78cb49fd516cc9f3
                               at /home/kai/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/winit-0.24.0/src/platform_impl/linux/mod.rs:736:5
  27:     0x5631ce8d988a - winit::platform_impl::platform::x11::EventLoop<T>::run_return::haa578a4f45ff46e7
                               at /home/kai/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/winit-0.24.0/src/platform_impl/linux/x11/mod.rs:320:21
  28:     0x5631ce8da7b1 - winit::platform_impl::platform::x11::EventLoop<T>::run::hce671b66b2d7ce46
                               at /home/kai/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/winit-0.24.0/src/platform_impl/linux/x11/mod.rs:398:9
  29:     0x5631ce92ec44 - winit::platform_impl::platform::EventLoop<T>::run::h5d18f8f758b9263b
                               at /home/kai/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/winit-0.24.0/src/platform_impl/linux/mod.rs:652:56
  30:     0x5631ce95747a - winit::event_loop::EventLoop<T>::run::hc928871fbdb7ffd3
                               at /home/kai/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/winit-0.24.0/src/event_loop.rs:154:9
  31:     0x5631ce8d1703 - integration::main::h1ec9aaf0d3232702
                               at /home/kai/dev/tmp/iced/examples/integration/src/main.rs:99:5
  32:     0x5631ce94bb7b - core::ops::function::FnOnce::call_once::h4a3f76bc49d5d787
                               at /home/kai/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:227:5
  33:     0x5631ce908b1e - std::sys_common::backtrace::__rust_begin_short_backtrace::hdda5137bd57a1645
                               at /home/kai/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys_common/backtrace.rs:125:18
  34:     0x5631ce93b401 - std::rt::lang_start::{{closure}}::h74947fbf8d104bc3
                               at /home/kai/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:49:18
  35:     0x5631cfdf075a - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h3b8c329143d7638a
                               at /rustc/676ee14729462585b969bbc52f32c307403f4126/library/core/src/ops/function.rs:259:13
  36:     0x5631cfdf075a - std::panicking::try::do_call::h4b72c261b4eefc1b
                               at /rustc/676ee14729462585b969bbc52f32c307403f4126/library/std/src/panicking.rs:379:40
  37:     0x5631cfdf075a - std::panicking::try::h703d31b7896cbd49
                               at /rustc/676ee14729462585b969bbc52f32c307403f4126/library/std/src/panicking.rs:343:19
  38:     0x5631cfdf075a - std::panic::catch_unwind::h37cad9b35388a915
                               at /rustc/676ee14729462585b969bbc52f32c307403f4126/library/std/src/panic.rs:431:14
  39:     0x5631cfdf075a - std::rt::lang_start_internal::hab5a8a909af4f90e
                               at /rustc/676ee14729462585b969bbc52f32c307403f4126/library/std/src/rt.rs:34:21
  40:     0x5631ce93b3e0 - std::rt::lang_start::h9b99a9b79188544d
                               at /home/kai/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:48:5
  41:     0x5631ce8d199c - main
  42:     0x7f2035dc4565 - __libc_start_main
  43:     0x5631ce8c74de - _start
  44:                0x0 - <unknown>
fish: “env RUST_BACKTRACE=full cargo r…” terminated by signal SIGSEGV (Address boundary error)

@zyansheep
Copy link

This fixes the problem perfectly for me (except there is an unused variable warning).

@thenlevy
Copy link
Contributor Author

@kaimast I tried it on gnome and sadly could not repoduce it :(

I noticed the following lines in your log

[2021-05-08T00:24:53Z ERROR gfx_backend_vulkan]
    VALIDATION [VUID-VkSwapchainCreateInfoKHR-imageExtent-01274 (2094043421)] : Validation Error: [ VUID-VkSwapchainCreateInfoKHR-imageExtent-01274 ] Object 0: handle = 0x5631d1e46630, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0x7cd0911d | vkCreateSwapchainKHR() called with imageExtent = (2313,1849), which is outside the bounds returned by vkGetPhysicalDeviceSurfaceCapabilitiesKHR(): currentExtent = (1543,1849), minImageExtent = (1543,1849), maxImageExtent = (1543,1849). 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://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#VUID-VkSwapchainCreateInfoKHR-imageExtent-01274)
    object info: (type: DEVICE, hndl: 94771974792752)
    ```
  

Do you also get them on the master branch ?

@kaimast
Copy link

kaimast commented May 13, 2021

I do get that error on master as well right before it crashes. Might be an issue with the Nvidia Linux drivers; they're quite bad.

I cannot reliably reproduce this. I usually have to resize the window quite a while for it to trigger the bug. So maybe this branch improves the behavior but does not fix all edge cases?

@hecrj hecrj marked this pull request as ready for review June 9, 2021 14:32
@hecrj
Copy link
Member

hecrj commented Jun 9, 2021

I made some changes in the branch.

I think simply changing Rectangle::snap to floor the width and height instead of using ceil should fix the issue.
Could you confirm this?

@thenlevy
Copy link
Contributor Author

thenlevy commented Jun 9, 2021

I made some changes in the branch.

I think simply changing Rectangle::snap to floor the width and height instead of using ceil should fix the issue.
Could you confirm this?

It seems to work 👍
I cannot reproduce the crash on this branch while I can easily reproduce it on master, so I solves the issue for me 👍

I speculate that what @kaimast is experiencing might be due to an unrelated problem, maybe some synchronization problem between the size of the windows and the size of the textures? Their error message indicate a large difference between the size of the scissor rect and the size of the target texture.

@hecrj
Copy link
Member

hecrj commented Jun 10, 2021

@thenlevy Awesome! Let's merge then! Thank you 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
4 participants