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

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

Issue 1263043006: Implement the texture uploading of ASTC compression for WebGL (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup and Remove unnecessary enum/OES extensions. Created 5 years, 4 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/gles2_cmd_decoder.h" 5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <cmath> 10 #include <cmath>
(...skipping 3103 matching lines...) Expand 10 before | Expand all | Expand 10 after
3114 caps.minor_version = 0; 3114 caps.minor_version = 0;
3115 } 3115 }
3116 if (feature_info_->feature_flags().multisampled_render_to_texture || 3116 if (feature_info_->feature_flags().multisampled_render_to_texture ||
3117 feature_info_->feature_flags().chromium_framebuffer_multisample || 3117 feature_info_->feature_flags().chromium_framebuffer_multisample ||
3118 unsafe_es3_apis_enabled()) { 3118 unsafe_es3_apis_enabled()) {
3119 DoGetIntegerv(GL_MAX_SAMPLES, &caps.max_samples); 3119 DoGetIntegerv(GL_MAX_SAMPLES, &caps.max_samples);
3120 } 3120 }
3121 3121
3122 caps.egl_image_external = 3122 caps.egl_image_external =
3123 feature_info_->feature_flags().oes_egl_image_external; 3123 feature_info_->feature_flags().oes_egl_image_external;
3124 caps.texture_format_astc =
3125 feature_info_->feature_flags().ext_texture_format_astc;
3124 caps.texture_format_atc = 3126 caps.texture_format_atc =
3125 feature_info_->feature_flags().ext_texture_format_atc; 3127 feature_info_->feature_flags().ext_texture_format_atc;
3126 caps.texture_format_bgra8888 = 3128 caps.texture_format_bgra8888 =
3127 feature_info_->feature_flags().ext_texture_format_bgra8888; 3129 feature_info_->feature_flags().ext_texture_format_bgra8888;
3128 caps.texture_format_dxt1 = 3130 caps.texture_format_dxt1 =
3129 feature_info_->feature_flags().ext_texture_format_dxt1; 3131 feature_info_->feature_flags().ext_texture_format_dxt1;
3130 caps.texture_format_dxt5 = 3132 caps.texture_format_dxt5 =
3131 feature_info_->feature_flags().ext_texture_format_dxt5; 3133 feature_info_->feature_flags().ext_texture_format_dxt5;
3132 caps.texture_format_etc1 = 3134 caps.texture_format_etc1 =
3133 feature_info_->feature_flags().oes_compressed_etc1_rgb8_texture; 3135 feature_info_->feature_flags().oes_compressed_etc1_rgb8_texture;
(...skipping 3728 matching lines...) Expand 10 before | Expand all | Expand 10 after
6862 } 6864 }
6863 } 6865 }
6864 } 6866 }
6865 6867
6866 bool GLES2DecoderImpl::PrepareTexturesForRender() { 6868 bool GLES2DecoderImpl::PrepareTexturesForRender() {
6867 DCHECK(state_.current_program.get()); 6869 DCHECK(state_.current_program.get());
6868 if (!texture_manager()->HaveUnrenderableTextures() && 6870 if (!texture_manager()->HaveUnrenderableTextures() &&
6869 !texture_manager()->HaveImages()) { 6871 !texture_manager()->HaveImages()) {
6870 return true; 6872 return true;
6871 } 6873 }
6872
6873 bool textures_set = false; 6874 bool textures_set = false;
6874 const Program::SamplerIndices& sampler_indices = 6875 const Program::SamplerIndices& sampler_indices =
6875 state_.current_program->sampler_indices(); 6876 state_.current_program->sampler_indices();
6876 for (size_t ii = 0; ii < sampler_indices.size(); ++ii) { 6877 for (size_t ii = 0; ii < sampler_indices.size(); ++ii) {
6877 const Program::UniformInfo* uniform_info = 6878 const Program::UniformInfo* uniform_info =
6878 state_.current_program->GetUniformInfo(sampler_indices[ii]); 6879 state_.current_program->GetUniformInfo(sampler_indices[ii]);
6879 DCHECK(uniform_info); 6880 DCHECK(uniform_info);
6880 for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) { 6881 for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) {
6881 GLuint texture_unit_index = uniform_info->texture_units[jj]; 6882 GLuint texture_unit_index = uniform_info->texture_units[jj];
6882 if (texture_unit_index < state_.texture_units.size()) { 6883 if (texture_unit_index < state_.texture_units.size()) {
(...skipping 2196 matching lines...) Expand 10 before | Expand all | Expand 10 after
9079 } 9080 }
9080 9081
9081 namespace { 9082 namespace {
9082 9083
9083 const int kS3TCBlockWidth = 4; 9084 const int kS3TCBlockWidth = 4;
9084 const int kS3TCBlockHeight = 4; 9085 const int kS3TCBlockHeight = 4;
9085 const int kS3TCDXT1BlockSize = 8; 9086 const int kS3TCDXT1BlockSize = 8;
9086 const int kS3TCDXT3AndDXT5BlockSize = 16; 9087 const int kS3TCDXT3AndDXT5BlockSize = 16;
9087 const int kEACAndETC2BlockSize = 4; 9088 const int kEACAndETC2BlockSize = 4;
9088 9089
9090 typedef struct {
9091 int blockWidth;
9092 int blockHeight;
9093 } ASTCBlockSize;
9094
9095 static const ASTCBlockSize kASTCBlockSize[] =
piman 2015/08/17 23:00:20 nit: you're in an anonymous namespace, so you don'
9096 {
9097 4, 4, /* GL_COMPRESSED_RGBA_ASTC_4x4_KHR */
9098 5, 4, /* and GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR */
9099 5, 5,
9100 6, 5,
9101 6, 6,
9102 8, 5,
9103 8, 6,
9104 8, 8,
9105 10, 5,
9106 10, 6,
9107 10, 8,
9108 10, 10,
9109 12, 10,
9110 12, 12,
9111 };
9112
9113
9089 bool IsValidDXTSize(GLint level, GLsizei size) { 9114 bool IsValidDXTSize(GLint level, GLsizei size) {
9090 return (size == 1) || 9115 return (size == 1) ||
9091 (size == 2) || !(size % kS3TCBlockWidth); 9116 (size == 2) || !(size % kS3TCBlockWidth);
9092 } 9117 }
9093 9118
9094 bool IsValidPVRTCSize(GLint level, GLsizei size) { 9119 bool IsValidPVRTCSize(GLint level, GLsizei size) {
9095 return GLES2Util::IsPOT(size); 9120 return GLES2Util::IsPOT(size);
9096 } 9121 }
9097 9122
9098 } // anonymous namespace. 9123 } // anonymous namespace.
9099 9124
9100 bool GLES2DecoderImpl::GetCompressedTexSizeInBytes( 9125 bool GLES2DecoderImpl::GetCompressedTexSizeInBytes(
9101 const char* function_name, GLsizei width, GLsizei height, GLsizei depth, 9126 const char* function_name, GLsizei width, GLsizei height, GLsizei depth,
9102 GLenum format, GLsizei* size_in_bytes) { 9127 GLenum format, GLsizei* size_in_bytes) {
9103 base::CheckedNumeric<GLsizei> bytes_required(0); 9128 base::CheckedNumeric<GLsizei> bytes_required(0);
9104 9129
9105 switch (format) { 9130 switch (format) {
9106 case GL_ATC_RGB_AMD: 9131 case GL_ATC_RGB_AMD:
9107 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: 9132 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
9108 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: 9133 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
9109 case GL_ETC1_RGB8_OES: 9134 case GL_ETC1_RGB8_OES:
9110 bytes_required = 9135 bytes_required =
9111 (width + kS3TCBlockWidth - 1) / kS3TCBlockWidth; 9136 (width + kS3TCBlockWidth - 1) / kS3TCBlockWidth;
9112 bytes_required *= 9137 bytes_required *=
9113 (height + kS3TCBlockHeight - 1) / kS3TCBlockHeight; 9138 (height + kS3TCBlockHeight - 1) / kS3TCBlockHeight;
9114 bytes_required *= kS3TCDXT1BlockSize; 9139 bytes_required *= kS3TCDXT1BlockSize;
9115 break; 9140 break;
9141 case GL_COMPRESSED_RGBA_ASTC_4x4_KHR:
9142 case GL_COMPRESSED_RGBA_ASTC_5x4_KHR:
9143 case GL_COMPRESSED_RGBA_ASTC_5x5_KHR:
9144 case GL_COMPRESSED_RGBA_ASTC_6x5_KHR:
9145 case GL_COMPRESSED_RGBA_ASTC_6x6_KHR:
9146 case GL_COMPRESSED_RGBA_ASTC_8x5_KHR:
9147 case GL_COMPRESSED_RGBA_ASTC_8x6_KHR:
9148 case GL_COMPRESSED_RGBA_ASTC_8x8_KHR:
9149 case GL_COMPRESSED_RGBA_ASTC_10x5_KHR:
9150 case GL_COMPRESSED_RGBA_ASTC_10x6_KHR:
9151 case GL_COMPRESSED_RGBA_ASTC_10x8_KHR:
9152 case GL_COMPRESSED_RGBA_ASTC_10x10_KHR:
9153 case GL_COMPRESSED_RGBA_ASTC_12x10_KHR:
9154 case GL_COMPRESSED_RGBA_ASTC_12x12_KHR:
9155 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
9156 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
9157 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
9158 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
9159 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
9160 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
9161 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
9162 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
9163 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
9164 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
9165 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
9166 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
9167 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
9168 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR: {
9169 const int index = (format < GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR) ?
9170 (int)format - GL_COMPRESSED_RGBA_ASTC_4x4_KHR :
piman 2015/08/17 23:00:20 nit: no c-style cast.
9171 (int)format - GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR;
piman 2015/08/17 23:00:21 nit: no c-style cast.
9172
9173 const int kBlockWidth = kASTCBlockSize[index].blockWidth;
9174 const int kBlockHeight = kASTCBlockSize[index].blockHeight;
9175
9176 int kBlockX =
9177 (std::max(width, kBlockWidth) + kBlockWidth - 1) / kBlockWidth;
9178 int kBlockY =
9179 (std::max(height, kBlockHeight) + kBlockHeight - 1) / kBlockHeight;
9180
9181 bytes_required = (kBlockX * kBlockY) << 4;
piman 2015/08/17 23:00:20 nit: rather than << 4, can you write * kASTCBlockB
9182 break;
9183 }
9116 case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD: 9184 case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD:
9117 case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD: 9185 case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD:
9118 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: 9186 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
9119 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: 9187 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
9120 bytes_required = 9188 bytes_required =
9121 (width + kS3TCBlockWidth - 1) / kS3TCBlockWidth; 9189 (width + kS3TCBlockWidth - 1) / kS3TCBlockWidth;
9122 bytes_required *= 9190 bytes_required *=
9123 (height + kS3TCBlockHeight - 1) / kS3TCBlockHeight; 9191 (height + kS3TCBlockHeight - 1) / kS3TCBlockHeight;
9124 bytes_required *= kS3TCDXT3AndDXT5BlockSize; 9192 bytes_required *= kS3TCDXT3AndDXT5BlockSize;
9125 break; 9193 break;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
9206 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: 9274 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
9207 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: 9275 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
9208 DCHECK_EQ(1, depth); // 2D formats. 9276 DCHECK_EQ(1, depth); // 2D formats.
9209 if (!IsValidDXTSize(level, width) || !IsValidDXTSize(level, height)) { 9277 if (!IsValidDXTSize(level, width) || !IsValidDXTSize(level, height)) {
9210 LOCAL_SET_GL_ERROR( 9278 LOCAL_SET_GL_ERROR(
9211 GL_INVALID_OPERATION, function_name, 9279 GL_INVALID_OPERATION, function_name,
9212 "width or height invalid for level"); 9280 "width or height invalid for level");
9213 return false; 9281 return false;
9214 } 9282 }
9215 return true; 9283 return true;
9284 case GL_COMPRESSED_RGBA_ASTC_4x4_KHR:
9285 case GL_COMPRESSED_RGBA_ASTC_5x4_KHR:
9286 case GL_COMPRESSED_RGBA_ASTC_5x5_KHR:
9287 case GL_COMPRESSED_RGBA_ASTC_6x5_KHR:
9288 case GL_COMPRESSED_RGBA_ASTC_6x6_KHR:
9289 case GL_COMPRESSED_RGBA_ASTC_8x5_KHR:
9290 case GL_COMPRESSED_RGBA_ASTC_8x6_KHR:
9291 case GL_COMPRESSED_RGBA_ASTC_8x8_KHR:
9292 case GL_COMPRESSED_RGBA_ASTC_10x5_KHR:
9293 case GL_COMPRESSED_RGBA_ASTC_10x6_KHR:
9294 case GL_COMPRESSED_RGBA_ASTC_10x8_KHR:
9295 case GL_COMPRESSED_RGBA_ASTC_10x10_KHR:
9296 case GL_COMPRESSED_RGBA_ASTC_12x10_KHR:
9297 case GL_COMPRESSED_RGBA_ASTC_12x12_KHR:
9298 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
9299 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
9300 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
9301 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
9302 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
9303 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
9304 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
9305 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
9306 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
9307 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
9308 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
9309 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
9310 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
9311 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
9216 case GL_ATC_RGB_AMD: 9312 case GL_ATC_RGB_AMD:
9217 case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD: 9313 case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD:
9218 case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD: 9314 case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD:
9219 case GL_ETC1_RGB8_OES: 9315 case GL_ETC1_RGB8_OES:
9220 DCHECK_EQ(1, depth); // 2D formats. 9316 DCHECK_EQ(1, depth); // 2D formats.
9221 if (width <= 0 || height <= 0) { 9317 if (width <= 0 || height <= 0) {
9222 LOCAL_SET_GL_ERROR( 9318 LOCAL_SET_GL_ERROR(
9223 GL_INVALID_OPERATION, function_name, 9319 GL_INVALID_OPERATION, function_name,
9224 "width or height invalid for level"); 9320 "width or height invalid for level");
9225 return false; 9321 return false;
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
9411 "glCompressedTexImage2D", "unknown texture target"); 9507 "glCompressedTexImage2D", "unknown texture target");
9412 return error::kNoError; 9508 return error::kNoError;
9413 } 9509 }
9414 Texture* texture = texture_ref->texture(); 9510 Texture* texture = texture_ref->texture();
9415 if (texture->IsImmutable()) { 9511 if (texture->IsImmutable()) {
9416 LOCAL_SET_GL_ERROR( 9512 LOCAL_SET_GL_ERROR(
9417 GL_INVALID_OPERATION, 9513 GL_INVALID_OPERATION,
9418 "glCompressedTexImage2D", "texture is immutable"); 9514 "glCompressedTexImage2D", "texture is immutable");
9419 return error::kNoError; 9515 return error::kNoError;
9420 } 9516 }
9421
9422 if (!ValidateCompressedTexDimensions("glCompressedTexImage2D", target, level, 9517 if (!ValidateCompressedTexDimensions("glCompressedTexImage2D", target, level,
9423 width, height, 1, internal_format) || 9518 width, height, 1, internal_format) ||
9424 !ValidateCompressedTexFuncData("glCompressedTexImage2D", width, height, 9519 !ValidateCompressedTexFuncData("glCompressedTexImage2D", width, height,
9425 1, internal_format, image_size)) { 9520 1, internal_format, image_size)) {
9426 return error::kNoError; 9521 return error::kNoError;
9427 } 9522 }
9428 9523
9429 if (!EnsureGPUMemoryAvailable(image_size)) { 9524 if (!EnsureGPUMemoryAvailable(image_size)) {
9430 LOCAL_SET_GL_ERROR( 9525 LOCAL_SET_GL_ERROR(
9431 GL_OUT_OF_MEMORY, "glCompressedTexImage2D", "out of memory"); 9526 GL_OUT_OF_MEMORY, "glCompressedTexImage2D", "out of memory");
(...skipping 4988 matching lines...) Expand 10 before | Expand all | Expand 10 after
14420 return error::kNoError; 14515 return error::kNoError;
14421 } 14516 }
14422 14517
14423 // Include the auto-generated part of this file. We split this because it means 14518 // Include the auto-generated part of this file. We split this because it means
14424 // we can easily edit the non-auto generated parts right here in this file 14519 // we can easily edit the non-auto generated parts right here in this file
14425 // instead of having to edit some template or the code generator. 14520 // instead of having to edit some template or the code generator.
14426 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 14521 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
14427 14522
14428 } // namespace gles2 14523 } // namespace gles2
14429 } // namespace gpu 14524 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698