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

Side by Side Diff: src/gpu/GrDefaultGeoProcFactory.cpp

Issue 1139723004: Preliminary attempt to remove batch tracker (Closed) Base URL: https://skia.googlesource.com/skia.git@cleanup5
Patch Set: tweaks Created 5 years, 7 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/GrDefaultGeoProcFactory.h ('k') | src/gpu/GrDefaultPathRenderer.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 "GrDefaultGeoProcFactory.h" 8 #include "GrDefaultGeoProcFactory.h"
9 9
10 #include "GrInvariantOutput.h" 10 #include "GrInvariantOutput.h"
11 #include "gl/GrGLGeometryProcessor.h" 11 #include "gl/GrGLGeometryProcessor.h"
12 #include "gl/builders/GrGLProgramBuilder.h" 12 #include "gl/builders/GrGLProgramBuilder.h"
13 13
14 /* 14 /*
15 * The default Geometry Processor simply takes position and multiplies it by the uniform view 15 * The default Geometry Processor simply takes position and multiplies it by the uniform view
16 * matrix. It also leaves coverage untouched. Behind the scenes, we may add per vertex color or 16 * matrix. It also leaves coverage untouched. Behind the scenes, we may add per vertex color or
17 * local coords. 17 * local coords.
18 */ 18 */
19 typedef GrDefaultGeoProcFactory Flag; 19 typedef GrDefaultGeoProcFactory Flag;
20 20
21 class DefaultGeoProc : public GrGeometryProcessor { 21 class DefaultGeoProc : public GrGeometryProcessor {
22 public: 22 public:
23 static GrGeometryProcessor* Create(uint32_t gpTypeFlags, 23 static GrGeometryProcessor* Create(uint32_t gpTypeFlags,
24 GrColor color, 24 GrColor color,
25 const SkMatrix& viewMatrix, 25 const SkMatrix& viewMatrix,
26 const SkMatrix& localMatrix, 26 const SkMatrix& localMatrix,
27 bool usesLocalCoords,
28 bool coverageIgnored,
27 uint8_t coverage) { 29 uint8_t coverage) {
28 return SkNEW_ARGS(DefaultGeoProc, (gpTypeFlags, 30 return SkNEW_ARGS(DefaultGeoProc, (gpTypeFlags,
29 color, 31 color,
30 viewMatrix, 32 viewMatrix,
31 localMatrix, 33 localMatrix,
32 coverage)); 34 coverage,
35 usesLocalCoords,
36 coverageIgnored));
33 } 37 }
34 38
35 const char* name() const override { return "DefaultGeometryProcessor"; } 39 const char* name() const override { return "DefaultGeometryProcessor"; }
36 40
37 const Attribute* inPosition() const { return fInPosition; } 41 const Attribute* inPosition() const { return fInPosition; }
38 const Attribute* inColor() const { return fInColor; } 42 const Attribute* inColor() const { return fInColor; }
39 const Attribute* inLocalCoords() const { return fInLocalCoords; } 43 const Attribute* inLocalCoords() const { return fInLocalCoords; }
40 const Attribute* inCoverage() const { return fInCoverage; } 44 const Attribute* inCoverage() const { return fInCoverage; }
41 GrColor color() const { return fColor; } 45 GrColor color() const { return fColor; }
46 bool colorIgnored() const { return GrColor_ILLEGAL == fColor; }
47 bool hasVertexColor() const { return SkToBool(fInColor); }
42 const SkMatrix& viewMatrix() const { return fViewMatrix; } 48 const SkMatrix& viewMatrix() const { return fViewMatrix; }
43 const SkMatrix& localMatrix() const { return fLocalMatrix; } 49 const SkMatrix& localMatrix() const { return fLocalMatrix; }
50 bool usesLocalCoords() const { return fUsesLocalCoords; }
44 uint8_t coverage() const { return fCoverage; } 51 uint8_t coverage() const { return fCoverage; }
45 52 bool coverageIgnored() const { return fCoverageIgnored; }
46 void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const override { 53 bool hasVertexCoverage() const { return SkToBool(fInCoverage); }
47 BatchTracker* local = bt->cast<BatchTracker>();
48 local->fInputColorType = GetColorInputType(&local->fColor, this->color() , init,
49 SkToBool(fInColor));
50
51 bool hasVertexCoverage = SkToBool(fInCoverage) && !init.fCoverageIgnored ;
52 bool covIsSolidWhite = !hasVertexCoverage && 0xff == this->coverage();
53 if (init.fCoverageIgnored) {
54 local->fInputCoverageType = kIgnored_GrGPInput;
55 } else if (covIsSolidWhite) {
56 local->fInputCoverageType = kAllOnes_GrGPInput;
57 } else if (hasVertexCoverage) {
58 SkASSERT(fInCoverage);
59 local->fInputCoverageType = kAttribute_GrGPInput;
60 } else {
61 local->fInputCoverageType = kUniform_GrGPInput;
62 local->fCoverage = this->coverage();
63 }
64 local->fUsesLocalCoords = init.fUsesLocalCoords;
65 }
66 54
67 class GLProcessor : public GrGLGeometryProcessor { 55 class GLProcessor : public GrGLGeometryProcessor {
68 public: 56 public:
69 GLProcessor(const GrGeometryProcessor& gp, const GrBatchTracker&) 57 GLProcessor(const GrGeometryProcessor& gp, const GrBatchTracker&)
70 : fColor(GrColor_ILLEGAL), fCoverage(0xff) {} 58 : fColor(GrColor_ILLEGAL), fCoverage(0xff) {}
71 59
72 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { 60 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
73 const DefaultGeoProc& gp = args.fGP.cast<DefaultGeoProc>(); 61 const DefaultGeoProc& gp = args.fGP.cast<DefaultGeoProc>();
74 GrGLGPBuilder* pb = args.fPB; 62 GrGLGPBuilder* pb = args.fPB;
75 GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder(); 63 GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder();
76 GrGLFragmentBuilder* fs = args.fPB->getFragmentShaderBuilder(); 64 GrGLFragmentBuilder* fs = args.fPB->getFragmentShaderBuilder();
77 const BatchTracker& local = args.fBT.cast<BatchTracker>();
78 65
79 // emit attributes 66 // emit attributes
80 vsBuilder->emitAttributes(gp); 67 vsBuilder->emitAttributes(gp);
81 68
82 // Setup pass through color 69 // Setup pass through color
83 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputC olor, gp.inColor(), 70 if (!gp.colorIgnored()) {
84 &fColorUniform); 71 if (gp.hasVertexColor()) {
72 pb->addPassThroughAttribute(gp.inColor(), args.fOutputColor) ;
73 } else {
74 this->setupUniformColor(pb, args.fOutputColor, &fColorUnifor m);
75 }
76 }
77
85 // Setup position 78 // Setup position
86 this->setupPosition(pb, gpArgs, gp.inPosition()->fName, gp.viewMatri x()); 79 this->setupPosition(pb, gpArgs, gp.inPosition()->fName, gp.viewMatri x());
87 80
88 if (gp.inLocalCoords()) { 81 if (gp.inLocalCoords()) {
89 // emit transforms with explicit local coords 82 // emit transforms with explicit local coords
90 this->emitTransforms(pb, gpArgs->fPositionVar, gp.inLocalCoords( )->fName, 83 this->emitTransforms(pb, gpArgs->fPositionVar, gp.inLocalCoords( )->fName,
91 gp.localMatrix(), args.fTransformsIn, args. fTransformsOut); 84 gp.localMatrix(), args.fTransformsIn, args. fTransformsOut);
92 } else { 85 } else {
93 // emit transforms with position 86 // emit transforms with position
94 this->emitTransforms(pb, gpArgs->fPositionVar, gp.inPosition()-> fName, 87 this->emitTransforms(pb, gpArgs->fPositionVar, gp.inPosition()-> fName,
95 gp.localMatrix(), args.fTransformsIn, args. fTransformsOut); 88 gp.localMatrix(), args.fTransformsIn, args. fTransformsOut);
96 } 89 }
97 90
98 // Setup coverage as pass through 91 // Setup coverage as pass through
99 if (kUniform_GrGPInput == local.fInputCoverageType) { 92 if (!gp.coverageIgnored()) {
100 const char* fragCoverage; 93 if (gp.hasVertexCoverage()) {
101 fCoverageUniform = pb->addUniform(GrGLProgramBuilder::kFragment_ Visibility, 94 fs->codeAppendf("float alpha = 1.0;");
102 kFloat_GrSLType, 95 args.fPB->addPassThroughAttribute(gp.inCoverage(), "alpha");
103 kDefault_GrSLPrecision, 96 fs->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage);
104 "Coverage", 97 } else if (gp.coverage() == 0xff) {
105 &fragCoverage); 98 fs->codeAppendf("%s = vec4(1);", args.fOutputCoverage);
106 fs->codeAppendf("%s = vec4(%s);", args.fOutputCoverage, fragCove rage); 99 } else {
107 } else if (kAttribute_GrGPInput == local.fInputCoverageType) { 100 const char* fragCoverage;
108 SkASSERT(gp.inCoverage()); 101 fCoverageUniform = pb->addUniform(GrGLProgramBuilder::kFragm ent_Visibility,
109 fs->codeAppendf("float alpha = 1.0;"); 102 kFloat_GrSLType,
110 args.fPB->addPassThroughAttribute(gp.inCoverage(), "alpha"); 103 kDefault_GrSLPrecision,
111 fs->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); 104 "Coverage",
112 } else if (kAllOnes_GrGPInput == local.fInputCoverageType) { 105 &fragCoverage);
113 fs->codeAppendf("%s = vec4(1);", args.fOutputCoverage); 106 fs->codeAppendf("%s = vec4(%s);", args.fOutputCoverage, frag Coverage);
107 }
114 } 108 }
115 } 109 }
116 110
117 static inline void GenKey(const GrGeometryProcessor& gp, 111 static inline void GenKey(const GrGeometryProcessor& gp,
118 const GrBatchTracker& bt, 112 const GrBatchTracker& bt,
119 const GrGLSLCaps&, 113 const GrGLSLCaps&,
120 GrProcessorKeyBuilder* b) { 114 GrProcessorKeyBuilder* b) {
121 const DefaultGeoProc& def = gp.cast<DefaultGeoProc>(); 115 const DefaultGeoProc& def = gp.cast<DefaultGeoProc>();
122 const BatchTracker& local = bt.cast<BatchTracker>();
123 uint32_t key = def.fFlags; 116 uint32_t key = def.fFlags;
124 key |= local.fInputColorType << 8 | local.fInputCoverageType << 16; 117 key |= def.colorIgnored() << 8;
125 key |= local.fUsesLocalCoords && def.localMatrix().hasPerspective() ? 0x1 << 24 : 0x0; 118 key |= def.coverageIgnored() << 9;
119 key |= def.hasVertexColor() << 10;
120 key |= def.hasVertexCoverage() << 11;
121 key |= def.coverage() == 0xff ? 0x1 << 12 : 0;
122 key |= def.usesLocalCoords() && def.localMatrix().hasPerspective() ? 0x1 << 24 : 0x0;
126 key |= ComputePosKey(def.viewMatrix()) << 25; 123 key |= ComputePosKey(def.viewMatrix()) << 25;
127 b->add32(key); 124 b->add32(key);
128 } 125 }
129 126
130 virtual void setData(const GrGLProgramDataManager& pdman, 127 virtual void setData(const GrGLProgramDataManager& pdman,
131 const GrPrimitiveProcessor& gp, 128 const GrPrimitiveProcessor& gp,
132 const GrBatchTracker& bt) override { 129 const GrBatchTracker& bt) override {
133 const DefaultGeoProc& dgp = gp.cast<DefaultGeoProc>(); 130 const DefaultGeoProc& dgp = gp.cast<DefaultGeoProc>();
134 this->setUniformViewMatrix(pdman, dgp.viewMatrix()); 131 this->setUniformViewMatrix(pdman, dgp.viewMatrix());
135 132
136 const BatchTracker& local = bt.cast<BatchTracker>(); 133 if (dgp.color() != fColor && !dgp.hasVertexColor()) {
137 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != f Color) {
138 GrGLfloat c[4]; 134 GrGLfloat c[4];
139 GrColorToRGBAFloat(local.fColor, c); 135 GrColorToRGBAFloat(dgp.color(), c);
140 pdman.set4fv(fColorUniform, 1, c); 136 pdman.set4fv(fColorUniform, 1, c);
141 fColor = local.fColor; 137 fColor = dgp.color();
142 } 138 }
143 if (kUniform_GrGPInput == local.fInputCoverageType && local.fCoverag e != fCoverage) { 139
144 pdman.set1f(fCoverageUniform, GrNormalizeByteToFloat(local.fCove rage)); 140 if (!dgp.coverageIgnored() && dgp.coverage() != fCoverage && !dgp.ha sVertexCoverage()) {
145 fCoverage = local.fCoverage; 141 pdman.set1f(fCoverageUniform, GrNormalizeByteToFloat(dgp.coverag e()));
142 fCoverage = dgp.coverage();
146 } 143 }
147 } 144 }
148 145
149 void setTransformData(const GrPrimitiveProcessor& primProc, 146 void setTransformData(const GrPrimitiveProcessor& primProc,
150 const GrGLProgramDataManager& pdman, 147 const GrGLProgramDataManager& pdman,
151 int index, 148 int index,
152 const SkTArray<const GrCoordTransform*, true>& tra nsforms) override { 149 const SkTArray<const GrCoordTransform*, true>& tra nsforms) override {
153 this->setTransformDataHelper<DefaultGeoProc>(primProc, pdman, index, transforms); 150 this->setTransformDataHelper<DefaultGeoProc>(primProc, pdman, index, transforms);
154 } 151 }
155 152
(...skipping 15 matching lines...) Expand all
171 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, 168 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt,
172 const GrGLSLCaps&) const ov erride { 169 const GrGLSLCaps&) const ov erride {
173 return SkNEW_ARGS(GLProcessor, (*this, bt)); 170 return SkNEW_ARGS(GLProcessor, (*this, bt));
174 } 171 }
175 172
176 private: 173 private:
177 DefaultGeoProc(uint32_t gpTypeFlags, 174 DefaultGeoProc(uint32_t gpTypeFlags,
178 GrColor color, 175 GrColor color,
179 const SkMatrix& viewMatrix, 176 const SkMatrix& viewMatrix,
180 const SkMatrix& localMatrix, 177 const SkMatrix& localMatrix,
181 uint8_t coverage) 178 uint8_t coverage,
179 bool usesLocalCoords,
180 bool coverageIgnored)
182 : fInPosition(NULL) 181 : fInPosition(NULL)
183 , fInColor(NULL) 182 , fInColor(NULL)
184 , fInLocalCoords(NULL) 183 , fInLocalCoords(NULL)
185 , fInCoverage(NULL) 184 , fInCoverage(NULL)
186 , fColor(color) 185 , fColor(color)
187 , fViewMatrix(viewMatrix) 186 , fViewMatrix(viewMatrix)
188 , fLocalMatrix(localMatrix) 187 , fLocalMatrix(localMatrix)
189 , fCoverage(coverage) 188 , fCoverage(coverage)
190 , fFlags(gpTypeFlags) { 189 , fFlags(gpTypeFlags)
190 , fUsesLocalCoords(usesLocalCoords)
191 , fCoverageIgnored(coverageIgnored) {
191 this->initClassID<DefaultGeoProc>(); 192 this->initClassID<DefaultGeoProc>();
192 bool hasColor = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kColor_G PType); 193 bool hasColor = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kColor_G PType);
193 bool hasLocalCoord = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kLo calCoord_GPType); 194 bool hasLocalCoord = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kLo calCoord_GPType);
194 bool hasCoverage = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kCove rage_GPType); 195 bool hasCoverage = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kCove rage_GPType);
195 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe rtexAttribType)); 196 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe rtexAttribType));
196 if (hasColor) { 197 if (hasColor) {
197 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVer texAttribType)); 198 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVer texAttribType));
198 } 199 }
199 if (hasLocalCoord) { 200 if (hasLocalCoord) {
200 fInLocalCoords = &this->addVertexAttrib(Attribute("inLocalCoord", 201 fInLocalCoords = &this->addVertexAttrib(Attribute("inLocalCoord",
201 kVec2f_GrVertexA ttribType)); 202 kVec2f_GrVertexAtt ribType));
202 this->setHasLocalCoords(); 203 this->setHasLocalCoords();
203 } 204 }
204 if (hasCoverage) { 205 if (hasCoverage) {
205 fInCoverage = &this->addVertexAttrib(Attribute("inCoverage", 206 fInCoverage = &this->addVertexAttrib(Attribute("inCoverage",
206 kFloat_GrVertexAttr ibType)); 207 kFloat_GrVertexAttr ibType));
207 } 208 }
208 } 209 }
209 210
210 struct BatchTracker {
211 GrGPInput fInputColorType;
212 GrGPInput fInputCoverageType;
213 GrColor fColor;
214 GrColor fCoverage;
215 bool fUsesLocalCoords;
216 };
217
218 const Attribute* fInPosition; 211 const Attribute* fInPosition;
219 const Attribute* fInColor; 212 const Attribute* fInColor;
220 const Attribute* fInLocalCoords; 213 const Attribute* fInLocalCoords;
221 const Attribute* fInCoverage; 214 const Attribute* fInCoverage;
222 GrColor fColor; 215 GrColor fColor;
223 SkMatrix fViewMatrix; 216 SkMatrix fViewMatrix;
224 SkMatrix fLocalMatrix; 217 SkMatrix fLocalMatrix;
225 uint8_t fCoverage; 218 uint8_t fCoverage;
226 uint32_t fFlags; 219 uint32_t fFlags;
220 bool fUsesLocalCoords;
221 bool fCoverageIgnored;
227 222
228 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; 223 GR_DECLARE_GEOMETRY_PROCESSOR_TEST;
229 224
230 typedef GrGeometryProcessor INHERITED; 225 typedef GrGeometryProcessor INHERITED;
231 }; 226 };
232 227
233 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DefaultGeoProc); 228 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DefaultGeoProc);
234 229
235 GrGeometryProcessor* DefaultGeoProc::TestCreate(SkRandom* random, 230 GrGeometryProcessor* DefaultGeoProc::TestCreate(SkRandom* random,
236 GrContext*, 231 GrContext*,
237 const GrDrawTargetCaps& caps, 232 const GrDrawTargetCaps& caps,
238 GrTexture*[]) { 233 GrTexture*[]) {
239 uint32_t flags = 0; 234 uint32_t flags = 0;
240 if (random->nextBool()) { 235 if (random->nextBool()) {
241 flags |= GrDefaultGeoProcFactory::kColor_GPType; 236 flags |= GrDefaultGeoProcFactory::kColor_GPType;
242 } 237 }
243 if (random->nextBool()) { 238 if (random->nextBool()) {
244 flags |= GrDefaultGeoProcFactory::kCoverage_GPType; 239 flags |= GrDefaultGeoProcFactory::kCoverage_GPType;
245 } 240 }
246 if (random->nextBool()) { 241 if (random->nextBool()) {
247 flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType; 242 flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType;
248 } 243 }
249 244
250 return DefaultGeoProc::Create(flags, 245 return DefaultGeoProc::Create(flags,
251 GrRandomColor(random), 246 GrRandomColor(random),
252 GrTest::TestMatrix(random), 247 GrTest::TestMatrix(random),
253 GrTest::TestMatrix(random), 248 GrTest::TestMatrix(random),
249 random->nextBool(),
250 random->nextBool(),
254 GrRandomCoverage(random)); 251 GrRandomCoverage(random));
255 } 252 }
256 253
257 const GrGeometryProcessor* GrDefaultGeoProcFactory::Create(uint32_t gpTypeFlags, 254 const GrGeometryProcessor* GrDefaultGeoProcFactory::Create(uint32_t gpTypeFlags,
258 GrColor color, 255 GrColor color,
256 bool usesLocalCoords,
257 bool coverageIgnored,
259 const SkMatrix& viewM atrix, 258 const SkMatrix& viewM atrix,
260 const SkMatrix& local Matrix, 259 const SkMatrix& local Matrix,
261 uint8_t coverage) { 260 uint8_t coverage) {
262 return DefaultGeoProc::Create(gpTypeFlags, 261 return DefaultGeoProc::Create(gpTypeFlags,
263 color, 262 color,
264 viewMatrix, 263 viewMatrix,
265 localMatrix, 264 localMatrix,
265 usesLocalCoords,
266 coverageIgnored,
266 coverage); 267 coverage);
267 } 268 }
OLDNEW
« no previous file with comments | « src/gpu/GrDefaultGeoProcFactory.h ('k') | src/gpu/GrDefaultPathRenderer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698