diff options
author | Brian Salomon <bsalomon@google.com> | 2017-03-01 11:28:27 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-03-01 18:16:09 +0000 |
commit | af9847ee11ae92dbb369cdca3e6d6ae69a62b973 (patch) | |
tree | ecd2f13f8e26bf5c76f257d8713d47082819191d | |
parent | 367eae207627566d877f787acc9c1be8538c21cc (diff) |
Use GrAAType in instanced rendering.
Change-Id: Ifb5a33f908de618d66fcb0dd329f064c1ecfcd63
Reviewed-on: https://skia-review.googlesource.com/9082
Reviewed-by: Chris Dalton <csmartdalton@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
-rw-r--r-- | include/gpu/GrTypesPriv.h | 2 | ||||
-rw-r--r-- | src/gpu/instanced/InstanceProcessor.cpp | 98 | ||||
-rw-r--r-- | src/gpu/instanced/InstanceProcessor.h | 6 | ||||
-rw-r--r-- | src/gpu/instanced/InstancedRendering.cpp | 28 | ||||
-rw-r--r-- | src/gpu/instanced/InstancedRendering.h | 27 | ||||
-rw-r--r-- | src/gpu/instanced/InstancedRenderingTypes.h | 16 |
6 files changed, 77 insertions, 100 deletions
diff --git a/include/gpu/GrTypesPriv.h b/include/gpu/GrTypesPriv.h index e7bb1addc3..2a18443a1f 100644 --- a/include/gpu/GrTypesPriv.h +++ b/include/gpu/GrTypesPriv.h @@ -12,7 +12,7 @@ #include "SkRefCnt.h" /** This enum indicates the type of antialiasing to be performed. */ -enum class GrAAType { +enum class GrAAType : unsigned { /** No antialiasing */ kNone, /** Use fragment shader code to compute a fractional pixel coverage. */ diff --git a/src/gpu/instanced/InstanceProcessor.cpp b/src/gpu/instanced/InstanceProcessor.cpp index 2ac5b8e8c8..efbf8251c4 100644 --- a/src/gpu/instanced/InstanceProcessor.cpp +++ b/src/gpu/instanced/InstanceProcessor.cpp @@ -67,8 +67,8 @@ InstanceProcessor::InstanceProcessor(OpInfo opInfo, GrBuffer* paramsBuffer) : fO this->addBufferAccess(&fParamsAccess); } - if (fOpInfo.fAntialiasMode >= AntialiasMode::kMSAA) { - if (!fOpInfo.isSimpleRects() || AntialiasMode::kMixedSamples == fOpInfo.fAntialiasMode) { + if (GrAATypeIsHW(fOpInfo.aaType())) { + if (!fOpInfo.isSimpleRects() || GrAAType::kMixedSamples == fOpInfo.aaType()) { this->setWillUseSampleLocations(); } } @@ -1076,7 +1076,7 @@ public: } private: - bool isMixedSampled() const { return AntialiasMode::kMixedSamples == fOpInfo.fAntialiasMode; } + bool isMixedSampled() const { return GrAAType::kMixedSamples == fOpInfo.aaType(); } void onInit(GrGLSLVaryingHandler*, GrGLSLVertexBuilder*) override; void setupRect(GrGLSLVertexBuilder*) override; @@ -1673,15 +1673,15 @@ void GLSLInstanceProcessor::BackendMultisample::acceptCoverageMask(GrGLSLPPFragm GLSLInstanceProcessor::Backend* GLSLInstanceProcessor::Backend::Create(const GrPipeline& pipeline, OpInfo opInfo, const VertexInputs& inputs) { - switch (opInfo.fAntialiasMode) { + switch (opInfo.aaType()) { default: SkFAIL("Unexpected antialias mode."); - case AntialiasMode::kNone: + case GrAAType::kNone: return new BackendNonAA(opInfo, inputs); - case AntialiasMode::kCoverage: + case GrAAType::kCoverage: return new BackendCoverage(opInfo, inputs); - case AntialiasMode::kMSAA: - case AntialiasMode::kMixedSamples: { + case GrAAType::kMSAA: + case GrAAType::kMixedSamples: { const GrRenderTargetPriv& rtp = pipeline.getRenderTarget()->renderTargetPriv(); const GrGpu::MultisampleSpecs& specs = rtp.getMultisampleSpecs(pipeline); return new BackendMultisample(opInfo, inputs, specs.fEffectiveSampleCnt); @@ -2027,60 +2027,50 @@ const GrBuffer* InstanceProcessor::FindOrCreateIndex8Buffer(GrGpu* gpu) { return nullptr; } -IndexRange InstanceProcessor::GetIndexRangeForRect(AntialiasMode aa) { - static constexpr IndexRange kRectRanges[kNumAntialiasModes] = { - {kRect_FirstIndex, 3 * kRect_TriCount}, // kNone - {kFramedRect_FirstIndex, 3 * kFramedRect_TriCount}, // kCoverage - {kRect_FirstIndex, 3 * kRect_TriCount}, // kMSAA - {kRect_FirstIndex, 3 * kRect_TriCount} // kMixedSamples - }; - - SkASSERT(aa >= AntialiasMode::kNone && aa <= AntialiasMode::kMixedSamples); - return kRectRanges[(int)aa]; - - GR_STATIC_ASSERT(0 == (int)AntialiasMode::kNone); - GR_STATIC_ASSERT(1 == (int)AntialiasMode::kCoverage); - GR_STATIC_ASSERT(2 == (int)AntialiasMode::kMSAA); - GR_STATIC_ASSERT(3 == (int)AntialiasMode::kMixedSamples); +IndexRange InstanceProcessor::GetIndexRangeForRect(GrAAType aaType) { + switch (aaType) { + case GrAAType::kCoverage: + return {kFramedRect_FirstIndex, 3 * kFramedRect_TriCount}; + case GrAAType::kNone: + case GrAAType::kMSAA: + case GrAAType::kMixedSamples: + return {kRect_FirstIndex, 3 * kRect_TriCount}; + } + SkFAIL("Unexpected aa type!"); + return {0, 0}; } -IndexRange InstanceProcessor::GetIndexRangeForOval(AntialiasMode aa, const SkRect& devBounds) { - if (AntialiasMode::kCoverage == aa && devBounds.height() * devBounds.width() >= 256 * 256) { +IndexRange InstanceProcessor::GetIndexRangeForOval(GrAAType aaType, const SkRect& devBounds) { + if (GrAAType::kCoverage == aaType && devBounds.height() * devBounds.width() >= 256 * 256) { // This threshold was chosen quasi-scientifically on Tegra X1. return {kDisjoint16Gons_FirstIndex, 3 * kDisjoint16Gons_TriCount}; } - static constexpr IndexRange kOvalRanges[kNumAntialiasModes] = { - {kOctagons_FirstIndex, 3 * kOctagons_TriCount}, // kNone - {kDisjointOctagons_FirstIndex, 3 * kDisjointOctagons_TriCount}, // kCoverage - {kOctagons_FirstIndex, 3 * kOctagons_TriCount}, // kMSAA - {kOctagonsFanned_FirstIndex, 3 * kOctagonsFanned_TriCount} // kMixedSamples - }; - - SkASSERT(aa >= AntialiasMode::kNone && aa <= AntialiasMode::kMixedSamples); - return kOvalRanges[(int)aa]; - - GR_STATIC_ASSERT(0 == (int)AntialiasMode::kNone); - GR_STATIC_ASSERT(1 == (int)AntialiasMode::kCoverage); - GR_STATIC_ASSERT(2 == (int)AntialiasMode::kMSAA); - GR_STATIC_ASSERT(3 == (int)AntialiasMode::kMixedSamples); + switch (aaType) { + case GrAAType::kNone: + case GrAAType::kMSAA: + return {kOctagons_FirstIndex, 3 * kOctagons_TriCount}; + case GrAAType::kCoverage: + return {kDisjointOctagons_FirstIndex, 3 * kDisjointOctagons_TriCount}; + case GrAAType::kMixedSamples: + return {kOctagonsFanned_FirstIndex, 3 * kOctagonsFanned_TriCount}; + } + SkFAIL("Unexpected aa type!"); + return {0, 0}; } -IndexRange InstanceProcessor::GetIndexRangeForRRect(AntialiasMode aa) { - static constexpr IndexRange kRRectRanges[kNumAntialiasModes] = { - {kCorneredRect_FirstIndex, 3 * kCorneredRect_TriCount}, // kNone - {kCorneredFramedRect_FirstIndex, 3 * kCorneredFramedRect_TriCount}, // kCoverage - {kCorneredRect_FirstIndex, 3 * kCorneredRect_TriCount}, // kMSAA - {kCorneredRectFanned_FirstIndex, 3 * kCorneredRectFanned_TriCount} // kMixedSamples - }; - - SkASSERT(aa >= AntialiasMode::kNone && aa <= AntialiasMode::kMixedSamples); - return kRRectRanges[(int)aa]; - - GR_STATIC_ASSERT(0 == (int)AntialiasMode::kNone); - GR_STATIC_ASSERT(1 == (int)AntialiasMode::kCoverage); - GR_STATIC_ASSERT(2 == (int)AntialiasMode::kMSAA); - GR_STATIC_ASSERT(3 == (int)AntialiasMode::kMixedSamples); +IndexRange InstanceProcessor::GetIndexRangeForRRect(GrAAType aaType) { + switch (aaType) { + case GrAAType::kNone: + case GrAAType::kMSAA: + return {kCorneredRect_FirstIndex, 3 * kCorneredRect_TriCount}; + case GrAAType::kCoverage: + return {kCorneredFramedRect_FirstIndex, 3 * kCorneredFramedRect_TriCount}; + case GrAAType::kMixedSamples: + return {kCorneredRectFanned_FirstIndex, 3 * kCorneredRectFanned_TriCount}; + } + SkFAIL("Unexpected aa type!"); + return {0, 0}; } const char* InstanceProcessor::GetNameOfIndexRange(IndexRange range) { diff --git a/src/gpu/instanced/InstanceProcessor.h b/src/gpu/instanced/InstanceProcessor.h index bfe503e5bc..8cde30f73f 100644 --- a/src/gpu/instanced/InstanceProcessor.h +++ b/src/gpu/instanced/InstanceProcessor.h @@ -43,9 +43,9 @@ public: */ static const GrBuffer* SK_WARN_UNUSED_RESULT FindOrCreateIndex8Buffer(GrGpu*); - static IndexRange GetIndexRangeForRect(AntialiasMode); - static IndexRange GetIndexRangeForOval(AntialiasMode, const SkRect& devBounds); - static IndexRange GetIndexRangeForRRect(AntialiasMode); + static IndexRange GetIndexRangeForRect(GrAAType); + static IndexRange GetIndexRangeForOval(GrAAType, const SkRect& devBounds); + static IndexRange GetIndexRangeForRRect(GrAAType); static const char* GetNameOfIndexRange(IndexRange); diff --git a/src/gpu/instanced/InstancedRendering.cpp b/src/gpu/instanced/InstancedRendering.cpp index 245d6d8281..127dca3b03 100644 --- a/src/gpu/instanced/InstancedRendering.cpp +++ b/src/gpu/instanced/InstancedRendering.cpp @@ -113,21 +113,20 @@ std::unique_ptr<InstancedRendering::Op> InstancedRendering::recordShape( return nullptr; } - AntialiasMode antialiasMode; - if (!this->selectAntialiasMode(viewMatrix, aa, info, aaType, &antialiasMode)) { + if (!this->selectAntialiasMode(viewMatrix, aa, info, aaType)) { return nullptr; } std::unique_ptr<Op> op = this->makeOp(); - op->fInfo.fAntialiasMode = antialiasMode; + op->fInfo.setAAType(*aaType); op->fInfo.fShapeTypes = GetShapeFlag(type); op->fInfo.fCannotDiscard = !info.fCanDiscard; Instance& instance = op->getSingleInstance(); instance.fInfo = (int)type << kShapeType_InfoBit; - Op::HasAABloat aaBloat = (antialiasMode == AntialiasMode::kCoverage) ? Op::HasAABloat::kYes - : Op::HasAABloat::kNo; + Op::HasAABloat aaBloat = + (*aaType == GrAAType::kCoverage) ? Op::HasAABloat::kYes : Op::HasAABloat::kNo; Op::IsZeroArea zeroArea = (bounds.isEmpty()) ? Op::IsZeroArea::kYes : Op::IsZeroArea::kNo; // The instanced shape renderer draws rectangles of [-1, -1, +1, +1], so we find the matrix that @@ -199,8 +198,7 @@ std::unique_ptr<InstancedRendering::Op> InstancedRendering::recordShape( inline bool InstancedRendering::selectAntialiasMode(const SkMatrix& viewMatrix, GrAA aa, const GrInstancedPipelineInfo& info, - GrAAType* aaType, - AntialiasMode* antialiasMode) { + GrAAType* aaType) { SkASSERT(!info.fColorDisabled || info.fDrawingShapeToStencil); SkASSERT(!info.fIsMixedSampled || info.fIsMultisampled); SkASSERT(GrCaps::InstancedSupport::kNone != fGpu->caps()->instancedSupport()); @@ -211,13 +209,11 @@ inline bool InstancedRendering::selectAntialiasMode(const SkMatrix& viewMatrix, // We can't draw to the stencil buffer without discard (or sample mask if MSAA). return false; } - *antialiasMode = AntialiasMode::kNone; *aaType = GrAAType::kNone; return true; } if (info.canUseCoverageAA() && viewMatrix.preservesRightAngles()) { - *antialiasMode = AntialiasMode::kCoverage; *aaType = GrAAType::kCoverage; return true; } @@ -226,12 +222,10 @@ inline bool InstancedRendering::selectAntialiasMode(const SkMatrix& viewMatrix, if (info.fIsMultisampled && fGpu->caps()->instancedSupport() >= GrCaps::InstancedSupport::kMultisampled) { if (!info.fIsMixedSampled || info.fColorDisabled) { - *antialiasMode = AntialiasMode::kMSAA; *aaType = GrAAType::kMSAA; return true; } if (fGpu->caps()->instancedSupport() >= GrCaps::InstancedSupport::kMixedSampled) { - *antialiasMode = AntialiasMode::kMixedSamples; *aaType = GrAAType::kMixedSamples; return true; } @@ -344,9 +338,8 @@ void InstancedRendering::Op::getFragmentProcessorAnalysisInputs( FragmentProcessorAnalysisInputs* input) const { input->colorInput()->setToConstant(this->getSingleInstance().fColor); - if (AntialiasMode::kCoverage == fInfo.fAntialiasMode || - (AntialiasMode::kNone == fInfo.fAntialiasMode && - !fInfo.isSimpleRects() && fInfo.fCannotDiscard)) { + if (GrAAType::kCoverage == fInfo.aaType() || + (GrAAType::kNone == fInfo.aaType() && !fInfo.isSimpleRects() && fInfo.fCannotDiscard)) { input->coverageInput()->setToUnknown(); } else { input->coverageInput()->setToSolidCoverage(); @@ -361,12 +354,11 @@ void InstancedRendering::Op::applyPipelineOptimizations( SkASSERT(!fIsTracked); if (kRect_ShapeFlag == fInfo.fShapeTypes) { - draw.fGeometry = InstanceProcessor::GetIndexRangeForRect(fInfo.fAntialiasMode); + draw.fGeometry = InstanceProcessor::GetIndexRangeForRect(fInfo.aaType()); } else if (kOval_ShapeFlag == fInfo.fShapeTypes) { - draw.fGeometry = InstanceProcessor::GetIndexRangeForOval(fInfo.fAntialiasMode, - this->bounds()); + draw.fGeometry = InstanceProcessor::GetIndexRangeForOval(fInfo.aaType(), this->bounds()); } else { - draw.fGeometry = InstanceProcessor::GetIndexRangeForRRect(fInfo.fAntialiasMode); + draw.fGeometry = InstanceProcessor::GetIndexRangeForRRect(fInfo.aaType()); } if (!fParams.empty()) { diff --git a/src/gpu/instanced/InstancedRendering.h b/src/gpu/instanced/InstancedRendering.h index 03fe242345..03120d21d5 100644 --- a/src/gpu/instanced/InstancedRendering.h +++ b/src/gpu/instanced/InstancedRendering.h @@ -109,18 +109,19 @@ protected: SkString dumpInfo() const override { SkString string; - string.printf("AA: %d, ShapeTypes: 0x%02x, IShapeTypes: 0x%02x, Persp %d, " - "NonSquare: %d, PLoad: %0.2f, Tracked: %d, NumDraws: %d, " - "GeomChanges: %d\n", - (int)fInfo.fAntialiasMode, - fInfo.fShapeTypes, - fInfo.fInnerShapeTypes, - fInfo.fHasPerspective, - fInfo.fNonSquare, - fPixelLoad, - fIsTracked, - fNumDraws, - fNumChangesInGeometry); + string.printf( + "AA: %d, ShapeTypes: 0x%02x, IShapeTypes: 0x%02x, Persp %d, " + "NonSquare: %d, PLoad: %0.2f, Tracked: %d, NumDraws: %d, " + "GeomChanges: %d\n", + (unsigned)fInfo.fAAType, + fInfo.fShapeTypes, + fInfo.fInnerShapeTypes, + fInfo.fHasPerspective, + fInfo.fNonSquare, + fPixelLoad, + fIsTracked, + fNumDraws, + fNumChangesInGeometry); string.append(DumpPipelineInfo(*this->pipeline())); string.append(INHERITED::dumpInfo()); return string; @@ -192,7 +193,7 @@ private: GrAAType*); bool selectAntialiasMode(const SkMatrix& viewMatrix, GrAA aa, const GrInstancedPipelineInfo&, - GrAAType*, AntialiasMode*); + GrAAType*); virtual std::unique_ptr<Op> makeOp() = 0; diff --git a/src/gpu/instanced/InstancedRenderingTypes.h b/src/gpu/instanced/InstancedRenderingTypes.h index 4e0c3d3d95..402f6e9fb2 100644 --- a/src/gpu/instanced/InstancedRenderingTypes.h +++ b/src/gpu/instanced/InstancedRenderingTypes.h @@ -42,15 +42,6 @@ enum class Attrib : uint8_t { }; constexpr int kNumAttribs = 1 + (int)Attrib::kLocalRect; -// TODO: replace with GrAAType? -enum class AntialiasMode : uint8_t { - kNone, - kCoverage, - kMSAA, - kMixedSamples -}; -constexpr int kNumAntialiasModes = 1 + (int)AntialiasMode::kMixedSamples; - enum class ShapeType : uint8_t { kRect, kOval, @@ -133,9 +124,12 @@ struct OpInfo { return !((fShapeTypes & ~kRect_ShapeFlag) | fInnerShapeTypes); } + GrAAType aaType() const { return static_cast<GrAAType>(fAAType); } + void setAAType(GrAAType aaType) { fAAType = static_cast<uint8_t>(aaType); } + union { struct { - AntialiasMode fAntialiasMode; + uint8_t fAAType; // GrAAType uint8_t fShapeTypes; uint8_t fInnerShapeTypes; bool fHasPerspective : 1; @@ -151,7 +145,7 @@ struct OpInfo { }; inline bool OpInfo::CanCombine(const OpInfo& a, const OpInfo& b) { - if (a.fAntialiasMode != b.fAntialiasMode) { + if (a.fAAType != b.fAAType) { return false; } if (SkToBool(a.fInnerShapeTypes) != SkToBool(b.fInnerShapeTypes)) { |