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 #include "GrGLProgramDesc.h" | |
7 | 8 |
8 #include "gl/builders/GrGLFragmentShaderBuilder.h" | 9 #include "GrGLProcessor.h" |
9 #include "GrGLProgramDesc.h" | |
10 #include "GrBackendProcessorFactory.h" | 10 #include "GrBackendProcessorFactory.h" |
11 #include "GrProcessor.h" | 11 #include "GrProcessor.h" |
12 #include "GrGpuGL.h" | 12 #include "GrGpuGL.h" |
13 #include "GrOptDrawState.h" | 13 #include "GrOptDrawState.h" |
14 | |
15 #include "SkChecksum.h" | 14 #include "SkChecksum.h" |
15 #include "gl/builders/GrGLFragmentShaderBuilder.h" | |
16 | 16 |
17 /** | 17 /** |
18 * The key for an individual coord transform is made up of a matrix type and a b it that | 18 * The key for an individual coord transform is made up of a matrix type and a b it that |
19 * indicates the source of the input coords. | 19 * indicates the source of the input coords. |
20 */ | 20 */ |
21 enum { | 21 enum { |
22 kMatrixTypeKeyBits = 1, | 22 kMatrixTypeKeyBits = 1, |
23 kMatrixTypeKeyMask = (1 << kMatrixTypeKeyBits) - 1, | 23 kMatrixTypeKeyMask = (1 << kMatrixTypeKeyBits) - 1, |
24 kPositionCoords_Flag = (1 << kMatrixTypeKeyBits), | 24 kPositionCoords_Flag = (1 << kMatrixTypeKeyBits), |
25 kTransformKeyBits = kMatrixTypeKeyBits + 1, | 25 kTransformKeyBits = kMatrixTypeKeyBits + 1, |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 b, keySize); | 172 b, keySize); |
173 } | 173 } |
174 }; | 174 }; |
175 | 175 |
176 | 176 |
177 template <class ProcessorKeyBuilder> | 177 template <class ProcessorKeyBuilder> |
178 bool | 178 bool |
179 GrGLProgramDesc::BuildStagedProcessorKey(const typename ProcessorKeyBuilder::Sta gedProcessor& stage, | 179 GrGLProgramDesc::BuildStagedProcessorKey(const typename ProcessorKeyBuilder::Sta gedProcessor& stage, |
180 const GrGLCaps& caps, | 180 const GrGLCaps& caps, |
181 bool requiresLocalCoordAttrib, | 181 bool requiresLocalCoordAttrib, |
182 GrGLProgramDesc* desc, | 182 GrProgramDesc* desc, |
183 int* offsetAndSizeIndex) { | 183 int* offsetAndSizeIndex) { |
184 GrProcessorKeyBuilder b(&desc->fKey); | 184 GrProcessorKeyBuilder b(&desc->fKey); |
185 uint16_t processorKeySize; | 185 uint16_t processorKeySize; |
186 uint32_t processorOffset = desc->fKey.count(); | 186 uint32_t processorOffset = desc->fKey.count(); |
187 if (processorOffset > SK_MaxU16 || | 187 if (processorOffset > SK_MaxU16 || |
188 !ProcessorKeyBuilder::GetProcessorKey(stage, caps, requiresLocalCoor dAttrib, &b, | 188 !ProcessorKeyBuilder::GetProcessorKey(stage, caps, requiresLocalCoor dAttrib, &b, |
189 &processorKeySize)){ | 189 &processorKeySize)){ |
190 desc->fKey.reset(); | 190 desc->fKey.reset(); |
191 return false; | 191 return false; |
192 } | 192 } |
193 | 193 |
194 uint16_t* offsetAndSize = | 194 uint16_t* offsetAndSize = |
195 reinterpret_cast<uint16_t*>(desc->fKey.begin() + kEffectKeyOffsetsAn dLengthOffset + | 195 reinterpret_cast<uint16_t*>(desc->fKey.begin() + kEffectKeyOffsetsAn dLengthOffset + |
196 *offsetAndSizeIndex * 2 * sizeof(uint16_ t)); | 196 *offsetAndSizeIndex * 2 * sizeof(uint16_ t)); |
197 offsetAndSize[0] = SkToU16(processorOffset); | 197 offsetAndSize[0] = SkToU16(processorOffset); |
198 offsetAndSize[1] = processorKeySize; | 198 offsetAndSize[1] = processorKeySize; |
199 ++(*offsetAndSizeIndex); | 199 ++(*offsetAndSizeIndex); |
200 return true; | 200 return true; |
201 } | 201 } |
202 | 202 |
203 bool GrGLProgramDesc::Build(const GrOptDrawState& optState, | 203 bool GrGLProgramDesc::Build(const GrOptDrawState& optState, |
204 GrGpu::DrawType drawType, | 204 GrGpu::DrawType drawType, |
205 GrGpuGL* gpu, | 205 GrGpuGL* gpu, |
206 const GrDeviceCoordTexture* dstCopy, | 206 const GrDeviceCoordTexture* dstCopy, |
207 GrGLProgramDesc* desc) { | 207 GrProgramDesc* desc) { |
208 bool inputColorIsUsed = optState.inputColorIsUsed(); | 208 bool inputColorIsUsed = optState.inputColorIsUsed(); |
209 bool inputCoverageIsUsed = optState.inputCoverageIsUsed(); | 209 bool inputCoverageIsUsed = optState.inputCoverageIsUsed(); |
210 | 210 |
211 // The descriptor is used as a cache key. Thus when a field of the | 211 // The descriptor is used as a cache key. Thus when a field of the |
212 // descriptor will not affect program generation (because of the attribute | 212 // descriptor will not affect program generation (because of the attribute |
213 // bindings in use or other descriptor field settings) it should be set | 213 // bindings in use or other descriptor field settings) it should be set |
214 // to a canonical value to avoid duplicate programs with different keys. | 214 // to a canonical value to avoid duplicate programs with different keys. |
215 | 215 |
216 bool requiresLocalCoordAttrib = optState.requiresLocalCoordAttrib(); | 216 bool requiresLocalCoordAttrib = optState.requiresLocalCoordAttrib(); |
217 | 217 |
(...skipping 23 matching lines...) Expand all Loading... | |
241 requiresLocalC oordAttrib, | 241 requiresLocalC oordAttrib, |
242 desc, | 242 desc, |
243 &offsetAndSize Index)) { | 243 &offsetAndSize Index)) { |
244 return false; | 244 return false; |
245 } | 245 } |
246 } | 246 } |
247 | 247 |
248 // --------DO NOT MOVE HEADER ABOVE THIS LINE------------------------------- ------------------- | 248 // --------DO NOT MOVE HEADER ABOVE THIS LINE------------------------------- ------------------- |
249 // Because header is a pointer into the dynamic array, we can't push any new data into the key | 249 // Because header is a pointer into the dynamic array, we can't push any new data into the key |
250 // below here. | 250 // below here. |
251 KeyHeader* header = desc->header(); | 251 GLKeyHeader* header = desc->atOffset<GLKeyHeader, kHeaderOffset>(); |
252 | 252 |
253 // make sure any padding in the header is zeroed. | 253 // make sure any padding in the header is zeroed. |
254 memset(header, 0, kHeaderSize); | 254 memset(header, 0, kHeaderSize); |
255 | 255 |
256 header->fHasGeometryProcessor = optState.hasGeometryProcessor(); | 256 header->fHasGeometryProcessor = optState.hasGeometryProcessor(); |
257 | 257 |
258 header->fEmitsPointSize = GrGpu::kDrawPoints_DrawType == drawType; | 258 header->fEmitsPointSize = GrGpu::kDrawPoints_DrawType == drawType; |
259 | 259 |
260 if (gpu->caps()->pathRenderingSupport() && | 260 if (gpu->caps()->pathRenderingSupport() && |
261 GrGpu::IsPathRenderingDrawType(drawType) && | 261 GrGpu::IsPathRenderingDrawType(drawType) && |
262 gpu->glPathRendering()->texturingMode() == GrGLPathRendering::FixedFunct ion_TexturingMode) { | 262 gpu->glPathRendering()->texturingMode() == GrGLPathRendering::FixedFunct ion_TexturingMode) { |
263 header->fUseFragShaderOnly = true; | 263 header->fUseFragShaderOnly = true; |
264 SkASSERT(!optState.hasGeometryProcessor()); | 264 SkASSERT(!optState.hasGeometryProcessor()); |
265 } else { | 265 } else { |
266 header->fUseFragShaderOnly = false; | 266 header->fUseFragShaderOnly = false; |
267 } | 267 } |
268 | 268 |
269 bool defaultToUniformInputs = GrGpu::IsPathRenderingDrawType(drawType) || | 269 bool defaultToUniformInputs = GrGpu::IsPathRenderingDrawType(drawType) || |
270 GR_GL_NO_CONSTANT_ATTRIBUTES; | 270 GR_GL_NO_CONSTANT_ATTRIBUTES; |
271 | 271 |
272 if (!inputColorIsUsed) { | 272 if (!inputColorIsUsed) { |
273 header->fColorInput = kAllOnes_ColorInput; | 273 header->fColorInput = GrProgramDesc::kAllOnes_ColorInput; |
274 } else if (defaultToUniformInputs && !optState.hasColorVertexAttribute()) { | 274 } else if (defaultToUniformInputs && !optState.hasColorVertexAttribute()) { |
275 header->fColorInput = kUniform_ColorInput; | 275 header->fColorInput = GrProgramDesc::kUniform_ColorInput; |
276 } else { | 276 } else { |
277 header->fColorInput = kAttribute_ColorInput; | 277 header->fColorInput = GrProgramDesc::kAttribute_ColorInput; |
278 SkASSERT(!header->fUseFragShaderOnly); | 278 SkASSERT(!header->fUseFragShaderOnly); |
279 } | 279 } |
280 | 280 |
281 bool covIsSolidWhite = !optState.hasCoverageVertexAttribute() && | 281 bool covIsSolidWhite = !optState.hasCoverageVertexAttribute() && |
282 0xffffffff == optState.getCoverageColor(); | 282 0xffffffff == optState.getCoverageColor(); |
283 | 283 |
284 if (covIsSolidWhite || !inputCoverageIsUsed) { | 284 if (covIsSolidWhite || !inputCoverageIsUsed) { |
285 header->fCoverageInput = kAllOnes_ColorInput; | 285 header->fCoverageInput = GrProgramDesc::kAllOnes_ColorInput; |
286 } else if (defaultToUniformInputs && !optState.hasCoverageVertexAttribute()) { | 286 } else if (defaultToUniformInputs && !optState.hasCoverageVertexAttribute()) { |
287 header->fCoverageInput = kUniform_ColorInput; | 287 header->fCoverageInput = GrProgramDesc::kUniform_ColorInput; |
288 } else { | 288 } else { |
289 header->fCoverageInput = kAttribute_ColorInput; | 289 header->fCoverageInput = GrProgramDesc::kAttribute_ColorInput; |
290 SkASSERT(!header->fUseFragShaderOnly); | 290 SkASSERT(!header->fUseFragShaderOnly); |
291 } | 291 } |
292 | 292 |
293 if (optState.readsDst()) { | 293 if (optState.readsDst()) { |
294 SkASSERT(dstCopy || gpu->caps()->dstReadInShaderSupport()); | 294 SkASSERT(dstCopy || gpu->caps()->dstReadInShaderSupport()); |
295 const GrTexture* dstCopyTexture = NULL; | 295 const GrTexture* dstCopyTexture = NULL; |
296 if (dstCopy) { | 296 if (dstCopy) { |
297 dstCopyTexture = dstCopy->texture(); | 297 dstCopyTexture = dstCopy->texture(); |
298 } | 298 } |
299 header->fDstReadKey = GrGLFragmentShaderBuilder::KeyForDstRead(dstCopyTe xture, | 299 header->fDstReadKey = GrGLFragmentShaderBuilder::KeyForDstRead(dstCopyTe xture, |
(...skipping 12 matching lines...) Expand all Loading... | |
312 } | 312 } |
313 | 313 |
314 // Record attribute indices | 314 // Record attribute indices |
315 header->fPositionAttributeIndex = optState.positionAttributeIndex(); | 315 header->fPositionAttributeIndex = optState.positionAttributeIndex(); |
316 header->fLocalCoordAttributeIndex = optState.localCoordAttributeIndex(); | 316 header->fLocalCoordAttributeIndex = optState.localCoordAttributeIndex(); |
317 | 317 |
318 // For constant color and coverage we need an attribute with an index beyond those already set | 318 // For constant color and coverage we need an attribute with an index beyond those already set |
319 int availableAttributeIndex = optState.getVertexAttribCount(); | 319 int availableAttributeIndex = optState.getVertexAttribCount(); |
320 if (optState.hasColorVertexAttribute()) { | 320 if (optState.hasColorVertexAttribute()) { |
321 header->fColorAttributeIndex = optState.colorVertexAttributeIndex(); | 321 header->fColorAttributeIndex = optState.colorVertexAttributeIndex(); |
322 } else if (GrGLProgramDesc::kAttribute_ColorInput == header->fColorInput) { | 322 } else if (GrProgramDesc::kAttribute_ColorInput == header->fColorInput) { |
323 SkASSERT(availableAttributeIndex < GrDrawState::kMaxVertexAttribCnt); | 323 SkASSERT(availableAttributeIndex < GrDrawState::kMaxVertexAttribCnt); |
324 header->fColorAttributeIndex = availableAttributeIndex; | 324 header->fColorAttributeIndex = availableAttributeIndex; |
325 availableAttributeIndex++; | 325 availableAttributeIndex++; |
326 } else { | 326 } else { |
327 header->fColorAttributeIndex = -1; | 327 header->fColorAttributeIndex = -1; |
328 } | 328 } |
329 | 329 |
330 if (optState.hasCoverageVertexAttribute()) { | 330 if (optState.hasCoverageVertexAttribute()) { |
331 header->fCoverageAttributeIndex = optState.coverageVertexAttributeIndex( ); | 331 header->fCoverageAttributeIndex = optState.coverageVertexAttributeIndex( ); |
332 } else if (GrGLProgramDesc::kAttribute_ColorInput == header->fCoverageInput) { | 332 } else if (GrProgramDesc::kAttribute_ColorInput == header->fCoverageInput) { |
333 SkASSERT(availableAttributeIndex < GrDrawState::kMaxVertexAttribCnt); | 333 SkASSERT(availableAttributeIndex < GrDrawState::kMaxVertexAttribCnt); |
334 header->fCoverageAttributeIndex = availableAttributeIndex; | 334 header->fCoverageAttributeIndex = availableAttributeIndex; |
335 } else { | 335 } else { |
336 header->fCoverageAttributeIndex = -1; | 336 header->fCoverageAttributeIndex = -1; |
337 } | 337 } |
338 | 338 |
339 header->fPrimaryOutputType = optState.getPrimaryOutputType(); | 339 header->fPrimaryOutputType = optState.getPrimaryOutputType(); |
340 header->fSecondaryOutputType = optState.getSecondaryOutputType(); | 340 header->fSecondaryOutputType = optState.getSecondaryOutputType(); |
341 | 341 |
342 header->fColorEffectCnt = optState.numColorStages(); | 342 header->fColorEffectCnt = optState.numColorStages(); |
343 header->fCoverageEffectCnt = optState.numCoverageStages(); | 343 header->fCoverageEffectCnt = optState.numCoverageStages(); |
344 desc->finalize(); | 344 GrGLProgramDesc::Finalize(desc); |
345 return true; | 345 return true; |
346 } | 346 } |
347 | 347 |
348 void GrGLProgramDesc::finalize() { | 348 void GrGLProgramDesc::Finalize(GrProgramDesc* desc) { |
bsalomon
2014/10/23 18:10:30
Should this be moved to GrProgramDesc (even if it
| |
349 int keyLength = fKey.count(); | 349 int keyLength = desc->fKey.count(); |
350 SkASSERT(0 == (keyLength % 4)); | 350 SkASSERT(0 == (keyLength % 4)); |
351 *this->atOffset<uint32_t, kLengthOffset>() = SkToU32(keyLength); | 351 *(desc->atOffset<uint32_t, GrProgramDesc::kLengthOffset>()) = SkToU32(keyLen gth); |
352 | 352 |
353 uint32_t* checksum = this->atOffset<uint32_t, kChecksumOffset>(); | 353 uint32_t* checksum = desc->atOffset<uint32_t, GrProgramDesc::kChecksumOffset >(); |
354 *checksum = 0; | 354 *checksum = 0; |
355 *checksum = SkChecksum::Compute(reinterpret_cast<uint32_t*>(fKey.begin()), k eyLength); | 355 *checksum = SkChecksum::Compute(reinterpret_cast<uint32_t*>(desc->fKey.begin ()), keyLength); |
356 } | 356 } |
357 | 357 |
358 GrGLProgramDesc& GrGLProgramDesc::operator= (const GrGLProgramDesc& other) { | |
359 size_t keyLength = other.keyLength(); | |
360 fKey.reset(keyLength); | |
361 memcpy(fKey.begin(), other.fKey.begin(), keyLength); | |
362 return *this; | |
363 } | |
OLD | NEW |