blob: 03646e1d4446b73ecfedafb8b0a8f376882e00e9 [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
30 static std::unique_ptr<GrDrawOp> Make() { return std::unique_ptr<GrDrawOp>(new TestOp); }
31
32private:
33 TestOp() : INHERITED(ClassID(), SkRect::MakeWH(100, 100), 0xFFFFFFFF) {}
34
35 void onPrepareDraws(Target* target) const override { return; }
36
37 typedef GrTestMeshDrawOp INHERITED;
38};
39
40/**
41 * FP used to test ref/IO counts on owned GrGpuResources. Can also be a parent FP to test counts
42 * of resources owned by child FPs.
43 */
44class TestFP : public GrFragmentProcessor {
45public:
46 struct Image {
47 Image(sk_sp<GrTexture> texture, GrIOType ioType) : fTexture(texture), fIOType(ioType) {}
48 sk_sp<GrTexture> fTexture;
49 GrIOType fIOType;
50 };
51 static sk_sp<GrFragmentProcessor> Make(sk_sp<GrFragmentProcessor> child) {
52 return sk_sp<GrFragmentProcessor>(new TestFP(std::move(child)));
53 }
Robert Phillips30f9bc62017-02-22 15:28:38 -050054 static sk_sp<GrFragmentProcessor> Make(GrContext* context,
55 const SkTArray<sk_sp<GrTextureProxy>>& proxies,
Brian Salomonbc6b99d2017-01-11 10:32:34 -050056 const SkTArray<sk_sp<GrBuffer>>& buffers,
57 const SkTArray<Image>& images) {
Robert Phillips30f9bc62017-02-22 15:28:38 -050058 return sk_sp<GrFragmentProcessor>(new TestFP(context, proxies, buffers, images));
Brian Salomonbc6b99d2017-01-11 10:32:34 -050059 }
60
61 const char* name() const override { return "test"; }
62
63 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder* b) const override {
64 // We don't really care about reusing these.
65 static int32_t gKey = 0;
66 b->add32(sk_atomic_inc(&gKey));
67 }
68
Brian Salomonbc6b99d2017-01-11 10:32:34 -050069private:
Robert Phillips30f9bc62017-02-22 15:28:38 -050070 TestFP(GrContext* context,
71 const SkTArray<sk_sp<GrTextureProxy>>& proxies,
72 const SkTArray<sk_sp<GrBuffer>>& buffers,
Brian Salomonbc6b99d2017-01-11 10:32:34 -050073 const SkTArray<Image>& images)
Brian Salomon587e08f2017-01-27 10:59:27 -050074 : INHERITED(kNone_OptimizationFlags), fSamplers(4), fBuffers(4), fImages(4) {
Robert Phillips30f9bc62017-02-22 15:28:38 -050075 for (const auto& proxy : proxies) {
Brian Osman32342f02017-03-04 08:12:46 -050076 this->addTextureSampler(&fSamplers.emplace_back(context->resourceProvider(), proxy));
Brian Salomonbc6b99d2017-01-11 10:32:34 -050077 }
78 for (const auto& buffer : buffers) {
79 this->addBufferAccess(&fBuffers.emplace_back(kRGBA_8888_GrPixelConfig, buffer.get()));
80 }
81 for (const Image& image : images) {
82 this->addImageStorageAccess(&fImages.emplace_back(
83 image.fTexture, image.fIOType, GrSLMemoryModel::kNone, GrSLRestrict::kNo));
84 }
85 }
86
Brian Salomon587e08f2017-01-27 10:59:27 -050087 TestFP(sk_sp<GrFragmentProcessor> child)
88 : INHERITED(kNone_OptimizationFlags), fSamplers(4), fBuffers(4), fImages(4) {
Brian Salomonbc6b99d2017-01-11 10:32:34 -050089 this->registerChildProcessor(std::move(child));
90 }
91
92 virtual GrGLSLFragmentProcessor* onCreateGLSLInstance() const override {
93 class TestGLSLFP : public GrGLSLFragmentProcessor {
94 public:
95 TestGLSLFP() {}
96 void emitCode(EmitArgs& args) override {
97 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
98 fragBuilder->codeAppendf("%s = %s;", args.fOutputColor, args.fInputColor);
99 }
100
101 private:
102 };
103 return new TestGLSLFP();
104 }
105
106 bool onIsEqual(const GrFragmentProcessor&) const override { return false; }
107
108 GrTAllocator<TextureSampler> fSamplers;
109 GrTAllocator<BufferAccess> fBuffers;
110 GrTAllocator<ImageStorageAccess> fImages;
Brian Salomon587e08f2017-01-27 10:59:27 -0500111 typedef GrFragmentProcessor INHERITED;
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500112};
113}
114
Brian Salomonf046e152017-01-11 15:24:47 -0500115template <typename T>
116inline void testingOnly_getIORefCnts(const T* resource, int* refCnt, int* readCnt, int* writeCnt) {
117 *refCnt = resource->fRefCnt;
118 *readCnt = resource->fPendingReads;
119 *writeCnt = resource->fPendingWrites;
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500120}
121
Robert Phillips2f493142017-03-02 18:18:38 -0500122void testingOnly_getIORefCnts(GrTextureProxy* proxy, int* refCnt, int* readCnt, int* writeCnt) {
Robert Phillips30f9bc62017-02-22 15:28:38 -0500123 *refCnt = proxy->getBackingRefCnt_TestOnly();
124 *readCnt = proxy->getPendingReadCnt_TestOnly();
125 *writeCnt = proxy->getPendingWriteCnt_TestOnly();
126}
127
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500128DEF_GPUTEST_FOR_ALL_CONTEXTS(ProcessorRefTest, reporter, ctxInfo) {
129 GrContext* context = ctxInfo.grContext();
130
131 GrTextureDesc desc;
132 desc.fConfig = kRGBA_8888_GrPixelConfig;
133 desc.fWidth = 10;
134 desc.fHeight = 10;
135
136 for (int parentCnt = 0; parentCnt < 2; parentCnt++) {
137 sk_sp<GrRenderTargetContext> renderTargetContext(context->makeRenderTargetContext(
138 SkBackingFit::kApprox, 1, 1, kRGBA_8888_GrPixelConfig, nullptr));
139 {
140 bool texelBufferSupport = context->caps()->shaderCaps()->texelBufferSupport();
141 bool imageLoadStoreSupport = context->caps()->shaderCaps()->imageLoadStoreSupport();
Brian Osman32342f02017-03-04 08:12:46 -0500142 sk_sp<GrTextureProxy> proxy1(GrSurfaceProxy::MakeDeferred(context->resourceProvider(),
Robert Phillips7928e762017-02-28 16:30:28 -0500143 *context->caps(), desc,
Robert Phillips30f9bc62017-02-22 15:28:38 -0500144 SkBackingFit::kExact,
145 SkBudgeted::kYes));
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500146 sk_sp<GrTexture> texture2(
147 context->resourceProvider()->createTexture(desc, SkBudgeted::kYes));
148 sk_sp<GrTexture> texture3(
149 context->resourceProvider()->createTexture(desc, SkBudgeted::kYes));
150 sk_sp<GrTexture> texture4(
151 context->resourceProvider()->createTexture(desc, SkBudgeted::kYes));
152 sk_sp<GrBuffer> buffer(texelBufferSupport
153 ? context->resourceProvider()->createBuffer(
154 1024, GrBufferType::kTexel_GrBufferType,
155 GrAccessPattern::kStatic_GrAccessPattern, 0)
156 : nullptr);
157 {
Robert Phillips30f9bc62017-02-22 15:28:38 -0500158 SkTArray<sk_sp<GrTextureProxy>> proxies;
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500159 SkTArray<sk_sp<GrBuffer>> buffers;
160 SkTArray<TestFP::Image> images;
Robert Phillips2f493142017-03-02 18:18:38 -0500161 proxies.push_back(proxy1);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500162 if (texelBufferSupport) {
163 buffers.push_back(buffer);
164 }
165 if (imageLoadStoreSupport) {
166 images.emplace_back(texture2, GrIOType::kRead_GrIOType);
167 images.emplace_back(texture3, GrIOType::kWrite_GrIOType);
168 images.emplace_back(texture4, GrIOType::kRW_GrIOType);
169 }
170 std::unique_ptr<GrDrawOp> op(TestOp::Make());
171 GrPaint paint;
Robert Phillips30f9bc62017-02-22 15:28:38 -0500172 auto fp = TestFP::Make(context,
173 std::move(proxies), std::move(buffers), std::move(images));
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500174 for (int i = 0; i < parentCnt; ++i) {
175 fp = TestFP::Make(std::move(fp));
176 }
177 paint.addColorFragmentProcessor(std::move(fp));
Brian Salomon82f44312017-01-11 13:42:54 -0500178 renderTargetContext->priv().testingOnly_addDrawOp(std::move(paint), GrAAType::kNone,
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500179 std::move(op));
180 }
181 int refCnt, readCnt, writeCnt;
182
Robert Phillips30f9bc62017-02-22 15:28:38 -0500183 testingOnly_getIORefCnts(proxy1.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500184 REPORTER_ASSERT(reporter, 1 == refCnt);
185 REPORTER_ASSERT(reporter, 1 == readCnt);
186 REPORTER_ASSERT(reporter, 0 == writeCnt);
187
188 if (texelBufferSupport) {
Brian Salomonf046e152017-01-11 15:24:47 -0500189 testingOnly_getIORefCnts(buffer.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500190 REPORTER_ASSERT(reporter, 1 == refCnt);
191 REPORTER_ASSERT(reporter, 1 == readCnt);
192 REPORTER_ASSERT(reporter, 0 == writeCnt);
193 }
194
195 if (imageLoadStoreSupport) {
Brian Salomonf046e152017-01-11 15:24:47 -0500196 testingOnly_getIORefCnts(texture2.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500197 REPORTER_ASSERT(reporter, 1 == refCnt);
198 REPORTER_ASSERT(reporter, 1 == readCnt);
199 REPORTER_ASSERT(reporter, 0 == writeCnt);
200
Brian Salomonf046e152017-01-11 15:24:47 -0500201 testingOnly_getIORefCnts(texture3.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500202 REPORTER_ASSERT(reporter, 1 == refCnt);
203 REPORTER_ASSERT(reporter, 0 == readCnt);
204 REPORTER_ASSERT(reporter, 1 == writeCnt);
205
Brian Salomonf046e152017-01-11 15:24:47 -0500206 testingOnly_getIORefCnts(texture4.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500207 REPORTER_ASSERT(reporter, 1 == refCnt);
208 REPORTER_ASSERT(reporter, 1 == readCnt);
209 REPORTER_ASSERT(reporter, 1 == writeCnt);
210 }
211
212 context->flush();
213
Robert Phillips30f9bc62017-02-22 15:28:38 -0500214 testingOnly_getIORefCnts(proxy1.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500215 REPORTER_ASSERT(reporter, 1 == refCnt);
216 REPORTER_ASSERT(reporter, 0 == readCnt);
217 REPORTER_ASSERT(reporter, 0 == writeCnt);
218
219 if (texelBufferSupport) {
Brian Salomonf046e152017-01-11 15:24:47 -0500220 testingOnly_getIORefCnts(buffer.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500221 REPORTER_ASSERT(reporter, 1 == refCnt);
222 REPORTER_ASSERT(reporter, 0 == readCnt);
223 REPORTER_ASSERT(reporter, 0 == writeCnt);
224 }
225
226 if (texelBufferSupport) {
Brian Salomonf046e152017-01-11 15:24:47 -0500227 testingOnly_getIORefCnts(texture2.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500228 REPORTER_ASSERT(reporter, 1 == refCnt);
229 REPORTER_ASSERT(reporter, 0 == readCnt);
230 REPORTER_ASSERT(reporter, 0 == writeCnt);
231
Brian Salomonf046e152017-01-11 15:24:47 -0500232 testingOnly_getIORefCnts(texture3.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500233 REPORTER_ASSERT(reporter, 1 == refCnt);
234 REPORTER_ASSERT(reporter, 0 == readCnt);
235 REPORTER_ASSERT(reporter, 0 == writeCnt);
236
Brian Salomonf046e152017-01-11 15:24:47 -0500237 testingOnly_getIORefCnts(texture4.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500238 REPORTER_ASSERT(reporter, 1 == refCnt);
239 REPORTER_ASSERT(reporter, 0 == readCnt);
240 REPORTER_ASSERT(reporter, 0 == writeCnt);
241 }
242 }
243 }
244}
Brian Salomon587e08f2017-01-27 10:59:27 -0500245
246// This test uses the random GrFragmentProcessor test factory, which relies on static initializers.
247#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
248
249static GrColor texel_color(int i, int j) {
250 SkASSERT((unsigned)i < 256 && (unsigned)j < 256);
251 GrColor color = GrColorPackRGBA(j, (uint8_t)(i + j), (uint8_t)(2 * j - i), i);
252 return GrPremulColor(color);
253}
254
255static GrColor4f texel_color4f(int i, int j) { return GrColor4f::FromGrColor(texel_color(i, j)); }
256
Robert Phillips30f9bc62017-02-22 15:28:38 -0500257void test_draw_op(GrContext* context, GrRenderTargetContext* rtc, sk_sp<GrFragmentProcessor> fp,
258 sk_sp<GrTextureProxy> inputDataProxy) {
Brian Salomon5d4cd9e2017-02-09 11:16:46 -0500259 GrPaint paint;
Robert Phillips30f9bc62017-02-22 15:28:38 -0500260 paint.addColorTextureProcessor(context, std::move(inputDataProxy), nullptr, SkMatrix::I());
Brian Salomon5d4cd9e2017-02-09 11:16:46 -0500261 paint.addColorFragmentProcessor(std::move(fp));
262 paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
263 GrPipelineBuilder pb(std::move(paint), GrAAType::kNone);
264 auto op =
265 GrNonAAFillRectOp::Make(GrColor_WHITE, SkMatrix::I(),
266 SkRect::MakeWH(rtc->width(), rtc->height()), nullptr, nullptr);
267 rtc->addDrawOp(pb, GrNoClip(), std::move(op));
268}
269
Hal Canary6f6961e2017-01-31 13:50:44 -0500270#if GR_TEST_UTILS
Brian Salomon5d4cd9e2017-02-09 11:16:46 -0500271DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ProcessorOptimizationValidationTest, reporter, ctxInfo) {
Brian Salomon587e08f2017-01-27 10:59:27 -0500272 GrContext* context = ctxInfo.grContext();
273 using FPFactory = GrProcessorTestFactory<GrFragmentProcessor>;
274 SkRandom random;
275 sk_sp<GrRenderTargetContext> rtc = context->makeRenderTargetContext(
276 SkBackingFit::kExact, 256, 256, kRGBA_8888_GrPixelConfig, nullptr);
277 GrSurfaceDesc desc;
278 desc.fWidth = 256;
279 desc.fHeight = 256;
280 desc.fFlags = kRenderTarget_GrSurfaceFlag;
281 desc.fConfig = kRGBA_8888_GrPixelConfig;
Brian Salomond1a8bdf2017-02-10 12:39:26 -0500282
283 // Put premul data into the RGBA texture that the test FPs can optionally use.
284 std::unique_ptr<GrColor[]> rgbaData(new GrColor[256 * 256]);
285 for (int y = 0; y < 256; ++y) {
286 for (int x = 0; x < 256; ++x) {
287 rgbaData.get()[256 * y + x] =
288 texel_color(random.nextULessThan(256), random.nextULessThan(256));
289 }
290 }
Brian Osman32342f02017-03-04 08:12:46 -0500291 sk_sp<GrTexture> tex0(context->resourceProvider()->createTexture(
Brian Salomond1a8bdf2017-02-10 12:39:26 -0500292 desc, SkBudgeted::kYes, rgbaData.get(), 256 * sizeof(GrColor)));
293
294 // Put random values into the alpha texture that the test FPs can optionally use.
Brian Salomon587e08f2017-01-27 10:59:27 -0500295 desc.fConfig = kAlpha_8_GrPixelConfig;
Brian Salomond1a8bdf2017-02-10 12:39:26 -0500296 std::unique_ptr<uint8_t[]> alphaData(new uint8_t[256 * 256]);
297 for (int y = 0; y < 256; ++y) {
298 for (int x = 0; x < 256; ++x) {
299 alphaData.get()[256 * y + x] = random.nextULessThan(256);
300 }
301 }
Brian Osman32342f02017-03-04 08:12:46 -0500302 sk_sp<GrTexture> tex1(context->resourceProvider()->createTexture(desc, SkBudgeted::kYes,
303 alphaData.get(), 256));
Brian Salomon587e08f2017-01-27 10:59:27 -0500304 GrTexture* textures[] = {tex0.get(), tex1.get()};
305 GrProcessorTestData testData(&random, context, rtc.get(), textures);
306
Brian Salomond1a8bdf2017-02-10 12:39:26 -0500307 // Use a different array of premul colors for the output of the fragment processor that preceeds
308 // the fragment processor under test.
Brian Salomon587e08f2017-01-27 10:59:27 -0500309 for (int y = 0; y < 256; ++y) {
310 for (int x = 0; x < 256; ++x) {
Brian Salomond1a8bdf2017-02-10 12:39:26 -0500311 rgbaData.get()[256 * y + x] = texel_color(x, y);
Brian Salomon587e08f2017-01-27 10:59:27 -0500312 }
313 }
314 desc.fConfig = kRGBA_8888_GrPixelConfig;
Robert Phillips30f9bc62017-02-22 15:28:38 -0500315
Robert Phillips2f493142017-03-02 18:18:38 -0500316 sk_sp<GrTextureProxy> dataProxy = GrSurfaceProxy::MakeDeferred(*context->caps(),
Brian Osman32342f02017-03-04 08:12:46 -0500317 context->resourceProvider(),
Robert Phillips30f9bc62017-02-22 15:28:38 -0500318 desc, SkBudgeted::kYes,
319 rgbaData.get(),
320 256 * sizeof(GrColor));
Brian Salomon587e08f2017-01-27 10:59:27 -0500321
322 // Because processors factories configure themselves in random ways, this is not exhaustive.
323 for (int i = 0; i < FPFactory::Count(); ++i) {
324 int timesToInvokeFactory = 5;
325 // Increase the number of attempts if the FP has child FPs since optimizations likely depend
326 // on child optimizations being present.
327 sk_sp<GrFragmentProcessor> fp = FPFactory::MakeIdx(i, &testData);
328 for (int j = 0; j < fp->numChildProcessors(); ++j) {
329 // This value made a reasonable trade off between time and coverage when this test was
330 // written.
331 timesToInvokeFactory *= FPFactory::Count() / 2;
332 }
333 for (int j = 0; j < timesToInvokeFactory; ++j) {
334 fp = FPFactory::MakeIdx(i, &testData);
335 if (!fp->hasConstantOutputForConstantInput() && !fp->preservesOpaqueInput() &&
Brian Salomonf3b995b2017-02-15 10:22:23 -0500336 !fp->compatibleWithCoverageAsAlpha()) {
Brian Salomon587e08f2017-01-27 10:59:27 -0500337 continue;
338 }
Robert Phillips2f493142017-03-02 18:18:38 -0500339 test_draw_op(context, rtc.get(), fp, dataProxy);
Brian Salomond1a8bdf2017-02-10 12:39:26 -0500340 memset(rgbaData.get(), 0x0, sizeof(GrColor) * 256 * 256);
Brian Salomon587e08f2017-01-27 10:59:27 -0500341 rtc->readPixels(
342 SkImageInfo::Make(256, 256, kRGBA_8888_SkColorType, kPremul_SkAlphaType),
Brian Salomond1a8bdf2017-02-10 12:39:26 -0500343 rgbaData.get(), 0, 0, 0);
Brian Salomon587e08f2017-01-27 10:59:27 -0500344 bool passing = true;
345 if (0) { // Useful to see what FPs are being tested.
346 SkString children;
347 for (int c = 0; c < fp->numChildProcessors(); ++c) {
348 if (!c) {
349 children.append("(");
350 }
351 children.append(fp->childProcessor(c).name());
352 children.append(c == fp->numChildProcessors() - 1 ? ")" : ", ");
353 }
354 SkDebugf("%s %s\n", fp->name(), children.c_str());
355 }
356 for (int y = 0; y < 256 && passing; ++y) {
357 for (int x = 0; x < 256 && passing; ++x) {
358 GrColor input = texel_color(x, y);
Brian Salomond1a8bdf2017-02-10 12:39:26 -0500359 GrColor output = rgbaData.get()[y * 256 + x];
Brian Salomonf3b995b2017-02-15 10:22:23 -0500360 if (fp->compatibleWithCoverageAsAlpha()) {
Brian Salomon587e08f2017-01-27 10:59:27 -0500361 // A modulating processor is allowed to modulate either the input color or
362 // just the input alpha.
363 bool legalColorModulation =
364 GrColorUnpackA(output) <= GrColorUnpackA(input) &&
365 GrColorUnpackR(output) <= GrColorUnpackR(input) &&
366 GrColorUnpackG(output) <= GrColorUnpackG(input) &&
367 GrColorUnpackB(output) <= GrColorUnpackB(input);
368 bool legalAlphaModulation =
369 GrColorUnpackA(output) <= GrColorUnpackA(input) &&
370 GrColorUnpackR(output) <= GrColorUnpackA(input) &&
371 GrColorUnpackG(output) <= GrColorUnpackA(input) &&
372 GrColorUnpackB(output) <= GrColorUnpackA(input);
373 if (!legalColorModulation && !legalAlphaModulation) {
374 ERRORF(reporter,
375 "\"Modulating\" processor %s made color/alpha value larger. "
376 "Input: 0x%0x8, Output: 0x%08x.",
377 fp->name(), input, output);
378 passing = false;
379 }
380 }
381 GrColor4f input4f = texel_color4f(x, y);
382 GrColor4f output4f = GrColor4f::FromGrColor(output);
383 GrColor4f expected4f;
384 if (fp->hasConstantOutputForConstantInput(input4f, &expected4f)) {
385 float rDiff = fabsf(output4f.fRGBA[0] - expected4f.fRGBA[0]);
386 float gDiff = fabsf(output4f.fRGBA[1] - expected4f.fRGBA[1]);
387 float bDiff = fabsf(output4f.fRGBA[2] - expected4f.fRGBA[2]);
388 float aDiff = fabsf(output4f.fRGBA[3] - expected4f.fRGBA[3]);
Brian Salomon5d4cd9e2017-02-09 11:16:46 -0500389 static constexpr float kTol = 4 / 255.f;
Brian Salomon587e08f2017-01-27 10:59:27 -0500390 if (rDiff > kTol || gDiff > kTol || bDiff > kTol || aDiff > kTol) {
391 ERRORF(reporter,
392 "Processor %s claimed output for const input doesn't match "
Brian Salomon5d4cd9e2017-02-09 11:16:46 -0500393 "actual output. Error: %f, Tolerance: %f, input: (%f, %f, %f, "
394 "%f), actual: (%f, %f, %f, %f), expected(%f, %f, %f, %f)",
395 fp->name(), SkTMax(rDiff, SkTMax(gDiff, SkTMax(bDiff, aDiff))),
396 kTol, input4f.fRGBA[0], input4f.fRGBA[1], input4f.fRGBA[2],
397 input4f.fRGBA[3], output4f.fRGBA[0], output4f.fRGBA[1],
398 output4f.fRGBA[2], output4f.fRGBA[3], expected4f.fRGBA[0],
399 expected4f.fRGBA[1], expected4f.fRGBA[2], expected4f.fRGBA[3]);
Brian Salomon587e08f2017-01-27 10:59:27 -0500400 passing = false;
401 }
402 }
403 if (GrColorIsOpaque(input) && fp->preservesOpaqueInput() &&
404 !GrColorIsOpaque(output)) {
405 ERRORF(reporter,
406 "Processor %s claimed opaqueness is preserved but it is not. Input: "
407 "0x%0x8, Output: 0x%08x.",
408 fp->name(), input, output);
409 passing = false;
410 }
411 }
412 }
413 }
414 }
415}
Hal Canary6f6961e2017-01-31 13:50:44 -0500416#endif // GR_TEST_UTILS
417#endif // SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
418#endif // SK_SUPPORT_GPU