blob: 759f97ce2c59e0c1687a556ce51af7a266e9ffd8 [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
egdaniel8dd688b2015-01-22 10:16:09 -08008#include "GrPipeline.h"
egdaniel3658f382014-09-15 07:01:59 -07009
Brian Salomon652ecb52017-01-17 12:39:53 -050010#include "GrAppliedClip.h"
bsalomoneb1cb5c2015-05-22 08:01:09 -070011#include "GrCaps.h"
joshualitt4973d9d2014-11-08 09:24:25 -080012#include "GrGpu.h"
egdaniel8dd688b2015-01-22 10:16:09 -080013#include "GrPipelineBuilder.h"
Brian Salomon652ecb52017-01-17 12:39:53 -050014#include "GrRenderTargetContext.h"
Robert Phillipsf2361d22016-10-25 14:20:06 -040015#include "GrRenderTargetOpList.h"
cdalton193d9cf2016-05-12 11:52:02 -070016#include "GrRenderTargetPriv.h"
egdaniel95131432014-12-09 11:15:43 -080017#include "GrXferProcessor.h"
egdaniel3658f382014-09-15 07:01:59 -070018
Brian Salomon89527432016-12-16 09:52:16 -050019#include "ops/GrOp.h"
joshualitt74417822015-08-07 11:42:16 -070020
Brian Salomone7d30482017-03-29 12:09:15 -040021void GrPipeline::init(const InitArgs& args) {
Brian Salomonb16e8ac2017-02-22 11:52:36 -050022 SkASSERT(args.fRenderTarget);
Brian Salomon92aee3d2016-12-21 09:20:25 -050023
Brian Salomonb5cb6832017-02-24 11:01:15 -050024 fRenderTarget.reset(args.fRenderTarget);
cdalton93a379b2016-05-11 13:58:08 -070025
Brian Salomonb5cb6832017-02-24 11:01:15 -050026 fFlags = args.fFlags;
Brian Salomon54d212e2017-03-21 14:22:38 -040027 if (args.fAppliedClip) {
28 fScissorState = args.fAppliedClip->scissorState();
29 if (args.fAppliedClip->hasStencilClip()) {
30 fFlags |= kHasStencilClip_Flag;
31 }
32 fWindowRectsState = args.fAppliedClip->windowRectsState();
33 }
Brian Salomon189098e72017-01-19 09:55:19 -050034 if (args.fProcessors->usesDistanceVectorField()) {
Brian Salomonb5cb6832017-02-24 11:01:15 -050035 fFlags |= kUsesDistanceVectorField_Flag;
dvonbeck9b03e7b2016-08-01 11:01:56 -070036 }
Brian Salomonf87e2b92017-01-19 11:31:50 -050037 if (args.fProcessors->disableOutputConversionToSRGB()) {
Brian Salomonb5cb6832017-02-24 11:01:15 -050038 fFlags |= kDisableOutputConversionToSRGB_Flag;
Brian Salomonf87e2b92017-01-19 11:31:50 -050039 }
40 if (args.fProcessors->allowSRGBInputs()) {
Brian Salomonb5cb6832017-02-24 11:01:15 -050041 fFlags |= kAllowSRGBInputs_Flag;
Brian Salomonf87e2b92017-01-19 11:31:50 -050042 }
Brian Salomon54d212e2017-03-21 14:22:38 -040043 if (!args.fUserStencil->isDisabled(fFlags & kHasStencilClip_Flag)) {
44 fFlags |= kStencilEnabled_Flag;
45 }
46
47 fUserStencilSettings = args.fUserStencil;
48
49 fDrawFace = static_cast<int16_t>(args.fDrawFace);
cdalton93a379b2016-05-11 13:58:08 -070050
Brian Salomon5dac9b32017-04-08 02:53:30 +000051 bool isHWAA = kHWAntialias_Flag & args.fFlags;
Brian Salomon189098e72017-01-19 09:55:19 -050052
Brian Salomon5dac9b32017-04-08 02:53:30 +000053 // Create XferProcessor from DS's XPFactory
54 {
55 bool hasMixedSamples =
56 args.fRenderTarget->isMixedSampled() && (isHWAA || this->isStencilEnabled());
57 sk_sp<GrXferProcessor> xferProcessor =
58 GrXPFactory::MakeXferProcessor(args.fProcessors->xpFactory(), args.fXPInputColor,
59 args.fXPInputCoverage, hasMixedSamples, *args.fCaps);
60 fXferProcessor.reset(xferProcessor.get());
61 }
Brian Salomon18dfa982017-04-03 16:57:43 -040062 if (args.fDstTexture.texture()) {
63 fDstTexture.reset(args.fDstTexture.texture());
64 fDstTextureOffset = args.fDstTexture.offset();
65 }
Brian Salomon31853842017-03-28 16:32:05 -040066
Brian Salomoneec6f7b2017-02-10 14:29:38 -050067 // Copy GrFragmentProcessors from GrPipelineBuilder to Pipeline, possibly removing some of the
68 // color fragment processors.
Brian Salomone14bd802017-04-04 15:13:25 -040069 fNumColorProcessors = args.fProcessors->numColorFragmentProcessors();
Brian Salomoneec6f7b2017-02-10 14:29:38 -050070 int numTotalProcessors =
Brian Salomonb5cb6832017-02-24 11:01:15 -050071 fNumColorProcessors + args.fProcessors->numCoverageFragmentProcessors();
Brian Salomon54d212e2017-03-21 14:22:38 -040072 if (args.fAppliedClip && args.fAppliedClip->clipCoverageFragmentProcessor()) {
Brian Salomon652ecb52017-01-17 12:39:53 -050073 ++numTotalProcessors;
74 }
Brian Salomonb5cb6832017-02-24 11:01:15 -050075 fFragmentProcessors.reset(numTotalProcessors);
bsalomonac856c92015-08-27 06:30:17 -070076 int currFPIdx = 0;
Brian Salomone14bd802017-04-04 15:13:25 -040077 for (int i = 0; i < args.fProcessors->numColorFragmentProcessors(); ++i, ++currFPIdx) {
Brian Salomon189098e72017-01-19 09:55:19 -050078 const GrFragmentProcessor* fp = args.fProcessors->colorFragmentProcessor(i);
Brian Salomonb5cb6832017-02-24 11:01:15 -050079 fFragmentProcessors[currFPIdx].reset(fp);
bsalomonae59b772014-11-19 08:23:49 -080080 }
egdaniel95131432014-12-09 11:15:43 -080081
Brian Salomoneec6f7b2017-02-10 14:29:38 -050082 for (int i = 0; i < args.fProcessors->numCoverageFragmentProcessors(); ++i, ++currFPIdx) {
Brian Salomon189098e72017-01-19 09:55:19 -050083 const GrFragmentProcessor* fp = args.fProcessors->coverageFragmentProcessor(i);
Brian Salomonb5cb6832017-02-24 11:01:15 -050084 fFragmentProcessors[currFPIdx].reset(fp);
egdaniel9cf45bf2014-10-08 06:49:10 -070085 }
Brian Salomon54d212e2017-03-21 14:22:38 -040086 if (args.fAppliedClip) {
87 if (const GrFragmentProcessor* fp = args.fAppliedClip->clipCoverageFragmentProcessor()) {
88 fFragmentProcessors[currFPIdx].reset(fp);
89 }
Brian Salomon652ecb52017-01-17 12:39:53 -050090 }
egdanielc0648242014-09-22 13:17:02 -070091}
92
robertphillips498d7ac2015-10-30 10:11:30 -070093static void add_dependencies_for_processor(const GrFragmentProcessor* proc, GrRenderTarget* rt) {
bsalomonb58a2b42016-09-26 06:55:02 -070094 GrFragmentProcessor::TextureAccessIter iter(proc);
Brian Salomonab015ef2017-04-04 10:15:51 -040095 while (const GrResourceIOProcessor::TextureSampler* sampler = iter.next()) {
Robert Phillipsf2361d22016-10-25 14:20:06 -040096 SkASSERT(rt->getLastOpList());
Brian Salomondb4183d2016-11-17 12:48:40 -050097 rt->getLastOpList()->addDependency(sampler->texture());
robertphillips498d7ac2015-10-30 10:11:30 -070098 }
99}
100
101void GrPipeline::addDependenciesTo(GrRenderTarget* rt) const {
102 for (int i = 0; i < fFragmentProcessors.count(); ++i) {
103 add_dependencies_for_processor(fFragmentProcessors[i].get(), rt);
104 }
105
Brian Salomon18dfa982017-04-03 16:57:43 -0400106 if (fDstTexture) {
Robert Phillipsf2361d22016-10-25 14:20:06 -0400107 SkASSERT(rt->getLastOpList());
Brian Salomon18dfa982017-04-03 16:57:43 -0400108 rt->getLastOpList()->addDependency(fDstTexture.get());
robertphillips498d7ac2015-10-30 10:11:30 -0700109 }
110}
111
csmartdalton119fb2b2017-02-08 14:41:05 -0500112GrPipeline::GrPipeline(GrRenderTarget* rt, SkBlendMode blendmode)
113 : fRenderTarget(rt)
114 , fScissorState()
115 , fWindowRectsState()
116 , fUserStencilSettings(&GrUserStencilSettings::kUnused)
117 , fDrawFace(static_cast<uint16_t>(GrDrawFace::kBoth))
118 , fFlags()
119 , fXferProcessor(GrPorterDuffXPFactory::CreateNoCoverageXP(blendmode).get())
120 , fFragmentProcessors()
121 , fNumColorProcessors(0) {
122}
123
egdaniel89af44a2014-09-26 06:15:04 -0700124////////////////////////////////////////////////////////////////////////////////
125
bsalomon7312ff82016-09-12 08:55:38 -0700126bool GrPipeline::AreEqual(const GrPipeline& a, const GrPipeline& b) {
bsalomoncb02b382015-08-12 11:14:50 -0700127 SkASSERT(&a != &b);
joshualitt8cab9a72015-07-16 09:13:50 -0700128
bsalomoncb02b382015-08-12 11:14:50 -0700129 if (a.getRenderTarget() != b.getRenderTarget() ||
bsalomonac856c92015-08-27 06:30:17 -0700130 a.fFragmentProcessors.count() != b.fFragmentProcessors.count() ||
131 a.fNumColorProcessors != b.fNumColorProcessors ||
bsalomoncb02b382015-08-12 11:14:50 -0700132 a.fScissorState != b.fScissorState ||
Brian Salomon9a767722017-03-13 17:57:28 -0400133 a.fWindowRectsState != b.fWindowRectsState ||
bsalomoncb02b382015-08-12 11:14:50 -0700134 a.fFlags != b.fFlags ||
csmartdaltonc633abb2016-11-01 08:55:55 -0700135 a.fUserStencilSettings != b.fUserStencilSettings ||
Brian Salomon8c852be2017-01-04 10:44:42 -0500136 a.fDrawFace != b.fDrawFace) {
egdaniel89af44a2014-09-26 06:15:04 -0700137 return false;
138 }
139
bsalomon2047b782015-12-21 13:12:54 -0800140 // Most of the time both are nullptr
141 if (a.fXferProcessor.get() || b.fXferProcessor.get()) {
142 if (!a.getXferProcessor().isEqual(b.getXferProcessor())) {
143 return false;
144 }
egdanielc2304142014-12-11 13:15:13 -0800145 }
146
bsalomonac856c92015-08-27 06:30:17 -0700147 for (int i = 0; i < a.numFragmentProcessors(); i++) {
bsalomon7312ff82016-09-12 08:55:38 -0700148 if (!a.getFragmentProcessor(i).isEqual(b.getFragmentProcessor(i))) {
egdaniel89af44a2014-09-26 06:15:04 -0700149 return false;
150 }
151 }
egdaniel89af44a2014-09-26 06:15:04 -0700152 return true;
153}