[Impeller] make GPU tracing off by default. (flutter/engine#50215)
Fixes https://github.com/flutter/flutter/issues/141788 Fixes https://github.com/flutter/flutter/issues/141798 Disable GPU tracing by default.
This commit is contained in:
@@ -232,6 +232,9 @@ struct Settings {
|
||||
// Some devices claim to support the required APIs but crash on their usage.
|
||||
bool enable_opengl_gpu_tracing = false;
|
||||
|
||||
// Enable GPU tracing in Vulkan backends.
|
||||
bool enable_vulkan_gpu_tracing = false;
|
||||
|
||||
// Data set by platform-specific embedders for use in font initialization.
|
||||
uint32_t font_initialization_data = 0;
|
||||
|
||||
|
||||
@@ -452,7 +452,8 @@ void ContextVK::Setup(Settings settings) {
|
||||
|
||||
// Create the GPU Tracer later because it depends on state from
|
||||
// the ContextVK.
|
||||
gpu_tracer_ = std::make_shared<GPUTracerVK>(weak_from_this());
|
||||
gpu_tracer_ = std::make_shared<GPUTracerVK>(weak_from_this(),
|
||||
settings.enable_gpu_tracing);
|
||||
gpu_tracer_->InitializeQueryPool(*this);
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
@@ -47,6 +47,7 @@ class ContextVK final : public Context,
|
||||
std::vector<std::shared_ptr<fml::Mapping>> shader_libraries_data;
|
||||
fml::UniqueFD cache_directory;
|
||||
bool enable_validation = false;
|
||||
bool enable_gpu_tracing = false;
|
||||
|
||||
Settings() = default;
|
||||
|
||||
|
||||
@@ -22,8 +22,12 @@ namespace impeller {
|
||||
|
||||
static constexpr uint32_t kPoolSize = 128u;
|
||||
|
||||
GPUTracerVK::GPUTracerVK(std::weak_ptr<ContextVK> context)
|
||||
GPUTracerVK::GPUTracerVK(std::weak_ptr<ContextVK> context,
|
||||
bool enable_gpu_tracing)
|
||||
: context_(std::move(context)) {
|
||||
if (!enable_gpu_tracing) {
|
||||
return;
|
||||
}
|
||||
timestamp_period_ = context_.lock()
|
||||
->GetDeviceHolder()
|
||||
->GetPhysicalDevice()
|
||||
|
||||
@@ -18,9 +18,14 @@ class GPUProbe;
|
||||
|
||||
/// @brief A class that uses timestamp queries to record the approximate GPU
|
||||
/// execution time.
|
||||
///
|
||||
/// To enable, add the following metadata to the application's Android manifest:
|
||||
/// <meta-data
|
||||
/// android:name="io.flutter.embedding.android.EnableVulkanGPUTracing"
|
||||
/// android:value="false" />
|
||||
class GPUTracerVK : public std::enable_shared_from_this<GPUTracerVK> {
|
||||
public:
|
||||
explicit GPUTracerVK(std::weak_ptr<ContextVK> context);
|
||||
GPUTracerVK(std::weak_ptr<ContextVK> context, bool enable_gpu_tracing);
|
||||
|
||||
~GPUTracerVK() = default;
|
||||
|
||||
|
||||
@@ -443,6 +443,7 @@ bool SwapchainImplVK::Present(const std::shared_ptr<SwapchainImageVK>& image,
|
||||
|
||||
const auto& context = ContextVK::Cast(*context_strong);
|
||||
const auto& sync = synchronizers_[current_frame_];
|
||||
context.GetGPUTracer()->MarkFrameEnd();
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/// Transition the image to color-attachment-optimal.
|
||||
@@ -493,8 +494,6 @@ bool SwapchainImplVK::Present(const std::shared_ptr<SwapchainImageVK>& image,
|
||||
}
|
||||
}
|
||||
|
||||
context.GetGPUTracer()->MarkFrameEnd();
|
||||
|
||||
auto task = [&, index, current_frame = current_frame_] {
|
||||
auto context_strong = context_.lock();
|
||||
if (!context_strong) {
|
||||
|
||||
@@ -15,8 +15,25 @@ namespace impeller {
|
||||
namespace testing {
|
||||
|
||||
#ifdef IMPELLER_DEBUG
|
||||
TEST(GPUTracerVK, CanBeDisabled) {
|
||||
auto const context =
|
||||
MockVulkanContextBuilder()
|
||||
.SetSettingsCallback([](ContextVK::Settings& settings) {
|
||||
settings.enable_gpu_tracing = false;
|
||||
})
|
||||
.Build();
|
||||
auto tracer = context->GetGPUTracer();
|
||||
|
||||
ASSERT_FALSE(tracer->IsEnabled());
|
||||
}
|
||||
|
||||
TEST(GPUTracerVK, CanTraceCmdBuffer) {
|
||||
auto const context = MockVulkanContextBuilder().Build();
|
||||
auto const context =
|
||||
MockVulkanContextBuilder()
|
||||
.SetSettingsCallback([](ContextVK::Settings& settings) {
|
||||
settings.enable_gpu_tracing = true;
|
||||
})
|
||||
.Build();
|
||||
auto tracer = context->GetGPUTracer();
|
||||
|
||||
ASSERT_TRUE(tracer->IsEnabled());
|
||||
@@ -48,7 +65,12 @@ TEST(GPUTracerVK, CanTraceCmdBuffer) {
|
||||
}
|
||||
|
||||
TEST(GPUTracerVK, DoesNotTraceOutsideOfFrameWorkload) {
|
||||
auto const context = MockVulkanContextBuilder().Build();
|
||||
auto const context =
|
||||
MockVulkanContextBuilder()
|
||||
.SetSettingsCallback([](ContextVK::Settings& settings) {
|
||||
settings.enable_gpu_tracing = true;
|
||||
})
|
||||
.Build();
|
||||
auto tracer = context->GetGPUTracer();
|
||||
|
||||
ASSERT_TRUE(tracer->IsEnabled());
|
||||
@@ -78,7 +100,12 @@ TEST(GPUTracerVK, DoesNotTraceOutsideOfFrameWorkload) {
|
||||
// This cmd buffer starts when there is a frame but finishes when there is none.
|
||||
// This should result in the same recorded work.
|
||||
TEST(GPUTracerVK, TracesWithPartialFrameOverlap) {
|
||||
auto const context = MockVulkanContextBuilder().Build();
|
||||
auto const context =
|
||||
MockVulkanContextBuilder()
|
||||
.SetSettingsCallback([](ContextVK::Settings& settings) {
|
||||
settings.enable_gpu_tracing = true;
|
||||
})
|
||||
.Build();
|
||||
auto tracer = context->GetGPUTracer();
|
||||
|
||||
ASSERT_TRUE(tracer->IsEnabled());
|
||||
|
||||
@@ -468,6 +468,8 @@ Settings SettingsFromCommandLine(const fml::CommandLine& command_line) {
|
||||
command_line.HasOption(FlagForSwitch(Switch::EnableVulkanValidation));
|
||||
settings.enable_opengl_gpu_tracing =
|
||||
command_line.HasOption(FlagForSwitch(Switch::EnableOpenGLGPUTracing));
|
||||
settings.enable_vulkan_gpu_tracing =
|
||||
command_line.HasOption(FlagForSwitch(Switch::EnableVulkanGPUTracing));
|
||||
|
||||
settings.enable_embedder_api =
|
||||
command_line.HasOption(FlagForSwitch(Switch::EnableEmbedderAPI));
|
||||
|
||||
@@ -279,6 +279,10 @@ DEF_SWITCH(EnableOpenGLGPUTracing,
|
||||
"enable-opengl-gpu-tracing",
|
||||
"Enable tracing of GPU execution time when using the Impeller "
|
||||
"OpenGLES backend.")
|
||||
DEF_SWITCH(EnableVulkanGPUTracing,
|
||||
"enable-vulkan-gpu-tracing",
|
||||
"Enable tracing of GPU execution time when using the Impeller "
|
||||
"Vulkan backend.")
|
||||
DEF_SWITCH(LeakVM,
|
||||
"leak-vm",
|
||||
"When the last shell shuts down, the shared VM is leaked by default "
|
||||
|
||||
@@ -18,7 +18,8 @@ namespace flutter {
|
||||
|
||||
static std::shared_ptr<impeller::Context> CreateImpellerContext(
|
||||
const fml::RefPtr<vulkan::VulkanProcTable>& proc_table,
|
||||
bool enable_vulkan_validation) {
|
||||
bool enable_vulkan_validation,
|
||||
bool enable_gpu_tracing) {
|
||||
std::vector<std::shared_ptr<fml::Mapping>> shader_mappings = {
|
||||
std::make_shared<fml::NonOwnedMapping>(impeller_entity_shaders_vk_data,
|
||||
impeller_entity_shaders_vk_length),
|
||||
@@ -41,6 +42,7 @@ static std::shared_ptr<impeller::Context> CreateImpellerContext(
|
||||
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;
|
||||
|
||||
auto context = impeller::ContextVK::Create(std::move(settings));
|
||||
|
||||
@@ -56,10 +58,12 @@ static std::shared_ptr<impeller::Context> CreateImpellerContext(
|
||||
}
|
||||
|
||||
AndroidContextVulkanImpeller::AndroidContextVulkanImpeller(
|
||||
bool enable_validation)
|
||||
bool enable_validation,
|
||||
bool enable_gpu_tracing)
|
||||
: AndroidContext(AndroidRenderingAPI::kVulkan),
|
||||
proc_table_(fml::MakeRefCounted<vulkan::VulkanProcTable>()) {
|
||||
auto impeller_context = CreateImpellerContext(proc_table_, enable_validation);
|
||||
auto impeller_context =
|
||||
CreateImpellerContext(proc_table_, enable_validation, enable_gpu_tracing);
|
||||
SetImpellerContext(impeller_context);
|
||||
is_valid_ =
|
||||
proc_table_->HasAcquiredMandatoryProcAddresses() && impeller_context;
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace flutter {
|
||||
|
||||
class AndroidContextVulkanImpeller : public AndroidContext {
|
||||
public:
|
||||
explicit AndroidContextVulkanImpeller(bool enable_validation);
|
||||
AndroidContextVulkanImpeller(bool enable_validation, bool enable_gpu_tracing);
|
||||
|
||||
~AndroidContextVulkanImpeller();
|
||||
|
||||
|
||||
@@ -47,6 +47,8 @@ public class FlutterLoader {
|
||||
"io.flutter.embedding.android.ImpellerBackend";
|
||||
private static final String IMPELLER_OPENGL_GPU_TRACING_DATA_KEY =
|
||||
"io.flutter.embedding.android.EnableOpenGLGPUTracing";
|
||||
private static final String IMPELLER_VULKAN_GPU_TRACING_DATA_KEY =
|
||||
"io.flutter.embedding.android.EnableVulkanGPUTracing";
|
||||
|
||||
/**
|
||||
* Set whether leave or clean up the VM after the last shell shuts down. It can be set from app's
|
||||
@@ -333,6 +335,9 @@ public class FlutterLoader {
|
||||
if (metaData.getBoolean(IMPELLER_OPENGL_GPU_TRACING_DATA_KEY, false)) {
|
||||
shellArgs.add("--enable-opengl-gpu-tracing");
|
||||
}
|
||||
if (metaData.getBoolean(IMPELLER_VULKAN_GPU_TRACING_DATA_KEY, false)) {
|
||||
shellArgs.add("--enable-vulkan-gpu-tracing");
|
||||
}
|
||||
String backend = metaData.getString(IMPELLER_BACKEND_META_DATA_KEY);
|
||||
if (backend != null) {
|
||||
shellArgs.add("--impeller-backend=" + backend);
|
||||
|
||||
@@ -74,7 +74,8 @@ static std::shared_ptr<flutter::AndroidContext> CreateAndroidContext(
|
||||
bool enable_impeller,
|
||||
const std::optional<std::string>& impeller_backend,
|
||||
bool enable_vulkan_validation,
|
||||
bool enable_opengl_gpu_tracing) {
|
||||
bool enable_opengl_gpu_tracing,
|
||||
bool enable_vulkan_gpu_tracing) {
|
||||
if (use_software_rendering) {
|
||||
FML_DCHECK(!enable_impeller);
|
||||
return std::make_shared<AndroidContext>(AndroidRenderingAPI::kSoftware);
|
||||
@@ -119,10 +120,10 @@ static std::shared_ptr<flutter::AndroidContext> CreateAndroidContext(
|
||||
enable_opengl_gpu_tracing);
|
||||
case AndroidRenderingAPI::kVulkan:
|
||||
return std::make_unique<AndroidContextVulkanImpeller>(
|
||||
enable_vulkan_validation);
|
||||
enable_vulkan_validation, enable_vulkan_gpu_tracing);
|
||||
case AndroidRenderingAPI::kAutoselect: {
|
||||
auto vulkan_backend = std::make_unique<AndroidContextVulkanImpeller>(
|
||||
enable_vulkan_validation);
|
||||
enable_vulkan_validation, enable_vulkan_gpu_tracing);
|
||||
if (!vulkan_backend->IsValid()) {
|
||||
return std::make_unique<AndroidContextGLImpeller>(
|
||||
std::make_unique<impeller::egl::Display>(),
|
||||
@@ -159,7 +160,8 @@ PlatformViewAndroid::PlatformViewAndroid(
|
||||
delegate.OnPlatformViewGetSettings().enable_impeller,
|
||||
delegate.OnPlatformViewGetSettings().impeller_backend,
|
||||
delegate.OnPlatformViewGetSettings().enable_vulkan_validation,
|
||||
delegate.OnPlatformViewGetSettings().enable_opengl_gpu_tracing)) {
|
||||
delegate.OnPlatformViewGetSettings().enable_opengl_gpu_tracing,
|
||||
delegate.OnPlatformViewGetSettings().enable_vulkan_gpu_tracing)) {
|
||||
}
|
||||
|
||||
PlatformViewAndroid::PlatformViewAndroid(
|
||||
|
||||
Reference in New Issue
Block a user