2011-08-16 15:45:58 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-05-10 19:01:53 +00:00
|
|
|
// This is a GPU-backend specific test.
|
2012-08-02 14:03:32 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkTypes.h"
|
2012-08-03 14:54:45 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/private/SkChecksum.h"
|
|
|
|
#include "include/utils/SkRandom.h"
|
|
|
|
#include "src/gpu/GrAutoLocaleSetter.h"
|
|
|
|
#include "src/gpu/GrContextPriv.h"
|
|
|
|
#include "src/gpu/GrDrawOpTest.h"
|
|
|
|
#include "src/gpu/GrDrawingManager.h"
|
|
|
|
#include "src/gpu/GrPipeline.h"
|
2020-04-06 17:57:30 +00:00
|
|
|
#include "src/gpu/GrProxyProvider.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrRenderTargetContextPriv.h"
|
|
|
|
#include "src/gpu/GrXferProcessor.h"
|
|
|
|
#include "src/gpu/effects/GrPorterDuffXferProcessor.h"
|
|
|
|
#include "src/gpu/effects/GrXfermodeFragmentProcessor.h"
|
|
|
|
#include "src/gpu/effects/generated/GrConfigConversionEffect.h"
|
|
|
|
#include "src/gpu/glsl/GrGLSLFragmentProcessor.h"
|
|
|
|
#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
|
|
|
|
#include "src/gpu/glsl/GrGLSLProgramBuilder.h"
|
2020-03-19 19:54:28 +00:00
|
|
|
#include "src/gpu/ops/GrDrawOp.h"
|
|
|
|
#include "tests/Test.h"
|
|
|
|
#include "tools/gpu/GrContextFactory.h"
|
|
|
|
|
|
|
|
#ifdef SK_GL
|
|
|
|
#include "src/gpu/gl/GrGLGpu.h"
|
|
|
|
#endif
|
2012-08-02 18:11:43 +00:00
|
|
|
|
2014-10-09 14:25:36 +00:00
|
|
|
/*
|
2014-10-15 18:05:26 +00:00
|
|
|
* A dummy processor which just tries to insert a massive key and verify that it can retrieve the
|
2014-10-09 14:25:36 +00:00
|
|
|
* whole thing correctly
|
|
|
|
*/
|
|
|
|
static const uint32_t kMaxKeySize = 1024;
|
2014-10-07 15:37:36 +00:00
|
|
|
|
2015-11-13 14:54:19 +00:00
|
|
|
class GLBigKeyProcessor : public GrGLSLFragmentProcessor {
|
2014-12-04 19:35:33 +00:00
|
|
|
public:
|
2016-02-03 20:25:40 +00:00
|
|
|
void emitCode(EmitArgs& args) override {
|
2015-05-13 15:51:49 +00:00
|
|
|
// pass through
|
2015-11-18 16:01:26 +00:00
|
|
|
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
|
2015-09-14 19:26:33 +00:00
|
|
|
if (args.fInputColor) {
|
2015-11-18 16:01:26 +00:00
|
|
|
fragBuilder->codeAppendf("%s = %s;\n", args.fOutputColor, args.fInputColor);
|
2015-09-14 19:26:33 +00:00
|
|
|
} else {
|
2015-11-18 16:01:26 +00:00
|
|
|
fragBuilder->codeAppendf("%s = vec4(1.0);\n", args.fOutputColor);
|
2015-09-14 19:26:33 +00:00
|
|
|
}
|
2015-05-13 15:51:49 +00:00
|
|
|
}
|
2014-12-04 19:35:33 +00:00
|
|
|
|
2016-11-29 18:43:05 +00:00
|
|
|
static void GenKey(const GrProcessor&, const GrShaderCaps&, GrProcessorKeyBuilder* b) {
|
2014-12-04 19:35:33 +00:00
|
|
|
for (uint32_t i = 0; i < kMaxKeySize; i++) {
|
|
|
|
b->add32(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-11-13 14:54:19 +00:00
|
|
|
typedef GrGLSLFragmentProcessor INHERITED;
|
2014-12-04 19:35:33 +00:00
|
|
|
};
|
2014-10-07 15:37:36 +00:00
|
|
|
|
2014-10-09 14:25:36 +00:00
|
|
|
class BigKeyProcessor : public GrFragmentProcessor {
|
|
|
|
public:
|
2017-08-11 13:40:37 +00:00
|
|
|
static std::unique_ptr<GrFragmentProcessor> Make() {
|
|
|
|
return std::unique_ptr<GrFragmentProcessor>(new BigKeyProcessor);
|
2014-10-07 15:37:36 +00:00
|
|
|
}
|
|
|
|
|
2020-04-01 18:18:28 +00:00
|
|
|
const char* name() const override { return "Big_Ole_Key"; }
|
2014-10-07 15:37:36 +00:00
|
|
|
|
2015-11-13 19:57:27 +00:00
|
|
|
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override {
|
2016-02-03 20:25:40 +00:00
|
|
|
return new GLBigKeyProcessor;
|
2014-12-04 19:35:33 +00:00
|
|
|
}
|
2014-10-07 15:37:36 +00:00
|
|
|
|
2017-08-11 13:40:37 +00:00
|
|
|
std::unique_ptr<GrFragmentProcessor> clone() const override { return Make(); }
|
2017-07-28 17:41:51 +00:00
|
|
|
|
2014-10-09 14:25:36 +00:00
|
|
|
private:
|
2017-10-09 14:54:08 +00:00
|
|
|
BigKeyProcessor() : INHERITED(kBigKeyProcessor_ClassID, kNone_OptimizationFlags) { }
|
2016-11-29 18:43:05 +00:00
|
|
|
virtual void onGetGLSLProcessorKey(const GrShaderCaps& caps,
|
2015-11-13 19:57:27 +00:00
|
|
|
GrProcessorKeyBuilder* b) const override {
|
2015-08-04 14:59:37 +00:00
|
|
|
GLBigKeyProcessor::GenKey(*this, caps, b);
|
|
|
|
}
|
2015-03-26 01:17:31 +00:00
|
|
|
bool onIsEqual(const GrFragmentProcessor&) const override { return true; }
|
2014-10-07 15:37:36 +00:00
|
|
|
|
2017-07-06 14:09:38 +00:00
|
|
|
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
|
2014-10-07 15:37:36 +00:00
|
|
|
|
2014-10-09 14:25:36 +00:00
|
|
|
typedef GrFragmentProcessor INHERITED;
|
|
|
|
};
|
2014-10-07 15:37:36 +00:00
|
|
|
|
2014-10-09 14:25:36 +00:00
|
|
|
GR_DEFINE_FRAGMENT_PROCESSOR_TEST(BigKeyProcessor);
|
2014-10-07 15:37:36 +00:00
|
|
|
|
2017-01-31 18:50:44 +00:00
|
|
|
#if GR_TEST_UTILS
|
2017-08-11 13:40:37 +00:00
|
|
|
std::unique_ptr<GrFragmentProcessor> BigKeyProcessor::TestCreate(GrProcessorTestData*) {
|
2016-06-09 15:01:03 +00:00
|
|
|
return BigKeyProcessor::Make();
|
2014-10-09 14:25:36 +00:00
|
|
|
}
|
2017-01-31 18:50:44 +00:00
|
|
|
#endif
|
2014-10-07 15:37:36 +00:00
|
|
|
|
2015-09-14 19:26:33 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class BlockInputFragmentProcessor : public GrFragmentProcessor {
|
|
|
|
public:
|
2017-08-11 13:40:37 +00:00
|
|
|
static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> fp) {
|
|
|
|
return std::unique_ptr<GrFragmentProcessor>(new BlockInputFragmentProcessor(std::move(fp)));
|
2015-09-14 19:26:33 +00:00
|
|
|
}
|
|
|
|
|
2020-04-17 14:35:38 +00:00
|
|
|
const char* name() const override { return "Block_Input"; }
|
2015-09-14 19:26:33 +00:00
|
|
|
|
2015-11-13 19:57:27 +00:00
|
|
|
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { return new GLFP; }
|
2015-09-14 19:26:33 +00:00
|
|
|
|
2017-08-11 13:40:37 +00:00
|
|
|
std::unique_ptr<GrFragmentProcessor> clone() const override {
|
2017-07-31 20:27:23 +00:00
|
|
|
return Make(this->childProcessor(0).clone());
|
2017-07-28 17:41:51 +00:00
|
|
|
}
|
|
|
|
|
2015-09-14 19:26:33 +00:00
|
|
|
private:
|
2015-11-13 14:54:19 +00:00
|
|
|
class GLFP : public GrGLSLFragmentProcessor {
|
2015-09-14 19:26:33 +00:00
|
|
|
public:
|
|
|
|
void emitCode(EmitArgs& args) override {
|
2020-01-24 19:52:10 +00:00
|
|
|
SkString temp = this->invokeChild(0, args);
|
2020-01-24 15:24:27 +00:00
|
|
|
args.fFragBuilder->codeAppendf("%s = %s;", args.fOutputColor, temp.c_str());
|
2015-09-14 19:26:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-11-13 14:54:19 +00:00
|
|
|
typedef GrGLSLFragmentProcessor INHERITED;
|
2015-09-14 19:26:33 +00:00
|
|
|
};
|
|
|
|
|
2017-08-11 13:40:37 +00:00
|
|
|
BlockInputFragmentProcessor(std::unique_ptr<GrFragmentProcessor> child)
|
2017-10-09 14:54:08 +00:00
|
|
|
: INHERITED(kBlockInputFragmentProcessor_ClassID, kNone_OptimizationFlags) {
|
2016-06-09 15:01:03 +00:00
|
|
|
this->registerChildProcessor(std::move(child));
|
2015-09-14 19:26:33 +00:00
|
|
|
}
|
|
|
|
|
2016-11-29 18:43:05 +00:00
|
|
|
void onGetGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override {}
|
2015-09-14 19:26:33 +00:00
|
|
|
|
|
|
|
bool onIsEqual(const GrFragmentProcessor&) const override { return true; }
|
|
|
|
|
|
|
|
typedef GrFragmentProcessor INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-10-09 14:25:36 +00:00
|
|
|
/*
|
|
|
|
* Begin test code
|
|
|
|
*/
|
|
|
|
static const int kRenderTargetHeight = 1;
|
|
|
|
static const int kRenderTargetWidth = 1;
|
|
|
|
|
2019-08-21 13:38:10 +00:00
|
|
|
static std::unique_ptr<GrRenderTargetContext> random_render_target_context(GrContext* context,
|
|
|
|
SkRandom* random,
|
|
|
|
const GrCaps* caps) {
|
2016-05-19 21:01:05 +00:00
|
|
|
GrSurfaceOrigin origin = random->nextBool() ? kTopLeft_GrSurfaceOrigin
|
|
|
|
: kBottomLeft_GrSurfaceOrigin;
|
2015-05-13 15:51:49 +00:00
|
|
|
|
2019-07-09 18:06:58 +00:00
|
|
|
GrColorType ct = GrColorType::kRGBA_8888;
|
2019-07-30 16:49:10 +00:00
|
|
|
const GrBackendFormat format = caps->getDefaultBackendFormat(ct, GrRenderable::kYes);
|
2018-11-16 20:43:41 +00:00
|
|
|
|
2019-08-07 19:52:37 +00:00
|
|
|
int sampleCnt = random->nextBool() ? caps->getRenderTargetSampleCount(2, format) : 1;
|
2019-06-24 17:25:42 +00:00
|
|
|
// Above could be 0 if msaa isn't supported.
|
2020-02-07 15:36:46 +00:00
|
|
|
sampleCnt = std::max(1, sampleCnt);
|
2019-06-24 17:25:42 +00:00
|
|
|
|
2020-01-08 16:52:34 +00:00
|
|
|
return GrRenderTargetContext::Make(
|
|
|
|
context, GrColorType::kRGBA_8888, nullptr, SkBackingFit::kExact,
|
|
|
|
{kRenderTargetWidth, kRenderTargetHeight}, sampleCnt, GrMipMapped::kNo,
|
|
|
|
GrProtected::kNo, origin);
|
2013-02-12 21:45:24 +00:00
|
|
|
}
|
|
|
|
|
2017-01-31 18:50:44 +00:00
|
|
|
#if GR_TEST_UTILS
|
2016-06-23 21:07:00 +00:00
|
|
|
static void set_random_xpf(GrPaint* paint, GrProcessorTestData* d) {
|
2017-01-09 16:46:10 +00:00
|
|
|
paint->setXPFactory(GrXPFactoryTestFactory::Get(d));
|
2014-12-11 21:15:13 +00:00
|
|
|
}
|
|
|
|
|
2017-08-11 13:40:37 +00:00
|
|
|
static std::unique_ptr<GrFragmentProcessor> create_random_proc_tree(GrProcessorTestData* d,
|
|
|
|
int minLevels, int maxLevels) {
|
2015-09-10 13:57:05 +00:00
|
|
|
SkASSERT(1 <= minLevels);
|
|
|
|
SkASSERT(minLevels <= maxLevels);
|
|
|
|
|
|
|
|
// Return a leaf node if maxLevels is 1 or if we randomly chose to terminate.
|
|
|
|
// If returning a leaf node, make sure that it doesn't have children (e.g. another
|
|
|
|
// GrComposeEffect)
|
|
|
|
const float terminateProbability = 0.3f;
|
|
|
|
if (1 == minLevels) {
|
|
|
|
bool terminate = (1 == maxLevels) || (d->fRandom->nextF() < terminateProbability);
|
|
|
|
if (terminate) {
|
2017-08-11 13:40:37 +00:00
|
|
|
std::unique_ptr<GrFragmentProcessor> fp;
|
2015-09-10 13:57:05 +00:00
|
|
|
while (true) {
|
2017-07-24 14:16:19 +00:00
|
|
|
fp = GrFragmentProcessorTestFactory::Make(d);
|
2019-05-10 19:01:53 +00:00
|
|
|
if (!fp) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-09-10 13:57:05 +00:00
|
|
|
if (0 == fp->numChildProcessors()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If we didn't terminate, choose either the left or right subtree to fulfill
|
|
|
|
// the minLevels requirement of this tree; the other child can have as few levels as it wants.
|
2017-02-13 17:41:44 +00:00
|
|
|
// Also choose a random xfer mode.
|
2015-09-10 13:57:05 +00:00
|
|
|
if (minLevels > 1) {
|
|
|
|
--minLevels;
|
|
|
|
}
|
2017-08-11 13:40:37 +00:00
|
|
|
auto minLevelsChild = create_random_proc_tree(d, minLevels, maxLevels - 1);
|
|
|
|
std::unique_ptr<GrFragmentProcessor> otherChild(create_random_proc_tree(d, 1, maxLevels - 1));
|
2019-05-10 19:01:53 +00:00
|
|
|
if (!minLevelsChild || !otherChild) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-10-28 19:42:34 +00:00
|
|
|
SkBlendMode mode = static_cast<SkBlendMode>(d->fRandom->nextRangeU(0,
|
2017-02-13 17:41:44 +00:00
|
|
|
(int)SkBlendMode::kLastMode));
|
2017-08-11 13:40:37 +00:00
|
|
|
std::unique_ptr<GrFragmentProcessor> fp;
|
2015-09-10 13:57:05 +00:00
|
|
|
if (d->fRandom->nextF() < 0.5f) {
|
2016-06-09 15:01:03 +00:00
|
|
|
fp = GrXfermodeFragmentProcessor::MakeFromTwoProcessors(std::move(minLevelsChild),
|
|
|
|
std::move(otherChild), mode);
|
2015-09-10 13:57:05 +00:00
|
|
|
SkASSERT(fp);
|
|
|
|
} else {
|
2016-06-09 15:01:03 +00:00
|
|
|
fp = GrXfermodeFragmentProcessor::MakeFromTwoProcessors(std::move(otherChild),
|
|
|
|
std::move(minLevelsChild), mode);
|
2015-09-10 13:57:05 +00:00
|
|
|
SkASSERT(fp);
|
|
|
|
}
|
|
|
|
return fp;
|
|
|
|
}
|
|
|
|
|
2016-06-23 21:07:00 +00:00
|
|
|
static void set_random_color_coverage_stages(GrPaint* paint,
|
|
|
|
GrProcessorTestData* d,
|
2017-06-19 20:39:13 +00:00
|
|
|
int maxStages,
|
|
|
|
int maxTreeLevels) {
|
2015-09-10 13:57:05 +00:00
|
|
|
// Randomly choose to either create a linear pipeline of procs or create one proc tree
|
|
|
|
const float procTreeProbability = 0.5f;
|
|
|
|
if (d->fRandom->nextF() < procTreeProbability) {
|
2017-08-11 13:40:37 +00:00
|
|
|
std::unique_ptr<GrFragmentProcessor> fp(create_random_proc_tree(d, 2, maxTreeLevels));
|
2017-06-30 12:40:28 +00:00
|
|
|
if (fp) {
|
|
|
|
paint->addColorFragmentProcessor(std::move(fp));
|
|
|
|
}
|
2015-09-10 13:57:05 +00:00
|
|
|
} else {
|
|
|
|
int numProcs = d->fRandom->nextULessThan(maxStages + 1);
|
|
|
|
int numColorProcs = d->fRandom->nextULessThan(numProcs + 1);
|
|
|
|
|
2019-05-10 19:01:53 +00:00
|
|
|
for (int s = 0; s < numProcs; ++s) {
|
2017-08-11 13:40:37 +00:00
|
|
|
std::unique_ptr<GrFragmentProcessor> fp(GrFragmentProcessorTestFactory::Make(d));
|
2019-05-10 19:01:53 +00:00
|
|
|
if (!fp) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-09-10 13:57:05 +00:00
|
|
|
// finally add the stage to the correct pipeline in the drawstate
|
|
|
|
if (s < numColorProcs) {
|
2016-06-23 21:07:00 +00:00
|
|
|
paint->addColorFragmentProcessor(std::move(fp));
|
2015-09-10 13:57:05 +00:00
|
|
|
} else {
|
2016-06-23 21:07:00 +00:00
|
|
|
paint->addCoverageFragmentProcessor(std::move(fp));
|
2015-09-10 13:57:05 +00:00
|
|
|
}
|
2014-10-09 14:25:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-31 18:50:44 +00:00
|
|
|
#endif
|
2014-10-09 14:25:36 +00:00
|
|
|
|
2017-01-31 18:50:44 +00:00
|
|
|
#if !GR_TEST_UTILS
|
|
|
|
bool GrDrawingManager::ProgramUnitTest(GrContext*, int) { return true; }
|
|
|
|
#else
|
2017-06-19 20:39:13 +00:00
|
|
|
bool GrDrawingManager::ProgramUnitTest(GrContext* context, int maxStages, int maxLevels) {
|
2019-02-04 18:26:26 +00:00
|
|
|
GrDrawingManager* drawingManager = context->priv().drawingManager();
|
|
|
|
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
|
2015-11-11 20:01:09 +00:00
|
|
|
|
2020-02-12 15:53:51 +00:00
|
|
|
GrProcessorTestData::ViewInfo views[2];
|
2017-04-06 11:59:41 +00:00
|
|
|
|
2014-10-09 14:25:36 +00:00
|
|
|
// setup dummy textures
|
2019-05-09 20:28:04 +00:00
|
|
|
GrMipMapped mipMapped = GrMipMapped(context->priv().caps()->mipMapSupport());
|
2018-01-16 13:06:32 +00:00
|
|
|
{
|
2020-02-07 19:17:25 +00:00
|
|
|
static constexpr SkISize kDummyDims = {34, 18};
|
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::kYes);
|
2020-03-27 00:37:01 +00:00
|
|
|
auto proxy = proxyProvider->createProxy(format, kDummyDims, GrRenderable::kYes, 1,
|
2020-02-14 15:47:18 +00:00
|
|
|
mipMapped, SkBackingFit::kExact, SkBudgeted::kNo,
|
2020-02-12 15:53:51 +00:00
|
|
|
GrProtected::kNo, GrInternalSurfaceFlags::kNone);
|
2020-03-27 00:37:01 +00:00
|
|
|
GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(format, GrColorType::kRGBA_8888);
|
2020-02-12 15:53:51 +00:00
|
|
|
views[0] = {{std::move(proxy), kBottomLeft_GrSurfaceOrigin, swizzle},
|
|
|
|
GrColorType::kRGBA_8888, kPremul_SkAlphaType};
|
2018-01-16 13:06:32 +00:00
|
|
|
}
|
|
|
|
{
|
2020-02-07 19:17:25 +00:00
|
|
|
static constexpr SkISize kDummyDims = {16, 22};
|
2018-11-16 20:43:41 +00:00
|
|
|
const GrBackendFormat format =
|
2019-07-30 16:49:10 +00:00
|
|
|
context->priv().caps()->getDefaultBackendFormat(GrColorType::kAlpha_8,
|
|
|
|
GrRenderable::kNo);
|
2020-03-27 00:37:01 +00:00
|
|
|
auto proxy = proxyProvider->createProxy(format, kDummyDims, GrRenderable::kNo, 1, mipMapped,
|
|
|
|
SkBackingFit::kExact, SkBudgeted::kNo,
|
2020-02-12 15:53:51 +00:00
|
|
|
GrProtected::kNo, GrInternalSurfaceFlags::kNone);
|
2020-03-27 00:37:01 +00:00
|
|
|
GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(format, GrColorType::kAlpha_8);
|
2020-02-12 15:53:51 +00:00
|
|
|
views[1] = {{std::move(proxy), kTopLeft_GrSurfaceOrigin, swizzle},
|
2020-02-07 19:17:25 +00:00
|
|
|
GrColorType::kAlpha_8, kPremul_SkAlphaType};
|
2018-01-16 13:06:32 +00:00
|
|
|
}
|
2012-08-03 14:34:46 +00:00
|
|
|
|
2020-02-12 15:53:51 +00:00
|
|
|
if (!std::get<0>(views[0]) || !std::get<0>(views[1])) {
|
2014-10-09 14:25:36 +00:00
|
|
|
SkDebugf("Could not allocate dummy textures");
|
2014-07-17 17:50:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-10 17:03:50 +00:00
|
|
|
SkRandom random;
|
2016-04-05 17:57:13 +00:00
|
|
|
static const int NUM_TESTS = 1024;
|
2015-05-13 15:51:49 +00:00
|
|
|
for (int t = 0; t < NUM_TESTS; t++) {
|
2014-10-09 14:25:36 +00:00
|
|
|
// setup random render target(can fail)
|
2019-08-21 13:38:10 +00:00
|
|
|
auto renderTargetContext =
|
|
|
|
random_render_target_context(context, &random, context->priv().caps());
|
2016-10-27 18:47:55 +00:00
|
|
|
if (!renderTargetContext) {
|
|
|
|
SkDebugf("Could not allocate renderTargetContext");
|
2014-10-09 14:25:36 +00:00
|
|
|
return false;
|
|
|
|
}
|
2013-05-22 14:34:04 +00:00
|
|
|
|
2017-05-12 18:09:46 +00:00
|
|
|
GrPaint paint;
|
2020-02-12 15:53:51 +00:00
|
|
|
GrProcessorTestData ptd(&random, context, 2, views);
|
2017-06-19 20:39:13 +00:00
|
|
|
set_random_color_coverage_stages(&paint, &ptd, maxStages, maxLevels);
|
2017-05-12 18:09:46 +00:00
|
|
|
set_random_xpf(&paint, &ptd);
|
|
|
|
GrDrawRandomOp(&random, renderTargetContext.get(), std::move(paint));
|
2012-08-02 18:11:43 +00:00
|
|
|
}
|
2015-05-13 15:51:49 +00:00
|
|
|
// Flush everything, test passes if flush is successful(ie, no asserts are hit, no crashes)
|
2020-04-11 15:46:09 +00:00
|
|
|
if (drawingManager->flush(nullptr, 0, SkSurface::BackendSurfaceAccess::kNoAccess, GrFlushInfo(),
|
|
|
|
GrPrepareForExternalIORequests())) {
|
|
|
|
drawingManager->submitToGpu(false);
|
|
|
|
}
|
2015-09-14 19:26:33 +00:00
|
|
|
|
|
|
|
// Validate that GrFPs work correctly without an input.
|
2020-01-08 16:52:34 +00:00
|
|
|
auto renderTargetContext = GrRenderTargetContext::Make(
|
|
|
|
context, GrColorType::kRGBA_8888, nullptr, SkBackingFit::kExact,
|
|
|
|
{kRenderTargetWidth, kRenderTargetHeight});
|
2016-10-27 18:47:55 +00:00
|
|
|
if (!renderTargetContext) {
|
|
|
|
SkDebugf("Could not allocate a renderTargetContext");
|
2016-05-19 21:01:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-24 14:16:19 +00:00
|
|
|
int fpFactoryCnt = GrFragmentProcessorTestFactory::Count();
|
2015-09-14 19:26:33 +00:00
|
|
|
for (int i = 0; i < fpFactoryCnt; ++i) {
|
|
|
|
// Since FP factories internally randomize, call each 10 times.
|
|
|
|
for (int j = 0; j < 10; ++j) {
|
2020-02-12 15:53:51 +00:00
|
|
|
GrProcessorTestData ptd(&random, context, 2, views);
|
2015-09-14 19:26:33 +00:00
|
|
|
|
2017-05-12 18:09:46 +00:00
|
|
|
GrPaint paint;
|
|
|
|
paint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc));
|
2017-08-11 13:40:37 +00:00
|
|
|
auto fp = GrFragmentProcessorTestFactory::MakeIdx(i, &ptd);
|
|
|
|
auto blockFP = BlockInputFragmentProcessor::Make(std::move(fp));
|
2017-05-12 18:09:46 +00:00
|
|
|
paint.addColorFragmentProcessor(std::move(blockFP));
|
|
|
|
GrDrawRandomOp(&random, renderTargetContext.get(), std::move(paint));
|
2020-04-11 15:46:09 +00:00
|
|
|
if (drawingManager->flush(nullptr, 0, SkSurface::BackendSurfaceAccess::kNoAccess,
|
|
|
|
GrFlushInfo(), GrPrepareForExternalIORequests())) {
|
|
|
|
drawingManager->submitToGpu(false);
|
|
|
|
}
|
2015-09-14 19:26:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-02 18:11:43 +00:00
|
|
|
return true;
|
|
|
|
}
|
2017-01-31 18:50:44 +00:00
|
|
|
#endif
|
2011-08-16 15:45:58 +00:00
|
|
|
|
2019-10-24 14:23:26 +00:00
|
|
|
static int get_programs_max_stages(const sk_gpu_test::ContextInfo& ctxInfo) {
|
2020-03-19 12:47:44 +00:00
|
|
|
int maxStages = 6;
|
2020-03-19 19:54:28 +00:00
|
|
|
#ifdef SK_GL
|
|
|
|
GrContext* context = ctxInfo.grContext();
|
2019-10-24 14:23:26 +00:00
|
|
|
if (skiatest::IsGLContextType(ctxInfo.type())) {
|
|
|
|
GrGLGpu* gpu = static_cast<GrGLGpu*>(context->priv().getGpu());
|
|
|
|
if (kGLES_GrGLStandard == gpu->glStandard()) {
|
|
|
|
// We've had issues with driver crashes and HW limits being exceeded with many effects on
|
|
|
|
// Android devices. We have passes on ARM devices with the default number of stages.
|
|
|
|
// TODO When we run ES 3.00 GLSL in more places, test again
|
2017-05-15 15:00:58 +00:00
|
|
|
#ifdef SK_BUILD_FOR_ANDROID
|
2019-10-24 14:23:26 +00:00
|
|
|
if (kARM_GrGLVendor != gpu->ctxInfo().vendor()) {
|
|
|
|
maxStages = 1;
|
|
|
|
}
|
2017-05-15 15:00:58 +00:00
|
|
|
#endif
|
2019-10-24 14:23:26 +00:00
|
|
|
// On iOS we can exceed the maximum number of varyings. http://skbug.com/6627.
|
2017-05-26 19:56:32 +00:00
|
|
|
#ifdef SK_BUILD_FOR_IOS
|
2019-10-24 14:23:26 +00:00
|
|
|
maxStages = 3;
|
2017-05-15 15:00:58 +00:00
|
|
|
#endif
|
2019-10-24 14:23:26 +00:00
|
|
|
}
|
2020-04-16 20:01:25 +00:00
|
|
|
// On Angle D3D we will hit a limit of out variables if we use too many stages. This is
|
|
|
|
// particularly true on D3D9 with a low limit on varyings and the fact that every varying is
|
|
|
|
// packed as though it has 4 components.
|
|
|
|
if (ctxInfo.type() == sk_gpu_test::GrContextFactory::kANGLE_D3D9_ES2_ContextType) {
|
|
|
|
maxStages = 2;
|
|
|
|
} else if (ctxInfo.type() == sk_gpu_test::GrContextFactory::kANGLE_D3D11_ES2_ContextType) {
|
2019-10-24 14:23:26 +00:00
|
|
|
maxStages = 3;
|
|
|
|
}
|
2017-06-19 18:39:43 +00:00
|
|
|
}
|
2020-03-19 19:54:28 +00:00
|
|
|
#endif
|
2017-05-15 15:00:58 +00:00
|
|
|
return maxStages;
|
Add config options to run different GPU APIs to dm and nanobench
Add extended config specification form that can be used to run different
gpu backend with different APIs.
The configs can be specified with the form:
gpu(api=string,dit=bool,nvpr=bool,samples=int)
This replaces and removes the --gpuAPI flag.
All existing configs should still work.
Adds following documentation:
out/Debug/dm --help config
Flags:
--config: type: string default: 565 8888 gpu nonrendering
Options: 565 8888 debug gpu gpudebug gpudft gpunull msaa16 msaa4
nonrendering null nullgpu nvprmsaa16 nvprmsaa4 pdf pdf_poppler skp svg
xps or use extended form 'backend(option=value,...)'.
Extended form: 'backend(option=value,...)'
Possible backends and options:
gpu(api=string,dit=bool,nvpr=bool,samples=int) GPU backend
api type: string default: native.
Select graphics API to use with gpu backend.
Options:
native Use platform default OpenGL or OpenGL ES backend.
gl Use OpenGL.
gles Use OpenGL ES.
debug Use debug OpenGL.
null Use null OpenGL.
dit type: bool default: false.
Use device independent text.
nvpr type: bool default: false.
Use NV_path_rendering OpenGL and OpenGL ES extension.
samples type: int default: 0.
Use multisampling with N samples.
Predefined configs:
gpu = gpu()
msaa4 = gpu(samples=4)
msaa16 = gpu(samples=16)
nvprmsaa4 = gpu(nvpr=true,samples=4)
nvprmsaa16 = gpu(nvpr=true,samples=16)
gpudft = gpu(dit=true)
gpudebug = gpu(api=debug)
gpunull = gpu(api=null)
debug = gpu(api=debug)
nullgpu = gpu(api=null)
BUG=skia:2992
Committed: https://skia.googlesource.com/skia/+/e13ca329fca4c28cf4e078561f591ab27b743d23
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1490113005
Committed: https://skia.googlesource.com/skia/+/c8b4336444e7b90382e04e33665fb3b8490b825b
Committed: https://skia.googlesource.com/skia/+/9ebc3f0ee6db215dde461dc4777d85988cf272dd
Review URL: https://codereview.chromium.org/1490113005
2015-12-23 09:33:00 +00:00
|
|
|
}
|
|
|
|
|
2019-10-24 14:23:26 +00:00
|
|
|
static int get_programs_max_levels(const sk_gpu_test::ContextInfo& ctxInfo) {
|
2017-06-19 20:39:13 +00:00
|
|
|
// A full tree with 5 levels (31 nodes) may cause a program that exceeds shader limits
|
|
|
|
// (e.g. uniform or varying limits); maxTreeLevels should be a number from 1 to 4 inclusive.
|
|
|
|
int maxTreeLevels = 4;
|
2019-10-24 14:23:26 +00:00
|
|
|
if (skiatest::IsGLContextType(ctxInfo.type())) {
|
|
|
|
// On iOS we can exceed the maximum number of varyings. http://skbug.com/6627.
|
2017-06-19 20:39:13 +00:00
|
|
|
#ifdef SK_BUILD_FOR_IOS
|
2019-10-22 15:39:41 +00:00
|
|
|
maxTreeLevels = 2;
|
2019-12-20 21:20:54 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SK_BUILD_FOR_ANDROID
|
|
|
|
GrGLGpu* gpu = static_cast<GrGLGpu*>(ctxInfo.grContext()->priv().getGpu());
|
|
|
|
// Tecno Spark 3 Pro with Power VR Rogue GE8300 will fail shader compiles with
|
|
|
|
// no message if the shader is particularly long.
|
|
|
|
if (gpu->ctxInfo().vendor() == kImagination_GrGLVendor) {
|
|
|
|
maxTreeLevels = 3;
|
|
|
|
}
|
2019-10-24 14:23:26 +00:00
|
|
|
#endif
|
|
|
|
if (ctxInfo.type() == sk_gpu_test::GrContextFactory::kANGLE_D3D9_ES2_ContextType ||
|
|
|
|
ctxInfo.type() == sk_gpu_test::GrContextFactory::kANGLE_D3D11_ES2_ContextType) {
|
|
|
|
// On Angle D3D we will hit a limit of out variables if we use too many stages.
|
|
|
|
maxTreeLevels = 2;
|
|
|
|
}
|
2017-06-19 20:39:13 +00:00
|
|
|
}
|
|
|
|
return maxTreeLevels;
|
|
|
|
}
|
|
|
|
|
2019-10-24 14:23:26 +00:00
|
|
|
static void test_programs(skiatest::Reporter* reporter, const sk_gpu_test::ContextInfo& ctxInfo) {
|
|
|
|
int maxStages = get_programs_max_stages(ctxInfo);
|
Add config options to run different GPU APIs to dm and nanobench
Add extended config specification form that can be used to run different
gpu backend with different APIs.
The configs can be specified with the form:
gpu(api=string,dit=bool,nvpr=bool,samples=int)
This replaces and removes the --gpuAPI flag.
All existing configs should still work.
Adds following documentation:
out/Debug/dm --help config
Flags:
--config: type: string default: 565 8888 gpu nonrendering
Options: 565 8888 debug gpu gpudebug gpudft gpunull msaa16 msaa4
nonrendering null nullgpu nvprmsaa16 nvprmsaa4 pdf pdf_poppler skp svg
xps or use extended form 'backend(option=value,...)'.
Extended form: 'backend(option=value,...)'
Possible backends and options:
gpu(api=string,dit=bool,nvpr=bool,samples=int) GPU backend
api type: string default: native.
Select graphics API to use with gpu backend.
Options:
native Use platform default OpenGL or OpenGL ES backend.
gl Use OpenGL.
gles Use OpenGL ES.
debug Use debug OpenGL.
null Use null OpenGL.
dit type: bool default: false.
Use device independent text.
nvpr type: bool default: false.
Use NV_path_rendering OpenGL and OpenGL ES extension.
samples type: int default: 0.
Use multisampling with N samples.
Predefined configs:
gpu = gpu()
msaa4 = gpu(samples=4)
msaa16 = gpu(samples=16)
nvprmsaa4 = gpu(nvpr=true,samples=4)
nvprmsaa16 = gpu(nvpr=true,samples=16)
gpudft = gpu(dit=true)
gpudebug = gpu(api=debug)
gpunull = gpu(api=null)
debug = gpu(api=debug)
nullgpu = gpu(api=null)
BUG=skia:2992
Committed: https://skia.googlesource.com/skia/+/e13ca329fca4c28cf4e078561f591ab27b743d23
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1490113005
Committed: https://skia.googlesource.com/skia/+/c8b4336444e7b90382e04e33665fb3b8490b825b
Committed: https://skia.googlesource.com/skia/+/9ebc3f0ee6db215dde461dc4777d85988cf272dd
Review URL: https://codereview.chromium.org/1490113005
2015-12-23 09:33:00 +00:00
|
|
|
if (maxStages == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2019-10-24 14:23:26 +00:00
|
|
|
int maxLevels = get_programs_max_levels(ctxInfo);
|
2017-06-19 20:39:13 +00:00
|
|
|
if (maxLevels == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2017-07-10 17:03:50 +00:00
|
|
|
|
2017-06-19 20:39:13 +00:00
|
|
|
REPORTER_ASSERT(reporter, GrDrawingManager::ProgramUnitTest(ctxInfo.grContext(), maxStages,
|
|
|
|
maxLevels));
|
Add config options to run different GPU APIs to dm and nanobench
Add extended config specification form that can be used to run different
gpu backend with different APIs.
The configs can be specified with the form:
gpu(api=string,dit=bool,nvpr=bool,samples=int)
This replaces and removes the --gpuAPI flag.
All existing configs should still work.
Adds following documentation:
out/Debug/dm --help config
Flags:
--config: type: string default: 565 8888 gpu nonrendering
Options: 565 8888 debug gpu gpudebug gpudft gpunull msaa16 msaa4
nonrendering null nullgpu nvprmsaa16 nvprmsaa4 pdf pdf_poppler skp svg
xps or use extended form 'backend(option=value,...)'.
Extended form: 'backend(option=value,...)'
Possible backends and options:
gpu(api=string,dit=bool,nvpr=bool,samples=int) GPU backend
api type: string default: native.
Select graphics API to use with gpu backend.
Options:
native Use platform default OpenGL or OpenGL ES backend.
gl Use OpenGL.
gles Use OpenGL ES.
debug Use debug OpenGL.
null Use null OpenGL.
dit type: bool default: false.
Use device independent text.
nvpr type: bool default: false.
Use NV_path_rendering OpenGL and OpenGL ES extension.
samples type: int default: 0.
Use multisampling with N samples.
Predefined configs:
gpu = gpu()
msaa4 = gpu(samples=4)
msaa16 = gpu(samples=16)
nvprmsaa4 = gpu(nvpr=true,samples=4)
nvprmsaa16 = gpu(nvpr=true,samples=16)
gpudft = gpu(dit=true)
gpudebug = gpu(api=debug)
gpunull = gpu(api=null)
debug = gpu(api=debug)
nullgpu = gpu(api=null)
BUG=skia:2992
Committed: https://skia.googlesource.com/skia/+/e13ca329fca4c28cf4e078561f591ab27b743d23
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1490113005
Committed: https://skia.googlesource.com/skia/+/c8b4336444e7b90382e04e33665fb3b8490b825b
Committed: https://skia.googlesource.com/skia/+/9ebc3f0ee6db215dde461dc4777d85988cf272dd
Review URL: https://codereview.chromium.org/1490113005
2015-12-23 09:33:00 +00:00
|
|
|
}
|
|
|
|
|
2019-10-24 14:23:26 +00:00
|
|
|
DEF_GPUTEST(Programs, reporter, options) {
|
2015-03-16 18:56:29 +00:00
|
|
|
// Set a locale that would cause shader compilation to fail because of , as decimal separator.
|
|
|
|
// skbug 3330
|
|
|
|
#ifdef SK_BUILD_FOR_WIN
|
|
|
|
GrAutoLocaleSetter als("sv-SE");
|
|
|
|
#else
|
|
|
|
GrAutoLocaleSetter als("sv_SE.UTF-8");
|
|
|
|
#endif
|
|
|
|
|
2015-05-13 15:51:49 +00:00
|
|
|
// We suppress prints to avoid spew
|
2017-11-15 20:48:03 +00:00
|
|
|
GrContextOptions opts = options;
|
2015-05-13 15:51:49 +00:00
|
|
|
opts.fSuppressPrints = true;
|
2016-03-31 01:56:19 +00:00
|
|
|
sk_gpu_test::GrContextFactory debugFactory(opts);
|
2019-10-24 14:23:26 +00:00
|
|
|
skiatest::RunWithGPUTestContexts(test_programs, &skiatest::IsRenderingGLOrMetalContextType,
|
|
|
|
reporter, opts);
|
2011-08-16 15:45:58 +00:00
|
|
|
}
|