OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 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 <algorithm> | 5 #include <algorithm> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/containers/small_map.h" | 8 #include "base/containers/small_map.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "gpu/command_buffer/service/gpu_timing.h" | |
13 #include "gpu/perftests/measurements.h" | 12 #include "gpu/perftests/measurements.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "testing/perf/perf_test.h" | 14 #include "testing/perf/perf_test.h" |
16 #include "ui/gfx/geometry/size.h" | 15 #include "ui/gfx/geometry/size.h" |
17 #include "ui/gl/gl_bindings.h" | 16 #include "ui/gl/gl_bindings.h" |
18 #include "ui/gl/gl_context.h" | 17 #include "ui/gl/gl_context.h" |
19 #include "ui/gl/gl_surface.h" | 18 #include "ui/gl/gl_surface.h" |
| 19 #include "ui/gl/gpu_timing.h" |
20 #include "ui/gl/scoped_make_current.h" | 20 #include "ui/gl/scoped_make_current.h" |
21 | 21 |
22 namespace gpu { | 22 namespace gpu { |
23 namespace { | 23 namespace { |
24 | 24 |
25 const int kUploadPerfWarmupRuns = 10; | 25 const int kUploadPerfWarmupRuns = 10; |
26 const int kUploadPerfTestRuns = 100; | 26 const int kUploadPerfTestRuns = 100; |
27 | 27 |
28 #define SHADER(Src) #Src | 28 #define SHADER(Src) #Src |
29 | 29 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 | 115 |
116 glGenFramebuffersEXT(1, &framebuffer_object_); | 116 glGenFramebuffersEXT(1, &framebuffer_object_); |
117 glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer_object_); | 117 glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer_object_); |
118 | 118 |
119 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | 119 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
120 GL_TEXTURE_2D, color_texture_, 0); | 120 GL_TEXTURE_2D, color_texture_, 0); |
121 DCHECK_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), | 121 DCHECK_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), |
122 glCheckFramebufferStatusEXT(GL_FRAMEBUFFER)); | 122 glCheckFramebufferStatusEXT(GL_FRAMEBUFFER)); |
123 | 123 |
124 glViewport(0, 0, size_.width(), size_.height()); | 124 glViewport(0, 0, size_.width(), size_.height()); |
| 125 gpu_timing_.Initialize(gl_context_.get()); |
| 126 gpu_timing_client_ = gpu_timing_.CreateGPUTimingClient(); |
125 | 127 |
126 if (gpu_timing_.Initialize(gl_context_.get())) { | 128 if (gpu_timing_client_->IsAvailable()) { |
127 LOG(INFO) << "Gpu timing initialized with timer type: " | 129 LOG(INFO) << "Gpu timing initialized with timer type: " |
128 << gpu_timing_.GetTimerTypeName(); | 130 << gpu_timing_client_->GetTimerTypeName(); |
129 gpu_timing_.CheckAndResetTimerErrors(); | 131 gpu_timing_client_->InvalidateTimerOffset(); |
130 gpu_timing_.InvalidateTimerOffset(); | |
131 } else { | 132 } else { |
132 LOG(WARNING) << "Can't initialize gpu timing"; | 133 LOG(WARNING) << "Can't initialize gpu timing"; |
133 } | 134 } |
134 // Prepare a simple program and a vertex buffer that will be | 135 // Prepare a simple program and a vertex buffer that will be |
135 // used to draw a quad on the offscreen surface. | 136 // used to draw a quad on the offscreen surface. |
136 vertex_shader_ = LoadShader(GL_VERTEX_SHADER, kVertexShader); | 137 vertex_shader_ = LoadShader(GL_VERTEX_SHADER, kVertexShader); |
137 fragment_shader_ = LoadShader(GL_FRAGMENT_SHADER, kFragmentShader); | 138 fragment_shader_ = LoadShader(GL_FRAGMENT_SHADER, kFragmentShader); |
138 program_object_ = glCreateProgram(); | 139 program_object_ = glCreateProgram(); |
139 CHECK_NE(0u, program_object_); | 140 CHECK_NE(0u, program_object_); |
140 | 141 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 // Upload and draw on the offscren surface. | 180 // Upload and draw on the offscren surface. |
180 // Return a list of pair. Each pair describe a gl operation and the wall | 181 // Return a list of pair. Each pair describe a gl operation and the wall |
181 // time elapsed in milliseconds. | 182 // time elapsed in milliseconds. |
182 std::vector<Measurement> UploadAndDraw(const std::vector<uint8>& pixels, | 183 std::vector<Measurement> UploadAndDraw(const std::vector<uint8>& pixels, |
183 const GLenum format, | 184 const GLenum format, |
184 const GLenum type) { | 185 const GLenum type) { |
185 ui::ScopedMakeCurrent smc(gl_context_.get(), surface_.get()); | 186 ui::ScopedMakeCurrent smc(gl_context_.get(), surface_.get()); |
186 DCHECK_NE(0u, framebuffer_object_); | 187 DCHECK_NE(0u, framebuffer_object_); |
187 glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer_object_); | 188 glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer_object_); |
188 | 189 |
189 MeasurementTimers total_timers(&gpu_timing_); | 190 MeasurementTimers total_timers(gpu_timing_client_.get()); |
190 GLuint texture_id = 0; | 191 GLuint texture_id = 0; |
191 | 192 |
192 MeasurementTimers tex_timers(&gpu_timing_); | 193 MeasurementTimers tex_timers(gpu_timing_client_.get()); |
193 glActiveTexture(GL_TEXTURE0); | 194 glActiveTexture(GL_TEXTURE0); |
194 glGenTextures(1, &texture_id); | 195 glGenTextures(1, &texture_id); |
195 glBindTexture(GL_TEXTURE_2D, texture_id); | 196 glBindTexture(GL_TEXTURE_2D, texture_id); |
196 | 197 |
197 glTexImage2D(GL_TEXTURE_2D, 0, format, size_.width(), size_.height(), 0, | 198 glTexImage2D(GL_TEXTURE_2D, 0, format, size_.width(), size_.height(), 0, |
198 format, type, &pixels[0]); | 199 format, type, &pixels[0]); |
199 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 200 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
200 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 201 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
201 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 202 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
202 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 203 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
203 CheckNoGlError(); | 204 CheckNoGlError(); |
204 tex_timers.Record(); | 205 tex_timers.Record(); |
205 | 206 |
206 MeasurementTimers draw_timers(&gpu_timing_); | 207 MeasurementTimers draw_timers(gpu_timing_client_.get()); |
207 glUseProgram(program_object_); | 208 glUseProgram(program_object_); |
208 glUniform1i(sampler_location_, 0); | 209 glUniform1i(sampler_location_, 0); |
209 | 210 |
210 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer_); | 211 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer_); |
211 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0); | 212 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0); |
212 glEnableVertexAttribArray(0); | 213 glEnableVertexAttribArray(0); |
213 | 214 |
214 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); | 215 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); |
215 draw_timers.Record(); | 216 draw_timers.Record(); |
216 | 217 |
217 MeasurementTimers finish_timers(&gpu_timing_); | 218 MeasurementTimers finish_timers(gpu_timing_client_.get()); |
218 glFinish(); | 219 glFinish(); |
219 CheckNoGlError(); | 220 CheckNoGlError(); |
220 finish_timers.Record(); | 221 finish_timers.Record(); |
221 total_timers.Record(); | 222 total_timers.Record(); |
222 | 223 |
223 glDeleteTextures(1, &texture_id); | 224 glDeleteTextures(1, &texture_id); |
224 | 225 |
225 std::vector<uint8> pixels_rendered(size_.GetArea() * 4); | 226 std::vector<uint8> pixels_rendered(size_.GetArea() * 4); |
226 glReadPixels(0, 0, size_.width(), size_.height(), GL_RGBA, type, | 227 glReadPixels(0, 0, size_.width(), size_.height(), GL_RGBA, type, |
227 &pixels_rendered[0]); | 228 &pixels_rendered[0]); |
228 CheckNoGlError(); | 229 CheckNoGlError(); |
229 | 230 |
230 // TODO(dcastagna): don't assume the format of the texture and do | 231 // TODO(dcastagna): don't assume the format of the texture and do |
231 // the appropriate format conversion. | 232 // the appropriate format conversion. |
232 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), format); | 233 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), format); |
233 EXPECT_EQ(pixels, pixels_rendered); | 234 EXPECT_EQ(pixels, pixels_rendered); |
234 | 235 |
235 std::vector<Measurement> measurements; | 236 std::vector<Measurement> measurements; |
236 bool gpu_timer_errors = | 237 bool gpu_timer_errors = |
237 gpu_timing_.IsAvailable() && gpu_timing_.CheckAndResetTimerErrors(); | 238 gpu_timing_client_->IsAvailable() && |
| 239 gpu_timing_client_->CheckAndResetTimerErrors(); |
238 if (!gpu_timer_errors) { | 240 if (!gpu_timer_errors) { |
239 measurements.push_back(total_timers.GetAsMeasurement("total")); | 241 measurements.push_back(total_timers.GetAsMeasurement("total")); |
240 measurements.push_back(tex_timers.GetAsMeasurement("teximage2d")); | 242 measurements.push_back(tex_timers.GetAsMeasurement("teximage2d")); |
241 measurements.push_back(draw_timers.GetAsMeasurement("drawarrays")); | 243 measurements.push_back(draw_timers.GetAsMeasurement("drawarrays")); |
242 measurements.push_back(finish_timers.GetAsMeasurement("finish")); | 244 measurements.push_back(finish_timers.GetAsMeasurement("finish")); |
243 } | 245 } |
244 return measurements; | 246 return measurements; |
245 } | 247 } |
246 | 248 |
247 const gfx::Size size_; // for the fbo and the texture | 249 const gfx::Size size_; // for the fbo and the texture |
248 scoped_refptr<gfx::GLContext> gl_context_; | 250 scoped_refptr<gfx::GLContext> gl_context_; |
249 scoped_refptr<gfx::GLSurface> surface_; | 251 scoped_refptr<gfx::GLSurface> surface_; |
250 GPUTiming gpu_timing_; | 252 GPUTiming gpu_timing_; |
| 253 scoped_refptr<GPUTimingClient> gpu_timing_client_; |
251 | 254 |
252 GLuint color_texture_ = 0; | 255 GLuint color_texture_ = 0; |
253 GLuint framebuffer_object_ = 0; | 256 GLuint framebuffer_object_ = 0; |
254 GLuint vertex_shader_ = 0; | 257 GLuint vertex_shader_ = 0; |
255 GLuint fragment_shader_ = 0; | 258 GLuint fragment_shader_ = 0; |
256 GLuint program_object_ = 0; | 259 GLuint program_object_ = 0; |
257 GLint sampler_location_ = -1; | 260 GLint sampler_location_ = -1; |
258 GLuint vertex_buffer_ = 0; | 261 GLuint vertex_buffer_ = 0; |
259 }; | 262 }; |
260 | 263 |
(...skipping 23 matching lines...) Expand all Loading... |
284 const auto m = entry.second.Divide(successful_runs); | 287 const auto m = entry.second.Divide(successful_runs); |
285 m.PrintResult(); | 288 m.PrintResult(); |
286 } | 289 } |
287 } | 290 } |
288 perf_test::PrintResult("sample_runs", "", "", | 291 perf_test::PrintResult("sample_runs", "", "", |
289 static_cast<size_t>(successful_runs), "laps", true); | 292 static_cast<size_t>(successful_runs), "laps", true); |
290 } | 293 } |
291 | 294 |
292 } // namespace | 295 } // namespace |
293 } // namespace gpu | 296 } // namespace gpu |
OLD | NEW |