| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "gpu/command_buffer/service/feature_info.h" | 5 #include "gpu/command_buffer/service/feature_info.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/macros.h" |
| 10 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
| 12 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 13 #include "gpu/command_buffer/service/gl_utils.h" | 14 #include "gpu/command_buffer/service/gl_utils.h" |
| 14 #include "gpu/command_buffer/service/gpu_switches.h" | 15 #include "gpu/command_buffer/service/gpu_switches.h" |
| 15 #include "ui/gl/gl_implementation.h" | 16 #include "ui/gl/gl_implementation.h" |
| 16 | 17 |
| 17 #if defined(OS_MACOSX) | 18 #if defined(OS_MACOSX) |
| 18 #include "ui/gl/io_surface_support_mac.h" | 19 #include "ui/gl/io_surface_support_mac.h" |
| 19 #endif | 20 #endif |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 workarounds->max_cube_map_texture_size = 4096; | 93 workarounds->max_cube_map_texture_size = 4096; |
| 93 if (workarounds->max_cube_map_texture_size_limit_1024) | 94 if (workarounds->max_cube_map_texture_size_limit_1024) |
| 94 workarounds->max_cube_map_texture_size = 1024; | 95 workarounds->max_cube_map_texture_size = 1024; |
| 95 if (workarounds->max_cube_map_texture_size_limit_512) | 96 if (workarounds->max_cube_map_texture_size_limit_512) |
| 96 workarounds->max_cube_map_texture_size = 512; | 97 workarounds->max_cube_map_texture_size = 512; |
| 97 } | 98 } |
| 98 | 99 |
| 99 } // anonymous namespace. | 100 } // anonymous namespace. |
| 100 | 101 |
| 101 FeatureInfo::FeatureFlags::FeatureFlags() | 102 FeatureInfo::FeatureFlags::FeatureFlags() |
| 102 : chromium_framebuffer_multisample(false), | 103 : chromium_color_buffer_float_rgba(false), |
| 104 chromium_color_buffer_float_rgb(false), |
| 105 chromium_framebuffer_multisample(false), |
| 103 use_core_framebuffer_multisample(false), | 106 use_core_framebuffer_multisample(false), |
| 104 multisampled_render_to_texture(false), | 107 multisampled_render_to_texture(false), |
| 105 use_img_for_multisampled_render_to_texture(false), | 108 use_img_for_multisampled_render_to_texture(false), |
| 106 oes_standard_derivatives(false), | 109 oes_standard_derivatives(false), |
| 107 oes_egl_image_external(false), | 110 oes_egl_image_external(false), |
| 108 oes_depth24(false), | 111 oes_depth24(false), |
| 109 oes_compressed_etc1_rgb8_texture(false), | 112 oes_compressed_etc1_rgb8_texture(false), |
| 110 packed_depth24_stencil8(false), | 113 packed_depth24_stencil8(false), |
| 111 npot_ok(false), | 114 npot_ok(false), |
| 112 enable_texture_float_linear(false), | 115 enable_texture_float_linear(false), |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 npot_ok = true; | 433 npot_ok = true; |
| 431 } | 434 } |
| 432 | 435 |
| 433 // Check if we should allow GL_OES_texture_float, GL_OES_texture_half_float, | 436 // Check if we should allow GL_OES_texture_float, GL_OES_texture_half_float, |
| 434 // GL_OES_texture_float_linear, GL_OES_texture_half_float_linear | 437 // GL_OES_texture_float_linear, GL_OES_texture_half_float_linear |
| 435 bool enable_texture_float = false; | 438 bool enable_texture_float = false; |
| 436 bool enable_texture_float_linear = false; | 439 bool enable_texture_float_linear = false; |
| 437 bool enable_texture_half_float = false; | 440 bool enable_texture_half_float = false; |
| 438 bool enable_texture_half_float_linear = false; | 441 bool enable_texture_half_float_linear = false; |
| 439 | 442 |
| 440 bool have_arb_texture_float = extensions.Contains("GL_ARB_texture_float"); | 443 bool may_enable_chromium_color_buffer_float = false; |
| 441 | 444 |
| 442 if (have_arb_texture_float) { | 445 if (extensions.Contains("GL_ARB_texture_float")) { |
| 443 enable_texture_float = true; | 446 enable_texture_float = true; |
| 444 enable_texture_float_linear = true; | 447 enable_texture_float_linear = true; |
| 445 enable_texture_half_float = true; | 448 enable_texture_half_float = true; |
| 446 enable_texture_half_float_linear = true; | 449 enable_texture_half_float_linear = true; |
| 450 may_enable_chromium_color_buffer_float = true; |
| 447 } else { | 451 } else { |
| 448 if (extensions.Contains("GL_OES_texture_float") || have_arb_texture_float) { | 452 if (extensions.Contains("GL_OES_texture_float")) { |
| 449 enable_texture_float = true; | 453 enable_texture_float = true; |
| 450 if (extensions.Contains("GL_OES_texture_float_linear") || | 454 if (extensions.Contains("GL_OES_texture_float_linear")) { |
| 451 have_arb_texture_float) { | |
| 452 enable_texture_float_linear = true; | 455 enable_texture_float_linear = true; |
| 453 } | 456 } |
| 457 if ((is_es3 && extensions.Contains("GL_EXT_color_buffer_float")) || |
| 458 feature_flags_.is_angle) { |
| 459 may_enable_chromium_color_buffer_float = true; |
| 460 } |
| 454 } | 461 } |
| 455 if (extensions.Contains("GL_OES_texture_half_float") || | 462 if (extensions.Contains("GL_OES_texture_half_float")) { |
| 456 have_arb_texture_float) { | |
| 457 enable_texture_half_float = true; | 463 enable_texture_half_float = true; |
| 458 if (extensions.Contains("GL_OES_texture_half_float_linear") || | 464 if (extensions.Contains("GL_OES_texture_half_float_linear")) { |
| 459 have_arb_texture_float) { | |
| 460 enable_texture_half_float_linear = true; | 465 enable_texture_half_float_linear = true; |
| 461 } | 466 } |
| 462 } | 467 } |
| 463 } | 468 } |
| 464 | 469 |
| 465 if (enable_texture_float) { | 470 if (enable_texture_float) { |
| 466 texture_format_validators_[GL_ALPHA].AddValue(GL_FLOAT); | 471 texture_format_validators_[GL_ALPHA].AddValue(GL_FLOAT); |
| 467 texture_format_validators_[GL_RGB].AddValue(GL_FLOAT); | 472 texture_format_validators_[GL_RGB].AddValue(GL_FLOAT); |
| 468 texture_format_validators_[GL_RGBA].AddValue(GL_FLOAT); | 473 texture_format_validators_[GL_RGBA].AddValue(GL_FLOAT); |
| 469 texture_format_validators_[GL_LUMINANCE].AddValue(GL_FLOAT); | 474 texture_format_validators_[GL_LUMINANCE].AddValue(GL_FLOAT); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 483 texture_format_validators_[GL_LUMINANCE].AddValue(GL_HALF_FLOAT_OES); | 488 texture_format_validators_[GL_LUMINANCE].AddValue(GL_HALF_FLOAT_OES); |
| 484 texture_format_validators_[GL_LUMINANCE_ALPHA].AddValue(GL_HALF_FLOAT_OES); | 489 texture_format_validators_[GL_LUMINANCE_ALPHA].AddValue(GL_HALF_FLOAT_OES); |
| 485 validators_.pixel_type.AddValue(GL_HALF_FLOAT_OES); | 490 validators_.pixel_type.AddValue(GL_HALF_FLOAT_OES); |
| 486 validators_.read_pixel_type.AddValue(GL_HALF_FLOAT_OES); | 491 validators_.read_pixel_type.AddValue(GL_HALF_FLOAT_OES); |
| 487 AddExtensionString("GL_OES_texture_half_float"); | 492 AddExtensionString("GL_OES_texture_half_float"); |
| 488 if (enable_texture_half_float_linear) { | 493 if (enable_texture_half_float_linear) { |
| 489 AddExtensionString("GL_OES_texture_half_float_linear"); | 494 AddExtensionString("GL_OES_texture_half_float_linear"); |
| 490 } | 495 } |
| 491 } | 496 } |
| 492 | 497 |
| 498 if (may_enable_chromium_color_buffer_float) { |
| 499 COMPILE_ASSERT(GL_RGBA32F_ARB == GL_RGBA32F && |
| 500 GL_RGBA32F_EXT == GL_RGBA32F && |
| 501 GL_RGB32F_ARB == GL_RGB32F && |
| 502 GL_RGB32F_EXT == GL_RGB32F, |
| 503 sized_float_internal_format_variations_must_match); |
| 504 // We don't check extension support beyond ARB_texture_float on desktop GL, |
| 505 // and format support varies between GL configurations. For example, spec |
| 506 // prior to OpenGL 3.0 mandates framebuffer support only for one |
| 507 // implementation-chosen format, and ES3.0 EXT_color_buffer_float does not |
| 508 // support rendering to RGB32F. Check for framebuffer completeness with |
| 509 // formats that the extensions expose, and only enable an extension when a |
| 510 // framebuffer created with its texture format is reported as complete. |
| 511 GLint fb_binding = 0; |
| 512 GLint tex_binding = 0; |
| 513 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &fb_binding); |
| 514 glGetIntegerv(GL_TEXTURE_BINDING_2D, &tex_binding); |
| 515 |
| 516 GLuint tex_id = 0; |
| 517 GLuint fb_id = 0; |
| 518 GLsizei width = 16; |
| 519 |
| 520 glGenTextures(1, &tex_id); |
| 521 glGenFramebuffersEXT(1, &fb_id); |
| 522 glBindTexture(GL_TEXTURE_2D, tex_id); |
| 523 // Nearest filter needed for framebuffer completeness on some drivers. |
| 524 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 525 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, width, width, 0, GL_RGBA, |
| 526 GL_FLOAT, NULL); |
| 527 glBindFramebufferEXT(GL_FRAMEBUFFER, fb_id); |
| 528 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
| 529 GL_TEXTURE_2D, tex_id, 0); |
| 530 GLenum statusRGBA = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); |
| 531 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, width, width, 0, GL_RGB, |
| 532 GL_FLOAT, NULL); |
| 533 GLenum statusRGB = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); |
| 534 glDeleteFramebuffersEXT(1, &fb_id); |
| 535 glDeleteTextures(1, &tex_id); |
| 536 |
| 537 glBindFramebufferEXT(GL_FRAMEBUFFER, static_cast<GLuint>(fb_binding)); |
| 538 glBindTexture(GL_TEXTURE_2D, static_cast<GLuint>(tex_binding)); |
| 539 |
| 540 DCHECK(glGetError() == GL_NO_ERROR); |
| 541 |
| 542 if (statusRGBA == GL_FRAMEBUFFER_COMPLETE) { |
| 543 validators_.texture_internal_format.AddValue(GL_RGBA32F); |
| 544 feature_flags_.chromium_color_buffer_float_rgba = true; |
| 545 AddExtensionString("GL_CHROMIUM_color_buffer_float_rgba"); |
| 546 } |
| 547 if (statusRGB == GL_FRAMEBUFFER_COMPLETE) { |
| 548 validators_.texture_internal_format.AddValue(GL_RGB32F); |
| 549 feature_flags_.chromium_color_buffer_float_rgb = true; |
| 550 AddExtensionString("GL_CHROMIUM_color_buffer_float_rgb"); |
| 551 } |
| 552 } |
| 553 |
| 493 // Check for multisample support | 554 // Check for multisample support |
| 494 if (!disallowed_features_.multisampling && | 555 if (!disallowed_features_.multisampling && |
| 495 !workarounds_.disable_framebuffer_multisample) { | 556 !workarounds_.disable_framebuffer_multisample) { |
| 496 bool ext_has_multisample = | 557 bool ext_has_multisample = |
| 497 extensions.Contains("GL_EXT_framebuffer_multisample") || is_es3; | 558 extensions.Contains("GL_EXT_framebuffer_multisample") || is_es3; |
| 498 if (feature_flags_.is_angle) { | 559 if (feature_flags_.is_angle) { |
| 499 ext_has_multisample |= | 560 ext_has_multisample |= |
| 500 extensions.Contains("GL_ANGLE_framebuffer_multisample"); | 561 extensions.Contains("GL_ANGLE_framebuffer_multisample"); |
| 501 } | 562 } |
| 502 feature_flags_.use_core_framebuffer_multisample = is_es3; | 563 feature_flags_.use_core_framebuffer_multisample = is_es3; |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 | 773 |
| 713 if ((is_es3 || extensions.Contains("GL_EXT_discard_framebuffer")) && | 774 if ((is_es3 || extensions.Contains("GL_EXT_discard_framebuffer")) && |
| 714 !workarounds_.disable_ext_discard_framebuffer) { | 775 !workarounds_.disable_ext_discard_framebuffer) { |
| 715 // DiscardFramebufferEXT is automatically bound to InvalidateFramebuffer. | 776 // DiscardFramebufferEXT is automatically bound to InvalidateFramebuffer. |
| 716 AddExtensionString("GL_EXT_discard_framebuffer"); | 777 AddExtensionString("GL_EXT_discard_framebuffer"); |
| 717 feature_flags_.ext_discard_framebuffer = true; | 778 feature_flags_.ext_discard_framebuffer = true; |
| 718 } | 779 } |
| 719 } | 780 } |
| 720 | 781 |
| 721 void FeatureInfo::AddExtensionString(const std::string& str) { | 782 void FeatureInfo::AddExtensionString(const std::string& str) { |
| 722 if (extensions_.find(str) == std::string::npos) { | 783 size_t pos = extensions_.find(str); |
| 784 while (pos != std::string::npos && |
| 785 pos + str.length() < extensions_.length() && |
| 786 extensions_.substr(pos + str.length(), 1) != " ") { |
| 787 // This extension name is a substring of another. |
| 788 pos = extensions_.find(str, pos + str.length()); |
| 789 } |
| 790 if (pos == std::string::npos) { |
| 723 extensions_ += (extensions_.empty() ? "" : " ") + str; | 791 extensions_ += (extensions_.empty() ? "" : " ") + str; |
| 724 } | 792 } |
| 725 } | 793 } |
| 726 | 794 |
| 727 FeatureInfo::~FeatureInfo() { | 795 FeatureInfo::~FeatureInfo() { |
| 728 } | 796 } |
| 729 | 797 |
| 730 } // namespace gles2 | 798 } // namespace gles2 |
| 731 } // namespace gpu | 799 } // namespace gpu |
| OLD | NEW |