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

Side by Side Diff: gpu/command_buffer/service/gpu_timing.cc

Issue 940633004: Added disjoint context class which manages disjoints within gpu timing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added releases and DCHECK in gpu_timing Created 5 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
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 "gpu/command_buffer/service/gpu_timing.h" 5 #include "gpu/command_buffer/service/gpu_timing.h"
6 6
7 #include "base/time/time.h" 7 #include "base/time/time.h"
8 #include "ui/gl/gl_bindings.h" 8 #include "ui/gl/gl_bindings.h"
9 #include "ui/gl/gl_context.h" 9 #include "ui/gl/gl_context.h"
10 #include "ui/gl/gl_version_info.h" 10 #include "ui/gl/gl_version_info.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 *end = (end_stamp / base::Time::kNanosecondsPerMicrosecond) + offset_; 56 *end = (end_stamp / base::Time::kNanosecondsPerMicrosecond) + offset_;
57 } 57 }
58 58
59 int64 GPUTimer::GetDeltaElapsed() { 59 int64 GPUTimer::GetDeltaElapsed() {
60 int64 start = 0; 60 int64 start = 0;
61 int64 end = 0; 61 int64 end = 0;
62 GetStartEndTimestamps(&start, &end); 62 GetStartEndTimestamps(&start, &end);
63 return end - start; 63 return end - start;
64 } 64 }
65 65
66 GPUTiming::GPUTiming() : cpu_time_for_testing_() { 66 GPUTiming::GPUTiming(gfx::GLContext* gl_context) {
67 Initialize(gl_context);
Daniele Castagna 2015/02/23 22:21:19 Why do you initialize the object here? gl_context
67 } 68 }
68 69
69 GPUTiming::~GPUTiming() { 70 GPUTiming::~GPUTiming() {
71 DCHECK(GetDisjointContextIDCount() == 0);
70 } 72 }
71 73
72 bool GPUTiming::Initialize(gfx::GLContext* gl_context) { 74 void GPUTiming::Initialize(gfx::GLContext* gl_context) {
Daniele Castagna 2015/02/23 22:21:19 Who's suppose to call this function? You call it f
73 DCHECK(gl_context); 75 timer_type_ = kTimerTypeInvalid;
74 DCHECK_EQ(kTimerTypeInvalid, timer_type_); 76 offset_ = 0; // offset cache when timer_type_ == kTimerTypeARB
77 offset_valid_ = false;
78 disjoint_occurred_ = false;
79 disjoint_contexts_.clear();
80 cpu_time_for_testing_.Reset();
75 81
76 const gfx::GLVersionInfo* version_info = gl_context->GetVersionInfo(); 82 if (gl_context) {
77 DCHECK(version_info); 83 const gfx::GLVersionInfo* version_info = gl_context->GetVersionInfo();
78 if (version_info->is_es3 && // glGetInteger64v is supported under ES3. 84 DCHECK(version_info);
79 gfx::g_driver_gl.ext.b_GL_EXT_disjoint_timer_query) { 85
80 timer_type_ = kTimerTypeDisjoint; 86 timer_type_ = kTimerTypeInvalid;
81 return true; 87 if (version_info->is_es3 && // glGetInteger64v is supported under ES3.
82 } else if (gfx::g_driver_gl.ext.b_GL_ARB_timer_query) { 88 gfx::g_driver_gl.ext.b_GL_EXT_disjoint_timer_query) {
83 timer_type_ = kTimerTypeARB; 89 timer_type_ = kTimerTypeDisjoint;
84 return true; 90 } else if (gfx::g_driver_gl.ext.b_GL_ARB_timer_query) {
91 timer_type_ = kTimerTypeARB;
92 }
85 } 93 }
86 return false;
87 } 94 }
88 95
89 bool GPUTiming::IsAvailable() { 96 bool GPUTiming::IsAvailable() {
90 return timer_type_ != kTimerTypeInvalid; 97 return timer_type_ != kTimerTypeInvalid;
91 } 98 }
92 99
100 int GPUTiming::CreateDisjointContextID() {
101 const int num_contexts = static_cast<int>(disjoint_contexts_.size());
102 for (int i = 0; i < num_contexts; ++i) {
Daniele Castagna 2015/02/23 22:21:19 What about using std::find_if?
103 DisjointContext& context = disjoint_contexts_[i];
104 if (!context.valid_) {
105 context.valid_ = true;
106 context.disjoint_value_ = disjoint_occurred_;
107 return i;
108 }
109 }
110 disjoint_contexts_.push_back(DisjointContext(disjoint_occurred_));
111 return num_contexts;
112 }
113
114 bool GPUTiming::ReleaseDisjointContextID(int disjoint_context_id) {
Daniele Castagna 2015/02/23 22:21:19 Could you test this in your test?
115 if (disjoint_context_id >= 0 &&
116 disjoint_context_id < static_cast<int>(disjoint_contexts_.size()) &&
117 disjoint_contexts_[disjoint_context_id].valid_) {
118 disjoint_contexts_[disjoint_context_id].valid_ = false;
119 return true;
120 }
121 return false;
122 }
123
124 int GPUTiming::GetDisjointContextIDCount() const {
125 int count = 0;
Daniele Castagna 2015/02/23 22:21:19 std::count_if?
126 for (const DisjointContext& context : disjoint_contexts_) {
127 if (context.disjoint_value_) {
128 ++count;
129 }
130 }
131 return count;
132 }
133
134 bool GPUTiming::CheckAndResetTimerErrors(int disjoint_context_id) {
135 if (timer_type_ == kTimerTypeDisjoint &&
Daniele Castagna 2015/02/23 22:21:19 If the timer_type_ is disjoint, and the context_id
136 disjoint_context_id >= 0 &&
137 disjoint_context_id < static_cast<int>(disjoint_contexts_.size()) &&
138 disjoint_contexts_[disjoint_context_id].valid_) {
139 GLint disjoint_value = 0;
140 glGetIntegerv(GL_GPU_DISJOINT_EXT, &disjoint_value);
141 if (disjoint_value != 0) {
142 disjoint_occurred_ = true;
143 for (DisjointContext& context : disjoint_contexts_) {
144 context.disjoint_value_ = true;
145 }
146 }
147
148 DisjointContext& context = disjoint_contexts_[disjoint_context_id];
149 const bool prev_disjoint_value = context.disjoint_value_;
150 context.disjoint_value_ = false;
151 return prev_disjoint_value;
152 }
153 return false;
154 }
155
93 const char* GPUTiming::GetTimerTypeName() const { 156 const char* GPUTiming::GetTimerTypeName() const {
94 switch (timer_type_) { 157 switch (timer_type_) {
95 case kTimerTypeDisjoint: 158 case kTimerTypeDisjoint:
96 return "GL_EXT_disjoint_timer_query"; 159 return "GL_EXT_disjoint_timer_query";
97 case kTimerTypeARB: 160 case kTimerTypeARB:
98 return "GL_ARB_timer_query"; 161 return "GL_ARB_timer_query";
99 default: 162 default:
100 return "Unknown"; 163 return "Unknown";
101 } 164 }
102 } 165 }
103 166
104 bool GPUTiming::CheckAndResetTimerErrors() {
105 if (timer_type_ == kTimerTypeDisjoint) {
106 GLint disjoint_value = 0;
107 glGetIntegerv(GL_GPU_DISJOINT_EXT, &disjoint_value);
108 return disjoint_value != 0;
109 } else {
110 return false;
111 }
112 }
113
114 int64 GPUTiming::CalculateTimerOffset() { 167 int64 GPUTiming::CalculateTimerOffset() {
115 if (!offset_valid_) { 168 if (!offset_valid_) {
116 GLint64 gl_now = 0; 169 GLint64 gl_now = 0;
117 glGetInteger64v(GL_TIMESTAMP, &gl_now); 170 glGetInteger64v(GL_TIMESTAMP, &gl_now);
118 int64 now = 171 int64 now =
119 cpu_time_for_testing_.is_null() 172 cpu_time_for_testing_.is_null()
120 ? base::TimeTicks::NowFromSystemTraceTime().ToInternalValue() 173 ? base::TimeTicks::NowFromSystemTraceTime().ToInternalValue()
121 : cpu_time_for_testing_.Run(); 174 : cpu_time_for_testing_.Run();
122 offset_ = now - gl_now / base::Time::kNanosecondsPerMicrosecond; 175 offset_ = now - gl_now / base::Time::kNanosecondsPerMicrosecond;
123 offset_valid_ = timer_type_ == kTimerTypeARB; 176 offset_valid_ = timer_type_ == kTimerTypeARB;
124 } 177 }
125 return offset_; 178 return offset_;
126 } 179 }
127 180
128 void GPUTiming::InvalidateTimerOffset() { 181 void GPUTiming::InvalidateTimerOffset() {
129 offset_valid_ = false; 182 offset_valid_ = false;
130 } 183 }
131 184
132 void GPUTiming::SetCpuTimeForTesting( 185 void GPUTiming::SetCpuTimeForTesting(
133 const base::Callback<int64(void)>& cpu_time) { 186 const base::Callback<int64(void)>& cpu_time) {
134 cpu_time_for_testing_ = cpu_time; 187 cpu_time_for_testing_ = cpu_time;
135 } 188 }
136 189
137 void GPUTiming::SetOffsetForTesting(int64 offset, bool cache_it) {
138 offset_ = offset;
139 offset_valid_ = cache_it;
140 }
141
142 void GPUTiming::SetTimerTypeForTesting(TimerType type) {
143 timer_type_ = type;
144 }
145
146 } // namespace gpu 190 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698