Commit cfc3180d authored by Peng Huang's avatar Peng Huang Committed by Commit Bot

viz: Create Vulkan instance and Vulkan GrContext with --enable-vulkan

This CL will create Vulkan instance and Vulkan GrContext when
--enable-vulkan is specified. And SkiaOutputSurfaceImpl and
SkiaOutputSurfaceImplOnGpu will use the Vulkan GrContext to
renderer to replay the SkDDL.

Known issues:
 * RasterDecoder still produces GL textures, it should use the GrContext
from GpuServiceImpl.
 * Media still produce GL textures.
 * WebGL still produce GL textures.
 * Browser UI doesn't use RasterDecoder.


Bug: 838899
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I1026c70e0916d25a9878767336b106299b9dbce7
Reviewed-on: https://chromium-review.googlesource.com/1126166Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Peng Huang <penghuang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#575438}
parent 8c646e5a
...@@ -245,7 +245,8 @@ void PixelTest::SetUpGpuServiceOnGpuThread(base::WaitableEvent* event) { ...@@ -245,7 +245,8 @@ void PixelTest::SetUpGpuServiceOnGpuThread(base::WaitableEvent* event) {
gpu_service_ = std::make_unique<viz::GpuServiceImpl>( gpu_service_ = std::make_unique<viz::GpuServiceImpl>(
gpu::GPUInfo(), nullptr /* watchdog_thread */, io_thread_->task_runner(), gpu::GPUInfo(), nullptr /* watchdog_thread */, io_thread_->task_runner(),
gpu::GpuFeatureInfo(), gpu::GpuPreferences(), gpu::GPUInfo(), gpu::GpuFeatureInfo(), gpu::GpuPreferences(), gpu::GPUInfo(),
gpu::GpuFeatureInfo(), base::DoNothing() /* exit_callback */); gpu::GpuFeatureInfo(), nullptr /* vulkan_implementation */,
base::DoNothing() /* exit_callback */);
// Uses a null gpu_host here, because we don't want to receive any message. // Uses a null gpu_host here, because we don't want to receive any message.
std::unique_ptr<viz::mojom::GpuHost> gpu_host; std::unique_ptr<viz::mojom::GpuHost> gpu_host;
......
...@@ -22,6 +22,7 @@ include_rules = [ ...@@ -22,6 +22,7 @@ include_rules = [
"+gpu/config", "+gpu/config",
"+gpu/ipc", "+gpu/ipc",
"+gpu/skia_bindings", "+gpu/skia_bindings",
"+gpu/vulkan",
"+mojo/public/cpp/bindings", "+mojo/public/cpp/bindings",
"+mojo/public/cpp/system", "+mojo/public/cpp/system",
"+skia", "+skia",
......
...@@ -315,12 +315,31 @@ sk_sp<SkImage> SkiaOutputSurfaceImpl::MakePromiseSkImage( ...@@ -315,12 +315,31 @@ sk_sp<SkImage> SkiaOutputSurfaceImpl::MakePromiseSkImage(
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(recorder_); DCHECK(recorder_);
// Convert internal format from GLES2 to platform GL. if (!gpu_service_->is_using_vulkan()) {
const auto* version_info = impl_on_gpu_->gl_version_info(); // Convert internal format from GLES2 to platform GL.
metadata.backend_format = GrBackendFormat::MakeGL( const auto* version_info = impl_on_gpu_->gl_version_info();
gl::GetInternalFormat(version_info, metadata.backend_format = GrBackendFormat::MakeGL(
*metadata.backend_format.getGLFormat()), gl::GetInternalFormat(version_info,
*metadata.backend_format.getGLTarget()); *metadata.backend_format.getGLFormat()),
*metadata.backend_format.getGLTarget());
} else {
#if BUILDFLAG(ENABLE_VULKAN)
VkFormat format = VK_FORMAT_UNDEFINED;
switch (metadata.color_type) {
case kRGBA_8888_SkColorType:
format = VK_FORMAT_R8G8B8A8_UNORM;
break;
case kBGRA_8888_SkColorType:
format = VK_FORMAT_B8G8R8A8_UNORM;
break;
default:
NOTREACHED();
}
metadata.backend_format = GrBackendFormat::MakeVk(format);
#else
NOTREACHED();
#endif
}
DCHECK(!metadata.mailbox.IsZero()); DCHECK(!metadata.mailbox.IsZero());
resource_sync_tokens_.push_back(metadata.sync_token); resource_sync_tokens_.push_back(metadata.sync_token);
...@@ -343,10 +362,19 @@ sk_sp<SkImage> SkiaOutputSurfaceImpl::MakePromiseSkImageFromYUV( ...@@ -343,10 +362,19 @@ sk_sp<SkImage> SkiaOutputSurfaceImpl::MakePromiseSkImageFromYUV(
// supported by Skia. // supported by Skia.
YUVResourceMetadata yuv_metadata(std::move(metadatas), yuv_color_space); YUVResourceMetadata yuv_metadata(std::move(metadatas), yuv_color_space);
// Convert internal format from GLES2 to platform GL. GrBackendFormat backend_format;
const auto* version_info = impl_on_gpu_->gl_version_info(); if (!gpu_service_->is_using_vulkan()) {
auto backend_format = GrBackendFormat::MakeGL( // Convert internal format from GLES2 to platform GL.
gl::GetInternalFormat(version_info, GL_BGRA8_EXT), GL_TEXTURE_2D); const auto* version_info = impl_on_gpu_->gl_version_info();
backend_format = GrBackendFormat::MakeGL(
gl::GetInternalFormat(version_info, GL_BGRA8_EXT), GL_TEXTURE_2D);
} else {
#if BUILDFLAG(ENABLE_VULKAN)
backend_format = GrBackendFormat::MakeVk(VK_FORMAT_B8G8R8A8_UNORM);
#else
NOTREACHED();
#endif
}
return PromiseTextureHelper<YUVResourceMetadata>::MakePromiseSkImage( return PromiseTextureHelper<YUVResourceMetadata>::MakePromiseSkImage(
this, &recorder_.value(), backend_format, yuv_metadata.size(), this, &recorder_.value(), backend_format, yuv_metadata.size(),
...@@ -393,11 +421,21 @@ SkCanvas* SkiaOutputSurfaceImpl::BeginPaintRenderPass( ...@@ -393,11 +421,21 @@ SkCanvas* SkiaOutputSurfaceImpl::BeginPaintRenderPass(
// TODO(penghuang): Figure out how to choose the right size. // TODO(penghuang): Figure out how to choose the right size.
constexpr size_t kCacheMaxResourceBytes = 90 * 1024 * 1024; constexpr size_t kCacheMaxResourceBytes = 90 * 1024 * 1024;
const auto* version_info = impl_on_gpu_->gl_version_info();
unsigned int texture_storage_format = TextureStorageFormat(format); GrBackendFormat backend_format;
auto backend_format = GrBackendFormat::MakeGL( if (!gpu_service_->is_using_vulkan()) {
gl::GetInternalFormat(version_info, texture_storage_format), const auto* version_info = impl_on_gpu_->gl_version_info();
GL_TEXTURE_2D); unsigned int texture_storage_format = TextureStorageFormat(format);
backend_format = GrBackendFormat::MakeGL(
gl::GetInternalFormat(version_info, texture_storage_format),
GL_TEXTURE_2D);
} else {
#if BUILDFLAG(ENABLE_VULKAN)
backend_format = GrBackendFormat::MakeVk(VK_FORMAT_B8G8R8A8_UNORM);
#else
NOTREACHED();
#endif
}
auto characterization = gr_context_thread_safe->createCharacterization( auto characterization = gr_context_thread_safe->createCharacterization(
kCacheMaxResourceBytes, image_info, backend_format, msaa_sample_count, kCacheMaxResourceBytes, image_info, backend_format, msaa_sample_count,
kTopLeft_GrSurfaceOrigin, surface_props, mipmap); kTopLeft_GrSurfaceOrigin, surface_props, mipmap);
...@@ -441,14 +479,25 @@ sk_sp<SkImage> SkiaOutputSurfaceImpl::MakePromiseSkImageFromRenderPass( ...@@ -441,14 +479,25 @@ sk_sp<SkImage> SkiaOutputSurfaceImpl::MakePromiseSkImageFromRenderPass(
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(recorder_); DCHECK(recorder_);
// Convert internal format from GLES2 to platform GL. SkColorType color_type = kBGRA_8888_SkColorType;
const auto* version_info = impl_on_gpu_->gl_version_info(); GrBackendFormat backend_format;
unsigned int texture_storage_format = TextureStorageFormat(format);
auto backend_format = GrBackendFormat::MakeGL( if (!gpu_service_->is_using_vulkan()) {
gl::GetInternalFormat(version_info, texture_storage_format), // Convert internal format from GLES2 to platform GL.
GL_TEXTURE_2D); const auto* version_info = impl_on_gpu_->gl_version_info();
SkColorType color_type = unsigned int texture_storage_format = TextureStorageFormat(format);
ResourceFormatToClosestSkColorType(true /*gpu_compositing */, format); backend_format = GrBackendFormat::MakeGL(
gl::GetInternalFormat(version_info, texture_storage_format),
GL_TEXTURE_2D);
color_type =
ResourceFormatToClosestSkColorType(true /*gpu_compositing */, format);
} else {
#if BUILDFLAG(ENABLE_VULKAN)
backend_format = GrBackendFormat::MakeVk(VK_FORMAT_B8G8R8A8_UNORM);
#else
NOTREACHED();
#endif
}
return PromiseTextureHelper<RenderPassId>::MakePromiseSkImage( return PromiseTextureHelper<RenderPassId>::MakePromiseSkImage(
this, &recorder_.value(), backend_format, size, this, &recorder_.value(), backend_format, size,
mipmap ? GrMipMapped::kYes : GrMipMapped::kNo, kTopLeft_GrSurfaceOrigin, mipmap ? GrMipMapped::kYes : GrMipMapped::kNo, kTopLeft_GrSurfaceOrigin,
......
...@@ -31,6 +31,10 @@ class GLSurface; ...@@ -31,6 +31,10 @@ class GLSurface;
namespace gpu { namespace gpu {
class SyncPointClientState; class SyncPointClientState;
#if BUILDFLAG(ENABLE_VULKAN)
class VulkanSurface;
#endif
} }
namespace viz { namespace viz {
...@@ -140,6 +144,9 @@ class SkiaOutputSurfaceImplOnGpu : public gpu::ImageTransportSurfaceDelegate { ...@@ -140,6 +144,9 @@ class SkiaOutputSurfaceImplOnGpu : public gpu::ImageTransportSurfaceDelegate {
void AddFilter(IPC::MessageFilter* message_filter) override; void AddFilter(IPC::MessageFilter* message_filter) override;
int32_t GetRouteID() const override; int32_t GetRouteID() const override;
void InitializeForGL();
void InitializeForVulkan();
void BindOrCopyTextureIfNecessary(gpu::TextureBase* texture_base); void BindOrCopyTextureIfNecessary(gpu::TextureBase* texture_base);
void PreprocessYUVResources( void PreprocessYUVResources(
std::vector<YUVResourceMetadata*> yuv_resource_metadatas); std::vector<YUVResourceMetadata*> yuv_resource_metadatas);
...@@ -147,6 +154,8 @@ class SkiaOutputSurfaceImplOnGpu : public gpu::ImageTransportSurfaceDelegate { ...@@ -147,6 +154,8 @@ class SkiaOutputSurfaceImplOnGpu : public gpu::ImageTransportSurfaceDelegate {
// Generage the next swap ID and push it to our pending swap ID queues. // Generage the next swap ID and push it to our pending swap ID queues.
void OnSwapBuffers(); void OnSwapBuffers();
void CreateSkSurfaceForVulkan(const gfx::Size& size);
const gpu::CommandBufferId command_buffer_id_; const gpu::CommandBufferId command_buffer_id_;
GpuServiceImpl* const gpu_service_; GpuServiceImpl* const gpu_service_;
const gpu::SurfaceHandle surface_handle_; const gpu::SurfaceHandle surface_handle_;
...@@ -154,13 +163,17 @@ class SkiaOutputSurfaceImplOnGpu : public gpu::ImageTransportSurfaceDelegate { ...@@ -154,13 +163,17 @@ class SkiaOutputSurfaceImplOnGpu : public gpu::ImageTransportSurfaceDelegate {
BufferPresentedCallback buffer_presented_callback_; BufferPresentedCallback buffer_presented_callback_;
scoped_refptr<gpu::SyncPointClientState> sync_point_client_state_; scoped_refptr<gpu::SyncPointClientState> sync_point_client_state_;
gpu::GpuPreferences gpu_preferences_; gpu::GpuPreferences gpu_preferences_;
scoped_refptr<gl::GLSurface> surface_; scoped_refptr<gl::GLSurface> gl_surface_;
sk_sp<SkSurface> sk_surface_; sk_sp<SkSurface> sk_surface_;
GrContext* gr_context_ = nullptr; GrContext* gr_context_ = nullptr;
scoped_refptr<gl::GLContext> gl_context_; scoped_refptr<gl::GLContext> gl_context_;
const gl::GLVersionInfo* gl_version_info_ = nullptr; const gl::GLVersionInfo* gl_version_info_ = nullptr;
OutputSurface::Capabilities capabilities_; OutputSurface::Capabilities capabilities_;
#if BUILDFLAG(ENABLE_VULKAN)
std::unique_ptr<gpu::VulkanSurface> vulkan_surface_;
#endif
// Offscreen surfaces for render passes. It can only be accessed on GPU // Offscreen surfaces for render passes. It can only be accessed on GPU
// thread. // thread.
base::flat_map<RenderPassId, sk_sp<SkSurface>> offscreen_surfaces_; base::flat_map<RenderPassId, sk_sp<SkSurface>> offscreen_surfaces_;
......
...@@ -8,6 +8,7 @@ include_rules = [ ...@@ -8,6 +8,7 @@ include_rules = [
"+gpu/ipc", "+gpu/ipc",
"+gpu/ipc/common", "+gpu/ipc/common",
"+gpu/ipc/service", "+gpu/ipc/service",
"+gpu/vulkan",
"+ipc", "+ipc",
"+media/gpu", "+media/gpu",
"+media/mojo", "+media/mojo",
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "components/crash/core/common/crash_key.h" #include "components/crash/core/common/crash_key.h"
#include "components/viz/common/gpu/vulkan_context_provider.h"
#include "components/viz/common/gpu/vulkan_in_process_context_provider.h"
#include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h"
#include "gpu/command_buffer/service/gpu_switches.h" #include "gpu/command_buffer/service/gpu_switches.h"
#include "gpu/command_buffer/service/scheduler.h" #include "gpu/command_buffer/service/scheduler.h"
...@@ -33,6 +35,7 @@ ...@@ -33,6 +35,7 @@
#include "gpu/ipc/service/gpu_channel_manager.h" #include "gpu/ipc/service/gpu_channel_manager.h"
#include "gpu/ipc/service/gpu_memory_buffer_factory.h" #include "gpu/ipc/service/gpu_memory_buffer_factory.h"
#include "gpu/ipc/service/gpu_watchdog_thread.h" #include "gpu/ipc/service/gpu_watchdog_thread.h"
#include "gpu/vulkan/buildflags.h"
#include "ipc/ipc_channel_handle.h" #include "ipc/ipc_channel_handle.h"
#include "ipc/ipc_sync_channel.h" #include "ipc/ipc_sync_channel.h"
#include "ipc/ipc_sync_message_filter.h" #include "ipc/ipc_sync_message_filter.h"
...@@ -135,6 +138,7 @@ GpuServiceImpl::GpuServiceImpl( ...@@ -135,6 +138,7 @@ GpuServiceImpl::GpuServiceImpl(
const base::Optional<gpu::GPUInfo>& gpu_info_for_hardware_gpu, const base::Optional<gpu::GPUInfo>& gpu_info_for_hardware_gpu,
const base::Optional<gpu::GpuFeatureInfo>& const base::Optional<gpu::GpuFeatureInfo>&
gpu_feature_info_for_hardware_gpu, gpu_feature_info_for_hardware_gpu,
gpu::VulkanImplementation* vulkan_implementation,
base::OnceClosure exit_callback) base::OnceClosure exit_callback)
: main_runner_(base::ThreadTaskRunnerHandle::Get()), : main_runner_(base::ThreadTaskRunnerHandle::Get()),
io_runner_(std::move(io_runner)), io_runner_(std::move(io_runner)),
...@@ -146,6 +150,9 @@ GpuServiceImpl::GpuServiceImpl( ...@@ -146,6 +150,9 @@ GpuServiceImpl::GpuServiceImpl(
gpu_feature_info_(gpu_feature_info), gpu_feature_info_(gpu_feature_info),
gpu_info_for_hardware_gpu_(gpu_info_for_hardware_gpu), gpu_info_for_hardware_gpu_(gpu_info_for_hardware_gpu),
gpu_feature_info_for_hardware_gpu_(gpu_feature_info_for_hardware_gpu), gpu_feature_info_for_hardware_gpu_(gpu_feature_info_for_hardware_gpu),
#if BUILDFLAG(ENABLE_VULKAN)
vulkan_implementation_(vulkan_implementation),
#endif
exit_callback_(std::move(exit_callback)), exit_callback_(std::move(exit_callback)),
bindings_(std::make_unique<mojo::BindingSet<mojom::GpuService>>()), bindings_(std::make_unique<mojo::BindingSet<mojom::GpuService>>()),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
...@@ -153,6 +160,16 @@ GpuServiceImpl::GpuServiceImpl( ...@@ -153,6 +160,16 @@ GpuServiceImpl::GpuServiceImpl(
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
protected_buffer_manager_ = new arc::ProtectedBufferManager(); protected_buffer_manager_ = new arc::ProtectedBufferManager();
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
#if BUILDFLAG(ENABLE_VULKAN)
if (vulkan_implementation_) {
vulkan_context_provider_ =
VulkanInProcessContextProvider::Create(vulkan_implementation_);
if (!vulkan_context_provider_)
DLOG(WARNING) << "Failed to create Vulkan context provider.";
}
#endif
weak_ptr_ = weak_ptr_factory_.GetWeakPtr(); weak_ptr_ = weak_ptr_factory_.GetWeakPtr();
} }
...@@ -293,6 +310,7 @@ bool GpuServiceImpl::GetGrContextForGLSurface(gl::GLSurface* surface, ...@@ -293,6 +310,7 @@ bool GpuServiceImpl::GetGrContextForGLSurface(gl::GLSurface* surface,
GrContext** gr_context, GrContext** gr_context,
gl::GLContext** gl_context) { gl::GLContext** gl_context) {
DCHECK(main_runner_->BelongsToCurrentThread()); DCHECK(main_runner_->BelongsToCurrentThread());
DCHECK(!is_using_vulkan());
DCHECK(surface); DCHECK(surface);
DCHECK(gr_context && !*gr_context); DCHECK(gr_context && !*gr_context);
DCHECK(gl_context && !*gl_context); DCHECK(gl_context && !*gl_context);
...@@ -328,6 +346,17 @@ bool GpuServiceImpl::GetGrContextForGLSurface(gl::GLSurface* surface, ...@@ -328,6 +346,17 @@ bool GpuServiceImpl::GetGrContextForGLSurface(gl::GLSurface* surface,
return !!gr_context; return !!gr_context;
} }
GrContext* GpuServiceImpl::GetGrContextForVulkan() {
DCHECK(main_runner_->BelongsToCurrentThread());
DCHECK(is_using_vulkan());
#if BUILDFLAG(ENABLE_VULKAN)
return vulkan_context_provider_->GetGrContext();
#else
NOTREACHED();
return nullptr;
#endif
}
gpu::ImageFactory* GpuServiceImpl::gpu_image_factory() { gpu::ImageFactory* GpuServiceImpl::gpu_image_factory() {
return gpu_memory_buffer_factory_ return gpu_memory_buffer_factory_
? gpu_memory_buffer_factory_->AsImageFactory() ? gpu_memory_buffer_factory_->AsImageFactory()
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "gpu/ipc/service/gpu_channel_manager_delegate.h" #include "gpu/ipc/service/gpu_channel_manager_delegate.h"
#include "gpu/ipc/service/gpu_config.h" #include "gpu/ipc/service/gpu_config.h"
#include "gpu/ipc/service/x_util.h" #include "gpu/ipc/service/x_util.h"
#include "gpu/vulkan/buildflags.h"
#include "mojo/public/cpp/bindings/binding_set.h" #include "mojo/public/cpp/bindings/binding_set.h"
#include "services/viz/privileged/interfaces/gl/gpu_host.mojom.h" #include "services/viz/privileged/interfaces/gl/gpu_host.mojom.h"
#include "services/viz/privileged/interfaces/gl/gpu_service.mojom.h" #include "services/viz/privileged/interfaces/gl/gpu_service.mojom.h"
...@@ -44,6 +45,7 @@ class GpuMemoryBufferFactory; ...@@ -44,6 +45,7 @@ class GpuMemoryBufferFactory;
class GpuWatchdogThread; class GpuWatchdogThread;
class Scheduler; class Scheduler;
class SyncPointManager; class SyncPointManager;
class VulkanImplementation;
} // namespace gpu } // namespace gpu
namespace media { namespace media {
...@@ -52,6 +54,8 @@ class MediaGpuChannelManager; ...@@ -52,6 +54,8 @@ class MediaGpuChannelManager;
namespace viz { namespace viz {
class VulkanContextProvider;
// This runs in the GPU process, and communicates with the gpu host (which is // This runs in the GPU process, and communicates with the gpu host (which is
// the window server) over the mojom APIs. This is responsible for setting up // the window server) over the mojom APIs. This is responsible for setting up
// the connection to clients, allocating/free'ing gpu memory etc. // the connection to clients, allocating/free'ing gpu memory etc.
...@@ -66,6 +70,7 @@ class VIZ_SERVICE_EXPORT GpuServiceImpl : public gpu::GpuChannelManagerDelegate, ...@@ -66,6 +70,7 @@ class VIZ_SERVICE_EXPORT GpuServiceImpl : public gpu::GpuChannelManagerDelegate,
const base::Optional<gpu::GPUInfo>& gpu_info_for_hardware_gpu, const base::Optional<gpu::GPUInfo>& gpu_info_for_hardware_gpu,
const base::Optional<gpu::GpuFeatureInfo>& const base::Optional<gpu::GpuFeatureInfo>&
gpu_feature_info_for_hardware_gpu, gpu_feature_info_for_hardware_gpu,
gpu::VulkanImplementation* vulkan_implementation,
base::OnceClosure exit_callback); base::OnceClosure exit_callback);
~GpuServiceImpl() override; ~GpuServiceImpl() override;
...@@ -83,6 +88,8 @@ class VIZ_SERVICE_EXPORT GpuServiceImpl : public gpu::GpuChannelManagerDelegate, ...@@ -83,6 +88,8 @@ class VIZ_SERVICE_EXPORT GpuServiceImpl : public gpu::GpuChannelManagerDelegate,
GrContext** gr_context, GrContext** gr_context,
gl::GLContext** gl_context); gl::GLContext** gl_context);
GrContext* GetGrContextForVulkan();
// Notifies the GpuHost to stop using GPU compositing. This should be called // Notifies the GpuHost to stop using GPU compositing. This should be called
// in response to an error in the GPU process that occurred after // in response to an error in the GPU process that occurred after
// InitializeWithHost() was called, otherwise GpuFeatureInfo should be set // InitializeWithHost() was called, otherwise GpuFeatureInfo should be set
...@@ -134,6 +141,16 @@ class VIZ_SERVICE_EXPORT GpuServiceImpl : public gpu::GpuChannelManagerDelegate, ...@@ -134,6 +141,16 @@ class VIZ_SERVICE_EXPORT GpuServiceImpl : public gpu::GpuChannelManagerDelegate,
return skia_output_surface_sequence_id_; return skia_output_surface_sequence_id_;
} }
#if BUILDFLAG(ENABLE_VULKAN)
bool is_using_vulkan() const { return !!vulkan_context_provider_; }
VulkanContextProvider* vulkan_context_provider() {
return vulkan_context_provider_.get();
}
#else
bool is_using_vulkan() const { return false; }
VulkanContextProvider* vulkan_context_provider() { return nullptr; }
#endif
void set_oopd_enabled() { oopd_enabled_ = true; } void set_oopd_enabled() { oopd_enabled_ = true; }
private: private:
...@@ -267,6 +284,11 @@ class VIZ_SERVICE_EXPORT GpuServiceImpl : public gpu::GpuChannelManagerDelegate, ...@@ -267,6 +284,11 @@ class VIZ_SERVICE_EXPORT GpuServiceImpl : public gpu::GpuChannelManagerDelegate,
struct GrContextAndGLContext; struct GrContextAndGLContext;
base::flat_map<unsigned long, GrContextAndGLContext> contexts_for_gl_; base::flat_map<unsigned long, GrContextAndGLContext> contexts_for_gl_;
#if BUILDFLAG(ENABLE_VULKAN)
gpu::VulkanImplementation* vulkan_implementation_;
scoped_refptr<VulkanContextProvider> vulkan_context_provider_;
#endif
// An event that will be signalled when we shutdown. On some platforms it // An event that will be signalled when we shutdown. On some platforms it
// comes from external sources. // comes from external sources.
std::unique_ptr<base::WaitableEvent> owned_shutdown_event_; std::unique_ptr<base::WaitableEvent> owned_shutdown_event_;
......
...@@ -50,9 +50,10 @@ class GpuServiceTest : public testing::Test { ...@@ -50,9 +50,10 @@ class GpuServiceTest : public testing::Test {
void SetUp() override { void SetUp() override {
ASSERT_TRUE(io_thread_.Start()); ASSERT_TRUE(io_thread_.Start());
gpu_service_ = std::make_unique<GpuServiceImpl>( gpu_service_ = std::make_unique<GpuServiceImpl>(
gpu::GPUInfo(), /*watchdog_thread=*/nullptr, io_thread_.task_runner(), gpu::GPUInfo(), nullptr /* watchdog_thread */, io_thread_.task_runner(),
gpu::GpuFeatureInfo(), gpu::GpuPreferences(), gpu::GPUInfo(), gpu::GpuFeatureInfo(), gpu::GpuPreferences(), gpu::GPUInfo(),
gpu::GpuFeatureInfo(), /*exit_callback=*/base::DoNothing()); gpu::GpuFeatureInfo(), nullptr /* vulkan_implementation */,
base::DoNothing() /* exit_callback */);
} }
void TearDown() override { void TearDown() override {
......
...@@ -170,7 +170,8 @@ VizMainImpl::VizMainImpl(Delegate* delegate, ...@@ -170,7 +170,8 @@ VizMainImpl::VizMainImpl(Delegate* delegate,
gpu_init_->gpu_info(), gpu_init_->TakeWatchdogThread(), io_task_runner(), gpu_init_->gpu_info(), gpu_init_->TakeWatchdogThread(), io_task_runner(),
gpu_init_->gpu_feature_info(), gpu_init_->gpu_preferences(), gpu_init_->gpu_feature_info(), gpu_init_->gpu_preferences(),
gpu_init_->gpu_info_for_hardware_gpu(), gpu_init_->gpu_info_for_hardware_gpu(),
gpu_init_->gpu_feature_info_for_hardware_gpu(), std::move(exit_callback)); gpu_init_->gpu_feature_info_for_hardware_gpu(),
gpu_init_->vulkan_implementation(), std::move(exit_callback));
if (dependencies_.create_display_compositor) if (dependencies_.create_display_compositor)
gpu_service_->set_oopd_enabled(); gpu_service_->set_oopd_enabled();
} }
......
...@@ -95,6 +95,9 @@ const gpu::GpuPreferences GetGpuPreferencesFromCommandLine() { ...@@ -95,6 +95,9 @@ const gpu::GpuPreferences GetGpuPreferencesFromCommandLine() {
gpu_preferences.disable_oop_rasterization = gpu_preferences.disable_oop_rasterization =
command_line->HasSwitch(switches::kDisableOopRasterization); command_line->HasSwitch(switches::kDisableOopRasterization);
gpu_preferences.enable_vulkan =
command_line->HasSwitch(switches::kEnableVulkan);
// Some of these preferences are set or adjusted in // Some of these preferences are set or adjusted in
// GpuDataManagerImplPrivate::AppendGpuCommandLine. // GpuDataManagerImplPrivate::AppendGpuCommandLine.
return gpu_preferences; return gpu_preferences;
......
...@@ -204,6 +204,9 @@ struct GPU_EXPORT GpuPreferences { ...@@ -204,6 +204,9 @@ struct GPU_EXPORT GpuPreferences {
// send a background/suspend signal. // send a background/suspend signal.
bool watchdog_starts_backgrounded = false; bool watchdog_starts_backgrounded = false;
// Use Vulkan for rasterization and display compositing.
bool enable_vulkan = false;
// Please update gpu_preferences_unittest.cc when making additions or // Please update gpu_preferences_unittest.cc when making additions or
// changes to this struct. // changes to this struct.
}; };
......
...@@ -74,6 +74,7 @@ void CheckGpuPreferencesEqual(GpuPreferences left, GpuPreferences right) { ...@@ -74,6 +74,7 @@ void CheckGpuPreferencesEqual(GpuPreferences left, GpuPreferences right) {
right.use_gpu_fences_for_overlay_planes); right.use_gpu_fences_for_overlay_planes);
EXPECT_EQ(left.watchdog_starts_backgrounded, EXPECT_EQ(left.watchdog_starts_backgrounded,
right.watchdog_starts_backgrounded); right.watchdog_starts_backgrounded);
EXPECT_EQ(left.enable_vulkan, right.enable_vulkan);
} }
} // namespace } // namespace
...@@ -150,6 +151,7 @@ TEST(GpuPreferencesTest, EncodeDecode) { ...@@ -150,6 +151,7 @@ TEST(GpuPreferencesTest, EncodeDecode) {
GPU_PREFERENCES_FIELD(disable_oop_rasterization, true) GPU_PREFERENCES_FIELD(disable_oop_rasterization, true)
GPU_PREFERENCES_FIELD(use_gpu_fences_for_overlay_planes, true) GPU_PREFERENCES_FIELD(use_gpu_fences_for_overlay_planes, true)
GPU_PREFERENCES_FIELD(watchdog_starts_backgrounded, true) GPU_PREFERENCES_FIELD(watchdog_starts_backgrounded, true)
GPU_PREFERENCES_FIELD(enable_vulkan, true)
input_prefs.texture_target_exception_list.emplace_back( input_prefs.texture_target_exception_list.emplace_back(
gfx::BufferUsage::SCANOUT, gfx::BufferFormat::RGBA_8888); gfx::BufferUsage::SCANOUT, gfx::BufferFormat::RGBA_8888);
......
...@@ -64,4 +64,5 @@ struct GpuPreferences { ...@@ -64,4 +64,5 @@ struct GpuPreferences {
bool disable_oop_rasterization; bool disable_oop_rasterization;
bool use_gpu_fences_for_overlay_planes; bool use_gpu_fences_for_overlay_planes;
bool watchdog_starts_backgrounded; bool watchdog_starts_backgrounded;
bool enable_vulkan;
}; };
...@@ -121,6 +121,7 @@ struct StructTraits<gpu::mojom::GpuPreferencesDataView, gpu::GpuPreferences> { ...@@ -121,6 +121,7 @@ struct StructTraits<gpu::mojom::GpuPreferencesDataView, gpu::GpuPreferences> {
out->use_gpu_fences_for_overlay_planes = out->use_gpu_fences_for_overlay_planes =
prefs.use_gpu_fences_for_overlay_planes(); prefs.use_gpu_fences_for_overlay_planes();
out->watchdog_starts_backgrounded = prefs.watchdog_starts_backgrounded(); out->watchdog_starts_backgrounded = prefs.watchdog_starts_backgrounded();
out->enable_vulkan = prefs.enable_vulkan();
return true; return true;
} }
...@@ -261,6 +262,9 @@ struct StructTraits<gpu::mojom::GpuPreferencesDataView, gpu::GpuPreferences> { ...@@ -261,6 +262,9 @@ struct StructTraits<gpu::mojom::GpuPreferencesDataView, gpu::GpuPreferences> {
static bool watchdog_starts_backgrounded(const gpu::GpuPreferences& prefs) { static bool watchdog_starts_backgrounded(const gpu::GpuPreferences& prefs) {
return prefs.watchdog_starts_backgrounded; return prefs.watchdog_starts_backgrounded;
} }
static bool enable_vulkan(const gpu::GpuPreferences& prefs) {
return prefs.enable_vulkan;
}
}; };
} // namespace mojo } // namespace mojo
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
import("//testing/test.gni") import("//testing/test.gni")
import("//build/config/ui.gni") import("//build/config/ui.gni")
import("//gpu/vulkan/features.gni")
if (is_mac) { if (is_mac) {
import("//build/config/mac/mac_sdk.gni") import("//build/config/mac/mac_sdk.gni")
} }
...@@ -64,6 +65,7 @@ component("service") { ...@@ -64,6 +65,7 @@ component("service") {
"//gpu/command_buffer/service:gles2", "//gpu/command_buffer/service:gles2",
"//gpu/config", "//gpu/config",
"//gpu/ipc/common", "//gpu/ipc/common",
"//gpu/vulkan:buildflags",
] ]
libs = [] libs = []
ldflags = [] ldflags = []
...@@ -129,6 +131,9 @@ component("service") { ...@@ -129,6 +131,9 @@ component("service") {
if (is_fuchsia) { if (is_fuchsia) {
sources += [ "image_transport_surface_fuchsia.cc" ] sources += [ "image_transport_surface_fuchsia.cc" ]
} }
if (enable_vulkan) {
deps += [ "//gpu/vulkan/init" ]
}
} }
source_set("test_support") { source_set("test_support") {
......
...@@ -38,6 +38,11 @@ ...@@ -38,6 +38,11 @@
#include "ui/gl/gl_surface_egl.h" #include "ui/gl/gl_surface_egl.h"
#endif #endif
#if BUILDFLAG(ENABLE_VULKAN)
#include "gpu/vulkan/init/vulkan_factory.h"
#include "gpu/vulkan/vulkan_implementation.h"
#endif
namespace gpu { namespace gpu {
namespace { namespace {
...@@ -172,6 +177,20 @@ bool GpuInit::InitializeAndStartSandbox(base::CommandLine* command_line, ...@@ -172,6 +177,20 @@ bool GpuInit::InitializeAndStartSandbox(base::CommandLine* command_line,
#endif // OS_WIN #endif // OS_WIN
} }
#if BUILDFLAG(ENABLE_VULKAN)
if (gpu_preferences_.enable_vulkan) {
vulkan_implementation_ = gpu::CreateVulkanImplementation();
if (!vulkan_implementation_ ||
!vulkan_implementation_->InitializeVulkanInstance()) {
DLOG(WARNING) << "Failed to create and initialize Vulkan implementation.";
vulkan_implementation_ = nullptr;
}
gpu_preferences_.enable_vulkan = !!vulkan_implementation_;
}
#else
gpu_preferences_.enable_vulkan = false;
#endif
sandbox_helper_->PreSandboxStartup(); sandbox_helper_->PreSandboxStartup();
bool attempted_startsandbox = false; bool attempted_startsandbox = false;
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "gpu/config/gpu_preferences.h" #include "gpu/config/gpu_preferences.h"
#include "gpu/ipc/service/gpu_ipc_service_export.h" #include "gpu/ipc/service/gpu_ipc_service_export.h"
#include "gpu/ipc/service/gpu_watchdog_thread.h" #include "gpu/ipc/service/gpu_watchdog_thread.h"
#include "gpu/vulkan/buildflags.h"
namespace base { namespace base {
class CommandLine; class CommandLine;
...@@ -19,6 +20,8 @@ class CommandLine; ...@@ -19,6 +20,8 @@ class CommandLine;
namespace gpu { namespace gpu {
class VulkanImplementation;
class GPU_IPC_SERVICE_EXPORT GpuSandboxHelper { class GPU_IPC_SERVICE_EXPORT GpuSandboxHelper {
public: public:
virtual ~GpuSandboxHelper() = default; virtual ~GpuSandboxHelper() = default;
...@@ -60,6 +63,13 @@ class GPU_IPC_SERVICE_EXPORT GpuInit { ...@@ -60,6 +63,13 @@ class GPU_IPC_SERVICE_EXPORT GpuInit {
return std::move(watchdog_thread_); return std::move(watchdog_thread_);
} }
bool init_successful() const { return init_successful_; } bool init_successful() const { return init_successful_; }
#if BUILDFLAG(ENABLE_VULKAN)
VulkanImplementation* vulkan_implementation() {
return vulkan_implementation_.get();
}
#else
VulkanImplementation* vulkan_implementation() { return nullptr; }
#endif
private: private:
GpuSandboxHelper* sandbox_helper_ = nullptr; GpuSandboxHelper* sandbox_helper_ = nullptr;
...@@ -74,6 +84,10 @@ class GPU_IPC_SERVICE_EXPORT GpuInit { ...@@ -74,6 +84,10 @@ class GPU_IPC_SERVICE_EXPORT GpuInit {
base::Optional<GPUInfo> gpu_info_for_hardware_gpu_; base::Optional<GPUInfo> gpu_info_for_hardware_gpu_;
base::Optional<GpuFeatureInfo> gpu_feature_info_for_hardware_gpu_; base::Optional<GpuFeatureInfo> gpu_feature_info_for_hardware_gpu_;
#if BUILDFLAG(ENABLE_VULKAN)
std::unique_ptr<VulkanImplementation> vulkan_implementation_;
#endif
void AdjustInfoToSwiftShader(); void AdjustInfoToSwiftShader();
DISALLOW_COPY_AND_ASSIGN(GpuInit); DISALLOW_COPY_AND_ASSIGN(GpuInit);
......
...@@ -56,6 +56,7 @@ TestGpuService::TestGpuService( ...@@ -56,6 +56,7 @@ TestGpuService::TestGpuService(
gpu::GpuPreferences(), gpu::GpuPreferences(),
base::nullopt, base::nullopt,
base::nullopt, base::nullopt,
nullptr /* vulkan_implementation */,
/*exit_callback=*/base::DoNothing()) {} /*exit_callback=*/base::DoNothing()) {}
} // namespace } // namespace
......
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