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