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

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

Issue 1462123003: Create GrGLSLVaryingHandler class for program building (Closed) Base URL: https://skia.googlesource.com/skia.git@putCapsOnArgs
Patch Set: fix release builder 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/GrGLProgramBuilder.h ('k') | src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp » ('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 "GrGLProgramBuilder.h" 8 #include "GrGLProgramBuilder.h"
9 9
10 #include "GrAutoLocaleSetter.h" 10 #include "GrAutoLocaleSetter.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 50
51 ///////////////////////////////////////////////////////////////////////////// 51 /////////////////////////////////////////////////////////////////////////////
52 52
53 GrGLProgramBuilder::GrGLProgramBuilder(GrGLGpu* gpu, const DrawArgs& args) 53 GrGLProgramBuilder::GrGLProgramBuilder(GrGLGpu* gpu, const DrawArgs& args)
54 : INHERITED(args) 54 : INHERITED(args)
55 , fGeometryProcessor(nullptr) 55 , fGeometryProcessor(nullptr)
56 , fXferProcessor(nullptr) 56 , fXferProcessor(nullptr)
57 , fGpu(gpu) 57 , fGpu(gpu)
58 , fUniforms(kVarsPerBlock) 58 , fUniforms(kVarsPerBlock)
59 , fSamplerUniforms(4) 59 , fSamplerUniforms(4)
60 , fSeparableVaryingInfos(kVarsPerBlock) { 60 , fVaryingHandler(this) {
61 }
62
63 void GrGLProgramBuilder::addVarying(const char* name,
64 GrGLSLVarying* varying,
65 GrSLPrecision precision) {
66 SkASSERT(varying);
67 if (varying->vsVarying()) {
68 fVS.addVarying(name, precision, varying);
69 }
70 if (this->primitiveProcessor().willUseGeoShader()) {
71 fGS.addVarying(name, precision, varying);
72 }
73 if (varying->fsVarying()) {
74 fFS.addVarying(varying, precision);
75 }
76 }
77
78 void GrGLProgramBuilder::addPassThroughAttribute(const GrPrimitiveProcessor::Att ribute* input,
79 const char* output) {
80 GrSLType type = GrVertexAttribTypeToSLType(input->fType);
81 GrGLSLVertToFrag v(type);
82 this->addVarying(input->fName, &v);
83 fVS.codeAppendf("%s = %s;", v.vsOut(), input->fName);
84 fFS.codeAppendf("%s = %s;", output, v.fsIn());
85 }
86
87 GrGLProgramBuilder::SeparableVaryingHandle GrGLProgramBuilder::addSeparableVaryi ng(
88 const ch ar* name,
89 GrGLSLVe rtToFrag* v,
90 GrSLPrec ision fsPrecision) {
91 // This call is not used for non-NVPR backends.
92 SkASSERT(fGpu->glCaps().shaderCaps()->pathRenderingSupport() &&
93 fArgs.fPrimitiveProcessor->isPathRendering() &&
94 !fArgs.fPrimitiveProcessor->willUseGeoShader() &&
95 fArgs.fPrimitiveProcessor->numAttribs() == 0);
96 this->addVarying(name, v, fsPrecision);
97 SeparableVaryingInfo& varyingInfo = fSeparableVaryingInfos.push_back();
98 varyingInfo.fVariable = fFS.fInputs.back();
99 varyingInfo.fLocation = fSeparableVaryingInfos.count() - 1;
100 return SeparableVaryingHandle(varyingInfo.fLocation);
101 } 61 }
102 62
103 GrGLSLProgramDataManager::UniformHandle GrGLProgramBuilder::internalAddUniformAr ray( 63 GrGLSLProgramDataManager::UniformHandle GrGLProgramBuilder::internalAddUniformAr ray(
104 uint32_t visibil ity, 64 uint32_t visibil ity,
105 GrSLType type, 65 GrSLType type,
106 GrSLPrecision pr ecision, 66 GrSLPrecision pr ecision,
107 const char* name , 67 const char* name ,
108 bool mangleName, 68 bool mangleName,
109 int count, 69 int count,
110 const char** out Name) { 70 const char** out Name) {
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 fGeometryProcessor = new GrGLInstalledGeoProc; 242 fGeometryProcessor = new GrGLInstalledGeoProc;
283 243
284 fGeometryProcessor->fGLProc.reset(gp.createGLSLInstance(*fGpu->glCaps().glsl Caps())); 244 fGeometryProcessor->fGLProc.reset(gp.createGLSLInstance(*fGpu->glCaps().glsl Caps()));
285 245
286 SkSTArray<4, GrGLSLTextureSampler> samplers(gp.numTextures()); 246 SkSTArray<4, GrGLSLTextureSampler> samplers(gp.numTextures());
287 this->emitSamplers(gp, &samplers, fGeometryProcessor); 247 this->emitSamplers(gp, &samplers, fGeometryProcessor);
288 248
289 GrGLSLGeometryProcessor::EmitArgs args(this, 249 GrGLSLGeometryProcessor::EmitArgs args(this,
290 &fVS, 250 &fVS,
291 &fFS, 251 &fFS,
252 &fVaryingHandler,
292 this->glslCaps(), 253 this->glslCaps(),
293 gp, 254 gp,
294 outColor, 255 outColor,
295 outCoverage, 256 outCoverage,
296 samplers, 257 samplers,
297 fCoordTransforms, 258 fCoordTransforms,
298 &fOutCoords); 259 &fOutCoords);
299 fGeometryProcessor->fGLProc->emitCode(args); 260 fGeometryProcessor->fGLProc->emitCode(args);
300 261
301 // We have to check that effects and the code they emit are consistent, ie i f an effect 262 // We have to check that effects and the code they emit are consistent, ie i f an effect
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 if (fFS.hasSecondaryOutput() && caps.glslCaps()->mustDeclareFragmentShaderOu tput()) { 428 if (fFS.hasSecondaryOutput() && caps.glslCaps()->mustDeclareFragmentShaderOu tput()) {
468 GL_CALL(BindFragDataLocationIndexed(programID, 0, 1, 429 GL_CALL(BindFragDataLocationIndexed(programID, 0, 1,
469 GrGLSLFragmentShaderBuilder::DeclaredSecondary ColorOutputName())); 430 GrGLSLFragmentShaderBuilder::DeclaredSecondary ColorOutputName()));
470 } 431 }
471 432
472 // handle NVPR separable varyings 433 // handle NVPR separable varyings
473 if (!fGpu->glCaps().shaderCaps()->pathRenderingSupport() || 434 if (!fGpu->glCaps().shaderCaps()->pathRenderingSupport() ||
474 !fGpu->glPathRendering()->shouldBindFragmentInputs()) { 435 !fGpu->glPathRendering()->shouldBindFragmentInputs()) {
475 return; 436 return;
476 } 437 }
477 int count = fSeparableVaryingInfos.count(); 438 int count = fVaryingHandler.fPathProcVaryingInfos.count();
478 for (int i = 0; i < count; ++i) { 439 for (int i = 0; i < count; ++i) {
479 GL_CALL(BindFragmentInputLocation(programID, 440 GL_CALL(BindFragmentInputLocation(programID, i,
480 i, 441 fVaryingHandler.fPathProcVaryingInfos[i]. fVariable.c_str()));
481 fSeparableVaryingInfos[i].fVariable.c_ str())); 442 fVaryingHandler.fPathProcVaryingInfos[i].fLocation = i;
482 fSeparableVaryingInfos[i].fLocation = i;
483 } 443 }
484 } 444 }
485 445
486 bool GrGLProgramBuilder::checkLinkStatus(GrGLuint programID) { 446 bool GrGLProgramBuilder::checkLinkStatus(GrGLuint programID) {
487 GrGLint linked = GR_GL_INIT_ZERO; 447 GrGLint linked = GR_GL_INIT_ZERO;
488 GL_CALL(GetProgramiv(programID, GR_GL_LINK_STATUS, &linked)); 448 GL_CALL(GetProgramiv(programID, GR_GL_LINK_STATUS, &linked));
489 if (!linked) { 449 if (!linked) {
490 GrGLint infoLen = GR_GL_INIT_ZERO; 450 GrGLint infoLen = GR_GL_INIT_ZERO;
491 GL_CALL(GetProgramiv(programID, GR_GL_INFO_LOG_LENGTH, &infoLen)); 451 GL_CALL(GetProgramiv(programID, GR_GL_INFO_LOG_LENGTH, &infoLen));
492 SkAutoMalloc log(sizeof(char)*(infoLen+1)); // outside if for debugger 452 SkAutoMalloc log(sizeof(char)*(infoLen+1)); // outside if for debugger
(...skipping 22 matching lines...) Expand all
515 GL_CALL_RET(location, GetUniformLocation(programID, fUniforms[i].fVa riable.c_str())); 475 GL_CALL_RET(location, GetUniformLocation(programID, fUniforms[i].fVa riable.c_str()));
516 fUniforms[i].fLocation = location; 476 fUniforms[i].fLocation = location;
517 } 477 }
518 } 478 }
519 479
520 // handle NVPR separable varyings 480 // handle NVPR separable varyings
521 if (!fGpu->glCaps().shaderCaps()->pathRenderingSupport() || 481 if (!fGpu->glCaps().shaderCaps()->pathRenderingSupport() ||
522 !fGpu->glPathRendering()->shouldBindFragmentInputs()) { 482 !fGpu->glPathRendering()->shouldBindFragmentInputs()) {
523 return; 483 return;
524 } 484 }
525 int count = fSeparableVaryingInfos.count(); 485 int count = fVaryingHandler.fPathProcVaryingInfos.count();
526 for (int i = 0; i < count; ++i) { 486 for (int i = 0; i < count; ++i) {
527 GrGLint location; 487 GrGLint location;
528 GL_CALL_RET(location, 488 GL_CALL_RET(location, GetProgramResourceLocation(
529 GetProgramResourceLocation(programID, 489 programID,
530 GR_GL_FRAGMENT_INPUT, 490 GR_GL_FRAGMENT_INPUT,
531 fSeparableVaryingInfos[i].fVariab le.c_str())); 491 fVaryingHandler.fPathProcVaryingInfos[i]. fVariable.c_str()));
532 fSeparableVaryingInfos[i].fLocation = location; 492 fVaryingHandler.fPathProcVaryingInfos[i].fLocation = location;
533 } 493 }
534 } 494 }
535 495
536 void GrGLProgramBuilder::cleanupProgram(GrGLuint programID, const SkTDArray<GrGL uint>& shaderIDs) { 496 void GrGLProgramBuilder::cleanupProgram(GrGLuint programID, const SkTDArray<GrGL uint>& shaderIDs) {
537 GL_CALL(DeleteProgram(programID)); 497 GL_CALL(DeleteProgram(programID));
538 cleanupShaders(shaderIDs); 498 cleanupShaders(shaderIDs);
539 } 499 }
540 void GrGLProgramBuilder::cleanupShaders(const SkTDArray<GrGLuint>& shaderIDs) { 500 void GrGLProgramBuilder::cleanupShaders(const SkTDArray<GrGLuint>& shaderIDs) {
541 for (int i = 0; i < shaderIDs.count(); ++i) { 501 for (int i = 0; i < shaderIDs.count(); ++i) {
542 GL_CALL(DeleteShader(shaderIDs[i])); 502 GL_CALL(DeleteShader(shaderIDs[i]));
543 } 503 }
544 } 504 }
545 505
546 GrGLProgram* GrGLProgramBuilder::createProgram(GrGLuint programID) { 506 GrGLProgram* GrGLProgramBuilder::createProgram(GrGLuint programID) {
547 return new GrGLProgram(fGpu, this->desc(), fUniformHandles, programID, fUnif orms, 507 return new GrGLProgram(fGpu, this->desc(), fUniformHandles, programID, fUnif orms,
548 fSeparableVaryingInfos, 508 fVaryingHandler.fPathProcVaryingInfos,
549 fGeometryProcessor, fXferProcessor, fFragmentProcesso rs.get(), 509 fGeometryProcessor, fXferProcessor, fFragmentProcesso rs.get(),
550 &fSamplerUniforms); 510 &fSamplerUniforms);
551 } 511 }
552 512
553 //////////////////////////////////////////////////////////////////////////////// /////////////////// 513 //////////////////////////////////////////////////////////////////////////////// ///////////////////
554 514
555 GrGLInstalledFragProcs::~GrGLInstalledFragProcs() { 515 GrGLInstalledFragProcs::~GrGLInstalledFragProcs() {
556 int numProcs = fProcs.count(); 516 int numProcs = fProcs.count();
557 for (int i = 0; i < numProcs; ++i) { 517 for (int i = 0; i < numProcs; ++i) {
558 delete fProcs[i]; 518 delete fProcs[i];
559 } 519 }
560 } 520 }
OLDNEW
« no previous file with comments | « src/gpu/gl/builders/GrGLProgramBuilder.h ('k') | src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698