Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/gpu/GrAppliedClip.h" |
| 9 | #include "src/gpu/GrProcessorSet.h" |
Robert Phillips | ce97857 | 2020-02-28 11:56:44 -0500 | [diff] [blame] | 10 | #include "src/gpu/GrProgramInfo.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "src/gpu/GrUserStencilSettings.h" |
| 12 | #include "src/gpu/SkGr.h" |
Michael Ludwig | 663afe5 | 2019-06-03 16:46:19 -0400 | [diff] [blame] | 13 | #include "src/gpu/geometry/GrRect.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "src/gpu/ops/GrSimpleMeshDrawOpHelper.h" |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 15 | |
| 16 | GrSimpleMeshDrawOpHelper::GrSimpleMeshDrawOpHelper(const MakeArgs& args, GrAAType aaType, |
Chris Dalton | baa1b35 | 2019-04-03 12:03:00 -0600 | [diff] [blame] | 17 | InputFlags inputFlags) |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 18 | : fProcessors(args.fProcessorSet) |
Chris Dalton | baa1b35 | 2019-04-03 12:03:00 -0600 | [diff] [blame] | 19 | , fPipelineFlags((GrPipeline::InputFlags)inputFlags) |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 20 | , fAAType((int)aaType) |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 21 | , fUsesLocalCoords(false) |
Brian Osman | 605c6d5 | 2019-03-15 12:10:35 -0400 | [diff] [blame] | 22 | , fCompatibleWithCoverageAsAlpha(false) { |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 23 | SkDEBUGCODE(fDidAnalysis = false); |
Brian Salomon | bfd18cd | 2017-08-09 16:27:09 -0400 | [diff] [blame] | 24 | SkDEBUGCODE(fMadePipeline = false); |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 25 | if (GrAATypeIsHW(aaType)) { |
Chris Dalton | baa1b35 | 2019-04-03 12:03:00 -0600 | [diff] [blame] | 26 | fPipelineFlags |= GrPipeline::InputFlags::kHWAntialias; |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 27 | } |
| 28 | } |
| 29 | |
| 30 | GrSimpleMeshDrawOpHelper::~GrSimpleMeshDrawOpHelper() { |
| 31 | if (fProcessors) { |
| 32 | fProcessors->~GrProcessorSet(); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | GrDrawOp::FixedFunctionFlags GrSimpleMeshDrawOpHelper::fixedFunctionFlags() const { |
| 37 | return GrAATypeIsHW((this->aaType())) ? GrDrawOp::FixedFunctionFlags::kUsesHWAA |
| 38 | : GrDrawOp::FixedFunctionFlags::kNone; |
| 39 | } |
| 40 | |
| 41 | bool GrSimpleMeshDrawOpHelper::isCompatible(const GrSimpleMeshDrawOpHelper& that, |
| 42 | const GrCaps& caps, const SkRect& thisBounds, |
Robert Phillips | b69001f | 2019-10-29 12:16:35 -0400 | [diff] [blame] | 43 | const SkRect& thatBounds, bool ignoreAAType) const { |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 44 | if (SkToBool(fProcessors) != SkToBool(that.fProcessors)) { |
| 45 | return false; |
| 46 | } |
| 47 | if (fProcessors) { |
| 48 | if (*fProcessors != *that.fProcessors) { |
| 49 | return false; |
| 50 | } |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 51 | } |
Robert Phillips | b69001f | 2019-10-29 12:16:35 -0400 | [diff] [blame] | 52 | |
| 53 | #ifdef SK_DEBUG |
| 54 | if (ignoreAAType) { |
| 55 | // If we're ignoring AA it should be bc we already know they are the same or that |
| 56 | // the are different but are compatible (i.e., one is AA and the other is None) |
Robert Phillips | bbd459d | 2019-10-29 14:40:03 -0400 | [diff] [blame] | 57 | SkASSERT(fAAType == that.fAAType || |
| 58 | GrMeshDrawOp::CanUpgradeAAOnMerge(this->aaType(), that.aaType())); |
Robert Phillips | b69001f | 2019-10-29 12:16:35 -0400 | [diff] [blame] | 59 | } |
| 60 | #endif |
| 61 | |
| 62 | bool result = fPipelineFlags == that.fPipelineFlags && |
| 63 | (ignoreAAType || fAAType == that.fAAType); |
Brian Osman | 605c6d5 | 2019-03-15 12:10:35 -0400 | [diff] [blame] | 64 | SkASSERT(!result || fCompatibleWithCoverageAsAlpha == that.fCompatibleWithCoverageAsAlpha); |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 65 | SkASSERT(!result || fUsesLocalCoords == that.fUsesLocalCoords); |
| 66 | return result; |
| 67 | } |
| 68 | |
Chris Dalton | 4b62aed | 2019-01-15 11:53:00 -0700 | [diff] [blame] | 69 | GrProcessorSet::Analysis GrSimpleMeshDrawOpHelper::finalizeProcessors( |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 70 | const GrCaps& caps, const GrAppliedClip* clip, bool hasMixedSampledCoverage, |
| 71 | GrClampType clampType, GrProcessorAnalysisCoverage geometryCoverage, |
| 72 | SkPMColor4f* geometryColor, bool* wideColor) { |
Chris Dalton | b8fff0d | 2019-03-05 10:11:58 -0700 | [diff] [blame] | 73 | GrProcessorAnalysisColor color = *geometryColor; |
Brian Osman | 5ced0bf | 2019-03-15 10:15:29 -0400 | [diff] [blame] | 74 | auto result = this->finalizeProcessors( |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 75 | caps, clip, hasMixedSampledCoverage, clampType, geometryCoverage, &color); |
Chris Dalton | b8fff0d | 2019-03-05 10:11:58 -0700 | [diff] [blame] | 76 | color.isConstant(geometryColor); |
Brian Osman | 8fa7ab4 | 2019-03-18 10:22:42 -0400 | [diff] [blame] | 77 | if (wideColor) { |
Brian Osman | 2715bf5 | 2019-12-06 14:38:47 -0500 | [diff] [blame] | 78 | *wideColor = !geometryColor->fitsInBytes(); |
Brian Osman | 8fa7ab4 | 2019-03-18 10:22:42 -0400 | [diff] [blame] | 79 | } |
Chris Dalton | b8fff0d | 2019-03-05 10:11:58 -0700 | [diff] [blame] | 80 | return result; |
| 81 | } |
| 82 | |
| 83 | GrProcessorSet::Analysis GrSimpleMeshDrawOpHelper::finalizeProcessors( |
| 84 | const GrCaps& caps, const GrAppliedClip* clip, const GrUserStencilSettings* userStencil, |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 85 | bool hasMixedSampledCoverage, GrClampType clampType, |
| 86 | GrProcessorAnalysisCoverage geometryCoverage, GrProcessorAnalysisColor* geometryColor) { |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 87 | SkDEBUGCODE(fDidAnalysis = true); |
| 88 | GrProcessorSet::Analysis analysis; |
| 89 | if (fProcessors) { |
| 90 | GrProcessorAnalysisCoverage coverage = geometryCoverage; |
| 91 | if (GrProcessorAnalysisCoverage::kNone == coverage) { |
Chris Dalton | 6982400 | 2017-10-31 00:37:52 -0600 | [diff] [blame] | 92 | coverage = clip->numClipCoverageFragmentProcessors() |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 93 | ? GrProcessorAnalysisCoverage::kSingleChannel |
| 94 | : GrProcessorAnalysisCoverage::kNone; |
| 95 | } |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 96 | SkPMColor4f overrideColor; |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 97 | analysis = fProcessors->finalize(*geometryColor, coverage, clip, userStencil, |
| 98 | hasMixedSampledCoverage, caps, clampType, &overrideColor); |
Brian Salomon | 0088f94 | 2017-07-12 11:51:27 -0400 | [diff] [blame] | 99 | if (analysis.inputColorIsOverridden()) { |
| 100 | *geometryColor = overrideColor; |
| 101 | } |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 102 | } else { |
| 103 | analysis = GrProcessorSet::EmptySetAnalysis(); |
| 104 | } |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 105 | fUsesLocalCoords = analysis.usesLocalCoords(); |
Brian Osman | 605c6d5 | 2019-03-15 12:10:35 -0400 | [diff] [blame] | 106 | fCompatibleWithCoverageAsAlpha = analysis.isCompatibleWithCoverageAsAlpha(); |
Chris Dalton | 4b62aed | 2019-01-15 11:53:00 -0700 | [diff] [blame] | 107 | return analysis; |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 108 | } |
| 109 | |
Robert Phillips | 3968fcb | 2019-12-05 16:40:31 -0500 | [diff] [blame] | 110 | const GrPipeline* GrSimpleMeshDrawOpHelper::CreatePipeline( |
Robert Phillips | 6c59fe4 | 2020-02-27 09:30:37 -0500 | [diff] [blame] | 111 | const GrCaps* caps, |
| 112 | SkArenaAlloc* arena, |
Robert Phillips | fad1e0f | 2020-02-28 09:11:02 -0500 | [diff] [blame] | 113 | const GrSurfaceProxyView* outputView, |
Robert Phillips | 6c59fe4 | 2020-02-27 09:30:37 -0500 | [diff] [blame] | 114 | GrAppliedClip&& appliedClip, |
| 115 | const GrXferProcessor::DstProxyView& dstProxyView, |
| 116 | GrProcessorSet&& processorSet, |
| 117 | GrPipeline::InputFlags pipelineFlags, |
| 118 | const GrUserStencilSettings* stencilSettings) { |
Robert Phillips | 3968fcb | 2019-12-05 16:40:31 -0500 | [diff] [blame] | 119 | GrPipeline::InitArgs pipelineArgs; |
| 120 | |
| 121 | pipelineArgs.fInputFlags = pipelineFlags; |
Robert Phillips | 3968fcb | 2019-12-05 16:40:31 -0500 | [diff] [blame] | 122 | pipelineArgs.fUserStencil = stencilSettings; |
Robert Phillips | ce97857 | 2020-02-28 11:56:44 -0500 | [diff] [blame] | 123 | pipelineArgs.fCaps = caps; |
| 124 | pipelineArgs.fDstProxyView = dstProxyView; |
Robert Phillips | fad1e0f | 2020-02-28 09:11:02 -0500 | [diff] [blame] | 125 | pipelineArgs.fOutputSwizzle = outputView->swizzle(); |
Robert Phillips | 3968fcb | 2019-12-05 16:40:31 -0500 | [diff] [blame] | 126 | |
Robert Phillips | 6c59fe4 | 2020-02-27 09:30:37 -0500 | [diff] [blame] | 127 | return arena->make<GrPipeline>(pipelineArgs, |
| 128 | std::move(processorSet), |
| 129 | std::move(appliedClip)); |
| 130 | } |
| 131 | |
| 132 | const GrPipeline* GrSimpleMeshDrawOpHelper::CreatePipeline( |
| 133 | GrOpFlushState* flushState, |
| 134 | GrProcessorSet&& processorSet, |
| 135 | GrPipeline::InputFlags pipelineFlags, |
| 136 | const GrUserStencilSettings* stencilSettings) { |
| 137 | return CreatePipeline(&flushState->caps(), |
| 138 | flushState->allocator(), |
| 139 | flushState->view(), |
| 140 | flushState->detachAppliedClip(), |
| 141 | flushState->dstProxyView(), |
| 142 | std::move(processorSet), |
| 143 | pipelineFlags, |
| 144 | stencilSettings); |
| 145 | } |
| 146 | |
| 147 | const GrPipeline* GrSimpleMeshDrawOpHelper::createPipeline(GrOpFlushState* flushState) { |
| 148 | return CreatePipeline(&flushState->caps(), |
| 149 | flushState->allocator(), |
| 150 | flushState->view(), |
| 151 | flushState->detachAppliedClip(), |
| 152 | flushState->dstProxyView(), |
| 153 | this->detachProcessorSet(), |
| 154 | this->pipelineFlags()); |
Chris Dalton | 07cdcfc9 | 2019-02-26 11:13:22 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Robert Phillips | ce97857 | 2020-02-28 11:56:44 -0500 | [diff] [blame] | 157 | GrProgramInfo* GrSimpleMeshDrawOpHelper::CreateProgramInfo( |
| 158 | const GrCaps* caps, |
| 159 | SkArenaAlloc* arena, |
| 160 | const GrSurfaceProxyView* outputView, |
| 161 | GrAppliedClip&& appliedClip, |
| 162 | const GrXferProcessor::DstProxyView& dstProxyView, |
| 163 | GrGeometryProcessor* geometryProcessor, |
| 164 | GrProcessorSet&& processorSet, |
Robert Phillips | ac6156c | 2020-02-28 16:02:40 -0500 | [diff] [blame^] | 165 | GrPrimitiveType primitiveType, |
| 166 | GrPipeline::InputFlags pipelineFlags, |
| 167 | const GrUserStencilSettings* stencilSettings) { |
Robert Phillips | ce97857 | 2020-02-28 11:56:44 -0500 | [diff] [blame] | 168 | static constexpr int kZeroPrimProcTextures = 0; |
| 169 | auto fixedDynamicState = GrMeshDrawOp::Target::MakeFixedDynamicState(arena, |
| 170 | &appliedClip, |
| 171 | kZeroPrimProcTextures); |
| 172 | |
| 173 | auto pipeline = CreatePipeline(caps, |
| 174 | arena, |
| 175 | outputView, |
| 176 | std::move(appliedClip), |
| 177 | dstProxyView, |
| 178 | std::move(processorSet), |
Robert Phillips | ac6156c | 2020-02-28 16:02:40 -0500 | [diff] [blame^] | 179 | pipelineFlags, |
| 180 | stencilSettings); |
Robert Phillips | ce97857 | 2020-02-28 11:56:44 -0500 | [diff] [blame] | 181 | |
| 182 | GrRenderTargetProxy* outputProxy = outputView->asRenderTargetProxy(); |
| 183 | |
| 184 | static constexpr int kOneMesh = 1; |
| 185 | auto tmp = arena->make<GrProgramInfo>(outputProxy->numSamples(), |
| 186 | outputProxy->numStencilSamples(), |
| 187 | outputProxy->backendFormat(), |
| 188 | outputView->origin(), |
| 189 | pipeline, |
| 190 | geometryProcessor, |
| 191 | fixedDynamicState, |
| 192 | nullptr, |
| 193 | kOneMesh, |
Robert Phillips | ac6156c | 2020-02-28 16:02:40 -0500 | [diff] [blame^] | 194 | primitiveType); |
Robert Phillips | ce97857 | 2020-02-28 11:56:44 -0500 | [diff] [blame] | 195 | SkASSERT(tmp->primProc().numTextureSamplers() <= 0); |
| 196 | return tmp; |
| 197 | } |
| 198 | |
Brian Osman | 9a390ac | 2018-11-12 09:47:48 -0500 | [diff] [blame] | 199 | #ifdef SK_DEBUG |
Chris Dalton | baa1b35 | 2019-04-03 12:03:00 -0600 | [diff] [blame] | 200 | static void dump_pipeline_flags(GrPipeline::InputFlags flags, SkString* result) { |
| 201 | if (GrPipeline::InputFlags::kNone != flags) { |
| 202 | if (flags & GrPipeline::InputFlags::kSnapVerticesToPixelCenters) { |
| 203 | result->append("Snap vertices to pixel center.\n"); |
| 204 | } |
| 205 | if (flags & GrPipeline::InputFlags::kHWAntialias) { |
| 206 | result->append("HW Antialiasing enabled.\n"); |
| 207 | } |
| 208 | return; |
| 209 | } |
| 210 | result->append("No pipeline flags\n"); |
| 211 | } |
| 212 | |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 213 | SkString GrSimpleMeshDrawOpHelper::dumpInfo() const { |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 214 | const GrProcessorSet& processors = fProcessors ? *fProcessors : GrProcessorSet::EmptySet(); |
| 215 | SkString result = processors.dumpProcessors(); |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 216 | result.append("AA Type: "); |
| 217 | switch (this->aaType()) { |
| 218 | case GrAAType::kNone: |
| 219 | result.append(" none\n"); |
| 220 | break; |
| 221 | case GrAAType::kCoverage: |
| 222 | result.append(" coverage\n"); |
| 223 | break; |
| 224 | case GrAAType::kMSAA: |
| 225 | result.append(" msaa\n"); |
| 226 | break; |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 227 | } |
Chris Dalton | baa1b35 | 2019-04-03 12:03:00 -0600 | [diff] [blame] | 228 | dump_pipeline_flags(fPipelineFlags, &result); |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 229 | return result; |
| 230 | } |
Brian Osman | 9a390ac | 2018-11-12 09:47:48 -0500 | [diff] [blame] | 231 | #endif |