bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
bsalomon@google.com | d472620 | 2012-08-03 14:34:46 +0000 | [diff] [blame] | 8 | // 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] | 9 | |
bsalomon@google.com | 2a48c3a | 2012-08-03 14:54:45 +0000 | [diff] [blame] | 10 | #include "SkTypes.h" |
| 11 | |
| 12 | #if SK_SUPPORT_GPU && SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
| 13 | |
bsalomon | 6f7f201 | 2015-03-16 14:00:52 -0700 | [diff] [blame] | 14 | #include "GrAutoLocaleSetter.h" |
bsalomon@google.com | 67b915d | 2013-02-04 16:13:32 +0000 | [diff] [blame] | 15 | #include "GrContextFactory.h" |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 16 | #include "GrContextPriv.h" |
Brian Salomon | 5ec9def | 2016-12-20 15:34:05 -0500 | [diff] [blame] | 17 | #include "GrDrawOpTest.h" |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 18 | #include "GrDrawingManager.h" |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 19 | #include "GrPipeline.h" |
Brian Salomon | 5ec9def | 2016-12-20 15:34:05 -0500 | [diff] [blame] | 20 | #include "GrRenderTargetContextPriv.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 | 7441782 | 2015-08-07 11:42:16 -0700 | [diff] [blame] | 26 | |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 27 | #include "ops/GrDrawOp.h" |
joshualitt | 7441782 | 2015-08-07 11:42:16 -0700 | [diff] [blame] | 28 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 29 | #include "effects/GrConfigConversionEffect.h" |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 30 | #include "effects/GrPorterDuffXferProcessor.h" |
wangyix | 059dffa | 2015-09-10 06:57:05 -0700 | [diff] [blame] | 31 | #include "effects/GrXfermodeFragmentProcessor.h" |
joshualitt | 7441782 | 2015-08-07 11:42:16 -0700 | [diff] [blame] | 32 | |
jvanverth | 39edf76 | 2014-12-22 11:44:19 -0800 | [diff] [blame] | 33 | #include "gl/GrGLGpu.h" |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 34 | #include "glsl/GrGLSLFragmentProcessor.h" |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame] | 35 | #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 36 | #include "glsl/GrGLSLProgramBuilder.h" |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 37 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 38 | /* |
bsalomon | 98b33eb | 2014-10-15 11:05:26 -0700 | [diff] [blame] | 39 | * 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] | 40 | * whole thing correctly |
| 41 | */ |
| 42 | static const uint32_t kMaxKeySize = 1024; |
| 43 | |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 44 | class GLBigKeyProcessor : public GrGLSLFragmentProcessor { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 45 | public: |
robertphillips | 9cdb992 | 2016-02-03 12:25:40 -0800 | [diff] [blame] | 46 | void emitCode(EmitArgs& args) override { |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 47 | // pass through |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 48 | GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 49 | if (args.fInputColor) { |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 50 | fragBuilder->codeAppendf("%s = %s;\n", args.fOutputColor, args.fInputColor); |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 51 | } else { |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 52 | fragBuilder->codeAppendf("%s = vec4(1.0);\n", args.fOutputColor); |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 53 | } |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 54 | } |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 55 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 56 | static void GenKey(const GrProcessor&, const GrShaderCaps&, GrProcessorKeyBuilder* b) { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 57 | for (uint32_t i = 0; i < kMaxKeySize; i++) { |
| 58 | b->add32(i); |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 59 | } |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 60 | } |
| 61 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 62 | private: |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 63 | typedef GrGLSLFragmentProcessor INHERITED; |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 64 | }; |
| 65 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 66 | class BigKeyProcessor : public GrFragmentProcessor { |
| 67 | public: |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 68 | static std::unique_ptr<GrFragmentProcessor> Make() { |
| 69 | return std::unique_ptr<GrFragmentProcessor>(new BigKeyProcessor); |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 70 | } |
| 71 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 72 | const char* name() const override { return "Big Ole Key"; } |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 73 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 74 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { |
robertphillips | 9cdb992 | 2016-02-03 12:25:40 -0800 | [diff] [blame] | 75 | return new GLBigKeyProcessor; |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 76 | } |
| 77 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 78 | std::unique_ptr<GrFragmentProcessor> clone() const override { return Make(); } |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 79 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 80 | private: |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 81 | BigKeyProcessor() : INHERITED(kBigKeyProcessor_ClassID, kNone_OptimizationFlags) { } |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 82 | virtual void onGetGLSLProcessorKey(const GrShaderCaps& caps, |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 83 | GrProcessorKeyBuilder* b) const override { |
wangyix | 4b3050b | 2015-08-04 07:59:37 -0700 | [diff] [blame] | 84 | GLBigKeyProcessor::GenKey(*this, caps, b); |
| 85 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 86 | bool onIsEqual(const GrFragmentProcessor&) const override { return true; } |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 87 | |
Brian Salomon | 0c26a9d | 2017-07-06 10:09:38 -0400 | [diff] [blame] | 88 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 89 | |
| 90 | typedef GrFragmentProcessor INHERITED; |
| 91 | }; |
| 92 | |
| 93 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(BigKeyProcessor); |
| 94 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 95 | #if GR_TEST_UTILS |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 96 | std::unique_ptr<GrFragmentProcessor> BigKeyProcessor::TestCreate(GrProcessorTestData*) { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 97 | return BigKeyProcessor::Make(); |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 98 | } |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 99 | #endif |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 100 | |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 101 | ////////////////////////////////////////////////////////////////////////////// |
| 102 | |
| 103 | class BlockInputFragmentProcessor : public GrFragmentProcessor { |
| 104 | public: |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 105 | static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> fp) { |
| 106 | return std::unique_ptr<GrFragmentProcessor>(new BlockInputFragmentProcessor(std::move(fp))); |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | const char* name() const override { return "Block Input"; } |
| 110 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 111 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { return new GLFP; } |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 112 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 113 | std::unique_ptr<GrFragmentProcessor> clone() const override { |
Brian Salomon | 96271cd | 2017-07-31 16:27:23 -0400 | [diff] [blame] | 114 | return Make(this->childProcessor(0).clone()); |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 115 | } |
| 116 | |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 117 | private: |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 118 | class GLFP : public GrGLSLFragmentProcessor { |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 119 | public: |
| 120 | void emitCode(EmitArgs& args) override { |
Ethan Nicholas | 2983f40 | 2017-05-08 09:36:08 -0400 | [diff] [blame] | 121 | this->emitChild(0, args); |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | private: |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 125 | typedef GrGLSLFragmentProcessor INHERITED; |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 126 | }; |
| 127 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 128 | BlockInputFragmentProcessor(std::unique_ptr<GrFragmentProcessor> child) |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 129 | : INHERITED(kBlockInputFragmentProcessor_ClassID, kNone_OptimizationFlags) { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 130 | this->registerChildProcessor(std::move(child)); |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 133 | void onGetGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override {} |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 134 | |
| 135 | bool onIsEqual(const GrFragmentProcessor&) const override { return true; } |
| 136 | |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 137 | typedef GrFragmentProcessor INHERITED; |
| 138 | }; |
| 139 | |
| 140 | ////////////////////////////////////////////////////////////////////////////// |
| 141 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 142 | /* |
| 143 | * Begin test code |
| 144 | */ |
| 145 | static const int kRenderTargetHeight = 1; |
| 146 | static const int kRenderTargetWidth = 1; |
| 147 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 148 | static sk_sp<GrRenderTargetContext> random_render_target_context(GrContext* context, |
| 149 | SkRandom* random, |
| 150 | const GrCaps* caps) { |
robertphillips | 82ec6e5 | 2016-05-19 14:01:05 -0700 | [diff] [blame] | 151 | GrSurfaceOrigin origin = random->nextBool() ? kTopLeft_GrSurfaceOrigin |
| 152 | : kBottomLeft_GrSurfaceOrigin; |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 153 | int sampleCnt = random->nextBool() ? caps->getSampleCount(4, kRGBA_8888_GrPixelConfig) : 0; |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 154 | |
Robert Phillips | dd3b3f4 | 2017-04-24 10:57:28 -0400 | [diff] [blame] | 155 | sk_sp<GrRenderTargetContext> renderTargetContext(context->makeDeferredRenderTargetContext( |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 156 | SkBackingFit::kExact, |
| 157 | kRenderTargetWidth, |
| 158 | kRenderTargetHeight, |
| 159 | kRGBA_8888_GrPixelConfig, |
| 160 | nullptr, |
| 161 | sampleCnt, |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 162 | GrMipMapped::kNo, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 163 | origin)); |
| 164 | return renderTargetContext; |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 165 | } |
| 166 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 167 | #if GR_TEST_UTILS |
robertphillips | 28a838e | 2016-06-23 14:07:00 -0700 | [diff] [blame] | 168 | static void set_random_xpf(GrPaint* paint, GrProcessorTestData* d) { |
Brian Salomon | a163392 | 2017-01-09 11:46:10 -0500 | [diff] [blame] | 169 | paint->setXPFactory(GrXPFactoryTestFactory::Get(d)); |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 170 | } |
| 171 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 172 | static std::unique_ptr<GrFragmentProcessor> create_random_proc_tree(GrProcessorTestData* d, |
| 173 | int minLevels, int maxLevels) { |
wangyix | 059dffa | 2015-09-10 06:57:05 -0700 | [diff] [blame] | 174 | SkASSERT(1 <= minLevels); |
| 175 | SkASSERT(minLevels <= maxLevels); |
| 176 | |
| 177 | // Return a leaf node if maxLevels is 1 or if we randomly chose to terminate. |
| 178 | // If returning a leaf node, make sure that it doesn't have children (e.g. another |
| 179 | // GrComposeEffect) |
| 180 | const float terminateProbability = 0.3f; |
| 181 | if (1 == minLevels) { |
| 182 | bool terminate = (1 == maxLevels) || (d->fRandom->nextF() < terminateProbability); |
| 183 | if (terminate) { |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 184 | std::unique_ptr<GrFragmentProcessor> fp; |
wangyix | 059dffa | 2015-09-10 06:57:05 -0700 | [diff] [blame] | 185 | while (true) { |
Brian Salomon | 1c05364 | 2017-07-24 10:16:19 -0400 | [diff] [blame] | 186 | fp = GrFragmentProcessorTestFactory::Make(d); |
wangyix | 059dffa | 2015-09-10 06:57:05 -0700 | [diff] [blame] | 187 | SkASSERT(fp); |
| 188 | if (0 == fp->numChildProcessors()) { |
| 189 | break; |
| 190 | } |
wangyix | 059dffa | 2015-09-10 06:57:05 -0700 | [diff] [blame] | 191 | } |
| 192 | return fp; |
| 193 | } |
| 194 | } |
| 195 | // If we didn't terminate, choose either the left or right subtree to fulfill |
| 196 | // the minLevels requirement of this tree; the other child can have as few levels as it wants. |
Brian Salomon | a12c153 | 2017-02-13 12:41:44 -0500 | [diff] [blame] | 197 | // Also choose a random xfer mode. |
wangyix | 059dffa | 2015-09-10 06:57:05 -0700 | [diff] [blame] | 198 | if (minLevels > 1) { |
| 199 | --minLevels; |
| 200 | } |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 201 | auto minLevelsChild = create_random_proc_tree(d, minLevels, maxLevels - 1); |
| 202 | std::unique_ptr<GrFragmentProcessor> otherChild(create_random_proc_tree(d, 1, maxLevels - 1)); |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 203 | SkBlendMode mode = static_cast<SkBlendMode>(d->fRandom->nextRangeU(0, |
Brian Salomon | a12c153 | 2017-02-13 12:41:44 -0500 | [diff] [blame] | 204 | (int)SkBlendMode::kLastMode)); |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 205 | std::unique_ptr<GrFragmentProcessor> fp; |
wangyix | 059dffa | 2015-09-10 06:57:05 -0700 | [diff] [blame] | 206 | if (d->fRandom->nextF() < 0.5f) { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 207 | fp = GrXfermodeFragmentProcessor::MakeFromTwoProcessors(std::move(minLevelsChild), |
| 208 | std::move(otherChild), mode); |
wangyix | 059dffa | 2015-09-10 06:57:05 -0700 | [diff] [blame] | 209 | SkASSERT(fp); |
| 210 | } else { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 211 | fp = GrXfermodeFragmentProcessor::MakeFromTwoProcessors(std::move(otherChild), |
| 212 | std::move(minLevelsChild), mode); |
wangyix | 059dffa | 2015-09-10 06:57:05 -0700 | [diff] [blame] | 213 | SkASSERT(fp); |
| 214 | } |
| 215 | return fp; |
| 216 | } |
| 217 | |
robertphillips | 28a838e | 2016-06-23 14:07:00 -0700 | [diff] [blame] | 218 | static void set_random_color_coverage_stages(GrPaint* paint, |
| 219 | GrProcessorTestData* d, |
Greg Daniel | 78325c1 | 2017-06-19 16:39:13 -0400 | [diff] [blame] | 220 | int maxStages, |
| 221 | int maxTreeLevels) { |
wangyix | 059dffa | 2015-09-10 06:57:05 -0700 | [diff] [blame] | 222 | // Randomly choose to either create a linear pipeline of procs or create one proc tree |
| 223 | const float procTreeProbability = 0.5f; |
| 224 | if (d->fRandom->nextF() < procTreeProbability) { |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 225 | std::unique_ptr<GrFragmentProcessor> fp(create_random_proc_tree(d, 2, maxTreeLevels)); |
Robert Phillips | 1c9686b | 2017-06-30 08:40:28 -0400 | [diff] [blame] | 226 | if (fp) { |
| 227 | paint->addColorFragmentProcessor(std::move(fp)); |
| 228 | } |
wangyix | 059dffa | 2015-09-10 06:57:05 -0700 | [diff] [blame] | 229 | } else { |
| 230 | int numProcs = d->fRandom->nextULessThan(maxStages + 1); |
| 231 | int numColorProcs = d->fRandom->nextULessThan(numProcs + 1); |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 232 | |
wangyix | 059dffa | 2015-09-10 06:57:05 -0700 | [diff] [blame] | 233 | for (int s = 0; s < numProcs;) { |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 234 | std::unique_ptr<GrFragmentProcessor> fp(GrFragmentProcessorTestFactory::Make(d)); |
wangyix | 059dffa | 2015-09-10 06:57:05 -0700 | [diff] [blame] | 235 | SkASSERT(fp); |
| 236 | |
| 237 | // finally add the stage to the correct pipeline in the drawstate |
| 238 | if (s < numColorProcs) { |
robertphillips | 28a838e | 2016-06-23 14:07:00 -0700 | [diff] [blame] | 239 | paint->addColorFragmentProcessor(std::move(fp)); |
wangyix | 059dffa | 2015-09-10 06:57:05 -0700 | [diff] [blame] | 240 | } else { |
robertphillips | 28a838e | 2016-06-23 14:07:00 -0700 | [diff] [blame] | 241 | paint->addCoverageFragmentProcessor(std::move(fp)); |
wangyix | 059dffa | 2015-09-10 06:57:05 -0700 | [diff] [blame] | 242 | } |
| 243 | ++s; |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 244 | } |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 245 | } |
| 246 | } |
| 247 | |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 248 | static void set_random_state(GrPaint* paint, SkRandom* random) { |
robertphillips | 28a838e | 2016-06-23 14:07:00 -0700 | [diff] [blame] | 249 | if (random->nextBool()) { |
| 250 | paint->setDisableOutputConversionToSRGB(true); |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 251 | } |
robertphillips | 28a838e | 2016-06-23 14:07:00 -0700 | [diff] [blame] | 252 | if (random->nextBool()) { |
| 253 | paint->setAllowSRGBInputs(true); |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 254 | } |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 255 | } |
| 256 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 257 | #endif |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 258 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 259 | #if !GR_TEST_UTILS |
| 260 | bool GrDrawingManager::ProgramUnitTest(GrContext*, int) { return true; } |
| 261 | #else |
Greg Daniel | 78325c1 | 2017-06-19 16:39:13 -0400 | [diff] [blame] | 262 | bool GrDrawingManager::ProgramUnitTest(GrContext* context, int maxStages, int maxLevels) { |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 263 | GrDrawingManager* drawingManager = context->contextPriv().drawingManager(); |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 264 | GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider(); |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 265 | |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 266 | sk_sp<GrTextureProxy> proxies[2]; |
| 267 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 268 | // setup dummy textures |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 269 | { |
| 270 | GrSurfaceDesc dummyDesc; |
| 271 | dummyDesc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 272 | dummyDesc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
| 273 | dummyDesc.fWidth = 34; |
| 274 | dummyDesc.fHeight = 18; |
| 275 | dummyDesc.fConfig = kRGBA_8888_GrPixelConfig; |
| 276 | proxies[0] = proxyProvider->createProxy(dummyDesc, SkBackingFit::kExact, SkBudgeted::kNo); |
| 277 | } |
| 278 | { |
| 279 | GrSurfaceDesc dummyDesc; |
| 280 | dummyDesc.fFlags = kNone_GrSurfaceFlags; |
| 281 | dummyDesc.fOrigin = kTopLeft_GrSurfaceOrigin; |
| 282 | dummyDesc.fWidth = 16; |
| 283 | dummyDesc.fHeight = 22; |
| 284 | dummyDesc.fConfig = kAlpha_8_GrPixelConfig; |
| 285 | proxies[1] = proxyProvider->createProxy(dummyDesc, SkBackingFit::kExact, SkBudgeted::kNo); |
| 286 | } |
bsalomon@google.com | d472620 | 2012-08-03 14:34:46 +0000 | [diff] [blame] | 287 | |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 288 | if (!proxies[0] || !proxies[1]) { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 289 | SkDebugf("Could not allocate dummy textures"); |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 290 | return false; |
| 291 | } |
| 292 | |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 293 | // dummy scissor state |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 294 | GrScissorState scissor; |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 295 | |
Brian Osman | 9f772a4 | 2017-07-10 13:03:50 -0400 | [diff] [blame] | 296 | SkRandom random; |
bsalomon | f3261af | 2016-04-05 10:57:13 -0700 | [diff] [blame] | 297 | static const int NUM_TESTS = 1024; |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 298 | for (int t = 0; t < NUM_TESTS; t++) { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 299 | // setup random render target(can fail) |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 300 | sk_sp<GrRenderTargetContext> renderTargetContext(random_render_target_context( |
| 301 | context, &random, context->caps())); |
| 302 | if (!renderTargetContext) { |
| 303 | SkDebugf("Could not allocate renderTargetContext"); |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 304 | return false; |
| 305 | } |
robertphillips | 0dfa62c | 2015-11-16 06:23:31 -0800 | [diff] [blame] | 306 | |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 307 | GrPaint paint; |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 308 | GrProcessorTestData ptd(&random, context, renderTargetContext.get(), proxies); |
Greg Daniel | 78325c1 | 2017-06-19 16:39:13 -0400 | [diff] [blame] | 309 | set_random_color_coverage_stages(&paint, &ptd, maxStages, maxLevels); |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 310 | set_random_xpf(&paint, &ptd); |
| 311 | set_random_state(&paint, &random); |
| 312 | GrDrawRandomOp(&random, renderTargetContext.get(), std::move(paint)); |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 313 | } |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 314 | // Flush everything, test passes if flush is successful(ie, no asserts are hit, no crashes) |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 315 | drawingManager->flush(nullptr); |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 316 | |
| 317 | // Validate that GrFPs work correctly without an input. |
Robert Phillips | dd3b3f4 | 2017-04-24 10:57:28 -0400 | [diff] [blame] | 318 | sk_sp<GrRenderTargetContext> renderTargetContext(context->makeDeferredRenderTargetContext( |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 319 | SkBackingFit::kExact, |
| 320 | kRenderTargetWidth, |
| 321 | kRenderTargetHeight, |
| 322 | kRGBA_8888_GrPixelConfig, |
| 323 | nullptr)); |
| 324 | if (!renderTargetContext) { |
| 325 | SkDebugf("Could not allocate a renderTargetContext"); |
robertphillips | 82ec6e5 | 2016-05-19 14:01:05 -0700 | [diff] [blame] | 326 | return false; |
| 327 | } |
| 328 | |
Brian Salomon | 1c05364 | 2017-07-24 10:16:19 -0400 | [diff] [blame] | 329 | int fpFactoryCnt = GrFragmentProcessorTestFactory::Count(); |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 330 | for (int i = 0; i < fpFactoryCnt; ++i) { |
| 331 | // Since FP factories internally randomize, call each 10 times. |
| 332 | for (int j = 0; j < 10; ++j) { |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 333 | GrProcessorTestData ptd(&random, context, renderTargetContext.get(), proxies); |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 334 | |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 335 | GrPaint paint; |
| 336 | paint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc)); |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 337 | auto fp = GrFragmentProcessorTestFactory::MakeIdx(i, &ptd); |
| 338 | auto blockFP = BlockInputFragmentProcessor::Make(std::move(fp)); |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 339 | paint.addColorFragmentProcessor(std::move(blockFP)); |
| 340 | GrDrawRandomOp(&random, renderTargetContext.get(), std::move(paint)); |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 341 | drawingManager->flush(nullptr); |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 342 | } |
| 343 | } |
| 344 | |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 345 | return true; |
| 346 | } |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 347 | #endif |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 348 | |
Greg Daniel | d895ca6 | 2017-06-19 14:39:43 -0400 | [diff] [blame] | 349 | static int get_glprograms_max_stages(const sk_gpu_test::ContextInfo& ctxInfo) { |
| 350 | GrContext* context = ctxInfo.grContext(); |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame^] | 351 | GrGLGpu* gpu = static_cast<GrGLGpu*>(context->contextPriv().getGpu()); |
Brian Salomon | e334c59 | 2017-05-15 11:00:58 -0400 | [diff] [blame] | 352 | int maxStages = 6; |
| 353 | if (kGLES_GrGLStandard == gpu->glStandard()) { |
| 354 | // We've had issues with driver crashes and HW limits being exceeded with many effects on |
| 355 | // Android devices. We have passes on ARM devices with the default number of stages. |
| 356 | // TODO When we run ES 3.00 GLSL in more places, test again |
| 357 | #ifdef SK_BUILD_FOR_ANDROID |
| 358 | if (kARM_GrGLVendor != gpu->ctxInfo().vendor()) { |
| 359 | maxStages = 1; |
| 360 | } |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 361 | #endif |
Brian Salomon | e334c59 | 2017-05-15 11:00:58 -0400 | [diff] [blame] | 362 | // On iOS we can exceed the maximum number of varyings. http://skbug.com/6627. |
Brian Osman | 4e1868c | 2017-05-26 15:56:32 -0400 | [diff] [blame] | 363 | #ifdef SK_BUILD_FOR_IOS |
Brian Salomon | e334c59 | 2017-05-15 11:00:58 -0400 | [diff] [blame] | 364 | maxStages = 3; |
| 365 | #endif |
| 366 | } |
Greg Daniel | d895ca6 | 2017-06-19 14:39:43 -0400 | [diff] [blame] | 367 | if (ctxInfo.type() == sk_gpu_test::GrContextFactory::kANGLE_D3D9_ES2_ContextType || |
| 368 | ctxInfo.type() == sk_gpu_test::GrContextFactory::kANGLE_D3D11_ES2_ContextType) { |
| 369 | // On Angle D3D we will hit a limit of out variables if we use too many stages. |
| 370 | maxStages = 3; |
| 371 | } |
Brian Salomon | e334c59 | 2017-05-15 11:00:58 -0400 | [diff] [blame] | 372 | return maxStages; |
| 373 | } |
| 374 | |
Greg Daniel | 78325c1 | 2017-06-19 16:39:13 -0400 | [diff] [blame] | 375 | static int get_glprograms_max_levels(const sk_gpu_test::ContextInfo& ctxInfo) { |
| 376 | // A full tree with 5 levels (31 nodes) may cause a program that exceeds shader limits |
| 377 | // (e.g. uniform or varying limits); maxTreeLevels should be a number from 1 to 4 inclusive. |
| 378 | int maxTreeLevels = 4; |
| 379 | // On iOS we can exceed the maximum number of varyings. http://skbug.com/6627. |
| 380 | #ifdef SK_BUILD_FOR_IOS |
| 381 | maxTreeLevels = 2; |
| 382 | #endif |
| 383 | if (ctxInfo.type() == sk_gpu_test::GrContextFactory::kANGLE_D3D9_ES2_ContextType || |
| 384 | ctxInfo.type() == sk_gpu_test::GrContextFactory::kANGLE_D3D11_ES2_ContextType) { |
| 385 | // On Angle D3D we will hit a limit of out variables if we use too many stages. |
| 386 | maxTreeLevels = 2; |
| 387 | } |
| 388 | return maxTreeLevels; |
| 389 | } |
| 390 | |
Brian Salomon | e334c59 | 2017-05-15 11:00:58 -0400 | [diff] [blame] | 391 | static void test_glprograms(skiatest::Reporter* reporter, const sk_gpu_test::ContextInfo& ctxInfo) { |
Greg Daniel | d895ca6 | 2017-06-19 14:39:43 -0400 | [diff] [blame] | 392 | int maxStages = get_glprograms_max_stages(ctxInfo); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 393 | if (maxStages == 0) { |
| 394 | return; |
| 395 | } |
Greg Daniel | 78325c1 | 2017-06-19 16:39:13 -0400 | [diff] [blame] | 396 | int maxLevels = get_glprograms_max_levels(ctxInfo); |
| 397 | if (maxLevels == 0) { |
| 398 | return; |
| 399 | } |
Brian Osman | 9f772a4 | 2017-07-10 13:03:50 -0400 | [diff] [blame] | 400 | |
Greg Daniel | 78325c1 | 2017-06-19 16:39:13 -0400 | [diff] [blame] | 401 | REPORTER_ASSERT(reporter, GrDrawingManager::ProgramUnitTest(ctxInfo.grContext(), maxStages, |
| 402 | maxLevels)); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 403 | } |
| 404 | |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 405 | DEF_GPUTEST(GLPrograms, reporter, options) { |
bsalomon | 3318ee7 | 2015-03-16 11:56:29 -0700 | [diff] [blame] | 406 | // Set a locale that would cause shader compilation to fail because of , as decimal separator. |
| 407 | // skbug 3330 |
| 408 | #ifdef SK_BUILD_FOR_WIN |
| 409 | GrAutoLocaleSetter als("sv-SE"); |
| 410 | #else |
| 411 | GrAutoLocaleSetter als("sv_SE.UTF-8"); |
| 412 | #endif |
| 413 | |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 414 | // We suppress prints to avoid spew |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 415 | GrContextOptions opts = options; |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 416 | opts.fSuppressPrints = true; |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 417 | sk_gpu_test::GrContextFactory debugFactory(opts); |
Brian Salomon | e334c59 | 2017-05-15 11:00:58 -0400 | [diff] [blame] | 418 | skiatest::RunWithGPUTestContexts(test_glprograms, &skiatest::IsRenderingGLContextType, reporter, |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 419 | opts); |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 420 | } |
| 421 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 422 | #endif |