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
|
|
|
|
|
2012-05-31 15:07:19 +00:00
|
|
|
#include "gl/GrGpuGL.h"
|
2012-10-25 19:00:29 +00:00
|
|
|
#include "GrBackendEffectFactory.h"
|
2013-02-04 16:13:32 +00:00
|
|
|
#include "GrContextFactory.h"
|
2013-03-20 19:19:53 +00:00
|
|
|
#include "GrDrawEffect.h"
|
2012-08-27 12:53:13 +00:00
|
|
|
#include "effects/GrConfigConversionEffect.h"
|
2012-08-07 17:36:29 +00:00
|
|
|
|
2012-11-21 22:38:36 +00:00
|
|
|
#include "SkRandom.h"
|
2012-08-02 18:11:43 +00:00
|
|
|
#include "Test.h"
|
|
|
|
|
2013-02-12 21:45:24 +00:00
|
|
|
void GrGLProgram::Desc::setRandom(SkMWCRandom* random,
|
|
|
|
const GrGpuGL* gpu,
|
|
|
|
const GrEffectStage stages[GrDrawState::kNumStages]) {
|
2013-03-01 18:21:22 +00:00
|
|
|
fAttribBindings = 0;
|
2013-02-12 21:45:24 +00:00
|
|
|
fEmitsPointSize = random->nextBool();
|
|
|
|
fColorInput = random->nextULessThan(kColorInputCnt);
|
|
|
|
fCoverageInput = random->nextULessThan(kColorInputCnt);
|
|
|
|
|
|
|
|
fColorFilterXfermode = random->nextULessThan(SkXfermode::kCoeffModesCnt);
|
|
|
|
|
|
|
|
fFirstCoverageStage = random->nextULessThan(GrDrawState::kNumStages);
|
|
|
|
|
2013-03-01 18:21:22 +00:00
|
|
|
fAttribBindings |= random->nextBool() ? GrDrawState::kCoverage_AttribBindingsBit : 0;
|
2013-02-12 21:45:24 +00:00
|
|
|
|
|
|
|
#if GR_GL_EXPERIMENTAL_GS
|
|
|
|
fExperimentalGS = gpu->getCaps().geometryShaderSupport() && random->nextBool();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
bool edgeAA = random->nextBool();
|
|
|
|
if (edgeAA) {
|
2013-03-01 18:21:22 +00:00
|
|
|
fAttribBindings |= GrDrawState::kEdge_AttribBindingsBit;
|
2013-02-12 21:45:24 +00:00
|
|
|
if (gpu->getCaps().shaderDerivativeSupport()) {
|
|
|
|
fVertexEdgeType = (GrDrawState::VertexEdgeType)
|
|
|
|
random->nextULessThan(GrDrawState::kVertexEdgeTypeCnt);
|
|
|
|
fDiscardIfOutsideEdge = random->nextBool();
|
|
|
|
} else {
|
|
|
|
fVertexEdgeType = GrDrawState::kHairLine_EdgeType;
|
|
|
|
fDiscardIfOutsideEdge = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gpu->getCaps().dualSourceBlendingSupport()) {
|
|
|
|
fDualSrcOutput = random->nextULessThan(kDualSrcOutputCnt);
|
|
|
|
} else {
|
|
|
|
fDualSrcOutput = kNone_DualSrcOutput;
|
|
|
|
}
|
|
|
|
|
2013-03-20 19:19:53 +00:00
|
|
|
// use separate tex coords?
|
|
|
|
if (random->nextBool()) {
|
|
|
|
fAttribBindings |= GrDrawState::kLocalCoords_AttribBindingsBit;
|
|
|
|
}
|
|
|
|
|
2013-02-12 21:45:24 +00:00
|
|
|
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
|
|
|
|
if (NULL != stages[s].getEffect()) {
|
|
|
|
const GrBackendEffectFactory& factory = (*stages[s].getEffect())->getFactory();
|
2013-03-20 19:19:53 +00:00
|
|
|
bool explicitLocalCoords = (fAttribBindings &
|
|
|
|
GrDrawState::kLocalCoords_AttribBindingsBit);
|
|
|
|
GrDrawEffect drawEffect(stages[s], explicitLocalCoords);
|
|
|
|
fEffectKeys[s] = factory.glEffectKey(drawEffect, gpu->glCaps());
|
2013-02-12 21:45:24 +00:00
|
|
|
}
|
|
|
|
}
|
2013-03-01 18:21:22 +00:00
|
|
|
|
|
|
|
int attributeIndex = 0;
|
|
|
|
fPositionAttributeIndex = attributeIndex;
|
|
|
|
++attributeIndex;
|
|
|
|
if (fColorInput || (fAttribBindings & GrDrawState::kColor_AttribBindingsBit)) {
|
|
|
|
fColorAttributeIndex = attributeIndex;
|
|
|
|
++attributeIndex;
|
|
|
|
}
|
|
|
|
if (fCoverageInput || (fAttribBindings & GrDrawState::kCoverage_AttribBindingsBit)) {
|
|
|
|
fCoverageAttributeIndex = attributeIndex;
|
|
|
|
++attributeIndex;
|
|
|
|
}
|
|
|
|
if (fAttribBindings & GrDrawState::kEdge_AttribBindingsBit) {
|
|
|
|
fEdgeAttributeIndex = attributeIndex;
|
|
|
|
++attributeIndex;
|
|
|
|
}
|
2013-03-20 19:19:53 +00:00
|
|
|
if (fAttribBindings & GrDrawState::kLocalCoords_AttribBindingsBit) {
|
|
|
|
fLocalCoordsAttributeIndex = attributeIndex;
|
2013-03-01 18:21:22 +00:00
|
|
|
++attributeIndex;
|
|
|
|
}
|
2013-02-12 21:45:24 +00:00
|
|
|
}
|
|
|
|
|
2013-02-04 18:39:24 +00:00
|
|
|
bool GrGpuGL::programUnitTest(int maxStages) {
|
|
|
|
|
|
|
|
maxStages = GrMin(maxStages, (int)GrDrawState::kNumStages);
|
2012-08-02 18:11:43 +00:00
|
|
|
|
2012-08-03 14:34:46 +00:00
|
|
|
GrTextureDesc dummyDesc;
|
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;
|
|
|
|
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 18:11:43 +00:00
|
|
|
static const int NUM_TESTS = 512;
|
|
|
|
|
2013-02-12 21:45:24 +00:00
|
|
|
SkMWCRandom random;
|
2012-08-02 18:11:43 +00: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-02-12 21:45:24 +00:00
|
|
|
GrGLProgram::Desc pdesc;
|
2012-10-29 19:51:22 +00:00
|
|
|
GrEffectStage stages[GrDrawState::kNumStages];
|
2012-08-02 18:11:43 +00:00
|
|
|
|
2013-03-12 12:26:08 +00:00
|
|
|
int currAttribIndex = GrDrawState::kAttribIndexCount;
|
|
|
|
int attribIndices[2];
|
2013-02-05 15:44:21 +00:00
|
|
|
for (int s = 0; s < maxStages; ++s) {
|
2012-08-02 18:11:43 +00:00
|
|
|
// enable the stage?
|
2013-02-12 21:45:24 +00:00
|
|
|
if (random.nextBool()) {
|
2012-08-03 14:34:46 +00:00
|
|
|
GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()};
|
2013-02-13 16:31:19 +00:00
|
|
|
SkAutoTUnref<const GrEffectRef> effect(GrEffectTestFactory::CreateStage(
|
|
|
|
&random,
|
|
|
|
this->getContext(),
|
|
|
|
dummyTextures));
|
2013-03-12 12:26:08 +00:00
|
|
|
for (int i = 0; i < effect.get()->get()->numVertexAttribs(); ++i) {
|
|
|
|
attribIndices[i] = currAttribIndex++;
|
|
|
|
}
|
2013-03-19 18:51:02 +00:00
|
|
|
stages[s].setEffect(effect.get(), attribIndices[0], attribIndices[1]);
|
2012-08-02 18:11:43 +00:00
|
|
|
}
|
|
|
|
}
|
2013-02-12 21:45:24 +00:00
|
|
|
pdesc.setRandom(&random, this, stages);
|
|
|
|
|
2012-10-29 19:51:22 +00:00
|
|
|
const GrEffectStage* stagePtrs[GrDrawState::kNumStages];
|
|
|
|
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
|
|
|
|
stagePtrs[s] = &stages[s];
|
|
|
|
}
|
2013-02-28 20:16:25 +00:00
|
|
|
SkAutoTUnref<GrGLProgram> program(GrGLProgram::Create(this->glContext(),
|
2012-08-02 18:11:43 +00:00
|
|
|
pdesc,
|
2012-10-29 19:51:22 +00:00
|
|
|
stagePtrs));
|
2012-08-02 18:11:43 +00:00
|
|
|
if (NULL == program.get()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2011-08-16 15:45:58 +00:00
|
|
|
|
2013-02-04 16:13:32 +00: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 18:39:24 +00: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 16:13:32 +00:00
|
|
|
}
|
|
|
|
}
|
2011-08-16 15:45:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "TestClassDef.h"
|
|
|
|
DEFINE_GPUTESTCLASS("GLPrograms", GLProgramsTestClass, GLProgramsTest)
|
|
|
|
|
2012-08-23 18:14:13 +00:00
|
|
|
// This is evil evil evil. The linker may throw away whole translation units as dead code if it
|
2012-10-17 13:36:14 +00:00
|
|
|
// thinks none of the functions are called. It will do this even if there are static initializers
|
2012-08-07 17:36:29 +00: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 14:22:17 +00:00
|
|
|
#include "SkMagnifierImageFilter.h"
|
2012-10-17 13:36:14 +00:00
|
|
|
#include "SkColorMatrixFilter.h"
|
2012-08-07 17:36:29 +00:00
|
|
|
|
|
|
|
void forceLinking();
|
|
|
|
|
|
|
|
void forceLinking() {
|
|
|
|
SkLightingImageFilter::CreateDistantLitDiffuse(SkPoint3(0,0,0), 0, 0, 0);
|
2012-08-13 14:22:17 +00:00
|
|
|
SkMagnifierImageFilter mag(SkRect::MakeWH(SK_Scalar1, SK_Scalar1), SK_Scalar1);
|
2013-01-28 14:26:09 +00:00
|
|
|
GrConfigConversionEffect::Create(NULL,
|
|
|
|
false,
|
|
|
|
GrConfigConversionEffect::kNone_PMConversion,
|
|
|
|
SkMatrix::I());
|
2012-10-17 13:36:14 +00:00
|
|
|
SkScalar matrix[20];
|
|
|
|
SkColorMatrixFilter cmf(matrix);
|
2012-08-07 17:36:29 +00:00
|
|
|
}
|
|
|
|
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif
|