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

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

Issue 952893003: Update from https://crrev.com/317530 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Fix gn for nacl 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 | « gpu/perftests/measurements.cc ('k') | mojo/converters/surfaces/surfaces_type_converters.cc » ('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/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "gpu/command_buffer/service/gpu_timing.h"
11 #include "gpu/perftests/measurements.h" 13 #include "gpu/perftests/measurements.h"
12 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/gfx/geometry/size.h" 15 #include "ui/gfx/geometry/size.h"
14 #include "ui/gl/gl_bindings.h" 16 #include "ui/gl/gl_bindings.h"
15 #include "ui/gl/gl_context.h" 17 #include "ui/gl/gl_context.h"
16 #include "ui/gl/gl_surface.h" 18 #include "ui/gl/gl_surface.h"
17 #include "ui/gl/scoped_make_current.h" 19 #include "ui/gl/scoped_make_current.h"
18 20
19 namespace gpu { 21 namespace gpu {
20 namespace { 22 namespace {
21 23
22 const int kUploadPerfWarmupRuns = 10; 24 const int kUploadPerfWarmupRuns = 10;
23 const int kUploadPerfTestRuns = 100; 25 const int kUploadPerfTestRuns = 100;
24 26
25 #define SHADER(Src) #Src 27 #define SHADER(Src) #Src
26 28
27 // clang-format off 29 // clang-format off
28 const char kVertexShader[] = 30 const char kVertexShader[] =
29 SHADER( 31 SHADER(
30 attribute vec2 a_position; 32 attribute vec2 a_position;
31 varying vec2 v_texCoord; 33 varying vec2 v_texCoord;
32 void main() { 34 void main() {
33 gl_Position = vec4(a_position.x, a_position.y, 0.0, 1.0); 35 gl_Position = vec4(a_position.x, a_position.y, 0.0, 1.0);
34 v_texCoord = vec2((a_position.x + 1) * 0.5, (a_position.y + 1) * 0.5); 36 v_texCoord = vec2((a_position.x + 1.0) * 0.5, (a_position.y + 1.0) * 0.5);
35 } 37 }
36 ); 38 );
37 const char kFragmentShader[] = 39 const char kFragmentShader[] =
38 SHADER( 40 SHADER(
39 uniform sampler2D a_texture; 41 uniform sampler2D a_texture;
40 varying vec2 v_texCoord; 42 varying vec2 v_texCoord;
41 void main() { 43 void main() {
42 gl_FragColor = texture2D(a_texture, v_texCoord.xy); 44 gl_FragColor = texture2D(a_texture, v_texCoord.xy);
43 } 45 }
44 ); 46 );
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 // PerfTest to check costs of texture upload at different stages 91 // PerfTest to check costs of texture upload at different stages
90 // on different platforms. 92 // on different platforms.
91 class TextureUploadPerfTest : public testing::Test { 93 class TextureUploadPerfTest : public testing::Test {
92 public: 94 public:
93 TextureUploadPerfTest() : size_(512, 512) {} 95 TextureUploadPerfTest() : size_(512, 512) {}
94 96
95 // Overridden from testing::Test 97 // Overridden from testing::Test
96 void SetUp() override { 98 void SetUp() override {
97 // Initialize an offscreen surface and a gl context. 99 // Initialize an offscreen surface and a gl context.
98 gfx::GLSurface::InitializeOneOff(); 100 gfx::GLSurface::InitializeOneOff();
99 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(size_); 101 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(4, 4));
100 gl_context_ = gfx::GLContext::CreateGLContext(NULL, // share_group 102 gl_context_ = gfx::GLContext::CreateGLContext(NULL, // share_group
101 surface_.get(), 103 surface_.get(),
102 gfx::PreferIntegratedGpu); 104 gfx::PreferIntegratedGpu);
105 ui::ScopedMakeCurrent smc(gl_context_.get(), surface_.get());
106 glGenTextures(1, &color_texture_);
107 glBindTexture(GL_TEXTURE_2D, color_texture_);
108 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);
110 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
111 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
112 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size_.width(), size_.height(), 0,
113 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
103 114
104 ui::ScopedMakeCurrent smc(gl_context_.get(), surface_.get()); 115 glGenFramebuffersEXT(1, &framebuffer_object_);
116 glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer_object_);
117
118 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
119 GL_TEXTURE_2D, color_texture_, 0);
120 DCHECK_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
121 glCheckFramebufferStatusEXT(GL_FRAMEBUFFER));
122
123 glViewport(0, 0, size_.width(), size_.height());
124
105 if (gpu_timing_.Initialize(gl_context_.get())) { 125 if (gpu_timing_.Initialize(gl_context_.get())) {
106 LOG(INFO) << "Gpu timing initialized with timer type: " 126 LOG(INFO) << "Gpu timing initialized with timer type: "
107 << gpu_timing_.GetTimerTypeName(); 127 << gpu_timing_.GetTimerTypeName();
108 gpu_timing_.CheckAndResetTimerErrors(); 128 gpu_timing_.CheckAndResetTimerErrors();
109 gpu_timing_.InvalidateTimerOffset(); 129 gpu_timing_.InvalidateTimerOffset();
110 } else { 130 } else {
111 LOG(WARNING) << "Can't initialize gpu timing"; 131 LOG(WARNING) << "Can't initialize gpu timing";
112 } 132 }
113
114 // Prepare a simple program and a vertex buffer that will be 133 // Prepare a simple program and a vertex buffer that will be
115 // used to draw a quad on the offscreen surface. 134 // used to draw a quad on the offscreen surface.
116 vertex_shader_ = LoadShader(GL_VERTEX_SHADER, kVertexShader); 135 vertex_shader_ = LoadShader(GL_VERTEX_SHADER, kVertexShader);
117 fragment_shader_ = LoadShader(GL_FRAGMENT_SHADER, kFragmentShader); 136 fragment_shader_ = LoadShader(GL_FRAGMENT_SHADER, kFragmentShader);
118 program_object_ = glCreateProgram(); 137 program_object_ = glCreateProgram();
119 CHECK_NE(0u, program_object_); 138 CHECK_NE(0u, program_object_);
120 139
121 glAttachShader(program_object_, vertex_shader_); 140 glAttachShader(program_object_, vertex_shader_);
122 glAttachShader(program_object_, fragment_shader_); 141 glAttachShader(program_object_, fragment_shader_);
123 glBindAttribLocation(program_object_, 0, "a_position"); 142 glBindAttribLocation(program_object_, 0, "a_position");
(...skipping 11 matching lines...) Expand all
135 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer_); 154 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer_);
136 static GLfloat positions[] = { 155 static GLfloat positions[] = {
137 -1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 156 -1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f,
138 }; 157 };
139 glBufferData(GL_ARRAY_BUFFER, sizeof(positions), positions, GL_STATIC_DRAW); 158 glBufferData(GL_ARRAY_BUFFER, sizeof(positions), positions, GL_STATIC_DRAW);
140 CheckNoGlError(); 159 CheckNoGlError();
141 } 160 }
142 161
143 void TearDown() override { 162 void TearDown() override {
144 ui::ScopedMakeCurrent smc(gl_context_.get(), surface_.get()); 163 ui::ScopedMakeCurrent smc(gl_context_.get(), surface_.get());
145 if (program_object_ != 0) { 164 glDeleteProgram(program_object_);
146 glDeleteProgram(program_object_); 165 glDeleteShader(vertex_shader_);
147 } 166 glDeleteShader(fragment_shader_);
148 if (vertex_shader_ != 0) { 167 glDeleteShader(vertex_buffer_);
149 glDeleteShader(vertex_shader_); 168
150 } 169 glBindFramebufferEXT(GL_FRAMEBUFFER, 0);
151 if (fragment_shader_ != 0) { 170 glDeleteFramebuffersEXT(1, &framebuffer_object_);
152 glDeleteShader(fragment_shader_); 171 glDeleteTextures(1, &color_texture_);
153 }
154 if (vertex_buffer_ != 0) {
155 glDeleteShader(vertex_buffer_);
156 }
157 172
158 gl_context_ = nullptr; 173 gl_context_ = nullptr;
159 surface_ = nullptr; 174 surface_ = nullptr;
160 } 175 }
161 176
162 protected: 177 protected:
163 // Upload and draw on the offscren surface. 178 // Upload and draw on the offscren surface.
164 // Return a list of pair. Each pair describe a gl operation and the wall 179 // Return a list of pair. Each pair describe a gl operation and the wall
165 // time elapsed in milliseconds. 180 // time elapsed in milliseconds.
166 std::vector<Measurement> UploadAndDraw(const std::vector<uint8>& pixels, 181 std::vector<Measurement> UploadAndDraw(const std::vector<uint8>& pixels,
167 const GLenum format, 182 const GLenum format,
168 const GLenum type) { 183 const GLenum type) {
169 ui::ScopedMakeCurrent smc(gl_context_.get(), surface_.get()); 184 ui::ScopedMakeCurrent smc(gl_context_.get(), surface_.get());
185 DCHECK_NE(0u, framebuffer_object_);
186 glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer_object_);
170 187
171 MeasurementTimers total_timers(&gpu_timing_); 188 MeasurementTimers total_timers(&gpu_timing_);
172 GLuint texture_id = 0; 189 GLuint texture_id = 0;
173 190
174 MeasurementTimers tex_timers(&gpu_timing_); 191 MeasurementTimers tex_timers(&gpu_timing_);
175 glActiveTexture(GL_TEXTURE0); 192 glActiveTexture(GL_TEXTURE0);
176 glGenTextures(1, &texture_id); 193 glGenTextures(1, &texture_id);
177 glBindTexture(GL_TEXTURE_2D, texture_id); 194 glBindTexture(GL_TEXTURE_2D, texture_id);
178 195
179 glTexImage2D(GL_TEXTURE_2D, 0, format, size_.width(), size_.height(), 0, 196 glTexImage2D(GL_TEXTURE_2D, 0, format, size_.width(), size_.height(), 0,
180 format, type, &pixels[0]); 197 format, type, &pixels[0]);
181 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 198 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
182 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 199 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
183 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 200 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
184 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 201 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
185 CheckNoGlError(); 202 CheckNoGlError();
186 tex_timers.Record(); 203 tex_timers.Record();
187 204
188 MeasurementTimers draw_timers(&gpu_timing_); 205 MeasurementTimers draw_timers(&gpu_timing_);
189 glUseProgram(program_object_); 206 glUseProgram(program_object_);
190 glUniform1i(sampler_location_, 0); 207 glUniform1i(sampler_location_, 0);
191 208
192 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer_); 209 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer_);
(...skipping 22 matching lines...) Expand all
215 EXPECT_EQ(pixels, pixels_rendered); 232 EXPECT_EQ(pixels, pixels_rendered);
216 233
217 std::vector<Measurement> measurements; 234 std::vector<Measurement> measurements;
218 measurements.push_back(total_timers.GetAsMeasurement("total")); 235 measurements.push_back(total_timers.GetAsMeasurement("total"));
219 measurements.push_back(tex_timers.GetAsMeasurement("teximage2d")); 236 measurements.push_back(tex_timers.GetAsMeasurement("teximage2d"));
220 measurements.push_back(draw_timers.GetAsMeasurement("drawarrays")); 237 measurements.push_back(draw_timers.GetAsMeasurement("drawarrays"));
221 measurements.push_back(finish_timers.GetAsMeasurement("finish")); 238 measurements.push_back(finish_timers.GetAsMeasurement("finish"));
222 return measurements; 239 return measurements;
223 } 240 }
224 241
225 const gfx::Size size_; // for the offscreen surface and the texture 242 const gfx::Size size_; // for the fbo and the texture
226 scoped_refptr<gfx::GLContext> gl_context_; 243 scoped_refptr<gfx::GLContext> gl_context_;
227 scoped_refptr<gfx::GLSurface> surface_; 244 scoped_refptr<gfx::GLSurface> surface_;
228 GPUTiming gpu_timing_; 245 GPUTiming gpu_timing_;
229 246
247 GLuint color_texture_ = 0;
248 GLuint framebuffer_object_ = 0;
230 GLuint vertex_shader_ = 0; 249 GLuint vertex_shader_ = 0;
231 GLuint fragment_shader_ = 0; 250 GLuint fragment_shader_ = 0;
232 GLuint program_object_ = 0; 251 GLuint program_object_ = 0;
233 GLint sampler_location_ = -1; 252 GLint sampler_location_ = -1;
234 GLuint vertex_buffer_ = 0; 253 GLuint vertex_buffer_ = 0;
235 }; 254 };
236 255
237 // Perf test that generates, uploads and draws a texture on a surface repeatedly 256 // Perf test that generates, uploads and draws a texture on a surface repeatedly
238 // and prints out aggregated measurements for all the runs. 257 // and prints out aggregated measurements for all the runs.
239 TEST_F(TextureUploadPerfTest, glTexImage2d) { 258 TEST_F(TextureUploadPerfTest, glTexImage2d) {
(...skipping 13 matching lines...) Expand all
253 } 272 }
254 273
255 for (const auto& entry : aggregates) { 274 for (const auto& entry : aggregates) {
256 const auto m = entry.second.Divide(kUploadPerfTestRuns); 275 const auto m = entry.second.Divide(kUploadPerfTestRuns);
257 m.PrintResult(); 276 m.PrintResult();
258 } 277 }
259 } 278 }
260 279
261 } // namespace 280 } // namespace
262 } // namespace gpu 281 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/perftests/measurements.cc ('k') | mojo/converters/surfaces/surfaces_type_converters.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698