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

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

Issue 777673003: move program descriptor generation to flush (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: more cleanup Created 6 years 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 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 "GrOptDrawState.h" 8 #include "GrOptDrawState.h"
9 9
10 #include "GrDrawState.h" 10 #include "GrDrawState.h"
11 #include "GrDrawTargetCaps.h" 11 #include "GrDrawTargetCaps.h"
12 #include "GrGpu.h" 12 #include "GrGpu.h"
13 #include "GrProcOptInfo.h" 13 #include "GrProcOptInfo.h"
14 14
15 GrOptDrawState::GrOptDrawState(const GrDrawState& drawState, 15 GrOptDrawState::GrOptDrawState(const GrDrawState& drawState,
16 GrGpu* gpu, 16 const GrDrawTargetCaps& caps,
17 const ScissorState& scissorState, 17 const ScissorState& scissorState,
18 const GrDeviceCoordTexture* dstCopy, 18 const GrDeviceCoordTexture* dstCopy,
19 GrGpu::DrawType drawType) { 19 GrGpu::DrawType drawType) {
20 20
21 GrBlendCoeff optSrcCoeff; 21 GrBlendCoeff optSrcCoeff;
22 GrBlendCoeff optDstCoeff; 22 GrBlendCoeff optDstCoeff;
23 GrDrawState::BlendOpt blendOpt = drawState.getBlendOpt(false, &optSrcCoeff, &optDstCoeff); 23 GrDrawState::BlendOpt blendOpt = drawState.getBlendOpt(false, &optSrcCoeff, &optDstCoeff);
24 24
25 // When path rendering the stencil settings are not always set on the draw s tate 25 // When path rendering the stencil settings are not always set on the draw s tate
26 // so we must check the draw type. In cases where we will skip drawing we si mply return a 26 // so we must check the draw type. In cases where we will skip drawing we si mply return a
(...skipping 18 matching lines...) Expand all
45 fStencilSettings = drawState.getStencil(); 45 fStencilSettings = drawState.getStencil();
46 fDrawFace = drawState.getDrawFace(); 46 fDrawFace = drawState.getDrawFace();
47 fSrcBlend = optSrcCoeff; 47 fSrcBlend = optSrcCoeff;
48 fDstBlend = optDstCoeff; 48 fDstBlend = optDstCoeff;
49 49
50 // TODO move this out of optDrawState 50 // TODO move this out of optDrawState
51 if (dstCopy) { 51 if (dstCopy) {
52 fDstCopy = *dstCopy; 52 fDstCopy = *dstCopy;
53 } 53 }
54 54
55 GrProgramDesc::DescInfo descInfo;
56
57 fFlags = 0; 55 fFlags = 0;
58 if (drawState.isHWAntialias()) { 56 if (drawState.isHWAntialias()) {
59 fFlags |= kHWAA_Flag; 57 fFlags |= kHWAA_Flag;
60 } 58 }
61 if (drawState.isColorWriteDisabled()) { 59 if (drawState.isColorWriteDisabled()) {
62 fFlags |= kDisableColorWrite_Flag; 60 fFlags |= kDisableColorWrite_Flag;
63 } 61 }
64 if (drawState.isDither()) { 62 if (drawState.isDither()) {
65 fFlags |= kDither_Flag; 63 fFlags |= kDither_Flag;
66 } 64 }
67 65
68 descInfo.fHasVertexColor = drawState.hasGeometryProcessor() && 66 fDescInfo.fHasVertexColor = drawState.hasGeometryProcessor() &&
69 drawState.getGeometryProcessor()->hasVertexColor( ); 67 drawState.getGeometryProcessor()->hasVertexColor ();
70 68
71 descInfo.fHasVertexCoverage = drawState.hasGeometryProcessor() && 69 fDescInfo.fHasVertexCoverage = drawState.hasGeometryProcessor() &&
72 drawState.getGeometryProcessor()->hasVertexCove rage(); 70 drawState.getGeometryProcessor()->hasVertexCo verage();
73 71
74 bool hasLocalCoords = drawState.hasGeometryProcessor() && 72 bool hasLocalCoords = drawState.hasGeometryProcessor() &&
75 drawState.getGeometryProcessor()->hasLocalCoords(); 73 drawState.getGeometryProcessor()->hasLocalCoords();
76 74
77 const GrProcOptInfo& colorPOI = drawState.colorProcInfo(); 75 const GrProcOptInfo& colorPOI = drawState.colorProcInfo();
78 int firstColorStageIdx = colorPOI.firstEffectiveStageIndex(); 76 int firstColorStageIdx = colorPOI.firstEffectiveStageIndex();
79 descInfo.fInputColorIsUsed = colorPOI.inputColorIsUsed(); 77 fDescInfo.fInputColorIsUsed = colorPOI.inputColorIsUsed();
80 fColor = colorPOI.inputColorToEffectiveStage(); 78 fColor = colorPOI.inputColorToEffectiveStage();
81 if (colorPOI.removeVertexAttrib()) { 79 if (colorPOI.removeVertexAttrib()) {
82 descInfo.fHasVertexColor = false; 80 fDescInfo.fHasVertexColor = false;
83 } 81 }
84 82
85 // TODO: Once we can handle single or four channel input into coverage stage s then we can use 83 // TODO: Once we can handle single or four channel input into coverage stage s then we can use
86 // drawState's coverageProcInfo (like color above) to set this initial infor mation. 84 // drawState's coverageProcInfo (like color above) to set this initial infor mation.
87 int firstCoverageStageIdx = 0; 85 int firstCoverageStageIdx = 0;
88 descInfo.fInputCoverageIsUsed = true; 86 fDescInfo.fInputCoverageIsUsed = true;
89 fCoverage = drawState.getCoverage(); 87 fCoverage = drawState.getCoverage();
90 88
91 this->adjustProgramForBlendOpt(drawState, blendOpt, &descInfo, &firstColorSt ageIdx, 89 this->adjustProgramForBlendOpt(drawState, blendOpt, &firstColorStageIdx,
92 &firstCoverageStageIdx); 90 &firstCoverageStageIdx);
93 91
94 this->getStageStats(drawState, firstColorStageIdx, firstCoverageStageIdx, ha sLocalCoords, 92 this->getStageStats(drawState, firstColorStageIdx, firstCoverageStageIdx, ha sLocalCoords);
95 &descInfo);
96 93
97 // Copy GeometryProcesssor from DS or ODS 94 // Copy GeometryProcesssor from DS or ODS
98 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType) || 95 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType) ||
99 GrGpu::kStencilPath_DrawType || 96 GrGpu::kStencilPath_DrawType ||
100 drawState.hasGeometryProcessor()); 97 drawState.hasGeometryProcessor());
101 fGeometryProcessor.reset(drawState.getGeometryProcessor()); 98 fGeometryProcessor.reset(drawState.getGeometryProcessor());
102 99
103 // Copy Stages from DS to ODS 100 // Copy Stages from DS to ODS
104 for (int i = firstColorStageIdx; i < drawState.numColorStages(); ++i) { 101 for (int i = firstColorStageIdx; i < drawState.numColorStages(); ++i) {
105 SkNEW_APPEND_TO_TARRAY(&fFragmentStages, 102 SkNEW_APPEND_TO_TARRAY(&fFragmentStages,
106 GrPendingFragmentStage, 103 GrPendingFragmentStage,
107 (drawState.fColorStages[i], hasLocalCoords)); 104 (drawState.fColorStages[i], hasLocalCoords));
108 } 105 }
109 fNumColorStages = fFragmentStages.count(); 106 fNumColorStages = fFragmentStages.count();
110 for (int i = firstCoverageStageIdx; i < drawState.numCoverageStages(); ++i) { 107 for (int i = firstCoverageStageIdx; i < drawState.numCoverageStages(); ++i) {
111 SkNEW_APPEND_TO_TARRAY(&fFragmentStages, 108 SkNEW_APPEND_TO_TARRAY(&fFragmentStages,
112 GrPendingFragmentStage, 109 GrPendingFragmentStage,
113 (drawState.fCoverageStages[i], hasLocalCoords)); 110 (drawState.fCoverageStages[i], hasLocalCoords));
114 } 111 }
115 112
116 this->setOutputStateInfo(drawState, blendOpt, *gpu->caps(), &descInfo); 113 this->setOutputStateInfo(drawState, blendOpt, caps);
117
118 // now create a key
119 gpu->buildProgramDesc(*this, descInfo, drawType, &fDesc);
120 }; 114 };
121 115
122 void GrOptDrawState::setOutputStateInfo(const GrDrawState& ds, 116 void GrOptDrawState::setOutputStateInfo(const GrDrawState& ds,
123 GrDrawState::BlendOpt blendOpt, 117 GrDrawState::BlendOpt blendOpt,
124 const GrDrawTargetCaps& caps, 118 const GrDrawTargetCaps& caps) {
125 GrProgramDesc::DescInfo* descInfo) {
126 // Set this default and then possibly change our mind if there is coverage. 119 // Set this default and then possibly change our mind if there is coverage.
127 descInfo->fPrimaryOutputType = GrProgramDesc::kModulate_PrimaryOutputType; 120 fDescInfo.fPrimaryOutputType = GrProgramDesc::kModulate_PrimaryOutputType;
128 descInfo->fSecondaryOutputType = GrProgramDesc::kNone_SecondaryOutputType; 121 fDescInfo.fSecondaryOutputType = GrProgramDesc::kNone_SecondaryOutputType;
129 122
130 // Determine whether we should use dual source blending or shader code to ke ep coverage 123 // Determine whether we should use dual source blending or shader code to ke ep coverage
131 // separate from color. 124 // separate from color.
132 bool keepCoverageSeparate = !(GrDrawState::kCoverageAsAlpha_BlendOpt == blen dOpt || 125 bool keepCoverageSeparate = !(GrDrawState::kCoverageAsAlpha_BlendOpt == blen dOpt ||
133 GrDrawState::kEmitCoverage_BlendOpt == blendOp t); 126 GrDrawState::kEmitCoverage_BlendOpt == blendOp t);
134 if (keepCoverageSeparate && !ds.hasSolidCoverage()) { 127 if (keepCoverageSeparate && !ds.hasSolidCoverage()) {
135 if (caps.dualSourceBlendingSupport()) { 128 if (caps.dualSourceBlendingSupport()) {
136 if (kZero_GrBlendCoeff == fDstBlend) { 129 if (kZero_GrBlendCoeff == fDstBlend) {
137 // write the coverage value to second color 130 // write the coverage value to second color
138 descInfo->fSecondaryOutputType = GrProgramDesc::kCoverage_Second aryOutputType; 131 fDescInfo.fSecondaryOutputType = GrProgramDesc::kCoverage_Second aryOutputType;
139 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; 132 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff;
140 } else if (kSA_GrBlendCoeff == fDstBlend) { 133 } else if (kSA_GrBlendCoeff == fDstBlend) {
141 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered. 134 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered.
142 descInfo->fSecondaryOutputType = GrProgramDesc::kCoverageISA_Sec ondaryOutputType; 135 fDescInfo.fSecondaryOutputType = GrProgramDesc::kCoverageISA_Sec ondaryOutputType;
143 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; 136 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff;
144 } else if (kSC_GrBlendCoeff == fDstBlend) { 137 } else if (kSC_GrBlendCoeff == fDstBlend) {
145 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered. 138 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered.
146 descInfo->fSecondaryOutputType = GrProgramDesc::kCoverageISC_Sec ondaryOutputType; 139 fDescInfo.fSecondaryOutputType = GrProgramDesc::kCoverageISC_Sec ondaryOutputType;
147 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; 140 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff;
148 } 141 }
149 } else if (descInfo->fReadsDst && 142 } else if (fDescInfo.fReadsDst &&
150 kOne_GrBlendCoeff == fSrcBlend && 143 kOne_GrBlendCoeff == fSrcBlend &&
151 kZero_GrBlendCoeff == fDstBlend) { 144 kZero_GrBlendCoeff == fDstBlend) {
152 descInfo->fPrimaryOutputType = GrProgramDesc::kCombineWithDst_Primar yOutputType; 145 fDescInfo.fPrimaryOutputType = GrProgramDesc::kCombineWithDst_Primar yOutputType;
153 } 146 }
154 } 147 }
155 } 148 }
156 149
157 void GrOptDrawState::adjustProgramForBlendOpt(const GrDrawState& ds, 150 void GrOptDrawState::adjustProgramForBlendOpt(const GrDrawState& ds,
158 GrDrawState::BlendOpt blendOpt, 151 GrDrawState::BlendOpt blendOpt,
159 GrProgramDesc::DescInfo* descInfo,
160 int* firstColorStageIdx, 152 int* firstColorStageIdx,
161 int* firstCoverageStageIdx) { 153 int* firstCoverageStageIdx) {
162 switch (blendOpt) { 154 switch (blendOpt) {
163 case GrDrawState::kNone_BlendOpt: 155 case GrDrawState::kNone_BlendOpt:
164 case GrDrawState::kSkipDraw_BlendOpt: 156 case GrDrawState::kSkipDraw_BlendOpt:
165 case GrDrawState::kCoverageAsAlpha_BlendOpt: 157 case GrDrawState::kCoverageAsAlpha_BlendOpt:
166 break; 158 break;
167 case GrDrawState::kEmitCoverage_BlendOpt: 159 case GrDrawState::kEmitCoverage_BlendOpt:
168 fColor = 0xffffffff; 160 fColor = 0xffffffff;
169 descInfo->fInputColorIsUsed = true; 161 fDescInfo.fInputColorIsUsed = true;
170 *firstColorStageIdx = ds.numColorStages(); 162 *firstColorStageIdx = ds.numColorStages();
171 descInfo->fHasVertexColor = false; 163 fDescInfo.fHasVertexColor = false;
172 break; 164 break;
173 case GrDrawState::kEmitTransBlack_BlendOpt: 165 case GrDrawState::kEmitTransBlack_BlendOpt:
174 fColor = 0; 166 fColor = 0;
175 fCoverage = 0xff; 167 fCoverage = 0xff;
176 descInfo->fInputColorIsUsed = true; 168 fDescInfo.fInputColorIsUsed = true;
177 descInfo->fInputCoverageIsUsed = true; 169 fDescInfo.fInputCoverageIsUsed = true;
178 *firstColorStageIdx = ds.numColorStages(); 170 *firstColorStageIdx = ds.numColorStages();
179 *firstCoverageStageIdx = ds.numCoverageStages(); 171 *firstCoverageStageIdx = ds.numCoverageStages();
180 descInfo->fHasVertexColor = false; 172 fDescInfo.fHasVertexColor = false;
181 descInfo->fHasVertexCoverage = false; 173 fDescInfo.fHasVertexCoverage = false;
182 break; 174 break;
183 } 175 }
184 } 176 }
185 177
186 static void get_stage_stats(const GrFragmentStage& stage, bool* readsDst, bool* readsFragPosition) { 178 static void get_stage_stats(const GrFragmentStage& stage, bool* readsDst, bool* readsFragPosition) {
187 if (stage.getProcessor()->willReadDstColor()) { 179 if (stage.getProcessor()->willReadDstColor()) {
188 *readsDst = true; 180 *readsDst = true;
189 } 181 }
190 if (stage.getProcessor()->willReadFragmentPosition()) { 182 if (stage.getProcessor()->willReadFragmentPosition()) {
191 *readsFragPosition = true; 183 *readsFragPosition = true;
192 } 184 }
193 } 185 }
194 186
195 void GrOptDrawState::getStageStats(const GrDrawState& ds, int firstColorStageIdx , 187 void GrOptDrawState::getStageStats(const GrDrawState& ds, int firstColorStageIdx ,
196 int firstCoverageStageIdx, bool hasLocalCoord s, 188 int firstCoverageStageIdx, bool hasLocalCoord s) {
197 GrProgramDesc::DescInfo* descInfo) {
198 // We will need a local coord attrib if there is one currently set on the op tState and we are 189 // We will need a local coord attrib if there is one currently set on the op tState and we are
199 // actually generating some effect code 190 // actually generating some effect code
200 descInfo->fRequiresLocalCoordAttrib = hasLocalCoords && 191 fDescInfo.fRequiresLocalCoordAttrib = hasLocalCoords &&
201 ds.numTotalStages() - firstColorStageIdx - firstCoverageStageIdx > 0; 192 ds.numTotalStages() - firstColorStageIdx - firstCoverageStageIdx > 0;
202 193
203 descInfo->fReadsDst = false; 194 fDescInfo.fReadsDst = false;
204 descInfo->fReadsFragPosition = false; 195 fDescInfo.fReadsFragPosition = false;
205 196
206 for (int s = firstColorStageIdx; s < ds.numColorStages(); ++s) { 197 for (int s = firstColorStageIdx; s < ds.numColorStages(); ++s) {
207 const GrFragmentStage& stage = ds.getColorStage(s); 198 const GrFragmentStage& stage = ds.getColorStage(s);
208 get_stage_stats(stage, &descInfo->fReadsDst, &descInfo->fReadsFragPositi on); 199 get_stage_stats(stage, &fDescInfo.fReadsDst, &fDescInfo.fReadsFragPositi on);
209 } 200 }
210 for (int s = firstCoverageStageIdx; s < ds.numCoverageStages(); ++s) { 201 for (int s = firstCoverageStageIdx; s < ds.numCoverageStages(); ++s) {
211 const GrFragmentStage& stage = ds.getCoverageStage(s); 202 const GrFragmentStage& stage = ds.getCoverageStage(s);
212 get_stage_stats(stage, &descInfo->fReadsDst, &descInfo->fReadsFragPositi on); 203 get_stage_stats(stage, &fDescInfo.fReadsDst, &fDescInfo.fReadsFragPositi on);
213 } 204 }
214 if (ds.hasGeometryProcessor()) { 205 if (ds.hasGeometryProcessor()) {
215 const GrGeometryProcessor& gp = *ds.getGeometryProcessor(); 206 const GrGeometryProcessor& gp = *ds.getGeometryProcessor();
216 descInfo->fReadsFragPosition = descInfo->fReadsFragPosition || gp.willRe adFragmentPosition(); 207 fDescInfo.fReadsFragPosition = fDescInfo.fReadsFragPosition || gp.willRe adFragmentPosition();
217 } 208 }
218 } 209 }
219 210
220 //////////////////////////////////////////////////////////////////////////////// 211 ////////////////////////////////////////////////////////////////////////////////
221 212
222 bool GrOptDrawState::operator== (const GrOptDrawState& that) const { 213 bool GrOptDrawState::operator== (const GrOptDrawState& that) const {
223 if (this->fDesc != that.fDesc) { 214 if (!fDescInfo.fHasVertexColor && this->fColor != that.fColor) {
224 return false;
225 }
226 bool hasVertexColors = this->fDesc.header().fColorInput == GrProgramDesc::kA ttribute_ColorInput;
227 if (!hasVertexColors && this->fColor != that.fColor) {
228 return false; 215 return false;
229 } 216 }
230 217
231 if (this->getRenderTarget() != that.getRenderTarget() || 218 if (this->getRenderTarget() != that.getRenderTarget() ||
232 this->fScissorState != that.fScissorState || 219 this->fFragmentStages.count() != that.fFragmentStages.count() ||
220 this->fNumColorStages != that.fNumColorStages ||
233 !this->fViewMatrix.cheapEqualTo(that.fViewMatrix) || 221 !this->fViewMatrix.cheapEqualTo(that.fViewMatrix) ||
234 this->fSrcBlend != that.fSrcBlend || 222 this->fSrcBlend != that.fSrcBlend ||
235 this->fDstBlend != that.fDstBlend || 223 this->fDstBlend != that.fDstBlend ||
236 this->fBlendConstant != that.fBlendConstant || 224 this->fBlendConstant != that.fBlendConstant ||
237 this->fFlags != that.fFlags || 225 this->fFlags != that.fFlags ||
238 this->fStencilSettings != that.fStencilSettings || 226 this->fStencilSettings != that.fStencilSettings ||
239 this->fDrawFace != that.fDrawFace || 227 this->fDrawFace != that.fDrawFace ||
228 fDescInfo.fInputColorIsUsed != that.fDescInfo.fInputColorIsUsed ||
229 fDescInfo.fInputCoverageIsUsed != that.fDescInfo.fInputCoverageIsUsed ||
230 fDescInfo.fReadsDst != that.fDescInfo.fReadsDst ||
231 fDescInfo.fReadsFragPosition != that.fDescInfo.fReadsFragPosition ||
232 fDescInfo.fRequiresLocalCoordAttrib != that.fDescInfo.fRequiresLocalCoor dAttrib ||
233 fDescInfo.fPrimaryOutputType != that.fDescInfo.fPrimaryOutputType ||
234 fDescInfo.fSecondaryOutputType != that.fDescInfo.fSecondaryOutputType ||
235 this->fScissorState != that.fScissorState ||
240 this->fDstCopy.texture() != that.fDstCopy.texture()) { 236 this->fDstCopy.texture() != that.fDstCopy.texture()) {
241 return false; 237 return false;
242 } 238 }
243 239
244 bool hasVertexCoverage = 240 if (!fDescInfo.fHasVertexCoverage && this->fCoverage != that.fCoverage) {
245 this->fDesc.header().fCoverageInput == GrProgramDesc::kAttribute_Col orInput;
246 if (!hasVertexCoverage && this->fCoverage != that.fCoverage) {
247 return false; 241 return false;
248 } 242 }
249 243
250 if (this->hasGeometryProcessor()) { 244 if (this->hasGeometryProcessor()) {
251 if (!that.hasGeometryProcessor()) { 245 if (!that.hasGeometryProcessor()) {
252 return false; 246 return false;
253 } else if (!this->getGeometryProcessor()->isEqual(*that.getGeometryProce ssor())) { 247 } else if (!this->getGeometryProcessor()->isEqual(*that.getGeometryProce ssor())) {
254 return false; 248 return false;
255 } 249 }
256 } else if (that.hasGeometryProcessor()) { 250 } else if (that.hasGeometryProcessor()) {
257 return false; 251 return false;
258 } 252 }
259 253
260 // The program desc comparison should have already assured that the stage co unts match. 254 // The program desc comparison should have already assured that the stage co unts match.
261 SkASSERT(this->numFragmentStages() == that.numFragmentStages()); 255 SkASSERT(this->numFragmentStages() == that.numFragmentStages());
262 for (int i = 0; i < this->numFragmentStages(); i++) { 256 for (int i = 0; i < this->numFragmentStages(); i++) {
263 257
264 if (this->getFragmentStage(i) != that.getFragmentStage(i)) { 258 if (this->getFragmentStage(i) != that.getFragmentStage(i)) {
265 return false; 259 return false;
266 } 260 }
267 } 261 }
268 return true; 262 return true;
269 } 263 }
270 264
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698