Skip to content

Commit

Permalink
Add glTraceBeginCHROMIUM and glTraceEndCHROMIUM.
Browse files Browse the repository at this point in the history
This is currently implemented as a no-op on the server side.
When implemented the glTraceBegin will issue a trace timestamp into
the GPU message stream. The glTraceEnd will issue another timestamp
into the GPU stream. Eventually, when the two timers have been
exeucted by the GPU, an event will be sent to about:tracing with the
relevant timeing information.

BUG=111509


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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@168323 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
dsinclair@chromium.org committed Nov 16, 2012
1 parent 295f532 commit 9430771
Show file tree
Hide file tree
Showing 21 changed files with 308 additions and 1 deletion.
15 changes: 15 additions & 0 deletions gpu/command_buffer/build_gles2_cmd_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2205,6 +2205,21 @@
'extension': True,
'chromium': True,
},
'TraceBeginCHROMIUM': {
'type': 'Custom',
'impl_func': False,
'immediate': False,
'client_test': False,
'cmd_args': 'GLuint bucket_id',
'extension': True,
'chromium': True,
},
'TraceEndCHROMIUM': {
'decoder_func': 'DoTraceEndCHROMIUM',
'unit_test': False,
'extension': True,
'chromium': True,
},
}


Expand Down
6 changes: 6 additions & 0 deletions gpu/command_buffer/client/gles2_c_lib_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,12 @@ void GLES2BindTexImage2DCHROMIUM(GLenum target, GLint imageId) {
void GLES2ReleaseTexImage2DCHROMIUM(GLenum target, GLint imageId) {
gles2::GetGLContext()->ReleaseTexImage2DCHROMIUM(target, imageId);
}
void GLES2TraceBeginCHROMIUM(const char* name) {
gles2::GetGLContext()->TraceBeginCHROMIUM(name);
}
void GLES2TraceEndCHROMIUM() {
gles2::GetGLContext()->TraceEndCHROMIUM();
}

#endif // GPU_COMMAND_BUFFER_CLIENT_GLES2_C_LIB_AUTOGEN_H_

14 changes: 14 additions & 0 deletions gpu/command_buffer/client/gles2_cmd_helper_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -1918,5 +1918,19 @@
}
}

void TraceBeginCHROMIUM(GLuint bucket_id) {
gles2::TraceBeginCHROMIUM* c = GetCmdSpace<gles2::TraceBeginCHROMIUM>();
if (c) {
c->Init(bucket_id);
}
}

void TraceEndCHROMIUM() {
gles2::TraceEndCHROMIUM* c = GetCmdSpace<gles2::TraceEndCHROMIUM>();
if (c) {
c->Init();
}
}

#endif // GPU_COMMAND_BUFFER_CLIENT_GLES2_CMD_HELPER_AUTOGEN_H_

10 changes: 10 additions & 0 deletions gpu/command_buffer/client/gles2_implementation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3459,6 +3459,16 @@ void GLES2Implementation::PopGroupMarkerEXT() {
debug_marker_manager_.PopGroup();
}

void GLES2Implementation::TraceBeginCHROMIUM(const char* name) {
GPU_CLIENT_SINGLE_THREAD_CHECK();
GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glTraceBeginCHROMIUM("
<< name << ")");

SetBucketAsCString(kResultBucketId, name);
helper_->TraceBeginCHROMIUM(kResultBucketId);
helper_->SetBucketSize(kResultBucketId, 0);
}

// Include the auto-generated part of this file. We split this because it means
// we can easily edit the non-auto generated parts right here in this file
// instead of having to edit some template or the code generator.
Expand Down
4 changes: 4 additions & 0 deletions gpu/command_buffer/client/gles2_implementation_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -502,5 +502,9 @@ virtual void BindTexImage2DCHROMIUM(GLenum target, GLint imageId) OVERRIDE;

virtual void ReleaseTexImage2DCHROMIUM(GLenum target, GLint imageId) OVERRIDE;

virtual void TraceBeginCHROMIUM(const char* name) OVERRIDE;

virtual void TraceEndCHROMIUM() OVERRIDE;

#endif // GPU_COMMAND_BUFFER_CLIENT_GLES2_IMPLEMENTATION_AUTOGEN_H_

6 changes: 6 additions & 0 deletions gpu/command_buffer/client/gles2_implementation_impl_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -1513,5 +1513,11 @@ void GLES2Implementation::ReleaseTexImage2DCHROMIUM(
helper_->ReleaseTexImage2DCHROMIUM(target, imageId);
}

void GLES2Implementation::TraceEndCHROMIUM() {
GPU_CLIENT_SINGLE_THREAD_CHECK();
GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glTraceEndCHROMIUM(" << ")");
helper_->TraceEndCHROMIUM();
}

