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/command_buffer/service/gpu_tracer.h" | 5 #include "gpu/command_buffer/service/gpu_tracer.h" |
6 | 6 |
7 #include <deque> | 7 #include <deque> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 13 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
14 #include "gpu/command_buffer/service/context_group.h" | |
15 #include "ui/gl/gl_version_info.h" | |
14 | 16 |
15 namespace gpu { | 17 namespace gpu { |
16 namespace gles2 { | 18 namespace gles2 { |
17 | 19 |
18 static const unsigned int kProcessInterval = 16; | 20 static const unsigned int kProcessInterval = 16; |
19 static TraceOutputter* g_outputter_thread = NULL; | 21 static TraceOutputter* g_outputter_thread = NULL; |
20 | 22 |
21 CPUTime::CPUTime() { | 23 CPUTime::CPUTime() { |
22 } | 24 } |
23 | 25 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 if (trace_service) { | 132 if (trace_service) { |
131 outputter_->TraceServiceBegin(category_, name_); | 133 outputter_->TraceServiceBegin(category_, name_); |
132 } | 134 } |
133 | 135 |
134 switch (tracer_type_) { | 136 switch (tracer_type_) { |
135 case kTracerTypeInvalid: | 137 case kTracerTypeInvalid: |
136 break; | 138 break; |
137 | 139 |
138 case kTracerTypeDisjointTimer: | 140 case kTracerTypeDisjointTimer: |
139 // For the disjoint timer, GPU idle time does not seem to increment the | 141 // For the disjoint timer, GPU idle time does not seem to increment the |
140 // internal counter. We must calculate the offset before any query. The | 142 // internal counter. We must calculate the offset before any query. |
141 // good news is any device that supports disjoint timer will also support | 143 // glGetInteger64v is supported under ES3 which we check for before using |
142 // glGetInteger64v, so we can query it directly unlike the ARBTimer case. | 144 // the kTracerTypeDisjointTimer. |
143 // The "offset_" variable will always be 0 during normal use cases, only | 145 { |
144 // under the unit tests will it be set to specific test values. | |
145 if (offset_ == 0) { | |
146 GLint64 gl_now = 0; | 146 GLint64 gl_now = 0; |
147 glGetInteger64v(GL_TIMESTAMP, &gl_now); | 147 glGetInteger64v(GL_TIMESTAMP, &gl_now); |
148 offset_ = cpu_time_->GetCurrentTime() - | 148 offset_ = cpu_time_->GetCurrentTime() - |
149 gl_now / base::Time::kNanosecondsPerMicrosecond; | 149 gl_now / base::Time::kNanosecondsPerMicrosecond; |
150 } | 150 } |
151 // Intentionally fall through to kTracerTypeARBTimer case.xs | 151 // Intentionally fall through to kTracerTypeARBTimer case.xs |
152 case kTracerTypeARBTimer: | 152 case kTracerTypeARBTimer: |
153 // GL_TIMESTAMP and GL_TIMESTAMP_EXT both have the same value. | 153 // GL_TIMESTAMP and GL_TIMESTAMP_EXT both have the same value. |
154 glQueryCounter(queries_[0], GL_TIMESTAMP); | 154 glQueryCounter(queries_[0], GL_TIMESTAMP); |
155 break; | 155 break; |
(...skipping 17 matching lines...) Expand all Loading... | |
173 outputter_->TraceServiceEnd(category_, name_); | 173 outputter_->TraceServiceEnd(category_, name_); |
174 } | 174 } |
175 } | 175 } |
176 | 176 |
177 bool GPUTrace::IsAvailable() { | 177 bool GPUTrace::IsAvailable() { |
178 if (tracer_type_ != kTracerTypeInvalid) { | 178 if (tracer_type_ != kTracerTypeInvalid) { |
179 if (!end_requested_) | 179 if (!end_requested_) |
180 return false; | 180 return false; |
181 | 181 |
182 GLint done = 0; | 182 GLint done = 0; |
183 glGetQueryObjectiv(queries_[1], GL_QUERY_RESULT_AVAILABLE, &done); | 183 glGetQueryObjectivARB(queries_[1], GL_QUERY_RESULT_AVAILABLE, &done); |
184 return !!done; | 184 return !!done; |
185 } | 185 } |
186 | 186 |
187 return true; | 187 return true; |
188 } | 188 } |
189 | 189 |
190 void GPUTrace::Process() { | 190 void GPUTrace::Process() { |
191 if (tracer_type_ == kTracerTypeInvalid) | 191 if (tracer_type_ == kTracerTypeInvalid) |
192 return; | 192 return; |
193 | 193 |
(...skipping 28 matching lines...) Expand all Loading... | |
222 } | 222 } |
223 | 223 |
224 GPUTracer::~GPUTracer() { | 224 GPUTracer::~GPUTracer() { |
225 } | 225 } |
226 | 226 |
227 bool GPUTracer::BeginDecoding() { | 227 bool GPUTracer::BeginDecoding() { |
228 if (gpu_executing_) | 228 if (gpu_executing_) |
229 return false; | 229 return false; |
230 | 230 |
231 if (outputter_ == NULL) { | 231 if (outputter_ == NULL) { |
232 tracer_type_ = DetermineTracerType(); | 232 tracer_type_ = DetermineTracerType(decoder_); |
233 const char* tracer_type_name = "Unknown"; | 233 const char* tracer_type_name = "Unknown"; |
234 switch (tracer_type_) { | 234 switch (tracer_type_) { |
235 case kTracerTypeDisjointTimer: | 235 case kTracerTypeDisjointTimer: |
236 tracer_type_name = "GL_EXT_disjoint_timer_query"; | 236 tracer_type_name = "GL_EXT_disjoint_timer_query"; |
237 break; | 237 break; |
238 case kTracerTypeARBTimer: | 238 case kTracerTypeARBTimer: |
239 tracer_type_name = "GL_ARB_timer_query"; | 239 tracer_type_name = "GL_ARB_timer_query"; |
240 break; | 240 break; |
241 | 241 |
242 default: | 242 default: |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
377 } | 377 } |
378 | 378 |
379 scoped_refptr<Outputter> GPUTracer::CreateOutputter(const std::string& name) { | 379 scoped_refptr<Outputter> GPUTracer::CreateOutputter(const std::string& name) { |
380 return TraceOutputter::Create(name); | 380 return TraceOutputter::Create(name); |
381 } | 381 } |
382 | 382 |
383 scoped_refptr<CPUTime> GPUTracer::CreateCPUTime() { | 383 scoped_refptr<CPUTime> GPUTracer::CreateCPUTime() { |
384 return new CPUTime(); | 384 return new CPUTime(); |
385 } | 385 } |
386 | 386 |
387 GpuTracerType GPUTracer::DetermineTracerType() { | 387 GpuTracerType GPUTracer::DetermineTracerType(gles2::GLES2Decoder* decoder) { |
388 if (gfx::g_driver_gl.ext.b_GL_EXT_disjoint_timer_query) { | 388 ContextGroup* context_group = decoder->GetContextGroup(); |
389 const gpu::gles2::FeatureInfo* feature_info = context_group->feature_info(); | |
390 const gfx::GLVersionInfo& version_info = feature_info->gl_version_info(); | |
391 | |
392 if (version_info.is_es3 && | |
393 gfx::g_driver_gl.ext.b_GL_EXT_disjoint_timer_query) { | |
389 return kTracerTypeDisjointTimer; | 394 return kTracerTypeDisjointTimer; |
390 } else if (gfx::g_driver_gl.ext.b_GL_ARB_timer_query) { | 395 } else if (gfx::g_driver_gl.ext.b_GL_ARB_timer_query) { |
391 return kTracerTypeARBTimer; | 396 return kTracerTypeARBTimer; |
392 } | 397 } |
393 | 398 |
394 return kTracerTypeInvalid; | 399 return kTracerTypeInvalid; |
395 } | 400 } |
396 | 401 |
397 void GPUTracer::PostTask() { | 402 void GPUTracer::PostTask() { |
398 base::MessageLoop::current()->PostDelayedTask( | 403 base::MessageLoop::current()->PostDelayedTask( |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
440 if (err != GL_NO_ERROR) | 445 if (err != GL_NO_ERROR) |
441 traces_.clear(); | 446 traces_.clear(); |
442 } | 447 } |
443 | 448 |
444 void GPUTracer::CalculateTimerOffset() { | 449 void GPUTracer::CalculateTimerOffset() { |
445 if (tracer_type_ != kTracerTypeInvalid) { | 450 if (tracer_type_ != kTracerTypeInvalid) { |
446 if (*gpu_trace_dev_category == '\0') { | 451 if (*gpu_trace_dev_category == '\0') { |
447 // If GPU device category is off, invalidate timing sync. | 452 // If GPU device category is off, invalidate timing sync. |
448 gpu_timing_synced_ = false; | 453 gpu_timing_synced_ = false; |
449 return; | 454 return; |
450 } else if (tracer_type_ == kTracerTypeDisjointTimer) { | 455 } else if (gpu_timing_synced_) { |
451 // Disjoint timers offsets should be calculated before every query. | 456 return; |
no sievers
2015/01/22 19:51:20
nit:
else if (!gpu_timing_synced_ && tracer_type
David Yen
2015/01/22 21:43:02
Done.
| |
457 } else if (tracer_type_ == kTracerTypeARBTimer) { | |
458 TRACE_EVENT0("gpu", "GPUTracer::CalculateTimerOffset"); | |
459 | |
460 // ARB Timer is written for OpenGL 3.2 which contains glGetInteger64v(). | |
461 GLint64 gl_now = 0; | |
462 glGetInteger64v(GL_TIMESTAMP, &gl_now); | |
463 timer_offset_ = cpu_time_->GetCurrentTime() - | |
464 gl_now / base::Time::kNanosecondsPerMicrosecond; | |
452 gpu_timing_synced_ = true; | 465 gpu_timing_synced_ = true; |
453 timer_offset_ = 0; | |
454 } | 466 } |
455 | |
456 if (gpu_timing_synced_) | |
457 return; | |
458 | |
459 TRACE_EVENT0("gpu", "GPUTracer::CalculateTimerOffset"); | |
460 | |
461 // NOTE(vmiura): It would be better to use glGetInteger64v, however | |
462 // it's not available everywhere. | |
463 GLuint64 gl_now = 0; | |
464 GLuint query; | |
465 | |
466 glGenQueriesARB(1, &query); | |
467 | |
468 glFinish(); | |
469 glQueryCounter(query, GL_TIMESTAMP); | |
470 glFinish(); | |
471 | |
472 glGetQueryObjectui64v(query, GL_QUERY_RESULT, &gl_now); | |
473 glDeleteQueriesARB(1, &query); | |
474 | |
475 gl_now /= base::Time::kNanosecondsPerMicrosecond; | |
476 timer_offset_ = cpu_time_->GetCurrentTime() - gl_now; | |
477 gpu_timing_synced_ = true; | |
478 } | 467 } |
479 } | 468 } |
480 | 469 |
481 void GPUTracer::IssueProcessTask() { | 470 void GPUTracer::IssueProcessTask() { |
482 if (traces_.empty() || process_posted_) | 471 if (traces_.empty() || process_posted_) |
483 return; | 472 return; |
484 | 473 |
485 process_posted_ = true; | 474 process_posted_ = true; |
486 PostTask(); | 475 PostTask(); |
487 } | 476 } |
488 | 477 |
489 } // namespace gles2 | 478 } // namespace gles2 |
490 } // namespace gpu | 479 } // namespace gpu |
OLD | NEW |