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

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

Issue 1022603002: gpu: Measure texture uploads with glTexSubImage2D and glTexImage2D. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reuse the same gl texture. Created 5 years, 9 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 | « no previous file | 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/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/perftests/measurements.h" 13 #include "gpu/perftests/measurements.h"
14 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "testing/perf/perf_test.h" 16 #include "testing/perf/perf_test.h"
17 #include "ui/gfx/geometry/size.h" 17 #include "ui/gfx/geometry/size.h"
18 #include "ui/gfx/geometry/vector2d_f.h" 18 #include "ui/gfx/geometry/vector2d_f.h"
19 #include "ui/gl/gl_bindings.h" 19 #include "ui/gl/gl_bindings.h"
20 #include "ui/gl/gl_context.h" 20 #include "ui/gl/gl_context.h"
21 #include "ui/gl/gl_enums.h" 21 #include "ui/gl/gl_enums.h"
22 #include "ui/gl/gl_surface.h" 22 #include "ui/gl/gl_surface.h"
23 #include "ui/gl/gl_version_info.h"
23 #include "ui/gl/gpu_timing.h" 24 #include "ui/gl/gpu_timing.h"
24 #include "ui/gl/scoped_make_current.h" 25 #include "ui/gl/scoped_make_current.h"
25 26
26 namespace gpu { 27 namespace gpu {
27 namespace { 28 namespace {
28 29
29 const int kUploadPerfWarmupRuns = 10; 30 const int kUploadPerfWarmupRuns = 5;
30 const int kUploadPerfTestRuns = 100; 31 const int kUploadPerfTestRuns = 30;
31 32
32 #define SHADER(Src) #Src 33 #define SHADER(Src) #Src
33 34
34 // clang-format off 35 // clang-format off
35 const char kVertexShader[] = 36 const char kVertexShader[] =
36 SHADER( 37 SHADER(
37 uniform vec2 translation; 38 uniform vec2 translation;
38 attribute vec2 a_position; 39 attribute vec2 a_position;
39 attribute vec2 a_texCoord; 40 attribute vec2 a_texCoord;
40 varying vec2 v_texCoord; 41 varying vec2 v_texCoord;
(...skipping 10 matching lines...) Expand all
51 const char kFragmentShader[] = 52 const char kFragmentShader[] =
52 SHADER( 53 SHADER(
53 uniform sampler2D a_texture; 54 uniform sampler2D a_texture;
54 varying vec2 v_texCoord; 55 varying vec2 v_texCoord;
55 void main() { 56 void main() {
56 gl_FragColor = texture2D(a_texture, v_texCoord); 57 gl_FragColor = texture2D(a_texture, v_texCoord);
57 } 58 }
58 ); 59 );
59 // clang-format on 60 // clang-format on
60 61
61 void CheckNoGlError() { 62 void CheckNoGlError(const std::string& msg) {
62 CHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); 63 CHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()) << " " << msg;
63 } 64 }
64 65
65 // Utility function to compile a shader from a string. 66 // Utility function to compile a shader from a string.
66 GLuint LoadShader(const GLenum type, const char* const src) { 67 GLuint LoadShader(const GLenum type, const char* const src) {
67 GLuint shader = 0; 68 GLuint shader = 0;
68 shader = glCreateShader(type); 69 shader = glCreateShader(type);
69 CHECK_NE(0u, shader); 70 CHECK_NE(0u, shader);
70 glShaderSource(shader, 1, &src, NULL); 71 glShaderSource(shader, 1, &src, NULL);
71 glCompileShader(shader); 72 glCompileShader(shader);
72 73
(...skipping 10 matching lines...) Expand all
83 } 84 }
84 CHECK_NE(0, compiled); 85 CHECK_NE(0, compiled);
85 return shader; 86 return shader;
86 } 87 }
87 88
88 int GLFormatBytePerPixel(GLenum format) { 89 int GLFormatBytePerPixel(GLenum format) {
89 DCHECK(format == GL_RGBA || format == GL_LUMINANCE || format == GL_RED_EXT); 90 DCHECK(format == GL_RGBA || format == GL_LUMINANCE || format == GL_RED_EXT);
90 return format == GL_RGBA ? 4 : 1; 91 return format == GL_RGBA ? 4 : 1;
91 } 92 }
92 93
94 GLenum GLFormatToStorageFormat(GLenum format) {
95 switch (format) {
96 case GL_RGBA:
97 return GL_RGBA8;
98 case GL_LUMINANCE:
99 return GL_LUMINANCE8;
100 case GL_RED_EXT:
101 return GL_R8;
102 default:
103 NOTREACHED();
104 }
105 return 0;
106 }
107
93 void GenerateTextureData(const gfx::Size& size, 108 void GenerateTextureData(const gfx::Size& size,
94 int bytes_per_pixel, 109 int bytes_per_pixel,
95 const int seed, 110 const int seed,
96 std::vector<uint8>* const pixels) { 111 std::vector<uint8>* const pixels) {
97 // Row bytes has to be multiple of 4 (GL_PACK_ALIGNMENT defaults to 4). 112 // Row bytes has to be multiple of 4 (GL_PACK_ALIGNMENT defaults to 4).
98 int stride = ((size.width() * bytes_per_pixel) + 3) & ~0x3; 113 int stride = ((size.width() * bytes_per_pixel) + 3) & ~0x3;
99 pixels->resize(size.height() * stride); 114 pixels->resize(size.height() * stride);
100 for (int y = 0; y < size.height(); ++y) { 115 for (int y = 0; y < size.height(); ++y) {
101 for (int x = 0; x < size.width(); ++x) { 116 for (int x = 0; x < size.width(); ++x) {
102 for (int channel = 0; channel < bytes_per_pixel; ++channel) { 117 for (int channel = 0; channel < bytes_per_pixel; ++channel) {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 235
221 glGenBuffersARB(1, &vertex_buffer_); 236 glGenBuffersARB(1, &vertex_buffer_);
222 CHECK_NE(0u, vertex_buffer_); 237 CHECK_NE(0u, vertex_buffer_);
223 DCHECK_NE(0u, vertex_buffer_); 238 DCHECK_NE(0u, vertex_buffer_);
224 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer_); 239 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer_);
225 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 4, 0); 240 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 4, 0);
226 glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 4, 241 glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 4,
227 reinterpret_cast<void*>(sizeof(GLfloat) * 2)); 242 reinterpret_cast<void*>(sizeof(GLfloat) * 2));
228 glEnableVertexAttribArray(0); 243 glEnableVertexAttribArray(0);
229 glEnableVertexAttribArray(1); 244 glEnableVertexAttribArray(1);
230 CheckNoGlError(); 245 CheckNoGlError("glEnableVertexAttribArray");
246
247 has_texture_storage_ =
248 gl_context_->GetVersionInfo()->is_es3 ||
249 gl_context_->HasExtension("GL_EXT_texture_storage") ||
250 gl_context_->HasExtension("GL_ARB_texture_storage");
231 } 251 }
232 252
233 void GenerateVertexBuffer(const gfx::Size& size) { 253 void GenerateVertexBuffer(const gfx::Size& size) {
234 DCHECK_NE(0u, vertex_buffer_); 254 DCHECK_NE(0u, vertex_buffer_);
235 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer_); 255 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer_);
236 // right and top are in clipspace 256 // right and top are in clipspace
237 float right = -1.f + 2.f * size.width() / fbo_size_.width(); 257 float right = -1.f + 2.f * size.width() / fbo_size_.width();
238 float top = -1.f + 2.f * size.height() / fbo_size_.height(); 258 float top = -1.f + 2.f * size.height() / fbo_size_.height();
239 // Four vertexes, one per line. Each vertex has two components per 259 // Four vertexes, one per line. Each vertex has two components per
240 // position and two per texcoord. 260 // position and two per texcoord.
241 // It represents a quad formed by two triangles if interpreted 261 // It represents a quad formed by two triangles if interpreted
242 // as a tristrip. 262 // as a tristrip.
243 263
244 // clang-format off 264 // clang-format off
245 GLfloat data[16] = { 265 GLfloat data[16] = {
246 -1.f, -1.f, 0.f, 0.f, 266 -1.f, -1.f, 0.f, 0.f,
247 right, -1.f, 1.f, 0.f, 267 right, -1.f, 1.f, 0.f,
248 -1.f, top, 0.f, 1.f, 268 -1.f, top, 0.f, 1.f,
249 right, top, 1.f, 1.f}; 269 right, top, 1.f, 1.f};
250 // clang-format on 270 // clang-format on
251 glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW); 271 glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);
252 CheckNoGlError(); 272 CheckNoGlError("glBufferData");
253 } 273 }
254 274
255 void TearDown() override { 275 void TearDown() override {
256 ui::ScopedMakeCurrent smc(gl_context_.get(), surface_.get()); 276 ui::ScopedMakeCurrent smc(gl_context_.get(), surface_.get());
257 glDeleteProgram(program_object_); 277 glDeleteProgram(program_object_);
258 glDeleteShader(vertex_shader_); 278 glDeleteShader(vertex_shader_);
259 glDeleteShader(fragment_shader_); 279 glDeleteShader(fragment_shader_);
260 glDeleteBuffersARB(1, &vertex_buffer_); 280 glDeleteBuffersARB(1, &vertex_buffer_);
261 281
262 glBindFramebufferEXT(GL_FRAMEBUFFER, 0); 282 glBindFramebufferEXT(GL_FRAMEBUFFER, 0);
263 glDeleteFramebuffersEXT(1, &framebuffer_object_); 283 glDeleteFramebuffersEXT(1, &framebuffer_object_);
264 glDeleteTextures(1, &color_texture_); 284 glDeleteTextures(1, &color_texture_);
265 CheckNoGlError(); 285 CheckNoGlError("glDeleteTextures");
266 286
267 gpu_timing_client_ = nullptr; 287 gpu_timing_client_ = nullptr;
268 gl_context_ = nullptr; 288 gl_context_ = nullptr;
269 surface_ = nullptr; 289 surface_ = nullptr;
270 } 290 }
271 291
272 protected: 292 protected:
273 GLuint CreateGLTexture() { 293 GLuint CreateGLTexture(const GLenum format,
294 const gfx::Size& size,
295 const bool specify_storage) {
274 GLuint texture_id = 0; 296 GLuint texture_id = 0;
275 glActiveTexture(GL_TEXTURE0); 297 glActiveTexture(GL_TEXTURE0);
276 glGenTextures(1, &texture_id); 298 glGenTextures(1, &texture_id);
277 glBindTexture(GL_TEXTURE_2D, texture_id); 299 glBindTexture(GL_TEXTURE_2D, texture_id);
300 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
301 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
302 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
303 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
304 if (specify_storage) {
305 if (has_texture_storage_) {
306 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GLFormatToStorageFormat(format),
307 size.width(), size.height());
308 CheckNoGlError("glTexStorage2DEXT");
309 } else {
310 glTexImage2D(GL_TEXTURE_2D, 0, format, size.width(), size.height(), 0,
311 format, GL_UNSIGNED_BYTE, nullptr);
312 CheckNoGlError("glTexImage2D");
313 }
314 }
278 return texture_id; 315 return texture_id;
279 } 316 }
280 317
281 void UploadTexture(GLuint texture_id, 318 void UploadTexture(GLuint texture_id,
282 const gfx::Size& size, 319 const gfx::Size& size,
283 const std::vector<uint8>& pixels, 320 const std::vector<uint8>& pixels,
284 GLenum format) { 321 GLenum format,
285 glTexImage2D(GL_TEXTURE_2D, 0, format, size.width(), size.height(), 0, 322 const bool subimage) {
286 format, GL_UNSIGNED_BYTE, &pixels[0]); 323 if (subimage) {
287 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 324 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, size.width(), size.height(),
288 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 325 format, GL_UNSIGNED_BYTE, &pixels[0]);
289 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 326 CheckNoGlError("glTexSubImage2D");
290 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 327 } else {
291 CheckNoGlError(); 328 glTexImage2D(GL_TEXTURE_2D, 0, format, size.width(), size.height(), 0,
329 format, GL_UNSIGNED_BYTE, &pixels[0]);
330 CheckNoGlError("glTexImage2D");
331 }
292 } 332 }
293 333
294 // Upload and draw on the offscren surface. 334 // Upload and draw on the offscren surface.
295 // Return a list of pair. Each pair describe a gl operation and the wall 335 // Return a list of pair. Each pair describe a gl operation and the wall
296 // time elapsed in milliseconds. 336 // time elapsed in milliseconds.
297 std::vector<Measurement> UploadAndDraw(const gfx::Size& size, 337 std::vector<Measurement> UploadAndDraw(GLuint texture_id,
338 const gfx::Size& size,
298 const std::vector<uint8>& pixels, 339 const std::vector<uint8>& pixels,
299 const GLenum format) { 340 const GLenum format,
300 GLuint texture_id = CreateGLTexture(); 341 const bool subimage) {
301 MeasurementTimers tex_timers(gpu_timing_client_.get()); 342 MeasurementTimers tex_timers(gpu_timing_client_.get());
302 UploadTexture(texture_id, size, pixels, format); 343 UploadTexture(texture_id, size, pixels, format, subimage);
303 tex_timers.Record(); 344 tex_timers.Record();
304 345
305 MeasurementTimers draw_timers(gpu_timing_client_.get()); 346 MeasurementTimers draw_timers(gpu_timing_client_.get());
306 347
307 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 348 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
308 draw_timers.Record(); 349 draw_timers.Record();
309 350
310 MeasurementTimers finish_timers(gpu_timing_client_.get()); 351 MeasurementTimers finish_timers(gpu_timing_client_.get());
311 glFinish(); 352 glFinish();
312 CheckNoGlError(); 353 CheckNoGlError("glFinish");
313 finish_timers.Record(); 354 finish_timers.Record();
314 355
315 glDeleteTextures(1, &texture_id);
316
317 std::vector<uint8> pixels_rendered(size.GetArea() * 4); 356 std::vector<uint8> pixels_rendered(size.GetArea() * 4);
318 glReadPixels(0, 0, size.width(), size.height(), GL_RGBA, GL_UNSIGNED_BYTE, 357 glReadPixels(0, 0, size.width(), size.height(), GL_RGBA, GL_UNSIGNED_BYTE,
319 &pixels_rendered[0]); 358 &pixels_rendered[0]);
320 CheckNoGlError(); 359 CheckNoGlError("glReadPixels");
321 EXPECT_TRUE( 360 EXPECT_TRUE(
322 CompareBufferToRGBABuffer(format, size, pixels, pixels_rendered)) 361 CompareBufferToRGBABuffer(format, size, pixels, pixels_rendered))
323 << "Format is: " << gfx::GLEnums::GetStringEnum(format); 362 << "Format is: " << gfx::GLEnums::GetStringEnum(format);
324 363
325 std::vector<Measurement> measurements; 364 std::vector<Measurement> measurements;
326 bool gpu_timer_errors = 365 bool gpu_timer_errors =
327 gpu_timing_client_->IsAvailable() && 366 gpu_timing_client_->IsAvailable() &&
328 gpu_timing_client_->CheckAndResetTimerErrors(); 367 gpu_timing_client_->CheckAndResetTimerErrors();
329 if (!gpu_timer_errors) { 368 if (!gpu_timer_errors) {
330 measurements.push_back(tex_timers.GetAsMeasurement("teximage2d")); 369 measurements.push_back(tex_timers.GetAsMeasurement(
370 subimage ? "texsubimage2d" : "teximage2d"));
331 measurements.push_back(draw_timers.GetAsMeasurement("drawarrays")); 371 measurements.push_back(draw_timers.GetAsMeasurement("drawarrays"));
332 measurements.push_back(finish_timers.GetAsMeasurement("finish")); 372 measurements.push_back(finish_timers.GetAsMeasurement("finish"));
333 } 373 }
334 return measurements; 374 return measurements;
335 } 375 }
336 376
337 void RunUploadAndDrawMultipleTimes(const gfx::Size& size, 377 void RunUploadAndDrawMultipleTimes(const gfx::Size& size,
338 const GLenum format) { 378 const GLenum format,
379 const bool subimage) {
339 std::vector<uint8> pixels; 380 std::vector<uint8> pixels;
340 base::SmallMap<std::map<std::string, Measurement>> 381 base::SmallMap<std::map<std::string, Measurement>>
341 aggregates; // indexed by name 382 aggregates; // indexed by name
342 int successful_runs = 0; 383 int successful_runs = 0;
384 GLuint texture_id = CreateGLTexture(format, size, subimage);
343 for (int i = 0; i < kUploadPerfWarmupRuns + kUploadPerfTestRuns; ++i) { 385 for (int i = 0; i < kUploadPerfWarmupRuns + kUploadPerfTestRuns; ++i) {
344 GenerateTextureData(size, GLFormatBytePerPixel(format), i + 1, &pixels); 386 GenerateTextureData(size, GLFormatBytePerPixel(format), i + 1, &pixels);
345 auto run = UploadAndDraw(size, pixels, format); 387 auto run = UploadAndDraw(texture_id, size, pixels, format, subimage);
346 if (i < kUploadPerfWarmupRuns || !run.size()) { 388 if (i < kUploadPerfWarmupRuns || !run.size()) {
347 continue; 389 continue;
348 } 390 }
349 successful_runs++; 391 successful_runs++;
350 for (const Measurement& measurement : run) { 392 for (const Measurement& measurement : run) {
351 auto& aggregate = aggregates[measurement.name]; 393 auto& aggregate = aggregates[measurement.name];
352 aggregate.name = measurement.name; 394 aggregate.name = measurement.name;
353 aggregate.Increment(measurement); 395 aggregate.Increment(measurement);
354 } 396 }
355 } 397 }
398 glDeleteTextures(1, &texture_id);
399
356 std::string graph_name = base::StringPrintf( 400 std::string graph_name = base::StringPrintf(
357 "%d_%s", size.width(), gfx::GLEnums::GetStringEnum(format).c_str()); 401 "%d_%s", size.width(), gfx::GLEnums::GetStringEnum(format).c_str());
402 if (subimage) {
403 graph_name += "_sub";
404 }
405
358 if (successful_runs) { 406 if (successful_runs) {
359 for (const auto& entry : aggregates) { 407 for (const auto& entry : aggregates) {
360 const auto m = entry.second.Divide(successful_runs); 408 const auto m = entry.second.Divide(successful_runs);
361 m.PrintResult(graph_name); 409 m.PrintResult(graph_name);
362 } 410 }
363 } 411 }
364 perf_test::PrintResult("sample_runs", "", graph_name, 412 perf_test::PrintResult("sample_runs", "", graph_name,
365 static_cast<size_t>(successful_runs), "laps", true); 413 static_cast<size_t>(successful_runs), "laps", true);
366 } 414 }
367 415
368 const gfx::Size fbo_size_; // for the fbo 416 const gfx::Size fbo_size_; // for the fbo
369 scoped_refptr<gfx::GLContext> gl_context_; 417 scoped_refptr<gfx::GLContext> gl_context_;
370 scoped_refptr<gfx::GLSurface> surface_; 418 scoped_refptr<gfx::GLSurface> surface_;
371 scoped_refptr<gfx::GPUTimingClient> gpu_timing_client_; 419 scoped_refptr<gfx::GPUTimingClient> gpu_timing_client_;
372 420
373 GLuint color_texture_ = 0; 421 GLuint color_texture_ = 0;
374 GLuint framebuffer_object_ = 0; 422 GLuint framebuffer_object_ = 0;
375 GLuint vertex_shader_ = 0; 423 GLuint vertex_shader_ = 0;
376 GLuint fragment_shader_ = 0; 424 GLuint fragment_shader_ = 0;
377 GLuint program_object_ = 0; 425 GLuint program_object_ = 0;
378 GLint sampler_location_ = -1; 426 GLint sampler_location_ = -1;
379 GLint translation_location_ = -1; 427 GLint translation_location_ = -1;
380 GLuint vertex_buffer_ = 0; 428 GLuint vertex_buffer_ = 0;
429
430 bool has_texture_storage_ = false;
381 }; 431 };
382 432
383 // Perf test that generates, uploads and draws a texture on a surface repeatedly 433 // Perf test that generates, uploads and draws a texture on a surface repeatedly
384 // and prints out aggregated measurements for all the runs. 434 // and prints out aggregated measurements for all the runs.
385 TEST_F(TextureUploadPerfTest, glTexImage2d) { 435 TEST_F(TextureUploadPerfTest, upload) {
386 int sizes[] = {21, 128, 256, 512, 1024}; 436 int sizes[] = {21, 128, 256, 512, 1024};
387 std::vector<GLenum> formats; 437 std::vector<GLenum> formats;
388 formats.push_back(GL_RGBA); 438 formats.push_back(GL_RGBA);
389 // Used by default for ResourceProvider::yuv_resource_format_. 439 // Used by default for ResourceProvider::yuv_resource_format_.
390 formats.push_back(GL_LUMINANCE); 440 formats.push_back(GL_LUMINANCE);
391 441
392 ui::ScopedMakeCurrent smc(gl_context_.get(), surface_.get()); 442 ui::ScopedMakeCurrent smc(gl_context_.get(), surface_.get());
393 bool has_texture_rg = gl_context_->HasExtension("GL_EXT_texture_rg") || 443 const bool has_texture_rg = gl_context_->HasExtension("GL_EXT_texture_rg") ||
394 gl_context_->HasExtension("GL_ARB_texture_rg"); 444 gl_context_->HasExtension("GL_ARB_texture_rg");
395 445
396 if (has_texture_rg) { 446 if (has_texture_rg) {
397 // Used as ResourceProvider::yuv_resource_format_ if 447 // Used as ResourceProvider::yuv_resource_format_ if
398 // {ARB,EXT}_texture_rg are available. 448 // {ARB,EXT}_texture_rg are available.
399 formats.push_back(GL_RED_EXT); 449 formats.push_back(GL_RED_EXT);
400 } 450 }
451
401 for (int side : sizes) { 452 for (int side : sizes) {
402 ASSERT_GE(fbo_size_.width(), side); 453 ASSERT_GE(fbo_size_.width(), side);
403 ASSERT_GE(fbo_size_.height(), side); 454 ASSERT_GE(fbo_size_.height(), side);
404 gfx::Size size(side, side); 455 gfx::Size size(side, side);
405 GenerateVertexBuffer(size); 456 GenerateVertexBuffer(size);
406 for (GLenum format : formats) { 457 for (GLenum format : formats) {
407 RunUploadAndDrawMultipleTimes(size, format); 458 RunUploadAndDrawMultipleTimes(size, format, true); // use glTexSubImage2D
459 RunUploadAndDrawMultipleTimes(size, format, false); // use glTexImage2D
408 } 460 }
409 } 461 }
410 } 462 }
411 463
412 // Perf test to check if the driver is doing texture renaming. 464 // Perf test to check if the driver is doing texture renaming.
413 // This test creates one GL texture_id and four different images. For 465 // This test creates one GL texture_id and four different images. For
414 // every image it uploads it using texture_id and it draws multiple 466 // every image it uploads it using texture_id and it draws multiple
415 // times. The cpu/wall time and the gpu time for all the uploads and 467 // times. The cpu/wall time and the gpu time for all the uploads and
416 // draws, but before glFinish, is computed and is printed out at the end as 468 // draws, but before glFinish, is computed and is printed out at the end as
417 // "upload_and_draw". If the gpu time is >> than the cpu/wall time we expect the 469 // "upload_and_draw". If the gpu time is >> than the cpu/wall time we expect the
418 // driver to do texture renaming: this means that while the gpu is drawing using 470 // driver to do texture renaming: this means that while the gpu is drawing using
419 // texture_id it didn't block cpu side the texture upload using the same 471 // texture_id it didn't block cpu side the texture upload using the same
420 // texture_id. 472 // texture_id.
421 TEST_F(TextureUploadPerfTest, renaming) { 473 TEST_F(TextureUploadPerfTest, renaming) {
422 gfx::Size texture_size(fbo_size_.width() / 2, fbo_size_.height() / 2); 474 gfx::Size texture_size(fbo_size_.width() / 2, fbo_size_.height() / 2);
423 475
424 std::vector<uint8> pixels[4]; 476 std::vector<uint8> pixels[4];
425 for (int i = 0; i < 4; ++i) { 477 for (int i = 0; i < 4; ++i) {
426 GenerateTextureData(texture_size, 4, i + 1, &pixels[i]); 478 GenerateTextureData(texture_size, 4, i + 1, &pixels[i]);
427 } 479 }
428 480
429 ui::ScopedMakeCurrent smc(gl_context_.get(), surface_.get()); 481 ui::ScopedMakeCurrent smc(gl_context_.get(), surface_.get());
430 GenerateVertexBuffer(texture_size); 482 GenerateVertexBuffer(texture_size);
431 483
432 gfx::Vector2dF positions[] = {gfx::Vector2dF(0.f, 0.f), 484 gfx::Vector2dF positions[] = {gfx::Vector2dF(0.f, 0.f),
433 gfx::Vector2dF(1.f, 0.f), 485 gfx::Vector2dF(1.f, 0.f),
434 gfx::Vector2dF(0.f, 1.f), 486 gfx::Vector2dF(0.f, 1.f),
435 gfx::Vector2dF(1.f, 1.f)}; 487 gfx::Vector2dF(1.f, 1.f)};
436 GLuint texture_id = CreateGLTexture(); 488 GLuint texture_id = CreateGLTexture(GL_RGBA, texture_size, true);
437 489
438 MeasurementTimers upload_and_draw_timers(gpu_timing_client_.get()); 490 MeasurementTimers upload_and_draw_timers(gpu_timing_client_.get());
439 491
440 for (int i = 0; i < 4; ++i) { 492 for (int i = 0; i < 4; ++i) {
441 UploadTexture(texture_id, texture_size, pixels[i % 4], GL_RGBA); 493 UploadTexture(texture_id, texture_size, pixels[i % 4], GL_RGBA, true);
442 DCHECK_NE(-1, translation_location_); 494 DCHECK_NE(-1, translation_location_);
443 glUniform2f(translation_location_, positions[i % 4].x(), 495 glUniform2f(translation_location_, positions[i % 4].x(),
444 positions[i % 4].y()); 496 positions[i % 4].y());
445 // Draw the same quad multiple times to make sure that the time spent on the 497 // Draw the same quad multiple times to make sure that the time spent on the
446 // gpu is more than the cpu time. 498 // gpu is more than the cpu time.
447 for (int draw = 0; draw < 128; ++draw) { 499 for (int draw = 0; draw < 128; ++draw) {
448 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 500 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
449 } 501 }
450 } 502 }
451 503
452 upload_and_draw_timers.Record(); 504 upload_and_draw_timers.Record();
453 MeasurementTimers finish_timers(gpu_timing_client_.get()); 505 MeasurementTimers finish_timers(gpu_timing_client_.get());
454 glFinish(); 506 glFinish();
455 CheckNoGlError(); 507 CheckNoGlError("glFinish");
456 finish_timers.Record(); 508 finish_timers.Record();
457 509
458 glDeleteTextures(1, &texture_id); 510 glDeleteTextures(1, &texture_id);
459 511
460 for (int i = 0; i < 4; ++i) { 512 for (int i = 0; i < 4; ++i) {
461 std::vector<uint8> pixels_rendered(texture_size.GetArea() * 4); 513 std::vector<uint8> pixels_rendered(texture_size.GetArea() * 4);
462 glReadPixels(texture_size.width() * positions[i].x(), 514 glReadPixels(texture_size.width() * positions[i].x(),
463 texture_size.height() * positions[i].y(), texture_size.width(), 515 texture_size.height() * positions[i].y(), texture_size.width(),
464 texture_size.height(), GL_RGBA, GL_UNSIGNED_BYTE, 516 texture_size.height(), GL_RGBA, GL_UNSIGNED_BYTE,
465 &pixels_rendered[0]); 517 &pixels_rendered[0]);
466 CheckNoGlError(); 518 CheckNoGlError("glReadPixels");
467 ASSERT_EQ(pixels[i].size(), pixels_rendered.size()); 519 ASSERT_EQ(pixels[i].size(), pixels_rendered.size());
468 EXPECT_EQ(pixels[i], pixels_rendered); 520 EXPECT_EQ(pixels[i], pixels_rendered);
469 } 521 }
470 522
471 bool gpu_timer_errors = gpu_timing_client_->IsAvailable() && 523 bool gpu_timer_errors = gpu_timing_client_->IsAvailable() &&
472 gpu_timing_client_->CheckAndResetTimerErrors(); 524 gpu_timing_client_->CheckAndResetTimerErrors();
473 if (!gpu_timer_errors) { 525 if (!gpu_timer_errors) {
474 upload_and_draw_timers.GetAsMeasurement("upload_and_draw") 526 upload_and_draw_timers.GetAsMeasurement("upload_and_draw")
475 .PrintResult("renaming"); 527 .PrintResult("renaming");
476 finish_timers.GetAsMeasurement("finish").PrintResult("renaming"); 528 finish_timers.GetAsMeasurement("finish").PrintResult("renaming");
477 } 529 }
478 } 530 }
479 531
480 } // namespace 532 } // namespace
481 } // namespace gpu 533 } // namespace gpu
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698