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 | 6f7f201 | 2015-03-16 14:00:52 -0700 | [diff] [blame] | 15 | #include "GrAutoLocaleSetter.h" |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 16 | #include "GrBatch.h" |
| 17 | #include "GrBatchTest.h" |
bsalomon@google.com | 67b915d | 2013-02-04 16:13:32 +0000 | [diff] [blame] | 18 | #include "GrContextFactory.h" |
egdaniel | 605dd0f | 2014-11-12 08:35:25 -0800 | [diff] [blame] | 19 | #include "GrInvariantOutput.h" |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 20 | #include "GrPipeline.h" |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 21 | #include "GrResourceProvider.h" |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 22 | #include "GrTest.h" |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 23 | #include "GrXferProcessor.h" |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 24 | #include "SkChecksum.h" |
tfarina@chromium.org | 223137f | 2012-11-21 22:38:36 +0000 | [diff] [blame] | 25 | #include "SkRandom.h" |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 26 | #include "Test.h" |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 27 | #include "effects/GrConfigConversionEffect.h" |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 28 | #include "effects/GrPorterDuffXferProcessor.h" |
jvanverth | 39edf76 | 2014-12-22 11:44:19 -0800 | [diff] [blame] | 29 | #include "gl/GrGLGpu.h" |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 30 | #include "gl/GrGLPathRendering.h" |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 31 | #include "gl/builders/GrGLProgramBuilder.h" |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 32 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 33 | /* |
bsalomon | 98b33eb | 2014-10-15 11:05:26 -0700 | [diff] [blame] | 34 | * 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] | 35 | * whole thing correctly |
| 36 | */ |
| 37 | static const uint32_t kMaxKeySize = 1024; |
| 38 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 39 | class GLBigKeyProcessor : public GrGLFragmentProcessor { |
| 40 | public: |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 41 | GLBigKeyProcessor(const GrProcessor&) {} |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 42 | |
wangyix | 7c157a9 | 2015-07-22 15:08:53 -0700 | [diff] [blame^] | 43 | virtual void emitCode(EmitArgs& args) override { |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 44 | // pass through |
wangyix | 7c157a9 | 2015-07-22 15:08:53 -0700 | [diff] [blame^] | 45 | GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder(); |
| 46 | fsBuilder->codeAppendf("%s = %s;\n", args.fOutputColor, args.fInputColor); |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 47 | } |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 48 | |
jvanverth | cfc1886 | 2015-04-28 08:48:20 -0700 | [diff] [blame] | 49 | static void GenKey(const GrProcessor& processor, const GrGLSLCaps&, GrProcessorKeyBuilder* b) { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 50 | for (uint32_t i = 0; i < kMaxKeySize; i++) { |
| 51 | b->add32(i); |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 52 | } |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 53 | } |
| 54 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 55 | private: |
| 56 | typedef GrGLFragmentProcessor INHERITED; |
| 57 | }; |
| 58 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 59 | class BigKeyProcessor : public GrFragmentProcessor { |
| 60 | public: |
| 61 | static GrFragmentProcessor* Create() { |
| 62 | GR_CREATE_STATIC_PROCESSOR(gBigKeyProcessor, BigKeyProcessor, ()) |
| 63 | return SkRef(gBigKeyProcessor); |
| 64 | } |
| 65 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 66 | const char* name() const override { return "Big Ole Key"; } |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 67 | |
jvanverth | cfc1886 | 2015-04-28 08:48:20 -0700 | [diff] [blame] | 68 | virtual void getGLProcessorKey(const GrGLSLCaps& caps, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 69 | GrProcessorKeyBuilder* b) const override { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 70 | GLBigKeyProcessor::GenKey(*this, caps, b); |
| 71 | } |
| 72 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 73 | GrGLFragmentProcessor* createGLInstance() const override { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 74 | return SkNEW_ARGS(GLBigKeyProcessor, (*this)); |
| 75 | } |
| 76 | |
| 77 | private: |
| 78 | BigKeyProcessor() { |
| 79 | this->initClassID<BigKeyProcessor>(); |
| 80 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 81 | bool onIsEqual(const GrFragmentProcessor&) const override { return true; } |
| 82 | void onComputeInvariantOutput(GrInvariantOutput* inout) const override { } |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 83 | |
| 84 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| 85 | |
| 86 | typedef GrFragmentProcessor INHERITED; |
| 87 | }; |
| 88 | |
| 89 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(BigKeyProcessor); |
| 90 | |
joshualitt | 0067ff5 | 2015-07-08 14:26:19 -0700 | [diff] [blame] | 91 | GrFragmentProcessor* BigKeyProcessor::TestCreate(GrProcessorTestData*) { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 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 | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 101 | static GrRenderTarget* random_render_target(GrTextureProvider* textureProvider, SkRandom* random, |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 102 | const GrCaps* caps) { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 103 | // setup render target |
| 104 | GrTextureParams params; |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 105 | GrSurfaceDesc texDesc; |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 106 | texDesc.fWidth = kRenderTargetWidth; |
| 107 | texDesc.fHeight = kRenderTargetHeight; |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 108 | texDesc.fFlags = kRenderTarget_GrSurfaceFlag; |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 109 | texDesc.fConfig = kRGBA_8888_GrPixelConfig; |
| 110 | texDesc.fOrigin = random->nextBool() == true ? kTopLeft_GrSurfaceOrigin : |
| 111 | kBottomLeft_GrSurfaceOrigin; |
joshualitt | 1573206 | 2015-05-13 12:15:14 -0700 | [diff] [blame] | 112 | texDesc.fSampleCnt = random->nextBool() == true ? SkTMin(4, caps->maxSampleCount()) : 0; |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 113 | |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 114 | GrUniqueKey key; |
| 115 | static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 116 | GrUniqueKey::Builder builder(&key, kDomain, 2); |
bsalomon | 24db3b1 | 2015-01-23 04:24:04 -0800 | [diff] [blame] | 117 | builder[0] = texDesc.fOrigin; |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 118 | builder[1] = texDesc.fSampleCnt; |
bsalomon | 24db3b1 | 2015-01-23 04:24:04 -0800 | [diff] [blame] | 119 | builder.finish(); |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 120 | |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 121 | GrTexture* texture = textureProvider->findAndRefTextureByUniqueKey(key); |
bsalomon | d27726e | 2014-10-12 05:40:00 -0700 | [diff] [blame] | 122 | if (!texture) { |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 123 | texture = textureProvider->createTexture(texDesc, true); |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 124 | if (texture) { |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 125 | textureProvider->assignUniqueKeyToTexture(key, texture); |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 126 | } |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 127 | } |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 128 | return texture ? texture->asRenderTarget() : NULL; |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 129 | } |
| 130 | |
joshualitt | 0067ff5 | 2015-07-08 14:26:19 -0700 | [diff] [blame] | 131 | static void set_random_xpf(GrPipelineBuilder* pipelineBuilder, GrProcessorTestData* d) { |
| 132 | SkAutoTUnref<const GrXPFactory> xpf(GrProcessorTestFactory<GrXPFactory>::CreateStage(d)); |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 133 | SkASSERT(xpf); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 134 | pipelineBuilder->setXPFactory(xpf.get()); |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 135 | } |
| 136 | |
joshualitt | 0067ff5 | 2015-07-08 14:26:19 -0700 | [diff] [blame] | 137 | static void set_random_color_coverage_stages(GrPipelineBuilder* pipelineBuilder, |
| 138 | GrProcessorTestData* d, int maxStages) { |
| 139 | int numProcs = d->fRandom->nextULessThan(maxStages + 1); |
| 140 | int numColorProcs = d->fRandom->nextULessThan(numProcs + 1); |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 141 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 142 | for (int s = 0; s < numProcs;) { |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 143 | SkAutoTUnref<const GrFragmentProcessor> fp( |
joshualitt | 0067ff5 | 2015-07-08 14:26:19 -0700 | [diff] [blame] | 144 | GrProcessorTestFactory<GrFragmentProcessor>::CreateStage(d)); |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 145 | SkASSERT(fp); |
| 146 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 147 | // finally add the stage to the correct pipeline in the drawstate |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 148 | if (s < numColorProcs) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 149 | pipelineBuilder->addColorProcessor(fp); |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 150 | } else { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 151 | pipelineBuilder->addCoverageProcessor(fp); |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 152 | } |
| 153 | ++s; |
| 154 | } |
| 155 | } |
| 156 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 157 | static void set_random_state(GrPipelineBuilder* pipelineBuilder, SkRandom* random) { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 158 | int state = 0; |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 159 | for (int i = 1; i <= GrPipelineBuilder::kLast_Flag; i <<= 1) { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 160 | state |= random->nextBool() * i; |
| 161 | } |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 162 | |
| 163 | // If we don't have an MSAA rendertarget then we have to disable useHWAA |
| 164 | if ((state | GrPipelineBuilder::kHWAntialias_Flag) && |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 165 | !pipelineBuilder->getRenderTarget()->isUnifiedMultisampled()) { |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 166 | state &= ~GrPipelineBuilder::kHWAntialias_Flag; |
| 167 | } |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 168 | pipelineBuilder->enableState(state); |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 169 | } |
| 170 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 171 | // 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] | 172 | static void set_random_stencil(GrPipelineBuilder* pipelineBuilder, SkRandom* random) { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 173 | GR_STATIC_CONST_SAME_STENCIL(kDoesWriteStencil, |
| 174 | kReplace_StencilOp, |
| 175 | kReplace_StencilOp, |
| 176 | kAlways_StencilFunc, |
| 177 | 0xffff, |
| 178 | 0xffff, |
| 179 | 0xffff); |
| 180 | GR_STATIC_CONST_SAME_STENCIL(kDoesNotWriteStencil, |
| 181 | kKeep_StencilOp, |
| 182 | kKeep_StencilOp, |
| 183 | kNever_StencilFunc, |
| 184 | 0xffff, |
| 185 | 0xffff, |
| 186 | 0xffff); |
| 187 | |
| 188 | if (random->nextBool()) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 189 | pipelineBuilder->setStencil(kDoesWriteStencil); |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 190 | } else { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 191 | pipelineBuilder->setStencil(kDoesNotWriteStencil); |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 192 | } |
| 193 | } |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 194 | |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 195 | bool GrDrawTarget::programUnitTest(GrContext* context, int maxStages) { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 196 | // setup dummy textures |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 197 | GrSurfaceDesc dummyDesc; |
bsalomon | bea0150 | 2015-07-16 10:00:28 -0700 | [diff] [blame] | 198 | dummyDesc.fFlags = kRenderTarget_GrSurfaceFlag; |
bsalomon@google.com | fec0bc3 | 2013-02-07 14:43:04 +0000 | [diff] [blame] | 199 | dummyDesc.fConfig = kSkia8888_GrPixelConfig; |
bsalomon@google.com | d472620 | 2012-08-03 14:34:46 +0000 | [diff] [blame] | 200 | dummyDesc.fWidth = 34; |
| 201 | dummyDesc.fHeight = 18; |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 202 | SkAutoTUnref<GrTexture> dummyTexture1( |
| 203 | fResourceProvider->createTexture(dummyDesc, false, NULL, 0)); |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 204 | dummyDesc.fFlags = kNone_GrSurfaceFlags; |
bsalomon@google.com | d472620 | 2012-08-03 14:34:46 +0000 | [diff] [blame] | 205 | dummyDesc.fConfig = kAlpha_8_GrPixelConfig; |
| 206 | dummyDesc.fWidth = 16; |
| 207 | dummyDesc.fHeight = 22; |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 208 | SkAutoTUnref<GrTexture> dummyTexture2( |
| 209 | fResourceProvider->createTexture(dummyDesc, false, NULL, 0)); |
bsalomon@google.com | d472620 | 2012-08-03 14:34:46 +0000 | [diff] [blame] | 210 | |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 211 | if (!dummyTexture1 || ! dummyTexture2) { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 212 | SkDebugf("Could not allocate dummy textures"); |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 213 | return false; |
| 214 | } |
| 215 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 216 | GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()}; |
| 217 | |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 218 | // dummy scissor state |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 219 | GrScissorState scissor; |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 220 | |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 221 | // wide open clip |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 222 | GrClip clip; |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 223 | |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 224 | SkRandom random; |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 225 | static const int NUM_TESTS = 2048; |
| 226 | for (int t = 0; t < NUM_TESTS; t++) { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 227 | // setup random render target(can fail) |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 228 | SkAutoTUnref<GrRenderTarget> rt(random_render_target( |
| 229 | fResourceProvider, &random, this->caps())); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 230 | if (!rt.get()) { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 231 | SkDebugf("Could not allocate render target"); |
| 232 | return false; |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 233 | } |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 234 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 235 | GrPipelineBuilder pipelineBuilder; |
| 236 | pipelineBuilder.setRenderTarget(rt.get()); |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 237 | pipelineBuilder.setClip(clip); |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 238 | |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 239 | SkAutoTUnref<GrBatch> batch(GrRandomBatch(&random, context)); |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 240 | SkASSERT(batch); |
egdaniel | c064824 | 2014-09-22 13:17:02 -0700 | [diff] [blame] | 241 | |
joshualitt | 9cc1775 | 2015-07-09 06:28:14 -0700 | [diff] [blame] | 242 | GrProcessorDataManager procDataManager; |
| 243 | GrProcessorTestData ptd(&random, context, &procDataManager, fGpu->caps(), dummyTextures); |
joshualitt | 0067ff5 | 2015-07-08 14:26:19 -0700 | [diff] [blame] | 244 | set_random_color_coverage_stages(&pipelineBuilder, &ptd, maxStages); |
| 245 | set_random_xpf(&pipelineBuilder, &ptd); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 246 | set_random_state(&pipelineBuilder, &random); |
| 247 | set_random_stencil(&pipelineBuilder, &random); |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 248 | |
joshualitt | 1c73548 | 2015-07-13 08:08:25 -0700 | [diff] [blame] | 249 | this->drawBatch(pipelineBuilder, batch); |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 250 | } |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 251 | |
| 252 | // Flush everything, test passes if flush is successful(ie, no asserts are hit, no crashes) |
| 253 | this->flush(); |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 254 | return true; |
| 255 | } |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 256 | |
tfarina@chromium.org | 4ee16bf | 2014-01-10 22:08:27 +0000 | [diff] [blame] | 257 | DEF_GPUTEST(GLPrograms, reporter, factory) { |
bsalomon | 3318ee7 | 2015-03-16 11:56:29 -0700 | [diff] [blame] | 258 | // Set a locale that would cause shader compilation to fail because of , as decimal separator. |
| 259 | // skbug 3330 |
| 260 | #ifdef SK_BUILD_FOR_WIN |
| 261 | GrAutoLocaleSetter als("sv-SE"); |
| 262 | #else |
| 263 | GrAutoLocaleSetter als("sv_SE.UTF-8"); |
| 264 | #endif |
| 265 | |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 266 | // We suppress prints to avoid spew |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 267 | GrContextOptions opts; |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 268 | opts.fSuppressPrints = true; |
| 269 | GrContextFactory debugFactory(opts); |
bsalomon@google.com | 67b915d | 2013-02-04 16:13:32 +0000 | [diff] [blame] | 270 | for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 271 | GrContext* context = debugFactory.get(static_cast<GrContextFactory::GLContextType>(type)); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 272 | if (context) { |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 273 | GrGLGpu* gpu = static_cast<GrGLGpu*>(context->getGpu()); |
joshualitt | 9e87fa7 | 2014-10-09 13:12:35 -0700 | [diff] [blame] | 274 | |
| 275 | /* |
| 276 | * For the time being, we only support the test with desktop GL or for android on |
| 277 | * ARM platforms |
| 278 | * TODO When we run ES 3.00 GLSL in more places, test again |
| 279 | */ |
| 280 | int maxStages; |
| 281 | if (kGL_GrGLStandard == gpu->glStandard() || |
| 282 | kARM_GrGLVendor == gpu->ctxInfo().vendor()) { |
| 283 | maxStages = 6; |
| 284 | } else if (kTegra3_GrGLRenderer == gpu->ctxInfo().renderer() || |
| 285 | kOther_GrGLRenderer == gpu->ctxInfo().renderer()) { |
| 286 | maxStages = 1; |
| 287 | } else { |
| 288 | return; |
| 289 | } |
bsalomon@google.com | 042a286 | 2013-02-04 18:39:24 +0000 | [diff] [blame] | 290 | #if SK_ANGLE |
| 291 | // Some long shaders run out of temporary registers in the D3D compiler on ANGLE. |
| 292 | if (type == GrContextFactory::kANGLE_GLContextType) { |
egdaniel | 305a889 | 2015-02-17 11:18:38 -0800 | [diff] [blame] | 293 | maxStages = 2; |
bsalomon@google.com | 042a286 | 2013-02-04 18:39:24 +0000 | [diff] [blame] | 294 | } |
| 295 | #endif |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 296 | GrTestTarget target; |
| 297 | context->getTestTarget(&target); |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 298 | REPORTER_ASSERT(reporter, target.target()->programUnitTest(context, maxStages)); |
bsalomon@google.com | 67b915d | 2013-02-04 16:13:32 +0000 | [diff] [blame] | 299 | } |
| 300 | } |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 301 | } |
| 302 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 303 | #endif |