skia2/tests/PrimitiveProcessorTest.cpp
Robert Phillips 4f6ba2e522 Revert "Move op memory storage to GrContext"
This reverts commit c8cee446bf.

Reason for revert: TSAN issues

Original change's description:
> Move op memory storage to GrContext
> 
> TBR=bsalomon@google.com
> Change-Id: Ifa95bf0073b9d948f2c937d10088b7734b971f90
> Reviewed-on: https://skia-review.googlesource.com/131500
> Reviewed-by: Brian Salomon <bsalomon@google.com>
> Reviewed-by: Greg Daniel <egdaniel@google.com>
> Commit-Queue: Robert Phillips <robertphillips@google.com>

TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com

Change-Id: Ia0d2b7408314d9b67d57388315376bbea23d3780
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/135181
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
2018-06-15 15:59:45 +00:00

160 lines
5.9 KiB
C++

/*
* 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"
#include "GrContext.h"
#include "GrContextPriv.h"
#include "GrGeometryProcessor.h"
#include "GrGpu.h"
#include "GrMemoryPool.h"
#include "GrOpFlushState.h"
#include "GrRenderTargetContext.h"
#include "GrRenderTargetContextPriv.h"
#include "SkPointPriv.h"
#include "SkString.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
#include "glsl/GrGLSLGeometryProcessor.h"
#include "glsl/GrGLSLVarying.h"
#include "ops/GrMeshDrawOp.h"
namespace {
class Op : public GrMeshDrawOp {
public:
DEFINE_OP_CLASS_ID
const char* name() const override { return "Dummy Op"; }
static std::unique_ptr<GrDrawOp> Make(GrContext* context, int numAttribs) {
return std::unique_ptr<GrDrawOp>(new Op(numAttribs));
}
FixedFunctionFlags fixedFunctionFlags() const override {
return FixedFunctionFlags::kNone;
}
RequiresDstTexture finalize(const GrCaps&, const GrAppliedClip*,\
GrPixelConfigIsClamped) override {
return RequiresDstTexture::kNo;
}
private:
friend class ::GrOpMemoryPool;
Op(int numAttribs) : INHERITED(ClassID()), fNumAttribs(numAttribs) {
this->setBounds(SkRect::MakeWH(1.f, 1.f), HasAABloat::kNo, IsZeroArea::kNo);
}
bool onCombineIfPossible(GrOp*, const GrCaps&) override { return false; }
void onPrepareDraws(Target* target) override {
class GP : public GrGeometryProcessor {
public:
GP(int numAttribs)
: INHERITED(kGP_ClassID) {
SkASSERT(numAttribs > 1);
for (auto i = 0; i < numAttribs; ++i) {
fAttribNames.push_back().printf("attr%d", i);
}
for (auto i = 0; i < numAttribs; ++i) {
this->addVertexAttrib(fAttribNames[i].c_str(), kFloat2_GrVertexAttribType);
}
}
const char* name() const override { return "Dummy GP"; }
GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const override {
class GLSLGP : public GrGLSLGeometryProcessor {
public:
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
const GP& gp = args.fGP.cast<GP>();
args.fVaryingHandler->emitAttributes(gp);
this->writeOutputPosition(args.fVertBuilder, gpArgs,
gp.getAttrib(0).name());
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
fragBuilder->codeAppendf("%s = half4(1);", args.fOutputColor);
fragBuilder->codeAppendf("%s = half4(1);", args.fOutputCoverage);
}
void setData(const GrGLSLProgramDataManager& pdman,
const GrPrimitiveProcessor& primProc,
FPCoordTransformIter&&) override {}
};
return new GLSLGP();
}
void getGLSLProcessorKey(const GrShaderCaps&,
GrProcessorKeyBuilder* builder) const override {
builder->add32(this->numAttribs());
}
private:
SkTArray<SkString> fAttribNames;
typedef GrGeometryProcessor INHERITED;
};
sk_sp<GrGeometryProcessor> gp(new GP(fNumAttribs));
QuadHelper helper;
size_t vertexStride = gp->getVertexStride();
SkPoint* vertices = reinterpret_cast<SkPoint*>(helper.init(target, vertexStride, 1));
SkPointPriv::SetRectTriStrip(vertices, 0.f, 0.f, 1.f, 1.f, vertexStride);
helper.recordDraw(target, gp.get(),
target->makePipeline(0, GrProcessorSet::MakeEmptySet(),
target->detachAppliedClip()));
}
int fNumAttribs;
typedef GrMeshDrawOp INHERITED;
};
}
DEF_GPUTEST_FOR_ALL_CONTEXTS(VertexAttributeCount, reporter, ctxInfo) {
GrContext* context = ctxInfo.grContext();
#if GR_GPU_STATS
GrGpu* gpu = context->contextPriv().getGpu();
#endif
sk_sp<GrRenderTargetContext> renderTargetContext(
context->contextPriv().makeDeferredRenderTargetContext(SkBackingFit::kApprox,
1, 1, kRGBA_8888_GrPixelConfig,
nullptr));
if (!renderTargetContext) {
ERRORF(reporter, "Could not create render target context.");
return;
}
int attribCnt = context->contextPriv().caps()->maxVertexAttributes();
if (!attribCnt) {
ERRORF(reporter, "No attributes allowed?!");
return;
}
context->flush();
context->contextPriv().resetGpuStats();
#if GR_GPU_STATS
REPORTER_ASSERT(reporter, gpu->stats()->numDraws() == 0);
REPORTER_ASSERT(reporter, gpu->stats()->numFailedDraws() == 0);
#endif
// Adding discard to appease vulkan validation warning about loading uninitialized data on draw
renderTargetContext->discard();
GrPaint grPaint;
// This one should succeed.
renderTargetContext->priv().testingOnly_addDrawOp(Op::Make(context, attribCnt));
context->flush();
#if GR_GPU_STATS
REPORTER_ASSERT(reporter, gpu->stats()->numDraws() == 1);
REPORTER_ASSERT(reporter, gpu->stats()->numFailedDraws() == 0);
#endif
context->contextPriv().resetGpuStats();
renderTargetContext->priv().testingOnly_addDrawOp(Op::Make(context, attribCnt + 1));
context->flush();
#if GR_GPU_STATS
REPORTER_ASSERT(reporter, gpu->stats()->numDraws() == 0);
REPORTER_ASSERT(reporter, gpu->stats()->numFailedDraws() == 1);
#endif
}