blob: fdba0d764c91a96c8709c31d62e106e772aa970c [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
egdaniele36914c2015-02-13 09:00:33 -080032 GrPipeline(const GrPipelineBuilder&,
33 const GrProcOptInfo& colorPOI,
34 const GrProcOptInfo& coveragePOI,
35 const GrDrawTargetCaps&,
36 const GrScissorState&,
egdaniel8dd688b2015-01-22 10:16:09 -080037 const GrDeviceCoordTexture* dstCopy);
egdanielb109ac22014-10-07 06:45:44 -070038
joshualitt9b989322014-12-15 14:16:27 -080039 /*
bsalomon6be6f7c2015-02-26 13:05:21 -080040 * Returns true if these pipelines are equivalent.
joshualitt9b989322014-12-15 14:16:27 -080041 */
egdaniel8dd688b2015-01-22 10:16:09 -080042 bool isEqual(const GrPipeline& that) const;
egdaniel89af44a2014-09-26 06:15:04 -070043
44 /// @}
45
46 ///////////////////////////////////////////////////////////////////////////
bsalomon6be6f7c2015-02-26 13:05:21 -080047 /// @name GrFragmentProcessors
egdaniel89af44a2014-09-26 06:15:04 -070048
bsalomon6be6f7c2015-02-26 13:05:21 -080049
50 int numColorFragmentStages() const { return fNumColorStages; }
51 int numCoverageFragmentStages() const { return fFragmentStages.count() - fNumColorStages; }
egdanield9aa2182014-10-09 13:47:05 -070052 int numFragmentStages() const { return fFragmentStages.count(); }
egdaniel89af44a2014-09-26 06:15:04 -070053
egdaniel378092f2014-12-03 10:40:13 -080054 const GrXferProcessor* getXferProcessor() const { return fXferProcessor.get(); }
55
bsalomonae59b772014-11-19 08:23:49 -080056 const GrPendingFragmentStage& getColorStage(int idx) const {
bsalomon6be6f7c2015-02-26 13:05:21 -080057 SkASSERT(idx < this->numColorFragmentStages());
egdanield9aa2182014-10-09 13:47:05 -070058 return fFragmentStages[idx];
59 }
bsalomonae59b772014-11-19 08:23:49 -080060 const GrPendingFragmentStage& getCoverageStage(int idx) const {
bsalomon6be6f7c2015-02-26 13:05:21 -080061 SkASSERT(idx < this->numCoverageFragmentStages());
egdanield9aa2182014-10-09 13:47:05 -070062 return fFragmentStages[fNumColorStages + idx];
63 }
bsalomonae59b772014-11-19 08:23:49 -080064 const GrPendingFragmentStage& getFragmentStage(int idx) const {
65 return fFragmentStages[idx];
66 }
egdaniel89af44a2014-09-26 06:15:04 -070067
68 /// @}
69
egdaniel89af44a2014-09-26 06:15:04 -070070 /**
71 * Retrieves the currently set render-target.
72 *
73 * @return The currently set render target.
74 */
bsalomon37dd3312014-11-03 08:47:23 -080075 GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); }
egdaniel89af44a2014-09-26 06:15:04 -070076
egdaniel89af44a2014-09-26 06:15:04 -070077 const GrStencilSettings& getStencil() const { return fStencilSettings; }
78
bsalomon3e791242014-12-17 13:43:13 -080079 const GrScissorState& getScissorState() const { return fScissorState; }
joshualitt54e0c122014-11-19 09:38:51 -080080
bsalomon04ddf892014-11-19 12:36:22 -080081 bool isDitherState() const { return SkToBool(fFlags & kDither_Flag); }
82 bool isHWAntialiasState() const { return SkToBool(fFlags & kHWAA_Flag); }
bsalomond79c5492015-04-27 10:07:04 -070083 bool snapVerticesToPixelCenters() const { return SkToBool(fFlags & kSnapVertices_Flag); }
bsalomon6be6f7c2015-02-26 13:05:21 -080084 // Skip any draws that refer to this pipeline (they should be a no-op).
bsalomonb03c4a32014-11-20 09:56:11 -080085 bool mustSkip() const { return NULL == this->getRenderTarget(); }
bsalomonae59b772014-11-19 08:23:49 -080086
egdaniel89af44a2014-09-26 06:15:04 -070087 /**
bsalomonae59b772014-11-19 08:23:49 -080088 * Gets whether the target is drawing clockwise, counterclockwise,
89 * or both faces.
90 * @return the current draw face(s).
egdaniel89af44a2014-09-26 06:15:04 -070091 */
egdaniel8dd688b2015-01-22 10:16:09 -080092 GrPipelineBuilder::DrawFace getDrawFace() const { return fDrawFace; }
bsalomonae59b772014-11-19 08:23:49 -080093
bsalomonae59b772014-11-19 08:23:49 -080094
95 ///////////////////////////////////////////////////////////////////////////
96
bsalomon50785a32015-02-06 07:02:37 -080097 bool readsFragPosition() const { return fReadsFragPosition; }
joshualittdafa4d02014-12-04 08:59:10 -080098
joshualitt4d8da812015-01-28 12:53:54 -080099 const GrPipelineInfo& getInitBatchTracker() const { return fInitBT; }
bsalomonae59b772014-11-19 08:23:49 -0800100
101private:
egdaniel89af44a2014-09-26 06:15:04 -0700102 /**
bsalomon04ddf892014-11-19 12:36:22 -0800103 * Alter the program desc and inputs (attribs and processors) based on the blend optimization.
egdaniel170f90b2014-09-16 12:54:40 -0700104 */
egdaniel8dd688b2015-01-22 10:16:09 -0800105 void adjustProgramFromOptimizations(const GrPipelineBuilder& ds,
egdaniel95131432014-12-09 11:15:43 -0800106 GrXferProcessor::OptFlags,
107 const GrProcOptInfo& colorPOI,
108 const GrProcOptInfo& coveragePOI,
109 int* firstColorStageIdx,
110 int* firstCoverageStageIdx);
egdaniela7dc0a82014-09-17 08:25:05 -0700111
egdanielc0648242014-09-22 13:17:02 -0700112 /**
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 */
egdaniel8dd688b2015-01-22 10:16:09 -0800117 void setOutputStateInfo(const GrPipelineBuilder& ds, GrXferProcessor::OptFlags,
egdaniel95131432014-12-09 11:15:43 -0800118 const GrDrawTargetCaps&);
egdanielc0648242014-09-22 13:17:02 -0700119
bsalomon04ddf892014-11-19 12:36:22 -0800120 enum Flags {
121 kDither_Flag = 0x1,
122 kHWAA_Flag = 0x2,
bsalomond79c5492015-04-27 10:07:04 -0700123 kSnapVertices_Flag = 0x4,
bsalomon04ddf892014-11-19 12:36:22 -0800124 };
125
bsalomonae59b772014-11-19 08:23:49 -0800126 typedef GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> RenderTarget;
127 typedef SkSTArray<8, GrPendingFragmentStage> FragmentStageArray;
egdaniel378092f2014-12-03 10:40:13 -0800128 typedef GrPendingProgramElement<const GrXferProcessor> ProgramXferProcessor;
bsalomonae59b772014-11-19 08:23:49 -0800129 RenderTarget fRenderTarget;
bsalomon3e791242014-12-17 13:43:13 -0800130 GrScissorState fScissorState;
egdaniel89af44a2014-09-26 06:15:04 -0700131 GrStencilSettings fStencilSettings;
joshualitt4d8da812015-01-28 12:53:54 -0800132 GrPipelineBuilder::DrawFace fDrawFace;
bsalomon04ddf892014-11-19 12:36:22 -0800133 uint32_t fFlags;
egdaniel378092f2014-12-03 10:40:13 -0800134 ProgramXferProcessor fXferProcessor;
joshualitta5305a12014-10-10 17:47:00 -0700135 FragmentStageArray fFragmentStages;
bsalomon50785a32015-02-06 07:02:37 -0800136 bool fReadsFragPosition;
joshualitt4d8da812015-01-28 12:53:54 -0800137 GrPipelineInfo fInitBT;
egdanield9aa2182014-10-09 13:47:05 -0700138
139 // This function is equivalent to the offset into fFragmentStages where coverage stages begin.
joshualitta5305a12014-10-10 17:47:00 -0700140 int fNumColorStages;
egdaniel89af44a2014-09-26 06:15:04 -0700141
joshualitt79f8fae2014-10-28 17:59:26 -0700142 GrProgramDesc fDesc;
egdanielc0648242014-09-22 13:17:02 -0700143
egdaniel89af44a2014-09-26 06:15:04 -0700144 typedef SkRefCnt INHERITED;
egdaniel3658f382014-09-15 07:01:59 -0700145};
146
147#endif