IDEDARY / Bevypunk

Bevypunk is a recreation of Cyberpunk UI in Bevy using Bevy-Lunex. This project showcases advanced workflow and complex use of Bevy-Lunex library.
https://idedary.github.io/Bevypunk/
Apache License 2.0
152 stars 4 forks source link

Input delay when moving mouse #2

Open tqwewe opened 8 months ago

tqwewe commented 8 months ago

Thanks for building such an awesome showcase!

I just compiled it and tested it myself, though there's quite a noticeable delay when moving my mouse to click buttons. I ran in release mode, and my PC is quite powerful with a 4070, so its definitely not my PC under performing.

Any ideas where this delay might be coming from?

For context, here's some of the logs I see when running the app:

AdapterInfo { name: "NVIDIA GeForce RTX 4070", vendor: 4318, device: 10118, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "535.86.05", backend: Vulkan }
SystemInfo { os: "Linux 23.05 NixOS", kernel: "6.1.63", cpu: "13th Gen Intel(R) Core(TM) i5-13600KF", core_count: "14", memory: "31.2 GiB" }

And I'm on Linux

nicopap commented 8 months ago

Bevy by default has the worst possible input latency. IE: it polls input right after the end of the previous frame, resulting on input latency of exactly one frame, even without counting accidental lag caused by bad system ordering. Using bevy_framepace might help a bit https://crates.io/crates/bevy_framepace

IDEDARY commented 8 months ago

@nicopap This is a usefull advice, thanks. I will try it if there is a difference. Bevy_Lunex currently uses a dummy entity to track cursor, so you can style it. Notice the bloom of the cursor for example. It pulls cursor data, puts it as transform on entity and then that is used. So there might even be 2 frame delay. I will try to add option to style native cursor sprite instead, which was recently merged in winit. Altough, its kinda surprising you noticed this delay. When OS cursor is hidden, I can't tell the difference, but that might be because of my 165hz display.

tqwewe commented 8 months ago

I've tried setting the present_mode to PresentMode::Immediate, since I noticed it was capped at 60fps, and this definitely removed the input delay feeling.. though I was getting over a thousand FPS at that point. I'm not sure why it was capped at 60fps since my monitor is 144hz. (Btw the background moving graphic was animating super fast with a higher FPS compared to a lower FPS).

I added bevy_framepace to have a more reasonable FPS (around 400), and this also felt just fine to move the mouse. Though still not as crispy as styling the native cursor I'd say.

Btw, not related but when I clicked "Quit Game" in the UI, I got a segfault:

fish: Job 1, './bevypunk' terminated by signal SIGSEGV (Address boundary error)