Skip to content

Commit

Permalink
Add glGetActiveUniformsiv to GPU command buffer.
Browse files Browse the repository at this point in the history
To improve performance, again we try to fetch all the info once through
an internal command glGetUniformsES3CHROMIUM.  Basically it gets all the
information that can be provided by glGetActiveUniformsiv except for those
that can already be queried through glGetActiveUniform, which will be cached
on the client side through internal command glGetProgramInfoCHROMIUM.

BUG=429053
TEST=gpu_unittests
R=piman@chromium.org
NOTRY=true

Review URL: https://codereview.chromium.org/921023002

Cr-Commit-Position: refs/heads/master@{#316666}
  • Loading branch information
zhenyao authored and Commit bot committed Feb 17, 2015
1 parent 96a2383 commit c7e7e13
Show file tree
Hide file tree
Showing 35 changed files with 1,459 additions and 289 deletions.
2 changes: 2 additions & 0 deletions gpu/GLES2/gl2chromium_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
#define glGetActiveUniform GLES2_GET_FUN(GetActiveUniform)
#define glGetActiveUniformBlockiv GLES2_GET_FUN(GetActiveUniformBlockiv)
#define glGetActiveUniformBlockName GLES2_GET_FUN(GetActiveUniformBlockName)
#define glGetActiveUniformsiv GLES2_GET_FUN(GetActiveUniformsiv)
#define glGetAttachedShaders GLES2_GET_FUN(GetAttachedShaders)
#define glGetAttribLocation GLES2_GET_FUN(GetAttribLocation)
#define glGetBooleanv GLES2_GET_FUN(GetBooleanv)
Expand Down Expand Up @@ -264,6 +265,7 @@
#define glGetUniformBlocksCHROMIUM GLES2_GET_FUN(GetUniformBlocksCHROMIUM)
#define glGetTransformFeedbackVaryingsCHROMIUM \
GLES2_GET_FUN(GetTransformFeedbackVaryingsCHROMIUM)
#define glGetUniformsES3CHROMIUM GLES2_GET_FUN(GetUniformsES3CHROMIUM)
#define glCreateStreamTextureCHROMIUM GLES2_GET_FUN(CreateStreamTextureCHROMIUM)
#define glCreateImageCHROMIUM GLES2_GET_FUN(CreateImageCHROMIUM)
#define glDestroyImageCHROMIUM GLES2_GET_FUN(DestroyImageCHROMIUM)
Expand Down
36 changes: 36 additions & 0 deletions gpu/command_buffer/build_gles2_cmd_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,22 @@
'GL_MOUSE_POSITION_CHROMIUM',
],
},
'UniformParameter': {
'type': 'GLenum',
'valid': [
'GL_UNIFORM_SIZE',
'GL_UNIFORM_TYPE',
'GL_UNIFORM_NAME_LENGTH',
'GL_UNIFORM_BLOCK_INDEX',
'GL_UNIFORM_OFFSET',
'GL_UNIFORM_ARRAY_STRIDE',
'GL_UNIFORM_MATRIX_STRIDE',
'GL_UNIFORM_IS_ROW_MAJOR',
],
'invalid': [
'GL_UNIFORM_BLOCK_NAME_LENGTH',
],
},
'UniformBlockParameter': {
'type': 'GLenum',
'valid': [
Expand Down Expand Up @@ -2064,6 +2080,15 @@
'result': ['int32_t'],
'unsafe': True,
},
'GetActiveUniformsiv': {
'type': 'Custom',
'data_transfer_methods': ['shm'],
'cmd_args':
'GLidProgram program, uint32_t indices_bucket_id, GLenum pname, '
'GLint* params',
'result': ['SizedResult<GLint>'],
'unsafe': True,
},
'GetAttachedShaders': {
'type': 'Custom',
'data_transfer_methods': ['shm'],
Expand Down Expand Up @@ -2255,6 +2280,17 @@
'result': ['uint32_t'],
'unsafe': True,
},
'GetUniformsES3CHROMIUM': {
'type': 'Custom',
'expectation': False,
'impl_func': False,
'extension': True,
'chromium': True,
'client_test': False,
'cmd_args': 'GLidProgram program, uint32_t bucket_id',
'result': ['uint32_t'],
'unsafe': True,
},
'GetTransformFeedbackVarying': {
'type': 'Custom',
'data_transfer_methods': ['shm'],
Expand Down
22 changes: 22 additions & 0 deletions gpu/command_buffer/client/gles2_c_lib_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,14 @@ void GLES2GetActiveUniformBlockName(GLuint program,
gles2::GetGLContext()->GetActiveUniformBlockName(program, index, bufsize,
length, name);
}
void GLES2GetActiveUniformsiv(GLuint program,
GLsizei count,
const GLuint* indices,
GLenum pname,
GLint* params) {
gles2::GetGLContext()->GetActiveUniformsiv(program, count, indices, pname,
params);
}
void GLES2GetAttachedShaders(GLuint program,
GLsizei maxcount,
GLsizei* count,
Expand Down Expand Up @@ -1090,6 +1098,12 @@ void GLES2GetTransformFeedbackVaryingsCHROMIUM(GLuint program,
gles2::GetGLContext()->GetTransformFeedbackVaryingsCHROMIUM(program, bufsize,
size, info);
}
void GLES2GetUniformsES3CHROMIUM(GLuint program,
GLsizei bufsize,
GLsizei* size,
void* info) {
gles2::GetGLContext()->GetUniformsES3CHROMIUM(program, bufsize, size, info);
}
GLuint GLES2CreateStreamTextureCHROMIUM(GLuint texture) {
return gles2::GetGLContext()->CreateStreamTextureCHROMIUM(texture);
}
Expand Down Expand Up @@ -1598,6 +1612,10 @@ extern const NameToFunc g_gles2_function_table[] = {
"glGetActiveUniformBlockName",
reinterpret_cast<GLES2FunctionPointer>(glGetActiveUniformBlockName),
},
{
"glGetActiveUniformsiv",
reinterpret_cast<GLES2FunctionPointer>(glGetActiveUniformsiv),
},
{
"glGetAttachedShaders",
reinterpret_cast<GLES2FunctionPointer>(glGetAttachedShaders),
Expand Down Expand Up @@ -2280,6 +2298,10 @@ extern const NameToFunc g_gles2_function_table[] = {
reinterpret_cast<GLES2FunctionPointer>(
glGetTransformFeedbackVaryingsCHROMIUM),
},
{
"glGetUniformsES3CHROMIUM",
reinterpret_cast<GLES2FunctionPointer>(glGetUniformsES3CHROMIUM),
},
{
"glCreateStreamTextureCHROMIUM",
reinterpret_cast<GLES2FunctionPointer>(glCreateStreamTextureCHROMIUM),
Expand Down
21 changes: 21 additions & 0 deletions gpu/command_buffer/client/gles2_cmd_helper_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,19 @@ void GetActiveUniformBlockName(GLuint program,
}
}

void GetActiveUniformsiv(GLuint program,
uint32_t indices_bucket_id,
GLenum pname,
uint32_t params_shm_id,
uint32_t params_shm_offset) {
gles2::cmds::GetActiveUniformsiv* c =
GetCmdSpace<gles2::cmds::GetActiveUniformsiv>();
if (c) {
c->Init(program, indices_bucket_id, pname, params_shm_id,
params_shm_offset);
}
}

void GetAttachedShaders(GLuint program,
uint32_t result_shm_id,
uint32_t result_shm_offset,
Expand Down Expand Up @@ -2227,6 +2240,14 @@ void GetTransformFeedbackVaryingsCHROMIUM(GLuint program, uint32_t bucket_id) {
}
}

void GetUniformsES3CHROMIUM(GLuint program, uint32_t bucket_id) {
gles2::cmds::GetUniformsES3CHROMIUM* c =
GetCmdSpace<gles2::cmds::GetUniformsES3CHROMIUM>();
if (c) {
c->Init(program, bucket_id);
}
}

void GetTranslatedShaderSourceANGLE(GLuint shader, uint32_t bucket_id) {
gles2::cmds::GetTranslatedShaderSourceANGLE* c =
GetCmdSpace<gles2::cmds::GetTranslatedShaderSourceANGLE>();
Expand Down
111 changes: 107 additions & 4 deletions gpu/command_buffer/client/gles2_implementation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2456,7 +2456,7 @@ void GLES2Implementation::GetActiveUniformBlockiv(
GPU_CLIENT_SINGLE_THREAD_CHECK();
GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glGetActiveUniformBlockiv("
<< program << ", " << index << ", "
<< GLES2Util::GetStringProgramParameter(pname) << ", "
<< GLES2Util::GetStringUniformBlockParameter(pname) << ", "
<< static_cast<const void*>(params) << ")");
TRACE_EVENT0("gpu", "GLES2::GetActiveUniformBlockiv");
bool success =
Expand All @@ -2472,6 +2472,68 @@ void GLES2Implementation::GetActiveUniformBlockiv(
CheckGLError();
}

bool GLES2Implementation::GetActiveUniformsivHelper(
GLuint program, GLsizei count, const GLuint* indices,
GLenum pname, GLint* params) {
typedef cmds::GetActiveUniformsiv::Result Result;
Result* result = GetResultAs<Result*>();
if (!result) {
return false;
}
result->SetNumResults(0);
base::CheckedNumeric<size_t> bytes = static_cast<size_t>(count);
bytes *= sizeof(GLuint);
if (!bytes.IsValid()) {
SetGLError(GL_INVALID_VALUE, "glGetActiveUniformsiv", "count overflow");
return false;
}
SetBucketContents(kResultBucketId, indices, bytes.ValueOrDefault(0));
helper_->GetActiveUniformsiv(
program, kResultBucketId, pname, GetResultShmId(), GetResultShmOffset());
WaitForCmd();
bool success = result->GetNumResults() == count;
if (success) {
if (params) {
result->CopyResult(params);
}
GPU_CLIENT_LOG_CODE_BLOCK({
for (int32_t i = 0; i < result->GetNumResults(); ++i) {
GPU_CLIENT_LOG(" " << i << ": " << result->GetData()[i]);
}
});
}
helper_->SetBucketSize(kResultBucketId, 0);
return success;
}

void GLES2Implementation::GetActiveUniformsiv(
GLuint program, GLsizei count, const GLuint* indices,
GLenum pname, GLint* params) {
GPU_CLIENT_SINGLE_THREAD_CHECK();
GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glGetActiveUniformsiv("
<< program << ", " << count << ", "
<< static_cast<const void*>(indices) << ", "
<< GLES2Util::GetStringUniformParameter(pname) << ", "
<< static_cast<const void*>(params) << ")");
TRACE_EVENT0("gpu", "GLES2::GetActiveUniformsiv");
if (count < 0) {
SetGLError(GL_INVALID_VALUE, "glGetActiveUniformsiv", "count < 0");
return;
}
bool success = share_group_->program_info_manager()->GetActiveUniformsiv(
this, program, count, indices, pname, params);
if (success) {
if (params) {
GPU_CLIENT_LOG_CODE_BLOCK({
for (GLsizei ii = 0; ii < count; ++ii) {
GPU_CLIENT_LOG(" " << ii << ": " << params[ii]);
}
});
}
}
CheckGLError();
}

void GLES2Implementation::GetAttachedShaders(
GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders) {
GPU_CLIENT_SINGLE_THREAD_CHECK();
Expand Down Expand Up @@ -3798,11 +3860,11 @@ void GLES2Implementation::GetUniformBlocksCHROMIUM(
GPU_CLIENT_SINGLE_THREAD_CHECK();
if (bufsize < 0) {
SetGLError(
GL_INVALID_VALUE, "glUniformBlocksCHROMIUM", "bufsize less than 0.");
GL_INVALID_VALUE, "glGetUniformBlocksCHROMIUM", "bufsize less than 0.");
return;
}
if (size == NULL) {
SetGLError(GL_INVALID_VALUE, "glUniformBlocksCHROMIUM", "size is null.");
SetGLError(GL_INVALID_VALUE, "glGetUniformBlocksCHROMIUM", "size is null.");
return;
}
// Make sure they've set size to 0 else the value will be undefined on
Expand All @@ -3817,9 +3879,50 @@ void GLES2Implementation::GetUniformBlocksCHROMIUM(
if (!info) {
return;
}
if (static_cast<size_t>(bufsize) < result.size()) {
SetGLError(GL_INVALID_OPERATION, "glGetUniformBlocksCHROMIUM",
"bufsize is too small for result.");
return;
}
memcpy(info, &result[0], result.size());
}

void GLES2Implementation::GetUniformsES3CHROMIUMHelper(
GLuint program, std::vector<int8>* result) {
DCHECK(result);
// Clear the bucket so if the command fails nothing will be in it.
helper_->SetBucketSize(kResultBucketId, 0);
helper_->GetUniformsES3CHROMIUM(program, kResultBucketId);
GetBucketContents(kResultBucketId, result);
}

void GLES2Implementation::GetUniformsES3CHROMIUM(
GLuint program, GLsizei bufsize, GLsizei* size, void* info) {
GPU_CLIENT_SINGLE_THREAD_CHECK();
if (bufsize < 0) {
SetGLError(
GL_INVALID_VALUE, "glGetUniformsES3CHROMIUM", "bufsize less than 0.");
return;
}
if (size == NULL) {
SetGLError(GL_INVALID_VALUE, "glGetUniformsES3CHROMIUM", "size is null.");
return;
}
// Make sure they've set size to 0 else the value will be undefined on
// lost context.
DCHECK_EQ(0, *size);
std::vector<int8> result;
GetUniformsES3CHROMIUMHelper(program, &result);
if (result.empty()) {
return;
}
*size = result.size();
if (!info) {
return;
}
if (static_cast<size_t>(bufsize) < result.size()) {
SetGLError(GL_INVALID_OPERATION,
"glUniformBlocksCHROMIUM", "bufsize is too small for result.");
"glGetUniformsES3CHROMIUM", "bufsize is too small for result.");
return;
}
memcpy(info, &result[0], result.size());
Expand Down
5 changes: 5 additions & 0 deletions gpu/command_buffer/client/gles2_implementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ class GLES2_IMPL_EXPORT GLES2Implementation
GLint* size, GLenum* type, char* name);
void GetUniformBlocksCHROMIUMHelper(
GLuint program, std::vector<int8>* result);
void GetUniformsES3CHROMIUMHelper(
GLuint program, std::vector<int8>* result);
GLuint GetUniformBlockIndexHelper(GLuint program, const char* name);
bool GetActiveUniformBlockNameHelper(
GLuint program, GLuint index, GLsizei bufsize,
Expand All @@ -235,6 +237,9 @@ class GLES2_IMPL_EXPORT GLES2Implementation
GLint* size, GLenum* type, char* name);
bool GetUniformIndicesHelper(
GLuint program, GLsizei count, const char* const* names, GLuint* indices);
bool GetActiveUniformsivHelper(
GLuint program, GLsizei count, const GLuint* indices,
GLenum pname, GLint* params);

void FreeUnusedSharedMemory();
void FreeEverything();
Expand Down
11 changes: 11 additions & 0 deletions gpu/command_buffer/client/gles2_implementation_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,12 @@ void GetActiveUniformBlockName(GLuint program,
GLsizei* length,
char* name) override;

void GetActiveUniformsiv(GLuint program,
GLsizei count,
const GLuint* indices,
GLenum pname,
GLint* params) override;

void GetAttachedShaders(GLuint program,
GLsizei maxcount,
GLsizei* count,
Expand Down Expand Up @@ -819,6 +825,11 @@ void GetTransformFeedbackVaryingsCHROMIUM(GLuint program,
GLsizei* size,
void* info) override;

void GetUniformsES3CHROMIUM(GLuint program,
GLsizei bufsize,
GLsizei* size,
void* info) override;

GLuint CreateStreamTextureCHROMIUM(GLuint texture) override;

GLuint CreateImageCHROMIUM(ClientBuffer buffer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,7 @@ TEST_F(GLES2ImplementationTest, GenTransformFeedbacks) {
// TODO(zmo): Implement unit test for GetActiveUniform
// TODO(zmo): Implement unit test for GetActiveUniformBlockiv
// TODO(zmo): Implement unit test for GetActiveUniformBlockName
// TODO(zmo): Implement unit test for GetActiveUniformsiv
// TODO(zmo): Implement unit test for GetAttachedShaders
// TODO(zmo): Implement unit test for GetAttribLocation

Expand Down
9 changes: 9 additions & 0 deletions gpu/command_buffer/client/gles2_interface_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ virtual void GetActiveUniformBlockName(GLuint program,
GLsizei bufsize,
GLsizei* length,
char* name) = 0;
virtual void GetActiveUniformsiv(GLuint program,
GLsizei count,
const GLuint* indices,
GLenum pname,
GLint* params) = 0;
virtual void GetAttachedShaders(GLuint program,
GLsizei maxcount,
GLsizei* count,
Expand Down Expand Up @@ -597,6 +602,10 @@ virtual void GetTransformFeedbackVaryingsCHROMIUM(GLuint program,
GLsizei bufsize,
GLsizei* size,
void* info) = 0;
virtual void GetUniformsES3CHROMIUM(GLuint program,
GLsizei bufsize,
GLsizei* size,
void* info) = 0;
virtual GLuint CreateStreamTextureCHROMIUM(GLuint texture) = 0;
virtual GLuint CreateImageCHROMIUM(ClientBuffer buffer,
GLsizei width,
Expand Down
9 changes: 9 additions & 0 deletions gpu/command_buffer/client/gles2_interface_stub_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ void GetActiveUniformBlockName(GLuint program,
GLsizei bufsize,
GLsizei* length,
char* name) override;
void GetActiveUniformsiv(GLuint program,
GLsizei count,
const GLuint* indices,
GLenum pname,
GLint* params) override;
void GetAttachedShaders(GLuint program,
GLsizei maxcount,
GLsizei* count,
Expand Down Expand Up @@ -582,6 +587,10 @@ void GetTransformFeedbackVaryingsCHROMIUM(GLuint program,
GLsizei bufsize,
GLsizei* size,
void* info) override;
void GetUniformsES3CHROMIUM(GLuint program,
GLsizei bufsize,
GLsizei* size,
void* info) override;
GLuint CreateStreamTextureCHROMIUM(GLuint texture) override;
GLuint CreateImageCHROMIUM(ClientBuffer buffer,
GLsizei width,
Expand Down
Loading

0 comments on commit c7e7e13

Please sign in to comment.