Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: gpu/command_buffer/service/texture_manager.cc

Issue 2117183006: gpu: Clarify sized texture format is available only if ES3 context or immutable texture is supported (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix oes-texture-float.html Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/texture_manager.h" 5 #include "gpu/command_buffer/service/texture_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 {GL_RGBA16I, GL_RGBA_INTEGER, GL_SHORT}, 224 {GL_RGBA16I, GL_RGBA_INTEGER, GL_SHORT},
225 {GL_RGBA32I, GL_RGBA_INTEGER, GL_INT}, 225 {GL_RGBA32I, GL_RGBA_INTEGER, GL_INT},
226 {GL_RGBA32UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT}, 226 {GL_RGBA32UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT},
227 {GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT}, 227 {GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT},
228 {GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT}, 228 {GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT},
229 {GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT}, 229 {GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT},
230 {GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT}, 230 {GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT},
231 {GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8}, 231 {GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8},
232 {GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, 232 {GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL,
233 GL_FLOAT_32_UNSIGNED_INT_24_8_REV}, 233 GL_FLOAT_32_UNSIGNED_INT_24_8_REV},
234 // Exposed by GL_APPLE_texture_format_BGRA8888
235 {GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE},
234 }; 236 };
235 237
236 for (size_t ii = 0; ii < arraysize(kSupportedFormatTypes); ++ii) { 238 for (size_t ii = 0; ii < arraysize(kSupportedFormatTypes); ++ii) {
237 supported_combinations_.insert(kSupportedFormatTypes[ii]); 239 supported_combinations_.insert(kSupportedFormatTypes[ii]);
238 } 240 }
239 } 241 }
240 242
241 // This may be accessed from multiple threads. 243 // This may be accessed from multiple threads.
242 bool IsValid(GLenum internal_format, GLenum format, GLenum type) const { 244 bool IsValid(GLenum internal_format, GLenum format, GLenum type) const {
243 FormatType query = { internal_format, format, type }; 245 FormatType query = { internal_format, format, type };
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 case GL_BLUE: 303 case GL_BLUE:
302 return swizzle->blue; 304 return swizzle->blue;
303 case GL_ALPHA: 305 case GL_ALPHA:
304 return swizzle->alpha; 306 return swizzle->alpha;
305 default: 307 default:
306 NOTREACHED(); 308 NOTREACHED();
307 return GL_NONE; 309 return GL_NONE;
308 } 310 }
309 } 311 }
310 312
313 bool SizedFormatAvailable(const FeatureInfo* feature_info,
314 bool immutable,
315 GLenum internal_format) {
316 if (immutable)
317 return true;
318
319 // TODO(dshwang): check if it's possible to remove
320 // CHROMIUM_color_buffer_float_rgb. crbug.com/329605
321 if ((feature_info->feature_flags().chromium_color_buffer_float_rgb &&
322 internal_format == GL_RGB32F) ||
323 (feature_info->feature_flags().chromium_color_buffer_float_rgba &&
324 internal_format == GL_RGBA32F)) {
325 return true;
326 }
dshwang 2016/10/14 12:03:34 following test failed. https://www.khronos.org/reg
Ken Russell (switch to Gerrit) 2016/10/20 04:59:40 Sorry, I don't remember. The ultimate goal was to
327
328 return feature_info->IsES3Enabled();
329 }
330
311 // A 32-bit and 64-bit compatible way of converting a pointer to a GLuint. 331 // A 32-bit and 64-bit compatible way of converting a pointer to a GLuint.
312 GLuint ToGLuint(const void* ptr) { 332 GLuint ToGLuint(const void* ptr) {
313 return static_cast<GLuint>(reinterpret_cast<size_t>(ptr)); 333 return static_cast<GLuint>(reinterpret_cast<size_t>(ptr));
314 } 334 }
315 335
316 base::LazyInstance<const FormatTypeValidator>::Leaky g_format_type_validator = 336 base::LazyInstance<const FormatTypeValidator>::Leaky g_format_type_validator =
317 LAZY_INSTANCE_INITIALIZER; 337 LAZY_INSTANCE_INITIALIZER;
318 338
319 class ScopedResetPixelUnpackBuffer{ 339 class ScopedResetPixelUnpackBuffer{
320 public: 340 public:
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 // In ES2 with OES_depth_texture, such limitation isn't specified. 614 // In ES2 with OES_depth_texture, such limitation isn't specified.
595 if (feature_info->IsES3Enabled()) { 615 if (feature_info->IsES3Enabled()) {
596 return false; 616 return false;
597 } 617 }
598 } 618 }
599 } else if (feature_info->validators()->compressed_texture_format.IsValid( 619 } else if (feature_info->validators()->compressed_texture_format.IsValid(
600 first_level.internal_format)) { 620 first_level.internal_format)) {
601 // TODO(zmo): The assumption that compressed textures are all filterable 621 // TODO(zmo): The assumption that compressed textures are all filterable
602 // may not be true in the future. 622 // may not be true in the future.
603 } else { 623 } else {
604 if (!Texture::TextureFilterable(feature_info, 624 if (!Texture::TextureFilterable(feature_info, first_level.internal_format,
605 first_level.internal_format, 625 first_level.type, immutable_)) {
606 first_level.type)) {
607 return false; 626 return false;
608 } 627 }
609 } 628 }
610 } 629 }
611 630
612 if (!feature_info->IsES3Enabled()) { 631 if (!feature_info->IsES3Enabled()) {
613 bool is_npot_compatible = !needs_mips && 632 bool is_npot_compatible = !needs_mips &&
614 sampler_state.wrap_s == GL_CLAMP_TO_EDGE && 633 sampler_state.wrap_s == GL_CLAMP_TO_EDGE &&
615 sampler_state.wrap_t == GL_CLAMP_TO_EDGE; 634 sampler_state.wrap_t == GL_CLAMP_TO_EDGE;
616 635
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 return false; 741 return false;
723 } 742 }
724 743
725 // Can't generate mips for depth or stencil textures. 744 // Can't generate mips for depth or stencil textures.
726 const Texture::LevelInfo& base = face_infos_[0].level_infos[base_level_]; 745 const Texture::LevelInfo& base = face_infos_[0].level_infos[base_level_];
727 uint32_t channels = GLES2Util::GetChannelsForFormat(base.format); 746 uint32_t channels = GLES2Util::GetChannelsForFormat(base.format);
728 if (channels & (GLES2Util::kDepth | GLES2Util::kStencil)) { 747 if (channels & (GLES2Util::kDepth | GLES2Util::kStencil)) {
729 return false; 748 return false;
730 } 749 }
731 750
732 if (!Texture::ColorRenderable(feature_info, base.internal_format) || 751 if (!Texture::ColorRenderable(feature_info, base.internal_format,
733 !Texture::TextureFilterable( 752 immutable_) ||
734 feature_info, base.internal_format, base.type)) { 753 !Texture::TextureFilterable(feature_info, base.internal_format, base.type,
754 immutable_)) {
735 return false; 755 return false;
736 } 756 }
737 757
738 for (size_t ii = 0; ii < face_infos_.size(); ++ii) { 758 for (size_t ii = 0; ii < face_infos_.size(); ++ii) {
739 const LevelInfo& info = face_infos_[ii].level_infos[base_level_]; 759 const LevelInfo& info = face_infos_[ii].level_infos[base_level_];
740 if ((info.target == 0) || 760 if ((info.target == 0) ||
741 feature_info->validators()->compressed_texture_format.IsValid( 761 feature_info->validators()->compressed_texture_format.IsValid(
742 info.internal_format) || 762 info.internal_format) ||
743 info.image.get()) { 763 info.image.get()) {
744 return false; 764 return false;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 depth == mip_depth && 821 depth == mip_depth &&
802 internal_format == base_level_face.internal_format && 822 internal_format == base_level_face.internal_format &&
803 format == base_level_face.format && 823 format == base_level_face.format &&
804 type == base_level_face.type); 824 type == base_level_face.type);
805 } 825 }
806 return complete; 826 return complete;
807 } 827 }
808 828
809 // static 829 // static
810 bool Texture::ColorRenderable(const FeatureInfo* feature_info, 830 bool Texture::ColorRenderable(const FeatureInfo* feature_info,
811 GLenum internal_format) { 831 GLenum internal_format,
832 bool immutable) {
812 if (feature_info->validators()->texture_unsized_internal_format.IsValid( 833 if (feature_info->validators()->texture_unsized_internal_format.IsValid(
813 internal_format)) { 834 internal_format)) {
814 return true; 835 return true;
815 } 836 }
816 return feature_info->validators()-> 837
817 texture_sized_color_renderable_internal_format.IsValid(internal_format); 838 return SizedFormatAvailable(feature_info, immutable, internal_format) &&
839 feature_info->validators()
840 ->texture_sized_color_renderable_internal_format.IsValid(
841 internal_format);
818 } 842 }
819 843
820 // static 844 // static
821 bool Texture::TextureFilterable(const FeatureInfo* feature_info, 845 bool Texture::TextureFilterable(const FeatureInfo* feature_info,
822 GLenum internal_format, 846 GLenum internal_format,
823 GLenum type) { 847 GLenum type,
848 bool immutable) {
824 if (feature_info->validators()->texture_unsized_internal_format.IsValid( 849 if (feature_info->validators()->texture_unsized_internal_format.IsValid(
825 internal_format)) { 850 internal_format)) {
826 switch (type) { 851 switch (type) {
827 case GL_FLOAT: 852 case GL_FLOAT:
828 return feature_info->feature_flags().enable_texture_float_linear; 853 return feature_info->feature_flags().enable_texture_float_linear;
829 case GL_HALF_FLOAT_OES: 854 case GL_HALF_FLOAT_OES:
830 return feature_info->feature_flags().enable_texture_half_float_linear; 855 return feature_info->feature_flags().enable_texture_half_float_linear;
831 default: 856 default:
832 // GL_HALF_FLOAT is ES3 only and should only be used with sized formats. 857 // GL_HALF_FLOAT is ES3 only and should only be used with sized formats.
833 return true; 858 return true;
834 } 859 }
835 } 860 }
836 return feature_info->validators()-> 861 return SizedFormatAvailable(feature_info, immutable, internal_format) &&
837 texture_sized_texture_filterable_internal_format.IsValid(internal_format); 862 feature_info->validators()
863 ->texture_sized_texture_filterable_internal_format.IsValid(
864 internal_format);
838 } 865 }
839 866
840 void Texture::SetLevelClearedRect(GLenum target, 867 void Texture::SetLevelClearedRect(GLenum target,
841 GLint level, 868 GLint level,
842 const gfx::Rect& cleared_rect) { 869 const gfx::Rect& cleared_rect) {
843 DCHECK_GE(level, 0); 870 DCHECK_GE(level, 0);
844 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); 871 size_t face_index = GLES2Util::GLTargetToFaceIndex(target);
845 DCHECK_LT(static_cast<size_t>(face_index), 872 DCHECK_LT(static_cast<size_t>(face_index),
846 face_infos_.size()); 873 face_infos_.size());
847 DCHECK_LT(static_cast<size_t>(level), 874 DCHECK_LT(static_cast<size_t>(level),
(...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after
1704 // However, it is required if command buffer is implemented on top of 1731 // However, it is required if command buffer is implemented on top of
1705 // recent OpenGL core versions or OpenGL ES 3.0+. Therefore, for consistency, 1732 // recent OpenGL core versions or OpenGL ES 3.0+. Therefore, for consistency,
1706 // it is better to deviate from ES2 spec and require cube completeness all 1733 // it is better to deviate from ES2 spec and require cube completeness all
1707 // the time. 1734 // the time.
1708 if (face_infos_.size() == 6 && !cube_complete_) 1735 if (face_infos_.size() == 6 && !cube_complete_)
1709 return false; 1736 return false;
1710 DCHECK(level >= 0 && 1737 DCHECK(level >= 0 &&
1711 level < static_cast<GLint>(face_infos_[0].level_infos.size())); 1738 level < static_cast<GLint>(face_infos_[0].level_infos.size()));
1712 GLenum internal_format = face_infos_[0].level_infos[level].internal_format; 1739 GLenum internal_format = face_infos_[0].level_infos[level].internal_format;
1713 bool color_renderable = 1740 bool color_renderable =
1714 ((feature_info->validators()->texture_unsized_internal_format. 1741 ((feature_info->validators()->texture_unsized_internal_format.IsValid(
1715 IsValid(internal_format) && 1742 internal_format) &&
1716 internal_format != GL_ALPHA && 1743 internal_format != GL_ALPHA && internal_format != GL_LUMINANCE &&
1717 internal_format != GL_LUMINANCE &&
1718 internal_format != GL_LUMINANCE_ALPHA && 1744 internal_format != GL_LUMINANCE_ALPHA &&
1719 internal_format != GL_SRGB_EXT) || 1745 internal_format != GL_SRGB_EXT) ||
1720 feature_info->validators()-> 1746 (SizedFormatAvailable(feature_info, immutable_, internal_format) &&
1721 texture_sized_color_renderable_internal_format.IsValid( 1747 feature_info->validators()
1722 internal_format)); 1748 ->texture_sized_color_renderable_internal_format.IsValid(
1749 internal_format)));
1723 bool depth_renderable = feature_info->validators()-> 1750 bool depth_renderable = feature_info->validators()->
1724 texture_depth_renderable_internal_format.IsValid(internal_format); 1751 texture_depth_renderable_internal_format.IsValid(internal_format);
1725 bool stencil_renderable = feature_info->validators()-> 1752 bool stencil_renderable = feature_info->validators()->
1726 texture_stencil_renderable_internal_format.IsValid(internal_format); 1753 texture_stencil_renderable_internal_format.IsValid(internal_format);
1727 return (color_renderable || depth_renderable || stencil_renderable); 1754 return (color_renderable || depth_renderable || stencil_renderable);
1728 } 1755 }
1729 1756
1730 GLenum Texture::GetCompatibilitySwizzleForChannel(GLenum channel) { 1757 GLenum Texture::GetCompatibilitySwizzleForChannel(GLenum channel) {
1731 return GetSwizzleForChannel(channel, compatibility_swizzle_); 1758 return GetSwizzleForChannel(channel, compatibility_swizzle_);
1732 } 1759 }
(...skipping 1747 matching lines...) Expand 10 before | Expand all | Expand 10 after
3480 uint32_t TextureManager::GetServiceIdGeneration() const { 3507 uint32_t TextureManager::GetServiceIdGeneration() const {
3481 return current_service_id_generation_; 3508 return current_service_id_generation_;
3482 } 3509 }
3483 3510
3484 void TextureManager::IncrementServiceIdGeneration() { 3511 void TextureManager::IncrementServiceIdGeneration() {
3485 current_service_id_generation_++; 3512 current_service_id_generation_++;
3486 } 3513 }
3487 3514
3488 } // namespace gles2 3515 } // namespace gles2
3489 } // namespace gpu 3516 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/texture_manager.h ('k') | gpu/command_buffer/tests/gl_texture_storage_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698