Skip to content

Commit

Permalink
[Impeller] Use Vulkan by default (#40809)
Browse files Browse the repository at this point in the history
[Impeller] Use Vulkan by default
dnfield authored Mar 31, 2023

Verified

This commit was signed with the committer’s verified signature.
Ana06 Ana María Martínez Gómez
1 parent 013e936 commit a6421ed
Showing 18 changed files with 105 additions and 60 deletions.
8 changes: 4 additions & 4 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
@@ -2182,10 +2182,10 @@ ORIGIN: ../../../flutter/shell/gpu/gpu_surface_vulkan_impeller.h + ../../../flut
ORIGIN: ../../../flutter/shell/platform/android/AndroidManifest.xml + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/android_choreographer.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/android_choreographer.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/android_context_gl_impeller.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/android_context_gl_impeller.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/android_context_gl_skia.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/android_context_gl_skia.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/android_context_impeller.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/android_context_impeller.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/android_display.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/android_display.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/android_egl_surface.cc + ../../../flutter/LICENSE
@@ -4759,10 +4759,10 @@ FILE: ../../../flutter/shell/gpu/gpu_surface_vulkan_impeller.h
FILE: ../../../flutter/shell/platform/android/AndroidManifest.xml
FILE: ../../../flutter/shell/platform/android/android_choreographer.cc
FILE: ../../../flutter/shell/platform/android/android_choreographer.h
FILE: ../../../flutter/shell/platform/android/android_context_gl_impeller.cc
FILE: ../../../flutter/shell/platform/android/android_context_gl_impeller.h
FILE: ../../../flutter/shell/platform/android/android_context_gl_skia.cc
FILE: ../../../flutter/shell/platform/android/android_context_gl_skia.h
FILE: ../../../flutter/shell/platform/android/android_context_impeller.cc
FILE: ../../../flutter/shell/platform/android/android_context_impeller.h
FILE: ../../../flutter/shell/platform/android/android_display.cc
FILE: ../../../flutter/shell/platform/android/android_display.h
FILE: ../../../flutter/shell/platform/android/android_egl_surface.cc
5 changes: 5 additions & 0 deletions common/settings.h
Original file line number Diff line number Diff line change
@@ -221,6 +221,11 @@ struct Settings {
// must be available to the application.
bool enable_vulkan_validation = false;

// Force Impeller to use the GL backend if possible.
// On platforms where there is no GL backend (e.g. macOS and iOS), this is a
// no-op.
bool impeller_force_gl = false;

// Data set by platform-specific embedders for use in font initialization.
uint32_t font_initialization_data = 0;

1 change: 1 addition & 0 deletions impeller/entity/contents/tiled_texture_contents.h
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
#include "impeller/entity/contents/filters/color_filter_contents.h"
#include "impeller/entity/entity.h"
#include "impeller/geometry/path.h"
#include "impeller/renderer/capabilities.h"
#include "impeller/renderer/sampler_descriptor.h"

namespace impeller {
3 changes: 3 additions & 0 deletions shell/common/switches.cc
Original file line number Diff line number Diff line change
@@ -453,6 +453,9 @@ Settings SettingsFromCommandLine(const fml::CommandLine& command_line) {
settings.enable_vulkan_validation =
command_line.HasOption(FlagForSwitch(Switch::EnableVulkanValidation));

settings.impeller_force_gl =
command_line.HasOption(FlagForSwitch(Switch::ImpellerForceGL));

settings.enable_embedder_api =
command_line.HasOption(FlagForSwitch(Switch::EnableEmbedderAPI));

6 changes: 6 additions & 0 deletions shell/common/switches.h
Original file line number Diff line number Diff line change
@@ -266,6 +266,12 @@ DEF_SWITCH(EnableVulkanValidation,
"Enable loading Vulkan validation layers. The layers must be "
"available to the application and loadable. On non-Vulkan backends, "
"this flag does nothing.")
DEF_SWITCH(
ImpellerForceGL,
"impeller-force-gl",
"Force Impeller to use the GL backend if it is available. If Impeller is "
"not enabled or it does not support a GL backend for the target "
"platform this flag does nothing.")
DEF_SWITCH(LeakVM,
"leak-vm",
"When the last shell shuts down, the shared VM is leaked by default "
4 changes: 2 additions & 2 deletions shell/platform/android/BUILD.gn
Original file line number Diff line number Diff line change
@@ -66,10 +66,10 @@ source_set("flutter_shell_native_src") {
"$root_build_dir/flutter_icu/icudtl.o",
"android_choreographer.cc",
"android_choreographer.h",
"android_context_gl_impeller.cc",
"android_context_gl_impeller.h",
"android_context_gl_skia.cc",
"android_context_gl_skia.h",
"android_context_impeller.cc",
"android_context_impeller.h",
"android_display.cc",
"android_display.h",
"android_egl_surface.cc",
18 changes: 0 additions & 18 deletions shell/platform/android/android_context_gl_impeller.cc

This file was deleted.

2 changes: 1 addition & 1 deletion shell/platform/android/android_context_gl_skia.cc
Original file line number Diff line number Diff line change
@@ -69,7 +69,7 @@ AndroidContextGLSkia::AndroidContextGLSkia(
fml::RefPtr<AndroidEnvironmentGL> environment,
const TaskRunners& task_runners,
uint8_t msaa_samples)
: AndroidContext(AndroidRenderingAPI::kOpenGLES),
: AndroidContext(AndroidRenderingAPI::kGPU),
environment_(std::move(environment)),
config_(nullptr),
task_runners_(task_runners) {
12 changes: 6 additions & 6 deletions shell/platform/android/android_context_gl_unittests.cc
Original file line number Diff line number Diff line change
@@ -87,7 +87,7 @@ TEST(AndroidContextGl, Create) {
ThreadHost::Type::UI | ThreadHost::Type::RASTER | ThreadHost::Type::IO));
TaskRunners task_runners = MakeTaskRunners(thread_label, thread_host);
auto context = std::make_unique<AndroidContextGLSkia>(
AndroidRenderingAPI::kOpenGLES, environment, task_runners, 0);
AndroidRenderingAPI::kGPU, environment, task_runners, 0);
context->SetMainSkiaContext(main_context);
EXPECT_NE(context.get(), nullptr);
context.reset();
@@ -108,7 +108,7 @@ TEST(AndroidContextGl, CreateSingleThread) {
TaskRunners(thread_label, platform_runner, platform_runner,
platform_runner, platform_runner);
auto context = std::make_unique<AndroidContextGLSkia>(
AndroidRenderingAPI::kOpenGLES, environment, task_runners, 0);
AndroidRenderingAPI::kGPU, environment, task_runners, 0);
context->SetMainSkiaContext(main_context);
EXPECT_NE(context.get(), nullptr);
context.reset();
@@ -127,7 +127,7 @@ TEST(AndroidSurfaceGL, CreateSnapshopSurfaceWhenOnscreenSurfaceIsNotNull) {
ThreadHost::Type::UI | ThreadHost::Type::RASTER | ThreadHost::Type::IO));
TaskRunners task_runners = MakeTaskRunners(thread_label, thread_host);
auto android_context = std::make_shared<AndroidContextGLSkia>(
AndroidRenderingAPI::kOpenGLES, environment, task_runners, 0);
AndroidRenderingAPI::kGPU, environment, task_runners, 0);
auto jni = std::make_shared<MockPlatformViewAndroidJNI>();
auto android_surface =
std::make_unique<AndroidSurfaceGLSkia>(android_context, jni);
@@ -155,7 +155,7 @@ TEST(AndroidSurfaceGL, CreateSnapshopSurfaceWhenOnscreenSurfaceIsNull) {
ThreadHost thread_host(host_config);
TaskRunners task_runners = MakeTaskRunners(thread_label, thread_host);
auto android_context = std::make_shared<AndroidContextGLSkia>(
AndroidRenderingAPI::kOpenGLES, environment, task_runners, 0);
AndroidRenderingAPI::kGPU, environment, task_runners, 0);
auto jni = std::make_shared<MockPlatformViewAndroidJNI>();
auto android_surface =
std::make_unique<AndroidSurfaceGLSkia>(android_context, jni);
@@ -178,7 +178,7 @@ TEST(AndroidContextGl, DISABLED_MSAAx4) {
ThreadHost::Type::UI | ThreadHost::Type::RASTER | ThreadHost::Type::IO));
TaskRunners task_runners = MakeTaskRunners(thread_label, thread_host);
auto context = std::make_unique<AndroidContextGLSkia>(
AndroidRenderingAPI::kOpenGLES, environment, task_runners, 4);
AndroidRenderingAPI::kGPU, environment, task_runners, 4);
context->SetMainSkiaContext(main_context);

EGLint sample_count;
@@ -200,7 +200,7 @@ TEST(AndroidContextGl, EnsureMakeCurrentChecksCurrentContextStatus) {
ThreadHost::Type::UI | ThreadHost::Type::RASTER | ThreadHost::Type::IO));
TaskRunners task_runners = MakeTaskRunners(thread_label, thread_host);
auto context = std::make_unique<AndroidContextGLSkia>(
AndroidRenderingAPI::kOpenGLES, environment, task_runners, 0);
AndroidRenderingAPI::kGPU, environment, task_runners, 0);

