egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 1 | /* |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 2 | * Copyright 2015 Google Inc. |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 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 Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/gpu/GrPipeline.h" |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "src/gpu/GrAppliedClip.h" |
| 11 | #include "src/gpu/GrCaps.h" |
| 12 | #include "src/gpu/GrGpu.h" |
| 13 | #include "src/gpu/GrRenderTargetContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "src/gpu/GrXferProcessor.h" |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 15 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 16 | #include "src/gpu/ops/GrOp.h" |
joshualitt | 7441782 | 2015-08-07 11:42:16 -0700 | [diff] [blame] | 17 | |
Brian Salomon | 982f546 | 2020-03-30 12:52:33 -0400 | [diff] [blame] | 18 | GrPipeline::GrPipeline(const InitArgs& args, |
| 19 | sk_sp<const GrXferProcessor> xferProcessor, |
Chris Dalton | b832ce6 | 2020-01-06 19:49:37 -0700 | [diff] [blame] | 20 | const GrAppliedHardClip& hardClip) |
Brian Salomon | 982f546 | 2020-03-30 12:52:33 -0400 | [diff] [blame] | 21 | : fWriteSwizzle(args.fWriteSwizzle) { |
Chris Dalton | baa1b35 | 2019-04-03 12:03:00 -0600 | [diff] [blame] | 22 | fFlags = (Flags)args.fInputFlags; |
Chris Dalton | b832ce6 | 2020-01-06 19:49:37 -0700 | [diff] [blame] | 23 | if (hardClip.hasStencilClip()) { |
Chris Dalton | baa1b35 | 2019-04-03 12:03:00 -0600 | [diff] [blame] | 24 | fFlags |= Flags::kHasStencilClip; |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 25 | } |
Chris Dalton | b832ce6 | 2020-01-06 19:49:37 -0700 | [diff] [blame] | 26 | if (hardClip.scissorState().enabled()) { |
Chris Dalton | 2e7ed26 | 2020-02-21 15:17:59 -0700 | [diff] [blame] | 27 | fFlags |= Flags::kScissorTestEnabled; |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 28 | } |
| 29 | |
Chris Dalton | b832ce6 | 2020-01-06 19:49:37 -0700 | [diff] [blame] | 30 | fWindowRectsState = hardClip.windowRectsState(); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 31 | |
Chris Dalton | b832ce6 | 2020-01-06 19:49:37 -0700 | [diff] [blame] | 32 | fXferProcessor = std::move(xferProcessor); |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 33 | |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 34 | SkASSERT((args.fDstProxyView.dstSampleType() != GrDstSampleType::kNone) == |
| 35 | SkToBool(args.fDstProxyView.proxy())); |
Greg Daniel | 524e28b | 2019-11-01 11:48:53 -0400 | [diff] [blame] | 36 | if (args.fDstProxyView.proxy()) { |
Greg Daniel | 524e28b | 2019-11-01 11:48:53 -0400 | [diff] [blame] | 37 | fDstProxyView = args.fDstProxyView.proxyView(); |
| 38 | fDstTextureOffset = args.fDstProxyView.offset(); |
Brian Salomon | 18dfa98 | 2017-04-03 16:57:43 -0400 | [diff] [blame] | 39 | } |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 40 | fDstSampleType = args.fDstProxyView.dstSampleType(); |
Chris Dalton | b832ce6 | 2020-01-06 19:49:37 -0700 | [diff] [blame] | 41 | } |
Brian Salomon | 3185384 | 2017-03-28 16:32:05 -0400 | [diff] [blame] | 42 | |
Chris Dalton | b832ce6 | 2020-01-06 19:49:37 -0700 | [diff] [blame] | 43 | GrPipeline::GrPipeline(const InitArgs& args, GrProcessorSet&& processors, |
| 44 | GrAppliedClip&& appliedClip) |
| 45 | : GrPipeline(args, processors.refXferProcessor(), appliedClip.hardClip()) { |
| 46 | SkASSERT(processors.isFinalized()); |
Brian Salomon | e5b399e | 2017-07-19 13:50:54 -0400 | [diff] [blame] | 47 | // Copy GrFragmentProcessors from GrProcessorSet to Pipeline |
John Stiles | 29d3e22 | 2020-07-21 17:28:12 -0400 | [diff] [blame] | 48 | fNumColorProcessors = processors.hasColorFragmentProcessor() ? 1 : 0; |
Chris Dalton | 6982400 | 2017-10-31 00:37:52 -0600 | [diff] [blame] | 49 | int numTotalProcessors = fNumColorProcessors + |
John Stiles | 29d3e22 | 2020-07-21 17:28:12 -0400 | [diff] [blame] | 50 | (processors.hasCoverageFragmentProcessor() ? 1 : 0) + |
John Stiles | 59e18dc | 2020-07-22 18:18:12 -0400 | [diff] [blame] | 51 | (appliedClip.hasCoverageFragmentProcessor() ? 1 : 0); |
Brian Salomon | b5cb683 | 2017-02-24 11:01:15 -0500 | [diff] [blame] | 52 | fFragmentProcessors.reset(numTotalProcessors); |
Robert Phillips | 82774f8 | 2019-06-20 14:38:27 -0400 | [diff] [blame] | 53 | |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 54 | int currFPIdx = 0; |
John Stiles | 29d3e22 | 2020-07-21 17:28:12 -0400 | [diff] [blame] | 55 | if (processors.hasColorFragmentProcessor()) { |
| 56 | fFragmentProcessors[currFPIdx++] = processors.detachColorFragmentProcessor(); |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 57 | } |
John Stiles | 29d3e22 | 2020-07-21 17:28:12 -0400 | [diff] [blame] | 58 | if (processors.hasCoverageFragmentProcessor()) { |
| 59 | fFragmentProcessors[currFPIdx++] = processors.detachCoverageFragmentProcessor(); |
egdaniel | 9cf45bf | 2014-10-08 06:49:10 -0700 | [diff] [blame] | 60 | } |
John Stiles | 59e18dc | 2020-07-22 18:18:12 -0400 | [diff] [blame] | 61 | if (appliedClip.hasCoverageFragmentProcessor()) { |
| 62 | fFragmentProcessors[currFPIdx++] = appliedClip.detachCoverageFragmentProcessor(); |
Robert Phillips | 82774f8 | 2019-06-20 14:38:27 -0400 | [diff] [blame] | 63 | } |
egdaniel | c064824 | 2014-09-22 13:17:02 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 66 | GrXferBarrierType GrPipeline::xferBarrierType(const GrCaps& caps) const { |
| 67 | if (fDstProxyView.proxy() && GrDstSampleTypeDirectlySamplesDst(fDstSampleType)) { |
Robert Phillips | c9c06d4 | 2017-06-12 10:58:31 -0400 | [diff] [blame] | 68 | return kTexture_GrXferBarrierType; |
| 69 | } |
| 70 | return this->getXferProcessor().xferBarrierType(caps); |
| 71 | } |
| 72 | |
Brian Salomon | 982f546 | 2020-03-30 12:52:33 -0400 | [diff] [blame] | 73 | GrPipeline::GrPipeline(GrScissorTest scissorTest, |
| 74 | sk_sp<const GrXferProcessor> xp, |
| 75 | const GrSwizzle& writeSwizzle, |
Chris Dalton | 1b6a43c | 2020-09-25 12:21:18 -0600 | [diff] [blame^] | 76 | InputFlags inputFlags) |
Robert Phillips | d0fe875 | 2019-01-31 14:13:59 -0500 | [diff] [blame] | 77 | : fWindowRectsState() |
Chris Dalton | baa1b35 | 2019-04-03 12:03:00 -0600 | [diff] [blame] | 78 | , fFlags((Flags)inputFlags) |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 79 | , fXferProcessor(std::move(xp)) |
Brian Salomon | 982f546 | 2020-03-30 12:52:33 -0400 | [diff] [blame] | 80 | , fWriteSwizzle(writeSwizzle) { |
Chris Dalton | 916c498 | 2018-08-15 00:53:25 -0600 | [diff] [blame] | 81 | if (GrScissorTest::kEnabled == scissorTest) { |
Chris Dalton | 2e7ed26 | 2020-02-21 15:17:59 -0700 | [diff] [blame] | 82 | fFlags |= Flags::kScissorTestEnabled; |
Chris Dalton | 46983b7 | 2017-06-06 12:27:16 -0600 | [diff] [blame] | 83 | } |
| 84 | } |
Jim Van Verth | 1223e7f | 2019-02-28 17:38:35 -0500 | [diff] [blame] | 85 | |
Chris Dalton | b204e4c | 2019-11-07 12:43:13 -0700 | [diff] [blame] | 86 | void 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 Stiles | 29d3e22 | 2020-07-21 17:28:12 -0400 | [diff] [blame] | 90 | // Ganesh will omit kHWAntialias regardless of multisampleDisableSupport. |
Chris Dalton | b204e4c | 2019-11-07 12:43:13 -0700 | [diff] [blame] | 91 | ignoredFlags |= InputFlags::kHWAntialias; |
| 92 | } |
| 93 | b->add32((uint32_t)fFlags & ~(uint32_t)ignoredFlags); |
| 94 | |
Chris Dalton | bbb3f64 | 2019-07-24 12:25:08 -0400 | [diff] [blame] | 95 | const GrXferProcessor::BlendInfo& blendInfo = this->getXferProcessor().getBlendInfo(); |
Jim Van Verth | 1223e7f | 2019-02-28 17:38:35 -0500 | [diff] [blame] | 96 | |
John Stiles | 29d3e22 | 2020-07-21 17:28:12 -0400 | [diff] [blame] | 97 | static constexpr uint32_t kBlendWriteShift = 1; |
| 98 | static constexpr uint32_t kBlendCoeffShift = 5; |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 99 | static constexpr uint32_t kBlendEquationShift = 5; |
| 100 | static constexpr uint32_t kDstSampleTypeInputShift = 1; |
Brian Salomon | 4dea72a | 2019-12-18 10:43:10 -0500 | [diff] [blame] | 101 | static_assert(kLast_GrBlendCoeff < (1 << kBlendCoeffShift)); |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 102 | static_assert(kLast_GrBlendEquation < (1 << kBlendEquationShift)); |
| 103 | static_assert(kBlendWriteShift + |
| 104 | 2 * kBlendCoeffShift + |
| 105 | kBlendEquationShift + |
| 106 | kDstSampleTypeInputShift <= 32); |
Jim Van Verth | 1223e7f | 2019-02-28 17:38:35 -0500 | [diff] [blame] | 107 | |
Chris Dalton | b204e4c | 2019-11-07 12:43:13 -0700 | [diff] [blame] | 108 | uint32_t blendKey = blendInfo.fWriteColor; |
| 109 | blendKey |= (blendInfo.fSrcBlend << kBlendWriteShift); |
| 110 | blendKey |= (blendInfo.fDstBlend << (kBlendWriteShift + kBlendCoeffShift)); |
| 111 | blendKey |= (blendInfo.fEquation << (kBlendWriteShift + 2 * kBlendCoeffShift)); |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 112 | // Note that we use the general fDstSampleType here and not localDstSampleType() |
| 113 | blendKey |= ((fDstSampleType == GrDstSampleType::kAsInputAttachment) |
| 114 | << (kBlendWriteShift + 2 * kBlendCoeffShift + kBlendEquationShift)); |
Jim Van Verth | 1223e7f | 2019-02-28 17:38:35 -0500 | [diff] [blame] | 115 | |
Chris Dalton | b204e4c | 2019-11-07 12:43:13 -0700 | [diff] [blame] | 116 | b->add32(blendKey); |
Jim Van Verth | 1223e7f | 2019-02-28 17:38:35 -0500 | [diff] [blame] | 117 | } |
Brian Salomon | c241b58 | 2019-11-27 08:57:17 -0500 | [diff] [blame] | 118 | |
Brian Salomon | d90b3d3 | 2020-07-09 12:04:31 -0400 | [diff] [blame] | 119 | void GrPipeline::visitTextureEffects( |
| 120 | const std::function<void(const GrTextureEffect&)>& func) const { |
| 121 | for (auto& fp : fFragmentProcessors) { |
| 122 | fp->visitTextureEffects(func); |
| 123 | } |
| 124 | } |
| 125 | |
Brian Salomon | c241b58 | 2019-11-27 08:57:17 -0500 | [diff] [blame] | 126 | void GrPipeline::visitProxies(const GrOp::VisitProxyFunc& func) const { |
| 127 | // This iteration includes any clip coverage FPs |
Brian Salomon | d90b3d3 | 2020-07-09 12:04:31 -0400 | [diff] [blame] | 128 | for (auto& fp : fFragmentProcessors) { |
| 129 | fp->visitProxies(func); |
Brian Salomon | c241b58 | 2019-11-27 08:57:17 -0500 | [diff] [blame] | 130 | } |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 131 | if (this->usesDstTexture()) { |
| 132 | func(fDstProxyView.proxy(), GrMipmapped::kNo); |
Brian Salomon | c241b58 | 2019-11-27 08:57:17 -0500 | [diff] [blame] | 133 | } |
| 134 | } |