Chromium Code Reviews| 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" | 12 #include "gpu/command_buffer/service/gpu_timing.h" |
| 13 #include "gpu/perftests/measurements.h" | 13 #include "gpu/perftests/measurements.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "testing/perf/perf_test.h" | |
| 15 #include "ui/gfx/geometry/size.h" | 16 #include "ui/gfx/geometry/size.h" |
| 16 #include "ui/gl/gl_bindings.h" | 17 #include "ui/gl/gl_bindings.h" |
| 17 #include "ui/gl/gl_context.h" | 18 #include "ui/gl/gl_context.h" |
| 18 #include "ui/gl/gl_surface.h" | 19 #include "ui/gl/gl_surface.h" |
| 19 #include "ui/gl/scoped_make_current.h" | 20 #include "ui/gl/scoped_make_current.h" |
| 20 | 21 |
| 21 namespace gpu { | 22 namespace gpu { |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 const int kUploadPerfWarmupRuns = 10; | 25 const int kUploadPerfWarmupRuns = 10; |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 glReadPixels(0, 0, size_.width(), size_.height(), GL_RGBA, type, | 226 glReadPixels(0, 0, size_.width(), size_.height(), GL_RGBA, type, |
| 226 &pixels_rendered[0]); | 227 &pixels_rendered[0]); |
| 227 CheckNoGlError(); | 228 CheckNoGlError(); |
| 228 | 229 |
| 229 // TODO(dcastagna): don't assume the format of the texture and do | 230 // TODO(dcastagna): don't assume the format of the texture and do |
| 230 // the appropriate format conversion. | 231 // the appropriate format conversion. |
| 231 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), format); | 232 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), format); |
| 232 EXPECT_EQ(pixels, pixels_rendered); | 233 EXPECT_EQ(pixels, pixels_rendered); |
| 233 | 234 |
| 234 std::vector<Measurement> measurements; | 235 std::vector<Measurement> measurements; |
| 235 measurements.push_back(total_timers.GetAsMeasurement("total")); | 236 bool gpu_timer_errors = |
| 236 measurements.push_back(tex_timers.GetAsMeasurement("teximage2d")); | 237 gpu_timing_.IsAvailable() && gpu_timing_.CheckAndResetTimerErrors(); |
| 237 measurements.push_back(draw_timers.GetAsMeasurement("drawarrays")); | 238 if (!gpu_timer_errors) { |
| 238 measurements.push_back(finish_timers.GetAsMeasurement("finish")); | 239 measurements.push_back(total_timers.GetAsMeasurement("total")); |
| 240 measurements.push_back(tex_timers.GetAsMeasurement("teximage2d")); | |
| 241 measurements.push_back(draw_timers.GetAsMeasurement("drawarrays")); | |
| 242 measurements.push_back(finish_timers.GetAsMeasurement("finish")); | |
| 243 } | |
| 239 return measurements; | 244 return measurements; |
| 240 } | 245 } |
| 241 | 246 |
| 242 const gfx::Size size_; // for the fbo and the texture | 247 const gfx::Size size_; // for the fbo and the texture |
| 243 scoped_refptr<gfx::GLContext> gl_context_; | 248 scoped_refptr<gfx::GLContext> gl_context_; |
| 244 scoped_refptr<gfx::GLSurface> surface_; | 249 scoped_refptr<gfx::GLSurface> surface_; |
| 245 GPUTiming gpu_timing_; | 250 GPUTiming gpu_timing_; |
| 246 | 251 |
| 247 GLuint color_texture_ = 0; | 252 GLuint color_texture_ = 0; |
| 248 GLuint framebuffer_object_ = 0; | 253 GLuint framebuffer_object_ = 0; |
| 249 GLuint vertex_shader_ = 0; | 254 GLuint vertex_shader_ = 0; |
| 250 GLuint fragment_shader_ = 0; | 255 GLuint fragment_shader_ = 0; |
| 251 GLuint program_object_ = 0; | 256 GLuint program_object_ = 0; |
| 252 GLint sampler_location_ = -1; | 257 GLint sampler_location_ = -1; |
| 253 GLuint vertex_buffer_ = 0; | 258 GLuint vertex_buffer_ = 0; |
| 254 }; | 259 }; |
| 255 | 260 |
| 256 // Perf test that generates, uploads and draws a texture on a surface repeatedly | 261 // Perf test that generates, uploads and draws a texture on a surface repeatedly |
| 257 // and prints out aggregated measurements for all the runs. | 262 // and prints out aggregated measurements for all the runs. |
| 258 TEST_F(TextureUploadPerfTest, glTexImage2d) { | 263 TEST_F(TextureUploadPerfTest, glTexImage2d) { |
| 259 std::vector<uint8> pixels; | 264 std::vector<uint8> pixels; |
| 260 base::SmallMap<std::map<std::string, Measurement>> | 265 base::SmallMap<std::map<std::string, Measurement>> |
| 261 aggregates; // indexed by name | 266 aggregates; // indexed by name |
| 267 size_t successful_runs = 0; | |
| 262 for (int i = 0; i < kUploadPerfWarmupRuns + kUploadPerfTestRuns; ++i) { | 268 for (int i = 0; i < kUploadPerfWarmupRuns + kUploadPerfTestRuns; ++i) { |
| 263 GenerateTextureData(size_, i + 1, &pixels); | 269 GenerateTextureData(size_, i + 1, &pixels); |
| 264 auto run = UploadAndDraw(pixels, GL_RGBA, GL_UNSIGNED_BYTE); | 270 auto run = UploadAndDraw(pixels, GL_RGBA, GL_UNSIGNED_BYTE); |
| 265 if (i >= kUploadPerfWarmupRuns) { | 271 if (i >= kUploadPerfWarmupRuns) { |
|
reveman
2015/02/23 16:48:29
nit: maybe "if (i < kUpload...) continue" to reduc
Daniele Castagna
2015/02/23 16:59:25
Done.
| |
| 266 for (const Measurement& m : run) { | 272 if (run.size() > 0) { |
|
reveman
2015/02/23 16:48:29
Nit: if (!run.size()) continue;
Daniele Castagna
2015/02/23 16:59:26
I moved this with the previous check.
Done.
| |
| 267 auto& agg = aggregates[m.name]; | 273 successful_runs++; |
| 268 agg.name = m.name; | 274 for (const Measurement& m : run) { |
|
reveman
2015/02/23 16:48:29
nit: s/m/measurement/
Daniele Castagna
2015/02/23 16:59:25
Done.
| |
| 269 agg.Increment(m); | 275 auto& agg = aggregates[m.name]; |
|
reveman
2015/02/23 16:48:29
nit: s/agg/aggregate/
Daniele Castagna
2015/02/23 16:59:26
Done.
| |
| 276 agg.name = m.name; | |
| 277 agg.Increment(m); | |
| 278 } | |
| 270 } | 279 } |
| 271 } | 280 } |
| 272 } | 281 } |
| 273 | 282 |
| 274 for (const auto& entry : aggregates) { | 283 for (const auto& entry : aggregates) { |
| 275 const auto m = entry.second.Divide(kUploadPerfTestRuns); | 284 const auto m = entry.second.Divide(successful_runs); |
| 276 m.PrintResult(); | 285 m.PrintResult(); |
| 277 } | 286 } |
| 287 perf_test::PrintResult("sample_runs", "", "", successful_runs, "laps", true); | |
| 278 } | 288 } |
| 279 | 289 |
| 280 } // namespace | 290 } // namespace |
| 281 } // namespace gpu | 291 } // namespace gpu |
| OLD | NEW |