[impeller] add Android flag for disabling surface control for debugging. (flutter/engine#55185)

I've found a few instances where Vulkan worked correctly but surface control did not. lets add a debugging flag we can ask folks to try to narrow down the issue.
This commit is contained in:
Jonah Williams
2024-09-13 14:39:20 -07:00
committed by GitHub
parent ebd65bf755
commit 9235fbb695
13 changed files with 89 additions and 26 deletions

View File

@@ -229,6 +229,9 @@ struct Settings {
bool enable_impeller = false;
#endif
// Force disable the android surface control even where supported.
bool disable_surface_control = false;
// If true, the UI thread is the platform thread on supported
// platforms.
bool merged_platform_ui_thread = true;

View File

@@ -445,6 +445,7 @@ void ContextVK::Setup(Settings settings) {
descriptor_pool_recycler_ = std::move(descriptor_pool_recycler);
device_name_ = std::string(physical_device_properties.deviceName);
command_queue_vk_ = std::make_shared<CommandQueueVK>(weak_from_this());
should_disable_surface_control_ = settings.disable_surface_control;
is_valid_ = true;
// Create the GPU Tracer later because it depends on state from
@@ -616,4 +617,8 @@ const std::unique_ptr<DriverInfoVK>& ContextVK::GetDriverInfo() const {
return driver_info_;
}
bool ContextVK::GetShouldDisableSurfaceControlSwapchain() const {
return should_disable_surface_control_;
}
} // namespace impeller

View File

@@ -49,6 +49,7 @@ class ContextVK final : public Context,
fml::UniqueFD cache_directory;
bool enable_validation = false;
bool enable_gpu_tracing = false;
bool disable_surface_control = false;
/// If validations are requested but cannot be enabled, log a fatal error.
bool fatal_missing_validations = false;
@@ -168,6 +169,10 @@ class ContextVK final : public Context,
void InitializeCommonlyUsedShadersIfNeeded() const override;
/// @brief Whether the Android Surface control based swapchain should be
/// disabled, even if the device is capable of supporting it.
bool GetShouldDisableSurfaceControlSwapchain() const;
private:
struct DeviceHolderImpl : public DeviceHolderVK {
// |DeviceHolder|
@@ -200,6 +205,7 @@ class ContextVK final : public Context,
std::shared_ptr<GPUTracerVK> gpu_tracer_;
std::shared_ptr<DescriptorPoolRecyclerVK> descriptor_pool_recycler_;
std::shared_ptr<CommandQueue> command_queue_vk_;
bool should_disable_surface_control_ = false;
const uint64_t hash_;

View File

@@ -57,11 +57,14 @@ std::shared_ptr<SwapchainVK> SwapchainVK::Create(
}
// TODO(147533): AHB swapchains on emulators are not functional.
const auto emulator = ContextVK::Cast(*context).GetDriverInfo()->IsEmulator();
auto& context_vk = ContextVK::Cast(*context);
const auto emulator = context_vk.GetDriverInfo()->IsEmulator();
const auto should_disable_sc =
context_vk.GetShouldDisableSurfaceControlSwapchain();
// Try AHB swapchains first.
if (!emulator && AHBSwapchainVK::IsAvailableOnPlatform() &&
!android::ShadowRealm::ShouldDisableAHB()) {
!android::ShadowRealm::ShouldDisableAHB() && !should_disable_sc) {
auto ahb_swapchain = std::shared_ptr<AHBSwapchainVK>(new AHBSwapchainVK(
context, //
window.GetHandle(), //

View File

@@ -524,6 +524,9 @@ Settings SettingsFromCommandLine(const fml::CommandLine& command_line) {
settings.enable_platform_isolates =
command_line.HasOption(FlagForSwitch(Switch::EnablePlatformIsolates));
settings.disable_surface_control = command_line.HasOption(
FlagForSwitch(Switch::DisableAndroidSurfaceControl));
return settings;
}

View File

@@ -297,6 +297,9 @@ DEF_SWITCH(EnablePlatformIsolates,
DEF_SWITCH(EnableMergedPlatformUIThread,
"enable-merged-platform-ui-thread",
"Merge the ui thread and platform thread.")
DEF_SWITCH(DisableAndroidSurfaceControl,
"disable-surface-control",
"Disable the SurfaceControl backed swapchain even when supported.")
DEF_SWITCHES_END
void PrintUsage(const std::string& executable_name);

View File

@@ -10,14 +10,13 @@
#include "flutter/impeller/entity/vk/framebuffer_blend_shaders_vk.h"
#include "flutter/impeller/entity/vk/modern_shaders_vk.h"
#include "flutter/impeller/renderer/backend/vulkan/context_vk.h"
#include "shell/platform/android/context/android_context.h"
namespace flutter {
static std::shared_ptr<impeller::Context> CreateImpellerContext(
const fml::RefPtr<fml::NativeLibrary>& vulkan_dylib,
bool enable_vulkan_validation,
bool enable_gpu_tracing,
bool quiet) {
const AndroidContext::ContextSettings& p_settings) {
if (!vulkan_dylib) {
VALIDATION_LOG << "Could not open the Vulkan dylib.";
return nullptr;
@@ -46,12 +45,13 @@ static std::shared_ptr<impeller::Context> CreateImpellerContext(
settings.proc_address_callback = instance_proc_addr.value();
settings.shader_libraries_data = std::move(shader_mappings);
settings.cache_directory = fml::paths::GetCachesDirectory();
settings.enable_validation = enable_vulkan_validation;
settings.enable_gpu_tracing = enable_gpu_tracing;
settings.enable_validation = p_settings.enable_validation;
settings.enable_gpu_tracing = p_settings.enable_gpu_tracing;
settings.disable_surface_control = p_settings.disable_surface_control;
auto context = impeller::ContextVK::Create(std::move(settings));
if (!quiet) {
if (!p_settings.quiet) {
if (context && impeller::CapabilitiesVK::Cast(*context->GetCapabilities())
.AreValidationsEnabled()) {
FML_LOG(IMPORTANT) << "Using the Impeller rendering backend (Vulkan with "
@@ -69,13 +69,11 @@ static std::shared_ptr<impeller::Context> CreateImpellerContext(
return context;
}
AndroidContextVKImpeller::AndroidContextVKImpeller(bool enable_validation,
bool enable_gpu_tracing,
bool quiet)
AndroidContextVKImpeller::AndroidContextVKImpeller(
const AndroidContext::ContextSettings& settings)
: AndroidContext(AndroidRenderingAPI::kImpellerVulkan),
vulkan_dylib_(fml::NativeLibrary::Create("libvulkan.so")) {
auto impeller_context = CreateImpellerContext(
vulkan_dylib_, enable_validation, enable_gpu_tracing, quiet);
auto impeller_context = CreateImpellerContext(vulkan_dylib_, settings);
SetImpellerContext(impeller_context);
is_valid_ = !!impeller_context;
}

View File

@@ -14,9 +14,8 @@ namespace flutter {
class AndroidContextVKImpeller : public AndroidContext {
public:
AndroidContextVKImpeller(bool enable_validation,
bool enable_gpu_tracing,
bool quiet = false);
explicit AndroidContextVKImpeller(
const AndroidContext::ContextSettings& settings);
~AndroidContextVKImpeller();

View File

@@ -22,6 +22,13 @@ class AndroidContext {
virtual ~AndroidContext();
struct ContextSettings {
bool enable_validation = false;
bool enable_gpu_tracing = false;
bool disable_surface_control = false;
bool quiet = false;
};
AndroidRenderingAPI RenderingApi() const;
virtual bool IsValid() const;

View File

@@ -23,6 +23,7 @@
#include "flutter/shell/common/shell.h"
#include "flutter/shell/common/switches.h"
#include "flutter/shell/platform/android/android_context_vk_impeller.h"
#include "flutter/shell/platform/android/context/android_context.h"
#include "flutter/shell/platform/android/flutter_main.h"
#include "impeller/base/validation.h"
#include "impeller/toolkit/android/proc_table.h"
@@ -269,9 +270,9 @@ AndroidRenderingAPI FlutterMain::SelectedRenderingAPI(
// checking if it is valid.
impeller::ScopedValidationDisable disable_validation;
auto vulkan_backend = std::make_unique<AndroidContextVKImpeller>(
/*enable_vulkan_validation=*/false,
/*enable_vulkan_gpu_tracing=*/false,
/*quiet=*/true);
AndroidContext::ContextSettings{.enable_validation = false,
.enable_gpu_tracing = false,
.quiet = true});
if (!vulkan_backend->IsValid()) {
return kVulkanUnsupportedFallback;
}

View File

@@ -49,6 +49,8 @@ public class FlutterLoader {
"io.flutter.embedding.android.EnableVulkanGPUTracing";
private static final String ENABLED_MERGED_PLATFORM_UI_THREAD_KEY =
"io.flutter.embedding.android.EnableMergedPlatformUIThread";
private static final String DISABLE_SURFACE_CONTROL =
"io.flutter.embedding.android.DisableSurfaceControl";
/**
* Set whether leave or clean up the VM after the last shell shuts down. It can be set from app's
@@ -361,6 +363,9 @@ public class FlutterLoader {
if (metaData.getBoolean(IMPELLER_VULKAN_GPU_TRACING_DATA_KEY, false)) {
shellArgs.add("--enable-vulkan-gpu-tracing");
}
if (metaData.getBoolean(DISABLE_SURFACE_CONTROL, false)) {
shellArgs.add("--disable-surface-control");
}
if (metaData.containsKey(ENABLED_MERGED_PLATFORM_UI_THREAD_KEY)) {
if (metaData.getBoolean(ENABLED_MERGED_PLATFORM_UI_THREAD_KEY)) {
shellArgs.add("--enable-merged-platform-ui-thread");
@@ -368,6 +373,7 @@ public class FlutterLoader {
shellArgs.add("--no-enable-merged-platform-ui-thread");
}
}
String backend = metaData.getString(IMPELLER_BACKEND_META_DATA_KEY);
if (backend != null) {
shellArgs.add("--impeller-backend=" + backend);

View File

@@ -38,6 +38,17 @@
namespace flutter {
namespace {
AndroidContext::ContextSettings CreateContextSettings(
const Settings& p_settings) {
AndroidContext::ContextSettings settings;
settings.enable_gpu_tracing = p_settings.enable_vulkan_gpu_tracing;
settings.enable_validation = p_settings.enable_vulkan_validation;
settings.disable_surface_control = p_settings.disable_surface_control;
return settings;
}
} // namespace
AndroidSurfaceFactoryImpl::AndroidSurfaceFactoryImpl(
const std::shared_ptr<AndroidContext>& context,
bool enable_impeller)
@@ -66,9 +77,8 @@ static std::shared_ptr<flutter::AndroidContext> CreateAndroidContext(
bool use_software_rendering,
const flutter::TaskRunners& task_runners,
AndroidRenderingAPI android_rendering_api,
bool enable_vulkan_validation,
bool enable_opengl_gpu_tracing,
bool enable_vulkan_gpu_tracing) {
const AndroidContext::ContextSettings& settings) {
switch (android_rendering_api) {
case AndroidRenderingAPI::kSoftware:
return std::make_shared<AndroidContext>(AndroidRenderingAPI::kSoftware);
@@ -77,8 +87,7 @@ static std::shared_ptr<flutter::AndroidContext> CreateAndroidContext(
std::make_unique<impeller::egl::Display>(),
enable_opengl_gpu_tracing);
case AndroidRenderingAPI::kImpellerVulkan:
return std::make_unique<AndroidContextVKImpeller>(
enable_vulkan_validation, enable_vulkan_gpu_tracing);
return std::make_unique<AndroidContextVKImpeller>(settings);
case AndroidRenderingAPI::kSkiaOpenGLES:
return std::make_unique<AndroidContextGLSkia>(
fml::MakeRefCounted<AndroidEnvironmentGL>(), //
@@ -101,10 +110,8 @@ PlatformViewAndroid::PlatformViewAndroid(
use_software_rendering,
task_runners,
delegate.OnPlatformViewGetSettings().android_rendering_api,
delegate.OnPlatformViewGetSettings().enable_vulkan_validation,
delegate.OnPlatformViewGetSettings().enable_opengl_gpu_tracing,
delegate.OnPlatformViewGetSettings().enable_vulkan_gpu_tracing)) {
}
CreateContextSettings(delegate.OnPlatformViewGetSettings()))) {}
PlatformViewAndroid::PlatformViewAndroid(
PlatformView::Delegate& delegate,

View File

@@ -236,6 +236,28 @@ public class FlutterLoaderTest {
assertTrue(arguments.contains(enableImpellerArg));
}
@Test
public void itSetsDisableSurfaceControlFromMetaData() {
FlutterJNI mockFlutterJNI = mock(FlutterJNI.class);
FlutterLoader flutterLoader = new FlutterLoader(mockFlutterJNI);
Bundle metaData = new Bundle();
metaData.putBoolean("io.flutter.embedding.android.DisableSurfaceControl", true);
ctx.getApplicationInfo().metaData = metaData;
FlutterLoader.Settings settings = new FlutterLoader.Settings();
assertFalse(flutterLoader.initialized());
flutterLoader.startInitialization(ctx, settings);
flutterLoader.ensureInitializationComplete(ctx, null);
shadowOf(getMainLooper()).idle();
final String disabledControlArg = "--disable-surface-control";
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());
assertTrue(arguments.contains(disabledControlArg));
}
@Test
@TargetApi(API_LEVELS.API_23)
@Config(sdk = API_LEVELS.API_23)