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