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

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

Issue 10915293: Simplify tracing of gpu memory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nitfix Created 8 years, 3 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 | Annotate | Revision Log
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 <stdio.h> 7 #include <stdio.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <list> 10 #include <list>
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 #include "ui/gl/gl_implementation.h" 55 #include "ui/gl/gl_implementation.h"
56 #include "ui/gl/gl_surface.h" 56 #include "ui/gl/gl_surface.h"
57 #if defined(OS_MACOSX) 57 #if defined(OS_MACOSX)
58 #include "ui/surface/io_surface_support_mac.h" 58 #include "ui/surface/io_surface_support_mac.h"
59 #endif 59 #endif
60 60
61 #if !defined(GL_DEPTH24_STENCIL8) 61 #if !defined(GL_DEPTH24_STENCIL8)
62 #define GL_DEPTH24_STENCIL8 0x88F0 62 #define GL_DEPTH24_STENCIL8 0x88F0
63 #endif 63 #endif
64 64
65 #define TRACE_BACKBUFFER_MEMORY_TOTAL(decoder) \
66 TRACE_COUNTER_ID1( \
67 "GLES2DecoderImpl", "BackbufferMemory", decoder, \
68 decoder->GetBackbufferMemoryTotal())
69
70 namespace gpu { 65 namespace gpu {
71 namespace gles2 { 66 namespace gles2 {
72 67
73 namespace { 68 namespace {
74 static const char kOESDerivativeExtension[] = "GL_OES_standard_derivatives"; 69 static const char kOESDerivativeExtension[] = "GL_OES_standard_derivatives";
75 } 70 }
76 71
77 class GLES2DecoderImpl; 72 class GLES2DecoderImpl;
78 73
79 // Check that certain assumptions the code makes are true. There are places in 74 // Check that certain assumptions the code makes are true. There are places in
(...skipping 1648 matching lines...) Expand 10 before | Expand all | Expand 10 after
1728 } 1723 }
1729 1724
1730 ScopedTextureUploadTimer::~ScopedTextureUploadTimer() { 1725 ScopedTextureUploadTimer::~ScopedTextureUploadTimer() {
1731 decoder_->texture_upload_count_++; 1726 decoder_->texture_upload_count_++;
1732 decoder_->total_texture_upload_time_ += 1727 decoder_->total_texture_upload_time_ +=
1733 base::TimeTicks::HighResNow() - begin_time_; 1728 base::TimeTicks::HighResNow() - begin_time_;
1734 } 1729 }
1735 1730
1736 Texture::Texture(GLES2DecoderImpl* decoder) 1731 Texture::Texture(GLES2DecoderImpl* decoder)
1737 : decoder_(decoder), 1732 : decoder_(decoder),
1738 memory_tracker_(decoder->GetContextGroup()->memory_tracker(), 1733 memory_tracker_(decoder->GetContextGroup()->memory_tracker()),
1739 NULL, NULL),
1740 id_(0) { 1734 id_(0) {
1741 } 1735 }
1742 1736
1743 Texture::~Texture() { 1737 Texture::~Texture() {
1744 // This does not destroy the render texture because that would require that 1738 // This does not destroy the render texture because that would require that
1745 // the associated GL context was current. Just check that it was explicitly 1739 // the associated GL context was current. Just check that it was explicitly
1746 // destroyed. 1740 // destroyed.
1747 DCHECK_EQ(id_, 0u); 1741 DCHECK_EQ(id_, 0u);
1748 } 1742 }
1749 1743
1750 void Texture::Create() { 1744 void Texture::Create() {
1751 ScopedGLErrorSuppressor suppressor(decoder_); 1745 ScopedGLErrorSuppressor suppressor(decoder_);
1752 Destroy(); 1746 Destroy();
1753 glGenTextures(1, &id_); 1747 glGenTextures(1, &id_);
1754 ScopedTexture2DBinder binder(decoder_, id_); 1748 ScopedTexture2DBinder binder(decoder_, id_);
1755 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 1749 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1756 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 1750 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1757 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 1751 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1758 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 1752 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1759 1753
1760 // TODO(apatrick): Attempt to diagnose crbug.com/97775. If SwapBuffers is 1754 // TODO(apatrick): Attempt to diagnose crbug.com/97775. If SwapBuffers is
1761 // never called on an offscreen context, no data will ever be uploaded to the 1755 // never called on an offscreen context, no data will ever be uploaded to the
1762 // saved offscreen color texture (it is deferred until to when SwapBuffers 1756 // saved offscreen color texture (it is deferred until to when SwapBuffers
1763 // is called). My idea is that some nvidia drivers might have a bug where 1757 // is called). My idea is that some nvidia drivers might have a bug where
1764 // deleting a texture that has never been populated might cause a 1758 // deleting a texture that has never been populated might cause a
1765 // crash. 1759 // crash.
1766 glTexImage2D( 1760 glTexImage2D(
1767 GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); 1761 GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
1768 memory_tracker_.UpdateMemRepresented(16u * 16u * 4u); 1762 memory_tracker_.UpdateMemRepresented(16u * 16u * 4u);
1769 TRACE_BACKBUFFER_MEMORY_TOTAL(decoder_);
1770 } 1763 }
1771 1764
1772 bool Texture::AllocateStorage(const gfx::Size& size, GLenum format) { 1765 bool Texture::AllocateStorage(const gfx::Size& size, GLenum format) {
1773 DCHECK_NE(id_, 0u); 1766 DCHECK_NE(id_, 0u);
1774 ScopedGLErrorSuppressor suppressor(decoder_); 1767 ScopedGLErrorSuppressor suppressor(decoder_);
1775 ScopedTexture2DBinder binder(decoder_, id_); 1768 ScopedTexture2DBinder binder(decoder_, id_);
1776 1769
1777 WrappedTexImage2D(GL_TEXTURE_2D, 1770 WrappedTexImage2D(GL_TEXTURE_2D,
1778 0, // mip level 1771 0, // mip level
1779 format, 1772 format,
1780 size.width(), 1773 size.width(),
1781 size.height(), 1774 size.height(),
1782 0, // border 1775 0, // border
1783 format, 1776 format,
1784 GL_UNSIGNED_BYTE, 1777 GL_UNSIGNED_BYTE,
1785 NULL); 1778 NULL);
1786 1779
1787 size_ = size; 1780 size_ = size;
1788 1781
1789 bool success = glGetError() == GL_NO_ERROR; 1782 bool success = glGetError() == GL_NO_ERROR;
1790 if (success) { 1783 if (success) {
1791 uint32 image_size = 0; 1784 uint32 image_size = 0;
1792 GLES2Util::ComputeImageDataSizes( 1785 GLES2Util::ComputeImageDataSizes(
1793 size.width(), size.height(), format, GL_UNSIGNED_BYTE, 4, &image_size, 1786 size.width(), size.height(), format, GL_UNSIGNED_BYTE, 4, &image_size,
1794 NULL, NULL); 1787 NULL, NULL);
1795 memory_tracker_.UpdateMemRepresented(image_size); 1788 memory_tracker_.UpdateMemRepresented(image_size);
1796 TRACE_BACKBUFFER_MEMORY_TOTAL(decoder_);
1797 } 1789 }
1798 return success; 1790 return success;
1799 } 1791 }
1800 1792
1801 void Texture::Copy(const gfx::Size& size, GLenum format) { 1793 void Texture::Copy(const gfx::Size& size, GLenum format) {
1802 DCHECK_NE(id_, 0u); 1794 DCHECK_NE(id_, 0u);
1803 ScopedGLErrorSuppressor suppressor(decoder_); 1795 ScopedGLErrorSuppressor suppressor(decoder_);
1804 ScopedTexture2DBinder binder(decoder_, id_); 1796 ScopedTexture2DBinder binder(decoder_, id_);
1805 glCopyTexImage2D(GL_TEXTURE_2D, 1797 glCopyTexImage2D(GL_TEXTURE_2D,
1806 0, // level 1798 0, // level
1807 format, 1799 format,
1808 0, 0, 1800 0, 0,
1809 size.width(), 1801 size.width(),
1810 size.height(), 1802 size.height(),
1811 0); // border 1803 0); // border
1812 } 1804 }
1813 1805
1814 void Texture::Destroy() { 1806 void Texture::Destroy() {
1815 if (id_ != 0) { 1807 if (id_ != 0) {
1816 ScopedGLErrorSuppressor suppressor(decoder_); 1808 ScopedGLErrorSuppressor suppressor(decoder_);
1817 glDeleteTextures(1, &id_); 1809 glDeleteTextures(1, &id_);
1818 id_ = 0; 1810 id_ = 0;
1819 memory_tracker_.UpdateMemRepresented(0); 1811 memory_tracker_.UpdateMemRepresented(0);
1820 TRACE_BACKBUFFER_MEMORY_TOTAL(decoder_);
1821 } 1812 }
1822 } 1813 }
1823 1814
1824 void Texture::Invalidate() { 1815 void Texture::Invalidate() {
1825 id_ = 0; 1816 id_ = 0;
1826 } 1817 }
1827 1818
1828 RenderBuffer::RenderBuffer(GLES2DecoderImpl* decoder) 1819 RenderBuffer::RenderBuffer(GLES2DecoderImpl* decoder)
1829 : decoder_(decoder), 1820 : decoder_(decoder),
1830 memory_tracker_(decoder->GetContextGroup()->memory_tracker(), 1821 memory_tracker_(decoder->GetContextGroup()->memory_tracker()),
1831 NULL, NULL),
1832 id_(0) { 1822 id_(0) {
1833 } 1823 }
1834 1824
1835 RenderBuffer::~RenderBuffer() { 1825 RenderBuffer::~RenderBuffer() {
1836 // This does not destroy the render buffer because that would require that 1826 // This does not destroy the render buffer because that would require that
1837 // the associated GL context was current. Just check that it was explicitly 1827 // the associated GL context was current. Just check that it was explicitly
1838 // destroyed. 1828 // destroyed.
1839 DCHECK_EQ(id_, 0u); 1829 DCHECK_EQ(id_, 0u);
1840 } 1830 }
1841 1831
(...skipping 25 matching lines...) Expand all
1867 format, 1857 format,
1868 size.width(), 1858 size.width(),
1869 size.height()); 1859 size.height());
1870 } 1860 }
1871 } 1861 }
1872 bool success = glGetError() == GL_NO_ERROR; 1862 bool success = glGetError() == GL_NO_ERROR;
1873 if (success) { 1863 if (success) {
1874 memory_tracker_.UpdateMemRepresented( 1864 memory_tracker_.UpdateMemRepresented(
1875 size.width() * size.height() * samples * 1865 size.width() * size.height() * samples *
1876 GLES2Util::RenderbufferBytesPerPixel(format)); 1866 GLES2Util::RenderbufferBytesPerPixel(format));
1877 TRACE_BACKBUFFER_MEMORY_TOTAL(decoder_);
1878 } 1867 }
1879 return success; 1868 return success;
1880 } 1869 }
1881 1870
1882 void RenderBuffer::Destroy() { 1871 void RenderBuffer::Destroy() {
1883 if (id_ != 0) { 1872 if (id_ != 0) {
1884 ScopedGLErrorSuppressor suppressor(decoder_); 1873 ScopedGLErrorSuppressor suppressor(decoder_);
1885 glDeleteRenderbuffersEXT(1, &id_); 1874 glDeleteRenderbuffersEXT(1, &id_);
1886 id_ = 0; 1875 id_ = 0;
1887 memory_tracker_.UpdateMemRepresented(0); 1876 memory_tracker_.UpdateMemRepresented(0);
1888 TRACE_BACKBUFFER_MEMORY_TOTAL(decoder_);
1889 } 1877 }
1890 } 1878 }
1891 1879
1892 void RenderBuffer::Invalidate() { 1880 void RenderBuffer::Invalidate() {
1893 id_ = 0; 1881 id_ = 0;
1894 } 1882 }
1895 1883
1896 FrameBuffer::FrameBuffer(GLES2DecoderImpl* decoder) 1884 FrameBuffer::FrameBuffer(GLES2DecoderImpl* decoder)
1897 : decoder_(decoder), 1885 : decoder_(decoder),
1898 id_(0) { 1886 id_(0) {
(...skipping 1241 matching lines...) Expand 10 before | Expand all | Expand 10 after
3140 return false; 3128 return false;
3141 } 3129 }
3142 if (offscreen_target_stencil_format_ && 3130 if (offscreen_target_stencil_format_ &&
3143 !offscreen_target_stencil_render_buffer_->AllocateStorage( 3131 !offscreen_target_stencil_render_buffer_->AllocateStorage(
3144 offscreen_size_, offscreen_target_stencil_format_, 3132 offscreen_size_, offscreen_target_stencil_format_,
3145 offscreen_target_samples_)) { 3133 offscreen_target_samples_)) {
3146 LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " 3134 LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed "
3147 << "to allocate storage for offscreen target stencil buffer."; 3135 << "to allocate storage for offscreen target stencil buffer.";
3148 return false; 3136 return false;
3149 } 3137 }
3150 TRACE_BACKBUFFER_MEMORY_TOTAL(this);
3151 3138
3152 // Attach the offscreen target buffers to the target frame buffer. 3139 // Attach the offscreen target buffers to the target frame buffer.
3153 if (IsOffscreenBufferMultisampled()) { 3140 if (IsOffscreenBufferMultisampled()) {
3154 offscreen_target_frame_buffer_->AttachRenderBuffer( 3141 offscreen_target_frame_buffer_->AttachRenderBuffer(
3155 GL_COLOR_ATTACHMENT0, 3142 GL_COLOR_ATTACHMENT0,
3156 offscreen_target_color_render_buffer_.get()); 3143 offscreen_target_color_render_buffer_.get());
3157 } else { 3144 } else {
3158 offscreen_target_frame_buffer_->AttachRenderTexture( 3145 offscreen_target_frame_buffer_->AttachRenderTexture(
3159 offscreen_target_color_texture_.get()); 3146 offscreen_target_color_texture_.get());
3160 } 3147 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
3231 if (!resize_callback_.is_null()) { 3218 if (!resize_callback_.is_null()) {
3232 resize_callback_.Run(gfx::Size(width, height)); 3219 resize_callback_.Run(gfx::Size(width, height));
3233 DCHECK(context_->IsCurrent(surface_.get())); 3220 DCHECK(context_->IsCurrent(surface_.get()));
3234 if (!context_->IsCurrent(surface_.get())) { 3221 if (!context_->IsCurrent(surface_.get())) {
3235 LOG(ERROR) << "GLES2DecoderImpl: Context lost because context no longer " 3222 LOG(ERROR) << "GLES2DecoderImpl: Context lost because context no longer "
3236 << "current after resize callback."; 3223 << "current after resize callback.";
3237 return error::kLostContext; 3224 return error::kLostContext;
3238 } 3225 }
3239 } 3226 }
3240 3227
3241 TRACE_BACKBUFFER_MEMORY_TOTAL(this);
3242
3243 return error::kNoError; 3228 return error::kNoError;
3244 } 3229 }
3245 3230
3246 const char* GLES2DecoderImpl::GetCommandName(unsigned int command_id) const { 3231 const char* GLES2DecoderImpl::GetCommandName(unsigned int command_id) const {
3247 if (command_id > kStartPoint && command_id < kNumCommands) { 3232 if (command_id > kStartPoint && command_id < kNumCommands) {
3248 return gles2::GetCommandName(static_cast<CommandId>(command_id)); 3233 return gles2::GetCommandName(static_cast<CommandId>(command_id));
3249 } 3234 }
3250 return GetCommonCommandName(static_cast<cmd::CommandId>(command_id)); 3235 return GetCommonCommandName(static_cast<cmd::CommandId>(command_id));
3251 } 3236 }
3252 3237
(...skipping 5074 matching lines...) Expand 10 before | Expand all | Expand 10 after
8327 // fix this. 8312 // fix this.
8328 if (needs_mac_nvidia_driver_workaround_) { 8313 if (needs_mac_nvidia_driver_workaround_) {
8329 offscreen_saved_frame_buffer_->Create(); 8314 offscreen_saved_frame_buffer_->Create();
8330 glFinish(); 8315 glFinish();
8331 } 8316 }
8332 8317
8333 // Allocate the offscreen saved color texture. 8318 // Allocate the offscreen saved color texture.
8334 DCHECK(offscreen_saved_color_format_); 8319 DCHECK(offscreen_saved_color_format_);
8335 offscreen_saved_color_texture_->AllocateStorage( 8320 offscreen_saved_color_texture_->AllocateStorage(
8336 offscreen_size_, offscreen_saved_color_format_); 8321 offscreen_size_, offscreen_saved_color_format_);
8337 TRACE_BACKBUFFER_MEMORY_TOTAL(this);
8338 8322
8339 offscreen_saved_frame_buffer_->AttachRenderTexture( 8323 offscreen_saved_frame_buffer_->AttachRenderTexture(
8340 offscreen_saved_color_texture_.get()); 8324 offscreen_saved_color_texture_.get());
8341 if (offscreen_saved_frame_buffer_->CheckStatus() != 8325 if (offscreen_saved_frame_buffer_->CheckStatus() !=
8342 GL_FRAMEBUFFER_COMPLETE) { 8326 GL_FRAMEBUFFER_COMPLETE) {
8343 LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " 8327 LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed "
8344 << "because offscreen saved FBO was incomplete."; 8328 << "because offscreen saved FBO was incomplete.";
8345 return error::kLostContext; 8329 return error::kLostContext;
8346 } 8330 }
8347 8331
(...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after
9292 } 9276 }
9293 9277
9294 9278
9295 // Include the auto-generated part of this file. We split this because it means 9279 // Include the auto-generated part of this file. We split this because it means
9296 // we can easily edit the non-auto generated parts right here in this file 9280 // we can easily edit the non-auto generated parts right here in this file
9297 // instead of having to edit some template or the code generator. 9281 // instead of having to edit some template or the code generator.
9298 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 9282 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
9299 9283
9300 } // namespace gles2 9284 } // namespace gles2
9301 } // namespace gpu 9285 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/buffer_manager.cc ('k') | gpu/command_buffer/service/memory_tracking.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698