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