diff options
author | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-19 21:03:20 +0000 |
---|---|---|
committer | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-19 21:03:20 +0000 |
commit | b28a20fba01645ff3c87d14e4f83d6ebdf9a1e2b (patch) | |
tree | ad3cfc1099e65dc3fba8a625d992cfdc97385d19 /gpu | |
parent | d9f9695633f8ea3dd1d4d02136c12cf2ffe429b8 (diff) | |
download | chromium_src-b28a20fba01645ff3c87d14e4f83d6ebdf9a1e2b.zip chromium_src-b28a20fba01645ff3c87d14e4f83d6ebdf9a1e2b.tar.gz chromium_src-b28a20fba01645ff3c87d14e4f83d6ebdf9a1e2b.tar.bz2 |
Add --enforce-gl-minimums flag
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/10066033
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133054 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu')
-rw-r--r-- | gpu/command_buffer/service/context_group.cc | 102 | ||||
-rw-r--r-- | gpu/command_buffer/service/context_group.h | 6 | ||||
-rw-r--r-- | gpu/command_buffer/service/gpu_switches.cc | 4 | ||||
-rw-r--r-- | gpu/command_buffer/service/gpu_switches.h | 1 |
4 files changed, 101 insertions, 12 deletions
diff --git a/gpu/command_buffer/service/context_group.cc b/gpu/command_buffer/service/context_group.cc index 8e8815a..dd99d84 100644 --- a/gpu/command_buffer/service/context_group.cc +++ b/gpu/command_buffer/service/context_group.cc @@ -6,11 +6,13 @@ #include <string> +#include "base/command_line.h" #include "base/string_util.h" #include "gpu/command_buffer/common/id_allocator.h" #include "gpu/command_buffer/service/buffer_manager.h" #include "gpu/command_buffer/service/framebuffer_manager.h" #include "gpu/command_buffer/service/gles2_cmd_decoder.h" +#include "gpu/command_buffer/service/gpu_switches.h" #include "gpu/command_buffer/service/program_manager.h" #include "gpu/command_buffer/service/renderbuffer_manager.h" #include "gpu/command_buffer/service/shader_manager.h" @@ -22,6 +24,8 @@ namespace gles2 { ContextGroup::ContextGroup(bool bind_generates_resource) : num_contexts_(0), + enforce_gl_minimums_(CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnforceGLMinimums)), bind_generates_resource_(bind_generates_resource), max_vertex_attribs_(0u), max_texture_units_(0u), @@ -50,6 +54,41 @@ static void GetIntegerv(GLenum pname, uint32* var) { *var = value; } +bool ContextGroup::CheckGLFeature(GLint min_required, GLint* v) { + GLint value = *v; + if (enforce_gl_minimums_) { + value = std::min(min_required, value); + } + *v = value; + return value >= min_required; +} + +bool ContextGroup::CheckGLFeatureU(GLint min_required, uint32* v) { + GLint value = *v; + if (enforce_gl_minimums_) { + value = std::min(min_required, value); + } + *v = value; + return value >= min_required; +} + +bool ContextGroup::QueryGLFeature( + GLenum pname, GLint min_required, GLint* v) { + GLint value = 0; + glGetIntegerv(pname, &value); + *v = value; + return CheckGLFeature(min_required, v); +} + +bool ContextGroup::QueryGLFeatureU( + GLenum pname, GLint min_required, uint32* v) { + uint32 value = 0; + GetIntegerv(pname, &value); + bool result = CheckGLFeatureU(min_required, &value); + *v = value; + return result; +} + bool ContextGroup::Initialize(const DisallowedFeatures& disallowed_features, const char* allowed_features) { if (num_contexts_ > 0) { @@ -63,8 +102,15 @@ bool ContextGroup::Initialize(const DisallowedFeatures& disallowed_features, return false; } + const GLint kMinRenderbufferSize = 512; // GL says 1 pixel! GLint max_renderbuffer_size = 0; - glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &max_renderbuffer_size); + if (!QueryGLFeature( + GL_MAX_RENDERBUFFER_SIZE, kMinRenderbufferSize, + &max_renderbuffer_size)) { + LOG(ERROR) << "ContextGroup::Initialize failed because maximum " + << "renderbuffer size too small."; + return false; + } GLint max_samples = 0; if (feature_info_->feature_flags().chromium_framebuffer_multisample) { glGetIntegerv(GL_MAX_SAMPLES, &max_samples); @@ -78,17 +124,19 @@ bool ContextGroup::Initialize(const DisallowedFeatures& disallowed_features, program_manager_.reset(new ProgramManager()); // Lookup GL things we need to know. - GetIntegerv(GL_MAX_VERTEX_ATTRIBS, &max_vertex_attribs_); - const GLuint kGLES2RequiredMinimumVertexAttribs = 8u; - if (max_vertex_attribs_ < kGLES2RequiredMinimumVertexAttribs) { + const GLint kGLES2RequiredMinimumVertexAttribs = 8u; + if (!QueryGLFeatureU( + GL_MAX_VERTEX_ATTRIBS, kGLES2RequiredMinimumVertexAttribs, + &max_vertex_attribs_)) { LOG(ERROR) << "ContextGroup::Initialize failed because too few " << "vertex attributes supported."; return false; } - GetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &max_texture_units_); const GLuint kGLES2RequiredMinimumTextureUnits = 8u; - if (max_texture_units_ < kGLES2RequiredMinimumTextureUnits) { + if (!QueryGLFeatureU( + GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, kGLES2RequiredMinimumTextureUnits, + &max_texture_units_)) { LOG(ERROR) << "ContextGroup::Initialize failed because too few " << "texture units supported."; return false; @@ -96,8 +144,17 @@ bool ContextGroup::Initialize(const DisallowedFeatures& disallowed_features, GLint max_texture_size = 0; GLint max_cube_map_texture_size = 0; - glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size); - glGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, &max_cube_map_texture_size); + const GLint kMinTextureSize = 2048; // GL actually says 64!?!? + const GLint kMinCubeMapSize = 256; // GL actually says 16!?!? + if (!QueryGLFeature( + GL_MAX_TEXTURE_SIZE, kMinTextureSize, &max_texture_size) || + !QueryGLFeature( + GL_MAX_CUBE_MAP_TEXTURE_SIZE, kMinCubeMapSize, + &max_cube_map_texture_size)) { + LOG(ERROR) << "ContextGroup::Initialize failed because maximum texture size" + << "is too small."; + return false; + } // Limit Intel on Mac to 512. // TODO(gman): Update this code to check for a specific version of @@ -116,14 +173,22 @@ bool ContextGroup::Initialize(const DisallowedFeatures& disallowed_features, } } #endif - texture_manager_.reset(new TextureManager(feature_info_.get(), max_texture_size, max_cube_map_texture_size)); - GetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &max_texture_image_units_); - GetIntegerv( - GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &max_vertex_texture_image_units_); + const GLint kMinTextureImageUnits = 8; + const GLint kMinVertexTextureImageUnits = 0; + if (!QueryGLFeatureU( + GL_MAX_TEXTURE_IMAGE_UNITS, kMinTextureImageUnits, + &max_texture_image_units_) || + !QueryGLFeatureU( + GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, kMinVertexTextureImageUnits, + &max_vertex_texture_image_units_)) { + LOG(ERROR) << "ContextGroup::Initialize failed because too few " + << "texture units."; + return false; + } if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) { GetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, @@ -140,6 +205,19 @@ bool ContextGroup::Initialize(const DisallowedFeatures& disallowed_features, max_vertex_uniform_vectors_ /= 4; } + const GLint kMinFragmentUniformVectors = 16; + const GLint kMinVaryingVectors = 8; + const GLint kMinVertexUniformVectors = 128; + if (!CheckGLFeatureU( + kMinFragmentUniformVectors, &max_fragment_uniform_vectors_) || + !CheckGLFeatureU(kMinVaryingVectors, &max_varying_vectors_) || + !CheckGLFeatureU( + kMinVertexUniformVectors, &max_vertex_uniform_vectors_)) { + LOG(ERROR) << "ContextGroup::Initialize failed because too few " + << "uniforms or varyings supported."; + return false; + } + if (!texture_manager_->Initialize()) { LOG(ERROR) << "Context::Group::Initialize failed because texture manager " << "failed to initialize."; diff --git a/gpu/command_buffer/service/context_group.h b/gpu/command_buffer/service/context_group.h index 7c78f97..5284c1c 100644 --- a/gpu/command_buffer/service/context_group.h +++ b/gpu/command_buffer/service/context_group.h @@ -112,8 +112,14 @@ class GPU_EXPORT ContextGroup : public base::RefCounted<ContextGroup> { IdAllocatorInterface* GetIdAllocator(unsigned namespace_id); private: + bool CheckGLFeature(GLint min_required, GLint* v); + bool CheckGLFeatureU(GLint min_required, uint32* v); + bool QueryGLFeature(GLenum pname, GLint min_required, GLint* v); + bool QueryGLFeatureU(GLenum pname, GLint min_required, uint32* v); + // Whether or not this context is initialized. int num_contexts_; + bool enforce_gl_minimums_; bool bind_generates_resource_; uint32 max_vertex_attribs_; diff --git a/gpu/command_buffer/service/gpu_switches.cc b/gpu/command_buffer/service/gpu_switches.cc index 2000b9a..ed5e083 100644 --- a/gpu/command_buffer/service/gpu_switches.cc +++ b/gpu/command_buffer/service/gpu_switches.cc @@ -19,11 +19,15 @@ const char kEnableGPUCommandLogging[] = "enable-gpu-command-logging"; // Turn on Calling GL Error after every command. const char kEnableGPUDebugging[] = "enable-gpu-debugging"; +// Enforce GL minimums. +const char kEnforceGLMinimums[] = "enforce-gl-minimums"; + const char* kGpuSwitches[] = { kCompileShaderAlwaysSucceeds, kDisableGLSLTranslator, kEnableGPUCommandLogging, kEnableGPUDebugging, + kEnforceGLMinimums, }; const int kNumGpuSwitches = arraysize(kGpuSwitches); diff --git a/gpu/command_buffer/service/gpu_switches.h b/gpu/command_buffer/service/gpu_switches.h index 4aed8c1..561058e 100644 --- a/gpu/command_buffer/service/gpu_switches.h +++ b/gpu/command_buffer/service/gpu_switches.h @@ -16,6 +16,7 @@ GPU_EXPORT extern const char kCompileShaderAlwaysSucceeds[]; GPU_EXPORT extern const char kDisableGLSLTranslator[]; GPU_EXPORT extern const char kEnableGPUCommandLogging[]; GPU_EXPORT extern const char kEnableGPUDebugging[]; +GPU_EXPORT extern const char kEnforceGLMinimums[]; GPU_EXPORT extern const char* kGpuSwitches[]; GPU_EXPORT extern const int kNumGpuSwitches; |