diff options
author | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-07 23:28:11 +0000 |
---|---|---|
committer | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-07 23:28:11 +0000 |
commit | 302ce6d93bce9050a23f3d02cf7c36d2a9d9a153 (patch) | |
tree | 29a7f80e9011493ba920f57124259c77efb66f88 /gpu | |
parent | 53d887fe6cc732e8baf180e8d76b7d03b6425659 (diff) | |
download | chromium_src-302ce6d93bce9050a23f3d02cf7c36d2a9d9a153.zip chromium_src-302ce6d93bce9050a23f3d02cf7c36d2a9d9a153.tar.gz chromium_src-302ce6d93bce9050a23f3d02cf7c36d2a9d9a153.tar.bz2 |
Correct reporting of compressed texture formats and shader binary formats
NOTE: There's an issue here that before this change
the largest number of values returned by glGetXXX was 4
and now it's undefined. The issue will come up if there
are ever more than 15 because the GLES2Implementation
only currently handles 15.
See GLES2Implementation::kMaxSizeOfSimpleResult.
http://code.google.com/p/chromium/issues/detail?id=88227
TEST=unit tests
BUG=none
Review URL: http://codereview.chromium.org/7304002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91781 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu')
12 files changed, 201 insertions, 19 deletions
diff --git a/gpu/command_buffer/build_gles2_cmd_buffer.py b/gpu/command_buffer/build_gles2_cmd_buffer.py index a530629..479acb8 100755 --- a/gpu/command_buffer/build_gles2_cmd_buffer.py +++ b/gpu/command_buffer/build_gles2_cmd_buffer.py @@ -155,7 +155,7 @@ GL_APICALL void GL_APIENTRY glReleaseShaderCompiler (void); GL_APICALL void GL_APIENTRY glRenderbufferStorage (GLenumRenderBufferTarget target, GLenumRenderBufferFormat internalformat, GLsizei width, GLsizei height); GL_APICALL void GL_APIENTRY glSampleCoverage (GLclampf value, GLboolean invert); GL_APICALL void GL_APIENTRY glScissor (GLint x, GLint y, GLsizei width, GLsizei height); -GL_APICALL void GL_APIENTRY glShaderBinary (GLsizeiNotNegative n, const GLuint* shaders, GLenum binaryformat, const void* binary, GLsizeiNotNegative length); +GL_APICALL void GL_APIENTRY glShaderBinary (GLsizeiNotNegative n, const GLuint* shaders, GLenumShaderBinaryFormat binaryformat, const void* binary, GLsizeiNotNegative length); GL_APICALL void GL_APIENTRY glShaderSource (GLidShader shader, GLsizeiNotNegative count, const char** str, const GLint* length); GL_APICALL void GL_APIENTRY glStencilFunc (GLenumCmpFunction func, GLint ref, GLuint mask); GL_APICALL void GL_APIENTRY glStencilFuncSeparate (GLenumFaceType face, GLenumCmpFunction func, GLint ref, GLuint mask); @@ -967,6 +967,11 @@ _ENUM_LISTS = { 'GL_STENCIL_INDEX8', ], }, + 'ShaderBinaryFormat': { + 'type': 'GLenum', + 'valid': [ + ], + }, 'StencilOp': { 'type': 'GLenum', 'valid': [ diff --git a/gpu/command_buffer/client/gles2_implementation.cc b/gpu/command_buffer/client/gles2_implementation.cc index 6afdbd7..8ef17af 100644 --- a/gpu/command_buffer/client/gles2_implementation.cc +++ b/gpu/command_buffer/client/gles2_implementation.cc @@ -434,8 +434,7 @@ GLES2Implementation::GLES2Implementation( void* transfer_buffer, int32 transfer_buffer_id, bool share_resources) - : util_(0), // TODO(gman): Get real number of compressed texture formats. - helper_(helper), + : helper_(helper), transfer_buffer_( kStartingOffset, transfer_buffer_size - kStartingOffset, @@ -496,6 +495,11 @@ GLES2Implementation::GLES2Implementation( GL_NUM_SHADER_BINARY_FORMATS, }; + util_.set_num_compressed_texture_formats( + gl_state_.num_compressed_texture_formats); + util_.set_num_shader_binary_formats( + gl_state_.num_shader_binary_formats); + GetMultipleIntegervCHROMIUM( pnames, arraysize(pnames), &gl_state_.max_combined_texture_image_units, sizeof(gl_state_)); diff --git a/gpu/command_buffer/common/gles2_cmd_utils.cc b/gpu/command_buffer/common/gles2_cmd_utils.cc index bcdb9f1..0f8d67b 100644 --- a/gpu/command_buffer/common/gles2_cmd_utils.cc +++ b/gpu/command_buffer/common/gles2_cmd_utils.cc @@ -150,6 +150,8 @@ int GLES2Util::GLGetNumValuesReturned(int id) const { return 4; case GL_SCISSOR_TEST: return 1; + case GL_SHADER_BINARY_FORMATS: + return num_shader_binary_formats_; case GL_SHADER_COMPILER: return 1; case GL_STENCIL_BACK_FAIL: diff --git a/gpu/command_buffer/common/gles2_cmd_utils.h b/gpu/command_buffer/common/gles2_cmd_utils.h index 7febeb5..85a4ee3 100644 --- a/gpu/command_buffer/common/gles2_cmd_utils.h +++ b/gpu/command_buffer/common/gles2_cmd_utils.h @@ -62,9 +62,25 @@ class GLES2Util { const char* name; }; - explicit GLES2Util( - int num_compressed_texture_formats) - : num_compressed_texture_formats_(num_compressed_texture_formats) { + GLES2Util() + : num_compressed_texture_formats_(0), + num_shader_binary_formats_(0) { + } + + int num_compressed_texture_formats() const { + return num_compressed_texture_formats_; + } + + void set_num_compressed_texture_formats(int num_compressed_texture_formats) { + num_compressed_texture_formats_ = num_compressed_texture_formats; + } + + int num_shader_binary_formats() const { + return num_shader_binary_formats_; + } + + void set_num_shader_binary_formats(int num_shader_binary_formats) { + num_shader_binary_formats_ = num_shader_binary_formats; } // Gets the number of values a particular id will return when a glGet @@ -111,6 +127,7 @@ class GLES2Util { static const size_t enum_to_string_table_len_; int num_compressed_texture_formats_; + int num_shader_binary_formats_; }; } // namespace gles2 diff --git a/gpu/command_buffer/common/gles2_cmd_utils_autogen.h b/gpu/command_buffer/common/gles2_cmd_utils_autogen.h index c562c4e..6c292b0 100644 --- a/gpu/command_buffer/common/gles2_cmd_utils_autogen.h +++ b/gpu/command_buffer/common/gles2_cmd_utils_autogen.h @@ -36,6 +36,7 @@ static std::string GetStringReadPixelFormat(uint32 value); static std::string GetStringRenderBufferFormat(uint32 value); static std::string GetStringRenderBufferParameter(uint32 value); static std::string GetStringRenderBufferTarget(uint32 value); +static std::string GetStringShaderBinaryFormat(uint32 value); static std::string GetStringShaderParameter(uint32 value); static std::string GetStringShaderPrecision(uint32 value); static std::string GetStringShaderType(uint32 value); diff --git a/gpu/command_buffer/common/gles2_cmd_utils_implementation_autogen.h b/gpu/command_buffer/common/gles2_cmd_utils_implementation_autogen.h index 9562636..37bf93e 100644 --- a/gpu/command_buffer/common/gles2_cmd_utils_implementation_autogen.h +++ b/gpu/command_buffer/common/gles2_cmd_utils_implementation_autogen.h @@ -833,6 +833,11 @@ std::string GLES2Util::GetStringRenderBufferTarget(uint32 value) { string_table, arraysize(string_table), value); } +std::string GLES2Util::GetStringShaderBinaryFormat(uint32 value) { + return GLES2Util::GetQualifiedEnumString( + NULL, 0, value); +} + std::string GLES2Util::GetStringShaderParameter(uint32 value) { static EnumToString string_table[] = { { GL_SHADER_TYPE, "GL_SHADER_TYPE" }, diff --git a/gpu/command_buffer/common/gles2_cmd_utils_unittest.cc b/gpu/command_buffer/common/gles2_cmd_utils_unittest.cc index 3a1da0a..0923616 100644 --- a/gpu/command_buffer/common/gles2_cmd_utils_unittest.cc +++ b/gpu/command_buffer/common/gles2_cmd_utils_unittest.cc @@ -14,15 +14,27 @@ namespace gpu { namespace gles2 { class GLES2UtilTest : public testing:: Test { - public: - GLES2UtilTest() - : util_(0) { - } - protected: GLES2Util util_; }; +TEST_F(GLES2UtilTest, GLGetNumValuesReturned) { + EXPECT_EQ(0, util_.GLGetNumValuesReturned(GL_COMPRESSED_TEXTURE_FORMATS)); + EXPECT_EQ(0, util_.GLGetNumValuesReturned(GL_SHADER_BINARY_FORMATS)); + + EXPECT_EQ(0, util_.num_compressed_texture_formats()); + EXPECT_EQ(0, util_.num_shader_binary_formats()); + + util_.set_num_compressed_texture_formats(1); + util_.set_num_shader_binary_formats(2); + + EXPECT_EQ(1, util_.GLGetNumValuesReturned(GL_COMPRESSED_TEXTURE_FORMATS)); + EXPECT_EQ(2, util_.GLGetNumValuesReturned(GL_SHADER_BINARY_FORMATS)); + + EXPECT_EQ(1, util_.num_compressed_texture_formats()); + EXPECT_EQ(2, util_.num_shader_binary_formats()); +} + TEST_F(GLES2UtilTest, ComputeImageDataSizeFormats) { const uint32 kWidth = 16; const uint32 kHeight = 12; diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc index cd007c4..9c344e1 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder.cc +++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc @@ -777,6 +777,8 @@ class GLES2DecoderImpl : public base::SupportsWeakPtr<GLES2DecoderImpl>, // Initialize or re-initialize the shader translator. bool InitializeShaderTranslator(); + void UpdateCapabilities(); + // Helpers for the glGen and glDelete functions. bool GenTexturesHelper(GLsizei n, const GLuint* client_ids); void DeleteTexturesHelper(GLsizei n, const GLuint* client_ids); @@ -1851,7 +1853,6 @@ GLES2DecoderImpl::GLES2DecoderImpl(SurfaceManager* surface_manager, surface_manager_(surface_manager), group_(ContextGroup::Ref(group ? group : new ContextGroup())), error_bits_(0), - util_(0), // TODO(gman): Set to actual num compress texture formats. pack_alignment_(4), unpack_alignment_(4), attrib_0_buffer_id_(0), @@ -1958,6 +1959,9 @@ bool GLES2DecoderImpl::Initialize( vertex_attrib_manager_.Initialize(group_->max_vertex_attribs()); + util_.set_num_compressed_texture_formats( + validators_->compressed_texture_format.GetValues().size()); + if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { // We have to enable vertex array 0 on OpenGL or it won't render. Note that // OpenGL ES 2.0 does not have this issue. @@ -2145,6 +2149,13 @@ bool GLES2DecoderImpl::Initialize( return true; } +void GLES2DecoderImpl::UpdateCapabilities() { + util_.set_num_compressed_texture_formats( + validators_->compressed_texture_format.GetValues().size()); + util_.set_num_shader_binary_formats( + validators_->shader_binary_format.GetValues().size()); +} + bool GLES2DecoderImpl::InitializeShaderTranslator() { // Re-check the state of use_shader_translator_ each time this is called. if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2 && @@ -3196,24 +3207,33 @@ bool GLES2DecoderImpl::GetHelper( } return true; case GL_COMPRESSED_TEXTURE_FORMATS: - *num_written = 0; - // We don't support compressed textures. + *num_written = validators_->compressed_texture_format.GetValues().size(); + if (params) { + for (GLint ii = 0; ii < *num_written; ++ii) { + params[ii] = validators_->compressed_texture_format.GetValues()[ii]; + } + } return true; case GL_NUM_COMPRESSED_TEXTURE_FORMATS: *num_written = 1; if (params) { - *params = 0; // We don't support compressed textures. + *params = validators_->compressed_texture_format.GetValues().size(); } return true; case GL_NUM_SHADER_BINARY_FORMATS: *num_written = 1; if (params) { - *params = 0; // We don't support binary shader formats. + *params = validators_->shader_binary_format.GetValues().size(); } return true; case GL_SHADER_BINARY_FORMATS: - *num_written = 0; - return true; // We don't support binary shader format.s + *num_written = validators_->shader_binary_format.GetValues().size(); + if (params) { + for (GLint ii = 0; ii < *num_written; ++ii) { + params[ii] = validators_->shader_binary_format.GetValues()[ii]; + } + } + return true; case GL_SHADER_COMPILER: *num_written = 1; if (params) { @@ -6855,6 +6875,8 @@ error::Error GLES2DecoderImpl::HandleRequestExtensionCHROMIUM( InitializeShaderTranslator(); } + UpdateCapabilities(); + return error::kNoError; } diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc b/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc index 981991b..52b9a22 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc +++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc @@ -4211,6 +4211,114 @@ TEST_F(GLES2DecoderTest, ReadPixelsGLError) { EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError()); } +static bool ValueInArray(GLint value, GLint* array, GLint count) { + for (GLint ii = 0; ii < count; ++ii) { + if (array[ii] == value) { + return true; + } + } + return false; +} + +TEST_F(GLES2DecoderManualInitTest, GetCompressedTextureFormats) { + InitDecoder( + "GL_EXT_texture_compression_s3tc", // extensions + false, // has alpha + false, // has depth + false, // has stencil + false, // request alpha + false, // request depth + false); // request stencil + + EXPECT_CALL(*gl_, GetError()) + .WillOnce(Return(GL_NO_ERROR)) + .WillOnce(Return(GL_NO_ERROR)) + .WillOnce(Return(GL_NO_ERROR)) + .WillOnce(Return(GL_NO_ERROR)) + .RetiresOnSaturation(); + + typedef GetIntegerv::Result Result; + Result* result = static_cast<Result*>(shared_memory_address_); + GetIntegerv cmd; + result->size = 0; + EXPECT_CALL(*gl_, GetIntegerv(_, _)) + .Times(0) + .RetiresOnSaturation(); + cmd.Init( + GL_NUM_COMPRESSED_TEXTURE_FORMATS, + shared_memory_id_, shared_memory_offset_); + EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); + EXPECT_EQ(1, result->GetNumResults()); + GLint num_formats = result->GetData()[0]; + EXPECT_EQ(4, num_formats); + EXPECT_EQ(GL_NO_ERROR, GetGLError()); + + result->size = 0; + cmd.Init( + GL_COMPRESSED_TEXTURE_FORMATS, + shared_memory_id_, shared_memory_offset_); + EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); + EXPECT_EQ(num_formats, result->GetNumResults()); + + EXPECT_TRUE(ValueInArray( + GL_COMPRESSED_RGB_S3TC_DXT1_EXT, + result->GetData(), result->GetNumResults())); + EXPECT_TRUE(ValueInArray( + GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, + result->GetData(), result->GetNumResults())); + EXPECT_TRUE(ValueInArray( + GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, + result->GetData(), result->GetNumResults())); + EXPECT_TRUE(ValueInArray( + GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, + result->GetData(), result->GetNumResults())); + + EXPECT_EQ(GL_NO_ERROR, GetGLError()); +} + +TEST_F(GLES2DecoderManualInitTest, GetNoCompressedTextureFormats) { + InitDecoder( + "", // extensions + false, // has alpha + false, // has depth + false, // has stencil + false, // request alpha + false, // request depth + false); // request stencil + + EXPECT_CALL(*gl_, GetError()) + .WillOnce(Return(GL_NO_ERROR)) + .WillOnce(Return(GL_NO_ERROR)) + .WillOnce(Return(GL_NO_ERROR)) + .WillOnce(Return(GL_NO_ERROR)) + .RetiresOnSaturation(); + + typedef GetIntegerv::Result Result; + Result* result = static_cast<Result*>(shared_memory_address_); + GetIntegerv cmd; + result->size = 0; + EXPECT_CALL(*gl_, GetIntegerv(_, _)) + .Times(0) + .RetiresOnSaturation(); + cmd.Init( + GL_NUM_COMPRESSED_TEXTURE_FORMATS, + shared_memory_id_, shared_memory_offset_); + EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); + EXPECT_EQ(1, result->GetNumResults()); + GLint num_formats = result->GetData()[0]; + EXPECT_EQ(0, num_formats); + EXPECT_EQ(GL_NO_ERROR, GetGLError()); + + result->size = 0; + cmd.Init( + GL_COMPRESSED_TEXTURE_FORMATS, + shared_memory_id_, shared_memory_offset_); + EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); + EXPECT_EQ(num_formats, result->GetNumResults()); + + EXPECT_EQ(GL_NO_ERROR, GetGLError()); +} + // TODO(gman): Complete this test. // TEST_F(GLES2DecoderTest, CompressedTexImage2DGLError) { // } diff --git a/gpu/command_buffer/service/gles2_cmd_validation.h b/gpu/command_buffer/service/gles2_cmd_validation.h index d98212b..22ee2da 100644 --- a/gpu/command_buffer/service/gles2_cmd_validation.h +++ b/gpu/command_buffer/service/gles2_cmd_validation.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -38,6 +38,10 @@ class ValueValidator { valid_values_.end(); } + const std::vector<T>& GetValues() const { + return valid_values_; + } + private: std::vector<T> valid_values_; }; diff --git a/gpu/command_buffer/service/gles2_cmd_validation_autogen.h b/gpu/command_buffer/service/gles2_cmd_validation_autogen.h index fa02ff5..00e9ef9 100644 --- a/gpu/command_buffer/service/gles2_cmd_validation_autogen.h +++ b/gpu/command_buffer/service/gles2_cmd_validation_autogen.h @@ -38,6 +38,7 @@ ValueValidator<GLenum> read_pixel_format; ValueValidator<GLenum> render_buffer_format; ValueValidator<GLenum> render_buffer_parameter; ValueValidator<GLenum> render_buffer_target; +ValueValidator<GLenum> shader_binary_format; ValueValidator<GLenum> shader_parameter; ValueValidator<GLenum> shader_precision; ValueValidator<GLenum> shader_type; diff --git a/gpu/command_buffer/service/gles2_cmd_validation_implementation_autogen.h b/gpu/command_buffer/service/gles2_cmd_validation_implementation_autogen.h index e7f7392..3102b10 100644 --- a/gpu/command_buffer/service/gles2_cmd_validation_implementation_autogen.h +++ b/gpu/command_buffer/service/gles2_cmd_validation_implementation_autogen.h @@ -510,6 +510,7 @@ Validators::Validators() render_buffer_target( valid_render_buffer_target_table, arraysize( valid_render_buffer_target_table)), + shader_binary_format(), shader_parameter( valid_shader_parameter_table, arraysize( valid_shader_parameter_table)), |