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

Mouse click frame drop on Bevy 0.14.0 #14303

Open
JonasAAA opened this issue Jul 14, 2024 · 15 comments
Open

Mouse click frame drop on Bevy 0.14.0 #14303

JonasAAA opened this issue Jul 14, 2024 · 15 comments
Labels
A-Rendering Drawing game state to the screen A-Windowing Platform-agnostic interface layer to run your app in C-Bug An unexpected or incorrect behavior C-Machine-Specific This bug is isolated to specific hardware or driver configurations C-Performance A change motivated by improving speed, memory usage or compile times O-Linux Specific to the Linux desktop operating system P-Regression Functionality that used to work but no longer does. Add a test for this! S-Blocked This cannot move forward until something else changes

Comments

@JonasAAA
Copy link

Bevy version

  • Original: 0.13.2
  • Current: 0.14.0

Relevant system information

Rust version: 1.79.0
OS: Ubuntu 24.04
CPU: AMD Ryzen 5 2600 Six-Core Processor
RAM: 15.5 GiB

What's performing poorly?

When I left or right click the mouse in a very basic Bevy 0.14.0 project, the FPS drops to 10, even in release mode. With Bevy 0.13.2 the FPS drops to 30 when I click the mouse, so still problematic, but not nearly as disruptive.

Small example which reproduces the issue is at https://github.com/JonasAAA/Bevy-Lag. The Bevy 0.13 version of the same code is at https://github.com/JonasAAA/Bevy-Lag/tree/bevy_0.13. Run cargo run --release and click the mouse to reproduce the issue.

Additional information

This issue seems very similar to #14216.

@JonasAAA JonasAAA added C-Bug An unexpected or incorrect behavior C-Performance A change motivated by improving speed, memory usage or compile times P-Regression Functionality that used to work but no longer does. Add a test for this! S-Needs-Triage This issue needs to be labelled labels Jul 14, 2024
@alice-i-cecile alice-i-cecile added A-Windowing Platform-agnostic interface layer to run your app in O-Linux Specific to the Linux desktop operating system S-Needs-Investigation This issue requires detective work to figure out what's going wrong and removed S-Needs-Triage This issue needs to be labelled labels Jul 14, 2024
@SpecificProtagonist
Copy link
Contributor

SpecificProtagonist commented Jul 15, 2024

Works fine for me (Manjaro, X11, Nvidia gpu). Are you using X or Wayland?

@JonasAAA
Copy link
Author

JonasAAA commented Jul 15, 2024

Are you using X or Wayland?

I'm using X.

@codaishin
Copy link

I have the same issue (Ubuntu 24.04 LTS, AMD Ryzen 5 PRO 4650G, NVIDIA GeForce RTX 3060 Ti, X11) for left, middle and right mouse buttons. Other mouse buttons work fine. When using wayland this issue doesn't seem to be present.

@janhohenheim
Copy link
Member

That seems fairly huge for our X11 support 👀
It would be nice if other people could report whether they get the same kinds of numbers (10 FPS) on X to see how widespread this is.

@JonasAAA
Copy link
Author

JonasAAA commented Jul 17, 2024

The game also drops to 10 fps when I do almost any action while the game window is selected, even things not involving the mouse, e.g. change keyboard language (using keyboard shortcut), pressing windows key, opening a terminal through a keyboard shortcut, etc.
But as expected, pressing random keys doesn't change the fps.

@bash
Copy link
Contributor

bash commented Jul 17, 2024

Works fine for me both in X11 and Wayland (Fedora 40, AMD GPU).

@victorb
Copy link

victorb commented Jul 17, 2024

I'm seeing the same on X11 + Nvidia GPU (driver 555.58.02) + Kernel 6.6.39-1-lts

As a workaround, I found that bevy_framepace both solves this particular issue + reduces overall input latency, might be worth for others to look into if you hit the same issue.

Without bevy_framepace (bevy_mod_picking only included to see click state, same issue happens without it fwiw)

Screencast.from.2024-07-17.18-45-24.webm

With bevy_framepace

Screencast.from.2024-07-17.18-46-31.webm
Example code
use bevy::{
    dev_tools::fps_overlay::{FpsOverlayConfig, FpsOverlayPlugin},
    prelude::*,
};
use bevy_mod_picking::prelude::*;
use std::f32::consts::TAU;

