| 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/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 #include <stdio.h> | 21 #include <stdio.h> |
| 21 | 22 |
| 22 /** | 23 /** |
| 23 * 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. |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 // 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 |
| 99 // corner of the screen than the previous circle. | 100 // corner of the screen than the previous circle. |
| 100 | 101 |
| 101 // 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 |
| 102 GrGLShaderVar aPosition("a_position", kVec2f_GrSLType, GrShaderVar::kAttribu
te_TypeModifier); | 103 GrGLShaderVar aPosition("a_position", kVec2f_GrSLType, GrShaderVar::kAttribu
te_TypeModifier); |
| 103 GrGLShaderVar oPosition("o_position", kVec2f_GrSLType, GrShaderVar::kVarying
Out_TypeModifier); | 104 GrGLShaderVar oPosition("o_position", kVec2f_GrSLType, GrShaderVar::kVarying
Out_TypeModifier); |
| 104 GrGLShaderVar aColor("a_color", kVec3f_GrSLType, GrShaderVar::kAttribute_Typ
eModifier); | 105 GrGLShaderVar aColor("a_color", kVec3f_GrSLType, GrShaderVar::kAttribute_Typ
eModifier); |
| 105 GrGLShaderVar oColor("o_color", kVec3f_GrSLType, GrShaderVar::kVaryingOut_Ty
peModifier); | 106 GrGLShaderVar oColor("o_color", kVec3f_GrSLType, GrShaderVar::kVaryingOut_Ty
peModifier); |
| 106 | 107 |
| 107 SkString vshaderTxt(version); | 108 SkString vshaderTxt(version); |
| 108 aPosition.appendDecl(*ctx, &vshaderTxt); | 109 aPosition.appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); |
| 109 vshaderTxt.append(";\n"); | 110 vshaderTxt.append(";\n"); |
| 110 aColor.appendDecl(*ctx, &vshaderTxt); | 111 aColor.appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); |
| 111 vshaderTxt.append(";\n"); | 112 vshaderTxt.append(";\n"); |
| 112 oPosition.appendDecl(*ctx, &vshaderTxt); | 113 oPosition.appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); |
| 113 vshaderTxt.append(";\n"); | 114 vshaderTxt.append(";\n"); |
| 114 oColor.appendDecl(*ctx, &vshaderTxt); | 115 oColor.appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); |
| 115 vshaderTxt.append(";\n"); | 116 vshaderTxt.append(";\n"); |
| 116 | 117 |
| 117 vshaderTxt.append( | 118 vshaderTxt.append( |
| 118 "void main()\n" | 119 "void main()\n" |
| 119 "{\n" | 120 "{\n" |
| 120 " gl_Position = vec4(a_position, 0.0, 1.0);\n" | 121 " gl_Position = vec4(a_position, 0.0, 1.0);\n" |
| 121 " o_position = a_position;\n" | 122 " o_position = a_position;\n" |
| 122 " o_color = a_color;\n" | 123 " o_color = a_color;\n" |
| 123 "}\n"); | 124 "}\n"); |
| 124 | 125 |
| 125 const GrGLInterface* gl = ctx->interface(); | 126 const GrGLInterface* gl = ctx->interface(); |
| 126 | 127 |
| 127 // 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 |
| 128 // 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- |
| 129 // 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. |
| 130 // 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 |
| 131 // next stage. | 132 // next stage. |
| 132 GrGLShaderVar oFragColor("o_FragColor", kVec4f_GrSLType, GrShaderVar::kOut_T
ypeModifier); | 133 GrGLShaderVar oFragColor("o_FragColor", kVec4f_GrSLType, GrShaderVar::kOut_T
ypeModifier); |
| 133 SkString fshaderTxt(version); | 134 SkString fshaderTxt(version); |
| 134 GrGLAppendGLSLDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, gl->f
Standard, | 135 GrGLAppendGLSLDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, gl->f
Standard, |
| 135 &fshaderTxt); | 136 &fshaderTxt); |
| 136 oPosition.setTypeModifier(GrShaderVar::kVaryingIn_TypeModifier); | 137 oPosition.setTypeModifier(GrShaderVar::kVaryingIn_TypeModifier); |
| 137 oPosition.appendDecl(*ctx, &fshaderTxt); | 138 oPosition.appendDecl(ctx->caps()->glslCaps(), &fshaderTxt); |
| 138 fshaderTxt.append(";\n"); | 139 fshaderTxt.append(";\n"); |
| 139 oColor.setTypeModifier(GrShaderVar::kVaryingIn_TypeModifier); | 140 oColor.setTypeModifier(GrShaderVar::kVaryingIn_TypeModifier); |
| 140 oColor.appendDecl(*ctx, &fshaderTxt); | 141 oColor.appendDecl(ctx->caps()->glslCaps(), &fshaderTxt); |
| 141 fshaderTxt.append(";\n"); | 142 fshaderTxt.append(";\n"); |
| 142 | 143 |
| 143 const char* fsOutName; | 144 const char* fsOutName; |
| 144 if (ctx->caps()->glslCaps()->mustDeclareFragmentShaderOutput()) { | 145 if (ctx->caps()->glslCaps()->mustDeclareFragmentShaderOutput()) { |
| 145 oFragColor.appendDecl(*ctx, &fshaderTxt); | 146 oFragColor.appendDecl(ctx->caps()->glslCaps(), &fshaderTxt); |
| 146 fshaderTxt.append(";\n"); | 147 fshaderTxt.append(";\n"); |
| 147 fsOutName = oFragColor.c_str(); | 148 fsOutName = oFragColor.c_str(); |
| 148 } else { | 149 } else { |
| 149 fsOutName = "gl_FragColor"; | 150 fsOutName = "gl_FragColor"; |
| 150 } | 151 } |
| 151 | 152 |
| 152 | 153 |
| 153 fshaderTxt.appendf( | 154 fshaderTxt.appendf( |
| 154 "void main()\n" | 155 "void main()\n" |
| 155 "{\n" | 156 "{\n" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseScalar_CoverageSe
tup, 2) ) | 295 DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseScalar_CoverageSe
tup, 2) ) |
| 295 DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseVec4_CoverageSetu
p, 2) ) | 296 DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseVec4_CoverageSetu
p, 2) ) |
| 296 DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseScalar_CoverageSe
tup, 4) ) | 297 DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseScalar_CoverageSe
tup, 4) ) |
| 297 DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseVec4_CoverageSetu
p, 4) ) | 298 DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseVec4_CoverageSetu
p, 4) ) |
| 298 DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseScalar_CoverageSe
tup, 6) ) | 299 DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseScalar_CoverageSe
tup, 6) ) |
| 299 DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseVec4_CoverageSetu
p, 6) ) | 300 DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseVec4_CoverageSetu
p, 6) ) |
| 300 DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseScalar_CoverageSe
tup, 8) ) | 301 DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseScalar_CoverageSe
tup, 8) ) |
| 301 DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseVec4_CoverageSetu
p, 8) ) | 302 DEF_BENCH( return new GLVec4ScalarBench(GLVec4ScalarBench::kUseVec4_CoverageSetu
p, 8) ) |
| 302 | 303 |
| 303 #endif | 304 #endif |
| OLD | NEW |