blob: 7d9349ba6df079e201d67d06bab89a68d8b03882 [file] [log] [blame]
Brian Salomonbc6b99d2017-01-11 10:32:34 -05001/*
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 Salomonc65aec92017-03-09 09:03:58 -050012#include "GrClip.h"
Brian Salomonbc6b99d2017-01-11 10:32:34 -050013#include "GrContext.h"
14#include "GrGpuResource.h"
Brian Salomon5d4cd9e2017-02-09 11:16:46 -050015#include "GrPipelineBuilder.h"
Brian Salomonbc6b99d2017-01-11 10:32:34 -050016#include "GrRenderTargetContext.h"
17#include "GrRenderTargetContextPriv.h"
18#include "GrResourceProvider.h"
19#include "glsl/GrGLSLFragmentProcessor.h"
20#include "glsl/GrGLSLFragmentShaderBuilder.h"
Brian Salomon5d4cd9e2017-02-09 11:16:46 -050021#include "ops/GrNonAAFillRectOp.h"
Brian Salomonbc6b99d2017-01-11 10:32:34 -050022#include "ops/GrTestMeshDrawOp.h"
23
24namespace {
25class TestOp : public GrTestMeshDrawOp {
26public:
27 DEFINE_OP_CLASS_ID
28 const char* name() const override { return "TestOp"; }
29
Brian Salomon649a3412017-03-09 13:50:43 -050030 static std::unique_ptr<GrMeshDrawOp> Make() {
31 return std::unique_ptr<GrMeshDrawOp>(new TestOp);
32 }
Brian Salomonbc6b99d2017-01-11 10:32:34 -050033
34private:
35 TestOp() : INHERITED(ClassID(), SkRect::MakeWH(100, 100), 0xFFFFFFFF) {}
36
37 void onPrepareDraws(Target* target) const override { return; }
38
39 typedef GrTestMeshDrawOp INHERITED;
40};
41
42/**
43 * FP used to test ref/IO counts on owned GrGpuResources. Can also be a parent FP to test counts
44 * of resources owned by child FPs.
45 */
46class TestFP : public GrFragmentProcessor {
47public:
48 struct Image {
49 Image(sk_sp<GrTexture> texture, GrIOType ioType) : fTexture(texture), fIOType(ioType) {}
50 sk_sp<GrTexture> fTexture;
51 GrIOType fIOType;
52 };
53 static sk_sp<GrFragmentProcessor> Make(sk_sp<GrFragmentProcessor> child) {
54 return sk_sp<GrFragmentProcessor>(new TestFP(std::move(child)));
55 }
Robert Phillips30f9bc62017-02-22 15:28:38 -050056 static sk_sp<GrFragmentProcessor> Make(GrContext* context,
57 const SkTArray<sk_sp<GrTextureProxy>>& proxies,
Brian Salomonbc6b99d2017-01-11 10:32:34 -050058 const SkTArray<sk_sp<GrBuffer>>& buffers,
59 const SkTArray<Image>& images) {
Robert Phillips30f9bc62017-02-22 15:28:38 -050060 return sk_sp<GrFragmentProcessor>(new TestFP(context, proxies, buffers, images));
Brian Salomonbc6b99d2017-01-11 10:32:34 -050061 }
62
63 const char* name() const override { return "test"; }
64
65 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder* b) const override {
66 // We don't really care about reusing these.
67 static int32_t gKey = 0;
68 b->add32(sk_atomic_inc(&gKey));
69 }
70
Brian Salomonbc6b99d2017-01-11 10:32:34 -050071private:
Robert Phillips30f9bc62017-02-22 15:28:38 -050072 TestFP(GrContext* context,
73 const SkTArray<sk_sp<GrTextureProxy>>& proxies,
74 const SkTArray<sk_sp<GrBuffer>>& buffers,
Brian Salomonbc6b99d2017-01-11 10:32:34 -050075 const SkTArray<Image>& images)
Brian Salomon587e08f2017-01-27 10:59:27 -050076 : INHERITED(kNone_OptimizationFlags), fSamplers(4), fBuffers(4), fImages(4) {
Robert Phillips30f9bc62017-02-22 15:28:38 -050077 for (const auto& proxy : proxies) {
Brian Osman32342f02017-03-04 08:12:46 -050078 this->addTextureSampler(&fSamplers.emplace_back(context->resourceProvider(), proxy));
Brian Salomonbc6b99d2017-01-11 10:32:34 -050079 }
80 for (const auto& buffer : buffers) {
81 this->addBufferAccess(&fBuffers.emplace_back(kRGBA_8888_GrPixelConfig, buffer.get()));
82 }
83 for (const Image& image : images) {
84 this->addImageStorageAccess(&fImages.emplace_back(
85 image.fTexture, image.fIOType, GrSLMemoryModel::kNone, GrSLRestrict::kNo));
86 }
87 }
88
Brian Salomon587e08f2017-01-27 10:59:27 -050089 TestFP(sk_sp<GrFragmentProcessor> child)
90 : INHERITED(kNone_OptimizationFlags), fSamplers(4), fBuffers(4), fImages(4) {
Brian Salomonbc6b99d2017-01-11 10:32:34 -050091 this->registerChildProcessor(std::move(child));
92 }
93
94 virtual GrGLSLFragmentProcessor* onCreateGLSLInstance() const override {
95 class TestGLSLFP : public GrGLSLFragmentProcessor {
96 public:
97 TestGLSLFP() {}
98 void emitCode(EmitArgs& args) override {
99 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
100 fragBuilder->codeAppendf("%s = %s;", args.fOutputColor, args.fInputColor);
101 }
102
103 private:
104 };
105 return new TestGLSLFP();
106 }
107
108 bool onIsEqual(const GrFragmentProcessor&) const override { return false; }
109
110 GrTAllocator<TextureSampler> fSamplers;
111 GrTAllocator<BufferAccess> fBuffers;
112 GrTAllocator<ImageStorageAccess> fImages;
Brian Salomon587e08f2017-01-27 10:59:27 -0500113 typedef GrFragmentProcessor INHERITED;
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500114};
115}
116
Brian Salomonf046e152017-01-11 15:24:47 -0500117template <typename T>
118inline void testingOnly_getIORefCnts(const T* resource, int* refCnt, int* readCnt, int* writeCnt) {
119 *refCnt = resource->fRefCnt;
120 *readCnt = resource->fPendingReads;
121 *writeCnt = resource->fPendingWrites;
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500122}
123
Robert Phillips2f493142017-03-02 18:18:38 -0500124void testingOnly_getIORefCnts(GrTextureProxy* proxy, int* refCnt, int* readCnt, int* writeCnt) {
Robert Phillips30f9bc62017-02-22 15:28:38 -0500125 *refCnt = proxy->getBackingRefCnt_TestOnly();
126 *readCnt = proxy->getPendingReadCnt_TestOnly();
127 *writeCnt = proxy->getPendingWriteCnt_TestOnly();
128}
129
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500130DEF_GPUTEST_FOR_ALL_CONTEXTS(ProcessorRefTest, reporter, ctxInfo) {
131 GrContext* context = ctxInfo.grContext();
132
133 GrTextureDesc desc;
134 desc.fConfig = kRGBA_8888_GrPixelConfig;
135 desc.fWidth = 10;
136 desc.fHeight = 10;
137
138 for (int parentCnt = 0; parentCnt < 2; parentCnt++) {
139 sk_sp<GrRenderTargetContext> renderTargetContext(context->makeRenderTargetContext(
140 SkBackingFit::kApprox, 1, 1, kRGBA_8888_GrPixelConfig, nullptr));
141 {
142 bool texelBufferSupport = context->caps()->shaderCaps()->texelBufferSupport();
143 bool imageLoadStoreSupport = context->caps()->shaderCaps()->imageLoadStoreSupport();
Brian Osman32342f02017-03-04 08:12:46 -0500144 sk_sp<GrTextureProxy> proxy1(GrSurfaceProxy::MakeDeferred(context->resourceProvider(),
Robert Phillips7928e762017-02-28 16:30:28 -0500145 *context->caps(), desc,
Robert Phillips30f9bc62017-02-22 15:28:38 -0500146 SkBackingFit::kExact,
147 SkBudgeted::kYes));
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500148 sk_sp<GrTexture> texture2(
149 context->resourceProvider()->createTexture(desc, SkBudgeted::kYes));
150 sk_sp<GrTexture> texture3(
151 context->resourceProvider()->createTexture(desc, SkBudgeted::kYes));
152 sk_sp<GrTexture> texture4(
153 context->resourceProvider()->createTexture(desc, SkBudgeted::kYes));
154 sk_sp<GrBuffer> buffer(texelBufferSupport
155 ? context->resourceProvider()->createBuffer(
156 1024, GrBufferType::kTexel_GrBufferType,
157 GrAccessPattern::kStatic_GrAccessPattern, 0)
158 : nullptr);
159 {
Robert Phillips30f9bc62017-02-22 15:28:38 -0500160 SkTArray<sk_sp<GrTextureProxy>> proxies;
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500161 SkTArray<sk_sp<GrBuffer>> buffers;
162 SkTArray<TestFP::Image> images;
Robert Phillips2f493142017-03-02 18:18:38 -0500163 proxies.push_back(proxy1);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500164 if (texelBufferSupport) {
165 buffers.push_back(buffer);
166 }
167 if (imageLoadStoreSupport) {
168 images.emplace_back(texture2, GrIOType::kRead_GrIOType);
169 images.emplace_back(texture3, GrIOType::kWrite_GrIOType);
170 images.emplace_back(texture4, GrIOType::kRW_GrIOType);
171 }
Brian Salomon649a3412017-03-09 13:50:43 -0500172 std::unique_ptr<GrMeshDrawOp> op(TestOp::Make());
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500173 GrPaint paint;
Robert Phillips30f9bc62017-02-22 15:28:38 -0500174 auto fp = TestFP::Make(context,
175 std::move(proxies), std::move(buffers), std::move(images));
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500176 for (int i = 0; i < parentCnt; ++i) {
177 fp = TestFP::Make(std::move(fp));
178 }
179 paint.addColorFragmentProcessor(std::move(fp));
Brian Salomon649a3412017-03-09 13:50:43 -0500180 renderTargetContext->priv().testingOnly_addMeshDrawOp(
181 std::move(paint), GrAAType::kNone, std::move(op));
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500182 }
183 int refCnt, readCnt, writeCnt;
184
Robert Phillips30f9bc62017-02-22 15:28:38 -0500185 testingOnly_getIORefCnts(proxy1.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500186 REPORTER_ASSERT(reporter, 1 == refCnt);
187 REPORTER_ASSERT(reporter, 1 == readCnt);
188 REPORTER_ASSERT(reporter, 0 == writeCnt);
189
190 if (texelBufferSupport) {
Brian Salomonf046e152017-01-11 15:24:47 -0500191 testingOnly_getIORefCnts(buffer.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500192 REPORTER_ASSERT(reporter, 1 == refCnt);
193 REPORTER_ASSERT(reporter, 1 == readCnt);
194 REPORTER_ASSERT(reporter, 0 == writeCnt);
195 }
196
197 if (imageLoadStoreSupport) {
Brian Salomonf046e152017-01-11 15:24:47 -0500198 testingOnly_getIORefCnts(texture2.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500199 REPORTER_ASSERT(reporter, 1 == refCnt);
200 REPORTER_ASSERT(reporter, 1 == readCnt);
201 REPORTER_ASSERT(reporter, 0 == writeCnt);
202
Brian Salomonf046e152017-01-11 15:24:47 -0500203 testingOnly_getIORefCnts(texture3.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500204 REPORTER_ASSERT(reporter, 1 == refCnt);
205 REPORTER_ASSERT(reporter, 0 == readCnt);
206 REPORTER_ASSERT(reporter, 1 == writeCnt);
207
Brian Salomonf046e152017-01-11 15:24:47 -0500208 testingOnly_getIORefCnts(texture4.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500209 REPORTER_ASSERT(reporter, 1 == refCnt);
210 REPORTER_ASSERT(reporter, 1 == readCnt);
211 REPORTER_ASSERT(reporter, 1 == writeCnt);
212 }
213
214 context->flush();
215
Robert Phillips30f9bc62017-02-22 15:28:38 -0500216 testingOnly_getIORefCnts(proxy1.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500217 REPORTER_ASSERT(reporter, 1 == refCnt);
218 REPORTER_ASSERT(reporter, 0 == readCnt);
219 REPORTER_ASSERT(reporter, 0 == writeCnt);
220
221 if (texelBufferSupport) {
Brian Salomonf046e152017-01-11 15:24:47 -0500222 testingOnly_getIORefCnts(buffer.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500223 REPORTER_ASSERT(reporter, 1 == refCnt);
224 REPORTER_ASSERT(reporter, 0 == readCnt);
225 REPORTER_ASSERT(reporter, 0 == writeCnt);
226 }
227
228 if (texelBufferSupport) {
Brian Salomonf046e152017-01-11 15:24:47 -0500229 testingOnly_getIORefCnts(texture2.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500230 REPORTER_ASSERT(reporter, 1 == refCnt);
231 REPORTER_ASSERT(reporter, 0 == readCnt);
232 REPORTER_ASSERT(reporter, 0 == writeCnt);
233
Brian Salomonf046e152017-01-11 15:24:47 -0500234 testingOnly_getIORefCnts(texture3.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500235 REPORTER_ASSERT(reporter, 1 == refCnt);
236 REPORTER_ASSERT(reporter, 0 == readCnt);
237 REPORTER_ASSERT(reporter, 0 == writeCnt);
238
Brian Salomonf046e152017-01-11 15:24:47 -0500239 testingOnly_getIORefCnts(texture4.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500240 REPORTER_ASSERT(reporter, 1 == refCnt);
241 REPORTER_ASSERT(reporter, 0 == readCnt);
242 REPORTER_ASSERT(reporter, 0 == writeCnt);
243 }
244 }
245 }
246}
Brian Salomon587e08f2017-01-27 10:59:27 -0500247
248// This test uses the random GrFragmentProcessor test factory, which relies on static initializers.
249#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
250
251static GrColor texel_color(int i, int j) {
252 SkASSERT((unsigned)i < 256 && (unsigned)j < 256);
253 GrColor color = GrColorPackRGBA(j, (uint8_t)(i + j), (uint8_t)(2 * j - i), i);
254 return GrPremulColor(color);
255}
256
257static GrColor4f texel_color4f(int i, int j) { return GrColor4f::FromGrColor(texel_color(i, j)); }
258
Robert Phillips30f9bc62017-02-22 15:28:38 -0500259void test_draw_op(GrContext* context, GrRenderTargetContext* rtc, sk_sp<GrFragmentProcessor> fp,
260 sk_sp<GrTextureProxy> inputDataProxy) {
Brian Salomon5d4cd9e2017-02-09 11:16:46 -0500261 GrPaint paint;
Robert Phillips30f9bc62017-02-22 15:28:38 -0500262 paint.addColorTextureProcessor(context, std::move(inputDataProxy), nullptr, SkMatrix::I());
Brian Salomon5d4cd9e2017-02-09 11:16:46 -0500263 paint.addColorFragmentProcessor(std::move(fp));
264 paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
265 GrPipelineBuilder pb(std::move(paint), GrAAType::kNone);
266 auto op =
267 GrNonAAFillRectOp::Make(GrColor_WHITE, SkMatrix::I(),
268 SkRect::MakeWH(rtc->width(), rtc->height()), nullptr, nullptr);
Brian Salomon649a3412017-03-09 13:50:43 -0500269 rtc->addMeshDrawOp(pb, GrNoClip(), std::move(op));
Brian Salomon5d4cd9e2017-02-09 11:16:46 -0500270}
271
Hal Canary6f6961e2017-01-31 13:50:44 -0500272#if GR_TEST_UTILS
Brian Salomon5d4cd9e2017-02-09 11:16:46 -0500273DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ProcessorOptimizationValidationTest, reporter, ctxInfo) {
Brian Salomon587e08f2017-01-27 10:59:27 -0500274 GrContext* context = ctxInfo.grContext();
275 using FPFactory = GrProcessorTestFactory<GrFragmentProcessor>;
276 SkRandom random;
277 sk_sp<GrRenderTargetContext> rtc = context->makeRenderTargetContext(
278 SkBackingFit::kExact, 256, 256, kRGBA_8888_GrPixelConfig, nullptr);
279 GrSurfaceDesc desc;
280 desc.fWidth = 256;
281 desc.fHeight = 256;
282 desc.fFlags = kRenderTarget_GrSurfaceFlag;
283 desc.fConfig = kRGBA_8888_GrPixelConfig;
Brian Salomond1a8bdf2017-02-10 12:39:26 -0500284
285 // Put premul data into the RGBA texture that the test FPs can optionally use.
286 std::unique_ptr<GrColor[]> rgbaData(new GrColor[256 * 256]);
287 for (int y = 0; y < 256; ++y) {
288 for (int x = 0; x < 256; ++x) {
289 rgbaData.get()[256 * y + x] =
290 texel_color(random.nextULessThan(256), random.nextULessThan(256));
291 }
292 }
Brian Osman32342f02017-03-04 08:12:46 -0500293 sk_sp<GrTexture> tex0(context->resourceProvider()->createTexture(
Brian Salomond1a8bdf2017-02-10 12:39:26 -0500294 desc, SkBudgeted::kYes, rgbaData.get(), 256 * sizeof(GrColor)));
295
296 // Put random values into the alpha texture that the test FPs can optionally use.
Brian Salomon587e08f2017-01-27 10:59:27 -0500297 desc.fConfig = kAlpha_8_GrPixelConfig;
Brian Salomond1a8bdf2017-02-10 12:39:26 -0500298 std::unique_ptr<uint8_t[]> alphaData(new uint8_t[256 * 256]);
299 for (int y = 0; y < 256; ++y) {
300 for (int x = 0; x < 256; ++x) {
301 alphaData.get()[256 * y + x] = random.nextULessThan(256);
302 }
303 }
Brian Osman32342f02017-03-04 08:12:46 -0500304 sk_sp<GrTexture> tex1(context->resourceProvider()->createTexture(desc, SkBudgeted::kYes,
305 alphaData.get(), 256));
Brian Salomon587e08f2017-01-27 10:59:27 -0500306 GrTexture* textures[] = {tex0.get(), tex1.get()};
307 GrProcessorTestData testData(&random, context, rtc.get(), textures);
308
Brian Salomond1a8bdf2017-02-10 12:39:26 -0500309 // Use a different array of premul colors for the output of the fragment processor that preceeds
310 // the fragment processor under test.
Brian Salomon587e08f2017-01-27 10:59:27 -0500311 for (int y = 0; y < 256; ++y) {
312 for (int x = 0; x < 256; ++x) {
Brian Salomond1a8bdf2017-02-10 12:39:26 -0500313 rgbaData.get()[256 * y + x] = texel_color(x, y);
Brian Salomon587e08f2017-01-27 10:59:27 -0500314 }
315 }
316 desc.fConfig = kRGBA_8888_GrPixelConfig;
Robert Phillips30f9bc62017-02-22 15:28:38 -0500317
Robert Phillips2f493142017-03-02 18:18:38 -0500318 sk_sp<GrTextureProxy> dataProxy = GrSurfaceProxy::MakeDeferred(*context->caps(),
Brian Osman32342f02017-03-04 08:12:46 -0500319 context->resourceProvider(),
Robert Phillips30f9bc62017-02-22 15:28:38 -0500320 desc, SkBudgeted::kYes,
321 rgbaData.get(),
322 256 * sizeof(GrColor));
Brian Salomon587e08f2017-01-27 10:59:27 -0500323
324 // Because processors factories configure themselves in random ways, this is not exhaustive.
325 for (int i = 0; i < FPFactory::Count(); ++i) {
326 int timesToInvokeFactory = 5;
327 // Increase the number of attempts if the FP has child FPs since optimizations likely depend
328 // on child optimizations being present.
329 sk_sp<GrFragmentProcessor> fp = FPFactory::MakeIdx(i, &testData);
330 for (int j = 0; j < fp->numChildProcessors(); ++j) {
331 // This value made a reasonable trade off between time and coverage when this test was
332 // written.
333 timesToInvokeFactory *= FPFactory::Count() / 2;
334 }
335 for (int j = 0; j < timesToInvokeFactory; ++j) {
336 fp = FPFactory::MakeIdx(i, &testData);
337 if (!fp->hasConstantOutputForConstantInput() && !fp->preservesOpaqueInput() &&
Brian Salomonf3b995b2017-02-15 10:22:23 -0500338 !fp->compatibleWithCoverageAsAlpha()) {
Brian Salomon587e08f2017-01-27 10:59:27 -0500339 continue;
340 }
Robert Phillips2f493142017-03-02 18:18:38 -0500341 test_draw_op(context, rtc.get(), fp, dataProxy);
Brian Salomond1a8bdf2017-02-10 12:39:26 -0500342 memset(rgbaData.get(), 0x0, sizeof(GrColor) * 256 * 256);
Brian Salomon587e08f2017-01-27 10:59:27 -0500343 rtc->readPixels(
344 SkImageInfo::Make(256, 256, kRGBA_8888_SkColorType, kPremul_SkAlphaType),
Brian Salomond1a8bdf2017-02-10 12:39:26 -0500345 rgbaData.get(), 0, 0, 0);
Brian Salomon587e08f2017-01-27 10:59:27 -0500346 bool passing = true;
347 if (0) { // Useful to see what FPs are being tested.
348 SkString children;
349 for (int c = 0; c < fp->numChildProcessors(); ++c) {
350 if (!c) {
351 children.append("(");
352 }
353 children.append(fp->childProcessor(c).name());
354 children.append(c == fp->numChildProcessors() - 1 ? ")" : ", ");
355 }
356 SkDebugf("%s %s\n", fp->name(), children.c_str());
357 }
358 for (int y = 0; y < 256 && passing; ++y) {
359 for (int x = 0; x < 256 && passing; ++x) {
360 GrColor input = texel_color(x, y);
Brian Salomond1a8bdf2017-02-10 12:39:26 -0500361 GrColor output = rgbaData.get()[y * 256 + x];
Brian Salomonf3b995b2017-02-15 10:22:23 -0500362 if (fp->compatibleWithCoverageAsAlpha()) {
Brian Salomon587e08f2017-01-27 10:59:27 -0500363 // A modulating processor is allowed to modulate either the input color or
364 // just the input alpha.
365 bool legalColorModulation =
366 GrColorUnpackA(output) <= GrColorUnpackA(input) &&
367 GrColorUnpackR(output) <= GrColorUnpackR(input) &&
368 GrColorUnpackG(output) <= GrColorUnpackG(input) &&
369 GrColorUnpackB(output) <= GrColorUnpackB(input);
370 bool legalAlphaModulation =
371 GrColorUnpackA(output) <= GrColorUnpackA(input) &&
372 GrColorUnpackR(output) <= GrColorUnpackA(input) &&
373 GrColorUnpackG(output) <= GrColorUnpackA(input) &&
374 GrColorUnpackB(output) <= GrColorUnpackA(input);
375 if (!legalColorModulation && !legalAlphaModulation) {
376 ERRORF(reporter,
377 "\"Modulating\" processor %s made color/alpha value larger. "
378 "Input: 0x%0x8, Output: 0x%08x.",
379 fp->name(), input, output);
380 passing = false;
381 }
382 }
383 GrColor4f input4f = texel_color4f(x, y);
384 GrColor4f output4f = GrColor4f::FromGrColor(output);
385 GrColor4f expected4f;
386 if (fp->hasConstantOutputForConstantInput(input4f, &expected4f)) {
387 float rDiff = fabsf(output4f.fRGBA[0] - expected4f.fRGBA[0]);
388 float gDiff = fabsf(output4f.fRGBA[1] - expected4f.fRGBA[1]);
389 float bDiff = fabsf(output4f.fRGBA[2] - expected4f.fRGBA[2]);
390 float aDiff = fabsf(output4f.fRGBA[3] - expected4f.fRGBA[3]);
Brian Salomon5d4cd9e2017-02-09 11:16:46 -0500391 static constexpr float kTol = 4 / 255.f;
Brian Salomon587e08f2017-01-27 10:59:27 -0500392 if (rDiff > kTol || gDiff > kTol || bDiff > kTol || aDiff > kTol) {
393 ERRORF(reporter,
394 "Processor %s claimed output for const input doesn't match "
Brian Salomon5d4cd9e2017-02-09 11:16:46 -0500395 "actual output. Error: %f, Tolerance: %f, input: (%f, %f, %f, "
396 "%f), actual: (%f, %f, %f, %f), expected(%f, %f, %f, %f)",
397 fp->name(), SkTMax(rDiff, SkTMax(gDiff, SkTMax(bDiff, aDiff))),
398 kTol, input4f.fRGBA[0], input4f.fRGBA[1], input4f.fRGBA[2],
399 input4f.fRGBA[3], output4f.fRGBA[0], output4f.fRGBA[1],
400 output4f.fRGBA[2], output4f.fRGBA[3], expected4f.fRGBA[0],
401 expected4f.fRGBA[1], expected4f.fRGBA[2], expected4f.fRGBA[3]);
Brian Salomon587e08f2017-01-27 10:59:27 -0500402 passing = false;
403 }
404 }
405 if (GrColorIsOpaque(input) && fp->preservesOpaqueInput() &&
406 !GrColorIsOpaque(output)) {
407 ERRORF(reporter,
408 "Processor %s claimed opaqueness is preserved but it is not. Input: "
409 "0x%0x8, Output: 0x%08x.",
410 fp->name(), input, output);
411 passing = false;
412 }
413 }
414 }
415 }
416 }
417}
Hal Canary6f6961e2017-01-31 13:50:44 -0500418#endif // GR_TEST_UTILS
419#endif // SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
420#endif // SK_SUPPORT_GPU