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.
|
|
|
|
*/
|
|
|
|
|
2021-06-16 19:28:00 +00:00
|
|
|
// This is a GPU-backend specific test. It relies on static initializers to work
|
2016-03-23 18:50:26 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkTypes.h"
|
2016-03-23 18:50:26 +00:00
|
|
|
|
2022-04-05 16:56:01 +00:00
|
|
|
#include "include/core/SkColorSpace.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkString.h"
|
2020-07-06 14:56:46 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/core/SkPointPriv.h"
|
2021-12-20 17:37:56 +00:00
|
|
|
#include "src/gpu/KeyBuilder.h"
|
2022-04-07 15:20:24 +00:00
|
|
|
#include "src/gpu/ganesh/GrDirectContextPriv.h"
|
|
|
|
#include "src/gpu/ganesh/GrGeometryProcessor.h"
|
|
|
|
#include "src/gpu/ganesh/GrGpu.h"
|
|
|
|
#include "src/gpu/ganesh/GrMemoryPool.h"
|
|
|
|
#include "src/gpu/ganesh/GrOpFlushState.h"
|
|
|
|
#include "src/gpu/ganesh/GrProgramInfo.h"
|
|
|
|
#include "src/gpu/ganesh/glsl/GrGLSLFragmentShaderBuilder.h"
|
|
|
|
#include "src/gpu/ganesh/glsl/GrGLSLVarying.h"
|
|
|
|
#include "src/gpu/ganesh/ops/GrMeshDrawOp.h"
|
|
|
|
#include "src/gpu/ganesh/ops/GrSimpleMeshDrawOpHelper.h"
|
|
|
|
#include "src/gpu/ganesh/v1/SurfaceDrawContext_v1.h"
|
2022-04-05 16:56:01 +00:00
|
|
|
#include "tests/Test.h"
|
|
|
|
|
|
|
|
#include <memory>
|
2016-03-23 18:50:26 +00:00
|
|
|
|
|
|
|
namespace {
|
2017-07-13 19:29:47 +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
|
|
|
|
2021-06-16 19:28:00 +00:00
|
|
|
const char* name() const override { return "Test Op"; }
|
2016-03-23 18:50:26 +00:00
|
|
|
|
2020-10-07 20:46:15 +00:00
|
|
|
static GrOp::Owner Make(GrRecordingContext* rContext, int numAttribs) {
|
|
|
|
return GrOp::Make<Op>(rContext, numAttribs);
|
2017-07-13 19:29:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FixedFunctionFlags fixedFunctionFlags() const override {
|
|
|
|
return FixedFunctionFlags::kNone;
|
|
|
|
}
|
|
|
|
|
2021-04-22 18:57:28 +00:00
|
|
|
GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*, GrClampType) override {
|
2019-01-15 18:53:00 +00:00
|
|
|
return GrProcessorSet::EmptySetAnalysis();
|
2017-01-03 14:42:58 +00:00
|
|
|
}
|
2016-12-21 16:14:46 +00:00
|
|
|
|
|
|
|
private:
|
2020-10-07 20:46:15 +00:00
|
|
|
friend class ::GrOp;
|
2018-06-12 14:11:12 +00:00
|
|
|
|
2016-12-21 16:14:46 +00:00
|
|
|
Op(int numAttribs) : INHERITED(ClassID()), fNumAttribs(numAttribs) {
|
2019-10-01 19:14:44 +00:00
|
|
|
this->setBounds(SkRect::MakeWH(1.f, 1.f), HasAABloat::kNo, IsHairline::kNo);
|
2016-03-23 18:50:26 +00:00
|
|
|
}
|
|
|
|
|
2020-03-12 16:07:19 +00:00
|
|
|
GrProgramInfo* programInfo() override { return fProgramInfo; }
|
|
|
|
|
2020-03-12 13:41:54 +00:00
|
|
|
void onCreateProgramInfo(const GrCaps* caps,
|
|
|
|
SkArenaAlloc* arena,
|
2020-11-19 18:41:26 +00:00
|
|
|
const GrSurfaceProxyView& writeView,
|
2021-07-13 19:26:39 +00:00
|
|
|
bool usesMSAASurface,
|
2020-03-12 13:41:54 +00:00
|
|
|
GrAppliedClip&& appliedClip,
|
2021-06-02 15:58:05 +00:00
|
|
|
const GrDstProxyView& dstProxyView,
|
2020-11-20 15:22:43 +00:00
|
|
|
GrXferBarrierFlags renderPassXferBarriers,
|
|
|
|
GrLoadOp colorLoadOp) override {
|
2016-03-23 18:50:26 +00:00
|
|
|
class GP : public GrGeometryProcessor {
|
|
|
|
public:
|
2019-11-20 21:08:10 +00:00
|
|
|
static GrGeometryProcessor* Make(SkArenaAlloc* arena, int numAttribs) {
|
2020-12-14 21:59:09 +00:00
|
|
|
return arena->make([&](void* ptr) {
|
|
|
|
return new (ptr) GP(numAttribs);
|
|
|
|
});
|
2016-09-27 13:34:10 +00:00
|
|
|
}
|
2019-11-20 21:08:10 +00:00
|
|
|
|
2021-06-16 19:28:00 +00:00
|
|
|
const char* name() const override { return "Test GP"; }
|
2016-03-23 18:50:26 +00:00
|
|
|
|
2021-08-09 19:56:24 +00:00
|
|
|
std::unique_ptr<ProgramImpl> makeProgramImpl(const GrShaderCaps&) const override {
|
2021-08-11 13:59:56 +00:00
|
|
|
class Impl : public ProgramImpl {
|
2016-03-23 18:50:26 +00:00
|
|
|
public:
|
2021-08-11 13:59:56 +00:00
|
|
|
void setData(const GrGLSLProgramDataManager&,
|
|
|
|
const GrShaderCaps&,
|
|
|
|
const GrGeometryProcessor&) override {}
|
|
|
|
|
|
|
|
private:
|
2016-03-23 18:50:26 +00:00
|
|
|
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
|
2021-03-22 18:48:09 +00:00
|
|
|
const GP& gp = args.fGeomProc.cast<GP>();
|
2016-03-23 18:50:26 +00:00
|
|
|
args.fVaryingHandler->emitAttributes(gp);
|
2021-04-14 14:32:25 +00:00
|
|
|
WriteOutputPosition(args.fVertBuilder, gpArgs, gp.fAttributes[0].name());
|
2018-02-14 20:38:14 +00:00
|
|
|
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
|
2021-03-10 01:16:43 +00:00
|
|
|
fragBuilder->codeAppendf("const half4 %s = half4(1);", args.fOutputColor);
|
|
|
|
fragBuilder->codeAppendf("const half4 %s = half4(1);",
|
|
|
|
args.fOutputCoverage);
|
2016-03-23 18:50:26 +00:00
|
|
|
}
|
|
|
|
};
|
2021-08-11 13:59:56 +00:00
|
|
|
|
|
|
|
return std::make_unique<Impl>();
|
2016-03-23 18:50:26 +00:00
|
|
|
}
|
2021-12-20 17:37:56 +00:00
|
|
|
void addToKey(const GrShaderCaps&, skgpu::KeyBuilder* builder) const override {
|
2018-06-19 18:33:47 +00:00
|
|
|
builder->add32(fNumAttribs);
|
2016-03-23 18:50:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-11-20 21:08:10 +00:00
|
|
|
GP(int numAttribs) : INHERITED(kGP_ClassID), fNumAttribs(numAttribs) {
|
|
|
|
SkASSERT(numAttribs > 1);
|
2020-08-03 17:21:46 +00:00
|
|
|
fAttribNames = std::make_unique<SkString[]>(numAttribs);
|
|
|
|
fAttributes = std::make_unique<Attribute[]>(numAttribs);
|
2019-11-20 21:08:10 +00:00
|
|
|
for (auto i = 0; i < numAttribs; ++i) {
|
|
|
|
fAttribNames[i].printf("attr%d", i);
|
|
|
|
// This gives us more of a mix of attribute types, and allows the
|
|
|
|
// component count to fit within the limits for iOS Metal.
|
|
|
|
if (i & 0x1) {
|
|
|
|
fAttributes[i] = {fAttribNames[i].c_str(), kFloat_GrVertexAttribType,
|
2022-01-21 19:59:22 +00:00
|
|
|
SkSLType::kFloat};
|
2019-11-20 21:08:10 +00:00
|
|
|
} else {
|
|
|
|
fAttributes[i] = {fAttribNames[i].c_str(), kFloat2_GrVertexAttribType,
|
2022-01-21 19:59:22 +00:00
|
|
|
SkSLType::kFloat2};
|
2019-11-20 21:08:10 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-16 21:14:56 +00:00
|
|
|
this->setVertexAttributesWithImplicitOffsets(fAttributes.get(), numAttribs);
|
2019-11-20 21:08:10 +00:00
|
|
|
}
|
|
|
|
|
2018-06-19 18:33:47 +00:00
|
|
|
int fNumAttribs;
|
|
|
|
std::unique_ptr<SkString[]> fAttribNames;
|
|
|
|
std::unique_ptr<Attribute[]> fAttributes;
|
2017-10-09 14:54:08 +00:00
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = GrGeometryProcessor;
|
2016-03-23 18:50:26 +00:00
|
|
|
};
|
2019-11-20 21:08:10 +00:00
|
|
|
|
2020-03-12 13:41:54 +00:00
|
|
|
GrGeometryProcessor* gp = GP::Make(arena, fNumAttribs);
|
|
|
|
|
|
|
|
fProgramInfo = GrSimpleMeshDrawOpHelper::CreateProgramInfo(caps,
|
|
|
|
arena,
|
2020-04-01 20:22:00 +00:00
|
|
|
writeView,
|
2021-08-26 16:05:11 +00:00
|
|
|
usesMSAASurface,
|
2020-03-12 13:41:54 +00:00
|
|
|
std::move(appliedClip),
|
|
|
|
dstProxyView,
|
|
|
|
gp,
|
|
|
|
GrProcessorSet::MakeEmptySet(),
|
|
|
|
GrPrimitiveType::kTriangles,
|
2020-09-11 13:33:54 +00:00
|
|
|
renderPassXferBarriers,
|
2020-11-20 15:22:43 +00:00
|
|
|
colorLoadOp,
|
2020-03-12 13:41:54 +00:00
|
|
|
GrPipeline::InputFlags::kNone);
|
|
|
|
}
|
|
|
|
|
2021-06-17 18:55:07 +00:00
|
|
|
void onPrepareDraws(GrMeshDrawTarget* target) override {
|
2020-03-12 13:41:54 +00:00
|
|
|
if (!fProgramInfo) {
|
|
|
|
this->createProgramInfo(target);
|
|
|
|
}
|
|
|
|
|
2021-03-22 18:48:09 +00:00
|
|
|
size_t vertexStride = fProgramInfo->geomProc().vertexStride();
|
2018-08-07 14:02:38 +00:00
|
|
|
QuadHelper helper(target, vertexStride, 1);
|
|
|
|
SkPoint* vertices = reinterpret_cast<SkPoint*>(helper.vertices());
|
2017-11-07 01:02:02 +00:00
|
|
|
SkPointPriv::SetRectTriStrip(vertices, 0.f, 0.f, 1.f, 1.f, vertexStride);
|
2020-03-12 13:41:54 +00:00
|
|
|
fMesh = helper.mesh();
|
2020-03-11 19:55:55 +00:00
|
|
|
}
|
|
|
|
|
2019-02-26 18:13:22 +00:00
|
|
|
void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override {
|
2020-03-12 13:41:54 +00:00
|
|
|
if (!fProgramInfo || !fMesh) {
|
|
|
|
return;
|
|
|
|
}
|
2019-12-05 21:40:31 +00:00
|
|
|
|
2020-03-16 23:34:44 +00:00
|
|
|
flushState->bindPipelineAndScissorClip(*fProgramInfo, chainBounds);
|
2021-03-22 18:48:09 +00:00
|
|
|
flushState->bindTextures(fProgramInfo->geomProc(), nullptr, fProgramInfo->pipeline());
|
2020-03-16 23:34:44 +00:00
|
|
|
flushState->drawMesh(*fMesh);
|
2016-03-23 18:50:26 +00:00
|
|
|
}
|
|
|
|
|
2020-03-12 13:41:54 +00:00
|
|
|
int fNumAttribs;
|
2020-03-16 15:25:50 +00:00
|
|
|
GrSimpleMesh* fMesh = nullptr;
|
2020-03-12 13:41:54 +00:00
|
|
|
GrProgramInfo* fProgramInfo = nullptr;
|
2016-03-23 18:50:26 +00:00
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = GrMeshDrawOp;
|
2016-03-23 18:50:26 +00:00
|
|
|
};
|
2020-08-06 18:11:56 +00:00
|
|
|
} // namespace
|
2016-03-23 18:50:26 +00:00
|
|
|
|
2016-06-27 14:15:20 +00:00
|
|
|
DEF_GPUTEST_FOR_ALL_CONTEXTS(VertexAttributeCount, reporter, ctxInfo) {
|
2021-07-28 19:13:20 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
2018-01-22 15:48:15 +00:00
|
|
|
#if GR_GPU_STATS
|
2021-07-28 19:13:20 +00:00
|
|
|
GrGpu* gpu = dContext->priv().getGpu();
|
2018-01-22 15:48:15 +00:00
|
|
|
#endif
|
2016-04-28 16:55:15 +00:00
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
auto sdc = skgpu::v1::SurfaceDrawContext::Make(dContext,
|
|
|
|
GrColorType::kRGBA_8888,
|
|
|
|
nullptr,
|
|
|
|
SkBackingFit::kApprox,
|
|
|
|
{1, 1},
|
|
|
|
SkSurfaceProps());
|
|
|
|
if (!sdc) {
|
2016-10-27 18:47:55 +00:00
|
|
|
ERRORF(reporter, "Could not create render target context.");
|
2016-03-23 18:50:26 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-07-28 19:13:20 +00:00
|
|
|
int attribCnt = dContext->priv().caps()->maxVertexAttributes();
|
2016-03-23 18:50:26 +00:00
|
|
|
if (!attribCnt) {
|
|
|
|
ERRORF(reporter, "No attributes allowed?!");
|
|
|
|
return;
|
|
|
|
}
|
2021-07-28 19:13:20 +00:00
|
|
|
dContext->flushAndSubmit();
|
|
|
|
dContext->priv().resetGpuStats();
|
2016-03-23 18:50:26 +00:00
|
|
|
#if GR_GPU_STATS
|
2018-01-22 15:48:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, gpu->stats()->numDraws() == 0);
|
|
|
|
REPORTER_ASSERT(reporter, gpu->stats()->numFailedDraws() == 0);
|
2016-03-23 18:50:26 +00:00
|
|
|
#endif
|
2018-02-27 19:26:32 +00:00
|
|
|
// Adding discard to appease vulkan validation warning about loading uninitialized data on draw
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc->discard();
|
2018-02-27 19:26:32 +00:00
|
|
|
|
2016-06-23 21:07:00 +00:00
|
|
|
GrPaint grPaint;
|
2016-03-23 18:50:26 +00:00
|
|
|
// This one should succeed.
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc->addDrawOp(Op::Make(dContext, attribCnt));
|
|
|
|
dContext->flushAndSubmit();
|
2016-03-23 18:50:26 +00:00
|
|
|
#if GR_GPU_STATS
|
2018-01-22 15:48:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, gpu->stats()->numDraws() == 1);
|
|
|
|
REPORTER_ASSERT(reporter, gpu->stats()->numFailedDraws() == 0);
|
2016-03-23 18:50:26 +00:00
|
|
|
#endif
|
2021-07-28 19:13:20 +00:00
|
|
|
dContext->priv().resetGpuStats();
|
|
|
|
sdc->addDrawOp(Op::Make(dContext, attribCnt + 1));
|
|
|
|
dContext->flushAndSubmit();
|
2016-03-23 18:50:26 +00:00
|
|
|
#if GR_GPU_STATS
|
2018-01-22 15:48:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, gpu->stats()->numDraws() == 0);
|
|
|
|
REPORTER_ASSERT(reporter, gpu->stats()->numFailedDraws() == 1);
|
2016-03-23 18:50:26 +00:00
|
|
|
#endif
|
|
|
|
}
|