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

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

Issue 1925093002: Handle compressed textures allocated via TexStorage2D. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed gpu_unittests after last refactor. Created 4 years, 7 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 <limits.h> 7 #include <limits.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 #include <stdio.h> 10 #include <stdio.h>
(...skipping 1241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1252 unsigned target, 1252 unsigned target,
1253 int level, 1253 int level,
1254 unsigned format, 1254 unsigned format,
1255 unsigned type, 1255 unsigned type,
1256 int xoffset, 1256 int xoffset,
1257 int yoffset, 1257 int yoffset,
1258 int width, 1258 int width,
1259 int height) override; 1259 int height) override;
1260 1260
1261 // overridden from GLES2Decoder 1261 // overridden from GLES2Decoder
1262 bool ClearCompressedTextureLevel(Texture* texture,
1263 unsigned target,
1264 int level,
1265 unsigned format,
1266 int width,
1267 int height) override;
1268 bool IsCompressedTextureFormat(unsigned format) override;
1269
1270 // overridden from GLES2Decoder
1262 bool ClearLevel3D(Texture* texture, 1271 bool ClearLevel3D(Texture* texture,
1263 unsigned target, 1272 unsigned target,
1264 int level, 1273 int level,
1265 unsigned format, 1274 unsigned format,
1266 unsigned type, 1275 unsigned type,
1267 int width, 1276 int width,
1268 int height, 1277 int height,
1269 int depth) override; 1278 int depth) override;
1270 1279
1271 // Restore all GL state that affects clearing. 1280 // Restore all GL state that affects clearing.
(...skipping 9132 matching lines...) Expand 10 before | Expand all | Expand 10 after
10404 zero.get()); 10413 zero.get());
10405 y += tile_height; 10414 y += tile_height;
10406 } 10415 }
10407 TextureRef* bound_texture = 10416 TextureRef* bound_texture =
10408 texture_manager()->GetTextureInfoForTarget(&state_, texture->target()); 10417 texture_manager()->GetTextureInfoForTarget(&state_, texture->target());
10409 glBindTexture(texture->target(), 10418 glBindTexture(texture->target(),
10410 bound_texture ? bound_texture->service_id() : 0); 10419 bound_texture ? bound_texture->service_id() : 0);
10411 return true; 10420 return true;
10412 } 10421 }
10413 10422
10423 bool GLES2DecoderImpl::ClearCompressedTextureLevel(Texture* texture,
10424 unsigned target,
10425 int level,
10426 unsigned format,
10427 int width,
10428 int height) {
10429 DCHECK(target != GL_TEXTURE_3D && target != GL_TEXTURE_2D_ARRAY);
10430 // This code path can only be called if the texture was originally
10431 // allocated via TexStorage2D. Note that TexStorage2D is exposed
10432 // internally for ES 2.0 contexts, but compressed texture support is
10433 // not part of that exposure.
10434 DCHECK(feature_info_->IsES3Enabled());
10435
10436 GLsizei bytes_required = 0;
10437 if (!GetCompressedTexSizeInBytes(
10438 "ClearCompressedTextureLevel", width, height, 1, format,
10439 &bytes_required)) {
10440 return false;
10441 }
10442
10443 TRACE_EVENT1("gpu", "GLES2DecoderImpl::ClearCompressedTextureLevel",
10444 "bytes_required", bytes_required);
10445
10446 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
10447 std::unique_ptr<char[]> zero(new char[bytes_required]);
10448 memset(zero.get(), 0, bytes_required);
10449 glBindTexture(texture->target(), texture->service_id());
10450 glCompressedTexSubImage2D(
10451 target, level, 0, 0, width, height, format, bytes_required, zero.get());
10452 TextureRef* bound_texture =
10453 texture_manager()->GetTextureInfoForTarget(&state_, texture->target());
10454 glBindTexture(texture->target(),
10455 bound_texture ? bound_texture->service_id() : 0);
10456 Buffer* bound_buffer = buffer_manager()->GetBufferInfoForTarget(
10457 &state_, GL_PIXEL_UNPACK_BUFFER);
10458 if (bound_buffer) {
10459 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, bound_buffer->service_id());
10460 }
10461 return true;
10462 }
10463
10464 bool GLES2DecoderImpl::IsCompressedTextureFormat(unsigned format) {
10465 return feature_info_->validators()->compressed_texture_format.IsValid(
10466 format);
10467 }
10468
10414 bool GLES2DecoderImpl::ClearLevel3D(Texture* texture, 10469 bool GLES2DecoderImpl::ClearLevel3D(Texture* texture,
10415 unsigned target, 10470 unsigned target,
10416 int level, 10471 int level,
10417 unsigned format, 10472 unsigned format,
10418 unsigned type, 10473 unsigned type,
10419 int width, 10474 int width,
10420 int height, 10475 int height,
10421 int depth) { 10476 int depth) {
10422 DCHECK(target == GL_TEXTURE_3D || target == GL_TEXTURE_2D_ARRAY); 10477 DCHECK(target == GL_TEXTURE_3D || target == GL_TEXTURE_2D_ARRAY);
10423 DCHECK(feature_info_->IsES3Enabled()); 10478 DCHECK(feature_info_->IsES3Enabled());
(...skipping 1196 matching lines...) Expand 10 before | Expand all | Expand 10 after
11620 } 11675 }
11621 11676
11622 if (!ValidateCompressedTexFuncData("glCompressedTexSubImage2D", 11677 if (!ValidateCompressedTexFuncData("glCompressedTexSubImage2D",
11623 width, height, 1, format, image_size) || 11678 width, height, 1, format, image_size) ||
11624 !ValidateCompressedTexSubDimensions("glCompressedTexSubImage2D", 11679 !ValidateCompressedTexSubDimensions("glCompressedTexSubImage2D",
11625 target, level, xoffset, yoffset, 0, 11680 target, level, xoffset, yoffset, 0,
11626 width, height, 1, format, texture)) { 11681 width, height, 1, format, texture)) {
11627 return; 11682 return;
11628 } 11683 }
11629 11684
11685 if (!texture->IsLevelCleared(target, level)) {
11686 // This can only happen if the compressed texture was allocated
11687 // using TexStorage2D.
11688 DCHECK(texture->IsImmutable());
11689 GLsizei level_width = 0, level_height = 0;
11690 bool success = texture->GetLevelSize(
11691 target, level, &level_width, &level_height, nullptr);
11692 DCHECK(success);
11693 // We can skip the clear if we're uploading the entire level.
11694 if (xoffset == 0 && yoffset == 0 &&
11695 width == level_width && height == level_height) {
11696 texture_manager()->SetLevelCleared(texture_ref, target, level, true);
11697 } else {
11698 texture_manager()->ClearTextureLevel(this, texture_ref, target, level);
11699 }
11700 DCHECK(texture->IsLevelCleared(target, level));
11701 }
11630 11702
11631 // Note: There is no need to deal with texture cleared tracking here
11632 // because the validation above means you can only get here if the level
11633 // is already a matching compressed format and in that case
11634 // CompressedTexImage2D already cleared the texture.
11635 glCompressedTexSubImage2D( 11703 glCompressedTexSubImage2D(
11636 target, level, xoffset, yoffset, width, height, format, image_size, data); 11704 target, level, xoffset, yoffset, width, height, format, image_size, data);
11637 11705
11638 // This may be a slow command. Exit command processing to allow for 11706 // This may be a slow command. Exit command processing to allow for
11639 // context preemption and GPU watchdog checks. 11707 // context preemption and GPU watchdog checks.
11640 ExitCommandProcessingEarly(); 11708 ExitCommandProcessingEarly();
11641 } 11709 }
11642 11710
11643 static void Clip( 11711 static void Clip(
11644 GLint start, GLint range, GLint sourceRange, 11712 GLint start, GLint range, GLint sourceRange,
(...skipping 2676 matching lines...) Expand 10 before | Expand all | Expand 10 after
14321 } 14389 }
14322 if (levels <= 0) { 14390 if (levels <= 0) {
14323 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "levels <= 0"); 14391 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "levels <= 0");
14324 return; 14392 return;
14325 } 14393 }
14326 if (!validators_->texture_internal_format_storage.IsValid(internal_format)) { 14394 if (!validators_->texture_internal_format_storage.IsValid(internal_format)) {
14327 LOCAL_SET_GL_ERROR_INVALID_ENUM( 14395 LOCAL_SET_GL_ERROR_INVALID_ENUM(
14328 function_name, internal_format, "internal_format"); 14396 function_name, internal_format, "internal_format");
14329 return; 14397 return;
14330 } 14398 }
14331 bool is_compressed_format; 14399 bool is_compressed_format = IsCompressedTextureFormat(internal_format);
14332 switch (internal_format) { 14400 if (is_compressed_format && target == GL_TEXTURE_3D) {
14333 case GL_COMPRESSED_R11_EAC: 14401 LOCAL_SET_GL_ERROR(
14334 case GL_COMPRESSED_SIGNED_R11_EAC: 14402 GL_INVALID_OPERATION, function_name, "target invalid for format");
14335 case GL_COMPRESSED_RG11_EAC: 14403 return;
14336 case GL_COMPRESSED_SIGNED_RG11_EAC:
14337 case GL_COMPRESSED_RGB8_ETC2:
14338 case GL_COMPRESSED_SRGB8_ETC2:
14339 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
14340 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
14341 case GL_COMPRESSED_RGBA8_ETC2_EAC:
14342 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
14343 is_compressed_format = true;
14344 if (target == GL_TEXTURE_3D) {
14345 LOCAL_SET_GL_ERROR(
14346 GL_INVALID_OPERATION, function_name, "target invalid for format");
14347 return;
14348 }
14349 break;
14350 default:
14351 is_compressed_format = false;
14352 break;
14353 } 14404 }
14354 if (!texture_manager()->ValidForTarget(target, 0, width, height, depth) || 14405 if (!texture_manager()->ValidForTarget(target, 0, width, height, depth) ||
14355 TextureManager::ComputeMipMapCount( 14406 TextureManager::ComputeMipMapCount(
14356 target, width, height, depth) < levels) { 14407 target, width, height, depth) < levels) {
14357 LOCAL_SET_GL_ERROR( 14408 LOCAL_SET_GL_ERROR(
14358 GL_INVALID_VALUE, function_name, "dimensions out of range"); 14409 GL_INVALID_VALUE, function_name, "dimensions out of range");
14359 return; 14410 return;
14360 } 14411 }
14361 TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( 14412 TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget(
14362 &state_, target); 14413 &state_, target);
(...skipping 2013 matching lines...) Expand 10 before | Expand all | Expand 10 after
16376 } 16427 }
16377 16428
16378 // Include the auto-generated part of this file. We split this because it means 16429 // Include the auto-generated part of this file. We split this because it means
16379 // we can easily edit the non-auto generated parts right here in this file 16430 // we can easily edit the non-auto generated parts right here in this file
16380 // instead of having to edit some template or the code generator. 16431 // instead of having to edit some template or the code generator.
16381 #include "base/macros.h" 16432 #include "base/macros.h"
16382 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 16433 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
16383 16434
16384 } // namespace gles2 16435 } // namespace gles2
16385 } // namespace gpu 16436 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/gles2_cmd_decoder.h ('k') | gpu/command_buffer/service/gles2_cmd_decoder_mock.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698