| OLD | NEW |
| 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 | 11 |
| 12 #if SK_SUPPORT_GPU | 12 #if SK_SUPPORT_GPU |
| 13 #include "GLBench.h" | 13 #include "GLBench.h" |
| 14 #include "gl/GrGLContext.h" |
| 14 #include "gl/GrGLGLSL.h" | 15 #include "gl/GrGLGLSL.h" |
| 15 #include "gl/GrGLInterface.h" | 16 #include "gl/GrGLInterface.h" |
| 16 #include "gl/GrGLShaderVar.h" | 17 #include "gl/GrGLShaderVar.h" |
| 17 #include "gl/GrGLUtil.h" | 18 #include "gl/GrGLUtil.h" |
| 18 #include "glsl/GrGLSLCaps.h" | 19 #include "glsl/GrGLSLCaps.h" |
| 19 | 20 |
| 20 /* | 21 /* |
| 21 * This is a native GL benchmark for instanced arrays vs vertex buffer objects.
To benchmark this | 22 * This is a native GL benchmark for instanced arrays vs vertex buffer objects.
To benchmark this |
| 22 * functionality, we draw n * kDrawMultipier triangles per run. If this number
is less than | 23 * functionality, we draw n * kDrawMultipier triangles per run. If this number
is less than |
| 23 * kNumTri then we do a single draw, either with instances, or drawArrays. Othe
rwise we do | 24 * kNumTri then we do a single draw, either with instances, or drawArrays. Othe
rwise we do |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 | 108 |
| 108 GrGLuint GLCpuPosInstancedArraysBench::setupShader(const GrGLContext* ctx) { | 109 GrGLuint GLCpuPosInstancedArraysBench::setupShader(const GrGLContext* ctx) { |
| 109 const char* version = GrGLGetGLSLVersionDecl(*ctx); | 110 const char* version = GrGLGetGLSLVersionDecl(*ctx); |
| 110 | 111 |
| 111 // setup vertex shader | 112 // setup vertex shader |
| 112 GrGLShaderVar aPosition("a_position", kVec2f_GrSLType, GrShaderVar::kAttribu
te_TypeModifier); | 113 GrGLShaderVar aPosition("a_position", kVec2f_GrSLType, GrShaderVar::kAttribu
te_TypeModifier); |
| 113 GrGLShaderVar aColor("a_color", kVec3f_GrSLType, GrShaderVar::kAttribute_Typ
eModifier); | 114 GrGLShaderVar aColor("a_color", kVec3f_GrSLType, GrShaderVar::kAttribute_Typ
eModifier); |
| 114 GrGLShaderVar oColor("o_color", kVec3f_GrSLType, GrShaderVar::kVaryingOut_Ty
peModifier); | 115 GrGLShaderVar oColor("o_color", kVec3f_GrSLType, GrShaderVar::kVaryingOut_Ty
peModifier); |
| 115 | 116 |
| 116 SkString vshaderTxt(version); | 117 SkString vshaderTxt(version); |
| 117 aPosition.appendDecl(*ctx, &vshaderTxt); | 118 aPosition.appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); |
| 118 vshaderTxt.append(";\n"); | 119 vshaderTxt.append(";\n"); |
| 119 aColor.appendDecl(*ctx, &vshaderTxt); | 120 aColor.appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); |
| 120 vshaderTxt.append(";\n"); | 121 vshaderTxt.append(";\n"); |
| 121 oColor.appendDecl(*ctx, &vshaderTxt); | 122 oColor.appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); |
| 122 vshaderTxt.append(";\n"); | 123 vshaderTxt.append(";\n"); |
| 123 | 124 |
| 124 vshaderTxt.append( | 125 vshaderTxt.append( |
| 125 "void main()\n" | 126 "void main()\n" |
| 126 "{\n" | 127 "{\n" |
| 127 "gl_Position = vec4(a_position, 0.f, 1.f);\n" | 128 "gl_Position = vec4(a_position, 0.f, 1.f);\n" |
| 128 "o_color = a_color;\n" | 129 "o_color = a_color;\n" |
| 129 "}\n"); | 130 "}\n"); |
| 130 | 131 |
| 131 const GrGLInterface* gl = ctx->interface(); | 132 const GrGLInterface* gl = ctx->interface(); |
| 132 | 133 |
| 133 // setup fragment shader | 134 // setup fragment shader |
| 134 GrGLShaderVar oFragColor("o_FragColor", kVec4f_GrSLType, GrShaderVar::kOut_T
ypeModifier); | 135 GrGLShaderVar oFragColor("o_FragColor", kVec4f_GrSLType, GrShaderVar::kOut_T
ypeModifier); |
| 135 SkString fshaderTxt(version); | 136 SkString fshaderTxt(version); |
| 136 GrGLAppendGLSLDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, gl->f
Standard, | 137 GrGLAppendGLSLDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, gl->f
Standard, |
| 137 &fshaderTxt); | 138 &fshaderTxt); |
| 138 oColor.setTypeModifier(GrShaderVar::kVaryingIn_TypeModifier); | 139 oColor.setTypeModifier(GrShaderVar::kVaryingIn_TypeModifier); |
| 139 oColor.appendDecl(*ctx, &fshaderTxt); | 140 oColor.appendDecl(ctx->caps()->glslCaps(), &fshaderTxt); |
| 140 fshaderTxt.append(";\n"); | 141 fshaderTxt.append(";\n"); |
| 141 | 142 |
| 142 const char* fsOutName; | 143 const char* fsOutName; |
| 143 if (ctx->caps()->glslCaps()->mustDeclareFragmentShaderOutput()) { | 144 if (ctx->caps()->glslCaps()->mustDeclareFragmentShaderOutput()) { |
| 144 oFragColor.appendDecl(*ctx, &fshaderTxt); | 145 oFragColor.appendDecl(ctx->caps()->glslCaps(), &fshaderTxt); |
| 145 fshaderTxt.append(";\n"); | 146 fshaderTxt.append(";\n"); |
| 146 fsOutName = oFragColor.c_str(); | 147 fsOutName = oFragColor.c_str(); |
| 147 } else { | 148 } else { |
| 148 fsOutName = "gl_FragColor"; | 149 fsOutName = "gl_FragColor"; |
| 149 } | 150 } |
| 150 | 151 |
| 151 fshaderTxt.appendf( | 152 fshaderTxt.appendf( |
| 152 "void main()\n" | 153 "void main()\n" |
| 153 "{\n" | 154 "{\n" |
| 154 "%s = vec4(o_color, 1.0f);\n" | 155 "%s = vec4(o_color, 1.0f);\n" |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench:
:kUseOne_VboSetup, 1) ) | 389 DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench:
:kUseOne_VboSetup, 1) ) |
| 389 DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench:
:kUseTwo_VboSetup, 1) ) | 390 DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench:
:kUseTwo_VboSetup, 1) ) |
| 390 DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench:
:kUseOne_VboSetup, 2) ) | 391 DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench:
:kUseOne_VboSetup, 2) ) |
| 391 DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench:
:kUseTwo_VboSetup, 2) ) | 392 DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench:
:kUseTwo_VboSetup, 2) ) |
| 392 DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench:
:kUseOne_VboSetup, 4) ) | 393 DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench:
:kUseOne_VboSetup, 4) ) |
| 393 DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench:
:kUseTwo_VboSetup, 4) ) | 394 DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench:
:kUseTwo_VboSetup, 4) ) |
| 394 DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench:
:kUseOne_VboSetup, 8) ) | 395 DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench:
:kUseOne_VboSetup, 8) ) |
| 395 DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench:
:kUseTwo_VboSetup, 8) ) | 396 DEF_BENCH( return new GLCpuPosInstancedArraysBench(GLCpuPosInstancedArraysBench:
:kUseTwo_VboSetup, 8) ) |
| 396 | 397 |
| 397 #endif | 398 #endif |
| OLD | NEW |