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

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

Issue 302663006: Incremental refactoring of GrGLProgram and GrGLShaderBuilder (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase 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') | src/gpu/gl/GrGLUniformManager.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 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 } 83 }
84 } 84 }
85 85
86 } 86 }
87 87
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 if (desc.getHeader().fHasVertexCode ||!gpu->shouldUseFixedFunctionTexturing( )) { 98 if (desc.getHeader().fHasVertexCode ||!gpu->shouldUseFixedFunctionTexturing( )) {
99 GrGLFullShaderBuilder fullBuilder(gpu, uman, desc); 99 GrGLFullShaderBuilder fullBuilder(gpu, uman, desc);
100 if (fullBuilder.genProgram(inColorStages, inCoverageStages, output)) { 100 if (fullBuilder.genProgram(inColorStages, inCoverageStages, output)) {
101 output->fHasVS = true; 101 output->fHasVS = true;
102 output->fUniformHandles.fViewMatrixUni = fullBuilder.getViewMatrixUn iform(); 102 output->fUniformHandles.fViewMatrixUni = fullBuilder.getViewMatrixUn iform();
103 output->fUniformHandles.fRTAdjustmentUni = fullBuilder.getRTAdjustme ntVecUniform(); 103 output->fUniformHandles.fRTAdjustmentUni = fullBuilder.getRTAdjustme ntVecUniform();
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 GrGLSLExpr4 dstContribution = dstCoeff * GrGLSLExpr4(this->dstColor()); 167 GrGLSLExpr4 dstContribution = dstCoeff * GrGLSLExpr4(this->dstColor());
168 168
169 fragColor = fragColor + dstContribution; 169 fragColor = fragColor + dstContribution;
170 } 170 }
171 this->fsCodeAppendf("\t%s = %s;\n", this->getColorOutputName(), fragColor.c_ str()); 171 this->fsCodeAppendf("\t%s = %s;\n", this->getColorOutputName(), fragColor.c_ str());
172 172
173 if (!this->finish(&output->fProgramID)) { 173 if (!this->finish(&output->fProgramID)) {
174 return false; 174 return false;
175 } 175 }
176 176
177 output->fUniformHandles.fRTHeightUni = this->getRTHeightUniform(); 177 output->fUniformHandles.fRTHeightUni = fRTHeightUniform;
178 output->fUniformHandles.fDstCopyTopLeftUni = this->getDstCopyTopLeftUniform( ); 178 output->fUniformHandles.fColorUni = fColorUniform;
179 output->fUniformHandles.fDstCopyScaleUni = this->getDstCopyScaleUniform(); 179 output->fUniformHandles.fCoverageUni = fCoverageUniform;
180 output->fUniformHandles.fColorUni = this->getColorUniform(); 180 output->fUniformHandles.fDstCopyTopLeftUni = fDstCopyTopLeftUniform;
181 output->fUniformHandles.fCoverageUni = this->getCoverageUniform(); 181 output->fUniformHandles.fDstCopyScaleUni = fDstCopyScaleUniform;
182 output->fUniformHandles.fDstCopySamplerUni = this->getDstCopySamplerUniform( ); 182 output->fUniformHandles.fDstCopySamplerUni = fDstCopySamplerUniform;
183 183
184 return true; 184 return true;
185 } 185 }
186 186
187 ////////////////////////////////////////////////////////////////////////////// 187 //////////////////////////////////////////////////////////////////////////////
188 188
189 GrGLShaderBuilder::GrGLShaderBuilder(GrGpuGL* gpu, 189 GrGLShaderBuilder::GrGLShaderBuilder(GrGpuGL* gpu,
190 GrGLUniformManager& uniformManager, 190 GrGLUniformManager* uniformManager,
191 const GrGLProgramDesc& desc) 191 const GrGLProgramDesc& desc)
192 : fDesc(desc) 192 : fDesc(desc)
193 , fGpu(gpu) 193 , fGpu(gpu)
194 , fUniformManager(uniformManager) 194 , fUniformManager(SkRef(uniformManager))
195 , fFSFeaturesAddedMask(0) 195 , fFSFeaturesAddedMask(0)
196 , fFSInputs(kVarsPerBlock) 196 , fFSInputs(kVarsPerBlock)
197 , fFSOutputs(kMaxFSOutputs) 197 , fFSOutputs(kMaxFSOutputs)
198 , fUniforms(kVarsPerBlock) 198 , fUniforms(kVarsPerBlock)
199 , fSetupFragPosition(false) 199 , fSetupFragPosition(false)
200 , fHasCustomColorOutput(false) 200 , fHasCustomColorOutput(false)
201 , fHasSecondaryOutput(false) 201 , fHasSecondaryOutput(false)
202 , fTopLeftFragPosRead(kTopLeftFragPosRead_FragPosKey == desc.getHeader().fFr agPosKey) { 202 , fTopLeftFragPosRead(kTopLeftFragPosRead_FragPosKey == desc.getHeader().fFr agPosKey) {
203 203
204 const GrGLProgramDesc::KeyHeader& header = desc.getHeader(); 204 const GrGLProgramDesc::KeyHeader& header = desc.getHeader();
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 int count, 446 int count,
447 const char* * outName) { 447 const char* * outName) {
448 SkASSERT(name && strlen(name)); 448 SkASSERT(name && strlen(name));
449 SkDEBUGCODE(static const uint32_t kVisibilityMask = kVertex_Visibility | kFr agment_Visibility); 449 SkDEBUGCODE(static const uint32_t kVisibilityMask = kVertex_Visibility | kFr agment_Visibility);
450 SkASSERT(0 == (~kVisibilityMask & visibility)); 450 SkASSERT(0 == (~kVisibilityMask & visibility));
451 SkASSERT(0 != visibility); 451 SkASSERT(0 != visibility);
452 452
453 BuilderUniform& uni = fUniforms.push_back(); 453 BuilderUniform& uni = fUniforms.push_back();
454 UniformHandle h = GrGLUniformManager::UniformHandle::CreateFromUniformIndex( fUniforms.count() - 1); 454 UniformHandle h = GrGLUniformManager::UniformHandle::CreateFromUniformIndex( fUniforms.count() - 1);
455 SkDEBUGCODE(UniformHandle h2 =) 455 SkDEBUGCODE(UniformHandle h2 =)
456 fUniformManager.appendUniform(type, count); 456 fUniformManager->appendUniform(type, count);
457 // We expect the uniform manager to initially have no uniforms and that all uniforms are added 457 // We expect the uniform manager to initially have no uniforms and that all uniforms are added
458 // by this function. Therefore, the handles should match. 458 // by this function. Therefore, the handles should match.
459 SkASSERT(h2 == h); 459 SkASSERT(h2 == h);
460 uni.fVariable.setType(type); 460 uni.fVariable.setType(type);
461 uni.fVariable.setTypeModifier(GrGLShaderVar::kUniform_TypeModifier); 461 uni.fVariable.setTypeModifier(GrGLShaderVar::kUniform_TypeModifier);
462 this->nameVariable(uni.fVariable.accessName(), 'u', name); 462 this->nameVariable(uni.fVariable.accessName(), 'u', name);
463 uni.fVariable.setArrayCount(count); 463 uni.fVariable.setArrayCount(count);
464 uni.fVisibility = visibility; 464 uni.fVisibility = visibility;
465 465
466 // If it is visible in both the VS and FS, the precision must match. 466 // If it is visible in both the VS and FS, the precision must match.
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 } 675 }
676 676
677 SkTDArray<GrGLuint> shadersToDelete; 677 SkTDArray<GrGLuint> shadersToDelete;
678 678
679 if (!this->compileAndAttachShaders(programId, &shadersToDelete)) { 679 if (!this->compileAndAttachShaders(programId, &shadersToDelete)) {
680 GL_CALL(DeleteProgram(programId)); 680 GL_CALL(DeleteProgram(programId));
681 return false; 681 return false;
682 } 682 }
683 683
684 this->bindProgramLocations(programId); 684 this->bindProgramLocations(programId);
685 if (fUniformManager.isUsingBindUniform()) { 685 if (fUniformManager->isUsingBindUniform()) {
686 fUniformManager.getUniformLocations(programId, fUniforms); 686 fUniformManager->getUniformLocations(programId, fUniforms);
687 } 687 }
688 688
689 GL_CALL(LinkProgram(programId)); 689 GL_CALL(LinkProgram(programId));
690 690
691 // Calling GetProgramiv is expensive in Chromium. Assume success in release builds. 691 // Calling GetProgramiv is expensive in Chromium. Assume success in release builds.
692 bool checkLinked = !fGpu->ctxInfo().isChromium(); 692 bool checkLinked = !fGpu->ctxInfo().isChromium();
693 #ifdef SK_DEBUG 693 #ifdef SK_DEBUG
694 checkLinked = true; 694 checkLinked = true;
695 #endif 695 #endif
696 if (checkLinked) { 696 if (checkLinked) {
(...skipping 12 matching lines...) Expand all
709 &length, 709 &length,
710 (char*)log.get())); 710 (char*)log.get()));
711 GrPrintf((char*)log.get()); 711 GrPrintf((char*)log.get());
712 } 712 }
713 SkDEBUGFAIL("Error linking program"); 713 SkDEBUGFAIL("Error linking program");
714 GL_CALL(DeleteProgram(programId)); 714 GL_CALL(DeleteProgram(programId));
715 return false; 715 return false;
716 } 716 }
717 } 717 }
718 718
719 if (!fUniformManager.isUsingBindUniform()) { 719 if (!fUniformManager->isUsingBindUniform()) {
720 fUniformManager.getUniformLocations(programId, fUniforms); 720 fUniformManager->getUniformLocations(programId, fUniforms);
721 } 721 }
722 722
723 for (int i = 0; i < shadersToDelete.count(); ++i) { 723 for (int i = 0; i < shadersToDelete.count(); ++i) {
724 GL_CALL(DeleteShader(shadersToDelete[i])); 724 GL_CALL(DeleteShader(shadersToDelete[i]));
725 } 725 }
726 726
727 *outProgramId = programId; 727 *outProgramId = programId;
728 return true; 728 return true;
729 } 729 }
730 730
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 } 823 }
824 } 824 }
825 825
826 const GrGLContextInfo& GrGLShaderBuilder::ctxInfo() const { 826 const GrGLContextInfo& GrGLShaderBuilder::ctxInfo() const {
827 return fGpu->ctxInfo(); 827 return fGpu->ctxInfo();
828 } 828 }
829 829
830 //////////////////////////////////////////////////////////////////////////////// 830 ////////////////////////////////////////////////////////////////////////////////
831 831
832 GrGLFullShaderBuilder::GrGLFullShaderBuilder(GrGpuGL* gpu, 832 GrGLFullShaderBuilder::GrGLFullShaderBuilder(GrGpuGL* gpu,
833 GrGLUniformManager& uniformManager, 833 GrGLUniformManager* uniformManager,
834 const GrGLProgramDesc& desc) 834 const GrGLProgramDesc& desc)
835 : INHERITED(gpu, uniformManager, desc) 835 : INHERITED(gpu, uniformManager, desc)
836 , fVSAttrs(kVarsPerBlock) 836 , fVSAttrs(kVarsPerBlock)
837 , fVSOutputs(kVarsPerBlock) 837 , fVSOutputs(kVarsPerBlock)
838 , fGSInputs(kVarsPerBlock) 838 , fGSInputs(kVarsPerBlock)
839 , fGSOutputs(kVarsPerBlock) { 839 , fGSOutputs(kVarsPerBlock) {
840 840
841 const GrGLProgramDesc::KeyHeader& header = this->desc().getHeader(); 841 const GrGLProgramDesc::KeyHeader& header = this->desc().getHeader();
842 842
843 fPositionVar = &fVSAttrs.push_back(); 843 fPositionVar = &fVSAttrs.push_back();
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 1063
1064 const AttributePair* attribEnd = fEffectAttributes.end(); 1064 const AttributePair* attribEnd = fEffectAttributes.end();
1065 for (const AttributePair* attrib = fEffectAttributes.begin(); attrib != attr ibEnd; ++attrib) { 1065 for (const AttributePair* attrib = fEffectAttributes.begin(); attrib != attr ibEnd; ++attrib) {
1066 GL_CALL(BindAttribLocation(programId, attrib->fIndex, attrib->fName.c_s tr())); 1066 GL_CALL(BindAttribLocation(programId, attrib->fIndex, attrib->fName.c_s tr()));
1067 } 1067 }
1068 } 1068 }
1069 1069
1070 //////////////////////////////////////////////////////////////////////////////// 1070 ////////////////////////////////////////////////////////////////////////////////
1071 1071
1072 GrGLFragmentOnlyShaderBuilder::GrGLFragmentOnlyShaderBuilder(GrGpuGL* gpu, 1072 GrGLFragmentOnlyShaderBuilder::GrGLFragmentOnlyShaderBuilder(GrGpuGL* gpu,
1073 GrGLUniformManager& uniformManager, 1073 GrGLUniformManager* uniformManager,
1074 const GrGLProgramDe sc& desc) 1074 const GrGLProgramDe sc& desc)
1075 : INHERITED(gpu, uniformManager, desc) 1075 : INHERITED(gpu, uniformManager, desc)
1076 , fNumTexCoordSets(0) { 1076 , fNumTexCoordSets(0) {
1077 1077
1078 SkASSERT(!desc.getHeader().fHasVertexCode); 1078 SkASSERT(!desc.getHeader().fHasVertexCode);
1079 SkASSERT(gpu->glCaps().pathRenderingSupport()); 1079 SkASSERT(gpu->glCaps().pathRenderingSupport());
1080 SkASSERT(GrGLProgramDesc::kAttribute_ColorInput != desc.getHeader().fColorIn put); 1080 SkASSERT(GrGLProgramDesc::kAttribute_ColorInput != desc.getHeader().fColorIn put);
1081 SkASSERT(GrGLProgramDesc::kAttribute_ColorInput != desc.getHeader().fCoverag eInput); 1081 SkASSERT(GrGLProgramDesc::kAttribute_ColorInput != desc.getHeader().fCoverag eInput);
1082 } 1082 }
1083 1083
(...skipping 12 matching lines...) Expand all
1096 1096
1097 GrGLPathTexGenProgramEffectsBuilder pathTexGenEffectsBuilder(this, 1097 GrGLPathTexGenProgramEffectsBuilder pathTexGenEffectsBuilder(this,
1098 effectCnt); 1098 effectCnt);
1099 this->INHERITED::createAndEmitEffects(&pathTexGenEffectsBuilder, 1099 this->INHERITED::createAndEmitEffects(&pathTexGenEffectsBuilder,
1100 effectStages, 1100 effectStages,
1101 effectKeys, 1101 effectKeys,
1102 effectCnt, 1102 effectCnt,
1103 inOutFSColor); 1103 inOutFSColor);
1104 return pathTexGenEffectsBuilder.finish(); 1104 return pathTexGenEffectsBuilder.finish();
1105 } 1105 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLShaderBuilder.h ('k') | src/gpu/gl/GrGLUniformManager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698