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

Side by Side Diff: gpu/perftests/texture_upload_perftest.cc

Issue 893673002: gpu: Add a class MeasurementTimers that measures wall, cpu and gpu time. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« gpu/perftests/measurements.cc ('K') | « gpu/perftests/measurements.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/time/time.h" 11 #include "gpu/perftests/measurements.h"
12 #include "base/timer/elapsed_timer.h"
13 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
14 #include "testing/perf/perf_test.h"
15 #include "ui/gfx/geometry/size.h" 13 #include "ui/gfx/geometry/size.h"
16 #include "ui/gl/gl_bindings.h" 14 #include "ui/gl/gl_bindings.h"
17 #include "ui/gl/gl_context.h" 15 #include "ui/gl/gl_context.h"
18 #include "ui/gl/gl_surface.h" 16 #include "ui/gl/gl_surface.h"
19 #include "ui/gl/scoped_make_current.h" 17 #include "ui/gl/scoped_make_current.h"
20 18
21 namespace gpu { 19 namespace gpu {
22 namespace { 20 namespace {
23 21
24 const int kUploadPerfWarmupRuns = 10; 22 const int kUploadPerfWarmupRuns = 10;
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 } 144 }
147 if (vertex_buffer_ != 0) { 145 if (vertex_buffer_ != 0) {
148 glDeleteShader(vertex_buffer_); 146 glDeleteShader(vertex_buffer_);
149 } 147 }
150 148
151 gl_context_ = nullptr; 149 gl_context_ = nullptr;
152 surface_ = nullptr; 150 surface_ = nullptr;
153 } 151 }
154 152
155 protected: 153 protected:
156 struct Measurement {
157 Measurement() : name(), wall_time(){};
158 Measurement(const std::string& name, const base::TimeDelta wall_time)
159 : name(name), wall_time(wall_time){};
160 std::string name;
161 base::TimeDelta wall_time;
162 };
163 // Upload and draw on the offscren surface. 154 // Upload and draw on the offscren surface.
164 // Return a list of pair. Each pair describe a gl operation and the wall 155 // Return a list of pair. Each pair describe a gl operation and the wall
165 // time elapsed in milliseconds. 156 // time elapsed in milliseconds.
166 std::vector<Measurement> UploadAndDraw(const std::vector<uint8>& pixels, 157 std::vector<Measurement> UploadAndDraw(const std::vector<uint8>& pixels,
167 const GLenum format, 158 const GLenum format,
168 const GLenum type) { 159 const GLenum type) {
169 std::vector<Measurement> measurements;
170 ui::ScopedMakeCurrent smc(gl_context_.get(), surface_.get()); 160 ui::ScopedMakeCurrent smc(gl_context_.get(), surface_.get());
171 161
172 base::ElapsedTimer total_timer; 162 MeasurementTimers total_timers;
173 GLuint texture_id = 0; 163 GLuint texture_id = 0;
174 164
175 base::ElapsedTimer tex_timer; 165 MeasurementTimers tex_timers;
176 glActiveTexture(GL_TEXTURE0); 166 glActiveTexture(GL_TEXTURE0);
177 glGenTextures(1, &texture_id); 167 glGenTextures(1, &texture_id);
178 glBindTexture(GL_TEXTURE_2D, texture_id); 168 glBindTexture(GL_TEXTURE_2D, texture_id);
179 169
180 glTexImage2D(GL_TEXTURE_2D, 0, format, size_.width(), size_.height(), 0, 170 glTexImage2D(GL_TEXTURE_2D, 0, format, size_.width(), size_.height(), 0,
181 format, type, &pixels[0]); 171 format, type, &pixels[0]);
182 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 172 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
183 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 173 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
184 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 174 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
185 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 175 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
186 CheckNoGlError(); 176 CheckNoGlError();
187 measurements.push_back(Measurement("teximage2d", tex_timer.Elapsed())); 177 tex_timers.Record();
188 178
189 base::ElapsedTimer draw_timer; 179 MeasurementTimers draw_timers;
190 glUseProgram(program_object_); 180 glUseProgram(program_object_);
191 glUniform1i(sampler_location_, 0); 181 glUniform1i(sampler_location_, 0);
192 182
193 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer_); 183 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer_);
194 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0); 184 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
195 glEnableVertexAttribArray(0); 185 glEnableVertexAttribArray(0);
196 186
197 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 187 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
198 measurements.push_back(Measurement("drawarrays", draw_timer.Elapsed())); 188 draw_timers.Record();
199 189
200 base::ElapsedTimer finish_timer; 190 MeasurementTimers finish_timers;
201 glFinish(); 191 glFinish();
202 CheckNoGlError(); 192 CheckNoGlError();
203 measurements.push_back(Measurement("finish", finish_timer.Elapsed())); 193 finish_timers.Record();
204 measurements.push_back(Measurement("total", total_timer.Elapsed())); 194 total_timers.Record();
205 195
206 glDeleteTextures(1, &texture_id); 196 glDeleteTextures(1, &texture_id);
207 197
208 std::vector<uint8> pixels_rendered(size_.GetArea() * 4); 198 std::vector<uint8> pixels_rendered(size_.GetArea() * 4);
209 glReadPixels(0, 0, size_.width(), size_.height(), GL_RGBA, type, 199 glReadPixels(0, 0, size_.width(), size_.height(), GL_RGBA, type,
210 &pixels_rendered[0]); 200 &pixels_rendered[0]);
211 CheckNoGlError(); 201 CheckNoGlError();
212 202
213 // TODO(dcastagna): don't assume the format of the texture and do 203 // TODO(dcastagna): don't assume the format of the texture and do
214 // the appropriate format conversion. 204 // the appropriate format conversion.
215 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), format); 205 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), format);
216 EXPECT_EQ(pixels, pixels_rendered); 206 EXPECT_EQ(pixels, pixels_rendered);
207
208 std::vector<Measurement> measurements;
209 measurements.push_back(total_timers.GetAsMeasurement("total"));
210 measurements.push_back(tex_timers.GetAsMeasurement("teximage2d"));
211 measurements.push_back(draw_timers.GetAsMeasurement("drawarrays"));
212 measurements.push_back(finish_timers.GetAsMeasurement("finish"));
217 return measurements; 213 return measurements;
218 } 214 }
219 215
220 const gfx::Size size_; // for the offscreen surface and the texture 216 const gfx::Size size_; // for the offscreen surface and the texture
221 scoped_refptr<gfx::GLContext> gl_context_; 217 scoped_refptr<gfx::GLContext> gl_context_;
222 scoped_refptr<gfx::GLSurface> surface_; 218 scoped_refptr<gfx::GLSurface> surface_;
223 219
224 GLuint vertex_shader_ = 0; 220 GLuint vertex_shader_ = 0;
225 GLuint fragment_shader_ = 0; 221 GLuint fragment_shader_ = 0;
226 GLuint program_object_ = 0; 222 GLuint program_object_ = 0;
227 GLint sampler_location_ = -1; 223 GLint sampler_location_ = -1;
228 GLuint vertex_buffer_ = 0; 224 GLuint vertex_buffer_ = 0;
229 }; 225 };
230 226
231 // Perf test that generates, uploads and draws a texture on a surface repeatedly 227 // Perf test that generates, uploads and draws a texture on a surface repeatedly
232 // and prints out aggregated measurements for all the runs. 228 // and prints out aggregated measurements for all the runs.
233 TEST_F(TextureUploadPerfTest, glTexImage2d) { 229 TEST_F(TextureUploadPerfTest, glTexImage2d) {
234 std::vector<uint8> pixels; 230 std::vector<uint8> pixels;
235 base::SmallMap<std::map<std::string, Measurement>> 231 base::SmallMap<std::map<std::string, Measurement>>
236 aggregates; // indexed by name 232 aggregates; // indexed by name
237 for (int i = 0; i < kUploadPerfWarmupRuns + kUploadPerfTestRuns; ++i) { 233 for (int i = 0; i < kUploadPerfWarmupRuns + kUploadPerfTestRuns; ++i) {
238 GenerateTextureData(size_, i + 1, &pixels); 234 GenerateTextureData(size_, i + 1, &pixels);
239 auto run = UploadAndDraw(pixels, GL_RGBA, GL_UNSIGNED_BYTE); 235 auto run = UploadAndDraw(pixels, GL_RGBA, GL_UNSIGNED_BYTE);
240 if (i >= kUploadPerfWarmupRuns) { 236 if (i >= kUploadPerfWarmupRuns) {
241 for (const Measurement& m : run) { 237 for (const Measurement& m : run) {
242 auto& agg = aggregates[m.name]; 238 auto& agg = aggregates[m.name];
243 agg.name = m.name; 239 agg.name = m.name;
244 agg.wall_time += m.wall_time; 240 agg.Increment(m);
245 } 241 }
246 } 242 }
247 } 243 }
248 244
249 for (const auto& entry : aggregates) { 245 for (const auto& entry : aggregates) {
250 const auto& m = entry.second; 246 const auto m = entry.second.Divide(kUploadPerfTestRuns);
251 perf_test::PrintResult( 247 m.PrintResult();
252 m.name, "", "", (m.wall_time / kUploadPerfTestRuns).InMillisecondsF(),
253 "ms", true);
254 } 248 }
255 } 249 }
256 250
257 } // namespace 251 } // namespace
258 } // namespace gpu 252 } // namespace gpu
OLDNEW
« gpu/perftests/measurements.cc ('K') | « gpu/perftests/measurements.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698