blob: 24d0b627951b6fb128bfab83fa45a09b19f75a60 [file] [log] [blame]
egdaniel3658f382014-09-15 07:01:59 -07001/*
egdaniel8dd688b2015-01-22 10:16:09 -08002 * Copyright 2015 Google Inc.
egdaniel3658f382014-09-15 07:01:59 -07003 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
egdaniel8dd688b2015-01-22 10:16:09 -08008#ifndef GrPipeline_DEFINED
9#define GrPipeline_DEFINED
egdaniel3658f382014-09-15 07:01:59 -070010
egdanielb109ac22014-10-07 06:45:44 -070011#include "GrColor.h"
12#include "GrGpu.h"
bsalomonae59b772014-11-19 08:23:49 -080013#include "GrPendingFragmentStage.h"
joshualitt79f8fae2014-10-28 17:59:26 -070014#include "GrProgramDesc.h"
egdanielb109ac22014-10-07 06:45:44 -070015#include "GrStencil.h"
16#include "GrTypesPriv.h"
17#include "SkMatrix.h"
18#include "SkRefCnt.h"
19
joshualitt4d8da812015-01-28 12:53:54 -080020class GrBatch;
joshualitt79f8fae2014-10-28 17:59:26 -070021class GrDeviceCoordTexture;
egdaniel8dd688b2015-01-22 10:16:09 -080022class GrPipelineBuilder;
egdaniel3658f382014-09-15 07:01:59 -070023
egdaniel3658f382014-09-15 07:01:59 -070024/**
egdaniel8dd688b2015-01-22 10:16:09 -080025 * 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.
egdaniel3658f382014-09-15 07:01:59 -070027 */
egdaniel8dd688b2015-01-22 10:16:09 -080028class GrPipeline {
egdaniel3658f382014-09-15 07:01:59 -070029public:
egdaniel8dd688b2015-01-22 10:16:09 -080030 SK_DECLARE_INST_COUNT(GrPipeline)
bsalomonae59b772014-11-19 08:23:49 -080031
joshualitt4d8da812015-01-28 12:53:54 -080032 // TODO get rid of this version of the constructor when we use batch everywhere
egdaniel8dd688b2015-01-22 10:16:09 -080033 GrPipeline(const GrPipelineBuilder& pipelineBuilder, const GrPrimitiveProcessor*,
34 const GrDrawTargetCaps&, const GrScissorState&,
35 const GrDeviceCoordTexture* dstCopy);
egdanielb109ac22014-10-07 06:45:44 -070036
joshualitt4d8da812015-01-28 12:53:54 -080037 GrPipeline(GrBatch*, const GrPipelineBuilder&, const GrDrawTargetCaps&,
38 const GrScissorState&, const GrDeviceCoordTexture* dstCopy);
39
joshualitt9b989322014-12-15 14:16:27 -080040 /*
egdaniel8dd688b2015-01-22 10:16:09 -080041 * Returns true if it is possible to combine the two GrPipelines and it will update 'this'
joshualitt9b989322014-12-15 14:16:27 -080042 * to subsume 'that''s draw.
43 */
egdaniel8dd688b2015-01-22 10:16:09 -080044 bool isEqual(const GrPipeline& that) const;
egdaniel89af44a2014-09-26 06:15:04 -070045
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.
egdaniel89af44a2014-09-26 06:15:04 -070063 ////
64
egdanield9aa2182014-10-09 13:47:05 -070065 int numColorStages() const { return fNumColorStages; }
66 int numCoverageStages() const { return fFragmentStages.count() - fNumColorStages; }
67 int numFragmentStages() const { return fFragmentStages.count(); }
egdaniel89af44a2014-09-26 06:15:04 -070068
egdaniel378092f2014-12-03 10:40:13 -080069 const GrXferProcessor* getXferProcessor() const { return fXferProcessor.get(); }
70
bsalomonae59b772014-11-19 08:23:49 -080071 const GrPendingFragmentStage& getColorStage(int idx) const {
egdanield9aa2182014-10-09 13:47:05 -070072 SkASSERT(idx < this->numColorStages());
73 return fFragmentStages[idx];
74 }
bsalomonae59b772014-11-19 08:23:49 -080075 const GrPendingFragmentStage& getCoverageStage(int idx) const {
egdanield9aa2182014-10-09 13:47:05 -070076 SkASSERT(idx < this->numCoverageStages());
77 return fFragmentStages[fNumColorStages + idx];
78 }
bsalomonae59b772014-11-19 08:23:49 -080079 const GrPendingFragmentStage& getFragmentStage(int idx) const {
80 return fFragmentStages[idx];
81 }
egdaniel89af44a2014-09-26 06:15:04 -070082
83 /// @}
84
85 ///////////////////////////////////////////////////////////////////////////
egdaniel89af44a2014-09-26 06:15:04 -070086 /// @name Render Target
87 ////
88
89 /**
90 * Retrieves the currently set render-target.
91 *
92 * @return The currently set render target.
93 */
bsalomon37dd3312014-11-03 08:47:23 -080094 GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); }
egdaniel89af44a2014-09-26 06:15:04 -070095
96 /// @}
97
98 ///////////////////////////////////////////////////////////////////////////
99 /// @name Stencil
100 ////
101
102 const GrStencilSettings& getStencil() const { return fStencilSettings; }
103
104 /// @}
105
106 ///////////////////////////////////////////////////////////////////////////
joshualitt54e0c122014-11-19 09:38:51 -0800107 /// @name ScissorState
108 ////
109
bsalomon3e791242014-12-17 13:43:13 -0800110 const GrScissorState& getScissorState() const { return fScissorState; }
joshualitt54e0c122014-11-19 09:38:51 -0800111
112 /// @}
113
joshualitt54e0c122014-11-19 09:38:51 -0800114 ///////////////////////////////////////////////////////////////////////////
bsalomon04ddf892014-11-19 12:36:22 -0800115 /// @name Boolean Queries
egdaniel89af44a2014-09-26 06:15:04 -0700116 ////
117
bsalomon04ddf892014-11-19 12:36:22 -0800118 bool isDitherState() const { return SkToBool(fFlags & kDither_Flag); }
119 bool isHWAntialiasState() const { return SkToBool(fFlags & kHWAA_Flag); }
bsalomonb03c4a32014-11-20 09:56:11 -0800120 bool mustSkip() const { return NULL == this->getRenderTarget(); }
bsalomonae59b772014-11-19 08:23:49 -0800121
122 /// @}
123
egdaniel89af44a2014-09-26 06:15:04 -0700124 /**
bsalomonae59b772014-11-19 08:23:49 -0800125 * Gets whether the target is drawing clockwise, counterclockwise,
126 * or both faces.
127 * @return the current draw face(s).
egdaniel89af44a2014-09-26 06:15:04 -0700128 */
egdaniel8dd688b2015-01-22 10:16:09 -0800129 GrPipelineBuilder::DrawFace getDrawFace() const { return fDrawFace; }
bsalomonae59b772014-11-19 08:23:49 -0800130
131 /// @}
132
133 ///////////////////////////////////////////////////////////////////////////
134
joshualitt9176e2c2014-11-20 07:28:52 -0800135 const GrDeviceCoordTexture* getDstCopy() const { return fDstCopy.texture() ? &fDstCopy : NULL; }
bsalomonae59b772014-11-19 08:23:49 -0800136
joshualitt873ad0e2015-01-20 09:08:51 -0800137 const GrProgramDesc::DescInfo& descInfo() const { return fDescInfo; }
joshualittdafa4d02014-12-04 08:59:10 -0800138
joshualitt4d8da812015-01-28 12:53:54 -0800139 const GrPipelineInfo& getInitBatchTracker() const { return fInitBT; }
bsalomonae59b772014-11-19 08:23:49 -0800140
141private:
joshualitt4d8da812015-01-28 12:53:54 -0800142 // 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
egdaniel89af44a2014-09-26 06:15:04 -0700150 /**
bsalomon04ddf892014-11-19 12:36:22 -0800151 * Alter the program desc and inputs (attribs and processors) based on the blend optimization.
egdaniel170f90b2014-09-16 12:54:40 -0700152 */
egdaniel8dd688b2015-01-22 10:16:09 -0800153 void adjustProgramFromOptimizations(const GrPipelineBuilder& ds,
egdaniel95131432014-12-09 11:15:43 -0800154 GrXferProcessor::OptFlags,
155 const GrProcOptInfo& colorPOI,
156 const GrProcOptInfo& coveragePOI,
157 int* firstColorStageIdx,
158 int* firstCoverageStageIdx);
egdaniela7dc0a82014-09-17 08:25:05 -0700159
egdanielc0648242014-09-22 13:17:02 -0700160 /**
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 */
egdaniel8dd688b2015-01-22 10:16:09 -0800165 void setOutputStateInfo(const GrPipelineBuilder& ds, GrXferProcessor::OptFlags,
egdaniel95131432014-12-09 11:15:43 -0800166 const GrDrawTargetCaps&);
egdanielc0648242014-09-22 13:17:02 -0700167
bsalomon04ddf892014-11-19 12:36:22 -0800168 enum Flags {
169 kDither_Flag = 0x1,
170 kHWAA_Flag = 0x2,
bsalomon04ddf892014-11-19 12:36:22 -0800171 };
172
bsalomonae59b772014-11-19 08:23:49 -0800173 typedef GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> RenderTarget;
174 typedef SkSTArray<8, GrPendingFragmentStage> FragmentStageArray;
egdaniel378092f2014-12-03 10:40:13 -0800175 typedef GrPendingProgramElement<const GrXferProcessor> ProgramXferProcessor;
bsalomonae59b772014-11-19 08:23:49 -0800176 RenderTarget fRenderTarget;
bsalomon3e791242014-12-17 13:43:13 -0800177 GrScissorState fScissorState;
egdaniel89af44a2014-09-26 06:15:04 -0700178 GrStencilSettings fStencilSettings;
joshualitt4d8da812015-01-28 12:53:54 -0800179 GrPipelineBuilder::DrawFace fDrawFace;
joshualitt9176e2c2014-11-20 07:28:52 -0800180 GrDeviceCoordTexture fDstCopy;
bsalomon04ddf892014-11-19 12:36:22 -0800181 uint32_t fFlags;
egdaniel378092f2014-12-03 10:40:13 -0800182 ProgramXferProcessor fXferProcessor;
joshualitta5305a12014-10-10 17:47:00 -0700183 FragmentStageArray fFragmentStages;
joshualittdafa4d02014-12-04 08:59:10 -0800184 GrProgramDesc::DescInfo fDescInfo;
joshualitt4d8da812015-01-28 12:53:54 -0800185 GrPipelineInfo fInitBT;
egdanield9aa2182014-10-09 13:47:05 -0700186
187 // This function is equivalent to the offset into fFragmentStages where coverage stages begin.
joshualitta5305a12014-10-10 17:47:00 -0700188 int fNumColorStages;
egdaniel89af44a2014-09-26 06:15:04 -0700189
joshualitt79f8fae2014-10-28 17:59:26 -0700190 GrProgramDesc fDesc;
egdanielc0648242014-09-22 13:17:02 -0700191
egdaniel89af44a2014-09-26 06:15:04 -0700192 typedef SkRefCnt INHERITED;
egdaniel3658f382014-09-15 07:01:59 -0700193};
194
195#endif