Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/ipc/service/gpu_command_buffer_stub.h" | 5 #include "gpu/ipc/service/gpu_command_buffer_stub.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/hash.h" | 11 #include "base/hash.h" |
| 12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/memory_pressure_listener.h" | |
| 14 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 15 #include "base/memory/shared_memory.h" | 16 #include "base/memory/shared_memory.h" |
| 17 #include "base/metrics/histogram_macros.h" | |
| 16 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 17 #include "base/trace_event/trace_event.h" | 19 #include "base/trace_event/trace_event.h" |
| 18 #include "build/build_config.h" | 20 #include "build/build_config.h" |
| 19 #include "gpu/command_buffer/common/constants.h" | 21 #include "gpu/command_buffer/common/constants.h" |
| 20 #include "gpu/command_buffer/common/gpu_memory_buffer_support.h" | 22 #include "gpu/command_buffer/common/gpu_memory_buffer_support.h" |
| 21 #include "gpu/command_buffer/common/mailbox.h" | 23 #include "gpu/command_buffer/common/mailbox.h" |
| 22 #include "gpu/command_buffer/common/sync_token.h" | 24 #include "gpu/command_buffer/common/sync_token.h" |
| 23 #include "gpu/command_buffer/service/gl_context_virtual.h" | 25 #include "gpu/command_buffer/service/gl_context_virtual.h" |
| 24 #include "gpu/command_buffer/service/gl_state_restorer_impl.h" | 26 #include "gpu/command_buffer/service/gl_state_restorer_impl.h" |
| 25 #include "gpu/command_buffer/service/image_manager.h" | 27 #include "gpu/command_buffer/service/image_manager.h" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 47 #include "ui/gl/init/gl_factory.h" | 49 #include "ui/gl/init/gl_factory.h" |
| 48 | 50 |
| 49 #if defined(OS_WIN) | 51 #if defined(OS_WIN) |
| 50 #include "base/win/win_util.h" | 52 #include "base/win/win_util.h" |
| 51 #endif | 53 #endif |
| 52 | 54 |
| 53 #if defined(OS_ANDROID) | 55 #if defined(OS_ANDROID) |
| 54 #include "gpu/ipc/service/stream_texture_android.h" | 56 #include "gpu/ipc/service/stream_texture_android.h" |
| 55 #endif | 57 #endif |
| 56 | 58 |
| 59 // Macro to reduce code duplication when logging memory in | |
| 60 // GpuCommandBufferMemoryTracker. This is needed as the UMA_HISTOGRAM_* macros | |
| 61 // require a unique call-site per histogram (you can't funnel multiple strings | |
| 62 // into the same call-site). | |
| 63 #define GPU_COMMAND_BUFFER_MEMORY_BLOCK(category) \ | |
| 64 do { \ | |
| 65 uint64_t mb_used = tracking_group_->GetSize() / (1024 * 1024); \ | |
| 66 switch (context_type_) { \ | |
| 67 case gles2::CONTEXT_TYPE_WEBGL1: \ | |
| 68 case gles2::CONTEXT_TYPE_WEBGL2: \ | |
| 69 UMA_HISTOGRAM_MEMORY_LARGE_MB("GPU.ContextMemory.WebGL." category, \ | |
| 70 mb_used); \ | |
| 71 break; \ | |
| 72 case gles2::CONTEXT_TYPE_OPENGLES2: \ | |
| 73 case gles2::CONTEXT_TYPE_OPENGLES3: \ | |
| 74 UMA_HISTOGRAM_MEMORY_LARGE_MB("GPU.ContextMemory.GLES." category, \ | |
| 75 mb_used); \ | |
| 76 break; \ | |
| 77 } \ | |
| 78 } while (false) | |
| 79 | |
| 57 namespace gpu { | 80 namespace gpu { |
| 58 struct WaitForCommandState { | 81 struct WaitForCommandState { |
| 59 WaitForCommandState(int32_t start, int32_t end, IPC::Message* reply) | 82 WaitForCommandState(int32_t start, int32_t end, IPC::Message* reply) |
| 60 : start(start), end(end), reply(reply) {} | 83 : start(start), end(end), reply(reply) {} |
| 61 | 84 |
| 62 int32_t start; | 85 int32_t start; |
| 63 int32_t end; | 86 int32_t end; |
| 64 std::unique_ptr<IPC::Message> reply; | 87 std::unique_ptr<IPC::Message> reply; |
| 65 }; | 88 }; |
| 66 | 89 |
| 67 namespace { | 90 namespace { |
| 68 | 91 |
| 69 // The GpuCommandBufferMemoryTracker class provides a bridge between the | 92 // The GpuCommandBufferMemoryTracker class provides a bridge between the |
| 70 // ContextGroup's memory type managers and the GpuMemoryManager class. | 93 // ContextGroup's memory type managers and the GpuMemoryManager class. |
| 71 class GpuCommandBufferMemoryTracker : public gles2::MemoryTracker { | 94 class GpuCommandBufferMemoryTracker : public gles2::MemoryTracker { |
| 72 public: | 95 public: |
| 73 explicit GpuCommandBufferMemoryTracker(GpuChannel* channel, | 96 explicit GpuCommandBufferMemoryTracker( |
| 74 uint64_t share_group_tracing_guid) | 97 GpuChannel* channel, |
| 98 uint64_t share_group_tracing_guid, | |
| 99 gles2::ContextType context_type, | |
| 100 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | |
| 75 : tracking_group_( | 101 : tracking_group_( |
| 76 channel->gpu_channel_manager() | 102 channel->gpu_channel_manager() |
| 77 ->gpu_memory_manager() | 103 ->gpu_memory_manager() |
| 78 ->CreateTrackingGroup(channel->GetClientPID(), this)), | 104 ->CreateTrackingGroup(channel->GetClientPID(), this)), |
| 79 client_tracing_id_(channel->client_tracing_id()), | 105 client_tracing_id_(channel->client_tracing_id()), |
| 80 client_id_(channel->client_id()), | 106 client_id_(channel->client_id()), |
| 81 share_group_tracing_guid_(share_group_tracing_guid) {} | 107 share_group_tracing_guid_(share_group_tracing_guid), |
| 108 context_type_(context_type), | |
| 109 memory_pressure_listener_(new base::MemoryPressureListener( | |
| 110 base::Bind(&GpuCommandBufferMemoryTracker::LogMemoryStatsPressure, | |
| 111 base::Unretained(this)))) { | |
| 112 // Set up |memory_stats_timer_| to call LogMemoryPeriodic every 1s | |
|
Ken Russell (switch to Gerrit)
2016/12/20 20:28:03
Update comment to indicate correct time, or just r
ericrk
2016/12/20 21:19:08
Done.
| |
| 113 // via the provided |task_runner|. | |
| 114 memory_stats_timer_.SetTaskRunner(std::move(task_runner)); | |
| 115 memory_stats_timer_.Start( | |
| 116 FROM_HERE, base::TimeDelta::FromSeconds(30), this, | |
| 117 &GpuCommandBufferMemoryTracker::LogMemoryStatsPeriodic); | |
| 118 } | |
| 82 | 119 |
| 83 void TrackMemoryAllocatedChange( | 120 void TrackMemoryAllocatedChange( |
| 84 size_t old_size, size_t new_size) override { | 121 size_t old_size, size_t new_size) override { |
| 85 tracking_group_->TrackMemoryAllocatedChange( | 122 tracking_group_->TrackMemoryAllocatedChange( |
| 86 old_size, new_size); | 123 old_size, new_size); |
| 87 } | 124 } |
| 88 | 125 |
| 89 bool EnsureGPUMemoryAvailable(size_t size_needed) override { | 126 bool EnsureGPUMemoryAvailable(size_t size_needed) override { |
| 90 return tracking_group_->EnsureGPUMemoryAvailable(size_needed); | 127 return tracking_group_->EnsureGPUMemoryAvailable(size_needed); |
| 91 }; | 128 } |
| 92 | 129 |
| 93 uint64_t ClientTracingId() const override { return client_tracing_id_; } | 130 uint64_t ClientTracingId() const override { return client_tracing_id_; } |
| 94 int ClientId() const override { return client_id_; } | 131 int ClientId() const override { return client_id_; } |
| 95 uint64_t ShareGroupTracingGUID() const override { | 132 uint64_t ShareGroupTracingGUID() const override { |
| 96 return share_group_tracing_guid_; | 133 return share_group_tracing_guid_; |
| 97 } | 134 } |
| 98 | 135 |
| 99 private: | 136 private: |
| 100 ~GpuCommandBufferMemoryTracker() override {} | 137 ~GpuCommandBufferMemoryTracker() override { LogMemoryStatsShutdown(); } |
| 138 | |
| 139 void LogMemoryStatsPeriodic() { GPU_COMMAND_BUFFER_MEMORY_BLOCK("Periodic"); } | |
| 140 void LogMemoryStatsShutdown() { GPU_COMMAND_BUFFER_MEMORY_BLOCK("Shutdown"); } | |
| 141 void LogMemoryStatsPressure( | |
| 142 base::MemoryPressureListener::MemoryPressureLevel pressure_level) { | |
| 143 // Only log on CRITICAL memory pressure. | |
| 144 if (pressure_level == | |
| 145 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { | |
| 146 GPU_COMMAND_BUFFER_MEMORY_BLOCK("Pressure"); | |
| 147 } | |
| 148 } | |
| 149 | |
| 101 std::unique_ptr<GpuMemoryTrackingGroup> tracking_group_; | 150 std::unique_ptr<GpuMemoryTrackingGroup> tracking_group_; |
| 102 const uint64_t client_tracing_id_; | 151 const uint64_t client_tracing_id_; |
| 103 const int client_id_; | 152 const int client_id_; |
| 104 const uint64_t share_group_tracing_guid_; | 153 const uint64_t share_group_tracing_guid_; |
| 105 | 154 |
| 155 // Variables used in memory stat histogram logging. | |
| 156 const gles2::ContextType context_type_; | |
| 157 base::RepeatingTimer memory_stats_timer_; | |
| 158 std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_; | |
| 159 | |
| 106 DISALLOW_COPY_AND_ASSIGN(GpuCommandBufferMemoryTracker); | 160 DISALLOW_COPY_AND_ASSIGN(GpuCommandBufferMemoryTracker); |
| 107 }; | 161 }; |
| 108 | 162 |
| 109 // FastSetActiveURL will shortcut the expensive call to SetActiveURL when the | 163 // FastSetActiveURL will shortcut the expensive call to SetActiveURL when the |
| 110 // url_hash matches. | 164 // url_hash matches. |
| 111 void FastSetActiveURL(const GURL& url, size_t url_hash, GpuChannel* channel) { | 165 void FastSetActiveURL(const GURL& url, size_t url_hash, GpuChannel* channel) { |
| 112 // Leave the previously set URL in the empty case -- empty URLs are given by | 166 // Leave the previously set URL in the empty case -- empty URLs are given by |
| 113 // BlinkPlatformImpl::createOffscreenGraphicsContext3DProvider. Hopefully the | 167 // BlinkPlatformImpl::createOffscreenGraphicsContext3DProvider. Hopefully the |
| 114 // onscreen context URL was set previously and will show up even when a crash | 168 // onscreen context URL was set previously and will show up even when a crash |
| 115 // occurs during offscreen command processing. | 169 // occurs during offscreen command processing. |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 501 context_group_ = share_command_buffer_stub->context_group_; | 555 context_group_ = share_command_buffer_stub->context_group_; |
| 502 DCHECK(context_group_->bind_generates_resource() == | 556 DCHECK(context_group_->bind_generates_resource() == |
| 503 init_params.attribs.bind_generates_resource); | 557 init_params.attribs.bind_generates_resource); |
| 504 } else { | 558 } else { |
| 505 scoped_refptr<gles2::FeatureInfo> feature_info = | 559 scoped_refptr<gles2::FeatureInfo> feature_info = |
| 506 new gles2::FeatureInfo(manager->gpu_driver_bug_workarounds()); | 560 new gles2::FeatureInfo(manager->gpu_driver_bug_workarounds()); |
| 507 gpu::GpuMemoryBufferFactory* gmb_factory = | 561 gpu::GpuMemoryBufferFactory* gmb_factory = |
| 508 channel_->gpu_channel_manager()->gpu_memory_buffer_factory(); | 562 channel_->gpu_channel_manager()->gpu_memory_buffer_factory(); |
| 509 context_group_ = new gles2::ContextGroup( | 563 context_group_ = new gles2::ContextGroup( |
| 510 manager->gpu_preferences(), channel_->mailbox_manager(), | 564 manager->gpu_preferences(), channel_->mailbox_manager(), |
| 511 new GpuCommandBufferMemoryTracker(channel_, | 565 new GpuCommandBufferMemoryTracker( |
| 512 command_buffer_id_.GetUnsafeValue()), | 566 channel_, command_buffer_id_.GetUnsafeValue(), |
| 567 init_params.attribs.context_type, channel_->task_runner()), | |
| 513 manager->shader_translator_cache(), | 568 manager->shader_translator_cache(), |
| 514 manager->framebuffer_completeness_cache(), feature_info, | 569 manager->framebuffer_completeness_cache(), feature_info, |
| 515 init_params.attribs.bind_generates_resource, | 570 init_params.attribs.bind_generates_resource, |
| 516 gmb_factory ? gmb_factory->AsImageFactory() : nullptr, | 571 gmb_factory ? gmb_factory->AsImageFactory() : nullptr, |
| 517 channel_->watchdog() /* progress_reporter */); | 572 channel_->watchdog() /* progress_reporter */); |
| 518 } | 573 } |
| 519 | 574 |
| 520 #if defined(OS_MACOSX) | 575 #if defined(OS_MACOSX) |
| 521 // Virtualize PreferIntegratedGpu contexts by default on OS X to prevent | 576 // Virtualize PreferIntegratedGpu contexts by default on OS X to prevent |
| 522 // performance regressions when enabling FCM. | 577 // performance regressions when enabling FCM. |
| (...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1145 command_buffer_->GetLastState().error == error::kLostContext) | 1200 command_buffer_->GetLastState().error == error::kLostContext) |
| 1146 return; | 1201 return; |
| 1147 | 1202 |
| 1148 command_buffer_->SetContextLostReason(error::kUnknown); | 1203 command_buffer_->SetContextLostReason(error::kUnknown); |
| 1149 if (decoder_) | 1204 if (decoder_) |
| 1150 decoder_->MarkContextLost(error::kUnknown); | 1205 decoder_->MarkContextLost(error::kUnknown); |
| 1151 command_buffer_->SetParseError(error::kLostContext); | 1206 command_buffer_->SetParseError(error::kLostContext); |
| 1152 } | 1207 } |
| 1153 | 1208 |
| 1154 } // namespace gpu | 1209 } // namespace gpu |
| OLD | NEW |