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

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: Increased fake CPU time in unittest to be greater than 1ms 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 | ui/gl/gpu_timing_unittest.cc » ('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) 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 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
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);
345 int64_t micro_now = NanoToMicro(gl_now); 345 const int64_t cpu_time = GetCurrentCPUTime();
346 offset_ = GetCurrentCPUTime() - micro_now; 346 const int64_t micro_offset = cpu_time - NanoToMicro(gl_now);
347 offset_valid_ = (timer_type_ == GPUTiming::kTimerTypeARB); 347
348 // We cannot expect these instructions to run with the accuracy
349 // within 1 microsecond, instead discard differences which are less
350 // than a single millisecond.
351 base::TimeDelta delta =
352 base::TimeDelta::FromMicroseconds(micro_offset - offset_);
353
354 if (delta.magnitude().InMilliseconds() >= 1) {
355 offset_ = micro_offset;
356 offset_valid_ = (timer_type_ == GPUTiming::kTimerTypeARB);
357 }
348 } else { 358 } else {
349 offset_ = 0; 359 offset_ = 0;
350 offset_valid_ = true; 360 offset_valid_ = true;
351 } 361 }
352 } 362 }
353 return offset_; 363 return offset_;
354 } 364 }
355 365
356 scoped_refptr<QueryResult> GPUTimingImpl::BeginElapsedTimeQuery() { 366 scoped_refptr<QueryResult> GPUTimingImpl::BeginElapsedTimeQuery() {
357 DCHECK(timer_type_ != GPUTiming::kTimerTypeInvalid); 367 DCHECK(timer_type_ != GPUTiming::kTimerTypeInvalid);
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 635
626 void GPUTimingClient::ForceTimeElapsedQuery() { 636 void GPUTimingClient::ForceTimeElapsedQuery() {
627 DCHECK(gpu_timing_); 637 DCHECK(gpu_timing_);
628 gpu_timing_->ForceTimeElapsedQuery(); 638 gpu_timing_->ForceTimeElapsedQuery();
629 } 639 }
630 640
631 GPUTimingClient::~GPUTimingClient() { 641 GPUTimingClient::~GPUTimingClient() {
632 } 642 }
633 643
634 } // namespace gfx 644 } // namespace gfx
OLDNEW
« no previous file with comments | « no previous file | ui/gl/gpu_timing_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698