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" |
| 14 | #include "src/gpu/GrRenderTargetOpList.h" |
| 15 | #include "src/gpu/GrXferProcessor.h" |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 16 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 17 | #include "src/gpu/ops/GrOp.h" |
joshualitt | 7441782 | 2015-08-07 11:42:16 -0700 | [diff] [blame] | 18 | |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 19 | GrPipeline::GrPipeline(const InitArgs& args, |
| 20 | GrProcessorSet&& processors, |
Greg Daniel | 2c3398d | 2019-06-19 11:58:01 -0400 | [diff] [blame^] | 21 | GrAppliedClip&& appliedClip) |
| 22 | : fOutputSwizzle(args.fOutputSwizzle) { |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 23 | SkASSERT(processors.isFinalized()); |
Brian Salomon | 92aee3d | 2016-12-21 09:20:25 -0500 | [diff] [blame] | 24 | |
Chris Dalton | baa1b35 | 2019-04-03 12:03:00 -0600 | [diff] [blame] | 25 | fFlags = (Flags)args.fInputFlags; |
Brian Salomon | bfd18cd | 2017-08-09 16:27:09 -0400 | [diff] [blame] | 26 | if (appliedClip.hasStencilClip()) { |
Chris Dalton | baa1b35 | 2019-04-03 12:03:00 -0600 | [diff] [blame] | 27 | fFlags |= Flags::kHasStencilClip; |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 28 | } |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 29 | if (appliedClip.scissorState().enabled()) { |
Chris Dalton | baa1b35 | 2019-04-03 12:03:00 -0600 | [diff] [blame] | 30 | fFlags |= Flags::kScissorEnabled; |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 31 | } |
| 32 | |
Brian Salomon | bfd18cd | 2017-08-09 16:27:09 -0400 | [diff] [blame] | 33 | fWindowRectsState = appliedClip.windowRectsState(); |
Chris Dalton | baa1b35 | 2019-04-03 12:03:00 -0600 | [diff] [blame] | 34 | if (!args.fUserStencil->isDisabled(fFlags & Flags::kHasStencilClip)) { |
| 35 | fFlags |= Flags::kStencilEnabled; |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | fUserStencilSettings = args.fUserStencil; |
| 39 | |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 40 | fXferProcessor = processors.refXferProcessor(); |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 41 | |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 42 | if (args.fDstProxy.proxy()) { |
Robert Phillips | 12c4629 | 2019-04-23 07:36:17 -0400 | [diff] [blame] | 43 | SkASSERT(args.fDstProxy.proxy()->isInstantiated()); |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 44 | |
| 45 | fDstTextureProxy.reset(args.fDstProxy.proxy()); |
| 46 | fDstTextureOffset = args.fDstProxy.offset(); |
Brian Salomon | 18dfa98 | 2017-04-03 16:57:43 -0400 | [diff] [blame] | 47 | } |
Brian Salomon | 3185384 | 2017-03-28 16:32:05 -0400 | [diff] [blame] | 48 | |
Brian Salomon | e5b399e | 2017-07-19 13:50:54 -0400 | [diff] [blame] | 49 | // Copy GrFragmentProcessors from GrProcessorSet to Pipeline |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 50 | fNumColorProcessors = processors.numColorFragmentProcessors(); |
Chris Dalton | 6982400 | 2017-10-31 00:37:52 -0600 | [diff] [blame] | 51 | int numTotalProcessors = fNumColorProcessors + |
| 52 | processors.numCoverageFragmentProcessors() + |
| 53 | appliedClip.numClipCoverageFragmentProcessors(); |
Brian Salomon | b5cb683 | 2017-02-24 11:01:15 -0500 | [diff] [blame] | 54 | fFragmentProcessors.reset(numTotalProcessors); |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 55 | int currFPIdx = 0; |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 56 | for (int i = 0; i < processors.numColorFragmentProcessors(); ++i, ++currFPIdx) { |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 57 | fFragmentProcessors[currFPIdx] = processors.detachColorFragmentProcessor(i); |
| 58 | if (!fFragmentProcessors[currFPIdx]->instantiate(args.fResourceProvider)) { |
Robert Phillips | a91e0b7 | 2017-05-01 13:12:20 -0400 | [diff] [blame] | 59 | this->markAsBad(); |
| 60 | } |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 61 | } |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 62 | for (int i = 0; i < processors.numCoverageFragmentProcessors(); ++i, ++currFPIdx) { |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 63 | fFragmentProcessors[currFPIdx] = processors.detachCoverageFragmentProcessor(i); |
| 64 | if (!fFragmentProcessors[currFPIdx]->instantiate(args.fResourceProvider)) { |
Robert Phillips | a91e0b7 | 2017-05-01 13:12:20 -0400 | [diff] [blame] | 65 | this->markAsBad(); |
| 66 | } |
egdaniel | 9cf45bf | 2014-10-08 06:49:10 -0700 | [diff] [blame] | 67 | } |
Chris Dalton | 6982400 | 2017-10-31 00:37:52 -0600 | [diff] [blame] | 68 | for (int i = 0; i < appliedClip.numClipCoverageFragmentProcessors(); ++i, ++currFPIdx) { |
| 69 | fFragmentProcessors[currFPIdx] = appliedClip.detachClipCoverageFragmentProcessor(i); |
Brian Salomon | bfd18cd | 2017-08-09 16:27:09 -0400 | [diff] [blame] | 70 | if (!fFragmentProcessors[currFPIdx]->instantiate(args.fResourceProvider)) { |
| 71 | this->markAsBad(); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 72 | } |
Brian Salomon | 652ecb5 | 2017-01-17 12:39:53 -0500 | [diff] [blame] | 73 | } |
egdaniel | c064824 | 2014-09-22 13:17:02 -0700 | [diff] [blame] | 74 | } |
| 75 | |
Robert Phillips | d261e10 | 2017-06-23 12:37:20 -0400 | [diff] [blame] | 76 | void GrPipeline::addDependenciesTo(GrOpList* opList, const GrCaps& caps) const { |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 77 | for (int i = 0; i < fFragmentProcessors.count(); ++i) { |
Robert Phillips | d261e10 | 2017-06-23 12:37:20 -0400 | [diff] [blame] | 78 | GrFragmentProcessor::TextureAccessIter iter(fFragmentProcessors[i].get()); |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 79 | while (const GrFragmentProcessor::TextureSampler* sampler = iter.next()) { |
Robert Phillips | d261e10 | 2017-06-23 12:37:20 -0400 | [diff] [blame] | 80 | opList->addDependency(sampler->proxy(), caps); |
| 81 | } |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 84 | if (fDstTextureProxy) { |
Robert Phillips | d261e10 | 2017-06-23 12:37:20 -0400 | [diff] [blame] | 85 | opList->addDependency(fDstTextureProxy.get(), caps); |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 86 | } |
Robert Phillips | d261e10 | 2017-06-23 12:37:20 -0400 | [diff] [blame] | 87 | |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Robert Phillips | d0fe875 | 2019-01-31 14:13:59 -0500 | [diff] [blame] | 90 | GrXferBarrierType GrPipeline::xferBarrierType(GrTexture* texture, const GrCaps& caps) const { |
| 91 | if (fDstTextureProxy.get() && fDstTextureProxy.get()->peekTexture() == texture) { |
Robert Phillips | c9c06d4 | 2017-06-12 10:58:31 -0400 | [diff] [blame] | 92 | return kTexture_GrXferBarrierType; |
| 93 | } |
| 94 | return this->getXferProcessor().xferBarrierType(caps); |
| 95 | } |
| 96 | |
Greg Daniel | 2c3398d | 2019-06-19 11:58:01 -0400 | [diff] [blame^] | 97 | GrPipeline::GrPipeline(GrScissorTest scissorTest, SkBlendMode blendmode, |
| 98 | const GrSwizzle& outputSwizzle, InputFlags inputFlags, |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 99 | const GrUserStencilSettings* userStencil) |
Robert Phillips | d0fe875 | 2019-01-31 14:13:59 -0500 | [diff] [blame] | 100 | : fWindowRectsState() |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 101 | , fUserStencilSettings(userStencil) |
Chris Dalton | baa1b35 | 2019-04-03 12:03:00 -0600 | [diff] [blame] | 102 | , fFlags((Flags)inputFlags) |
Robert Phillips | 2890fbf | 2017-07-26 15:48:41 -0400 | [diff] [blame] | 103 | , fXferProcessor(GrPorterDuffXPFactory::MakeNoCoverageXP(blendmode)) |
| 104 | , fFragmentProcessors() |
Greg Daniel | 2c3398d | 2019-06-19 11:58:01 -0400 | [diff] [blame^] | 105 | , fNumColorProcessors(0) |
| 106 | , fOutputSwizzle(outputSwizzle) { |
Chris Dalton | 916c498 | 2018-08-15 00:53:25 -0600 | [diff] [blame] | 107 | if (GrScissorTest::kEnabled == scissorTest) { |
Chris Dalton | baa1b35 | 2019-04-03 12:03:00 -0600 | [diff] [blame] | 108 | fFlags |= Flags::kScissorEnabled; |
Chris Dalton | 46983b7 | 2017-06-06 12:27:16 -0600 | [diff] [blame] | 109 | } |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 110 | if (!userStencil->isDisabled(false)) { |
Chris Dalton | baa1b35 | 2019-04-03 12:03:00 -0600 | [diff] [blame] | 111 | fFlags |= Flags::kStencilEnabled; |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 112 | } |
Chris Dalton | 46983b7 | 2017-06-06 12:27:16 -0600 | [diff] [blame] | 113 | } |
Jim Van Verth | 1223e7f | 2019-02-28 17:38:35 -0500 | [diff] [blame] | 114 | |
| 115 | uint32_t GrPipeline::getBlendInfoKey() const { |
| 116 | GrXferProcessor::BlendInfo blendInfo; |
| 117 | this->getXferProcessor().getBlendInfo(&blendInfo); |
| 118 | |
| 119 | static const uint32_t kBlendWriteShift = 1; |
| 120 | static const uint32_t kBlendCoeffShift = 5; |
| 121 | GR_STATIC_ASSERT(kLast_GrBlendCoeff < (1 << kBlendCoeffShift)); |
| 122 | GR_STATIC_ASSERT(kFirstAdvancedGrBlendEquation - 1 < 4); |
| 123 | |
| 124 | uint32_t key = blendInfo.fWriteColor; |
| 125 | key |= (blendInfo.fSrcBlend << kBlendWriteShift); |
| 126 | key |= (blendInfo.fDstBlend << (kBlendWriteShift + kBlendCoeffShift)); |
| 127 | key |= (blendInfo.fEquation << (kBlendWriteShift + 2 * kBlendCoeffShift)); |
| 128 | |
| 129 | return key; |
| 130 | } |