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

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

Issue 1505343003: Updating texture validation to account for sampler objects in ES3 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed issue on devices without TEXTURE_FLOAT_LINEAR Created 4 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 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 bool can_render_; 64 bool can_render_;
65 bool can_render_to_; 65 bool can_render_to_;
66 bool npot_; 66 bool npot_;
67 67
68 // Since we will be hashing this signature structure, the padding must be 68 // Since we will be hashing this signature structure, the padding must be
69 // zero initialized. Although the C++11 specifications specify that this is 69 // zero initialized. Although the C++11 specifications specify that this is
70 // true, we will use a constructor with a memset to further enforce it instead 70 // true, we will use a constructor with a memset to further enforce it instead
71 // of relying on compilers adhering to this deep dark corner specification. 71 // of relying on compilers adhering to this deep dark corner specification.
72 TextureSignature(GLenum target, 72 TextureSignature(GLenum target,
73 GLint level, 73 GLint level,
74 GLenum min_filter, 74 const SamplerState& sampler_state,
75 GLenum mag_filter,
76 GLenum wrap_r,
77 GLenum wrap_s,
78 GLenum wrap_t,
79 GLenum usage, 75 GLenum usage,
80 GLenum internal_format, 76 GLenum internal_format,
81 GLenum compare_func,
82 GLenum compare_mode,
83 GLsizei width, 77 GLsizei width,
84 GLsizei height, 78 GLsizei height,
85 GLsizei depth, 79 GLsizei depth,
86 GLfloat max_lod,
87 GLfloat min_lod,
88 GLint base_level, 80 GLint base_level,
89 GLint border, 81 GLint border,
90 GLint max_level, 82 GLint max_level,
91 GLenum format, 83 GLenum format,
92 GLenum type, 84 GLenum type,
93 bool has_image, 85 bool has_image,
94 bool can_render, 86 bool can_render,
95 bool can_render_to, 87 bool can_render_to,
96 bool npot) { 88 bool npot) {
97 memset(this, 0, sizeof(TextureSignature)); 89 memset(this, 0, sizeof(TextureSignature));
98 target_ = target; 90 target_ = target;
99 level_ = level; 91 level_ = level;
100 min_filter_ = min_filter; 92 min_filter_ = sampler_state.min_filter;
101 mag_filter_ = mag_filter; 93 mag_filter_ = sampler_state.mag_filter;
102 wrap_r_ = wrap_r; 94 wrap_r_ = sampler_state.wrap_r;
103 wrap_s_ = wrap_s; 95 wrap_s_ = sampler_state.wrap_s;
104 wrap_t_ = wrap_t; 96 wrap_t_ = sampler_state.wrap_t;
105 usage_ = usage; 97 usage_ = usage;
106 internal_format_ = internal_format; 98 internal_format_ = internal_format;
107 compare_func_ = compare_func; 99 compare_func_ = sampler_state.compare_func;
108 compare_mode_ = compare_mode; 100 compare_mode_ = sampler_state.compare_mode;
109 width_ = width; 101 width_ = width;
110 height_ = height; 102 height_ = height;
111 depth_ = depth; 103 depth_ = depth;
112 max_lod_ = max_lod; 104 max_lod_ = sampler_state.max_lod;
113 min_lod_ = min_lod; 105 min_lod_ = sampler_state.min_lod;
114 base_level_ = base_level; 106 base_level_ = base_level;
115 border_ = border; 107 border_ = border;
116 max_level_ = max_level; 108 max_level_ = max_level;
117 format_ = format; 109 format_ = format;
118 type_ = type; 110 type_ = type;
119 has_image_ = has_image; 111 has_image_ = has_image;
120 can_render_ = can_render; 112 can_render_ = can_render;
121 can_render_to_ = can_render_to; 113 can_render_to_ = can_render_to;
122 npot_ = npot; 114 npot_ = npot;
123 } 115 }
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 TextureManager::~TextureManager() { 274 TextureManager::~TextureManager() {
283 for (unsigned int i = 0; i < destruction_observers_.size(); i++) 275 for (unsigned int i = 0; i < destruction_observers_.size(); i++)
284 destruction_observers_[i]->OnTextureManagerDestroying(this); 276 destruction_observers_[i]->OnTextureManagerDestroying(this);
285 277
286 DCHECK(textures_.empty()); 278 DCHECK(textures_.empty());
287 279
288 // If this triggers, that means something is keeping a reference to 280 // If this triggers, that means something is keeping a reference to
289 // a Texture belonging to this. 281 // a Texture belonging to this.
290 CHECK_EQ(texture_count_, 0u); 282 CHECK_EQ(texture_count_, 0u);
291 283
292 DCHECK_EQ(0, num_unrenderable_textures_);
293 DCHECK_EQ(0, num_unsafe_textures_); 284 DCHECK_EQ(0, num_unsafe_textures_);
294 DCHECK_EQ(0, num_uncleared_mips_); 285 DCHECK_EQ(0, num_uncleared_mips_);
295 DCHECK_EQ(0, num_images_); 286 DCHECK_EQ(0, num_images_);
296 287
297 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( 288 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
298 this); 289 this);
299 } 290 }
300 291
301 void TextureManager::Destroy(bool have_context) { 292 void TextureManager::Destroy(bool have_context) {
302 have_context_ = have_context; 293 have_context_ = have_context;
(...skipping 11 matching lines...) Expand all
314 305
315 Texture::Texture(GLuint service_id) 306 Texture::Texture(GLuint service_id)
316 : mailbox_manager_(NULL), 307 : mailbox_manager_(NULL),
317 memory_tracking_ref_(NULL), 308 memory_tracking_ref_(NULL),
318 service_id_(service_id), 309 service_id_(service_id),
319 owned_service_id_(service_id), 310 owned_service_id_(service_id),
320 cleared_(true), 311 cleared_(true),
321 num_uncleared_mips_(0), 312 num_uncleared_mips_(0),
322 num_npot_faces_(0), 313 num_npot_faces_(0),
323 target_(0), 314 target_(0),
324 min_filter_(GL_NEAREST_MIPMAP_LINEAR),
325 mag_filter_(GL_LINEAR),
326 wrap_r_(GL_REPEAT),
327 wrap_s_(GL_REPEAT),
328 wrap_t_(GL_REPEAT),
329 usage_(GL_NONE), 315 usage_(GL_NONE),
330 compare_func_(GL_LEQUAL),
331 compare_mode_(GL_NONE),
332 max_lod_(1000.0f),
333 min_lod_(-1000.0f),
334 base_level_(0), 316 base_level_(0),
335 max_level_(1000), 317 max_level_(1000),
336 max_level_set_(-1), 318 max_level_set_(-1),
337 texture_complete_(false), 319 texture_complete_(false),
338 texture_mips_dirty_(false), 320 texture_mips_dirty_(false),
339 cube_complete_(false), 321 cube_complete_(false),
340 texture_level0_dirty_(false), 322 texture_level0_dirty_(false),
341 npot_(false), 323 npot_(false),
342 has_been_bound_(false), 324 has_been_bound_(false),
343 framebuffer_attachment_count_(0), 325 framebuffer_attachment_count_(0),
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 } 416 }
435 const Texture::LevelInfo& first_face = 417 const Texture::LevelInfo& first_face =
436 face_infos_[0].level_infos[base_level_]; 418 face_infos_[0].level_infos[base_level_];
437 if (first_face.width == 0 || 419 if (first_face.width == 0 ||
438 first_face.height == 0 || 420 first_face.height == 0 ||
439 first_face.depth == 0) { 421 first_face.depth == 0) {
440 return CAN_RENDER_NEVER; 422 return CAN_RENDER_NEVER;
441 } 423 }
442 } 424 }
443 425
444 bool needs_mips = NeedsMips();
445 if (needs_mips) {
446 if (!texture_complete())
447 return CAN_RENDER_NEVER;
448 }
449
450 if (target_ == GL_TEXTURE_CUBE_MAP && !cube_complete()) 426 if (target_ == GL_TEXTURE_CUBE_MAP && !cube_complete())
451 return CAN_RENDER_NEVER; 427 return CAN_RENDER_NEVER;
452 428
453 bool is_npot_compatible = !needs_mips && 429 // Texture may be renderable, but it depends on the sampler it's used with,
454 wrap_s_ == GL_CLAMP_TO_EDGE && 430 // the context that's using it, and the extensions available.
455 wrap_t_ == GL_CLAMP_TO_EDGE; 431 return CAN_RENDER_NEEDS_VALIDATION;
456
457 if (!is_npot_compatible) {
458 if (target_ == GL_TEXTURE_RECTANGLE_ARB)
459 return CAN_RENDER_NEVER;
460 else if (npot())
461 return CAN_RENDER_ONLY_IF_NPOT;
462 }
463
464 return CAN_RENDER_ALWAYS;
465 } 432 }
466 433
467 bool Texture::CanRender(const FeatureInfo* feature_info) const { 434 bool Texture::CanRender(const FeatureInfo* feature_info) const {
435 return CanRenderWithSampler(feature_info, sampler_state());
436 }
437
438 bool Texture::CanRenderWithSampler(const FeatureInfo* feature_info,
439 const SamplerState& sampler_state) const {
468 switch (can_render_condition_) { 440 switch (can_render_condition_) {
469 case CAN_RENDER_ALWAYS: 441 case CAN_RENDER_ALWAYS:
470 return true; 442 return true;
471 case CAN_RENDER_NEVER: 443 case CAN_RENDER_NEVER:
472 return false; 444 return false;
473 case CAN_RENDER_ONLY_IF_NPOT: 445 case CAN_RENDER_NEEDS_VALIDATION:
474 break; 446 break;
475 } 447 }
476 return feature_info->feature_flags().npot_ok; 448
449 bool needs_mips = sampler_state.min_filter != GL_NEAREST &&
450 sampler_state.min_filter != GL_LINEAR;
451 if (needs_mips) {
452 if (static_cast<size_t>(base_level_) >= face_infos_[0].level_infos.size())
453 return false;
454
455 const Texture::LevelInfo& first_level =
456 face_infos_[0].level_infos[base_level_];
457
458 if (!texture_complete()) {
459 return false;
460 } else if (first_level.type == GL_FLOAT &&
461 !feature_info->feature_flags().enable_texture_float_linear &&
462 (sampler_state.min_filter != GL_NEAREST_MIPMAP_NEAREST ||
463 sampler_state.mag_filter != GL_NEAREST)) {
464 return false;
465 } else if (first_level.type == GL_HALF_FLOAT_OES &&
466 !feature_info->feature_flags().enable_texture_half_float_linear &&
467 (sampler_state.min_filter != GL_NEAREST_MIPMAP_NEAREST ||
468 sampler_state.mag_filter != GL_NEAREST)) {
469 return false;
470 }
471 }
472
473 if (!feature_info->IsES3Enabled()) {
474 bool is_npot_compatible = !needs_mips &&
475 sampler_state.wrap_s == GL_CLAMP_TO_EDGE &&
476 sampler_state.wrap_t == GL_CLAMP_TO_EDGE;
477
478 if (!is_npot_compatible) {
479 if (target_ == GL_TEXTURE_RECTANGLE_ARB)
480 return false;
481 else if (npot())
482 return feature_info->feature_flags().npot_ok;
483 }
484 }
485
486 return true;
477 } 487 }
478 488
479 void Texture::AddToSignature( 489 void Texture::AddToSignature(
480 const FeatureInfo* feature_info, 490 const FeatureInfo* feature_info,
481 GLenum target, 491 GLenum target,
482 GLint level, 492 GLint level,
483 std::string* signature) const { 493 std::string* signature) const {
484 DCHECK(feature_info); 494 DCHECK(feature_info);
485 DCHECK(signature); 495 DCHECK(signature);
486 DCHECK_GE(level, 0); 496 DCHECK_GE(level, 0);
487 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); 497 size_t face_index = GLES2Util::GLTargetToFaceIndex(target);
488 DCHECK_LT(static_cast<size_t>(face_index), 498 DCHECK_LT(static_cast<size_t>(face_index),
489 face_infos_.size()); 499 face_infos_.size());
490 DCHECK_LT(static_cast<size_t>(level), 500 DCHECK_LT(static_cast<size_t>(level),
491 face_infos_[face_index].level_infos.size()); 501 face_infos_[face_index].level_infos.size());
492 502
493 const Texture::LevelInfo& info = 503 const Texture::LevelInfo& info =
494 face_infos_[face_index].level_infos[level]; 504 face_infos_[face_index].level_infos[level];
495 505
496 TextureSignature signature_data(target, 506 TextureSignature signature_data(target,
497 level, 507 level,
498 min_filter_, 508 sampler_state_,
499 mag_filter_,
500 wrap_r_,
501 wrap_s_,
502 wrap_t_,
503 usage_, 509 usage_,
504 info.internal_format, 510 info.internal_format,
505 compare_func_,
506 compare_mode_,
507 info.width, 511 info.width,
508 info.height, 512 info.height,
509 info.depth, 513 info.depth,
510 max_lod_,
511 min_lod_,
512 base_level_, 514 base_level_,
513 info.border, 515 info.border,
514 max_level_, 516 max_level_,
515 info.format, 517 info.format,
516 info.type, 518 info.type,
517 info.image.get() != NULL, 519 info.image.get() != NULL,
518 CanRender(feature_info), 520 CanRender(feature_info),
519 CanRenderTo(), 521 CanRenderTo(),
520 npot_); 522 npot_);
521 523
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 const FeatureInfo* feature_info, GLenum target, GLint max_levels) { 560 const FeatureInfo* feature_info, GLenum target, GLint max_levels) {
559 DCHECK_EQ(0u, target_); // you can only set this once. 561 DCHECK_EQ(0u, target_); // you can only set this once.
560 target_ = target; 562 target_ = target;
561 size_t num_faces = (target == GL_TEXTURE_CUBE_MAP) ? 6 : 1; 563 size_t num_faces = (target == GL_TEXTURE_CUBE_MAP) ? 6 : 1;
562 face_infos_.resize(num_faces); 564 face_infos_.resize(num_faces);
563 for (size_t ii = 0; ii < num_faces; ++ii) { 565 for (size_t ii = 0; ii < num_faces; ++ii) {
564 face_infos_[ii].level_infos.resize(max_levels); 566 face_infos_[ii].level_infos.resize(max_levels);
565 } 567 }
566 568
567 if (target == GL_TEXTURE_EXTERNAL_OES || target == GL_TEXTURE_RECTANGLE_ARB) { 569 if (target == GL_TEXTURE_EXTERNAL_OES || target == GL_TEXTURE_RECTANGLE_ARB) {
568 min_filter_ = GL_LINEAR; 570 sampler_state_.min_filter = GL_LINEAR;
569 wrap_s_ = wrap_t_ = GL_CLAMP_TO_EDGE; 571 sampler_state_.wrap_s = sampler_state_.wrap_t = GL_CLAMP_TO_EDGE;
570 } 572 }
571 573
572 if (target == GL_TEXTURE_EXTERNAL_OES) { 574 if (target == GL_TEXTURE_EXTERNAL_OES) {
573 immutable_ = true; 575 immutable_ = true;
574 } 576 }
575 Update(feature_info); 577 Update(feature_info);
576 UpdateCanRenderCondition(); 578 UpdateCanRenderCondition();
577 } 579 }
578 580
579 bool Texture::CanGenerateMipmaps( 581 bool Texture::CanGenerateMipmaps(
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 bool cleared = info->cleared_rect == gfx::Rect(info->width, info->height); 745 bool cleared = info->cleared_rect == gfx::Rect(info->width, info->height);
744 if (cleared == was_cleared) 746 if (cleared == was_cleared)
745 return; 747 return;
746 int delta = cleared ? -1 : +1; 748 int delta = cleared ? -1 : +1;
747 num_uncleared_mips_ += delta; 749 num_uncleared_mips_ += delta;
748 for (RefSet::iterator it = refs_.begin(); it != refs_.end(); ++it) 750 for (RefSet::iterator it = refs_.begin(); it != refs_.end(); ++it)
749 (*it)->manager()->UpdateUnclearedMips(delta); 751 (*it)->manager()->UpdateUnclearedMips(delta);
750 } 752 }
751 753
752 void Texture::UpdateCanRenderCondition() { 754 void Texture::UpdateCanRenderCondition() {
753 CanRenderCondition can_render_condition = GetCanRenderCondition(); 755 can_render_condition_ = GetCanRenderCondition();
754 if (can_render_condition_ == can_render_condition)
755 return;
756 for (RefSet::iterator it = refs_.begin(); it != refs_.end(); ++it)
757 (*it)->manager()->UpdateCanRenderCondition(can_render_condition_,
758 can_render_condition);
759 can_render_condition_ = can_render_condition;
760 } 756 }
761 757
762 void Texture::UpdateHasImages() { 758 void Texture::UpdateHasImages() {
763 if (face_infos_.empty()) 759 if (face_infos_.empty())
764 return; 760 return;
765 761
766 bool has_images = false; 762 bool has_images = false;
767 for (size_t ii = 0; ii < face_infos_.size(); ++ii) { 763 for (size_t ii = 0; ii < face_infos_.size(); ++ii) {
768 for (size_t jj = 0; jj < face_infos_[ii].level_infos.size(); ++jj) { 764 for (size_t jj = 0; jj < face_infos_[ii].level_infos.size(); ++jj) {
769 const Texture::LevelInfo& info = face_infos_[ii].level_infos[jj]; 765 const Texture::LevelInfo& info = face_infos_[ii].level_infos[jj];
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 case GL_TEXTURE_MIN_LOD: 984 case GL_TEXTURE_MIN_LOD:
989 case GL_TEXTURE_MAX_LOD: 985 case GL_TEXTURE_MAX_LOD:
990 { 986 {
991 GLfloat fparam = static_cast<GLfloat>(param); 987 GLfloat fparam = static_cast<GLfloat>(param);
992 return SetParameterf(feature_info, pname, fparam); 988 return SetParameterf(feature_info, pname, fparam);
993 } 989 }
994 case GL_TEXTURE_MIN_FILTER: 990 case GL_TEXTURE_MIN_FILTER:
995 if (!feature_info->validators()->texture_min_filter_mode.IsValid(param)) { 991 if (!feature_info->validators()->texture_min_filter_mode.IsValid(param)) {
996 return GL_INVALID_ENUM; 992 return GL_INVALID_ENUM;
997 } 993 }
998 min_filter_ = param; 994 sampler_state_.min_filter = param;
999 break; 995 break;
1000 case GL_TEXTURE_MAG_FILTER: 996 case GL_TEXTURE_MAG_FILTER:
1001 if (!feature_info->validators()->texture_mag_filter_mode.IsValid(param)) { 997 if (!feature_info->validators()->texture_mag_filter_mode.IsValid(param)) {
1002 return GL_INVALID_ENUM; 998 return GL_INVALID_ENUM;
1003 } 999 }
1004 mag_filter_ = param; 1000 sampler_state_.mag_filter = param;
1005 break; 1001 break;
1006 case GL_TEXTURE_WRAP_R: 1002 case GL_TEXTURE_WRAP_R:
1007 if (!feature_info->validators()->texture_wrap_mode.IsValid(param)) { 1003 if (!feature_info->validators()->texture_wrap_mode.IsValid(param)) {
1008 return GL_INVALID_ENUM; 1004 return GL_INVALID_ENUM;
1009 } 1005 }
1010 wrap_r_ = param; 1006 sampler_state_.wrap_r = param;
1011 break; 1007 break;
1012 case GL_TEXTURE_WRAP_S: 1008 case GL_TEXTURE_WRAP_S:
1013 if (!feature_info->validators()->texture_wrap_mode.IsValid(param)) { 1009 if (!feature_info->validators()->texture_wrap_mode.IsValid(param)) {
1014 return GL_INVALID_ENUM; 1010 return GL_INVALID_ENUM;
1015 } 1011 }
1016 wrap_s_ = param; 1012 sampler_state_.wrap_s = param;
1017 break; 1013 break;
1018 case GL_TEXTURE_WRAP_T: 1014 case GL_TEXTURE_WRAP_T:
1019 if (!feature_info->validators()->texture_wrap_mode.IsValid(param)) { 1015 if (!feature_info->validators()->texture_wrap_mode.IsValid(param)) {
1020 return GL_INVALID_ENUM; 1016 return GL_INVALID_ENUM;
1021 } 1017 }
1022 wrap_t_ = param; 1018 sampler_state_.wrap_t = param;
1023 break; 1019 break;
1024 case GL_TEXTURE_COMPARE_FUNC: 1020 case GL_TEXTURE_COMPARE_FUNC:
1025 if (!feature_info->validators()->texture_compare_func.IsValid(param)) { 1021 if (!feature_info->validators()->texture_compare_func.IsValid(param)) {
1026 return GL_INVALID_ENUM; 1022 return GL_INVALID_ENUM;
1027 } 1023 }
1028 compare_func_ = param; 1024 sampler_state_.compare_func = param;
1029 break; 1025 break;
1030 case GL_TEXTURE_COMPARE_MODE: 1026 case GL_TEXTURE_COMPARE_MODE:
1031 if (!feature_info->validators()->texture_compare_mode.IsValid(param)) { 1027 if (!feature_info->validators()->texture_compare_mode.IsValid(param)) {
1032 return GL_INVALID_ENUM; 1028 return GL_INVALID_ENUM;
1033 } 1029 }
1034 compare_mode_ = param; 1030 sampler_state_.compare_mode = param;
1035 break; 1031 break;
1036 case GL_TEXTURE_BASE_LEVEL: 1032 case GL_TEXTURE_BASE_LEVEL:
1037 if (param < 0) { 1033 if (param < 0) {
1038 return GL_INVALID_VALUE; 1034 return GL_INVALID_VALUE;
1039 } 1035 }
1040 UpdateBaseLevel(param); 1036 UpdateBaseLevel(param);
1041 break; 1037 break;
1042 case GL_TEXTURE_MAX_LEVEL: 1038 case GL_TEXTURE_MAX_LEVEL:
1043 if (param < 0) { 1039 if (param < 0) {
1044 return GL_INVALID_VALUE; 1040 return GL_INVALID_VALUE;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1077 case GL_TEXTURE_COMPARE_FUNC: 1073 case GL_TEXTURE_COMPARE_FUNC:
1078 case GL_TEXTURE_COMPARE_MODE: 1074 case GL_TEXTURE_COMPARE_MODE:
1079 case GL_TEXTURE_BASE_LEVEL: 1075 case GL_TEXTURE_BASE_LEVEL:
1080 case GL_TEXTURE_MAX_LEVEL: 1076 case GL_TEXTURE_MAX_LEVEL:
1081 case GL_TEXTURE_USAGE_ANGLE: 1077 case GL_TEXTURE_USAGE_ANGLE:
1082 { 1078 {
1083 GLint iparam = static_cast<GLint>(param); 1079 GLint iparam = static_cast<GLint>(param);
1084 return SetParameteri(feature_info, pname, iparam); 1080 return SetParameteri(feature_info, pname, iparam);
1085 } 1081 }
1086 case GL_TEXTURE_MIN_LOD: 1082 case GL_TEXTURE_MIN_LOD:
1087 min_lod_ = param; 1083 sampler_state_.min_lod = param;
1088 break; 1084 break;
1089 case GL_TEXTURE_MAX_LOD: 1085 case GL_TEXTURE_MAX_LOD:
1090 max_lod_ = param; 1086 sampler_state_.max_lod = param;
1091 break; 1087 break;
1092 case GL_TEXTURE_MAX_ANISOTROPY_EXT: 1088 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
1093 if (param < 1.f) { 1089 if (param < 1.f) {
1094 return GL_INVALID_VALUE; 1090 return GL_INVALID_VALUE;
1095 } 1091 }
1096 break; 1092 break;
1097 default: 1093 default:
1098 NOTREACHED(); 1094 NOTREACHED();
1099 return GL_INVALID_ENUM; 1095 return GL_INVALID_ENUM;
1100 } 1096 }
(...skipping 18 matching lines...) Expand all
1119 const GLsizei levels_needed = first_face.num_mip_levels; 1115 const GLsizei levels_needed = first_face.num_mip_levels;
1120 1116
1121 texture_complete_ = 1117 texture_complete_ =
1122 max_level_set_ >= (levels_needed - 1) && max_level_set_ >= 0; 1118 max_level_set_ >= (levels_needed - 1) && max_level_set_ >= 0;
1123 cube_complete_ = (face_infos_.size() == 6) && 1119 cube_complete_ = (face_infos_.size() == 6) &&
1124 (first_level.width == first_level.height) && 1120 (first_level.width == first_level.height) &&
1125 (first_level.width > 0); 1121 (first_level.width > 0);
1126 1122
1127 if (first_level.width == 0 || first_level.height == 0) { 1123 if (first_level.width == 0 || first_level.height == 0) {
1128 texture_complete_ = false; 1124 texture_complete_ = false;
1129 } else if (first_level.type == GL_FLOAT &&
1130 !feature_info->feature_flags().enable_texture_float_linear &&
1131 (min_filter_ != GL_NEAREST_MIPMAP_NEAREST ||
1132 mag_filter_ != GL_NEAREST)) {
1133 texture_complete_ = false;
1134 } else if (first_level.type == GL_HALF_FLOAT_OES &&
1135 !feature_info->feature_flags().enable_texture_half_float_linear &&
1136 (min_filter_ != GL_NEAREST_MIPMAP_NEAREST ||
1137 mag_filter_ != GL_NEAREST)) {
1138 texture_complete_ = false;
1139 } 1125 }
1140 1126
1141 bool texture_level0_complete = true; 1127 bool texture_level0_complete = true;
1142 if (cube_complete_ && texture_level0_dirty_) { 1128 if (cube_complete_ && texture_level0_dirty_) {
1143 for (size_t ii = 0; ii < face_infos_.size(); ++ii) { 1129 for (size_t ii = 0; ii < face_infos_.size(); ++ii) {
1144 const Texture::LevelInfo& face_base_level = 1130 const Texture::LevelInfo& face_base_level =
1145 face_infos_[ii].level_infos[base_level_]; 1131 face_infos_[ii].level_infos[base_level_];
1146 if (!TextureFaceComplete(first_level, 1132 if (!TextureFaceComplete(first_level,
1147 ii, 1133 ii,
1148 face_base_level.target, 1134 face_base_level.target,
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
1449 max_cube_map_levels_(ComputeMipMapCount(GL_TEXTURE_CUBE_MAP, 1435 max_cube_map_levels_(ComputeMipMapCount(GL_TEXTURE_CUBE_MAP,
1450 max_cube_map_texture_size, 1436 max_cube_map_texture_size,
1451 max_cube_map_texture_size, 1437 max_cube_map_texture_size,
1452 max_cube_map_texture_size)), 1438 max_cube_map_texture_size)),
1453 max_3d_levels_(ComputeMipMapCount(GL_TEXTURE_3D, 1439 max_3d_levels_(ComputeMipMapCount(GL_TEXTURE_3D,
1454 // Same as GL_TEXTURE_2D_ARRAY 1440 // Same as GL_TEXTURE_2D_ARRAY
1455 max_3d_texture_size, 1441 max_3d_texture_size,
1456 max_3d_texture_size, 1442 max_3d_texture_size,
1457 max_3d_texture_size)), 1443 max_3d_texture_size)),
1458 use_default_textures_(use_default_textures), 1444 use_default_textures_(use_default_textures),
1459 num_unrenderable_textures_(0),
1460 num_unsafe_textures_(0), 1445 num_unsafe_textures_(0),
1461 num_uncleared_mips_(0), 1446 num_uncleared_mips_(0),
1462 num_images_(0), 1447 num_images_(0),
1463 texture_count_(0), 1448 texture_count_(0),
1464 have_context_(true), 1449 have_context_(true),
1465 current_service_id_generation_(0) { 1450 current_service_id_generation_(0) {
1466 for (int ii = 0; ii < kNumDefaultTextures; ++ii) { 1451 for (int ii = 0; ii < kNumDefaultTextures; ++ii) {
1467 black_texture_ids_[ii] = 0; 1452 black_texture_ids_[ii] = 0;
1468 } 1453 }
1469 } 1454 }
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
1737 textures_.erase(it); 1722 textures_.erase(it);
1738 } 1723 }
1739 } 1724 }
1740 1725
1741 void TextureManager::StartTracking(TextureRef* ref) { 1726 void TextureManager::StartTracking(TextureRef* ref) {
1742 Texture* texture = ref->texture(); 1727 Texture* texture = ref->texture();
1743 ++texture_count_; 1728 ++texture_count_;
1744 num_uncleared_mips_ += texture->num_uncleared_mips(); 1729 num_uncleared_mips_ += texture->num_uncleared_mips();
1745 if (!texture->SafeToRenderFrom()) 1730 if (!texture->SafeToRenderFrom())
1746 ++num_unsafe_textures_; 1731 ++num_unsafe_textures_;
1747 if (!texture->CanRender(feature_info_.get()))
1748 ++num_unrenderable_textures_;
1749 if (texture->HasImages()) 1732 if (texture->HasImages())
1750 ++num_images_; 1733 ++num_images_;
1751 } 1734 }
1752 1735
1753 void TextureManager::StopTracking(TextureRef* ref) { 1736 void TextureManager::StopTracking(TextureRef* ref) {
1754 if (ref->num_observers()) { 1737 if (ref->num_observers()) {
1755 for (unsigned int i = 0; i < destruction_observers_.size(); i++) { 1738 for (unsigned int i = 0; i < destruction_observers_.size(); i++) {
1756 destruction_observers_[i]->OnTextureRefDestroying(ref); 1739 destruction_observers_[i]->OnTextureRefDestroying(ref);
1757 } 1740 }
1758 DCHECK_EQ(ref->num_observers(), 0); 1741 DCHECK_EQ(ref->num_observers(), 0);
1759 } 1742 }
1760 1743
1761 Texture* texture = ref->texture(); 1744 Texture* texture = ref->texture();
1762 1745
1763 --texture_count_; 1746 --texture_count_;
1764 if (texture->HasImages()) { 1747 if (texture->HasImages()) {
1765 DCHECK_NE(0, num_images_); 1748 DCHECK_NE(0, num_images_);
1766 --num_images_; 1749 --num_images_;
1767 } 1750 }
1768 if (!texture->CanRender(feature_info_.get())) {
1769 DCHECK_NE(0, num_unrenderable_textures_);
1770 --num_unrenderable_textures_;
1771 }
1772 if (!texture->SafeToRenderFrom()) { 1751 if (!texture->SafeToRenderFrom()) {
1773 DCHECK_NE(0, num_unsafe_textures_); 1752 DCHECK_NE(0, num_unsafe_textures_);
1774 --num_unsafe_textures_; 1753 --num_unsafe_textures_;
1775 } 1754 }
1776 num_uncleared_mips_ -= texture->num_uncleared_mips(); 1755 num_uncleared_mips_ -= texture->num_uncleared_mips();
1777 DCHECK_GE(num_uncleared_mips_, 0); 1756 DCHECK_GE(num_uncleared_mips_, 0);
1778 } 1757 }
1779 1758
1780 MemoryTypeTracker* TextureManager::GetMemTracker() { 1759 MemoryTypeTracker* TextureManager::GetMemTracker() {
1781 return memory_type_tracker_.get(); 1760 return memory_type_tracker_.get();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1829 void TextureManager::UpdateSafeToRenderFrom(int delta) { 1808 void TextureManager::UpdateSafeToRenderFrom(int delta) {
1830 num_unsafe_textures_ += delta; 1809 num_unsafe_textures_ += delta;
1831 DCHECK_GE(num_unsafe_textures_, 0); 1810 DCHECK_GE(num_unsafe_textures_, 0);
1832 } 1811 }
1833 1812
1834 void TextureManager::UpdateUnclearedMips(int delta) { 1813 void TextureManager::UpdateUnclearedMips(int delta) {
1835 num_uncleared_mips_ += delta; 1814 num_uncleared_mips_ += delta;
1836 DCHECK_GE(num_uncleared_mips_, 0); 1815 DCHECK_GE(num_uncleared_mips_, 0);
1837 } 1816 }
1838 1817
1839 void TextureManager::UpdateCanRenderCondition(
1840 Texture::CanRenderCondition old_condition,
1841 Texture::CanRenderCondition new_condition) {
1842 if (old_condition == Texture::CAN_RENDER_NEVER ||
1843 (old_condition == Texture::CAN_RENDER_ONLY_IF_NPOT &&
1844 !feature_info_->feature_flags().npot_ok)) {
1845 DCHECK_GT(num_unrenderable_textures_, 0);
1846 --num_unrenderable_textures_;
1847 }
1848 if (new_condition == Texture::CAN_RENDER_NEVER ||
1849 (new_condition == Texture::CAN_RENDER_ONLY_IF_NPOT &&
1850 !feature_info_->feature_flags().npot_ok))
1851 ++num_unrenderable_textures_;
1852 }
1853
1854 void TextureManager::UpdateNumImages(int delta) { 1818 void TextureManager::UpdateNumImages(int delta) {
1855 num_images_ += delta; 1819 num_images_ += delta;
1856 DCHECK_GE(num_images_, 0); 1820 DCHECK_GE(num_images_, 0);
1857 } 1821 }
1858 1822
1859 void TextureManager::IncFramebufferStateChangeCount() { 1823 void TextureManager::IncFramebufferStateChangeCount() {
1860 if (framebuffer_manager_) 1824 if (framebuffer_manager_)
1861 framebuffer_manager_->IncFramebufferStateChangeCount(); 1825 framebuffer_manager_->IncFramebufferStateChangeCount();
1862 } 1826 }
1863 1827
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after
2673 uint32_t TextureManager::GetServiceIdGeneration() const { 2637 uint32_t TextureManager::GetServiceIdGeneration() const {
2674 return current_service_id_generation_; 2638 return current_service_id_generation_;
2675 } 2639 }
2676 2640
2677 void TextureManager::IncrementServiceIdGeneration() { 2641 void TextureManager::IncrementServiceIdGeneration() {
2678 current_service_id_generation_++; 2642 current_service_id_generation_++;
2679 } 2643 }
2680 2644
2681 } // namespace gles2 2645 } // namespace gles2
2682 } // namespace gpu 2646 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/texture_manager.h ('k') | gpu/command_buffer/service/texture_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698