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