Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "tests/Test.h" |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/gpu/GrContext.h" |
| 11 | #include "include/gpu/GrGpuResource.h" |
| 12 | #include "src/gpu/GrClip.h" |
| 13 | #include "src/gpu/GrContextPriv.h" |
Brian Salomon | f2ebdd9 | 2019-09-30 12:15:30 -0400 | [diff] [blame] | 14 | #include "src/gpu/GrImageInfo.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 15 | #include "src/gpu/GrMemoryPool.h" |
| 16 | #include "src/gpu/GrProxyProvider.h" |
| 17 | #include "src/gpu/GrRenderTargetContext.h" |
| 18 | #include "src/gpu/GrRenderTargetContextPriv.h" |
| 19 | #include "src/gpu/GrResourceProvider.h" |
| 20 | #include "src/gpu/glsl/GrGLSLFragmentProcessor.h" |
| 21 | #include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h" |
| 22 | #include "src/gpu/ops/GrFillRectOp.h" |
| 23 | #include "src/gpu/ops/GrMeshDrawOp.h" |
| 24 | #include "tests/TestUtils.h" |
Mike Klein | 0ec1c57 | 2018-12-04 11:52:51 -0500 | [diff] [blame] | 25 | #include <atomic> |
Hal Canary | 8a00144 | 2018-09-19 11:31:27 -0400 | [diff] [blame] | 26 | #include <random> |
| 27 | |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 28 | namespace { |
Brian Salomon | 82ddc94 | 2017-07-14 12:00:13 -0400 | [diff] [blame] | 29 | class TestOp : public GrMeshDrawOp { |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 30 | public: |
| 31 | DEFINE_OP_CLASS_ID |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 32 | static std::unique_ptr<GrDrawOp> Make(GrContext* context, |
| 33 | std::unique_ptr<GrFragmentProcessor> fp) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 34 | GrOpMemoryPool* pool = context->priv().opMemoryPool(); |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 35 | |
| 36 | return pool->allocate<TestOp>(std::move(fp)); |
Brian Salomon | 82ddc94 | 2017-07-14 12:00:13 -0400 | [diff] [blame] | 37 | } |
| 38 | |
Robert Phillips | 5f567c7 | 2017-09-14 08:27:37 -0400 | [diff] [blame] | 39 | const char* name() const override { return "TestOp"; } |
| 40 | |
Chris Dalton | 1706cbf | 2019-05-21 19:35:29 -0600 | [diff] [blame] | 41 | void visitProxies(const VisitProxyFunc& func) const override { |
Robert Phillips | 5f567c7 | 2017-09-14 08:27:37 -0400 | [diff] [blame] | 42 | fProcessors.visitProxies(func); |
| 43 | } |
| 44 | |
Brian Salomon | 82ddc94 | 2017-07-14 12:00:13 -0400 | [diff] [blame] | 45 | FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; } |
| 46 | |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 47 | GrProcessorSet::Analysis finalize( |
| 48 | const GrCaps& caps, const GrAppliedClip* clip, bool hasMixedSampledCoverage, |
| 49 | GrClampType clampType) override { |
Brian Salomon | 82ddc94 | 2017-07-14 12:00:13 -0400 | [diff] [blame] | 50 | static constexpr GrProcessorAnalysisColor kUnknownColor; |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 51 | SkPMColor4f overrideColor; |
Chris Dalton | b8fff0d | 2019-03-05 10:11:58 -0700 | [diff] [blame] | 52 | return fProcessors.finalize( |
| 53 | kUnknownColor, GrProcessorAnalysisCoverage::kNone, clip, |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 54 | &GrUserStencilSettings::kUnused, hasMixedSampledCoverage, caps, clampType, |
| 55 | &overrideColor); |
Brian Salomon | 649a341 | 2017-03-09 13:50:43 -0500 | [diff] [blame] | 56 | } |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 57 | |
| 58 | private: |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 59 | friend class ::GrOpMemoryPool; // for ctor |
| 60 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 61 | TestOp(std::unique_ptr<GrFragmentProcessor> fp) |
| 62 | : INHERITED(ClassID()), fProcessors(std::move(fp)) { |
Greg Daniel | 5faf474 | 2019-10-01 15:14:44 -0400 | [diff] [blame] | 63 | this->setBounds(SkRect::MakeWH(100, 100), HasAABloat::kNo, IsHairline::kNo); |
Brian Salomon | 82ddc94 | 2017-07-14 12:00:13 -0400 | [diff] [blame] | 64 | } |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 65 | |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 66 | void onPrepareDraws(Target* target) override { return; } |
Chris Dalton | 07cdcfc9 | 2019-02-26 11:13:22 -0700 | [diff] [blame] | 67 | void onExecute(GrOpFlushState*, const SkRect&) override { return; } |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 68 | |
Brian Salomon | 82ddc94 | 2017-07-14 12:00:13 -0400 | [diff] [blame] | 69 | GrProcessorSet fProcessors; |
| 70 | |
| 71 | typedef GrMeshDrawOp INHERITED; |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | /** |
Robert Phillips | 3d4cac5 | 2019-06-11 08:08:08 -0400 | [diff] [blame] | 75 | * FP used to test ref counts on owned GrGpuResources. Can also be a parent FP to test counts |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 76 | * of resources owned by child FPs. |
| 77 | */ |
| 78 | class TestFP : public GrFragmentProcessor { |
| 79 | public: |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 80 | static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> child) { |
| 81 | return std::unique_ptr<GrFragmentProcessor>(new TestFP(std::move(child))); |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 82 | } |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 83 | static std::unique_ptr<GrFragmentProcessor> Make(const SkTArray<sk_sp<GrTextureProxy>>& proxies, |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 84 | const SkTArray<sk_sp<GrGpuBuffer>>& buffers) { |
Brian Salomon | 559f556 | 2017-11-15 14:28:33 -0500 | [diff] [blame] | 85 | return std::unique_ptr<GrFragmentProcessor>(new TestFP(proxies, buffers)); |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | const char* name() const override { return "test"; } |
| 89 | |
| 90 | void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder* b) const override { |
Mike Klein | 0ec1c57 | 2018-12-04 11:52:51 -0500 | [diff] [blame] | 91 | static std::atomic<int32_t> nextKey{0}; |
| 92 | b->add32(nextKey++); |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 93 | } |
| 94 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 95 | std::unique_ptr<GrFragmentProcessor> clone() const override { |
| 96 | return std::unique_ptr<GrFragmentProcessor>(new TestFP(*this)); |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 97 | } |
| 98 | |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 99 | private: |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 100 | TestFP(const SkTArray<sk_sp<GrTextureProxy>>& proxies, |
| 101 | const SkTArray<sk_sp<GrGpuBuffer>>& buffers) |
Brian Salomon | 662ea4b | 2018-07-12 14:53:49 -0400 | [diff] [blame] | 102 | : INHERITED(kTestFP_ClassID, kNone_OptimizationFlags), fSamplers(4) { |
Robert Phillips | 30f9bc6 | 2017-02-22 15:28:38 -0500 | [diff] [blame] | 103 | for (const auto& proxy : proxies) { |
Brian Salomon | f7dcd76 | 2018-07-30 14:48:15 -0400 | [diff] [blame] | 104 | fSamplers.emplace_back(proxy); |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 105 | } |
Brian Salomon | f7dcd76 | 2018-07-30 14:48:15 -0400 | [diff] [blame] | 106 | this->setTextureSamplerCnt(fSamplers.count()); |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 107 | } |
| 108 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 109 | TestFP(std::unique_ptr<GrFragmentProcessor> child) |
Brian Salomon | 662ea4b | 2018-07-12 14:53:49 -0400 | [diff] [blame] | 110 | : INHERITED(kTestFP_ClassID, kNone_OptimizationFlags), fSamplers(4) { |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 111 | this->registerChildProcessor(std::move(child)); |
| 112 | } |
| 113 | |
Brian Salomon | 96271cd | 2017-07-31 16:27:23 -0400 | [diff] [blame] | 114 | explicit TestFP(const TestFP& that) |
Brian Salomon | 662ea4b | 2018-07-12 14:53:49 -0400 | [diff] [blame] | 115 | : INHERITED(kTestFP_ClassID, that.optimizationFlags()), fSamplers(4) { |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 116 | for (int i = 0; i < that.fSamplers.count(); ++i) { |
| 117 | fSamplers.emplace_back(that.fSamplers[i]); |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 118 | } |
Brian Salomon | 96271cd | 2017-07-31 16:27:23 -0400 | [diff] [blame] | 119 | for (int i = 0; i < that.numChildProcessors(); ++i) { |
| 120 | this->registerChildProcessor(that.childProcessor(i).clone()); |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 121 | } |
Brian Salomon | f7dcd76 | 2018-07-30 14:48:15 -0400 | [diff] [blame] | 122 | this->setTextureSamplerCnt(fSamplers.count()); |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 123 | } |
| 124 | |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 125 | virtual GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { |
| 126 | class TestGLSLFP : public GrGLSLFragmentProcessor { |
| 127 | public: |
| 128 | TestGLSLFP() {} |
| 129 | void emitCode(EmitArgs& args) override { |
| 130 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 131 | fragBuilder->codeAppendf("%s = %s;", args.fOutputColor, args.fInputColor); |
| 132 | } |
| 133 | |
| 134 | private: |
| 135 | }; |
| 136 | return new TestGLSLFP(); |
| 137 | } |
| 138 | |
| 139 | bool onIsEqual(const GrFragmentProcessor&) const override { return false; } |
Brian Salomon | f7dcd76 | 2018-07-30 14:48:15 -0400 | [diff] [blame] | 140 | const TextureSampler& onTextureSampler(int i) const override { return fSamplers[i]; } |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 141 | |
| 142 | GrTAllocator<TextureSampler> fSamplers; |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 143 | typedef GrFragmentProcessor INHERITED; |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 144 | }; |
| 145 | } |
| 146 | |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 147 | DEF_GPUTEST_FOR_ALL_CONTEXTS(ProcessorRefTest, reporter, ctxInfo) { |
| 148 | GrContext* context = ctxInfo.grContext(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 149 | GrProxyProvider* proxyProvider = context->priv().proxyProvider(); |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 150 | |
Robert Phillips | 16d8ec6 | 2017-07-27 16:16:25 -0400 | [diff] [blame] | 151 | GrSurfaceDesc desc; |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 152 | desc.fWidth = 10; |
| 153 | desc.fHeight = 10; |
Robert Phillips | 16d8ec6 | 2017-07-27 16:16:25 -0400 | [diff] [blame] | 154 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 155 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 156 | const GrBackendFormat format = |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 157 | context->priv().caps()->getDefaultBackendFormat(GrColorType::kRGBA_8888, |
| 158 | GrRenderable::kNo); |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 159 | |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 160 | for (bool makeClone : {false, true}) { |
| 161 | for (int parentCnt = 0; parentCnt < 2; parentCnt++) { |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 162 | auto renderTargetContext = context->priv().makeDeferredRenderTargetContext( |
| 163 | SkBackingFit::kApprox, 1, 1, GrColorType::kRGBA_8888, nullptr); |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 164 | { |
Robert Phillips | 3d4cac5 | 2019-06-11 08:08:08 -0400 | [diff] [blame] | 165 | sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy( |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 166 | format, desc, GrRenderable::kNo, 1, kTopLeft_GrSurfaceOrigin, |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 167 | GrMipMapped::kNo, SkBackingFit::kExact, SkBudgeted::kYes, GrProtected::kNo); |
Robert Phillips | 3d4cac5 | 2019-06-11 08:08:08 -0400 | [diff] [blame] | 168 | |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 169 | { |
| 170 | SkTArray<sk_sp<GrTextureProxy>> proxies; |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 171 | SkTArray<sk_sp<GrGpuBuffer>> buffers; |
Robert Phillips | 3d4cac5 | 2019-06-11 08:08:08 -0400 | [diff] [blame] | 172 | proxies.push_back(proxy); |
Brian Salomon | 559f556 | 2017-11-15 14:28:33 -0500 | [diff] [blame] | 173 | auto fp = TestFP::Make(std::move(proxies), std::move(buffers)); |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 174 | for (int i = 0; i < parentCnt; ++i) { |
| 175 | fp = TestFP::Make(std::move(fp)); |
| 176 | } |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 177 | std::unique_ptr<GrFragmentProcessor> clone; |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 178 | if (makeClone) { |
| 179 | clone = fp->clone(); |
| 180 | } |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 181 | std::unique_ptr<GrDrawOp> op(TestOp::Make(context, std::move(fp))); |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 182 | renderTargetContext->priv().testingOnly_addDrawOp(std::move(op)); |
| 183 | if (clone) { |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 184 | op = TestOp::Make(context, std::move(clone)); |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 185 | renderTargetContext->priv().testingOnly_addDrawOp(std::move(op)); |
| 186 | } |
| 187 | } |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 188 | |
Robert Phillips | 3d4cac5 | 2019-06-11 08:08:08 -0400 | [diff] [blame] | 189 | // If the fp is cloned the number of refs should increase by one (for the clone) |
| 190 | int expectedProxyRefs = makeClone ? 3 : 2; |
| 191 | |
Brian Salomon | 28a8f28 | 2019-10-24 20:07:39 -0400 | [diff] [blame] | 192 | CheckSingleThreadedProxyRefs(reporter, proxy.get(), expectedProxyRefs, -1); |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 193 | |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 194 | context->flush(); |
| 195 | |
Brian Salomon | 557e812 | 2019-10-24 10:37:08 -0400 | [diff] [blame] | 196 | // just one from the 'proxy' sk_sp |
Brian Salomon | 28a8f28 | 2019-10-24 20:07:39 -0400 | [diff] [blame] | 197 | CheckSingleThreadedProxyRefs(reporter, proxy.get(), 1, 1); |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 198 | } |
| 199 | } |
| 200 | } |
| 201 | } |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 202 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 203 | #include "tools/flags/CommandLineFlags.h" |
Mike Klein | 84836b7 | 2019-03-21 11:31:36 -0500 | [diff] [blame] | 204 | static DEFINE_bool(randomProcessorTest, false, |
| 205 | "Use non-deterministic seed for random processor tests?"); |
Mike Klein | 5b3f343 | 2019-03-21 11:42:21 -0500 | [diff] [blame] | 206 | static DEFINE_int(processorSeed, 0, |
| 207 | "Use specific seed for processor tests. Overridden by --randomProcessorTest."); |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 208 | |
| 209 | #if GR_TEST_UTILS |
| 210 | |
Michael Ludwig | 7034f15 | 2018-10-08 16:43:58 -0400 | [diff] [blame] | 211 | static GrColor input_texel_color(int i, int j, SkScalar delta) { |
| 212 | // Delta must be less than 0.5 to prevent over/underflow issues with the input color |
| 213 | SkASSERT(delta <= 0.5); |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 214 | |
Brian Osman | 50ea3c0 | 2019-02-04 10:01:53 -0500 | [diff] [blame] | 215 | SkColor color = SkColorSetARGB((uint8_t)(i & 0xFF), |
| 216 | (uint8_t)(j & 0xFF), |
| 217 | (uint8_t)((i + j) & 0xFF), |
| 218 | (uint8_t)((2 * j - i) & 0xFF)); |
Brian Osman | cb3d087 | 2018-10-16 15:19:28 -0400 | [diff] [blame] | 219 | SkColor4f color4f = SkColor4f::FromColor(color); |
Michael Ludwig | 7034f15 | 2018-10-08 16:43:58 -0400 | [diff] [blame] | 220 | for (int i = 0; i < 4; i++) { |
Brian Osman | cb3d087 | 2018-10-16 15:19:28 -0400 | [diff] [blame] | 221 | if (color4f[i] > 0.5) { |
| 222 | color4f[i] -= delta; |
Michael Ludwig | 7034f15 | 2018-10-08 16:43:58 -0400 | [diff] [blame] | 223 | } else { |
Brian Osman | cb3d087 | 2018-10-16 15:19:28 -0400 | [diff] [blame] | 224 | color4f[i] += delta; |
Michael Ludwig | 7034f15 | 2018-10-08 16:43:58 -0400 | [diff] [blame] | 225 | } |
| 226 | } |
Brian Osman | cb3d087 | 2018-10-16 15:19:28 -0400 | [diff] [blame] | 227 | return color4f.premul().toBytes_RGBA(); |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 228 | } |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 229 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 230 | void test_draw_op(GrContext* context, |
| 231 | GrRenderTargetContext* rtc, |
| 232 | std::unique_ptr<GrFragmentProcessor> fp, |
Greg Daniel | c594e62 | 2019-10-15 14:01:49 -0400 | [diff] [blame] | 233 | sk_sp<GrTextureProxy> inputDataProxy, |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 234 | GrColorType inputColorType) { |
Brian Salomon | 5d4cd9e | 2017-02-09 11:16:46 -0500 | [diff] [blame] | 235 | GrPaint paint; |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 236 | paint.addColorTextureProcessor(std::move(inputDataProxy), inputColorType, SkMatrix::I()); |
Brian Salomon | 5d4cd9e | 2017-02-09 11:16:46 -0500 | [diff] [blame] | 237 | paint.addColorFragmentProcessor(std::move(fp)); |
| 238 | paint.setPorterDuffXPFactory(SkBlendMode::kSrc); |
Brian Salomon | ac70f84 | 2017-05-08 10:43:33 -0400 | [diff] [blame] | 239 | |
Michael Ludwig | aa1b6b3 | 2019-05-29 14:43:13 -0400 | [diff] [blame] | 240 | auto op = GrFillRectOp::MakeNonAARect(context, std::move(paint), SkMatrix::I(), |
| 241 | SkRect::MakeWH(rtc->width(), rtc->height())); |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 242 | rtc->addDrawOp(GrNoClip(), std::move(op)); |
Brian Salomon | 5d4cd9e | 2017-02-09 11:16:46 -0500 | [diff] [blame] | 243 | } |
| 244 | |
Michael Ludwig | 7034f15 | 2018-10-08 16:43:58 -0400 | [diff] [blame] | 245 | // This assumes that the output buffer will be the same size as inputDataProxy |
| 246 | void render_fp(GrContext* context, GrRenderTargetContext* rtc, GrFragmentProcessor* fp, |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 247 | sk_sp<GrTextureProxy> inputDataProxy, GrColorType inputColorType, GrColor* buffer) { |
Michael Ludwig | 7034f15 | 2018-10-08 16:43:58 -0400 | [diff] [blame] | 248 | // test_draw_op needs to take ownership of an FP, so give it a clone that it can own |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 249 | test_draw_op(context, rtc, fp->clone(), inputDataProxy, inputColorType); |
Brian Salomon | 9f2b86c | 2019-10-22 10:37:46 -0400 | [diff] [blame] | 250 | memset(buffer, 0x0, sizeof(GrColor) * inputDataProxy->width() * inputDataProxy->height()); |
| 251 | rtc->readPixels(SkImageInfo::Make(inputDataProxy->dimensions(), kRGBA_8888_SkColorType, |
| 252 | kPremul_SkAlphaType), |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 253 | buffer, 0, {0, 0}); |
Michael Ludwig | 7034f15 | 2018-10-08 16:43:58 -0400 | [diff] [blame] | 254 | } |
| 255 | |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 256 | /** Initializes the two test texture proxies that are available to the FP test factories. */ |
Robert Phillips | 7eeb74f | 2019-03-29 07:26:46 -0400 | [diff] [blame] | 257 | bool init_test_textures(GrResourceProvider* resourceProvider, |
| 258 | GrProxyProvider* proxyProvider, |
| 259 | SkRandom* random, |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 260 | sk_sp<GrTextureProxy> proxies[2], |
| 261 | GrColorType proxyColorTypes[2]) { |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 262 | static const int kTestTextureSize = 256; |
Brian Osman | c35a2d4 | 2017-03-17 10:58:53 -0400 | [diff] [blame] | 263 | |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 264 | { |
| 265 | // Put premul data into the RGBA texture that the test FPs can optionally use. |
| 266 | std::unique_ptr<GrColor[]> rgbaData(new GrColor[kTestTextureSize * kTestTextureSize]); |
| 267 | for (int y = 0; y < kTestTextureSize; ++y) { |
| 268 | for (int x = 0; x < kTestTextureSize; ++x) { |
Michael Ludwig | 7034f15 | 2018-10-08 16:43:58 -0400 | [diff] [blame] | 269 | rgbaData[kTestTextureSize * y + x] = input_texel_color( |
| 270 | random->nextULessThan(256), random->nextULessThan(256), 0.0f); |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 271 | } |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 272 | } |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 273 | |
Brian Osman | 2700abc | 2018-09-12 10:19:41 -0400 | [diff] [blame] | 274 | SkImageInfo ii = SkImageInfo::Make(kTestTextureSize, kTestTextureSize, |
| 275 | kRGBA_8888_SkColorType, kPremul_SkAlphaType); |
| 276 | SkPixmap pixmap(ii, rgbaData.get(), ii.minRowBytes()); |
| 277 | sk_sp<SkImage> img = SkImage::MakeRasterCopy(pixmap); |
Brian Salomon | 96b383a | 2019-08-13 16:55:41 -0400 | [diff] [blame] | 278 | proxies[0] = |
| 279 | proxyProvider->createTextureProxy(img, 1, SkBudgeted::kYes, SkBackingFit::kExact); |
Robert Phillips | 12c4629 | 2019-04-23 07:36:17 -0400 | [diff] [blame] | 280 | proxies[0]->instantiate(resourceProvider); |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 281 | proxyColorTypes[0] = GrColorType::kRGBA_8888; |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 282 | } |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 283 | |
| 284 | { |
| 285 | // Put random values into the alpha texture that the test FPs can optionally use. |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 286 | std::unique_ptr<uint8_t[]> alphaData(new uint8_t[kTestTextureSize * kTestTextureSize]); |
| 287 | for (int y = 0; y < kTestTextureSize; ++y) { |
| 288 | for (int x = 0; x < kTestTextureSize; ++x) { |
| 289 | alphaData[kTestTextureSize * y + x] = random->nextULessThan(256); |
| 290 | } |
| 291 | } |
| 292 | |
Brian Osman | 2700abc | 2018-09-12 10:19:41 -0400 | [diff] [blame] | 293 | SkImageInfo ii = SkImageInfo::Make(kTestTextureSize, kTestTextureSize, |
| 294 | kAlpha_8_SkColorType, kPremul_SkAlphaType); |
| 295 | SkPixmap pixmap(ii, alphaData.get(), ii.minRowBytes()); |
| 296 | sk_sp<SkImage> img = SkImage::MakeRasterCopy(pixmap); |
Brian Salomon | 96b383a | 2019-08-13 16:55:41 -0400 | [diff] [blame] | 297 | proxies[1] = |
| 298 | proxyProvider->createTextureProxy(img, 1, SkBudgeted::kYes, SkBackingFit::kExact); |
Robert Phillips | 12c4629 | 2019-04-23 07:36:17 -0400 | [diff] [blame] | 299 | proxies[1]->instantiate(resourceProvider); |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 300 | proxyColorTypes[1] = GrColorType::kAlpha_8; |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 301 | } |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 302 | |
| 303 | return proxies[0] && proxies[1]; |
| 304 | } |
| 305 | |
| 306 | // Creates a texture of premul colors used as the output of the fragment processor that precedes |
| 307 | // the fragment processor under test. Color values are those provided by input_texel_color(). |
Michael Ludwig | 7034f15 | 2018-10-08 16:43:58 -0400 | [diff] [blame] | 308 | sk_sp<GrTextureProxy> make_input_texture(GrProxyProvider* proxyProvider, int width, int height, |
| 309 | SkScalar delta) { |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 310 | std::unique_ptr<GrColor[]> data(new GrColor[width * height]); |
| 311 | for (int y = 0; y < width; ++y) { |
| 312 | for (int x = 0; x < height; ++x) { |
Michael Ludwig | 7034f15 | 2018-10-08 16:43:58 -0400 | [diff] [blame] | 313 | data.get()[width * y + x] = input_texel_color(x, y, delta); |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 314 | } |
| 315 | } |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 316 | |
Brian Osman | 2700abc | 2018-09-12 10:19:41 -0400 | [diff] [blame] | 317 | SkImageInfo ii = SkImageInfo::Make(width, height, kRGBA_8888_SkColorType, kPremul_SkAlphaType); |
| 318 | SkPixmap pixmap(ii, data.get(), ii.minRowBytes()); |
| 319 | sk_sp<SkImage> img = SkImage::MakeRasterCopy(pixmap); |
Brian Salomon | 96b383a | 2019-08-13 16:55:41 -0400 | [diff] [blame] | 320 | return proxyProvider->createTextureProxy(img, 1, SkBudgeted::kYes, SkBackingFit::kExact); |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 321 | } |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 322 | |
Brian Salomon | cd8b6d5 | 2019-08-13 12:40:04 -0400 | [diff] [blame] | 323 | // We tag logged data as unpremul to avoid conversion when encoding as PNG. The input texture |
| 324 | // actually contains unpremul data. Also, even though we made the result data by rendering into |
| 325 | // a "unpremul" GrRenderTargetContext, our input texture is unpremul and outside of the random |
| 326 | // effect configuration, we didn't do anything to ensure the output is actually premul. We just |
| 327 | // don't currently allow kUnpremul GrRenderTargetContexts. |
| 328 | static constexpr auto kLogAlphaType = kUnpremul_SkAlphaType; |
Michael Ludwig | e8e1075 | 2018-10-01 12:42:53 -0400 | [diff] [blame] | 329 | |
Brian Salomon | cd8b6d5 | 2019-08-13 12:40:04 -0400 | [diff] [blame] | 330 | bool log_pixels(GrColor* pixels, int widthHeight, SkString* dst) { |
| 331 | auto info = SkImageInfo::Make(widthHeight, widthHeight, kRGBA_8888_SkColorType, kLogAlphaType); |
| 332 | SkBitmap bmp; |
| 333 | bmp.installPixels(info, pixels, widthHeight * sizeof(GrColor)); |
Brian Salomon | 28a8f28 | 2019-10-24 20:07:39 -0400 | [diff] [blame] | 334 | return BipmapToBase64DataURI(bmp, dst); |
Michael Ludwig | e8e1075 | 2018-10-01 12:42:53 -0400 | [diff] [blame] | 335 | } |
| 336 | |
Brian Salomon | cd8b6d5 | 2019-08-13 12:40:04 -0400 | [diff] [blame] | 337 | bool log_texture_proxy(GrContext* context, sk_sp<GrTextureProxy> src, SkString* dst) { |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 338 | auto sContext = |
| 339 | context->priv().makeWrappedSurfaceContext(src, GrColorType::kRGBA_8888, kLogAlphaType); |
Brian Salomon | 9f2b86c | 2019-10-22 10:37:46 -0400 | [diff] [blame] | 340 | SkImageInfo ii = SkImageInfo::Make(src->dimensions(), kRGBA_8888_SkColorType, kLogAlphaType); |
Brian Salomon | cd8b6d5 | 2019-08-13 12:40:04 -0400 | [diff] [blame] | 341 | SkBitmap bm; |
| 342 | SkAssertResult(bm.tryAllocPixels(ii)); |
| 343 | SkAssertResult(sContext->readPixels(ii, bm.getPixels(), bm.rowBytes(), {0, 0})); |
Brian Salomon | 28a8f28 | 2019-10-24 20:07:39 -0400 | [diff] [blame] | 344 | return BipmapToBase64DataURI(bm, dst); |
Michael Ludwig | e8e1075 | 2018-10-01 12:42:53 -0400 | [diff] [blame] | 345 | } |
| 346 | |
Michael Ludwig | 7034f15 | 2018-10-08 16:43:58 -0400 | [diff] [blame] | 347 | bool fuzzy_color_equals(const SkPMColor4f& c1, const SkPMColor4f& c2) { |
| 348 | // With the loss of precision of rendering into 32-bit color, then estimating the FP's output |
| 349 | // from that, it is not uncommon for a valid output to differ from estimate by up to 0.01 |
| 350 | // (really 1/128 ~ .0078, but frequently floating point issues make that tolerance a little |
| 351 | // too unforgiving). |
| 352 | static constexpr SkScalar kTolerance = 0.01f; |
| 353 | for (int i = 0; i < 4; i++) { |
| 354 | if (!SkScalarNearlyEqual(c1[i], c2[i], kTolerance)) { |
| 355 | return false; |
| 356 | } |
| 357 | } |
| 358 | return true; |
| 359 | } |
| 360 | |
| 361 | int modulation_index(int channelIndex, bool alphaModulation) { |
| 362 | return alphaModulation ? 3 : channelIndex; |
| 363 | } |
| 364 | |
| 365 | // Given three input colors (color preceding the FP being tested), and the output of the FP, this |
| 366 | // ensures that the out1 = fp * in1.a, out2 = fp * in2.a, and out3 = fp * in3.a, where fp is the |
| 367 | // pre-modulated color that should not be changing across frames (FP's state doesn't change). |
| 368 | // |
| 369 | // When alphaModulation is false, this tests the very similar conditions that out1 = fp * in1, |
| 370 | // etc. using per-channel modulation instead of modulation by just the input alpha channel. |
| 371 | // - This estimates the pre-modulated fp color from one of the input/output pairs and confirms the |
| 372 | // conditions hold for the other two pairs. |
| 373 | bool legal_modulation(const GrColor& in1, const GrColor& in2, const GrColor& in3, |
| 374 | const GrColor& out1, const GrColor& out2, const GrColor& out3, |
| 375 | bool alphaModulation) { |
| 376 | // Convert to floating point, which is the number space the FP operates in (more or less) |
Brian Osman | cb3d087 | 2018-10-16 15:19:28 -0400 | [diff] [blame] | 377 | SkPMColor4f in1f = SkPMColor4f::FromBytes_RGBA(in1); |
| 378 | SkPMColor4f in2f = SkPMColor4f::FromBytes_RGBA(in2); |
| 379 | SkPMColor4f in3f = SkPMColor4f::FromBytes_RGBA(in3); |
| 380 | SkPMColor4f out1f = SkPMColor4f::FromBytes_RGBA(out1); |
| 381 | SkPMColor4f out2f = SkPMColor4f::FromBytes_RGBA(out2); |
| 382 | SkPMColor4f out3f = SkPMColor4f::FromBytes_RGBA(out3); |
Michael Ludwig | 7034f15 | 2018-10-08 16:43:58 -0400 | [diff] [blame] | 383 | |
| 384 | // Reconstruct the output of the FP before the shader modulated its color with the input value. |
| 385 | // When the original input is very small, it may cause the final output color to round |
| 386 | // to 0, in which case we estimate the pre-modulated color using one of the stepped frames that |
| 387 | // will then have a guaranteed larger channel value (since the offset will be added to it). |
| 388 | SkPMColor4f fpPreModulation; |
| 389 | for (int i = 0; i < 4; i++) { |
| 390 | int modulationIndex = modulation_index(i, alphaModulation); |
| 391 | if (in1f[modulationIndex] < 0.2f) { |
| 392 | // Use the stepped frame |
| 393 | fpPreModulation[i] = out2f[i] / in2f[modulationIndex]; |
| 394 | } else { |
| 395 | fpPreModulation[i] = out1f[i] / in1f[modulationIndex]; |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | // With reconstructed pre-modulated FP output, derive the expected value of fp * input for each |
| 400 | // of the transformed input colors. |
Brian Osman | cb3d087 | 2018-10-16 15:19:28 -0400 | [diff] [blame] | 401 | SkPMColor4f expected1 = alphaModulation ? (fpPreModulation * in1f.fA) |
| 402 | : (fpPreModulation * in1f); |
| 403 | SkPMColor4f expected2 = alphaModulation ? (fpPreModulation * in2f.fA) |
| 404 | : (fpPreModulation * in2f); |
| 405 | SkPMColor4f expected3 = alphaModulation ? (fpPreModulation * in3f.fA) |
| 406 | : (fpPreModulation * in3f); |
Michael Ludwig | 7034f15 | 2018-10-08 16:43:58 -0400 | [diff] [blame] | 407 | |
Brian Osman | cb3d087 | 2018-10-16 15:19:28 -0400 | [diff] [blame] | 408 | return fuzzy_color_equals(out1f, expected1) && |
| 409 | fuzzy_color_equals(out2f, expected2) && |
| 410 | fuzzy_color_equals(out3f, expected3); |
Michael Ludwig | 7034f15 | 2018-10-08 16:43:58 -0400 | [diff] [blame] | 411 | } |
| 412 | |
Brian Salomon | 5d4cd9e | 2017-02-09 11:16:46 -0500 | [diff] [blame] | 413 | DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ProcessorOptimizationValidationTest, reporter, ctxInfo) { |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 414 | GrContext* context = ctxInfo.grContext(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 415 | GrProxyProvider* proxyProvider = context->priv().proxyProvider(); |
| 416 | auto resourceProvider = context->priv().resourceProvider(); |
Brian Salomon | 1c05364 | 2017-07-24 10:16:19 -0400 | [diff] [blame] | 417 | using FPFactory = GrFragmentProcessorTestFactory; |
Brian Osman | c35a2d4 | 2017-03-17 10:58:53 -0400 | [diff] [blame] | 418 | |
Michael Ludwig | 3ad86d0 | 2018-09-28 16:00:38 -0400 | [diff] [blame] | 419 | uint32_t seed = FLAGS_processorSeed; |
Brian Osman | c35a2d4 | 2017-03-17 10:58:53 -0400 | [diff] [blame] | 420 | if (FLAGS_randomProcessorTest) { |
| 421 | std::random_device rd; |
| 422 | seed = rd(); |
| 423 | } |
| 424 | // If a non-deterministic bot fails this test, check the output to see what seed it used, then |
Michael Ludwig | 3ad86d0 | 2018-09-28 16:00:38 -0400 | [diff] [blame] | 425 | // use --processorSeed <seed> (without --randomProcessorTest) to reproduce. |
Brian Osman | c35a2d4 | 2017-03-17 10:58:53 -0400 | [diff] [blame] | 426 | SkRandom random(seed); |
| 427 | |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 428 | // Make the destination context for the test. |
| 429 | static constexpr int kRenderSize = 256; |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 430 | auto rtc = context->priv().makeDeferredRenderTargetContext( |
Brian Salomon | 27ae52c | 2019-07-03 11:27:44 -0400 | [diff] [blame] | 431 | SkBackingFit::kExact, kRenderSize, kRenderSize, GrColorType::kRGBA_8888, nullptr); |
Brian Salomon | d1a8bdf | 2017-02-10 12:39:26 -0500 | [diff] [blame] | 432 | |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 433 | sk_sp<GrTextureProxy> proxies[2]; |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 434 | GrColorType proxyColorTypes[2]; |
| 435 | if (!init_test_textures(resourceProvider, proxyProvider, &random, proxies, proxyColorTypes)) { |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 436 | ERRORF(reporter, "Could not create test textures"); |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 437 | return; |
| 438 | } |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 439 | GrProcessorTestData testData(&random, context, rtc.get(), proxies, proxyColorTypes); |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 440 | |
Michael Ludwig | 7034f15 | 2018-10-08 16:43:58 -0400 | [diff] [blame] | 441 | // Coverage optimization uses three frames with a linearly transformed input texture. The first |
| 442 | // frame has no offset, second frames add .2 and .4, which should then be present as a fixed |
| 443 | // difference between the frame outputs if the FP is properly following the modulation |
| 444 | // requirements of the coverage optimization. |
| 445 | static constexpr SkScalar kInputDelta = 0.2f; |
| 446 | auto inputTexture1 = make_input_texture(proxyProvider, kRenderSize, kRenderSize, 0.0f); |
| 447 | auto inputTexture2 = make_input_texture(proxyProvider, kRenderSize, kRenderSize, kInputDelta); |
| 448 | auto inputTexture3 = make_input_texture(proxyProvider, kRenderSize, kRenderSize, 2*kInputDelta); |
Robert Phillips | 30f9bc6 | 2017-02-22 15:28:38 -0500 | [diff] [blame] | 449 | |
Michael Ludwig | e8e1075 | 2018-10-01 12:42:53 -0400 | [diff] [blame] | 450 | // Encoded images are very verbose and this tests many potential images, so only export the |
| 451 | // first failure (subsequent failures have a reasonable chance of being related). |
| 452 | bool loggedFirstFailure = false; |
Michael Ludwig | 314d377 | 2018-10-03 16:04:38 -0400 | [diff] [blame] | 453 | bool loggedFirstWarning = false; |
Michael Ludwig | 7034f15 | 2018-10-08 16:43:58 -0400 | [diff] [blame] | 454 | |
| 455 | // Storage for the three frames required for coverage compatibility optimization. Each frame |
| 456 | // uses the correspondingly numbered inputTextureX. |
| 457 | std::unique_ptr<GrColor[]> readData1(new GrColor[kRenderSize * kRenderSize]); |
| 458 | std::unique_ptr<GrColor[]> readData2(new GrColor[kRenderSize * kRenderSize]); |
| 459 | std::unique_ptr<GrColor[]> readData3(new GrColor[kRenderSize * kRenderSize]); |
| 460 | |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 461 | // Because processor factories configure themselves in random ways, this is not exhaustive. |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 462 | for (int i = 0; i < FPFactory::Count(); ++i) { |
| 463 | int timesToInvokeFactory = 5; |
| 464 | // Increase the number of attempts if the FP has child FPs since optimizations likely depend |
| 465 | // on child optimizations being present. |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 466 | std::unique_ptr<GrFragmentProcessor> fp = FPFactory::MakeIdx(i, &testData); |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 467 | for (int j = 0; j < fp->numChildProcessors(); ++j) { |
| 468 | // This value made a reasonable trade off between time and coverage when this test was |
| 469 | // written. |
| 470 | timesToInvokeFactory *= FPFactory::Count() / 2; |
| 471 | } |
Brian Osman | 50ea3c0 | 2019-02-04 10:01:53 -0500 | [diff] [blame] | 472 | #if defined(__MSVC_RUNTIME_CHECKS) |
| 473 | // This test is infuriatingly slow with MSVC runtime checks enabled |
| 474 | timesToInvokeFactory = 1; |
| 475 | #endif |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 476 | for (int j = 0; j < timesToInvokeFactory; ++j) { |
| 477 | fp = FPFactory::MakeIdx(i, &testData); |
Robert Phillips | a91e0b7 | 2017-05-01 13:12:20 -0400 | [diff] [blame] | 478 | |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 479 | if (!fp->hasConstantOutputForConstantInput() && !fp->preservesOpaqueInput() && |
Brian Salomon | f3b995b | 2017-02-15 10:22:23 -0500 | [diff] [blame] | 480 | !fp->compatibleWithCoverageAsAlpha()) { |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 481 | continue; |
| 482 | } |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 483 | |
Michael Ludwig | 7034f15 | 2018-10-08 16:43:58 -0400 | [diff] [blame] | 484 | if (fp->compatibleWithCoverageAsAlpha()) { |
| 485 | // 2nd and 3rd frames are only used when checking coverage optimization |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 486 | render_fp(context, rtc.get(), fp.get(), inputTexture2, GrColorType::kRGBA_8888, |
Greg Daniel | c594e62 | 2019-10-15 14:01:49 -0400 | [diff] [blame] | 487 | readData2.get()); |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 488 | render_fp(context, rtc.get(), fp.get(), inputTexture3, GrColorType::kRGBA_8888, |
Greg Daniel | c594e62 | 2019-10-15 14:01:49 -0400 | [diff] [blame] | 489 | readData3.get()); |
Michael Ludwig | 7034f15 | 2018-10-08 16:43:58 -0400 | [diff] [blame] | 490 | } |
| 491 | // Draw base frame last so that rtc holds the original FP behavior if we need to |
| 492 | // dump the image to the log. |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 493 | render_fp(context, rtc.get(), fp.get(), inputTexture1, GrColorType::kRGBA_8888, |
Greg Daniel | c594e62 | 2019-10-15 14:01:49 -0400 | [diff] [blame] | 494 | readData1.get()); |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 495 | |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 496 | if (0) { // Useful to see what FPs are being tested. |
| 497 | SkString children; |
Michael Ludwig | 7034f15 | 2018-10-08 16:43:58 -0400 | [diff] [blame] | 498 | for (int c = 0; c < fp->numChildProcessors(); ++c) { |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 499 | if (!c) { |
| 500 | children.append("("); |
| 501 | } |
Michael Ludwig | 7034f15 | 2018-10-08 16:43:58 -0400 | [diff] [blame] | 502 | children.append(fp->childProcessor(c).name()); |
| 503 | children.append(c == fp->numChildProcessors() - 1 ? ")" : ", "); |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 504 | } |
Michael Ludwig | 7034f15 | 2018-10-08 16:43:58 -0400 | [diff] [blame] | 505 | SkDebugf("%s %s\n", fp->name(), children.c_str()); |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 506 | } |
Michael Ludwig | 314d377 | 2018-10-03 16:04:38 -0400 | [diff] [blame] | 507 | |
| 508 | // This test has a history of being flaky on a number of devices. If an FP is logically |
| 509 | // violating the optimizations, it's reasonable to expect it to violate requirements on |
| 510 | // a large number of pixels in the image. Sporadic pixel violations are more indicative |
| 511 | // of device errors and represents a separate problem. |
Michael Ludwig | 72ab346 | 2018-12-10 12:43:36 -0500 | [diff] [blame] | 512 | #if defined(SK_BUILD_FOR_SKQP) |
Michael Ludwig | 314d377 | 2018-10-03 16:04:38 -0400 | [diff] [blame] | 513 | static constexpr int kMaxAcceptableFailedPixels = 0; // Strict when running as SKQP |
| 514 | #else |
| 515 | static constexpr int kMaxAcceptableFailedPixels = 2 * kRenderSize; // ~0.7% of the image |
| 516 | #endif |
| 517 | |
| 518 | int failedPixelCount = 0; |
| 519 | // Collect first optimization failure message, to be output later as a warning or an |
| 520 | // error depending on whether the rendering "passed" or failed. |
| 521 | SkString coverageMessage; |
| 522 | SkString opaqueMessage; |
| 523 | SkString constMessage; |
| 524 | for (int y = 0; y < kRenderSize; ++y) { |
| 525 | for (int x = 0; x < kRenderSize; ++x) { |
| 526 | bool passing = true; |
Michael Ludwig | 7034f15 | 2018-10-08 16:43:58 -0400 | [diff] [blame] | 527 | GrColor input = input_texel_color(x, y, 0.0f); |
| 528 | GrColor output = readData1.get()[y * kRenderSize + x]; |
| 529 | |
| 530 | if (fp->compatibleWithCoverageAsAlpha()) { |
| 531 | GrColor i2 = input_texel_color(x, y, kInputDelta); |
| 532 | GrColor i3 = input_texel_color(x, y, 2 * kInputDelta); |
| 533 | |
| 534 | GrColor o2 = readData2.get()[y * kRenderSize + x]; |
| 535 | GrColor o3 = readData3.get()[y * kRenderSize + x]; |
| 536 | |
| 537 | // A compatible processor is allowed to modulate either the input color or |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 538 | // just the input alpha. |
Michael Ludwig | 7034f15 | 2018-10-08 16:43:58 -0400 | [diff] [blame] | 539 | bool legalAlphaModulation = legal_modulation(input, i2, i3, output, o2, o3, |
| 540 | /* alpha */ true); |
| 541 | bool legalColorModulation = legal_modulation(input, i2, i3, output, o2, o3, |
| 542 | /* alpha */ false); |
| 543 | |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 544 | if (!legalColorModulation && !legalAlphaModulation) { |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 545 | passing = false; |
Michael Ludwig | 314d377 | 2018-10-03 16:04:38 -0400 | [diff] [blame] | 546 | |
| 547 | if (coverageMessage.isEmpty()) { |
Michael Ludwig | 7034f15 | 2018-10-08 16:43:58 -0400 | [diff] [blame] | 548 | coverageMessage.printf("\"Modulating\" processor %s did not match " |
| 549 | "alpha-modulation nor color-modulation rules. " |
| 550 | "Input: 0x%08x, Output: 0x%08x, pixel (%d, %d).", |
| 551 | fp->name(), input, output, x, y); |
Michael Ludwig | 314d377 | 2018-10-03 16:04:38 -0400 | [diff] [blame] | 552 | } |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 553 | } |
| 554 | } |
Michael Ludwig | 7034f15 | 2018-10-08 16:43:58 -0400 | [diff] [blame] | 555 | |
Brian Osman | cb3d087 | 2018-10-16 15:19:28 -0400 | [diff] [blame] | 556 | SkPMColor4f input4f = SkPMColor4f::FromBytes_RGBA(input); |
| 557 | SkPMColor4f output4f = SkPMColor4f::FromBytes_RGBA(output); |
Brian Osman | 1d5b598 | 2018-10-01 13:41:39 -0400 | [diff] [blame] | 558 | SkPMColor4f expected4f; |
Michael Ludwig | 7034f15 | 2018-10-08 16:43:58 -0400 | [diff] [blame] | 559 | if (fp->hasConstantOutputForConstantInput(input4f, &expected4f)) { |
Brian Osman | cb3d087 | 2018-10-16 15:19:28 -0400 | [diff] [blame] | 560 | float rDiff = fabsf(output4f.fR - expected4f.fR); |
| 561 | float gDiff = fabsf(output4f.fG - expected4f.fG); |
| 562 | float bDiff = fabsf(output4f.fB - expected4f.fB); |
| 563 | float aDiff = fabsf(output4f.fA - expected4f.fA); |
Brian Salomon | 5d4cd9e | 2017-02-09 11:16:46 -0500 | [diff] [blame] | 564 | static constexpr float kTol = 4 / 255.f; |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 565 | if (rDiff > kTol || gDiff > kTol || bDiff > kTol || aDiff > kTol) { |
Michael Ludwig | 314d377 | 2018-10-03 16:04:38 -0400 | [diff] [blame] | 566 | if (constMessage.isEmpty()) { |
| 567 | passing = false; |
| 568 | |
| 569 | constMessage.printf("Processor %s claimed output for const input " |
| 570 | "doesn't match actual output. Error: %f, Tolerance: %f, " |
| 571 | "input: (%f, %f, %f, %f), actual: (%f, %f, %f, %f), " |
Michael Ludwig | 7034f15 | 2018-10-08 16:43:58 -0400 | [diff] [blame] | 572 | "expected(%f, %f, %f, %f)", fp->name(), |
Michael Ludwig | 314d377 | 2018-10-03 16:04:38 -0400 | [diff] [blame] | 573 | SkTMax(rDiff, SkTMax(gDiff, SkTMax(bDiff, aDiff))), kTol, |
| 574 | input4f.fR, input4f.fG, input4f.fB, input4f.fA, |
Brian Osman | cb3d087 | 2018-10-16 15:19:28 -0400 | [diff] [blame] | 575 | output4f.fR, output4f.fG, output4f.fB, output4f.fA, |
| 576 | expected4f.fR, expected4f.fG, expected4f.fB, expected4f.fA); |
Michael Ludwig | 314d377 | 2018-10-03 16:04:38 -0400 | [diff] [blame] | 577 | } |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 578 | } |
| 579 | } |
Brian Osman | 00b2939 | 2018-11-05 15:42:43 -0500 | [diff] [blame] | 580 | if (input4f.isOpaque() && fp->preservesOpaqueInput() && !output4f.isOpaque()) { |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 581 | passing = false; |
Michael Ludwig | 314d377 | 2018-10-03 16:04:38 -0400 | [diff] [blame] | 582 | |
| 583 | if (opaqueMessage.isEmpty()) { |
| 584 | opaqueMessage.printf("Processor %s claimed opaqueness is preserved but " |
| 585 | "it is not. Input: 0x%08x, Output: 0x%08x.", |
Michael Ludwig | 7034f15 | 2018-10-08 16:43:58 -0400 | [diff] [blame] | 586 | fp->name(), input, output); |
Michael Ludwig | e8e1075 | 2018-10-01 12:42:53 -0400 | [diff] [blame] | 587 | } |
Brian Osman | bd1f76f | 2017-03-15 11:33:12 -0400 | [diff] [blame] | 588 | } |
Michael Ludwig | 314d377 | 2018-10-03 16:04:38 -0400 | [diff] [blame] | 589 | |
| 590 | if (!passing) { |
| 591 | // Regardless of how many optimizations the pixel violates, count it as a |
| 592 | // single bad pixel. |
| 593 | failedPixelCount++; |
| 594 | } |
| 595 | } |
| 596 | } |
| 597 | |
| 598 | // Finished analyzing the entire image, see if the number of pixel failures meets the |
| 599 | // threshold for an FP violating the optimization requirements. |
| 600 | if (failedPixelCount > kMaxAcceptableFailedPixels) { |
Michael Ludwig | 4504a652 | 2018-10-03 16:47:55 -0400 | [diff] [blame] | 601 | ERRORF(reporter, "Processor violated %d of %d pixels, seed: 0x%08x, processor: %s" |
Michael Ludwig | 314d377 | 2018-10-03 16:04:38 -0400 | [diff] [blame] | 602 | ", first failing pixel details are below:", |
| 603 | failedPixelCount, kRenderSize * kRenderSize, seed, |
Michael Ludwig | 7034f15 | 2018-10-08 16:43:58 -0400 | [diff] [blame] | 604 | fp->dumpInfo().c_str()); |
Michael Ludwig | 314d377 | 2018-10-03 16:04:38 -0400 | [diff] [blame] | 605 | |
| 606 | // Print first failing pixel's details. |
| 607 | if (!coverageMessage.isEmpty()) { |
| 608 | ERRORF(reporter, coverageMessage.c_str()); |
| 609 | } |
| 610 | if (!constMessage.isEmpty()) { |
| 611 | ERRORF(reporter, constMessage.c_str()); |
| 612 | } |
| 613 | if (!opaqueMessage.isEmpty()) { |
| 614 | ERRORF(reporter, opaqueMessage.c_str()); |
| 615 | } |
| 616 | |
| 617 | if (!loggedFirstFailure) { |
| 618 | // Print with ERRORF to make sure the encoded image is output |
| 619 | SkString input; |
Brian Salomon | cd8b6d5 | 2019-08-13 12:40:04 -0400 | [diff] [blame] | 620 | log_texture_proxy(context, inputTexture1, &input); |
Michael Ludwig | 314d377 | 2018-10-03 16:04:38 -0400 | [diff] [blame] | 621 | SkString output; |
Brian Salomon | cd8b6d5 | 2019-08-13 12:40:04 -0400 | [diff] [blame] | 622 | log_pixels(readData1.get(), kRenderSize, &output); |
Michael Ludwig | 314d377 | 2018-10-03 16:04:38 -0400 | [diff] [blame] | 623 | ERRORF(reporter, "Input image: %s\n\n" |
| 624 | "===========================================================\n\n" |
| 625 | "Output image: %s\n", input.c_str(), output.c_str()); |
| 626 | loggedFirstFailure = true; |
| 627 | } |
Michael Ludwig | 7034f15 | 2018-10-08 16:43:58 -0400 | [diff] [blame] | 628 | } else if(failedPixelCount > 0) { |
Michael Ludwig | 314d377 | 2018-10-03 16:04:38 -0400 | [diff] [blame] | 629 | // Don't trigger an error, but don't just hide the failures either. |
| 630 | INFOF(reporter, "Processor violated %d of %d pixels (below error threshold), seed: " |
| 631 | "0x%08x, processor: %s", failedPixelCount, kRenderSize * kRenderSize, |
Michael Ludwig | 7034f15 | 2018-10-08 16:43:58 -0400 | [diff] [blame] | 632 | seed, fp->dumpInfo().c_str()); |
Michael Ludwig | 314d377 | 2018-10-03 16:04:38 -0400 | [diff] [blame] | 633 | if (!coverageMessage.isEmpty()) { |
| 634 | INFOF(reporter, coverageMessage.c_str()); |
| 635 | } |
| 636 | if (!constMessage.isEmpty()) { |
| 637 | INFOF(reporter, constMessage.c_str()); |
| 638 | } |
| 639 | if (!opaqueMessage.isEmpty()) { |
| 640 | INFOF(reporter, opaqueMessage.c_str()); |
| 641 | } |
| 642 | if (!loggedFirstWarning) { |
| 643 | SkString input; |
Brian Salomon | cd8b6d5 | 2019-08-13 12:40:04 -0400 | [diff] [blame] | 644 | log_texture_proxy(context, inputTexture1, &input); |
Michael Ludwig | 314d377 | 2018-10-03 16:04:38 -0400 | [diff] [blame] | 645 | SkString output; |
Brian Salomon | cd8b6d5 | 2019-08-13 12:40:04 -0400 | [diff] [blame] | 646 | log_pixels(readData1.get(), kRenderSize, &output); |
Michael Ludwig | 314d377 | 2018-10-03 16:04:38 -0400 | [diff] [blame] | 647 | INFOF(reporter, "Input image: %s\n\n" |
| 648 | "===========================================================\n\n" |
| 649 | "Output image: %s\n", input.c_str(), output.c_str()); |
| 650 | loggedFirstWarning = true; |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 651 | } |
| 652 | } |
| 653 | } |
| 654 | } |
| 655 | } |
Robert Phillips | 18166ee | 2017-06-01 12:55:44 -0400 | [diff] [blame] | 656 | |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 657 | // Tests that fragment processors returned by GrFragmentProcessor::clone() are equivalent to their |
| 658 | // progenitors. |
| 659 | DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ProcessorCloneTest, reporter, ctxInfo) { |
| 660 | GrContext* context = ctxInfo.grContext(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 661 | GrProxyProvider* proxyProvider = context->priv().proxyProvider(); |
| 662 | auto resourceProvider = context->priv().resourceProvider(); |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 663 | |
| 664 | SkRandom random; |
| 665 | |
| 666 | // Make the destination context for the test. |
| 667 | static constexpr int kRenderSize = 1024; |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 668 | auto rtc = context->priv().makeDeferredRenderTargetContext( |
Brian Salomon | 27ae52c | 2019-07-03 11:27:44 -0400 | [diff] [blame] | 669 | SkBackingFit::kExact, kRenderSize, kRenderSize, GrColorType::kRGBA_8888, nullptr); |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 670 | |
| 671 | sk_sp<GrTextureProxy> proxies[2]; |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 672 | GrColorType proxyColorTypes[2]; |
| 673 | if (!init_test_textures(resourceProvider, proxyProvider, &random, proxies, proxyColorTypes)) { |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 674 | ERRORF(reporter, "Could not create test textures"); |
| 675 | return; |
| 676 | } |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 677 | GrProcessorTestData testData(&random, context, rtc.get(), proxies, proxyColorTypes); |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 678 | |
Michael Ludwig | 7034f15 | 2018-10-08 16:43:58 -0400 | [diff] [blame] | 679 | auto inputTexture = make_input_texture(proxyProvider, kRenderSize, kRenderSize, 0.0f); |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 680 | std::unique_ptr<GrColor[]> readData1(new GrColor[kRenderSize * kRenderSize]); |
| 681 | std::unique_ptr<GrColor[]> readData2(new GrColor[kRenderSize * kRenderSize]); |
Brian Salomon | cd8b6d5 | 2019-08-13 12:40:04 -0400 | [diff] [blame] | 682 | // On failure we write out images, but just write the first failing set as the print is very |
| 683 | // large. |
| 684 | bool loggedFirstFailure = false; |
| 685 | |
| 686 | // This test has a history of being flaky on a number of devices. If an FP clone is logically |
| 687 | // wrong, it's reasonable to expect it produce a large number of pixel differences in the image |
| 688 | // Sporadic pixel violations are more indicative device errors and represents a separate |
| 689 | // problem. |
| 690 | #if defined(SK_BUILD_FOR_SKQP) |
| 691 | static constexpr int kMaxAcceptableFailedPixels = 0; // Strict when running as SKQP |
| 692 | #else |
| 693 | static constexpr int kMaxAcceptableFailedPixels = 2 * kRenderSize; // ~0.7% of the image |
| 694 | #endif |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 695 | |
| 696 | // Because processor factories configure themselves in random ways, this is not exhaustive. |
| 697 | for (int i = 0; i < GrFragmentProcessorTestFactory::Count(); ++i) { |
| 698 | static constexpr int kTimesToInvokeFactory = 10; |
| 699 | for (int j = 0; j < kTimesToInvokeFactory; ++j) { |
| 700 | auto fp = GrFragmentProcessorTestFactory::MakeIdx(i, &testData); |
| 701 | auto clone = fp->clone(); |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 702 | if (!clone) { |
Brian Salomon | 96271cd | 2017-07-31 16:27:23 -0400 | [diff] [blame] | 703 | ERRORF(reporter, "Clone of processor %s failed.", fp->name()); |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 704 | continue; |
| 705 | } |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 706 | const char* name = fp->name(); |
Brian Salomon | ce06e26 | 2017-08-01 16:23:40 -0400 | [diff] [blame] | 707 | REPORTER_ASSERT(reporter, !strcmp(fp->name(), clone->name())); |
| 708 | REPORTER_ASSERT(reporter, fp->compatibleWithCoverageAsAlpha() == |
| 709 | clone->compatibleWithCoverageAsAlpha()); |
| 710 | REPORTER_ASSERT(reporter, fp->isEqual(*clone)); |
| 711 | REPORTER_ASSERT(reporter, fp->preservesOpaqueInput() == clone->preservesOpaqueInput()); |
| 712 | REPORTER_ASSERT(reporter, fp->hasConstantOutputForConstantInput() == |
| 713 | clone->hasConstantOutputForConstantInput()); |
| 714 | REPORTER_ASSERT(reporter, fp->numChildProcessors() == clone->numChildProcessors()); |
| 715 | REPORTER_ASSERT(reporter, fp->usesLocalCoords() == clone->usesLocalCoords()); |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 716 | // Draw with original and read back the results. |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 717 | render_fp(context, rtc.get(), fp.get(), inputTexture, GrColorType::kRGBA_8888, |
Greg Daniel | c594e62 | 2019-10-15 14:01:49 -0400 | [diff] [blame] | 718 | readData1.get()); |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 719 | |
| 720 | // Draw with clone and read back the results. |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 721 | render_fp(context, rtc.get(), clone.get(), inputTexture, GrColorType::kRGBA_8888, |
Greg Daniel | c594e62 | 2019-10-15 14:01:49 -0400 | [diff] [blame] | 722 | readData2.get()); |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 723 | |
| 724 | // Check that the results are the same. |
| 725 | bool passing = true; |
Brian Salomon | cd8b6d5 | 2019-08-13 12:40:04 -0400 | [diff] [blame] | 726 | int failedPixelCount = 0; |
| 727 | int firstWrongX = 0; |
| 728 | int firstWrongY = 0; |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 729 | for (int y = 0; y < kRenderSize && passing; ++y) { |
| 730 | for (int x = 0; x < kRenderSize && passing; ++x) { |
| 731 | int idx = y * kRenderSize + x; |
| 732 | if (readData1[idx] != readData2[idx]) { |
Brian Salomon | cd8b6d5 | 2019-08-13 12:40:04 -0400 | [diff] [blame] | 733 | if (!failedPixelCount) { |
| 734 | firstWrongX = x; |
| 735 | firstWrongY = y; |
| 736 | } |
| 737 | ++failedPixelCount; |
| 738 | } |
| 739 | if (failedPixelCount > kMaxAcceptableFailedPixels) { |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 740 | passing = false; |
Brian Salomon | cd8b6d5 | 2019-08-13 12:40:04 -0400 | [diff] [blame] | 741 | idx = firstWrongY * kRenderSize + firstWrongX; |
| 742 | ERRORF(reporter, |
| 743 | "Processor %s made clone produced different output at (%d, %d). " |
| 744 | "Input color: 0x%08x, Original Output Color: 0x%08x, " |
| 745 | "Clone Output Color: 0x%08x.", |
| 746 | name, firstWrongX, firstWrongY, input_texel_color(x, y, 0.0f), |
| 747 | readData1[idx], readData2[idx]); |
| 748 | if (!loggedFirstFailure) { |
| 749 | // Write the images out as data urls for inspection. |
| 750 | // We mark the data as unpremul to avoid conversion when encoding as |
| 751 | // PNG. Also, even though we made the data by rendering into |
| 752 | // a "unpremul" GrRenderTargetContext, our input texture is unpremul and |
| 753 | // outside of the random effect configuration, we didn't do anything to |
| 754 | // ensure the output is actually premul. |
| 755 | auto info = SkImageInfo::Make(kRenderSize, kRenderSize, |
| 756 | kRGBA_8888_SkColorType, |
| 757 | kUnpremul_SkAlphaType); |
| 758 | SkString input, orig, clone; |
| 759 | if (log_texture_proxy(context, inputTexture, &input) && |
| 760 | log_pixels(readData1.get(), kRenderSize, &orig) && |
| 761 | log_pixels(readData2.get(), kRenderSize, &clone)) { |
| 762 | ERRORF(reporter, |
| 763 | "\nInput image:\n%s\n\n" |
| 764 | "===========================================================" |
| 765 | "\n\n" |
| 766 | "Orig output image:\n%s\n" |
| 767 | "===========================================================" |
| 768 | "\n\n" |
| 769 | "Clone output image:\n%s\n", |
| 770 | input.c_str(), orig.c_str(), clone.c_str()); |
| 771 | loggedFirstFailure = true; |
| 772 | } |
| 773 | } |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 774 | } |
| 775 | } |
| 776 | } |
| 777 | } |
| 778 | } |
| 779 | } |
| 780 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 781 | #endif // GR_TEST_UTILS |