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" |
egdaniel | b109ac2 | 2014-10-07 06:45:44 -0700 | [diff] [blame] | 13 | #include "GrGpu.h" |
joshualitt | dbe1e6f | 2015-07-16 08:12:45 -0700 | [diff] [blame] | 14 | #include "GrNonAtomicRef.h" |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 15 | #include "GrPendingProgramElement.h" |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 16 | #include "GrPrimitiveProcessor.h" |
robertphillips | 28a838e | 2016-06-23 14:07:00 -0700 | [diff] [blame] | 17 | #include "GrProcOptInfo.h" |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 18 | #include "GrProgramDesc.h" |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 19 | #include "GrStencilSettings.h" |
egdaniel | b109ac2 | 2014-10-07 06:45:44 -0700 | [diff] [blame] | 20 | #include "GrTypesPriv.h" |
| 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 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 29 | class GrBatch; |
robertphillips | 55fdccc | 2016-06-06 06:16:20 -0700 | [diff] [blame] | 30 | class GrDrawContext; |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 31 | class GrDeviceCoordTexture; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 32 | class GrPipelineBuilder; |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 33 | |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 34 | struct GrBatchToXPOverrides { |
ethannicholas | 3b7af78 | 2016-02-01 11:45:45 -0800 | [diff] [blame] | 35 | GrBatchToXPOverrides() |
| 36 | : fUsePLSDstRead(false) {} |
| 37 | |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 38 | bool fUsePLSDstRead; |
| 39 | }; |
| 40 | |
| 41 | struct GrPipelineOptimizations { |
| 42 | GrProcOptInfo fColorPOI; |
| 43 | GrProcOptInfo fCoveragePOI; |
| 44 | GrBatchToXPOverrides fOverrides; |
| 45 | }; |
| 46 | |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 47 | /** |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 48 | * Class that holds an optimized version of a GrPipelineBuilder. It is meant to be an immutable |
| 49 | * 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] | 50 | */ |
cdalton | 4833f39 | 2016-02-02 22:46:16 -0800 | [diff] [blame] | 51 | class GrPipeline : public GrNonAtomicRef<GrPipeline> { |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 52 | public: |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 53 | /////////////////////////////////////////////////////////////////////////// |
| 54 | /// @name Creation |
| 55 | |
bsalomon | a387a11 | 2015-08-11 14:47:42 -0700 | [diff] [blame] | 56 | struct CreateArgs { |
| 57 | const GrPipelineBuilder* fPipelineBuilder; |
robertphillips | 55fdccc | 2016-06-06 06:16:20 -0700 | [diff] [blame] | 58 | GrDrawContext* fDrawContext; |
bsalomon | a387a11 | 2015-08-11 14:47:42 -0700 | [diff] [blame] | 59 | const GrCaps* fCaps; |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 60 | GrPipelineOptimizations fOpts; |
cdalton | d472792 | 2015-11-10 12:49:06 -0800 | [diff] [blame] | 61 | const GrScissorState* fScissor; |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 62 | bool fHasStencilClip; |
bsalomon | a387a11 | 2015-08-11 14:47:42 -0700 | [diff] [blame] | 63 | GrXferProcessor::DstTexture fDstTexture; |
| 64 | }; |
| 65 | |
bsalomon | 47dfc36 | 2015-08-10 08:23:11 -0700 | [diff] [blame] | 66 | /** Creates a pipeline into a pre-allocated buffer */ |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 67 | static GrPipeline* CreateAt(void* memory, const CreateArgs&, GrXPOverridesForBatch*); |
egdaniel | b109ac2 | 2014-10-07 06:45:44 -0700 | [diff] [blame] | 68 | |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 69 | /// @} |
| 70 | |
| 71 | /////////////////////////////////////////////////////////////////////////// |
| 72 | /// @name Comparisons |
| 73 | |
| 74 | /** |
joshualitt | 2fe7923 | 2015-08-05 12:02:27 -0700 | [diff] [blame] | 75 | * Returns true if these pipelines are equivalent. Coord transforms may be applied either on |
| 76 | * the GPU or the CPU. When we apply them on the CPU then the matrices need not agree in order |
| 77 | * to combine draws. Therefore we take a param that indicates whether coord transforms should be |
| 78 | * compared." |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 79 | */ |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 80 | static bool AreEqual(const GrPipeline& a, const GrPipeline& b, bool ignoreCoordTransforms); |
| 81 | |
| 82 | /** |
| 83 | * Allows a GrBatch subclass to determine whether two GrBatches can combine. This is a stricter |
| 84 | * test than isEqual because it also considers blend barriers when the two batches' bounds |
| 85 | * overlap |
| 86 | */ |
| 87 | static bool CanCombine(const GrPipeline& a, const SkRect& aBounds, |
| 88 | const GrPipeline& b, const SkRect& bBounds, |
| 89 | const GrCaps& caps, |
| 90 | bool ignoreCoordTransforms = false) { |
| 91 | if (!AreEqual(a, b, ignoreCoordTransforms)) { |
| 92 | return false; |
| 93 | } |
| 94 | if (a.xferBarrierType(caps)) { |
| 95 | return aBounds.fRight <= bBounds.fLeft || |
| 96 | aBounds.fBottom <= bBounds.fTop || |
| 97 | bBounds.fRight <= aBounds.fLeft || |
| 98 | bBounds.fBottom <= aBounds.fTop; |
| 99 | } |
| 100 | return true; |
| 101 | } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 102 | |
| 103 | /// @} |
| 104 | |
| 105 | /////////////////////////////////////////////////////////////////////////// |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 106 | /// @name GrFragmentProcessors |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 107 | |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 108 | // Make the renderTarget's drawTarget (if it exists) be dependent on any |
| 109 | // drawTargets in this pipeline |
| 110 | void addDependenciesTo(GrRenderTarget* rt) const; |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 111 | |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 112 | int numColorFragmentProcessors() const { return fNumColorProcessors; } |
| 113 | int numCoverageFragmentProcessors() const { |
| 114 | return fFragmentProcessors.count() - fNumColorProcessors; |
| 115 | } |
| 116 | int numFragmentProcessors() const { return fFragmentProcessors.count(); } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 117 | |
bsalomon | 2047b78 | 2015-12-21 13:12:54 -0800 | [diff] [blame] | 118 | const GrXferProcessor& getXferProcessor() const { |
| 119 | if (fXferProcessor.get()) { |
| 120 | return *fXferProcessor.get(); |
| 121 | } else { |
| 122 | // A null xp member means the common src-over case. GrXferProcessor's ref'ing |
| 123 | // mechanism is not thread safe so we do not hold a ref on this global. |
| 124 | return GrPorterDuffXPFactory::SimpleSrcOverXP(); |
| 125 | } |
| 126 | } |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 127 | |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 128 | const GrFragmentProcessor& getColorFragmentProcessor(int idx) const { |
| 129 | SkASSERT(idx < this->numColorFragmentProcessors()); |
| 130 | return *fFragmentProcessors[idx].get(); |
egdaniel | d9aa218 | 2014-10-09 13:47:05 -0700 | [diff] [blame] | 131 | } |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 132 | |
| 133 | const GrFragmentProcessor& getCoverageFragmentProcessor(int idx) const { |
| 134 | SkASSERT(idx < this->numCoverageFragmentProcessors()); |
| 135 | return *fFragmentProcessors[fNumColorProcessors + idx].get(); |
egdaniel | d9aa218 | 2014-10-09 13:47:05 -0700 | [diff] [blame] | 136 | } |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 137 | |
| 138 | const GrFragmentProcessor& getFragmentProcessor(int idx) const { |
| 139 | return *fFragmentProcessors[idx].get(); |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 140 | } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 141 | |
| 142 | /// @} |
| 143 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 144 | /** |
| 145 | * Retrieves the currently set render-target. |
| 146 | * |
| 147 | * @return The currently set render target. |
| 148 | */ |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 149 | GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 150 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 151 | const GrStencilSettings& getStencil() const { return fStencilSettings; } |
| 152 | |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 153 | const GrScissorState& getScissorState() const { return fScissorState; } |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 154 | |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 155 | bool isHWAntialiasState() const { return SkToBool(fFlags & kHWAA_Flag); } |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 156 | bool snapVerticesToPixelCenters() const { return SkToBool(fFlags & kSnapVertices_Flag); } |
brianosman | 64d094d | 2016-03-25 06:01:59 -0700 | [diff] [blame] | 157 | bool getDisableOutputConversionToSRGB() const { |
| 158 | return SkToBool(fFlags & kDisableOutputConversionToSRGB_Flag); |
| 159 | } |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame] | 160 | bool getAllowSRGBInputs() const { |
| 161 | return SkToBool(fFlags & kAllowSRGBInputs_Flag); |
| 162 | } |
dvonbeck | 9b03e7b | 2016-08-01 11:01:56 -0700 | [diff] [blame] | 163 | bool usesDistanceVectorField() const { |
| 164 | return SkToBool(fFlags & kUsesDistanceVectorField_Flag); |
| 165 | } |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 166 | bool hasStencilClip() const { |
| 167 | return SkToBool(fFlags & kHasStencilClip_Flag); |
| 168 | } |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 169 | |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 170 | GrXferBarrierType xferBarrierType(const GrCaps& caps) const { |
bsalomon | 2047b78 | 2015-12-21 13:12:54 -0800 | [diff] [blame] | 171 | return this->getXferProcessor().xferBarrierType(fRenderTarget.get(), caps); |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 172 | } |
| 173 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 174 | /** |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 175 | * Gets whether the target is drawing clockwise, counterclockwise, |
| 176 | * or both faces. |
| 177 | * @return the current draw face(s). |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 178 | */ |
robertphillips | 5fa7f30 | 2016-07-21 09:21:04 -0700 | [diff] [blame] | 179 | GrDrawFace getDrawFace() const { return fDrawFace; } |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 180 | |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 181 | |
| 182 | /////////////////////////////////////////////////////////////////////////// |
| 183 | |
egdaniel | 56cf6dc | 2015-11-30 10:15:58 -0800 | [diff] [blame] | 184 | bool ignoresCoverage() const { return fIgnoresCoverage; } |
joshualitt | dafa4d0 | 2014-12-04 08:59:10 -0800 | [diff] [blame] | 185 | |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 186 | private: |
bsalomon | c699873 | 2015-08-10 12:01:15 -0700 | [diff] [blame] | 187 | GrPipeline() { /** Initialized in factory function*/ } |
bsalomon | 47dfc36 | 2015-08-10 08:23:11 -0700 | [diff] [blame] | 188 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 189 | /** |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 190 | * Alter the program desc and inputs (attribs and processors) based on the blend optimization. |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame] | 191 | */ |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 192 | void adjustProgramFromOptimizations(const GrPipelineBuilder& ds, |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 193 | GrXferProcessor::OptFlags, |
| 194 | const GrProcOptInfo& colorPOI, |
| 195 | const GrProcOptInfo& coveragePOI, |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 196 | int* firstColorProcessorIdx, |
| 197 | int* firstCoverageProcessorIdx); |
egdaniel | a7dc0a8 | 2014-09-17 08:25:05 -0700 | [diff] [blame] | 198 | |
egdaniel | c064824 | 2014-09-22 13:17:02 -0700 | [diff] [blame] | 199 | /** |
| 200 | * Calculates the primary and secondary output types of the shader. For certain output types |
| 201 | * the function may adjust the blend coefficients. After this function is called the src and dst |
| 202 | * blend coeffs will represent those used by backend API. |
| 203 | */ |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 204 | void setOutputStateInfo(const GrPipelineBuilder& ds, GrXferProcessor::OptFlags, |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 205 | const GrCaps&); |
egdaniel | c064824 | 2014-09-22 13:17:02 -0700 | [diff] [blame] | 206 | |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 207 | enum Flags { |
brianosman | 64d094d | 2016-03-25 06:01:59 -0700 | [diff] [blame] | 208 | kHWAA_Flag = 0x1, |
| 209 | kSnapVertices_Flag = 0x2, |
| 210 | kDisableOutputConversionToSRGB_Flag = 0x4, |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame] | 211 | kAllowSRGBInputs_Flag = 0x8, |
dvonbeck | 9b03e7b | 2016-08-01 11:01:56 -0700 | [diff] [blame] | 212 | kUsesDistanceVectorField_Flag = 0x10, |
| 213 | kHasStencilClip_Flag = 0x20, |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 214 | }; |
| 215 | |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 216 | typedef GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> RenderTarget; |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 217 | typedef GrPendingProgramElement<const GrFragmentProcessor> PendingFragmentProcessor; |
| 218 | typedef SkAutoSTArray<8, PendingFragmentProcessor> FragmentProcessorArray; |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 219 | typedef GrPendingProgramElement<const GrXferProcessor> ProgramXferProcessor; |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 220 | RenderTarget fRenderTarget; |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 221 | GrScissorState fScissorState; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 222 | GrStencilSettings fStencilSettings; |
robertphillips | 5fa7f30 | 2016-07-21 09:21:04 -0700 | [diff] [blame] | 223 | GrDrawFace fDrawFace; |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 224 | uint32_t fFlags; |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 225 | ProgramXferProcessor fXferProcessor; |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 226 | FragmentProcessorArray fFragmentProcessors; |
egdaniel | 56cf6dc | 2015-11-30 10:15:58 -0800 | [diff] [blame] | 227 | bool fIgnoresCoverage; |
egdaniel | d9aa218 | 2014-10-09 13:47:05 -0700 | [diff] [blame] | 228 | |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 229 | // This value is also the index in fFragmentProcessors where coverage processors begin. |
| 230 | int fNumColorProcessors; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 231 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 232 | typedef SkRefCnt INHERITED; |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 233 | }; |
| 234 | |
| 235 | #endif |