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

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: Add braces and cleanup. Created 5 years, 3 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 3147 matching lines...) Expand 10 before | Expand all | Expand 10 after
3158 caps.minor_version = 0; 3158 caps.minor_version = 0;
3159 } 3159 }
3160 if (feature_info_->feature_flags().multisampled_render_to_texture || 3160 if (feature_info_->feature_flags().multisampled_render_to_texture ||
3161 feature_info_->feature_flags().chromium_framebuffer_multisample || 3161 feature_info_->feature_flags().chromium_framebuffer_multisample ||
3162 unsafe_es3_apis_enabled()) { 3162 unsafe_es3_apis_enabled()) {
3163 DoGetIntegerv(GL_MAX_SAMPLES, &caps.max_samples); 3163 DoGetIntegerv(GL_MAX_SAMPLES, &caps.max_samples);
3164 } 3164 }
3165 3165
3166 caps.egl_image_external = 3166 caps.egl_image_external =
3167 feature_info_->feature_flags().oes_egl_image_external; 3167 feature_info_->feature_flags().oes_egl_image_external;
3168 caps.texture_format_astc =
3169 feature_info_->feature_flags().ext_texture_format_astc;
3168 caps.texture_format_atc = 3170 caps.texture_format_atc =
3169 feature_info_->feature_flags().ext_texture_format_atc; 3171 feature_info_->feature_flags().ext_texture_format_atc;
3170 caps.texture_format_bgra8888 = 3172 caps.texture_format_bgra8888 =
3171 feature_info_->feature_flags().ext_texture_format_bgra8888; 3173 feature_info_->feature_flags().ext_texture_format_bgra8888;
3172 caps.texture_format_dxt1 = 3174 caps.texture_format_dxt1 =
3173 feature_info_->feature_flags().ext_texture_format_dxt1; 3175 feature_info_->feature_flags().ext_texture_format_dxt1;
3174 caps.texture_format_dxt5 = 3176 caps.texture_format_dxt5 =
3175 feature_info_->feature_flags().ext_texture_format_dxt5; 3177 feature_info_->feature_flags().ext_texture_format_dxt5;
3176 caps.texture_format_etc1 = 3178 caps.texture_format_etc1 =
3177 feature_info_->feature_flags().oes_compressed_etc1_rgb8_texture; 3179 feature_info_->feature_flags().oes_compressed_etc1_rgb8_texture;
(...skipping 3752 matching lines...) Expand 10 before | Expand all | Expand 10 after
6930 } 6932 }
6931 } 6933 }
6932 } 6934 }
6933 6935
6934 bool GLES2DecoderImpl::PrepareTexturesForRender() { 6936 bool GLES2DecoderImpl::PrepareTexturesForRender() {
6935 DCHECK(state_.current_program.get()); 6937 DCHECK(state_.current_program.get());
6936 if (!texture_manager()->HaveUnrenderableTextures() && 6938 if (!texture_manager()->HaveUnrenderableTextures() &&
6937 !texture_manager()->HaveImages()) { 6939 !texture_manager()->HaveImages()) {
6938 return true; 6940 return true;
6939 } 6941 }
6940
6941 bool textures_set = false; 6942 bool textures_set = false;
6942 const Program::SamplerIndices& sampler_indices = 6943 const Program::SamplerIndices& sampler_indices =
6943 state_.current_program->sampler_indices(); 6944 state_.current_program->sampler_indices();
6944 for (size_t ii = 0; ii < sampler_indices.size(); ++ii) { 6945 for (size_t ii = 0; ii < sampler_indices.size(); ++ii) {
6945 const Program::UniformInfo* uniform_info = 6946 const Program::UniformInfo* uniform_info =
6946 state_.current_program->GetUniformInfo(sampler_indices[ii]); 6947 state_.current_program->GetUniformInfo(sampler_indices[ii]);
6947 DCHECK(uniform_info); 6948 DCHECK(uniform_info);
6948 for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) { 6949 for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) {
6949 GLuint texture_unit_index = uniform_info->texture_units[jj]; 6950 GLuint texture_unit_index = uniform_info->texture_units[jj];
6950 if (texture_unit_index < state_.texture_units.size()) { 6951 if (texture_unit_index < state_.texture_units.size()) {
(...skipping 2256 matching lines...) Expand 10 before | Expand all | Expand 10 after
9207 } 9208 }
9208 TextureRef* bound_texture = 9209 TextureRef* bound_texture =
9209 texture_manager()->GetTextureInfoForTarget(&state_, texture->target()); 9210 texture_manager()->GetTextureInfoForTarget(&state_, texture->target());
9210 glBindTexture(texture->target(), 9211 glBindTexture(texture->target(),
9211 bound_texture ? bound_texture->service_id() : 0); 9212 bound_texture ? bound_texture->service_id() : 0);
9212 return true; 9213 return true;
9213 } 9214 }
9214 9215
9215 namespace { 9216 namespace {
9216 9217
9218 const int kASTCBlockSize = 16;
9217 const int kS3TCBlockWidth = 4; 9219 const int kS3TCBlockWidth = 4;
9218 const int kS3TCBlockHeight = 4; 9220 const int kS3TCBlockHeight = 4;
9219 const int kS3TCDXT1BlockSize = 8; 9221 const int kS3TCDXT1BlockSize = 8;
9220 const int kS3TCDXT3AndDXT5BlockSize = 16; 9222 const int kS3TCDXT3AndDXT5BlockSize = 16;
9221 const int kEACAndETC2BlockSize = 4; 9223 const int kEACAndETC2BlockSize = 4;
9222 9224
9225 typedef struct {
9226 int blockWidth;
9227 int blockHeight;
9228 } ASTCBlockArray;
9229
9230 const ASTCBlockArray kASTCBlockArray[] = {
9231 {4, 4}, /* GL_COMPRESSED_RGBA_ASTC_4x4_KHR */
9232 {5, 4}, /* and GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR */
9233 {5, 5},
9234 {6, 5},
9235 {6, 6},
9236 {8, 5},
9237 {8, 6},
9238 {8, 8},
9239 {10, 5},
9240 {10, 6},
9241 {10, 8},
9242 {10, 10},
9243 {12, 10},
9244 {12, 12}};
9245
9223 bool IsValidDXTSize(GLint level, GLsizei size) { 9246 bool IsValidDXTSize(GLint level, GLsizei size) {
9224 return (size == 1) || 9247 return (size == 1) ||
9225 (size == 2) || !(size % kS3TCBlockWidth); 9248 (size == 2) || !(size % kS3TCBlockWidth);
9226 } 9249 }
9227 9250
9228 bool IsValidPVRTCSize(GLint level, GLsizei size) { 9251 bool IsValidPVRTCSize(GLint level, GLsizei size) {
9229 return GLES2Util::IsPOT(size); 9252 return GLES2Util::IsPOT(size);
9230 } 9253 }
9231 9254
9232 } // anonymous namespace. 9255 } // anonymous namespace.
9233 9256
9234 bool GLES2DecoderImpl::GetCompressedTexSizeInBytes( 9257 bool GLES2DecoderImpl::GetCompressedTexSizeInBytes(
9235 const char* function_name, GLsizei width, GLsizei height, GLsizei depth, 9258 const char* function_name, GLsizei width, GLsizei height, GLsizei depth,
9236 GLenum format, GLsizei* size_in_bytes) { 9259 GLenum format, GLsizei* size_in_bytes) {
9237 base::CheckedNumeric<GLsizei> bytes_required(0); 9260 base::CheckedNumeric<GLsizei> bytes_required(0);
9238 9261
9239 switch (format) { 9262 switch (format) {
9240 case GL_ATC_RGB_AMD: 9263 case GL_ATC_RGB_AMD:
9241 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: 9264 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
9242 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: 9265 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
9243 case GL_ETC1_RGB8_OES: 9266 case GL_ETC1_RGB8_OES:
9244 bytes_required = 9267 bytes_required =
9245 (width + kS3TCBlockWidth - 1) / kS3TCBlockWidth; 9268 (width + kS3TCBlockWidth - 1) / kS3TCBlockWidth;
9246 bytes_required *= 9269 bytes_required *=
9247 (height + kS3TCBlockHeight - 1) / kS3TCBlockHeight; 9270 (height + kS3TCBlockHeight - 1) / kS3TCBlockHeight;
9248 bytes_required *= kS3TCDXT1BlockSize; 9271 bytes_required *= kS3TCDXT1BlockSize;
9249 break; 9272 break;
9273 case GL_COMPRESSED_RGBA_ASTC_4x4_KHR:
9274 case GL_COMPRESSED_RGBA_ASTC_5x4_KHR:
9275 case GL_COMPRESSED_RGBA_ASTC_5x5_KHR:
9276 case GL_COMPRESSED_RGBA_ASTC_6x5_KHR:
9277 case GL_COMPRESSED_RGBA_ASTC_6x6_KHR:
9278 case GL_COMPRESSED_RGBA_ASTC_8x5_KHR:
9279 case GL_COMPRESSED_RGBA_ASTC_8x6_KHR:
9280 case GL_COMPRESSED_RGBA_ASTC_8x8_KHR:
9281 case GL_COMPRESSED_RGBA_ASTC_10x5_KHR:
9282 case GL_COMPRESSED_RGBA_ASTC_10x6_KHR:
9283 case GL_COMPRESSED_RGBA_ASTC_10x8_KHR:
9284 case GL_COMPRESSED_RGBA_ASTC_10x10_KHR:
9285 case GL_COMPRESSED_RGBA_ASTC_12x10_KHR:
9286 case GL_COMPRESSED_RGBA_ASTC_12x12_KHR:
9287 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
9288 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
9289 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
9290 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
9291 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
9292 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
9293 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
9294 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
9295 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
9296 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
9297 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
9298 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
9299 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
9300 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR: {
9301 const int index = (format < GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR) ?
9302 static_cast<int>(format - GL_COMPRESSED_RGBA_ASTC_4x4_KHR) :
9303 static_cast<int>(format - GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR);
9304
9305 const int kBlockWidth = kASTCBlockArray[index].blockWidth;
9306 const int kBlockHeight = kASTCBlockArray[index].blockHeight;
9307
9308 bytes_required =
9309 (width + kBlockWidth - 1) / kBlockWidth;
9310 bytes_required *=
9311 (height + kBlockHeight - 1) / kBlockHeight;
9312
9313 bytes_required *= kASTCBlockSize;
9314 break;
9315 }
9250 case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD: 9316 case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD:
9251 case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD: 9317 case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD:
9252 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: 9318 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
9253 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: 9319 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
9254 bytes_required = 9320 bytes_required =
9255 (width + kS3TCBlockWidth - 1) / kS3TCBlockWidth; 9321 (width + kS3TCBlockWidth - 1) / kS3TCBlockWidth;
9256 bytes_required *= 9322 bytes_required *=
9257 (height + kS3TCBlockHeight - 1) / kS3TCBlockHeight; 9323 (height + kS3TCBlockHeight - 1) / kS3TCBlockHeight;
9258 bytes_required *= kS3TCDXT3AndDXT5BlockSize; 9324 bytes_required *= kS3TCDXT3AndDXT5BlockSize;
9259 break; 9325 break;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
9340 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: 9406 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
9341 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: 9407 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
9342 DCHECK_EQ(1, depth); // 2D formats. 9408 DCHECK_EQ(1, depth); // 2D formats.
9343 if (!IsValidDXTSize(level, width) || !IsValidDXTSize(level, height)) { 9409 if (!IsValidDXTSize(level, width) || !IsValidDXTSize(level, height)) {
9344 LOCAL_SET_GL_ERROR( 9410 LOCAL_SET_GL_ERROR(
9345 GL_INVALID_OPERATION, function_name, 9411 GL_INVALID_OPERATION, function_name,
9346 "width or height invalid for level"); 9412 "width or height invalid for level");
9347 return false; 9413 return false;
9348 } 9414 }
9349 return true; 9415 return true;
9416 case GL_COMPRESSED_RGBA_ASTC_4x4_KHR:
9417 case GL_COMPRESSED_RGBA_ASTC_5x4_KHR:
9418 case GL_COMPRESSED_RGBA_ASTC_5x5_KHR:
9419 case GL_COMPRESSED_RGBA_ASTC_6x5_KHR:
9420 case GL_COMPRESSED_RGBA_ASTC_6x6_KHR:
9421 case GL_COMPRESSED_RGBA_ASTC_8x5_KHR:
9422 case GL_COMPRESSED_RGBA_ASTC_8x6_KHR:
9423 case GL_COMPRESSED_RGBA_ASTC_8x8_KHR:
9424 case GL_COMPRESSED_RGBA_ASTC_10x5_KHR:
9425 case GL_COMPRESSED_RGBA_ASTC_10x6_KHR:
9426 case GL_COMPRESSED_RGBA_ASTC_10x8_KHR:
9427 case GL_COMPRESSED_RGBA_ASTC_10x10_KHR:
9428 case GL_COMPRESSED_RGBA_ASTC_12x10_KHR:
9429 case GL_COMPRESSED_RGBA_ASTC_12x12_KHR:
9430 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
9431 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
9432 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
9433 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
9434 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
9435 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
9436 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
9437 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
9438 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
9439 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
9440 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
9441 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
9442 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
9443 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
9350 case GL_ATC_RGB_AMD: 9444 case GL_ATC_RGB_AMD:
9351 case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD: 9445 case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD:
9352 case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD: 9446 case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD:
9353 case GL_ETC1_RGB8_OES: 9447 case GL_ETC1_RGB8_OES:
9354 DCHECK_EQ(1, depth); // 2D formats. 9448 DCHECK_EQ(1, depth); // 2D formats.
9355 if (width <= 0 || height <= 0) { 9449 if (width <= 0 || height <= 0) {
9356 LOCAL_SET_GL_ERROR( 9450 LOCAL_SET_GL_ERROR(
9357 GL_INVALID_OPERATION, function_name, 9451 GL_INVALID_OPERATION, function_name,
9358 "width or height invalid for level"); 9452 "width or height invalid for level");
9359 return false; 9453 return false;
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
9545 "glCompressedTexImage2D", "unknown texture target"); 9639 "glCompressedTexImage2D", "unknown texture target");
9546 return error::kNoError; 9640 return error::kNoError;
9547 } 9641 }
9548 Texture* texture = texture_ref->texture(); 9642 Texture* texture = texture_ref->texture();
9549 if (texture->IsImmutable()) { 9643 if (texture->IsImmutable()) {
9550 LOCAL_SET_GL_ERROR( 9644 LOCAL_SET_GL_ERROR(
9551 GL_INVALID_OPERATION, 9645 GL_INVALID_OPERATION,
9552 "glCompressedTexImage2D", "texture is immutable"); 9646 "glCompressedTexImage2D", "texture is immutable");
9553 return error::kNoError; 9647 return error::kNoError;
9554 } 9648 }
9555
9556 if (!ValidateCompressedTexDimensions("glCompressedTexImage2D", target, level, 9649 if (!ValidateCompressedTexDimensions("glCompressedTexImage2D", target, level,
9557 width, height, 1, internal_format) || 9650 width, height, 1, internal_format) ||
9558 !ValidateCompressedTexFuncData("glCompressedTexImage2D", width, height, 9651 !ValidateCompressedTexFuncData("glCompressedTexImage2D", width, height,
9559 1, internal_format, image_size)) { 9652 1, internal_format, image_size)) {
9560 return error::kNoError; 9653 return error::kNoError;
9561 } 9654 }
9562 9655
9563 if (!EnsureGPUMemoryAvailable(image_size)) { 9656 if (!EnsureGPUMemoryAvailable(image_size)) {
9564 LOCAL_SET_GL_ERROR( 9657 LOCAL_SET_GL_ERROR(
9565 GL_OUT_OF_MEMORY, "glCompressedTexImage2D", "out of memory"); 9658 GL_OUT_OF_MEMORY, "glCompressedTexImage2D", "out of memory");
(...skipping 5217 matching lines...) Expand 10 before | Expand all | Expand 10 after
14783 return error::kNoError; 14876 return error::kNoError;
14784 } 14877 }
14785 14878
14786 // Include the auto-generated part of this file. We split this because it means 14879 // Include the auto-generated part of this file. We split this because it means
14787 // we can easily edit the non-auto generated parts right here in this file 14880 // we can easily edit the non-auto generated parts right here in this file
14788 // instead of having to edit some template or the code generator. 14881 // instead of having to edit some template or the code generator.
14789 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 14882 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
14790 14883
14791 } // namespace gles2 14884 } // namespace gles2
14792 } // namespace gpu 14885 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/feature_info.cc ('k') | gpu/command_buffer/service/gles2_cmd_decoder_unittest_textures.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698