blob: 538f3056f0a30f7bb326aa0fa7c67073b3ab4c29 [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
Robert Phillips06273bc2021-08-11 15:43:50 -04008#include "src/gpu/ops/GrSimpleMeshDrawOpHelper.h"
9
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "src/gpu/GrAppliedClip.h"
11#include "src/gpu/GrProcessorSet.h"
Robert Phillipsce978572020-02-28 11:56:44 -050012#include "src/gpu/GrProgramInfo.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "src/gpu/GrUserStencilSettings.h"
14#include "src/gpu/SkGr.h"
Michael Ludwig663afe52019-06-03 16:46:19 -040015#include "src/gpu/geometry/GrRect.h"
Brian Salomonb4d61062017-07-12 11:24:41 -040016
Herb Derbyc76d4092020-10-07 16:46:15 -040017GrSimpleMeshDrawOpHelper::GrSimpleMeshDrawOpHelper(GrProcessorSet* processorSet,
Robert Phillips360ec182020-03-26 13:29:50 -040018 GrAAType aaType,
Chris Daltonbaa1b352019-04-03 12:03:00 -060019 InputFlags inputFlags)
Herb Derbyc76d4092020-10-07 16:46:15 -040020 : fProcessors(processorSet)
Chris Daltonbaa1b352019-04-03 12:03:00 -060021 , fPipelineFlags((GrPipeline::InputFlags)inputFlags)
Brian Salomonb4d61062017-07-12 11:24:41 -040022 , fAAType((int)aaType)
Brian Salomonb4d61062017-07-12 11:24:41 -040023 , fUsesLocalCoords(false)
Brian Osman605c6d52019-03-15 12:10:35 -040024 , fCompatibleWithCoverageAsAlpha(false) {
Brian Salomonb4d61062017-07-12 11:24:41 -040025 SkDEBUGCODE(fDidAnalysis = false);
Brian Salomonbfd18cd2017-08-09 16:27:09 -040026 SkDEBUGCODE(fMadePipeline = false);
Brian Salomonb4d61062017-07-12 11:24:41 -040027}
28
29GrSimpleMeshDrawOpHelper::~GrSimpleMeshDrawOpHelper() {
30 if (fProcessors) {
31 fProcessors->~GrProcessorSet();
32 }
33}
34
35GrDrawOp::FixedFunctionFlags GrSimpleMeshDrawOpHelper::fixedFunctionFlags() const {
Robert Phillips360ec182020-03-26 13:29:50 -040036 return GrAATypeIsHW(this->aaType()) ? GrDrawOp::FixedFunctionFlags::kUsesHWAA
37 : GrDrawOp::FixedFunctionFlags::kNone;
Brian Salomonb4d61062017-07-12 11:24:41 -040038}
39
40bool GrSimpleMeshDrawOpHelper::isCompatible(const GrSimpleMeshDrawOpHelper& that,
41 const GrCaps& caps, const SkRect& thisBounds,
Robert Phillipsb69001f2019-10-29 12:16:35 -040042 const SkRect& thatBounds, bool ignoreAAType) const {
Brian Salomonb4d61062017-07-12 11:24:41 -040043 if (SkToBool(fProcessors) != SkToBool(that.fProcessors)) {
44 return false;
45 }
46 if (fProcessors) {
47 if (*fProcessors != *that.fProcessors) {
48 return false;
49 }
Brian Salomonb4d61062017-07-12 11:24:41 -040050 }
Robert Phillipsb69001f2019-10-29 12:16:35 -040051
52#ifdef SK_DEBUG
53 if (ignoreAAType) {
54 // If we're ignoring AA it should be bc we already know they are the same or that
55 // the are different but are compatible (i.e., one is AA and the other is None)
Robert Phillipsbbd459d2019-10-29 14:40:03 -040056 SkASSERT(fAAType == that.fAAType ||
57 GrMeshDrawOp::CanUpgradeAAOnMerge(this->aaType(), that.aaType()));
Robert Phillipsb69001f2019-10-29 12:16:35 -040058 }
59#endif
60
61 bool result = fPipelineFlags == that.fPipelineFlags &&
62 (ignoreAAType || fAAType == that.fAAType);
Brian Osman605c6d52019-03-15 12:10:35 -040063 SkASSERT(!result || fCompatibleWithCoverageAsAlpha == that.fCompatibleWithCoverageAsAlpha);
Brian Salomonb4d61062017-07-12 11:24:41 -040064 SkASSERT(!result || fUsesLocalCoords == that.fUsesLocalCoords);
65 return result;
66}
67
Chris Dalton4b62aed2019-01-15 11:53:00 -070068GrProcessorSet::Analysis GrSimpleMeshDrawOpHelper::finalizeProcessors(
Chris Dalton57ab06c2021-04-22 12:57:28 -060069 const GrCaps& caps, const GrAppliedClip* clip, GrClampType clampType,
70 GrProcessorAnalysisCoverage geometryCoverage, SkPMColor4f* geometryColor, bool* wideColor) {
Chris Daltonb8fff0d2019-03-05 10:11:58 -070071 GrProcessorAnalysisColor color = *geometryColor;
Chris Dalton57ab06c2021-04-22 12:57:28 -060072 auto result = this->finalizeProcessors(caps, clip, clampType, geometryCoverage, &color);
Chris Daltonb8fff0d2019-03-05 10:11:58 -070073 color.isConstant(geometryColor);
Brian Osman8fa7ab42019-03-18 10:22:42 -040074 if (wideColor) {
Brian Osman2715bf52019-12-06 14:38:47 -050075 *wideColor = !geometryColor->fitsInBytes();
Brian Osman8fa7ab42019-03-18 10:22:42 -040076 }
Chris Daltonb8fff0d2019-03-05 10:11:58 -070077 return result;
78}
79
80GrProcessorSet::Analysis GrSimpleMeshDrawOpHelper::finalizeProcessors(
81 const GrCaps& caps, const GrAppliedClip* clip, const GrUserStencilSettings* userStencil,
Chris Dalton57ab06c2021-04-22 12:57:28 -060082 GrClampType clampType, GrProcessorAnalysisCoverage geometryCoverage,
83 GrProcessorAnalysisColor* geometryColor) {
Brian Salomonb4d61062017-07-12 11:24:41 -040084 SkDEBUGCODE(fDidAnalysis = true);
85 GrProcessorSet::Analysis analysis;
86 if (fProcessors) {
87 GrProcessorAnalysisCoverage coverage = geometryCoverage;
88 if (GrProcessorAnalysisCoverage::kNone == coverage) {
Chris Dalton83420eb2021-06-23 18:47:09 -060089 coverage = (clip && clip->hasCoverageFragmentProcessor())
Brian Salomonb4d61062017-07-12 11:24:41 -040090 ? GrProcessorAnalysisCoverage::kSingleChannel
91 : GrProcessorAnalysisCoverage::kNone;
92 }
Brian Osmancf860852018-10-31 14:04:39 -040093 SkPMColor4f overrideColor;
Chris Dalton57ab06c2021-04-22 12:57:28 -060094 analysis = fProcessors->finalize(*geometryColor, coverage, clip, userStencil, caps,
95 clampType, &overrideColor);
Brian Salomon0088f942017-07-12 11:51:27 -040096 if (analysis.inputColorIsOverridden()) {
97 *geometryColor = overrideColor;
98 }
Brian Salomonb4d61062017-07-12 11:24:41 -040099 } else {
100 analysis = GrProcessorSet::EmptySetAnalysis();
101 }
Brian Salomonb4d61062017-07-12 11:24:41 -0400102 fUsesLocalCoords = analysis.usesLocalCoords();
Brian Osman605c6d52019-03-15 12:10:35 -0400103 fCompatibleWithCoverageAsAlpha = analysis.isCompatibleWithCoverageAsAlpha();
Chris Dalton4b62aed2019-01-15 11:53:00 -0700104 return analysis;
Brian Salomonb4d61062017-07-12 11:24:41 -0400105}
106
Robert Phillips3968fcb2019-12-05 16:40:31 -0500107const GrPipeline* GrSimpleMeshDrawOpHelper::CreatePipeline(
Robert Phillips6c59fe42020-02-27 09:30:37 -0500108 const GrCaps* caps,
109 SkArenaAlloc* arena,
Brian Salomon8afde5f2020-04-01 16:22:00 -0400110 GrSwizzle writeViewSwizzle,
Robert Phillips6c59fe42020-02-27 09:30:37 -0500111 GrAppliedClip&& appliedClip,
John Stiles52cb1d02021-06-02 11:58:05 -0400112 const GrDstProxyView& dstProxyView,
Robert Phillips6c59fe42020-02-27 09:30:37 -0500113 GrProcessorSet&& processorSet,
Chris Dalton1b6a43c2020-09-25 12:21:18 -0600114 GrPipeline::InputFlags pipelineFlags) {
Robert Phillips3968fcb2019-12-05 16:40:31 -0500115 GrPipeline::InitArgs pipelineArgs;
116
117 pipelineArgs.fInputFlags = pipelineFlags;
Robert Phillipsce978572020-02-28 11:56:44 -0500118 pipelineArgs.fCaps = caps;
119 pipelineArgs.fDstProxyView = dstProxyView;
Brian Salomon8afde5f2020-04-01 16:22:00 -0400120 pipelineArgs.fWriteSwizzle = writeViewSwizzle;
Robert Phillips3968fcb2019-12-05 16:40:31 -0500121
Robert Phillips6c59fe42020-02-27 09:30:37 -0500122 return arena->make<GrPipeline>(pipelineArgs,
123 std::move(processorSet),
124 std::move(appliedClip));
125}
126
127const GrPipeline* GrSimpleMeshDrawOpHelper::CreatePipeline(
128 GrOpFlushState* flushState,
129 GrProcessorSet&& processorSet,
Chris Dalton1b6a43c2020-09-25 12:21:18 -0600130 GrPipeline::InputFlags pipelineFlags) {
Robert Phillips6c59fe42020-02-27 09:30:37 -0500131 return CreatePipeline(&flushState->caps(),
132 flushState->allocator(),
Adlai Hollere2296f72020-11-19 13:41:26 -0500133 flushState->writeView().swizzle(),
Robert Phillips6c59fe42020-02-27 09:30:37 -0500134 flushState->detachAppliedClip(),
135 flushState->dstProxyView(),
136 std::move(processorSet),
Chris Dalton1b6a43c2020-09-25 12:21:18 -0600137 pipelineFlags);
Robert Phillips6c59fe42020-02-27 09:30:37 -0500138}
139
140const GrPipeline* GrSimpleMeshDrawOpHelper::createPipeline(GrOpFlushState* flushState) {
141 return CreatePipeline(&flushState->caps(),
142 flushState->allocator(),
Adlai Hollere2296f72020-11-19 13:41:26 -0500143 flushState->writeView().swizzle(),
Robert Phillips6c59fe42020-02-27 09:30:37 -0500144 flushState->detachAppliedClip(),
145 flushState->dstProxyView(),
146 this->detachProcessorSet(),
147 this->pipelineFlags());
Chris Dalton07cdcfc92019-02-26 11:13:22 -0700148}
149
Chris Dalton1b6a43c2020-09-25 12:21:18 -0600150const GrPipeline* GrSimpleMeshDrawOpHelper::createPipeline(
151 const GrCaps* caps,
152 SkArenaAlloc* arena,
153 GrSwizzle writeViewSwizzle,
154 GrAppliedClip&& appliedClip,
John Stiles52cb1d02021-06-02 11:58:05 -0400155 const GrDstProxyView& dstProxyView) {
Chris Dalton1b6a43c2020-09-25 12:21:18 -0600156 return GrSimpleMeshDrawOpHelper::CreatePipeline(caps,
157 arena,
158 writeViewSwizzle,
159 std::move(appliedClip),
160 dstProxyView,
161 this->detachProcessorSet(),
162 this->pipelineFlags());
163}
164
Robert Phillipsce978572020-02-28 11:56:44 -0500165GrProgramInfo* GrSimpleMeshDrawOpHelper::CreateProgramInfo(
166 const GrCaps* caps,
167 SkArenaAlloc* arena,
Adlai Hollere2296f72020-11-19 13:41:26 -0500168 const GrSurfaceProxyView& writeView,
Chris Dalton2a26c502021-08-26 10:05:11 -0600169 bool usesMSAASurface,
Robert Phillipsce978572020-02-28 11:56:44 -0500170 GrAppliedClip&& appliedClip,
John Stiles52cb1d02021-06-02 11:58:05 -0400171 const GrDstProxyView& dstProxyView,
Robert Phillipsce978572020-02-28 11:56:44 -0500172 GrGeometryProcessor* geometryProcessor,
173 GrProcessorSet&& processorSet,
Robert Phillipsac6156c2020-02-28 16:02:40 -0500174 GrPrimitiveType primitiveType,
Greg Danield358cbe2020-09-11 09:33:54 -0400175 GrXferBarrierFlags renderPassXferBarriers,
Greg Daniel42dbca52020-11-20 10:22:43 -0500176 GrLoadOp colorLoadOp,
Robert Phillipsac6156c2020-02-28 16:02:40 -0500177 GrPipeline::InputFlags pipelineFlags,
Robert Phillips709e2402020-03-23 18:29:16 +0000178 const GrUserStencilSettings* stencilSettings) {
Robert Phillipsce978572020-02-28 11:56:44 -0500179 auto pipeline = CreatePipeline(caps,
180 arena,
Adlai Hollere2296f72020-11-19 13:41:26 -0500181 writeView.swizzle(),
Robert Phillipsce978572020-02-28 11:56:44 -0500182 std::move(appliedClip),
183 dstProxyView,
184 std::move(processorSet),
Chris Dalton1b6a43c2020-09-25 12:21:18 -0600185 pipelineFlags);
Robert Phillipsce978572020-02-28 11:56:44 -0500186
Chris Dalton2a26c502021-08-26 10:05:11 -0600187 return CreateProgramInfo(caps, arena, pipeline, writeView, usesMSAASurface, geometryProcessor,
188 primitiveType, renderPassXferBarriers, colorLoadOp, stencilSettings);
Robert Phillips4f93c572020-03-18 08:13:53 -0400189}
190
Chris Dalton2a26c502021-08-26 10:05:11 -0600191GrProgramInfo* GrSimpleMeshDrawOpHelper::CreateProgramInfo(const GrCaps* caps,
192 SkArenaAlloc* arena,
Robert Phillips4f93c572020-03-18 08:13:53 -0400193 const GrPipeline* pipeline,
Adlai Hollere2296f72020-11-19 13:41:26 -0500194 const GrSurfaceProxyView& writeView,
Chris Dalton2a26c502021-08-26 10:05:11 -0600195 bool usesMSAASurface,
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,
Greg Daniel42dbca52020-11-20 10:22:43 -0500199 GrLoadOp colorLoadOp,
Chris Dalton1b6a43c2020-09-25 12:21:18 -0600200 const GrUserStencilSettings* stencilSettings) {
Chris Dalton2a26c502021-08-26 10:05:11 -0600201 auto tmp = arena->make<GrProgramInfo>(*caps,
202 writeView,
203 usesMSAASurface,
Robert Phillipsce978572020-02-28 11:56:44 -0500204 pipeline,
Chris Dalton1b6a43c2020-09-25 12:21:18 -0600205 stencilSettings,
Robert Phillipsce978572020-02-28 11:56:44 -0500206 geometryProcessor,
Greg Danield358cbe2020-09-11 09:33:54 -0400207 primitiveType,
208 0,
Greg Daniel42dbca52020-11-20 10:22:43 -0500209 xferBarrierFlags,
210 colorLoadOp);
Robert Phillipsce978572020-02-28 11:56:44 -0500211 return tmp;
212}
213
Robert Phillipsb58098f2020-03-02 16:25:29 -0500214GrProgramInfo* GrSimpleMeshDrawOpHelper::createProgramInfo(
215 const GrCaps* caps,
216 SkArenaAlloc* arena,
Adlai Hollere2296f72020-11-19 13:41:26 -0500217 const GrSurfaceProxyView& writeView,
Chris Dalton2a26c502021-08-26 10:05:11 -0600218 bool usesMSAASurface,
Robert Phillipsb58098f2020-03-02 16:25:29 -0500219 GrAppliedClip&& appliedClip,
John Stiles52cb1d02021-06-02 11:58:05 -0400220 const GrDstProxyView& dstProxyView,
Robert Phillipsb58098f2020-03-02 16:25:29 -0500221 GrGeometryProcessor* gp,
Greg Danield358cbe2020-09-11 09:33:54 -0400222 GrPrimitiveType primType,
Greg Daniel42dbca52020-11-20 10:22:43 -0500223 GrXferBarrierFlags renderPassXferBarriers,
224 GrLoadOp colorLoadOp) {
Robert Phillipsb58098f2020-03-02 16:25:29 -0500225 return CreateProgramInfo(caps,
226 arena,
Brian Salomon8afde5f2020-04-01 16:22:00 -0400227 writeView,
Chris Dalton2a26c502021-08-26 10:05:11 -0600228 usesMSAASurface,
Robert Phillipsb58098f2020-03-02 16:25:29 -0500229 std::move(appliedClip),
230 dstProxyView,
231 gp,
232 this->detachProcessorSet(),
233 primType,
Greg Danield358cbe2020-09-11 09:33:54 -0400234 renderPassXferBarriers,
Greg Daniel42dbca52020-11-20 10:22:43 -0500235 colorLoadOp,
Robert Phillipsb58098f2020-03-02 16:25:29 -0500236 this->pipelineFlags());
237}
238
John Stiles8d9bf642020-08-12 15:07:45 -0400239#if GR_TEST_UTILS
Chris Daltonbaa1b352019-04-03 12:03:00 -0600240static void dump_pipeline_flags(GrPipeline::InputFlags flags, SkString* result) {
241 if (GrPipeline::InputFlags::kNone != flags) {
242 if (flags & GrPipeline::InputFlags::kSnapVerticesToPixelCenters) {
243 result->append("Snap vertices to pixel center.\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