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 | 67b915d | 2013-02-04 16:13:32 +0000 | [diff] [blame] | 15 | #include "GrContextFactory.h" |
egdaniel | 605dd0f | 2014-11-12 08:35:25 -0800 | [diff] [blame] | 16 | #include "GrInvariantOutput.h" |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 17 | #include "GrPipeline.h" |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 18 | #include "GrTest.h" |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 19 | #include "GrXferProcessor.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" |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 23 | #include "effects/GrConfigConversionEffect.h" |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 24 | #include "effects/GrPorterDuffXferProcessor.h" |
jvanverth | 39edf76 | 2014-12-22 11:44:19 -0800 | [diff] [blame] | 25 | #include "gl/GrGLGpu.h" |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 26 | #include "gl/GrGLPathRendering.h" |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 27 | #include "gl/builders/GrGLProgramBuilder.h" |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 28 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 29 | /* |
bsalomon | 98b33eb | 2014-10-15 11:05:26 -0700 | [diff] [blame] | 30 | * A dummy processor which just tries to insert a massive key and verify that it can retrieve the |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 31 | * whole thing correctly |
| 32 | */ |
| 33 | static const uint32_t kMaxKeySize = 1024; |
| 34 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 35 | class GLBigKeyProcessor : public GrGLFragmentProcessor { |
| 36 | public: |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 37 | GLBigKeyProcessor(const GrProcessor&) {} |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 38 | |
joshualitt | 1598899 | 2014-10-09 15:04:05 -0700 | [diff] [blame] | 39 | virtual void emitCode(GrGLFPBuilder* builder, |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 40 | const GrFragmentProcessor& fp, |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 41 | const char* outputColor, |
| 42 | const char* inputColor, |
| 43 | const TransformedCoordsArray&, |
joshualitt | 267ce48 | 2014-11-25 14:52:21 -0800 | [diff] [blame] | 44 | const TextureSamplerArray&) {} |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 45 | |
| 46 | static void GenKey(const GrProcessor& processor, const GrGLCaps&, GrProcessorKeyBuilder* b) { |
| 47 | for (uint32_t i = 0; i < kMaxKeySize; i++) { |
| 48 | b->add32(i); |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 49 | } |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 50 | } |
| 51 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 52 | private: |
| 53 | typedef GrGLFragmentProcessor INHERITED; |
| 54 | }; |
| 55 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 56 | class BigKeyProcessor : public GrFragmentProcessor { |
| 57 | public: |
| 58 | static GrFragmentProcessor* Create() { |
| 59 | GR_CREATE_STATIC_PROCESSOR(gBigKeyProcessor, BigKeyProcessor, ()) |
| 60 | return SkRef(gBigKeyProcessor); |
| 61 | } |
| 62 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 63 | const char* name() const SK_OVERRIDE { return "Big Ole Key"; } |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 64 | |
| 65 | virtual void getGLProcessorKey(const GrGLCaps& caps, |
| 66 | GrProcessorKeyBuilder* b) const SK_OVERRIDE { |
| 67 | GLBigKeyProcessor::GenKey(*this, caps, b); |
| 68 | } |
| 69 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 70 | GrGLFragmentProcessor* createGLInstance() const SK_OVERRIDE { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 71 | return SkNEW_ARGS(GLBigKeyProcessor, (*this)); |
| 72 | } |
| 73 | |
| 74 | private: |
| 75 | BigKeyProcessor() { |
| 76 | this->initClassID<BigKeyProcessor>(); |
| 77 | } |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 78 | bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE { return true; } |
| 79 | void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE { } |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 80 | |
| 81 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| 82 | |
| 83 | typedef GrFragmentProcessor INHERITED; |
| 84 | }; |
| 85 | |
| 86 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(BigKeyProcessor); |
| 87 | |
| 88 | GrFragmentProcessor* BigKeyProcessor::TestCreate(SkRandom*, |
| 89 | GrContext*, |
| 90 | const GrDrawTargetCaps&, |
| 91 | GrTexture*[]) { |
| 92 | return BigKeyProcessor::Create(); |
| 93 | } |
| 94 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 95 | /* |
| 96 | * Begin test code |
| 97 | */ |
| 98 | static const int kRenderTargetHeight = 1; |
| 99 | static const int kRenderTargetWidth = 1; |
| 100 | |
bsalomon | 24db3b1 | 2015-01-23 04:24:04 -0800 | [diff] [blame] | 101 | static GrRenderTarget* random_render_target(GrContext* context, SkRandom* random) { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 102 | // setup render target |
| 103 | GrTextureParams params; |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 104 | GrSurfaceDesc texDesc; |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 105 | texDesc.fWidth = kRenderTargetWidth; |
| 106 | texDesc.fHeight = kRenderTargetHeight; |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 107 | texDesc.fFlags = kRenderTarget_GrSurfaceFlag; |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 108 | texDesc.fConfig = kRGBA_8888_GrPixelConfig; |
| 109 | texDesc.fOrigin = random->nextBool() == true ? kTopLeft_GrSurfaceOrigin : |
| 110 | kBottomLeft_GrSurfaceOrigin; |
bsalomon | 24db3b1 | 2015-01-23 04:24:04 -0800 | [diff] [blame] | 111 | GrContentKey key; |
| 112 | static const GrContentKey::Domain kDomain = GrContentKey::GenerateDomain(); |
| 113 | GrContentKey::Builder builder(&key, kDomain, 1); |
| 114 | builder[0] = texDesc.fOrigin; |
| 115 | builder.finish(); |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 116 | |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 117 | GrTexture* texture = context->findAndRefCachedTexture(key); |
bsalomon | d27726e | 2014-10-12 05:40:00 -0700 | [diff] [blame] | 118 | if (!texture) { |
bsalomon | d042358 | 2015-02-06 08:49:24 -0800 | [diff] [blame^] | 119 | texture = context->createTexture(texDesc, true); |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 120 | if (texture) { |
| 121 | SkAssertResult(context->addResourceToCache(key, texture)); |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 122 | } |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 123 | } |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 124 | return texture ? texture->asRenderTarget() : NULL; |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 125 | } |
| 126 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 127 | static void set_random_xpf(GrContext* context, const GrDrawTargetCaps& caps, |
| 128 | GrPipelineBuilder* pipelineBuilder, SkRandom* random, |
| 129 | GrTexture* dummyTextures[]) { |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 130 | SkAutoTUnref<const GrXPFactory> xpf( |
| 131 | GrProcessorTestFactory<GrXPFactory>::CreateStage(random, context, caps, dummyTextures)); |
| 132 | SkASSERT(xpf); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 133 | pipelineBuilder->setXPFactory(xpf.get()); |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 134 | } |
| 135 | |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 136 | static const GrGeometryProcessor* get_random_gp(GrContext* context, |
| 137 | const GrDrawTargetCaps& caps, |
| 138 | SkRandom* random, |
| 139 | GrTexture* dummyTextures[]) { |
| 140 | return GrProcessorTestFactory<GrGeometryProcessor>::CreateStage(random, |
| 141 | context, |
| 142 | caps, |
| 143 | dummyTextures); |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 144 | } |
| 145 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 146 | static void set_random_color_coverage_stages(GrGLGpu* gpu, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 147 | GrPipelineBuilder* pipelineBuilder, |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 148 | int maxStages, |
| 149 | bool usePathRendering, |
| 150 | SkRandom* random, |
| 151 | GrTexture* dummyTextures[]) { |
| 152 | int numProcs = random->nextULessThan(maxStages + 1); |
| 153 | int numColorProcs = random->nextULessThan(numProcs + 1); |
| 154 | |
| 155 | int currTextureCoordSet = 0; |
| 156 | for (int s = 0; s < numProcs;) { |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 157 | SkAutoTUnref<const GrFragmentProcessor> fp( |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 158 | GrProcessorTestFactory<GrFragmentProcessor>::CreateStage(random, |
| 159 | gpu->getContext(), |
| 160 | *gpu->caps(), |
| 161 | dummyTextures)); |
| 162 | SkASSERT(fp); |
| 163 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 164 | // If adding this effect would exceed the max texture coord set count then generate a |
| 165 | // new random effect. |
| 166 | if (usePathRendering && gpu->glPathRendering()->texturingMode() == |
| 167 | GrGLPathRendering::FixedFunction_TexturingMode) {; |
| 168 | int numTransforms = fp->numTransforms(); |
| 169 | if (currTextureCoordSet + numTransforms > |
| 170 | gpu->glCaps().maxFixedFunctionTextureCoords()) { |
| 171 | continue; |
| 172 | } |
| 173 | currTextureCoordSet += numTransforms; |
| 174 | } |
| 175 | |
| 176 | // finally add the stage to the correct pipeline in the drawstate |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 177 | if (s < numColorProcs) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 178 | pipelineBuilder->addColorProcessor(fp); |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 179 | } else { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 180 | pipelineBuilder->addCoverageProcessor(fp); |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 181 | } |
| 182 | ++s; |
| 183 | } |
| 184 | } |
| 185 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 186 | static void set_random_state(GrPipelineBuilder* pipelineBuilder, SkRandom* random) { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 187 | int state = 0; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 188 | for (int i = 1; i <= GrPipelineBuilder::kLast_StateBit; i <<= 1) { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 189 | state |= random->nextBool() * i; |
| 190 | } |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 191 | pipelineBuilder->enableState(state); |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 192 | } |
| 193 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 194 | // right now, the only thing we seem to care about in drawState's stencil is 'doesWrite()' |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 195 | static void set_random_stencil(GrPipelineBuilder* pipelineBuilder, SkRandom* random) { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 196 | GR_STATIC_CONST_SAME_STENCIL(kDoesWriteStencil, |
| 197 | kReplace_StencilOp, |
| 198 | kReplace_StencilOp, |
| 199 | kAlways_StencilFunc, |
| 200 | 0xffff, |
| 201 | 0xffff, |
| 202 | 0xffff); |
| 203 | GR_STATIC_CONST_SAME_STENCIL(kDoesNotWriteStencil, |
| 204 | kKeep_StencilOp, |
| 205 | kKeep_StencilOp, |
| 206 | kNever_StencilFunc, |
| 207 | 0xffff, |
| 208 | 0xffff, |
| 209 | 0xffff); |
| 210 | |
| 211 | if (random->nextBool()) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 212 | pipelineBuilder->setStencil(kDoesWriteStencil); |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 213 | } else { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 214 | pipelineBuilder->setStencil(kDoesNotWriteStencil); |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 215 | } |
| 216 | } |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 217 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 218 | bool GrDrawTarget::programUnitTest(int maxStages) { |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 219 | GrGLGpu* gpu = static_cast<GrGLGpu*>(fContext->getGpu()); |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 220 | // setup dummy textures |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 221 | GrSurfaceDesc dummyDesc; |
| 222 | dummyDesc.fFlags = kRenderTarget_GrSurfaceFlag; |
bsalomon@google.com | fec0bc3 | 2013-02-07 14:43:04 +0000 | [diff] [blame] | 223 | dummyDesc.fConfig = kSkia8888_GrPixelConfig; |
bsalomon@google.com | d472620 | 2012-08-03 14:34:46 +0000 | [diff] [blame] | 224 | dummyDesc.fWidth = 34; |
| 225 | dummyDesc.fHeight = 18; |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 226 | SkAutoTUnref<GrTexture> dummyTexture1(gpu->createTexture(dummyDesc, false, NULL, 0)); |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 227 | dummyDesc.fFlags = kNone_GrSurfaceFlags; |
bsalomon@google.com | d472620 | 2012-08-03 14:34:46 +0000 | [diff] [blame] | 228 | dummyDesc.fConfig = kAlpha_8_GrPixelConfig; |
| 229 | dummyDesc.fWidth = 16; |
| 230 | dummyDesc.fHeight = 22; |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 231 | SkAutoTUnref<GrTexture> dummyTexture2(gpu->createTexture(dummyDesc, false, NULL, 0)); |
bsalomon@google.com | d472620 | 2012-08-03 14:34:46 +0000 | [diff] [blame] | 232 | |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 233 | if (!dummyTexture1 || ! dummyTexture2) { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 234 | SkDebugf("Could not allocate dummy textures"); |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 235 | return false; |
| 236 | } |
| 237 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 238 | GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()}; |
| 239 | |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 240 | // dummy scissor state |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 241 | GrScissorState scissor; |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 242 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 243 | // setup clip |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 244 | SkRect screen = SkRect::MakeWH(SkIntToScalar(kRenderTargetWidth), |
| 245 | SkIntToScalar(kRenderTargetHeight)); |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 246 | |
| 247 | SkClipStack stack; |
| 248 | stack.clipDevRect(screen, SkRegion::kReplace_Op, false); |
| 249 | |
| 250 | // wrap the SkClipStack in a GrClipData |
| 251 | GrClipData clipData; |
joshualitt | de358a9 | 2015-02-05 08:19:35 -0800 | [diff] [blame] | 252 | clipData.fClipStack.reset(SkRef(&stack)); |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 253 | this->setClip(&clipData); |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 254 | |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 255 | SkRandom random; |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 256 | static const int NUM_TESTS = 512; |
| 257 | for (int t = 0; t < NUM_TESTS;) { |
| 258 | // setup random render target(can fail) |
bsalomon | 24db3b1 | 2015-01-23 04:24:04 -0800 | [diff] [blame] | 259 | SkAutoTUnref<GrRenderTarget> rt(random_render_target(fContext, &random)); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 260 | if (!rt.get()) { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 261 | SkDebugf("Could not allocate render target"); |
| 262 | return false; |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 263 | } |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 264 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 265 | GrPipelineBuilder pipelineBuilder; |
| 266 | pipelineBuilder.setRenderTarget(rt.get()); |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 267 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 268 | // if path rendering we have to setup a couple of things like the draw type |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 269 | bool usePathRendering = gpu->glCaps().pathRenderingSupport() && random.nextBool(); |
egdaniel | c064824 | 2014-09-22 13:17:02 -0700 | [diff] [blame] | 270 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 271 | // twiddle drawstate knobs randomly |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 272 | bool hasGeometryProcessor = !usePathRendering; |
joshualitt | 43893e4 | 2014-12-13 06:46:13 -0800 | [diff] [blame] | 273 | SkAutoTUnref<const GrGeometryProcessor> gp; |
| 274 | SkAutoTUnref<const GrPathProcessor> pathProc; |
joshualitt | bd769d0 | 2014-09-04 08:56:46 -0700 | [diff] [blame] | 275 | if (hasGeometryProcessor) { |
joshualitt | 43893e4 | 2014-12-13 06:46:13 -0800 | [diff] [blame] | 276 | gp.reset(get_random_gp(fContext, gpu->glCaps(), &random, dummyTextures)); |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 277 | } else { |
joshualitt | 43893e4 | 2014-12-13 06:46:13 -0800 | [diff] [blame] | 278 | pathProc.reset(GrPathProcessor::Create(GrColor_WHITE)); |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 279 | } |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 280 | set_random_color_coverage_stages(gpu, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 281 | &pipelineBuilder, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 282 | maxStages - hasGeometryProcessor, |
| 283 | usePathRendering, |
| 284 | &random, |
| 285 | dummyTextures); |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 286 | |
| 287 | // creates a random xfer processor factory on the draw state |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 288 | set_random_xpf(fContext, gpu->glCaps(), &pipelineBuilder, &random, dummyTextures); |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 289 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 290 | set_random_state(&pipelineBuilder, &random); |
| 291 | set_random_stencil(&pipelineBuilder, &random); |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 292 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 293 | GrDeviceCoordTexture dstCopy; |
| 294 | |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 295 | const GrPrimitiveProcessor* primProc; |
| 296 | if (hasGeometryProcessor) { |
joshualitt | 43893e4 | 2014-12-13 06:46:13 -0800 | [diff] [blame] | 297 | primProc = gp.get(); |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 298 | } else { |
joshualitt | 43893e4 | 2014-12-13 06:46:13 -0800 | [diff] [blame] | 299 | primProc = pathProc.get(); |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 300 | } |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 301 | if (!this->setupDstReadIfNecessary(pipelineBuilder, &dstCopy, NULL)) { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 302 | SkDebugf("Couldn't setup dst read texture"); |
bsalomon | 848faf0 | 2014-07-11 10:01:02 -0700 | [diff] [blame] | 303 | return false; |
| 304 | } |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 305 | |
| 306 | // create optimized draw state, setup readDst texture if required, and build a descriptor |
| 307 | // and program. ODS creation can fail, so we have to check |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 308 | GrPipeline pipeline(pipelineBuilder, primProc, *gpu->caps(), scissor, &dstCopy); |
| 309 | if (pipeline.mustSkip()) { |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 310 | continue; |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 311 | } |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 312 | GrBatchTracker bt; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 313 | primProc->initBatchTracker(&bt, pipeline.getInitBatchTracker()); |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 314 | |
| 315 | GrProgramDesc desc; |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 316 | gpu->buildProgramDesc(&desc, *primProc, pipeline, bt); |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 317 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 318 | GrGpu::DrawArgs args(primProc, &pipeline, &desc, &bt); |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 319 | SkAutoTUnref<GrGLProgram> program(GrGLProgramBuilder::CreateProgram(args, gpu)); |
| 320 | |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 321 | if (NULL == program.get()) { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 322 | SkDebugf("Failed to create program!"); |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 323 | return false; |
| 324 | } |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 325 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 326 | // because occasionally optimized drawstate creation will fail for valid reasons, we only |
| 327 | // want to increment on success |
| 328 | ++t; |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 329 | } |
| 330 | return true; |
| 331 | } |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 332 | |
tfarina@chromium.org | 4ee16bf | 2014-01-10 22:08:27 +0000 | [diff] [blame] | 333 | DEF_GPUTEST(GLPrograms, reporter, factory) { |
bsalomon@google.com | 67b915d | 2013-02-04 16:13:32 +0000 | [diff] [blame] | 334 | for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { |
| 335 | GrContext* context = factory->get(static_cast<GrContextFactory::GLContextType>(type)); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 336 | if (context) { |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 337 | GrGLGpu* gpu = static_cast<GrGLGpu*>(context->getGpu()); |
joshualitt | 9e87fa7 | 2014-10-09 13:12:35 -0700 | [diff] [blame] | 338 | |
| 339 | /* |
| 340 | * For the time being, we only support the test with desktop GL or for android on |
| 341 | * ARM platforms |
| 342 | * TODO When we run ES 3.00 GLSL in more places, test again |
| 343 | */ |
| 344 | int maxStages; |
| 345 | if (kGL_GrGLStandard == gpu->glStandard() || |
| 346 | kARM_GrGLVendor == gpu->ctxInfo().vendor()) { |
| 347 | maxStages = 6; |
| 348 | } else if (kTegra3_GrGLRenderer == gpu->ctxInfo().renderer() || |
| 349 | kOther_GrGLRenderer == gpu->ctxInfo().renderer()) { |
| 350 | maxStages = 1; |
| 351 | } else { |
| 352 | return; |
| 353 | } |
bsalomon@google.com | 042a286 | 2013-02-04 18:39:24 +0000 | [diff] [blame] | 354 | #if SK_ANGLE |
| 355 | // Some long shaders run out of temporary registers in the D3D compiler on ANGLE. |
| 356 | if (type == GrContextFactory::kANGLE_GLContextType) { |
| 357 | maxStages = 3; |
| 358 | } |
| 359 | #endif |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 360 | GrTestTarget target; |
| 361 | context->getTestTarget(&target); |
| 362 | REPORTER_ASSERT(reporter, target.target()->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 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 367 | #endif |