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