blob: 05be7bbea40961af006ab7694e5ce0eddce10e73 [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
12#include "GrContext.h"
13#include "GrGpuResource.h"
Brian Salomon5d4cd9e2017-02-09 11:16:46 -050014#include "GrPipelineBuilder.h"
Brian Salomonbc6b99d2017-01-11 10:32:34 -050015#include "GrRenderTargetContext.h"
16#include "GrRenderTargetContextPriv.h"
17#include "GrResourceProvider.h"
18#include "glsl/GrGLSLFragmentProcessor.h"
19#include "glsl/GrGLSLFragmentShaderBuilder.h"
Brian Salomon5d4cd9e2017-02-09 11:16:46 -050020#include "ops/GrNonAAFillRectOp.h"
Brian Salomonbc6b99d2017-01-11 10:32:34 -050021#include "ops/GrTestMeshDrawOp.h"
22
23namespace {
24class TestOp : public GrTestMeshDrawOp {
25public:
26 DEFINE_OP_CLASS_ID
27 const char* name() const override { return "TestOp"; }
28
29 static std::unique_ptr<GrDrawOp> Make() { return std::unique_ptr<GrDrawOp>(new TestOp); }
30
31private:
32 TestOp() : INHERITED(ClassID(), SkRect::MakeWH(100, 100), 0xFFFFFFFF) {}
33
34 void onPrepareDraws(Target* target) const override { return; }
35
36 typedef GrTestMeshDrawOp INHERITED;
37};
38
39/**
40 * FP used to test ref/IO counts on owned GrGpuResources. Can also be a parent FP to test counts
41 * of resources owned by child FPs.
42 */
43class TestFP : public GrFragmentProcessor {
44public:
45 struct Image {
46 Image(sk_sp<GrTexture> texture, GrIOType ioType) : fTexture(texture), fIOType(ioType) {}
47 sk_sp<GrTexture> fTexture;
48 GrIOType fIOType;
49 };
50 static sk_sp<GrFragmentProcessor> Make(sk_sp<GrFragmentProcessor> child) {
51 return sk_sp<GrFragmentProcessor>(new TestFP(std::move(child)));
52 }
Robert Phillips30f9bc62017-02-22 15:28:38 -050053 static sk_sp<GrFragmentProcessor> Make(GrContext* context,
54 const SkTArray<sk_sp<GrTextureProxy>>& proxies,
Brian Salomonbc6b99d2017-01-11 10:32:34 -050055 const SkTArray<sk_sp<GrBuffer>>& buffers,
56 const SkTArray<Image>& images) {
Robert Phillips30f9bc62017-02-22 15:28:38 -050057 return sk_sp<GrFragmentProcessor>(new TestFP(context, proxies, buffers, images));
Brian Salomonbc6b99d2017-01-11 10:32:34 -050058 }
59
60 const char* name() const override { return "test"; }
61
62 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder* b) const override {
63 // We don't really care about reusing these.
64 static int32_t gKey = 0;
65 b->add32(sk_atomic_inc(&gKey));
66 }
67
Brian Salomonbc6b99d2017-01-11 10:32:34 -050068private:
Robert Phillips30f9bc62017-02-22 15:28:38 -050069 TestFP(GrContext* context,
70 const SkTArray<sk_sp<GrTextureProxy>>& proxies,
71 const SkTArray<sk_sp<GrBuffer>>& buffers,
Brian Salomonbc6b99d2017-01-11 10:32:34 -050072 const SkTArray<Image>& images)
Brian Salomon587e08f2017-01-27 10:59:27 -050073 : INHERITED(kNone_OptimizationFlags), fSamplers(4), fBuffers(4), fImages(4) {
Robert Phillips30f9bc62017-02-22 15:28:38 -050074 for (const auto& proxy : proxies) {
75 this->addTextureSampler(&fSamplers.emplace_back(context->textureProvider(), proxy));
Brian Salomonbc6b99d2017-01-11 10:32:34 -050076 }
77 for (const auto& buffer : buffers) {
78 this->addBufferAccess(&fBuffers.emplace_back(kRGBA_8888_GrPixelConfig, buffer.get()));
79 }
80 for (const Image& image : images) {
81 this->addImageStorageAccess(&fImages.emplace_back(
82 image.fTexture, image.fIOType, GrSLMemoryModel::kNone, GrSLRestrict::kNo));
83 }
84 }
85
Brian Salomon587e08f2017-01-27 10:59:27 -050086 TestFP(sk_sp<GrFragmentProcessor> child)
87 : INHERITED(kNone_OptimizationFlags), fSamplers(4), fBuffers(4), fImages(4) {
Brian Salomonbc6b99d2017-01-11 10:32:34 -050088 this->registerChildProcessor(std::move(child));
89 }
90
91 virtual GrGLSLFragmentProcessor* onCreateGLSLInstance() const override {
92 class TestGLSLFP : public GrGLSLFragmentProcessor {
93 public:
94 TestGLSLFP() {}
95 void emitCode(EmitArgs& args) override {
96 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
97 fragBuilder->codeAppendf("%s = %s;", args.fOutputColor, args.fInputColor);
98 }
99
100 private:
101 };
102 return new TestGLSLFP();
103 }
104
105 bool onIsEqual(const GrFragmentProcessor&) const override { return false; }
106
107 GrTAllocator<TextureSampler> fSamplers;
108 GrTAllocator<BufferAccess> fBuffers;
109 GrTAllocator<ImageStorageAccess> fImages;
Brian Salomon587e08f2017-01-27 10:59:27 -0500110 typedef GrFragmentProcessor INHERITED;
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500111};
112}
113
Brian Salomonf046e152017-01-11 15:24:47 -0500114template <typename T>
115inline void testingOnly_getIORefCnts(const T* resource, int* refCnt, int* readCnt, int* writeCnt) {
116 *refCnt = resource->fRefCnt;
117 *readCnt = resource->fPendingReads;
118 *writeCnt = resource->fPendingWrites;
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500119}
120
Robert Phillips2f493142017-03-02 18:18:38 -0500121void testingOnly_getIORefCnts(GrTextureProxy* proxy, int* refCnt, int* readCnt, int* writeCnt) {
Robert Phillips30f9bc62017-02-22 15:28:38 -0500122 *refCnt = proxy->getBackingRefCnt_TestOnly();
123 *readCnt = proxy->getPendingReadCnt_TestOnly();
124 *writeCnt = proxy->getPendingWriteCnt_TestOnly();
125}
126
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500127DEF_GPUTEST_FOR_ALL_CONTEXTS(ProcessorRefTest, reporter, ctxInfo) {
128 GrContext* context = ctxInfo.grContext();
129
130 GrTextureDesc desc;
131 desc.fConfig = kRGBA_8888_GrPixelConfig;
132 desc.fWidth = 10;
133 desc.fHeight = 10;
134
135 for (int parentCnt = 0; parentCnt < 2; parentCnt++) {
136 sk_sp<GrRenderTargetContext> renderTargetContext(context->makeRenderTargetContext(
137 SkBackingFit::kApprox, 1, 1, kRGBA_8888_GrPixelConfig, nullptr));
138 {
139 bool texelBufferSupport = context->caps()->shaderCaps()->texelBufferSupport();
140 bool imageLoadStoreSupport = context->caps()->shaderCaps()->imageLoadStoreSupport();
Robert Phillips2f493142017-03-02 18:18:38 -0500141 sk_sp<GrTextureProxy> proxy1(GrSurfaceProxy::MakeDeferred(context->textureProvider(),
Robert Phillips7928e762017-02-28 16:30:28 -0500142 *context->caps(), desc,
Robert Phillips30f9bc62017-02-22 15:28:38 -0500143 SkBackingFit::kExact,
144 SkBudgeted::kYes));
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500145 sk_sp<GrTexture> texture2(
146 context->resourceProvider()->createTexture(desc, SkBudgeted::kYes));
147 sk_sp<GrTexture> texture3(
148 context->resourceProvider()->createTexture(desc, SkBudgeted::kYes));
149 sk_sp<GrTexture> texture4(
150 context->resourceProvider()->createTexture(desc, SkBudgeted::kYes));
151 sk_sp<GrBuffer> buffer(texelBufferSupport
152 ? context->resourceProvider()->createBuffer(
153 1024, GrBufferType::kTexel_GrBufferType,
154 GrAccessPattern::kStatic_GrAccessPattern, 0)
155 : nullptr);
156 {
Robert Phillips30f9bc62017-02-22 15:28:38 -0500157 SkTArray<sk_sp<GrTextureProxy>> proxies;
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500158 SkTArray<sk_sp<GrBuffer>> buffers;
159 SkTArray<TestFP::Image> images;
Robert Phillips2f493142017-03-02 18:18:38 -0500160 proxies.push_back(proxy1);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500161 if (texelBufferSupport) {
162 buffers.push_back(buffer);
163 }
164 if (imageLoadStoreSupport) {
165 images.emplace_back(texture2, GrIOType::kRead_GrIOType);
166 images.emplace_back(texture3, GrIOType::kWrite_GrIOType);
167 images.emplace_back(texture4, GrIOType::kRW_GrIOType);
168 }
169 std::unique_ptr<GrDrawOp> op(TestOp::Make());
170 GrPaint paint;
Robert Phillips30f9bc62017-02-22 15:28:38 -0500171 auto fp = TestFP::Make(context,
172 std::move(proxies), std::move(buffers), std::move(images));
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500173 for (int i = 0; i < parentCnt; ++i) {
174 fp = TestFP::Make(std::move(fp));
175 }
176 paint.addColorFragmentProcessor(std::move(fp));
Brian Salomon82f44312017-01-11 13:42:54 -0500177 renderTargetContext->priv().testingOnly_addDrawOp(std::move(paint), GrAAType::kNone,
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500178 std::move(op));
179 }
180 int refCnt, readCnt, writeCnt;
181
Robert Phillips30f9bc62017-02-22 15:28:38 -0500182 testingOnly_getIORefCnts(proxy1.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500183 REPORTER_ASSERT(reporter, 1 == refCnt);
184 REPORTER_ASSERT(reporter, 1 == readCnt);
185 REPORTER_ASSERT(reporter, 0 == writeCnt);
186
187 if (texelBufferSupport) {
Brian Salomonf046e152017-01-11 15:24:47 -0500188 testingOnly_getIORefCnts(buffer.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500189 REPORTER_ASSERT(reporter, 1 == refCnt);
190 REPORTER_ASSERT(reporter, 1 == readCnt);
191 REPORTER_ASSERT(reporter, 0 == writeCnt);
192 }
193
194 if (imageLoadStoreSupport) {
Brian Salomonf046e152017-01-11 15:24:47 -0500195 testingOnly_getIORefCnts(texture2.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500196 REPORTER_ASSERT(reporter, 1 == refCnt);
197 REPORTER_ASSERT(reporter, 1 == readCnt);
198 REPORTER_ASSERT(reporter, 0 == writeCnt);
199
Brian Salomonf046e152017-01-11 15:24:47 -0500200 testingOnly_getIORefCnts(texture3.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500201 REPORTER_ASSERT(reporter, 1 == refCnt);
202 REPORTER_ASSERT(reporter, 0 == readCnt);
203 REPORTER_ASSERT(reporter, 1 == writeCnt);
204
Brian Salomonf046e152017-01-11 15:24:47 -0500205 testingOnly_getIORefCnts(texture4.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500206 REPORTER_ASSERT(reporter, 1 == refCnt);
207 REPORTER_ASSERT(reporter, 1 == readCnt);
208 REPORTER_ASSERT(reporter, 1 == writeCnt);
209 }
210
211 context->flush();
212
Robert Phillips30f9bc62017-02-22 15:28:38 -0500213 testingOnly_getIORefCnts(proxy1.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500214 REPORTER_ASSERT(reporter, 1 == refCnt);
215 REPORTER_ASSERT(reporter, 0 == readCnt);
216 REPORTER_ASSERT(reporter, 0 == writeCnt);
217
218 if (texelBufferSupport) {
Brian Salomonf046e152017-01-11 15:24:47 -0500219 testingOnly_getIORefCnts(buffer.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500220 REPORTER_ASSERT(reporter, 1 == refCnt);
221 REPORTER_ASSERT(reporter, 0 == readCnt);
222 REPORTER_ASSERT(reporter, 0 == writeCnt);
223 }
224
225 if (texelBufferSupport) {
Brian Salomonf046e152017-01-11 15:24:47 -0500226 testingOnly_getIORefCnts(texture2.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500227 REPORTER_ASSERT(reporter, 1 == refCnt);
228 REPORTER_ASSERT(reporter, 0 == readCnt);
229 REPORTER_ASSERT(reporter, 0 == writeCnt);
230
Brian Salomonf046e152017-01-11 15:24:47 -0500231 testingOnly_getIORefCnts(texture3.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500232 REPORTER_ASSERT(reporter, 1 == refCnt);
233 REPORTER_ASSERT(reporter, 0 == readCnt);
234 REPORTER_ASSERT(reporter, 0 == writeCnt);
235
Brian Salomonf046e152017-01-11 15:24:47 -0500236 testingOnly_getIORefCnts(texture4.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500237 REPORTER_ASSERT(reporter, 1 == refCnt);
238 REPORTER_ASSERT(reporter, 0 == readCnt);
239 REPORTER_ASSERT(reporter, 0 == writeCnt);
240 }
241 }
242 }
243}
Brian Salomon587e08f2017-01-27 10:59:27 -0500244
245// This test uses the random GrFragmentProcessor test factory, which relies on static initializers.
246#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
247
248static GrColor texel_color(int i, int j) {
249 SkASSERT((unsigned)i < 256 && (unsigned)j < 256);
250 GrColor color = GrColorPackRGBA(j, (uint8_t)(i + j), (uint8_t)(2 * j - i), i);
251 return GrPremulColor(color);
252}
253
254static GrColor4f texel_color4f(int i, int j) { return GrColor4f::FromGrColor(texel_color(i, j)); }
255
Robert Phillips30f9bc62017-02-22 15:28:38 -0500256void test_draw_op(GrContext* context, GrRenderTargetContext* rtc, sk_sp<GrFragmentProcessor> fp,
257 sk_sp<GrTextureProxy> inputDataProxy) {
Brian Salomon5d4cd9e2017-02-09 11:16:46 -0500258 GrPaint paint;
Robert Phillips30f9bc62017-02-22 15:28:38 -0500259 paint.addColorTextureProcessor(context, std::move(inputDataProxy), nullptr, SkMatrix::I());
Brian Salomon5d4cd9e2017-02-09 11:16:46 -0500260 paint.addColorFragmentProcessor(std::move(fp));
261 paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
262 GrPipelineBuilder pb(std::move(paint), GrAAType::kNone);
263 auto op =
264 GrNonAAFillRectOp::Make(GrColor_WHITE, SkMatrix::I(),
265 SkRect::MakeWH(rtc->width(), rtc->height()), nullptr, nullptr);
266 rtc->addDrawOp(pb, GrNoClip(), std::move(op));
267}
268
Hal Canary6f6961e2017-01-31 13:50:44 -0500269#if GR_TEST_UTILS
Brian Salomon5d4cd9e2017-02-09 11:16:46 -0500270DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ProcessorOptimizationValidationTest, reporter, ctxInfo) {
Brian Salomon587e08f2017-01-27 10:59:27 -0500271 GrContext* context = ctxInfo.grContext();
272 using FPFactory = GrProcessorTestFactory<GrFragmentProcessor>;
273 SkRandom random;
274 sk_sp<GrRenderTargetContext> rtc = context->makeRenderTargetContext(
275 SkBackingFit::kExact, 256, 256, kRGBA_8888_GrPixelConfig, nullptr);
276 GrSurfaceDesc desc;
277 desc.fWidth = 256;
278 desc.fHeight = 256;
279 desc.fFlags = kRenderTarget_GrSurfaceFlag;
280 desc.fConfig = kRGBA_8888_GrPixelConfig;
Brian Salomond1a8bdf2017-02-10 12:39:26 -0500281
282 // Put premul data into the RGBA texture that the test FPs can optionally use.
283 std::unique_ptr<GrColor[]> rgbaData(new GrColor[256 * 256]);
284 for (int y = 0; y < 256; ++y) {
285 for (int x = 0; x < 256; ++x) {
286 rgbaData.get()[256 * y + x] =
287 texel_color(random.nextULessThan(256), random.nextULessThan(256));
288 }
289 }
290 sk_sp<GrTexture> tex0(context->textureProvider()->createTexture(
291 desc, SkBudgeted::kYes, rgbaData.get(), 256 * sizeof(GrColor)));
292
293 // Put random values into the alpha texture that the test FPs can optionally use.
Brian Salomon587e08f2017-01-27 10:59:27 -0500294 desc.fConfig = kAlpha_8_GrPixelConfig;
Brian Salomond1a8bdf2017-02-10 12:39:26 -0500295 std::unique_ptr<uint8_t[]> alphaData(new uint8_t[256 * 256]);
296 for (int y = 0; y < 256; ++y) {
297 for (int x = 0; x < 256; ++x) {
298 alphaData.get()[256 * y + x] = random.nextULessThan(256);
299 }
300 }
301 sk_sp<GrTexture> tex1(context->textureProvider()->createTexture(desc, SkBudgeted::kYes,
302 alphaData.get(), 256));
Brian Salomon587e08f2017-01-27 10:59:27 -0500303 GrTexture* textures[] = {tex0.get(), tex1.get()};
304 GrProcessorTestData testData(&random, context, rtc.get(), textures);
305
Brian Salomond1a8bdf2017-02-10 12:39:26 -0500306 // Use a different array of premul colors for the output of the fragment processor that preceeds
307 // the fragment processor under test.
Brian Salomon587e08f2017-01-27 10:59:27 -0500308 for (int y = 0; y < 256; ++y) {
309 for (int x = 0; x < 256; ++x) {
Brian Salomond1a8bdf2017-02-10 12:39:26 -0500310 rgbaData.get()[256 * y + x] = texel_color(x, y);
Brian Salomon587e08f2017-01-27 10:59:27 -0500311 }
312 }
313 desc.fConfig = kRGBA_8888_GrPixelConfig;
Robert Phillips30f9bc62017-02-22 15:28:38 -0500314
Robert Phillips2f493142017-03-02 18:18:38 -0500315 sk_sp<GrTextureProxy> dataProxy = GrSurfaceProxy::MakeDeferred(*context->caps(),
Robert Phillips30f9bc62017-02-22 15:28:38 -0500316 context->textureProvider(),
317 desc, SkBudgeted::kYes,
318 rgbaData.get(),
319 256 * sizeof(GrColor));
Brian Salomon587e08f2017-01-27 10:59:27 -0500320
321 // Because processors factories configure themselves in random ways, this is not exhaustive.
322 for (int i = 0; i < FPFactory::Count(); ++i) {
323 int timesToInvokeFactory = 5;
324 // Increase the number of attempts if the FP has child FPs since optimizations likely depend
325 // on child optimizations being present.
326 sk_sp<GrFragmentProcessor> fp = FPFactory::MakeIdx(i, &testData);
327 for (int j = 0; j < fp->numChildProcessors(); ++j) {
328 // This value made a reasonable trade off between time and coverage when this test was
329 // written.
330 timesToInvokeFactory *= FPFactory::Count() / 2;
331 }
332 for (int j = 0; j < timesToInvokeFactory; ++j) {
333 fp = FPFactory::MakeIdx(i, &testData);
334 if (!fp->hasConstantOutputForConstantInput() && !fp->preservesOpaqueInput() &&
Brian Salomonf3b995b2017-02-15 10:22:23 -0500335 !fp->compatibleWithCoverageAsAlpha()) {
Brian Salomon587e08f2017-01-27 10:59:27 -0500336 continue;
337 }
Robert Phillips2f493142017-03-02 18:18:38 -0500338 test_draw_op(context, rtc.get(), fp, dataProxy);
Brian Salomond1a8bdf2017-02-10 12:39:26 -0500339 memset(rgbaData.get(), 0x0, sizeof(GrColor) * 256 * 256);
Brian Salomon587e08f2017-01-27 10:59:27 -0500340 rtc->readPixels(
341 SkImageInfo::Make(256, 256, kRGBA_8888_SkColorType, kPremul_SkAlphaType),
Brian Salomond1a8bdf2017-02-10 12:39:26 -0500342 rgbaData.get(), 0, 0, 0);
Brian Salomon587e08f2017-01-27 10:59:27 -0500343 bool passing = true;
344 if (0) { // Useful to see what FPs are being tested.
345 SkString children;
346 for (int c = 0; c < fp->numChildProcessors(); ++c) {
347 if (!c) {
348 children.append("(");
349 }
350 children.append(fp->childProcessor(c).name());
351 children.append(c == fp->numChildProcessors() - 1 ? ")" : ", ");
352 }
353 SkDebugf("%s %s\n", fp->name(), children.c_str());
354 }
355 for (int y = 0; y < 256 && passing; ++y) {
356 for (int x = 0; x < 256 && passing; ++x) {
357 GrColor input = texel_color(x, y);
Brian Salomond1a8bdf2017-02-10 12:39:26 -0500358 GrColor output = rgbaData.get()[y * 256 + x];
Brian Salomonf3b995b2017-02-15 10:22:23 -0500359 if (fp->compatibleWithCoverageAsAlpha()) {
Brian Salomon587e08f2017-01-27 10:59:27 -0500360 // A modulating processor is allowed to modulate either the input color or
361 // just the input alpha.
362 bool legalColorModulation =
363 GrColorUnpackA(output) <= GrColorUnpackA(input) &&
364 GrColorUnpackR(output) <= GrColorUnpackR(input) &&
365 GrColorUnpackG(output) <= GrColorUnpackG(input) &&
366 GrColorUnpackB(output) <= GrColorUnpackB(input);
367 bool legalAlphaModulation =
368 GrColorUnpackA(output) <= GrColorUnpackA(input) &&
369 GrColorUnpackR(output) <= GrColorUnpackA(input) &&
370 GrColorUnpackG(output) <= GrColorUnpackA(input) &&
371 GrColorUnpackB(output) <= GrColorUnpackA(input);
372 if (!legalColorModulation && !legalAlphaModulation) {
373 ERRORF(reporter,
374 "\"Modulating\" processor %s made color/alpha value larger. "
375 "Input: 0x%0x8, Output: 0x%08x.",
376 fp->name(), input, output);
377 passing = false;
378 }
379 }
380 GrColor4f input4f = texel_color4f(x, y);
381 GrColor4f output4f = GrColor4f::FromGrColor(output);
382 GrColor4f expected4f;
383 if (fp->hasConstantOutputForConstantInput(input4f, &expected4f)) {
384 float rDiff = fabsf(output4f.fRGBA[0] - expected4f.fRGBA[0]);
385 float gDiff = fabsf(output4f.fRGBA[1] - expected4f.fRGBA[1]);
386 float bDiff = fabsf(output4f.fRGBA[2] - expected4f.fRGBA[2]);
387 float aDiff = fabsf(output4f.fRGBA[3] - expected4f.fRGBA[3]);
Brian Salomon5d4cd9e2017-02-09 11:16:46 -0500388 static constexpr float kTol = 4 / 255.f;
Brian Salomon587e08f2017-01-27 10:59:27 -0500389 if (rDiff > kTol || gDiff > kTol || bDiff > kTol || aDiff > kTol) {
390 ERRORF(reporter,
391 "Processor %s claimed output for const input doesn't match "
Brian Salomon5d4cd9e2017-02-09 11:16:46 -0500392 "actual output. Error: %f, Tolerance: %f, input: (%f, %f, %f, "
393 "%f), actual: (%f, %f, %f, %f), expected(%f, %f, %f, %f)",
394 fp->name(), SkTMax(rDiff, SkTMax(gDiff, SkTMax(bDiff, aDiff))),
395 kTol, input4f.fRGBA[0], input4f.fRGBA[1], input4f.fRGBA[2],
396 input4f.fRGBA[3], output4f.fRGBA[0], output4f.fRGBA[1],
397 output4f.fRGBA[2], output4f.fRGBA[3], expected4f.fRGBA[0],
398 expected4f.fRGBA[1], expected4f.fRGBA[2], expected4f.fRGBA[3]);
Brian Salomon587e08f2017-01-27 10:59:27 -0500399 passing = false;
400 }
401 }
402 if (GrColorIsOpaque(input) && fp->preservesOpaqueInput() &&
403 !GrColorIsOpaque(output)) {
404 ERRORF(reporter,
405 "Processor %s claimed opaqueness is preserved but it is not. Input: "
406 "0x%0x8, Output: 0x%08x.",
407 fp->name(), input, output);
408 passing = false;
409 }
410 }
411 }
412 }
413 }
414}
Hal Canary6f6961e2017-01-31 13:50:44 -0500415#endif // GR_TEST_UTILS
416#endif // SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
417#endif // SK_SUPPORT_GPU