Commit 6aee9290 authored by Vasiliy Telezhnikov's avatar Vasiliy Telezhnikov Committed by Commit Bot

Reland "Use GrShaderCache with Vulkan"

This is a reland of db7626d6

Changes from the original: check if vk_context_provider not null.

Original change's description:
> Use GrShaderCache with Vulkan
>
> VulkanContextProvider is created before GrShaderCache and so cache
> wasn't pass to Skia via GrContextOptions.
>
> This CL defers init of GrContext in VulkanInProcessContextProvider to
> SharedContextState::InitializeGrContext to mitigate this.
>
> Use of cache itself is under feature flag for metrics comparison and
> a kill switch purpose.
>
> Bug: 1151031
> Change-Id: Idc410b9b557f7ca67164eb80d6a37a27ceb0f6d2
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2551245
> Reviewed-by: Peng Huang <penghuang@chromium.org>
> Commit-Queue: Vasiliy Telezhnikov <vasilyt@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#829651}

Bug: 1151031
Change-Id: Ibd4e7d55fdc56c1ea2cc0e82d6cc6c34459165c5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2554353Reviewed-by: default avatarPeng Huang <penghuang@chromium.org>
Commit-Queue: Vasiliy Telezhnikov <vasilyt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#830753}
parent 1c7bd68a
......@@ -215,6 +215,13 @@ bool AwVulkanContextProvider::Initialize(AwDrawFn_InitVkParams* params) {
return !!globals_;
}
bool AwVulkanContextProvider::InitializeGrContext(
const GrContextOptions& context_options) {
// GrContext is created in Globals, so nothing to do here besides DCHECK.
DCHECK(globals_);
return globals_->gr_context.get() != nullptr;
}
void AwVulkanContextProvider::SecondaryCBDrawBegin(
sk_sp<GrVkSecondaryCBDrawContext> draw_context) {
DCHECK(draw_context);
......
......@@ -48,6 +48,7 @@ class AwVulkanContextProvider final : public viz::VulkanContextProvider {
AwDrawFn_InitVkParams* params);
// viz::VulkanContextProvider implementation:
bool InitializeGrContext(const GrContextOptions& context_options) override;
gpu::VulkanImplementation* GetVulkanImplementation() override;
gpu::VulkanDeviceQueue* GetDeviceQueue() override;
GrDirectContext* GetGrContext() override;
......
......@@ -12,6 +12,7 @@
#include "components/viz/common/viz_vulkan_context_provider_export.h"
#include "third_party/vulkan_headers/include/vulkan/vulkan.h"
struct GrContextOptions;
class GrDirectContext;
class GrVkSecondaryCBDrawContext;
......@@ -26,6 +27,7 @@ namespace viz {
class VIZ_VULKAN_CONTEXT_PROVIDER_EXPORT VulkanContextProvider
: public base::RefCountedThreadSafe<VulkanContextProvider> {
public:
virtual bool InitializeGrContext(const GrContextOptions& context_options) = 0;
virtual gpu::VulkanImplementation* GetVulkanImplementation() = 0;
virtual gpu::VulkanDeviceQueue* GetDeviceQueue() = 0;
virtual GrDirectContext* GetGrContext() = 0;
......
......@@ -23,11 +23,10 @@ namespace viz {
scoped_refptr<VulkanInProcessContextProvider>
VulkanInProcessContextProvider::Create(
gpu::VulkanImplementation* vulkan_implementation,
const GrContextOptions& options,
const gpu::GPUInfo* gpu_info) {
scoped_refptr<VulkanInProcessContextProvider> context_provider(
new VulkanInProcessContextProvider(vulkan_implementation));
if (!context_provider->Initialize(options, gpu_info))
if (!context_provider->Initialize(gpu_info))
return nullptr;
return context_provider;
}
......@@ -41,7 +40,6 @@ VulkanInProcessContextProvider::~VulkanInProcessContextProvider() {
}
bool VulkanInProcessContextProvider::Initialize(
const GrContextOptions& context_options,
const gpu::GPUInfo* gpu_info) {
DCHECK(!device_queue_);
......@@ -64,6 +62,11 @@ bool VulkanInProcessContextProvider::Initialize(
if (!device_queue_)
return false;
return true;
}
bool VulkanInProcessContextProvider::InitializeGrContext(
const GrContextOptions& context_options) {
GrVkBackendContext backend_context;
backend_context.fInstance = device_queue_->GetVulkanInstance();
backend_context.fPhysicalDevice = device_queue_->GetVulkanPhysicalDevice();
......@@ -86,6 +89,10 @@ bool VulkanInProcessContextProvider::Initialize(
return vkGetInstanceProcAddr(instance, proc_name);
};
const auto& instance_extensions = vulkan_implementation_->GetVulkanInstance()
->vulkan_info()
.enabled_instance_extensions;
std::vector<const char*> device_extensions;
device_extensions.reserve(device_queue_->enabled_extensions().size());
for (const auto& extension : device_queue_->enabled_extensions())
......
......@@ -30,12 +30,12 @@ class VIZ_VULKAN_CONTEXT_PROVIDER_EXPORT VulkanInProcessContextProvider
public:
static scoped_refptr<VulkanInProcessContextProvider> Create(
gpu::VulkanImplementation* vulkan_implementation,
const GrContextOptions& context_options = GrContextOptions(),
const gpu::GPUInfo* gpu_info = nullptr);
void Destroy();
// VulkanContextProvider implementation
bool InitializeGrContext(const GrContextOptions& context_options) override;
gpu::VulkanImplementation* GetVulkanImplementation() override;
gpu::VulkanDeviceQueue* GetDeviceQueue() override;
GrDirectContext* GetGrContext() override;
......@@ -49,8 +49,7 @@ class VIZ_VULKAN_CONTEXT_PROVIDER_EXPORT VulkanInProcessContextProvider
gpu::VulkanImplementation* vulkan_implementation);
~VulkanInProcessContextProvider() override;
bool Initialize(const GrContextOptions& context_options,
const gpu::GPUInfo* gpu_info);
bool Initialize(const gpu::GPUInfo* gpu_info);
#if BUILDFLAG(ENABLE_VULKAN)
sk_sp<GrDirectContext> gr_context_;
......
......@@ -369,7 +369,7 @@ GpuServiceImpl::GpuServiceImpl(
// If GL is using a real GPU, the gpu_info will be passed in and vulkan will
// use the same GPU.
vulkan_context_provider_ = VulkanInProcessContextProvider::Create(
vulkan_implementation_, context_options,
vulkan_implementation_,
(is_native_vulkan && is_native_gl) ? &gpu_info : nullptr);
if (vulkan_context_provider_) {
// If Vulkan is supported, then OOP-R is supported.
......
......@@ -17,6 +17,7 @@
#include "gpu/command_buffer/service/service_utils.h"
#include "gpu/command_buffer/service/skia_utils.h"
#include "gpu/config/gpu_driver_bug_workarounds.h"
#include "gpu/config/gpu_finch_features.h"
#include "gpu/config/skia_limits.h"
#include "gpu/vulkan/buildflags.h"
#include "skia/buildflags.h"
......@@ -33,10 +34,6 @@
#include "gpu/vulkan/vulkan_device_queue.h"
#endif
#if defined(OS_ANDROID)
#include "gpu/config/gpu_finch_features.h"
#endif
#if defined(OS_FUCHSIA)
#include "gpu/vulkan/fuchsia/vulkan_fuchsia_ext.h"
#endif
......@@ -178,12 +175,10 @@ SharedContextState::SharedContextState(
case GrContextType::kVulkan:
if (vk_context_provider_) {
#if BUILDFLAG(ENABLE_VULKAN)
gr_context_ = vk_context_provider_->GetGrContext();
external_semaphore_pool_ =
std::make_unique<ExternalSemaphorePool>(this);
#endif
use_virtualized_gl_contexts_ = false;
DCHECK(gr_context_);
}
break;
case GrContextType::kMetal:
......@@ -271,6 +266,16 @@ bool SharedContextState::InitializeGrContext(
DetermineGrCacheLimitsFromAvailableMemory(&max_resource_cache_bytes,
&glyph_cache_max_texture_bytes);
// If you make any changes to the GrContext::Options here that could
// affect text rendering, make sure to match the capabilities initialized
// in GetCapabilities and ensuring these are also used by the
// PaintOpBufferSerializer.
GrContextOptions options = GetDefaultGrContextOptions(gr_context_type_);
options.fPersistentCache = cache;
options.fShaderErrorHandler = this;
if (gpu_preferences.force_max_texture_size)
options.fMaxTextureSizeOverride = gpu_preferences.force_max_texture_size;
if (gr_context_type_ == GrContextType::kGL) {
DCHECK(context_->IsCurrent(nullptr));
bool use_version_es2 = false;
......@@ -296,25 +301,32 @@ bool SharedContextState::InitializeGrContext(
glProgramBinary(program, binaryFormat, binary, length);
};
}
// If you make any changes to the GrContext::Options here that could
// affect text rendering, make sure to match the capabilities initialized
// in GetCapabilities and ensuring these are also used by the
// PaintOpBufferSerializer.
GrContextOptions options = GetDefaultGrContextOptions(GrContextType::kGL);
options.fDriverBugWorkarounds =
GrDriverBugWorkarounds(workarounds.ToIntSet());
options.fPersistentCache = cache;
options.fAvoidStencilBuffers = workarounds.avoid_stencil_buffers;
if (workarounds.disable_program_disk_cache) {
options.fShaderCacheStrategy =
GrContextOptions::ShaderCacheStrategy::kBackendSource;
}
options.fShaderErrorHandler = this;
if (gpu_preferences.force_max_texture_size)
options.fMaxTextureSizeOverride = gpu_preferences.force_max_texture_size;
options.fPreferExternalImagesOverES3 = true;
owned_gr_context_ = GrDirectContext::MakeGL(std::move(interface), options);
gr_context_ = owned_gr_context_.get();
} else if (gr_context_type_ == GrContextType::kVulkan) {
#if BUILDFLAG(ENABLE_VULKAN)
if (vk_context_provider_) {
// TODO(vasilyt): Remove this if there is no problem with caching.
if (!base::FeatureList::IsEnabled(
features::kEnableGrShaderCacheForVulkan))
options.fPersistentCache = nullptr;
if (!vk_context_provider_->InitializeGrContext(options)) {
LOG(ERROR) << "Failed to initialize GrContext for Vulkan.";
return false;
}
gr_context_ = vk_context_provider_->GetGrContext();
DCHECK(gr_context_);
}
#endif
}
if (!gr_context_) {
......
......@@ -123,6 +123,10 @@ const base::Feature kSkiaDawn{"SkiaDawn", base::FEATURE_DISABLED_BY_DEFAULT};
const base::Feature kEnableSharedImageForWebview{
"EnableSharedImageForWebview", base::FEATURE_ENABLED_BY_DEFAULT};
// Enable GrShaderCache to use with Vulkan backend.
const base::Feature kEnableGrShaderCacheForVulkan{
"EnableGrShaderCacheForVulkan", base::FEATURE_ENABLED_BY_DEFAULT};
bool IsUsingVulkan() {
bool enable = base::FeatureList::IsEnabled(kVulkan);
#if defined(OS_ANDROID)
......
......@@ -53,6 +53,8 @@ GPU_EXPORT extern const base::Feature kSkiaDawn;
GPU_EXPORT extern const base::Feature kEnableSharedImageForWebview;
GPU_EXPORT extern const base::Feature kEnableGrShaderCacheForVulkan;
GPU_EXPORT bool IsUsingVulkan();
#if defined(OS_ANDROID)
GPU_EXPORT bool IsAImageReaderEnabled();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment