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.
|
|
|
|
*/
|
|
|
|
|
2012-08-03 14:34:46 +00:00
|
|
|
// This is a GPU-backend specific test. It relies on static intializers to work
|
2012-08-02 14:03:32 +00:00
|
|
|
|
2012-08-03 14:54:45 +00:00
|
|
|
#include "SkTypes.h"
|
|
|
|
|
|
|
|
#if SK_SUPPORT_GPU && SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
|
|
|
|
|
2015-03-16 21:00:52 +00:00
|
|
|
#include "GrAutoLocaleSetter.h"
|
2015-05-13 15:51:49 +00:00
|
|
|
#include "GrBatchTest.h"
|
2013-02-04 16:13:32 +00:00
|
|
|
#include "GrContextFactory.h"
|
2014-11-12 16:35:25 +00:00
|
|
|
#include "GrInvariantOutput.h"
|
2015-01-22 18:16:09 +00:00
|
|
|
#include "GrPipeline.h"
|
2015-05-29 17:26:19 +00:00
|
|
|
#include "GrResourceProvider.h"
|
2014-11-06 20:57:13 +00:00
|
|
|
#include "GrTest.h"
|
2014-12-09 19:15:43 +00:00
|
|
|
#include "GrXferProcessor.h"
|
2013-05-22 14:34:04 +00:00
|
|
|
#include "SkChecksum.h"
|
2012-11-21 22:38:36 +00:00
|
|
|
#include "SkRandom.h"
|
2012-08-02 18:11:43 +00:00
|
|
|
#include "Test.h"
|
2015-08-07 18:42:16 +00:00
|
|
|
|
2015-08-13 21:55:50 +00:00
|
|
|
#include "batches/GrDrawBatch.h"
|
2015-08-07 18:42:16 +00:00
|
|
|
|
2014-11-06 20:57:13 +00:00
|
|
|
#include "effects/GrConfigConversionEffect.h"
|
2014-12-09 19:15:43 +00:00
|
|
|
#include "effects/GrPorterDuffXferProcessor.h"
|
2015-09-10 13:57:05 +00:00
|
|
|
#include "effects/GrXfermodeFragmentProcessor.h"
|
2015-08-07 18:42:16 +00:00
|
|
|
|
2014-12-22 19:44:19 +00:00
|
|
|
#include "gl/GrGLGpu.h"
|
2014-11-06 20:57:13 +00:00
|
|
|
#include "gl/GrGLPathRendering.h"
|
|
|
|
#include "gl/builders/GrGLProgramBuilder.h"
|
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
|
|
|
|
2014-12-04 19:35:33 +00:00
|
|
|
class GLBigKeyProcessor : public GrGLFragmentProcessor {
|
|
|
|
public:
|
|
|
|
GLBigKeyProcessor(const GrProcessor&) {}
|
|
|
|
|
2015-07-22 22:08:53 +00:00
|
|
|
virtual void emitCode(EmitArgs& args) override {
|
2015-05-13 15:51:49 +00:00
|
|
|
// pass through
|
2015-07-22 22:08:53 +00:00
|
|
|
GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
|
2015-09-14 19:26:33 +00:00
|
|
|
if (args.fInputColor) {
|
|
|
|
fsBuilder->codeAppendf("%s = %s;\n", args.fOutputColor, args.fInputColor);
|
|
|
|
} else {
|
|
|
|
fsBuilder->codeAppendf("%s = vec4(1.0);\n", args.fOutputColor);
|
|
|
|
}
|
2015-05-13 15:51:49 +00:00
|
|
|
}
|
2014-12-04 19:35:33 +00:00
|
|
|
|
2015-04-28 15:48:20 +00:00
|
|
|
static void GenKey(const GrProcessor& processor, const GrGLSLCaps&, GrProcessorKeyBuilder* b) {
|
2014-12-04 19:35:33 +00:00
|
|
|
for (uint32_t i = 0; i < kMaxKeySize; i++) {
|
|
|
|
b->add32(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef GrGLFragmentProcessor INHERITED;
|
|
|
|
};
|
2014-10-07 15:37:36 +00:00
|
|
|
|
2014-10-09 14:25:36 +00:00
|
|
|
class BigKeyProcessor : public GrFragmentProcessor {
|
|
|
|
public:
|
|
|
|
static GrFragmentProcessor* Create() {
|
2015-10-21 13:57:30 +00:00
|
|
|
return new BigKeyProcessor;
|
2014-10-07 15:37:36 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* name() const override { return "Big Ole Key"; }
|
2014-10-07 15:37:36 +00:00
|
|
|
|
2015-08-18 18:29:31 +00:00
|
|
|
GrGLFragmentProcessor* onCreateGLInstance() const override {
|
2015-08-26 20:07:48 +00:00
|
|
|
return new GLBigKeyProcessor(*this);
|
2014-12-04 19:35:33 +00:00
|
|
|
}
|
2014-10-07 15:37:36 +00:00
|
|
|
|
2014-10-09 14:25:36 +00:00
|
|
|
private:
|
2014-12-04 19:35:33 +00:00
|
|
|
BigKeyProcessor() {
|
|
|
|
this->initClassID<BigKeyProcessor>();
|
|
|
|
}
|
2015-08-04 14:59:37 +00:00
|
|
|
virtual void onGetGLProcessorKey(const GrGLSLCaps& caps,
|
|
|
|
GrProcessorKeyBuilder* b) const override {
|
|
|
|
GLBigKeyProcessor::GenKey(*this, caps, b);
|
|
|
|
}
|
2015-03-26 01:17:31 +00:00
|
|
|
bool onIsEqual(const GrFragmentProcessor&) const override { return true; }
|
|
|
|
void onComputeInvariantOutput(GrInvariantOutput* inout) const override { }
|
2014-10-07 15:37:36 +00:00
|
|
|
|
2014-10-09 14:25:36 +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
|
|
|
|
2015-08-29 01:46:56 +00:00
|
|
|
const GrFragmentProcessor* BigKeyProcessor::TestCreate(GrProcessorTestData*) {
|
2014-10-09 14:25:36 +00:00
|
|
|
return BigKeyProcessor::Create();
|
|
|
|
}
|
2014-10-07 15:37:36 +00:00
|
|
|
|
2015-09-14 19:26:33 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class BlockInputFragmentProcessor : public GrFragmentProcessor {
|
|
|
|
public:
|
|
|
|
static GrFragmentProcessor* Create(const GrFragmentProcessor* fp) {
|
|
|
|
return new BlockInputFragmentProcessor(fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* name() const override { return "Block Input"; }
|
|
|
|
|
|
|
|
GrGLFragmentProcessor* onCreateGLInstance() const override { return new GLFP; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
class GLFP : public GrGLFragmentProcessor {
|
|
|
|
public:
|
|
|
|
void emitCode(EmitArgs& args) override {
|
2015-09-24 13:00:00 +00:00
|
|
|
this->emitChild(0, nullptr, args);
|
2015-09-14 19:26:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef GrGLFragmentProcessor INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
BlockInputFragmentProcessor(const GrFragmentProcessor* child) {
|
|
|
|
this->initClassID<BlockInputFragmentProcessor>();
|
|
|
|
this->registerChildProcessor(child);
|
|
|
|
}
|
|
|
|
|
|
|
|
void onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override {}
|
|
|
|
|
|
|
|
bool onIsEqual(const GrFragmentProcessor&) const override { return true; }
|
|
|
|
|
|
|
|
void onComputeInvariantOutput(GrInvariantOutput* inout) const override {
|
|
|
|
inout->setToOther(kRGBA_GrColorComponentFlags, GrColor_WHITE,
|
|
|
|
GrInvariantOutput::kWillNot_ReadInput);
|
|
|
|
this->childProcessor(0).computeInvariantOutput(inout);
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef GrFragmentProcessor INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-10-09 14:25:36 +00:00
|
|
|
/*
|
|
|
|
* Begin test code
|
|
|
|
*/
|
|
|
|
static const int kRenderTargetHeight = 1;
|
|
|
|
static const int kRenderTargetWidth = 1;
|
|
|
|
|
2015-05-29 17:26:19 +00:00
|
|
|
static GrRenderTarget* random_render_target(GrTextureProvider* textureProvider, SkRandom* random,
|
2015-05-19 16:29:46 +00:00
|
|
|
const GrCaps* caps) {
|
2014-10-09 14:25:36 +00:00
|
|
|
// setup render target
|
|
|
|
GrTextureParams params;
|
2014-10-28 21:33:06 +00:00
|
|
|
GrSurfaceDesc texDesc;
|
2014-10-09 14:25:36 +00:00
|
|
|
texDesc.fWidth = kRenderTargetWidth;
|
|
|
|
texDesc.fHeight = kRenderTargetHeight;
|
2014-10-28 21:33:06 +00:00
|
|
|
texDesc.fFlags = kRenderTarget_GrSurfaceFlag;
|
2014-10-09 14:25:36 +00:00
|
|
|
texDesc.fConfig = kRGBA_8888_GrPixelConfig;
|
|
|
|
texDesc.fOrigin = random->nextBool() == true ? kTopLeft_GrSurfaceOrigin :
|
|
|
|
kBottomLeft_GrSurfaceOrigin;
|
2015-05-13 19:15:14 +00:00
|
|
|
texDesc.fSampleCnt = random->nextBool() == true ? SkTMin(4, caps->maxSampleCount()) : 0;
|
2015-05-13 15:51:49 +00:00
|
|
|
|
2015-02-19 15:24:21 +00:00
|
|
|
GrUniqueKey key;
|
|
|
|
static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
|
2015-05-13 15:51:49 +00:00
|
|
|
GrUniqueKey::Builder builder(&key, kDomain, 2);
|
2015-01-23 12:24:04 +00:00
|
|
|
builder[0] = texDesc.fOrigin;
|
2015-05-13 15:51:49 +00:00
|
|
|
builder[1] = texDesc.fSampleCnt;
|
2015-01-23 12:24:04 +00:00
|
|
|
builder.finish();
|
2014-10-09 14:25:36 +00:00
|
|
|
|
2015-05-29 17:26:19 +00:00
|
|
|
GrTexture* texture = textureProvider->findAndRefTextureByUniqueKey(key);
|
2014-10-12 12:40:00 +00:00
|
|
|
if (!texture) {
|
2015-05-29 17:26:19 +00:00
|
|
|
texture = textureProvider->createTexture(texDesc, true);
|
2015-02-02 21:00:10 +00:00
|
|
|
if (texture) {
|
2015-05-29 17:26:19 +00:00
|
|
|
textureProvider->assignUniqueKeyToTexture(key, texture);
|
2014-10-09 14:25:36 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-27 14:41:13 +00:00
|
|
|
return texture ? texture->asRenderTarget() : nullptr;
|
2013-02-12 21:45:24 +00:00
|
|
|
}
|
|
|
|
|
2015-07-08 21:26:19 +00:00
|
|
|
static void set_random_xpf(GrPipelineBuilder* pipelineBuilder, GrProcessorTestData* d) {
|
2015-09-14 19:26:33 +00:00
|
|
|
SkAutoTUnref<const GrXPFactory> xpf(GrProcessorTestFactory<GrXPFactory>::Create(d));
|
2014-12-11 21:15:13 +00:00
|
|
|
SkASSERT(xpf);
|
2015-01-22 18:16:09 +00:00
|
|
|
pipelineBuilder->setXPFactory(xpf.get());
|
2014-12-11 21:15:13 +00:00
|
|
|
}
|
|
|
|
|
2015-09-10 13:57:05 +00:00
|
|
|
static const GrFragmentProcessor* create_random_proc_tree(GrProcessorTestData* d,
|
|
|
|
int minLevels, int maxLevels) {
|
|
|
|
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) {
|
|
|
|
const GrFragmentProcessor* fp;
|
|
|
|
while (true) {
|
2015-09-14 19:26:33 +00:00
|
|
|
fp = GrProcessorTestFactory<GrFragmentProcessor>::Create(d);
|
2015-09-10 13:57:05 +00:00
|
|
|
SkASSERT(fp);
|
|
|
|
if (0 == fp->numChildProcessors()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fp->unref();
|
|
|
|
}
|
|
|
|
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.
|
|
|
|
// Also choose a random xfer mode that's supported by CreateFrom2Procs().
|
|
|
|
if (minLevels > 1) {
|
|
|
|
--minLevels;
|
|
|
|
}
|
|
|
|
SkAutoTUnref<const GrFragmentProcessor> minLevelsChild(create_random_proc_tree(d, minLevels,
|
|
|
|
maxLevels - 1));
|
|
|
|
SkAutoTUnref<const GrFragmentProcessor> otherChild(create_random_proc_tree(d, 1,
|
|
|
|
maxLevels - 1));
|
|
|
|
SkXfermode::Mode mode = static_cast<SkXfermode::Mode>(d->fRandom->nextRangeU(0,
|
|
|
|
SkXfermode::kLastCoeffMode));
|
|
|
|
const GrFragmentProcessor* fp;
|
|
|
|
if (d->fRandom->nextF() < 0.5f) {
|
|
|
|
fp = GrXfermodeFragmentProcessor::CreateFromTwoProcessors(minLevelsChild, otherChild, mode);
|
|
|
|
SkASSERT(fp);
|
|
|
|
} else {
|
|
|
|
fp = GrXfermodeFragmentProcessor::CreateFromTwoProcessors(otherChild, minLevelsChild, mode);
|
|
|
|
SkASSERT(fp);
|
|
|
|
}
|
|
|
|
return fp;
|
|
|
|
}
|
|
|
|
|
2015-07-08 21:26:19 +00:00
|
|
|
static void set_random_color_coverage_stages(GrPipelineBuilder* pipelineBuilder,
|
|
|
|
GrProcessorTestData* d, int maxStages) {
|
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) {
|
|
|
|
// A full tree with 5 levels (31 nodes) may exceed the max allowed length of the gl
|
|
|
|
// processor key; maxTreeLevels should be a number from 1 to 4 inclusive.
|
|
|
|
const int maxTreeLevels = 4;
|
2014-11-19 16:23:49 +00:00
|
|
|
SkAutoTUnref<const GrFragmentProcessor> fp(
|
2015-09-10 13:57:05 +00:00
|
|
|
create_random_proc_tree(d, 2, maxTreeLevels));
|
|
|
|
pipelineBuilder->addColorFragmentProcessor(fp);
|
|
|
|
} else {
|
|
|
|
int numProcs = d->fRandom->nextULessThan(maxStages + 1);
|
|
|
|
int numColorProcs = d->fRandom->nextULessThan(numProcs + 1);
|
|
|
|
|
|
|
|
for (int s = 0; s < numProcs;) {
|
|
|
|
SkAutoTUnref<const GrFragmentProcessor> fp(
|
2015-09-15 22:33:27 +00:00
|
|
|
GrProcessorTestFactory<GrFragmentProcessor>::Create(d));
|
2015-09-10 13:57:05 +00:00
|
|
|
SkASSERT(fp);
|
|
|
|
|
|
|
|
// finally add the stage to the correct pipeline in the drawstate
|
|
|
|
if (s < numColorProcs) {
|
|
|
|
pipelineBuilder->addColorFragmentProcessor(fp);
|
|
|
|
} else {
|
|
|
|
pipelineBuilder->addCoverageFragmentProcessor(fp);
|
|
|
|
}
|
|
|
|
++s;
|
2014-10-09 14:25:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-22 18:16:09 +00:00
|
|
|
static void set_random_state(GrPipelineBuilder* pipelineBuilder, SkRandom* random) {
|
2014-10-09 14:25:36 +00:00
|
|
|
int state = 0;
|
2015-04-27 17:07:04 +00:00
|
|
|
for (int i = 1; i <= GrPipelineBuilder::kLast_Flag; i <<= 1) {
|
2014-10-09 14:25:36 +00:00
|
|
|
state |= random->nextBool() * i;
|
|
|
|
}
|
2015-05-13 15:51:49 +00:00
|
|
|
|
|
|
|
// If we don't have an MSAA rendertarget then we have to disable useHWAA
|
|
|
|
if ((state | GrPipelineBuilder::kHWAntialias_Flag) &&
|
2015-06-12 15:59:45 +00:00
|
|
|
!pipelineBuilder->getRenderTarget()->isUnifiedMultisampled()) {
|
2015-05-13 15:51:49 +00:00
|
|
|
state &= ~GrPipelineBuilder::kHWAntialias_Flag;
|
|
|
|
}
|
2015-01-22 18:16:09 +00:00
|
|
|
pipelineBuilder->enableState(state);
|
2014-10-09 14:25:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// right now, the only thing we seem to care about in drawState's stencil is 'doesWrite()'
|
2015-01-22 18:16:09 +00:00
|
|
|
static void set_random_stencil(GrPipelineBuilder* pipelineBuilder, SkRandom* random) {
|
2014-10-09 14:25:36 +00:00
|
|
|
GR_STATIC_CONST_SAME_STENCIL(kDoesWriteStencil,
|
|
|
|
kReplace_StencilOp,
|
|
|
|
kReplace_StencilOp,
|
|
|
|
kAlways_StencilFunc,
|
|
|
|
0xffff,
|
|
|
|
0xffff,
|
|
|
|
0xffff);
|
|
|
|
GR_STATIC_CONST_SAME_STENCIL(kDoesNotWriteStencil,
|
|
|
|
kKeep_StencilOp,
|
|
|
|
kKeep_StencilOp,
|
|
|
|
kNever_StencilFunc,
|
|
|
|
0xffff,
|
|
|
|
0xffff,
|
|
|
|
0xffff);
|
|
|
|
|
|
|
|
if (random->nextBool()) {
|
2015-01-22 18:16:09 +00:00
|
|
|
pipelineBuilder->setStencil(kDoesWriteStencil);
|
2014-10-09 14:25:36 +00:00
|
|
|
} else {
|
2015-01-22 18:16:09 +00:00
|
|
|
pipelineBuilder->setStencil(kDoesNotWriteStencil);
|
2014-10-09 14:25:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-29 17:26:19 +00:00
|
|
|
bool GrDrawTarget::programUnitTest(GrContext* context, int maxStages) {
|
2014-10-09 14:25:36 +00:00
|
|
|
// setup dummy textures
|
2014-10-28 21:33:06 +00:00
|
|
|
GrSurfaceDesc dummyDesc;
|
2015-07-16 17:00:28 +00:00
|
|
|
dummyDesc.fFlags = kRenderTarget_GrSurfaceFlag;
|
2013-02-07 14:43:04 +00:00
|
|
|
dummyDesc.fConfig = kSkia8888_GrPixelConfig;
|
2012-08-03 14:34:46 +00:00
|
|
|
dummyDesc.fWidth = 34;
|
|
|
|
dummyDesc.fHeight = 18;
|
2015-05-29 17:26:19 +00:00
|
|
|
SkAutoTUnref<GrTexture> dummyTexture1(
|
2015-08-27 14:41:13 +00:00
|
|
|
context->textureProvider()->createTexture(dummyDesc, false, nullptr, 0));
|
2014-10-28 21:33:06 +00:00
|
|
|
dummyDesc.fFlags = kNone_GrSurfaceFlags;
|
2012-08-03 14:34:46 +00:00
|
|
|
dummyDesc.fConfig = kAlpha_8_GrPixelConfig;
|
|
|
|
dummyDesc.fWidth = 16;
|
|
|
|
dummyDesc.fHeight = 22;
|
2015-05-29 17:26:19 +00:00
|
|
|
SkAutoTUnref<GrTexture> dummyTexture2(
|
2015-08-27 14:41:13 +00:00
|
|
|
context->textureProvider()->createTexture(dummyDesc, false, nullptr, 0));
|
2012-08-03 14:34:46 +00:00
|
|
|
|
2014-07-17 17:50:59 +00:00
|
|
|
if (!dummyTexture1 || ! dummyTexture2) {
|
2014-10-09 14:25:36 +00:00
|
|
|
SkDebugf("Could not allocate dummy textures");
|
2014-07-17 17:50:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-10-09 14:25:36 +00:00
|
|
|
GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()};
|
2012-08-02 18:11:43 +00:00
|
|
|
|
2014-11-19 17:38:51 +00:00
|
|
|
// dummy scissor state
|
2014-12-17 21:43:13 +00:00
|
|
|
GrScissorState scissor;
|
2014-11-19 17:38:51 +00:00
|
|
|
|
2015-05-13 15:51:49 +00:00
|
|
|
// wide open clip
|
2015-02-23 22:44:57 +00:00
|
|
|
GrClip clip;
|
2013-05-22 14:34:04 +00:00
|
|
|
|
2014-10-09 14:25:36 +00:00
|
|
|
SkRandom random;
|
2015-05-13 15:51:49 +00:00
|
|
|
static const int NUM_TESTS = 2048;
|
|
|
|
for (int t = 0; t < NUM_TESTS; t++) {
|
2014-10-09 14:25:36 +00:00
|
|
|
// setup random render target(can fail)
|
2015-05-29 17:26:19 +00:00
|
|
|
SkAutoTUnref<GrRenderTarget> rt(random_render_target(
|
2015-07-31 20:59:30 +00:00
|
|
|
context->textureProvider(), &random, this->caps()));
|
2014-11-06 20:57:13 +00:00
|
|
|
if (!rt.get()) {
|
2014-10-09 14:25:36 +00:00
|
|
|
SkDebugf("Could not allocate render target");
|
|
|
|
return false;
|
|
|
|
}
|
2013-05-22 14:34:04 +00:00
|
|
|
|
2015-01-22 18:16:09 +00:00
|
|
|
GrPipelineBuilder pipelineBuilder;
|
|
|
|
pipelineBuilder.setRenderTarget(rt.get());
|
2015-02-23 22:44:57 +00:00
|
|
|
pipelineBuilder.setClip(clip);
|
2013-05-22 14:34:04 +00:00
|
|
|
|
2015-08-13 20:34:48 +00:00
|
|
|
SkAutoTUnref<GrDrawBatch> batch(GrRandomDrawBatch(&random, context));
|
2015-05-13 15:51:49 +00:00
|
|
|
SkASSERT(batch);
|
2014-09-22 20:17:02 +00:00
|
|
|
|
2015-10-06 15:40:50 +00:00
|
|
|
GrProcessorTestData ptd(&random, context, fGpu->caps(), dummyTextures);
|
2015-07-08 21:26:19 +00:00
|
|
|
set_random_color_coverage_stages(&pipelineBuilder, &ptd, maxStages);
|
|
|
|
set_random_xpf(&pipelineBuilder, &ptd);
|
2015-01-22 18:16:09 +00:00
|
|
|
set_random_state(&pipelineBuilder, &random);
|
|
|
|
set_random_stencil(&pipelineBuilder, &random);
|
2014-10-09 14:25:36 +00:00
|
|
|
|
2015-07-13 15:08:25 +00:00
|
|
|
this->drawBatch(pipelineBuilder, batch);
|
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)
|
|
|
|
this->flush();
|
2015-09-14 19:26:33 +00:00
|
|
|
|
|
|
|
// Validate that GrFPs work correctly without an input.
|
|
|
|
GrSurfaceDesc rtDesc;
|
|
|
|
rtDesc.fWidth = kRenderTargetWidth;
|
|
|
|
rtDesc.fHeight = kRenderTargetHeight;
|
|
|
|
rtDesc.fFlags = kRenderTarget_GrSurfaceFlag;
|
|
|
|
rtDesc.fConfig = kRGBA_8888_GrPixelConfig;
|
|
|
|
SkAutoTUnref<GrRenderTarget> rt(
|
|
|
|
fContext->textureProvider()->createTexture(rtDesc, false)->asRenderTarget());
|
|
|
|
int fpFactoryCnt = GrProcessorTestFactory<GrFragmentProcessor>::Count();
|
|
|
|
for (int i = 0; i < fpFactoryCnt; ++i) {
|
|
|
|
// Since FP factories internally randomize, call each 10 times.
|
|
|
|
for (int j = 0; j < 10; ++j) {
|
|
|
|
SkAutoTUnref<GrDrawBatch> batch(GrRandomDrawBatch(&random, context));
|
|
|
|
SkASSERT(batch);
|
2015-10-06 15:40:50 +00:00
|
|
|
GrProcessorTestData ptd(&random, context, this->caps(), dummyTextures);
|
2015-09-14 19:26:33 +00:00
|
|
|
GrPipelineBuilder builder;
|
|
|
|
builder.setXPFactory(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->unref();
|
|
|
|
builder.setRenderTarget(rt);
|
|
|
|
builder.setClip(clip);
|
|
|
|
|
|
|
|
SkAutoTUnref<const GrFragmentProcessor> fp(
|
|
|
|
GrProcessorTestFactory<GrFragmentProcessor>::CreateIdx(i, &ptd));
|
|
|
|
SkAutoTUnref<const GrFragmentProcessor> blockFP(
|
|
|
|
BlockInputFragmentProcessor::Create(fp));
|
|
|
|
builder.addColorFragmentProcessor(blockFP);
|
|
|
|
|
|
|
|
this->drawBatch(builder, batch);
|
|
|
|
this->flush();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-02 18:11:43 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-08-16 15:45:58 +00:00
|
|
|
|
2014-01-10 22:08:27 +00:00
|
|
|
DEF_GPUTEST(GLPrograms, reporter, factory) {
|
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
|
2015-05-22 21:01:46 +00:00
|
|
|
GrContextOptions opts;
|
2015-05-13 15:51:49 +00:00
|
|
|
opts.fSuppressPrints = true;
|
|
|
|
GrContextFactory debugFactory(opts);
|
2013-02-04 16:13:32 +00:00
|
|
|
for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) {
|
2015-05-13 15:51:49 +00:00
|
|
|
GrContext* context = debugFactory.get(static_cast<GrContextFactory::GLContextType>(type));
|
2014-09-05 20:34:00 +00:00
|
|
|
if (context) {
|
2014-12-16 15:33:49 +00:00
|
|
|
GrGLGpu* gpu = static_cast<GrGLGpu*>(context->getGpu());
|
2014-10-09 20:12:35 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* For the time being, we only support the test with desktop GL or for android on
|
|
|
|
* ARM platforms
|
|
|
|
* TODO When we run ES 3.00 GLSL in more places, test again
|
|
|
|
*/
|
|
|
|
int maxStages;
|
|
|
|
if (kGL_GrGLStandard == gpu->glStandard() ||
|
|
|
|
kARM_GrGLVendor == gpu->ctxInfo().vendor()) {
|
|
|
|
maxStages = 6;
|
|
|
|
} else if (kTegra3_GrGLRenderer == gpu->ctxInfo().renderer() ||
|
|
|
|
kOther_GrGLRenderer == gpu->ctxInfo().renderer()) {
|
|
|
|
maxStages = 1;
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
2013-02-04 18:39:24 +00:00
|
|
|
#if SK_ANGLE
|
|
|
|
// Some long shaders run out of temporary registers in the D3D compiler on ANGLE.
|
|
|
|
if (type == GrContextFactory::kANGLE_GLContextType) {
|
2015-02-17 19:18:38 +00:00
|
|
|
maxStages = 2;
|
2013-02-04 18:39:24 +00:00
|
|
|
}
|
2015-08-27 17:38:39 +00:00
|
|
|
#endif
|
|
|
|
#if SK_COMMAND_BUFFER
|
|
|
|
// Some long shaders run out of temporary registers in the D3D compiler on ANGLE.
|
|
|
|
// TODO(hendrikw): This only needs to happen with the ANGLE comand buffer backend.
|
|
|
|
if (type == GrContextFactory::kCommandBuffer_GLContextType) {
|
|
|
|
maxStages = 2;
|
|
|
|
}
|
2013-02-04 18:39:24 +00:00
|
|
|
#endif
|
2014-11-06 20:57:13 +00:00
|
|
|
GrTestTarget target;
|
|
|
|
context->getTestTarget(&target);
|
2015-05-29 17:26:19 +00:00
|
|
|
REPORTER_ASSERT(reporter, target.target()->programUnitTest(context, maxStages));
|
2013-02-04 16:13:32 +00:00
|
|
|
}
|
|
|
|
}
|
2011-08-16 15:45:58 +00:00
|
|
|
}
|
|
|
|
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif
|