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

Side by Side Diff: src/gpu/glsl/GrGLSLVarying.cpp

Issue 1673093002: Use noperspective interpolation for 2D draws (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: GrShaderBits->GrShaderFlags Created 4 years, 10 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
« src/gpu/glsl/GrGLSLShaderVar.h ('K') | « src/gpu/glsl/GrGLSLVarying.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 2015 Google Inc. 2 * Copyright 2015 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 "glsl/GrGLSLVarying.h" 8 #include "glsl/GrGLSLVarying.h"
9 9
10 #include "glsl/GrGLSLProgramBuilder.h" 10 #include "glsl/GrGLSLProgramBuilder.h"
11 11
12 void GrGLSLVaryingHandler::addPassThroughAttribute(const GrGeometryProcessor::At tribute* input, 12 void GrGLSLVaryingHandler::addPassThroughAttribute(const GrGeometryProcessor::At tribute* input,
13 const char* output) { 13 const char* output, GrSLPreci sion precision) {
14 GrSLType type = GrVertexAttribTypeToSLType(input->fType); 14 GrSLType type = GrVertexAttribTypeToSLType(input->fType);
15 GrGLSLVertToFrag v(type); 15 GrGLSLVertToFrag v(type);
16 this->addVarying(input->fName, &v); 16 this->addVarying(input->fName, &v, precision);
17 this->writePassThroughAttribute(input, output, v);
18 }
19
20 void GrGLSLVaryingHandler::addFlatPassThroughAttribute(const GrGeometryProcessor ::Attribute* input,
21 const char* output,
22 GrSLPrecision precision) {
23 GrSLType type = GrVertexAttribTypeToSLType(input->fType);
24 GrGLSLVertToFrag v(type);
25 this->addFlatVarying(input->fName, &v, precision);
26 this->writePassThroughAttribute(input, output, v);
27 }
28
29 void GrGLSLVaryingHandler::writePassThroughAttribute(const GrGeometryProcessor:: Attribute* input,
30 const char* output, const G rGLSLVarying& v) {
17 fProgramBuilder->fVS.codeAppendf("%s = %s;", v.vsOut(), input->fName); 31 fProgramBuilder->fVS.codeAppendf("%s = %s;", v.vsOut(), input->fName);
18 32
19 if (fProgramBuilder->primitiveProcessor().willUseGeoShader()) { 33 if (fProgramBuilder->primitiveProcessor().willUseGeoShader()) {
20 fProgramBuilder->fGS.codeAppendf("%s = %s[0];", v.gsOut(), v.gsIn()); 34 fProgramBuilder->fGS.codeAppendf("%s = %s[0];", v.gsOut(), v.gsIn());
21 } 35 }
22 36
23 fProgramBuilder->fFS.codeAppendf("%s = %s;", output, v.fsIn()); 37 fProgramBuilder->fFS.codeAppendf("%s = %s;", output, v.fsIn());
24 } 38 }
25 39
26 void GrGLSLVaryingHandler::addVarying(const char* name, 40 void GrGLSLVaryingHandler::internalAddVarying(const char* name,
27 GrGLSLVarying* varying, 41 GrGLSLVarying* varying,
28 GrSLPrecision precision) { 42 GrSLPrecision precision,
43 bool flat) {
44 bool willUseGeoShader = fProgramBuilder->primitiveProcessor().willUseGeoShad er();
29 SkASSERT(varying); 45 SkASSERT(varying);
46 SkASSERT(varying->vsVarying() || willUseGeoShader);
egdaniel 2016/02/12 03:55:07 if we add this assert, shouldn't we also have SkAS
Chris Dalton 2016/02/12 16:25:28 My idea behind that assert was that it made sure t
47
48 VaryingInfo& v = fVaryings.push_back();
egdaniel 2016/02/12 03:55:07 I don't necessarily dislike this VaryingInfo thing
Chris Dalton 2016/02/12 16:25:28 Yeah, you get a compile error if you use both (whi
egdaniel 2016/02/12 16:33:58 Just throwing in an idea off your comment. Would i
49 v.fType = varying->fType;
50 v.fPrecision = precision;
51 v.fIsFlat = flat;
52 v.fVisibility = kNone_GrShaderFlags;
30 if (varying->vsVarying()) { 53 if (varying->vsVarying()) {
31 this->addVertexVarying(name, precision, varying); 54 v.fVisibility |= kVertex_GrShaderFlag;
55 fProgramBuilder->nameVariable(&v.fVsOut, 'v', name);
56 varying->fVsOut = v.fVsOut.c_str();
32 } 57 }
33 if (fProgramBuilder->primitiveProcessor().willUseGeoShader()) { 58 if (willUseGeoShader) {
34 this->addGeomVarying(name, precision, varying); 59 v.fVisibility |= kGeometry_GrShaderFlag;
60 fProgramBuilder->nameVariable(&v.fGsOut, 'g', name);
61 varying->fGsIn = v.fVsOut.c_str();
62 varying->fGsOut = v.fGsOut.c_str();
35 } 63 }
36 if (varying->fsVarying()) { 64 if (varying->fsVarying()) {
37 this->addFragVarying(precision, varying); 65 v.fVisibility |= kFragment_GrShaderFlag;
66 varying->fFsIn = (willUseGeoShader ? v.fGsOut : v.fVsOut).c_str();
38 } 67 }
39 } 68 }
40 69
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) { 70 void GrGLSLVaryingHandler::emitAttributes(const GrGeometryProcessor& gp) {
85 int vaCount = gp.numAttribs(); 71 int vaCount = gp.numAttribs();
86 for (int i = 0; i < vaCount; i++) { 72 for (int i = 0; i < vaCount; i++) {
87 const GrGeometryProcessor::Attribute& attr = gp.getAttrib(i); 73 const GrGeometryProcessor::Attribute& attr = gp.getAttrib(i);
88 this->addAttribute(GrShaderVar(attr.fName, 74 this->addAttribute(GrShaderVar(attr.fName,
89 GrVertexAttribTypeToSLType(attr.fType), 75 GrVertexAttribTypeToSLType(attr.fType),
90 GrShaderVar::kAttribute_TypeModifier, 76 GrShaderVar::kAttribute_TypeModifier,
91 GrShaderVar::kNonArray, 77 GrShaderVar::kNonArray,
92 attr.fPrecision)); 78 attr.fPrecision));
93 } 79 }
94 } 80 }
95 81
96 void GrGLSLVaryingHandler::addAttribute(const GrShaderVar& var) { 82 void GrGLSLVaryingHandler::addAttribute(const GrShaderVar& var) {
97 SkASSERT(GrShaderVar::kAttribute_TypeModifier == var.getTypeModifier()); 83 SkASSERT(GrShaderVar::kAttribute_TypeModifier == var.getTypeModifier());
98 for (int j = 0; j < fVertexInputs.count(); ++j) { 84 for (int j = 0; j < fVertexInputs.count(); ++j) {
99 const GrGLSLShaderVar& attr = fVertexInputs[j]; 85 const GrGLSLShaderVar& attr = fVertexInputs[j];
100 // if attribute already added, don't add it again 86 // if attribute already added, don't add it again
101 if (attr.getName().equals(var.getName())) { 87 if (attr.getName().equals(var.getName())) {
102 return; 88 return;
103 } 89 }
104 } 90 }
105 fVertexInputs.push_back(var); 91 fVertexInputs.push_back(var);
106 } 92 }
107 93
94 void GrGLSLVaryingHandler::setNoPerspective() {
95 const GrGLSLCaps& caps = *fProgramBuilder->glslCaps();
96 if (!caps.noperspectiveInterpolationSupport()) {
97 return;
98 }
99 if (const char* extension = caps.noperspectiveInterpolationExtensionString() ) {
100 int bit = 1 << GrGLSLFragmentShaderBuilder::kNoPerspectiveInterpolation_ GLSLPrivateFeature;
101 fProgramBuilder->fVS.addFeature(bit, extension);
102 if (fProgramBuilder->primitiveProcessor().willUseGeoShader()) {
103 fProgramBuilder->fGS.addFeature(bit, extension);
104 }
105 fProgramBuilder->fFS.addFeature(bit, extension);
106 }
107 fDefaultInterpolationModifier = "noperspective";
108 }
109
108 void GrGLSLVaryingHandler::finalize() { 110 void GrGLSLVaryingHandler::finalize() {
111 for (int i = 0; i < fVaryings.count(); ++i) {
112 const VaryingInfo& v = this->fVaryings[i];
113 const char* modifier = v.fIsFlat ? "flat" : fDefaultInterpolationModifie r;
114 if (v.fVisibility & kVertex_GrShaderFlag) {
115 fVertexOutputs.push_back().set(v.fType, GrShaderVar::kVaryingOut_Typ eModifier, v.fVsOut,
116 v.fPrecision, nullptr, modifier);
117 if (v.fVisibility & kGeometry_GrShaderFlag) {
118 fGeomInputs.push_back().set(v.fType, GrShaderVar::kVaryingIn_Typ eModifier, v.fVsOut,
119 GrShaderVar::kUnsizedArray, v.fPreci sion, nullptr,
120 modifier);
121 }
122 }
123 if (v.fVisibility & kFragment_GrShaderFlag) {
124 const char* fsIn = v.fVsOut.c_str();
125 if (v.fVisibility & kGeometry_GrShaderFlag) {
126 fGeomOutputs.push_back().set(v.fType, GrGLSLShaderVar::kVaryingO ut_TypeModifier,
127 v.fGsOut, v.fPrecision, nullptr, mo difier);
128 fsIn = v.fGsOut.c_str();
129 }
130 fFragInputs.push_back().set(v.fType, GrShaderVar::kVaryingIn_TypeMod ifier, fsIn,
131 v.fPrecision, nullptr, modifier);
132 }
133 }
109 this->onFinalize(); 134 this->onFinalize();
110 } 135 }
111 136
112 void GrGLSLVaryingHandler::appendDecls(const VarArray& vars, SkString* out) cons t { 137 void GrGLSLVaryingHandler::appendDecls(const VarArray& vars, SkString* out) cons t {
113 for (int i = 0; i < vars.count(); ++i) { 138 for (int i = 0; i < vars.count(); ++i) {
114 vars[i].appendDecl(fProgramBuilder->glslCaps(), out); 139 vars[i].appendDecl(fProgramBuilder->glslCaps(), out);
115 out->append(";"); 140 out->append(";");
116 } 141 }
117 } 142 }
118 143
119 void GrGLSLVaryingHandler::getVertexDecls(SkString* inputDecls, SkString* output Decls) const { 144 void GrGLSLVaryingHandler::getVertexDecls(SkString* inputDecls, SkString* output Decls) const {
120 this->appendDecls(fVertexInputs, inputDecls); 145 this->appendDecls(fVertexInputs, inputDecls);
121 this->appendDecls(fVertexOutputs, outputDecls); 146 this->appendDecls(fVertexOutputs, outputDecls);
122 } 147 }
123 148
124 void GrGLSLVaryingHandler::getGeomDecls(SkString* inputDecls, SkString* outputDe cls) const { 149 void GrGLSLVaryingHandler::getGeomDecls(SkString* inputDecls, SkString* outputDe cls) const {
125 this->appendDecls(fGeomInputs, inputDecls); 150 this->appendDecls(fGeomInputs, inputDecls);
126 this->appendDecls(fGeomOutputs, outputDecls); 151 this->appendDecls(fGeomOutputs, outputDecls);
127 } 152 }
128 153
129 void GrGLSLVaryingHandler::getFragDecls(SkString* inputDecls, SkString* outputDe cls) const { 154 void GrGLSLVaryingHandler::getFragDecls(SkString* inputDecls, SkString* outputDe cls) const {
130 // We should not have any outputs in the fragment shader when using version 1.10 155 // We should not have any outputs in the fragment shader when using version 1.10
131 SkASSERT(k110_GrGLSLGeneration != fProgramBuilder->glslCaps()->generation() || 156 SkASSERT(k110_GrGLSLGeneration != fProgramBuilder->glslCaps()->generation() ||
132 fFragOutputs.empty()); 157 fFragOutputs.empty());
133 this->appendDecls(fFragInputs, inputDecls); 158 this->appendDecls(fFragInputs, inputDecls);
134 this->appendDecls(fFragOutputs, outputDecls); 159 this->appendDecls(fFragOutputs, outputDecls);
135 } 160 }
136 161
OLDNEW
« src/gpu/glsl/GrGLSLShaderVar.h ('K') | « src/gpu/glsl/GrGLSLVarying.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698