Skip to content

Commit

Permalink
Revert 147328 - Current status of patch:
Browse files Browse the repository at this point in the history
- In-memory cache
- maximum in memory limit (currently 6mb)
- lru eviction
- Cache includes saving the attribute + uniform mappings

Wiring:
- Added bindings for glProgramBinary and glGetProgramBinary
- Plumbed the shader cache from gl_channel_manager to program_manager

Refactoring:
- moved the meat of DoCompile to the ProgramManager

New:
- added field to ShaderInfo to store if we have a possible pending cache compile
- exposed attrib_map and uniform_map in ShaderInfo for the cache
- program_cache base class with in-memory status storage
- Simple memory_program_cache implementation, stores programs with lru eviction
- Added caching logic to DoCompileShader in gles2_cmd_decoder and Link in program_manager


Design doc: https://docs.google.com/document/d/1Vceem-nF4TCICoeGSh7OMXxfGuJEJYblGXRgN9V9hcE/edit

BUG=88572

Review URL: https://chromiumcodereview.appspot.com/10534173

TBR=dmurph@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10795037

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@147497 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
gman@chromium.org committed Jul 19, 2012
1 parent afaaacd commit 7f1a51c
Show file tree
Hide file tree
Showing 42 changed files with 107 additions and 2,220 deletions.
10 changes: 3 additions & 7 deletions content/common/gpu/gpu_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,8 @@ GpuChannel::GpuChannel(GpuChannelManager* gpu_channel_manager,
gfx::GLShareGroup* share_group,
gpu::gles2::MailboxManager* mailbox,
int client_id,
bool software,
gpu::gles2::ProgramCache* program_cache)
bool software)
: gpu_channel_manager_(gpu_channel_manager),
program_cache_(program_cache),
unprocessed_messages_(new gpu::RefCountedCounter),
client_id_(client_id),
share_group_(share_group ? share_group : new gfx::GLShareGroup),
Expand Down Expand Up @@ -334,8 +332,7 @@ void GpuChannel::CreateViewCommandBuffer(
surface_id,
watchdog_,
software_,
init_params.active_url,
program_cache_));
init_params.active_url));
if (preempt_by_counter_.get())
stub->SetPreemptByCounter(preempt_by_counter_);
router_.AddRoute(*route_id, stub.get());
Expand Down Expand Up @@ -486,8 +483,7 @@ void GpuChannel::OnCreateOffscreenCommandBuffer(
route_id,
0, watchdog_,
software_,
init_params.active_url,
program_cache_));
init_params.active_url));
if (preempt_by_counter_.get())
stub->SetPreemptByCounter(preempt_by_counter_);
router_.AddRoute(route_id, stub.get());
Expand Down
9 changes: 1 addition & 8 deletions content/common/gpu/gpu_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include <deque>
#include <string>
#include <vector>

#include "base/id_map.h"
#include "base/memory/ref_counted.h"
Expand Down Expand Up @@ -39,9 +38,6 @@ class WaitableEvent;

namespace gpu {
struct RefCountedCounter;
namespace gles2 {
class ProgramCache;
}
}

#if defined(OS_ANDROID)
Expand All @@ -62,8 +58,7 @@ class GpuChannel : public IPC::Listener,
gfx::GLShareGroup* share_group,
gpu::gles2::MailboxManager* mailbox_manager,
int client_id,
bool software,
gpu::gles2::ProgramCache* program_cache);
bool software);

bool Init(base::MessageLoopProxy* io_message_loop,
base::WaitableEvent* shutdown_event);
Expand Down Expand Up @@ -166,8 +161,6 @@ class GpuChannel : public IPC::Listener,
// are destroyed. So a raw pointer is safe.
GpuChannelManager* gpu_channel_manager_;

gpu::gles2::ProgramCache* program_cache_;

scoped_ptr<IPC::SyncChannel> channel_;

// Number of routed messages for pending processing on a stub.
Expand Down
16 changes: 3 additions & 13 deletions content/common/gpu/gpu_channel_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@
#include "content/common/gpu/gpu_channel_manager.h"

#include "base/bind.h"
#include "base/command_line.h"
#include "content/common/child_thread.h"
#include "content/common/gpu/gpu_channel.h"
#include "content/common/gpu/gpu_memory_manager.h"
#include "content/common/gpu/gpu_messages.h"
#include "content/common/gpu/sync_point_manager.h"
#include "gpu/command_buffer/service/gpu_switches.h"
#include "gpu/command_buffer/service/mailbox_manager.h"
#include "gpu/command_buffer/service/memory_program_cache.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_share_group.h"

