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

Side by Side Diff: bench/GLVertexAttributesBench.cpp

Issue 1216963011: fix for angle (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 5 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 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "Benchmark.h" 8 #include "Benchmark.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkImageEncoder.h" 10 #include "SkImageEncoder.h"
11 #if SK_SUPPORT_GPU 11 #if SK_SUPPORT_GPU
12 #include "GrTest.h" 12 #include "GrTest.h"
13 #include "gl/GrGLGLSL.h" 13 #include "gl/GrGLGLSL.h"
14 #include "gl/GrGLInterface.h" 14 #include "gl/GrGLInterface.h"
15 #include "gl/GrGLShaderVar.h" 15 #include "gl/GrGLShaderVar.h"
16 #include "gl/GrGLUtil.h" 16 #include "gl/GrGLUtil.h"
17 #include "glsl/GrGLSLCaps.h" 17 #include "glsl/GrGLSLCaps.h"
18 #include <stdio.h> 18 #include <stdio.h>
19 19
20 /* 20 /*
21 * This is a native GL benchmark for determining the cost of uploading vertex at tributes 21 * This is a native GL benchmark for determining the cost of uploading vertex at tributes
22 */ 22 */
23 class GLVertexAttributesBench : public Benchmark { 23 class GLVertexAttributesBench : public Benchmark {
24 public: 24 public:
25 GLVertexAttributesBench(uint32_t attribs) 25 GLVertexAttributesBench(uint32_t attribs)
26 : fTexture(0) 26 : fTexture(0)
27 , fBuffers(0) 27 , fBuffers(0)
28 , fProgram(0) 28 , fProgram(0)
29 , fVAO(0)
30 , fVBO(0) 29 , fVBO(0)
31 , fAttribs(attribs) 30 , fAttribs(attribs)
32 , fStride(2 * sizeof(SkPoint) + fAttribs * sizeof(GrGLfloat) * 4) { 31 , fStride(2 * sizeof(SkPoint) + fAttribs * sizeof(GrGLfloat) * 4) {
33 fName.appendf("GLVertexAttributesBench_%d", fAttribs); 32 fName.appendf("GLVertexAttributesBench_%d", fAttribs);
34 } 33 }
35 34
36 protected: 35 protected:
37 const char* onGetName() override { return fName.c_str(); } 36 const char* onGetName() override { return fName.c_str(); }
38 void onPerCanvasPreDraw(SkCanvas* canvas) override; 37 void onPerCanvasPreDraw(SkCanvas* canvas) override;
39 void setup(const GrGLContext*); 38 void setup(const GrGLContext*);
40 void onDraw(const int loops, SkCanvas*) override; 39 void onDraw(const int loops, SkCanvas*) override;
41 void onPerCanvasPostDraw(SkCanvas* canvas) override; 40 void onPerCanvasPostDraw(SkCanvas* canvas) override;
42 41
43 static const GrGLuint kScreenWidth = 800; 42 static const GrGLuint kScreenWidth = 800;
44 static const GrGLuint kScreenHeight = 600; 43 static const GrGLuint kScreenHeight = 600;
45 static const uint32_t kNumTri = 10000; 44 static const uint32_t kNumTri = 10000;
46 static const uint32_t kVerticesPerTri = 3; 45 static const uint32_t kVerticesPerTri = 3;
47 static const uint32_t kDrawMultiplier = 512; 46 static const uint32_t kDrawMultiplier = 512;
48 static const uint32_t kMaxAttribs = 7; 47 static const uint32_t kMaxAttribs = 7;
49 48
50 private: 49 private:
51 GrGLuint fTexture; 50 GrGLuint fTexture;
52 SkTArray<GrGLuint> fBuffers; 51 SkTArray<GrGLuint> fBuffers;
53 GrGLuint fProgram; 52 GrGLuint fProgram;
54 GrGLuint fVAO;
55 GrGLuint fVBO; 53 GrGLuint fVBO;
56 SkTArray<unsigned char> fVertices; 54 SkTArray<unsigned char> fVertices;
57 uint32_t fAttribs; 55 uint32_t fAttribs;
58 size_t fStride; 56 size_t fStride;
59 SkString fName; 57 SkString fName;
60 typedef Benchmark INHERITED; 58 typedef Benchmark INHERITED;
61 }; 59 };
62 60
63 static const GrGLContext* get_gl_context(SkCanvas* canvas) { 61 static const GrGLContext* get_gl_context(SkCanvas* canvas) {
64 // This bench exclusively tests GL calls directly 62 // This bench exclusively tests GL calls directly
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 // This bench exclusively tests GL calls directly 94 // This bench exclusively tests GL calls directly
97 const GrGLContext* ctx = get_gl_context(canvas); 95 const GrGLContext* ctx = get_gl_context(canvas);
98 if (!ctx) { 96 if (!ctx) {
99 return; 97 return;
100 } 98 }
101 99
102 const GrGLInterface* gl = ctx->interface(); 100 const GrGLInterface* gl = ctx->interface();
103 101
104 // teardown 102 // teardown
105 GR_GL_CALL(gl, BindBuffer(GR_GL_ARRAY_BUFFER, 0)); 103 GR_GL_CALL(gl, BindBuffer(GR_GL_ARRAY_BUFFER, 0));
106 GR_GL_CALL(gl, BindVertexArray(0));
107 GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, 0)); 104 GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, 0));
108 GR_GL_CALL(gl, BindFramebuffer(GR_GL_FRAMEBUFFER, 0)); 105 GR_GL_CALL(gl, BindFramebuffer(GR_GL_FRAMEBUFFER, 0));
109 GR_GL_CALL(gl, DeleteTextures(1, &fTexture)); 106 GR_GL_CALL(gl, DeleteTextures(1, &fTexture));
110 GR_GL_CALL(gl, DeleteProgram(fProgram)); 107 GR_GL_CALL(gl, DeleteProgram(fProgram));
111 GR_GL_CALL(gl, DeleteBuffers(fBuffers.count(), fBuffers.begin())); 108 GR_GL_CALL(gl, DeleteBuffers(fBuffers.count(), fBuffers.begin()));
112 GR_GL_CALL(gl, DeleteVertexArrays(1, &fVAO));
113 } 109 }
114 110
115 //////////////////////////////////////////////////////////////////////////////// /////////////////// 111 //////////////////////////////////////////////////////////////////////////////// ///////////////////
116 112
117 static GrGLuint load_shader(const GrGLInterface* gl, const char* shaderSrc, GrGL enum type) { 113 static GrGLuint load_shader(const GrGLInterface* gl, const char* shaderSrc, GrGL enum type) {
118 GrGLuint shader; 114 GrGLuint shader;
119 // Create the shader object 115 // Create the shader object
120 GR_GL_CALL_RET(gl, shader, CreateShader(type)); 116 GR_GL_CALL_RET(gl, shader, CreateShader(type));
121 117
122 // Load the shader source 118 // Load the shader source
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 "void main()\n" 170 "void main()\n"
175 "{\n" 171 "{\n"
176 "gl_Position = a_position;\n"); 172 "gl_Position = a_position;\n");
177 173
178 for (uint32_t i = 0; i < attribs; i++) { 174 for (uint32_t i = 0; i < attribs; i++) {
179 vshaderTxt.appendf("%s = %s;\n", oVars[i].c_str(), aVars[i].c_str()); 175 vshaderTxt.appendf("%s = %s;\n", oVars[i].c_str(), aVars[i].c_str());
180 } 176 }
181 177
182 // Passthrough position as a dummy 178 // Passthrough position as a dummy
183 for (uint32_t i = attribs; i < maxAttribs; i++) { 179 for (uint32_t i = attribs; i < maxAttribs; i++) {
184 vshaderTxt.appendf("%s = vec4(0.f, 0.f, 0.f, 1.f);\n", oVars[i].c_str()) ; 180 vshaderTxt.appendf("%s = vec4(0, 0, 0, 1);\n", oVars[i].c_str());
185 } 181 }
186 182
187 vshaderTxt.append("}\n"); 183 vshaderTxt.append("}\n");
188 184
189 const GrGLInterface* gl = ctx->interface(); 185 const GrGLInterface* gl = ctx->interface();
190 GrGLuint vertexShader = load_shader(gl, vshaderTxt.c_str(), GR_GL_VERTEX_SHA DER); 186 GrGLuint vertexShader = load_shader(gl, vshaderTxt.c_str(), GR_GL_VERTEX_SHA DER);
191 187
192 // setup fragment shader 188 // setup fragment shader
193 GrGLShaderVar oFragColor("o_FragColor", kVec4f_GrSLType, GrShaderVar::kOut_T ypeModifier); 189 GrGLShaderVar oFragColor("o_FragColor", kVec4f_GrSLType, GrShaderVar::kOut_T ypeModifier);
194 SkString fshaderTxt(version); 190 SkString fshaderTxt(version);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 SkDebugf("------ failed to encode %s\n", filename); 268 SkDebugf("------ failed to encode %s\n", filename);
273 remove(filename); // remove any partial file 269 remove(filename); // remove any partial file
274 return; 270 return;
275 } 271 }
276 } 272 }
277 #endif 273 #endif
278 274
279 static void setup_framebuffer(const GrGLInterface* gl, int screenWidth, int scre enHeight) { 275 static void setup_framebuffer(const GrGLInterface* gl, int screenWidth, int scre enHeight) {
280 //Setup framebuffer 276 //Setup framebuffer
281 GrGLuint texture; 277 GrGLuint texture;
282 GR_GL_CALL(gl, PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0));
283 GR_GL_CALL(gl, PixelStorei(GR_GL_PACK_ROW_LENGTH, 0));
284 GR_GL_CALL(gl, GenTextures(1, &texture)); 278 GR_GL_CALL(gl, GenTextures(1, &texture));
285 GR_GL_CALL(gl, ActiveTexture(GR_GL_TEXTURE15)); 279 GR_GL_CALL(gl, ActiveTexture(GR_GL_TEXTURE15));
286 GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, texture)); 280 GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, texture));
287 GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_MAG_FILTER, GR_ GL_NEAREST)); 281 GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_MAG_FILTER, GR_ GL_NEAREST));
288 GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_MIN_FILTER, GR_ GL_NEAREST)); 282 GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_MIN_FILTER, GR_ GL_NEAREST));
289 GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_WRAP_S, GR_GL_C LAMP_TO_EDGE)); 283 GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_WRAP_S, GR_GL_C LAMP_TO_EDGE));
290 GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_WRAP_T, GR_GL_C LAMP_TO_EDGE)); 284 GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_WRAP_T, GR_GL_C LAMP_TO_EDGE));
291 GR_GL_CALL(gl, TexImage2D(GR_GL_TEXTURE_2D, 285 GR_GL_CALL(gl, TexImage2D(GR_GL_TEXTURE_2D,
292 0, //level 286 0, //level
293 GR_GL_RGBA8, //internal format 287 GR_GL_RGBA, //internal format
294 screenWidth, // width 288 screenWidth, // width
295 screenHeight, // height 289 screenHeight, // height
296 0, //border 290 0, //border
297 GR_GL_RGBA, //format 291 GR_GL_RGBA, //format
298 GR_GL_UNSIGNED_BYTE, // type 292 GR_GL_UNSIGNED_BYTE, // type
299 NULL)); 293 NULL));
300 294
301 // bind framebuffer 295 // bind framebuffer
302 GrGLuint framebuffer; 296 GrGLuint framebuffer;
303 GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, 0)); 297 GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, 0));
(...skipping 16 matching lines...) Expand all
320 fProgram = compile_shader(ctx, fAttribs, kMaxAttribs); 314 fProgram = compile_shader(ctx, fAttribs, kMaxAttribs);
321 315
322 // setup matrices 316 // setup matrices
323 SkMatrix viewMatrices[kNumTri]; 317 SkMatrix viewMatrices[kNumTri];
324 for (uint32_t i = 0 ; i < kNumTri; i++) { 318 for (uint32_t i = 0 ; i < kNumTri; i++) {
325 SkMatrix m = SkMatrix::I(); 319 SkMatrix m = SkMatrix::I();
326 m.setScale(0.0001f, 0.0001f); 320 m.setScale(0.0001f, 0.0001f);
327 viewMatrices[i] = m; 321 viewMatrices[i] = m;
328 } 322 }
329 323
330 // setup VAO
331 GR_GL_CALL(gl, GenVertexArrays(1, &fVAO));
332 GR_GL_CALL(gl, BindVertexArray(fVAO));
333
334 // presetup vertex attributes, color is set to be a light gray no matter how many vertex 324 // presetup vertex attributes, color is set to be a light gray no matter how many vertex
335 // attributes are used 325 // attributes are used
336 float targetColor = 0.9f; 326 float targetColor = 0.9f;
337 float colorContribution = targetColor / fAttribs; 327 float colorContribution = targetColor / fAttribs;
338 fVertices.reset(static_cast<int>(kVerticesPerTri * kNumTri * fStride)); 328 fVertices.reset(static_cast<int>(kVerticesPerTri * kNumTri * fStride));
339 for (uint32_t i = 0; i < kNumTri; i++) { 329 for (uint32_t i = 0; i < kNumTri; i++) {
340 unsigned char* ptr = &fVertices[static_cast<int>(i * kVerticesPerTri * f Stride)]; 330 unsigned char* ptr = &fVertices[static_cast<int>(i * kVerticesPerTri * f Stride)];
341 SkPoint* p = reinterpret_cast<SkPoint*>(ptr); 331 SkPoint* p = reinterpret_cast<SkPoint*>(ptr);
342 p->set(-1.0f, -1.0f); p++; p->set( 0.0f, 1.0f); 332 p->set(-1.0f, -1.0f); p++; p->set( 0.0f, 1.0f);
343 p = reinterpret_cast<SkPoint*>(ptr + fStride); 333 p = reinterpret_cast<SkPoint*>(ptr + fStride);
(...skipping 18 matching lines...) Expand all
362 352
363 GR_GL_CALL(gl, GenBuffers(1, &fVBO)); 353 GR_GL_CALL(gl, GenBuffers(1, &fVBO));
364 fBuffers.push_back(fVBO); 354 fBuffers.push_back(fVBO);
365 355
366 // clear screen 356 // clear screen
367 GR_GL_CALL(gl, ClearColor(0.03f, 0.03f, 0.03f, 1.0f)); 357 GR_GL_CALL(gl, ClearColor(0.03f, 0.03f, 0.03f, 1.0f));
368 GR_GL_CALL(gl, Clear(GR_GL_COLOR_BUFFER_BIT)); 358 GR_GL_CALL(gl, Clear(GR_GL_COLOR_BUFFER_BIT));
369 359
370 // set us up to draw 360 // set us up to draw
371 GR_GL_CALL(gl, UseProgram(fProgram)); 361 GR_GL_CALL(gl, UseProgram(fProgram));
372 GR_GL_CALL(gl, BindVertexArray(fVAO));
373 } 362 }
374 363
375 void GLVertexAttributesBench::onDraw(const int loops, SkCanvas* canvas) { 364 void GLVertexAttributesBench::onDraw(const int loops, SkCanvas* canvas) {
376 const GrGLContext* ctx = get_gl_context(canvas); 365 const GrGLContext* ctx = get_gl_context(canvas);
377 if (!ctx) { 366 if (!ctx) {
378 return; 367 return;
379 } 368 }
380 369
381 const GrGLInterface* gl = ctx->interface(); 370 const GrGLInterface* gl = ctx->interface();
382 371
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 409
421 DEF_BENCH( return new GLVertexAttributesBench(0) ) 410 DEF_BENCH( return new GLVertexAttributesBench(0) )
422 DEF_BENCH( return new GLVertexAttributesBench(1) ) 411 DEF_BENCH( return new GLVertexAttributesBench(1) )
423 DEF_BENCH( return new GLVertexAttributesBench(2) ) 412 DEF_BENCH( return new GLVertexAttributesBench(2) )
424 DEF_BENCH( return new GLVertexAttributesBench(3) ) 413 DEF_BENCH( return new GLVertexAttributesBench(3) )
425 DEF_BENCH( return new GLVertexAttributesBench(4) ) 414 DEF_BENCH( return new GLVertexAttributesBench(4) )
426 DEF_BENCH( return new GLVertexAttributesBench(5) ) 415 DEF_BENCH( return new GLVertexAttributesBench(5) )
427 DEF_BENCH( return new GLVertexAttributesBench(6) ) 416 DEF_BENCH( return new GLVertexAttributesBench(6) )
428 DEF_BENCH( return new GLVertexAttributesBench(7) ) 417 DEF_BENCH( return new GLVertexAttributesBench(7) )
429 #endif 418 #endif
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