| 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" | |
| 16 #include "gl/GrGLInterface.h" | 15 #include "gl/GrGLInterface.h" |
| 17 #include "gl/GrGLUtil.h" | 16 #include "gl/GrGLUtil.h" |
| 17 #include "glsl/GrGLSL.h" |
| 18 #include "glsl/GrGLSLCaps.h" | 18 #include "glsl/GrGLSLCaps.h" |
| 19 #include "glsl/GrGLSLShaderVar.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. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 CoverageSetup fCoverageSetup; | 86 CoverageSetup fCoverageSetup; |
| 87 uint32_t fNumStages; | 87 uint32_t fNumStages; |
| 88 GrGLuint fVboId; | 88 GrGLuint fVboId; |
| 89 GrGLuint fProgram; | 89 GrGLuint fProgram; |
| 90 GrGLuint fFboTextureId; | 90 GrGLuint fFboTextureId; |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 93 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 94 | 94 |
| 95 GrGLuint GLVec4ScalarBench::setupShader(const GrGLContext* ctx) { | 95 GrGLuint GLVec4ScalarBench::setupShader(const GrGLContext* ctx) { |
| 96 const char* version = ctx->caps()->glslCaps()->versionDeclString(); | 96 const GrGLSLCaps* glslCaps = ctx->caps()->glslCaps(); |
| 97 const char* version = glslCaps->versionDeclString(); |
| 97 | 98 |
| 98 // this shader draws fNumStages overlapping circles of increasing opacity (c
overage) and | 99 // 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 | 100 // decreasing size, with the center of each subsequent circle closer to the
bottom-right |
| 100 // corner of the screen than the previous circle. | 101 // corner of the screen than the previous circle. |
| 101 | 102 |
| 102 // set up vertex shader; this is a trivial vertex shader that passes through
position and color | 103 // set up vertex shader; this is a trivial vertex shader that passes through
position and color |
| 103 GrGLSLShaderVar aPosition("a_position", kVec2f_GrSLType, GrShaderVar::kAttri
bute_TypeModifier); | 104 GrGLSLShaderVar aPosition("a_position", kVec2f_GrSLType, GrShaderVar::kAttri
bute_TypeModifier); |
| 104 GrGLSLShaderVar oPosition("o_position", kVec2f_GrSLType, GrShaderVar::kVaryi
ngOut_TypeModifier); | 105 GrGLSLShaderVar oPosition("o_position", kVec2f_GrSLType, GrShaderVar::kVaryi
ngOut_TypeModifier); |
| 105 GrGLSLShaderVar aColor("a_color", kVec3f_GrSLType, GrShaderVar::kAttribute_T
ypeModifier); | 106 GrGLSLShaderVar aColor("a_color", kVec3f_GrSLType, GrShaderVar::kAttribute_T
ypeModifier); |
| 106 GrGLSLShaderVar oColor("o_color", kVec3f_GrSLType, GrShaderVar::kVaryingOut_
TypeModifier); | 107 GrGLSLShaderVar oColor("o_color", kVec3f_GrSLType, GrShaderVar::kVaryingOut_
TypeModifier); |
| 107 | 108 |
| 108 SkString vshaderTxt(version); | 109 SkString vshaderTxt(version); |
| 109 aPosition.appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); | 110 aPosition.appendDecl(glslCaps, &vshaderTxt); |
| 110 vshaderTxt.append(";\n"); | 111 vshaderTxt.append(";\n"); |
| 111 aColor.appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); | 112 aColor.appendDecl(glslCaps, &vshaderTxt); |
| 112 vshaderTxt.append(";\n"); | 113 vshaderTxt.append(";\n"); |
| 113 oPosition.appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); | 114 oPosition.appendDecl(glslCaps, &vshaderTxt); |
| 114 vshaderTxt.append(";\n"); | 115 vshaderTxt.append(";\n"); |
| 115 oColor.appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); | 116 oColor.appendDecl(glslCaps, &vshaderTxt); |
| 116 vshaderTxt.append(";\n"); | 117 vshaderTxt.append(";\n"); |
| 117 | 118 |
| 118 vshaderTxt.append( | 119 vshaderTxt.append( |
| 119 "void main()\n" | 120 "void main()\n" |
| 120 "{\n" | 121 "{\n" |
| 121 " gl_Position = vec4(a_position, 0.0, 1.0);\n" | 122 " gl_Position = vec4(a_position, 0.0, 1.0);\n" |
| 122 " o_position = a_position;\n" | 123 " o_position = a_position;\n" |
| 123 " o_color = a_color;\n" | 124 " o_color = a_color;\n" |
| 124 "}\n"); | 125 "}\n"); |
| 125 | 126 |
| 126 const GrGLInterface* gl = ctx->interface(); | 127 const GrGLInterface* gl = ctx->interface(); |
| 127 | 128 |
| 128 // set up fragment shader; this fragment shader will have fNumStages coverag
e stages plus an | 129 // 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- | 130 // 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. | 131 // 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 | 132 // Then, this coverage is mixed with the coverage from the previous stage an
d passed to the |
| 132 // next stage. | 133 // next stage. |
| 133 GrGLSLShaderVar oFragColor("o_FragColor", kVec4f_GrSLType, GrShaderVar::kOut
_TypeModifier); | 134 GrGLSLShaderVar oFragColor("o_FragColor", kVec4f_GrSLType, GrShaderVar::kOut
_TypeModifier); |
| 134 SkString fshaderTxt(version); | 135 SkString fshaderTxt(version); |
| 135 GrGLAppendGLSLDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, gl->f
Standard, | 136 GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, *glslCa
ps, &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(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(glslCaps, &fshaderTxt); |
| 142 fshaderTxt.append(";\n"); | 142 fshaderTxt.append(";\n"); |
| 143 | 143 |
| 144 const char* fsOutName; | 144 const char* fsOutName; |
| 145 if (ctx->caps()->glslCaps()->mustDeclareFragmentShaderOutput()) { | 145 if (glslCaps->mustDeclareFragmentShaderOutput()) { |
| 146 oFragColor.appendDecl(ctx->caps()->glslCaps(), &fshaderTxt); | 146 oFragColor.appendDecl(glslCaps, &fshaderTxt); |
| 147 fshaderTxt.append(";\n"); | 147 fshaderTxt.append(";\n"); |
| 148 fsOutName = oFragColor.c_str(); | 148 fsOutName = oFragColor.c_str(); |
| 149 } else { | 149 } else { |
| 150 fsOutName = "gl_FragColor"; | 150 fsOutName = "gl_FragColor"; |
| 151 } | 151 } |
| 152 | 152 |
| 153 | 153 |
| 154 fshaderTxt.appendf( | 154 fshaderTxt.appendf( |
| 155 "void main()\n" | 155 "void main()\n" |
| 156 "{\n" | 156 "{\n" |
| (...skipping 138 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 |