Stop tracking whether GrFragmentProcessors read their input

Change-Id: Id5338901978b97289798eaef873527597bd8dfd6
Reviewed-on: https://skia-review.googlesource.com/7414
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
This commit is contained in:
Brian Salomon 2017-01-23 14:35:25 -05:00 committed by Skia Commit-Bot
parent 319ba3d3a1
commit 5f13fbac19
24 changed files with 36 additions and 131 deletions

View File

@ -672,7 +672,7 @@ private:
}
void onComputeInvariantOutput(GrInvariantOutput* inout) const override {
inout->setToUnknown(GrInvariantOutput::kWillNot_ReadInput);
inout->setToUnknown();
}
GrPerlinNoise2Effect(SkPerlinNoiseShader2::Type type,
@ -1084,7 +1084,7 @@ private:
}
void onComputeInvariantOutput(GrInvariantOutput* inout) const override {
inout->setToUnknown(GrInvariantOutput::kWillNot_ReadInput);
inout->setToUnknown();
}
GrImprovedPerlinNoiseEffect(int octaves, SkScalar z,

View File

@ -55,26 +55,14 @@ struct GrPipelineInput {
class GrInvariantOutput {
public:
GrInvariantOutput(GrColor color, GrColorComponentFlags flags)
: fColor(color)
, fValidFlags(flags)
, fNonMulStageFound(false)
, fWillUseInputColor(true) {}
: fColor(color), fValidFlags(flags), fNonMulStageFound(false) {}
GrInvariantOutput(const GrPipelineInput& input)
: fColor(input.fColor)
, fValidFlags(input.fValidFlags)
, fNonMulStageFound(false)
, fWillUseInputColor(false) {}
: fColor(input.fColor), fValidFlags(input.fValidFlags), fNonMulStageFound(false) {}
virtual ~GrInvariantOutput() {}
enum ReadInput {
kWill_ReadInput,
kWillNot_ReadInput,
};
void mulByUnknownOpaqueFourComponents() {
SkDEBUGCODE(this->validate());
if (this->isOpaque()) {
fValidFlags = kA_GrColorComponentFlag;
} else {
@ -82,32 +70,26 @@ public:
// multiplied is opaque.
this->mulByUnknownFourComponents();
}
SkDEBUGCODE(this->validate());
}
void mulByUnknownFourComponents() {
SkDEBUGCODE(this->validate());
if (this->hasZeroAlpha()) {
this->internalSetToTransparentBlack();
} else {
this->internalSetToUnknown();
}
SkDEBUGCODE(this->validate());
}
void mulByUnknownSingleComponent() {
SkDEBUGCODE(this->validate());
if (this->hasZeroAlpha()) {
this->internalSetToTransparentBlack();
} else {
// We don't need to change fIsSingleComponent in this case
fValidFlags = kNone_GrColorComponentFlags;
}
SkDEBUGCODE(this->validate());
}
void mulByKnownSingleComponent(uint8_t alpha) {
SkDEBUGCODE(this->validate());
if (this->hasZeroAlpha() || 0 == alpha) {
this->internalSetToTransparentBlack();
} else {
@ -120,11 +102,9 @@ public:
// We don't need to change fIsSingleComponent in this case
}
}
SkDEBUGCODE(this->validate());
}
void mulByKnownFourComponents(GrColor color) {
SkDEBUGCODE(this->validate());
uint32_t a;
if (GetAlphaAndCheckSingleChannel(color, &a)) {
this->mulByKnownSingleComponent(a);
@ -137,12 +117,10 @@ public:
SkMulDiv255Round(GrColorUnpackA(fColor), a));
}
}
SkDEBUGCODE(this->validate());
}
// Ignores the incoming color's RGB and muls its alpha by color.
void mulAlphaByKnownFourComponents(GrColor color) {
SkDEBUGCODE(this->validate());
uint32_t a;
if (GetAlphaAndCheckSingleChannel(color, &a)) {
this->mulAlphaByKnownSingleComponent(a);
@ -162,13 +140,11 @@ public:
} else {
fValidFlags = kNone_GrColorComponentFlags;
}
SkDEBUGCODE(this->validate());
}
// Ignores the incoming color's RGB and muls its alpha by the alpha param and sets all channels
// equal to that value.
void mulAlphaByKnownSingleComponent(uint8_t alpha) {
SkDEBUGCODE(this->validate());
if (0 == alpha || this->hasZeroAlpha()) {
this->internalSetToTransparentBlack();
} else {
@ -181,63 +157,35 @@ public:
fValidFlags = kNone_GrColorComponentFlags;
}
}
SkDEBUGCODE(this->validate());
}
void premulFourChannelColor() {
SkDEBUGCODE(this->validate());
fNonMulStageFound = true;
if (!(fValidFlags & kA_GrColorComponentFlag)) {
fValidFlags = kNone_GrColorComponentFlags;
} else {
fColor = GrPremulColor(fColor);
}
SkDEBUGCODE(this->validate());
}
void invalidateComponents(GrColorComponentFlags invalidateFlags, ReadInput readsInput) {
SkDEBUGCODE(this->validate());
void invalidateComponents(GrColorComponentFlags invalidateFlags) {
fValidFlags = (fValidFlags & ~invalidateFlags);
fNonMulStageFound = true;
if (kWillNot_ReadInput == readsInput) {
fWillUseInputColor = false;
}
SkDEBUGCODE(this->validate());
}
void setToOther(GrColorComponentFlags validFlags, GrColor color, ReadInput readsInput) {
SkDEBUGCODE(this->validate());
void setToOther(GrColorComponentFlags validFlags, GrColor color) {
fValidFlags = validFlags;
fColor = color;
fNonMulStageFound = true;
if (kWillNot_ReadInput == readsInput) {
fWillUseInputColor = false;
}
if (kRGBA_GrColorComponentFlags == fValidFlags) {
}
SkDEBUGCODE(this->validate());
}
void setToUnknown(ReadInput readsInput) {
SkDEBUGCODE(this->validate());
void setToUnknown() {
this->internalSetToUnknown();
fNonMulStageFound= true;
if (kWillNot_ReadInput == readsInput) {
fWillUseInputColor = false;
}
SkDEBUGCODE(this->validate());
fNonMulStageFound = true;
}
GrColor color() const { return fColor; }
GrColorComponentFlags validFlags() const { return fValidFlags; }
bool willUseInputColor() const { return fWillUseInputColor; }
#ifdef SK_DEBUG
void validate() const {
// If we claim that we are not using the input color we must not be modulating the input.
SkASSERT(fNonMulStageFound || fWillUseInputColor);
}
#endif
private:
friend class GrProcOptInfo;
@ -253,14 +201,12 @@ private:
fColor = color;
fValidFlags = flags;
fNonMulStageFound = false;
fWillUseInputColor = true;
}
void reset(const GrPipelineInput& input) {
fColor = input.fColor;
fValidFlags = input.fValidFlags;
fNonMulStageFound = false;
fWillUseInputColor = true;
}
void internalSetToTransparentBlack() {
@ -284,8 +230,6 @@ private:
return (fValidFlags == kRGBA_GrColorComponentFlags && 0xFFFFFFFF == fColor);
}
void resetWillUseInputColor() { fWillUseInputColor = true; }
bool allStagesMulInput() const { return !fNonMulStageFound; }
void resetNonMulStageFound() { fNonMulStageFound = false; }
@ -297,7 +241,6 @@ private:
GrColor fColor;
GrColorComponentFlags fValidFlags;
bool fNonMulStageFound;
bool fWillUseInputColor;
};
#endif

View File

@ -393,7 +393,7 @@ private:
// then we can't know the final result.
if (0 != fMatrix[kAlphaRowStartIdx + i]) {
if (!(inout->validFlags() & kRGBAFlags[i])) {
inout->setToUnknown(GrInvariantOutput::kWill_ReadInput);
inout->setToUnknown();
return;
} else {
uint32_t component = (inout->color() >> kShifts[i]) & 0xFF;
@ -407,8 +407,7 @@ private:
// underflow this may deviate from the actual result. Maybe the effect should pin its
// result if the matrix could over/underflow for any component?
inout->setToOther(kA_GrColorComponentFlag,
static_cast<uint8_t>(SkScalarPin(outputA, 0, 255)) << GrColor_SHIFT_A,
GrInvariantOutput::kWill_ReadInput);
static_cast<uint8_t>(SkScalarPin(outputA, 0, 255)) << GrColor_SHIFT_A);
}
SkScalar fMatrix[20];

View File

@ -223,7 +223,7 @@ public:
const char* name() const override { return "NormalBevelFP"; }
void onComputeInvariantOutput(GrInvariantOutput* inout) const override {
inout->setToUnknown(GrInvariantOutput::ReadInput::kWillNot_ReadInput);
inout->setToUnknown();
}
private:

View File

@ -50,7 +50,7 @@ public:
const char* name() const override { return "NormalFlatFP"; }
void onComputeInvariantOutput(GrInvariantOutput* inout) const override {
inout->setToUnknown(GrInvariantOutput::ReadInput::kWillNot_ReadInput);
inout->setToUnknown();
}
private:

View File

@ -103,7 +103,7 @@ public:
const char* name() const override { return "NormalMapFP"; }
void onComputeInvariantOutput(GrInvariantOutput* inout) const override {
inout->setToUnknown(GrInvariantOutput::ReadInput::kWillNot_ReadInput);
inout->setToUnknown();
}
const SkMatrix& invCTM() const { return fInvCTM; }

View File

@ -287,7 +287,7 @@ private:
void onComputeInvariantOutput(GrInvariantOutput* inout) const override {
// TODO: optimize this
inout->setToUnknown(GrInvariantOutput::kWill_ReadInput);
inout->setToUnknown();
}
ArithmeticFP(float k1, float k2, float k3, float k4, bool enforcePMColor,

View File

@ -528,7 +528,7 @@ void GrDisplacementMapEffect::onComputeInvariantOutput(GrInvariantOutput* inout)
// and no displacement offset push any texture coordinates out of bounds OR if the constant
// alpha is 0. Since this isn't trivial to compute at this point, let's assume the output is
// not of constant color when a displacement effect is applied.
inout->setToUnknown(GrInvariantOutput::kWillNot_ReadInput);
inout->setToUnknown();
}
///////////////////////////////////////////////////////////////////////////////

View File

@ -115,8 +115,7 @@ private:
void onComputeInvariantOutput(GrInvariantOutput* inout) const override {
// The output is always black. The alpha value for the color passed in is arbitrary.
inout->setToOther(kRGB_GrColorComponentFlags, GrColorPackRGBA(0, 0, 0, 0),
GrInvariantOutput::kWill_ReadInput);
inout->setToOther(kRGB_GrColorComponentFlags, GrColorPackRGBA(0, 0, 0, 0));
}
};

