0

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 <penghuang@chromium.org>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#777434}
This commit is contained in:
Peng Huang
2020-06-11 19:20:54 +00:00
committed by Commit Bot
parent 9c0c6ecc84
commit 9c5949a06d
3 changed files with 43 additions and 2 deletions

@ -1823,6 +1823,11 @@ def _GetMessageForMatchingType(input_api, affected_file, line_number, line,
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 @@ def _GetMessageForMatchingType(input_api, affected_file, line_number, line,
elif type_name in line:
matched = True
result = []
if matched:
result.append(' %s:%d:' % (affected_file.LocalPath(), line_number))
for message_line in message:

@ -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 @@ bool VulkanInProcessContextProvider::Initialize(
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 @@ void VulkanInProcessContextProvider::Destroy() {
gr_context_.reset();
}
executor_.reset();
if (device_queue_) {
device_queue_->Destroy();
device_queue_.reset();

@ -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 @@ class VIZ_VULKAN_CONTEXT_PROVIDER_EXPORT VulkanInProcessContextProvider
#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