Commit d9705adf authored by Antoine Labour's avatar Antoine Labour Committed by Commit Bot

In-process SharedImageInterface

This adds a InProcessSharedImageInterface tear-off class linked to
InProcessCommandBuffer, that implements SharedImageInterface using the
same GLContext/GLSurface and TaskExecutor as the InProcessCommandBuffer.

Bug: 870116
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
Change-Id: I916a87a3ae6c1360e1e10766654b96455eb2e1ca
Reviewed-on: https://chromium-review.googlesource.com/1171782
Commit-Queue: Antoine Labour <piman@chromium.org>
Reviewed-by: default avatarSunny Sachanandani <sunnyps@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582441}
parent d8c8dbf2
include_rules = [
"+components/viz/common/resources/resource_format.h",
]
...@@ -52,6 +52,10 @@ CommandBuffer* GLInProcessContext::GetCommandBuffer() { ...@@ -52,6 +52,10 @@ CommandBuffer* GLInProcessContext::GetCommandBuffer() {
return command_buffer_.get(); return command_buffer_.get();
} }
SharedImageInterface* GLInProcessContext::GetSharedImageInterface() {
return command_buffer_->GetSharedImageInterface();
}
void GLInProcessContext::SetUpdateVSyncParametersCallback( void GLInProcessContext::SetUpdateVSyncParametersCallback(
const InProcessCommandBuffer::UpdateVSyncParametersCallback& callback) { const InProcessCommandBuffer::UpdateVSyncParametersCallback& callback) {
command_buffer_->SetUpdateVSyncParametersCallback(callback); command_buffer_->SetUpdateVSyncParametersCallback(callback);
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "ui/gl/gl_surface.h" #include "ui/gl/gl_surface.h"
namespace gpu { namespace gpu {
class SharedImageInterface;
class TransferBuffer; class TransferBuffer;
struct GpuFeatureInfo; struct GpuFeatureInfo;
struct SharedMemoryLimits; struct SharedMemoryLimits;
...@@ -62,6 +63,8 @@ class GL_IN_PROCESS_CONTEXT_EXPORT GLInProcessContext { ...@@ -62,6 +63,8 @@ class GL_IN_PROCESS_CONTEXT_EXPORT GLInProcessContext {
CommandBuffer* GetCommandBuffer(); CommandBuffer* GetCommandBuffer();
SharedImageInterface* GetSharedImageInterface();
void SetUpdateVSyncParametersCallback( void SetUpdateVSyncParametersCallback(
const InProcessCommandBuffer::UpdateVSyncParametersCallback& callback); const InProcessCommandBuffer::UpdateVSyncParametersCallback& callback);
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "gpu/command_buffer/client/gpu_control_client.h" #include "gpu/command_buffer/client/gpu_control_client.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/client/shared_image_interface.h"
#include "gpu/command_buffer/common/gpu_memory_buffer_support.h" #include "gpu/command_buffer/common/gpu_memory_buffer_support.h"
#include "gpu/command_buffer/common/swap_buffers_complete_params.h" #include "gpu/command_buffer/common/swap_buffers_complete_params.h"
#include "gpu/command_buffer/common/swap_buffers_flags.h" #include "gpu/command_buffer/common/swap_buffers_flags.h"
...@@ -48,6 +49,7 @@ ...@@ -48,6 +49,7 @@
#include "gpu/command_buffer/service/raster_decoder.h" #include "gpu/command_buffer/service/raster_decoder.h"
#include "gpu/command_buffer/service/raster_decoder_context_state.h" #include "gpu/command_buffer/service/raster_decoder_context_state.h"
#include "gpu/command_buffer/service/service_utils.h" #include "gpu/command_buffer/service/service_utils.h"
#include "gpu/command_buffer/service/shared_image_factory.h"
#include "gpu/command_buffer/service/sync_point_manager.h" #include "gpu/command_buffer/service/sync_point_manager.h"
#include "gpu/command_buffer/service/transfer_buffer_manager.h" #include "gpu/command_buffer/service/transfer_buffer_manager.h"
#include "gpu/config/gpu_crash_keys.h" #include "gpu/config/gpu_crash_keys.h"
...@@ -162,6 +164,70 @@ scoped_refptr<CommandBufferTaskExecutor> MaybeGetDefaultTaskExecutor( ...@@ -162,6 +164,70 @@ scoped_refptr<CommandBufferTaskExecutor> MaybeGetDefaultTaskExecutor(
} // anonyous namespace } // anonyous namespace
class InProcessCommandBuffer::SharedImageInterface
: public gpu::SharedImageInterface {
public:
explicit SharedImageInterface(InProcessCommandBuffer* parent)
: parent_(parent),
command_buffer_id_(CommandBufferId::FromUnsafeValue(
g_next_command_buffer_id.GetNext() + 1)) {}
~SharedImageInterface() override = default;
Mailbox CreateSharedImage(viz::ResourceFormat format,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
uint32_t usage) override {
auto mailbox = Mailbox::Generate();
{
base::AutoLock lock(lock_);
// Note: we enqueue the task under the lock to guarantee monotonicity of
// the release ids as seen by the service. Unretained is safe because
// InProcessCommandBuffer synchronizes with the GPU thread at destruction
// time, cancelling tasks, before |this| is destroyed.
parent_->QueueOnceTask(
false,
base::BindOnce(&InProcessCommandBuffer::CreateSharedImageOnGpuThread,
parent_->gpu_thread_weak_ptr_, mailbox, format, size,
color_space, usage,
MakeSyncToken(next_fence_sync_release_++)));
}
return mailbox;
}
void DestroySharedImage(const SyncToken& sync_token,
const Mailbox& mailbox) override {
// Need a repeatable task to handle SyncToken waits.
parent_->QueueRepeatableTask(base::BindRepeating(
&InProcessCommandBuffer::DestroySharedImageOnGpuThread,
parent_->gpu_thread_weak_ptr_, sync_token, mailbox));
}
SyncToken GenUnverifiedSyncToken() override {
base::AutoLock lock(lock_);
return MakeSyncToken(next_fence_sync_release_ - 1);
}
CommandBufferId command_buffer_id() const { return command_buffer_id_; }
private:
SyncToken MakeSyncToken(uint64_t release_id) {
return SyncToken(CommandBufferNamespace::IN_PROCESS, command_buffer_id_,
release_id);
}
InProcessCommandBuffer* const parent_;
const CommandBufferId command_buffer_id_;
// Accessed on any thread. release_id_lock_ protects access to
// next_fence_sync_release_.
base::Lock lock_;
uint64_t next_fence_sync_release_ = 1;
DISALLOW_COPY_AND_ASSIGN(SharedImageInterface);
};
InProcessCommandBuffer::InProcessCommandBuffer( InProcessCommandBuffer::InProcessCommandBuffer(
scoped_refptr<CommandBufferTaskExecutor> task_executer) scoped_refptr<CommandBufferTaskExecutor> task_executer)
: command_buffer_id_(CommandBufferId::FromUnsafeValue( : command_buffer_id_(CommandBufferId::FromUnsafeValue(
...@@ -169,6 +235,7 @@ InProcessCommandBuffer::InProcessCommandBuffer( ...@@ -169,6 +235,7 @@ InProcessCommandBuffer::InProcessCommandBuffer(
flush_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, flush_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC,
base::WaitableEvent::InitialState::NOT_SIGNALED), base::WaitableEvent::InitialState::NOT_SIGNALED),
task_executor_(MaybeGetDefaultTaskExecutor(std::move(task_executer))), task_executor_(MaybeGetDefaultTaskExecutor(std::move(task_executer))),
shared_image_interface_(new SharedImageInterface(this)),
fence_sync_wait_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, fence_sync_wait_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC,
base::WaitableEvent::InitialState::NOT_SIGNALED), base::WaitableEvent::InitialState::NOT_SIGNALED),
client_thread_weak_ptr_factory_(this), client_thread_weak_ptr_factory_(this),
...@@ -204,6 +271,11 @@ int InProcessCommandBuffer::GetRasterDecoderIdForTest() const { ...@@ -204,6 +271,11 @@ int InProcessCommandBuffer::GetRasterDecoderIdForTest() const {
->DecoderIdForTest(); ->DecoderIdForTest();
} }
gpu::SharedImageInterface* InProcessCommandBuffer::GetSharedImageInterface()
const {
return shared_image_interface_.get();
}
bool InProcessCommandBuffer::MakeCurrent() { bool InProcessCommandBuffer::MakeCurrent() {
CheckSequencedThread(); CheckSequencedThread();
...@@ -387,6 +459,14 @@ gpu::ContextResult InProcessCommandBuffer::InitializeOnGpuThread( ...@@ -387,6 +459,14 @@ gpu::ContextResult InProcessCommandBuffer::InitializeOnGpuThread(
task_executor_->sync_point_manager()->CreateSyncPointClientState( task_executor_->sync_point_manager()->CreateSyncPointClientState(
GetNamespaceID(), GetCommandBufferID(), GetNamespaceID(), GetCommandBufferID(),
sync_point_order_data_->sequence_id()); sync_point_order_data_->sequence_id());
// Make the SharedImageInterface use the same sequence as the command buffer,
// it's necessary for WebView because of the blocking behavior.
// TODO(piman): see if it's worth using a different sequence for non-WebView.
shared_image_client_state_ =
task_executor_->sync_point_manager()->CreateSyncPointClientState(
CommandBufferNamespace::IN_PROCESS,
shared_image_interface_->command_buffer_id(),
sync_point_order_data_->sequence_id());
if (context_group_->use_passthrough_cmd_decoder()) { if (context_group_->use_passthrough_cmd_decoder()) {
// When using the passthrough command decoder, only share with other // When using the passthrough command decoder, only share with other
...@@ -562,6 +642,8 @@ bool InProcessCommandBuffer::DestroyOnGpuThread() { ...@@ -562,6 +642,8 @@ bool InProcessCommandBuffer::DestroyOnGpuThread() {
gpu_thread_weak_ptr_factory_.InvalidateWeakPtrs(); gpu_thread_weak_ptr_factory_.InvalidateWeakPtrs();
// Clean up GL resources if possible. // Clean up GL resources if possible.
bool have_context = context_.get() && context_->MakeCurrent(surface_.get()); bool have_context = context_.get() && context_->MakeCurrent(surface_.get());
if (shared_image_factory_)
shared_image_factory_->DestroyAllSharedImages(have_context);
// Prepare to destroy the surface while the context is still current, because // Prepare to destroy the surface while the context is still current, because
// some surface destructors make GL calls. // some surface destructors make GL calls.
...@@ -586,6 +668,10 @@ bool InProcessCommandBuffer::DestroyOnGpuThread() { ...@@ -586,6 +668,10 @@ bool InProcessCommandBuffer::DestroyOnGpuThread() {
sync_point_client_state_->Destroy(); sync_point_client_state_->Destroy();
sync_point_client_state_ = nullptr; sync_point_client_state_ = nullptr;
} }
if (shared_image_client_state_) {
shared_image_client_state_->Destroy();
shared_image_client_state_ = nullptr;
}
gl_share_group_ = nullptr; gl_share_group_ = nullptr;
context_group_ = nullptr; context_group_ = nullptr;
...@@ -1190,6 +1276,48 @@ void InProcessCommandBuffer::GetGpuFenceOnGpuThread( ...@@ -1190,6 +1276,48 @@ void InProcessCommandBuffer::GetGpuFenceOnGpuThread(
} }
} }
void InProcessCommandBuffer::CreateSharedImageOnGpuThread(
const Mailbox& mailbox,
viz::ResourceFormat format,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
uint32_t usage,
const SyncToken& sync_token) {
CheckSequencedThread();
if (!MakeCurrent())
return;
if (!shared_image_factory_) {
shared_image_factory_ = std::make_unique<SharedImageFactory>(
GetGpuPreferences(), context_group_->feature_info()->workarounds(),
GetGpuFeatureInfo(), context_group_->mailbox_manager(), image_factory_,
nullptr);
}
if (!shared_image_factory_->CreateSharedImage(mailbox, format, size,
color_space, usage)) {
// Signal errors by losing the command buffer.
command_buffer_->SetParseError(error::kLostContext);
return;
}
context_group_->mailbox_manager()->PushTextureUpdates(sync_token);
shared_image_client_state_->ReleaseFenceSync(sync_token.release_count());
}
void InProcessCommandBuffer::DestroySharedImageOnGpuThread(
const SyncToken& sync_token,
const Mailbox& mailbox) {
CheckSequencedThread();
if (OnWaitSyncToken(sync_token))
return;
if (!MakeCurrent())
return;
if (!shared_image_factory_ ||
!shared_image_factory_->DestroySharedImage(mailbox)) {
// Signal errors by losing the command buffer.
command_buffer_->SetParseError(error::kLostContext);
return;
}
}
void InProcessCommandBuffer::SetLock(base::Lock*) { void InProcessCommandBuffer::SetLock(base::Lock*) {
// No support for using on multiple threads. // No support for using on multiple threads.
NOTREACHED(); NOTREACHED();
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
#include "base/synchronization/waitable_event.h" #include "base/synchronization/waitable_event.h"
#include "components/viz/common/resources/resource_format.h"
#include "gpu/command_buffer/client/gpu_control.h" #include "gpu/command_buffer/client/gpu_control.h"
#include "gpu/command_buffer/common/command_buffer.h" #include "gpu/command_buffer/common/command_buffer.h"
#include "gpu/command_buffer/common/context_result.h" #include "gpu/command_buffer/common/context_result.h"
...@@ -61,6 +62,8 @@ class GpuProcessActivityFlags; ...@@ -61,6 +62,8 @@ class GpuProcessActivityFlags;
class CommandBufferTaskExecutor; class CommandBufferTaskExecutor;
class GpuMemoryBufferManager; class GpuMemoryBufferManager;
class ImageFactory; class ImageFactory;
class SharedImageFactory;
class SharedImageInterface;
class SyncPointClientState; class SyncPointClientState;
class SyncPointOrderData; class SyncPointOrderData;
class TransferBufferManager; class TransferBufferManager;
...@@ -198,7 +201,11 @@ class GL_IN_PROCESS_CONTEXT_EXPORT InProcessCommandBuffer ...@@ -198,7 +201,11 @@ class GL_IN_PROCESS_CONTEXT_EXPORT InProcessCommandBuffer
return task_executor_.get(); return task_executor_.get();
} }
gpu::SharedImageInterface* GetSharedImageInterface() const;
private: private:
class SharedImageInterface;
struct InitializeOnGpuThreadParams { struct InitializeOnGpuThreadParams {
bool is_offscreen; bool is_offscreen;
SurfaceHandle window; SurfaceHandle window;
...@@ -264,6 +271,14 @@ class GL_IN_PROCESS_CONTEXT_EXPORT InProcessCommandBuffer ...@@ -264,6 +271,14 @@ class GL_IN_PROCESS_CONTEXT_EXPORT InProcessCommandBuffer
uint32_t gpu_fence_id, uint32_t gpu_fence_id,
const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
base::OnceCallback<void(std::unique_ptr<gfx::GpuFence>)> callback); base::OnceCallback<void(std::unique_ptr<gfx::GpuFence>)> callback);
void CreateSharedImageOnGpuThread(const Mailbox& mailbox,
viz::ResourceFormat format,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
uint32_t usage,
const SyncToken& sync_tokne);
void DestroySharedImageOnGpuThread(const SyncToken& sync_token,
const Mailbox& mailbox);
// Callbacks on the gpu thread. // Callbacks on the gpu thread.
void PerformDelayedWorkOnGpuThread(); void PerformDelayedWorkOnGpuThread();
...@@ -287,6 +302,9 @@ class GL_IN_PROCESS_CONTEXT_EXPORT InProcessCommandBuffer ...@@ -287,6 +302,9 @@ class GL_IN_PROCESS_CONTEXT_EXPORT InProcessCommandBuffer
scoped_refptr<gl::GLSurface> surface_; scoped_refptr<gl::GLSurface> surface_;
scoped_refptr<SyncPointOrderData> sync_point_order_data_; scoped_refptr<SyncPointOrderData> sync_point_order_data_;
scoped_refptr<SyncPointClientState> sync_point_client_state_; scoped_refptr<SyncPointClientState> sync_point_client_state_;
scoped_refptr<SyncPointClientState> shared_image_client_state_;
std::unique_ptr<SharedImageFactory> shared_image_factory_;
// Used to throttle PerformDelayedWorkOnGpuThread. // Used to throttle PerformDelayedWorkOnGpuThread.
bool delayed_work_pending_ = false; bool delayed_work_pending_ = false;
ImageFactory* image_factory_ = nullptr; ImageFactory* image_factory_ = nullptr;
...@@ -309,6 +327,7 @@ class GL_IN_PROCESS_CONTEXT_EXPORT InProcessCommandBuffer ...@@ -309,6 +327,7 @@ class GL_IN_PROCESS_CONTEXT_EXPORT InProcessCommandBuffer
// Accessed on both threads: // Accessed on both threads:
base::WaitableEvent flush_event_; base::WaitableEvent flush_event_;
scoped_refptr<CommandBufferTaskExecutor> task_executor_; scoped_refptr<CommandBufferTaskExecutor> task_executor_;
std::unique_ptr<SharedImageInterface> shared_image_interface_;
// The group of contexts that share namespaces with this context. // The group of contexts that share namespaces with this context.
scoped_refptr<gles2::ContextGroup> context_group_; scoped_refptr<gles2::ContextGroup> context_group_;
......
...@@ -116,6 +116,10 @@ ContextSupport* RasterInProcessContext::GetContextSupport() { ...@@ -116,6 +116,10 @@ ContextSupport* RasterInProcessContext::GetContextSupport() {
return raster_implementation_.get(); return raster_implementation_.get();
} }
SharedImageInterface* RasterInProcessContext::GetSharedImageInterface() {
return command_buffer_->GetSharedImageInterface();
}
ServiceTransferCache* RasterInProcessContext::GetTransferCacheForTest() const { ServiceTransferCache* RasterInProcessContext::GetTransferCacheForTest() const {
return command_buffer_->GetTransferCacheForTest(); return command_buffer_->GetTransferCacheForTest();
} }
......
...@@ -21,6 +21,7 @@ namespace gpu { ...@@ -21,6 +21,7 @@ namespace gpu {
class CommandBufferHelper; class CommandBufferHelper;
class ContextSupport; class ContextSupport;
class ServiceTransferCache; class ServiceTransferCache;
class SharedImageInterface;
class TransferBuffer; class TransferBuffer;
struct GpuFeatureInfo; struct GpuFeatureInfo;
struct SharedMemoryLimits; struct SharedMemoryLimits;
...@@ -59,6 +60,8 @@ class RasterInProcessContext { ...@@ -59,6 +60,8 @@ class RasterInProcessContext {
ContextSupport* GetContextSupport(); ContextSupport* GetContextSupport();
SharedImageInterface* GetSharedImageInterface();
// Test only functions. // Test only functions.
ServiceTransferCache* GetTransferCacheForTest() const; ServiceTransferCache* GetTransferCacheForTest() const;
InProcessCommandBuffer* GetCommandBufferForTest() const; InProcessCommandBuffer* GetCommandBufferForTest() const;
......
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