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

mobile and webgpu: trigger redraw request when needed and improve window creation #11245

Merged

Conversation

mockersf
Copy link
Member

@mockersf mockersf commented Jan 7, 2024

Objective

Solution

  • Create initial window on mobile after the initial Resume event. macOS is included because it's excluded from the other initial window creation and I didn't want it to feel alone. Also, it makes sense. this is needed for Android
    #[cfg(not(any(target_os = "android", target_os = "ios", target_os = "macos")))]
  • request redraw during plugin initialisation (needed for WebGPU)
  • request redraw when receiving AboutToWait instead of at the end of the event handler. request to redraw during a RedrawRequested event are ignored on iOS

@mockersf mockersf added C-Bug An unexpected or incorrect behavior O-Android Specific to the Android mobile operating system O-iOS Specific to the iOS mobile operating system labels Jan 7, 2024
@alice-i-cecile alice-i-cecile added this to the 0.13 milestone Jan 7, 2024
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

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

Ah, this is a nice and straightforward fix. Sorry for missing this in my review.

@nicopap nicopap added the P-High This is particularly urgent, and deserves immediate attention label Jan 7, 2024
Copy link
Contributor

@nicopap nicopap left a comment

Choose a reason for hiding this comment

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

I can't really test it, so I'm not confident thumbing up.

But I see window creation on the Event::NewEvents(StartCause::Init) for ios and macos. (lines 367 to 391) Are those now redundant? If they don't run, we should probably remove those lines.

@mockersf mockersf marked this pull request as draft January 7, 2024 21:00
@alice-i-cecile alice-i-cecile added the A-Windowing Platform-agnostic interface layer to run your app in label Jan 7, 2024
@mockersf mockersf changed the title mobile: create window on initial resume mobile and webgpu: trigger redraw request when needed and improve window creation Jan 8, 2024
@mockersf mockersf added the O-WebGPU Specific to the WebGPU render API label Jan 8, 2024
@mockersf mockersf marked this pull request as ready for review January 8, 2024 20:59
@mockersf
Copy link
Member Author

mockersf commented Jan 8, 2024

But I see window creation on the Event::NewEvents(StartCause::Init) for ios and macos. (lines 367 to 391) Are those now redundant? If they don't run, we should probably remove those lines.

Right, we should!

The first commit just fixed Android, and worked on iOS locally due to a cached build artefact with another change.

I added a correct fix for iOS (don't request redraw during a RedrawRequested event) and for WebGPU which was also broken (request redraw during plugin initialisation).

I tested this PR on macOS, WebGL2, WebGPU, iOS and Android

);

create_window_system_state.apply(&mut app.world);
Event::AboutToWait => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Whats the reason for moving Window::request_redraw() into Event::AboutToWait?

I would recommend to call Window::request_redraw() as soon as you know that you want to draw. Calling it in Event::AboutToWait has the disadvantage of queuing that request later then you could, which might let you miss frames.

The previous method of calling Window::request_redraw() at the end of the event loop was therefor better imo.

Copy link
Member Author

Choose a reason for hiding this comment

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

the previous method doesn't work on iOS, because most of Bevy request redraw come from the update which is called when reacting to a RedrawRequested event, and that doesn't work on iOS

Copy link
Contributor

Choose a reason for hiding this comment

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

What exactly doesn't work on iOS?
Are you saying that WindowEvent::RedrawRequested is not being sent on iOS?

Copy link
Member Author

@mockersf mockersf Jan 9, 2024

Choose a reason for hiding this comment

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

Yup, WindowEvent::RedrawRequested is not sent if request_redraw() is called while processing WindowEvent::RedrawRequested on iOS.

I also saw this assert in winit code that also makes me believe it should be avoided
https://github.com/rust-windowing/winit/blob/master/src/platform_impl/ios/app_state.rs#L648-L651

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, this would be a bug in Winit.
Will report back when I know more!

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

@daxpedda I haven't had time yet to test your branch and Bevy is currently broken for another reason on iOS. I will as soon as possible and update you!

@@ -696,6 +676,44 @@ pub fn winit_runner(mut app: App) {
runner_state.active = ActiveState::WillSuspend;
}
Event::Resumed => {
#[cfg(any(target_os = "android", target_os = "ios", target_os = "macos"))]
Copy link
Contributor

@daxpedda daxpedda Jan 9, 2024

Choose a reason for hiding this comment

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

Creating windows outside of Event::Resumed for these targets is indeed incorrect.
So this change is great!

I would recommend you to move window creation of all targets inside Event::Resumed, it would cut down on the cfg guards.
Let me know if there is a reason why this can't be done or isn't desirable!

@@ -682,7 +663,6 @@ pub fn winit_runner(mut app: App) {
event: DeviceEvent::MouseMotion { delta: (x, y) },
..
} => {
runner_state.redraw_requested = true;
Copy link
Contributor

@daxpedda daxpedda Jan 9, 2024

Choose a reason for hiding this comment

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

I believe this is a good change, I tried to describe the issue in #11235 (comment).

However, as far as I'm aware Bevy currently doesn't call Window::request_redraw() when it actually needs to redraw when using reactive mode. Keep in mind that removing this line will make the current status worse until this is properly addressed.

Copy link
Contributor

@nicopap nicopap left a comment

Choose a reason for hiding this comment

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

LGTM. Nice changes. I was wary of using AboutToWait, because of the disclaimer in the doc. But given the restriction on redraw_request on iOS and the fact there isn't an alternative seems to make it the only sensible choice.

@alice-i-cecile alice-i-cecile 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 Jan 9, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jan 9, 2024
Merged via the queue into bevyengine:main with commit 0e61435 Jan 9, 2024
24 checks passed
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-Bug An unexpected or incorrect behavior O-Android Specific to the Android mobile operating system O-iOS Specific to the iOS mobile operating system O-WebGPU Specific to the WebGPU render API P-High This is particularly urgent, and deserves immediate attention 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.

4 participants