1 /*
2 * Copyright 2021 Google LLC.
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
8 #include "src/gpu/ganesh/ops/PathTessellateOp.h"
9
10 #include "src/gpu/ganesh/GrAppliedClip.h"
11 #include "src/gpu/ganesh/GrCaps.h"
12 #include "src/gpu/ganesh/GrOpFlushState.h"
13 #include "src/gpu/ganesh/GrRecordingContextPriv.h"
14 #include "src/gpu/ganesh/tessellate/GrPathTessellationShader.h"
15
16 namespace skgpu::v1 {
17
visitProxies(const GrVisitProxyFunc & func) const18 void PathTessellateOp::visitProxies(const GrVisitProxyFunc& func) const {
19 if (fTessellationProgram) {
20 fTessellationProgram->pipeline().visitProxies(func);
21 } else {
22 fProcessors.visitProxies(func);
23 }
24 }
25
finalize(const GrCaps & caps,const GrAppliedClip * clip,GrClampType clampType)26 GrProcessorSet::Analysis PathTessellateOp::finalize(const GrCaps& caps,
27 const GrAppliedClip* clip,
28 GrClampType clampType) {
29 auto analysis = fProcessors.finalize(this->headDraw().fColor,
30 GrProcessorAnalysisCoverage::kNone,
31 clip,
32 nullptr,
33 caps,
34 clampType,
35 &this->headDraw().fColor);
36 if (!analysis.usesLocalCoords()) {
37 // Since we don't need local coords, we can transform on CPU instead of in the shader. This
38 // gives us better batching potential.
39 this->headDraw().fPathMatrix = fShaderMatrix;
40 fShaderMatrix = SkMatrix::I();
41 }
42 return analysis;
43 }
44
onCombineIfPossible(GrOp * grOp,SkArenaAlloc *,const GrCaps &)45 GrDrawOp::CombineResult PathTessellateOp::onCombineIfPossible(GrOp* grOp,
46 SkArenaAlloc*,
47 const GrCaps&) {
48 auto* op = grOp->cast<PathTessellateOp>();
49 bool canMerge = fAAType == op->fAAType &&
50 fStencil == op->fStencil &&
51 fProcessors == op->fProcessors &&
52 fShaderMatrix == op->fShaderMatrix;
53 if (canMerge) {
54 fTotalCombinedPathVerbCnt += op->fTotalCombinedPathVerbCnt;
55 fPatchAttribs |= op->fPatchAttribs;
56
57 if (!(fPatchAttribs & PatchAttribs::kColor) &&
58 this->headDraw().fColor != op->headDraw().fColor) {
59 // Color is no longer uniform. Move it into patch attribs.
60 fPatchAttribs |= PatchAttribs::kColor;
61 }
62
63 *fPathDrawTail = op->fPathDrawList;
64 fPathDrawTail = op->fPathDrawTail;
65 return CombineResult::kMerged;
66 }
67
68 return CombineResult::kCannotCombine;
69 }
70
prepareTessellator(const GrTessellationShader::ProgramArgs & args,GrAppliedClip && appliedClip)71 void PathTessellateOp::prepareTessellator(const GrTessellationShader::ProgramArgs& args,
72 GrAppliedClip&& appliedClip) {
73 SkASSERT(!fTessellator);
74 SkASSERT(!fTessellationProgram);
75 auto* pipeline = GrTessellationShader::MakePipeline(args, fAAType, std::move(appliedClip),
76 std::move(fProcessors));
77 fTessellator = PathWedgeTessellator::Make(args.fArena,
78 args.fCaps->shaderCaps()->fInfinitySupport,
79 fPatchAttribs);
80 auto* tessShader = GrPathTessellationShader::Make(*args.fCaps->shaderCaps(),
81 args.fArena,
82 fShaderMatrix,
83 this->headDraw().fColor,
84 fTessellator->patchAttribs());
85 fTessellationProgram = GrTessellationShader::MakeProgram(args, tessShader, pipeline, fStencil);
86 }
87
onPrePrepare(GrRecordingContext * context,const GrSurfaceProxyView & writeView,GrAppliedClip * clip,const GrDstProxyView & dstProxyView,GrXferBarrierFlags renderPassXferBarriers,GrLoadOp colorLoadOp)88 void PathTessellateOp::onPrePrepare(GrRecordingContext* context,
89 const GrSurfaceProxyView& writeView, GrAppliedClip* clip,
90 const GrDstProxyView& dstProxyView,
91 GrXferBarrierFlags renderPassXferBarriers,
92 GrLoadOp colorLoadOp) {
93 // DMSAA is not supported on DDL.
94 bool usesMSAASurface = writeView.asRenderTargetProxy()->numSamples() > 1;
95 this->prepareTessellator({context->priv().recordTimeAllocator(), writeView, usesMSAASurface,
96 &dstProxyView, renderPassXferBarriers, colorLoadOp,
97 context->priv().caps()},
98 (clip) ? std::move(*clip) : GrAppliedClip::Disabled());
99 SkASSERT(fTessellationProgram);
100 context->priv().recordProgramInfo(fTessellationProgram);
101 }
102
onPrepare(GrOpFlushState * flushState)103 void PathTessellateOp::onPrepare(GrOpFlushState* flushState) {
104 if (!fTessellator) {
105 this->prepareTessellator({flushState->allocator(), flushState->writeView(),
106 flushState->usesMSAASurface(), &flushState->dstProxyView(),
107 flushState->renderPassBarriers(), flushState->colorLoadOp(),
108 &flushState->caps()}, flushState->detachAppliedClip());
109 SkASSERT(fTessellator);
110 }
111 fTessellator->prepare(flushState,
112 fShaderMatrix,
113 *fPathDrawList,
114 fTotalCombinedPathVerbCnt);
115 }
116
onExecute(GrOpFlushState * flushState,const SkRect & chainBounds)117 void PathTessellateOp::onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) {
118 SkASSERT(fTessellator);
119 SkASSERT(fTessellationProgram);
120 flushState->bindPipelineAndScissorClip(*fTessellationProgram, this->bounds());
121 flushState->bindTextures(fTessellationProgram->geomProc(), nullptr,
122 fTessellationProgram->pipeline());
123 fTessellator->draw(flushState);
124 }
125
126 } // namespace skgpu::v1
127