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

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

Issue 139013008: Implement support for rendering to 32-bit float textures on ES3 (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Make TexSubImage validation agree with TexImage validation Created 6 years, 10 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 #include "base/bits.h" 6 #include "base/bits.h"
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "gpu/command_buffer/common/gles2_cmd_utils.h" 8 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
9 #include "gpu/command_buffer/service/context_state.h" 9 #include "gpu/command_buffer/service/context_state.h"
10 #include "gpu/command_buffer/service/error_state.h" 10 #include "gpu/command_buffer/service/error_state.h"
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 } 510 }
511 } 511 }
512 512
513 bool Texture::ValidForTexture( 513 bool Texture::ValidForTexture(
514 GLint target, 514 GLint target,
515 GLint level, 515 GLint level,
516 GLint xoffset, 516 GLint xoffset,
517 GLint yoffset, 517 GLint yoffset,
518 GLsizei width, 518 GLsizei width,
519 GLsizei height, 519 GLsizei height,
520 GLenum format,
521 GLenum type) const { 520 GLenum type) const {
522 size_t face_index = GLTargetToFaceIndex(target); 521 size_t face_index = GLTargetToFaceIndex(target);
523 if (level >= 0 && face_index < level_infos_.size() && 522 if (level >= 0 && face_index < level_infos_.size() &&
524 static_cast<size_t>(level) < level_infos_[face_index].size()) { 523 static_cast<size_t>(level) < level_infos_[face_index].size()) {
525 const LevelInfo& info = level_infos_[GLTargetToFaceIndex(target)][level]; 524 const LevelInfo& info = level_infos_[GLTargetToFaceIndex(target)][level];
526 int32 right; 525 int32 right;
527 int32 top; 526 int32 top;
528 return SafeAddInt32(xoffset, width, &right) && 527 return SafeAddInt32(xoffset, width, &right) &&
529 SafeAddInt32(yoffset, height, &top) && 528 SafeAddInt32(yoffset, height, &top) &&
530 xoffset >= 0 && 529 xoffset >= 0 &&
531 yoffset >= 0 && 530 yoffset >= 0 &&
532 right <= info.width && 531 right <= info.width &&
533 top <= info.height && 532 top <= info.height &&
534 format == info.internal_format &&
535 type == info.type; 533 type == info.type;
536 } 534 }
537 return false; 535 return false;
538 } 536 }
539 537
540 bool Texture::GetLevelSize( 538 bool Texture::GetLevelSize(
541 GLint target, GLint level, GLsizei* width, GLsizei* height) const { 539 GLint target, GLint level, GLsizei* width, GLsizei* height) const {
542 DCHECK(width); 540 DCHECK(width);
543 DCHECK(height); 541 DCHECK(height);
544 size_t face_index = GLTargetToFaceIndex(target); 542 size_t face_index = GLTargetToFaceIndex(target);
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after
1252 void TextureManager::UpdateNumImages(int delta) { 1250 void TextureManager::UpdateNumImages(int delta) {
1253 num_images_ += delta; 1251 num_images_ += delta;
1254 DCHECK_GE(num_images_, 0); 1252 DCHECK_GE(num_images_, 0);
1255 } 1253 }
1256 1254
1257 void TextureManager::IncFramebufferStateChangeCount() { 1255 void TextureManager::IncFramebufferStateChangeCount() {
1258 if (framebuffer_manager_) 1256 if (framebuffer_manager_)
1259 framebuffer_manager_->IncFramebufferStateChangeCount(); 1257 framebuffer_manager_->IncFramebufferStateChangeCount();
1260 } 1258 }
1261 1259
1262 bool TextureManager::ValidateTextureParameters( 1260 bool TextureManager::ValidateFormatAndTypeCombination(
1263 ErrorState* error_state, const char* function_name, 1261 ErrorState* error_state, const char* function_name, GLenum format,
1264 GLenum target, GLenum format, GLenum type, GLint level) { 1262 GLenum type) {
1265 if (!feature_info_->GetTextureFormatValidator(format).IsValid(type)) { 1263 if (!feature_info_->GetTextureFormatValidator(format).IsValid(type)) {
1266 ERRORSTATE_SET_GL_ERROR(
1267 error_state, GL_INVALID_OPERATION, function_name,
1268 (std::string("invalid type ") +
1269 GLES2Util::GetStringEnum(type) + " for format " +
1270 GLES2Util::GetStringEnum(format)).c_str());
1271 return false;
1272 }
1273
1274 uint32 channels = GLES2Util::GetChannelsForFormat(format);
1275 if ((channels & (GLES2Util::kDepth | GLES2Util::kStencil)) != 0 && level) {
1276 ERRORSTATE_SET_GL_ERROR( 1264 ERRORSTATE_SET_GL_ERROR(
1277 error_state, GL_INVALID_OPERATION, function_name, 1265 error_state, GL_INVALID_OPERATION, function_name,
1278 (std::string("invalid type ") + 1266 (std::string("invalid type ") +
1279 GLES2Util::GetStringEnum(type) + " for format " + 1267 GLES2Util::GetStringEnum(type) + " for format " +
1280 GLES2Util::GetStringEnum(format)).c_str()); 1268 GLES2Util::GetStringEnum(format)).c_str());
1281 return false; 1269 return false;
1282 } 1270 }
1283 return true; 1271 return true;
1284 } 1272 }
1285 1273
1274 bool TextureManager::ValidateTextureParameters(
1275 ErrorState* error_state, const char* function_name,
1276 GLenum format, GLenum type, GLenum internal_format, GLint level) {
1277 const Validators* validators = feature_info_->validators();
1278 if (!validators->texture_format.IsValid(format)) {
1279 ERRORSTATE_SET_GL_ERROR_INVALID_ENUM(
1280 error_state, function_name, format, "format");
1281 return false;
1282 }
1283 if (!validators->pixel_type.IsValid(type)) {
1284 ERRORSTATE_SET_GL_ERROR_INVALID_ENUM(
1285 error_state, function_name, type, "type");
1286 return false;
1287 }
1288 if (format != internal_format &&
1289 !((internal_format == GL_RGBA32F && format == GL_RGBA) ||
1290 (internal_format == GL_RGB32F && format == GL_RGB))) {
1291 ERRORSTATE_SET_GL_ERROR(
1292 error_state, GL_INVALID_OPERATION, function_name,
1293 "format != internalformat");
1294 return false;
1295 }
1296 uint32 channels = GLES2Util::GetChannelsForFormat(format);
1297 if ((channels & (GLES2Util::kDepth | GLES2Util::kStencil)) != 0 && level) {
1298 ERRORSTATE_SET_GL_ERROR(
1299 error_state, GL_INVALID_OPERATION, function_name,
1300 (std::string("invalid format ") + GLES2Util::GetStringEnum(format) +
1301 " for level != 0").c_str());
1302 return false;
1303 }
1304 return ValidateFormatAndTypeCombination(error_state, function_name,
1305 format, type);
1306 }
1307
1286 // Gets the texture id for a given target. 1308 // Gets the texture id for a given target.
1287 TextureRef* TextureManager::GetTextureInfoForTarget( 1309 TextureRef* TextureManager::GetTextureInfoForTarget(
1288 ContextState* state, GLenum target) { 1310 ContextState* state, GLenum target) {
1289 TextureUnit& unit = state->texture_units[state->active_texture_unit]; 1311 TextureUnit& unit = state->texture_units[state->active_texture_unit];
1290 TextureRef* texture = NULL; 1312 TextureRef* texture = NULL;
1291 switch (target) { 1313 switch (target) {
1292 case GL_TEXTURE_2D: 1314 case GL_TEXTURE_2D:
1293 texture = unit.bound_texture_2d.get(); 1315 texture = unit.bound_texture_2d.get();
1294 break; 1316 break;
1295 case GL_TEXTURE_CUBE_MAP: 1317 case GL_TEXTURE_CUBE_MAP:
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1329 const char* function_name, 1351 const char* function_name,
1330 const DoTextImage2DArguments& args, 1352 const DoTextImage2DArguments& args,
1331 TextureRef** texture_ref) { 1353 TextureRef** texture_ref) {
1332 ErrorState* error_state = state->GetErrorState(); 1354 ErrorState* error_state = state->GetErrorState();
1333 const Validators* validators = feature_info_->validators(); 1355 const Validators* validators = feature_info_->validators();
1334 if (!validators->texture_target.IsValid(args.target)) { 1356 if (!validators->texture_target.IsValid(args.target)) {
1335 ERRORSTATE_SET_GL_ERROR_INVALID_ENUM( 1357 ERRORSTATE_SET_GL_ERROR_INVALID_ENUM(
1336 error_state, function_name, args.target, "target"); 1358 error_state, function_name, args.target, "target");
1337 return false; 1359 return false;
1338 } 1360 }
1339 if (!validators->texture_format.IsValid(args.internal_format)) { 1361 if (!validators->texture_internal_format.IsValid(args.internal_format)) {
1340 ERRORSTATE_SET_GL_ERROR_INVALID_ENUM( 1362 ERRORSTATE_SET_GL_ERROR_INVALID_ENUM(
1341 error_state, function_name, args.internal_format, 1363 error_state, function_name, args.internal_format,
1342 "internal_format"); 1364 "internalformat");
1343 return false;
1344 }
1345 if (!validators->texture_format.IsValid(args.format)) {
1346 ERRORSTATE_SET_GL_ERROR_INVALID_ENUM(
1347 error_state, function_name, args.format, "format");
1348 return false;
1349 }
1350 if (!validators->pixel_type.IsValid(args.type)) {
1351 ERRORSTATE_SET_GL_ERROR_INVALID_ENUM(
1352 error_state, function_name, args.type, "type");
1353 return false;
1354 }
1355 if (args.format != args.internal_format) {
1356 ERRORSTATE_SET_GL_ERROR(
1357 error_state, GL_INVALID_OPERATION, function_name,
1358 "format != internalFormat");
1359 return false; 1365 return false;
1360 } 1366 }
1361 if (!ValidateTextureParameters( 1367 if (!ValidateTextureParameters(
1362 error_state, function_name, args.target, args.format, args.type, 1368 error_state, function_name, args.format, args.type,
1363 args.level)) { 1369 args.internal_format, args.level)) {
1364 return false; 1370 return false;
1365 } 1371 }
1366 if (!ValidForTarget(args.target, args.level, args.width, args.height, 1) || 1372 if (!ValidForTarget(args.target, args.level, args.width, args.height, 1) ||
1367 args.border != 0) { 1373 args.border != 0) {
1368 ERRORSTATE_SET_GL_ERROR( 1374 ERRORSTATE_SET_GL_ERROR(
1369 error_state, GL_INVALID_VALUE, function_name, 1375 error_state, GL_INVALID_VALUE, function_name,
1370 "dimensions out of range"); 1376 "dimensions out of range");
1371 return false; 1377 return false;
1372 } 1378 }
1373 if ((GLES2Util::GetChannelsForFormat(args.format) & 1379 if ((GLES2Util::GetChannelsForFormat(args.format) &
(...skipping 15 matching lines...) Expand all
1389 ERRORSTATE_SET_GL_ERROR( 1395 ERRORSTATE_SET_GL_ERROR(
1390 error_state, GL_INVALID_OPERATION, function_name, 1396 error_state, GL_INVALID_OPERATION, function_name,
1391 "texture is immutable"); 1397 "texture is immutable");
1392 return false; 1398 return false;
1393 } 1399 }
1394 1400
1395 // TODO - verify that using the managed vs unmanaged does not matter. 1401 // TODO - verify that using the managed vs unmanaged does not matter.
1396 // They both use the same MemoryTracker, and this call just re-routes 1402 // They both use the same MemoryTracker, and this call just re-routes
1397 // to it. 1403 // to it.
1398 if (!memory_tracker_managed_->EnsureGPUMemoryAvailable(args.pixels_size)) { 1404 if (!memory_tracker_managed_->EnsureGPUMemoryAvailable(args.pixels_size)) {
1399 ERRORSTATE_SET_GL_ERROR(error_state, GL_OUT_OF_MEMORY, "glTexImage2D", 1405 ERRORSTATE_SET_GL_ERROR(error_state, GL_OUT_OF_MEMORY, function_name,
1400 "out of memory"); 1406 "out of memory");
1401 return false; 1407 return false;
1402 } 1408 }
1403 1409
1404 // Write the TextureReference since this is valid. 1410 // Write the TextureReference since this is valid.
1405 *texture_ref = local_texture_ref; 1411 *texture_ref = local_texture_ref;
1406 return true; 1412 return true;
1407 } 1413 }
1408 1414
1409 void TextureManager::ValidateAndDoTexImage2D( 1415 void TextureManager::ValidateAndDoTexImage2D(
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1487 } 1493 }
1488 1494
1489 ScopedTextureUploadTimer::~ScopedTextureUploadTimer() { 1495 ScopedTextureUploadTimer::~ScopedTextureUploadTimer() {
1490 texture_state_->texture_upload_count++; 1496 texture_state_->texture_upload_count++;
1491 texture_state_->total_texture_upload_time += 1497 texture_state_->total_texture_upload_time +=
1492 base::TimeTicks::HighResNow() - begin_time_; 1498 base::TimeTicks::HighResNow() - begin_time_;
1493 } 1499 }
1494 1500
1495 } // namespace gles2 1501 } // namespace gles2
1496 } // namespace gpu 1502 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698