blob: a9d34aea9c15275887ca60fb676bb2a1bdc9573f [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#ifndef GrPipeline_DEFINED
9#define GrPipeline_DEFINED
egdaniel3658f382014-09-15 07:01:59 -070010
egdanielb109ac22014-10-07 06:45:44 -070011#include "GrColor.h"
bsalomonac856c92015-08-27 06:30:17 -070012#include "GrFragmentProcessor.h"
joshualittdbe1e6f2015-07-16 08:12:45 -070013#include "GrNonAtomicRef.h"
bsalomonac856c92015-08-27 06:30:17 -070014#include "GrPendingProgramElement.h"
kkinnunencabe20c2015-06-01 01:37:26 -070015#include "GrPrimitiveProcessor.h"
robertphillips28a838e2016-06-23 14:07:00 -070016#include "GrProcOptInfo.h"
Brian Salomon5298dc82017-02-22 11:52:03 -050017#include "GrProcessorSet.h"
joshualitt79f8fae2014-10-28 17:59:26 -070018#include "GrProgramDesc.h"
csmartdaltonbf4a8f92016-09-06 10:01:06 -070019#include "GrScissorState.h"
csmartdaltonc633abb2016-11-01 08:55:55 -070020#include "GrUserStencilSettings.h"
csmartdaltonbf4a8f92016-09-06 10:01:06 -070021#include "GrWindowRectsState.h"
egdanielb109ac22014-10-07 06:45:44 -070022#include "SkMatrix.h"
23#include "SkRefCnt.h"
robertphillips5fa7f302016-07-21 09:21:04 -070024#include "effects/GrCoverageSetOpXP.h"
25#include "effects/GrDisableColorXP.h"
26#include "effects/GrPorterDuffXferProcessor.h"
27#include "effects/GrSimpleTextureEffect.h"
28
Brian Salomon652ecb52017-01-17 12:39:53 -050029class GrAppliedClip;
joshualitt79f8fae2014-10-28 17:59:26 -070030class GrDeviceCoordTexture;
Brian Salomon25a88092016-12-01 09:36:50 -050031class GrOp;
egdaniel8dd688b2015-01-22 10:16:09 -080032class GrPipelineBuilder;
Brian Salomon25a88092016-12-01 09:36:50 -050033class GrRenderTargetContext;
egdaniel3658f382014-09-15 07:01:59 -070034
Brian Salomon92aee3d2016-12-21 09:20:25 -050035/**
egdaniel8dd688b2015-01-22 10:16:09 -080036 * Class that holds an optimized version of a GrPipelineBuilder. It is meant to be an immutable
37 * class, and contains all data needed to set the state for a gpu draw.
egdaniel3658f382014-09-15 07:01:59 -070038 */
cdalton4833f392016-02-02 22:46:16 -080039class GrPipeline : public GrNonAtomicRef<GrPipeline> {
egdaniel3658f382014-09-15 07:01:59 -070040public:
bsalomoncb02b382015-08-12 11:14:50 -070041 ///////////////////////////////////////////////////////////////////////////
42 /// @name Creation
43
Brian Salomon189098e72017-01-19 09:55:19 -050044 enum Flags {
45 /**
46 * Perform HW anti-aliasing. This means either HW FSAA, if supported by the render target,
47 * or smooth-line rendering if a line primitive is drawn and line smoothing is supported by
48 * the 3D API.
49 */
50 kHWAntialias_Flag = 0x1,
51
52 /**
53 * Modifies the vertex shader so that vertices will be positioned at pixel centers.
54 */
55 kSnapVerticesToPixelCenters_Flag = 0x2,
Brian Salomon189098e72017-01-19 09:55:19 -050056 };
57
bsalomona387a112015-08-11 14:47:42 -070058 struct CreateArgs {
Brian Salomon189098e72017-01-19 09:55:19 -050059 uint32_t fFlags = 0;
60 GrDrawFace fDrawFace = GrDrawFace::kBoth;
61 const GrProcessorSet* fProcessors = nullptr;
Brian Salomon5298dc82017-02-22 11:52:03 -050062 const GrProcessorSet::FragmentProcessorAnalysis* fAnalysis;
Brian Salomon189098e72017-01-19 09:55:19 -050063 const GrUserStencilSettings* fUserStencil = &GrUserStencilSettings::kUnused;
64 GrAppliedClip* fAppliedClip = nullptr;
Brian Salomonb16e8ac2017-02-22 11:52:36 -050065 GrRenderTarget* fRenderTarget = nullptr;
Brian Salomon189098e72017-01-19 09:55:19 -050066 const GrCaps* fCaps = nullptr;
bsalomona387a112015-08-11 14:47:42 -070067 GrXferProcessor::DstTexture fDstTexture;
68 };
69
bsalomon47dfc362015-08-10 08:23:11 -070070 /** Creates a pipeline into a pre-allocated buffer */
Brian Salomon92aee3d2016-12-21 09:20:25 -050071 static GrPipeline* CreateAt(void* memory, const CreateArgs&, GrPipelineOptimizations*);
egdanielb109ac22014-10-07 06:45:44 -070072
csmartdalton119fb2b2017-02-08 14:41:05 -050073 /**
74 * Creates a simple pipeline with default settings and no processors. The provided blend mode
75 * must be "Porter Duff" (<= kLastCoeffMode).
76 **/
77 GrPipeline(GrRenderTarget*, SkBlendMode);
78
bsalomoncb02b382015-08-12 11:14:50 -070079 /// @}
80
81 ///////////////////////////////////////////////////////////////////////////
82 /// @name Comparisons
83
84 /**
joshualitt2fe79232015-08-05 12:02:27 -070085 * Returns true if these pipelines are equivalent. Coord transforms may be applied either on
86 * the GPU or the CPU. When we apply them on the CPU then the matrices need not agree in order
87 * to combine draws. Therefore we take a param that indicates whether coord transforms should be
88 * compared."
joshualitt9b989322014-12-15 14:16:27 -080089 */
bsalomon7312ff82016-09-12 08:55:38 -070090 static bool AreEqual(const GrPipeline& a, const GrPipeline& b);
bsalomoncb02b382015-08-12 11:14:50 -070091
92 /**
Brian Salomon09d994e2016-12-21 11:14:46 -050093 * Allows a GrOp subclass to determine whether two GrOp instances can combine. This is a
94 * stricter test than isEqual because it also considers blend barriers when the two ops'
95 * bounds overlap
bsalomoncb02b382015-08-12 11:14:50 -070096 */
97 static bool CanCombine(const GrPipeline& a, const SkRect& aBounds,
98 const GrPipeline& b, const SkRect& bBounds,
bsalomon7312ff82016-09-12 08:55:38 -070099 const GrCaps& caps) {
100 if (!AreEqual(a, b)) {
bsalomoncb02b382015-08-12 11:14:50 -0700101 return false;
102 }
103 if (a.xferBarrierType(caps)) {
104 return aBounds.fRight <= bBounds.fLeft ||
105 aBounds.fBottom <= bBounds.fTop ||
106 bBounds.fRight <= aBounds.fLeft ||
107 bBounds.fBottom <= aBounds.fTop;
108 }
109 return true;
110 }
egdaniel89af44a2014-09-26 06:15:04 -0700111
112 /// @}
113
114 ///////////////////////////////////////////////////////////////////////////
bsalomon6be6f7c2015-02-26 13:05:21 -0800115 /// @name GrFragmentProcessors
egdaniel89af44a2014-09-26 06:15:04 -0700116
Robert Phillipsf2361d22016-10-25 14:20:06 -0400117 // Make the renderTarget's GrOpList (if it exists) be dependent on any
118 // GrOpLists in this pipeline
robertphillips498d7ac2015-10-30 10:11:30 -0700119 void addDependenciesTo(GrRenderTarget* rt) const;
bsalomon6be6f7c2015-02-26 13:05:21 -0800120
bsalomonac856c92015-08-27 06:30:17 -0700121 int numColorFragmentProcessors() const { return fNumColorProcessors; }
122 int numCoverageFragmentProcessors() const {
123 return fFragmentProcessors.count() - fNumColorProcessors;
124 }
125 int numFragmentProcessors() const { return fFragmentProcessors.count(); }
egdaniel89af44a2014-09-26 06:15:04 -0700126
bsalomon2047b782015-12-21 13:12:54 -0800127 const GrXferProcessor& getXferProcessor() const {
128 if (fXferProcessor.get()) {
129 return *fXferProcessor.get();
130 } else {
131 // A null xp member means the common src-over case. GrXferProcessor's ref'ing
132 // mechanism is not thread safe so we do not hold a ref on this global.
133 return GrPorterDuffXPFactory::SimpleSrcOverXP();
134 }
135 }
egdaniel378092f2014-12-03 10:40:13 -0800136
bsalomonac856c92015-08-27 06:30:17 -0700137 const GrFragmentProcessor& getColorFragmentProcessor(int idx) const {
138 SkASSERT(idx < this->numColorFragmentProcessors());
139 return *fFragmentProcessors[idx].get();
egdanield9aa2182014-10-09 13:47:05 -0700140 }
bsalomonac856c92015-08-27 06:30:17 -0700141
142 const GrFragmentProcessor& getCoverageFragmentProcessor(int idx) const {
143 SkASSERT(idx < this->numCoverageFragmentProcessors());
144 return *fFragmentProcessors[fNumColorProcessors + idx].get();
egdanield9aa2182014-10-09 13:47:05 -0700145 }
bsalomonac856c92015-08-27 06:30:17 -0700146
147 const GrFragmentProcessor& getFragmentProcessor(int idx) const {
148 return *fFragmentProcessors[idx].get();
bsalomonae59b772014-11-19 08:23:49 -0800149 }
egdaniel89af44a2014-09-26 06:15:04 -0700150
151 /// @}
152
egdaniel89af44a2014-09-26 06:15:04 -0700153 /**
154 * Retrieves the currently set render-target.
155 *
156 * @return The currently set render target.
157 */
bsalomon37dd3312014-11-03 08:47:23 -0800158 GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); }
egdaniel89af44a2014-09-26 06:15:04 -0700159
csmartdaltonc633abb2016-11-01 08:55:55 -0700160 const GrUserStencilSettings* getUserStencil() const { return fUserStencilSettings; }
egdaniel89af44a2014-09-26 06:15:04 -0700161
bsalomon3e791242014-12-17 13:43:13 -0800162 const GrScissorState& getScissorState() const { return fScissorState; }
joshualitt54e0c122014-11-19 09:38:51 -0800163
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700164 const GrWindowRectsState& getWindowRectsState() const { return fWindowRectsState; }
csmartdalton28341fa2016-08-17 10:00:21 -0700165
Brian Salomon189098e72017-01-19 09:55:19 -0500166 bool isHWAntialiasState() const { return SkToBool(fFlags & kHWAntialias_Flag); }
167 bool snapVerticesToPixelCenters() const {
168 return SkToBool(fFlags & kSnapVerticesToPixelCenters_Flag);
169 }
brianosman64d094d2016-03-25 06:01:59 -0700170 bool getDisableOutputConversionToSRGB() const {
171 return SkToBool(fFlags & kDisableOutputConversionToSRGB_Flag);
172 }
brianosman898235c2016-04-06 07:38:23 -0700173 bool getAllowSRGBInputs() const {
174 return SkToBool(fFlags & kAllowSRGBInputs_Flag);
175 }
dvonbeck9b03e7b2016-08-01 11:01:56 -0700176 bool usesDistanceVectorField() const {
177 return SkToBool(fFlags & kUsesDistanceVectorField_Flag);
178 }
cdalton193d9cf2016-05-12 11:52:02 -0700179 bool hasStencilClip() const {
180 return SkToBool(fFlags & kHasStencilClip_Flag);
181 }
csmartdaltonc633abb2016-11-01 08:55:55 -0700182 bool isStencilEnabled() const {
183 return SkToBool(fFlags & kStencilEnabled_Flag);
184 }
bsalomonae59b772014-11-19 08:23:49 -0800185
bsalomoncb02b382015-08-12 11:14:50 -0700186 GrXferBarrierType xferBarrierType(const GrCaps& caps) const {
bsalomon2047b782015-12-21 13:12:54 -0800187 return this->getXferProcessor().xferBarrierType(fRenderTarget.get(), caps);
bsalomoncb02b382015-08-12 11:14:50 -0700188 }
189
egdaniel89af44a2014-09-26 06:15:04 -0700190 /**
bsalomonae59b772014-11-19 08:23:49 -0800191 * Gets whether the target is drawing clockwise, counterclockwise,
192 * or both faces.
193 * @return the current draw face(s).
egdaniel89af44a2014-09-26 06:15:04 -0700194 */
Brian Salomon189098e72017-01-19 09:55:19 -0500195 GrDrawFace getDrawFace() const { return static_cast<GrDrawFace>(fDrawFace); }
bsalomonae59b772014-11-19 08:23:49 -0800196
bsalomonae59b772014-11-19 08:23:49 -0800197private:
bsalomonc6998732015-08-10 12:01:15 -0700198 GrPipeline() { /** Initialized in factory function*/ }
bsalomon47dfc362015-08-10 08:23:11 -0700199
Brian Salomonf87e2b92017-01-19 11:31:50 -0500200 /** This is a continuation of the public "Flags" enum. */
Brian Salomon189098e72017-01-19 09:55:19 -0500201 enum PrivateFlags {
Brian Salomonf87e2b92017-01-19 11:31:50 -0500202 kDisableOutputConversionToSRGB_Flag = 0x4,
203 kAllowSRGBInputs_Flag = 0x8,
Brian Salomon189098e72017-01-19 09:55:19 -0500204 kUsesDistanceVectorField_Flag = 0x10,
205 kHasStencilClip_Flag = 0x20,
206 kStencilEnabled_Flag = 0x40,
bsalomon04ddf892014-11-19 12:36:22 -0800207 };
208
bsalomonae59b772014-11-19 08:23:49 -0800209 typedef GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> RenderTarget;
bsalomonac856c92015-08-27 06:30:17 -0700210 typedef GrPendingProgramElement<const GrFragmentProcessor> PendingFragmentProcessor;
211 typedef SkAutoSTArray<8, PendingFragmentProcessor> FragmentProcessorArray;
egdaniel378092f2014-12-03 10:40:13 -0800212 typedef GrPendingProgramElement<const GrXferProcessor> ProgramXferProcessor;
bsalomonae59b772014-11-19 08:23:49 -0800213 RenderTarget fRenderTarget;
bsalomon3e791242014-12-17 13:43:13 -0800214 GrScissorState fScissorState;
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700215 GrWindowRectsState fWindowRectsState;
csmartdaltonc633abb2016-11-01 08:55:55 -0700216 const GrUserStencilSettings* fUserStencilSettings;
Brian Salomon189098e72017-01-19 09:55:19 -0500217 uint16_t fDrawFace;
218 uint16_t fFlags;
egdaniel378092f2014-12-03 10:40:13 -0800219 ProgramXferProcessor fXferProcessor;
bsalomonac856c92015-08-27 06:30:17 -0700220 FragmentProcessorArray fFragmentProcessors;
egdanield9aa2182014-10-09 13:47:05 -0700221
bsalomonac856c92015-08-27 06:30:17 -0700222 // This value is also the index in fFragmentProcessors where coverage processors begin.
223 int fNumColorProcessors;
egdaniel89af44a2014-09-26 06:15:04 -0700224
egdaniel89af44a2014-09-26 06:15:04 -0700225 typedef SkRefCnt INHERITED;
egdaniel3658f382014-09-15 07:01:59 -0700226};
227
228#endif