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