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

Side by Side Diff: gpu/ipc/service/gpu_channel_manager.cc

Issue 2814843002: gpu: GPU service scheduler. (Closed)
Patch Set: rebase Created 3 years, 7 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/ipc/service/gpu_channel_manager.h" 5 #include "gpu/ipc/service/gpu_channel_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
16 #include "base/threading/thread_task_runner_handle.h" 16 #include "base/threading/thread_task_runner_handle.h"
17 #include "build/build_config.h" 17 #include "build/build_config.h"
18 #include "gpu/command_buffer/common/sync_token.h" 18 #include "gpu/command_buffer/common/sync_token.h"
19 #include "gpu/command_buffer/service/feature_info.h" 19 #include "gpu/command_buffer/service/feature_info.h"
20 #include "gpu/command_buffer/service/mailbox_manager.h" 20 #include "gpu/command_buffer/service/mailbox_manager.h"
21 #include "gpu/command_buffer/service/memory_program_cache.h" 21 #include "gpu/command_buffer/service/memory_program_cache.h"
22 #include "gpu/command_buffer/service/preemption_flag.h" 22 #include "gpu/command_buffer/service/preemption_flag.h"
23 #include "gpu/command_buffer/service/scheduler.h"
23 #include "gpu/command_buffer/service/shader_translator_cache.h" 24 #include "gpu/command_buffer/service/shader_translator_cache.h"
24 #include "gpu/command_buffer/service/sync_point_manager.h" 25 #include "gpu/command_buffer/service/sync_point_manager.h"
25 #include "gpu/ipc/common/gpu_messages.h" 26 #include "gpu/ipc/common/gpu_messages.h"
26 #include "gpu/ipc/service/gpu_channel.h" 27 #include "gpu/ipc/service/gpu_channel.h"
27 #include "gpu/ipc/service/gpu_channel_manager_delegate.h" 28 #include "gpu/ipc/service/gpu_channel_manager_delegate.h"
28 #include "gpu/ipc/service/gpu_memory_buffer_factory.h" 29 #include "gpu/ipc/service/gpu_memory_buffer_factory.h"
29 #include "gpu/ipc/service/gpu_memory_manager.h" 30 #include "gpu/ipc/service/gpu_memory_manager.h"
30 #include "ui/gl/gl_bindings.h" 31 #include "ui/gl/gl_bindings.h"
31 #include "ui/gl/gl_share_group.h" 32 #include "ui/gl/gl_share_group.h"
32 #include "ui/gl/init/gl_factory.h" 33 #include "ui/gl/init/gl_factory.h"
33 34
34 namespace gpu { 35 namespace gpu {
35 36
36 namespace { 37 namespace {
37 #if defined(OS_ANDROID) 38 #if defined(OS_ANDROID)
38 // Amount of time we expect the GPU to stay powered up without being used. 39 // Amount of time we expect the GPU to stay powered up without being used.
39 const int kMaxGpuIdleTimeMs = 40; 40 const int kMaxGpuIdleTimeMs = 40;
40 // Maximum amount of time we keep pinging the GPU waiting for the client to 41 // Maximum amount of time we keep pinging the GPU waiting for the client to
41 // draw. 42 // draw.
42 const int kMaxKeepAliveTimeMs = 200; 43 const int kMaxKeepAliveTimeMs = 200;
43 #endif 44 #endif
44
45 } 45 }
46 46
47 GpuChannelManager::GpuChannelManager( 47 GpuChannelManager::GpuChannelManager(
48 const GpuPreferences& gpu_preferences, 48 const GpuPreferences& gpu_preferences,
49 GpuChannelManagerDelegate* delegate, 49 GpuChannelManagerDelegate* delegate,
50 GpuWatchdogThread* watchdog, 50 GpuWatchdogThread* watchdog,
51 scoped_refptr<base::SingleThreadTaskRunner> task_runner, 51 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
52 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, 52 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
53 Scheduler* scheduler,
53 SyncPointManager* sync_point_manager, 54 SyncPointManager* sync_point_manager,
54 GpuMemoryBufferFactory* gpu_memory_buffer_factory, 55 GpuMemoryBufferFactory* gpu_memory_buffer_factory,
55 const GpuFeatureInfo& gpu_feature_info, 56 const GpuFeatureInfo& gpu_feature_info,
56 GpuProcessActivityFlags activity_flags) 57 GpuProcessActivityFlags activity_flags)
57 : task_runner_(task_runner), 58 : task_runner_(task_runner),
58 io_task_runner_(io_task_runner), 59 io_task_runner_(io_task_runner),
59 gpu_preferences_(gpu_preferences), 60 gpu_preferences_(gpu_preferences),
60 gpu_driver_bug_workarounds_(base::CommandLine::ForCurrentProcess()), 61 gpu_driver_bug_workarounds_(base::CommandLine::ForCurrentProcess()),
61 delegate_(delegate), 62 delegate_(delegate),
62 watchdog_(watchdog), 63 watchdog_(watchdog),
63 share_group_(new gl::GLShareGroup()), 64 share_group_(new gl::GLShareGroup()),
64 mailbox_manager_(gles2::MailboxManager::Create(gpu_preferences)), 65 mailbox_manager_(gles2::MailboxManager::Create(gpu_preferences)),
65 gpu_memory_manager_(this), 66 gpu_memory_manager_(this),
67 scheduler_(scheduler),
66 sync_point_manager_(sync_point_manager), 68 sync_point_manager_(sync_point_manager),
67 gpu_memory_buffer_factory_(gpu_memory_buffer_factory), 69 gpu_memory_buffer_factory_(gpu_memory_buffer_factory),
68 gpu_feature_info_(gpu_feature_info), 70 gpu_feature_info_(gpu_feature_info),
69 exiting_for_lost_context_(false), 71 exiting_for_lost_context_(false),
70 activity_flags_(std::move(activity_flags)), 72 activity_flags_(std::move(activity_flags)),
71 weak_factory_(this) { 73 weak_factory_(this) {
72 DCHECK(task_runner); 74 DCHECK(task_runner);
73 DCHECK(io_task_runner); 75 DCHECK(io_task_runner);
74 if (gpu_preferences_.ui_prioritize_in_gpu_process) 76 if (gpu_preferences.ui_prioritize_in_gpu_process)
75 preemption_flag_ = new PreemptionFlag; 77 preemption_flag_ = new PreemptionFlag;
76 } 78 }
77 79
78 GpuChannelManager::~GpuChannelManager() { 80 GpuChannelManager::~GpuChannelManager() {
79 // Destroy channels before anything else because of dependencies. 81 // Destroy channels before anything else because of dependencies.
80 gpu_channels_.clear(); 82 gpu_channels_.clear();
81 if (default_offscreen_surface_.get()) { 83 if (default_offscreen_surface_.get()) {
82 default_offscreen_surface_->Destroy(); 84 default_offscreen_surface_->Destroy();
83 default_offscreen_surface_ = NULL; 85 default_offscreen_surface_ = NULL;
84 } 86 }
85 } 87 }
86 88
87 gles2::ProgramCache* GpuChannelManager::program_cache() { 89 gles2::ProgramCache* GpuChannelManager::program_cache() {
88 if (!program_cache_.get() && 90 if (!program_cache_.get() &&
89 !gpu_preferences_.disable_gpu_program_cache) { 91 !gpu_preferences_.disable_gpu_program_cache) {
90 const GpuDriverBugWorkarounds& workarounds = gpu_driver_bug_workarounds_; 92 const GpuDriverBugWorkarounds& workarounds = gpu_driver_bug_workarounds_;
91 bool disable_disk_cache = 93 bool disable_disk_cache =
92 gpu_preferences_.disable_gpu_shader_disk_cache || 94 gpu_preferences_.disable_gpu_shader_disk_cache ||
93 workarounds.disable_program_disk_cache; 95 workarounds.disable_program_disk_cache;
94 program_cache_.reset(new gles2::MemoryProgramCache( 96 program_cache_.reset(new gles2::MemoryProgramCache(
95 gpu_preferences_.gpu_program_cache_size, disable_disk_cache, 97 gpu_preferences_.gpu_program_cache_size, disable_disk_cache,
96 workarounds.disable_program_caching_for_transform_feedback, 98 workarounds.disable_program_caching_for_transform_feedback,
97 &activity_flags_)); 99 &activity_flags_));
98 } 100 }
99 return program_cache_.get(); 101 return program_cache_.get();
100 } 102 }
101 103
102 gles2::ShaderTranslatorCache* 104 gles2::ShaderTranslatorCache* GpuChannelManager::shader_translator_cache() {
103 GpuChannelManager::shader_translator_cache() {
104 if (!shader_translator_cache_.get()) { 105 if (!shader_translator_cache_.get()) {
105 shader_translator_cache_ = 106 shader_translator_cache_ =
106 new gles2::ShaderTranslatorCache(gpu_preferences_); 107 new gles2::ShaderTranslatorCache(gpu_preferences_);
107 } 108 }
108 return shader_translator_cache_.get(); 109 return shader_translator_cache_.get();
109 } 110 }
110 111
111 gles2::FramebufferCompletenessCache* 112 gles2::FramebufferCompletenessCache*
112 GpuChannelManager::framebuffer_completeness_cache() { 113 GpuChannelManager::framebuffer_completeness_cache() {
113 if (!framebuffer_completeness_cache_.get()) 114 if (!framebuffer_completeness_cache_.get())
114 framebuffer_completeness_cache_ = 115 framebuffer_completeness_cache_ = new gles2::FramebufferCompletenessCache;
115 new gles2::FramebufferCompletenessCache;
116 return framebuffer_completeness_cache_.get(); 116 return framebuffer_completeness_cache_.get();
117 } 117 }
118 118
119 void GpuChannelManager::RemoveChannel(int client_id) { 119 void GpuChannelManager::RemoveChannel(int client_id) {
120 delegate_->DidDestroyChannel(client_id); 120 delegate_->DidDestroyChannel(client_id);
121 gpu_channels_.erase(client_id); 121 gpu_channels_.erase(client_id);
122 } 122 }
123 123
124 GpuChannel* GpuChannelManager::LookupChannel(int32_t client_id) const { 124 GpuChannel* GpuChannelManager::LookupChannel(int32_t client_id) const {
125 const auto& it = gpu_channels_.find(client_id); 125 const auto& it = gpu_channels_.find(client_id);
126 return it != gpu_channels_.end() ? it->second.get() : nullptr; 126 return it != gpu_channels_.end() ? it->second.get() : nullptr;
127 } 127 }
128 128
129 GpuChannel* GpuChannelManager::EstablishChannel(int client_id, 129 GpuChannel* GpuChannelManager::EstablishChannel(int client_id,
130 uint64_t client_tracing_id, 130 uint64_t client_tracing_id,
131 bool is_gpu_host) { 131 bool is_gpu_host) {
132 std::unique_ptr<GpuChannel> gpu_channel = base::MakeUnique<GpuChannel>( 132 std::unique_ptr<GpuChannel> gpu_channel = base::MakeUnique<GpuChannel>(
133 this, sync_point_manager_, watchdog_, share_group_, mailbox_manager_, 133 this, scheduler_, sync_point_manager_, watchdog_, share_group_,
134 is_gpu_host ? preemption_flag_ : nullptr, 134 mailbox_manager_, is_gpu_host ? preemption_flag_ : nullptr,
135 is_gpu_host ? nullptr : preemption_flag_, task_runner_, io_task_runner_, 135 is_gpu_host ? nullptr : preemption_flag_, task_runner_, io_task_runner_,
136 client_id, client_tracing_id, is_gpu_host); 136 client_id, client_tracing_id, is_gpu_host);
137 137
138 GpuChannel* gpu_channel_ptr = gpu_channel.get(); 138 GpuChannel* gpu_channel_ptr = gpu_channel.get();
139 gpu_channels_[client_id] = std::move(gpu_channel); 139 gpu_channels_[client_id] = std::move(gpu_channel);
140 return gpu_channel_ptr; 140 return gpu_channel_ptr;
141 } 141 }
142 142
143 void GpuChannelManager::InternalDestroyGpuMemoryBuffer( 143 void GpuChannelManager::InternalDestroyGpuMemoryBuffer(
144 gfx::GpuMemoryBufferId id, 144 gfx::GpuMemoryBufferId id,
145 int client_id) { 145 int client_id) {
146 io_task_runner_->PostTask( 146 io_task_runner_->PostTask(
147 FROM_HERE, 147 FROM_HERE,
148 base::Bind(&GpuChannelManager::InternalDestroyGpuMemoryBufferOnIO, 148 base::Bind(&GpuChannelManager::InternalDestroyGpuMemoryBufferOnIO,
149 base::Unretained(this), id, client_id)); 149 base::Unretained(this), id, client_id));
150 } 150 }
151 151
152 void GpuChannelManager::InternalDestroyGpuMemoryBufferOnIO( 152 void GpuChannelManager::InternalDestroyGpuMemoryBufferOnIO(
153 gfx::GpuMemoryBufferId id, 153 gfx::GpuMemoryBufferId id,
154 int client_id) { 154 int client_id) {
155 gpu_memory_buffer_factory_->DestroyGpuMemoryBuffer(id, client_id); 155 gpu_memory_buffer_factory_->DestroyGpuMemoryBuffer(id, client_id);
156 } 156 }
157 157
158 void GpuChannelManager::DestroyGpuMemoryBuffer( 158 void GpuChannelManager::DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
159 gfx::GpuMemoryBufferId id, 159 int client_id,
160 int client_id, 160 const SyncToken& sync_token) {
161 const SyncToken& sync_token) {
162 if (!sync_point_manager_->WaitOutOfOrder( 161 if (!sync_point_manager_->WaitOutOfOrder(
163 sync_token, 162 sync_token,
164 base::Bind(&GpuChannelManager::InternalDestroyGpuMemoryBuffer, 163 base::Bind(&GpuChannelManager::InternalDestroyGpuMemoryBuffer,
165 base::Unretained(this), id, client_id))) { 164 base::Unretained(this), id, client_id))) {
166 // No sync token or invalid sync token, destroy immediately. 165 // No sync token or invalid sync token, destroy immediately.
167 InternalDestroyGpuMemoryBuffer(id, client_id); 166 InternalDestroyGpuMemoryBuffer(id, client_id);
168 } 167 }
169 } 168 }
170 169
171 void GpuChannelManager::PopulateShaderCache(const std::string& program_proto) { 170 void GpuChannelManager::PopulateShaderCache(const std::string& program_proto) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 last_gpu_access_time_ = base::TimeTicks::Now(); 209 last_gpu_access_time_ = base::TimeTicks::Now();
211 } 210 }
212 211
213 void GpuChannelManager::WakeUpGpu() { 212 void GpuChannelManager::WakeUpGpu() {
214 begin_wake_up_time_ = base::TimeTicks::Now(); 213 begin_wake_up_time_ = base::TimeTicks::Now();
215 ScheduleWakeUpGpu(); 214 ScheduleWakeUpGpu();
216 } 215 }
217 216
218 void GpuChannelManager::ScheduleWakeUpGpu() { 217 void GpuChannelManager::ScheduleWakeUpGpu() {
219 base::TimeTicks now = base::TimeTicks::Now(); 218 base::TimeTicks now = base::TimeTicks::Now();
220 TRACE_EVENT2("gpu", "GpuChannelManager::ScheduleWakeUp", 219 TRACE_EVENT2("gpu", "GpuChannelManager::ScheduleWakeUp", "idle_time",
221 "idle_time", (now - last_gpu_access_time_).InMilliseconds(), 220 (now - last_gpu_access_time_).InMilliseconds(),
222 "keep_awake_time", (now - begin_wake_up_time_).InMilliseconds()); 221 "keep_awake_time", (now - begin_wake_up_time_).InMilliseconds());
223 if (now - last_gpu_access_time_ < 222 if (now - last_gpu_access_time_ <
224 base::TimeDelta::FromMilliseconds(kMaxGpuIdleTimeMs)) 223 base::TimeDelta::FromMilliseconds(kMaxGpuIdleTimeMs))
225 return; 224 return;
226 if (now - begin_wake_up_time_ > 225 if (now - begin_wake_up_time_ >
227 base::TimeDelta::FromMilliseconds(kMaxKeepAliveTimeMs)) 226 base::TimeDelta::FromMilliseconds(kMaxKeepAliveTimeMs))
228 return; 227 return;
229 228
230 DoWakeUpGpu(); 229 DoWakeUpGpu();
231 230
(...skipping 14 matching lines...) Expand all
246 } 245 }
247 } 246 }
248 if (!stub || !stub->decoder()->MakeCurrent()) 247 if (!stub || !stub->decoder()->MakeCurrent())
249 return; 248 return;
250 glFinish(); 249 glFinish();
251 DidAccessGpu(); 250 DidAccessGpu();
252 } 251 }
253 #endif 252 #endif
254 253
255 } // namespace gpu 254 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698