blob: 5817ce846d1e83bc49504eb8ee41112f62b43648 [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"
Brian Salomonae5f9532018-07-31 11:03:40 -040014#include "GrPendingIOResource.h"
Brian Salomon5298dc82017-02-22 11:52:03 -050015#include "GrProcessorSet.h"
joshualitt79f8fae2014-10-28 17:59:26 -070016#include "GrProgramDesc.h"
Brian Salomona4677b52017-05-04 12:39:56 -040017#include "GrRect.h"
Robert Phillips2890fbf2017-07-26 15:48:41 -040018#include "GrRenderTargetProxy.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;
Brian Salomon25a88092016-12-01 09:36:50 -050030class GrOp;
Brian Salomon25a88092016-12-01 09:36:50 -050031class GrRenderTargetContext;
egdaniel3658f382014-09-15 07:01:59 -070032
Brian Salomon92aee3d2016-12-21 09:20:25 -050033/**
Brian Salomone5b399e2017-07-19 13:50:54 -040034 * This immutable object contains information needed to set build a shader program and set API
35 * state for a draw. It is used along with a GrPrimitiveProcessor and a source of geometric
36 * data (GrMesh or GrPath) to draw.
egdaniel3658f382014-09-15 07:01:59 -070037 */
Brian Salomon16351462017-07-19 16:35:31 -040038class GrPipeline {
egdaniel3658f382014-09-15 07:01:59 -070039public:
bsalomoncb02b382015-08-12 11:14:50 -070040 ///////////////////////////////////////////////////////////////////////////
41 /// @name Creation
42
Brian Salomon189098e72017-01-19 09:55:19 -050043 enum Flags {
44 /**
45 * Perform HW anti-aliasing. This means either HW FSAA, if supported by the render target,
46 * or smooth-line rendering if a line primitive is drawn and line smoothing is supported by
47 * the 3D API.
48 */
49 kHWAntialias_Flag = 0x1,
Brian Salomon189098e72017-01-19 09:55:19 -050050 /**
51 * Modifies the vertex shader so that vertices will be positioned at pixel centers.
52 */
53 kSnapVerticesToPixelCenters_Flag = 0x2,
Brian Salomon189098e72017-01-19 09:55:19 -050054 };
55
Brian Salomonb5cb6832017-02-24 11:01:15 -050056 struct InitArgs {
Brian Salomon189098e72017-01-19 09:55:19 -050057 uint32_t fFlags = 0;
Brian Salomon189098e72017-01-19 09:55:19 -050058 const GrUserStencilSettings* fUserStencil = &GrUserStencilSettings::kUnused;
Robert Phillips2890fbf2017-07-26 15:48:41 -040059 GrRenderTargetProxy* fProxy = nullptr;
Brian Salomon189098e72017-01-19 09:55:19 -050060 const GrCaps* fCaps = nullptr;
Robert Phillips9bee2e52017-05-29 12:37:20 -040061 GrResourceProvider* fResourceProvider = nullptr;
Robert Phillipsbb581ce2017-05-29 15:05:15 -040062 GrXferProcessor::DstProxy fDstProxy;
bsalomona387a112015-08-11 14:47:42 -070063 };
64
Brian Salomonb5cb6832017-02-24 11:01:15 -050065 /**
Brian Salomon49348902018-06-26 09:12:38 -040066 * Some state can be changed between GrMeshes without changing GrPipelines. This is generally
67 * less expensive then using multiple pipelines. Such state is called "dynamic state". It can
68 * be specified in two ways:
69 * 1) FixedDynamicState - use this to specify state that does not vary between GrMeshes.
70 * 2) DynamicStateArrays - use this to specify per mesh values for dynamic state.
Chris Dalton46983b72017-06-06 12:27:16 -060071 **/
Brian Salomon49348902018-06-26 09:12:38 -040072 struct FixedDynamicState {
Brian Salomon7eae3e02018-08-07 14:02:38 +000073 explicit FixedDynamicState(const SkIRect& scissorRect) : fScissorRect(scissorRect) {}
74 FixedDynamicState() = default;
75 SkIRect fScissorRect = SkIRect::EmptyIRect();
Brian Salomoncd7907b2018-08-30 08:36:18 -040076 // Must have GrPrimitiveProcessor::numTextureSamplers() entries. Can be null if no samplers.
Brian Salomon7eae3e02018-08-07 14:02:38 +000077 GrTextureProxy** fPrimitiveProcessorTextures = nullptr;
Chris Dalton46983b72017-06-06 12:27:16 -060078 };
79
80 /**
Brian Salomon49348902018-06-26 09:12:38 -040081 * Any non-null array overrides the FixedDynamicState on a mesh-by-mesh basis. Arrays must
82 * have one entry for each GrMesh.
83 */
84 struct DynamicStateArrays {
85 const SkIRect* fScissorRects = nullptr;
86 };
87
88 /**
csmartdalton119fb2b2017-02-08 14:41:05 -050089 * Creates a simple pipeline with default settings and no processors. The provided blend mode
Chris Dalton916c4982018-08-15 00:53:25 -060090 * must be "Porter Duff" (<= kLastCoeffMode). If using GrScissorTest::kEnabled, the caller must
Chris Dalton46983b72017-06-06 12:27:16 -060091 * specify a scissor rectangle through the DynamicState struct.
csmartdalton119fb2b2017-02-08 14:41:05 -050092 **/
Chris Dalton916c4982018-08-15 00:53:25 -060093 GrPipeline(GrRenderTargetProxy*, GrScissorTest, SkBlendMode);
csmartdalton119fb2b2017-02-08 14:41:05 -050094
Brian Salomonbfd18cd2017-08-09 16:27:09 -040095 GrPipeline(const InitArgs&, GrProcessorSet&&, GrAppliedClip&&);
Brian Salomon6d4b65e2017-05-03 17:06:09 -040096
Brian Salomon16351462017-07-19 16:35:31 -040097 GrPipeline(const GrPipeline&) = delete;
98 GrPipeline& operator=(const GrPipeline&) = delete;
99
egdaniel89af44a2014-09-26 06:15:04 -0700100 /// @}
101
102 ///////////////////////////////////////////////////////////////////////////
bsalomon6be6f7c2015-02-26 13:05:21 -0800103 /// @name GrFragmentProcessors
egdaniel89af44a2014-09-26 06:15:04 -0700104
Robert Phillipsd261e102017-06-23 12:37:20 -0400105 // Make the renderTargetContext's GrOpList be dependent on any GrOpLists in this pipeline
106 void addDependenciesTo(GrOpList* recipient, const GrCaps&) const;
bsalomon6be6f7c2015-02-26 13:05:21 -0800107
bsalomonac856c92015-08-27 06:30:17 -0700108 int numColorFragmentProcessors() const { return fNumColorProcessors; }
109 int numCoverageFragmentProcessors() const {
110 return fFragmentProcessors.count() - fNumColorProcessors;
111 }
112 int numFragmentProcessors() const { return fFragmentProcessors.count(); }
egdaniel89af44a2014-09-26 06:15:04 -0700113
bsalomon2047b782015-12-21 13:12:54 -0800114 const GrXferProcessor& getXferProcessor() const {
Brian Salomond61c9d92017-04-10 10:54:25 -0400115 if (fXferProcessor) {
bsalomon2047b782015-12-21 13:12:54 -0800116 return *fXferProcessor.get();
117 } else {
118 // A null xp member means the common src-over case. GrXferProcessor's ref'ing
119 // mechanism is not thread safe so we do not hold a ref on this global.
120 return GrPorterDuffXPFactory::SimpleSrcOverXP();
121 }
122 }
egdaniel378092f2014-12-03 10:40:13 -0800123
Brian Salomon18dfa982017-04-03 16:57:43 -0400124 /**
125 * If the GrXferProcessor uses a texture to access the dst color, then this returns that
126 * texture and the offset to the dst contents within that texture.
127 */
Robert Phillipsbb581ce2017-05-29 15:05:15 -0400128 GrTextureProxy* dstTextureProxy(SkIPoint* offset = nullptr) const {
Brian Salomon18dfa982017-04-03 16:57:43 -0400129 if (offset) {
130 *offset = fDstTextureOffset;
131 }
Robert Phillipsbb581ce2017-05-29 15:05:15 -0400132 return fDstTextureProxy.get();
133 }
134
135 GrTexture* peekDstTexture(SkIPoint* offset = nullptr) const {
136 if (GrTextureProxy* dstProxy = this->dstTextureProxy(offset)) {
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400137 return dstProxy->peekTexture();
Robert Phillipsbb581ce2017-05-29 15:05:15 -0400138 }
139
140 return nullptr;
Brian Salomon18dfa982017-04-03 16:57:43 -0400141 }
142
bsalomonac856c92015-08-27 06:30:17 -0700143 const GrFragmentProcessor& getColorFragmentProcessor(int idx) const {
144 SkASSERT(idx < this->numColorFragmentProcessors());
145 return *fFragmentProcessors[idx].get();
egdanield9aa2182014-10-09 13:47:05 -0700146 }
bsalomonac856c92015-08-27 06:30:17 -0700147
148 const GrFragmentProcessor& getCoverageFragmentProcessor(int idx) const {
149 SkASSERT(idx < this->numCoverageFragmentProcessors());
150 return *fFragmentProcessors[fNumColorProcessors + idx].get();
egdanield9aa2182014-10-09 13:47:05 -0700151 }
bsalomonac856c92015-08-27 06:30:17 -0700152
153 const GrFragmentProcessor& getFragmentProcessor(int idx) const {
154 return *fFragmentProcessors[idx].get();
bsalomonae59b772014-11-19 08:23:49 -0800155 }
egdaniel89af44a2014-09-26 06:15:04 -0700156
157 /// @}
158
egdaniel89af44a2014-09-26 06:15:04 -0700159 /**
160 * Retrieves the currently set render-target.
161 *
162 * @return The currently set render target.
163 */
Robert Phillips2890fbf2017-07-26 15:48:41 -0400164 GrRenderTargetProxy* proxy() const { return fProxy.get(); }
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400165 GrRenderTarget* renderTarget() const { return fProxy.get()->peekRenderTarget(); }
egdaniel89af44a2014-09-26 06:15:04 -0700166
csmartdaltonc633abb2016-11-01 08:55:55 -0700167 const GrUserStencilSettings* getUserStencil() const { return fUserStencilSettings; }
egdaniel89af44a2014-09-26 06:15:04 -0700168
Chris Dalton916c4982018-08-15 00:53:25 -0600169 bool isScissorEnabled() const {
170 return SkToBool(fFlags & kScissorEnabled_Flag);
Brian Salomon49348902018-06-26 09:12:38 -0400171 }
joshualitt54e0c122014-11-19 09:38:51 -0800172
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700173 const GrWindowRectsState& getWindowRectsState() const { return fWindowRectsState; }
csmartdalton28341fa2016-08-17 10:00:21 -0700174
Brian Salomon189098e72017-01-19 09:55:19 -0500175 bool isHWAntialiasState() const { return SkToBool(fFlags & kHWAntialias_Flag); }
176 bool snapVerticesToPixelCenters() const {
177 return SkToBool(fFlags & kSnapVerticesToPixelCenters_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 }
Robert Phillipsa91e0b72017-05-01 13:12:20 -0400185 bool isBad() const { return SkToBool(fFlags & kIsBad_Flag); }
bsalomonae59b772014-11-19 08:23:49 -0800186
Robert Phillipsc9c06d42017-06-12 10:58:31 -0400187 GrXferBarrierType xferBarrierType(const GrCaps& caps) const;
bsalomoncb02b382015-08-12 11:14:50 -0700188
Brian Salomon82dfd3d2017-06-14 12:30:35 -0400189 static SkString DumpFlags(uint32_t flags) {
190 if (flags) {
191 SkString result;
192 if (flags & GrPipeline::kSnapVerticesToPixelCenters_Flag) {
193 result.append("Snap vertices to pixel center.\n");
194 }
195 if (flags & GrPipeline::kHWAntialias_Flag) {
196 result.append("HW Antialiasing enabled.\n");
197 }
Brian Salomon82dfd3d2017-06-14 12:30:35 -0400198 return result;
199 }
200 return SkString("No pipeline flags\n");
201 }
202
bsalomonae59b772014-11-19 08:23:49 -0800203private:
Robert Phillipsa91e0b72017-05-01 13:12:20 -0400204 void markAsBad() { fFlags |= kIsBad_Flag; }
205
Brian Salomonf87e2b92017-01-19 11:31:50 -0500206 /** This is a continuation of the public "Flags" enum. */
Brian Salomon189098e72017-01-19 09:55:19 -0500207 enum PrivateFlags {
Brian Salomone23bffd2017-06-02 11:01:10 -0400208 kHasStencilClip_Flag = 0x10,
209 kStencilEnabled_Flag = 0x20,
Brian Salomon49348902018-06-26 09:12:38 -0400210 kScissorEnabled_Flag = 0x40,
211 kIsBad_Flag = 0x80,
bsalomon04ddf892014-11-19 12:36:22 -0800212 };
213
Robert Phillips2890fbf2017-07-26 15:48:41 -0400214 using RenderTargetProxy = GrPendingIOResource<GrRenderTargetProxy, kWrite_GrIOType>;
Robert Phillipsbb581ce2017-05-29 15:05:15 -0400215 using DstTextureProxy = GrPendingIOResource<GrTextureProxy, kRead_GrIOType>;
Brian Salomonaff329b2017-08-11 09:40:37 -0400216 using FragmentProcessorArray = SkAutoSTArray<8, std::unique_ptr<const GrFragmentProcessor>>;
Brian Salomon18dfa982017-04-03 16:57:43 -0400217
Robert Phillipsbb581ce2017-05-29 15:05:15 -0400218 DstTextureProxy fDstTextureProxy;
Brian Salomon18dfa982017-04-03 16:57:43 -0400219 SkIPoint fDstTextureOffset;
Robert Phillips19e51dc2017-08-09 09:30:51 -0400220 // MDB TODO: do we still need the destination proxy here?
Robert Phillips2890fbf2017-07-26 15:48:41 -0400221 RenderTargetProxy fProxy;
Brian Salomon18dfa982017-04-03 16:57:43 -0400222 GrWindowRectsState fWindowRectsState;
223 const GrUserStencilSettings* fUserStencilSettings;
Brian Salomon18dfa982017-04-03 16:57:43 -0400224 uint16_t fFlags;
Brian Salomond61c9d92017-04-10 10:54:25 -0400225 sk_sp<const GrXferProcessor> fXferProcessor;
Brian Salomon18dfa982017-04-03 16:57:43 -0400226 FragmentProcessorArray fFragmentProcessors;
egdanield9aa2182014-10-09 13:47:05 -0700227
bsalomonac856c92015-08-27 06:30:17 -0700228 // This value is also the index in fFragmentProcessors where coverage processors begin.
Brian Salomon18dfa982017-04-03 16:57:43 -0400229 int fNumColorProcessors;
egdaniel3658f382014-09-15 07:01:59 -0700230};
231
232#endif