View File

@ -121,7 +121,7 @@ bool OverdrawFragmentProcessor::onIsEqual(const GrFragmentProcessor& other) cons
}
void OverdrawFragmentProcessor::onComputeInvariantOutput(GrInvariantOutput* inout) const {
inout->invalidateComponents(kRGBA_GrColorComponentFlags, GrInvariantOutput::kWill_ReadInput);
inout->invalidateComponents(kRGBA_GrColorComponentFlags);
}
GLOverdrawFragmentProcessor::GLOverdrawFragmentProcessor(const GrColor4f* colors) {

View File

@ -536,7 +536,7 @@ private:
}
void onComputeInvariantOutput(GrInvariantOutput* inout) const override {
inout->setToUnknown(GrInvariantOutput::kWillNot_ReadInput);
inout->setToUnknown();
}
GrPerlinNoiseEffect(SkPerlinNoiseShader::Type type,

View File

@ -456,7 +456,7 @@ public:
const char* name() const override { return "RRectsGaussianEdgeFP"; }
void onComputeInvariantOutput(GrInvariantOutput* inout) const override {
inout->setToUnknown(GrInvariantOutput::kWill_ReadInput);
inout->setToUnknown();
}
const SkRRect& first() const { return fFirst; }

View File

@ -561,7 +561,7 @@ void ColorTableEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const
if (fFlags & SkTable_ColorFilter::kA_Flag) {
invalidateFlags |= kA_GrColorComponentFlag;
}
inout->invalidateComponents(invalidateFlags, GrInvariantOutput::kWill_ReadInput);
inout->invalidateComponents(invalidateFlags);
}
///////////////////////////////////////////////////////////////////////////////

