[Impeller] Give Impeller a dedicated raster priority level worker loop. (#43166)
We'd like to (or already are) using the concurrent message loop for high priority rendering tasks like PSO construction and render pass encoding. The default priority level for the engine managed concurrent message loop is 2, which is a significantly lower priority than the raster thread at -5. This is almost certainly causing priority inversion.
We must move back to dedicated runners so we can adjust thread priorities.
diff --git a/ci/licenses_golden/excluded_files b/ci/licenses_golden/excluded_files
index 3be2859..8c0100e 100644
--- a/ci/licenses_golden/excluded_files
+++ b/ci/licenses_golden/excluded_files
@@ -230,7 +230,6 @@
../../../flutter/shell/platform/android/.gitignore
../../../flutter/shell/platform/android/android_context_gl_impeller_unittests.cc
../../../flutter/shell/platform/android/android_context_gl_unittests.cc
-../../../flutter/shell/platform/android/android_context_vulkan_impeller_unittests.cc
../../../flutter/shell/platform/android/android_shell_holder_unittests.cc
../../../flutter/shell/platform/android/apk_asset_provider_unittests.cc
../../../flutter/shell/platform/android/external_view_embedder/external_view_embedder_unittests.cc
diff --git a/fml/concurrent_message_loop.cc b/fml/concurrent_message_loop.cc
index 911e403..ace1985 100644
--- a/fml/concurrent_message_loop.cc
+++ b/fml/concurrent_message_loop.cc
@@ -29,6 +29,7 @@
ConcurrentMessageLoop::~ConcurrentMessageLoop() {
Terminate();
for (auto& worker : workers_) {
+ FML_DCHECK(worker.joinable());
worker.join();
}
}
diff --git a/impeller/playground/backend/metal/playground_impl_mtl.mm b/impeller/playground/backend/metal/playground_impl_mtl.mm
index 55e1787..e9ffbf6 100644
--- a/impeller/playground/backend/metal/playground_impl_mtl.mm
+++ b/impeller/playground/backend/metal/playground_impl_mtl.mm
@@ -73,10 +73,9 @@
if (!window) {
return;
}
- auto worker_task_runner = concurrent_loop_->GetTaskRunner();
- auto context = ContextMTL::Create(
- ShaderLibraryMappingsForPlayground(), worker_task_runner,
- is_gpu_disabled_sync_switch_, "Playground Library");
+ auto context =
+ ContextMTL::Create(ShaderLibraryMappingsForPlayground(),
+ is_gpu_disabled_sync_switch_, "Playground Library");
if (!context) {
return;
}
diff --git a/impeller/playground/backend/vulkan/playground_impl_vk.cc b/impeller/playground/backend/vulkan/playground_impl_vk.cc
index f92192c..7783a8c 100644
--- a/impeller/playground/backend/vulkan/playground_impl_vk.cc
+++ b/impeller/playground/backend/vulkan/playground_impl_vk.cc
@@ -52,9 +52,7 @@
}
PlaygroundImplVK::PlaygroundImplVK(PlaygroundSwitches switches)
- : PlaygroundImpl(switches),
- concurrent_loop_(fml::ConcurrentMessageLoop::Create()),
- handle_(nullptr, &DestroyWindowHandle) {
+ : PlaygroundImpl(switches), handle_(nullptr, &DestroyWindowHandle) {
if (!::glfwVulkanSupported()) {
#ifdef TARGET_OS_MAC
VALIDATION_LOG << "Attempted to initialize a Vulkan playground on macOS "
@@ -86,7 +84,6 @@
&::glfwGetInstanceProcAddress);
context_settings.shader_libraries_data = ShaderLibraryMappingsForPlayground();
context_settings.cache_directory = fml::paths::GetCachesDirectory();
- context_settings.worker_task_runner = concurrent_loop_->GetTaskRunner();
context_settings.enable_validation = switches_.enable_vulkan_validation;
auto context = ContextVK::Create(std::move(context_settings));
diff --git a/impeller/playground/backend/vulkan/playground_impl_vk.h b/impeller/playground/backend/vulkan/playground_impl_vk.h
index bb0a784..0dae50b 100644
--- a/impeller/playground/backend/vulkan/playground_impl_vk.h
+++ b/impeller/playground/backend/vulkan/playground_impl_vk.h
@@ -4,7 +4,6 @@
#pragma once
-#include "flutter/fml/concurrent_message_loop.h"
#include "flutter/fml/macros.h"
#include "impeller/playground/playground_impl.h"
#include "impeller/renderer/backend/vulkan/vk.h"
@@ -18,7 +17,6 @@
~PlaygroundImplVK();
private:
- std::shared_ptr<fml::ConcurrentMessageLoop> concurrent_loop_;
std::shared_ptr<Context> context_;
// Windows management.
diff --git a/impeller/playground/playground.cc b/impeller/playground/playground.cc
index ce81afa..447da44 100644
--- a/impeller/playground/playground.cc
+++ b/impeller/playground/playground.cc
@@ -139,6 +139,9 @@
}
void Playground::TeardownWindow() {
+ if (context_) {
+ context_->Shutdown();
+ }
context_.reset();
renderer_.reset();
impl_.reset();
diff --git a/impeller/renderer/backend/gles/context_gles.cc b/impeller/renderer/backend/gles/context_gles.cc
index 47e7256..4f590e2 100644
--- a/impeller/renderer/backend/gles/context_gles.cc
+++ b/impeller/renderer/backend/gles/context_gles.cc
@@ -107,6 +107,8 @@
return is_valid_;
}
+void ContextGLES::Shutdown() {}
+
// |Context|
std::string ContextGLES::DescribeGpuModel() const {
return reactor_->GetProcTable().GetDescription()->GetString();
diff --git a/impeller/renderer/backend/gles/context_gles.h b/impeller/renderer/backend/gles/context_gles.h
index 2faea35..37fca72 100644
--- a/impeller/renderer/backend/gles/context_gles.h
+++ b/impeller/renderer/backend/gles/context_gles.h
@@ -72,6 +72,9 @@
// |Context|
const std::shared_ptr<const Capabilities>& GetCapabilities() const override;
+ // |Context|
+ void Shutdown() override;
+
FML_DISALLOW_COPY_AND_ASSIGN(ContextGLES);
};
diff --git a/impeller/renderer/backend/metal/command_buffer_mtl.mm b/impeller/renderer/backend/metal/command_buffer_mtl.mm
index 58aa6b5..894f8b1 100644
--- a/impeller/renderer/backend/metal/command_buffer_mtl.mm
+++ b/impeller/renderer/backend/metal/command_buffer_mtl.mm
@@ -202,32 +202,39 @@
return false;
}
- auto task = fml::MakeCopyable([render_pass, buffer, render_command_encoder,
- weak_context = context_]() {
- auto context = weak_context.lock();
- if (!context) {
- return;
- }
- auto is_gpu_disabled_sync_switch =
- ContextMTL::Cast(*context).GetIsGpuDisabledSyncSwitch();
- is_gpu_disabled_sync_switch->Execute(fml::SyncSwitch::Handlers().SetIfFalse(
- [&render_pass, &render_command_encoder, &buffer, &context] {
- auto mtl_render_pass = static_cast<RenderPassMTL*>(render_pass.get());
- if (!mtl_render_pass->label_.empty()) {
- [render_command_encoder
- setLabel:@(mtl_render_pass->label_.c_str())];
- }
-
- auto result = mtl_render_pass->EncodeCommands(
- context->GetResourceAllocator(), render_command_encoder);
+ auto task = fml::MakeCopyable(
+ [render_pass, buffer, render_command_encoder, weak_context = context_]() {
+ auto context = weak_context.lock();
+ if (!context) {
[render_command_encoder endEncoding];
- if (result) {
- [buffer commit];
- } else {
- VALIDATION_LOG << "Failed to encode command buffer";
- }
- }));
- });
+ return;
+ }
+ auto is_gpu_disabled_sync_switch =
+ ContextMTL::Cast(*context).GetIsGpuDisabledSyncSwitch();
+ is_gpu_disabled_sync_switch->Execute(
+ fml::SyncSwitch::Handlers()
+ .SetIfFalse([&render_pass, &render_command_encoder, &buffer,
+ &context] {
+ auto mtl_render_pass =
+ static_cast<RenderPassMTL*>(render_pass.get());
+ if (!mtl_render_pass->label_.empty()) {
+ [render_command_encoder
+ setLabel:@(mtl_render_pass->label_.c_str())];
+ }
+
+ auto result = mtl_render_pass->EncodeCommands(
+ context->GetResourceAllocator(), render_command_encoder);
+ [render_command_encoder endEncoding];
+ if (result) {
+ [buffer commit];
+ } else {
+ VALIDATION_LOG << "Failed to encode command buffer";
+ }
+ })
+ .SetIfTrue([&render_command_encoder] {
+ [render_command_encoder endEncoding];
+ }));
+ });
worker_task_runner->PostTask(task);
return true;
}
diff --git a/impeller/renderer/backend/metal/context_mtl.h b/impeller/renderer/backend/metal/context_mtl.h
index 85f9f3a..1a07ad8 100644
--- a/impeller/renderer/backend/metal/context_mtl.h
+++ b/impeller/renderer/backend/metal/context_mtl.h
@@ -35,12 +35,10 @@
public:
static std::shared_ptr<ContextMTL> Create(
const std::vector<std::string>& shader_library_paths,
- std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner,
std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch);
static std::shared_ptr<ContextMTL> Create(
const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries_data,
- std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner,
std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch,
const std::string& label);
@@ -48,7 +46,6 @@
id<MTLDevice> device,
id<MTLCommandQueue> command_queue,
const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries_data,
- std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner,
std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch,
const std::string& label);
@@ -84,9 +81,12 @@
// |Context|
bool UpdateOffscreenLayerPixelFormat(PixelFormat format) override;
+ // |Context|
+ void Shutdown() override;
+
id<MTLCommandBuffer> CreateMTLCommandBuffer(const std::string& label) const;
- const std::shared_ptr<fml::ConcurrentTaskRunner>& GetWorkerTaskRunner() const;
+ const std::shared_ptr<fml::ConcurrentTaskRunner> GetWorkerTaskRunner() const;
std::shared_ptr<const fml::SyncSwitch> GetIsGpuDisabledSyncSwitch() const;
@@ -98,7 +98,7 @@
std::shared_ptr<SamplerLibrary> sampler_library_;
std::shared_ptr<AllocatorMTL> resource_allocator_;
std::shared_ptr<const Capabilities> device_capabilities_;
- std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner_;
+ std::shared_ptr<fml::ConcurrentMessageLoop> raster_message_loop_;
std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch_;
bool is_valid_ = false;
@@ -106,7 +106,6 @@
id<MTLDevice> device,
id<MTLCommandQueue> command_queue,
NSArray<id<MTLLibrary>>* shader_libraries,
- std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner,
std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch);
std::shared_ptr<CommandBuffer> CreateCommandBufferInQueue(
diff --git a/impeller/renderer/backend/metal/context_mtl.mm b/impeller/renderer/backend/metal/context_mtl.mm
index 04dba5c..2237626 100644
--- a/impeller/renderer/backend/metal/context_mtl.mm
+++ b/impeller/renderer/backend/metal/context_mtl.mm
@@ -71,11 +71,9 @@
id<MTLDevice> device,
id<MTLCommandQueue> command_queue,
NSArray<id<MTLLibrary>>* shader_libraries,
- std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner,
std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch)
: device_(device),
command_queue_(command_queue),
- worker_task_runner_(std::move(worker_task_runner)),
is_gpu_disabled_sync_switch_(std::move(is_gpu_disabled_sync_switch)) {
// Validate device.
if (!device_) {
@@ -83,6 +81,24 @@
return;
}
+ // Worker task runner.
+ {
+ raster_message_loop_ = fml::ConcurrentMessageLoop::Create(
+ std::min(4u, std::thread::hardware_concurrency()));
+ raster_message_loop_->PostTaskToAllWorkers([]() {
+ // See https://github.com/flutter/flutter/issues/65752
+ // Intentionally opt out of QoS for raster task workloads.
+ [[NSThread currentThread] setThreadPriority:1.0];
+ sched_param param;
+ int policy;
+ pthread_t thread = pthread_self();
+ if (!pthread_getschedparam(thread, &policy, ¶m)) {
+ param.sched_priority = 50;
+ pthread_setschedparam(thread, policy, ¶m);
+ }
+ });
+ }
+
// Setup the shader library.
{
if (shader_libraries == nil) {
@@ -210,7 +226,6 @@
std::shared_ptr<ContextMTL> ContextMTL::Create(
const std::vector<std::string>& shader_library_paths,
- std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner,
std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch) {
auto device = CreateMetalDevice();
auto command_queue = CreateMetalCommandQueue(device);
@@ -220,7 +235,7 @@
auto context = std::shared_ptr<ContextMTL>(new ContextMTL(
device, command_queue,
MTLShaderLibraryFromFilePaths(device, shader_library_paths),
- std::move(worker_task_runner), std::move(is_gpu_disabled_sync_switch)));
+ std::move(is_gpu_disabled_sync_switch)));
if (!context->IsValid()) {
FML_LOG(ERROR) << "Could not create Metal context.";
return nullptr;
@@ -230,7 +245,6 @@
std::shared_ptr<ContextMTL> ContextMTL::Create(
const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries_data,
- std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner,
std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch,
const std::string& library_label) {
auto device = CreateMetalDevice();
@@ -238,11 +252,11 @@
if (!command_queue) {
return nullptr;
}
- auto context = std::shared_ptr<ContextMTL>(new ContextMTL(
- device, command_queue,
- MTLShaderLibraryFromFileData(device, shader_libraries_data,
- library_label),
- std::move(worker_task_runner), std::move(is_gpu_disabled_sync_switch)));
+ auto context = std::shared_ptr<ContextMTL>(
+ new ContextMTL(device, command_queue,
+ MTLShaderLibraryFromFileData(device, shader_libraries_data,
+ library_label),
+ std::move(is_gpu_disabled_sync_switch)));
if (!context->IsValid()) {
FML_LOG(ERROR) << "Could not create Metal context.";
return nullptr;
@@ -254,14 +268,13 @@
id<MTLDevice> device,
id<MTLCommandQueue> command_queue,
const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries_data,
- std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner,
std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch,
const std::string& library_label) {
- auto context = std::shared_ptr<ContextMTL>(new ContextMTL(
- device, command_queue,
- MTLShaderLibraryFromFileData(device, shader_libraries_data,
- library_label),
- std::move(worker_task_runner), std::move(is_gpu_disabled_sync_switch)));
+ auto context = std::shared_ptr<ContextMTL>(
+ new ContextMTL(device, command_queue,
+ MTLShaderLibraryFromFileData(device, shader_libraries_data,
+ library_label),
+ std::move(is_gpu_disabled_sync_switch)));
if (!context->IsValid()) {
FML_LOG(ERROR) << "Could not create Metal context.";
return nullptr;
@@ -301,9 +314,14 @@
return CreateCommandBufferInQueue(command_queue_);
}
-const std::shared_ptr<fml::ConcurrentTaskRunner>&
+// |Context|
+void ContextMTL::Shutdown() {
+ raster_message_loop_.reset();
+}
+
+const std::shared_ptr<fml::ConcurrentTaskRunner>
ContextMTL::GetWorkerTaskRunner() const {
- return worker_task_runner_;
+ return raster_message_loop_->GetTaskRunner();
}
std::shared_ptr<const fml::SyncSwitch> ContextMTL::GetIsGpuDisabledSyncSwitch()
diff --git a/impeller/renderer/backend/vulkan/context_vk.cc b/impeller/renderer/backend/vulkan/context_vk.cc
index 74ba948..81e700f 100644
--- a/impeller/renderer/backend/vulkan/context_vk.cc
+++ b/impeller/renderer/backend/vulkan/context_vk.cc
@@ -4,6 +4,12 @@
#include "impeller/renderer/backend/vulkan/context_vk.h"
+#ifdef FML_OS_ANDROID
+#include <pthread.h>
+#include <sys/resource.h>
+#include <sys/time.h>
+#endif // FML_OS_ANDROID
+
#include <map>
#include <memory>
#include <optional>
@@ -120,12 +126,15 @@
return;
}
- if (!settings.worker_task_runner) {
- VALIDATION_LOG
- << "Cannot set up a Vulkan context without a worker task runner.";
- return;
- }
- worker_task_runner_ = settings.worker_task_runner;
+ raster_message_loop_ = fml::ConcurrentMessageLoop::Create(
+ std::min(4u, std::thread::hardware_concurrency()));
+#ifdef FML_OS_ANDROID
+ raster_message_loop_->PostTaskToAllWorkers([]() {
+ if (::setpriority(PRIO_PROCESS, gettid(), -5) != 0) {
+ FML_LOG(ERROR) << "Failed to set Workers task runner priority";
+ }
+ });
+#endif // FML_OS_ANDROID
auto& dispatcher = VULKAN_HPP_DEFAULT_DISPATCHER;
dispatcher.init(settings.proc_address_callback);
@@ -335,10 +344,10 @@
/// Setup the pipeline library.
///
auto pipeline_library = std::shared_ptr<PipelineLibraryVK>(
- new PipelineLibraryVK(device_holder, //
- caps, //
- std::move(settings.cache_directory), //
- worker_task_runner_ //
+ new PipelineLibraryVK(device_holder, //
+ caps, //
+ std::move(settings.cache_directory), //
+ raster_message_loop_->GetTaskRunner() //
));
if (!pipeline_library->IsValid()) {
@@ -458,7 +467,11 @@
const std::shared_ptr<fml::ConcurrentTaskRunner>
ContextVK::GetConcurrentWorkerTaskRunner() const {
- return worker_task_runner_;
+ return raster_message_loop_->GetTaskRunner();
+}
+
+void ContextVK::Shutdown() {
+ raster_message_loop_->Terminate();
}
std::unique_ptr<Surface> ContextVK::AcquireNextSurface() {
diff --git a/impeller/renderer/backend/vulkan/context_vk.h b/impeller/renderer/backend/vulkan/context_vk.h
index cadb168..25f1ff6 100644
--- a/impeller/renderer/backend/vulkan/context_vk.h
+++ b/impeller/renderer/backend/vulkan/context_vk.h
@@ -39,7 +39,6 @@
PFN_vkGetInstanceProcAddr proc_address_callback = nullptr;
std::vector<std::shared_ptr<fml::Mapping>> shader_libraries_data;
fml::UniqueFD cache_directory;
- std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner;
bool enable_validation = false;
Settings() = default;
@@ -78,6 +77,9 @@
// |Context|
const std::shared_ptr<const Capabilities>& GetCapabilities() const override;
+ // |Context|
+ void Shutdown() override;
+
void SetOffscreenFormat(PixelFormat pixel_format);
template <typename T>
@@ -159,7 +161,7 @@
std::shared_ptr<const Capabilities> device_capabilities_;
std::shared_ptr<FenceWaiterVK> fence_waiter_;
std::string device_name_;
- std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner_;
+ std::shared_ptr<fml::ConcurrentMessageLoop> raster_message_loop_;
const uint64_t hash_;
bool is_valid_ = false;
diff --git a/impeller/renderer/backend/vulkan/test/mock_vulkan.cc b/impeller/renderer/backend/vulkan/test/mock_vulkan.cc
index d4faece..a6f3d08 100644
--- a/impeller/renderer/backend/vulkan/test/mock_vulkan.cc
+++ b/impeller/renderer/backend/vulkan/test/mock_vulkan.cc
@@ -433,8 +433,6 @@
std::shared_ptr<ContextVK> CreateMockVulkanContext(void) {
ContextVK::Settings settings;
auto message_loop = fml::ConcurrentMessageLoop::Create();
- settings.worker_task_runner =
- std::make_shared<fml::ConcurrentTaskRunner>(message_loop);
settings.proc_address_callback = GetMockVulkanProcAddress;
return ContextVK::Create(std::move(settings));
}
diff --git a/impeller/renderer/context.h b/impeller/renderer/context.h
index 36bf48c..554b496 100644
--- a/impeller/renderer/context.h
+++ b/impeller/renderer/context.h
@@ -42,6 +42,10 @@
virtual std::shared_ptr<CommandBuffer> CreateCommandBuffer() const = 0;
+ /// @brief Force all pending async work to finish by deleting any owned
+ /// concurrent message loops.
+ virtual void Shutdown() = 0;
+
protected:
Context();
diff --git a/impeller/renderer/testing/mocks.h b/impeller/renderer/testing/mocks.h
index e845a2a..3066523 100644
--- a/impeller/renderer/testing/mocks.h
+++ b/impeller/renderer/testing/mocks.h
@@ -90,6 +90,8 @@
MOCK_CONST_METHOD0(IsValid, bool());
+ MOCK_METHOD0(Shutdown, void());
+
MOCK_CONST_METHOD0(GetResourceAllocator, std::shared_ptr<Allocator>());
MOCK_CONST_METHOD0(GetShaderLibrary, std::shared_ptr<ShaderLibrary>());
diff --git a/lib/ui/painting/image_decoder_unittests.cc b/lib/ui/painting/image_decoder_unittests.cc
index 485fc8d..168aa70 100644
--- a/lib/ui/painting/image_decoder_unittests.cc
+++ b/lib/ui/painting/image_decoder_unittests.cc
@@ -142,6 +142,8 @@
return nullptr;
}
+ void Shutdown() override {}
+
mutable size_t command_buffer_count_ = 0;
private:
diff --git a/shell/common/animator_unittests.cc b/shell/common/animator_unittests.cc
index cf20635..e15aa1b 100644
--- a/shell/common/animator_unittests.cc
+++ b/shell/common/animator_unittests.cc
@@ -82,7 +82,6 @@
return ShellTestPlatformView::Create(
shell, shell.GetTaskRunners(), vsync_clock, create_vsync_waiter,
ShellTestPlatformView::BackendType::kDefaultBackend, nullptr,
- shell.GetConcurrentWorkerTaskRunner(),
shell.GetIsGpuDisabledSyncSwitch());
},
[](Shell& shell) { return std::make_unique<Rasterizer>(shell); });
diff --git a/shell/common/shell_test_platform_view.cc b/shell/common/shell_test_platform_view.cc
index b8188c8..248448f 100644
--- a/shell/common/shell_test_platform_view.cc
+++ b/shell/common/shell_test_platform_view.cc
@@ -27,7 +27,6 @@
BackendType backend,
const std::shared_ptr<ShellTestExternalViewEmbedder>&
shell_test_external_view_embedder,
- const std::shared_ptr<fml::ConcurrentTaskRunner>& worker_task_runner,
const std::shared_ptr<const fml::SyncSwitch>& is_gpu_disabled_sync_switch) {
// TODO(gw280): https://github.com/flutter/flutter/issues/50298
// Make this fully runtime configurable
@@ -49,8 +48,7 @@
case BackendType::kMetalBackend:
return std::make_unique<ShellTestPlatformViewMetal>(
delegate, task_runners, vsync_clock, create_vsync_waiter,
- shell_test_external_view_embedder, worker_task_runner,
- is_gpu_disabled_sync_switch);
+ shell_test_external_view_embedder, is_gpu_disabled_sync_switch);
#endif // SHELL_ENABLE_METAL
default:
@@ -84,7 +82,6 @@
create_vsync_waiter, //
config_.rendering_backend, //
config_.shell_test_external_view_embedder, //
- shell.GetConcurrentWorkerTaskRunner(), //
shell.GetIsGpuDisabledSyncSwitch() //
);
}
diff --git a/shell/common/shell_test_platform_view.h b/shell/common/shell_test_platform_view.h
index 3ac0d43..fdbe870 100644
--- a/shell/common/shell_test_platform_view.h
+++ b/shell/common/shell_test_platform_view.h
@@ -29,7 +29,6 @@
BackendType backend,
const std::shared_ptr<ShellTestExternalViewEmbedder>&
shell_test_external_view_embedder,
- const std::shared_ptr<fml::ConcurrentTaskRunner>& worker_task_runner,
const std::shared_ptr<const fml::SyncSwitch>&
is_gpu_disabled_sync_switch);
diff --git a/shell/common/shell_test_platform_view_metal.h b/shell/common/shell_test_platform_view_metal.h
index a20b9c5..c5c0a8d 100644
--- a/shell/common/shell_test_platform_view_metal.h
+++ b/shell/common/shell_test_platform_view_metal.h
@@ -17,16 +17,14 @@
class ShellTestPlatformViewMetal final : public ShellTestPlatformView,
public GPUSurfaceMetalDelegate {
public:
- ShellTestPlatformViewMetal(
- PlatformView::Delegate& delegate,
- const TaskRunners& task_runners,
- std::shared_ptr<ShellTestVsyncClock> vsync_clock,
- CreateVsyncWaiter create_vsync_waiter,
- std::shared_ptr<ShellTestExternalViewEmbedder>
- shell_test_external_view_embedder,
- const std::shared_ptr<fml::ConcurrentTaskRunner>& worker_task_runner,
- const std::shared_ptr<const fml::SyncSwitch>&
- is_gpu_disabled_sync_switch);
+ ShellTestPlatformViewMetal(PlatformView::Delegate& delegate,
+ const TaskRunners& task_runners,
+ std::shared_ptr<ShellTestVsyncClock> vsync_clock,
+ CreateVsyncWaiter create_vsync_waiter,
+ std::shared_ptr<ShellTestExternalViewEmbedder>
+ shell_test_external_view_embedder,
+ const std::shared_ptr<const fml::SyncSwitch>&
+ is_gpu_disabled_sync_switch);
// |ShellTestPlatformView|
virtual ~ShellTestPlatformViewMetal() override;
diff --git a/shell/common/shell_test_platform_view_metal.mm b/shell/common/shell_test_platform_view_metal.mm
index 598ecd5..4e96c6d 100644
--- a/shell/common/shell_test_platform_view_metal.mm
+++ b/shell/common/shell_test_platform_view_metal.mm
@@ -32,14 +32,11 @@
class DarwinContextMetal {
public:
explicit DarwinContextMetal(bool impeller,
- std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner,
std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch)
: context_(impeller ? nil : [[FlutterDarwinContextMetalSkia alloc] initWithDefaultMTLDevice]),
- impeller_context_(
- impeller ? [[FlutterDarwinContextMetalImpeller alloc]
- initWithTaskRunner:std::move(worker_task_runner)
- is_gpu_disabled_sync_switch:std::move(is_gpu_disabled_sync_switch)]
- : nil),
+ impeller_context_(impeller ? [[FlutterDarwinContextMetalImpeller alloc]
+ init:std::move(is_gpu_disabled_sync_switch)]
+ : nil),
offscreen_texture_(CreateOffscreenTexture(
impeller ? [impeller_context_ context]->GetMTLDevice() : [context_ device])) {}
@@ -74,12 +71,10 @@
std::shared_ptr<ShellTestVsyncClock> vsync_clock,
CreateVsyncWaiter create_vsync_waiter,
std::shared_ptr<ShellTestExternalViewEmbedder> shell_test_external_view_embedder,
- const std::shared_ptr<fml::ConcurrentTaskRunner>& worker_task_runner,
const std::shared_ptr<const fml::SyncSwitch>& is_gpu_disabled_sync_switch)
: ShellTestPlatformView(delegate, task_runners),
GPUSurfaceMetalDelegate(MTLRenderTargetType::kMTLTexture),
metal_context_(std::make_unique<DarwinContextMetal>(GetSettings().enable_impeller,
- worker_task_runner,
is_gpu_disabled_sync_switch)),
create_vsync_waiter_(std::move(create_vsync_waiter)),
vsync_clock_(std::move(vsync_clock)),
diff --git a/shell/common/shell_unittests.cc b/shell/common/shell_unittests.cc
index 0e110aa..16abef0 100644
--- a/shell/common/shell_unittests.cc
+++ b/shell/common/shell_unittests.cc
@@ -413,7 +413,6 @@
std::make_unique<VsyncWaiterFallback>(task_runners));
},
ShellTestPlatformView::BackendType::kDefaultBackend, nullptr,
- shell.GetConcurrentWorkerTaskRunner(),
shell.GetIsGpuDisabledSyncSwitch());
},
[](Shell& shell) { return std::make_unique<Rasterizer>(shell); });
diff --git a/shell/platform/android/BUILD.gn b/shell/platform/android/BUILD.gn
index db8a0c5..15bfe17 100644
--- a/shell/platform/android/BUILD.gn
+++ b/shell/platform/android/BUILD.gn
@@ -43,7 +43,6 @@
sources = [
"android_context_gl_impeller_unittests.cc",
"android_context_gl_unittests.cc",
- "android_context_vulkan_impeller_unittests.cc",
"android_shell_holder_unittests.cc",
"apk_asset_provider_unittests.cc",
"flutter_shell_native_unittests.cc",
diff --git a/shell/platform/android/android_context_vulkan_impeller.cc b/shell/platform/android/android_context_vulkan_impeller.cc
index 9d8deaa..50df30c 100644
--- a/shell/platform/android/android_context_vulkan_impeller.cc
+++ b/shell/platform/android/android_context_vulkan_impeller.cc
@@ -14,7 +14,6 @@
static std::shared_ptr<impeller::Context> CreateImpellerContext(
const fml::RefPtr<vulkan::VulkanProcTable>& proc_table,
- std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner,
bool enable_vulkan_validation) {
std::vector<std::shared_ptr<fml::Mapping>> shader_mappings = {
std::make_shared<fml::NonOwnedMapping>(impeller_entity_shaders_vk_data,
@@ -32,7 +31,6 @@
settings.proc_address_callback = instance_proc_addr;
settings.shader_libraries_data = std::move(shader_mappings);
settings.cache_directory = fml::paths::GetCachesDirectory();
- settings.worker_task_runner = std::move(worker_task_runner);
settings.enable_validation = enable_vulkan_validation;
FML_LOG(ERROR) << "Using the Impeller rendering backend (Vulkan).";
@@ -41,12 +39,10 @@
}
AndroidContextVulkanImpeller::AndroidContextVulkanImpeller(
- bool enable_validation,
- std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner)
+ bool enable_validation)
: AndroidContext(AndroidRenderingAPI::kVulkan),
proc_table_(fml::MakeRefCounted<vulkan::VulkanProcTable>()) {
- auto impeller_context = CreateImpellerContext(
- proc_table_, std::move(worker_task_runner), enable_validation);
+ auto impeller_context = CreateImpellerContext(proc_table_, enable_validation);
SetImpellerContext(impeller_context);
is_valid_ =
proc_table_->HasAcquiredMandatoryProcAddresses() && impeller_context;
diff --git a/shell/platform/android/android_context_vulkan_impeller.h b/shell/platform/android/android_context_vulkan_impeller.h
index 1c990d2..02e9a30 100644
--- a/shell/platform/android/android_context_vulkan_impeller.h
+++ b/shell/platform/android/android_context_vulkan_impeller.h
@@ -14,9 +14,7 @@
class AndroidContextVulkanImpeller : public AndroidContext {
public:
- AndroidContextVulkanImpeller(
- bool enable_validation,
- std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner);
+ AndroidContextVulkanImpeller(bool enable_validation);
~AndroidContextVulkanImpeller();
diff --git a/shell/platform/android/android_context_vulkan_impeller_unittests.cc b/shell/platform/android/android_context_vulkan_impeller_unittests.cc
deleted file mode 100644
index 6ac09d8..0000000
--- a/shell/platform/android/android_context_vulkan_impeller_unittests.cc
+++ /dev/null
@@ -1,31 +0,0 @@
-#include <memory>
-
-#include "flutter/fml/synchronization/waitable_event.h"
-#include "flutter/impeller/renderer/backend/vulkan/context_vk.h"
-#include "flutter/shell/platform/android/android_context_vulkan_impeller.h"
-#include "gmock/gmock.h"
-#include "gtest/gtest.h"
-
-namespace flutter {
-namespace testing {
-
-TEST(AndroidContextVulkanImpeller, DoesNotCreateOwnMessageLoop) {
- auto loop = fml::ConcurrentMessageLoop::Create();
- auto context = std::make_unique<AndroidContextVulkanImpeller>(
- false, loop->GetTaskRunner());
- ASSERT_TRUE(context);
-
- auto impeller_context = std::static_pointer_cast<impeller::ContextVK>(
- context->GetImpellerContext());
- ASSERT_TRUE(impeller_context);
-
- fml::AutoResetWaitableEvent latch;
- impeller_context->GetConcurrentWorkerTaskRunner()->PostTask([loop, &latch]() {
- ASSERT_TRUE(loop->RunsTasksOnCurrentThread());
- latch.Signal();
- });
- latch.Wait();
-}
-
-} // namespace testing
-} // namespace flutter
diff --git a/shell/platform/android/android_shell_holder.cc b/shell/platform/android/android_shell_holder.cc
index f555c38..becc686 100644
--- a/shell/platform/android/android_shell_holder.cc
+++ b/shell/platform/android/android_shell_holder.cc
@@ -109,10 +109,9 @@
[&jni_facade, &weak_platform_view](Shell& shell) {
std::unique_ptr<PlatformViewAndroid> platform_view_android;
platform_view_android = std::make_unique<PlatformViewAndroid>(
- shell, // delegate
- shell.GetTaskRunners(), // task runners
- shell.GetConcurrentWorkerTaskRunner(), // worker task runner
- jni_facade, // JNI interop
+ shell, // delegate
+ shell.GetTaskRunners(), // task runners
+ jni_facade, // JNI interop
shell.GetSettings()
.enable_software_rendering, // use software rendering
shell.GetSettings().msaa_samples // msaa sample count
diff --git a/shell/platform/android/platform_view_android.cc b/shell/platform/android/platform_view_android.cc
index a1053fb..2993c3d 100644
--- a/shell/platform/android/platform_view_android.cc
+++ b/shell/platform/android/platform_view_android.cc
@@ -63,7 +63,6 @@
static std::shared_ptr<flutter::AndroidContext> CreateAndroidContext(
bool use_software_rendering,
const flutter::TaskRunners& task_runners,
- const std::shared_ptr<fml::ConcurrentTaskRunner>& worker_task_runner,
uint8_t msaa_samples,
bool enable_impeller,
const std::optional<std::string>& impeller_backend,
@@ -90,10 +89,10 @@
std::make_unique<impeller::egl::Display>());
case AndroidRenderingAPI::kVulkan:
return std::make_unique<AndroidContextVulkanImpeller>(
- enable_vulkan_validation, worker_task_runner);
+ enable_vulkan_validation);
case AndroidRenderingAPI::kAutoselect: {
auto vulkan_backend = std::make_unique<AndroidContextVulkanImpeller>(
- enable_vulkan_validation, worker_task_runner);
+ enable_vulkan_validation);
if (!vulkan_backend->IsValid()) {
return std::make_unique<AndroidContextGLImpeller>(
std::make_unique<impeller::egl::Display>());
@@ -115,7 +114,6 @@
PlatformViewAndroid::PlatformViewAndroid(
PlatformView::Delegate& delegate,
const flutter::TaskRunners& task_runners,
- const std::shared_ptr<fml::ConcurrentTaskRunner>& worker_task_runner,
const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade,
bool use_software_rendering,
uint8_t msaa_samples)
@@ -126,7 +124,6 @@
CreateAndroidContext(
use_software_rendering,
task_runners,
- worker_task_runner,
msaa_samples,
delegate.OnPlatformViewGetSettings().enable_impeller,
delegate.OnPlatformViewGetSettings().impeller_backend,
diff --git a/shell/platform/android/platform_view_android.h b/shell/platform/android/platform_view_android.h
index 300f3ab..069b2f9 100644
--- a/shell/platform/android/platform_view_android.h
+++ b/shell/platform/android/platform_view_android.h
@@ -42,13 +42,11 @@
public:
static bool Register(JNIEnv* env);
- PlatformViewAndroid(
- PlatformView::Delegate& delegate,
- const flutter::TaskRunners& task_runners,
- const std::shared_ptr<fml::ConcurrentTaskRunner>& worker_task_runner,
- const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade,
- bool use_software_rendering,
- uint8_t msaa_samples);
+ PlatformViewAndroid(PlatformView::Delegate& delegate,
+ const flutter::TaskRunners& task_runners,
+ const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade,
+ bool use_software_rendering,
+ uint8_t msaa_samples);
//----------------------------------------------------------------------------
/// @brief Creates a new PlatformViewAndroid but using an existing
diff --git a/shell/platform/darwin/graphics/FlutterDarwinContextMetalImpeller.h b/shell/platform/darwin/graphics/FlutterDarwinContextMetalImpeller.h
index 4a09c6d..549723d 100644
--- a/shell/platform/darwin/graphics/FlutterDarwinContextMetalImpeller.h
+++ b/shell/platform/darwin/graphics/FlutterDarwinContextMetalImpeller.h
@@ -25,9 +25,7 @@
/**
* Initializes a FlutterDarwinContextMetalImpeller.
*/
-- (instancetype)initWithTaskRunner:(std::shared_ptr<fml::ConcurrentTaskRunner>)task_runner
- is_gpu_disabled_sync_switch:
- (std::shared_ptr<const fml::SyncSwitch>)is_gpu_disabled_sync_switch;
+- (instancetype)init:(std::shared_ptr<const fml::SyncSwitch>)is_gpu_disabled_sync_switch;
/**
* Creates an external texture with the specified ID and contents.
diff --git a/shell/platform/darwin/graphics/FlutterDarwinContextMetalImpeller.mm b/shell/platform/darwin/graphics/FlutterDarwinContextMetalImpeller.mm
index 34cc332..00c4115 100644
--- a/shell/platform/darwin/graphics/FlutterDarwinContextMetalImpeller.mm
+++ b/shell/platform/darwin/graphics/FlutterDarwinContextMetalImpeller.mm
@@ -17,7 +17,6 @@
FLUTTER_ASSERT_ARC
static std::shared_ptr<impeller::ContextMTL> CreateImpellerContext(
- std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner,
std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch) {
std::vector<std::shared_ptr<fml::Mapping>> shader_mappings = {
std::make_shared<fml::NonOwnedMapping>(impeller_entity_shaders_data,
@@ -29,9 +28,8 @@
std::make_shared<fml::NonOwnedMapping>(impeller_framebuffer_blend_shaders_data,
impeller_framebuffer_blend_shaders_length),
};
- auto context =
- impeller::ContextMTL::Create(shader_mappings, std::move(worker_task_runner),
- std::move(is_gpu_disabled_sync_switch), "Impeller Library");
+ auto context = impeller::ContextMTL::Create(
+ shader_mappings, std::move(is_gpu_disabled_sync_switch), "Impeller Library");
if (!context) {
FML_LOG(ERROR) << "Could not create Metal Impeller Context.";
return nullptr;
@@ -43,13 +41,10 @@
@implementation FlutterDarwinContextMetalImpeller
-- (instancetype)initWithTaskRunner:(std::shared_ptr<fml::ConcurrentTaskRunner>)task_runner
- is_gpu_disabled_sync_switch:
- (std::shared_ptr<const fml::SyncSwitch>)is_gpu_disabled_sync_switch {
+- (instancetype)init:(std::shared_ptr<const fml::SyncSwitch>)is_gpu_disabled_sync_switch {
self = [super init];
if (self != nil) {
- _context =
- CreateImpellerContext(std::move(task_runner), std::move(is_gpu_disabled_sync_switch));
+ _context = CreateImpellerContext(std::move(is_gpu_disabled_sync_switch));
id<MTLDevice> device = _context->GetMTLDevice();
if (!device) {
FML_DLOG(ERROR) << "Could not acquire Metal device.";
diff --git a/shell/platform/darwin/ios/ios_context.h b/shell/platform/darwin/ios/ios_context.h
index 3506567..9a4049b 100644
--- a/shell/platform/darwin/ios/ios_context.h
+++ b/shell/platform/darwin/ios/ios_context.h
@@ -53,8 +53,6 @@
/// @param[in] msaa_samples
/// The number of MSAA samples to use. Only supplied to
/// Skia, must be either 0, 1, 2, 4, or 8.
- /// @param[in] task_runner
- /// The engine concurrent task runner.
///
/// @return A valid context on success. `nullptr` on failure.
///
@@ -62,7 +60,6 @@
IOSRenderingAPI api,
IOSRenderingBackend backend,
MsaaSampleCount msaa_samples,
- std::shared_ptr<fml::ConcurrentTaskRunner> task_runner,
std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch);
//----------------------------------------------------------------------------
diff --git a/shell/platform/darwin/ios/ios_context.mm b/shell/platform/darwin/ios/ios_context.mm
index fba7071..007de7a 100644
--- a/shell/platform/darwin/ios/ios_context.mm
+++ b/shell/platform/darwin/ios/ios_context.mm
@@ -22,7 +22,6 @@
IOSRenderingAPI api,
IOSRenderingBackend backend,
MsaaSampleCount msaa_samples,
- std::shared_ptr<fml::ConcurrentTaskRunner> task_runner,
std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch) {
switch (api) {
case IOSRenderingAPI::kSoftware:
@@ -33,8 +32,7 @@
case IOSRenderingBackend::kSkia:
return std::make_unique<IOSContextMetalSkia>(msaa_samples);
case IOSRenderingBackend::kImpeller:
- return std::make_unique<IOSContextMetalImpeller>(std::move(task_runner),
- std::move(is_gpu_disabled_sync_switch));
+ return std::make_unique<IOSContextMetalImpeller>(std::move(is_gpu_disabled_sync_switch));
}
#endif // SHELL_ENABLE_METAL
default:
diff --git a/shell/platform/darwin/ios/ios_context_metal_impeller.h b/shell/platform/darwin/ios/ios_context_metal_impeller.h
index 1013621..1647b37 100644
--- a/shell/platform/darwin/ios/ios_context_metal_impeller.h
+++ b/shell/platform/darwin/ios/ios_context_metal_impeller.h
@@ -20,8 +20,7 @@
class IOSContextMetalImpeller final : public IOSContext {
public:
- IOSContextMetalImpeller(std::shared_ptr<fml::ConcurrentTaskRunner> task_runner,
- std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch);
+ IOSContextMetalImpeller(std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch);
~IOSContextMetalImpeller();
diff --git a/shell/platform/darwin/ios/ios_context_metal_impeller.mm b/shell/platform/darwin/ios/ios_context_metal_impeller.mm
index 75f3a53..d618722 100644
--- a/shell/platform/darwin/ios/ios_context_metal_impeller.mm
+++ b/shell/platform/darwin/ios/ios_context_metal_impeller.mm
@@ -9,13 +9,11 @@
namespace flutter {
IOSContextMetalImpeller::IOSContextMetalImpeller(
- std::shared_ptr<fml::ConcurrentTaskRunner> task_runner,
std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch)
: IOSContext(MsaaSampleCount::kFour),
darwin_context_metal_impeller_(fml::scoped_nsobject<FlutterDarwinContextMetalImpeller>{
[[FlutterDarwinContextMetalImpeller alloc]
- initWithTaskRunner:std::move(task_runner)
- is_gpu_disabled_sync_switch:std::move(is_gpu_disabled_sync_switch)]}) {}
+ init:std::move(is_gpu_disabled_sync_switch)]}) {}
IOSContextMetalImpeller::~IOSContextMetalImpeller() = default;
diff --git a/shell/platform/darwin/ios/platform_view_ios.mm b/shell/platform/darwin/ios/platform_view_ios.mm
index 61095c8..f600f6c 100644
--- a/shell/platform/darwin/ios/platform_view_ios.mm
+++ b/shell/platform/darwin/ios/platform_view_ios.mm
@@ -65,7 +65,6 @@
delegate.OnPlatformViewGetSettings().enable_impeller ? IOSRenderingBackend::kImpeller
: IOSRenderingBackend::kSkia,
static_cast<MsaaSampleCount>(delegate.OnPlatformViewGetSettings().msaa_samples),
- worker_task_runner,
std::move(is_gpu_disabled_sync_switch)),
platform_views_controller,
task_runners) {}
diff --git a/shell/platform/embedder/embedder_surface_metal_impeller.h b/shell/platform/embedder/embedder_surface_metal_impeller.h
index 2ddacd9..109870a 100644
--- a/shell/platform/embedder/embedder_surface_metal_impeller.h
+++ b/shell/platform/embedder/embedder_surface_metal_impeller.h
@@ -41,7 +41,6 @@
MetalDispatchTable metal_dispatch_table_;
std::shared_ptr<EmbedderExternalViewEmbedder> external_view_embedder_;
std::shared_ptr<impeller::Context> context_;
- std::shared_ptr<fml::ConcurrentMessageLoop> concurrent_loop_;
// |EmbedderSurface|
bool IsValid() const override;
diff --git a/shell/platform/embedder/embedder_surface_metal_impeller.mm b/shell/platform/embedder/embedder_surface_metal_impeller.mm
index ba56152..139f3e9 100644
--- a/shell/platform/embedder/embedder_surface_metal_impeller.mm
+++ b/shell/platform/embedder/embedder_surface_metal_impeller.mm
@@ -29,8 +29,7 @@
std::shared_ptr<EmbedderExternalViewEmbedder> external_view_embedder)
: GPUSurfaceMetalDelegate(MTLRenderTargetType::kMTLTexture),
metal_dispatch_table_(std::move(metal_dispatch_table)),
- external_view_embedder_(std::move(external_view_embedder)),
- concurrent_loop_(fml::ConcurrentMessageLoop::Create()) {
+ external_view_embedder_(std::move(external_view_embedder)) {
std::vector<std::shared_ptr<fml::Mapping>> shader_mappings = {
std::make_shared<fml::NonOwnedMapping>(impeller_entity_shaders_data,
impeller_entity_shaders_length),
@@ -45,7 +44,6 @@
(id<MTLDevice>)device, // device
(id<MTLCommandQueue>)command_queue, // command_queue
shader_mappings, // shader_libraries_data
- concurrent_loop_->GetTaskRunner(), // worker_task_runner
std::make_shared<fml::SyncSwitch>(false), // is_gpu_disabled_sync_switch
"Impeller Library" // library_label
);