From 3634509ac780f4277e1ba708231270360539592b Mon Sep 17 00:00:00 2001 From: penghuang Date: Mon, 15 Jun 2015 08:06:49 -0700 Subject: Using OrderingBarrier() in GLES2Implementation::Bind()* for better performance. CommandBufferHelper::Flush() in GLES2Implementation::Bind*() is expensive, so replace them with the cheaper CommandBufferHelper::OderingBarrier(). Also implement CommandBufferHelper::OderingBarrier() for Pepper. BUG=496699 Review URL: https://codereview.chromium.org/1174553004 Cr-Commit-Position: refs/heads/master@{#334378} --- ppapi/proxy/plugin_dispatcher.cc | 8 ++++++ ppapi/proxy/plugin_dispatcher.h | 10 ++++++++ ppapi/proxy/ppapi_command_buffer_proxy.cc | 42 +++++++++++++++++++++++-------- ppapi/proxy/ppapi_command_buffer_proxy.h | 6 ++++- ppapi/shared_impl/host_resource.h | 5 ++++ 5 files changed, 60 insertions(+), 11 deletions(-) (limited to 'ppapi') diff --git a/ppapi/proxy/plugin_dispatcher.cc b/ppapi/proxy/plugin_dispatcher.cc index fb3c23e..15c521c 100644 --- a/ppapi/proxy/plugin_dispatcher.cc +++ b/ppapi/proxy/plugin_dispatcher.cc @@ -63,6 +63,14 @@ InstanceData::~InstanceData() { mouse_lock_callback->Abort(); } +InstanceData::FlushInfo::FlushInfo() + : flush_pending(false), + put_offset(0) { +} + +InstanceData::FlushInfo::~FlushInfo() { +} + PluginDispatcher::PluginDispatcher(PP_GetInterface_Func get_interface, const PpapiPermissions& permissions, bool incognito) diff --git a/ppapi/proxy/plugin_dispatcher.h b/ppapi/proxy/plugin_dispatcher.h index 03d09e8..159e69c 100644 --- a/ppapi/proxy/plugin_dispatcher.h +++ b/ppapi/proxy/plugin_dispatcher.h @@ -67,6 +67,16 @@ struct InstanceData { // The message handler which should handle JavaScript->Plugin messages, if // one has been registered, otherwise NULL. scoped_ptr message_handler; + + // Flush info for PpapiCommandBufferProxy::OrderingBarrier(). + struct FlushInfo { + FlushInfo(); + ~FlushInfo(); + bool flush_pending; + HostResource resource; + int32 put_offset; + }; + FlushInfo flush_info_; }; class PPAPI_PROXY_EXPORT PluginDispatcher diff --git a/ppapi/proxy/ppapi_command_buffer_proxy.cc b/ppapi/proxy/ppapi_command_buffer_proxy.cc index 384df02..9d59b0d 100644 --- a/ppapi/proxy/ppapi_command_buffer_proxy.cc +++ b/ppapi/proxy/ppapi_command_buffer_proxy.cc @@ -5,7 +5,6 @@ #include "ppapi/proxy/ppapi_command_buffer_proxy.h" #include "base/numerics/safe_conversions.h" -#include "ppapi/proxy/plugin_dispatcher.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/shared_impl/api_id.h" #include "ppapi/shared_impl/host_resource.h" @@ -25,6 +24,8 @@ PpapiCommandBufferProxy::PpapiCommandBufferProxy( shared_state_shm_.reset( new base::SharedMemory(shared_state.shmem(), false)); shared_state_shm_->Map(shared_state.size()); + InstanceData* data = dispatcher->GetInstanceData(resource.instance()); + flush_info_ = &data->flush_info_; } PpapiCommandBufferProxy::~PpapiCommandBufferProxy() { @@ -51,18 +52,20 @@ void PpapiCommandBufferProxy::Flush(int32 put_offset) { if (last_state_.error != gpu::error::kNoError) return; - IPC::Message* message = new PpapiHostMsg_PPBGraphics3D_AsyncFlush( - ppapi::API_ID_PPB_GRAPHICS_3D, resource_, put_offset); - - // Do not let a synchronous flush hold up this message. If this handler is - // deferred until after the synchronous flush completes, it will overwrite the - // cached last_state_ with out-of-date data. - message->set_unblock(true); - Send(message); + OrderingBarrier(put_offset); + FlushInternal(); } void PpapiCommandBufferProxy::OrderingBarrier(int32 put_offset) { - Flush(put_offset); + if (last_state_.error != gpu::error::kNoError) + return; + + if (flush_info_->flush_pending && flush_info_->resource != resource_) + FlushInternal(); + + flush_info_->flush_pending = true; + flush_info_->resource = resource_; + flush_info_->put_offset = put_offset; } void PpapiCommandBufferProxy::WaitForTokenInRange(int32 start, int32 end) { @@ -270,5 +273,24 @@ gpu::CommandBufferSharedState* PpapiCommandBufferProxy::shared_state() const { shared_state_shm_->memory()); } +void PpapiCommandBufferProxy::FlushInternal() { + DCHECK(last_state_.error == gpu::error::kNoError); + + DCHECK(flush_info_->flush_pending); + + IPC::Message* message = new PpapiHostMsg_PPBGraphics3D_AsyncFlush( + ppapi::API_ID_PPB_GRAPHICS_3D, flush_info_->resource, + flush_info_->put_offset); + + // Do not let a synchronous flush hold up this message. If this handler is + // deferred until after the synchronous flush completes, it will overwrite the + // cached last_state_ with out-of-date data. + message->set_unblock(true); + Send(message); + + flush_info_->flush_pending = false; + flush_info_->resource.SetHostResource(0, 0); +} + } // namespace proxy } // namespace ppapi diff --git a/ppapi/proxy/ppapi_command_buffer_proxy.h b/ppapi/proxy/ppapi_command_buffer_proxy.h index 24ed177..3bf8ece 100644 --- a/ppapi/proxy/ppapi_command_buffer_proxy.h +++ b/ppapi/proxy/ppapi_command_buffer_proxy.h @@ -11,6 +11,7 @@ #include "gpu/command_buffer/client/gpu_control.h" #include "gpu/command_buffer/common/command_buffer.h" #include "gpu/command_buffer/common/command_buffer_shared.h" +#include "ppapi/proxy/plugin_dispatcher.h" #include "ppapi/proxy/ppapi_proxy_export.h" #include "ppapi/shared_impl/host_resource.h" @@ -21,7 +22,6 @@ class Message; namespace ppapi { namespace proxy { -class PluginDispatcher; class SerializedHandle; class PPAPI_PROXY_EXPORT PpapiCommandBufferProxy : public gpu::CommandBuffer, @@ -78,6 +78,8 @@ class PPAPI_PROXY_EXPORT PpapiCommandBufferProxy : public gpu::CommandBuffer, // The shared memory area used to update state. gpu::CommandBufferSharedState* shared_state() const; + void FlushInternal(); + gpu::Capabilities capabilities_; State last_state_; scoped_ptr shared_state_shm_; @@ -87,6 +89,8 @@ class PPAPI_PROXY_EXPORT PpapiCommandBufferProxy : public gpu::CommandBuffer, base::Closure channel_error_callback_; + InstanceData::FlushInfo *flush_info_; + DISALLOW_COPY_AND_ASSIGN(PpapiCommandBufferProxy); }; diff --git a/ppapi/shared_impl/host_resource.h b/ppapi/shared_impl/host_resource.h index 3c49090..7828cd2 100644 --- a/ppapi/shared_impl/host_resource.h +++ b/ppapi/shared_impl/host_resource.h @@ -64,6 +64,11 @@ class PPAPI_SHARED_EXPORT HostResource { return host_resource_ < other.host_resource_; } + bool operator!=(const HostResource& other) const { + return instance_ != other.instance_ || + host_resource_ != other.host_resource_; + } + private: PP_Instance instance_; PP_Resource host_resource_; -- cgit v1.1