blob: 5c29d4f6eec5bc7242507f96c3eae80e66d47aa8 [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
Herb Derbyc76d4092020-10-07 16:46:15 -040016GrSimpleMeshDrawOpHelper::GrSimpleMeshDrawOpHelper(GrProcessorSet* processorSet,
Robert Phillips360ec182020-03-26 13:29:50 -040017 GrAAType aaType,
Chris Daltonbaa1b352019-04-03 12:03:00 -060018 InputFlags inputFlags)
Herb Derbyc76d4092020-10-07 16:46:15 -040019 : fProcessors(processorSet)
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 Dalton57ab06c2021-04-22 12:57:28 -060071 const GrCaps& caps, const GrAppliedClip* clip, GrClampType clampType,
72 GrProcessorAnalysisCoverage geometryCoverage, SkPMColor4f* geometryColor, bool* wideColor) {
Chris Daltonb8fff0d2019-03-05 10:11:58 -070073 GrProcessorAnalysisColor color = *geometryColor;
Chris Dalton57ab06c2021-04-22 12:57:28 -060074 auto result = this->finalizeProcessors(caps, clip, clampType, geometryCoverage, &color);
Chris Daltonb8fff0d2019-03-05 10:11:58 -070075 color.isConstant(geometryColor);
Brian Osman8fa7ab42019-03-18 10:22:42 -040076 if (wideColor) {
Brian Osman2715bf52019-12-06 14:38:47 -050077 *wideColor = !geometryColor->fitsInBytes();
Brian Osman8fa7ab42019-03-18 10:22:42 -040078 }
Chris Daltonb8fff0d2019-03-05 10:11:58 -070079 return result;
80}
81
82GrProcessorSet::Analysis GrSimpleMeshDrawOpHelper::finalizeProcessors(
83 const GrCaps& caps, const GrAppliedClip* clip, const GrUserStencilSettings* userStencil,
Chris Dalton57ab06c2021-04-22 12:57:28 -060084 GrClampType clampType, GrProcessorAnalysisCoverage geometryCoverage,
85 GrProcessorAnalysisColor* geometryColor) {
Brian Salomonb4d61062017-07-12 11:24:41 -040086 SkDEBUGCODE(fDidAnalysis = true);
87 GrProcessorSet::Analysis analysis;
88 if (fProcessors) {
89 GrProcessorAnalysisCoverage coverage = geometryCoverage;
90 if (GrProcessorAnalysisCoverage::kNone == coverage) {
John Stiles59e18dc2020-07-22 18:18:12 -040091 coverage = clip->hasCoverageFragmentProcessor()
Brian Salomonb4d61062017-07-12 11:24:41 -040092 ? GrProcessorAnalysisCoverage::kSingleChannel
93 : GrProcessorAnalysisCoverage::kNone;
94 }
Brian Osmancf860852018-10-31 14:04:39 -040095 SkPMColor4f overrideColor;
Chris Dalton57ab06c2021-04-22 12:57:28 -060096 analysis = fProcessors->finalize(*geometryColor, coverage, clip, userStencil, caps,
97 clampType, &overrideColor);
Brian Salomon0088f942017-07-12 11:51:27 -040098 if (analysis.inputColorIsOverridden()) {
99 *geometryColor = overrideColor;
100 }
Brian Salomonb4d61062017-07-12 11:24:41 -0400101 } else {
102 analysis = GrProcessorSet::EmptySetAnalysis();
103 }
Brian Salomonb4d61062017-07-12 11:24:41 -0400104 fUsesLocalCoords = analysis.usesLocalCoords();
Brian Osman605c6d52019-03-15 12:10:35 -0400105 fCompatibleWithCoverageAsAlpha = analysis.isCompatibleWithCoverageAsAlpha();
Chris Dalton4b62aed2019-01-15 11:53:00 -0700106 return analysis;
Brian Salomonb4d61062017-07-12 11:24:41 -0400107}
108
Robert Phillips3968fcb2019-12-05 16:40:31 -0500109const GrPipeline* GrSimpleMeshDrawOpHelper::CreatePipeline(
Robert Phillips6c59fe42020-02-27 09:30:37 -0500110 const GrCaps* caps,
111 SkArenaAlloc* arena,
Brian Salomon8afde5f2020-04-01 16:22:00 -0400112 GrSwizzle writeViewSwizzle,
Robert Phillips6c59fe42020-02-27 09:30:37 -0500113 GrAppliedClip&& appliedClip,
John Stiles52cb1d02021-06-02 11:58:05 -0400114 const GrDstProxyView& dstProxyView,
Robert Phillips6c59fe42020-02-27 09:30:37 -0500115 GrProcessorSet&& processorSet,
Chris Dalton1b6a43c2020-09-25 12:21:18 -0600116 GrPipeline::InputFlags pipelineFlags) {
Robert Phillips3968fcb2019-12-05 16:40:31 -0500117 GrPipeline::InitArgs pipelineArgs;
118
119 pipelineArgs.fInputFlags = pipelineFlags;
Robert Phillipsce978572020-02-28 11:56:44 -0500120 pipelineArgs.fCaps = caps;
121 pipelineArgs.fDstProxyView = dstProxyView;
Brian Salomon8afde5f2020-04-01 16:22:00 -0400122 pipelineArgs.fWriteSwizzle = writeViewSwizzle;
Robert Phillips3968fcb2019-12-05 16:40:31 -0500123
Robert Phillips6c59fe42020-02-27 09:30:37 -0500124 return arena->make<GrPipeline>(pipelineArgs,
125 std::move(processorSet),
126 std::move(appliedClip));
127}
128
129const GrPipeline* GrSimpleMeshDrawOpHelper::CreatePipeline(
130 GrOpFlushState* flushState,
131 GrProcessorSet&& processorSet,
Chris Dalton1b6a43c2020-09-25 12:21:18 -0600132 GrPipeline::InputFlags pipelineFlags) {
Robert Phillips6c59fe42020-02-27 09:30:37 -0500133 return CreatePipeline(&flushState->caps(),
134 flushState->allocator(),
Adlai Hollere2296f72020-11-19 13:41:26 -0500135 flushState->writeView().swizzle(),
Robert Phillips6c59fe42020-02-27 09:30:37 -0500136 flushState->detachAppliedClip(),
137 flushState->dstProxyView(),
138 std::move(processorSet),
Chris Dalton1b6a43c2020-09-25 12:21:18 -0600139 pipelineFlags);
Robert Phillips6c59fe42020-02-27 09:30:37 -0500140}
141
142const GrPipeline* GrSimpleMeshDrawOpHelper::createPipeline(GrOpFlushState* flushState) {
143 return CreatePipeline(&flushState->caps(),
144 flushState->allocator(),
Adlai Hollere2296f72020-11-19 13:41:26 -0500145 flushState->writeView().swizzle(),
Robert Phillips6c59fe42020-02-27 09:30:37 -0500146 flushState->detachAppliedClip(),
147 flushState->dstProxyView(),
148 this->detachProcessorSet(),
149 this->pipelineFlags());
Chris Dalton07cdcfc92019-02-26 11:13:22 -0700150}
151
Chris Dalton1b6a43c2020-09-25 12:21:18 -0600152const GrPipeline* GrSimpleMeshDrawOpHelper::createPipeline(
153 const GrCaps* caps,
154 SkArenaAlloc* arena,
155 GrSwizzle writeViewSwizzle,
156 GrAppliedClip&& appliedClip,
John Stiles52cb1d02021-06-02 11:58:05 -0400157 const GrDstProxyView& dstProxyView) {
Chris Dalton1b6a43c2020-09-25 12:21:18 -0600158 return GrSimpleMeshDrawOpHelper::CreatePipeline(caps,
159 arena,
160 writeViewSwizzle,
161 std::move(appliedClip),
162 dstProxyView,
163 this->detachProcessorSet(),
164 this->pipelineFlags());
165}
166
Robert Phillipsce978572020-02-28 11:56:44 -0500167GrProgramInfo* GrSimpleMeshDrawOpHelper::CreateProgramInfo(
168 const GrCaps* caps,
169 SkArenaAlloc* arena,
Adlai Hollere2296f72020-11-19 13:41:26 -0500170 const GrSurfaceProxyView& writeView,
Robert Phillipsce978572020-02-28 11:56:44 -0500171 GrAppliedClip&& appliedClip,
John Stiles52cb1d02021-06-02 11:58:05 -0400172 const GrDstProxyView& dstProxyView,
Robert Phillipsce978572020-02-28 11:56:44 -0500173 GrGeometryProcessor* geometryProcessor,
174 GrProcessorSet&& processorSet,
Robert Phillipsac6156c2020-02-28 16:02:40 -0500175 GrPrimitiveType primitiveType,
Greg Danield358cbe2020-09-11 09:33:54 -0400176 GrXferBarrierFlags renderPassXferBarriers,
Greg Daniel42dbca52020-11-20 10:22:43 -0500177 GrLoadOp colorLoadOp,
Robert Phillipsac6156c2020-02-28 16:02:40 -0500178 GrPipeline::InputFlags pipelineFlags,
Robert Phillips709e2402020-03-23 18:29:16 +0000179 const GrUserStencilSettings* stencilSettings) {
Robert Phillipsce978572020-02-28 11:56:44 -0500180 auto pipeline = CreatePipeline(caps,
181 arena,
Adlai Hollere2296f72020-11-19 13:41:26 -0500182 writeView.swizzle(),
Robert Phillipsce978572020-02-28 11:56:44 -0500183 std::move(appliedClip),
184 dstProxyView,
185 std::move(processorSet),
Chris Dalton1b6a43c2020-09-25 12:21:18 -0600186 pipelineFlags);
Robert Phillipsce978572020-02-28 11:56:44 -0500187
Greg Danield358cbe2020-09-11 09:33:54 -0400188 return CreateProgramInfo(arena, pipeline, writeView, geometryProcessor, primitiveType,
Greg Daniel42dbca52020-11-20 10:22:43 -0500189 renderPassXferBarriers, colorLoadOp, stencilSettings);
Robert Phillips4f93c572020-03-18 08:13:53 -0400190}
191
192GrProgramInfo* GrSimpleMeshDrawOpHelper::CreateProgramInfo(SkArenaAlloc* arena,
193 const GrPipeline* pipeline,
Adlai Hollere2296f72020-11-19 13:41:26 -0500194 const GrSurfaceProxyView& writeView,
Robert Phillips4f93c572020-03-18 08:13:53 -0400195 GrGeometryProcessor* geometryProcessor,
Greg Danield358cbe2020-09-11 09:33:54 -0400196 GrPrimitiveType primitiveType,
Chris Dalton1b6a43c2020-09-25 12:21:18 -0600197 GrXferBarrierFlags xferBarrierFlags,
Greg Daniel42dbca52020-11-20 10:22:43 -0500198 GrLoadOp colorLoadOp,
Chris Dalton1b6a43c2020-09-25 12:21:18 -0600199 const GrUserStencilSettings* stencilSettings) {
Robert Phillips5c809642020-11-20 12:28:45 -0500200 auto tmp = arena->make<GrProgramInfo>(writeView,
Robert Phillipsce978572020-02-28 11:56:44 -0500201 pipeline,
Chris Dalton1b6a43c2020-09-25 12:21:18 -0600202 stencilSettings,
Robert Phillipsce978572020-02-28 11:56:44 -0500203 geometryProcessor,
Greg Danield358cbe2020-09-11 09:33:54 -0400204 primitiveType,
205 0,
Greg Daniel42dbca52020-11-20 10:22:43 -0500206 xferBarrierFlags,
207 colorLoadOp);
Robert Phillipsce978572020-02-28 11:56:44 -0500208 return tmp;
209}
210
Robert Phillipsb58098f2020-03-02 16:25:29 -0500211GrProgramInfo* GrSimpleMeshDrawOpHelper::createProgramInfo(
212 const GrCaps* caps,
213 SkArenaAlloc* arena,
Adlai Hollere2296f72020-11-19 13:41:26 -0500214 const GrSurfaceProxyView& writeView,
Robert Phillipsb58098f2020-03-02 16:25:29 -0500215 GrAppliedClip&& appliedClip,
John Stiles52cb1d02021-06-02 11:58:05 -0400216 const GrDstProxyView& dstProxyView,
Robert Phillipsb58098f2020-03-02 16:25:29 -0500217 GrGeometryProcessor* gp,
Greg Danield358cbe2020-09-11 09:33:54 -0400218 GrPrimitiveType primType,
Greg Daniel42dbca52020-11-20 10:22:43 -0500219 GrXferBarrierFlags renderPassXferBarriers,
220 GrLoadOp colorLoadOp) {
Robert Phillipsb58098f2020-03-02 16:25:29 -0500221 return CreateProgramInfo(caps,
222 arena,
Brian Salomon8afde5f2020-04-01 16:22:00 -0400223 writeView,
Robert Phillipsb58098f2020-03-02 16:25:29 -0500224 std::move(appliedClip),
225 dstProxyView,
226 gp,
227 this->detachProcessorSet(),
228 primType,
Greg Danield358cbe2020-09-11 09:33:54 -0400229 renderPassXferBarriers,
Greg Daniel42dbca52020-11-20 10:22:43 -0500230 colorLoadOp,
Robert Phillipsb58098f2020-03-02 16:25:29 -0500231 this->pipelineFlags());
232}
233
John Stiles8d9bf642020-08-12 15:07:45 -0400234#if GR_TEST_UTILS
Chris Daltonbaa1b352019-04-03 12:03:00 -0600235static void dump_pipeline_flags(GrPipeline::InputFlags flags, SkString* result) {
236 if (GrPipeline::InputFlags::kNone != flags) {
237 if (flags & GrPipeline::InputFlags::kSnapVerticesToPixelCenters) {
238 result->append("Snap vertices to pixel center.\n");
239 }
240 if (flags & GrPipeline::InputFlags::kHWAntialias) {
241 result->append("HW Antialiasing enabled.\n");
242 }
Chris Dalton1b6a43c2020-09-25 12:21:18 -0600243 if (flags & GrPipeline::InputFlags::kWireframe) {
244 result->append("Wireframe enabled.\n");
245 }
246 if (flags & GrPipeline::InputFlags::kConservativeRaster) {
247 result->append("Conservative raster enabled.\n");
248 }
Chris Daltonbaa1b352019-04-03 12:03:00 -0600249 return;
250 }
251 result->append("No pipeline flags\n");
252}
253
Brian Salomonb4d61062017-07-12 11:24:41 -0400254SkString GrSimpleMeshDrawOpHelper::dumpInfo() const {
Brian Salomon91326c32017-08-09 16:02:19 -0400255 const GrProcessorSet& processors = fProcessors ? *fProcessors : GrProcessorSet::EmptySet();
256 SkString result = processors.dumpProcessors();
Brian Salomonb4d61062017-07-12 11:24:41 -0400257 result.append("AA Type: ");
258 switch (this->aaType()) {
259 case GrAAType::kNone:
260 result.append(" none\n");
261 break;
262 case GrAAType::kCoverage:
263 result.append(" coverage\n");
264 break;
265 case GrAAType::kMSAA:
266 result.append(" msaa\n");
267 break;
Brian Salomonb4d61062017-07-12 11:24:41 -0400268 }
Chris Daltonbaa1b352019-04-03 12:03:00 -0600269 dump_pipeline_flags(fPipelineFlags, &result);
Brian Salomonb4d61062017-07-12 11:24:41 -0400270 return result;
271}
Brian Osman9a390ac2018-11-12 09:47:48 -0500272#endif