From 20975061360bae81bb929c7d54ab6af4c472eac2 Mon Sep 17 00:00:00 2001 From: gaaclarke <30870216+gaaclarke@users.noreply.github.com> Date: Fri, 9 Jun 2023 17:22:21 +0000 Subject: [PATCH] [Impeller] Makes validation layers flag work for android (flutter/engine#42625) This builds and links in the validation layers for android. They then can be turned on or off with a manifest field. fixes https://github.com/flutter/flutter/issues/123788 depends on https://github.com/flutter/buildroot/pull/741 ## 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. - [ ] I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides]. - [x] 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]. [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 --- DEPS | 2 +- .../flutter/shell/platform/android/BUILD.gn | 22 +++++++++++++++++++ .../engine/loader/FlutterLoader.java | 11 ++++++++-- .../shell/platform/fuchsia/flutter/BUILD.gn | 1 + .../scenario_app/android/gradle.properties | 2 +- engine/src/flutter/tools/gn | 9 ++++---- engine/src/flutter/vulkan/config.gni | 6 +---- 7 files changed, 39 insertions(+), 14 deletions(-) diff --git a/DEPS b/DEPS index 11e74f6419..40e65a8ab8 100644 --- a/DEPS +++ b/DEPS @@ -257,7 +257,7 @@ allowed_hosts = [ ] deps = { - 'src': 'https://github.com/flutter/buildroot.git' + '@' + '859e7ccc38f55f89dac8aea49367b7a4c1656490', + 'src': 'https://github.com/flutter/buildroot.git' + '@' + 'fabb92f0ada787444ad0be22638c80a6d5927a2c', # Fuchsia compatibility # diff --git a/engine/src/flutter/shell/platform/android/BUILD.gn b/engine/src/flutter/shell/platform/android/BUILD.gn index 0f3ff3ebb5..da4811bdcf 100644 --- a/engine/src/flutter/shell/platform/android/BUILD.gn +++ b/engine/src/flutter/shell/platform/android/BUILD.gn @@ -6,9 +6,11 @@ import("//build/config/android/config.gni") import("//build/toolchain/clang.gni") import("//flutter/build/zip_bundle.gni") import("//flutter/common/config.gni") +import("//flutter/impeller/tools/impeller.gni") import("//flutter/shell/config.gni") import("//flutter/shell/gpu/gpu.gni") import("//flutter/shell/version/version.gni") +import("//flutter/vulkan/config.gni") shell_gpu_configuration("android_gpu_configuration") { enable_software = true @@ -478,6 +480,26 @@ action("android_jar") { ":pom_libflutter", ] + if (enable_vulkan_validation_layers) { + assert(impeller_enable_vulkan) + deps += [ "//third_party/vulkan_validation_layers" ] + args += [ + "--native_lib", + rebase_path("libVkLayer_khronos_validation.so", + root_build_dir, + root_build_dir), + ] + if (current_cpu == "arm64") { + args += [ + "--native_lib", + rebase_path("$android_libcpp_root/libs/arm64-v8a/libc++_shared.so", + root_build_dir), + ] + } else { + assert(false, "Validation layers not supported for arch.") + } + } + if (flutter_runtime_mode == "profile") { deps += [ "//flutter/shell/vmservice:vmservice_snapshot" ] args += [ diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java index 5461838e7a..38334c6452 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java @@ -41,6 +41,8 @@ public class FlutterLoader { "io.flutter.embedding.android.OldGenHeapSize"; private static final String ENABLE_IMPELLER_META_DATA_KEY = "io.flutter.embedding.android.EnableImpeller"; + private static final String ENABLE_VULKAN_VALIDATION_META_DATA_KEY = + "io.flutter.embedding.android.EnableVulkanValidation"; /** * Set whether leave or clean up the VM after the last shell shuts down. It can be set from app's @@ -316,8 +318,13 @@ public class FlutterLoader { shellArgs.add("--prefetched-default-font-manager"); - if (metaData != null && metaData.getBoolean(ENABLE_IMPELLER_META_DATA_KEY, false)) { - shellArgs.add("--enable-impeller"); + if (metaData != null) { + if (metaData.getBoolean(ENABLE_IMPELLER_META_DATA_KEY, false)) { + shellArgs.add("--enable-impeller"); + } + if (metaData.getBoolean(ENABLE_VULKAN_VALIDATION_META_DATA_KEY, false)) { + shellArgs.add("--enable-vulkan-validation"); + } } final String leakVM = isLeakVM(metaData) ? "true" : "false"; diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/BUILD.gn b/engine/src/flutter/shell/platform/fuchsia/flutter/BUILD.gn index 68af2224ef..b9b4202306 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/BUILD.gn +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/BUILD.gn @@ -6,6 +6,7 @@ assert(is_fuchsia) import("//build/fuchsia/sdk.gni") import("//flutter/common/config.gni") +import("//flutter/shell/config.gni") import("//flutter/shell/gpu/gpu.gni") import("//flutter/testing/testing.gni") import("//flutter/tools/fuchsia/dart.gni") diff --git a/engine/src/flutter/testing/scenario_app/android/gradle.properties b/engine/src/flutter/testing/scenario_app/android/gradle.properties index 06d12a7d35..0b5c48ae64 100644 --- a/engine/src/flutter/testing/scenario_app/android/gradle.properties +++ b/engine/src/flutter/testing/scenario_app/android/gradle.properties @@ -1,4 +1,4 @@ -org.gradle.jvmargs=-Xmx1536M +org.gradle.jvmargs=-Xmx2048M android.useAndroidX=true android.enableJetifier=true android.builder.sdkDownload=false diff --git a/engine/src/flutter/tools/gn b/engine/src/flutter/tools/gn index d94ba6e56f..07334fbdde 100755 --- a/engine/src/flutter/tools/gn +++ b/engine/src/flutter/tools/gn @@ -80,6 +80,8 @@ def to_command_line(gn_args): def merge(key, value): if isinstance(value, bool): return '%s=%s' % (key, 'true' if value else 'false') + if isinstance(value, int): + return '%s=%d' % (key, value) return '%s="%s"' % (key, value) return [merge(x, y) for x, y in gn_args.items()] @@ -548,11 +550,8 @@ def to_gn_args(args): gn_args['use_fstack_protector'] = True if args.enable_vulkan_validation_layers: - if args.target_os != 'fuchsia': - print( - 'Vulkan validation layers are currently only supported on Fuchsia targets.' - ) - sys.exit(1) + if args.target_os == 'android': + gn_args['android_api_level'] = 26 gn_args['enable_vulkan_validation_layers'] = True # Enable pointer compression on 64-bit mobile targets. iOS is excluded due to diff --git a/engine/src/flutter/vulkan/config.gni b/engine/src/flutter/vulkan/config.gni index 08ccbab720..bbddfb1dfa 100644 --- a/engine/src/flutter/vulkan/config.gni +++ b/engine/src/flutter/vulkan/config.gni @@ -3,10 +3,6 @@ # found in the LICENSE file. declare_args() { - # Whether to include vulkan validation layers, if available. - # - # Currently these are only supported on Fuchsia, where by default they are - # disabled, to enable them pass `--enable-vulkan-validation-layers` to your - # gn args. + # Whether to include vulkan validation layers. enable_vulkan_validation_layers = false }