| 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 "SkMatrix.h" | 8 #include "SkMatrix.h" |
| 9 #include "SkPoint.h" | 9 #include "SkPoint.h" |
| 10 #include "SkString.h" | 10 #include "SkString.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/GrGLContext.h" |
| 15 #include "gl/GrGLGLSL.h" | 15 #include "gl/GrGLGLSL.h" |
| 16 #include "gl/GrGLInterface.h" | 16 #include "gl/GrGLInterface.h" |
| 17 #include "gl/GrGLShaderVar.h" | |
| 18 #include "gl/GrGLUtil.h" | 17 #include "gl/GrGLUtil.h" |
| 19 #include "glsl/GrGLSLCaps.h" | 18 #include "glsl/GrGLSLCaps.h" |
| 19 #include "glsl/GrGLSLShaderVar.h" |
| 20 | 20 |
| 21 #include <stdio.h> | 21 #include <stdio.h> |
| 22 | 22 |
| 23 /** | 23 /** |
| 24 * This is a GL benchmark for comparing the performance of using vec4 or float f
or coverage in GLSL. | 24 * This is a GL benchmark for comparing the performance of using vec4 or float f
or coverage in GLSL. |
| 25 * The generated shader code from this bench will draw several overlapping circl
es, one in each | 25 * The generated shader code from this bench will draw several overlapping circl
es, one in each |
| 26 * stage, to simulate coverage calculations. The number of circles (i.e. the nu
mber of stages) can | 26 * stage, to simulate coverage calculations. The number of circles (i.e. the nu
mber of stages) can |
| 27 * be set as a parameter. | 27 * be set as a parameter. |
| 28 */ | 28 */ |
| 29 | 29 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 93 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 94 | 94 |
| 95 GrGLuint GLVec4ScalarBench::setupShader(const GrGLContext* ctx) { | 95 GrGLuint GLVec4ScalarBench::setupShader(const GrGLContext* ctx) { |
| 96 const char* version = GrGLGetGLSLVersionDecl(*ctx); | 96 const char* version = GrGLGetGLSLVersionDecl(*ctx); |
| 97 | 97 |
| 98 // this shader draws fNumStages overlapping circles of increasing opacity (c
overage) and | 98 // this shader draws fNumStages overlapping circles of increasing opacity (c
overage) and |
| 99 // decreasing size, with the center of each subsequent circle closer to the
bottom-right | 99 // decreasing size, with the center of each subsequent circle closer to the
bottom-right |
| 100 // corner of the screen than the previous circle. | 100 // corner of the screen than the previous circle. |
| 101 | 101 |
| 102 // set up vertex shader; this is a trivial vertex shader that passes through
position and color | 102 // set up vertex shader; this is a trivial vertex shader that passes through
position and color |
| 103 GrGLShaderVar aPosition("a_position", kVec2f_GrSLType, GrShaderVar::kAttribu
te_TypeModifier); | 103 GrGLSLShaderVar aPosition("a_position", kVec2f_GrSLType, GrShaderVar::kAttri
bute_TypeModifier); |
| 104 GrGLShaderVar oPosition("o_position", kVec2f_GrSLType, GrShaderVar::kVarying
Out_TypeModifier); | 104 GrGLSLShaderVar oPosition("o_position", kVec2f_GrSLType, GrShaderVar::kVaryi
ngOut_TypeModifier); |
| 105 GrGLShaderVar aColor("a_color", kVec3f_GrSLType, GrShaderVar::kAttribute_Typ
eModifier); | 105 GrGLSLShaderVar aColor("a_color", kVec3f_GrSLType, GrShaderVar::kAttribute_T
ypeModifier); |
| 106 GrGLShaderVar oColor("o_color", kVec3f_GrSLType, GrShaderVar::kVaryingOut_Ty
peModifier); | 106 GrGLSLShaderVar oColor("o_color", kVec3f_GrSLType, GrShaderVar::kVaryingOut_
TypeModifier); |
| 107 | 107 |
| 108 SkString vshaderTxt(version); | 108 SkString vshaderTxt(version); |
| 109 aPosition.appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); | 109 aPosition.appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); |
| 110 vshaderTxt.append(";\n"); | 110 vshaderTxt.append(";\n"); |
| 111 aColor.appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); | 111 aColor.appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); |
| 112 vshaderTxt.append(";\n"); | 112 vshaderTxt.append(";\n"); |
| 113 oPosition.appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); | 113 oPosition.appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); |
| 114 vshaderTxt.append(";\n"); | 114 vshaderTxt.append(";\n"); |
| 115 oColor.appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); | 115 oColor.appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); |
| 116 vshaderTxt.append(";\n"); | 116 vshaderTxt.append(";\n"); |
| 117 | 117 |
| 118 vshaderTxt.append( | 118 vshaderTxt.append( |
| 119 "void main()\n" | 119 "void main()\n" |
| 120 "{\n" | 120 "{\n" |
| 121 " gl_Position = vec4(a_position, 0.0, 1.0);\n" | 121 " gl_Position = vec4(a_position, 0.0, 1.0);\n" |
| 122 " o_position = a_position;\n" | 122 " o_position = a_position;\n" |
| 123 " o_color = a_color;\n" | 123 " o_color = a_color;\n" |
| 124 "}\n"); | 124 "}\n"); |
| 125 | 125 |
| 126 const GrGLInterface* gl = ctx->interface(); | 126 const GrGLInterface* gl = ctx->interface(); |
| 127 | 127 |
| 128 // set up fragment shader; this fragment shader will have fNumStages coverag
e stages plus an | 128 // set up fragment shader; this fragment shader will have fNumStages coverag
e stages plus an |
| 129 // XP stage at the end. Each coverage stage computes the pixel's distance f
rom some hard- | 129 // XP stage at the end. Each coverage stage computes the pixel's distance f
rom some hard- |
| 130 // coded center and compare that to some hard-coded circle radius to compute
a coverage. | 130 // coded center and compare that to some hard-coded circle radius to compute
a coverage. |
| 131 // Then, this coverage is mixed with the coverage from the previous stage an
d passed to the | 131 // Then, this coverage is mixed with the coverage from the previous stage an
d passed to the |
| 132 // next stage. | 132 // next stage. |
| 133 GrGLShaderVar oFragColor("o_FragColor", kVec4f_GrSLType, GrShaderVar::kOut_T
ypeModifier); | 133 GrGLSLShaderVar oFragColor("o_FragColor", kVec4f_GrSLType, GrShaderVar::kOut
_TypeModifier); |
| 134 SkString fshaderTxt(version); | 134 SkString fshaderTxt(version); |
| 135 GrGLAppendGLSLDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, gl->f
Standard, | 135 GrGLAppendGLSLDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, gl->f
Standard, |
| 136 &fshaderTxt); | 136 &fshaderTxt); |
| 137 oPosition.setTypeModifier(GrShaderVar::kVaryingIn_TypeModifier); | 137 oPosition.setTypeModifier(GrShaderVar::kVaryingIn_TypeModifier); |
| 138 oPosition.appendDecl(ctx->caps()->glslCaps(), &fshaderTxt); | 138 oPosition.appendDecl(ctx->caps()->glslCaps(), &fshaderTxt); |
| 139 fshaderTxt.append(";\n"); | 139 fshaderTxt.append(";\n"); |
| 140 oColor.setTypeModifier(GrShaderVar::kVaryingIn_TypeModifier); | 140 oColor.setTypeModifier(GrShaderVar::kVaryingIn_TypeModifier); |
| 141 oColor.appendDecl(ctx->caps()->glslCaps(), &fshaderTxt); | 141 oColor.appendDecl(ctx->caps()->glslCaps(), &fshaderTxt); |
| 142 fshaderTxt.append(";\n"); | 142 fshaderTxt.append(";\n"); |
| 143 | 143 |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseScalar_CoverageSe
tup, 2) ) | 295 DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseScalar_CoverageSe
tup, 2) ) |
| 296 DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseVec4_CoverageSetu
p, 2) ) | 296 DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseVec4_CoverageSetu
p, 2) ) |
| 297 DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseScalar_CoverageSe
tup, 4) ) | 297 DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseScalar_CoverageSe
tup, 4) ) |
| 298 DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseVec4_CoverageSetu
p, 4) ) | 298 DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseVec4_CoverageSetu
p, 4) ) |
| 299 DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseScalar_CoverageSe
tup, 6) ) | 299 DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseScalar_CoverageSe
tup, 6) ) |
| 300 DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseVec4_CoverageSetu
p, 6) ) | 300 DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseVec4_CoverageSetu
p, 6) ) |
| 301 DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseScalar_CoverageSe
tup, 8) ) | 301 DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseScalar_CoverageSe
tup, 8) ) |
| 302 DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseVec4_CoverageSetu
p, 8) ) | 302 DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseVec4_CoverageSetu
p, 8) ) |
| 303 | 303 |
| 304 #endif | 304 #endif |
| OLD | NEW |