#endif // GPU_COMMAND_BUFFER_CLIENT_GLES2_IMPLEMENTATION_IMPL_AUTOGEN_H_

11 changes: 11 additions & 0 deletions gpu/command_buffer/client/gles2_implementation_unittest_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -1786,5 +1786,16 @@ TEST_F(GLES2ImplementationTest, ReleaseTexImage2DCHROMIUM) {
gl_->ReleaseTexImage2DCHROMIUM(GL_TEXTURE_2D, 2);
EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected)));
}

TEST_F(GLES2ImplementationTest, TraceEndCHROMIUM) {
struct Cmds {
TraceEndCHROMIUM cmd;
};
Cmds expected;
expected.cmd.Init();

gl_->TraceEndCHROMIUM();
EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected)));
}
#endif // GPU_COMMAND_BUFFER_CLIENT_GLES2_IMPLEMENTATION_UNITTEST_AUTOGEN_H_

2 changes: 2 additions & 0 deletions gpu/command_buffer/client/gles2_interface_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,5 +288,7 @@ virtual void BindUniformLocationCHROMIUM(
GLuint program, GLint location, const char* name) = 0;
virtual void BindTexImage2DCHROMIUM(GLenum target, GLint imageId) = 0;
virtual void ReleaseTexImage2DCHROMIUM(GLenum target, GLint imageId) = 0;
virtual void TraceBeginCHROMIUM(const char* name) = 0;
virtual void TraceEndCHROMIUM() = 0;
#endif // GPU_COMMAND_BUFFER_CLIENT_GLES2_INTERFACE_AUTOGEN_H_

2 changes: 2 additions & 0 deletions gpu/command_buffer/client/gles2_interface_stub_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,5 +320,7 @@ virtual void BindUniformLocationCHROMIUM(
GLuint program, GLint location, const char* name) OVERRIDE;
virtual void BindTexImage2DCHROMIUM(GLenum target, GLint imageId) OVERRIDE;
virtual void ReleaseTexImage2DCHROMIUM(GLenum target, GLint imageId) OVERRIDE;
virtual void TraceBeginCHROMIUM(const char* name) OVERRIDE;
virtual void TraceEndCHROMIUM() OVERRIDE;
#endif // GPU_COMMAND_BUFFER_CLIENT_GLES2_INTERFACE_STUB_AUTOGEN_H_

