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

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

Issue 937263006: Refactored GLContext to own GPUTiming which spawn GPUTimingClients. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added GPUTiming descriptions for all 3 classes, refptr in GPUTimer 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
« no previous file with comments | « gpu/perftests/measurements.cc ('k') | ui/gl/BUILD.gn » ('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 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 "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "gpu/command_buffer/service/gpu_timing.h"
14 #include "gpu/perftests/measurements.h" 13 #include "gpu/perftests/measurements.h"
15 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
16 #include "testing/perf/perf_test.h" 15 #include "testing/perf/perf_test.h"
17 #include "ui/gfx/geometry/size.h" 16 #include "ui/gfx/geometry/size.h"
18 #include "ui/gl/gl_bindings.h" 17 #include "ui/gl/gl_bindings.h"
19 #include "ui/gl/gl_context.h" 18 #include "ui/gl/gl_context.h"
20 #include "ui/gl/gl_surface.h" 19 #include "ui/gl/gl_surface.h"
20 #include "ui/gl/gpu_timing.h"
21 #include "ui/gl/scoped_make_current.h" 21 #include "ui/gl/scoped_make_current.h"
22 22
23 namespace gpu { 23 namespace gpu {
24 namespace { 24 namespace {
25 25
26 const int kUploadPerfWarmupRuns = 10; 26 const int kUploadPerfWarmupRuns = 10;
27 const int kUploadPerfTestRuns = 100; 27 const int kUploadPerfTestRuns = 100;
28 28
29 #define SHADER(Src) #Src 29 #define SHADER(Src) #Src
30 30
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 117
118 glGenFramebuffersEXT(1, &framebuffer_object_); 118 glGenFramebuffersEXT(1, &framebuffer_object_);
119 glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer_object_); 119 glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer_object_);
120 120
121 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, 121 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
122 GL_TEXTURE_2D, color_texture_, 0); 122 GL_TEXTURE_2D, color_texture_, 0);
123 DCHECK_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), 123 DCHECK_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
124 glCheckFramebufferStatusEXT(GL_FRAMEBUFFER)); 124 glCheckFramebufferStatusEXT(GL_FRAMEBUFFER));
125 125
126 glViewport(0, 0, fbo_size_.width(), fbo_size_.height()); 126 glViewport(0, 0, fbo_size_.width(), fbo_size_.height());
127 gpu_timing_client_ = gl_context_->CreateGPUTimingClient();
127 128
128 if (gpu_timing_.Initialize(gl_context_.get())) { 129 if (gpu_timing_client_->IsAvailable()) {
129 LOG(INFO) << "Gpu timing initialized with timer type: " 130 LOG(INFO) << "Gpu timing initialized with timer type: "
130 << gpu_timing_.GetTimerTypeName(); 131 << gpu_timing_client_->GetTimerTypeName();
131 gpu_timing_.CheckAndResetTimerErrors(); 132 gpu_timing_client_->InvalidateTimerOffset();
132 gpu_timing_.InvalidateTimerOffset();
133 } else { 133 } else {
134 LOG(WARNING) << "Can't initialize gpu timing"; 134 LOG(WARNING) << "Can't initialize gpu timing";
135 } 135 }
136 // Prepare a simple program and a vertex buffer that will be 136 // Prepare a simple program and a vertex buffer that will be
137 // used to draw a quad on the offscreen surface. 137 // used to draw a quad on the offscreen surface.
138 vertex_shader_ = LoadShader(GL_VERTEX_SHADER, kVertexShader); 138 vertex_shader_ = LoadShader(GL_VERTEX_SHADER, kVertexShader);
139 fragment_shader_ = LoadShader(GL_FRAGMENT_SHADER, kFragmentShader); 139 fragment_shader_ = LoadShader(GL_FRAGMENT_SHADER, kFragmentShader);
140 program_object_ = glCreateProgram(); 140 program_object_ = glCreateProgram();
141 CHECK_NE(0u, program_object_); 141 CHECK_NE(0u, program_object_);
142 142
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 } 198 }
199 199
200 protected: 200 protected:
201 // Upload and draw on the offscren surface. 201 // Upload and draw on the offscren surface.
202 // Return a list of pair. Each pair describe a gl operation and the wall 202 // Return a list of pair. Each pair describe a gl operation and the wall
203 // time elapsed in milliseconds. 203 // time elapsed in milliseconds.
204 std::vector<Measurement> UploadAndDraw(const gfx::Size& size, 204 std::vector<Measurement> UploadAndDraw(const gfx::Size& size,
205 const std::vector<uint8>& pixels, 205 const std::vector<uint8>& pixels,
206 const GLenum format, 206 const GLenum format,
207 const GLenum type) { 207 const GLenum type) {
208 MeasurementTimers total_timers(&gpu_timing_); 208 MeasurementTimers total_timers(gpu_timing_client_.get());
209 GLuint texture_id = 0; 209 GLuint texture_id = 0;
210 210
211 MeasurementTimers tex_timers(&gpu_timing_); 211 MeasurementTimers tex_timers(gpu_timing_client_.get());
212 glActiveTexture(GL_TEXTURE0); 212 glActiveTexture(GL_TEXTURE0);
213 glGenTextures(1, &texture_id); 213 glGenTextures(1, &texture_id);
214 glBindTexture(GL_TEXTURE_2D, texture_id); 214 glBindTexture(GL_TEXTURE_2D, texture_id);
215 215
216 glTexImage2D(GL_TEXTURE_2D, 0, format, size.width(), size.height(), 0, 216 glTexImage2D(GL_TEXTURE_2D, 0, format, size.width(), size.height(), 0,
217 format, type, &pixels[0]); 217 format, type, &pixels[0]);
218 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 218 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
219 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 219 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
220 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 220 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
221 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 221 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
222 CheckNoGlError(); 222 CheckNoGlError();
223 tex_timers.Record(); 223 tex_timers.Record();
224 224
225 MeasurementTimers draw_timers(&gpu_timing_); 225 MeasurementTimers draw_timers(gpu_timing_client_.get());
226 glUseProgram(program_object_); 226 glUseProgram(program_object_);
227 glUniform1i(sampler_location_, 0); 227 glUniform1i(sampler_location_, 0);
228 228
229 DCHECK_NE(0u, vertex_buffer_); 229 DCHECK_NE(0u, vertex_buffer_);
230 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer_); 230 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer_);
231 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 4, 0); 231 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 4, 0);
232 glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 4, 232 glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 4,
233 reinterpret_cast<void*>(sizeof(GLfloat) * 2)); 233 reinterpret_cast<void*>(sizeof(GLfloat) * 2));
234 glEnableVertexAttribArray(0); 234 glEnableVertexAttribArray(0);
235 glEnableVertexAttribArray(1); 235 glEnableVertexAttribArray(1);
236 236
237 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 237 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
238 draw_timers.Record(); 238 draw_timers.Record();
239 239
240 MeasurementTimers finish_timers(&gpu_timing_); 240 MeasurementTimers finish_timers(gpu_timing_client_.get());
241 glFinish(); 241 glFinish();
242 CheckNoGlError(); 242 CheckNoGlError();
243 finish_timers.Record(); 243 finish_timers.Record();
244 total_timers.Record(); 244 total_timers.Record();
245 245
246 glDeleteTextures(1, &texture_id); 246 glDeleteTextures(1, &texture_id);
247 247
248 std::vector<uint8> pixels_rendered(size.GetArea() * 4); 248 std::vector<uint8> pixels_rendered(size.GetArea() * 4);
249 glReadPixels(0, 0, size.width(), size.height(), GL_RGBA, type, 249 glReadPixels(0, 0, size.width(), size.height(), GL_RGBA, type,
250 &pixels_rendered[0]); 250 &pixels_rendered[0]);
251 CheckNoGlError(); 251 CheckNoGlError();
252 252
253 // TODO(dcastagna): don't assume the format of the texture and do 253 // TODO(dcastagna): don't assume the format of the texture and do
254 // the appropriate format conversion. 254 // the appropriate format conversion.
255 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), format); 255 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), format);
256 EXPECT_EQ(pixels, pixels_rendered); 256 EXPECT_EQ(pixels, pixels_rendered);
257 257
258 std::vector<Measurement> measurements; 258 std::vector<Measurement> measurements;
259 bool gpu_timer_errors = 259 bool gpu_timer_errors =
260 gpu_timing_.IsAvailable() && gpu_timing_.CheckAndResetTimerErrors(); 260 gpu_timing_client_->IsAvailable() &&
261 gpu_timing_client_->CheckAndResetTimerErrors();
261 if (!gpu_timer_errors) { 262 if (!gpu_timer_errors) {
262 measurements.push_back(total_timers.GetAsMeasurement("total")); 263 measurements.push_back(total_timers.GetAsMeasurement("total"));
263 measurements.push_back(tex_timers.GetAsMeasurement("teximage2d")); 264 measurements.push_back(tex_timers.GetAsMeasurement("teximage2d"));
264 measurements.push_back(draw_timers.GetAsMeasurement("drawarrays")); 265 measurements.push_back(draw_timers.GetAsMeasurement("drawarrays"));
265 measurements.push_back(finish_timers.GetAsMeasurement("finish")); 266 measurements.push_back(finish_timers.GetAsMeasurement("finish"));
266 } 267 }
267 return measurements; 268 return measurements;
268 } 269 }
269 270
270 void RunUploadAndDrawMultipleTimes(const gfx::Size& size) { 271 void RunUploadAndDrawMultipleTimes(const gfx::Size& size) {
(...skipping 20 matching lines...) Expand all
291 m.PrintResult(base::StringPrintf("_%d", size.width())); 292 m.PrintResult(base::StringPrintf("_%d", size.width()));
292 } 293 }
293 } 294 }
294 perf_test::PrintResult("sample_runs", "", "", 295 perf_test::PrintResult("sample_runs", "", "",
295 static_cast<size_t>(successful_runs), "laps", true); 296 static_cast<size_t>(successful_runs), "laps", true);
296 } 297 }
297 298
298 const gfx::Size fbo_size_; // for the fbo 299 const gfx::Size fbo_size_; // for the fbo
299 scoped_refptr<gfx::GLContext> gl_context_; 300 scoped_refptr<gfx::GLContext> gl_context_;
300 scoped_refptr<gfx::GLSurface> surface_; 301 scoped_refptr<gfx::GLSurface> surface_;
301 GPUTiming gpu_timing_; 302 scoped_refptr<gfx::GPUTimingClient> gpu_timing_client_;
302 303
303 GLuint color_texture_ = 0; 304 GLuint color_texture_ = 0;
304 GLuint framebuffer_object_ = 0; 305 GLuint framebuffer_object_ = 0;
305 GLuint vertex_shader_ = 0; 306 GLuint vertex_shader_ = 0;
306 GLuint fragment_shader_ = 0; 307 GLuint fragment_shader_ = 0;
307 GLuint program_object_ = 0; 308 GLuint program_object_ = 0;
308 GLint sampler_location_ = -1; 309 GLint sampler_location_ = -1;
309 GLuint vertex_buffer_ = 0; 310 GLuint vertex_buffer_ = 0;
310 }; 311 };
311 312
(...skipping 11 matching lines...) Expand all
323 324
324 DCHECK_NE(0u, framebuffer_object_); 325 DCHECK_NE(0u, framebuffer_object_);
325 glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer_object_); 326 glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer_object_);
326 327
327 RunUploadAndDrawMultipleTimes(size); 328 RunUploadAndDrawMultipleTimes(size);
328 } 329 }
329 } 330 }
330 331
331 } // namespace 332 } // namespace
332 } // namespace gpu 333 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/perftests/measurements.cc ('k') | ui/gl/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698