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"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrClip.h"
|
2020-10-14 15:23:11 +00:00
|
|
|
#include "src/gpu/GrDirectContextPriv.h"
|
2021-08-11 17:01:06 +00:00
|
|
|
#include "src/gpu/GrFragmentProcessor.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/GrResourceProvider.h"
|
2021-12-20 17:37:56 +00:00
|
|
|
#include "src/gpu/KeyBuilder.h"
|
2021-04-28 16:39:21 +00:00
|
|
|
#include "src/gpu/SkGr.h"
|
2021-07-06 20:28:52 +00:00
|
|
|
#include "src/gpu/effects/GrTextureEffect.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
|
|
|
|
#include "src/gpu/ops/GrMeshDrawOp.h"
|
2021-07-28 19:13:20 +00:00
|
|
|
#include "src/gpu/v1/SurfaceDrawContext_v1.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tests/TestUtils.h"
|
2020-12-09 21:37:04 +00:00
|
|
|
|
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
|
2020-10-07 20:46:15 +00:00
|
|
|
static GrOp::Owner Make(GrRecordingContext* rContext,
|
|
|
|
std::unique_ptr<GrFragmentProcessor> fp) {
|
|
|
|
return GrOp::Make<TestOp>(rContext, 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"; }
|
|
|
|
|
2021-06-17 13:23:58 +00:00
|
|
|
void visitProxies(const GrVisitProxyFunc& 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; }
|
|
|
|
|
2021-04-22 18:57:28 +00:00
|
|
|
GrProcessorSet::Analysis finalize(const GrCaps& caps, const GrAppliedClip* clip,
|
|
|
|
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,
|
2021-04-22 18:57:28 +00:00
|
|
|
&GrUserStencilSettings::kUnused, caps, clampType, &overrideColor);
|
2017-03-09 18:50:43 +00:00
|
|
|
}
|
2017-01-11 15:32:34 +00:00
|
|
|
|
|
|
|
private:
|
2020-10-07 20:46:15 +00:00
|
|
|
friend class ::GrOp; // for ctor
|
2018-06-12 14:11:12 +00:00
|
|
|
|
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-11-19 18:41:26 +00:00
|
|
|
const GrSurfaceProxyView& writeView,
|
2021-07-13 19:26:39 +00:00
|
|
|
bool usesMSAASurface,
|
2020-03-11 19:55:55 +00:00
|
|
|
GrAppliedClip&&,
|
2021-06-02 15:58:05 +00:00
|
|
|
const GrDstProxyView&,
|
2020-11-20 15:22:43 +00:00
|
|
|
GrXferBarrierFlags renderPassXferBarriers,
|
|
|
|
GrLoadOp colorLoadOp) override {}
|
2020-03-12 16:07:19 +00:00
|
|
|
void onPrePrepareDraws(GrRecordingContext*,
|
2020-11-19 18:41:26 +00:00
|
|
|
const GrSurfaceProxyView& writeView,
|
2020-03-12 16:07:19 +00:00
|
|
|
GrAppliedClip*,
|
2021-06-02 15:58:05 +00:00
|
|
|
const GrDstProxyView&,
|
2020-11-20 15:22:43 +00:00
|
|
|
GrXferBarrierFlags renderPassXferBarriers,
|
|
|
|
GrLoadOp colorLoadOp) override {}
|
2021-06-17 18:55:07 +00:00
|
|
|
void onPrepareDraws(GrMeshDrawTarget*) 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;
|
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = GrMeshDrawOp;
|
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"; }
|
|
|
|
|
2021-12-20 17:37:56 +00:00
|
|
|
void onAddToKey(const GrShaderCaps&, skgpu::KeyBuilder* 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-07-20 17:48:02 +00:00
|
|
|
for (const GrSurfaceProxyView& 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
|
|
|
}
|
|
|
|
|
2021-08-09 19:36:59 +00:00
|
|
|
explicit TestFP(const TestFP& that) : INHERITED(that) {}
|
2017-07-28 17:41:51 +00:00
|
|
|
|
2021-08-09 15:23:04 +00:00
|
|
|
std::unique_ptr<ProgramImpl> onMakeProgramImpl() const override {
|
2021-08-10 17:56:13 +00:00
|
|
|
class Impl : public ProgramImpl {
|
2017-01-11 15:32:34 +00:00
|
|
|
public:
|
|
|
|
void emitCode(EmitArgs& args) override {
|
2020-12-15 14:47:26 +00:00
|
|
|
args.fFragBuilder->codeAppendf("return half4(1);");
|
2017-01-11 15:32:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
};
|
2021-08-10 17:56:13 +00:00
|
|
|
return std::make_unique<Impl>();
|
2017-01-11 15:32:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool onIsEqual(const GrFragmentProcessor&) const override { return false; }
|
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = GrFragmentProcessor;
|
2017-01-11 15:32:34 +00:00
|
|
|
};
|
2020-08-06 18:11:56 +00:00
|
|
|
} // namespace
|
2017-01-11 15:32:34 +00:00
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_ALL_CONTEXTS(ProcessorRefTest, reporter, ctxInfo) {
|
2021-07-28 19:13:20 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
|
|
|
GrProxyProvider* proxyProvider = dContext->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 =
|
2021-07-28 19:13:20 +00:00
|
|
|
dContext->priv().caps()->getDefaultBackendFormat(GrColorType::kRGBA_8888,
|
|
|
|
GrRenderable::kNo);
|
2022-02-15 21:30:59 +00:00
|
|
|
skgpu::Swizzle swizzle = dContext->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++) {
|
2021-07-28 19:13:20 +00:00
|
|
|
auto sdc = skgpu::v1::SurfaceDrawContext::Make(
|
|
|
|
dContext, GrColorType::kRGBA_8888, nullptr, SkBackingFit::kApprox, {1, 1},
|
2021-04-19 23:27:09 +00:00
|
|
|
SkSurfaceProps());
|
2017-01-11 15:32:34 +00:00
|
|
|
{
|
2019-06-11 12:08:08 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
|
2020-07-21 13:27:25 +00:00
|
|
|
format, kDims, GrRenderable::kNo, 1, GrMipmapped::kNo, SkBackingFit::kExact,
|
2020-03-27 00:37:01 +00:00
|
|
|
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();
|
|
|
|
}
|
2021-07-28 19:13:20 +00:00
|
|
|
GrOp::Owner op = TestOp::Make(dContext, std::move(fp));
|
|
|
|
sdc->addDrawOp(std::move(op));
|
2017-07-28 17:41:51 +00:00
|
|
|
if (clone) {
|
2021-07-28 19:13:20 +00:00
|
|
|
op = TestOp::Make(dContext, std::move(clone));
|
|
|
|
sdc->addDrawOp(std::move(op));
|
2017-07-28 17:41:51 +00:00
|
|
|
}
|
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
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
dContext->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
|
|
|
|
|
2021-08-13 03:01:41 +00:00
|
|
|
static GrColor input_texel_color(int x, int y, SkScalar delta) {
|
2018-10-08 20:43:58 +00:00
|
|
|
// 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
|
|
|
|
2021-08-13 03:01:41 +00:00
|
|
|
SkColor color = SkColorSetARGB((uint8_t)(x & 0xFF),
|
|
|
|
(uint8_t)(y & 0xFF),
|
|
|
|
(uint8_t)((x + y) & 0xFF),
|
|
|
|
(uint8_t)((2 * y - x) & 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
|
|
|
|
2020-07-20 15:45:58 +00:00
|
|
|
// The output buffer must be the same size as the render-target context.
|
2021-08-13 03:01:41 +00:00
|
|
|
static void render_fp(GrDirectContext* dContext,
|
|
|
|
skgpu::v1::SurfaceDrawContext* sdc,
|
|
|
|
std::unique_ptr<GrFragmentProcessor> fp,
|
|
|
|
GrColor* outBuffer) {
|
2021-07-07 18:15:12 +00:00
|
|
|
sdc->fillWithFP(std::move(fp));
|
|
|
|
std::fill_n(outBuffer, sdc->width() * sdc->height(), 0);
|
|
|
|
auto ii = SkImageInfo::Make(sdc->dimensions(), kRGBA_8888_SkColorType, kPremul_SkAlphaType);
|
|
|
|
GrPixmap resultPM(ii, outBuffer, sdc->width()*sizeof(uint32_t));
|
|
|
|
sdc->readPixels(dContext, resultPM, {0, 0});
|
2018-10-08 20:43:58 +00:00
|
|
|
}
|
|
|
|
|
2020-07-20 13:45:51 +00:00
|
|
|
// This class is responsible for reproducibly generating a random fragment processor.
|
|
|
|
// An identical randomly-designed FP can be generated as many times as needed.
|
|
|
|
class TestFPGenerator {
|
|
|
|
public:
|
|
|
|
TestFPGenerator() = delete;
|
|
|
|
TestFPGenerator(GrDirectContext* context, GrResourceProvider* resourceProvider)
|
|
|
|
: fContext(context)
|
|
|
|
, fResourceProvider(resourceProvider)
|
|
|
|
, fInitialSeed(synthesizeInitialSeed())
|
|
|
|
, fRandomSeed(fInitialSeed) {}
|
|
|
|
|
|
|
|
uint32_t initialSeed() { return fInitialSeed; }
|
|
|
|
|
|
|
|
bool init() {
|
|
|
|
// Initializes the two test texture proxies that are available to the FP test factories.
|
|
|
|
SkRandom random{fRandomSeed};
|
|
|
|
static constexpr int kTestTextureSize = 256;
|
|
|
|
|
|
|
|
{
|
|
|
|
// Put premul data into the RGBA texture that the test FPs can optionally use.
|
|
|
|
GrColor* rgbaData = new GrColor[kTestTextureSize * kTestTextureSize];
|
|
|
|
for (int y = 0; y < kTestTextureSize; ++y) {
|
|
|
|
for (int x = 0; x < kTestTextureSize; ++x) {
|
|
|
|
rgbaData[kTestTextureSize * y + x] = input_texel_color(
|
|
|
|
random.nextULessThan(256), random.nextULessThan(256), 0.0f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SkImageInfo ii = SkImageInfo::Make(kTestTextureSize, kTestTextureSize,
|
|
|
|
kRGBA_8888_SkColorType, kPremul_SkAlphaType);
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.installPixels(
|
|
|
|
ii, rgbaData, ii.minRowBytes(),
|
|
|
|
[](void* addr, void* context) { delete[](GrColor*) addr; }, nullptr);
|
|
|
|
bitmap.setImmutable();
|
2021-04-28 16:39:21 +00:00
|
|
|
auto view = std::get<0>(GrMakeUncachedBitmapProxyView(fContext, bitmap));
|
|
|
|
if (!view || !view.proxy()->instantiate(fResourceProvider)) {
|
2020-07-20 13:45:51 +00:00
|
|
|
SkDebugf("Unable to instantiate RGBA8888 test texture.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
fTestViews[0] = GrProcessorTestData::ViewInfo{view, GrColorType::kRGBA_8888,
|
|
|
|
kPremul_SkAlphaType};
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// Put random values into the alpha texture that the test FPs can optionally use.
|
|
|
|
uint8_t* alphaData = new uint8_t[kTestTextureSize * kTestTextureSize];
|
|
|
|
for (int y = 0; y < kTestTextureSize; ++y) {
|
|
|
|
for (int x = 0; x < kTestTextureSize; ++x) {
|
|
|
|
alphaData[kTestTextureSize * y + x] = random.nextULessThan(256);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SkImageInfo ii = SkImageInfo::Make(kTestTextureSize, kTestTextureSize,
|
|
|
|
kAlpha_8_SkColorType, kPremul_SkAlphaType);
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.installPixels(
|
|
|
|
ii, alphaData, ii.minRowBytes(),
|
|
|
|
[](void* addr, void* context) { delete[](uint8_t*) addr; }, nullptr);
|
|
|
|
bitmap.setImmutable();
|
2021-04-28 16:39:21 +00:00
|
|
|
auto view = std::get<0>(GrMakeUncachedBitmapProxyView(fContext, bitmap));
|
|
|
|
if (!view || !view.proxy()->instantiate(fResourceProvider)) {
|
2020-07-20 13:45:51 +00:00
|
|
|
SkDebugf("Unable to instantiate A8 test texture.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
fTestViews[1] = GrProcessorTestData::ViewInfo{view, GrColorType::kAlpha_8,
|
|
|
|
kPremul_SkAlphaType};
|
2018-01-16 13:06:32 +00:00
|
|
|
}
|
2020-07-20 13:45:51 +00:00
|
|
|
|
|
|
|
return true;
|
2017-07-25 13:43:22 +00:00
|
|
|
}
|
2018-01-16 13:06:32 +00:00
|
|
|
|
2020-07-20 13:45:51 +00:00
|
|
|
void reroll() {
|
|
|
|
// Feed our current random seed into SkRandom to generate a new seed.
|
|
|
|
SkRandom random{fRandomSeed};
|
|
|
|
fRandomSeed = random.nextU();
|
2019-12-18 15:41:58 +00:00
|
|
|
}
|
2018-01-16 13:06:32 +00:00
|
|
|
|
2020-08-10 17:12:41 +00:00
|
|
|
std::unique_ptr<GrFragmentProcessor> make(int type, int randomTreeDepth,
|
2020-07-20 15:45:58 +00:00
|
|
|
std::unique_ptr<GrFragmentProcessor> inputFP) {
|
2020-07-20 13:45:51 +00:00
|
|
|
// This will generate the exact same randomized FP (of each requested type) each time
|
|
|
|
// it's called. Call `reroll` to get a different FP.
|
|
|
|
SkRandom random{fRandomSeed};
|
2020-08-10 17:12:41 +00:00
|
|
|
GrProcessorTestData testData{&random, fContext, randomTreeDepth,
|
|
|
|
SK_ARRAY_COUNT(fTestViews), fTestViews,
|
2020-07-20 15:45:58 +00:00
|
|
|
std::move(inputFP)};
|
2020-07-20 13:45:51 +00:00
|
|
|
return GrFragmentProcessorTestFactory::MakeIdx(type, &testData);
|
2017-07-25 13:43:22 +00:00
|
|
|
}
|
2018-01-16 13:06:32 +00:00
|
|
|
|
2020-08-10 17:12:41 +00:00
|
|
|
std::unique_ptr<GrFragmentProcessor> make(int type, int randomTreeDepth,
|
|
|
|
GrSurfaceProxyView view,
|
2020-07-20 15:45:58 +00:00
|
|
|
SkAlphaType alpha = kPremul_SkAlphaType) {
|
2020-08-10 17:12:41 +00:00
|
|
|
return make(type, randomTreeDepth, GrTextureEffect::Make(view, alpha));
|
2020-07-20 15:45:58 +00:00
|
|
|
}
|
|
|
|
|
2020-07-20 13:45:51 +00:00
|
|
|
private:
|
|
|
|
static uint32_t synthesizeInitialSeed() {
|
|
|
|
if (FLAGS_randomProcessorTest) {
|
|
|
|
std::random_device rd;
|
|
|
|
return rd();
|
|
|
|
} else {
|
|
|
|
return FLAGS_processorSeed;
|
|
|
|
}
|
2019-12-18 15:41:58 +00:00
|
|
|
}
|
2017-07-25 13:43:22 +00:00
|
|
|
|
2020-07-20 13:45:51 +00:00
|
|
|
GrDirectContext* fContext; // owned by caller
|
|
|
|
GrResourceProvider* fResourceProvider; // owned by caller
|
|
|
|
const uint32_t fInitialSeed;
|
|
|
|
uint32_t fRandomSeed;
|
|
|
|
GrProcessorTestData::ViewInfo fTestViews[2];
|
|
|
|
};
|
2017-07-25 13:43:22 +00:00
|
|
|
|
2020-08-11 20:04:31 +00:00
|
|
|
// Creates an array of color values from input_texel_color(), to be used as an input texture.
|
2021-08-13 03:01:41 +00:00
|
|
|
static std::vector<GrColor> make_input_pixels(int width, int height, SkScalar delta) {
|
2020-08-11 20:04:31 +00:00
|
|
|
std::vector<GrColor> pixel(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-08-11 20:04:31 +00:00
|
|
|
pixel[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
|
|
|
|
2020-08-11 20:04:31 +00:00
|
|
|
return pixel;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Creates a texture of premul colors used as the output of the fragment processor that precedes
|
|
|
|
// the fragment processor under test. An array of W*H colors are passed in as the texture data.
|
2021-08-13 03:01:41 +00:00
|
|
|
static GrSurfaceProxyView make_input_texture(GrRecordingContext* context,
|
2020-08-11 20:04:31 +00:00
|
|
|
int width, int height, GrColor* pixel) {
|
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;
|
2020-08-11 20:04:31 +00:00
|
|
|
bitmap.installPixels(ii, pixel, ii.minRowBytes());
|
2020-01-28 22:02:49 +00:00
|
|
|
bitmap.setImmutable();
|
2021-04-28 16:39:21 +00:00
|
|
|
return std::get<0>(GrMakeUncachedBitmapProxyView(context, bitmap));
|
2017-07-25 13:43:22 +00:00
|
|
|
}
|
2018-01-16 13:06:32 +00:00
|
|
|
|
2020-07-20 13:45:51 +00:00
|
|
|
// We tag logged data as unpremul to avoid conversion when encoding as PNG. The input texture
|
2019-08-13 16:40:04 +00:00
|
|
|
// actually contains unpremul data. Also, even though we made the result data by rendering into
|
2021-07-28 19:13:20 +00:00
|
|
|
// a "unpremul" SurfaceDrawContext, our input texture is unpremul and outside of the random
|
2019-08-13 16:40:04 +00:00
|
|
|
// effect configuration, we didn't do anything to ensure the output is actually premul. We just
|
2020-12-09 21:37:04 +00:00
|
|
|
// don't currently allow kUnpremul GrSurfaceDrawContexts.
|
2019-08-13 16:40:04 +00:00
|
|
|
static constexpr auto kLogAlphaType = kUnpremul_SkAlphaType;
|
|
|
|
|
2021-08-13 03:01:41 +00:00
|
|
|
static bool log_pixels(GrColor* pixels, int widthHeight, SkString* dst) {
|
2020-07-20 13:45:51 +00:00
|
|
|
SkImageInfo info =
|
|
|
|
SkImageInfo::Make(widthHeight, widthHeight, kRGBA_8888_SkColorType, kLogAlphaType);
|
2019-08-13 16:40:04 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-08-13 03:01:41 +00:00
|
|
|
static bool log_texture_view(GrDirectContext* dContext, GrSurfaceProxyView src, SkString* dst) {
|
2020-02-11 16:54:55 +00:00
|
|
|
SkImageInfo ii = SkImageInfo::Make(src.proxy()->dimensions(), kRGBA_8888_SkColorType,
|
|
|
|
kLogAlphaType);
|
2020-01-14 14:56:04 +00:00
|
|
|
|
2021-08-02 15:14:38 +00:00
|
|
|
auto sContext = dContext->priv().makeSC(std::move(src), ii.colorInfo());
|
2018-10-01 16:42:53 +00:00
|
|
|
SkBitmap bm;
|
|
|
|
SkAssertResult(bm.tryAllocPixels(ii));
|
2020-12-24 01:36:44 +00:00
|
|
|
SkAssertResult(sContext->readPixels(dContext, bm.pixmap(), {0, 0}));
|
2019-10-25 00:07:39 +00:00
|
|
|
return BipmapToBase64DataURI(bm, dst);
|
2018-10-01 16:42:53 +00:00
|
|
|
}
|
|
|
|
|
2021-08-13 03:01:41 +00:00
|
|
|
static bool fuzzy_color_equals(const SkPMColor4f& c1, const SkPMColor4f& c2) {
|
2018-10-08 20:43:58 +00:00
|
|
|
// 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).
|
2021-08-13 03:01:41 +00:00
|
|
|
static bool legal_modulation(const GrColor inGr[3], const GrColor outGr[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) {
|
2021-08-13 03:01:41 +00:00
|
|
|
inf[i] = SkPMColor4f::FromBytes_RGBA(inGr[i]);
|
|
|
|
outf[i] = SkPMColor4f::FromBytes_RGBA(outGr[i]);
|
2019-12-18 19:57:45 +00:00
|
|
|
}
|
|
|
|
// 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;
|
2020-07-20 17:48:02 +00:00
|
|
|
const SkPMColor4f& in = inf[maxInIdx];
|
|
|
|
const SkPMColor4f& 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.
|
2022-02-04 21:09:04 +00:00
|
|
|
if ((false)) {
|
|
|
|
if (!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]));
|
|
|
|
}
|
2019-12-18 19:57:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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-20 13:45:51 +00:00
|
|
|
GrDirectContext* context = ctxInfo.directContext();
|
|
|
|
GrResourceProvider* resourceProvider = context->priv().resourceProvider();
|
2017-07-24 14:16:19 +00:00
|
|
|
using FPFactory = GrFragmentProcessorTestFactory;
|
2017-03-17 14:58:53 +00:00
|
|
|
|
2020-07-20 13:45:51 +00:00
|
|
|
TestFPGenerator fpGenerator{context, resourceProvider};
|
|
|
|
if (!fpGenerator.init()) {
|
|
|
|
ERRORF(reporter, "Could not initialize TestFPGenerator");
|
|
|
|
return;
|
2017-03-17 14:58:53 +00:00
|
|
|
}
|
|
|
|
|
2017-07-25 13:43:22 +00:00
|
|
|
// Make the destination context for the test.
|
|
|
|
static constexpr int kRenderSize = 256;
|
2021-07-28 19:13:20 +00:00
|
|
|
auto sdc = skgpu::v1::SurfaceDrawContext::Make(
|
2020-01-08 16:52:34 +00:00
|
|
|
context, GrColorType::kRGBA_8888, nullptr, SkBackingFit::kExact,
|
2021-04-19 23:27:09 +00:00
|
|
|
{kRenderSize, kRenderSize}, SkSurfaceProps());
|
2017-02-10 17:39:26 +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-08-11 20:04:31 +00:00
|
|
|
std::vector<GrColor> inputPixels1 = make_input_pixels(kRenderSize, kRenderSize, 0.0f);
|
|
|
|
std::vector<GrColor> inputPixels2 =
|
|
|
|
make_input_pixels(kRenderSize, kRenderSize, 1 * kInputDelta);
|
|
|
|
std::vector<GrColor> inputPixels3 =
|
|
|
|
make_input_pixels(kRenderSize, kRenderSize, 2 * kInputDelta);
|
|
|
|
GrSurfaceProxyView inputTexture1 =
|
|
|
|
make_input_texture(context, kRenderSize, kRenderSize, inputPixels1.data());
|
|
|
|
GrSurfaceProxyView inputTexture2 =
|
|
|
|
make_input_texture(context, kRenderSize, kRenderSize, inputPixels2.data());
|
|
|
|
GrSurfaceProxyView inputTexture3 =
|
|
|
|
make_input_texture(context, kRenderSize, kRenderSize, inputPixels3.data());
|
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
|
|
|
|
2020-07-20 13:45:51 +00:00
|
|
|
// Storage for the three frames required for coverage compatibility optimization testing.
|
|
|
|
// Each frame uses the correspondingly numbered inputTextureX.
|
|
|
|
std::vector<GrColor> readData1(kRenderSize * kRenderSize);
|
|
|
|
std::vector<GrColor> readData2(kRenderSize * kRenderSize);
|
|
|
|
std::vector<GrColor> readData3(kRenderSize * kRenderSize);
|
2018-10-08 20:43:58 +00:00
|
|
|
|
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) {
|
2020-07-20 17:48:02 +00:00
|
|
|
int optimizedForOpaqueInput = 0;
|
|
|
|
int optimizedForCoverageAsAlpha = 0;
|
|
|
|
int optimizedForConstantOutputForInput = 0;
|
2020-07-20 13:45:51 +00:00
|
|
|
|
2020-07-20 17:48:02 +00:00
|
|
|
#ifdef __MSVC_RUNTIME_CHECKS
|
2019-02-04 15:01:53 +00:00
|
|
|
// This test is infuriatingly slow with MSVC runtime checks enabled
|
2020-07-20 17:48:02 +00:00
|
|
|
static constexpr int kMinimumTrials = 1;
|
|
|
|
static constexpr int kMaximumTrials = 1;
|
|
|
|
static constexpr int kExpectedSuccesses = 1;
|
|
|
|
#else
|
|
|
|
// We start by testing each fragment-processor 100 times, watching the optimization bits
|
|
|
|
// that appear. If we see an optimization bit appear in those first 100 trials, we keep
|
|
|
|
// running tests until we see at least five successful trials that have this optimization
|
|
|
|
// bit enabled. If we never see a particular optimization bit after 100 trials, we assume
|
|
|
|
// that this FP doesn't support that optimization at all.
|
|
|
|
static constexpr int kMinimumTrials = 100;
|
|
|
|
static constexpr int kMaximumTrials = 2000;
|
|
|
|
static constexpr int kExpectedSuccesses = 5;
|
2019-02-04 15:01:53 +00:00
|
|
|
#endif
|
2020-07-20 13:45:51 +00:00
|
|
|
|
2020-07-20 17:48:02 +00:00
|
|
|
for (int trial = 0;; ++trial) {
|
2020-07-20 13:45:51 +00:00
|
|
|
// Create a randomly-configured FP.
|
|
|
|
fpGenerator.reroll();
|
2020-08-10 17:12:41 +00:00
|
|
|
std::unique_ptr<GrFragmentProcessor> fp =
|
2020-08-10 20:35:01 +00:00
|
|
|
fpGenerator.make(i, /*randomTreeDepth=*/1, inputTexture1);
|
2020-07-20 17:48:02 +00:00
|
|
|
|
|
|
|
// If we have iterated enough times and seen a sufficient number of successes on each
|
|
|
|
// optimization bit that can be returned, stop running trials.
|
|
|
|
if (trial >= kMinimumTrials) {
|
|
|
|
bool moreTrialsNeeded = (optimizedForOpaqueInput > 0 &&
|
|
|
|
optimizedForOpaqueInput < kExpectedSuccesses) ||
|
|
|
|
(optimizedForCoverageAsAlpha > 0 &&
|
|
|
|
optimizedForCoverageAsAlpha < kExpectedSuccesses) ||
|
|
|
|
(optimizedForConstantOutputForInput > 0 &&
|
|
|
|
optimizedForConstantOutputForInput < kExpectedSuccesses);
|
|
|
|
if (!moreTrialsNeeded) break;
|
|
|
|
|
|
|
|
if (trial >= kMaximumTrials) {
|
|
|
|
SkDebugf("Abandoning ProcessorOptimizationValidationTest after %d trials. "
|
2020-08-11 17:58:32 +00:00
|
|
|
"Seed: 0x%08x, processor:\n%s",
|
|
|
|
kMaximumTrials, fpGenerator.initialSeed(), fp->dumpTreeInfo().c_str());
|
2020-07-20 17:48:02 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-05-01 17:12:20 +00:00
|
|
|
|
2020-07-20 17:48:02 +00:00
|
|
|
// Skip further testing if this trial has no optimization bits enabled.
|
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-07-20 13:45:51 +00:00
|
|
|
// We can make identical copies of the test FP in order to test coverage-as-alpha.
|
2018-10-08 20:43:58 +00:00
|
|
|
if (fp->compatibleWithCoverageAsAlpha()) {
|
2020-07-20 15:45:58 +00:00
|
|
|
// Create and render two identical versions of this FP, but using different input
|
|
|
|
// textures, to check coverage optimization. We don't need to do this step for
|
|
|
|
// constant-output or preserving-opacity tests.
|
2021-07-28 19:13:20 +00:00
|
|
|
render_fp(context, sdc.get(),
|
2020-08-10 20:35:01 +00:00
|
|
|
fpGenerator.make(i, /*randomTreeDepth=*/1, inputTexture2),
|
2020-08-10 17:12:41 +00:00
|
|
|
readData2.data());
|
2021-07-28 19:13:20 +00:00
|
|
|
render_fp(context, sdc.get(),
|
2020-08-10 20:35:01 +00:00
|
|
|
fpGenerator.make(i, /*randomTreeDepth=*/1, inputTexture3),
|
2020-08-10 17:12:41 +00:00
|
|
|
readData3.data());
|
2020-07-20 17:48:02 +00:00
|
|
|
++optimizedForCoverageAsAlpha;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fp->hasConstantOutputForConstantInput()) {
|
|
|
|
++optimizedForConstantOutputForInput;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fp->preservesOpaqueInput()) {
|
|
|
|
++optimizedForOpaqueInput;
|
2018-10-08 20:43:58 +00:00
|
|
|
}
|
2020-06-18 18:16:00 +00:00
|
|
|
|
2020-07-20 15:45: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.
|
2021-07-28 19:13:20 +00:00
|
|
|
render_fp(context, sdc.get(), fpGenerator.make(i, /*randomTreeDepth=*/1, inputTexture1),
|
2020-08-10 17:12:41 +00:00
|
|
|
readData1.data());
|
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
|
|
|
|
|
|
|
|
// Collect first optimization failure message, to be output later as a warning or an
|
|
|
|
// error depending on whether the rendering "passed" or failed.
|
2020-07-20 13:45:51 +00:00
|
|
|
int failedPixelCount = 0;
|
2018-10-03 20:04:38 +00:00
|
|
|
SkString coverageMessage;
|
|
|
|
SkString opaqueMessage;
|
|
|
|
SkString constMessage;
|
|
|
|
for (int y = 0; y < kRenderSize; ++y) {
|
|
|
|
for (int x = 0; x < kRenderSize; ++x) {
|
|
|
|
bool passing = true;
|
2020-08-11 20:04:31 +00:00
|
|
|
GrColor input = inputPixels1[y * kRenderSize + x];
|
2020-07-20 13:45:51 +00:00
|
|
|
GrColor output = readData1[y * kRenderSize + x];
|
2018-10-08 20:43:58 +00:00
|
|
|
|
|
|
|
if (fp->compatibleWithCoverageAsAlpha()) {
|
2019-12-18 19:57:45 +00:00
|
|
|
GrColor ins[3];
|
|
|
|
ins[0] = input;
|
2020-08-11 20:04:31 +00:00
|
|
|
ins[1] = inputPixels2[y * kRenderSize + x];
|
|
|
|
ins[2] = inputPixels3[y * kRenderSize + x];
|
2018-10-08 20:43:58 +00:00
|
|
|
|
2019-12-18 19:57:45 +00:00
|
|
|
GrColor outs[3];
|
|
|
|
outs[0] = output;
|
2020-07-20 13:45:51 +00:00
|
|
|
outs[1] = readData2[y * kRenderSize + x];
|
|
|
|
outs[2] = readData3[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(
|
2020-08-11 17:58:32 +00:00
|
|
|
"\"Modulating\" processor did not match alpha-modulation "
|
|
|
|
"nor color-modulation rules.\n"
|
2018-10-08 20:43:58 +00:00
|
|
|
"Input: 0x%08x, Output: 0x%08x, pixel (%d, %d).",
|
2020-08-11 17:58:32 +00:00
|
|
|
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;
|
|
|
|
|
2020-08-11 17:58:32 +00:00
|
|
|
constMessage.printf(
|
|
|
|
"Processor claimed output for const input doesn't match "
|
|
|
|
"actual output.\n"
|
|
|
|
"Error: %f, Tolerance: %f, input: (%f, %f, %f, %f), "
|
|
|
|
"actual: (%f, %f, %f, %f), expected(%f, %f, %f, %f).",
|
|
|
|
std::max(rDiff, std::max(gDiff, std::max(bDiff, aDiff))),
|
|
|
|
kTol, 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()) {
|
2020-08-11 17:58:32 +00:00
|
|
|
opaqueMessage.printf(
|
|
|
|
"Processor claimed opaqueness is preserved but "
|
2018-10-03 20:04:38 +00:00
|
|
|
"it is not. Input: 0x%08x, Output: 0x%08x.",
|
2020-08-11 17:58:32 +00:00
|
|
|
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) {
|
2020-08-11 17:58:32 +00:00
|
|
|
ERRORF(reporter,
|
|
|
|
"Processor violated %d of %d pixels, seed: 0x%08x.\n"
|
|
|
|
"Processor:\n%s\nFirst failing pixel details are below:",
|
2020-07-20 13:45:51 +00:00
|
|
|
failedPixelCount, kRenderSize * kRenderSize, fpGenerator.initialSeed(),
|
2020-08-11 17:58:32 +00:00
|
|
|
fp->dumpTreeInfo().c_str());
|
2018-10-03 20:04:38 +00:00
|
|
|
|
|
|
|
// Print first failing pixel's details.
|
|
|
|
if (!coverageMessage.isEmpty()) {
|
2022-02-10 15:06:54 +00:00
|
|
|
ERRORF(reporter, "%s", coverageMessage.c_str());
|
2018-10-03 20:04:38 +00:00
|
|
|
}
|
|
|
|
if (!constMessage.isEmpty()) {
|
2022-02-10 15:06:54 +00:00
|
|
|
ERRORF(reporter, "%s", constMessage.c_str());
|
2018-10-03 20:04:38 +00:00
|
|
|
}
|
|
|
|
if (!opaqueMessage.isEmpty()) {
|
2022-02-10 15:06:54 +00:00
|
|
|
ERRORF(reporter, "%s", opaqueMessage.c_str());
|
2018-10-03 20:04:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2020-07-20 13:45:51 +00:00
|
|
|
log_pixels(readData1.data(), 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;
|
|
|
|
}
|
2020-07-20 13:45:51 +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,
|
2020-07-20 13:45:51 +00:00
|
|
|
fpGenerator.initialSeed(), fp->dumpInfo().c_str());
|
2018-10-03 20:04:38 +00:00
|
|
|
if (!coverageMessage.isEmpty()) {
|
2021-06-25 15:05:20 +00:00
|
|
|
INFOF(reporter, "%s", coverageMessage.c_str());
|
2018-10-03 20:04:38 +00:00
|
|
|
}
|
|
|
|
if (!constMessage.isEmpty()) {
|
2021-06-25 15:05:20 +00:00
|
|
|
INFOF(reporter, "%s", constMessage.c_str());
|
2018-10-03 20:04:38 +00:00
|
|
|
}
|
|
|
|
if (!opaqueMessage.isEmpty()) {
|
2021-06-25 15:05:20 +00:00
|
|
|
INFOF(reporter, "%s", opaqueMessage.c_str());
|
2018-10-03 20:04:38 +00:00
|
|
|
}
|
|
|
|
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;
|
2020-07-20 13:45:51 +00:00
|
|
|
log_pixels(readData1.data(), 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-08-10 15:38:41 +00:00
|
|
|
static void assert_processor_equality(skiatest::Reporter* reporter,
|
|
|
|
const GrFragmentProcessor& fp,
|
|
|
|
const GrFragmentProcessor& clone) {
|
|
|
|
REPORTER_ASSERT(reporter, !strcmp(fp.name(), clone.name()),
|
2020-08-11 17:58:32 +00:00
|
|
|
"\n%s", fp.dumpTreeInfo().c_str());
|
2020-08-10 15:38:41 +00:00
|
|
|
REPORTER_ASSERT(reporter, fp.compatibleWithCoverageAsAlpha() ==
|
|
|
|
clone.compatibleWithCoverageAsAlpha(),
|
2020-08-11 17:58:32 +00:00
|
|
|
"\n%s", fp.dumpTreeInfo().c_str());
|
2020-08-10 15:38:41 +00:00
|
|
|
REPORTER_ASSERT(reporter, fp.isEqual(clone),
|
2020-08-11 17:58:32 +00:00
|
|
|
"\n%s", fp.dumpTreeInfo().c_str());
|
2020-08-10 15:38:41 +00:00
|
|
|
REPORTER_ASSERT(reporter, fp.preservesOpaqueInput() == clone.preservesOpaqueInput(),
|
2020-08-11 17:58:32 +00:00
|
|
|
"\n%s", fp.dumpTreeInfo().c_str());
|
2020-08-10 15:38:41 +00:00
|
|
|
REPORTER_ASSERT(reporter, fp.hasConstantOutputForConstantInput() ==
|
|
|
|
clone.hasConstantOutputForConstantInput(),
|
2020-08-11 17:58:32 +00:00
|
|
|
"\n%s", fp.dumpTreeInfo().c_str());
|
2020-08-10 15:38:41 +00:00
|
|
|
REPORTER_ASSERT(reporter, fp.numChildProcessors() == clone.numChildProcessors(),
|
2020-08-11 17:58:32 +00:00
|
|
|
"\n%s", fp.dumpTreeInfo().c_str());
|
2021-08-02 16:37:14 +00:00
|
|
|
REPORTER_ASSERT(reporter, fp.sampleUsage() == clone.sampleUsage(),
|
2020-08-11 17:58:32 +00:00
|
|
|
"\n%s", fp.dumpTreeInfo().c_str());
|
2021-08-02 16:37:14 +00:00
|
|
|
REPORTER_ASSERT(reporter, fp.usesSampleCoords() == clone.usesSampleCoords(),
|
2020-08-11 17:58:32 +00:00
|
|
|
"\n%s", fp.dumpTreeInfo().c_str());
|
2020-08-10 15:38:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool verify_identical_render(skiatest::Reporter* reporter, int renderSize,
|
|
|
|
const char* processorType,
|
|
|
|
const GrColor readData1[], const GrColor readData2[]) {
|
|
|
|
// The ProcessorClone 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)
|
|
|
|
const int maxAcceptableFailedPixels = 0; // Strict when running as SKQP
|
|
|
|
#else
|
|
|
|
const int maxAcceptableFailedPixels = 2 * renderSize; // ~0.002% of the pixels (size 1024*1024)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int failedPixelCount = 0;
|
|
|
|
int firstWrongX = 0;
|
|
|
|
int firstWrongY = 0;
|
|
|
|
int idx = 0;
|
|
|
|
for (int y = 0; y < renderSize; ++y) {
|
|
|
|
for (int x = 0; x < renderSize; ++x, ++idx) {
|
|
|
|
if (readData1[idx] != readData2[idx]) {
|
|
|
|
if (!failedPixelCount) {
|
|
|
|
firstWrongX = x;
|
|
|
|
firstWrongY = y;
|
|
|
|
}
|
|
|
|
++failedPixelCount;
|
|
|
|
}
|
|
|
|
if (failedPixelCount > maxAcceptableFailedPixels) {
|
|
|
|
idx = firstWrongY * renderSize + firstWrongX;
|
|
|
|
ERRORF(reporter,
|
|
|
|
"%s produced different output at (%d, %d). "
|
|
|
|
"Input color: 0x%08x, Original Output Color: 0x%08x, "
|
|
|
|
"Clone Output Color: 0x%08x.",
|
|
|
|
processorType, firstWrongX, firstWrongY, input_texel_color(x, y, 0.0f),
|
|
|
|
readData1[idx], readData2[idx]);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void log_clone_failure(skiatest::Reporter* reporter, int renderSize,
|
|
|
|
GrDirectContext* context, const GrSurfaceProxyView& inputTexture,
|
|
|
|
GrColor pixelsFP[], GrColor pixelsClone[], GrColor pixelsRegen[]) {
|
|
|
|
// Write the images out as data URLs for inspection.
|
|
|
|
SkString inputURL, origURL, cloneURL, regenURL;
|
|
|
|
if (log_texture_view(context, inputTexture, &inputURL) &&
|
|
|
|
log_pixels(pixelsFP, renderSize, &origURL) &&
|
|
|
|
log_pixels(pixelsClone, renderSize, &cloneURL) &&
|
|
|
|
log_pixels(pixelsRegen, renderSize, ®enURL)) {
|
|
|
|
ERRORF(reporter,
|
|
|
|
"\nInput image:\n%s\n\n"
|
|
|
|
"==========================================================="
|
|
|
|
"\n\n"
|
|
|
|
"Orig output image:\n%s\n"
|
|
|
|
"==========================================================="
|
|
|
|
"\n\n"
|
|
|
|
"Clone output image:\n%s\n"
|
|
|
|
"==========================================================="
|
|
|
|
"\n\n"
|
|
|
|
"Regen output image:\n%s\n",
|
|
|
|
inputURL.c_str(), origURL.c_str(), cloneURL.c_str(), regenURL.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-20 13:45:51 +00:00
|
|
|
GrDirectContext* context = ctxInfo.directContext();
|
|
|
|
GrResourceProvider* resourceProvider = context->priv().resourceProvider();
|
2017-07-25 13:43:22 +00:00
|
|
|
|
2020-07-20 13:45:51 +00:00
|
|
|
TestFPGenerator fpGenerator{context, resourceProvider};
|
|
|
|
if (!fpGenerator.init()) {
|
|
|
|
ERRORF(reporter, "Could not initialize TestFPGenerator");
|
|
|
|
return;
|
|
|
|
}
|
2017-07-25 13:43:22 +00:00
|
|
|
|
|
|
|
// Make the destination context for the test.
|
|
|
|
static constexpr int kRenderSize = 1024;
|
2021-07-28 19:13:20 +00:00
|
|
|
auto sdc = skgpu::v1::SurfaceDrawContext::Make(
|
2020-01-08 16:52:34 +00:00
|
|
|
context, GrColorType::kRGBA_8888, nullptr, SkBackingFit::kExact,
|
2021-04-19 23:27:09 +00:00
|
|
|
{kRenderSize, kRenderSize}, SkSurfaceProps());
|
2017-07-25 13:43:22 +00:00
|
|
|
|
2020-08-11 20:04:31 +00:00
|
|
|
std::vector<GrColor> inputPixels = make_input_pixels(kRenderSize, kRenderSize, 0.0f);
|
|
|
|
GrSurfaceProxyView inputTexture =
|
|
|
|
make_input_texture(context, kRenderSize, kRenderSize, inputPixels.data());
|
2020-07-20 13:45:51 +00:00
|
|
|
|
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;
|
|
|
|
|
2020-07-20 13:45:51 +00:00
|
|
|
// Storage for the original frame's readback and the readback of its clone.
|
2020-08-10 15:38:41 +00:00
|
|
|
std::vector<GrColor> readDataFP(kRenderSize * kRenderSize);
|
|
|
|
std::vector<GrColor> readDataClone(kRenderSize * kRenderSize);
|
|
|
|
std::vector<GrColor> readDataRegen(kRenderSize * kRenderSize);
|
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-07-20 13:45:51 +00:00
|
|
|
fpGenerator.reroll();
|
2020-08-10 17:12:41 +00:00
|
|
|
std::unique_ptr<GrFragmentProcessor> fp =
|
2020-08-10 20:35:01 +00:00
|
|
|
fpGenerator.make(i, /*randomTreeDepth=*/1, /*inputFP=*/nullptr);
|
2020-08-10 17:12:41 +00:00
|
|
|
std::unique_ptr<GrFragmentProcessor> regen =
|
2020-08-10 20:35:01 +00:00
|
|
|
fpGenerator.make(i, /*randomTreeDepth=*/1, /*inputFP=*/nullptr);
|
2020-06-15 19:07:19 +00:00
|
|
|
std::unique_ptr<GrFragmentProcessor> clone = fp->clone();
|
2017-07-25 13:43:22 +00:00
|
|
|
if (!clone) {
|
2020-08-11 17:58:32 +00:00
|
|
|
ERRORF(reporter, "Clone of processor %s failed.", fp->dumpTreeInfo().c_str());
|
2017-07-25 13:43:22 +00:00
|
|
|
continue;
|
|
|
|
}
|
2020-08-10 15:38:41 +00:00
|
|
|
assert_processor_equality(reporter, *fp, *clone);
|
|
|
|
|
2017-07-25 13:43:22 +00:00
|
|
|
// Draw with original and read back the results.
|
2021-07-28 19:13:20 +00:00
|
|
|
render_fp(context, sdc.get(), std::move(fp), readDataFP.data());
|
2017-07-25 13:43:22 +00:00
|
|
|
|
|
|
|
// Draw with clone and read back the results.
|
2021-07-28 19:13:20 +00:00
|
|
|
render_fp(context, sdc.get(), std::move(clone), readDataClone.data());
|
2017-07-25 13:43:22 +00:00
|
|
|
|
|
|
|
// Check that the results are the same.
|
2020-08-10 15:38:41 +00:00
|
|
|
if (!verify_identical_render(reporter, kRenderSize, "Processor clone",
|
|
|
|
readDataFP.data(), readDataClone.data())) {
|
|
|
|
// Dump a description from the regenerated processor (since the original FP has
|
|
|
|
// already been consumed).
|
2020-08-11 17:58:32 +00:00
|
|
|
ERRORF(reporter, "FP hierarchy:\n%s", regen->dumpTreeInfo().c_str());
|
2020-08-10 15:38:41 +00:00
|
|
|
|
|
|
|
// Render and readback output from the regenerated FP. If this also mismatches, the
|
|
|
|
// FP itself doesn't generate consistent output. This could happen if:
|
|
|
|
// - the FP's TestCreate() does not always generate the same FP from a given seed
|
|
|
|
// - the FP's Make() does not always generate the same FP when given the same inputs
|
|
|
|
// - the FP itself generates inconsistent pixels (shader UB?)
|
|
|
|
// - the driver has a bug
|
2021-07-28 19:13:20 +00:00
|
|
|
render_fp(context, sdc.get(), std::move(regen), readDataRegen.data());
|
2020-08-10 15:38:41 +00:00
|
|
|
|
|
|
|
if (!verify_identical_render(reporter, kRenderSize, "Regenerated processor",
|
|
|
|
readDataFP.data(), readDataRegen.data())) {
|
|
|
|
ERRORF(reporter, "Output from regen did not match original!\n");
|
|
|
|
} else {
|
|
|
|
ERRORF(reporter, "Regenerated processor output matches original results.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
// If this is the first time we've encountered a cloning failure, log the generated
|
|
|
|
// images to the reporter as data URLs.
|
|
|
|
if (!loggedFirstFailure) {
|
|
|
|
log_clone_failure(reporter, kRenderSize, context, inputTexture,
|
|
|
|
readDataFP.data(), readDataClone.data(),
|
|
|
|
readDataRegen.data());
|
|
|
|
loggedFirstFailure = true;
|
2017-07-25 13:43:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-31 18:50:44 +00:00
|
|
|
#endif // GR_TEST_UTILS
|