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 | |
| 47 | static void GenKey(const GrProcessor& processor, const GrGLCaps&, GrProcessorKeyBuilder* b) { |
| 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 | |
| 66 | virtual void getGLProcessorKey(const GrGLCaps& 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 | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 118 | GrTexture* texture = context->findAndRefCachedTexture(key); |
bsalomon | d27726e | 2014-10-12 05:40:00 -0700 | [diff] [blame] | 119 | if (!texture) { |
bsalomon | d042358 | 2015-02-06 08:49:24 -0800 | [diff] [blame] | 120 | texture = context->createTexture(texDesc, true); |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 121 | if (texture) { |
bsalomon | f99e961 | 2015-02-19 08:24:16 -0800 | [diff] [blame] | 122 | context->addResourceToCache(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 | |
| 156 | int currTextureCoordSet = 0; |
| 157 | for (int s = 0; s < numProcs;) { |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 158 | SkAutoTUnref<const GrFragmentProcessor> fp( |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 159 | GrProcessorTestFactory<GrFragmentProcessor>::CreateStage(random, |
| 160 | gpu->getContext(), |
| 161 | *gpu->caps(), |
| 162 | dummyTextures)); |
| 163 | SkASSERT(fp); |
| 164 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 165 | // If adding this effect would exceed the max texture coord set count then generate a |
| 166 | // new random effect. |
| 167 | if (usePathRendering && gpu->glPathRendering()->texturingMode() == |
| 168 | GrGLPathRendering::FixedFunction_TexturingMode) {; |
| 169 | int numTransforms = fp->numTransforms(); |
| 170 | if (currTextureCoordSet + numTransforms > |
| 171 | gpu->glCaps().maxFixedFunctionTextureCoords()) { |
| 172 | continue; |
| 173 | } |
| 174 | currTextureCoordSet += numTransforms; |
| 175 | } |
| 176 | |
| 177 | // finally add the stage to the correct pipeline in the drawstate |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 178 | if (s < numColorProcs) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 179 | pipelineBuilder->addColorProcessor(fp); |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 180 | } else { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 181 | pipelineBuilder->addCoverageProcessor(fp); |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 182 | } |
| 183 | ++s; |
| 184 | } |
| 185 | } |
| 186 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 187 | static void set_random_state(GrPipelineBuilder* pipelineBuilder, SkRandom* random) { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 188 | int state = 0; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 189 | for (int i = 1; i <= GrPipelineBuilder::kLast_StateBit; i <<= 1) { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 190 | state |= random->nextBool() * i; |
| 191 | } |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 192 | pipelineBuilder->enableState(state); |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 193 | } |
| 194 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 195 | // 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] | 196 | static void set_random_stencil(GrPipelineBuilder* pipelineBuilder, SkRandom* random) { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 197 | GR_STATIC_CONST_SAME_STENCIL(kDoesWriteStencil, |
| 198 | kReplace_StencilOp, |
| 199 | kReplace_StencilOp, |
| 200 | kAlways_StencilFunc, |
| 201 | 0xffff, |
| 202 | 0xffff, |
| 203 | 0xffff); |
| 204 | GR_STATIC_CONST_SAME_STENCIL(kDoesNotWriteStencil, |
| 205 | kKeep_StencilOp, |
| 206 | kKeep_StencilOp, |
| 207 | kNever_StencilFunc, |
| 208 | 0xffff, |
| 209 | 0xffff, |
| 210 | 0xffff); |
| 211 | |
| 212 | if (random->nextBool()) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 213 | pipelineBuilder->setStencil(kDoesWriteStencil); |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 214 | } else { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 215 | pipelineBuilder->setStencil(kDoesNotWriteStencil); |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 216 | } |
| 217 | } |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 218 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 219 | bool GrDrawTarget::programUnitTest(int maxStages) { |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 220 | GrGLGpu* gpu = static_cast<GrGLGpu*>(fContext->getGpu()); |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 221 | // setup dummy textures |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 222 | GrSurfaceDesc dummyDesc; |
| 223 | dummyDesc.fFlags = kRenderTarget_GrSurfaceFlag; |
bsalomon@google.com | fec0bc3 | 2013-02-07 14:43:04 +0000 | [diff] [blame] | 224 | dummyDesc.fConfig = kSkia8888_GrPixelConfig; |
bsalomon@google.com | d472620 | 2012-08-03 14:34:46 +0000 | [diff] [blame] | 225 | dummyDesc.fWidth = 34; |
| 226 | dummyDesc.fHeight = 18; |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 227 | SkAutoTUnref<GrTexture> dummyTexture1(gpu->createTexture(dummyDesc, false, NULL, 0)); |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 228 | dummyDesc.fFlags = kNone_GrSurfaceFlags; |
bsalomon@google.com | d472620 | 2012-08-03 14:34:46 +0000 | [diff] [blame] | 229 | dummyDesc.fConfig = kAlpha_8_GrPixelConfig; |
| 230 | dummyDesc.fWidth = 16; |
| 231 | dummyDesc.fHeight = 22; |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 232 | SkAutoTUnref<GrTexture> dummyTexture2(gpu->createTexture(dummyDesc, false, NULL, 0)); |
bsalomon@google.com | d472620 | 2012-08-03 14:34:46 +0000 | [diff] [blame] | 233 | |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 234 | if (!dummyTexture1 || ! dummyTexture2) { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 235 | SkDebugf("Could not allocate dummy textures"); |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 236 | return false; |
| 237 | } |
| 238 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 239 | GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()}; |
| 240 | |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 241 | // dummy scissor state |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 242 | GrScissorState scissor; |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 243 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 244 | // setup clip |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 245 | SkRect screen = SkRect::MakeWH(SkIntToScalar(kRenderTargetWidth), |
| 246 | SkIntToScalar(kRenderTargetHeight)); |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 247 | |
| 248 | SkClipStack stack; |
| 249 | stack.clipDevRect(screen, SkRegion::kReplace_Op, false); |
| 250 | |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 251 | // wrap the SkClipStack in a GrClip |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 252 | GrClip clip; |
| 253 | clip.setClipStack(&stack); |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 254 | |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 255 | SkRandom random; |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 256 | static const int NUM_TESTS = 512; |
| 257 | for (int t = 0; t < NUM_TESTS;) { |
| 258 | // setup random render target(can fail) |
bsalomon | 24db3b1 | 2015-01-23 04:24:04 -0800 | [diff] [blame] | 259 | SkAutoTUnref<GrRenderTarget> rt(random_render_target(fContext, &random)); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 260 | if (!rt.get()) { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 261 | SkDebugf("Could not allocate render target"); |
| 262 | return false; |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 263 | } |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 264 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 265 | GrPipelineBuilder pipelineBuilder; |
| 266 | pipelineBuilder.setRenderTarget(rt.get()); |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 267 | pipelineBuilder.setClip(clip); |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 268 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 269 | // if path rendering we have to setup a couple of things like the draw type |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 270 | bool usePathRendering = gpu->glCaps().pathRenderingSupport() && random.nextBool(); |
egdaniel | c064824 | 2014-09-22 13:17:02 -0700 | [diff] [blame] | 271 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 272 | // twiddle drawstate knobs randomly |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 273 | bool hasGeometryProcessor = !usePathRendering; |
joshualitt | 43893e4 | 2014-12-13 06:46:13 -0800 | [diff] [blame] | 274 | SkAutoTUnref<const GrGeometryProcessor> gp; |
| 275 | SkAutoTUnref<const GrPathProcessor> pathProc; |
joshualitt | bd769d0 | 2014-09-04 08:56:46 -0700 | [diff] [blame] | 276 | if (hasGeometryProcessor) { |
joshualitt | 43893e4 | 2014-12-13 06:46:13 -0800 | [diff] [blame] | 277 | gp.reset(get_random_gp(fContext, gpu->glCaps(), &random, dummyTextures)); |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 278 | } else { |
joshualitt | 43893e4 | 2014-12-13 06:46:13 -0800 | [diff] [blame] | 279 | pathProc.reset(GrPathProcessor::Create(GrColor_WHITE)); |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 280 | } |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 281 | set_random_color_coverage_stages(gpu, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 282 | &pipelineBuilder, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 283 | maxStages - hasGeometryProcessor, |
| 284 | usePathRendering, |
| 285 | &random, |
| 286 | dummyTextures); |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 287 | |
| 288 | // creates a random xfer processor factory on the draw state |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 289 | set_random_xpf(fContext, gpu->glCaps(), &pipelineBuilder, &random, dummyTextures); |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 290 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 291 | set_random_state(&pipelineBuilder, &random); |
| 292 | set_random_stencil(&pipelineBuilder, &random); |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 293 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 294 | GrDeviceCoordTexture dstCopy; |
| 295 | |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 296 | const GrPrimitiveProcessor* primProc; |
| 297 | if (hasGeometryProcessor) { |
joshualitt | 43893e4 | 2014-12-13 06:46:13 -0800 | [diff] [blame] | 298 | primProc = gp.get(); |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 299 | } else { |
joshualitt | 43893e4 | 2014-12-13 06:46:13 -0800 | [diff] [blame] | 300 | primProc = pathProc.get(); |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 301 | } |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 302 | |
| 303 | const GrProcOptInfo& colorPOI = pipelineBuilder.colorProcInfo(primProc); |
| 304 | const GrProcOptInfo& coveragePOI = pipelineBuilder.coverageProcInfo(primProc); |
| 305 | |
| 306 | if (!this->setupDstReadIfNecessary(pipelineBuilder, colorPOI, coveragePOI, &dstCopy, |
| 307 | NULL)) { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 308 | SkDebugf("Couldn't setup dst read texture"); |
bsalomon | 848faf0 | 2014-07-11 10:01:02 -0700 | [diff] [blame] | 309 | return false; |
| 310 | } |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 311 | |
| 312 | // create optimized draw state, setup readDst texture if required, and build a descriptor |
| 313 | // and program. ODS creation can fail, so we have to check |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 314 | GrPipeline pipeline(pipelineBuilder, colorPOI, coveragePOI, |
| 315 | *gpu->caps(), scissor, &dstCopy); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 316 | if (pipeline.mustSkip()) { |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 317 | continue; |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 318 | } |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 319 | GrBatchTracker bt; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 320 | primProc->initBatchTracker(&bt, pipeline.getInitBatchTracker()); |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 321 | |
| 322 | GrProgramDesc desc; |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 323 | gpu->buildProgramDesc(&desc, *primProc, pipeline, bt); |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 324 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 325 | GrGpu::DrawArgs args(primProc, &pipeline, &desc, &bt); |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 326 | SkAutoTUnref<GrGLProgram> program(GrGLProgramBuilder::CreateProgram(args, gpu)); |
| 327 | |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 328 | if (NULL == program.get()) { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 329 | SkDebugf("Failed to create program!"); |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 330 | return false; |
| 331 | } |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 332 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 333 | // because occasionally optimized drawstate creation will fail for valid reasons, we only |
| 334 | // want to increment on success |
| 335 | ++t; |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 336 | } |
| 337 | return true; |
| 338 | } |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 339 | |
tfarina@chromium.org | 4ee16bf | 2014-01-10 22:08:27 +0000 | [diff] [blame] | 340 | DEF_GPUTEST(GLPrograms, reporter, factory) { |
bsalomon | 3318ee7 | 2015-03-16 11:56:29 -0700 | [diff] [blame] | 341 | // Set a locale that would cause shader compilation to fail because of , as decimal separator. |
| 342 | // skbug 3330 |
| 343 | #ifdef SK_BUILD_FOR_WIN |
| 344 | GrAutoLocaleSetter als("sv-SE"); |
| 345 | #else |
| 346 | GrAutoLocaleSetter als("sv_SE.UTF-8"); |
| 347 | #endif |
| 348 | |
bsalomon@google.com | 67b915d | 2013-02-04 16:13:32 +0000 | [diff] [blame] | 349 | for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { |
| 350 | GrContext* context = factory->get(static_cast<GrContextFactory::GLContextType>(type)); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 351 | if (context) { |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 352 | GrGLGpu* gpu = static_cast<GrGLGpu*>(context->getGpu()); |
joshualitt | 9e87fa7 | 2014-10-09 13:12:35 -0700 | [diff] [blame] | 353 | |
| 354 | /* |
| 355 | * For the time being, we only support the test with desktop GL or for android on |
| 356 | * ARM platforms |
| 357 | * TODO When we run ES 3.00 GLSL in more places, test again |
| 358 | */ |
| 359 | int maxStages; |
| 360 | if (kGL_GrGLStandard == gpu->glStandard() || |
| 361 | kARM_GrGLVendor == gpu->ctxInfo().vendor()) { |
| 362 | maxStages = 6; |
| 363 | } else if (kTegra3_GrGLRenderer == gpu->ctxInfo().renderer() || |
| 364 | kOther_GrGLRenderer == gpu->ctxInfo().renderer()) { |
| 365 | maxStages = 1; |
| 366 | } else { |
| 367 | return; |
| 368 | } |
bsalomon@google.com | 042a286 | 2013-02-04 18:39:24 +0000 | [diff] [blame] | 369 | #if SK_ANGLE |
| 370 | // Some long shaders run out of temporary registers in the D3D compiler on ANGLE. |
| 371 | if (type == GrContextFactory::kANGLE_GLContextType) { |
egdaniel | 305a889 | 2015-02-17 11:18:38 -0800 | [diff] [blame] | 372 | maxStages = 2; |
bsalomon@google.com | 042a286 | 2013-02-04 18:39:24 +0000 | [diff] [blame] | 373 | } |
| 374 | #endif |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 375 | GrTestTarget target; |
| 376 | context->getTestTarget(&target); |
| 377 | REPORTER_ASSERT(reporter, target.target()->programUnitTest(maxStages)); |
bsalomon@google.com | 67b915d | 2013-02-04 16:13:32 +0000 | [diff] [blame] | 378 | } |
| 379 | } |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 380 | } |
| 381 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 382 | #endif |