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

Side by Side Diff: ui/gl/gpu_timing.cc

Issue 1647333002: Fix GPUTiming offset so it is stable within significant digits. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « no previous file | no next file » | 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) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 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 "ui/gl/gpu_timing.h" 5 #include "ui/gl/gpu_timing.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 #include "ui/gl/gl_bindings.h" 9 #include "ui/gl/gl_bindings.h"
10 #include "ui/gl/gl_context.h" 10 #include "ui/gl/gl_context.h"
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 } 334 }
335 } 335 }
336 return disjoint_counter_; 336 return disjoint_counter_;
337 } 337 }
338 338
339 int64_t GPUTimingImpl::CalculateTimerOffset() { 339 int64_t GPUTimingImpl::CalculateTimerOffset() {
340 if (!offset_valid_) { 340 if (!offset_valid_) {
341 if (timer_type_ == GPUTiming::kTimerTypeDisjoint || 341 if (timer_type_ == GPUTiming::kTimerTypeDisjoint ||
342 timer_type_ == GPUTiming::kTimerTypeARB) { 342 timer_type_ == GPUTiming::kTimerTypeARB) {
343 GLint64 gl_now = 0; 343 GLint64 gl_now = 0;
344 glGetInteger64v(GL_TIMESTAMP, &gl_now); 344 glGetInteger64v(GL_TIMESTAMP, &gl_now);
Ken Russell (switch to Gerrit) 2016/01/29 22:54:31 I've recently learned that this query returns 0 on
David Yen 2016/01/30 02:14:11 So this would only apply to the core profile (comp
345 int64_t micro_now = NanoToMicro(gl_now); 345 const int64_t cpu_time = GetCurrentCPUTime();
346 offset_ = GetCurrentCPUTime() - micro_now; 346
347 offset_valid_ = (timer_type_ == GPUTiming::kTimerTypeARB); 347 const int64_t micro_offset = cpu_time - NanoToMicro(gl_now);
348
349 // We cannot expect these instructions to run with the accuracy
350 // within 1 microsecond, round down to nearest milliseconds instead and
351 // only update if the difference is larger than 1 millisecond.
352 const int64_t rounded_offset =
353 (micro_offset / base::Time::kMicrosecondsPerMillisecond) *
354 base::Time::kMicrosecondsPerMillisecond;
Ken Russell (switch to Gerrit) 2016/01/29 22:54:31 Is there any way to use base::Time to do this roun
David Yen 2016/01/30 02:14:11 Done. This is much better now thank you.
355
356 const int64_t diff = rounded_offset - offset_;
357 const int64_t abs_diff = (diff < 0) ? -diff : diff;
358
359 if (abs_diff > 1) {
360 offset_ = rounded_offset;
361 offset_valid_ = (timer_type_ == GPUTiming::kTimerTypeARB);
362 }
348 } else { 363 } else {
349 offset_ = 0; 364 offset_ = 0;
350 offset_valid_ = true; 365 offset_valid_ = true;
351 } 366 }
352 } 367 }
353 return offset_; 368 return offset_;
354 } 369 }
355 370
356 scoped_refptr<QueryResult> GPUTimingImpl::BeginElapsedTimeQuery() { 371 scoped_refptr<QueryResult> GPUTimingImpl::BeginElapsedTimeQuery() {
357 DCHECK(timer_type_ != GPUTiming::kTimerTypeInvalid); 372 DCHECK(timer_type_ != GPUTiming::kTimerTypeInvalid);
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 640
626 void GPUTimingClient::ForceTimeElapsedQuery() { 641 void GPUTimingClient::ForceTimeElapsedQuery() {
627 DCHECK(gpu_timing_); 642 DCHECK(gpu_timing_);
628 gpu_timing_->ForceTimeElapsedQuery(); 643 gpu_timing_->ForceTimeElapsedQuery();
629 } 644 }
630 645
631 GPUTimingClient::~GPUTimingClient() { 646 GPUTimingClient::~GPUTimingClient() {
632 } 647 }
633 648
634 } // namespace gfx 649 } // namespace gfx
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698