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