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