| 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/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 #include <stdio.h> | 20 #include <stdio.h> |
| 21 | 21 |
| 22 /* | 22 /* |
| 23 * This is a native GL benchmark for determining the cost of uploading vertex at
tributes | 23 * This is a native GL benchmark for determining the cost of uploading vertex at
tributes |
| 24 */ | 24 */ |
| 25 class GLVertexAttributesBench : public GLBench { | 25 class GLVertexAttributesBench : public GLBench { |
| 26 public: | 26 public: |
| 27 GLVertexAttributesBench(uint32_t attribs) | 27 GLVertexAttributesBench(uint32_t attribs) |
| 28 : fTexture(0) | 28 : fTexture(0) |
| 29 , fBuffers(0) | 29 , fBuffers(0) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 typedef Benchmark INHERITED; | 61 typedef Benchmark INHERITED; |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 64 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 65 | 65 |
| 66 GrGLuint GLVertexAttributesBench::setupShader(const GrGLContext* ctx, uint32_t a
ttribs, | 66 GrGLuint GLVertexAttributesBench::setupShader(const GrGLContext* ctx, uint32_t a
ttribs, |
| 67 uint32_t maxAttribs) { | 67 uint32_t maxAttribs) { |
| 68 const char* version = GrGLGetGLSLVersionDecl(*ctx); | 68 const char* version = GrGLGetGLSLVersionDecl(*ctx); |
| 69 | 69 |
| 70 // setup vertex shader | 70 // setup vertex shader |
| 71 GrGLShaderVar aPosition("a_position", kVec4f_GrSLType, GrShaderVar::kAttribu
te_TypeModifier); | 71 GrGLSLShaderVar aPosition("a_position", kVec4f_GrSLType, GrShaderVar::kAttri
bute_TypeModifier); |
| 72 SkTArray<GrGLShaderVar> aVars; | 72 SkTArray<GrGLSLShaderVar> aVars; |
| 73 SkTArray<GrGLShaderVar> oVars; | 73 SkTArray<GrGLSLShaderVar> oVars; |
| 74 | 74 |
| 75 SkString vshaderTxt(version); | 75 SkString vshaderTxt(version); |
| 76 aPosition.appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); | 76 aPosition.appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); |
| 77 vshaderTxt.append(";\n"); | 77 vshaderTxt.append(";\n"); |
| 78 | 78 |
| 79 for (uint32_t i = 0; i < attribs; i++) { | 79 for (uint32_t i = 0; i < attribs; i++) { |
| 80 SkString aname; | 80 SkString aname; |
| 81 aname.appendf("a_color_%d", i); | 81 aname.appendf("a_color_%d", i); |
| 82 aVars.push_back(GrGLShaderVar(aname.c_str(), | 82 aVars.push_back(GrGLSLShaderVar(aname.c_str(), |
| 83 kVec4f_GrSLType, | 83 kVec4f_GrSLType, |
| 84 GrShaderVar::kAttribute_TypeModifier)); | 84 GrShaderVar::kAttribute_TypeModifier)); |
| 85 aVars.back().appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); | 85 aVars.back().appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); |
| 86 vshaderTxt.append(";\n"); | 86 vshaderTxt.append(";\n"); |
| 87 | 87 |
| 88 } | 88 } |
| 89 | 89 |
| 90 for (uint32_t i = 0; i < maxAttribs; i++) { | 90 for (uint32_t i = 0; i < maxAttribs; i++) { |
| 91 SkString oname; | 91 SkString oname; |
| 92 oname.appendf("o_color_%d", i); | 92 oname.appendf("o_color_%d", i); |
| 93 oVars.push_back(GrGLShaderVar(oname.c_str(), | 93 oVars.push_back(GrGLSLShaderVar(oname.c_str(), |
| 94 kVec4f_GrSLType, | 94 kVec4f_GrSLType, |
| 95 GrShaderVar::kVaryingOut_TypeModifier)); | 95 GrShaderVar::kVaryingOut_TypeModifier)); |
| 96 oVars.back().appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); | 96 oVars.back().appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); |
| 97 vshaderTxt.append(";\n"); | 97 vshaderTxt.append(";\n"); |
| 98 } | 98 } |
| 99 | 99 |
| 100 vshaderTxt.append( | 100 vshaderTxt.append( |
| 101 "void main()\n" | 101 "void main()\n" |
| 102 "{\n" | 102 "{\n" |
| 103 "gl_Position = a_position;\n"); | 103 "gl_Position = a_position;\n"); |
| 104 | 104 |
| 105 for (uint32_t i = 0; i < attribs; i++) { | 105 for (uint32_t i = 0; i < attribs; i++) { |
| 106 vshaderTxt.appendf("%s = %s;\n", oVars[i].c_str(), aVars[i].c_str()); | 106 vshaderTxt.appendf("%s = %s;\n", oVars[i].c_str(), aVars[i].c_str()); |
| 107 } | 107 } |
| 108 | 108 |
| 109 // Passthrough position as a dummy | 109 // Passthrough position as a dummy |
| 110 for (uint32_t i = attribs; i < maxAttribs; i++) { | 110 for (uint32_t i = attribs; i < maxAttribs; i++) { |
| 111 vshaderTxt.appendf("%s = vec4(0, 0, 0, 1);\n", oVars[i].c_str()); | 111 vshaderTxt.appendf("%s = vec4(0, 0, 0, 1);\n", oVars[i].c_str()); |
| 112 } | 112 } |
| 113 | 113 |
| 114 vshaderTxt.append("}\n"); | 114 vshaderTxt.append("}\n"); |
| 115 | 115 |
| 116 const GrGLInterface* gl = ctx->interface(); | 116 const GrGLInterface* gl = ctx->interface(); |
| 117 | 117 |
| 118 // setup fragment shader | 118 // setup fragment shader |
| 119 GrGLShaderVar oFragColor("o_FragColor", kVec4f_GrSLType, GrShaderVar::kOut_T
ypeModifier); | 119 GrGLSLShaderVar oFragColor("o_FragColor", kVec4f_GrSLType, GrShaderVar::kOut
_TypeModifier); |
| 120 SkString fshaderTxt(version); | 120 SkString fshaderTxt(version); |
| 121 GrGLAppendGLSLDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, gl->f
Standard, | 121 GrGLAppendGLSLDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, gl->f
Standard, |
| 122 &fshaderTxt); | 122 &fshaderTxt); |
| 123 | 123 |
| 124 const char* fsOutName; | 124 const char* fsOutName; |
| 125 if (ctx->caps()->glslCaps()->mustDeclareFragmentShaderOutput()) { | 125 if (ctx->caps()->glslCaps()->mustDeclareFragmentShaderOutput()) { |
| 126 oFragColor.appendDecl(ctx->caps()->glslCaps(), &fshaderTxt); | 126 oFragColor.appendDecl(ctx->caps()->glslCaps(), &fshaderTxt); |
| 127 fshaderTxt.append(";\n"); | 127 fshaderTxt.append(";\n"); |
| 128 fsOutName = oFragColor.c_str(); | 128 fsOutName = oFragColor.c_str(); |
| 129 } else { | 129 } else { |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 | 261 |
| 262 DEF_BENCH( return new GLVertexAttributesBench(0) ) | 262 DEF_BENCH( return new GLVertexAttributesBench(0) ) |
| 263 DEF_BENCH( return new GLVertexAttributesBench(1) ) | 263 DEF_BENCH( return new GLVertexAttributesBench(1) ) |
| 264 DEF_BENCH( return new GLVertexAttributesBench(2) ) | 264 DEF_BENCH( return new GLVertexAttributesBench(2) ) |
| 265 DEF_BENCH( return new GLVertexAttributesBench(3) ) | 265 DEF_BENCH( return new GLVertexAttributesBench(3) ) |
| 266 DEF_BENCH( return new GLVertexAttributesBench(4) ) | 266 DEF_BENCH( return new GLVertexAttributesBench(4) ) |
| 267 DEF_BENCH( return new GLVertexAttributesBench(5) ) | 267 DEF_BENCH( return new GLVertexAttributesBench(5) ) |
| 268 DEF_BENCH( return new GLVertexAttributesBench(6) ) | 268 DEF_BENCH( return new GLVertexAttributesBench(6) ) |
| 269 DEF_BENCH( return new GLVertexAttributesBench(7) ) | 269 DEF_BENCH( return new GLVertexAttributesBench(7) ) |
| 270 #endif | 270 #endif |
| OLD | NEW |