blob: 98f1487ec266f15e55c03abd77e389338ce9dd8a [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"
14#include "src/gpu/GrRenderTargetOpList.h"
15#include "src/gpu/GrXferProcessor.h"
egdaniel3658f382014-09-15 07:01:59 -070016
Mike Kleinc0bd9f92019-04-23 12:05:21 -050017#include "src/gpu/ops/GrOp.h"
joshualitt74417822015-08-07 11:42:16 -070018
Brian Salomon49348902018-06-26 09:12:38 -040019GrPipeline::GrPipeline(const InitArgs& args,
20 GrProcessorSet&& processors,
Greg Daniel2c3398d2019-06-19 11:58:01 -040021 GrAppliedClip&& appliedClip)
22 : fOutputSwizzle(args.fOutputSwizzle) {
Brian Salomon91326c32017-08-09 16:02:19 -040023 SkASSERT(processors.isFinalized());
Brian Salomon92aee3d2016-12-21 09:20:25 -050024
Chris Daltonbaa1b352019-04-03 12:03:00 -060025 fFlags = (Flags)args.fInputFlags;
Brian Salomonbfd18cd2017-08-09 16:27:09 -040026 if (appliedClip.hasStencilClip()) {
Chris Daltonbaa1b352019-04-03 12:03:00 -060027 fFlags |= Flags::kHasStencilClip;
Brian Salomon54d212e2017-03-21 14:22:38 -040028 }
Brian Salomond818ebf2018-07-02 14:08:49 +000029 if (appliedClip.scissorState().enabled()) {
Chris Daltonbaa1b352019-04-03 12:03:00 -060030 fFlags |= Flags::kScissorEnabled;
Brian Salomon49348902018-06-26 09:12:38 -040031 }
32
Brian Salomonbfd18cd2017-08-09 16:27:09 -040033 fWindowRectsState = appliedClip.windowRectsState();
Chris Daltonbaa1b352019-04-03 12:03:00 -060034 if (!args.fUserStencil->isDisabled(fFlags & Flags::kHasStencilClip)) {
35 fFlags |= Flags::kStencilEnabled;
Brian Salomon54d212e2017-03-21 14:22:38 -040036 }
37
38 fUserStencilSettings = args.fUserStencil;
39
Brian Salomon91326c32017-08-09 16:02:19 -040040 fXferProcessor = processors.refXferProcessor();
Brian Salomon189098e72017-01-19 09:55:19 -050041
Robert Phillipsbb581ce2017-05-29 15:05:15 -040042 if (args.fDstProxy.proxy()) {
Robert Phillips12c46292019-04-23 07:36:17 -040043 SkASSERT(args.fDstProxy.proxy()->isInstantiated());
Robert Phillipsbb581ce2017-05-29 15:05:15 -040044
45 fDstTextureProxy.reset(args.fDstProxy.proxy());
46 fDstTextureOffset = args.fDstProxy.offset();
Brian Salomon18dfa982017-04-03 16:57:43 -040047 }
Brian Salomon31853842017-03-28 16:32:05 -040048
Brian Salomone5b399e2017-07-19 13:50:54 -040049 // Copy GrFragmentProcessors from GrProcessorSet to Pipeline
Brian Salomon91326c32017-08-09 16:02:19 -040050 fNumColorProcessors = processors.numColorFragmentProcessors();
Chris Dalton69824002017-10-31 00:37:52 -060051 int numTotalProcessors = fNumColorProcessors +
52 processors.numCoverageFragmentProcessors() +
53 appliedClip.numClipCoverageFragmentProcessors();
Brian Salomonb5cb6832017-02-24 11:01:15 -050054 fFragmentProcessors.reset(numTotalProcessors);
Robert Phillips82774f82019-06-20 14:38:27 -040055
bsalomonac856c92015-08-27 06:30:17 -070056 int currFPIdx = 0;
Brian Salomon91326c32017-08-09 16:02:19 -040057 for (int i = 0; i < processors.numColorFragmentProcessors(); ++i, ++currFPIdx) {
Brian Salomonaff329b2017-08-11 09:40:37 -040058 fFragmentProcessors[currFPIdx] = processors.detachColorFragmentProcessor(i);
bsalomonae59b772014-11-19 08:23:49 -080059 }
Brian Salomon91326c32017-08-09 16:02:19 -040060 for (int i = 0; i < processors.numCoverageFragmentProcessors(); ++i, ++currFPIdx) {
Brian Salomonaff329b2017-08-11 09:40:37 -040061 fFragmentProcessors[currFPIdx] = processors.detachCoverageFragmentProcessor(i);
egdaniel9cf45bf2014-10-08 06:49:10 -070062 }
Chris Dalton69824002017-10-31 00:37:52 -060063 for (int i = 0; i < appliedClip.numClipCoverageFragmentProcessors(); ++i, ++currFPIdx) {
64 fFragmentProcessors[currFPIdx] = appliedClip.detachClipCoverageFragmentProcessor(i);
Robert Phillips82774f82019-06-20 14:38:27 -040065 }
66
67#ifdef SK_DEBUG
68 for (int i = 0; i < numTotalProcessors; ++i) {
69 if (!fFragmentProcessors[i]->isInstantiated()) {
Brian Salomonbfd18cd2017-08-09 16:27:09 -040070 this->markAsBad();
Robert Phillips82774f82019-06-20 14:38:27 -040071 break;
Brian Salomon54d212e2017-03-21 14:22:38 -040072 }
Brian Salomon652ecb52017-01-17 12:39:53 -050073 }
Robert Phillips82774f82019-06-20 14:38:27 -040074#endif
egdanielc0648242014-09-22 13:17:02 -070075}
76
Robert Phillipsd261e102017-06-23 12:37:20 -040077void GrPipeline::addDependenciesTo(GrOpList* opList, const GrCaps& caps) const {
robertphillips498d7ac2015-10-30 10:11:30 -070078 for (int i = 0; i < fFragmentProcessors.count(); ++i) {
Robert Phillipsd261e102017-06-23 12:37:20 -040079 GrFragmentProcessor::TextureAccessIter iter(fFragmentProcessors[i].get());
Brian Salomone782f842018-07-31 13:53:11 -040080 while (const GrFragmentProcessor::TextureSampler* sampler = iter.next()) {
Robert Phillipsd261e102017-06-23 12:37:20 -040081 opList->addDependency(sampler->proxy(), caps);
82 }
robertphillips498d7ac2015-10-30 10:11:30 -070083 }
84
Robert Phillipsbb581ce2017-05-29 15:05:15 -040085 if (fDstTextureProxy) {
Robert Phillipsd261e102017-06-23 12:37:20 -040086 opList->addDependency(fDstTextureProxy.get(), caps);
robertphillips498d7ac2015-10-30 10:11:30 -070087 }
Robert Phillipsd261e102017-06-23 12:37:20 -040088
robertphillips498d7ac2015-10-30 10:11:30 -070089}
90
Robert Phillipsd0fe8752019-01-31 14:13:59 -050091GrXferBarrierType GrPipeline::xferBarrierType(GrTexture* texture, const GrCaps& caps) const {
92 if (fDstTextureProxy.get() && fDstTextureProxy.get()->peekTexture() == texture) {
Robert Phillipsc9c06d42017-06-12 10:58:31 -040093 return kTexture_GrXferBarrierType;
94 }
95 return this->getXferProcessor().xferBarrierType(caps);
96}
97
Chris Daltonc3318f02019-07-19 14:20:53 -060098GrPipeline::GrPipeline(GrScissorTest scissorTest, sk_sp<const GrXferProcessor> xp,
Greg Daniel2c3398d2019-06-19 11:58:01 -040099 const GrSwizzle& outputSwizzle, InputFlags inputFlags,
Chris Daltond7291ba2019-03-07 14:17:03 -0700100 const GrUserStencilSettings* userStencil)
Robert Phillipsd0fe8752019-01-31 14:13:59 -0500101 : fWindowRectsState()
Chris Daltond7291ba2019-03-07 14:17:03 -0700102 , fUserStencilSettings(userStencil)
Chris Daltonbaa1b352019-04-03 12:03:00 -0600103 , fFlags((Flags)inputFlags)
Chris Daltonc3318f02019-07-19 14:20:53 -0600104 , fXferProcessor(std::move(xp))
Robert Phillips2890fbf2017-07-26 15:48:41 -0400105 , fFragmentProcessors()
Greg Daniel2c3398d2019-06-19 11:58:01 -0400106 , fNumColorProcessors(0)
107 , fOutputSwizzle(outputSwizzle) {
Chris Dalton916c4982018-08-15 00:53:25 -0600108 if (GrScissorTest::kEnabled == scissorTest) {
Chris Daltonbaa1b352019-04-03 12:03:00 -0600109 fFlags |= Flags::kScissorEnabled;
Chris Dalton46983b72017-06-06 12:27:16 -0600110 }
Chris Daltond7291ba2019-03-07 14:17:03 -0700111 if (!userStencil->isDisabled(false)) {
Chris Daltonbaa1b352019-04-03 12:03:00 -0600112 fFlags |= Flags::kStencilEnabled;
Chris Daltond7291ba2019-03-07 14:17:03 -0700113 }
Chris Dalton46983b72017-06-06 12:27:16 -0600114}
Jim Van Verth1223e7f2019-02-28 17:38:35 -0500115
116uint32_t GrPipeline::getBlendInfoKey() const {
Chris Daltonbbb3f642019-07-24 12:25:08 -0400117 const GrXferProcessor::BlendInfo& blendInfo = this->getXferProcessor().getBlendInfo();
Jim Van Verth1223e7f2019-02-28 17:38:35 -0500118
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}