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

Program crashes when releasing the framerate #17

Closed
Ceyron opened this issue Nov 6, 2024 · 6 comments
Closed

Program crashes when releasing the framerate #17

Ceyron opened this issue Nov 6, 2024 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@Ceyron
Copy link
Collaborator

Ceyron commented Nov 6, 2024

I compiled the main branch, executed the program and unticked the Limit FPS under the Rendering tap in the GUI. Then the program crashes

thread '<unnamed>' panicked at 'Error in wgpuDeviceCreateSwapChain: Validation Error

Caused by:
    Requested present mode Immediate is not in the list of supported present modes: [Fifo]
', src/lib.rs:495:5
stack backtrace:
   0:     0x7c402cc2e4ba - std::backtrace_rs::backtrace::libunwind::trace::h9a6b80bbf328ba5d
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7c402cc2e4ba - std::backtrace_rs::backtrace::trace_unsynchronized::hd162ec543a11886b
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7c402cc2e4ba - std::sys_common::backtrace::_print_fmt::h78a5099be12f51a6
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7c402cc2e4ba - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::ha1c5390454d74f71
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7c402cc4f6bf - core::fmt::write::h9ffde816c577717b
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/fmt/mod.rs:1254:17
   5:     0x7c402cc2be45 - std::io::Write::write_fmt::h88186074961638e4
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/io/mod.rs:1698:15
   6:     0x7c402cc2e285 - std::sys_common::backtrace::_print::h184198273ed08d59
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x7c402cc2e285 - std::sys_common::backtrace::print::h1b4d8e7add699453
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x7c402cc2f61e - std::panicking::default_hook::{{closure}}::h393bcea75423915a
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:269:22
   9:     0x7c402cc2f3c5 - std::panicking::default_hook::h48c64f31d8b3fd03
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:288:9
  10:     0x7c402cc2fb7e - std::panicking::rust_panic_with_hook::hafdc493a79370062
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:691:13
  11:     0x7c402cc2fa79 - std::panicking::begin_panic_handler::{{closure}}::h0a64bc82e36bedc7
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:582:13
  12:     0x7c402cc2e926 - std::sys_common::backtrace::__rust_end_short_backtrace::hc203444fb7416a16
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:150:18
  13:     0x7c402cc2f7d2 - rust_begin_unwind
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:578:5
  14:     0x7c402c877173 - core::panicking::panic_fmt::h0f6ef0178afce4f2
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/panicking.rs:67:14
  15:     0x7c402c9a6966 - wgpu_native::handle_error_fatal::h4dab13fcf1fc1a53
  16:     0x7c402c9b8818 - wgpuDeviceCreateSwapChain
  17:     0x618933c59b92 - _ZN4wgpu6Device15createSwapChainENS_7SurfaceERKNS_19SwapChainDescriptorE
  18:     0x618933c7edbc - _ZN8Renderer13initSwapChainEv
  19:     0x618933c7da92 - _ZN8Renderer7onFrameEv
  20:     0x618933c7ad15 - main
  21:     0x7c402c234e08 - <unknown>
  22:     0x7c402c234ecc - __libc_start_main
  23:     0x618933c57635 - _start
  24:                0x0 - <unknown>
fatal runtime error: failed to initiate panic, error 5
Aborted (core dumped)

My OS is Arch Linux. System info from CMAKE configure:

-- The CXX compiler identification is GNU 14.2.1
-- The C compiler identification is GNU 14.2.1
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Using X11 for window creation
-- Found X11: /usr/include
-- Looking for XOpenDisplay in /usr/lib/libX11.so;/usr/lib/libXext.so
-- Looking for XOpenDisplay in /usr/lib/libX11.so;/usr/lib/libXext.so - found
-- Looking for gethostbyname
-- Looking for gethostbyname - found
-- Looking for connect
-- Looking for connect - found
-- Looking for remove
-- Looking for remove - found
-- Looking for shmat
-- Looking for shmat - found
-- Looking for IceConnectionNumber in ICE
-- Looking for IceConnectionNumber in ICE - found
-- Using wgpu-native backend for WebGPU
-- Using WebGPU runtime from '/home/felix/Downloads/game-physics-template-0.1.1/build/_deps/webgpu-backend-wgpu-src/bin/linux-x86_64/libwgpu_native.so'
-- Configuring done (54.0s)
-- Generating done (0.0s)
@Ceyron Ceyron added the bug Something isn't working label Nov 6, 2024
@KeKsBoTer
Copy link

KeKsBoTer commented Nov 6, 2024

Can you try setting "wgpu::PresentMode::Immediate" to "wgpu::PresentMode::AutoNoVsync" here:

if (Checkbox("Limit FPS", &limitFPS))

