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