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