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

Unified 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, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gl/gpu_timing.cc
diff --git a/ui/gl/gpu_timing.cc b/ui/gl/gpu_timing.cc
index 8989bd55b2a71c9851e03cfba59aca989a2d4e3a..77e803838932346e7d7313a0402ce761c62bbed3 100644
--- a/ui/gl/gpu_timing.cc
+++ b/ui/gl/gpu_timing.cc
@@ -342,9 +342,24 @@ int64_t GPUTimingImpl::CalculateTimerOffset() {
timer_type_ == GPUTiming::kTimerTypeARB) {
GLint64 gl_now = 0;
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
- int64_t micro_now = NanoToMicro(gl_now);
- offset_ = GetCurrentCPUTime() - micro_now;
- offset_valid_ = (timer_type_ == GPUTiming::kTimerTypeARB);
+ const int64_t cpu_time = GetCurrentCPUTime();
+
+ const int64_t micro_offset = cpu_time - NanoToMicro(gl_now);
+
+ // We cannot expect these instructions to run with the accuracy
+ // within 1 microsecond, round down to nearest milliseconds instead and
+ // only update if the difference is larger than 1 millisecond.
+ const int64_t rounded_offset =
+ (micro_offset / base::Time::kMicrosecondsPerMillisecond) *
+ 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.
+
+ const int64_t diff = rounded_offset - offset_;
+ const int64_t abs_diff = (diff < 0) ? -diff : diff;
+
+ if (abs_diff > 1) {
+ offset_ = rounded_offset;
+ offset_valid_ = (timer_type_ == GPUTiming::kTimerTypeARB);
+ }
} else {
offset_ = 0;
offset_valid_ = true;
« 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