4 changes: 4 additions & 0 deletions gpu/command_buffer/client/gles2_interface_stub_impl_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -602,5 +602,9 @@ void GLES2InterfaceStub::BindTexImage2DCHROMIUM(
void GLES2InterfaceStub::ReleaseTexImage2DCHROMIUM(
GLenum /* target */, GLint /* imageId */) {
}
void GLES2InterfaceStub::TraceBeginCHROMIUM(const char* /* name */) {
}
void GLES2InterfaceStub::TraceEndCHROMIUM() {
}
#endif // GPU_COMMAND_BUFFER_CLIENT_GLES2_INTERFACE_STUB_IMPL_AUTOGEN_H_

2 changes: 2 additions & 0 deletions gpu/command_buffer/cmd_buffer_functions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,5 @@ GL_APICALL void GL_APIENTRY glConsumeTextureCHROMIUM (GLenumTextureTarge
GL_APICALL void GL_APIENTRY glBindUniformLocationCHROMIUM (GLidProgram program, GLint location, const char* name);
GL_APICALL void GL_APIENTRY glBindTexImage2DCHROMIUM (GLenumTextureBindTarget target, GLint imageId);
GL_APICALL void GL_APIENTRY glReleaseTexImage2DCHROMIUM (GLenumTextureBindTarget target, GLint imageId);
GL_APICALL void GL_APIENTRY glTraceBeginCHROMIUM (const char* name);
GL_APICALL void GL_APIENTRY glTraceEndCHROMIUM (void);
64 changes: 64 additions & 0 deletions gpu/command_buffer/common/gles2_cmd_format_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -10508,6 +10508,70 @@ COMPILE_ASSERT(offsetof(ReleaseTexImage2DCHROMIUM, target) == 4,
COMPILE_ASSERT(offsetof(ReleaseTexImage2DCHROMIUM, imageId) == 8,
OffsetOf_ReleaseTexImage2DCHROMIUM_imageId_not_8);

struct TraceBeginCHROMIUM {
typedef TraceBeginCHROMIUM ValueType;
static const CommandId kCmdId = kTraceBeginCHROMIUM;
static const cmd::ArgFlags kArgFlags = cmd::kFixed;

static uint32 ComputeSize() {
return static_cast<uint32>(sizeof(ValueType)); // NOLINT
}

void SetHeader() {
header.SetCmd<ValueType>();
}

void Init(GLuint _bucket_id) {
SetHeader();
bucket_id = _bucket_id;
}

void* Set(void* cmd, GLuint _bucket_id) {
static_cast<ValueType*>(cmd)->Init(_bucket_id);
return NextCmdAddress<ValueType>(cmd);
}

gpu::CommandHeader header;
uint32 bucket_id;
};

COMPILE_ASSERT(sizeof(TraceBeginCHROMIUM) == 8,
Sizeof_TraceBeginCHROMIUM_is_not_8);
COMPILE_ASSERT(offsetof(TraceBeginCHROMIUM, header) == 0,
OffsetOf_TraceBeginCHROMIUM_header_not_0);
COMPILE_ASSERT(offsetof(TraceBeginCHROMIUM, bucket_id) == 4,
OffsetOf_TraceBeginCHROMIUM_bucket_id_not_4);

struct TraceEndCHROMIUM {
typedef TraceEndCHROMIUM ValueType;
static const CommandId kCmdId = kTraceEndCHROMIUM;
static const cmd::ArgFlags kArgFlags = cmd::kFixed;

static uint32 ComputeSize() {
return static_cast<uint32>(sizeof(ValueType)); // NOLINT
}

void SetHeader() {
header.SetCmd<ValueType>();
}

void Init() {
SetHeader();
}

void* Set(void* cmd) {
static_cast<ValueType*>(cmd)->Init();
return NextCmdAddress<ValueType>(cmd);
}

gpu::CommandHeader header;
};

COMPILE_ASSERT(sizeof(TraceEndCHROMIUM) == 4,
Sizeof_TraceEndCHROMIUM_is_not_4);
COMPILE_ASSERT(offsetof(TraceEndCHROMIUM, header) == 0,
OffsetOf_TraceEndCHROMIUM_header_not_0);


#endif // GPU_COMMAND_BUFFER_COMMON_GLES2_CMD_FORMAT_AUTOGEN_H_

24 changes: 24 additions & 0 deletions gpu/command_buffer/common/gles2_cmd_format_test_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -4232,5 +4232,29 @@ TEST_F(GLES2FormatTest, ReleaseTexImage2DCHROMIUM) {
next_cmd, sizeof(cmd));
}

TEST_F(GLES2FormatTest, TraceBeginCHROMIUM) {
TraceBeginCHROMIUM& cmd = *GetBufferAs<TraceBeginCHROMIUM>();
void* next_cmd = cmd.Set(
&cmd,
static_cast<GLuint>(11));
EXPECT_EQ(static_cast<uint32>(TraceBeginCHROMIUM::kCmdId),
cmd.header.command);
EXPECT_EQ(sizeof(cmd), cmd.header.size * 4u);
EXPECT_EQ(static_cast<GLuint>(11), cmd.bucket_id);
CheckBytesWrittenMatchesExpectedSize(
next_cmd, sizeof(cmd));
}

TEST_F(GLES2FormatTest, TraceEndCHROMIUM) {
TraceEndCHROMIUM& cmd = *GetBufferAs<TraceEndCHROMIUM>();
void* next_cmd = cmd.Set(
&cmd);
EXPECT_EQ(static_cast<uint32>(TraceEndCHROMIUM::kCmdId),
cmd.header.command);
EXPECT_EQ(sizeof(cmd), cmd.header.size * 4u);
CheckBytesWrittenMatchesExpectedSize(
next_cmd, sizeof(cmd));
}

#endif // GPU_COMMAND_BUFFER_COMMON_GLES2_CMD_FORMAT_TEST_AUTOGEN_H_

2 changes: 2 additions & 0 deletions gpu/command_buffer/common/gles2_cmd_ids_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@
OP(BindUniformLocationCHROMIUMBucket) /* 484 */ \
OP(BindTexImage2DCHROMIUM) /* 485 */ \
OP(ReleaseTexImage2DCHROMIUM) /* 486 */ \
OP(TraceBeginCHROMIUM) /* 487 */ \
OP(TraceEndCHROMIUM) /* 488 */ \

enum CommandId {
kStartPoint = cmd::kLastCommonId, // All GLES2 commands start after this.
Expand Down
36 changes: 36 additions & 0 deletions gpu/command_buffer/service/gles2_cmd_decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <algorithm>
#include <list>
#include <map>
#include <stack>
#include <string>
#include <vector>

Expand Down Expand Up @@ -39,6 +40,7 @@
#include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h"
#include "gpu/command_buffer/service/gles2_cmd_validation.h"
#include "gpu/command_buffer/service/gpu_switches.h"
#include "gpu/command_buffer/service/gpu_trace.h"
#include "gpu/command_buffer/service/image_manager.h"
#include "gpu/command_buffer/service/mailbox_manager.h"
#include "gpu/command_buffer/service/memory_tracking.h"
Expand Down Expand Up @@ -771,6 +773,8 @@ class GLES2DecoderImpl : public base::SupportsWeakPtr<GLES2DecoderImpl>,
GLenum target,
GLint image_id);

void DoTraceEndCHROMIUM(void);

// Creates a ProgramInfo for the given program.
ProgramManager::ProgramInfo* CreateProgramInfo(
GLuint client_id, GLuint service_id) {
Expand Down Expand Up @@ -1574,6 +1578,8 @@ class GLES2DecoderImpl : public base::SupportsWeakPtr<GLES2DecoderImpl>,
base::TimeDelta total_texture_upload_time_;
base::TimeDelta total_processing_commands_time_;

std::stack<linked_ptr<GPUTrace> > gpu_trace_stack_;

DISALLOW_COPY_AND_ASSIGN(GLES2DecoderImpl);
};

Expand Down Expand Up @@ -9324,6 +9330,36 @@ void GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM(
GL_RGBA, GL_UNSIGNED_BYTE, false);
}

error::Error GLES2DecoderImpl::HandleTraceBeginCHROMIUM(
uint32 immediate_data_size, const gles2::TraceBeginCHROMIUM& c) {
Bucket* bucket = GetBucket(c.bucket_id);
if (!bucket || bucket->size() == 0) {
return error::kInvalidArguments;
}
std::string command_name;
if (!bucket->GetAsString(&command_name)) {
return error::kInvalidArguments;
}

linked_ptr<GPUTrace> trace(new GPUTrace(command_name));
trace->EnableStartTrace();
gpu_trace_stack_.push(trace);

return error::kNoError;
}

void GLES2DecoderImpl::DoTraceEndCHROMIUM() {
if (gpu_trace_stack_.empty()) {
SetGLError(GL_INVALID_OPERATION,
"glTraceEndCHROMIUM", "no trace begin found");
return;
}

linked_ptr<GPUTrace> trace = gpu_trace_stack_.top();
trace->EnableEndTrace();
gpu_trace_stack_.pop();
}

// Include the auto-generated part of this file. We split this because it means
// we can easily edit the non-auto generated parts right here in this file
// instead of having to edit some template or the code generator.
Expand Down
6 changes: 6 additions & 0 deletions gpu/command_buffer/service/gles2_cmd_decoder_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -3093,6 +3093,12 @@ error::Error GLES2DecoderImpl::HandleReleaseTexImage2DCHROMIUM(
return error::kNoError;
}

error::Error GLES2DecoderImpl::HandleTraceEndCHROMIUM(
uint32 immediate_data_size, const gles2::TraceEndCHROMIUM& c) {
DoTraceEndCHROMIUM();
return error::kNoError;
}


bool GLES2DecoderImpl::SetCapabilityState(GLenum cap, bool enabled) {
switch (cap) {
Expand Down
31 changes: 30 additions & 1 deletion gpu/command_buffer/service/gles2_cmd_decoder_unittest_3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,37 @@ class GLES2DecoderTest3 : public GLES2DecoderTestBase {
GLES2DecoderTest3() { }
};

TEST_F(GLES2DecoderTest3, TraceBeginCHROMIUM) {
const uint32 kBucketId = 123;
const char kName[] = "test_command";
SetBucketAsCString(kBucketId, kName);

TraceBeginCHROMIUM begin_cmd;
begin_cmd.Init(kBucketId);
EXPECT_EQ(error::kNoError, ExecuteCmd(begin_cmd));
}

TEST_F(GLES2DecoderTest3, TraceEndCHROMIUM) {
// Test end fails if no begin.
TraceEndCHROMIUM end_cmd;
end_cmd.Init();
EXPECT_EQ(error::kNoError, ExecuteCmd(end_cmd));
EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());

const uint32 kBucketId = 123;
const char kName[] = "test_command";
SetBucketAsCString(kBucketId, kName);

TraceBeginCHROMIUM begin_cmd;
begin_cmd.Init(kBucketId);
EXPECT_EQ(error::kNoError, ExecuteCmd(begin_cmd));

end_cmd.Init();
EXPECT_EQ(error::kNoError, ExecuteCmd(end_cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
}

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

} // namespace gles2
} // namespace gpu

Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,8 @@
// TODO(gman): BindUniformLocationCHROMIUMBucket
// TODO(gman): BindTexImage2DCHROMIUM
// TODO(gman): ReleaseTexImage2DCHROMIUM
// TODO(gman): TraceBeginCHROMIUM

// TODO(gman): TraceEndCHROMIUM
#endif // GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_DECODER_UNITTEST_3_AUTOGEN_H_

Loading

0 comments on commit 9430771

Please sign in to comment.