Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions impeller/renderer/backend/vulkan/context_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "impeller/renderer/backend/vulkan/context_vk.h"

#include "fml/concurrent_message_loop.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Newline between primary header and the rest.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


#ifdef FML_OS_ANDROID
#include <pthread.h>
#include <sys/resource.h>
Expand Down Expand Up @@ -128,6 +130,12 @@ void ContextVK::Setup(Settings settings) {
return;
}

queue_submit_thread_ = std::make_unique<fml::Thread>("QueueSubmitThread");
queue_submit_thread_->GetTaskRunner()->PostTask([]() {
// submitKHR is extremely cheap and mostly blocks on an internal fence.
fml::RequestAffinity(fml::CpuAffinity::kEfficiency);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about just fml::Thread? That has a handy way to name the thread too. You can still post task to it to set it as an efficiency affinity.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh neat, didn't realize that. makes more sense

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

});

raster_message_loop_ = fml::ConcurrentMessageLoop::Create(
std::min(4u, std::thread::hardware_concurrency()));
raster_message_loop_->PostTaskToAllWorkers([]() {
Expand Down Expand Up @@ -486,6 +494,10 @@ const vk::Device& ContextVK::GetDevice() const {
return device_holder_->device.get();
}

const fml::RefPtr<fml::TaskRunner> ContextVK::GetQueueSubmitRunner() const {
return queue_submit_thread_->GetTaskRunner();
}

const std::shared_ptr<fml::ConcurrentTaskRunner>
ContextVK::GetConcurrentWorkerTaskRunner() const {
return raster_message_loop_->GetTaskRunner();
Expand All @@ -500,6 +512,7 @@ void ContextVK::Shutdown() {
fence_waiter_.reset();
resource_manager_.reset();

queue_submit_thread_->Join();
raster_message_loop_->Terminate();
}

Expand Down
14 changes: 14 additions & 0 deletions impeller/renderer/backend/vulkan/context_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "flutter/fml/macros.h"
#include "flutter/fml/mapping.h"
#include "flutter/fml/unique_fd.h"
#include "fml/thread.h"
#include "impeller/base/backend_cast.h"
#include "impeller/core/formats.h"
#include "impeller/renderer/backend/vulkan/command_pool_vk.h"
Expand Down Expand Up @@ -133,6 +134,18 @@ class ContextVK final : public Context,
const std::shared_ptr<fml::ConcurrentTaskRunner>
GetConcurrentWorkerTaskRunner() const;

/// @brief A single-threaded task runner that should only be used for
/// submitKHR.
///
/// SubmitKHR will block until all previously submitted command buffers have
/// been scheduled. If there are no platform views in the scene (excluding
/// texture backed platform views). Then it is safe for SwapchainImpl::Present
/// to return before submit has completed. To do so, we offload the submit
/// command to a specialized single threaded task runner. The single thread
/// ensures that we do not queue up too much work and that the submissions
/// proceed in order.
const fml::RefPtr<fml::TaskRunner> GetQueueSubmitRunner() const;

std::shared_ptr<SurfaceContextVK> CreateSurfaceContext();

const std::shared_ptr<QueueVK>& GetGraphicsQueue() const;
Expand Down Expand Up @@ -176,6 +189,7 @@ class ContextVK final : public Context,
std::shared_ptr<CommandPoolRecyclerVK> command_pool_recycler_;
std::string device_name_;
std::shared_ptr<fml::ConcurrentMessageLoop> raster_message_loop_;
std::unique_ptr<fml::Thread> queue_submit_thread_;
std::shared_ptr<GPUTracerVK> gpu_tracer_;

bool sync_presentation_ = false;
Expand Down
2 changes: 1 addition & 1 deletion impeller/renderer/backend/vulkan/gpu_tracer_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace impeller {

static constexpr uint32_t kPoolSize = 64u;
static constexpr uint32_t kPoolSize = 1024u;

GPUTracerVK::GPUTracerVK(const std::shared_ptr<DeviceHolder>& device_holder)
: device_holder_(device_holder) {
Expand Down
2 changes: 1 addition & 1 deletion impeller/renderer/backend/vulkan/swapchain_impl_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ bool SwapchainImplVK::Present(const std::shared_ptr<SwapchainImageVK>& image,
if (context.GetSyncPresentation()) {
task();
} else {
context.GetConcurrentWorkerTaskRunner()->PostTask(task);
context.GetQueueSubmitRunner()->PostTask(task);
}
return true;
}
Expand Down
4 changes: 3 additions & 1 deletion impeller/renderer/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ class Context {
///
/// This is required for correct rendering on Android when using
/// the hybrid composition mode. This has no effect on other
/// backends.
/// backends. This is analogous to the check for isMainThread in
/// surface_mtl.mm to block presentation on scheduling of all
/// pending work.
virtual void SetSyncPresentation(bool value) {}

//----------------------------------------------------------------------------
Expand Down