blob: 39e3f0680ffec3d0bc912c70f0927d434dc27fb6 [file] [log] [blame]
egdaniel3658f382014-09-15 07:01:59 -07001/*
egdaniel8dd688b2015-01-22 10:16:09 -08002 * Copyright 2015 Google Inc.
egdaniel3658f382014-09-15 07:01:59 -07003 *
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/GrPipeline.h"
egdaniel3658f382014-09-15 07:01:59 -07009
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "src/gpu/GrAppliedClip.h"
11#include "src/gpu/GrCaps.h"
12#include "src/gpu/GrGpu.h"
13#include "src/gpu/GrRenderTargetContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "src/gpu/GrXferProcessor.h"
egdaniel3658f382014-09-15 07:01:59 -070015
Mike Kleinc0bd9f92019-04-23 12:05:21 -050016#include "src/gpu/ops/GrOp.h"
joshualitt74417822015-08-07 11:42:16 -070017
Brian Salomon982f5462020-03-30 12:52:33 -040018GrPipeline::GrPipeline(const InitArgs& args,
19 sk_sp<const GrXferProcessor> xferProcessor,
Chris Daltonb832ce62020-01-06 19:49:37 -070020 const GrAppliedHardClip& hardClip)
Brian Salomon982f5462020-03-30 12:52:33 -040021 : fWriteSwizzle(args.fWriteSwizzle) {
Chris Daltonbaa1b352019-04-03 12:03:00 -060022 fFlags = (Flags)args.fInputFlags;
Chris Daltonb832ce62020-01-06 19:49:37 -070023 if (hardClip.hasStencilClip()) {
Chris Daltonbaa1b352019-04-03 12:03:00 -060024 fFlags |= Flags::kHasStencilClip;
Brian Salomon54d212e2017-03-21 14:22:38 -040025 }
Chris Daltonb832ce62020-01-06 19:49:37 -070026 if (hardClip.scissorState().enabled()) {
Chris Dalton2e7ed262020-02-21 15:17:59 -070027 fFlags |= Flags::kScissorTestEnabled;
Brian Salomon49348902018-06-26 09:12:38 -040028 }
29
Chris Daltonb832ce62020-01-06 19:49:37 -070030 fWindowRectsState = hardClip.windowRectsState();
Brian Salomon54d212e2017-03-21 14:22:38 -040031
Chris Daltonb832ce62020-01-06 19:49:37 -070032 fXferProcessor = std::move(xferProcessor);
Brian Salomon189098e72017-01-19 09:55:19 -050033
Greg Danield358cbe2020-09-11 09:33:54 -040034 SkASSERT((args.fDstProxyView.dstSampleType() != GrDstSampleType::kNone) ==
35 SkToBool(args.fDstProxyView.proxy()));
Greg Daniel524e28b2019-11-01 11:48:53 -040036 if (args.fDstProxyView.proxy()) {
Greg Daniel524e28b2019-11-01 11:48:53 -040037 fDstProxyView = args.fDstProxyView.proxyView();
38 fDstTextureOffset = args.fDstProxyView.offset();
Brian Salomon18dfa982017-04-03 16:57:43 -040039 }
Greg Danield358cbe2020-09-11 09:33:54 -040040 fDstSampleType = args.fDstProxyView.dstSampleType();
Chris Daltonb832ce62020-01-06 19:49:37 -070041}
Brian Salomon31853842017-03-28 16:32:05 -040042
Chris Daltonb832ce62020-01-06 19:49:37 -070043GrPipeline::GrPipeline(const InitArgs& args, GrProcessorSet&& processors,
44 GrAppliedClip&& appliedClip)
45 : GrPipeline(args, processors.refXferProcessor(), appliedClip.hardClip()) {
46 SkASSERT(processors.isFinalized());
Brian Salomone5b399e2017-07-19 13:50:54 -040047 // Copy GrFragmentProcessors from GrProcessorSet to Pipeline
John Stiles29d3e222020-07-21 17:28:12 -040048 fNumColorProcessors = processors.hasColorFragmentProcessor() ? 1 : 0;
Chris Dalton69824002017-10-31 00:37:52 -060049 int numTotalProcessors = fNumColorProcessors +
John Stiles29d3e222020-07-21 17:28:12 -040050 (processors.hasCoverageFragmentProcessor() ? 1 : 0) +
John Stiles59e18dc2020-07-22 18:18:12 -040051 (appliedClip.hasCoverageFragmentProcessor() ? 1 : 0);
Brian Salomonb5cb6832017-02-24 11:01:15 -050052 fFragmentProcessors.reset(numTotalProcessors);
Robert Phillips82774f82019-06-20 14:38:27 -040053
bsalomonac856c92015-08-27 06:30:17 -070054 int currFPIdx = 0;
John Stiles29d3e222020-07-21 17:28:12 -040055 if (processors.hasColorFragmentProcessor()) {
56 fFragmentProcessors[currFPIdx++] = processors.detachColorFragmentProcessor();
bsalomonae59b772014-11-19 08:23:49 -080057 }
John Stiles29d3e222020-07-21 17:28:12 -040058 if (processors.hasCoverageFragmentProcessor()) {
59 fFragmentProcessors[currFPIdx++] = processors.detachCoverageFragmentProcessor();
egdaniel9cf45bf2014-10-08 06:49:10 -070060 }
John Stiles59e18dc2020-07-22 18:18:12 -040061 if (appliedClip.hasCoverageFragmentProcessor()) {
62 fFragmentProcessors[currFPIdx++] = appliedClip.detachCoverageFragmentProcessor();
Robert Phillips82774f82019-06-20 14:38:27 -040063 }
egdanielc0648242014-09-22 13:17:02 -070064}
65
Greg Danield358cbe2020-09-11 09:33:54 -040066GrXferBarrierType GrPipeline::xferBarrierType(const GrCaps& caps) const {
67 if (fDstProxyView.proxy() && GrDstSampleTypeDirectlySamplesDst(fDstSampleType)) {
Robert Phillipsc9c06d42017-06-12 10:58:31 -040068 return kTexture_GrXferBarrierType;
69 }
70 return this->getXferProcessor().xferBarrierType(caps);
71}
72
Brian Salomon982f5462020-03-30 12:52:33 -040073GrPipeline::GrPipeline(GrScissorTest scissorTest,
74 sk_sp<const GrXferProcessor> xp,
75 const GrSwizzle& writeSwizzle,
Chris Dalton1b6a43c2020-09-25 12:21:18 -060076 InputFlags inputFlags)
Robert Phillipsd0fe8752019-01-31 14:13:59 -050077 : fWindowRectsState()
Chris Daltonbaa1b352019-04-03 12:03:00 -060078 , fFlags((Flags)inputFlags)
Chris Daltonc3318f02019-07-19 14:20:53 -060079 , fXferProcessor(std::move(xp))
Brian Salomon982f5462020-03-30 12:52:33 -040080 , fWriteSwizzle(writeSwizzle) {
Chris Dalton916c4982018-08-15 00:53:25 -060081 if (GrScissorTest::kEnabled == scissorTest) {
Chris Dalton2e7ed262020-02-21 15:17:59 -070082 fFlags |= Flags::kScissorTestEnabled;
Chris Dalton46983b72017-06-06 12:27:16 -060083 }
84}
Jim Van Verth1223e7f2019-02-28 17:38:35 -050085
Chris Daltonb204e4c2019-11-07 12:43:13 -070086void GrPipeline::genKey(GrProcessorKeyBuilder* b, const GrCaps& caps) const {
87 // kSnapVerticesToPixelCenters is implemented in a shader.
88 InputFlags ignoredFlags = InputFlags::kSnapVerticesToPixelCenters;
89 if (!caps.multisampleDisableSupport()) {
John Stiles29d3e222020-07-21 17:28:12 -040090 // Ganesh will omit kHWAntialias regardless of multisampleDisableSupport.
Chris Daltonb204e4c2019-11-07 12:43:13 -070091 ignoredFlags |= InputFlags::kHWAntialias;
92 }
93 b->add32((uint32_t)fFlags & ~(uint32_t)ignoredFlags);
94
Chris Daltonbbb3f642019-07-24 12:25:08 -040095 const GrXferProcessor::BlendInfo& blendInfo = this->getXferProcessor().getBlendInfo();
Jim Van Verth1223e7f2019-02-28 17:38:35 -050096
John Stiles29d3e222020-07-21 17:28:12 -040097 static constexpr uint32_t kBlendWriteShift = 1;
98 static constexpr uint32_t kBlendCoeffShift = 5;
Greg Danield358cbe2020-09-11 09:33:54 -040099 static constexpr uint32_t kBlendEquationShift = 5;
100 static constexpr uint32_t kDstSampleTypeInputShift = 1;
Brian Salomon4dea72a2019-12-18 10:43:10 -0500101 static_assert(kLast_GrBlendCoeff < (1 << kBlendCoeffShift));
Greg Danield358cbe2020-09-11 09:33:54 -0400102 static_assert(kLast_GrBlendEquation < (1 << kBlendEquationShift));
103 static_assert(kBlendWriteShift +
104 2 * kBlendCoeffShift +
105 kBlendEquationShift +
106 kDstSampleTypeInputShift <= 32);
Jim Van Verth1223e7f2019-02-28 17:38:35 -0500107
Chris Daltonb204e4c2019-11-07 12:43:13 -0700108 uint32_t blendKey = blendInfo.fWriteColor;
109 blendKey |= (blendInfo.fSrcBlend << kBlendWriteShift);
110 blendKey |= (blendInfo.fDstBlend << (kBlendWriteShift + kBlendCoeffShift));
111 blendKey |= (blendInfo.fEquation << (kBlendWriteShift + 2 * kBlendCoeffShift));
Greg Danield358cbe2020-09-11 09:33:54 -0400112 // Note that we use the general fDstSampleType here and not localDstSampleType()
113 blendKey |= ((fDstSampleType == GrDstSampleType::kAsInputAttachment)
114 << (kBlendWriteShift + 2 * kBlendCoeffShift + kBlendEquationShift));
Jim Van Verth1223e7f2019-02-28 17:38:35 -0500115
Chris Daltonb204e4c2019-11-07 12:43:13 -0700116 b->add32(blendKey);
Jim Van Verth1223e7f2019-02-28 17:38:35 -0500117}
Brian Salomonc241b582019-11-27 08:57:17 -0500118
Brian Salomond90b3d32020-07-09 12:04:31 -0400119void GrPipeline::visitTextureEffects(
120 const std::function<void(const GrTextureEffect&)>& func) const {
121 for (auto& fp : fFragmentProcessors) {
122 fp->visitTextureEffects(func);
123 }
124}
125
Brian Salomonc241b582019-11-27 08:57:17 -0500126void GrPipeline::visitProxies(const GrOp::VisitProxyFunc& func) const {
127 // This iteration includes any clip coverage FPs
Brian Salomond90b3d32020-07-09 12:04:31 -0400128 for (auto& fp : fFragmentProcessors) {
129 fp->visitProxies(func);
Brian Salomonc241b582019-11-27 08:57:17 -0500130 }
Greg Danield358cbe2020-09-11 09:33:54 -0400131 if (this->usesDstTexture()) {
132 func(fDstProxyView.proxy(), GrMipmapped::kNo);
Brian Salomonc241b582019-11-27 08:57:17 -0500133 }
134}