[Impeller] Give Impeller a dedicated raster priority level worker loop. (flutter/engine#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.
This commit is contained in:
Jonah Williams
2023-06-27 11:08:49 -07:00
committed by GitHub
parent 6504962164
commit ac3ce651f3
39 changed files with 156 additions and 185 deletions

View File

@@ -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

View File

@@ -29,6 +29,7 @@ ConcurrentMessageLoop::ConcurrentMessageLoop(size_t worker_count)
ConcurrentMessageLoop::~ConcurrentMessageLoop() {
Terminate();
for (auto& worker : workers_) {
FML_DCHECK(worker.joinable());
worker.join();
}
}

View File

@@ -73,10 +73,9 @@ PlaygroundImplMTL::PlaygroundImplMTL(PlaygroundSwitches switches)
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;
}

View File

@@ -52,9 +52,7 @@ void PlaygroundImplVK::DestroyWindowHandle(WindowHandle handle) {
}
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 @@ PlaygroundImplVK::PlaygroundImplVK(PlaygroundSwitches switches)
&::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));

View File

@@ -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 @@ class PlaygroundImplVK final : public PlaygroundImpl {
~PlaygroundImplVK();
private:
std::shared_ptr<fml::ConcurrentMessageLoop> concurrent_loop_;
std::shared_ptr<Context> context_;
// Windows management.

View File

@@ -139,6 +139,9 @@ void Playground::SetupWindow() {
}
void Playground::TeardownWindow() {
if (context_) {
context_->Shutdown();
}
context_.reset();
renderer_.reset();
impl_.reset();

View File

@@ -107,6 +107,8 @@ bool ContextGLES::IsValid() const {
return is_valid_;
}
void ContextGLES::Shutdown() {}
// |Context|
std::string ContextGLES::DescribeGpuModel() const {
return reactor_->GetProcTable().GetDescription()->GetString();

View File

@@ -72,6 +72,9 @@ class ContextGLES final : public Context,
// |Context|
const std::shared_ptr<const Capabilities>& GetCapabilities() const override;
// |Context|
void Shutdown() override;
FML_DISALLOW_COPY_AND_ASSIGN(ContextGLES);
};

View File

@@ -202,32 +202,39 @@ bool CommandBufferMTL::SubmitCommandsAsync(
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;
}

View File

@@ -35,12 +35,10 @@ class ContextMTL final : public Context,
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 @@ class ContextMTL final : public Context,
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 @@ class ContextMTL final : public Context,
// |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 @@ class ContextMTL final : public Context,
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 @@ class ContextMTL final : public Context,
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(

View File

@@ -71,11 +71,9 @@ ContextMTL::ContextMTL(
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 @@ ContextMTL::ContextMTL(
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, &param)) {
param.sched_priority = 50;
pthread_setschedparam(thread, policy, &param);
}
});
}
// Setup the shader library.
{
if (shader_libraries == nil) {
@@ -210,7 +226,6 @@ static id<MTLCommandQueue> CreateMetalCommandQueue(id<MTLDevice> device) {
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 @@ std::shared_ptr<ContextMTL> ContextMTL::Create(
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(
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 @@ std::shared_ptr<ContextMTL> ContextMTL::Create(
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 @@ std::shared_ptr<ContextMTL> ContextMTL::Create(
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 @@ std::shared_ptr<CommandBuffer> ContextMTL::CreateCommandBuffer() const {
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()

View File

@@ -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 @@ void ContextVK::Setup(Settings settings) {
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 @@ void ContextVK::Setup(Settings settings) {
/// 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 vk::Device& ContextVK::GetDevice() const {
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() {

View File

@@ -39,7 +39,6 @@ class ContextVK final : public Context,
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 @@ class ContextVK final : public Context,
// |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 @@ class ContextVK final : public Context,
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;

View File

@@ -433,8 +433,6 @@ PFN_vkVoidFunction GetMockVulkanProcAddress(VkInstance instance,
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));
}

View File

@@ -42,6 +42,10 @@ class Context {
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();

View File

@@ -90,6 +90,8 @@ class MockImpellerContext : public Context {
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>());

View File

@@ -142,6 +142,8 @@ class TestImpellerContext : public impeller::Context {
return nullptr;
}
void Shutdown() override {}
mutable size_t command_buffer_count_ = 0;
private:

View File

@@ -82,7 +82,6 @@ TEST_F(ShellTest, VSyncTargetTime) {
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); });

View File

@@ -27,7 +27,6 @@ std::unique_ptr<ShellTestPlatformView> ShellTestPlatformView::Create(
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 @@ std::unique_ptr<ShellTestPlatformView> ShellTestPlatformView::Create(
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 @@ std::unique_ptr<PlatformView> ShellTestPlatformViewBuilder::operator()(
create_vsync_waiter, //
config_.rendering_backend, //
config_.shell_test_external_view_embedder, //
shell.GetConcurrentWorkerTaskRunner(), //
shell.GetIsGpuDisabledSyncSwitch() //
);
}

View File

@@ -29,7 +29,6 @@ class ShellTestPlatformView : public PlatformView {
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);

View File

@@ -17,16 +17,14 @@ class DarwinContextMetal;
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;

View File

@@ -32,14 +32,11 @@ static fml::scoped_nsprotocol<id<MTLTexture>> CreateOffscreenTexture(id<MTLDevic
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 @@ ShellTestPlatformViewMetal::ShellTestPlatformViewMetal(
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)),

View File

@@ -413,7 +413,6 @@ TEST_F(ShellTest,
std::make_unique<VsyncWaiterFallback>(task_runners));
},
ShellTestPlatformView::BackendType::kDefaultBackend, nullptr,
shell.GetConcurrentWorkerTaskRunner(),
shell.GetIsGpuDisabledSyncSwitch());
},
[](Shell& shell) { return std::make_unique<Rasterizer>(shell); });

View File

@@ -43,7 +43,6 @@ executable("flutter_shell_native_unittests") {
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",

View File

@@ -14,7 +14,6 @@ namespace flutter {
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 @@ static std::shared_ptr<impeller::Context> CreateImpellerContext(
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 @@ static std::shared_ptr<impeller::Context> CreateImpellerContext(
}
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;

View File

@@ -14,9 +14,7 @@ namespace flutter {
class AndroidContextVulkanImpeller : public AndroidContext {
public:
AndroidContextVulkanImpeller(
bool enable_validation,
std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner);
AndroidContextVulkanImpeller(bool enable_validation);
~AndroidContextVulkanImpeller();

View File

@@ -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

View File

@@ -109,10 +109,9 @@ AndroidShellHolder::AndroidShellHolder(
[&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

View File

@@ -63,7 +63,6 @@ std::unique_ptr<AndroidSurface> AndroidSurfaceFactoryImpl::CreateSurface() {
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 @@ static std::shared_ptr<flutter::AndroidContext> CreateAndroidContext(
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 @@ static std::shared_ptr<flutter::AndroidContext> CreateAndroidContext(
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 @@ PlatformViewAndroid::PlatformViewAndroid(
CreateAndroidContext(
use_software_rendering,
task_runners,
worker_task_runner,
msaa_samples,
delegate.OnPlatformViewGetSettings().enable_impeller,
delegate.OnPlatformViewGetSettings().impeller_backend,

View File

@@ -42,13 +42,11 @@ class PlatformViewAndroid final : public PlatformView {
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

View File

@@ -25,9 +25,7 @@ NS_ASSUME_NONNULL_BEGIN
/**
* 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.

View File

@@ -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 @@ static std::shared_ptr<impeller::ContextMTL> CreateImpellerContext(
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 @@ static std::shared_ptr<impeller::ContextMTL> CreateImpellerContext(
@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.";

View File

@@ -53,8 +53,6 @@ class IOSContext {
/// @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 @@ class IOSContext {
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);
//----------------------------------------------------------------------------

View File

@@ -22,7 +22,6 @@ std::unique_ptr<IOSContext> IOSContext::Create(
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 @@ std::unique_ptr<IOSContext> IOSContext::Create(
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:

View File

@@ -20,8 +20,7 @@ namespace flutter {
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();

View File

@@ -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;

View File

@@ -65,7 +65,6 @@ PlatformViewIOS::PlatformViewIOS(
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) {}

View File

@@ -41,7 +41,6 @@ class EmbedderSurfaceMetalImpeller final : public EmbedderSurface,
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;

View File

@@ -29,8 +29,7 @@ EmbedderSurfaceMetalImpeller::EmbedderSurfaceMetalImpeller(
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 @@ EmbedderSurfaceMetalImpeller::EmbedderSurfaceMetalImpeller(
(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
);