auto pbuffer_surface = context->CreatePbufferSurface();
auto status = pbuffer_surface->MakeCurrent();
18 changes: 18 additions & 0 deletions shell/platform/android/android_context_impeller.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "flutter/shell/platform/android/android_context_impeller.h"

namespace flutter {

AndroidContextImpeller::AndroidContextImpeller()
: AndroidContext(AndroidRenderingAPI::kGPU) {}

AndroidContextImpeller::~AndroidContextImpeller() = default;

bool AndroidContextImpeller::IsValid() const {
return true;
}

} // namespace flutter
Original file line number Diff line number Diff line change
@@ -2,27 +2,27 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_CONTEXT_GL_IMPELLER_H_
#define FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_CONTEXT_GL_IMPELLER_H_
#ifndef FLUTTER_SHELL_PLATFORM_ANDROID_android_context_impeller_H_
#define FLUTTER_SHELL_PLATFORM_ANDROID_android_context_impeller_H_

#include "flutter/fml/macros.h"
#include "flutter/shell/platform/android/context/android_context.h"

namespace flutter {

class AndroidContextGLImpeller : public AndroidContext {
class AndroidContextImpeller : public AndroidContext {
public:
AndroidContextGLImpeller();
AndroidContextImpeller();

~AndroidContextGLImpeller();
~AndroidContextImpeller();

// |AndroidContext|
bool IsValid() const override;

private:
FML_DISALLOW_COPY_AND_ASSIGN(AndroidContextGLImpeller);
FML_DISALLOW_COPY_AND_ASSIGN(AndroidContextImpeller);
};

} // namespace flutter

#endif // FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_CONTEXT_GL_IMPELLER_H_
#endif // FLUTTER_SHELL_PLATFORM_ANDROID_android_context_impeller_H_
3 changes: 1 addition & 2 deletions shell/platform/android/android_surface_gl_impeller.cc
Original file line number Diff line number Diff line change
@@ -75,10 +75,9 @@ 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 GL rendering backend.";
return context;
}

