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" |
| 12 | #include "GrGpu.h" |
joshualitt | dbe1e6f | 2015-07-16 08:12:45 -0700 | [diff] [blame] | 13 | #include "GrNonAtomicRef.h" |
joshualitt | 6968428 | 2015-07-13 13:29:13 -0700 | [diff] [blame] | 14 | #include "GrPendingFragmentStage.h" |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 15 | #include "GrPrimitiveProcessor.h" |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 16 | #include "GrProgramDesc.h" |
egdaniel | b109ac2 | 2014-10-07 06:45:44 -0700 | [diff] [blame] | 17 | #include "GrStencil.h" |
| 18 | #include "GrTypesPriv.h" |
| 19 | #include "SkMatrix.h" |
| 20 | #include "SkRefCnt.h" |
| 21 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 22 | class GrBatch; |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 23 | class GrDeviceCoordTexture; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 24 | class GrPipelineBuilder; |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 25 | |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 26 | /** |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 27 | * Class that holds an optimized version of a GrPipelineBuilder. It is meant to be an immutable |
| 28 | * 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] | 29 | */ |
joshualitt | dbe1e6f | 2015-07-16 08:12:45 -0700 | [diff] [blame] | 30 | class GrPipeline : public GrNonAtomicRef { |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 31 | public: |
bsalomon | 47dfc36 | 2015-08-10 08:23:11 -0700 | [diff] [blame] | 32 | /** Creates a pipeline into a pre-allocated buffer */ |
| 33 | static GrPipeline* CreateAt(void* memory, |
bsalomon | c699873 | 2015-08-10 12:01:15 -0700 | [diff] [blame^] | 34 | const GrPipelineBuilder&, |
bsalomon | 47dfc36 | 2015-08-10 08:23:11 -0700 | [diff] [blame] | 35 | const GrProcOptInfo& colorPOI, |
| 36 | const GrProcOptInfo& coveragePOI, |
bsalomon | c699873 | 2015-08-10 12:01:15 -0700 | [diff] [blame^] | 37 | const GrCaps&, |
| 38 | const GrScissorState&, |
| 39 | const GrXferProcessor::DstTexture*, |
| 40 | GrPipelineOptimizations*); |
egdaniel | b109ac2 | 2014-10-07 06:45:44 -0700 | [diff] [blame] | 41 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 42 | /* |
joshualitt | 2fe7923 | 2015-08-05 12:02:27 -0700 | [diff] [blame] | 43 | * Returns true if these pipelines are equivalent. Coord transforms may be applied either on |
| 44 | * the GPU or the CPU. When we apply them on the CPU then the matrices need not agree in order |
| 45 | * to combine draws. Therefore we take a param that indicates whether coord transforms should be |
| 46 | * compared." |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 47 | */ |
joshualitt | 2fe7923 | 2015-08-05 12:02:27 -0700 | [diff] [blame] | 48 | bool isEqual(const GrPipeline& that, bool ignoreCoordTransforms = false) const; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 49 | |
| 50 | /// @} |
| 51 | |
| 52 | /////////////////////////////////////////////////////////////////////////// |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 53 | /// @name GrFragmentProcessors |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 54 | |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 55 | |
| 56 | int numColorFragmentStages() const { return fNumColorStages; } |
| 57 | int numCoverageFragmentStages() const { return fFragmentStages.count() - fNumColorStages; } |
egdaniel | d9aa218 | 2014-10-09 13:47:05 -0700 | [diff] [blame] | 58 | int numFragmentStages() const { return fFragmentStages.count(); } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 59 | |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 60 | const GrXferProcessor* getXferProcessor() const { return fXferProcessor.get(); } |
| 61 | |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 62 | const GrPendingFragmentStage& getColorStage(int idx) const { |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 63 | SkASSERT(idx < this->numColorFragmentStages()); |
egdaniel | d9aa218 | 2014-10-09 13:47:05 -0700 | [diff] [blame] | 64 | return fFragmentStages[idx]; |
| 65 | } |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 66 | const GrPendingFragmentStage& getCoverageStage(int idx) const { |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 67 | SkASSERT(idx < this->numCoverageFragmentStages()); |
egdaniel | d9aa218 | 2014-10-09 13:47:05 -0700 | [diff] [blame] | 68 | return fFragmentStages[fNumColorStages + idx]; |
| 69 | } |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 70 | const GrPendingFragmentStage& getFragmentStage(int idx) const { |
| 71 | return fFragmentStages[idx]; |
| 72 | } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 73 | |
| 74 | /// @} |
| 75 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 76 | /** |
| 77 | * Retrieves the currently set render-target. |
| 78 | * |
| 79 | * @return The currently set render target. |
| 80 | */ |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 81 | GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 82 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 83 | const GrStencilSettings& getStencil() const { return fStencilSettings; } |
| 84 | |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 85 | const GrScissorState& getScissorState() const { return fScissorState; } |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 86 | |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 87 | bool isDitherState() const { return SkToBool(fFlags & kDither_Flag); } |
| 88 | bool isHWAntialiasState() const { return SkToBool(fFlags & kHWAA_Flag); } |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 89 | bool snapVerticesToPixelCenters() const { return SkToBool(fFlags & kSnapVertices_Flag); } |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 90 | // Skip any draws that refer to this pipeline (they should be a no-op). |
bsalomon | b03c4a3 | 2014-11-20 09:56:11 -0800 | [diff] [blame] | 91 | bool mustSkip() const { return NULL == this->getRenderTarget(); } |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 92 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 93 | /** |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 94 | * Gets whether the target is drawing clockwise, counterclockwise, |
| 95 | * or both faces. |
| 96 | * @return the current draw face(s). |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 97 | */ |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 98 | GrPipelineBuilder::DrawFace getDrawFace() const { return fDrawFace; } |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 99 | |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 100 | |
| 101 | /////////////////////////////////////////////////////////////////////////// |
| 102 | |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 103 | bool readsFragPosition() const { return fReadsFragPosition; } |
joshualitt | dafa4d0 | 2014-12-04 08:59:10 -0800 | [diff] [blame] | 104 | |
joshualitt | 2fe7923 | 2015-08-05 12:02:27 -0700 | [diff] [blame] | 105 | const SkTArray<const GrCoordTransform*, true>& coordTransforms() const { |
| 106 | return fCoordTransforms; |
| 107 | } |
| 108 | |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 109 | private: |
bsalomon | c699873 | 2015-08-10 12:01:15 -0700 | [diff] [blame^] | 110 | GrPipeline() { /** Initialized in factory function*/ } |
bsalomon | 47dfc36 | 2015-08-10 08:23:11 -0700 | [diff] [blame] | 111 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 112 | /** |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 113 | * 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] | 114 | */ |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 115 | void adjustProgramFromOptimizations(const GrPipelineBuilder& ds, |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 116 | GrXferProcessor::OptFlags, |
| 117 | const GrProcOptInfo& colorPOI, |
| 118 | const GrProcOptInfo& coveragePOI, |
| 119 | int* firstColorStageIdx, |
| 120 | int* firstCoverageStageIdx); |
egdaniel | a7dc0a8 | 2014-09-17 08:25:05 -0700 | [diff] [blame] | 121 | |
egdaniel | c064824 | 2014-09-22 13:17:02 -0700 | [diff] [blame] | 122 | /** |
| 123 | * Calculates the primary and secondary output types of the shader. For certain output types |
| 124 | * the function may adjust the blend coefficients. After this function is called the src and dst |
| 125 | * blend coeffs will represent those used by backend API. |
| 126 | */ |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 127 | void setOutputStateInfo(const GrPipelineBuilder& ds, GrXferProcessor::OptFlags, |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 128 | const GrCaps&); |
egdaniel | c064824 | 2014-09-22 13:17:02 -0700 | [diff] [blame] | 129 | |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 130 | enum Flags { |
| 131 | kDither_Flag = 0x1, |
| 132 | kHWAA_Flag = 0x2, |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 133 | kSnapVertices_Flag = 0x4, |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 134 | }; |
| 135 | |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 136 | typedef GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> RenderTarget; |
| 137 | typedef SkSTArray<8, GrPendingFragmentStage> FragmentStageArray; |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 138 | typedef GrPendingProgramElement<const GrXferProcessor> ProgramXferProcessor; |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 139 | RenderTarget fRenderTarget; |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 140 | GrScissorState fScissorState; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 141 | GrStencilSettings fStencilSettings; |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 142 | GrPipelineBuilder::DrawFace fDrawFace; |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 143 | uint32_t fFlags; |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 144 | ProgramXferProcessor fXferProcessor; |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 145 | FragmentStageArray fFragmentStages; |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 146 | bool fReadsFragPosition; |
egdaniel | d9aa218 | 2014-10-09 13:47:05 -0700 | [diff] [blame] | 147 | |
| 148 | // This function is equivalent to the offset into fFragmentStages where coverage stages begin. |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 149 | int fNumColorStages; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 150 | |
joshualitt | 2fe7923 | 2015-08-05 12:02:27 -0700 | [diff] [blame] | 151 | SkSTArray<8, const GrCoordTransform*, true> fCoordTransforms; |
joshualitt | 2fe7923 | 2015-08-05 12:02:27 -0700 | [diff] [blame] | 152 | GrProgramDesc fDesc; |
egdaniel | c064824 | 2014-09-22 13:17:02 -0700 | [diff] [blame] | 153 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 154 | typedef SkRefCnt INHERITED; |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 155 | }; |
| 156 | |
| 157 | #endif |