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

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

Issue 11516014: Track managed memory usage in the command buffer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unit test compile error Created 8 years 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 | Annotate | Revision Log
« no previous file with comments | « gpu/command_buffer/service/texture_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/stringprintf.h" 7 #include "base/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/feature_info.h" 9 #include "gpu/command_buffer/service/feature_info.h"
10 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" 10 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 have_context_ = have_context; 75 have_context_ = have_context;
76 texture_infos_.clear(); 76 texture_infos_.clear();
77 for (int ii = 0; ii < kNumDefaultTextures; ++ii) { 77 for (int ii = 0; ii < kNumDefaultTextures; ++ii) {
78 default_textures_[ii] = NULL; 78 default_textures_[ii] = NULL;
79 } 79 }
80 80
81 if (have_context) { 81 if (have_context) {
82 glDeleteTextures(arraysize(black_texture_ids_), black_texture_ids_); 82 glDeleteTextures(arraysize(black_texture_ids_), black_texture_ids_);
83 } 83 }
84 84
85 DCHECK_EQ(0u, mem_represented_); 85 DCHECK_EQ(0u, memory_tracker_managed_->GetMemRepresented());
86 UpdateMemRepresented(); 86 DCHECK_EQ(0u, memory_tracker_unmanaged_->GetMemRepresented());
87 memory_tracker_managed_->UpdateMemRepresented();
88 memory_tracker_unmanaged_->UpdateMemRepresented();
87 } 89 }
88 90
89 TextureManager::TextureInfo::TextureInfo(TextureManager* manager, 91 TextureManager::TextureInfo::TextureInfo(TextureManager* manager,
90 GLuint service_id) 92 GLuint service_id)
91 : manager_(manager), 93 : manager_(manager),
92 service_id_(service_id), 94 service_id_(service_id),
93 deleted_(false), 95 deleted_(false),
94 cleared_(true), 96 cleared_(true),
95 num_uncleared_mips_(0), 97 num_uncleared_mips_(0),
96 target_(0), 98 target_(0),
97 min_filter_(GL_NEAREST_MIPMAP_LINEAR), 99 min_filter_(GL_NEAREST_MIPMAP_LINEAR),
98 mag_filter_(GL_LINEAR), 100 mag_filter_(GL_LINEAR),
99 wrap_s_(GL_REPEAT), 101 wrap_s_(GL_REPEAT),
100 wrap_t_(GL_REPEAT), 102 wrap_t_(GL_REPEAT),
101 usage_(GL_NONE), 103 usage_(GL_NONE),
104 tracking_pool_(MemoryTracker::kUnmanaged),
102 max_level_set_(-1), 105 max_level_set_(-1),
103 texture_complete_(false), 106 texture_complete_(false),
104 cube_complete_(false), 107 cube_complete_(false),
105 npot_(false), 108 npot_(false),
106 has_been_bound_(false), 109 has_been_bound_(false),
107 framebuffer_attachment_count_(0), 110 framebuffer_attachment_count_(0),
108 owned_(true), 111 owned_(true),
109 stream_texture_(false), 112 stream_texture_(false),
110 immutable_(false), 113 immutable_(false),
111 estimated_size_(0) { 114 estimated_size_(0) {
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 } 688 }
686 } 689 }
687 return 0; 690 return 0;
688 } 691 }
689 692
690 TextureManager::TextureManager( 693 TextureManager::TextureManager(
691 MemoryTracker* memory_tracker, 694 MemoryTracker* memory_tracker,
692 FeatureInfo* feature_info, 695 FeatureInfo* feature_info,
693 GLint max_texture_size, 696 GLint max_texture_size,
694 GLint max_cube_map_texture_size) 697 GLint max_cube_map_texture_size)
695 : texture_memory_tracker_(new MemoryTypeTracker(memory_tracker)), 698 : memory_tracker_managed_(
699 new MemoryTypeTracker(memory_tracker, MemoryTracker::kManaged)),
700 memory_tracker_unmanaged_(
701 new MemoryTypeTracker(memory_tracker, MemoryTracker::kUnmanaged)),
696 feature_info_(feature_info), 702 feature_info_(feature_info),
697 max_texture_size_(max_texture_size), 703 max_texture_size_(max_texture_size),
698 max_cube_map_texture_size_(max_cube_map_texture_size), 704 max_cube_map_texture_size_(max_cube_map_texture_size),
699 max_levels_(ComputeMipMapCount(max_texture_size, 705 max_levels_(ComputeMipMapCount(max_texture_size,
700 max_texture_size, 706 max_texture_size,
701 max_texture_size)), 707 max_texture_size)),
702 max_cube_map_levels_(ComputeMipMapCount(max_cube_map_texture_size, 708 max_cube_map_levels_(ComputeMipMapCount(max_cube_map_texture_size,
703 max_cube_map_texture_size, 709 max_cube_map_texture_size,
704 max_cube_map_texture_size)), 710 max_cube_map_texture_size)),
705 num_unrenderable_textures_(0), 711 num_unrenderable_textures_(0),
706 num_unsafe_textures_(0), 712 num_unsafe_textures_(0),
707 num_uncleared_mips_(0), 713 num_uncleared_mips_(0),
708 texture_info_count_(0), 714 texture_info_count_(0),
709 mem_represented_(0),
710 have_context_(true) { 715 have_context_(true) {
711 for (int ii = 0; ii < kNumDefaultTextures; ++ii) { 716 for (int ii = 0; ii < kNumDefaultTextures; ++ii) {
712 black_texture_ids_[ii] = 0; 717 black_texture_ids_[ii] = 0;
713 } 718 }
714 } 719 }
715 720
716 void TextureManager::UpdateMemRepresented() {
717 texture_memory_tracker_->UpdateMemRepresented(mem_represented_);
718 }
719
720 bool TextureManager::Initialize() { 721 bool TextureManager::Initialize() {
721 UpdateMemRepresented(); 722 memory_tracker_managed_->UpdateMemRepresented();
723 memory_tracker_unmanaged_->UpdateMemRepresented();
722 724
723 // TODO(gman): The default textures have to be real textures, not the 0 725 // TODO(gman): The default textures have to be real textures, not the 0
724 // texture because we simulate non shared resources on top of shared 726 // texture because we simulate non shared resources on top of shared
725 // resources and all contexts that share resource share the same default 727 // resources and all contexts that share resource share the same default
726 // texture. 728 // texture.
727 default_textures_[kTexture2D] = CreateDefaultAndBlackTextures( 729 default_textures_[kTexture2D] = CreateDefaultAndBlackTextures(
728 GL_TEXTURE_2D, &black_texture_ids_[kTexture2D]); 730 GL_TEXTURE_2D, &black_texture_ids_[kTexture2D]);
729 default_textures_[kCubeMap] = CreateDefaultAndBlackTextures( 731 default_textures_[kCubeMap] = CreateDefaultAndBlackTextures(
730 GL_TEXTURE_CUBE_MAP, &black_texture_ids_[kCubeMap]); 732 GL_TEXTURE_CUBE_MAP, &black_texture_ids_[kCubeMap]);
731 733
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 if (!info->CanRender(feature_info_)) { 907 if (!info->CanRender(feature_info_)) {
906 DCHECK_NE(0, num_unrenderable_textures_); 908 DCHECK_NE(0, num_unrenderable_textures_);
907 --num_unrenderable_textures_; 909 --num_unrenderable_textures_;
908 } 910 }
909 if (!info->SafeToRenderFrom()) { 911 if (!info->SafeToRenderFrom()) {
910 DCHECK_NE(0, num_unsafe_textures_); 912 DCHECK_NE(0, num_unsafe_textures_);
911 --num_unsafe_textures_; 913 --num_unsafe_textures_;
912 } 914 }
913 num_uncleared_mips_ -= info->num_uncleared_mips(); 915 num_uncleared_mips_ -= info->num_uncleared_mips();
914 DCHECK_GE(num_uncleared_mips_, 0); 916 DCHECK_GE(num_uncleared_mips_, 0);
915 mem_represented_ -= info->estimated_size(); 917
918 GetMemTracker(info->tracking_pool_)->TrackMemFree(info->estimated_size());
916 info->SetLevelInfo( 919 info->SetLevelInfo(
917 feature_info_, target, level, internal_format, width, height, depth, 920 feature_info_, target, level, internal_format, width, height, depth,
918 border, format, type, cleared); 921 border, format, type, cleared);
919 mem_represented_ += info->estimated_size(); 922 GetMemTracker(info->tracking_pool_)->TrackMemAlloc(info->estimated_size());
920 UpdateMemRepresented(); 923 GetMemTracker(info->tracking_pool_)->UpdateMemRepresented();
921 924
922 num_uncleared_mips_ += info->num_uncleared_mips(); 925 num_uncleared_mips_ += info->num_uncleared_mips();
923 if (!info->CanRender(feature_info_)) { 926 if (!info->CanRender(feature_info_)) {
924 ++num_unrenderable_textures_; 927 ++num_unrenderable_textures_;
925 } 928 }
926 if (!info->SafeToRenderFrom()) { 929 if (!info->SafeToRenderFrom()) {
927 ++num_unsafe_textures_; 930 ++num_unsafe_textures_;
928 } 931 }
929 } 932 }
930 933
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1062 if (!info->CanRender(feature_info_)) { 1065 if (!info->CanRender(feature_info_)) {
1063 DCHECK_NE(0, num_unrenderable_textures_); 1066 DCHECK_NE(0, num_unrenderable_textures_);
1064 --num_unrenderable_textures_; 1067 --num_unrenderable_textures_;
1065 } 1068 }
1066 if (!info->SafeToRenderFrom()) { 1069 if (!info->SafeToRenderFrom()) {
1067 DCHECK_NE(0, num_unsafe_textures_); 1070 DCHECK_NE(0, num_unsafe_textures_);
1068 --num_unsafe_textures_; 1071 --num_unsafe_textures_;
1069 } 1072 }
1070 num_uncleared_mips_ -= info->num_uncleared_mips(); 1073 num_uncleared_mips_ -= info->num_uncleared_mips();
1071 DCHECK_GE(num_uncleared_mips_, 0); 1074 DCHECK_GE(num_uncleared_mips_, 0);
1072 mem_represented_ -= info->estimated_size(); 1075 GetMemTracker(info->tracking_pool_)->TrackMemFree(info->estimated_size());
1073 bool result = info->MarkMipmapsGenerated(feature_info_); 1076 bool result = info->MarkMipmapsGenerated(feature_info_);
1074 mem_represented_ += info->estimated_size(); 1077 GetMemTracker(info->tracking_pool_)->TrackMemAlloc(info->estimated_size());
1075 UpdateMemRepresented(); 1078 GetMemTracker(info->tracking_pool_)->UpdateMemRepresented();
1076 1079
1077 num_uncleared_mips_ += info->num_uncleared_mips(); 1080 num_uncleared_mips_ += info->num_uncleared_mips();
1078 if (!info->CanRender(feature_info_)) { 1081 if (!info->CanRender(feature_info_)) {
1079 ++num_unrenderable_textures_; 1082 ++num_unrenderable_textures_;
1080 } 1083 }
1081 if (!info->SafeToRenderFrom()) { 1084 if (!info->SafeToRenderFrom()) {
1082 ++num_unsafe_textures_; 1085 ++num_unsafe_textures_;
1083 } 1086 }
1084 return result; 1087 return result;
1085 } 1088 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1125 if (!texture->CanRender(feature_info_)) { 1128 if (!texture->CanRender(feature_info_)) {
1126 DCHECK_NE(0, num_unrenderable_textures_); 1129 DCHECK_NE(0, num_unrenderable_textures_);
1127 --num_unrenderable_textures_; 1130 --num_unrenderable_textures_;
1128 } 1131 }
1129 if (!texture->SafeToRenderFrom()) { 1132 if (!texture->SafeToRenderFrom()) {
1130 DCHECK_NE(0, num_unsafe_textures_); 1133 DCHECK_NE(0, num_unsafe_textures_);
1131 --num_unsafe_textures_; 1134 --num_unsafe_textures_;
1132 } 1135 }
1133 num_uncleared_mips_ -= texture->num_uncleared_mips(); 1136 num_uncleared_mips_ -= texture->num_uncleared_mips();
1134 DCHECK_GE(num_uncleared_mips_, 0); 1137 DCHECK_GE(num_uncleared_mips_, 0);
1135 mem_represented_ -= texture->estimated_size(); 1138 GetMemTracker(texture->tracking_pool_)->TrackMemFree(
1136 UpdateMemRepresented(); 1139 texture->estimated_size());
1140 GetMemTracker(texture->tracking_pool_)->UpdateMemRepresented();
1141 }
1142
1143 MemoryTypeTracker* TextureManager::GetMemTracker(
1144 MemoryTracker::Pool tracking_pool) {
1145 switch(tracking_pool) {
1146 case MemoryTracker::kManaged:
1147 return memory_tracker_managed_.get();
1148 break;
1149 case MemoryTracker::kUnmanaged:
1150 return memory_tracker_unmanaged_.get();
1151 break;
1152 default:
1153 break;
1154 }
1155 NOTREACHED();
1156 return NULL;
1137 } 1157 }
1138 1158
1139 bool TextureManager::GetClientId(GLuint service_id, GLuint* client_id) const { 1159 bool TextureManager::GetClientId(GLuint service_id, GLuint* client_id) const {
1140 // This doesn't need to be fast. It's only used during slow queries. 1160 // This doesn't need to be fast. It's only used during slow queries.
1141 for (TextureInfoMap::const_iterator it = texture_infos_.begin(); 1161 for (TextureInfoMap::const_iterator it = texture_infos_.begin();
1142 it != texture_infos_.end(); ++it) { 1162 it != texture_infos_.end(); ++it) {
1143 if (it->second->service_id() == service_id) { 1163 if (it->second->service_id() == service_id) {
1144 *client_id = it->first; 1164 *client_id = it->first;
1145 return true; 1165 return true;
1146 } 1166 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 void TextureManager::AddToSignature( 1199 void TextureManager::AddToSignature(
1180 TextureInfo* info, 1200 TextureInfo* info,
1181 GLenum target, 1201 GLenum target,
1182 GLint level, 1202 GLint level,
1183 std::string* signature) const { 1203 std::string* signature) const {
1184 info->AddToSignature(feature_info_.get(), target, level, signature); 1204 info->AddToSignature(feature_info_.get(), target, level, signature);
1185 } 1205 }
1186 1206
1187 } // namespace gles2 1207 } // namespace gles2
1188 } // namespace gpu 1208 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/texture_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698