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

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: fName -> fVsOut 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
« no previous file with comments | « 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();
45 VaryingInfo& v = fVaryings.push_back();
46
29 SkASSERT(varying); 47 SkASSERT(varying);
48 v.fType = varying->fType;
49 v.fPrecision = precision;
50 v.fIsFlat = flat;
51 fProgramBuilder->nameVariable(&v.fVsOut, 'v', name);
52 v.fVisibility = kNone_GrShaderFlags;
30 if (varying->vsVarying()) { 53 if (varying->vsVarying()) {
31 this->addVertexVarying(name, precision, varying); 54 varying->fVsOut = v.fVsOut.c_str();
55 v.fVisibility |= kVertex_GrShaderFlag;
32 } 56 }
33 if (fProgramBuilder->primitiveProcessor().willUseGeoShader()) { 57 if (willUseGeoShader) {
34 this->addGeomVarying(name, precision, varying); 58 fProgramBuilder->nameVariable(&v.fGsOut, 'g', name);
59 varying->fGsIn = v.fVsOut.c_str();
60 varying->fGsOut = v.fGsOut.c_str();
61 v.fVisibility |= kGeometry_GrShaderFlag;
35 } 62 }
36 if (varying->fsVarying()) { 63 if (varying->fsVarying()) {
37 this->addFragVarying(precision, varying); 64 varying->fFsIn = (willUseGeoShader ? v.fGsOut : v.fVsOut).c_str();
65 v.fVisibility |= kFragment_GrShaderFlag;
38 } 66 }
39 } 67 }
40 68
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) { 69 void GrGLSLVaryingHandler::emitAttributes(const GrGeometryProcessor& gp) {
85 int vaCount = gp.numAttribs(); 70 int vaCount = gp.numAttribs();
86 for (int i = 0; i < vaCount; i++) { 71 for (int i = 0; i < vaCount; i++) {
87 const GrGeometryProcessor::Attribute& attr = gp.getAttrib(i); 72 const GrGeometryProcessor::Attribute& attr = gp.getAttrib(i);
88 this->addAttribute(GrShaderVar(attr.fName, 73 this->addAttribute(GrShaderVar(attr.fName,
89 GrVertexAttribTypeToSLType(attr.fType), 74 GrVertexAttribTypeToSLType(attr.fType),
90 GrShaderVar::kAttribute_TypeModifier, 75 GrShaderVar::kAttribute_TypeModifier,
91 GrShaderVar::kNonArray, 76 GrShaderVar::kNonArray,
92 attr.fPrecision)); 77 attr.fPrecision));
93 } 78 }
94 } 79 }
95 80
96 void GrGLSLVaryingHandler::addAttribute(const GrShaderVar& var) { 81 void GrGLSLVaryingHandler::addAttribute(const GrShaderVar& var) {
97 SkASSERT(GrShaderVar::kAttribute_TypeModifier == var.getTypeModifier()); 82 SkASSERT(GrShaderVar::kAttribute_TypeModifier == var.getTypeModifier());
98 for (int j = 0; j < fVertexInputs.count(); ++j) { 83 for (int j = 0; j < fVertexInputs.count(); ++j) {
99 const GrGLSLShaderVar& attr = fVertexInputs[j]; 84 const GrGLSLShaderVar& attr = fVertexInputs[j];
100 // if attribute already added, don't add it again 85 // if attribute already added, don't add it again
101 if (attr.getName().equals(var.getName())) { 86 if (attr.getName().equals(var.getName())) {
102 return; 87 return;
103 } 88 }
104 } 89 }
105 fVertexInputs.push_back(var); 90 fVertexInputs.push_back(var);
106 } 91 }
107 92
93 void GrGLSLVaryingHandler::setNoPerspective() {
94 const GrGLSLCaps& caps = *fProgramBuilder->glslCaps();
95 if (!caps.noperspectiveInterpolationSupport()) {
96 return;
97 }
98 if (const char* extension = caps.noperspectiveInterpolationExtensionString() ) {
99 int bit = 1 << GrGLSLFragmentShaderBuilder::kNoPerspectiveInterpolation_ GLSLPrivateFeature;
100 fProgramBuilder->fVS.addFeature(bit, extension);
101 if (fProgramBuilder->primitiveProcessor().willUseGeoShader()) {
102 fProgramBuilder->fGS.addFeature(bit, extension);
103 }
104 fProgramBuilder->fFS.addFeature(bit, extension);
105 }
106 fDefaultInterpolationModifier = "noperspective";
107 }
108
108 void GrGLSLVaryingHandler::finalize() { 109 void GrGLSLVaryingHandler::finalize() {
110 for (int i = 0; i < fVaryings.count(); ++i) {
111 const VaryingInfo& v = this->fVaryings[i];
112 const char* modifier = v.fIsFlat ? "flat" : fDefaultInterpolationModifie r;
113 if (v.fVisibility & kVertex_GrShaderFlag) {
114 fVertexOutputs.push_back().set(v.fType, GrShaderVar::kVaryingOut_Typ eModifier, v.fVsOut,
115 v.fPrecision, nullptr, modifier);
116 if (v.fVisibility & kGeometry_GrShaderFlag) {
117 fGeomInputs.push_back().set(v.fType, GrShaderVar::kVaryingIn_Typ eModifier, v.fVsOut,
118 GrShaderVar::kUnsizedArray, v.fPreci sion, nullptr,
119 modifier);
120 }
121 }
122 if (v.fVisibility & kFragment_GrShaderFlag) {
123 const char* fsIn = v.fVsOut.c_str();
124 if (v.fVisibility & kGeometry_GrShaderFlag) {
125 fGeomOutputs.push_back().set(v.fType, GrGLSLShaderVar::kVaryingO ut_TypeModifier,
126 v.fGsOut, v.fPrecision, nullptr, mo difier);
127 fsIn = v.fGsOut.c_str();
128 }
129 fFragInputs.push_back().set(v.fType, GrShaderVar::kVaryingIn_TypeMod ifier, fsIn,
130 v.fPrecision, nullptr, modifier);
131 }
132 }
109 this->onFinalize(); 133 this->onFinalize();
110 } 134 }
111 135
112 void GrGLSLVaryingHandler::appendDecls(const VarArray& vars, SkString* out) cons t { 136 void GrGLSLVaryingHandler::appendDecls(const VarArray& vars, SkString* out) cons t {
113 for (int i = 0; i < vars.count(); ++i) { 137 for (int i = 0; i < vars.count(); ++i) {
114 vars[i].appendDecl(fProgramBuilder->glslCaps(), out); 138 vars[i].appendDecl(fProgramBuilder->glslCaps(), out);
115 out->append(";"); 139 out->append(";");
116 } 140 }
117 } 141 }
118 142
119 void GrGLSLVaryingHandler::getVertexDecls(SkString* inputDecls, SkString* output Decls) const { 143 void GrGLSLVaryingHandler::getVertexDecls(SkString* inputDecls, SkString* output Decls) const {
120 this->appendDecls(fVertexInputs, inputDecls); 144 this->appendDecls(fVertexInputs, inputDecls);
121 this->appendDecls(fVertexOutputs, outputDecls); 145 this->appendDecls(fVertexOutputs, outputDecls);
122 } 146 }
123 147
124 void GrGLSLVaryingHandler::getGeomDecls(SkString* inputDecls, SkString* outputDe cls) const { 148 void GrGLSLVaryingHandler::getGeomDecls(SkString* inputDecls, SkString* outputDe cls) const {
125 this->appendDecls(fGeomInputs, inputDecls); 149 this->appendDecls(fGeomInputs, inputDecls);
126 this->appendDecls(fGeomOutputs, outputDecls); 150 this->appendDecls(fGeomOutputs, outputDecls);
127 } 151 }
128 152
129 void GrGLSLVaryingHandler::getFragDecls(SkString* inputDecls, SkString* outputDe cls) const { 153 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 154 // We should not have any outputs in the fragment shader when using version 1.10
131 SkASSERT(k110_GrGLSLGeneration != fProgramBuilder->glslCaps()->generation() || 155 SkASSERT(k110_GrGLSLGeneration != fProgramBuilder->glslCaps()->generation() ||
132 fFragOutputs.empty()); 156 fFragOutputs.empty());
133 this->appendDecls(fFragInputs, inputDecls); 157 this->appendDecls(fFragInputs, inputDecls);
134 this->appendDecls(fFragOutputs, outputDecls); 158 this->appendDecls(fFragOutputs, outputDecls);
135 } 159 }
136 160
OLDNEW
« no previous file with comments | « src/gpu/glsl/GrGLSLVarying.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698