blob: bb9a3daaee337a6ea9ebfecc506834f209e93853 [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 Phillips30f9bc62017-02-22 15:28:38 -0500121void testingOnly_getIORefCnts(GrSurfaceProxy* proxy, int* refCnt, int* readCnt, int* writeCnt) {
122 *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 Phillips30f9bc62017-02-22 15:28:38 -0500141 sk_sp<GrSurfaceProxy> proxy1(GrSurfaceProxy::MakeDeferred(*context->caps(), desc,
142 SkBackingFit::kExact,
143 SkBudgeted::kYes));
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500144 sk_sp<GrTexture> texture2(
145 context->resourceProvider()->createTexture(desc, SkBudgeted::kYes));
146 sk_sp<GrTexture> texture3(
147 context->resourceProvider()->createTexture(desc, SkBudgeted::kYes));
148 sk_sp<GrTexture> texture4(
149 context->resourceProvider()->createTexture(desc, SkBudgeted::kYes));
150 sk_sp<GrBuffer> buffer(texelBufferSupport
151 ? context->resourceProvider()->createBuffer(
152 1024, GrBufferType::kTexel_GrBufferType,
153 GrAccessPattern::kStatic_GrAccessPattern, 0)
154 : nullptr);
155 {
Robert Phillips30f9bc62017-02-22 15:28:38 -0500156 SkTArray<sk_sp<GrTextureProxy>> proxies;
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500157 SkTArray<sk_sp<GrBuffer>> buffers;
158 SkTArray<TestFP::Image> images;
Robert Phillips30f9bc62017-02-22 15:28:38 -0500159 proxies.push_back(sk_ref_sp(proxy1->asTextureProxy()));
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500160 if (texelBufferSupport) {
161 buffers.push_back(buffer);
162 }
163 if (imageLoadStoreSupport) {
164 images.emplace_back(texture2, GrIOType::kRead_GrIOType);
165 images.emplace_back(texture3, GrIOType::kWrite_GrIOType);
166 images.emplace_back(texture4, GrIOType::kRW_GrIOType);
167 }
168 std::unique_ptr<GrDrawOp> op(TestOp::Make());
169 GrPaint paint;
Robert Phillips30f9bc62017-02-22 15:28:38 -0500170 auto fp = TestFP::Make(context,
171 std::move(proxies), std::move(buffers), std::move(images));
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500172 for (int i = 0; i < parentCnt; ++i) {
173 fp = TestFP::Make(std::move(fp));
174 }
175 paint.addColorFragmentProcessor(std::move(fp));
Brian Salomon82f44312017-01-11 13:42:54 -0500176 renderTargetContext->priv().testingOnly_addDrawOp(std::move(paint), GrAAType::kNone,
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500177 std::move(op));
178 }
179 int refCnt, readCnt, writeCnt;
180
Robert Phillips30f9bc62017-02-22 15:28:38 -0500181 testingOnly_getIORefCnts(proxy1.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500182 REPORTER_ASSERT(reporter, 1 == refCnt);
183 REPORTER_ASSERT(reporter, 1 == readCnt);
184 REPORTER_ASSERT(reporter, 0 == writeCnt);
185
186 if (texelBufferSupport) {
Brian Salomonf046e152017-01-11 15:24:47 -0500187 testingOnly_getIORefCnts(buffer.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500188 REPORTER_ASSERT(reporter, 1 == refCnt);
189 REPORTER_ASSERT(reporter, 1 == readCnt);
190 REPORTER_ASSERT(reporter, 0 == writeCnt);
191 }
192
193 if (imageLoadStoreSupport) {
Brian Salomonf046e152017-01-11 15:24:47 -0500194 testingOnly_getIORefCnts(texture2.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500195 REPORTER_ASSERT(reporter, 1 == refCnt);
196 REPORTER_ASSERT(reporter, 1 == readCnt);
197 REPORTER_ASSERT(reporter, 0 == writeCnt);
198
Brian Salomonf046e152017-01-11 15:24:47 -0500199 testingOnly_getIORefCnts(texture3.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500200 REPORTER_ASSERT(reporter, 1 == refCnt);
201 REPORTER_ASSERT(reporter, 0 == readCnt);
202 REPORTER_ASSERT(reporter, 1 == writeCnt);
203
Brian Salomonf046e152017-01-11 15:24:47 -0500204 testingOnly_getIORefCnts(texture4.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500205 REPORTER_ASSERT(reporter, 1 == refCnt);
206 REPORTER_ASSERT(reporter, 1 == readCnt);
207 REPORTER_ASSERT(reporter, 1 == writeCnt);
208 }
209
210 context->flush();
211
Robert Phillips30f9bc62017-02-22 15:28:38 -0500212 testingOnly_getIORefCnts(proxy1.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500213 REPORTER_ASSERT(reporter, 1 == refCnt);
214 REPORTER_ASSERT(reporter, 0 == readCnt);
215 REPORTER_ASSERT(reporter, 0 == writeCnt);
216
217 if (texelBufferSupport) {
Brian Salomonf046e152017-01-11 15:24:47 -0500218 testingOnly_getIORefCnts(buffer.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500219 REPORTER_ASSERT(reporter, 1 == refCnt);
220 REPORTER_ASSERT(reporter, 0 == readCnt);
221 REPORTER_ASSERT(reporter, 0 == writeCnt);
222 }
223
224 if (texelBufferSupport) {
Brian Salomonf046e152017-01-11 15:24:47 -0500225 testingOnly_getIORefCnts(texture2.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500226 REPORTER_ASSERT(reporter, 1 == refCnt);
227 REPORTER_ASSERT(reporter, 0 == readCnt);
228 REPORTER_ASSERT(reporter, 0 == writeCnt);
229
Brian Salomonf046e152017-01-11 15:24:47 -0500230 testingOnly_getIORefCnts(texture3.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500231 REPORTER_ASSERT(reporter, 1 == refCnt);
232 REPORTER_ASSERT(reporter, 0 == readCnt);
233 REPORTER_ASSERT(reporter, 0 == writeCnt);
234
Brian Salomonf046e152017-01-11 15:24:47 -0500235 testingOnly_getIORefCnts(texture4.get(), &refCnt, &readCnt, &writeCnt);
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500236 REPORTER_ASSERT(reporter, 1 == refCnt);
237 REPORTER_ASSERT(reporter, 0 == readCnt);
238 REPORTER_ASSERT(reporter, 0 == writeCnt);
239 }
240 }
241 }
242}
Brian Salomon587e08f2017-01-27 10:59:27 -0500243
244// This test uses the random GrFragmentProcessor test factory, which relies on static initializers.
245#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
246
247static GrColor texel_color(int i, int j) {
248 SkASSERT((unsigned)i < 256 && (unsigned)j < 256);
249 GrColor color = GrColorPackRGBA(j, (uint8_t)(i + j), (uint8_t)(2 * j - i), i);
250 return GrPremulColor(color);
251}
252
253static GrColor4f texel_color4f(int i, int j) { return GrColor4f::FromGrColor(texel_color(i, j)); }
254
Robert Phillips30f9bc62017-02-22 15:28:38 -0500255void test_draw_op(GrContext* context, GrRenderTargetContext* rtc, sk_sp<GrFragmentProcessor> fp,
256 sk_sp<GrTextureProxy> inputDataProxy) {
Brian Salomon5d4cd9e2017-02-09 11:16:46 -0500257 GrPaint paint;
Robert Phillips30f9bc62017-02-22 15:28:38 -0500258 paint.addColorTextureProcessor(context, std::move(inputDataProxy), nullptr, SkMatrix::I());
Brian Salomon5d4cd9e2017-02-09 11:16:46 -0500259 paint.addColorFragmentProcessor(std::move(fp));
260 paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
261 GrPipelineBuilder pb(std::move(paint), GrAAType::kNone);
262 auto op =
263 GrNonAAFillRectOp::Make(GrColor_WHITE, SkMatrix::I(),
264 SkRect::MakeWH(rtc->width(), rtc->height()), nullptr, nullptr);
265 rtc->addDrawOp(pb, GrNoClip(), std::move(op));
266}
267
Hal Canary6f6961e2017-01-31 13:50:44 -0500268#if GR_TEST_UTILS
Brian Salomon5d4cd9e2017-02-09 11:16:46 -0500269DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ProcessorOptimizationValidationTest, reporter, ctxInfo) {
Brian Salomon587e08f2017-01-27 10:59:27 -0500270 GrContext* context = ctxInfo.grContext();
271 using FPFactory = GrProcessorTestFactory<GrFragmentProcessor>;
272 SkRandom random;
273 sk_sp<GrRenderTargetContext> rtc = context->makeRenderTargetContext(
274 SkBackingFit::kExact, 256, 256, kRGBA_8888_GrPixelConfig, nullptr);
275 GrSurfaceDesc desc;
276 desc.fWidth = 256;
277 desc.fHeight = 256;
278 desc.fFlags = kRenderTarget_GrSurfaceFlag;
279 desc.fConfig = kRGBA_8888_GrPixelConfig;
Brian Salomond1a8bdf2017-02-10 12:39:26 -0500280
281 // Put premul data into the RGBA texture that the test FPs can optionally use.
282 std::unique_ptr<GrColor[]> rgbaData(new GrColor[256 * 256]);
283 for (int y = 0; y < 256; ++y) {
284 for (int x = 0; x < 256; ++x) {
285 rgbaData.get()[256 * y + x] =
286 texel_color(random.nextULessThan(256), random.nextULessThan(256));
287 }
288 }
289 sk_sp<GrTexture> tex0(context->textureProvider()->createTexture(
290 desc, SkBudgeted::kYes, rgbaData.get(), 256 * sizeof(GrColor)));
291
292 // Put random values into the alpha texture that the test FPs can optionally use.
Brian Salomon587e08f2017-01-27 10:59:27 -0500293 desc.fConfig = kAlpha_8_GrPixelConfig;
Brian Salomond1a8bdf2017-02-10 12:39:26 -0500294 std::unique_ptr<uint8_t[]> alphaData(new uint8_t[256 * 256]);
295 for (int y = 0; y < 256; ++y) {
296 for (int x = 0; x < 256; ++x) {
297 alphaData.get()[256 * y + x] = random.nextULessThan(256);
298 }
299 }
300 sk_sp<GrTexture> tex1(context->textureProvider()->createTexture(desc, SkBudgeted::kYes,
301 alphaData.get(), 256));
Brian Salomon587e08f2017-01-27 10:59:27 -0500302 GrTexture* textures[] = {tex0.get(), tex1.get()};
303 GrProcessorTestData testData(&random, context, rtc.get(), textures);
304
Brian Salomond1a8bdf2017-02-10 12:39:26 -0500305 // Use a different array of premul colors for the output of the fragment processor that preceeds
306 // the fragment processor under test.
Brian Salomon587e08f2017-01-27 10:59:27 -0500307 for (int y = 0; y < 256; ++y) {
308 for (int x = 0; x < 256; ++x) {
Brian Salomond1a8bdf2017-02-10 12:39:26 -0500309 rgbaData.get()[256 * y + x] = texel_color(x, y);
Brian Salomon587e08f2017-01-27 10:59:27 -0500310 }
311 }
312 desc.fConfig = kRGBA_8888_GrPixelConfig;
Robert Phillips30f9bc62017-02-22 15:28:38 -0500313
314 sk_sp<GrSurfaceProxy> dataProxy = GrSurfaceProxy::MakeDeferred(*context->caps(),
315 context->textureProvider(),
316 desc, SkBudgeted::kYes,
317 rgbaData.get(),
318 256 * sizeof(GrColor));
Brian Salomon587e08f2017-01-27 10:59:27 -0500319
320 // Because processors factories configure themselves in random ways, this is not exhaustive.
321 for (int i = 0; i < FPFactory::Count(); ++i) {
322 int timesToInvokeFactory = 5;
323 // Increase the number of attempts if the FP has child FPs since optimizations likely depend
324 // on child optimizations being present.
325 sk_sp<GrFragmentProcessor> fp = FPFactory::MakeIdx(i, &testData);
326 for (int j = 0; j < fp->numChildProcessors(); ++j) {
327 // This value made a reasonable trade off between time and coverage when this test was
328 // written.
329 timesToInvokeFactory *= FPFactory::Count() / 2;
330 }
331 for (int j = 0; j < timesToInvokeFactory; ++j) {
332 fp = FPFactory::MakeIdx(i, &testData);
333 if (!fp->hasConstantOutputForConstantInput() && !fp->preservesOpaqueInput() &&
Brian Salomonf3b995b2017-02-15 10:22:23 -0500334 !fp->compatibleWithCoverageAsAlpha()) {
Brian Salomon587e08f2017-01-27 10:59:27 -0500335 continue;
336 }
Robert Phillips30f9bc62017-02-22 15:28:38 -0500337 test_draw_op(context, rtc.get(), fp, sk_ref_sp(dataProxy->asTextureProxy()));
Brian Salomond1a8bdf2017-02-10 12:39:26 -0500338 memset(rgbaData.get(), 0x0, sizeof(GrColor) * 256 * 256);
Brian Salomon587e08f2017-01-27 10:59:27 -0500339 rtc->readPixels(
340 SkImageInfo::Make(256, 256, kRGBA_8888_SkColorType, kPremul_SkAlphaType),
Brian Salomond1a8bdf2017-02-10 12:39:26 -0500341 rgbaData.get(), 0, 0, 0);
Brian Salomon587e08f2017-01-27 10:59:27 -0500342 bool passing = true;
343 if (0) { // Useful to see what FPs are being tested.
344 SkString children;
345 for (int c = 0; c < fp->numChildProcessors(); ++c) {
346 if (!c) {
347 children.append("(");
348 }
349 children.append(fp->childProcessor(c).name());
350 children.append(c == fp->numChildProcessors() - 1 ? ")" : ", ");
351 }
352 SkDebugf("%s %s\n", fp->name(), children.c_str());
353 }
354 for (int y = 0; y < 256 && passing; ++y) {
355 for (int x = 0; x < 256 && passing; ++x) {
356 GrColor input = texel_color(x, y);
Brian Salomond1a8bdf2017-02-10 12:39:26 -0500357 GrColor output = rgbaData.get()[y * 256 + x];
Brian Salomonf3b995b2017-02-15 10:22:23 -0500358 if (fp->compatibleWithCoverageAsAlpha()) {
Brian Salomon587e08f2017-01-27 10:59:27 -0500359 // A modulating processor is allowed to modulate either the input color or
360 // just the input alpha.
361 bool legalColorModulation =
362 GrColorUnpackA(output) <= GrColorUnpackA(input) &&
363 GrColorUnpackR(output) <= GrColorUnpackR(input) &&
364 GrColorUnpackG(output) <= GrColorUnpackG(input) &&
365 GrColorUnpackB(output) <= GrColorUnpackB(input);
366 bool legalAlphaModulation =
367 GrColorUnpackA(output) <= GrColorUnpackA(input) &&
368 GrColorUnpackR(output) <= GrColorUnpackA(input) &&
369 GrColorUnpackG(output) <= GrColorUnpackA(input) &&
370 GrColorUnpackB(output) <= GrColorUnpackA(input);
371 if (!legalColorModulation && !legalAlphaModulation) {
372 ERRORF(reporter,
373 "\"Modulating\" processor %s made color/alpha value larger. "
374 "Input: 0x%0x8, Output: 0x%08x.",
375 fp->name(), input, output);
376 passing = false;
377 }
378 }
379 GrColor4f input4f = texel_color4f(x, y);
380 GrColor4f output4f = GrColor4f::FromGrColor(output);
381 GrColor4f expected4f;
382 if (fp->hasConstantOutputForConstantInput(input4f, &expected4f)) {
383 float rDiff = fabsf(output4f.fRGBA[0] - expected4f.fRGBA[0]);
384 float gDiff = fabsf(output4f.fRGBA[1] - expected4f.fRGBA[1]);
385 float bDiff = fabsf(output4f.fRGBA[2] - expected4f.fRGBA[2]);
386 float aDiff = fabsf(output4f.fRGBA[3] - expected4f.fRGBA[3]);
Brian Salomon5d4cd9e2017-02-09 11:16:46 -0500387 static constexpr float kTol = 4 / 255.f;
Brian Salomon587e08f2017-01-27 10:59:27 -0500388 if (rDiff > kTol || gDiff > kTol || bDiff > kTol || aDiff > kTol) {
389 ERRORF(reporter,
390 "Processor %s claimed output for const input doesn't match "
Brian Salomon5d4cd9e2017-02-09 11:16:46 -0500391 "actual output. Error: %f, Tolerance: %f, input: (%f, %f, %f, "
392 "%f), actual: (%f, %f, %f, %f), expected(%f, %f, %f, %f)",
393 fp->name(), SkTMax(rDiff, SkTMax(gDiff, SkTMax(bDiff, aDiff))),
394 kTol, input4f.fRGBA[0], input4f.fRGBA[1], input4f.fRGBA[2],
395 input4f.fRGBA[3], output4f.fRGBA[0], output4f.fRGBA[1],
396 output4f.fRGBA[2], output4f.fRGBA[3], expected4f.fRGBA[0],
397 expected4f.fRGBA[1], expected4f.fRGBA[2], expected4f.fRGBA[3]);
Brian Salomon587e08f2017-01-27 10:59:27 -0500398 passing = false;
399 }
400 }
401 if (GrColorIsOpaque(input) && fp->preservesOpaqueInput() &&
402 !GrColorIsOpaque(output)) {
403 ERRORF(reporter,
404 "Processor %s claimed opaqueness is preserved but it is not. Input: "
405 "0x%0x8, Output: 0x%08x.",
406 fp->name(), input, output);
407 passing = false;
408 }
409 }
410 }
411 }
412 }
413}
Hal Canary6f6961e2017-01-31 13:50:44 -0500414#endif // GR_TEST_UTILS
415#endif // SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
416#endif // SK_SUPPORT_GPU