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" |
bsalomon@google.com | 67b915d | 2013-02-04 16:13:32 +0000 | [diff] [blame] | 16 | #include "GrContextFactory.h" |
egdaniel | 605dd0f | 2014-11-12 08:35:25 -0800 | [diff] [blame] | 17 | #include "GrInvariantOutput.h" |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 18 | #include "GrPipeline.h" |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 19 | #include "GrTest.h" |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 20 | #include "GrXferProcessor.h" |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 21 | #include "SkChecksum.h" |
tfarina@chromium.org | 223137f | 2012-11-21 22:38:36 +0000 | [diff] [blame] | 22 | #include "SkRandom.h" |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 23 | #include "Test.h" |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 24 | #include "effects/GrConfigConversionEffect.h" |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 25 | #include "effects/GrPorterDuffXferProcessor.h" |
jvanverth | 39edf76 | 2014-12-22 11:44:19 -0800 | [diff] [blame] | 26 | #include "gl/GrGLGpu.h" |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 27 | #include "gl/GrGLPathRendering.h" |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 28 | #include "gl/builders/GrGLProgramBuilder.h" |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 29 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 30 | /* |
bsalomon | 98b33eb | 2014-10-15 11:05:26 -0700 | [diff] [blame] | 31 | * 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] | 32 | * whole thing correctly |
| 33 | */ |
| 34 | static const uint32_t kMaxKeySize = 1024; |
| 35 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 36 | class GLBigKeyProcessor : public GrGLFragmentProcessor { |
| 37 | public: |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 38 | GLBigKeyProcessor(const GrProcessor&) {} |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 39 | |
joshualitt | 1598899 | 2014-10-09 15:04:05 -0700 | [diff] [blame] | 40 | virtual void emitCode(GrGLFPBuilder* builder, |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 41 | const GrFragmentProcessor& fp, |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 42 | const char* outputColor, |
| 43 | const char* inputColor, |
| 44 | const TransformedCoordsArray&, |
joshualitt | 267ce48 | 2014-11-25 14:52:21 -0800 | [diff] [blame] | 45 | const TextureSamplerArray&) {} |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 46 | |
jvanverth | cfc1886 | 2015-04-28 08:48:20 -0700 | [diff] [blame] | 47 | static void GenKey(const GrProcessor& processor, const GrGLSLCaps&, GrProcessorKeyBuilder* b) { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 48 | for (uint32_t i = 0; i < kMaxKeySize; i++) { |
| 49 | b->add32(i); |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 50 | } |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 51 | } |
| 52 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 53 | private: |
| 54 | typedef GrGLFragmentProcessor INHERITED; |
| 55 | }; |
| 56 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 57 | class BigKeyProcessor : public GrFragmentProcessor { |
| 58 | public: |
| 59 | static GrFragmentProcessor* Create() { |
| 60 | GR_CREATE_STATIC_PROCESSOR(gBigKeyProcessor, BigKeyProcessor, ()) |
| 61 | return SkRef(gBigKeyProcessor); |
| 62 | } |
| 63 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 64 | const char* name() const override { return "Big Ole Key"; } |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 65 | |
jvanverth | cfc1886 | 2015-04-28 08:48:20 -0700 | [diff] [blame] | 66 | virtual void getGLProcessorKey(const GrGLSLCaps& caps, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 67 | GrProcessorKeyBuilder* b) const override { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 68 | GLBigKeyProcessor::GenKey(*this, caps, b); |
| 69 | } |
| 70 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 71 | GrGLFragmentProcessor* createGLInstance() const override { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 72 | return SkNEW_ARGS(GLBigKeyProcessor, (*this)); |
| 73 | } |
| 74 | |
| 75 | private: |
| 76 | BigKeyProcessor() { |
| 77 | this->initClassID<BigKeyProcessor>(); |
| 78 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 79 | bool onIsEqual(const GrFragmentProcessor&) const override { return true; } |
| 80 | void onComputeInvariantOutput(GrInvariantOutput* inout) const override { } |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 81 | |
| 82 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| 83 | |
| 84 | typedef GrFragmentProcessor INHERITED; |
| 85 | }; |
| 86 | |
| 87 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(BigKeyProcessor); |
| 88 | |
| 89 | GrFragmentProcessor* BigKeyProcessor::TestCreate(SkRandom*, |
| 90 | GrContext*, |
| 91 | const GrDrawTargetCaps&, |
| 92 | GrTexture*[]) { |
| 93 | return BigKeyProcessor::Create(); |
| 94 | } |
| 95 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 96 | /* |
| 97 | * Begin test code |
| 98 | */ |
| 99 | static const int kRenderTargetHeight = 1; |
| 100 | static const int kRenderTargetWidth = 1; |
| 101 | |
bsalomon | 24db3b1 | 2015-01-23 04:24:04 -0800 | [diff] [blame] | 102 | static GrRenderTarget* random_render_target(GrContext* context, SkRandom* random) { |
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; |
bsalomon | 8718aaf | 2015-02-19 07:24:21 -0800 | [diff] [blame] | 112 | GrUniqueKey key; |
| 113 | static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); |
| 114 | GrUniqueKey::Builder builder(&key, kDomain, 1); |
bsalomon | 24db3b1 | 2015-01-23 04:24:04 -0800 | [diff] [blame] | 115 | builder[0] = texDesc.fOrigin; |
| 116 | builder.finish(); |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 117 | |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame^] | 118 | GrTexture* texture = context->textureProvider()->findAndRefTextureByUniqueKey(key); |
bsalomon | d27726e | 2014-10-12 05:40:00 -0700 | [diff] [blame] | 119 | if (!texture) { |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame^] | 120 | texture = context->textureProvider()->createTexture(texDesc, true); |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 121 | if (texture) { |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame^] | 122 | context->textureProvider()->assignUniqueKeyToTexture(key, texture); |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 123 | } |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 124 | } |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 125 | return texture ? texture->asRenderTarget() : NULL; |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 126 | } |
| 127 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 128 | static void set_random_xpf(GrContext* context, const GrDrawTargetCaps& caps, |
| 129 | GrPipelineBuilder* pipelineBuilder, SkRandom* random, |
| 130 | GrTexture* dummyTextures[]) { |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 131 | SkAutoTUnref<const GrXPFactory> xpf( |
| 132 | GrProcessorTestFactory<GrXPFactory>::CreateStage(random, context, caps, dummyTextures)); |
| 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 | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 137 | static const GrGeometryProcessor* get_random_gp(GrContext* context, |
| 138 | const GrDrawTargetCaps& caps, |
| 139 | SkRandom* random, |
| 140 | GrTexture* dummyTextures[]) { |
| 141 | return GrProcessorTestFactory<GrGeometryProcessor>::CreateStage(random, |
| 142 | context, |
| 143 | caps, |
| 144 | dummyTextures); |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [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, |
| 150 | bool usePathRendering, |
| 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 | } |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 179 | pipelineBuilder->enableState(state); |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 180 | } |
| 181 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 182 | // 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] | 183 | static void set_random_stencil(GrPipelineBuilder* pipelineBuilder, SkRandom* random) { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 184 | GR_STATIC_CONST_SAME_STENCIL(kDoesWriteStencil, |
| 185 | kReplace_StencilOp, |
| 186 | kReplace_StencilOp, |
| 187 | kAlways_StencilFunc, |
| 188 | 0xffff, |
| 189 | 0xffff, |
| 190 | 0xffff); |
| 191 | GR_STATIC_CONST_SAME_STENCIL(kDoesNotWriteStencil, |
| 192 | kKeep_StencilOp, |
| 193 | kKeep_StencilOp, |
| 194 | kNever_StencilFunc, |
| 195 | 0xffff, |
| 196 | 0xffff, |
| 197 | 0xffff); |
| 198 | |
| 199 | if (random->nextBool()) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 200 | pipelineBuilder->setStencil(kDoesWriteStencil); |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 201 | } else { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 202 | pipelineBuilder->setStencil(kDoesNotWriteStencil); |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 203 | } |
| 204 | } |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 205 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 206 | bool GrDrawTarget::programUnitTest(int maxStages) { |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 207 | GrGLGpu* gpu = static_cast<GrGLGpu*>(fContext->getGpu()); |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 208 | // setup dummy textures |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 209 | GrSurfaceDesc dummyDesc; |
| 210 | dummyDesc.fFlags = kRenderTarget_GrSurfaceFlag; |
bsalomon@google.com | fec0bc3 | 2013-02-07 14:43:04 +0000 | [diff] [blame] | 211 | dummyDesc.fConfig = kSkia8888_GrPixelConfig; |
bsalomon@google.com | d472620 | 2012-08-03 14:34:46 +0000 | [diff] [blame] | 212 | dummyDesc.fWidth = 34; |
| 213 | dummyDesc.fHeight = 18; |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 214 | SkAutoTUnref<GrTexture> dummyTexture1(gpu->createTexture(dummyDesc, false, NULL, 0)); |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 215 | dummyDesc.fFlags = kNone_GrSurfaceFlags; |
bsalomon@google.com | d472620 | 2012-08-03 14:34:46 +0000 | [diff] [blame] | 216 | dummyDesc.fConfig = kAlpha_8_GrPixelConfig; |
| 217 | dummyDesc.fWidth = 16; |
| 218 | dummyDesc.fHeight = 22; |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 219 | SkAutoTUnref<GrTexture> dummyTexture2(gpu->createTexture(dummyDesc, false, NULL, 0)); |
bsalomon@google.com | d472620 | 2012-08-03 14:34:46 +0000 | [diff] [blame] | 220 | |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 221 | if (!dummyTexture1 || ! dummyTexture2) { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 222 | SkDebugf("Could not allocate dummy textures"); |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 223 | return false; |
| 224 | } |
| 225 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 226 | GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()}; |
| 227 | |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 228 | // dummy scissor state |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 229 | GrScissorState scissor; |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 230 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 231 | // setup clip |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 232 | SkRect screen = SkRect::MakeWH(SkIntToScalar(kRenderTargetWidth), |
| 233 | SkIntToScalar(kRenderTargetHeight)); |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 234 | |
| 235 | SkClipStack stack; |
| 236 | stack.clipDevRect(screen, SkRegion::kReplace_Op, false); |
| 237 | |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 238 | // wrap the SkClipStack in a GrClip |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 239 | GrClip clip; |
| 240 | clip.setClipStack(&stack); |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 241 | |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 242 | SkRandom random; |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 243 | static const int NUM_TESTS = 512; |
| 244 | for (int t = 0; t < NUM_TESTS;) { |
| 245 | // setup random render target(can fail) |
bsalomon | 24db3b1 | 2015-01-23 04:24:04 -0800 | [diff] [blame] | 246 | SkAutoTUnref<GrRenderTarget> rt(random_render_target(fContext, &random)); |
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 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 256 | // if path rendering we have to setup a couple of things like the draw type |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 257 | bool usePathRendering = gpu->glCaps().shaderCaps()->pathRenderingSupport() && |
| 258 | random.nextBool(); |
egdaniel | c064824 | 2014-09-22 13:17:02 -0700 | [diff] [blame] | 259 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 260 | // twiddle drawstate knobs randomly |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 261 | bool hasGeometryProcessor = !usePathRendering; |
joshualitt | 43893e4 | 2014-12-13 06:46:13 -0800 | [diff] [blame] | 262 | SkAutoTUnref<const GrGeometryProcessor> gp; |
| 263 | SkAutoTUnref<const GrPathProcessor> pathProc; |
joshualitt | bd769d0 | 2014-09-04 08:56:46 -0700 | [diff] [blame] | 264 | if (hasGeometryProcessor) { |
joshualitt | 43893e4 | 2014-12-13 06:46:13 -0800 | [diff] [blame] | 265 | gp.reset(get_random_gp(fContext, gpu->glCaps(), &random, dummyTextures)); |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 266 | } else { |
joshualitt | 43893e4 | 2014-12-13 06:46:13 -0800 | [diff] [blame] | 267 | pathProc.reset(GrPathProcessor::Create(GrColor_WHITE)); |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 268 | } |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 269 | set_random_color_coverage_stages(gpu, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 270 | &pipelineBuilder, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 271 | maxStages - hasGeometryProcessor, |
| 272 | usePathRendering, |
| 273 | &random, |
| 274 | dummyTextures); |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 275 | |
| 276 | // creates a random xfer processor factory on the draw state |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 277 | set_random_xpf(fContext, gpu->glCaps(), &pipelineBuilder, &random, dummyTextures); |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 278 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 279 | set_random_state(&pipelineBuilder, &random); |
| 280 | set_random_stencil(&pipelineBuilder, &random); |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 281 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 282 | GrDeviceCoordTexture dstCopy; |
| 283 | |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 284 | const GrPrimitiveProcessor* primProc; |
| 285 | if (hasGeometryProcessor) { |
joshualitt | 43893e4 | 2014-12-13 06:46:13 -0800 | [diff] [blame] | 286 | primProc = gp.get(); |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 287 | } else { |
joshualitt | 43893e4 | 2014-12-13 06:46:13 -0800 | [diff] [blame] | 288 | primProc = pathProc.get(); |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 289 | } |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 290 | |
| 291 | const GrProcOptInfo& colorPOI = pipelineBuilder.colorProcInfo(primProc); |
| 292 | const GrProcOptInfo& coveragePOI = pipelineBuilder.coverageProcInfo(primProc); |
| 293 | |
| 294 | if (!this->setupDstReadIfNecessary(pipelineBuilder, colorPOI, coveragePOI, &dstCopy, |
| 295 | NULL)) { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 296 | SkDebugf("Couldn't setup dst read texture"); |
bsalomon | 848faf0 | 2014-07-11 10:01:02 -0700 | [diff] [blame] | 297 | return false; |
| 298 | } |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 299 | |
| 300 | // create optimized draw state, setup readDst texture if required, and build a descriptor |
| 301 | // and program. ODS creation can fail, so we have to check |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 302 | GrPipeline pipeline(pipelineBuilder, colorPOI, coveragePOI, |
| 303 | *gpu->caps(), scissor, &dstCopy); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 304 | if (pipeline.mustSkip()) { |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 305 | continue; |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 306 | } |
cdalton | 9954bc3 | 2015-04-29 14:17:00 -0700 | [diff] [blame] | 307 | |
| 308 | GrXferBarrierType barrierType; |
| 309 | if (pipeline.getXferProcessor()->willNeedXferBarrier(rt, *gpu->caps(), &barrierType)) { |
| 310 | gpu->xferBarrier(barrierType); |
| 311 | } |
| 312 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 313 | GrBatchTracker bt; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 314 | primProc->initBatchTracker(&bt, pipeline.getInitBatchTracker()); |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 315 | |
| 316 | GrProgramDesc desc; |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 317 | gpu->buildProgramDesc(&desc, *primProc, pipeline, bt); |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 318 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 319 | GrGpu::DrawArgs args(primProc, &pipeline, &desc, &bt); |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 320 | SkAutoTUnref<GrGLProgram> program(GrGLProgramBuilder::CreateProgram(args, gpu)); |
| 321 | |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 322 | if (NULL == program.get()) { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 323 | SkDebugf("Failed to create program!"); |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 324 | return false; |
| 325 | } |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 326 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 327 | // because occasionally optimized drawstate creation will fail for valid reasons, we only |
| 328 | // want to increment on success |
| 329 | ++t; |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 330 | } |
| 331 | return true; |
| 332 | } |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 333 | |
tfarina@chromium.org | 4ee16bf | 2014-01-10 22:08:27 +0000 | [diff] [blame] | 334 | DEF_GPUTEST(GLPrograms, reporter, factory) { |
bsalomon | 3318ee7 | 2015-03-16 11:56:29 -0700 | [diff] [blame] | 335 | // Set a locale that would cause shader compilation to fail because of , as decimal separator. |
| 336 | // skbug 3330 |
| 337 | #ifdef SK_BUILD_FOR_WIN |
| 338 | GrAutoLocaleSetter als("sv-SE"); |
| 339 | #else |
| 340 | GrAutoLocaleSetter als("sv_SE.UTF-8"); |
| 341 | #endif |
| 342 | |
bsalomon@google.com | 67b915d | 2013-02-04 16:13:32 +0000 | [diff] [blame] | 343 | for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { |
| 344 | GrContext* context = factory->get(static_cast<GrContextFactory::GLContextType>(type)); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 345 | if (context) { |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 346 | GrGLGpu* gpu = static_cast<GrGLGpu*>(context->getGpu()); |
joshualitt | 9e87fa7 | 2014-10-09 13:12:35 -0700 | [diff] [blame] | 347 | |
| 348 | /* |
| 349 | * For the time being, we only support the test with desktop GL or for android on |
| 350 | * ARM platforms |
| 351 | * TODO When we run ES 3.00 GLSL in more places, test again |
| 352 | */ |
| 353 | int maxStages; |
| 354 | if (kGL_GrGLStandard == gpu->glStandard() || |
| 355 | kARM_GrGLVendor == gpu->ctxInfo().vendor()) { |
| 356 | maxStages = 6; |
| 357 | } else if (kTegra3_GrGLRenderer == gpu->ctxInfo().renderer() || |
| 358 | kOther_GrGLRenderer == gpu->ctxInfo().renderer()) { |
| 359 | maxStages = 1; |
| 360 | } else { |
| 361 | return; |
| 362 | } |
bsalomon@google.com | 042a286 | 2013-02-04 18:39:24 +0000 | [diff] [blame] | 363 | #if SK_ANGLE |
| 364 | // Some long shaders run out of temporary registers in the D3D compiler on ANGLE. |
| 365 | if (type == GrContextFactory::kANGLE_GLContextType) { |
egdaniel | 305a889 | 2015-02-17 11:18:38 -0800 | [diff] [blame] | 366 | maxStages = 2; |
bsalomon@google.com | 042a286 | 2013-02-04 18:39:24 +0000 | [diff] [blame] | 367 | } |
| 368 | #endif |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 369 | GrTestTarget target; |
| 370 | context->getTestTarget(&target); |
| 371 | REPORTER_ASSERT(reporter, target.target()->programUnitTest(maxStages)); |
bsalomon@google.com | 67b915d | 2013-02-04 16:13:32 +0000 | [diff] [blame] | 372 | } |
| 373 | } |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 374 | } |
| 375 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 376 | #endif |