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