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
15class GrStencilSettings;
16
17class GrProgramInfo {
18public:
19 GrProgramInfo(int numSamples,
20 int numStencilSamples,
21 const GrBackendFormat& backendFormat,
22 GrSurfaceOrigin origin,
23 const GrPipeline* pipeline,
24 const GrPrimitiveProcessor* primProc,
25 GrPrimitiveType primitiveType,
26 uint8_t tessellationPatchVertexCount = 0)
27 : fNumRasterSamples(pipeline->isStencilEnabled() ? numStencilSamples : numSamples)
28 , fIsMixedSampled(fNumRasterSamples > numSamples)
29 , fBackendFormat(backendFormat)
30 , fOrigin(origin)
31 , fPipeline(pipeline)
32 , fPrimProc(primProc)
33 , fPrimitiveType(primitiveType)
34 , fTessellationPatchVertexCount(tessellationPatchVertexCount) {
35 SkASSERT(fNumRasterSamples > 0);
36 SkASSERT((GrPrimitiveType::kPatches == fPrimitiveType) ==
37 (fTessellationPatchVertexCount > 0));
38 fRequestedFeatures = fPrimProc->requestedFeatures();
39 for (int i = 0; i < fPipeline->numFragmentProcessors(); ++i) {
40 fRequestedFeatures |= fPipeline->getFragmentProcessor(i).requestedFeatures();
41 }
42 fRequestedFeatures |= fPipeline->getXferProcessor().requestedFeatures();
43
44 SkDEBUGCODE(this->validate(false);)
45 }
46
47 GrProcessor::CustomFeatures requestedFeatures() const { return fRequestedFeatures; }
48
49 int numRasterSamples() const { return fNumRasterSamples; }
50 bool isMixedSampled() const { return fIsMixedSampled; }
51 // The backend format of the destination render target [proxy]
52 const GrBackendFormat& backendFormat() const { return fBackendFormat; }
53 GrSurfaceOrigin origin() const { return fOrigin; }
54 const GrPipeline& pipeline() const { return *fPipeline; }
55 const GrPrimitiveProcessor& primProc() const { return *fPrimProc; }
56
57 GrPrimitiveType primitiveType() const { return fPrimitiveType; }
58 uint8_t tessellationPatchVertexCount() const {
59 SkASSERT(GrPrimitiveType::kPatches == fPrimitiveType);
60 return fTessellationPatchVertexCount;
61 }
62
63 uint16_t primitiveTypeKey() const {
64 return ((uint16_t)fPrimitiveType << 8) | fTessellationPatchVertexCount;
65 }
66
67 // For Dawn, Metal and Vulkan the number of stencil bits is known a priori so we can
68 // create the stencil settings here.
69 GrStencilSettings nonGLStencilSettings() const;
70
71 // Invokes the visitor function on all FP proxies in the pipeline. The caller is responsible
72 // to call the visitor on its own primProc proxies.
73 void visitFPProxies(const GrOp::VisitProxyFunc& func) const { fPipeline->visitProxies(func); }
74
75#ifdef SK_DEBUG
76 void validate(bool flushTime) const;
77 void checkAllInstantiated() const;
78 void checkMSAAAndMIPSAreResolved() const;
79
80 bool isNVPR() const {
81 return fPrimProc->isPathRendering() && !fPrimProc->willUseGeoShader() &&
82 !fPrimProc->numVertexAttributes() && !fPrimProc->numInstanceAttributes();
83 }
84#endif
85
86private:
87 const int fNumRasterSamples;
88 const bool fIsMixedSampled;
89 const GrBackendFormat fBackendFormat;
90 const GrSurfaceOrigin fOrigin;
91 const GrPipeline* fPipeline;
92 const GrPrimitiveProcessor* fPrimProc;
93 GrProcessor::CustomFeatures fRequestedFeatures;
94 GrPrimitiveType fPrimitiveType;
95 uint8_t fTessellationPatchVertexCount; // GrPrimType::kPatches.
96};
97
98#endif
99