egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 1 | /* |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 2 | * Copyright 2015 Google Inc. |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 8 | #ifndef GrPipeline_DEFINED |
| 9 | #define GrPipeline_DEFINED |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 10 | |
egdaniel | b109ac2 | 2014-10-07 06:45:44 -0700 | [diff] [blame] | 11 | #include "GrColor.h" |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 12 | #include "GrFragmentProcessor.h" |
joshualitt | dbe1e6f | 2015-07-16 08:12:45 -0700 | [diff] [blame] | 13 | #include "GrNonAtomicRef.h" |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 14 | #include "GrPendingProgramElement.h" |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 15 | #include "GrPrimitiveProcessor.h" |
robertphillips | 28a838e | 2016-06-23 14:07:00 -0700 | [diff] [blame] | 16 | #include "GrProcOptInfo.h" |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 17 | #include "GrProgramDesc.h" |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 18 | #include "GrScissorState.h" |
csmartdalton | c633abb | 2016-11-01 08:55:55 -0700 | [diff] [blame] | 19 | #include "GrUserStencilSettings.h" |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 20 | #include "GrWindowRectsState.h" |
egdaniel | b109ac2 | 2014-10-07 06:45:44 -0700 | [diff] [blame] | 21 | #include "SkMatrix.h" |
| 22 | #include "SkRefCnt.h" |
| 23 | |
robertphillips | 5fa7f30 | 2016-07-21 09:21:04 -0700 | [diff] [blame] | 24 | #include "effects/GrCoverageSetOpXP.h" |
| 25 | #include "effects/GrDisableColorXP.h" |
| 26 | #include "effects/GrPorterDuffXferProcessor.h" |
| 27 | #include "effects/GrSimpleTextureEffect.h" |
| 28 | |
Brian Salomon | 652ecb5 | 2017-01-17 12:39:53 -0500 | [diff] [blame] | 29 | class GrAppliedClip; |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 30 | class GrDeviceCoordTexture; |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 31 | class GrOp; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 32 | class GrPipelineBuilder; |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 33 | class GrRenderTargetContext; |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 34 | |
Brian Salomon | 92aee3d | 2016-12-21 09:20:25 -0500 | [diff] [blame] | 35 | /** |
| 36 | * This Describes aspects of the GrPrimitiveProcessor produced by a GrDrawOp that are used in |
| 37 | * pipeline analysis. |
| 38 | */ |
| 39 | class GrPipelineAnalysisDrawOpInput { |
| 40 | public: |
| 41 | GrPipelineAnalysisDrawOpInput(GrPipelineInput* color, GrPipelineInput* coverage) |
| 42 | : fColorInput(color), fCoverageInput(coverage) {} |
| 43 | GrPipelineInput* pipelineColorInput() { return fColorInput; } |
| 44 | GrPipelineInput* pipelineCoverageInput() { return fCoverageInput; } |
ethannicholas | 3b7af78 | 2016-02-01 11:45:45 -0800 | [diff] [blame] | 45 | |
Brian Salomon | 92aee3d | 2016-12-21 09:20:25 -0500 | [diff] [blame] | 46 | void setUsesPLSDstRead() { fUsesPLSDstRead = true; } |
| 47 | |
| 48 | bool usesPLSDstRead() const { return fUsesPLSDstRead; } |
| 49 | |
| 50 | private: |
| 51 | GrPipelineInput* fColorInput; |
| 52 | GrPipelineInput* fCoverageInput; |
| 53 | bool fUsesPLSDstRead = false; |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 54 | }; |
| 55 | |
Brian Salomon | 92aee3d | 2016-12-21 09:20:25 -0500 | [diff] [blame] | 56 | /** This is used to track pipeline analysis through the color and coverage fragment processors. */ |
| 57 | struct GrPipelineAnalysis { |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 58 | GrProcOptInfo fColorPOI; |
| 59 | GrProcOptInfo fCoveragePOI; |
Brian Salomon | 92aee3d | 2016-12-21 09:20:25 -0500 | [diff] [blame] | 60 | bool fUsesPLSDstRead = false; |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 61 | }; |
| 62 | |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 63 | class GrProcessorSet; |
| 64 | |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 65 | /** |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 66 | * 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. |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 68 | */ |
cdalton | 4833f39 | 2016-02-02 22:46:16 -0800 | [diff] [blame] | 69 | class GrPipeline : public GrNonAtomicRef<GrPipeline> { |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 70 | public: |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 71 | /////////////////////////////////////////////////////////////////////////// |
| 72 | /// @name Creation |
| 73 | |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 74 | 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 Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 86 | }; |
| 87 | |
bsalomon | a387a11 | 2015-08-11 14:47:42 -0700 | [diff] [blame] | 88 | struct CreateArgs { |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 89 | 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 Salomon | 92aee3d | 2016-12-21 09:20:25 -0500 | [diff] [blame] | 96 | GrPipelineAnalysis fAnalysis; |
bsalomon | a387a11 | 2015-08-11 14:47:42 -0700 | [diff] [blame] | 97 | GrXferProcessor::DstTexture fDstTexture; |
| 98 | }; |
| 99 | |
bsalomon | 47dfc36 | 2015-08-10 08:23:11 -0700 | [diff] [blame] | 100 | /** Creates a pipeline into a pre-allocated buffer */ |
Brian Salomon | 92aee3d | 2016-12-21 09:20:25 -0500 | [diff] [blame] | 101 | static GrPipeline* CreateAt(void* memory, const CreateArgs&, GrPipelineOptimizations*); |
egdaniel | b109ac2 | 2014-10-07 06:45:44 -0700 | [diff] [blame] | 102 | |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 103 | /// @} |
| 104 | |
| 105 | /////////////////////////////////////////////////////////////////////////// |
| 106 | /// @name Comparisons |
| 107 | |
| 108 | /** |
joshualitt | 2fe7923 | 2015-08-05 12:02:27 -0700 | [diff] [blame] | 109 | * 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." |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 113 | */ |
bsalomon | 7312ff8 | 2016-09-12 08:55:38 -0700 | [diff] [blame] | 114 | static bool AreEqual(const GrPipeline& a, const GrPipeline& b); |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 115 | |
| 116 | /** |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 117 | * 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 |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 120 | */ |
| 121 | static bool CanCombine(const GrPipeline& a, const SkRect& aBounds, |
| 122 | const GrPipeline& b, const SkRect& bBounds, |
bsalomon | 7312ff8 | 2016-09-12 08:55:38 -0700 | [diff] [blame] | 123 | const GrCaps& caps) { |
| 124 | if (!AreEqual(a, b)) { |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 125 | 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 | } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 135 | |
| 136 | /// @} |
| 137 | |
| 138 | /////////////////////////////////////////////////////////////////////////// |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 139 | /// @name GrFragmentProcessors |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 140 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 141 | // Make the renderTarget's GrOpList (if it exists) be dependent on any |
| 142 | // GrOpLists in this pipeline |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 143 | void addDependenciesTo(GrRenderTarget* rt) const; |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 144 | |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 145 | int numColorFragmentProcessors() const { return fNumColorProcessors; } |
| 146 | int numCoverageFragmentProcessors() const { |
| 147 | return fFragmentProcessors.count() - fNumColorProcessors; |
| 148 | } |
| 149 | int numFragmentProcessors() const { return fFragmentProcessors.count(); } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 150 | |
bsalomon | 2047b78 | 2015-12-21 13:12:54 -0800 | [diff] [blame] | 151 | 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 | } |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 160 | |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 161 | const GrFragmentProcessor& getColorFragmentProcessor(int idx) const { |
| 162 | SkASSERT(idx < this->numColorFragmentProcessors()); |
| 163 | return *fFragmentProcessors[idx].get(); |
egdaniel | d9aa218 | 2014-10-09 13:47:05 -0700 | [diff] [blame] | 164 | } |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 165 | |
| 166 | const GrFragmentProcessor& getCoverageFragmentProcessor(int idx) const { |
| 167 | SkASSERT(idx < this->numCoverageFragmentProcessors()); |
| 168 | return *fFragmentProcessors[fNumColorProcessors + idx].get(); |
egdaniel | d9aa218 | 2014-10-09 13:47:05 -0700 | [diff] [blame] | 169 | } |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 170 | |
| 171 | const GrFragmentProcessor& getFragmentProcessor(int idx) const { |
| 172 | return *fFragmentProcessors[idx].get(); |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 173 | } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 174 | |
| 175 | /// @} |
| 176 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 177 | /** |
| 178 | * Retrieves the currently set render-target. |
| 179 | * |
| 180 | * @return The currently set render target. |
| 181 | */ |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 182 | GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 183 | |
csmartdalton | c633abb | 2016-11-01 08:55:55 -0700 | [diff] [blame] | 184 | const GrUserStencilSettings* getUserStencil() const { return fUserStencilSettings; } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 185 | |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 186 | const GrScissorState& getScissorState() const { return fScissorState; } |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 187 | |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 188 | const GrWindowRectsState& getWindowRectsState() const { return fWindowRectsState; } |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 189 | |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 190 | bool isHWAntialiasState() const { return SkToBool(fFlags & kHWAntialias_Flag); } |
| 191 | bool snapVerticesToPixelCenters() const { |
| 192 | return SkToBool(fFlags & kSnapVerticesToPixelCenters_Flag); |
| 193 | } |
brianosman | 64d094d | 2016-03-25 06:01:59 -0700 | [diff] [blame] | 194 | bool getDisableOutputConversionToSRGB() const { |
| 195 | return SkToBool(fFlags & kDisableOutputConversionToSRGB_Flag); |
| 196 | } |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame] | 197 | bool getAllowSRGBInputs() const { |
| 198 | return SkToBool(fFlags & kAllowSRGBInputs_Flag); |
| 199 | } |
dvonbeck | 9b03e7b | 2016-08-01 11:01:56 -0700 | [diff] [blame] | 200 | bool usesDistanceVectorField() const { |
| 201 | return SkToBool(fFlags & kUsesDistanceVectorField_Flag); |
| 202 | } |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 203 | bool hasStencilClip() const { |
| 204 | return SkToBool(fFlags & kHasStencilClip_Flag); |
| 205 | } |
csmartdalton | c633abb | 2016-11-01 08:55:55 -0700 | [diff] [blame] | 206 | bool isStencilEnabled() const { |
| 207 | return SkToBool(fFlags & kStencilEnabled_Flag); |
| 208 | } |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 209 | |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 210 | GrXferBarrierType xferBarrierType(const GrCaps& caps) const { |
bsalomon | 2047b78 | 2015-12-21 13:12:54 -0800 | [diff] [blame] | 211 | return this->getXferProcessor().xferBarrierType(fRenderTarget.get(), caps); |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 212 | } |
| 213 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 214 | /** |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 215 | * Gets whether the target is drawing clockwise, counterclockwise, |
| 216 | * or both faces. |
| 217 | * @return the current draw face(s). |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 218 | */ |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 219 | GrDrawFace getDrawFace() const { return static_cast<GrDrawFace>(fDrawFace); } |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 220 | |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 221 | private: |
bsalomon | c699873 | 2015-08-10 12:01:15 -0700 | [diff] [blame] | 222 | GrPipeline() { /** Initialized in factory function*/ } |
bsalomon | 47dfc36 | 2015-08-10 08:23:11 -0700 | [diff] [blame] | 223 | |
Brian Salomon | f87e2b9 | 2017-01-19 11:31:50 -0500 | [diff] [blame] | 224 | /** This is a continuation of the public "Flags" enum. */ |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 225 | enum PrivateFlags { |
Brian Salomon | f87e2b9 | 2017-01-19 11:31:50 -0500 | [diff] [blame] | 226 | kDisableOutputConversionToSRGB_Flag = 0x4, |
| 227 | kAllowSRGBInputs_Flag = 0x8, |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 228 | kUsesDistanceVectorField_Flag = 0x10, |
| 229 | kHasStencilClip_Flag = 0x20, |
| 230 | kStencilEnabled_Flag = 0x40, |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 231 | }; |
| 232 | |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 233 | typedef GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> RenderTarget; |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 234 | typedef GrPendingProgramElement<const GrFragmentProcessor> PendingFragmentProcessor; |
| 235 | typedef SkAutoSTArray<8, PendingFragmentProcessor> FragmentProcessorArray; |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 236 | typedef GrPendingProgramElement<const GrXferProcessor> ProgramXferProcessor; |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 237 | RenderTarget fRenderTarget; |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 238 | GrScissorState fScissorState; |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 239 | GrWindowRectsState fWindowRectsState; |
csmartdalton | c633abb | 2016-11-01 08:55:55 -0700 | [diff] [blame] | 240 | const GrUserStencilSettings* fUserStencilSettings; |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 241 | uint16_t fDrawFace; |
| 242 | uint16_t fFlags; |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 243 | ProgramXferProcessor fXferProcessor; |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 244 | FragmentProcessorArray fFragmentProcessors; |
egdaniel | d9aa218 | 2014-10-09 13:47:05 -0700 | [diff] [blame] | 245 | |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 246 | // This value is also the index in fFragmentProcessors where coverage processors begin. |
| 247 | int fNumColorProcessors; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 248 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 249 | typedef SkRefCnt INHERITED; |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 250 | }; |
| 251 | |
| 252 | #endif |