Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(391)

Side by Side Diff: bench/GLVertexAttributesBench.cpp

Issue 1403373012: Make appending default precision be controled by GLSL (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « bench/GLVec4ScalarBench.cpp ('k') | src/gpu/gl/GrGLGLSL.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
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 #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)
(...skipping 30 matching lines...) Expand all
58 uint32_t fAttribs; 58 uint32_t fAttribs;
59 size_t fStride; 59 size_t fStride;
60 SkString fName; 60 SkString fName;
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 = ctx->caps()->glslCaps()->versionDeclString(); 68 const GrGLSLCaps* glslCaps = ctx->caps()->glslCaps();
69 const char* version = glslCaps->versionDeclString();
69 70
70 // setup vertex shader 71 // setup vertex shader
71 GrGLSLShaderVar aPosition("a_position", kVec4f_GrSLType, GrShaderVar::kAttri bute_TypeModifier); 72 GrGLSLShaderVar aPosition("a_position", kVec4f_GrSLType, GrShaderVar::kAttri bute_TypeModifier);
72 SkTArray<GrGLSLShaderVar> aVars; 73 SkTArray<GrGLSLShaderVar> aVars;
73 SkTArray<GrGLSLShaderVar> oVars; 74 SkTArray<GrGLSLShaderVar> oVars;
74 75
75 SkString vshaderTxt(version); 76 SkString vshaderTxt(version);
76 aPosition.appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); 77 aPosition.appendDecl(glslCaps, &vshaderTxt);
77 vshaderTxt.append(";\n"); 78 vshaderTxt.append(";\n");
78 79
79 for (uint32_t i = 0; i < attribs; i++) { 80 for (uint32_t i = 0; i < attribs; i++) {
80 SkString aname; 81 SkString aname;
81 aname.appendf("a_color_%d", i); 82 aname.appendf("a_color_%d", i);
82 aVars.push_back(GrGLSLShaderVar(aname.c_str(), 83 aVars.push_back(GrGLSLShaderVar(aname.c_str(),
83 kVec4f_GrSLType, 84 kVec4f_GrSLType,
84 GrShaderVar::kAttribute_TypeModifier)); 85 GrShaderVar::kAttribute_TypeModifier));
85 aVars.back().appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); 86 aVars.back().appendDecl(glslCaps, &vshaderTxt);
86 vshaderTxt.append(";\n"); 87 vshaderTxt.append(";\n");
87 88
88 } 89 }
89 90
90 for (uint32_t i = 0; i < maxAttribs; i++) { 91 for (uint32_t i = 0; i < maxAttribs; i++) {
91 SkString oname; 92 SkString oname;
92 oname.appendf("o_color_%d", i); 93 oname.appendf("o_color_%d", i);
93 oVars.push_back(GrGLSLShaderVar(oname.c_str(), 94 oVars.push_back(GrGLSLShaderVar(oname.c_str(),
94 kVec4f_GrSLType, 95 kVec4f_GrSLType,
95 GrShaderVar::kVaryingOut_TypeModifier)); 96 GrShaderVar::kVaryingOut_TypeModifier));
96 oVars.back().appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); 97 oVars.back().appendDecl(glslCaps, &vshaderTxt);
97 vshaderTxt.append(";\n"); 98 vshaderTxt.append(";\n");
98 } 99 }
99 100
100 vshaderTxt.append( 101 vshaderTxt.append(
101 "void main()\n" 102 "void main()\n"
102 "{\n" 103 "{\n"
103 "gl_Position = a_position;\n"); 104 "gl_Position = a_position;\n");
104 105
105 for (uint32_t i = 0; i < attribs; i++) { 106 for (uint32_t i = 0; i < attribs; i++) {
106 vshaderTxt.appendf("%s = %s;\n", oVars[i].c_str(), aVars[i].c_str()); 107 vshaderTxt.appendf("%s = %s;\n", oVars[i].c_str(), aVars[i].c_str());
107 } 108 }
108 109
109 // Passthrough position as a dummy 110 // Passthrough position as a dummy
110 for (uint32_t i = attribs; i < maxAttribs; i++) { 111 for (uint32_t i = attribs; i < maxAttribs; i++) {
111 vshaderTxt.appendf("%s = vec4(0, 0, 0, 1);\n", oVars[i].c_str()); 112 vshaderTxt.appendf("%s = vec4(0, 0, 0, 1);\n", oVars[i].c_str());
112 } 113 }
113 114
114 vshaderTxt.append("}\n"); 115 vshaderTxt.append("}\n");
115 116
116 const GrGLInterface* gl = ctx->interface(); 117 const GrGLInterface* gl = ctx->interface();
117 118
118 // setup fragment shader 119 // setup fragment shader
119 GrGLSLShaderVar oFragColor("o_FragColor", kVec4f_GrSLType, GrShaderVar::kOut _TypeModifier); 120 GrGLSLShaderVar oFragColor("o_FragColor", kVec4f_GrSLType, GrShaderVar::kOut _TypeModifier);
120 SkString fshaderTxt(version); 121 SkString fshaderTxt(version);
121 GrGLAppendGLSLDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, gl->f Standard, 122 GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, *glslCa ps, &fshaderTxt);
122 &fshaderTxt);
123 123
124 const char* fsOutName; 124 const char* fsOutName;
125 if (ctx->caps()->glslCaps()->mustDeclareFragmentShaderOutput()) { 125 if (glslCaps->mustDeclareFragmentShaderOutput()) {
126 oFragColor.appendDecl(ctx->caps()->glslCaps(), &fshaderTxt); 126 oFragColor.appendDecl(glslCaps, &fshaderTxt);
127 fshaderTxt.append(";\n"); 127 fshaderTxt.append(";\n");
128 fsOutName = oFragColor.c_str(); 128 fsOutName = oFragColor.c_str();
129 } else { 129 } else {
130 fsOutName = "gl_FragColor"; 130 fsOutName = "gl_FragColor";
131 } 131 }
132 132
133 for (uint32_t i = 0; i < maxAttribs; i++) { 133 for (uint32_t i = 0; i < maxAttribs; i++) {
134 oVars[i].setTypeModifier(GrShaderVar::kVaryingIn_TypeModifier); 134 oVars[i].setTypeModifier(GrShaderVar::kVaryingIn_TypeModifier);
135 oVars[i].appendDecl(ctx->caps()->glslCaps(), &fshaderTxt); 135 oVars[i].appendDecl(glslCaps, &fshaderTxt);
136 fshaderTxt.append(";\n"); 136 fshaderTxt.append(";\n");
137 } 137 }
138 138
139 fshaderTxt.appendf( 139 fshaderTxt.appendf(
140 "void main()\n" 140 "void main()\n"
141 "{\n" 141 "{\n"
142 "%s = ", fsOutName); 142 "%s = ", fsOutName);
143 143
144 fshaderTxt.appendf("%s", oVars[0].c_str()); 144 fshaderTxt.appendf("%s", oVars[0].c_str());
145 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
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
OLDNEW
« no previous file with comments | « bench/GLVec4ScalarBench.cpp ('k') | src/gpu/gl/GrGLGLSL.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698