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 #include <stdio.h> | 20 #include <stdio.h> |
20 | 21 |
21 /* | 22 /* |
22 * 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 |
23 */ | 24 */ |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 GrGLuint GLVertexAttributesBench::setupShader(const GrGLContext* ctx, uint32_t a
ttribs, | 66 GrGLuint GLVertexAttributesBench::setupShader(const GrGLContext* ctx, uint32_t a
ttribs, |
66 uint32_t maxAttribs) { | 67 uint32_t maxAttribs) { |
67 const char* version = GrGLGetGLSLVersionDecl(*ctx); | 68 const char* version = GrGLGetGLSLVersionDecl(*ctx); |
68 | 69 |
69 // setup vertex shader | 70 // setup vertex shader |
70 GrGLShaderVar aPosition("a_position", kVec4f_GrSLType, GrShaderVar::kAttribu
te_TypeModifier); | 71 GrGLShaderVar aPosition("a_position", kVec4f_GrSLType, GrShaderVar::kAttribu
te_TypeModifier); |
71 SkTArray<GrGLShaderVar> aVars; | 72 SkTArray<GrGLShaderVar> aVars; |
72 SkTArray<GrGLShaderVar> oVars; | 73 SkTArray<GrGLShaderVar> oVars; |
73 | 74 |
74 SkString vshaderTxt(version); | 75 SkString vshaderTxt(version); |
75 aPosition.appendDecl(*ctx, &vshaderTxt); | 76 aPosition.appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); |
76 vshaderTxt.append(";\n"); | 77 vshaderTxt.append(";\n"); |
77 | 78 |
78 for (uint32_t i = 0; i < attribs; i++) { | 79 for (uint32_t i = 0; i < attribs; i++) { |
79 SkString aname; | 80 SkString aname; |
80 aname.appendf("a_color_%d", i); | 81 aname.appendf("a_color_%d", i); |
81 aVars.push_back(GrGLShaderVar(aname.c_str(), | 82 aVars.push_back(GrGLShaderVar(aname.c_str(), |
82 kVec4f_GrSLType, | 83 kVec4f_GrSLType, |
83 GrShaderVar::kAttribute_TypeModifier)); | 84 GrShaderVar::kAttribute_TypeModifier)); |
84 aVars.back().appendDecl(*ctx, &vshaderTxt); | 85 aVars.back().appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); |
85 vshaderTxt.append(";\n"); | 86 vshaderTxt.append(";\n"); |
86 | 87 |
87 } | 88 } |
88 | 89 |
89 for (uint32_t i = 0; i < maxAttribs; i++) { | 90 for (uint32_t i = 0; i < maxAttribs; i++) { |
90 SkString oname; | 91 SkString oname; |
91 oname.appendf("o_color_%d", i); | 92 oname.appendf("o_color_%d", i); |
92 oVars.push_back(GrGLShaderVar(oname.c_str(), | 93 oVars.push_back(GrGLShaderVar(oname.c_str(), |
93 kVec4f_GrSLType, | 94 kVec4f_GrSLType, |
94 GrShaderVar::kVaryingOut_TypeModifier)); | 95 GrShaderVar::kVaryingOut_TypeModifier)); |
95 oVars.back().appendDecl(*ctx, &vshaderTxt); | 96 oVars.back().appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); |
96 vshaderTxt.append(";\n"); | 97 vshaderTxt.append(";\n"); |
97 } | 98 } |
98 | 99 |
99 vshaderTxt.append( | 100 vshaderTxt.append( |
100 "void main()\n" | 101 "void main()\n" |
101 "{\n" | 102 "{\n" |
102 "gl_Position = a_position;\n"); | 103 "gl_Position = a_position;\n"); |
103 | 104 |
104 for (uint32_t i = 0; i < attribs; i++) { | 105 for (uint32_t i = 0; i < attribs; i++) { |
105 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()); |
106 } | 107 } |
107 | 108 |
108 // Passthrough position as a dummy | 109 // Passthrough position as a dummy |
109 for (uint32_t i = attribs; i < maxAttribs; i++) { | 110 for (uint32_t i = attribs; i < maxAttribs; i++) { |
110 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()); |
111 } | 112 } |
112 | 113 |
113 vshaderTxt.append("}\n"); | 114 vshaderTxt.append("}\n"); |
114 | 115 |
115 const GrGLInterface* gl = ctx->interface(); | 116 const GrGLInterface* gl = ctx->interface(); |
116 | 117 |
117 // setup fragment shader | 118 // setup fragment shader |
118 GrGLShaderVar oFragColor("o_FragColor", kVec4f_GrSLType, GrShaderVar::kOut_T
ypeModifier); | 119 GrGLShaderVar oFragColor("o_FragColor", kVec4f_GrSLType, GrShaderVar::kOut_T
ypeModifier); |
119 SkString fshaderTxt(version); | 120 SkString fshaderTxt(version); |
120 GrGLAppendGLSLDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, gl->f
Standard, | 121 GrGLAppendGLSLDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, gl->f
Standard, |
121 &fshaderTxt); | 122 &fshaderTxt); |
122 | 123 |
123 const char* fsOutName; | 124 const char* fsOutName; |
124 if (ctx->caps()->glslCaps()->mustDeclareFragmentShaderOutput()) { | 125 if (ctx->caps()->glslCaps()->mustDeclareFragmentShaderOutput()) { |
125 oFragColor.appendDecl(*ctx, &fshaderTxt); | 126 oFragColor.appendDecl(ctx->caps()->glslCaps(), &fshaderTxt); |
126 fshaderTxt.append(";\n"); | 127 fshaderTxt.append(";\n"); |
127 fsOutName = oFragColor.c_str(); | 128 fsOutName = oFragColor.c_str(); |
128 } else { | 129 } else { |
129 fsOutName = "gl_FragColor"; | 130 fsOutName = "gl_FragColor"; |
130 } | 131 } |
131 | 132 |
132 for (uint32_t i = 0; i < maxAttribs; i++) { | 133 for (uint32_t i = 0; i < maxAttribs; i++) { |
133 oVars[i].setTypeModifier(GrShaderVar::kVaryingIn_TypeModifier); | 134 oVars[i].setTypeModifier(GrShaderVar::kVaryingIn_TypeModifier); |
134 oVars[i].appendDecl(*ctx, &fshaderTxt); | 135 oVars[i].appendDecl(ctx->caps()->glslCaps(), &fshaderTxt); |
135 fshaderTxt.append(";\n"); | 136 fshaderTxt.append(";\n"); |
136 } | 137 } |
137 | 138 |
138 fshaderTxt.appendf( | 139 fshaderTxt.appendf( |
139 "void main()\n" | 140 "void main()\n" |
140 "{\n" | 141 "{\n" |
141 "%s = ", fsOutName); | 142 "%s = ", fsOutName); |
142 | 143 |
143 fshaderTxt.appendf("%s", oVars[0].c_str()); | 144 fshaderTxt.appendf("%s", oVars[0].c_str()); |
144 for (uint32_t i = 1; i < maxAttribs; i++) { | 145 for (uint32_t i = 1; i < maxAttribs; i++) { |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 | 261 |
261 DEF_BENCH( return new GLVertexAttributesBench(0) ) | 262 DEF_BENCH( return new GLVertexAttributesBench(0) ) |
262 DEF_BENCH( return new GLVertexAttributesBench(1) ) | 263 DEF_BENCH( return new GLVertexAttributesBench(1) ) |
263 DEF_BENCH( return new GLVertexAttributesBench(2) ) | 264 DEF_BENCH( return new GLVertexAttributesBench(2) ) |
264 DEF_BENCH( return new GLVertexAttributesBench(3) ) | 265 DEF_BENCH( return new GLVertexAttributesBench(3) ) |
265 DEF_BENCH( return new GLVertexAttributesBench(4) ) | 266 DEF_BENCH( return new GLVertexAttributesBench(4) ) |
266 DEF_BENCH( return new GLVertexAttributesBench(5) ) | 267 DEF_BENCH( return new GLVertexAttributesBench(5) ) |
267 DEF_BENCH( return new GLVertexAttributesBench(6) ) | 268 DEF_BENCH( return new GLVertexAttributesBench(6) ) |
268 DEF_BENCH( return new GLVertexAttributesBench(7) ) | 269 DEF_BENCH( return new GLVertexAttributesBench(7) ) |
269 #endif | 270 #endif |
OLD | NEW |