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/gl/GrGLProgramDesc.cpp

Issue 509153002: Initial change to create GeometryProcessor (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: adding some tests to ignore Created 6 years, 3 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 2013 Google Inc. 2 * Copyright 2013 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 "gl/builders/GrGLProgramBuilder.h" 8 #include "gl/builders/GrGLProgramBuilder.h"
9 #include "GrGLProgramDesc.h" 9 #include "GrGLProgramDesc.h"
10 #include "GrBackendEffectFactory.h" 10 #include "GrBackendEffectFactory.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 return true; 46 return true;
47 } 47 }
48 48
49 bool GrGLProgramDesc::Build(const GrDrawState& drawState, 49 bool GrGLProgramDesc::Build(const GrDrawState& drawState,
50 GrGpu::DrawType drawType, 50 GrGpu::DrawType drawType,
51 GrDrawState::BlendOptFlags blendOpts, 51 GrDrawState::BlendOptFlags blendOpts,
52 GrBlendCoeff srcCoeff, 52 GrBlendCoeff srcCoeff,
53 GrBlendCoeff dstCoeff, 53 GrBlendCoeff dstCoeff,
54 const GrGpuGL* gpu, 54 const GrGpuGL* gpu,
55 const GrDeviceCoordTexture* dstCopy, 55 const GrDeviceCoordTexture* dstCopy,
56 const GrEffectStage** geometryProcessor,
56 SkTArray<const GrEffectStage*, true>* colorStages, 57 SkTArray<const GrEffectStage*, true>* colorStages,
57 SkTArray<const GrEffectStage*, true>* coverageStages , 58 SkTArray<const GrEffectStage*, true>* coverageStages ,
58 GrGLProgramDesc* desc) { 59 GrGLProgramDesc* desc) {
59 colorStages->reset(); 60 colorStages->reset();
60 coverageStages->reset(); 61 coverageStages->reset();
61 62
62 // This should already have been caught 63 // This should already have been caught
63 SkASSERT(!(GrDrawState::kSkipDraw_BlendOptFlag & blendOpts)); 64 SkASSERT(!(GrDrawState::kSkipDraw_BlendOptFlag & blendOpts));
64 65
65 bool skipCoverage = SkToBool(blendOpts & GrDrawState::kEmitTransBlack_BlendO ptFlag); 66 bool skipCoverage = SkToBool(blendOpts & GrDrawState::kEmitTransBlack_BlendO ptFlag);
66 67
67 bool skipColor = SkToBool(blendOpts & (GrDrawState::kEmitTransBlack_BlendOpt Flag | 68 bool skipColor = SkToBool(blendOpts & (GrDrawState::kEmitTransBlack_BlendOpt Flag |
68 GrDrawState::kEmitCoverage_BlendOptFl ag)); 69 GrDrawState::kEmitCoverage_BlendOptFl ag));
69 70
70 int firstEffectiveColorStage = 0; 71 int firstEffectiveColorStage = 0;
71 bool inputColorIsUsed = true; 72 bool inputColorIsUsed = true;
73
74 if (drawState.getGeometryProcessor()) {
75 const GrEffect* effect = drawState.getGeometryProcessor()->getEffect();
76 inputColorIsUsed = effect->willUseInputColor();
77 }
78
72 if (!skipColor) { 79 if (!skipColor) {
73 firstEffectiveColorStage = drawState.numColorStages(); 80 firstEffectiveColorStage = drawState.numColorStages();
74 while (firstEffectiveColorStage > 0 && inputColorIsUsed) { 81 while (firstEffectiveColorStage > 0 && inputColorIsUsed) {
75 --firstEffectiveColorStage; 82 --firstEffectiveColorStage;
76 const GrEffect* effect = drawState.getColorStage(firstEffectiveColor Stage).getEffect(); 83 const GrEffect* effect = drawState.getColorStage(firstEffectiveColor Stage).getEffect();
77 inputColorIsUsed = effect->willUseInputColor(); 84 inputColorIsUsed = effect->willUseInputColor();
78 } 85 }
79 } 86 }
80 87
81 int firstEffectiveCoverageStage = 0; 88 int firstEffectiveCoverageStage = 0;
(...skipping 18 matching lines...) Expand all
100 bool requiresLocalCoordAttrib = !(skipCoverage && skipColor) && 107 bool requiresLocalCoordAttrib = !(skipCoverage && skipColor) &&
101 drawState.hasLocalCoordAttribute(); 108 drawState.hasLocalCoordAttribute();
102 109
103 bool readsDst = false; 110 bool readsDst = false;
104 bool readFragPosition = false; 111 bool readFragPosition = false;
105 112
106 // Provide option for shader programs without vertex shader only when drawin g paths. 113 // Provide option for shader programs without vertex shader only when drawin g paths.
107 bool requiresVertexShader = !GrGpu::IsPathRenderingDrawType(drawType); 114 bool requiresVertexShader = !GrGpu::IsPathRenderingDrawType(drawType);
108 115
109 int numStages = 0; 116 int numStages = 0;
117 if (drawState.getGeometryProcessor()) {
118 numStages++;
119 }
110 if (!skipColor) { 120 if (!skipColor) {
111 numStages += drawState.numColorStages() - firstEffectiveColorStage; 121 numStages += drawState.numColorStages() - firstEffectiveColorStage;
112 } 122 }
113 if (!skipCoverage) { 123 if (!skipCoverage) {
114 numStages += drawState.numCoverageStages() - firstEffectiveCoverageStage ; 124 numStages += drawState.numCoverageStages() - firstEffectiveCoverageStage ;
115 } 125 }
116 GR_STATIC_ASSERT(0 == kEffectKeyOffsetsAndLengthOffset % sizeof(uint32_t)); 126 GR_STATIC_ASSERT(0 == kEffectKeyOffsetsAndLengthOffset % sizeof(uint32_t));
117 // Make room for everything up to and including the array of offsets to effe ct keys. 127 // Make room for everything up to and including the array of offsets to effe ct keys.
118 desc->fKey.reset(); 128 desc->fKey.reset();
119 desc->fKey.push_back_n(kEffectKeyOffsetsAndLengthOffset + 2 * sizeof(uint16_ t) * numStages); 129 desc->fKey.push_back_n(kEffectKeyOffsetsAndLengthOffset + 2 * sizeof(uint16_ t) * numStages);
120 130
121 int offsetAndSizeIndex = 0; 131 int offsetAndSizeIndex = 0;
122 bool effectKeySuccess = true; 132 bool effectKeySuccess = true;
133
134 KeyHeader* header = desc->header();
135 // make sure any padding in the header is zeroed.
136 memset(desc->header(), 0, kHeaderSize);
137
138 // We can only have one effect which touches the vertex shader
139 if (drawState.getGeometryProcessor()) {
140 uint16_t* offsetAndSize =
141 reinterpret_cast<uint16_t*>(desc->fKey.begin() + kEffectKeyOffse tsAndLengthOffset +
142 offsetAndSizeIndex * 2 * sizeof(uint 16_t));
143
144 GrEffectKeyBuilder b(&desc->fKey);
145 uint16_t effectKeySize;
146 uint32_t effectOffset = desc->fKey.count();
147 effectKeySuccess |= GetEffectKeyAndUpdateStats(
148 *drawState.getGeometryProcessor(), gpu->glCa ps(),
149 requiresLocalCoordAttrib, &b,
150 &effectKeySize, &readsDst,
151 &readFragPosition, &requiresVertexShader);
152 effectKeySuccess |= (effectOffset <= SK_MaxU16);
153
154 offsetAndSize[0] = SkToU16(effectOffset);
155 offsetAndSize[1] = effectKeySize;
156 ++offsetAndSizeIndex;
157 *geometryProcessor = drawState.getGeometryProcessor();
158 SkASSERT(requiresVertexShader);
159 header->fHasGeometryProcessor = true;
160 }
161
123 if (!skipColor) { 162 if (!skipColor) {
124 for (int s = firstEffectiveColorStage; s < drawState.numColorStages(); + +s) { 163 for (int s = firstEffectiveColorStage; s < drawState.numColorStages(); + +s) {
125 uint16_t* offsetAndSize = 164 uint16_t* offsetAndSize =
126 reinterpret_cast<uint16_t*>(desc->fKey.begin() + kEffectKeyOffse tsAndLengthOffset + 165 reinterpret_cast<uint16_t*>(desc->fKey.begin() + kEffectKeyOffse tsAndLengthOffset +
127 offsetAndSizeIndex * 2 * sizeof(uint 16_t)); 166 offsetAndSizeIndex * 2 * sizeof(uint 16_t));
128 167
168 bool effectRequiresVertexShader = false;
129 GrEffectKeyBuilder b(&desc->fKey); 169 GrEffectKeyBuilder b(&desc->fKey);
130 uint16_t effectKeySize; 170 uint16_t effectKeySize;
131 uint32_t effectOffset = desc->fKey.count(); 171 uint32_t effectOffset = desc->fKey.count();
132 effectKeySuccess |= GetEffectKeyAndUpdateStats( 172 effectKeySuccess |= GetEffectKeyAndUpdateStats(
133 drawState.getColorStage(s), gpu->glCaps(), 173 drawState.getColorStage(s), gpu->glCaps(),
134 requiresLocalCoordAttrib, &b, 174 requiresLocalCoordAttrib, &b,
135 &effectKeySize, &readsDst, 175 &effectKeySize, &readsDst,
136 &readFragPosition, &requiresVertexShader); 176 &readFragPosition, &effectRequiresVertexShad er);
137 effectKeySuccess |= (effectOffset <= SK_MaxU16); 177 effectKeySuccess |= (effectOffset <= SK_MaxU16);
138 178
139 offsetAndSize[0] = SkToU16(effectOffset); 179 offsetAndSize[0] = SkToU16(effectOffset);
140 offsetAndSize[1] = effectKeySize; 180 offsetAndSize[1] = effectKeySize;
141 ++offsetAndSizeIndex; 181 ++offsetAndSizeIndex;
182 SkASSERT(!effectRequiresVertexShader);
142 } 183 }
143 } 184 }
144 if (!skipCoverage) { 185 if (!skipCoverage) {
145 for (int s = firstEffectiveCoverageStage; s < drawState.numCoverageStage s(); ++s) { 186 for (int s = firstEffectiveCoverageStage; s < drawState.numCoverageStage s(); ++s) {
146 uint16_t* offsetAndSize = 187 uint16_t* offsetAndSize =
147 reinterpret_cast<uint16_t*>(desc->fKey.begin() + kEffectKeyOffse tsAndLengthOffset + 188 reinterpret_cast<uint16_t*>(desc->fKey.begin() + kEffectKeyOffse tsAndLengthOffset +
148 offsetAndSizeIndex * 2 * sizeof(uint 16_t)); 189 offsetAndSizeIndex * 2 * sizeof(uint 16_t));
149 190
191 bool effectRequiresVertexShader = false;
150 GrEffectKeyBuilder b(&desc->fKey); 192 GrEffectKeyBuilder b(&desc->fKey);
151 uint16_t effectKeySize; 193 uint16_t effectKeySize;
152 uint32_t effectOffset = desc->fKey.count(); 194 uint32_t effectOffset = desc->fKey.count();
153 effectKeySuccess |= GetEffectKeyAndUpdateStats( 195 effectKeySuccess |= GetEffectKeyAndUpdateStats(
154 drawState.getCoverageStage(s), gpu->glCaps() , 196 drawState.getCoverageStage(s), gpu->glCaps() ,
155 requiresLocalCoordAttrib, &b, 197 requiresLocalCoordAttrib, &b,
156 &effectKeySize, &readsDst, 198 &effectKeySize, &readsDst,
157 &readFragPosition, &requiresVertexShader); 199 &readFragPosition, &effectRequiresVertexShad er);
158 effectKeySuccess |= (effectOffset <= SK_MaxU16); 200 effectKeySuccess |= (effectOffset <= SK_MaxU16);
159 201
160 offsetAndSize[0] = SkToU16(effectOffset); 202 offsetAndSize[0] = SkToU16(effectOffset);
161 offsetAndSize[1] = effectKeySize; 203 offsetAndSize[1] = effectKeySize;
162 ++offsetAndSizeIndex; 204 ++offsetAndSizeIndex;
205 SkASSERT(!effectRequiresVertexShader);
163 } 206 }
164 } 207 }
165 if (!effectKeySuccess) { 208 if (!effectKeySuccess) {
166 desc->fKey.reset(); 209 desc->fKey.reset();
167 return false; 210 return false;
168 } 211 }
169 212
170 KeyHeader* header = desc->header();
171 // make sure any padding in the header is zeroed.
172 memset(desc->header(), 0, kHeaderSize);
173
174 // Because header is a pointer into the dynamic array, we can't push any new data into the key 213 // Because header is a pointer into the dynamic array, we can't push any new data into the key
175 // below here. 214 // below here.
176 215
177 header->fRequiresVertexShader = requiresVertexShader || requiresLocalCoordAt trib; 216 header->fRequiresVertexShader = requiresVertexShader || requiresLocalCoordAt trib;
178 header->fEmitsPointSize = GrGpu::kDrawPoints_DrawType == drawType; 217 header->fEmitsPointSize = GrGpu::kDrawPoints_DrawType == drawType;
179 218
180 // Currently the experimental GS will only work with triangle prims (and it doesn't do anything 219 // Currently the experimental GS will only work with triangle prims (and it doesn't do anything
181 // other than pass through values from the VS to the FS anyway). 220 // other than pass through values from the VS to the FS anyway).
182 #if GR_GL_EXPERIMENTAL_GS 221 #if GR_GL_EXPERIMENTAL_GS
183 #if 0 222 #if 0
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 } 291 }
253 292
254 // Here we deal with whether/how we handle color and coverage separately. 293 // Here we deal with whether/how we handle color and coverage separately.
255 294
256 // Set this default and then possibly change our mind if there is coverage. 295 // Set this default and then possibly change our mind if there is coverage.
257 header->fCoverageOutput = kModulate_CoverageOutput; 296 header->fCoverageOutput = kModulate_CoverageOutput;
258 297
259 // If we do have coverage determine whether it matters. 298 // If we do have coverage determine whether it matters.
260 bool separateCoverageFromColor = false; 299 bool separateCoverageFromColor = false;
261 if (!drawState.isCoverageDrawing() && !skipCoverage && 300 if (!drawState.isCoverageDrawing() && !skipCoverage &&
262 (drawState.numCoverageStages() > 0 || requiresCoverageAttrib)) { 301 (drawState.numCoverageStages() > 0 ||
302 drawState.getGeometryProcessor() ||
303 requiresCoverageAttrib)) {
263 304
264 if (gpu->caps()->dualSourceBlendingSupport() && 305 if (gpu->caps()->dualSourceBlendingSupport() &&
265 !(blendOpts & (GrDrawState::kEmitCoverage_BlendOptFlag | 306 !(blendOpts & (GrDrawState::kEmitCoverage_BlendOptFlag |
266 GrDrawState::kCoverageAsAlpha_BlendOptFlag))) { 307 GrDrawState::kCoverageAsAlpha_BlendOptFlag))) {
267 if (kZero_GrBlendCoeff == dstCoeff) { 308 if (kZero_GrBlendCoeff == dstCoeff) {
268 // write the coverage value to second color 309 // write the coverage value to second color
269 header->fCoverageOutput = kSecondaryCoverage_CoverageOutput; 310 header->fCoverageOutput = kSecondaryCoverage_CoverageOutput;
270 separateCoverageFromColor = true; 311 separateCoverageFromColor = true;
271 } else if (kSA_GrBlendCoeff == dstCoeff) { 312 } else if (kSA_GrBlendCoeff == dstCoeff) {
272 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered. 313 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered.
273 header->fCoverageOutput = kSecondaryCoverageISA_CoverageOutput; 314 header->fCoverageOutput = kSecondaryCoverageISA_CoverageOutput;
274 separateCoverageFromColor = true; 315 separateCoverageFromColor = true;
275 } else if (kSC_GrBlendCoeff == dstCoeff) { 316 } else if (kSC_GrBlendCoeff == dstCoeff) {
276 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered. 317 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered.
277 header->fCoverageOutput = kSecondaryCoverageISC_CoverageOutput; 318 header->fCoverageOutput = kSecondaryCoverageISC_CoverageOutput;
278 separateCoverageFromColor = true; 319 separateCoverageFromColor = true;
279 } 320 }
280 } else if (readsDst && 321 } else if (readsDst &&
281 kOne_GrBlendCoeff == srcCoeff && 322 kOne_GrBlendCoeff == srcCoeff &&
282 kZero_GrBlendCoeff == dstCoeff) { 323 kZero_GrBlendCoeff == dstCoeff) {
283 header->fCoverageOutput = kCombineWithDst_CoverageOutput; 324 header->fCoverageOutput = kCombineWithDst_CoverageOutput;
284 separateCoverageFromColor = true; 325 separateCoverageFromColor = true;
285 } 326 }
286 } 327 }
328
329 header->fSeparateCoverageFromColor = separateCoverageFromColor;
330
287 if (!skipColor) { 331 if (!skipColor) {
288 for (int s = firstEffectiveColorStage; s < drawState.numColorStages(); + +s) { 332 for (int s = firstEffectiveColorStage; s < drawState.numColorStages(); + +s) {
289 colorStages->push_back(&drawState.getColorStage(s)); 333 colorStages->push_back(&drawState.getColorStage(s));
290 } 334 }
291 } 335 }
292 if (!skipCoverage) { 336 if (!skipCoverage) {
293 SkTArray<const GrEffectStage*, true>* array; 337 SkTArray<const GrEffectStage*, true>* array;
294 if (separateCoverageFromColor) { 338 if (separateCoverageFromColor) {
295 array = coverageStages; 339 array = coverageStages;
296 } else { 340 } else {
(...skipping 19 matching lines...) Expand all
316 *checksum = 0; 360 *checksum = 0;
317 *checksum = SkChecksum::Compute(reinterpret_cast<uint32_t*>(fKey.begin()), k eyLength); 361 *checksum = SkChecksum::Compute(reinterpret_cast<uint32_t*>(fKey.begin()), k eyLength);
318 } 362 }
319 363
320 GrGLProgramDesc& GrGLProgramDesc::operator= (const GrGLProgramDesc& other) { 364 GrGLProgramDesc& GrGLProgramDesc::operator= (const GrGLProgramDesc& other) {
321 size_t keyLength = other.keyLength(); 365 size_t keyLength = other.keyLength();
322 fKey.reset(keyLength); 366 fKey.reset(keyLength);
323 memcpy(fKey.begin(), other.fKey.begin(), keyLength); 367 memcpy(fKey.begin(), other.fKey.begin(), keyLength);
324 return *this; 368 return *this;
325 } 369 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698