2017-06-06 18:27:16 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkTypes.h"
|
|
|
|
#include "tests/Test.h"
|
2017-06-06 18:27:16 +00:00
|
|
|
|
2020-07-06 14:56:46 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2020-07-01 16:55:01 +00:00
|
|
|
#include "include/gpu/GrRecordingContext.h"
|
2019-06-18 13:58:02 +00:00
|
|
|
#include "src/gpu/GrColor.h"
|
2020-10-14 15:23:11 +00:00
|
|
|
#include "src/gpu/GrDirectContextPriv.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrGeometryProcessor.h"
|
2019-09-30 16:15:30 +00:00
|
|
|
#include "src/gpu/GrImageInfo.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrMemoryPool.h"
|
|
|
|
#include "src/gpu/GrOpFlushState.h"
|
2019-08-26 15:08:51 +00:00
|
|
|
#include "src/gpu/GrOpsRenderPass.h"
|
2019-10-08 16:32:56 +00:00
|
|
|
#include "src/gpu/GrProgramInfo.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrRecordingContextPriv.h"
|
|
|
|
#include "src/gpu/GrResourceProvider.h"
|
|
|
|
#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
|
|
|
|
#include "src/gpu/glsl/GrGLSLVarying.h"
|
|
|
|
#include "src/gpu/glsl/GrGLSLVertexGeoBuilder.h"
|
2021-08-11 19:43:50 +00:00
|
|
|
#include "src/gpu/ops/GrDrawOp.h"
|
2021-07-28 19:13:20 +00:00
|
|
|
#include "src/gpu/v1/SurfaceDrawContext_v1.h"
|
2017-06-06 18:27:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This is a GPU-backend specific test for dynamic pipeline state. It draws boxes using dynamic
|
|
|
|
* scissor rectangles then reads back the result to verify a successful test.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static constexpr int kScreenSize = 6;
|
|
|
|
static constexpr int kNumMeshes = 4;
|
|
|
|
static constexpr int kScreenSplitX = kScreenSize/2;
|
|
|
|
static constexpr int kScreenSplitY = kScreenSize/2;
|
|
|
|
|
2018-06-26 13:12:38 +00:00
|
|
|
static const SkIRect kDynamicScissors[kNumMeshes] = {
|
|
|
|
SkIRect::MakeLTRB(0, 0, kScreenSplitX, kScreenSplitY),
|
|
|
|
SkIRect::MakeLTRB(0, kScreenSplitY, kScreenSplitX, kScreenSize),
|
|
|
|
SkIRect::MakeLTRB(kScreenSplitX, 0, kScreenSize, kScreenSplitY),
|
|
|
|
SkIRect::MakeLTRB(kScreenSplitX, kScreenSplitY, kScreenSize, kScreenSize),
|
2017-06-06 18:27:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const GrColor kMeshColors[kNumMeshes] {
|
|
|
|
GrColorPackRGBA(255, 0, 0, 255),
|
|
|
|
GrColorPackRGBA(0, 255, 0, 255),
|
|
|
|
GrColorPackRGBA(0, 0, 255, 255),
|
|
|
|
GrColorPackRGBA(0, 0, 0, 255)
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Vertex {
|
|
|
|
float fX;
|
|
|
|
float fY;
|
|
|
|
GrColor fColor;
|
|
|
|
};
|
|
|
|
|
2021-08-11 13:59:56 +00:00
|
|
|
namespace {
|
|
|
|
class PipelineDynamicStateTestProcessor : public GrGeometryProcessor {
|
2017-06-06 18:27:16 +00:00
|
|
|
public:
|
2019-11-20 21:08:10 +00:00
|
|
|
static GrGeometryProcessor* Make(SkArenaAlloc* arena) {
|
2021-08-11 13:59:56 +00:00
|
|
|
return arena->make(
|
|
|
|
[&](void* ptr) { return new (ptr) PipelineDynamicStateTestProcessor(); });
|
2018-06-19 18:33:47 +00:00
|
|
|
}
|
2017-06-06 18:27:16 +00:00
|
|
|
|
|
|
|
const char* name() const override { return "GrPipelineDynamicStateTest Processor"; }
|
|
|
|
|
2021-08-06 19:33:58 +00:00
|
|
|
void addToKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const final {}
|
2017-06-06 18:27:16 +00:00
|
|
|
|
2021-08-09 19:56:24 +00:00
|
|
|
std::unique_ptr<ProgramImpl> makeProgramImpl(const GrShaderCaps&) const final;
|
2017-06-06 18:27:16 +00:00
|
|
|
|
Change how GPs configure attributes
Adds setVertexAttributes and setInstanceAttributes. These take a pointer
to the first attribute, and a count. The count is the total number of
possible attributes, though some may not be initialized. The base class
computes the number of initialized attributes, pre-computes the strides,
and only allows subsequent access to the initialized attributes.
The attributes need to be allocated contiguously. Some GPs place them in
an array, though most just place them as consecutive members, and pass
a pointer to the first one.
Indexed access would be possible, but now it makes more sense to iterate
over all attributes, so enable that, and use range-based for everywhere.
Completely remove the per-attribute offset helper (again - possible, but
not real helpful), and make the stride always available. In many ops,
just use the GP's computed stride, rather than re-computing it.
Bug: skia:
Change-Id: Ie4cccb7969a98ee5a10b373e714fbd702e875b3e
Reviewed-on: https://skia-review.googlesource.com/c/169241
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2018-11-12 20:34:00 +00:00
|
|
|
private:
|
2021-08-11 13:59:56 +00:00
|
|
|
PipelineDynamicStateTestProcessor() : INHERITED(kGrPipelineDynamicStateTestProcessor_ClassID) {
|
2019-11-20 21:08:10 +00:00
|
|
|
this->setVertexAttributes(kAttributes, SK_ARRAY_COUNT(kAttributes));
|
|
|
|
}
|
|
|
|
|
2021-08-11 13:59:56 +00:00
|
|
|
const Attribute& inVertex() const { return kAttributes[0]; }
|
|
|
|
const Attribute& inColor() const { return kAttributes[1]; }
|
|
|
|
|
Change how GPs configure attributes
Adds setVertexAttributes and setInstanceAttributes. These take a pointer
to the first attribute, and a count. The count is the total number of
possible attributes, though some may not be initialized. The base class
computes the number of initialized attributes, pre-computes the strides,
and only allows subsequent access to the initialized attributes.
The attributes need to be allocated contiguously. Some GPs place them in
an array, though most just place them as consecutive members, and pass
a pointer to the first one.
Indexed access would be possible, but now it makes more sense to iterate
over all attributes, so enable that, and use range-based for everywhere.
Completely remove the per-attribute offset helper (again - possible, but
not real helpful), and make the stride always available. In many ops,
just use the GP's computed stride, rather than re-computing it.
Bug: skia:
Change-Id: Ie4cccb7969a98ee5a10b373e714fbd702e875b3e
Reviewed-on: https://skia-review.googlesource.com/c/169241
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2018-11-12 20:34:00 +00:00
|
|
|
static constexpr Attribute kAttributes[] = {
|
2021-08-11 13:59:56 +00:00
|
|
|
{"vertex", kFloat2_GrVertexAttribType, kHalf2_GrSLType},
|
|
|
|
{"color", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType},
|
Change how GPs configure attributes
Adds setVertexAttributes and setInstanceAttributes. These take a pointer
to the first attribute, and a count. The count is the total number of
possible attributes, though some may not be initialized. The base class
computes the number of initialized attributes, pre-computes the strides,
and only allows subsequent access to the initialized attributes.
The attributes need to be allocated contiguously. Some GPs place them in
an array, though most just place them as consecutive members, and pass
a pointer to the first one.
Indexed access would be possible, but now it makes more sense to iterate
over all attributes, so enable that, and use range-based for everywhere.
Completely remove the per-attribute offset helper (again - possible, but
not real helpful), and make the stride always available. In many ops,
just use the GP's computed stride, rather than re-computing it.
Bug: skia:
Change-Id: Ie4cccb7969a98ee5a10b373e714fbd702e875b3e
Reviewed-on: https://skia-review.googlesource.com/c/169241
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2018-11-12 20:34:00 +00:00
|
|
|
};
|
2017-06-06 18:27:16 +00:00
|
|
|
|
|
|
|
friend class GLSLPipelineDynamicStateTestProcessor;
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = GrGeometryProcessor;
|
2017-06-06 18:27:16 +00:00
|
|
|
};
|
2021-08-11 13:59:56 +00:00
|
|
|
} // anonymous namespace
|
2017-06-06 18:27:16 +00:00
|
|
|
|
2021-08-09 19:56:24 +00:00
|
|
|
std::unique_ptr<GrGeometryProcessor::ProgramImpl>
|
2021-08-11 13:59:56 +00:00
|
|
|
PipelineDynamicStateTestProcessor::makeProgramImpl(const GrShaderCaps&) const {
|
|
|
|
class Impl : public GrGeometryProcessor::ProgramImpl {
|
|
|
|
public:
|
|
|
|
void setData(const GrGLSLProgramDataManager&,
|
|
|
|
const GrShaderCaps&,
|
|
|
|
const GrGeometryProcessor&) final {}
|
|
|
|
|
|
|
|
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) final {
|
|
|
|
const PipelineDynamicStateTestProcessor& mp =
|
|
|
|
args.fGeomProc.cast<PipelineDynamicStateTestProcessor>();
|
|
|
|
GrGLSLVertexBuilder* v = args.fVertBuilder;
|
|
|
|
GrGLSLFPFragmentBuilder* f = args.fFragBuilder;
|
|
|
|
|
|
|
|
GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler;
|
|
|
|
varyingHandler->emitAttributes(mp);
|
|
|
|
f->codeAppendf("half4 %s;", args.fOutputColor);
|
2021-08-11 17:01:06 +00:00
|
|
|
varyingHandler->addPassThroughAttribute(mp.inColor().asShaderVar(), args.fOutputColor);
|
2021-08-11 13:59:56 +00:00
|
|
|
|
|
|
|
v->codeAppendf("float2 vertex = %s;", mp.inVertex().name());
|
|
|
|
gpArgs->fPositionVar.set(kFloat2_GrSLType, "vertex");
|
|
|
|
f->codeAppendf("const half4 %s = half4(1);", args.fOutputCoverage);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return std::make_unique<Impl>();
|
2017-06-06 18:27:16 +00:00
|
|
|
}
|
|
|
|
|
2021-08-11 13:59:56 +00:00
|
|
|
namespace {
|
2017-06-06 18:27:16 +00:00
|
|
|
class GrPipelineDynamicStateTestOp : public GrDrawOp {
|
|
|
|
public:
|
|
|
|
DEFINE_OP_CLASS_ID
|
|
|
|
|
2020-10-07 20:46:15 +00:00
|
|
|
static GrOp::Owner Make(GrRecordingContext* context,
|
|
|
|
GrScissorTest scissorTest,
|
|
|
|
sk_sp<const GrBuffer> vbuff) {
|
|
|
|
return GrOp::Make<GrPipelineDynamicStateTestOp>(context, scissorTest, std::move(vbuff));
|
2018-06-07 15:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-10-07 20:46:15 +00:00
|
|
|
friend class GrOp;
|
2018-06-12 14:11:12 +00:00
|
|
|
|
2018-08-15 06:53:25 +00:00
|
|
|
GrPipelineDynamicStateTestOp(GrScissorTest scissorTest, sk_sp<const GrBuffer> vbuff)
|
2020-03-23 18:29:16 +00:00
|
|
|
: INHERITED(ClassID())
|
|
|
|
, fScissorTest(scissorTest)
|
|
|
|
, fVertexBuffer(std::move(vbuff)) {
|
2017-06-06 18:27:16 +00:00
|
|
|
this->setBounds(SkRect::MakeIWH(kScreenSize, kScreenSize),
|
2019-10-01 19:14:44 +00:00
|
|
|
HasAABloat::kNo, IsHairline::kNo);
|
2017-06-06 18:27:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* name() const override { return "GrPipelineDynamicStateTestOp"; }
|
|
|
|
FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; }
|
2021-04-22 18:57:28 +00:00
|
|
|
GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*, GrClampType) override {
|
2020-03-23 18:29:16 +00:00
|
|
|
return GrProcessorSet::EmptySetAnalysis();
|
2017-06-16 14:04:34 +00:00
|
|
|
}
|
2020-03-23 18:29:16 +00:00
|
|
|
void onPrePrepare(GrRecordingContext*,
|
2020-11-19 18:41:26 +00:00
|
|
|
const GrSurfaceProxyView& writeView,
|
2020-03-23 18:29:16 +00:00
|
|
|
GrAppliedClip*,
|
2021-06-02 15:58:05 +00:00
|
|
|
const GrDstProxyView&,
|
2020-11-20 15:22:43 +00:00
|
|
|
GrXferBarrierFlags renderPassXferBarriers,
|
|
|
|
GrLoadOp colorLoadOp) override {}
|
2017-06-06 18:27:16 +00:00
|
|
|
void onPrepare(GrOpFlushState*) override {}
|
2019-10-08 16:32:56 +00:00
|
|
|
void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override {
|
2020-03-23 18:29:16 +00:00
|
|
|
GrPipeline pipeline(fScissorTest, SkBlendMode::kSrc,
|
2020-11-19 18:41:26 +00:00
|
|
|
flushState->drawOpArgs().writeView().swizzle());
|
2020-03-16 15:25:50 +00:00
|
|
|
SkSTArray<kNumMeshes, GrSimpleMesh> meshes;
|
2017-06-06 18:27:16 +00:00
|
|
|
for (int i = 0; i < kNumMeshes; ++i) {
|
2020-03-16 15:25:50 +00:00
|
|
|
GrSimpleMesh& mesh = meshes.push_back();
|
2020-03-13 15:21:12 +00:00
|
|
|
mesh.set(fVertexBuffer, 4, 4 * i);
|
2017-06-06 18:27:16 +00:00
|
|
|
}
|
2019-10-08 16:32:56 +00:00
|
|
|
|
2021-08-11 13:59:56 +00:00
|
|
|
auto geomProc = PipelineDynamicStateTestProcessor::Make(flushState->allocator());
|
2020-03-23 18:29:16 +00:00
|
|
|
|
2021-08-26 16:05:11 +00:00
|
|
|
GrProgramInfo programInfo(flushState->caps(),
|
|
|
|
flushState->writeView(),
|
|
|
|
flushState->usesMSAASurface(),
|
2020-03-23 18:29:16 +00:00
|
|
|
&pipeline,
|
2020-09-25 18:21:18 +00:00
|
|
|
&GrUserStencilSettings::kUnused,
|
2020-03-23 18:29:16 +00:00
|
|
|
geomProc,
|
2020-09-11 13:33:54 +00:00
|
|
|
GrPrimitiveType::kTriangleStrip, 0,
|
2020-11-20 15:22:43 +00:00
|
|
|
flushState->renderPassBarriers(),
|
|
|
|
flushState->colorLoadOp());
|
2020-03-23 18:29:16 +00:00
|
|
|
|
|
|
|
flushState->bindPipeline(programInfo, SkRect::MakeIWH(kScreenSize, kScreenSize));
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
2020-03-16 23:34:44 +00:00
|
|
|
if (fScissorTest == GrScissorTest::kEnabled) {
|
|
|
|
flushState->setScissorRect(kDynamicScissors[i]);
|
|
|
|
}
|
|
|
|
flushState->drawMesh(meshes[i]);
|
|
|
|
}
|
2017-06-06 18:27:16 +00:00
|
|
|
}
|
|
|
|
|
2018-08-15 06:53:25 +00:00
|
|
|
GrScissorTest fScissorTest;
|
2017-06-06 18:27:16 +00:00
|
|
|
const sk_sp<const GrBuffer> fVertexBuffer;
|
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = GrDrawOp;
|
2017-06-06 18:27:16 +00:00
|
|
|
};
|
2021-08-11 13:59:56 +00:00
|
|
|
} // anonymous namespace
|
2017-06-06 18:27:16 +00:00
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrPipelineDynamicStateTest, reporter, ctxInfo) {
|
2020-08-11 16:02:22 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
|
|
|
GrResourceProvider* rp = dContext->priv().resourceProvider();
|
2017-06-06 18:27:16 +00:00
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
auto sdc = skgpu::v1::SurfaceDrawContext::Make(
|
2020-08-11 16:02:22 +00:00
|
|
|
dContext, GrColorType::kRGBA_8888, nullptr, SkBackingFit::kExact,
|
2021-04-19 23:27:09 +00:00
|
|
|
{kScreenSize, kScreenSize}, SkSurfaceProps());
|
2021-07-28 19:13:20 +00:00
|
|
|
if (!sdc) {
|
2017-06-06 18:27:16 +00:00
|
|
|
ERRORF(reporter, "could not create render target context.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
constexpr float d = (float) kScreenSize;
|
|
|
|
Vertex vdata[kNumMeshes * 4] = {
|
|
|
|
{0, 0, kMeshColors[0]},
|
|
|
|
{0, d, kMeshColors[0]},
|
|
|
|
{d, 0, kMeshColors[0]},
|
|
|
|
{d, d, kMeshColors[0]},
|
|
|
|
|
|
|
|
{0, 0, kMeshColors[1]},
|
|
|
|
{0, d, kMeshColors[1]},
|
|
|
|
{d, 0, kMeshColors[1]},
|
|
|
|
{d, d, kMeshColors[1]},
|
|
|
|
|
|
|
|
{0, 0, kMeshColors[2]},
|
|
|
|
{0, d, kMeshColors[2]},
|
|
|
|
{d, 0, kMeshColors[2]},
|
|
|
|
{d, d, kMeshColors[2]},
|
|
|
|
|
|
|
|
{0, 0, kMeshColors[3]},
|
|
|
|
{0, d, kMeshColors[3]},
|
|
|
|
{d, 0, kMeshColors[3]},
|
|
|
|
{d, d, kMeshColors[3]}
|
|
|
|
};
|
|
|
|
|
2019-02-07 16:31:24 +00:00
|
|
|
sk_sp<const GrBuffer> vbuff(rp->createBuffer(sizeof(vdata), GrGpuBufferType::kVertex,
|
|
|
|
kDynamic_GrAccessPattern, vdata));
|
2017-06-06 18:27:16 +00:00
|
|
|
if (!vbuff) {
|
|
|
|
ERRORF(reporter, "vbuff is null.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t resultPx[kScreenSize * kScreenSize];
|
|
|
|
|
2018-08-15 06:53:25 +00:00
|
|
|
for (GrScissorTest scissorTest : {GrScissorTest::kEnabled, GrScissorTest::kDisabled}) {
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc->clear(SkPMColor4f::FromBytes_RGBA(0xbaaaaaad));
|
|
|
|
sdc->addDrawOp(GrPipelineDynamicStateTestOp::Make(dContext, scissorTest, vbuff));
|
2020-08-11 16:02:22 +00:00
|
|
|
auto ii = SkImageInfo::Make(kScreenSize, kScreenSize,
|
|
|
|
kRGBA_8888_SkColorType, kPremul_SkAlphaType);
|
2020-12-24 01:36:44 +00:00
|
|
|
GrPixmap resultPM(ii, resultPx, kScreenSize*sizeof(uint32_t));
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc->readPixels(dContext, resultPM, {0, 0});
|
2017-06-06 18:27:16 +00:00
|
|
|
for (int y = 0; y < kScreenSize; ++y) {
|
|
|
|
for (int x = 0; x < kScreenSize; ++x) {
|
|
|
|
int expectedColorIdx;
|
2018-08-15 06:53:25 +00:00
|
|
|
if (GrScissorTest::kEnabled == scissorTest) {
|
2017-06-06 18:27:16 +00:00
|
|
|
expectedColorIdx = (x < kScreenSplitX ? 0 : 2) + (y < kScreenSplitY ? 0 : 1);
|
|
|
|
} else {
|
|
|
|
expectedColorIdx = kNumMeshes - 1;
|
|
|
|
}
|
|
|
|
uint32_t expected = kMeshColors[expectedColorIdx];
|
|
|
|
uint32_t actual = resultPx[y * kScreenSize + x];
|
|
|
|
if (expected != actual) {
|
|
|
|
ERRORF(reporter, "[scissor=%s] pixel (%i,%i): got 0x%x expected 0x%x",
|
2018-08-15 06:53:25 +00:00
|
|
|
GrScissorTest::kEnabled == scissorTest ? "enabled" : "disabled", x, y,
|
2017-06-06 18:27:16 +00:00
|
|
|
actual, expected);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|