blob: a6fb1b2123ffb374a01f38197bca4c57e78f3886 [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,
Robert Phillipsce978572020-02-28 11:56:44 -0500169 GrAppliedClip&& appliedClip,
John Stiles52cb1d02021-06-02 11:58:05 -0400170 const GrDstProxyView& dstProxyView,
Robert Phillipsce978572020-02-28 11:56:44 -0500171 GrGeometryProcessor* geometryProcessor,
172 GrProcessorSet&& processorSet,
Robert Phillipsac6156c2020-02-28 16:02:40 -0500173 GrPrimitiveType primitiveType,
Greg Danield358cbe2020-09-11 09:33:54 -0400174 GrXferBarrierFlags renderPassXferBarriers,
Greg Daniel42dbca52020-11-20 10:22:43 -0500175 GrLoadOp colorLoadOp,
Robert Phillipsac6156c2020-02-28 16:02:40 -0500176 GrPipeline::InputFlags pipelineFlags,
Robert Phillips709e2402020-03-23 18:29:16 +0000177 const GrUserStencilSettings* stencilSettings) {
Robert Phillipsce978572020-02-28 11:56:44 -0500178 auto pipeline = CreatePipeline(caps,
179 arena,
Adlai Hollere2296f72020-11-19 13:41:26 -0500180 writeView.swizzle(),
Robert Phillipsce978572020-02-28 11:56:44 -0500181 std::move(appliedClip),
182 dstProxyView,
183 std::move(processorSet),
Chris Dalton1b6a43c2020-09-25 12:21:18 -0600184 pipelineFlags);
Robert Phillipsce978572020-02-28 11:56:44 -0500185
Greg Danield358cbe2020-09-11 09:33:54 -0400186 return CreateProgramInfo(arena, pipeline, writeView, geometryProcessor, primitiveType,
Greg Daniel42dbca52020-11-20 10:22:43 -0500187 renderPassXferBarriers, colorLoadOp, stencilSettings);
Robert Phillips4f93c572020-03-18 08:13:53 -0400188}
189
190GrProgramInfo* GrSimpleMeshDrawOpHelper::CreateProgramInfo(SkArenaAlloc* arena,
191 const GrPipeline* pipeline,
Adlai Hollere2296f72020-11-19 13:41:26 -0500192 const GrSurfaceProxyView& writeView,
Robert Phillips4f93c572020-03-18 08:13:53 -0400193 GrGeometryProcessor* geometryProcessor,
Greg Danield358cbe2020-09-11 09:33:54 -0400194 GrPrimitiveType primitiveType,
Chris Dalton1b6a43c2020-09-25 12:21:18 -0600195 GrXferBarrierFlags xferBarrierFlags,
Greg Daniel42dbca52020-11-20 10:22:43 -0500196 GrLoadOp colorLoadOp,
Chris Dalton1b6a43c2020-09-25 12:21:18 -0600197 const GrUserStencilSettings* stencilSettings) {
Robert Phillips5c809642020-11-20 12:28:45 -0500198 auto tmp = arena->make<GrProgramInfo>(writeView,
Robert Phillipsce978572020-02-28 11:56:44 -0500199 pipeline,
Chris Dalton1b6a43c2020-09-25 12:21:18 -0600200 stencilSettings,
Robert Phillipsce978572020-02-28 11:56:44 -0500201 geometryProcessor,
Greg Danield358cbe2020-09-11 09:33:54 -0400202 primitiveType,
203 0,
Greg Daniel42dbca52020-11-20 10:22:43 -0500204 xferBarrierFlags,
205 colorLoadOp);
Robert Phillipsce978572020-02-28 11:56:44 -0500206 return tmp;
207}
208
Robert Phillipsb58098f2020-03-02 16:25:29 -0500209GrProgramInfo* GrSimpleMeshDrawOpHelper::createProgramInfo(
210 const GrCaps* caps,
211 SkArenaAlloc* arena,
Adlai Hollere2296f72020-11-19 13:41:26 -0500212 const GrSurfaceProxyView& writeView,
Robert Phillipsb58098f2020-03-02 16:25:29 -0500213 GrAppliedClip&& appliedClip,
John Stiles52cb1d02021-06-02 11:58:05 -0400214 const GrDstProxyView& dstProxyView,
Robert Phillipsb58098f2020-03-02 16:25:29 -0500215 GrGeometryProcessor* gp,
Greg Danield358cbe2020-09-11 09:33:54 -0400216 GrPrimitiveType primType,
Greg Daniel42dbca52020-11-20 10:22:43 -0500217 GrXferBarrierFlags renderPassXferBarriers,
218 GrLoadOp colorLoadOp) {
Robert Phillipsb58098f2020-03-02 16:25:29 -0500219 return CreateProgramInfo(caps,
220 arena,
Brian Salomon8afde5f2020-04-01 16:22:00 -0400221 writeView,
Robert Phillipsb58098f2020-03-02 16:25:29 -0500222 std::move(appliedClip),
223 dstProxyView,
224 gp,
225 this->detachProcessorSet(),
226 primType,
Greg Danield358cbe2020-09-11 09:33:54 -0400227 renderPassXferBarriers,
Greg Daniel42dbca52020-11-20 10:22:43 -0500228 colorLoadOp,
Robert Phillipsb58098f2020-03-02 16:25:29 -0500229 this->pipelineFlags());
230}
231
John Stiles8d9bf642020-08-12 15:07:45 -0400232#if GR_TEST_UTILS
Chris Daltonbaa1b352019-04-03 12:03:00 -0600233static void dump_pipeline_flags(GrPipeline::InputFlags flags, SkString* result) {
234 if (GrPipeline::InputFlags::kNone != flags) {
235 if (flags & GrPipeline::InputFlags::kSnapVerticesToPixelCenters) {
236 result->append("Snap vertices to pixel center.\n");
237 }
Chris Dalton1b6a43c2020-09-25 12:21:18 -0600238 if (flags & GrPipeline::InputFlags::kWireframe) {
239 result->append("Wireframe enabled.\n");
240 }
241 if (flags & GrPipeline::InputFlags::kConservativeRaster) {
242 result->append("Conservative raster enabled.\n");
243 }
Chris Daltonbaa1b352019-04-03 12:03:00 -0600244 return;
245 }
246 result->append("No pipeline flags\n");
247}
248
Brian Salomonb4d61062017-07-12 11:24:41 -0400249SkString GrSimpleMeshDrawOpHelper::dumpInfo() const {
Brian Salomon91326c32017-08-09 16:02:19 -0400250 const GrProcessorSet& processors = fProcessors ? *fProcessors : GrProcessorSet::EmptySet();
251 SkString result = processors.dumpProcessors();
Brian Salomonb4d61062017-07-12 11:24:41 -0400252 result.append("AA Type: ");
253 switch (this->aaType()) {
254 case GrAAType::kNone:
255 result.append(" none\n");
256 break;
257 case GrAAType::kCoverage:
258 result.append(" coverage\n");
259 break;
260 case GrAAType::kMSAA:
261 result.append(" msaa\n");
262 break;
Brian Salomonb4d61062017-07-12 11:24:41 -0400263 }
Chris Daltonbaa1b352019-04-03 12:03:00 -0600264 dump_pipeline_flags(fPipelineFlags, &result);
Brian Salomonb4d61062017-07-12 11:24:41 -0400265 return result;
266}
Brian Osman9a390ac2018-11-12 09:47:48 -0500267#endif