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