bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
bsalomon@google.com | d472620 | 2012-08-03 14:34:46 +0000 | [diff] [blame] | 9 | // This is a GPU-backend specific test. It relies on static intializers to work |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 10 | |
bsalomon@google.com | 2a48c3a | 2012-08-03 14:54:45 +0000 | [diff] [blame] | 11 | #include "SkTypes.h" |
| 12 | |
| 13 | #if SK_SUPPORT_GPU && SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
| 14 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 15 | #include "GrBackendProcessorFactory.h" |
bsalomon@google.com | 67b915d | 2013-02-04 16:13:32 +0000 | [diff] [blame] | 16 | #include "GrContextFactory.h" |
egdaniel | c064824 | 2014-09-22 13:17:02 -0700 | [diff] [blame] | 17 | #include "GrOptDrawState.h" |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 18 | #include "effects/GrConfigConversionEffect.h" |
joshualitt | fe1233c | 2014-10-07 12:16:35 -0700 | [diff] [blame^] | 19 | #include "gl/builders/GrGLProgramBuilder.h" |
kkinnunen | ec56e45 | 2014-08-25 22:21:16 -0700 | [diff] [blame] | 20 | #include "gl/GrGLPathRendering.h" |
tfarina@chromium.org | 8f6884a | 2014-01-24 20:56:26 +0000 | [diff] [blame] | 21 | #include "gl/GrGpuGL.h" |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 22 | #include "SkChecksum.h" |
tfarina@chromium.org | 223137f | 2012-11-21 22:38:36 +0000 | [diff] [blame] | 23 | #include "SkRandom.h" |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 24 | #include "Test.h" |
| 25 | |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 26 | static void get_stage_stats(const GrFragmentStage stage, bool* readsDst, |
| 27 | bool* readsFragPosition, bool* requiresVertexShader) { |
joshualitt | fe1233c | 2014-10-07 12:16:35 -0700 | [diff] [blame^] | 28 | if (stage.getProcessor()->willReadDstColor()) { |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 29 | *readsDst = true; |
joshualitt | bd769d0 | 2014-09-04 08:56:46 -0700 | [diff] [blame] | 30 | } |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 31 | if (stage.getProcessor()->willReadFragmentPosition()) { |
| 32 | *readsFragPosition = true; |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | bool GrGLProgramDesc::setRandom(SkRandom* random, |
| 37 | GrGpuGL* gpu, |
| 38 | const GrRenderTarget* dstRenderTarget, |
| 39 | const GrTexture* dstCopyTexture, |
| 40 | const GrGeometryStage* geometryProcessor, |
| 41 | const GrFragmentStage* stages[], |
| 42 | int numColorStages, |
| 43 | int numCoverageStages, |
| 44 | int currAttribIndex, |
| 45 | GrGpu::DrawType drawType) { |
| 46 | bool isPathRendering = GrGpu::IsPathRenderingDrawType(drawType); |
| 47 | bool useLocalCoords = !isPathRendering && |
| 48 | random->nextBool() && |
| 49 | currAttribIndex < GrDrawState::kMaxVertexAttribCnt; |
| 50 | |
| 51 | int numStages = numColorStages + numCoverageStages; |
| 52 | fKey.reset(); |
| 53 | |
| 54 | GR_STATIC_ASSERT(0 == kEffectKeyOffsetsAndLengthOffset % sizeof(uint32_t)); |
| 55 | |
| 56 | // Make room for everything up to and including the array of offsets to effect keys. |
| 57 | fKey.push_back_n(kEffectKeyOffsetsAndLengthOffset + 2 * sizeof(uint16_t) * (numStages + |
| 58 | (geometryProcessor ? 1 : 0))); |
| 59 | |
| 60 | bool dstRead = false; |
| 61 | bool fragPos = false; |
| 62 | bool vertexShader = SkToBool(geometryProcessor); |
| 63 | int offset = 0; |
| 64 | if (geometryProcessor) { |
| 65 | const GrGeometryStage* stage = geometryProcessor; |
| 66 | uint16_t* offsetAndSize = reinterpret_cast<uint16_t*>(fKey.begin() + |
| 67 | kEffectKeyOffsetsAndLengthOffset + |
| 68 | offset * 2 * sizeof(uint16_t)); |
| 69 | uint32_t effectKeyOffset = fKey.count(); |
| 70 | if (effectKeyOffset > SK_MaxU16) { |
| 71 | fKey.reset(); |
| 72 | return false; |
| 73 | } |
| 74 | GrProcessorKeyBuilder b(&fKey); |
| 75 | uint16_t effectKeySize; |
| 76 | if (!GetProcessorKey(*stage, gpu->glCaps(), useLocalCoords, &b, &effectKeySize)) { |
| 77 | fKey.reset(); |
| 78 | return false; |
| 79 | } |
| 80 | vertexShader = true; |
| 81 | fragPos = stage->getProcessor()->willReadFragmentPosition(); |
| 82 | offsetAndSize[0] = effectKeyOffset; |
| 83 | offsetAndSize[1] = effectKeySize; |
| 84 | offset++; |
| 85 | } |
| 86 | |
| 87 | for (int s = 0; s < numStages; ++s, ++offset) { |
| 88 | const GrFragmentStage* stage = stages[s]; |
| 89 | uint16_t* offsetAndSize = reinterpret_cast<uint16_t*>(fKey.begin() + |
| 90 | kEffectKeyOffsetsAndLengthOffset + |
| 91 | offset * 2 * sizeof(uint16_t)); |
| 92 | uint32_t effectKeyOffset = fKey.count(); |
| 93 | if (effectKeyOffset > SK_MaxU16) { |
| 94 | fKey.reset(); |
| 95 | return false; |
| 96 | } |
| 97 | GrProcessorKeyBuilder b(&fKey); |
| 98 | uint16_t effectKeySize; |
| 99 | if (!GetProcessorKey(*stages[s], gpu->glCaps(), useLocalCoords, &b, &effectKeySize)) { |
| 100 | fKey.reset(); |
| 101 | return false; |
| 102 | } |
| 103 | get_stage_stats(*stage, &dstRead, &fragPos, &vertexShader); |
| 104 | offsetAndSize[0] = effectKeyOffset; |
| 105 | offsetAndSize[1] = effectKeySize; |
| 106 | } |
| 107 | |
| 108 | KeyHeader* header = this->header(); |
| 109 | memset(header, 0, kHeaderSize); |
| 110 | header->fEmitsPointSize = random->nextBool(); |
| 111 | |
| 112 | header->fPositionAttributeIndex = 0; |
| 113 | |
| 114 | // if the effects have used up all off the available attributes, |
| 115 | // don't try to use color or coverage attributes as input |
| 116 | do { |
| 117 | header->fColorInput = static_cast<GrGLProgramDesc::ColorInput>( |
| 118 | random->nextULessThan(kColorInputCnt)); |
| 119 | } while ((GrDrawState::kMaxVertexAttribCnt <= currAttribIndex || isPathRendering) && |
| 120 | kAttribute_ColorInput == header->fColorInput); |
| 121 | header->fColorAttributeIndex = (header->fColorInput == kAttribute_ColorInput) ? |
| 122 | currAttribIndex++ : |
| 123 | -1; |
| 124 | |
| 125 | do { |
| 126 | header->fCoverageInput = static_cast<GrGLProgramDesc::ColorInput>( |
| 127 | random->nextULessThan(kColorInputCnt)); |
| 128 | } while ((GrDrawState::kMaxVertexAttribCnt <= currAttribIndex || isPathRendering) && |
| 129 | kAttribute_ColorInput == header->fCoverageInput); |
| 130 | header->fCoverageAttributeIndex = (header->fCoverageInput == kAttribute_ColorInput) ? |
| 131 | currAttribIndex++ : |
| 132 | -1; |
| 133 | bool useGS = random->nextBool(); |
| 134 | #if GR_GL_EXPERIMENTAL_GS |
| 135 | header->fExperimentalGS = gpu->caps()->geometryShaderSupport() && useGS; |
| 136 | #else |
| 137 | (void) useGS; |
| 138 | #endif |
| 139 | |
| 140 | header->fLocalCoordAttributeIndex = useLocalCoords ? currAttribIndex++ : -1; |
| 141 | |
| 142 | header->fColorEffectCnt = numColorStages; |
| 143 | header->fCoverageEffectCnt = numCoverageStages; |
| 144 | |
| 145 | if (dstRead) { |
| 146 | header->fDstReadKey = SkToU8(GrGLFragmentShaderBuilder::KeyForDstRead(dstCopyTexture, |
| 147 | gpu->glCaps())); |
| 148 | } else { |
| 149 | header->fDstReadKey = 0; |
| 150 | } |
| 151 | if (fragPos) { |
| 152 | header->fFragPosKey = SkToU8(GrGLFragmentShaderBuilder::KeyForFragmentPosition(dstRenderTarget, |
| 153 | gpu->glCaps())); |
| 154 | } else { |
| 155 | header->fFragPosKey = 0; |
| 156 | } |
| 157 | |
| 158 | header->fUseFragShaderOnly = isPathRendering && gpu->glPathRendering()->texturingMode() == |
| 159 | GrGLPathRendering::FixedFunction_TexturingMode; |
| 160 | header->fHasGeometryProcessor = vertexShader; |
| 161 | |
| 162 | GrOptDrawState::PrimaryOutputType primaryOutput; |
| 163 | GrOptDrawState::SecondaryOutputType secondaryOutput; |
| 164 | if (!dstRead) { |
| 165 | primaryOutput = GrOptDrawState::kModulate_PrimaryOutputType; |
| 166 | } else { |
| 167 | primaryOutput = static_cast<GrOptDrawState::PrimaryOutputType>( |
| 168 | random->nextULessThan(GrOptDrawState::kPrimaryOutputTypeCnt)); |
| 169 | } |
| 170 | |
| 171 | if (GrOptDrawState::kCombineWithDst_PrimaryOutputType == primaryOutput || |
| 172 | !gpu->caps()->dualSourceBlendingSupport()) { |
| 173 | secondaryOutput = GrOptDrawState::kNone_SecondaryOutputType; |
| 174 | } else { |
| 175 | secondaryOutput = static_cast<GrOptDrawState::SecondaryOutputType>( |
| 176 | random->nextULessThan(GrOptDrawState::kSecondaryOutputTypeCnt)); |
| 177 | } |
| 178 | |
| 179 | header->fPrimaryOutputType = primaryOutput; |
| 180 | header->fSecondaryOutputType = secondaryOutput; |
| 181 | |
| 182 | this->finalize(); |
| 183 | return true; |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 184 | } |
| 185 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 186 | // TODO clean this up, we have to do this to test geometry processors but there has got to be |
| 187 | // a better way. In the mean time, we actually fill out these generic vertex attribs below with |
| 188 | // the correct vertex attribs from the GP. We have to ensure, however, we don't try to add more |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 189 | // than two attributes. |
| 190 | GrVertexAttrib genericVertexAttribs[] = { |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 191 | { kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding }, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 192 | { kVec2f_GrVertexAttribType, 0, kGeometryProcessor_GrVertexAttribBinding }, |
| 193 | { kVec2f_GrVertexAttribType, 0, kGeometryProcessor_GrVertexAttribBinding } |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 194 | }; |
| 195 | |
| 196 | /* |
| 197 | * convert sl type to vertexattrib type, not a complete implementation, only use for debugging |
| 198 | */ |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 199 | GrVertexAttribType convert_sltype_to_attribtype(GrSLType type) { |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 200 | switch (type) { |
| 201 | case kFloat_GrSLType: |
| 202 | return kFloat_GrVertexAttribType; |
| 203 | case kVec2f_GrSLType: |
| 204 | return kVec2f_GrVertexAttribType; |
| 205 | case kVec3f_GrSLType: |
| 206 | return kVec3f_GrVertexAttribType; |
| 207 | case kVec4f_GrSLType: |
| 208 | return kVec4f_GrVertexAttribType; |
| 209 | default: |
| 210 | SkFAIL("Type isn't convertible"); |
| 211 | return kFloat_GrVertexAttribType; |
| 212 | } |
| 213 | } |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 214 | // TODO end test hack |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 215 | |
| 216 | |
bsalomon@google.com | 042a286 | 2013-02-04 18:39:24 +0000 | [diff] [blame] | 217 | bool GrGpuGL::programUnitTest(int maxStages) { |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 218 | |
bsalomon@google.com | d472620 | 2012-08-03 14:34:46 +0000 | [diff] [blame] | 219 | GrTextureDesc dummyDesc; |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 220 | dummyDesc.fFlags = kRenderTarget_GrTextureFlagBit; |
bsalomon@google.com | fec0bc3 | 2013-02-07 14:43:04 +0000 | [diff] [blame] | 221 | dummyDesc.fConfig = kSkia8888_GrPixelConfig; |
bsalomon@google.com | d472620 | 2012-08-03 14:34:46 +0000 | [diff] [blame] | 222 | dummyDesc.fWidth = 34; |
| 223 | dummyDesc.fHeight = 18; |
| 224 | SkAutoTUnref<GrTexture> dummyTexture1(this->createTexture(dummyDesc, NULL, 0)); |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 225 | dummyDesc.fFlags = kNone_GrTextureFlags; |
bsalomon@google.com | d472620 | 2012-08-03 14:34:46 +0000 | [diff] [blame] | 226 | dummyDesc.fConfig = kAlpha_8_GrPixelConfig; |
| 227 | dummyDesc.fWidth = 16; |
| 228 | dummyDesc.fHeight = 22; |
| 229 | SkAutoTUnref<GrTexture> dummyTexture2(this->createTexture(dummyDesc, NULL, 0)); |
| 230 | |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 231 | if (!dummyTexture1 || ! dummyTexture2) { |
| 232 | return false; |
| 233 | } |
| 234 | |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 235 | static const int NUM_TESTS = 512; |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 236 | |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 237 | SkRandom random; |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 238 | for (int t = 0; t < NUM_TESTS; ++t) { |
| 239 | |
| 240 | #if 0 |
| 241 | GrPrintf("\nTest Program %d\n-------------\n", t); |
| 242 | static const int stop = -1; |
| 243 | if (t == stop) { |
| 244 | int breakpointhere = 9; |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 245 | } |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 246 | #endif |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 247 | |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 248 | GrGLProgramDesc pdesc; |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 249 | |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 250 | int currAttribIndex = 1; // we need to always leave room for position |
| 251 | int currTextureCoordSet = 0; |
| 252 | GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()}; |
| 253 | |
| 254 | int numStages = random.nextULessThan(maxStages + 1); |
| 255 | int numColorStages = random.nextULessThan(numStages + 1); |
| 256 | int numCoverageStages = numStages - numColorStages; |
| 257 | |
| 258 | SkAutoSTMalloc<8, const GrFragmentStage*> stages(numStages); |
| 259 | |
egdaniel | ae44496 | 2014-09-22 12:29:52 -0700 | [diff] [blame] | 260 | bool usePathRendering = this->glCaps().pathRenderingSupport() && random.nextBool(); |
egdaniel | c064824 | 2014-09-22 13:17:02 -0700 | [diff] [blame] | 261 | |
egdaniel | ae44496 | 2014-09-22 12:29:52 -0700 | [diff] [blame] | 262 | GrGpu::DrawType drawType = usePathRendering ? GrGpu::kDrawPath_DrawType : |
| 263 | GrGpu::kDrawPoints_DrawType; |
commit-bot@chromium.org | 8e919ad | 2013-10-21 14:48:23 +0000 | [diff] [blame] | 264 | |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 265 | SkAutoTDelete<GrGeometryStage> geometryProcessor; |
egdaniel | ae44496 | 2014-09-22 12:29:52 -0700 | [diff] [blame] | 266 | bool hasGeometryProcessor = usePathRendering ? false : random.nextBool(); |
joshualitt | bd769d0 | 2014-09-04 08:56:46 -0700 | [diff] [blame] | 267 | if (hasGeometryProcessor) { |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 268 | while (true) { |
| 269 | SkAutoTUnref<const GrGeometryProcessor> effect( |
| 270 | GrProcessorTestFactory<GrGeometryProcessor>::CreateStage(&random, this->getContext(), *this->caps(), |
| 271 | dummyTextures)); |
| 272 | SkASSERT(effect); |
| 273 | // Only geometryProcessor can use vertex shader |
| 274 | GrGeometryStage* stage = SkNEW_ARGS(GrGeometryStage, (effect.get())); |
| 275 | geometryProcessor.reset(stage); |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 276 | |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 277 | // we have to set dummy vertex attribs |
| 278 | const GrGeometryProcessor::VertexAttribArray& v = effect->getVertexAttribs(); |
| 279 | int numVertexAttribs = v.count(); |
joshualitt | 07a2553 | 2014-10-07 08:05:21 -0700 | [diff] [blame] | 280 | |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 281 | SkASSERT(GrGeometryProcessor::kMaxVertexAttribs == 2 && |
| 282 | GrGeometryProcessor::kMaxVertexAttribs >= numVertexAttribs); |
| 283 | size_t runningStride = GrVertexAttribTypeSize(genericVertexAttribs[0].fType); |
| 284 | for (int i = 0; i < numVertexAttribs; i++) { |
| 285 | genericVertexAttribs[i + 1].fOffset = runningStride; |
| 286 | genericVertexAttribs[i + 1].fType = |
| 287 | convert_sltype_to_attribtype(v[i].getType()); |
| 288 | runningStride += GrVertexAttribTypeSize(genericVertexAttribs[i + 1].fType); |
| 289 | } |
| 290 | |
| 291 | // update the vertex attributes with the ds |
| 292 | GrDrawState* ds = this->drawState(); |
| 293 | ds->setVertexAttribs<genericVertexAttribs>(numVertexAttribs + 1, runningStride); |
| 294 | currAttribIndex = numVertexAttribs + 1; |
| 295 | break; |
| 296 | } |
| 297 | } |
| 298 | for (int s = 0; s < numStages;) { |
| 299 | SkAutoTUnref<const GrFragmentProcessor> effect( |
| 300 | GrProcessorTestFactory<GrFragmentProcessor>::CreateStage( |
| 301 | &random, |
| 302 | this->getContext(), |
| 303 | *this->caps(), |
| 304 | dummyTextures)); |
| 305 | SkASSERT(effect); |
| 306 | |
| 307 | // If adding this effect would exceed the max texture coord set count then generate a |
| 308 | // new random effect. |
| 309 | if (usePathRendering && this->glPathRendering()->texturingMode() == |
| 310 | GrGLPathRendering::FixedFunction_TexturingMode) {; |
| 311 | int numTransforms = effect->numTransforms(); |
| 312 | if (currTextureCoordSet + numTransforms > this->glCaps().maxFixedFunctionTextureCoords()) { |
| 313 | continue; |
| 314 | } |
| 315 | currTextureCoordSet += numTransforms; |
| 316 | } |
| 317 | GrFragmentStage* stage = SkNEW_ARGS(GrFragmentStage, (effect.get())); |
| 318 | |
| 319 | stages[s] = stage; |
| 320 | ++s; |
| 321 | } |
| 322 | const GrTexture* dstTexture = random.nextBool() ? dummyTextures[0] : dummyTextures[1]; |
| 323 | if (!pdesc.setRandom(&random, |
| 324 | this, |
| 325 | dummyTextures[0]->asRenderTarget(), |
| 326 | dstTexture, |
| 327 | geometryProcessor.get(), |
| 328 | stages.get(), |
| 329 | numColorStages, |
| 330 | numCoverageStages, |
| 331 | currAttribIndex, |
| 332 | drawType)) { |
bsalomon | 848faf0 | 2014-07-11 10:01:02 -0700 | [diff] [blame] | 333 | return false; |
| 334 | } |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 335 | |
| 336 | SkAutoTUnref<GrOptDrawState> optState(GrOptDrawState::Create(this->getDrawState(), |
| 337 | *this->caps(), |
| 338 | drawType)); |
joshualitt | fe1233c | 2014-10-07 12:16:35 -0700 | [diff] [blame^] | 339 | SkAutoTUnref<GrGLProgram> program( |
| 340 | GrGLProgramBuilder::CreateProgram(*optState, |
| 341 | pdesc, |
| 342 | drawType, |
| 343 | geometryProcessor, |
| 344 | stages, |
| 345 | stages + numColorStages, |
| 346 | this)); |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 347 | for (int s = 0; s < numStages; ++s) { |
| 348 | SkDELETE(stages[s]); |
| 349 | } |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 350 | if (NULL == program.get()) { |
| 351 | return false; |
| 352 | } |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 353 | |
| 354 | // We have to reset the drawstate because we might have added a gp |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 355 | this->drawState()->reset(); |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 356 | } |
| 357 | return true; |
| 358 | } |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 359 | |
tfarina@chromium.org | 4ee16bf | 2014-01-10 22:08:27 +0000 | [diff] [blame] | 360 | DEF_GPUTEST(GLPrograms, reporter, factory) { |
bsalomon@google.com | 67b915d | 2013-02-04 16:13:32 +0000 | [diff] [blame] | 361 | for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { |
| 362 | GrContext* context = factory->get(static_cast<GrContextFactory::GLContextType>(type)); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 363 | if (context) { |
bsalomon@google.com | 042a286 | 2013-02-04 18:39:24 +0000 | [diff] [blame] | 364 | GrGpuGL* gpu = static_cast<GrGpuGL*>(context->getGpu()); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 365 | int maxStages = 6; |
bsalomon@google.com | 042a286 | 2013-02-04 18:39:24 +0000 | [diff] [blame] | 366 | #if SK_ANGLE |
| 367 | // Some long shaders run out of temporary registers in the D3D compiler on ANGLE. |
| 368 | if (type == GrContextFactory::kANGLE_GLContextType) { |
| 369 | maxStages = 3; |
| 370 | } |
| 371 | #endif |
| 372 | REPORTER_ASSERT(reporter, gpu->programUnitTest(maxStages)); |
bsalomon@google.com | 67b915d | 2013-02-04 16:13:32 +0000 | [diff] [blame] | 373 | } |
| 374 | } |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 375 | } |
| 376 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 377 | // This is evil evil evil. The linker may throw away whole translation units as dead code if it |
bsalomon@google.com | 67e78c9 | 2012-10-17 13:36:14 +0000 | [diff] [blame] | 378 | // thinks none of the functions are called. It will do this even if there are static initializers |
bsalomon@google.com | a1bf0ff | 2012-08-07 17:36:29 +0000 | [diff] [blame] | 379 | // in the unit that could pass pointers to functions from the unit out to other translation units! |
| 380 | // We force some of the effects that would otherwise be discarded to link here. |
| 381 | |
commit-bot@chromium.org | 40eb3c1 | 2014-01-06 23:41:14 +0000 | [diff] [blame] | 382 | #include "SkAlphaThresholdFilter.h" |
tfarina@chromium.org | 8f6884a | 2014-01-24 20:56:26 +0000 | [diff] [blame] | 383 | #include "SkColorMatrixFilter.h" |
bsalomon@google.com | a1bf0ff | 2012-08-07 17:36:29 +0000 | [diff] [blame] | 384 | #include "SkLightingImageFilter.h" |
bsalomon@google.com | 82aa748 | 2012-08-13 14:22:17 +0000 | [diff] [blame] | 385 | #include "SkMagnifierImageFilter.h" |
bsalomon@google.com | a1bf0ff | 2012-08-07 17:36:29 +0000 | [diff] [blame] | 386 | |
| 387 | void forceLinking(); |
| 388 | |
| 389 | void forceLinking() { |
| 390 | SkLightingImageFilter::CreateDistantLitDiffuse(SkPoint3(0,0,0), 0, 0, 0); |
commit-bot@chromium.org | 9109e18 | 2014-01-07 16:04:01 +0000 | [diff] [blame] | 391 | SkAlphaThresholdFilter::Create(SkRegion(), .5f, .5f); |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 392 | SkAutoTUnref<SkImageFilter> mag(SkMagnifierImageFilter::Create( |
commit-bot@chromium.org | cac5fd5 | 2014-03-10 10:51:58 +0000 | [diff] [blame] | 393 | SkRect::MakeWH(SK_Scalar1, SK_Scalar1), SK_Scalar1)); |
bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 394 | GrConfigConversionEffect::Create(NULL, |
| 395 | false, |
| 396 | GrConfigConversionEffect::kNone_PMConversion, |
| 397 | SkMatrix::I()); |
bsalomon@google.com | 67e78c9 | 2012-10-17 13:36:14 +0000 | [diff] [blame] | 398 | SkScalar matrix[20]; |
commit-bot@chromium.org | 727a352 | 2014-02-21 18:46:30 +0000 | [diff] [blame] | 399 | SkAutoTUnref<SkColorMatrixFilter> cmf(SkColorMatrixFilter::Create(matrix)); |
bsalomon@google.com | a1bf0ff | 2012-08-07 17:36:29 +0000 | [diff] [blame] | 400 | } |
| 401 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 402 | #endif |