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

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

Issue 356513003: Step towards variable length effect keys. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: tweak comment Created 6 years, 5 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
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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 GrGLShaderVar::kOut_TypeModifier, 187 GrGLShaderVar::kOut_TypeModifier,
188 declared_color_output_name()); 188 declared_color_output_name());
189 fHasCustomColorOutput = true; 189 fHasCustomColorOutput = true;
190 } 190 }
191 191
192 this->emitCodeBeforeEffects(&inputColor, &inputCoverage); 192 this->emitCodeBeforeEffects(&inputColor, &inputCoverage);
193 193
194 /////////////////////////////////////////////////////////////////////////// 194 ///////////////////////////////////////////////////////////////////////////
195 // emit the per-effect code for both color and coverage effects 195 // emit the per-effect code for both color and coverage effects
196 196
197 GrGLProgramDesc::EffectKeyProvider colorKeyProvider(
198 &this->desc(), GrGLProgramDesc::EffectKeyProvider::kColor_EffectType);
197 fOutput.fColorEffects.reset(this->createAndEmitEffects(colorStages, 199 fOutput.fColorEffects.reset(this->createAndEmitEffects(colorStages,
198 this->desc().getEffec tKeys(),
199 this->desc().numColor Effects(), 200 this->desc().numColor Effects(),
201 colorKeyProvider,
200 &inputColor)); 202 &inputColor));
201 203
204 GrGLProgramDesc::EffectKeyProvider coverageKeyProvider(
205 &this->desc(), GrGLProgramDesc::EffectKeyProvider::kCoverage_EffectType) ;
202 fOutput.fCoverageEffects.reset(this->createAndEmitEffects(coverageStages, 206 fOutput.fCoverageEffects.reset(this->createAndEmitEffects(coverageStages,
203 this->desc().getEffectKeys() + this->desc(). numColorEffects(), 207 this->desc().numCoverageEffects(),
204 this->desc().numCoverageEffects(), 208 coverageKeyProvider,
205 &inputCoverage)); 209 &inputCoverage));
206 210
207 this->emitCodeAfterEffects(); 211 this->emitCodeAfterEffects();
208 212
209 /////////////////////////////////////////////////////////////////////////// 213 ///////////////////////////////////////////////////////////////////////////
210 // write the secondary color output if necessary 214 // write the secondary color output if necessary
211 if (GrGLProgramDesc::CoverageOutputUsesSecondaryOutput(header.fCoverageOutpu t)) { 215 if (GrGLProgramDesc::CoverageOutputUsesSecondaryOutput(header.fCoverageOutpu t)) {
212 const char* secondaryOutputName = this->enableSecondaryOutput(); 216 const char* secondaryOutputName = this->enableSecondaryOutput();
213 217
214 // default coeff to ones for kCoverage_DualSrcOutput 218 // default coeff to ones for kCoverage_DualSrcOutput
215 GrGLSLExpr4 coeff(1); 219 GrGLSLExpr4 coeff(1);
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 for (int i = 0; i < fUniforms.count(); ++i) { 598 for (int i = 0; i < fUniforms.count(); ++i) {
595 if (fUniforms[i].fVisibility & visibility) { 599 if (fUniforms[i].fVisibility & visibility) {
596 fUniforms[i].fVariable.appendDecl(this->ctxInfo(), out); 600 fUniforms[i].fVariable.appendDecl(this->ctxInfo(), out);
597 out->append(";\n"); 601 out->append(";\n");
598 } 602 }
599 } 603 }
600 } 604 }
601 605
602 void GrGLShaderBuilder::createAndEmitEffects(GrGLProgramEffectsBuilder* programE ffectsBuilder, 606 void GrGLShaderBuilder::createAndEmitEffects(GrGLProgramEffectsBuilder* programE ffectsBuilder,
603 const GrEffectStage* effectStages[] , 607 const GrEffectStage* effectStages[] ,
604 const EffectKey effectKeys[],
605 int effectCnt, 608 int effectCnt,
609 const GrGLProgramDesc::EffectKeyPro vider& keyProvider,
606 GrGLSLExpr4* fsInOutColor) { 610 GrGLSLExpr4* fsInOutColor) {
607 bool effectEmitted = false; 611 bool effectEmitted = false;
608 612
609 GrGLSLExpr4 inColor = *fsInOutColor; 613 GrGLSLExpr4 inColor = *fsInOutColor;
610 GrGLSLExpr4 outColor; 614 GrGLSLExpr4 outColor;
611 615
612 for (int e = 0; e < effectCnt; ++e) { 616 for (int e = 0; e < effectCnt; ++e) {
613 SkASSERT(NULL != effectStages[e] && NULL != effectStages[e]->getEffect() ); 617 SkASSERT(NULL != effectStages[e] && NULL != effectStages[e]->getEffect() );
614 const GrEffectStage& stage = *effectStages[e]; 618 const GrEffectStage& stage = *effectStages[e];
615 619
616 CodeStage::AutoStageRestore csar(&fCodeStage, &stage); 620 CodeStage::AutoStageRestore csar(&fCodeStage, &stage);
617 621
618 if (inColor.isZeros()) { 622 if (inColor.isZeros()) {
619 SkString inColorName; 623 SkString inColorName;
620 624
621 // Effects have no way to communicate zeros, they treat an empty str ing as ones. 625 // Effects have no way to communicate zeros, they treat an empty str ing as ones.
622 this->nameVariable(&inColorName, '\0', "input"); 626 this->nameVariable(&inColorName, '\0', "input");
623 this->fsCodeAppendf("\tvec4 %s = %s;\n", inColorName.c_str(), inColo r.c_str()); 627 this->fsCodeAppendf("\tvec4 %s = %s;\n", inColorName.c_str(), inColo r.c_str());
624 inColor = inColorName; 628 inColor = inColorName;
625 } 629 }
626 630
627 // create var to hold stage result 631 // create var to hold stage result
628 SkString outColorName; 632 SkString outColorName;
629 this->nameVariable(&outColorName, '\0', "output"); 633 this->nameVariable(&outColorName, '\0', "output");
630 this->fsCodeAppendf("\tvec4 %s;\n", outColorName.c_str()); 634 this->fsCodeAppendf("\tvec4 %s;\n", outColorName.c_str());
631 outColor = outColorName; 635 outColor = outColorName;
632 636
633 637
634 programEffectsBuilder->emitEffect(stage, 638 programEffectsBuilder->emitEffect(stage,
635 effectKeys[e], 639 keyProvider.get(e),
636 outColor.c_str(), 640 outColor.c_str(),
637 inColor.isOnes() ? NULL : inColor.c_st r(), 641 inColor.isOnes() ? NULL : inColor.c_st r(),
638 fCodeStage.stageIndex()); 642 fCodeStage.stageIndex());
639 643
640 inColor = outColor; 644 inColor = outColor;
641 effectEmitted = true; 645 effectEmitted = true;
642 } 646 }
643 647
644 if (effectEmitted) { 648 if (effectEmitted) {
645 *fsInOutColor = outColor; 649 *fsInOutColor = outColor;
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 if (attrib->fIndex == attributeIndex) { 973 if (attrib->fIndex == attributeIndex) {
970 return &attrib->fName; 974 return &attrib->fName;
971 } 975 }
972 } 976 }
973 977
974 return NULL; 978 return NULL;
975 } 979 }
976 980
977 GrGLProgramEffects* GrGLFullShaderBuilder::createAndEmitEffects( 981 GrGLProgramEffects* GrGLFullShaderBuilder::createAndEmitEffects(
978 const GrEffectStage* effectStages[], 982 const GrEffectStage* effectStages[],
979 const EffectKey effectKeys[],
980 int effectCnt, 983 int effectCnt,
984 const GrGLProgramDesc::EffectKeyProvider& keyProvider,
981 GrGLSLExpr4* inOutFSColor) { 985 GrGLSLExpr4* inOutFSColor) {
982 986
983 GrGLVertexProgramEffectsBuilder programEffectsBuilder(this, effectCnt); 987 GrGLVertexProgramEffectsBuilder programEffectsBuilder(this, effectCnt);
984 this->INHERITED::createAndEmitEffects(&programEffectsBuilder, 988 this->INHERITED::createAndEmitEffects(&programEffectsBuilder,
985 effectStages, 989 effectStages,
986 effectKeys,
987 effectCnt, 990 effectCnt,
991 keyProvider,
988 inOutFSColor); 992 inOutFSColor);
989 return programEffectsBuilder.finish(); 993 return programEffectsBuilder.finish();
990 } 994 }
991 995
992 bool GrGLFullShaderBuilder::compileAndAttachShaders(GrGLuint programId, 996 bool GrGLFullShaderBuilder::compileAndAttachShaders(GrGLuint programId,
993 SkTDArray<GrGLuint>* shaderI ds) const { 997 SkTDArray<GrGLuint>* shaderI ds) const {
994 const GrGLContext& glCtx = this->gpu()->glContext(); 998 const GrGLContext& glCtx = this->gpu()->glContext();
995 SkString vertShaderSrc(GrGetGLSLVersionDecl(this->ctxInfo())); 999 SkString vertShaderSrc(GrGetGLSLVersionDecl(this->ctxInfo()));
996 this->appendUniformDecls(kVertex_Visibility, &vertShaderSrc); 1000 this->appendUniformDecls(kVertex_Visibility, &vertShaderSrc);
997 this->appendDecls(fVSAttrs, &vertShaderSrc); 1001 this->appendDecls(fVSAttrs, &vertShaderSrc);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 1090
1087 int GrGLFragmentOnlyShaderBuilder::addTexCoordSets(int count) { 1091 int GrGLFragmentOnlyShaderBuilder::addTexCoordSets(int count) {
1088 int firstFreeCoordSet = fOutput.fTexCoordSetCnt; 1092 int firstFreeCoordSet = fOutput.fTexCoordSetCnt;
1089 fOutput.fTexCoordSetCnt += count; 1093 fOutput.fTexCoordSetCnt += count;
1090 SkASSERT(gpu()->glCaps().maxFixedFunctionTextureCoords() >= fOutput.fTexCoor dSetCnt); 1094 SkASSERT(gpu()->glCaps().maxFixedFunctionTextureCoords() >= fOutput.fTexCoor dSetCnt);
1091 return firstFreeCoordSet; 1095 return firstFreeCoordSet;
1092 } 1096 }
1093 1097
1094 GrGLProgramEffects* GrGLFragmentOnlyShaderBuilder::createAndEmitEffects( 1098 GrGLProgramEffects* GrGLFragmentOnlyShaderBuilder::createAndEmitEffects(
1095 const GrEffectStage* effectStages[], 1099 const GrEffectStage* effectStages[],
1096 const EffectKey effectKeys[],
1097 int effectCnt, 1100 int effectCnt,
1101 const GrGLProgramDesc::EffectKeyProvider& keyProvider,
1098 GrGLSLExpr4* inOutFSColor) { 1102 GrGLSLExpr4* inOutFSColor) {
1099 1103
1100 GrGLPathTexGenProgramEffectsBuilder pathTexGenEffectsBuilder(this, 1104 GrGLPathTexGenProgramEffectsBuilder pathTexGenEffectsBuilder(this,
1101 effectCnt); 1105 effectCnt);
1102 this->INHERITED::createAndEmitEffects(&pathTexGenEffectsBuilder, 1106 this->INHERITED::createAndEmitEffects(&pathTexGenEffectsBuilder,
1103 effectStages, 1107 effectStages,
1104 effectKeys,
1105 effectCnt, 1108 effectCnt,
1109 keyProvider,
1106 inOutFSColor); 1110 inOutFSColor);
1107 return pathTexGenEffectsBuilder.finish(); 1111 return pathTexGenEffectsBuilder.finish();
1108 } 1112 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698