see https://docs.rs/wgpu/latest/wgpu/enum.PresentMode.html#variant.AutoNoVsync

@Ceyron
Copy link
Collaborator Author

Ceyron commented Nov 6, 2024

wgpu::PresentMode::AutoNoVsync

gives me

[build] /home/felix/Downloads/game-physics-template/src/Simulator.cpp: In member function ‘void Simulator::onGUI()’:
[build] /home/felix/Downloads/game-physics-template/src/Simulator.cpp:85:60: error: ‘AutoNoVsync’ is not a member of ‘wgpu::PresentMode’
[build]    85 |                 renderer.setPresentMode(wgpu::PresentMode::AutoNoVsync);
[build]       |                                                            ^~~~~~~~~~~
[build] make[2]: *** [CMakeFiles/Template.dir/build.make:146: CMakeFiles/Template.dir/src/Simulator.cpp.o] Error 1
[build] make[1]: *** [CMakeFiles/Makefile2:187: CMakeFiles/Template.dir/all] Error 2
[build] make: *** [Makefile:91: all] Error 2

Could it be that this is a feature only supported by a more recent version of WebGPU?

@wi-re
Copy link
Collaborator

wi-re commented Nov 6, 2024

I could reproduce the issue on my WSL setup:

The version in our codebase only supports:

ENUM(PresentMode)
	ENUM_ENTRY(Immediate, 0x00000000)
	ENUM_ENTRY(Mailbox, 0x00000001)
	ENUM_ENTRY(Fifo, 0x00000002)
	ENUM_ENTRY(Force32, 0x7FFFFFFF)
END

If you then look at the webgpu documentation you get this:

Immediate = 4
Presentation frames are not queued at all. The moment a present command is executed on the GPU, the presented image is swapped onto the front buffer immediately.

Tearing can be observed.

Supported on most platforms except older DX12 and Wayland.

This is traditionally called “Vsync Off”.

We can bandaid fix this for now by disabling the limit fps button if we are running on wayland, e.g.,

#ifdef _GLFW_WAYLAND
        ImGui::BeginDisabled();
        if (Checkbox("Limit FPS (disabled on Wayland)", &limitFPS))
        ImGui::EndDisabled();
#else
        if (Checkbox("Limit FPS", &limitFPS)){
            if (limitFPS)
                renderer.setPresentMode(wgpu::PresentMode::Fifo);
            else
                renderer.setPresentMode(wgpu::PresentMode::Immediate);
        }
#endif

This is now implemented in the fix-wayland branch.

@Ceyron
Copy link
Collaborator Author

Ceyron commented Nov 7, 2024

Thanks for looking into it. The approach definitely fixes it on Wayland for me.

However, it also occurs on X11 sessions. Using version d9939f3ac22d9915aa7bcad6f509a27da250fa13 of the fix-wayland branch, I get the following when running CMAKE configure

-- The CXX compiler identification is GNU 14.2.1
-- The C compiler identification is GNU 14.2.1
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
 Using X11 (detected via XDG_SESSION_TYPE)
-- Using wgpu-native backend for WebGPU
-- Using WebGPU runtime from '/home/felix/Downloads/game-physics-template/build/_deps/webgpu-backend-wgpu-src/bin/linux-x86_64/libwgpu_native.so'
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Including X11 support
-- Found X11: /usr/include
-- Looking for XOpenDisplay in /usr/lib/libX11.so;/usr/lib/libXext.so
-- Looking for XOpenDisplay in /usr/lib/libX11.so;/usr/lib/libXext.so - found
-- Looking for gethostbyname
-- Looking for gethostbyname - found
-- Looking for connect
-- Looking for connect - found
-- Looking for remove
-- Looking for remove - found
-- Looking for shmat
-- Looking for shmat - found
-- Looking for IceConnectionNumber in ICE
-- Looking for IceConnectionNumber in ICE - found
-- Configuring done (26.5s)
-- Generating done (0.0s)

Running the program and releasing the FPS results in the same stack trace as initially described.

However, this is only on my Arch Laptop with Intel iGPU. On my X11 Ubuntu 22.04 workstation with an nvidia GPU, there is no issue with it. Based on that, I assume it might be related to my Laptop having integrated graphics? Or could it also be an issue with Vulkan? I assume WebGPU is using Vulkan in the backend?

Since it should not impact the students much, I guess it's not a high priority, but I still find it strange.

@wi-re
Copy link
Collaborator

wi-re commented Nov 7, 2024

PR #16 addresses this issue by disabling the button in incompatible setups and making setups compatible is beyond our scope. I think we can close this issue for now.

@Ceyron
Copy link
Collaborator Author

Ceyron commented Nov 7, 2024

Agree

@Ceyron Ceyron closed this as completed Nov 7, 2024
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
Development

No branches or pull requests

4 participants