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

Side by Side Diff: src/gpu/gl/builders/GrGLShaderBuilder.cpp

Issue 1431433003: Move shader compiling to ProgramBuilder and various ShaderBuilder cleanups. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: nits 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 | « src/gpu/gl/builders/GrGLShaderBuilder.h ('k') | src/gpu/gl/builders/GrGLVertexShaderBuilder.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 2014 Google Inc. 2 * Copyright 2014 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 "GrGLShaderBuilder.h" 8 #include "GrGLShaderBuilder.h"
9 #include "GrGLProgramBuilder.h"
10 #include "GrGLShaderStringBuilder.h"
11 #include "gl/GrGLCaps.h"
12 #include "gl/GrGLContext.h"
13 #include "gl/GrGLGpu.h" 9 #include "gl/GrGLGpu.h"
10 #include "gl/builders/GrGLProgramBuilder.h"
14 #include "glsl/GrGLSLCaps.h" 11 #include "glsl/GrGLSLCaps.h"
15 #include "glsl/GrGLSLShaderVar.h" 12 #include "glsl/GrGLSLShaderVar.h"
16 #include "glsl/GrGLSLTextureSampler.h" 13 #include "glsl/GrGLSLTextureSampler.h"
17 14
18 namespace { 15 namespace {
19 void append_texture_lookup(SkString* out, 16 void append_texture_lookup(SkString* out,
20 GrGLGpu* gpu, 17 GrGLGpu* gpu,
21 const char* samplerName, 18 const char* samplerName,
22 const char* coordName, 19 const char* coordName,
23 uint32_t configComponentMask, 20 uint32_t configComponentMask,
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 113
117 void GrGLShaderBuilder::appendTextureLookupAndModulate(const char* modulation, 114 void GrGLShaderBuilder::appendTextureLookupAndModulate(const char* modulation,
118 const GrGLSLTextureSample r& sampler, 115 const GrGLSLTextureSample r& sampler,
119 const char* coordName, 116 const char* coordName,
120 GrSLType varyingType) { 117 GrSLType varyingType) {
121 SkString lookup; 118 SkString lookup;
122 this->appendTextureLookup(&lookup, sampler, coordName, varyingType); 119 this->appendTextureLookup(&lookup, sampler, coordName, varyingType);
123 this->codeAppend((GrGLSLExpr4(modulation) * GrGLSLExpr4(lookup)).c_str()); 120 this->codeAppend((GrGLSLExpr4(modulation) * GrGLSLExpr4(lookup)).c_str());
124 } 121 }
125 122
126
127 const GrGLenum* GrGLShaderBuilder::GetTexParamSwizzle(GrPixelConfig config, cons t GrGLCaps& caps) {
128 if (caps.textureSwizzleSupport() && GrPixelConfigIsAlphaOnly(config)) {
129 if (caps.textureRedSupport()) {
130 static const GrGLenum gRedSmear[] = { GR_GL_RED, GR_GL_RED, GR_GL_RE D, GR_GL_RED };
131 return gRedSmear;
132 } else {
133 static const GrGLenum gAlphaSmear[] = { GR_GL_ALPHA, GR_GL_ALPHA,
134 GR_GL_ALPHA, GR_GL_ALPHA };
135 return gAlphaSmear;
136 }
137 } else {
138 static const GrGLenum gStraight[] = { GR_GL_RED, GR_GL_GREEN, GR_GL_BLUE , GR_GL_ALPHA };
139 return gStraight;
140 }
141 }
142
143 void GrGLShaderBuilder::addFeature(uint32_t featureBit, const char* extensionNam e) { 123 void GrGLShaderBuilder::addFeature(uint32_t featureBit, const char* extensionNam e) {
144 if (!(featureBit & fFeaturesAddedMask)) { 124 if (!(featureBit & fFeaturesAddedMask)) {
145 this->extensions().appendf("#extension %s: require\n", extensionName); 125 this->extensions().appendf("#extension %s: require\n", extensionName);
146 fFeaturesAddedMask |= featureBit; 126 fFeaturesAddedMask |= featureBit;
147 } 127 }
148 } 128 }
149 129
150 void GrGLShaderBuilder::appendDecls(const VarArray& vars, SkString* out) const { 130 void GrGLShaderBuilder::appendDecls(const VarArray& vars, SkString* out) const {
151 for (int i = 0; i < vars.count(); ++i) { 131 for (int i = 0; i < vars.count(); ++i) {
152 vars[i].appendDecl(fProgramBuilder->glslCaps(), out); 132 vars[i].appendDecl(fProgramBuilder->glslCaps(), out);
153 out->append(";\n"); 133 out->append(";\n");
154 } 134 }
155 } 135 }
156 136
157 void GrGLShaderBuilder::appendTextureLookup(const char* samplerName, 137 void GrGLShaderBuilder::appendTextureLookup(const char* samplerName,
158 const char* coordName, 138 const char* coordName,
159 uint32_t configComponentMask, 139 uint32_t configComponentMask,
160 const char* swizzle) { 140 const char* swizzle) {
161 append_texture_lookup(&this->code(), 141 append_texture_lookup(&this->code(),
162 fProgramBuilder->gpu(), 142 fProgramBuilder->gpu(),
163 samplerName, 143 samplerName,
164 coordName, 144 coordName,
165 configComponentMask, 145 configComponentMask,
166 swizzle, 146 swizzle,
167 kVec2f_GrSLType); 147 kVec2f_GrSLType);
168 } 148 }
169 149
170 void GrGLShaderBuilder::addLayoutQualifier(const char* param, InterfaceQualifier interface) { 150 void GrGLShaderBuilder::addLayoutQualifier(const char* param, InterfaceQualifier interface) {
171 SkASSERT(fProgramBuilder->gpu()->glslGeneration() >= k330_GrGLSLGeneration | | 151 SkASSERT(fProgramBuilder->glslCaps()->generation() >= k330_GrGLSLGeneration ||
172 fProgramBuilder->gpu()->glCaps().glslCaps()->mustEnableAdvBlendEqs( )); 152 fProgramBuilder->glslCaps()->mustEnableAdvBlendEqs());
173 fLayoutParams[interface].push_back() = param; 153 fLayoutParams[interface].push_back() = param;
174 } 154 }
175 155
176 void GrGLShaderBuilder::compileAndAppendLayoutQualifiers() { 156 void GrGLShaderBuilder::compileAndAppendLayoutQualifiers() {
177 static const char* interfaceQualifierNames[] = { 157 static const char* interfaceQualifierNames[] = {
178 "out" 158 "out"
179 }; 159 };
180 160
181 for (int interface = 0; interface <= kLastInterfaceQualifier; ++interface) { 161 for (int interface = 0; interface <= kLastInterfaceQualifier; ++interface) {
182 const SkTArray<SkString>& params = fLayoutParams[interface]; 162 const SkTArray<SkString>& params = fLayoutParams[interface];
183 if (params.empty()) { 163 if (params.empty()) {
184 continue; 164 continue;
185 } 165 }
186 this->layoutQualifiers().appendf("layout(%s", params[0].c_str()); 166 this->layoutQualifiers().appendf("layout(%s", params[0].c_str());
187 for (int i = 1; i < params.count(); ++i) { 167 for (int i = 1; i < params.count(); ++i) {
188 this->layoutQualifiers().appendf(", %s", params[i].c_str()); 168 this->layoutQualifiers().appendf(", %s", params[i].c_str());
189 } 169 }
190 this->layoutQualifiers().appendf(") %s;\n", interfaceQualifierNames[inte rface]); 170 this->layoutQualifiers().appendf(") %s;\n", interfaceQualifierNames[inte rface]);
191 } 171 }
192 172
193 GR_STATIC_ASSERT(0 == GrGLShaderBuilder::kOut_InterfaceQualifier); 173 GR_STATIC_ASSERT(0 == GrGLShaderBuilder::kOut_InterfaceQualifier);
194 GR_STATIC_ASSERT(SK_ARRAY_COUNT(interfaceQualifierNames) == kLastInterfaceQu alifier + 1); 174 GR_STATIC_ASSERT(SK_ARRAY_COUNT(interfaceQualifierNames) == kLastInterfaceQu alifier + 1);
195 } 175 }
196 176
197 bool 177 void GrGLShaderBuilder::finalize(uint32_t visibility) {
198 GrGLShaderBuilder::finalize(GrGLuint programId, GrGLenum type, SkTDArray<GrGLuin t>* shaderIds) {
199 SkASSERT(!fFinalized); 178 SkASSERT(!fFinalized);
179 this->versionDecl() = fProgramBuilder->glslCaps()->versionDeclString();
180 this->compileAndAppendLayoutQualifiers();
181 fProgramBuilder->appendUniformDecls((GrGLProgramBuilder::ShaderVisibility) v isibility,
182 &this->uniforms());
183 this->appendDecls(fInputs, &this->inputs());
184 SkASSERT(k110_GrGLSLGeneration != fProgramBuilder->glslCaps()->generation() ||
185 fOutputs.empty());
186 this->appendDecls(fOutputs, &this->outputs());
187 this->onFinalize();
200 // append the 'footer' to code 188 // append the 'footer' to code
201 this->code().append("}"); 189 this->code().append("}");
202 190
203 for (int i = 0; i <= fCodeIndex; i++) { 191 for (int i = 0; i <= fCodeIndex; i++) {
204 fCompilerStrings[i] = fShaderStrings[i].c_str(); 192 fCompilerStrings[i] = fShaderStrings[i].c_str();
205 fCompilerStringLengths[i] = (int)fShaderStrings[i].size(); 193 fCompilerStringLengths[i] = (int)fShaderStrings[i].size();
206 } 194 }
207 195
208 GrGLGpu* gpu = fProgramBuilder->gpu(); 196 fFinalized = true;
209 GrGLuint shaderId = GrGLCompileAndAttachShader(gpu->glContext(), 197 }
210 programId,
211 type,
212 fCompilerStrings.begin(),
213 fCompilerStringLengths.begin( ),
214 fCompilerStrings.count(),
215 gpu->stats());
216 198
217 fFinalized = true;
218
219 if (!shaderId) {
220 return false;
221 }
222
223 *shaderIds->append() = shaderId;
224
225 return true;
226 }
OLDNEW
« no previous file with comments | « src/gpu/gl/builders/GrGLShaderBuilder.h ('k') | src/gpu/gl/builders/GrGLVertexShaderBuilder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698