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

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: 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
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 "gpu/command_buffer/service/gpu_timing.h"
13 #include "gpu/perftests/measurements.h" 12 #include "gpu/perftests/measurements.h"
14 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
15 #include "ui/gfx/geometry/size.h" 14 #include "ui/gfx/geometry/size.h"
16 #include "ui/gl/gl_bindings.h" 15 #include "ui/gl/gl_bindings.h"
17 #include "ui/gl/gl_context.h" 16 #include "ui/gl/gl_context.h"
18 #include "ui/gl/gl_surface.h" 17 #include "ui/gl/gl_surface.h"
18 #include "ui/gl/gpu_timing.h"
19 #include "ui/gl/scoped_make_current.h" 19 #include "ui/gl/scoped_make_current.h"
20 20
21 namespace gpu { 21 namespace gpu {
22 namespace { 22 namespace {
23 23
24 const int kUploadPerfWarmupRuns = 10; 24 const int kUploadPerfWarmupRuns = 10;
25 const int kUploadPerfTestRuns = 100; 25 const int kUploadPerfTestRuns = 100;
26 26
27 #define SHADER(Src) #Src 27 #define SHADER(Src) #Src
28 28
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 114
115 glGenFramebuffersEXT(1, &framebuffer_object_); 115 glGenFramebuffersEXT(1, &framebuffer_object_);
116 glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer_object_); 116 glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer_object_);
117 117
118 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, 118 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
119 GL_TEXTURE_2D, color_texture_, 0); 119 GL_TEXTURE_2D, color_texture_, 0);
120 DCHECK_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), 120 DCHECK_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
121 glCheckFramebufferStatusEXT(GL_FRAMEBUFFER)); 121 glCheckFramebufferStatusEXT(GL_FRAMEBUFFER));
122 122
123 glViewport(0, 0, size_.width(), size_.height()); 123 glViewport(0, 0, size_.width(), size_.height());
124 gpu_timing_.Initialize(gl_context_.get());
125 gpu_timing_client_ = gpu_timing_.CreateGPUTimingClient();
124 126
125 if (gpu_timing_.Initialize(gl_context_.get())) { 127 if (gpu_timing_client_->IsAvailable()) {
126 LOG(INFO) << "Gpu timing initialized with timer type: " 128 LOG(INFO) << "Gpu timing initialized with timer type: "
127 << gpu_timing_.GetTimerTypeName(); 129 << gpu_timing_client_->GetTimerTypeName();
128 gpu_timing_.CheckAndResetTimerErrors(); 130 gpu_timing_client_->InvalidateTimerOffset();
129 gpu_timing_.InvalidateTimerOffset();
130 } else { 131 } else {
131 LOG(WARNING) << "Can't initialize gpu timing"; 132 LOG(WARNING) << "Can't initialize gpu timing";
132 } 133 }
133 // Prepare a simple program and a vertex buffer that will be 134 // Prepare a simple program and a vertex buffer that will be
134 // used to draw a quad on the offscreen surface. 135 // used to draw a quad on the offscreen surface.
135 vertex_shader_ = LoadShader(GL_VERTEX_SHADER, kVertexShader); 136 vertex_shader_ = LoadShader(GL_VERTEX_SHADER, kVertexShader);
136 fragment_shader_ = LoadShader(GL_FRAGMENT_SHADER, kFragmentShader); 137 fragment_shader_ = LoadShader(GL_FRAGMENT_SHADER, kFragmentShader);
137 program_object_ = glCreateProgram(); 138 program_object_ = glCreateProgram();
138 CHECK_NE(0u, program_object_); 139 CHECK_NE(0u, program_object_);
139 140
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 // Upload and draw on the offscren surface. 179 // Upload and draw on the offscren surface.
179 // Return a list of pair. Each pair describe a gl operation and the wall 180 // Return a list of pair. Each pair describe a gl operation and the wall
180 // time elapsed in milliseconds. 181 // time elapsed in milliseconds.
181 std::vector<Measurement> UploadAndDraw(const std::vector<uint8>& pixels, 182 std::vector<Measurement> UploadAndDraw(const std::vector<uint8>& pixels,
182 const GLenum format, 183 const GLenum format,
183 const GLenum type) { 184 const GLenum type) {
184 ui::ScopedMakeCurrent smc(gl_context_.get(), surface_.get()); 185 ui::ScopedMakeCurrent smc(gl_context_.get(), surface_.get());
185 DCHECK_NE(0u, framebuffer_object_); 186 DCHECK_NE(0u, framebuffer_object_);
186 glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer_object_); 187 glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer_object_);
187 188
188 MeasurementTimers total_timers(&gpu_timing_); 189 MeasurementTimers total_timers(gpu_timing_client_.get());
189 GLuint texture_id = 0; 190 GLuint texture_id = 0;
190 191
191 MeasurementTimers tex_timers(&gpu_timing_); 192 MeasurementTimers tex_timers(gpu_timing_client_.get());
192 glActiveTexture(GL_TEXTURE0); 193 glActiveTexture(GL_TEXTURE0);
193 glGenTextures(1, &texture_id); 194 glGenTextures(1, &texture_id);
194 glBindTexture(GL_TEXTURE_2D, texture_id); 195 glBindTexture(GL_TEXTURE_2D, texture_id);
195 196
196 glTexImage2D(GL_TEXTURE_2D, 0, format, size_.width(), size_.height(), 0, 197 glTexImage2D(GL_TEXTURE_2D, 0, format, size_.width(), size_.height(), 0,
197 format, type, &pixels[0]); 198 format, type, &pixels[0]);
198 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 199 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
199 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 200 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
200 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 201 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); 202 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
202 CheckNoGlError(); 203 CheckNoGlError();
203 tex_timers.Record(); 204 tex_timers.Record();
204 205
205 MeasurementTimers draw_timers(&gpu_timing_); 206 MeasurementTimers draw_timers(gpu_timing_client_.get());
206 glUseProgram(program_object_); 207 glUseProgram(program_object_);
207 glUniform1i(sampler_location_, 0); 208 glUniform1i(sampler_location_, 0);
208 209
209 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer_); 210 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer_);
210 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0); 211 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
211 glEnableVertexAttribArray(0); 212 glEnableVertexAttribArray(0);
212 213
213 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 214 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
214 draw_timers.Record(); 215 draw_timers.Record();
215 216
216 MeasurementTimers finish_timers(&gpu_timing_); 217 MeasurementTimers finish_timers(gpu_timing_client_.get());
217 glFinish(); 218 glFinish();
218 CheckNoGlError(); 219 CheckNoGlError();
219 finish_timers.Record(); 220 finish_timers.Record();
220 total_timers.Record(); 221 total_timers.Record();
221 222
222 glDeleteTextures(1, &texture_id); 223 glDeleteTextures(1, &texture_id);
223 224
224 std::vector<uint8> pixels_rendered(size_.GetArea() * 4); 225 std::vector<uint8> pixels_rendered(size_.GetArea() * 4);
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 measurements.push_back(total_timers.GetAsMeasurement("total"));
236 measurements.push_back(tex_timers.GetAsMeasurement("teximage2d")); 237 measurements.push_back(tex_timers.GetAsMeasurement("teximage2d"));
237 measurements.push_back(draw_timers.GetAsMeasurement("drawarrays")); 238 measurements.push_back(draw_timers.GetAsMeasurement("drawarrays"));
238 measurements.push_back(finish_timers.GetAsMeasurement("finish")); 239 measurements.push_back(finish_timers.GetAsMeasurement("finish"));
239 return measurements; 240 return measurements;
240 } 241 }
241 242
242 const gfx::Size size_; // for the fbo and the texture 243 const gfx::Size size_; // for the fbo and the texture
243 scoped_refptr<gfx::GLContext> gl_context_; 244 scoped_refptr<gfx::GLContext> gl_context_;
244 scoped_refptr<gfx::GLSurface> surface_; 245 scoped_refptr<gfx::GLSurface> surface_;
245 GPUTiming gpu_timing_; 246 GPUTiming gpu_timing_;
247 scoped_refptr<GPUTimingClient> gpu_timing_client_;
246 248
247 GLuint color_texture_ = 0; 249 GLuint color_texture_ = 0;
248 GLuint framebuffer_object_ = 0; 250 GLuint framebuffer_object_ = 0;
249 GLuint vertex_shader_ = 0; 251 GLuint vertex_shader_ = 0;
250 GLuint fragment_shader_ = 0; 252 GLuint fragment_shader_ = 0;
251 GLuint program_object_ = 0; 253 GLuint program_object_ = 0;
252 GLint sampler_location_ = -1; 254 GLint sampler_location_ = -1;
253 GLuint vertex_buffer_ = 0; 255 GLuint vertex_buffer_ = 0;
254 }; 256 };
255 257
(...skipping 16 matching lines...) Expand all
272 } 274 }
273 275
274 for (const auto& entry : aggregates) { 276 for (const auto& entry : aggregates) {
275 const auto m = entry.second.Divide(kUploadPerfTestRuns); 277 const auto m = entry.second.Divide(kUploadPerfTestRuns);
276 m.PrintResult(); 278 m.PrintResult();
277 } 279 }
278 } 280 }
279 281
280 } // namespace 282 } // namespace
281 } // namespace gpu 283 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698