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