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

Side by Side Diff: src/gpu/glsl/GrGLSLVarying.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/glsl/GrGLSLVarying.h ('k') | src/gpu/glsl/GrGLSLVertexShaderBuilder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "glsl/GrGLSLVarying.h"
9
10 #include "glsl/GrGLSLProgramBuilder.h"
11
12 void GrGLSLVaryingHandler::addPassThroughAttribute(const GrGeometryProcessor::At tribute* input,
13 const char* output) {
14 GrSLType type = GrVertexAttribTypeToSLType(input->fType);
15 GrGLSLVertToFrag v(type);
16 this->addVarying(input->fName, &v);
17 fProgramBuilder->fVS.codeAppendf("%s = %s;", v.vsOut(), input->fName);
18
19 if (fProgramBuilder->primitiveProcessor().willUseGeoShader()) {
20 fProgramBuilder->fGS.codeAppendf("%s = %s[0];", v.gsOut(), v.gsIn());
21 }
22
23 fProgramBuilder->fFS.codeAppendf("%s = %s;", output, v.fsIn());
24 }
25
26 void GrGLSLVaryingHandler::addVarying(const char* name,
27 GrGLSLVarying* varying,
28 GrSLPrecision precision) {
29 SkASSERT(varying);
30 if (varying->vsVarying()) {
31 this->addVertexVarying(name, precision, varying);
32 }
33 if (fProgramBuilder->primitiveProcessor().willUseGeoShader()) {
34 this->addGeomVarying(name, precision, varying);
35 }
36 if (varying->fsVarying()) {
37 this->addFragVarying(precision, varying);
38 }
39 }
40
41 void GrGLSLVaryingHandler::addVertexVarying(const char* name,
42 GrSLPrecision precision,
43 GrGLSLVarying* v) {
44 fVertexOutputs.push_back();
45 fVertexOutputs.back().setType(v->fType);
46 fVertexOutputs.back().setTypeModifier(GrGLSLShaderVar::kVaryingOut_TypeModif ier);
47 fVertexOutputs.back().setPrecision(precision);
48 fProgramBuilder->nameVariable(fVertexOutputs.back().accessName(), 'v', name) ;
49 v->fVsOut = fVertexOutputs.back().getName().c_str();
50 }
51 void GrGLSLVaryingHandler::addGeomVarying(const char* name,
52 GrSLPrecision precision,
53 GrGLSLVarying* v) {
54 // if we have a GS take each varying in as an array
55 // and output as non-array.
56 if (v->vsVarying()) {
57 fGeomInputs.push_back();
58 fGeomInputs.back().setType(v->fType);
59 fGeomInputs.back().setTypeModifier(GrGLSLShaderVar::kVaryingIn_TypeModif ier);
60 fGeomInputs.back().setPrecision(precision);
61 fGeomInputs.back().setUnsizedArray();
62 *fGeomInputs.back().accessName() = v->fVsOut;
63 v->fGsIn = v->fVsOut;
64 }
65
66 if (v->fsVarying()) {
67 fGeomOutputs.push_back();
68 fGeomOutputs.back().setType(v->fType);
69 fGeomOutputs.back().setTypeModifier(GrGLSLShaderVar::kVaryingOut_TypeMod ifier);
70 fGeomOutputs.back().setPrecision(precision);
71 fProgramBuilder->nameVariable(fGeomOutputs.back().accessName(), 'g', nam e);
72 v->fGsOut = fGeomOutputs.back().getName().c_str();
73 }
74 }
75
76 void GrGLSLVaryingHandler::addFragVarying(GrSLPrecision precision, GrGLSLVarying * v) {
77 v->fFsIn = v->fGsOut ? v->fGsOut : v->fVsOut;
78 fFragInputs.push_back().set(v->fType,
79 GrGLSLShaderVar::kVaryingIn_TypeModifier,
80 v->fFsIn,
81 precision);
82 }
83
84 void GrGLSLVaryingHandler::emitAttributes(const GrGeometryProcessor& gp) {
85 int vaCount = gp.numAttribs();
86 for (int i = 0; i < vaCount; i++) {
87 const GrGeometryProcessor::Attribute& attr = gp.getAttrib(i);
88 this->addAttribute(GrShaderVar(attr.fName,
89 GrVertexAttribTypeToSLType(attr.fType),
90 GrShaderVar::kAttribute_TypeModifier,
91 GrShaderVar::kNonArray,
92 attr.fPrecision));
93 }
94 }
95
96 void GrGLSLVaryingHandler::addAttribute(const GrShaderVar& var) {
97 SkASSERT(GrShaderVar::kAttribute_TypeModifier == var.getTypeModifier());
98 for (int j = 0; j < fVertexInputs.count(); ++j) {
99 const GrGLSLShaderVar& attr = fVertexInputs[j];
100 // if attribute already added, don't add it again
101 if (attr.getName().equals(var.getName())) {
102 return;
103 }
104 }
105 fVertexInputs.push_back(var);
106 }
107
108 void GrGLSLVaryingHandler::appendDecls(const VarArray& vars, SkString* out) cons t {
109 for (int i = 0; i < vars.count(); ++i) {
110 vars[i].appendDecl(fProgramBuilder->glslCaps(), out);
111 out->append(";");
112 }
113 }
114
115 void GrGLSLVaryingHandler::getVertexDecls(SkString* inputDecls, SkString* output Decls) const {
116 this->appendDecls(fVertexInputs, inputDecls);
117 this->appendDecls(fVertexOutputs, outputDecls);
118 }
119
120 void GrGLSLVaryingHandler::getGeomDecls(SkString* inputDecls, SkString* outputDe cls) const {
121 this->appendDecls(fGeomInputs, inputDecls);
122 this->appendDecls(fGeomOutputs, outputDecls);
123 }
124
125 void GrGLSLVaryingHandler::getFragDecls(SkString* inputDecls, SkString* outputDe cls) const {
126 // We should not have any outputs in the fragment shader when using version 1.10
127 SkASSERT(k110_GrGLSLGeneration != fProgramBuilder->glslCaps()->generation() ||
128 fFragOutputs.empty());
129 this->appendDecls(fFragInputs, inputDecls);
130 this->appendDecls(fFragOutputs, outputDecls);
131 }
132
OLDNEW
« no previous file with comments | « src/gpu/glsl/GrGLSLVarying.h ('k') | src/gpu/glsl/GrGLSLVertexShaderBuilder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698