OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 // This is a GPU-backend specific test. It relies on static intializers to work | 9 // This is a GPU-backend specific test. It relies on static intializers to work |
10 | 10 |
11 #include "SkTypes.h" | 11 #include "SkTypes.h" |
12 | 12 |
13 #if SK_SUPPORT_GPU && SK_ALLOW_STATIC_GLOBAL_INITIALIZERS | 13 #if SK_SUPPORT_GPU && SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
14 | 14 |
15 #include "GrBackendEffectFactory.h" | 15 #include "GrBackendProcessorFactory.h" |
16 #include "GrContextFactory.h" | 16 #include "GrContextFactory.h" |
17 #include "effects/GrConfigConversionEffect.h" | 17 #include "effects/GrConfigConversionEffect.h" |
18 #include "gl/GrGLPathRendering.h" | 18 #include "gl/GrGLPathRendering.h" |
19 #include "gl/GrGpuGL.h" | 19 #include "gl/GrGpuGL.h" |
20 #include "SkChecksum.h" | 20 #include "SkChecksum.h" |
21 #include "SkRandom.h" | 21 #include "SkRandom.h" |
22 #include "Test.h" | 22 #include "Test.h" |
23 | 23 |
24 static void get_stage_stats(const GrEffectStage stage, bool* readsDst, | 24 static void get_stage_stats(const GrFragmentStage stage, bool* readsDst, |
25 bool* readsFragPosition, bool* requiresVertexShader)
{ | 25 bool* readsFragPosition, bool* requiresVertexShader)
{ |
26 if (stage.getEffect()->willReadDstColor()) { | 26 if (stage.getFragmentProcessor()->willReadDstColor()) { |
27 *readsDst = true; | 27 *readsDst = true; |
28 } | 28 } |
29 if (stage.getEffect()->willReadFragmentPosition()) { | 29 if (stage.getProcessor()->willReadFragmentPosition()) { |
30 *readsFragPosition = true; | 30 *readsFragPosition = true; |
31 } | 31 } |
32 if (stage.getEffect()->requiresVertexShader()) { | |
33 *requiresVertexShader = true; | |
34 } | |
35 } | 32 } |
36 | 33 |
37 bool GrGLProgramDesc::setRandom(SkRandom* random, | 34 bool GrGLProgramDesc::setRandom(SkRandom* random, |
38 const GrGpuGL* gpu, | 35 const GrGpuGL* gpu, |
39 const GrRenderTarget* dstRenderTarget, | 36 const GrRenderTarget* dstRenderTarget, |
40 const GrTexture* dstCopyTexture, | 37 const GrTexture* dstCopyTexture, |
41 const GrEffectStage* geometryProcessor, | 38 const GrGeometryStage* geometryProcessor, |
42 const GrEffectStage* stages[], | 39 const GrFragmentStage* stages[], |
43 int numColorStages, | 40 int numColorStages, |
44 int numCoverageStages, | 41 int numCoverageStages, |
45 int currAttribIndex) { | 42 int currAttribIndex) { |
46 bool useLocalCoords = random->nextBool() && currAttribIndex < GrDrawState::k
MaxVertexAttribCnt; | 43 bool useLocalCoords = random->nextBool() && currAttribIndex < GrDrawState::k
MaxVertexAttribCnt; |
47 | 44 |
48 int numStages = numColorStages + numCoverageStages; | 45 int numStages = numColorStages + numCoverageStages; |
49 fKey.reset(); | 46 fKey.reset(); |
50 | 47 |
51 GR_STATIC_ASSERT(0 == kEffectKeyOffsetsAndLengthOffset % sizeof(uint32_t)); | 48 GR_STATIC_ASSERT(0 == kEffectKeyOffsetsAndLengthOffset % sizeof(uint32_t)); |
52 | 49 |
53 // Make room for everything up to and including the array of offsets to effe
ct keys. | 50 // Make room for everything up to and including the array of offsets to effe
ct keys. |
54 fKey.push_back_n(kEffectKeyOffsetsAndLengthOffset + 2 * sizeof(uint16_t) * (
numStages + | 51 fKey.push_back_n(kEffectKeyOffsetsAndLengthOffset + 2 * sizeof(uint16_t) * (
numStages + |
55 (geometryProcessor ? 1 : 0))); | 52 (geometryProcessor ? 1 : 0))); |
56 | 53 |
57 bool dstRead = false; | 54 bool dstRead = false; |
58 bool fragPos = false; | 55 bool fragPos = false; |
59 bool vertexShader = SkToBool(geometryProcessor); | 56 bool vertexShader = SkToBool(geometryProcessor); |
60 int offset = 0; | 57 int offset = 0; |
61 if (geometryProcessor) { | 58 if (geometryProcessor) { |
62 const GrEffectStage* stage = geometryProcessor; | 59 const GrGeometryStage* stage = geometryProcessor; |
63 uint16_t* offsetAndSize = reinterpret_cast<uint16_t*>(fKey.begin() + | 60 uint16_t* offsetAndSize = reinterpret_cast<uint16_t*>(fKey.begin() + |
64 kEffectKeyOffsetsA
ndLengthOffset + | 61 kEffectKeyOffsetsA
ndLengthOffset + |
65 offset * 2 * sizeo
f(uint16_t)); | 62 offset * 2 * sizeo
f(uint16_t)); |
66 uint32_t effectKeyOffset = fKey.count(); | 63 uint32_t effectKeyOffset = fKey.count(); |
67 if (effectKeyOffset > SK_MaxU16) { | 64 if (effectKeyOffset > SK_MaxU16) { |
68 fKey.reset(); | 65 fKey.reset(); |
69 return false; | 66 return false; |
70 } | 67 } |
71 GrEffectKeyBuilder b(&fKey); | 68 GrProcessorKeyBuilder b(&fKey); |
72 uint16_t effectKeySize; | 69 uint16_t effectKeySize; |
73 if (!GetEffectKey(*stage, gpu->glCaps(), useLocalCoords, &b, &effectKeyS
ize)) { | 70 if (!GetProcessorKey(*stage, gpu->glCaps(), useLocalCoords, &b, &effectK
eySize)) { |
74 fKey.reset(); | 71 fKey.reset(); |
75 return false; | 72 return false; |
76 } | 73 } |
77 get_stage_stats(*stage, &dstRead, &fragPos, &vertexShader); | 74 vertexShader = true; |
| 75 fragPos = stage->getProcessor()->willReadFragmentPosition(); |
78 offsetAndSize[0] = effectKeyOffset; | 76 offsetAndSize[0] = effectKeyOffset; |
79 offsetAndSize[1] = effectKeySize; | 77 offsetAndSize[1] = effectKeySize; |
80 offset++; | 78 offset++; |
81 } | 79 } |
82 | 80 |
83 for (int s = 0; s < numStages; ++s, ++offset) { | 81 for (int s = 0; s < numStages; ++s, ++offset) { |
84 const GrEffectStage* stage = stages[s]; | 82 const GrFragmentStage* stage = stages[s]; |
85 uint16_t* offsetAndSize = reinterpret_cast<uint16_t*>(fKey.begin() + | 83 uint16_t* offsetAndSize = reinterpret_cast<uint16_t*>(fKey.begin() + |
86 kEffectKeyOffsetsA
ndLengthOffset + | 84 kEffectKeyOffsetsA
ndLengthOffset + |
87 offset * 2 * sizeo
f(uint16_t)); | 85 offset * 2 * sizeo
f(uint16_t)); |
88 uint32_t effectKeyOffset = fKey.count(); | 86 uint32_t effectKeyOffset = fKey.count(); |
89 if (effectKeyOffset > SK_MaxU16) { | 87 if (effectKeyOffset > SK_MaxU16) { |
90 fKey.reset(); | 88 fKey.reset(); |
91 return false; | 89 return false; |
92 } | 90 } |
93 GrEffectKeyBuilder b(&fKey); | 91 GrProcessorKeyBuilder b(&fKey); |
94 uint16_t effectKeySize; | 92 uint16_t effectKeySize; |
95 if (!GetEffectKey(*stages[s], gpu->glCaps(), useLocalCoords, &b, &effect
KeySize)) { | 93 if (!GetProcessorKey(*stages[s], gpu->glCaps(), useLocalCoords, &b, &eff
ectKeySize)) { |
96 fKey.reset(); | 94 fKey.reset(); |
97 return false; | 95 return false; |
98 } | 96 } |
99 get_stage_stats(*stage, &dstRead, &fragPos, &vertexShader); | 97 get_stage_stats(*stage, &dstRead, &fragPos, &vertexShader); |
100 offsetAndSize[0] = effectKeyOffset; | 98 offsetAndSize[0] = effectKeyOffset; |
101 offsetAndSize[1] = effectKeySize; | 99 offsetAndSize[1] = effectKeySize; |
102 } | 100 } |
103 | 101 |
104 KeyHeader* header = this->header(); | 102 KeyHeader* header = this->header(); |
105 memset(header, 0, kHeaderSize); | 103 memset(header, 0, kHeaderSize); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 this->finalize(); | 171 this->finalize(); |
174 return true; | 172 return true; |
175 } | 173 } |
176 | 174 |
177 // TODO clean this up, we have to do this to test geometry processors but there
has got to be | 175 // TODO clean this up, we have to do this to test geometry processors but there
has got to be |
178 // a better way. In the mean time, we actually fill out these generic vertex at
tribs below with | 176 // a better way. In the mean time, we actually fill out these generic vertex at
tribs below with |
179 // the correct vertex attribs from the GP. We have to ensure, however, we don't
try to add more | 177 // the correct vertex attribs from the GP. We have to ensure, however, we don't
try to add more |
180 // than two attributes. | 178 // than two attributes. |
181 GrVertexAttrib genericVertexAttribs[] = { | 179 GrVertexAttrib genericVertexAttribs[] = { |
182 { kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding }, | 180 { kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding }, |
183 { kVec2f_GrVertexAttribType, 0, kEffect_GrVertexAttribBinding }, | 181 { kVec2f_GrVertexAttribType, 0, kGeometryProcessor_GrVertexAttribBinding }
, |
184 { kVec2f_GrVertexAttribType, 0, kEffect_GrVertexAttribBinding } | 182 { kVec2f_GrVertexAttribType, 0, kGeometryProcessor_GrVertexAttribBinding } |
185 }; | 183 }; |
186 | 184 |
187 /* | 185 /* |
188 * convert sl type to vertexattrib type, not a complete implementation, only use
for debugging | 186 * convert sl type to vertexattrib type, not a complete implementation, only use
for debugging |
189 */ | 187 */ |
190 GrVertexAttribType convert_sltype_to_attribtype(GrSLType type) { | 188 GrVertexAttribType convert_sltype_to_attribtype(GrSLType type) { |
191 switch (type) { | 189 switch (type) { |
192 case kFloat_GrSLType: | 190 case kFloat_GrSLType: |
193 return kFloat_GrVertexAttribType; | 191 return kFloat_GrVertexAttribType; |
194 case kVec2f_GrSLType: | 192 case kVec2f_GrSLType: |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 GrGLProgramDesc pdesc; | 237 GrGLProgramDesc pdesc; |
240 | 238 |
241 int currAttribIndex = 1; // we need to always leave room for position | 239 int currAttribIndex = 1; // we need to always leave room for position |
242 int currTextureCoordSet = 0; | 240 int currTextureCoordSet = 0; |
243 GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()}; | 241 GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()}; |
244 | 242 |
245 int numStages = random.nextULessThan(maxStages + 1); | 243 int numStages = random.nextULessThan(maxStages + 1); |
246 int numColorStages = random.nextULessThan(numStages + 1); | 244 int numColorStages = random.nextULessThan(numStages + 1); |
247 int numCoverageStages = numStages - numColorStages; | 245 int numCoverageStages = numStages - numColorStages; |
248 | 246 |
249 SkAutoSTMalloc<8, const GrEffectStage*> stages(numStages); | 247 SkAutoSTMalloc<8, const GrFragmentStage*> stages(numStages); |
250 | 248 |
251 bool useFixedFunctionPathRendering = this->glCaps().pathRenderingSupport
() && | 249 bool useFixedFunctionPathRendering = this->glCaps().pathRenderingSupport
() && |
252 this->glPathRendering()->texturingMode() == GrGLPathRendering::Fixed
Function_TexturingMode && | 250 this->glPathRendering()->texturingMode() == GrGLPathRendering::Fixed
Function_TexturingMode && |
253 random.nextBool(); | 251 random.nextBool(); |
254 | 252 |
255 SkAutoTDelete<GrEffectStage> geometryProcessor; | 253 SkAutoTDelete<GrGeometryStage> geometryProcessor; |
256 bool hasGeometryProcessor = useFixedFunctionPathRendering ? false : rand
om.nextBool(); | 254 bool hasGeometryProcessor = false;//useFixedFunctionPathRendering ? fals
e : random.nextBool(); |
257 if (hasGeometryProcessor) { | 255 if (hasGeometryProcessor) { |
258 while (true) { | 256 while (true) { |
259 SkAutoTUnref<const GrEffect> effect(GrEffectTestFactory::CreateS
tage( | 257 SkAutoTUnref<const GrGeometryProcessor> effect( |
260
&random, | 258 GrProcessorTestFactory<GrGeometryProcessor>::CreateStage
(&random, this->getContext(), *this->caps(), |
261
this->getContext(), | 259 dummyTextures)); |
262
*this->caps(), | |
263
dummyTextures)); | |
264 SkASSERT(effect); | 260 SkASSERT(effect); |
265 // Only geometryProcessor can use vertex shader | 261 // Only geometryProcessor can use vertex shader |
266 if (!effect->requiresVertexShader()) { | 262 GrGeometryStage* stage = SkNEW_ARGS(GrGeometryStage, (effect.get
())); |
267 continue; | |
268 } | |
269 | |
270 GrEffectStage* stage = SkNEW_ARGS(GrEffectStage, (effect.get()))
; | |
271 geometryProcessor.reset(stage); | 263 geometryProcessor.reset(stage); |
272 | 264 |
273 // we have to set dummy vertex attribs | 265 // we have to set dummy vertex attribs |
274 const GrEffect::VertexAttribArray& v = effect->getVertexAttribs(
); | 266 const GrGeometryProcessor::VertexAttribArray& v = effect->getVer
texAttribs(); |
275 int numVertexAttribs = v.count(); | 267 int numVertexAttribs = v.count(); |
276 | 268 |
277 SkASSERT(GrEffect::kMaxVertexAttribs == 2 && | 269 SkASSERT(GrGeometryProcessor::kMaxVertexAttribs == 2 && |
278 GrEffect::kMaxVertexAttribs >= numVertexAttribs); | 270 GrGeometryProcessor::kMaxVertexAttribs >= numVertexAttr
ibs); |
279 size_t runningStride = GrVertexAttribTypeSize(genericVertexAttri
bs[0].fType); | 271 size_t runningStride = GrVertexAttribTypeSize(genericVertexAttri
bs[0].fType); |
280 for (int i = 0; i < numVertexAttribs; i++) { | 272 for (int i = 0; i < numVertexAttribs; i++) { |
281 genericVertexAttribs[i + 1].fOffset = runningStride; | 273 genericVertexAttribs[i + 1].fOffset = runningStride; |
282 genericVertexAttribs[i + 1].fType = | 274 genericVertexAttribs[i + 1].fType = |
283 convert_sltype_to_attribtype(v[i].getType()); | 275 convert_sltype_to_attribtype(v[i].getType()); |
284 runningStride += GrVertexAttribTypeSize(genericVertexAttribs
[i + 1].fType); | 276 runningStride += GrVertexAttribTypeSize(genericVertexAttribs
[i + 1].fType); |
285 } | 277 } |
286 | 278 |
287 // update the vertex attributes with the ds | 279 // update the vertex attributes with the ds |
288 GrDrawState* ds = this->drawState(); | 280 GrDrawState* ds = this->drawState(); |
289 ds->setVertexAttribs<genericVertexAttribs>(numVertexAttribs + 1,
runningStride); | 281 ds->setVertexAttribs<genericVertexAttribs>(numVertexAttribs + 1,
runningStride); |
290 currAttribIndex = numVertexAttribs + 1; | 282 currAttribIndex = numVertexAttribs + 1; |
291 break; | 283 break; |
292 } | 284 } |
293 } | 285 } |
294 for (int s = 0; s < numStages;) { | 286 for (int s = 0; s < numStages;) { |
295 SkAutoTUnref<const GrEffect> effect(GrEffectTestFactory::CreateStage
( | 287 SkAutoTUnref<const GrFragmentProcessor> effect( |
| 288 GrProcessorTestFactory<GrFragmentProcessor>::CreateStage( |
296 &ran
dom, | 289 &ran
dom, |
297 this
->getContext(), | 290 this
->getContext(), |
298 *thi
s->caps(), | 291 *thi
s->caps(), |
299 dumm
yTextures)); | 292 dumm
yTextures)); |
300 SkASSERT(effect); | 293 SkASSERT(effect); |
301 | 294 |
302 // Only geometryProcessor can use vertex shader | |
303 if (effect->requiresVertexShader()) { | |
304 continue; | |
305 } | |
306 | |
307 // If adding this effect would exceed the max texture coord set coun
t then generate a | 295 // If adding this effect would exceed the max texture coord set coun
t then generate a |
308 // new random effect. | 296 // new random effect. |
309 if (useFixedFunctionPathRendering) { | 297 if (useFixedFunctionPathRendering) { |
310 int numTransforms = effect->numTransforms(); | 298 int numTransforms = effect->numTransforms(); |
311 if (currTextureCoordSet + numTransforms > this->glCaps().maxFixe
dFunctionTextureCoords()) { | 299 if (currTextureCoordSet + numTransforms > this->glCaps().maxFixe
dFunctionTextureCoords()) { |
312 continue; | 300 continue; |
313 } | 301 } |
314 currTextureCoordSet += numTransforms; | 302 currTextureCoordSet += numTransforms; |
315 } | 303 } |
316 GrEffectStage* stage = SkNEW_ARGS(GrEffectStage, (effect.get())); | 304 GrFragmentStage* stage = SkNEW_ARGS(GrFragmentStage, (effect.get()))
; |
317 | 305 |
318 stages[s] = stage; | 306 stages[s] = stage; |
319 ++s; | 307 ++s; |
320 } | 308 } |
321 const GrTexture* dstTexture = random.nextBool() ? dummyTextures[0] : dum
myTextures[1]; | 309 const GrTexture* dstTexture = random.nextBool() ? dummyTextures[0] : dum
myTextures[1]; |
322 if (!pdesc.setRandom(&random, | 310 if (!pdesc.setRandom(&random, |
323 this, | 311 this, |
324 dummyTextures[0]->asRenderTarget(), | 312 dummyTextures[0]->asRenderTarget(), |
325 dstTexture, | 313 dstTexture, |
326 geometryProcessor.get(), | 314 geometryProcessor.get(), |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 SkRect::MakeWH(SK_Scalar1, SK_Scalar1), SK_Scalar1)); | 373 SkRect::MakeWH(SK_Scalar1, SK_Scalar1), SK_Scalar1)); |
386 GrConfigConversionEffect::Create(NULL, | 374 GrConfigConversionEffect::Create(NULL, |
387 false, | 375 false, |
388 GrConfigConversionEffect::kNone_PMConversio
n, | 376 GrConfigConversionEffect::kNone_PMConversio
n, |
389 SkMatrix::I()); | 377 SkMatrix::I()); |
390 SkScalar matrix[20]; | 378 SkScalar matrix[20]; |
391 SkAutoTUnref<SkColorMatrixFilter> cmf(SkColorMatrixFilter::Create(matrix)); | 379 SkAutoTUnref<SkColorMatrixFilter> cmf(SkColorMatrixFilter::Create(matrix)); |
392 } | 380 } |
393 | 381 |
394 #endif | 382 #endif |
OLD | NEW |