Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 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 | |
Robert Phillips | a87c529 | 2019-11-12 10:12:42 -0500 | [diff] [blame] | 15 | class GrStencilSettings; |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 16 | |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 17 | class GrProgramInfo { |
| 18 | public: |
| 19 | GrProgramInfo(int numSamples, |
Chris Dalton | 5e8cdfd | 2019-11-11 15:23:30 -0700 | [diff] [blame] | 20 | int numStencilSamples, |
Robert Phillips | 933484f | 2019-11-26 09:38:55 -0500 | [diff] [blame] | 21 | const GrBackendFormat& backendFormat, |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 22 | GrSurfaceOrigin origin, |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 23 | const GrPipeline* pipeline, |
| 24 | const GrPrimitiveProcessor* primProc, |
Chris Dalton | 5a2f962 | 2019-12-27 14:56:38 -0700 | [diff] [blame] | 25 | GrPrimitiveType primitiveType, |
| 26 | uint8_t tessellationPatchVertexCount = 0) |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 27 | : fNumRasterSamples(pipeline->isStencilEnabled() ? numStencilSamples : numSamples) |
Chris Dalton | 5e8cdfd | 2019-11-11 15:23:30 -0700 | [diff] [blame] | 28 | , fIsMixedSampled(fNumRasterSamples > numSamples) |
Robert Phillips | 933484f | 2019-11-26 09:38:55 -0500 | [diff] [blame] | 29 | , fBackendFormat(backendFormat) |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 30 | , fOrigin(origin) |
| 31 | , fPipeline(pipeline) |
| 32 | , fPrimProc(primProc) |
Chris Dalton | 5a2f962 | 2019-12-27 14:56:38 -0700 | [diff] [blame] | 33 | , fPrimitiveType(primitiveType) |
| 34 | , fTessellationPatchVertexCount(tessellationPatchVertexCount) { |
Chris Dalton | 5e8cdfd | 2019-11-11 15:23:30 -0700 | [diff] [blame] | 35 | SkASSERT(fNumRasterSamples > 0); |
Chris Dalton | 5a2f962 | 2019-12-27 14:56:38 -0700 | [diff] [blame] | 36 | SkASSERT((GrPrimitiveType::kPatches == fPrimitiveType) == |
| 37 | (fTessellationPatchVertexCount > 0)); |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 38 | fRequestedFeatures = fPrimProc->requestedFeatures(); |
| 39 | for (int i = 0; i < fPipeline->numFragmentProcessors(); ++i) { |
| 40 | fRequestedFeatures |= fPipeline->getFragmentProcessor(i).requestedFeatures(); |
Robert Phillips | 7de1333 | 2019-10-09 15:44:54 -0400 | [diff] [blame] | 41 | } |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 42 | fRequestedFeatures |= fPipeline->getXferProcessor().requestedFeatures(); |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 43 | |
Robert Phillips | 8053c97 | 2019-11-21 10:44:53 -0500 | [diff] [blame] | 44 | SkDEBUGCODE(this->validate(false);) |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 45 | } |
| 46 | |
Robert Phillips | 7de1333 | 2019-10-09 15:44:54 -0400 | [diff] [blame] | 47 | GrProcessor::CustomFeatures requestedFeatures() const { return fRequestedFeatures; } |
| 48 | |
Chris Dalton | 5e8cdfd | 2019-11-11 15:23:30 -0700 | [diff] [blame] | 49 | int numRasterSamples() const { return fNumRasterSamples; } |
| 50 | bool isMixedSampled() const { return fIsMixedSampled; } |
Robert Phillips | 933484f | 2019-11-26 09:38:55 -0500 | [diff] [blame] | 51 | // The backend format of the destination render target [proxy] |
| 52 | const GrBackendFormat& backendFormat() const { return fBackendFormat; } |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 53 | GrSurfaceOrigin origin() const { return fOrigin; } |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 54 | const GrPipeline& pipeline() const { return *fPipeline; } |
| 55 | const GrPrimitiveProcessor& primProc() const { return *fPrimProc; } |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 56 | |
Robert Phillips | cea290f | 2019-11-06 11:21:03 -0500 | [diff] [blame] | 57 | GrPrimitiveType primitiveType() const { return fPrimitiveType; } |
Chris Dalton | 5a2f962 | 2019-12-27 14:56:38 -0700 | [diff] [blame] | 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 | } |
Robert Phillips | cea290f | 2019-11-06 11:21:03 -0500 | [diff] [blame] | 66 | |
Robert Phillips | a87c529 | 2019-11-12 10:12:42 -0500 | [diff] [blame] | 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 | |
Chris Dalton | be45742 | 2020-03-16 18:05:03 -0600 | [diff] [blame] | 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); } |
Robert Phillips | 8053c97 | 2019-11-21 10:44:53 -0500 | [diff] [blame] | 74 | |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 75 | #ifdef SK_DEBUG |
Robert Phillips | 8053c97 | 2019-11-21 10:44:53 -0500 | [diff] [blame] | 76 | void validate(bool flushTime) const; |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 77 | void checkAllInstantiated() const; |
| 78 | void checkMSAAAndMIPSAreResolved() const; |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 79 | |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 80 | bool isNVPR() const { |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 81 | return fPrimProc->isPathRendering() && !fPrimProc->willUseGeoShader() && |
| 82 | !fPrimProc->numVertexAttributes() && !fPrimProc->numInstanceAttributes(); |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 83 | } |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 84 | #endif |
| 85 | |
| 86 | private: |
Chris Dalton | 5e8cdfd | 2019-11-11 15:23:30 -0700 | [diff] [blame] | 87 | const int fNumRasterSamples; |
| 88 | const bool fIsMixedSampled; |
Robert Phillips | 933484f | 2019-11-26 09:38:55 -0500 | [diff] [blame] | 89 | const GrBackendFormat fBackendFormat; |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 90 | const GrSurfaceOrigin fOrigin; |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 91 | const GrPipeline* fPipeline; |
| 92 | const GrPrimitiveProcessor* fPrimProc; |
Robert Phillips | 7de1333 | 2019-10-09 15:44:54 -0400 | [diff] [blame] | 93 | GrProcessor::CustomFeatures fRequestedFeatures; |
Robert Phillips | cea290f | 2019-11-06 11:21:03 -0500 | [diff] [blame] | 94 | GrPrimitiveType fPrimitiveType; |
Chris Dalton | 5a2f962 | 2019-12-27 14:56:38 -0700 | [diff] [blame] | 95 | uint8_t fTessellationPatchVertexCount; // GrPrimType::kPatches. |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | #endif |