bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
36.01k stars 3.55k forks source link

Basic Pipelined-Rendering App has Excessive CPU Utilization #3210

Open Supermath101 opened 2 years ago

Supermath101 commented 2 years ago

Bevy version

Commit ID: e8412df0

Operating system & version

Manjaro Linux with Nvidia proprietary drivers.

What you did

I ran a very basic Pipelined rendering app on release mode.

use bevy::{
    ecs::prelude::*,
    prelude::{App},
    PipelinedDefaultPlugins,
    render2::{
        camera::OrthographicCameraBundle
    }
};

fn main() {
    App::new().add_plugins(PipelinedDefaultPlugins)
    .add_startup_system(setup_system)
    .run();
}

fn setup_system(mut commands: Commands) {
    commands.spawn_bundle(OrthographicCameraBundle::new_2d());
}

What you expected to happen

This example code should in-theory run at near 0% CPU utilization.

What actually happened

The CPU utilization was hovering around 1/3 usage.

Additional information

The output of running cargo-flamegraph: flamegraph.zip

I'm running an Intel Core i7-9750H with 16 GB of RAM.

This was the 2nd item that was logged (I thought it might be useful):

INFO bevy_render2::renderer: AdapterInfo { name: "NVIDIA GeForce GTX 1660 Ti", vendor: 4318, device: 8593, device_type: DiscreteGpu, backend: Vulkan }
alice-i-cecile commented 2 years ago

Per Discord, this still happens on the old renderer, and on 0.5, correct?

alice-i-cecile commented 2 years ago

For reference: I'm getting about 1-2% CPU usage with a very basic scene on the same commit.

Supermath101 commented 2 years ago

Per Discord, this still happens on the old renderer, and on 0.5, correct?

Correct.

superdump commented 2 years ago

I’m wondering if somehow vsync is turned off.

cart commented 2 years ago

Yup this is almost certainly due to a lack of frame limiting. Right now vsync is our only default form of frame limiting, which isn't great for a variety of reasons:

  1. Games without vsync munch on CPUs
  2. We can't use the (often better) Mailbox vsync mode where it is available without spiking CPU usage

On top of that, we'll need to sort out a new way to handle "delta times" anyway when we enable "actual parallel pipelining" in the new renderer, which im still working on. I might just add "on by default" frame limiting with those changes, as I think the changes I need to make have lots of overlap with frame limiting.

maniwani commented 2 years ago

@TheRawMeatball and I discussed frame-rate limiting before (inspired by the user who hit the change detection warning overnight). Seems like it'd be a small change to the winit loop. Relevant discussion. https://discord.com/channels/691052431525675048/743663924229963868/906440570203942972