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

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

Issue 25048002: Express (GLSL expression, possibly known value) pairs as a class (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase Created 7 years, 2 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
« src/gpu/gl/GrGLSL.h ('K') | « 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 GrGLShaderBuilder::GrGLShaderBuilder(GrGpuGL* gpu, 92 GrGLShaderBuilder::GrGLShaderBuilder(GrGpuGL* gpu,
93 GrGLUniformManager& uniformManager, 93 GrGLUniformManager& uniformManager,
94 const GrGLProgramDesc& desc) 94 const GrGLProgramDesc& desc)
95 : fGpu(gpu) 95 : fGpu(gpu)
96 , fUniformManager(uniformManager) 96 , fUniformManager(uniformManager)
97 , fFSFeaturesAddedMask(0) 97 , fFSFeaturesAddedMask(0)
98 , fFSInputs(kVarsPerBlock) 98 , fFSInputs(kVarsPerBlock)
99 , fFSOutputs(kMaxFSOutputs) 99 , fFSOutputs(kMaxFSOutputs)
100 , fUniforms(kVarsPerBlock) 100 , fUniforms(kVarsPerBlock)
101 , fSetupFragPosition(false) 101 , fSetupFragPosition(false)
102 , fKnownColorValue(GrGLProgramDesc::KnownColorInputValue(desc.getHeader().fC olorInput))
103 , fKnownCoverageValue(GrGLProgramDesc::KnownColorInputValue(desc.getHeader() .fCoverageInput))
104 , fHasCustomColorOutput(false) 102 , fHasCustomColorOutput(false)
105 , fHasSecondaryOutput(false) 103 , fHasSecondaryOutput(false)
106 , fTopLeftFragPosRead(kTopLeftFragPosRead_FragPosKey == desc.getHeader().fFr agPosKey) { 104 , fTopLeftFragPosRead(kTopLeftFragPosRead_FragPosKey == desc.getHeader().fFr agPosKey) {
107 105
108 const GrGLProgramDesc::KeyHeader& header = desc.getHeader(); 106 const GrGLProgramDesc::KeyHeader& header = desc.getHeader();
109 107
110 // Emit code to read the dst copy textue if necessary. 108 // Emit code to read the dst copy textue if necessary.
111 if (kNoDstRead_DstReadKey != header.fDstReadKey && 109 if (kNoDstRead_DstReadKey != header.fDstReadKey &&
112 GrGLCaps::kNone_FBFetchType == fGpu->glCaps().fbFetchType()) { 110 GrGLCaps::kNone_FBFetchType == fGpu->glCaps().fbFetchType()) {
113 bool topDown = SkToBool(kTopLeftOrigin_DstReadKeyBit & header.fDstReadKe y); 111 bool topDown = SkToBool(kTopLeftOrigin_DstReadKeyBit & header.fDstReadKe y);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 configMask, 143 configMask,
146 "rgba"); 144 "rgba");
147 this->fsCodeAppend(";\n\n"); 145 this->fsCodeAppend(";\n\n");
148 } 146 }
149 147
150 if (GrGLProgramDesc::kUniform_ColorInput == header.fColorInput) { 148 if (GrGLProgramDesc::kUniform_ColorInput == header.fColorInput) {
151 const char* name; 149 const char* name;
152 fColorUniform = this->addUniform(GrGLShaderBuilder::kFragment_Visibility , 150 fColorUniform = this->addUniform(GrGLShaderBuilder::kFragment_Visibility ,
153 kVec4f_GrSLType, "Color", &name); 151 kVec4f_GrSLType, "Color", &name);
154 fInputColor = name; 152 fInputColor = name;
153 } else if (GrGLProgramDesc::kSolidWhite_ColorInput == header.fColorInput) {
154 fInputColor = GrGLSLExpr<4>(1);
155 } else if (GrGLProgramDesc::kTransBlack_ColorInput == header.fColorInput) {
156 fInputColor = GrGLSLExpr<4>(0);
155 } 157 }
156 158
157 if (GrGLProgramDesc::kUniform_ColorInput == header.fCoverageInput) { 159 if (GrGLProgramDesc::kUniform_ColorInput == header.fCoverageInput) {
158 const char* name; 160 const char* name;
159 fCoverageUniform = this->addUniform(GrGLShaderBuilder::kFragment_Visibil ity, 161 fCoverageUniform = this->addUniform(GrGLShaderBuilder::kFragment_Visibil ity,
160 kVec4f_GrSLType, "Coverage", &name); 162 kVec4f_GrSLType, "Coverage", &name);
161 fInputCoverage = name; 163 fInputCoverage = name;
164 } else if (GrGLProgramDesc::kSolidWhite_ColorInput == header.fCoverageInput) {
165 fInputCoverage = GrGLSLExpr<4>(1);
166 } else if (GrGLProgramDesc::kTransBlack_ColorInput == header.fCoverageInput) {
167 fInputCoverage = GrGLSLExpr<4>(0);
162 } 168 }
163 169
164 if (k110_GrGLSLGeneration != fGpu->glslGeneration()) { 170 if (k110_GrGLSLGeneration != fGpu->glslGeneration()) {
165 fFSOutputs.push_back().set(kVec4f_GrSLType, 171 fFSOutputs.push_back().set(kVec4f_GrSLType,
166 GrGLShaderVar::kOut_TypeModifier, 172 GrGLShaderVar::kOut_TypeModifier,
167 declared_color_output_name()); 173 declared_color_output_name());
168 fHasCustomColorOutput = true; 174 fHasCustomColorOutput = true;
169 } 175 }
170 } 176 }
171 177
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 this->appendTextureLookup(&fFSCode, sampler, coordName, varyingType); 288 this->appendTextureLookup(&fFSCode, sampler, coordName, varyingType);
283 } 289 }
284 290
285 void GrGLShaderBuilder::fsAppendTextureLookupAndModulate( 291 void GrGLShaderBuilder::fsAppendTextureLookupAndModulate(
286 const char* modulation, 292 const char* modulation,
287 const GrGLShaderBuilder::TextureSamp ler& sampler, 293 const GrGLShaderBuilder::TextureSamp ler& sampler,
288 const char* coordName, 294 const char* coordName,
289 GrSLType varyingType) { 295 GrSLType varyingType) {
290 SkString lookup; 296 SkString lookup;
291 this->appendTextureLookup(&lookup, sampler, coordName, varyingType); 297 this->appendTextureLookup(&lookup, sampler, coordName, varyingType);
292 GrGLSLModulatef<4>(&fFSCode, modulation, lookup.c_str()); 298 fFSCode.append((GrGLSLExpr<4>(modulation) * GrGLSLExpr<4>(lookup)).c_str());
293 } 299 }
294 300
295 GrGLShaderBuilder::DstReadKey GrGLShaderBuilder::KeyForDstRead(const GrTexture* dstCopy, 301 GrGLShaderBuilder::DstReadKey GrGLShaderBuilder::KeyForDstRead(const GrTexture* dstCopy,
296 const GrGLCaps& c aps) { 302 const GrGLCaps& c aps) {
297 uint32_t key = kYesDstRead_DstReadKeyBit; 303 uint32_t key = kYesDstRead_DstReadKeyBit;
298 if (GrGLCaps::kNone_FBFetchType != caps.fbFetchType()) { 304 if (GrGLCaps::kNone_FBFetchType != caps.fbFetchType()) {
299 return key; 305 return key;
300 } 306 }
301 SkASSERT(NULL != dstCopy); 307 SkASSERT(NULL != dstCopy);
302 if (!caps.textureSwizzleSupport() && GrPixelConfigIsAlphaOnly(dstCopy->confi g())) { 308 if (!caps.textureSwizzleSupport() && GrPixelConfigIsAlphaOnly(dstCopy->confi g())) {
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 fUniforms[i].fVariable.appendDecl(this->ctxInfo(), out); 508 fUniforms[i].fVariable.appendDecl(this->ctxInfo(), out);
503 out->append(";\n"); 509 out->append(";\n");
504 } 510 }
505 } 511 }
506 } 512 }
507 513
508 void GrGLShaderBuilder::createAndEmitEffects(GrGLProgramEffectsBuilder* programE ffectsBuilder, 514 void GrGLShaderBuilder::createAndEmitEffects(GrGLProgramEffectsBuilder* programE ffectsBuilder,
509 const GrEffectStage* effectStages[] , 515 const GrEffectStage* effectStages[] ,
510 const EffectKey effectKeys[], 516 const EffectKey effectKeys[],
511 int effectCnt, 517 int effectCnt,
512 SkString* fsInOutColor, 518 GrGLSLExpr<4>* fsInOutColor) {
513 GrSLConstantVec* fsInOutColorKnownV alue) {
514 bool effectEmitted = false; 519 bool effectEmitted = false;
515 520
516 SkString inColor = *fsInOutColor; 521 GrGLSLExpr<4> inColor = *fsInOutColor;
517 SkString outColor; 522 GrGLSLExpr<4> outColor;
518 523
519 for (int e = 0; e < effectCnt; ++e) { 524 for (int e = 0; e < effectCnt; ++e) {
520 SkASSERT(NULL != effectStages[e] && NULL != effectStages[e]->getEffect() ); 525 SkASSERT(NULL != effectStages[e] && NULL != effectStages[e]->getEffect() );
521 const GrEffectStage& stage = *effectStages[e]; 526 const GrEffectStage& stage = *effectStages[e];
522 527
523 CodeStage::AutoStageRestore csar(&fCodeStage, &stage); 528 CodeStage::AutoStageRestore csar(&fCodeStage, &stage);
524 529
525 if (kZeros_GrSLConstantVec == *fsInOutColorKnownValue) { 530 if (inColor.isZeros()) {
531 SkString inColorName;
532
526 // Effects have no way to communicate zeros, they treat an empty str ing as ones. 533 // Effects have no way to communicate zeros, they treat an empty str ing as ones.
527 this->nameVariable(&inColor, '\0', "input"); 534 this->nameVariable(&inColorName, '\0', "input");
528 this->fsCodeAppendf("\tvec4 %s = %s;\n", inColor.c_str(), GrGLSLZero sVecf(4)); 535 this->fsCodeAppendf("\tvec4 %s = %s;\n", inColorName.c_str(), inColo r.c_str());
536 inColor = inColorName;
529 } 537 }
530 538
531 // create var to hold stage result 539 // create var to hold stage result
532 this->nameVariable(&outColor, '\0', "output"); 540 SkString outColorName;
533 this->fsCodeAppendf("\tvec4 %s;\n", outColor.c_str()); 541 this->nameVariable(&outColorName, '\0', "output");
542 this->fsCodeAppendf("\tvec4 %s;\n", outColorName.c_str());
543 outColor = outColorName;
544
534 545
535 programEffectsBuilder->emitEffect(stage, 546 programEffectsBuilder->emitEffect(stage,
536 effectKeys[e], 547 effectKeys[e],
537 outColor.c_str(), 548 outColor.c_str(),
538 inColor.isEmpty() ? NULL : inColor.c_s tr(), 549 inColor.isOnes() ? NULL : inColor.c_st r(),
539 fCodeStage.stageIndex()); 550 fCodeStage.stageIndex());
540 551
541 inColor = outColor; 552 inColor = outColor;
542 *fsInOutColorKnownValue = kNone_GrSLConstantVec;
543 effectEmitted = true; 553 effectEmitted = true;
544 } 554 }
545 555
546 if (effectEmitted) { 556 if (effectEmitted) {
547 *fsInOutColor = outColor; 557 *fsInOutColor = outColor;
548 } 558 }
549 } 559 }
550 560
551 const char* GrGLShaderBuilder::getColorOutputName() const { 561 const char* GrGLShaderBuilder::getColorOutputName() const {
552 return fHasCustomColorOutput ? declared_color_output_name() : "gl_FragColor" ; 562 return fHasCustomColorOutput ? declared_color_output_name() : "gl_FragColor" ;
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 } 832 }
823 } 833 }
824 834
825 return NULL; 835 return NULL;
826 } 836 }
827 837
828 GrGLProgramEffects* GrGLFullShaderBuilder::createAndEmitEffects( 838 GrGLProgramEffects* GrGLFullShaderBuilder::createAndEmitEffects(
829 const GrEffectStage* effectStages[], 839 const GrEffectStage* effectStages[],
830 const EffectKey effectKeys[], 840 const EffectKey effectKeys[],
831 int effectCnt, 841 int effectCnt,
832 SkString* inOutFSColor, 842 GrGLSLExpr<4>* inOutFSColor) {
833 GrSLConstantVec* fsInOutColorKnownValue) {
834 843
835 GrGLVertexProgramEffectsBuilder programEffectsBuilder(this, effectCnt); 844 GrGLVertexProgramEffectsBuilder programEffectsBuilder(this, effectCnt);
836 this->INHERITED::createAndEmitEffects(&programEffectsBuilder, 845 this->INHERITED::createAndEmitEffects(&programEffectsBuilder,
837 effectStages, 846 effectStages,
838 effectKeys, 847 effectKeys,
839 effectCnt, 848 effectCnt,
840 inOutFSColor, 849 inOutFSColor);
841 fsInOutColorKnownValue);
842 return programEffectsBuilder.finish(); 850 return programEffectsBuilder.finish();
843 } 851 }
844 852
845 bool GrGLFullShaderBuilder::compileAndAttachShaders(GrGLuint programId) const { 853 bool GrGLFullShaderBuilder::compileAndAttachShaders(GrGLuint programId) const {
846 const GrGLInterface* glInterface = this->gpu()->glInterface(); 854 const GrGLInterface* glInterface = this->gpu()->glInterface();
847 SkString vertShaderSrc(GrGetGLSLVersionDecl(this->ctxInfo())); 855 SkString vertShaderSrc(GrGetGLSLVersionDecl(this->ctxInfo()));
848 this->appendUniformDecls(kVertex_Visibility, &vertShaderSrc); 856 this->appendUniformDecls(kVertex_Visibility, &vertShaderSrc);
849 this->appendDecls(fVSAttrs, &vertShaderSrc); 857 this->appendDecls(fVSAttrs, &vertShaderSrc);
850 this->appendDecls(fVSOutputs, &vertShaderSrc); 858 this->appendDecls(fVSOutputs, &vertShaderSrc);
851 vertShaderSrc.append("void main() {\n"); 859 vertShaderSrc.append("void main() {\n");
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 SkASSERT(gpu->glCaps().fixedFunctionSupport()); 940 SkASSERT(gpu->glCaps().fixedFunctionSupport());
933 SkASSERT(gpu->glCaps().pathStencilingSupport()); 941 SkASSERT(gpu->glCaps().pathStencilingSupport());
934 SkASSERT(GrGLProgramDesc::kAttribute_ColorInput != desc.getHeader().fColorIn put); 942 SkASSERT(GrGLProgramDesc::kAttribute_ColorInput != desc.getHeader().fColorIn put);
935 SkASSERT(GrGLProgramDesc::kAttribute_ColorInput != desc.getHeader().fCoverag eInput); 943 SkASSERT(GrGLProgramDesc::kAttribute_ColorInput != desc.getHeader().fCoverag eInput);
936 } 944 }
937 945
938 GrGLProgramEffects* GrGLFragmentOnlyShaderBuilder::createAndEmitEffects( 946 GrGLProgramEffects* GrGLFragmentOnlyShaderBuilder::createAndEmitEffects(
939 const GrEffectStage* effectStages[], 947 const GrEffectStage* effectStages[],
940 const EffectKey effectKeys[], 948 const EffectKey effectKeys[],
941 int effectCnt, 949 int effectCnt,
942 SkString* inOutFSColor, 950 GrGLSLExpr<4>* inOutFSColor) {
943 GrSLConstantVec* fsInOutColorKnownValue) {
944 951
945 GrGLTexGenProgramEffectsBuilder texGenEffectsBuilder(this, effectCnt); 952 GrGLTexGenProgramEffectsBuilder texGenEffectsBuilder(this, effectCnt);
946 this->INHERITED::createAndEmitEffects(&texGenEffectsBuilder, 953 this->INHERITED::createAndEmitEffects(&texGenEffectsBuilder,
947 effectStages, 954 effectStages,
948 effectKeys, 955 effectKeys,
949 effectCnt, 956 effectCnt,
950 inOutFSColor, 957 inOutFSColor);
951 fsInOutColorKnownValue);
952 return texGenEffectsBuilder.finish(); 958 return texGenEffectsBuilder.finish();
953 } 959 }
OLDNEW
« src/gpu/gl/GrGLSL.h ('K') | « src/gpu/gl/GrGLShaderBuilder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698