AndroidSurfaceGLImpeller::AndroidSurfaceGLImpeller(
const std::shared_ptr<AndroidContext>& android_context,
const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade)
3 changes: 3 additions & 0 deletions shell/platform/android/android_surface_vulkan_impeller.cc
Original file line number Diff line number Diff line change
@@ -56,6 +56,9 @@ AndroidSurfaceVulkanImpeller::AndroidSurfaceVulkanImpeller(
CreateImpellerContext(proc_table_, workers_, enable_vulkan_validation);
is_valid_ =
proc_table_->HasAcquiredMandatoryProcAddresses() && impeller_context_;
if (is_valid_) {
FML_LOG(ERROR) << "Using the Impeller Vulkan rendering backend.";
}
}

AndroidSurfaceVulkanImpeller::~AndroidSurfaceVulkanImpeller() = default;
2 changes: 1 addition & 1 deletion shell/platform/android/context/android_context.h
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ namespace flutter {

enum class AndroidRenderingAPI {
kSoftware,
kOpenGLES,
kGPU,
};

//------------------------------------------------------------------------------
Original file line number Diff line number Diff line change
@@ -46,6 +46,8 @@ public class FlutterShellArgs {
public static final String ARG_ENABLE_IMPELLER = "--enable-impeller";
public static final String ARG_KEY_ENABLE_VULKAN_VALIDATION = "enable-vulkan-validation";
public static final String ARG_ENABLE_VULKAN_VALIDATION = "--enable-vulkan-validation";
public static final String ARG_KEY_IMPELLER_FORCE_GL = "impeller-force-gl";
public static final String ARG_IMPELLER_FORCE_GL = "--impeller-force-gl";
public static final String ARG_KEY_DUMP_SHADER_SKP_ON_SHADER_COMPILATION =
"dump-skp-on-shader-compilation";
public static final String ARG_DUMP_SHADER_SKP_ON_SHADER_COMPILATION =
@@ -126,6 +128,9 @@ public static FlutterShellArgs fromIntent(@NonNull Intent intent) {
if (intent.getBooleanExtra(ARG_KEY_ENABLE_VULKAN_VALIDATION, false)) {
args.add(ARG_ENABLE_VULKAN_VALIDATION);
}
if (intent.getBooleanExtra(ARG_KEY_IMPELLER_FORCE_GL, false)) {
args.add(ARG_IMPELLER_FORCE_GL);
}
if (intent.getBooleanExtra(ARG_KEY_DUMP_SHADER_SKP_ON_SHADER_COMPILATION, false)) {
args.add(ARG_DUMP_SHADER_SKP_ON_SHADER_COMPILATION);
}
39 changes: 21 additions & 18 deletions shell/platform/android/platform_view_android.cc
Original file line number Diff line number Diff line change
@@ -10,8 +10,8 @@
#include "flutter/fml/synchronization/waitable_event.h"
#include "flutter/shell/common/shell_io_manager.h"
#include "flutter/shell/gpu/gpu_surface_gl_delegate.h"
#include "flutter/shell/platform/android/android_context_gl_impeller.h"
#include "flutter/shell/platform/android/android_context_gl_skia.h"
#include "flutter/shell/platform/android/android_context_impeller.h"
#include "flutter/shell/platform/android/android_external_texture_gl.h"
#include "flutter/shell/platform/android/android_surface_gl_impeller.h"
#include "flutter/shell/platform/android/android_surface_gl_skia.h"
@@ -33,11 +33,13 @@ AndroidSurfaceFactoryImpl::AndroidSurfaceFactoryImpl(
const std::shared_ptr<AndroidContext>& context,
std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
bool enable_impeller,
bool enable_vulkan_validation)
bool enable_vulkan_validation,
bool impeller_force_gl)
: android_context_(context),
jni_facade_(std::move(jni_facade)),
enable_impeller_(enable_impeller),
enable_vulkan_validation_(enable_vulkan_validation) {}
enable_vulkan_validation_(enable_vulkan_validation),
impeller_force_gl_(impeller_force_gl) {}

AndroidSurfaceFactoryImpl::~AndroidSurfaceFactoryImpl() = default;

@@ -46,17 +48,17 @@ std::unique_ptr<AndroidSurface> AndroidSurfaceFactoryImpl::CreateSurface() {
case AndroidRenderingAPI::kSoftware:
return std::make_unique<AndroidSurfaceSoftware>(android_context_,
jni_facade_);
case AndroidRenderingAPI::kOpenGLES:
case AndroidRenderingAPI::kGPU:
if (enable_impeller_) {
// TODO(kaushikiska@): Enable this after wiring a preference for Vulkan backend.
#if false
return std::make_unique<AndroidSurfaceVulkanImpeller>(
android_context_, jni_facade_, enable_vulkan_validation_);

#else
if (!impeller_force_gl_) {
auto vk_surface = std::make_unique<AndroidSurfaceVulkanImpeller>(
android_context_, jni_facade_, enable_vulkan_validation_);
if (vk_surface->IsValid()) {
return vk_surface;
}
}
return std::make_unique<AndroidSurfaceGLImpeller>(android_context_,
jni_facade_);
#endif
} else {
return std::make_unique<AndroidSurfaceGLSkia>(android_context_,
jni_facade_);
@@ -76,10 +78,10 @@ static std::shared_ptr<flutter::AndroidContext> CreateAndroidContext(
return std::make_shared<AndroidContext>(AndroidRenderingAPI::kSoftware);
}
if (enable_impeller) {
return std::make_unique<AndroidContextGLImpeller>();
return std::make_unique<AndroidContextImpeller>();
}
return std::make_unique<AndroidContextGLSkia>(
AndroidRenderingAPI::kOpenGLES, //
AndroidRenderingAPI::kGPU, //
fml::MakeRefCounted<AndroidEnvironmentGL>(), //
task_runners, //
msaa_samples //
@@ -116,10 +118,11 @@ PlatformViewAndroid::PlatformViewAndroid(
FML_CHECK(android_context_->IsValid())
<< "Could not create surface from invalid Android context.";
surface_factory_ = std::make_shared<AndroidSurfaceFactoryImpl>(
android_context_, //
jni_facade_, //
delegate.OnPlatformViewGetSettings().enable_impeller, //
delegate.OnPlatformViewGetSettings().enable_vulkan_validation //
android_context_, //
jni_facade_, //
delegate.OnPlatformViewGetSettings().enable_impeller, //
delegate.OnPlatformViewGetSettings().enable_vulkan_validation, //
delegate.OnPlatformViewGetSettings().impeller_force_gl //
);
android_surface_ = surface_factory_->CreateSurface();
FML_CHECK(android_surface_ && android_surface_->IsValid())
@@ -271,7 +274,7 @@ void PlatformViewAndroid::UpdateSemantics(
void PlatformViewAndroid::RegisterExternalTexture(
int64_t texture_id,
const fml::jni::ScopedJavaGlobalRef<jobject>& surface_texture) {
if (android_context_->RenderingApi() == AndroidRenderingAPI::kOpenGLES) {
if (android_context_->RenderingApi() == AndroidRenderingAPI::kGPU) {
RegisterTexture(std::make_shared<AndroidExternalTextureGL>(
texture_id, surface_texture, jni_facade_));
} else {
4 changes: 3 additions & 1 deletion shell/platform/android/platform_view_android.h
Original file line number Diff line number Diff line change
@@ -29,7 +29,8 @@ class AndroidSurfaceFactoryImpl : public AndroidSurfaceFactory {
AndroidSurfaceFactoryImpl(const std::shared_ptr<AndroidContext>& context,
std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
bool enable_impeller,
bool enable_vulkan_validation);
bool enable_vulkan_validation,
bool impeller_force_gl);

~AndroidSurfaceFactoryImpl() override;

@@ -40,6 +41,7 @@ class AndroidSurfaceFactoryImpl : public AndroidSurfaceFactory {
std::shared_ptr<PlatformViewAndroidJNI> jni_facade_;
const bool enable_impeller_;
const bool enable_vulkan_validation_;
const bool impeller_force_gl_;
};

class PlatformViewAndroid final : public PlatformView {
Original file line number Diff line number Diff line change
@@ -193,6 +193,24 @@ public void itDoesNotSetEnableVulkanValidationByDefault() {
assertFalse(arguments.contains(enableVulkanValidationArg));
}

@Test
public void itDoesNotSetEnableGLByDefault() {
FlutterJNI mockFlutterJNI = mock(FlutterJNI.class);
FlutterLoader flutterLoader = new FlutterLoader(mockFlutterJNI);

assertFalse(flutterLoader.initialized());
flutterLoader.startInitialization(ctx);
flutterLoader.ensureInitializationComplete(ctx, null);
shadowOf(getMainLooper()).idle();

final String enableGLArg = "--impeller-force-gl";
ArgumentCaptor<String[]> shellArgsCaptor = ArgumentCaptor.forClass(String[].class);
verify(mockFlutterJNI, times(1))
.init(eq(ctx), shellArgsCaptor.capture(), anyString(), anyString(), anyString(), anyLong());
List<String> arguments = Arrays.asList(shellArgsCaptor.getValue());
assertFalse(arguments.contains(enableGLArg));
}

@Test
public void itSetsEnableImpellerFromMetaData() {
FlutterJNI mockFlutterJNI = mock(FlutterJNI.class);

0 comments on commit a6421ed

Please sign in to comment.