vulkan: add SkExecutor used by skia to execute some CPU tasks
With this executor, skia will off some CPU works (computing draw path,
releasing vk resource, etc) from GPU main thread to background threads.
Bug: None
Change-Id: Iac3f235cb17e7896edd432d205a3bb7ab9cf8a0d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2240132
Commit-Queue: Peng Huang <[email protected]>
Reviewed-by: Brian Salomon <[email protected]>
Reviewed-by: Daniel Cheng <[email protected]>
Cr-Commit-Position: refs/heads/master@{#777434}
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index f78b8eec..d7985f77 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -1823,6 +1823,11 @@
match has been found and the additional text passed as |message| in case the
target type name matches the text inside the line passed as parameter.
"""
+ result = []
+
+ if line.endswith(" nocheck"):
+ return result
+
matched = False
if type_name[0:1] == '/':
regex = type_name[1:]
@@ -1831,7 +1836,6 @@
elif type_name in line:
matched = True
- result = []
if matched:
result.append(' %s:%d:' % (affected_file.LocalPath(), line_number))
for message_line in message:
diff --git a/components/viz/common/gpu/vulkan_in_process_context_provider.cc b/components/viz/common/gpu/vulkan_in_process_context_provider.cc
index 204fea1..4d098c5 100644
--- a/components/viz/common/gpu/vulkan_in_process_context_provider.cc
+++ b/components/viz/common/gpu/vulkan_in_process_context_provider.cc
@@ -4,6 +4,8 @@
#include "components/viz/common/gpu/vulkan_in_process_context_provider.h"
+#include "base/task/thread_pool.h"
+#include "base/task/thread_pool/thread_pool_instance.h"
#include "gpu/vulkan/buildflags.h"
#include "gpu/vulkan/init/gr_vk_memory_allocator_impl.h"
#include "gpu/vulkan/vulkan_device_queue.h"
@@ -12,9 +14,30 @@
#include "gpu/vulkan/vulkan_implementation.h"
#include "gpu/vulkan/vulkan_instance.h"
#include "gpu/vulkan/vulkan_util.h"
+#include "third_party/skia/include/core/SkExecutor.h"
#include "third_party/skia/include/gpu/GrContext.h"
#include "third_party/skia/include/gpu/vk/GrVkExtensions.h"
+namespace {
+
+class VizExecutor : public SkExecutor {
+ public:
+ VizExecutor() = default;
+ ~VizExecutor() override = default;
+ VizExecutor(const VizExecutor&) = delete;
+ VizExecutor& operator=(const VizExecutor&) = delete;
+
+ // std::function is used by SkExecutor in //third_party/skia. nocheck
+ using Fn = std::function<void(void)>; // nocheck
+ // SkExecutor:
+ void add(Fn task) override {
+ base::ThreadPool::PostTask(
+ FROM_HERE, base::BindOnce([](Fn task) { task(); }, std::move(task)));
+ }
+};
+
+} // namespace
+
namespace viz {
// static
@@ -102,7 +125,16 @@
vulkan_implementation_->enforce_protected_memory() ? GrProtected::kYes
: GrProtected::kNo;
- gr_context_ = GrContext::MakeVulkan(backend_context, context_options);
+ GrContextOptions options;
+ if (base::ThreadPoolInstance::Get()) {
+ // For some tests, ThreadPoolInstance is not initialized. VizExecutor will
+ // not be used for this case.
+ // TODO(penghuang): Make sure ThreadPoolInstance is initialized for related
+ // tests.
+ executor_ = std::make_unique<VizExecutor>();
+ options.fExecutor = executor_.get();
+ }
+ gr_context_ = GrContext::MakeVulkan(backend_context, options);
return gr_context_ != nullptr;
}
@@ -122,6 +154,8 @@
gr_context_.reset();
}
+ executor_.reset();
+
if (device_queue_) {
device_queue_->Destroy();
device_queue_.reset();
diff --git a/components/viz/common/gpu/vulkan_in_process_context_provider.h b/components/viz/common/gpu/vulkan_in_process_context_provider.h
index 1215dff2..05ea0a5c 100644
--- a/components/viz/common/gpu/vulkan_in_process_context_provider.h
+++ b/components/viz/common/gpu/vulkan_in_process_context_provider.h
@@ -16,6 +16,8 @@
#include "third_party/skia/include/gpu/vk/GrVkBackendContext.h"
#endif
+class SkExecutor;
+
namespace gpu {
class VulkanImplementation;
class VulkanDeviceQueue;
@@ -53,6 +55,7 @@
#if BUILDFLAG(ENABLE_VULKAN)
sk_sp<GrContext> gr_context_;
+ std::unique_ptr<SkExecutor> executor_;
gpu::VulkanImplementation* vulkan_implementation_;
std::unique_ptr<gpu::VulkanDeviceQueue> device_queue_;
#endif