GpuChannelManager::GpuChannelManager(ChildThread* gpu_child_thread,
Expand All @@ -28,13 +24,7 @@ GpuChannelManager::GpuChannelManager(ChildThread* gpu_child_thread,
ALLOW_THIS_IN_INITIALIZER_LIST(gpu_memory_manager_(this,
GpuMemoryManager::kDefaultMaxSurfacesWithFrontbufferSoftLimit)),
watchdog_(watchdog),
sync_point_manager_(new SyncPointManager),
program_cache_(
gfx::g_glProgramBinary &&
gfx::g_glGetProgramBinary &&
!CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableGpuProgramCache) ?
new gpu::gles2::MemoryProgramCache() : NULL) {
sync_point_manager_(new SyncPointManager) {
DCHECK(gpu_child_thread);
DCHECK(io_message_loop);
DCHECK(shutdown_event);
Expand Down Expand Up @@ -75,6 +65,7 @@ void GpuChannelManager::AppendAllCommandBufferStubs(
it != gpu_channels_.end(); ++it ) {
it->second->AppendAllCommandBufferStubs(stubs);
}

}

bool GpuChannelManager::OnMessageReceived(const IPC::Message& msg) {
Expand Down Expand Up @@ -114,8 +105,7 @@ void GpuChannelManager::OnEstablishChannel(int client_id, bool share_context) {
share_group,
mailbox_manager,
client_id,
false,
program_cache_.get());
false);
if (channel->Init(io_message_loop_, shutdown_event_)) {
gpu_channels_[client_id] = channel;
channel_handle.name = channel->GetChannelName();
Expand Down
5 changes: 0 additions & 5 deletions content/common/gpu/gpu_channel_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
#ifndef CONTENT_COMMON_GPU_GPU_CHANNEL_MANAGER_H_
#define CONTENT_COMMON_GPU_GPU_CHANNEL_MANAGER_H_

#include <vector>

#include "base/hash_tables.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/message_loop_proxy.h"
#include "build/build_config.h"
Expand All @@ -29,7 +26,6 @@ class GLShareGroup;
namespace gpu {
namespace gles2 {
class MailboxManager;
class ProgramCache;
}
}

Expand Down Expand Up @@ -120,7 +116,6 @@ class GpuChannelManager : public IPC::Listener,
GpuMemoryManager gpu_memory_manager_;
GpuWatchdog* watchdog_;
scoped_refptr<SyncPointManager> sync_point_manager_;
scoped_ptr<gpu::gles2::ProgramCache> program_cache_;

DISALLOW_COPY_AND_ASSIGN(GpuChannelManager);
};
Expand Down
7 changes: 2 additions & 5 deletions content/common/gpu/gpu_command_buffer_stub.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ GpuCommandBufferStub::GpuCommandBufferStub(
int32 surface_id,
GpuWatchdog* watchdog,
bool software,
const GURL& active_url,
gpu::gles2::ProgramCache* program_cache)
const GURL& active_url)
: channel_(channel),
handle_(handle),
initial_size_(size),
Expand All @@ -104,9 +103,7 @@ GpuCommandBufferStub::GpuCommandBufferStub(
if (share_group) {
context_group_ = share_group->context_group_;
} else {
context_group_ = new gpu::gles2::ContextGroup(mailbox_manager,
true,
program_cache);
context_group_ = new gpu::gles2::ContextGroup(mailbox_manager, true);
}
if (surface_id != 0)
surface_state_.reset(new GpuCommandBufferStubBase::SurfaceState(
Expand Down
5 changes: 2 additions & 3 deletions content/common/gpu/gpu_command_buffer_stub.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "base/observer_list.h"
#include "content/common/content_export.h"
#include "content/common/gpu/gpu_memory_allocation.h"
#include "content/common/gpu/gpu_memory_allocation.h"
#include "googleurl/src/gurl.h"
#include "gpu/command_buffer/common/constants.h"
#include "gpu/command_buffer/service/command_buffer_service.h"
Expand All @@ -40,7 +41,6 @@ class GpuWatchdog;

namespace gpu {
namespace gles2 {
class ProgramCache;
class MailboxManager;
}
}
Expand Down Expand Up @@ -105,8 +105,7 @@ class GpuCommandBufferStub
int32 surface_id,
GpuWatchdog* watchdog,
bool software,
const GURL& active_url,
gpu::gles2::ProgramCache* program_cache);
const GURL& active_url);

virtual ~GpuCommandBufferStub();

Expand Down
8 changes: 0 additions & 8 deletions gpu/command_buffer/common/gl_mock.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,6 @@ class MockGLInterface : public GLInterface {

MOCK_METHOD2(GetIntegerv, void(GLenum pname, GLint* params));

MOCK_METHOD5(GetProgramBinary, void(
GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat,
GLvoid* binary));

MOCK_METHOD3(GetProgramiv, void(GLuint program, GLenum pname, GLint* params));

MOCK_METHOD4(GetProgramInfoLog, void(
Expand Down Expand Up @@ -311,10 +307,6 @@ class MockGLInterface : public GLInterface {

MOCK_METHOD2(PolygonOffset, void(GLfloat factor, GLfloat units));

MOCK_METHOD4(ProgramBinary, void(
GLuint program, GLenum binaryFormat, const GLvoid* binary,
GLsizei length));

MOCK_METHOD2(QueryCounter, void(GLuint id, GLenum target));

MOCK_METHOD1(ReadBuffer, void(GLenum src));
Expand Down
7 changes: 2 additions & 5 deletions gpu/command_buffer/service/context_group.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "gpu/command_buffer/service/context_group.h"

#include <algorithm>
#include <string>

#include "base/command_line.h"
Expand All @@ -27,8 +26,7 @@ namespace gles2 {

ContextGroup::ContextGroup(
MailboxManager* mailbox_manager,
bool bind_generates_resource,
ProgramCache* program_cache)
bool bind_generates_resource)
: mailbox_manager_(mailbox_manager ? mailbox_manager : new MailboxManager),
num_contexts_(0),
enforce_gl_minimums_(CommandLine::ForCurrentProcess()->HasSwitch(
Expand All @@ -41,7 +39,6 @@ ContextGroup::ContextGroup(
max_fragment_uniform_vectors_(0u),
max_varying_vectors_(0u),
max_vertex_uniform_vectors_(0u),
program_cache_(program_cache),
feature_info_(new FeatureInfo()) {
{
TransferBufferManager* manager = new TransferBufferManager();
Expand Down Expand Up @@ -96,7 +93,7 @@ bool ContextGroup::Initialize(const DisallowedFeatures& disallowed_features,
renderbuffer_manager_.reset(new RenderbufferManager(
max_renderbuffer_size, max_samples));
shader_manager_.reset(new ShaderManager());
program_manager_.reset(new ProgramManager(program_cache_));
program_manager_.reset(new ProgramManager());

// Lookup GL things we need to know.
const GLint kGLES2RequiredMinimumVertexAttribs = 8u;
Expand Down
6 changes: 1 addition & 5 deletions gpu/command_buffer/service/context_group.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class TransferBufferManagerInterface;

namespace gles2 {

class ProgramCache;
class BufferManager;
class GLES2Decoder;
class FramebufferManager;
Expand All @@ -42,8 +41,7 @@ class GPU_EXPORT ContextGroup : public base::RefCounted<ContextGroup> {

ContextGroup(
MailboxManager* mailbox_manager,
bool bind_generates_resource,
ProgramCache* program_cache);
bool bind_generates_resource);

// This should only be called by GLES2Decoder. This must be paired with a
// call to destroy if it succeeds.
Expand Down Expand Up @@ -151,8 +149,6 @@ class GPU_EXPORT ContextGroup : public base::RefCounted<ContextGroup> {
uint32 max_varying_vectors_;
uint32 max_vertex_uniform_vectors_;

ProgramCache* program_cache_;

scoped_ptr<BufferManager> buffer_manager_;

scoped_ptr<FramebufferManager> framebuffer_manager_;
Expand Down
2 changes: 1 addition & 1 deletion gpu/command_buffer/service/context_group_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ContextGroupTest : public testing::Test {
virtual void SetUp() {
gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>());
::gfx::GLInterface::SetGLInterface(gl_.get());
group_ = ContextGroup::Ref(new ContextGroup(NULL, true, NULL));
group_ = ContextGroup::Ref(new ContextGroup(NULL, true));
}

virtual void TearDown() {
Expand Down
5 changes: 0 additions & 5 deletions gpu/command_buffer/service/gl_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,6 @@

#define GL_GLEXT_PROTOTYPES 1

// GL_OES_get_program_binary
#define GL_PROGRAM_BINARY_LENGTH_OES 0x8741
#define GL_NUM_PROGRAM_BINARY_FORMATS_OES 0x87FE
#define GL_PROGRAM_BINARY_FORMATS_OES 0x87FF

// Define this for extra GL error debugging (slower).
// #define GL_ERROR_DEBUGGING
#ifdef GL_ERROR_DEBUGGING
Expand Down
61 changes: 48 additions & 13 deletions gpu/command_buffer/service/gles2_cmd_decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#include "gpu/command_buffer/service/gles2_cmd_validation.h"
#include "gpu/command_buffer/service/gpu_switches.h"
#include "gpu/command_buffer/service/mailbox_manager.h"
#include "gpu/command_buffer/service/program_cache.h"
#include "gpu/command_buffer/service/program_manager.h"
#include "gpu/command_buffer/service/query_manager.h"
#include "gpu/command_buffer/service/renderbuffer_manager.h"
Expand Down Expand Up @@ -4720,16 +4719,7 @@ void GLES2DecoderImpl::DoLinkProgram(GLuint program) {
return;
}

ShaderTranslator* vertex_translator = NULL;
ShaderTranslator* fragment_translator = NULL;
if (use_shader_translator_) {
vertex_translator = vertex_translator_;
fragment_translator = fragment_translator_;
}
if (info->Link(shader_manager(),
vertex_translator,
fragment_translator,
feature_info_)) {
if (info->Link()) {
if (info == current_program_.get()) {
program_manager()->ClearUniforms(info);
}
Expand Down Expand Up @@ -5816,13 +5806,58 @@ void GLES2DecoderImpl::DoCompileShader(GLuint client_id) {
if (!info) {
return;
}
// Translate GL ES 2.0 shader to Desktop GL shader and pass that to
// glShaderSource and then glCompileShader.
const char* shader_src = info->source() ? info->source()->c_str() : "";
ShaderTranslator* translator = NULL;
if (use_shader_translator_) {
translator = info->shader_type() == GL_VERTEX_SHADER ?
vertex_translator_.get() : fragment_translator_.get();
}

program_manager()->DoCompileShader(info, translator, feature_info_);
if (!translator->Translate(shader_src)) {
info->SetStatus(false, translator->info_log(), NULL);
return;
}
shader_src = translator->translated_shader();
if (!feature_info_->feature_flags().angle_translated_shader_source)
info->UpdateTranslatedSource(shader_src);
}

glShaderSource(info->service_id(), 1, &shader_src, NULL);
glCompileShader(info->service_id());
if (feature_info_->feature_flags().angle_translated_shader_source) {
GLint max_len = 0;
glGetShaderiv(info->service_id(),
GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE,
&max_len);
scoped_array<char> temp(new char[max_len]);
GLint len = 0;
glGetTranslatedShaderSourceANGLE(
info->service_id(), max_len, &len, temp.get());
DCHECK(max_len == 0 || len < max_len);
DCHECK(len == 0 || temp[len] == '\0');
info->UpdateTranslatedSource(temp.get());
}

GLint status = GL_FALSE;
glGetShaderiv(info->service_id(), GL_COMPILE_STATUS, &status);
if (status) {
info->SetStatus(true, "", translator);
} else {
// We cannot reach here if we are using the shader translator.
// All invalid shaders must be rejected by the translator.
// All translated shaders must compile.
LOG_IF(ERROR, use_shader_translator_)
<< "Shader translator allowed/produced an invalid shader.";
GLint max_len = 0;
glGetShaderiv(info->service_id(), GL_INFO_LOG_LENGTH, &max_len);
scoped_array<char> temp(new char[max_len]);
GLint len = 0;
glGetShaderInfoLog(info->service_id(), max_len, &len, temp.get());
DCHECK(max_len == 0 || len < max_len);
DCHECK(len == 0 || temp[len] == '\0');
info->SetStatus(false, std::string(temp.get(), len).c_str(), NULL);
}
};

void GLES2DecoderImpl::DoGetShaderiv(
Expand Down
2 changes: 1 addition & 1 deletion gpu/command_buffer/service/gles2_cmd_decoder_unittest_1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ void GLES2DecoderTestBase::SpecializedSetup<GetProgramInfoLog, 0>(
attach_cmd.Init(client_program_id_, kClientFragmentShaderId);
EXPECT_EQ(error::kNoError, ExecuteCmd(attach_cmd));

info->Link(NULL, NULL, NULL, NULL);
info->Link();
};

template <>
Expand Down
Loading

0 comments on commit 7f1a51c

Please sign in to comment.