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

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

Issue 1673093002: Use noperspective interpolation for 2D draws (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: formatting 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
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 #ifndef GrGLSLVarying_DEFINED 8 #ifndef GrGLSLVarying_DEFINED
9 #define GrGLSLVarying_DEFINED 9 #define GrGLSLVarying_DEFINED
10 10
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 GrGLSLGeoToFrag(GrSLType type) 65 GrGLSLGeoToFrag(GrSLType type)
66 : GrGLSLVarying(type, kGeoToFrag_Varying) {} 66 : GrGLSLVarying(type, kGeoToFrag_Varying) {}
67 }; 67 };
68 68
69 static const int kVaryingsPerBlock = 8; 69 static const int kVaryingsPerBlock = 8;
70 70
71 class GrGLSLVaryingHandler { 71 class GrGLSLVaryingHandler {
72 public: 72 public:
73 explicit GrGLSLVaryingHandler(GrGLSLProgramBuilder* program) 73 explicit GrGLSLVaryingHandler(GrGLSLProgramBuilder* program)
74 : fVertexInputs(kVaryingsPerBlock) 74 : fVertexInputs(kVaryingsPerBlock)
75 , fVertexOutputs(kVaryingsPerBlock) 75 , fVaryingShaderVars(kVaryingsPerBlock)
76 , fGeomInputs(kVaryingsPerBlock)
77 , fGeomOutputs(kVaryingsPerBlock)
78 , fFragInputs(kVaryingsPerBlock)
79 , fFragOutputs(kVaryingsPerBlock) 76 , fFragOutputs(kVaryingsPerBlock)
80 , fProgramBuilder(program) {} 77 , fProgramBuilder(program)
81 78 , fNoPerspective(false) {}
82 typedef GrTAllocator<GrGLSLShaderVar> VarArray; 79 /*
83 typedef GrGLSLProgramDataManager::VaryingHandle VaryingHandle; 80 * Notifies the varying handler that this shader will never emit geometry in perspective and
81 * therefore does not require perspective-correct interpolation. When suppor ted, this allows
82 * varyings to use the "noperspective" keyword, which means the GPU can use cheaper math for
83 * interpolation.
84 */
85 void setNoPerspective();
84 86
85 /* 87 /*
86 * addVarying allows fine grained control for setting up varyings between st ages. Calling this 88 * addVarying allows fine grained control for setting up varyings between st ages. Calling this
87 * functions will make sure all necessary decls are setup for the client. Th e client however is 89 * functions will make sure all necessary decls are setup for the client. Th e client however is
88 * responsible for setting up all shader code (e.g "vOut = vIn;") If you jus t need to take an 90 * responsible for setting up all shader code (e.g "vOut = vIn;") If you jus t need to take an
89 * attribute and pass it through to an output value in a fragment shader, us e 91 * attribute and pass it through to an output value in a fragment shader, us e
90 * addPassThroughAttribute. 92 * addPassThroughAttribute.
91 * TODO convert most uses of addVarying to addPassThroughAttribute 93 * TODO convert most uses of addVarying to addPassThroughAttribute
92 */ 94 */
93 void addVarying(const char* name, 95 void addVarying(const char* name,
94 GrGLSLVarying*, 96 GrGLSLVarying* varying,
95 GrSLPrecision precision = kDefault_GrSLPrecision); 97 GrSLPrecision precision = kDefault_GrSLPrecision) {
98 SkASSERT(GrSLTypeIsFloatType(varying->type())); // Integers must use add FlatVarying.
99 this->internalAddVarying(name, varying, precision, false /*flat*/);
100 }
96 101
97 /* 102 /*
98 * This call can be used by GP to pass an attribute through all shaders dire ctly to 'output' in 103 * addFlatVarying sets up a varying whose value is constant across every fra gment. The graphics
99 * the fragment shader. Though this call effects both the vertex shader and fragment shader, 104 * pipeline will pull its value from the final vertex of the draw primitive (provoking vertex).
100 * it expects 'output' to be defined in the fragment shader before this call is made. If there 105 * Flat interpolation is not always supported and the user must check the ca ps before using.
106 * TODO: Some platforms can change the provoking vertex. Should we be resett ing this knob?
107 */
108 void addFlatVarying(const char* name,
egdaniel 2016/02/10 14:23:44 instead of adding a new call here, does it make mo
Chris Dalton 2016/02/10 15:29:30 I thought this over quite a bit myself and my pref
109 GrGLSLVarying* varying,
110 GrSLPrecision precision = kDefault_GrSLPrecision) {
111 this->internalAddVarying(name, varying, precision, true /*flat*/);
112 }
113
114 /*
115 * The GP can use these calls to pass an attribute through all shaders direc tly to 'output' in
116 * the fragment shader. Though these calls affect both the vertex shader an d fragment shader,
117 * they expect 'output' to be defined in the fragment shader before the call is made. If there
101 * is a geometry shader, we will simply take the value of the varying from t he first vertex and 118 * is a geometry shader, we will simply take the value of the varying from t he first vertex and
102 * that will be set as the output varying for all emitted vertices. 119 * that will be set as the output varying for all emitted vertices.
103 * TODO it might be nicer behavior to have a flag to declare output inside t his call 120 * TODO it might be nicer behavior to have a flag to declare output inside t hese calls
104 */ 121 */
105 void addPassThroughAttribute(const GrGeometryProcessor::Attribute*, const ch ar* output); 122 void addPassThroughAttribute(const GrGeometryProcessor::Attribute*, const ch ar* output,
123 GrSLPrecision = kDefault_GrSLPrecision);
124 void addFlatPassThroughAttribute(const GrGeometryProcessor::Attribute*, cons t char* output,
125 GrSLPrecision = kDefault_GrSLPrecision);
106 126
107 void emitAttributes(const GrGeometryProcessor& gp); 127 void emitAttributes(const GrGeometryProcessor& gp);
108 128
109 void getVertexDecls(SkString* inputDecls, SkString* outputDecls) const; 129 void getVertexDecls(SkString* inputDecls, SkString* outputDecls) const;
110 void getGeomDecls(SkString* inputDecls, SkString* outputDecls) const; 130 void getGeomDecls(SkString* inputDecls, SkString* outputDecls) const;
111 void getFragDecls(SkString* inputDecls, SkString* outputDecls) const; 131 void getFragDecls(SkString* inputDecls, SkString* outputDecls) const;
132
112 protected: 133 protected:
113 VarArray fVertexInputs; 134 struct VaryingShaderVars {
114 VarArray fVertexOutputs; 135 GrGLSLShaderVar fVertexOutput;
115 VarArray fGeomInputs; 136 GrGLSLShaderVar fGeomInput;
116 VarArray fGeomOutputs; 137 GrGLSLShaderVar fGeomOutput;
117 VarArray fFragInputs; 138 GrGLSLShaderVar fFragInput;
118 VarArray fFragOutputs; 139 bool fIsFlat;
140
141 void addModifier(const char* modifier) {
142 fVertexOutput.addModifier(modifier);
143 fGeomInput.addModifier(modifier);
144 fGeomOutput.addModifier(modifier);
145 fFragInput.addModifier(modifier);
146 }
147 };
148
149 typedef GrTAllocator<GrGLSLShaderVar> ShaderVarList;
150 typedef GrTAllocator<VaryingShaderVars> VaryingShaderVarsList;
151 typedef GrGLSLProgramDataManager::VaryingHandle VaryingHandle;
152
153 ShaderVarList fVertexInputs;
154 VaryingShaderVarsList fVaryingShaderVars;
155 ShaderVarList fFragOutputs;
119 156
120 // This is not owned by the class 157 // This is not owned by the class
121 GrGLSLProgramBuilder* fProgramBuilder; 158 GrGLSLProgramBuilder* fProgramBuilder;
122 159
123 private: 160 private:
124 void addVertexVarying(const char* name, GrSLPrecision precision, GrGLSLVaryi ng* v);
125 void addGeomVarying(const char* name, GrSLPrecision precision, GrGLSLVarying * v);
126 void addFragVarying(GrSLPrecision precision, GrGLSLVarying* v);
127
128 void addAttribute(const GrShaderVar& var); 161 void addAttribute(const GrShaderVar& var);
129 162
163 void internalAddVarying(const char* name, GrGLSLVarying*, GrSLPrecision, boo l flat);
164 void writePassThroughAttribute(const GrGeometryProcessor::Attribute*, const char* output,
165 const GrGLSLVarying&);
166
130 // helper function for get*Decls 167 // helper function for get*Decls
131 void appendDecls(const VarArray& vars, SkString* out) const; 168 void appendDecls(const ShaderVarList& vars, SkString* out) const;
169
170 bool fNoPerspective;
132 171
133 friend class GrGLSLProgramBuilder; 172 friend class GrGLSLProgramBuilder;
134 }; 173 };
135 174
136 #endif 175 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698