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 "GrBackendProcessorFactory.h" |
11 #include "GrEffect.h" | 11 #include "GrProcessor.h" |
12 #include "GrGpuGL.h" | 12 #include "GrGpuGL.h" |
13 #include "GrOptDrawState.h" | 13 #include "GrOptDrawState.h" |
14 | 14 |
15 #include "SkChecksum.h" | 15 #include "SkChecksum.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 { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 } | 53 } |
54 if (kRGB_GrColorComponentFlags & swizzleComponentMask) { | 54 if (kRGB_GrColorComponentFlags & swizzleComponentMask) { |
55 // The 'r', 'g', and/or 'b's must be mapped to 'a' according to our semantics that | 55 // The 'r', 'g', and/or 'b's must be mapped to 'a' according to our semantics that |
56 // alpha-only textures smear alpha across all four channels when rea d. | 56 // alpha-only textures smear alpha across all four channels when rea d. |
57 return true; | 57 return true; |
58 } | 58 } |
59 } | 59 } |
60 return false; | 60 return false; |
61 } | 61 } |
62 | 62 |
63 static uint32_t gen_attrib_key(const GrEffect* effect) { | 63 static uint32_t gen_attrib_key(const GrGeometryProcessor* effect) { |
64 uint32_t key = 0; | 64 uint32_t key = 0; |
65 | 65 |
66 const GrEffect::VertexAttribArray& vars = effect->getVertexAttribs(); | 66 const GrGeometryProcessor::VertexAttribArray& vars = effect->getVertexAttrib s(); |
67 int numAttributes = vars.count(); | 67 int numAttributes = vars.count(); |
68 SkASSERT(numAttributes <= 2); | 68 SkASSERT(numAttributes <= 2); |
69 for (int a = 0; a < numAttributes; ++a) { | 69 for (int a = 0; a < numAttributes; ++a) { |
70 uint32_t value = 1 << a; | 70 uint32_t value = 1 << a; |
71 key |= value; | 71 key |= value; |
72 } | 72 } |
73 return key; | 73 return key; |
74 } | 74 } |
75 | 75 |
76 static uint32_t gen_transform_key(const GrEffectStage& effectStage, | 76 static uint32_t gen_transform_key(const GrProcessorStage& effectStage, |
77 bool useExplicitLocalCoords) { | 77 bool useExplicitLocalCoords) { |
78 uint32_t totalKey = 0; | 78 uint32_t totalKey = 0; |
79 int numTransforms = effectStage.getEffect()->numTransforms(); | 79 int numTransforms = effectStage.getProcessor()->numTransforms(); |
80 for (int t = 0; t < numTransforms; ++t) { | 80 for (int t = 0; t < numTransforms; ++t) { |
81 uint32_t key = 0; | 81 uint32_t key = 0; |
82 if (effectStage.isPerspectiveCoordTransform(t, useExplicitLocalCoords)) { | 82 if (effectStage.isPerspectiveCoordTransform(t, useExplicitLocalCoords)) { |
83 key |= kGeneral_MatrixType; | 83 key |= kGeneral_MatrixType; |
84 } else { | 84 } else { |
85 key |= kNoPersp_MatrixType; | 85 key |= kNoPersp_MatrixType; |
86 } | 86 } |
87 | 87 |
88 const GrCoordTransform& coordTransform = effectStage.getEffect()->coordT ransform(t); | 88 const GrCoordTransform& coordTransform = effectStage.getProcessor()->coo rdTransform(t); |
89 if (kLocal_GrCoordSet != coordTransform.sourceCoords() && useExplicitLoc alCoords) { | 89 if (kLocal_GrCoordSet != coordTransform.sourceCoords() && useExplicitLoc alCoords) { |
90 key |= kPositionCoords_Flag; | 90 key |= kPositionCoords_Flag; |
91 } | 91 } |
92 key <<= kTransformKeyBits * t; | 92 key <<= kTransformKeyBits * t; |
93 SkASSERT(0 == (totalKey & key)); // keys for each transform ought not to overlap | 93 SkASSERT(0 == (totalKey & key)); // keys for each transform ought not to overlap |
94 totalKey |= key; | 94 totalKey |= key; |
95 } | 95 } |
96 return totalKey; | 96 return totalKey; |
97 } | 97 } |
98 | 98 |
99 static uint32_t gen_texture_key(const GrEffect* effect, const GrGLCaps& caps) { | 99 static uint32_t gen_texture_key(const GrProcessor* effect, const GrGLCaps& caps) { |
100 uint32_t key = 0; | 100 uint32_t key = 0; |
101 int numTextures = effect->numTextures(); | 101 int numTextures = effect->numTextures(); |
102 for (int t = 0; t < numTextures; ++t) { | 102 for (int t = 0; t < numTextures; ++t) { |
103 const GrTextureAccess& access = effect->textureAccess(t); | 103 const GrTextureAccess& access = effect->textureAccess(t); |
104 uint32_t configComponentMask = GrPixelConfigComponentMask(access.getText ure()->config()); | 104 uint32_t configComponentMask = GrPixelConfigComponentMask(access.getText ure()->config()); |
105 if (swizzle_requires_alpha_remapping(caps, configComponentMask, access.s wizzleMask())) { | 105 if (swizzle_requires_alpha_remapping(caps, configComponentMask, access.s wizzleMask())) { |
106 key |= 1 << t; | 106 key |= 1 << t; |
107 } | 107 } |
108 } | 108 } |
109 return key; | 109 return key; |
110 } | 110 } |
111 | 111 |
112 /** | 112 /** |
113 * A function which emits a meta key into the key builder. This is required bec ause shader code may | 113 * A function which emits a meta key into the key builder. This is required bec ause shader code may |
114 * be dependent on properties of the effect that the effect itself doesn't use | 114 * be dependent on properties of the effect that the effect itself doesn't use |
115 * in its key (e.g. the pixel format of textures used). So we create a meta-key for | 115 * in its key (e.g. the pixel format of textures used). So we create a meta-key for |
116 * every effect using this function. It is also responsible for inserting the ef fect's class ID | 116 * every effect using this function. It is also responsible for inserting the ef fect's class ID |
117 * which must be different for every GrEffect subclass. It can fail if an effect uses too many | 117 * which must be different for every GrProcessor subclass. It can fail if an eff ect uses too many |
118 * textures, attributes, etc for the space allotted in the meta-key. | 118 * textures, attributes, etc for the space allotted in the meta-key. |
bsalomon
2014/09/22 15:35:24
del "attributes"?
| |
119 */ | 119 */ |
120 | 120 |
121 static bool gen_effect_meta_key(const GrEffectStage& effectStage, | 121 static uint32_t* get_processor_meta_key(const GrProcessorStage& processorStage, |
122 bool useExplicitLocalCoords, | 122 bool useExplicitLocalCoords, |
123 const GrGLCaps& caps, | 123 const GrGLCaps& caps, |
124 GrEffectKeyBuilder* b) { | 124 GrProcessorKeyBuilder* b) { |
125 | 125 |
126 uint32_t textureKey = gen_texture_key(effectStage.getEffect(), caps); | 126 uint32_t textureKey = gen_texture_key(processorStage.getProcessor(), caps); |
127 uint32_t transformKey = gen_transform_key(effectStage,useExplicitLocalCoords ); | 127 uint32_t transformKey = gen_transform_key(processorStage,useExplicitLocalCoo rds); |
128 uint32_t attribKey = gen_attrib_key(effectStage.getEffect()); | 128 uint32_t classID = processorStage.getProcessor()->getFactory().effectClassID (); |
129 uint32_t classID = effectStage.getEffect()->getFactory().effectClassID(); | |
130 | 129 |
131 // Currently we allow 16 bits for each of the above portions of the meta-key . Fail if they | 130 // Currently we allow 16 bits for each of the above portions of the meta-key . Fail if they |
132 // don't fit. | 131 // don't fit. |
133 static const uint32_t kMetaKeyInvalidMask = ~((uint32_t) SK_MaxU16); | 132 static const uint32_t kMetaKeyInvalidMask = ~((uint32_t) SK_MaxU16); |
134 if ((textureKey | transformKey | attribKey | classID) & kMetaKeyInvalidMask) { | 133 if ((textureKey | transformKey | classID) & kMetaKeyInvalidMask) { |
135 return false; | 134 return NULL; |
136 } | 135 } |
137 | 136 |
138 uint32_t* key = b->add32n(2); | 137 uint32_t* key = b->add32n(2); |
139 key[0] = (textureKey << 16 | transformKey); | 138 key[0] = (textureKey << 16 | transformKey); |
140 key[1] = (classID << 16 | attribKey); | 139 key[1] = (classID << 16); |
141 return true; | 140 return key; |
142 } | 141 } |
143 | 142 |
144 bool GrGLProgramDesc::GetEffectKey(const GrEffectStage& stage, const GrGLCaps& c aps, | 143 bool GrGLProgramDesc::GetProcessorKey(const GrProcessorStage& stage, |
145 bool useExplicitLocalCoords, GrEffectKeyBuild er* b, | 144 const GrGLCaps& caps, |
146 uint16_t* effectKeySize) { | 145 bool useExplicitLocalCoords, |
147 const GrBackendEffectFactory& factory = stage.getEffect()->getFactory(); | 146 GrProcessorKeyBuilder* b, |
148 const GrEffect& effect = *stage.getEffect(); | 147 uint16_t* processorKeySize) { |
149 factory.getGLEffectKey(effect, caps, b); | 148 const GrProcessor& effect = *stage.getProcessor(); |
149 const GrBackendProcessorFactory& factory = effect.getFactory(); | |
150 factory.getGLProcessorKey(effect, caps, b); | |
150 size_t size = b->size(); | 151 size_t size = b->size(); |
151 if (size > SK_MaxU16) { | 152 if (size > SK_MaxU16) { |
152 *effectKeySize = 0; // suppresses a warning. | 153 *processorKeySize = 0; // suppresses a warning. |
153 return false; | 154 return false; |
154 } | 155 } |
155 *effectKeySize = SkToU16(size); | 156 *processorKeySize = SkToU16(size); |
156 if (!gen_effect_meta_key(stage, useExplicitLocalCoords, caps, b)) { | 157 if (NULL == get_processor_meta_key(stage, useExplicitLocalCoords, caps, b)) { |
157 return false; | 158 return false; |
158 } | 159 } |
159 return true; | 160 return true; |
160 } | 161 } |
161 | 162 |
163 bool GrGLProgramDesc::GetGeometryProcessorKey(const GrGeometryStage& stage, | |
164 const GrGLCaps& caps, | |
165 bool useExplicitLocalCoords, | |
166 GrProcessorKeyBuilder* b, | |
167 uint16_t* processorKeySize) { | |
168 const GrProcessor& effect = *stage.getProcessor(); | |
169 const GrBackendProcessorFactory& factory = effect.getFactory(); | |
170 factory.getGLProcessorKey(effect, caps, b); | |
171 size_t size = b->size(); | |
172 if (size > SK_MaxU16) { | |
173 *processorKeySize = 0; // suppresses a warning. | |
174 return false; | |
175 } | |
176 *processorKeySize = SkToU16(size); | |
177 uint32_t* key = get_processor_meta_key(stage, useExplicitLocalCoords, caps, b); | |
178 if (NULL == key) { | |
179 return false; | |
180 } | |
181 uint32_t attribKey = gen_attrib_key(stage.getGeometryProcessor()); | |
182 | |
183 // Currently we allow 16 bits for each of the above portions of the meta-key . Fail if they | |
184 // don't fit. | |
185 static const uint32_t kMetaKeyInvalidMask = ~((uint32_t) SK_MaxU16); | |
186 if ((attribKey) & kMetaKeyInvalidMask) { | |
187 return false; | |
188 } | |
189 | |
190 key[1] |= attribKey; | |
191 return true; | |
192 } | |
193 | |
194 | |
162 bool GrGLProgramDesc::Build(const GrOptDrawState& optState, | 195 bool GrGLProgramDesc::Build(const GrOptDrawState& optState, |
163 GrGpu::DrawType drawType, | 196 GrGpu::DrawType drawType, |
164 GrBlendCoeff srcCoeff, | 197 GrBlendCoeff srcCoeff, |
165 GrBlendCoeff dstCoeff, | 198 GrBlendCoeff dstCoeff, |
166 const GrGpuGL* gpu, | 199 const GrGpuGL* gpu, |
167 const GrDeviceCoordTexture* dstCopy, | 200 const GrDeviceCoordTexture* dstCopy, |
168 const GrEffectStage** geometryProcessor, | 201 const GrGeometryStage** geometryProcessor, |
169 SkTArray<const GrEffectStage*, true>* colorStages, | 202 SkTArray<const GrFragmentStage*, true>* colorStages, |
170 SkTArray<const GrEffectStage*, true>* coverageStages , | 203 SkTArray<const GrFragmentStage*, true>* coverageStag es, |
171 GrGLProgramDesc* desc) { | 204 GrGLProgramDesc* desc) { |
172 colorStages->reset(); | 205 colorStages->reset(); |
173 coverageStages->reset(); | 206 coverageStages->reset(); |
174 | 207 |
175 bool inputColorIsUsed = optState.inputColorIsUsed(); | 208 bool inputColorIsUsed = optState.inputColorIsUsed(); |
176 bool inputCoverageIsUsed = optState.inputColorIsUsed(); | 209 bool inputCoverageIsUsed = optState.inputColorIsUsed(); |
177 | 210 |
178 // 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 |
179 // descriptor will not affect program generation (because of the attribute | 212 // descriptor will not affect program generation (because of the attribute |
180 // 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 |
(...skipping 16 matching lines...) Expand all Loading... | |
197 KeyHeader* header = desc->header(); | 230 KeyHeader* header = desc->header(); |
198 // make sure any padding in the header is zeroed. | 231 // make sure any padding in the header is zeroed. |
199 memset(desc->header(), 0, kHeaderSize); | 232 memset(desc->header(), 0, kHeaderSize); |
200 | 233 |
201 // We can only have one effect which touches the vertex shader | 234 // We can only have one effect which touches the vertex shader |
202 if (optState.hasGeometryProcessor()) { | 235 if (optState.hasGeometryProcessor()) { |
203 uint16_t* offsetAndSize = | 236 uint16_t* offsetAndSize = |
204 reinterpret_cast<uint16_t*>(desc->fKey.begin() + kEffectKeyOffse tsAndLengthOffset + | 237 reinterpret_cast<uint16_t*>(desc->fKey.begin() + kEffectKeyOffse tsAndLengthOffset + |
205 offsetAndSizeIndex * 2 * sizeof(uint 16_t)); | 238 offsetAndSizeIndex * 2 * sizeof(uint 16_t)); |
206 | 239 |
207 GrEffectKeyBuilder b(&desc->fKey); | 240 GrProcessorKeyBuilder b(&desc->fKey); |
208 uint16_t effectKeySize; | 241 uint16_t processorKeySize; |
209 uint32_t effectOffset = desc->fKey.count(); | 242 uint32_t processorOffset = desc->fKey.count(); |
210 effectKeySuccess |= GetEffectKey(*optState.getGeometryProcessor(), g pu->glCaps(), | 243 const GrGeometryStage& gpStage = *optState.getGeometryProcessor(); |
211 requiresLocalCoordAttrib, &b, &effe ctKeySize); | 244 effectKeySuccess |= GetGeometryProcessorKey(gpStage, gpu->glCaps(), |
bsalomon
2014/09/22 15:35:24
I think this has always been wrong, but shouldn't
| |
212 effectKeySuccess |= (effectOffset <= SK_MaxU16); | 245 requiresLocalCoordAttrib, &b , |
246 &processorKeySize); | |
247 effectKeySuccess |= (processorOffset <= SK_MaxU16); | |
213 | 248 |
214 offsetAndSize[0] = SkToU16(effectOffset); | 249 offsetAndSize[0] = SkToU16(processorOffset); |
215 offsetAndSize[1] = effectKeySize; | 250 offsetAndSize[1] = processorKeySize; |
216 ++offsetAndSizeIndex; | 251 ++offsetAndSizeIndex; |
217 *geometryProcessor = optState.getGeometryProcessor(); | 252 *geometryProcessor = &gpStage; |
218 header->fHasGeometryProcessor = true; | 253 header->fHasGeometryProcessor = true; |
219 } | 254 } |
220 | 255 |
221 for (int s = 0; s < optState.numColorStages(); ++s) { | 256 for (int s = 0; s < optState.numColorStages(); ++s) { |
222 uint16_t* offsetAndSize = | 257 uint16_t* offsetAndSize = |
223 reinterpret_cast<uint16_t*>(desc->fKey.begin() + kEffectKeyOffsetsAn dLengthOffset + | 258 reinterpret_cast<uint16_t*>(desc->fKey.begin() + kEffectKeyOffsetsAn dLengthOffset + |
224 offsetAndSizeIndex * 2 * sizeof(uint16_t )); | 259 offsetAndSizeIndex * 2 * sizeof(uint16_t )); |
225 | 260 |
226 GrEffectKeyBuilder b(&desc->fKey); | 261 GrProcessorKeyBuilder b(&desc->fKey); |
227 uint16_t effectKeySize; | 262 uint16_t processorKeySize; |
228 uint32_t effectOffset = desc->fKey.count(); | 263 uint32_t processorOffset = desc->fKey.count(); |
229 effectKeySuccess |= GetEffectKey(optState.getColorStage(s), gpu->glCaps( ), | 264 effectKeySuccess |= GetProcessorKey(optState.getColorStage(s), gpu->glCa ps(), |
230 requiresLocalCoordAttrib, &b, &effectKe ySize); | 265 requiresLocalCoordAttrib, &b, &processo rKeySize); |
231 effectKeySuccess |= (effectOffset <= SK_MaxU16); | 266 effectKeySuccess |= (processorOffset <= SK_MaxU16); |
232 | 267 |
233 offsetAndSize[0] = SkToU16(effectOffset); | 268 offsetAndSize[0] = SkToU16(processorOffset); |
234 offsetAndSize[1] = effectKeySize; | 269 offsetAndSize[1] = processorKeySize; |
235 ++offsetAndSizeIndex; | 270 ++offsetAndSizeIndex; |
236 } | 271 } |
237 | 272 |
238 for (int s = 0; s < optState.numCoverageStages(); ++s) { | 273 for (int s = 0; s < optState.numCoverageStages(); ++s) { |
239 uint16_t* offsetAndSize = | 274 uint16_t* offsetAndSize = |
240 reinterpret_cast<uint16_t*>(desc->fKey.begin() + kEffectKeyOffsetsAn dLengthOffset + | 275 reinterpret_cast<uint16_t*>(desc->fKey.begin() + kEffectKeyOffsetsAn dLengthOffset + |
241 offsetAndSizeIndex * 2 * sizeof(uint16_t )); | 276 offsetAndSizeIndex * 2 * sizeof(uint16_t )); |
242 | 277 |
243 GrEffectKeyBuilder b(&desc->fKey); | 278 GrProcessorKeyBuilder b(&desc->fKey); |
244 uint16_t effectKeySize; | 279 uint16_t processorKeySize; |
245 uint32_t effectOffset = desc->fKey.count(); | 280 uint32_t processorOffset = desc->fKey.count(); |
246 effectKeySuccess |= GetEffectKey(optState.getCoverageStage(s), gpu->glCa ps(), | 281 effectKeySuccess |= GetProcessorKey(optState.getCoverageStage(s), gpu->g lCaps(), |
247 requiresLocalCoordAttrib, &b, &effectKe ySize); | 282 requiresLocalCoordAttrib, &b, &processo rKeySize); |
248 effectKeySuccess |= (effectOffset <= SK_MaxU16); | 283 effectKeySuccess |= (processorOffset <= SK_MaxU16); |
249 | 284 |
250 offsetAndSize[0] = SkToU16(effectOffset); | 285 offsetAndSize[0] = SkToU16(processorOffset); |
251 offsetAndSize[1] = effectKeySize; | 286 offsetAndSize[1] = processorKeySize; |
252 ++offsetAndSizeIndex; | 287 ++offsetAndSizeIndex; |
253 } | 288 } |
254 | 289 |
255 if (!effectKeySuccess) { | 290 if (!effectKeySuccess) { |
256 desc->fKey.reset(); | 291 desc->fKey.reset(); |
257 return false; | 292 return false; |
258 } | 293 } |
259 | 294 |
260 // Because header is a pointer into the dynamic array, we can't push any new data into the key | 295 // Because header is a pointer into the dynamic array, we can't push any new data into the key |
261 // below here. | 296 // below here. |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
374 kOne_GrBlendCoeff == srcCoeff && | 409 kOne_GrBlendCoeff == srcCoeff && |
375 kZero_GrBlendCoeff == dstCoeff) { | 410 kZero_GrBlendCoeff == dstCoeff) { |
376 header->fCoverageOutput = kCombineWithDst_CoverageOutput; | 411 header->fCoverageOutput = kCombineWithDst_CoverageOutput; |
377 separateCoverageFromColor = true; | 412 separateCoverageFromColor = true; |
378 } | 413 } |
379 } | 414 } |
380 | 415 |
381 for (int s = 0; s < optState.numColorStages(); ++s) { | 416 for (int s = 0; s < optState.numColorStages(); ++s) { |
382 colorStages->push_back(&optState.getColorStage(s)); | 417 colorStages->push_back(&optState.getColorStage(s)); |
383 } | 418 } |
384 SkTArray<const GrEffectStage*, true>* array; | 419 SkTArray<const GrFragmentStage*, true>* array; |
385 if (separateCoverageFromColor) { | 420 if (separateCoverageFromColor) { |
386 array = coverageStages; | 421 array = coverageStages; |
387 } else { | 422 } else { |
388 array = colorStages; | 423 array = colorStages; |
389 } | 424 } |
390 for (int s = 0; s < optState.numCoverageStages(); ++s) { | 425 for (int s = 0; s < optState.numCoverageStages(); ++s) { |
391 array->push_back(&optState.getCoverageStage(s)); | 426 array->push_back(&optState.getCoverageStage(s)); |
392 } | 427 } |
393 | 428 |
394 header->fColorEffectCnt = colorStages->count(); | 429 header->fColorEffectCnt = colorStages->count(); |
(...skipping 12 matching lines...) Expand all Loading... | |
407 *checksum = 0; | 442 *checksum = 0; |
408 *checksum = SkChecksum::Compute(reinterpret_cast<uint32_t*>(fKey.begin()), k eyLength); | 443 *checksum = SkChecksum::Compute(reinterpret_cast<uint32_t*>(fKey.begin()), k eyLength); |
409 } | 444 } |
410 | 445 |
411 GrGLProgramDesc& GrGLProgramDesc::operator= (const GrGLProgramDesc& other) { | 446 GrGLProgramDesc& GrGLProgramDesc::operator= (const GrGLProgramDesc& other) { |
412 size_t keyLength = other.keyLength(); | 447 size_t keyLength = other.keyLength(); |
413 fKey.reset(keyLength); | 448 fKey.reset(keyLength); |
414 memcpy(fKey.begin(), other.fKey.begin(), keyLength); | 449 memcpy(fKey.begin(), other.fKey.begin(), keyLength); |
415 return *this; | 450 return *this; |
416 } | 451 } |
OLD | NEW |