2011-08-16 19:45:58 +04: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 18:34:46 +04:00
|
|
|
// This is a GPU-backend specific test. It relies on static intializers to work
|
2012-08-02 18:03:32 +04:00
|
|
|
|
2012-08-03 18:54:45 +04:00
|
|
|
#include "SkTypes.h"
|
|
|
|
|
|
|
|
#if SK_SUPPORT_GPU && SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
|
|
|
|
|
2012-05-31 19:07:19 +04:00
|
|
|
#include "gl/GrGpuGL.h"
|
2012-10-25 23:00:29 +04:00
|
|
|
#include "GrBackendEffectFactory.h"
|
2013-02-04 20:13:32 +04:00
|
|
|
#include "GrContextFactory.h"
|
2013-03-20 23:19:53 +04:00
|
|
|
#include "GrDrawEffect.h"
|
2012-08-27 16:53:13 +04:00
|
|
|
#include "effects/GrConfigConversionEffect.h"
|
2012-08-07 21:36:29 +04:00
|
|
|
|
2012-11-22 02:38:36 +04:00
|
|
|
#include "SkRandom.h"
|
2012-08-02 22:11:43 +04:00
|
|
|
#include "Test.h"
|
|
|
|
|
2013-03-27 22:14:57 +04:00
|
|
|
void GrGLProgramDesc::setRandom(SkMWCRandom* random,
|
|
|
|
const GrGpuGL* gpu,
|
2013-03-30 00:30:50 +04:00
|
|
|
const GrTexture* dstTexture,
|
2013-05-09 17:45:02 +04:00
|
|
|
const GrEffectStage* stages[GrDrawState::kNumStages],
|
2013-04-02 00:06:51 +04:00
|
|
|
int currAttribIndex) {
|
2013-02-13 01:45:24 +04:00
|
|
|
fEmitsPointSize = random->nextBool();
|
2013-04-02 00:06:51 +04:00
|
|
|
|
|
|
|
fPositionAttributeIndex = 0;
|
|
|
|
|
2013-04-02 11:01:34 +04:00
|
|
|
// if the effects have used up all off the available attributes,
|
2013-04-02 00:06:51 +04:00
|
|
|
// don't try to use color or coverage attributes as input
|
|
|
|
do {
|
|
|
|
fColorInput = random->nextULessThan(kColorInputCnt);
|
2013-04-02 11:01:34 +04:00
|
|
|
} while (GrDrawState::kMaxVertexAttribCnt <= currAttribIndex &&
|
2013-04-02 00:06:51 +04:00
|
|
|
kAttribute_ColorInput == fColorInput);
|
|
|
|
fColorAttributeIndex = (fColorInput == kAttribute_ColorInput) ? currAttribIndex++ : -1;
|
|
|
|
|
|
|
|
do {
|
|
|
|
fCoverageInput = random->nextULessThan(kColorInputCnt);
|
|
|
|
} while (GrDrawState::kMaxVertexAttribCnt <= currAttribIndex &&
|
|
|
|
kAttribute_ColorInput == fCoverageInput);
|
|
|
|
fCoverageAttributeIndex = (fCoverageInput == kAttribute_ColorInput) ? currAttribIndex++ : -1;
|
2013-02-13 01:45:24 +04:00
|
|
|
|
2013-04-19 19:03:21 +04:00
|
|
|
fColorFilterXfermode = random->nextULessThan(SkXfermode::kLastCoeffMode + 1);
|
2013-02-13 01:45:24 +04:00
|
|
|
|
|
|
|
fFirstCoverageStage = random->nextULessThan(GrDrawState::kNumStages);
|
|
|
|
|
|
|
|
#if GR_GL_EXPERIMENTAL_GS
|
2013-03-25 19:38:39 +04:00
|
|
|
fExperimentalGS = gpu->caps()->geometryShaderSupport() && random->nextBool();
|
2013-02-13 01:45:24 +04:00
|
|
|
#endif
|
|
|
|
|
2013-03-26 20:49:37 +04:00
|
|
|
fDiscardIfZeroCoverage = random->nextBool();
|
2013-03-27 11:01:04 +04:00
|
|
|
|
2013-04-02 00:06:51 +04:00
|
|
|
bool useLocalCoords = random->nextBool() && currAttribIndex < GrDrawState::kMaxVertexAttribCnt;
|
|
|
|
fLocalCoordAttributeIndex = useLocalCoords ? currAttribIndex++ : -1;
|
2013-03-20 23:19:53 +04:00
|
|
|
|
2013-03-30 00:30:50 +04:00
|
|
|
bool dstRead = false;
|
2013-02-13 01:45:24 +04:00
|
|
|
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
|
2013-05-09 17:45:02 +04:00
|
|
|
if (NULL != stages[s]) {
|
|
|
|
const GrBackendEffectFactory& factory = (*stages[s]->getEffect())->getFactory();
|
|
|
|
GrDrawEffect drawEffect(*stages[s], useLocalCoords);
|
2013-03-20 23:19:53 +04:00
|
|
|
fEffectKeys[s] = factory.glEffectKey(drawEffect, gpu->glCaps());
|
2013-05-09 18:55:46 +04:00
|
|
|
if ((*stages[s]->getEffect())->willReadDstColor()) {
|
2013-03-30 00:30:50 +04:00
|
|
|
dstRead = true;
|
|
|
|
}
|
2013-02-13 01:45:24 +04:00
|
|
|
}
|
|
|
|
}
|
2013-03-01 22:21:22 +04:00
|
|
|
|
2013-03-30 00:30:50 +04:00
|
|
|
if (dstRead) {
|
2013-05-13 22:50:25 +04:00
|
|
|
this->fDstReadKey = GrGLShaderBuilder::KeyForDstRead(dstTexture, gpu->glCaps());
|
2013-03-30 00:30:50 +04:00
|
|
|
}
|
2013-04-19 17:14:45 +04:00
|
|
|
|
|
|
|
CoverageOutput coverageOutput;
|
|
|
|
bool illegalCoverageOutput;
|
|
|
|
do {
|
|
|
|
coverageOutput = static_cast<CoverageOutput>(random->nextULessThan(kCoverageOutputCnt));
|
|
|
|
illegalCoverageOutput = (!gpu->caps()->dualSourceBlendingSupport() &&
|
|
|
|
CoverageOutputUsesSecondaryOutput(coverageOutput)) ||
|
2013-04-19 17:25:28 +04:00
|
|
|
(!dstRead && kCombineWithDst_CoverageOutput == coverageOutput);
|
2013-04-19 17:14:45 +04:00
|
|
|
} while (illegalCoverageOutput);
|
|
|
|
|
|
|
|
fCoverageOutput = coverageOutput;
|
2013-02-13 01:45:24 +04:00
|
|
|
}
|
|
|
|
|
2013-02-04 22:39:24 +04:00
|
|
|
bool GrGpuGL::programUnitTest(int maxStages) {
|
|
|
|
|
|
|
|
maxStages = GrMin(maxStages, (int)GrDrawState::kNumStages);
|
2012-08-02 22:11:43 +04:00
|
|
|
|
2012-08-03 18:34:46 +04:00
|
|
|
GrTextureDesc dummyDesc;
|
2013-02-07 18:43:04 +04:00
|
|
|
dummyDesc.fConfig = kSkia8888_GrPixelConfig;
|
2012-08-03 18:34:46 +04:00
|
|
|
dummyDesc.fWidth = 34;
|
|
|
|
dummyDesc.fHeight = 18;
|
|
|
|
SkAutoTUnref<GrTexture> dummyTexture1(this->createTexture(dummyDesc, NULL, 0));
|
|
|
|
dummyDesc.fConfig = kAlpha_8_GrPixelConfig;
|
|
|
|
dummyDesc.fWidth = 16;
|
|
|
|
dummyDesc.fHeight = 22;
|
|
|
|
SkAutoTUnref<GrTexture> dummyTexture2(this->createTexture(dummyDesc, NULL, 0));
|
|
|
|
|
2012-08-02 22:11:43 +04:00
|
|
|
static const int NUM_TESTS = 512;
|
|
|
|
|
2013-02-13 01:45:24 +04:00
|
|
|
SkMWCRandom random;
|
2012-08-02 22:11:43 +04:00
|
|
|
for (int t = 0; t < NUM_TESTS; ++t) {
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
GrPrintf("\nTest Program %d\n-------------\n", t);
|
|
|
|
static const int stop = -1;
|
|
|
|
if (t == stop) {
|
|
|
|
int breakpointhere = 9;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-03-27 22:14:57 +04:00
|
|
|
GrGLProgramDesc pdesc;
|
2013-05-09 17:45:02 +04:00
|
|
|
const GrEffectStage* stages[GrDrawState::kNumStages];
|
|
|
|
memset(stages, 0, sizeof(stages));
|
2012-08-02 22:11:43 +04:00
|
|
|
|
2013-04-02 00:06:51 +04:00
|
|
|
int currAttribIndex = 1; // we need to always leave room for position
|
2013-03-12 16:26:08 +04:00
|
|
|
int attribIndices[2];
|
2013-03-30 00:30:50 +04:00
|
|
|
GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()};
|
2013-02-05 19:44:21 +04:00
|
|
|
for (int s = 0; s < maxStages; ++s) {
|
2012-08-02 22:11:43 +04:00
|
|
|
// enable the stage?
|
2013-02-13 01:45:24 +04:00
|
|
|
if (random.nextBool()) {
|
2013-02-13 20:31:19 +04:00
|
|
|
SkAutoTUnref<const GrEffectRef> effect(GrEffectTestFactory::CreateStage(
|
|
|
|
&random,
|
|
|
|
this->getContext(),
|
2013-03-25 22:19:00 +04:00
|
|
|
*this->caps(),
|
2013-02-13 20:31:19 +04:00
|
|
|
dummyTextures));
|
2013-03-21 21:44:39 +04:00
|
|
|
int numAttribs = (*effect)->numVertexAttribs();
|
|
|
|
|
2013-04-02 00:06:51 +04:00
|
|
|
// If adding this effect would exceed the max attrib count then generate a
|
2013-04-02 11:01:34 +04:00
|
|
|
// new random effect.
|
2013-04-02 00:06:51 +04:00
|
|
|
if (currAttribIndex + numAttribs > GrDrawState::kMaxVertexAttribCnt) {
|
2013-03-21 21:44:39 +04:00
|
|
|
--s;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (int i = 0; i < numAttribs; ++i) {
|
2013-03-12 16:26:08 +04:00
|
|
|
attribIndices[i] = currAttribIndex++;
|
|
|
|
}
|
2013-05-09 17:45:02 +04:00
|
|
|
GrEffectStage* stage = SkNEW(GrEffectStage);
|
|
|
|
stage->setEffect(effect.get(), attribIndices[0], attribIndices[1]);
|
|
|
|
stages[s] = stage;
|
2012-08-02 22:11:43 +04:00
|
|
|
}
|
|
|
|
}
|
2013-03-30 00:30:50 +04:00
|
|
|
const GrTexture* dstTexture = random.nextBool() ? dummyTextures[0] : dummyTextures[1];
|
2013-04-02 00:06:51 +04:00
|
|
|
pdesc.setRandom(&random, this, dstTexture, stages, currAttribIndex);
|
2013-04-02 11:01:34 +04:00
|
|
|
|
2013-03-01 00:16:25 +04:00
|
|
|
SkAutoTUnref<GrGLProgram> program(GrGLProgram::Create(this->glContext(),
|
2012-08-02 22:11:43 +04:00
|
|
|
pdesc,
|
2013-05-09 17:45:02 +04:00
|
|
|
stages));
|
|
|
|
for (int s = 0; s < maxStages; ++s) {
|
|
|
|
SkDELETE(stages[s]);
|
|
|
|
}
|
2012-08-02 22:11:43 +04:00
|
|
|
if (NULL == program.get()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2011-08-16 19:45:58 +04:00
|
|
|
|
2013-02-04 20:13:32 +04:00
|
|
|
static void GLProgramsTest(skiatest::Reporter* reporter, GrContextFactory* factory) {
|
|
|
|
for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) {
|
|
|
|
GrContext* context = factory->get(static_cast<GrContextFactory::GLContextType>(type));
|
|
|
|
if (NULL != context) {
|
2013-02-04 22:39:24 +04:00
|
|
|
GrGpuGL* gpu = static_cast<GrGpuGL*>(context->getGpu());
|
|
|
|
int maxStages = GrDrawState::kNumStages;
|
|
|
|
#if SK_ANGLE
|
|
|
|
// Some long shaders run out of temporary registers in the D3D compiler on ANGLE.
|
|
|
|
if (type == GrContextFactory::kANGLE_GLContextType) {
|
|
|
|
maxStages = 3;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
REPORTER_ASSERT(reporter, gpu->programUnitTest(maxStages));
|
2013-02-04 20:13:32 +04:00
|
|
|
}
|
|
|
|
}
|
2011-08-16 19:45:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "TestClassDef.h"
|
|
|
|
DEFINE_GPUTESTCLASS("GLPrograms", GLProgramsTestClass, GLProgramsTest)
|
|
|
|
|
2012-08-23 22:14:13 +04:00
|
|
|
// This is evil evil evil. The linker may throw away whole translation units as dead code if it
|
2012-10-17 17:36:14 +04:00
|
|
|
// thinks none of the functions are called. It will do this even if there are static initializers
|
2012-08-07 21:36:29 +04:00
|
|
|
// in the unit that could pass pointers to functions from the unit out to other translation units!
|
|
|
|
// We force some of the effects that would otherwise be discarded to link here.
|
|
|
|
|
|
|
|
#include "SkLightingImageFilter.h"
|
2012-08-13 18:22:17 +04:00
|
|
|
#include "SkMagnifierImageFilter.h"
|
2012-10-17 17:36:14 +04:00
|
|
|
#include "SkColorMatrixFilter.h"
|
2012-08-07 21:36:29 +04:00
|
|
|
|
|
|
|
void forceLinking();
|
|
|
|
|
|
|
|
void forceLinking() {
|
|
|
|
SkLightingImageFilter::CreateDistantLitDiffuse(SkPoint3(0,0,0), 0, 0, 0);
|
2012-08-13 18:22:17 +04:00
|
|
|
SkMagnifierImageFilter mag(SkRect::MakeWH(SK_Scalar1, SK_Scalar1), SK_Scalar1);
|
2013-01-28 18:26:09 +04:00
|
|
|
GrConfigConversionEffect::Create(NULL,
|
|
|
|
false,
|
|
|
|
GrConfigConversionEffect::kNone_PMConversion,
|
|
|
|
SkMatrix::I());
|
2012-10-17 17:36:14 +04:00
|
|
|
SkScalar matrix[20];
|
|
|
|
SkColorMatrixFilter cmf(matrix);
|
2012-08-07 21:36:29 +04:00
|
|
|
}
|
|
|
|
|
2012-08-02 18:03:32 +04:00
|
|
|
#endif
|