[Impeller] Enable vulkan validations via a flag on Android. (flutter/engine#40792)

[Impeller] Enable vulkan validations via a flag on Android.
This commit is contained in:
Chinmay Garde 2023-03-30 13:07:51 -07:00 committed by GitHub
parent 5468c8b8bb
commit 8116ea14c7
9 changed files with 59 additions and 14 deletions

View File

@ -217,6 +217,10 @@ struct Settings {
bool enable_impeller = false;
#endif
// Enable Vulkan validation on backends that support it. The validation layers
// must be available to the application.
bool enable_vulkan_validation = false;
// Data set by platform-specific embedders for use in font initialization.
uint32_t font_initialization_data = 0;

View File

@ -450,6 +450,9 @@ Settings SettingsFromCommandLine(const fml::CommandLine& command_line) {
enable_impeller_value.empty() || "true" == enable_impeller_value;
}
settings.enable_vulkan_validation =
command_line.HasOption(FlagForSwitch(Switch::EnableVulkanValidation));
settings.enable_embedder_api =
command_line.HasOption(FlagForSwitch(Switch::EnableEmbedderAPI));

View File

@ -261,6 +261,11 @@ DEF_SWITCH(EnableImpeller,
"enable-impeller",
"Enable the Impeller renderer on supported platforms. Ignored if "
"Impeller is not supported on the platform.")
DEF_SWITCH(EnableVulkanValidation,
"enable-vulkan-validation",
"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(LeakVM,
"leak-vm",
"When the last shell shuts down, the shared VM is leaked by default "

View File

@ -20,9 +20,10 @@
namespace flutter {
std::shared_ptr<impeller::Context> CreateImpellerContext(
static std::shared_ptr<impeller::Context> CreateImpellerContext(
const fml::RefPtr<vulkan::VulkanProcTable>& proc_table,
const std::shared_ptr<fml::ConcurrentMessageLoop>& concurrent_loop) {
const std::shared_ptr<fml::ConcurrentMessageLoop>& concurrent_loop,
bool enable_vulkan_validation) {
std::vector<std::shared_ptr<fml::Mapping>> shader_mappings = {
std::make_shared<fml::NonOwnedMapping>(impeller_entity_shaders_vk_data,
impeller_entity_shaders_vk_length),
@ -40,17 +41,19 @@ std::shared_ptr<impeller::Context> CreateImpellerContext(
settings.shader_libraries_data = std::move(shader_mappings);
settings.cache_directory = fml::paths::GetCachesDirectory();
settings.worker_task_runner = concurrent_loop->GetTaskRunner();
settings.enable_validation = enable_vulkan_validation;
return impeller::ContextVK::Create(std::move(settings));
}
AndroidSurfaceVulkanImpeller::AndroidSurfaceVulkanImpeller(
const std::shared_ptr<AndroidContext>& android_context,
const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade)
const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade,
bool enable_vulkan_validation)
: AndroidSurface(android_context),
proc_table_(fml::MakeRefCounted<vulkan::VulkanProcTable>()),
workers_(fml::ConcurrentMessageLoop::Create()) {
impeller_context_ = CreateImpellerContext(proc_table_, workers_);
impeller_context_ =
CreateImpellerContext(proc_table_, workers_, enable_vulkan_validation);
is_valid_ =
proc_table_->HasAcquiredMandatoryProcAddresses() && impeller_context_;
}

View File

@ -17,7 +17,8 @@ class AndroidSurfaceVulkanImpeller : public AndroidSurface {
public:
AndroidSurfaceVulkanImpeller(
const std::shared_ptr<AndroidContext>& android_context,
const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade);
const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade,
bool enable_vulkan_validation);
~AndroidSurfaceVulkanImpeller() override;

View File

@ -44,6 +44,8 @@ public class FlutterShellArgs {
public static final String ARG_TRACE_SYSTRACE = "--trace-systrace";
public static final String ARG_KEY_ENABLE_IMPELLER = "enable-impeller";
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_DUMP_SHADER_SKP_ON_SHADER_COMPILATION =
"dump-skp-on-shader-compilation";
public static final String ARG_DUMP_SHADER_SKP_ON_SHADER_COMPILATION =
@ -121,6 +123,9 @@ public class FlutterShellArgs {
if (intent.getBooleanExtra(ARG_KEY_ENABLE_IMPELLER, false)) {
args.add(ARG_ENABLE_IMPELLER);
}
if (intent.getBooleanExtra(ARG_KEY_ENABLE_VULKAN_VALIDATION, false)) {
args.add(ARG_ENABLE_VULKAN_VALIDATION);
}
if (intent.getBooleanExtra(ARG_KEY_DUMP_SHADER_SKP_ON_SHADER_COMPILATION, false)) {
args.add(ARG_DUMP_SHADER_SKP_ON_SHADER_COMPILATION);
}

View File

@ -32,10 +32,12 @@ namespace flutter {
AndroidSurfaceFactoryImpl::AndroidSurfaceFactoryImpl(
const std::shared_ptr<AndroidContext>& context,
std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
bool enable_impeller)
bool enable_impeller,
bool enable_vulkan_validation)
: android_context_(context),
jni_facade_(std::move(jni_facade)),
enable_impeller_(enable_impeller) {}
enable_impeller_(enable_impeller),
enable_vulkan_validation_(enable_vulkan_validation) {}
AndroidSurfaceFactoryImpl::~AndroidSurfaceFactoryImpl() = default;
@ -48,8 +50,8 @@ std::unique_ptr<AndroidSurface> AndroidSurfaceFactoryImpl::CreateSurface() {
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_);
return std::make_unique<AndroidSurfaceVulkanImpeller>(
android_context_, jni_facade_, enable_vulkan_validation_);
#else
return std::make_unique<AndroidSurfaceGLImpeller>(android_context_,
@ -114,10 +116,12 @@ 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);
android_context_, //
jni_facade_, //
delegate.OnPlatformViewGetSettings().enable_impeller, //
delegate.OnPlatformViewGetSettings().enable_vulkan_validation //
);
android_surface_ = surface_factory_->CreateSurface();
FML_CHECK(android_surface_ && android_surface_->IsValid())
<< "Could not create an OpenGL, Vulkan or Software surface to set up "
"rendering.";

View File

@ -28,7 +28,8 @@ class AndroidSurfaceFactoryImpl : public AndroidSurfaceFactory {
public:
AndroidSurfaceFactoryImpl(const std::shared_ptr<AndroidContext>& context,
std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
bool enable_impeller);
bool enable_impeller,
bool enable_vulkan_validation);
~AndroidSurfaceFactoryImpl() override;
@ -38,6 +39,7 @@ class AndroidSurfaceFactoryImpl : public AndroidSurfaceFactory {
const std::shared_ptr<AndroidContext>& android_context_;
std::shared_ptr<PlatformViewAndroidJNI> jni_facade_;
const bool enable_impeller_;
const bool enable_vulkan_validation_;
};
class PlatformViewAndroid final : public PlatformView {

View File

@ -175,6 +175,24 @@ public class FlutterLoaderTest {
assertFalse(arguments.contains(enableImpellerArg));
}
@Test
public void itDoesNotSetEnableVulkanValidationByDefault() {
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 enableVulkanValidationArg = "--enable-vulkan-validation";
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(enableVulkanValidationArg));
}
@Test
public void itSetsEnableImpellerFromMetaData() {
FlutterJNI mockFlutterJNI = mock(FlutterJNI.class);