Commit 4df3f6e1 authored by Vikas Soni's avatar Vikas Soni Committed by Commit Bot

Add VulkanContextProvider to RasterDecoderContextState.

Add VulkanContextProvider to RasterDecoderContextState which is needed
to get VkDevice in shareable image. Refactor RasterDecoderContextState
class to have seperate constructors for Vulkan and GL.

Bug: 891060
Change-Id: I0ca7e657d33fdcfa62ab6465f7023a914610b7ce
Reviewed-on: https://chromium-review.googlesource.com/c/1312194
Commit-Queue: vikas soni <vikassoni@chromium.org>
Reviewed-by: default avatarEric Karl <ericrk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605146}
parent 819fcfd3
...@@ -257,8 +257,6 @@ void GpuServiceImpl::InitializeWithHost( ...@@ -257,8 +257,6 @@ void GpuServiceImpl::InitializeWithHost(
skia_output_surface_sequence_id_ = skia_output_surface_sequence_id_ =
scheduler_->CreateSequence(gpu::SchedulingPriority::kHigh); scheduler_->CreateSequence(gpu::SchedulingPriority::kHigh);
GrContext* vulkan_gr_context =
is_using_vulkan() ? vulkan_context_provider()->GetGrContext() : nullptr;
// Defer creation of the render thread. This is to prevent it from handling // Defer creation of the render thread. This is to prevent it from handling
// IPC messages before the sandbox has been enabled and all other necessary // IPC messages before the sandbox has been enabled and all other necessary
// initialization has succeeded. // initialization has succeeded.
...@@ -266,7 +264,7 @@ void GpuServiceImpl::InitializeWithHost( ...@@ -266,7 +264,7 @@ void GpuServiceImpl::InitializeWithHost(
gpu_preferences_, this, watchdog_thread_.get(), main_runner_, io_runner_, gpu_preferences_, this, watchdog_thread_.get(), main_runner_, io_runner_,
scheduler_.get(), sync_point_manager_, gpu_memory_buffer_factory_.get(), scheduler_.get(), sync_point_manager_, gpu_memory_buffer_factory_.get(),
gpu_feature_info_, std::move(activity_flags), gpu_feature_info_, std::move(activity_flags),
std::move(default_offscreen_surface), vulkan_gr_context); std::move(default_offscreen_surface), vulkan_context_provider());
media_gpu_channel_manager_.reset( media_gpu_channel_manager_.reset(
new media::MediaGpuChannelManager(gpu_channel_manager_.get())); new media::MediaGpuChannelManager(gpu_channel_manager_.get()));
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
import("//build/config/jumbo.gni") import("//build/config/jumbo.gni")
import("//build/config/ui.gni") import("//build/config/ui.gni")
import("//third_party/protobuf/proto_library.gni") import("//third_party/protobuf/proto_library.gni")
import("//gpu/vulkan/features.gni")
group("service") { group("service") {
if (is_component_build) { if (is_component_build) {
...@@ -293,6 +294,7 @@ target(link_target_type, "gles2_sources") { ...@@ -293,6 +294,7 @@ target(link_target_type, "gles2_sources") {
"//gpu/command_buffer/common:gles2_utils", "//gpu/command_buffer/common:gles2_utils",
"//gpu/config", "//gpu/config",
"//gpu/ipc/common:surface_handle_type", "//gpu/ipc/common:surface_handle_type",
"//gpu/vulkan:buildflags",
"//third_party/angle:angle_image_util", "//third_party/angle:angle_image_util",
"//third_party/angle:commit_id", "//third_party/angle:commit_id",
"//third_party/angle:translator", "//third_party/angle:translator",
...@@ -307,6 +309,10 @@ target(link_target_type, "gles2_sources") { ...@@ -307,6 +309,10 @@ target(link_target_type, "gles2_sources") {
"//ui/gl/init", "//ui/gl/init",
] ]
if (enable_vulkan) {
deps += [ "//components/viz/common:vulkan_context_provider" ]
}
if (is_mac) { if (is_mac) {
# Required by gles2_cmd_decoder.cc on Mac. # Required by gles2_cmd_decoder.cc on Mac.
libs = [ libs = [
......
include_rules = [ include_rules = [
"+cc/paint", "+cc/paint",
"+third_party/skia", "+third_party/skia",
"+components/viz/common/gpu/vulkan_context_provider.h",
"+components/viz/common/resources/resource_format.h", "+components/viz/common/resources/resource_format.h",
"+components/viz/common/resources/resource_format_utils.h", "+components/viz/common/resources/resource_format_utils.h",
"+components/viz/common/resources/resource_sizes.h", "+components/viz/common/resources/resource_sizes.h",
......
...@@ -9,12 +9,17 @@ ...@@ -9,12 +9,17 @@
#include "gpu/command_buffer/common/activity_flags.h" #include "gpu/command_buffer/common/activity_flags.h"
#include "gpu/command_buffer/service/service_transfer_cache.h" #include "gpu/command_buffer/service/service_transfer_cache.h"
#include "gpu/config/gpu_driver_bug_workarounds.h" #include "gpu/config/gpu_driver_bug_workarounds.h"
#include "gpu/vulkan/buildflags.h"
#include "ui/gl/gl_bindings.h" #include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_context.h" #include "ui/gl/gl_context.h"
#include "ui/gl/gl_share_group.h" #include "ui/gl/gl_share_group.h"
#include "ui/gl/gl_surface.h" #include "ui/gl/gl_surface.h"
#include "ui/gl/init/create_gr_gl_interface.h" #include "ui/gl/init/create_gr_gl_interface.h"
#if BUILDFLAG(ENABLE_VULKAN)
#include "components/viz/common/gpu/vulkan_context_provider.h"
#endif
namespace gpu { namespace gpu {
namespace raster { namespace raster {
...@@ -22,13 +27,10 @@ RasterDecoderContextState::RasterDecoderContextState( ...@@ -22,13 +27,10 @@ RasterDecoderContextState::RasterDecoderContextState(
scoped_refptr<gl::GLShareGroup> share_group, scoped_refptr<gl::GLShareGroup> share_group,
scoped_refptr<gl::GLSurface> surface, scoped_refptr<gl::GLSurface> surface,
scoped_refptr<gl::GLContext> context, scoped_refptr<gl::GLContext> context,
bool use_virtualized_gl_contexts, bool use_virtualized_gl_contexts)
GrContext* vulkan_gr_context)
: share_group(std::move(share_group)), : share_group(std::move(share_group)),
surface(std::move(surface)), surface(std::move(surface)),
context(std::move(context)), context(std::move(context)),
gr_context(vulkan_gr_context),
use_vulkan_gr_context(!!gr_context),
use_virtualized_gl_contexts(use_virtualized_gl_contexts) { use_virtualized_gl_contexts(use_virtualized_gl_contexts) {
if (base::ThreadTaskRunnerHandle::IsSet()) { if (base::ThreadTaskRunnerHandle::IsSet()) {
base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
...@@ -36,6 +38,27 @@ RasterDecoderContextState::RasterDecoderContextState( ...@@ -36,6 +38,27 @@ RasterDecoderContextState::RasterDecoderContextState(
} }
} }
RasterDecoderContextState::RasterDecoderContextState(
viz::VulkanContextProvider* vulkan_context_provider)
#if BUILDFLAG(ENABLE_VULKAN)
: vk_context_provider(vulkan_context_provider),
gr_context(vk_context_provider->GetGrContext()),
use_vulkan_gr_context(true)
#endif
{
// This constructor should not be called if Vulkan is not enabled.
#if !BUILDFLAG(ENABLE_VULKAN)
DCHECK(false);
#endif
// gr_context should not be null.
DCHECK(gr_context);
if (base::ThreadTaskRunnerHandle::IsSet()) {
base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
this, "RasterDecoderContextState", base::ThreadTaskRunnerHandle::Get());
}
}
RasterDecoderContextState::~RasterDecoderContextState() { RasterDecoderContextState::~RasterDecoderContextState() {
if (gr_context) if (gr_context)
gr_context->abandonContext(); gr_context->abandonContext();
......
...@@ -19,6 +19,10 @@ class GLShareGroup; ...@@ -19,6 +19,10 @@ class GLShareGroup;
class GLSurface; class GLSurface;
} // namespace gl } // namespace gl
namespace viz {
class VulkanContextProvider;
} // namespace viz
namespace gpu { namespace gpu {
class GpuDriverBugWorkarounds; class GpuDriverBugWorkarounds;
class GpuProcessActivityFlags; class GpuProcessActivityFlags;
...@@ -30,11 +34,16 @@ struct GPU_GLES2_EXPORT RasterDecoderContextState ...@@ -30,11 +34,16 @@ struct GPU_GLES2_EXPORT RasterDecoderContextState
: public base::RefCounted<RasterDecoderContextState>, : public base::RefCounted<RasterDecoderContextState>,
public base::trace_event::MemoryDumpProvider { public base::trace_event::MemoryDumpProvider {
public: public:
// Used for GL.
RasterDecoderContextState(scoped_refptr<gl::GLShareGroup> share_group, RasterDecoderContextState(scoped_refptr<gl::GLShareGroup> share_group,
scoped_refptr<gl::GLSurface> surface, scoped_refptr<gl::GLSurface> surface,
scoped_refptr<gl::GLContext> context, scoped_refptr<gl::GLContext> context,
bool use_virtualized_gl_contexts, bool use_virtualized_gl_contexts);
GrContext* vulkan_gr_context = nullptr);
// Used for Vulkan.
RasterDecoderContextState(
viz::VulkanContextProvider* vulkan_context_provider);
void InitializeGrContext(const GpuDriverBugWorkarounds& workarounds, void InitializeGrContext(const GpuDriverBugWorkarounds& workarounds,
GrContextOptions::PersistentCache* cache, GrContextOptions::PersistentCache* cache,
GpuProcessActivityFlags* activity_flags = nullptr, GpuProcessActivityFlags* activity_flags = nullptr,
...@@ -42,10 +51,14 @@ struct GPU_GLES2_EXPORT RasterDecoderContextState ...@@ -42,10 +51,14 @@ struct GPU_GLES2_EXPORT RasterDecoderContextState
void PurgeMemory( void PurgeMemory(
base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level); base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level);
// These should be null for Vulkan mode.
scoped_refptr<gl::GLShareGroup> share_group; scoped_refptr<gl::GLShareGroup> share_group;
scoped_refptr<gl::GLSurface> surface; scoped_refptr<gl::GLSurface> surface;
scoped_refptr<gl::GLContext> context; scoped_refptr<gl::GLContext> context;
GrContext* gr_context;
// Should be null for GL mode.
viz::VulkanContextProvider* vk_context_provider = nullptr;
GrContext* gr_context = nullptr;
sk_sp<GrContext> owned_gr_context; sk_sp<GrContext> owned_gr_context;
std::unique_ptr<ServiceTransferCache> transfer_cache; std::unique_ptr<ServiceTransferCache> transfer_cache;
const bool use_vulkan_gr_context = false; const bool use_vulkan_gr_context = false;
......
...@@ -63,7 +63,7 @@ GpuChannelManager::GpuChannelManager( ...@@ -63,7 +63,7 @@ GpuChannelManager::GpuChannelManager(
const GpuFeatureInfo& gpu_feature_info, const GpuFeatureInfo& gpu_feature_info,
GpuProcessActivityFlags activity_flags, GpuProcessActivityFlags activity_flags,
scoped_refptr<gl::GLSurface> default_offscreen_surface, scoped_refptr<gl::GLSurface> default_offscreen_surface,
GrContext* vulkan_gr_context) viz::VulkanContextProvider* vulkan_context_provider)
: task_runner_(task_runner), : task_runner_(task_runner),
io_task_runner_(io_task_runner), io_task_runner_(io_task_runner),
gpu_preferences_(gpu_preferences), gpu_preferences_(gpu_preferences),
...@@ -84,7 +84,7 @@ GpuChannelManager::GpuChannelManager( ...@@ -84,7 +84,7 @@ GpuChannelManager::GpuChannelManager(
memory_pressure_listener_( memory_pressure_listener_(
base::Bind(&GpuChannelManager::HandleMemoryPressure, base::Bind(&GpuChannelManager::HandleMemoryPressure,
base::Unretained(this))), base::Unretained(this))),
vulkan_gr_context_(vulkan_gr_context), vulkan_context_provider_(vulkan_context_provider),
weak_factory_(this) { weak_factory_(this) {
DCHECK(task_runner->BelongsToCurrentThread()); DCHECK(task_runner->BelongsToCurrentThread());
DCHECK(io_task_runner); DCHECK(io_task_runner);
...@@ -432,9 +432,15 @@ GpuChannelManager::GetRasterDecoderContextState(ContextResult* result) { ...@@ -432,9 +432,15 @@ GpuChannelManager::GetRasterDecoderContextState(ContextResult* result) {
} }
// TODO(penghuang): https://crbug.com/899735 Handle device lost for Vulkan. // TODO(penghuang): https://crbug.com/899735 Handle device lost for Vulkan.
raster_decoder_context_state_ = new raster::RasterDecoderContextState( if (vulkan_context_provider_) {
std::move(share_group), std::move(surface), std::move(context), raster_decoder_context_state_ =
use_virtualized_gl_contexts, vulkan_gr_context_); new raster::RasterDecoderContextState(vulkan_context_provider_);
} else {
raster_decoder_context_state_ = new raster::RasterDecoderContextState(
std::move(share_group), std::move(surface), std::move(context),
use_virtualized_gl_contexts);
}
const bool enable_raster_transport = const bool enable_raster_transport =
gpu_feature_info_.status_values[GPU_FEATURE_TYPE_OOP_RASTERIZATION] == gpu_feature_info_.status_values[GPU_FEATURE_TYPE_OOP_RASTERIZATION] ==
gpu::kGpuFeatureStatusEnabled; gpu::kGpuFeatureStatusEnabled;
......
...@@ -37,8 +37,6 @@ ...@@ -37,8 +37,6 @@
#include "ui/gl/gl_surface.h" #include "ui/gl/gl_surface.h"
#include "url/gurl.h" #include "url/gurl.h"
class GrContext;
namespace gl { namespace gl {
class GLShareGroup; class GLShareGroup;
} }
...@@ -68,18 +66,19 @@ class ProgramCache; ...@@ -68,18 +66,19 @@ class ProgramCache;
class GPU_IPC_SERVICE_EXPORT GpuChannelManager class GPU_IPC_SERVICE_EXPORT GpuChannelManager
: public raster::GrShaderCache::Client { : public raster::GrShaderCache::Client {
public: public:
GpuChannelManager(const GpuPreferences& gpu_preferences, GpuChannelManager(
GpuChannelManagerDelegate* delegate, const GpuPreferences& gpu_preferences,
GpuWatchdogThread* watchdog, GpuChannelManagerDelegate* delegate,
scoped_refptr<base::SingleThreadTaskRunner> task_runner, GpuWatchdogThread* watchdog,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, scoped_refptr<base::SingleThreadTaskRunner> task_runner,
Scheduler* scheduler, scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
SyncPointManager* sync_point_manager, Scheduler* scheduler,
GpuMemoryBufferFactory* gpu_memory_buffer_factory, SyncPointManager* sync_point_manager,
const GpuFeatureInfo& gpu_feature_info, GpuMemoryBufferFactory* gpu_memory_buffer_factory,
GpuProcessActivityFlags activity_flags, const GpuFeatureInfo& gpu_feature_info,
scoped_refptr<gl::GLSurface> default_offscreen_surface, GpuProcessActivityFlags activity_flags,
GrContext* vulkan_gr_context = nullptr); scoped_refptr<gl::GLSurface> default_offscreen_surface,
viz::VulkanContextProvider* vulkan_context_provider = nullptr);
~GpuChannelManager() override; ~GpuChannelManager() override;
GpuChannelManagerDelegate* delegate() const { return delegate_; } GpuChannelManagerDelegate* delegate() const { return delegate_; }
...@@ -241,9 +240,9 @@ class GPU_IPC_SERVICE_EXPORT GpuChannelManager ...@@ -241,9 +240,9 @@ class GPU_IPC_SERVICE_EXPORT GpuChannelManager
scoped_refptr<raster::RasterDecoderContextState> scoped_refptr<raster::RasterDecoderContextState>
raster_decoder_context_state_; raster_decoder_context_state_;
// With --enable-vulkan, the vulkan_gr_context_ will be set from // With --enable-vulkan, the vulkan_context_provider_ will be set from
// viz::GpuServiceImpl. The raster decoders will use it for rasterization. // viz::GpuServiceImpl. The raster decoders will use it for rasterization.
GrContext* vulkan_gr_context_; viz::VulkanContextProvider* vulkan_context_provider_;
// Member variables should appear before the WeakPtrFactory, to ensure // Member variables should appear before the WeakPtrFactory, to ensure
// that any WeakPtrs to Controller are invalidated before its members // that any WeakPtrs to Controller are invalidated before its members
......
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