View File

@ -181,7 +181,7 @@ sk_sp<GrFragmentProcessor> GrFragmentProcessor::MulOutputByInputUnpremulColor(
void onComputeInvariantOutput(GrInvariantOutput* inout) const override {
// TODO: Add a helper to GrInvariantOutput that handles multiplying by color with flags?
if (!(inout->validFlags() & kA_GrColorComponentFlag)) {
inout->setToUnknown(GrInvariantOutput::kWill_ReadInput);
inout->setToUnknown();
return;
}
@ -208,7 +208,7 @@ sk_sp<GrFragmentProcessor> GrFragmentProcessor::MulOutputByInputUnpremulColor(
color |= SkMulDiv255Round(GrColorUnpackB(c0), GrColorUnpackB(c1)) <<
GrColor_SHIFT_B;
}
inout->setToOther(commonFlags, color, GrInvariantOutput::kWill_ReadInput);
inout->setToOther(commonFlags, color);
}
};
if (!fp) {
@ -272,8 +272,7 @@ sk_sp<GrFragmentProcessor> GrFragmentProcessor::OverrideInput(sk_sp<GrFragmentPr
}
void onComputeInvariantOutput(GrInvariantOutput* inout) const override {
inout->setToOther(kRGBA_GrColorComponentFlags, fColor.toGrColor(),
GrInvariantOutput::kWillNot_ReadInput);
inout->setToOther(kRGBA_GrColorComponentFlags, fColor.toGrColor());
this->childProcessor(0).computeInvariantOutput(inout);
}
@ -282,11 +281,7 @@ sk_sp<GrFragmentProcessor> GrFragmentProcessor::OverrideInput(sk_sp<GrFragmentPr
GrInvariantOutput childOut(0x0, kNone_GrColorComponentFlags);
fp->computeInvariantOutput(&childOut);
if (childOut.willUseInputColor()) {
return sk_sp<GrFragmentProcessor>(new ReplaceInputFragmentProcessor(std::move(fp), color));
} else {
return fp;
}
}
sk_sp<GrFragmentProcessor> GrFragmentProcessor::RunInSeries(sk_sp<GrFragmentProcessor>* series,
@ -354,7 +349,7 @@ sk_sp<GrFragmentProcessor> GrFragmentProcessor::RunInSeries(sk_sp<GrFragmentProc
int firstIdx = info.firstEffectiveProcessorIndex();
cnt -= firstIdx;
if (firstIdx > 0 && info.inputColorIsUsed()) {
if (firstIdx > 0) {
// See comment above - need to preserve 4f and color spaces during invariant processing.
sk_sp<GrFragmentProcessor> colorFP(GrConstColorProcessor::Make(
GrColor4f::FromGrColor(info.inputColorToFirstEffectiveProccesor()),
@ -366,9 +361,6 @@ sk_sp<GrFragmentProcessor> GrFragmentProcessor::RunInSeries(sk_sp<GrFragmentProc
replacementSeries.emplace_back(std::move(series[firstIdx + i]));
}
series = replacementSeries.begin();
} else {
series += firstIdx;
cnt -= firstIdx;
}
if (1 == cnt) {

View File

@ -12,17 +12,10 @@
void GrProcOptInfo::analyzeProcessors(const GrFragmentProcessor* const* processors, int cnt) {
for (int i = 0; i < cnt; ++i) {
const GrFragmentProcessor* processor = processors[i];
fInOut.resetWillUseInputColor();
processor->computeInvariantOutput(&fInOut);
SkDEBUGCODE(fInOut.validate());
if (!fInOut.willUseInputColor()) {
fFirstEffectiveProcessorIndex = i;
fInputColorIsUsed = false;
}
if (kRGBA_GrColorComponentFlags == fInOut.validFlags()) {
fFirstEffectiveProcessorIndex = i + 1;
fInputColor = fInOut.color();
fInputColorIsUsed = true;
// Since we are clearing all previous color stages we are in a state where we have found
// zero stages that don't multiply the inputColor.
fInOut.resetNonMulStageFound();

View File

@ -64,11 +64,6 @@ public:
*/
int firstEffectiveProcessorIndex() const { return fFirstEffectiveProcessorIndex; }
/**
* True if the first effective processor reads its input, false otherwise.
*/
bool inputColorIsUsed() const { return fInputColorIsUsed; }
/**
* If input color is used and per-vertex colors are not used, this is the input color to the
* first effective processor.
@ -79,7 +74,6 @@ private:
void internalReset(GrColor color, GrColorComponentFlags colorFlags, bool isLCDCoverage) {
fInOut.reset(color, colorFlags);
fFirstEffectiveProcessorIndex = 0;
fInputColorIsUsed = true;
fInputColor = color;
fIsLCDCoverage = isLCDCoverage;
}
@ -88,7 +82,6 @@ private:
GrInvariantOutput fInOut;
int fFirstEffectiveProcessorIndex = 0;
bool fInputColorIsUsed = true;
bool fIsLCDCoverage = false;
GrColor fInputColor = 0;
};

View File

@ -64,8 +64,7 @@ private:
void GrConstColorProcessor::onComputeInvariantOutput(GrInvariantOutput* inout) const {
if (kIgnore_InputMode == fMode) {
inout->setToOther(kRGBA_GrColorComponentFlags, fColor.toGrColor(),
GrInvariantOutput::kWillNot_ReadInput);
inout->setToOther(kRGBA_GrColorComponentFlags, fColor.toGrColor());
} else {
float r = fColor.fRGBA[0];
bool colorIsSingleChannel = r == fColor.fRGBA[1] && r == fColor.fRGBA[2] &&

View File

@ -45,7 +45,7 @@ private:
};
void DitherEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const {
inout->setToUnknown(GrInvariantOutput::kWill_ReadInput);
inout->setToUnknown();
}
//////////////////////////////////////////////////////////////////////////////

View File

@ -109,7 +109,7 @@ bool GrGammaEffect::onIsEqual(const GrFragmentProcessor& s) const {
}
void GrGammaEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const {
inout->setToUnknown(GrInvariantOutput::kWill_ReadInput);
inout->setToUnknown();
}
///////////////////////////////////////////////////////////////////////////////

View File

@ -42,7 +42,7 @@ protected:
}
void onComputeInvariantOutput(GrInvariantOutput* inout) const override {
inout->setToUnknown(GrInvariantOutput::kWill_ReadInput);
inout->setToUnknown();
}
private:
@ -197,20 +197,9 @@ protected:
inout->color(), inout->validFlags(),
&blendColor, &blendFlags);
}
// will the shader code reference the input color?
GrInvariantOutput::ReadInput readsInput = GrInvariantOutput::kWillNot_ReadInput;
if (kDst_Child == fChild) {
if (kZero_GrBlendCoeff != srcCoeff || GrBlendCoeffRefsSrc(dstCoeff)) {
readsInput = GrInvariantOutput::kWill_ReadInput;
}
inout->setToOther(blendFlags, blendColor);
} else {
if (kZero_GrBlendCoeff != dstCoeff || GrBlendCoeffRefsDst(srcCoeff)) {
readsInput = GrInvariantOutput::kWill_ReadInput;
}
}
inout->setToOther(blendFlags, blendColor, readsInput);
} else {
inout->setToUnknown(GrInvariantOutput::kWill_ReadInput);
inout->setToUnknown();
}
}

View File

@ -187,8 +187,7 @@ private:
void onComputeInvariantOutput(GrInvariantOutput* inout) const override {
// YUV is opaque
inout->setToOther(kA_GrColorComponentFlag, 0xFF << GrColor_SHIFT_A,
GrInvariantOutput::kWillNot_ReadInput);
inout->setToOther(kA_GrColorComponentFlag, 0xFF << GrColor_SHIFT_A);
}
GrCoordTransform fYTransform;
@ -348,7 +347,7 @@ private:
}
void onComputeInvariantOutput(GrInvariantOutput* inout) const override {
inout->setToUnknown(GrInvariantOutput::kWillNot_ReadInput);
inout->setToUnknown();
}
GrCoordTransform fTransform;

View File

@ -132,8 +132,7 @@ private:
bool onIsEqual(const GrFragmentProcessor&) const override { return true; }
void onComputeInvariantOutput(GrInvariantOutput* inout) const override {
inout->setToOther(kRGBA_GrColorComponentFlags, GrColor_WHITE,
GrInvariantOutput::kWillNot_ReadInput);
inout->setToOther(kRGBA_GrColorComponentFlags, GrColor_WHITE);
this->childProcessor(0).computeInvariantOutput(inout);
}

View File

@ -36,7 +36,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageStorageLoad, reporter, ctxInfo) {
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {}
void onComputeInvariantOutput(GrInvariantOutput* inout) const override {
inout->setToUnknown(GrInvariantOutput::kWillNot_ReadInput);
inout->setToUnknown();
}
bool onIsEqual(const GrFragmentProcessor& that) const override { return true; }

View File

@ -64,7 +64,7 @@ public:
void onComputeInvariantOutput(GrInvariantOutput* inout) const override {
// We don't care about optimizing these processors.
inout->setToUnknown(GrInvariantOutput::kWill_ReadInput);
inout->setToUnknown();
}
private: