mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[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:
parent
5468c8b8bb
commit
8116ea14c7
@ -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;
|
||||
|
||||
|
||||
@ -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));
|
||||
|
||||
|
||||
@ -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 "
|
||||
|
||||
@ -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_;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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.";
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user