Remove GrPipelineOptimizations computation from GrPipeline::init and nest in GrMeshDrawOp.

Change-Id: I4a702c83857606c1cb050294c408922eef5769ea
Reviewed-on: https://skia-review.googlesource.com/10414
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
This commit is contained in:
Brian Salomon 2017-03-29 12:09:15 -04:00 committed by Skia Commit-Bot
parent 4a24e10a0b
commit e7d30484ea
35 changed files with 101 additions and 120 deletions

View File

@ -18,7 +18,7 @@
#include "ops/GrOp.h"
GrPipelineOptimizations GrPipeline::init(const InitArgs& args) {
void GrPipeline::init(const InitArgs& args) {
SkASSERT(args.fAnalysis);
SkASSERT(args.fRenderTarget);
@ -106,21 +106,6 @@ GrPipelineOptimizations GrPipeline::init(const InitArgs& args) {
fFragmentProcessors[currFPIdx].reset(fp);
}
}
// Setup info we need to pass to GrPrimitiveProcessors that are used with this GrPipeline.
GrPipelineOptimizations optimizations;
optimizations.fFlags = 0;
if (GrColor_ILLEGAL != overrideColor) {
optimizations.fFlags |= GrPipelineOptimizations::kUseOverrideColor_Flag;
optimizations.fOverrideColor = overrideColor;
}
if (args.fAnalysis->usesLocalCoords()) {
optimizations.fFlags |= GrPipelineOptimizations::kReadsLocalCoords_Flag;
}
if (args.fAnalysis->isCompatibleWithCoverageAsAlpha()) {
optimizations.fFlags |= GrPipelineOptimizations::kCanTweakAlphaForCoverage_Flag;
}
return optimizations;
}
static void add_dependencies_for_processor(const GrFragmentProcessor* proc, GrRenderTarget* rt) {

View File

@ -12,7 +12,6 @@
#include "GrFragmentProcessor.h"
#include "GrNonAtomicRef.h"
#include "GrPendingProgramElement.h"
#include "GrPrimitiveProcessor.h"
#include "GrProcessorSet.h"
#include "GrProgramDesc.h"
#include "GrScissorState.h"
@ -79,7 +78,7 @@ public:
GrPipeline(GrRenderTarget*, SkBlendMode);
/** (Re)initializes a pipeline. After initialization the pipeline can be used. */
GrPipelineOptimizations init(const InitArgs&);
void init(const InitArgs&);
/** True if the pipeline has been initialized. */
bool isInitialized() const { return SkToBool(fRenderTarget.get()); }

View File

@ -33,63 +33,6 @@
class GrGLSLPrimitiveProcessor;
struct GrInitInvariantOutput;
/*
* This class allows the GrPipeline to communicate information about the pipeline to a GrOp which
* inform its decisions for GrPrimitiveProcessor setup. These are not properly part of the pipeline
* because they reflect the specific inputs that the op provided to perform the analysis (e.g. that
* the GrGeometryProcessor would output an opaque color).
*
* The pipeline analysis that produced this may have decided to elide some GrProcessors. However,
* those elisions may depend upon changing the color output by the GrGeometryProcessor used by the
* GrDrawOp. The op must check getOverrideColorIfSet() for this.
*/
class GrPipelineOptimizations {
public:
/** Does the pipeline require access to (implicit or explicit) local coordinates? */
bool readsLocalCoords() const {
return SkToBool(kReadsLocalCoords_Flag & fFlags);
}
/** Does the pipeline allow the GrPrimitiveProcessor to combine color and coverage into one
color output ? */
bool canTweakAlphaForCoverage() const {
return SkToBool(kCanTweakAlphaForCoverage_Flag & fFlags);
}
/** Does the pipeline require the GrPrimitiveProcessor to specify a specific color (and if
so get the color)? */
bool getOverrideColorIfSet(GrColor* overrideColor) const {
if (SkToBool(kUseOverrideColor_Flag & fFlags)) {
if (overrideColor) {
*overrideColor = fOverrideColor;
}
return true;
}
return false;
}
private:
enum {
// If this is not set the primitive processor need not produce local coordinates
kReadsLocalCoords_Flag = 0x1,
// If this flag is set then the primitive processor may produce color*coverage as
// its color output (and not output a separate coverage).
kCanTweakAlphaForCoverage_Flag = 0x2,
// If this flag is set the GrPrimitiveProcessor must produce fOverrideColor as its
// output color. If not set fOverrideColor is to be ignored.
kUseOverrideColor_Flag = 0x4,
};
uint32_t fFlags;
GrColor fOverrideColor;
friend class GrPipeline; // To initialize this
};
/*
* GrPrimitiveProcessor defines an interface which all subclasses must implement. All
* GrPrimitiveProcessors must proivide seed color and coverage for the Ganesh color / coverage

View File

@ -5,9 +5,9 @@
* found in the LICENSE file.
*/
#include "GrProgramDesc.h"
#include "GrProcessor.h"
#include "GrPipeline.h"
#include "GrPrimitiveProcessor.h"
#include "GrProcessor.h"
#include "GrRenderTargetPriv.h"
#include "GrShaderCaps.h"
#include "GrTexturePriv.h"

View File

@ -753,7 +753,7 @@ private:
*coverage = GrPipelineAnalysisCoverage::kSingleChannel;
}
void applyPipelineOptimizations(const GrPipelineOptimizations& optimizations) override {
void applyPipelineOptimizations(const PipelineOptimizations& optimizations) override {
optimizations.getOverrideColorIfSet(&fColor);
fUsesLocalCoords = optimizations.readsLocalCoords();

View File

@ -193,7 +193,7 @@ public:
return str;
}
void applyPipelineOptimizations(const GrPipelineOptimizations& optimizations) override {
void applyPipelineOptimizations(const PipelineOptimizations& optimizations) override {
GrColor color;
if (optimizations.getOverrideColorIfSet(&color)) {
this->first()->setColor(color);

View File

@ -716,7 +716,7 @@ private:
*coverage = GrPipelineAnalysisCoverage::kSingleChannel;
}
void applyPipelineOptimizations(const GrPipelineOptimizations& optimizations) override {
void applyPipelineOptimizations(const PipelineOptimizations& optimizations) override {
optimizations.getOverrideColorIfSet(&fColor);
fUsesLocalCoords = optimizations.readsLocalCoords();
}

View File

@ -178,7 +178,7 @@ private:
*coverage = GrPipelineAnalysisCoverage::kSingleChannel;
}
void applyPipelineOptimizations(const GrPipelineOptimizations& optimizations) override {
void applyPipelineOptimizations(const PipelineOptimizations& optimizations) override {
optimizations.getOverrideColorIfSet(&fPaths[0].fColor);
fUsesLocalCoords = optimizations.readsLocalCoords();
fCanTweakAlphaForCoverage = optimizations.canTweakAlphaForCoverage();

View File

@ -179,7 +179,7 @@ private:
color->setToConstant(fRects[0].fColor);
*coverage = GrPipelineAnalysisCoverage::kSingleChannel;
}
void applyPipelineOptimizations(const GrPipelineOptimizations&) override;
void applyPipelineOptimizations(const PipelineOptimizations&) override;
void onPrepareDraws(Target*) const override;
static const int kMiterIndexCnt = 3 * 24;
@ -230,7 +230,7 @@ private:
typedef GrMeshDrawOp INHERITED;
};
void AAStrokeRectOp::applyPipelineOptimizations(const GrPipelineOptimizations& optimizations) {
void AAStrokeRectOp::applyPipelineOptimizations(const PipelineOptimizations& optimizations) {
optimizations.getOverrideColorIfSet(&fRects[0].fColor);
fUsesLocalCoords = optimizations.readsLocalCoords();

View File

@ -275,7 +275,7 @@ private:
*coverage = GrPipelineAnalysisCoverage::kSingleChannel;
}
void applyPipelineOptimizations(const GrPipelineOptimizations& optimizations) override {
void applyPipelineOptimizations(const PipelineOptimizations& optimizations) override {
optimizations.getOverrideColorIfSet(&fGeoData[0].fColor);
if (!optimizations.readsLocalCoords()) {
fViewMatrixIfUsingLocalCoords.reset();

View File

@ -68,7 +68,7 @@ void GrAtlasTextOp::getFragmentProcessorAnalysisInputs(GrPipelineAnalysisColor*
}
}
void GrAtlasTextOp::applyPipelineOptimizations(const GrPipelineOptimizations& optimizations) {
void GrAtlasTextOp::applyPipelineOptimizations(const PipelineOptimizations& optimizations) {
optimizations.getOverrideColorIfSet(&fGeoData[0].fColor);
fColor = fGeoData[0].fColor;

View File

@ -101,7 +101,7 @@ public:
private:
void getFragmentProcessorAnalysisInputs(GrPipelineAnalysisColor*,
GrPipelineAnalysisCoverage*) const override;
void applyPipelineOptimizations(const GrPipelineOptimizations&) override;
void applyPipelineOptimizations(const PipelineOptimizations&) override;
struct FlushInfo {
sk_sp<const GrBuffer> fVertexBuffer;

View File

@ -302,7 +302,7 @@ private:
*coverage = GrPipelineAnalysisCoverage::kSingleChannel;
}
void applyPipelineOptimizations(const GrPipelineOptimizations& optimizations) override {
void applyPipelineOptimizations(const PipelineOptimizations& optimizations) override {
optimizations.getOverrideColorIfSet(&fColor);
fUsesLocalCoords = optimizations.readsLocalCoords();

View File

@ -139,7 +139,7 @@ private:
: GrPipelineAnalysisCoverage::kSingleChannel;
}
void applyPipelineOptimizations(const GrPipelineOptimizations& optimizations) override {
void applyPipelineOptimizations(const PipelineOptimizations& optimizations) override {
optimizations.getOverrideColorIfSet(&fColor);
fUsesLocalCoords = optimizations.readsLocalCoords();
}

View File

@ -12,7 +12,7 @@
#include "SkRSXform.h"
#include "SkRandom.h"
void GrDrawAtlasOp::applyPipelineOptimizations(const GrPipelineOptimizations& optimizations) {
void GrDrawAtlasOp::applyPipelineOptimizations(const PipelineOptimizations& optimizations) {
SkASSERT(fGeoData.count() == 1);
if (optimizations.getOverrideColorIfSet(&fGeoData[0].fColor) && fHasColors) {
size_t vertexStride =

View File

@ -51,7 +51,7 @@ private:
void onPrepareDraws(Target*) const override;
void applyPipelineOptimizations(const GrPipelineOptimizations&) override;
void applyPipelineOptimizations(const PipelineOptimizations&) override;
GrColor color() const { return fColor; }
const SkMatrix& viewMatrix() const { return fViewMatrix; }

View File

@ -27,8 +27,7 @@ SkString GrDrawPathOp::dumpInfo() const {
return string;
}
GrPipelineOptimizations GrDrawPathOpBase::initPipeline(const GrOpFlushState& state,
GrPipeline* pipeline) {
void GrDrawPathOpBase::initPipeline(const GrOpFlushState& state, GrPipeline* pipeline) {
static constexpr GrUserStencilSettings kCoverPass{
GrUserStencilSettings::StaticInit<
0x0000,
@ -65,11 +64,9 @@ void init_stencil_pass_settings(const GrOpFlushState& flushState,
//////////////////////////////////////////////////////////////////////////////
void GrDrawPathOp::onExecute(GrOpFlushState* state) {
GrColor color = this->color();
GrPipeline pipeline;
GrPipelineOptimizations optimizations = this->initPipeline(*state, &pipeline);
optimizations.getOverrideColorIfSet(&color);
sk_sp<GrPathProcessor> pathProc(GrPathProcessor::Create(color, this->viewMatrix()));
this->initPipeline(*state, &pipeline);
sk_sp<GrPathProcessor> pathProc(GrPathProcessor::Create(this->color(), this->viewMatrix()));
GrStencilSettings stencil;
init_stencil_pass_settings(*state, this->fillType(), &stencil);

View File

@ -39,7 +39,7 @@ protected:
GrColor color() const { return fAnalysis.inputColor(); }
GrPathRendering::FillType fillType() const { return fFillType; }
const GrProcessorSet& processors() const { return fProcessorSet; }
GrPipelineOptimizations initPipeline(const GrOpFlushState&, GrPipeline*);
void initPipeline(const GrOpFlushState&, GrPipeline*);
const GrProcessorSet::FragmentProcessorAnalysis& doFragmentProcessorAnalysis(
const GrCaps& caps, const GrAppliedClip* clip) {
fProcessorSet.analyzeAndEliminateFragmentProcessors(

View File

@ -84,7 +84,7 @@ void GrDrawVerticesOp::getFragmentProcessorAnalysisInputs(
*coverage = GrPipelineAnalysisCoverage::kNone;
}
void GrDrawVerticesOp::applyPipelineOptimizations(const GrPipelineOptimizations& optimizations) {
void GrDrawVerticesOp::applyPipelineOptimizations(const PipelineOptimizations& optimizations) {
SkASSERT(fMeshes.count() == 1);
GrColor overrideColor;
if (optimizations.getOverrideColorIfSet(&overrideColor)) {

View File

@ -72,7 +72,7 @@ private:
void getFragmentProcessorAnalysisInputs(GrPipelineAnalysisColor* color,
GrPipelineAnalysisCoverage* coverage) const override;
void applyPipelineOptimizations(const GrPipelineOptimizations&) override;
void applyPipelineOptimizations(const PipelineOptimizations&) override;
void onPrepareDraws(Target*) const override;
sk_sp<GrGeometryProcessor> makeGP(bool* hasColorAttribute, bool* hasLocalCoordAttribute) const;

View File

@ -67,7 +67,7 @@ private:
*coverage = GrPipelineAnalysisCoverage::kNone;
}
void applyPipelineOptimizations(const GrPipelineOptimizations& analysioptimizations) override {
void applyPipelineOptimizations(const PipelineOptimizations& analysioptimizations) override {
analysioptimizations.getOverrideColorIfSet(&fPatches[0].fColor);
}

View File

@ -265,7 +265,7 @@ private:
*coverage = GrPipelineAnalysisCoverage::kNone;
}
void applyPipelineOptimizations(const GrPipelineOptimizations& optimizations) override {
void applyPipelineOptimizations(const PipelineOptimizations& optimizations) override {
optimizations.getOverrideColorIfSet(&fPaths[0].fColor);
}

View File

@ -40,7 +40,8 @@ public:
}
void initPipeline(const GrPipeline::InitArgs& args) {
this->applyPipelineOptimizations(fPipeline.init(args));
fPipeline.init(args);
this->applyPipelineOptimizations(PipelineOptimizations(*args.fAnalysis));
}
/**
@ -58,6 +59,62 @@ public:
protected:
GrMeshDrawOp(uint32_t classID);
/**
* This is a legacy class only used by GrMeshDrawOp and will be removed. It presents some
* aspects of GrProcessorSet::FragmentProcessorAnalysis to GrMeshDrawOp subclasses.
*/
class PipelineOptimizations {
public:
PipelineOptimizations(const GrProcessorSet::FragmentProcessorAnalysis& analysis) {
fFlags = 0;
if (analysis.getInputColorOverrideAndColorProcessorEliminationCount(&fOverrideColor) >=
0) {
fFlags |= kUseOverrideColor_Flag;
}
if (analysis.usesLocalCoords()) {
fFlags |= kReadsLocalCoords_Flag;
}
if (analysis.isCompatibleWithCoverageAsAlpha()) {
fFlags |= kCanTweakAlphaForCoverage_Flag;
}
}
/** Does the pipeline require access to (implicit or explicit) local coordinates? */
bool readsLocalCoords() const { return SkToBool(kReadsLocalCoords_Flag & fFlags); }
/** Does the pipeline allow the GrPrimitiveProcessor to combine color and coverage into one
color output ? */
bool canTweakAlphaForCoverage() const {
return SkToBool(kCanTweakAlphaForCoverage_Flag & fFlags);
}
/** Does the pipeline require the GrPrimitiveProcessor to specify a specific color (and if
so get the color)? */
bool getOverrideColorIfSet(GrColor* overrideColor) const {
if (SkToBool(kUseOverrideColor_Flag & fFlags)) {
if (overrideColor) {
*overrideColor = fOverrideColor;
}
return true;
}
return false;
}
private:
enum {
// If this is not set the primitive processor need not produce local coordinates
kReadsLocalCoords_Flag = 0x1,
// If this flag is set then the primitive processor may produce color*coverage as
// its color output (and not output a separate coverage).
kCanTweakAlphaForCoverage_Flag = 0x2,
// If this flag is set the GrPrimitiveProcessor must produce fOverrideColor as its
// output color. If not set fOverrideColor is to be ignored.
kUseOverrideColor_Flag = 0x4,
};
uint32_t fFlags;
GrColor fOverrideColor;
};
/** Helper for rendering instances using an instanced index index buffer. This class creates the
space for the vertices and flushes the draws to the GrMeshDrawOp::Target. */
@ -111,7 +168,7 @@ private:
* After GrPipeline analysis is complete this is called so that the op can use the analysis
* results when constructing its GrPrimitiveProcessor.
*/
virtual void applyPipelineOptimizations(const GrPipelineOptimizations&) = 0;
virtual void applyPipelineOptimizations(const PipelineOptimizations&) = 0;
void onPrepare(GrOpFlushState* state) final;
void onExecute(GrOpFlushState* state) final;

View File

@ -116,7 +116,7 @@ private:
*coverage = GrPipelineAnalysisCoverage::kNone;
}
void applyPipelineOptimizations(const GrPipelineOptimizations& optimizations) override {
void applyPipelineOptimizations(const PipelineOptimizations& optimizations) override {
optimizations.getOverrideColorIfSet(&fRects[0].fColor);
}

View File

@ -136,7 +136,7 @@ private:
*coverage = GrPipelineAnalysisCoverage::kNone;
}
void applyPipelineOptimizations(const GrPipelineOptimizations& optimizations) override {
void applyPipelineOptimizations(const PipelineOptimizations& optimizations) override {
optimizations.getOverrideColorIfSet(&fRects[0].fColor);
}

View File

@ -161,7 +161,7 @@ private:
target->draw(gp.get(), mesh);
}
void applyPipelineOptimizations(const GrPipelineOptimizations& optimizations) override {
void applyPipelineOptimizations(const PipelineOptimizations& optimizations) override {
optimizations.getOverrideColorIfSet(&fColor);
fNeedsLocalCoords = optimizations.readsLocalCoords();
}

View File

@ -811,7 +811,7 @@ private:
*coverage = GrPipelineAnalysisCoverage::kSingleChannel;
}
void applyPipelineOptimizations(const GrPipelineOptimizations& optimizations) override {
void applyPipelineOptimizations(const PipelineOptimizations& optimizations) override {
optimizations.getOverrideColorIfSet(&fGeoData[0].fColor);
if (!optimizations.readsLocalCoords()) {
fViewMatrixIfUsingLocalCoords.reset();
@ -1263,7 +1263,7 @@ private:
*coverage = GrPipelineAnalysisCoverage::kSingleChannel;
}
void applyPipelineOptimizations(const GrPipelineOptimizations& optimizations) override {
void applyPipelineOptimizations(const PipelineOptimizations& optimizations) override {
if (!optimizations.readsLocalCoords()) {
fViewMatrixIfUsingLocalCoords.reset();
}
@ -1478,7 +1478,7 @@ private:
*coverage = GrPipelineAnalysisCoverage::kSingleChannel;
}
void applyPipelineOptimizations(const GrPipelineOptimizations& optimizations) override {
void applyPipelineOptimizations(const PipelineOptimizations& optimizations) override {
optimizations.getOverrideColorIfSet(&fGeoData[0].fColor);
fUsesLocalCoords = optimizations.readsLocalCoords();
}
@ -1794,7 +1794,7 @@ private:
*coverage = GrPipelineAnalysisCoverage::kSingleChannel;
}
void applyPipelineOptimizations(const GrPipelineOptimizations& optimizations) override {
void applyPipelineOptimizations(const PipelineOptimizations& optimizations) override {
optimizations.getOverrideColorIfSet(&fGeoData[0].fColor);
if (!optimizations.readsLocalCoords()) {
fViewMatrixIfUsingLocalCoords.reset();
@ -2158,7 +2158,7 @@ private:
*coverage = GrPipelineAnalysisCoverage::kSingleChannel;
}
void applyPipelineOptimizations(const GrPipelineOptimizations& optimizations) override {
void applyPipelineOptimizations(const PipelineOptimizations& optimizations) override {
optimizations.getOverrideColorIfSet(&fGeoData[0].fColor);
if (!optimizations.readsLocalCoords()) {
fViewMatrixIfUsingLocalCoords.reset();

View File

@ -83,7 +83,7 @@ private:
*coverage = GrPipelineAnalysisCoverage::kNone;
}
void applyPipelineOptimizations(const GrPipelineOptimizations& optimizations) override {
void applyPipelineOptimizations(const PipelineOptimizations& optimizations) override {
optimizations.getOverrideColorIfSet(&fRegions[0].fColor);
}

View File

@ -148,7 +148,7 @@ private:
*coverage = GrPipelineAnalysisCoverage::kSingleChannel;
}
void applyPipelineOptimizations(const GrPipelineOptimizations& optimizations) override {
void applyPipelineOptimizations(const PipelineOptimizations& optimizations) override {
optimizations.getOverrideColorIfSet(&fCircles[0].fColor);
if (!optimizations.readsLocalCoords()) {
fViewMatrixIfUsingLocalCoords.reset();
@ -569,7 +569,7 @@ private:
*coverage = GrPipelineAnalysisCoverage::kSingleChannel;
}
void applyPipelineOptimizations(const GrPipelineOptimizations& optimizations) override {
void applyPipelineOptimizations(const PipelineOptimizations& optimizations) override {
optimizations.getOverrideColorIfSet(&fGeoData[0].fColor);
if (!optimizations.readsLocalCoords()) {
fViewMatrixIfUsingLocalCoords.reset();

View File

@ -205,7 +205,7 @@ private:
*coverage = GrPipelineAnalysisCoverage::kSingleChannel;
}
void applyPipelineOptimizations(const GrPipelineOptimizations& optimizations) override {
void applyPipelineOptimizations(const PipelineOptimizations& optimizations) override {
optimizations.getOverrideColorIfSet(&fShapes[0].fColor);
fUsesLocalCoords = optimizations.readsLocalCoords();
}

View File

@ -186,7 +186,7 @@ private:
*coverage = GrPipelineAnalysisCoverage::kSingleChannel;
}
void applyPipelineOptimizations(const GrPipelineOptimizations& optimizations) override {
void applyPipelineOptimizations(const PipelineOptimizations& optimizations) override {
optimizations.getOverrideColorIfSet(&fColor);
fCanTweakAlphaForCoverage = optimizations.canTweakAlphaForCoverage();
fNeedsLocalCoords = optimizations.readsLocalCoords();

View File

@ -39,7 +39,7 @@ private:
*coverage = GrPipelineAnalysisCoverage::kSingleChannel;
}
void applyPipelineOptimizations(const GrPipelineOptimizations& optimizations) override {
void applyPipelineOptimizations(const PipelineOptimizations& optimizations) override {
optimizations.getOverrideColorIfSet(&fColor);
fUsesLocalCoords = optimizations.readsLocalCoords();
}

View File

@ -1003,7 +1003,7 @@ static void test_lcd_coverage_fallback_case(skiatest::Reporter* reporter, const
*coverage = GrPipelineAnalysisCoverage::kLCD;
}
void applyPipelineOptimizations(const GrPipelineOptimizations&) override {}
void applyPipelineOptimizations(const PipelineOptimizations&) override {}
bool onCombineIfPossible(GrOp*, const GrCaps&) override { return false; }
void onPrepareDraws(Target*) const override {}

View File

@ -70,7 +70,7 @@ private:
*coverage = GrPipelineAnalysisCoverage::kSingleChannel;
}
void applyPipelineOptimizations(const GrPipelineOptimizations& optimizations) override {
void applyPipelineOptimizations(const PipelineOptimizations& optimizations) override {
optimizations.getOverrideColorIfSet(&fColor);
}

View File

@ -46,7 +46,7 @@ private:
*coverage = GrPipelineAnalysisCoverage::kSingleChannel;
}
void applyPipelineOptimizations(const GrPipelineOptimizations&) override {}
void applyPipelineOptimizations(const PipelineOptimizations&) override {}
bool onCombineIfPossible(GrOp*, const GrCaps&) override { return false; }
void onPrepareDraws(Target* target) const override {
class GP : public GrGeometryProcessor {