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

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

Issue 304383002: Make GrGLShaderBuilder store a GenProgramOutput (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Attempt to revert angle changes Created 6 years, 6 months 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 | Annotate | Revision Log
« no previous file with comments | « src/gpu/gl/GrGLShaderBuilder.h ('k') | no next file » | 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 2012 Google Inc. 2 * Copyright 2012 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 "gl/GrGLShaderBuilder.h" 8 #include "gl/GrGLShaderBuilder.h"
9 #include "gl/GrGLProgram.h" 9 #include "gl/GrGLProgram.h"
10 #include "gl/GrGLUniformHandle.h" 10 #include "gl/GrGLUniformHandle.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 static const char kDstCopyColorName[] = "_dstColor"; 88 static const char kDstCopyColorName[] = "_dstColor";
89 89
90 /////////////////////////////////////////////////////////////////////////////// 90 ///////////////////////////////////////////////////////////////////////////////
91 91
92 bool GrGLShaderBuilder::GenProgram(GrGpuGL* gpu, 92 bool GrGLShaderBuilder::GenProgram(GrGpuGL* gpu,
93 GrGLUniformManager* uman, 93 GrGLUniformManager* uman,
94 const GrGLProgramDesc& desc, 94 const GrGLProgramDesc& desc,
95 const GrEffectStage* inColorStages[], 95 const GrEffectStage* inColorStages[],
96 const GrEffectStage* inCoverageStages[], 96 const GrEffectStage* inCoverageStages[],
97 GenProgramOutput* output) { 97 GenProgramOutput* output) {
98 SkAutoTDelete<GrGLShaderBuilder> builder;
98 if (desc.getHeader().fHasVertexCode ||!gpu->shouldUseFixedFunctionTexturing( )) { 99 if (desc.getHeader().fHasVertexCode ||!gpu->shouldUseFixedFunctionTexturing( )) {
99 GrGLFullShaderBuilder fullBuilder(gpu, uman, desc); 100 builder.reset(SkNEW_ARGS(GrGLFullShaderBuilder, (gpu, uman, desc)));
100 if (fullBuilder.genProgram(inColorStages, inCoverageStages, output)) {
101 output->fHasVS = true;
102 output->fUniformHandles.fViewMatrixUni = fullBuilder.getViewMatrixUn iform();
103 output->fUniformHandles.fRTAdjustmentUni = fullBuilder.getRTAdjustme ntVecUniform();
104 return true;
105 }
106 } else { 101 } else {
107 GrGLFragmentOnlyShaderBuilder fragmentOnlyBuilder(gpu, uman, desc); 102 builder.reset(SkNEW_ARGS(GrGLFragmentOnlyShaderBuilder, (gpu, uman, desc )));
108 if (fragmentOnlyBuilder.genProgram(inColorStages, inCoverageStages, outp ut)) { 103 }
109 output->fHasVS = false; 104 if (builder->genProgram(inColorStages, inCoverageStages)) {
110 output->fNumTexCoordSets = fragmentOnlyBuilder.getNumTexCoordSets(); 105 *output = builder->getOutput();
111 return true; 106 return true;
112 }
113 } 107 }
114 return false; 108 return false;
115 } 109 }
116 110
117 bool GrGLShaderBuilder::genProgram(const GrEffectStage* colorStages[], 111 bool GrGLShaderBuilder::genProgram(const GrEffectStage* colorStages[],
118 const GrEffectStage* coverageStages[], 112 const GrEffectStage* coverageStages[]) {
119 GenProgramOutput* output) {
120 const GrGLProgramDesc::KeyHeader& header = this->desc().getHeader(); 113 const GrGLProgramDesc::KeyHeader& header = this->desc().getHeader();
121 114
122 // incoming color to current stage being processed. 115 // incoming color to current stage being processed.
123 GrGLSLExpr4 inColor = this->getInputColor(); 116 GrGLSLExpr4 inColor = this->getInputColor();
124 117
125 output->fColorEffects = 118 fOutput.fColorEffects =
126 this->createAndEmitEffects(colorStages, 119 this->createAndEmitEffects(colorStages,
127 this->desc().getEffectKeys(), 120 this->desc().getEffectKeys(),
128 this->desc().numColorEffects(), 121 this->desc().numColorEffects(),
129 &inColor); 122 &inColor);
130 123
131 /////////////////////////////////////////////////////////////////////////// 124 ///////////////////////////////////////////////////////////////////////////
132 // compute the partial coverage 125 // compute the partial coverage
133 GrGLSLExpr4 inCoverage = this->getInputCoverage(); 126 GrGLSLExpr4 inCoverage = this->getInputCoverage();
134 127
135 output->fCoverageEffects = 128 fOutput.fCoverageEffects =
136 this->createAndEmitEffects(coverageStages, 129 this->createAndEmitEffects(coverageStages,
137 this->desc().getEffectKeys() + this->desc(). numColorEffects(), 130 this->desc().getEffectKeys() + this->desc(). numColorEffects(),
138 this->desc().numCoverageEffects(), 131 this->desc().numCoverageEffects(),
139 &inCoverage); 132 &inCoverage);
140 133
141 if (GrGLProgramDesc::CoverageOutputUsesSecondaryOutput(header.fCoverageOutpu t)) { 134 if (GrGLProgramDesc::CoverageOutputUsesSecondaryOutput(header.fCoverageOutpu t)) {
142 const char* secondaryOutputName = this->enableSecondaryOutput(); 135 const char* secondaryOutputName = this->enableSecondaryOutput();
143 136
144 // default coeff to ones for kCoverage_DualSrcOutput 137 // default coeff to ones for kCoverage_DualSrcOutput
145 GrGLSLExpr4 coeff(1); 138 GrGLSLExpr4 coeff(1);
(...skipping 17 matching lines...) Expand all
163 // Now tack on "+(1-coverage)dst onto the frag color if we were asked to do so. 156 // Now tack on "+(1-coverage)dst onto the frag color if we were asked to do so.
164 if (GrGLProgramDesc::kCombineWithDst_CoverageOutput == header.fCoverageOutpu t) { 157 if (GrGLProgramDesc::kCombineWithDst_CoverageOutput == header.fCoverageOutpu t) {
165 GrGLSLExpr4 dstCoeff = GrGLSLExpr4(1) - inCoverage; 158 GrGLSLExpr4 dstCoeff = GrGLSLExpr4(1) - inCoverage;
166 159
167 GrGLSLExpr4 dstContribution = dstCoeff * GrGLSLExpr4(this->dstColor()); 160 GrGLSLExpr4 dstContribution = dstCoeff * GrGLSLExpr4(this->dstColor());
168 161
169 fragColor = fragColor + dstContribution; 162 fragColor = fragColor + dstContribution;
170 } 163 }
171 this->fsCodeAppendf("\t%s = %s;\n", this->getColorOutputName(), fragColor.c_ str()); 164 this->fsCodeAppendf("\t%s = %s;\n", this->getColorOutputName(), fragColor.c_ str());
172 165
173 if (!this->finish(&output->fProgramID)) { 166 if (!this->finish()) {
174 return false; 167 return false;
175 } 168 }
176 169
177 output->fUniformHandles.fRTHeightUni = fRTHeightUniform;
178 output->fUniformHandles.fColorUni = fColorUniform;
179 output->fUniformHandles.fCoverageUni = fCoverageUniform;
180 output->fUniformHandles.fDstCopyTopLeftUni = fDstCopyTopLeftUniform;
181 output->fUniformHandles.fDstCopyScaleUni = fDstCopyScaleUniform;
182 output->fUniformHandles.fDstCopySamplerUni = fDstCopySamplerUniform;
183
184 return true; 170 return true;
185 } 171 }
186 172
187 ////////////////////////////////////////////////////////////////////////////// 173 //////////////////////////////////////////////////////////////////////////////
188 174
189 GrGLShaderBuilder::GrGLShaderBuilder(GrGpuGL* gpu, 175 GrGLShaderBuilder::GrGLShaderBuilder(GrGpuGL* gpu,
190 GrGLUniformManager* uniformManager, 176 GrGLUniformManager* uniformManager,
191 const GrGLProgramDesc& desc) 177 const GrGLProgramDesc& desc)
192 : fDesc(desc) 178 : fDesc(desc)
193 , fGpu(gpu) 179 , fGpu(gpu)
194 , fUniformManager(SkRef(uniformManager)) 180 , fUniformManager(SkRef(uniformManager))
195 , fFSFeaturesAddedMask(0) 181 , fFSFeaturesAddedMask(0)
196 , fFSInputs(kVarsPerBlock) 182 , fFSInputs(kVarsPerBlock)
197 , fFSOutputs(kMaxFSOutputs) 183 , fFSOutputs(kMaxFSOutputs)
198 , fUniforms(kVarsPerBlock) 184 , fUniforms(kVarsPerBlock)
199 , fSetupFragPosition(false) 185 , fSetupFragPosition(false)
186 , fTopLeftFragPosRead(kTopLeftFragPosRead_FragPosKey == desc.getHeader().fFr agPosKey)
200 , fHasCustomColorOutput(false) 187 , fHasCustomColorOutput(false)
201 , fHasSecondaryOutput(false) 188 , fHasSecondaryOutput(false) {
202 , fTopLeftFragPosRead(kTopLeftFragPosRead_FragPosKey == desc.getHeader().fFr agPosKey) {
203 189
204 const GrGLProgramDesc::KeyHeader& header = desc.getHeader(); 190 const GrGLProgramDesc::KeyHeader& header = desc.getHeader();
205 191
206 // Emit code to read the dst copy textue if necessary. 192 // Emit code to read the dst copy textue if necessary.
207 if (kNoDstRead_DstReadKey != header.fDstReadKey && 193 if (kNoDstRead_DstReadKey != header.fDstReadKey &&
208 GrGLCaps::kNone_FBFetchType == fGpu->glCaps().fbFetchType()) { 194 GrGLCaps::kNone_FBFetchType == fGpu->glCaps().fbFetchType()) {
209 bool topDown = SkToBool(kTopLeftOrigin_DstReadKeyBit & header.fDstReadKe y); 195 bool topDown = SkToBool(kTopLeftOrigin_DstReadKeyBit & header.fDstReadKe y);
210 const char* dstCopyTopLeftName; 196 const char* dstCopyTopLeftName;
211 const char* dstCopyCoordScaleName; 197 const char* dstCopyCoordScaleName;
198 const char* dstCopySamplerName;
212 uint32_t configMask; 199 uint32_t configMask;
213 if (SkToBool(kUseAlphaConfig_DstReadKeyBit & header.fDstReadKey)) { 200 if (SkToBool(kUseAlphaConfig_DstReadKeyBit & header.fDstReadKey)) {
214 configMask = kA_GrColorComponentFlag; 201 configMask = kA_GrColorComponentFlag;
215 } else { 202 } else {
216 configMask = kRGBA_GrColorComponentFlags; 203 configMask = kRGBA_GrColorComponentFlags;
217 } 204 }
218 fDstCopySamplerUniform = this->addUniform(kFragment_Visibility, 205 fOutput.fUniformHandles.fDstCopySamplerUni =
219 kSampler2D_GrSLType, 206 this->addUniform(kFragment_Visibility, kSampler2D_GrSLType, "DstCopy Sampler",
220 "DstCopySampler"); 207 &dstCopySamplerName);
221 fDstCopyTopLeftUniform = this->addUniform(kFragment_Visibility, 208 fOutput.fUniformHandles.fDstCopyTopLeftUni =
222 kVec2f_GrSLType, 209 this->addUniform(kFragment_Visibility, kVec2f_GrSLType, "DstCopyUppe rLeft",
223 "DstCopyUpperLeft", 210 &dstCopyTopLeftName);
224 &dstCopyTopLeftName); 211 fOutput.fUniformHandles.fDstCopyScaleUni =
225 fDstCopyScaleUniform = this->addUniform(kFragment_Visibility, 212 this->addUniform(kFragment_Visibility, kVec2f_GrSLType, "DstCopyCoor dScale",
226 kVec2f_GrSLType, 213 &dstCopyCoordScaleName);
227 "DstCopyCoordScale",
228 &dstCopyCoordScaleName);
229 const char* fragPos = this->fragmentPosition(); 214 const char* fragPos = this->fragmentPosition();
230 this->fsCodeAppend("\t// Read color from copy of the destination.\n"); 215 this->fsCodeAppend("\t// Read color from copy of the destination.\n");
231 this->fsCodeAppendf("\tvec2 _dstTexCoord = (%s.xy - %s) * %s;\n", 216 this->fsCodeAppendf("\tvec2 _dstTexCoord = (%s.xy - %s) * %s;\n",
232 fragPos, dstCopyTopLeftName, dstCopyCoordScaleName); 217 fragPos, dstCopyTopLeftName, dstCopyCoordScaleName);
233 if (!topDown) { 218 if (!topDown) {
234 this->fsCodeAppend("\t_dstTexCoord.y = 1.0 - _dstTexCoord.y;\n"); 219 this->fsCodeAppend("\t_dstTexCoord.y = 1.0 - _dstTexCoord.y;\n");
235 } 220 }
236 this->fsCodeAppendf("\tvec4 %s = ", kDstCopyColorName); 221 this->fsCodeAppendf("\tvec4 %s = ", kDstCopyColorName);
237 append_texture_lookup(&fFSCode, 222 append_texture_lookup(&fFSCode,
238 fGpu, 223 fGpu,
239 this->getUniformCStr(fDstCopySamplerUniform), 224 dstCopySamplerName,
240 "_dstTexCoord", 225 "_dstTexCoord",
241 configMask, 226 configMask,
242 "rgba"); 227 "rgba");
243 this->fsCodeAppend(";\n\n"); 228 this->fsCodeAppend(";\n\n");
244 } 229 }
245 230
246 if (GrGLProgramDesc::kUniform_ColorInput == header.fColorInput) { 231 if (GrGLProgramDesc::kUniform_ColorInput == header.fColorInput) {
247 const char* name; 232 const char* name;
248 fColorUniform = this->addUniform(GrGLShaderBuilder::kFragment_Visibility , 233 fOutput.fUniformHandles.fColorUni =
249 kVec4f_GrSLType, "Color", &name); 234 this->addUniform(GrGLShaderBuilder::kFragment_Visibility, kVec4f_GrS LType, "Color",
235 &name);
250 fInputColor = GrGLSLExpr4(name); 236 fInputColor = GrGLSLExpr4(name);
251 } else if (GrGLProgramDesc::kSolidWhite_ColorInput == header.fColorInput) { 237 } else if (GrGLProgramDesc::kSolidWhite_ColorInput == header.fColorInput) {
252 fInputColor = GrGLSLExpr4(1); 238 fInputColor = GrGLSLExpr4(1);
253 } else if (GrGLProgramDesc::kTransBlack_ColorInput == header.fColorInput) { 239 } else if (GrGLProgramDesc::kTransBlack_ColorInput == header.fColorInput) {
254 fInputColor = GrGLSLExpr4(0); 240 fInputColor = GrGLSLExpr4(0);
255 } 241 }
256 242
257 if (GrGLProgramDesc::kUniform_ColorInput == header.fCoverageInput) { 243 if (GrGLProgramDesc::kUniform_ColorInput == header.fCoverageInput) {
258 const char* name; 244 const char* name;
259 fCoverageUniform = this->addUniform(GrGLShaderBuilder::kFragment_Visibil ity, 245 fOutput.fUniformHandles.fCoverageUni =
260 kVec4f_GrSLType, "Coverage", &name); 246 this->addUniform(GrGLShaderBuilder::kFragment_Visibility, kVec4f_GrS LType, "Coverage",
247 &name);
261 fInputCoverage = GrGLSLExpr4(name); 248 fInputCoverage = GrGLSLExpr4(name);
262 } else if (GrGLProgramDesc::kSolidWhite_ColorInput == header.fCoverageInput) { 249 } else if (GrGLProgramDesc::kSolidWhite_ColorInput == header.fCoverageInput) {
263 fInputCoverage = GrGLSLExpr4(1); 250 fInputCoverage = GrGLSLExpr4(1);
264 } else if (GrGLProgramDesc::kTransBlack_ColorInput == header.fCoverageInput) { 251 } else if (GrGLProgramDesc::kTransBlack_ColorInput == header.fCoverageInput) {
265 fInputCoverage = GrGLSLExpr4(0); 252 fInputCoverage = GrGLSLExpr4(0);
266 } 253 }
267 254
268 if (k110_GrGLSLGeneration != fGpu->glslGeneration()) { 255 if (k110_GrGLSLGeneration != fGpu->glslGeneration()) {
269 fFSOutputs.push_back().set(kVec4f_GrSLType, 256 fFSOutputs.push_back().set(kVec4f_GrSLType,
270 GrGLShaderVar::kOut_TypeModifier, 257 GrGLShaderVar::kOut_TypeModifier,
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 } 340 }
354 } 341 }
355 static const char kFBFetchColorName[] = "gl_LastFragData[0]"; 342 static const char kFBFetchColorName[] = "gl_LastFragData[0]";
356 GrGLCaps::FBFetchType fetchType = fGpu->glCaps().fbFetchType(); 343 GrGLCaps::FBFetchType fetchType = fGpu->glCaps().fbFetchType();
357 if (GrGLCaps::kEXT_FBFetchType == fetchType) { 344 if (GrGLCaps::kEXT_FBFetchType == fetchType) {
358 SkAssertResult(this->enablePrivateFeature(kEXTShaderFramebufferFetch_GLS LPrivateFeature)); 345 SkAssertResult(this->enablePrivateFeature(kEXTShaderFramebufferFetch_GLS LPrivateFeature));
359 return kFBFetchColorName; 346 return kFBFetchColorName;
360 } else if (GrGLCaps::kNV_FBFetchType == fetchType) { 347 } else if (GrGLCaps::kNV_FBFetchType == fetchType) {
361 SkAssertResult(this->enablePrivateFeature(kNVShaderFramebufferFetch_GLSL PrivateFeature)); 348 SkAssertResult(this->enablePrivateFeature(kNVShaderFramebufferFetch_GLSL PrivateFeature));
362 return kFBFetchColorName; 349 return kFBFetchColorName;
363 } else if (fDstCopySamplerUniform.isValid()) { 350 } else if (fOutput.fUniformHandles.fDstCopySamplerUni.isValid()) {
364 return kDstCopyColorName; 351 return kDstCopyColorName;
365 } else { 352 } else {
366 return ""; 353 return "";
367 } 354 }
368 } 355 }
369 356
370 void GrGLShaderBuilder::appendTextureLookup(SkString* out, 357 void GrGLShaderBuilder::appendTextureLookup(SkString* out,
371 const GrGLShaderBuilder::TextureSamp ler& sampler, 358 const GrGLShaderBuilder::TextureSamp ler& sampler,
372 const char* coordName, 359 const char* coordName,
373 GrSLType varyingType) const { 360 GrSLType varyingType) const {
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 GrGLShaderVar::kUpperLeft_Origin); 505 GrGLShaderVar::kUpperLeft_Origin);
519 fSetupFragPosition = true; 506 fSetupFragPosition = true;
520 } 507 }
521 return "gl_FragCoord"; 508 return "gl_FragCoord";
522 } else { 509 } else {
523 static const char* kCoordName = "fragCoordYDown"; 510 static const char* kCoordName = "fragCoordYDown";
524 if (!fSetupFragPosition) { 511 if (!fSetupFragPosition) {
525 // temporarily change the stage index because we're inserting non-st age code. 512 // temporarily change the stage index because we're inserting non-st age code.
526 CodeStage::AutoStageRestore csar(&fCodeStage, NULL); 513 CodeStage::AutoStageRestore csar(&fCodeStage, NULL);
527 514
528 SkASSERT(!fRTHeightUniform.isValid()); 515 SkASSERT(!fOutput.fUniformHandles.fRTHeightUni.isValid());
529 const char* rtHeightName; 516 const char* rtHeightName;
530 517
531 fRTHeightUniform = this->addUniform(kFragment_Visibility, 518 fOutput.fUniformHandles.fRTHeightUni =
532 kFloat_GrSLType, 519 this->addUniform(kFragment_Visibility, kFloat_GrSLType, "RTHeigh t", &rtHeightName);
533 "RTHeight",
534 &rtHeightName);
535 520
536 this->fFSCode.prependf("\tvec4 %s = vec4(gl_FragCoord.x, %s - gl_Fra gCoord.y, gl_FragCoord.zw);\n", 521 this->fFSCode.prependf("\tvec4 %s = vec4(gl_FragCoord.x, %s - gl_Fra gCoord.y, gl_FragCoord.zw);\n",
537 kCoordName, rtHeightName); 522 kCoordName, rtHeightName);
538 fSetupFragPosition = true; 523 fSetupFragPosition = true;
539 } 524 }
540 SkASSERT(fRTHeightUniform.isValid()); 525 SkASSERT(fOutput.fUniformHandles.fRTHeightUni.isValid());
541 return kCoordName; 526 return kCoordName;
542 } 527 }
543 } 528 }
544 529
545 void GrGLShaderBuilder::fsEmitFunction(GrSLType returnType, 530 void GrGLShaderBuilder::fsEmitFunction(GrSLType returnType,
546 const char* name, 531 const char* name,
547 int argCnt, 532 int argCnt,
548 const GrGLShaderVar* args, 533 const GrGLShaderVar* args,
549 const char* body, 534 const char* body,
550 SkString* outName) { 535 SkString* outName) {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 const char* GrGLShaderBuilder::enableSecondaryOutput() { 645 const char* GrGLShaderBuilder::enableSecondaryOutput() {
661 if (!fHasSecondaryOutput) { 646 if (!fHasSecondaryOutput) {
662 fFSOutputs.push_back().set(kVec4f_GrSLType, 647 fFSOutputs.push_back().set(kVec4f_GrSLType,
663 GrGLShaderVar::kOut_TypeModifier, 648 GrGLShaderVar::kOut_TypeModifier,
664 dual_source_output_name()); 649 dual_source_output_name());
665 fHasSecondaryOutput = true; 650 fHasSecondaryOutput = true;
666 } 651 }
667 return dual_source_output_name(); 652 return dual_source_output_name();
668 } 653 }
669 654
670 bool GrGLShaderBuilder::finish(GrGLuint* outProgramId) { 655 bool GrGLShaderBuilder::finish() {
671 GrGLuint programId = 0; 656 SkASSERT(0 == fOutput.fProgramID);
672 GL_CALL_RET(programId, CreateProgram()); 657 GL_CALL_RET(fOutput.fProgramID, CreateProgram());
673 if (!programId) { 658 if (!fOutput.fProgramID) {
674 return false; 659 return false;
675 } 660 }
676 661
677 SkTDArray<GrGLuint> shadersToDelete; 662 SkTDArray<GrGLuint> shadersToDelete;
678 663
679 if (!this->compileAndAttachShaders(programId, &shadersToDelete)) { 664 if (!this->compileAndAttachShaders(fOutput.fProgramID, &shadersToDelete)) {
680 GL_CALL(DeleteProgram(programId)); 665 GL_CALL(DeleteProgram(fOutput.fProgramID));
681 return false; 666 return false;
682 } 667 }
683 668
684 this->bindProgramLocations(programId); 669 this->bindProgramLocations(fOutput.fProgramID);
685 if (fUniformManager->isUsingBindUniform()) { 670 if (fUniformManager->isUsingBindUniform()) {
686 fUniformManager->getUniformLocations(programId, fUniforms); 671 fUniformManager->getUniformLocations(fOutput.fProgramID, fUniforms);
687 } 672 }
688 673
689 GL_CALL(LinkProgram(programId)); 674 GL_CALL(LinkProgram(fOutput.fProgramID));
690 675
691 // Calling GetProgramiv is expensive in Chromium. Assume success in release builds. 676 // Calling GetProgramiv is expensive in Chromium. Assume success in release builds.
692 bool checkLinked = !fGpu->ctxInfo().isChromium(); 677 bool checkLinked = !fGpu->ctxInfo().isChromium();
693 #ifdef SK_DEBUG 678 #ifdef SK_DEBUG
694 checkLinked = true; 679 checkLinked = true;
695 #endif 680 #endif
696 if (checkLinked) { 681 if (checkLinked) {
697 GrGLint linked = GR_GL_INIT_ZERO; 682 GrGLint linked = GR_GL_INIT_ZERO;
698 GL_CALL(GetProgramiv(programId, GR_GL_LINK_STATUS, &linked)); 683 GL_CALL(GetProgramiv(fOutput.fProgramID, GR_GL_LINK_STATUS, &linked));
699 if (!linked) { 684 if (!linked) {
700 GrGLint infoLen = GR_GL_INIT_ZERO; 685 GrGLint infoLen = GR_GL_INIT_ZERO;
701 GL_CALL(GetProgramiv(programId, GR_GL_INFO_LOG_LENGTH, &infoLen)); 686 GL_CALL(GetProgramiv(fOutput.fProgramID, GR_GL_INFO_LOG_LENGTH, &inf oLen));
702 SkAutoMalloc log(sizeof(char)*(infoLen+1)); // outside if for debug ger 687 SkAutoMalloc log(sizeof(char)*(infoLen+1)); // outside if for debug ger
703 if (infoLen > 0) { 688 if (infoLen > 0) {
704 // retrieve length even though we don't need it to workaround 689 // retrieve length even though we don't need it to workaround
705 // bug in chrome cmd buffer param validation. 690 // bug in chrome cmd buffer param validation.
706 GrGLsizei length = GR_GL_INIT_ZERO; 691 GrGLsizei length = GR_GL_INIT_ZERO;
707 GL_CALL(GetProgramInfoLog(programId, 692 GL_CALL(GetProgramInfoLog(fOutput.fProgramID,
708 infoLen+1, 693 infoLen+1,
709 &length, 694 &length,
710 (char*)log.get())); 695 (char*)log.get()));
711 GrPrintf((char*)log.get()); 696 GrPrintf((char*)log.get());
712 } 697 }
713 SkDEBUGFAIL("Error linking program"); 698 SkDEBUGFAIL("Error linking program");
714 GL_CALL(DeleteProgram(programId)); 699 GL_CALL(DeleteProgram(fOutput.fProgramID));
700 fOutput.fProgramID = 0;
715 return false; 701 return false;
716 } 702 }
717 } 703 }
718 704
719 if (!fUniformManager->isUsingBindUniform()) { 705 if (!fUniformManager->isUsingBindUniform()) {
720 fUniformManager->getUniformLocations(programId, fUniforms); 706 fUniformManager->getUniformLocations(fOutput.fProgramID, fUniforms);
721 } 707 }
722 708
723 for (int i = 0; i < shadersToDelete.count(); ++i) { 709 for (int i = 0; i < shadersToDelete.count(); ++i) {
724 GL_CALL(DeleteShader(shadersToDelete[i])); 710 GL_CALL(DeleteShader(shadersToDelete[i]));
725 } 711 }
726 712
727 *outProgramId = programId;
728 return true; 713 return true;
729 } 714 }
730 715
731 // Compiles a GL shader and attaches it to a program. Returns the shader ID if 716 // Compiles a GL shader and attaches it to a program. Returns the shader ID if
732 // successful, or 0 if not. 717 // successful, or 0 if not.
733 static GrGLuint attach_shader(const GrGLContext& glCtx, 718 static GrGLuint attach_shader(const GrGLContext& glCtx,
734 GrGLuint programId, 719 GrGLuint programId,
735 GrGLenum type, 720 GrGLenum type,
736 const SkString& shaderSrc) { 721 const SkString& shaderSrc) {
737 const GrGLInterface* gli = glCtx.interface(); 722 const GrGLInterface* gli = glCtx.interface();
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 GrGLUniformManager* uniformManager, 818 GrGLUniformManager* uniformManager,
834 const GrGLProgramDesc& desc) 819 const GrGLProgramDesc& desc)
835 : INHERITED(gpu, uniformManager, desc) 820 : INHERITED(gpu, uniformManager, desc)
836 , fVSAttrs(kVarsPerBlock) 821 , fVSAttrs(kVarsPerBlock)
837 , fVSOutputs(kVarsPerBlock) 822 , fVSOutputs(kVarsPerBlock)
838 , fGSInputs(kVarsPerBlock) 823 , fGSInputs(kVarsPerBlock)
839 , fGSOutputs(kVarsPerBlock) { 824 , fGSOutputs(kVarsPerBlock) {
840 825
841 const GrGLProgramDesc::KeyHeader& header = this->desc().getHeader(); 826 const GrGLProgramDesc::KeyHeader& header = this->desc().getHeader();
842 827
828 fOutput.fHasVertexShader = true;
829
843 fPositionVar = &fVSAttrs.push_back(); 830 fPositionVar = &fVSAttrs.push_back();
844 fPositionVar->set(kVec2f_GrSLType, GrGLShaderVar::kAttribute_TypeModifier, " aPosition"); 831 fPositionVar->set(kVec2f_GrSLType, GrGLShaderVar::kAttribute_TypeModifier, " aPosition");
845 if (-1 != header.fLocalCoordAttributeIndex) { 832 if (-1 != header.fLocalCoordAttributeIndex) {
846 fLocalCoordsVar = &fVSAttrs.push_back(); 833 fLocalCoordsVar = &fVSAttrs.push_back();
847 fLocalCoordsVar->set(kVec2f_GrSLType, 834 fLocalCoordsVar->set(kVec2f_GrSLType,
848 GrGLShaderVar::kAttribute_TypeModifier, 835 GrGLShaderVar::kAttribute_TypeModifier,
849 "aLocalCoords"); 836 "aLocalCoords");
850 } else { 837 } else {
851 fLocalCoordsVar = fPositionVar; 838 fLocalCoordsVar = fPositionVar;
852 } 839 }
853 840
854 const char* viewMName; 841 const char* viewMName;
855 fViewMatrixUniform = this->addUniform(GrGLShaderBuilder::kVertex_Visibility, 842 fOutput.fUniformHandles.fViewMatrixUni =
856 kMat33f_GrSLType, "ViewM", &viewMName) ; 843 this->addUniform(GrGLShaderBuilder::kVertex_Visibility, kMat33f_GrSLType , "ViewM",
844 &viewMName);
857 const char* rtAdjustName; 845 const char* rtAdjustName;
858 fRTAdustmentVecUniform = this->addUniform(GrGLShaderBuilder::kVertex_Visibil ity, 846 fOutput.fUniformHandles.fRTAdjustmentUni =
859 kVec4f_GrSLType, "rtAdjustment", & rtAdjustName); 847 this->addUniform(GrGLShaderBuilder::kVertex_Visibility, kVec4f_GrSLType, "rtAdjustment",
848 &rtAdjustName);
860 849
861 // Transform the position into Skia's device coords. 850 // Transform the position into Skia's device coords.
862 this->vsCodeAppendf("\tvec3 pos3 = %s * vec3(%s, 1);\n", 851 this->vsCodeAppendf("\tvec3 pos3 = %s * vec3(%s, 1);\n",
863 viewMName, fPositionVar->c_str()); 852 viewMName, fPositionVar->c_str());
864 853
865 // Transform from Skia's device coords to GL's normalized device coords. 854 // Transform from Skia's device coords to GL's normalized device coords.
866 this->vsCodeAppendf( 855 this->vsCodeAppendf(
867 "\tgl_Position = vec4(dot(pos3.xz, %s.xy), dot(pos3.yz, %s.zw), 0, pos3. z);\n", 856 "\tgl_Position = vec4(dot(pos3.xz, %s.xy), dot(pos3.yz, %s.zw), 0, pos3. z);\n",
868 rtAdjustName, rtAdjustName); 857 rtAdjustName, rtAdjustName);
869 858
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 for (const AttributePair* attrib = fEffectAttributes.begin(); attrib != attr ibEnd; ++attrib) { 1054 for (const AttributePair* attrib = fEffectAttributes.begin(); attrib != attr ibEnd; ++attrib) {
1066 GL_CALL(BindAttribLocation(programId, attrib->fIndex, attrib->fName.c_s tr())); 1055 GL_CALL(BindAttribLocation(programId, attrib->fIndex, attrib->fName.c_s tr()));
1067 } 1056 }
1068 } 1057 }
1069 1058
1070 //////////////////////////////////////////////////////////////////////////////// 1059 ////////////////////////////////////////////////////////////////////////////////
1071 1060
1072 GrGLFragmentOnlyShaderBuilder::GrGLFragmentOnlyShaderBuilder(GrGpuGL* gpu, 1061 GrGLFragmentOnlyShaderBuilder::GrGLFragmentOnlyShaderBuilder(GrGpuGL* gpu,
1073 GrGLUniformManager* uniformManager, 1062 GrGLUniformManager* uniformManager,
1074 const GrGLProgramDe sc& desc) 1063 const GrGLProgramDe sc& desc)
1075 : INHERITED(gpu, uniformManager, desc) 1064 : INHERITED(gpu, uniformManager, desc) {
1076 , fNumTexCoordSets(0) {
1077 1065
1078 SkASSERT(!desc.getHeader().fHasVertexCode); 1066 SkASSERT(!desc.getHeader().fHasVertexCode);
1079 SkASSERT(gpu->glCaps().pathRenderingSupport()); 1067 SkASSERT(gpu->glCaps().pathRenderingSupport());
1080 SkASSERT(GrGLProgramDesc::kAttribute_ColorInput != desc.getHeader().fColorIn put); 1068 SkASSERT(GrGLProgramDesc::kAttribute_ColorInput != desc.getHeader().fColorIn put);
1081 SkASSERT(GrGLProgramDesc::kAttribute_ColorInput != desc.getHeader().fCoverag eInput); 1069 SkASSERT(GrGLProgramDesc::kAttribute_ColorInput != desc.getHeader().fCoverag eInput);
1082 } 1070 }
1083 1071
1084 int GrGLFragmentOnlyShaderBuilder::addTexCoordSets(int count) { 1072 int GrGLFragmentOnlyShaderBuilder::addTexCoordSets(int count) {
1085 int firstFreeCoordSet = fNumTexCoordSets; 1073 int firstFreeCoordSet = fOutput.fTexCoordSetCnt;
1086 fNumTexCoordSets += count; 1074 fOutput.fTexCoordSetCnt += count;
1087 SkASSERT(gpu()->glCaps().maxFixedFunctionTextureCoords() >= fNumTexCoordSets ); 1075 SkASSERT(gpu()->glCaps().maxFixedFunctionTextureCoords() >= fOutput.fTexCoor dSetCnt);
1088 return firstFreeCoordSet; 1076 return firstFreeCoordSet;
1089 } 1077 }
1090 1078
1091 GrGLProgramEffects* GrGLFragmentOnlyShaderBuilder::createAndEmitEffects( 1079 GrGLProgramEffects* GrGLFragmentOnlyShaderBuilder::createAndEmitEffects(
1092 const GrEffectStage* effectStages[], 1080 const GrEffectStage* effectStages[],
1093 const EffectKey effectKeys[], 1081 const EffectKey effectKeys[],
1094 int effectCnt, 1082 int effectCnt,
1095 GrGLSLExpr4* inOutFSColor) { 1083 GrGLSLExpr4* inOutFSColor) {
1096 1084
1097 GrGLPathTexGenProgramEffectsBuilder pathTexGenEffectsBuilder(this, 1085 GrGLPathTexGenProgramEffectsBuilder pathTexGenEffectsBuilder(this,
1098 effectCnt); 1086 effectCnt);
1099 this->INHERITED::createAndEmitEffects(&pathTexGenEffectsBuilder, 1087 this->INHERITED::createAndEmitEffects(&pathTexGenEffectsBuilder,
1100 effectStages, 1088 effectStages,
1101 effectKeys, 1089 effectKeys,
1102 effectCnt, 1090 effectCnt,
1103 inOutFSColor); 1091 inOutFSColor);
1104 return pathTexGenEffectsBuilder.finish(); 1092 return pathTexGenEffectsBuilder.finish();
1105 } 1093 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLShaderBuilder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698