[Impeller] Reland: Added a switch to turn on vulkan (flutter/engine#42669)

relands https://github.com/flutter/engine/pull/42585

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide] and the [C++,
Objective-C, Java style guides].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [ ] I added new tests to check the change I am making or feature I am
adding, or Hixie said the PR is test-exempt. See [testing the engine]
for instructions on writing and running engine tests.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I signed the [CLA].
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[C++, Objective-C, Java style guides]:
https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
[testing the engine]:
https://github.com/flutter/flutter/wiki/Testing-the-engine
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat
This commit is contained in:
gaaclarke
2023-06-09 18:35:29 +00:00
committed by GitHub
parent 73d68604ab
commit bf5c52d8af
7 changed files with 59 additions and 22 deletions

View File

@@ -217,6 +217,9 @@ struct Settings {
bool enable_impeller = false;
#endif
// Requests a particular backend to be used (ex "opengles" or "vulkan")
std::optional<std::string> impeller_backend;
// Enable Vulkan validation on backends that support it. The validation layers
// must be available to the application.
bool enable_vulkan_validation = false;

View File

@@ -443,11 +443,23 @@ Settings SettingsFromCommandLine(const fml::CommandLine& command_line) {
settings.use_asset_fonts =
!command_line.HasOption(FlagForSwitch(Switch::DisableAssetFonts));
std::string enable_impeller_value;
if (command_line.GetOptionValue(FlagForSwitch(Switch::EnableImpeller),
&enable_impeller_value)) {
settings.enable_impeller =
enable_impeller_value.empty() || "true" == enable_impeller_value;
{
std::string enable_impeller_value;
if (command_line.GetOptionValue(FlagForSwitch(Switch::EnableImpeller),
&enable_impeller_value)) {
settings.enable_impeller =
enable_impeller_value.empty() || "true" == enable_impeller_value;
}
}
{
std::string impeller_backend_value;
if (command_line.GetOptionValue(FlagForSwitch(Switch::ImpellerBackend),
&impeller_backend_value)) {
if (!impeller_backend_value.empty()) {
settings.impeller_backend = impeller_backend_value;
}
}
}
settings.enable_vulkan_validation =

View File

@@ -261,6 +261,10 @@ DEF_SWITCH(EnableImpeller,
"enable-impeller",
"Enable the Impeller renderer on supported platforms. Ignored if "
"Impeller is not supported on the platform.")
DEF_SWITCH(ImpellerBackend,
"impeller-backend",
"Requests a particular Impeller backend on platforms that support "
"multiple backends. (ex `opengles` or `vulkan`)")
DEF_SWITCH(EnableVulkanValidation,
"enable-vulkan-validation",
"Enable loading Vulkan validation layers. The layers must be "

View File

@@ -74,7 +74,7 @@ static std::shared_ptr<impeller::Context> CreateImpellerContext(
FML_LOG(ERROR) << "Could not add reactor worker.";
return nullptr;
}
FML_LOG(ERROR) << "Using the Impeller rendering backend.";
FML_LOG(ERROR) << "Using the Impeller rendering backend (OpenGLES).";
return context;
}

View File

@@ -34,6 +34,9 @@ static std::shared_ptr<impeller::Context> CreateImpellerContext(
settings.cache_directory = fml::paths::GetCachesDirectory();
settings.worker_task_runner = std::move(worker_task_runner);
settings.enable_validation = enable_vulkan_validation;
FML_LOG(ERROR) << "Using the Impeller rendering backend (Vulkan).";
return impeller::ContextVK::Create(std::move(settings));
}

View File

@@ -43,6 +43,8 @@ public class FlutterLoader {
"io.flutter.embedding.android.EnableImpeller";
private static final String ENABLE_VULKAN_VALIDATION_META_DATA_KEY =
"io.flutter.embedding.android.EnableVulkanValidation";
private static final String IMPELLER_BACKEND_META_DATA_KEY =
"io.flutter.embedding.android.ImpellerBackend";
/**
* Set whether leave or clean up the VM after the last shell shuts down. It can be set from app's
@@ -325,6 +327,8 @@ public class FlutterLoader {
if (metaData.getBoolean(ENABLE_VULKAN_VALIDATION_META_DATA_KEY, false)) {
shellArgs.add("--enable-vulkan-validation");
}
String backend = metaData.getString(IMPELLER_BACKEND_META_DATA_KEY, "opengles");
shellArgs.add("--impeller-backend=" + backend);
}
final String leakVM = isLeakVM(metaData) ? "true" : "false";

View File

@@ -51,16 +51,9 @@ std::unique_ptr<AndroidSurface> AndroidSurfaceFactoryImpl::CreateSurface() {
}
case AndroidRenderingAPI::kVulkan:
FML_DCHECK(enable_impeller_);
// TODO(kaushikiska@): Enable this after wiring a preference for Vulkan
// backend.
#if false
return std::make_unique<AndroidSurfaceVulkanImpeller>(
return std::make_unique<AndroidSurfaceVulkanImpeller>(
std::static_pointer_cast<AndroidContextVulkanImpeller>(
android_context_));
#else
return std::make_unique<AndroidSurfaceGLImpeller>(
std::static_pointer_cast<AndroidContextGLImpeller>(android_context_));
#endif
default:
FML_DCHECK(false);
return nullptr;
@@ -73,19 +66,36 @@ static std::shared_ptr<flutter::AndroidContext> CreateAndroidContext(
const std::shared_ptr<fml::ConcurrentTaskRunner>& worker_task_runner,
uint8_t msaa_samples,
bool enable_impeller,
const std::optional<std::string>& impeller_backend,
bool enable_vulkan_validation) {
if (use_software_rendering) {
return std::make_shared<AndroidContext>(AndroidRenderingAPI::kSoftware);
}
if (enable_impeller) {
// TODO(kaushikiska@): Enable this after wiring a preference for Vulkan
// backend.
#if false
return std::make_unique<AndroidContextVulkanImpeller>(enable_vulkan_validation, std::move(worker_task_runner));
#else
return std::make_unique<AndroidContextGLImpeller>(
std::make_unique<impeller::egl::Display>());
#endif
// TODO(gaaclarke): We need to devise a more complete heuristic about what
// backend to use by default.
// Default value is OpenGLES.
AndroidRenderingAPI backend = AndroidRenderingAPI::kOpenGLES;
if (impeller_backend.has_value()) {
if (impeller_backend.value() == "opengles") {
backend = AndroidRenderingAPI::kOpenGLES;
} else if (impeller_backend.value() == "vulkan") {
backend = AndroidRenderingAPI::kVulkan;
} else {
FML_CHECK(impeller_backend.value() == "vulkan" ||
impeller_backend.value() == "opengles");
}
}
switch (backend) {
case AndroidRenderingAPI::kOpenGLES:
return std::make_unique<AndroidContextGLImpeller>(
std::make_unique<impeller::egl::Display>());
case AndroidRenderingAPI::kVulkan:
return std::make_unique<AndroidContextVulkanImpeller>(
enable_vulkan_validation, worker_task_runner);
default:
FML_UNREACHABLE();
}
}
return std::make_unique<AndroidContextGLSkia>(
AndroidRenderingAPI::kOpenGLES, //
@@ -112,6 +122,7 @@ PlatformViewAndroid::PlatformViewAndroid(
worker_task_runner,
msaa_samples,
delegate.OnPlatformViewGetSettings().enable_impeller,
delegate.OnPlatformViewGetSettings().impeller_backend,
delegate.OnPlatformViewGetSettings().enable_vulkan_validation)) {}
PlatformViewAndroid::PlatformViewAndroid(