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 { |
Brian Osman | 978693c | 2020-01-24 14:52:10 -0500 | [diff] [blame] | 118 | SkString temp = this->invokeChild(0, args); |
Brian Osman | cddfc5e | 2020-01-24 10:24:27 -0500 | [diff] [blame] | 119 | args.fFragBuilder->codeAppendf("%s = %s;", args.fOutputColor, temp.c_str()); |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | private: |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 123 | typedef GrGLSLFragmentProcessor INHERITED; |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 124 | }; |
| 125 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 126 | BlockInputFragmentProcessor(std::unique_ptr<GrFragmentProcessor> child) |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 127 | : INHERITED(kBlockInputFragmentProcessor_ClassID, kNone_OptimizationFlags) { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 128 | this->registerChildProcessor(std::move(child)); |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 129 | } |
| 130 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 131 | void onGetGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override {} |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 132 | |
| 133 | bool onIsEqual(const GrFragmentProcessor&) const override { return true; } |
| 134 | |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 135 | typedef GrFragmentProcessor INHERITED; |
| 136 | }; |
| 137 | |
| 138 | ////////////////////////////////////////////////////////////////////////////// |
| 139 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 140 | /* |
| 141 | * Begin test code |
| 142 | */ |
| 143 | static const int kRenderTargetHeight = 1; |
| 144 | static const int kRenderTargetWidth = 1; |
| 145 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 146 | static std::unique_ptr<GrRenderTargetContext> random_render_target_context(GrContext* context, |
| 147 | SkRandom* random, |
| 148 | const GrCaps* caps) { |
robertphillips | 82ec6e5 | 2016-05-19 14:01:05 -0700 | [diff] [blame] | 149 | GrSurfaceOrigin origin = random->nextBool() ? kTopLeft_GrSurfaceOrigin |
| 150 | : kBottomLeft_GrSurfaceOrigin; |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 151 | |
Greg Daniel | 5c96db8 | 2019-07-09 14:06:58 -0400 | [diff] [blame] | 152 | GrColorType ct = GrColorType::kRGBA_8888; |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 153 | const GrBackendFormat format = caps->getDefaultBackendFormat(ct, GrRenderable::kYes); |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 154 | |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 155 | int sampleCnt = random->nextBool() ? caps->getRenderTargetSampleCount(2, format) : 1; |
Robert Phillips | d8f79a2 | 2019-06-24 13:25:42 -0400 | [diff] [blame] | 156 | // Above could be 0 if msaa isn't supported. |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 157 | sampleCnt = std::max(1, sampleCnt); |
Robert Phillips | d8f79a2 | 2019-06-24 13:25:42 -0400 | [diff] [blame] | 158 | |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 159 | return GrRenderTargetContext::Make( |
| 160 | context, GrColorType::kRGBA_8888, nullptr, SkBackingFit::kExact, |
| 161 | {kRenderTargetWidth, kRenderTargetHeight}, sampleCnt, GrMipMapped::kNo, |
| 162 | GrProtected::kNo, origin); |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 163 | } |
| 164 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 165 | #if GR_TEST_UTILS |
robertphillips | 28a838e | 2016-06-23 14:07:00 -0700 | [diff] [blame] | 166 | static void set_random_xpf(GrPaint* paint, GrProcessorTestData* d) { |
Brian Salomon | a163392 | 2017-01-09 11:46:10 -0500 | [diff] [blame] | 167 | paint->setXPFactory(GrXPFactoryTestFactory::Get(d)); |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 168 | } |
| 169 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 170 | static std::unique_ptr<GrFragmentProcessor> create_random_proc_tree(GrProcessorTestData* d, |
| 171 | int minLevels, int maxLevels) { |
wangyix | 059dffa | 2015-09-10 06:57:05 -0700 | [diff] [blame] | 172 | SkASSERT(1 <= minLevels); |
| 173 | SkASSERT(minLevels <= maxLevels); |
| 174 | |
| 175 | // Return a leaf node if maxLevels is 1 or if we randomly chose to terminate. |
| 176 | // If returning a leaf node, make sure that it doesn't have children (e.g. another |
| 177 | // GrComposeEffect) |
| 178 | const float terminateProbability = 0.3f; |
| 179 | if (1 == minLevels) { |
| 180 | bool terminate = (1 == maxLevels) || (d->fRandom->nextF() < terminateProbability); |
| 181 | if (terminate) { |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 182 | std::unique_ptr<GrFragmentProcessor> fp; |
wangyix | 059dffa | 2015-09-10 06:57:05 -0700 | [diff] [blame] | 183 | while (true) { |
Brian Salomon | 1c05364 | 2017-07-24 10:16:19 -0400 | [diff] [blame] | 184 | fp = GrFragmentProcessorTestFactory::Make(d); |
Ben Wagner | f1344ac | 2019-05-10 15:01:53 -0400 | [diff] [blame] | 185 | if (!fp) { |
| 186 | return nullptr; |
| 187 | } |
wangyix | 059dffa | 2015-09-10 06:57:05 -0700 | [diff] [blame] | 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)); |
Ben Wagner | f1344ac | 2019-05-10 15:01:53 -0400 | [diff] [blame] | 203 | if (!minLevelsChild || !otherChild) { |
| 204 | return nullptr; |
| 205 | } |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 206 | SkBlendMode mode = static_cast<SkBlendMode>(d->fRandom->nextRangeU(0, |
Brian Salomon | a12c153 | 2017-02-13 12:41:44 -0500 | [diff] [blame] | 207 | (int)SkBlendMode::kLastMode)); |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 208 | std::unique_ptr<GrFragmentProcessor> fp; |
wangyix | 059dffa | 2015-09-10 06:57:05 -0700 | [diff] [blame] | 209 | if (d->fRandom->nextF() < 0.5f) { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 210 | fp = GrXfermodeFragmentProcessor::MakeFromTwoProcessors(std::move(minLevelsChild), |
| 211 | std::move(otherChild), mode); |
wangyix | 059dffa | 2015-09-10 06:57:05 -0700 | [diff] [blame] | 212 | SkASSERT(fp); |
| 213 | } else { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 214 | fp = GrXfermodeFragmentProcessor::MakeFromTwoProcessors(std::move(otherChild), |
| 215 | std::move(minLevelsChild), mode); |
wangyix | 059dffa | 2015-09-10 06:57:05 -0700 | [diff] [blame] | 216 | SkASSERT(fp); |
| 217 | } |
| 218 | return fp; |
| 219 | } |
| 220 | |
robertphillips | 28a838e | 2016-06-23 14:07:00 -0700 | [diff] [blame] | 221 | static void set_random_color_coverage_stages(GrPaint* paint, |
| 222 | GrProcessorTestData* d, |
Greg Daniel | 78325c1 | 2017-06-19 16:39:13 -0400 | [diff] [blame] | 223 | int maxStages, |
| 224 | int maxTreeLevels) { |
wangyix | 059dffa | 2015-09-10 06:57:05 -0700 | [diff] [blame] | 225 | // Randomly choose to either create a linear pipeline of procs or create one proc tree |
| 226 | const float procTreeProbability = 0.5f; |
| 227 | if (d->fRandom->nextF() < procTreeProbability) { |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 228 | std::unique_ptr<GrFragmentProcessor> fp(create_random_proc_tree(d, 2, maxTreeLevels)); |
Robert Phillips | 1c9686b | 2017-06-30 08:40:28 -0400 | [diff] [blame] | 229 | if (fp) { |
| 230 | paint->addColorFragmentProcessor(std::move(fp)); |
| 231 | } |
wangyix | 059dffa | 2015-09-10 06:57:05 -0700 | [diff] [blame] | 232 | } else { |
| 233 | int numProcs = d->fRandom->nextULessThan(maxStages + 1); |
| 234 | int numColorProcs = d->fRandom->nextULessThan(numProcs + 1); |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 235 | |
Ben Wagner | f1344ac | 2019-05-10 15:01:53 -0400 | [diff] [blame] | 236 | for (int s = 0; s < numProcs; ++s) { |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 237 | std::unique_ptr<GrFragmentProcessor> fp(GrFragmentProcessorTestFactory::Make(d)); |
Ben Wagner | f1344ac | 2019-05-10 15:01:53 -0400 | [diff] [blame] | 238 | if (!fp) { |
| 239 | continue; |
| 240 | } |
wangyix | 059dffa | 2015-09-10 06:57:05 -0700 | [diff] [blame] | 241 | // finally add the stage to the correct pipeline in the drawstate |
| 242 | if (s < numColorProcs) { |
robertphillips | 28a838e | 2016-06-23 14:07:00 -0700 | [diff] [blame] | 243 | paint->addColorFragmentProcessor(std::move(fp)); |
wangyix | 059dffa | 2015-09-10 06:57:05 -0700 | [diff] [blame] | 244 | } else { |
robertphillips | 28a838e | 2016-06-23 14:07:00 -0700 | [diff] [blame] | 245 | paint->addCoverageFragmentProcessor(std::move(fp)); |
wangyix | 059dffa | 2015-09-10 06:57:05 -0700 | [diff] [blame] | 246 | } |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 247 | } |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 248 | } |
| 249 | } |
| 250 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 251 | #endif |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 252 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 253 | #if !GR_TEST_UTILS |
| 254 | bool GrDrawingManager::ProgramUnitTest(GrContext*, int) { return true; } |
| 255 | #else |
Greg Daniel | 78325c1 | 2017-06-19 16:39:13 -0400 | [diff] [blame] | 256 | bool GrDrawingManager::ProgramUnitTest(GrContext* context, int maxStages, int maxLevels) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 257 | GrDrawingManager* drawingManager = context->priv().drawingManager(); |
| 258 | GrProxyProvider* proxyProvider = context->priv().proxyProvider(); |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 259 | |
Greg Daniel | 026a60c | 2020-02-12 10:53:51 -0500 | [diff] [blame] | 260 | GrProcessorTestData::ViewInfo views[2]; |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 261 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 262 | // setup dummy textures |
Brian Salomon | 4687bdd | 2019-05-09 16:28:04 -0400 | [diff] [blame] | 263 | GrMipMapped mipMapped = GrMipMapped(context->priv().caps()->mipMapSupport()); |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 264 | { |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 265 | static constexpr SkISize kDummyDims = {34, 18}; |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 266 | const GrBackendFormat format = |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 267 | context->priv().caps()->getDefaultBackendFormat(GrColorType::kRGBA_8888, |
| 268 | GrRenderable::kYes); |
Greg Daniel | 47c20e8 | 2020-01-21 14:29:57 -0500 | [diff] [blame] | 269 | GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(format, GrColorType::kRGBA_8888); |
Greg Daniel | 026a60c | 2020-02-12 10:53:51 -0500 | [diff] [blame] | 270 | auto proxy = proxyProvider->createProxy(format, kDummyDims, swizzle, GrRenderable::kYes, 1, |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 271 | mipMapped, SkBackingFit::kExact, SkBudgeted::kNo, |
Greg Daniel | 026a60c | 2020-02-12 10:53:51 -0500 | [diff] [blame] | 272 | GrProtected::kNo, GrInternalSurfaceFlags::kNone); |
| 273 | views[0] = {{std::move(proxy), kBottomLeft_GrSurfaceOrigin, swizzle}, |
| 274 | GrColorType::kRGBA_8888, kPremul_SkAlphaType}; |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 275 | } |
| 276 | { |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 277 | static constexpr SkISize kDummyDims = {16, 22}; |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 278 | const GrBackendFormat format = |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 279 | context->priv().caps()->getDefaultBackendFormat(GrColorType::kAlpha_8, |
| 280 | GrRenderable::kNo); |
Greg Daniel | 47c20e8 | 2020-01-21 14:29:57 -0500 | [diff] [blame] | 281 | GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(format, GrColorType::kAlpha_8); |
Greg Daniel | 026a60c | 2020-02-12 10:53:51 -0500 | [diff] [blame] | 282 | auto proxy = proxyProvider->createProxy(format, kDummyDims, swizzle, GrRenderable::kNo, 1, |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 283 | mipMapped, SkBackingFit::kExact, SkBudgeted::kNo, |
Greg Daniel | 026a60c | 2020-02-12 10:53:51 -0500 | [diff] [blame] | 284 | GrProtected::kNo, GrInternalSurfaceFlags::kNone); |
| 285 | views[1] = {{std::move(proxy), kTopLeft_GrSurfaceOrigin, swizzle}, |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 286 | GrColorType::kAlpha_8, kPremul_SkAlphaType}; |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 287 | } |
bsalomon@google.com | d472620 | 2012-08-03 14:34:46 +0000 | [diff] [blame] | 288 | |
Greg Daniel | 026a60c | 2020-02-12 10:53:51 -0500 | [diff] [blame] | 289 | if (!std::get<0>(views[0]) || !std::get<0>(views[1])) { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 290 | SkDebugf("Could not allocate dummy textures"); |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 291 | return false; |
| 292 | } |
| 293 | |
Brian Osman | 9f772a4 | 2017-07-10 13:03:50 -0400 | [diff] [blame] | 294 | SkRandom random; |
bsalomon | f3261af | 2016-04-05 10:57:13 -0700 | [diff] [blame] | 295 | static const int NUM_TESTS = 1024; |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 296 | for (int t = 0; t < NUM_TESTS; t++) { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 297 | // setup random render target(can fail) |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 298 | auto renderTargetContext = |
| 299 | random_render_target_context(context, &random, context->priv().caps()); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 300 | if (!renderTargetContext) { |
| 301 | SkDebugf("Could not allocate renderTargetContext"); |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 302 | return false; |
| 303 | } |
robertphillips | 0dfa62c | 2015-11-16 06:23:31 -0800 | [diff] [blame] | 304 | |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 305 | GrPaint paint; |
Greg Daniel | 026a60c | 2020-02-12 10:53:51 -0500 | [diff] [blame] | 306 | GrProcessorTestData ptd(&random, context, 2, views); |
Greg Daniel | 78325c1 | 2017-06-19 16:39:13 -0400 | [diff] [blame] | 307 | set_random_color_coverage_stages(&paint, &ptd, maxStages, maxLevels); |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 308 | set_random_xpf(&paint, &ptd); |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 309 | GrDrawRandomOp(&random, renderTargetContext.get(), std::move(paint)); |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 310 | } |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 311 | // 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] | 312 | drawingManager->flush(nullptr, 0, SkSurface::BackendSurfaceAccess::kNoAccess, GrFlushInfo(), |
| 313 | GrPrepareForExternalIORequests()); |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 314 | |
| 315 | // Validate that GrFPs work correctly without an input. |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 316 | auto renderTargetContext = GrRenderTargetContext::Make( |
| 317 | context, GrColorType::kRGBA_8888, nullptr, SkBackingFit::kExact, |
| 318 | {kRenderTargetWidth, kRenderTargetHeight}); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 319 | if (!renderTargetContext) { |
| 320 | SkDebugf("Could not allocate a renderTargetContext"); |
robertphillips | 82ec6e5 | 2016-05-19 14:01:05 -0700 | [diff] [blame] | 321 | return false; |
| 322 | } |
| 323 | |
Brian Salomon | 1c05364 | 2017-07-24 10:16:19 -0400 | [diff] [blame] | 324 | int fpFactoryCnt = GrFragmentProcessorTestFactory::Count(); |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 325 | for (int i = 0; i < fpFactoryCnt; ++i) { |
| 326 | // Since FP factories internally randomize, call each 10 times. |
| 327 | for (int j = 0; j < 10; ++j) { |
Greg Daniel | 026a60c | 2020-02-12 10:53:51 -0500 | [diff] [blame] | 328 | GrProcessorTestData ptd(&random, context, 2, views); |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 329 | |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 330 | GrPaint paint; |
| 331 | paint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc)); |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 332 | auto fp = GrFragmentProcessorTestFactory::MakeIdx(i, &ptd); |
| 333 | auto blockFP = BlockInputFragmentProcessor::Make(std::move(fp)); |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 334 | paint.addColorFragmentProcessor(std::move(blockFP)); |
| 335 | GrDrawRandomOp(&random, renderTargetContext.get(), std::move(paint)); |
Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 336 | drawingManager->flush(nullptr, 0, SkSurface::BackendSurfaceAccess::kNoAccess, |
Greg Daniel | 797efca | 2019-05-09 14:04:20 -0400 | [diff] [blame] | 337 | GrFlushInfo(), GrPrepareForExternalIORequests()); |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 338 | } |
| 339 | } |
| 340 | |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 341 | return true; |
| 342 | } |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 343 | #endif |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 344 | |
Jim Van Verth | 5a8f3e4 | 2019-10-24 10:23:26 -0400 | [diff] [blame] | 345 | static int get_programs_max_stages(const sk_gpu_test::ContextInfo& ctxInfo) { |
Greg Daniel | d895ca6 | 2017-06-19 14:39:43 -0400 | [diff] [blame] | 346 | GrContext* context = ctxInfo.grContext(); |
Brian Salomon | e334c59 | 2017-05-15 11:00:58 -0400 | [diff] [blame] | 347 | int maxStages = 6; |
Jim Van Verth | 5a8f3e4 | 2019-10-24 10:23:26 -0400 | [diff] [blame] | 348 | if (skiatest::IsGLContextType(ctxInfo.type())) { |
| 349 | GrGLGpu* gpu = static_cast<GrGLGpu*>(context->priv().getGpu()); |
| 350 | if (kGLES_GrGLStandard == gpu->glStandard()) { |
| 351 | // We've had issues with driver crashes and HW limits being exceeded with many effects on |
| 352 | // Android devices. We have passes on ARM devices with the default number of stages. |
| 353 | // TODO When we run ES 3.00 GLSL in more places, test again |
Brian Salomon | e334c59 | 2017-05-15 11:00:58 -0400 | [diff] [blame] | 354 | #ifdef SK_BUILD_FOR_ANDROID |
Jim Van Verth | 5a8f3e4 | 2019-10-24 10:23:26 -0400 | [diff] [blame] | 355 | if (kARM_GrGLVendor != gpu->ctxInfo().vendor()) { |
| 356 | maxStages = 1; |
| 357 | } |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 358 | #endif |
Jim Van Verth | 5a8f3e4 | 2019-10-24 10:23:26 -0400 | [diff] [blame] | 359 | // 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] | 360 | #ifdef SK_BUILD_FOR_IOS |
Jim Van Verth | 5a8f3e4 | 2019-10-24 10:23:26 -0400 | [diff] [blame] | 361 | maxStages = 3; |
Brian Salomon | e334c59 | 2017-05-15 11:00:58 -0400 | [diff] [blame] | 362 | #endif |
Jim Van Verth | 5a8f3e4 | 2019-10-24 10:23:26 -0400 | [diff] [blame] | 363 | } |
| 364 | if (ctxInfo.type() == sk_gpu_test::GrContextFactory::kANGLE_D3D9_ES2_ContextType || |
| 365 | ctxInfo.type() == sk_gpu_test::GrContextFactory::kANGLE_D3D11_ES2_ContextType) { |
| 366 | // On Angle D3D we will hit a limit of out variables if we use too many stages. |
| 367 | maxStages = 3; |
| 368 | } |
Greg Daniel | d895ca6 | 2017-06-19 14:39:43 -0400 | [diff] [blame] | 369 | } |
Brian Salomon | e334c59 | 2017-05-15 11:00:58 -0400 | [diff] [blame] | 370 | return maxStages; |
| 371 | } |
| 372 | |
Jim Van Verth | 5a8f3e4 | 2019-10-24 10:23:26 -0400 | [diff] [blame] | 373 | static int get_programs_max_levels(const sk_gpu_test::ContextInfo& ctxInfo) { |
Greg Daniel | 78325c1 | 2017-06-19 16:39:13 -0400 | [diff] [blame] | 374 | // A full tree with 5 levels (31 nodes) may cause a program that exceeds shader limits |
| 375 | // (e.g. uniform or varying limits); maxTreeLevels should be a number from 1 to 4 inclusive. |
| 376 | int maxTreeLevels = 4; |
Jim Van Verth | 5a8f3e4 | 2019-10-24 10:23:26 -0400 | [diff] [blame] | 377 | if (skiatest::IsGLContextType(ctxInfo.type())) { |
| 378 | // On iOS we can exceed the maximum number of varyings. http://skbug.com/6627. |
Greg Daniel | 78325c1 | 2017-06-19 16:39:13 -0400 | [diff] [blame] | 379 | #ifdef SK_BUILD_FOR_IOS |
Michael Ludwig | 6387dc1 | 2019-10-22 15:39:41 +0000 | [diff] [blame] | 380 | maxTreeLevels = 2; |
Jim Van Verth | 5a8f3e4 | 2019-10-24 10:23:26 -0400 | [diff] [blame] | 381 | #endif |
Brian Salomon | 9c4ee9c | 2019-12-20 16:20:54 -0500 | [diff] [blame] | 382 | #ifdef SK_BUILD_FOR_ANDROID |
| 383 | GrGLGpu* gpu = static_cast<GrGLGpu*>(ctxInfo.grContext()->priv().getGpu()); |
| 384 | // Tecno Spark 3 Pro with Power VR Rogue GE8300 will fail shader compiles with |
| 385 | // no message if the shader is particularly long. |
| 386 | if (gpu->ctxInfo().vendor() == kImagination_GrGLVendor) { |
| 387 | maxTreeLevels = 3; |
| 388 | } |
| 389 | #endif |
Jim Van Verth | 5a8f3e4 | 2019-10-24 10:23:26 -0400 | [diff] [blame] | 390 | if (ctxInfo.type() == sk_gpu_test::GrContextFactory::kANGLE_D3D9_ES2_ContextType || |
| 391 | ctxInfo.type() == sk_gpu_test::GrContextFactory::kANGLE_D3D11_ES2_ContextType) { |
| 392 | // On Angle D3D we will hit a limit of out variables if we use too many stages. |
| 393 | maxTreeLevels = 2; |
| 394 | } |
Greg Daniel | 78325c1 | 2017-06-19 16:39:13 -0400 | [diff] [blame] | 395 | } |
| 396 | return maxTreeLevels; |
| 397 | } |
| 398 | |
Jim Van Verth | 5a8f3e4 | 2019-10-24 10:23:26 -0400 | [diff] [blame] | 399 | static void test_programs(skiatest::Reporter* reporter, const sk_gpu_test::ContextInfo& ctxInfo) { |
| 400 | int maxStages = get_programs_max_stages(ctxInfo); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 401 | if (maxStages == 0) { |
| 402 | return; |
| 403 | } |
Jim Van Verth | 5a8f3e4 | 2019-10-24 10:23:26 -0400 | [diff] [blame] | 404 | int maxLevels = get_programs_max_levels(ctxInfo); |
Greg Daniel | 78325c1 | 2017-06-19 16:39:13 -0400 | [diff] [blame] | 405 | if (maxLevels == 0) { |
| 406 | return; |
| 407 | } |
Brian Osman | 9f772a4 | 2017-07-10 13:03:50 -0400 | [diff] [blame] | 408 | |
Greg Daniel | 78325c1 | 2017-06-19 16:39:13 -0400 | [diff] [blame] | 409 | REPORTER_ASSERT(reporter, GrDrawingManager::ProgramUnitTest(ctxInfo.grContext(), maxStages, |
| 410 | maxLevels)); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 411 | } |
| 412 | |
Jim Van Verth | 5a8f3e4 | 2019-10-24 10:23:26 -0400 | [diff] [blame] | 413 | DEF_GPUTEST(Programs, reporter, options) { |
bsalomon | 3318ee7 | 2015-03-16 11:56:29 -0700 | [diff] [blame] | 414 | // Set a locale that would cause shader compilation to fail because of , as decimal separator. |
| 415 | // skbug 3330 |
| 416 | #ifdef SK_BUILD_FOR_WIN |
| 417 | GrAutoLocaleSetter als("sv-SE"); |
| 418 | #else |
| 419 | GrAutoLocaleSetter als("sv_SE.UTF-8"); |
| 420 | #endif |
| 421 | |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 422 | // We suppress prints to avoid spew |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 423 | GrContextOptions opts = options; |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 424 | opts.fSuppressPrints = true; |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 425 | sk_gpu_test::GrContextFactory debugFactory(opts); |
Jim Van Verth | 5a8f3e4 | 2019-10-24 10:23:26 -0400 | [diff] [blame] | 426 | skiatest::RunWithGPUTestContexts(test_programs, &skiatest::IsRenderingGLOrMetalContextType, |
| 427 | reporter, opts); |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 428 | } |