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

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

Issue 2440093003: WIP GPU scheduler + delayed activation / tile draw
Patch Set: SignalSyncToken -> IsFenceSyncReleased Created 4 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
« no previous file with comments | « gpu/ipc/service/gpu_channel_manager.h ('k') | gpu/ipc/service/gpu_channel_test_common.h » ('j') | 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/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/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
15 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
16 #include "build/build_config.h" 16 #include "build/build_config.h"
17 #include "gpu/command_buffer/common/sync_token.h" 17 #include "gpu/command_buffer/common/sync_token.h"
18 #include "gpu/command_buffer/service/feature_info.h" 18 #include "gpu/command_buffer/service/feature_info.h"
19 #include "gpu/command_buffer/service/mailbox_manager.h" 19 #include "gpu/command_buffer/service/mailbox_manager.h"
20 #include "gpu/command_buffer/service/memory_program_cache.h" 20 #include "gpu/command_buffer/service/memory_program_cache.h"
21 #include "gpu/command_buffer/service/shader_translator_cache.h" 21 #include "gpu/command_buffer/service/shader_translator_cache.h"
22 #include "gpu/command_buffer/service/sync_point_manager.h" 22 #include "gpu/command_buffer/service/sync_point_manager.h"
23 #include "gpu/ipc/common/gpu_messages.h" 23 #include "gpu/ipc/common/gpu_messages.h"
24 #include "gpu/ipc/service/gpu_channel.h" 24 #include "gpu/ipc/service/gpu_channel.h"
25 #include "gpu/ipc/service/gpu_channel_manager_delegate.h" 25 #include "gpu/ipc/service/gpu_channel_manager_delegate.h"
26 #include "gpu/ipc/service/gpu_memory_buffer_factory.h" 26 #include "gpu/ipc/service/gpu_memory_buffer_factory.h"
27 #include "gpu/ipc/service/gpu_memory_manager.h" 27 #include "gpu/ipc/service/gpu_memory_manager.h"
28 #include "gpu/ipc/service/gpu_scheduler.h"
28 #include "ui/gl/gl_bindings.h" 29 #include "ui/gl/gl_bindings.h"
29 #include "ui/gl/gl_share_group.h" 30 #include "ui/gl/gl_share_group.h"
30 #include "ui/gl/init/gl_factory.h" 31 #include "ui/gl/init/gl_factory.h"
31 32
32 namespace gpu { 33 namespace gpu {
33 34
34 namespace { 35 namespace {
35 #if defined(OS_ANDROID) 36 #if defined(OS_ANDROID)
36 // Amount of time we expect the GPU to stay powered up without being used. 37 // Amount of time we expect the GPU to stay powered up without being used.
37 const int kMaxGpuIdleTimeMs = 40; 38 const int kMaxGpuIdleTimeMs = 40;
38 // Maximum amount of time we keep pinging the GPU waiting for the client to 39 // Maximum amount of time we keep pinging the GPU waiting for the client to
39 // draw. 40 // draw.
40 const int kMaxKeepAliveTimeMs = 200; 41 const int kMaxKeepAliveTimeMs = 200;
41 #endif 42 #endif
42
43 } 43 }
44 44
45 GpuChannelManager::GpuChannelManager( 45 GpuChannelManager::GpuChannelManager(
46 const GpuPreferences& gpu_preferences, 46 const GpuPreferences& gpu_preferences,
47 GpuChannelManagerDelegate* delegate, 47 GpuChannelManagerDelegate* delegate,
48 GpuWatchdogThread* watchdog, 48 GpuWatchdogThread* watchdog,
49 base::SingleThreadTaskRunner* task_runner, 49 base::SingleThreadTaskRunner* task_runner,
50 base::SingleThreadTaskRunner* io_task_runner, 50 base::SingleThreadTaskRunner* io_task_runner,
51 base::WaitableEvent* shutdown_event, 51 base::WaitableEvent* shutdown_event,
52 SyncPointManager* sync_point_manager, 52 SyncPointManager* sync_point_manager,
53 GpuMemoryBufferFactory* gpu_memory_buffer_factory) 53 GpuMemoryBufferFactory* gpu_memory_buffer_factory)
54 : task_runner_(task_runner), 54 : task_runner_(task_runner),
55 io_task_runner_(io_task_runner), 55 io_task_runner_(io_task_runner),
56 gpu_preferences_(gpu_preferences), 56 gpu_preferences_(gpu_preferences),
57 gpu_driver_bug_workarounds_(base::CommandLine::ForCurrentProcess()), 57 gpu_driver_bug_workarounds_(base::CommandLine::ForCurrentProcess()),
58 delegate_(delegate), 58 delegate_(delegate),
59 watchdog_(watchdog), 59 watchdog_(watchdog),
60 shutdown_event_(shutdown_event), 60 shutdown_event_(shutdown_event),
61 share_group_(new gl::GLShareGroup()), 61 share_group_(new gl::GLShareGroup()),
62 mailbox_manager_(gles2::MailboxManager::Create(gpu_preferences)), 62 mailbox_manager_(gles2::MailboxManager::Create(gpu_preferences)),
63 gpu_memory_manager_(this), 63 gpu_memory_manager_(this),
64 sync_point_manager_(sync_point_manager), 64 sync_point_manager_(sync_point_manager),
65 sync_point_client_waiter_( 65 sync_point_client_waiter_(
66 sync_point_manager->CreateSyncPointClientWaiter()), 66 sync_point_manager->CreateSyncPointClientWaiter()),
67 gpu_memory_buffer_factory_(gpu_memory_buffer_factory), 67 gpu_memory_buffer_factory_(gpu_memory_buffer_factory),
68 exiting_for_lost_context_(false), 68 exiting_for_lost_context_(false),
69 weak_factory_(this) { 69 weak_factory_(this) {
70 DCHECK(task_runner); 70 DCHECK(task_runner);
71 DCHECK(io_task_runner); 71 DCHECK(io_task_runner);
72 if (gpu_preferences_.ui_prioritize_in_gpu_process) 72 if (gpu_preferences.enable_gpu_scheduler) {
73 scheduler_ = GpuScheduler::Create(task_runner);
74 } else if (gpu_preferences.ui_prioritize_in_gpu_process) {
73 preemption_flag_ = new PreemptionFlag; 75 preemption_flag_ = new PreemptionFlag;
76 }
74 } 77 }
75 78
76 GpuChannelManager::~GpuChannelManager() { 79 GpuChannelManager::~GpuChannelManager() {
77 // Destroy channels before anything else because of dependencies. 80 // Destroy channels before anything else because of dependencies.
78 gpu_channels_.clear(); 81 gpu_channels_.clear();
79 if (default_offscreen_surface_.get()) { 82 if (default_offscreen_surface_.get()) {
80 default_offscreen_surface_->Destroy(); 83 default_offscreen_surface_->Destroy();
81 default_offscreen_surface_ = NULL; 84 default_offscreen_surface_ = NULL;
82 } 85 }
83 } 86 }
84 87
85 gles2::ProgramCache* GpuChannelManager::program_cache() { 88 gles2::ProgramCache* GpuChannelManager::program_cache() {
86 if (!program_cache_.get() && 89 if (!program_cache_.get() &&
87 (gl::g_driver_gl.ext.b_GL_ARB_get_program_binary || 90 (gl::g_driver_gl.ext.b_GL_ARB_get_program_binary ||
88 gl::g_driver_gl.ext.b_GL_OES_get_program_binary) && 91 gl::g_driver_gl.ext.b_GL_OES_get_program_binary) &&
89 !gpu_preferences_.disable_gpu_program_cache) { 92 !gpu_preferences_.disable_gpu_program_cache) {
90 bool disable_disk_cache = 93 bool disable_disk_cache =
91 gpu_preferences_.disable_gpu_shader_disk_cache || 94 gpu_preferences_.disable_gpu_shader_disk_cache ||
92 gpu_driver_bug_workarounds_.disable_program_disk_cache; 95 gpu_driver_bug_workarounds_.disable_program_disk_cache;
93 program_cache_.reset(new gles2::MemoryProgramCache( 96 program_cache_.reset(new gles2::MemoryProgramCache(
94 gpu_preferences_.gpu_program_cache_size, disable_disk_cache)); 97 gpu_preferences_.gpu_program_cache_size, disable_disk_cache));
95 } 98 }
96 return program_cache_.get(); 99 return program_cache_.get();
97 } 100 }
98 101
99 gles2::ShaderTranslatorCache* 102 gles2::ShaderTranslatorCache* GpuChannelManager::shader_translator_cache() {
100 GpuChannelManager::shader_translator_cache() {
101 if (!shader_translator_cache_.get()) { 103 if (!shader_translator_cache_.get()) {
102 shader_translator_cache_ = 104 shader_translator_cache_ =
103 new gles2::ShaderTranslatorCache(gpu_preferences_); 105 new gles2::ShaderTranslatorCache(gpu_preferences_);
104 } 106 }
105 return shader_translator_cache_.get(); 107 return shader_translator_cache_.get();
106 } 108 }
107 109
108 gles2::FramebufferCompletenessCache* 110 gles2::FramebufferCompletenessCache*
109 GpuChannelManager::framebuffer_completeness_cache() { 111 GpuChannelManager::framebuffer_completeness_cache() {
110 if (!framebuffer_completeness_cache_.get()) 112 if (!framebuffer_completeness_cache_.get())
111 framebuffer_completeness_cache_ = 113 framebuffer_completeness_cache_ = new gles2::FramebufferCompletenessCache;
112 new gles2::FramebufferCompletenessCache;
113 return framebuffer_completeness_cache_.get(); 114 return framebuffer_completeness_cache_.get();
114 } 115 }
115 116
116 void GpuChannelManager::RemoveChannel(int client_id) { 117 void GpuChannelManager::RemoveChannel(int client_id) {
117 delegate_->DidDestroyChannel(client_id); 118 delegate_->DidDestroyChannel(client_id);
118 gpu_channels_.erase(client_id); 119 gpu_channels_.erase(client_id);
119 } 120 }
120 121
121 GpuChannel* GpuChannelManager::LookupChannel(int32_t client_id) const { 122 GpuChannel* GpuChannelManager::LookupChannel(int32_t client_id) const {
122 const auto& it = gpu_channels_.find(client_id); 123 const auto& it = gpu_channels_.find(client_id);
123 return it != gpu_channels_.end() ? it->second : nullptr; 124 return it != gpu_channels_.end() ? it->second : nullptr;
124 } 125 }
125 126
126 std::unique_ptr<GpuChannel> GpuChannelManager::CreateGpuChannel( 127 std::unique_ptr<GpuChannel> GpuChannelManager::CreateGpuChannel(
127 int client_id, 128 int client_id,
128 uint64_t client_tracing_id, 129 uint64_t client_tracing_id,
129 bool preempts, 130 bool preempts,
130 bool allow_view_command_buffers, 131 bool allow_view_command_buffers,
131 bool allow_real_time_streams) { 132 bool allow_real_time_streams) {
132 return base::MakeUnique<GpuChannel>( 133 return base::MakeUnique<GpuChannel>(
133 this, sync_point_manager(), watchdog_, share_group(), mailbox_manager(), 134 this, sync_point_manager_, watchdog_, scheduler_.get(), share_group_,
134 preempts ? preemption_flag() : nullptr, 135 mailbox_manager_, preempts ? preemption_flag_ : nullptr,
135 preempts ? nullptr : preemption_flag(), task_runner_.get(), 136 preempts ? nullptr : preemption_flag_, task_runner_, io_task_runner_,
136 io_task_runner_.get(), client_id, client_tracing_id, 137 client_id, client_tracing_id, allow_view_command_buffers,
137 allow_view_command_buffers, allow_real_time_streams); 138 allow_real_time_streams);
138 } 139 }
139 140
140 IPC::ChannelHandle GpuChannelManager::EstablishChannel( 141 IPC::ChannelHandle GpuChannelManager::EstablishChannel(
141 int client_id, 142 int client_id,
142 uint64_t client_tracing_id, 143 uint64_t client_tracing_id,
143 bool preempts, 144 bool preempts,
144 bool allow_view_command_buffers, 145 bool allow_view_command_buffers,
145 bool allow_real_time_streams) { 146 bool allow_real_time_streams) {
146 std::unique_ptr<GpuChannel> channel( 147 std::unique_ptr<GpuChannel> channel(
147 CreateGpuChannel(client_id, client_tracing_id, preempts, 148 CreateGpuChannel(client_id, client_tracing_id, preempts,
(...skipping 11 matching lines...) Expand all
159 base::Bind(&GpuChannelManager::InternalDestroyGpuMemoryBufferOnIO, 160 base::Bind(&GpuChannelManager::InternalDestroyGpuMemoryBufferOnIO,
160 base::Unretained(this), id, client_id)); 161 base::Unretained(this), id, client_id));
161 } 162 }
162 163
163 void GpuChannelManager::InternalDestroyGpuMemoryBufferOnIO( 164 void GpuChannelManager::InternalDestroyGpuMemoryBufferOnIO(
164 gfx::GpuMemoryBufferId id, 165 gfx::GpuMemoryBufferId id,
165 int client_id) { 166 int client_id) {
166 gpu_memory_buffer_factory_->DestroyGpuMemoryBuffer(id, client_id); 167 gpu_memory_buffer_factory_->DestroyGpuMemoryBuffer(id, client_id);
167 } 168 }
168 169
169 void GpuChannelManager::DestroyGpuMemoryBuffer( 170 void GpuChannelManager::DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
170 gfx::GpuMemoryBufferId id, 171 int client_id,
171 int client_id, 172 const SyncToken& sync_token) {
172 const SyncToken& sync_token) {
173 if (sync_token.HasData()) { 173 if (sync_token.HasData()) {
174 scoped_refptr<SyncPointClientState> release_state = 174 scoped_refptr<SyncPointClientState> release_state =
175 sync_point_manager()->GetSyncPointClientState( 175 sync_point_manager()->GetSyncPointClientState(
176 sync_token.namespace_id(), sync_token.command_buffer_id()); 176 sync_token.namespace_id(), sync_token.command_buffer_id());
177 if (release_state) { 177 if (release_state) {
178 sync_point_client_waiter_->WaitOutOfOrder( 178 sync_point_client_waiter_->WaitOutOfOrder(
179 release_state.get(), sync_token.release_count(), 179 release_state.get(), sync_token.release_count(),
180 base::Bind(&GpuChannelManager::InternalDestroyGpuMemoryBuffer, 180 base::Bind(&GpuChannelManager::InternalDestroyGpuMemoryBuffer,
181 base::Unretained(this), id, client_id)); 181 base::Unretained(this), id, client_id));
182 return; 182 return;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 last_gpu_access_time_ = base::TimeTicks::Now(); 247 last_gpu_access_time_ = base::TimeTicks::Now();
248 } 248 }
249 249
250 void GpuChannelManager::WakeUpGpu() { 250 void GpuChannelManager::WakeUpGpu() {
251 begin_wake_up_time_ = base::TimeTicks::Now(); 251 begin_wake_up_time_ = base::TimeTicks::Now();
252 ScheduleWakeUpGpu(); 252 ScheduleWakeUpGpu();
253 } 253 }
254 254
255 void GpuChannelManager::ScheduleWakeUpGpu() { 255 void GpuChannelManager::ScheduleWakeUpGpu() {
256 base::TimeTicks now = base::TimeTicks::Now(); 256 base::TimeTicks now = base::TimeTicks::Now();
257 TRACE_EVENT2("gpu", "GpuChannelManager::ScheduleWakeUp", 257 TRACE_EVENT2("gpu", "GpuChannelManager::ScheduleWakeUp", "idle_time",
258 "idle_time", (now - last_gpu_access_time_).InMilliseconds(), 258 (now - last_gpu_access_time_).InMilliseconds(),
259 "keep_awake_time", (now - begin_wake_up_time_).InMilliseconds()); 259 "keep_awake_time", (now - begin_wake_up_time_).InMilliseconds());
260 if (now - last_gpu_access_time_ < 260 if (now - last_gpu_access_time_ <
261 base::TimeDelta::FromMilliseconds(kMaxGpuIdleTimeMs)) 261 base::TimeDelta::FromMilliseconds(kMaxGpuIdleTimeMs))
262 return; 262 return;
263 if (now - begin_wake_up_time_ > 263 if (now - begin_wake_up_time_ >
264 base::TimeDelta::FromMilliseconds(kMaxKeepAliveTimeMs)) 264 base::TimeDelta::FromMilliseconds(kMaxKeepAliveTimeMs))
265 return; 265 return;
266 266
267 DoWakeUpGpu(); 267 DoWakeUpGpu();
268 268
(...skipping 14 matching lines...) Expand all
283 } 283 }
284 } 284 }
285 if (!stub || !stub->decoder()->MakeCurrent()) 285 if (!stub || !stub->decoder()->MakeCurrent())
286 return; 286 return;
287 glFinish(); 287 glFinish();
288 DidAccessGpu(); 288 DidAccessGpu();
289 } 289 }
290 #endif 290 #endif
291 291
292 } // namespace gpu 292 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/ipc/service/gpu_channel_manager.h ('k') | gpu/ipc/service/gpu_channel_test_common.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698