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