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 | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 15 | class GrMesh; |
Robert Phillips | a87c529 | 2019-11-12 10:12:42 -0500 | [diff] [blame] | 16 | class GrStencilSettings; |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 17 | |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 18 | class GrProgramInfo { |
| 19 | public: |
| 20 | GrProgramInfo(int numSamples, |
Chris Dalton | 5e8cdfd | 2019-11-11 15:23:30 -0700 | [diff] [blame] | 21 | int numStencilSamples, |
Robert Phillips | 933484f | 2019-11-26 09:38:55 -0500 | [diff] [blame^] | 22 | const GrBackendFormat& backendFormat, |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 23 | GrSurfaceOrigin origin, |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 24 | const GrPipeline* pipeline, |
| 25 | const GrPrimitiveProcessor* primProc, |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 26 | const GrPipeline::FixedDynamicState* fixedDynamicState, |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 27 | const GrPipeline::DynamicStateArrays* dynamicStateArrays, |
Robert Phillips | cea290f | 2019-11-06 11:21:03 -0500 | [diff] [blame] | 28 | int numDynamicStateArrays, |
| 29 | GrPrimitiveType primitiveType) |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 30 | : fNumRasterSamples(pipeline->isStencilEnabled() ? numStencilSamples : numSamples) |
Chris Dalton | 5e8cdfd | 2019-11-11 15:23:30 -0700 | [diff] [blame] | 31 | , fIsMixedSampled(fNumRasterSamples > numSamples) |
Robert Phillips | 933484f | 2019-11-26 09:38:55 -0500 | [diff] [blame^] | 32 | , fBackendFormat(backendFormat) |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 33 | , fOrigin(origin) |
| 34 | , fPipeline(pipeline) |
| 35 | , fPrimProc(primProc) |
| 36 | , fFixedDynamicState(fixedDynamicState) |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 37 | , fDynamicStateArrays(dynamicStateArrays) |
Robert Phillips | cea290f | 2019-11-06 11:21:03 -0500 | [diff] [blame] | 38 | , fNumDynamicStateArrays(numDynamicStateArrays) |
| 39 | , fPrimitiveType(primitiveType) { |
Chris Dalton | 5e8cdfd | 2019-11-11 15:23:30 -0700 | [diff] [blame] | 40 | SkASSERT(fNumRasterSamples > 0); |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 41 | fRequestedFeatures = fPrimProc->requestedFeatures(); |
| 42 | for (int i = 0; i < fPipeline->numFragmentProcessors(); ++i) { |
| 43 | fRequestedFeatures |= fPipeline->getFragmentProcessor(i).requestedFeatures(); |
Robert Phillips | 7de1333 | 2019-10-09 15:44:54 -0400 | [diff] [blame] | 44 | } |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 45 | fRequestedFeatures |= fPipeline->getXferProcessor().requestedFeatures(); |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 46 | |
Robert Phillips | 8053c97 | 2019-11-21 10:44:53 -0500 | [diff] [blame] | 47 | SkDEBUGCODE(this->validate(false);) |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 48 | (void) fNumDynamicStateArrays; // touch this to quiet unused member warnings |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 49 | } |
| 50 | |
Robert Phillips | 7de1333 | 2019-10-09 15:44:54 -0400 | [diff] [blame] | 51 | GrProcessor::CustomFeatures requestedFeatures() const { return fRequestedFeatures; } |
| 52 | |
Chris Dalton | 5e8cdfd | 2019-11-11 15:23:30 -0700 | [diff] [blame] | 53 | int numRasterSamples() const { return fNumRasterSamples; } |
| 54 | bool isMixedSampled() const { return fIsMixedSampled; } |
Robert Phillips | 933484f | 2019-11-26 09:38:55 -0500 | [diff] [blame^] | 55 | // The backend format of the destination render target [proxy] |
| 56 | const GrBackendFormat& backendFormat() const { return fBackendFormat; } |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 57 | GrSurfaceOrigin origin() const { return fOrigin; } |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 58 | const GrPipeline& pipeline() const { return *fPipeline; } |
| 59 | const GrPrimitiveProcessor& primProc() const { return *fPrimProc; } |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 60 | const GrPipeline::FixedDynamicState* fixedDynamicState() const { return fFixedDynamicState; } |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 61 | |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 62 | bool hasDynamicScissors() const { |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 63 | return fPipeline->isScissorEnabled() && |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 64 | fDynamicStateArrays && fDynamicStateArrays->fScissorRects; |
| 65 | } |
| 66 | |
| 67 | const SkIRect& dynamicScissor(int i) const { |
| 68 | SkASSERT(this->hasDynamicScissors()); |
| 69 | |
| 70 | return fDynamicStateArrays->fScissorRects[i]; |
| 71 | } |
| 72 | |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 73 | bool hasFixedScissor() const { return fPipeline->isScissorEnabled() && fFixedDynamicState; } |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 74 | |
| 75 | const SkIRect& fixedScissor() const { |
| 76 | SkASSERT(this->hasFixedScissor()); |
| 77 | |
| 78 | return fFixedDynamicState->fScissorRect; |
| 79 | } |
| 80 | |
| 81 | bool hasDynamicPrimProcTextures() const { |
| 82 | return fDynamicStateArrays && fDynamicStateArrays->fPrimitiveProcessorTextures; |
| 83 | } |
| 84 | |
Michael Ludwig | fcdd061 | 2019-11-25 08:34:31 -0500 | [diff] [blame] | 85 | const GrSurfaceProxy* const* dynamicPrimProcTextures(int i) const { |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 86 | SkASSERT(this->hasDynamicPrimProcTextures()); |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 87 | SkASSERT(i < fNumDynamicStateArrays); |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 88 | |
| 89 | return fDynamicStateArrays->fPrimitiveProcessorTextures + |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 90 | i * fPrimProc->numTextureSamplers(); |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | bool hasFixedPrimProcTextures() const { |
| 94 | return fFixedDynamicState && fFixedDynamicState->fPrimitiveProcessorTextures; |
| 95 | } |
| 96 | |
Michael Ludwig | fcdd061 | 2019-11-25 08:34:31 -0500 | [diff] [blame] | 97 | const GrSurfaceProxy* const* fixedPrimProcTextures() const { |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 98 | SkASSERT(this->hasFixedPrimProcTextures()); |
| 99 | |
| 100 | return fFixedDynamicState->fPrimitiveProcessorTextures; |
| 101 | } |
| 102 | |
Robert Phillips | cea290f | 2019-11-06 11:21:03 -0500 | [diff] [blame] | 103 | GrPrimitiveType primitiveType() const { return fPrimitiveType; } |
| 104 | |
Robert Phillips | a87c529 | 2019-11-12 10:12:42 -0500 | [diff] [blame] | 105 | // For Dawn, Metal and Vulkan the number of stencil bits is known a priori so we can |
| 106 | // create the stencil settings here. |
| 107 | GrStencilSettings nonGLStencilSettings() const; |
| 108 | |
Robert Phillips | 8053c97 | 2019-11-21 10:44:53 -0500 | [diff] [blame] | 109 | void visitProxies(const GrOp::VisitProxyFunc& fn) const { |
| 110 | fPipeline->visitProxies(fn); |
| 111 | } |
| 112 | |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 113 | #ifdef SK_DEBUG |
Robert Phillips | 8053c97 | 2019-11-21 10:44:53 -0500 | [diff] [blame] | 114 | void validate(bool flushTime) const; |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 115 | void checkAllInstantiated() const; |
| 116 | void checkMSAAAndMIPSAreResolved() const; |
| 117 | void compatibleWithMeshes(const GrMesh meshes[], int meshCount) const; |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 118 | |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 119 | bool isNVPR() const { |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 120 | return fPrimProc->isPathRendering() && !fPrimProc->willUseGeoShader() && |
| 121 | !fPrimProc->numVertexAttributes() && !fPrimProc->numInstanceAttributes(); |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 122 | } |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 123 | #endif |
| 124 | |
| 125 | private: |
Chris Dalton | 5e8cdfd | 2019-11-11 15:23:30 -0700 | [diff] [blame] | 126 | const int fNumRasterSamples; |
| 127 | const bool fIsMixedSampled; |
Robert Phillips | 933484f | 2019-11-26 09:38:55 -0500 | [diff] [blame^] | 128 | const GrBackendFormat fBackendFormat; |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 129 | const GrSurfaceOrigin fOrigin; |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 130 | const GrPipeline* fPipeline; |
| 131 | const GrPrimitiveProcessor* fPrimProc; |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 132 | const GrPipeline::FixedDynamicState* fFixedDynamicState; |
| 133 | const GrPipeline::DynamicStateArrays* fDynamicStateArrays; |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 134 | const int fNumDynamicStateArrays; |
Robert Phillips | 7de1333 | 2019-10-09 15:44:54 -0400 | [diff] [blame] | 135 | GrProcessor::CustomFeatures fRequestedFeatures; |
Robert Phillips | cea290f | 2019-11-06 11:21:03 -0500 | [diff] [blame] | 136 | GrPrimitiveType fPrimitiveType; |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 137 | }; |
| 138 | |
| 139 | #endif |