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 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame^] | 32 | // TODO get rid of this version of the constructor when we use batch everywhere |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 33 | GrPipeline(const GrPipelineBuilder& pipelineBuilder, const GrPrimitiveProcessor*, |
| 34 | const GrDrawTargetCaps&, const GrScissorState&, |
| 35 | const GrDeviceCoordTexture* dstCopy); |
egdaniel | b109ac2 | 2014-10-07 06:45:44 -0700 | [diff] [blame] | 36 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame^] | 37 | GrPipeline(GrBatch*, const GrPipelineBuilder&, const GrDrawTargetCaps&, |
| 38 | const GrScissorState&, const GrDeviceCoordTexture* dstCopy); |
| 39 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 40 | /* |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 41 | * Returns true if it is possible to combine the two GrPipelines and it will update 'this' |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 42 | * to subsume 'that''s draw. |
| 43 | */ |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 44 | bool isEqual(const GrPipeline& that) const; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 45 | |
| 46 | /// @} |
| 47 | |
| 48 | /////////////////////////////////////////////////////////////////////////// |
| 49 | /// @name Effect Stages |
| 50 | /// Each stage hosts a GrProcessor. The effect produces an output color or coverage in the |
| 51 | /// fragment shader. Its inputs are the output from the previous stage as well as some variables |
| 52 | /// available to it in the fragment and vertex shader (e.g. the vertex position, the dst color, |
| 53 | /// the fragment position, local coordinates). |
| 54 | /// |
| 55 | /// The stages are divided into two sets, color-computing and coverage-computing. The final |
| 56 | /// color stage produces the final pixel color. The coverage-computing stages function exactly |
| 57 | /// as the color-computing but the output of the final coverage stage is treated as a fractional |
| 58 | /// pixel coverage rather than as input to the src/dst color blend step. |
| 59 | /// |
| 60 | /// The input color to the first color-stage is either the constant color or interpolated |
| 61 | /// per-vertex colors. The input to the first coverage stage is either a constant coverage |
| 62 | /// (usually full-coverage) or interpolated per-vertex coverage. |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 63 | //// |
| 64 | |
egdaniel | d9aa218 | 2014-10-09 13:47:05 -0700 | [diff] [blame] | 65 | int numColorStages() const { return fNumColorStages; } |
| 66 | int numCoverageStages() const { return fFragmentStages.count() - fNumColorStages; } |
| 67 | int numFragmentStages() const { return fFragmentStages.count(); } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 68 | |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 69 | const GrXferProcessor* getXferProcessor() const { return fXferProcessor.get(); } |
| 70 | |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 71 | const GrPendingFragmentStage& getColorStage(int idx) const { |
egdaniel | d9aa218 | 2014-10-09 13:47:05 -0700 | [diff] [blame] | 72 | SkASSERT(idx < this->numColorStages()); |
| 73 | return fFragmentStages[idx]; |
| 74 | } |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 75 | const GrPendingFragmentStage& getCoverageStage(int idx) const { |
egdaniel | d9aa218 | 2014-10-09 13:47:05 -0700 | [diff] [blame] | 76 | SkASSERT(idx < this->numCoverageStages()); |
| 77 | return fFragmentStages[fNumColorStages + idx]; |
| 78 | } |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 79 | const GrPendingFragmentStage& getFragmentStage(int idx) const { |
| 80 | return fFragmentStages[idx]; |
| 81 | } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 82 | |
| 83 | /// @} |
| 84 | |
| 85 | /////////////////////////////////////////////////////////////////////////// |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 86 | /// @name Render Target |
| 87 | //// |
| 88 | |
| 89 | /** |
| 90 | * Retrieves the currently set render-target. |
| 91 | * |
| 92 | * @return The currently set render target. |
| 93 | */ |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 94 | GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 95 | |
| 96 | /// @} |
| 97 | |
| 98 | /////////////////////////////////////////////////////////////////////////// |
| 99 | /// @name Stencil |
| 100 | //// |
| 101 | |
| 102 | const GrStencilSettings& getStencil() const { return fStencilSettings; } |
| 103 | |
| 104 | /// @} |
| 105 | |
| 106 | /////////////////////////////////////////////////////////////////////////// |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 107 | /// @name ScissorState |
| 108 | //// |
| 109 | |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 110 | const GrScissorState& getScissorState() const { return fScissorState; } |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 111 | |
| 112 | /// @} |
| 113 | |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 114 | /////////////////////////////////////////////////////////////////////////// |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 115 | /// @name Boolean Queries |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 116 | //// |
| 117 | |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 118 | bool isDitherState() const { return SkToBool(fFlags & kDither_Flag); } |
| 119 | bool isHWAntialiasState() const { return SkToBool(fFlags & kHWAA_Flag); } |
bsalomon | b03c4a3 | 2014-11-20 09:56:11 -0800 | [diff] [blame] | 120 | bool mustSkip() const { return NULL == this->getRenderTarget(); } |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 121 | |
| 122 | /// @} |
| 123 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 124 | /** |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 125 | * Gets whether the target is drawing clockwise, counterclockwise, |
| 126 | * or both faces. |
| 127 | * @return the current draw face(s). |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 128 | */ |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 129 | GrPipelineBuilder::DrawFace getDrawFace() const { return fDrawFace; } |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 130 | |
| 131 | /// @} |
| 132 | |
| 133 | /////////////////////////////////////////////////////////////////////////// |
| 134 | |
joshualitt | 9176e2c | 2014-11-20 07:28:52 -0800 | [diff] [blame] | 135 | const GrDeviceCoordTexture* getDstCopy() const { return fDstCopy.texture() ? &fDstCopy : NULL; } |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 136 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 137 | const GrProgramDesc::DescInfo& descInfo() const { return fDescInfo; } |
joshualitt | dafa4d0 | 2014-12-04 08:59:10 -0800 | [diff] [blame] | 138 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame^] | 139 | const GrPipelineInfo& getInitBatchTracker() const { return fInitBT; } |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 140 | |
| 141 | private: |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame^] | 142 | // TODO we can have one constructor once GrBatch is complete |
| 143 | void internalConstructor(const GrPipelineBuilder&, |
| 144 | const GrProcOptInfo& colorPOI, |
| 145 | const GrProcOptInfo& coveragePOI, |
| 146 | const GrDrawTargetCaps&, |
| 147 | const GrScissorState&, |
| 148 | const GrDeviceCoordTexture* dstCopy); |
| 149 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 150 | /** |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 151 | * 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] | 152 | */ |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 153 | void adjustProgramFromOptimizations(const GrPipelineBuilder& ds, |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 154 | GrXferProcessor::OptFlags, |
| 155 | const GrProcOptInfo& colorPOI, |
| 156 | const GrProcOptInfo& coveragePOI, |
| 157 | int* firstColorStageIdx, |
| 158 | int* firstCoverageStageIdx); |
egdaniel | a7dc0a8 | 2014-09-17 08:25:05 -0700 | [diff] [blame] | 159 | |
egdaniel | c064824 | 2014-09-22 13:17:02 -0700 | [diff] [blame] | 160 | /** |
| 161 | * Calculates the primary and secondary output types of the shader. For certain output types |
| 162 | * the function may adjust the blend coefficients. After this function is called the src and dst |
| 163 | * blend coeffs will represent those used by backend API. |
| 164 | */ |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 165 | void setOutputStateInfo(const GrPipelineBuilder& ds, GrXferProcessor::OptFlags, |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 166 | const GrDrawTargetCaps&); |
egdaniel | c064824 | 2014-09-22 13:17:02 -0700 | [diff] [blame] | 167 | |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 168 | enum Flags { |
| 169 | kDither_Flag = 0x1, |
| 170 | kHWAA_Flag = 0x2, |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 171 | }; |
| 172 | |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 173 | typedef GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> RenderTarget; |
| 174 | typedef SkSTArray<8, GrPendingFragmentStage> FragmentStageArray; |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 175 | typedef GrPendingProgramElement<const GrXferProcessor> ProgramXferProcessor; |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 176 | RenderTarget fRenderTarget; |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 177 | GrScissorState fScissorState; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 178 | GrStencilSettings fStencilSettings; |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame^] | 179 | GrPipelineBuilder::DrawFace fDrawFace; |
joshualitt | 9176e2c | 2014-11-20 07:28:52 -0800 | [diff] [blame] | 180 | GrDeviceCoordTexture fDstCopy; |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 181 | uint32_t fFlags; |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 182 | ProgramXferProcessor fXferProcessor; |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 183 | FragmentStageArray fFragmentStages; |
joshualitt | dafa4d0 | 2014-12-04 08:59:10 -0800 | [diff] [blame] | 184 | GrProgramDesc::DescInfo fDescInfo; |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame^] | 185 | GrPipelineInfo fInitBT; |
egdaniel | d9aa218 | 2014-10-09 13:47:05 -0700 | [diff] [blame] | 186 | |
| 187 | // This function is equivalent to the offset into fFragmentStages where coverage stages begin. |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 188 | int fNumColorStages; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 189 | |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 190 | GrProgramDesc fDesc; |
egdaniel | c064824 | 2014-09-22 13:17:02 -0700 | [diff] [blame] | 191 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 192 | typedef SkRefCnt INHERITED; |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 193 | }; |
| 194 | |
| 195 | #endif |