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 "base/strings/stringprintf.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" |
| 20 #include "ui/gl/gpu_timing.h" |
19 #include "ui/gl/scoped_make_current.h" | 21 #include "ui/gl/scoped_make_current.h" |
20 | 22 |
21 namespace gpu { | 23 namespace gpu { |
22 namespace { | 24 namespace { |
23 | 25 |
24 const int kUploadPerfWarmupRuns = 10; | 26 const int kUploadPerfWarmupRuns = 10; |
25 const int kUploadPerfTestRuns = 100; | 27 const int kUploadPerfTestRuns = 100; |
26 | 28 |
27 #define SHADER(Src) #Src | 29 #define SHADER(Src) #Src |
28 | 30 |
29 // clang-format off | 31 // clang-format off |
30 const char kVertexShader[] = | 32 const char kVertexShader[] = |
31 SHADER( | 33 SHADER( |
32 attribute vec2 a_position; | 34 attribute vec2 a_position; |
| 35 attribute vec2 a_texCoord; |
33 varying vec2 v_texCoord; | 36 varying vec2 v_texCoord; |
34 void main() { | 37 void main() { |
35 gl_Position = vec4(a_position.x, a_position.y, 0.0, 1.0); | 38 gl_Position = vec4(a_position.x, a_position.y, 0.0, 1.0); |
36 v_texCoord = vec2((a_position.x + 1.0) * 0.5, (a_position.y + 1.0) * 0.5); | 39 v_texCoord = a_texCoord; |
37 } | 40 } |
38 ); | 41 ); |
39 const char kFragmentShader[] = | 42 const char kFragmentShader[] = |
40 SHADER( | 43 SHADER( |
41 uniform sampler2D a_texture; | 44 uniform sampler2D a_texture; |
42 varying vec2 v_texCoord; | 45 varying vec2 v_texCoord; |
43 void main() { | 46 void main() { |
44 gl_FragColor = texture2D(a_texture, v_texCoord.xy); | 47 gl_FragColor = texture2D(a_texture, v_texCoord); |
45 } | 48 } |
46 ); | 49 ); |
47 // clang-format on | 50 // clang-format on |
48 | 51 |
49 void CheckNoGlError() { | 52 void CheckNoGlError() { |
50 CHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 53 CHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
51 } | 54 } |
52 | 55 |
53 // Utility function to compile a shader from a string. | 56 // Utility function to compile a shader from a string. |
54 GLuint LoadShader(const GLenum type, const char* const src) { | 57 GLuint LoadShader(const GLenum type, const char* const src) { |
(...skipping 18 matching lines...) Expand all Loading... |
73 return shader; | 76 return shader; |
74 } | 77 } |
75 | 78 |
76 void GenerateTextureData(const gfx::Size& size, | 79 void GenerateTextureData(const gfx::Size& size, |
77 const int seed, | 80 const int seed, |
78 std::vector<uint8>* const pixels) { | 81 std::vector<uint8>* const pixels) { |
79 pixels->resize(size.GetArea() * 4); | 82 pixels->resize(size.GetArea() * 4); |
80 for (int y = 0; y < size.height(); ++y) { | 83 for (int y = 0; y < size.height(); ++y) { |
81 for (int x = 0; x < size.width(); ++x) { | 84 for (int x = 0; x < size.width(); ++x) { |
82 const size_t offset = (y * size.width() + x) * 4; | 85 const size_t offset = (y * size.width() + x) * 4; |
83 pixels->at(offset) = (y + seed) % 256; | 86 pixels->at(offset) = (y + seed) % 64; |
84 pixels->at(offset + 1) = (x + seed) % 256; | 87 pixels->at(offset + 1) = (x + seed) % 128; |
85 pixels->at(offset + 2) = (y + x + seed) % 256; | 88 pixels->at(offset + 2) = (y + x + seed) % 256; |
86 pixels->at(offset + 3) = 255; | 89 pixels->at(offset + 3) = 255; |
87 } | 90 } |
88 } | 91 } |
89 } | 92 } |
90 | 93 |
91 // PerfTest to check costs of texture upload at different stages | 94 // PerfTest to check costs of texture upload at different stages |
92 // on different platforms. | 95 // on different platforms. |
93 class TextureUploadPerfTest : public testing::Test { | 96 class TextureUploadPerfTest : public testing::Test { |
94 public: | 97 public: |
95 TextureUploadPerfTest() : size_(512, 512) {} | 98 TextureUploadPerfTest() : fbo_size_(1024, 1024) {} |
96 | 99 |
97 // Overridden from testing::Test | 100 // Overridden from testing::Test |
98 void SetUp() override { | 101 void SetUp() override { |
99 // Initialize an offscreen surface and a gl context. | 102 // Initialize an offscreen surface and a gl context. |
100 gfx::GLSurface::InitializeOneOff(); | 103 gfx::GLSurface::InitializeOneOff(); |
101 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(4, 4)); | 104 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(4, 4)); |
102 gl_context_ = gfx::GLContext::CreateGLContext(NULL, // share_group | 105 gl_context_ = gfx::GLContext::CreateGLContext(NULL, // share_group |
103 surface_.get(), | 106 surface_.get(), |
104 gfx::PreferIntegratedGpu); | 107 gfx::PreferIntegratedGpu); |
105 ui::ScopedMakeCurrent smc(gl_context_.get(), surface_.get()); | 108 ui::ScopedMakeCurrent smc(gl_context_.get(), surface_.get()); |
106 glGenTextures(1, &color_texture_); | 109 glGenTextures(1, &color_texture_); |
107 glBindTexture(GL_TEXTURE_2D, color_texture_); | 110 glBindTexture(GL_TEXTURE_2D, color_texture_); |
108 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 111 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
109 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 112 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
110 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 113 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
111 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 114 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
112 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size_.width(), size_.height(), 0, | 115 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fbo_size_.width(), |
113 GL_RGBA, GL_UNSIGNED_BYTE, nullptr); | 116 fbo_size_.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
114 | 117 |
115 glGenFramebuffersEXT(1, &framebuffer_object_); | 118 glGenFramebuffersEXT(1, &framebuffer_object_); |
116 glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer_object_); | 119 glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer_object_); |
117 | 120 |
118 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | 121 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
119 GL_TEXTURE_2D, color_texture_, 0); | 122 GL_TEXTURE_2D, color_texture_, 0); |
120 DCHECK_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), | 123 DCHECK_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), |
121 glCheckFramebufferStatusEXT(GL_FRAMEBUFFER)); | 124 glCheckFramebufferStatusEXT(GL_FRAMEBUFFER)); |
122 | 125 |
123 glViewport(0, 0, size_.width(), size_.height()); | 126 glViewport(0, 0, fbo_size_.width(), fbo_size_.height()); |
| 127 gpu_timing_client_ = gl_context_->CreateGPUTimingClient(); |
124 | 128 |
125 if (gpu_timing_.Initialize(gl_context_.get())) { | 129 if (gpu_timing_client_->IsAvailable()) { |
126 LOG(INFO) << "Gpu timing initialized with timer type: " | 130 LOG(INFO) << "Gpu timing initialized with timer type: " |
127 << gpu_timing_.GetTimerTypeName(); | 131 << gpu_timing_client_->GetTimerTypeName(); |
128 gpu_timing_.CheckAndResetTimerErrors(); | 132 gpu_timing_client_->InvalidateTimerOffset(); |
129 gpu_timing_.InvalidateTimerOffset(); | |
130 } else { | 133 } else { |
131 LOG(WARNING) << "Can't initialize gpu timing"; | 134 LOG(WARNING) << "Can't initialize gpu timing"; |
132 } | 135 } |
133 // Prepare a simple program and a vertex buffer that will be | 136 // Prepare a simple program and a vertex buffer that will be |
134 // used to draw a quad on the offscreen surface. | 137 // used to draw a quad on the offscreen surface. |
135 vertex_shader_ = LoadShader(GL_VERTEX_SHADER, kVertexShader); | 138 vertex_shader_ = LoadShader(GL_VERTEX_SHADER, kVertexShader); |
136 fragment_shader_ = LoadShader(GL_FRAGMENT_SHADER, kFragmentShader); | 139 fragment_shader_ = LoadShader(GL_FRAGMENT_SHADER, kFragmentShader); |
137 program_object_ = glCreateProgram(); | 140 program_object_ = glCreateProgram(); |
138 CHECK_NE(0u, program_object_); | 141 CHECK_NE(0u, program_object_); |
139 | 142 |
140 glAttachShader(program_object_, vertex_shader_); | 143 glAttachShader(program_object_, vertex_shader_); |
141 glAttachShader(program_object_, fragment_shader_); | 144 glAttachShader(program_object_, fragment_shader_); |
142 glBindAttribLocation(program_object_, 0, "a_position"); | 145 glBindAttribLocation(program_object_, 0, "a_position"); |
| 146 glBindAttribLocation(program_object_, 1, "a_texCoord"); |
143 glLinkProgram(program_object_); | 147 glLinkProgram(program_object_); |
144 | 148 |
145 GLint linked = -1; | 149 GLint linked = -1; |
146 glGetProgramiv(program_object_, GL_LINK_STATUS, &linked); | 150 glGetProgramiv(program_object_, GL_LINK_STATUS, &linked); |
147 CHECK_NE(0, linked); | 151 CHECK_NE(0, linked); |
148 | 152 |
149 sampler_location_ = glGetUniformLocation(program_object_, "a_texture"); | 153 sampler_location_ = glGetUniformLocation(program_object_, "a_texture"); |
150 CHECK_NE(-1, sampler_location_); | 154 CHECK_NE(-1, sampler_location_); |
151 | 155 |
152 glGenBuffersARB(1, &vertex_buffer_); | 156 glGenBuffersARB(1, &vertex_buffer_); |
153 CHECK_NE(0u, vertex_buffer_); | 157 CHECK_NE(0u, vertex_buffer_); |
154 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer_); | |
155 static GLfloat positions[] = { | |
156 -1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, | |
157 }; | |
158 glBufferData(GL_ARRAY_BUFFER, sizeof(positions), positions, GL_STATIC_DRAW); | |
159 CheckNoGlError(); | 158 CheckNoGlError(); |
160 } | 159 } |
161 | 160 |
| 161 void GenerateVertexBuffer(const gfx::Size& size) { |
| 162 DCHECK_NE(0u, vertex_buffer_); |
| 163 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer_); |
| 164 // right and top are in clipspace |
| 165 float right = -1.f + 2.f * size.width() / fbo_size_.width(); |
| 166 float top = -1.f + 2.f * size.height() / fbo_size_.height(); |
| 167 // Four vertexes, one per line. Each vertex has two components per |
| 168 // position and two per texcoord. |
| 169 // It represents a quad formed by two triangles if interpreted |
| 170 // as a tristrip. |
| 171 |
| 172 // clang-format off |
| 173 GLfloat data[16] = { |
| 174 -1.f, -1.f, 0.f, 0.f, |
| 175 right, -1.f, 1.f, 0.f, |
| 176 -1.f, top, 0.f, 1.f, |
| 177 right, top, 1.f, 1.f}; |
| 178 // clang-format on |
| 179 |
| 180 glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW); |
| 181 CheckNoGlError(); |
| 182 } |
| 183 |
162 void TearDown() override { | 184 void TearDown() override { |
163 ui::ScopedMakeCurrent smc(gl_context_.get(), surface_.get()); | 185 ui::ScopedMakeCurrent smc(gl_context_.get(), surface_.get()); |
164 glDeleteProgram(program_object_); | 186 glDeleteProgram(program_object_); |
165 glDeleteShader(vertex_shader_); | 187 glDeleteShader(vertex_shader_); |
166 glDeleteShader(fragment_shader_); | 188 glDeleteShader(fragment_shader_); |
167 glDeleteShader(vertex_buffer_); | 189 glDeleteBuffersARB(1, &vertex_buffer_); |
168 | 190 |
169 glBindFramebufferEXT(GL_FRAMEBUFFER, 0); | 191 glBindFramebufferEXT(GL_FRAMEBUFFER, 0); |
170 glDeleteFramebuffersEXT(1, &framebuffer_object_); | 192 glDeleteFramebuffersEXT(1, &framebuffer_object_); |
171 glDeleteTextures(1, &color_texture_); | 193 glDeleteTextures(1, &color_texture_); |
| 194 CheckNoGlError(); |
172 | 195 |
173 gl_context_ = nullptr; | 196 gl_context_ = nullptr; |
174 surface_ = nullptr; | 197 surface_ = nullptr; |
175 } | 198 } |
176 | 199 |
177 protected: | 200 protected: |
178 // Upload and draw on the offscren surface. | 201 // Upload and draw on the offscren surface. |
179 // 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 |
180 // time elapsed in milliseconds. | 203 // time elapsed in milliseconds. |
181 std::vector<Measurement> UploadAndDraw(const std::vector<uint8>& pixels, | 204 std::vector<Measurement> UploadAndDraw(const gfx::Size& size, |
| 205 const std::vector<uint8>& pixels, |
182 const GLenum format, | 206 const GLenum format, |
183 const GLenum type) { | 207 const GLenum type) { |
184 ui::ScopedMakeCurrent smc(gl_context_.get(), surface_.get()); | 208 MeasurementTimers total_timers(gpu_timing_client_.get()); |
185 DCHECK_NE(0u, framebuffer_object_); | |
186 glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer_object_); | |
187 | |
188 MeasurementTimers total_timers(&gpu_timing_); | |
189 GLuint texture_id = 0; | 209 GLuint texture_id = 0; |
190 | 210 |
191 MeasurementTimers tex_timers(&gpu_timing_); | 211 MeasurementTimers tex_timers(gpu_timing_client_.get()); |
192 glActiveTexture(GL_TEXTURE0); | 212 glActiveTexture(GL_TEXTURE0); |
193 glGenTextures(1, &texture_id); | 213 glGenTextures(1, &texture_id); |
194 glBindTexture(GL_TEXTURE_2D, texture_id); | 214 glBindTexture(GL_TEXTURE_2D, texture_id); |
195 | 215 |
196 glTexImage2D(GL_TEXTURE_2D, 0, format, size_.width(), size_.height(), 0, | 216 glTexImage2D(GL_TEXTURE_2D, 0, format, size.width(), size.height(), 0, |
197 format, type, &pixels[0]); | 217 format, type, &pixels[0]); |
198 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 218 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
199 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 219 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
200 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); |
201 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); |
202 CheckNoGlError(); | 222 CheckNoGlError(); |
203 tex_timers.Record(); | 223 tex_timers.Record(); |
204 | 224 |
205 MeasurementTimers draw_timers(&gpu_timing_); | 225 MeasurementTimers draw_timers(gpu_timing_client_.get()); |
206 glUseProgram(program_object_); | 226 glUseProgram(program_object_); |
207 glUniform1i(sampler_location_, 0); | 227 glUniform1i(sampler_location_, 0); |
208 | 228 |
| 229 DCHECK_NE(0u, vertex_buffer_); |
209 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer_); | 230 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer_); |
210 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0); | 231 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 4, 0); |
| 232 glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 4, |
| 233 reinterpret_cast<void*>(sizeof(GLfloat) * 2)); |
211 glEnableVertexAttribArray(0); | 234 glEnableVertexAttribArray(0); |
| 235 glEnableVertexAttribArray(1); |
212 | 236 |
213 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); | 237 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); |
214 draw_timers.Record(); | 238 draw_timers.Record(); |
215 | 239 |
216 MeasurementTimers finish_timers(&gpu_timing_); | 240 MeasurementTimers finish_timers(gpu_timing_client_.get()); |
217 glFinish(); | 241 glFinish(); |
218 CheckNoGlError(); | 242 CheckNoGlError(); |
219 finish_timers.Record(); | 243 finish_timers.Record(); |
220 total_timers.Record(); | 244 total_timers.Record(); |
221 | 245 |
222 glDeleteTextures(1, &texture_id); | 246 glDeleteTextures(1, &texture_id); |
223 | 247 |
224 std::vector<uint8> pixels_rendered(size_.GetArea() * 4); | 248 std::vector<uint8> pixels_rendered(size.GetArea() * 4); |
225 glReadPixels(0, 0, size_.width(), size_.height(), GL_RGBA, type, | 249 glReadPixels(0, 0, size.width(), size.height(), GL_RGBA, type, |
226 &pixels_rendered[0]); | 250 &pixels_rendered[0]); |
227 CheckNoGlError(); | 251 CheckNoGlError(); |
228 | 252 |
229 // 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 |
230 // the appropriate format conversion. | 254 // the appropriate format conversion. |
231 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), format); | 255 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), format); |
232 EXPECT_EQ(pixels, pixels_rendered); | 256 EXPECT_EQ(pixels, pixels_rendered); |
233 | 257 |
234 std::vector<Measurement> measurements; | 258 std::vector<Measurement> measurements; |
235 measurements.push_back(total_timers.GetAsMeasurement("total")); | 259 bool gpu_timer_errors = |
236 measurements.push_back(tex_timers.GetAsMeasurement("teximage2d")); | 260 gpu_timing_client_->IsAvailable() && |
237 measurements.push_back(draw_timers.GetAsMeasurement("drawarrays")); | 261 gpu_timing_client_->CheckAndResetTimerErrors(); |
238 measurements.push_back(finish_timers.GetAsMeasurement("finish")); | 262 if (!gpu_timer_errors) { |
| 263 measurements.push_back(total_timers.GetAsMeasurement("total")); |
| 264 measurements.push_back(tex_timers.GetAsMeasurement("teximage2d")); |
| 265 measurements.push_back(draw_timers.GetAsMeasurement("drawarrays")); |
| 266 measurements.push_back(finish_timers.GetAsMeasurement("finish")); |
| 267 } |
239 return measurements; | 268 return measurements; |
240 } | 269 } |
241 | 270 |
242 const gfx::Size size_; // for the fbo and the texture | 271 void RunUploadAndDrawMultipleTimes(const gfx::Size& size) { |
| 272 std::vector<uint8> pixels; |
| 273 base::SmallMap<std::map<std::string, Measurement>> |
| 274 aggregates; // indexed by name |
| 275 int successful_runs = 0; |
| 276 for (int i = 0; i < kUploadPerfWarmupRuns + kUploadPerfTestRuns; ++i) { |
| 277 GenerateTextureData(size, i + 1, &pixels); |
| 278 auto run = UploadAndDraw(size, pixels, GL_RGBA, GL_UNSIGNED_BYTE); |
| 279 if (i < kUploadPerfWarmupRuns || !run.size()) { |
| 280 continue; |
| 281 } |
| 282 successful_runs++; |
| 283 for (const Measurement& measurement : run) { |
| 284 auto& aggregate = aggregates[measurement.name]; |
| 285 aggregate.name = measurement.name; |
| 286 aggregate.Increment(measurement); |
| 287 } |
| 288 } |
| 289 if (successful_runs) { |
| 290 for (const auto& entry : aggregates) { |
| 291 const auto m = entry.second.Divide(successful_runs); |
| 292 m.PrintResult(base::StringPrintf("_%d", size.width())); |
| 293 } |
| 294 } |
| 295 perf_test::PrintResult("sample_runs", "", "", |
| 296 static_cast<size_t>(successful_runs), "laps", true); |
| 297 } |
| 298 |
| 299 const gfx::Size fbo_size_; // for the fbo |
243 scoped_refptr<gfx::GLContext> gl_context_; | 300 scoped_refptr<gfx::GLContext> gl_context_; |
244 scoped_refptr<gfx::GLSurface> surface_; | 301 scoped_refptr<gfx::GLSurface> surface_; |
245 GPUTiming gpu_timing_; | 302 scoped_refptr<gfx::GPUTimingClient> gpu_timing_client_; |
246 | 303 |
247 GLuint color_texture_ = 0; | 304 GLuint color_texture_ = 0; |
248 GLuint framebuffer_object_ = 0; | 305 GLuint framebuffer_object_ = 0; |
249 GLuint vertex_shader_ = 0; | 306 GLuint vertex_shader_ = 0; |
250 GLuint fragment_shader_ = 0; | 307 GLuint fragment_shader_ = 0; |
251 GLuint program_object_ = 0; | 308 GLuint program_object_ = 0; |
252 GLint sampler_location_ = -1; | 309 GLint sampler_location_ = -1; |
253 GLuint vertex_buffer_ = 0; | 310 GLuint vertex_buffer_ = 0; |
254 }; | 311 }; |
255 | 312 |
256 // Perf test that generates, uploads and draws a texture on a surface repeatedly | 313 // Perf test that generates, uploads and draws a texture on a surface repeatedly |
257 // and prints out aggregated measurements for all the runs. | 314 // and prints out aggregated measurements for all the runs. |
258 TEST_F(TextureUploadPerfTest, glTexImage2d) { | 315 TEST_F(TextureUploadPerfTest, glTexImage2d) { |
259 std::vector<uint8> pixels; | 316 int sizes[] = {128, 256, 512, 1024}; |
260 base::SmallMap<std::map<std::string, Measurement>> | 317 for (int side : sizes) { |
261 aggregates; // indexed by name | 318 ASSERT_GE(fbo_size_.width(), side); |
262 for (int i = 0; i < kUploadPerfWarmupRuns + kUploadPerfTestRuns; ++i) { | 319 ASSERT_GE(fbo_size_.height(), side); |
263 GenerateTextureData(size_, i + 1, &pixels); | |
264 auto run = UploadAndDraw(pixels, GL_RGBA, GL_UNSIGNED_BYTE); | |
265 if (i >= kUploadPerfWarmupRuns) { | |
266 for (const Measurement& m : run) { | |
267 auto& agg = aggregates[m.name]; | |
268 agg.name = m.name; | |
269 agg.Increment(m); | |
270 } | |
271 } | |
272 } | |
273 | 320 |
274 for (const auto& entry : aggregates) { | 321 gfx::Size size(side, side); |
275 const auto m = entry.second.Divide(kUploadPerfTestRuns); | 322 ui::ScopedMakeCurrent smc(gl_context_.get(), surface_.get()); |
276 m.PrintResult(); | 323 GenerateVertexBuffer(size); |
| 324 |
| 325 DCHECK_NE(0u, framebuffer_object_); |
| 326 glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer_object_); |
| 327 |
| 328 RunUploadAndDrawMultipleTimes(size); |
277 } | 329 } |
278 } | 330 } |
279 | 331 |
280 } // namespace | 332 } // namespace |
281 } // namespace gpu | 333 } // namespace gpu |
OLD | NEW |