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

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: 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[] =
9096 {
9097 4, 4, /* GL_COMPRESSED_RGBA_ASTC_4x4_KHR */
9098 5, 4,
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 4, 4, /* GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR */
bajones 2015/08/07 21:35:58 These values are not currently used. May want to r
9112 5, 4,
9113 5, 5,
9114 6, 5,
9115 6, 6,
9116 8, 5,
9117 8, 6,
9118 8, 8,
9119 10, 5,
9120 10, 6,
9121 10, 8,
9122 10, 10,
9123 12, 10,
9124 12, 12
9125 };
9126
9127
9089 bool IsValidDXTSize(GLint level, GLsizei size) { 9128 bool IsValidDXTSize(GLint level, GLsizei size) {
9090 return (size == 1) || 9129 return (size == 1) ||
9091 (size == 2) || !(size % kS3TCBlockWidth); 9130 (size == 2) || !(size % kS3TCBlockWidth);
9092 } 9131 }
9093 9132
9094 bool IsValidPVRTCSize(GLint level, GLsizei size) { 9133 bool IsValidPVRTCSize(GLint level, GLsizei size) {
9095 return GLES2Util::IsPOT(size); 9134 return GLES2Util::IsPOT(size);
9096 } 9135 }
9097 9136
9098 } // anonymous namespace. 9137 } // anonymous namespace.
9099 9138
9100 bool GLES2DecoderImpl::GetCompressedTexSizeInBytes( 9139 bool GLES2DecoderImpl::GetCompressedTexSizeInBytes(
9101 const char* function_name, GLsizei width, GLsizei height, GLsizei depth, 9140 const char* function_name, GLsizei width, GLsizei height, GLsizei depth,
9102 GLenum format, GLsizei* size_in_bytes) { 9141 GLenum format, GLsizei* size_in_bytes) {
9103 base::CheckedNumeric<GLsizei> bytes_required(0); 9142 base::CheckedNumeric<GLsizei> bytes_required(0);
9104 9143
9105 switch (format) { 9144 switch (format) {
9106 case GL_ATC_RGB_AMD: 9145 case GL_ATC_RGB_AMD:
9107 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: 9146 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
9108 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: 9147 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
9109 case GL_ETC1_RGB8_OES: 9148 case GL_ETC1_RGB8_OES:
9110 bytes_required = 9149 bytes_required =
9111 (width + kS3TCBlockWidth - 1) / kS3TCBlockWidth; 9150 (width + kS3TCBlockWidth - 1) / kS3TCBlockWidth;
9112 bytes_required *= 9151 bytes_required *=
9113 (height + kS3TCBlockHeight - 1) / kS3TCBlockHeight; 9152 (height + kS3TCBlockHeight - 1) / kS3TCBlockHeight;
9114 bytes_required *= kS3TCDXT1BlockSize; 9153 bytes_required *= kS3TCDXT1BlockSize;
9115 break; 9154 break;
9155 case GL_COMPRESSED_RGBA_ASTC_4x4_KHR:
9156 case GL_COMPRESSED_RGBA_ASTC_5x4_KHR:
9157 case GL_COMPRESSED_RGBA_ASTC_5x5_KHR:
9158 case GL_COMPRESSED_RGBA_ASTC_6x5_KHR:
9159 case GL_COMPRESSED_RGBA_ASTC_6x6_KHR:
9160 case GL_COMPRESSED_RGBA_ASTC_8x5_KHR:
9161 case GL_COMPRESSED_RGBA_ASTC_8x6_KHR:
9162 case GL_COMPRESSED_RGBA_ASTC_8x8_KHR:
9163 case GL_COMPRESSED_RGBA_ASTC_10x5_KHR:
9164 case GL_COMPRESSED_RGBA_ASTC_10x6_KHR:
9165 case GL_COMPRESSED_RGBA_ASTC_10x8_KHR:
9166 case GL_COMPRESSED_RGBA_ASTC_10x10_KHR:
9167 case GL_COMPRESSED_RGBA_ASTC_12x10_KHR:
9168 case GL_COMPRESSED_RGBA_ASTC_12x12_KHR:
9169 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
9170 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
9171 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
9172 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
9173 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
9174 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
9175 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
9176 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
9177 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
9178 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
9179 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
9180 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
9181 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
9182 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR: {
9183 const int index = (format < GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR) ?
9184 (int)format - GL_COMPRESSED_RGBA_ASTC_4x4_KHR :
9185 (int)format - GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR;
bajones 2015/08/07 21:35:58 The way this algorithim is set up it will never in
9186
9187 const int kBlockWidth = kASTCBlockSize[index].blockWidth;
9188 const int kBlockHeight = kASTCBlockSize[index].blockHeight;
9189
9190 int kBlockX =
9191 (std::max(width, kBlockWidth) + kBlockWidth - 1) / kBlockWidth;
9192 int kBlockY =
9193 (std::max(height, kBlockHeight) + kBlockHeight - 1) / kBlockHeight;
9194
9195 bytes_required = (kBlockX * kBlockY) << 4;
9196 break;
9197 }
9116 case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD: 9198 case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD:
9117 case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD: 9199 case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD:
9118 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: 9200 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
9119 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: 9201 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
9120 bytes_required = 9202 bytes_required =
9121 (width + kS3TCBlockWidth - 1) / kS3TCBlockWidth; 9203 (width + kS3TCBlockWidth - 1) / kS3TCBlockWidth;
9122 bytes_required *= 9204 bytes_required *=
9123 (height + kS3TCBlockHeight - 1) / kS3TCBlockHeight; 9205 (height + kS3TCBlockHeight - 1) / kS3TCBlockHeight;
9124 bytes_required *= kS3TCDXT3AndDXT5BlockSize; 9206 bytes_required *= kS3TCDXT3AndDXT5BlockSize;
9125 break; 9207 break;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
9206 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: 9288 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
9207 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: 9289 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
9208 DCHECK_EQ(1, depth); // 2D formats. 9290 DCHECK_EQ(1, depth); // 2D formats.
9209 if (!IsValidDXTSize(level, width) || !IsValidDXTSize(level, height)) { 9291 if (!IsValidDXTSize(level, width) || !IsValidDXTSize(level, height)) {
9210 LOCAL_SET_GL_ERROR( 9292 LOCAL_SET_GL_ERROR(
9211 GL_INVALID_OPERATION, function_name, 9293 GL_INVALID_OPERATION, function_name,
9212 "width or height invalid for level"); 9294 "width or height invalid for level");
9213 return false; 9295 return false;
9214 } 9296 }
9215 return true; 9297 return true;
9298 case GL_COMPRESSED_RGBA_ASTC_4x4_KHR:
9299 case GL_COMPRESSED_RGBA_ASTC_5x4_KHR:
9300 case GL_COMPRESSED_RGBA_ASTC_5x5_KHR:
9301 case GL_COMPRESSED_RGBA_ASTC_6x5_KHR:
9302 case GL_COMPRESSED_RGBA_ASTC_6x6_KHR:
9303 case GL_COMPRESSED_RGBA_ASTC_8x5_KHR:
9304 case GL_COMPRESSED_RGBA_ASTC_8x6_KHR:
9305 case GL_COMPRESSED_RGBA_ASTC_8x8_KHR:
9306 case GL_COMPRESSED_RGBA_ASTC_10x5_KHR:
9307 case GL_COMPRESSED_RGBA_ASTC_10x6_KHR:
9308 case GL_COMPRESSED_RGBA_ASTC_10x8_KHR:
9309 case GL_COMPRESSED_RGBA_ASTC_10x10_KHR:
9310 case GL_COMPRESSED_RGBA_ASTC_12x10_KHR:
9311 case GL_COMPRESSED_RGBA_ASTC_12x12_KHR:
9312 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
9313 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
9314 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
9315 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
9316 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
9317 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
9318 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
9319 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
9320 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
9321 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
9322 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
9323 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
9324 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
9325 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
9216 case GL_ATC_RGB_AMD: 9326 case GL_ATC_RGB_AMD:
9217 case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD: 9327 case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD:
9218 case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD: 9328 case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD:
9219 case GL_ETC1_RGB8_OES: 9329 case GL_ETC1_RGB8_OES:
9220 DCHECK_EQ(1, depth); // 2D formats. 9330 DCHECK_EQ(1, depth); // 2D formats.
9221 if (width <= 0 || height <= 0) { 9331 if (width <= 0 || height <= 0) {
9222 LOCAL_SET_GL_ERROR( 9332 LOCAL_SET_GL_ERROR(
9223 GL_INVALID_OPERATION, function_name, 9333 GL_INVALID_OPERATION, function_name,
9224 "width or height invalid for level"); 9334 "width or height invalid for level");
9225 return false; 9335 return false;
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
9411 "glCompressedTexImage2D", "unknown texture target"); 9521 "glCompressedTexImage2D", "unknown texture target");
9412 return error::kNoError; 9522 return error::kNoError;
9413 } 9523 }
9414 Texture* texture = texture_ref->texture(); 9524 Texture* texture = texture_ref->texture();
9415 if (texture->IsImmutable()) { 9525 if (texture->IsImmutable()) {
9416 LOCAL_SET_GL_ERROR( 9526 LOCAL_SET_GL_ERROR(
9417 GL_INVALID_OPERATION, 9527 GL_INVALID_OPERATION,
9418 "glCompressedTexImage2D", "texture is immutable"); 9528 "glCompressedTexImage2D", "texture is immutable");
9419 return error::kNoError; 9529 return error::kNoError;
9420 } 9530 }
9421
9422 if (!ValidateCompressedTexDimensions("glCompressedTexImage2D", target, level, 9531 if (!ValidateCompressedTexDimensions("glCompressedTexImage2D", target, level,
9423 width, height, 1, internal_format) || 9532 width, height, 1, internal_format) ||
9424 !ValidateCompressedTexFuncData("glCompressedTexImage2D", width, height, 9533 !ValidateCompressedTexFuncData("glCompressedTexImage2D", width, height,
9425 1, internal_format, image_size)) { 9534 1, internal_format, image_size)) {
9426 return error::kNoError; 9535 return error::kNoError;
9427 } 9536 }
9428 9537
9429 if (!EnsureGPUMemoryAvailable(image_size)) { 9538 if (!EnsureGPUMemoryAvailable(image_size)) {
9430 LOCAL_SET_GL_ERROR( 9539 LOCAL_SET_GL_ERROR(
9431 GL_OUT_OF_MEMORY, "glCompressedTexImage2D", "out of memory"); 9540 GL_OUT_OF_MEMORY, "glCompressedTexImage2D", "out of memory");
(...skipping 4988 matching lines...) Expand 10 before | Expand all | Expand 10 after
14420 return error::kNoError; 14529 return error::kNoError;
14421 } 14530 }
14422 14531
14423 // Include the auto-generated part of this file. We split this because it means 14532 // 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 14533 // 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. 14534 // instead of having to edit some template or the code generator.
14426 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 14535 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
14427 14536
14428 } // namespace gles2 14537 } // namespace gles2
14429 } // namespace gpu 14538 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698