diff options
author | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-22 14:18:55 +0000 |
---|---|---|
committer | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-22 14:18:55 +0000 |
commit | 5068a9fab7bea41cae8ecd8e4fa29676f860a166 (patch) | |
tree | 892b64aade6d8d2428cf02f4473c3f44cc0a7be3 /gpu | |
parent | b30f59db92f16e34e77bc0cecac6ca0aaf071439 (diff) | |
download | chromium_src-5068a9fab7bea41cae8ecd8e4fa29676f860a166.zip chromium_src-5068a9fab7bea41cae8ecd8e4fa29676f860a166.tar.gz chromium_src-5068a9fab7bea41cae8ecd8e4fa29676f860a166.tar.bz2 |
Start adding memory tracking to GPU process
This one only tracks texture memory and does not include
the backbuffer.
BUG=none
TEST=ran with about:tracing
Review URL: http://codereview.chromium.org/8949027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@115532 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu')
-rw-r--r-- | gpu/command_buffer/service/texture_manager.cc | 39 | ||||
-rw-r--r-- | gpu/command_buffer/service/texture_manager.h | 18 |
2 files changed, 50 insertions, 7 deletions
diff --git a/gpu/command_buffer/service/texture_manager.cc b/gpu/command_buffer/service/texture_manager.cc index ef0335b..b9789b9 100644 --- a/gpu/command_buffer/service/texture_manager.cc +++ b/gpu/command_buffer/service/texture_manager.cc @@ -4,6 +4,7 @@ #include "gpu/command_buffer/service/texture_manager.h" #include "base/bits.h" +#include "base/debug/trace_event.h" #include "gpu/command_buffer/common/gles2_cmd_utils.h" #include "gpu/command_buffer/service/feature_info.h" #include "gpu/command_buffer/service/gles2_cmd_decoder.h" @@ -247,6 +248,12 @@ void TextureManager::TextureInfo::SetLevelInfo( info.border = border; info.format = format; info.type = type; + + estimated_size_ -= info.estimated_size; + GLES2Util::ComputeImageDataSize( + width, height, format, type, 4, &info.estimated_size); + estimated_size_ += info.estimated_size; + if (!info.cleared) { DCHECK_NE(0, num_uncleared_mips_); --num_uncleared_mips_; @@ -544,13 +551,25 @@ TextureManager::TextureManager( num_unrenderable_textures_(0), num_unsafe_textures_(0), num_uncleared_mips_(0), + mem_represented_(0), + last_reported_mem_represented_(1), black_2d_texture_id_(0), black_cube_texture_id_(0), black_oes_external_texture_id_(0), black_arb_texture_rectangle_id_(0) { } +void TextureManager::UpdateMemRepresented() { + if (mem_represented_ != last_reported_mem_represented_) { + last_reported_mem_represented_ = mem_represented_; + TRACE_COUNTER_ID1( + "TextureManager", "TextureMemory", this, mem_represented_); + } +} + bool TextureManager::Initialize(const FeatureInfo* feature_info) { + UpdateMemRepresented(); + // TODO(gman): The default textures have to be real textures, not the 0 // texture because we simulate non shared resources on top of shared // resources and all contexts that share resource share the same default @@ -620,16 +639,13 @@ TextureManager::TextureInfo::Ref TextureManager::CreateDefaultAndBlackTextures( 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, true); } } else { - // TODO(kbr): previous code called SetLevelInfo directly on the - // TextureInfo object for the GL_TEXTURE_EXTERNAL_OES case. - // Unclear whether this was deliberate. if (needs_initialization) { SetLevelInfo(&temp_feature_info, default_texture, GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, true); } else { - default_texture->SetLevelInfo( - &temp_feature_info, GL_TEXTURE_EXTERNAL_OES, 0, + SetLevelInfo( + &temp_feature_info, default_texture, GL_TEXTURE_EXTERNAL_OES, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, true); } } @@ -753,9 +769,13 @@ void TextureManager::SetLevelInfo( } num_uncleared_mips_ -= info->num_uncleared_mips(); DCHECK_GE(num_uncleared_mips_, 0); + mem_represented_ -= info->estimated_size(); info->SetLevelInfo( feature_info, target, level, internal_format, width, height, depth, border, format, type, cleared); + mem_represented_ += info->estimated_size(); + UpdateMemRepresented(); + num_uncleared_mips_ += info->num_uncleared_mips(); if (!info->CanRender(feature_info)) { ++num_unrenderable_textures_; @@ -802,7 +822,11 @@ bool TextureManager::MarkMipmapsGenerated( } num_uncleared_mips_ -= info->num_uncleared_mips(); DCHECK_GE(num_uncleared_mips_, 0); + mem_represented_ -= info->estimated_size(); bool result = info->MarkMipmapsGenerated(feature_info); + mem_represented_ += info->estimated_size(); + UpdateMemRepresented(); + num_uncleared_mips_ += info->num_uncleared_mips(); if (!info->CanRender(feature_info)) { ++num_unrenderable_textures_; @@ -852,6 +876,11 @@ void TextureManager::RemoveTextureInfo( num_uncleared_mips_ -= info->num_uncleared_mips(); DCHECK_GE(num_uncleared_mips_, 0); info->MarkAsDeleted(); + // TODO(gman): Unforunately the memory does not get de-allocated here as + // resources are ref counted but for now there's no easy way to track this + // info past this point. + mem_represented_ += info->estimated_size(); + UpdateMemRepresented(); texture_infos_.erase(it); } } diff --git a/gpu/command_buffer/service/texture_manager.h b/gpu/command_buffer/service/texture_manager.h index 0217ed9..6226f92 100644 --- a/gpu/command_buffer/service/texture_manager.h +++ b/gpu/command_buffer/service/texture_manager.h @@ -76,6 +76,10 @@ class TextureManager { return num_uncleared_mips_; } + uint32 estimated_size() const { + return estimated_size_; + } + // True if this texture meets all the GLES2 criteria for rendering. // See section 3.8.2 of the GLES2 spec. bool CanRender(const FeatureInfo* feature_info) const; @@ -204,7 +208,8 @@ class TextureManager { depth(0), border(0), format(0), - type(0) { + type(0), + estimated_size(0) { } bool cleared; @@ -217,6 +222,7 @@ class TextureManager { GLint border; GLenum format; GLenum type; + uint32 estimated_size; }; // Set the info for a particular level. @@ -254,7 +260,7 @@ class TextureManager { const FeatureInfo* feature_info, GLenum pname, GLint param); // Makes each of the mip levels as though they were generated. - bool MarkMipmapsGenerated(const FeatureInfo* feature_info); + bool MarkMipmapsGenerated( const FeatureInfo* feature_info); void MarkAsDeleted() { service_id_ = 0; @@ -328,6 +334,9 @@ class TextureManager { // or dimensions of the texture object can be made. bool immutable_; + // Size in bytes this texture is assumed to take in memory. + uint32 estimated_size_; + DISALLOW_COPY_AND_ASSIGN(TextureInfo); }; @@ -483,6 +492,8 @@ class TextureManager { GLenum target, GLuint* black_texture); + void UpdateMemRepresented(); + // Info for each texture in the system. typedef base::hash_map<GLuint, TextureInfo::Ref> TextureInfoMap; TextureInfoMap texture_infos_; @@ -496,6 +507,9 @@ class TextureManager { int num_unsafe_textures_; int num_uncleared_mips_; + uint32 mem_represented_; + uint32 last_reported_mem_represented_; + // Black (0,0,0,1) textures for when non-renderable textures are used. // NOTE: There is no corresponding TextureInfo for these textures. // TextureInfos are only for textures the client side can access. |