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