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