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 | |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 12 | #include "include/gpu/GrDirectContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "include/private/SkChecksum.h" |
| 14 | #include "include/utils/SkRandom.h" |
| 15 | #include "src/gpu/GrAutoLocaleSetter.h" |
Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 16 | #include "src/gpu/GrDirectContextPriv.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 17 | #include "src/gpu/GrDrawOpTest.h" |
| 18 | #include "src/gpu/GrDrawingManager.h" |
| 19 | #include "src/gpu/GrPipeline.h" |
Robert Phillips | e19babf | 2020-04-06 13:57:30 -0400 | [diff] [blame] | 20 | #include "src/gpu/GrProxyProvider.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 21 | #include "src/gpu/GrXferProcessor.h" |
John Stiles | f743d4e | 2020-07-23 11:35:08 -0400 | [diff] [blame] | 22 | #include "src/gpu/effects/GrBlendFragmentProcessor.h" |
Brian Salomon | 1171d31 | 2020-03-19 08:47:44 -0400 | [diff] [blame] | 23 | #include "src/gpu/effects/GrPorterDuffXferProcessor.h" |
Brian Salomon | 1171d31 | 2020-03-19 08:47:44 -0400 | [diff] [blame] | 24 | #include "src/gpu/effects/generated/GrConfigConversionEffect.h" |
Brian Salomon | 1171d31 | 2020-03-19 08:47:44 -0400 | [diff] [blame] | 25 | #include "src/gpu/glsl/GrGLSLFragmentProcessor.h" |
| 26 | #include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h" |
| 27 | #include "src/gpu/glsl/GrGLSLProgramBuilder.h" |
Brian Salomon | f4ba4ec | 2020-03-19 15:54:28 -0400 | [diff] [blame] | 28 | #include "src/gpu/ops/GrDrawOp.h" |
| 29 | #include "tests/Test.h" |
| 30 | #include "tools/gpu/GrContextFactory.h" |
| 31 | |
| 32 | #ifdef SK_GL |
| 33 | #include "src/gpu/gl/GrGLGpu.h" |
| 34 | #endif |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 35 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 36 | /* |
bsalomon | 98b33eb | 2014-10-15 11:05:26 -0700 | [diff] [blame] | 37 | * 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] | 38 | * whole thing correctly |
| 39 | */ |
| 40 | static const uint32_t kMaxKeySize = 1024; |
| 41 | |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 42 | class GLBigKeyProcessor : public GrGLSLFragmentProcessor { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 43 | public: |
robertphillips | 9cdb992 | 2016-02-03 12:25:40 -0800 | [diff] [blame] | 44 | void emitCode(EmitArgs& args) override { |
Brian Osman | 03f9e2a | 2020-12-08 11:17:26 -0500 | [diff] [blame] | 45 | args.fFragBuilder->codeAppendf("%s = half4(1);\n", args.fOutputColor); |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 46 | } |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 47 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 48 | static void GenKey(const GrProcessor&, const GrShaderCaps&, GrProcessorKeyBuilder* b) { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 49 | for (uint32_t i = 0; i < kMaxKeySize; i++) { |
| 50 | b->add32(i); |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 51 | } |
joshualitt | d909759 | 2014-10-07 08:37:36 -0700 | [diff] [blame] | 52 | } |
| 53 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 54 | private: |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 55 | using INHERITED = GrGLSLFragmentProcessor; |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 58 | class BigKeyProcessor : public GrFragmentProcessor { |
| 59 | public: |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 60 | static std::unique_ptr<GrFragmentProcessor> Make() { |
| 61 | return std::unique_ptr<GrFragmentProcessor>(new BigKeyProcessor); |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 62 | } |
| 63 | |
Ethan Nicholas | 7c75226 | 2020-04-01 14:18:28 -0400 | [diff] [blame] | 64 | const char* name() const override { return "Big_Ole_Key"; } |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 65 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 66 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { |
robertphillips | 9cdb992 | 2016-02-03 12:25:40 -0800 | [diff] [blame] | 67 | return new GLBigKeyProcessor; |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 68 | } |
| 69 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 70 | std::unique_ptr<GrFragmentProcessor> clone() const override { return Make(); } |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 71 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 72 | private: |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 73 | BigKeyProcessor() : INHERITED(kBigKeyProcessor_ClassID, kNone_OptimizationFlags) { } |
John Stiles | 1cf2c8d | 2020-08-13 22:58:04 -0400 | [diff] [blame] | 74 | void onGetGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override { |
wangyix | 4b3050b | 2015-08-04 07:59:37 -0700 | [diff] [blame] | 75 | GLBigKeyProcessor::GenKey(*this, caps, b); |
| 76 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 77 | bool onIsEqual(const GrFragmentProcessor&) const override { return true; } |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 78 | |
Brian Salomon | 0c26a9d | 2017-07-06 10:09:38 -0400 | [diff] [blame] | 79 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 80 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 81 | using INHERITED = GrFragmentProcessor; |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(BigKeyProcessor); |
| 85 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 86 | #if GR_TEST_UTILS |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 87 | std::unique_ptr<GrFragmentProcessor> BigKeyProcessor::TestCreate(GrProcessorTestData*) { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 88 | return BigKeyProcessor::Make(); |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 89 | } |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 90 | #endif |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 91 | |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 92 | ////////////////////////////////////////////////////////////////////////////// |
| 93 | |
| 94 | class BlockInputFragmentProcessor : public GrFragmentProcessor { |
| 95 | public: |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 96 | static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> fp) { |
| 97 | return std::unique_ptr<GrFragmentProcessor>(new BlockInputFragmentProcessor(std::move(fp))); |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 98 | } |
| 99 | |
Brian Salomon | f49debf | 2020-04-17 10:35:38 -0400 | [diff] [blame] | 100 | const char* name() const override { return "Block_Input"; } |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 101 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 102 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { return new GLFP; } |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 103 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 104 | std::unique_ptr<GrFragmentProcessor> clone() const override { |
Brian Osman | 12c5d29 | 2020-07-13 16:11:35 -0400 | [diff] [blame] | 105 | return Make(this->childProcessor(0)->clone()); |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 106 | } |
| 107 | |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 108 | private: |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 109 | class GLFP : public GrGLSLFragmentProcessor { |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 110 | public: |
| 111 | void emitCode(EmitArgs& args) override { |
Brian Osman | 978693c | 2020-01-24 14:52:10 -0500 | [diff] [blame] | 112 | SkString temp = this->invokeChild(0, args); |
Brian Osman | cddfc5e | 2020-01-24 10:24:27 -0500 | [diff] [blame] | 113 | args.fFragBuilder->codeAppendf("%s = %s;", args.fOutputColor, temp.c_str()); |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | private: |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 117 | using INHERITED = GrGLSLFragmentProcessor; |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 118 | }; |
| 119 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 120 | BlockInputFragmentProcessor(std::unique_ptr<GrFragmentProcessor> child) |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 121 | : INHERITED(kBlockInputFragmentProcessor_ClassID, kNone_OptimizationFlags) { |
Michael Ludwig | 9aba625 | 2020-06-22 14:46:36 -0400 | [diff] [blame] | 122 | this->registerChild(std::move(child)); |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 125 | void onGetGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override {} |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 126 | |
| 127 | bool onIsEqual(const GrFragmentProcessor&) const override { return true; } |
| 128 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 129 | using INHERITED = GrFragmentProcessor; |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 130 | }; |
| 131 | |
| 132 | ////////////////////////////////////////////////////////////////////////////// |
| 133 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 134 | /* |
| 135 | * Begin test code |
| 136 | */ |
| 137 | static const int kRenderTargetHeight = 1; |
| 138 | static const int kRenderTargetWidth = 1; |
| 139 | |
Brian Salomon | eebe735 | 2020-12-09 16:37:04 -0500 | [diff] [blame] | 140 | static std::unique_ptr<GrSurfaceDrawContext> random_render_target_context( |
Robert Phillips | 58adb34 | 2020-07-23 09:41:57 -0400 | [diff] [blame] | 141 | GrRecordingContext* rContext, |
| 142 | SkRandom* random, |
| 143 | const GrCaps* caps) { |
robertphillips | 82ec6e5 | 2016-05-19 14:01:05 -0700 | [diff] [blame] | 144 | GrSurfaceOrigin origin = random->nextBool() ? kTopLeft_GrSurfaceOrigin |
| 145 | : kBottomLeft_GrSurfaceOrigin; |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 146 | |
Greg Daniel | 5c96db8 | 2019-07-09 14:06:58 -0400 | [diff] [blame] | 147 | GrColorType ct = GrColorType::kRGBA_8888; |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 148 | const GrBackendFormat format = caps->getDefaultBackendFormat(ct, GrRenderable::kYes); |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 149 | |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 150 | int sampleCnt = random->nextBool() ? caps->getRenderTargetSampleCount(2, format) : 1; |
Robert Phillips | d8f79a2 | 2019-06-24 13:25:42 -0400 | [diff] [blame] | 151 | // Above could be 0 if msaa isn't supported. |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 152 | sampleCnt = std::max(1, sampleCnt); |
Robert Phillips | d8f79a2 | 2019-06-24 13:25:42 -0400 | [diff] [blame] | 153 | |
Brian Salomon | eebe735 | 2020-12-09 16:37:04 -0500 | [diff] [blame] | 154 | return GrSurfaceDrawContext::Make( |
Robert Phillips | 58adb34 | 2020-07-23 09:41:57 -0400 | [diff] [blame] | 155 | rContext, GrColorType::kRGBA_8888, nullptr, SkBackingFit::kExact, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 156 | {kRenderTargetWidth, kRenderTargetHeight}, sampleCnt, GrMipmapped::kNo, |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 157 | GrProtected::kNo, origin); |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 158 | } |
| 159 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 160 | #if GR_TEST_UTILS |
robertphillips | 28a838e | 2016-06-23 14:07:00 -0700 | [diff] [blame] | 161 | static void set_random_xpf(GrPaint* paint, GrProcessorTestData* d) { |
Brian Salomon | a163392 | 2017-01-09 11:46:10 -0500 | [diff] [blame] | 162 | paint->setXPFactory(GrXPFactoryTestFactory::Get(d)); |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 163 | } |
| 164 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 165 | static std::unique_ptr<GrFragmentProcessor> create_random_proc_tree(GrProcessorTestData* d, |
| 166 | int minLevels, int maxLevels) { |
wangyix | 059dffa | 2015-09-10 06:57:05 -0700 | [diff] [blame] | 167 | SkASSERT(1 <= minLevels); |
| 168 | SkASSERT(minLevels <= maxLevels); |
| 169 | |
| 170 | // Return a leaf node if maxLevels is 1 or if we randomly chose to terminate. |
| 171 | // If returning a leaf node, make sure that it doesn't have children (e.g. another |
| 172 | // GrComposeEffect) |
| 173 | const float terminateProbability = 0.3f; |
| 174 | if (1 == minLevels) { |
| 175 | bool terminate = (1 == maxLevels) || (d->fRandom->nextF() < terminateProbability); |
| 176 | if (terminate) { |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 177 | std::unique_ptr<GrFragmentProcessor> fp; |
wangyix | 059dffa | 2015-09-10 06:57:05 -0700 | [diff] [blame] | 178 | while (true) { |
Brian Salomon | 1c05364 | 2017-07-24 10:16:19 -0400 | [diff] [blame] | 179 | fp = GrFragmentProcessorTestFactory::Make(d); |
Ben Wagner | f1344ac | 2019-05-10 15:01:53 -0400 | [diff] [blame] | 180 | if (!fp) { |
| 181 | return nullptr; |
| 182 | } |
Brian Osman | 12c5d29 | 2020-07-13 16:11:35 -0400 | [diff] [blame] | 183 | if (0 == fp->numNonNullChildProcessors()) { |
wangyix | 059dffa | 2015-09-10 06:57:05 -0700 | [diff] [blame] | 184 | break; |
| 185 | } |
wangyix | 059dffa | 2015-09-10 06:57:05 -0700 | [diff] [blame] | 186 | } |
| 187 | return fp; |
| 188 | } |
| 189 | } |
| 190 | // If we didn't terminate, choose either the left or right subtree to fulfill |
| 191 | // 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] | 192 | // Also choose a random xfer mode. |
wangyix | 059dffa | 2015-09-10 06:57:05 -0700 | [diff] [blame] | 193 | if (minLevels > 1) { |
| 194 | --minLevels; |
| 195 | } |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 196 | auto minLevelsChild = create_random_proc_tree(d, minLevels, maxLevels - 1); |
| 197 | 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] | 198 | if (!minLevelsChild || !otherChild) { |
| 199 | return nullptr; |
| 200 | } |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 201 | SkBlendMode mode = static_cast<SkBlendMode>(d->fRandom->nextRangeU(0, |
Brian Salomon | a12c153 | 2017-02-13 12:41:44 -0500 | [diff] [blame] | 202 | (int)SkBlendMode::kLastMode)); |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 203 | std::unique_ptr<GrFragmentProcessor> fp; |
wangyix | 059dffa | 2015-09-10 06:57:05 -0700 | [diff] [blame] | 204 | if (d->fRandom->nextF() < 0.5f) { |
John Stiles | f743d4e | 2020-07-23 11:35:08 -0400 | [diff] [blame] | 205 | fp = GrBlendFragmentProcessor::Make(std::move(minLevelsChild), std::move(otherChild), mode); |
wangyix | 059dffa | 2015-09-10 06:57:05 -0700 | [diff] [blame] | 206 | SkASSERT(fp); |
| 207 | } else { |
John Stiles | f743d4e | 2020-07-23 11:35:08 -0400 | [diff] [blame] | 208 | fp = GrBlendFragmentProcessor::Make(std::move(otherChild), std::move(minLevelsChild), mode); |
wangyix | 059dffa | 2015-09-10 06:57:05 -0700 | [diff] [blame] | 209 | SkASSERT(fp); |
| 210 | } |
| 211 | return fp; |
| 212 | } |
| 213 | |
robertphillips | 28a838e | 2016-06-23 14:07:00 -0700 | [diff] [blame] | 214 | static void set_random_color_coverage_stages(GrPaint* paint, |
| 215 | GrProcessorTestData* d, |
Greg Daniel | 78325c1 | 2017-06-19 16:39:13 -0400 | [diff] [blame] | 216 | int maxStages, |
| 217 | int maxTreeLevels) { |
wangyix | 059dffa | 2015-09-10 06:57:05 -0700 | [diff] [blame] | 218 | // Randomly choose to either create a linear pipeline of procs or create one proc tree |
| 219 | const float procTreeProbability = 0.5f; |
| 220 | if (d->fRandom->nextF() < procTreeProbability) { |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 221 | std::unique_ptr<GrFragmentProcessor> fp(create_random_proc_tree(d, 2, maxTreeLevels)); |
Robert Phillips | 1c9686b | 2017-06-30 08:40:28 -0400 | [diff] [blame] | 222 | if (fp) { |
John Stiles | 5933d7d | 2020-07-21 12:28:35 -0400 | [diff] [blame] | 223 | paint->setColorFragmentProcessor(std::move(fp)); |
Robert Phillips | 1c9686b | 2017-06-30 08:40:28 -0400 | [diff] [blame] | 224 | } |
wangyix | 059dffa | 2015-09-10 06:57:05 -0700 | [diff] [blame] | 225 | } else { |
John Stiles | 41d91b6 | 2020-07-21 14:39:40 -0400 | [diff] [blame] | 226 | if (maxStages >= 1) { |
| 227 | if (std::unique_ptr<GrFragmentProcessor> fp = GrFragmentProcessorTestFactory::Make(d)) { |
John Stiles | 5933d7d | 2020-07-21 12:28:35 -0400 | [diff] [blame] | 228 | paint->setColorFragmentProcessor(std::move(fp)); |
John Stiles | 41d91b6 | 2020-07-21 14:39:40 -0400 | [diff] [blame] | 229 | } |
| 230 | } |
| 231 | if (maxStages >= 2) { |
| 232 | if (std::unique_ptr<GrFragmentProcessor> fp = GrFragmentProcessorTestFactory::Make(d)) { |
| 233 | paint->setCoverageFragmentProcessor(std::move(fp)); |
wangyix | 059dffa | 2015-09-10 06:57:05 -0700 | [diff] [blame] | 234 | } |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 235 | } |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 236 | } |
| 237 | } |
| 238 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 239 | #endif |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 240 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 241 | #if !GR_TEST_UTILS |
Robert Phillips | 4e105e2 | 2020-07-16 09:18:50 -0400 | [diff] [blame] | 242 | bool GrDrawingManager::ProgramUnitTest(GrDirectContext*, int) { return true; } |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 243 | #else |
Robert Phillips | 4e105e2 | 2020-07-16 09:18:50 -0400 | [diff] [blame] | 244 | bool GrDrawingManager::ProgramUnitTest(GrDirectContext* direct, int maxStages, int maxLevels) { |
| 245 | GrProxyProvider* proxyProvider = direct->priv().proxyProvider(); |
| 246 | const GrCaps* caps = direct->priv().caps(); |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 247 | |
Greg Daniel | 026a60c | 2020-02-12 10:53:51 -0500 | [diff] [blame] | 248 | GrProcessorTestData::ViewInfo views[2]; |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 249 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 250 | // setup dummy textures |
Brian Salomon | 69100f0 | 2020-07-21 10:49:25 -0400 | [diff] [blame] | 251 | GrMipmapped mipMapped = GrMipmapped(caps->mipmapSupport()); |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 252 | { |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 253 | static constexpr SkISize kDummyDims = {34, 18}; |
Robert Phillips | 4e105e2 | 2020-07-16 09:18:50 -0400 | [diff] [blame] | 254 | const GrBackendFormat format = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888, |
| 255 | GrRenderable::kYes); |
Brian Salomon | df1bd6d | 2020-03-26 20:37:01 -0400 | [diff] [blame] | 256 | auto proxy = proxyProvider->createProxy(format, kDummyDims, GrRenderable::kYes, 1, |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 257 | mipMapped, SkBackingFit::kExact, SkBudgeted::kNo, |
Greg Daniel | 026a60c | 2020-02-12 10:53:51 -0500 | [diff] [blame] | 258 | GrProtected::kNo, GrInternalSurfaceFlags::kNone); |
Robert Phillips | 4e105e2 | 2020-07-16 09:18:50 -0400 | [diff] [blame] | 259 | GrSwizzle swizzle = caps->getReadSwizzle(format, GrColorType::kRGBA_8888); |
Greg Daniel | 026a60c | 2020-02-12 10:53:51 -0500 | [diff] [blame] | 260 | views[0] = {{std::move(proxy), kBottomLeft_GrSurfaceOrigin, swizzle}, |
| 261 | GrColorType::kRGBA_8888, kPremul_SkAlphaType}; |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 262 | } |
| 263 | { |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 264 | static constexpr SkISize kDummyDims = {16, 22}; |
Robert Phillips | 4e105e2 | 2020-07-16 09:18:50 -0400 | [diff] [blame] | 265 | const GrBackendFormat format = caps->getDefaultBackendFormat(GrColorType::kAlpha_8, |
| 266 | GrRenderable::kNo); |
Brian Salomon | df1bd6d | 2020-03-26 20:37:01 -0400 | [diff] [blame] | 267 | auto proxy = proxyProvider->createProxy(format, kDummyDims, GrRenderable::kNo, 1, mipMapped, |
| 268 | SkBackingFit::kExact, SkBudgeted::kNo, |
Greg Daniel | 026a60c | 2020-02-12 10:53:51 -0500 | [diff] [blame] | 269 | GrProtected::kNo, GrInternalSurfaceFlags::kNone); |
Robert Phillips | 4e105e2 | 2020-07-16 09:18:50 -0400 | [diff] [blame] | 270 | GrSwizzle swizzle = caps->getReadSwizzle(format, GrColorType::kAlpha_8); |
Greg Daniel | 026a60c | 2020-02-12 10:53:51 -0500 | [diff] [blame] | 271 | views[1] = {{std::move(proxy), kTopLeft_GrSurfaceOrigin, swizzle}, |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 272 | GrColorType::kAlpha_8, kPremul_SkAlphaType}; |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 273 | } |
bsalomon@google.com | d472620 | 2012-08-03 14:34:46 +0000 | [diff] [blame] | 274 | |
Greg Daniel | 026a60c | 2020-02-12 10:53:51 -0500 | [diff] [blame] | 275 | if (!std::get<0>(views[0]) || !std::get<0>(views[1])) { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 276 | SkDebugf("Could not allocate dummy textures"); |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 277 | return false; |
| 278 | } |
| 279 | |
Brian Osman | 9f772a4 | 2017-07-10 13:03:50 -0400 | [diff] [blame] | 280 | SkRandom random; |
bsalomon | f3261af | 2016-04-05 10:57:13 -0700 | [diff] [blame] | 281 | static const int NUM_TESTS = 1024; |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 282 | for (int t = 0; t < NUM_TESTS; t++) { |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 283 | // setup random render target(can fail) |
Robert Phillips | 4e105e2 | 2020-07-16 09:18:50 -0400 | [diff] [blame] | 284 | auto renderTargetContext = random_render_target_context(direct, &random, caps); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 285 | if (!renderTargetContext) { |
| 286 | SkDebugf("Could not allocate renderTargetContext"); |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 287 | return false; |
| 288 | } |
robertphillips | 0dfa62c | 2015-11-16 06:23:31 -0800 | [diff] [blame] | 289 | |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 290 | GrPaint paint; |
John Stiles | 87d0a2f | 2020-08-10 13:12:41 -0400 | [diff] [blame] | 291 | GrProcessorTestData ptd(&random, direct, /*maxTreeDepth=*/1, SK_ARRAY_COUNT(views), views); |
Greg Daniel | 78325c1 | 2017-06-19 16:39:13 -0400 | [diff] [blame] | 292 | set_random_color_coverage_stages(&paint, &ptd, maxStages, maxLevels); |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 293 | set_random_xpf(&paint, &ptd); |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 294 | GrDrawRandomOp(&random, renderTargetContext.get(), std::move(paint)); |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 295 | } |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 296 | // Flush everything, test passes if flush is successful(ie, no asserts are hit, no crashes) |
Robert Phillips | 4e105e2 | 2020-07-16 09:18:50 -0400 | [diff] [blame] | 297 | direct->flush(GrFlushInfo()); |
| 298 | direct->submit(false); |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 299 | |
| 300 | // Validate that GrFPs work correctly without an input. |
Brian Salomon | eebe735 | 2020-12-09 16:37:04 -0500 | [diff] [blame] | 301 | auto renderTargetContext = GrSurfaceDrawContext::Make( |
Robert Phillips | 4e105e2 | 2020-07-16 09:18:50 -0400 | [diff] [blame] | 302 | direct, GrColorType::kRGBA_8888, nullptr, SkBackingFit::kExact, |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 303 | {kRenderTargetWidth, kRenderTargetHeight}); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 304 | if (!renderTargetContext) { |
| 305 | SkDebugf("Could not allocate a renderTargetContext"); |
robertphillips | 82ec6e5 | 2016-05-19 14:01:05 -0700 | [diff] [blame] | 306 | return false; |
| 307 | } |
| 308 | |
Brian Salomon | 1c05364 | 2017-07-24 10:16:19 -0400 | [diff] [blame] | 309 | int fpFactoryCnt = GrFragmentProcessorTestFactory::Count(); |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 310 | for (int i = 0; i < fpFactoryCnt; ++i) { |
| 311 | // Since FP factories internally randomize, call each 10 times. |
| 312 | for (int j = 0; j < 10; ++j) { |
John Stiles | 87d0a2f | 2020-08-10 13:12:41 -0400 | [diff] [blame] | 313 | GrProcessorTestData ptd(&random, direct, /*maxTreeDepth=*/1, SK_ARRAY_COUNT(views), |
| 314 | views); |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 315 | |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 316 | GrPaint paint; |
| 317 | paint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc)); |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 318 | auto fp = GrFragmentProcessorTestFactory::MakeIdx(i, &ptd); |
| 319 | auto blockFP = BlockInputFragmentProcessor::Make(std::move(fp)); |
John Stiles | 5933d7d | 2020-07-21 12:28:35 -0400 | [diff] [blame] | 320 | paint.setColorFragmentProcessor(std::move(blockFP)); |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 321 | GrDrawRandomOp(&random, renderTargetContext.get(), std::move(paint)); |
Robert Phillips | 4e105e2 | 2020-07-16 09:18:50 -0400 | [diff] [blame] | 322 | |
| 323 | direct->flush(GrFlushInfo()); |
| 324 | direct->submit(false); |
bsalomon | b5b6032 | 2015-09-14 12:26:33 -0700 | [diff] [blame] | 325 | } |
| 326 | } |
| 327 | |
bsalomon@google.com | c3841b9 | 2012-08-02 18:11:43 +0000 | [diff] [blame] | 328 | return true; |
| 329 | } |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 330 | #endif |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 331 | |
Jim Van Verth | 5a8f3e4 | 2019-10-24 10:23:26 -0400 | [diff] [blame] | 332 | static int get_programs_max_stages(const sk_gpu_test::ContextInfo& ctxInfo) { |
Brian Salomon | 1171d31 | 2020-03-19 08:47:44 -0400 | [diff] [blame] | 333 | int maxStages = 6; |
Brian Salomon | f4ba4ec | 2020-03-19 15:54:28 -0400 | [diff] [blame] | 334 | #ifdef SK_GL |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 335 | auto context = ctxInfo.directContext(); |
Jim Van Verth | 5a8f3e4 | 2019-10-24 10:23:26 -0400 | [diff] [blame] | 336 | if (skiatest::IsGLContextType(ctxInfo.type())) { |
| 337 | GrGLGpu* gpu = static_cast<GrGLGpu*>(context->priv().getGpu()); |
| 338 | if (kGLES_GrGLStandard == gpu->glStandard()) { |
| 339 | // We've had issues with driver crashes and HW limits being exceeded with many effects on |
| 340 | // Android devices. We have passes on ARM devices with the default number of stages. |
| 341 | // 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] | 342 | #ifdef SK_BUILD_FOR_ANDROID |
Jim Van Verth | 5a8f3e4 | 2019-10-24 10:23:26 -0400 | [diff] [blame] | 343 | if (kARM_GrGLVendor != gpu->ctxInfo().vendor()) { |
| 344 | maxStages = 1; |
| 345 | } |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 346 | #endif |
Jim Van Verth | 5a8f3e4 | 2019-10-24 10:23:26 -0400 | [diff] [blame] | 347 | // 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] | 348 | #ifdef SK_BUILD_FOR_IOS |
Jim Van Verth | 5a8f3e4 | 2019-10-24 10:23:26 -0400 | [diff] [blame] | 349 | maxStages = 3; |
Brian Salomon | e334c59 | 2017-05-15 11:00:58 -0400 | [diff] [blame] | 350 | #endif |
Jim Van Verth | 5a8f3e4 | 2019-10-24 10:23:26 -0400 | [diff] [blame] | 351 | } |
Brian Salomon | b0aab2c | 2020-04-16 16:01:25 -0400 | [diff] [blame] | 352 | // On Angle D3D we will hit a limit of out variables if we use too many stages. This is |
| 353 | // particularly true on D3D9 with a low limit on varyings and the fact that every varying is |
| 354 | // packed as though it has 4 components. |
| 355 | if (ctxInfo.type() == sk_gpu_test::GrContextFactory::kANGLE_D3D9_ES2_ContextType) { |
| 356 | maxStages = 2; |
| 357 | } else if (ctxInfo.type() == sk_gpu_test::GrContextFactory::kANGLE_D3D11_ES2_ContextType) { |
Jim Van Verth | 5a8f3e4 | 2019-10-24 10:23:26 -0400 | [diff] [blame] | 358 | maxStages = 3; |
| 359 | } |
Greg Daniel | d895ca6 | 2017-06-19 14:39:43 -0400 | [diff] [blame] | 360 | } |
Brian Salomon | f4ba4ec | 2020-03-19 15:54:28 -0400 | [diff] [blame] | 361 | #endif |
Brian Salomon | e334c59 | 2017-05-15 11:00:58 -0400 | [diff] [blame] | 362 | return maxStages; |
| 363 | } |
| 364 | |
Jim Van Verth | 5a8f3e4 | 2019-10-24 10:23:26 -0400 | [diff] [blame] | 365 | static int get_programs_max_levels(const sk_gpu_test::ContextInfo& ctxInfo) { |
Greg Daniel | 78325c1 | 2017-06-19 16:39:13 -0400 | [diff] [blame] | 366 | // A full tree with 5 levels (31 nodes) may cause a program that exceeds shader limits |
| 367 | // (e.g. uniform or varying limits); maxTreeLevels should be a number from 1 to 4 inclusive. |
| 368 | int maxTreeLevels = 4; |
Jim Van Verth | 5a8f3e4 | 2019-10-24 10:23:26 -0400 | [diff] [blame] | 369 | if (skiatest::IsGLContextType(ctxInfo.type())) { |
| 370 | // 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] | 371 | #ifdef SK_BUILD_FOR_IOS |
Michael Ludwig | 6387dc1 | 2019-10-22 15:39:41 +0000 | [diff] [blame] | 372 | maxTreeLevels = 2; |
Jim Van Verth | 5a8f3e4 | 2019-10-24 10:23:26 -0400 | [diff] [blame] | 373 | #endif |
Brian Salomon | 32d41b7 | 2020-09-21 10:22:49 -0400 | [diff] [blame] | 374 | #if defined(SK_BUILD_FOR_ANDROID) && defined(SK_GL) |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 375 | GrGLGpu* gpu = static_cast<GrGLGpu*>(ctxInfo.directContext()->priv().getGpu()); |
Brian Salomon | 9c4ee9c | 2019-12-20 16:20:54 -0500 | [diff] [blame] | 376 | // Tecno Spark 3 Pro with Power VR Rogue GE8300 will fail shader compiles with |
| 377 | // no message if the shader is particularly long. |
| 378 | if (gpu->ctxInfo().vendor() == kImagination_GrGLVendor) { |
| 379 | maxTreeLevels = 3; |
| 380 | } |
| 381 | #endif |
Jim Van Verth | 5a8f3e4 | 2019-10-24 10:23:26 -0400 | [diff] [blame] | 382 | if (ctxInfo.type() == sk_gpu_test::GrContextFactory::kANGLE_D3D9_ES2_ContextType || |
| 383 | ctxInfo.type() == sk_gpu_test::GrContextFactory::kANGLE_D3D11_ES2_ContextType) { |
| 384 | // On Angle D3D we will hit a limit of out variables if we use too many stages. |
| 385 | maxTreeLevels = 2; |
| 386 | } |
Greg Daniel | 78325c1 | 2017-06-19 16:39:13 -0400 | [diff] [blame] | 387 | } |
| 388 | return maxTreeLevels; |
| 389 | } |
| 390 | |
Jim Van Verth | 5a8f3e4 | 2019-10-24 10:23:26 -0400 | [diff] [blame] | 391 | static void test_programs(skiatest::Reporter* reporter, const sk_gpu_test::ContextInfo& ctxInfo) { |
| 392 | int maxStages = get_programs_max_stages(ctxInfo); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 393 | if (maxStages == 0) { |
| 394 | return; |
| 395 | } |
Jim Van Verth | 5a8f3e4 | 2019-10-24 10:23:26 -0400 | [diff] [blame] | 396 | int maxLevels = get_programs_max_levels(ctxInfo); |
Greg Daniel | 78325c1 | 2017-06-19 16:39:13 -0400 | [diff] [blame] | 397 | if (maxLevels == 0) { |
| 398 | return; |
| 399 | } |
Brian Osman | 9f772a4 | 2017-07-10 13:03:50 -0400 | [diff] [blame] | 400 | |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 401 | REPORTER_ASSERT(reporter, GrDrawingManager::ProgramUnitTest(ctxInfo.directContext(), maxStages, |
Greg Daniel | 78325c1 | 2017-06-19 16:39:13 -0400 | [diff] [blame] | 402 | maxLevels)); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 403 | } |
| 404 | |
Jim Van Verth | 5a8f3e4 | 2019-10-24 10:23:26 -0400 | [diff] [blame] | 405 | DEF_GPUTEST(Programs, 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); |
Jim Van Verth | 5a8f3e4 | 2019-10-24 10:23:26 -0400 | [diff] [blame] | 418 | skiatest::RunWithGPUTestContexts(test_programs, &skiatest::IsRenderingGLOrMetalContextType, |
| 419 | reporter, opts); |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 420 | } |