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