fn main() {
    App::new()
        .add_plugins((
            DefaultPlugins,
            FpsOverlayPlugin::default(),
            bevy_framepace::FramepacePlugin,
            DefaultPickingPlugins,
        ))
        .insert_resource(DebugPickingMode::Noisy)
        .add_systems(Startup, setup)
        .add_systems(Update, rotate_cuboid)
        .run();
}

#[derive(Component)]
struct RotateMe;

fn setup(
    mut commands: Commands,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<StandardMaterial>>,
) {
    commands.spawn(Camera3dBundle {
        transform: Transform::from_xyz(0.0, 10.0, 20.0).looking_at(Vec3::ZERO, Vec3::Y),
        ..default()
    });

    commands.spawn(DirectionalLightBundle {
        directional_light: DirectionalLight {
            illuminance: 100.0,
            ..default()
        },
        transform: Transform::from_xyz(3.0, 3.0, 3.0).looking_at(Vec3::ZERO, Vec3::Y),
        ..default()
    });

    commands.spawn((
        PbrBundle {
            mesh: meshes.add(Cuboid::default()),
            material: materials.add(Color::srgba(1.0, 0.0, 0.0, 1.0)),
            transform: Transform::from_translation(Vec3::ZERO).with_scale(Vec3::splat(5.0)),
            ..default()
        },
        RotateMe,
    ));
}

fn rotate_cuboid(mut query: Query<&mut Transform, With<RotateMe>>, time: Res<Time>) {
    for mut t in query.iter_mut() {
        t.rotate_y(0.3 * TAU * time.delta_seconds());
    }
}

@janhohenheim janhohenheim added the C-Machine-Specific This bug is isolated to specific hardware or driver configurations label Jul 18, 2024
@janhohenheim
Copy link
Member

janhohenheim commented Jul 18, 2024

Update: it seems like all cases of this are using Nvidia + X11. Using Wayland always fixes the issue. So far AMD users have not run into this, but as @SpecificProtagonist notes, not all Nvidia + X11 users run into it either, so we might need more testing in this regard.

@SpecificProtagonist
Copy link
Contributor

SpecificProtagonist commented Jul 18, 2024

Ah sorry, I've just noticed that it used my igpu, not my Nvidia dgpu. Will try with the later later.
Edit: No fps drop on Nvidia (using the proprietary drivers).

@JonasAAA
Copy link
Author

I didn't include this in the issue description, but I'm also using Nvidia GPU. So I also fall in the bucket of users using X11 + Nvidia GPU combo and experiencing this issue.

@OSCARWB
Copy link

OSCARWB commented Jul 24, 2024

I've been having a similar problem in my own project and been trying to figure it out and just stumbled on this issue.
Also Nvidia GPU + X11

I don't get an FPS drop when clicking, but about every second the frame time spikes. Frame times stabilise when the window is unfocused. But start spiking again when mousing over the window, which sounds similar to #14216.

I get this problem on your example project @JonasAAA and most bevy 0.14 projects I've tested.

I tried bevy_framepace as suggested by @victorb on my project and it seems to fix it.

@victorb
Copy link

victorb commented Jul 31, 2024

@honehone12 been doing more digging trying to find where the issue is coming from here: honehone12/bevy_replicon_bootstrap#47

@victorb
Copy link

victorb commented Jul 31, 2024

So, I bisected between two versions from the previous mentioned issue, landed on gfx-rs/wgpu@e5c62fb being the commit who introduced the issue in wgpu. Parent commit (gfx-rs/wgpu@886dc94) don't suffer from the same issue. Was introduced in this PR: gfx-rs/wgpu#4967

I don't think I posses enough skill to actually attempt to solve this issue however.

@janhohenheim
Copy link
Member

@victorb good detective work! Could you open an issue on wgpu informing them? I'll set this to blocked in the meantime :)

@janhohenheim janhohenheim added S-Blocked This cannot move forward until something else changes and removed S-Needs-Investigation This issue requires detective work to figure out what's going wrong labels Jul 31, 2024
@honehone12
Copy link

@victorb nice work !! thank you !!

@alice-i-cecile alice-i-cecile added the A-Rendering Drawing game state to the screen label Sep 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen A-Windowing Platform-agnostic interface layer to run your app in C-Bug An unexpected or incorrect behavior C-Machine-Specific This bug is isolated to specific hardware or driver configurations C-Performance A change motivated by improving speed, memory usage or compile times O-Linux Specific to the Linux desktop operating system P-Regression Functionality that used to work but no longer does. Add a test for this! S-Blocked This cannot move forward until something else changes
Projects
None yet
Development

No branches or pull requests

9 participants