blob: 23bc438002c70255572584d1fa1f7a0dbe7f9f4e [file] [log] [blame]
Brian Salomonb4d61062017-07-12 11:24:41 -04001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -05008#include "src/gpu/GrAppliedClip.h"
9#include "src/gpu/GrProcessorSet.h"
Robert Phillipsce978572020-02-28 11:56:44 -050010#include "src/gpu/GrProgramInfo.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "src/gpu/GrUserStencilSettings.h"
12#include "src/gpu/SkGr.h"
Michael Ludwig663afe52019-06-03 16:46:19 -040013#include "src/gpu/geometry/GrRect.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "src/gpu/ops/GrSimpleMeshDrawOpHelper.h"
Brian Salomonb4d61062017-07-12 11:24:41 -040015
Robert Phillips360ec182020-03-26 13:29:50 -040016GrSimpleMeshDrawOpHelper::GrSimpleMeshDrawOpHelper(const MakeArgs& args,
17 GrAAType aaType,
Chris Daltonbaa1b352019-04-03 12:03:00 -060018 InputFlags inputFlags)
Brian Salomonb4d61062017-07-12 11:24:41 -040019 : fProcessors(args.fProcessorSet)
Chris Daltonbaa1b352019-04-03 12:03:00 -060020 , fPipelineFlags((GrPipeline::InputFlags)inputFlags)
Brian Salomonb4d61062017-07-12 11:24:41 -040021 , fAAType((int)aaType)
Brian Salomonb4d61062017-07-12 11:24:41 -040022 , fUsesLocalCoords(false)
Brian Osman605c6d52019-03-15 12:10:35 -040023 , fCompatibleWithCoverageAsAlpha(false) {
Brian Salomonb4d61062017-07-12 11:24:41 -040024 SkDEBUGCODE(fDidAnalysis = false);
Brian Salomonbfd18cd2017-08-09 16:27:09 -040025 SkDEBUGCODE(fMadePipeline = false);
Brian Salomonb4d61062017-07-12 11:24:41 -040026 if (GrAATypeIsHW(aaType)) {
Chris Daltonbaa1b352019-04-03 12:03:00 -060027 fPipelineFlags |= GrPipeline::InputFlags::kHWAntialias;
Brian Salomonb4d61062017-07-12 11:24:41 -040028 }
29}
30
31GrSimpleMeshDrawOpHelper::~GrSimpleMeshDrawOpHelper() {
32 if (fProcessors) {
33 fProcessors->~GrProcessorSet();
34 }
35}
36
37GrDrawOp::FixedFunctionFlags GrSimpleMeshDrawOpHelper::fixedFunctionFlags() const {
Robert Phillips360ec182020-03-26 13:29:50 -040038 return GrAATypeIsHW(this->aaType()) ? GrDrawOp::FixedFunctionFlags::kUsesHWAA
39 : GrDrawOp::FixedFunctionFlags::kNone;
Brian Salomonb4d61062017-07-12 11:24:41 -040040}
41
42bool GrSimpleMeshDrawOpHelper::isCompatible(const GrSimpleMeshDrawOpHelper& that,
43 const GrCaps& caps, const SkRect& thisBounds,
Robert Phillipsb69001f2019-10-29 12:16:35 -040044 const SkRect& thatBounds, bool ignoreAAType) const {
Brian Salomonb4d61062017-07-12 11:24:41 -040045 if (SkToBool(fProcessors) != SkToBool(that.fProcessors)) {
46 return false;
47 }
48 if (fProcessors) {
49 if (*fProcessors != *that.fProcessors) {
50 return false;
51 }
Brian Salomonb4d61062017-07-12 11:24:41 -040052 }
Robert Phillipsb69001f2019-10-29 12:16:35 -040053
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 Phillipsbbd459d2019-10-29 14:40:03 -040058 SkASSERT(fAAType == that.fAAType ||
59 GrMeshDrawOp::CanUpgradeAAOnMerge(this->aaType(), that.aaType()));
Robert Phillipsb69001f2019-10-29 12:16:35 -040060 }
61#endif
62
63 bool result = fPipelineFlags == that.fPipelineFlags &&
64 (ignoreAAType || fAAType == that.fAAType);
Brian Osman605c6d52019-03-15 12:10:35 -040065 SkASSERT(!result || fCompatibleWithCoverageAsAlpha == that.fCompatibleWithCoverageAsAlpha);
Brian Salomonb4d61062017-07-12 11:24:41 -040066 SkASSERT(!result || fUsesLocalCoords == that.fUsesLocalCoords);
67 return result;
68}
69
Chris Dalton4b62aed2019-01-15 11:53:00 -070070GrProcessorSet::Analysis GrSimpleMeshDrawOpHelper::finalizeProcessors(
Chris Dalton6ce447a2019-06-23 18:07:38 -060071 const GrCaps& caps, const GrAppliedClip* clip, bool hasMixedSampledCoverage,
72 GrClampType clampType, GrProcessorAnalysisCoverage geometryCoverage,
73 SkPMColor4f* geometryColor, bool* wideColor) {
Chris Daltonb8fff0d2019-03-05 10:11:58 -070074 GrProcessorAnalysisColor color = *geometryColor;
Brian Osman5ced0bf2019-03-15 10:15:29 -040075 auto result = this->finalizeProcessors(
Chris Dalton6ce447a2019-06-23 18:07:38 -060076 caps, clip, hasMixedSampledCoverage, clampType, geometryCoverage, &color);
Chris Daltonb8fff0d2019-03-05 10:11:58 -070077 color.isConstant(geometryColor);
Brian Osman8fa7ab42019-03-18 10:22:42 -040078 if (wideColor) {
Brian Osman2715bf52019-12-06 14:38:47 -050079 *wideColor = !geometryColor->fitsInBytes();
Brian Osman8fa7ab42019-03-18 10:22:42 -040080 }
Chris Daltonb8fff0d2019-03-05 10:11:58 -070081 return result;
82}
83
84GrProcessorSet::Analysis GrSimpleMeshDrawOpHelper::finalizeProcessors(
85 const GrCaps& caps, const GrAppliedClip* clip, const GrUserStencilSettings* userStencil,
Chris Dalton6ce447a2019-06-23 18:07:38 -060086 bool hasMixedSampledCoverage, GrClampType clampType,
87 GrProcessorAnalysisCoverage geometryCoverage, GrProcessorAnalysisColor* geometryColor) {
Brian Salomonb4d61062017-07-12 11:24:41 -040088 SkDEBUGCODE(fDidAnalysis = true);
89 GrProcessorSet::Analysis analysis;
90 if (fProcessors) {
91 GrProcessorAnalysisCoverage coverage = geometryCoverage;
92 if (GrProcessorAnalysisCoverage::kNone == coverage) {
John Stiles59e18dc2020-07-22 18:18:12 -040093 coverage = clip->hasCoverageFragmentProcessor()
Brian Salomonb4d61062017-07-12 11:24:41 -040094 ? GrProcessorAnalysisCoverage::kSingleChannel
95 : GrProcessorAnalysisCoverage::kNone;
96 }
Brian Osmancf860852018-10-31 14:04:39 -040097 SkPMColor4f overrideColor;
Chris Dalton6ce447a2019-06-23 18:07:38 -060098 analysis = fProcessors->finalize(*geometryColor, coverage, clip, userStencil,
99 hasMixedSampledCoverage, caps, clampType, &overrideColor);
Brian Salomon0088f942017-07-12 11:51:27 -0400100 if (analysis.inputColorIsOverridden()) {
101 *geometryColor = overrideColor;
102 }
Brian Salomonb4d61062017-07-12 11:24:41 -0400103 } else {
104 analysis = GrProcessorSet::EmptySetAnalysis();
105 }
Brian Salomonb4d61062017-07-12 11:24:41 -0400106 fUsesLocalCoords = analysis.usesLocalCoords();
Brian Osman605c6d52019-03-15 12:10:35 -0400107 fCompatibleWithCoverageAsAlpha = analysis.isCompatibleWithCoverageAsAlpha();
Chris Dalton4b62aed2019-01-15 11:53:00 -0700108 return analysis;
Brian Salomonb4d61062017-07-12 11:24:41 -0400109}
110
Robert Phillips3968fcb2019-12-05 16:40:31 -0500111const GrPipeline* GrSimpleMeshDrawOpHelper::CreatePipeline(
Robert Phillips6c59fe42020-02-27 09:30:37 -0500112 const GrCaps* caps,
113 SkArenaAlloc* arena,
Brian Salomon8afde5f2020-04-01 16:22:00 -0400114 GrSwizzle writeViewSwizzle,
Robert Phillips6c59fe42020-02-27 09:30:37 -0500115 GrAppliedClip&& appliedClip,
116 const GrXferProcessor::DstProxyView& dstProxyView,
117 GrProcessorSet&& processorSet,
Chris Dalton1b6a43c2020-09-25 12:21:18 -0600118 GrPipeline::InputFlags pipelineFlags) {
Robert Phillips3968fcb2019-12-05 16:40:31 -0500119 GrPipeline::InitArgs pipelineArgs;
120
121 pipelineArgs.fInputFlags = pipelineFlags;
Robert Phillipsce978572020-02-28 11:56:44 -0500122 pipelineArgs.fCaps = caps;
123 pipelineArgs.fDstProxyView = dstProxyView;
Brian Salomon8afde5f2020-04-01 16:22:00 -0400124 pipelineArgs.fWriteSwizzle = writeViewSwizzle;
Robert Phillips3968fcb2019-12-05 16:40:31 -0500125
Robert Phillips6c59fe42020-02-27 09:30:37 -0500126 return arena->make<GrPipeline>(pipelineArgs,
127 std::move(processorSet),
128 std::move(appliedClip));
129}
130
131const GrPipeline* GrSimpleMeshDrawOpHelper::CreatePipeline(
132 GrOpFlushState* flushState,
133 GrProcessorSet&& processorSet,
Chris Dalton1b6a43c2020-09-25 12:21:18 -0600134 GrPipeline::InputFlags pipelineFlags) {
Robert Phillips6c59fe42020-02-27 09:30:37 -0500135 return CreatePipeline(&flushState->caps(),
136 flushState->allocator(),
Brian Salomon8afde5f2020-04-01 16:22:00 -0400137 flushState->writeView()->swizzle(),
Robert Phillips6c59fe42020-02-27 09:30:37 -0500138 flushState->detachAppliedClip(),
139 flushState->dstProxyView(),
140 std::move(processorSet),
Chris Dalton1b6a43c2020-09-25 12:21:18 -0600141 pipelineFlags);
Robert Phillips6c59fe42020-02-27 09:30:37 -0500142}
143
144const GrPipeline* GrSimpleMeshDrawOpHelper::createPipeline(GrOpFlushState* flushState) {
145 return CreatePipeline(&flushState->caps(),
146 flushState->allocator(),
Brian Salomon8afde5f2020-04-01 16:22:00 -0400147 flushState->writeView()->swizzle(),
Robert Phillips6c59fe42020-02-27 09:30:37 -0500148 flushState->detachAppliedClip(),
149 flushState->dstProxyView(),
150 this->detachProcessorSet(),
151 this->pipelineFlags());
Chris Dalton07cdcfc92019-02-26 11:13:22 -0700152}
153
Chris Dalton1b6a43c2020-09-25 12:21:18 -0600154const GrPipeline* GrSimpleMeshDrawOpHelper::createPipeline(
155 const GrCaps* caps,
156 SkArenaAlloc* arena,
157 GrSwizzle writeViewSwizzle,
158 GrAppliedClip&& appliedClip,
159 const GrXferProcessor::DstProxyView& dstProxyView) {
160 return GrSimpleMeshDrawOpHelper::CreatePipeline(caps,
161 arena,
162 writeViewSwizzle,
163 std::move(appliedClip),
164 dstProxyView,
165 this->detachProcessorSet(),
166 this->pipelineFlags());
167}
168
Robert Phillipsce978572020-02-28 11:56:44 -0500169GrProgramInfo* GrSimpleMeshDrawOpHelper::CreateProgramInfo(
170 const GrCaps* caps,
171 SkArenaAlloc* arena,
Brian Salomon8afde5f2020-04-01 16:22:00 -0400172 const GrSurfaceProxyView* writeView,
Robert Phillipsce978572020-02-28 11:56:44 -0500173 GrAppliedClip&& appliedClip,
174 const GrXferProcessor::DstProxyView& dstProxyView,
175 GrGeometryProcessor* geometryProcessor,
176 GrProcessorSet&& processorSet,
Robert Phillipsac6156c2020-02-28 16:02:40 -0500177 GrPrimitiveType primitiveType,
Greg Danield358cbe2020-09-11 09:33:54 -0400178 GrXferBarrierFlags renderPassXferBarriers,
Robert Phillipsac6156c2020-02-28 16:02:40 -0500179 GrPipeline::InputFlags pipelineFlags,
Robert Phillips709e2402020-03-23 18:29:16 +0000180 const GrUserStencilSettings* stencilSettings) {
Robert Phillipsce978572020-02-28 11:56:44 -0500181 auto pipeline = CreatePipeline(caps,
182 arena,
Brian Salomon8afde5f2020-04-01 16:22:00 -0400183 writeView->swizzle(),
Robert Phillipsce978572020-02-28 11:56:44 -0500184 std::move(appliedClip),
185 dstProxyView,
186 std::move(processorSet),
Chris Dalton1b6a43c2020-09-25 12:21:18 -0600187 pipelineFlags);
Robert Phillipsce978572020-02-28 11:56:44 -0500188
Greg Danield358cbe2020-09-11 09:33:54 -0400189 return CreateProgramInfo(arena, pipeline, writeView, geometryProcessor, primitiveType,
Chris Dalton1b6a43c2020-09-25 12:21:18 -0600190 renderPassXferBarriers, stencilSettings);
Robert Phillips4f93c572020-03-18 08:13:53 -0400191}
192
193GrProgramInfo* GrSimpleMeshDrawOpHelper::CreateProgramInfo(SkArenaAlloc* arena,
194 const GrPipeline* pipeline,
Brian Salomon8afde5f2020-04-01 16:22:00 -0400195 const GrSurfaceProxyView* writeView,
Robert Phillips4f93c572020-03-18 08:13:53 -0400196 GrGeometryProcessor* geometryProcessor,
Greg Danield358cbe2020-09-11 09:33:54 -0400197 GrPrimitiveType primitiveType,
Chris Dalton1b6a43c2020-09-25 12:21:18 -0600198 GrXferBarrierFlags xferBarrierFlags,
199 const GrUserStencilSettings* stencilSettings) {
Brian Salomon8afde5f2020-04-01 16:22:00 -0400200 GrRenderTargetProxy* outputProxy = writeView->asRenderTargetProxy();
Robert Phillipsce978572020-02-28 11:56:44 -0500201
Robert Phillipsce978572020-02-28 11:56:44 -0500202 auto tmp = arena->make<GrProgramInfo>(outputProxy->numSamples(),
203 outputProxy->numStencilSamples(),
204 outputProxy->backendFormat(),
Brian Salomon8afde5f2020-04-01 16:22:00 -0400205 writeView->origin(),
Robert Phillipsce978572020-02-28 11:56:44 -0500206 pipeline,
Chris Dalton1b6a43c2020-09-25 12:21:18 -0600207 stencilSettings,
Robert Phillipsce978572020-02-28 11:56:44 -0500208 geometryProcessor,
Greg Danield358cbe2020-09-11 09:33:54 -0400209 primitiveType,
210 0,
Chris Dalton1b6a43c2020-09-25 12:21:18 -0600211 xferBarrierFlags);
Robert Phillipsce978572020-02-28 11:56:44 -0500212 return tmp;
213}
214
Robert Phillipsb58098f2020-03-02 16:25:29 -0500215GrProgramInfo* GrSimpleMeshDrawOpHelper::createProgramInfo(
216 const GrCaps* caps,
217 SkArenaAlloc* arena,
Brian Salomon8afde5f2020-04-01 16:22:00 -0400218 const GrSurfaceProxyView* writeView,
Robert Phillipsb58098f2020-03-02 16:25:29 -0500219 GrAppliedClip&& appliedClip,
220 const GrXferProcessor::DstProxyView& dstProxyView,
221 GrGeometryProcessor* gp,
Greg Danield358cbe2020-09-11 09:33:54 -0400222 GrPrimitiveType primType,
223 GrXferBarrierFlags renderPassXferBarriers) {
Robert Phillipsb58098f2020-03-02 16:25:29 -0500224 return CreateProgramInfo(caps,
225 arena,
Brian Salomon8afde5f2020-04-01 16:22:00 -0400226 writeView,
Robert Phillipsb58098f2020-03-02 16:25:29 -0500227 std::move(appliedClip),
228 dstProxyView,
229 gp,
230 this->detachProcessorSet(),
231 primType,
Greg Danield358cbe2020-09-11 09:33:54 -0400232 renderPassXferBarriers,
Robert Phillipsb58098f2020-03-02 16:25:29 -0500233 this->pipelineFlags());
234}
235
John Stiles8d9bf642020-08-12 15:07:45 -0400236#if GR_TEST_UTILS
Chris Daltonbaa1b352019-04-03 12:03:00 -0600237static void dump_pipeline_flags(GrPipeline::InputFlags flags, SkString* result) {
238 if (GrPipeline::InputFlags::kNone != flags) {
239 if (flags & GrPipeline::InputFlags::kSnapVerticesToPixelCenters) {
240 result->append("Snap vertices to pixel center.\n");
241 }
242 if (flags & GrPipeline::InputFlags::kHWAntialias) {
243 result->append("HW Antialiasing enabled.\n");
244 }
Chris Dalton1b6a43c2020-09-25 12:21:18 -0600245 if (flags & GrPipeline::InputFlags::kWireframe) {
246 result->append("Wireframe enabled.\n");
247 }
248 if (flags & GrPipeline::InputFlags::kConservativeRaster) {
249 result->append("Conservative raster enabled.\n");
250 }
Chris Daltonbaa1b352019-04-03 12:03:00 -0600251 return;
252 }
253 result->append("No pipeline flags\n");
254}
255
Brian Salomonb4d61062017-07-12 11:24:41 -0400256SkString GrSimpleMeshDrawOpHelper::dumpInfo() const {
Brian Salomon91326c32017-08-09 16:02:19 -0400257 const GrProcessorSet& processors = fProcessors ? *fProcessors : GrProcessorSet::EmptySet();
258 SkString result = processors.dumpProcessors();
Brian Salomonb4d61062017-07-12 11:24:41 -0400259 result.append("AA Type: ");
260 switch (this->aaType()) {
261 case GrAAType::kNone:
262 result.append(" none\n");
263 break;
264 case GrAAType::kCoverage:
265 result.append(" coverage\n");
266 break;
267 case GrAAType::kMSAA:
268 result.append(" msaa\n");
269 break;
Brian Salomonb4d61062017-07-12 11:24:41 -0400270 }
Chris Daltonbaa1b352019-04-03 12:03:00 -0600271 dump_pipeline_flags(fPipelineFlags, &result);
Brian Salomonb4d61062017-07-12 11:24:41 -0400272 return result;
273}
Brian Osman9a390ac2018-11-12 09:47:48 -0500274#endif