| 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 "GrOptDrawState.h" | 17 #include "GrOptDrawState.h" |
| 18 #include "effects/GrConfigConversionEffect.h" | 18 #include "effects/GrConfigConversionEffect.h" |
| 19 #include "gl/GrGLPathRendering.h" | 19 #include "gl/GrGLPathRendering.h" |
| 20 #include "gl/GrGpuGL.h" | 20 #include "gl/GrGpuGL.h" |
| 21 #include "SkChecksum.h" | 21 #include "SkChecksum.h" |
| 22 #include "SkRandom.h" | 22 #include "SkRandom.h" |
| 23 #include "Test.h" | 23 #include "Test.h" |
| 24 | 24 |
| 25 static void get_stage_stats(const GrEffectStage stage, bool* readsDst, | 25 static void get_stage_stats(const GrFragmentStage stage, bool* readsDst, |
| 26 bool* readsFragPosition, bool* requiresVertexShader)
{ | 26 bool* readsFragPosition, bool* requiresVertexShader)
{ |
| 27 if (stage.getEffect()->willReadDstColor()) { | 27 if (stage.getFragmentProcessor()->willReadDstColor()) { |
| 28 *readsDst = true; | 28 *readsDst = true; |
| 29 } | 29 } |
| 30 if (stage.getEffect()->willReadFragmentPosition()) { | 30 if (stage.getProcessor()->willReadFragmentPosition()) { |
| 31 *readsFragPosition = true; | 31 *readsFragPosition = true; |
| 32 } | 32 } |
| 33 if (stage.getEffect()->requiresVertexShader()) { | |
| 34 *requiresVertexShader = true; | |
| 35 } | |
| 36 } | 33 } |
| 37 | 34 |
| 38 bool GrGLProgramDesc::setRandom(SkRandom* random, | 35 bool GrGLProgramDesc::setRandom(SkRandom* random, |
| 39 GrGpuGL* gpu, | 36 GrGpuGL* gpu, |
| 40 const GrRenderTarget* dstRenderTarget, | 37 const GrRenderTarget* dstRenderTarget, |
| 41 const GrTexture* dstCopyTexture, | 38 const GrTexture* dstCopyTexture, |
| 42 const GrEffectStage* geometryProcessor, | 39 const GrGeometryStage* geometryProcessor, |
| 43 const GrEffectStage* stages[], | 40 const GrFragmentStage* stages[], |
| 44 int numColorStages, | 41 int numColorStages, |
| 45 int numCoverageStages, | 42 int numCoverageStages, |
| 46 int currAttribIndex, | 43 int currAttribIndex, |
| 47 GrGpu::DrawType drawType) { | 44 GrGpu::DrawType drawType) { |
| 48 bool isPathRendering = GrGpu::IsPathRenderingDrawType(drawType); | 45 bool isPathRendering = GrGpu::IsPathRenderingDrawType(drawType); |
| 49 bool useLocalCoords = !isPathRendering && | 46 bool useLocalCoords = !isPathRendering && |
| 50 random->nextBool() && | 47 random->nextBool() && |
| 51 currAttribIndex < GrDrawState::kMaxVertexAttribCnt; | 48 currAttribIndex < GrDrawState::kMaxVertexAttribCnt; |
| 52 | 49 |
| 53 int numStages = numColorStages + numCoverageStages; | 50 int numStages = numColorStages + numCoverageStages; |
| 54 fKey.reset(); | 51 fKey.reset(); |
| 55 | 52 |
| 56 GR_STATIC_ASSERT(0 == kEffectKeyOffsetsAndLengthOffset % sizeof(uint32_t)); | 53 GR_STATIC_ASSERT(0 == kEffectKeyOffsetsAndLengthOffset % sizeof(uint32_t)); |
| 57 | 54 |
| 58 // Make room for everything up to and including the array of offsets to effe
ct keys. | 55 // Make room for everything up to and including the array of offsets to effe
ct keys. |
| 59 fKey.push_back_n(kEffectKeyOffsetsAndLengthOffset + 2 * sizeof(uint16_t) * (
numStages + | 56 fKey.push_back_n(kEffectKeyOffsetsAndLengthOffset + 2 * sizeof(uint16_t) * (
numStages + |
| 60 (geometryProcessor ? 1 : 0))); | 57 (geometryProcessor ? 1 : 0))); |
| 61 | 58 |
| 62 bool dstRead = false; | 59 bool dstRead = false; |
| 63 bool fragPos = false; | 60 bool fragPos = false; |
| 64 bool vertexShader = SkToBool(geometryProcessor); | 61 bool vertexShader = SkToBool(geometryProcessor); |
| 65 int offset = 0; | 62 int offset = 0; |
| 66 if (geometryProcessor) { | 63 if (geometryProcessor) { |
| 67 const GrEffectStage* stage = geometryProcessor; | 64 const GrGeometryStage* stage = geometryProcessor; |
| 68 uint16_t* offsetAndSize = reinterpret_cast<uint16_t*>(fKey.begin() + | 65 uint16_t* offsetAndSize = reinterpret_cast<uint16_t*>(fKey.begin() + |
| 69 kEffectKeyOffsetsA
ndLengthOffset + | 66 kEffectKeyOffsetsA
ndLengthOffset + |
| 70 offset * 2 * sizeo
f(uint16_t)); | 67 offset * 2 * sizeo
f(uint16_t)); |
| 71 uint32_t effectKeyOffset = fKey.count(); | 68 uint32_t effectKeyOffset = fKey.count(); |
| 72 if (effectKeyOffset > SK_MaxU16) { | 69 if (effectKeyOffset > SK_MaxU16) { |
| 73 fKey.reset(); | 70 fKey.reset(); |
| 74 return false; | 71 return false; |
| 75 } | 72 } |
| 76 GrEffectKeyBuilder b(&fKey); | 73 GrProcessorKeyBuilder b(&fKey); |
| 77 uint16_t effectKeySize; | 74 uint16_t effectKeySize; |
| 78 if (!GetEffectKey(*stage, gpu->glCaps(), useLocalCoords, &b, &effectKeyS
ize)) { | 75 if (!GetProcessorKey(*stage, gpu->glCaps(), useLocalCoords, &b, &effectK
eySize)) { |
| 79 fKey.reset(); | 76 fKey.reset(); |
| 80 return false; | 77 return false; |
| 81 } | 78 } |
| 82 get_stage_stats(*stage, &dstRead, &fragPos, &vertexShader); | 79 vertexShader = true; |
| 80 fragPos = stage->getProcessor()->willReadFragmentPosition(); |
| 83 offsetAndSize[0] = effectKeyOffset; | 81 offsetAndSize[0] = effectKeyOffset; |
| 84 offsetAndSize[1] = effectKeySize; | 82 offsetAndSize[1] = effectKeySize; |
| 85 offset++; | 83 offset++; |
| 86 } | 84 } |
| 87 | 85 |
| 88 for (int s = 0; s < numStages; ++s, ++offset) { | 86 for (int s = 0; s < numStages; ++s, ++offset) { |
| 89 const GrEffectStage* stage = stages[s]; | 87 const GrFragmentStage* stage = stages[s]; |
| 90 uint16_t* offsetAndSize = reinterpret_cast<uint16_t*>(fKey.begin() + | 88 uint16_t* offsetAndSize = reinterpret_cast<uint16_t*>(fKey.begin() + |
| 91 kEffectKeyOffsetsA
ndLengthOffset + | 89 kEffectKeyOffsetsA
ndLengthOffset + |
| 92 offset * 2 * sizeo
f(uint16_t)); | 90 offset * 2 * sizeo
f(uint16_t)); |
| 93 uint32_t effectKeyOffset = fKey.count(); | 91 uint32_t effectKeyOffset = fKey.count(); |
| 94 if (effectKeyOffset > SK_MaxU16) { | 92 if (effectKeyOffset > SK_MaxU16) { |
| 95 fKey.reset(); | 93 fKey.reset(); |
| 96 return false; | 94 return false; |
| 97 } | 95 } |
| 98 GrEffectKeyBuilder b(&fKey); | 96 GrProcessorKeyBuilder b(&fKey); |
| 99 uint16_t effectKeySize; | 97 uint16_t effectKeySize; |
| 100 if (!GetEffectKey(*stages[s], gpu->glCaps(), useLocalCoords, &b, &effect
KeySize)) { | 98 if (!GetProcessorKey(*stages[s], gpu->glCaps(), useLocalCoords, &b, &eff
ectKeySize)) { |
| 101 fKey.reset(); | 99 fKey.reset(); |
| 102 return false; | 100 return false; |
| 103 } | 101 } |
| 104 get_stage_stats(*stage, &dstRead, &fragPos, &vertexShader); | 102 get_stage_stats(*stage, &dstRead, &fragPos, &vertexShader); |
| 105 offsetAndSize[0] = effectKeyOffset; | 103 offsetAndSize[0] = effectKeyOffset; |
| 106 offsetAndSize[1] = effectKeySize; | 104 offsetAndSize[1] = effectKeySize; |
| 107 } | 105 } |
| 108 | 106 |
| 109 KeyHeader* header = this->header(); | 107 KeyHeader* header = this->header(); |
| 110 memset(header, 0, kHeaderSize); | 108 memset(header, 0, kHeaderSize); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 this->finalize(); | 181 this->finalize(); |
| 184 return true; | 182 return true; |
| 185 } | 183 } |
| 186 | 184 |
| 187 // TODO clean this up, we have to do this to test geometry processors but there
has got to be | 185 // TODO clean this up, we have to do this to test geometry processors but there
has got to be |
| 188 // a better way. In the mean time, we actually fill out these generic vertex at
tribs below with | 186 // a better way. In the mean time, we actually fill out these generic vertex at
tribs below with |
| 189 // the correct vertex attribs from the GP. We have to ensure, however, we don't
try to add more | 187 // the correct vertex attribs from the GP. We have to ensure, however, we don't
try to add more |
| 190 // than two attributes. | 188 // than two attributes. |
| 191 GrVertexAttrib genericVertexAttribs[] = { | 189 GrVertexAttrib genericVertexAttribs[] = { |
| 192 { kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding }, | 190 { kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding }, |
| 193 { kVec2f_GrVertexAttribType, 0, kEffect_GrVertexAttribBinding }, | 191 { kVec2f_GrVertexAttribType, 0, kGeometryProcessor_GrVertexAttribBinding }
, |
| 194 { kVec2f_GrVertexAttribType, 0, kEffect_GrVertexAttribBinding } | 192 { kVec2f_GrVertexAttribType, 0, kGeometryProcessor_GrVertexAttribBinding } |
| 195 }; | 193 }; |
| 196 | 194 |
| 197 /* | 195 /* |
| 198 * convert sl type to vertexattrib type, not a complete implementation, only use
for debugging | 196 * convert sl type to vertexattrib type, not a complete implementation, only use
for debugging |
| 199 */ | 197 */ |
| 200 GrVertexAttribType convert_sltype_to_attribtype(GrSLType type) { | 198 GrVertexAttribType convert_sltype_to_attribtype(GrSLType type) { |
| 201 switch (type) { | 199 switch (type) { |
| 202 case kFloat_GrSLType: | 200 case kFloat_GrSLType: |
| 203 return kFloat_GrVertexAttribType; | 201 return kFloat_GrVertexAttribType; |
| 204 case kVec2f_GrSLType: | 202 case kVec2f_GrSLType: |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 GrGLProgramDesc pdesc; | 247 GrGLProgramDesc pdesc; |
| 250 | 248 |
| 251 int currAttribIndex = 1; // we need to always leave room for position | 249 int currAttribIndex = 1; // we need to always leave room for position |
| 252 int currTextureCoordSet = 0; | 250 int currTextureCoordSet = 0; |
| 253 GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()}; | 251 GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()}; |
| 254 | 252 |
| 255 int numStages = random.nextULessThan(maxStages + 1); | 253 int numStages = random.nextULessThan(maxStages + 1); |
| 256 int numColorStages = random.nextULessThan(numStages + 1); | 254 int numColorStages = random.nextULessThan(numStages + 1); |
| 257 int numCoverageStages = numStages - numColorStages; | 255 int numCoverageStages = numStages - numColorStages; |
| 258 | 256 |
| 259 SkAutoSTMalloc<8, const GrEffectStage*> stages(numStages); | 257 SkAutoSTMalloc<8, const GrFragmentStage*> stages(numStages); |
| 260 | 258 |
| 261 bool usePathRendering = this->glCaps().pathRenderingSupport() && random.
nextBool(); | 259 bool usePathRendering = this->glCaps().pathRenderingSupport() && random.
nextBool(); |
| 262 | 260 |
| 263 GrGpu::DrawType drawType = usePathRendering ? GrGpu::kDrawPath_DrawType
: | 261 GrGpu::DrawType drawType = usePathRendering ? GrGpu::kDrawPath_DrawType
: |
| 264 GrGpu::kDrawPoints_DrawTyp
e; | 262 GrGpu::kDrawPoints_DrawTyp
e; |
| 265 | 263 |
| 266 SkAutoTDelete<GrEffectStage> geometryProcessor; | 264 SkAutoTDelete<GrGeometryStage> geometryProcessor; |
| 267 bool hasGeometryProcessor = usePathRendering ? false : random.nextBool()
; | 265 bool hasGeometryProcessor = usePathRendering ? false : random.nextBool()
; |
| 268 if (hasGeometryProcessor) { | 266 if (hasGeometryProcessor) { |
| 269 while (true) { | 267 while (true) { |
| 270 SkAutoTUnref<const GrEffect> effect(GrEffectTestFactory::CreateS
tage( | 268 SkAutoTUnref<const GrGeometryProcessor> effect( |
| 271
&random, | 269 GrProcessorTestFactory<GrGeometryProcessor>::CreateStage
(&random, this->getContext(), *this->caps(), |
| 272
this->getContext(), | 270 dummyTextures)); |
| 273
*this->caps(), | |
| 274
dummyTextures)); | |
| 275 SkASSERT(effect); | 271 SkASSERT(effect); |
| 276 // Only geometryProcessor can use vertex shader | 272 // Only geometryProcessor can use vertex shader |
| 277 if (!effect->requiresVertexShader()) { | 273 GrGeometryStage* stage = SkNEW_ARGS(GrGeometryStage, (effect.get
())); |
| 278 continue; | |
| 279 } | |
| 280 | |
| 281 GrEffectStage* stage = SkNEW_ARGS(GrEffectStage, (effect.get()))
; | |
| 282 geometryProcessor.reset(stage); | 274 geometryProcessor.reset(stage); |
| 283 | 275 |
| 284 // we have to set dummy vertex attribs | 276 // we have to set dummy vertex attribs |
| 285 const GrEffect::VertexAttribArray& v = effect->getVertexAttribs(
); | 277 const GrGeometryProcessor::VertexAttribArray& v = effect->getVer
texAttribs(); |
| 286 int numVertexAttribs = v.count(); | 278 int numVertexAttribs = v.count(); |
| 287 | 279 |
| 288 SkASSERT(GrEffect::kMaxVertexAttribs == 2 && | 280 SkASSERT(GrGeometryProcessor::kMaxVertexAttribs == 2 && |
| 289 GrEffect::kMaxVertexAttribs >= numVertexAttribs); | 281 GrGeometryProcessor::kMaxVertexAttribs >= numVertexAttr
ibs); |
| 290 size_t runningStride = GrVertexAttribTypeSize(genericVertexAttri
bs[0].fType); | 282 size_t runningStride = GrVertexAttribTypeSize(genericVertexAttri
bs[0].fType); |
| 291 for (int i = 0; i < numVertexAttribs; i++) { | 283 for (int i = 0; i < numVertexAttribs; i++) { |
| 292 genericVertexAttribs[i + 1].fOffset = runningStride; | 284 genericVertexAttribs[i + 1].fOffset = runningStride; |
| 293 genericVertexAttribs[i + 1].fType = | 285 genericVertexAttribs[i + 1].fType = |
| 294 convert_sltype_to_attribtype(v[i].getType()); | 286 convert_sltype_to_attribtype(v[i].getType()); |
| 295 runningStride += GrVertexAttribTypeSize(genericVertexAttribs
[i + 1].fType); | 287 runningStride += GrVertexAttribTypeSize(genericVertexAttribs
[i + 1].fType); |
| 296 } | 288 } |
| 297 | 289 |
| 298 // update the vertex attributes with the ds | 290 // update the vertex attributes with the ds |
| 299 GrDrawState* ds = this->drawState(); | 291 GrDrawState* ds = this->drawState(); |
| 300 ds->setVertexAttribs<genericVertexAttribs>(numVertexAttribs + 1,
runningStride); | 292 ds->setVertexAttribs<genericVertexAttribs>(numVertexAttribs + 1,
runningStride); |
| 301 currAttribIndex = numVertexAttribs + 1; | 293 currAttribIndex = numVertexAttribs + 1; |
| 302 break; | 294 break; |
| 303 } | 295 } |
| 304 } | 296 } |
| 305 for (int s = 0; s < numStages;) { | 297 for (int s = 0; s < numStages;) { |
| 306 SkAutoTUnref<const GrEffect> effect(GrEffectTestFactory::CreateStage
( | 298 SkAutoTUnref<const GrFragmentProcessor> effect( |
| 299 GrProcessorTestFactory<GrFragmentProcessor>::CreateStage( |
| 307 &ran
dom, | 300 &ran
dom, |
| 308 this
->getContext(), | 301 this
->getContext(), |
| 309 *thi
s->caps(), | 302 *thi
s->caps(), |
| 310 dumm
yTextures)); | 303 dumm
yTextures)); |
| 311 SkASSERT(effect); | 304 SkASSERT(effect); |
| 312 | 305 |
| 313 // Only geometryProcessor can use vertex shader | |
| 314 if (effect->requiresVertexShader()) { | |
| 315 continue; | |
| 316 } | |
| 317 | |
| 318 // If adding this effect would exceed the max texture coord set coun
t then generate a | 306 // If adding this effect would exceed the max texture coord set coun
t then generate a |
| 319 // new random effect. | 307 // new random effect. |
| 320 if (usePathRendering && this->glPathRendering()->texturingMode() == | 308 if (usePathRendering && this->glPathRendering()->texturingMode() == |
| 321 GrGLPathRendering::FixedFunction_TexturingMo
de) {; | 309 GrGLPathRendering::FixedFunction_TexturingMo
de) {; |
| 322 int numTransforms = effect->numTransforms(); | 310 int numTransforms = effect->numTransforms(); |
| 323 if (currTextureCoordSet + numTransforms > this->glCaps().maxFixe
dFunctionTextureCoords()) { | 311 if (currTextureCoordSet + numTransforms > this->glCaps().maxFixe
dFunctionTextureCoords()) { |
| 324 continue; | 312 continue; |
| 325 } | 313 } |
| 326 currTextureCoordSet += numTransforms; | 314 currTextureCoordSet += numTransforms; |
| 327 } | 315 } |
| 328 GrEffectStage* stage = SkNEW_ARGS(GrEffectStage, (effect.get())); | 316 GrFragmentStage* stage = SkNEW_ARGS(GrFragmentStage, (effect.get()))
; |
| 329 | 317 |
| 330 stages[s] = stage; | 318 stages[s] = stage; |
| 331 ++s; | 319 ++s; |
| 332 } | 320 } |
| 333 const GrTexture* dstTexture = random.nextBool() ? dummyTextures[0] : dum
myTextures[1]; | 321 const GrTexture* dstTexture = random.nextBool() ? dummyTextures[0] : dum
myTextures[1]; |
| 334 if (!pdesc.setRandom(&random, | 322 if (!pdesc.setRandom(&random, |
| 335 this, | 323 this, |
| 336 dummyTextures[0]->asRenderTarget(), | 324 dummyTextures[0]->asRenderTarget(), |
| 337 dstTexture, | 325 dstTexture, |
| 338 geometryProcessor.get(), | 326 geometryProcessor.get(), |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 SkRect::MakeWH(SK_Scalar1, SK_Scalar1), SK_Scalar1)); | 386 SkRect::MakeWH(SK_Scalar1, SK_Scalar1), SK_Scalar1)); |
| 399 GrConfigConversionEffect::Create(NULL, | 387 GrConfigConversionEffect::Create(NULL, |
| 400 false, | 388 false, |
| 401 GrConfigConversionEffect::kNone_PMConversio
n, | 389 GrConfigConversionEffect::kNone_PMConversio
n, |
| 402 SkMatrix::I()); | 390 SkMatrix::I()); |
| 403 SkScalar matrix[20]; | 391 SkScalar matrix[20]; |
| 404 SkAutoTUnref<SkColorMatrixFilter> cmf(SkColorMatrixFilter::Create(matrix)); | 392 SkAutoTUnref<SkColorMatrixFilter> cmf(SkColorMatrixFilter::Create(matrix)); |
| 405 } | 393 } |
| 406 | 394 |
| 407 #endif | 395 #endif |
| OLD | NEW |