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 | |
| 8 | #include "SkTypes.h" |
| 9 | #include "Test.h" |
| 10 | |
| 11 | #if SK_SUPPORT_GPU |
Brian Salomon | ac70f84 | 2017-05-08 10:43:33 -0400 | [diff] [blame] | 12 | #include <random> |
Brian Salomon | c65aec9 | 2017-03-09 09:03:58 -0500 | [diff] [blame] | 13 | #include "GrClip.h" |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 14 | #include "GrContext.h" |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame^] | 15 | #include "GrContextPriv.h" |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 16 | #include "GrGpuResource.h" |
| 17 | #include "GrRenderTargetContext.h" |
| 18 | #include "GrRenderTargetContextPriv.h" |
| 19 | #include "GrResourceProvider.h" |
| 20 | #include "glsl/GrGLSLFragmentProcessor.h" |
| 21 | #include "glsl/GrGLSLFragmentShaderBuilder.h" |
Brian Salomon | 82ddc94 | 2017-07-14 12:00:13 -0400 | [diff] [blame] | 22 | #include "ops/GrMeshDrawOp.h" |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 23 | #include "ops/GrRectOpFactory.h" |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 24 | |
| 25 | namespace { |
Brian Salomon | 82ddc94 | 2017-07-14 12:00:13 -0400 | [diff] [blame] | 26 | class TestOp : public GrMeshDrawOp { |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 27 | public: |
| 28 | DEFINE_OP_CLASS_ID |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 29 | static std::unique_ptr<GrDrawOp> Make(std::unique_ptr<GrFragmentProcessor> fp) { |
Brian Salomon | 82ddc94 | 2017-07-14 12:00:13 -0400 | [diff] [blame] | 30 | return std::unique_ptr<GrDrawOp>(new TestOp(std::move(fp))); |
| 31 | } |
| 32 | |
Robert Phillips | 5f567c7 | 2017-09-14 08:27:37 -0400 | [diff] [blame] | 33 | const char* name() const override { return "TestOp"; } |
| 34 | |
Robert Phillips | f1748f5 | 2017-09-14 14:11:24 -0400 | [diff] [blame] | 35 | void visitProxies(const VisitProxyFunc& func) const override { |
Robert Phillips | 5f567c7 | 2017-09-14 08:27:37 -0400 | [diff] [blame] | 36 | fProcessors.visitProxies(func); |
| 37 | } |
| 38 | |
Brian Salomon | 82ddc94 | 2017-07-14 12:00:13 -0400 | [diff] [blame] | 39 | FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; } |
| 40 | |
Brian Osman | 9a725dd | 2017-09-20 09:53:22 -0400 | [diff] [blame] | 41 | RequiresDstTexture finalize(const GrCaps& caps, const GrAppliedClip* clip, |
| 42 | GrPixelConfigIsClamped dstIsClamped) override { |
Brian Salomon | 82ddc94 | 2017-07-14 12:00:13 -0400 | [diff] [blame] | 43 | static constexpr GrProcessorAnalysisColor kUnknownColor; |
| 44 | GrColor overrideColor; |
| 45 | fProcessors.finalize(kUnknownColor, GrProcessorAnalysisCoverage::kNone, clip, false, caps, |
Brian Osman | 9a725dd | 2017-09-20 09:53:22 -0400 | [diff] [blame] | 46 | dstIsClamped, &overrideColor); |
Brian Salomon | 82ddc94 | 2017-07-14 12:00:13 -0400 | [diff] [blame] | 47 | return RequiresDstTexture::kNo; |
Brian Salomon | 649a341 | 2017-03-09 13:50:43 -0500 | [diff] [blame] | 48 | } |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 49 | |
| 50 | private: |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 51 | TestOp(std::unique_ptr<GrFragmentProcessor> fp) |
| 52 | : INHERITED(ClassID()), fProcessors(std::move(fp)) { |
Brian Salomon | 82ddc94 | 2017-07-14 12:00:13 -0400 | [diff] [blame] | 53 | this->setBounds(SkRect::MakeWH(100, 100), HasAABloat::kNo, IsZeroArea::kNo); |
| 54 | } |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 55 | |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 56 | void onPrepareDraws(Target* target) override { return; } |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 57 | |
Brian Salomon | 82ddc94 | 2017-07-14 12:00:13 -0400 | [diff] [blame] | 58 | bool onCombineIfPossible(GrOp* op, const GrCaps& caps) override { return false; } |
| 59 | |
| 60 | GrProcessorSet fProcessors; |
| 61 | |
| 62 | typedef GrMeshDrawOp INHERITED; |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | /** |
| 66 | * FP used to test ref/IO counts on owned GrGpuResources. Can also be a parent FP to test counts |
| 67 | * of resources owned by child FPs. |
| 68 | */ |
| 69 | class TestFP : public GrFragmentProcessor { |
| 70 | public: |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 71 | static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> child) { |
| 72 | return std::unique_ptr<GrFragmentProcessor>(new TestFP(std::move(child))); |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 73 | } |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 74 | static std::unique_ptr<GrFragmentProcessor> Make(const SkTArray<sk_sp<GrTextureProxy>>& proxies, |
Brian Salomon | 559f556 | 2017-11-15 14:28:33 -0500 | [diff] [blame] | 75 | const SkTArray<sk_sp<GrBuffer>>& buffers) { |
| 76 | return std::unique_ptr<GrFragmentProcessor>(new TestFP(proxies, buffers)); |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | const char* name() const override { return "test"; } |
| 80 | |
| 81 | void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder* b) const override { |
| 82 | // We don't really care about reusing these. |
| 83 | static int32_t gKey = 0; |
| 84 | b->add32(sk_atomic_inc(&gKey)); |
| 85 | } |
| 86 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 87 | std::unique_ptr<GrFragmentProcessor> clone() const override { |
| 88 | return std::unique_ptr<GrFragmentProcessor>(new TestFP(*this)); |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 89 | } |
| 90 | |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 91 | private: |
Brian Salomon | 559f556 | 2017-11-15 14:28:33 -0500 | [diff] [blame] | 92 | TestFP(const SkTArray<sk_sp<GrTextureProxy>>& proxies, const SkTArray<sk_sp<GrBuffer>>& buffers) |
| 93 | : INHERITED(kTestFP_ClassID, kNone_OptimizationFlags), fSamplers(4), fBuffers(4) { |
Robert Phillips | 30f9bc6 | 2017-02-22 15:28:38 -0500 | [diff] [blame] | 94 | for (const auto& proxy : proxies) { |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 95 | this->addTextureSampler(&fSamplers.emplace_back(proxy)); |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 96 | } |
| 97 | for (const auto& buffer : buffers) { |
| 98 | this->addBufferAccess(&fBuffers.emplace_back(kRGBA_8888_GrPixelConfig, buffer.get())); |
| 99 | } |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 100 | } |
| 101 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 102 | TestFP(std::unique_ptr<GrFragmentProcessor> child) |
Brian Salomon | 559f556 | 2017-11-15 14:28:33 -0500 | [diff] [blame] | 103 | : INHERITED(kTestFP_ClassID, kNone_OptimizationFlags), fSamplers(4), fBuffers(4) { |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 104 | this->registerChildProcessor(std::move(child)); |
| 105 | } |
| 106 | |
Brian Salomon | 96271cd | 2017-07-31 16:27:23 -0400 | [diff] [blame] | 107 | explicit TestFP(const TestFP& that) |
Brian Salomon | 559f556 | 2017-11-15 14:28:33 -0500 | [diff] [blame] | 108 | : INHERITED(kTestFP_ClassID, that.optimizationFlags()), fSamplers(4), fBuffers(4) { |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 109 | for (int i = 0; i < that.fSamplers.count(); ++i) { |
| 110 | fSamplers.emplace_back(that.fSamplers[i]); |
| 111 | this->addTextureSampler(&fSamplers.back()); |
| 112 | } |
| 113 | for (int i = 0; i < that.fBuffers.count(); ++i) { |
| 114 | fBuffers.emplace_back(that.fBuffers[i]); |
| 115 | this->addBufferAccess(&fBuffers.back()); |
| 116 | } |
Brian Salomon | 96271cd | 2017-07-31 16:27:23 -0400 | [diff] [blame] | 117 | for (int i = 0; i < that.numChildProcessors(); ++i) { |
| 118 | this->registerChildProcessor(that.childProcessor(i).clone()); |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 119 | } |
| 120 | } |
| 121 | |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 122 | virtual GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { |
| 123 | class TestGLSLFP : public GrGLSLFragmentProcessor { |
| 124 | public: |
| 125 | TestGLSLFP() {} |
| 126 | void emitCode(EmitArgs& args) override { |
| 127 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 128 | fragBuilder->codeAppendf("%s = %s;", args.fOutputColor, args.fInputColor); |
| 129 | } |
| 130 | |
| 131 | private: |
| 132 | }; |
| 133 | return new TestGLSLFP(); |
| 134 | } |
| 135 | |
| 136 | bool onIsEqual(const GrFragmentProcessor&) const override { return false; } |
| 137 | |
| 138 | GrTAllocator<TextureSampler> fSamplers; |
| 139 | GrTAllocator<BufferAccess> fBuffers; |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 140 | typedef GrFragmentProcessor INHERITED; |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 141 | }; |
| 142 | } |
| 143 | |
Brian Salomon | f046e15 | 2017-01-11 15:24:47 -0500 | [diff] [blame] | 144 | template <typename T> |
| 145 | inline void testingOnly_getIORefCnts(const T* resource, int* refCnt, int* readCnt, int* writeCnt) { |
| 146 | *refCnt = resource->fRefCnt; |
| 147 | *readCnt = resource->fPendingReads; |
| 148 | *writeCnt = resource->fPendingWrites; |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 149 | } |
| 150 | |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 151 | void testingOnly_getIORefCnts(GrTextureProxy* proxy, int* refCnt, int* readCnt, int* writeCnt) { |
Robert Phillips | 30f9bc6 | 2017-02-22 15:28:38 -0500 | [diff] [blame] | 152 | *refCnt = proxy->getBackingRefCnt_TestOnly(); |
| 153 | *readCnt = proxy->getPendingReadCnt_TestOnly(); |
| 154 | *writeCnt = proxy->getPendingWriteCnt_TestOnly(); |
| 155 | } |
| 156 | |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 157 | DEF_GPUTEST_FOR_ALL_CONTEXTS(ProcessorRefTest, reporter, ctxInfo) { |
| 158 | GrContext* context = ctxInfo.grContext(); |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame^] | 159 | GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider(); |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 160 | |
Robert Phillips | 16d8ec6 | 2017-07-27 16:16:25 -0400 | [diff] [blame] | 161 | GrSurfaceDesc desc; |
| 162 | desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 163 | desc.fWidth = 10; |
| 164 | desc.fHeight = 10; |
Robert Phillips | 16d8ec6 | 2017-07-27 16:16:25 -0400 | [diff] [blame] | 165 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 166 | |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 167 | for (bool makeClone : {false, true}) { |
| 168 | for (int parentCnt = 0; parentCnt < 2; parentCnt++) { |
| 169 | sk_sp<GrRenderTargetContext> renderTargetContext( |
| 170 | context->makeDeferredRenderTargetContext( SkBackingFit::kApprox, 1, 1, |
| 171 | kRGBA_8888_GrPixelConfig, nullptr)); |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 172 | { |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 173 | bool texelBufferSupport = context->caps()->shaderCaps()->texelBufferSupport(); |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 174 | sk_sp<GrTextureProxy> proxy1( |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame^] | 175 | GrSurfaceProxy::MakeDeferred(proxyProvider, |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 176 | desc, SkBackingFit::kExact, |
| 177 | SkBudgeted::kYes)); |
| 178 | sk_sp<GrTextureProxy> proxy2 |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame^] | 179 | (GrSurfaceProxy::MakeDeferred(proxyProvider, |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 180 | desc, SkBackingFit::kExact, |
| 181 | SkBudgeted::kYes)); |
| 182 | sk_sp<GrTextureProxy> proxy3( |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame^] | 183 | GrSurfaceProxy::MakeDeferred(proxyProvider, |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 184 | desc, SkBackingFit::kExact, |
| 185 | SkBudgeted::kYes)); |
| 186 | sk_sp<GrTextureProxy> proxy4( |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame^] | 187 | GrSurfaceProxy::MakeDeferred(proxyProvider, |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 188 | desc, SkBackingFit::kExact, |
| 189 | SkBudgeted::kYes)); |
| 190 | sk_sp<GrBuffer> buffer(texelBufferSupport |
| 191 | ? context->resourceProvider()->createBuffer( |
| 192 | 1024, GrBufferType::kTexel_GrBufferType, |
| 193 | GrAccessPattern::kStatic_GrAccessPattern, 0) |
| 194 | : nullptr); |
| 195 | { |
| 196 | SkTArray<sk_sp<GrTextureProxy>> proxies; |
| 197 | SkTArray<sk_sp<GrBuffer>> buffers; |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 198 | proxies.push_back(proxy1); |
| 199 | if (texelBufferSupport) { |
| 200 | buffers.push_back(buffer); |
| 201 | } |
Brian Salomon | 559f556 | 2017-11-15 14:28:33 -0500 | [diff] [blame] | 202 | auto fp = TestFP::Make(std::move(proxies), std::move(buffers)); |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 203 | for (int i = 0; i < parentCnt; ++i) { |
| 204 | fp = TestFP::Make(std::move(fp)); |
| 205 | } |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 206 | std::unique_ptr<GrFragmentProcessor> clone; |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 207 | if (makeClone) { |
| 208 | clone = fp->clone(); |
| 209 | } |
| 210 | std::unique_ptr<GrDrawOp> op(TestOp::Make(std::move(fp))); |
| 211 | renderTargetContext->priv().testingOnly_addDrawOp(std::move(op)); |
| 212 | if (clone) { |
| 213 | op = TestOp::Make(std::move(clone)); |
| 214 | renderTargetContext->priv().testingOnly_addDrawOp(std::move(op)); |
| 215 | } |
| 216 | } |
| 217 | int refCnt, readCnt, writeCnt; |
| 218 | |
| 219 | testingOnly_getIORefCnts(proxy1.get(), &refCnt, &readCnt, &writeCnt); |
| 220 | // IO counts should be double if there is a clone of the FP. |
| 221 | int ioRefMul = makeClone ? 2 : 1; |
| 222 | REPORTER_ASSERT(reporter, 1 == refCnt); |
| 223 | REPORTER_ASSERT(reporter, ioRefMul * 1 == readCnt); |
| 224 | REPORTER_ASSERT(reporter, ioRefMul * 0 == writeCnt); |
| 225 | |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 226 | if (texelBufferSupport) { |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 227 | testingOnly_getIORefCnts(buffer.get(), &refCnt, &readCnt, &writeCnt); |
| 228 | REPORTER_ASSERT(reporter, 1 == refCnt); |
| 229 | REPORTER_ASSERT(reporter, ioRefMul * 1 == readCnt); |
| 230 | REPORTER_ASSERT(reporter, ioRefMul * 0 == writeCnt); |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 231 | } |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 232 | |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 233 | context->flush(); |
| 234 | |
| 235 | testingOnly_getIORefCnts(proxy1.get(), &refCnt, &readCnt, &writeCnt); |
| 236 | REPORTER_ASSERT(reporter, 1 == refCnt); |
| 237 | REPORTER_ASSERT(reporter, ioRefMul * 0 == readCnt); |
| 238 | REPORTER_ASSERT(reporter, ioRefMul * 0 == writeCnt); |
| 239 | |
| 240 | if (texelBufferSupport) { |
| 241 | testingOnly_getIORefCnts(buffer.get(), &refCnt, &readCnt, &writeCnt); |
| 242 | REPORTER_ASSERT(reporter, 1 == refCnt); |
| 243 | REPORTER_ASSERT(reporter, ioRefMul * 0 == readCnt); |
| 244 | REPORTER_ASSERT(reporter, ioRefMul * 0 == writeCnt); |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 245 | } |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 246 | |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 247 | if (texelBufferSupport) { |
| 248 | testingOnly_getIORefCnts(proxy2.get(), &refCnt, &readCnt, &writeCnt); |
| 249 | REPORTER_ASSERT(reporter, 1 == refCnt); |
| 250 | REPORTER_ASSERT(reporter, ioRefMul * 0 == readCnt); |
| 251 | REPORTER_ASSERT(reporter, ioRefMul * 0 == writeCnt); |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 252 | |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 253 | testingOnly_getIORefCnts(proxy3.get(), &refCnt, &readCnt, &writeCnt); |
| 254 | REPORTER_ASSERT(reporter, 1 == refCnt); |
| 255 | REPORTER_ASSERT(reporter, ioRefMul * 0 == readCnt); |
| 256 | REPORTER_ASSERT(reporter, ioRefMul * 0 == writeCnt); |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 257 | |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 258 | testingOnly_getIORefCnts(proxy4.get(), &refCnt, &readCnt, &writeCnt); |
| 259 | REPORTER_ASSERT(reporter, 1 == refCnt); |
| 260 | REPORTER_ASSERT(reporter, ioRefMul * 0 == readCnt); |
| 261 | REPORTER_ASSERT(reporter, ioRefMul * 0 == writeCnt); |
| 262 | } |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 263 | } |
| 264 | } |
| 265 | } |
| 266 | } |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 267 | |
| 268 | // This test uses the random GrFragmentProcessor test factory, which relies on static initializers. |
| 269 | #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
| 270 | |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 271 | #include "SkCommandLineFlags.h" |
| 272 | DEFINE_bool(randomProcessorTest, false, "Use non-deterministic seed for random processor tests?"); |
| 273 | |
| 274 | #if GR_TEST_UTILS |
| 275 | |
| 276 | static GrColor input_texel_color(int i, int j) { |
| 277 | GrColor color = GrColorPackRGBA((uint8_t)j, (uint8_t)(i + j), (uint8_t)(2 * j - i), (uint8_t)i); |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 278 | return GrPremulColor(color); |
| 279 | } |
| 280 | |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 281 | static GrColor4f input_texel_color4f(int i, int j) { |
| 282 | return GrColor4f::FromGrColor(input_texel_color(i, j)); |
| 283 | } |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 284 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 285 | void test_draw_op(GrRenderTargetContext* rtc, std::unique_ptr<GrFragmentProcessor> fp, |
Robert Phillips | 30f9bc6 | 2017-02-22 15:28:38 -0500 | [diff] [blame] | 286 | sk_sp<GrTextureProxy> inputDataProxy) { |
Brian Salomon | 5d4cd9e | 2017-02-09 11:16:46 -0500 | [diff] [blame] | 287 | GrPaint paint; |
Brian Osman | 2240be9 | 2017-10-18 13:15:13 -0400 | [diff] [blame] | 288 | paint.addColorTextureProcessor(std::move(inputDataProxy), SkMatrix::I()); |
Brian Salomon | 5d4cd9e | 2017-02-09 11:16:46 -0500 | [diff] [blame] | 289 | paint.addColorFragmentProcessor(std::move(fp)); |
| 290 | paint.setPorterDuffXPFactory(SkBlendMode::kSrc); |
Brian Salomon | ac70f84 | 2017-05-08 10:43:33 -0400 | [diff] [blame] | 291 | |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 292 | auto op = GrRectOpFactory::MakeNonAAFill(std::move(paint), SkMatrix::I(), |
| 293 | SkRect::MakeWH(rtc->width(), rtc->height()), |
| 294 | GrAAType::kNone); |
Brian Salomon | ac70f84 | 2017-05-08 10:43:33 -0400 | [diff] [blame] | 295 | rtc->addDrawOp(GrNoClip(), std::move(op)); |
Brian Salomon | 5d4cd9e | 2017-02-09 11:16:46 -0500 | [diff] [blame] | 296 | } |
| 297 | |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 298 | /** Initializes the two test texture proxies that are available to the FP test factories. */ |
| 299 | bool init_test_textures(GrContext* context, SkRandom* random, sk_sp<GrTextureProxy> proxies[2]) { |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame^] | 300 | GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider(); |
| 301 | |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 302 | static const int kTestTextureSize = 256; |
| 303 | GrSurfaceDesc desc; |
| 304 | desc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
| 305 | desc.fWidth = kTestTextureSize; |
| 306 | desc.fHeight = kTestTextureSize; |
| 307 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
Brian Osman | c35a2d4 | 2017-03-17 10:58:53 -0400 | [diff] [blame] | 308 | |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 309 | // Put premul data into the RGBA texture that the test FPs can optionally use. |
| 310 | std::unique_ptr<GrColor[]> rgbaData(new GrColor[kTestTextureSize * kTestTextureSize]); |
| 311 | for (int y = 0; y < kTestTextureSize; ++y) { |
| 312 | for (int x = 0; x < kTestTextureSize; ++x) { |
| 313 | rgbaData[kTestTextureSize * y + x] = |
| 314 | input_texel_color(random->nextULessThan(256), random->nextULessThan(256)); |
| 315 | } |
| 316 | } |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame^] | 317 | proxies[0] = GrSurfaceProxy::MakeDeferred(proxyProvider, desc, SkBudgeted::kYes, |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 318 | rgbaData.get(), kTestTextureSize * sizeof(GrColor)); |
| 319 | |
| 320 | // Put random values into the alpha texture that the test FPs can optionally use. |
| 321 | desc.fConfig = kAlpha_8_GrPixelConfig; |
| 322 | std::unique_ptr<uint8_t[]> alphaData(new uint8_t[kTestTextureSize * kTestTextureSize]); |
| 323 | for (int y = 0; y < kTestTextureSize; ++y) { |
| 324 | for (int x = 0; x < kTestTextureSize; ++x) { |
| 325 | alphaData[kTestTextureSize * y + x] = random->nextULessThan(256); |
| 326 | } |
| 327 | } |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame^] | 328 | proxies[1] = GrSurfaceProxy::MakeDeferred(proxyProvider, desc, SkBudgeted::kYes, |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 329 | alphaData.get(), kTestTextureSize); |
| 330 | |
| 331 | return proxies[0] && proxies[1]; |
| 332 | } |
| 333 | |
| 334 | // Creates a texture of premul colors used as the output of the fragment processor that precedes |
| 335 | // the fragment processor under test. Color values are those provided by input_texel_color(). |
| 336 | sk_sp<GrTextureProxy> make_input_texture(GrContext* context, int width, int height) { |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame^] | 337 | GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider(); |
| 338 | |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 339 | std::unique_ptr<GrColor[]> data(new GrColor[width * height]); |
| 340 | for (int y = 0; y < width; ++y) { |
| 341 | for (int x = 0; x < height; ++x) { |
| 342 | data.get()[width * y + x] = input_texel_color(x, y); |
| 343 | } |
| 344 | } |
| 345 | GrSurfaceDesc desc; |
| 346 | desc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
| 347 | desc.fWidth = width; |
| 348 | desc.fHeight = height; |
| 349 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame^] | 350 | return GrSurfaceProxy::MakeDeferred(proxyProvider, desc, SkBudgeted::kYes, |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 351 | data.get(), width * sizeof(GrColor)); |
| 352 | } |
Brian Salomon | 5d4cd9e | 2017-02-09 11:16:46 -0500 | [diff] [blame] | 353 | DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ProcessorOptimizationValidationTest, reporter, ctxInfo) { |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 354 | GrContext* context = ctxInfo.grContext(); |
Brian Salomon | 1c05364 | 2017-07-24 10:16:19 -0400 | [diff] [blame] | 355 | using FPFactory = GrFragmentProcessorTestFactory; |
Brian Osman | c35a2d4 | 2017-03-17 10:58:53 -0400 | [diff] [blame] | 356 | |
| 357 | uint32_t seed = 0; |
| 358 | if (FLAGS_randomProcessorTest) { |
| 359 | std::random_device rd; |
| 360 | seed = rd(); |
| 361 | } |
| 362 | // If a non-deterministic bot fails this test, check the output to see what seed it used, then |
| 363 | // hard-code that value here: |
| 364 | SkRandom random(seed); |
| 365 | |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 366 | // Make the destination context for the test. |
| 367 | static constexpr int kRenderSize = 256; |
Robert Phillips | dd3b3f4 | 2017-04-24 10:57:28 -0400 | [diff] [blame] | 368 | sk_sp<GrRenderTargetContext> rtc = context->makeDeferredRenderTargetContext( |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 369 | SkBackingFit::kExact, kRenderSize, kRenderSize, kRGBA_8888_GrPixelConfig, nullptr); |
Brian Salomon | d1a8bdf | 2017-02-10 12:39:26 -0500 | [diff] [blame] | 370 | |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 371 | sk_sp<GrTextureProxy> proxies[2]; |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 372 | if (!init_test_textures(context, &random, proxies)) { |
| 373 | ERRORF(reporter, "Could not create test textures"); |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 374 | return; |
| 375 | } |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 376 | GrProcessorTestData testData(&random, context, rtc.get(), proxies); |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 377 | |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 378 | auto inputTexture = make_input_texture(context, kRenderSize, kRenderSize); |
Robert Phillips | 30f9bc6 | 2017-02-22 15:28:38 -0500 | [diff] [blame] | 379 | |
Ben Wagner | 8c79194 | 2017-07-25 11:47:48 -0400 | [diff] [blame] | 380 | std::unique_ptr<GrColor[]> readData(new GrColor[kRenderSize * kRenderSize]); |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 381 | // Because processor factories configure themselves in random ways, this is not exhaustive. |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 382 | for (int i = 0; i < FPFactory::Count(); ++i) { |
| 383 | int timesToInvokeFactory = 5; |
| 384 | // Increase the number of attempts if the FP has child FPs since optimizations likely depend |
| 385 | // on child optimizations being present. |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 386 | std::unique_ptr<GrFragmentProcessor> fp = FPFactory::MakeIdx(i, &testData); |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 387 | for (int j = 0; j < fp->numChildProcessors(); ++j) { |
| 388 | // This value made a reasonable trade off between time and coverage when this test was |
| 389 | // written. |
| 390 | timesToInvokeFactory *= FPFactory::Count() / 2; |
| 391 | } |
| 392 | for (int j = 0; j < timesToInvokeFactory; ++j) { |
| 393 | fp = FPFactory::MakeIdx(i, &testData); |
Robert Phillips | 9bee2e5 | 2017-05-29 12:37:20 -0400 | [diff] [blame] | 394 | if (!fp->instantiate(context->resourceProvider())) { |
Robert Phillips | a91e0b7 | 2017-05-01 13:12:20 -0400 | [diff] [blame] | 395 | continue; |
| 396 | } |
| 397 | |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 398 | if (!fp->hasConstantOutputForConstantInput() && !fp->preservesOpaqueInput() && |
Brian Salomon | f3b995b | 2017-02-15 10:22:23 -0500 | [diff] [blame] | 399 | !fp->compatibleWithCoverageAsAlpha()) { |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 400 | continue; |
| 401 | } |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 402 | |
| 403 | // Since we transfer away ownership of the original FP, we make a clone. |
| 404 | auto clone = fp->clone(); |
| 405 | |
| 406 | test_draw_op(rtc.get(), std::move(fp), inputTexture); |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 407 | memset(readData.get(), 0x0, sizeof(GrColor) * kRenderSize * kRenderSize); |
| 408 | rtc->readPixels(SkImageInfo::Make(kRenderSize, kRenderSize, kRGBA_8888_SkColorType, |
| 409 | kPremul_SkAlphaType), |
| 410 | readData.get(), 0, 0, 0); |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 411 | bool passing = true; |
| 412 | if (0) { // Useful to see what FPs are being tested. |
| 413 | SkString children; |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 414 | for (int c = 0; c < clone->numChildProcessors(); ++c) { |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 415 | if (!c) { |
| 416 | children.append("("); |
| 417 | } |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 418 | children.append(clone->name()); |
| 419 | children.append(c == clone->numChildProcessors() - 1 ? ")" : ", "); |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 420 | } |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 421 | SkDebugf("%s %s\n", clone->name(), children.c_str()); |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 422 | } |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 423 | for (int y = 0; y < kRenderSize && passing; ++y) { |
| 424 | for (int x = 0; x < kRenderSize && passing; ++x) { |
| 425 | GrColor input = input_texel_color(x, y); |
| 426 | GrColor output = readData.get()[y * kRenderSize + x]; |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 427 | if (clone->compatibleWithCoverageAsAlpha()) { |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 428 | // A modulating processor is allowed to modulate either the input color or |
| 429 | // just the input alpha. |
| 430 | bool legalColorModulation = |
| 431 | GrColorUnpackA(output) <= GrColorUnpackA(input) && |
| 432 | GrColorUnpackR(output) <= GrColorUnpackR(input) && |
| 433 | GrColorUnpackG(output) <= GrColorUnpackG(input) && |
| 434 | GrColorUnpackB(output) <= GrColorUnpackB(input); |
| 435 | bool legalAlphaModulation = |
| 436 | GrColorUnpackA(output) <= GrColorUnpackA(input) && |
| 437 | GrColorUnpackR(output) <= GrColorUnpackA(input) && |
| 438 | GrColorUnpackG(output) <= GrColorUnpackA(input) && |
| 439 | GrColorUnpackB(output) <= GrColorUnpackA(input); |
| 440 | if (!legalColorModulation && !legalAlphaModulation) { |
| 441 | ERRORF(reporter, |
| 442 | "\"Modulating\" processor %s made color/alpha value larger. " |
Greg Daniel | 10ed243 | 2017-12-01 16:19:43 -0500 | [diff] [blame] | 443 | "Input: 0x%08x, Output: 0x%08x, pixel (%d, %d).", |
| 444 | clone->name(), input, output, x, y); |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 445 | passing = false; |
| 446 | } |
| 447 | } |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 448 | GrColor4f input4f = input_texel_color4f(x, y); |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 449 | GrColor4f output4f = GrColor4f::FromGrColor(output); |
| 450 | GrColor4f expected4f; |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 451 | if (clone->hasConstantOutputForConstantInput(input4f, &expected4f)) { |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 452 | float rDiff = fabsf(output4f.fRGBA[0] - expected4f.fRGBA[0]); |
| 453 | float gDiff = fabsf(output4f.fRGBA[1] - expected4f.fRGBA[1]); |
| 454 | float bDiff = fabsf(output4f.fRGBA[2] - expected4f.fRGBA[2]); |
| 455 | float aDiff = fabsf(output4f.fRGBA[3] - expected4f.fRGBA[3]); |
Brian Salomon | 5d4cd9e | 2017-02-09 11:16:46 -0500 | [diff] [blame] | 456 | static constexpr float kTol = 4 / 255.f; |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 457 | if (rDiff > kTol || gDiff > kTol || bDiff > kTol || aDiff > kTol) { |
| 458 | ERRORF(reporter, |
| 459 | "Processor %s claimed output for const input doesn't match " |
Brian Salomon | 5d4cd9e | 2017-02-09 11:16:46 -0500 | [diff] [blame] | 460 | "actual output. Error: %f, Tolerance: %f, input: (%f, %f, %f, " |
| 461 | "%f), actual: (%f, %f, %f, %f), expected(%f, %f, %f, %f)", |
| 462 | fp->name(), SkTMax(rDiff, SkTMax(gDiff, SkTMax(bDiff, aDiff))), |
| 463 | kTol, input4f.fRGBA[0], input4f.fRGBA[1], input4f.fRGBA[2], |
| 464 | input4f.fRGBA[3], output4f.fRGBA[0], output4f.fRGBA[1], |
| 465 | output4f.fRGBA[2], output4f.fRGBA[3], expected4f.fRGBA[0], |
| 466 | expected4f.fRGBA[1], expected4f.fRGBA[2], expected4f.fRGBA[3]); |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 467 | passing = false; |
| 468 | } |
| 469 | } |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 470 | if (GrColorIsOpaque(input) && clone->preservesOpaqueInput() && |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 471 | !GrColorIsOpaque(output)) { |
| 472 | ERRORF(reporter, |
| 473 | "Processor %s claimed opaqueness is preserved but it is not. Input: " |
Brian Osman | 2f3865b | 2017-03-15 13:35:51 -0400 | [diff] [blame] | 474 | "0x%08x, Output: 0x%08x.", |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 475 | clone->name(), input, output); |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 476 | passing = false; |
| 477 | } |
Brian Osman | bd1f76f | 2017-03-15 11:33:12 -0400 | [diff] [blame] | 478 | if (!passing) { |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 479 | ERRORF(reporter, "Seed: 0x%08x, Processor details: %s", seed, |
| 480 | clone->dumpInfo().c_str()); |
Brian Osman | bd1f76f | 2017-03-15 11:33:12 -0400 | [diff] [blame] | 481 | } |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 482 | } |
| 483 | } |
| 484 | } |
| 485 | } |
| 486 | } |
Robert Phillips | 18166ee | 2017-06-01 12:55:44 -0400 | [diff] [blame] | 487 | |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 488 | // Tests that fragment processors returned by GrFragmentProcessor::clone() are equivalent to their |
| 489 | // progenitors. |
| 490 | DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ProcessorCloneTest, reporter, ctxInfo) { |
| 491 | GrContext* context = ctxInfo.grContext(); |
| 492 | |
| 493 | SkRandom random; |
| 494 | |
| 495 | // Make the destination context for the test. |
| 496 | static constexpr int kRenderSize = 1024; |
| 497 | sk_sp<GrRenderTargetContext> rtc = context->makeDeferredRenderTargetContext( |
| 498 | SkBackingFit::kExact, kRenderSize, kRenderSize, kRGBA_8888_GrPixelConfig, nullptr); |
| 499 | |
| 500 | sk_sp<GrTextureProxy> proxies[2]; |
| 501 | if (!init_test_textures(context, &random, proxies)) { |
| 502 | ERRORF(reporter, "Could not create test textures"); |
| 503 | return; |
| 504 | } |
| 505 | GrProcessorTestData testData(&random, context, rtc.get(), proxies); |
| 506 | |
| 507 | auto inputTexture = make_input_texture(context, kRenderSize, kRenderSize); |
| 508 | std::unique_ptr<GrColor[]> readData1(new GrColor[kRenderSize * kRenderSize]); |
| 509 | std::unique_ptr<GrColor[]> readData2(new GrColor[kRenderSize * kRenderSize]); |
| 510 | auto readInfo = SkImageInfo::Make(kRenderSize, kRenderSize, kRGBA_8888_SkColorType, |
| 511 | kPremul_SkAlphaType); |
| 512 | |
| 513 | // Because processor factories configure themselves in random ways, this is not exhaustive. |
| 514 | for (int i = 0; i < GrFragmentProcessorTestFactory::Count(); ++i) { |
| 515 | static constexpr int kTimesToInvokeFactory = 10; |
| 516 | for (int j = 0; j < kTimesToInvokeFactory; ++j) { |
| 517 | auto fp = GrFragmentProcessorTestFactory::MakeIdx(i, &testData); |
| 518 | auto clone = fp->clone(); |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 519 | if (!clone) { |
Brian Salomon | 96271cd | 2017-07-31 16:27:23 -0400 | [diff] [blame] | 520 | ERRORF(reporter, "Clone of processor %s failed.", fp->name()); |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 521 | continue; |
| 522 | } |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 523 | const char* name = fp->name(); |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 524 | if (!fp->instantiate(context->resourceProvider()) || |
| 525 | !clone->instantiate(context->resourceProvider())) { |
| 526 | continue; |
| 527 | } |
Brian Salomon | ce06e26 | 2017-08-01 16:23:40 -0400 | [diff] [blame] | 528 | REPORTER_ASSERT(reporter, !strcmp(fp->name(), clone->name())); |
| 529 | REPORTER_ASSERT(reporter, fp->compatibleWithCoverageAsAlpha() == |
| 530 | clone->compatibleWithCoverageAsAlpha()); |
| 531 | REPORTER_ASSERT(reporter, fp->isEqual(*clone)); |
| 532 | REPORTER_ASSERT(reporter, fp->preservesOpaqueInput() == clone->preservesOpaqueInput()); |
| 533 | REPORTER_ASSERT(reporter, fp->hasConstantOutputForConstantInput() == |
| 534 | clone->hasConstantOutputForConstantInput()); |
| 535 | REPORTER_ASSERT(reporter, fp->numChildProcessors() == clone->numChildProcessors()); |
| 536 | REPORTER_ASSERT(reporter, fp->usesLocalCoords() == clone->usesLocalCoords()); |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 537 | // Draw with original and read back the results. |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 538 | test_draw_op(rtc.get(), std::move(fp), inputTexture); |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 539 | memset(readData1.get(), 0x0, sizeof(GrColor) * kRenderSize * kRenderSize); |
| 540 | rtc->readPixels(readInfo, readData1.get(), 0, 0, 0); |
| 541 | |
| 542 | // Draw with clone and read back the results. |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 543 | test_draw_op(rtc.get(), std::move(clone), inputTexture); |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 544 | memset(readData2.get(), 0x0, sizeof(GrColor) * kRenderSize * kRenderSize); |
| 545 | rtc->readPixels(readInfo, readData2.get(), 0, 0, 0); |
| 546 | |
| 547 | // Check that the results are the same. |
| 548 | bool passing = true; |
| 549 | for (int y = 0; y < kRenderSize && passing; ++y) { |
| 550 | for (int x = 0; x < kRenderSize && passing; ++x) { |
| 551 | int idx = y * kRenderSize + x; |
| 552 | if (readData1[idx] != readData2[idx]) { |
| 553 | ERRORF(reporter, |
| 554 | "Processor %s made clone produced different output. " |
| 555 | "Input color: 0x%08x, Original Output Color: 0x%08x, " |
| 556 | "Clone Output Color: 0x%08x..", |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 557 | name, input_texel_color(x, y), readData1[idx], readData2[idx]); |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 558 | passing = false; |
| 559 | } |
| 560 | } |
| 561 | } |
| 562 | } |
| 563 | } |
| 564 | } |
| 565 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 566 | #endif // GR_TEST_UTILS |
| 567 | #endif // SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
| 568 | #endif // SK_SUPPORT_GPU |