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

Wait before making window visible #9692

Merged
merged 3 commits into from
Sep 11, 2023

Conversation

IceSentry
Copy link
Contributor

@IceSentry IceSentry commented Sep 4, 2023

Objective

  • The current example still has one white frame before it starts rendering.

Solution

  • Wait 3 frames before toggling visibility

@IceSentry IceSentry added C-Examples An addition or correction to our examples A-Windowing Platform-agnostic interface layer to run your app in labels Sep 4, 2023
@hymm hymm self-requested a review September 4, 2023 17:49
@mockersf
Copy link
Member

mockersf commented Sep 4, 2023

would it work with a fixed number of frames rather than a timed delay?

@IceSentry
Copy link
Contributor Author

Good idea, I just tried using a fixed number of frames and for me it works with 3 frames.

@IceSentry
Copy link
Contributor Author

I noticed the other systems don't use the PrimaryWindow marker so I removed it too for simplicity.

@IceSentry IceSentry force-pushed the toggle-visible-delay branch from 285236c to e11b83f Compare September 5, 2023 02:14
@IceSentry IceSentry force-pushed the toggle-visible-delay branch from e11b83f to a9b8fb1 Compare September 5, 2023 02:14
Copy link
Contributor

@hymm hymm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. I no longer see the white window on Windows 11.

// There might still be a white frame when doing it in startup.
// Alternatively, you could have a system that waits a few seconds before making the window visible.
primary_window.single_mut().visible = true;
fn toggle_visible(mut window: Query<&mut Window>, frames: Res<FrameCount>) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a good suggestion, but other toggle_ systems in this example are triggered by user input, while this one is more like a delayed setup

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, how about make_visible or automatically_toggle_visible to make it more obvious?

@UkoeHB
Copy link
Contributor

UkoeHB commented Sep 7, 2023

If you set window theme to Dark then it flashes a dark screen which is much less noticeable.

@IceSentry
Copy link
Contributor Author

The dark theme makes it less noticeable, but the fix in this PR makes it completely disappear and only ever render when it's ready. The main issue is that it needs to be done by the user.

Copy link
Member

@JoJoJet JoJoJet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, why aren't we doing this by default in every app?

@IceSentry
Copy link
Contributor Author

why aren't we doing this by default in every app?

The main reason is that for pretty much every other bevy api if a user configures a value bevy won't change it. Implementing this in bevy would require bevy itself taking control of the visible flag. This was mildly controversial when a PR tried to do that last year.

With that being said, there could be ways to do it without this issue. Like, if the flag is set to visible, we could still spawn the window as invisible and then make it visible when the gpu is ready. So we wouldn't actually touch the user controlled visible flag. I can look into making a PR with this approach.

@mockersf
Copy link
Member

mockersf commented Sep 8, 2023

Nice, why aren't we doing this by default in every app?

Doing this directly in engine, a few things would have to be checked:

  • is that empty frame happening on all OS? it seems visibility controls only exists on Windows, macOS and x11. and iOS? no idea what it does there
  • is it happening on all windows, or only the first one created at application start
  • is there a way to check if the texture is ready to be rendered to instead of adding a delay

@IceSentry
Copy link
Contributor Author

is it happening on all windows, or only the first one created at application start

I did some quick testing for this and it looks like only the first window is affected, spawning new windows after that doesn't produce any flash.

is that empty frame happening on all OS?

It definitely happens on windows and I've seen some linux users mention it too. I don't know about macOS or mobile

is there a way to check if the texture is ready to be rendered to instead of adding a delay

From what I understand we mostly need a way to detect the first present on the swap chain. This would require a way to communicate back from the render world to the main world. It's certainly possible but waiting a frame after the window creation also does the trick and is much easier to implement. This PR needs more than a frame because I think the window doesn't get created instantly.

@mockersf mockersf added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Sep 8, 2023
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Sep 11, 2023
Merged via the queue into bevyengine:main with commit 027ff9f Sep 11, 2023
@bjorn3
Copy link
Contributor

bjorn3 commented Sep 11, 2023

For non-game style apps it is common to avoid requesting a new frame to be drawn on every vsync, right? In that case I would expect it to be possible to have the frame count get stuck at a value smaller than 3 until the user directly interacts with the app to trigger a rerender.

@IceSentry
Copy link
Contributor Author

IceSentry commented Sep 11, 2023

@bjorn3 yes that's also something that would need to be considered in a built-in solution. That's why this is just an example to show how to use the api to enable/disable window visibility.

rdrpenguin04 pushed a commit to rdrpenguin04/bevy that referenced this pull request Jan 9, 2024
# Objective

- The current example still has one white frame before it starts
rendering.

## Solution

- Wait 3 frames before toggling visibility
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Windowing Platform-agnostic interface layer to run your app in C-Examples An addition or correction to our examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants