2016-03-23 18:50:26 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// This is a GPU-backend specific test. It relies on static intializers to work
|
|
|
|
|
|
|
|
#include "SkTypes.h"
|
|
|
|
#include "Test.h"
|
|
|
|
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
#include "GrContext.h"
|
|
|
|
#include "GrGeometryProcessor.h"
|
|
|
|
#include "GrGpu.h"
|
2016-12-16 14:52:16 +00:00
|
|
|
#include "GrOpFlushState.h"
|
2016-12-01 21:40:24 +00:00
|
|
|
#include "GrRenderTargetContext.h"
|
|
|
|
#include "GrRenderTargetContextPriv.h"
|
2016-03-23 18:50:26 +00:00
|
|
|
#include "GrTextureProvider.h"
|
2016-12-01 21:40:24 +00:00
|
|
|
#include "SkString.h"
|
2016-10-13 20:25:34 +00:00
|
|
|
#include "glsl/GrGLSLFragmentShaderBuilder.h"
|
2016-12-01 21:40:24 +00:00
|
|
|
#include "glsl/GrGLSLGeometryProcessor.h"
|
2016-03-23 18:50:26 +00:00
|
|
|
#include "glsl/GrGLSLVarying.h"
|
2016-12-16 14:52:16 +00:00
|
|
|
#include "ops/GrMeshDrawOp.h"
|
2016-03-23 18:50:26 +00:00
|
|
|
|
|
|
|
namespace {
|
2016-12-21 16:14:46 +00:00
|
|
|
class Op : public GrMeshDrawOp {
|
2016-03-23 18:50:26 +00:00
|
|
|
public:
|
2016-12-01 14:36:50 +00:00
|
|
|
DEFINE_OP_CLASS_ID
|
2016-03-23 18:50:26 +00:00
|
|
|
|
2016-12-21 16:14:46 +00:00
|
|
|
const char* name() const override { return "Dummy Op"; }
|
2016-03-23 18:50:26 +00:00
|
|
|
|
2017-01-03 14:42:58 +00:00
|
|
|
static std::unique_ptr<GrDrawOp> Make(int numAttribs) {
|
|
|
|
return std::unique_ptr<GrDrawOp>(new Op(numAttribs));
|
|
|
|
}
|
2016-12-21 16:14:46 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Op(int numAttribs) : INHERITED(ClassID()), fNumAttribs(numAttribs) {
|
2016-07-08 13:40:56 +00:00
|
|
|
this->setBounds(SkRect::MakeWH(1.f, 1.f), HasAABloat::kNo, IsZeroArea::kNo);
|
2016-03-23 18:50:26 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 14:20:25 +00:00
|
|
|
void getPipelineAnalysisInput(GrPipelineAnalysisDrawOpInput* input) const override {
|
|
|
|
input->pipelineColorInput()->setUnknownFourComponents();
|
|
|
|
input->pipelineCoverageInput()->setUnknownSingleComponent();
|
|
|
|
}
|
|
|
|
|
|
|
|
void applyPipelineOptimizations(const GrPipelineOptimizations&) override {}
|
2016-12-01 14:36:50 +00:00
|
|
|
bool onCombineIfPossible(GrOp*, const GrCaps&) override { return false; }
|
2016-03-23 18:50:26 +00:00
|
|
|
void onPrepareDraws(Target* target) const override {
|
|
|
|
class GP : public GrGeometryProcessor {
|
|
|
|
public:
|
|
|
|
GP(int numAttribs) {
|
|
|
|
this->initClassID<GP>();
|
|
|
|
SkASSERT(numAttribs > 1);
|
|
|
|
for (auto i = 0; i < numAttribs; ++i) {
|
|
|
|
fAttribNames.push_back().printf("attr%d", i);
|
|
|
|
}
|
|
|
|
for (auto i = 0; i < numAttribs; ++i) {
|
2016-08-17 18:33:39 +00:00
|
|
|
this->addVertexAttrib(fAttribNames[i].c_str(), kVec2f_GrVertexAttribType);
|
2016-03-23 18:50:26 +00:00
|
|
|
}
|
2016-09-27 13:34:10 +00:00
|
|
|
}
|
2016-03-23 18:50:26 +00:00
|
|
|
const char* name() const override { return "Dummy GP"; }
|
|
|
|
|
2016-11-29 18:43:05 +00:00
|
|
|
GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const override {
|
2016-03-23 18:50:26 +00:00
|
|
|
class GLSLGP : public GrGLSLGeometryProcessor {
|
|
|
|
public:
|
|
|
|
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
|
|
|
|
const GP& gp = args.fGP.cast<GP>();
|
|
|
|
args.fVaryingHandler->emitAttributes(gp);
|
|
|
|
this->setupPosition(args.fVertBuilder, gpArgs, gp.fAttribs[0].fName);
|
2016-10-13 20:25:34 +00:00
|
|
|
GrGLSLPPFragmentBuilder* fragBuilder = args.fFragBuilder;
|
|
|
|
fragBuilder->codeAppendf("%s = vec4(1);", args.fOutputColor);
|
|
|
|
fragBuilder->codeAppendf("%s = vec4(1);", args.fOutputCoverage);
|
2016-03-23 18:50:26 +00:00
|
|
|
}
|
|
|
|
void setData(const GrGLSLProgramDataManager& pdman,
|
2016-09-20 16:12:47 +00:00
|
|
|
const GrPrimitiveProcessor& primProc,
|
|
|
|
FPCoordTransformIter&&) override {}
|
2016-03-23 18:50:26 +00:00
|
|
|
};
|
|
|
|
return new GLSLGP();
|
|
|
|
}
|
2016-11-29 18:43:05 +00:00
|
|
|
void getGLSLProcessorKey(const GrShaderCaps&,
|
2016-03-23 18:50:26 +00:00
|
|
|
GrProcessorKeyBuilder* builder) const override {
|
|
|
|
builder->add32(this->numAttribs());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkTArray<SkString> fAttribNames;
|
|
|
|
};
|
2016-11-04 15:49:42 +00:00
|
|
|
sk_sp<GrGeometryProcessor> gp(new GP(fNumAttribs));
|
2016-03-23 18:50:26 +00:00
|
|
|
QuadHelper helper;
|
|
|
|
size_t vertexStride = gp->getVertexStride();
|
|
|
|
SkPoint* vertices = reinterpret_cast<SkPoint*>(helper.init(target, vertexStride, 1));
|
|
|
|
vertices->setRectFan(0.f, 0.f, 1.f, 1.f, vertexStride);
|
2016-11-04 15:49:42 +00:00
|
|
|
helper.recordDraw(target, gp.get());
|
2016-03-23 18:50:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int fNumAttribs;
|
|
|
|
|
2016-12-01 21:40:24 +00:00
|
|
|
typedef GrMeshDrawOp INHERITED;
|
2016-03-23 18:50:26 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-06-27 14:15:20 +00:00
|
|
|
DEF_GPUTEST_FOR_ALL_CONTEXTS(VertexAttributeCount, reporter, ctxInfo) {
|
2016-05-11 13:33:06 +00:00
|
|
|
GrContext* context = ctxInfo.grContext();
|
2016-04-28 16:55:15 +00:00
|
|
|
|
2016-10-27 18:47:55 +00:00
|
|
|
sk_sp<GrRenderTargetContext> renderTargetContext(context->makeRenderTargetContext(
|
|
|
|
SkBackingFit::kApprox,
|
|
|
|
1, 1, kRGBA_8888_GrPixelConfig,
|
|
|
|
nullptr));
|
|
|
|
if (!renderTargetContext) {
|
|
|
|
ERRORF(reporter, "Could not create render target context.");
|
2016-03-23 18:50:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
int attribCnt = context->caps()->maxVertexAttributes();
|
|
|
|
if (!attribCnt) {
|
|
|
|
ERRORF(reporter, "No attributes allowed?!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
context->flush();
|
|
|
|
context->resetGpuStats();
|
|
|
|
#if GR_GPU_STATS
|
|
|
|
REPORTER_ASSERT(reporter, context->getGpu()->stats()->numDraws() == 0);
|
|
|
|
REPORTER_ASSERT(reporter, context->getGpu()->stats()->numFailedDraws() == 0);
|
|
|
|
#endif
|
2016-06-23 21:07:00 +00:00
|
|
|
GrPaint grPaint;
|
2016-03-23 18:50:26 +00:00
|
|
|
// This one should succeed.
|
2017-01-11 18:42:54 +00:00
|
|
|
renderTargetContext->priv().testingOnly_addDrawOp(GrPaint(grPaint), GrAAType::kNone,
|
2016-12-21 16:14:46 +00:00
|
|
|
Op::Make(attribCnt));
|
2016-03-23 18:50:26 +00:00
|
|
|
context->flush();
|
|
|
|
#if GR_GPU_STATS
|
|
|
|
REPORTER_ASSERT(reporter, context->getGpu()->stats()->numDraws() == 1);
|
|
|
|
REPORTER_ASSERT(reporter, context->getGpu()->stats()->numFailedDraws() == 0);
|
|
|
|
#endif
|
|
|
|
context->resetGpuStats();
|
2017-01-11 18:42:54 +00:00
|
|
|
renderTargetContext->priv().testingOnly_addDrawOp(std::move(grPaint), GrAAType::kNone,
|
2016-12-21 16:14:46 +00:00
|
|
|
Op::Make(attribCnt + 1));
|
2016-03-23 18:50:26 +00:00
|
|
|
context->flush();
|
|
|
|
#if GR_GPU_STATS
|
|
|
|
REPORTER_ASSERT(reporter, context->getGpu()->stats()->numDraws() == 0);
|
|
|
|
REPORTER_ASSERT(reporter, context->getGpu()->stats()->numFailedDraws() == 1);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|