blob: 3949a75c5cb0cd16467528909ee1b8563f32ebe9 [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"
joshualitt79f8fae2014-10-28 17:59:26 -070017#include "GrProgramDesc.h"
csmartdaltonbf4a8f92016-09-06 10:01:06 -070018#include "GrScissorState.h"
csmartdaltonc633abb2016-11-01 08:55:55 -070019#include "GrUserStencilSettings.h"
csmartdaltonbf4a8f92016-09-06 10:01:06 -070020#include "GrWindowRectsState.h"
egdanielb109ac22014-10-07 06:45:44 -070021#include "SkMatrix.h"
22#include "SkRefCnt.h"
23
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/**
36 * This Describes aspects of the GrPrimitiveProcessor produced by a GrDrawOp that are used in
37 * pipeline analysis.
38 */
39class GrPipelineAnalysisDrawOpInput {
40public:
41 GrPipelineAnalysisDrawOpInput(GrPipelineInput* color, GrPipelineInput* coverage)
42 : fColorInput(color), fCoverageInput(coverage) {}
43 GrPipelineInput* pipelineColorInput() { return fColorInput; }
44 GrPipelineInput* pipelineCoverageInput() { return fCoverageInput; }
ethannicholas3b7af782016-02-01 11:45:45 -080045
Brian Salomon92aee3d2016-12-21 09:20:25 -050046 void setUsesPLSDstRead() { fUsesPLSDstRead = true; }
47
48 bool usesPLSDstRead() const { return fUsesPLSDstRead; }
49
50private:
51 GrPipelineInput* fColorInput;
52 GrPipelineInput* fCoverageInput;
53 bool fUsesPLSDstRead = false;
ethannicholasff210322015-11-24 12:10:10 -080054};
55
Brian Salomon92aee3d2016-12-21 09:20:25 -050056/** This is used to track pipeline analysis through the color and coverage fragment processors. */
57struct GrPipelineAnalysis {
ethannicholasff210322015-11-24 12:10:10 -080058 GrProcOptInfo fColorPOI;
59 GrProcOptInfo fCoveragePOI;
Brian Salomon92aee3d2016-12-21 09:20:25 -050060 bool fUsesPLSDstRead = false;
ethannicholasff210322015-11-24 12:10:10 -080061};
62
Brian Salomon189098e72017-01-19 09:55:19 -050063class GrProcessorSet;
64
egdaniel3658f382014-09-15 07:01:59 -070065/**
egdaniel8dd688b2015-01-22 10:16:09 -080066 * Class that holds an optimized version of a GrPipelineBuilder. It is meant to be an immutable
67 * class, and contains all data needed to set the state for a gpu draw.
egdaniel3658f382014-09-15 07:01:59 -070068 */
cdalton4833f392016-02-02 22:46:16 -080069class GrPipeline : public GrNonAtomicRef<GrPipeline> {
egdaniel3658f382014-09-15 07:01:59 -070070public:
bsalomoncb02b382015-08-12 11:14:50 -070071 ///////////////////////////////////////////////////////////////////////////
72 /// @name Creation
73
Brian Salomon189098e72017-01-19 09:55:19 -050074 enum Flags {
75 /**
76 * Perform HW anti-aliasing. This means either HW FSAA, if supported by the render target,
77 * or smooth-line rendering if a line primitive is drawn and line smoothing is supported by
78 * the 3D API.
79 */
80 kHWAntialias_Flag = 0x1,
81
82 /**
83 * Modifies the vertex shader so that vertices will be positioned at pixel centers.
84 */
85 kSnapVerticesToPixelCenters_Flag = 0x2,
Brian Salomon189098e72017-01-19 09:55:19 -050086 };
87
bsalomona387a112015-08-11 14:47:42 -070088 struct CreateArgs {
Brian Salomon189098e72017-01-19 09:55:19 -050089 uint32_t fFlags = 0;
90 GrDrawFace fDrawFace = GrDrawFace::kBoth;
91 const GrProcessorSet* fProcessors = nullptr;
92 const GrUserStencilSettings* fUserStencil = &GrUserStencilSettings::kUnused;
93 GrAppliedClip* fAppliedClip = nullptr;
94 GrRenderTargetContext* fRenderTargetContext = nullptr;
95 const GrCaps* fCaps = nullptr;
Brian Salomon92aee3d2016-12-21 09:20:25 -050096 GrPipelineAnalysis fAnalysis;
bsalomona387a112015-08-11 14:47:42 -070097 GrXferProcessor::DstTexture fDstTexture;
98 };
99
bsalomon47dfc362015-08-10 08:23:11 -0700100 /** Creates a pipeline into a pre-allocated buffer */
Brian Salomon92aee3d2016-12-21 09:20:25 -0500101 static GrPipeline* CreateAt(void* memory, const CreateArgs&, GrPipelineOptimizations*);
egdanielb109ac22014-10-07 06:45:44 -0700102
bsalomoncb02b382015-08-12 11:14:50 -0700103 /// @}
104
105 ///////////////////////////////////////////////////////////////////////////
106 /// @name Comparisons
107
108 /**
joshualitt2fe79232015-08-05 12:02:27 -0700109 * Returns true if these pipelines are equivalent. Coord transforms may be applied either on
110 * the GPU or the CPU. When we apply them on the CPU then the matrices need not agree in order
111 * to combine draws. Therefore we take a param that indicates whether coord transforms should be
112 * compared."
joshualitt9b989322014-12-15 14:16:27 -0800113 */
bsalomon7312ff82016-09-12 08:55:38 -0700114 static bool AreEqual(const GrPipeline& a, const GrPipeline& b);
bsalomoncb02b382015-08-12 11:14:50 -0700115
116 /**
Brian Salomon09d994e2016-12-21 11:14:46 -0500117 * Allows a GrOp subclass to determine whether two GrOp instances can combine. This is a
118 * stricter test than isEqual because it also considers blend barriers when the two ops'
119 * bounds overlap
bsalomoncb02b382015-08-12 11:14:50 -0700120 */
121 static bool CanCombine(const GrPipeline& a, const SkRect& aBounds,
122 const GrPipeline& b, const SkRect& bBounds,
bsalomon7312ff82016-09-12 08:55:38 -0700123 const GrCaps& caps) {
124 if (!AreEqual(a, b)) {
bsalomoncb02b382015-08-12 11:14:50 -0700125 return false;
126 }
127 if (a.xferBarrierType(caps)) {
128 return aBounds.fRight <= bBounds.fLeft ||
129 aBounds.fBottom <= bBounds.fTop ||
130 bBounds.fRight <= aBounds.fLeft ||
131 bBounds.fBottom <= aBounds.fTop;
132 }
133 return true;
134 }
egdaniel89af44a2014-09-26 06:15:04 -0700135
136 /// @}
137
138 ///////////////////////////////////////////////////////////////////////////
bsalomon6be6f7c2015-02-26 13:05:21 -0800139 /// @name GrFragmentProcessors
egdaniel89af44a2014-09-26 06:15:04 -0700140
Robert Phillipsf2361d22016-10-25 14:20:06 -0400141 // Make the renderTarget's GrOpList (if it exists) be dependent on any
142 // GrOpLists in this pipeline
robertphillips498d7ac2015-10-30 10:11:30 -0700143 void addDependenciesTo(GrRenderTarget* rt) const;
bsalomon6be6f7c2015-02-26 13:05:21 -0800144
bsalomonac856c92015-08-27 06:30:17 -0700145 int numColorFragmentProcessors() const { return fNumColorProcessors; }
146 int numCoverageFragmentProcessors() const {
147 return fFragmentProcessors.count() - fNumColorProcessors;
148 }
149 int numFragmentProcessors() const { return fFragmentProcessors.count(); }
egdaniel89af44a2014-09-26 06:15:04 -0700150
bsalomon2047b782015-12-21 13:12:54 -0800151 const GrXferProcessor& getXferProcessor() const {
152 if (fXferProcessor.get()) {
153 return *fXferProcessor.get();
154 } else {
155 // A null xp member means the common src-over case. GrXferProcessor's ref'ing
156 // mechanism is not thread safe so we do not hold a ref on this global.
157 return GrPorterDuffXPFactory::SimpleSrcOverXP();
158 }
159 }
egdaniel378092f2014-12-03 10:40:13 -0800160
bsalomonac856c92015-08-27 06:30:17 -0700161 const GrFragmentProcessor& getColorFragmentProcessor(int idx) const {
162 SkASSERT(idx < this->numColorFragmentProcessors());
163 return *fFragmentProcessors[idx].get();
egdanield9aa2182014-10-09 13:47:05 -0700164 }
bsalomonac856c92015-08-27 06:30:17 -0700165
166 const GrFragmentProcessor& getCoverageFragmentProcessor(int idx) const {
167 SkASSERT(idx < this->numCoverageFragmentProcessors());
168 return *fFragmentProcessors[fNumColorProcessors + idx].get();
egdanield9aa2182014-10-09 13:47:05 -0700169 }
bsalomonac856c92015-08-27 06:30:17 -0700170
171 const GrFragmentProcessor& getFragmentProcessor(int idx) const {
172 return *fFragmentProcessors[idx].get();
bsalomonae59b772014-11-19 08:23:49 -0800173 }
egdaniel89af44a2014-09-26 06:15:04 -0700174
175 /// @}
176
egdaniel89af44a2014-09-26 06:15:04 -0700177 /**
178 * Retrieves the currently set render-target.
179 *
180 * @return The currently set render target.
181 */
bsalomon37dd3312014-11-03 08:47:23 -0800182 GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); }
egdaniel89af44a2014-09-26 06:15:04 -0700183
csmartdaltonc633abb2016-11-01 08:55:55 -0700184 const GrUserStencilSettings* getUserStencil() const { return fUserStencilSettings; }
egdaniel89af44a2014-09-26 06:15:04 -0700185
bsalomon3e791242014-12-17 13:43:13 -0800186 const GrScissorState& getScissorState() const { return fScissorState; }
joshualitt54e0c122014-11-19 09:38:51 -0800187
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700188 const GrWindowRectsState& getWindowRectsState() const { return fWindowRectsState; }
csmartdalton28341fa2016-08-17 10:00:21 -0700189
Brian Salomon189098e72017-01-19 09:55:19 -0500190 bool isHWAntialiasState() const { return SkToBool(fFlags & kHWAntialias_Flag); }
191 bool snapVerticesToPixelCenters() const {
192 return SkToBool(fFlags & kSnapVerticesToPixelCenters_Flag);
193 }
brianosman64d094d2016-03-25 06:01:59 -0700194 bool getDisableOutputConversionToSRGB() const {
195 return SkToBool(fFlags & kDisableOutputConversionToSRGB_Flag);
196 }
brianosman898235c2016-04-06 07:38:23 -0700197 bool getAllowSRGBInputs() const {
198 return SkToBool(fFlags & kAllowSRGBInputs_Flag);
199 }
dvonbeck9b03e7b2016-08-01 11:01:56 -0700200 bool usesDistanceVectorField() const {
201 return SkToBool(fFlags & kUsesDistanceVectorField_Flag);
202 }
cdalton193d9cf2016-05-12 11:52:02 -0700203 bool hasStencilClip() const {
204 return SkToBool(fFlags & kHasStencilClip_Flag);
205 }
csmartdaltonc633abb2016-11-01 08:55:55 -0700206 bool isStencilEnabled() const {
207 return SkToBool(fFlags & kStencilEnabled_Flag);
208 }
bsalomonae59b772014-11-19 08:23:49 -0800209
bsalomoncb02b382015-08-12 11:14:50 -0700210 GrXferBarrierType xferBarrierType(const GrCaps& caps) const {
bsalomon2047b782015-12-21 13:12:54 -0800211 return this->getXferProcessor().xferBarrierType(fRenderTarget.get(), caps);
bsalomoncb02b382015-08-12 11:14:50 -0700212 }
213
egdaniel89af44a2014-09-26 06:15:04 -0700214 /**
bsalomonae59b772014-11-19 08:23:49 -0800215 * Gets whether the target is drawing clockwise, counterclockwise,
216 * or both faces.
217 * @return the current draw face(s).
egdaniel89af44a2014-09-26 06:15:04 -0700218 */
Brian Salomon189098e72017-01-19 09:55:19 -0500219 GrDrawFace getDrawFace() const { return static_cast<GrDrawFace>(fDrawFace); }
bsalomonae59b772014-11-19 08:23:49 -0800220
bsalomonae59b772014-11-19 08:23:49 -0800221private:
bsalomonc6998732015-08-10 12:01:15 -0700222 GrPipeline() { /** Initialized in factory function*/ }
bsalomon47dfc362015-08-10 08:23:11 -0700223
Brian Salomonf87e2b92017-01-19 11:31:50 -0500224 /** This is a continuation of the public "Flags" enum. */
Brian Salomon189098e72017-01-19 09:55:19 -0500225 enum PrivateFlags {
Brian Salomonf87e2b92017-01-19 11:31:50 -0500226 kDisableOutputConversionToSRGB_Flag = 0x4,
227 kAllowSRGBInputs_Flag = 0x8,
Brian Salomon189098e72017-01-19 09:55:19 -0500228 kUsesDistanceVectorField_Flag = 0x10,
229 kHasStencilClip_Flag = 0x20,
230 kStencilEnabled_Flag = 0x40,
bsalomon04ddf892014-11-19 12:36:22 -0800231 };
232
bsalomonae59b772014-11-19 08:23:49 -0800233 typedef GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> RenderTarget;
bsalomonac856c92015-08-27 06:30:17 -0700234 typedef GrPendingProgramElement<const GrFragmentProcessor> PendingFragmentProcessor;
235 typedef SkAutoSTArray<8, PendingFragmentProcessor> FragmentProcessorArray;
egdaniel378092f2014-12-03 10:40:13 -0800236 typedef GrPendingProgramElement<const GrXferProcessor> ProgramXferProcessor;
bsalomonae59b772014-11-19 08:23:49 -0800237 RenderTarget fRenderTarget;
bsalomon3e791242014-12-17 13:43:13 -0800238 GrScissorState fScissorState;
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700239 GrWindowRectsState fWindowRectsState;
csmartdaltonc633abb2016-11-01 08:55:55 -0700240 const GrUserStencilSettings* fUserStencilSettings;
Brian Salomon189098e72017-01-19 09:55:19 -0500241 uint16_t fDrawFace;
242 uint16_t fFlags;
egdaniel378092f2014-12-03 10:40:13 -0800243 ProgramXferProcessor fXferProcessor;
bsalomonac856c92015-08-27 06:30:17 -0700244 FragmentProcessorArray fFragmentProcessors;
egdanield9aa2182014-10-09 13:47:05 -0700245
bsalomonac856c92015-08-27 06:30:17 -0700246 // This value is also the index in fFragmentProcessors where coverage processors begin.
247 int fNumColorProcessors;
egdaniel89af44a2014-09-26 06:15:04 -0700248
egdaniel89af44a2014-09-26 06:15:04 -0700249 typedef SkRefCnt INHERITED;
egdaniel3658f382014-09-15 07:01:59 -0700250};
251
252#endif