• 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/GrGeometryProcessor.h"
13 #include "src/gpu/GrPipeline.h"
14 
15 class GrStencilSettings;
16 
17 class GrProgramInfo {
18 public:
GrProgramInfo(const GrSurfaceProxyView & targetView,const GrPipeline * pipeline,const GrUserStencilSettings * userStencilSettings,const GrGeometryProcessor * geomProc,GrPrimitiveType primitiveType,uint8_t tessellationPatchVertexCount,GrXferBarrierFlags renderPassXferBarriers,GrLoadOp colorLoadOp)19     GrProgramInfo(const GrSurfaceProxyView& targetView,
20                   const GrPipeline* pipeline,
21                   const GrUserStencilSettings* userStencilSettings,
22                   const GrGeometryProcessor* geomProc,
23                   GrPrimitiveType primitiveType,
24                   uint8_t tessellationPatchVertexCount,
25                   GrXferBarrierFlags renderPassXferBarriers,
26                   GrLoadOp colorLoadOp)
27             : fNumSamples(targetView.asRenderTargetProxy()->numSamples())
28             , fNeedsStencil(targetView.asRenderTargetProxy()->needsStencil())
29             , fBackendFormat(targetView.proxy()->backendFormat())
30             , fOrigin(targetView.origin())
31             , fTargetSupportsVkResolveLoad(
32                       targetView.asRenderTargetProxy()->numSamples() > 1 &&
33                       targetView.asTextureProxy() &&
34                       targetView.asRenderTargetProxy()->supportsVkInputAttachment())
35             , fPipeline(pipeline)
36             , fUserStencilSettings(userStencilSettings)
37             , fGeomProc(geomProc)
38             , fPrimitiveType(primitiveType)
39             , fTessellationPatchVertexCount(tessellationPatchVertexCount)
40             , fRenderPassXferBarriers(renderPassXferBarriers)
41             , fColorLoadOp(colorLoadOp) {
42         SkASSERT(this->numSamples() > 0);
43         SkASSERT((GrPrimitiveType::kPatches == fPrimitiveType) ==
44                  (fTessellationPatchVertexCount > 0));
45         fRequestedFeatures = fGeomProc->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     }
53 
requestedFeatures()54     GrProcessor::CustomFeatures requestedFeatures() const { return fRequestedFeatures; }
55 
numSamples()56     int numSamples() const { return fNumSamples; }
needsStencil()57     int needsStencil() const { return fNeedsStencil; }
isStencilEnabled()58     bool isStencilEnabled() const {
59         return fUserStencilSettings != &GrUserStencilSettings::kUnused ||
60                fPipeline->hasStencilClip();
61     }
userStencilSettings()62     const GrUserStencilSettings* userStencilSettings() const { return fUserStencilSettings; }
63     // The backend format of the destination render target [proxy]
backendFormat()64     const GrBackendFormat& backendFormat() const { return fBackendFormat; }
origin()65     GrSurfaceOrigin origin() const { return fOrigin;  }
pipeline()66     const GrPipeline& pipeline() const { return *fPipeline; }
geomProc()67     const GrGeometryProcessor& geomProc() const { return *fGeomProc; }
68 
primitiveType()69     GrPrimitiveType primitiveType() const { return fPrimitiveType; }
tessellationPatchVertexCount()70     uint8_t tessellationPatchVertexCount() const {
71         SkASSERT(GrPrimitiveType::kPatches == fPrimitiveType);
72         return fTessellationPatchVertexCount;
73     }
74 
targetSupportsVkResolveLoad()75     bool targetSupportsVkResolveLoad() const { return fTargetSupportsVkResolveLoad; }
76 
renderPassBarriers()77     GrXferBarrierFlags renderPassBarriers() const { return fRenderPassXferBarriers; }
78 
colorLoadOp()79     GrLoadOp colorLoadOp() const { return fColorLoadOp; }
80 
primitiveTypeKey()81     uint16_t primitiveTypeKey() const {
82         return ((uint16_t)fPrimitiveType << 8) | fTessellationPatchVertexCount;
83     }
84 
85     // For Dawn, Metal and Vulkan the number of stencil bits is known a priori so we can
86     // create the stencil settings here.
87     GrStencilSettings nonGLStencilSettings() const;
88 
89     // Invokes the visitor function on all FP proxies in the pipeline. The caller is responsible
90     // to call the visitor on its own primProc proxies.
visitFPProxies(const GrOp::VisitProxyFunc & func)91     void visitFPProxies(const GrOp::VisitProxyFunc& func) const { fPipeline->visitProxies(func); }
92 
93 #ifdef SK_DEBUG
94     void validate(bool flushTime) const;
95     void checkAllInstantiated() const;
96     void checkMSAAAndMIPSAreResolved() const;
97 #endif
98 
99 private:
100     const int                             fNumSamples;
101     const bool                            fNeedsStencil;
102     const GrBackendFormat                 fBackendFormat;
103     const GrSurfaceOrigin                 fOrigin;
104     const bool                            fTargetSupportsVkResolveLoad;
105     const GrPipeline*                     fPipeline;
106     const GrUserStencilSettings*          fUserStencilSettings;
107     const GrGeometryProcessor*            fGeomProc;
108     GrProcessor::CustomFeatures           fRequestedFeatures;
109     GrPrimitiveType                       fPrimitiveType;
110     uint8_t                               fTessellationPatchVertexCount;  // GrPrimType::kPatches.
111     GrXferBarrierFlags                    fRenderPassXferBarriers;
112     GrLoadOp                              fColorLoadOp;
113 };
114 
115 #endif
116