blob: 497554bd34e628592f888211ca0b85d7cf4af3b8 [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"
joshualittdbe1e6f2015-07-16 08:12:45 -070013#include "GrNonAtomicRef.h"
joshualitt69684282015-07-13 13:29:13 -070014#include "GrPendingFragmentStage.h"
kkinnunencabe20c2015-06-01 01:37:26 -070015#include "GrPrimitiveProcessor.h"
joshualitt79f8fae2014-10-28 17:59:26 -070016#include "GrProgramDesc.h"
egdanielb109ac22014-10-07 06:45:44 -070017#include "GrStencil.h"
18#include "GrTypesPriv.h"
19#include "SkMatrix.h"
20#include "SkRefCnt.h"
21
joshualitt4d8da812015-01-28 12:53:54 -080022class GrBatch;
joshualitt79f8fae2014-10-28 17:59:26 -070023class GrDeviceCoordTexture;
egdaniel8dd688b2015-01-22 10:16:09 -080024class GrPipelineBuilder;
egdaniel3658f382014-09-15 07:01:59 -070025
egdaniel3658f382014-09-15 07:01:59 -070026/**
egdaniel8dd688b2015-01-22 10:16:09 -080027 * 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.
egdaniel3658f382014-09-15 07:01:59 -070029 */
joshualittdbe1e6f2015-07-16 08:12:45 -070030class GrPipeline : public GrNonAtomicRef {
egdaniel3658f382014-09-15 07:01:59 -070031public:
bsalomon47dfc362015-08-10 08:23:11 -070032 /** Creates a pipeline into a pre-allocated buffer */
33 static GrPipeline* CreateAt(void* memory,
bsalomonc6998732015-08-10 12:01:15 -070034 const GrPipelineBuilder&,
bsalomon47dfc362015-08-10 08:23:11 -070035 const GrProcOptInfo& colorPOI,
36 const GrProcOptInfo& coveragePOI,
bsalomonc6998732015-08-10 12:01:15 -070037 const GrCaps&,
38 const GrScissorState&,
39 const GrXferProcessor::DstTexture*,
40 GrPipelineOptimizations*);
egdanielb109ac22014-10-07 06:45:44 -070041
joshualitt9b989322014-12-15 14:16:27 -080042 /*
joshualitt2fe79232015-08-05 12:02:27 -070043 * 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."
joshualitt9b989322014-12-15 14:16:27 -080047 */
joshualitt2fe79232015-08-05 12:02:27 -070048 bool isEqual(const GrPipeline& that, bool ignoreCoordTransforms = false) const;
egdaniel89af44a2014-09-26 06:15:04 -070049
50 /// @}
51
52 ///////////////////////////////////////////////////////////////////////////
bsalomon6be6f7c2015-02-26 13:05:21 -080053 /// @name GrFragmentProcessors
egdaniel89af44a2014-09-26 06:15:04 -070054
bsalomon6be6f7c2015-02-26 13:05:21 -080055
56 int numColorFragmentStages() const { return fNumColorStages; }
57 int numCoverageFragmentStages() const { return fFragmentStages.count() - fNumColorStages; }
egdanield9aa2182014-10-09 13:47:05 -070058 int numFragmentStages() const { return fFragmentStages.count(); }
egdaniel89af44a2014-09-26 06:15:04 -070059
egdaniel378092f2014-12-03 10:40:13 -080060 const GrXferProcessor* getXferProcessor() const { return fXferProcessor.get(); }
61
bsalomonae59b772014-11-19 08:23:49 -080062 const GrPendingFragmentStage& getColorStage(int idx) const {
bsalomon6be6f7c2015-02-26 13:05:21 -080063 SkASSERT(idx < this->numColorFragmentStages());
egdanield9aa2182014-10-09 13:47:05 -070064 return fFragmentStages[idx];
65 }
bsalomonae59b772014-11-19 08:23:49 -080066 const GrPendingFragmentStage& getCoverageStage(int idx) const {
bsalomon6be6f7c2015-02-26 13:05:21 -080067 SkASSERT(idx < this->numCoverageFragmentStages());
egdanield9aa2182014-10-09 13:47:05 -070068 return fFragmentStages[fNumColorStages + idx];
69 }
bsalomonae59b772014-11-19 08:23:49 -080070 const GrPendingFragmentStage& getFragmentStage(int idx) const {
71 return fFragmentStages[idx];
72 }
egdaniel89af44a2014-09-26 06:15:04 -070073
74 /// @}
75
egdaniel89af44a2014-09-26 06:15:04 -070076 /**
77 * Retrieves the currently set render-target.
78 *
79 * @return The currently set render target.
80 */
bsalomon37dd3312014-11-03 08:47:23 -080081 GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); }
egdaniel89af44a2014-09-26 06:15:04 -070082
egdaniel89af44a2014-09-26 06:15:04 -070083 const GrStencilSettings& getStencil() const { return fStencilSettings; }
84
bsalomon3e791242014-12-17 13:43:13 -080085 const GrScissorState& getScissorState() const { return fScissorState; }
joshualitt54e0c122014-11-19 09:38:51 -080086
bsalomon04ddf892014-11-19 12:36:22 -080087 bool isDitherState() const { return SkToBool(fFlags & kDither_Flag); }
88 bool isHWAntialiasState() const { return SkToBool(fFlags & kHWAA_Flag); }
bsalomond79c5492015-04-27 10:07:04 -070089 bool snapVerticesToPixelCenters() const { return SkToBool(fFlags & kSnapVertices_Flag); }
bsalomon6be6f7c2015-02-26 13:05:21 -080090 // Skip any draws that refer to this pipeline (they should be a no-op).
bsalomonb03c4a32014-11-20 09:56:11 -080091 bool mustSkip() const { return NULL == this->getRenderTarget(); }
bsalomonae59b772014-11-19 08:23:49 -080092
egdaniel89af44a2014-09-26 06:15:04 -070093 /**
bsalomonae59b772014-11-19 08:23:49 -080094 * Gets whether the target is drawing clockwise, counterclockwise,
95 * or both faces.
96 * @return the current draw face(s).
egdaniel89af44a2014-09-26 06:15:04 -070097 */
egdaniel8dd688b2015-01-22 10:16:09 -080098 GrPipelineBuilder::DrawFace getDrawFace() const { return fDrawFace; }
bsalomonae59b772014-11-19 08:23:49 -080099
bsalomonae59b772014-11-19 08:23:49 -0800100
101 ///////////////////////////////////////////////////////////////////////////
102
bsalomon50785a32015-02-06 07:02:37 -0800103 bool readsFragPosition() const { return fReadsFragPosition; }
joshualittdafa4d02014-12-04 08:59:10 -0800104
joshualitt2fe79232015-08-05 12:02:27 -0700105 const SkTArray<const GrCoordTransform*, true>& coordTransforms() const {
106 return fCoordTransforms;
107 }
108
bsalomonae59b772014-11-19 08:23:49 -0800109private:
bsalomonc6998732015-08-10 12:01:15 -0700110 GrPipeline() { /** Initialized in factory function*/ }
bsalomon47dfc362015-08-10 08:23:11 -0700111
egdaniel89af44a2014-09-26 06:15:04 -0700112 /**
bsalomon04ddf892014-11-19 12:36:22 -0800113 * Alter the program desc and inputs (attribs and processors) based on the blend optimization.
egdaniel170f90b2014-09-16 12:54:40 -0700114 */
egdaniel8dd688b2015-01-22 10:16:09 -0800115 void adjustProgramFromOptimizations(const GrPipelineBuilder& ds,
egdaniel95131432014-12-09 11:15:43 -0800116 GrXferProcessor::OptFlags,
117 const GrProcOptInfo& colorPOI,
118 const GrProcOptInfo& coveragePOI,
119 int* firstColorStageIdx,
120 int* firstCoverageStageIdx);
egdaniela7dc0a82014-09-17 08:25:05 -0700121
egdanielc0648242014-09-22 13:17:02 -0700122 /**
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 */
egdaniel8dd688b2015-01-22 10:16:09 -0800127 void setOutputStateInfo(const GrPipelineBuilder& ds, GrXferProcessor::OptFlags,
bsalomon4b91f762015-05-19 09:29:46 -0700128 const GrCaps&);
egdanielc0648242014-09-22 13:17:02 -0700129
bsalomon04ddf892014-11-19 12:36:22 -0800130 enum Flags {
131 kDither_Flag = 0x1,
132 kHWAA_Flag = 0x2,
bsalomond79c5492015-04-27 10:07:04 -0700133 kSnapVertices_Flag = 0x4,
bsalomon04ddf892014-11-19 12:36:22 -0800134 };
135
bsalomonae59b772014-11-19 08:23:49 -0800136 typedef GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> RenderTarget;
137 typedef SkSTArray<8, GrPendingFragmentStage> FragmentStageArray;
egdaniel378092f2014-12-03 10:40:13 -0800138 typedef GrPendingProgramElement<const GrXferProcessor> ProgramXferProcessor;
bsalomonae59b772014-11-19 08:23:49 -0800139 RenderTarget fRenderTarget;
bsalomon3e791242014-12-17 13:43:13 -0800140 GrScissorState fScissorState;
egdaniel89af44a2014-09-26 06:15:04 -0700141 GrStencilSettings fStencilSettings;
joshualitt4d8da812015-01-28 12:53:54 -0800142 GrPipelineBuilder::DrawFace fDrawFace;
bsalomon04ddf892014-11-19 12:36:22 -0800143 uint32_t fFlags;
egdaniel378092f2014-12-03 10:40:13 -0800144 ProgramXferProcessor fXferProcessor;
joshualitta5305a12014-10-10 17:47:00 -0700145 FragmentStageArray fFragmentStages;
bsalomon50785a32015-02-06 07:02:37 -0800146 bool fReadsFragPosition;
egdanield9aa2182014-10-09 13:47:05 -0700147
148 // This function is equivalent to the offset into fFragmentStages where coverage stages begin.
joshualitta5305a12014-10-10 17:47:00 -0700149 int fNumColorStages;
egdaniel89af44a2014-09-26 06:15:04 -0700150
joshualitt2fe79232015-08-05 12:02:27 -0700151 SkSTArray<8, const GrCoordTransform*, true> fCoordTransforms;
joshualitt2fe79232015-08-05 12:02:27 -0700152 GrProgramDesc fDesc;
egdanielc0648242014-09-22 13:17:02 -0700153
egdaniel89af44a2014-09-26 06:15:04 -0700154 typedef SkRefCnt INHERITED;
egdaniel3658f382014-09-15 07:01:59 -0700155};
156
157#endif