2017-01-11 15:32:34 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tests/Test.h"
|
|
|
|
|
2020-07-06 14:56:46 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2020-01-28 22:02:49 +00:00
|
|
|
#include "src/gpu/GrBitmapTextureMaker.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrClip.h"
|
|
|
|
#include "src/gpu/GrContextPriv.h"
|
2020-03-05 19:14:18 +00:00
|
|
|
#include "src/gpu/GrGpuResource.h"
|
2019-09-30 16:15:30 +00:00
|
|
|
#include "src/gpu/GrImageInfo.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrMemoryPool.h"
|
|
|
|
#include "src/gpu/GrProxyProvider.h"
|
|
|
|
#include "src/gpu/GrRenderTargetContext.h"
|
|
|
|
#include "src/gpu/GrRenderTargetContextPriv.h"
|
|
|
|
#include "src/gpu/GrResourceProvider.h"
|
|
|
|
#include "src/gpu/glsl/GrGLSLFragmentProcessor.h"
|
|
|
|
#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
|
|
|
|
#include "src/gpu/ops/GrFillRectOp.h"
|
|
|
|
#include "src/gpu/ops/GrMeshDrawOp.h"
|
|
|
|
#include "tests/TestUtils.h"
|
2018-12-04 16:52:51 +00:00
|
|
|
#include <atomic>
|
2018-09-19 15:31:27 +00:00
|
|
|
#include <random>
|
|
|
|
|
2017-01-11 15:32:34 +00:00
|
|
|
namespace {
|
2017-07-14 16:00:13 +00:00
|
|
|
class TestOp : public GrMeshDrawOp {
|
2017-01-11 15:32:34 +00:00
|
|
|
public:
|
|
|
|
DEFINE_OP_CLASS_ID
|
2018-06-12 14:11:12 +00:00
|
|
|
static std::unique_ptr<GrDrawOp> Make(GrContext* context,
|
|
|
|
std::unique_ptr<GrFragmentProcessor> fp) {
|
2019-02-04 18:26:26 +00:00
|
|
|
GrOpMemoryPool* pool = context->priv().opMemoryPool();
|
2018-06-19 17:09:54 +00:00
|
|
|
|
|
|
|
return pool->allocate<TestOp>(std::move(fp));
|
2017-07-14 16:00:13 +00:00
|
|
|
}
|
|
|
|
|
2017-09-14 12:27:37 +00:00
|
|
|
const char* name() const override { return "TestOp"; }
|
|
|
|
|
2019-05-22 01:35:29 +00:00
|
|
|
void visitProxies(const VisitProxyFunc& func) const override {
|
2017-09-14 12:27:37 +00:00
|
|
|
fProcessors.visitProxies(func);
|
|
|
|
}
|
|
|
|
|
2017-07-14 16:00:13 +00:00
|
|
|
FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; }
|
|
|
|
|
2019-06-24 00:07:38 +00:00
|
|
|
GrProcessorSet::Analysis finalize(
|
|
|
|
const GrCaps& caps, const GrAppliedClip* clip, bool hasMixedSampledCoverage,
|
|
|
|
GrClampType clampType) override {
|
2017-07-14 16:00:13 +00:00
|
|
|
static constexpr GrProcessorAnalysisColor kUnknownColor;
|
2018-10-31 18:04:39 +00:00
|
|
|
SkPMColor4f overrideColor;
|
2019-03-05 17:11:58 +00:00
|
|
|
return fProcessors.finalize(
|
|
|
|
kUnknownColor, GrProcessorAnalysisCoverage::kNone, clip,
|
2019-06-24 00:07:38 +00:00
|
|
|
&GrUserStencilSettings::kUnused, hasMixedSampledCoverage, caps, clampType,
|
|
|
|
&overrideColor);
|
2017-03-09 18:50:43 +00:00
|
|
|
}
|
2017-01-11 15:32:34 +00:00
|
|
|
|
|
|
|
private:
|
2018-06-12 14:11:12 +00:00
|
|
|
friend class ::GrOpMemoryPool; // for ctor
|
|
|
|
|
2017-08-11 13:40:37 +00:00
|
|
|
TestOp(std::unique_ptr<GrFragmentProcessor> fp)
|
|
|
|
: INHERITED(ClassID()), fProcessors(std::move(fp)) {
|
2019-10-01 19:14:44 +00:00
|
|
|
this->setBounds(SkRect::MakeWH(100, 100), HasAABloat::kNo, IsHairline::kNo);
|
2017-07-14 16:00:13 +00:00
|
|
|
}
|
2017-01-11 15:32:34 +00:00
|
|
|
|
2020-03-12 16:07:19 +00:00
|
|
|
GrProgramInfo* programInfo() override { return nullptr; }
|
2020-03-11 19:55:55 +00:00
|
|
|
void onCreateProgramInfo(const GrCaps*,
|
|
|
|
SkArenaAlloc*,
|
2020-04-01 20:22:00 +00:00
|
|
|
const GrSurfaceProxyView* writeView,
|
2020-03-11 19:55:55 +00:00
|
|
|
GrAppliedClip&&,
|
|
|
|
const GrXferProcessor::DstProxyView&) override { return; }
|
2020-03-12 16:07:19 +00:00
|
|
|
void onPrePrepareDraws(GrRecordingContext*,
|
2020-04-01 20:22:00 +00:00
|
|
|
const GrSurfaceProxyView* writeView,
|
2020-03-12 16:07:19 +00:00
|
|
|
GrAppliedClip*,
|
|
|
|
const GrXferProcessor::DstProxyView&) override { return; }
|
2017-08-09 20:02:19 +00:00
|
|
|
void onPrepareDraws(Target* target) override { return; }
|
2019-02-26 18:13:22 +00:00
|
|
|
void onExecute(GrOpFlushState*, const SkRect&) override { return; }
|
2017-01-11 15:32:34 +00:00
|
|
|
|
2017-07-14 16:00:13 +00:00
|
|
|
GrProcessorSet fProcessors;
|
|
|
|
|
|
|
|
typedef GrMeshDrawOp INHERITED;
|
2017-01-11 15:32:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2019-06-11 12:08:08 +00:00
|
|
|
* FP used to test ref counts on owned GrGpuResources. Can also be a parent FP to test counts
|
2017-01-11 15:32:34 +00:00
|
|
|
* of resources owned by child FPs.
|
|
|
|
*/
|
|
|
|
class TestFP : public GrFragmentProcessor {
|
|
|
|
public:
|
2017-08-11 13:40:37 +00:00
|
|
|
static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> child) {
|
|
|
|
return std::unique_ptr<GrFragmentProcessor>(new TestFP(std::move(child)));
|
2017-01-11 15:32:34 +00:00
|
|
|
}
|
2020-06-17 18:19:19 +00:00
|
|
|
static std::unique_ptr<GrFragmentProcessor> Make(const SkTArray<GrSurfaceProxyView>& views) {
|
|
|
|
return std::unique_ptr<GrFragmentProcessor>(new TestFP(views));
|
2017-01-11 15:32:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* name() const override { return "test"; }
|
|
|
|
|
|
|
|
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder* b) const override {
|
2018-12-04 16:52:51 +00:00
|
|
|
static std::atomic<int32_t> nextKey{0};
|
|
|
|
b->add32(nextKey++);
|
2017-01-11 15:32:34 +00:00
|
|
|
}
|
|
|
|
|
2017-08-11 13:40:37 +00:00
|
|
|
std::unique_ptr<GrFragmentProcessor> clone() const override {
|
|
|
|
return std::unique_ptr<GrFragmentProcessor>(new TestFP(*this));
|
2017-07-28 17:41:51 +00:00
|
|
|
}
|
|
|
|
|
2017-01-11 15:32:34 +00:00
|
|
|
private:
|
2020-06-17 18:19:19 +00:00
|
|
|
TestFP(const SkTArray<GrSurfaceProxyView>& views)
|
|
|
|
: INHERITED(kTestFP_ClassID, kNone_OptimizationFlags) {
|
2020-02-12 15:53:51 +00:00
|
|
|
for (const auto& view : views) {
|
2020-06-22 18:46:36 +00:00
|
|
|
this->registerChild(GrTextureEffect::Make(view, kUnknown_SkAlphaType));
|
2017-01-11 15:32:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-11 13:40:37 +00:00
|
|
|
TestFP(std::unique_ptr<GrFragmentProcessor> child)
|
2020-06-17 18:19:19 +00:00
|
|
|
: INHERITED(kTestFP_ClassID, kNone_OptimizationFlags) {
|
2020-06-22 18:46:36 +00:00
|
|
|
this->registerChild(std::move(child));
|
2017-01-11 15:32:34 +00:00
|
|
|
}
|
|
|
|
|
2020-06-17 18:19:19 +00:00
|
|
|
explicit TestFP(const TestFP& that) : INHERITED(kTestFP_ClassID, that.optimizationFlags()) {
|
|
|
|
this->cloneAndRegisterAllChildProcessors(that);
|
2017-07-28 17:41:51 +00:00
|
|
|
}
|
|
|
|
|
2017-01-11 15:32:34 +00:00
|
|
|
virtual GrGLSLFragmentProcessor* onCreateGLSLInstance() const override {
|
|
|
|
class TestGLSLFP : public GrGLSLFragmentProcessor {
|
|
|
|
public:
|
|
|
|
TestGLSLFP() {}
|
|
|
|
void emitCode(EmitArgs& args) override {
|
|
|
|
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
|
|
|
|
fragBuilder->codeAppendf("%s = %s;", args.fOutputColor, args.fInputColor);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
};
|
|
|
|
return new TestGLSLFP();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool onIsEqual(const GrFragmentProcessor&) const override { return false; }
|
|
|
|
|
2017-01-27 15:59:27 +00:00
|
|
|
typedef GrFragmentProcessor INHERITED;
|
2017-01-11 15:32:34 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_ALL_CONTEXTS(ProcessorRefTest, reporter, ctxInfo) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto context = ctxInfo.directContext();
|
2019-02-04 18:26:26 +00:00
|
|
|
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
|
2017-01-11 15:32:34 +00:00
|
|
|
|
2020-02-07 19:17:25 +00:00
|
|
|
static constexpr SkISize kDims = {10, 10};
|
2017-01-11 15:32:34 +00:00
|
|
|
|
2018-11-16 20:43:41 +00:00
|
|
|
const GrBackendFormat format =
|
2019-07-30 16:49:10 +00:00
|
|
|
context->priv().caps()->getDefaultBackendFormat(GrColorType::kRGBA_8888,
|
|
|
|
GrRenderable::kNo);
|
2020-01-21 19:29:57 +00:00
|
|
|
GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(format, GrColorType::kRGBA_8888);
|
2018-11-16 20:43:41 +00:00
|
|
|
|
2017-07-28 17:41:51 +00:00
|
|
|
for (bool makeClone : {false, true}) {
|
|
|
|
for (int parentCnt = 0; parentCnt < 2; parentCnt++) {
|
2020-01-08 16:52:34 +00:00
|
|
|
auto renderTargetContext = GrRenderTargetContext::Make(
|
|
|
|
context, GrColorType::kRGBA_8888, nullptr, SkBackingFit::kApprox, {1, 1});
|
2017-01-11 15:32:34 +00:00
|
|
|
{
|
2019-06-11 12:08:08 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
|
2020-03-27 00:37:01 +00:00
|
|
|
format, kDims, GrRenderable::kNo, 1, GrMipMapped::kNo, SkBackingFit::kExact,
|
|
|
|
SkBudgeted::kYes, GrProtected::kNo);
|
2019-06-11 12:08:08 +00:00
|
|
|
|
2017-07-28 17:41:51 +00:00
|
|
|
{
|
2020-02-12 15:53:51 +00:00
|
|
|
SkTArray<GrSurfaceProxyView> views;
|
|
|
|
views.push_back({proxy, kTopLeft_GrSurfaceOrigin, swizzle});
|
2020-06-17 18:19:19 +00:00
|
|
|
auto fp = TestFP::Make(std::move(views));
|
2017-07-28 17:41:51 +00:00
|
|
|
for (int i = 0; i < parentCnt; ++i) {
|
|
|
|
fp = TestFP::Make(std::move(fp));
|
|
|
|
}
|
2017-08-11 13:40:37 +00:00
|
|
|
std::unique_ptr<GrFragmentProcessor> clone;
|
2017-07-28 17:41:51 +00:00
|
|
|
if (makeClone) {
|
|
|
|
clone = fp->clone();
|
|
|
|
}
|
2018-06-12 14:11:12 +00:00
|
|
|
std::unique_ptr<GrDrawOp> op(TestOp::Make(context, std::move(fp)));
|
2017-07-28 17:41:51 +00:00
|
|
|
renderTargetContext->priv().testingOnly_addDrawOp(std::move(op));
|
|
|
|
if (clone) {
|
2018-06-12 14:11:12 +00:00
|
|
|
op = TestOp::Make(context, std::move(clone));
|
2017-07-28 17:41:51 +00:00
|
|
|
renderTargetContext->priv().testingOnly_addDrawOp(std::move(op));
|
|
|
|
}
|
2017-01-11 15:32:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-11 12:08:08 +00:00
|
|
|
// If the fp is cloned the number of refs should increase by one (for the clone)
|
|
|
|
int expectedProxyRefs = makeClone ? 3 : 2;
|
2017-01-11 15:32:34 +00:00
|
|
|
|
2019-10-25 00:07:39 +00:00
|
|
|
CheckSingleThreadedProxyRefs(reporter, proxy.get(), expectedProxyRefs, -1);
|
2017-01-11 15:32:34 +00:00
|
|
|
|
2020-05-14 19:45:44 +00:00
|
|
|
context->flushAndSubmit();
|
2017-01-11 15:32:34 +00:00
|
|
|
|
2019-10-24 14:37:08 +00:00
|
|
|
// just one from the 'proxy' sk_sp
|
2019-10-25 00:07:39 +00:00
|
|
|
CheckSingleThreadedProxyRefs(reporter, proxy.get(), 1, 1);
|
2017-01-11 15:32:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-01-27 15:59:27 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/flags/CommandLineFlags.h"
|
2019-03-21 16:31:36 +00:00
|
|
|
static DEFINE_bool(randomProcessorTest, false,
|
|
|
|
"Use non-deterministic seed for random processor tests?");
|
2019-03-21 16:42:21 +00:00
|
|
|
static DEFINE_int(processorSeed, 0,
|
|
|
|
"Use specific seed for processor tests. Overridden by --randomProcessorTest.");
|
2017-07-25 13:43:22 +00:00
|
|
|
|
|
|
|
#if GR_TEST_UTILS
|
|
|
|
|
2018-10-08 20:43:58 +00:00
|
|
|
static GrColor input_texel_color(int i, int j, SkScalar delta) {
|
|
|
|
// Delta must be less than 0.5 to prevent over/underflow issues with the input color
|
|
|
|
SkASSERT(delta <= 0.5);
|
2017-01-27 15:59:27 +00:00
|
|
|
|
2019-02-04 15:01:53 +00:00
|
|
|
SkColor color = SkColorSetARGB((uint8_t)(i & 0xFF),
|
|
|
|
(uint8_t)(j & 0xFF),
|
|
|
|
(uint8_t)((i + j) & 0xFF),
|
|
|
|
(uint8_t)((2 * j - i) & 0xFF));
|
2018-10-16 19:19:28 +00:00
|
|
|
SkColor4f color4f = SkColor4f::FromColor(color);
|
2019-12-18 19:57:45 +00:00
|
|
|
// We only apply delta to the r,g, and b channels. This is because we're using this
|
|
|
|
// to test the canTweakAlphaForCoverage() optimization. A processor is allowed
|
|
|
|
// to use the input color's alpha in its calculation and report this optimization.
|
|
|
|
for (int i = 0; i < 3; i++) {
|
2018-10-16 19:19:28 +00:00
|
|
|
if (color4f[i] > 0.5) {
|
|
|
|
color4f[i] -= delta;
|
2018-10-08 20:43:58 +00:00
|
|
|
} else {
|
2018-10-16 19:19:28 +00:00
|
|
|
color4f[i] += delta;
|
2018-10-08 20:43:58 +00:00
|
|
|
}
|
|
|
|
}
|
2018-10-16 19:19:28 +00:00
|
|
|
return color4f.premul().toBytes_RGBA();
|
2017-07-25 13:43:22 +00:00
|
|
|
}
|
2017-01-27 15:59:27 +00:00
|
|
|
|
2018-06-12 14:11:12 +00:00
|
|
|
void test_draw_op(GrContext* context,
|
|
|
|
GrRenderTargetContext* rtc,
|
|
|
|
std::unique_ptr<GrFragmentProcessor> fp,
|
2020-02-11 16:54:55 +00:00
|
|
|
GrSurfaceProxyView inputDataView,
|
2019-11-23 00:09:27 +00:00
|
|
|
SkAlphaType inputAlphaType) {
|
2017-02-09 16:16:46 +00:00
|
|
|
GrPaint paint;
|
2020-02-11 16:54:55 +00:00
|
|
|
paint.addColorFragmentProcessor(GrTextureEffect::Make(std::move(inputDataView),
|
|
|
|
inputAlphaType));
|
2017-02-09 16:16:46 +00:00
|
|
|
paint.addColorFragmentProcessor(std::move(fp));
|
|
|
|
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
|
2017-05-08 14:43:33 +00:00
|
|
|
|
2019-05-29 18:43:13 +00:00
|
|
|
auto op = GrFillRectOp::MakeNonAARect(context, std::move(paint), SkMatrix::I(),
|
|
|
|
SkRect::MakeWH(rtc->width(), rtc->height()));
|
2019-11-23 00:09:27 +00:00
|
|
|
rtc->priv().testingOnly_addDrawOp(std::move(op));
|
2017-02-09 16:16:46 +00:00
|
|
|
}
|
|
|
|
|
2020-02-11 16:54:55 +00:00
|
|
|
// This assumes that the output buffer will be the same size as inputDataView
|
2020-06-18 18:16:00 +00:00
|
|
|
void render_fp(GrContext* context,
|
|
|
|
GrRenderTargetContext* rtc,
|
|
|
|
std::unique_ptr<GrFragmentProcessor> fp,
|
|
|
|
GrSurfaceProxyView inputDataView,
|
|
|
|
SkAlphaType inputAlphaType,
|
|
|
|
GrColor* buffer) {
|
|
|
|
test_draw_op(context, rtc, std::move(fp), inputDataView, inputAlphaType);
|
2020-02-11 16:54:55 +00:00
|
|
|
memset(buffer, 0x0,
|
|
|
|
sizeof(GrColor) * inputDataView.proxy()->width() * inputDataView.proxy()->height());
|
|
|
|
rtc->readPixels(SkImageInfo::Make(inputDataView.proxy()->dimensions(), kRGBA_8888_SkColorType,
|
2019-10-22 14:37:46 +00:00
|
|
|
kPremul_SkAlphaType),
|
2019-07-01 17:05:28 +00:00
|
|
|
buffer, 0, {0, 0});
|
2018-10-08 20:43:58 +00:00
|
|
|
}
|
|
|
|
|
2017-07-25 13:43:22 +00:00
|
|
|
/** Initializes the two test texture proxies that are available to the FP test factories. */
|
2019-03-29 11:26:46 +00:00
|
|
|
bool init_test_textures(GrResourceProvider* resourceProvider,
|
2020-01-28 22:02:49 +00:00
|
|
|
GrRecordingContext* context,
|
2019-03-29 11:26:46 +00:00
|
|
|
SkRandom* random,
|
2020-02-12 15:53:51 +00:00
|
|
|
GrProcessorTestData::ViewInfo views[2]) {
|
2017-07-25 13:43:22 +00:00
|
|
|
static const int kTestTextureSize = 256;
|
2017-03-17 14:58:53 +00:00
|
|
|
|
2018-01-16 13:06:32 +00:00
|
|
|
{
|
|
|
|
// Put premul data into the RGBA texture that the test FPs can optionally use.
|
2020-01-28 22:02:49 +00:00
|
|
|
GrColor* rgbaData = new GrColor[kTestTextureSize * kTestTextureSize];
|
2018-01-16 13:06:32 +00:00
|
|
|
for (int y = 0; y < kTestTextureSize; ++y) {
|
|
|
|
for (int x = 0; x < kTestTextureSize; ++x) {
|
2018-10-08 20:43:58 +00:00
|
|
|
rgbaData[kTestTextureSize * y + x] = input_texel_color(
|
|
|
|
random->nextULessThan(256), random->nextULessThan(256), 0.0f);
|
2018-01-16 13:06:32 +00:00
|
|
|
}
|
2017-07-25 13:43:22 +00:00
|
|
|
}
|
2018-01-16 13:06:32 +00:00
|
|
|
|
2018-09-12 14:19:41 +00:00
|
|
|
SkImageInfo ii = SkImageInfo::Make(kTestTextureSize, kTestTextureSize,
|
|
|
|
kRGBA_8888_SkColorType, kPremul_SkAlphaType);
|
2020-01-28 22:02:49 +00:00
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.installPixels(ii, rgbaData, ii.minRowBytes(),
|
|
|
|
[](void* addr, void* context) { delete[] (GrColor*)addr; }, nullptr);
|
|
|
|
bitmap.setImmutable();
|
2020-03-18 14:06:13 +00:00
|
|
|
GrBitmapTextureMaker maker(context, bitmap, GrImageTexGenPolicy::kNew_Uncached_Budgeted);
|
2020-02-28 23:07:32 +00:00
|
|
|
auto view = maker.view(GrMipMapped::kNo);
|
2020-02-03 19:17:08 +00:00
|
|
|
if (!view.proxy() || !view.proxy()->instantiate(resourceProvider)) {
|
2019-12-18 15:41:58 +00:00
|
|
|
return false;
|
|
|
|
}
|
2020-02-12 15:53:51 +00:00
|
|
|
views[0] = {view, GrColorType::kRGBA_8888, kPremul_SkAlphaType};
|
2017-07-25 13:43:22 +00:00
|
|
|
}
|
2018-01-16 13:06:32 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
// Put random values into the alpha texture that the test FPs can optionally use.
|
2020-01-28 22:02:49 +00:00
|
|
|
uint8_t* alphaData = new uint8_t[kTestTextureSize * kTestTextureSize];
|
2018-01-16 13:06:32 +00:00
|
|
|
for (int y = 0; y < kTestTextureSize; ++y) {
|
|
|
|
for (int x = 0; x < kTestTextureSize; ++x) {
|
|
|
|
alphaData[kTestTextureSize * y + x] = random->nextULessThan(256);
|
|
|
|
}
|
2017-07-25 13:43:22 +00:00
|
|
|
}
|
2018-01-16 13:06:32 +00:00
|
|
|
|
2018-09-12 14:19:41 +00:00
|
|
|
SkImageInfo ii = SkImageInfo::Make(kTestTextureSize, kTestTextureSize,
|
|
|
|
kAlpha_8_SkColorType, kPremul_SkAlphaType);
|
2020-01-28 22:02:49 +00:00
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.installPixels(ii, alphaData, ii.minRowBytes(),
|
|
|
|
[](void* addr, void* context) { delete[] (uint8_t*)addr; }, nullptr);
|
|
|
|
bitmap.setImmutable();
|
2020-03-18 14:06:13 +00:00
|
|
|
GrBitmapTextureMaker maker(context, bitmap, GrImageTexGenPolicy::kNew_Uncached_Budgeted);
|
2020-02-28 23:07:32 +00:00
|
|
|
auto view = maker.view(GrMipMapped::kNo);
|
2020-02-03 19:17:08 +00:00
|
|
|
if (!view.proxy() || !view.proxy()->instantiate(resourceProvider)) {
|
2019-12-18 15:41:58 +00:00
|
|
|
return false;
|
|
|
|
}
|
2020-02-12 15:53:51 +00:00
|
|
|
views[1] = {view, GrColorType::kAlpha_8, kPremul_SkAlphaType};
|
2017-07-25 13:43:22 +00:00
|
|
|
}
|
|
|
|
|
2019-12-18 15:41:58 +00:00
|
|
|
return true;
|
2017-07-25 13:43:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Creates a texture of premul colors used as the output of the fragment processor that precedes
|
|
|
|
// the fragment processor under test. Color values are those provided by input_texel_color().
|
2020-02-11 16:54:55 +00:00
|
|
|
GrSurfaceProxyView make_input_texture(GrRecordingContext* context, int width, int height,
|
|
|
|
SkScalar delta) {
|
2020-01-28 22:02:49 +00:00
|
|
|
GrColor* data = new GrColor[width * height];
|
2017-07-25 13:43:22 +00:00
|
|
|
for (int y = 0; y < width; ++y) {
|
|
|
|
for (int x = 0; x < height; ++x) {
|
2020-01-28 22:02:49 +00:00
|
|
|
data[width * y + x] = input_texel_color(x, y, delta);
|
2017-07-25 13:43:22 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-16 13:06:32 +00:00
|
|
|
|
2018-09-12 14:19:41 +00:00
|
|
|
SkImageInfo ii = SkImageInfo::Make(width, height, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
|
2020-01-28 22:02:49 +00:00
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.installPixels(ii, data, ii.minRowBytes(),
|
|
|
|
[](void* addr, void* context) { delete[] (GrColor*)addr; }, nullptr);
|
|
|
|
bitmap.setImmutable();
|
2020-03-18 14:06:13 +00:00
|
|
|
GrBitmapTextureMaker maker(context, bitmap, GrImageTexGenPolicy::kNew_Uncached_Budgeted);
|
2020-02-28 23:07:32 +00:00
|
|
|
return maker.view(GrMipMapped::kNo);
|
2017-07-25 13:43:22 +00:00
|
|
|
}
|
2018-01-16 13:06:32 +00:00
|
|
|
|
2019-08-13 16:40:04 +00:00
|
|
|
// We tag logged data as unpremul to avoid conversion when encoding as PNG. The input texture
|
|
|
|
// actually contains unpremul data. Also, even though we made the result data by rendering into
|
|
|
|
// a "unpremul" GrRenderTargetContext, our input texture is unpremul and outside of the random
|
|
|
|
// effect configuration, we didn't do anything to ensure the output is actually premul. We just
|
|
|
|
// don't currently allow kUnpremul GrRenderTargetContexts.
|
|
|
|
static constexpr auto kLogAlphaType = kUnpremul_SkAlphaType;
|
|
|
|
|
|
|
|
bool log_pixels(GrColor* pixels, int widthHeight, SkString* dst) {
|
|
|
|
auto info = SkImageInfo::Make(widthHeight, widthHeight, kRGBA_8888_SkColorType, kLogAlphaType);
|
|
|
|
SkBitmap bmp;
|
|
|
|
bmp.installPixels(info, pixels, widthHeight * sizeof(GrColor));
|
2019-10-25 00:07:39 +00:00
|
|
|
return BipmapToBase64DataURI(bmp, dst);
|
2019-08-13 16:40:04 +00:00
|
|
|
}
|
|
|
|
|
2020-02-11 16:54:55 +00:00
|
|
|
bool log_texture_view(GrContext* context, GrSurfaceProxyView src, SkString* dst) {
|
|
|
|
SkImageInfo ii = SkImageInfo::Make(src.proxy()->dimensions(), kRGBA_8888_SkColorType,
|
|
|
|
kLogAlphaType);
|
2020-01-14 14:56:04 +00:00
|
|
|
|
2020-02-11 16:54:55 +00:00
|
|
|
auto sContext = GrSurfaceContext::Make(context, std::move(src), GrColorType::kRGBA_8888,
|
2020-01-14 14:56:04 +00:00
|
|
|
kLogAlphaType, nullptr);
|
2018-10-01 16:42:53 +00:00
|
|
|
SkBitmap bm;
|
|
|
|
SkAssertResult(bm.tryAllocPixels(ii));
|
2019-08-13 16:40:04 +00:00
|
|
|
SkAssertResult(sContext->readPixels(ii, bm.getPixels(), bm.rowBytes(), {0, 0}));
|
2019-10-25 00:07:39 +00:00
|
|
|
return BipmapToBase64DataURI(bm, dst);
|
2018-10-01 16:42:53 +00:00
|
|
|
}
|
|
|
|
|
2018-10-08 20:43:58 +00:00
|
|
|
bool fuzzy_color_equals(const SkPMColor4f& c1, const SkPMColor4f& c2) {
|
|
|
|
// With the loss of precision of rendering into 32-bit color, then estimating the FP's output
|
2019-12-17 20:20:23 +00:00
|
|
|
// from that, it is not uncommon for a valid output to differ from estimate by up to 0.01
|
2018-10-08 20:43:58 +00:00
|
|
|
// (really 1/128 ~ .0078, but frequently floating point issues make that tolerance a little
|
|
|
|
// too unforgiving).
|
2019-12-17 20:20:23 +00:00
|
|
|
static constexpr SkScalar kTolerance = 0.01f;
|
2018-10-08 20:43:58 +00:00
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
if (!SkScalarNearlyEqual(c1[i], c2[i], kTolerance)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-12-18 19:57:45 +00:00
|
|
|
// Given three input colors (color preceding the FP being tested) provided to the FP at the same
|
|
|
|
// local coord and the three corresponding FP outputs, this ensures that either:
|
|
|
|
// out[0] = fp * in[0].a, out[1] = fp * in[1].a, and out[2] = fp * in[2].a
|
|
|
|
// where fp is the pre-modulated color that should not be changing across frames (FP's state doesn't
|
|
|
|
// change), OR:
|
|
|
|
// out[0] = fp * in[0], out[1] = fp * in[1], and out[2] = fp * in[2]
|
|
|
|
// (per-channel modulation instead of modulation by just the alpha channel)
|
|
|
|
// It does this by estimating the pre-modulated fp color from one of the input/output pairs and
|
|
|
|
// confirms the conditions hold for the other two pairs.
|
|
|
|
// It is required that the three input colors have the same alpha as fp is allowed to be a function
|
|
|
|
// of the input alpha (but not r, g, or b).
|
|
|
|
bool legal_modulation(const GrColor in[3], const GrColor out[3]) {
|
2018-10-08 20:43:58 +00:00
|
|
|
// Convert to floating point, which is the number space the FP operates in (more or less)
|
2019-12-18 19:57:45 +00:00
|
|
|
SkPMColor4f inf[3], outf[3];
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
|
inf[i] = SkPMColor4f::FromBytes_RGBA(in[i]);
|
|
|
|
outf[i] = SkPMColor4f::FromBytes_RGBA(out[i]);
|
|
|
|
}
|
|
|
|
// This test is only valid if all the input alphas are the same.
|
|
|
|
SkASSERT(inf[0].fA == inf[1].fA && inf[1].fA == inf[2].fA);
|
2018-10-08 20:43:58 +00:00
|
|
|
|
|
|
|
// Reconstruct the output of the FP before the shader modulated its color with the input value.
|
|
|
|
// When the original input is very small, it may cause the final output color to round
|
|
|
|
// to 0, in which case we estimate the pre-modulated color using one of the stepped frames that
|
|
|
|
// will then have a guaranteed larger channel value (since the offset will be added to it).
|
2019-12-27 17:18:19 +00:00
|
|
|
SkPMColor4f fpPreColorModulation = {0,0,0,0};
|
|
|
|
SkPMColor4f fpPreAlphaModulation = {0,0,0,0};
|
2018-10-08 20:43:58 +00:00
|
|
|
for (int i = 0; i < 4; i++) {
|
2019-12-18 19:57:45 +00:00
|
|
|
// Use the most stepped up frame
|
|
|
|
int maxInIdx = inf[0][i] > inf[1][i] ? 0 : 1;
|
|
|
|
maxInIdx = inf[maxInIdx][i] > inf[2][i] ? maxInIdx : 2;
|
|
|
|
const auto& in = inf[maxInIdx];
|
|
|
|
const auto& out = outf[maxInIdx];
|
2019-12-27 17:18:19 +00:00
|
|
|
if (in[i] > 0) {
|
|
|
|
fpPreColorModulation[i] = out[i] / in[i];
|
|
|
|
}
|
|
|
|
if (in[3] > 0) {
|
|
|
|
fpPreAlphaModulation[i] = out[i] / in[3];
|
|
|
|
}
|
2018-10-08 20:43:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// With reconstructed pre-modulated FP output, derive the expected value of fp * input for each
|
|
|
|
// of the transformed input colors.
|
2019-12-18 19:57:45 +00:00
|
|
|
SkPMColor4f expectedForAlphaModulation[3];
|
|
|
|
SkPMColor4f expectedForColorModulation[3];
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
|
expectedForAlphaModulation[i] = fpPreAlphaModulation * inf[i].fA;
|
|
|
|
expectedForColorModulation[i] = fpPreColorModulation * inf[i];
|
|
|
|
// If the input alpha is 0 then the other channels should also be zero
|
|
|
|
// since the color is assumed to be premul. Modulating zeros by anything
|
|
|
|
// should produce zeros.
|
|
|
|
if (inf[i].fA == 0) {
|
|
|
|
SkASSERT(inf[i].fR == 0 && inf[i].fG == 0 && inf[i].fB == 0);
|
|
|
|
expectedForColorModulation[i] = expectedForAlphaModulation[i] = {0, 0, 0, 0};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isLegalColorModulation = fuzzy_color_equals(outf[0], expectedForColorModulation[0]) &&
|
|
|
|
fuzzy_color_equals(outf[1], expectedForColorModulation[1]) &&
|
|
|
|
fuzzy_color_equals(outf[2], expectedForColorModulation[2]);
|
|
|
|
|
|
|
|
bool isLegalAlphaModulation = fuzzy_color_equals(outf[0], expectedForAlphaModulation[0]) &&
|
|
|
|
fuzzy_color_equals(outf[1], expectedForAlphaModulation[1]) &&
|
|
|
|
fuzzy_color_equals(outf[2], expectedForAlphaModulation[2]);
|
|
|
|
|
|
|
|
// This can be enabled to print the values that caused this check to fail.
|
|
|
|
if (0 && !isLegalColorModulation && !isLegalAlphaModulation) {
|
|
|
|
SkDebugf("Color modulation test\n\timplied mod color: (%.03f, %.03f, %.03f, %.03f)\n",
|
|
|
|
fpPreColorModulation[0],
|
|
|
|
fpPreColorModulation[1],
|
|
|
|
fpPreColorModulation[2],
|
|
|
|
fpPreColorModulation[3]);
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
|
SkDebugf("\t(%.03f, %.03f, %.03f, %.03f) -> "
|
|
|
|
"(%.03f, %.03f, %.03f, %.03f) | "
|
|
|
|
"(%.03f, %.03f, %.03f, %.03f), ok: %d\n",
|
|
|
|
inf[i].fR, inf[i].fG, inf[i].fB, inf[i].fA,
|
|
|
|
outf[i].fR, outf[i].fG, outf[i].fB, outf[i].fA,
|
|
|
|
expectedForColorModulation[i].fR, expectedForColorModulation[i].fG,
|
|
|
|
expectedForColorModulation[i].fB, expectedForColorModulation[i].fA,
|
|
|
|
fuzzy_color_equals(outf[i], expectedForColorModulation[i]));
|
|
|
|
}
|
|
|
|
SkDebugf("Alpha modulation test\n\timplied mod color: (%.03f, %.03f, %.03f, %.03f)\n",
|
|
|
|
fpPreAlphaModulation[0],
|
|
|
|
fpPreAlphaModulation[1],
|
|
|
|
fpPreAlphaModulation[2],
|
|
|
|
fpPreAlphaModulation[3]);
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
|
SkDebugf("\t(%.03f, %.03f, %.03f, %.03f) -> "
|
|
|
|
"(%.03f, %.03f, %.03f, %.03f) | "
|
|
|
|
"(%.03f, %.03f, %.03f, %.03f), ok: %d\n",
|
|
|
|
inf[i].fR, inf[i].fG, inf[i].fB, inf[i].fA,
|
|
|
|
outf[i].fR, outf[i].fG, outf[i].fB, outf[i].fA,
|
|
|
|
expectedForAlphaModulation[i].fR, expectedForAlphaModulation[i].fG,
|
|
|
|
expectedForAlphaModulation[i].fB, expectedForAlphaModulation[i].fA,
|
|
|
|
fuzzy_color_equals(outf[i], expectedForAlphaModulation[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return isLegalColorModulation || isLegalAlphaModulation;
|
2018-10-08 20:43:58 +00:00
|
|
|
}
|
|
|
|
|
2017-02-09 16:16:46 +00:00
|
|
|
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ProcessorOptimizationValidationTest, reporter, ctxInfo) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto context = ctxInfo.directContext();
|
2019-02-04 18:26:26 +00:00
|
|
|
auto resourceProvider = context->priv().resourceProvider();
|
2017-07-24 14:16:19 +00:00
|
|
|
using FPFactory = GrFragmentProcessorTestFactory;
|
2017-03-17 14:58:53 +00:00
|
|
|
|
2018-09-28 20:00:38 +00:00
|
|
|
uint32_t seed = FLAGS_processorSeed;
|
2017-03-17 14:58:53 +00:00
|
|
|
if (FLAGS_randomProcessorTest) {
|
|
|
|
std::random_device rd;
|
|
|
|
seed = rd();
|
|
|
|
}
|
|
|
|
// If a non-deterministic bot fails this test, check the output to see what seed it used, then
|
2018-09-28 20:00:38 +00:00
|
|
|
// use --processorSeed <seed> (without --randomProcessorTest) to reproduce.
|
2017-03-17 14:58:53 +00:00
|
|
|
SkRandom random(seed);
|
|
|
|
|
2017-07-25 13:43:22 +00:00
|
|
|
// Make the destination context for the test.
|
|
|
|
static constexpr int kRenderSize = 256;
|
2020-01-08 16:52:34 +00:00
|
|
|
auto rtc = GrRenderTargetContext::Make(
|
|
|
|
context, GrColorType::kRGBA_8888, nullptr, SkBackingFit::kExact,
|
|
|
|
{kRenderSize, kRenderSize});
|
2017-02-10 17:39:26 +00:00
|
|
|
|
2020-02-12 15:53:51 +00:00
|
|
|
GrProcessorTestData::ViewInfo views[2];
|
|
|
|
if (!init_test_textures(resourceProvider, context, &random, views)) {
|
2017-07-25 13:43:22 +00:00
|
|
|
ERRORF(reporter, "Could not create test textures");
|
2017-05-29 19:05:15 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-02-12 15:53:51 +00:00
|
|
|
GrProcessorTestData testData(&random, context, 2, views);
|
2017-01-27 15:59:27 +00:00
|
|
|
|
2018-10-08 20:43:58 +00:00
|
|
|
// Coverage optimization uses three frames with a linearly transformed input texture. The first
|
|
|
|
// frame has no offset, second frames add .2 and .4, which should then be present as a fixed
|
|
|
|
// difference between the frame outputs if the FP is properly following the modulation
|
|
|
|
// requirements of the coverage optimization.
|
|
|
|
static constexpr SkScalar kInputDelta = 0.2f;
|
2020-01-28 22:02:49 +00:00
|
|
|
auto inputTexture1 = make_input_texture(context, kRenderSize, kRenderSize, 0.0f);
|
|
|
|
auto inputTexture2 = make_input_texture(context, kRenderSize, kRenderSize, kInputDelta);
|
|
|
|
auto inputTexture3 = make_input_texture(context, kRenderSize, kRenderSize, 2*kInputDelta);
|
2017-01-27 15:59:27 +00:00
|
|
|
|
2018-10-01 16:42:53 +00:00
|
|
|
// Encoded images are very verbose and this tests many potential images, so only export the
|
|
|
|
// first failure (subsequent failures have a reasonable chance of being related).
|
|
|
|
bool loggedFirstFailure = false;
|
2018-10-03 20:04:38 +00:00
|
|
|
bool loggedFirstWarning = false;
|
2018-10-08 20:43:58 +00:00
|
|
|
|
|
|
|
// Storage for the three frames required for coverage compatibility optimization. Each frame
|
|
|
|
// uses the correspondingly numbered inputTextureX.
|
|
|
|
std::unique_ptr<GrColor[]> readData1(new GrColor[kRenderSize * kRenderSize]);
|
|
|
|
std::unique_ptr<GrColor[]> readData2(new GrColor[kRenderSize * kRenderSize]);
|
|
|
|
std::unique_ptr<GrColor[]> readData3(new GrColor[kRenderSize * kRenderSize]);
|
|
|
|
|
2017-07-25 13:43:22 +00:00
|
|
|
// Because processor factories configure themselves in random ways, this is not exhaustive.
|
2017-01-27 15:59:27 +00:00
|
|
|
for (int i = 0; i < FPFactory::Count(); ++i) {
|
|
|
|
int timesToInvokeFactory = 5;
|
|
|
|
// Increase the number of attempts if the FP has child FPs since optimizations likely depend
|
|
|
|
// on child optimizations being present.
|
2017-08-11 13:40:37 +00:00
|
|
|
std::unique_ptr<GrFragmentProcessor> fp = FPFactory::MakeIdx(i, &testData);
|
2017-01-27 15:59:27 +00:00
|
|
|
for (int j = 0; j < fp->numChildProcessors(); ++j) {
|
|
|
|
// This value made a reasonable trade off between time and coverage when this test was
|
|
|
|
// written.
|
|
|
|
timesToInvokeFactory *= FPFactory::Count() / 2;
|
|
|
|
}
|
2019-02-04 15:01:53 +00:00
|
|
|
#if defined(__MSVC_RUNTIME_CHECKS)
|
|
|
|
// This test is infuriatingly slow with MSVC runtime checks enabled
|
|
|
|
timesToInvokeFactory = 1;
|
|
|
|
#endif
|
2017-01-27 15:59:27 +00:00
|
|
|
for (int j = 0; j < timesToInvokeFactory; ++j) {
|
|
|
|
fp = FPFactory::MakeIdx(i, &testData);
|
2017-05-01 17:12:20 +00:00
|
|
|
|
2017-01-27 15:59:27 +00:00
|
|
|
if (!fp->hasConstantOutputForConstantInput() && !fp->preservesOpaqueInput() &&
|
2017-02-15 15:22:23 +00:00
|
|
|
!fp->compatibleWithCoverageAsAlpha()) {
|
2017-01-27 15:59:27 +00:00
|
|
|
continue;
|
|
|
|
}
|
2017-08-11 13:40:37 +00:00
|
|
|
|
2020-06-18 18:16:00 +00:00
|
|
|
// All draws use a clone so that we can continue to query fp. ProcessorCloneTest should
|
|
|
|
// validate that clones are equivalent to the original.
|
2018-10-08 20:43:58 +00:00
|
|
|
if (fp->compatibleWithCoverageAsAlpha()) {
|
|
|
|
// 2nd and 3rd frames are only used when checking coverage optimization
|
2020-06-18 18:16:00 +00:00
|
|
|
render_fp(context, rtc.get(), fp->clone(), inputTexture2, kPremul_SkAlphaType,
|
2019-10-15 18:01:49 +00:00
|
|
|
readData2.get());
|
2020-06-18 18:16:00 +00:00
|
|
|
render_fp(context, rtc.get(), fp->clone(), inputTexture3, kPremul_SkAlphaType,
|
2019-10-15 18:01:49 +00:00
|
|
|
readData3.get());
|
2018-10-08 20:43:58 +00:00
|
|
|
}
|
2020-06-18 18:16:00 +00:00
|
|
|
|
2018-10-08 20:43:58 +00:00
|
|
|
// Draw base frame last so that rtc holds the original FP behavior if we need to
|
|
|
|
// dump the image to the log.
|
2020-06-18 18:16:00 +00:00
|
|
|
render_fp(context, rtc.get(), fp->clone(), inputTexture1, kPremul_SkAlphaType,
|
2019-10-15 18:01:49 +00:00
|
|
|
readData1.get());
|
2017-08-11 13:40:37 +00:00
|
|
|
|
2018-10-03 20:04:38 +00:00
|
|
|
// This test has a history of being flaky on a number of devices. If an FP is logically
|
|
|
|
// violating the optimizations, it's reasonable to expect it to violate requirements on
|
|
|
|
// a large number of pixels in the image. Sporadic pixel violations are more indicative
|
|
|
|
// of device errors and represents a separate problem.
|
2018-12-10 17:43:36 +00:00
|
|
|
#if defined(SK_BUILD_FOR_SKQP)
|
2018-10-03 20:04:38 +00:00
|
|
|
static constexpr int kMaxAcceptableFailedPixels = 0; // Strict when running as SKQP
|
|
|
|
#else
|
|
|
|
static constexpr int kMaxAcceptableFailedPixels = 2 * kRenderSize; // ~0.7% of the image
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int failedPixelCount = 0;
|
|
|
|
// Collect first optimization failure message, to be output later as a warning or an
|
|
|
|
// error depending on whether the rendering "passed" or failed.
|
|
|
|
SkString coverageMessage;
|
|
|
|
SkString opaqueMessage;
|
|
|
|
SkString constMessage;
|
|
|
|
for (int y = 0; y < kRenderSize; ++y) {
|
|
|
|
for (int x = 0; x < kRenderSize; ++x) {
|
|
|
|
bool passing = true;
|
2018-10-08 20:43:58 +00:00
|
|
|
GrColor input = input_texel_color(x, y, 0.0f);
|
|
|
|
GrColor output = readData1.get()[y * kRenderSize + x];
|
|
|
|
|
|
|
|
if (fp->compatibleWithCoverageAsAlpha()) {
|
2019-12-18 19:57:45 +00:00
|
|
|
GrColor ins[3];
|
|
|
|
ins[0] = input;
|
|
|
|
ins[1] = input_texel_color(x, y, kInputDelta);
|
|
|
|
ins[2] = input_texel_color(x, y, 2 * kInputDelta);
|
2018-10-08 20:43:58 +00:00
|
|
|
|
2019-12-18 19:57:45 +00:00
|
|
|
GrColor outs[3];
|
|
|
|
outs[0] = output;
|
|
|
|
outs[1] = readData2.get()[y * kRenderSize + x];
|
|
|
|
outs[2] = readData3.get()[y * kRenderSize + x];
|
2018-10-08 20:43:58 +00:00
|
|
|
|
2019-12-18 19:57:45 +00:00
|
|
|
if (!legal_modulation(ins, outs)) {
|
2017-01-27 15:59:27 +00:00
|
|
|
passing = false;
|
2018-10-03 20:04:38 +00:00
|
|
|
if (coverageMessage.isEmpty()) {
|
2019-12-18 19:57:45 +00:00
|
|
|
coverageMessage.printf(
|
|
|
|
"\"Modulating\" processor %s did not match "
|
2018-10-08 20:43:58 +00:00
|
|
|
"alpha-modulation nor color-modulation rules. "
|
|
|
|
"Input: 0x%08x, Output: 0x%08x, pixel (%d, %d).",
|
|
|
|
fp->name(), input, output, x, y);
|
2018-10-03 20:04:38 +00:00
|
|
|
}
|
2017-01-27 15:59:27 +00:00
|
|
|
}
|
|
|
|
}
|
2018-10-08 20:43:58 +00:00
|
|
|
|
2018-10-16 19:19:28 +00:00
|
|
|
SkPMColor4f input4f = SkPMColor4f::FromBytes_RGBA(input);
|
|
|
|
SkPMColor4f output4f = SkPMColor4f::FromBytes_RGBA(output);
|
2018-10-01 17:41:39 +00:00
|
|
|
SkPMColor4f expected4f;
|
2018-10-08 20:43:58 +00:00
|
|
|
if (fp->hasConstantOutputForConstantInput(input4f, &expected4f)) {
|
2018-10-16 19:19:28 +00:00
|
|
|
float rDiff = fabsf(output4f.fR - expected4f.fR);
|
|
|
|
float gDiff = fabsf(output4f.fG - expected4f.fG);
|
|
|
|
float bDiff = fabsf(output4f.fB - expected4f.fB);
|
|
|
|
float aDiff = fabsf(output4f.fA - expected4f.fA);
|
2017-02-09 16:16:46 +00:00
|
|
|
static constexpr float kTol = 4 / 255.f;
|
2017-01-27 15:59:27 +00:00
|
|
|
if (rDiff > kTol || gDiff > kTol || bDiff > kTol || aDiff > kTol) {
|
2018-10-03 20:04:38 +00:00
|
|
|
if (constMessage.isEmpty()) {
|
|
|
|
passing = false;
|
|
|
|
|
|
|
|
constMessage.printf("Processor %s claimed output for const input "
|
|
|
|
"doesn't match actual output. Error: %f, Tolerance: %f, "
|
|
|
|
"input: (%f, %f, %f, %f), actual: (%f, %f, %f, %f), "
|
2018-10-08 20:43:58 +00:00
|
|
|
"expected(%f, %f, %f, %f)", fp->name(),
|
2020-02-07 15:36:46 +00:00
|
|
|
std::max(rDiff, std::max(gDiff, std::max(bDiff, aDiff))), kTol,
|
2018-10-03 20:04:38 +00:00
|
|
|
input4f.fR, input4f.fG, input4f.fB, input4f.fA,
|
2018-10-16 19:19:28 +00:00
|
|
|
output4f.fR, output4f.fG, output4f.fB, output4f.fA,
|
|
|
|
expected4f.fR, expected4f.fG, expected4f.fB, expected4f.fA);
|
2018-10-03 20:04:38 +00:00
|
|
|
}
|
2017-01-27 15:59:27 +00:00
|
|
|
}
|
|
|
|
}
|
2018-11-05 20:42:43 +00:00
|
|
|
if (input4f.isOpaque() && fp->preservesOpaqueInput() && !output4f.isOpaque()) {
|
2017-01-27 15:59:27 +00:00
|
|
|
passing = false;
|
2018-10-03 20:04:38 +00:00
|
|
|
|
|
|
|
if (opaqueMessage.isEmpty()) {
|
|
|
|
opaqueMessage.printf("Processor %s claimed opaqueness is preserved but "
|
|
|
|
"it is not. Input: 0x%08x, Output: 0x%08x.",
|
2018-10-08 20:43:58 +00:00
|
|
|
fp->name(), input, output);
|
2018-10-03 20:04:38 +00:00
|
|
|
}
|
2017-01-27 15:59:27 +00:00
|
|
|
}
|
2018-10-03 20:04:38 +00:00
|
|
|
|
2017-03-15 15:33:12 +00:00
|
|
|
if (!passing) {
|
2018-10-03 20:04:38 +00:00
|
|
|
// Regardless of how many optimizations the pixel violates, count it as a
|
|
|
|
// single bad pixel.
|
|
|
|
failedPixelCount++;
|
2017-03-15 15:33:12 +00:00
|
|
|
}
|
2017-01-27 15:59:27 +00:00
|
|
|
}
|
|
|
|
}
|
2018-10-03 20:04:38 +00:00
|
|
|
|
|
|
|
// Finished analyzing the entire image, see if the number of pixel failures meets the
|
|
|
|
// threshold for an FP violating the optimization requirements.
|
|
|
|
if (failedPixelCount > kMaxAcceptableFailedPixels) {
|
2018-10-03 20:47:55 +00:00
|
|
|
ERRORF(reporter, "Processor violated %d of %d pixels, seed: 0x%08x, processor: %s"
|
2018-10-03 20:04:38 +00:00
|
|
|
", first failing pixel details are below:",
|
|
|
|
failedPixelCount, kRenderSize * kRenderSize, seed,
|
2018-10-08 20:43:58 +00:00
|
|
|
fp->dumpInfo().c_str());
|
2018-10-03 20:04:38 +00:00
|
|
|
|
|
|
|
// Print first failing pixel's details.
|
|
|
|
if (!coverageMessage.isEmpty()) {
|
|
|
|
ERRORF(reporter, coverageMessage.c_str());
|
|
|
|
}
|
|
|
|
if (!constMessage.isEmpty()) {
|
|
|
|
ERRORF(reporter, constMessage.c_str());
|
|
|
|
}
|
|
|
|
if (!opaqueMessage.isEmpty()) {
|
|
|
|
ERRORF(reporter, opaqueMessage.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!loggedFirstFailure) {
|
|
|
|
// Print with ERRORF to make sure the encoded image is output
|
|
|
|
SkString input;
|
2020-02-11 16:54:55 +00:00
|
|
|
log_texture_view(context, inputTexture1, &input);
|
2018-10-03 20:04:38 +00:00
|
|
|
SkString output;
|
2019-08-13 16:40:04 +00:00
|
|
|
log_pixels(readData1.get(), kRenderSize, &output);
|
2018-10-03 20:04:38 +00:00
|
|
|
ERRORF(reporter, "Input image: %s\n\n"
|
|
|
|
"===========================================================\n\n"
|
|
|
|
"Output image: %s\n", input.c_str(), output.c_str());
|
|
|
|
loggedFirstFailure = true;
|
|
|
|
}
|
2018-10-08 20:43:58 +00:00
|
|
|
} else if(failedPixelCount > 0) {
|
2018-10-03 20:04:38 +00:00
|
|
|
// Don't trigger an error, but don't just hide the failures either.
|
|
|
|
INFOF(reporter, "Processor violated %d of %d pixels (below error threshold), seed: "
|
|
|
|
"0x%08x, processor: %s", failedPixelCount, kRenderSize * kRenderSize,
|
2018-10-08 20:43:58 +00:00
|
|
|
seed, fp->dumpInfo().c_str());
|
2018-10-03 20:04:38 +00:00
|
|
|
if (!coverageMessage.isEmpty()) {
|
|
|
|
INFOF(reporter, coverageMessage.c_str());
|
|
|
|
}
|
|
|
|
if (!constMessage.isEmpty()) {
|
|
|
|
INFOF(reporter, constMessage.c_str());
|
|
|
|
}
|
|
|
|
if (!opaqueMessage.isEmpty()) {
|
|
|
|
INFOF(reporter, opaqueMessage.c_str());
|
|
|
|
}
|
|
|
|
if (!loggedFirstWarning) {
|
|
|
|
SkString input;
|
2020-02-11 16:54:55 +00:00
|
|
|
log_texture_view(context, inputTexture1, &input);
|
2018-10-03 20:04:38 +00:00
|
|
|
SkString output;
|
2019-08-13 16:40:04 +00:00
|
|
|
log_pixels(readData1.get(), kRenderSize, &output);
|
2018-10-03 20:04:38 +00:00
|
|
|
INFOF(reporter, "Input image: %s\n\n"
|
|
|
|
"===========================================================\n\n"
|
|
|
|
"Output image: %s\n", input.c_str(), output.c_str());
|
|
|
|
loggedFirstWarning = true;
|
|
|
|
}
|
|
|
|
}
|
2017-01-27 15:59:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-01 16:55:44 +00:00
|
|
|
|
2020-06-15 19:07:19 +00:00
|
|
|
static void describe_fp_children(const GrFragmentProcessor& fp,
|
|
|
|
std::string indent,
|
|
|
|
SkString* text) {
|
|
|
|
for (int index = 0; index < fp.numChildProcessors(); ++index) {
|
|
|
|
const GrFragmentProcessor& childFP = fp.childProcessor(index);
|
|
|
|
text->appendf("\n%s(#%d) -> %s", indent.c_str(), index, childFP.name());
|
|
|
|
describe_fp_children(childFP, indent + "\t", text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static SkString describe_fp(const GrFragmentProcessor& fp) {
|
|
|
|
SkString text;
|
|
|
|
text.printf("\n%s", fp.name());
|
|
|
|
describe_fp_children(fp, "\t", &text);
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2020-06-18 18:16:00 +00:00
|
|
|
// Tests that a fragment processor returned by GrFragmentProcessor::clone() is equivalent to its
|
|
|
|
// progenitor.
|
2017-07-25 13:43:22 +00:00
|
|
|
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ProcessorCloneTest, reporter, ctxInfo) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto context = ctxInfo.directContext();
|
2019-02-04 18:26:26 +00:00
|
|
|
auto resourceProvider = context->priv().resourceProvider();
|
2017-07-25 13:43:22 +00:00
|
|
|
|
|
|
|
SkRandom random;
|
|
|
|
|
|
|
|
// Make the destination context for the test.
|
|
|
|
static constexpr int kRenderSize = 1024;
|
2020-01-08 16:52:34 +00:00
|
|
|
auto rtc = GrRenderTargetContext::Make(
|
|
|
|
context, GrColorType::kRGBA_8888, nullptr, SkBackingFit::kExact,
|
|
|
|
{kRenderSize, kRenderSize});
|
2017-07-25 13:43:22 +00:00
|
|
|
|
2020-02-12 15:53:51 +00:00
|
|
|
GrProcessorTestData::ViewInfo views[2];
|
|
|
|
if (!init_test_textures(resourceProvider, context, &random, views)) {
|
2017-07-25 13:43:22 +00:00
|
|
|
ERRORF(reporter, "Could not create test textures");
|
|
|
|
return;
|
|
|
|
}
|
2020-02-12 15:53:51 +00:00
|
|
|
GrProcessorTestData testData(&random, context, 2, views);
|
2017-07-25 13:43:22 +00:00
|
|
|
|
2020-01-28 22:02:49 +00:00
|
|
|
auto inputTexture = make_input_texture(context, kRenderSize, kRenderSize, 0.0f);
|
2017-07-25 13:43:22 +00:00
|
|
|
std::unique_ptr<GrColor[]> readData1(new GrColor[kRenderSize * kRenderSize]);
|
|
|
|
std::unique_ptr<GrColor[]> readData2(new GrColor[kRenderSize * kRenderSize]);
|
2019-08-13 16:40:04 +00:00
|
|
|
// On failure we write out images, but just write the first failing set as the print is very
|
|
|
|
// large.
|
|
|
|
bool loggedFirstFailure = false;
|
|
|
|
|
|
|
|
// This test has a history of being flaky on a number of devices. If an FP clone is logically
|
|
|
|
// wrong, it's reasonable to expect it produce a large number of pixel differences in the image
|
|
|
|
// Sporadic pixel violations are more indicative device errors and represents a separate
|
|
|
|
// problem.
|
|
|
|
#if defined(SK_BUILD_FOR_SKQP)
|
|
|
|
static constexpr int kMaxAcceptableFailedPixels = 0; // Strict when running as SKQP
|
|
|
|
#else
|
|
|
|
static constexpr int kMaxAcceptableFailedPixels = 2 * kRenderSize; // ~0.7% of the image
|
|
|
|
#endif
|
2017-07-25 13:43:22 +00:00
|
|
|
|
|
|
|
// Because processor factories configure themselves in random ways, this is not exhaustive.
|
|
|
|
for (int i = 0; i < GrFragmentProcessorTestFactory::Count(); ++i) {
|
|
|
|
static constexpr int kTimesToInvokeFactory = 10;
|
|
|
|
for (int j = 0; j < kTimesToInvokeFactory; ++j) {
|
2020-06-15 19:07:19 +00:00
|
|
|
std::unique_ptr<GrFragmentProcessor> fp =
|
|
|
|
GrFragmentProcessorTestFactory::MakeIdx(i, &testData);
|
|
|
|
std::unique_ptr<GrFragmentProcessor> clone = fp->clone();
|
2017-07-25 13:43:22 +00:00
|
|
|
if (!clone) {
|
2017-07-31 20:27:23 +00:00
|
|
|
ERRORF(reporter, "Clone of processor %s failed.", fp->name());
|
2017-07-25 13:43:22 +00:00
|
|
|
continue;
|
|
|
|
}
|
2017-08-11 13:40:37 +00:00
|
|
|
const char* name = fp->name();
|
2020-06-15 19:07:19 +00:00
|
|
|
REPORTER_ASSERT(reporter, !strcmp(fp->name(), clone->name()),
|
|
|
|
"%s\n", describe_fp(*fp).c_str());
|
2017-08-01 20:23:40 +00:00
|
|
|
REPORTER_ASSERT(reporter, fp->compatibleWithCoverageAsAlpha() ==
|
2020-06-15 19:07:19 +00:00
|
|
|
clone->compatibleWithCoverageAsAlpha(),
|
|
|
|
"%s\n", describe_fp(*fp).c_str());
|
|
|
|
REPORTER_ASSERT(reporter, fp->isEqual(*clone),
|
|
|
|
"%s\n", describe_fp(*fp).c_str());
|
|
|
|
REPORTER_ASSERT(reporter, fp->preservesOpaqueInput() == clone->preservesOpaqueInput(),
|
|
|
|
"%s\n", describe_fp(*fp).c_str());
|
2017-08-01 20:23:40 +00:00
|
|
|
REPORTER_ASSERT(reporter, fp->hasConstantOutputForConstantInput() ==
|
2020-06-15 19:07:19 +00:00
|
|
|
clone->hasConstantOutputForConstantInput(),
|
|
|
|
"%s\n", describe_fp(*fp).c_str());
|
|
|
|
REPORTER_ASSERT(reporter, fp->numChildProcessors() == clone->numChildProcessors(),
|
|
|
|
"%s\n", describe_fp(*fp).c_str());
|
2020-07-01 21:21:27 +00:00
|
|
|
REPORTER_ASSERT(reporter, fp->usesVaryingCoords() == clone->usesVaryingCoords(),
|
Update how sample(matrix) calls are invoked in SkSL
This removes the kMixed type of SkSL::SampleMatrix. All analysis of FP
sampling due to parent-child relationships is tracked in flags on
GrFragmentProcessor now.
The sample strategy is tracked as follows:
- An FP marks itself as using the local coordinate builtin directly (automatically done for .fp code based on reference to sk_TransformedCoords2D[0]).
- This state propagates up the parent towards the root, marking FPs as using coordinates indirectly. We stop the propagation when we hit a parent FP that explicitly samples the child because it becomes the source of the child's coordinates.
- If that parent references its local coordinates directly, that kicks off its own upwards propagation.
- Being sampled explicitly propagates down to all children, and effectively disables vertex-shader evaluation of transforms.
- A variable matrix automatically marks this flag as well, since it's essentially a shortcut to (matrix expression) * coords.
- The matrix type also propagates down, but right now that's only for whether or not there's perspective.
- This doesn't affect FS coord evaluation since each FP applies its action independently.
- But for VS-promoted transforms, the child's varying may inherit perspective (or other more general matrix types) from the parent and switch from a float2 to a float3.
- A SampleMatrix no longer tracks a base or owner, GrFragmentProcessor exposes its parent FP. An FP's sample matrix is always owned by its immediate parent.
- This means that you can have a hierarchy from root to leaf like: [uniform, none, none, uses local coords], and that leaf will have a SampleMatrix of kNone type. However, because of parent tracking, the coordinate generation can walk up to the root and detect the proper transform expression it needs to produce, and automatically de-duplicate across children.
Currently, all FP's that are explicitly sampled have a signature of (color, float2 coord). FP's that don't use local coords, or whose coords are promoted to a varying have a signature of (color).
- In this case, the shader builder either updates args.fLocalCoords to point to the varying directly, or adds a float2 local to the function body that includes the perspective divide.
GrFragmentProcessor automatically pretends it has an identity coord transform if the FP is marked as referencing the local coord builtin. This allows these FPs to still be processed as part of GrGLSLGeometryProcessor::collectTransforms, but removes the need for FP implementations to declare an identity GrCoordTransform.
- To test this theory, GrTextureEffect and GrSkSLFP no longer have coord transforms explicitly.
- Later CLs can trivially remove them from a lot of the other effects.
- The coord generation should not change because it detects in both cases that the coord transform matrices were identity.
GrGLSLGeometryProcessor's collectTransforms and emitTransformCode has been completely overhauled to recurse up an FP's parent pointers and collect the expressions that affect the result. It de-duplicates expressions between siblings, and is able to produce a single varying for the base local coord (either when there are no intervening transforms, or the root FP needs an explicit coordinate to start off with).
This also adds the fp_sample_chaining GM from Brian, with a few more configurations to fill out the cells.
Bug: skia:10396
Change-Id: I86acc0c34c9f29d6371b34370bee9a18c2acf1c1
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/297868
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2020-06-24 13:04:56 +00:00
|
|
|
"%s\n", describe_fp(*fp).c_str());
|
|
|
|
REPORTER_ASSERT(reporter, fp->referencesSampleCoords() ==
|
|
|
|
clone->referencesSampleCoords(),
|
2020-06-15 19:07:19 +00:00
|
|
|
"%s\n", describe_fp(*fp).c_str());
|
2017-07-25 13:43:22 +00:00
|
|
|
// Draw with original and read back the results.
|
2020-06-18 18:16:00 +00:00
|
|
|
render_fp(context, rtc.get(), std::move(fp), inputTexture, kPremul_SkAlphaType,
|
2019-10-15 18:01:49 +00:00
|
|
|
readData1.get());
|
2017-07-25 13:43:22 +00:00
|
|
|
|
|
|
|
// Draw with clone and read back the results.
|
2020-06-18 18:16:00 +00:00
|
|
|
render_fp(context, rtc.get(), std::move(clone), inputTexture, kPremul_SkAlphaType,
|
2019-10-15 18:01:49 +00:00
|
|
|
readData2.get());
|
2017-07-25 13:43:22 +00:00
|
|
|
|
|
|
|
// Check that the results are the same.
|
|
|
|
bool passing = true;
|
2019-08-13 16:40:04 +00:00
|
|
|
int failedPixelCount = 0;
|
|
|
|
int firstWrongX = 0;
|
|
|
|
int firstWrongY = 0;
|
2017-07-25 13:43:22 +00:00
|
|
|
for (int y = 0; y < kRenderSize && passing; ++y) {
|
|
|
|
for (int x = 0; x < kRenderSize && passing; ++x) {
|
|
|
|
int idx = y * kRenderSize + x;
|
|
|
|
if (readData1[idx] != readData2[idx]) {
|
2019-08-13 16:40:04 +00:00
|
|
|
if (!failedPixelCount) {
|
|
|
|
firstWrongX = x;
|
|
|
|
firstWrongY = y;
|
|
|
|
}
|
|
|
|
++failedPixelCount;
|
|
|
|
}
|
|
|
|
if (failedPixelCount > kMaxAcceptableFailedPixels) {
|
|
|
|
passing = false;
|
|
|
|
idx = firstWrongY * kRenderSize + firstWrongX;
|
2017-07-25 13:43:22 +00:00
|
|
|
ERRORF(reporter,
|
2019-08-13 16:40:04 +00:00
|
|
|
"Processor %s made clone produced different output at (%d, %d). "
|
2017-07-25 13:43:22 +00:00
|
|
|
"Input color: 0x%08x, Original Output Color: 0x%08x, "
|
2019-08-13 16:40:04 +00:00
|
|
|
"Clone Output Color: 0x%08x.",
|
|
|
|
name, firstWrongX, firstWrongY, input_texel_color(x, y, 0.0f),
|
|
|
|
readData1[idx], readData2[idx]);
|
|
|
|
if (!loggedFirstFailure) {
|
|
|
|
// Write the images out as data urls for inspection.
|
|
|
|
// We mark the data as unpremul to avoid conversion when encoding as
|
|
|
|
// PNG. Also, even though we made the data by rendering into
|
|
|
|
// a "unpremul" GrRenderTargetContext, our input texture is unpremul and
|
|
|
|
// outside of the random effect configuration, we didn't do anything to
|
|
|
|
// ensure the output is actually premul.
|
|
|
|
auto info = SkImageInfo::Make(kRenderSize, kRenderSize,
|
|
|
|
kRGBA_8888_SkColorType,
|
|
|
|
kUnpremul_SkAlphaType);
|
2020-06-18 18:16:00 +00:00
|
|
|
SkString inputURL, origURL, cloneURL;
|
|
|
|
if (log_texture_view(context, inputTexture, &inputURL) &&
|
|
|
|
log_pixels(readData1.get(), kRenderSize, &origURL) &&
|
|
|
|
log_pixels(readData2.get(), kRenderSize, &cloneURL)) {
|
2019-08-13 16:40:04 +00:00
|
|
|
ERRORF(reporter,
|
|
|
|
"\nInput image:\n%s\n\n"
|
|
|
|
"==========================================================="
|
|
|
|
"\n\n"
|
|
|
|
"Orig output image:\n%s\n"
|
|
|
|
"==========================================================="
|
|
|
|
"\n\n"
|
|
|
|
"Clone output image:\n%s\n",
|
2020-06-18 18:16:00 +00:00
|
|
|
inputURL.c_str(), origURL.c_str(), cloneURL.c_str());
|
2019-08-13 16:40:04 +00:00
|
|
|
loggedFirstFailure = true;
|
|
|
|
}
|
|
|
|
}
|
2017-07-25 13:43:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-31 18:50:44 +00:00
|
|
|
#endif // GR_TEST_UTILS
|