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

Force Android emulator to use GPU hardware acceleration #2319

Closed
roman-petrov opened this issue Mar 26, 2020 · 18 comments
Closed

Force Android emulator to use GPU hardware acceleration #2319

roman-petrov opened this issue Mar 26, 2020 · 18 comments
Labels
in flutter Relates to running Flutter apps is enhancement
Milestone

Comments

@roman-petrov
Copy link

On my machine emulator seems to be running without GPU acceleration when launched from Visual Studio Code or AVD event when I configure hardware acceleration as follows:

image

But I when I launch it from command line with -gpu host argument rendering performance increases dramatically.

Android documentation at https://developer.android.com/studio/run/emulator-acceleration says:

By default, the emulator decides whether to use hardware or software graphics acceleration based on your computer setup. If your GPU hardware and drivers are compatible, the emulator uses the GPU. Otherwise, the emulator uses software acceleration (using your computer's CPU) to simulate GPU processing.

If you start the emulator from the command line, you can also override the graphics acceleration setting in the AVD for that virtual device instance.

I am not sure if this is some issue with Android emulators / AVD on my machine or it is something that could help other users too and might be implemented in Dart Code?..

@roman-petrov
Copy link
Author

I decided to close this issue since I figured out that Dart Code launches Flutter emulator through

flutter emulators --launch <emulator id>

so feature I suggested should be available in Flutter first...

@DanTup
Copy link
Member

DanTup commented Mar 30, 2020

Yep, Flutter does the emulator launching. If it's a common need to force this, it may make sense to have a switch in Flutter (which could be passed through from DartVS Code).

The code that launches is here:

https://github.com/flutter/flutter/blob/ba57ea09d17a30c05d6771cffdb6d10250b2f359/packages/flutter_tools/lib/src/android/android_emulator.dart#L56-L59

And that gets called from here:

https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/commands/emulators.dart#L72

If there's a switch you can add on to emulator -avd foo to control the hardware acceleration, it might not be too tricky to pass a flag through there.

@roman-petrov
Copy link
Author

@DanTup, thank you for clarifications. Currently I am not sure if anybody else observes that launching emulators when using -gpu host flag from console significantly speeds up emulator: this is only my observation which might be incorrect.

So being not sure if it 's a common need to force GPU acceleration from console I closed the issue.

@DanTup
Copy link
Member

DanTup commented Apr 13, 2020

How significant is the difference you see, and on what OS (both host, and which Android version)?

I tested with a Pixel emulator on MacBook Pro and see about 14 seconds (cold boot) with and without the flag.

Based on the info at https://developer.android.com/studio/run/emulator-acceleration#accel-graphics it seems like this my default based on the emulator image - so you may be able to set this in Android Studio and then in future it'll use that setting without needing the flag:

Screenshot 2020-04-13 at 12 17 16

@roman-petrov
Copy link
Author

@DanTup, actually in my observations I see performance improvement only in rendering, not startup. So when I launch emulator from console with -gpu host I see that animations are smoother than when I launch from VSCode/Android Studio.

But as I said - I am not sure if this is happening only on my machine and if anyone else is able to reproduce such behavior, so I decided to close this issue...

@DanTup
Copy link
Member

DanTup commented Apr 13, 2020

Oh sorry, I misunderstood your comment and thought you were talking about the launch performance (I did think that sounded a bit strange!).

If you change the emulator settings using the dropdown shown above, does that resolve the issue when launching from VS Code?

@roman-petrov
Copy link
Author

roman-petrov commented Apr 14, 2020

Actually, I tried setting Graphics dropdown to both Automatic and Hardware - GLES 2.0 and launching emulator from AVD Manager

Still my observations are that rendering is better/smoother if I launch emulator using command line using console command

C:\Users\<my username>\AppData\Local\Android\Sdk\emulator\emulator.exe -avd MyAvd -gpu host

Anyways, this issue (if it exists) is 100% not connected to Dart-Code, it might be related to Android tooling or even my machine configuration.

That's why I decided to close the issue:) @DanTup, thank you very much for all your help!

@DanTup
Copy link
Member

DanTup commented Apr 14, 2020

Ah, I guess that menu doesn't do the same.

There's an open issue at #1553 that might provide another way to do this (if implemented) that would let you override the command executed to launch an emulator (so you could replace it with emulator -avd foo -gpu host).

@roman-petrov
Copy link
Author

Thank you! Actually I am already following the issue you mentioned and looking forward to see it resolved.

@DanTup
Copy link
Member

DanTup commented Apr 15, 2020

I've implemented it and added an example of how it works to #1553. I'll ship a beta version for testing later in the month if you want to try it out before it ships in a release.

@roman-petrov
Copy link
Author

Thank you very much for all your efforts! I will definitely try this feature after beta is shipped!

@DanTup DanTup added this to the v3.10.0 milestone Apr 27, 2020
@DanTup DanTup added in flutter Relates to running Flutter apps is enhancement labels Apr 27, 2020
@doducthangcvp291
Copy link

@roman-petrov Currently I am using a Dell laptop , with 2 GPUs, an onboard GPU and an AMD Radeon R5 M435. When I run Android Studio + emulator (installed running on hardware) and I check that it only uses the onboard GPU . How to use AMD for running emulator .

@roman-petrov
Copy link
Author

@doducthangcvp291, I don't have any idea how to answer your question. All these issue details are listed above, I have nothing to add.

@doducthangcvp291
Copy link

I just use command C:\Users<my username>\AppData\Local\Android\Sdk\emulator\emulator.exe -avd MyAvd -gpu host , right ?

@roman-petrov
Copy link
Author

This is the closed issue in Dart Code plugin for Visual Studio Code but you asking just a general question about Android emulators. So this is not the right place to ask such questions and I am not an expert in Android emulators, please read the official documentation about how to use them.

@gopelkujo
Copy link

gopelkujo commented Oct 6, 2022

Actually, I tried setting Graphics dropdown to both Automatic and Hardware - GLES 2.0 and launching emulator from AVD Manager

Still my observations are that rendering is better/smoother if I launch emulator using command line using console command

C:\Users\<my username>\AppData\Local\Android\Sdk\emulator\emulator.exe -avd MyAvd -gpu host

Anyways, this issue (if it exists) is 100% not connected to Dart-Code, it might be related to Android tooling or even my machine configuration.

That's why I decided to close the issue:) @DanTup, thank you very much for all your help!

I just experienced the same thing as you (slow emulator when running from flutter vscode) in Linux, and your information running emulator from that command really help me boost my emulator performance, i still haven't found a fix solution. But anyway thanks for that!

@pedrohms
Copy link

I dont know if you already fix this issue, but the work oround I used is:
1.I changed the name from emulator to emulator-bin
2. And created a bash script with $EMULATOR_PATH/emulator $*

this fixed my problem

@BiEchi
Copy link

BiEchi commented Mar 13, 2024

Seems like -gpu host raises such error. Is there a way to solve it?

WARNING | Your GPU drivers may have a bug. If you experience graphical issues, please consider switching to software rendering.
library_mode host gpu mode host
Initializing hardware OpenGLES emulation supportandroid_startOpenglesRenderer: gpu infoI0313 22:50:00.118760 27958 HealthMonitor.cpp:279] HealthMonitor disabled.
GlxEnginegetDefaultDisplay: Failed to open display 0. DISPLAY: [(null)]
E0313 22:50:00.119003 27958 EmulationGl.cpp:233] Failed to get EGL display.
E0313 22:50:00.119014 27958 FrameBuffer.cpp:333] Failed to initialize GL emulation.
E0313 22:50:00.119046 27958 RendererImpl.cpp:141] Could not initialize emulated framebuffer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in flutter Relates to running Flutter apps is enhancement
Projects
None yet
Development

No branches or pull requests

6 participants