• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 Google LLC
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 
8 #ifndef GrProgramInfo_DEFINED
9 #define GrProgramInfo_DEFINED
10 
11 #include "include/gpu/GrTypes.h"
12 #include "src/gpu/GrPipeline.h"
13 #include "src/gpu/GrPrimitiveProcessor.h"
14 
15 class GrMesh;
16 class GrStencilSettings;
17 
18 class GrProgramInfo {
19 public:
20     GrProgramInfo(int numSamples,
21                   int numStencilSamples,
22                   const GrBackendFormat& backendFormat,
23                   GrSurfaceOrigin origin,
24                   const GrPipeline* pipeline,
25                   const GrPrimitiveProcessor* primProc,
26                   const GrPipeline::FixedDynamicState* fixedDynamicState,
27                   const GrPipeline::DynamicStateArrays* dynamicStateArrays,
28                   int numDynamicStateArrays,
29                   GrPrimitiveType primitiveType,
30                   uint8_t tessellationPatchVertexCount = 0)
31             : fNumRasterSamples(pipeline->isStencilEnabled() ? numStencilSamples : numSamples)
32             , fIsMixedSampled(fNumRasterSamples > numSamples)
33             , fBackendFormat(backendFormat)
34             , fOrigin(origin)
35             , fPipeline(pipeline)
36             , fPrimProc(primProc)
37             , fFixedDynamicState(fixedDynamicState)
38             , fDynamicStateArrays(dynamicStateArrays)
39             , fNumDynamicStateArrays(numDynamicStateArrays)
40             , fPrimitiveType(primitiveType)
41             , fTessellationPatchVertexCount(tessellationPatchVertexCount) {
42         SkASSERT(fNumRasterSamples > 0);
43         SkASSERT((GrPrimitiveType::kPatches == fPrimitiveType) ==
44                  (fTessellationPatchVertexCount > 0));
45         fRequestedFeatures = fPrimProc->requestedFeatures();
46         for (int i = 0; i < fPipeline->numFragmentProcessors(); ++i) {
47             fRequestedFeatures |= fPipeline->getFragmentProcessor(i).requestedFeatures();
48         }
49         fRequestedFeatures |= fPipeline->getXferProcessor().requestedFeatures();
50 
51         SkDEBUGCODE(this->validate(false);)
52         (void) fNumDynamicStateArrays;  // touch this to quiet unused member warnings
53     }
54 
requestedFeatures()55     GrProcessor::CustomFeatures requestedFeatures() const { return fRequestedFeatures; }
56 
numRasterSamples()57     int numRasterSamples() const { return fNumRasterSamples;  }
isMixedSampled()58     bool isMixedSampled() const { return fIsMixedSampled; }
59     // The backend format of the destination render target [proxy]
backendFormat()60     const GrBackendFormat& backendFormat() const { return fBackendFormat; }
origin()61     GrSurfaceOrigin origin() const { return fOrigin;  }
pipeline()62     const GrPipeline& pipeline() const { return *fPipeline; }
primProc()63     const GrPrimitiveProcessor& primProc() const { return *fPrimProc; }
fixedDynamicState()64     const GrPipeline::FixedDynamicState* fixedDynamicState() const { return fFixedDynamicState; }
numDynamicStateArrays()65     int numDynamicStateArrays() const { return fNumDynamicStateArrays; }
66 
hasDynamicScissors()67     bool hasDynamicScissors() const {
68         return fPipeline->isScissorEnabled() &&
69                fDynamicStateArrays && fDynamicStateArrays->fScissorRects;
70     }
71 
dynamicScissor(int i)72     const SkIRect& dynamicScissor(int i) const {
73         SkASSERT(this->hasDynamicScissors());
74 
75         return fDynamicStateArrays->fScissorRects[i];
76     }
77 
hasFixedScissor()78     bool hasFixedScissor() const { return fPipeline->isScissorEnabled() && fFixedDynamicState; }
79 
fixedScissor()80     const SkIRect& fixedScissor() const {
81         SkASSERT(this->hasFixedScissor());
82 
83         return fFixedDynamicState->fScissorRect;
84     }
85 
hasDynamicPrimProcTextures()86     bool hasDynamicPrimProcTextures() const {
87         return fDynamicStateArrays && fDynamicStateArrays->fPrimitiveProcessorTextures;
88     }
89 
dynamicPrimProcTextures(int i)90     const GrSurfaceProxy* const* dynamicPrimProcTextures(int i) const {
91         SkASSERT(this->hasDynamicPrimProcTextures());
92         SkASSERT(i < fNumDynamicStateArrays);
93 
94         return fDynamicStateArrays->fPrimitiveProcessorTextures +
95                                                                 i * fPrimProc->numTextureSamplers();
96     }
97 
hasFixedPrimProcTextures()98     bool hasFixedPrimProcTextures() const {
99         return fFixedDynamicState && fFixedDynamicState->fPrimitiveProcessorTextures;
100     }
101 
fixedPrimProcTextures()102     const GrSurfaceProxy* const* fixedPrimProcTextures() const {
103         SkASSERT(this->hasFixedPrimProcTextures());
104 
105         return fFixedDynamicState->fPrimitiveProcessorTextures;
106     }
107 
primitiveType()108     GrPrimitiveType primitiveType() const { return fPrimitiveType; }
tessellationPatchVertexCount()109     uint8_t tessellationPatchVertexCount() const {
110         SkASSERT(GrPrimitiveType::kPatches == fPrimitiveType);
111         return fTessellationPatchVertexCount;
112     }
113 
primitiveTypeKey()114     uint16_t primitiveTypeKey() const {
115         return ((uint16_t)fPrimitiveType << 8) | fTessellationPatchVertexCount;
116     }
117 
118     // For Dawn, Metal and Vulkan the number of stencil bits is known a priori so we can
119     // create the stencil settings here.
120     GrStencilSettings nonGLStencilSettings() const;
121 
visitProxies(const GrOp::VisitProxyFunc & fn)122     void visitProxies(const GrOp::VisitProxyFunc& fn) const {
123         fPipeline->visitProxies(fn);
124     }
125 
126 #ifdef SK_DEBUG
127     void validate(bool flushTime) const;
128     void checkAllInstantiated() const;
129     void checkMSAAAndMIPSAreResolved() const;
130 
isNVPR()131     bool isNVPR() const {
132         return fPrimProc->isPathRendering() && !fPrimProc->willUseGeoShader() &&
133                !fPrimProc->numVertexAttributes() && !fPrimProc->numInstanceAttributes();
134     }
135 #endif
136 
137 private:
138     const int                             fNumRasterSamples;
139     const bool                            fIsMixedSampled;
140     const GrBackendFormat                 fBackendFormat;
141     const GrSurfaceOrigin                 fOrigin;
142     const GrPipeline*                     fPipeline;
143     const GrPrimitiveProcessor*           fPrimProc;
144     const GrPipeline::FixedDynamicState*  fFixedDynamicState;
145     const GrPipeline::DynamicStateArrays* fDynamicStateArrays;
146     const int                             fNumDynamicStateArrays;
147     GrProcessor::CustomFeatures           fRequestedFeatures;
148     GrPrimitiveType                       fPrimitiveType;
149     uint8_t                               fTessellationPatchVertexCount;  // GrPrimType::kPatches.
150 };
151 
152 #endif
153